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

Support proxying devices with isochronous IN endpoints #23

Merged
merged 5 commits into from
Aug 6, 2024

Conversation

xairy
Copy link
Contributor

@xairy xairy commented Jun 15, 2024

With these changes, I'm able to proxy a few Logitech USB web cameras at a low resolution (160x120 pixels) via dwc3.

Proxying with a higher resolution fails to produce a picture on the host: I think because the transfer rate is too low and all the frames get dropped.

I have not tried other UDCs besides dwc3 yet.

Also fixes #13.

xairy added 2 commits June 14, 2024 20:29
It's used for stopping the proxy.
To allow proxing device with larger configuration descriptors.

Also drop unused definitions.
xairy added a commit to xairy/raw-gadget that referenced this pull request Jun 15, 2024
Proxyied devices that switch between interface altsettings do 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.

To interrupt Raw Gadget transfers, send the SIGUSR1 signal to the endpoint
threads via pthread_kill and add a no-op handler for this signal.

To avoid the endpoints threads being blocked forever on libusb sync I/O
functions, add a timeout of 1 second for them.

As a side-effect, this change makes the proxy print "Operation timed out"
messages every second when there's no activity on an endpoint. We can remove
them, but I think they might be valuable for getting more visibility
into what's happening.

Fixes AristoChen#13.
@xairy xairy force-pushed the iso branch 2 times, most recently from 5f2857a to 7dbbcda Compare June 15, 2024 00:48
@xairy xairy changed the title Support proxying devices with isochronous OUT endpoints Support proxying devices with isochronous IN endpoints Jun 15, 2024
With this change, I'm able to proxy one of Logitech USB web cameras at a
low resolution (160x120 pixels) via dwc3.

Proxying with higher resolutions fails to produce a picture on the host:
I think because the transfer rate is too low and all the frames get dropped.
@xairy
Copy link
Contributor Author

xairy commented Jun 21, 2024

Tested proxying with dwc2 on Raspberry Pi 4: the initial enumeration works, but attempting to stream a picture fails with ioctl(USB_RAW_IOCTL_EP_ENABLE): Cannot allocate memory and dwc2 fe980000.usb: dwc2_hsotg_ep_enable: No suitable fifo found.

I think this happens due to the hardware limitations (no FIFOs for the used packet size?).

I think failing to proxy the device in this case is fine. However, I filed #24 for a possible improvement.

proxy.cpp Outdated
}
}
else {
// For non-0-length requests, we have to trieve the data and
Copy link
Owner

Choose a reason for hiding this comment

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

I guess you mean retrieve instead of trieve?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, fixed and also clarified the comment.

@AristoChen
Copy link
Owner

Hi @xairy

Thanks for the PR! Glad to see ISOC is supported now!

Overall the PR looks good to me, I will find devices to test before merging, thanks again!

Raw Gadget doesn't support it: see [1] for details.

With this change, I'm able to proxy another Logitech web camera.

[1] https://lore.kernel.org/linux-usb/CA+fCnZeLRqk-FOkJ81qMY0NMZC7YnW=beTw=w_DVA=OhOnywRw@mail.gmail.com/T/#u
@xairy
Copy link
Contributor Author

xairy commented Jul 3, 2024

You're welcome!

I recommend using a DWC3-based device for testing, if you have one. Raspberry Pi with its dwc2, unfortunately, doesn't work. Other UDCs I haven't tested.

@AristoChen
Copy link
Owner

I found this document listing some vendors that are using DWC3, I will try if I can get any of them. In the mean time, May I know the model of the device that you used for testing? thanks!

@xairy
Copy link
Contributor Author

xairy commented Jul 4, 2024

I use a ThinkPad X1 Carbon 6th Gen laptop, but getting DWC3 enabled there is tricky: https://xairy.io/articles/thinkpad-xdci. I believe that ROCK Pi uses DWC3, but I haven't tried it myself.

@AristoChen
Copy link
Owner

Using a laptop with DWC3 sounds cool! but unfortunately a bit too expensive 😓.

I got a rockpi 4c+ recently, but it doesn't looks like the OTG port works out of the box, I will find some time to see how to fix it

@AristoChen
Copy link
Owner

I borrowed an NXP i.MX8MP recently, and it also uses dwc3, I will find some time to get a USB camera or something else to test this PR :)

@AristoChen
Copy link
Owner

I am able to proxy the USB webcam with 1920*1080 resolution!

Just out of curiosity, did you run the usb-proxy in a serial console environemt or a ssh environment?

In serial console environment, I am not able to proxy high resolution(I think it is because of the printed messages are too much), while using ssh works a lot better

@xairy
Copy link
Contributor Author

xairy commented Aug 4, 2024

That's awesome!

I was running the proxy locally in a Terminal. Perhaps, the DWC3 controller in my laptop is just slow.

@AristoChen
Copy link
Owner

I see, I am merging the PR now, thanks again for this awesome PR! Glad to see ISOC is now supported!

@AristoChen AristoChen merged commit c6454ce into AristoChen:main Aug 6, 2024
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.

Fix support for proxying devices that switch interface altsettings
2 participants