dissect_usb_descriptor_header() takes an additional value_string
authorMartin Kaiser <wireshark@kaiser.cx>
Mon, 2 Sep 2013 14:31:22 +0000 (14:31 -0000)
committerMartin Kaiser <wireshark@kaiser.cx>
Mon, 2 Sep 2013 14:31:22 +0000 (14:31 -0000)
parameter to intrepret the descriptor type depending on the class

per default, the list of standard descriptor types is used

svn path=/trunk/; revision=51642

epan/dissectors/packet-usb-hid.c
epan/dissectors/packet-usb-video.c
epan/dissectors/packet-usb.c
epan/dissectors/packet-usb.h

index c5444058ced490d95a53b27f66a3d44f65f5edcf..7330b56f45d99d4b649d5a0a5c86b1d116044583 100644 (file)
@@ -825,7 +825,7 @@ dissect_usb_hid_class_descriptors(tvbuff_t *tvb, packet_info *pinfo _U_,
     ti = proto_tree_add_text(tree, tvb, offset, -1, "HID DESCRIPTOR");
     desc_tree = proto_item_add_subtree(ti, ett_usb_hid_descriptor);
 
-    dissect_usb_descriptor_header(desc_tree, tvb, offset);
+    dissect_usb_descriptor_header(desc_tree, tvb, offset, NULL);
     offset += 2;
     proto_tree_add_item(desc_tree, hf_usb_hid_bcdHID,
             tvb, offset, 2, ENC_LITTLE_ENDIAN);
index 3012fb689de169af84aac7a8485eab0fdd7517d0..e53c16cf029271e33bf6c9b514dd288b0114442b 100644 (file)
@@ -909,7 +909,7 @@ dissect_usb_video_control_interface_descriptor(proto_tree *parent_tree, tvbuff_t
     }
 
     /* Common fields */
-    dissect_usb_descriptor_header(tree, tvb, offset);
+    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
     subtype_item = proto_tree_add_item(tree, hf_usb_vid_control_ifdesc_subtype, tvb, offset+2, 1, ENC_NA);
     offset += 3;
 
@@ -1360,7 +1360,7 @@ dissect_usb_video_streaming_interface_descriptor(proto_tree *parent_tree, tvbuff
         tree = proto_item_add_subtree(item, ett_descriptor_video_streaming);
     }
 
-    dissect_usb_descriptor_header(tree, tvb, offset);
+    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
     proto_tree_add_item(tree, hf_usb_vid_streaming_ifdesc_subtype, tvb, offset+2, 1, ENC_NA);
     offset += 3;
 
@@ -1434,7 +1434,7 @@ dissect_usb_video_endpoint_descriptor(proto_tree *parent_tree, tvbuff_t *tvb,
         tree = proto_item_add_subtree(item, ett_descriptor_video_endpoint);
     }
 
-    dissect_usb_descriptor_header(tree, tvb, offset);
+    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
     proto_tree_add_item(tree, hf_usb_vid_epdesc_subtype, tvb, offset+2, 1, ENC_NA);
     offset += 3;
 
index c1aad5e140babef5aecf70e93556528792c1aceb..bd46c9bb71c1fd03cb47bf9107993b78b7972406 100644 (file)
@@ -1124,15 +1124,26 @@ dissect_usb_setup_get_configuration_response(packet_info *pinfo _U_, proto_tree
  */
 
 void dissect_usb_descriptor_header(proto_tree *tree,
-                                   tvbuff_t *tvb, int offset)
+                                   tvbuff_t *tvb, int offset,
+                                   value_string_ext *type_val_str)
 {
-    /* bLength */
-    proto_tree_add_item(tree,
-                        hf_usb_bLength,
-                        tvb, offset, 1,  ENC_LITTLE_ENDIAN);
-
-    /* bDescriptorType */
-    proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset+1, 1, ENC_LITTLE_ENDIAN);
+    guint8      desc_type;
+    proto_item *type_item = NULL;
+
+
+    proto_tree_add_item(tree, hf_usb_bLength,
+          tvb, offset, 1,  ENC_LITTLE_ENDIAN);
+    offset++;
+
+    desc_type = tvb_get_guint8(tvb, offset);
+    type_item = proto_tree_add_item(tree, hf_usb_bDescriptorType,
+          tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    /* if the caller provided no class specific value string, we're
+     * using the standard descriptor types */
+    if (!type_val_str)
+          type_val_str = &std_descriptor_type_vals_ext;
+    proto_item_append_text(type_item, " (%s)",
+             val_to_str_ext(desc_type, type_val_str, "unknown"));
 }
 
 /* 9.6.2 */
@@ -1155,7 +1166,7 @@ dissect_usb_device_qualifier_descriptor(packet_info *pinfo _U_, proto_tree *pare
         tree = proto_item_add_subtree(item, ett_descriptor_device);
     }
 
-    dissect_usb_descriptor_header(tree, tvb, offset);
+    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
     offset += 2;
 
     /* bcdUSB */
@@ -1252,7 +1263,7 @@ dissect_usb_device_descriptor(packet_info *pinfo, proto_tree *parent_tree,
 
     usb_conv_info=(usb_conv_info_t *)pinfo->usb_conv_info;
 
-    dissect_usb_descriptor_header(tree, tvb, offset);
+    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
     offset += 2;
 
     /* bcdUSB */
@@ -1397,7 +1408,7 @@ dissect_usb_string_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
         proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset+1, 1, ENC_LITTLE_ENDIAN);
     }
     else
-       dissect_usb_descriptor_header(tree, tvb, offset);
+       dissect_usb_descriptor_header(tree, tvb, offset, NULL);
 
     offset += 2;
 
@@ -1454,7 +1465,7 @@ dissect_usb_interface_descriptor(packet_info *pinfo, proto_tree *parent_tree,
     }
 
     len = tvb_get_guint8(tvb, offset);
-    dissect_usb_descriptor_header(tree, tvb, offset);
+    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
     offset += 2;
 
     /* bInterfaceNumber */
@@ -1564,7 +1575,7 @@ dissect_usb_endpoint_descriptor(packet_info *pinfo, proto_tree *parent_tree,
     }
 
     len = tvb_get_guint8(tvb, offset);
-    dissect_usb_descriptor_header(tree, tvb, offset);
+    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
     offset += 2;
 
     endpoint = tvb_get_guint8(tvb, offset)&0x0f;
@@ -1662,7 +1673,7 @@ dissect_usb_interface_assn_descriptor(packet_info *pinfo _U_, proto_tree *parent
         tree = proto_item_add_subtree(item, ett_descriptor_device);
     }
 
-    dissect_usb_descriptor_header(tree, tvb, offset);
+    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
     offset += 2;
 
     /* bFirstInterface */
@@ -1712,7 +1723,7 @@ dissect_usb_unknown_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
     }
 
     bLength = tvb_get_guint8(tvb, offset);
-    dissect_usb_descriptor_header(tree, tvb, offset);
+    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
     offset += bLength;
 
     if (item) {
@@ -1761,7 +1772,7 @@ dissect_usb_configuration_descriptor(packet_info *pinfo _U_, proto_tree *parent_
         tree = proto_item_add_subtree(item, ett_descriptor_device);
     }
 
-    dissect_usb_descriptor_header(tree, tvb, offset);
+    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
     offset += 2;
 
     /* wTotalLength */
index 20a75d578e72733ef3a78e15918de59be4a4b06d..4fd31aff4017b28374ce191860266494d74e0784 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef __PACKET_USB_H__
 #define __PACKET_USB_H__
 
+#include <epan/value_string.h>
 #include <epan/wmem/wmem.h>
 
 typedef struct _usb_address_t {
@@ -186,7 +187,9 @@ typedef struct _usb_data_t {
 
 usb_conv_info_t *get_usb_iface_conv_info(packet_info *pinfo, guint8 interface_num);
 
-void dissect_usb_descriptor_header(proto_tree *tree, tvbuff_t *tvb, int offset);
+void dissect_usb_descriptor_header(proto_tree *tree,
+                                   tvbuff_t *tvb, int offset,
+                                   value_string_ext *type_val_str);
 void dissect_usb_endpoint_address(proto_tree *tree, tvbuff_t *tvb, int offset);
 
 #endif