3 // Prevent multiple inclusion
6 #include "af-structs.h"
8 #include "basic-types.h"
10 #include <lib/support/Span.h>
12 /** @brief Cluster Init
14 * This function is called when a specific cluster is initialized. It gives the
15 * application an opportunity to take care of cluster initialization procedures.
16 * It is called exactly once for each endpoint where cluster is present.
18 * @param endpoint Ver.: always
19 * @param clusterId Ver.: always
21 void emberAfClusterInitCallback(chip::EndpointId endpoint, chip::ClusterId clusterId);
23 // Cluster Init Functions
25 {{#all_user_clusters_names}}
27 /** @brief {{name}} Cluster Init
31 * @param endpoint Endpoint that is being initialized
33 void emberAf{{asCamelCased name false}}ClusterInitCallback(chip::EndpointId endpoint);
35 {{/all_user_clusters_names}}
37 // Cluster Server/Client Init Functions
39 {{#all_user_clusters}}
42 // {{name}} Cluster {{side}}
45 /** @brief {{name}} Cluster {{asCamelCased side false}} Init
47 * {{asCamelCased side false}} Init
49 * @param endpoint Endpoint that is being initialized
51 void emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}InitCallback(chip::EndpointId endpoint);
53 /** @brief {{name}} Cluster {{asCamelCased side false}} Attribute Changed
55 * {{asCamelCased side false}} Attribute Changed
57 * @param endpoint Endpoint that is being initialized
58 * @param attributeId Attribute that changed
60 void emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}AttributeChangedCallback(chip::EndpointId endpoint, chip::AttributeId attributeId);
62 /** @brief {{name}} Cluster {{asCamelCased side false}} Manufacturer Specific Attribute Changed
64 * {{asCamelCased side false}} Manufacturer Specific Attribute Changed
66 * @param endpoint Endpoint that is being initialized
67 * @param attributeId Attribute that changed
68 * @param manufacturerCode Manufacturer Code of the attribute that changed
70 void emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}ManufacturerSpecificAttributeChangedCallback(chip::EndpointId endpoint, chip::AttributeId attributeId, uint16_t manufacturerCode);
72 /** @brief {{name}} Cluster {{asCamelCased side false}} Message Sent
74 * {{asCamelCased side false}} Message Sent
76 * @param type The type of message sent
77 * @param indexOrDestination The destination or address to which the message was sent
78 * @param apsFrame The APS frame for the message
79 * @param msgLen The length of the message
80 * @param message The message that was sent
81 * @param status The status of the sent message
83 void emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}MessageSentCallback(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message, EmberStatus status);
85 /** @brief {{name}} Cluster {{asCamelCased side false}} Pre Attribute Changed
87 * {{asCamelCased side}} Pre Attribute Changed
89 * @param endpoint Endpoint that is being initialized
90 * @param attributeId Attribute to be changed
91 * @param attributeType Attribute type
92 * @param size Attribute size
93 * @param value Attribute value
95 EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}PreAttributeChangedCallback(chip::EndpointId endpoint, chip::AttributeId attributeId, EmberAfAttributeType attributeType, uint8_t size, uint8_t * value);
97 /** @brief {{name}} Cluster {{asCamelCased side false}} Tick
99 * {{asCamelCased side}} Tick
101 * @param endpoint Endpoint that is being served
103 void emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}TickCallback(chip::EndpointId endpoint);
104 {{/all_user_clusters}}
106 // Cluster Commands Callback
108 {{#all_user_clusters}}
109 {{#if (isEnabled enabled)}}
110 {{#all_user_cluster_commands}}
111 {{#if (isStrEqual clusterName parent.name)}}
112 {{#if (isCommandAvailable parent.side incoming outgoing commandSource)}}
114 * @brief {{parent.name}} Cluster {{name}} Command callback
115 {{#if (zcl_command_arguments_count this.id)}}
116 {{#zcl_command_arguments}}
117 * @param {{asCamelCased label}}
118 {{/zcl_command_arguments}}
122 bool emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback({{#zcl_command_arguments}}{{#if (isOctetString type)}}chip::ByteSpan{{else}}{{asUnderlyingZclType type}}{{/if}} {{asSymbol label}}{{#unless (isLastElement index count)}}, {{/unless}}{{/zcl_command_arguments}});
126 {{/all_user_cluster_commands}}
128 {{/all_user_clusters}}
131 // Non-Cluster Related Callbacks
134 /** @brief Add To Current App Tasks
136 * This function is only useful to sleepy end devices. This function will note
137 * the passed item as part of a set of tasks the application has outstanding
138 * (e.g. message sent requiring APS acknwoledgement). This will affect how the
139 * application behaves with regard to sleeping and polling. Until the
140 * outstanding task is completed, the device may poll more frequently and sleep
143 * @param tasks Ver.: always
145 void emberAfAddToCurrentAppTasksCallback(EmberAfApplicationTask tasks);
147 /** @brief Remove From Current App Tasks
149 * This function is only useful to sleepy end devices. This function will
150 * remove the passed item from the set of tasks the application has outstanding
151 * (e.g. message sent requiring APS acknwoledgement). This will affect how the
152 * application behaves with regard to sleeping and polling. Removing the item
153 * from the list of outstanding tasks may allow the device to sleep longer and
154 * poll less frequently. If there are other outstanding tasks the system may
155 * still have to stay away and poll more often.
157 * @param tasks Ver.: always
159 void emberAfRemoveFromCurrentAppTasksCallback(EmberAfApplicationTask tasks);
161 /** @brief Allow Network Write Attribute
163 * This function is called by the application framework before it writes an
164 * attribute in response to a write attribute request from an external device.
165 * The value passed into this callback is the value to which the attribute is to
166 * be set by the framework.
167 Example: In mirroring simple metering data
168 * on an Energy Services Interface (ESI) (formerly called Energy Service Portal
169 * (ESP) in SE 1.0).), a mirrored simple meter needs to write read-only
170 * attributes on its mirror. The-meter-mirror sample application, located in
171 * app/framework/sample-apps, uses this callback to allow the mirrored device to
172 * write simple metering attributes on the mirror regardless of the fact that
173 * most simple metering attributes are defined as read-only by the ZigBee
175 Note: The ZCL specification does not (as of this
176 * writing) specify any permission-level security for writing writeable
177 * attributes. As far as the ZCL specification is concerned, if an attribute is
178 * writeable, any device that has a link key for the device should be able to
179 * write that attribute. Furthermore if an attribute is read only, it should not
180 * be written over the air. Thus, if you implement permissions for writing
181 * attributes as a feature, you MAY be operating outside the specification. This
182 * is unlikely to be a problem for writing read-only attributes, but it may be a
183 * problem for attributes that are writeable according to the specification but
184 * restricted by the application implementing this callback.
186 * @param endpoint Ver.: always
187 * @param clusterId Ver.: always
188 * @param attributeId Ver.: always
189 * @param mask Ver.: always
190 * @param manufacturerCode Ver.: always
191 * @param value Ver.: always
192 * @param type Ver.: always
194 EmberAfAttributeWritePermission emberAfAllowNetworkWriteAttributeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
195 chip::AttributeId attributeId, uint8_t mask,
196 uint16_t manufacturerCode, uint8_t * value, uint8_t type);
198 /** @brief Attribute Read Access
200 * This function is called whenever the Application Framework needs to check
201 * access permission for an attribute read.
203 * @param endpoint Ver.: always
204 * @param clusterId Ver.: always
205 * @param manufacturerCode Ver.: always
206 * @param attributeId Ver.: always
208 bool emberAfAttributeReadAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, uint16_t manufacturerCode,
209 chip::AttributeId attributeId);
211 /** @brief Attribute Write Access
213 * This function is called whenever the Application Framework needs to check
214 * access permission for an attribute write.
216 * @param endpoint Ver.: always
217 * @param clusterId Ver.: always
218 * @param manufacturerCode Ver.: always
219 * @param attributeId Ver.: always
221 bool emberAfAttributeWriteAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, uint16_t manufacturerCode,
222 chip::AttributeId attributeId);
224 /** @brief Default Response
226 * This function is called by the application framework when a Default Response
227 * command is received from an external device. The application should return
228 * true if the message was processed or false if it was not.
230 * @param clusterId The cluster identifier of this response. Ver.: always
231 * @param commandId The command identifier to which this is a response. Ver.:
233 * @param status Specifies either SUCCESS or the nature of the error that was
234 * detected in the received command. Ver.: always
236 bool emberAfDefaultResponseCallback(chip::ClusterId clusterId, chip::CommandId commandId, EmberAfStatus status);
238 /** @brief Configure Reporting Response
240 * This function is called by the application framework when a Configure
241 * Reporting Response command is received from an external device. The
242 * application should return true if the message was processed or false if it
245 * @param clusterId The cluster identifier of this response. Ver.: always
246 * @param buffer Buffer containing the list of attribute status records. Ver.:
248 * @param bufLen The length in bytes of the list. Ver.: always
250 bool emberAfConfigureReportingResponseCallback(chip::ClusterId clusterId, uint8_t * buffer, uint16_t bufLen);
252 /** @brief Read Reporting Configuration Response
254 * This function is called by the application framework when a Read Reporting
255 * Configuration Response command is received from an external device. The
256 * application should return true if the message was processed or false if it
259 * @param clusterId The cluster identifier of this response. Ver.: always
260 * @param buffer Buffer containing the list of attribute reporting configuration
261 * records. Ver.: always
262 * @param bufLen The length in bytes of the list. Ver.: always
264 bool emberAfReadReportingConfigurationResponseCallback(chip::ClusterId clusterId, uint8_t * buffer, uint16_t bufLen);
266 /** @brief Discover Attributes Response
268 * This function is called by the application framework when a Discover
269 * Attributes Response or Discover Attributes Extended Response command is
270 * received from an external device. The Discover Attributes Response command
271 * contains a bool indicating if discovery is complete and a list of zero or
272 * more attribute identifier/type records. The final argument indicates whether
273 * the response is in the extended format or not. The application should return
274 * true if the message was processed or false if it was not.
276 * @param clusterId The cluster identifier of this response. Ver.: always
277 * @param discoveryComplete Indicates whether there are more attributes to be
278 * discovered. true if there are no more attributes to be discovered. Ver.:
280 * @param buffer Buffer containing the list of attribute identifier/type
281 * records. Ver.: always
282 * @param bufLen The length in bytes of the list. Ver.: always
283 * @param extended Indicates whether the response is in the extended format or
286 bool emberAfDiscoverAttributesResponseCallback(chip::ClusterId clusterId, bool discoveryComplete, uint8_t * buffer,
287 uint16_t bufLen, bool extended);
289 /** @brief Discover Commands Generated Response
291 * This function is called by the framework when Discover Commands Generated
292 * Response is received.
294 * @param clusterId The cluster identifier of this response. Ver.: always
295 * @param manufacturerCode Manufacturer code Ver.: always
296 * @param discoveryComplete Indicates whether there are more commands to be
297 * discovered. Ver.: always
298 * @param commandIds Buffer containing the list of command identifiers. Ver.:
300 * @param commandIdCount The length of bytes of the list, whish is the same as
301 * the number of identifiers. Ver.: always
303 bool emberAfDiscoverCommandsGeneratedResponseCallback(chip::ClusterId clusterId, uint16_t manufacturerCode, bool discoveryComplete,
304 chip::CommandId * commandIds, uint16_t commandIdCount);
307 /** @brief Discover Commands Received Response
309 * This function is called by the framework when Discover Commands Received
310 * Response is received.
312 * @param clusterId The cluster identifier of this response. Ver.: always
313 * @param manufacturerCode Manufacturer code Ver.: always
314 * @param discoveryComplete Indicates whether there are more commands to be
315 * discovered. Ver.: always
316 * @param commandIds Buffer containing the list of command identifiers. Ver.:
318 * @param commandIdCount The length of bytes of the list, whish is the same as
319 * the number of identifiers. Ver.: always
321 bool emberAfDiscoverCommandsReceivedResponseCallback(chip::ClusterId clusterId, uint16_t manufacturerCode, bool discoveryComplete,
322 chip::CommandId * commandIds, uint16_t commandIdCount);
325 /** @brief Pre Command Received
327 * This callback is the second in the Application Framework's message processing
328 * chain. At this point in the processing of incoming over-the-air messages, the
329 * application has determined that the incoming message is a ZCL command. It
330 * parses enough of the message to populate an EmberAfClusterCommand struct. The
331 * Application Framework defines this struct value in a local scope to the
332 * command processing but also makes it available through a global pointer
333 * called emberAfCurrentCommand, in app/framework/util/util.c. When command
334 * processing is complete, this pointer is cleared.
336 * @param cmd Ver.: always
338 bool emberAfPreCommandReceivedCallback(EmberAfClusterCommand * cmd);
340 /** @brief Pre Message Send
342 * This function is called by the framework when it is about to pass a message
343 * to the stack primitives for sending. This message may or may not be ZCL,
344 * ZDO, or some other protocol. This is called prior to
346 * fragmentation that may be done. If the function returns true it is assumed
347 * the callback has consumed and processed the message. The callback must also
348 * set the EmberStatus status code to be passed back to the caller. The
349 * framework will do no further processing on the message.
351 * function returns false then it is assumed that the callback has not processed
352 * the mesasge and the framework will continue to process accordingly.
354 * @param messageStruct The structure containing the parameters of the APS
355 * message to be sent. Ver.: always
356 * @param status A pointer to the status code value that will be returned to the
357 * caller. Ver.: always
359 bool emberAfPreMessageSendCallback(EmberAfMessageStruct * messageStruct, EmberStatus * status);
361 /** @brief Message Sent
363 * This function is called by the application framework from the message sent
364 * handler, when it is informed by the stack regarding the message sent status.
365 * All of the values passed to the emberMessageSentHandler are passed on to this
366 * callback. This provides an opportunity for the application to verify that its
367 * message has been sent successfully and take the appropriate action. This
368 * callback should return a bool value of true or false. A value of true
369 * indicates that the message sent notification has been handled and should not
370 * be handled by the application framework.
372 * @param type Ver.: always
373 * @param indexOrDestination Ver.: always
374 * @param apsFrame Ver.: always
375 * @param msgLen Ver.: always
376 * @param message Ver.: always
377 * @param status Ver.: always
379 bool emberAfMessageSentCallback(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame,
380 uint16_t msgLen, uint8_t * message, EmberStatus status);
382 /** @brief Pre Attribute Change
384 * This function is called by the application framework before it changes an
385 * attribute value. The value passed into this callback is the value to which
386 * the attribute is to be set by the framework. The application should return
387 * ::EMBER_ZCL_STATUS_SUCCESS to permit the change or any other ::EmberAfStatus
390 * @param endpoint Ver.: always
391 * @param clusterId Ver.: always
392 * @param attributeId Ver.: always
393 * @param mask Ver.: always
394 * @param manufacturerCode Ver.: always
395 * @param type Ver.: always
396 * @param size Ver.: always
397 * @param value Ver.: always
399 EmberAfStatus emberAfPreAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId,
400 uint8_t mask, uint16_t manufacturerCode, uint8_t type, uint8_t size,
403 /** @brief Post Attribute Change
405 * This function is called by the application framework after it changes an
406 * attribute value. The value passed into this callback is the value to which
407 * the attribute was set by the framework.
409 * @param endpoint Ver.: always
410 * @param clusterId Ver.: always
411 * @param attributeId Ver.: always
412 * @param mask Ver.: always
413 * @param manufacturerCode Ver.: always
414 * @param type Ver.: always
415 * @param size Ver.: always
416 * @param value Ver.: always
418 void emberAfPostAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t mask,
419 uint16_t manufacturerCode, uint8_t type, uint8_t size, uint8_t * value);
421 /** @brief Read Attributes Response
423 * This function is called by the application framework when a Read Attributes
424 * Response command is received from an external device. The application should
425 * return true if the message was processed or false if it was not.
427 * @param clusterId The cluster identifier of this response. Ver.: always
428 * @param buffer Buffer containing the list of read attribute status records.
430 * @param bufLen The length in bytes of the list. Ver.: always
432 bool emberAfReadAttributesResponseCallback(chip::ClusterId clusterId, uint8_t * buffer, uint16_t bufLen);
434 /** @brief External Attribute Read
436 * Like emberAfExternalAttributeWriteCallback above, this function is called
437 * when the framework needs to read an attribute that is not stored within the
438 * Application Framework's data structures.
440 * information about the attribute itself is passed as a pointer to an
441 * EmberAfAttributeMetadata struct, which is stored within the application and
442 * used to manage the attribute. A complete description of the
443 * EmberAfAttributeMetadata struct is provided in
444 * app/framework/include/af-types.h
445 This function assumes that the
446 * application is able to read the attribute, write it into the passed buffer,
447 * and return immediately. Any attributes that require a state machine for
448 * reading and writing are not really candidates for externalization at the
449 * present time. The Application Framework does not currently include a state
450 * machine for reading or writing attributes that must take place across a
451 * series of application ticks. Attributes that cannot be read in a timely
452 * manner should be stored within the Application Framework and updated
453 * occasionally by the application code from within the
454 * emberAfMainTickCallback.
455 If the application was successfully able to
456 * read the attribute and write it into the passed buffer, it should return a
457 * value of EMBER_ZCL_STATUS_SUCCESS. Ensure that the size of the externally
458 * managed attribute value is smaller than what the buffer can hold. In the case
459 * of a buffer overflow throw an appropriate error such as
460 * EMBER_ZCL_STATUS_INSUFFICIENT_SPACE. Any other return value indicates the
461 * application was not able to read the attribute.
463 * @param endpoint Ver.: always
464 * @param clusterId Ver.: always
465 * @param attributeMetadata Ver.: always
466 * @param manufacturerCode Ver.: always
467 * @param buffer Ver.: always
468 * @param maxReadLength Ver.: always
470 EmberAfStatus emberAfExternalAttributeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
471 EmberAfAttributeMetadata * attributeMetadata, uint16_t manufacturerCode,
472 uint8_t * buffer, uint16_t maxReadLength);
474 /** @brief Write Attributes Response
476 * This function is called by the application framework when a Write Attributes
477 * Response command is received from an external device. The application should
478 * return true if the message was processed or false if it was not.
480 * @param clusterId The cluster identifier of this response. Ver.: always
481 * @param buffer Buffer containing the list of write attribute status records.
483 * @param bufLen The length in bytes of the list. Ver.: always
485 bool emberAfWriteAttributesResponseCallback(chip::ClusterId clusterId, uint8_t * buffer, uint16_t bufLen);
487 /** @brief External Attribute Write
489 * This function is called whenever the Application Framework needs to write an
490 * attribute which is not stored within the data structures of the Application
491 * Framework itself. One of the new features in Version 2 is the ability to
492 * store attributes outside the Framework. This is particularly useful for
493 * attributes that do not need to be stored because they can be read off the
494 * hardware when they are needed, or are stored in some central location used by
495 * many modules within the system. In this case, you can indicate that the
496 * attribute is stored externally. When the framework needs to write an external
497 * attribute, it makes a call to this callback.
498 This callback is very
499 * useful for host micros which need to store attributes in persistent memory.
500 * Because each host micro (used with an Ember NCP) has its own type of
501 * persistent memory storage, the Application Framework does not include the
502 * ability to mark attributes as stored in flash the way that it does for Ember
503 * SoCs like the EM35x. On a host micro, any attributes that need to be stored
504 * in persistent memory should be marked as external and accessed through the
505 * external read and write callbacks. Any host code associated with the
506 * persistent storage should be implemented within this callback.
508 * the important information about the attribute itself is passed as a pointer
509 * to an EmberAfAttributeMetadata struct, which is stored within the application
510 * and used to manage the attribute. A complete description of the
511 * EmberAfAttributeMetadata struct is provided in
512 * app/framework/include/af-types.h.
513 This function assumes that the
514 * application is able to write the attribute and return immediately. Any
515 * attributes that require a state machine for reading and writing are not
516 * candidates for externalization at the present time. The Application Framework
517 * does not currently include a state machine for reading or writing attributes
518 * that must take place across a series of application ticks. Attributes that
519 * cannot be written immediately should be stored within the Application
520 * Framework and updated occasionally by the application code from within the
521 * emberAfMainTickCallback.
522 If the application was successfully able to
523 * write the attribute, it returns a value of EMBER_ZCL_STATUS_SUCCESS. Any
524 * other return value indicates the application was not able to write the
527 * @param endpoint Ver.: always
528 * @param clusterId Ver.: always
529 * @param attributeMetadata Ver.: always
530 * @param manufacturerCode Ver.: always
531 * @param buffer Ver.: always
533 EmberAfStatus emberAfExternalAttributeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
534 EmberAfAttributeMetadata * attributeMetadata, uint16_t manufacturerCode,
537 /** @brief Report Attributes
539 * This function is called by the application framework when a Report Attributes
540 * command is received from an external device. The application should return
541 * true if the message was processed or false if it was not.
543 * @param clusterId The cluster identifier of this command. Ver.: always
544 * @param buffer Buffer containing the list of attribute report records. Ver.:
546 * @param bufLen The length in bytes of the list. Ver.: always
548 bool emberAfReportAttributesCallback(chip::ClusterId clusterId, uint8_t * buffer, uint16_t bufLen);
550 /** @brief Get Current Time
552 * This callback is called when device attempts to get current time from the
553 * hardware. If this device has means to retrieve exact time, then this method
554 * should implement it. If the callback can't provide the exact time it should
555 * return 0 to indicate failure. Default action is to return 0, which indicates
556 * that device does not have access to real time.
559 uint32_t emberAfGetCurrentTimeCallback();
561 /** @brief Get Endpoint Info
563 * This function is a callback to an application implemented endpoint that
564 * operates outside the normal application framework. When the framework wishes
565 * to perform operations with that endpoint it uses this callback to retrieve
566 * the endpoint's information. If the endpoint exists and the application can
567 * provide data then true shall be returned. Otherwise the callback must return
570 * @param endpoint The endpoint to retrieve data for. Ver.: always
571 * @param returnNetworkIndex The index corresponding to the ZigBee network the
572 * endpoint belongs to. If not using a multi-network device, 0 must be
573 * returned. Otherwise on a multi-network device the stack will switch to this
574 * network before sending the message. Ver.: always
575 * @param returnEndpointInfo A pointer to a data struct that will be written
576 * with information about the endpoint. Ver.: always
578 bool emberAfGetEndpointInfoCallback(chip::EndpointId endpoint, uint8_t * returnNetworkIndex, EmberAfEndpointInfoStruct * returnEndpointInfo);
580 /** @brief Get Source Route Overhead
582 * This function is called by the framework to determine the overhead required
583 * in the network frame for source routing to a particular destination.
585 * @param destination The node id of the destination Ver.: always
587 uint8_t emberAfGetSourceRouteOverheadCallback(chip::NodeId destination);
589 /** @brief Registration Abort
591 * This callback is called when the device should abort the registration
595 void emberAfRegistrationAbortCallback();
597 /** @brief Interpan Send Message
599 * This function will send a raw MAC message with interpan frame format using
600 * the passed parameters.
602 * @param header Interpan header info Ver.: always
603 * @param messageLength The length of the message received or to send Ver.:
605 * @param message The message data received or to send. Ver.: always
607 EmberStatus emberAfInterpanSendMessageCallback(EmberAfInterpanHeader * header, uint16_t messageLength, uint8_t * message);
609 /** @brief Start Move
611 * This function is called to initiate the process for a device to move (rejoin)
615 bool emberAfStartMoveCallback();