diff --git a/examples/lock-app/lock-common/include/LockEndpoint.h b/examples/lock-app/lock-common/include/LockEndpoint.h index 01b22a12033ab3..6f456c991805ab 100644 --- a/examples/lock-app/lock-common/include/LockEndpoint.h +++ b/examples/lock-app/lock-common/include/LockEndpoint.h @@ -64,12 +64,12 @@ class LockEndpoint inline chip::EndpointId GetEndpointId() const { return mEndpointId; } - bool Lock(const chip::app::CommandHandler * commandObj, const Optional & pin, OperationErrorEnum & err, - OperationSourceEnum opSource); - bool Unlock(const chip::app::CommandHandler * commandObj, const Optional & pin, OperationErrorEnum & err, - OperationSourceEnum opSource); - bool Unbolt(const chip::app::CommandHandler * commandObj, const Optional & pin, OperationErrorEnum & err, - OperationSourceEnum opSource); + bool Lock(const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource); + bool Unlock(const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource); + bool Unbolt(const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource); bool GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) const; bool SetUser(uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, const chip::CharSpan & userName, @@ -101,8 +101,9 @@ class LockEndpoint OperatingModeEnum operatingMode); private: - bool setLockState(const chip::app::CommandHandler * commandObj, DlLockState lockState, const Optional & pin, - OperationErrorEnum & err, OperationSourceEnum opSource = OperationSourceEnum::kUnspecified); + bool setLockState(const Nullable & fabricIdx, const Nullable & nodeId, DlLockState lockState, + const Optional & pin, OperationErrorEnum & err, + OperationSourceEnum opSource = OperationSourceEnum::kUnspecified); const char * lockStateToString(DlLockState lockState) const; bool weekDayScheduleInAction(uint16_t userIndex) const; diff --git a/examples/lock-app/lock-common/include/LockManager.h b/examples/lock-app/lock-common/include/LockManager.h index 728424092bde1e..eea60d568ef06b 100644 --- a/examples/lock-app/lock-common/include/LockManager.h +++ b/examples/lock-app/lock-common/include/LockManager.h @@ -35,12 +35,12 @@ class LockManager bool SendLockAlarm(chip::EndpointId endpointId, AlarmCodeEnum alarmCode); - bool Lock(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, const Optional & pin, - OperationErrorEnum & err, OperationSourceEnum opSource); - bool Unlock(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, const Optional & pin, - OperationErrorEnum & err, OperationSourceEnum opSource); - bool Unbolt(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, const Optional & pin, - OperationErrorEnum & err, OperationSourceEnum opSource); + bool Lock(chip::EndpointId endpointId, const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource); + bool Unlock(chip::EndpointId endpointId, const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource); + bool Unbolt(chip::EndpointId endpointId, const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource); bool GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user); bool SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, diff --git a/examples/lock-app/lock-common/src/LockEndpoint.cpp b/examples/lock-app/lock-common/src/LockEndpoint.cpp index c528024c295b90..8db0f4da97a4bd 100644 --- a/examples/lock-app/lock-common/src/LockEndpoint.cpp +++ b/examples/lock-app/lock-common/src/LockEndpoint.cpp @@ -22,28 +22,28 @@ using chip::to_underlying; using chip::app::DataModel::MakeNullable; -bool LockEndpoint::Lock(const chip::app::CommandHandler * commandObj, const Optional & pin, - OperationErrorEnum & err, OperationSourceEnum opSource) +bool LockEndpoint::Lock(const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource) { - return setLockState(commandObj, DlLockState::kLocked, pin, err, opSource); + return setLockState(fabricIdx, nodeId, DlLockState::kLocked, pin, err, opSource); } -bool LockEndpoint::Unlock(const chip::app::CommandHandler * commandObj, const Optional & pin, - OperationErrorEnum & err, OperationSourceEnum opSource) +bool LockEndpoint::Unlock(const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource) { if (DoorLockServer::Instance().SupportsUnbolt(mEndpointId)) { // If Unbolt is supported Unlock is supposed to pull the latch - setLockState(commandObj, DlLockState::kUnlatched, pin, err, opSource); + setLockState(fabricIdx, nodeId, DlLockState::kUnlatched, pin, err, opSource); } - return setLockState(commandObj, DlLockState::kUnlocked, pin, err, opSource); + return setLockState(fabricIdx, nodeId, DlLockState::kUnlocked, pin, err, opSource); } -bool LockEndpoint::Unbolt(const chip::app::CommandHandler * commandObj, const Optional & pin, - OperationErrorEnum & err, OperationSourceEnum opSource) +bool LockEndpoint::Unbolt(const Nullable & fabricIdx, const Nullable & nodeId, + const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource) { - return setLockState(commandObj, DlLockState::kUnlocked, pin, err, opSource); + return setLockState(fabricIdx, nodeId, DlLockState::kUnlocked, pin, err, opSource); } bool LockEndpoint::GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) const @@ -391,8 +391,9 @@ DlStatus LockEndpoint::SetSchedule(uint8_t holidayIndex, DlScheduleStatus status return DlStatus::kSuccess; } -bool LockEndpoint::setLockState(const chip::app::CommandHandler * commandObj, DlLockState lockState, - const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource) +bool LockEndpoint::setLockState(const Nullable & fabricIdx, const Nullable & nodeId, + DlLockState lockState, const Optional & pin, OperationErrorEnum & err, + OperationSourceEnum opSource) { // Assume pin is required until told otherwise bool requirePin = true; @@ -478,7 +479,7 @@ bool LockEndpoint::setLockState(const chip::app::CommandHandler * commandObj, Dl LockOpCredentials userCredential[] = { { CredentialTypeEnum::kPin, uint16_t(credentialIndex) } }; auto userCredentials = MakeNullable>(userCredential); DoorLockServer::Instance().SetLockState(mEndpointId, mLockState, opSource, MakeNullable(static_cast(userIndex + 1)), - userCredentials, commandObj); + userCredentials, fabricIdx, nodeId); return true; } diff --git a/examples/lock-app/lock-common/src/LockManager.cpp b/examples/lock-app/lock-common/src/LockManager.cpp index 9353a00c411e35..8fd1ef5441b139 100644 --- a/examples/lock-app/lock-common/src/LockManager.cpp +++ b/examples/lock-app/lock-common/src/LockManager.cpp @@ -134,8 +134,9 @@ bool LockManager::SendLockAlarm(chip::EndpointId endpointId, AlarmCodeEnum alarm return lockEndpoint->SendLockAlarm(alarmCode); } -bool LockManager::Lock(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource) +bool LockManager::Lock(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pin, OperationErrorEnum & err, + OperationSourceEnum opSource) { auto lockEndpoint = getEndpoint(endpointId); if (nullptr == lockEndpoint) @@ -143,11 +144,12 @@ bool LockManager::Lock(const chip::app::CommandHandler * commandObj, chip::Endpo ChipLogError(Zcl, "Unable to lock the door - endpoint does not exist or not initialized [endpointId=%d]", endpointId); return false; } - return lockEndpoint->Lock(commandObj, pin, err, opSource); + return lockEndpoint->Lock(fabricIdx, nodeId, pin, err, opSource); } -bool LockManager::Unlock(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource) +bool LockManager::Unlock(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pin, OperationErrorEnum & err, + OperationSourceEnum opSource) { auto lockEndpoint = getEndpoint(endpointId); if (nullptr == lockEndpoint) @@ -155,11 +157,12 @@ bool LockManager::Unlock(const chip::app::CommandHandler * commandObj, chip::End ChipLogError(Zcl, "Unable to unlock the door - endpoint does not exist or not initialized [endpointId=%d]", endpointId); return false; } - return lockEndpoint->Unlock(commandObj, pin, err, opSource); + return lockEndpoint->Unlock(fabricIdx, nodeId, pin, err, opSource); } -bool LockManager::Unbolt(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pin, OperationErrorEnum & err, OperationSourceEnum opSource) +bool LockManager::Unbolt(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pin, OperationErrorEnum & err, + OperationSourceEnum opSource) { auto lockEndpoint = getEndpoint(endpointId); if (nullptr == lockEndpoint) @@ -167,7 +170,7 @@ bool LockManager::Unbolt(const chip::app::CommandHandler * commandObj, chip::End ChipLogError(Zcl, "Unable to unbolt the door - endpoint does not exist or not initialized [endpointId=%d]", endpointId); return false; } - return lockEndpoint->Unbolt(commandObj, pin, err, opSource); + return lockEndpoint->Unbolt(fabricIdx, nodeId, pin, err, opSource); } bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) diff --git a/examples/lock-app/lock-common/src/ZCLDoorLockCallbacks.cpp b/examples/lock-app/lock-common/src/ZCLDoorLockCallbacks.cpp index 2ac632613ab53a..2b649db7443d42 100644 --- a/examples/lock-app/lock-common/src/ZCLDoorLockCallbacks.cpp +++ b/examples/lock-app/lock-common/src/ZCLDoorLockCallbacks.cpp @@ -28,22 +28,25 @@ using namespace chip::app::Clusters::DoorLock; // should wait for door to be locked on lock command and return success) but // door lock server should check pin before even calling the lock-door // callback. -bool emberAfPluginDoorLockOnDoorLockCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pinCode, OperationErrorEnum & err) +bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pinCode, + OperationErrorEnum & err) { - return LockManager::Instance().Lock(commandObj, endpointId, pinCode, err, OperationSourceEnum::kRemote); + return LockManager::Instance().Lock(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote); } -bool emberAfPluginDoorLockOnDoorUnlockCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pinCode, OperationErrorEnum & err) +bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pinCode, + OperationErrorEnum & err) { - return LockManager::Instance().Unlock(commandObj, endpointId, pinCode, err, OperationSourceEnum::kRemote); + return LockManager::Instance().Unlock(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote); } -bool emberAfPluginDoorLockOnDoorUnboltCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pinCode, OperationErrorEnum & err) +bool emberAfPluginDoorLockOnDoorUnboltCommand(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pinCode, + OperationErrorEnum & err) { - return LockManager::Instance().Unbolt(commandObj, endpointId, pinCode, err, OperationSourceEnum::kRemote); + return LockManager::Instance().Unbolt(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote); } bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) diff --git a/src/app/clusters/door-lock-server/door-lock-server-callback.cpp b/src/app/clusters/door-lock-server/door-lock-server-callback.cpp index a28bc8c05f6f27..a1644286c1af1a 100644 --- a/src/app/clusters/door-lock-server/door-lock-server-callback.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server-callback.cpp @@ -45,24 +45,27 @@ using namespace chip::app::Clusters::DoorLock; // ============================================================================= bool __attribute__((weak)) -emberAfPluginDoorLockOnDoorLockCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pinCode, OperationErrorEnum & err) +emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pinCode, + OperationErrorEnum & err) { err = OperationErrorEnum::kUnspecified; return false; } bool __attribute__((weak)) -emberAfPluginDoorLockOnDoorUnlockCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pinCode, OperationErrorEnum & err) +emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pinCode, + OperationErrorEnum & err) { err = OperationErrorEnum::kUnspecified; return false; } bool __attribute__((weak)) -emberAfPluginDoorLockOnDoorUnboltCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pinCode, OperationErrorEnum & err) +emberAfPluginDoorLockOnDoorUnboltCommand(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pinCode, + OperationErrorEnum & err) { err = OperationErrorEnum::kUnspecified; return false; 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 c0d4b01b586f03..0d5039312faf9b 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -105,7 +105,7 @@ bool DoorLockServer::SetLockState(chip::EndpointId endpointId, DlLockState newLo bool DoorLockServer::SetLockState(chip::EndpointId endpointId, DlLockState newLockState, OperationSourceEnum opSource, const Nullable & userIndex, const Nullable> & credentials, - const chip::app::CommandHandler * commandObj) + const Nullable & fabricIdx, const Nullable & nodeId) { bool success = SetLockState(endpointId, newLockState); @@ -128,17 +128,8 @@ bool DoorLockServer::SetLockState(chip::EndpointId endpointId, DlLockState newLo opType = LockOperationTypeEnum::kUnlatch; } - if (commandObj == nullptr) - { - SendLockOperationEvent(endpointId, opType, opSource, OperationErrorEnum::kUnspecified, userIndex, - Nullable(), Nullable(), credentials, success); - } - else - { - SendLockOperationEvent(endpointId, opType, opSource, OperationErrorEnum::kUnspecified, userIndex, - Nullable(getFabricIndex(commandObj)), - Nullable(getNodeId(commandObj)), credentials, success); - } + SendLockOperationEvent(endpointId, opType, opSource, OperationErrorEnum::kUnspecified, userIndex, fabricIdx, nodeId, + credentials, success); // Reset wrong entry attempts (in case there were any incorrect credentials presented before) if lock/unlock was a success // and a valid credential was presented. @@ -3435,7 +3426,8 @@ bool DoorLockServer::HandleRemoteLockOperation(chip::app::CommandHandler * comma } // credentials check succeeded, try to lock/unlock door - success = opHandler(commandObj, endpoint, pinCode, reason); + success = opHandler(endpoint, Nullable(getFabricIndex(commandObj)), + Nullable(getNodeId(commandObj)), pinCode, reason); // The app should trigger the lock state change as it may take a while before the lock actually locks/unlocks exit: if (!success && reason == OperationErrorEnum::kInvalidCredential) 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 b54fb7e222f27d..f02fadf45fb0bd 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -59,8 +59,9 @@ using chip::app::DataModel::NullNullable; using CredentialStruct = chip::app::Clusters::DoorLock::Structs::CredentialStruct::Type; using LockOpCredentials = CredentialStruct; -typedef bool (*RemoteLockOpHandler)(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pinCode, OperationErrorEnum & err); +typedef bool (*RemoteLockOpHandler)(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pinCode, + OperationErrorEnum & err); static constexpr size_t DOOR_LOCK_MAX_USER_NAME_SIZE = 10; /**< Maximum size of the user name (in characters). */ static constexpr size_t DOOR_LOCK_USER_NAME_BUFFER_SIZE = @@ -95,14 +96,16 @@ class DoorLockServer * @param endpointId ID of the endpoint to the lock state * @param newLockState new lock state * @param opSource source of the operation (will be used in the event). - * @param commandObj command context + * @param fabricIdx fabric index + * @param nodeId node id * * @return true on success, false on failure. */ bool SetLockState(chip::EndpointId endpointId, DlLockState newLockState, OperationSourceEnum opSource, const Nullable & userIndex = NullNullable, const Nullable> & credentials = NullNullable, - const chip::app::CommandHandler * commandObj = nullptr); + const Nullable & fabricIdx = NullNullable, + const Nullable & nodeId = NullNullable); /** * Updates the LockState attribute with new value. @@ -900,44 +903,50 @@ emberAfPluginDoorLockOnUnhandledAttributeChange(chip::EndpointId EndpointId, con /** * @brief User handler for LockDoor command (server) * - * @param commandObj command context * @param endpointId endpoint for which LockDoor command is called + * @param fabricIdx fabric index + * @param nodeId node id * @param pinCode PIN code (optional) * @param err error code if door locking failed (set only if retval==false) * * @retval true on success * @retval false if error happenned (err should be set to appropriate error code) */ -bool emberAfPluginDoorLockOnDoorLockCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pinCode, OperationErrorEnum & err); +bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pinCode, + OperationErrorEnum & err); /** * @brief User handler for UnlockDoor command (server) * - * @param commandObj command context * @param endpointId endpoint for which UnlockDoor command is called + * @param fabricIdx fabric index + * @param nodeId node id * @param pinCode PIN code (optional) * @param err error code if door unlocking failed (set only if retval==false) * * @retval true on success * @retval false if error happenned (err should be set to appropriate error code) */ -bool emberAfPluginDoorLockOnDoorUnlockCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pinCode, OperationErrorEnum & err); +bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pinCode, + OperationErrorEnum & err); /** * @brief User handler for UnboltDoor command (server) * - * @param commandObj command context * @param endpointId endpoint for which UnboltDoor command is called + * @param fabricIdx fabric index + * @param nodeId node id * @param pinCode PIN code (optional) * @param err error code if door unbolting failed (set only if retval==false) * * @retval true on success * @retval false if error happenned (err should be set to appropriate error code) */ -bool emberAfPluginDoorLockOnDoorUnboltCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, - const Optional & pinCode, OperationErrorEnum & err); +bool emberAfPluginDoorLockOnDoorUnboltCommand(chip::EndpointId endpointId, const Nullable & fabricIdx, + const Nullable & nodeId, const Optional & pinCode, + OperationErrorEnum & err); /** * @brief This callback is called when the AutoRelock timer is expired.