6#include "libxr_mem.hpp"
7#include "libxr_type.hpp"
8#include "usb/core/bos.hpp"
9#include "usb/core/core.hpp"
11namespace LibXR::USB::WinUsbMsOs20
17static constexpr uint16_t MSOS20_DESCRIPTOR_INDEX = 0x0007;
18static constexpr uint16_t MSOS20_SET_ALT_ENUMERATION = 0x0008;
21static constexpr uint16_t MS_OS_20_SET_HEADER_DESCRIPTOR = 0x0000;
22static constexpr uint16_t MS_OS_20_SUBSET_HEADER_CONFIGURATION = 0x0001;
23static constexpr uint16_t MS_OS_20_SUBSET_HEADER_FUNCTION = 0x0002;
24static constexpr uint16_t MS_OS_20_FEATURE_COMPATIBLE_ID = 0x0003;
25static constexpr uint16_t MS_OS_20_FEATURE_REG_PROPERTY = 0x0004;
28static constexpr uint16_t REG_MULTI_SZ = 0x0007;
31static constexpr uint8_t MSOS20_PLATFORM_CAPABILITY_UUID[16] = {
32 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C,
33 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F,
37static constexpr uint16_t GUID_CHARS_WITH_BRACES = 38;
38static constexpr uint16_t GUID_STR_UTF16_BYTES = (GUID_CHARS_WITH_BRACES + 1) * 2;
41static constexpr uint8_t PROP_NAME_DEVICE_INTERFACE_GUIDS_UTF16[] = {
42 'D', 0x00,
'e', 0x00,
'v', 0x00,
'i', 0x00,
'c', 0x00,
'e', 0x00,
'I', 0x00,
43 'n', 0x00,
't', 0x00,
'e', 0x00,
'r', 0x00,
'f', 0x00,
'a', 0x00,
'c', 0x00,
44 'e', 0x00,
'G', 0x00,
'U', 0x00,
'I', 0x00,
'D', 0x00,
's', 0x00, 0x00, 0x00};
45static constexpr uint16_t PROP_NAME_DEVICE_INTERFACE_GUIDS_BYTES =
46 static_cast<uint16_t
>(
sizeof(PROP_NAME_DEVICE_INTERFACE_GUIDS_UTF16));
55 uint16_t wLength = 0x000A;
56 uint16_t wDescriptorType = MS_OS_20_SET_HEADER_DESCRIPTOR;
57 uint32_t dwWindowsVersion = 0x06030000;
58 uint16_t wTotalLength = 0;
64 uint16_t wLength = 0x0008;
65 uint16_t wDescriptorType = MS_OS_20_SUBSET_HEADER_CONFIGURATION;
66 uint8_t bConfigurationValue = 0;
67 uint8_t bReserved = 0;
68 uint16_t wTotalLength = 0;
74 uint16_t wLength = 0x0008;
75 uint16_t wDescriptorType = MS_OS_20_SUBSET_HEADER_FUNCTION;
76 uint8_t bFirstInterface = 0;
77 uint8_t bReserved = 0;
78 uint16_t wTotalLength = 0;
84 uint16_t wLength = 0x0014;
85 uint16_t wDescriptorType = MS_OS_20_FEATURE_COMPATIBLE_ID;
88 uint8_t CompatibleID[8] = {
'W',
'I',
'N',
'U',
'S',
'B', 0x00, 0x00};
91 uint8_t SubCompatibleID[8] = {0};
98 uint16_t wDescriptorType = MS_OS_20_FEATURE_REG_PROPERTY;
99 uint16_t wPropertyDataType = 0;
100 uint16_t wPropertyNameLength = 0;
109 uint8_t bLength = 0x1C;
110 uint8_t bDescriptorType = 0x10;
111 uint8_t bDevCapabilityType = 0x05;
112 uint8_t bReserved = 0x00;
114 uint8_t PlatformCapabilityUUID[16] = {
115 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C,
116 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F,
119 uint32_t dwWindowsVersion = 0x06030000;
120 uint16_t wMSOSDescriptorSetTotalLength = 0;
121 uint8_t bMS_VendorCode = 0x20;
122 uint8_t bAltEnumCode = 0x00;
128static_assert(
sizeof(
MsOs20SetHeader) == 10,
"SetHeader size mismatch");
139 uint16_t msos_descriptor_set_total_length,
140 uint8_t vendor_code = 0x20,
141 uint32_t windows_version = 0x06030000)
144 Memory::FastCopy(cap.PlatformCapabilityUUID, MSOS20_PLATFORM_CAPABILITY_UUID,
145 sizeof(MSOS20_PLATFORM_CAPABILITY_UUID));
146 cap.dwWindowsVersion = windows_version;
147 cap.wMSOSDescriptorSetTotalLength = msos_descriptor_set_total_length;
148 cap.bMS_VendorCode = vendor_code;
149 cap.bAltEnumCode = 0x00;
163 uint8_t vendor_code = 0x20,
164 uint32_t windows_version = 0x06030000)
165 : descriptor_set_(descriptor_set),
166 vendor_code_(vendor_code),
167 windows_version_(windows_version)
169 RefreshPlatformCap();
174 descriptor_set_ = descriptor_set;
175 RefreshPlatformCap();
178 void SetVendorCode(uint8_t vendor_code)
180 vendor_code_ = vendor_code;
181 platform_cap_.bMS_VendorCode = vendor_code_;
192 if (setup ==
nullptr)
200 if ((BM & 0x60) != 0x40)
206 if ((BM & 0x1F) != 0x00)
212 if (setup->
bRequest != vendor_code_)
218 if (setup->
wIndex == MSOS20_DESCRIPTOR_INDEX)
221 if ((BM & 0x80) == 0)
226 if (descriptor_set_.
addr_ ==
nullptr || descriptor_set_.
size_ == 0 ||
227 descriptor_set_.
size_ > 0xFFFF)
239 result.
in_data = descriptor_set_;
246 if (setup->
wIndex == MSOS20_SET_ALT_ENUMERATION)
249 if ((BM & 0x80) != 0)
272 void RefreshPlatformCap()
277 MSOS20_PLATFORM_CAPABILITY_UUID,
278 sizeof(MSOS20_PLATFORM_CAPABILITY_UUID));
279 platform_cap_.dwWindowsVersion = windows_version_;
280 platform_cap_.bMS_VendorCode = vendor_code_;
281 platform_cap_.bAltEnumCode = 0x00;
283 if (descriptor_set_.
size_ <= 0xFFFF)
285 platform_cap_.wMSOSDescriptorSetTotalLength =
286 static_cast<uint16_t
>(descriptor_set_.
size_);
290 platform_cap_.wMSOSDescriptorSetTotalLength = 0;
298 uint8_t vendor_code_ = 0x20;
301 uint32_t windows_version_ = 0x06030000;
304 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).
@ NOT_SUPPORT
不支持 | Not supported
@ OK
操作成功 | Operation successful
@ ARG_ERR
参数错误 | Argument error
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)