google / gousb

gousb provides low-level interface for accessing USB devices
Apache License 2.0
838 stars 124 forks source link

allow only libusb auto detach #117

Open ARizzo35 opened 1 year ago

google-cla[bot] commented 1 year ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

zagrodzki commented 1 year ago

I think this change requires more explanations. When is this needed? Why doesn't the current implementation work for your use case? Could your use case be solved without adding new methods?

ARizzo35 commented 1 year ago

I think this change requires more explanations. When is this needed? Why doesn't the current implementation work for your use case? Could your use case be solved without adding new methods?

I used this library to interact with a FTDI chip over USB, specifically using their MPSSE. In order to use the USB device in this mode, on one specific interface (the chip has multiple interfaces), the standard linux kernel USB serial driver for FTDI has to be unloaded first.

The libusb auto-detach implementation handles unloading the kernel driver for a specific interface properly so that it can be claimed. In this gousb library, extra functionality is added in the implementation of SetAutoDetach() which sets a flag to detach the kernel driver for all interfaces on the device when the config is changed, which is not normal behavior in libusb.

This added function only calls the libusb auto-detach binding, and does not set the autodetach flag in the device class.

An extra boolean parameter could be added to the current implementation of SetAutoDetach() to handle this as well, but that would be less backwards compatible since Golang does not support optional function parameters with default values.

zagrodzki commented 1 year ago

if I understand correctly, you're saying that just setting the libusb option is sufficient and the kernel will automatically detach whatever interfaces need to be claimed in whatever config is currently loaded? Ok. I wonder if the current behavior is then something that is actually required, or was the code unnecessarily overzealous in calling the detach function?