usb: derive USB device Serial Number String from HWINFO
Derive USB device Serial Number String from HWINFO driver. Signed-off-by: Johann Fischer <j.fischer@phytec.de>
This commit is contained in:
parent
93b740c464
commit
f75c30b2ed
|
@ -6,6 +6,7 @@
|
|||
menuconfig USB_DEVICE_STACK
|
||||
bool "USB device stack"
|
||||
depends on USB_DEVICE_DRIVER || ARCH_POSIX
|
||||
select HWINFO
|
||||
help
|
||||
Enable USB device stack.
|
||||
|
||||
|
@ -42,11 +43,12 @@ config USB_DEVICE_PRODUCT
|
|||
USB device Product string. MUST be configured by vendor.
|
||||
|
||||
config USB_DEVICE_SN
|
||||
string "USB serial number"
|
||||
default "ABCDEF012345" if USB_MASS_STORAGE
|
||||
default "0.01"
|
||||
string "USB device Serial Number String"
|
||||
default "0123456789ABCDEF"
|
||||
help
|
||||
USB device SerialNumber string. MUST be configured by vendor.
|
||||
Placeholder for USB device Serial Number String.
|
||||
Serial Number String will be derived from
|
||||
Hardware Information Driver (HWINFO).
|
||||
|
||||
config USB_COMPOSITE_DEVICE
|
||||
bool "Enable composite device driver"
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <usb/usb_device.h>
|
||||
#include <usb/usb_common.h>
|
||||
#include "usb_descriptor.h"
|
||||
#include <drivers/hwinfo.h>
|
||||
|
||||
#define LOG_LEVEL CONFIG_USB_DEVICE_LOG_LEVEL
|
||||
#include <logging/log.h>
|
||||
|
@ -290,16 +291,29 @@ static struct usb_cfg_data *usb_get_cfg_data(struct usb_if_descriptor *iface)
|
|||
}
|
||||
|
||||
/*
|
||||
* Default USB SN string descriptor is CONFIG_USB_DEVICE_SN, but sometimes
|
||||
* we want use another string as SN descriptor such as the chip's unique
|
||||
* ID. So user can implement this function return a string thats will be
|
||||
* replaced the default SN.
|
||||
* Please note that the new SN descriptor you changed must has same length
|
||||
* as CONFIG_USB_DEVICE_SN.
|
||||
* Default USB Serial Number string descriptor will be derived from
|
||||
* Hardware Information Driver (HWINFO). User can implement own variant
|
||||
* of this function. Please note that the length of the new Serial Number
|
||||
* descriptor may not exceed the length of the CONFIG_USB_DEVICE_SN.
|
||||
*/
|
||||
__weak u8_t *usb_update_sn_string_descriptor(void)
|
||||
{
|
||||
return NULL;
|
||||
u8_t hwid[sizeof(CONFIG_USB_DEVICE_SN) / 2];
|
||||
static u8_t sn[sizeof(CONFIG_USB_DEVICE_SN) + 1];
|
||||
const char hex[] = "0123456789ABCDEF";
|
||||
|
||||
memset(hwid, 0, sizeof(hwid));
|
||||
memset(sn, 0, sizeof(sn));
|
||||
|
||||
if (hwinfo_get_device_id(hwid, sizeof(hwid)) > 0) {
|
||||
LOG_HEXDUMP_DBG(hwid, sizeof(hwid), "Serial Number");
|
||||
for (int i = 0; i < sizeof(hwid); i++) {
|
||||
sn[i * 2] = hex[hwid[(sizeof(hwid) - 1) - i] >> 4];
|
||||
sn[i * 2 + 1] = hex[hwid[(sizeof(hwid) - 1) - i] & 0xF];
|
||||
}
|
||||
}
|
||||
|
||||
return sn;
|
||||
}
|
||||
|
||||
static void usb_fix_ascii_sn_string_descriptor(struct usb_sn_descriptor *sn)
|
||||
|
|
Loading…
Reference in a new issue