-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
#include "AppTask.h" | ||
#include "AppConfig.h" | ||
#include "BoltLockManager.h" | ||
#include "FabricTableDelegate.h" | ||
#include "LEDUtil.h" | ||
#include "LEDWidget.h" | ||
|
||
|
@@ -212,6 +213,7 @@ CHIP_ERROR AppTask::Init() | |
(void) initParams.InitializeStaticResourcesBeforeServerInit(); | ||
initParams.testEventTriggerDelegate = &testEventTriggerDelegate; | ||
ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); | ||
AppFabricTableDelegate::Init(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe planned.. but we should do it for all the samples. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) |
||
|
||
gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); | ||
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,8 @@ class AppTask | |
static void IdentifyStartHandler(Identify *); | ||
static void IdentifyStopHandler(Identify *); | ||
|
||
static void StartBLEAdvertisementHandler(const AppEvent & event); | ||
|
||
private: | ||
CHIP_ERROR Init(); | ||
|
||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would be better to make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, great point :) |
||
static void UpdateLedStateEventHandler(const AppEvent & event); | ||
|
||
static void ChipEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "AppTask.h" | ||
|
||
#include <app/server/Server.h> | ||
#include <app/util/attribute-storage.h> | ||
|
||
namespace chip { | ||
|
||
class AppFabricTableDelegate : public FabricTable::Delegate | ||
{ | ||
public: | ||
~AppFabricTableDelegate() { Server::GetInstance().GetFabricTable().RemoveFabricDelegate(this); } | ||
|
||
static void Init() | ||
{ | ||
static AppFabricTableDelegate sAppFabricDelegate; | ||
Server::GetInstance().GetFabricTable().AddFabricDelegate(&sAppFabricDelegate); | ||
} | ||
|
||
private: | ||
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) | ||
{ | ||
if (Server::GetInstance().GetFabricTable().FabricCount() == 0) | ||
{ | ||
#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT | ||
Server::GetInstance().ScheduleFactoryReset(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO the best from the Matter perspective would be to modify the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
#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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
/* Erase Matter data */ | ||
DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().DoFactoryReset(); | ||
/* Erase Thread credentials and disconnect */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thread... and Wi-Fi right? |
||
DeviceLayer::ConnectivityMgr().ErasePersistentInfo(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we call |
||
#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); | ||
#endif | ||
}); | ||
#endif | ||
} | ||
} | ||
}; | ||
} // namespace chip |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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 :)