usb: Allow registration of a single non-contiguous string descriptor for WinUSB

Classic WinUSB support is detected by probing for a string descriptor
at index 0xEE with a special string.
usbd_register_extra_string() allows registration of a string at this
index without having to provide 237 other string descriptors

Originally filed as https://github.com/libopencm3/libopencm3/pull/849

WCID reference: https://github.com/pbatard/libwdi/wiki/WCID-Devices
This commit is contained in:
Devan Lai
2020-10-17 17:12:20 +00:00
committed by Karl Palsson
parent ffe8ddfca2
commit c13c2b3b3c
4 changed files with 38 additions and 1 deletions

View File

@@ -179,7 +179,21 @@ usb_standard_get_descriptor(usbd_device *usbd_dev,
sizeof(sd->wData[0]);
*len = MIN(*len, sd->bLength);
} else {
} else if (descr_idx == usbd_dev->extra_string_idx) {
/* This string is returned as UTF16, hence the
* multiplication
*/
sd->bLength = strlen(usbd_dev->extra_string) * 2 +
sizeof(sd->bLength) +
sizeof(sd->bDescriptorType);
*len = MIN(*len, sd->bLength);
for (i = 0; i < (*len / 2) - 1; i++) {
sd->wData[i] =
usbd_dev->extra_string[i];
}
} else {
array_idx = descr_idx - 1;
if (!usbd_dev->strings) {