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

Test for Removing Thread credentials after last fabric remove #174

Closed
wants to merge 1 commit into from

Conversation

ArekBalysNordic
Copy link
Owner

  1. Commission to the Matter Network
  2. chiptool_ncs operationalcredentials remove-fabric 2 1 0

@@ -67,7 +69,6 @@ class AppTask
static void FunctionHandler(const AppEvent & event);
static void StartBLEAdvertisementAndLockActionEventHandler(const AppEvent & event);
static void LockActionEventHandler(const AppEvent & event);
static void StartBLEAdvertisementHandler(const AppEvent & event);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to make FabricTableDelegate a friend of AppTask instead of moving this method to public.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, great point :)

if (Server::GetInstance().GetFabricTable().FabricCount() == 0)
{
#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
Server::GetInstance().ScheduleFactoryReset();
Copy link
Collaborator

@kkasperczyk-no kkasperczyk-no Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the best from the Matter perspective would be to modify the ScheduleFactoryReset to do not call Shutdown always, but only in case configuration requires it. It could be controlled e.g. using some Matter define, then set by us using Kconfig. This way we would avoid duplicating the code here and re-use what currently exist.
Nevertheless such implementation would mean everyone get our fix for free, so I can understand if we do not want to do that.

#elif defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_ONLY) || defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START)
DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) {
// Delete all fabrics and emit Leave event.
Server::GetInstance().GetFabricTable().DeleteAllFabrics();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it delete all fabrics from RAM? Does it make sense assuming we already have FabricCount() == 0?

/* Erase Matter data */
DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().DoFactoryReset();
/* Erase Thread credentials and disconnect */
DeviceLayer::ConnectivityMgr().ErasePersistentInfo();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we call ClearWiFiStationProvision() for WiFi devices? Currently this method only clears the cached network configuration but I suppose we can extend it so that the station is disconnected from AP.

Copy link
Collaborator

@LuDuda LuDuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Some questions below.

After removing the last fabric the device will perform the factory reset only without
rebooting. The current RAM state will be saved and the new commissioning to the next
fabric will use the next possible fabric index.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what about a case, where user would like to persist Thread Credentials (aka < NCS 2.5.0)? We could introduce a new option like: CHIP_LAST_FABRIC_REMOVED_NONE to keep pre NCS 2.5.0 behavior, but more important to enable customers to implement custom way of handling it.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add something like that :)

Server::GetInstance().GetFabricTable().DeleteAllFabrics();
/* Erase Matter data */
DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().DoFactoryReset();
/* Erase Thread credentials and disconnect */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thread... and Wi-Fi right?

@@ -212,6 +213,7 @@ CHIP_ERROR AppTask::Init()
(void) initParams.InitializeStaticResourcesBeforeServerInit();
initParams.testEventTriggerDelegate = &testEventTriggerDelegate;
ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams));
AppFabricTableDelegate::Init();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe planned.. but we should do it for all the samples.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course, this draft points only to the Lock to be clearer for the review :)

if (Server::GetInstance().GetFabricTable().FabricCount() == 0)
{
#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
Server::GetInstance().ScheduleFactoryReset();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I heard from Eve that calling FactoryReset immediately does not work. That 3 seconds delay is necessary. We don't see such an issue?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't call factory reset immediately, but schedule it to call within the CHIP thread. If I called it immediately in this method, that was true, and the device couldn't send ack to the chip controller. Postponing it to the CHIP thread seems to resolve that problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants