From 312429be3c0c0b0cd4316a17109005c0dbe65e9e Mon Sep 17 00:00:00 2001 From: Emil Obalski Date: Tue, 27 Oct 2020 10:38:27 +0100 Subject: [PATCH] usb: samples: Add Extension descriptor to webUSB sample. WebUSB sample is using BOS descriptor. Because of that the bcdUSB field of device descriptor is set to 0x0210. This requires for the BOS descriptor to have LPM support. LPM support use additional descriptor that the HOST can read by requesting BOS desc. The descriptor is called Extension descriptor and is specified in `USB Link Power Management ECN` document considered a part of USB 2.0 spec. This patch adds missing part of the BOS descriptor and fixes issue with webUSB sample not passing i'LPM L1 Suspend Resume Test' from USB3CV test tool. Signed-off-by: Emil Obalski --- include/usb/bos.h | 8 ++++++++ samples/subsys/usb/webusb/src/main.c | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/usb/bos.h b/include/usb/bos.h index 991a8cce717..b02104426d4 100644 --- a/include/usb/bos.h +++ b/include/usb/bos.h @@ -16,6 +16,7 @@ /* BOS descriptor type */ #define DESCRIPTOR_TYPE_BOS 0x0F +#define USB_BOS_CAPABILITY_EXTENSION 0x02 #define USB_BOS_CAPABILITY_PLATFORM 0x05 /* BOS Capability Descriptor */ @@ -50,6 +51,13 @@ struct usb_bos_capability_msos { uint8_t bAltEnumCode; } __packed; +struct usb_bos_capability_lpm { + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bDevCapabilityType; + uint32_t bmAttributes; +} __packed; + size_t usb_bos_get_length(void); void usb_bos_fix_total_length(void); void usb_bos_register_cap(struct usb_bos_platform_descriptor *hdr); diff --git a/samples/subsys/usb/webusb/src/main.c b/samples/subsys/usb/webusb/src/main.c index da55935b53a..6ca9dbb9c47 100644 --- a/samples/subsys/usb/webusb/src/main.c +++ b/samples/subsys/usb/webusb/src/main.c @@ -120,6 +120,17 @@ USB_DEVICE_BOS_DESC_DEFINE_CAP struct usb_bos_msosv2_desc { }, }; +USB_DEVICE_BOS_DESC_DEFINE_CAP struct usb_bos_capability_lpm bos_cap_lpm = { + .bLength = sizeof(struct usb_bos_capability_lpm), + .bDescriptorType = USB_DEVICE_CAPABILITY_DESC, + .bDevCapabilityType = USB_BOS_CAPABILITY_EXTENSION, + /** + * BIT(1) - LPM support + * BIT(2) - BESL support + */ + .bmAttributes = BIT(1) | BIT(2), +}; + /* WebUSB Device Requests */ static const uint8_t webusb_allowed_origins[] = { /* Allowed Origins Header: @@ -289,6 +300,7 @@ void main(void) usb_bos_register_cap((void *)&bos_cap_webusb); usb_bos_register_cap((void *)&bos_cap_msosv2); + usb_bos_register_cap((void *)&bos_cap_lpm); /* Set the custom and vendor request handlers */ webusb_register_request_handlers(&req_handlers);