|
|
|
@ -178,6 +178,9 @@ static USBDescriptor vcom_strings[] = {
@@ -178,6 +178,9 @@ static USBDescriptor vcom_strings[] = {
|
|
|
|
|
{0, NULL}, // version
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#define USB_DESC_MAX_STRLEN 100 |
|
|
|
|
static uint8_t vcom_buffers[3][2+2*USB_DESC_MAX_STRLEN]; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
check if one string contains another |
|
|
|
|
*/ |
|
|
|
@ -196,7 +199,7 @@ static bool string_contains(const char *haystack, const char *needle)
@@ -196,7 +199,7 @@ static bool string_contains(const char *haystack, const char *needle)
|
|
|
|
|
/*
|
|
|
|
|
handle substitution of variables in strings for USB descriptors |
|
|
|
|
*/ |
|
|
|
|
static char *string_substitute(const char *str) |
|
|
|
|
static void string_substitute(const char *str, char *str2) |
|
|
|
|
{ |
|
|
|
|
uint8_t new_len = strlen(str); |
|
|
|
|
if (string_contains(str, "%BOARD%")) { |
|
|
|
@ -205,7 +208,10 @@ static char *string_substitute(const char *str)
@@ -205,7 +208,10 @@ static char *string_substitute(const char *str)
|
|
|
|
|
if (string_contains(str, "%SERIAL%")) { |
|
|
|
|
new_len += 24 - 8; |
|
|
|
|
} |
|
|
|
|
char *str2 = malloc(new_len+1); |
|
|
|
|
if (new_len+1 > USB_DESC_MAX_STRLEN) { |
|
|
|
|
strcpy(str2, str); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
char *p = str2; |
|
|
|
|
while (*str) { |
|
|
|
|
char c = *str; |
|
|
|
@ -231,19 +237,18 @@ static char *string_substitute(const char *str)
@@ -231,19 +237,18 @@ static char *string_substitute(const char *str)
|
|
|
|
|
*p++ = *str++; |
|
|
|
|
} |
|
|
|
|
*p = 0; |
|
|
|
|
return str2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
dynamically allocate a USB descriptor string |
|
|
|
|
*/ |
|
|
|
|
static void setup_usb_string(USBDescriptor *desc, const char *str) |
|
|
|
|
static void setup_usb_string(USBDescriptor *desc, const char *str, uint8_t *b) |
|
|
|
|
{ |
|
|
|
|
char *str2 = string_substitute(str); |
|
|
|
|
char str2[USB_DESC_MAX_STRLEN]; |
|
|
|
|
string_substitute(str, str2); |
|
|
|
|
uint8_t len = strlen(str2); |
|
|
|
|
desc->ud_size = 2+2*len; |
|
|
|
|
uint8_t *b = (uint8_t *)calloc(1, desc->ud_size); |
|
|
|
|
desc->ud_string = (const uint8_t *)b; |
|
|
|
|
b[0] = USB_DESC_BYTE(desc->ud_size); |
|
|
|
|
b[1] = USB_DESC_BYTE(USB_DESCRIPTOR_STRING); |
|
|
|
@ -252,9 +257,6 @@ static void setup_usb_string(USBDescriptor *desc, const char *str)
@@ -252,9 +257,6 @@ static void setup_usb_string(USBDescriptor *desc, const char *str)
|
|
|
|
|
b[2+i*2] = str2[i]; |
|
|
|
|
b[2+i*2+1] = 0; |
|
|
|
|
} |
|
|
|
|
if (str2 != str) { |
|
|
|
|
free(str2); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -262,9 +264,9 @@ static void setup_usb_string(USBDescriptor *desc, const char *str)
@@ -262,9 +264,9 @@ static void setup_usb_string(USBDescriptor *desc, const char *str)
|
|
|
|
|
*/ |
|
|
|
|
void setup_usb_strings(void) |
|
|
|
|
{ |
|
|
|
|
setup_usb_string(&vcom_strings[1], HAL_USB_STRING_MANUFACTURER); |
|
|
|
|
setup_usb_string(&vcom_strings[2], HAL_USB_STRING_PRODUCT); |
|
|
|
|
setup_usb_string(&vcom_strings[3], HAL_USB_STRING_SERIAL); |
|
|
|
|
setup_usb_string(&vcom_strings[1], HAL_USB_STRING_MANUFACTURER, vcom_buffers[0]); |
|
|
|
|
setup_usb_string(&vcom_strings[2], HAL_USB_STRING_PRODUCT, vcom_buffers[1]); |
|
|
|
|
setup_usb_string(&vcom_strings[3], HAL_USB_STRING_SERIAL, vcom_buffers[2]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|