USBIP虚拟控制器和根集线器HUB的设备信息分析
USBIP是一套可以实现USB远程设备的本机映射,这样就像在本地操作目标USB设备一样。其原理是在本地端通过安装一个虚拟的USB根控制器,根集线器,同时虚拟出4个USB端口,当远程USB设备连接到远程机器时,可以把远程设备的USB信息通过网络传输到本地,在本地的虚拟USB端口虚拟一个相同的设备,这样本地机器在操作这个虚拟的设备时,通过网络就像操作远程设备一样。这个功能相当于一个网络硬盘一样,只是这玩意用于USB设备。
USBIP代码开源,本人拿到的这一套代码比较老,不过还好支持X64系统,在Win10上安装有一点小问题,本人经过排查并修改了这个BUG.但这并不妨碍本人这一套代码的敬佩。
USBIP的工程目录
USBIP的工程目录如下图所示,有设备端的,有主机端的,有关于网络通讯端,也有公共的代码。本人现在并未完全研究,所以也暂时说不上来这些代码的功能,但并不妨碍我们对这些代码有一个认识.
工程名 | 输出 | 类型 |
---|---|---|
attacher | attacher.exe | 应用 |
libdrv | libdrv.lib | 驱动 |
usbip_common | usbip_common.lib | |
usbip_stub | usbip_stub.sys | 驱动 |
usbip_vhci | usbip_vhci.sys | 驱动 |
usbip_vhci_ude | usbip_vhci_ude.sys | 驱动 |
usbipd | usbipd.exe | 应用 |
USBIP编译后的
USBIP整个工程编译完成后如下图:
除过本人调试要用的intall.bat和Devcon.exe,剩下的都是编译后的文件。
USBIP的安装
在主机端即需要虚拟USB设备端,是需要先安装虚拟USB控制器和虚拟USB集线器的。不过实际我们只需要安装根控制器,而根集线器会自动安装。
USBIP使用如下命令安装:
usbip.exe install -w
usbip.exe对应的工程为usbip,而且该工程引用了usbip_common编译后的lib文件。
而本人通过devcon也可以使用如下方式安装:
CD /d %~dp0
devcon.exe install usbip_root.inf "USBIPWIN\root"
执行完成以上命令后,就可以看到USBIP虚拟控制器和根集线器的驱动安装完成。
我们在设备管理器中可以看到如下:
我们对设备树进行整理:
名称 | sys文件 | inf文件 | 硬件ID |
---|---|---|---|
usbip-win VHIC Root | usbip_vhic.sys | usbip_root.inf | USBIPWIN\root |
usbip-win VHCI | usbip_vhic.sys | usbip_vhci.inf(oem115.inf) | USBIPWIN\vhci |
usbip-win VHUB | usbip_vhic.sys | usbip_vhci.inf(oem115.inf) | USB\ROOT_HUB&VID1209&PID8250&REV0000 |
我们也可以通过USBTreeview来看到设备树,其中VHCI-USB控制器的信息如下图:
===================== USB Host Controller =======================
+++++++++++++++++ Device Information ++++++++++++++++++
Device Description : usbip-win VHCI
Device Path 1 : \\?\USBIPWIN#vhci#1&79f5d87&58#{3abf6f2d-71c4-462a-8a92-1e6861e6af27} (GUID_DEVINTERFACE_USB_HOST_CONTROLLER)
Device Path 2 : \\?\USBIPWIN#vhci#1&79f5d87&58#{d35f7840-6a0c-11d2-b841-00c04fad5171}
Kernel Name : \Device\0000007c
Device ID : USBIPWIN\VHCI\1&79F5D87&58
Hardware IDs : USBIPWIN\vhci
Driver KeyName : {36fc9e60-c465-11cf-8056-444553540000}\0116 (GUID_DEVCLASS_USB)
Driver : \SystemRoot\System32\drivers\usbip_vhci.sys (Version: Date: 2021-04-14)
Driver Inf : C:\Windows\inf\oem115.inf
Legacy BusType : PNPBus
Class : USB
Class GUID : {36fc9e60-c465-11cf-8056-444553540000} (GUID_DEVCLASS_USB)
Service : usbip_vhci
Enumerator : USBIPWIN
Location Info : Root
Manufacturer Info : usbip-win
Capabilities : 0x00 (-)
Status : 0x0180200A (DN_DRIVER_LOADED, DN_STARTED, DN_DISABLEABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER)
Problem Code : 0
Address : 1
HcDisableSelectiveSuspend: 0
EnableSelectiveSuspend : 0
SelectiveSuspendEnabled : 0
EnhancedPowerMgmtEnabled : 0
IdleInWorkingState : 0
WakeFromSleepState : 0
Power State : D0 (supported: D0, D3)
Child Device 1 : usbip-win VHUB
Device Path : \\?\USB#ROOT_HUB#2&31d71e8d&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8} (GUID_DEVINTERFACE_USB_HUB)
Kernel Name : \Device\0000007d
Device ID : USB\ROOT_HUB\2&31D71E8D&0
Class : USB
Driver KeyName : {36fc9e60-c465-11cf-8056-444553540000}\0117 (GUID_DEVCLASS_USB)
Service : usbip_vhci
--------------- USB Hostcontroller Info0 --------------
PciVendorId : 0x0000
PciDeviceId : 0x0000
PciRevision : 0x00
NumberOfRootPorts : 0x01 (1 Ports)
ControllerFlavor : 0x3E8 (1000 = EHCI_Generic)
HcFeatureFlags : 0x00
Port Power Switching : no
Selective Suspend : no
Legacy BIOS : no
Roothub Symbolic Link : USB#ROOT_HUB#2&31d71e8d&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8}
BusStatistics Error : ERROR_INVALID_FUNCTION
DriverVersion Error : ERROR_INVALID_FUNCTION
BandwidthInfo Error : ERROR_INVALID_FUNCTION
-------- USB Hostcontroller Power States Info ---------
SystemState : S0 S1 S2 S3 S4 S5
HcDevicePowerState : D0 -- -- -- D3 --
HcDeviceWake : -- -- -- -- -- --
HcSystemWake : -- -- -- -- -- --
RhDevicePowerState : -- D3 D3 D3 D3 --
RhDeviceWake : D2 D2 D2 D2 D2 D2
RhSystemWake : S0 S0 S0 S0 S0 S0
LastSystemSleepState : -- -- -- -- -- --
CanWakeup : no no no no no no
IsPowered : no no no no no no
根集线器HUB的信息如下图:
========================= USB Root Hub =========================
Sum of Hubs and Devices : 0
Sum of Endpoints : 0
+++++++++++++++++ Device Information ++++++++++++++++++
Device Description : usbip-win VHUB
Device Path : \\?\USB#ROOT_HUB#2&31d71e8d&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8} (GUID_DEVINTERFACE_USB_HUB)
Kernel Name : \Device\0000007d
Device ID : USB\ROOT_HUB\2&31D71E8D&0
Hardware IDs : USB\VID_1209&PID_8250&REV_0000
Driver KeyName : {36fc9e60-c465-11cf-8056-444553540000}\0117 (GUID_DEVCLASS_USB)
Driver : \SystemRoot\System32\drivers\usbip_vhci.sys (Version: Date: 2021-04-14)
Driver Inf : C:\Windows\inf\oem115.inf
Legacy BusType : PNPBus
Class : USB
Class GUID : {36fc9e60-c465-11cf-8056-444553540000} (GUID_DEVCLASS_USB)
Service : usbip_vhci
Enumerator : USB
Location Info : VHCI
Manufacturer Info : usbip-win
Capabilities : 0x00 (-)
Status : 0x0180200A (DN_DRIVER_LOADED, DN_STARTED, DN_DISABLEABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER)
Problem Code : 0
Address : 1
HcDisableSelectiveSuspend: 0
EnableSelectiveSuspend : 0
SelectiveSuspendEnabled : 0
EnhancedPowerMgmtEnabled : 0
IdleInWorkingState : 0
WakeFromSleepState : 0
Power State : D0 (supported: D0, D3)
------------------- USB Hub Descriptor -----------------
bDescriptorLength : 0x09 (9 bytes)
bDescriptorType : 0x29 (Hub Descriptor)
bNumberOfPorts : 0x06 (6 Ports)
wHubCharacteristics : 0x0000
Power switching : Ganged
Compound device : No
Over-current protection : Global
TT Think Time : At most 8 FS bit times
Port Indicators : Not supported
bPowerOnToPowerGood : 0x01 (2 ms)
bHubControlCurrent : 0x01 (1 mA)
DeviceRemovable : 0x00
Bit 0 : 0 (reserved, any value)
Bit 1 : 0 (Device at Port 1 is removable)
Bit 2 : 0 (Device at Port 2 is removable)
Bit 3 : 0 (Device at Port 3 is removable)
Bit 4 : 0 (Device at Port 4 is removable)
Bit 5 : 0 (Device at Port 5 is removable)
Bit 6 : 0 (Device at Port 6 is removable)
Bit 7 : 0 (unused, must be 0)
PowerControlMask : 0x00
Data (HexDump) : 09 29 06 00 00 01 01 00 00 .).......
HubIsBusPowered : 0x00 (Self Powered)
-------------- Extended USB Hub Descriptor -------------
HubType : USB Root Hub
HighestPortNumber : 6
------------------- USB Hub Descriptor -----------------
bDescriptorLength : 0x09 (9 bytes)
bDescriptorType : 0x29 (Hub Descriptor)
bNumberOfPorts : 0x06 (6 Ports)
wHubCharacteristics : 0x0000
Power switching : Ganged
Compound device : No
Over-current protection : Global
TT Think Time : At most 8 FS bit times
Port Indicators : Not supported
bPowerOnToPowerGood : 0x01 (2 ms)
bHubControlCurrent : 0x01 (1 mA)
DeviceRemovable : 0x00
Bit 0 : 0 (reserved, any value)
Bit 1 : 0 (Device at Port 1 is removable)
Bit 2 : 0 (Device at Port 2 is removable)
Bit 3 : 0 (Device at Port 3 is removable)
Bit 4 : 0 (Device at Port 4 is removable)
Bit 5 : 0 (Device at Port 5 is removable)
Bit 6 : 0 (Device at Port 6 is removable)
Bit 7 : 0 (unused, must be 0)
PowerControlMask : 0x00
Data (HexDump) : 09 29 06 00 00 01 01 00 00 .).......
----------------- USB Hub Capabilities ----------------
HighSpeedCapable : No
HighSpeed : No
MultiTtCapable : Yes
HubIsMultiTt : Yes
ArmedWakeOnConnect : Yes
IsBusPowered : No
IsRoot : Yes
Data (HexDump) : BC FF FF FF ....