Skip to content

Commit

Permalink
[EFR32] Lock-app updates, adding multiple users and credentials (#19229)
Browse files Browse the repository at this point in the history
* code review comments. Fix mCredentials, fix NVM flash saving

* restyle

* cleanup

* remove unused array

* remove TotalCredentials key

* Check mMaxUsers against DOOR_LOCK_MAX_USERS
  • Loading branch information
mykrupp authored and pull[bot] committed Jun 25, 2022
1 parent 9562322 commit 1706510
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 72 deletions.
28 changes: 18 additions & 10 deletions examples/lock-app/efr32/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@

using namespace ::chip;

// Currently up to 10 users are support on the EFR32 platform
#define DOOR_LOCK_MAX_USERS 10
#define DOOR_LOCK_MAX_CREDENTIAL_SIZE 8
#define MININUM_USER_INDEX 1
#define MINIMUM_CREDENTIAL_INDEX 1
#define MAX_CREDENTIAL_PER_USER 10
#define MAX_CREDENTIALS 50

static constexpr size_t DOOR_LOCK_CREDENTIAL_INFO_MAX_DATA_SIZE = 20;

Expand All @@ -55,7 +61,7 @@ class LockManager
} State;

CHIP_ERROR Init(chip::app::DataModel::Nullable<chip::app::Clusters::DoorLock::DlLockState> state,
uint8_t maxNumberOfCredentialsPerUser);
uint8_t maxNumberOfCredentialsPerUser, uint16_t numberOfSupportedUsers);
bool NextState();
bool IsActionInProgress();
bool InitiateAction(int32_t aActor, Action_t aAction);
Expand All @@ -67,10 +73,10 @@ class LockManager
bool Lock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, DlOperationError & err);
bool Unlock(chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin, DlOperationError & err);

bool GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) const;
bool SetUser(uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, const chip::CharSpan & userName,
uint32_t uniqueId, DlUserStatus userStatus, DlUserType usertype, DlCredentialRule credentialRule,
const DlCredential * credentials, size_t totalCredentials);
bool GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) const;
bool SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier,
const chip::CharSpan & userName, uint32_t uniqueId, DlUserStatus userStatus, DlUserType usertype,
DlCredentialRule credentialRule, const DlCredential * credentials, size_t totalCredentials);

bool GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType,
EmberAfPluginDoorLockCredentialInfo & credential) const;
Expand Down Expand Up @@ -99,13 +105,15 @@ class LockManager
static void AutoLockTimerEventHandler(AppEvent * aEvent);
static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);

EmberAfPluginDoorLockUserInfo mLockUser;
EmberAfPluginDoorLockCredentialInfo mLockCredentials;
EmberAfPluginDoorLockUserInfo mLockUsers[DOOR_LOCK_MAX_USERS];
EmberAfPluginDoorLockCredentialInfo mLockCredentials[MAX_CREDENTIALS];

char mUserName[DOOR_LOCK_MAX_USER_NAME_SIZE];
uint8_t mCredentialData[DOOR_LOCK_MAX_CREDENTIAL_SIZE];
chip::Platform::ScopedMemoryBuffer<DlCredential> mCredentials;
uint8_t mMaxCredentialsPerUser;
uint16_t mMaxUsers;

char mUserNames[ArraySize(mLockUsers)][DOOR_LOCK_MAX_USER_NAME_SIZE];
uint8_t mCredentialData[MAX_CREDENTIALS][DOOR_LOCK_MAX_CREDENTIAL_SIZE];
chip::Platform::ScopedMemoryBuffer<DlCredential> mCredentials[MAX_CREDENTIAL_PER_USER];

static LockManager sLock;
};
Expand Down
11 changes: 10 additions & 1 deletion examples/lock-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,18 @@ CHIP_ERROR AppTask::Init()
endpointId);
maxCredentialsPerUser = 5;
}

uint16_t numberOfSupportedUsers = 0;
if (!DoorLockServer::Instance().GetNumberOfUserSupported(endpointId, numberOfSupportedUsers))
{
ChipLogError(Zcl,
"Unable to get number of supported users when initializing lock endpoint, defaulting to 10 [endpointId=%d]",
endpointId);
numberOfSupportedUsers = 10;
}
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

err = LockMgr().Init(state, maxCredentialsPerUser);
err = LockMgr().Init(state, maxCredentialsPerUser, numberOfSupportedUsers);
if (err != CHIP_NO_ERROR)
{
EFR32_LOG("LockMgr().Init() failed");
Expand Down
Loading

0 comments on commit 1706510

Please sign in to comment.