USB Redirection PDF Print E-mail
Written by Laxmikant Rashinkar   
Saturday, 19 January 2013 20:24

We are working on adding USB redirection to XRdp.

 

As a first step, we plan to integrate the open source USBIP project into XRdp. Based on what Mr. Google has to say, it appears that getting USBIP to work is not trivial. So we played around with buildiing and installing USBIP on various platforms and, to cut a long story short, yup, it's not trivial.

 

This is the home page for USBIP: http://usbip.sourceforge.net

 

USBIP works in Windows as well as Linux. This document is all about the Linux implementation.

 

Since USBIP is all about moving USB traffic between two machines over a network, it uses the following terminology

  • USB Server: this is the machine where you plugin a physical USB device that you want to redirect. In our case, this machine will be running NeutrinoRDP (which is a fork of FreeRDP-1.0.1)
  • USB client: this is the remote machine and sees the USB devices exported by the USB Server as a virutal USB device. In our case, this machine will be running XRdp

First off, there are many versions of USBIP. For Linux kernels 2.6.28 and later, the USBIP code is part of the kernel distribution and can be found in drivers/staging/usbip. For kernels 2.6.27 and lower, code from the USBIP home page can be used.

 

Our objective was to run Debian Squeeze with kernel version 3.0.15 on the USB Server and LinuxMint 13 Mate 32 bit on the USB client system. The default kernel for Debian Squeeze is 2.6.32-5 and for LinuxMint 13 it is 3.2.0-23. Since we could not find the source for kernel 3.2.0 on kernel.org, we decided to use the USBIP package from the 3.2.1 kernel source.

 

Before we proceed to build the USBIP packages, you should be aware that LinuxMint distros have USBIP as installable binaries, but only for the userspace code. The kernel module drivers are installed as source, but when we built and deployed them, USBIP would not work. In fact, the kernel just hung up.

 

Building and deploying kernel 3.0.15 on Debian Squeeze

  • ensure following packages are installed
    • linux-header that matches your installed kernel
    • initramfs-tools
  • download kernel 3.2.1 from kernel.org
  • extract this kernel to our projects dir, so we have /home/lk/projects/linux-3.0.15
  • cd /home/lk/projects/linux-3.0.15
  • cp /usr/src/linux-headers-`uname -r`/.config . (notice that dot)
  • make oldconfig
  • make menuconfig (or make xconfig for UI based configuration)
  • make
  • make modules
  • sudo -s
  • make modules_install
  • make install
  • update-initramfs -c -k 3.0.15
  • cd /boot
  • update-grub2
  • optional: edit /etc/default/grub to change grub options
  • reboot system - it will boot into kernel 3.0.15 by default

Building and deploying USBIP-3.2.1 on Debian Squeeze (this is our USB Server machine)

  • from kernel.org, download kernel source 3.2.1 and extract it to a temp directory
  • from the extracted code,  copy drivers/staging/usbip/* to /home/lk/projects/usbip-3.2.1
  • building USBIP-3.2.1 kernel modules
    • cd /home/lk/projects/linux-3.0.15
    • make M=/home/lk/projects/usbip-3.2.1
    • if build is successful, drivers will be located in /home/lk/projects/usbip-3.2.1
    • NOTE: is you get an error stating linux/export.h not found, just comment out that line in the source code
  • buildiing usbip-3.2.1 userspace code
    • cd /home/lk/projects/usbip-3.2.1/userspace
    • ./configure --prefix=/home/lk/deploy/usbip-3.2.1
    • make
    • make install
    • usbip-3.2.1 binaries and libraries will be located in /home/lk/deploy/usbip-3.2.1

Buildiing and deploying USBIP-3.2.1 on LinuxMint 13 Mate 32bit system (this is our USB client machine)

  • use synaptic package manager or apt-get command to install linux-headers-3.2.0-23-generic package
  • from kernel.org, download kernel source 3.2.1 and extract it to /home/lk/projects so you will get /home/lk/projects/linux-3.2.1
  • building USBIP-3.2.1 kernel modules
    • cd /usr/src/linux-headers-3.2.0-23-generic
    • make M=/home/lk/projects/linux-3.2.1/drivers/staging/usbip
    • if build is successful, kernel drivers will be in /home/lk/projects/linux-3.2.1/drivers/staging/usbip
  • buildiing usbip-3.2.1 userspace code
    • cd /home/lk/projects/linux-3.2.1/drivers/staging/usbip/userspace
    • ./configure --prefix=/home/lk/deploy/usbip-3.2.1
    • make
    • make install
    • usbip-3.2.1 binaries and libraries will be located in /home/lk/deploy/usbip-3.2.1

Starting USBIP on the server machine (Debian Squeeze in our case)

  • sudo -s
  • cd /home/lk/projects/usbip-3.2.1
  • insmod usbip-core.ko
  • insmod usbip-host.ko
  • cd /home/lk/deploy/usbip-3.2.1/sbin
  • ./usbipd -D (this starts usbipd as a daemon)
  • run command ps -fe | grep usbipd to ensure usbipd is indeed running
  • run command ./usbip list -l to show a list of USB devices; this is what I get on my system

Local USB devices

=================

- busid 2-1 (046d:c31c)

2-1:1.0 -> usbhid

2-1:1.1 -> usbhid

 

- busid 2-2 (046d:c064)

2-2:1.0 -> usbhid

  • Now plugin the USB device that you want to redirect; in my case I'm pluggin in a USB thumb drive. Notice that a file browser pops up and displays the contents of the USB thum drive
  • runing command ./usbip list -l once again to show this
Local USB devices
=================
- busid 1-3 (0718:0069)
1-3:1.0 -> usb-storage
- busid 2-1 (046d:c31c)
2-1:1.0 -> usbhid
2-1:1.1 -> usbhid
- busid 2-2 (046d:c064)
2-2:1.0 -> usbhid
Notice the usb-storage device with a busid of 1-3 and VendorID:ProductID of 0718:0069. That is the device we just plugged in
  • now we need to bind our USB thumb drive so it is visible to the USB client
  • ./usbip bind --busid=1-3
  • if the bind is successful, notice that the file browser for the USB thumb drive closes automatically
  • our USB thumb drive is now exported and can be accessed remotely

starting USBIP on the client machine (LinuxMint 13 in our case)

  • sudo -s
  • cd home/lk/projects/linux-3.2.1/drivers/staging/usbip
  • insmod usbip-core.ko
  • insmod vhci-hcd.ko (this creates a virual USB hub)
  • cd /home/lk/deploy/usbip-3.2.1/sbin
  • run command ./usbip list --remote=<ip addr of USB Server> to see list of exported USB devices

./usbip list --remote=192.168.2.139

Exportable USB devices

======================

- 192.168.2.139

1-3: Imation Corp. : unknown product (0718:0069)

: /sys/devices/pci0000:00/0000:00:10.3/usb1/1-3

: (Defined at Interface level) (00/00/00)

:  0 - Mass Storage / SCSI / Bulk-Only (08/06/50)

  • we now need to attach to this exported USB device
  • ./usbip attach --host=192.168.2.139 --busid=1-3
  • if all goes well, you should see a file browser pop up showing the contents of the USB thumb drive that was plugged into the USB server machine
  • you can also run the command lsusb to list the attached device
  • to detach the exported USB device, you must run the command ./usbip detach --port=0
  • the port number is a bit of a mystery. I can't figure out how to determine the port number dynamically, other than knowing that the first device to be attached is port 0, the 2nd one is 1 etc. Older versions of usbip had a port option that displayed the port number, but newer version don't have this option
Take a look at the documentation in the usbip-3.2.1/userspace/README file

 

Last Updated on Saturday, 19 January 2013 23:47