| 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...] -D <device> [hexnum ....]\n", |
| 13 |
progname); |
| 14 |
fprintf(stderr, "\tOptions:\n"); |
| 15 |
fprintf(stderr, "\t\t[-v] # Increase verbosity\n"); |
| 16 |
fprintf(stderr, |
| 17 |
"\t\t[-d mask] # Debug mask (0xFF for everything)\n"); |
| 18 |
fprintf(stderr, "\tDevice:\n"); |
| 19 |
fprintf(stderr, "\t\t/proc/bus/usb/<bus>/<dev>\n"); |
| 20 |
fprintf(stderr, "\t\t/dev/bus/usb/<bus>/<dev>\n"); |
| 21 |
exit(1); |
| 22 |
} |
| 23 |
|
| 24 |
static void xusb_destructor(void *data) |
| 25 |
{ |
| 26 |
struct xusb_device *xusb_device = data; |
| 27 |
xusb_destroy(xusb_device); |
| 28 |
} |
| 29 |
|
| 30 |
#define XUSB_IFACE_DESC(p, i, d) \ |
| 31 |
{ SPEC_HEAD(0xe4e4, (p), (d)), (i) } |
| 32 |
|
| 33 |
static struct xusb_iface_description { |
| 34 |
struct xusb_spec spec; |
| 35 |
int interface_num; |
| 36 |
} test_specs[] = { |
| 37 |
/* 115x */ |
| 38 |
XUSB_IFACE_DESC(0x1150, 1, "old-astribank-NOFW"), |
| 39 |
XUSB_IFACE_DESC(0x1151, 1, "old-astribank-USB"), |
| 40 |
XUSB_IFACE_DESC(0x1152, 1, "old-astribank-FPGA"), |
| 41 |
|
| 42 |
/* 116x */ |
| 43 |
XUSB_IFACE_DESC(0x1160, 1, "astribank2-NOFW"), |
| 44 |
XUSB_IFACE_DESC(0x1161, 1, "astribank2-USB"), |
| 45 |
XUSB_IFACE_DESC(0x1162, 1, "astribank2-FPGA"), |
| 46 |
XUSB_IFACE_DESC(0x1163, 1, "astribank2-TWINSTAR"), |
| 47 |
XUSB_IFACE_DESC(0x1191, 1, "xpanel"), |
| 48 |
XUSB_IFACE_DESC(0x1183, 1, "multi-ps"), |
| 49 |
XUSB_IFACE_DESC(0x11a3, 0, "auth-dongle"), |
| 50 |
XUSB_IFACE_DESC(0xbb01, 0, "iwc"), |
| 51 |
{}, |
| 52 |
}; |
| 53 |
|
| 54 |
static int run_spec(int i, xusb_filter_t filter, char *devpath) |
| 55 |
{ |
| 56 |
struct xusb_iface_description *desc = &test_specs[i]; |
| 57 |
struct xusb_spec *s = &desc->spec; |
| 58 |
struct xlist_node *xlist; |
| 59 |
struct xlist_node *curr; |
| 60 |
int interface_num = desc->interface_num; |
| 61 |
int num_devs; |
| 62 |
|
| 63 |
if (!s->name) |
| 64 |
return 0; |
| 65 |
xlist = xusb_find_byproduct(s, 1, filter, devpath); |
| 66 |
num_devs = (xlist) ? xlist_length(xlist) : 0; |
| 67 |
INFO("total %d devices of type %s (interface=%d)\n", |
| 68 |
num_devs, s->name, interface_num); |
| 69 |
for (curr = xlist_shift(xlist); curr; curr = xlist_shift(xlist)) { |
| 70 |
struct xusb_device *xusb_device; |
| 71 |
struct xusb_iface *iface; |
| 72 |
int ret; |
| 73 |
|
| 74 |
xusb_device = curr->data; |
| 75 |
ret = xusb_claim(xusb_device, interface_num, &iface); |
| 76 |
if (ret < 0) { |
| 77 |
ERR("%s: xusb_claim() failed (ret = %d)\n", |
| 78 |
xusb_devpath(xusb_device), ret); |
| 79 |
continue; |
| 80 |
} |
| 81 |
xusb_showinfo(xusb_device); |
| 82 |
xusb_release(iface); |
| 83 |
} |
| 84 |
xlist_destroy(xlist, xusb_destructor); |
| 85 |
return 1; |
| 86 |
} |
| 87 |
|
| 88 |
int main(int argc, char *argv[]) |
| 89 |
{ |
| 90 |
char *devpath = NULL; |
| 91 |
const char options[] = "vd:D:EFp"; |
| 92 |
xusb_filter_t filter = NULL; |
| 93 |
int i; |
| 94 |
|
| 95 |
progname = argv[0]; |
| 96 |
while (1) { |
| 97 |
int c; |
| 98 |
|
| 99 |
c = getopt(argc, argv, options); |
| 100 |
if (c == -1) |
| 101 |
break; |
| 102 |
|
| 103 |
switch (c) { |
| 104 |
case 'D': |
| 105 |
devpath = optarg; |
| 106 |
filter = xusb_filter_bypath; |
| 107 |
break; |
| 108 |
case 'v': |
| 109 |
verbose++; |
| 110 |
break; |
| 111 |
case 'd': |
| 112 |
debug_mask = strtoul(optarg, NULL, 0); |
| 113 |
break; |
| 114 |
case 'h': |
| 115 |
default: |
| 116 |
ERR("Unknown option '%c'\n", c); |
| 117 |
usage(); |
| 118 |
} |
| 119 |
} |
| 120 |
i = 0; |
| 121 |
while (run_spec(i, filter, devpath)) |
| 122 |
i++; |
| 123 |
return 0; |
| 124 |
} |