-
Notifications
You must be signed in to change notification settings - Fork 31
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
ioctl(USB_RAW_IOCTL_EP_READ): Cannot send after transport endpoint shutdown when changing altinterface #9
Comments
Hi, Thanks for reporting the issue! could you please provide the output of this command |
Bus 001 Device 010: ID 045e:02ea Microsoft Corp. Xbox One S Controller |
Hi @RandomOnlineName , Thanks for providing the info, could you please also provide the output of And I got a Xbox controller to test today, I do encounter similiar issue, and please try to switch to commit ID # in usb-proxy directory
$ git reset --hard 6aecd455b2ef3d6734ab92105ca00c01464d4030
$ make -j$(nproc) with commit ID |
uname -a outputs "Linux rasberrypi 5.15.89v7lAlex+ #3 SMP Tue Mar 21 18:08:19 GMT 2023 armv7l GNU/Linux" |
I think the problem is that the |
It's also possible that we need this Raw Gadget patch xairy/raw-gadget@60042be to avoid disabling the Raw Gadget device if the emulation code accidentally does an endpoint operation on a disabled endpoint. |
Hi @xairy , Thanks for helping out on this issue! I was awared that the I didn't try to implement the mechanism to kill the thread that calls I will try that patch and update the result here when I have time. Thanks again for the help! |
I don't think implementing the non-blocking mode will make that much of a difference: we will still need some way to wait for the transfer to complete and will still need a way to interrupt this waiting. Using a signal to interrupt a blocking syscall is not that unusual of an approach. Technically, we don't even need to kill the thread. We can use any signal and add a no-op handler for it. The important part is that sending a signal will interrupt the To make this work, we also need this patch btw xairy/raw-gadget@98f9a64, besides the one I linked above. If all this proves to work, I will send these patches upstream. |
Hi @xairy , I see, thanks for the explanation! Hi @RandomOnlineName , I might need your help, I think my Xbox controller behaves differently by comparing your log and my log, I never received the USB control request to change interface/altsetting, so please apply the patches mentioned above for Raw Gadget and apply the following for usb-proxy diff --git a/proxy.cpp b/proxy.cpp
index e3dbd57..e139e3a 100644
--- a/proxy.cpp
+++ b/proxy.cpp
@@ -291,8 +291,15 @@ void terminate_eps(int fd, int config, int interface, int altsetting) {
for (int i = 0; i < alt->interface.bNumEndpoints; i++) {
struct raw_gadget_endpoint *ep = &alt->endpoints[i];
- if (ep->thread_read && pthread_join(ep->thread_read, NULL)) {
- fprintf(stderr, "Error join thread_read\n");
+ if (ep->thread_read) {
+ if (ep->thread_info.dir == "out") {
+ pthread_kill(ep->thread_read, SIGINT);
+ printf("Sent SIGINT to thread_read for EP%02x\n",
+ ep->thread_info.endpoint.bEndpointAddress);
+ }
+ if (pthread_join(ep->thread_read, NULL)) {
+ fprintf(stderr, "Error join thread_read\n");
+ }
}
if (ep->thread_write && pthread_join(ep->thread_write, NULL)) {
fprintf(stderr, "Error join thread_write\n"); I don't have a proper USB device to test this logic, hopefully it works, feel free to let me know if it doesn't, thanks |
I will test this when I get back to my computer. Thank you for the help. |
It causes an "ioctl(USB_RAW_IOCTL_READ): Interrupted system call" error with the same log otherwise |
@RandomOnlineName I think you need to add a no-op handler for |
I tested out the approach I suggested: xairy/raw-gadget@0732f53, it works. I used it for handling the reset event, but it should work the same for switching altsetting/interface. |
A cleaner solution via On a side note, I found this article very useful to learn about pthread cancellation. |
Disable endpoint before attempting to join threads that might be blocked on read/write Raw Gadget ioctls. Hopefully fixes AristoChen#9.
Disable endpoint before attempting to join threads that might be blocked on read/write Raw Gadget ioctls. Hopefully fixes AristoChen#9.
Disable endpoint before attempting to join threads that might be blocked on read/write Raw Gadget ioctls. Hopefully fixes AristoChen#9.
Looked through usb-proxy code: #9 (comment) +
Actually, scratch that: |
Looks like interrupting blocked threads will not fix proxying the device. Something else is wrong: I don't think the host is supposed to send those |
Related to AristoChen#9.
Related to AristoChen#9.
Added support for reset handling: https://github.com/xairy/usb-proxy/tree/reset. Together with ignoring meaningless Requires Raw Gadget patches from |
I have tried https://github.com/xairy/usb-proxy/tree/reset and https://github.com/xairy/raw-gadget/tree/dev but get event: disconnect Could there be something different about our devices like kernel version or something else? |
Ah, I think this is that bug in dwc2 that it reports a disconnect instead of a reset. Please try this patch:
If it still fails, please upload the full log somewhere and share. |
Checked with my R Pi 4, we also need something like this: diff --git a/proxy.cpp b/proxy.cpp
index 2ae255a..6474545 100644
--- a/proxy.cpp
+++ b/proxy.cpp
@@ -129,7 +129,7 @@ void *ep_loop_write(void *arg) {
if (ep.bEndpointAddress & USB_DIR_IN) {
int rv = usb_raw_ep_write(fd, (struct usb_raw_ep_io *)&io);
- if (rv < 0 && please_stop_eps) {
+ if (rv < 0) {
printf("EP%x(%s_%s): thread interrupted\n", ep.bEndpointAddress,
transfer_type.c_str(), dir.c_str());
break;
@@ -218,7 +218,7 @@ void *ep_loop_read(void *arg) {
io.inner.length = sizeof(io.data);
int rv = usb_raw_ep_read(fd, (struct usb_raw_ep_io *)&io);
- if (rv < 0 && please_stop_eps) {
+ if (rv < 0) {
printf("EP%x(%s_%s): thread interrupted\n", ep.bEndpointAddress,
transfer_type.c_str(), dir.c_str());
break; And then it works. I'll think about how to implement this more cleanly. |
Raw Gadget patches are now in Waiting for #10 to be reviewed, and then will send another PR with reset handling that fixes this issue (https://github.com/xairy/usb-proxy/commits/reset). |
log
kmsg
This issue when passing through an xbox controller and with my raspberry pi 4B
When trying to run the program the program hangs for 5-10 second before crashing an printing the error
When switching interfaces the program tries to terminate endpoints but one of them hangs when reading and from what I can tell that causes the crash
The proxy works perfectly using dummy raw gadget and also another device (usb drive) which changes interfaces
A wireshark file as a result of proxying the controller is here
The text was updated successfully, but these errors were encountered: