From 20f2b3b74b4b86eaf32b12aee8cf093a0c9263fc Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Mon, 26 Jan 2026 01:19:56 +0100 Subject: [PATCH] Fix interface strings when are not all enabled. Signed-off-by: Pol Henarejos --- src/usb/usb.c | 8 +++++++- src/usb/usb_descriptors.c | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/usb/usb.c b/src/usb/usb.c index e040e8b..35e8da1 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -74,7 +74,9 @@ queue_t card_to_usb_q = {0}; #ifndef ENABLE_EMULATION extern tusb_desc_device_t desc_device; #endif -void usb_init() { +extern char *string_desc_itf[4], *string_desc_arr[]; +void usb_init() +{ #ifndef ENABLE_EMULATION if (phy_data.vidpid_present) { desc_device.idVendor = phy_data.vid; @@ -108,20 +110,24 @@ void usb_init() { if (enabled_usb_itf & PHY_USB_ITF_HID) { ITF_HID_CTAP = ITF_HID_TOTAL++; ITF_HID = ITF_TOTAL++; + string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[5]; } if (enabled_usb_itf & PHY_USB_ITF_KB) { ITF_HID_KB = ITF_HID_TOTAL++; ITF_KEYBOARD = ITF_TOTAL++; + string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[6]; } #endif #ifdef USB_ITF_CCID if (enabled_usb_itf & PHY_USB_ITF_CCID) { ITF_SC_CCID = ITF_SC_TOTAL++; ITF_CCID = ITF_TOTAL++; + string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[7]; } if (enabled_usb_itf & PHY_USB_ITF_WCID) { ITF_SC_WCID = ITF_SC_TOTAL++; ITF_WCID = ITF_TOTAL++; + string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[8]; } #endif card_locked_itf = ITF_TOTAL; diff --git a/src/usb/usb_descriptors.c b/src/usb/usb_descriptors.c index bbf62d9..3657b52 100644 --- a/src/usb/usb_descriptors.c +++ b/src/usb/usb_descriptors.c @@ -316,6 +316,7 @@ uint8_t const *tud_descriptor_bos_cb(void) { //--------------------------------------------------------------------+ // array of pointer to string descriptors +char *string_desc_itf[4] = {0}; char const *string_desc_arr [] = { (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409) "Pol Henarejos", // 1: Manufacturer @@ -369,6 +370,9 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) { str = phy_data.usb_product; } } + else if (index >= 5 && string_desc_itf[index - 5] != NULL) { + str = string_desc_itf[index - 5]; + } uint8_t buff_avail = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; if (index >= 4) {