Skip to content

Commit

Permalink
Handle fabric removal in the Door Lock Cluster and fix GetUser/GetCre…
Browse files Browse the repository at this point in the history
…dentialStatus commands (#18812)

* Set up the fabric removal handler in the door lock cluster

* Clear up the fabric index on fabric removal in the users and credentials of the door lock

* Add modification/creation source in the user/credential structure of the door lock

* [#14919] Return the next occupied slot for GetUser/GetCredentialStatus commands

* Apply suggestions from code review

Fix typos

Co-authored-by: Boris Zbarsky <[email protected]>

* Fix code review notes

* Update efr32 lock app and address code review feedback

* Update auto-generated files

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 31, 2023
1 parent 0d4d041 commit 1629954
Show file tree
Hide file tree
Showing 9 changed files with 468 additions and 233 deletions.
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;

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

0 comments on commit 1629954

Please sign in to comment.