diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index 407afc0af5f001..ad201e78cf7d2f 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -1353,12 +1353,13 @@ bool DoorLockServer::OnFabricRemoved(chip::EndpointId endpointId, chip::FabricIn ChipLogProgress(Zcl, "[OnFabricRemoved] Handling a fabric removal from the door lock server [endpointId=%d,fabricIndex=%d]", endpointId, fabricIndex); + bool status{ true }; // Iterate over all the users and clean up the deleted fabric if (!clearFabricFromUsers(endpointId, fabricIndex)) { ChipLogError(Zcl, "[OnFabricRemoved] Unable to cleanup fabric from users - internal error [endpointId=%d,fabricIndex=%d]", endpointId, fabricIndex); - return false; + status = false; } // Iterate over all the credentials and clean up the fabrics @@ -1367,10 +1368,15 @@ bool DoorLockServer::OnFabricRemoved(chip::EndpointId endpointId, chip::FabricIn ChipLogError(Zcl, "[OnFabricRemoved] Unable to cleanup fabric from credentials - internal error [endpointId=%d,fabricIndex=%d]", endpointId, fabricIndex); - return false; + status = false; } - return true; + if (mOnFabricRemovedCustomCallback) + { + mOnFabricRemovedCustomCallback(endpointId, fabricIndex); + } + + return status; } /********************************************************** diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index 72492843bb1b44..212c374077298f 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -93,7 +93,8 @@ class DoorLockServer public: static DoorLockServer & Instance(); - using Feature = chip::app::Clusters::DoorLock::Feature; + using Feature = chip::app::Clusters::DoorLock::Feature; + using OnFabricRemovedCustomCallback = void (*)(chip::EndpointId endpointId, chip::FabricIndex fabricIndex); void InitServer(chip::EndpointId endpointId); @@ -202,6 +203,18 @@ class DoorLockServer inline bool SupportsUnbolt(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kUnbolt); } + /** + * @brief Allows the application to register a custom callback which will be called after the default DoorLock + * OnFabricRemoved implementation. At that point the door lock cluster has done any + * spec-required clearing of state for fabric removal. + * + * @param callback callback to be registered + */ + inline void SetOnFabricRemovedCustomCallback(OnFabricRemovedCustomCallback callback) + { + mOnFabricRemovedCustomCallback = callback; + } + bool OnFabricRemoved(chip::EndpointId endpointId, chip::FabricIndex fabricIndex); static void DoorLockOnAutoRelockCallback(chip::System::Layer *, void * callbackContext); @@ -580,6 +593,8 @@ class DoorLockServer std::array mEndpointCtx; + OnFabricRemovedCustomCallback mOnFabricRemovedCustomCallback{ nullptr }; + static DoorLockServer instance; };