From 11399642d8de79f985e1945f70b1289bbf8528b9 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Wed, 12 Apr 2023 21:05:23 +0800 Subject: [PATCH] [factorydata] use example test provider if fail to read factorydata (#25937) - move factorydata init to chipdevicemanager - init factorydata after initchipstack and before ble adv --- config/ameba/chip.cmake | 2 +- .../ameba/main/CHIPDeviceManager.cpp | 19 +++++++++++++++++++ .../ameba/main/chipinterface.cpp | 13 ------------- .../ameba/main/CHIPDeviceManager.cpp | 19 +++++++++++++++++++ .../ameba/main/chipinterface.cpp | 13 ------------- .../ameba/main/CHIPDeviceManager.cpp | 19 +++++++++++++++++++ .../lighting-app/ameba/main/chipinterface.cpp | 13 ------------- .../ameba/main/CHIPDeviceManager.cpp | 19 +++++++++++++++++++ .../ameba/main/chipinterface.cpp | 13 ------------- 9 files changed, 77 insertions(+), 53 deletions(-) diff --git a/config/ameba/chip.cmake b/config/ameba/chip.cmake index 8de905ae3a9a95..d221ab57352f94 100644 --- a/config/ameba/chip.cmake +++ b/config/ameba/chip.cmake @@ -107,7 +107,7 @@ string(APPEND CHIP_GN_ARGS "ameba_cc = \"arm-none-eabi-gcc\"\n") string(APPEND CHIP_GN_ARGS "ameba_cxx = \"arm-none-eabi-c++\"\n") string(APPEND CHIP_GN_ARGS "ameba_cpu = \"ameba\"\n") string(APPEND CHIP_GN_ARGS "chip_inet_config_enable_ipv4 = false\n") -string(APPEND CHIP_GN_ARGS "chip_use_transitional_commissionable_data_provider = false\n") +string(APPEND CHIP_GN_ARGS "chip_use_transitional_commissionable_data_provider = true\n") # Enable persistent storage audit if (matter_enable_persistentstorage_audit) diff --git a/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp b/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp index 4c1b55fbddb9fc..d0db78341501a5 100644 --- a/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp +++ b/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp @@ -28,11 +28,15 @@ #include "CHIPDeviceManager.h" #include #include +#include +#include +#include #include #include #include using namespace ::chip; +using namespace ::chip::Credentials; namespace chip { @@ -40,6 +44,8 @@ namespace DeviceManager { using namespace ::chip::DeviceLayer; +chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; + void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg) { CHIPDeviceManagerCallbacks * cb = reinterpret_cast(arg); @@ -61,6 +67,19 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb) err = PlatformMgr().InitChipStack(); SuccessOrExit(err); + err = mFactoryDataProvider.Init(); + if (err == CHIP_NO_ERROR) + { + SetCommissionableDataProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + } + else + { + ChipLogProgress(DeviceLayer, "Using example DAC provider"); + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); + } + if (CONFIG_NETWORK_LAYER_BLE) { ConnectivityMgr().SetBLEAdvertisingEnabled(true); diff --git a/examples/all-clusters-app/ameba/main/chipinterface.cpp b/examples/all-clusters-app/ameba/main/chipinterface.cpp index c0e918e2082a86..c8b2e9a4333e14 100644 --- a/examples/all-clusters-app/ameba/main/chipinterface.cpp +++ b/examples/all-clusters-app/ameba/main/chipinterface.cpp @@ -31,11 +31,8 @@ #include #include #include -#include -#include #include #include -#include #include #include #include @@ -51,7 +48,6 @@ #endif using namespace ::chip; -using namespace ::chip::Credentials; using namespace ::chip::DeviceManager; using namespace ::chip::DeviceLayer; using namespace ::chip::System; @@ -122,7 +118,6 @@ Identify gIdentify1 = { static DeviceCallbacks EchoCallbacks; chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; -chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; static void InitServer(intptr_t context) { @@ -158,10 +153,6 @@ extern "C" void ChipTest(void) initPref(); - mFactoryDataProvider.Init(); - SetCommissionableDataProvider(&mFactoryDataProvider); - SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); - CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance(); err = deviceMgr.Init(&EchoCallbacks); @@ -170,10 +161,6 @@ extern "C" void ChipTest(void) ChipLogError(DeviceLayer, "DeviceManagerInit() - ERROR!\r\n"); } - // Set DeviceInstanceInfoProvider after CHIPDeviceManager init - // CHIPDeviceManager init will set GenericDeviceInsanceInfoProvider first - SetDeviceInstanceInfoProvider(&mFactoryDataProvider); - chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, 0); statusLED1.Init(STATUS_LED_GPIO_NUM); diff --git a/examples/light-switch-app/ameba/main/CHIPDeviceManager.cpp b/examples/light-switch-app/ameba/main/CHIPDeviceManager.cpp index 4c1b55fbddb9fc..d0db78341501a5 100644 --- a/examples/light-switch-app/ameba/main/CHIPDeviceManager.cpp +++ b/examples/light-switch-app/ameba/main/CHIPDeviceManager.cpp @@ -28,11 +28,15 @@ #include "CHIPDeviceManager.h" #include #include +#include +#include +#include #include #include #include using namespace ::chip; +using namespace ::chip::Credentials; namespace chip { @@ -40,6 +44,8 @@ namespace DeviceManager { using namespace ::chip::DeviceLayer; +chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; + void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg) { CHIPDeviceManagerCallbacks * cb = reinterpret_cast(arg); @@ -61,6 +67,19 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb) err = PlatformMgr().InitChipStack(); SuccessOrExit(err); + err = mFactoryDataProvider.Init(); + if (err == CHIP_NO_ERROR) + { + SetCommissionableDataProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + } + else + { + ChipLogProgress(DeviceLayer, "Using example DAC provider"); + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); + } + if (CONFIG_NETWORK_LAYER_BLE) { ConnectivityMgr().SetBLEAdvertisingEnabled(true); diff --git a/examples/light-switch-app/ameba/main/chipinterface.cpp b/examples/light-switch-app/ameba/main/chipinterface.cpp index 85e4c401514d99..7bc5c3efae4416 100644 --- a/examples/light-switch-app/ameba/main/chipinterface.cpp +++ b/examples/light-switch-app/ameba/main/chipinterface.cpp @@ -31,11 +31,8 @@ #include #include #include -#include -#include #include #include -#include #include #include #include @@ -51,7 +48,6 @@ #endif using namespace ::chip; -using namespace ::chip::Credentials; using namespace ::chip::DeviceManager; using namespace ::chip::DeviceLayer; using namespace ::chip::System; @@ -97,7 +93,6 @@ Identify gIdentify1 = { static DeviceCallbacks EchoCallbacks; chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; -chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; static void InitServer(intptr_t context) { @@ -132,10 +127,6 @@ extern "C" void ChipTest(void) initPref(); - mFactoryDataProvider.Init(); - SetCommissionableDataProvider(&mFactoryDataProvider); - SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); - CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance(); err = deviceMgr.Init(&EchoCallbacks); @@ -148,10 +139,6 @@ extern "C" void ChipTest(void) ChipLogProgress(DeviceLayer, "DeviceManagerInit() - OK\r\n"); } - // Set DeviceInstanceInfoProvider after CHIPDeviceManager init - // CHIPDeviceManager init will set GenericDeviceInsanceInfoProvider first - SetDeviceInstanceInfoProvider(&mFactoryDataProvider); - chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, 0); statusLED1.Init(STATUS_LED_GPIO_NUM); diff --git a/examples/lighting-app/ameba/main/CHIPDeviceManager.cpp b/examples/lighting-app/ameba/main/CHIPDeviceManager.cpp index 98c148f505ed31..01931850922b4c 100644 --- a/examples/lighting-app/ameba/main/CHIPDeviceManager.cpp +++ b/examples/lighting-app/ameba/main/CHIPDeviceManager.cpp @@ -26,6 +26,9 @@ #include "CHIPDeviceManager.h" #include +#include +#include +#include #include #include #include @@ -41,6 +44,7 @@ #include using namespace ::chip; +using namespace ::chip::Credentials; namespace chip { @@ -48,6 +52,8 @@ namespace DeviceManager { using namespace ::chip::DeviceLayer; +chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; + void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg) { CHIPDeviceManagerCallbacks * cb = reinterpret_cast(arg); @@ -68,6 +74,19 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb) err = PlatformMgr().InitChipStack(); SuccessOrExit(err); + err = mFactoryDataProvider.Init(); + if (err == CHIP_NO_ERROR) + { + SetCommissionableDataProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + } + else + { + ChipLogProgress(DeviceLayer, "Using example DAC provider"); + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); + } + if (CONFIG_NETWORK_LAYER_BLE) { ConnectivityMgr().SetBLEAdvertisingEnabled(true); diff --git a/examples/lighting-app/ameba/main/chipinterface.cpp b/examples/lighting-app/ameba/main/chipinterface.cpp index f46fe7ad320557..e9ef017c97861a 100644 --- a/examples/lighting-app/ameba/main/chipinterface.cpp +++ b/examples/lighting-app/ameba/main/chipinterface.cpp @@ -25,8 +25,6 @@ #include #include "chip_porting.h" -#include -#include #include #include @@ -36,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -49,7 +46,6 @@ #endif using namespace ::chip; -using namespace ::chip::Credentials; using namespace ::chip::DeviceManager; using namespace ::chip::DeviceLayer; using namespace ::chip::System; @@ -81,7 +77,6 @@ void NetWorkCommissioningInstInit() static DeviceCallbacks EchoCallbacks; chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; -chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; void OnIdentifyStart(Identify *) { @@ -148,10 +143,6 @@ extern "C" void ChipTest(void) initPref(); - mFactoryDataProvider.Init(); - SetCommissionableDataProvider(&mFactoryDataProvider); - SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); - CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance(); err = deviceMgr.Init(&EchoCallbacks); @@ -164,10 +155,6 @@ extern "C" void ChipTest(void) ChipLogProgress(DeviceLayer, "DeviceManagerInit() - OK\r\n"); } - // Set DeviceInstanceInfoProvider after CHIPDeviceManager init - // CHIPDeviceManager init will set GenericDeviceInsanceInfoProvider first - SetDeviceInstanceInfoProvider(&mFactoryDataProvider); - chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, 0); statusLED1.Init(STATUS_LED_GPIO_NUM); diff --git a/examples/ota-requestor-app/ameba/main/CHIPDeviceManager.cpp b/examples/ota-requestor-app/ameba/main/CHIPDeviceManager.cpp index 4c1b55fbddb9fc..d0db78341501a5 100644 --- a/examples/ota-requestor-app/ameba/main/CHIPDeviceManager.cpp +++ b/examples/ota-requestor-app/ameba/main/CHIPDeviceManager.cpp @@ -28,11 +28,15 @@ #include "CHIPDeviceManager.h" #include #include +#include +#include +#include #include #include #include using namespace ::chip; +using namespace ::chip::Credentials; namespace chip { @@ -40,6 +44,8 @@ namespace DeviceManager { using namespace ::chip::DeviceLayer; +chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; + void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg) { CHIPDeviceManagerCallbacks * cb = reinterpret_cast(arg); @@ -61,6 +67,19 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb) err = PlatformMgr().InitChipStack(); SuccessOrExit(err); + err = mFactoryDataProvider.Init(); + if (err == CHIP_NO_ERROR) + { + SetCommissionableDataProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + } + else + { + ChipLogProgress(DeviceLayer, "Using example DAC provider"); + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); + } + if (CONFIG_NETWORK_LAYER_BLE) { ConnectivityMgr().SetBLEAdvertisingEnabled(true); diff --git a/examples/ota-requestor-app/ameba/main/chipinterface.cpp b/examples/ota-requestor-app/ameba/main/chipinterface.cpp index 2dd76a6dba308b..ee8e80086fbca4 100644 --- a/examples/ota-requestor-app/ameba/main/chipinterface.cpp +++ b/examples/ota-requestor-app/ameba/main/chipinterface.cpp @@ -25,12 +25,9 @@ #include #include #include -#include -#include #include #include -#include #include #include #include @@ -51,7 +48,6 @@ using namespace chip::Messaging; using namespace chip::app::Clusters::OtaSoftwareUpdateProvider::Commands; using namespace ::chip; -using namespace ::chip::Credentials; using namespace ::chip::DeviceManager; using namespace ::chip::DeviceLayer; @@ -74,7 +70,6 @@ void NetWorkCommissioningInstInit() static DeviceCallbacks EchoCallbacks; chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; -chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; static void InitServer(intptr_t context) { @@ -95,10 +90,6 @@ extern "C" void ChipTest(void) initPref(); - mFactoryDataProvider.Init(); - SetCommissionableDataProvider(&mFactoryDataProvider); - SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); - CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance(); err = deviceMgr.Init(&EchoCallbacks); if (err != CHIP_NO_ERROR) @@ -110,9 +101,5 @@ extern "C" void ChipTest(void) ChipLogProgress(DeviceLayer, "DeviceManagerInit() - OK\r\n"); } - // Set DeviceInstanceInfoProvider after CHIPDeviceManager init - // CHIPDeviceManager init will set GenericDeviceInsanceInfoProvider first - SetDeviceInstanceInfoProvider(&mFactoryDataProvider); - chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, 0); }