1 /* $NetBSD: usbdevs.c,v 1.24 2005/05/08 08:12:45 augustss Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (augustss@NetBSD.org).
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/types.h>
40 #include <dev/usb/usb.h>
42 #define USBDEV "/dev/usb"
48 void usbdev(int f
, int a
, int rec
);
50 void dumpone(char *name
, int f
, int addr
);
51 int main(int, char **);
57 fprintf(stderr
, "usage: %s [-a addr] [-d] [-f dev] [-v]\n",
62 char done
[USB_MAX_DEVICES
];
66 usbdev(int f
, int a
, int rec
)
68 struct usb_device_info di
;
72 e
= ioctl(f
, USB_DEVICEINFO
, &di
);
75 printf("addr %d: I/O error\n", a
);
78 printf("addr %d: ", a
);
81 switch (di
.udi_speed
) {
82 case USB_SPEED_LOW
: printf("low speed, "); break;
83 case USB_SPEED_FULL
: printf("full speed, "); break;
84 case USB_SPEED_HIGH
: printf("high speed, "); break;
88 printf("power %d mA, ", di
.udi_power
);
90 printf("self powered, ");
92 printf("config %d, ", di
.udi_config
);
94 printf("unconfigured, ");
97 printf("%s(0x%04x), %s(0x%04x), rev %s",
98 di
.udi_product
, di
.udi_productNo
,
99 di
.udi_vendor
, di
.udi_vendorNo
, di
.udi_release
);
100 if (di
.udi_serial
[0])
101 printf(", serial %s", di
.udi_serial
);
103 printf("%s, %s", di
.udi_product
, di
.udi_vendor
);
106 for (i
= 0; i
< USB_MAX_DEVNAMES
; i
++)
107 if (di
.udi_devnames
[i
][0])
108 printf("%*s %s\n", indent
, "",
113 for (p
= 0; p
< di
.udi_nports
; p
++) {
114 int s
= di
.udi_ports
[p
];
115 if (s
>= USB_MAX_DEVICES
) {
117 printf("%*sport %d %s\n", indent
+1, "", p
+1,
118 s
== USB_PORT_ENABLED
? "enabled" :
119 s
== USB_PORT_SUSPENDED
? "suspended" :
120 s
== USB_PORT_POWERED
? "powered" :
121 s
== USB_PORT_DISABLED
? "disabled" :
128 printf("%*s", indent
, "");
130 printf("port %d ", p
+1);
132 printf("addr 0 should never happen!\n");
144 for (a
= 1; a
< USB_MAX_DEVICES
; a
++) {
151 dumpone(char *name
, int f
, int addr
)
154 printf("Controller %s:\n", name
);
156 memset(done
, 0, sizeof done
);
164 main(int argc
, char **argv
)
172 while ((ch
= getopt(argc
, argv
, "a:df:v?")) != -1) {
195 for (ncont
= 0, i
= 0; i
< 10; i
++) {
196 snprintf(buf
, sizeof(buf
), "%s%d", USBDEV
, i
);
197 f
= open(buf
, O_RDONLY
);
199 dumpone(buf
, f
, addr
);
202 if (errno
== ENOENT
|| errno
== ENXIO
)
208 if (verbose
&& ncont
== 0)
209 printf("%s: no USB controllers found\n",
212 f
= open(dev
, O_RDONLY
);
214 dumpone(dev
, f
, addr
);