/[soft]/ldetect/trunk/lspcidrake.c
ViewVC logotype

Contents of /ldetect/trunk/lspcidrake.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1357 - (show annotations) (download)
Tue May 17 09:21:22 2011 UTC (10 years, 1 month ago) by dmorgan
File MIME type: text/plain
File size: 3353 byte(s)
Import  ldetect
1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <getopt.h>
5 #include "libldetect.h"
6
7 static int verboze = 0;
8
9 static void printit(struct pciusb_entries entries, void print_class(unsigned long )) {
10 unsigned int i;
11 for (i = 0; i < entries.nb; i++) {
12 struct pciusb_entry *e = &entries.entries[i];
13 printf("%-16s: ", e->module ? e->module : "unknown");
14 if (e->text)
15 printf(e->text);
16 else printf("unknown (%04x/%04x/%04x/%04x)", e->vendor, e->device, e->subvendor, e->subdevice);
17 if (e->class_id) {
18 print_class(e->class_id);
19 }
20 if (verboze && e->text) {
21 printf(" (vendor:%04x device:%04x", e->vendor, e->device);
22 if (e->subvendor != 0xffff || e->subdevice != 0xffff)
23 printf(" subv:%04x subd:%04x", e->subvendor, e->subdevice);
24 printf(")");
25 }
26 if (e->pci_revision)
27 printf(" (rev: %02x)", e->pci_revision);
28 printf("\n");
29 }
30 pciusb_free(&entries);
31 }
32
33 static void print_pci_class(unsigned long class_id) {
34 const char *s = pci_class2text(class_id);
35 if (strcmp(s, "NOT_DEFINED") != 0)
36 printf(" [%s]", s);
37 }
38
39 static void print_usb_class(unsigned long class_id) {
40 struct usb_class_text s = usb_class2text(class_id);
41 if (s.usb_class_text) {
42 printf(" [");
43 printf("%s", s.usb_class_text);
44 if (s.usb_sub_text) printf("|%s", s.usb_sub_text);
45 if (s.usb_prot_text) printf("|%s", s.usb_prot_text);
46 printf("]");
47 }
48 }
49
50 static void print_dmi_entries(struct dmi_entries entries) {
51 unsigned int i;
52 for (i = 0; i < entries.nb; i++)
53 printf("%-16s: %s\n", entries.entries[i].module, entries.entries[i].constraints);
54 }
55
56 static void print_hid_entries(struct hid_entries entries) {
57 unsigned int i;
58 for (i = 0; i < entries.nb; i++)
59 printf("%-16s: %s\n", entries.entries[i].module,
60 entries.entries[i].text);
61 }
62
63 static void usage(void)
64 {
65 printf(
66 "usage: lspcidrake [options]\n"
67 "\t-p, --pci-file <file>\tPCI devices source [/proc/bus/pci/devices by default]\n"
68 "\t-u, --usb-file <file>\tUSB devices source [/proc/bus/usb/devices by default]\n"
69 "\t-v, --verbose\t\tVerbose mode [print ids and sub-ids], implies full probe\n"
70 "\t-d, --dmidecode <file>\tTo use this dmidecode output instead of calling demicode\n");
71 }
72
73 int main(int argc, char **argv) {
74 int opt, fake = 0;
75 struct option options[] = { { "verbose", 0, NULL, 'v' },
76 { "pci-file", 1, NULL, 'p' },
77 { "usb-file", 1, NULL, 'u' },
78 { "dmidecode", 0, NULL, 'd' },
79 { NULL, 0, NULL, 0 } };
80
81 while ((opt = getopt_long(argc, argv, "vp:u:d", options, NULL)) != -1) {
82 switch (opt) {
83 case 'v':
84 verboze = 1;
85 break;
86 case 'p':
87 proc_pci_path = optarg;
88 fake = 1;
89 break;
90 case 'u':
91 proc_usb_path = optarg;
92 fake = 1;
93 break;
94 case 'd':
95 dmidecode_file = optarg;
96 fake = 1;
97 break;
98 default:
99 usage();
100 return 1;
101 }
102 }
103
104 if (!fake || proc_pci_path) printit(pci_probe(), print_pci_class);
105 if (!fake || proc_usb_path) printit(usb_probe(), print_usb_class);
106
107 if (!fake && geteuid() == 0 || dmidecode_file) {
108 struct dmi_entries dmi_entries = dmi_probe();
109 print_dmi_entries(dmi_entries);
110 dmi_entries_free(dmi_entries);
111 }
112
113 if (!fake || sysfs_hid_path) {
114 struct hid_entries hid_entries = hid_probe();
115 print_hid_entries(hid_entries);
116 hid_entries_free(&hid_entries);
117 }
118
119 return 0;
120 }

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.28