diff --git a/src/HAL/Include/nanoHAL_ConfigurationManager.h b/src/HAL/Include/nanoHAL_ConfigurationManager.h index bc3c627998..59d61be5ea 100644 --- a/src/HAL/Include/nanoHAL_ConfigurationManager.h +++ b/src/HAL/Include/nanoHAL_ConfigurationManager.h @@ -186,15 +186,18 @@ extern "C" HAL_Configuration_Wireless80211 *ConfigurationManager_GetWirelessConfigurationFromId(uint32_t configurationId); // gets the HAL_Configuration_WirelessAP configuration block that has the specified Id, if that exists - // defined as weak needs to be free to implement the storage of the configuration block as they see fit + // memory is allocated for the configuration block, has to be free by the caller + // defined as weak to allow replacement at platform/target level to allow different storage management HAL_Configuration_WirelessAP *ConfigurationManager_GetWirelessAPConfigurationFromId(uint32_t configurationId); // gets the HAL_Configuration_X509CaRootBundle certificate store, if that exists - // defined as weak needs to be free to implement the storage of the configuration block as they see fit + // memory is allocated for the configuration block, has to be free by the caller + // defined as weak to allow replacement at platform/target level to allow different storage management HAL_Configuration_X509CaRootBundle *ConfigurationManager_GetCertificateStore(); // gets the HAL_Configuration_X509DeviceCertificate device certificate, if that exists - // defined as weak needs to be free to implement the storage of the configuration block as they see fit + // memory is allocated for the configuration block, has to be free by the caller + // defined as weak to allow replacement at platform/target level to allow different storage management HAL_Configuration_X509DeviceCertificate *ConfigurationManager_GetDeviceCertificate(); #ifdef __cplusplus diff --git a/src/HAL/nanoHAL_ConfigurationManager.c b/src/HAL/nanoHAL_ConfigurationManager.c index be0fcbf1b6..9080c1d886 100644 --- a/src/HAL/nanoHAL_ConfigurationManager.c +++ b/src/HAL/nanoHAL_ConfigurationManager.c @@ -223,7 +223,20 @@ __nfweak HAL_Configuration_Wireless80211 *ConfigurationManager_GetWirelessConfig { if (g_TargetConfiguration.Wireless80211Configs->Configs[i]->Id == configurationId) { - return g_TargetConfiguration.Wireless80211Configs->Configs[i]; + // need to make a copy + HAL_Configuration_Wireless80211 *configBlock = + (HAL_Configuration_Wireless80211 *)platform_malloc(sizeof(HAL_Configuration_Wireless80211)); + + // check allocation + if (configBlock) + { + memcpy( + configBlock, + g_TargetConfiguration.Wireless80211Configs->Configs[i], + sizeof(HAL_Configuration_Wireless80211)); + + return configBlock; + } } } @@ -237,7 +250,20 @@ __nfweak HAL_Configuration_WirelessAP *ConfigurationManager_GetWirelessAPConfigu { if (g_TargetConfiguration.WirelessAPConfigs->Configs[i]->Id == configurationId) { - return g_TargetConfiguration.WirelessAPConfigs->Configs[i]; + // need to make a copy + HAL_Configuration_WirelessAP *configBlock = + (HAL_Configuration_WirelessAP *)platform_malloc(sizeof(HAL_Configuration_WirelessAP)); + + // check allocation + if (configBlock) + { + memcpy( + configBlock, + g_TargetConfiguration.WirelessAPConfigs->Configs[i], + sizeof(HAL_Configuration_WirelessAP)); + + return configBlock; + } } } @@ -249,7 +275,21 @@ __nfweak HAL_Configuration_X509CaRootBundle *ConfigurationManager_GetCertificate { if (g_TargetConfiguration.CertificateStore->Count) { - return g_TargetConfiguration.CertificateStore->Certificates[0]; + // need to make a copy + // need to compute size as the cert size is variable + int32_t blockSize = offsetof(HAL_Configuration_X509CaRootBundle, Certificate) + + g_TargetConfiguration.CertificateStore->Certificates[0]->CertificateSize; + + HAL_Configuration_X509CaRootBundle *configBlock = + (HAL_Configuration_X509CaRootBundle *)platform_malloc(blockSize); + + // check allocation + if (configBlock) + { + memcpy(configBlock, g_TargetConfiguration.CertificateStore->Certificates[0], blockSize); + + return configBlock; + } } // not found @@ -260,7 +300,21 @@ __nfweak HAL_Configuration_X509DeviceCertificate *ConfigurationManager_GetDevice { if (g_TargetConfiguration.DeviceCertificates->Count) { - return g_TargetConfiguration.DeviceCertificates->Certificates[0]; + // need to make a copy + // need to compute size as the cert size is variable + int32_t blockSize = offsetof(HAL_Configuration_X509DeviceCertificate, Certificate) + + g_TargetConfiguration.DeviceCertificates->Certificates[0]->CertificateSize; + + HAL_Configuration_X509DeviceCertificate *configBlock = + (HAL_Configuration_X509DeviceCertificate *)platform_malloc(blockSize); + + // check allocation + if (configBlock) + { + memcpy(configBlock, g_TargetConfiguration.DeviceCertificates->Certificates[0], blockSize); + + return configBlock; + } } // not found