summaryrefslogtreecommitdiff
path: root/hald/ids.c
blob: 98e4f9fc8e67224ba14637ac27a49e93364025b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
/***************************************************************************
 * CVSID: $Id$
 *
 * classdev.c : Handling of functional kernel devices
 *
 * Copyright (C) 2004 David Zeuthen, <david@fubar.dk>
 *
 * Licensed under the Academic Free License version 2.1
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 **************************************************************************/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>

#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>

#include "logger.h"

#include "ids.h"

#ifdef USE_PCI_IDS
/** Pointer to where the pci.ids file is loaded */
static char *pci_ids = NULL;

/** Length of data store at at pci_ids */
static size_t pci_ids_len;

/** Iterator position into pci_ids */
static size_t pci_ids_iter_pos;

/** Initialize the pci.ids line iterator to the beginning of the file */
static void
pci_ids_line_iter_init (void)
{
	pci_ids_iter_pos = 0;
}

/** Maximum length of lines in pci.ids */
#define PCI_IDS_MAX_LINE_LEN 512

/**  
 *  pci_ids_line_iter_get_line:
 *  @line_len:           Pointer to where number of bytes in line will
 *                       be stored
 *  Returns:             Pointer to the line; only valid until the
 *                       next invocation of this function
 *
 *  Get the next line from pci.ids
 */
static char *
pci_ids_line_iter_get_line (unsigned int *line_len)
{
	unsigned int i;
	static char line[PCI_IDS_MAX_LINE_LEN];

	for (i = 0;
	     pci_ids_iter_pos < pci_ids_len &&
	     i < PCI_IDS_MAX_LINE_LEN - 1 &&
	     pci_ids[pci_ids_iter_pos] != '\n'; i++, pci_ids_iter_pos++) {
		line[i] = pci_ids[pci_ids_iter_pos];
	}

	line[i] = '\0';
	if (line_len != NULL)
		*line_len = i;

	pci_ids_iter_pos++;

	return line;
}

/** 
 *  pci_ids_line_iter_has_more:
 *
 *  Returns:              #TRUE iff there are more lines to process
 *
 *  See if there are more lines to process in pci.ids 
 */
static dbus_bool_t
pci_ids_line_iter_has_more (void)
{
	return pci_ids_iter_pos < pci_ids_len;
}


/** 
 *  ids_find_pci:
 *  @vendor_id:           PCI vendor id or 0 if unknown
 *  @product_id:          PCI product id or 0 if unknown
 *  @subsys_vendor_id:    PCI subsystem vendor id or 0 if unknown
 *  @subsys_product_id:   PCI subsystem product id or 0 if unknown
 *  @vendor_name:         Set to pointer of result or NULL
 *  @product_name:        Set to pointer of result or NULL
 *  @subsys_vendor_name:  Set to pointer of result or NULL
 *  @subsys_product_name: Set to pointer of result or NULL
 *
 *  Find the names for a PCI device.
 *
 *  The pointers returned are only valid until the next invocation of this
 *  function.
 */
void
ids_find_pci (int vendor_id, int product_id,
	      int subsys_vendor_id, int subsys_product_id,
	      char **vendor_name, char **product_name,
	      char **subsys_vendor_name, char **subsys_product_name)
{
	char *line;
	unsigned int i;
	unsigned int line_len;
	unsigned int num_tabs;
	char rep_vi[8];
	char rep_pi[8];
	char rep_svi[8];
	char rep_spi[8];
	dbus_bool_t vendor_matched = FALSE;
	dbus_bool_t product_matched = FALSE;
	static char store_vn[PCI_IDS_MAX_LINE_LEN];
	static char store_pn[PCI_IDS_MAX_LINE_LEN];
	static char store_svn[PCI_IDS_MAX_LINE_LEN];
	static char store_spn[PCI_IDS_MAX_LINE_LEN];

	snprintf (rep_vi, 8, "%04x", vendor_id);
	snprintf (rep_pi, 8, "%04x", product_id);
	snprintf (rep_svi, 8, "%04x", subsys_vendor_id);
	snprintf (rep_spi, 8, "%04x", subsys_product_id);

	*vendor_name = NULL;
	*product_name = NULL;
	*subsys_vendor_name = NULL;
	*subsys_product_name = NULL;

	for (pci_ids_line_iter_init (); pci_ids_line_iter_has_more ();) {
		line = pci_ids_line_iter_get_line (&line_len);

		/* skip lines with no content */
		if (line_len < 4)
			continue;

		/* skip comments */
		if (line[0] == '#')
			continue;

		/* count number of tabs */
		num_tabs = 0;
		for (i = 0; i < line_len; i++) {
			if (line[i] != '\t')
				break;
			num_tabs++;
		}

		switch (num_tabs) {
		case 0:
			/* vendor names */
			vendor_matched = FALSE;

			/* first check subsys_vendor_id, if haven't done 
			 * already */
			if (*subsys_vendor_name == NULL
			    && subsys_vendor_id != 0) {
				if (memcmp (line, rep_svi, 4) == 0) {
					/* found it */
					for (i = 4; i < line_len; i++) {
						if (!isspace (line[i]))
							break;
					}
					strncpy (store_svn, line + i,
						 PCI_IDS_MAX_LINE_LEN);
					*subsys_vendor_name = store_svn;
				}
			}

			/* check vendor_id */
			if (vendor_id != 0) {
				if (memcmp (line, rep_vi, 4) == 0) {
					/* found it */
					vendor_matched = TRUE;

					for (i = 4; i < line_len; i++) {
						if (!isspace (line[i]))
							break;
					}
					strncpy (store_vn, line + i,
						 PCI_IDS_MAX_LINE_LEN);
					*vendor_name = store_vn;
				}
			}

			break;

		case 1:
			product_matched = FALSE;

			/* product names */
			if (!vendor_matched)
				continue;

			/* check product_id */
			if (product_id != 0) {
				if (memcmp (line + 1, rep_pi, 4) == 0) {
					/* found it */

					product_matched = TRUE;

					for (i = 5; i < line_len; i++) {
						if (!isspace (line[i]))
							break;
					}
					strncpy (store_pn, line + i,
						 PCI_IDS_MAX_LINE_LEN);
					*product_name = store_pn;
				}
			}
			break;

		case 2:
			/* subsystem_vendor subsystem_product */
			if (!vendor_matched || !product_matched)
				continue;

			/* check product_id */
			if (subsys_vendor_id != 0
			    && subsys_product_id != 0) {
				if (memcmp (line + 2, rep_svi, 4) == 0
				    && memcmp (line + 7, rep_spi,
					       4) == 0) {
					/* found it */
					for (i = 11; i < line_len; i++) {
						if (!isspace (line[i]))
							break;
					}
					strncpy (store_spn, line + i,
						 PCI_IDS_MAX_LINE_LEN);
					*subsys_product_name = store_spn;
				}
			}

			break;

		default:
			break;
		}

	}
}


/**  
 *  pci_ids_load:
 *  @path:               Path of the pci.ids file, e.g. /usr/share/hwdata/pci.ids
 *  
 *  Returns:             #TRUE if the file was succesfully loaded
 *
 *  Load the PCI database used for mapping vendor, product, subsys_vendor
 *  and subsys_product numbers into names.
 */
static dbus_bool_t
pci_ids_load (const char *path)
{
	int fd;
	struct stat statbuf;
	gboolean ret;

	ret = FALSE;

	if (stat (path, &statbuf) != 0) {
		HAL_WARNING (("Couldn't stat pci.ids file '%s', errno=%d: %s", path, errno, strerror (errno)));
		goto out;
	}
	pci_ids_len = statbuf.st_size;

	fd = open (path, O_RDONLY);
	if (fd < 0) {
		HAL_WARNING (("Couldn't open pci.ids file '%s', errno=%d: %s", path, errno, strerror (errno)));
		goto out;
	}

	pci_ids = mmap (NULL, pci_ids_len, PROT_READ, MAP_SHARED, fd, 0);
	if (pci_ids == MAP_FAILED) {
		HAL_WARNING (("Couldn't mmap pci.ids file '%s', errno=%d: %s", path, errno, strerror (errno)));
		close (fd);
		goto out;
	}

	ret = TRUE;

	close (fd);
out:
	return ret;
}

void
pci_ids_init (void)
{
	/* Load /usr/share/hwdata/pci.ids */
	pci_ids_load (PCI_IDS_DIR "/pci.ids");
}

#endif /*USE_PCI_IDS*/

/*==========================================================================*/

#ifdef USE_USB_IDS
/** Pointer to where the usb.ids file is loaded */
static char *usb_ids = NULL;

/** Length of data store at at usb_ids */
static size_t usb_ids_len;

/** Iterator position into usb_ids */
static size_t usb_ids_iter_pos;

/** Initialize the usb.ids line iterator to the beginning of the file */
static void
usb_ids_line_iter_init (void)
{
	usb_ids_iter_pos = 0;
}

/** Maximum length of lines in usb.ids */
#define USB_IDS_MAX_LINE_LEN 512

/** 
 *  usb_ids_line_iter_get_line:
 *  @line_len:            Pointer to where number of bytes in line will
 *                        be stored
 *  Returns:              Pointer to the line; only valid until the
 *                        next invocation of this function
 *
 *  Get the next line from usb.ids 
 */
static char *
usb_ids_line_iter_get_line (unsigned int *line_len)
{
	unsigned int i;
	static char line[USB_IDS_MAX_LINE_LEN];

	for (i = 0;
	     usb_ids_iter_pos < usb_ids_len &&
	     i < USB_IDS_MAX_LINE_LEN - 1 &&
	     usb_ids[usb_ids_iter_pos] != '\n'; i++, usb_ids_iter_pos++) {
		line[i] = usb_ids[usb_ids_iter_pos];
	}

	line[i] = '\0';
	if (line_len != NULL)
		*line_len = i;

	usb_ids_iter_pos++;

	return line;
}

/**  
 *  usb_ids_line_iter_has_more:
 *  
 *  Returns:              #TRUE iff there are more lines to process
 *
 *  See if there are more lines to process in usb.ids
 */
static dbus_bool_t
usb_ids_line_iter_has_more (void)
{
	return usb_ids_iter_pos < usb_ids_len;
}

/** 
 *  ids_find_usb:
 *  @vendor_id:          USB vendor id or 0 if unknown
 *  @product_id:         USB product id or 0 if unknown
 *  @vendor_name:        Set to pointer of result or NULL
 *  @product_name:       Set to pointer of result or NULL
 *
 *  Find the names for a USB device.
 *
 *  The pointers returned are only valid until the next invocation of this
 *  function.
 */
void
ids_find_usb (int vendor_id, int product_id,
	      char **vendor_name, char **product_name)
{
	char *line;
	unsigned int i;
	unsigned int line_len;
	unsigned int num_tabs;
	char rep_vi[8];
	char rep_pi[8];
	static char store_vn[USB_IDS_MAX_LINE_LEN];
	static char store_pn[USB_IDS_MAX_LINE_LEN];
	dbus_bool_t vendor_matched = FALSE;

	snprintf (rep_vi, 8, "%04x", vendor_id);
	snprintf (rep_pi, 8, "%04x", product_id);

	*vendor_name = NULL;
	*product_name = NULL;

	for (usb_ids_line_iter_init (); usb_ids_line_iter_has_more ();) {
		line = usb_ids_line_iter_get_line (&line_len);

		/* skip lines with no content */
		if (line_len < 4)
			continue;

		/* skip comments */
		if (line[0] == '#')
			continue;

		/* count number of tabs */
		num_tabs = 0;
		for (i = 0; i < line_len; i++) {
			if (line[i] != '\t')
				break;
			num_tabs++;
		}

		switch (num_tabs) {
		case 0:
			/* vendor names */
			vendor_matched = FALSE;

			/* check vendor_id */
			if (vendor_id != 0) {
				if (memcmp (line, rep_vi, 4) == 0) {
					/* found it */
					vendor_matched = TRUE;

					for (i = 4; i < line_len; i++) {
						if (!isspace (line[i]))
							break;
					}
					strncpy (store_vn, line + i,
						 USB_IDS_MAX_LINE_LEN);
					*vendor_name = store_vn;
				}
			}
			break;

		case 1:
			/* product names */
			if (!vendor_matched)
				continue;

			/* check product_id */
			if (product_id != 0) {
				if (memcmp (line + 1, rep_pi, 4) == 0) {
					/* found it */
					for (i = 5; i < line_len; i++) {
						if (!isspace (line[i]))
							break;
					}
					strncpy (store_pn, line + i,
						 USB_IDS_MAX_LINE_LEN);
					*product_name = store_pn;

					/* no need to continue the search */
					return;
				}
			}
			break;

		default:
			break;
		}

	}
}

/**  
 *  usb_ids_load:
 *  @path:               Path of the usb.ids file, e.g. /usr/share/hwdata/usb.ids
 *  Returns:             #TRUE if the file was succesfully loaded
 *
 *  Load the USB database used for mapping vendor, product, subsys_vendor
 *  and subsys_product numbers into names.
 */
static dbus_bool_t
usb_ids_load (const char *path)
{
	int fd;
	struct stat statbuf;
	gboolean ret;

	ret = FALSE;

	if (stat (path, &statbuf) != 0) {
		HAL_WARNING (("Couldn't stat usb.ids file '%s', errno=%d: %s", path, errno, strerror (errno)));
		goto out;
	}
	usb_ids_len = statbuf.st_size;

	fd = open (path, O_RDONLY);
	if (fd < 0) {
		HAL_WARNING (("Couldn't open usb.ids file '%s', errno=%d: %s", path, errno, strerror (errno)));
		goto out;
	}

	usb_ids = mmap (NULL, usb_ids_len, PROT_READ, MAP_SHARED, fd, 0);
	if (usb_ids == MAP_FAILED) {
		HAL_WARNING (("Couldn't mmap usb.ids file '%s', errno=%d: %s", path, errno, strerror (errno)));
		close (fd);
		goto out;
	}

	ret = TRUE;

	close (fd);
out:
	return ret;
}

void
usb_ids_init (void)
{
	/* Load /usr/share/hwdata/usb.ids */
	usb_ids_load (USB_IDS_DIR "/usb.ids");
}

#endif /*USE_USB_IDS*/

/*==========================================================================*/

#ifdef USE_PNP_IDS

/* This, somewhat incomplete, list is from this sources:
 * http://www.plasma-online.de/english/identify/serial/pnp_id_pnp.html 
 * http://www-pc.uni-regensburg.de/hardware/TECHNIK/PCI_PNP/pnpid.txt
 *
 * Keep this sorted!
 */
struct pnp_id {
	const char *id;
   	const char *desc;
} static const pnp_ids_list[] = {
	/* Crystal Semiconductor devices */
	{"CSC0000", "Crystal Semiconductor CS423x sound -- SB/WSS/OPL3 emulation"},
	{"CSC0001", "Crystal Semiconductor CS423x sound -- joystick"},
	{"CSC0003", "Crystal Semiconductor CS423x sound -- MPU401"},
	{"CSC0010", "Crystal Semiconductor CS423x sound -- control"},
	/* IBM devices */
	{"IBM0071", "IBM infrared communications device"},
	{"IBM3760", "IBM DSP"},
	{"IBM3780", "IBM pointing device"},
        /* FinePoint devices */
        {"FPI2004", "FinePoint Innovations Tablet"},
        /* Fujitsu (Siemens Computers) devices */
        {"FUJ02E5", "Wacom Serial Pen HID Tablet"},
        {"FUJ02E6", "Fujitsu Serial TouchScreen"},
	/* interrupt controllers */
	{"PNP0000", "AT Interrupt Controller"},
	{"PNP0001", "EISA Interrupt Controller"},
	{"PNP0002", "MCA Interrupt Controller"},
	{"PNP0003", "APIC"},
	{"PNP0004", "Cyrix SLiC MP interrupt controller"},
	/* timers */
	{"PNP0100", "AT Timer"},
	{"PNP0101", "EISA Timer"},
	{"PNP0102", "MCA Timer"},
	/* DMA controllers */
	{"PNP0200", "AT DMA Controller"},
	{"PNP0201", "EISA DMA Controller"},
	{"PNP0202", "MCA DMA Controller"},
	/* keyboards */
	{"PNP0300", "IBM PC/XT keyboard controller (83-key)"},
	{"PNP0301", "IBM PC/AT keyboard controller (86-key)"},
	{"PNP0302", "IBM PC/XT keyboard controller (84-key)"},
	{"PNP0303", "IBM Enhanced (101/102-key, PS/2 mouse support)"},
	{"PNP0304", "Olivetti Keyboard (83-key)"},
	{"PNP0305", "Olivetti Keyboard (102-key)"},
	{"PNP0306", "Olivetti Keyboard (86-key)"},
	{"PNP0307", "Microsoft Windows(R) Keyboard"},
	{"PNP0308", "General Input Device Emulation Interface (GIDEI) legacy"},
	{"PNP0309", "Olivetti Keyboard (A101/102 key)"},
	{"PNP030A", "AT&T 302 keyboard"},
	{"PNP030B", "Reserved by Microsoft"},
	{"PNP0320", "Japanese 101-key keyboard"},
	{"PNP0321", "Japanese AX keyboard"},
	{"PNP0322", "Japanese 106-key keyboard A01"},
	{"PNP0323", "Japanese 106-key keyboard 002/003"},
	{"PNP0324", "Japanese 106-key keyboard 001"},
	{"PNP0325", "Japanese Toshiba Desktop keyboard"},
	{"PNP0326", "Japanese Toshiba Laptop keyboard"},
	{"PNP0327", "Japanese Toshiba Notebook keyboard"},
	{"PNP0340", "Korean 84-key keyboard"},
	{"PNP0341", "Korean 86-key keyboard"},
	{"PNP0342", "Korean Enhanced keyboard"},
	{"PNP0343", "Korean Enhanced keyboard 101b"},
	{"PNP0343", "Korean Enhanced keyboard 101c"},
	{"PNP0344", "Korean Enhanced keyboard 103"},
	/* parallel ports */
	{"PNP0400", "Standard LPT printer port"},
	{"PNP0401", "ECP printer port"},
	/* serial ports */
	{"PNP0500", "Standard PC COM port"},
	{"PNP0501", "16550A-compatible COM port"},
	{"PNP0502", "Multiport serial device (non-intelligent 16550)"},
	{"PNP0510", "Generic IRDA-compatible device"},
	{"PNP0511", "Generic IRDA-compatible device"},
	/* IDE controller */
	{"PNP0600", "Generic ESDI/IDE/ATA compatible hard disk controller"},
	{"PNP0601", "Plus Hardcard II"},
	{"PNP0602", "Plus Hardcard IIXL/EZ"},
	{"PNP0603", "Generic IDE supporting Microsoft Device Bay Specification"},
	{"PNP0604", "PC standard floppy disk controller"},
	{"PNP0605", "HP Omnibook floppy disk controller"},
	{"PNP0680", "Bus Master E-IDE controller"},
	{"PNP0700", "PC standard floppy disk controller"},
	{"PNP0701", "Standard floppy controller supporting MS Device Bay Spec"},
	/* system devices */
	{"PNP0800", "AT-style speaker sound"},
	/* obsolete devices */
	{"PNP0802", "Microsoft Sound System compatible device (obsolete, use PNPB0xx instead)"},
	/* display adapters / graphic cards */
	{"PNP0900", "VGA Compatible"},
	{"PNP0901", "Video Seven VRAM/VRAM II/1024i"},
	{"PNP0902", "IBM 8514/A Compatible"},
	{"PNP0903", "Trident VGA"},
	{"PNP0904", "Cirrus Logic Laptop VGA"},
	{"PNP0905", "Cirrus Logic VGA"},
	{"PNP0906", "Tseng Labs ET4000"},
	{"PNP0907", "Western Digital VGA"},
	{"PNP0908", "Western Digital Laptop VGA"},
	{"PNP0909", "S3 Inc. 911/924"},
	{"PNP090A", "ATI Ultra Pro/Plus (Mach 32)"},
	{"PNP090B", "ATI Ultra (Mach 8)"},
	{"PNP090C", "IBM XGA Compatible"},
	{"PNP090D", "ATI VGA Wonder"},
	{"PNP090E", "Weitek P9000 Graphics Adapter"},
	{"PNP090F", "Oak Technology VGA"},
	{"PNP0910", "Compaq QVision"},
	{"PNP0911", "IBM XGA/2"},
	{"PNP0912", "Tseng Labs ET4000 W32/W32i/W32p"},
	{"PNP0913", "S3 Inc. 801/928/964"},
	{"PNP0914", "Cirrus Logic 5429/5434 (memory mapped)"},
	{"PNP0915", "Compaq Advanced VGA (AVGA)"},
	{"PNP0916", "ATI Ultra Pro Turbo (Mach64)"},
	{"PNP0917", "Reserved by Microsoft"},
	{"PNP0918", "Matrox MGA"},
	{"PNP0919", "Compaq QVision 2000"},
	{"PNP091A", "Tseng Labs W128"},
	{"PNP0930", "Chips & Technologies Super VGA"},
	{"PNP0931", "Chips & Technologies Accelerator"},
	{"PNP0940", "NCR 77c22e Super VGA"},
	{"PNP0941", "NCR 77c32blt"},
	{"PNP09FF", "Plug and Play Monitors (VESA DDC)"},
	/* peripheral buses */
	{"PNP0A00", "ISA Bus"},
	{"PNP0A01", "EISA Bus"},
	{"PNP0A02", "MCA Bus"},
	{"PNP0A03", "PCI Bus"},
	{"PNP0A04", "VESA/VL Bus"},
	{"PNP0A05", "Generic ACPI Bus"},
	{"PNP0A06", "Generic ACPI Extended-IO Bus (EIO bus)"},
	/* system devices */
	{"PNP0B00", "AT Real-Time Clock"},
	{"PNP0C00", "Plug and Play BIOS (only created by the root enumerator)"},
	{"PNP0C01", "System Board"},
	{"PNP0C02", "General ID for reserving resources required by PnP motherboard registers. (Not device specific.)"},
	{"PNP0C03", "Plug and Play BIOS Event Notification Interrupt"},
	{"PNP0C04", "Math Coprocessor"},
	{"PNP0C05", "APM BIOS (Version independent)"},
	{"PNP0C06", "Reserved for identification of early Plug and Play BIOS implementation"},
	{"PNP0C07", "Reserved for identification of early Plug and Play BIOS implementation"},
	{"PNP0C08", "ACPI system board hardware"},
	{"PNP0C09", "ACPI Embedded Controller"},
	{"PNP0C0A", "ACPI Control Method Battery"},
	{"PNP0C0B", "ACPI Fan"},
	{"PNP0C0C", "ACPI power button device"},
	{"PNP0C0D", "ACPI lid device"},
	{"PNP0C0E", "ACPI sleep button device"},
	{"PNP0C0F", "PCI interrupt link device"},
	{"PNP0C10", "ACPI system indicator device"},
	{"PNP0C11", "ACPI thermal zone"},
	{"PNP0C12", "Device Bay Controller"},
	{"PNP0C13", "Plug and Play BIOS (used when ACPI mode cannot be used)"},
	{"PNP0CF0", "Compaq LTE Lite Support"},
	{"PNP0CF1", "Compaq LTE Elite Support"},
	/* PCMCIA controllers */
	{"PNP0E00", "Intel 82365-Compatible PCMCIA Controller"},
	{"PNP0E01", "Cirrus Logic CL-PD6720 PCMCIA Controller"},
	{"PNP0E02", "VLSI VL82C146 PCMCIA Controller"},
	{"PNP0E03", "Intel 82365-compatible CardBus controller"},
	/* mice */
	{"PNP0F00", "Microsoft Bus Mouse"},
	{"PNP0F01", "Microsoft Serial Mouse"},
	{"PNP0F02", "Microsoft InPort Mouse"},
	{"PNP0F03", "Microsoft PS/2-style Mouse"},
	{"PNP0F04", "Mouse Systems Mouse"},
	{"PNP0F05", "Mouse Systems 3-Button Mouse (COM2)"},
	{"PNP0F06", "Genius Mouse (COM1)"},
	{"PNP0F07", "Genius Mouse (COM2)"},
	{"PNP0F08", "Logitech Serial Mouse"},
	{"PNP0F09", "Microsoft BallPoint Serial Mouse"},
	{"PNP0F0A", "Microsoft Plug and Play Mouse"},
	{"PNP0F0B", "Microsoft Plug and Play BallPoint Mouse"},
	{"PNP0F0C", "Microsoft-compatible Serial Mouse"},
	{"PNP0F0D", "Microsoft-compatible InPort-compatible Mouse"},
	{"PNP0F0E", "Microsoft-compatible PS/2-style Mouse"},
	{"PNP0F0F", "Microsoft-compatible Serial BallPoint-compatible Mouse"},
	{"PNP0F10", "Texas Instruments QuickPort Mouse"},
	{"PNP0F11", "Microsoft-compatible Bus Mouse"},
	{"PNP0F12", "Logitech PS/2-style Mouse"},
	{"PNP0F13", "PS/2 Port for PS/2-style Mice"},
	{"PNP0F14", "Microsoft Kids Mouse"},
	{"PNP0F15", "Logitech bus mouse"},
	{"PNP0F16", "Logitech SWIFT device"},
	{"PNP0F17", "Logitech-compatible serial mouse"},
	{"PNP0F18", "Logitech-compatible bus mouse"},
	{"PNP0F19", "Logitech-compatible PS/2-style Mouse"},
	{"PNP0F1A", "Logitech-compatible SWIFT Device"},
	{"PNP0F1B", "HP Omnibook Mouse"},
	{"PNP0F1C", "Compaq LTE Trackball PS/2-style Mouse"},
	{"PNP0F1D", "Compaq LTE Trackball Serial Mouse"},
	{"PNP0F1E", "Microsoft Kids Trackball Mouse"},
	{"PNP0F1F", "Reserved by Microsoft Input Device Group"},
	{"PNP0F20", "Reserved by Microsoft Input Device Group"},
	{"PNP0F21", "Reserved by Microsoft Input Device Group"},
	{"PNP0F22", "Reserved by Microsoft Input Device Group"},
	{"PNP0F23", "Reserved by Microsoft Input Device Group"},
	{"PNP0FFF", "Reserved by Microsoft Systems"},
	{"PNP0XXX", "Unknown System Device"},
	/* network cards */
	{"PNP8000", "Network Adapter"},
	{"PNP8001", "Novell/Anthem NE3200"},
	{"PNP8004", "Compaq NE3200"},
	{"PNP8006", "Intel EtherExpress/32"},
	{"PNP8008", "HP EtherTwist EISA LAN Adapter/32 (HP27248A)"},
	{"PNP8065", "Ungermann-Bass NIUps or NIUps/EOTP"},
	{"PNP8072", "DEC (DE211) EtherWorks MC/TP"},
	{"PNP8073", "DEC (DE212) EtherWorks MC/TP_BNC"},
	{"PNP8074", "HP MC LAN Adapter/16 TP (PC27246)"},
	{"PNP8078", "DCA 10 Mb MCA"},
	{"PNP807F", "Racal NI9210"},
	{"PNP8081", "Pure Data Ethernet"},
	{"PNP8096", "Thomas-Conrad TC4046"},
	{"PNP80C9", "IBM Token Ring"},
	{"PNP80CA", "IBM Token Ring II"},
	{"PNP80CB", "IBM Token Ring II/Short"},
	{"PNP80CC", "IBM Token Ring 4/16Mbs"},
	{"PNP80D3", "Novell/Anthem NE1000"},
	{"PNP80D4", "Novell/Anthem NE2000"},
	{"PNP80D5", "NE1000 Compatible"},
	{"PNP80D6", "NE2000 Compatible"},
	{"PNP80D7", "Novell/Anthem NE1500T"},
	{"PNP80D8", "Novell/Anthem NE2100"},
	{"PNP80D9", "NE2000 Plus"},
	{"PNP80DD", "SMC ARCNETPC"},
	{"PNP80DE", "SMC ARCNET PC100, PC200"},
	{"PNP80DF", "SMC ARCNET PC110, PC210, PC250"},
	{"PNP80E0", "SMC ARCNET PC130/E"},
	{"PNP80E1", "SMC ARCNET PC120, PC220, PC260"},
	{"PNP80E2", "SMC ARCNET PC270/E"},
	{"PNP80E5", "SMC ARCNET PC600W, PC650W"},
	{"PNP80E7", "DEC DEPCA"},
	{"PNP80E8", "DEC (DE100) EtherWorks LC"},
	{"PNP80E9", "DEC (DE200) EtherWorks Turbo"},
	{"PNP80EA", "DEC (DE101) EtherWorks LC/TP"},
	{"PNP80EB", "DEC (DE201) EtherWorks Turbo/TP"},
	{"PNP80EC", "DEC (DE202) EtherWorks Turbo/TP_BNC"},
	{"PNP80ED", "DEC (DE102) EtherWorks LC/TP_BNC"},
	{"PNP80EE", "DEC EE101 (Built-In)"},
	{"PNP80EF", "DEC PC 433 WS (Built-In)"},
	{"PNP80F1", "3Com EtherLink Plus"},
	{"PNP80F3", "3Com EtherLink II or IITP (8 or 16-bit)"},
	{"PNP80F4", "3Com TokenLink"},
	{"PNP80F6", "3Com EtherLink 16"},
	{"PNP80F7", "3Com EtherLink III"},
	{"PNP80F8", "3Com Generic Etherlink Plug and Play Device"},
	{"PNP80FB", "Thomas Conrad TC6045"},
	{"PNP80FC", "Thomas Conrad TC6042"},
	{"PNP80FD", "Thomas Conrad TC6142"},
	{"PNP80FE", "Thomas Conrad TC6145"},
	{"PNP80FF", "Thomas Conrad TC6242"},
	{"PNP8100", "Thomas Conrad TC6245"},
	{"PNP8101", "Thomas-Conrad TC4045"},
	{"PNP8104", "Thomas-Conrad TC4035"},
	{"PNP8105", "DCA 10 MB"},
	{"PNP8106", "DCA 10 MB Fiber Optic"},
	{"PNP8107", "DCA 10 MB Twisted Pair"},
	{"PNP8113", "Racal NI6510"},
	{"PNP8114", "Racal NI5210/8 or NI5210/16"},
	{"PNP8119", "Ungermann-Bass pcNIU"},
	{"PNP811A", "Ungermann-Bass pcNIU/ex 128K"},
	{"PNP811B", "Ungermann-Bass pcNIU/ex 512K"}, 
	{"PNP811C", "Ungermann-Bass NIUpc"},
	{"PNP811D", "Ungermann-Bass NIUpc/3270"},
	{"PNP8120", "Ungermann-Bass NIUpc/EOTP"},
	{"PNP8123", "SMC StarCard PLUS (WD/8003S)"},
	{"PNP8124", "SMC StarCard PLUS With On Board Hub (WD/8003SH)"},
	{"PNP8125", "SMC EtherCard PLUS (WD/8003E)"},
	{"PNP8126", "SMC EtherCard PLUS With Boot ROM Socket (WD/8003EBT)"},
	{"PNP8127", "SMC EtherCard PLUS With Boot ROM Socket (WD/8003EB)"},
	{"PNP8128", "SMC EtherCard PLUS TP (WD/8003WT)"},
	{"PNP812A", "SMC EtherCard PLUS 16 With Boot ROM Socket (WD/8013EBT)"},
	{"PNP812D", "Intel EtherExpress 16 or 16TP"},
	{"PNP812F", "Intel TokenExpress 16/4"},
	{"PNP8130", "Intel TokenExpress MCA 16/4"},
	{"PNP8132", "Intel EtherExpress 16 (MCA)"},
	{"PNP8133", "Compaq Ethernet 16E"},
	{"PNP8137", "Artisoft AE-1"},
	{"PNP8138", "Artisoft AE-2 or AE-3"},
	{"PNP8141", "Amplicard AC 210/XT"},
	{"PNP8142", "Amplicard AC 210/AT"},
	{"PNP814B", "Everex SpeedLink /PC16 (EV2027)"},
	{"PNP8155", "HP PC LAN Adapter/8 TP (HP27245)"},
	{"PNP8156", "HP PC LAN Adapter/16 TP (HP27247A)"},
	{"PNP8157", "HP PC LAN Adapter/8 TL (HP27250)"},
	{"PNP8158", "HP PC LAN Adapter/16 TP Plus (HP27247B)"},
	{"PNP8159", "HP PC LAN Adapter/16 TL Plus (HP27252)"},
	{"PNP815F", "National Semiconductor Ethernode *16AT"},
	{"PNP8160", "National Semiconductor AT/LANTIC EtherNODE 16-AT3"},
	{"PNP8169", "NCR StarCard"},
	{"PNP816A", "NCR Token-Ring 4 Mbs ISA"},
	{"PNP816B", "NCR WaveLAN AT"},
	{"PNP816C", "NCR WaveLan MC"},
	{"PNP816D", "NCR Token-Ring 16/4 Mbs ISA"},
	{"PNP8191", "Olicom 16/4 Token-Ring Adapter"},
	{"PNP81A5", "Research Machines Ethernet"},
	{"PNP81B9", "ToshibaLAN (internal)"},
	{"PNP81C3", "SMC EtherCard PLUS Elite (WD/8003EP)"},
	{"PNP81C4", "SMC EtherCard PLUS 10T (WD/8003W)"},
	{"PNP81C5", "SMC EtherCard PLUS Elite 16 (WD/8013EP)"},
	{"PNP81C6", "SMC EtherCard PLUS Elite 16T (WD/8013W)"},
	{"PNP81C7", "SMC EtherCard PLUS Elite 16 Combo (WD/8013EW or 8013EWC)"},
	{"PNP81C8", "SMC EtherElite Ultra 16"},
	{"PNP81C9", "SMC TigerCard (8216L, 8216LC, 8216LT)"},
	{"PNP81CA", "SMC EtherEZ (8416)"},
	{"PNP81D7", "Madge Smart 16/4 PC Ringnode"},
	{"PNP81D8", "Madge Smart 16/4 Ringnode ISA"},
	{"PNP81E4", "Pure Data PDI9025-32 (Token Ring)"},
	{"PNP81E6", "Pure Data PDI508+ (ArcNet)"},
	{"PNP81E7", "Pure Data PDI516+ (ArcNet)"},
	{"PNP81EB", "Proteon Token Ring (P1390)"},
	{"PNP81EC", "Proteon Token Ring (P1392)"},
	{"PNP81ED", "Proteon Token Ring ISA (P1340)"},
	{"PNP81EE", "Proteon Token Ring ISA (P1342)"},
	{"PNP81EF", "Proteon Token Ring ISA (P1346)"},
	{"PNP81F0", "Proteon Token Ring ISA (P1347)"},
	{"PNP81FF", "Cabletron E2000 Series DNI"},
	{"PNP8200", "Cabletron E2100 Series DNI"},
	{"PNP8201", "Cabletron T2015 4/16 Mbit/s DNI"},
	{"PNP8209", "Zenith Data Systems Z-Note"},
	{"PNP820A", "Zenith Data Systems NE2000-Compatible"},
	{"PNP8213", "Xircom Pocket Ethernet II"},
	{"PNP8214", "Xircom Pocket Ethernet I"},
	{"PNP8215", "Xircom Pocket Ethernet III Adapter"},
	{"PNP821D", "RadiSys EXM-10"},
	{"PNP8227", "SMC 3000 Series"},
	{"PNP8228", "SMC 91C2 controller"},
	{"PNP8231", "AMD AM2100/AM1500T"},
	{"PNP824F", "RCE 10Base-T (16 bit)"},
	{"PNP8250", "RCE 10Base-T (8 bit)"},
	{"PNP8263", "Tulip NCC-16"},
	{"PNP8277", "Exos 105"},
	{"PNP828A", "Intel '595 based Ethernet"},
	{"PNP828B", "TI2000-style Token Ring"},
	{"PNP828C", "AMD PCNet Family cards"},
	{"PNP828D", "AMD PCNet32 (VL version)"},
	{"PNP8294", "IrDA Infrared NDIS driver (Microsoft-supplied)"},
	{"PNP82BD", "IBM PCMCIA-NIC"},
	{"PNP82C0", "Eagle Technology NE200T"},
	{"PNP82C2", "Xircom CE10"},
	{"PNP82C3", "Xircom CEM2"},
	{"PNP82C4", "Xircom CE2"},
	{"PNP8321", "DEC Ethernet (All Types)"},
	{"PNP8323", "SMC EtherCard (All Types except 8013/A)"},
	{"PNP8324", "ARCNET Compatible"},
	{"PNP8325", "SMC TokenCard PLUS (8115T)"},
	{"PNP8326", "Thomas Conrad (All Arcnet Types)"},
	{"PNP8327", "IBM Token Ring (All Types)"},
	{"PNP8328", "Ungermann-Bass NIU"},
	{"PNP8329", "Proteon ProNET-4/16 ISA Token Ring (P1392+,P1392,1390)"},
	{"PNP8385", "Remote Network Access [RNA] Driver"},
	{"PNP8387", "Remote Network Access [RNA] PPP Driver"},
	{"PNP8388", "Reserved for Microsoft Networking components"},
	{"PNP8389", "Peer IrLAN infrared driver (Microsoft-supplied)"},
	{"PNP8390", "Generic network adapter"},
	{"PNP8XXX", "Unknown Network Adapter"},
	/* modems */
	{"PNP9000", "Modem"},
	/* CD controller */
	{"PNPA000", "Adaptec 154x compatible SCSI controller"},
	{"PNPA001", "Adaptec 174x compatible SCSI controller"},
	{"PNPA002", "Future Domain 16-700 compatible controller"},
	{"PNPA003", "Mitsumi CD-ROM adapter (Panasonic spec., used on SBPro/SB16)"},
	{"PNPA01B", "Trantor 128 SCSI Controller"},
	{"PNPA01D", "Trantor T160 SCSI Controller"},
	{"PNPA01E", "Trantor T338 Parallel SCSI controller"},
	{"PNPA01F", "Trantor T348 Parallel SCSI controller"},
	{"PNPA020", "Trantor Media Vision SCSI controller"},
	{"PNPA022", "Always IN-2000 SCSI controller"},
	{"PNPA02B", "Sony proprietary CD-ROM controller"},
	{"PNPA02D", "Trantor T13b 8-bit SCSI controller"},
	{"PNPA02F", "Trantor T358 Parallel SCSI controller"},
	{"PNPA030", "Mitsumi LU-005 Single Speed CD-ROM controller + drive"},
	{"PNPA031", "Mitsumi FX-001 Single Speed CD-ROM controller + drive"},
	{"PNPA032", "Mitsumi FX-001 Double Speed CD-ROM controller + drive"},
	{"PNPAXXX", "Unknown SCSI, Proprietary CD Adapter"},
	/* multimedia devices */
	{"PNPB000", "Creative Labs Sound Blaster 1.5 (or compatible sound device)"},
	{"PNPB001", "Creative Labs Sound Blaster 2.0 (or compatible sound device)"},
	{"PNPB002", "Creative Labs Sound Blaster Pro (or compatible sound device)"},
	{"PNPB003", "Creative Labs Sound Blaster 16 (or compatible sound device)"},
	{"PNPB004", "MediaVision Thunderboard (or compatible sound device)"},
	{"PNPB005", "Adlib-compatible FM synthesizer device"},
	{"PNPB006", "MPU401 compatible"},
	{"PNPB007", "Microsoft Windows Sound System-compatible sound device"},
	{"PNPB008", "Compaq Business Audio"},
	{"PNPB009", "Plug and Play Microsoft Windows Sound System Device"},
	{"PNPB00A", "MediaVision Pro Audio Spectrum (Trantor SCSI enabled, Thunder Chip Disabled)"},
	{"PNPB00B", "MediaVision Pro Audio 3D"},
	{"PNPB00C", "MusicQuest MQX-32M"},
	{"PNPB00D", "MediaVision Pro Audio Spectrum Basic (No Trantor SCSI, Thunder Chip Enabled)"},
	{"PNPB00E", "MediaVision Pro Audio Spectrum (Trantor SCSI enabled, Thunder Chip Disabled)"},
	{"PNPB00F", "MediaVision Jazz-16 chipset (OEM Versions)"},
	{"PNPB010", "Orchid Videola - Auravision VxP500 chipset"},
	{"PNPB018", "MediaVision Pro Audio Spectrum 8-bit"},
	{"PNPB019", "MediaVision Pro Audio Spectrum Basic (No Trantor SCSI, Thunder Chip Enabled)"},
	{"PNPB020", "Yamaha OPL3-compatible FM synthesizer device"},
	{"PNPB02F", "Joystick/Game port"},
	{"PNPB077", "OAK Mozart Sound System"},
	{"PNPB078", "OAK Mozart Sound System MPU-401"},
	{"PNPBXXX", "Unknown Multimedia Device"},
	/* modems */
	{"PNPC000", "Compaq 14400 Modem (TBD)"},
	{"PNPC001", "Compaq 2400/9600 Modem (TBD)"},
	{"PNPCXXX", "Unknown Modem"},
	/* some other network cards */
	{"PNPD300", "SK-NET TR4/16+ Token-Ring"},
	{"PNPE000", "SK-NET G16, G16/TP Ethernet"},
	{"PNPF000", "SK-NET FDDI-FI FDDI LAN"},
	/* Toshiba devices */
	{"TOS6200", "Toshiba Notebook Extra HCI driver"},
	{"TOS6202", "Toshiba Notebook Extra HCI driver"},
	{"TOS6207", "Toshiba Notebook Extra HCI driver"},
	{"TOS7400", "Toshiba AcuPoint"},
	/* Wacom devices */
	{"WACf004", "Wacom Serial Tablet PC Pen Tablet/Digitizer"},
	{"WACf005", "Wacom Serial Tablet PC Pen Tablet/Digitizer"},
	{"WACf006", "Wacom Serial Tablet PC Pen Tablet/Digitizer"}
};

static int 
ids_comp_pnp(const void *id1, const void *id2) {
        struct pnp_id *pnp_id1 = (struct pnp_id *) id1;
        struct pnp_id *pnp_id2 = (struct pnp_id *) id2;
        return strcasecmp(pnp_id1->id, pnp_id2->id);
}

void
ids_find_pnp (const char *pnp_id, char **pnp_description)
{
	struct pnp_id search, *res;

        search.id = (char *) pnp_id;
        res = bsearch(&search, pnp_ids_list, sizeof(pnp_ids_list)/sizeof(pnp_ids_list[0]), 
		      sizeof(struct pnp_id), ids_comp_pnp);

        if (res != NULL)
        	*pnp_description = (char *) res->desc;
	else
        	*pnp_description = NULL; 
        return;
}

#endif /*USE_PNP_IDS*/

/*==========================================================================*/

void
ids_init (void)
{
	pci_ids_init ();
	usb_ids_init ();
}