1 /* $NetBSD: usbdevs.c,v 1.4 1998/07/23 13:57:51 augustss Exp $ */
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (augustss@netbsd.org).
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
43 #include <sys/types.h>
48 #include <dev/usb/usb.h>
49 #if defined(__FreeBSD__)
50 #include <sys/ioctl.h>
53 #define USBDEV "/dev/usb"
57 void usage __P((void));
58 void usbdev __P((int f, int a, int rec));
59 void usbdump __P((int f));
60 void dumpone __P((char *name, int f, int addr));
61 int main __P((int, char **));
63 extern char *__progname;
68 fprintf(stderr, "Usage: %s [-a addr] [-f dev] [-v]\n", __progname);
72 char done[USB_MAX_DEVICES];
81 struct usb_device_info di;
85 e = ioctl(f, USB_DEVICEINFO, &di);
89 printf("addr %d: ", di.addr);
92 printf("low speed, ");
94 printf("power %d mA, ", di.power);
96 printf("self powered, ");
98 printf("config %d, ", di.config);
100 printf("unconfigured, ");
103 printf("%s(0x%04x), %s(0x%04x), rev 0x%04x",
104 di.product, di.productNo,
105 di.vendor, di.vendorNo, di.releaseNo);
107 printf("%s, %s", di.product, di.vendor);
111 for (p = 0; p < di.nports; p++) {
113 if (s >= USB_MAX_DEVICES) {
115 printf("%*sport %d %s\n", indent+1, "", p+1,
116 s == USB_PORT_ENABLED ? "enabled" :
117 s == USB_PORT_SUSPENDED ? "suspended" :
118 s == USB_PORT_POWERED ? "powered" :
119 s == USB_PORT_DISABLED ? "disabled" :
126 printf("%*s", indent, "");
128 printf("port %d ", p+1);
129 usbdev(f, di.ports[p], 1);
140 for (a = 1; a < USB_MAX_DEVICES; a++) {
147 dumpone(name, f, addr)
153 printf("Controller %s:\n", name);
155 memset(done, 0, sizeof done);
175 while ((ch = getopt(argc, argv, "a:f:v")) != -1) {
195 for (ncont = 0, i = 0; i < 10; i++) {
196 sprintf(buf, "%s%d", USBDEV, i);
197 f = open(buf, O_RDONLY);
200 dumpone(buf, f, addr);
207 if (verbose && ncont == 0)
208 printf("%s: no USB controllers found\n", __progname);
210 f = open(dev, O_RDONLY);
212 dumpone(dev, f, addr);