1. 定义存储在字符串索引 0xEE 处的 OS 字符串描述符
#define bMS_VendorCode ( 0x01 )
// "MSFT100" : index : 0xEE : langId : 0x0000
const U8 OS_StringDescritpor[ ] =
{ 0x12, 0x03, 'M', 0, 'S', 0, 'F', 0, 'T', 0, '1', 0, '0', 0, '0', 0, bMS_VendorCode, 0 };
处理 usb 标准请求时, 读取 index==0xEE 的串描述符, 返回 OS_StringDescritpor
bMS_VendorCode 将作为后续 Vendor 请求的请求代码
2. 设置扩展兼容 ID OS 特征描述符包
// "WINUSB\0\0" : wIndex : 0x0004
const U8 WINUSB_ExtendedCompatId_Descritpor[ ] =
{
0x28, 0x00, 0x00, 0x00, // dwLength
0x00, 0x01, // bcdVersion
0x04, 0x00, // wIndex
0x01, // bCount
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved[7]
0x00, // bFirstInterfaceNumber
0x01, // RESERVED ( 0x01 )
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, // compactiableID[8]
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // subCompactiableID[8]
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Reserved[6]
};
处理请求带代码为 bMS_VendorCode 的 vendor 请求时, 若设置包的 wIndex == 0x0004 返回WINUSB_ExtendedCompatId_Descritpor
3. 注册设备接口 GUID
// L"DeviceInterfaceGUID" : wIndex = 0x0005
// L"{12345678-1234-1234-1234-123456789ABC}"
//
const U8 WINUSB_ExtendedProperty_InterfaceGUID_Descritpor[ ] =
{
0x8E, 0x00, 0x00, 0x00, // dwTotalSize = Header + All sections
0x00, 0x01, // bcdVersion
0x05, 0x00, // wIndex
0x01, 0x00, // wCount
0x84, 0x00, 0x00, 0x00, // dwSize -- this section
0x01, 0x00, 0x00, 0x00, // dwPropertyDataType
0x28, 0x00, // wPropertyNameLength
'D', 0x00, 'e', 0x00, // bProperytName : WCHAR : L"DeviceInterfaceGUID"
'v', 0x00, 'i', 0x00, // bProperytName : WCHAR
'c', 0x00, 'e', 0x00, // bProperytName : WCHAR
'I', 0x00, 'n', 0x00, // bProperytName : WCHAR
't', 0x00, 'e', 0x00, // bProperytName : WCHAR
'r', 0x00, 'f', 0x00, // bProperytName : WCHAR
'a', 0x00, 'c', 0x00, // bProperytName : WCHAR
'e', 0x00, 'G', 0x00, // bProperytName : WCHAR
'U', 0x00, 'I', 0x00, // bProperytName : WCHAR
'D', 0x00, 0x00, 0x00, // bProperytName : WCHAR
0x4E, 0x00, 0x00, 0x00, // dwPropertyDataLength : 78 Bytes = 0x0000004E
'{', 0x00, '1', 0x00, // bPropertyData : WCHAR : L"{12345678-1234-1234-1234-123456789ABC}"
'2', 0x00, '3', 0x00, // bPropertyData
'4', 0x00, '5', 0x00, // bPropertyData
'6', 0x00, '7', 0x00, // bPropertyData
'8', 0x00, '-', 0x00, // bPropertyData
'1', 0x00, '2', 0x00, // bPropertyData
'3', 0x00, '4', 0x00, // bPropertyData
'-', 0x00, '1', 0x00, // bPropertyData
'2', 0x00, '3', 0x00, // bPropertyData
'4', 0x00, '-', 0x00, // bPropertyData
'1', 0x00, '2', 0x00, // bPropertyData
'3', 0x00, '4', 0x00, // bPropertyData
'-', 0x00, '1', 0x00, // bPropertyData
'2', 0x00, '3', 0x00, // bPropertyData
'4', 0x00, '5', 0x00, // bPropertyData
'6', 0x00, '7', 0x00, // bPropertyData
'8', 0x00, '9', 0x00, // bPropertyData
'A', 0x00, 'B', 0x00, // bPropertyData
'C', 0x00, '}', 0x00, // bPropertyData
0x00, 0x00 // bPropertyData
};
处理请求带代码为 bMS_VendorCode 的 vendor 请求时, 若设置包的 wIndex == 0x0005 返回WINUSB_ExtendedProperty_InterfaceGUID_Descritpor
至此, Windows 将安装 WinUsb.sys 作为设备的驱动