From dbab0a8b50f17b965c057bc22b3f167c622db3da Mon Sep 17 00:00:00 2001 From: Junior Martinez Date: Tue, 7 Mar 2023 21:31:26 -0500 Subject: [PATCH 1/2] Fix a few issues preventing siwx917 builds. efr32 KeyValueStoreManagerImpl.cpp and MigrationManager implementation could and should be share for the siwx917 platform so move it and renable the class and namespace of the migration manager --- .../SiWx917/include/CHIPProjectConfig.h | 11 - .../platform/silabs/SiWx917/SiWx917/rsi_if.c | 1 + .../{efr32 => }/KeyValueStoreManagerImpl.cpp | 4 +- .../silabs/{efr32 => }/MigrationManager.cpp | 10 +- .../silabs/{efr32 => }/MigrationManager.h | 14 +- src/platform/silabs/SiWx917/BUILD.gn | 4 +- .../SiWx917/KeyValueStoreManagerImpl.cpp | 213 ------------------ src/platform/silabs/efr32/BUILD.gn | 4 +- 8 files changed, 20 insertions(+), 241 deletions(-) rename src/platform/silabs/{efr32 => }/KeyValueStoreManagerImpl.cpp (98%) rename src/platform/silabs/{efr32 => }/MigrationManager.cpp (92%) rename src/platform/silabs/{efr32 => }/MigrationManager.h (80%) delete mode 100644 src/platform/silabs/SiWx917/KeyValueStoreManagerImpl.cpp diff --git a/examples/lighting-app/silabs/SiWx917/include/CHIPProjectConfig.h b/examples/lighting-app/silabs/SiWx917/include/CHIPProjectConfig.h index ff01045a6c6707..751ebfcff265f2 100644 --- a/examples/lighting-app/silabs/SiWx917/include/CHIPProjectConfig.h +++ b/examples/lighting-app/silabs/SiWx917/include/CHIPProjectConfig.h @@ -69,17 +69,6 @@ */ #define CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION 1 -/** - * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING - * - * A string identifying the software version running on the device. - * CHIP service currently expects the software version to be in the format - * {MAJOR_VERSION}.0d{MINOR_VERSION} - */ -#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING -#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "0.1ALPHA" -#endif - /** * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION * diff --git a/examples/platform/silabs/SiWx917/SiWx917/rsi_if.c b/examples/platform/silabs/SiWx917/SiWx917/rsi_if.c index 4197532369b0ee..d2e3a5124695dc 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/rsi_if.c +++ b/examples/platform/silabs/SiWx917/SiWx917/rsi_if.c @@ -422,6 +422,7 @@ static void wfx_rsi_save_ap_info() static void wfx_rsi_do_join(void) { int32_t status; + rsi_security_mode_t connect_security_mode; if (wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED)) { diff --git a/src/platform/silabs/efr32/KeyValueStoreManagerImpl.cpp b/src/platform/silabs/KeyValueStoreManagerImpl.cpp similarity index 98% rename from src/platform/silabs/efr32/KeyValueStoreManagerImpl.cpp rename to src/platform/silabs/KeyValueStoreManagerImpl.cpp index dc5b3267564e1b..da31073fa48ec4 100644 --- a/src/platform/silabs/efr32/KeyValueStoreManagerImpl.cpp +++ b/src/platform/silabs/KeyValueStoreManagerImpl.cpp @@ -49,7 +49,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::Init(void) err = SilabsConfig::Init(); SuccessOrExit(err); - EFR32::EFR32Migration::GetMigrationManager().applyMigrations(); + Silabs::MigrationManager::GetMigrationInstance().applyMigrations(); memset(mKvsKeyMap, 0, sizeof(mKvsKeyMap)); size_t outLen; @@ -183,7 +183,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t // The user doesn't need the KeyString prefix, Read data after it size_t KeyStringLen = strlen(key); err = SilabsConfig::ReadConfigValueBin(nvm3Key, reinterpret_cast(value), value_size, outLen, - (offset_bytes + KeyStringLen)); + (offset_bytes + KeyStringLen)); if (read_bytes_size) { *read_bytes_size = outLen; diff --git a/src/platform/silabs/efr32/MigrationManager.cpp b/src/platform/silabs/MigrationManager.cpp similarity index 92% rename from src/platform/silabs/efr32/MigrationManager.cpp rename to src/platform/silabs/MigrationManager.cpp index abd0bcbc834adf..037f9f7f292079 100644 --- a/src/platform/silabs/efr32/MigrationManager.cpp +++ b/src/platform/silabs/MigrationManager.cpp @@ -26,7 +26,7 @@ using namespace ::chip::DeviceLayer::PersistedStorage; namespace chip { namespace DeviceLayer { -namespace EFR32 { +namespace Silabs { namespace { typedef void (*func_ptr)(); @@ -45,7 +45,7 @@ static migrationData_t migrationTable[] = { } // namespace -void EFR32Migration::applyMigrations() +void MigrationManager::applyMigrations() { uint32_t lastMigationGroupDone = 0; SilabsConfig::ReadConfigValue(SilabsConfig::kConfigKey_MigrationCounter, lastMigationGroupDone); @@ -62,12 +62,12 @@ void EFR32Migration::applyMigrations() SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_MigrationCounter, completedMigrationGroup); } -EFR32Migration & EFR32Migration::GetMigrationManager() +MigrationManager & MigrationManager::GetMigrationInstance() { - static EFR32Migration sMigrationManager; + static MigrationManager sMigrationManager; return sMigrationManager; } -} // namespace EFR32 +} // namespace Silabs } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/silabs/efr32/MigrationManager.h b/src/platform/silabs/MigrationManager.h similarity index 80% rename from src/platform/silabs/efr32/MigrationManager.h rename to src/platform/silabs/MigrationManager.h index 59ea29d0769152..2d560c4fa194df 100644 --- a/src/platform/silabs/efr32/MigrationManager.h +++ b/src/platform/silabs/MigrationManager.h @@ -20,25 +20,25 @@ namespace chip { namespace DeviceLayer { -namespace EFR32 { +namespace Silabs { -class EFR32Migration +class MigrationManager { friend class KeyValueStoreManagerImpl; public: /** - * The EFR32 migration manager is implemented as a singleton + * The Silabs migration manager is implemented as a singleton * User should get the object from this getter. */ - static EFR32Migration & GetMigrationManager(); + static MigrationManager & GetMigrationInstance(); static void applyMigrations(); private: - EFR32Migration(){}; - ~EFR32Migration(){}; + MigrationManager(){}; + ~MigrationManager(){}; }; -} // namespace EFR32 +} // namespace Silabs } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index d53d04894869ce..e79810a4029093 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -43,8 +43,11 @@ static_library("SiWx917") { "${silabs_platform_dir}/DiagnosticDataProviderImpl.cpp", "${silabs_platform_dir}/DiagnosticDataProviderImpl.h", "${silabs_platform_dir}/InetPlatformConfig.h", + "${silabs_platform_dir}/KeyValueStoreManagerImpl.cpp", "${silabs_platform_dir}/KeyValueStoreManagerImpl.h", "${silabs_platform_dir}/Logging.cpp", + "${silabs_platform_dir}/MigrationManager.cpp", + "${silabs_platform_dir}/MigrationManager.h", "${silabs_platform_dir}/PlatformManagerImpl.h", "${silabs_platform_dir}/SilabsConfig.cpp", "${silabs_platform_dir}/SilabsConfig.h", @@ -53,7 +56,6 @@ static_library("SiWx917") { "../../SingletonConfigurationManager.cpp", "BLEManagerImpl.cpp", "ConfigurationManagerImpl.cpp", - "KeyValueStoreManagerImpl.cpp", "PlatformManagerImpl.cpp", "bluetooth/rsi_ble_config.h", "bluetooth/wfx_sl_ble_init.c", diff --git a/src/platform/silabs/SiWx917/KeyValueStoreManagerImpl.cpp b/src/platform/silabs/SiWx917/KeyValueStoreManagerImpl.cpp deleted file mode 100644 index 9bca8221fcb229..00000000000000 --- a/src/platform/silabs/SiWx917/KeyValueStoreManagerImpl.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * - * Copyright (c) 2021-2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * Platform-specific key value storage implementation for SILABS - */ - -#include -#include -#include -#include -#include -#include -#include - -using namespace ::chip; -using namespace ::chip::DeviceLayer::Internal; - -#define CONVERT_KEYMAP_INDEX_TO_NVM3KEY(index) (SilabsConfig::kConfigKey_KvsFirstKeySlot + index) -#define CONVERT_NVM3KEY_TO_KEYMAP_INDEX(nvm3Key) (nvm3Key - SilabsConfig::kConfigKey_KvsFirstKeySlot) - -namespace chip { -namespace DeviceLayer { -namespace PersistedStorage { - -KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance; -char mKvsStoredKeyString[KeyValueStoreManagerImpl::kMaxEntries][PersistentStorageDelegate::kKeyLengthMax + 1]; - -CHIP_ERROR KeyValueStoreManagerImpl::Init(void) -{ - CHIP_ERROR err; - err = SilabsConfig::Init(); - SuccessOrExit(err); - - memset(mKvsStoredKeyString, 0, sizeof(mKvsStoredKeyString)); - size_t outLen; - err = SilabsConfig::ReadConfigValueBin(SilabsConfig::kConfigKey_KvsStringKeyMap, - reinterpret_cast(mKvsStoredKeyString), sizeof(mKvsStoredKeyString), outLen); - - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) // Initial boot - { - err = CHIP_NO_ERROR; - } - -exit: - return err; -} - -bool KeyValueStoreManagerImpl::IsValidKvsNvm3Key(uint32_t nvm3Key) const -{ - return ((SilabsConfig::kConfigKey_KvsFirstKeySlot <= nvm3Key) && (nvm3Key <= SilabsConfig::kConfigKey_KvsLastKeySlot)); -} - -CHIP_ERROR KeyValueStoreManagerImpl::MapKvsKeyToNvm3(const char * key, uint32_t & nvm3Key, bool isSlotNeeded) const -{ - CHIP_ERROR err; - uint8_t firstEmptyKeySlot = kMaxEntries; - for (uint8_t keyIndex = 0; keyIndex < kMaxEntries; keyIndex++) - { - if (strcmp(key, mKvsStoredKeyString[keyIndex]) == 0) - { - nvm3Key = CONVERT_KEYMAP_INDEX_TO_NVM3KEY(keyIndex); - VerifyOrDie(IsValidKvsNvm3Key(nvm3Key) == true); - return CHIP_NO_ERROR; - } - - if (isSlotNeeded && (firstEmptyKeySlot == kMaxEntries) && (mKvsStoredKeyString[keyIndex][0] == 0)) - { - firstEmptyKeySlot = keyIndex; - } - } - - if (isSlotNeeded) - { - if (firstEmptyKeySlot != kMaxEntries) - { - nvm3Key = CONVERT_KEYMAP_INDEX_TO_NVM3KEY(firstEmptyKeySlot); - VerifyOrDie(IsValidKvsNvm3Key(nvm3Key) == true); - err = CHIP_NO_ERROR; - } - else - { - err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; - } - } - else - { - err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; - } - return err; -} - -void KeyValueStoreManagerImpl::ForceKeyMapSave() -{ - OnScheduledKeyMapSave(nullptr, nullptr); -} - -void KeyValueStoreManagerImpl::OnScheduledKeyMapSave(System::Layer * systemLayer, void * appState) -{ - SilabsConfig::WriteConfigValueBin(SilabsConfig::kConfigKey_KvsStringKeyMap, - reinterpret_cast(mKvsStoredKeyString), sizeof(mKvsStoredKeyString)); -} - -void KeyValueStoreManagerImpl::ScheduleKeyMapSave(void) -{ - /* - During commissioning, the key map will be modified multiples times subsequently. - Commit the key map in nvm once it as stabilized. - */ - SystemLayer().StartTimer( - std::chrono::duration_cast(System::Clock::Seconds32(SILABS_KVS_SAVE_DELAY_SECONDS)), - KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL); -} - -CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size, - size_t offset_bytes) const -{ - VerifyOrReturnError(key != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - - uint32_t nvm3Key; - CHIP_ERROR err = MapKvsKeyToNvm3(key, nvm3Key); - VerifyOrReturnError(err == CHIP_NO_ERROR, err); - - size_t outLen; - err = SilabsConfig::ReadConfigValueBin(nvm3Key, reinterpret_cast(value), value_size, outLen, offset_bytes); - if (read_bytes_size) - { - *read_bytes_size = outLen; - } - - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) - { - return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; - } - - return err; -} - -CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size) -{ - VerifyOrReturnError(key != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - - uint32_t nvm3Key; - CHIP_ERROR err = MapKvsKeyToNvm3(key, nvm3Key, /* isSlotNeeded */ true); - VerifyOrReturnError(err == CHIP_NO_ERROR, err); - - err = SilabsConfig::WriteConfigValueBin(nvm3Key, reinterpret_cast(value), value_size); - if (err == CHIP_NO_ERROR) - { - uint32_t keyIndex = nvm3Key - SilabsConfig::kConfigKey_KvsFirstKeySlot; - Platform::CopyString(mKvsStoredKeyString[keyIndex], key); - ScheduleKeyMapSave(); - } - - return err; -} - -CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key) -{ - VerifyOrReturnError(key != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - - uint32_t nvm3Key; - CHIP_ERROR err = MapKvsKeyToNvm3(key, nvm3Key); - VerifyOrReturnError(err == CHIP_NO_ERROR, err); - - err = SilabsConfig::ClearConfigValue(nvm3Key); - if (err == CHIP_NO_ERROR) - { - uint32_t keyIndex = CONVERT_NVM3KEY_TO_KEYMAP_INDEX(nvm3Key); - memset(mKvsStoredKeyString[keyIndex], 0, sizeof(mKvsStoredKeyString[keyIndex])); - ScheduleKeyMapSave(); - } - - return err; -} - -CHIP_ERROR KeyValueStoreManagerImpl::ErasePartition(void) -{ - // Iterate over all the Matter Kvs nvm3 records and delete each one... - CHIP_ERROR err = CHIP_NO_ERROR; - for (uint32_t nvm3Key = SilabsConfig::kMinConfigKey_MatterKvs; nvm3Key < SilabsConfig::kMaxConfigKey_MatterKvs; nvm3Key++) - { - err = SilabsConfig::ClearConfigValue(nvm3Key); - - if (err != CHIP_NO_ERROR) - { - break; - } - } - - memset(mKvsStoredKeyString, 0, sizeof(mKvsStoredKeyString)); - return err; -} - -} // namespace PersistedStorage -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index f294a8d2d10846..f5f0108ed778e2 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -57,8 +57,10 @@ static_library("efr32") { "${silabs_platform_dir}/DiagnosticDataProviderImpl.cpp", "${silabs_platform_dir}/DiagnosticDataProviderImpl.h", "${silabs_platform_dir}/InetPlatformConfig.h", + "${silabs_platform_dir}/KeyValueStoreManagerImpl.cpp", "${silabs_platform_dir}/KeyValueStoreManagerImpl.h", "${silabs_platform_dir}/Logging.cpp", + "${silabs_platform_dir}/MigrationManager.cpp", "${silabs_platform_dir}/PlatformManagerImpl.h", "${silabs_platform_dir}/SilabsConfig.cpp", "${silabs_platform_dir}/SilabsConfig.h", @@ -66,8 +68,6 @@ static_library("efr32") { "../../FreeRTOS/SystemTimeSupport.cpp", "../../SingletonConfigurationManager.cpp", "ConfigurationManagerImpl.cpp", - "KeyValueStoreManagerImpl.cpp", - "MigrationManager.cpp", "PlatformManagerImpl.cpp", ] From 423c1ca6a8df145acb522bc22332fe6bfee0bfef Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 8 Mar 2023 02:40:09 +0000 Subject: [PATCH 2/2] Restyled by clang-format --- src/platform/silabs/KeyValueStoreManagerImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/silabs/KeyValueStoreManagerImpl.cpp b/src/platform/silabs/KeyValueStoreManagerImpl.cpp index da31073fa48ec4..ffff7b945186bb 100644 --- a/src/platform/silabs/KeyValueStoreManagerImpl.cpp +++ b/src/platform/silabs/KeyValueStoreManagerImpl.cpp @@ -183,7 +183,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t // The user doesn't need the KeyString prefix, Read data after it size_t KeyStringLen = strlen(key); err = SilabsConfig::ReadConfigValueBin(nvm3Key, reinterpret_cast(value), value_size, outLen, - (offset_bytes + KeyStringLen)); + (offset_bytes + KeyStringLen)); if (read_bytes_size) { *read_bytes_size = outLen;