Diff below extends 'struct usb_device_info' to include the port number
where the USB device is attached to.  It doesn't grow the structure and
reuse implicit padding.

I'd like to export the port number to userland to satisfy devel/libusb1,
see: https://github.com/libusb/libusb/issues/314

Ok?

Index: src/sys/dev/usb/usb.h
===================================================================
RCS file: /cvs/src/sys/dev/usb/usb.h,v
retrieving revision 1.60
diff -u -p -r1.60 usb.h
--- src/sys/dev/usb/usb.h       10 Jul 2018 09:17:03 -0000      1.60
+++ src/sys/dev/usb/usb.h       11 Jul 2018 09:04:04 -0000
@@ -737,6 +737,7 @@ struct usb_device_info {
 #define USB_SPEED_FULL 2
 #define USB_SPEED_HIGH 3
 #define USB_SPEED_SUPER        4
+       u_int8_t        udi_port;
        int             udi_power;      /* power consumption in mA, 0 if 
selfpowered */
        int             udi_nports;
        char            udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
Index: src/sys/dev/usb/usb_subr.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/usb_subr.c,v
retrieving revision 1.137
diff -u -p -r1.137 usb_subr.c
--- src/sys/dev/usb/usb_subr.c  10 Jul 2018 09:17:03 -0000      1.137
+++ src/sys/dev/usb/usb_subr.c  11 Jul 2018 09:04:10 -0000
@@ -1321,6 +1321,7 @@ usbd_fill_deviceinfo(struct usbd_device 
        di->udi_config = dev->config;
        di->udi_power = dev->self_powered ? 0 : dev->power;
        di->udi_speed = dev->speed;
+       di->udi_port = dev->powersrc ? dev->powersrc->portno : 0;
 
        if (dev->subdevs != NULL) {
                for (i = 0; dev->subdevs[i] && i < USB_MAX_DEVNAMES; i++) {
Index: ports/devel/libusb1/Makefile
===================================================================
RCS file: /cvs/ports/devel/libusb1/Makefile,v
retrieving revision 1.28
diff -u -p -r1.28 Makefile
--- ports/devel/libusb1/Makefile        10 Jul 2018 09:19:13 -0000      1.28
+++ ports/devel/libusb1/Makefile        12 Jul 2018 10:12:03 -0000
@@ -3,7 +3,7 @@
 COMMENT =              library for USB device access from userspace
 
 VERSION =              1.0.21
-REVISION =             0
+REVISION =             1
 DISTNAME =             libusb-${VERSION}
 PKGNAME =              libusb1-${VERSION}
 
Index: ports/devel/libusb1/patches/patch-libusb_os_openbsd_usb_c
===================================================================
RCS file: ports/devel/libusb1/patches/patch-libusb_os_openbsd_usb_c
diff -N ports/devel/libusb1/patches/patch-libusb_os_openbsd_usb_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ ports/devel/libusb1/patches/patch-libusb_os_openbsd_usb_c   12 Jul 2018 
10:11:56 -0000
@@ -0,0 +1,15 @@
+$OpenBSD$
+
+Export port number, fix github #314.
+
+Index: libusb/os/openbsd_usb.c
+--- libusb/os/openbsd_usb.c.orig
++++ libusb/os/openbsd_usb.c
+@@ -201,6 +201,7 @@ obsd_get_device_list(struct libusb_context * ctx,
+                               dev->bus_number = di.udi_bus;
+                               dev->device_address = di.udi_addr;
+                               dev->speed = di.udi_speed;
++                              dev->port_number = di.udi_port;
+ 
+                               dpriv = (struct device_priv *)dev->os_priv;
+                               dpriv->fd = -1;

Reply via email to