Skip to content

Commit c3300b1

Browse files
authored
Adding support for OEM SKU and Serial Numbers (#3030)
1 parent 8f13c66 commit c3300b1

12 files changed

+160
-8
lines changed

src/HAL/Include/nanoHAL_ConfigurationManager.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) .NET Foundation and Contributors
33
// See LICENSE file in the project root for full license information.
44
//
@@ -218,6 +218,18 @@ extern "C"
218218
// gets the HAL_Configuration_NetworkInterface configuration block that has the SpecificConfig Id, if that exists
219219
int32_t ConfigurationManager_FindNetworkConfigurationMatchingWirelessConfigurationFromId(uint32_t configurationId);
220220

221+
// Gets the OEM model SKU.
222+
// This is defined as weak to allow the target/platform to provide the implementation.
223+
void ConfigurationManager_GetOemModelSku(char *model, size_t modelSkuSize);
224+
225+
// Gets the module serial number.
226+
// This is defined as weak to allow the target/platform to provide the implementation.
227+
void ConfigurationManager_GetModuleSerialNumber(char *serialNumber, size_t serialNumberSize);
228+
229+
// Gets the system serial number.
230+
// This is defined as weak to allow the target/platform to provide the implementation.
231+
void ConfigurationManager_GetSystemSerialNumber(char *serialNumber, size_t serialNumberSize);
232+
221233
#ifdef __cplusplus
222234
}
223235
#endif

src/HAL/nanoHAL_ConfigurationManager.c

+14
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,17 @@ __nfweak bool ConfigurationManager_CheckExistingConfigurationBlock(
339339

340340
return memcmp(cursor1, cursor2, existingConfigBlockSize) == 0;
341341
}
342+
343+
__nfweak void ConfigurationManager_GetOemModelSku(char *model, size_t modelSkuSize)
344+
{
345+
// default implementation
346+
// this is weak so the target can provide the implementation
347+
memset(model, 0, modelSkuSize);
348+
}
349+
350+
__nfweak void ConfigurationManager_GetModuleSerialNumber(char *serialNumber, size_t serialNumberSize)
351+
{
352+
// default implementation
353+
// this is weak so a manufacturer can provide a strong implementation
354+
memset(serialNumber, 0, serialNumberSize);
355+
}

src/HAL/nanoHAL_ConfigurationManager_stubs.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <nanoHAL_v2.h>
77

8-
__nfweak void ConfigurationManager_Initialize(){};
8+
__nfweak void ConfigurationManager_Initialize() {};
99

1010
__nfweak void *ConfigurationManager_FindNetworkConfigurationBlocks(uint32_t startAddress, uint32_t endAddress)
1111
{
@@ -70,3 +70,18 @@ __nfweak bool ConfigurationManager_CheckExistingConfigurationBlock(
7070

7171
return false;
7272
}
73+
74+
__nfweak void ConfigurationManager_GetOemModelSku(char *model, size_t modelSkuSize)
75+
{
76+
memset(model, 0, modelSkuSize);
77+
}
78+
79+
__nfweak void ConfigurationManager_GetModuleSerialNumber(char *serialNumber, size_t serialNumberSize)
80+
{
81+
memset(serialNumber, 0, serialNumberSize);
82+
}
83+
84+
__nfweak void ConfigurationManager_GetSystemSerialNumber(char *serialNumber, size_t serialNumberSize)
85+
{
86+
memset(serialNumber, 0, serialNumberSize);
87+
}

src/HAL/nanoHAL_SystemInformation.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ bool GetHalSystemInfo(HalSystemInfo &systemInfo)
3232
len = sizeof(systemInfo.m_releaseInfo.TargetName);
3333
hal_strncpy_s((char *)&systemInfo.m_releaseInfo.TargetName[0], len, PLATFORMNAMESTRING, len - 1);
3434

35-
// we are not supporting this at this time
3635
// OEM_MODEL_SKU:
37-
// memcpy((void*)&(systemInfo.m_OemModelInfo), (void*)&(g_ConfigurationSector.OEM_Model_SKU),
38-
// sizeof(OEM_MODEL_SKU));
36+
ConfigurationManager_GetOemModelSku((char *)&systemInfo.m_OemModelInfo, sizeof(systemInfo.m_OemModelInfo));
3937

40-
// we are not supporting this at this time
4138
// OEM_SERIAL_NUMBERS:
42-
// memcpy((void*)&(systemInfo.m_OemSerialNumbers), (void*)&(g_ConfigurationSector.OemSerialNumbers),
43-
// sizeof(OEM_SERIAL_NUMBERS));
39+
ConfigurationManager_GetModuleSerialNumber(
40+
(char *)&systemInfo.m_OemSerialNumbers.module_serial_number,
41+
sizeof(systemInfo.m_OemSerialNumbers.module_serial_number));
42+
43+
ConfigurationManager_GetSystemSerialNumber(
44+
(char *)&systemInfo.m_OemSerialNumbers.system_serial_number,
45+
sizeof(systemInfo.m_OemSerialNumbers.system_serial_number));
4446

4547
return TRUE;
4648
#endif

targets/AzureRTOS/Maxim/_common/targetHAL_ConfigurationManager.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,11 @@ __nfweak bool InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface
526526
// can't create a "default" network config because we are lacking definition of a MAC address
527527
return FALSE;
528528
}
529+
530+
// default implementation
531+
// this is weak so a manufacturer can provide a strong implementation
532+
__nfweak void ConfigurationManager_GetSystemSerialNumber(char *serialNumber, size_t serialNumberSize)
533+
{
534+
// do the thing to get unique device ID
535+
memset(serialNumber, 0, serialNumberSize);
536+
}

targets/AzureRTOS/ST/_common/targetHAL_ConfigurationManager.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -766,3 +766,11 @@ int32_t ConfigurationManager_FindNetworkConfigurationMatchingWirelessConfigurati
766766
// not found
767767
return -1;
768768
}
769+
770+
// default implementation
771+
// this is weak so a manufacturer can provide a strong implementation
772+
__nfweak void ConfigurationManager_GetSystemSerialNumber(char *serialNumber, size_t serialNumberSize)
773+
{
774+
// do the thing to get unique device ID
775+
memset(serialNumber, 0, serialNumberSize);
776+
}

targets/AzureRTOS/SiliconLabs/_common/targetHAL_ConfigurationManager.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <nanoHAL_v2.h>
88
#include <nanoWeak.h>
99
// #include <network_options.h>
10+
#include <em_device.h>
1011

1112
#if defined(WIFI_DRIVER_ISM43362) && defined(I_AM_NANOCLR)
1213
#include <wifi.h>
@@ -773,3 +774,35 @@ int32_t ConfigurationManager_FindNetworkConfigurationMatchingWirelessConfigurati
773774
// not found
774775
return -1;
775776
}
777+
778+
// default implementation
779+
// this is weak so a manufacturer can provide a strong implementation
780+
__nfweak void ConfigurationManager_GetSystemSerialNumber(char *serialNumber, size_t serialNumberSize)
781+
{
782+
memset(serialNumber, 0, serialNumberSize);
783+
784+
// Use the device Unique ID which is 64 bits long
785+
// Put it in the LSB of the serial number
786+
int startOfId = serialNumberSize - 8;
787+
788+
// high 32 bits
789+
uint32_t rawId = DEVINFO->UNIQUEH;
790+
for (int i = 3; i >= 0; --i)
791+
{
792+
serialNumber[startOfId + i] = rawId & 0xFF;
793+
rawId >>= 8;
794+
}
795+
796+
// low 32 bits
797+
rawId = DEVINFO->UNIQUEL;
798+
for (int i = 7; i >= 4; --i)
799+
{
800+
serialNumber[startOfId + i] = rawId & 0xFF;
801+
rawId >>= 8;
802+
}
803+
804+
// Disambiguation is needed because the hardware-specific identifier used to create the
805+
// default serial number on other platforms may be in the same range.
806+
// Set the first byte to a number that is unique (within the nanoFramework CLR) for the Giant Gecko.
807+
serialNumber[0] = 3;
808+
}

targets/ChibiOS/_common/targetHAL_ConfigurationManager.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -641,3 +641,19 @@ __nfweak bool InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface
641641
// can't create a "default" network config because we are lacking definition of a MAC address
642642
return FALSE;
643643
}
644+
645+
// default implementation
646+
// this is weak so a manufacturer can provide a strong implementation
647+
__nfweak void ConfigurationManager_GetSystemSerialNumber(char *serialNumber, size_t serialNumberSize)
648+
{
649+
// do the thing to get unique device ID
650+
memset(serialNumber, 0, serialNumberSize);
651+
// Use the 96 bit unique device ID => 12 bytes
652+
// memory copy from the address pointed by UID_BASE define (from STM32 HAL)
653+
memcpy(&serialNumber[serialNumberSize - 12], ((uint8_t *)UID_BASE), 12);
654+
655+
// Disambiguation is needed because the hardware-specific identifier used to create the
656+
// default serial number on other platforms may be in the same range.
657+
// Set the first byte to a number that is unique (within the nanoFramework CLR) for STM32.
658+
serialNumber[0] = 2;
659+
}

targets/ESP32/_common/targetHAL_ConfigurationManager.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -896,3 +896,23 @@ HAL_Configuration_X509DeviceCertificate *ConfigurationManager_GetDeviceCertifica
896896
// not found, or failed to allocate memory
897897
return NULL;
898898
}
899+
900+
// default implementation
901+
// this is weak so a manufacturer can provide a strong implementation
902+
__nfweak void ConfigurationManager_GetSystemSerialNumber(char *serialNumber, size_t serialNumberSize)
903+
{
904+
memset(serialNumber, 0, serialNumberSize);
905+
906+
// Use the factory-provided MAC address as unique ID
907+
uint8_t macAddress[6];
908+
esp_err_t err = esp_read_mac(macAddress, ESP_MAC_EFUSE_FACTORY);
909+
if (err == ESP_OK)
910+
{
911+
memcpy(&serialNumber[serialNumberSize - sizeof(macAddress)], macAddress, sizeof(macAddress));
912+
913+
// Disambiguation is needed because the hardware-specific identifier used to create the
914+
// default serial number on other platforms may be in the same range.
915+
// Set the first byte to a number that is unique (within the nanoFramework CLR) for ESP32.
916+
serialNumber[0] = 1;
917+
}
918+
}

targets/FreeRTOS/NXP/_common/targetHAL_ConfigurationManager.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,11 @@ bool InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface *pconfig,
420420
// can't create a "default" network config because we are lacking definition of a MAC address
421421
return FALSE;
422422
}
423+
424+
// default implementation
425+
// this is weak so a manufacturer can provide a strong implementation
426+
__nfweak void ConfigurationManager_GetSystemSerialNumber(char *serialNumber, size_t serialNumberSize)
427+
{
428+
// do the thing to get unique device ID
429+
memset(serialNumber, 0, serialNumberSize);
430+
}

targets/TI_SimpleLink/_common/targetHAL_ConfigurationManager_CC13xx_26xx.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -594,3 +594,11 @@ bool InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface *pconfig,
594594

595595
return true;
596596
}
597+
598+
// default implementation
599+
// this is weak so a manufacturer can provide a strong implementation
600+
__nfweak void ConfigurationManager_GetSystemSerialNumber(char *serialNumber, size_t serialNumberSize)
601+
{
602+
// do the thing to get unique device ID
603+
memset(serialNumber, 0, serialNumberSize);
604+
}

targets/TI_SimpleLink/_common/targetHAL_ConfigurationManager_CC32xx.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -593,3 +593,11 @@ bool InitialiseNetworkDefaultConfig(HAL_Configuration_NetworkInterface *pconfig,
593593

594594
return true;
595595
}
596+
597+
// default implementation
598+
// this is weak so a manufacturer can provide a strong implementation
599+
__nfweak void ConfigurationManager_GetSystemSerialNumber(char *serialNumber, size_t serialNumberSize)
600+
{
601+
// do the thing to get unique device ID
602+
memset(serialNumber, 0, serialNumberSize);
603+
}

0 commit comments

Comments
 (0)