USB over IP at home

Sometimes there is a desire to work with a device connected via USB without keeping it on the table next to the laptop. I have such a device, a Chinese laser engraver with 500 mW, which is quite unpleasant to be near. Besides the immediate danger to the eyes, the laser emits toxic combustion products during operation, so the device should be in a well-ventilated area and preferably isolated from people. But how do you control such a device? I accidentally found the answer while browsing the OpenWRT repository in hopes of finding a worthy use for an old D-Link DIR-320 A2 router. I decided to use the method described earlier on Habr. USB over IP tunnel, however, all installation instructions have become outdated, so I am writing my own.

OpenWRT is an operating system that needs no introduction, so I won't describe its installation. For my router, I took the latest stable release OpenWrt 19.07.3 and connected it to the main access point via Wi-Fi as a client, choosing the mode lan, so as not to trouble the firewall.

Server part

We proceed according to the official instructions. After connecting via ssh, we install the necessary packages.

root@OpenWrt:~# opkg update
root@OpenWrt:~# opkg install kmod-usb-ohci usbip-server usbip-client

Next, connect our device to the router's USB port (in my case, the devices are: USB hub, flash drive, which contains the router's file system (due to lack of space on the internal storage), and the engraver itself).

Let's try to list the connected devices:

root@OpenWrt:~# usbip list -l

Empty.

Through googling, I found the culprit, which turned out to be the library libudev-fbsd.
We manually extract the last working version from the repository libudev_3.2-1 from the OpenWRT 17.01.7 release for my architecture, in my case it is libudev_3.2-1_mipsel_mips32.ipk. Using wget/scp, we upload it to the router's memory and reinstall it

root@OpenWrt:~# opkg remove --force-depends libudev-fbsd
root@OpenWrt:~# opkg install libudev_3.2-1_mipsel_mips32.ipk

Checking:

root@OpenWrt:~# usbip list -l
 - busid 1-1.1 (090c:1000)
   Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) : Flash Drive (090c:1000)

 - busid 1-1.4 (1a86:7523)
   QinHeng Electronics : HL-340 USB-Serial adapter (1a86:7523)

The Chinese device connected to the USB hub received bsuid 1-1.4. Remembered.

Now let's start the daemon:

root@OpenWrt:~# usbipd -D

and bind the Chinese device

root@OpenWrt:~# usbip bind -b 1-1.4
usbip: info: bind device on busid 1-1.4: complete

Checking that everything works:

root@OpenWrt:/home# netstat -alpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3240            0.0.0.0:*               LISTEN      1884/usbipd

To bind the device automatically in the future, let's edit /etc/rc.local, adding before exit 0 the following:

usbipd -D &
sleep 1
usbip bind -b 1-1.4

Client side

Let's try to connect the device to Windows 10 using the aforementioned instructions from openwrt.org. I’ll say right away: this attempt is doomed to fail. First, it only considers Windows 7 x64. Secondly, there's a link to a thread on sourceforge.net, which suggests downloading a patched driver from Dropbox from 2014. When trying to run it on Windows 10 and connect to our device, we get the error:

c:Utilsusbip>usbip -a 192.168.31.203 1-1.4
usbip for windows ($Id$)

*** ERROR: cannot find device

This is due to the fact that the client does not work with a server built on a kernel older than version 3.14.
The usbip server on OpenWRT 19.07.3 is built on kernel 4.14.180.

Continuing my search, I stumble upon an updated development of the Windows client on github. Okay, Windows 10 x64 support is claimed, but the client is purely experimental, therefore there are a number of limitations.

So, first they ask to install the certificate, and indeed twice. Fine, we place it in Trusted Root Certification Authority and Trusted Publishers.

Next, it is necessary to switch the operating system to test mode. This is done with the command

bcdedit.exe /set TESTSIGNING ON

I couldn't do it the first time due to secure boot.To disable it, you need to reboot into UEFI and set secure boot to disable. On some laptop models, you may need to set a supervisor password.

After that, we boot into Windows and do bcdedit.exe /set TESTSIGNING ON
Windows says everything is okay. We reboot again and see the Test Mode notice in the bottom right corner, along with the version and build number of the OS.

What are all these manipulations for? To install an unsigned driver USB/IP VHCI.This can be done by downloading the files usbip.exe, usbip_vhci.sys, usbip_vhci.inf, usbip_vhci.cer, usbip_vhci.cat, and executing with administrator rights

usbip.exe install

or the second method, installing Legacy Hardware manually. I chose the second option, received a warning about the installation of an unsigned driver, and accepted it.

Next, we check that we can connect to a remote USB device by executing the command:

usbip.exe list -r

we receive the list of devices:

c:Utilsusbip>usbip.exe list -r 192.168.31.203
usbip: error: failed to open usb id database
Exportable USB devices
======================
 - 192.168.31.203
      1-1.4: unknown vendor : unknown product (1a86:7523)
           : /sys/devices/ssb0:1/ehci-platform.0/usb1/1-1/1-1.4
           : unknown class / unknown subclass / unknown protocol (ff/00/00)

on the error usbip: error: failed to open usb id database we do not pay attention, it doesn't affect the work.

Now, binding the device:

c:Utilsusbip>usbip.exe attach -r 192.168.31.203 -b 1-1.4

That's it, Windows has detected a new device, now it can be used as if it were physically connected to the laptop.

I had to struggle a bit with the Chinese engraver, as trying to install its CH341SER driver through the provided installer (yes, the engraver is based on Arduino) caused USB/IP VHCI to crash Windows into a BSOD. However, installing the CH341SER driver up to via usbip.exe solved the problem.

In conclusion: the engraver is buzzing and smoking in the kitchen with the window open and the door closed, I am observing the burning process from another room through the native software that does not sense anything unusual.

Sources used:

https://openwrt.org/docs/guide-user/services/usb.iptunnel
https://github.com/cezanne/usbip-win

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster