For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / epan / dissectors / packet-btamp.c
index 8885fc6ee0a3149dfd2aed85d6d852d2a79e9d58..f651f1a25f6030e645f289f404b07feb14c9c388 100644 (file)
@@ -137,7 +137,7 @@ dissect_comrej(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tr
     guint16 reason;
 
     reason = tvb_get_letohs(tvb, offset);
-    proto_tree_add_item(tree, hf_btamp_rej_reason, tvb, offset, 2, TRUE);
+    proto_tree_add_item(tree, hf_btamp_rej_reason, tvb, offset, 2, ENC_LITTLE_ENDIAN);
     offset+=2;
 
     switch(reason){
@@ -154,10 +154,10 @@ dissect_comrej(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tr
 static int
 dissect_discoverrequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
 {
-    proto_tree_add_item(tree, hf_btamp_mtu, tvb, offset, 2, TRUE);
+    proto_tree_add_item(tree, hf_btamp_mtu, tvb, offset, 2, ENC_LITTLE_ENDIAN);
     offset+=2;
 
-    proto_tree_add_item(tree, hf_btamp_extfeatures, tvb, offset, 2, TRUE);
+    proto_tree_add_item(tree, hf_btamp_extfeatures, tvb, offset, 2, ENC_LITTLE_ENDIAN);
     offset+=2;
 
     return offset;
@@ -175,13 +175,13 @@ dissect_controller_entry(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, prot
             "Entry: %u", idx);
     btamp_controller_entry_tree=proto_item_add_subtree(ti_controller_entry, ett_btamp_controller_entry);
 
-    proto_tree_add_item(btamp_controller_entry_tree, hf_btamp_controller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(btamp_controller_entry_tree, hf_btamp_controller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(btamp_controller_entry_tree, hf_btamp_controller_type, tvb, offset, 1, TRUE);
+    proto_tree_add_item(btamp_controller_entry_tree, hf_btamp_controller_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(btamp_controller_entry_tree, hf_btamp_controller_status, tvb, offset, 1, TRUE);
+    proto_tree_add_item(btamp_controller_entry_tree, hf_btamp_controller_status, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
     return offset;
@@ -195,10 +195,10 @@ dissect_discoverresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tr
     proto_tree *btamp_controller_list_tree=NULL;
     proto_item *ti_controller_list=NULL;
 
-    proto_tree_add_item(tree, hf_btamp_mtu, tvb, offset, 2, TRUE);
+    proto_tree_add_item(tree, hf_btamp_mtu, tvb, offset, 2, ENC_LITTLE_ENDIAN);
     offset+=2;
 
-    proto_tree_add_item(tree, hf_btamp_extfeatures, tvb, offset, 2, TRUE);
+    proto_tree_add_item(tree, hf_btamp_extfeatures, tvb, offset, 2, ENC_LITTLE_ENDIAN);
     offset+=2;
 
     length = tvb_length_remaining(tvb, offset);
@@ -208,7 +208,7 @@ dissect_discoverresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tr
             "Controller list");
     btamp_controller_list_tree=proto_item_add_subtree(ti_controller_list, ett_btamp_controller_list);
 
-    while ((length = tvb_length_remaining(tvb, offset)) >= 3) {
+    while (tvb_length_remaining(tvb, offset) >= 3) {
         offset = dissect_controller_entry(tvb, offset, pinfo, btamp_controller_list_tree, idx);
         ++idx;
     }
@@ -231,7 +231,7 @@ dissect_changenotify(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *
             "Controller list");
     btamp_controller_list_tree=proto_item_add_subtree(ti_controller_list, ett_btamp_controller_list);
 
-    while ((length = tvb_length_remaining(tvb, offset)) >= 3) {
+    while (tvb_length_remaining(tvb, offset) >= 3) {
         offset = dissect_controller_entry(tvb, offset, pinfo, btamp_controller_list_tree, idx);
         ++idx;
     }
@@ -248,7 +248,7 @@ dissect_changeresponse(tvbuff_t *tvb _U_, int offset, packet_info *pinfo _U_, pr
 static int
 dissect_getinforequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
 {
-    proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
     return offset;
@@ -260,19 +260,19 @@ dissect_getinforesponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto
     proto_tree *btamp_controller_tree=NULL;
     proto_item *ti_controller=NULL;
 
-    proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(tree, hf_btamp_status, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_status, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(tree, hf_btamp_total_bw, tvb, offset, 4, TRUE);
+    proto_tree_add_item(tree, hf_btamp_total_bw, tvb, offset, 4, ENC_LITTLE_ENDIAN);
     offset+=4;
 
-    proto_tree_add_item(tree, hf_btamp_max_guaran_bw, tvb, offset, 4, TRUE);
+    proto_tree_add_item(tree, hf_btamp_max_guaran_bw, tvb, offset, 4, ENC_LITTLE_ENDIAN);
     offset+=4;
 
-    proto_tree_add_item(tree, hf_btamp_min_latency, tvb, offset, 4, TRUE);
+    proto_tree_add_item(tree, hf_btamp_min_latency, tvb, offset, 4, ENC_LITTLE_ENDIAN);
     offset+=4;
 
     ti_controller=proto_tree_add_none_format(tree,
@@ -280,10 +280,10 @@ dissect_getinforesponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto
             offset, 2,
             "PAL Capabilities");
     btamp_controller_tree=proto_item_add_subtree(ti_controller, ett_btamp_caps);
-    proto_tree_add_item(btamp_controller_tree, hf_btamp_pal_caps_guaranteed, tvb, offset, 2, TRUE);
+    proto_tree_add_item(btamp_controller_tree, hf_btamp_pal_caps_guaranteed, tvb, offset, 2, ENC_LITTLE_ENDIAN);
     offset+=2;
 
-    proto_tree_add_item(tree, hf_btamp_amp_assoc_size, tvb, offset, 2, TRUE);
+    proto_tree_add_item(tree, hf_btamp_amp_assoc_size, tvb, offset, 2, ENC_LITTLE_ENDIAN);
     offset+=2;
 
     return offset;
@@ -292,7 +292,7 @@ dissect_getinforesponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto
 static int
 dissect_getampassocrequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
 {
-    proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
     return offset;
@@ -301,7 +301,7 @@ dissect_getampassocrequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, pr
 static int
 dissect_ampassoc(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
 {
-    proto_tree_add_item(tree, hf_btamp_amp_assoc, tvb, offset, tvb_length_remaining(tvb, offset), TRUE);
+    proto_tree_add_item(tree, hf_btamp_amp_assoc, tvb, offset, tvb_length_remaining(tvb, offset), ENC_NA);
     offset+=tvb_length_remaining(tvb, offset);
 
     return offset;
@@ -310,10 +310,10 @@ dissect_ampassoc(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *
 static int
 dissect_getampassocresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
 {
-    proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_controller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(tree, hf_btamp_status, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_status, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
     offset=dissect_ampassoc(tvb, offset, pinfo, tree);
@@ -324,10 +324,10 @@ dissect_getampassocresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto
 static int
 dissect_createphysicalrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
 {
-    proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
     offset=dissect_ampassoc(tvb, offset, pinfo, tree);
@@ -338,13 +338,13 @@ dissect_createphysicalrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, pro
 static int
 dissect_createphysicalresponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
 {
-    proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(tree, hf_btamp_status, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_status, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
     return offset;
@@ -353,10 +353,10 @@ dissect_createphysicalresponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_
 static int
 dissect_discphysicalchanrequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
 {
-    proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
     return offset;
@@ -365,19 +365,19 @@ dissect_discphysicalchanrequest(tvbuff_t *tvb, int offset, packet_info *pinfo _U
 static int
 dissect_discphysicalchanresponse(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
 {
-    proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_lcontroller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_rcontroller_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
-    proto_tree_add_item(tree, hf_btamp_controller_status, tvb, offset, 1, TRUE);
+    proto_tree_add_item(tree, hf_btamp_controller_status, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset+=1;
 
     return offset;
 }
 
-static void dissect_btamp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+static int dissect_btamp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
     int offset=0;
     proto_item *ti=NULL;
@@ -389,11 +389,28 @@ static void dissect_btamp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     guint16 cmd_length;
 
     col_set_str(pinfo->cinfo, COL_PROTOCOL, "AMP");
-    col_clear(pinfo->cinfo, COL_INFO);
-    col_set_str(pinfo->cinfo, COL_INFO, pinfo->p2p_dir == P2P_DIR_SENT ? "Sent " : "Rcvd ");
+    switch (pinfo->p2p_dir) {
+
+    case P2P_DIR_SENT:
+        col_add_str(pinfo->cinfo, COL_INFO, "Sent ");
+        break;
+
+    case P2P_DIR_RECV:
+        col_add_str(pinfo->cinfo, COL_INFO, "Rcvd ");
+        break;
+
+    case P2P_DIR_UNKNOWN:
+        col_clear(pinfo->cinfo, COL_INFO);
+        break;
+
+    default:
+        col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown direction %d ",
+                     pinfo->p2p_dir);
+        break;
+    }
 
     if(tree){
-        ti=proto_tree_add_item(tree, proto_btamp, tvb, offset, -1, FALSE);
+        ti=proto_tree_add_item(tree, proto_btamp, tvb, offset, -1, ENC_NA);
         btamp_tree=proto_item_add_subtree(ti, ett_btamp);
     }
 
@@ -405,14 +422,14 @@ static void dissect_btamp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     btamp_cmd_tree=proto_item_add_subtree(ti_command, ett_btamp_cmd);
 
     cmd_code=tvb_get_guint8(tvb, offset);
-    proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_code, tvb, offset, 1, TRUE);
+    proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_code, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset++;
 
-    proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_ident, tvb, offset, 1, TRUE);
+    proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_ident, tvb, offset, 1, ENC_LITTLE_ENDIAN);
     offset++;
 
     cmd_length=tvb_get_letohs(tvb, offset);
-    proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_length, tvb, offset, 2, TRUE);
+    proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
     proto_item_set_len(ti_command, cmd_length+4);
     offset+=2;
 
@@ -470,13 +487,14 @@ static void dissect_btamp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
         break;
 
     default:
-        proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_data, tvb, offset, -1, TRUE);
+        proto_tree_add_item(btamp_cmd_tree, hf_btamp_cmd_data, tvb, offset, -1, ENC_NA);
         offset+=tvb_length_remaining(tvb, offset);
         break;
     }
 
     proto_item_append_text(ti_command, "%s", val_to_str(cmd_code, command_code_vals, "Unknown PDU (%u)"));
     col_append_str(pinfo->cinfo, COL_INFO, val_to_str(cmd_code, command_code_vals, "Unknown PDU (%u)"));
+return offset;
 }
 
 /* Register the protocol with Wireshark */
@@ -511,7 +529,7 @@ proto_register_btamp(void)
                 "L2CAP Command Data", HFILL }
         },
         { &hf_btamp_rej_reason,
-            { "Reason",           "btl2cap.rej_reason",
+            { "Reason",           "btamp.rej_reason",
                 FT_UINT16, BASE_HEX, VALS(reason_vals), 0x0,
                 NULL, HFILL }
         },
@@ -624,7 +642,7 @@ proto_register_btamp(void)
     /* Register the protocol name and description */
     proto_btamp = proto_register_protocol("Bluetooth AMP Packet", "AMP", "btamp");
 
-    register_dissector("btamp", dissect_btamp, proto_btamp);
+    new_register_dissector("btamp", dissect_btamp, proto_btamp);
 
     /* Required function calls to register the header fields and subtrees used */
     proto_register_field_array(proto_btamp, hf, array_length(hf));
@@ -637,6 +655,6 @@ proto_reg_handoff_btamp(void)
     dissector_handle_t btamp_handle;
 
     btamp_handle = find_dissector("btamp");
-    dissector_add("btl2cap.cid", BTL2CAP_FIXED_CID_AMP_MAN, btamp_handle);
+    dissector_add_uint("btl2cap.cid", BTL2CAP_FIXED_CID_AMP_MAN, btamp_handle);
 }