update(demo): add more descriptor init macros

Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
sakumisu
2025-12-03 17:40:37 +08:00
parent 006123c296
commit a20f53c6de
17 changed files with 829 additions and 1355 deletions

View File

@@ -556,7 +556,7 @@ struct usb_bos_header_descriptor {
} __PACKED;
/* BOS Capability platform Descriptor */
struct usb_bos_capability_platform_descriptor {
struct usb_bos_capability_platform_common_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDevCapabilityType;
@@ -564,16 +564,26 @@ struct usb_bos_capability_platform_descriptor {
uint8_t PlatformCapabilityUUID[16];
} __PACKED;
/* BOS Capability MS OS Descriptors version 2 */
struct usb_bos_capability_msosv2_descriptor {
/* Microsoft OS 2.0 Platform Capability Descriptor
* See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/
* microsoft-defined-usb-descriptors
* Adapted from the source:
* https://github.com/sowbug/weblight/blob/master/firmware/webusb.c
* (BSD-2) Thanks http://janaxelson.com/files/ms_os_20_descriptors.c
*/
struct usb_bos_capability_platform_winusb_descriptor {
struct usb_bos_capability_platform_common_descriptor common;
uint32_t dwWindowsVersion;
uint16_t wMSOSDescriptorSetTotalLength;
uint8_t bVendorCode;
uint8_t bAltEnumCode;
} __PACKED;
/* BOS Capability webusb */
struct usb_bos_capability_webusb_descriptor {
/* WebUSB Platform Capability Descriptor:
* https://wicg.github.io/webusb/#webusb-platform-capability-descriptor
*/
struct usb_bos_capability_platform_webusb_descriptor {
struct usb_bos_capability_platform_common_descriptor common;
uint16_t bcdVersion;
uint8_t bVendorCode;
uint8_t iLandingPage;
@@ -587,26 +597,6 @@ struct usb_bos_capability_extension_descriptor {
uint32_t bmAttributes;
} __PACKED;
/* Microsoft OS 2.0 Platform Capability Descriptor
* See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/
* microsoft-defined-usb-descriptors
* Adapted from the source:
* https://github.com/sowbug/weblight/blob/master/firmware/webusb.c
* (BSD-2) Thanks http://janaxelson.com/files/ms_os_20_descriptors.c
*/
struct usb_bos_capability_platform_msosv2_descriptor {
struct usb_bos_capability_platform_descriptor platform_msos;
struct usb_bos_capability_msosv2_descriptor data_msosv2;
} __PACKED;
/* WebUSB Platform Capability Descriptor:
* https://wicg.github.io/webusb/#webusb-platform-capability-descriptor
*/
struct usb_bos_capability_platform_webusb_descriptor {
struct usb_bos_capability_platform_descriptor platform_webusb;
struct usb_bos_capability_webusb_descriptor data_webusb;
} __PACKED;
struct usb_webusb_url_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
@@ -625,18 +615,12 @@ struct usb_bos_descriptor {
uint32_t string_len;
};
/* USB Device Capability Descriptor */
struct usb_device_capability_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDevCapabilityType;
} __PACKED;
/** USB descriptor header */
struct usb_desc_header {
uint8_t bLength; /**< descriptor length */
uint8_t bDescriptorType; /**< descriptor type */
};
// clang-format off
#define USB_DEVICE_DESCRIPTOR_INIT(bcdUSB, bDeviceClass, bDeviceSubClass, bDeviceProtocol, idVendor, idProduct, bcdDevice, bNumConfigurations) \
0x12, /* bLength */ \
@@ -705,7 +689,7 @@ struct usb_desc_header {
WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \
bInterval /* bInterval */
#define USB_IAD_INIT(bFirstInterface, bInterfaceCount, bFunctionClass, bFunctionSubClass, bFunctionProtocol) \
#define USB_IAD_DESCRIPTOR_INIT(bFirstInterface, bInterfaceCount, bFunctionClass, bFunctionSubClass, bFunctionProtocol) \
0x08, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
bFirstInterface, /* bFirstInterface */ \
@@ -716,9 +700,144 @@ struct usb_desc_header {
0x00 /* iFunction */
#define USB_LANGID_INIT(id) \
0x04, /* bLength */ \
0x04, /* bLength */ \
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ \
WBVAL(id) /* wLangID0 */
#define USB_BOS_HEADER_DESCRIPTOR_INIT(wTotalLength, bNumDeviceCaps) \
0x05, /* bLength */ \
USB_DESCRIPTOR_TYPE_BINARY_OBJECT_STORE, /* bDescriptorType */\
WBVAL(wTotalLength), /* wTotalLength */ \
bNumDeviceCaps /* bNumDeviceCaps */
#define USB_BOS_CAP_PLATFORM_WEBUSB_DESCRIPTOR_INIT(bVendorCode, iLandingPage) \
0x18, /* bLength */ \
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, /* bDescriptorType */ \
USB_DEVICE_CAPABILITY_PLATFORM, /* bDevCapabilityType */ \
0x00, /* bReserved */ \
0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47, /* PlatformCapabilityUUID */ \
0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65, \
WBVAL(0x0100), /* bcdVersion */ \
bVendorCode, /* bVendorCode */ \
iLandingPage /* iLandingPage */
#define USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_INIT(bVendorCode, wMSOSDescriptorSetTotalLength) \
0x1C, /* bLength */ \
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, /* bDescriptorType */ \
USB_DEVICE_CAPABILITY_PLATFORM, /* bDevCapabilityType */ \
0x00, /* bReserved */ \
0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, /* PlatformCapabilityUUID */ \
0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F, \
DBVAL(0x06030000), /* dwWindowsVersion */ \
WBVAL(wMSOSDescriptorSetTotalLength), /* wMSOSDescriptorSetTotalLength */ \
bVendorCode, /* bVendorCode */ \
0x00 /* bAltEnumCode */
#define USB_BOS_CAP_PLATFORM_WEBUSB_DESCRIPTOR_LEN 24
#define USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_LEN 28
#define USB_MSOSV1_STRING_DESCRIPTOR_INIT(vendor_code) \
0x12, /* bLength */ \
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ \
'M', 0, /* bString[0] */ \
'S', 0, /* bString[1] */ \
'F', 0, /* bString[2] */ \
'T', 0, /* bString[3] */ \
'1', 0, /* bString[4] */ \
'0', 0, /* bString[5] */ \
vendor_code, /* bMS_VendorCode */ \
0x00 /* bPad */
#define USB_MSOSV1_COMP_ID_HEADER_DESCRIPTOR_INIT(bCount) \
DBVAL((sizeof(struct usb_msosv1_compat_id_header_descriptor) + sizeof(struct usb_msosv1_comp_id_function_descriptor) * bCount)), /* dwLength */ \
WBVAL(0x0100), /* bcdVersion */ \
WBVAL(0x0004), /* wIndex */ \
bCount, /* bCount */ \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved[7] */
#define USB_MSOSV1_COMP_ID_FUNCTION_WINUSB_DESCRIPTOR_INIT(bFirstInterfaceNumber) \
bFirstInterfaceNumber, /* bFirstInterfaceNumber */\
0x01, /* reserved1 */ \
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, /* compatibleID[8] */ \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* subCompatibleID[8] */ \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved2[6] */
#define USB_MSOSV1_COMP_ID_FUNCTION_MTP_DESCRIPTOR_INIT(bFirstInterfaceNumber)\
bFirstInterfaceNumber, /* bFirstInterfaceNumber */\
0x01, /* reserved1 */ \
'M', 'T', 'P', 'U', 'S', 'B', 0x00, 0x00, /* compatibleID[8] */ \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* subCompatibleID[8] */ \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved2[6] */
#define USB_MSOSV1_COMP_ID_FUNCTION_ADB_DESCRIPTOR_INIT(bFirstInterfaceNumber)\
bFirstInterfaceNumber, * bFirstInterfaceNumber */\
0x01, /* reserved1 */ \
'A', 'D', 'B', 0x00, 0x00, 0x00, 0x00, 0x00, /* compatibleID[8] */ \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* subCompatibleID[8] */ \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved2[6] */
#define USB_MSOSV1_COMP_ID_DESCRIPTOR_LEN(bCount) \
(sizeof(struct usb_msosv1_compat_id_header_descriptor) + sizeof(struct usb_msosv1_comp_id_function_descriptor) * (bCount))
#define USB_MSOSV2_COMP_ID_SET_HEADER_DESCRIPTOR_INIT(wDescriptorSetTotalLength) \
WBVAL(WINUSB_DESCRIPTOR_SET_HEADER_SIZE), /* wLength */ \
WBVAL(WINUSB_SET_HEADER_DESCRIPTOR_TYPE), /* wDescriptorType */ \
DBVAL(0x06030000), /* dwWindowsVersion */ \
WBVAL(wDescriptorSetTotalLength) /* wDescriptorSetTotalLength */
#define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_SINGLE_DESCRIPTOR_INIT() \
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_SIZE), /* wLength */ \
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_TYPE), /* wDescriptorType */ \
'W', 'I', 'N', 'U', 'S', 'B', 0, 0, /* CompatibleId*/ \
0, 0, 0, 0, 0, 0, 0, 0, /* SubCompatibleId*/ \
WBVAL(132), /* wLength */ \
WBVAL(WINUSB_FEATURE_REG_PROPERTY_TYPE), /* wDescriptorType */ \
WBVAL(WINUSB_PROP_DATA_TYPE_REG_SZ), /* wPropertyDataType */ \
WBVAL(42), /* wPropertyNameLength bPropertyName: "DeviceInterfaceGUID" */ \
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, \
'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, \
'G', 0, 'U', 0, 'I', 0, 'D', 0, 's', 0, 0, 0, \
WBVAL(80), /* wPropertyDataLength */ \
'{', 0, \
'C', 0, 'D', 0, 'B', 0, '3', 0, 'B', 0, '5', 0, 'A', 0, 'D', 0, '-', 0, \
'2', 0, '9', 0, '3', 0, 'B', 0, '-', 0, \
'4', 0, '6', 0, '6', 0, '3', 0, '-', 0, \
'A', 0, 'A', 0, '3', 0, '6', 0, '-', \
0, '1', 0, 'A', 0, 'A', 0, 'E', 0, '4', 0, '6', 0, '4', 0, '6', 0, '3', 0, '7', 0, '7', 0, '6', 0, \
'}', 0, 0, 0, 0, 0
#define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_SINGLE_DESCRIPTOR_LEN \
(WINUSB_FEATURE_COMPATIBLE_ID_SIZE + 132)
#define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_INIT(bFirstInterfaceNumber) \
WBVAL(WINUSB_FUNCTION_SUBSET_HEADER_SIZE), /* wLength */ \
WBVAL(WINUSB_SUBSET_HEADER_FUNCTION_TYPE), /* wDescriptorType */ \
bFirstInterfaceNumber, /* bFirstInterface*/ \
0, /* bReserved */ \
WBVAL((WINUSB_FUNCTION_SUBSET_HEADER_SIZE + WINUSB_FEATURE_COMPATIBLE_ID_SIZE + 132)), /* wSubsetLength */\
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_SIZE), /* wLength */ \
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_TYPE), /* wDescriptorType */ \
'W', 'I', 'N', 'U', 'S', 'B', 0, 0, /* CompatibleId*/ \
0, 0, 0, 0, 0, 0, 0, 0, /* SubCompatibleId*/ \
WBVAL(132), /* wLength */ \
WBVAL(WINUSB_FEATURE_REG_PROPERTY_TYPE), /* wDescriptorType */ \
WBVAL(WINUSB_PROP_DATA_TYPE_REG_MULTI_SZ), /* wPropertyDataType */ \
WBVAL(42), /* wPropertyNameLength bPropertyName: "DeviceInterfaceGUID" */ \
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, \
'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, \
'G', 0, 'U', 0, 'I', 0, 'D', 0, 's', 0, 0, 0, \
WBVAL(80), /* wPropertyDataLength */ \
'{', 0, \
'C', 0, 'D', 0, 'B', 0, '3', 0, 'B', 0, '5', 0, 'A', 0, 'D', 0, '-', 0, \
'2', 0, '9', 0, '3', 0, 'B', 0, '-', 0, \
'4', 0, '6', 0, '6', 0, '3', 0, '-', 0, \
'A', 0, 'A', 0, '3', 0, '6', 0, '-', \
0, '1', 0, 'A', 0, 'A', 0, 'E', 0, '4', 0, '6', 0, '4', 0, '6', 0, '3', 0, '7', 0, '7', 0, '6', 0, \
'}', 0, 0, 0, 0, 0
#define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_LEN \
(WINUSB_FUNCTION_SUBSET_HEADER_SIZE + WINUSB_FEATURE_COMPATIBLE_ID_SIZE + 132)
// clang-format on
#endif /* USB_DEF_H */