Bug 224454 - Feature request: implement libusb_get_parent and libusb_has_capability
Summary: Feature request: implement libusb_get_parent and libusb_has_capability
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: usb (show other bugs)
Version: 11.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-usb (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-19 14:02 UTC by Ting-Wei Lan
Modified: 2024-08-12 19:01 UTC (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ting-Wei Lan 2017-12-19 14:02:33 UTC
These two functions are available in libusb (http://libusb.info/) and they are currently used by libgusb (https://github.com/hughsie/libgusb/pull/10), a GObject wrapper for libusb. Can we get them implemented in FreeBSD to make applications or libraries porting easier?
Comment 1 Hans Petter Selasky freebsd_committer freebsd_triage 2017-12-19 15:28:09 UTC
Hi,

Can you suggest a patch to implement them in FreeBSD 12-current?

/usr/src/lib/libusb

I'm uncertain if the functions you mention are useful to FreeBSD in general including ports, or if it is better to stub them in the code where these functions are used.

The function to get the parent USB device must be re-constructed in userspace by using the information obtained from:

/usr/include/libusb20.h:uint8_t	libusb20_dev_get_parent_address(struct libusb20_device *pdev);

Also this introduce a couple of races, like what to do if the parent USB device vanishes, refcounts and so on.

--HPS
Comment 2 Ting-Wei Lan 2017-12-21 18:43:35 UTC
I have no FreeBSD 12 installation. The machine I used to test libgusb runs FreeBSD 11.1-RELEASE. I can setup FreeBSD 12 in virtual machine if I have to provide some code running on it.

I think libusb_has_capability is easier to implement. Do you think it is correct for libusb_has_capability to always return 1 for the hotplug capability?

I found there is another missing function today: libusb_interrupt_event_handler. gvfs uses it in its MTP backend, and this is the only libusb function it calls. gvfs has an option to disable libusb support, so it doesn't cause build problems.
Comment 3 Hans Petter Selasky freebsd_committer freebsd_triage 2017-12-21 20:14:58 UTC
Hi,

libusb is the same for -12 and -11. Just make a patch for your current system and I'll fix the rest.

> I think libusb_has_capability is easier to implement. Do you think it is correct for libusb_has_capability to always return 1 for the hotplug capability?

Can you check what is expected by the hotplug capability? What functions must be implemented when this capability returns 1?

> I found there is another missing function today:
> libusb_interrupt_event_handler. gvfs uses it in its MTP backend,
> and this is the only libusb function it calls. gvfs has an
> option to disable libusb support, so it doesn't cause build problems.

Is this a variant of the existing "libusb_event_handler_active()"? Can you investigate a bit?

--HPS
Comment 5 Hans Petter Selasky freebsd_committer freebsd_triage 2021-02-07 20:18:21 UTC
Hi,

libusb_has_capability() is now implemented:

/usr/include/libusb.h:	/* libusb supports libusb_has_capability(). */
/usr/include/libusb.h:int	libusb_has_capability(uint32_t capability);

--HPS
Comment 6 Ed Maste freebsd_committer freebsd_triage 2024-06-06 14:34:53 UTC
libusb_get_parent was introduced in libusb in:

commit cfb8610242394d532778a483570089c2bed52c84
Author: Pete Batard <pete@akeo.ie>
Date:   Thu May 10 20:01:10 2012 +0100

    All: Add parent and port topology calls
    
    * Adds libusb_get_port_number, libusb_get_parent and libusb_get_port_path
    * Linux implementation provided by Alan Stern, OS X by Nathan Hjelm
    * Unsupported for *BSD platforms

It is a trivial getter that returns a parent libusb_device member. From what I can tell the parent_dev is never set in any of libusb's BSD osdep code.
Comment 7 Gleb Popov freebsd_committer freebsd_triage 2024-08-12 19:01:55 UTC
Bumped into this in devel/py-pyusb port - it requires this function to initialize the Python bindings.