|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Project CHIP Authors |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +#include "access/Privilege.h" |
| 18 | +#include <app/server-cluster/ServerClusterInterface.h> |
| 19 | + |
| 20 | +#include <app-common/zap-generated/ids/Attributes.h> |
| 21 | +#include <app/data-model-provider/MetadataTypes.h> |
| 22 | +#include <crypto/RandUtils.h> |
| 23 | +#include <lib/support/BitFlags.h> |
| 24 | +#include <optional> |
| 25 | +#include <protocols/interaction_model/StatusCode.h> |
| 26 | + |
| 27 | +namespace chip { |
| 28 | +namespace app { |
| 29 | +namespace { |
| 30 | + |
| 31 | +using namespace chip::app::Clusters; |
| 32 | +using namespace chip::app::DataModel; |
| 33 | + |
| 34 | +constexpr AttributeEntry kGlobalAttributeEntries[] = { |
| 35 | + { |
| 36 | + Globals::Attributes::ClusterRevision::Id, |
| 37 | + BitFlags<AttributeQualityFlags>(), |
| 38 | + Access::Privilege::kView, |
| 39 | + std::nullopt, |
| 40 | + }, |
| 41 | + { |
| 42 | + Globals::Attributes::FeatureMap::Id, |
| 43 | + BitFlags<AttributeQualityFlags>(), |
| 44 | + Access::Privilege::kView, |
| 45 | + std::nullopt, |
| 46 | + }, |
| 47 | + { |
| 48 | + Globals::Attributes::AttributeList::Id, |
| 49 | + BitFlags<AttributeQualityFlags>(AttributeQualityFlags::kListAttribute), |
| 50 | + Access::Privilege::kView, |
| 51 | + std::nullopt, |
| 52 | + }, |
| 53 | + { |
| 54 | + Globals::Attributes::AcceptedCommandList::Id, |
| 55 | + BitFlags<AttributeQualityFlags>(AttributeQualityFlags::kListAttribute), |
| 56 | + Access::Privilege::kView, |
| 57 | + std::nullopt, |
| 58 | + }, |
| 59 | + { |
| 60 | + Globals::Attributes::GeneratedCommandList::Id, |
| 61 | + BitFlags<AttributeQualityFlags>(AttributeQualityFlags::kListAttribute), |
| 62 | + Access::Privilege::kView, |
| 63 | + std::nullopt, |
| 64 | + }, |
| 65 | +}; |
| 66 | + |
| 67 | +} // namespace |
| 68 | + |
| 69 | +ServerClusterInterface::ServerClusterInterface() |
| 70 | +{ |
| 71 | + // SPEC - 7.10.3. Cluster Data Version |
| 72 | + // A cluster data version SHALL be initialized randomly when it is first published. |
| 73 | + mDataVersion = Crypto::GetRandU32(); |
| 74 | + |
| 75 | + // marks that this sever cluster interface is NOT in list |
| 76 | + mNext = this; |
| 77 | +} |
| 78 | + |
| 79 | +CHIP_ERROR ServerClusterInterface::Attributes(const ConcreteClusterPath & path, DataModel::ListBuilder<AttributeEntry> & builder) |
| 80 | +{ |
| 81 | + |
| 82 | + return builder.ReferenceExisting(Span<const AttributeEntry>(kGlobalAttributeEntries)); |
| 83 | +} |
| 84 | + |
| 85 | +BitFlags<ClusterQualityFlags> ServerClusterInterface::GetClusterFlags() const |
| 86 | +{ |
| 87 | + return BitFlags<ClusterQualityFlags>(); |
| 88 | +} |
| 89 | + |
| 90 | +ActionReturnStatus ServerClusterInterface::WriteAttribute(const WriteAttributeRequest & request, AttributeValueDecoder & decoder) |
| 91 | +{ |
| 92 | + return Protocols::InteractionModel::Status::UnsupportedWrite; |
| 93 | +} |
| 94 | + |
| 95 | +std::optional<ActionReturnStatus> ServerClusterInterface::Invoke(const InvokeRequest & request, |
| 96 | + chip::TLV::TLVReader & input_arguments, CommandHandler * handler) |
| 97 | +{ |
| 98 | + return Protocols::InteractionModel::Status::UnsupportedCommand; |
| 99 | +} |
| 100 | + |
| 101 | +CHIP_ERROR ServerClusterInterface::AcceptedCommands(const ConcreteClusterPath & path, |
| 102 | + DataModel::ListBuilder<AcceptedCommandEntry> & builder) |
| 103 | +{ |
| 104 | + return CHIP_NO_ERROR; |
| 105 | +} |
| 106 | + |
| 107 | +CHIP_ERROR ServerClusterInterface::GeneratedCommands(const ConcreteClusterPath & path, DataModel::ListBuilder<CommandId> & builder) |
| 108 | +{ |
| 109 | + return CHIP_NO_ERROR; |
| 110 | +} |
| 111 | + |
| 112 | +} // namespace app |
| 113 | +} // namespace chip |
0 commit comments