Debian Codegraph @

xpp/xtalk/xusb_test_bypath.c

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <xtalk/debug.h>
5 #include <xtalk/xusb.h>
6 #include <autoconfig.h>
7
8 static char *progname;
9
10 static void usage()
11 {
12 fprintf(stderr, "Usage: %s [options...] <busnum>/<devnum> ...\n", progname);
13 fprintf(stderr, "\tOptions:\n");
14 fprintf(stderr, "\t\t[-v] # Increase verbosity\n");
15 fprintf(stderr,
16 "\t\t[-d mask] # Debug mask (0xFF for everything)\n");
17 exit(1);
18 }
19
20 static int check_devpath(const char *devpath)
21 {
22 const struct xusb_spec *spec;
23 struct xusb_device *xusb_dev;
24 struct xusb_iface *iface;
25 int ret;
26
27 printf("Checking %s: ", devpath);
28 fflush(stdout);
29 xusb_dev = xusb_find_bypath(devpath);
30 if (!xusb_dev) {
31 ERR("missing %s\n", devpath);
32 return 1;
33 }
34 spec = xusb_device_spec(xusb_dev);
35 printf("Found: %04x:%04x\n", spec->vendor_id, spec->product_id);
36 ret = xusb_claim(xusb_dev, 1, &iface);
37 if (ret < 0) {
38 ERR("%s: xusb_claim() failed (ret = %d)\n",
39 xusb_devpath(xusb_dev), ret);
40 return 1;
41 }
42 xusb_showinfo(xusb_dev);
43 xusb_release(iface);
44 return 1;
45 }
46
47 int main(int argc, char *argv[])
48 {
49 const char options[] = "vd:";
50 int i;
51
52 progname = argv[0];
53 while (1) {
54 int c;
55
56 c = getopt(argc, argv, options);
57 if (c == -1)
58 break;
59
60 switch (c) {
61 case 'v':
62 verbose++;
63 break;
64 case 'd':
65 debug_mask = strtoul(optarg, NULL, 0);
66 break;
67 case 'h':
68 default:
69 ERR("Unknown option '%c'\n", c);
70 usage();
71 }
72 }
73 for (i = optind; i < argc; i++)
74 check_devpath(argv[i]);
75 return 0;
76 }