3 // Prevent multiple inclusion
6 #include "af-structs.h"
8 #include "basic-types.h"
10 /** @brief Cluster Init
12 * This function is called when a specific cluster is initialized. It gives the
13 * application an opportunity to take care of cluster initialization procedures.
14 * It is called exactly once for each endpoint where cluster is present.
16 * @param endpoint Ver.: always
17 * @param clusterId Ver.: always
19 void emberAfClusterInitCallback(chip::EndpointId endpoint, chip::ClusterId clusterId);
21 // Cluster Init Functions
23 {{#all_user_clusters_names}}
25 /** @brief {{name}} Cluster Init
29 * @param endpoint Endpoint that is being initialized
31 void emberAf{{asCamelCased name false}}ClusterInitCallback(chip::EndpointId endpoint);
33 {{/all_user_clusters_names}}
35 // Cluster Server/Client Init Functions
37 {{#all_user_clusters}}
40 // {{name}} Cluster {{side}}
43 /** @brief {{name}} Cluster {{asCamelCased side false}} Init
45 * {{asCamelCased side false}} Init
47 * @param endpoint Endpoint that is being initialized
49 void emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}InitCallback(chip::EndpointId endpoint);
51 /** @brief {{name}} Cluster {{asCamelCased side false}} Attribute Changed
53 * {{asCamelCased side false}} Attribute Changed
55 * @param endpoint Endpoint that is being initialized
56 * @param attributeId Attribute that changed
58 void emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}AttributeChangedCallback(chip::EndpointId endpoint, chip::AttributeId attributeId);
60 /** @brief {{name}} Cluster {{asCamelCased side false}} Manufacturer Specific Attribute Changed
62 * {{asCamelCased side false}} Manufacturer Specific Attribute Changed
64 * @param endpoint Endpoint that is being initialized
65 * @param attributeId Attribute that changed
66 * @param manufacturerCode Manufacturer Code of the attribute that changed
68 void emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}ManufacturerSpecificAttributeChangedCallback(chip::EndpointId endpoint, chip::AttributeId attributeId, uint16_t manufacturerCode);
70 /** @brief {{name}} Cluster {{asCamelCased side false}} Message Sent
72 * {{asCamelCased side false}} Message Sent
74 * @param type The type of message sent
75 * @param indexOrDestination The destination or address to which the message was sent
76 * @param apsFrame The APS frame for the message
77 * @param msgLen The length of the message
78 * @param message The message that was sent
79 * @param status The status of the sent message
81 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);
83 /** @brief {{name}} Cluster {{asCamelCased side false}} Pre Attribute Changed
85 * {{asCamelCased side}} Pre Attribute Changed
87 * @param endpoint Endpoint that is being initialized
88 * @param attributeId Attribute to be changed
89 * @param attributeType Attribute type
90 * @param size Attribute size
91 * @param value Attribute value
93 EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}PreAttributeChangedCallback(chip::EndpointId endpoint, chip::AttributeId attributeId, EmberAfAttributeType attributeType, uint8_t size, uint8_t * value);
95 /** @brief {{name}} Cluster {{asCamelCased side false}} Tick
97 * {{asCamelCased side}} Tick
99 * @param endpoint Endpoint that is being served
101 void emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}TickCallback(chip::EndpointId endpoint);
102 {{/all_user_clusters}}
104 // Cluster Commands Callback
106 {{#all_user_clusters}}
107 {{#if (isEnabled enabled)}}
108 {{#all_user_cluster_commands}}
109 {{#if (isStrEqual clusterName parent.name)}}
110 {{#if (isCommandAvailable parent.side incoming outgoing commandSource)}}
112 * @brief {{parent.name}} Cluster {{name}} Command callback
113 {{#if (zcl_command_arguments_count this.id)}}
114 {{#zcl_command_arguments}}
115 * @param {{asCamelCased label}}
116 {{/zcl_command_arguments}}
120 {{#if (zcl_command_arguments_count this.id)}}
121 bool emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback({{#zcl_command_arguments}} {{asUnderlyingType type}} {{asSymbol label}}{{#unless (isLastElement index count)}}, {{/unless}}{{/zcl_command_arguments}});
123 bool emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback();
129 {{/all_user_cluster_commands}}
131 {{/all_user_clusters}}
134 // Non-Cluster Related Callbacks
137 /** @brief Add To Current App Tasks
139 * This function is only useful to sleepy end devices. This function will note
140 * the passed item as part of a set of tasks the application has outstanding
141 * (e.g. message sent requiring APS acknwoledgement). This will affect how the
142 * application behaves with regard to sleeping and polling. Until the
143 * outstanding task is completed, the device may poll more frequently and sleep
146 * @param tasks Ver.: always
148 void emberAfAddToCurrentAppTasksCallback(EmberAfApplicationTask tasks);
150 /** @brief Remove From Current App Tasks
152 * This function is only useful to sleepy end devices. This function will
153 * remove the passed item from the set of tasks the application has outstanding
154 * (e.g. message sent requiring APS acknwoledgement). This will affect how the
155 * application behaves with regard to sleeping and polling. Removing the item
156 * from the list of outstanding tasks may allow the device to sleep longer and
157 * poll less frequently. If there are other outstanding tasks the system may
158 * still have to stay away and poll more often.
160 * @param tasks Ver.: always
162 void emberAfRemoveFromCurrentAppTasksCallback(EmberAfApplicationTask tasks);
164 /** @brief Allow Network Write Attribute
166 * This function is called by the application framework before it writes an
167 * attribute in response to a write attribute request from an external device.
168 * The value passed into this callback is the value to which the attribute is to
169 * be set by the framework.
170 Example: In mirroring simple metering data
171 * on an Energy Services Interface (ESI) (formerly called Energy Service Portal
172 * (ESP) in SE 1.0).), a mirrored simple meter needs to write read-only
173 * attributes on its mirror. The-meter-mirror sample application, located in
174 * app/framework/sample-apps, uses this callback to allow the mirrored device to
175 * write simple metering attributes on the mirror regardless of the fact that
176 * most simple metering attributes are defined as read-only by the ZigBee
178 Note: The ZCL specification does not (as of this
179 * writing) specify any permission-level security for writing writeable
180 * attributes. As far as the ZCL specification is concerned, if an attribute is
181 * writeable, any device that has a link key for the device should be able to
182 * write that attribute. Furthermore if an attribute is read only, it should not
183 * be written over the air. Thus, if you implement permissions for writing
184 * attributes as a feature, you MAY be operating outside the specification. This
185 * is unlikely to be a problem for writing read-only attributes, but it may be a
186 * problem for attributes that are writeable according to the specification but
187 * restricted by the application implementing this callback.
189 * @param endpoint Ver.: always
190 * @param clusterId Ver.: always
191 * @param attributeId Ver.: always
192 * @param mask Ver.: always
193 * @param manufacturerCode Ver.: always
194 * @param value Ver.: always
195 * @param type Ver.: always
197 EmberAfAttributeWritePermission emberAfAllowNetworkWriteAttributeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
198 chip::AttributeId attributeId, uint8_t mask,
199 uint16_t manufacturerCode, uint8_t * value, uint8_t type);
201 /** @brief Attribute Read Access
203 * This function is called whenever the Application Framework needs to check
204 * access permission for an attribute read.
206 * @param endpoint Ver.: always
207 * @param clusterId Ver.: always
208 * @param manufacturerCode Ver.: always
209 * @param attributeId Ver.: always
211 bool emberAfAttributeReadAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, uint16_t manufacturerCode,
212 chip::AttributeId attributeId);
214 /** @brief Attribute Write Access
216 * This function is called whenever the Application Framework needs to check
217 * access permission for an attribute write.
219 * @param endpoint Ver.: always
220 * @param clusterId Ver.: always
221 * @param manufacturerCode Ver.: always
222 * @param attributeId Ver.: always
224 bool emberAfAttributeWriteAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, uint16_t manufacturerCode,
225 chip::AttributeId attributeId);
227 /** @brief Default Response
229 * This function is called by the application framework when a Default Response
230 * command is received from an external device. The application should return
231 * true if the message was processed or false if it was not.
233 * @param clusterId The cluster identifier of this response. Ver.: always
234 * @param commandId The command identifier to which this is a response. Ver.:
236 * @param status Specifies either SUCCESS or the nature of the error that was
237 * detected in the received command. Ver.: always
239 bool emberAfDefaultResponseCallback(chip::ClusterId clusterId, chip::CommandId commandId, EmberAfStatus status);
241 /** @brief Discover Attributes Response
243 * This function is called by the application framework when a Discover
244 * Attributes Response or Discover Attributes Extended Response command is
245 * received from an external device. The Discover Attributes Response command
246 * contains a bool indicating if discovery is complete and a list of zero or
247 * more attribute identifier/type records. The final argument indicates whether
248 * the response is in the extended format or not. The application should return
249 * true if the message was processed or false if it was not.
251 * @param clusterId The cluster identifier of this response. Ver.: always
252 * @param discoveryComplete Indicates whether there are more attributes to be
253 * discovered. true if there are no more attributes to be discovered. Ver.:
255 * @param buffer Buffer containing the list of attribute identifier/type
256 * records. Ver.: always
257 * @param bufLen The length in bytes of the list. Ver.: always
258 * @param extended Indicates whether the response is in the extended format or
261 bool emberAfDiscoverAttributesResponseCallback(chip::ClusterId clusterId, bool discoveryComplete, uint8_t * buffer,
262 uint16_t bufLen, bool extended);
264 /** @brief Discover Commands Generated Response
266 * This function is called by the framework when Discover Commands Generated
267 * Response is received.
269 * @param clusterId The cluster identifier of this response. Ver.: always
270 * @param manufacturerCode Manufacturer code Ver.: always
271 * @param discoveryComplete Indicates whether there are more commands to be
272 * discovered. Ver.: always
273 * @param commandIds Buffer containing the list of command identifiers. Ver.:
275 * @param commandIdCount The length of bytes of the list, whish is the same as
276 * the number of identifiers. Ver.: always
278 bool emberAfDiscoverCommandsGeneratedResponseCallback(chip::ClusterId clusterId, uint16_t manufacturerCode, bool discoveryComplete,
279 chip::CommandId * commandIds, uint16_t commandIdCount);
282 /** @brief Discover Commands Received Response
284 * This function is called by the framework when Discover Commands Received
285 * Response is received.
287 * @param clusterId The cluster identifier of this response. Ver.: always
288 * @param manufacturerCode Manufacturer code Ver.: always
289 * @param discoveryComplete Indicates whether there are more commands to be
290 * discovered. Ver.: always
291 * @param commandIds Buffer containing the list of command identifiers. Ver.:
293 * @param commandIdCount The length of bytes of the list, whish is the same as
294 * the number of identifiers. Ver.: always
296 bool emberAfDiscoverCommandsReceivedResponseCallback(chip::ClusterId clusterId, uint16_t manufacturerCode, bool discoveryComplete,
297 chip::CommandId * commandIds, uint16_t commandIdCount);
300 /** @brief Pre Command Received
302 * This callback is the second in the Application Framework's message processing
303 * chain. At this point in the processing of incoming over-the-air messages, the
304 * application has determined that the incoming message is a ZCL command. It
305 * parses enough of the message to populate an EmberAfClusterCommand struct. The
306 * Application Framework defines this struct value in a local scope to the
307 * command processing but also makes it available through a global pointer
308 * called emberAfCurrentCommand, in app/framework/util/util.c. When command
309 * processing is complete, this pointer is cleared.
311 * @param cmd Ver.: always
313 bool emberAfPreCommandReceivedCallback(EmberAfClusterCommand * cmd);
315 /** @brief Pre Message Send
317 * This function is called by the framework when it is about to pass a message
318 * to the stack primitives for sending. This message may or may not be ZCL,
319 * ZDO, or some other protocol. This is called prior to
321 * fragmentation that may be done. If the function returns true it is assumed
322 * the callback has consumed and processed the message. The callback must also
323 * set the EmberStatus status code to be passed back to the caller. The
324 * framework will do no further processing on the message.
326 * function returns false then it is assumed that the callback has not processed
327 * the mesasge and the framework will continue to process accordingly.
329 * @param messageStruct The structure containing the parameters of the APS
330 * message to be sent. Ver.: always
331 * @param status A pointer to the status code value that will be returned to the
332 * caller. Ver.: always
334 bool emberAfPreMessageSendCallback(EmberAfMessageStruct * messageStruct, EmberStatus * status);
336 /** @brief Message Sent
338 * This function is called by the application framework from the message sent
339 * handler, when it is informed by the stack regarding the message sent status.
340 * All of the values passed to the emberMessageSentHandler are passed on to this
341 * callback. This provides an opportunity for the application to verify that its
342 * message has been sent successfully and take the appropriate action. This
343 * callback should return a bool value of true or false. A value of true
344 * indicates that the message sent notification has been handled and should not
345 * be handled by the application framework.
347 * @param type Ver.: always
348 * @param indexOrDestination Ver.: always
349 * @param apsFrame Ver.: always
350 * @param msgLen Ver.: always
351 * @param message Ver.: always
352 * @param status Ver.: always
354 bool emberAfMessageSentCallback(EmberOutgoingMessageType type, uint16_t indexOrDestination, EmberApsFrame * apsFrame,
355 uint16_t msgLen, uint8_t * message, EmberStatus status);
357 /** @brief Pre Attribute Change
359 * This function is called by the application framework before it changes an
360 * attribute value. The value passed into this callback is the value to which
361 * the attribute is to be set by the framework. The application should return
362 * ::EMBER_ZCL_STATUS_SUCCESS to permit the change or any other ::EmberAfStatus
365 * @param endpoint Ver.: always
366 * @param clusterId Ver.: always
367 * @param attributeId Ver.: always
368 * @param mask Ver.: always
369 * @param manufacturerCode Ver.: always
370 * @param type Ver.: always
371 * @param size Ver.: always
372 * @param value Ver.: always
374 EmberAfStatus emberAfPreAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId,
375 uint8_t mask, uint16_t manufacturerCode, uint8_t type, uint8_t size,
378 /** @brief Post Attribute Change
380 * This function is called by the application framework after it changes an
381 * attribute value. The value passed into this callback is the value to which
382 * the attribute was set by the framework.
384 * @param endpoint Ver.: always
385 * @param clusterId Ver.: always
386 * @param attributeId Ver.: always
387 * @param mask Ver.: always
388 * @param manufacturerCode Ver.: always
389 * @param type Ver.: always
390 * @param size Ver.: always
391 * @param value Ver.: always
393 void emberAfPostAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t mask,
394 uint16_t manufacturerCode, uint8_t type, uint8_t size, uint8_t * value);
396 /** @brief Read Attributes Response
398 * This function is called by the application framework when a Read Attributes
399 * Response command is received from an external device. The application should
400 * return true if the message was processed or false if it was not.
402 * @param clusterId The cluster identifier of this response. Ver.: always
403 * @param buffer Buffer containing the list of read attribute status records.
405 * @param bufLen The length in bytes of the list. Ver.: always
407 bool emberAfReadAttributesResponseCallback(chip::ClusterId clusterId, uint8_t * buffer, uint16_t bufLen);
409 /** @brief External Attribute Read
411 * Like emberAfExternalAttributeWriteCallback above, this function is called
412 * when the framework needs to read an attribute that is not stored within the
413 * Application Framework's data structures.
415 * information about the attribute itself is passed as a pointer to an
416 * EmberAfAttributeMetadata struct, which is stored within the application and
417 * used to manage the attribute. A complete description of the
418 * EmberAfAttributeMetadata struct is provided in
419 * app/framework/include/af-types.h
420 This function assumes that the
421 * application is able to read the attribute, write it into the passed buffer,
422 * and return immediately. Any attributes that require a state machine for
423 * reading and writing are not really candidates for externalization at the
424 * present time. The Application Framework does not currently include a state
425 * machine for reading or writing attributes that must take place across a
426 * series of application ticks. Attributes that cannot be read in a timely
427 * manner should be stored within the Application Framework and updated
428 * occasionally by the application code from within the
429 * emberAfMainTickCallback.
430 If the application was successfully able to
431 * read the attribute and write it into the passed buffer, it should return a
432 * value of EMBER_ZCL_STATUS_SUCCESS. Ensure that the size of the externally
433 * managed attribute value is smaller than what the buffer can hold. In the case
434 * of a buffer overflow throw an appropriate error such as
435 * EMBER_ZCL_STATUS_INSUFFICIENT_SPACE. Any other return value indicates the
436 * application was not able to read the attribute.
438 * @param endpoint Ver.: always
439 * @param clusterId Ver.: always
440 * @param attributeMetadata Ver.: always
441 * @param manufacturerCode Ver.: always
442 * @param buffer Ver.: always
443 * @param maxReadLength Ver.: always
445 EmberAfStatus emberAfExternalAttributeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
446 EmberAfAttributeMetadata * attributeMetadata, uint16_t manufacturerCode,
447 uint8_t * buffer, uint16_t maxReadLength);
449 /** @brief Write Attributes Response
451 * This function is called by the application framework when a Write Attributes
452 * Response command is received from an external device. The application should
453 * return true if the message was processed or false if it was not.
455 * @param clusterId The cluster identifier of this response. Ver.: always
456 * @param buffer Buffer containing the list of write attribute status records.
458 * @param bufLen The length in bytes of the list. Ver.: always
460 bool emberAfWriteAttributesResponseCallback(chip::ClusterId clusterId, uint8_t * buffer, uint16_t bufLen);
462 /** @brief External Attribute Write
464 * This function is called whenever the Application Framework needs to write an
465 * attribute which is not stored within the data structures of the Application
466 * Framework itself. One of the new features in Version 2 is the ability to
467 * store attributes outside the Framework. This is particularly useful for
468 * attributes that do not need to be stored because they can be read off the
469 * hardware when they are needed, or are stored in some central location used by
470 * many modules within the system. In this case, you can indicate that the
471 * attribute is stored externally. When the framework needs to write an external
472 * attribute, it makes a call to this callback.
473 This callback is very
474 * useful for host micros which need to store attributes in persistent memory.
475 * Because each host micro (used with an Ember NCP) has its own type of
476 * persistent memory storage, the Application Framework does not include the
477 * ability to mark attributes as stored in flash the way that it does for Ember
478 * SoCs like the EM35x. On a host micro, any attributes that need to be stored
479 * in persistent memory should be marked as external and accessed through the
480 * external read and write callbacks. Any host code associated with the
481 * persistent storage should be implemented within this callback.
483 * the important information about the attribute itself is passed as a pointer
484 * to an EmberAfAttributeMetadata struct, which is stored within the application
485 * and used to manage the attribute. A complete description of the
486 * EmberAfAttributeMetadata struct is provided in
487 * app/framework/include/af-types.h.
488 This function assumes that the
489 * application is able to write the attribute and return immediately. Any
490 * attributes that require a state machine for reading and writing are not
491 * candidates for externalization at the present time. The Application Framework
492 * does not currently include a state machine for reading or writing attributes
493 * that must take place across a series of application ticks. Attributes that
494 * cannot be written immediately should be stored within the Application
495 * Framework and updated occasionally by the application code from within the
496 * emberAfMainTickCallback.
497 If the application was successfully able to
498 * write the attribute, it returns a value of EMBER_ZCL_STATUS_SUCCESS. Any
499 * other return value indicates the application was not able to write the
502 * @param endpoint Ver.: always
503 * @param clusterId Ver.: always
504 * @param attributeMetadata Ver.: always
505 * @param manufacturerCode Ver.: always
506 * @param buffer Ver.: always
508 EmberAfStatus emberAfExternalAttributeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
509 EmberAfAttributeMetadata * attributeMetadata, uint16_t manufacturerCode,
512 /** @brief Report Attributes
514 * This function is called by the application framework when a Report Attributes
515 * command is received from an external device. The application should return
516 * true if the message was processed or false if it was not.
518 * @param clusterId The cluster identifier of this command. Ver.: always
519 * @param buffer Buffer containing the list of attribute report records. Ver.:
521 * @param bufLen The length in bytes of the list. Ver.: always
523 bool emberAfReportAttributesCallback(chip::ClusterId clusterId, uint8_t * buffer, uint16_t bufLen);
525 /** @brief Get Current Time
527 * This callback is called when device attempts to get current time from the
528 * hardware. If this device has means to retrieve exact time, then this method
529 * should implement it. If the callback can't provide the exact time it should
530 * return 0 to indicate failure. Default action is to return 0, which indicates
531 * that device does not have access to real time.
534 uint32_t emberAfGetCurrentTimeCallback();
536 /** @brief Get Endpoint Info
538 * This function is a callback to an application implemented endpoint that
539 * operates outside the normal application framework. When the framework wishes
540 * to perform operations with that endpoint it uses this callback to retrieve
541 * the endpoint's information. If the endpoint exists and the application can
542 * provide data then true shall be returned. Otherwise the callback must return
545 * @param endpoint The endpoint to retrieve data for. Ver.: always
546 * @param returnNetworkIndex The index corresponding to the ZigBee network the
547 * endpoint belongs to. If not using a multi-network device, 0 must be
548 * returned. Otherwise on a multi-network device the stack will switch to this
549 * network before sending the message. Ver.: always
550 * @param returnEndpointInfo A pointer to a data struct that will be written
551 * with information about the endpoint. Ver.: always
553 bool emberAfGetEndpointInfoCallback(chip::EndpointId endpoint, uint8_t * returnNetworkIndex, EmberAfEndpointInfoStruct * returnEndpointInfo);
555 /** @brief Get Source Route Overhead
557 * This function is called by the framework to determine the overhead required
558 * in the network frame for source routing to a particular destination.
560 * @param destination The node id of the destination Ver.: always
562 uint8_t emberAfGetSourceRouteOverheadCallback(EmberNodeId destination);
564 /** @brief Registration Abort
566 * This callback is called when the device should abort the registration
570 void emberAfRegistrationAbortCallback();
572 /** @brief Interpan Send Message
574 * This function will send a raw MAC message with interpan frame format using
575 * the passed parameters.
577 * @param header Interpan header info Ver.: always
578 * @param messageLength The length of the message received or to send Ver.:
580 * @param message The message data received or to send. Ver.: always
582 EmberStatus emberAfInterpanSendMessageCallback(EmberAfInterpanHeader * header, uint16_t messageLength, uint8_t * message);
584 /** @brief Start Move
586 * This function is called to initiate the process for a device to move (rejoin)
590 bool emberAfStartMoveCallback();