]> git.ipfire.org Git - thirdparty/systemd.git/blob - hwdb/ids-update.pl
869c49b861a8d377361021239004f93762397987
[thirdparty/systemd.git] / hwdb / ids-update.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 sub usb_vendor {
7 my $vendor;
8
9 open(IN, "<", "usb.ids");
10 open(OUT, ">", "20-usb-vendor-product.hwdb");
11 print(OUT "# This file is part of systemd.\n" .
12 "#\n" .
13 "# Data imported and updated from: http://www.linux-usb.org/usb.ids\n");
14
15 while (my $line = <IN>) {
16 $line =~ s/\s+$//;
17 $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
18 if (defined $1) {
19 $vendor = uc $1;
20 my $text = $2;
21 print(OUT "\n");
22 print(OUT "usb:v" . $vendor . "*\n");
23 print(OUT " ID_VENDOR_FROM_DATABASE=" . $text . "\n");
24 next;
25 }
26
27 $line =~ m/^\t([0-9a-f]{4})\s*(.+)$/;
28 if (defined $1) {
29 my $product = uc $1;
30 my $text = $2;
31 print(OUT "\n");
32 print(OUT "usb:v" . $vendor . "p" . $product . "*\n");
33 print(OUT " ID_PRODUCT_FROM_DATABASE=" . $text . "\n");
34 }
35 }
36
37 close(INP);
38 close(OUTP);
39 }
40
41 sub usb_classes {
42 my $class;
43 my $subclass;
44 my $protocol;
45
46 open(IN, "<", "usb.ids");
47 open(OUT, ">", "20-usb-classes.hwdb");
48 print(OUT "# This file is part of systemd.\n" .
49 "#\n" .
50 "# Data imported and updated from: http://www.linux-usb.org/usb.ids\n");
51
52 while (my $line = <IN>) {
53 $line =~ s/\s+$//;
54
55 $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/;
56 if (defined $1) {
57 $class = uc $1;
58 if ($class =~ m/^00$/) {
59 next;
60 }
61 my $text = $2;
62 print(OUT "\n");
63 print(OUT "usb:v*p*d*dc" . $class . "*\n");
64 print(OUT " ID_USB_CLASS_FROM_DATABASE=" . $text . "\n");
65 next;
66 }
67
68 if (not defined $class) {
69 next;
70 } elsif ($line =~ m/^$/) {
71 last;
72 }
73
74 $line =~ m/^\t([0-9a-f]{2})\s*(.+)$/;
75 if (defined $1) {
76 $subclass = uc $1;
77 if ($subclass =~ m/^00$/) {
78 next;
79 }
80 my $text = $2;
81 if ($text =~ m/^(\?|None|Unused)$/) {
82 next;
83 }
84 print(OUT "\n");
85 print(OUT "usb:v*p*d*dc" . $class . "dsc" . $subclass . "*\n");
86 print(OUT " ID_USB_SUBCLASS_FROM_DATABASE=" . $text . "\n");
87 next;
88 }
89
90 $line =~ m/^\t\t([0-9a-f]{2})\s*(.+)$/;
91 if (defined $1) {
92 $protocol = uc $1;
93 my $text = $2;
94 if ($text =~ m/^(\?|None|Unused)$/) {
95 next;
96 }
97 print(OUT "\n");
98 print(OUT "usb:v*p*d*dc" . $class . "dsc" . $subclass . "dp" . $protocol . "*\n");
99 print(OUT " ID_USB_PROTOCOL_FROM_DATABASE=" . $text . "\n");
100 }
101 }
102
103 close(INP);
104 close(OUTP);
105 }
106
107 sub pci_vendor {
108 my $vendor;
109 my $device;
110
111 open(IN, "<", "usb.ids");
112 open(IN, "<", "pci.ids");
113 open(OUT, ">", "20-pci-vendor-product.hwdb");
114 print(OUT "# This file is part of systemd.\n" .
115 "#\n" .
116 "# Data imported and updated from: http://pci-ids.ucw.cz/v2.2/pci.ids\n");
117
118 while (my $line = <IN>) {
119 $line =~ s/\s+$//;
120 $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
121
122 if (defined $1) {
123 $vendor = uc $1;
124 my $text = $2;
125 print(OUT "\n");
126 print(OUT "pci:v0000" . $vendor . "*\n");
127 print(OUT " ID_VENDOR_FROM_DATABASE=" . $text . "\n");
128 next;
129 }
130
131 $line =~ m/^\t([0-9a-f]{4})\s*(.+)$/;
132 if (defined $1) {
133 $device = uc $1;
134 my $text = $2;
135 print(OUT "\n");
136 print(OUT "pci:v0000" . $vendor . "d0000" . $device . "*\n");
137 print(OUT " ID_PRODUCT_FROM_DATABASE=" . $text . "\n");
138 next;
139 }
140
141 $line =~ m/^\t\t([0-9a-f]{4})\s*([0-9a-f]{4})\s*(.*)$/;
142 if (defined $1) {
143 my $sub_vendor = uc $1;
144 my $sub_device = uc $2;
145 my $text = $3;
146 print(OUT "\n");
147 print(OUT "pci:v0000" . $vendor . "d0000" . $device . "sv0000" . $sub_vendor . "sd0000" . $sub_device . "*\n");
148 print(OUT " ID_PRODUCT_FROM_DATABASE=" . $text . "\n");
149 }
150 }
151
152 close(INP);
153 close(OUTP);
154 }
155
156 sub pci_classes {
157 my $class;
158 my $subclass;
159 my $interface;
160
161 open(IN, "<", "pci.ids");
162 open(OUT, ">", "20-pci-classes.hwdb");
163 print(OUT "# This file is part of systemd.\n" .
164 "#\n" .
165 "# Data imported and updated from: http://pci-ids.ucw.cz/v2.2/pci.ids\n");
166
167 while (my $line = <IN>) {
168 $line =~ s/\s+$//;
169
170 $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/;
171 if (defined $1) {
172 $class = uc $1;
173 my $text = $2;
174 print(OUT "\n");
175 print(OUT "pci:v*d*sv*sd*bc" . $class . "*\n");
176 print(OUT " ID_PCI_CLASS_FROM_DATABASE=" . $text . "\n");
177 next;
178 }
179
180 if (not defined $class) {
181 next;
182 } elsif ($line =~ m/^$/) {
183 last;
184 }
185
186 $line =~ m/^\t([0-9a-f]{2})\s*(.+)$/;
187 if (defined $1) {
188 $subclass = uc $1;
189 my $text = $2;
190 print(OUT "\n");
191 print(OUT "pci:v*d*sv*sd*bc" . $class . "sc" . $subclass . "*\n");
192 print(OUT " ID_PCI_SUBCLASS_FROM_DATABASE=" . $text . "\n");
193 next;
194 }
195
196 $line =~ m/^\t\t([0-9a-f]{2})\s*(.+)$/;
197 if (defined $1) {
198 $interface = uc $1;
199 my $text = $2;
200 print(OUT "\n");
201 print(OUT "pci:v*d*sv*sd*bc" . $class . "sc" . $subclass . "i" . $interface . "*\n");
202 print(OUT " ID_PCI_INTERFACE_FROM_DATABASE=" . $text . "\n");
203 }
204 }
205
206 close(INP);
207 close(OUTP);
208 }
209
210 sub oui {
211 my $iab_prefix;
212 my %iab_prefixes = ();
213
214 open(OUT, ">", "20-OUI.hwdb");
215 print(OUT "# This file is part of systemd.\n" .
216 "#\n" .
217 "# Data imported and updated from: http://standards.ieee.org/develop/regauth/iab/iab.txt\n" .
218 "# Data imported and updated from: http://standards.ieee.org/develop/regauth/oui/oui.txt\n");
219
220 open(IN, "<", "iab.txt");
221 while (my $line = <IN>) {
222 $line =~ s/\s+$//;
223 $line =~ m/^([0-9A-F]{2})-([0-9A-F]{2})-([0-9A-F]{2})\s*\(hex\)\s*.+$/;
224 if (defined $1) {
225 $iab_prefix = $1 . $2 . $3;
226 $iab_prefixes{ $iab_prefix } = 1;
227 next;
228 }
229
230 $line =~ m/^([0-9A-F]{3})000-\g1FFF\s*\(base 16\)\s*(.+)$/;
231 if (defined $1) {
232 my $vendor = uc $1;
233 my $text = $2;
234
235 print(OUT "\n");
236 print(OUT "OUI:" . $iab_prefix . $vendor . "*\n");
237 print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n");
238 }
239 }
240 close(INP);
241
242 open(IN, "<", "oui.txt");
243 while (my $line = <IN>) {
244 $line =~ s/\s+$//;
245 $line =~ m/^([0-9A-F]{6})\s*\(base 16\)\s*(.+)$/;
246 if (defined $1) {
247 my $vendor = uc $1;
248 my $text = $2;
249
250 # skip the IAB prefixes
251 if (! exists $iab_prefixes{ $vendor }) {
252 print(OUT "\n");
253 print(OUT "OUI:" . $vendor . "*\n");
254 print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n");
255 }
256 }
257 }
258 close(INP);
259 close(OUTP);
260 }
261
262 usb_vendor();
263 usb_classes();
264
265 pci_vendor();
266 pci_classes();
267
268 oui();