jiegec / usbip

A Rust library to run a USB/IP server
MIT License
278 stars 26 forks source link

USBIP attached device gets disconnected after a few seconds #6

Closed joshurawr closed 2 months ago

joshurawr commented 2 years ago

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 debian-kernel@lists.debian.org

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.

joshurawr commented 2 years ago

Following up, I wanted to note that I'm on wired gigabit lan. I also tested v5.0 versus the latest version and found identical behavior between versions. However, I was able to get different behavior with different devices.

 3-16-2: Sony Corp. : DualSense wireless controller (PS5) (054c:0ce6)
       : /sys/bus/3/16/2
       : (Defined at Interface level) (00/00/00)
       :  0 - Audio / Control Device / unknown protocol (01/01/00)
       :  1 - Audio / Streaming / unknown protocol (01/02/00)
       :  2 - Audio / Streaming / unknown protocol (01/02/00)
       :  3 - Human Interface Device / No Subclass / None (03/00/00)

This is the "problem device." I don't know if you might have any intuition about USB 2.0 devices that might be interfering with the connection, or if there might be workarounds. I haven't tested any other USB 2.0 devices yet.

I did a passthrough on different devices (USB 1.1, below) and it appears to maintain the attached USB device without the server throwing any errors (it will also stay connected even if I also attach the problematic device above, when that device gets disconnected)

  3-9-4: Blue Microphones : Yeti Stereo Microphone (b58e:9e84)
       : /sys/bus/3/9/4
       : (Defined at Interface level) (00/00/00)
       :  0 - Audio / Control Device / unknown protocol (01/01/00)
       :  1 - Audio / Streaming / unknown protocol (01/02/00)
       :  2 - Audio / Streaming / unknown protocol (01/02/00)

 3-17-2: Sony Corp. : Batoh Device / PlayStation 3 Controller (054c:0268)
       : /sys/bus/3/17/2
       : (Defined at Interface level) (00/00/00)
       :  0 - Human Interface Device / No Subclass / None (03/00/00)

These remain connected:

sudo usbip port
Imported USB devices
====================
Port 00: <Port in Use> at Full Speed(12Mbps)
       Sony Corp. : Batoh Device / PlayStation 3 Controller (054c:0268)
       3-1 -> usbip://My-Macbook-Pro.local:3240/3-17-2
           -> remote bus/dev 003/002
Port 01: <Port in Use> at Full Speed(12Mbps)
       Blue Microphones : Yeti Stereo Microphone (b58e:9e84)
       3-2 -> usbip://My-Macbook-Pro.local:3240/3-9-4
           -> remote bus/dev 003/004

This fails after a few seconds:

Imported USB devices
====================
Port 00: <Port in Use> at High Speed(480Mbps)
       Sony Corp. : DualSense wireless controller (PS5) (054c:0ce6)
       3-1 -> usbip://My-Macbook-Pro.local:3240/3-18-2
           -> remote bus/dev 003/002
jiegec commented 2 years ago

I think the error UnexpectedEof is due to TCP connection closing. The actual error is not shown in the logs.

joshurawr commented 2 years ago

is there something I can do to resolve it, or get additional logs? Maybe on the client side too?

joshurawr commented 2 years ago

Here are the client logs when I try to connect. There's some info about invalid byte count that looks like it might be useful.

Sep 12 19:05:02 raspberrypi kernel: [21359.250707] vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3)
Sep 12 19:05:02 raspberrypi kernel: [21359.250739] vhci_hcd vhci_hcd.0: devid(196610) speed(3) speed_str(high-speed)
Sep 12 19:05:02 raspberrypi kernel: [21359.251332] vhci_hcd vhci_hcd.0: Device attached
Sep 12 19:05:02 raspberrypi kernel: [21359.483511] usb 3-1: new high-speed USB device number 25 using vhci_hcd
Sep 12 19:05:02 raspberrypi kernel: [21359.695510] usb 3-1: SetAddress Request (25) to port 0
Sep 12 19:05:03 raspberrypi kernel: [21360.078099] usb 3-1: New USB device found, idVendor=054c, idProduct=0ce6, bcdDevice= 0.00
Sep 12 19:05:03 raspberrypi kernel: [21360.078133] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Sep 12 19:05:03 raspberrypi kernel: [21360.078149] usb 3-1: Product: Wireless Controller
Sep 12 19:05:03 raspberrypi kernel: [21360.078163] usb 3-1: Manufacturer: Sony Interactive Entertainment
Sep 12 19:05:06 raspberrypi kernel: [21363.228228] playstation 0003:054C:0CE6.0018: hidraw0: USB HID v1.11 Gamepad [Sony Interactive Entertainment Wireless Controller] on usb-vhci_hcd.0-1/input3
Sep 12 19:05:07 raspberrypi kernel: [21364.499619] playstation 0003:054C:0CE6.0018: Invalid byte count transferred, expected 64 got 0
Sep 12 19:05:07 raspberrypi kernel: [21364.499654] playstation 0003:054C:0CE6.0018: Failed to retrieve DualSense firmware info: -22
Sep 12 19:05:07 raspberrypi kernel: [21364.499691] playstation 0003:054C:0CE6.0018: Failed to get firmware info from DualSense
Sep 12 19:05:07 raspberrypi kernel: [21364.499705] playstation 0003:054C:0CE6.0018: Failed to create dualsense.
Sep 12 19:05:07 raspberrypi kernel: [21364.555536] playstation: probe of 0003:054C:0CE6.0018 failed with error -22
Sep 12 19:05:07 raspberrypi mtp-probe: checking bus 3, device 25: "/sys/devices/platform/vhci_hcd.0/usb3/3-1"
Sep 12 19:05:07 raspberrypi mtp-probe: bus: 3, device: 25 was not an MTP device
Sep 12 19:05:07 raspberrypi kernel: [21364.631124] vhci_hcd: unlink->seqnum 48843
Sep 12 19:05:07 raspberrypi kernel: [21364.631153] vhci_hcd: the urb (seqnum 48843) was already given back
Sep 12 19:05:13 raspberrypi kernel: [21369.911250] usbip_core: unknown command
Sep 12 19:05:13 raspberrypi kernel: [21369.911266] vhci_hcd: unknown pdu 0
Sep 12 19:05:13 raspberrypi kernel: [21369.911273] usbip_core: unknown command
Sep 12 19:05:13 raspberrypi kernel: [21369.911383] vhci_hcd: stop threads
Sep 12 19:05:13 raspberrypi kernel: [21369.911389] vhci_hcd: release socket
Sep 12 19:05:13 raspberrypi kernel: [21369.911408] vhci_hcd: disconnect device
Sep 12 19:05:13 raspberrypi kernel: [21369.911505] usb 3-1: enqueue for inactive port 0
Sep 12 19:05:13 raspberrypi kernel: [21369.911505] usb 3-1: USB disconnect, device number 25
Sep 12 19:05:13 raspberrypi systemd-udevd[1972]: controlC3: Process '/usr/sbin/alsactl -E HOME=/run/alsa -E XDG_RUNTIME_DIR=/run/alsa/runtime restore 3' failed with exit code 99.
Aussiedler commented 1 year ago

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

I downloaded the latest 0.5.0 version and tried to start a host like in the readme and your first post here. But I get every time the error, he can't find the cargo file in the directory... can you help me here?

Bildschirmfoto 2022-11-18 um 16 24 09

I'm on a Mac Pro with Big Sur OS.

jiegec commented 1 year ago

@Aussiedler You need to setup Rust development environment.

jamesadevine commented 1 year ago

I suspect this issue is caused by reading too much data (> than the ep max packet size) of the usb ip device.

This commit: https://github.com/jiegec/usbip/pull/8/commits/ee51a4003b95ef54400aa6990ce2b05823f03967 fixed the instability with my device.

jiegec commented 2 months ago

Please try again, and if the issue persists, you can reopen the issue.