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