usbdev: Add board unique serial string support

iSerialNumber field in the device descriptor can be used to determining the
board when multiple boards connected to the same host. So add feature to change
serial string by board unique ID dynamically.
To use this feature, user must be implement the board_usbdev_serialstr() logic.

refs #13909
This commit is contained in:
SPRESENSE
2022-01-18 10:36:37 +09:00
committed by Alin Jerpelea
parent f2ee1c5b35
commit 021a58d71a
13 changed files with 143 additions and 2 deletions
+4
View File
@@ -3563,3 +3563,7 @@ config BOARDCTL_IOCTL
Architecture specific logic must provide board_ioctl() interface. Architecture specific logic must provide board_ioctl() interface.
endif # BOARDCTL endif # BOARDCTL
config BOARD_USBDEV_SERIALSTR
bool
default n
+52
View File
@@ -227,9 +227,17 @@ config COMPOSITE_PRODUCTSTR
---help--- ---help---
The product ID code/string The product ID code/string
config COMPOSITE_BOARD_SERIALSTR
bool "Enable board unique ID to composite serial string"
default n
select BOARD_USBDEV_SERIALSTR
---help---
Use board unique serial number to iSerialNumber in the device descriptor.
config COMPOSITE_SERIALSTR config COMPOSITE_SERIALSTR
string "Composite serial string" string "Composite serial string"
default "001" default "001"
depends on !COMPOSITE_BOARD_SERIALSTR
---help--- ---help---
Device serial number string Device serial number string
@@ -352,6 +360,13 @@ config PL2303_VENDORSTR
string "Vendor string" string "Vendor string"
default "NuttX" default "NuttX"
config PL2303_BOARD_SERIALSTR
bool "Enable board unique ID to PL2303 serial string"
default n
select BOARD_USBDEV_SERIALSTR
---help---
Use board unique serial number to iSerialNumber in the device descriptor.
config PL2303_PRODUCTSTR config PL2303_PRODUCTSTR
string "Product string" string "Product string"
default "PL2303 Emulation" default "PL2303 Emulation"
@@ -565,6 +580,13 @@ config CDCACM_PRODUCTSTR
string "Product string" string "Product string"
default "CDC/ACM Serial" default "CDC/ACM Serial"
config CDCACM_BOARD_SERIALSTR
bool "Enable board unique ID to CDC/ACM serial string"
default n
select BOARD_USBDEV_SERIALSTR
---help---
Use board unique serial number to iSerialNumber in the device descriptor.
endif # !CDCACM_COMPOSITE endif # !CDCACM_COMPOSITE
endif # CDCACM endif # CDCACM
@@ -675,9 +697,17 @@ config USBADB_PRODUCTSTR
string "Product string" string "Product string"
default "Debug Bridge" default "Debug Bridge"
config USBADB_BOARD_SERIALSTR
bool "Enable board unique ID to USBADB serial string"
default n
select BOARD_USBDEV_SERIALSTR
---help---
Use board unique serial number to iSerialNumber in the device descriptor.
config USBADB_SERIALSTR config USBADB_SERIALSTR
string "Serial string" string "Serial string"
default "1234" default "1234"
depends on !USBADB_BOARD_SERIALSTR
endif # !USBADB_COMPOSITE endif # !USBADB_COMPOSITE
@@ -824,6 +854,13 @@ config USBMSC_PRODUCTSTR
string "Mass storage product string" string "Mass storage product string"
default "Mass Storage" default "Mass Storage"
config USBMSC_BOARD_SERIALSTR
bool "Enable board unique ID to mass storage serial string"
default n
select BOARD_USBDEV_SERIALSTR
---help---
Use board unique serial number to iSerialNumber in the device descriptor.
endif # !USBMSC_COMPOSITE endif # !USBMSC_COMPOSITE
config USBMSC_VERSIONNO config USBMSC_VERSIONNO
@@ -921,9 +958,17 @@ config RNDIS_PRODUCTSTR
string "RNDIS product string" string "RNDIS product string"
default "RNDIS gadget" default "RNDIS gadget"
config RNDIS_BOARD_SERIALSTR
bool "Enable board unique ID to RNDIS serial string"
default n
select BOARD_USBDEV_SERIALSTR
---help---
Use board unique serial number to iSerialNumber in the device descriptor.
config RNDIS_SERIALSTR config RNDIS_SERIALSTR
string "RNDIS serial string" string "RNDIS serial string"
default "1234" default "1234"
depends on !RNDIS_BOARD_SERIALSTR
config RNDIS_VERSIONNO config RNDIS_VERSIONNO
hex "RNDIS Version Number" hex "RNDIS Version Number"
@@ -1137,6 +1182,13 @@ config CDCECM_PRODUCTSTR
string "Product string" string "Product string"
default "CDC/ECM Ethernet" default "CDC/ECM Ethernet"
config CDCECM_BOARD_SERIALSTR
bool "Enable board unique ID to CDC/ECM serial string"
default n
select BOARD_USBDEV_SERIALSTR
---help---
Use board unique serial number to iSerialNumber in the device descriptor.
endif # !CDCECM_COMPOSITE endif # !CDCECM_COMPOSITE
endif # CDCECM endif # CDCECM
+8
View File
@@ -40,6 +40,10 @@
#include <fcntl.h> #include <fcntl.h>
#include <poll.h> #include <poll.h>
#ifdef CONFIG_USBADB_BOARD_SERIALSTR
#include <nuttx/board.h>
#endif
#ifdef CONFIG_USBADB_COMPOSITE #ifdef CONFIG_USBADB_COMPOSITE
# include <nuttx/usb/composite.h> # include <nuttx/usb/composite.h>
# include "composite.h" # include "composite.h"
@@ -890,7 +894,11 @@ static int usbclass_mkstrdesc(uint8_t id, FAR struct usb_strdesc_s *strdesc)
break; break;
case USBADB_SERIALSTRID: case USBADB_SERIALSTRID:
#ifdef CONFIG_USBADB_BOARD_SERIALSTR
str = board_usbdev_serialstr();
#else
str = CONFIG_USBADB_SERIALSTR; str = CONFIG_USBADB_SERIALSTR;
#endif
break; break;
case USBADB_CONFIGSTRID: case USBADB_CONFIGSTRID:
+8
View File
@@ -36,6 +36,10 @@
#include <nuttx/usb/cdcacm.h> #include <nuttx/usb/cdcacm.h>
#include <nuttx/usb/usbdev_trace.h> #include <nuttx/usb/usbdev_trace.h>
#ifdef CONFIG_CDCACM_BOARD_SERIALSTR
#include <nuttx/board.h>
#endif
#include "cdcacm.h" #include "cdcacm.h"
/**************************************************************************** /****************************************************************************
@@ -144,7 +148,11 @@ int cdcacm_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
break; break;
case CDCACM_SERIALSTRID: case CDCACM_SERIALSTRID:
#ifdef CONFIG_CDCACM_BOARD_SERIALSTR
str = board_usbdev_serialstr();
#else
str = CONFIG_CDCACM_SERIALSTR; str = CONFIG_CDCACM_SERIALSTR;
#endif
break; break;
case CDCACM_CONFIGSTRID: case CDCACM_CONFIGSTRID:
+8
View File
@@ -56,6 +56,10 @@
# include <nuttx/net/pkt.h> # include <nuttx/net/pkt.h>
#endif #endif
#ifdef CONFIG_CDCECM_BOARD_SERIALSTR
#include <nuttx/board.h>
#endif
#include "cdcecm.h" #include "cdcecm.h"
#ifdef CONFIG_NET_CDCECM #ifdef CONFIG_NET_CDCECM
@@ -1389,7 +1393,11 @@ static int cdcecm_mkstrdesc(uint8_t id, FAR struct usb_strdesc_s *strdesc)
break; break;
case CDCECM_SERIALSTRID: case CDCECM_SERIALSTRID:
#ifdef CONFIG_CDCECM_BOARD_SERIALSTR
str = board_usbdev_serialstr();
#else
str = "0"; str = "0";
#endif
break; break;
case CDCECM_CONFIGSTRID: case CDCECM_CONFIGSTRID:
+2
View File
@@ -118,7 +118,9 @@ static const struct usbdevclass_driverops_s g_driverops =
const char g_compvendorstr[] = CONFIG_COMPOSITE_VENDORSTR; const char g_compvendorstr[] = CONFIG_COMPOSITE_VENDORSTR;
const char g_compproductstr[] = CONFIG_COMPOSITE_PRODUCTSTR; const char g_compproductstr[] = CONFIG_COMPOSITE_PRODUCTSTR;
#ifndef CONFIG_COMPOSITE_BOARD_SERIALSTR
const char g_compserialstr[] = CONFIG_COMPOSITE_SERIALSTR; const char g_compserialstr[] = CONFIG_COMPOSITE_SERIALSTR;
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
+8
View File
@@ -32,6 +32,10 @@
#include <assert.h> #include <assert.h>
#include <debug.h> #include <debug.h>
#ifdef CONFIG_COMPOSITE_BOARD_SERIALSTR
#include <nuttx/board.h>
#endif
#include <nuttx/usb/usbdev_trace.h> #include <nuttx/usb/usbdev_trace.h>
#include "composite.h" #include "composite.h"
@@ -143,7 +147,11 @@ int composite_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
break; break;
case COMPOSITE_SERIALSTRID: case COMPOSITE_SERIALSTRID:
#ifdef CONFIG_COMPOSITE_BOARD_SERIALSTR
str = board_usbdev_serialstr();
#else
str = g_compserialstr; str = g_compserialstr;
#endif
break; break;
case COMPOSITE_CONFIGSTRID: case COMPOSITE_CONFIGSTRID:
+8
View File
@@ -46,6 +46,10 @@
#include <nuttx/usb/usbdev.h> #include <nuttx/usb/usbdev.h>
#include <nuttx/usb/usbdev_trace.h> #include <nuttx/usb/usbdev_trace.h>
#ifdef CONFIG_PL2303_BOARD_SERIALSTR
#include <nuttx/board.h>
#endif
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
@@ -853,7 +857,11 @@ static int usbclass_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
break; break;
case PL2303_SERIALSTRID: case PL2303_SERIALSTRID:
#ifdef CONFIG_PL2303_BOARD_SERIALSTR
str = board_usbdev_serialstr();
#else
str = CONFIG_PL2303_SERIALSTR; str = CONFIG_PL2303_SERIALSTR;
#endif
break; break;
case PL2303_CONFIGSTRID: case PL2303_CONFIGSTRID:
+8
View File
@@ -49,6 +49,10 @@
#include <nuttx/wdog.h> #include <nuttx/wdog.h>
#include <nuttx/wqueue.h> #include <nuttx/wqueue.h>
#ifdef CONFIG_RNDIS_BOARD_SERIALSTR
#include <nuttx/board.h>
#endif
#include "rndis_std.h" #include "rndis_std.h"
/**************************************************************************** /****************************************************************************
@@ -1921,7 +1925,11 @@ static int usbclass_mkstrdesc(uint8_t id, FAR struct usb_strdesc_s *strdesc)
break; break;
case RNDIS_SERIALSTRID: case RNDIS_SERIALSTRID:
#ifdef CONFIG_RNDIS_BOARD_SERIALSTR
str = board_usbdev_serialstr();
#else
str = CONFIG_RNDIS_SERIALSTR; str = CONFIG_RNDIS_SERIALSTR;
#endif
break; break;
#endif #endif
+6
View File
@@ -466,7 +466,9 @@ extern "C"
#ifndef CONFIG_USBMSC_COMPOSITE #ifndef CONFIG_USBMSC_COMPOSITE
EXTERN const char g_mscvendorstr[]; EXTERN const char g_mscvendorstr[];
EXTERN const char g_mscproductstr[]; EXTERN const char g_mscproductstr[];
#ifndef CONFIG_USBMSC_BOARD_SERIALSTR
EXTERN const char g_mscserialstr[]; EXTERN const char g_mscserialstr[];
#endif
/* If we are using a composite device, then vendor/product/serial number /* If we are using a composite device, then vendor/product/serial number
* strings are provided by the composite device logic. * strings are provided by the composite device logic.
@@ -475,12 +477,16 @@ EXTERN const char g_mscserialstr[];
#else #else
EXTERN const char g_compvendorstr[]; EXTERN const char g_compvendorstr[];
EXTERN const char g_compproductstr[]; EXTERN const char g_compproductstr[];
#ifndef CONFIG_COMPOSITE_BOARD_SERIALSTR
EXTERN const char g_compserialstr[]; EXTERN const char g_compserialstr[];
#endif
#define g_mscvendorstr g_compvendorstr #define g_mscvendorstr g_compvendorstr
#define g_mscproductstr g_compproductstr #define g_mscproductstr g_compproductstr
#ifndef CONFIG_USBMSC_BOARD_SERIALSTR
#define g_mscserialstr g_compserialstr #define g_mscserialstr g_compserialstr
#endif #endif
#endif
/* Used to hand-off the state structure when the SCSI worker thread is /* Used to hand-off the state structure when the SCSI worker thread is
* started * started
+10
View File
@@ -33,6 +33,10 @@
#include <nuttx/usb/usb.h> #include <nuttx/usb/usb.h>
#include <nuttx/usb/usbdev_trace.h> #include <nuttx/usb/usbdev_trace.h>
#ifdef CONFIG_USBMSC_BOARD_SERIALSTR
#include <nuttx/board.h>
#endif
#include "usbmsc.h" #include "usbmsc.h"
/**************************************************************************** /****************************************************************************
@@ -103,8 +107,10 @@ static const struct usb_qualdesc_s g_qualdesc =
#ifndef CONFIG_USBMSC_COMPOSITE #ifndef CONFIG_USBMSC_COMPOSITE
const char g_mscvendorstr[] = CONFIG_USBMSC_VENDORSTR; const char g_mscvendorstr[] = CONFIG_USBMSC_VENDORSTR;
const char g_mscproductstr[] = CONFIG_USBMSC_PRODUCTSTR; const char g_mscproductstr[] = CONFIG_USBMSC_PRODUCTSTR;
#ifndef CONFIG_USBMSC_BOARD_SERIALSTR
const char g_mscserialstr[] = CONFIG_USBMSC_SERIALSTR; const char g_mscserialstr[] = CONFIG_USBMSC_SERIALSTR;
#endif #endif
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@@ -152,7 +158,11 @@ int usbmsc_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
break; break;
case USBMSC_SERIALSTRID: case USBMSC_SERIALSTRID:
#ifdef CONFIG_USBMSC_BOARD_SERIALSTR
str = board_usbdev_serialstr();
#else
str = g_mscserialstr; str = g_mscserialstr;
#endif
break; break;
#endif #endif
+4 -2
View File
@@ -173,6 +173,8 @@ static int usbmsc_cmdstatusstate(FAR struct usbmsc_dev_s *priv);
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static const char *g_productrevision = "0101";
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@@ -703,13 +705,13 @@ static inline int usbmsc_cmdinquiry(FAR struct usbmsc_dev_s *priv,
memcpy(response->productid, g_mscproductstr, len); memcpy(response->productid, g_mscproductstr, len);
len = strlen(g_mscserialstr); len = strlen(g_productrevision);
if (len > 4) if (len > 4)
{ {
len = 4; len = 4;
} }
memcpy(response->revision, g_mscserialstr, len); memcpy(response->revision, g_productrevision, len);
} }
} }
+17
View File
@@ -429,6 +429,23 @@ int board_composite_initialize(int port);
FAR void *board_composite_connect(int port, int configid); FAR void *board_composite_connect(int port, int configid);
#endif #endif
/****************************************************************************
* Name: board_usbdev_serialstr
*
* Description:
* Use board unique serial number string to iSerialNumber field in the
* device descriptor. This is for determining the board when multiple
* boards on the same host.
*
* Returned Value:
* The board unique serial number string.
*
****************************************************************************/
#if defined(CONFIG_BOARD_USBDEV_SERIALSTR)
FAR const char *board_usbdev_serialstr(void);
#endif
/**************************************************************************** /****************************************************************************
* Name: board_graphics_setup * Name: board_graphics_setup
* *