From 5d461dfa644b5e825425000e25253801e896323a Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Tue, 5 Apr 2022 11:52:52 +0800 Subject: [PATCH 1/3] [PersistentStorage] [Commissioning] Restructure PersistentStorage configuration to fix commissioning issue - Key-values outside of below domains are not stored in proper domains "chip-factory" "chip-config" "chip-counters" - Add more domains to be registered into DCT - Add AmebaConfig::EnsureNamespace2 to register some domains into DCT2 - Change wrong error code in AmebaWiFiDriver::Init --- src/platform/Ameba/AmebaConfig.cpp | 25 +++++++++++++++++++ src/platform/Ameba/AmebaConfig.h | 13 ++++++++++ .../Ameba/ConfigurationManagerImpl.cpp | 24 ++++++++++++++++++ .../Ameba/NetworkCommissioningWiFiDriver.cpp | 4 +-- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/platform/Ameba/AmebaConfig.cpp b/src/platform/Ameba/AmebaConfig.cpp index f21d4bb1b702a0..127a9d501ce5f3 100644 --- a/src/platform/Ameba/AmebaConfig.cpp +++ b/src/platform/Ameba/AmebaConfig.cpp @@ -45,6 +45,18 @@ namespace Internal { const char AmebaConfig::kConfigNamespace_ChipFactory[] = "chip-factory"; const char AmebaConfig::kConfigNamespace_ChipConfig[] = "chip-config"; const char AmebaConfig::kConfigNamespace_ChipCounters[] = "chip-counters"; +const char AmebaConfig::kConfigNamespace_ChipFabric1[] = "chip-fabric-1"; +const char AmebaConfig::kConfigNamespace_ChipFabric2[] = "chip-fabric-2"; +const char AmebaConfig::kConfigNamespace_ChipFabric3[] = "chip-fabric-3"; +const char AmebaConfig::kConfigNamespace_ChipFabric4[] = "chip-fabric-4"; +const char AmebaConfig::kConfigNamespace_ChipFabric5[] = "chip-fabric-5"; +const char AmebaConfig::kConfigNamespace_ChipACL[] = "chip-acl"; +const char AmebaConfig::kConfigNamespace_ChipGroupMsgCounters[] = "chip-groupmsgcounters"; +const char AmebaConfig::kConfigNamespace_ChipAttributes[] = "chip-attributes"; +const char AmebaConfig::kConfigNamespace_ChipBindingTable[] = "chip-bindingtable"; +const char AmebaConfig::kConfigNamespace_ChipOTA[] = "chip-ota"; +const char AmebaConfig::kConfigNamespace_ChipDNS[] = "chip-dns"; +const char AmebaConfig::kConfigNamespace_ChipOthers[] = "chip-others"; // Keys stored in the chip-factory namespace const AmebaConfig::Key AmebaConfig::kConfigKey_SerialNum = { kConfigNamespace_ChipFactory, "serial-num" }; @@ -271,6 +283,19 @@ CHIP_ERROR AmebaConfig::EnsureNamespace(const char * ns) return CHIP_NO_ERROR; } +CHIP_ERROR AmebaConfig::EnsureNamespace2(const char * ns) +{ + int32_t success = -1; + + success = registerPref2(ns); + if (success != 0) + { + ChipLogError(DeviceLayer, "dct_register_module2 failed\n"); + } + + return CHIP_NO_ERROR; +} + CHIP_ERROR AmebaConfig::ClearNamespace(const char * ns) { int32_t success = -1; diff --git a/src/platform/Ameba/AmebaConfig.h b/src/platform/Ameba/AmebaConfig.h index 2ca0f0adbcc5a6..dc87ed455f9dcd 100755 --- a/src/platform/Ameba/AmebaConfig.h +++ b/src/platform/Ameba/AmebaConfig.h @@ -40,6 +40,18 @@ class AmebaConfig static const char kConfigNamespace_ChipFactory[]; static const char kConfigNamespace_ChipConfig[]; static const char kConfigNamespace_ChipCounters[]; + static const char kConfigNamespace_ChipFabric1[]; + static const char kConfigNamespace_ChipFabric2[]; + static const char kConfigNamespace_ChipFabric3[]; + static const char kConfigNamespace_ChipFabric4[]; + static const char kConfigNamespace_ChipFabric5[]; + static const char kConfigNamespace_ChipACL[]; + static const char kConfigNamespace_ChipGroupMsgCounters[]; + static const char kConfigNamespace_ChipAttributes[]; + static const char kConfigNamespace_ChipBindingTable[]; + static const char kConfigNamespace_ChipOTA[]; + static const char kConfigNamespace_ChipDNS[]; + static const char kConfigNamespace_ChipOthers[]; // Key definitions for well-known keys. static const Key kConfigKey_SerialNum; @@ -96,6 +108,7 @@ class AmebaConfig static bool ConfigValueExists(Key key); static CHIP_ERROR EnsureNamespace(const char * ns); + static CHIP_ERROR EnsureNamespace2(const char * ns); static CHIP_ERROR ClearNamespace(const char * ns); static void RunConfigUnitTest(void); diff --git a/src/platform/Ameba/ConfigurationManagerImpl.cpp b/src/platform/Ameba/ConfigurationManagerImpl.cpp index 6658765714b28c..3aed7d347cb59f 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.cpp +++ b/src/platform/Ameba/ConfigurationManagerImpl.cpp @@ -55,6 +55,30 @@ CHIP_ERROR ConfigurationManagerImpl::Init() SuccessOrExit(err); err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipCounters); SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric1); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric2); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric3); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric4); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace2(AmebaConfig::kConfigNamespace_ChipFabric5); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipACL); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipGroupMsgCounters); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipAttributes); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipBindingTable); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipOTA); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipDNS); + SuccessOrExit(err); + err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipOthers); + SuccessOrExit(err); if (AmebaConfig::ConfigValueExists(AmebaConfig::kCounterKey_RebootCount)) { diff --git a/src/platform/Ameba/NetworkCommissioningWiFiDriver.cpp b/src/platform/Ameba/NetworkCommissioningWiFiDriver.cpp index d96a99a44afc72..f4a81102968d02 100644 --- a/src/platform/Ameba/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/Ameba/NetworkCommissioningWiFiDriver.cpp @@ -43,13 +43,13 @@ CHIP_ERROR AmebaWiFiDriver::Init(NetworkStatusChangeCallback *) err = PersistedStorage::KeyValueStoreMgr().Get(kWiFiCredentialsKeyName, mSavedNetwork.credentials, sizeof(mSavedNetwork.credentials), &credentialsLen); - if (err == CHIP_ERROR_NOT_FOUND) + if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND) { return CHIP_NO_ERROR; } err = PersistedStorage::KeyValueStoreMgr().Get(kWiFiSSIDKeyName, mSavedNetwork.ssid, sizeof(mSavedNetwork.ssid), &ssidLen); - if (err == CHIP_ERROR_NOT_FOUND) + if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND) { return CHIP_NO_ERROR; } From a30aa4ddf69ce11974e13e104b0f615767e5ee40 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Tue, 5 Apr 2022 13:45:10 +0800 Subject: [PATCH 2/3] [chipinterface] Revise initialization order - Current init order faces hardfault - Move InitOTARequestor after Server is initialized --- examples/all-clusters-app/ameba/main/chipinterface.cpp | 8 ++++---- examples/lighting-app/ameba/main/chipinterface.cpp | 8 ++++---- examples/ota-requestor-app/ameba/main/chipinterface.cpp | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/all-clusters-app/ameba/main/chipinterface.cpp b/examples/all-clusters-app/ameba/main/chipinterface.cpp index 7a89291eafb3f3..306d9c36717e00 100644 --- a/examples/all-clusters-app/ameba/main/chipinterface.cpp +++ b/examples/all-clusters-app/ameba/main/chipinterface.cpp @@ -151,10 +151,6 @@ static void InitOTARequestor(void) static void InitServer(intptr_t context) { -#if CONFIG_ENABLE_OTA_REQUESTOR - InitOTARequestor(); -#endif - // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; initParams.InitializeStaticResourcesBeforeServerInit(); @@ -164,6 +160,10 @@ static void InitServer(intptr_t context) SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); NetWorkCommissioningInstInit(); +#if CONFIG_ENABLE_OTA_REQUESTOR + InitOTARequestor(); +#endif + if (RTW_SUCCESS != wifi_is_connected_to_ap()) { // QR code will be used with CHIP Tool diff --git a/examples/lighting-app/ameba/main/chipinterface.cpp b/examples/lighting-app/ameba/main/chipinterface.cpp index cc0082864f3001..6ef8940aaacfc3 100644 --- a/examples/lighting-app/ameba/main/chipinterface.cpp +++ b/examples/lighting-app/ameba/main/chipinterface.cpp @@ -172,10 +172,6 @@ static Identify gIdentify1 = { static void InitServer(intptr_t context) { -#if CONFIG_ENABLE_OTA_REQUESTOR - InitOTARequestor(); -#endif - // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); @@ -185,6 +181,10 @@ static void InitServer(intptr_t context) SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); NetWorkCommissioningInstInit(); +#if CONFIG_ENABLE_OTA_REQUESTOR + InitOTARequestor(); +#endif + if (RTW_SUCCESS != wifi_is_connected_to_ap()) { // QR code will be used with CHIP Tool diff --git a/examples/ota-requestor-app/ameba/main/chipinterface.cpp b/examples/ota-requestor-app/ameba/main/chipinterface.cpp index df6cf6a71b9f82..983a340a5ebaef 100644 --- a/examples/ota-requestor-app/ameba/main/chipinterface.cpp +++ b/examples/ota-requestor-app/ameba/main/chipinterface.cpp @@ -134,8 +134,6 @@ static void InitOTARequestor(void) static void InitServer(intptr_t context) { - InitOTARequestor(); - // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); @@ -144,6 +142,8 @@ static void InitServer(intptr_t context) // Initialize device attestation config SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); NetWorkCommissioningInstInit(); + + InitOTARequestor(); } extern "C" void ChipTest(void) From d83a2f93fe713e618653956ca38164e4734de737 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 5 Apr 2022 07:57:16 +0000 Subject: [PATCH 3/3] Restyled by clang-format --- src/platform/Ameba/AmebaConfig.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/platform/Ameba/AmebaConfig.cpp b/src/platform/Ameba/AmebaConfig.cpp index 127a9d501ce5f3..f34f0f6f90c160 100644 --- a/src/platform/Ameba/AmebaConfig.cpp +++ b/src/platform/Ameba/AmebaConfig.cpp @@ -42,21 +42,21 @@ namespace Internal { // *** CAUTION ***: Changing the names or namespaces of these values will *break* existing devices. // NVS namespaces used to store device configuration information. -const char AmebaConfig::kConfigNamespace_ChipFactory[] = "chip-factory"; -const char AmebaConfig::kConfigNamespace_ChipConfig[] = "chip-config"; -const char AmebaConfig::kConfigNamespace_ChipCounters[] = "chip-counters"; -const char AmebaConfig::kConfigNamespace_ChipFabric1[] = "chip-fabric-1"; -const char AmebaConfig::kConfigNamespace_ChipFabric2[] = "chip-fabric-2"; -const char AmebaConfig::kConfigNamespace_ChipFabric3[] = "chip-fabric-3"; -const char AmebaConfig::kConfigNamespace_ChipFabric4[] = "chip-fabric-4"; -const char AmebaConfig::kConfigNamespace_ChipFabric5[] = "chip-fabric-5"; -const char AmebaConfig::kConfigNamespace_ChipACL[] = "chip-acl"; -const char AmebaConfig::kConfigNamespace_ChipGroupMsgCounters[] = "chip-groupmsgcounters"; -const char AmebaConfig::kConfigNamespace_ChipAttributes[] = "chip-attributes"; -const char AmebaConfig::kConfigNamespace_ChipBindingTable[] = "chip-bindingtable"; -const char AmebaConfig::kConfigNamespace_ChipOTA[] = "chip-ota"; -const char AmebaConfig::kConfigNamespace_ChipDNS[] = "chip-dns"; -const char AmebaConfig::kConfigNamespace_ChipOthers[] = "chip-others"; +const char AmebaConfig::kConfigNamespace_ChipFactory[] = "chip-factory"; +const char AmebaConfig::kConfigNamespace_ChipConfig[] = "chip-config"; +const char AmebaConfig::kConfigNamespace_ChipCounters[] = "chip-counters"; +const char AmebaConfig::kConfigNamespace_ChipFabric1[] = "chip-fabric-1"; +const char AmebaConfig::kConfigNamespace_ChipFabric2[] = "chip-fabric-2"; +const char AmebaConfig::kConfigNamespace_ChipFabric3[] = "chip-fabric-3"; +const char AmebaConfig::kConfigNamespace_ChipFabric4[] = "chip-fabric-4"; +const char AmebaConfig::kConfigNamespace_ChipFabric5[] = "chip-fabric-5"; +const char AmebaConfig::kConfigNamespace_ChipACL[] = "chip-acl"; +const char AmebaConfig::kConfigNamespace_ChipGroupMsgCounters[] = "chip-groupmsgcounters"; +const char AmebaConfig::kConfigNamespace_ChipAttributes[] = "chip-attributes"; +const char AmebaConfig::kConfigNamespace_ChipBindingTable[] = "chip-bindingtable"; +const char AmebaConfig::kConfigNamespace_ChipOTA[] = "chip-ota"; +const char AmebaConfig::kConfigNamespace_ChipDNS[] = "chip-dns"; +const char AmebaConfig::kConfigNamespace_ChipOthers[] = "chip-others"; // Keys stored in the chip-factory namespace const AmebaConfig::Key AmebaConfig::kConfigKey_SerialNum = { kConfigNamespace_ChipFactory, "serial-num" };