Skip to content

Conversation

@Dadoum
Copy link

@Dadoum Dadoum commented Oct 8, 2025

Allows the library user to detach kernel drivers only for specific interfaces, which is useful when handling only a part of a more complex device.

@google-cla
Copy link

google-cla bot commented Oct 8, 2025

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
Copy link
Collaborator

I think this is generally fine, but I'm curious about the use case. Please update the PR description.

gofmt has something to say about your changes; see the test failures.

@Dadoum
Copy link
Author

Dadoum commented Oct 11, 2025

The library already has a function to detach all drivers from a device upon opening it, but sometimes you might only want to detach the driver from only one interface, like in my case, using go-ncm on one specific interface of the phone but still leave the previous usbmuxer do its job managing the other ones.


// DetachKernelDriver detaches the driver currently attached to the given
// interface.
func (d *Device) DetachKernelDriver(ifNumber int) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be on the Configuration rather than the Device? Once a Device is opened, you would need to select a configuration before you know what interfaces are available.

@zagrodzki
Copy link
Collaborator

I'm wondering if there could be a universal approach to detaching kernel drivers. Right now the API is mixing two approaches:

  • autodetach on the device, which is really acting when a configuration is selected. Detaches when user tries to access the resource.
  • (proposed) detach a specific interface (in a specific config of a specific device). User needs to explicitly detach.

And the implementation is also inconsistent, since calling Device.SetAutoDetach affects two things:

  • detaches all interfaces when a config is selected
  • calls libusb_set_auto_detach_kernel_driver, which auto-detaches when a specific interface is claimed.

It would be nice to have a consistent approach. I would lean towards disabling autodetach and preferring explicit DetachKernelDriver(int) and DetachKernelDriverAll() on the configuration.

An alternative would be to add Configuration.SetAutoDetach(), which would auto-detach on claimed interface, like Device.SetAutoDetach() auto-detaches on all interfaces of a configuration.

Or both. I don't know. Calling @stapelberg for a gut feeling check.

@stapelberg
Copy link
Collaborator

Or both. I don't know. Calling @stapelberg for a gut feeling check.

It’s been years since I last worked with USB APIs 😅

I don’t think my gut tells me anything on these questions, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants