chiark / gitweb /
hwdb: Add SDIO database to ids-update.pl script
[elogind.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
111         open(IN, "<", "pci.ids");
112         open(OUT, ">", "20-pci-vendor-model.hwdb");
113         print(OUT "# This file is part of systemd.\n" .
114                   "#\n" .
115                   "# Data imported from: http://pci-ids.ucw.cz/v2.2/pci.ids\n");
116
117         while (my $line = <IN>) {
118                 $line =~ s/\s+$//;
119                 $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
120
121                 if (defined $1) {
122                         $vendor = uc $1;
123                         my $text = $2;
124                         print(OUT "\n");
125                         print(OUT "pci:v0000" . $vendor . "*\n");
126                         print(OUT " ID_VENDOR_FROM_DATABASE=" . $text . "\n");
127                         next;
128                 }
129
130                 $line =~ m/^\t([0-9a-f]{4})\s*(.+)$/;
131                 if (defined $1) {
132                         $device = uc $1;
133                         my $text = $2;
134                         print(OUT "\n");
135                         print(OUT "pci:v0000" . $vendor . "d0000" . $device . "*\n");
136                         print(OUT " ID_MODEL_FROM_DATABASE=" . $text . "\n");
137                         next;
138                 }
139
140                 $line =~ m/^\t\t([0-9a-f]{4})\s*([0-9a-f]{4})\s*(.*)$/;
141                 if (defined $1) {
142                         my $sub_vendor = uc $1;
143                         my $sub_device = uc $2;
144                         my $text = $3;
145                         print(OUT "\n");
146                         print(OUT "pci:v0000" . $vendor . "d0000" . $device . "sv0000" . $sub_vendor . "sd0000" . $sub_device . "*\n");
147                         print(OUT " ID_MODEL_FROM_DATABASE=" . $text . "\n");
148                 }
149         }
150
151         close(IN);
152         close(OUT);
153 }
154
155 sub pci_classes {
156         my $class;
157         my $subclass;
158         my $interface;
159
160         open(IN, "<", "pci.ids");
161         open(OUT, ">", "20-pci-classes.hwdb");
162         print(OUT "# This file is part of systemd.\n" .
163                   "#\n" .
164                   "# Data imported from: http://pci-ids.ucw.cz/v2.2/pci.ids\n");
165
166         while (my $line = <IN>) {
167                 $line =~ s/\s+$//;
168
169                 $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/;
170                 if (defined $1) {
171                         $class = uc $1;
172                         my $text = $2;
173                         print(OUT "\n");
174                         print(OUT "pci:v*d*sv*sd*bc" . $class . "*\n");
175                         print(OUT " ID_PCI_CLASS_FROM_DATABASE=" . $text . "\n");
176                         next;
177                 }
178
179                 if (not defined $class) {
180                         next;
181                 } elsif ($line =~ m/^$/) {
182                         last;
183                 }
184
185                 $line =~ m/^\t([0-9a-f]{2})\s*(.+)$/;
186                 if (defined $1) {
187                         $subclass = uc $1;
188                         my $text = $2;
189                         print(OUT "\n");
190                         print(OUT "pci:v*d*sv*sd*bc" . $class . "sc" . $subclass . "*\n");
191                         print(OUT " ID_PCI_SUBCLASS_FROM_DATABASE=" . $text . "\n");
192                         next;
193                 }
194
195                 $line =~ m/^\t\t([0-9a-f]{2})\s*(.+)$/;
196                 if (defined $1) {
197                         $interface = uc $1;
198                         my $text = $2;
199                         print(OUT "\n");
200                         print(OUT "pci:v*d*sv*sd*bc" .  $class . "sc" . $subclass . "i" . $interface . "*\n");
201                         print(OUT " ID_PCI_INTERFACE_FROM_DATABASE=" . $text . "\n");
202                 }
203         }
204
205         close(IN);
206         close(OUT);
207 }
208
209 sub sdio_vendor {
210         my $vendor;
211         my $device;
212
213         open(IN, "<", "sdio.ids");
214         open(OUT, ">", "20-sdio-vendor-model.hwdb");
215         print(OUT "# This file is part of systemd.\n" .
216                   "#\n" .
217                   "# Data imported from: hwdb/sdio.ids\n");
218
219         while (my $line = <IN>) {
220                 $line =~ s/\s+$//;
221                 $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
222
223                 if (defined $1) {
224                         $vendor = uc $1;
225                         my $text = $2;
226                         print(OUT "\n");
227                         print(OUT "sdio:c*v" . $vendor . "*\n");
228                         print(OUT " ID_VENDOR_FROM_DATABASE=" . $text . "\n");
229                         next;
230                 }
231
232                 $line =~ m/^\t([0-9a-f]{4})\s*(.+)$/;
233                 if (defined $1) {
234                         $device = uc $1;
235                         my $text = $2;
236                         print(OUT "\n");
237                         print(OUT "sdio:c*v" . $vendor . "d" . $device . "*\n");
238                         print(OUT " ID_MODEL_FROM_DATABASE=" . $text . "\n");
239                         next;
240                 }
241         }
242
243         close(IN);
244         close(OUT);
245 }
246
247 sub sdio_classes {
248         my $class;
249         my $subclass;
250         my $interface;
251
252         open(IN, "<", "sdio.ids");
253         open(OUT, ">", "20-sdio-classes.hwdb");
254         print(OUT "# This file is part of systemd.\n" .
255                   "#\n" .
256                   "# Data imported from: hwdb/sdio.ids\n");
257
258         while (my $line = <IN>) {
259                 $line =~ s/\s+$//;
260
261                 $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/;
262                 if (defined $1) {
263                         $class = uc $1;
264                         my $text = $2;
265                         print(OUT "\n");
266                         print(OUT "sdio:c" . $class . "v*d*\n");
267                         print(OUT " ID_SDIO_CLASS_FROM_DATABASE=" . $text . "\n");
268                         next;
269                 }
270         }
271
272         close(IN);
273         close(OUT);
274 }
275
276 sub oui {
277         my $iab_prefix;
278         my %iab_prefixes = ();
279
280         open(OUT, ">", "20-OUI.hwdb");
281         print(OUT "# This file is part of systemd.\n" .
282                   "#\n" .
283                   "# Data imported from:\n" .
284                   "#   http://standards.ieee.org/develop/regauth/oui/oui.txt\n" .
285                   "#   http://standards.ieee.org/develop/regauth/iab/iab.txt\n");
286
287         open(IN, "<", "iab.txt");
288         while (my $line = <IN>) {
289                 $line =~ s/^ +//;
290                 $line =~ s/\s+$//;
291                 $line =~ m/^([0-9A-F]{2})-([0-9A-F]{2})-([0-9A-F]{2})\s*\(hex\)\s*.+$/;
292                 if (defined $1) {
293                         $iab_prefix = $1 . $2 . $3;
294                         $iab_prefixes{ $iab_prefix } = 1;
295                         next;
296                 }
297
298                 $line =~ m/^([0-9A-F]{3})000-\g1FFF\s*\(base 16\)\s*(.+)$/;
299                 if (defined $1) {
300                         my $vendor = uc $1;
301                         my $text = $2;
302
303                         print(OUT "\n");
304                         print(OUT "OUI:" . $iab_prefix . $vendor . "*\n");
305                         print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n");
306                 }
307         }
308         close(IN);
309
310         open(IN, "<", "oui.txt");
311         while (my $line = <IN>) {
312                 $line =~ s/^ +//;
313                 $line =~ s/\s+$//;
314                 $line =~ m/^([0-9A-F]{6})\s*\(base 16\)\s*(.+)$/;
315                 if (defined $1) {
316                         my $vendor = uc $1;
317                         my $text = $2;
318
319                         # skip the IAB prefixes
320                         if (! exists $iab_prefixes{ $vendor }) {
321                                 print(OUT "\n");
322                                 print(OUT "OUI:" . $vendor . "*\n");
323                                 print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n");
324                         }
325                 }
326         }
327         close(IN);
328         close(OUT);
329 }
330
331 usb_vendor();
332 usb_classes();
333
334 pci_vendor();
335 pci_classes();
336
337 sdio_vendor();
338 sdio_classes();
339
340 oui();