Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle fabric removal in the Door Lock Cluster and fix GetUser/GetCredentialStatus commands #18812

4 changes: 2 additions & 2 deletions examples/lock-app/efr32/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class LockManager
bool GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType,
EmberAfPluginDoorLockCredentialInfo & credential) const;

bool SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialStatus credentialStatus,
DlCredentialType credentialType, const chip::ByteSpan & credentialData);
bool SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator, chip::FabricIndex modifier,
DlCredentialStatus credentialStatus, DlCredentialType credentialType, const chip::ByteSpan & credentialData);

bool setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional<chip::ByteSpan> & pin,
DlOperationError & err);
Expand Down
25 changes: 19 additions & 6 deletions examples/lock-app/efr32/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,12 @@ bool LockManager::GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & us
user.userUniqueId = userInDb.userUniqueId;
user.userType = userInDb.userType;
user.credentialRule = userInDb.credentialRule;
user.createdBy = userInDb.createdBy;
user.lastModifiedBy = userInDb.lastModifiedBy;
// So far there's no way to actually create the credential outside Matter, so here we always set the creation/modification
// source to Matter
user.creationSource = DlAssetSource::kMatterIM;
user.createdBy = userInDb.createdBy;
user.modificationSource = DlAssetSource::kMatterIM;
user.lastModifiedBy = userInDb.lastModifiedBy;

ChipLogDetail(Zcl,
"Found occupied user "
Expand Down Expand Up @@ -318,20 +322,27 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential
}
credential.credentialType = credentialInStorage.credentialType;
credential.credentialData = credentialInStorage.credentialData;
credential.createdBy = credentialInStorage.createdBy;
credential.lastModifiedBy = credentialInStorage.lastModifiedBy;
// So far there's no way to actually create the credential outside Matter, so here we always set the creation/modification
// source to Matter
credential.creationSource = DlAssetSource::kMatterIM;
credential.modificationSource = DlAssetSource::kMatterIM;
tehampson marked this conversation as resolved.
Show resolved Hide resolved

ChipLogDetail(Zcl, "Found occupied credential [type=%u,dataSize=%u]", to_underlying(credential.credentialType),
credential.credentialData.size());

return true;
}

bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialStatus credentialStatus,
DlCredentialType credentialType, const chip::ByteSpan & credentialData)
bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator,
chip::FabricIndex modifier, DlCredentialStatus credentialStatus, DlCredentialType credentialType,
const chip::ByteSpan & credentialData)
{
ChipLogProgress(Zcl,
"Door Lock App: LockManager::SetCredential "
"[credentialStatus=%u,credentialType=%u,credentialDataSize=%u]",
to_underlying(credentialStatus), to_underlying(credentialType), credentialData.size());
"[credentialStatus=%u,credentialType=%u,credentialDataSize=%u,creator=%d,modifier=%d]",
to_underlying(credentialStatus), to_underlying(credentialType), credentialData.size(), creator, modifier);

auto & credentialInStorage = mLockCredentials;
if (credentialData.size() > DOOR_LOCK_CREDENTIAL_INFO_MAX_DATA_SIZE)
Expand All @@ -344,6 +355,8 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
}
credentialInStorage.status = credentialStatus;
credentialInStorage.credentialType = credentialType;
credentialInStorage.createdBy = creator;
credentialInStorage.lastModifiedBy = modifier;

memcpy(mCredentialData, credentialData.data(), credentialData.size());
mCredentialData[credentialData.size()] = 0;
Expand Down
6 changes: 4 additions & 2 deletions examples/lock-app/efr32/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t cr
return LockMgr().GetCredential(endpointId, credentialIndex, credentialType, credential);
}

bool emberAfPluginDoorLockSetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialStatus credentialStatus,
bool emberAfPluginDoorLockSetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator,
chip::FabricIndex modifier, DlCredentialStatus credentialStatus,
DlCredentialType credentialType, const chip::ByteSpan & credentialData)
{
return LockMgr().SetCredential(endpointId, credentialIndex, credentialStatus, credentialType, credentialData);
return LockMgr().SetCredential(endpointId, credentialIndex, creator, modifier, credentialStatus, credentialType,
credentialData);
}

bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user)
Expand Down
16 changes: 12 additions & 4 deletions examples/lock-app/linux/src/LockEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ bool LockEndpoint::GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & u
user.userUniqueId = userInDb.userUniqueId;
user.userType = userInDb.userType;
user.credentialRule = userInDb.credentialRule;
user.createdBy = userInDb.createdBy;
user.lastModifiedBy = userInDb.lastModifiedBy;
// So far there's no way to actually create the credential outside the matter, so here we always set the creation/modification
// source to Matter
user.creationSource = DlAssetSource::kMatterIM;
user.createdBy = userInDb.createdBy;
user.modificationSource = DlAssetSource::kMatterIM;
user.lastModifiedBy = userInDb.lastModifiedBy;

ChipLogDetail(Zcl,
"Found occupied user "
Expand Down Expand Up @@ -151,8 +155,12 @@ bool LockEndpoint::GetCredential(uint16_t credentialIndex, DlCredentialType cred
}
credential.credentialType = credentialInStorage.credentialType;
credential.credentialData = chip::ByteSpan(credentialInStorage.credentialData, credentialInStorage.credentialDataSize);
credential.createdBy = credentialInStorage.createdBy;
credential.lastModifiedBy = credentialInStorage.modifiedBy;
// So far there's no way to actually create the credential outside the matter, so here we always set the creation/modification
// source to Matter
credential.creationSource = DlAssetSource::kMatterIM;
credential.createdBy = credentialInStorage.createdBy;
credential.modificationSource = DlAssetSource::kMatterIM;
credential.lastModifiedBy = credentialInStorage.modifiedBy;

ChipLogDetail(Zcl, "Found occupied credential [endpoint=%d,index=%u,type=%u,dataSize=%u,createdBy=%u,modifiedBy=%u]",
mEndpointId, credentialIndex, to_underlying(credential.credentialType),
Expand Down
Loading