From 9d0e50521380e835993b522051835a3fdb6e3307 Mon Sep 17 00:00:00 2001 From: Arkadiusz Balys Date: Mon, 9 Oct 2023 12:06:32 +0200 Subject: [PATCH] Add handling a local lock operation error to door-lock-server 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);