Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / util / af-types.h
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 /**
19  *
20  *    Copyright (c) 2020 Silicon Labs
21  *
22  *    Licensed under the Apache License, Version 2.0 (the "License");
23  *    you may not use this file except in compliance with the License.
24  *    You may obtain a copy of the License at
25  *
26  *        http://www.apache.org/licenses/LICENSE-2.0
27  *
28  *    Unless required by applicable law or agreed to in writing, software
29  *    distributed under the License is distributed on an "AS IS" BASIS,
30  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  *    See the License for the specific language governing permissions and
32  *    limitations under the License.
33  */
34 /***************************************************************************/
35 /**
36  * @file
37  * @brief The include file for all the types for Ember
38  *ApplicationFramework
39  *******************************************************************************
40  ******************************************************************************/
41
42 #pragma once
43
44 /** @addtogroup aftypes Zigbee Application Framework Types Reference
45  * This documentation describes the types used by the Zigbee
46  * Application Framework.
47  * @{
48  */
49
50 #include <stdbool.h> // For bool
51 #include <stddef.h>  // For NULL.
52 #include <stdint.h>  // For various uint*_t types
53
54 #include "af-enums.h"
55 #include "basic-types.h"
56 #include "types_stub.h" // For various types.
57
58 #ifdef EZSP_HOST
59 #include "app/util/ezsp/ezsp-enum.h"
60 #endif
61
62 /**
63  * @brief Type for referring to ZCL attribute type
64  */
65 typedef uint8_t EmberAfAttributeType;
66
67 /**
68  * @brief Type for the cluster mask
69  */
70 typedef uint8_t EmberAfClusterMask;
71
72 /**
73  * @brief Type for the attribute mask
74  */
75 typedef uint8_t EmberAfAttributeMask;
76
77 /**
78  * @brief Generic function type, used for either of the cluster function.
79  *
80  * This type is used for the array of the cluster functions, and should
81  * always be cast into one of the specific functions before being called.
82  */
83 typedef void (*EmberAfGenericClusterFunction)(void);
84
85 /**
86  * @brief A distinguished manufacturer code that is used to indicate the
87  * absence of a manufacturer-specific cluster, command, or attribute.
88  */
89 #define EMBER_AF_NULL_MANUFACTURER_CODE 0x0000
90
91 /**
92  * @brief Type for default values.
93  *
94  * Default value is either a value itself, if it is 2 bytes or less,
95  * or a pointer to the value itself, if attribute type is longer than
96  * 2 bytes.
97  */
98 typedef union
99 {
100     /**
101      * Points to data if size is more than 2 bytes.
102      * If size is more than 2 bytes, and this value is NULL,
103      * then the default value is all zeroes.
104      */
105     uint8_t * ptrToDefaultValue;
106     /**
107      * Actual default value if the attribute size is 2 bytes or less.
108      */
109     uint16_t defaultValue;
110 } EmberAfDefaultAttributeValue;
111
112 /**
113  * @brief Type describing the attribute default, min and max values.
114  *
115  * This struct is required if the attribute mask specifies that this
116  * attribute has a known min and max values.
117  */
118 typedef struct
119 {
120     /**
121      * Default value of the attribute.
122      */
123     EmberAfDefaultAttributeValue defaultValue;
124     /**
125      * Minimum allowed value
126      */
127     EmberAfDefaultAttributeValue minValue;
128     /**
129      * Maximum allowed value.
130      */
131     EmberAfDefaultAttributeValue maxValue;
132 } EmberAfAttributeMinMaxValue;
133
134 /**
135  * @brief Union describing the attribute default/min/max values.
136  */
137 typedef union
138 {
139     /**
140      * Points to data if size is more than 2 bytes.
141      * If size is more than 2 bytes, and this value is NULL,
142      * then the default value is all zeroes.
143      */
144     uint8_t * ptrToDefaultValue;
145     /**
146      * Actual default value if the attribute size is 2 bytes or less.
147      */
148     uint16_t defaultValue;
149     /**
150      * Points to the min max attribute value structure, if min/max is
151      * supported for this attribute.
152      */
153     EmberAfAttributeMinMaxValue * ptrToMinMaxValue;
154 } EmberAfDefaultOrMinMaxAttributeValue;
155
156 /**
157  * @brief Each attribute has it's metadata stored in such struct.
158  *
159  * There is only one of these per attribute across all endpoints.
160  */
161 typedef struct
162 {
163     /**
164      * Attribute ID, according to ZCL specs.
165      */
166     chip::AttributeId attributeId;
167     /**
168      * Attribute type, according to ZCL specs.
169      */
170     EmberAfAttributeType attributeType;
171     /**
172      * Size of this attribute in bytes.
173      */
174     uint8_t size;
175     /**
176      * Attribute mask, tagging attribute with specific
177      * functionality. See ATTRIBUTE_MASK_ macros defined
178      * in att-storage.h.
179      */
180     EmberAfAttributeMask mask;
181     /**
182      * Pointer to the default value union. Actual value stored
183      * depends on the mask.
184      */
185     EmberAfDefaultOrMinMaxAttributeValue defaultValue;
186 } EmberAfAttributeMetadata;
187
188 /**
189  * @brief Struct describing cluster
190  */
191 typedef struct
192 {
193     /**
194      *  ID of cluster according to ZCL spec
195      */
196     chip::ClusterId clusterId;
197     /**
198      * Pointer to attribute metadata array for this cluster.
199      */
200     EmberAfAttributeMetadata * attributes;
201     /**
202      * Total number of attributes
203      */
204     uint16_t attributeCount;
205     /**
206      * Total size of non-external, non-singleton attribute for this cluster.
207      */
208     uint16_t clusterSize;
209     /**
210      * Mask with additional functionality for cluster. See CLUSTER_MASK
211      * macros.
212      */
213     EmberAfClusterMask mask;
214
215     /**
216      * An array into the cluster functions. The length of the array
217      * is determined by the function bits in mask. This may be null
218      * if this cluster has no functions.
219      */
220     const EmberAfGenericClusterFunction * functions;
221 } EmberAfCluster;
222
223 /**
224  * @brief Struct used to find an attribute in storage. Together the elements
225  * in this search record constitute the "primary key" used to identify a unique
226  * attribute value in attribute storage.
227  */
228 typedef struct
229 {
230     /**
231      * Endpoint that the attribute is located on
232      */
233     chip::EndpointId endpoint;
234
235     /**
236      * Cluster that the attribute is located on. If the cluster
237      * id is inside the manufacturer specific range, 0xfc00 - 0xffff,
238      * The manufacturer code should also be set to the code associated
239      * with the manufacturer specific cluster.
240      */
241     chip::ClusterId clusterId;
242
243     /**
244      * Cluster mask for the cluster, used to determine if it is
245      * the server or client version of the cluster. See CLUSTER_MASK_
246      * macros defined in att-storage.h
247      */
248     EmberAfClusterMask clusterMask;
249
250     /**
251      * The two byte identifier for the attribute. If the cluster id is
252      * inside the manufacturer specific range 0xfc00 - 0xffff, or the manufacturer
253      * code is NOT 0, the attribute is assumed to be manufacturer specific.
254      */
255     chip::AttributeId attributeId;
256
257     /**
258      * Manufacturer Code associated with the cluster and or attribute.
259      * If the cluster id is inside the manufacturer specific
260      * range, this value should indicate the manufacturer code for the
261      * manufacturer specific cluster. Otherwise if this value is non zero,
262      * and the cluster id is a standard ZCL cluster,
263      * it is assumed that the attribute being sought is a manufacturer specific
264      * extension to the standard ZCL cluster indicated by the cluster id.
265      */
266     uint16_t manufacturerCode;
267 } EmberAfAttributeSearchRecord;
268
269 /**
270  * A struct used to construct a table of manufacturer codes for
271  * manufacturer specific attributes and clusters.
272  */
273 typedef struct
274 {
275     uint16_t index;
276     uint16_t manufacturerCode;
277 } EmberAfManufacturerCodeEntry;
278
279 /**
280  * This type is used to compare two ZCL attribute values. The size of this data
281  * type depends on the platform.
282  */
283 #ifdef HAL_HAS_INT64
284 typedef uint64_t EmberAfDifferenceType;
285 #else
286 typedef uint32_t EmberAfDifferenceType;
287 #endif
288
289 /**
290  * @brief a struct containing the superset of values
291  * passed to both emberIncomingMessageHandler on the SOC and
292  * ezspIncomingMessageHandler on the host.
293  */
294 typedef struct
295 {
296     /**
297      * The type of the incoming message
298      */
299     EmberIncomingMessageType type;
300     /**
301      * APS frame for the incoming message
302      */
303     EmberApsFrame * apsFrame;
304     /**
305      * The message copied into a flat buffer
306      */
307     uint8_t * message;
308     /**
309      * Length of the incoming message
310      */
311     uint16_t msgLen;
312     /**
313      * Two byte node id of the sending node.
314      */
315     uint16_t source;
316     /**
317      * Link quality from the node that last relayed
318      * the message.
319      */
320     uint8_t lastHopLqi;
321     /**
322      * The energy level (in units of dBm) observed during the reception.
323      */
324     int8_t lastHopRssi;
325     /**
326      * The index of a binding that matches the message
327      * or 0xFF if there is no matching binding.
328      */
329     uint8_t bindingTableIndex;
330     /**
331      * The index of the entry in the address table
332      * that matches the sender of the message or 0xFF
333      * if there is no matching entry.
334      */
335     uint8_t addressTableIndex;
336     /**
337      * The index of the network on which this message was received.
338      */
339     uint8_t networkIndex;
340 } EmberAfIncomingMessage;
341
342 /**
343  * @brief Interpan Message type: unicast, broadcast, or multicast.
344  */
345 typedef uint8_t EmberAfInterpanMessageType;
346 #define EMBER_AF_INTER_PAN_UNICAST 0x00
347 #define EMBER_AF_INTER_PAN_BROADCAST 0x08
348 #define EMBER_AF_INTER_PAN_MULTICAST 0x0C
349
350 // Legacy names
351 #define INTER_PAN_UNICAST EMBER_AF_INTER_PAN_UNICAST
352 #define INTER_PAN_BROADCAST EMBER_AF_INTER_PAN_BROADCAST
353 #define INTER_PAN_MULTICAST EMBER_AF_INTER_PAN_MULTICAST
354
355 #define EMBER_AF_INTERPAN_OPTION_NONE 0x0000
356 #define EMBER_AF_INTERPAN_OPTION_APS_ENCRYPT 0x0001
357 #define EMBER_AF_INTERPAN_OPTION_MAC_HAS_LONG_ADDRESS 0x0002
358
359 /**
360  * @brief The options for sending/receiving interpan messages.
361  */
362 typedef uint16_t EmberAfInterpanOptions;
363
364 /**
365  * @brief Interpan header used for sending and receiving interpan
366  *   messages.
367  */
368 typedef struct
369 {
370     EmberAfInterpanMessageType messageType;
371
372     /**
373      * MAC addressing
374      * For outgoing messages this is the destination.  For incoming messages
375      * it is the source, which always has a long address.
376      */
377     EmberEUI64 longAddress;
378     EmberNodeId shortAddress;
379     EmberPanId panId;
380
381     /**
382      * APS data
383      */
384     chip::ClusterId clusterId;
385     /**
386      * The groupId is only used for
387      * EMBER_AF_INTERPAN_MULTICAST
388      */
389     chip::GroupId groupId;
390     EmberAfInterpanOptions options;
391 } EmberAfInterpanHeader;
392
393 // Legacy Name
394 #define InterPanHeader EmberAfInterpanHeader
395
396 /**
397  * @brief The options for what interpan messages are allowed.
398  */
399 typedef uint8_t EmberAfAllowedInterpanOptions;
400
401 #define EMBER_AF_INTERPAN_DIRECTION_CLIENT_TO_SERVER 0x01
402 #define EMBER_AF_INTERPAN_DIRECTION_SERVER_TO_CLIENT 0x02
403 #define EMBER_AF_INTERPAN_DIRECTION_BOTH 0x03
404 #define EMBER_AF_INTERPAN_GLOBAL_COMMAND 0x04
405 #define EMBER_AF_INTERPAN_MANUFACTURER_SPECIFIC 0x08
406
407 /**
408  * @brief This structure is used define an interpan message that
409  *   will be accepted by the interpan filters.
410  */
411 typedef struct
412 {
413     chip::ClusterId clusterId;
414     chip::CommandId commandId;
415     EmberAfAllowedInterpanOptions options;
416 } EmberAfAllowedInterPanMessage;
417
418 /**
419  * @brief The EmberAFClusterCommand is a struct wrapper
420  *   for all the data pertaining to a command which comes
421  *   in over the air. This enables struct is used to
422  *   encapsulate a command in a single place on the stack
423  *   and pass a pointer to that location around during
424  *   command processing
425  */
426 typedef struct
427 {
428     /**
429      * APS frame for the incoming message
430      */
431     EmberApsFrame * apsFrame;
432     EmberIncomingMessageType type;
433     chip::NodeId source;
434     uint8_t * buffer;
435     uint16_t bufLen;
436     bool clusterSpecific;
437     bool mfgSpecific;
438     uint16_t mfgCode;
439     uint8_t seqNum;
440     chip::CommandId commandId;
441     uint8_t payloadStartIndex;
442     uint8_t direction;
443     EmberAfInterpanHeader * interPanHeader;
444     uint8_t networkIndex;
445 } EmberAfClusterCommand;
446
447 /**
448  * @brief Endpoint type struct describes clusters that are on the endpoint.
449  */
450 typedef struct
451 {
452     /**
453      * Pointer to the cluster structs, describing clusters on this
454      * endpoint type.
455      */
456     EmberAfCluster * cluster;
457     /**
458      * Number of clusters in this endpoint type.
459      */
460     uint8_t clusterCount;
461     /**
462      * Size of all non-external, non-singlet attribute in this endpoint type.
463      */
464     uint16_t endpointSize;
465 } EmberAfEndpointType;
466
467 #ifdef EZSP_HOST
468 typedef EzspDecisionId EmberAfTcLinkKeyRequestPolicy;
469 typedef EzspDecisionId EmberAfAppLinkKeyRequestPolicy;
470 #define EMBER_AF_ALLOW_TC_KEY_REQUESTS EZSP_ALLOW_TC_KEY_REQUESTS_AND_SEND_CURRENT_KEY
471 #define EMBER_AF_DENY_TC_KEY_REQUESTS EZSP_DENY_TC_KEY_REQUESTS
472 #define EMBER_AF_ALLOW_APP_KEY_REQUESTS EZSP_ALLOW_APP_KEY_REQUESTS
473 #define EMBER_AF_DENY_APP_KEY_REQUESTS EZSP_DENY_APP_KEY_REQUESTS
474 #else
475 typedef EmberTcLinkKeyRequestPolicy EmberAfTcLinkKeyRequestPolicy;
476 typedef EmberAppLinkKeyRequestPolicy EmberAfAppLinkKeyRequestPolicy;
477 #define EMBER_AF_ALLOW_TC_KEY_REQUESTS EMBER_ALLOW_TC_LINK_KEY_REQUEST_AND_SEND_CURRENT_KEY
478 #define EMBER_AF_DENY_TC_KEY_REQUESTS EMBER_DENY_TC_LINK_KEY_REQUESTS
479 #define EMBER_AF_ALLOW_APP_KEY_REQUESTS EMBER_ALLOW_APP_LINK_KEY_REQUEST
480 #define EMBER_AF_DENY_APP_KEY_REQUESTS EMBER_DENY_APP_LINK_KEY_REQUESTS
481 #endif
482
483 #ifdef DOXYGEN_SHOULD_SKIP_THIS
484 enum EmberAfEndpointBitmask;
485 #else
486 typedef uint8_t EmberAfEndpointBitmask;
487 enum
488 #endif
489 { EMBER_AF_ENDPOINT_DISABLED = 0x00,
490   EMBER_AF_ENDPOINT_ENABLED  = 0x01,
491 };
492
493 /**
494  * @brief Struct that maps actual endpoint type, onto a specific endpoint.
495  */
496 typedef struct
497 {
498     /**
499      * Actual zigbee endpoint number.
500      */
501     chip::EndpointId endpoint;
502     /**
503      * Device ID of the device on this endpoint.
504      */
505     uint16_t deviceId;
506     /**
507      * Version of the device.
508      */
509     uint8_t deviceVersion;
510     /**
511      * Endpoint type for this endpoint.
512      */
513     EmberAfEndpointType * endpointType;
514     /**
515      * Network index for this endpoint.
516      */
517     uint8_t networkIndex;
518     /**
519      * Meta-data about the endpoint
520      */
521     EmberAfEndpointBitmask bitmask;
522 } EmberAfDefinedEndpoint;
523
524 // Cluster specific types
525
526 /**
527  * @brief Bitmask data type for storing one bit of information for each ESI in
528  * the ESI table.
529  */
530 #if (EMBER_AF_PLUGIN_ESI_MANAGEMENT_ESI_TABLE_SIZE <= 8)
531 typedef uint8_t EmberAfPluginEsiManagementBitmask;
532 #elif (EMBER_AF_PLUGIN_ESI_MANAGEMENT_ESI_TABLE_SIZE <= 16)
533 typedef uint16_t EmberAfPluginEsiManagementBitmask;
534 #elif (EMBER_AF_PLUGIN_ESI_MANAGEMENT_ESI_TABLE_SIZE <= 32)
535 typedef uint32_t EmberAfPluginEsiManagementBitmask;
536 #else
537 #error "EMBER_AF_PLUGIN_ESI_MANAGEMENT_ESI_TABLE_SIZE cannot exceed 32"
538 #endif
539
540 /**
541  * @brief Struct that describes a load control event.
542  *
543  * This is used in the load control event callback and
544  * within the demand response load control cluster code.
545  */
546 typedef struct
547 {
548     uint32_t eventId;
549 #ifdef EMBER_AF_PLUGIN_DRLC_SERVER
550     EmberEUI64 source;
551     chip::EndpointId sourceEndpoint;
552 #endif // EMBER_AF_PLUGIN_DRLC_SERVER
553
554 #ifdef EMBER_AF_PLUGIN_DRLC
555     EmberAfPluginEsiManagementBitmask esiBitmask;
556 #endif // EMBER_AF_PLUGIN_DRLC
557
558     chip::EndpointId destinationEndpoint;
559     uint16_t deviceClass;
560     uint8_t utilityEnrollmentGroup;
561     /**
562      * Start time in seconds
563      */
564     uint32_t startTime;
565     /**
566      * Duration in minutes
567      */
568     uint16_t duration;
569     uint8_t criticalityLevel;
570     uint8_t coolingTempOffset;
571     uint8_t heatingTempOffset;
572     int16_t coolingTempSetPoint;
573     int16_t heatingTempSetPoint;
574     int8_t avgLoadPercentage;
575     uint8_t dutyCycle;
576     uint8_t eventControl;
577     uint32_t startRand;
578     uint32_t durationRand;
579     uint8_t optionControl;
580 } EmberAfLoadControlEvent;
581
582 /**
583  * @brief This is an enum used to indicate the result of the
584  *   service discovery.  Unicast discoveries are completed
585  *   as soon as a response is received.  Broadcast discoveries
586  *   wait a period of time for multiple responses to be received.
587  */
588 typedef enum
589 {
590     EMBER_AF_BROADCAST_SERVICE_DISCOVERY_COMPLETE                     = 0x00,
591     EMBER_AF_BROADCAST_SERVICE_DISCOVERY_RESPONSE_RECEIVED            = 0x01,
592     EMBER_AF_UNICAST_SERVICE_DISCOVERY_TIMEOUT                        = 0x02,
593     EMBER_AF_UNICAST_SERVICE_DISCOVERY_COMPLETE_WITH_RESPONSE         = 0x03,
594     EMBER_AF_BROADCAST_SERVICE_DISCOVERY_COMPLETE_WITH_RESPONSE       = 0x04,
595     EMBER_AF_UNICAST_SERVICE_DISCOVERY_COMPLETE_WITH_EMPTY_RESPONSE   = 0x05,
596     EMBER_AF_BROADCAST_SERVICE_DISCOVERY_COMPLETE_WITH_EMPTY_RESPONSE = 0x06,
597 } EmberAfServiceDiscoveryStatus;
598
599 #define EM_AF_DISCOVERY_RESPONSE_MASK (0x05)
600
601 /**
602  * @brief A simple way to determine if the service discovery callback
603  *   has a response.
604  */
605 #define emberAfHaveDiscoveryResponseStatus(status) ((status) &EM_AF_DISCOVERY_RESPONSE_MASK)
606
607 /**
608  * @brief A structure containing general information about the service discovery.
609  */
610 typedef struct
611 {
612     /**
613      * The status indicates both the type of request (broadcast or unicast)
614      * and whether a response has been received.
615      */
616     EmberAfServiceDiscoveryStatus status;
617
618     /**
619      * This indicates what ZDO request cluster was associated with the request.
620      * It is helpful for a callback that may be used for multiple ZDO request types
621      * to determine the type of data returned.  This will be based on the
622      * ZDO cluster values defined in ember-types.h.
623      */
624     uint16_t zdoRequestClusterId;
625
626     /**
627      * This is the address of the device that matched the request, which may
628      * be different than the device that *actually* is responding.  This occurs
629      * when parents respond on behalf of their children.
630      */
631     EmberNodeId matchAddress;
632
633     /**
634      * Only if the status code indicates a response will this data be non-NULL.
635      * When there is data, the type is according to the ZDO cluster ID sent out.
636      * For NETWORK_ADDRESS_REQUEST or IEEE_ADDRESS_REQUEST, the long ID will
637      * be contained in the responseData,  so it will be a value of type ::EmberEUI64.
638      * The short ID will be in the matchAddress parameter field.
639      * For the MATCH_DESCRIPTORS_REQUEST the responseData will point
640      * to an ::EmberAfEndpointList structure.
641      */
642     const void * responseData;
643 } EmberAfServiceDiscoveryResult;
644
645 /**
646  * @brief A list of endpoints received during a service discovery attempt.
647  *   This will be returned for a match descriptor request and a
648  *   active endpoint request.
649  */
650 typedef struct
651 {
652     uint8_t count;
653     const chip::EndpointId * list;
654 } EmberAfEndpointList;
655
656 /**
657  * @brief A list of clusters received during a service discovery attempt.
658  * This will be returned for a simple descriptor request.
659  */
660 typedef struct
661 {
662     uint8_t inClusterCount;
663     const chip::ClusterId * inClusterList;
664     uint8_t outClusterCount;
665     const chip::ClusterId * outClusterList;
666     uint16_t deviceId;
667     chip::EndpointId endpoint;
668 } EmberAfClusterList;
669
670 /**
671  * @brief This defines a callback where a code element or cluster can be informed
672  * as to the result of a service discovery they have requested.
673  * For each match, the callback is fired with all the resulting matches from
674  * that source.  If the discovery was unicast to a specific device, then
675  * the callback will only be fired once with either MATCH_FOUND or COMPLETE
676  * (no matches found).  If the discovery is broadcast then multiple callbacks
677  * may be fired with ::EMBER_AF_SERVICE_DISCOVERY_RESPONSE_RECEIVED.
678  * After a couple seconds the callback will then be fired with
679  * ::EMBER_AF_SERVICE_DISCOVERY_COMPLETE as the result.
680  */
681 typedef void(EmberAfServiceDiscoveryCallback)(const EmberAfServiceDiscoveryResult * result);
682
683 /**
684  * @brief This defines a callback where a code element or cluster can be
685  * informed as to the result of a request to initiate a partner link key
686  * exchange.  The callback will be triggered with success equal to true if the
687  * exchange completed successfully.
688  */
689 typedef void(EmberAfPartnerLinkKeyExchangeCallback)(bool success);
690
691 /**
692  * @brief This is an enum used to control how the device will poll for a given
693  * active cluster-related event.  When the event is scheduled, the application
694  * can pass a poll control value which will be stored along with the event.
695  * The processor is only allowed to poll according to the most restrictive
696  * value for all active event.  For instance, if two events are active, one
697  * with EMBER_AF_LONG_POLL and the other with EMBER_AF_SHORT_POLL, then the
698  * processor will short poll until the second event is deactivated.
699  */
700 typedef enum
701 {
702     EMBER_AF_LONG_POLL,
703     EMBER_AF_SHORT_POLL,
704 } EmberAfEventPollControl;
705
706 /**
707  * @brief This is an enum used to control how the device
708  *        will sleep for a given active cluster related event.
709  *        When the event is scheduled, the scheduling code can
710  *        pass a sleep control value which will be stored along
711  *        with the event. The processor is only allowed to sleep
712  *        according to the most restrictive sleep control value
713  *        for any active event. For instance, if two events
714  *        are active, one with EMBER_AF_OK_TO_HIBERNATE and the
715  *        other with EMBER_AF_OK_TO_NAP, then the processor
716  *        will only be allowed to nap until the second event
717  *        is deactivated.
718  */
719 typedef enum
720 {
721     EMBER_AF_OK_TO_SLEEP,
722     /** @deprecated. */
723     EMBER_AF_OK_TO_HIBERNATE = EMBER_AF_OK_TO_SLEEP,
724     /** @deprecated. */
725     EMBER_AF_OK_TO_NAP,
726     EMBER_AF_STAY_AWAKE,
727 } EmberAfEventSleepControl;
728
729 /**
730  * @brief An enum used to track the tasks that the Application
731  * framework cares about. These are intended to be tasks
732  * that should keep the device out of hibernation like an
733  * application level request / response. If the response does
734  * not come in as a data ack, then the application will need
735  * to stay out of hibernation to wait and poll for it.
736  *
737  * Of course some tasks do not necessarily have a response. For
738  * instance, a ZDO request may or may not have a response. In this
739  * case, the application framework cannot rely on the fact that
740  * a response will come in to end the wake cycle, so the Application
741  * framework must timeout the wake cycle if no expected
742  * response is received or no other event can be relied upon to
743  * end the wake cycle.
744  *
745  * Tasks of this type should be added to the wake timeout mask
746  * by calling ::emberAfSetWakeTimeoutBitmaskCallback so that they
747  * can be governed by a timeout instead of a request / response
748  *
749  * the current tasks bitmask is an uint32_t bitmask used to
750  * track which tasks are active at any given time. The bottom 16 bits,
751  * values 0x01 - 0x8000 are reserved for Ember's use. The top
752  * 16 bits are reserved for the customer, values 0x10000 -
753  * 0x80000000
754  */
755 #ifdef DOXYGEN_SHOULD_SKIP_THIS
756 enum EmberAfApplicationTask
757 #else
758 typedef uint32_t EmberAfApplicationTask;
759 enum
760 #endif
761 {
762     // we may be able to remove these top two since they are
763     // handled by the stack on the SOC.
764     EMBER_AF_WAITING_FOR_DATA_ACK                     = 0x00000001, // not needed?
765     EMBER_AF_LAST_POLL_GOT_DATA                       = 0x00000002, // not needed?
766     EMBER_AF_WAITING_FOR_SERVICE_DISCOVERY            = 0x00000004,
767     EMBER_AF_WAITING_FOR_ZDO_RESPONSE                 = 0x00000008,
768     EMBER_AF_WAITING_FOR_ZCL_RESPONSE                 = 0x00000010,
769     EMBER_AF_WAITING_FOR_REGISTRATION                 = 0x00000020,
770     EMBER_AF_WAITING_FOR_PARTNER_LINK_KEY_EXCHANGE    = 0x00000040,
771     EMBER_AF_FORCE_SHORT_POLL                         = 0x00000080,
772     EMBER_AF_FRAGMENTATION_IN_PROGRESS                = 0x00000100,
773     EMBER_AF_FORCE_SHORT_POLL_FOR_PARENT_CONNECTIVITY = 0x00000200,
774 };
775
776 /**
777  * @brief a structure used to keep track of cluster related events and
778  * their sleep control values. The cluster code will not know at
779  * runtime all of the events that it has access to in the event table
780  * This structure is stored by the application framework in an event
781  * context table which along with helper functions allows the cluster
782  * code to schedule and deactivate its associated events.
783  */
784 typedef struct
785 {
786     /**
787      * The endpoint of the associated cluster event.
788      */
789     chip::EndpointId endpoint;
790     /**
791      * The cluster id of the associated cluster event.
792      */
793     chip::ClusterId clusterId;
794     /**
795      * The server/client identity of the associated cluster event.
796      */
797     bool isClient;
798     /**
799      * A poll control value used to control the network polling behavior while
800      * the event is active.
801      */
802     EmberAfEventPollControl pollControl;
803     /**
804      * A sleep control value used to control the processor's sleep
805      * behavior while the event is active.
806      */
807     EmberAfEventSleepControl sleepControl;
808     /**
809      * A pointer to the event control value which is stored in the event table
810      * and is used to actually schedule the event.
811      */
812     EmberEventControl * eventControl;
813 } EmberAfEventContext;
814
815 /**
816  * @brief Type for referring to the handler for network events.
817  */
818 typedef void (*EmberAfNetworkEventHandler)(void);
819
820 /**
821  * @brief Type for referring to the handler for endpoint events.
822  */
823 typedef void (*EmberAfEndpointEventHandler)(chip::EndpointId endpoint);
824
825 #ifdef EMBER_AF_PLUGIN_GROUPS_SERVER
826 /**
827  * @brief Indicates the absence of a Group table entry.
828  */
829 #define EMBER_AF_GROUP_TABLE_NULL_INDEX 0xFF
830 /**
831  * @brief Value used when setting or getting the endpoint in a Group table
832  * entry.  It indicates that the entry is not in use.
833  */
834 #define EMBER_AF_GROUP_TABLE_UNUSED_ENDPOINT_ID 0x00
835 /**
836  * @brief Maximum length of Group names, not including the length byte.
837  */
838 #define ZCL_GROUPS_CLUSTER_MAXIMUM_NAME_LENGTH 16
839 /**
840  * @brief A structure used to store group table entries in RAM or in tokens,
841  * depending on the platform.  If the endpoint field is
842  * ::EMBER_AF_GROUP_TABLE_UNUSED_ENDPOINT_ID, the entry is unused.
843  */
844 typedef struct
845 {
846     chip::EndpointId endpoint; // 0x00 when not in use
847     chip::GroupId groupId;
848     uint8_t bindingIndex;
849 #ifdef EMBER_AF_PLUGIN_GROUPS_SERVER_NAME_SUPPORT
850     uint8_t name[ZCL_GROUPS_CLUSTER_MAXIMUM_NAME_LENGTH + 1];
851 #endif
852 } EmberAfGroupTableEntry;
853 #endif // EMBER_AF_PLUGIN_GROUPS_SERVER
854
855 /**
856  * @brief Indicates the absence of a Scene table entry.
857  */
858 #define EMBER_AF_SCENE_TABLE_NULL_INDEX 0xFF
859 /**
860  * @brief Value used when setting or getting the endpoint in a Scene table
861  * entry.  It indicates that the entry is not in use.
862  */
863 #define EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID 0x00
864 /**
865  * @brief Maximum length of Scene names, not including the length byte.
866  */
867 #define ZCL_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH 16
868 /**
869  * @brief The group identifier for the global scene.
870  */
871 #define ZCL_SCENES_GLOBAL_SCENE_GROUP_ID 0x0000
872 /**
873  * @brief The scene identifier for the global scene.
874  */
875 #define ZCL_SCENES_GLOBAL_SCENE_SCENE_ID 0x00
876 /**
877  * @brief A structure used to store scene table entries in RAM or in tokens,
878  * depending on a plugin setting.  If endpoint field is
879  * ::EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID, the entry is unused.
880  */
881 typedef struct
882 {
883     chip::EndpointId endpoint; // 0x00 when this record is not in use
884     chip::GroupId groupId;     // 0x0000 if not associated with a group
885     uint8_t sceneId;
886 #ifdef EMBER_AF_PLUGIN_SCENES_NAME_SUPPORT
887     uint8_t name[ZCL_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH + 1];
888 #endif
889     uint16_t transitionTime;     // in seconds
890     uint8_t transitionTime100ms; // in tenths of a seconds
891 #ifdef ZCL_USING_ON_OFF_CLUSTER_SERVER
892     bool hasOnOffValue;
893     bool onOffValue;
894 #endif
895 #ifdef ZCL_USING_LEVEL_CONTROL_CLUSTER_SERVER
896     bool hasCurrentLevelValue;
897     uint8_t currentLevelValue;
898 #endif
899 #ifdef ZCL_USING_THERMOSTAT_CLUSTER_SERVER
900     bool hasOccupiedCoolingSetpointValue;
901     int16_t occupiedCoolingSetpointValue;
902     bool hasOccupiedHeatingSetpointValue;
903     int16_t occupiedHeatingSetpointValue;
904     bool hasSystemModeValue;
905     uint8_t systemModeValue;
906 #endif
907 #ifdef ZCL_USING_COLOR_CONTROL_CLUSTER_SERVER
908     bool hasCurrentXValue;
909     uint16_t currentXValue;
910     bool hasCurrentYValue;
911     uint16_t currentYValue;
912     bool hasEnhancedCurrentHueValue;
913     uint16_t enhancedCurrentHueValue;
914     bool hasCurrentSaturationValue;
915     uint8_t currentSaturationValue;
916     bool hasColorLoopActiveValue;
917     uint8_t colorLoopActiveValue;
918     bool hasColorLoopDirectionValue;
919     uint8_t colorLoopDirectionValue;
920     bool hasColorLoopTimeValue;
921     uint16_t colorLoopTimeValue;
922     bool hasColorTemperatureMiredsValue;
923     uint16_t colorTemperatureMiredsValue;
924 #endif // ZCL_USING_COLOR_CONTROL_CLUSTER_SERVER
925 #ifdef ZCL_USING_DOOR_LOCK_CLUSTER_SERVER
926     bool hasLockStateValue;
927     uint8_t lockStateValue;
928 #endif
929 #ifdef ZCL_USING_WINDOW_COVERING_CLUSTER_SERVER
930     bool hasCurrentPositionLiftPercentageValue;
931     uint8_t currentPositionLiftPercentageValue;
932     bool hasCurrentPositionTiltPercentageValue;
933     uint8_t currentPositionTiltPercentageValue;
934 #endif
935 } EmberAfSceneTableEntry;
936
937 #if !defined(EMBER_AF_PLUGIN_MESSAGING_CLIENT)
938 // In order to be able to forward declare callbacks regardless of whether the plugin
939 // is enabled, we need to define all data structures.  In order to be able to define
940 // the messaging client data struct, we need to declare this variable.
941 #define EMBER_AF_PLUGIN_MESSAGING_CLIENT_MESSAGE_SIZE 0
942 #endif
943
944 typedef struct
945 {
946     bool valid;
947     bool active;
948     EmberAfPluginEsiManagementBitmask esiBitmask;
949     chip::EndpointId clientEndpoint;
950     uint32_t messageId;
951     uint8_t messageControl;
952     uint32_t startTime;
953     uint32_t endTime;
954     uint16_t durationInMinutes;
955     uint8_t message[EMBER_AF_PLUGIN_MESSAGING_CLIENT_MESSAGE_SIZE + 1];
956 } EmberAfPluginMessagingClientMessage;
957
958 #define ZCL_PRICE_CLUSTER_MAXIMUM_RATE_LABEL_LENGTH 11
959 typedef struct
960 {
961     bool valid;
962     bool active;
963     chip::EndpointId clientEndpoint;
964     uint32_t providerId;
965     uint8_t rateLabel[ZCL_PRICE_CLUSTER_MAXIMUM_RATE_LABEL_LENGTH + 1];
966     uint32_t issuerEventId;
967     uint32_t currentTime;
968     uint8_t unitOfMeasure;
969     uint16_t currency;
970     uint8_t priceTrailingDigitAndPriceTier;
971     uint8_t numberOfPriceTiersAndRegisterTier;
972     uint32_t startTime;
973     uint32_t endTime;
974     uint16_t durationInMinutes;
975     uint32_t price;
976     uint8_t priceRatio;
977     uint32_t generationPrice;
978     uint8_t generationPriceRatio;
979     uint32_t alternateCostDelivered;
980     uint8_t alternateCostUnit;
981     uint8_t alternateCostTrailingDigit;
982     uint8_t numberOfBlockThresholds;
983     uint8_t priceControl;
984 } EmberAfPluginPriceClientPrice;
985
986 /**
987  * @brief Specifies CPP Authorization values
988  */
989 #ifdef DOXYGEN_SHOULD_SKIP_THIS
990 enum EmberAfPluginPriceCppAuth
991 #else
992 typedef uint8_t EmberAfPluginPriceCppAuth;
993 enum
994 #endif
995 {
996     EMBER_AF_PLUGIN_PRICE_CPP_AUTH_PENDING  = 0,
997     EMBER_AF_PLUGIN_PRICE_CPP_AUTH_ACCEPTED = 1,
998     EMBER_AF_PLUGIN_PRICE_CPP_AUTH_REJECTED = 2,
999     EMBER_AF_PLUGIN_PRICE_CPP_AUTH_FORCED   = 3,
1000     EMBER_AF_PLUGIN_PRICE_CPP_AUTH_RESERVED = 4
1001 };
1002
1003 /**
1004  * @brief Value used when setting or getting the endpoint in a report table
1005  * entry.  It indicates that the entry is not in use.
1006  */
1007 #define EMBER_AF_PLUGIN_REPORTING_UNUSED_ENDPOINT_ID 0x00
1008 /**
1009  * @brief A structure used to store reporting configurations.  If endpoint
1010  * field is ::EMBER_AF_PLUGIN_REPORTING_UNUSED_ENDPOINT_ID, the entry is
1011  * unused.
1012  */
1013 typedef struct
1014 {
1015     /** EMBER_ZCL_REPORTING_DIRECTION_REPORTED for reports sent from the local
1016      *  device or EMBER_ZCL_REPORTING_DIRECTION_RECEIVED for reports received
1017      *  from a remote device.
1018      */
1019     EmberAfReportingDirection direction;
1020     /** The local endpoint from which the attribute is reported or to which the
1021      * report is received.  If ::EMBER_AF_PLUGIN_REPORTING_UNUSED_ENDPOINT_ID,
1022      * the entry is unused.
1023      */
1024     chip::EndpointId endpoint;
1025     /** The cluster where the attribute is located. */
1026     chip::ClusterId clusterId;
1027     /** The id of the attribute being reported or received. */
1028     chip::AttributeId attributeId;
1029     /** CLUSTER_MASK_SERVER for server-side attributes or CLUSTER_MASK_CLIENT for
1030      *  client-side attributes.
1031      */
1032     uint8_t mask;
1033     /** Manufacturer code associated with the cluster and/or attribute.  If the
1034      *  cluster id is inside the manufacturer-specific range, this value
1035      *  indicates the manufacturer code for the cluster.  Otherwise, if this
1036      *  value is non-zero and the cluster id is a standard ZCL cluster, it
1037      *  indicates the manufacturer code for attribute.
1038      */
1039     uint16_t manufacturerCode;
1040     union
1041     {
1042         struct
1043         {
1044             /** The minimum reporting interval, measured in seconds. */
1045             uint16_t minInterval;
1046             /** The maximum reporting interval, measured in seconds. */
1047             uint16_t maxInterval;
1048             /** The minimum change to the attribute that will result in a report
1049              *  being sent.
1050              */
1051             uint32_t reportableChange;
1052         } reported;
1053         struct
1054         {
1055             /** The node id of the source of the received reports. */
1056             chip::NodeId source;
1057             /** The remote endpoint from which the attribute is reported. */
1058             chip::EndpointId endpoint;
1059             /** The maximum expected time between reports, measured in seconds. */
1060             uint16_t timeout;
1061         } received;
1062     } data;
1063 } EmberAfPluginReportingEntry;
1064
1065 typedef enum
1066 {
1067     EMBER_AF_PLUGIN_TUNNELING_CLIENT_SUCCESS                          = 0x00,
1068     EMBER_AF_PLUGIN_TUNNELING_CLIENT_BUSY                             = 0x01,
1069     EMBER_AF_PLUGIN_TUNNELING_CLIENT_NO_MORE_TUNNEL_IDS               = 0x02,
1070     EMBER_AF_PLUGIN_TUNNELING_CLIENT_PROTOCOL_NOT_SUPPORTED           = 0x03,
1071     EMBER_AF_PLUGIN_TUNNELING_CLIENT_FLOW_CONTROL_NOT_SUPPORTED       = 0x04,
1072     EMBER_AF_PLUGIN_TUNNELING_CLIENT_IEEE_ADDRESS_REQUEST_FAILED      = 0xF9,
1073     EMBER_AF_PLUGIN_TUNNELING_CLIENT_IEEE_ADDRESS_NOT_FOUND           = 0xFA,
1074     EMBER_AF_PLUGIN_TUNNELING_CLIENT_ADDRESS_TABLE_FULL               = 0xFB,
1075     EMBER_AF_PLUGIN_TUNNELING_CLIENT_LINK_KEY_EXCHANGE_REQUEST_FAILED = 0xFC,
1076     EMBER_AF_PLUGIN_TUNNELING_CLIENT_LINK_KEY_EXCHANGE_FAILED         = 0xFD,
1077     EMBER_AF_PLUGIN_TUNNELING_CLIENT_REQUEST_TUNNEL_FAILED            = 0xFE,
1078     EMBER_AF_PLUGIN_TUNNELING_CLIENT_REQUEST_TUNNEL_TIMEOUT           = 0xFF,
1079 } EmberAfPluginTunnelingClientStatus;
1080
1081 #ifdef EMBER_AF_PLUGIN_ZLL_COMMISSIONING_COMMON
1082 /**
1083  * @brief Status codes used by the ZLL Commissioning plugin.
1084  */
1085 #ifdef DOXYGEN_SHOULD_SKIP_THIS
1086 enum EmberAfZllCommissioningStatus
1087 #else
1088 typedef uint8_t EmberAfZllCommissioningStatus;
1089 enum
1090 #endif
1091 {
1092     EMBER_AF_ZLL_ABORTED_BY_APPLICATION                      = 0x00,
1093     EMBER_AF_ZLL_CHANNEL_CHANGE_FAILED                       = 0x01,
1094     EMBER_AF_ZLL_JOINING_FAILED                              = 0x02,
1095     EMBER_AF_ZLL_NO_NETWORKS_FOUND                           = 0x03,
1096     EMBER_AF_ZLL_PREEMPTED_BY_STACK                          = 0x04,
1097     EMBER_AF_ZLL_SENDING_START_JOIN_FAILED                   = 0x05,
1098     EMBER_AF_ZLL_SENDING_DEVICE_INFORMATION_REQUEST_FAILED   = 0x06,
1099     EMBER_AF_ZLL_SENDING_IDENTIFY_REQUEST_FAILED             = 0x07,
1100     EMBER_AF_ZLL_SENDING_RESET_TO_FACTORY_NEW_REQUEST_FAILED = 0x08,
1101     EMBER_AF_ZLL_NETWORK_FORMATION_FAILED                    = 0x09,
1102     EMBER_AF_ZLL_NETWORK_UPDATE_OPERATION                    = 0x0A,
1103 };
1104
1105 /**
1106  * @brief A structure used to represent Group Information Records used by ZLL
1107  * Commissioning.
1108  */
1109 typedef struct
1110 {
1111     chip::GroupId groupId;
1112     uint8_t groupType;
1113 } EmberAfPluginZllCommissioningGroupInformationRecord;
1114
1115 /**
1116  * @brief A structure used to represent Endpoint Information Records used by
1117  * ZLL Commissioning.
1118  */
1119 typedef struct
1120 {
1121     EmberNodeId networkAddress;
1122     chip::EndpointId endpointId;
1123     uint16_t deviceId;
1124     uint8_t version;
1125 } EmberAfPluginZllCommissioningEndpointInformationRecord;
1126 #endif
1127
1128 typedef enum
1129 {
1130     NO_APP_MESSAGE               = 0,
1131     RECEIVED_PARTNER_CERTIFICATE = 1,
1132     GENERATING_EPHEMERAL_KEYS    = 2,
1133     GENERATING_SHARED_SECRET     = 3,
1134     KEY_GENERATION_DONE          = 4,
1135     GENERATE_SHARED_SECRET_DONE  = 5,
1136     /**
1137      * LINK_KEY_ESTABLISHED indicates Success,
1138      * key establishment done.
1139      */
1140     LINK_KEY_ESTABLISHED = 6,
1141
1142     /**
1143      * Error codes:
1144      * Transient failures where Key Establishment could be retried
1145      */
1146     NO_LOCAL_RESOURCES                  = 7,
1147     PARTNER_NO_RESOURCES                = 8,
1148     TIMEOUT_OCCURRED                    = 9,
1149     INVALID_APP_COMMAND                 = 10,
1150     MESSAGE_SEND_FAILURE                = 11,
1151     PARTNER_SENT_TERMINATE              = 12,
1152     INVALID_PARTNER_MESSAGE             = 13,
1153     PARTNER_SENT_DEFAULT_RESPONSE_ERROR = 14,
1154
1155     /**
1156      * Fatal Errors:
1157      * These results are not worth retrying because the outcome
1158      * will not change
1159      */
1160     BAD_CERTIFICATE_ISSUER      = 15,
1161     KEY_CONFIRM_FAILURE         = 16,
1162     BAD_KEY_ESTABLISHMENT_SUITE = 17,
1163
1164     KEY_TABLE_FULL = 18,
1165
1166     /**
1167      * Neither initiator nor responder is an
1168      * ESP/TC so the key establishment is not
1169      * allowed per the spec.
1170      */
1171     NO_ESTABLISHMENT_ALLOWED = 19,
1172
1173     /* 283k1 certificates need to have valid key usage
1174      */
1175     INVALID_CERTIFICATE_KEY_USAGE = 20,
1176 } EmberAfKeyEstablishmentNotifyMessage;
1177
1178 #define APP_NOTIFY_ERROR_CODE_START NO_LOCAL_RESOURCES
1179 #define APP_NOTIFY_MESSAGE_TEXT                                                                                                    \
1180     {                                                                                                                              \
1181         "None", "Received Cert", "Generate keys", "Generate secret", "Key generate done", "Generate secret done",                  \
1182             "Link key verified",                                                                                                   \
1183                                                                                                                                    \
1184             /* Transient Error codes */                                                                                            \
1185             "No local resources", "Partner no resources", "Timeout", "Invalid app. command", "Message send failure",               \
1186             "Partner sent terminate", "Bad message", "Partner sent Default Rsp",                                                   \
1187                                                                                                                                    \
1188             /* Fatal errors */                                                                                                     \
1189             "Bad cert issuer", "Key confirm failure", "Bad key est. suite", "Key table full", "Not allowed", "Invalid Key Usage",  \
1190     }
1191
1192 /**
1193  * @brief Type for referring to the tick callback for cluster.
1194  *
1195  * Tick function will be called once for each tick for each endpoint in
1196  * the cluster. The rate of tick is determined by the metadata of the
1197  * cluster.
1198  */
1199 typedef void (*EmberAfTickFunction)(chip::EndpointId endpoint);
1200
1201 /**
1202  * @brief Type for referring to the init callback for cluster.
1203  *
1204  * Init function is called when the application starts up, once for
1205  * each cluster/endpoint combination.
1206  */
1207 typedef void (*EmberAfInitFunction)(chip::EndpointId endpoint);
1208
1209 /**
1210  * @brief Type for referring to the attribute changed callback function.
1211  *
1212  * This function is called just after an attribute changes.
1213  */
1214 typedef void (*EmberAfClusterAttributeChangedCallback)(chip::EndpointId endpoint, chip::AttributeId attributeId);
1215
1216 /**
1217  * @brief Type for referring to the manufacturer specific
1218  *        attribute changed callback function.
1219  *
1220  * This function is called just after a manufacturer specific attribute changes.
1221  */
1222 typedef void (*EmberAfManufacturerSpecificClusterAttributeChangedCallback)(chip::EndpointId endpoint, chip::AttributeId attributeId,
1223                                                                            uint16_t manufacturerCode);
1224
1225 /**
1226  * @brief Type for referring to the pre-attribute changed callback function.
1227  *
1228  * This function is called before an attribute changes.
1229  */
1230 typedef EmberAfStatus (*EmberAfClusterPreAttributeChangedCallback)(chip::EndpointId endpoint, chip::AttributeId attributeId,
1231                                                                    EmberAfAttributeType attributeType, uint8_t size,
1232                                                                    uint8_t * value);
1233
1234 /**
1235  * @brief Type for referring to the default response callback function.
1236  *
1237  * This function is called when default response is received, before
1238  * the global callback. Global callback is called immediately afterwards.
1239  */
1240 typedef void (*EmberAfDefaultResponseFunction)(chip::EndpointId endpoint, chip::CommandId commandId, EmberAfStatus status);
1241
1242 /**
1243  * @brief Type for referring to the message sent callback function.
1244  *
1245  * This function is called when a message is sent.
1246  */
1247 typedef void (*EmberAfMessageSentFunction)(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame,
1248                                            uint16_t msgLen, uint8_t * message, EmberStatus status);
1249
1250 /**
1251  * @brief The EmberAfMessageStruct is a struct wrapper that
1252  *   contains all the data about a low-level message to be
1253  *   sent (it may be ZCL or may be some other protocol).
1254  */
1255 typedef struct
1256 {
1257     EmberAfMessageSentFunction callback;
1258     EmberApsFrame * apsFrame;
1259     uint8_t * message;
1260     uint64_t indexOrDestination;
1261     uint16_t messageLength;
1262     EmberOutgoingMessageType type;
1263     bool broadcast;
1264 } EmberAfMessageStruct;
1265
1266 /**
1267  * @brief A data struct for a link key backup.
1268  *
1269  * Each entry notes the EUI64 of the device it is paired to and the key data.
1270  *   This key may be hashed and not the actual link key currently in use.
1271  */
1272
1273 typedef struct
1274 {
1275     EmberEUI64 deviceId;
1276     EmberKeyData key;
1277 } EmberAfLinkKeyBackupData;
1278
1279 /**
1280  * @brief A data struct for all the trust center backup data.
1281  *
1282  * The 'keyList' pointer must point to an array and 'maxKeyListLength'
1283  * must be populated with the maximum number of entries the array can hold.
1284  *
1285  * Functions that modify this data structure will populate 'keyListLength'
1286  * indicating how many keys were actually written into 'keyList'.
1287  */
1288
1289 typedef struct
1290 {
1291     EmberEUI64 extendedPanId;
1292     uint8_t keyListLength;
1293     uint8_t maxKeyListLength;
1294     EmberAfLinkKeyBackupData * keyList;
1295 } EmberAfTrustCenterBackupData;
1296
1297 /**
1298  * @brief The length of the hardware tag in the Ember Bootloader Query
1299  *   Response.
1300  */
1301 #define EMBER_AF_STANDALONE_BOOTLOADER_HARDWARE_TAG_LENGTH 16
1302
1303 /**
1304  * @brief A data struct for the information retrieved during a response
1305  *   to an Ember Bootloader over-the-air query.
1306  */
1307 typedef struct
1308 {
1309     uint8_t hardwareTag[EMBER_AF_STANDALONE_BOOTLOADER_HARDWARE_TAG_LENGTH];
1310     uint8_t eui64[EUI64_SIZE];
1311     uint16_t mfgId;
1312     uint16_t bootloaderVersion;
1313     uint8_t capabilities;
1314     uint8_t platform;
1315     uint8_t micro;
1316     uint8_t phy;
1317     bool bootloaderActive;
1318 } EmberAfStandaloneBootloaderQueryResponseData;
1319
1320 /**
1321  * @brief A data struct used to keep track of incoming and outgoing
1322  *   commands for command discovery
1323  */
1324 typedef struct
1325 {
1326     uint16_t clusterId;
1327     chip::CommandId commandId;
1328     uint8_t mask;
1329 } EmberAfCommandMetadata;
1330
1331 /**
1332  * @brief A data structure used to describe the time in a human
1333  * understandable format (as opposed to 32-bit UTC)
1334  */
1335
1336 typedef struct
1337 {
1338     uint16_t year;
1339     uint8_t month;
1340     uint8_t day;
1341     uint8_t hours;
1342     uint8_t minutes;
1343     uint8_t seconds;
1344 } EmberAfTimeStruct;
1345
1346 /**
1347  * @brief A data structure used to describe the ZCL Date data type
1348  */
1349
1350 typedef struct
1351 {
1352     uint8_t year;
1353     uint8_t month;
1354     uint8_t dayOfMonth;
1355     uint8_t dayOfWeek;
1356 } EmberAfDate;
1357
1358 /* Simple Metering Server Test Code */
1359 #define EMBER_AF_PLUGIN_SIMPLE_METERING_SERVER_ELECTRIC_METER 0
1360 #define EMBER_AF_PLUGIN_SIMPLE_METERING_SERVER_GAS_METER 1
1361
1362 // Functional Notification Flags
1363 // Also #defined in enums.h under slightly different names
1364 #define EMBER_AF_METERING_FNF_NEW_OTA_FIRMWARE 0x00000001
1365 #define EMBER_AF_METERING_FNF_CBKE_UPDATE_REQUEST 0x00000002
1366 #define EMBER_AF_METERING_FNF_TIME_SYNC 0x00000004
1367 #define EMBER_AF_METERING_FNF_STAY_AWAKE_REQUEST_HAN 0x00000010
1368 #define EMBER_AF_METERING_FNF_STAY_AWAKE_REQUEST_WAN 0x00000020
1369 #define EMBER_AF_METERING_FNF_PUSH_HISTORICAL_METERING_DATA_ATTRIBUTE_SET 0x000001C0
1370 #define EMBER_AF_METERING_FNF_PUSH_HISTORICAL_PREPAYMENT_DATA_ATTRIBUTE_SET 0x00000E00
1371 #define EMBER_AF_METERING_FNF_PUSH_ALL_STATIC_DATA_BASIC_CLUSTER 0x00001000
1372 #define EMBER_AF_METERING_FNF_PUSH_ALL_STATIC_DATA_METERING_CLUSTER 0x00002000
1373 #define EMBER_AF_METERING_FNF_PUSH_ALL_STATIC_DATA_PREPAYMENT_CLUSTER 0x00004000
1374 #define EMBER_AF_METERING_FNF_NETWORK_KEY_ACTIVE 0x00008000
1375 #define EMBER_AF_METERING_FNF_DISPLAY_MESSAGE 0x00010000
1376 #define EMBER_AF_METERING_FNF_CANCEL_ALL_MESSAGES 0x00020000
1377 #define EMBER_AF_METERING_FNF_CHANGE_SUPPLY 0x00040000
1378 #define EMBER_AF_METERING_FNF_LOCAL_CHANGE_SUPPLY 0x00080000
1379 #define EMBER_AF_METERING_FNF_SET_UNCONTROLLED_FLOW_THRESHOLD 0x00100000
1380 #define EMBER_AF_METERING_FNF_TUNNEL_MESSAGE_PENDING 0x00200000
1381 #define EMBER_AF_METERING_FNF_GET_SNAPSHOT 0x00400000
1382 #define EMBER_AF_METERING_FNF_GET_SAMPLED_DATA 0x00800000
1383 #define EMBER_AF_METERING_FNF_NEW_SUB_GHZ_CHANNEL_MASKS_AVAILABLE 0x01000000
1384 #define EMBER_AF_METERING_FNF_ENERGY_SCAN_PENDING 0x02000000
1385 #define EMBER_AF_METERING_FNF_CHANNEL_CHANGE_PENDING 0x04000000
1386
1387 // Notification Flags 2
1388 #define EMBER_AF_METERING_NF2_PUBLISH_PRICE 0x00000001
1389 #define EMBER_AF_METERING_NF2_PUBLISH_BLOCK_PERIOD 0x00000002
1390 #define EMBER_AF_METERING_NF2_PUBLISH_TARIFF_INFORMATION 0x00000004
1391 #define EMBER_AF_METERING_NF2_PUBLISH_CONVERSION_FACTOR 0x00000008
1392 #define EMBER_AF_METERING_NF2_PUBLISH_CALORIFIC_VALUE 0x00000010
1393 #define EMBER_AF_METERING_NF2_PUBLISH_CO2_VALUE 0x00000020
1394 #define EMBER_AF_METERING_NF2_PUBLISH_BILLING_PERIOD 0x00000040
1395 #define EMBER_AF_METERING_NF2_PUBLISH_CONSOLIDATED_BILL 0x00000080
1396 #define EMBER_AF_METERING_NF2_PUBLISH_PRICE_MATRIX 0x00000100
1397 #define EMBER_AF_METERING_NF2_PUBLISH_BLOCK_THRESHOLDS 0x00000200
1398 #define EMBER_AF_METERING_NF2_PUBLISH_CURRENCY_CONVERSION 0x00000400
1399 #define EMBER_AF_METERING_NF2_PUBLISH_CREDIT_PAYMENT_INFO 0x00001000
1400 #define EMBER_AF_METERING_NF2_PUBLISH_CPP_EVENT 0x00002000
1401 #define EMBER_AF_METERING_NF2_PUBLISH_TIER_LABELS 0x00004000
1402 #define EMBER_AF_METERING_NF2_CANCEL_TARIFF 0x00008000
1403
1404 // Notification Flags 3
1405 #define EMBER_AF_METERING_NF3_PUBLISH_CALENDAR 0x00000001
1406 #define EMBER_AF_METERING_NF3_PUBLISH_SPECIAL_DAYS 0x00000002
1407 #define EMBER_AF_METERING_NF3_PUBLISH_SEASONS 0x00000004
1408 #define EMBER_AF_METERING_NF3_PUBLISH_WEEK 0x00000008
1409 #define EMBER_AF_METERING_NF3_PUBLISH_DAY 0x00000010
1410 #define EMBER_AF_METERING_NF3_CANCEL_CALENDAR 0x00000020
1411
1412 // Notification Flags 4
1413 #define EMBER_AF_METERING_NF4_SELECT_AVAILABLE_EMERGENCY_CREDIT 0x00000001
1414 #define EMBER_AF_METERING_NF4_CHANGE_DEBT 0x00000002
1415 #define EMBER_AF_METERING_NF4_EMERGENCY_CREDIT_SETUP 0x00000004
1416 #define EMBER_AF_METERING_NF4_CONSUMER_TOP_UP 0x00000008
1417 #define EMBER_AF_METERING_NF4_CREDIT_ADJUSTMENT 0x00000010
1418 #define EMBER_AF_METERING_NF4_CHANGE_PAYMENT_MODE 0x00000020
1419 #define EMBER_AF_METERING_NF4_GET_PREPAY_SNAPSHOT 0x00000040
1420 #define EMBER_AF_METERING_NF4_GET_TOP_UP_LOG 0x00000080
1421 #define EMBER_AF_METERING_NF4_SET_LOW_CREDIT_WARNING_LEVEL 0x00000100
1422 #define EMBER_AF_METERING_NF4_GET_DEBT_REPAYMENT_LOG 0x00000200
1423 #define EMBER_AF_METERING_NF4_SET_MAXIMUM_CREDIT_LIMIT 0x00000400
1424 #define EMBER_AF_METERING_NF4_SET_OVERALL_DEBT_CAP 0x00000800
1425
1426 // Notification Flags 5
1427 #define EMBER_AF_METERING_NF5_PUBLISH_CHANGE_OF_TENANCY 0x00000001
1428 #define EMBER_AF_METERING_NF5_PUBLISH_CHANGE_OF_SUPPLIER 0x00000002
1429 #define EMBER_AF_METERING_NF5_REQUEST_NEW_PASSWORD_1_RESPONSE 0x00000004
1430 #define EMBER_AF_METERING_NF5_REQUEST_NEW_PASSWORD_2_RESPONSE 0x00000008
1431 #define EMBER_AF_METERING_NF5_REQUEST_NEW_PASSWORD_3_RESPONSE 0x00000010
1432 #define EMBER_AF_METERING_NF5_REQUEST_NEW_PASSWORD_4_RESPONSE 0x00000020
1433 #define EMBER_AF_METERING_NF5_UPDATE_SITE_ID 0x00000040
1434 #define EMBER_AF_METERING_NF5_RESET_BATTERY_COUNTER 0x00000080
1435 #define EMBER_AF_METERING_NF5_UPDATE_CIN 0x00000100
1436
1437 /**
1438  * @brief Device Management plugin types
1439  */
1440
1441 #define EMBER_AF_DEVICE_MANAGEMENT_MAXIMUM_PROPOSED_PROVIDER_NAME_LENGTH (16)
1442 #define EMBER_AF_DEVICE_MANAGEMENT_MAXIMUM_PROPOSED_PROVIDER_CONTACT_DETAILS_LENGTH (18)
1443 #define EMBER_AF_DEVICE_MANAGEMENT_MAXIMUM_SITE_ID_LENGTH (32)
1444 #define EMBER_AF_DEVICE_MANAGEMENT_MAXIMUM_CIN_LENGTH (24)
1445 #define EMBER_AF_DEVICE_MANAGEMENT_MAXIMUM_PASSWORD_LENGTH (10)
1446
1447 #ifdef DOXYGEN_SHOULD_SKIP_THIS
1448 enum EmberAfDeviceManagementPasswordType
1449 #else
1450 typedef uint16_t EmberAfDeviceManagementPasswordType;
1451 enum
1452 #endif
1453 {
1454     UNUSED_PASSWORD   = 0x00,
1455     SERVICE_PASSWORD  = 0x01,
1456     CONSUMER_PASSWORD = 0x02,
1457 };
1458
1459 #ifdef DOXYGEN_SHOULD_SKIP_THIS
1460 enum EmberAfDeviceManagementChangePendingFlags
1461 #else
1462 typedef uint8_t EmberAfDeviceManagementChangePendingFlags;
1463 enum
1464 #endif
1465 {
1466     EMBER_AF_DEVICE_MANAGEMENT_CHANGE_OF_TENANCY_PENDING_MASK        = 0x01,
1467     EMBER_AF_DEVICE_MANAGEMENT_CHANGE_OF_SUPPLIER_PENDING_MASK       = 0x02,
1468     EMBER_AF_DEVICE_MANAGEMENT_UPDATE_SITE_ID_PENDING_MASK           = 0x04,
1469     EMBER_AF_DEVICE_MANAGEMENT_UPDATE_CIN_PENDING_MASK               = 0x08,
1470     EMBER_AF_DEVICE_MANAGEMENT_UPDATE_SERVICE_PASSWORD_PENDING_MASK  = 0x10,
1471     EMBER_AF_DEVICE_MANAGEMENT_UPDATE_CONSUMER_PASSWORD_PENDING_MASK = 0x20,
1472 };
1473
1474 typedef struct
1475 {
1476     // Optional fields only used by Gas Proxy Function plugin.
1477     uint32_t providerId;
1478     uint32_t issuerEventId;
1479     uint8_t tariffType;
1480
1481     // always used fields
1482     uint32_t implementationDateTime;
1483     uint32_t tenancy;
1484 } EmberAfDeviceManagementTenancy;
1485
1486 typedef struct
1487 {
1488     uint32_t proposedProviderId;
1489     uint32_t implementationDateTime;
1490     uint32_t providerChangeControl;
1491     uint8_t proposedProviderName[EMBER_AF_DEVICE_MANAGEMENT_MAXIMUM_PROPOSED_PROVIDER_NAME_LENGTH + 1];
1492     uint8_t proposedProviderContactDetails[EMBER_AF_DEVICE_MANAGEMENT_MAXIMUM_PROPOSED_PROVIDER_CONTACT_DETAILS_LENGTH + 1];
1493 } EmberAfDeviceManagementSupplier;
1494
1495 typedef struct
1496 {
1497     uint32_t requestDateTime;
1498     uint32_t implementationDateTime;
1499     uint8_t supplyStatus;
1500     uint8_t originatorIdSupplyControlBits;
1501 } EmberAfDeviceManagementSupply;
1502
1503 typedef struct
1504 {
1505     uint8_t siteId[EMBER_AF_DEVICE_MANAGEMENT_MAXIMUM_SITE_ID_LENGTH + 1];
1506     uint32_t implementationDateTime;
1507     uint32_t issuerEventId;
1508 } EmberAfDeviceManagementSiteId;
1509
1510 typedef struct
1511 {
1512     uint8_t cin[EMBER_AF_DEVICE_MANAGEMENT_MAXIMUM_CIN_LENGTH + 1];
1513     uint32_t implementationDateTime;
1514     uint32_t issuerEventId;
1515 } EmberAfDeviceManagementCIN;
1516
1517 typedef struct
1518 {
1519     bool supplyTamperState;
1520     bool supplyDepletionState;
1521     bool supplyUncontrolledFlowState;
1522     bool loadLimitSupplyState;
1523 } EmberAfDeviceManagementSupplyStatusFlags;
1524
1525 typedef struct
1526 {
1527     uint16_t uncontrolledFlowThreshold;
1528     uint16_t multiplier;
1529     uint16_t divisor;
1530     uint16_t measurementPeriod;
1531     uint8_t unitOfMeasure;
1532     uint8_t stabilisationPeriod;
1533 } EmberAfDeviceManagementUncontrolledFlowThreshold;
1534
1535 typedef struct
1536 {
1537     uint32_t implementationDateTime;
1538     uint8_t supplyStatus;
1539 } EmberAfDeviceManagementSupplyStatus;
1540
1541 typedef struct
1542 {
1543     uint8_t password[EMBER_AF_DEVICE_MANAGEMENT_MAXIMUM_PASSWORD_LENGTH + 1];
1544     uint32_t implementationDateTime;
1545     uint16_t durationInMinutes;
1546     EmberAfDeviceManagementPasswordType passwordType;
1547 } EmberAfDeviceManagementPassword;
1548
1549 typedef struct
1550 {
1551     uint8_t startIndex;
1552     uint8_t endIndex;
1553 } EmberAfDeviceManagementAttributeRange;
1554
1555 // attrRange is a list of attributeId values in a cluster. It's needed to track contigous
1556 // segments of valid attributeId's with gaps in the middle.
1557 // attributeSetId is the value of the upper byte in the attributeId. It ranges from 0x01(Price)
1558 // to 0x08(OTA Event Configuration)
1559 // Eg. {0x00,0x05} and {0x08,0x0A}
1560 // We're betting that there isn't a list of cluster attributes that has more than 5 gaps.
1561 typedef struct
1562 {
1563     uint8_t attributeSetId;
1564     EmberAfDeviceManagementAttributeRange attributeRange[7];
1565 } EmberAfDeviceManagementAttributeTable;
1566
1567 typedef struct
1568 {
1569     bool encryption;
1570
1571     uint8_t * plainPayload;
1572     uint16_t plainPayloadLength;
1573
1574     uint8_t * encryptedPayload;
1575     uint16_t encryptedPayloadLength;
1576 } EmberAfGbzMessageData;
1577
1578 typedef struct
1579 {
1580     uint8_t * gbzCommands;
1581     uint16_t gbzCommandsLength;
1582     uint8_t * gbzCommandsResponse;
1583     uint16_t gbzCommandsResponseLength;
1584     uint16_t messageCode;
1585 } EmberAfGpfMessage;
1586
1587 /**
1588  * @brief Zigbee Internet Client/Server Remote Cluster Types
1589  */
1590 typedef uint16_t EmberAfRemoteClusterType;
1591
1592 #define EMBER_AF_REMOTE_CLUSTER_TYPE_NONE 0x0000
1593 #define EMBER_AF_REMOTE_CLUSTER_TYPE_SERVER 0x0001
1594 #define EMBER_AF_REMOTE_CLUSTER_TYPE_CLIENT 0x0002
1595 #define EMBER_AF_REMOTE_CLUSTER_TYPE_INVALID 0xFFFF
1596
1597 /**
1598  * @brief Zigbee Internet Client/Server remote cluster struct.
1599  */
1600 typedef struct
1601 {
1602     chip::ClusterId clusterId;
1603     uint16_t deviceId;
1604     chip::EndpointId endpoint;
1605     EmberAfRemoteClusterType type;
1606 } EmberAfRemoteClusterStruct;
1607
1608 /**
1609  * @brief Zigbee Internet Client/Server Remote Binding struct
1610  */
1611 typedef struct
1612 {
1613     EmberEUI64 targetEUI64;
1614     chip::EndpointId sourceEndpoint;
1615     chip::EndpointId destEndpoint;
1616     chip::ClusterId clusterId;
1617     EmberEUI64 destEUI64;
1618     EmberEUI64 sourceEUI64;
1619 } EmberAfRemoteBindingStruct;
1620
1621 typedef struct
1622 {
1623     chip::ClusterId clusterId;
1624     bool server;
1625 } EmberAfClusterInfo;
1626
1627 #if !defined(EMBER_AF_MAX_CLUSTERS_PER_ENDPOINT)
1628 #define EMBER_AF_MAX_CLUSTERS_PER_ENDPOINT 3
1629 #endif
1630
1631 /**
1632  * @brief A struct containing basic information about an endpoint.
1633  */
1634 typedef struct
1635 {
1636     EmberAfClusterInfo clusters[EMBER_AF_MAX_CLUSTERS_PER_ENDPOINT];
1637     uint16_t deviceId;
1638     chip::EndpointId endpoint;
1639     uint8_t clusterCount;
1640 } EmberAfEndpointInfoStruct;
1641
1642 #if !defined(EMBER_AF_MAX_ENDPOINTS_PER_DEVICE)
1643 #define EMBER_AF_MAX_ENDPOINTS_PER_DEVICE 1
1644 #endif
1645
1646 // Although we treat this like a bitmap, only 1 bit is set at a time.
1647 // We use the bitmap feature to allow us to find all devices
1648 // with any in a set of status codes using
1649 // emberAfPluginDeviceDatabaseFindDeviceByStatus().
1650 typedef enum
1651 {
1652     EMBER_AF_DEVICE_DISCOVERY_STATUS_NONE                = 0x00,
1653     EMBER_AF_DEVICE_DISCOVERY_STATUS_NEW                 = 0x01,
1654     EMBER_AF_DEVICE_DISCOVERY_STATUS_FIND_ENDPOINTS      = 0x02,
1655     EMBER_AF_DEVICE_DISCOVERY_STATUS_FIND_CLUSTERS       = 0x04,
1656     EMBER_AF_DEVICE_DISCOVERY_STATUS_FIND_STACK_REVISION = 0x08,
1657
1658     EMBER_AF_DEVICE_DISCOVERY_STATUS_DONE   = 0x40,
1659     EMBER_AF_DEVICE_DISCOVERY_STATUS_FAILED = 0x80,
1660 } EmberAfDeviceDiscoveryStatus;
1661
1662 /**
1663  * @brief A struct containing endpoint information about a device.
1664  */
1665 typedef struct
1666 {
1667     EmberEUI64 eui64;
1668     EmberAfEndpointInfoStruct endpoints[EMBER_AF_MAX_ENDPOINTS_PER_DEVICE];
1669     EmberAfDeviceDiscoveryStatus status;
1670     uint8_t discoveryFailures;
1671     uint8_t capabilities;
1672     uint8_t endpointCount;
1673     uint8_t stackRevision;
1674 } EmberAfDeviceInfo;
1675
1676 typedef struct
1677 {
1678     uint16_t deviceIndex;
1679 } EmberAfDeviceDatabaseIterator;
1680
1681 typedef struct
1682 {
1683     EmberNodeId emberNodeId;
1684     uint32_t timeStamp;
1685 } EmberAfJoiningDevice;
1686
1687 #define EMBER_AF_INVALID_CLUSTER_ID 0xFFFF
1688
1689 #define EMBER_AF_INVALID_ENDPOINT 0xFF
1690
1691 #define EMBER_AF_INVALID_PAN_ID 0xFFFF
1692
1693 /**
1694  * @brief Permit join times
1695  */
1696 #define EMBER_AF_PERMIT_JOIN_FOREVER 0xFF
1697 #define EMBER_AF_PERMIT_JOIN_MAX_TIMEOUT 0xFE
1698
1699 #define MAX_INT32U_VALUE (0xFFFFFFFFUL)
1700 #define MAX_INT16U_VALUE (0xFFFF)
1701 #define MAX_INT8U_VALUE (0xFF)
1702
1703 /**
1704  * @brief Returns the elapsed time between two 32 bit values.
1705  *   Result may not be valid if the time samples differ by more than 2147483647
1706  */
1707 #define elapsedTimeInt32u(oldTime, newTime) ((uint32_t)((uint32_t)(newTime) - (uint32_t)(oldTime)))
1708
1709 /**
1710  * @brief The overhead of the ZDO response.
1711  *   1 byte for the sequence and 1 byte for the status code.
1712  */
1713 #define EMBER_AF_ZDO_RESPONSE_OVERHEAD 2
1714
1715 /** @} END addtogroup */