summaryrefslogtreecommitdiffstats
path: root/lspcidrake.c
blob: f1b11fe0c0da9ecbcde45ab4828a084d6fac6609 (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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libldetect.h"

int verboze = 0;
int full_probe = 0;

void usage(void) {
	printf("usage: lspcidrake [-v] [-f]\n");
	exit(0);
}

void print_name(struct pciusb_entry *e) {
	printf("%-16s: ", e->module ? e->module : "unknown");
	if (e->text)
		printf(e->text);
	else	printf("unknown (%04x/%04x/%04x/%04x)", e->vendor, e->device, e->subvendor, e->subdevice);
}

void print_id(struct pciusb_entry *e) {
	if (verboze && e->text) {
		printf(" (vendor:%04x device:%04x", e->vendor, e->device);
		if (e->subvendor != 0xffff || e->subdevice != 0xffff)
			printf(" subv:%04x subd:%04x", e->subvendor, e->subdevice);
		printf(")");
	}
}

void pci_printit(struct pciusb_entries *entries) {
	unsigned int i;
	for (i = 0; i < entries->nb; i++) {
		struct pciusb_entry *e = &entries->entries[i];
		print_name(e);
		if (e->class_) {
			const char *class_ = pci_class2text(e->class_);
			if (strcmp(class_, "NOT_DEFINED") != 0) printf(" [%s]", class_);
		}
		print_id(e);
		printf("\n");
	}
}

void usb_printit(struct pciusb_entries *entries) {
	unsigned int i;
	for (i = 0; i < entries->nb; i++) {
		struct pciusb_entry *e = &entries->entries[i];
		print_name(e);
		if (e->class_) 
			printf(" [%s]", usb_class2text(e->class_));
		print_id(e);
		printf("\n");
	}
}

int main(int argc, char **argv) {
	char ** ptr = argv;
	while (ptr && *ptr) {
		if (!strcmp(*ptr, "-h") || !strcmp(*ptr, "--help"))
			usage();
		if (!strcmp(*ptr, "-v")) {
			verboze = 1;
			full_probe = 1;
		}
		if (!strcmp(*ptr, "-f"))
			full_probe = 1;
		ptr++;
	}

	struct pciusb_entries entries = pci_probe(full_probe);
	pci_printit(&entries);
	pciusb_free(&entries);

	entries = usb_probe();
	usb_printit(&entries);
	pciusb_free(&entries);
	exit(0);
}