Skip to content

Commit

Permalink
Make sure to generate events when we clear credentials. (#25028)
Browse files Browse the repository at this point in the history
* Make sure to generate events when we clear credentials.

We could end up in a situation where we cleared some credentials, then
hit an error, and never generated the event for the credentials we had
cleared.

* Address review comment.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Sep 29, 2023
1 parent b066d49 commit 0b5bd54
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2895,23 +2895,37 @@ EmberAfStatus DoorLockServer::clearCredentials(chip::EndpointId endpointId, chip
return EMBER_ZCL_STATUS_FAILURE;
}

EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
bool clearedCredential = false;
for (uint16_t i = 1; i < maxNumberOfCredentials; ++i)
{
auto status = clearCredential(endpointId, modifier, sourceNodeId, credentialType, i, false);
if (EMBER_ZCL_STATUS_SUCCESS != status)
EmberAfStatus clearStatus = clearCredential(endpointId, modifier, sourceNodeId, credentialType, i, false);
if (EMBER_ZCL_STATUS_SUCCESS != clearStatus)
{
ChipLogError(Zcl,
"[clearCredentials] Unable to clear the credential - internal error "
"[endpointId=%d,credentialType=%u,credentialIndex=%d,status=%d]",
endpointId, to_underlying(credentialType), i, status);
return status;
if (status == EMBER_ZCL_STATUS_SUCCESS)
{
status = clearStatus;
}
}
else
{
clearedCredential = true;
}
}

sendRemoteLockUserChange(endpointId, credentialTypeToLockDataType(credentialType), DataOperationTypeEnum::kClear, sourceNodeId,
modifier, 0xFFFE, 0xFFFE);
// Generate the event if we cleared any credentials, even if we then had errors
// clearing other ones, so we don't have credentials silently disappearing.
if (clearedCredential)
{
sendRemoteLockUserChange(endpointId, credentialTypeToLockDataType(credentialType), DataOperationTypeEnum::kClear,
sourceNodeId, modifier, 0xFFFE, 0xFFFE);
}

return EMBER_ZCL_STATUS_SUCCESS;
return status;
}

bool DoorLockServer::clearFabricFromCredentials(chip::EndpointId endpointId, CredentialTypeEnum credentialType,
Expand Down

0 comments on commit 0b5bd54

Please sign in to comment.