From 49ebd08f89b0d83202e99671039053101dcb5da7 Mon Sep 17 00:00:00 2001 From: James Swan <122404367+swan-amazon@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:32:59 +0000 Subject: [PATCH] last fabric --- .../general-commissioning-server.cpp | 34 +++++++++++++++---- .../DefaultTermsAndConditionsProvider.cpp | 2 +- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp index f166852bce10c8..f6ea7fd1294a04 100644 --- a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp +++ b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp @@ -38,6 +38,7 @@ #include #include #include +#include using namespace chip; using namespace chip::app; @@ -477,12 +478,7 @@ void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t } // anonymous namespace -void MatterGeneralCommissioningPluginServerInitCallback() -{ - Breadcrumb::Set(0, 0); - AttributeAccessInterfaceRegistry::Instance().Register(&gAttrAccess); - DeviceLayer::PlatformMgrImpl().AddEventHandler(OnPlatformEventHandler); -} + namespace chip { namespace app { @@ -496,3 +492,29 @@ void SetBreadcrumb(Attributes::Breadcrumb::TypeInfo::Type breadcrumb) } // namespace Clusters } // namespace app } // namespace chip + +class GeneralCommissioningFabricTableDelegate : public chip::FabricTable::Delegate +{ +public: + // Gets called when a fabric is deleted + void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) override + { + // If the FabricIndex matches the last remaining entry in the Fabrics list, then the device SHALL delete all Matter + // related data on the node which was created since it was commissioned. + if (Server::GetInstance().GetFabricTable().FabricCount() == 0) + { + ChipLogProgress(Zcl, "general-commissioning-server: Last Fabric index 0x%x was removed", static_cast(fabricIndex)); + Server::GetInstance().GetTermsAndConditionsProvider()->ResetAcceptance(); + } + } +}; + +void MatterGeneralCommissioningPluginServerInitCallback() +{ + Breadcrumb::Set(0, 0); + AttributeAccessInterfaceRegistry::Instance().Register(&gAttrAccess); + DeviceLayer::PlatformMgrImpl().AddEventHandler(OnPlatformEventHandler); + + static GeneralCommissioningFabricTableDelegate generalCommissioningFabricTableDelegate; + Server::GetInstance().GetFabricTable().AddFabricDelegate(&generalCommissioningFabricTableDelegate); +} diff --git a/src/app/server/DefaultTermsAndConditionsProvider.cpp b/src/app/server/DefaultTermsAndConditionsProvider.cpp index db82433e03c3e5..d00c16d14492cb 100644 --- a/src/app/server/DefaultTermsAndConditionsProvider.cpp +++ b/src/app/server/DefaultTermsAndConditionsProvider.cpp @@ -69,7 +69,7 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::CheckAcceptance(const O // Validate if we have received any terms and conditions acceptance if (!inTermsAndConditions.HasValue()) { - ChipLogError(AppServer, "Failed to HasReceivedTermsAndConditionsAcknowledgements"); + ChipLogError(AppServer, "No terms and conditions have been accepted"); outState = TermsAndConditionsState::TC_ACKNOWLEDGEMENTS_NOT_RECEIVED; return CHIP_NO_ERROR; }