Skip to content

Commit

Permalink
[Silabs] Add support for factory and commissionable data provisioning…
Browse files Browse the repository at this point in the history
… with the use… (project-chip#34087)

* Add support factory and commissionable data provisioning with the use of librairies

* Restyled by clang-format

* remove files that are now used

* fix for wifi ncp build

* address comments

* fixup include path

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and austina-csa committed Jul 10, 2024
1 parent 77957b4 commit 2057bd0
Show file tree
Hide file tree
Showing 30 changed files with 2,523 additions and 866 deletions.
13 changes: 10 additions & 3 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@
#include "AppConfig.h"
#include "AppEvent.h"
#include "AppTask.h"

#include <app/server/Server.h>

#define APP_ACTION_BUTTON 1

#ifdef DISPLAY_ENABLED
#include "lcd.h"
#ifdef QR_CODE_ENABLED
#include "qrcodegen.h"
#endif // QR_CODE_ENABLED
#endif // DISPLAY_ENABLED

#include "SilabsDeviceDataProvider.h"
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
#include <app/icd/server/ICDNotifier.h> // nogncheck
#endif
#include <ProvisionManager.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/util/attribute-storage.h>
#include <assert.h>
Expand Down Expand Up @@ -744,6 +745,11 @@ void BaseApplication::DispatchEvent(AppEvent * aEvent)
void BaseApplication::ScheduleFactoryReset()
{
PlatformMgr().ScheduleWork([](intptr_t) {
// Press both buttons to request provisioning
if (GetPlatform().GetButtonState(APP_ACTION_BUTTON))
{
Provision::Manager::GetInstance().SetProvisionRequired(true);
}
PlatformMgr().HandleServerShuttingDown();
ConfigurationMgr().InitiateFactoryReset();
});
Expand All @@ -765,7 +771,8 @@ void BaseApplication::OutputQrCode(bool refreshLCD)
char setupPayloadBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1];
chip::MutableCharSpan setupPayload(setupPayloadBuffer);

if (Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(setupPayload) == CHIP_NO_ERROR)
CHIP_ERROR err = Provision::Manager::GetInstance().GetStorage().GetSetupPayload(setupPayload);
if (CHIP_NO_ERROR == err)
{
// Print setup info on LCD if available
#ifdef QR_CODE_ENABLED
Expand Down
16 changes: 8 additions & 8 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeystore;
#endif

#include "SilabsDeviceDataProvider.h"
#include <ProvisionManager.h>
#include <app/InteractionModelEngine.h>
#include <app/TimerDelegates.h>

Expand All @@ -80,8 +80,6 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys

#include <DeviceInfoProviderImpl.h>
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <examples/platform/silabs/SilabsDeviceAttestationCreds.h>

#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

Expand All @@ -92,7 +90,7 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys
using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;
using namespace ::chip::Credentials::Silabs;
using namespace ::chip::Credentials;
using namespace chip::DeviceLayer::Silabs;

#if CHIP_ENABLE_OPENTHREAD
Expand Down Expand Up @@ -174,7 +172,7 @@ void ApplicationStart(void * unused)

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Credentials::Silabs::GetSilabsDacProvider());
SetDeviceAttestationCredentialsProvider(&Provision::Manager::GetInstance().GetStorage());
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

SILABS_LOG("Starting App Task");
Expand All @@ -190,7 +188,6 @@ void ApplicationStart(void * unused)
void SilabsMatterConfig::AppInit()
{
GetPlatform().Init();

sMainTaskHandle = osThreadNew(ApplicationStart, nullptr, &kMainTaskAttr);
SILABS_LOG("Starting scheduler");
VerifyOrDie(sMainTaskHandle); // We can't proceed if the Main Task creation failed.
Expand Down Expand Up @@ -257,8 +254,11 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)

ReturnErrorOnFailure(PlatformMgr().InitChipStack());

SetDeviceInstanceInfoProvider(&Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider());
SetCommissionableDataProvider(&Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider());
// Provision Manager
Silabs::Provision::Manager & provision = Silabs::Provision::Manager::GetInstance();
ReturnErrorOnFailure(provision.Init());
SetDeviceInstanceInfoProvider(&provision.GetStorage());
SetCommissionableDataProvider(&provision.GetStorage());

chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName(appName);

Expand Down
54 changes: 5 additions & 49 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ source_set("test-event-trigger") {
"${silabs_common_plat_dir}/SilabsTestEventTriggerDelegate.h",
]

deps = [ "${chip_root}/src/platform/silabs/provision:provision-headers" ]
public_configs = [ ":test-event-trigger-config" ]

public_deps = [
":silabs-factory-data-provider",
"${chip_root}/src/app:test-event-trigger",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
Expand All @@ -114,46 +113,9 @@ source_set("siwx917-matter-shell") {
}
}

config("attestation-credentials-config") {
include_dirs = [ "${chip_root}" ]
}

source_set("siwx917-attestation-credentials") {
sources = [
"${silabs_common_plat_dir}/SilabsDeviceAttestationCreds.cpp",
"${silabs_common_plat_dir}/SilabsDeviceAttestationCreds.h",
]

public_deps = [
"${chip_root}/src/credentials",
"${chip_root}/src/platform:platform_base",
]

public_configs = [ ":attestation-credentials-config" ]
}

source_set("silabs-factory-data-provider") {
sources = [
"${silabs_common_plat_dir}/SilabsDeviceDataProvider.cpp",
"${silabs_common_plat_dir}/SilabsDeviceDataProvider.h",
]

public_deps = [
"${chip_root}/src/credentials",
"${chip_root}/src/lib/support",
"${chip_root}/src/platform:platform_base",
"${chip_root}/src/setup_payload",
]

public_configs = [ ":siwx917-common-config" ]

if (sl_enable_test_event_trigger) {
public_configs += [ ":test-event-trigger-config" ]
}
}

config("siwx917-common-config") {
defines = [ "OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout_sec}" ]
libs = [ "${sdk_support_root}/matter/provision/lib/libProvision_si917.a" ]

if (!disable_lcd) {
include_dirs = [ "${silabs_common_plat_dir}/display" ]
Expand Down Expand Up @@ -210,7 +172,7 @@ config("silabs-wifi-config") {
}

source_set("siwx917-common") {
deps = []
deps = [ "${chip_root}/src/platform/silabs/provision:provision-headers" ]
defines = []
public_deps = []
public_configs = [
Expand All @@ -229,6 +191,8 @@ source_set("siwx917-common") {
"${silabs_common_plat_dir}/LEDWidget.cpp",
"${silabs_common_plat_dir}/MatterConfig.cpp",
"${silabs_common_plat_dir}/SoftwareFaultReports.cpp",
"${silabs_common_plat_dir}/provision/ProvisionStorageCustom.cpp",
"${silabs_common_plat_dir}/provision/ProvisionStorageFlash.cpp",
"${silabs_common_plat_dir}/silabs_utils.cpp",
"${silabs_common_plat_dir}/syscalls_stubs.cpp",
"${silabs_plat_si91x_wifi_dir}/dhcp_client.cpp",
Expand Down Expand Up @@ -282,14 +246,6 @@ source_set("siwx917-common") {
]
}

# Attestation Credentials
deps += [ ":siwx917-attestation-credentials" ]

# Factory Data Provider
if (use_efr32_factory_data_provider) {
public_deps += [ ":silabs-factory-data-provider" ]
}

public_deps += [
"${chip_root}/examples/providers:device_info_provider",
"${chip_root}/src/lib",
Expand Down
199 changes: 0 additions & 199 deletions examples/platform/silabs/SilabsDeviceAttestationCreds.cpp

This file was deleted.

Loading

0 comments on commit 2057bd0

Please sign in to comment.