chiark / gitweb /
96db87d788c8c54f0e364a8482acead8953f7cc9
[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 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                         my $text = $2;
59                         if ($text =~ m/^(\?|None|Unused)$/) {
60                                 next;
61                         }
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                         my $text = $2;
78                         if ($text =~ m/^(\?|None|Unused)$/) {
79                                 next;
80                         }
81                         print(OUT "\n");
82                         print(OUT "usb:v*p*d*dc" . $class . "dsc" . $subclass . "*\n");
83                         print(OUT " ID_USB_SUBCLASS_FROM_DATABASE=" . $text . "\n");
84                         next;
85                 }
86
87                 $line =~ m/^\t\t([0-9a-f]{2})\s*(.*)$/;
88                 if (defined $1) {
89                         $protocol = uc $1;
90                         my $text = $2;
91                         if ($text =~ m/^(\?|None|Unused)$/) {
92                                 next;
93                         }
94                         print(OUT "\n");
95                         print(OUT "usb:v*p*d*dc" .  $class . "dsc" . $subclass . "dp" . $protocol . "*\n");
96                         print(OUT " ID_USB_PROTOCOL_FROM_DATABASE=" . $text . "\n");
97                 }
98         }
99
100         close(INP);
101         close(OUTP);
102 }
103
104 sub pci_vendor {
105         my $vendor;
106         my $device;
107
108         open(IN, "<", "usb.ids");
109         open(IN, "<", "pci.ids");
110         open(OUT, ">", "20-pci-vendor-product.hwdb");
111         print(OUT "# This file is part of systemd.\n" .
112                   "#\n" .
113                   "# Data imported and updated from: http://pciids.sourceforge.net/v2.2/pci.ids\n");
114
115         while (my $line = <IN>) {
116                 $line =~ s/\s+$//;
117                 $line =~ m/^([0-9a-f]{4})\s*(.*)$/;
118
119                 if (defined $1) {
120                         $vendor = uc $1;
121                         my $text = $2;
122                         print(OUT "\n");
123                         print(OUT "pci:v0000" . $vendor . "*\n");
124                         print(OUT " ID_VENDOR_FROM_DATABASE=" . $text . "\n");
125                         next;
126                 }
127
128                 $line =~ m/^\t([0-9a-f]{4})\s*(.*)$/;
129                 if (defined $1) {
130                         $device = uc $1;
131                         my $text = $2;
132                         print(OUT "\n");
133                         print(OUT "pci:v0000" . $vendor . "d0000" . $device . "*\n");
134                         print(OUT " ID_PRODUCT_FROM_DATABASE=" . $text . "\n");
135                         next;
136                 }
137
138                 $line =~ m/^\t\t([0-9a-f]{4})\s*([0-9a-f]{4})\s*(.*)$/;
139                 if (defined $1) {
140                         my $sub_vendor = uc $1;
141                         my $sub_device = uc $2;
142                         my $text = $3;
143                         print(OUT "\n");
144                         print(OUT "pci:v0000" . $vendor . "d0000" . $device . "sv0000" . $sub_vendor . "sd0000" . $sub_device . "*\n");
145                         print(OUT " ID_PRODUCT_FROM_DATABASE=" . $text . "\n");
146                 }
147         }
148
149         close(INP);
150         close(OUTP);
151 }
152
153 sub pci_classes {
154         my $class;
155         my $subclass;
156         my $interface;
157
158         open(IN, "<", "pci.ids");
159         open(OUT, ">", "20-pci-classes.hwdb");
160         print(OUT "# This file is part of systemd.\n" .
161                   "#\n" .
162                   "# Data imported and updated from: http://pciids.sourceforge.net/v2.2/pci.ids\n");
163
164         while (my $line = <IN>) {
165                 $line =~ s/\s+$//;
166
167                 $line =~ m/^C\ ([0-9a-f]{2})\s*(.*)$/;
168                 if (defined $1) {
169                         $class = uc $1;
170                         my $text = $2;
171                         print(OUT "\n");
172                         print(OUT "pci:v*d*sv*sd*bc" . $class . "*\n");
173                         print(OUT " ID_PCI_CLASS_FROM_DATABASE=" . $text . "\n");
174                         next;
175                 }
176
177                 if (not defined $class) {
178                         next;
179                 } elsif ($line =~ m/^$/) {
180                         last;
181                 }
182
183                 $line =~ m/^\t([0-9a-f]{2})\s*(.*)$/;
184                 if (defined $1) {
185                         $subclass = uc $1;
186                         my $text = $2;
187                         print(OUT "\n");
188                         print(OUT "pci:v*d*sv*sd*bc" . $class . "sc" . $subclass . "*\n");
189                         print(OUT " ID_PCI_SUBCLASS_FROM_DATABASE=" . $text . "\n");
190                         next;
191                 }
192
193                 $line =~ m/^\t\t([0-9a-f]{2})\s*(.*)$/;
194                 if (defined $1) {
195                         $interface = uc $1;
196                         my $text = $2;
197                         print(OUT "\n");
198                         print(OUT "pci:v*d*sv*sd*bc" .  $class . "sc" . $subclass . "i" . $interface . "*\n");
199                         print(OUT " ID_PCI_INTERFACE_FROM_DATABASE=" . $text . "\n");
200                 }
201         }
202
203         close(INP);
204         close(OUTP);
205 }
206
207 sub oui {
208         open(IN, "<", "oui.txt");
209         open(OUT, ">", "20-OUI.hwdb");
210         print(OUT "# This file is part of systemd.\n" .
211                   "#\n" .
212                   "# Data imported and updated from: http://standards.ieee.org/develop/regauth/oui/oui.txt\n");
213
214         while (my $line = <IN>) {
215                 $line =~ s/\s+$//;
216                 $line =~ m/^([0-9A-F]{6})\s*\(base 16\)\s*(.*)$/;
217                 if (defined $1) {
218                         my $vendor = uc $1;
219                         my $text = $2;
220                         print(OUT "\n");
221                         print(OUT "OUI:" . $vendor . "\n");
222                         print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n");
223                 }
224         }
225
226         close(INP);
227         close(OUTP);
228 }
229
230 usb_vendor();
231 usb_classes();
232
233 pci_vendor();
234 pci_classes();
235
236 oui();