]>
Commit | Line | Data |
---|---|---|
796b06c2 KS |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
cf7ebcea | 6 | sub usb_vendor { |
8db6dcfd KS |
7 | my $vendor; |
8 | ||
9 | open(IN, "<", "usb.ids"); | |
1d09582a | 10 | open(OUT, ">", "20-usb-vendor-model.hwdb"); |
8db6dcfd KS |
11 | print(OUT "# This file is part of systemd.\n" . |
12 | "#\n" . | |
378cf88f | 13 | "# Data imported from: http://www.linux-usb.org/usb.ids\n"); |
8db6dcfd KS |
14 | |
15 | while (my $line = <IN>) { | |
16 | $line =~ s/\s+$//; | |
c35ddc5b | 17 | $line =~ m/^([0-9a-f]{4})\s*(.+)$/; |
8db6dcfd KS |
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 | ||
c35ddc5b | 27 | $line =~ m/^\t([0-9a-f]{4})\s*(.+)$/; |
8db6dcfd | 28 | if (defined $1) { |
1d09582a | 29 | my $model = uc $1; |
8db6dcfd KS |
30 | my $text = $2; |
31 | print(OUT "\n"); | |
1d09582a KS |
32 | print(OUT "usb:v" . $vendor . "p" . $model . "*\n"); |
33 | print(OUT " ID_MODEL_FROM_DATABASE=" . $text . "\n"); | |
8db6dcfd KS |
34 | } |
35 | } | |
36 | ||
f9cd2224 MM |
37 | close(IN); |
38 | close(OUT); | |
8db6dcfd KS |
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" . | |
378cf88f | 50 | "# Data imported from: http://www.linux-usb.org/usb.ids\n"); |
8db6dcfd KS |
51 | |
52 | while (my $line = <IN>) { | |
53 | $line =~ s/\s+$//; | |
54 | ||
c35ddc5b | 55 | $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/; |
8db6dcfd KS |
56 | if (defined $1) { |
57 | $class = uc $1; | |
09d8f5d7 | 58 | if ($class =~ m/^00$/) { |
8db6dcfd KS |
59 | next; |
60 | } | |
09d8f5d7 | 61 | my $text = $2; |
8db6dcfd KS |
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 | ||
c35ddc5b | 74 | $line =~ m/^\t([0-9a-f]{2})\s*(.+)$/; |
8db6dcfd KS |
75 | if (defined $1) { |
76 | $subclass = uc $1; | |
09d8f5d7 KS |
77 | if ($subclass =~ m/^00$/) { |
78 | next; | |
79 | } | |
8db6dcfd KS |
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 | ||
c35ddc5b | 90 | $line =~ m/^\t\t([0-9a-f]{2})\s*(.+)$/; |
8db6dcfd KS |
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 | ||
f9cd2224 MM |
103 | close(IN); |
104 | close(OUT); | |
cf7ebcea KS |
105 | } |
106 | ||
107 | sub pci_vendor { | |
8db6dcfd KS |
108 | my $vendor; |
109 | my $device; | |
d060b62f | 110 | my $device_text; |
8db6dcfd | 111 | |
8db6dcfd | 112 | open(IN, "<", "pci.ids"); |
1d09582a | 113 | open(OUT, ">", "20-pci-vendor-model.hwdb"); |
8db6dcfd KS |
114 | print(OUT "# This file is part of systemd.\n" . |
115 | "#\n" . | |
378cf88f | 116 | "# Data imported from: http://pci-ids.ucw.cz/v2.2/pci.ids\n"); |
8db6dcfd KS |
117 | |
118 | while (my $line = <IN>) { | |
119 | $line =~ s/\s+$//; | |
c35ddc5b | 120 | $line =~ m/^([0-9a-f]{4})\s*(.+)$/; |
8db6dcfd KS |
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 | ||
c35ddc5b | 131 | $line =~ m/^\t([0-9a-f]{4})\s*(.+)$/; |
8db6dcfd KS |
132 | if (defined $1) { |
133 | $device = uc $1; | |
d060b62f | 134 | $device_text = $2; |
8db6dcfd KS |
135 | print(OUT "\n"); |
136 | print(OUT "pci:v0000" . $vendor . "d0000" . $device . "*\n"); | |
d060b62f | 137 | print(OUT " ID_MODEL_FROM_DATABASE=" . $device_text . "\n"); |
8db6dcfd KS |
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; | |
d060b62f KS |
145 | my $sub_text = $3; |
146 | $sub_text =~ s/^\Q$device_text\E\s*//; | |
bd64a88f | 147 | $sub_text =~ s/(.+)/\ ($1)/; |
8db6dcfd KS |
148 | print(OUT "\n"); |
149 | print(OUT "pci:v0000" . $vendor . "d0000" . $device . "sv0000" . $sub_vendor . "sd0000" . $sub_device . "*\n"); | |
d060b62f | 150 | print(OUT " ID_MODEL_FROM_DATABASE=" . $device_text . $sub_text . "\n"); |
8db6dcfd KS |
151 | } |
152 | } | |
153 | ||
f9cd2224 MM |
154 | close(IN); |
155 | close(OUT); | |
796b06c2 | 156 | } |
cf7ebcea KS |
157 | |
158 | sub pci_classes { | |
8db6dcfd KS |
159 | my $class; |
160 | my $subclass; | |
161 | my $interface; | |
162 | ||
163 | open(IN, "<", "pci.ids"); | |
164 | open(OUT, ">", "20-pci-classes.hwdb"); | |
165 | print(OUT "# This file is part of systemd.\n" . | |
166 | "#\n" . | |
378cf88f | 167 | "# Data imported from: http://pci-ids.ucw.cz/v2.2/pci.ids\n"); |
8db6dcfd KS |
168 | |
169 | while (my $line = <IN>) { | |
170 | $line =~ s/\s+$//; | |
171 | ||
c35ddc5b | 172 | $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/; |
8db6dcfd KS |
173 | if (defined $1) { |
174 | $class = uc $1; | |
175 | my $text = $2; | |
176 | print(OUT "\n"); | |
177 | print(OUT "pci:v*d*sv*sd*bc" . $class . "*\n"); | |
178 | print(OUT " ID_PCI_CLASS_FROM_DATABASE=" . $text . "\n"); | |
179 | next; | |
180 | } | |
181 | ||
182 | if (not defined $class) { | |
183 | next; | |
184 | } elsif ($line =~ m/^$/) { | |
185 | last; | |
186 | } | |
187 | ||
c35ddc5b | 188 | $line =~ m/^\t([0-9a-f]{2})\s*(.+)$/; |
8db6dcfd KS |
189 | if (defined $1) { |
190 | $subclass = uc $1; | |
191 | my $text = $2; | |
192 | print(OUT "\n"); | |
193 | print(OUT "pci:v*d*sv*sd*bc" . $class . "sc" . $subclass . "*\n"); | |
194 | print(OUT " ID_PCI_SUBCLASS_FROM_DATABASE=" . $text . "\n"); | |
195 | next; | |
196 | } | |
197 | ||
c35ddc5b | 198 | $line =~ m/^\t\t([0-9a-f]{2})\s*(.+)$/; |
8db6dcfd KS |
199 | if (defined $1) { |
200 | $interface = uc $1; | |
201 | my $text = $2; | |
202 | print(OUT "\n"); | |
203 | print(OUT "pci:v*d*sv*sd*bc" . $class . "sc" . $subclass . "i" . $interface . "*\n"); | |
204 | print(OUT " ID_PCI_INTERFACE_FROM_DATABASE=" . $text . "\n"); | |
205 | } | |
206 | } | |
207 | ||
f9cd2224 MM |
208 | close(IN); |
209 | close(OUT); | |
796b06c2 | 210 | } |
cf7ebcea | 211 | |
56243d09 MH |
212 | sub sdio_vendor { |
213 | my $vendor; | |
214 | my $device; | |
215 | ||
216 | open(IN, "<", "sdio.ids"); | |
217 | open(OUT, ">", "20-sdio-vendor-model.hwdb"); | |
218 | print(OUT "# This file is part of systemd.\n" . | |
219 | "#\n" . | |
220 | "# Data imported from: hwdb/sdio.ids\n"); | |
221 | ||
222 | while (my $line = <IN>) { | |
223 | $line =~ s/\s+$//; | |
224 | $line =~ m/^([0-9a-f]{4})\s*(.+)$/; | |
225 | ||
226 | if (defined $1) { | |
227 | $vendor = uc $1; | |
228 | my $text = $2; | |
229 | print(OUT "\n"); | |
230 | print(OUT "sdio:c*v" . $vendor . "*\n"); | |
231 | print(OUT " ID_VENDOR_FROM_DATABASE=" . $text . "\n"); | |
232 | next; | |
233 | } | |
234 | ||
235 | $line =~ m/^\t([0-9a-f]{4})\s*(.+)$/; | |
236 | if (defined $1) { | |
237 | $device = uc $1; | |
238 | my $text = $2; | |
239 | print(OUT "\n"); | |
240 | print(OUT "sdio:c*v" . $vendor . "d" . $device . "*\n"); | |
241 | print(OUT " ID_MODEL_FROM_DATABASE=" . $text . "\n"); | |
242 | next; | |
243 | } | |
244 | } | |
245 | ||
246 | close(IN); | |
247 | close(OUT); | |
248 | } | |
249 | ||
250 | sub sdio_classes { | |
251 | my $class; | |
252 | my $subclass; | |
253 | my $interface; | |
254 | ||
255 | open(IN, "<", "sdio.ids"); | |
256 | open(OUT, ">", "20-sdio-classes.hwdb"); | |
257 | print(OUT "# This file is part of systemd.\n" . | |
258 | "#\n" . | |
259 | "# Data imported from: hwdb/sdio.ids\n"); | |
260 | ||
261 | while (my $line = <IN>) { | |
262 | $line =~ s/\s+$//; | |
263 | ||
264 | $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/; | |
265 | if (defined $1) { | |
266 | $class = uc $1; | |
267 | my $text = $2; | |
268 | print(OUT "\n"); | |
269 | print(OUT "sdio:c" . $class . "v*d*\n"); | |
270 | print(OUT " ID_SDIO_CLASS_FROM_DATABASE=" . $text . "\n"); | |
271 | next; | |
272 | } | |
273 | } | |
274 | ||
275 | close(IN); | |
276 | close(OUT); | |
277 | } | |
278 | ||
fd5a4613 KS |
279 | # MAC Address Block Large/Medium/Small |
280 | # Large MA-L 24/24 bit (OUI) | |
281 | # Medium MA-M 28/20 bit (OUI prefix owned by IEEE) | |
282 | # Small MA-S 36/12 bit (OUI prefix owned by IEEE) | |
cf7ebcea | 283 | sub oui { |
fd5a4613 KS |
284 | my $prefix; |
285 | my %ieee_prefixes = (); | |
5fe25aff | 286 | |
8db6dcfd KS |
287 | open(OUT, ">", "20-OUI.hwdb"); |
288 | print(OUT "# This file is part of systemd.\n" . | |
289 | "#\n" . | |
378cf88f | 290 | "# Data imported from:\n" . |
fd5a4613 KS |
291 | "# https://services13.ieee.org/RST/standards-ra-web/rest/assignments/download/?registry=MA-L&format=txt\n" . |
292 | "# https://services13.ieee.org/RST/standards-ra-web/rest/assignments/download/?registry=MA-M&format=txt\n" . | |
293 | "# https://services13.ieee.org/RST/standards-ra-web/rest/assignments/download/?registry=MA-S&format=txt\n"); | |
8db6dcfd | 294 | |
fd5a4613 | 295 | open(IN, "<", "ma-small.txt"); |
8db6dcfd | 296 | while (my $line = <IN>) { |
f2f18613 | 297 | $line =~ s/^ +//; |
8db6dcfd | 298 | $line =~ s/\s+$//; |
5fe25aff TG |
299 | $line =~ m/^([0-9A-F]{2})-([0-9A-F]{2})-([0-9A-F]{2})\s*\(hex\)\s*.+$/; |
300 | if (defined $1) { | |
fd5a4613 KS |
301 | $prefix = $1 . $2 . $3; |
302 | $ieee_prefixes{ $prefix } = 1; | |
5fe25aff TG |
303 | next; |
304 | } | |
305 | ||
306 | $line =~ m/^([0-9A-F]{3})000-\g1FFF\s*\(base 16\)\s*(.+)$/; | |
8db6dcfd KS |
307 | if (defined $1) { |
308 | my $vendor = uc $1; | |
309 | my $text = $2; | |
5fe25aff | 310 | |
8db6dcfd | 311 | print(OUT "\n"); |
fd5a4613 | 312 | print(OUT "OUI:" . $prefix . $vendor . "*\n"); |
8db6dcfd KS |
313 | print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n"); |
314 | } | |
315 | } | |
f9cd2224 | 316 | close(IN); |
5fe25aff | 317 | |
fd5a4613 KS |
318 | open(IN, "<", "ma-medium.txt"); |
319 | while (my $line = <IN>) { | |
320 | $line =~ s/^ +//; | |
321 | $line =~ s/\s+$//; | |
322 | $line =~ m/^([0-9A-F]{2})-([0-9A-F]{2})-([0-9A-F]{2})\s*\(hex\)\s*.+$/; | |
323 | if (defined $1) { | |
324 | $prefix = $1 . $2 . $3; | |
325 | $ieee_prefixes{ $prefix } = 1; | |
326 | next; | |
327 | } | |
328 | ||
329 | $line =~ m/^([0-9A-F])00000-\g1FFFFF\s*\(base 16\)\s*(.+)$/; | |
330 | if (defined $1) { | |
331 | my $vendor = uc $1; | |
332 | my $text = $2; | |
333 | ||
334 | print(OUT "\n"); | |
335 | print(OUT "OUI:" . $prefix . $vendor . "*\n"); | |
336 | print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n"); | |
337 | } | |
338 | } | |
339 | ||
340 | open(IN, "<", "ma-large.txt"); | |
5fe25aff | 341 | while (my $line = <IN>) { |
f2f18613 | 342 | $line =~ s/^ +//; |
5fe25aff TG |
343 | $line =~ s/\s+$//; |
344 | $line =~ m/^([0-9A-F]{6})\s*\(base 16\)\s*(.+)$/; | |
345 | if (defined $1) { | |
346 | my $vendor = uc $1; | |
347 | my $text = $2; | |
8db6dcfd | 348 | |
fd5a4613 KS |
349 | if ($text =~ m/^IEEE REGISTRATION AUTHORITY/) { |
350 | next; | |
351 | } | |
352 | ||
353 | # skip the IEEE owned prefixes | |
354 | if (! exists $ieee_prefixes{ $vendor }) { | |
5fe25aff TG |
355 | print(OUT "\n"); |
356 | print(OUT "OUI:" . $vendor . "*\n"); | |
357 | print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n"); | |
358 | } | |
359 | } | |
360 | } | |
f9cd2224 | 361 | close(IN); |
fd5a4613 | 362 | |
f9cd2224 | 363 | close(OUT); |
448004c3 | 364 | } |
cf7ebcea KS |
365 | |
366 | usb_vendor(); | |
8db6dcfd KS |
367 | usb_classes(); |
368 | ||
cf7ebcea KS |
369 | pci_vendor(); |
370 | pci_classes(); | |
8db6dcfd | 371 | |
56243d09 MH |
372 | sdio_vendor(); |
373 | sdio_classes(); | |
374 | ||
cf7ebcea | 375 | oui(); |