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

lock storage refactor #37847

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 43 additions & 12 deletions examples/lock-app/silabs/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include <cmsis_os2.h>
#include <lib/core/CHIPError.h>

struct WeekDaysScheduleInfo
#include <lib/support/DefaultStorageKeyAllocator.h>

struct WeekDayScheduleInfo
{
DlScheduleStatus status;
EmberAfPluginDoorLockWeekDaySchedule schedule;
Expand Down Expand Up @@ -112,6 +114,30 @@ class ParamBuilder
using namespace ::chip;
using namespace EFR32DoorLock::ResourceRanges;

struct LockUserInfo
{
char userName[DOOR_LOCK_USER_NAME_BUFFER_SIZE];
size_t userNameSize;
uint32_t userUniqueId;
UserStatusEnum userStatus;
UserTypeEnum userType;
CredentialRuleEnum credentialRule;
chip::EndpointId endpointId;
chip::FabricIndex createdBy;
chip::FabricIndex lastModifiedBy;
uint16_t currentCredentialCount;
};

struct LockCredentialInfo
{
DlCredentialStatus status;
CredentialTypeEnum credentialType;
chip::FabricIndex createdBy;
chip::FabricIndex lastModifiedBy;
uint8_t credentialData[kMaxCredentialSize];
size_t credentialDataSize;
};

class LockManager
{
public:
Expand Down Expand Up @@ -192,8 +218,6 @@ class LockManager
OperationErrorEnum & err);
const char * lockStateToString(DlLockState lockState) const;

bool ReadConfigValues();

void UnlockAfterUnlatch();

private:
Expand Down Expand Up @@ -244,17 +268,24 @@ class LockManager
static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);

osTimerId_t mLockTimer;
EmberAfPluginDoorLockUserInfo mLockUsers[kMaxUsers];
EmberAfPluginDoorLockCredentialInfo mLockCredentials[kNumCredentialTypes][kMaxCredentials];
WeekDaysScheduleInfo mWeekdaySchedule[kMaxUsers][kMaxWeekdaySchedulesPerUser];
YearDayScheduleInfo mYeardaySchedule[kMaxUsers][kMaxYeardaySchedulesPerUser];
HolidayScheduleInfo mHolidaySchedule[kMaxHolidaySchedules];

char mUserNames[MATTER_ARRAY_SIZE(mLockUsers)][DOOR_LOCK_MAX_USER_NAME_SIZE];
uint8_t mCredentialData[kNumCredentialTypes][kMaxCredentials][kMaxCredentialSize];
CredentialStruct mCredentials[kMaxUsers][kMaxCredentials];

EFR32DoorLock::LockInitParams::LockParam LockParams;

static StorageKeyName LockUserEndpoint(uint16_t userIndex, chip::EndpointId endpoint) { return StorageKeyName::Formatted("g/lu/%x/e/%x", userIndex, endpoint); }
static StorageKeyName LockCredentialEndpoint(uint16_t credentialIndex, chip::EndpointId endpoint) { return StorageKeyName::Formatted("g/lc/%x/e/%x", credentialIndex, endpoint); }
static StorageKeyName LockUserCredentialMap(uint16_t userIndex) { return StorageKeyName::Formatted("g/lu/%x/lc", userIndex); } // Stores all the credential indices that belong to a user
static StorageKeyName LockUserWeekDayScheduleEndpoint(uint16_t userIndex, uint16_t scheduleIndex, chip::EndpointId endpoint) { return StorageKeyName::Formatted("g/lu/%x/lw/%x/e/%x", userIndex, scheduleIndex, endpoint); }
static StorageKeyName LockUserYearDayScheduleEndpoint(uint16_t userIndex, uint16_t scheduleIndex, chip::EndpointId endpoint) { return StorageKeyName::Formatted("g/lu/%x/ly/%x/e/%x", userIndex, scheduleIndex, endpoint); }
static StorageKeyName LockHolidayScheduleEndpoint(uint16_t scheduleIndex, chip::EndpointId endpoint) { return StorageKeyName::Formatted("g/lh/%x/e/%x", scheduleIndex, endpoint); }

LockUserInfo userInStorage;
LockCredentialInfo credentialInStorage;
WeekDayScheduleInfo weekDayScheduleInStorage;
YearDayScheduleInfo yearDayScheduleInStorage;
HolidayScheduleInfo holidayScheduleInStorage;
CredentialStruct mCredential;
CredentialStruct mCredentials[kMaxCredentialsPerUser];

};

LockManager & LockMgr();
5 changes: 2 additions & 3 deletions examples/lock-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
#include <app-common/zap-generated/cluster-objects.h>

#include <app/clusters/door-lock-server/door-lock-server.h>
#include <setup_payload/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
#include <setup_payload/OnboardingCodesUtil.h>

#include <assert.h>

Expand Down Expand Up @@ -266,8 +266,6 @@ void AppTask::AppTaskMain(void * pvParameter)

SILABS_LOG("App Task started");

// Users and credentials should be checked once from nvm flash on boot
LockMgr().ReadConfigValues();

while (true)
{
Expand Down Expand Up @@ -412,3 +410,4 @@ void AppTask::UpdateClusterState(intptr_t context)
SILABS_LOG("ERR: updating lock state %x", to_underlying(status));
}
}

Loading
Loading