|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2020-2024 Project CHIP Authors |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +#include <app/data-model/Nullable.h> |
| 20 | +#include <app/util/af.h> |
| 21 | +#include <lib/core/DataModelTypes.h> |
| 22 | + |
| 23 | +#ifdef MATTER_DM_PLUGIN_DOOR_LOCK_SERVER |
| 24 | +#include "chef-lock-manager.h" |
| 25 | +#include <app/clusters/door-lock-server/door-lock-server.h> |
| 26 | + |
| 27 | +using namespace chip; |
| 28 | +using namespace chip::app::Clusters; |
| 29 | +using namespace chip::app::Clusters::DoorLock; |
| 30 | +using chip::app::DataModel::Nullable; |
| 31 | + |
| 32 | +// ============================================================================= |
| 33 | +// 'Default' callbacks for cluster commands |
| 34 | +// ============================================================================= |
| 35 | + |
| 36 | +// App handles physical aspects of locking but not locking logic. That is it |
| 37 | +// should wait for door to be locked on lock command and return success) but |
| 38 | +// door lock server should check pin before even calling the lock-door |
| 39 | +// callback. |
| 40 | +bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx, |
| 41 | + const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode, |
| 42 | + OperationErrorEnum & err) |
| 43 | +{ |
| 44 | + return LockManager::Instance().Lock(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote); |
| 45 | +} |
| 46 | + |
| 47 | +bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx, |
| 48 | + const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode, |
| 49 | + OperationErrorEnum & err) |
| 50 | +{ |
| 51 | + return LockManager::Instance().Unlock(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote); |
| 52 | +} |
| 53 | + |
| 54 | +bool emberAfPluginDoorLockOnDoorUnboltCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx, |
| 55 | + const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode, |
| 56 | + OperationErrorEnum & err) |
| 57 | +{ |
| 58 | + return LockManager::Instance().Unbolt(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote); |
| 59 | +} |
| 60 | + |
| 61 | +bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) |
| 62 | +{ |
| 63 | + return LockManager::Instance().GetUser(endpointId, userIndex, user); |
| 64 | +} |
| 65 | + |
| 66 | +bool emberAfPluginDoorLockSetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, |
| 67 | + chip::FabricIndex modifier, const chip::CharSpan & userName, uint32_t uniqueId, |
| 68 | + UserStatusEnum userStatus, UserTypeEnum usertype, CredentialRuleEnum credentialRule, |
| 69 | + const CredentialStruct * credentials, size_t totalCredentials) |
| 70 | +{ |
| 71 | + |
| 72 | + return LockManager::Instance().SetUser(endpointId, userIndex, creator, modifier, userName, uniqueId, userStatus, usertype, |
| 73 | + credentialRule, credentials, totalCredentials); |
| 74 | +} |
| 75 | + |
| 76 | +bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType, |
| 77 | + EmberAfPluginDoorLockCredentialInfo & credential) |
| 78 | +{ |
| 79 | + return LockManager::Instance().GetCredential(endpointId, credentialIndex, credentialType, credential); |
| 80 | +} |
| 81 | + |
| 82 | +bool emberAfPluginDoorLockSetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator, |
| 83 | + chip::FabricIndex modifier, DlCredentialStatus credentialStatus, |
| 84 | + CredentialTypeEnum credentialType, const chip::ByteSpan & credentialData) |
| 85 | +{ |
| 86 | + return LockManager::Instance().SetCredential(endpointId, credentialIndex, creator, modifier, credentialStatus, credentialType, |
| 87 | + credentialData); |
| 88 | +} |
| 89 | + |
| 90 | +DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, |
| 91 | + EmberAfPluginDoorLockWeekDaySchedule & schedule) |
| 92 | +{ |
| 93 | + return LockManager::Instance().GetSchedule(endpointId, weekdayIndex, userIndex, schedule); |
| 94 | +} |
| 95 | + |
| 96 | +DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, |
| 97 | + EmberAfPluginDoorLockHolidaySchedule & schedule) |
| 98 | +{ |
| 99 | + return LockManager::Instance().GetSchedule(endpointId, holidayIndex, schedule); |
| 100 | +} |
| 101 | + |
| 102 | +DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, |
| 103 | + DlScheduleStatus status, DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, |
| 104 | + uint8_t endHour, uint8_t endMinute) |
| 105 | +{ |
| 106 | + return LockManager::Instance().SetSchedule(endpointId, weekdayIndex, userIndex, status, daysMask, startHour, startMinute, |
| 107 | + endHour, endMinute); |
| 108 | +} |
| 109 | + |
| 110 | +DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, |
| 111 | + DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime) |
| 112 | +{ |
| 113 | + return LockManager::Instance().SetSchedule(endpointId, yearDayIndex, userIndex, status, localStartTime, localEndTime); |
| 114 | +} |
| 115 | + |
| 116 | +DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, |
| 117 | + EmberAfPluginDoorLockYearDaySchedule & schedule) |
| 118 | +{ |
| 119 | + return LockManager::Instance().GetSchedule(endpointId, yearDayIndex, userIndex, schedule); |
| 120 | +} |
| 121 | + |
| 122 | +DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, |
| 123 | + uint32_t localStartTime, uint32_t localEndTime, OperatingModeEnum operatingMode) |
| 124 | +{ |
| 125 | + return LockManager::Instance().SetSchedule(endpointId, holidayIndex, status, localStartTime, localEndTime, operatingMode); |
| 126 | +} |
| 127 | + |
| 128 | +void emberAfDoorLockClusterInitCallback(EndpointId endpoint) |
| 129 | +{ |
| 130 | + DoorLockServer::Instance().InitServer(endpoint); |
| 131 | + LockManager::Instance().InitEndpoint(endpoint); |
| 132 | +} |
| 133 | +#endif // MATTER_DM_PLUGIN_DOOR_LOCK_SERVER |
0 commit comments