3 # make-usb - Creates a file containing vendor and product ids.
4 # It use the databases at
5 # http://www.linux-usb.org/usb.ids
6 # to create our file epan/dissectors/usb.c
8 # It also uses the values culled out of libgphoto2 using usb-ptp-extract-models.pl
13 if sys.version_info[0] < 3:
16 import urllib.request, urllib.error, urllib.parse
19 MODE_VENDOR_PRODUCT = 1
20 MIN_VENDORS = 2900 # 2948 as of 2015-06-28
21 MIN_PRODUCTS = 15000 # 15415 as of 2015-06-28
25 # Grab from linux-usb.org
26 if sys.version_info[0] < 3:
27 response = urllib.urlopen('http://www.linux-usb.org/usb.ids')
29 response = urllib.request.urlopen('http://www.linux-usb.org/usb.ids')
30 lines = response.read().splitlines()
34 vendors_str="static const value_string usb_vendors_vals[] = {\n"
35 products_str="static const value_string usb_products_vals[] = {\n"
41 if line == "# Vendors, devices and interfaces. Please keep sorted.":
42 mode = MODE_VENDOR_PRODUCT
44 elif line == "# List of known device classes, subclasses and protocols":
48 if mode == MODE_VENDOR_PRODUCT:
49 if re.match("^[0-9a-f]{4}", line):
51 vendors[last_vendor] = re.sub("\"", "\\\"", re.sub("\?+", "?", repr(line[4:].strip())[1:-1].replace("\\", "\\\\")))
52 elif re.match("^\t[0-9a-f]{4}", line):
54 product = "%s%s"%(last_vendor, line[:4])
55 products[product] = re.sub("\"", "\\\"", re.sub("\?+", "?", repr(line[4:].strip())[1:-1].replace("\\", "\\\\")))
58 # Grab from libgphoto (indirectly through tools/usb-ptp-extract-models.pl)
59 u = open('tools/usb-ptp-extract-models.txt','r')
60 for line in u.readlines():
62 products[fields[0]]= ' '.join(fields[1:])
64 if (len(vendors) < MIN_VENDORS):
65 sys.stderr.write("Not enough vendors: %d\n" % len(vendors))
68 if (len(products) < MIN_PRODUCTS):
69 sys.stderr.write("Not enough products: %d\n" % len(products))
72 for v in sorted(vendors):
73 vendors_str += " { 0x%s, \"%s\" },\n"%(v,vendors[v])
75 vendors_str += """ { 0, NULL }\n};
76 value_string_ext ext_usb_vendors_vals = VALUE_STRING_EXT_INIT(usb_vendors_vals);
79 for p in sorted(products):
80 products_str += " { 0x%s, \"%s\" },\n"%(p,products[p])
82 products_str += """ { 0, NULL }\n};
83 value_string_ext ext_usb_products_vals = VALUE_STRING_EXT_INIT(usb_products_vals);
87 * USB vendor id and product ids
88 * This file was generated by running python ./tools/make-usb.py
89 * Don't change it directly.
91 * Copyright 2012, Michal Labedzki for Tieto Corporation
93 * Other values imported from libghoto2/camlibs/ptp2/library.c, music-players.h
95 * Copyright (C) 2001-2005 Mariusz Woloszyn <emsi@ipartners.pl>
96 * Copyright (C) 2003-2013 Marcus Meissner <marcus@jet.franken.de>
97 * Copyright (C) 2005 Hubert Figuiere <hfiguiere@teaser.fr>
98 * Copyright (C) 2009 Axel Waggershauser <awagger@web.de>
99 * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com>
100 * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se>
101 * Copyright (C) 2007 Ted Bullock
102 * Copyright (C) 2012 Sony Mobile Communications AB
104 * Wireshark - Network traffic analyzer
105 * By Gerald Combs <gerald@wireshark.org>
106 * Copyright 1998 Gerald Combs
108 * This program is free software; you can redistribute it and/or
109 * modify it under the terms of the GNU General Public License
110 * as published by the Free Software Foundation; either version 2
111 * of the License, or (at your option) any later version.
113 * This program is distributed in the hope that it will be useful,
114 * but WITHOUT ANY WARRANTY; without even the implied warranty of
115 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
116 * GNU General Public License for more details.
118 * You should have received a copy of the GNU General Public License
119 * along with this program; if not, write to the Free Software
120 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
124 * XXX We should probably parse a USB ID file at program start instead
125 * of generating this file.
129 #include <epan/packet.h>
132 f = open('epan/dissectors/usb.c', 'w')
137 f.write(products_str)