Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ameba] use example test provider if fail to read factorydata #25937

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/ameba/chip.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,24 @@
#include "CHIPDeviceManager.h"
#include <app/ConcreteAttributePath.h>
#include <app/util/basic-types.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <platform/Ameba/FactoryDataProvider.h>
#include <support/CHIPMem.h>
#include <support/CodeUtils.h>
#include <support/ErrorStr.h>

using namespace ::chip;
using namespace ::chip::Credentials;

namespace chip {

namespace DeviceManager {

using namespace ::chip::DeviceLayer;

chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider;

void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg)
{
CHIPDeviceManagerCallbacks * cb = reinterpret_cast<CHIPDeviceManagerCallbacks *>(arg);
Expand All @@ -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);
Expand Down
13 changes: 0 additions & 13 deletions examples/all-clusters-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/af.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <lib/support/ErrorStr.h>
#include <platform/Ameba/AmebaConfig.h>
#include <platform/Ameba/FactoryDataProvider.h>
#include <platform/Ameba/NetworkCommissioningDriver.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
Expand All @@ -51,7 +48,6 @@
#endif

using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;
using namespace ::chip::System;
Expand Down Expand Up @@ -122,7 +118,6 @@ Identify gIdentify1 = {

static DeviceCallbacks EchoCallbacks;
chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider;

static void InitServer(intptr_t context)
{
Expand Down Expand Up @@ -158,10 +153,6 @@ extern "C" void ChipTest(void)

initPref();

mFactoryDataProvider.Init();
SetCommissionableDataProvider(&mFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider);

CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance();

err = deviceMgr.Init(&EchoCallbacks);
Expand All @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions examples/light-switch-app/ameba/main/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,24 @@
#include "CHIPDeviceManager.h"
#include <app/ConcreteAttributePath.h>
#include <app/util/basic-types.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <platform/Ameba/FactoryDataProvider.h>
#include <support/CHIPMem.h>
#include <support/CodeUtils.h>
#include <support/ErrorStr.h>

using namespace ::chip;
using namespace ::chip::Credentials;

namespace chip {

namespace DeviceManager {

using namespace ::chip::DeviceLayer;

chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider;

void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg)
{
CHIPDeviceManagerCallbacks * cb = reinterpret_cast<CHIPDeviceManagerCallbacks *>(arg);
Expand All @@ -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);
Expand Down
13 changes: 0 additions & 13 deletions examples/light-switch-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/af.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <lib/support/ErrorStr.h>
#include <platform/Ameba/AmebaConfig.h>
#include <platform/Ameba/FactoryDataProvider.h>
#include <platform/Ameba/NetworkCommissioningDriver.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
Expand All @@ -51,7 +48,6 @@
#endif

using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;
using namespace ::chip::System;
Expand Down Expand Up @@ -97,7 +93,6 @@ Identify gIdentify1 = {

static DeviceCallbacks EchoCallbacks;
chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider;

static void InitServer(intptr_t context)
{
Expand Down Expand Up @@ -132,10 +127,6 @@ extern "C" void ChipTest(void)

initPref();

mFactoryDataProvider.Init();
SetCommissionableDataProvider(&mFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider);

CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance();

err = deviceMgr.Init(&EchoCallbacks);
Expand All @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions examples/lighting-app/ameba/main/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

#include "CHIPDeviceManager.h"
#include <app/util/basic-types.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <platform/Ameba/FactoryDataProvider.h>
#include <support/CHIPMem.h>
#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
Expand All @@ -41,13 +44,16 @@
#include <app/util/util.h>

using namespace ::chip;
using namespace ::chip::Credentials;

namespace chip {

namespace DeviceManager {

using namespace ::chip::DeviceLayer;

chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider;

void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg)
{
CHIPDeviceManagerCallbacks * cb = reinterpret_cast<CHIPDeviceManagerCallbacks *>(arg);
Expand All @@ -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);
Expand Down
13 changes: 0 additions & 13 deletions examples/lighting-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include <DeviceInfoProviderImpl.h>

#include "chip_porting.h"
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <platform/CHIPDeviceLayer.h>
#include <support/CHIPMem.h>

Expand All @@ -36,7 +34,6 @@
#include <app/util/af.h>
#include <lib/support/ErrorStr.h>
#include <platform/Ameba/AmebaConfig.h>
#include <platform/Ameba/FactoryDataProvider.h>
#include <platform/Ameba/NetworkCommissioningDriver.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
Expand All @@ -49,7 +46,6 @@
#endif

using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;
using namespace ::chip::System;
Expand Down Expand Up @@ -81,7 +77,6 @@ void NetWorkCommissioningInstInit()

static DeviceCallbacks EchoCallbacks;
chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider;

void OnIdentifyStart(Identify *)
{
Expand Down Expand Up @@ -148,10 +143,6 @@ extern "C" void ChipTest(void)

initPref();

mFactoryDataProvider.Init();
SetCommissionableDataProvider(&mFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider);

CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance();

err = deviceMgr.Init(&EchoCallbacks);
Expand All @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions examples/ota-requestor-app/ameba/main/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,24 @@
#include "CHIPDeviceManager.h"
#include <app/ConcreteAttributePath.h>
#include <app/util/basic-types.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <platform/Ameba/FactoryDataProvider.h>
#include <support/CHIPMem.h>
#include <support/CodeUtils.h>
#include <support/ErrorStr.h>

using namespace ::chip;
using namespace ::chip::Credentials;

namespace chip {

namespace DeviceManager {

using namespace ::chip::DeviceLayer;

chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider;

void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg)
{
CHIPDeviceManagerCallbacks * cb = reinterpret_cast<CHIPDeviceManagerCallbacks *>(arg);
Expand All @@ -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);
Expand Down
13 changes: 0 additions & 13 deletions examples/ota-requestor-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/server/Server.h>
#include <app/util/af.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

#include <lib/support/ErrorStr.h>
#include <platform/Ameba/AmebaConfig.h>
#include <platform/Ameba/FactoryDataProvider.h>
#include <platform/Ameba/NetworkCommissioningDriver.h>
#include <platform/CHIPDeviceLayer.h>
#include <support/CHIPMem.h>
Expand All @@ -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;

Expand All @@ -74,7 +70,6 @@ void NetWorkCommissioningInstInit()

static DeviceCallbacks EchoCallbacks;
chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider;

static void InitServer(intptr_t context)
{
Expand All @@ -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)
Expand All @@ -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);
}