On 01/29/18 19:44, Romain Tartière wrote:
Hello!
FreeBSD's libusb allows userland programs to access USB devices in a way
similar to GNU/Linux with it's libusb.
However, there are some differences between these implementations. I
recently diagnosed an issue in sigrok, provided a patch, but the
maintainer is having some questions and I am not sure about the best way
to address them.
If someone with more USB insight could give a look to this GitHub issue,
that would be awesome !
Basically, the usb_get_port_path() calls libusb_open() before (and
libusb_close() after) libusb_get_port_numbers() because this is required
on FreeBSD:
https://github.com/sigrokproject/libsigrok/blob/a9010323ddf4e479663e871386c05db05ea3522e/src/usb.c#L478-L491
However, calling libusb_open() twice fails…
The issue is here:
https://github.com/sigrokproject/libsigrok/pull/6
Hi,
Does the attached patch for FreeBSD's libusb solve your issue?
--HPS
Index: libusb20_int.h
===================================================================
--- libusb20_int.h (revision 328435)
+++ libusb20_int.h (working copy)
@@ -237,8 +237,12 @@
uint8_t is_opened;
uint8_t parent_address;
uint8_t parent_port;
+ uint8_t port_level;
char usb_desc[96];
+
+#define LIBUSB20_DEVICE_PORT_PATH_MAX 32
+ uint8_t port_path[LIBUSB20_DEVICE_PORT_PATH_MAX];
};
extern const struct libusb20_backend_methods libusb20_ugen20_backend;
Index: libusb20_ugen20.c
===================================================================
--- libusb20_ugen20.c (revision 328435)
+++ libusb20_ugen20.c (working copy)
@@ -136,6 +136,7 @@
const char *tmp = id;
struct usb_device_descriptor ddesc;
struct usb_device_info devinfo;
+ struct usb_device_port_path udpp;
uint32_t plugtime;
char buf[64];
int f;
@@ -219,6 +220,21 @@
pdev->device_address, devinfo.udi_vendor,
devinfo.udi_product, pdev->bus_number);
+ /* get parent port path */
+
+ if (ioctl(f, IOUSB(USB_GET_DEV_PORT_PATH), &udpp)) {
+ error = LIBUSB20_ERROR_OTHER;
+ goto done;
+ }
+
+ if (udpp.udp_port_level > LIBUSB20_DEVICE_PORT_PATH_MAX) {
+ error = LIBUSB20_ERROR_OVERFLOW;
+ goto done;
+ }
+
+ memcpy(pdev->port_path, udpp.udp_port_no, udpp.udp_port_level);
+ pdev->port_level = udpp.udp_port_level;
+
error = 0;
done:
close(f);
@@ -653,17 +669,13 @@
static int
ugen20_get_port_path(struct libusb20_device *pdev, uint8_t *buf, uint8_t bufsize)
{
- struct usb_device_port_path udpp;
- if (ioctl(pdev->file_ctrl, IOUSB(USB_GET_DEV_PORT_PATH), &udpp))
- return (LIBUSB20_ERROR_OTHER);
-
- if (udpp.udp_port_level > bufsize)
+ if (pdev->port_level > bufsize)
return (LIBUSB20_ERROR_OVERFLOW);
- memcpy(buf, udpp.udp_port_no, udpp.udp_port_level);
+ memcpy(buf, pdev->port_path, pdev->port_level);
- return (udpp.udp_port_level); /* success */
+ return (pdev->port_level); /* success */
}
static int
_______________________________________________
freebsd-usb@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"