@@ -533,13 +533,13 @@ static int sreq_get_desc_cfg(struct usbd_context *const uds_ctx,
533
533
return 0 ;
534
534
}
535
535
536
- #define USBD_HWID_SN_MAX 32U
536
+ #define USBD_SN_ASCII7_LENGTH (CONFIG_USBD_HWINFO_DEVID_LENGTH * 2)
537
537
538
538
/* Generate valid USB device serial number from hwid */
539
- static ssize_t get_sn_from_hwid (uint8_t sn [static USBD_HWID_SN_MAX ])
539
+ static ssize_t get_sn_from_hwid (uint8_t sn [static USBD_SN_ASCII7_LENGTH ])
540
540
{
541
541
static const char hex [] = "0123456789ABCDEF" ;
542
- uint8_t hwid [USBD_HWID_SN_MAX / 2U ];
542
+ uint8_t hwid [USBD_SN_ASCII7_LENGTH / 2U ];
543
543
ssize_t hwid_len = - ENOSYS ;
544
544
545
545
if (IS_ENABLED (CONFIG_HWINFO )) {
@@ -554,36 +554,37 @@ static ssize_t get_sn_from_hwid(uint8_t sn[static USBD_HWID_SN_MAX])
554
554
return hwid_len ;
555
555
}
556
556
557
- for (ssize_t i = 0 ; i < hwid_len ; i ++ ) {
557
+ for (ssize_t i = 0 ; i < MIN ( hwid_len , sizeof ( hwid )) ; i ++ ) {
558
558
sn [i * 2 ] = hex [hwid [i ] >> 4 ];
559
559
sn [i * 2 + 1 ] = hex [hwid [i ] & 0xF ];
560
560
}
561
561
562
- return hwid_len * 2 ;
562
+ return MIN ( hwid_len , sizeof ( hwid )) * 2 ;
563
563
}
564
564
565
565
/* Copy and convert ASCII-7 string descriptor to UTF16-LE */
566
566
static void string_ascii7_to_utf16le (struct usbd_desc_node * const dn ,
567
567
struct net_buf * const buf , const uint16_t wLength )
568
568
{
569
- uint8_t hwid_sn [ USBD_HWID_SN_MAX ];
569
+ uint8_t sn_ascii7_str [ USBD_SN_ASCII7_LENGTH ];
570
570
struct usb_desc_header head = {
571
571
.bDescriptorType = dn -> bDescriptorType ,
572
572
};
573
- uint8_t * ascii7_str ;
573
+ const uint8_t * ascii7_str ;
574
574
size_t len ;
575
575
size_t i ;
576
576
577
- if (dn -> str .utype == USBD_DUT_STRING_SERIAL_NUMBER && dn -> str .use_hwinfo ) {
578
- ssize_t hwid_len = get_sn_from_hwid (hwid_sn );
577
+ if (IS_ENABLED (CONFIG_HWINFO ) &&
578
+ dn -> str .utype == USBD_DUT_STRING_SERIAL_NUMBER && dn -> str .use_hwinfo ) {
579
+ ssize_t sn_ascii7_str_len = get_sn_from_hwid (sn_ascii7_str );
579
580
580
- if (hwid_len < 0 ) {
581
+ if (sn_ascii7_str_len < 0 ) {
581
582
errno = - ENOTSUP ;
582
583
return ;
583
584
}
584
585
585
- head .bLength = sizeof (head ) + hwid_len * 2 ;
586
- ascii7_str = hwid_sn ;
586
+ head .bLength = sizeof (head ) + sn_ascii7_str_len * 2 ;
587
+ ascii7_str = sn_ascii7_str ;
587
588
} else {
588
589
head .bLength = dn -> bLength ;
589
590
ascii7_str = (uint8_t * )dn -> ptr ;
0 commit comments