forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nrfconnect] Added erasing network credentials after last fabric remove
Users can decide now what should happen after removing the last fabric: - Do nothing. - Erase the saved network credentials (Thread/WI-FI). - Erase the saved network credentials and start Bluetooth LE advertising. - Erase the saved network credentials and reboot the device.
- Loading branch information
1 parent
6bb0b71
commit 4d9d29c
Showing
18 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
examples/platform/nrfconnect/util/include/FabricTableDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* | ||
* 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() | ||
{ | ||
#ifndef CONFIG_CHIP_LAST_FABRIC_NONE | ||
static AppFabricTableDelegate sAppFabricDelegate; | ||
Server::GetInstance().GetFabricTable().AddFabricDelegate(&sAppFabricDelegate); | ||
#endif // CONFIG_CHIP_LAST_FABRIC_NONE | ||
} | ||
|
||
private: | ||
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) | ||
{ | ||
#ifndef CONFIG_CHIP_LAST_FABRIC_NONE | ||
if (Server::GetInstance().GetFabricTable().FabricCount() == 0) | ||
{ | ||
#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT | ||
Server::GetInstance().ScheduleFactoryReset(); | ||
#elif defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_ONLY) || defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START) | ||
DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) { | ||
/* Erase Matter data */ | ||
DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().DoFactoryReset(); | ||
/* Erase Network credentials and disconnect */ | ||
DeviceLayer::ConnectivityMgr().ErasePersistentInfo(); | ||
DeviceLayer::ConnectivityMgr().ClearWiFiStationProvision(); | ||
#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 // CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START | ||
}); | ||
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT | ||
} | ||
#endif // CONFIG_CHIP_LAST_FABRIC_NONE | ||
} | ||
}; | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters