From 262be103e0478fc70fcc4e392c5ad1ad60bc074b Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 23 Jul 2018 16:12:14 +0700 Subject: add descriptor string count for tud_desc_set_t --- src/device/usbd.c | 18 +++++++++++------- src/device/usbd.h | 8 +++++--- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/device') diff --git a/src/device/usbd.c b/src/device/usbd.c index 0319ec8fd..7ae2f44c5 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -315,7 +315,7 @@ static void usbd_reset(uint8_t rhport) extern tusb_desc_device_t const _desc_auto_device; extern uint8_t const * const _desc_auto_config; - tud_desc_set.device = &_desc_auto_device; + tud_desc_set.device = (uint8_t const*) &_desc_auto_device; tud_desc_set.config = _desc_auto_config; #if CFG_TUD_HID_BOOT_PROTOCOL @@ -509,13 +509,17 @@ static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * co break; case TUSB_DESC_STRING: - // windows sometimes ask for string at index 238 !!! - if ( !(desc_index < 100) ) return 0; - - desc_data = tud_desc_set.string_arr[desc_index]; - VERIFY( desc_data != NULL, 0 ); + if ( desc_index < tud_desc_set.string_count ) + { + desc_data = tud_desc_set.string_arr[desc_index]; + VERIFY( desc_data != NULL, 0 ); - len = desc_data[0]; // first byte of descriptor is its size + len = desc_data[0]; // first byte of descriptor is its size + }else + { + // out of range + return 0; + } break; case TUSB_DESC_DEVICE_QUALIFIER: diff --git a/src/device/usbd.h b/src/device/usbd.h index c2b05f8ff..8413aa15e 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -59,9 +59,11 @@ /// \brief Descriptor pointer collector to all the needed. typedef struct { - void const * device; ///< pointer to device descriptor \ref tusb_desc_device_t - uint8_t const * config; ///< pointer to the whole configuration descriptor, starting by \ref tusb_desc_configuration_t - uint8_t const** string_arr; ///< a array of pointers to string descriptors + uint8_t const * device; ///< pointer to device descriptor \ref tusb_desc_device_t + uint8_t const * config; ///< pointer to the whole configuration descriptor, starting by \ref tusb_desc_configuration_t + + uint8_t const** string_arr; ///< a array of pointers to string descriptors + uint16_t string_count; struct { uint8_t const* composite; -- cgit v1.3.1