From 55bb8847a2ef3540416bc64afb4344f84b0cf748 Mon Sep 17 00:00:00 2001 From: Michael Rupp <95718139+mykrupp@users.noreply.github.com> Date: Thu, 7 Jul 2022 13:26:08 -0400 Subject: [PATCH 1/3] Fix 2 door lock edge cases --- examples/lock-app/efr32/include/LockManager.h | 1 + examples/lock-app/efr32/src/LockManager.cpp | 36 +++++++------------ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/examples/lock-app/efr32/include/LockManager.h b/examples/lock-app/efr32/include/LockManager.h index 01332f9c42b838..ff416a49faabc9 100644 --- a/examples/lock-app/efr32/include/LockManager.h +++ b/examples/lock-app/efr32/include/LockManager.h @@ -158,6 +158,7 @@ class LockManager uint32_t localEndTime, DlOperatingMode operatingMode); bool IsValidUserIndex(uint16_t userIndex); + bool IsCredentialIndexGreaterThanZero(uint16_t credentialIndex, DlCredentialType type); bool IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type); bool IsValidWeekdayScheduleIndex(uint8_t scheduleIndex); bool IsValidYeardayScheduleIndex(uint8_t scheduleIndex); diff --git a/examples/lock-app/efr32/src/LockManager.cpp b/examples/lock-app/efr32/src/LockManager.cpp index b59b15b57c4110..72d4cfbf14251d 100644 --- a/examples/lock-app/efr32/src/LockManager.cpp +++ b/examples/lock-app/efr32/src/LockManager.cpp @@ -104,6 +104,17 @@ bool LockManager::IsValidUserIndex(uint16_t userIndex) return (userIndex < kMaxUsers); } +bool LockManager::IsCredentialIndexGreaterThanZero(uint16_t credentialIndex, DlCredentialType type) +{ + // Programming PIN index is the only index allowed to be 0 + if (DlCredentialType::kProgrammingPIN == type) + { + return (0 == credentialIndex); + } + + return (credentialIndex > 0); +} + bool LockManager::IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type) { // appclusters, 5.2.6.3.1: 0 is allowed index for Programming PIN credential only @@ -406,7 +417,7 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential EmberAfPluginDoorLockCredentialInfo & credential) { - VerifyOrReturnValue(credentialIndex > 0, false); // indices are one-indexed + VerifyOrReturnValue(IsCredentialIndexGreaterThanZero(credentialIndex, credentialType), false); // indices are one-indexed except ProgrammingPin credentialIndex--; @@ -453,7 +464,7 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential const chip::ByteSpan & credentialData) { - VerifyOrReturnValue(credentialIndex > 0, false); // indices are one-indexed + VerifyOrReturnValue(IsCredentialIndexGreaterThanZero(credentialIndex, credentialType), false); // indices are one-indexed except ProgrammingPin credentialIndex--; @@ -635,23 +646,6 @@ const char * LockManager::lockStateToString(DlLockState lockState) const bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional & pin, DlOperationError & err) { - DlLockState curState = DlLockState::kLocked; - if (mState == kState_UnlockCompleted) - curState = DlLockState::kUnlocked; - - if ((curState == lockState) && (curState == DlLockState::kLocked)) - { - ChipLogDetail(Zcl, "Door Lock App: door is already locked, ignoring command to set lock state to \"%s\" [endpointId=%d]", - lockStateToString(lockState), endpointId); - return true; - } - else if ((curState == lockState) && (curState == DlLockState::kUnlocked)) - { - ChipLogDetail(Zcl, - "Door Lock App: door is already unlocked, ignoring command to set unlock state to \"%s\" [endpointId=%d]", - lockStateToString(lockState), endpointId); - return true; - } // Assume pin is required until told otherwise bool requirePin = true; @@ -661,14 +655,12 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat if (!pin.HasValue()) { ChipLogDetail(Zcl, "Door Lock App: PIN code is not specified, but it is required [endpointId=%d]", mEndpointId); - curState = lockState; // If a pin code is not required if (!requirePin) { ChipLogDetail(Zcl, "Door Lock App: setting door lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState), endpointId); - curState = lockState; return true; } @@ -690,8 +682,6 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat "Lock App: specified PIN code was found in the database, setting lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState), mEndpointId); - curState = lockState; - return true; } } From 91f9d02365ff48250791b081065244351143229e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 7 Jul 2022 17:37:06 +0000 Subject: [PATCH 2/3] remove check of lower bound for credential index --- examples/lock-app/efr32/src/LockManager.cpp | 23 ++------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/examples/lock-app/efr32/src/LockManager.cpp b/examples/lock-app/efr32/src/LockManager.cpp index 72d4cfbf14251d..ab9e548562981e 100644 --- a/examples/lock-app/efr32/src/LockManager.cpp +++ b/examples/lock-app/efr32/src/LockManager.cpp @@ -104,17 +104,6 @@ bool LockManager::IsValidUserIndex(uint16_t userIndex) return (userIndex < kMaxUsers); } -bool LockManager::IsCredentialIndexGreaterThanZero(uint16_t credentialIndex, DlCredentialType type) -{ - // Programming PIN index is the only index allowed to be 0 - if (DlCredentialType::kProgrammingPIN == type) - { - return (0 == credentialIndex); - } - - return (credentialIndex > 0); -} - bool LockManager::IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type) { // appclusters, 5.2.6.3.1: 0 is allowed index for Programming PIN credential only @@ -417,11 +406,7 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential EmberAfPluginDoorLockCredentialInfo & credential) { - VerifyOrReturnValue(IsCredentialIndexGreaterThanZero(credentialIndex, credentialType), false); // indices are one-indexed except ProgrammingPin - - credentialIndex--; - - VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType), false); + VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // indices are one-indexed ChipLogProgress(Zcl, "Lock App: LockManager::GetCredential [credentialType=%u], credentialIndex=%d", to_underlying(credentialType), credentialIndex); @@ -464,11 +449,7 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential const chip::ByteSpan & credentialData) { - VerifyOrReturnValue(IsCredentialIndexGreaterThanZero(credentialIndex, credentialType), false); // indices are one-indexed except ProgrammingPin - - credentialIndex--; - - VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType), false); + VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // indices are one-indexed ChipLogProgress(Zcl, "Door Lock App: LockManager::SetCredential " From 4d5e760d634ee7ba7e257f3e1e82f9f7b403a3da Mon Sep 17 00:00:00 2001 From: Michael Rupp <95718139+mykrupp@users.noreply.github.com> Date: Thu, 7 Jul 2022 19:12:41 -0400 Subject: [PATCH 3/3] remove unused function declaration --- examples/lock-app/efr32/include/LockManager.h | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/lock-app/efr32/include/LockManager.h b/examples/lock-app/efr32/include/LockManager.h index ff416a49faabc9..01332f9c42b838 100644 --- a/examples/lock-app/efr32/include/LockManager.h +++ b/examples/lock-app/efr32/include/LockManager.h @@ -158,7 +158,6 @@ class LockManager uint32_t localEndTime, DlOperatingMode operatingMode); bool IsValidUserIndex(uint16_t userIndex); - bool IsCredentialIndexGreaterThanZero(uint16_t credentialIndex, DlCredentialType type); bool IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type); bool IsValidWeekdayScheduleIndex(uint8_t scheduleIndex); bool IsValidYeardayScheduleIndex(uint8_t scheduleIndex);