From b7ddb7c7c077a0ca8eb095f4df2c066eb29c2b43 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Thu, 11 Aug 2022 07:52:43 +0100 Subject: [PATCH] usb: Implemented support for sending the Microsoft OS-specific descriptor component of a platform capability descriptor --- include/libopencm3/usb/bos.h | 4 ++++ include/libopencm3/usb/microsoft.h | 11 +++++++++++ lib/usb/usb_standard.c | 12 +++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/libopencm3/usb/bos.h b/include/libopencm3/usb/bos.h index b128f9f1..4e5325e6 100644 --- a/include/libopencm3/usb/bos.h +++ b/include/libopencm3/usb/bos.h @@ -87,6 +87,8 @@ typedef struct __attribute__((packed)) usb_bos_uuid { uint8_t e[6]; } usb_bos_uuid; +#define USB_BOS_UUID_SIZE sizeof(usb_bos_uuid) + typedef struct usb_device_capability_descriptor { uint8_t bLength; uint8_t bDescriptorType; @@ -125,6 +127,8 @@ typedef struct __attribute__((packed)) usb_platform_device_capability_descriptor usb_bos_uuid PlatformCapabilityUUID; /* Descriptor ends here. The following are used internally: */ + /* This is a type-erased struct of the platform-specific capability data */ + const void *CapabilityData; } usb_platform_device_capability_descriptor; #define USB_DCT_PLATFORM_SIZE 20U diff --git a/include/libopencm3/usb/microsoft.h b/include/libopencm3/usb/microsoft.h index d81879ed..15cc072a 100644 --- a/include/libopencm3/usb/microsoft.h +++ b/include/libopencm3/usb/microsoft.h @@ -76,6 +76,17 @@ enum microsoft_registry_types { {0x65U, 0x9dU, 0x9eU, 0x64U, 0x8aU, 0x9fU}, \ } +#define MICROSOFT_WINDOWS_VERSION_WINBLUE 0x06030000 + +typedef struct microsoft_os_descriptor_set_information { + uint32_t dwWindowsVersion; + uint16_t wMSOSDescriptorSetTotalLength; + uint8_t bMS_VendorCode; + uint8_t bAltEnumCode; +} microsoft_os_descriptor_set_information; + +#define MICROSOFT_OS_DESCRIPTOR_SET_INFORMATION_SIZE sizeof(microsoft_os_descriptor_set_information) + #endif /**@}*/ diff --git a/lib/usb/usb_standard.c b/lib/usb/usb_standard.c index b252b3c3..938c4aea 100644 --- a/lib/usb/usb_standard.c +++ b/lib/usb/usb_standard.c @@ -38,8 +38,12 @@ LGPL License Terms @ref lgpl_license #include #include #include +#include #include "usb_private.h" +static const usb_bos_uuid microsoft_os_descriptor_platform_capability_id = + MICROSOFT_OS_DESCRIPTOR_PLATFORM_CAPABILITY_ID; + int usbd_register_set_config_callback(usbd_device *usbd_dev, usbd_set_config_callback callback) { @@ -149,8 +153,14 @@ static uint16_t build_devcap_platform(const usb_platform_device_capability_descr len -= count; const uint16_t total = count; + if (!memcmp(&plat->PlatformCapabilityUUID, µsoft_os_descriptor_platform_capability_id, USB_BOS_UUID_SIZE)) { + const microsoft_os_descriptor_set_information *info = plat->CapabilityData; + count = MIN(len, MICROSOFT_OS_DESCRIPTOR_SET_INFORMATION_SIZE); + memcpy(buf + total, info, count); + return total + count; + } - return total; + return 0; } /* This can return 0 to indicate an error in the descriptor */