1 /* $NetBSD: usbdevs.c,v 1.17 2001/02/19 23:22:48 cgd Exp $ */
2 /* $FreeBSD: src/usr.sbin/usbdevs/usbdevs.c,v 1.5.2.3 2002/11/13 15:15:21 joe Exp $ */
3 /* $DragonFly: src/usr.sbin/usbdevs/usbdevs.c,v 1.2 2003/06/17 04:30:03 dillon Exp $ */
6 * Copyright (c) 1998 The NetBSD Foundation, Inc.
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Lennart Augustsson (augustss@netbsd.org).
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
44 #include <sys/types.h>
49 #include <dev/usb/usb.h>
50 #if defined(__FreeBSD__)
51 #include <sys/ioctl.h>
54 #define USBDEV "/dev/usb"
60 void usbdev(int f, int a, int rec);
62 void dumpone(char *name, int f, int addr);
63 int main(int, char **);
68 fprintf(stderr, "Usage: %s [-a addr] [-d] [-f dev] [-v]\n",
73 char done[USB_MAX_DEVICES];
77 usbdev(int f, int a, int rec)
79 struct usb_device_info di;
83 e = ioctl(f, USB_DEVICEINFO, &di);
86 printf("addr %d: I/O error\n", a);
89 printf("addr %d: ", a);
93 printf("low speed, ");
95 printf("power %d mA, ", di.udi_power);
97 printf("self powered, ");
99 printf("config %d, ", di.udi_config);
101 printf("unconfigured, ");
104 printf("%s(0x%04x), %s(0x%04x), rev %s",
105 di.udi_product, di.udi_productNo,
106 di.udi_vendor, di.udi_vendorNo, di.udi_release);
108 printf("%s, %s", di.udi_product, di.udi_vendor);
111 for (i = 0; i < USB_MAX_DEVNAMES; i++)
112 if (di.udi_devnames[i][0])
113 printf("%*s %s\n", indent, "",
118 for (p = 0; p < di.udi_nports; p++) {
119 int s = di.udi_ports[p];
120 if (s >= USB_MAX_DEVICES) {
122 printf("%*sport %d %s\n", indent+1, "", p+1,
123 s == USB_PORT_ENABLED ? "enabled" :
124 s == USB_PORT_SUSPENDED ? "suspended" :
125 s == USB_PORT_POWERED ? "powered" :
126 s == USB_PORT_DISABLED ? "disabled" :
133 printf("%*s", indent, "");
135 printf("port %d ", p+1);
137 printf("addr 0 should never happen!\n");
149 for (a = 1; a < USB_MAX_DEVICES; a++) {
156 dumpone(char *name, int f, int addr)
159 printf("Controller %s:\n", name);
161 memset(done, 0, sizeof done);
169 main(int argc, char **argv)
177 while ((ch = getopt(argc, argv, "a:df:v?")) != -1) {
200 for (ncont = 0, i = 0; i < 10; i++) {
201 sprintf(buf, "%s%d", USBDEV, i);
202 f = open(buf, O_RDONLY);
204 dumpone(buf, f, addr);
207 if (errno == ENOENT || errno == ENXIO)
213 if (verbose && ncont == 0)
214 printf("%s: no USB controllers found\n",
217 f = open(dev, O_RDONLY);
219 dumpone(dev, f, addr);