ids-update.pl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Date::Format;
  5. sub usb_vendor {
  6. my $vendor;
  7. my $source_date;
  8. open(IN, "<", "usb.ids");
  9. open(OUT, ">", "20-usb-vendor-model.hwdb");
  10. print(OUT "# This file is part of systemd.\n" .
  11. "#\n" .
  12. "# Generated: " . time2str("%Y-%m-%d\n", time) .
  13. "#\n" .
  14. "# Data imported from: http://www.linux-usb.org/usb.ids\n");
  15. while (my $line = <IN>) {
  16. $line =~ s/\s+$//;
  17. if (not defined $source_date) {
  18. $line =~ m/^#\s*Date:\s*(.+)$/;
  19. if (defined $1) {
  20. $source_date = $1;
  21. print(OUT "#\n# Source date: $1\n");
  22. next;
  23. }
  24. }
  25. $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
  26. if (defined $1) {
  27. $vendor = uc $1;
  28. my $text = $2;
  29. print(OUT "\n");
  30. print(OUT "usb:v" . $vendor . "*\n");
  31. print(OUT " ID_VENDOR_FROM_DATABASE=" . $text . "\n");
  32. next;
  33. }
  34. $line =~ m/^\t([0-9a-f]{4})\s*(.+)$/;
  35. if (defined $1) {
  36. my $model = uc $1;
  37. my $text = $2;
  38. print(OUT "\n");
  39. print(OUT "usb:v" . $vendor . "p" . $model . "*\n");
  40. print(OUT " ID_MODEL_FROM_DATABASE=" . $text . "\n");
  41. }
  42. }
  43. close(IN);
  44. close(OUT);
  45. }
  46. sub usb_classes {
  47. my $class;
  48. my $subclass;
  49. my $protocol;
  50. my $source_date;
  51. open(IN, "<", "usb.ids");
  52. open(OUT, ">", "20-usb-classes.hwdb");
  53. print(OUT "# This file is part of systemd.\n" .
  54. "#\n" .
  55. "# Generated: " . time2str("%Y-%m-%d\n", time) .
  56. "#\n" .
  57. "# Data imported from: http://www.linux-usb.org/usb.ids\n");
  58. while (my $line = <IN>) {
  59. $line =~ s/\s+$//;
  60. if (not defined $source_date) {
  61. $line =~ m/^#\s*Date:\s*(.+)$/;
  62. if (defined $1) {
  63. $source_date = $1;
  64. print(OUT "#\n# Source date: $1\n");
  65. next;
  66. }
  67. }
  68. $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/;
  69. if (defined $1) {
  70. $class = uc $1;
  71. if ($class =~ m/^00$/) {
  72. next;
  73. }
  74. my $text = $2;
  75. print(OUT "\n");
  76. print(OUT "usb:v*p*d*dc" . $class . "*\n");
  77. print(OUT " ID_USB_CLASS_FROM_DATABASE=" . $text . "\n");
  78. next;
  79. }
  80. if (not defined $class) {
  81. next;
  82. } elsif ($line =~ m/^$/) {
  83. last;
  84. }
  85. $line =~ m/^\t([0-9a-f]{2})\s*(.+)$/;
  86. if (defined $1) {
  87. $subclass = uc $1;
  88. if ($subclass =~ m/^00$/) {
  89. next;
  90. }
  91. my $text = $2;
  92. if ($text =~ m/^(\?|None|Unused)$/) {
  93. next;
  94. }
  95. print(OUT "\n");
  96. print(OUT "usb:v*p*d*dc" . $class . "dsc" . $subclass . "*\n");
  97. print(OUT " ID_USB_SUBCLASS_FROM_DATABASE=" . $text . "\n");
  98. next;
  99. }
  100. $line =~ m/^\t\t([0-9a-f]{2})\s*(.+)$/;
  101. if (defined $1) {
  102. $protocol = uc $1;
  103. my $text = $2;
  104. if ($text =~ m/^(\?|None|Unused)$/) {
  105. next;
  106. }
  107. print(OUT "\n");
  108. print(OUT "usb:v*p*d*dc" . $class . "dsc" . $subclass . "dp" . $protocol . "*\n");
  109. print(OUT " ID_USB_PROTOCOL_FROM_DATABASE=" . $text . "\n");
  110. }
  111. }
  112. close(IN);
  113. close(OUT);
  114. }
  115. sub pci_vendor {
  116. my $vendor;
  117. my $device;
  118. my $device_text;
  119. my $source_date;
  120. open(IN, "<", "pci.ids");
  121. open(OUT, ">", "20-pci-vendor-model.hwdb");
  122. print(OUT "# This file is part of systemd.\n" .
  123. "#\n" .
  124. "# Generated: " . time2str("%Y-%m-%d\n", time) .
  125. "#\n" .
  126. "# Data imported from: http://pci-ids.ucw.cz/v2.2/pci.ids\n");
  127. while (my $line = <IN>) {
  128. $line =~ s/\s+$//;
  129. if (not defined $source_date) {
  130. $line =~ m/^#\s*Date:\s*(.+)$/;
  131. if (defined $1) {
  132. $source_date = $1;
  133. print(OUT "#\n# Source date: $1\n");
  134. next;
  135. }
  136. }
  137. $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
  138. if (defined $1) {
  139. $vendor = uc $1;
  140. my $text = $2;
  141. print(OUT "\n");
  142. print(OUT "pci:v0000" . $vendor . "*\n");
  143. print(OUT " ID_VENDOR_FROM_DATABASE=" . $text . "\n");
  144. next;
  145. }
  146. $line =~ m/^\t([0-9a-f]{4})\s*(.+)$/;
  147. if (defined $1) {
  148. $device = uc $1;
  149. $device_text = $2;
  150. print(OUT "\n");
  151. print(OUT "pci:v0000" . $vendor . "d0000" . $device . "*\n");
  152. print(OUT " ID_MODEL_FROM_DATABASE=" . $device_text . "\n");
  153. next;
  154. }
  155. $line =~ m/^\t\t([0-9a-f]{4})\s*([0-9a-f]{4})\s*(.*)$/;
  156. if (defined $1) {
  157. my $sub_vendor = uc $1;
  158. my $sub_device = uc $2;
  159. my $sub_text = $3;
  160. $sub_text =~ s/^\Q$device_text\E\s*//;
  161. $sub_text =~ s/(.+)/\ ($1)/;
  162. print(OUT "\n");
  163. print(OUT "pci:v0000" . $vendor . "d0000" . $device . "sv0000" . $sub_vendor . "sd0000" . $sub_device . "*\n");
  164. print(OUT " ID_MODEL_FROM_DATABASE=" . $device_text . $sub_text . "\n");
  165. }
  166. }
  167. close(IN);
  168. close(OUT);
  169. }
  170. sub pci_classes {
  171. my $class;
  172. my $subclass;
  173. my $interface;
  174. my $source_date;
  175. open(IN, "<", "pci.ids");
  176. open(OUT, ">", "20-pci-classes.hwdb");
  177. print(OUT "# This file is part of systemd.\n" .
  178. "#\n" .
  179. "# Generated: " . time2str("%Y-%m-%d\n", time) .
  180. "#\n" .
  181. "# Data imported from: http://pci-ids.ucw.cz/v2.2/pci.ids\n");
  182. while (my $line = <IN>) {
  183. $line =~ s/\s+$//;
  184. if (not defined $source_date) {
  185. $line =~ m/^#\s*Date:\s*(.+)$/;
  186. if (defined $1) {
  187. $source_date = $1;
  188. print(OUT "#\n# Source date: $1\n");
  189. next;
  190. }
  191. }
  192. $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/;
  193. if (defined $1) {
  194. $class = uc $1;
  195. my $text = $2;
  196. print(OUT "\n");
  197. print(OUT "pci:v*d*sv*sd*bc" . $class . "*\n");
  198. print(OUT " ID_PCI_CLASS_FROM_DATABASE=" . $text . "\n");
  199. next;
  200. }
  201. if (not defined $class) {
  202. next;
  203. } elsif ($line =~ m/^$/) {
  204. last;
  205. }
  206. $line =~ m/^\t([0-9a-f]{2})\s*(.+)$/;
  207. if (defined $1) {
  208. $subclass = uc $1;
  209. my $text = $2;
  210. print(OUT "\n");
  211. print(OUT "pci:v*d*sv*sd*bc" . $class . "sc" . $subclass . "*\n");
  212. print(OUT " ID_PCI_SUBCLASS_FROM_DATABASE=" . $text . "\n");
  213. next;
  214. }
  215. $line =~ m/^\t\t([0-9a-f]{2})\s*(.+)$/;
  216. if (defined $1) {
  217. $interface = uc $1;
  218. my $text = $2;
  219. print(OUT "\n");
  220. print(OUT "pci:v*d*sv*sd*bc" . $class . "sc" . $subclass . "i" . $interface . "*\n");
  221. print(OUT " ID_PCI_INTERFACE_FROM_DATABASE=" . $text . "\n");
  222. }
  223. }
  224. close(IN);
  225. close(OUT);
  226. }
  227. sub sdio_vendor {
  228. my $vendor;
  229. my $device;
  230. open(IN, "<", "sdio.ids");
  231. open(OUT, ">", "20-sdio-vendor-model.hwdb");
  232. print(OUT "# This file is part of systemd.\n" .
  233. "#\n" .
  234. "# Generated: " . time2str("%Y-%m-%d\n", time) .
  235. "#\n" .
  236. "# Data imported from: hwdb/sdio.ids\n");
  237. while (my $line = <IN>) {
  238. $line =~ s/\s+$//;
  239. $line =~ m/^([0-9a-f]{4})\s*(.+)$/;
  240. if (defined $1) {
  241. $vendor = uc $1;
  242. my $text = $2;
  243. print(OUT "\n");
  244. print(OUT "sdio:c*v" . $vendor . "*\n");
  245. print(OUT " ID_VENDOR_FROM_DATABASE=" . $text . "\n");
  246. next;
  247. }
  248. $line =~ m/^\t([0-9a-f]{4})\s*(.+)$/;
  249. if (defined $1) {
  250. $device = uc $1;
  251. my $text = $2;
  252. print(OUT "\n");
  253. print(OUT "sdio:c*v" . $vendor . "d" . $device . "*\n");
  254. print(OUT " ID_MODEL_FROM_DATABASE=" . $text . "\n");
  255. next;
  256. }
  257. }
  258. close(IN);
  259. close(OUT);
  260. }
  261. sub sdio_classes {
  262. my $class;
  263. my $subclass;
  264. my $interface;
  265. open(IN, "<", "sdio.ids");
  266. open(OUT, ">", "20-sdio-classes.hwdb");
  267. print(OUT "# This file is part of systemd.\n" .
  268. "#\n" .
  269. "# Generated: " . time2str("%Y-%m-%d\n", time) .
  270. "#\n" .
  271. "# Data imported from: hwdb/sdio.ids\n");
  272. while (my $line = <IN>) {
  273. $line =~ s/\s+$//;
  274. $line =~ m/^C\ ([0-9a-f]{2})\s*(.+)$/;
  275. if (defined $1) {
  276. $class = uc $1;
  277. my $text = $2;
  278. print(OUT "\n");
  279. print(OUT "sdio:c" . $class . "v*d*\n");
  280. print(OUT " ID_SDIO_CLASS_FROM_DATABASE=" . $text . "\n");
  281. next;
  282. }
  283. }
  284. close(IN);
  285. close(OUT);
  286. }
  287. sub oui {
  288. my $iab_prefix;
  289. my %iab_prefixes = ();
  290. my $source_date;
  291. open(OUT, ">", "20-OUI.hwdb");
  292. print(OUT "# This file is part of systemd.\n" .
  293. "#\n" .
  294. "# Generated: " . time2str("%Y-%m-%d\n", time) .
  295. "#\n" .
  296. "# Data imported from:\n" .
  297. "# http://standards.ieee.org/develop/regauth/oui/oui.txt\n" .
  298. "# http://standards.ieee.org/develop/regauth/iab/iab.txt\n");
  299. open(IN, "<", "iab.txt");
  300. while (my $line = <IN>) {
  301. $line =~ s/^ +//;
  302. if (not defined $source_date) {
  303. $line =~ m/^\s*Generated:\s+(.+)$/;
  304. if (defined $1) {
  305. $source_date = $1;
  306. print(OUT "#\n# Source date: $1\n");
  307. next;
  308. }
  309. }
  310. $line =~ s/\s+$//;
  311. $line =~ m/^([0-9A-F]{2})-([0-9A-F]{2})-([0-9A-F]{2})\s*\(hex\)\s*.+$/;
  312. if (defined $1) {
  313. $iab_prefix = $1 . $2 . $3;
  314. $iab_prefixes{ $iab_prefix } = 1;
  315. next;
  316. }
  317. $line =~ m/^([0-9A-F]{3})000-\g1FFF\s*\(base 16\)\s*(.+)$/;
  318. if (defined $1) {
  319. my $vendor = uc $1;
  320. my $text = $2;
  321. print(OUT "\n");
  322. print(OUT "OUI:" . $iab_prefix . $vendor . "*\n");
  323. print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n");
  324. }
  325. }
  326. close(IN);
  327. open(IN, "<", "oui.txt");
  328. while (my $line = <IN>) {
  329. $line =~ s/^ +//;
  330. $line =~ s/\s+$//;
  331. $line =~ m/^([0-9A-F]{6})\s*\(base 16\)\s*(.+)$/;
  332. if (defined $1) {
  333. my $vendor = uc $1;
  334. my $text = $2;
  335. # skip the IAB prefixes
  336. if (! exists $iab_prefixes{ $vendor }) {
  337. print(OUT "\n");
  338. print(OUT "OUI:" . $vendor . "*\n");
  339. print(OUT " ID_OUI_FROM_DATABASE=" . $text . "\n");
  340. }
  341. }
  342. }
  343. close(IN);
  344. close(OUT);
  345. }
  346. usb_vendor();
  347. usb_classes();
  348. pci_vendor();
  349. pci_classes();
  350. sdio_vendor();
  351. sdio_classes();
  352. oui();