Catch retransmission of FINs, so if we're doing "reassemble until end of
[metze/wireshark/wip.git] / tools / make-usb.py
1 #!/usr/bin/env python
2 #
3 # $Id$
4 #
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
9 #
10 # It also uses the values culled out of libgphoto2 using usb-ptp-extract-models.pl
11
12 import re
13 import urllib
14
15 MODE_IDLE           = 0
16 MODE_VENDOR_PRODUCT = 1
17
18
19 mode = MODE_IDLE
20
21 # Grab from linux-usb.org
22 response = urllib.urlopen('http://www.linux-usb.org/usb.ids')
23 lines = response.read().splitlines()
24
25 vendors  = dict()
26 products = dict()
27 vendors_str="static const value_string usb_vendors_vals[] = {\n"
28 products_str="static const value_string usb_products_vals[] = {\n"
29
30
31 for line in lines:
32     line = line.rstrip()
33
34     if line == "# Vendors, devices and interfaces. Please keep sorted.":
35         mode = MODE_VENDOR_PRODUCT
36         continue
37     elif line == "# List of known device classes, subclasses and protocols":
38         mode = MODE_IDLE
39         continue
40
41     if mode == MODE_VENDOR_PRODUCT:
42         if re.match("^[0-9a-f]{4}", line):
43             last_vendor=line[:4]
44             vendors[last_vendor] = re.sub("\"", "\\\"", re.sub("\?+", "?", repr(line[4:].strip())[1:-1].replace("\\", "\\\\")))
45         elif re.match("^\t[0-9a-f]{4}", line):
46             line = line.strip()
47             product = "%s%s"%(last_vendor, line[:4])
48             products[product] = re.sub("\"", "\\\"", re.sub("\?+", "?", repr(line[4:].strip())[1:-1].replace("\\", "\\\\")))
49
50
51 # Grab from libgphoto (indirectly through tools/usb-ptp-extract-models.pl)
52 u = open('tools/usb-ptp-extract-models.txt','r')
53 for line in u.readlines():
54     fields=line.split()
55     products[fields[0]]= ' '.join(fields[1:])
56
57
58 for v in sorted(vendors):
59     vendors_str += "    { 0x%s, \"%s\" },\n"%(v,vendors[v])
60
61 vendors_str += """    { 0, NULL }\n};
62 value_string_ext ext_usb_vendors_vals = VALUE_STRING_EXT_INIT(usb_vendors_vals);
63 """
64
65 for p in sorted(products):
66     products_str += "    { 0x%s, \"%s\" },\n"%(p,products[p])
67
68 products_str += """    { 0, NULL }\n};
69 value_string_ext ext_usb_products_vals = VALUE_STRING_EXT_INIT(usb_products_vals);
70 """
71
72 header="""/* usb.c
73  * USB vendor id and product ids
74  * This file was generated by running python ./tools/make-usb.py
75  * Don't change it directly.
76  *
77  * Copyright 2012, Michal Labedzki for Tieto Corporation
78  *
79  * Other values imported from libghoto2/camlibs/ptp2/library.c, music-players.h
80  *
81  * Copyright (C) 2001-2005 Mariusz Woloszyn <emsi@ipartners.pl>
82  * Copyright (C) 2003-2013 Marcus Meissner <marcus@jet.franken.de>
83  * Copyright (C) 2005 Hubert Figuiere <hfiguiere@teaser.fr>
84  * Copyright (C) 2009 Axel Waggershauser <awagger@web.de>
85  * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com>
86  * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se>
87  * Copyright (C) 2007 Ted Bullock
88  * Copyright (C) 2012 Sony Mobile Communications AB
89  *
90  * $Id$
91  *
92  * Wireshark - Network traffic analyzer
93  * By Gerald Combs <gerald@wireshark.org>
94  * Copyright 1998 Gerald Combs
95  *
96  * This program is free software; you can redistribute it and/or
97  * modify it under the terms of the GNU General Public License
98  * as published by the Free Software Foundation; either version 2
99  * of the License, or (at your option) any later version.
100  *
101  * This program is distributed in the hope that it will be useful,
102  * but WITHOUT ANY WARRANTY; without even the implied warranty of
103  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
104  * GNU General Public License for more details.
105  *
106  * You should have received a copy of the GNU General Public License
107  * along with this program; if not, write to the Free Software
108  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
109  */
110
111 #include "config.h"
112 #include <epan/packet.h>
113 """
114
115 f = open('epan/dissectors/usb.c', 'w')
116 f.write(header)
117 f.write("\n")
118 f.write(vendors_str)
119 f.write("\n\n")
120 f.write(products_str)
121 f.write("\n")
122 f.close()
123
124 print("Success!")
125
126