From f47df94dfb6dcd3b384b7dd313a3317edfc075a0 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Thu, 8 Sep 2022 10:45:25 +0200 Subject: [PATCH] Added some string descriptors. Signed-off-by: Pol Henarejos --- src/usb/hid/usb_descriptors.c | 68 +++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/usb/hid/usb_descriptors.c b/src/usb/hid/usb_descriptors.c index d49d470..2696ec2 100644 --- a/src/usb/hid/usb_descriptors.c +++ b/src/usb/hid/usb_descriptors.c @@ -25,6 +25,8 @@ #include "tusb.h" #include "u2f_hid.h" +#include "pico/unique_id.h" +#include "hsm_version.h" /* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug. * Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC. @@ -49,7 +51,7 @@ tusb_desc_device_t const desc_device = .idVendor = 0xCafe, .idProduct = 0x4231, - .bcdDevice = 0x0100, + .bcdDevice = HSM_SDK_VERSION, .iManufacturer = 0x01, .iProduct = 0x02, @@ -145,8 +147,8 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index) char const* string_desc_arr [] = { (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409) - "TinyUSB", // 1: Manufacturer - "TinyUSB Device", // 2: Product + "Pol Henarejos", // 1: Manufacturer + "Pico HSM", // 2: Product "123456", // 3: Serials, should use chip ID }; @@ -156,37 +158,41 @@ static uint16_t _desc_str[32]; // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) { - (void) langid; + (void) langid; - uint8_t chr_count; + uint8_t chr_count; - if ( index == 0) - { - memcpy(&_desc_str[1], string_desc_arr[0], 2); - chr_count = 1; - }else - { - // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors. - // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors - - if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL; - - const char* str = string_desc_arr[index]; - - // Cap at max char - chr_count = (uint8_t) strlen(str); - if ( chr_count > 31 ) chr_count = 31; - - // Convert ASCII string into UTF-16 - for(uint8_t i=0; i 31 ) + chr_count = 31; + + // Convert ASCII string into UTF-16 + for(uint8_t i=0; i