Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsusb: detach the kernel driver before claiming the interface #52

Closed
wants to merge 1 commit into from

Conversation

jazzguitar81
Copy link
Contributor

To display a report descriptor for HID device, we have to success claim
the interface. So, we need to detach the kernel driver before claming the
interface.

The libusb_set_auto_detach_kernel_driver() in libusb automatically do detach
the kernel driver on an interface when claiming the interface, and attach it
when releasing the interface.

Signed-off-by: Jaejoong Kim climbbb.kim@gmail.com

To display a report descriptor for HID device, we have to success claim
the interface. So, we need to detach the kernel driver before claming the
interface.

The libusb_set_auto_detach_kernel_driver() in libusb automatically do detach
the kernel driver on an interface when claiming the interface, and attach it
when releasing the interface.

Signed-off-by: Jaejoong Kim <climbbb.kim@gmail.com>
Copy link
Owner

@gregkh gregkh left a comment

Choose a reason for hiding this comment

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

Sorry for the delay.

What type of side-affect does this cause? I'm leery of changing the way the interaction with the kernel works here, as unbind/bind could cause issues for some devices, right?

@jazzguitar81
Copy link
Contributor Author

With original source(without my patch), the return value of libusb_claim_interface is -6 which means LIBUSB_ERROR_BUSY if another program or driver has claimed the interface.

To display the report descriptor for HID device, we need to detach the kernel driver or another program. The libusb_set_auto_detach_kernel_driver() makes 'auto_detach_kernel_driver' field from struct libusb_device_handle set as enable.

There is a comment about the fail case about libusb_claim_interface:

static void dump_hid_device()
.. snip..

3195 } else {
3196 /* recent Linuxes require claim() for RECIP_INTERFACE,
3197 * so "rmmod hid" will often make these available.
3198 */
3199 printf(" Report Descriptors: \n"
3200 " ** UNAVAILABLE **\n");
3201 }

I don't think this makes the side-effect the HID devices already claimed interface. The only problem is the shortly mouse pointer is stop while detached the HID kernel driver and re-attach the kernel driver if the user run the 'lsusb' command.

@gregkh
Copy link
Owner

gregkh commented Nov 23, 2017

Let me think about this for maybe the next release...

@jazzguitar81
Copy link
Contributor Author

Still here..
I'm OK if you drop this patch :)

Anyway, I checked usbhid-dump(dump hid report descriptor) source code and it also detach a hid interface before claim interface. Proceed in the following order:
detach --> claim --> releae --> attach interface back

So, the usbhid-dump program also causes the mouse pointer to be briefly interrupted.

@gregkh
Copy link
Owner

gregkh commented Feb 14, 2019 via email

@jazzguitar81
Copy link
Contributor Author

@ValZapod
Sorry about late response.

@jazzguitar81 @gregkh Maybe I don't understand smth, but is "detach/unbind the kernel driver" really necessary? One could just use

No really necessary. I just want to show a report descriptor from lsusb without any other actions.

cat /sys/kernel/debug/hid/*/rdesc

You can read about it there http://www.slashdev.ca/2010/05/08/get-usb-report-descriptor-with-linux/ (first comment).

@gregkh
I still OK if you close this PR.

@gregkh
Copy link
Owner

gregkh commented Jun 21, 2019

There's nothing to comment on it. debugfs is accessible only by root, as it is for debugging information only.

I really don't like the unbind/bind method here, as I have stated a number of times already.

@gregkh
Copy link
Owner

gregkh commented Jun 29, 2019

And about debug descriptors?

I have no idea what you are referring to with when you say this, sorry, please be more specific.

@gregkh
Copy link
Owner

gregkh commented Jan 10, 2020

I really do not like the unbind/bind stuff here, it can cause problems with userspace so I'm going to just close this out, thanks.

@gregkh gregkh closed this Jan 10, 2020
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.

2 participants