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

Handle reset and a few other fixes #14

Merged
merged 4 commits into from
Jan 15, 2024
Merged

Conversation

xairy
Copy link
Contributor

@xairy xairy commented Oct 29, 2023

Add handling of the USB_RAW_EVENT_RESET Raw Gadget event and fix a few other issues.

See the commit descriptions for details.

Fixes #9.

For USB_REQ_SET_CONFIGURATION/USB_REQ_SET_INTERFACE transfers, we should
complete the transfer via usb_raw_ep0_read only after we spawned the
endpoint threads.
When auto_detach_kernel_driver is set to 1, the kernel will attach a
kernel driver when an interface is released. We don't want that, set
auto_detach_kernel_driver to 0.
Add handling of the USB_RAW_EVENT_RESET Raw Gadget event.

This allows to continue proxying the device if the host decided to reset it,
which can happen during normal device operation.

On a reset event, stop all endpoint threads and reset the proxied device to
effectively restart proxying.
@AristoChen
Copy link
Owner

Hi @xairy ,

Thanks for the PR! and sorry that I am about to go on a business trip abroad, so I can only review after I am back

@@ -122,7 +122,7 @@ int connect_device(int vendor_id, int product_id) {
return result;
}

result = libusb_set_auto_detach_kernel_driver(dev_handle, 1);
result = libusb_set_auto_detach_kernel_driver(dev_handle, 0);
Copy link
Owner

Choose a reason for hiding this comment

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

May I know the reason to set the value to 0? does it fix any issues? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it prevents the kernel from attaching a driver to the interface when the proxy calls release_interface during a device reset or an altsetting change. I think this was the original intention of the libusb_set_auto_detach_kernel_driver call, but it used a wrong argument by mistake.

@AristoChen
Copy link
Owner

AristoChen commented Dec 10, 2023

Hi @xairy and @imatespl ,

Let's bring the conversation to here if you don't mind, I noticed that I won't get any notifictation if you have new comments there

thanks!

@AristoChen
Copy link
Owner

Looks like there is no further discussion, so I will merge this PR soon, and also I will open a new issue to make sure we will have a fix for the issue discussed here

@AristoChen AristoChen merged commit ccab473 into AristoChen:main Jan 15, 2024
@xairy
Copy link
Contributor Author

xairy commented Jan 15, 2024

Looks like there is no further discussion, so I will merge this PR soon, and also I will open a new issue to make sure we will have a fix for the issue discussed here

Sorry for not responding. I was meaning to get back to this, but I've been busy with other things. Thank you for merging!

@AristoChen
Copy link
Owner

Sorry for not responding. I was meaning to get back to this, but I've been busy with other things. Thank you for merging!

No worry, I know people get very busy from time to time, even I am not available all the time maintaining this repo, and thanks for the contributions! we can continue the discussion in #20 if you have any thought. thanks again!

@xairy xairy deleted the reset branch June 14, 2024 23:54
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.

ioctl(USB_RAW_IOCTL_EP_READ): Cannot send after transport endpoint shutdown when changing altinterface
3 participants