AristoChen / usb-proxy

A USB proxy based on raw-gadget and libusb
Apache License 2.0
136 stars 29 forks source link

Fix support for proxying devices that switch interface altsettings #13

Open xairy opened 8 months ago

xairy commented 8 months ago

Even though #6 added basic support for devices that switch between interface altsettings, it might not work properly in certain cases: the endpoint handling threads might fail to be joined, as they might be blocked on libusb or Raw Gadget transfers.

Interrupting Raw Gadget transfers is simple: just send any signal to the endpoint threads via pthread_kill and add a no-op handler for this signal (but perhaps a signal other than SIGINT, as USB Proxy already uses this signal internally).

However, interrupting the libusb transfers is a problem.

A simple solution would be use the timeout argument of the libusb sync I/O API, but unfortunately libusb has a bug that makes sync I/O ignore the timeout argument.

We need to either switch to using async libusb I/O or figure out another way to interrupt libusb transfers (without fully resetting the device, as done in #14).

Ah, actually libusb timeouts work as expected, it's just that receive_data zeroes out timeout.