Skip to content

Commit

Permalink
[EFR32] Fix 2 door lock edge cases (#20446)
Browse files Browse the repository at this point in the history
* Fix 2 door lock edge cases

* remove check of lower bound for credential index

* remove unused function declaration

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Jul 25, 2022
1 parent 38ed2df commit 5290633
Showing 1 changed file with 2 additions and 31 deletions.
33 changes: 2 additions & 31 deletions examples/lock-app/efr32/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,7 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential
EmberAfPluginDoorLockCredentialInfo & credential)
{

VerifyOrReturnValue(credentialIndex > 0, false); // indices are one-indexed

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);
Expand Down Expand Up @@ -453,11 +449,7 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
const chip::ByteSpan & credentialData)
{

VerifyOrReturnValue(credentialIndex > 0, false); // indices are one-indexed

credentialIndex--;

VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType), false);
VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // indices are one-indexed

ChipLogProgress(Zcl,
"Door Lock App: LockManager::SetCredential "
Expand Down Expand Up @@ -635,23 +627,6 @@ const char * LockManager::lockStateToString(DlLockState lockState) const
bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional<chip::ByteSpan> & 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;
Expand All @@ -661,14 +636,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;
}

Expand All @@ -690,8 +663,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;
}
}
Expand Down

0 comments on commit 5290633

Please sign in to comment.