USB/IP项目总结
青云最近推出了云桌面功能,用户可以像使用本地计算机一样访问远程主机,支持USB重定向,不禁让我想起了2年前调试的一个开源项目USB/IP,当时还用英文写了一个总结性文档,放在这里方便以后查看。
USB/IP Summary
Abstract
The USB/IP project aims to provide users with the ability to access remote USB devices via IP network.
From a user’s perspective, there is no difference from accessing USB devices those plugged into your
local machine physically. The project is opened source and could be built into newer Linux kernel by
proper configuration. The shortage is that there is no official document demonstrating the architecture
and overall structure of it. This is part of the reason for the coming of this document.
Client/Server Model
The machine which a USB device physically attached is the server with a Linux system running upon, and the
machine from where a user access USB resource is the client, it can either be a Linux or a Windows box.
In the following section we will describe the structure of this project, how client talks to server and vice versa.
For simplicity, we will omit case that using a Linux box as the client side machine, and only discuss the topic
according to the following diagram.
Windows Client
There are two parts in client side, the user space tool and the underlying virtual bus driver; within this document
we will refer them to usbip.exe and USBIPEnum.sys, respectively. Firstly, a user launch usbip.exe to query exported
USB devices from a server, and he or she might decide to import a device if there is one available. If the import
request succeeded, usbip.exe would send an IRP to USBIPEnum.sys informing it to create a physical device object
which representing a real USB device plugged into the client machine. Certainly, there is no real device attached to
the client machine, but our system will treat it as a real one without aware. The system will then send many IRPs to
our virtual bus driver for querying purpose, such as device capability querying, device hardware ID querying and so
on. Some queries have nothing to do with the actual device on server side, and our virtual bus driver will finish them
immediately. But when the user access the data store on the remote USB device, our bus driver would receive IRPs
those associated with URBs (USB request block), the bus driver could not give her back the data required immediately.
In this case, USBIPEnum.sys will look up whether there is a pending read request from usbip.exe, and if
(1):
There is indeed one pending read request; USBIPEnum.sys will feed the read quest with a URB properly, the IRP is
enqueued and set to pending state. Till this time, the read operation from usbip.exe will successfully returned,
usbip.exe will then imbed the URB in a package according to the protocol between client and server and send this
package to the server. Usbip.exe always waits on a socket, when it receives a package from the server, it will call
WriteFile() API to write the package to our virtual USB device. Upon receiving the write IRP, USBIPEnum.sys gets
data from this write IRP and feeds the former pending IRP with appropriate data, and then that pending IRP would
be completed successfully, it would be de-queued subsequently.
(2):
There is no pending read request; the IRP will be enqueued and set to pending state. If there comes
a read request from usbip.exe some times later, USBIPEnum.sys will search through the queue to get
an IRP which has not been sent to the server. When it finds one, it will feed the read operation with info
from that found IRP, and all subsequent behaviors will be exactly the same as (1) above.
Linux Server
Similar to the client side, there are also two parts in server side, the user space tool usbipd and the driver part. Here
we will omit the discussion of usbip tool which used to list USB devices in the system or bind the USB device to our
driver. Usbipd is a tool to meet the requirement from the client side, for example exported devices querying and import
requesting.After usbipd exported a device to a client, a TCP connection would be established between them. Usbipd
will then send this TCP connection information to the underlying usbiphost driver, the latter will then start two threads
for receiving and sending purposes, respectively. The receiving thread will then wait on the established TCP connection
port to get request from client side. When the receiving thread gets a submit command from the client, it extract info
from the package and allocate an URB, set info into this URB appropriately and submit it to the USBCore. When the
system finish handling this URB, the sending thread in usbip-
host driver will be awaked, it will package the result of this URB and send to the client. There is also another driver named
usbip-core, which maintains an event handler loop. The event handler loop is started by usbip-host driver by invoking a
method exported by usbip-core. Before starting the event handler, usbip-host driver set some procedures for usbip
core for calling back purpose. For example, when a shutdown event happens, usbip-host will set the event bit, and usbip-
core will be noticed latterly, it then invokes the shutdown event handler which defined in usbip-host driver.
Kernel Debugging
Client: VMWare+Windbg
Windbg runs on your host machine, it connects to Windows client (XP, Win7) runs on virtual machine via named pipe.
System that runs on virtual machine imports USB device from remote Linux server.
Server: VMWare+KGDB
Both systems can run on a virtual machine, one is a debugger that run GDB and the other is a debug gee which act as
a server.Your physical USB device attached to the latter one. The debug gee must be built with kernel debugging switch
enabled and some other switch enabled if needed. One might encounter some configuration problems while playing with
this stuff, and there are many web sites you could go for help.
Prerequisite Knowledge
The developer should be familiar with these concepts: Windows Driver Model, IRP, URB, Pending state, etc.
USB/IP项目总结的更多相关文章
- Nginx 实现 IP+项目名 访问
参考: https://blog.csdn.net/csdn1152789046/article/details/51362735 修改前 项目放在Tomcat的webapps/ROOT/ 目录下面 ...
- 免费开源的获取代理ip项目
地址:https://github.com/awolfly9/IPProxyTool 根据教程获取ip,项目使用Python语言写的,正好可以让前些日子学了点Python皮毛的我长长见识: ip都是会 ...
- Tomcat不需要输入项目名便可访问项目(直接用域名或者ip)
一般需要输入项目名访问项目是怎么个方法呢? 直接将项目放在 tomcat 安装目录的 webapps 目录下, 然后在域名或者ip后面 域名(ip)/项目目录, 这样会显得比较麻烦. 那么应该怎么才可 ...
- 如何在tomcat部署项目(用ip访问)
找了好长时间的错误,server.xml中一点错误也没有,但就是访问不到,最终发现就是服务器没有开放80端口的缘故. 服务器是Windows系统 1.控制面板=>系统和安全=>Window ...
- Linux usb 5. usbip (USB Over IP) 使用实例
文章目录 0. 简介 1. Server 配置 2. Client 配置 参考资料 0. 简介 USB Over IP 是一种应用很多的场景,目前已经有现成的解决方案 usbip.linux 和 wi ...
- STM32 USB虚拟串口(转)
源:STM32 USB虚拟串口 串口调试在项目中被使用越来越多,串口资源的紧缺也变的尤为突出.很多本本人群,更是深有体会,不准备一个USB转串口工具就没办法进行开发.本章节来简单概述STM32低端芯片 ...
- STM32 USB虚拟串口
串口调试在项目中被使用越来越多,串口资源的紧缺也变的尤为突出.很多本本人群,更是深有体会,不准备一个USB转串口工具就没办法进行开发.本章节来简单概述STM32低端芯片上的USB虚拟串口的移植.在官方 ...
- [转]C,C++开源项目中的100个Bugs
[转]C,C++开源项目中的100个Bugs http://tonybai.com/2013/04/10/100-bugs-in-c-cpp-opensource-projects/ 俄罗斯OOO P ...
- C,C++开源项目中的100个Bugs
俄罗斯OOO Program Verification Systems公司用自己的静态源码分析产品PVS-Studio对一些知名的C/C++开源项目,诸如Apache Http Server.Chro ...
随机推荐
- luogu2569 [SCOI2010]股票交易
题解看这里 #include <iostream> #include <cstring> #include <cstdio> using namespace std ...
- angularJs模块ui-router之多视图
可以给ui-view指定名称,这样一个模板中就可以有多个ui-view.假设您有一个应用,需要动态填充graph.table data和filters,像下面这样: 当您需要使用多视图时,需要用到状态 ...
- 三丶人生苦短,我用python【第三篇】 pycharm
1 pycharm的下载安装 下载地址:https://www.jetbrains.com/pycharm/download/#section=windows ....安装没啥好说的 建议购买正版,其 ...
- C. RMQ with Shifts
C. RMQ with Shifts Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 131072KB 64-bit intege ...
- 【bzoj3956】Count 单调栈+可持久化线段树
题目描述 输入 输出 样例输入 3 2 0 2 1 2 1 1 1 3 样例输出 0 3 题解 单调栈+可持久化线段树 本题是 bzoj4826 的弱化版(我为什么做题总喜欢先挑难的做QAQ) $k$ ...
- 【bzoj4237】稻草人 分治+单调栈+二分
题目描述 JOI村有一片荒地,上面竖着N个稻草人,村民们每年多次在稻草人们的周围举行祭典. 有一次,JOI村的村长听到了稻草人们的启示,计划在荒地中开垦一片田地.和启示中的一样,田地需要满足以下条件: ...
- [luoguP2325] [SCOI2005]王室联邦(树分块乱搞)
传送门 想了半小时,没什么思路.. 看了题解,是个叫做树分块的奇奇怪怪的操作.. 题解 树分块的研究 #include <cstdio> #include <cstring> ...
- 【单调队列+尺取】HDU 3530 Subsequence
acm.hdu.edu.cn/showproblem.php?pid=3530 [题意] 给定一个长度为n的序列,问这个序列满足最大值和最小值的差在[m,k]的范围内的最长子区间是多长? [思路] 对 ...
- 空指针问题(java.lang.NullPointerException)
在Java中对值为null的指针调用任何方法,就会引发空指针异常(java.lang.NullPointerException).空指针异常绝对是Java中最难查找和调试的一种异常,你永远无法得到任何 ...
- leetcode 15. 3Sum 二维vector
传送门 15. 3Sum My Submissions Question Total Accepted: 108534 Total Submissions: 584814 Difficulty: Me ...