summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorn_hibma <n_hibma@FreeBSD.org>1998-11-26 23:13:13 +0000
committern_hibma <n_hibma@FreeBSD.org>1998-11-26 23:13:13 +0000
commit1f1ab4819c23e37e12cd77a9f862f0b56a026bd6 (patch)
tree34b8718ca7c243ba6fca181b98eb980de3d02aca /usr.sbin
parentcb434691d915a69b39259cd29b94ec59672a7ca3 (diff)
downloadFreeBSD-src-1f1ab4819c23e37e12cd77a9f862f0b56a026bd6.zip
FreeBSD-src-1f1ab4819c23e37e12cd77a9f862f0b56a026bd6.tar.gz
Initial commit of ported NetBSD USB stack
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/usbd/Makefile15
-rw-r--r--usr.sbin/usbd/usbd.880
-rw-r--r--usr.sbin/usbd/usbd.c183
-rw-r--r--usr.sbin/usbdevs/Makefile8
-rw-r--r--usr.sbin/usbdevs/usbdevs.867
-rw-r--r--usr.sbin/usbdevs/usbdevs.c212
6 files changed, 565 insertions, 0 deletions
diff --git a/usr.sbin/usbd/Makefile b/usr.sbin/usbd/Makefile
new file mode 100644
index 0000000..0c74ed5
--- /dev/null
+++ b/usr.sbin/usbd/Makefile
@@ -0,0 +1,15 @@
+# FIXME have a look at all the other files and align it
+
+PROG= usbd
+MAN= usbd.8
+
+# for FreeBSD we need MAN8 instead of MAN
+MAN8= usbd.8
+
+# This hard coded path is not necessary as soon as we are in the
+# base FreeBSD system. The .h files will be in /usr/include by then.
+#
+CFLAGS += -I../../sys
+
+.include <bsd.prog.mk>
+.include <bsd.subdir.mk>
diff --git a/usr.sbin/usbd/usbd.8 b/usr.sbin/usbd/usbd.8
new file mode 100644
index 0000000..47d745e
--- /dev/null
+++ b/usr.sbin/usbd/usbd.8
@@ -0,0 +1,80 @@
+.\" $NetBSD: usbd.8,v 1.2 1998/07/13 11:01:50 augustss Exp $
+.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" Author: Lennart Augustsson
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd July 12, 1998
+.Dt USBD 8
+.Os
+.Sh NAME
+.Nm usbd
+.Nd supervise USB attach/detach
+.Sh SYNOPSIS
+.Nm
+.Op Fl d
+.Op Fl f Ar device
+.Op Fl t Ar timeout
+.Op Fl v
+.Sh DESCRIPTION
+.Nm
+handles the USB device attachment and detachment.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl d
+Enable debugging to the standard output,
+and do not disassociate from the controlling terminal.
+.It Fl e
+Do one device tree exploration and then exit.
+.It Fl f Ar device
+Specify the pathname of a USB controller device file.
+The flag may be repeated to watch more than one USB controller.
+The default is
+.Pa /dev/usb0 ,
+.Pa /dev/usb1 ,
+.Pa /dev/usb2 ,
+and
+.Pa /dev/usb3 .
+.It Fl t Ar timeout
+Set the timeout interval (in seconds) before an exploration happens
+without being triggered by a connect or disconnect.
+A timeout of 0 means that there is no timeout. The default is 30.
+.It Fl v
+Be verbose.
+.El
+.Sh SEE ALSO
+.Xr usb 4
+.Sh HISTORY
+The
+.Nm
+command appeared in
+.Nx 1.4 .
diff --git a/usr.sbin/usbd/usbd.c b/usr.sbin/usbd/usbd.c
new file mode 100644
index 0000000..99a2d52
--- /dev/null
+++ b/usr.sbin/usbd/usbd.c
@@ -0,0 +1,183 @@
+/* $NetBSD: usbd.c,v 1.2 1998/07/23 18:39:53 augustss Exp $ */
+
+/*
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Author: Lennart Augustsson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/time.h>
+#if defined(__FreeBSD__)
+#include <sys/ioctl.h>
+#include <sys/malloc.h>
+#endif
+#include <dev/usb/usb.h>
+
+#define USBDEV "/dev/usb"
+#define MAXUSBDEV 4
+
+extern char *__progname;
+
+void usage(void);
+
+void
+usage(void)
+{
+ fprintf(stderr, "Usage: %s [-d] [-e] [-f dev] [-t timeout] [-v]\n",
+ __progname);
+ exit(1);
+}
+
+#define NDEVS 20 /* maximum number of usb controllers */
+
+/*
+ * Sometimes a device does not respond in time for interrupt
+ * driven explore to find it. Therefore we run an exploration
+ * at regular intervals to catch those.
+ */
+#define TIMEOUT 30
+
+int
+main(int argc, char **argv)
+{
+ int r, i;
+ char *devs[NDEVS];
+ int ndevs = 0;
+ int fds[NDEVS];
+ fd_set fdset;
+ int ch, verbose = 0;
+ int debug = 0;
+ int explore = 0;
+ int itimo = TIMEOUT;
+ int maxfd;
+ char buf[50];
+ struct timeval timo;
+ extern char *optarg;
+ extern int optind;
+
+ while ((ch = getopt(argc, argv, "def:t:v")) != -1) {
+ switch(ch) {
+ case 'd':
+ debug++;
+ break;
+ case 'e':
+ explore++;
+ break;
+ case 'f':
+ if (ndevs < NDEVS)
+ devs[ndevs++] = optarg;
+ break;
+ case 't':
+ itimo = atoi(optarg);
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ maxfd = 0;
+ if (ndevs == 0) {
+ for (i = 0; i < MAXUSBDEV; i++) {
+ sprintf(buf, "%s%d", USBDEV, i);
+ fds[ndevs] = open(buf, O_RDWR);
+ if (fds[ndevs] >= 0) {
+ devs[ndevs] = strdup(buf);
+ if (verbose)
+ printf("%s: opening %s\n",
+ __progname, devs[ndevs]);
+ if (fds[ndevs] > maxfd)
+ maxfd = fds[ndevs];
+ ndevs++;
+ }
+ }
+ } else {
+ for (i = 0; i < ndevs; i++) {
+ fds[i] = open(devs[i], O_RDWR);
+ if (fds[i] < 0)
+ err(1, "%s", devs[i]);
+ else if (fds[i] > maxfd)
+ maxfd = fds[i];
+ }
+ }
+ if (ndevs == 0) {
+ if (verbose)
+ printf("%s: no USB controllers found\n", __progname);
+ exit(0);
+ }
+
+ if (explore) {
+ for (i = 0; i < ndevs; i++) {
+ r = ioctl(fds[i], USB_DISCOVER);
+ if (r < 0)
+ err(1, "USB_DISCOVER");
+ }
+ exit(0);
+ }
+
+ if (!debug)
+ daemon(0, 0);
+
+
+
+ FD_ZERO(&fdset);
+ for (;;) {
+ for (i = 0; i < ndevs; i++)
+ FD_SET(fds[i], &fdset);
+ timo.tv_usec = 0;
+ timo.tv_sec = itimo;
+ r = select(maxfd+1, &fdset, &fdset, 0, itimo ? &timo : 0);
+ if (r < 0)
+ warn("select failed\n");
+ for (i = 0; i < ndevs; i++)
+ if (r == 0 || FD_ISSET(fds[i], &fdset)) {
+ if (verbose)
+ printf("%s: doing %sdiscovery on %s\n",
+ __progname, r ? "" : "timeout ",
+ devs[i]);
+ if (ioctl(fds[i], USB_DISCOVER) < 0)
+ err(1, "USB_DISCOVER");
+ }
+ }
+}
diff --git a/usr.sbin/usbdevs/Makefile b/usr.sbin/usbdevs/Makefile
new file mode 100644
index 0000000..1f40a90
--- /dev/null
+++ b/usr.sbin/usbdevs/Makefile
@@ -0,0 +1,8 @@
+# $NetBSD: Makefile,v 1.2 1998/07/12 20:40:45 augustss Exp $
+
+PROG= usbdevs
+MAN8= usbdevs.8
+CFLAGS+=-I../..//sys
+
+.include <bsd.prog.mk>
+.include <bsd.subdir.mk>
diff --git a/usr.sbin/usbdevs/usbdevs.8 b/usr.sbin/usbdevs/usbdevs.8
new file mode 100644
index 0000000..8f9f256
--- /dev/null
+++ b/usr.sbin/usbdevs/usbdevs.8
@@ -0,0 +1,67 @@
+.\" $NetBSD: usbdevs.8,v 1.3 1998/07/23 13:57:51 augustss Exp $
+.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" Author: Lennart Augustsson
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd July 12, 1998
+.Dt USBDEVS 8
+.Os
+.Sh NAME
+.Nm usbdevs
+.Nd show USB devices connected to the system
+.Sh SYNOPSIS
+.Nm
+.Op Fl a Ar addr
+.Op Fl f Ar dev
+.Op Fl v
+.Sh DESCRIPTION
+.Nm
+prints a listing of all USB devices connected to the system
+with some information about each device.
+The indentation of each line indicates its distance from the root.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl a Ar addr
+only print information about the device at the given address.
+.It Fl f Ar dev
+only print information for the given USB controller.
+.It Fl v
+Be verbose.
+.El
+.Sh SEE ALSO
+.Xr usb 4
+.Sh HISTORY
+The
+.Nm
+command appeared in
+.Nx 1.4 .
diff --git a/usr.sbin/usbdevs/usbdevs.c b/usr.sbin/usbdevs/usbdevs.c
new file mode 100644
index 0000000..a12a994
--- /dev/null
+++ b/usr.sbin/usbdevs/usbdevs.c
@@ -0,0 +1,212 @@
+/* $NetBSD: usbdevs.c,v 1.4 1998/07/23 13:57:51 augustss Exp $ */
+
+/*
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Author: Lennart Augustsson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <err.h>
+#include <errno.h>
+#include <dev/usb/usb.h>
+#if defined(__FreeBSD__)
+#include <sys/ioctl.h>
+#endif
+
+#define USBDEV "/dev/usb"
+
+int verbose;
+
+void usage __P((void));
+void usbdev __P((int f, int a, int rec));
+void usbdump __P((int f));
+void dumpone __P((char *name, int f, int addr));
+int main __P((int, char **));
+
+extern char *__progname;
+
+void
+usage()
+{
+ fprintf(stderr, "Usage: %s [-a addr] [-f dev] [-v]\n", __progname);
+ exit(1);
+}
+
+char done[USB_MAX_DEVICES];
+int indent;
+
+void
+usbdev(f, a, rec)
+ int f;
+ int a;
+ int rec;
+{
+ struct usb_device_info di;
+ int e, p;
+
+ di.addr = a;
+ e = ioctl(f, USB_DEVICEINFO, &di);
+ if (e)
+ return;
+ done[a] = 1;
+ printf("addr %d: ", di.addr);
+ if (verbose) {
+ if (di.lowspeed)
+ printf("low speed, ");
+ if (di.power)
+ printf("power %d mA, ", di.power);
+ else
+ printf("self powered, ");
+ if (di.config)
+ printf("config %d, ", di.config);
+ else
+ printf("unconfigured, ");
+ }
+ printf("%s, %s", di.product, di.vendor);
+ if (verbose)
+ printf(", rev %s", di.revision);
+ printf("\n");
+ if (!rec)
+ return;
+ for (p = 0; p < di.nports; p++) {
+ int s = di.ports[p];
+ if (s >= USB_MAX_DEVICES) {
+ if (verbose) {
+ printf("%*sport %d %s\n", indent+1, "", p+1,
+ s == USB_PORT_ENABLED ? "enabled" :
+ s == USB_PORT_SUSPENDED ? "suspended" :
+ s == USB_PORT_POWERED ? "powered" :
+ s == USB_PORT_DISABLED ? "disabled" :
+ "???");
+
+ }
+ continue;
+ }
+ indent++;
+ printf("%*s", indent, "");
+ if (verbose)
+ printf("port %d ", p+1);
+ usbdev(f, di.ports[p], 1);
+ indent--;
+ }
+}
+
+void
+usbdump(f)
+ int f;
+{
+ int a;
+
+ for (a = 1; a < USB_MAX_DEVICES; a++) {
+ if (!done[a])
+ usbdev(f, a, 1);
+ }
+}
+
+void
+dumpone(name, f, addr)
+ char *name;
+ int f;
+ int addr;
+{
+ if (verbose)
+ printf("Controller %s:\n", name);
+ indent = 0;
+ memset(done, 0, sizeof done);
+ if (addr)
+ usbdev(f, addr, 0);
+ else
+ usbdump(f);
+}
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int ch, i, f;
+ char buf[50];
+ extern int optind;
+ extern char *optarg;
+ char *dev = 0;
+ int addr = 0;
+ int ncont;
+
+ while ((ch = getopt(argc, argv, "a:f:v")) != -1) {
+ switch(ch) {
+ case 'a':
+ addr = atoi(optarg);
+ break;
+ case 'f':
+ dev = optarg;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (dev == 0) {
+ for (ncont = 0, i = 0; i < 10; i++) {
+ sprintf(buf, "%s%d", USBDEV, i);
+ f = open(buf, O_RDONLY);
+ if (f >= 0) {
+ ncont++;
+ dumpone(buf, f, addr);
+ close(f);
+ } else {
+ if (errno == EACCES)
+ warn("%s", buf);
+ }
+ }
+ if (verbose && ncont == 0)
+ printf("%s: no USB controllers found\n", __progname);
+ } else {
+ f = open(dev, O_RDONLY);
+ if (f >= 0)
+ dumpone(dev, f, addr);
+ else
+ err(1, "%s", dev);
+ }
+ exit(0);
+}
OpenPOWER on IntegriCloud