Skip to content

Commit

Permalink
fix programmingPin index for removeFabrics (project-chip#20944)
Browse files Browse the repository at this point in the history
* fix programmingPin index for removeFabrics

* rerun ci
  • Loading branch information
mykrupp authored and isiu-apple committed Sep 16, 2022
1 parent 4918768 commit 3c669f8
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions examples/lock-app/efr32/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ bool LockManager::IsValidUserIndex(uint16_t userIndex)

bool LockManager::IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type)
{
// appclusters, 5.2.6.3.1: 0 is allowed index for Programming PIN credential only
if (DlCredentialType::kProgrammingPIN == type)
{
return (0 == credentialIndex);
return (0 == credentialIndex); // 0 is required index for Programming PIN
}

return (credentialIndex < kMaxCredentialsPerUser);
}

Expand Down Expand Up @@ -406,19 +404,19 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential
EmberAfPluginDoorLockCredentialInfo & credential)
{

VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // indices are one-indexed
if (DlCredentialType::kProgrammingPIN == credentialType)
{
VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType),
false); // programming pin index is only index allowed to contain 0
}
else
{
VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // otherwise, indices are one-indexed
}

ChipLogProgress(Zcl, "Lock App: LockManager::GetCredential [credentialType=%u], credentialIndex=%d",
to_underlying(credentialType), credentialIndex);

if (credentialType == DlCredentialType::kProgrammingPIN)
{
ChipLogError(Zcl, "Programming user not supported [credentialType=%u], credentialIndex=%d", to_underlying(credentialType),
credentialIndex);

return true;
}

const auto & credentialInStorage = mLockCredentials[credentialIndex];

credential.status = credentialInStorage.status;
Expand Down Expand Up @@ -449,7 +447,15 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
const chip::ByteSpan & credentialData)
{

VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // indices are one-indexed
if (DlCredentialType::kProgrammingPIN == credentialType)
{
VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType),
false); // programming pin index is only index allowed to contain 0
}
else
{
VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // otherwise, indices are one-indexed
}

ChipLogProgress(Zcl,
"Door Lock App: LockManager::SetCredential "
Expand Down

0 comments on commit 3c669f8

Please sign in to comment.