Date: Mon, 29 Jan 2018 20:10:06 +0100 From: Hans Petter Selasky <hps@selasky.org> To: =?UTF-8?Q?Romain_Tarti=c3=a8re?= <romain@FreeBSD.org>, usb@freebsd.org Subject: Re: Feedback for portable libusb code Message-ID: <9128056d-c916-597e-f866-48cf6051ee0e@selasky.org> In-Reply-To: <20180129184445.GB7783@blogreen.org> References: <20180129184445.GB7783@blogreen.org>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------10B0C664C0A9F56F53F827C7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 --------------10B0C664C0A9F56F53F827C7 Content-Type: text/x-patch; name="libusb.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="libusb.diff" 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 --------------10B0C664C0A9F56F53F827C7--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9128056d-c916-597e-f866-48cf6051ee0e>