-
1Step 1
Intro
This guide goes through the setup of both client and server. It was written with a Debian/Ubuntu GNU/Linux system in mind, however, all of the tools are common to all Linux distributions, instructions can easily be adapted (instructions will happily be accepted and added for other distributions).
A deb package is available that automates steps 2 & 3, these are available from https://github.com/timsavage/usbip-tools/releases
This solution uses USBIP to export the USB device and some UDEV rules to automate the exporting when a device is plugged in.
Security
A note on the security of this solution. usbipd does not include any security mechanisms, similar to other UNIX protocols (eg NFS). To make this solution secure some suggestions would be:
- Configure your firewall rules to only allow access from white listed IPs
- Configure usbipd to listen on localhost only and tunnel over SSH
-
2Step 2
Server Setup
Note: Before continuing ensure you do not have the Debian usbip package installed. This package is out of date and the project has since been merged into the kernel proper.
Install the USBIP kernel module and tools:
# Install the Linux tools package $ sudo apt install linux-tools-generic # Ensure the kernel module is inserted $ sudo modprobe usbip_host
To ensure the module is loaded on restart add the following to the file /etc/modules-load.d/usbip-server-tools.conf
# USBIP Host module loaded usbip_host
Finally start the usbip daemon to export the devices:
# Start USB IP as a daemon (-P will create a PID file /var/run/usbipd.pid) $ sudo usbipd -D -P
Add UDEV rules to automatically export devices when they are plugged in, add the following to the file
/etc/udev/rules.d/91-usbip-server-tools.rules# Auto bind any FTDI device (well any product that includes an FTDI interface). SUBSYSTEM=="usb" ATTRS{idVendor}=="0403" ATTRS{idProduct}=="6001" RUN+="/usr/bin/usbip bind -b $kernel" # Auto bind a USBTiny ISP SUBSYSTEM=="usb" ATTRS{idVendor}=="1781" ATTRS{idProduct}=="0c9f" RUN+="/usr/bin/usbip bind -b $kernel"
-
3Step 3
Client Setup
Install the USBIP kernel module and tools:
# Install the Linux tools package $ sudo apt install linux-tools-generic # Ensure the kernel module is inserted $ sudo modprobe vhci-hcd
To ensure the module is loaded on restart add the following to the file /etc/modules-load.d/usbip-client-tools.conf
# USBIP Host module loaded vhci-hcd
-
4Step 4
Connecting Remote Devices
With the setup complete the next step is to connect to a remote device
- Plugin your USB device to your server (either FTDI serial device or an USBTiny ISP, for other devices skip to step 5)
- Check the device is available on the client:
# List remote devices $ sudo usbip list -r $REMOTE_HOST Exportable USB devices ======================
- $REMOTE_HOST
3-1: Multiple Vendors : USBtiny (1781:0c9f)
: /sys/devices/pci0000:00/0000:00:1d.1/usb3/3-1
: Vendor Specific Class / unknown subclass / unknown protocol (ff/00/00) - The plugged in device should appear in the list, you will need to take note of the bus number (in this case 3-1). This is needed to attach the device for use on your local machine.
- Attach the device on your client machine:
# Attach to the exported device $ sudo usbip attach -r $REMOTE_HOST -b 3-1 # Confirm the device is available with lsusb $ lsusb ...snip... Bus 009 Device 022: ID 1781:0c9f Multiple Vendors USBtiny ...snip...
- Device is ready to use.
-
5Step 5
Adding support for additional USB devices
Technically any USB device can be exported using usbip, adding support for another device is essentially about configuring UDEV to automatically bind (export) the device when a device is plugged in.
All USB devices are identified by two values the Vendor ID and the Product ID. These IDs are used in the UDEV rules file to match known USB devices and execute the command to bind the device.
The entry in the UDEV rules file:
SUBSYSTEM=="usb" ATTRS{idVendor}=="1781" ATTRS{idProduct}=="0c9f" RUN+="/usr/bin/usbip bind -b $kernel"
Basically breaks down to match USB devices with a vendor ID of 0x1781, product ID of 0x0c9f and execute the command to bind the device. The $kernel is a macro that is replaced by the kernel ID of the device.
The combination of 0x1781 and 0x0c9f is the USB Tiny. See http://www.linux-usb.org/usb.ids
To identify the vendor and product IDs use lsusb to list all of the devices on the server machine, as you can see from the listing in step 4 the values 1781:0c9f are listed. Use those values to add in additional entries into the rules file to support more devices.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.