From 39979070d0c436c9d0609dde7593f7a77dd54aa2 Mon Sep 17 00:00:00 2001 From: AlvinHsiao <89836894+AlvinHsiao@users.noreply.github.com> Date: Wed, 6 Jul 2022 10:38:42 +0800 Subject: [PATCH] [Infineon] Lock-app updates, adding multiple users and credentials for 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 --- .../lock-app/cyw30739/include/LockManager.h | 122 ++++- .../lock-app/cyw30739/include/chip_lock.h | 1 + .../lock-app/cyw30739/src/LockManager.cpp | 447 ++++++++++++++---- .../lock-app/cyw30739/src/ZclCallbacks.cpp | 12 +- examples/lock-app/cyw30739/src/main.cpp | 108 +++-- src/platform/CYW30739/CYW30739Config.h | 7 +- 6 files changed, 559 insertions(+), 138 deletions(-) diff --git a/examples/lock-app/cyw30739/include/LockManager.h b/examples/lock-app/cyw30739/include/LockManager.h index 596e5e9f42d035..1cf92b5efe5de1 100644 --- a/examples/lock-app/cyw30739/include/LockManager.h +++ b/examples/lock-app/cyw30739/include/LockManager.h @@ -26,11 +26,73 @@ #include #include -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 { @@ -59,7 +121,7 @@ class LockManager } Actor; CHIP_ERROR Init(chip::app::DataModel::Nullable state, - uint8_t maxNumberOfCredentialsPerUser); + CYW30739DoorLock::LockInitParams::LockParam lockParam); bool NextState(); bool IsActionInProgress(); bool InitiateAction(int32_t aActor, Action_t aAction); @@ -71,16 +133,39 @@ class LockManager bool Lock(chip::EndpointId endpointId, const Optional & pin, DlOperationError & err); bool Unlock(chip::EndpointId endpointId, const Optional & 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 & pin, DlOperationError & err); @@ -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 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() diff --git a/examples/lock-app/cyw30739/include/chip_lock.h b/examples/lock-app/cyw30739/include/chip_lock.h index b752e02e2fe067..85aaddb87057aa 100644 --- a/examples/lock-app/cyw30739/include/chip_lock.h +++ b/examples/lock-app/cyw30739/include/chip_lock.h @@ -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 diff --git a/examples/lock-app/cyw30739/src/LockManager.cpp b/examples/lock-app/cyw30739/src/LockManager.cpp index d5af8592543829..2a845b62abb3ac 100644 --- a/examples/lock-app/cyw30739/src/LockManager.cpp +++ b/examples/lock-app/cyw30739/src/LockManager.cpp @@ -19,25 +19,62 @@ #include "LockManager.h" #include "wiced_bt_event.h" +#include #include #include -using namespace chip::DeviceLayer::Internal; - LockManager LockManager::sLock; wiced_timer_t sLockTimer; -CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable state, - uint8_t maxNumberOfCredentialsPerUser) +using namespace chip::DeviceLayer::Internal; +using namespace CYW30739DoorLock::LockInitParams; + +CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable state, LockParam lockParam) { - // Allocate buffer for credentials - if (!mCredentials.Alloc(maxNumberOfCredentialsPerUser)) + LockParams = lockParam; + + if (LockParams.numberOfUsers > kMaxUsers) + { + ChipLogError(Zcl, + "Max number of users is greater than %d, the maximum amount of users currently supported on this platform", + kMaxUsers); + return APP_ERROR_ALLOCATION_FAILED; + } + + if (LockParams.numberOfCredentialsPerUser > kMaxCredentialsPerUser) { - printf("Failed to allocate array for lock credentials"); - return CHIP_ERROR_NO_MEMORY; + ChipLogError( + Zcl, + "Max number of credentials per user is greater than %d, the maximum amount of users currently supported on this " + "platform", + kMaxCredentialsPerUser); + return APP_ERROR_ALLOCATION_FAILED; + } + + if (LockParams.numberOfWeekdaySchedulesPerUser > kMaxWeekdaySchedulesPerUser) + { + ChipLogError( + Zcl, "Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + kMaxWeekdaySchedulesPerUser); + return APP_ERROR_ALLOCATION_FAILED; + } + + if (LockParams.numberOfYeardaySchedulesPerUser > kMaxYeardaySchedulesPerUser) + { + ChipLogError( + Zcl, "Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + kMaxYeardaySchedulesPerUser); + return APP_ERROR_ALLOCATION_FAILED; + } + + if (LockParams.numberOfHolidaySchedules > kMaxHolidaySchedules) + { + ChipLogError( + Zcl, "Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + kMaxHolidaySchedules); + return APP_ERROR_ALLOCATION_FAILED; } - mMaxCredentialsPerUser = maxNumberOfCredentialsPerUser; wiced_result_t result; @@ -45,7 +82,7 @@ CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable(&mLockUser), - sizeof(EmberAfPluginDoorLockUserInfo), outLen); + CYW30739Config::ReadConfigValueBin(CYW30739Config::kConfigKey_LockUser, reinterpret_cast(&mLockUsers), + sizeof(EmberAfPluginDoorLockUserInfo) * ArraySize(mLockUsers), outLen); + CYW30739Config::ReadConfigValueBin(CYW30739Config::kConfigKey_Credential, reinterpret_cast(&mLockCredentials), - sizeof(EmberAfPluginDoorLockCredentialInfo), outLen); + sizeof(EmberAfPluginDoorLockCredentialInfo) * ArraySize(mLockCredentials), outLen); + + CYW30739Config::ReadConfigValueBin(CYW30739Config::kConfigKey_LockUserName, reinterpret_cast(mUserNames), + sizeof(mUserNames), outLen); - CYW30739Config::ReadConfigValueStr(CYW30739Config::kConfigKey_LockUserName, mUserName, DOOR_LOCK_USER_NAME_BUFFER_SIZE, outLen); + CYW30739Config::ReadConfigValueBin(CYW30739Config::kConfigKey_CredentialData, reinterpret_cast(mCredentialData), + sizeof(mCredentialData), outLen); - CYW30739Config::ReadConfigValueBin(CYW30739Config::kConfigKey_CredentialData, mCredentialData, sizeof(mCredentialData), outLen); + CYW30739Config::ReadConfigValueBin(CYW30739Config::kConfigKey_UserCredentials, reinterpret_cast(mCredentials), + sizeof(DlCredential) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser, + outLen); - CYW30739Config::ReadConfigValueBin(CYW30739Config::kConfigKey_UserCredentials, reinterpret_cast(mCredentials.Get()), - sizeof(DlCredential), outLen); + CYW30739Config::ReadConfigValueBin(CYW30739Config::kConfigKey_WeekDaySchedules, reinterpret_cast(mWeekdaySchedule), + sizeof(EmberAfPluginDoorLockWeekDaySchedule) * LockParams.numberOfWeekdaySchedulesPerUser * + LockParams.numberOfUsers, + outLen); + + CYW30739Config::ReadConfigValueBin(CYW30739Config::kConfigKey_YearDaySchedules, reinterpret_cast(mYeardaySchedule), + sizeof(EmberAfPluginDoorLockYearDaySchedule) * LockParams.numberOfYeardaySchedulesPerUser * + LockParams.numberOfUsers, + outLen); + + CYW30739Config::ReadConfigValueBin(CYW30739Config::kConfigKey_HolidaySchedules, + reinterpret_cast(&(mHolidaySchedule)), + sizeof(EmberAfPluginDoorLockHolidaySchedule) * LockParams.numberOfHolidaySchedules, outLen); return true; } @@ -131,13 +217,13 @@ void LockManager::StartTimer(uint32_t aTimeoutMs) { if (wiced_is_timer_in_use(&sLockTimer)) { - printf("app timer already started!\n"); + ChipLogError(Zcl, "app timer already started!"); CancelTimer(); } if (wiced_start_timer(&sLockTimer, aTimeoutMs) != WICED_BT_SUCCESS) { - printf("sLockTimer timer start() failed\n"); + ChipLogError(Zcl, "sLockTimer timer start() failed"); return; } } @@ -146,7 +232,7 @@ void LockManager::CancelTimer(void) { if (wiced_stop_timer(&sLockTimer) != WICED_BT_SUCCESS) { - printf("Lock timer timer stop() failed\n"); + ChipLogError(Zcl, "Lock timer timer stop() failed"); return; } } @@ -163,7 +249,7 @@ void LockManager::TimerEventHandler(WICED_TIMER_PARAM_TYPE cb_params) if (wiced_app_event_serialize(fn, (void *) lock) != WICED_TRUE) { - printf("wiced_app_event_serialize failed\n"); + ChipLogError(Zcl, "wiced_app_event_serialize failed "); } } @@ -205,39 +291,49 @@ bool LockManager::Unlock(chip::EndpointId endpointId, const Optional 0, false); // indices are one-indexed + + userIndex--; + + VerifyOrReturnValue(IsValidUserIndex(userIndex), false); - const auto & userInDb = mLockUser; - user.userStatus = userInDb.userStatus; + ChipLogProgress(Zcl, "Door Lock App: LockManager::GetUser [endpoint=%d,userIndex=%hu]", endpointId, userIndex); + + const auto & userInDb = mLockUsers[userIndex]; + + user.userStatus = userInDb.userStatus; if (DlUserStatus::kAvailable == user.userStatus) { - ChipLogDetail(Zcl, "Found unoccupied user [endpoint=%d]", mEndpointId); + ChipLogDetail(Zcl, "Found unoccupied user [endpoint=%d]", endpointId); return true; } user.userName = chip::CharSpan(userInDb.userName.data(), userInDb.userName.size()); - user.credentials = chip::Span(userInDb.credentials.data(), userInDb.credentials.size()); + user.credentials = chip::Span(mCredentials[userIndex], userInDb.credentials.size()); 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 " "[endpoint=%d,name=\"%.*s\",credentialsCount=%u,uniqueId=%lx,type=%u,credentialRule=%u," "createdBy=%d,lastModifiedBy=%d]", - mEndpointId, static_cast(user.userName.size()), user.userName.data(), user.credentials.size(), + endpointId, static_cast(user.userName.size()), user.userName.data(), user.credentials.size(), user.userUniqueId, to_underlying(user.userType), to_underlying(user.credentialRule), user.createdBy, user.lastModifiedBy); return true; } -bool LockManager::SetUser(uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, +bool LockManager::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) { @@ -245,27 +341,32 @@ bool LockManager::SetUser(uint16_t userIndex, chip::FabricIndex creator, chip::F "Door Lock App: LockManager::SetUser " "[endpoint=%d,userIndex=%d,creator=%d,modifier=%d,userName=%s,uniqueId=%ld " "userStatus=%u,userType=%u,credentialRule=%u,credentials=%p,totalCredentials=%u]", - mEndpointId, userIndex, creator, modifier, userName.data(), uniqueId, to_underlying(userStatus), + endpointId, userIndex, creator, modifier, userName.data(), uniqueId, to_underlying(userStatus), to_underlying(usertype), to_underlying(credentialRule), credentials, totalCredentials); - auto & userInStorage = mLockUser; + VerifyOrReturnValue(userIndex > 0, false); // indices are one-indexed + + userIndex--; + + VerifyOrReturnValue(IsValidUserIndex(userIndex), false); + + auto & userInStorage = mLockUsers[userIndex]; if (userName.size() > DOOR_LOCK_MAX_USER_NAME_SIZE) { - ChipLogError(Zcl, "Cannot set user - user name is too long [endpoint=%d,index=%d]", mEndpointId, userIndex); + ChipLogError(Zcl, "Cannot set user - user name is too long [endpoint=%d,index=%d]", endpointId, userIndex); return false; } - if (totalCredentials > mMaxCredentialsPerUser) + if (totalCredentials > LockParams.numberOfCredentialsPerUser) { ChipLogError(Zcl, "Cannot set user - total number of credentials is too big [endpoint=%d,index=%d,totalCredentials=%u]", - mEndpointId, userIndex, totalCredentials); + endpointId, userIndex, totalCredentials); return false; } - chip::Platform::CopyString(mUserName, userName); - mUserName[userName.size()] = 0; - userInStorage.userName = chip::CharSpan(mUserName, userName.size()); + chip::Platform::CopyString(mUserNames[userIndex], userName); + userInStorage.userName = chip::CharSpan(mUserNames[userIndex], userName.size()); userInStorage.userUniqueId = uniqueId; userInStorage.userStatus = userStatus; userInStorage.userType = usertype; @@ -275,35 +376,54 @@ bool LockManager::SetUser(uint16_t userIndex, chip::FabricIndex creator, chip::F for (size_t i = 0; i < totalCredentials; ++i) { - mCredentials[i] = credentials[i]; - mCredentials[i].CredentialType = 1; - mCredentials[i].CredentialIndex = i + 1; + mCredentials[userIndex][i] = credentials[i]; + mCredentials[userIndex][i].CredentialType = 1; + mCredentials[userIndex][i].CredentialIndex = i + 1; } - userInStorage.credentials = chip::Span(mCredentials.Get(), totalCredentials); + userInStorage.credentials = chip::Span(mCredentials[userIndex], totalCredentials); // Save user information in NVM flash - CYW30739Config::WriteConfigValueBin(CYW30739Config::kConfigKey_LockUser, reinterpret_cast(&userInStorage), - sizeof(EmberAfPluginDoorLockUserInfo)); + CYW30739Config::WriteConfigValueBin(CYW30739Config::kConfigKey_LockUser, reinterpret_cast(&mLockUsers), + sizeof(EmberAfPluginDoorLockUserInfo) * LockParams.numberOfUsers); - CYW30739Config::WriteConfigValueBin(CYW30739Config::kConfigKey_UserCredentials, - reinterpret_cast(mCredentials.Get()), sizeof(DlCredential)); + CYW30739Config::WriteConfigValueBin(CYW30739Config::kConfigKey_UserCredentials, reinterpret_cast(mCredentials), + sizeof(DlCredential) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser); - CYW30739Config::WriteConfigValueStr(CYW30739Config::kConfigKey_LockUserName, mUserName, sizeof(userName.size())); + CYW30739Config::WriteConfigValueBin(CYW30739Config::kConfigKey_LockUserName, reinterpret_cast(mUserNames), + sizeof(mUserNames)); - ChipLogProgress(Zcl, "Successfully set the user [mEndpointId=%d,index=%d]", mEndpointId, userIndex); + ChipLogProgress(Zcl, "Successfully set the user [mEndpointId=%d,index=%d]", endpointId, userIndex); return true; } bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType, - EmberAfPluginDoorLockCredentialInfo & credential) const + EmberAfPluginDoorLockCredentialInfo & credential) { - ChipLogProgress(Zcl, "Lock App: LockManager::GetCredential [credentialType=%u]", to_underlying(credentialType)); - const auto & credentialInStorage = mLockCredentials; + VerifyOrReturnValue(credentialIndex > 0, false); // indices are one-indexed + + credentialIndex--; + + VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType), false); + + ChipLogProgress(Zcl, "Lock App: LockManager::GetCredential [credentialType=%u], credentialIndex=%d", + to_underlying(credentialType), credentialIndex); + + if (credentialType == DlCredentialType::kProgrammingPIN) + { + ChipLogError(Zcl, "Programming user not supported [credentialType=%u], credentialIndex=%d", to_underlying(credentialType), + credentialIndex); + + return true; + } + + const auto & credentialInStorage = mLockCredentials[credentialIndex]; credential.status = credentialInStorage.status; + ChipLogDetail(Zcl, "CredentialStatus: %d, CredentialIndex: %d ", (int) credential.status, credentialIndex); + if (DlCredentialStatus::kAvailable == credential.status) { ChipLogDetail(Zcl, "Found unoccupied credential "); @@ -311,6 +431,12 @@ 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()); @@ -318,44 +444,175 @@ bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credential 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) { + + VerifyOrReturnValue(credentialIndex > 0, false); // indices are one-indexed + + credentialIndex--; + + VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType), false); + 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[credentialIndex]; - auto & credentialInStorage = mLockCredentials; - if (credentialData.size() > DOOR_LOCK_CREDENTIAL_INFO_MAX_DATA_SIZE) - { - ChipLogError(Zcl, - "Cannot get the credential - data size exceeds limit " - "[dataSize=%u,maxDataSize=%u]", - credentialData.size(), DOOR_LOCK_CREDENTIAL_INFO_MAX_DATA_SIZE); - return false; - } credentialInStorage.status = credentialStatus; credentialInStorage.credentialType = credentialType; + credentialInStorage.createdBy = creator; + credentialInStorage.lastModifiedBy = modifier; - memcpy(mCredentialData, credentialData.data(), credentialData.size()); - mCredentialData[credentialData.size()] = 0; + memcpy(mCredentialData[credentialIndex], credentialData.data(), credentialData.size()); + credentialInStorage.credentialData = chip::ByteSpan{ mCredentialData[credentialIndex], credentialData.size() }; - credentialInStorage.credentialData = chip::ByteSpan{ mCredentialData, credentialData.size() }; - - // Save user information in NVM flash - CYW30739Config::WriteConfigValueBin(CYW30739Config::kConfigKey_Credential, - reinterpret_cast(&credentialInStorage), - sizeof(EmberAfPluginDoorLockCredentialInfo)); + // Save credential information in NVM flash + CYW30739Config::WriteConfigValueBin(CYW30739Config::kConfigKey_Credential, reinterpret_cast(&mLockCredentials), + sizeof(EmberAfPluginDoorLockCredentialInfo) * LockParams.numberOfCredentialsPerUser); CYW30739Config::WriteConfigValueBin(CYW30739Config::kConfigKey_CredentialData, - reinterpret_cast(&mCredentialData), credentialData.size()); + reinterpret_cast(&mCredentialData), sizeof(mCredentialData)); ChipLogProgress(Zcl, "Successfully set the credential [credentialType=%u]", to_underlying(credentialType)); return true; } +DlStatus LockManager::GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, + EmberAfPluginDoorLockWeekDaySchedule & schedule) +{ + + VerifyOrReturnValue(weekdayIndex > 0, DlStatus::kFailure); // indices are one-indexed + VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed + + weekdayIndex--; + userIndex--; + + VerifyOrReturnValue(IsValidWeekdayScheduleIndex(weekdayIndex), DlStatus::kFailure); + VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure); + + schedule = mWeekdaySchedule[userIndex][weekdayIndex]; + + return DlStatus::kSuccess; +} + +DlStatus LockManager::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) +{ + + VerifyOrReturnValue(weekdayIndex > 0, DlStatus::kFailure); // indices are one-indexed + VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed + + weekdayIndex--; + userIndex--; + + VerifyOrReturnValue(IsValidWeekdayScheduleIndex(weekdayIndex), DlStatus::kFailure); + VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure); + + auto & scheduleInStorage = mWeekdaySchedule[userIndex][weekdayIndex]; + + scheduleInStorage.daysMask = daysMask; + scheduleInStorage.startHour = startHour; + scheduleInStorage.startMinute = startMinute; + scheduleInStorage.endHour = endHour; + scheduleInStorage.endMinute = endMinute; + + // Save schedule information in NVM flash + CYW30739Config::WriteConfigValueBin( + CYW30739Config::kConfigKey_WeekDaySchedules, reinterpret_cast(mWeekdaySchedule), + sizeof(EmberAfPluginDoorLockWeekDaySchedule) * LockParams.numberOfWeekdaySchedulesPerUser * LockParams.numberOfUsers); + + return DlStatus::kSuccess; +} + +DlStatus LockManager::GetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, + EmberAfPluginDoorLockYearDaySchedule & schedule) +{ + VerifyOrReturnValue(yearDayIndex > 0, DlStatus::kFailure); // indices are one-indexed + VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed + + yearDayIndex--; + userIndex--; + + VerifyOrReturnValue(IsValidYeardayScheduleIndex(yearDayIndex), DlStatus::kFailure); + VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure); + + auto & scheduleInStorage = mYeardaySchedule[userIndex][yearDayIndex]; + + schedule = scheduleInStorage; + + return DlStatus::kSuccess; +} + +DlStatus LockManager::SetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, + DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime) +{ + VerifyOrReturnValue(yearDayIndex > 0, DlStatus::kFailure); // indices are one-indexed + VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed + + yearDayIndex--; + userIndex--; + + VerifyOrReturnValue(IsValidYeardayScheduleIndex(yearDayIndex), DlStatus::kFailure); + VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure); + + auto & scheduleInStorage = mYeardaySchedule[userIndex][yearDayIndex]; + + scheduleInStorage.localStartTime = localStartTime; + scheduleInStorage.localEndTime = localEndTime; + + // Save schedule information in NVM flash + CYW30739Config::WriteConfigValueBin( + CYW30739Config::kConfigKey_YearDaySchedules, reinterpret_cast(mYeardaySchedule), + sizeof(EmberAfPluginDoorLockYearDaySchedule) * LockParams.numberOfYeardaySchedulesPerUser * LockParams.numberOfUsers); + + return DlStatus::kSuccess; +} + +DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, + EmberAfPluginDoorLockHolidaySchedule & schedule) +{ + VerifyOrReturnValue(holidayIndex > 0, DlStatus::kFailure); // indices are one-indexed + + holidayIndex--; + + VerifyOrReturnValue(IsValidHolidayScheduleIndex(holidayIndex), DlStatus::kFailure); + + auto & scheduleInStorage = mHolidaySchedule[holidayIndex]; + + schedule = scheduleInStorage; + + return DlStatus::kSuccess; +} + +DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, + uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode) +{ + VerifyOrReturnValue(holidayIndex > 0, DlStatus::kFailure); // indices are one-indexed + + holidayIndex--; + + VerifyOrReturnValue(IsValidHolidayScheduleIndex(holidayIndex), DlStatus::kFailure); + + auto & scheduleInStorage = mHolidaySchedule[holidayIndex]; + + scheduleInStorage.localStartTime = localStartTime; + scheduleInStorage.localEndTime = localEndTime; + scheduleInStorage.operatingMode = operatingMode; + + // Save schedule information in NVM flash + CYW30739Config::WriteConfigValueBin(CYW30739Config::kConfigKey_HolidaySchedules, + reinterpret_cast(&(mHolidaySchedule)), + sizeof(EmberAfPluginDoorLockHolidaySchedule) * LockParams.numberOfHolidaySchedules); + + return DlStatus::kSuccess; +} + const char * LockManager::lockStateToString(DlLockState lockState) const { switch (lockState) @@ -378,30 +635,52 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat if (mState == kState_UnlockCompleted) curState = DlLockState::kUnlocked; - if (curState == lockState) + if ((curState == lockState) && (curState == DlLockState::kLocked)) { - ChipLogDetail(Zcl, "Door Lock App: door is already locked, set lock state to \"%s\" [endpointId=%d]", - lockStateToString(lockState), mEndpointId); + ChipLogDetail(Zcl, "Door Lock App: door is already locked, ignoring command to set lock state to \"%s\" [endpointId=%d]", + lockStateToString(lockState), endpointId); + return true; + } + else if ((curState == lockState) && (curState == DlLockState::kUnlocked)) + { + ChipLogDetail(Zcl, + "Door Lock App: door is already unlocked, ignoring command to set unlock state to \"%s\" [endpointId=%d]", + lockStateToString(lockState), endpointId); + return true; } + // Assume pin is required until told otherwise + bool requirePin = true; + chip::app::Clusters::DoorLock::Attributes::RequirePINforRemoteOperation::Get(endpointId, &requirePin); + + // If a pin code is not given if (!pin.HasValue()) { - ChipLogDetail(Zcl, "Door Lock App: PIN code is not specified, setting door lock state to \"%s\" [endpointId=%d]", - lockStateToString(lockState), mEndpointId); + ChipLogDetail(Zcl, "Door Lock App: PIN code is not specified, but it is required [endpointId=%d]", mEndpointId); curState = lockState; - return true; + // If a pin code is not required + if (!requirePin) + { + ChipLogDetail(Zcl, "Door Lock App: setting door lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState), + endpointId); + curState = lockState; + return true; + } + + return false; } // Check the PIN code - for (uint8_t i; i < 10; i++) + for (uint8_t i = 0; i < kMaxCredentials; i++) { - if (mLockCredentials.credentialType != DlCredentialType::kPin || mLockCredentials.status == DlCredentialStatus::kAvailable) + if (mLockCredentials[i].credentialType != DlCredentialType::kPin || + mLockCredentials[i].status == DlCredentialStatus::kAvailable) { continue; } - if (mLockCredentials.credentialData.data_equal(pin.Value())) + if (mLockCredentials[i].credentialData.data_equal(pin.Value())) { ChipLogDetail(Zcl, "Lock App: specified PIN code was found in the database, setting lock state to \"%s\" [endpointId=%d]", diff --git a/examples/lock-app/cyw30739/src/ZclCallbacks.cpp b/examples/lock-app/cyw30739/src/ZclCallbacks.cpp index ecbc2f78804b24..2b06dd4e1f3d1f 100644 --- a/examples/lock-app/cyw30739/src/ZclCallbacks.cpp +++ b/examples/lock-app/cyw30739/src/ZclCallbacks.cpp @@ -94,15 +94,17 @@ 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) { - return LockMgr().GetUser(userIndex, user); + return LockMgr().GetUser(endpointId, userIndex, user); } bool emberAfPluginDoorLockSetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, @@ -111,8 +113,8 @@ bool emberAfPluginDoorLockSetUser(chip::EndpointId endpointId, uint16_t userInde const DlCredential * credentials, size_t totalCredentials) { - return LockMgr().SetUser(userIndex, creator, modifier, userName, uniqueId, userStatus, usertype, credentialRule, credentials, - totalCredentials); + return LockMgr().SetUser(endpointId, userIndex, creator, modifier, userName, uniqueId, userStatus, usertype, credentialRule, + credentials, totalCredentials); } // TODO: These functions will be supported by door-lock-server in the future. These are set to return failure until implemented. diff --git a/examples/lock-app/cyw30739/src/main.cpp b/examples/lock-app/cyw30739/src/main.cpp index c214e63796e07e..4a32f49cfa2a9f 100644 --- a/examples/lock-app/cyw30739/src/main.cpp +++ b/examples/lock-app/cyw30739/src/main.cpp @@ -52,6 +52,7 @@ using namespace ::chip::DeviceLayer::Internal; using namespace ::chip::Credentials; using namespace ::chip::DeviceLayer; using namespace ::chip::Shell; +using namespace CYW30739DoorLock::LockInitParams; wiced_bool_t syncClusterToButtonAction = false; @@ -62,6 +63,7 @@ static void HandleThreadStateChangeEvent(const ChipDeviceEvent * event); static void ActionInitiated(LockManager::Action_t aAction, int32_t aActor); static void ActionCompleted(LockManager::Action_t aAction); static void WriteClusterState(uint8_t value); +static void UpdateClusterState(intptr_t context); #ifndef _countof #define _countof(a) (sizeof(a) / sizeof(a[0])) @@ -84,20 +86,20 @@ APPLICATION_START() wiced_result_t result; uint32_t i; - printf("\nChipLock App starting\n"); + ChipLogProgress(Zcl, "ChipLock App starting"); mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); err = chip::Platform::MemoryInit(); if (err != CHIP_NO_ERROR) { - printf("ERROR MemoryInit %ld\n", err.AsInteger()); + ChipLogError(Zcl, "ERROR MemoryInit %ld", err.AsInteger()); } result = app_button_init(); if (result != WICED_SUCCESS) { - printf("ERROR app_button_init %d\n", result); + ChipLogError(Zcl, "ERROR app_button_init %d", result); } /* Init. LED Manager. */ @@ -105,44 +107,44 @@ APPLICATION_START() { result = wiced_led_manager_init(&chip_lighting_led_config[i]); if (result != WICED_SUCCESS) - printf("wiced_led_manager_init fail i=%ld, (%d)\n", i, result); + ChipLogError(Zcl, "wiced_led_manager_init fail i=%ld, (%d)", i, result); } - printf("Initializing CHIP\n"); + ChipLogProgress(Zcl, "Initializing CHIP"); err = PlatformMgr().InitChipStack(); if (err != CHIP_NO_ERROR) { - printf("ERROR InitChipStack %ld\n", err.AsInteger()); + ChipLogError(Zcl, "ERROR InitChipStack %ld", err.AsInteger()); } #if CHIP_DEVICE_CONFIG_ENABLE_THREAD - printf("Initializing OpenThread stack\n"); + ChipLogProgress(Zcl, "Initializing OpenThread stack"); err = ThreadStackMgr().InitThreadStack(); if (err != CHIP_NO_ERROR) { - printf("ERROR InitThreadStack %ld\n", err.AsInteger()); + ChipLogError(Zcl, "ERROR InitThreadStack %ld", err.AsInteger()); } #endif err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router); if (err != CHIP_NO_ERROR) { - printf("ERROR SetThreadDeviceType %ld\n", err.AsInteger()); + ChipLogError(Zcl, "ERROR SetThreadDeviceType %ld", err.AsInteger()); } - printf("Starting event loop task\n"); + ChipLogProgress(Zcl, "Starting event loop task"); err = PlatformMgr().StartEventLoopTask(); if (err != CHIP_NO_ERROR) { - printf("ERROR StartEventLoopTask %ld\n", err.AsInteger()); + ChipLogError(Zcl, "ERROR StartEventLoopTask %ld", err.AsInteger()); } #if CHIP_DEVICE_CONFIG_ENABLE_THREAD - printf("Starting thread task\n"); + ChipLogProgress(Zcl, "Starting thread task"); err = ThreadStackMgr().StartThreadTask(); if (err != CHIP_NO_ERROR) { - printf("ERROR StartThreadTask %ld\n", err.AsInteger()); + ChipLogError(Zcl, "ERROR StartThreadTask %ld", err.AsInteger()); } #endif @@ -151,7 +153,7 @@ APPLICATION_START() const int ret = Engine::Root().Init(); if (!chip::ChipError::IsSuccess(ret)) { - printf("ERROR Shell Init %d\n", ret); + ChipLogError(Zcl, "ERROR Shell Init %d", ret); } RegisterAppShellCommands(); Engine::Root().RunMainLoop(); @@ -161,8 +163,7 @@ APPLICATION_START() void InitApp(intptr_t args) { - ConfigurationMgr().LogDeviceConfig(); - + CHIP_ERROR err = CHIP_NO_ERROR; PlatformMgrImpl().AddEventHandler(EventHandler, 0); /* Start CHIP datamodel server */ @@ -185,25 +186,72 @@ void InitApp(intptr_t args) chip::DeviceLayer::PlatformMgr().LockChipStack(); chip::app::Clusters::DoorLock::Attributes::LockState::Get(endpointId, state); - uint8_t maxCredentialsPerUser = 0; - if (!DoorLockServer::Instance().GetNumberOfCredentialsSupportedPerUser(endpointId, maxCredentialsPerUser)) + uint8_t numberOfCredentialsPerUser = 0; + if (!DoorLockServer::Instance().GetNumberOfCredentialsSupportedPerUser(endpointId, numberOfCredentialsPerUser)) { ChipLogError(Zcl, "Unable to get number of credentials supported per user when initializing lock endpoint, defaulting to 5 " "[endpointId=%d]", endpointId); - maxCredentialsPerUser = 5; + numberOfCredentialsPerUser = 5; } - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - CHIP_ERROR err = LockMgr().Init(state, maxCredentialsPerUser); - if (err != CHIP_NO_ERROR) + uint16_t numberOfUsers = 0; + if (!DoorLockServer::Instance().GetNumberOfUserSupported(endpointId, numberOfUsers)) { - printf("LockMgr().Init() failed\n"); + ChipLogError(Zcl, + "Unable to get number of supported users when initializing lock endpoint, defaulting to 10 [endpointId=%d]", + endpointId); + numberOfUsers = 10; } + uint8_t numberOfWeekdaySchedulesPerUser = 0; + if (!DoorLockServer::Instance().GetNumberOfWeekDaySchedulesPerUserSupported(endpointId, numberOfWeekdaySchedulesPerUser)) + { + ChipLogError( + Zcl, + "Unable to get number of supported weekday schedules when initializing lock endpoint, defaulting to 10 [endpointId=%d]", + endpointId); + numberOfWeekdaySchedulesPerUser = 10; + } + + uint8_t numberOfYeardaySchedulesPerUser = 0; + if (!DoorLockServer::Instance().GetNumberOfYearDaySchedulesPerUserSupported(endpointId, numberOfYeardaySchedulesPerUser)) + { + ChipLogError( + Zcl, + "Unable to get number of supported yearday schedules when initializing lock endpoint, defaulting to 10 [endpointId=%d]", + endpointId); + numberOfYeardaySchedulesPerUser = 10; + } + + uint8_t numberOfHolidaySchedules = 0; + if (!DoorLockServer::Instance().GetNumberOfHolidaySchedulesSupported(endpointId, numberOfHolidaySchedules)) + { + ChipLogError( + Zcl, + "Unable to get number of supported holiday schedules when initializing lock endpoint, defaulting to 10 [endpointId=%d]", + endpointId); + numberOfHolidaySchedules = 10; + } + + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); + + err = LockMgr().Init(state, + ParamBuilder() + .SetNumberOfUsers(numberOfUsers) + .SetNumberOfCredentialsPerUser(numberOfCredentialsPerUser) + .SetNumberOfWeekdaySchedulesPerUser(numberOfWeekdaySchedulesPerUser) + .SetNumberOfYeardaySchedulesPerUser(numberOfYeardaySchedulesPerUser) + .SetNumberOfHolidaySchedules(numberOfHolidaySchedules) + .GetLockParam()); + LockMgr().SetCallbacks(ActionInitiated, ActionCompleted); + chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast(nullptr)); + + ConfigurationMgr().LogDeviceConfig(); + #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR OTAConfig::Init(); #endif @@ -229,11 +277,11 @@ void ActionInitiated(LockManager::Action_t aAction, int32_t aActor) // and start flashing the LEDs rapidly to indicate action initiation. if (aAction == LockManager::LOCK_ACTION) { - printf("Lock Action has been initiated\n"); + ChipLogDetail(Zcl, "Lock Action has been initiated"); } else if (aAction == LockManager::UNLOCK_ACTION) { - printf("Unlock Action has been initiated\n"); + ChipLogDetail(Zcl, "Unlock Action has been initiated"); } if (aActor == LockManager::ACTOR_BUTTON) @@ -244,12 +292,12 @@ void ActionInitiated(LockManager::Action_t aAction, int32_t aActor) // Action initiated, update the light led if (aAction == LockManager::LOCK_ACTION) { - printf("Lock Action has been initiated"); + ChipLogDetail(Zcl, "Lock Action has been initiated"); wiced_led_manager_disable_led(PLATFORM_LED_2); } else if (aAction == LockManager::UNLOCK_ACTION) { - printf("Unlock Action has been initiated"); + ChipLogDetail(Zcl, "Unlock Action has been initiated"); wiced_led_manager_enable_led(PLATFORM_LED_2); } } @@ -267,7 +315,7 @@ void UpdateClusterState(intptr_t context) if (status != EMBER_ZCL_STATUS_SUCCESS) { - printf("ERR: updating lock state %x", status); + ChipLogError(Zcl, "ERR: updating lock state %x", status); } } @@ -278,11 +326,11 @@ void ActionCompleted(LockManager::Action_t aAction) // Turn off the lock LED if in an UNLOCKED state. if (aAction == LockManager::LOCK_ACTION) { - printf("Lock Action has been completed\n"); + ChipLogDetail(Zcl, "Lock Action has been completed"); } else if (aAction == LockManager::UNLOCK_ACTION) { - printf("Unlock Action has been completed\n"); + ChipLogDetail(Zcl, "Unlock Action has been completed"); } if (syncClusterToButtonAction) diff --git a/src/platform/CYW30739/CYW30739Config.h b/src/platform/CYW30739/CYW30739Config.h index 3ca513c114d604..21766b19d11a1c 100644 --- a/src/platform/CYW30739/CYW30739Config.h +++ b/src/platform/CYW30739/CYW30739Config.h @@ -80,13 +80,16 @@ class CYW30739Config static constexpr Key kConfigKey_LockUserName = CYW30739ConfigKey(kChipConfig_KeyBase, 0x0d); static constexpr Key kConfigKey_CredentialData = CYW30739ConfigKey(kChipConfig_KeyBase, 0x0e); static constexpr Key kConfigKey_UserCredentials = CYW30739ConfigKey(kChipConfig_KeyBase, 0x0f); - static constexpr Key kConfigKey_BootReason = CYW30739ConfigKey(kChipConfig_KeyBase, 0x10); + static constexpr Key kConfigKey_WeekDaySchedules = CYW30739ConfigKey(kChipConfig_KeyBase, 0x10); + static constexpr Key kConfigKey_YearDaySchedules = CYW30739ConfigKey(kChipConfig_KeyBase, 0x11); + static constexpr Key kConfigKey_HolidaySchedules = CYW30739ConfigKey(kChipConfig_KeyBase, 0x12); + static constexpr Key kConfigKey_BootReason = CYW30739ConfigKey(kChipConfig_KeyBase, 0x13); // Set key id limits for each group. static constexpr Key kMinConfigKey_ChipFactory = CYW30739ConfigKey(kChipFactory_KeyBase, 0x00); static constexpr Key kMaxConfigKey_ChipFactory = CYW30739ConfigKey(kChipFactory_KeyBase, 0x0a); static constexpr Key kMinConfigKey_ChipConfig = CYW30739ConfigKey(kChipConfig_KeyBase, 0x00); - static constexpr Key kMaxConfigKey_ChipConfig = CYW30739ConfigKey(kChipConfig_KeyBase, 0x10); + static constexpr Key kMaxConfigKey_ChipConfig = CYW30739ConfigKey(kChipConfig_KeyBase, 0x13); static CHIP_ERROR Init(void);