chiark / gitweb /
d51f2208f7a32d026a01c6ec3a7f91132325ec0f
[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 pci_vendor {
42         my $vendor;
43         my $device;
44
45         open(IN, "<", "usb.ids");
46         open(IN, "<", "pci.ids");
47         open(OUT, ">", "20-pci-vendor-product.hwdb");
48         print(OUT "# This file is part of systemd.\n" .
49                   "#\n" .
50                   "# Data imported and updated from: http://pciids.sourceforge.net/v2.2/pci.ids\n");
51
52         while (my $line = <IN>) {
53                 $line =~ s/\s+$//;
54                 $line =~ m/^([0-9a-f]{4})\s*(.*)$/;
55
56                 if (defined $1) {
57                         $vendor = uc $1;
58                         my $text = $2;
59                         print(OUT "\n");
60                         print(OUT "pci:v0000" . $vendor . "*\n");
61                         print(OUT " ID_VENDOR_FROM_DATABASE=" . $text . "\n");
62                         next;
63                 }
64
65                 $line =~ m/^\t([0-9a-f]{4})\s*(.*)$/;
66                 if (defined $1) {
67                         $device = uc $1;
68                         my $text = $2;
69                         print(OUT "\n");
70                         print(OUT "pci:v0000" . $vendor . "d0000" . $device . "*\n");
71                         print(OUT " ID_PRODUCT_FROM_DATABASE=" . $text . "\n");
72                         next;
73                 }
74
75                 $line =~ m/^\t\t([0-9a-f]{4})\s*([0-9a-f]{4})\s*(.*)$/;
76                 if (defined $1) {
77                         my $sub_vendor = uc $1;
78                         my $sub_device = uc $2;
79                         my $text = $3;
80                         print(OUT "\n");
81                         print(OUT "pci:v0000" . $vendor . "d0000" . $device . "sv0000" . $sub_vendor . "sd0000" . $sub_device . "*\n");
82                         print(OUT " ID_PRODUCT_FROM_DATABASE=" . $text . "\n");
83                 }
84         }
85
86         close(INP);
87         close(OUTP);
88 }
89
90 sub pci_classes {
91         my $class;
92         my $subclass;
93         my $interface;
94
95         open(IN, "<", "pci.ids");
96         open(OUT, ">", "20-pci-classes.hwdb");
97         print(OUT "# This file is part of systemd.\n" .
98                   "#\n" .
99                   "# Data imported and updated from: http://pciids.sourceforge.net/v2.2/pci.ids\n");
100
101         while (my $line = <IN>) {
102                 $line =~ s/\s+$//;
103
104                 $line =~ m/^C\ ([0-9a-f]{2})\s*(.*)$/;
105                 if (defined $1) {
106                         $class = uc $1;
107                         my $text = $2;
108                         print(OUT "\n");
109                         print(OUT "pci:v*d*sv*sd*bc" . $class . "*\n");
110                         print(OUT " ID_PCI_CLASS_FROM_DATABASE=" . $text . "\n");
111                         next;
112                 }
113
114                 if (not defined $class) {
115                         next;
116                 }
117
118                 $line =~ m/^\t([0-9a-f]{2})\s*(.*)$/;
119                 if (defined $1) {
120                         $subclass = uc $1;
121                         my $text = $2;
122                         print(OUT "\n");
123                         print(OUT "pci:v*d*sv*sd*bc" . $class . "sc" . $subclass . "*\n");
124                         print(OUT " ID_PCI_SUBCLASS_FROM_DATABASE=" . $text . "\n");
125                         next;
126                 }
127
128                 $line =~ m/^\t\t([0-9a-f]{2})\s*(.*)$/;
129                 if (defined $1) {
130                         $interface = uc $1;
131                         my $text = $2;
132                         print(OUT "\n");
133                         print(OUT "pci:v*d*sv*sd*bc" .  $class . "sc" . $subclass . "i" . $interface . "*\n");
134                         print(OUT " ID_PCI_INTERFACE_FROM_DATABASE=" . $text . "\n");
135                 }
136         }
137
138         close(INP);
139         close(OUTP);
140 }
141
142 sub oui {
143         open(IN, "<", "oui.txt");
144         open(OUT, ">", "20-OUI.hwdb");
145         print(OUT "# This file is part of systemd.\n" .
146                   "#\n" .
147                   "# Data imported and updated from: http://standards.ieee.org/develop/regauth/oui/oui.txt\n");
148
149         while (my $line = <IN>) {
150                 $line =~ s/\s+$//;
151                 $line =~ m/^([0-9A-F]{6})\s*\(base 16\)\s*(.*)$/;
152                 if (defined $1) {
153                         my $vendor = uc $1;
154                         my $text = $2;
155                         print(OUT "\n");
156                         print(OUT "OUI:" . $vendor . "\n");
157                         print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n");
158                 }
159         }
160
161         close(INP);
162         close(OUTP);
163 }
164
165 usb_vendor();
166 pci_vendor();
167 pci_classes();
168 oui();