From f58216ba544961f18f9abfc80ce163aec799341b Mon Sep 17 00:00:00 2001 From: Morozov-5F Date: Tue, 21 Jun 2022 14:29:24 +0300 Subject: [PATCH] [#19563] Check enum ranges for Door Lock commands - Refactor the cluster, so it is consistent in way of handling commands --- .../door-lock-server/door-lock-server.cpp | 281 +++++++++--------- .../door-lock-server/door-lock-server.h | 157 ++++++---- 2 files changed, 254 insertions(+), 184 deletions(-) diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index 58c9384b33a42d..d216e9ad926992 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -230,7 +230,7 @@ bool DoorLockServer::GetNumberOfHolidaySchedulesSupported(chip::EndpointId endpo Attributes::NumberOfHolidaySchedulesSupported::Get, numberOfHolidaySchedules); } -void DoorLockServer::SetUserCommandHandler(chip::app::CommandHandler * commandObj, +void DoorLockServer::setUserCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::SetUser::DecodableType & commandData) { @@ -271,7 +271,8 @@ void DoorLockServer::SetUserCommandHandler(chip::app::CommandHandler * commandOb if (!userIndexValid(commandPath.mEndpointId, userIndex)) { - emberAfDoorLockClusterPrintln("[SetUser] User index out of bounds [userIndex=%d]", userIndex); + emberAfDoorLockClusterPrintln("[SetUser] User index out of bounds [endpointId=%d,userIndex=%d]", commandPath.mEndpointId, + userIndex); emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); return; } @@ -287,6 +288,27 @@ void DoorLockServer::SetUserCommandHandler(chip::app::CommandHandler * commandOb return; } + if (!userStatus.IsNull() && + (userStatus.Value() < DlUserStatus::kAvailable || userStatus.Value() > DlUserStatus::kOccupiedDisabled)) + { + emberAfDoorLockClusterPrintln( + "[SetUser] Unable to set the user: user status is out of range [endpointId=%d,userIndex=%d,userStatus=%u]", + commandPath.mEndpointId, userIndex, to_underlying(userStatus.Value())); + + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); + return; + } + + if (!userType.IsNull() && (userType.Value() < DlUserType::kUnrestrictedUser || userType.Value() > DlUserType::kRemoteOnlyUser)) + { + emberAfDoorLockClusterPrintln( + "[SetUser] Unable to set the user: user type is out of range [endpointId=%d,userIndex=%d,userType=%u]", + commandPath.mEndpointId, userIndex, to_underlying(userType.Value())); + + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); + return; + } + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; switch (operationType) { @@ -299,20 +321,21 @@ void DoorLockServer::SetUserCommandHandler(chip::app::CommandHandler * commandOb userType, credentialRule); break; case DlDataOperationType::kClear: + default: // appclusters, 5.2.4.34: SetUser command allow only kAdd/kModify, we should respond with INVALID_COMMAND if we got kClear + // or anything else status = EMBER_ZCL_STATUS_INVALID_COMMAND; + emberAfDoorLockClusterPrintln("[SetUser] Invalid operation type [endpointId=%d,operationType=%u]", commandPath.mEndpointId, + to_underlying(operationType)); break; } emberAfSendImmediateDefaultResponse(status); } -void DoorLockServer::GetUserCommandHandler(chip::app::CommandHandler * commandObj, - const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::GetUser::DecodableType & commandData) +void DoorLockServer::getUserCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint16_t userIndex) { - auto & userIndex = commandData.userIndex; - emberAfDoorLockClusterPrintln("[GetUser] Incoming command [endpointId=%d,userIndex=%d]", commandPath.mEndpointId, userIndex); if (!SupportsUSR(commandPath.mEndpointId)) @@ -412,11 +435,9 @@ void DoorLockServer::GetUserCommandHandler(chip::app::CommandHandler * commandOb } } -void DoorLockServer::ClearUserCommandHandler(chip::app::CommandHandler * commandObj, - const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::ClearUser::DecodableType & commandData) +void DoorLockServer::clearUserCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint16_t userIndex) { - auto & userIndex = commandData.userIndex; emberAfDoorLockClusterPrintln("[ClearUser] Incoming command [endpointId=%d,userIndex=%d]", commandPath.mEndpointId, userIndex); if (!SupportsUSR(commandPath.mEndpointId)) @@ -485,7 +506,7 @@ void DoorLockServer::ClearUserCommandHandler(chip::app::CommandHandler * command emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); } -void DoorLockServer::SetCredentialCommandHandler( +void DoorLockServer::setCredentialCommandHandler( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::SetCredential::DecodableType & commandData) { @@ -534,18 +555,19 @@ void DoorLockServer::SetCredentialCommandHandler( emberAfDoorLockClusterPrintln("[SetCredential] Credential index is out of range [endpointId=%d,credentialType=%u" ",credentialIndex=%d]", commandPath.mEndpointId, to_underlying(credentialType), credentialIndex); - sendSetCredentialResponse(commandObj, DlStatus::kInvalidField, 0, nextAvailableCredentialSlot); + sendSetCredentialResponse(commandObj, commandPath, DlStatus::kInvalidField, 0, nextAvailableCredentialSlot); return; } // appclusters, 5.2.4.40.3: If the credential data length is out of bounds we should return INVALID_COMMAND + // OPTIMIZE: we can move range checking to the single function size_t minSize, maxSize; if (!getCredentialRange(commandPath.mEndpointId, credentialType, minSize, maxSize)) { emberAfDoorLockClusterPrintln( "[SetCredential] Unable to get min/max range for credential: internal error [endpointId=%d,credentialIndex=%d]", commandPath.mEndpointId, credentialIndex); - sendSetCredentialResponse(commandObj, DlStatus::kFailure, 0, nextAvailableCredentialSlot); + sendSetCredentialResponse(commandObj, commandPath, DlStatus::kFailure, 0, nextAvailableCredentialSlot); return; } if (credentialData.size() < minSize || credentialData.size() > maxSize) @@ -554,7 +576,7 @@ void DoorLockServer::SetCredentialCommandHandler( "[endpointId=%d,credentialType=%u,minLength=%u,maxLength=%u,length=%u]", commandPath.mEndpointId, to_underlying(credentialType), static_cast(minSize), static_cast(maxSize), static_cast(credentialData.size())); - sendSetCredentialResponse(commandObj, DlStatus::kInvalidField, 0, nextAvailableCredentialSlot); + sendSetCredentialResponse(commandObj, commandPath, DlStatus::kInvalidField, 0, nextAvailableCredentialSlot); return; } @@ -567,7 +589,7 @@ void DoorLockServer::SetCredentialCommandHandler( emberAfDoorLockClusterPrintln("[SetCredential] Unable to get the credential to exclude duplicated entry " "[endpointId=%d,credentialType=%u,credentialIndex=%d]", commandPath.mEndpointId, to_underlying(credentialType), i); - sendSetCredentialResponse(commandObj, DlStatus::kFailure, 0, nextAvailableCredentialSlot); + sendSetCredentialResponse(commandObj, commandPath, DlStatus::kFailure, 0, nextAvailableCredentialSlot); return; } if (DlCredentialStatus::kAvailable != currentCredential.status && currentCredential.credentialType == credentialType && @@ -578,7 +600,7 @@ void DoorLockServer::SetCredentialCommandHandler( "[endpointId=%d,credentialType=%u,dataLength=%u,existingCredentialIndex=%d,credentialIndex=%d]", commandPath.mEndpointId, to_underlying(credentialType), static_cast(credentialData.size()), i, credentialIndex); - sendSetCredentialResponse(commandObj, DlStatus::kDuplicate, 0, nextAvailableCredentialSlot); + sendSetCredentialResponse(commandObj, commandPath, DlStatus::kDuplicate, 0, nextAvailableCredentialSlot); return; } } @@ -590,7 +612,27 @@ void DoorLockServer::SetCredentialCommandHandler( "[SetCredential] Unable to check if credential exists: app error [endpointId=%d,credentialIndex=%d]", commandPath.mEndpointId, credentialIndex); - sendSetCredentialResponse(commandObj, DlStatus::kFailure, 0, nextAvailableCredentialSlot); + sendSetCredentialResponse(commandObj, commandPath, DlStatus::kFailure, 0, nextAvailableCredentialSlot); + return; + } + + // OPTIMIZE: We can unify the checks for enum validity here and in set user command handler + if (!userStatus.IsNull() && + (userStatus.Value() < DlUserStatus::kAvailable || userStatus.Value() > DlUserStatus::kOccupiedDisabled)) + { + emberAfDoorLockClusterPrintln("[SetCredential] Unable to set the credential: user status is out of range " + "[endpointId=%d,credentialIndex=%d,userStatus=%u]", + commandPath.mEndpointId, credentialIndex, to_underlying(userStatus.Value())); + sendSetCredentialResponse(commandObj, commandPath, DlStatus::kInvalidField, 0, nextAvailableCredentialSlot); + return; + } + + if (!userType.IsNull() && (userType.Value() < DlUserType::kUnrestrictedUser || userType.Value() > DlUserType::kRemoteOnlyUser)) + { + emberAfDoorLockClusterPrintln("[SetCredential] Unable to set the credential: user type is out of range " + "[endpointId=%d,credentialIndex=%d,userType=%u]", + commandPath.mEndpointId, credentialIndex, to_underlying(userType.Value())); + sendSetCredentialResponse(commandObj, commandPath, DlStatus::kInvalidField, 0, nextAvailableCredentialSlot); return; } @@ -601,7 +643,7 @@ void DoorLockServer::SetCredentialCommandHandler( DlStatus status = createCredential(commandPath.mEndpointId, fabricIdx, sourceNodeId, credentialIndex, credentialType, existingCredential, credentialData, userIndex, userStatus, userType, createdUserIndex); - sendSetCredentialResponse(commandObj, status, createdUserIndex, nextAvailableCredentialSlot); + sendSetCredentialResponse(commandObj, commandPath, status, createdUserIndex, nextAvailableCredentialSlot); return; } case DlDataOperationType::kModify: { @@ -612,7 +654,7 @@ void DoorLockServer::SetCredentialCommandHandler( "[endpointId=%d,credentialIndex=%d]", commandPath.mEndpointId, credentialIndex); - sendSetCredentialResponse(commandObj, DlStatus::kInvalidField, 0, nextAvailableCredentialSlot); + sendSetCredentialResponse(commandObj, commandPath, DlStatus::kInvalidField, 0, nextAvailableCredentialSlot); return; } @@ -621,33 +663,28 @@ void DoorLockServer::SetCredentialCommandHandler( { auto status = modifyProgrammingPIN(commandPath.mEndpointId, fabricIdx, sourceNodeId, credentialIndex, credentialType, existingCredential, credentialData); - sendSetCredentialResponse(commandObj, status, 0, nextAvailableCredentialSlot); + sendSetCredentialResponse(commandObj, commandPath, status, 0, nextAvailableCredentialSlot); return; } auto status = modifyCredential(commandPath.mEndpointId, fabricIdx, sourceNodeId, credentialIndex, credentialType, existingCredential, credentialData, userIndex.Value(), userStatus, userType); - sendSetCredentialResponse(commandObj, status, 0, nextAvailableCredentialSlot); + sendSetCredentialResponse(commandObj, commandPath, status, 0, nextAvailableCredentialSlot); return; } case DlDataOperationType::kClear: + default: // appclusters, 5.2.4.40: set credential command supports only Add and Modify operational type. - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); - return; + sendSetCredentialResponse(commandObj, commandPath, DlStatus::kInvalidField, 0, nextAvailableCredentialSlot); } - - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); } -void DoorLockServer::GetCredentialStatusCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::GetCredentialStatus::DecodableType & commandData) +void DoorLockServer::getCredentialStatusCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, + DlCredentialType credentialType, uint16_t credentialIndex) { emberAfDoorLockClusterPrintln("[GetCredentialStatus] Incoming command [endpointId=%d]", commandPath.mEndpointId); - const auto & credentialType = commandData.credential.credentialType; - const auto & credentialIndex = commandData.credential.credentialIndex; - if (!credentialTypeSupported(commandPath.mEndpointId, credentialType)) { emberAfDoorLockClusterPrintln("[GetCredentialStatus] Credential type is not supported [endpointId=%d,credentialType=%u" @@ -726,7 +763,7 @@ void DoorLockServer::GetCredentialStatusCommandHandler( nextCredentialIndex); } -void DoorLockServer::ClearCredentialCommandHandler( +void DoorLockServer::clearCredentialCommandHandler( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearCredential::DecodableType & commandData) { @@ -767,9 +804,10 @@ void DoorLockServer::ClearCredentialCommandHandler( clearCredential(commandPath.mEndpointId, modifier, sourceNodeId, credentialType, credentialIndex, false)); } -void DoorLockServer::SetWeekDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::SetWeekDaySchedule::DecodableType & commandData) +void DoorLockServer::setWeekDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t weekDayIndex, + uint16_t userIndex, const chip::BitMask & daysMask, + uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute) { auto endpointId = commandPath.mEndpointId; if (!SupportsSchedules(endpointId)) @@ -797,20 +835,12 @@ void DoorLockServer::SetWeekDayScheduleCommandHandler( return; } - auto weekDayIndex = commandData.weekDayIndex; - auto userIndex = commandData.userIndex; - const auto & daysMask = commandData.daysMask; - auto startHour = commandData.startHour; - auto startMinute = commandData.startMinute; - auto endHour = commandData.endHour; - auto endMinute = commandData.endMinute; - if (!weekDayIndexValid(endpointId, weekDayIndex) || !userIndexValid(endpointId, userIndex)) { emberAfDoorLockClusterPrintln( "[SetWeekDaySchedule] Unable to add schedule - index out of range [endpointId=%d,weekDayIndex=%d,userIndex=%d]", endpointId, weekDayIndex, userIndex); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_FIELD); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); return; } @@ -832,12 +862,13 @@ void DoorLockServer::SetWeekDayScheduleCommandHandler( rawDaysMask = static_cast(rawDaysMask >> 1); } + // TODO: Check that bits are within range if (setBitsInDaysMask == 0 || setBitsInDaysMask > 1) { emberAfDoorLockClusterPrintln("[SetWeekDaySchedule] Unable to add schedule - daysMask is out of range " "[endpointId=%d,weekDayIndex=%d,userIndex=%d,daysMask=%x]", endpointId, weekDayIndex, userIndex, daysMask.Raw()); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_FIELD); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); return; } @@ -847,7 +878,7 @@ void DoorLockServer::SetWeekDayScheduleCommandHandler( emberAfDoorLockClusterPrintln("[SetWeekDaySchedule] Unable to add schedule - start time out of range " "[endpointId=%d,weekDayIndex=%d,userIndex=%d,startTime=\"%d:%d\",endTime=\"%d:%d\"]", endpointId, weekDayIndex, userIndex, startHour, startMinute, endHour, endMinute); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_FIELD); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); return; } @@ -856,7 +887,7 @@ void DoorLockServer::SetWeekDayScheduleCommandHandler( emberAfDoorLockClusterPrintln("[SetWeekDaySchedule] Unable to add schedule - invalid time " "[endpointId=%d,weekDayIndex=%d,userIndex=%d,startTime=\"%d:%d\",endTime=\"%d:%d\"]", endpointId, weekDayIndex, userIndex, startHour, startMinute, endHour, endMinute); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_FIELD); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); return; } @@ -882,9 +913,9 @@ void DoorLockServer::SetWeekDayScheduleCommandHandler( emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); } -void DoorLockServer::GetWeekDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::GetWeekDaySchedule::DecodableType & commandData) +void DoorLockServer::getWeekDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t weekDayIndex, + uint16_t userIndex) { auto endpointId = commandPath.mEndpointId; if (!SupportsSchedules(endpointId)) @@ -896,9 +927,6 @@ void DoorLockServer::GetWeekDayScheduleCommandHandler( emberAfDoorLockClusterPrintln("[GetWeekDaySchedule] Incoming command [endpointId=%d]", endpointId); - auto weekDayIndex = commandData.weekDayIndex; - auto userIndex = commandData.userIndex; - if (!weekDayIndexValid(endpointId, weekDayIndex) || !userIndexValid(endpointId, userIndex)) { emberAfDoorLockClusterPrintln( @@ -928,9 +956,9 @@ void DoorLockServer::GetWeekDayScheduleCommandHandler( scheduleInfo.startHour, scheduleInfo.startMinute, scheduleInfo.endHour, scheduleInfo.endMinute); } -void DoorLockServer::ClearWeekDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::ClearWeekDaySchedule::DecodableType & commandData) +void DoorLockServer::clearWeekDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t weekDayIndex, + uint16_t userIndex) { auto endpointId = commandPath.mEndpointId; if (!SupportsSchedules(endpointId)) @@ -958,9 +986,6 @@ void DoorLockServer::ClearWeekDayScheduleCommandHandler( return; } - auto weekDayIndex = commandData.weekDayIndex; - auto userIndex = commandData.userIndex; - if (!userIndexValid(endpointId, userIndex) || (!weekDayIndexValid(endpointId, weekDayIndex) && 0xFE != weekDayIndex)) { emberAfDoorLockClusterPrintln( @@ -1008,9 +1033,9 @@ void DoorLockServer::ClearWeekDayScheduleCommandHandler( emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); } -void DoorLockServer::SetYearDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::SetYearDaySchedule::DecodableType & commandData) +void DoorLockServer::setYearDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t yearDayIndex, + uint16_t userIndex, uint32_t localStartTime, uint32_t localEndTime) { auto endpointId = commandPath.mEndpointId; if (!SupportsSchedules(endpointId)) @@ -1038,17 +1063,12 @@ void DoorLockServer::SetYearDayScheduleCommandHandler( return; } - auto yearDayIndex = commandData.yearDayIndex; - auto userIndex = commandData.userIndex; - auto localStarTime = commandData.localStartTime; - auto localEndTime = commandData.localEndTime; - if (!yearDayIndexValid(endpointId, yearDayIndex) || !userIndexValid(endpointId, userIndex)) { emberAfDoorLockClusterPrintln( "[SetYearDaySchedule] Unable to add schedule - index out of range [endpointId=%d,yearDayIndex=%d,userIndex=%d]", endpointId, yearDayIndex, userIndex); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_FIELD); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); return; } @@ -1061,17 +1081,17 @@ void DoorLockServer::SetYearDayScheduleCommandHandler( return; } - if (localEndTime <= localStarTime) + if (localEndTime <= localStartTime) { emberAfDoorLockClusterPrintln("[SetYearDaySchedule] Unable to add schedule - schedule ends earlier than starts" "[endpointId=%d,yearDayIndex=%d,userIndex=%d,localStarTime=%" PRIu32 ",localEndTime=%" PRIu32 "]", - endpointId, yearDayIndex, userIndex, localStarTime, localEndTime); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_FIELD); + endpointId, yearDayIndex, userIndex, localStartTime, localEndTime); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); return; } - auto status = emberAfPluginDoorLockSetSchedule(endpointId, yearDayIndex, userIndex, DlScheduleStatus::kOccupied, localStarTime, + auto status = emberAfPluginDoorLockSetSchedule(endpointId, yearDayIndex, userIndex, DlScheduleStatus::kOccupied, localStartTime, localEndTime); if (DlStatus::kSuccess != status) { @@ -1085,7 +1105,7 @@ void DoorLockServer::SetYearDayScheduleCommandHandler( emberAfDoorLockClusterPrintln("[SetYearDaySchedule] Successfully created new schedule " "[endpointId=%d,yearDayIndex=%d,userIndex=%d,localStartTime=%" PRIu32 ",endTime=%" PRIu32 "]", - endpointId, yearDayIndex, userIndex, localStarTime, localEndTime); + endpointId, yearDayIndex, userIndex, localStartTime, localEndTime); sendRemoteLockUserChange(endpointId, DlLockDataType::kYearDaySchedule, DlDataOperationType::kAdd, sourceNodeId, fabricIdx, userIndex, static_cast(yearDayIndex)); @@ -1093,9 +1113,9 @@ void DoorLockServer::SetYearDayScheduleCommandHandler( emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); } -void DoorLockServer::GetYearDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::GetYearDaySchedule::DecodableType & commandData) +void DoorLockServer::getYearDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t yearDayIndex, + uint16_t userIndex) { auto endpointId = commandPath.mEndpointId; if (!SupportsSchedules(endpointId)) @@ -1106,9 +1126,6 @@ void DoorLockServer::GetYearDayScheduleCommandHandler( } emberAfDoorLockClusterPrintln("[GetYearDaySchedule] incoming command [endpointId=%d]", endpointId); - auto yearDayIndex = commandData.yearDayIndex; - auto userIndex = commandData.userIndex; - if (!yearDayIndexValid(endpointId, yearDayIndex) || !userIndexValid(endpointId, userIndex)) { emberAfDoorLockClusterPrintln( @@ -1138,9 +1155,9 @@ void DoorLockServer::GetYearDayScheduleCommandHandler( scheduleInfo.localStartTime, scheduleInfo.localEndTime); } -void DoorLockServer::ClearYearDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::ClearYearDaySchedule::DecodableType & commandData) +void DoorLockServer::clearYearDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t yearDayIndex, + uint16_t userIndex) { auto endpointId = commandPath.mEndpointId; if (!SupportsSchedules(endpointId)) @@ -1167,9 +1184,6 @@ void DoorLockServer::ClearYearDayScheduleCommandHandler( return; } - auto yearDayIndex = commandData.yearDayIndex; - auto userIndex = commandData.userIndex; - if (!userIndexValid(endpointId, userIndex) || (!yearDayIndexValid(endpointId, yearDayIndex) && 0xFE != yearDayIndex)) { emberAfDoorLockClusterPrintln( @@ -2257,32 +2271,21 @@ DlStatus DoorLockServer::modifyCredential(chip::EndpointId endpointId, chip::Fab return status; } -CHIP_ERROR DoorLockServer::sendSetCredentialResponse(chip::app::CommandHandler * commandObj, DlStatus status, uint16_t userIndex, - uint16_t nextCredentialIndex) +void DoorLockServer::sendSetCredentialResponse(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, DlStatus status, + uint16_t userIndex, uint16_t nextCredentialIndex) { - CHIP_ERROR err = CHIP_NO_ERROR; - - using ResponseFields = Commands::SetCredentialResponse::Fields; - - app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ::Id, Commands::SetCredentialResponse::Id }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(path)); - VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = writer->Put(TLV::ContextTag(to_underlying(ResponseFields::kStatus)), status)); - + Commands::SetCredentialResponse::Type command{}; + command.status = status; if (0 != userIndex) { - SuccessOrExit(err = writer->Put(TLV::ContextTag(to_underlying(ResponseFields::kUserIndex)), userIndex)); + command.userIndex.SetNonNull(userIndex); } - if (0 != nextCredentialIndex) { - SuccessOrExit(err = writer->Put(TLV::ContextTag(to_underlying(ResponseFields::kNextCredentialIndex)), nextCredentialIndex)); + command.nextCredentialIndex.SetNonNull(nextCredentialIndex); } - SuccessOrExit(err = commandObj->FinishCommand()); - -exit: - return err; + commandObj->AddResponse(commandPath, command); } bool DoorLockServer::credentialTypeSupported(chip::EndpointId endpointId, DlCredentialType type) @@ -2951,9 +2954,9 @@ DlLockDataType DoorLockServer::credentialTypeToLockDataType(DlCredentialType cre return DlLockDataType::kUnspecified; } -void DoorLockServer::setHolidaySchedule(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - uint8_t holidayIndex, uint32_t localStartTime, uint32_t localEndTime, - DlOperatingMode operatingMode) +void DoorLockServer::setHolidayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t holidayIndex, + uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode) { VerifyOrDie(nullptr != commandObj); @@ -2972,7 +2975,7 @@ void DoorLockServer::setHolidaySchedule(chip::app::CommandHandler * commandObj, emberAfDoorLockClusterPrintln( "[SetHolidaySchedule] Unable to add schedule - index out of range [endpointId=%d,scheduleIndex=%d]", endpointId, holidayIndex); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_FIELD); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); return; } @@ -2981,17 +2984,17 @@ void DoorLockServer::setHolidaySchedule(chip::app::CommandHandler * commandObj, emberAfDoorLockClusterPrintln("[SetHolidaySchedule] Unable to add schedule - schedule ends earlier than starts" "[endpointId=%d,scheduleIndex=%d,localStarTime=%" PRIu32 ",localEndTime=%" PRIu32 "]", endpointId, holidayIndex, localStartTime, localEndTime); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_FIELD); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); return; } - if (operatingMode > DlOperatingMode::kPassage) + if (operatingMode > DlOperatingMode::kPassage || operatingMode < DlOperatingMode::kNormal) { emberAfDoorLockClusterPrintln("[SetHolidaySchedule] Unable to add schedule - operating mode is out of range" "[endpointId=%d,scheduleIndex=%d,localStarTime=%" PRIu32 ",localEndTime=%" PRIu32 ", operatingMode=%d]", endpointId, holidayIndex, localStartTime, localEndTime, to_underlying(operatingMode)); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_FIELD); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND); return; } @@ -3013,8 +3016,8 @@ void DoorLockServer::setHolidaySchedule(chip::app::CommandHandler * commandObj, emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); } -void DoorLockServer::getHolidaySchedule(chip::app::CommandHandler * commandObj, const ConcreteCommandPath & commandPath, - uint8_t holidayIndex) +void DoorLockServer::getHolidayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const ConcreteCommandPath & commandPath, uint8_t holidayIndex) { auto endpointId = commandPath.mEndpointId; if (!SupportsSchedules(endpointId)) @@ -3047,8 +3050,8 @@ void DoorLockServer::getHolidaySchedule(chip::app::CommandHandler * commandObj, scheduleInfo.localEndTime, scheduleInfo.operatingMode); } -void DoorLockServer::clearHolidaySchedule(chip::app::CommandHandler * commandObj, - const chip::app::ConcreteCommandPath & commandPath, uint8_t holidayIndex) +void DoorLockServer::clearHolidayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t holidayIndex) { auto endpointId = commandPath.mEndpointId; if (!SupportsSchedules(endpointId)) @@ -3354,7 +3357,7 @@ bool emberAfDoorLockClusterSetUserCallback(chip::app::CommandHandler * commandOb const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::SetUser::DecodableType & commandData) { - DoorLockServer::Instance().SetUserCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().setUserCommandHandler(commandObj, commandPath, commandData); return true; } @@ -3362,7 +3365,7 @@ bool emberAfDoorLockClusterGetUserCallback(chip::app::CommandHandler * commandOb const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::GetUser::DecodableType & commandData) { - DoorLockServer::Instance().GetUserCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().getUserCommandHandler(commandObj, commandPath, commandData.userIndex); return true; } @@ -3370,7 +3373,7 @@ bool emberAfDoorLockClusterClearUserCallback(chip::app::CommandHandler * command const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearUser::DecodableType & commandData) { - DoorLockServer::Instance().ClearUserCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().clearUserCommandHandler(commandObj, commandPath, commandData.userIndex); return true; } @@ -3378,7 +3381,7 @@ bool emberAfDoorLockClusterSetCredentialCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::SetCredential::DecodableType & commandData) { - DoorLockServer::Instance().SetCredentialCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().setCredentialCommandHandler(commandObj, commandPath, commandData); return true; } @@ -3386,7 +3389,8 @@ bool emberAfDoorLockClusterGetCredentialStatusCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::GetCredentialStatus::DecodableType & commandData) { - DoorLockServer::Instance().GetCredentialStatusCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().getCredentialStatusCommandHandler(commandObj, commandPath, commandData.credential.credentialType, + commandData.credential.credentialIndex); return true; } @@ -3394,7 +3398,7 @@ bool emberAfDoorLockClusterClearCredentialCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearCredential::DecodableType & commandData) { - DoorLockServer::Instance().ClearCredentialCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().clearCredentialCommandHandler(commandObj, commandPath, commandData); return true; } @@ -3402,7 +3406,9 @@ bool emberAfDoorLockClusterSetWeekDayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::SetWeekDaySchedule::DecodableType & commandData) { - DoorLockServer::Instance().SetWeekDayScheduleCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().setWeekDayScheduleCommandHandler( + commandObj, commandPath, commandData.weekDayIndex, commandData.userIndex, commandData.daysMask, commandData.startHour, + commandData.startMinute, commandData.endHour, commandData.endMinute); return true; } @@ -3410,7 +3416,8 @@ bool emberAfDoorLockClusterGetWeekDayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::GetWeekDaySchedule::DecodableType & commandData) { - DoorLockServer::Instance().GetWeekDayScheduleCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().getWeekDayScheduleCommandHandler(commandObj, commandPath, commandData.weekDayIndex, + commandData.userIndex); return true; } @@ -3418,7 +3425,8 @@ bool emberAfDoorLockClusterClearWeekDayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearWeekDaySchedule::DecodableType & commandData) { - DoorLockServer::Instance().ClearWeekDayScheduleCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().clearWeekDayScheduleCommandHandler(commandObj, commandPath, commandData.weekDayIndex, + commandData.userIndex); return true; } @@ -3426,7 +3434,9 @@ bool emberAfDoorLockClusterSetYearDayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::SetYearDaySchedule::DecodableType & commandData) { - DoorLockServer::Instance().SetYearDayScheduleCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().setYearDayScheduleCommandHandler(commandObj, commandPath, commandData.yearDayIndex, + commandData.userIndex, commandData.localStartTime, + commandData.localEndTime); return true; } @@ -3434,7 +3444,8 @@ bool emberAfDoorLockClusterGetYearDayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::GetYearDaySchedule::DecodableType & commandData) { - DoorLockServer::Instance().GetYearDayScheduleCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().getYearDayScheduleCommandHandler(commandObj, commandPath, commandData.yearDayIndex, + commandData.userIndex); return true; } @@ -3442,7 +3453,8 @@ bool emberAfDoorLockClusterClearYearDayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearYearDaySchedule::DecodableType & commandData) { - DoorLockServer::Instance().ClearYearDayScheduleCommandHandler(commandObj, commandPath, commandData); + DoorLockServer::Instance().clearYearDayScheduleCommandHandler(commandObj, commandPath, commandData.yearDayIndex, + commandData.userIndex); return true; } @@ -3450,8 +3462,9 @@ bool emberAfDoorLockClusterSetHolidayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::SetHolidaySchedule::DecodableType & commandData) { - DoorLockServer::Instance().setHolidaySchedule(commandObj, commandPath, commandData.holidayIndex, commandData.localStartTime, - commandData.localEndTime, commandData.operatingMode); + DoorLockServer::Instance().setHolidayScheduleCommandHandler(commandObj, commandPath, commandData.holidayIndex, + commandData.localStartTime, commandData.localEndTime, + commandData.operatingMode); return true; } @@ -3459,7 +3472,7 @@ bool emberAfDoorLockClusterGetHolidayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::GetHolidaySchedule::DecodableType & commandData) { - DoorLockServer::Instance().getHolidaySchedule(commandObj, commandPath, commandData.holidayIndex); + DoorLockServer::Instance().getHolidayScheduleCommandHandler(commandObj, commandPath, commandData.holidayIndex); return true; } @@ -3467,7 +3480,7 @@ bool emberAfDoorLockClusterClearHolidayScheduleCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearHolidaySchedule::DecodableType & commandData) { - DoorLockServer::Instance().clearHolidaySchedule(commandObj, commandPath, commandData.holidayIndex); + DoorLockServer::Instance().clearHolidayScheduleCommandHandler(commandObj, commandPath, commandData.holidayIndex); return true; } @@ -3583,9 +3596,9 @@ MatterDoorLockClusterServerPreAttributeChangedCallback(const chip::app::Concrete return res; } -void emberAfPluginDoorLockServerLockoutEventHandler(void) {} +void emberAfPluginDoorLockServerLockoutEventHandler() {} -void emberAfPluginDoorLockServerRelockEventHandler(void) {} +void emberAfPluginDoorLockServerRelockEventHandler() {} void MatterDoorLockPluginServerInitCallback() { diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index d7289c4bd2c094..53b028f0f80462 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -117,45 +117,6 @@ class DoorLockServer bool GetNumberOfCredentialsSupportedPerUser(chip::EndpointId endpointId, uint8_t & numberOfCredentialsSupportedPerUser); bool GetNumberOfHolidaySchedulesSupported(chip::EndpointId endpointId, uint8_t & numberOfHolidaySchedules); - void SetUserCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::SetUser::DecodableType & commandData); - - void GetUserCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::GetUser::DecodableType & commandData); - - void ClearUserCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::ClearUser::DecodableType & commandData); - - void SetCredentialCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::SetCredential::DecodableType & commandData); - - void GetCredentialStatusCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::GetCredentialStatus::DecodableType & commandData); - - void ClearCredentialCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::ClearCredential::DecodableType & commandData); - - void SetWeekDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::SetWeekDaySchedule::DecodableType & commandData); - void GetWeekDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::GetWeekDaySchedule::DecodableType & commandData); - void ClearWeekDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::ClearWeekDaySchedule::DecodableType & commandData); - - void SetYearDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::SetYearDaySchedule::DecodableType & commandData); - void GetYearDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::GetYearDaySchedule::DecodableType & commandData); - void ClearYearDayScheduleCommandHandler( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::DoorLock::Commands::ClearYearDaySchedule::DecodableType & commandData); - bool HasFeature(chip::EndpointId endpointId, DoorLockFeature feature); inline bool SupportsPIN(chip::EndpointId endpointId) { return HasFeature(endpointId, DoorLockFeature::kPINCredentials); } @@ -263,10 +224,12 @@ class DoorLockServer bool clearFabricFromCredentials(chip::EndpointId endpointId, DlCredentialType credentialType, chip::FabricIndex fabricToRemove); bool clearFabricFromCredentials(chip::EndpointId endpointId, chip::FabricIndex fabricToRemove); - CHIP_ERROR sendSetCredentialResponse(chip::app::CommandHandler * commandObj, DlStatus status, uint16_t userIndex, - uint16_t nextCredentialIndex); + void sendSetCredentialResponse(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + DlStatus status, uint16_t userIndex, uint16_t nextCredentialIndex); // TODO: Maybe use CHIP_APPLICATION_ERROR instead of boolean in class methods? + // OPTIMIZE: there are a lot of methods such as this that could be made static which could help reduce the stack footprint + // in case of multiple lock endpoints bool credentialTypeSupported(chip::EndpointId endpointId, DlCredentialType type); bool weekDayIndexValid(chip::EndpointId endpointId, uint8_t weekDayIndex); @@ -304,14 +267,57 @@ class DoorLockServer DlLockDataType credentialTypeToLockDataType(DlCredentialType credentialType); - void setHolidaySchedule(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - uint8_t holidayIndex, uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode); + void setUserCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::SetUser::DecodableType & commandData); + + void getUserCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + uint16_t userIndex); + + void clearUserCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + uint16_t userIndex); + + void setCredentialCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::SetCredential::DecodableType & commandData); + + void getCredentialStatusCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, DlCredentialType credentialType, + uint16_t credentialIndex); + + void clearCredentialCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::ClearCredential::DecodableType & commandData); + + void setWeekDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t weekDayIndex, + uint16_t userIndex, const chip::BitMask & daysMask, uint8_t startHour, + uint8_t startMinute, uint8_t endHour, uint8_t endMinute); + + void getWeekDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t weekDayIndex, + uint16_t userIndex); + + void clearWeekDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t weekDayIndex, + uint16_t userIndex); + + void setYearDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t yearDayIndex, + uint16_t userIndex, uint32_t localStartTime, uint32_t localEndTime); + void getYearDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t yearDayIndex, + uint16_t userIndex); + void clearYearDayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t yearDayIndex, + uint16_t userIndex); + + void setHolidayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t holidayIndex, + uint32_t localStartTime, uint32_t localEndTime, DlOperatingMode operatingMode); - void getHolidaySchedule(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - uint8_t holidayIndex); + void getHolidayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t holidayIndex); - void clearHolidaySchedule(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - uint8_t holidayIndex); + void clearHolidayScheduleCommandHandler(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, uint8_t holidayIndex); bool RemoteOperationEnabled(chip::EndpointId endpointId) const; @@ -323,8 +329,8 @@ class DoorLockServer * @param opType remote operation type (lock, unlock) * @param opHandler plugin handler for specified command * @param pinCode pin code passed by client - * @return true if locking/unlocking was successfull - * @return false if error happenned during lock/unlock + * @return true if locking/unlocking was successful + * @return false if error happened during lock/unlock */ bool HandleRemoteLockOperation(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, DlLockOperationType opType, RemoteLockOpHandler opHandler, @@ -342,7 +348,7 @@ class DoorLockServer * @param nodeId node id * @param credList list of credentials used in lock operation (can be NULL if no credentials were used) * @param credListSize size of credentials list (if 0, then no credentials were used) - * @param opSuccess flags if operation was successfull or not + * @param opSuccess flags if operation was successful or not */ void SendLockOperationEvent(chip::EndpointId endpointId, DlLockOperationType opType, DlOperationSource opSource, DlOperationError opErr, const Nullable & userId, @@ -424,6 +430,57 @@ class DoorLockServer chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DoorLock::Commands::ClearHolidaySchedule::DecodableType & commandData); + friend bool + emberAfDoorLockClusterSetUserCallback(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::SetUser::DecodableType & commandData); + + friend bool + emberAfDoorLockClusterGetUserCallback(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::GetUser::DecodableType & commandData); + + friend bool + emberAfDoorLockClusterClearUserCallback(chip::app::CommandHandler * commandObj, + const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::ClearUser::DecodableType & commandData); + + friend bool emberAfDoorLockClusterSetCredentialCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::SetCredential::DecodableType & commandData); + + friend bool emberAfDoorLockClusterGetCredentialStatusCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::GetCredentialStatus::DecodableType & commandData); + + friend bool emberAfDoorLockClusterClearCredentialCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::ClearCredential::DecodableType & commandData); + + friend bool emberAfDoorLockClusterSetWeekDayScheduleCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::SetWeekDaySchedule::DecodableType & commandData); + + friend bool emberAfDoorLockClusterGetWeekDayScheduleCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::GetWeekDaySchedule::DecodableType & commandData); + + friend bool emberAfDoorLockClusterClearWeekDayScheduleCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::ClearWeekDaySchedule::DecodableType & commandData); + + friend bool emberAfDoorLockClusterSetYearDayScheduleCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::SetYearDaySchedule::DecodableType & commandData); + + friend bool emberAfDoorLockClusterGetYearDayScheduleCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::GetYearDaySchedule::DecodableType & commandData); + + friend bool emberAfDoorLockClusterClearYearDayScheduleCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::DoorLock::Commands::ClearYearDaySchedule::DecodableType & commandData); + EmberEventControl AutolockEvent; /**< for automatic relock scheduling */ static DoorLockServer instance;