Linux usb 5. usbip (USB Over IP) 使用實例


0. 簡介

USB Over IP 是一種應用很多的場景,目前已經有現成的解決方案 usbip。linux 和 windows 環境下都有配套軟件,本文不分析原理就驗證一下 Linux 環境下 usbip 功能的使用。

在這里插入圖片描述
在這里插入圖片描述

1. Server 配置

運行環境為 ubuntu 20.04.2。操作命令如下:

// (1) 關閉防火牆
$ sudo ufw disable

// (2) 加載 server 端驅動
$ cd /lib/modules/`uname -r`/kernel/drivers/usb/usbip
$ sudo insmod usbip-core.ko
$ sudo insmod usbip-host.ko

// (3) 編譯安裝 usbip 用戶態工具 
$ cd /lib/modules/`uname -r`/build/tools/usb/usbip
$ ./autogen.sh && ./configure && make && sudo make install
$ sudo echo "/usr/local/lib/" >> /etc/ld.so.conf
$ sudo ldconfig

// (4) 啟動 usbip server 守護進程
$ sudo usbipd -D

// (5) 查詢 server 端可用的 device
$ usbip list -l
usbip: error: failed to open /usr/share/hwdata//usb.ids
 - busid 2-1 (0e0f:0003)
   unknown vendor : unknown product (0e0f:0003)

 - busid 1-2 (0781:5567)
   unknown vendor : unknown product (0781:5567)

$ lsusb
Bus 001 Device 007: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

// (6) 將其中的 u盤設備 export 出去
$ sudo usbip bind --busid 1-2
usbip: info: bind device on busid 1-1: complete

2. Client 配置

運行環境為 ubuntu 20.04.2。操作命令如下:

// (1) 關閉防火牆
$ sudo ufw disable

// (2) 加載 client 端驅動
$ cd /lib/modules/`uname -r`/kernel/drivers/usb/usbip
$ sudo insmod usbip-core.ko
$ sudo insmod vhci-hcd.ko

// (3) 編譯安裝 usbip 用戶態工具 
$ cd /lib/modules/`uname -r`/build/tools/usb/usbip
$ ./autogen.sh && ./configure && make && sudo make install

// (4) 查詢 server export 出來的 device
$ sudo usbip list --remote 192.168.232.128
usbip: error: failed to open /usr/share/hwdata//usb.ids
Exportable USB devices
======================
 - 192.168.232.128
        1-2: unknown vendor : unknown product (0781:5567)
           : /sys/devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2
           : (Defined at Interface level) (00/00/00)

// (5) 掛載 server 設備到 client 本地
$ sudo usbip attach --remote 192.168.232.128 -b 1-2
usbip: debug: usbip.c:129:[run_command] running command: `attach'
usbip: debug: usbip_attach.c:100:[import_device] got free port 0
libusbip: debug: vhci_driver.c:367:[usbip_vhci_attach_device2] writing: 0 3 65543 3
libusbip: debug: vhci_driver.c:372:[usbip_vhci_attach_device2] attach attribute path: /sys/devices/platform/vhci_hcd.0/attach
libusbip: debug: vhci_driver.c:380:[usbip_vhci_attach_device2] attached port: 0

// (6) 查看本地 usb 設備,已經可用看到 u盤設備,功能可用正常使用
$ sudo usbip port
usbip: error: failed to open /usr/share/hwdata//usb.ids
Imported USB devices
====================
Port 00: <Port in Use> at High Speed(480Mbps)
       unknown vendor : unknown product (0781:5567)
       3-1 -> usbip://192.168.232.128:3240/1-2
           -> remote bus/dev 001/007
$ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 2a45:0004 Meizu Corp. PRO 6
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

參考資料

1.USB/IP PROJECT
2.usbip/README
3.myusbip
4.USBIP介紹
5.USB/IP - a Peripheral Bus Extension for Device Sharing over IP Network
6.USB/IP: A Transparent Device Sharing Technology over IP Network


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM