6#include "libxr_type.hpp"
7#include "usb/core/bos.hpp"
8#include "usb/core/core.hpp"
10namespace LibXR::USB::WinUsbMsOs20
16static constexpr uint16_t MSOS20_DESCRIPTOR_INDEX = 0x0007;
17static constexpr uint16_t MSOS20_SET_ALT_ENUMERATION = 0x0008;
20static constexpr uint16_t MS_OS_20_SET_HEADER_DESCRIPTOR = 0x0000;
21static constexpr uint16_t MS_OS_20_SUBSET_HEADER_CONFIGURATION = 0x0001;
22static constexpr uint16_t MS_OS_20_SUBSET_HEADER_FUNCTION = 0x0002;
23static constexpr uint16_t MS_OS_20_FEATURE_COMPATIBLE_ID = 0x0003;
24static constexpr uint16_t MS_OS_20_FEATURE_REG_PROPERTY = 0x0004;
27static constexpr uint16_t REG_MULTI_SZ = 0x0007;
30static constexpr uint8_t MSOS20_PLATFORM_CAPABILITY_UUID[16] = {
31 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C,
32 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F,
36static constexpr uint16_t GUID_CHARS_WITH_BRACES = 38;
37static constexpr uint16_t GUID_STR_UTF16_BYTES = (GUID_CHARS_WITH_BRACES + 1) * 2;
40static constexpr uint8_t PROP_NAME_DEVICE_INTERFACE_GUIDS_UTF16[] = {
41 'D', 0x00,
'e', 0x00,
'v', 0x00,
'i', 0x00,
'c', 0x00,
'e', 0x00,
'I', 0x00,
42 'n', 0x00,
't', 0x00,
'e', 0x00,
'r', 0x00,
'f', 0x00,
'a', 0x00,
'c', 0x00,
43 'e', 0x00,
'G', 0x00,
'U', 0x00,
'I', 0x00,
'D', 0x00,
's', 0x00, 0x00, 0x00};
44static constexpr uint16_t PROP_NAME_DEVICE_INTERFACE_GUIDS_BYTES =
45 static_cast<uint16_t
>(
sizeof(PROP_NAME_DEVICE_INTERFACE_GUIDS_UTF16));
54 uint16_t wLength = 0x000A;
55 uint16_t wDescriptorType = MS_OS_20_SET_HEADER_DESCRIPTOR;
56 uint32_t dwWindowsVersion = 0x06030000;
57 uint16_t wTotalLength = 0;
63 uint16_t wLength = 0x0008;
64 uint16_t wDescriptorType = MS_OS_20_SUBSET_HEADER_CONFIGURATION;
65 uint8_t bConfigurationValue = 0;
66 uint8_t bReserved = 0;
67 uint16_t wTotalLength = 0;
73 uint16_t wLength = 0x0008;
74 uint16_t wDescriptorType = MS_OS_20_SUBSET_HEADER_FUNCTION;
75 uint8_t bFirstInterface = 0;
76 uint8_t bReserved = 0;
77 uint16_t wTotalLength = 0;
83 uint16_t wLength = 0x0014;
84 uint16_t wDescriptorType = MS_OS_20_FEATURE_COMPATIBLE_ID;
87 uint8_t CompatibleID[8] = {
'W',
'I',
'N',
'U',
'S',
'B', 0x00, 0x00};
90 uint8_t SubCompatibleID[8] = {0};
97 uint16_t wDescriptorType = MS_OS_20_FEATURE_REG_PROPERTY;
98 uint16_t wPropertyDataType = 0;
99 uint16_t wPropertyNameLength = 0;
108 uint8_t bLength = 0x1C;
109 uint8_t bDescriptorType = 0x10;
110 uint8_t bDevCapabilityType = 0x05;
111 uint8_t bReserved = 0x00;
113 uint8_t PlatformCapabilityUUID[16] = {
114 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C,
115 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F,
118 uint32_t dwWindowsVersion = 0x06030000;
119 uint16_t wMSOSDescriptorSetTotalLength = 0;
120 uint8_t bMS_VendorCode = 0x20;
121 uint8_t bAltEnumCode = 0x00;
127static_assert(
sizeof(
MsOs20SetHeader) == 10,
"SetHeader size mismatch");
138 uint16_t msos_descriptor_set_total_length,
139 uint8_t vendor_code = 0x20,
140 uint32_t windows_version = 0x06030000)
143 Memory::FastCopy(cap.PlatformCapabilityUUID, MSOS20_PLATFORM_CAPABILITY_UUID,
144 sizeof(MSOS20_PLATFORM_CAPABILITY_UUID));
145 cap.dwWindowsVersion = windows_version;
146 cap.wMSOSDescriptorSetTotalLength = msos_descriptor_set_total_length;
147 cap.bMS_VendorCode = vendor_code;
148 cap.bAltEnumCode = 0x00;
162 uint8_t vendor_code = 0x20,
163 uint32_t windows_version = 0x06030000)
164 : descriptor_set_(descriptor_set),
165 vendor_code_(vendor_code),
166 windows_version_(windows_version)
168 RefreshPlatformCap();
173 descriptor_set_ = descriptor_set;
174 RefreshPlatformCap();
177 void SetVendorCode(uint8_t vendor_code)
179 vendor_code_ = vendor_code;
180 platform_cap_.bMS_VendorCode = vendor_code_;
191 if (setup ==
nullptr)
193 return ErrorCode::ARG_ERR;
199 if ((BM & 0x60) != 0x40)
201 return ErrorCode::NOT_SUPPORT;
205 if ((BM & 0x1F) != 0x00)
207 return ErrorCode::NOT_SUPPORT;
211 if (setup->
bRequest != vendor_code_)
213 return ErrorCode::NOT_SUPPORT;
217 if (setup->
wIndex == MSOS20_DESCRIPTOR_INDEX)
220 if ((BM & 0x80) == 0)
222 return ErrorCode::NOT_SUPPORT;
225 if (descriptor_set_.
addr_ ==
nullptr || descriptor_set_.
size_ == 0 ||
226 descriptor_set_.
size_ > 0xFFFF)
228 return ErrorCode::ARG_ERR;
234 return ErrorCode::NOT_SUPPORT;
238 result.
in_data = descriptor_set_;
241 return ErrorCode::OK;
245 if (setup->
wIndex == MSOS20_SET_ALT_ENUMERATION)
248 if ((BM & 0x80) != 0)
251 return ErrorCode::NOT_SUPPORT;
264 return ErrorCode::OK;
267 return ErrorCode::NOT_SUPPORT;
271 void RefreshPlatformCap()
276 MSOS20_PLATFORM_CAPABILITY_UUID,
277 sizeof(MSOS20_PLATFORM_CAPABILITY_UUID));
278 platform_cap_.dwWindowsVersion = windows_version_;
279 platform_cap_.bMS_VendorCode = vendor_code_;
280 platform_cap_.bAltEnumCode = 0x00;
282 if (descriptor_set_.
size_ <= 0xFFFF)
284 platform_cap_.wMSOSDescriptorSetTotalLength =
285 static_cast<uint16_t
>(descriptor_set_.
size_);
289 platform_cap_.wMSOSDescriptorSetTotalLength = 0;
297 uint8_t vendor_code_ = 0x20;
300 uint32_t windows_version_ = 0x06030000;
303 MsOs20PlatformCapability platform_cap_{};
常量原始数据封装类。 A class for encapsulating constant raw data.
size_t size_
数据大小(字节)。 The size of the data (in bytes).
const void * addr_
数据存储地址(常量)。 The storage address of the data (constant).
static void FastCopy(void *dst, const void *src, size_t size)
快速内存拷贝 / Fast memory copy
BOS 能力接口 / BOS capability interface.
ErrorCode OnVendorRequest(bool, const SetupPacket *setup, LibXR::USB::BosVendorResult &result) override
处理该能力相关 Vendor 请求 / Handle vendor request for this capability
LibXR::ConstRawData GetCapabilityDescriptor() const override
返回能力块(不含 BOS 头) Return capability block (without BOS header).
Vendor 请求处理结果(EP0 控制传输) Vendor request handling result for EP0 control transfers.
bool handled
已处理该请求 / Request consumed by capability
ConstRawData in_data
IN 数据阶段返回数据 / IN data stage payload.
bool write_zlp
状态阶段发送 ZLP / Send ZLP at status stage
bool early_read_zlp
提前准备 OUT 以适配主机短读 / Arm OUT early for short-read tolerance
USB 标准请求 SETUP 包(固定8字节) Standard USB setup packet (8 bytes)
uint16_t wIndex
对象索引,如接口号或端点号 / Index (e.g., interface or endpoint)
uint16_t wLength
数据阶段长度 / Number of bytes in data stage
uint8_t bRequest
请求码 / Request code (e.g., GET_DESCRIPTOR)