Skip to content

Commit

Permalink
[Silabs] Merge PlatformManagerImpl.cpp for efr32 and si917 platforms (#…
Browse files Browse the repository at this point in the history
…33274)

* Merge PlatformManagerImpl.cpp for efr32 and si917 platforms as they were mostly the same

* add a nullptr check
  • Loading branch information
jmartinez-silabs authored May 3, 2024
1 parent fcfc9bc commit e6d3184
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <platform/PlatformManager.h>
#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.ipp>
#include <platform/silabs/DiagnosticDataProviderImpl.h>

#if defined(TINYCRYPT_PRIMITIVES)
#include "tinycrypt/ecc.h"
#endif
Expand All @@ -39,36 +40,32 @@
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#include "AppConfig.h"
#include "FreeRTOS.h"

using namespace chip::DeviceLayer::Internal;

namespace chip {
namespace DeviceLayer {

PlatformManagerImpl PlatformManagerImpl::sInstance;

#if SLI_SI91X_MCU_INTERFACE
#if defined(TINYCRYPT_PRIMITIVES)
sys_mutex_t PlatformManagerImpl::rngMutexHandle = NULL;
#endif

#if defined(TINYCRYPT_PRIMITIVES)
int PlatformManagerImpl::uECC_RNG_Function(uint8_t * dest, unsigned int size)
{
int res;

sys_mutex_lock(&rngMutexHandle);
res = (chip::Crypto::DRBG_get_bytes(dest, size) == CHIP_NO_ERROR) ? size : 0;
int res = (chip::Crypto::DRBG_get_bytes(dest, size) == CHIP_NO_ERROR) ? size : 0;
sys_mutex_unlock(&rngMutexHandle);

return res;
}
#endif
#endif // TINYCRYPT_PRIMITIVES

static void app_get_random(uint8_t * aOutput, size_t aLen)
{
size_t i;

for (i = 0; i < aLen; i++)
VerifyOrReturn(aOutput != nullptr);
for (size_t i = 0; i < aLen; i++)
{
aOutput[i] = rand();
}
Expand All @@ -81,6 +78,7 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s

return 0;
}
#endif // SLI_SI91X_MCU_INTERFACE

CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
{
Expand All @@ -97,16 +95,15 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)

ReturnErrorOnFailure(System::Clock::InitClock_RealTime());

// 16 : Threshold value
ReturnErrorOnFailure(chip::Crypto::add_entropy_source(app_entropy_source, NULL, 16));
#if SLI_SI91X_MCU_INTERFACE
ReturnErrorOnFailure(chip::Crypto::add_entropy_source(app_entropy_source, NULL, 16 /*Threshold value*/));

#if defined(TINYCRYPT_PRIMITIVES)
/* Set RNG function for tinycrypt operations. */
err_t ret;
ret = sys_mutex_new(&rngMutexHandle);
VerifyOrExit((ERR_OK == ret), err = CHIP_ERROR_NO_MEMORY);
VerifyOrExit(sys_mutex_new(&rngMutexHandle) == ERR_OK, err = CHIP_ERROR_NO_MEMORY);
uECC_set_rng(PlatformManagerImpl::uECC_RNG_Function);
#endif
#endif // TINYCRYPT_PRIMITIVES
#endif // SLI_SI91X_MCU_INTERFACE

// Call _InitChipStack() on the generic implementation base class
// to finish the initialization process.
Expand Down Expand Up @@ -139,6 +136,7 @@ void PlatformManagerImpl::_Shutdown()
{
Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>::_Shutdown();
}

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
void PlatformManagerImpl::HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData)
{
Expand Down Expand Up @@ -206,7 +204,7 @@ void PlatformManagerImpl::HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wf

(void) sInstance.PostEvent(&event);
}
#endif
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION

} // namespace DeviceLayer
} // namespace chip
2 changes: 1 addition & 1 deletion src/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static_library("SiWx917") {
"${silabs_platform_dir}/Logging.cpp",
"${silabs_platform_dir}/MigrationManager.cpp",
"${silabs_platform_dir}/MigrationManager.h",
"${silabs_platform_dir}/PlatformManagerImpl.cpp",
"${silabs_platform_dir}/PlatformManagerImpl.h",
"${silabs_platform_dir}/SilabsConfig.cpp",
"${silabs_platform_dir}/SilabsConfig.h",
Expand All @@ -63,7 +64,6 @@ static_library("SiWx917") {
"../rs911x/rsi_ble_config.h",
"../rs911x/wfx_sl_ble_init.c",
"../rs911x/wfx_sl_ble_init.h",
"PlatformManagerImpl.cpp",
]

if (chip_enable_ota_requestor) {
Expand Down
2 changes: 1 addition & 1 deletion src/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static_library("efr32") {
"${silabs_platform_dir}/KeyValueStoreManagerImpl.h",
"${silabs_platform_dir}/Logging.cpp",
"${silabs_platform_dir}/MigrationManager.cpp",
"${silabs_platform_dir}/PlatformManagerImpl.cpp",
"${silabs_platform_dir}/PlatformManagerImpl.h",
"${silabs_platform_dir}/SilabsConfig.cpp",
"${silabs_platform_dir}/SilabsConfig.h",
Expand All @@ -64,7 +65,6 @@ static_library("efr32") {
"${silabs_platform_dir}/platformAbstraction/SilabsPlatformBase.h",
"../../FreeRTOS/SystemTimeSupport.cpp",
"../../SingletonConfigurationManager.cpp",
"PlatformManagerImpl.cpp",
]

if (chip_enable_ble_rs911x) {
Expand Down
163 changes: 0 additions & 163 deletions src/platform/silabs/efr32/PlatformManagerImpl.cpp

This file was deleted.

0 comments on commit e6d3184

Please sign in to comment.