diff options
author | joe <joe@FreeBSD.org> | 2002-02-16 16:16:12 +0000 |
---|---|---|
committer | joe <joe@FreeBSD.org> | 2002-02-16 16:16:12 +0000 |
commit | 16e403b1a10e182711fe8df83d64db848633d78f (patch) | |
tree | a9069873e11e93937cdd42f748b49295ca0a377e /usr.sbin/usbdevs/usbdevs.c | |
parent | a6fbc8577e59b0369bb7a6af91e8b6a4a20829a2 (diff) | |
download | FreeBSD-src-16e403b1a10e182711fe8df83d64db848633d78f.zip FreeBSD-src-16e403b1a10e182711fe8df83d64db848633d78f.tar.gz |
Merge from NetBSD:
* Add a -d flag to show the device drivers associated with each device.
* Update to use the new speed structure entry.
Diffstat (limited to 'usr.sbin/usbdevs/usbdevs.c')
-rw-r--r-- | usr.sbin/usbdevs/usbdevs.c | 88 |
1 files changed, 49 insertions, 39 deletions
diff --git a/usr.sbin/usbdevs/usbdevs.c b/usr.sbin/usbdevs/usbdevs.c index 09c754b..26196ec 100644 --- a/usr.sbin/usbdevs/usbdevs.c +++ b/usr.sbin/usbdevs/usbdevs.c @@ -1,4 +1,4 @@ -/* $NetBSD: usbdevs.c,v 1.4 1998/07/23 13:57:51 augustss Exp $ */ +/* $NetBSD: usbdevs.c,v 1.17 2001/02/19 23:22:48 cgd Exp $ */ /* $FreeBSD$ */ /* @@ -52,20 +52,20 @@ #define USBDEV "/dev/usb" -int verbose; +int verbose = 0; +int showdevs = 0; -void usage __P((void)); -void usbdev __P((int f, int a, int rec)); -void usbdump __P((int f)); -void dumpone __P((char *name, int f, int addr)); -int main __P((int, char **)); - -extern char *__progname; +void usage(void); +void usbdev(int f, int a, int rec); +void usbdump(int f); +void dumpone(char *name, int f, int addr); +int main(int, char **); void usage() { - fprintf(stderr, "Usage: %s [-a addr] [-f dev] [-v]\n", __progname); + fprintf(stderr, "Usage: %s [-a addr] [-d] [-f dev] [-v]\n", + getprogname()); exit(1); } @@ -73,23 +73,27 @@ char done[USB_MAX_DEVICES]; int indent; void -usbdev(f, a, rec) - int f; - int a; - int rec; +usbdev(int f, int a, int rec) { struct usb_device_info di; - int e, p; + int e, p, i; di.addr = a; e = ioctl(f, USB_DEVICEINFO, &di); - if (e) + if (e) { + if (errno != ENXIO) + printf("addr %d: I/O error\n", a); return; + } + printf("addr %d: ", a); done[a] = 1; - printf("addr %d: ", di.addr); if (verbose) { - if (di.lowspeed) - printf("low speed, "); + switch (di.speed) { + case USB_SPEED_LOW: printf("low speed, "); break; + case USB_SPEED_FULL: printf("full speed, "); break; + case USB_SPEED_HIGH: printf("high speed, "); break; + default: break; + } if (di.power) printf("power %d mA, ", di.power); else @@ -100,12 +104,18 @@ usbdev(f, a, rec) printf("unconfigured, "); } if (verbose) { - printf("%s(0x%04x), %s(0x%04x), rev 0x%04x", - di.product, di.productNo, - di.vendor, di.vendorNo, di.releaseNo); + printf("%s(0x%04x), %s(0x%04x), rev %s", + di.product, di.productNo, + di.vendor, di.vendorNo, di.release); } else printf("%s, %s", di.product, di.vendor); printf("\n"); + if (showdevs) { + for (i = 0; i < USB_MAX_DEVNAMES; i++) + if (di.devnames[i][0]) + printf("%*s %s\n", indent, "", + di.devnames[i]); + } if (!rec) return; for (p = 0; p < di.nports; p++) { @@ -126,14 +136,16 @@ usbdev(f, a, rec) printf("%*s", indent, ""); if (verbose) printf("port %d ", p+1); - usbdev(f, di.ports[p], 1); + if (s == 0) + printf("addr 0 should never happen!\n"); + else + usbdev(f, s, 1); indent--; } } void -usbdump(f) - int f; +usbdump(int f) { int a; @@ -144,10 +156,7 @@ usbdump(f) } void -dumpone(name, f, addr) - char *name; - int f; - int addr; +dumpone(char *name, int f, int addr) { if (verbose) printf("Controller %s:\n", name); @@ -160,23 +169,22 @@ dumpone(name, f, addr) } int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { int ch, i, f; char buf[50]; - extern int optind; - extern char *optarg; char *dev = 0; int addr = 0; int ncont; - while ((ch = getopt(argc, argv, "a:f:v")) != -1) { + while ((ch = getopt(argc, argv, "a:df:v?")) != -1) { switch(ch) { case 'a': addr = atoi(optarg); break; + case 'd': + showdevs++; + break; case 'f': dev = optarg; break; @@ -196,16 +204,18 @@ main(argc, argv) sprintf(buf, "%s%d", USBDEV, i); f = open(buf, O_RDONLY); if (f >= 0) { - ncont++; dumpone(buf, f, addr); close(f); } else { - if (errno == EACCES) - warn("%s", buf); + if (errno == ENOENT || errno == ENXIO) + continue; + warn("%s", buf); } + ncont++; } if (verbose && ncont == 0) - printf("%s: no USB controllers found\n", __progname); + printf("%s: no USB controllers found\n", + getprogname()); } else { f = open(dev, O_RDONLY); if (f >= 0) |