xairy / raw-gadget

USB Raw Gadget — a low-level interface for the Linux USB Gadget subsystem
357 stars 37 forks source link

Possibility of emulating a USB hub for multiple devices? #78

Closed Berghopper closed 2 months ago

Berghopper commented 2 months ago

Not super familiar with the USB spec. But I do know that USB hubs have their own protocol. Would it be anyhow possible to emulate different devices with raw_gadget? (not just adding more endpoints, but actually different devices)..

Would this require some extra features kernel-wise to be able to do this, or do we need extra hardware? (like a usb hub controller?)

In some cases this might be very useful and avoid having to use multiple UDCs.

For reference: Chapter 11 of usb 2.0 spec

xairy commented 2 months ago

Emulating a USB hub is only possible with an Aspeed UDC. I never tried this myself though. Other UDCs just don't support this.

But emulating any type of a normal device should be possible minding the existing limitations without any kernel changes.

Berghopper commented 2 months ago

Thanks for answering! Working on a project to emulate multiple 360 controllers, hence why the question :).

My next and last resort would be the 360 wireless receiver, since it actually acts as 1 device, but can support up to 4 controllers.

xairy commented 1 month ago

You can technically emulate a single USB device with up to 255 HID interfaces, each of which acting as a separate input source. That's what that 360 wireless receiver likely does. Maybe this will work for your use case.

Berghopper commented 1 month ago

@xairy Seems to work indeed:

https://github.com/Berghopper/360-w-raw-gadget/

It's not quite recognized as two separate devices, but xinput definitely registers 2 control surfaces/controllers! :)

Also I had to change the wireless receiver's protocol to that of a 'normal' controller (little bit of cheating there).

xairy commented 1 month ago

That's awesome! It's great to see Raw Gadget being useful!

Thanks for noting that FunctionFS does not support providing that vendor-specific descriptor. I wasn't aware of this limitation.