Below is an updated diff.  I will add the documentation bits
soonish once I've tested all possible configurations as you
requested.

I am also planning to rework the structure of usbdevs.c as it is
a bit confusing currently but that will happen incrementally after
this diff.

Index: sys/dev/usb/uhub.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/uhub.c,v
retrieving revision 1.83
diff -u -p -r1.83 uhub.c
--- sys/dev/usb/uhub.c  12 Feb 2015 05:07:52 -0000      1.83
+++ sys/dev/usb/uhub.c  22 Apr 2015 11:10:46 -0000
@@ -53,6 +53,9 @@
 #define DPRINTF(x...)
 #endif
 
+/* controls enabling/disabling of USB bus probing */
+int busprobe = 1;
+
 struct uhub_softc {
        struct device           sc_dev;         /* base device */
        struct usbd_device      *sc_hub;        /* USB device */
@@ -487,6 +490,9 @@ uhub_explore(struct usbd_device *dev)
                        else
                                speed = sc->sc_hub->speed;
                }
+
+               if (!busprobe)
+                       return (0);
 
                /*
                 * Reduce the speed, otherwise we won't setup the proper
Index: sys/dev/usb/usb.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/usb.c,v
retrieving revision 1.107
diff -u -p -r1.107 usb.c
--- sys/dev/usb/usb.c   14 Mar 2015 03:38:50 -0000      1.107
+++ sys/dev/usb/usb.c   22 Apr 2015 11:10:46 -0000
@@ -87,6 +87,8 @@ int   usb_noexplore = 0;
 #define DPRINTFN(n,x)
 #endif
 
+extern int busprobe;
+
 struct usb_softc {
        struct device    sc_dev;        /* base device */
        struct usbd_bus  *sc_bus;       /* USB controller */
@@ -607,6 +609,14 @@ usbioctl(dev_t devt, u_long cmd, caddr_t
 #endif
                break;
 #endif /* USB_DEBUG */
+       case USB_GET_BUS_PROBE:
+               *(unsigned int *)data = busprobe;
+               break;          
+       case USB_SET_BUS_PROBE:
+               if ((error = suser(curproc, 0)) != 0)
+                       return (error);
+               busprobe = !!*(unsigned int *)data;
+               break;
        case USB_REQUEST:
        {
                struct usb_ctl_request *ur = (void *)data;
Index: sys/dev/usb/usb.h
===================================================================
RCS file: /cvs/src/sys/dev/usb/usb.h,v
retrieving revision 1.50
diff -u -p -r1.50 usb.h
--- sys/dev/usb/usb.h   14 Feb 2015 06:18:58 -0000      1.50
+++ sys/dev/usb/usb.h   22 Apr 2015 11:10:46 -0000
@@ -720,14 +720,16 @@ struct usb_device_stats {
 };
 
 /* USB controller */
-#define USB_REQUEST            _IOWR('U', 1, struct usb_ctl_request)
-#define USB_SETDEBUG           _IOW ('U', 2, unsigned int)
+#define USB_REQUEST            _IOWR('U', 1,  struct usb_ctl_request)
+#define USB_SETDEBUG           _IOW ('U', 2,  unsigned int)
 #define USB_DISCOVER           _IO  ('U', 3)
-#define USB_DEVICEINFO         _IOWR('U', 4, struct usb_device_info)
-#define USB_DEVICESTATS                _IOR ('U', 5, struct usb_device_stats)
-#define USB_DEVICE_GET_CDESC   _IOWR('U', 6, struct usb_device_cdesc)
-#define USB_DEVICE_GET_FDESC   _IOWR('U', 7, struct usb_device_fdesc)
-#define USB_DEVICE_GET_DDESC   _IOWR('U', 8, struct usb_device_ddesc)
+#define USB_DEVICEINFO         _IOWR('U', 4,  struct usb_device_info)
+#define USB_DEVICESTATS                _IOR ('U', 5,  struct usb_device_stats)
+#define USB_DEVICE_GET_CDESC   _IOWR('U', 6,  struct usb_device_cdesc)
+#define USB_DEVICE_GET_FDESC   _IOWR('U', 7,  struct usb_device_fdesc)
+#define USB_DEVICE_GET_DDESC   _IOWR('U', 8,  struct usb_device_ddesc)
+#define USB_GET_BUS_PROBE      _IOR ('U', 9,  unsigned int)
+#define USB_SET_BUS_PROBE      _IOW ('U', 10, unsigned int)
 
 /* Generic HID device */
 #define USB_GET_REPORT_DESC    _IOR ('U', 21, struct usb_ctl_report_desc)
Index: usr.sbin/usbdevs/usbdevs.8
===================================================================
RCS file: /cvs/src/usr.sbin/usbdevs/usbdevs.8,v
retrieving revision 1.9
diff -u -p -r1.9 usbdevs.8
--- usr.sbin/usbdevs/usbdevs.8  26 Jun 2008 05:42:21 -0000      1.9
+++ usr.sbin/usbdevs/usbdevs.8  22 Apr 2015 11:10:46 -0000
@@ -39,6 +39,7 @@
 .Op Fl dv
 .Op Fl a Ar addr
 .Op Fl f Ar dev
+.Op Fl p Ns Op Ar on | off
 .Sh DESCRIPTION
 .Nm
 prints a listing of all USB devices connected to the system
@@ -53,6 +54,10 @@ Only print information about the device 
 Show the device drivers associated with each device.
 .It Fl f Ar dev
 Only print information for the given USB controller.
+.It Fl p Ns Op Ar on | off
+Enable or disable USB bus probing.  The default
+is
+.Ar on .
 .It Fl v
 Be verbose.
 .El
Index: usr.sbin/usbdevs/usbdevs.c
===================================================================
RCS file: /cvs/src/usr.sbin/usbdevs/usbdevs.c,v
retrieving revision 1.24
diff -u -p -r1.24 usbdevs.c
--- usr.sbin/usbdevs/usbdevs.c  31 Mar 2015 13:38:27 -0000      1.24
+++ usr.sbin/usbdevs/usbdevs.c  22 Apr 2015 11:10:46 -0000
@@ -30,14 +30,15 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <sys/types.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
 #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>
 
 #ifndef nitems
@@ -46,21 +47,23 @@
 
 #define USBDEV "/dev/usb"
 
-int verbose = 0;
-int showdevs = 0;
+int verbose;
+int showdevs;
+int getprobe;
+int setprobe;
 
 void usage(void);
 void usbdev(int f, int a, int rec);
 void usbdump(int f);
 void dumpone(char *name, int f, int addr);
-int main(int, char **);
+void busprobe(int f, unsigned int probe);
 
 extern char *__progname;
 
 void
 usage(void)
 {
-       fprintf(stderr, "usage: %s [-dv] [-a addr] [-f dev]\n", __progname);
+       fprintf(stderr, "usage: %s [-dv] [-a addr] [-f dev] [-p[on | off]]\n", 
__progname);
        exit(1);
 }
 
@@ -177,17 +180,32 @@ dumpone(char *name, int f, int addr)
                usbdump(f);
 }
 
+void
+busprobe(int f, unsigned int probe)
+{
+       if (setprobe) {
+               if (ioctl(f, USB_SET_BUS_PROBE, &probe))
+                       err(1, "setprobe");
+       } else if (getprobe) {
+               if (ioctl(f, USB_GET_BUS_PROBE, &probe))
+                       err(1, "getprobe");
+               printf("bus probing: %s\n",
+                      probe ? "on" : "off");
+       }
+}
+
 int
 main(int argc, char **argv)
 {
-       int ch, i, f;
-       char buf[50];
+       char buf[PATH_MAX];
        char *dev = 0;
        const char *errstr;
+       unsigned int probe = 1;
+       int ch, i, f;
        int addr = 0;
        int ncont;
 
-       while ((ch = getopt(argc, argv, "a:df:v?")) != -1) {
+       while ((ch = getopt(argc, argv, "a:df:p::v")) != -1) {
                switch (ch) {
                case 'a':
                        addr = strtonum(optarg, 1, USB_MAX_DEVICES, &errstr);
@@ -200,6 +218,19 @@ main(int argc, char **argv)
                case 'f':
                        dev = optarg;
                        break;
+               case 'p':
+                       if (!optarg) {
+                               getprobe = 1;
+                       } else {
+                               if (!strcmp(optarg, "on"))
+                                       probe = 1;
+                               else if (!strcmp(optarg, "off"))
+                                       probe = 0;
+                               else
+                                       usage();
+                               setprobe = 1;
+                       }
+                       break;
                case 'v':
                        verbose = 1;
                        break;
@@ -210,11 +241,19 @@ main(int argc, char **argv)
        argc -= optind;
        argv += optind;
 
+       if (argc)
+               usage();
+
        if (dev == 0) {
                for (ncont = 0, i = 0; i < 10; i++) {
                        snprintf(buf, sizeof buf, "%s%d", USBDEV, i);
                        f = open(buf, O_RDONLY);
                        if (f >= 0) {
+                               if (setprobe || getprobe) {
+                                       busprobe(f, probe);
+                                       close(f);
+                                       break;
+                               }
                                dumpone(buf, f, addr);
                                close(f);
                        } else {
@@ -229,10 +268,15 @@ main(int argc, char **argv)
                            __progname);
        } else {
                f = open(dev, O_RDONLY);
-               if (f >= 0)
-                       dumpone(dev, f, addr);
-               else
+               if (f >= 0) {
+                       if (setprobe || getprobe)
+                               busprobe(f, probe);
+                       else
+                               dumpone(dev, f, addr);
+                       close(f);
+               } else {
                        err(1, "%s", dev);
+               }
        }
        exit(0);
 }

Reply via email to