AristoChen / usb-proxy

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

Modify faulty usb endpoint descriptor #8

Closed pr8x closed 1 year ago

pr8x commented 1 year ago

Is it possible to modify usb endpoint descriptors and change the length of a field? I am trying to fix an old USB device that sends a faulty endpoint descriptor (Most likely wrong WMaxPacketSize length). Since the descriptor is invalid it might not be enumerated by libusb, so would this even work with this library?

AristoChen commented 1 year ago

Yes, it is possible to modify the descriptor before sending to the host, you may try to modify or hardcode your preferred descriptor here

https://github.com/AristoChen/usb-proxy/blob/b0ccd74090f3ffc9a7484251771ebb8997d6f7fb/usb-proxy.cpp#L53-L150

pr8x commented 1 year ago

Would this also work when the usb device is not recognized by the system due an error in the endpoint descriptor? Also, can the same be achieved via injection files?

AristoChen commented 1 year ago

Hi,

Are you able to see the usb device via lsusb command? if yes, then I guess should be able to work. However, I don't have such a usb device to test, so no gurantee that this project could work with it.

Currently, injection files might not be able to work with your use cases, I think this feature is complicated, I can add it to my to do list, and if more people are interested in this feature, I may try to figure it out sooner.

pr8x commented 1 year ago

Good news, the device is listed by lsusb and it seems to be operable. However, when running usb-proxy I am not seeing the device forwarded to my PC:

sudo ./usb-proxy --device=20980000.usb --driver=20980000.usb --vendor XXX --product_id YYY

Device is: 20980000.usb Driver is: 20980000.usb vendor_id is: XXX product_id is: YYY Device opened successfully Setup USB config successfully Start for EP0, thread id(1663) event: connect, length: 0 Start hotplug_monitor thread, thread id(1665)

I am using RPI Zero and the USB device is connected to it via an OTG host cable. The other micro usb port is connected to my Windows machine.

EDIT: Just realized that the second USB port is for power only 🤦‍♂️Ok, I guess I need a RPi 3 or something then...

AristoChen commented 1 year ago

If I remember correctly, there is no OTG port on RPi 3, you may want to try RPi 4

pr8x commented 1 year ago

Ok managed to fix my problem by using a Teensy. Thanks for your help though!