CH569设备USB2.0支持WCID-WINUSB-基于MSOS-V2.0
2025-09-04
0
0
由于MSOS1.0是通过0xee的字符串触发的,且需要设备描述符bcdUSB的值设为0x200,在获取信息时需要:
- 获取字符串描述符(0xee),解析出vendorId
- 发送vendor控制请求,Index=04 00 获取兼容ID的内容
- 发送vendor控制请求,Index=05 00 获取Winusb驱动设备的DeviceInterfaceGUIDs(实际好像不发生)
对于MSOS-V2.0,其流程如下:
- 获取BOS描述符(索引为0x0f),BOS描述符包括BOS描述符和索引为5的平台描述符
- 根据BOS描述符信息下发index = 07 00 的vendor请求。
前题 建议设置bcdUSB的值设为0x210
BOS描述符内容如下:
const uint8_t WINUSB20_WCIDBOS [33] =
{
///////////////////////////////////////
/// WCID20 BOS descriptor
///////////////////////////////////////
0x05, /* bLength */
0x0f, /* bDescriptorType */
0x21, 0x00, /* wTotalLength */
0x01, /* bNumDeviceCaps */
///////////////////////////////////////
/// WCID20 device capability descriptor
///////////////////////////////////////
0x1c, /* bLength */
0x10, /* bDescriptorType */
0x05, /* bDevCapabilityType 平台描描述符 */
0x00, /* bReserved */
0xdf, 0x60, 0xdd, 0xd8, 0x89, 0x45, 0xc7, 0x4c, /* bPlatformCapabilityUUID_16 */
0x9c, 0xd2, 0x65, 0x9d, 0x9e, 0x64, 0x8a, 0x9f, /* bPlatformCapabilityUUID_16 */
0x00, 0x00, 0x03, 0x06, /* dwWindowsVersion */
sizeof(WINUSB20_WCIDDescriptorSet) & 0xff, (sizeof(WINUSB20_WCIDDescriptorSet)>>8) &0xff ,/* wDescriptorSetTotalLength */
1, /* bVendorCode */
0x00, /* bAltEnumCode */
};
通过BUSHOUND模拟:
然后系统解析BOS中的平台描述符,解析出vendorid(这里为1),OS2.0描述符集总长度。
然后系统通过index=07 00 下发vendor请求
通过BUSHOUND模拟请求:
const uint8_t WINUSB20_WCIDDescriptorSet [162] =
{
///////////////////////////////////////
/// WCID20 descriptor set descriptor
///////////////////////////////////////
0x0a, 0x00, /* wLength */
0x00, 0x00, /* wDescriptorType */
0x00, 0x00, 0x03, 0x06, /* dwWindowsVersion */
0xa2, 0x00, /* wDescriptorSetTotalLength */
///////////////////////////////////////
/// WCID20 compatible ID descriptor
///////////////////////////////////////
0x14, 0x00, /* wLength */
0x03, 0x00, /* wDescriptorType */
/* WINUSB */
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, /* cCID_8 */
/* */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* cSubCID_8 */
///////////////////////////////////////
/// WCID20 registry property descriptor
///////////////////////////////////////
0x84, 0x00, /* wLength */
0x04, 0x00, /* wDescriptorType */
0x07, 0x00, /* wPropertyDataType */
0x2a, 0x00, /* wPropertyNameLength */
/* DeviceInterfaceGUIDs */
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, /* wcPropertyName_21 */
'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, /* wcPropertyName_21 */
't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00, /* wcPropertyName_21 */
'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, /* wcPropertyName_21 */
'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, /* wcPropertyName_21 */
0x00, 0x00, /* wcPropertyName_21 */
0x50, 0x00, /* wPropertyDataLength */
/* {1D4B2365-4749-48EA-B38A-7C6FDDDD7E26} */
'{', 0x00, '1', 0x00, 'D', 0x00, '4', 0x00, /* wcPropertyData_40 */
'B', 0x00, '2', 0x00, '3', 0x00, '6', 0x00, /* wcPropertyData_40 */
'5', 0x00, '-', 0x00, '4', 0x00, '7', 0x00, /* wcPropertyData_40 */
'4', 0x00, '9', 0x00, '-', 0x00, '4', 0x00, /* wcPropertyData_40 */
'8', 0x00, 'E', 0x00, 'A', 0x00, '-', 0x00, /* wcPropertyData_40 */
'B', 0x00, '3', 0x00, '8', 0x00, 'A', 0x00, /* wcPropertyData_40 */
'-', 0x00, '7', 0x00, 'C', 0x00, '6', 0x00, /* wcPropertyData_40 */
'F', 0x00, 'D', 0x00, 'D', 0x00, 'D', 0x00, /* wcPropertyData_40 */
'D', 0x00, '7', 0x00, 'E', 0x00, '2', 0x00, /* wcPropertyData_40 */
'6', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00, /* wcPropertyData_40 */
};
这里的 {1D4B2365-4749-48EA-B38A-7C6FDDDD7E26}为设备接口GUID.
通过WINOBJ可以看到:
查看设备注册表信息:
相关代码修改:
UINT16 GetDesc()
{
UINT16 SetupLen = 0;
switch( UsbSetupBuf->wValueH )
{
case USB_DESCR_TYP_DEVICE:
pDescr = (UINT8 *)hs_device_descriptor;
SetupLen = ( SetupReqLen > sizeof(hs_device_descriptor) )? sizeof(hs_device_descriptor):SetupReqLen;
break;
case USB_DESCR_TYP_CONFIG:
pDescr = (UINT8 *)hs_config_descriptor;
SetupLen = (SetupReqLen > sizeof(hs_config_descriptor) )? sizeof(hs_config_descriptor):SetupReqLen;
break;
case 0xf:
pDescr = (UINT8 *)WINUSB20_WCIDBOS;
SetupLen = (SetupReqLen > sizeof(WINUSB20_WCIDBOS) )? sizeof(WINUSB20_WCIDBOS):SetupReqLen;
break;
...
}
...
}
UINT16 U20_NonStandard_Request_Deal()
{
UINT8 endp_dir;
SetupLen = UsbSetupBuf->wLength;
endp_dir = UsbSetupBuf->bRequestType & 0x80;
UINT16 len = 0;
SetupLen = USB_DESCR_UNSUPPORTED;
switch(SetupReq)
{
case 0x01://vendor id
switch(UsbSetupBuf->wIndexL)
{
case 0x04: //兼容ID
pDescr = (UINT8 *)CompactId20;
SetupLen = ( SetupReqLen > sizeof(CompactId20) )? sizeof(CompactId20):SetupReqLen;
break;
case 0x05: //接口GUID
pDescr = (UINT8 *)COMP_IF3_WCIDProperties;
SetupLen = sizeof(COMP_IF3_WCIDProperties);
break;
case 0x07:
pDescr = (UINT8 *)WINUSB20_WCIDDescriptorSet;
SetupLen = sizeof(WINUSB20_WCIDDescriptorSet);;
break;
default:
break;
}
break;
default:
break;
}
if( (SetupLen != USB_DESCR_UNSUPPORTED) && (SetupLen != 0))
{
len = (SetupLen >= U20_UEP0_MAXSIZE ) ? U20_UEP0_MAXSIZE : SetupLen;
if(endp_dir)
{
memcpy(endp0RTbuff, pDescr, len );
pDescr += len;
}
SetupLen -= len;
}
printf("SetupLen=%d\r\n",SetupLen);
return len;
}
- MSOS2.0的相关文档详见:https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-os-2-0-descriptors-specification
- MSOS2.0的中文版可参考 https://www.usbzh.com/article/detail-1069.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