伴随端口CompanionPortNumber与伴随HUB链接名CompanionHubSymLnk
2026-09-29
本文链接为:http://www.usbzh.com/article/detail-1810.html ,欢迎转载,转载请附上本文链接。
通过IOCTL_USB_GET_PORT_CONNECTOR_PROPERTIES获取的结构信息如下:
typedef struct _USB_PORT_CONNECTOR_PROPERTIES {
// one based port number
ULONG ConnectionIndex;
// The number of bytes required to hold the entire USB_PORT_CONNECTOR_PROPERTIES
// structure, including the full CompanionHubSymbolicLinkName string
ULONG ActualLength;
// bitmask of flags indicating properties and capabilities of the port
USB_PORT_PROPERTIES UsbPortProperties;
// Zero based index number of the companion port being queried.
USHORT CompanionIndex;
// Port number of the companion port
USHORT CompanionPortNumber;
// Symbolic link name for the companion hub
WCHAR CompanionHubSymbolicLinkName[1];
} USB_PORT_CONNECTOR_PROPERTIES, *PUSB_PORT_CONNECTOR_PROPERTIES;
其中
- ConnectionIndex:该端口号
- CompanionPortNumber:是该端品对应的伴随端口
- CompanionHubSymbolicLinkName:端口对应的伴随端口所在的HUB的链接名
例用usbtreeviewer也可以快速速看到该信息,点击任意一HUB,即可以看到类似的信息:
=========================== USB Port2 ===========================
Connection Status : 0x01 (Device is connected)
Port Chain : 1-1-2
Properties : 0x01
IsUserConnectable : yes
PortIsDebugCapable : no
PortHasMultiCompanions : no
PortConnectorIsTypeC : no
ConnectionIndex : 0x02 (Port 2)
CompanionIndex : 0
CompanionHubSymLnk : USB#VID_05E3&PID_0626#5&31036e8e&0&13#{f18a0e88-c30c-11d0-8815-00a0c906bed8}
CompanionPortNumber : 0x02 (Port 2)
-> CompanionPortChain : 1-13-2
图例如下:
物理世界
┌─────────────────────────────────────────┐
│ USB 3.0 Type-A 连接器(1个) │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ USB 2.0 引脚 │ │ SuperSpeed 引脚│ │
│ └──────┬───────┘ └──────┬───────┘ │
└──────────┼─────────────────┼────────────┘
│ │
│ │
┌──────────▼───────┐ ┌──────▼────────────┐
│ USB 2.0 HUB │ │ USB 3.0 HUB │
│ (逻辑 HUB A) │ │ (逻辑 HUB B) │
│ │ │ │
│ Port 7 ◄───────┼──┼──► Port 3 │
└──────────┬───────┘ └──────┬────────────┘
│ │
│ │
┌──────────▼─────────────────▼────────────┐
│ Windows USB 栈 │
│ │
│ 查询 HUB A 的 Port 7 时: │
│ ConnectionIndex = 7 │
│ CompanionPortNumber = 3 │
│ CompanionHubSymbolicLinkName │
│ ──► 指向 HUB B 的符号链接 │
│ │
│ 查询 HUB B 的 Port 3 时: │
│ ConnectionIndex = 3 │
│ CompanionPortNumber = 7 │
│ CompanionHubSymbolicLinkName │
│ ──► 指向 HUB A 的符号链接 │
└─────────────────────────────────────────┘
获取方式如下:
UCHAR buff[512];
PUSB_PORT_CONNECTOR_PROPERTIES props = (PUSB_PORT_CONNECTOR_PROPERTIES)buff;
props->ConnectionIndex = PortIndex;
props->CompanionIndex = 0;
if (!DeviceIoControl(hDevice,
IOCTL_USB_GET_PORT_CONNECTOR_PROPERTIES,
buff, sizeof(buff),
buff, sizeof(buff),
&bytes, NULL))
{
return;
}
本文链接为:http://www.usbzh.com/article/detail-1810.html ,欢迎转载,转载请附上本文链接。
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936 USB技术交流3:1031974172
USB百科





