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

[nrfconnect] Add a delay to last fabric remove action #29844

Merged
merged 1 commit into from
Oct 19, 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
9 changes: 9 additions & 0 deletions config/nrfconnect/chip-module/Kconfig.features
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,13 @@ choice CHIP_LAST_FABRIC_REMOVED_ACTION

endchoice

config CHIP_LAST_FABRIC_REMOVED_ACTION_DELAY
int "After removing the last fabric wait defined time [in milliseconds] to perform an action"
depends on !CHIP_LAST_FABRIC_REMOVED_NONE
default 500
help
After removing the last fabric the device will wait for the defined time and then perform
an action chosen by the CHIP_LAST_FABRIC_REMOVED_ACTION option. This schedule will allow for
avoiding race conditions before the device removes non-volatile data.

endif # CHIP
3 changes: 0 additions & 3 deletions examples/all-clusters-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@

struct k_timer;
struct Identify;
class AppFabricTableDelegate;

class AppTask
{
public:
friend class AppFabricTableDelegate;

static AppTask & Instance(void)
{
static AppTask sAppTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@

struct k_timer;
struct Identify;
class AppFabricTableDelegate;

class AppTask
{
public:
friend class AppFabricTableDelegate;

static AppTask & Instance(void)
{
static AppTask sAppTask;
Expand Down
3 changes: 0 additions & 3 deletions examples/light-switch-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@

struct k_timer;
struct Identify;
class AppFabricTableDelegate;

class AppTask
{
public:
friend class AppFabricTableDelegate;

static AppTask & Instance()
{
static AppTask sAppTask;
Expand Down
3 changes: 0 additions & 3 deletions examples/lighting-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@

struct k_timer;
struct Identify;
class AppFabricTableDelegate;

class AppTask
{
public:
friend class AppFabricTableDelegate;

static AppTask & Instance()
{
static AppTask sAppTask;
Expand Down
3 changes: 0 additions & 3 deletions examples/lock-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@

struct k_timer;
struct Identify;
class AppFabricTableDelegate;

class AppTask
{
public:
friend class AppFabricTableDelegate;

static AppTask & Instance()
{
static AppTask sAppTask;
Expand Down
33 changes: 22 additions & 11 deletions examples/platform/nrfconnect/util/include/FabricTableDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

#pragma once

#include "AppTask.h"

#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
#ifdef CONFIG_CHIP_WIFI
Expand All @@ -42,36 +40,49 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
#ifndef CONFIG_CHIP_LAST_FABRIC_REMOVED_NONE
static AppFabricTableDelegate sAppFabricDelegate;
chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sAppFabricDelegate);
k_timer_init(&sFabricRemovedTimer, &OnFabricRemovedTimerCallback, nullptr);
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_NONE
}

private:
void OnFabricRemoved(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex)
{
k_timer_start(&sFabricRemovedTimer, K_MSEC(CONFIG_CHIP_LAST_FABRIC_REMOVED_ACTION_DELAY), K_NO_WAIT);
}

static void OnFabricRemovedTimerCallback(k_timer * timer)
{
#ifndef CONFIG_CHIP_LAST_FABRIC_REMOVED_NONE
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) {
#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
chip::Server::GetInstance().ScheduleFactoryReset();
chip::Server::GetInstance().ScheduleFactoryReset();
#elif defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_ONLY) || defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START)
chip::DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) {
/* Erase Matter data */
// Erase Matter data
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().DoFactoryReset();
/* Erase Network credentials and disconnect */
// Erase Network credentials and disconnect
chip::DeviceLayer::ConnectivityMgr().ErasePersistentInfo();
#ifdef CONFIG_CHIP_WIFI
chip::DeviceLayer::WiFiManager::Instance().Disconnect();
chip::DeviceLayer::ConnectivityMgr().ClearWiFiStationProvision();
#endif
#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START
/* Start the New BLE advertising */
AppEvent event;
event.Handler = AppTask::StartBLEAdvertisementHandler;
AppTask::Instance().PostEvent(event);
// Start the New BLE advertising
if (!chip::DeviceLayer::ConnectivityMgr().IsBLEAdvertisingEnabled())
{
if (CHIP_NO_ERROR == chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow())
{
return;
}
}
ChipLogError(FabricProvisioning, "Could not start Bluetooth LE advertising");
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START
});
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
});
}
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_NONE
}

inline static k_timer sFabricRemovedTimer;
};
3 changes: 0 additions & 3 deletions examples/pump-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@
#endif

struct k_timer;
class AppFabricTableDelegate;

class AppTask
{
public:
friend class AppFabricTableDelegate;

static AppTask & Instance(void)
{
static AppTask sAppTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@
#endif

struct k_timer;
class AppFabricTableDelegate;

class AppTask
{
public:
friend class AppFabricTableDelegate;

static AppTask & Instance(void)
{
static AppTask sAppTask;
Expand Down
3 changes: 0 additions & 3 deletions examples/window-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@

struct k_timer;
struct Identify;
class AppFabricTableDelegate;

class AppTask
{
public:
friend class AppFabricTableDelegate;

static AppTask & Instance(void)
{
static AppTask sAppTask;
Expand Down
Loading