Code Monkey home page Code Monkey logo

usbip's Introduction

usbip

Coverage Status crates.io

A Rust library to run a USB/IP server to simulate USB devices.

It also enables sharing devices from an OS supporting libusb(libusb claims that it supports Linux, macOS, Windows, OpenBSD/NetBSD, Haiku and Solaris) to another OS supporting USB/IP(Linux, Windows). Sharing an CCID SmartCard from macOS to Linux is tested by running gpg --card-status.

How to use

See examples directory. Three examples are provided:

  1. hid_keyboard: Simulate a hid keyboard that types something every second.
  2. cdc_acm_serial: Simulate a serial that gets a character every second.
  3. host: Act like original usb/ip sharing server, sharing one device from one machine to another. Also supports sharing from macOS to Linux!

To run example, run:

$ env RUST_LOG=info cargo run --example hid_keyboard

Then, in a USB/IP client environment:

$ usbip list -r $remote_ip
$ usbip attach -r $remote_ip -b $bus_id

Then, you can inspect the simulated USB device behavior in both sides.

API

See code comments. Not finalized yet, so get prepared for api breaking changes.

usbip's People

Contributors

313ctric avatar h7x4 avatar jamesadevine avatar jiegec avatar linkmauve avatar oysteintveit-nordicsemi 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  avatar

usbip's Issues

WebAssembly + WebUSB support

Hello! I'm curious if you or anyone is considering porting this to WebAssembly so that it can be combined with WebUSB. I have a project idea where I transport USB/IP over WebSockets to share device from the browser to a web server.

Cannot use library because of error E0658

If I include the library in my Cargo.toml the project will not compile because of the following error:

error[E0658]: use of unstable library feature 'thread_local_const_init'
  --> /home/******/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.20.0/src/coop.rs:34:1
   |
34 | / thread_local! {
35 | |     static CURRENT: Cell<Budget> = const { Cell::new(Budget::unconstrained()) };
36 | | }
   | |_^
   |
   = note: see issue #84223 <https://github.com/rust-lang/rust/issues/84223> for more information
   = help: add `#![feature(thread_local_const_init)]` to the crate attributes to enable
   = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info)

It seems to have something to do with tokio that is used by usbip.

Unknown command when listing devices from Windows USB/IP client

Trying to use usb/ip to share a gaming steering wheel from a new macbook to a windows machine. I installed this rust usbip server on my m2 macbook and started the host example:

% env RUST_LOG=debug cargo run --example host
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Running target/debug/examples/host
[2023-09-19T22:20:06Z INFO usbip] Got connection from Ok(192.168.2.99:40304)
[2023-09-19T22:20:06Z WARN usbip] Got unknown command [1, 6, 128, 5]
[2023-09-19T22:20:06Z WARN usbip] Got unknown command [0, 0, 0, 0]

But I get the above warning and no response when I try to list the devices from Windows using the usb/ip client (v0.2..0 or v0.1.0) this command: usbip --list 192.168.2.168

Should this be a supported configuration?

Prevent panic on invalid interface number

At https://github.com/jiegec/usbip/blob/master/src/device.rs#L349, setup_packet.index is sometimes (much) larger than the number of interfaces, I got 514, 1284, 264, 520, 1034 and 1290 for instance on a device with only 12 interfaces.

Since all of them seem to be in range modulo 256, I could add such a modulo but I’d prefer someone accustomed to USB to verify that this is indeed the correct fix.

The modulo otherwise fixes this panic:

thread 'tokio-runtime-worker' panicked at 'index out of bounds: the len is 12 but the index is 514', src/device.rs:349:37

devices no longer recognized since ecc21544

For example, the cdc_acm_serial example is no longer working in master since ecc2154

Steps to reproduce:

$ git checkout ecc2154444683f0d33b36a45f5ae58b7ea4dd04d
$ cargo run --example cdc_acm_serial &
$ sudo usbip attach -r 127.0.0.1 -b 0-0-0
$ lsusb | grep 0000
$ dmesg
[1406626.087302] vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3)
[1406626.087306] vhci_hcd vhci_hcd.0: devid(0) speed(3) speed_str(high-speed)
[1406626.087313] vhci_hcd vhci_hcd.0: Device attached
[1406626.304190] usb 7-1: new high-speed USB device number 69 using vhci_hcd

The previous commit was working as expected

$ git checkout ecc2154444683f0d33b36a45f5ae58b7ea4dd04d~1
$ cargo run --example cdc_acm_serial &
$ sudo usbip attach -r 127.0.0.1 -b 0
$ lsusb | grep 0000
Bus 007 Device 068: ID 0000:0000 Manufacturer Product
$ dmesg
[1406416.086748] vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3)
[1406416.086753] vhci_hcd vhci_hcd.0: devid(0) speed(3) speed_str(high-speed)
[1406416.086760] vhci_hcd vhci_hcd.0: Device attached
[1406416.304218] usb 7-1: new high-speed USB device number 68 using vhci_hcd
[1406416.418213] usb 7-1: SetAddress Request (68) to port 0
[1406416.676329] usb 7-1: New USB device found, idVendor=0000, idProduct=0000, bcdDevice= 0.00
[1406416.676334] usb 7-1: New USB device strings: Mfr=2, Product=3, SerialNumber=4
[1406416.676337] usb 7-1: Product: Product
[1406416.676339] usb 7-1: Manufacturer: Manufacturer
[1406416.676340] usb 7-1: SerialNumber: Serial
[1406416.840288] cdc_acm 7-1:1.0: ttyACM0: USB ACM device

attach to example keyboard failed

Env:
ubuntu 22.04
kernel: 6.2.0-26-generic
usbip (usbip-utils 2.0)

Commands:
env RUST_LOG=info cargo run --example hid_keyboard

On another terminal:
sudo usbip list -r 127.0.0.1 works OK
sudo usbip attach -r 127.0.0.1 -b 0 panic:

thread 'tokio-runtime-worker' panicked at 'not implemented: hid request SetupPacket { request_type: 33, request: 10, value: 0, index: 0, length: 0 }', src/hid.rs:109:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: PoisonError { .. }', examples/hid_keyboard.rs:34:42

Host Panic on MacOS

Example program host would panic on MacOS with LIBUSB_ERROR_NOT_FOUND when hitting USB Billboard Device 2109:8884. An easy workaround is to handle errors from dev.active_config_descriptor() like:

(around src/lib.rs:57)

let cfg = match dev.active_config_descriptor() {
    Ok(cfg) => cfg,
    Err(err) => {
        println!("LibUSB Error: {:?}: {}", dev, err);
        continue;
    }
};

I haven't had a chance to test it thoroughly (by doing some programming on some developing SBCs), but at least I can now list available devices from M1 Macs.

The Direction enum seems to be shadowed

The Direction enum seems to be shadowed by the rusb crate.

Importing Direction will result in the following error:

error[E0603]: enum `Direction` is private
 --> src/cdc.rs:8:94
  |
8 | use usbip::{UsbEndpoint, EndpointAttributes, UsbInterfaceHandler, UsbInterface, SetupPacket, Direction};
  |                                                                                              ^^^^^^^^^ private enum
  |
note: the enum `Direction` is defined here
 --> /home/void/.cargo/registry/src/github.com-1ecc6299db9ec823/usbip-0.4.0/src/lib.rs:6:5
  |
6 | use rusb::*;
  |     ^^^^^^^

At the same time the consts crate is also not marked as public making a direct import with use usbip::consts::Direction impossible.

Support non-libusb/WinUSB devices on Windows

Brandon@AsusRogStrix MINGW64 ~/Desktop/usbip (master)
$ cargo run --example host
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target\debug\examples\host.exe`
[2024-01-20T20:41:55Z WARN  usbip] Impossible to share Bus 004 Device 000: ID 8086:7a60: Operation not supported or unimplemented on this platform, ignoring device
[2024-01-20T20:41:55Z WARN  usbip] Impossible to share Bus 004 Device 004: ID 8087:0033: Operation not supported or unimplemented on this platform, ignoring device
[2024-01-20T20:41:55Z WARN  usbip] Impossible to share Bus 001 Device 000: ID 1d6b:0004: Operation not supported or unimplemented on this platform, ignoring device
[2024-01-20T20:41:55Z WARN  usbip] Impossible to share Bus 004 Device 003: ID 322e:2122: Entity not found, ignoring device
[2024-01-20T20:41:55Z WARN  usbip] Impossible to share Bus 004 Device 021: ID 18e1:01b3: Entity not found, ignoring device
[2024-01-20T20:41:55Z WARN  usbip] Impossible to share Bus 002 Device 000: ID 8086:1135: Operation not supported or unimplemented on this platform, ignoring device
[2024-01-20T20:41:55Z WARN  usbip] Impossible to share Bus 003 Device 000: ID 1d6b:0000: Operation not supported or unimplemented on this platform, ignoring device

Trying to see what the issue is, opening this issue to put my notes

not implemented: control in

Hiya!

I have an app exposing a usbip virtual device and getting the following when running sudo lsusb -v from Linux:

Control IN setup=SetupPacket { request_type: c0, request: a, value: 0, index: 1, length: 1 }
thread 'tokio-runtime-worker' panicked at 'not implemented: control in'

First, I'm not entirely sure what the 0xc0 request type is, any ideas? Second, it seems a bit harsh to simply panic - on a normal USB device I think it is conventional to stall? Is there a usbip equivalent that could be implemented instead?

Issues with usbip-win on windows 10

Hi, i really like your project, but i came across some issues.

So my setup is - windows 10, i installed usbip-win version 0.3.5 from https://github.com/cezanne/usbip-win.
I try to run localy keyboard example on native windows 10.

When i tried to use your repo, i got problems when running keyboard example:

  1. when calling '''./usbip attach -r 127.0.0.1 -b 0'''
    example doesn't detect bus, because usbip-win sends bus id in format like "0\0fefefefefe..." - and you check for "0\0\0\0\0\0\0..."
    I've fixed it by checking if one bus sctring contains another.
  2. than it doesnt work - and get stuck in loop, reporting wrong packet requests from client. I've found solution for that by manualy replacing:
    0x02, // bcdUSB: USB 2.1
    value with
    0x01, // bcdUSB

and
self.ep0_in.max_packet_size as u8, // bMaxPacketSize0
with
0x08, // bMaxPacketSize0

I found that values by trying mimic python/c baced repo, which works with usbip-win.

Now, i have one last problem, which i don't know how to fix.
When i run example - it runs, it creates new HID keyboard device, and even sends 1 as input... But, it doesn't just send one "1" per second - it's like spams it. (like 10-20 characters per second).

So, question is, where i can get compatible version of usbip-win client which works correctly with your example (and on win 10).
Or, what i should additionaly change to fix the issue of auto-repeated characters, on busy server (i've observed, that when server doesn't reply for like 250ms it starts to spam last character.
My goal is to have something like: 127x0x0x1 string outputed fast, and than - to do nothing for next ten seconds, than repeat.
And my ultimate goal is to have syncronous api which i can call something like PressKey("A"); ReleaseKey("A"); from thread with logic, imitating human input.

Trying to wrap my head around this issue for last few days with no luck...

I'm really new to rust and usbip/hid so any help or suggestions are appreciated.

Flash drive and webcam cannot be mounted on Linux

After starting the server, I try to connect a USB drive or a webcam on a Linux client, I see them in the list of devices via lsusb or usblist -r, I can make an attachment, but I can’t use these devices in the system, the webcam gives an error when starting, and the flash card is not displayed, maybe I configured the server incorrectly?

Снимок экрана 2024-01-16 в 17 44 57 Снимок экрана 2024-01-16 в 17 40 18 Снимок экрана 2024-01-16 в 17 39 27 Снимок экрана 2024-01-16 в 17 36 49

USBIP attached device gets disconnected after a few seconds

I'm trying to pass a USB device from macOS to Linux. It's disconnecting after about 5 seconds. On the macOS host/server, I run env RUST_LOG=info cargo run --example host

The client is running Debian 11 and usbip:

Package: usbip
Version: 2.0+5.10.136-1
Priority: optional
Section: admin
Source: linux (5.10.136-1)
Maintainer: Debian Kernel Team [email protected]

On the client, I run sudo usbip list -r 192.168.4.185 (this is the local IP address of the mac), and I get the full list of USB devices exposed by usbip server implementation on the mac.

At this point, I get some info logs on the server that seem to be pointing to some issue, although the operation on the client did appear to complete successfully:

[2022-09-06T22:45:56Z INFO usbip] Got connection from Ok(192.168.5.245:37120)
[2022-09-06T22:45:56Z INFO usbip] Handler ended with Err(Custom { kind: UnexpectedEof, error: "early eof" })

Then I attach a device. In my case:

sudo usbip attach -r 192.168.4.185 -b 3-16-2

At this point, I get some success logs from the server, and the client shows the attached device if I run sudo usbip port:

Server:
[2022-09-06T22:49:34Z INFO usbip] Got connection from Ok(192.168.5.245:58240)
[2022-09-06T22:49:34Z INFO usbip] Found device "/sys/bus/3/16/2"

After about 5 seconds, the server throws the same error message from earlier:
[2022-09-06T22:49:44Z INFO usbip] Handler ended with Err(Custom { kind: UnexpectedEof, error: "early eof" })

At this point, the device is no longer attached to the client.

Can't get the example `host` to work

The host example fails to share a logitech receiver.

How I reproduced it:

  1. Plug in the receiver on my Raspberry PI

  2. Set up the server:

    ~/usbip master ❯ export RUST_LOG=info
    ~/usbip master ❯ sudo target/release/examples/host
  3. Set up the client on my computer:

    ~ ❯ sudo usbip list -r 192.168.124.103                                                                                                                                                     16:28:58
    [sudo] password for bczhc:
    Exportable USB devices
    ======================
     - 192.168.124.103
          4-1-0: Linux Foundation : 3.0 root hub (1d6b:0003)
               : /sys/bus/4/1/0
               : Hub / Unused / unknown protocol (09/00/03)
               :  0 - Hub / Unused / Full speed (or root) hub (09/00/00)
    
          3-1-0: Linux Foundation : 2.0 root hub (1d6b:0002)
               : /sys/bus/3/1/0
               : Hub / Unused / Single TT (09/00/01)
               :  0 - Hub / Unused / Full speed (or root) hub (09/00/00)
    
          2-1-0: Linux Foundation : 3.0 root hub (1d6b:0003)
               : /sys/bus/2/1/0
               : Hub / Unused / unknown protocol (09/00/03)
               :  0 - Hub / Unused / Full speed (or root) hub (09/00/00)
    
         1-47-4: Logitech, Inc. : Unifying Receiver (046d:c52f)
               : /sys/bus/1/47/4
               : (Defined at Interface level) (00/00/00)
               :  0 - Human Interface Device / Boot Interface Subclass / Mouse (03/01/02)
               :  1 - Human Interface Device / No Subclass / None (03/00/00)
    
          1-2-1: VIA Labs, Inc. : Hub (2109:3431)
               : /sys/bus/1/2/1
               : Hub / Unused / Single TT (09/00/01)
               :  0 - Hub / Unused / Full speed (or root) hub (09/00/00)
    
          1-1-0: Linux Foundation : 2.0 root hub (1d6b:0002)
               : /sys/bus/1/1/0
               : Hub / Unused / Single TT (09/00/01)
               :  0 - Hub / Unused / Full speed (or root) hub (09/00/00)
    
    ~ ❯ sudo usbip attach -r 192.168.124.103 -b 1-47-4                                                                                                                                         16:29:06

Actual behavior

The cursor won't move when I move the mouse.

Expected behavior

Not so.

Additional info

With the original usbip (as the server), this works.

dmesg:

[114533.584038] vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3)
[114533.584049] vhci_hcd vhci_hcd.0: devid(65540) speed(2) speed_str(full-speed)
[114533.584056] vhci_hcd vhci_hcd.0: Device attached
[114533.759561] vhci_hcd: vhci_device speed not set
[114533.816210] usb 5-1: new full-speed USB device number 30 using vhci_hcd
[114533.886315] vhci_hcd: vhci_device speed not set
[114533.942896] usb 5-1: SetAddress Request (30) to port 0
[114533.968102] usb 5-1: not running at top speed; connect to a high speed hub
[114533.989433] usb 5-1: New USB device found, idVendor=046d, idProduct=c52f, bcdDevice=1e.00
[114533.989440] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[114533.989444] usb 5-1: Product: USB Receiver
[114533.989447] usb 5-1: Manufacturer: Logitech
[114534.013670] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013687] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013697] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013706] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013716] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013725] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013734] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013746] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013756] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013765] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013774] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013783] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013792] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013801] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013810] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013819] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013828] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013838] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013847] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013856] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013865] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013874] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013883] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013892] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013903] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013913] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013923] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013933] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013943] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013953] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013963] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013973] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013983] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.013993] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014003] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014012] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014022] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014032] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014042] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014052] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014062] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014072] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014082] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014092] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014102] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014112] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014122] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014132] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014142] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014151] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014161] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014171] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014181] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014191] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014201] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014211] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014221] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014231] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014241] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014251] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014261] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014271] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014281] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014291] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014301] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014311] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.014320] logitech-djreceiver 0003:046D:C52F.003C: unknown main item tag 0x0
[114534.034080] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034084] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034087] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034089] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034092] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034095] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034097] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034100] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034102] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034105] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034107] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034110] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034112] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034115] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034117] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034120] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034123] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034125] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034128] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034130] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034133] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034135] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034138] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034140] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034143] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034145] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034148] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034151] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034153] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034156] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034158] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034161] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034165] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034167] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034170] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034173] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034175] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034178] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034180] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034183] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034186] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034188] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034191] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034193] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034196] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034199] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034201] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034204] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034206] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034209] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034212] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034214] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034217] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034220] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034222] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034225] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034227] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034230] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034233] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034235] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034238] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034240] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034243] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034246] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034248] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034251] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034253] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034256] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034259] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034261] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034264] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034266] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034269] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034272] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034274] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034277] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034279] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034282] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0
[114534.034285] logitech-djreceiver 0003:046D:C52F.003D: unknown main item tag 0x0

Server wrongly assumes devices are no longer used after unlink command

In the current implementation, the server removes a USB device from its used_device list when it receives USBIP_CMD_UNLINK.

This however leads to issues when multiple URBs are unlinked (wrongly triggers usbip_ret_unlink_fail) or when attempting to submit an URB afterwards (panics on current_import_device.unwrap()). Looking at the USB/IP protocol (3rd diagram) both things should be possible.

Host example error on MacOS

I have a Bluttooth dongle10, when it plugged, the host example thrown an exception.

  usbip git:(master) sudo env RUST_LOG=info RUST_BACKTRACE=full cargo run --example host
   Compiling usbip v0.6.0 (/Users/yaochunlin/work/usbip)
    Finished dev [unoptimized + debuginfo] target(s) in 1.37s
     Running `target/debug/examples/host`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NotFound', src/lib.rs:63:54
stack backtrace:
   0:        0x108808db7 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h25e7da9115301bd9
   1:        0x108819f5b - core::fmt::write::h4d1b053dd3817697
   2:        0x1087de7c6 - std::io::Write::write_fmt::h48fc6e40b56483f8
   3:        0x108808b80 - std::sys_common::backtrace::print::h6fa1159600d88f18
   4:        0x1087f51f5 - std::panicking::default_hook::{{closure}}::h0a8254be9e82d10f
   5:        0x1087f4f71 - std::panicking::default_hook::hc1504d29d6ed0579
   6:        0x1087f58bb - std::panicking::rust_panic_with_hook::h4aeedb5e21e62c34
   7:        0x1088094e3 - std::panicking::begin_panic_handler::{{closure}}::hb8ebfc8b40cd97df
   8:        0x108808eb9 - std::sys_common::backtrace::__rust_end_short_backtrace::h7ef18953f8f8bb9b
   9:        0x1087f546d - _rust_begin_unwind
  10:        0x108829e93 - core::panicking::panic_fmt::h311d6d0f06c691be
  11:        0x108829e55 - core::result::unwrap_failed::hda3d26196913454a
  12:        0x1084ae2f9 - core::result::Result<T,E>::unwrap::h28ef900968b6b5b1
                               at /private/tmp/rust-20230902-17312-1ox8e1o/rustc-1.72.0-src/library/core/src/result.rs:1076:23
  13:        0x1084b6afd - usbip::UsbIpServer::with_devices::hfd6c4a9bacbde975
                               at /Users/yaochunlin/work/usbip/src/lib.rs:63:23
  14:        0x1084b88c6 - usbip::UsbIpServer::new_from_host::h3a273bdd93c8cb6a
                               at /Users/yaochunlin/work/usbip/src/lib.rs:189:52
  15:        0x10849c57b - host::main::{{closure}}::h0769c2f4ff143694
                               at /Users/yaochunlin/work/usbip/examples/host.rs:8:27
  16:        0x10848a732 - tokio::runtime::park::CachedParkThread::block_on::{{closure}}::h405f7adf04e18609
                               at /Users/yaochunlin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/park.rs:282:63
  17:        0x10848a1b9 - tokio::runtime::coop::with_budget::hade375f944a68b07
                               at /Users/yaochunlin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/coop.rs:107:5
  18:        0x10848a1b9 - tokio::runtime::coop::budget::h7882096bb18894c7
                               at /Users/yaochunlin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/coop.rs:73:5
  19:        0x10848a1b9 - tokio::runtime::park::CachedParkThread::block_on::h72a97453d7254f5c
                               at /Users/yaochunlin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/park.rs:282:31
  20:        0x10849654f - tokio::runtime::context::blocking::BlockingRegionGuard::block_on::hff84f6a3da3e9933
                               at /Users/yaochunlin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context/blocking.rs:66:9
  21:        0x108495424 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}::h27f4893595b1174d
                               at /Users/yaochunlin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
  22:        0x10849448e - tokio::runtime::context::runtime::enter_runtime::h3557e94792c66141
                               at /Users/yaochunlin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context/runtime.rs:65:16
  23:        0x1084953e5 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h725fc24d56ec91aa
                               at /Users/yaochunlin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
  24:        0x10847383b - tokio::runtime::runtime::Runtime::block_on::h45dbe91f8c846544
                               at /Users/yaochunlin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/runtime.rs:349:45
  25:        0x1084a3ffe - host::main::h18055fdd1812db92
                               at /Users/yaochunlin/work/usbip/examples/host.rs:12:5
  26:        0x10847b6be - core::ops::function::FnOnce::call_once::hb5aa621061f79dc8
                               at /private/tmp/rust-20230902-17312-1ox8e1o/rustc-1.72.0-src/library/core/src/ops/function.rs:250:5
  27:        0x1084aa8c1 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd3e06039e4075dbe
                               at /private/tmp/rust-20230902-17312-1ox8e1o/rustc-1.72.0-src/library/std/src/sys_common/backtrace.rs:135:18
  28:        0x10847f624 - std::rt::lang_start::{{closure}}::he6433942e32e1799
                               at /private/tmp/rust-20230902-17312-1ox8e1o/rustc-1.72.0-src/library/std/src/rt.rs:166:18
  29:        0x1087f5354 - std::panicking::try::he1007db618a42bd9
  30:        0x1087ec14e - std::rt::lang_start_internal::h4bc01625444a6117
  31:        0x10847f5f7 - std::rt::lang_start::h8a3b273862067ccb
                               at /private/tmp/rust-20230902-17312-1ox8e1o/rustc-1.72.0-src/library/std/src/rt.rs:165:17
  32:        0x1084a4088 - _main

This is my dongle's Info.
VID 0x0001
PID 0x0a12

no entry found for key

$ RUST_LOG=debug cargo run --example host
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `/Users/brandon/.cargo/target/debug/examples/host`
[2024-01-13T19:13:29Z INFO  usbip] Got connection from Ok(redacted:49871)
[2024-01-13T19:13:29Z INFO  usbip] Remote closed the connection
[2024-01-13T19:13:29Z INFO  usbip] Handler ended with Ok(())
[2024-01-13T19:13:58Z INFO  usbip] Got connection from Ok(redacted:49879)
[2024-01-13T19:13:58Z DEBUG usbip::device] Control IN setup=SetupPacket { request_type: 80, request: 6, value: 100, index: 0, length: 40 }
[2024-01-13T19:13:58Z DEBUG usbip::device] Get device descriptor
[2024-01-13T19:13:58Z DEBUG usbip::device] Control IN setup=SetupPacket { request_type: 80, request: 6, value: 100, index: 0, length: 12 }
[2024-01-13T19:13:58Z DEBUG usbip::device] Get device descriptor
[2024-01-13T19:13:58Z DEBUG usbip::device] Control IN setup=SetupPacket { request_type: 80, request: 6, value: 200, index: 0, length: ff }
[2024-01-13T19:13:58Z DEBUG usbip::device] Get configuration descriptor
[2024-01-13T19:13:58Z DEBUG usbip::device] Control IN setup=SetupPacket { request_type: 80, request: 6, value: 3ee, index: 0, length: 12 }
[2024-01-13T19:13:58Z DEBUG usbip::device] Get string descriptor
thread 'tokio-runtime-worker' panicked at /Users/brandon/Desktop/usbip/src/device.rs:358:62:
no entry found for key
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Incorrect Constant Values for Standard Device Request Codes

In consts.rs the codes for SetInterface and SynthFrame (should be SynchFrame) are incorrect.
They are currently 0x11 and 0x12 respectively, but should be decimal 11 and 12 (0x0B and 0x0C).

They are specified in Table 9-4 of the USB 2.0 specification.
https://www.usb.org/document-library/usb-20-specification (usb_20.pdf, page 251).

I would be happy to create a pull request, but it's such a small fix it would probably be quicker for someone else to just do it.

Thanks

Changing the USB speed fails to update ep0 max packet size

When changing the public UsbDevice::speed, the max packet size of ep0_in/out are not updated, which then leads to the device failing to enumerate. (Invalid ep0 maxpacket: 64)

The correct value for USB 3.0+ is 9, where the actual max packet size is 2^bMaxPacketSize0

I hope its okay to just open issues for now, will also open an MR once I find time :)

CP2112 shared problem (error setting SMBus config)

OS
Server: MacOS 13.6.4 (22G513) Intel
Client: Linux ubuntu-labview 5.15.0-101-generic. and windows 10 usbip-win-client


@after Connection:
Server:
[2024-03-28T09:28:12Z INFO usbip] Handler ended with Ok(())
[2024-03-28T09:28:33Z INFO usbip] Got connection from Ok(192.168.XX.XX:47526)

@client:
1, usbip list -r:
20-4-1: Genesys Logic, Inc. : 4-port hub (05e3:0610)
: /sys/bus/20/4/1
: Hub / Unused / Single TT (09/00/01)
: 0 - Hub / Unused / Full speed (or root) hub (09/00/00)

2, lsusb:
Bus 001 Device 002: ID 10c4:ea90 Silicon Labs CP2112 HID I2C Bridge

3, dmesg:
[ 124.060224] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[ 124.060232] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1
[ 124.060244] vhci_hcd: created sysfs vhci_hcd.0
[ 124.060311] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.15
[ 124.060316] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 124.060319] usb usb1: Product: USB/IP Virtual Host Controller
[ 124.060323] usb usb1: Manufacturer: Linux 5.15.0-101-generic vhci_hcd
[ 124.060325] usb usb1: SerialNumber: vhci_hcd.0
[ 124.060485] hub 1-0:1.0: USB hub found
[ 124.060493] hub 1-0:1.0: 8 ports detected
[ 124.060677] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller
[ 124.060680] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 2
[ 124.060697] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[ 124.060726] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.15
[ 124.060730] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 124.060733] usb usb2: Product: USB/IP Virtual Host Controller
[ 124.060736] usb usb2: Manufacturer: Linux 5.15.0-101-generic vhci_hcd
[ 124.060738] usb usb2: SerialNumber: vhci_hcd.0
[ 124.060825] hub 2-0:1.0: USB hub found
[ 124.060831] hub 2-0:1.0: 8 ports detected
[ 125.605587] vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3)
[ 125.605603] vhci_hcd vhci_hcd.0: devid(1310723) speed(2) speed_str(full-speed)
[ 125.605630] vhci_hcd vhci_hcd.0: Device attached
[ 125.779236] vhci_hcd: vhci_device speed not set
[ 125.839294] usb 1-1: new full-speed USB device number 2 using vhci_hcd
[ 125.907292] vhci_hcd: vhci_device speed not set
[ 125.967284] usb 1-1: SetAddress Request (2) to port 0
[ 125.997752] usb 1-1: New USB device found, idVendor=10c4, idProduct=ea90, bcdDevice= 0.00
[ 125.997771] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 125.997781] usb 1-1: Product: FQDD-WB-A1.1
[ 125.997788] usb 1-1: Manufacturer: Silicon Laboratories
[ 125.997796] usb 1-1: SerialNumber: FQDD-WB-A1.1-001
[ 126.046371] hid: raw HID events driver (C) Jiri Kosina
[ 126.060660] usbcore: registered new interface driver usbhid
[ 126.060672] usbhid: USB HID core driver
[ 126.097325] cp2112 0003:10C4:EA90.0001: hidraw0: USB HID v1.01 Device [Silicon Laboratories FQDD-WB-A1.1] on usb-vhci_hcd.0-1/input0
[ 126.156285] cp2112 0003:10C4:EA90.0001: Part Number: 0x0C Device Version: 0x03
[ 126.160031] cp2112 0003:10C4:EA90.0001: error setting SMBus config
[ 126.161332] cp2112: probe of 0003:10C4:EA90.0001 failed with error -5
[ 126.208356] vhci_hcd: unlink->seqnum 82
[ 126.208376] vhci_hcd: the urb (seqnum 82) was already given back


Use the Chip SDK test:

./hidSMBusExample

Device 0 Information:
HidSmbus_Open(): HID_SMBUS_SUCCESS
VID = 0x10C4
PID = 0xEA90
Release Number = 0.00
Part Number = 12
Version = 3
Serial = FQDD-WB-A1.1-001
Manufacturer = Silicon Laboratories
Product = FQDD-WB-A1.1
Bit Rate = 100000 Hz
Slave Address = 02
Auto Send Read Response = false
Write Timeout = 0 ms
Read Timeout = 0 ms
Transfer Retries = 1
SCL Low Timeout = false
==================== HidSmbus_GetSmbusConfig():HID_SMBUS_SUCCESS
Response Timeout = 1000 ms
==================== HidSmbus_GetTimeouts():HID_SMBUS_SUCCESS
GPIO0Mode = GPIO_INPUT_OPEN_DRAIN
GPIO1Mode = GPIO_INPUT_OPEN_DRAIN
GPIO2Mode = GPIO_INPUT_OPEN_DRAIN
GPIO3Mode = GPIO_INPUT_OPEN_DRAIN
GPIO4Mode = GPIO_INPUT_OPEN_DRAIN
GPIO5Mode = GPIO_INPUT_OPEN_DRAIN
GPIO6Mode = GPIO_INPUT_OPEN_DRAIN
GPIO7Mode = GPIO_INPUT_OPEN_DRAIN
Clock Out Divider = 0
Clock Out Divider = 48000000
==================== HidSmbus_GetGpioConfig():HID_SMBUS_SUCCESS
LatchValue = 0x17
==================== HidSmbus_ReadLatch: HID_SMBUS_SUCCESS
Custom Vid: 0x10C4
Custom Pid: 0xEA90
Custom Power: 100 mA
Custom Power Mode: HID_SMBUS_BUS_POWER
Release Version: 01.00
==================== HidSmbus_GetUsbConfig: HID_SMBUS_SUCCESS
HID_SMBUS_LOCK_VID: 1
HID_SMBUS_LOCK_PID: 1
HID_SMBUS_LOCK_POWER: 1
HID_SMBUS_LOCK_POWER_MODE: 1
HID_SMBUS_LOCK_RELEASE_VERSION: 1
HID_SMBUS_LOCK_MFG_STR: 1
HID_SMBUS_LOCK_PRODUCT_STR: 0
HID_SMBUS_LOCK_SERIAL_STR: 0
==================== HidSmbus_GetLock: HID_SMBUS_SUCCESS
Manufacturing String: Silicon Laboratories
==================== HidSmbus_GetManufacturingString: HID_SMBUS_SUCCESS
Product String: FQDD-WB-A1.1
==================== HidSmbus_GetProductString: HID_SMBUS_SUCCESS
Serial String: FQDD-WB-A1.1-001
==================== HidSmbus_GetSerialString: HID_SMBUS_SUCCESS
==================== HidSmbus_Close(): HID_SMBUS_SUCCESS


i2cdetect -l
non i2c bus....


Summary

through this usbip server. I did can control the CP2112 GPIO. but the i2c bus did not trans out.

P.S
1, I try to control at the local OS (macOS), It fine.
2, I try to use the virtualhere server at macOS and the virtualhere client at windows10, is fine too.
3, I try to use the usbip-win server at windows10 and the usbip client at this ubuntu, is fine too.

thanks a lot to help

Host example Mac to Linux - is a "bind" necessary?

I've used usbipd-win before, with Windows 10 and WSL, with success. There, I need to do a usbip bind on the host before attaching a device. Is that a thing here as well?

Aim:

  • to have an ESP32 development board mapped from Mac (host) to Multipass (client; Linux), for sandboxed embedded development

Situation:

  • Multipass can see the driver, and identify it correctly:

    [MP]$ usbip list -r 192.168.1.62
    Exportable USB devices
    ======================
     - 192.168.1.62
        20-35-6: Silicon Labs : CP210x UART Bridge (10c4:ea60)
               : /sys/bus/20/35/6
               : (Defined at Interface level) (00/00/00)
               :  0 - Vendor Specific Class / unknown subclass / unknown protocol (ff/00/00)
    

... but attaching doesn't cut it:

[MP]$ usbip attach -r 192.168.1.62 -b 20-35-6
libusbip: error: udev_device_new_from_subsystem_sysname failed
usbip: error: open vhci_driver

Same with or without sudo.

Do the error messages tell anything to you? I'll be going through the source next, to get an idea.

Modifying device vector during server loop

Hello!

I'm trying to create a program where I can add and remove devices during execution. But I find this to be difficult to do in a safe manner for several reasons:

  • The handler function is private, so I'm not able to create my own server loop.
  • The server function spawns threads for each socket without keeping track of them, so it's not trivial to close the threads when removing a usb from the vector. (I haven't found any way to do graceful shutdown in the protocol spec)

I had imagined to create something like the following:

/// Spawn a USB/IP server at `addr` using [TcpListener]
pub async fn customServer(addr: SocketAddr, server: UsbIpServer) {
    let listener = TcpListener::bind(addr).await.expect("bind to addr");

    let server = async move {
        let usbip_server = Arc::new(server);
        loop {
            tokio::select! {
		val = listener.accept() => {
                    match val {
                        Ok((mut socket, _addr)) => {
                            ...
                        }
                        Err(err) => {
                            ...
                        }
                    }
		}
		
		val = listen_for_devicelist_changes() => {
		    // add or remove device
		    ...
		}
	    }
        }
    };

    server.await
}

Is this something you would consider to be in the scope of the library?

Access to URB `transfer_buffer_length` in `handle_urb`

I'm trying to replay USB requests on a remote machine. There's a bit of a problematic API for handle_urb, where it seems to be missing a variable that's supposed to tell how large the data buffer is. The setup packets wLength appear to only be for control requests.

Maybe the transfer_buffer_length from the urb struct should be included as an argument to both device and interface handle_urb?

This is the field I'm trying to access, for an interface bulk in request

image

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.