forked from osmocom/wireshark
From Michal Labedzki:
USB: Add support for vendor and product names from usb.ids database Part of: https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5032 svn path=/trunk/; revision=46280
This commit is contained in:
parent
a8b7b8b86c
commit
5a61f202d4
|
@ -1298,6 +1298,7 @@ set(IPMI_SUBPARSERS
|
|||
set(DISSECTOR_SUPPORT_SRC
|
||||
${IPMI_SUBPARSERS}
|
||||
dissectors/packet-dcerpc-nt.c
|
||||
usb.c
|
||||
register.c
|
||||
)
|
||||
|
||||
|
|
|
@ -1598,6 +1598,7 @@ IPMI_SUBPARSERS = \
|
|||
DISSECTOR_SUPPORT_SRC = \
|
||||
$(IPMI_SUBPARSERS) \
|
||||
packet-dcerpc-nt.c \
|
||||
usb.c \
|
||||
register.c
|
||||
|
||||
# this target needed for distribution only
|
||||
|
|
|
@ -414,6 +414,9 @@ static const value_string usb_urb_type_vals[] = {
|
|||
{0, NULL}
|
||||
};
|
||||
|
||||
extern value_string_ext ext_usb_vendors_vals;
|
||||
extern value_string_ext ext_usb_products_vals;
|
||||
|
||||
/*
|
||||
* Descriptor types.
|
||||
*/
|
||||
|
@ -990,9 +993,12 @@ dissect_usb_device_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
|
|||
proto_item *item = NULL;
|
||||
proto_item *nitem = NULL;
|
||||
proto_tree *tree = NULL;
|
||||
proto_item *nitem = NULL;
|
||||
int old_offset = offset;
|
||||
guint32 protocol;
|
||||
const gchar *description;
|
||||
guint16 product_id;
|
||||
guint32 product;
|
||||
|
||||
if (parent_tree) {
|
||||
item = proto_tree_add_text(parent_tree, tvb, offset, -1, "DEVICE DESCRIPTOR");
|
||||
|
@ -1029,11 +1035,17 @@ dissect_usb_device_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
|
|||
|
||||
/* idVendor */
|
||||
proto_tree_add_item(tree, hf_usb_idVendor, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
||||
offset+=2;
|
||||
vendor_id = tvb_get_letohs(tvb, offset);
|
||||
offset += 2;
|
||||
|
||||
/* idProduct */
|
||||
proto_tree_add_item(tree, hf_usb_idProduct, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
||||
offset+=2;
|
||||
nitem = proto_tree_add_item(tree, hf_usb_idProduct, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
||||
product_id = tvb_get_letohs(tvb, offset);
|
||||
product = vendor_id << 16 | product_id;
|
||||
proto_item_set_text(nitem, "idProduct: %s (0x%04x)",
|
||||
val_to_str_ext_const(product, &ext_usb_products_vals, "Unknown"),
|
||||
product_id);
|
||||
offset += 2;
|
||||
|
||||
/* bcdDevice */
|
||||
proto_tree_add_item(tree, hf_usb_bcdDevice, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
||||
|
@ -3000,7 +3012,7 @@ proto_register_usb(void)
|
|||
|
||||
{ &hf_usb_idVendor,
|
||||
{ "idVendor", "usb.idVendor",
|
||||
FT_UINT16, BASE_HEX, NULL, 0x0,
|
||||
FT_UINT16, BASE_HEX | BASE_EXT_STRING, &ext_usb_vendors_vals, 0x0,
|
||||
NULL, HFILL }},
|
||||
|
||||
{ &hf_usb_idProduct,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,97 @@
|
|||
#/usr/bin/python
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# make-usb - Creates a file containing vendor and product ids.
|
||||
# It use the databases at
|
||||
# http://www.linux-usb.org/usb.ids
|
||||
# to create our file epan/dissectors/usb.c
|
||||
#
|
||||
|
||||
import re
|
||||
import urllib
|
||||
|
||||
MODE_IDLE = 0
|
||||
MODE_VENDOR_PRODUCT = 1
|
||||
|
||||
|
||||
mode = MODE_IDLE
|
||||
|
||||
response = urllib.urlopen('http://www.linux-usb.org/usb.ids')
|
||||
lines = response.read().splitlines()
|
||||
|
||||
vendors="static const value_string usb_vendors_vals[] = {\n"
|
||||
products="static const value_string usb_products_vals[] = {\n"
|
||||
|
||||
|
||||
for line in lines:
|
||||
line = line.rstrip()
|
||||
|
||||
if line == "# Vendors, devices and interfaces. Please keep sorted.":
|
||||
mode = MODE_VENDOR_PRODUCT
|
||||
continue
|
||||
elif line == "# List of known device classes, subclasses and protocols":
|
||||
mode = MODE_IDLE
|
||||
continue
|
||||
|
||||
if mode == MODE_VENDOR_PRODUCT:
|
||||
if re.match("^[0-9a-f]{4}", line):
|
||||
vendors += " { 0x%s, \"%s\" },\n"%(line[:4], re.sub("\"", "\\\"", re.sub("\?+", "?", line[4:].strip().replace("\\", "\\\\"))))
|
||||
last_vendor = line[:4]
|
||||
elif re.match("^\t[0-9a-f]{4}", line):
|
||||
line = line.strip()
|
||||
products += " { 0x%s%s, \"%s\" },\n"%(last_vendor, line[:4], re.sub("\"", "\\\"", re.sub("\?+", "?", line[4:].strip().replace("\\", "\\\\"))))
|
||||
|
||||
|
||||
vendors += """ { 0, NULL }\n};
|
||||
value_string_ext ext_usb_vendors_vals = VALUE_STRING_EXT_INIT(usb_vendors_vals);
|
||||
"""
|
||||
|
||||
products += """ { 0, NULL }\n};
|
||||
value_string_ext ext_usb_products_vals = VALUE_STRING_EXT_INIT(usb_products_vals);
|
||||
"""
|
||||
|
||||
header="""/* usb.c
|
||||
* USB vendor id and product ids
|
||||
* This file was generated by running python ./tools/make-usb.py
|
||||
* Don't change it directly.
|
||||
*
|
||||
* Copyright 2012, Michal Labedzki for Tieto Corporation
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <epan/packet.h>
|
||||
"""
|
||||
|
||||
f = open('epan/dissectors/usb.c', 'w')
|
||||
f.write(header)
|
||||
f.write("\n")
|
||||
f.write(vendors)
|
||||
f.write("\n\n")
|
||||
f.write(products)
|
||||
f.write("\n")
|
||||
f.close()
|
||||
|
||||
print("Success!")
|
||||
|
||||
|
Loading…
Reference in New Issue