2 * $NetBSD: usbdevs.c,v 1.17 2001/02/19 23:22:48 cgd Exp $
3 * $FreeBSD: src/usr.sbin/usbdevs/usbdevs.c,v 1.8 2002/04/22 13:44:47 des Exp $
4 * $DragonFly: src/usr.sbin/usbdevs/usbdevs.c,v 1.7 2005/12/05 01:23:23 swildner Exp $
8 * Copyright (c) 1998 The NetBSD Foundation, Inc.
11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Lennart Augustsson (augustss@netbsd.org).
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the NetBSD
25 * Foundation, Inc. and its contributors.
26 * 4. Neither the name of The NetBSD Foundation nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
34 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
46 #include <sys/types.h>
51 #include <bus/usb/usb.h>
52 #if defined(__DragonFly__)
53 #include <sys/ioctl.h>
56 #define USBDEV "/dev/usb"
62 void usbdev(int f
, int a
, int rec
);
64 void dumpone(char *name
, int f
, int addr
);
65 int main(int, char **);
70 fprintf(stderr
, "usage: %s [-a addr] [-d] [-f dev] [-v]\n",
75 char done
[USB_MAX_DEVICES
];
79 usbdev(int f
, int a
, int rec
)
81 struct usb_device_info di
;
85 e
= ioctl(f
, USB_DEVICEINFO
, &di
);
88 printf("addr %d: I/O error\n", a
);
91 printf("addr %d: ", a
);
94 switch (di
.udi_speed
) {
95 case USB_SPEED_LOW
: printf("low speed, "); break;
96 case USB_SPEED_FULL
: printf("full speed, "); break;
97 case USB_SPEED_HIGH
: printf("high speed, "); break;
101 printf("power %d mA, ", di
.udi_power
);
103 printf("self powered, ");
105 printf("config %d, ", di
.udi_config
);
107 printf("unconfigured, ");
110 printf("%s(0x%04x), %s(0x%04x), rev %s",
111 di
.udi_product
, di
.udi_productNo
,
112 di
.udi_vendor
, di
.udi_vendorNo
, di
.udi_release
);
114 printf("%s, %s", di
.udi_product
, di
.udi_vendor
);
117 for (i
= 0; i
< USB_MAX_DEVNAMES
; i
++)
118 if (di
.udi_devnames
[i
][0])
119 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:v")) != -1) {
205 for (ncont
= 0, i
= 0; i
< 10; i
++) {
206 sprintf(buf
, "%s%d", USBDEV
, i
);
207 f
= open(buf
, O_RDONLY
);
209 dumpone(buf
, f
, addr
);
212 if (errno
== ENOENT
|| errno
== ENXIO
)
218 if (verbose
&& ncont
== 0)
219 printf("%s: no USB controllers found\n",
222 f
= open(dev
, O_RDONLY
);
224 dumpone(dev
, f
, addr
);