From 8f69cc974d6531a3e5a5a1e6cefde50a2694562d Mon Sep 17 00:00:00 2001 From: dragonmux Date: Thu, 11 Aug 2022 09:38:14 +0100 Subject: [PATCH] usb_standard: Added computation of the total BOS length to build_bos_descriptor --- lib/usb/usb_standard.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/usb/usb_standard.c b/lib/usb/usb_standard.c index 938c4aea..97eab616 100644 --- a/lib/usb/usb_standard.c +++ b/lib/usb/usb_standard.c @@ -171,6 +171,7 @@ static uint16_t build_bos_descriptor(usbd_device *usbd_dev, uint8_t *const buf, memcpy(buf, bos, count); len -= count; uint16_t total = count; + uint16_t total_length = bos->bLength; size_t offset = 0; for (uint8_t i = 0; i < bos->bNumDeviceCaps; ++i) { @@ -181,6 +182,7 @@ static uint16_t build_bos_descriptor(usbd_device *usbd_dev, uint8_t *const buf, switch (dev_cap->bDevCapabilityType) { case USB_DCT_PLATFORM: count = build_devcap_platform((const usb_platform_device_capability_descriptor *)dev_cap, buf + total, len); + total_length += dev_cap->bLength; offset += sizeof(usb_platform_device_capability_descriptor) + MICROSOFT_OS_DESCRIPTOR_SET_INFORMATION_SIZE; break; default: @@ -190,10 +192,9 @@ static uint16_t build_bos_descriptor(usbd_device *usbd_dev, uint8_t *const buf, return 0; len -= count; total += count; - if (!count && !len) - return 0; } + ((usb_bos_descriptor *)buf)->wTotalLength = total_length; return total; }