]> git.ipfire.org Git - thirdparty/systemd.git/blob - hwdb/ids-update.pl
update TODO
[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-model.hwdb");
11 print(OUT "# This file is part of systemd.\n" .
12 "#\n" .
13 "# Data imported 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 $model = uc $1;
30 my $text = $2;
31 print(OUT "\n");
32 print(OUT "usb:v" . $vendor . "p" . $model . "*\n");
33 print(OUT " ID_MODEL_FROM_DATABASE=" . $text . "\n");
34 }
35 }
36
37 close(IN);
38 close(OUT);
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 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(IN);
104 close(OUT);
105 }
106
107 sub pci_vendor {
108 my $vendor;
109 my $device;
110 my $device_text;
111
112 open(IN, "<", "pci.ids");
113 open(OUT, ">", "20-pci-vendor-model.hwdb");
114 print(OUT "# This file is part of systemd.\n" .
115 "#\n" .
116 "# Data imported 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 $device_text = $2;
135 print(OUT "\n");
136 print(OUT "pci:v0000" . $vendor . "d0000" . $device . "*\n");
137 print(OUT " ID_MODEL_FROM_DATABASE=" . $device_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 $sub_text = $3;
146 $sub_text =~ s/^\Q$device_text\E\s*//;
147 $sub_text =~ s/(.+)/\ ($1)/;
148 print(OUT "\n");
149 print(OUT "pci:v0000" . $vendor . "d0000" . $device . "sv0000" . $sub_vendor . "sd0000" . $sub_device . "*\n");
150 print(OUT " ID_MODEL_FROM_DATABASE=" . $device_text . $sub_text . "\n");
151 }
152 }
153
154 close(IN);
155 close(OUT);
156 }
157
158 sub pci_classes {
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" .
167 "# Data imported from: http://pci-ids.ucw.cz/v2.2/pci.ids\n");
168
169 while (my $line = <IN>) {
170 $line =~ s/\s+$//;
171
172 $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/;
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
188 $line =~ m/^\t([0-9a-f]{2})\s*(.+)$/;
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
198 $line =~ m/^\t\t([0-9a-f]{2})\s*(.+)$/;
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
208 close(IN);
209 close(OUT);
210 }
211
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
279 sub oui {
280 my $iab_prefix;
281 my %iab_prefixes = ();
282
283 open(OUT, ">", "20-OUI.hwdb");
284 print(OUT "# This file is part of systemd.\n" .
285 "#\n" .
286 "# Data imported from:\n" .
287 "# http://standards.ieee.org/develop/regauth/oui/oui.txt\n" .
288 "# http://standards.ieee.org/develop/regauth/iab/iab.txt\n");
289
290 open(IN, "<", "iab.txt");
291 while (my $line = <IN>) {
292 $line =~ s/^ +//;
293 $line =~ s/\s+$//;
294 $line =~ m/^([0-9A-F]{2})-([0-9A-F]{2})-([0-9A-F]{2})\s*\(hex\)\s*.+$/;
295 if (defined $1) {
296 $iab_prefix = $1 . $2 . $3;
297 $iab_prefixes{ $iab_prefix } = 1;
298 next;
299 }
300
301 $line =~ m/^([0-9A-F]{3})000-\g1FFF\s*\(base 16\)\s*(.+)$/;
302 if (defined $1) {
303 my $vendor = uc $1;
304 my $text = $2;
305
306 print(OUT "\n");
307 print(OUT "OUI:" . $iab_prefix . $vendor . "*\n");
308 print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n");
309 }
310 }
311 close(IN);
312
313 open(IN, "<", "oui.txt");
314 while (my $line = <IN>) {
315 $line =~ s/^ +//;
316 $line =~ s/\s+$//;
317 $line =~ m/^([0-9A-F]{6})\s*\(base 16\)\s*(.+)$/;
318 if (defined $1) {
319 my $vendor = uc $1;
320 my $text = $2;
321
322 # skip the IAB prefixes
323 if (! exists $iab_prefixes{ $vendor }) {
324 print(OUT "\n");
325 print(OUT "OUI:" . $vendor . "*\n");
326 print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n");
327 }
328 }
329 }
330 close(IN);
331 close(OUT);
332 }
333
334 usb_vendor();
335 usb_classes();
336
337 pci_vendor();
338 pci_classes();
339
340 sdio_vendor();
341 sdio_classes();
342
343 oui();