chiark / gitweb /
udev: in addition to DEVMODE, honor DEVUID, DEVGID from the uevent
[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-product.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 $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(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-product.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_PRODUCT_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_PRODUCT_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 oui {
210         my $iab_prefix;
211         my %iab_prefixes = ();
212
213         open(OUT, ">", "20-OUI.hwdb");
214         print(OUT "# This file is part of systemd.\n" .
215                   "#\n" .
216                   "# Data imported from:\n" .
217                   "#   http://standards.ieee.org/develop/regauth/oui/oui.txt\n" .
218                   "#   http://standards.ieee.org/develop/regauth/iab/iab.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(IN);
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(IN);
259         close(OUT);
260 }
261
262 usb_vendor();
263 usb_classes();
264
265 pci_vendor();
266 pci_classes();
267
268 oui();