Monday, August 15, 2016

usb over ip

you can share usb device over tcp/ip using usbip

*** setup information***
kernel: 4.4.0-21-generic
linux distro: ubuntu
server ip (pc that share usb device): 192.168.0.212


I- compile kernel driver and install
1- install kernel source
$ sudo apt-get install linux-source

2- extract the kernel source archive
$ cd  /usr/src/linux-source-4.4.0
$ sudo tar xvf linux-source-4.4.0.tar.bz2
$ cd linux-source-4.4.0/

3- copy Module.symvers from kernel header
$ sudo cp /usr/src/linux-headers-4.4.0-21-generic/Module.symvers .

4-  go to usbip directory and do the compiling and install
$ cd ./drivers/usb/usbip
$ sudo make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
$ sudo make -C /lib/modules/$(uname -r)/build M=$(pwd) modules_install 

II- compile usbip tools and install
1- run autogen.sh script
$ cd -
$ cd tools/usb/usbip
$ sudo sh autogen.sh

2- compile and install
$ sudo ./configure
$ sudo make
$ sudo make install

3- run ldconfig to load newly install lib
$ sudo ldconfig

III- load usbip kernel module
$ sudo modprobe usbip-core
$ sudo modprobe usbip-host
$ sudo modprobe vhci-hcd

**** *** **
we have to do all the above step on both client and server


*** server part ****
1- list all the usb that connect to our machine
$ sudo /usr/local/sbin/usbip list -l
 - busid 3-1 (0bb4:0c02)
   HTC (High Tech Computer Corp.) : Dream / ADP1 / G1 / Magic / Tattoo (Debug) (0bb4:0c02)

 - busid 3-12 (04f2:b398)
   Chicony Electronics Co., Ltd : unknown product (04f2:b398)

 - busid 3-2 (0461:4e54)
   Primax Electronics, Ltd : unknown product (0461:4e54)

 - busid 3-7 (8087:07dc)
   Intel Corp. : unknown product (8087:07dc)


2- now we want to share busid 3-2 (0461:4e54)
$ sudo  /usr/local/sbin/usbip bind --busid=3-2
usbip: info: bind device on busid 3-2: complete

$ sudo  /usr/local/sbin/usbipd


 *** client part ***
1- list all the available usb devices that the server share
$ sudo /usr/local/sbin/usbip list -r 192.168.0.212
Exportable USB devices
======================
 - 192.168.0.212
        3-2: Primax Electronics, Ltd : unknown product (0461:4e54)
           : /sys/devices/pci0000:00/0000:00:14.0/usb3/3-2
           : (Defined at Interface level) (00/00/00)



2- attach the shared usb to our client machine
$ sudo /usr/local/sbin/usbip attach --remote=192.168.0.212 --busid=3-2

*** Now we can start using the usb as if is it physically attach to our machine


-to detach the usb from our client use the following
$ sudo usbip detach --port=0

- screenshot on client of the usb that share from server machine


No comments:

Post a Comment