GithubHelp home page GithubHelp logo

aristochen / usb-proxy Goto Github PK

View Code? Open in Web Editor NEW
130.0 10.0 28.0 73 KB

A USB proxy based on raw-gadget and libusb

License: Apache License 2.0

Makefile 0.74% C++ 97.54% C 1.72%
usb proxy libusb otg raspberry-pi usb-otg mitm mitmproxy man-in-the-middle rpi

usb-proxy's Introduction

usb-proxy

This software is a USB proxy based on raw-gadget and libusb. It is recommended to run this repo on a computer that has an USB OTG port, such as Raspberry Pi 4 or other hardware that can work with raw-gadget, otherwise might need to use dummy_hcd kernel module to set up virtual USB Device and Host controller that connected to each other inside the kernel.

------------     -----------------------------------------------     -----------------------
|          |     |                                             |     |                     |
|          |     |-------------                     -----------|     |-------------        |
|   USB    <----->     USB    |    Host COMPUTER    |   USB    <----->     USB    |  USB   |
|  device  |     |  host port |  running usb-proxy  | OTG port |     |  host port |  Host  |
|          |     |-------------   with raw-gadget   -----------|     |-------------        |
|          |     |                                             |     |                     |
------------     -----------------------------------------------     -----------------------
------------     ------------------------------------
|          |     |                                  |
|          |     |-------------    Host COMPUTER    |
|   USB    <----->     USB    |  running usb-proxy  |
|  device  |     |  host port |   with raw-gadget   |
|          |     |-------------    and dummy_hcd    |
|          |     |                                  |
------------     ------------------------------------

How to use

Step 1: Prerequisite

Please clone the raw-gadget, and compile the kernel modules(if you need dummy_hcd as well, please compile it, otherwise only need to compile raw-gadget) in the repo, then load raw-gadget kernel module, you will be able to access /dev/raw-gadget afterward.

Install the package

sudo apt install libusb-1.0-0-dev libjsoncpp-dev

Step 2: Check device and driver name

Please check the name of device and driver on your hardware with the following command. If you are going to use dummy_hcd, then this step can be skipped, because usb-proxy will use dummy_hcd by default.

# For device name
$ ls /sys/class/udc/
fe980000.usb
# For driver name
$ cat /sys/class/udc/fe980000.usb/uevent
USB_UDC_NAME=fe980000.usb

Note: If you are not able to see the above on your Raspberry Pi 4, probably you didn't enable the dwc2 kernel module, please execute the following command and try again after reboot.

$ echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
$ echo "dwc2" | sudo tee -a /etc/modules
$ sudo reboot

Step 3: Check vendor_id and product_id of USB device

Please plug the USB device that you want to test into Raspberry Pi 4, then execute lsusb on terminal.

$ lsusb
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 1b3f:2247 Generalplus Technology Inc. GENERAL WEBCAM
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

As you can see, There is a Bus 001 Device 003: ID 1b3f:2247 Generalplus Technology Inc. GENERAL WEBCAM, and 1b3f:2247 is the vendor_id and product_id with a colon between them.

Step 4: Run

Usage:
    -h/--help: print this help message
    -v/--verbose: increase verbosity
    --device: use specific device
    --driver: use specific driver
    --vendor_id: use specific vendor_id(HEX) of USB device
    --product_id: use specific product_id(HEX) of USB device
    --enable_injection: enable the injection feature
    --injection_file: specify the file that contains injection rules
  • If device not specified, usb-proxy will use dummy_udc.0 as default device.
  • If driver not specified, usb-proxy will use dummy_udc as default driver.
  • If both vendor_id and product_id not specified, usb-proxy will connect the first USB device it can find.

For example:

$ ./usb-proxy --device=fe980000.usb --driver=fe980000.usb --vendor_id=1b3f --product_id=2247

Please replace fe980000.usb with the device that you have when running this software, and then replace the driver variable with the string after USB_UDC_NAME= in step 2. Please also modify the vendor_id and product_id variable that you have checked in step 3.


How to do MITM attack with this project

This feature is still very simple. Ideas or suggestions are very welcome.

Step 1: Create rules

Please edit the injection.json for the injection rules. The following is the default template.

Note: The comment in the following template is only for explaining the meaning, please do not copy the comment, it is invalid in json.

{
	"control": {
        "modify": [ // For modify the control transfer data
            {
                "enable": false, // Enable this rule or not
                "bRequestType": 0, // Hex value
                "bRequest": 0, // Hex value
                "wValue": 0, // Hex value
                "wIndex": 0, // Hex value
                "wLength": 0, // Hex value
                "content_pattern": [], // If USB packet contains any data that match any patterns, the matched data will be replaced with the value in "replacement". Format is Hex string, for example: \\x01\\x00\\x00\\x00
                "replacement": "" // The content after modified. Format is Hex string, for example: \\x02\\x00\\x00\\x00
            }
        ],
        "ignore": [ // For ignoring control transfer packet, it won't be sent to Host/Device if match the rule
            {
                "enable": false,
                "bRequestType": 0,
                "bRequest": 0,
                "wValue": 0,
                "wIndex": 0,
                "wLength": 0,
                "content_pattern": []
            }
        ],
        "stall": [ // For stalling Host if match the rule
            {
                "enable": false,
                "bRequestType": 0,
                "bRequest": 0,
                "wValue": 0,
                "wIndex": 0,
                "wLength": 0,
                "content_pattern": []
            }
        ]
    },
    "int": [
        {
            "ep_address": 81, // Endpoint address in Hex
            "enable": false,
            "content_pattern": [],
            "replacement": ""
        }
    ],
    "bulk": [
        {
            "ep_address": 81,
            "enable": false,
            "content_pattern": [],
            "replacement": ""
        }
    ],
	"isoc": [] // This transfer type is not supported yet
}

For example, the following rules work with my USB mouse, and convert left click to right click, and convert right click to left click.

{
    "control": {
        "modify": [],
        "ignore": [],
        "stall": []
    },
    "int": [
        {
            "ep_address": 81,
            "enable": true,
            "content_pattern": ["\\x01\\x00\\x00\\x00"],
            "replacement": "\\x02\\x00\\x00\\x00"
        },
        {
            "ep_address": 81,
            "enable": true,
            "content_pattern": ["\\x02\\x00\\x00\\x00"],
            "replacement": "\\x01\\x00\\x00\\x00"
        }
    ],
    "bulk": [],
    "isoc": []
}

Step 2: Run

Use the --enable_injection to enable this feature, and use --injection_file to specify the file path of your customized injection rules, if it is not specified, usb-proxy will use injection.json by default.

For example

$ ./usb-proxy --device=fe980000.usb --driver=fe980000.usb --enable_injection --injection_file=myInjectionRules.json

usb-proxy's People

Contributors

aristochen avatar msawahara avatar xairy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

usb-proxy's Issues

Automatically remap endpoint addresses based on their capabilities

Right now, USB Proxy tried to use the same addresses for UDC endpoints as the addresses that are provided in the USB descriptors of the proxied device. This doesn't always work, as UDC endpoints might not support the required addresses or capabilities.

Instead, we need to dynamically remap the endpoint addresses; see assign_ep_address in the Raw Gadget examples for reference.

This issue has previously came up here.

Fix support for proxying devices that switch interface altsettings

Even though #6 added basic support for devices that switch between interface altsettings, it might 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.

Interrupting Raw Gadget transfers is simple: just send any signal to the endpoint threads via pthread_kill and add a no-op handler for this signal (but perhaps a signal other than SIGINT, as USB Proxy already uses this signal internally).

However, interrupting the libusb transfers is a problem.

A simple solution would be use the timeout argument of the libusb sync I/O API, but unfortunately libusb has a bug that makes sync I/O ignore the timeout argument.

We need to either switch to using async libusb I/O or figure out another way to interrupt libusb transfers (without fully resetting the device, as done in #14).

Ah, actually libusb timeouts work as expected, it's just that receive_data zeroes out timeout.

Unable to exit normally

int main(int argc, char **argv)
{
    const char *device = "dummy_udc.0";
    const char *driver = "dummy_udc";
    int vendor_id = -1;
    int product_id = -1;

    struct sigaction action;
    memset(&action, 0, sizeof(struct sigaction));
    action.sa_handler = handle_signal;
    sigaction(SIGTERM, &action, NULL);
    sigaction(SIGINT, &action, NULL);

    //........................................................
    printf("Device is: %s\n", device);
    printf("Driver is: %s\n", driver);
    printf("vendor_id is: %d\n", vendor_id);
    printf("product_id is: %d\n", product_id);

    if (injection_enabled) {
        printf("Injection enabled\n");
        if (injection_file.empty()) {
            printf("Injection file not specified\n");
            return 1;
        }
        struct stat buffer;
        if (stat(injection_file.c_str(), &buffer) != 0) {
            printf("Injection file %s not found\n", injection_file.c_str());
            return 1;
        }

        Json::Reader jsonReader;
        std::ifstream ifs(injection_file.c_str());
        if (jsonReader.parse(ifs, injection_config))
            printf("Parsed injection file: %s\n", injection_file.c_str());
        else {
            printf("Error parsing injection file: %s\n", injection_file.c_str());
            return 1;
        }
        ifs.close();
    }

    //.......................................................
    while (connect_device(vendor_id, product_id)) {
        sleep(1);
    }
    printf("Device opened successfully\n");

    setup_host_usb_desc();
    printf("Setup USB config successfully\n");

    int fd = usb_raw_open();
    usb_raw_init(fd, USB_SPEED_HIGH, driver, device);
    usb_raw_run(fd);

    ep0_loop(fd);

    close(fd);
    //---------here-1------------------------
    int bNumConfigurations = device_device_desc.bNumConfigurations;
    for (int i = 0; i < bNumConfigurations; i++) {
        int bNumInterfaces = device_config_desc[i]->bNumInterfaces;
        for (int j = 0; j < bNumInterfaces; j++) {
            int num_altsetting = device_config_desc[i]->interface[j].num_altsetting;
            for (int k = 0; k < num_altsetting; k++) {
                delete[] host_device_desc.configs[i].interfaces[j].altsettings[k].endpoints;
            }
            delete[] host_device_desc.configs[i].interfaces[j].altsettings;
        }
        delete[] host_device_desc.configs[i].interfaces;
    }
    //---------here-2------------------------
    delete[] host_device_desc.configs;
    delete[] device_config_desc;

    if (context && callback_handle != -1) {
        libusb_hotplug_deregister_callback(context, callback_handle);
    }
    if (hotplug_monitor_thread &&
        pthread_join(hotplug_monitor_thread, NULL)) {
        fprintf(stderr, "Error join hotplug_monitor_thread\n");
    }

    return 0;
}

Hello author:
When sending a signal to the program through kill SIGINT, the program cannot exit normally and cannot reach the position of here-2 at all

reset device may trigger hotplug thread and the process will be killed

Based on the discussion, we may need to implement a mechanism to prevent the hotplug thread kill the process if the Host send reset request

These might not be the best solution, but what I have in my mind now are

  1. Stop the hotplug thread before reset, and try to restart the hotplug thread after reset
  2. Add a flag like this commit to let user decide whether the hotplug thread should be created or not, which will be default yes.

Xbox handle for mapping

hello, author:
When I use the Xbox handle for mapping, this problem occurs, It failed

//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
w@w-BoDE-WXX9:~/Downloads/UbuntuKO$ uname -a
Linux w-BoDE-WXX9 5.15.0-89-generic #99~20.04.1-Ubuntu SMP Thu Nov 2 15:16:47 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------

w@w-BoDE-WXX9:~/Downloads/UbuntuKO$ lsmod | grep -E "dummy_hcd|raw_gadget"
raw_gadget             40960  0
dummy_hcd              45056  0

//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
w@w-BoDE-WXX9:~/Downloads/UbuntuKO$ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 27c6:5125 Shenzhen Goodix Technology Co.,Ltd. Goodix Fingerprint Device
Bus 001 Device 003: ID 0408:1040 Quanta Computer, Inc. ov9734_techfront_camera
Bus 001 Device 044: ID 045e:0b12 Microsoft Corp. Controller
Bus 001 Device 005: ID 8087:0026 Intel Corp.
Bus 001 Device 046: ID 0bda:8152 Realtek Semiconductor Corp. RTL8152 Fast Ethernet Adapter
Bus 001 Device 045: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------

w@w-BoDE-WXX9:~/Downloads/UbuntuKO$ lsusb -v -d 045e:0b12

Bus 001 Device 044: ID 045e:0b12 Microsoft Corp. Controller
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass        71
  bDeviceProtocol       208
  bMaxPacketSize0        64
  idVendor           0x045e Microsoft Corp.
  idProduct          0x0b12
  bcdDevice            5.09
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0077
    bNumInterfaces          3
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     71
      bInterfaceProtocol    208
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               4
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     71
      bInterfaceProtocol    208
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               2
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     71
      bInterfaceProtocol    208
      iInterface              0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     71
      bInterfaceProtocol    208
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x00e4  1x 228 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     71
      bInterfaceProtocol    208
      iInterface              0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     71
      bInterfaceProtocol    208
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x04  EP 4 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0

//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------

w@w-BoDE-WXX9:~/Downloads/UbuntuKO$ ls /sys/class/udc/
dummy_udc.0  usbip-vudc.0
w@w-BoDE-WXX9:~/Downloads/UbuntuKO$ cat /sys/class/udc/dummy_udc.0/uevent
USB_UDC_NAME=dummy_udc

//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
w@w-BoDE-WXX9:~/Downloads/UbuntuKO$ sudo ./usb-proxy --vendor_id=045e --product_id=0b12 --verbose
Device is: dummy_udc.0
Driver is: dummy_udc
vendor_id is: 1118
product_id is: 2834
9 Devices in list
Target device not found
Device opened successfully
InterfaceNumber 1 AlternateSetting 0 has no endpoint, skip
InterfaceNumber 2 AlternateSetting 0 has no endpoint, skip
Setup USB config successfully
Start hotplug_monitor thread, thread id(2670)
Start for EP0, thread id(2668)
ep #0:
  name: ep1in-bulk
  addr: 1
  type: ___ blk ___
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #1:
  name: ep2out-bulk
  addr: 2
  type: ___ blk ___
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #2:
  name: ep5in-int
  addr: 5
  type: ___ ___ int
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #3:
  name: ep6in-bulk
  addr: 6
  type: ___ blk ___
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #4:
  name: ep7out-bulk
  addr: 7
  type: ___ blk ___
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #5:
  name: ep10in-int
  addr: 10
  type: ___ ___ int
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #6:
  name: ep11in-bulk
  addr: 11
  type: ___ blk ___
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #7:
  name: ep12out-bulk
  addr: 12
  type: ___ blk ___
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #8:
  name: ep15in-int
  addr: 15
  type: ___ ___ int
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #9:
  name: ep1out-bulk
  addr: 1
  type: ___ blk ___
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #10:
  name: ep2in-bulk
  addr: 2
  type: ___ blk ___
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #11:
  name: ep-aout
  addr: 255
  type: ___ blk int
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #12:
  name: ep-bin
  addr: 255
  type: ___ blk int
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #13:
  name: ep-cout
  addr: 255
  type: ___ blk int
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #14:
  name: ep-dout
  addr: 255
  type: ___ blk int
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #15:
  name: ep-ein
  addr: 255
  type: ___ blk int
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #16:
  name: ep-fout
  addr: 255
  type: ___ blk int
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #17:
  name: ep-gin
  addr: 255
  type: ___ blk int
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #18:
  name: ep-hout
  addr: 255
  type: ___ blk int
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #19:
  name: ep-iout
  addr: 255
  type: ___ blk int
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #20:
  name: ep-jin
  addr: 255
  type: ___ blk int
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #21:
  name: ep-kout
  addr: 255
  type: ___ blk int
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
ep #22:
  name: ep-lin
  addr: 255
  type: ___ blk int
  dir : in  ___
  maxpacket_limit: 65535
  max_streams: 16
ep #23:
  name: ep-mout
  addr: 255
  type: ___ blk int
  dir : ___ out
  maxpacket_limit: 65535
  max_streams: 16
event: connect, length: 0
libusb: error [udev_hotplug_event] ignoring udev action change
libusb: error [udev_hotplug_event] ignoring udev action change
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0100, wIndex: 0x0000, wLength: 64
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_DEVICE
Control transfer succeed
ep0: transferred 18 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0100, wIndex: 0x0000, wLength: 18
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_DEVICE
Control transfer succeed
ep0: transferred 18 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0200, wIndex: 0x0000, wLength: 9
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_CONFIG
Control transfer succeed
ep0: transferred 9 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0200, wIndex: 0x0000, wLength: 119
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_CONFIG
Control transfer succeed
ep0: transferred 119 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0300, wIndex: 0x0000, wLength: 255
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_STRING
Control transfer succeed
ep0: transferred 4 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0302, wIndex: 0x0409, wLength: 255
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_STRING
Control transfer succeed
ep0: transferred 22 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0301, wIndex: 0x0409, wLength: 255
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_STRING
Control transfer succeed
ep0: transferred 20 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0303, wIndex: 0x0409, wLength: 255
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_STRING
Control transfer succeed
ep0: transferred 58 bytes (in)
event: control, length: 8
  bRequestType: 0x00 (OUT), bRequest: 0x09, wValue: 0x0001, wIndex: 0x0000, wLength: 0
  type = USB_TYPE_STANDARD
  req = USB_REQ_SET_CONFIGURATION
Activating 2 endpoints on interface 0
int_out: addr = 2, ep = #1
Creating thread for EP02
int_in: addr = 2, ep = #10
Creating thread for EP82
Start writing thread for EP02, thread id(2674)
Start reading thread for EP02, thread id(2673)
Start reading thread for EP82, thread id(2675)
process_eps done
Start writing thread for EP82, thread id(2676)
Activating 0 endpoints on interface 1
process_eps done
Activating 0 endpoints on interface 2
process_eps done
libusb: error [udev_hotplug_event] ignoring udev action change
EP2(int_out): read 5 bytes from host
EP2(int_out): enqueued 5 bytes to queue
EP82(int_in): enqueued 8 bytes to queue
EP82(int_in): wrote 8 bytes to host
libusb: error [udev_hotplug_event] ignoring udev action bind
EP82(int_in): enqueued 8 bytes to queue
EP82(int_in): wrote 8 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host
EP82(int_in): enqueued 48 bytes to queue
EP82(int_in): wrote 48 bytes to host

host to device transfer size

Hi, I've tested on Raspberry PI 4 and BeagleBone Black and on both there seems to be an issue with data from host to device.
The issue may come from raw-gadget itself but I'm not sure what would be the right approach.
It seems that when we get data from the host, it could contain more than just one packet (up to info.eps[i].limits.maxpacket_limit) which aside from the weird behavior on the actual device, it may also get lost when sent via libusb_interrupt_transfer in send_data (I'm unable to actually verify this on the device).

On BeagleBone Black I can see this when adding traces for data reception in ep_loop_read:

#[email protected]>481B/0x07/out
#[email protected]>545B/0x07/out
#[email protected]>481B/0x07/out
#[email protected]>545B/0x07/out
#[email protected]>545B/0x07/out
#[email protected]>481B/0x07/out
#[email protected]>481B/0x07/out
#[email protected]>481B/0x07/out
#[email protected]>481B/0x07/out 
#[email protected]>417B/0x07/out
#[email protected]> 33B/0x07/out
#[email protected]> 33B/0x07/out
#[email protected]> 33B/0x07/out

Meaning that at 253.250 (sec.ms) from starting the proxy it received 480 bytes (see first message - I added 1 byte because I am preserving the endpoint info for my own use).
Sometimes the transfer size equals actual payload like in the last 3 cases where 32 bytes were received.

On BeagleBone Black, the maxpacket_limit is reported to be 512 for the EPs assigned for use via proxy.
Any chance this can be tuned to only process one message at a time?

On Raspberry PI 4 the behavior is worse as it transfers 1024 bytes at a time most of the time and sometimes it gets blocked for a second with no transfer at all but the Raspberry PI is somewhat known to exhibit USB issues.

The transfers from device to host don't show any issue and they respect the expected message size.

Thanks in advance for any feedback

hotplug_callback bug

int hotplug_callback(struct libusb_context *ctx __attribute__((unused)),
			struct libusb_device *dev __attribute__((unused)),
			libusb_hotplug_event envet __attribute__((unused)),
			void *user_data __attribute__((unused))) {
	printf("Hotplug event\n");

	kill(0, SIGINT);
	return 0;
}

Suggest replacing the kill 0 line with another one. I have integrated it into the Android system. When plugging in or unplugging peripherals, it may send a SIGINT signal to the init 0 process, causing system issues.

why event.inner.length == 4294967295 ep0_loop return

I run usb-proxy in banana pi m2 plus, when i disconnect usb device from broad then raw_gadget return 4294967295, this number ep0_loop break, so usb_proxy main thread Segmentation fault
./usb-proxy --device=musb-hdrc.4.auto --driver=musb-hdrc
Device is: musb-hdrc.4.auto
Driver is: musb-hdrc
vendor_id is: -1
product_id is: -1
Device opened successfully
Setup USB config successfully
Start hotplug_monitor thread, thread id(10504)
Start for EP0, thread id(10487)
event: connect, length: 0
Hotplug event
Received SIGINT, stopping...
event: unknown, length: 4294967295
End for EP0, thread id(10487)
Segmentation fault

i want to known why event.inner.length == 4294967295 ep0_loop return,thanks

error Proxing a keyboard: ioctl(USB_RAW_IOCTL_EP0_WRITE): Cannot send after transport endpoint shutdown

first of all thanks for sharing your work, I successfuly proxied a ethernet adapter but fails with all HID i have

pi@raspberrypi:~/usb-proxy $ sudo ./usb-proxy --device=fe980000.usb --driver=fe980000.usb --vendor_id=1997 --product_id=2433
Device is: fe980000.usb
Driver is: fe980000.usb
vendor_id is: 6551
product_id is: 9267
Device opened successfully
Start hotplug_monitor thread, thread id(2326)
Setup USB config successfully
Start for EP0, thread id(2324)
event: connect, length: 0
event: control, length: 8
bRequestType: 0x80 (IN), bRequest: 0x06, wValue: 0x0100, wIndex: 0x0000, wLength: 64
type = USB_TYPE_STANDARD
req = USB_REQ_GET_DESCRIPTOR
desc = USB_DT_DEVICE
ep0: transferred 18 bytes (in)
event: control, length: 8
bRequestType: 0x80 (IN), bRequest: 0x06, wValue: 0x0100, wIndex: 0x0000, wLength: 18
type = USB_TYPE_STANDARD
req = USB_REQ_GET_DESCRIPTOR
desc = USB_DT_DEVICE
ep0: transferred 18 bytes (in)
event: control, length: 8
bRequestType: 0x80 (IN), bRequest: 0x06, wValue: 0x0200, wIndex: 0x0000, wLength: 255
type = USB_TYPE_STANDARD
req = USB_REQ_GET_DESCRIPTOR
desc = USB_DT_CONFIG
ioctl(USB_RAW_IOCTL_EP0_WRITE): Cannot send after transport endpoint shutdown

Any idea whats causing this?

unable to compile project

hi, i tried to compile project, but i get error:

root@raspberrypi:/home/user/raw-gadget/raw_gadget# make
make -C /lib/modules/6.1.21-v8+/build M=/home/user/raw-gadget/raw_gadget SUBDIRS=/home/user/raw-gadget/raw_gadget modules
make[1]: Entering directory '/root/linux-0afb5e98488aed7017b9bf321b575d0177feb7ed'
  CC [M]  /home/user/raw-gadget/raw_gadget/raw_gadget.o
/home/user/raw-gadget/raw_gadget/raw_gadget.c: In function ‘raw_ioctl_run’:
/home/user/raw-gadget/raw_gadget/raw_gadget.c:595:8: error: implicit declaration of function ‘usb_gadget_probe_driver’; did you mean ‘usb_gadget_frame_number’? [-Werror=implicit-function-declaration]
  595 |  ret = usb_gadget_probe_driver(&dev->driver);
      |        ^~~~~~~~~~~~~~~~~~~~~~~
      |        usb_gadget_frame_number
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:250: /home/user/raw-gadget/raw_gadget/raw_gadget.o] Error 1
make[1]: *** [Makefile:2012: /home/user/raw-gadget/raw_gadget] Error 2
make[1]: Leaving directory '/root/linux-0afb5e98488aed7017b9bf321b575d0177feb7ed'
make: *** [Makefile:8: default] Error 2
root@raspberrypi:/home/user/raw-gadget/raw_gadget# 
Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux
root@raspberrypi:/home/user/raw-gadget/raw_gadget# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

PS handle for mapping, this problem occurs

When I use the PS handle for mapping, this problem occurs,
Just use the Xbox handle, thank you

root@eden:usb-proxy# ./usb-proxy --device=usbip-vudc.0 --driver=usbip-vudc --vendor_id=054c --product_id=0ce6
Device is: usbip-vudc.0
Driver is: usbip-vudc
vendor_id is: 1356
product_id is: 3302
Device opened successfully
Start hotplug_monitor thread, thread id(29557)
InterfaceNumber 0 AlternateSetting 0 has no endpoint, skip
InterfaceNumber 1 AlternateSetting 0 has no endpoint, skip
InterfaceNumber 2 AlternateSetting 0 has no endpoint, skip
Setup USB config successfully
Start for EP0, thread id(29547)
event: connect, length: 0

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

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

libusb_handle_events_completed cause seqfault

Hi. Nice work!
I have some problems with running proxy.

Is it possible to "mitm" the communication between the flash drive and my external computer?

"pendrive" <-> (USB <- raspberrypi -> USB OTG) <-> my external pc

My setup:
Raspberry Pi 4 B - 8gb ram
Kernel 5.15.34
libusb-1.0.25

Im getting seqfault in libusb_handle_events_completed(NULL, NULL);
Zrzut ekranu 2022-05-1 o 18 10 03
stacktrace:
Zrzut ekranu 2022-05-1 o 18 10 17

After commenting this line libusb_handle_events_completed(NULL, NULL); it looks working better, but still failing?

Device is: fe980000.usb
Driver is: fe980000.usb
vendor_id is: 2316
product_id is: 4096
5 Devices in list
Target device not found
Device opened successfully
Setup USB config successfully
Start hotplug_monitor thread, thread id(3243)
Start for EP0, thread id(3241)
event: connect, length: 0
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0100, wIndex: 0x0000, wLength: 18
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_DEVICE
Control transfer succeed
ep0: transferred 18 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0302, wIndex: 0x0409, wLength: 2
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_STRING
Control transfer succeed
ep0: transferred 2 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0302, wIndex: 0x0409, wLength: 18
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_STRING
Control transfer succeed
ep0: transferred 18 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0301, wIndex: 0x0409, wLength: 2
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_STRING
Control transfer succeed
ep0: transferred 2 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0301, wIndex: 0x0409, wLength: 32
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_STRING
Control transfer succeed
ep0: transferred 32 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0f00, wIndex: 0x0000, wLength: 5
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_BOS
Control transfer succeed
ep0: transferred 5 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0f00, wIndex: 0x0000, wLength: 22
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_BOS
Control transfer succeed
ep0: transferred 22 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0200, wIndex: 0x0000, wLength: 9
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_CONFIG
Control transfer succeed
ep0: transferred 9 bytes (in)
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0200, wIndex: 0x0000, wLength: 44
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_CONFIG
Control transfer succeed
ep0: transferred 44 bytes (in)
event: control, length: 8
  bRequestType: 0x00 (OUT), bRequest: 0x09, wValue: 0x0001, wIndex: 0x0000, wLength: 0
  type = USB_TYPE_STANDARD
  req = USB_REQ_SET_CONFIGURATION
Found desired configuration at index: 0
ep #0:
  name: ep1in
  addr: 1
  type: iso blk int
  dir : in  ___
  maxpacket_limit: 1024
  max_streams: 0
ep #1:
  name: ep1out
  addr: 1
  type: iso blk int
  dir : ___ out
  maxpacket_limit: 1024
  max_streams: 0
ep #2:
  name: ep2in
  addr: 2
  type: iso blk int
  dir : in  ___
  maxpacket_limit: 1024
  max_streams: 0
ep #3:
  name: ep2out
  addr: 2
  type: iso blk int
  dir : ___ out
  maxpacket_limit: 1024
  max_streams: 0
ep #4:
  name: ep3in
  addr: 3
  type: iso blk int
  dir : in  ___
  maxpacket_limit: 1024
  max_streams: 0
ep #5:
  name: ep3out
  addr: 3
  type: iso blk int
  dir : ___ out
  maxpacket_limit: 1024
  max_streams: 0
ep #6:
  name: ep4in
  addr: 4
  type: iso blk int
  dir : in  ___
  maxpacket_limit: 1024
  max_streams: 0
ep #7:
  name: ep4out
  addr: 4
  type: iso blk int
  dir : ___ out
  maxpacket_limit: 1024
  max_streams: 0
ep #8:
  name: ep5in
  addr: 5
  type: iso blk int
  dir : in  ___
  maxpacket_limit: 1024
  max_streams: 0
ep #9:
  name: ep5out
  addr: 5
  type: iso blk int
  dir : ___ out
  maxpacket_limit: 1024
  max_streams: 0
ep #10:
  name: ep6in
  addr: 6
  type: iso blk int
  dir : in  ___
  maxpacket_limit: 1024
  max_streams: 0
ep #11:
  name: ep6out
  addr: 6
  type: iso blk int
  dir : ___ out
  maxpacket_limit: 1024
  max_streams: 0
ep #12:
  name: ep7in
  addr: 7
  type: iso blk int
  dir : in  ___
  maxpacket_limit: 1024
  max_streams: 0
ep #13:
  name: ep7out
  addr: 7
  type: iso blk int
  dir : ___ out
  maxpacket_limit: 1024
  max_streams: 0
bNumEndpoints is 2
bulk_out: addr = 1, ep = #1
Creating thread for EP01
Start reading thread for EP01, thread id(3244)
bulk_in: addr = 2, ep = #2
Creating thread for EP82
Start writing thread for EP01, thread id(3245)
Start reading thread for EP82, thread id(3246)
process_eps done
Start writing thread for EP82, thread id(3247)
event: control, length: 8
  bRequestType: 0xa1  (IN), bRequest: 0xfe, wValue: 0x0000, wIndex: 0x0000, wLength: 1
  type = USB_TYPE_CLASS
  req = unknown = 0xfe
Control transfer succeed
ep0: transferred 1 bytes (in)
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 36 bytes to queue
EP82(bulk_in): wrote 36 bytes to host
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 36 bytes to queue
EP82(bulk_in): wrote 36 bytes to host
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 13 bytes to host
event: control, length: 8
  bRequestType: 0x80  (IN), bRequest: 0x06, wValue: 0x0300, wIndex: 0x0000, wLength: 255
  type = USB_TYPE_STANDARD
  req = USB_REQ_GET_DESCRIPTOR
  desc = USB_DT_STRING
Control transfer succeed
ep0: transferred 4 bytes (in)
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 18 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 18 bytes to host
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 8 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 8 bytes to host
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 4 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 4 bytes to host
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 36 bytes to queue
EP82(bulk_in): wrote 36 bytes to host
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 512 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 512 bytes to host
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 512 bytes to queue
EP82(bulk_in): wrote 512 bytes to host
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 512 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 512 bytes to host
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 512 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 512 bytes to host
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 512 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 512 bytes to host
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 512 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
EP82(bulk_in): wrote 512 bytes to host
EP82(bulk_in): wrote 13 bytes to host
EP1(bulk_out): read 31 bytes from host
EP1(bulk_out): enqueued 31 bytes to queue
EP82(bulk_in): enqueued 1024 bytes to queue
EP82(bulk_in): enqueued 512 bytes to queue
EP82(bulk_in): enqueued 13 bytes to queue
ioctl(USB_RAW_IOCTL_EP_WRITE): Cannot send after transport endpoint shutdown
ioctl(USB_RAW_IOCTL_EP_READ): Cannot send after transport endpoint shutdown

Modify faulty usb endpoint descriptor

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?

Dynamically select emulated device speed

The proxy currently always uses USB_SPEED_HIGH for emulating devices.

We need to dynamically figure out the actual speed of the device via libusb_get_device_speed and use that for usb_raw_init.

We then also need to improve #10 to patch in the right bMaxPacketSize0 depending on the used speed. Note that the speed provided to usb_raw_init is merely a hint, and the UDC might decide to use a different one. To find out which speed UDC decided to use, we need to resolve xairy/raw-gadget#41 first.

Not a critical issue, filing to not forget.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.