Line data Source code
1 : /**
2 : *
3 : * Copyright (c) 2020 Project CHIP Authors
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 :
18 : #pragma once
19 :
20 : /** @addtogroup aftypes Zigbee Application Framework Types Reference
21 : * This documentation describes the types used by the Zigbee
22 : * Application Framework.
23 : * @{
24 : */
25 :
26 : #include <stdbool.h> // For bool
27 : #include <stdint.h> // For various uint*_t types
28 :
29 : #include <app/util/MarkAttributeDirty.h>
30 : #include <app/util/basic-types.h>
31 : #include <app/util/types_stub.h> // For various types.
32 :
33 : #include <app/util/attribute-metadata.h> // EmberAfAttributeMetadata
34 :
35 : #include <app/AttributePathParams.h>
36 : #include <app/ConcreteAttributePath.h>
37 : #include <app/data-model-provider/MetadataTypes.h>
38 : #include <app/data-model/Nullable.h>
39 : #include <lib/core/DataModelTypes.h>
40 : #include <lib/support/Variant.h>
41 : #include <messaging/ExchangeContext.h>
42 :
43 : #include <app-common/zap-generated/cluster-enums.h>
44 : #include <app-common/zap-generated/cluster-objects.h>
45 : #include <protocols/interaction_model/StatusCode.h>
46 :
47 : /**
48 : * @brief Generic function type, used for either of the cluster function.
49 : *
50 : * This type is used for the array of the cluster functions, and should
51 : * always be cast into one of the specific functions before being called.
52 : */
53 : typedef void (*EmberAfGenericClusterFunction)(void);
54 :
55 : /**
56 : * @brief A distinguished manufacturer code that is used to indicate the
57 : * absence of a manufacturer-specific cluster, command, or attribute.
58 : */
59 : #define MATTER_DM_NULL_MANUFACTURER_CODE 0x0000
60 :
61 : // The following define names are relevant to the ZAP_CLUSTER_MASK macro.
62 : #define MATTER_CLUSTER_FLAG_INIT_FUNCTION 0x01
63 : #define MATTER_CLUSTER_FLAG_ATTRIBUTE_CHANGED_FUNCTION 0x02
64 : // Bit 2 (0x04) and Bit3 (0x08) are free.
65 : #define MATTER_CLUSTER_FLAG_SHUTDOWN_FUNCTION 0x10
66 : #define MATTER_CLUSTER_FLAG_PRE_ATTRIBUTE_CHANGED_FUNCTION 0x20
67 : #define MATTER_CLUSTER_FLAG_SERVER 0x40
68 : #define MATTER_CLUSTER_FLAG_CLIENT 0x80
69 :
70 : /**
71 : * @brief Type for the cluster mask
72 : * Value of the mask represents a single, or aggregated, MATTER_CLUSTER_FLAG_X
73 : */
74 : typedef uint8_t EmberAfClusterMask;
75 :
76 : /**
77 : * @brief Struct describing cluster
78 : */
79 : struct EmberAfCluster
80 : {
81 : /**
82 : * ID of cluster according to ZCL spec
83 : */
84 : chip::ClusterId clusterId;
85 : /**
86 : * Pointer to attribute metadata array for this cluster.
87 : */
88 : const EmberAfAttributeMetadata * attributes;
89 : /**
90 : * Total number of attributes
91 : */
92 : uint16_t attributeCount;
93 : /**
94 : * Total size of non-external, non-singleton attribute for this cluster.
95 : */
96 : uint16_t clusterSize;
97 : /**
98 : * Mask with additional functionality for cluster. See CLUSTER_MASK
99 : * macros.
100 : */
101 : EmberAfClusterMask mask;
102 :
103 : /**
104 : * An array into the cluster functions. The length of the array
105 : * is determined by the function bits in mask. This may be null
106 : * if this cluster has no functions.
107 : */
108 : const EmberAfGenericClusterFunction * functions;
109 :
110 : /**
111 : * A list of client generated commands. A client generated command
112 : * is a client to server command. Can be nullptr or terminated by 0xFFFF_FFFF.
113 : */
114 : const chip::CommandId * acceptedCommandList;
115 :
116 : /**
117 : * A list of server generated commands. A server generated command
118 : * is a response to client command request. Can be nullptr or terminated by 0xFFFF_FFFF.
119 : */
120 : const chip::CommandId * generatedCommandList;
121 :
122 : /**
123 : * Pointer to an array of event IDs of the events supported by the cluster instance.
124 : * Can be nullptr.
125 : */
126 : const chip::EventId * eventList;
127 :
128 : /**
129 : * Total number of events supported by the cluster instance (in eventList array).
130 : */
131 : uint16_t eventCount;
132 :
133 20175 : bool IsServer() const { return (mask & MATTER_CLUSTER_FLAG_SERVER) != 0; }
134 :
135 8 : bool IsClient() const { return (mask & MATTER_CLUSTER_FLAG_CLIENT) != 0; }
136 : };
137 :
138 : using EmberAfDeviceType = chip::app::DataModel::DeviceTypeEntry;
139 :
140 : /**
141 : * @brief Struct used to find an attribute in storage. Together the elements
142 : * in this search record constitute the "primary key" used to identify a unique
143 : * attribute value in attribute storage.
144 : */
145 : typedef struct
146 : {
147 : /**
148 : * Endpoint that the attribute is located on
149 : */
150 : chip::EndpointId endpoint;
151 :
152 : /**
153 : * Cluster that the attribute is located on.
154 : */
155 : chip::ClusterId clusterId;
156 :
157 : /**
158 : * The identifier for the attribute.
159 : */
160 : chip::AttributeId attributeId;
161 : } EmberAfAttributeSearchRecord;
162 :
163 : /**
164 : * This type is used to compare two ZCL attribute values. The size of this data
165 : * type depends on the platform.
166 : */
167 : #ifdef HAL_HAS_INT64
168 : typedef uint64_t EmberAfDifferenceType;
169 : #else
170 : typedef uint32_t EmberAfDifferenceType;
171 : #endif
172 :
173 : /**
174 : * @brief Endpoint type struct describes clusters that are on the endpoint.
175 : */
176 : typedef struct
177 : {
178 : /**
179 : * Pointer to the cluster structs, describing clusters on this
180 : * endpoint type.
181 : */
182 : const EmberAfCluster * cluster;
183 : /**
184 : * Number of clusters in this endpoint type.
185 : */
186 : uint8_t clusterCount;
187 : /**
188 : * Size of all non-external, non-singlet attribute in this endpoint type.
189 : */
190 : uint16_t endpointSize;
191 : } EmberAfEndpointType;
192 :
193 : enum class EmberAfEndpointOptions : uint8_t
194 : {
195 : isEnabled = 0x1,
196 : isFlatComposition = 0x2,
197 : };
198 :
199 : /**
200 : * @brief Struct that maps actual endpoint type, onto a specific endpoint.
201 : */
202 : struct EmberAfDefinedEndpoint
203 : {
204 : /**
205 : * Actual zigbee endpoint number.
206 : */
207 : chip::EndpointId endpoint = chip::kInvalidEndpointId;
208 :
209 : /**
210 : * Span pointing to a list of supported device types
211 : */
212 : chip::Span<const EmberAfDeviceType> deviceTypeList;
213 :
214 : /**
215 : * Meta-data about the endpoint
216 : */
217 : chip::BitMask<EmberAfEndpointOptions> bitmask;
218 : /**
219 : * Endpoint type for this endpoint.
220 : */
221 : const EmberAfEndpointType * endpointType = nullptr;
222 : /**
223 : * Pointer to the DataVersion storage for the server clusters on this
224 : * endpoint
225 : */
226 : chip::DataVersion * dataVersions = nullptr;
227 :
228 : /**
229 : * Root endpoint id for composed device type.
230 : */
231 : chip::EndpointId parentEndpointId = chip::kInvalidEndpointId;
232 :
233 : /**
234 : * Span pointing to a list of tags. Lifetime has to outlive usage, and data is owned by callers.
235 : */
236 : chip::Span<const chip::app::Clusters::Descriptor::Structs::SemanticTagStruct::Type> tagList;
237 :
238 : #if CHIP_CONFIG_USE_ENDPOINT_UNIQUE_ID
239 : /**
240 : * Unique Id for this endpoint.
241 : */
242 : char endpointUniqueId[chip::app::Clusters::Descriptor::Attributes::EndpointUniqueID::TypeInfo::MaxLength()] = { 0 };
243 :
244 : uint8_t endpointUniqueIdSize = 0;
245 : #endif
246 : };
247 :
248 : enum class MatterClusterShutdownType
249 : {
250 : kClusterShutdown, // "normal" shutdown, e.g. application stop. Perform cleanups like: timer and delegate cleanup.
251 : kPermanentRemove, // full "remove", for situations when the endpoint the cluster on is going away permanently (for example, a
252 : // bridged device that is no longer being bridged).
253 : };
254 :
255 : /**
256 : * @brief Type for referring to the tick callback for cluster.
257 : *
258 : * Tick function will be called once for each tick for each endpoint in
259 : * the cluster. The rate of tick is determined by the metadata of the
260 : * cluster.
261 : */
262 : typedef void (*EmberAfTickFunction)(chip::EndpointId endpoint);
263 :
264 : /**
265 : * @brief Type for referring to the init callback for cluster.
266 : *
267 : * Init function is called when the application starts up, once for
268 : * each cluster/endpoint combination.
269 : */
270 : typedef void (*EmberAfInitFunction)(chip::EndpointId endpoint);
271 :
272 : /**
273 : * @brief Type for referring to the shutdown callback for cluster.
274 : *
275 : * Init function is called when the cluster is shut down, for example
276 : * when an endpoint is disabled
277 : */
278 : typedef void (*EmberAfShutdownFunction)(chip::EndpointId endpoint);
279 :
280 : /**
281 : * @brief Type for referring to the attribute changed callback function.
282 : *
283 : * This function is called just after an attribute changes.
284 : */
285 : typedef void (*EmberAfClusterAttributeChangedCallback)(const chip::app::ConcreteAttributePath & attributePath);
286 :
287 : /**
288 : * @brief Type for referring to the pre-attribute changed callback function.
289 : *
290 : * This function is called before an attribute changes.
291 : */
292 : typedef chip::Protocols::InteractionModel::Status (*EmberAfClusterPreAttributeChangedCallback)(
293 : const chip::app::ConcreteAttributePath & attributePath, EmberAfAttributeType attributeType, uint16_t size, uint8_t * value);
294 :
295 : #define MAX_INT32U_VALUE (0xFFFFFFFFUL)
296 : #define MAX_INT16U_VALUE (0xFFFF)
297 :
298 : /** @} END addtogroup */
|