1 /* $NetBSD: usbdevs.c,v 1.22 2003/11/12 13:31:08 grant 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.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/types.h>
41 #include <dev/usb/usb.h>
42 #if defined(__FreeBSD__)
43 #include <sys/ioctl.h>
46 #define USBDEV "/dev/usb"
53 void usbdev(int f, int a, int rec);
55 void dumpone(char *name, int f, int addr);
56 int main(int, char **);
61 fprintf(stderr, "usage: %s [-a addr] [-d] [-f dev] [-o] [-v]\n",
66 char done[USB_MAX_DEVICES];
70 usbdev(int f, int a, int rec)
72 struct usb_device_info di;
76 e = ioctl(f, USB_DEVICEINFO, &di);
79 printf("addr %d: I/O error\n", a);
82 printf("addr %d: ", a);
85 switch (di.udi_speed) {
86 case USB_SPEED_LOW: printf("low speed, "); break;
87 case USB_SPEED_FULL: printf("full speed, "); break;
88 case USB_SPEED_HIGH: printf("high speed, "); break;
92 printf("power %d mA, ", di.udi_power);
94 printf("self powered, ");
96 printf("config %d, ", di.udi_config);
98 printf("unconfigured, ");
101 printf("%s(0x%04x), %s(0x%04x), rev %s",
102 di.udi_product, di.udi_productNo,
103 di.udi_vendor, di.udi_vendorNo, di.udi_release);
105 printf("%s, %s", di.udi_product, di.udi_vendor);
109 for (i = 0; i < USB_MAX_DEVNAMES; i++) {
110 if (di.udi_devnames[i][0]) {
112 printf(", device %s",
115 printf("%*s %s\n", indent, "",
124 for (p = 0; p < di.udi_nports; p++) {
125 int s = di.udi_ports[p];
126 if (s >= USB_MAX_DEVICES) {
128 printf("%*sport %d %s\n", indent+1, "", p+1,
129 s == USB_PORT_ENABLED ? "enabled" :
130 s == USB_PORT_SUSPENDED ? "suspended" :
131 s == USB_PORT_POWERED ? "powered" :
132 s == USB_PORT_DISABLED ? "disabled" :
139 printf("%*s", indent, "");
141 printf("port %d ", p+1);
143 printf("addr 0 should never happen!\n");
155 for (a = 1; a < USB_MAX_DEVICES; a++) {
162 dumpone(char *name, int f, int addr)
165 printf("Controller %s:\n", name);
167 memset(done, 0, sizeof done);
175 main(int argc, char **argv)
183 while ((ch = getopt(argc, argv, "a:df:ov?")) != -1) {
209 for (ncont = 0, i = 0; i < 10; i++) {
210 snprintf(buf, sizeof(buf), "%s%d", USBDEV, i);
211 f = open(buf, O_RDONLY);
213 dumpone(buf, f, addr);
216 if (errno == ENOENT || errno == ENXIO)
222 if (verbose && ncont == 0)
223 printf("%s: no USB controllers found\n",
226 f = open(dev, O_RDONLY);
228 dumpone(dev, f, addr);