`libusb_attach_kernel_driver` does not work

I have a problem completely shutting down my Linux application that uses libusb (the kernel does not return an interface):

 int rc; rc = libusb_reset_device(handle_); if (rc < 0) { cerr << "Error resetting the device: " << libusb_error_name(rc); } for (int ifnum = 0; ifnum < 2; ifnum++) { rc = libusb_release_interface(handle_, ifnum); if (rc < 0) { cerr << "Error releasing interface: " << libusb_error_name(rc); } if (libusb_kernel_driver_active(handle_, ifnum)) { cerr << "Reattaching CDC ACM kernel driver."; rc = libusb_attach_kernel_driver(handle_, ifnum); if (rc < 0) { cerr << "Error reattaching CDC ACM kernel driver: " << libusb_error_name(rc); } } } libusb_close(handle_); libusb_exit(NULL); 

The problem is that rebooting the kernel driver does not work. In fact, libusb_kernel_driver_active does not return 1, but even if I comment on it and always call libusb_attach_kernel_driver , I will never return to my device /dev/ttyACM0 . In this case, I get LIBUSB_ERROR_NOT_FOUND .

+6
source share
1 answer

I debugged the linux cdc-acm driver attachment code, and I found out the cause of this problem. The reason for reconnecting is not that I required both the management interface and the CDC ACM device data interface. If I only disconnect / attach the management interface (ifnum == 0), then everything works as expected. This should be documented somewhere.

+1
source

All Articles