Regularly, the problem arises of connecting a USB device to a remote PC via a local area network. Under the cat is the story of my search in this direction, and the path to a ready-made solution based on the open-source
USB / IP project with a description of obstacles carefully set by various people along this path, as well as ways to circumvent them.
Part One, Historical
If the machine is virtual - all this is easy. The functionality of USB probros from the host to the virtual machine appeared in VMWare 4.1. But in my case, the security key, recognized as WIBU-KEY, had to be connected to different machines at different times, and not only virtual ones.
The first search round back in 2009 led me to a piece of hardware called
TrendNet TU2-NU4Pros:
Minuses:
- does not always work. Suppose the Guardant Stealth II protection key does not start through it, cursing with the error “the device cannot be started”.
- Management software (read - mount and unmount USB devices) is shabby to the extreme. Command line keys, automation - not, not heard. Everything is just hands. Nightmare.
- the control software searches for the piece of hardware on the network by broadcasting, so it only works within one broadcast segment of the network. It is impossible to specify the IP address of the piece of iron with your hands. Is a piece of iron in another subnet? Then you have a problem.
- developers have hammered on the device, sending bug reports is useless.
The second round happened at a time not so remote, and led me to the topic of the article -
USB / IP project . It attracts with openness, especially since the guys from
ReactOS signed a driver for Windows to them, so now even on x64 everything works without any crutches like a test mode. For what the team ReactOS many thanks! Everything sounds beautiful, let's try to feel, is it really? Unfortunately, the project itself is also forgotten, and there is no need to count on support - but where ours did not disappear, there is a source code, we will understand!
')
Part Two, server-linux
A USB / IP server sharing USB devices over the network can only be raised on a Linux-based OS. Well, Linux is so Linux, we install on the Debian 8 virtual machine in the minimum configuration, the standard hand movement:
sudo apt-get update sudo apt-get upgrade sudo apt-get install usbip
Established. Further, the Internet suggests that you need to download the usbip module, but - hello, the first rake. There is no such module. This is due to the fact that most of the manuals in the network refer to the older 0.1.x branch, and in the extreme 0.2.0 the usbip modules have different names.
Therefore:
sudo modprobe usbip-core sudo modprobe usbip-host sudo lsmod | grep usbip
Well, add the following lines to / etc / modules to load them automatically when the system starts:
usbip-core usbip-host vhci-hcd
Run the usbip server:
sudo usbipd -D
Further, the world-wide mind tells us that scripts that allow us to manage the server are bundled with usbip — show which device it will share across the network, view the status, and so on. Here we are waiting for another garden tool - these scripts in the 0.2.x branch, again renamed. You can get a list of commands using
sudo usbip
After reading the description of the commands, it becomes clear that in order to share the required USB-device, usbip wants to know its Bus ID. Dear viewers, the rake number three in the arena: the Bus ID that will give us
lsusb (the seemingly most obvious path) is not suitable for it! The fact is that the glands like USB hubs are ignored by usbip. Therefore, we use the built-in command:
user@usb-server:~$ sudo usbip list -l - busid 1-1 (064f:0bd7) WIBU-Systems AG : BOX/U (064f:0bd7)
Note: hereinafter in the listings I will describe everything using the example of my particular USB dongle. Your name of the piece of iron and steam VID: PID can and will be different. Mine is called Wibu-Systems AG: BOX / U, VID 064F, PID 0BD7.Now we can share our device:
user@usb-server:~$ sudo usbip bind --busid=1-1 usbip: info: bind device on busid 1-1: complete
Cheers, comrades!
user@usb-server:~$ sudo usbip list -r localhost Exportable USB devices ====================== - localhost 1-1: WIBU-Systems AG : BOX/U (064f:0bd7) : /sys/devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb1/1-1 : Vendor Specific Class / unknown subclass / unknown protocol (ff/00/ff)
Three cheers, comrades! The server shared the piece of iron over the network, and we can connect it! It remains only to add the autorun of the usbip daemon to /etc/rc.local
usbipd -D
Part Three, Client and Tangled
I tried to connect the shared device over the network to a machine running Debian immediately on the same server, and everything connected perfectly:
sudo usbip attach --remote=localhost --busid=1-1
Go to Windows. In my case, it was Windows Server 2008R2 Standard Edition. The official manual asks to install the driver first. The procedure is beautifully described in the readme attached to the windows-client, we do everything as it is written, everything works out. On XP also works without any difficulties.
Having unpacked the client, we try to mount our key:
C:\Program Files\USB-IP>usbip -a %server-ip% 1-1 usbip err: usbip_network.c: 121 (usbip_recv_op_common) recv op_common, -1 usbip err: usbip_windows.c: 756 (query_interface0) recv op_common usbip err: usbip_windows.c: 829 (attach_device) cannot find device
Oh oh. Something went wrong. We use the skill of Google. There are fragmentary mentions that something is wrong with constants; in the server part, the developers changed the protocol version when upgrading to version 0.2.0, but forgot to make it in the client under Win. The proposed solution - change the constant in the source and rebuild the client.
But I really do not want to download Visual Studio for the sake of this procedure. But I have a good old Hiew. In the source code, the constant is declared as a double word. Look in the file 0x00000106, replacing with 0x00000111. Do not forget the reverse byte order. The result - two matches, patchim:
[usbip.exe] 00000CBC: 06 11 00000E0A: 06 11
Yeah ... yes!
C:\Program Files\USB-IP>usbip -a %server-ip% 1-1 new usb device attached to usbvbus port 1
At this one could finish the presentation, but the music did not play long. Rebooting the server, I found that the device is not mounted on the client!
C:\Program Files\USB-IP>usbip -a %server-ip% 1-1 usbip err: usbip_windows.c: 829 (attach_device) cannot find device
And that's all. Even the all-knowing Google could not answer me. And at the same time, the command to display devices available on the server quite correctly shows - here it is, the key, you can mount. I try to mount from under Linux - it works! And if now try out from under Windows? Oh horror - it works!
Rake last: something there in the server code is not written. When a device is shared, it does not read the number of USB descriptors from it. And when mounting the device from under Linux, this field is filled. Unfortunately, I am familiar with development under Linux at the level “make && make install”. Therefore, the problem was solved with the help of a rather dirty hack - by adding to /etc/rc.local
usbip attach --remote=localhost --busid=1-1 usbip port usbip detach --port=00
The final part
After some ordeal, it works. The desired is received, now the key can be mounted to any PC (and unmounted, of course, also), including outside the broadcast network segment. If you want to - you can do this using the shell script. What is nice - the pleasure is absolutely free.
I hope that my experience will help Habrazhiteli to bypass those rakes, which were imprinted on my forehead. Thanks for attention!