Merge from NetBSD:
* Add a -d flag to show the device drivers associated with each device. * Update to use the new speed structure entry.
This commit is contained in:
parent
9c564b6c92
commit
8c1dde21a3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=90733
@ -1,5 +1,5 @@
|
||||
.\" $NetBSD: usbdevs.8,v 1.3 1998/07/23 13:57:51 augustss Exp $
|
||||
.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
.\" $NetBSD: usbdevs.8,v 1.5 2000/10/15 12:44:11 bjh21 Exp $
|
||||
.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Author: Lennart Augustsson
|
||||
@ -34,7 +34,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd July 12, 1998
|
||||
.Dd October 15, 2000
|
||||
.Dt USBDEVS 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -43,6 +43,7 @@
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl a Ar addr
|
||||
.Op Fl d
|
||||
.Op Fl f Ar dev
|
||||
.Op Fl v
|
||||
.Sh DESCRIPTION
|
||||
@ -52,9 +53,11 @@ with some information about each device.
|
||||
The indentation of each line indicates its distance from the root.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.Bl -tag -width Fl
|
||||
.It Fl a Ar addr
|
||||
only print information about the device at the given address.
|
||||
.It Fl d
|
||||
Show the device drivers associated with each device.
|
||||
.It Fl f Ar dev
|
||||
only print information for the given USB controller.
|
||||
.It Fl v
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user