From b9d525e46abadef4d70b888bd454de08e47d9dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20Ba=C5=82ys?= Date: Thu, 19 Oct 2023 19:28:46 +0200 Subject: [PATCH] Add handling a local lock operation error to door-lock-server (#29857) The current implementation of the door-lock server supports emitting the LockOperationEvent only if the credential has been provided remotely. In case we use a custom handling lock credential in the application code the event is emitted only on the correct credential, but we also need a mechanism that allows the door lock server to handle a lock operation error when the wrong credential has been provided. Added handling local lock operation error to emit LockOperationEvent and call HandleWrongCodeEntry. --- .../clusters/door-lock-server/door-lock-server.cpp | 12 ++++++++++++ .../clusters/door-lock-server/door-lock-server.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+) 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 01edd3f1b60253..7552841edfb5e6 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -202,6 +202,18 @@ bool DoorLockServer::SetPrivacyModeButton(chip::EndpointId endpointId, bool isEn return SetAttribute(endpointId, Attributes::EnablePrivacyModeButton::Id, Attributes::EnablePrivacyModeButton::Set, isEnabled); } +void DoorLockServer::HandleLocalLockOperationError(chip::EndpointId endpointId, LockOperationTypeEnum opType, + OperationSourceEnum opSource, Nullable userId) +{ + SendLockOperationEvent(endpointId, opType, opSource, OperationErrorEnum::kInvalidCredential, userId, + Nullable(), Nullable(), Nullable>(), + false); + + HandleWrongCodeEntry(endpointId); + + ChipLogProgress(Zcl, "Handling a local Lock Operation Error: [endpoint=%d, user=%d]", endpointId, userId.Value()); +} + bool DoorLockServer::HandleWrongCodeEntry(chip::EndpointId endpointId) { auto endpointContext = getContext(endpointId); 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 70988c17786964..a8007f211641a4 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -228,6 +228,20 @@ class DoorLockServer */ void ResetWrongCodeEntryAttempts(chip::EndpointId endpointId); + /** + * @brief Handles a local lock operation error. This method allows handling a wrong attempt of providing + * user credential entry that has been provided locally by the user. The method will emit the LockOperationEvent + * to inform the controller that a local wrong attempt occurred, and also call HandleWrongEntry method to + * increment wrong entry counter. + * + * @param endpointId + * @param opType Operation source to be registered in the LockOperationEvent. + * @param opSource source of the operation to be registered in the LockOperationEvent. + * @param userId Optional user id to be registered in the LockOperationEvent + */ + void HandleLocalLockOperationError(chip::EndpointId endpointId, LockOperationTypeEnum opType, OperationSourceEnum opSource, + Nullable userId); + private: chip::FabricIndex getFabricIndex(const chip::app::CommandHandler * commandObj); chip::NodeId getNodeId(const chip::app::CommandHandler * commandObj);