Skip to content

Commit 2431112

Browse files
mykrupppull[bot]
authored andcommitted
fix programmingPin index for removeFabrics (#20944)
* fix programmingPin index for removeFabrics * rerun ci
1 parent 5f872e2 commit 2431112

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

examples/lock-app/efr32/src/LockManager.cpp

+19-13
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,10 @@ bool LockManager::IsValidUserIndex(uint16_t userIndex)
106106

107107
bool LockManager::IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type)
108108
{
109-
// appclusters, 5.2.6.3.1: 0 is allowed index for Programming PIN credential only
110109
if (DlCredentialType::kProgrammingPIN == type)
111110
{
112-
return (0 == credentialIndex);
111+
return (0 == credentialIndex); // 0 is required index for Programming PIN
113112
}
114-
115113
return (credentialIndex < kMaxCredentialsPerUser);
116114
}
117115

@@ -406,19 +404,19 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential
406404
EmberAfPluginDoorLockCredentialInfo & credential)
407405
{
408406

409-
VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // indices are one-indexed
407+
if (DlCredentialType::kProgrammingPIN == credentialType)
408+
{
409+
VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType),
410+
false); // programming pin index is only index allowed to contain 0
411+
}
412+
else
413+
{
414+
VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // otherwise, indices are one-indexed
415+
}
410416

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

414-
if (credentialType == DlCredentialType::kProgrammingPIN)
415-
{
416-
ChipLogError(Zcl, "Programming user not supported [credentialType=%u], credentialIndex=%d", to_underlying(credentialType),
417-
credentialIndex);
418-
419-
return true;
420-
}
421-
422420
const auto & credentialInStorage = mLockCredentials[credentialIndex];
423421

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

452-
VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // indices are one-indexed
450+
if (DlCredentialType::kProgrammingPIN == credentialType)
451+
{
452+
VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType),
453+
false); // programming pin index is only index allowed to contain 0
454+
}
455+
else
456+
{
457+
VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // otherwise, indices are one-indexed
458+
}
453459

454460
ChipLogProgress(Zcl,
455461
"Door Lock App: LockManager::SetCredential "

0 commit comments

Comments
 (0)