Skip to content

Commit

Permalink
[Infineon] Lock-app updates, adding multiple users and credentials fo…
Browse files Browse the repository at this point in the history
…r CYW30739 (#20034)

* [Infineon] Lock-app updates, adding multiple users and credentials.

    * Fix mCredentials, fix NVM flash saving

    * restyle

    * cleanup

    * remove unused array

    * remove TotalCredentials key

    * Check mMaxUsers against DOOR_LOCK_MAX_USERS

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
AlvinHsiao and restyled-commits authored Jul 6, 2022
1 parent 5e3f841 commit 5bc59e9
Show file tree
Hide file tree
Showing 6 changed files with 559 additions and 138 deletions.
122 changes: 105 additions & 17 deletions examples/lock-app/cyw30739/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,73 @@
#include <stdint.h>
#include <wiced_timer.h>

using namespace ::chip;
namespace CYW30739DoorLock {
namespace ResourceRanges {
// Used to size arrays
static constexpr uint16_t kMaxUsers = 10;
static constexpr uint8_t kMaxCredentialsPerUser = 10;
static constexpr uint8_t kMaxWeekdaySchedulesPerUser = 10;
static constexpr uint8_t kMaxYeardaySchedulesPerUser = 10;
static constexpr uint8_t kMaxHolidaySchedules = 10;
static constexpr uint8_t kMaxCredentialSize = 8;

// Indices received for user/credential/schedules are 1-indexed
static constexpr uint8_t kStartIndexValue = 1;

static constexpr uint8_t kMaxCredentials = kMaxUsers * kMaxCredentialsPerUser;
} // namespace ResourceRanges

namespace LockInitParams {

struct LockParam
{
// Read from zap attributes
uint16_t numberOfUsers = 0;
uint8_t numberOfCredentialsPerUser = 0;
uint8_t numberOfWeekdaySchedulesPerUser = 0;
uint8_t numberOfYeardaySchedulesPerUser = 0;
uint8_t numberOfHolidaySchedules = 0;
};

class ParamBuilder
{
public:
ParamBuilder & SetNumberOfUsers(uint16_t numberOfUsers)
{
lockParam_.numberOfUsers = numberOfUsers;
return *this;
}
ParamBuilder & SetNumberOfCredentialsPerUser(uint8_t numberOfCredentialsPerUser)
{
lockParam_.numberOfCredentialsPerUser = numberOfCredentialsPerUser;
return *this;
}
ParamBuilder & SetNumberOfWeekdaySchedulesPerUser(uint8_t numberOfWeekdaySchedulesPerUser)
{
lockParam_.numberOfWeekdaySchedulesPerUser = numberOfWeekdaySchedulesPerUser;
return *this;
}
ParamBuilder & SetNumberOfYeardaySchedulesPerUser(uint8_t numberOfYeardaySchedulesPerUser)
{
lockParam_.numberOfYeardaySchedulesPerUser = numberOfYeardaySchedulesPerUser;
return *this;
}
ParamBuilder & SetNumberOfHolidaySchedules(uint8_t numberOfHolidaySchedules)
{
lockParam_.numberOfHolidaySchedules = numberOfHolidaySchedules;
return *this;
}
LockParam GetLockParam() { return lockParam_; }

#define DOOR_LOCK_MAX_CREDENTIAL_SIZE 8
private:
LockParam lockParam_;
};

static constexpr size_t DOOR_LOCK_CREDENTIAL_INFO_MAX_DATA_SIZE = 20;
} // namespace LockInitParams
} // namespace CYW30739DoorLock

using namespace ::chip;
using namespace CYW30739DoorLock::ResourceRanges;

class LockManager
{
Expand Down Expand Up @@ -59,7 +121,7 @@ class LockManager
} Actor;

CHIP_ERROR Init(chip::app::DataModel::Nullable<chip::app::Clusters::DoorLock::DlLockState> state,
uint8_t maxNumberOfCredentialsPerUser);
CYW30739DoorLock::LockInitParams::LockParam lockParam);
bool NextState();
bool IsActionInProgress();
bool InitiateAction(int32_t aActor, Action_t aAction);
Expand All @@ -71,16 +133,39 @@ 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);
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;
EmberAfPluginDoorLockCredentialInfo & credential);

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

DlStatus GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex,
EmberAfPluginDoorLockWeekDaySchedule & schedule);

DlStatus SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, DlScheduleStatus status,
DlDaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute);

DlStatus GetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex,
EmberAfPluginDoorLockYearDaySchedule & schedule);

DlStatus SetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, DlScheduleStatus status,
uint32_t localStartTime, uint32_t localEndTime);

DlStatus GetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & schedule);

DlStatus SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, uint32_t localStartTime,
uint32_t localEndTime, DlOperatingMode operatingMode);

bool SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialStatus credentialStatus,
DlCredentialType credentialType, const chip::ByteSpan & credentialData);
bool IsValidUserIndex(uint16_t userIndex);
bool IsValidCredentialIndex(uint16_t credentialIndex, DlCredentialType type);
bool IsValidWeekdayScheduleIndex(uint8_t scheduleIndex);
bool IsValidYeardayScheduleIndex(uint8_t scheduleIndex);
bool IsValidHolidayScheduleIndex(uint8_t scheduleIndex);

bool setLockState(chip::EndpointId endpointId, DlLockState lockState, const Optional<chip::ByteSpan> & pin,
DlOperationError & err);
Expand All @@ -102,15 +187,18 @@ class LockManager
static void TimerEventHandler(WICED_TIMER_PARAM_TYPE cb_params);
static int ActuatorMovementTimerEventHandler(void * aEvent);

EmberAfPluginDoorLockUserInfo mLockUser;
EmberAfPluginDoorLockCredentialInfo mLockCredentials;
EmberAfPluginDoorLockUserInfo mLockUsers[kMaxUsers];
EmberAfPluginDoorLockCredentialInfo mLockCredentials[kMaxCredentials];
EmberAfPluginDoorLockWeekDaySchedule mWeekdaySchedule[kMaxUsers][kMaxWeekdaySchedulesPerUser];
EmberAfPluginDoorLockYearDaySchedule mYeardaySchedule[kMaxUsers][kMaxYeardaySchedulesPerUser];
EmberAfPluginDoorLockHolidaySchedule mHolidaySchedule[kMaxHolidaySchedules];

char mUserName[DOOR_LOCK_MAX_USER_NAME_SIZE];
uint8_t mCredentialData[DOOR_LOCK_MAX_CREDENTIAL_SIZE];
chip::Platform::ScopedMemoryBuffer<DlCredential> mCredentials;
uint8_t mMaxCredentialsPerUser;
char mUserNames[ArraySize(mLockUsers)][DOOR_LOCK_MAX_USER_NAME_SIZE];
uint8_t mCredentialData[kMaxCredentials][kMaxCredentialSize];
DlCredential mCredentials[kMaxUsers][kMaxCredentialsPerUser];

static LockManager sLock;
CYW30739DoorLock::LockInitParams::LockParam LockParams;
};

inline LockManager & LockMgr()
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/cyw30739/include/chip_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// Application-defined error codes in the CHIP_ERROR space
#define APP_ERROR_INIT_TIMER_FAILED CHIP_ERROR_NO_MEMORY // should use CHIP_APPLICATION_ERROR when it's ready
#define APP_ERROR_ALLOCATION_FAILED CHIP_APPLICATION_ERROR(0x07)

// Application configurations
#define ACTUATOR_MOVEMENT_PERIOS_MS 1000
Loading

0 comments on commit 5bc59e9

Please sign in to comment.