|
| 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 <app/server-cluster/DefaultServerCluster.h> |
| 18 | + |
| 19 | +#include <access/Privilege.h> |
| 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 std::array<AttributeEntry, 5> 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 | +DefaultServerCluster::DefaultServerCluster() |
| 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 | + |
| 76 | +CHIP_ERROR DefaultServerCluster::Attributes(const ConcreteClusterPath & path, DataModel::ListBuilder<AttributeEntry> & builder) |
| 77 | +{ |
| 78 | + |
| 79 | + return builder.ReferenceExisting(kGlobalAttributeEntries); |
| 80 | +} |
| 81 | + |
| 82 | +BitFlags<ClusterQualityFlags> DefaultServerCluster::GetClusterFlags() const |
| 83 | +{ |
| 84 | + return {}; |
| 85 | +} |
| 86 | + |
| 87 | +ActionReturnStatus DefaultServerCluster::WriteAttribute(const WriteAttributeRequest & request, AttributeValueDecoder & decoder) |
| 88 | +{ |
| 89 | + return Protocols::InteractionModel::Status::UnsupportedWrite; |
| 90 | +} |
| 91 | + |
| 92 | +std::optional<ActionReturnStatus> |
| 93 | +DefaultServerCluster::InvokeCommand(const InvokeRequest & request, chip::TLV::TLVReader & input_arguments, CommandHandler * handler) |
| 94 | +{ |
| 95 | + return Protocols::InteractionModel::Status::UnsupportedCommand; |
| 96 | +} |
| 97 | + |
| 98 | +CHIP_ERROR DefaultServerCluster::AcceptedCommands(const ConcreteClusterPath & path, |
| 99 | + DataModel::ListBuilder<AcceptedCommandEntry> & builder) |
| 100 | +{ |
| 101 | + return CHIP_NO_ERROR; |
| 102 | +} |
| 103 | + |
| 104 | +CHIP_ERROR DefaultServerCluster::GeneratedCommands(const ConcreteClusterPath & path, DataModel::ListBuilder<CommandId> & builder) |
| 105 | +{ |
| 106 | + return CHIP_NO_ERROR; |
| 107 | +} |
| 108 | + |
| 109 | +} // namespace app |
| 110 | +} // namespace chip |
0 commit comments