Change script for apply upstream code
[platform/upstream/connectedhomeip.git] / src / app / zap-templates / callback-stub-src.zapt
1 {{chip_header}}
2
3 #include "callback.h"
4 #include "cluster-id.h"
5
6 using namespace chip;
7
8 // Cluster Init Functions
9 void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId)
10 {
11     switch (clusterId)
12     {
13     {{#all_user_clusters_names}}
14      case ZCL_{{asDelimitedMacro define}}_ID :
15         emberAf{{asCamelCased name false}}ClusterInitCallback(endpoint);
16         break;
17     {{/all_user_clusters_names}}
18     default:
19         // Unrecognized cluster ID
20         break;
21     }
22 }
23
24 {{#all_user_clusters_names}}
25 void __attribute__((weak)) emberAf{{asCamelCased name false}}ClusterInitCallback(EndpointId endpoint)
26 {
27     // To prevent warning
28     (void) endpoint;
29 }
30 {{/all_user_clusters_names}}
31
32 //
33 // Non-Cluster Related Callbacks
34 //
35
36 /** @brief Add To Current App Tasks
37  *
38  * This function is only useful to sleepy end devices.  This function will note
39  * the passed item as part of a set of tasks the application has outstanding
40  * (e.g. message sent requiring APS acknwoledgement).  This will affect how the
41  * application behaves with regard to sleeping and polling.  Until the
42  * outstanding task is completed, the device may poll more frequently and sleep
43  * less often.
44  *
45  * @param tasks   Ver.: always
46  */
47 void emberAfAddToCurrentAppTasksCallback(EmberAfApplicationTask tasks) {}
48
49 /** @brief Remove From Current App Tasks
50  *
51  * This function is only useful to sleepy end devices.  This function will
52  * remove the passed item from the set of tasks the application has outstanding
53  * (e.g. message sent requiring APS acknwoledgement).  This will affect how the
54  * application behaves with regard to sleeping and polling.  Removing the item
55  * from the list of outstanding tasks may allow the device to sleep longer and
56  * poll less frequently.  If there are other outstanding tasks the system may
57  * still have to stay away and poll more often.
58  *
59  * @param tasks   Ver.: always
60  */
61 void emberAfRemoveFromCurrentAppTasksCallback(EmberAfApplicationTask tasks) {}
62
63 /** @brief Allow Network Write Attribute
64  *
65  * This function is called by the application framework before it writes an
66  * attribute in response to a write attribute request from an external device.
67  * The value passed into this callback is the value to which the attribute is to
68  * be set by the framework.
69         Example:        In mirroring simple metering data
70  * on an Energy Services Interface (ESI) (formerly called Energy Service Portal
71  * (ESP) in SE 1.0).), a mirrored simple meter needs to write read-only
72  * attributes on its mirror. The-meter-mirror sample application, located in
73  * app/framework/sample-apps, uses this callback to allow the mirrored device to
74  * write simple metering attributes on the mirror regardless of the fact that
75  * most simple metering attributes are defined as read-only by the ZigBee
76  * specification.
77         Note:   The ZCL specification does not (as of this
78  * writing) specify any permission-level security for writing writeable
79  * attributes. As far as the ZCL specification is concerned, if an attribute is
80  * writeable, any device that has a link key for the device should be able to
81  * write that attribute. Furthermore if an attribute is read only, it should not
82  * be written over the air. Thus, if you implement permissions for writing
83  * attributes as a feature, you MAY be operating outside the specification. This
84  * is unlikely to be a problem for writing read-only attributes, but it may be a
85  * problem for attributes that are writeable according to the specification but
86  * restricted by the application implementing this callback.
87  *
88  * @param endpoint   Ver.: always
89  * @param clusterId   Ver.: always
90  * @param attributeId   Ver.: always
91  * @param mask   Ver.: always
92  * @param manufacturerCode   Ver.: always
93  * @param value   Ver.: always
94  * @param type   Ver.: always
95  */
96 EmberAfAttributeWritePermission emberAfAllowNetworkWriteAttributeCallback(EndpointId endpoint, ClusterId clusterId,
97                                                                           AttributeId attributeId, uint8_t mask,
98                                                                           uint16_t manufacturerCode, uint8_t * value, uint8_t type)
99 {
100     return EMBER_ZCL_ATTRIBUTE_WRITE_PERMISSION_ALLOW_WRITE_NORMAL; // Default
101 }
102
103 /** @brief Attribute Read Access
104  *
105  * This function is called whenever the Application Framework needs to check
106  * access permission for an attribute read.
107  *
108  * @param endpoint   Ver.: always
109  * @param clusterId   Ver.: always
110  * @param manufacturerCode   Ver.: always
111  * @param attributeId   Ver.: always
112  */
113 bool emberAfAttributeReadAccessCallback(EndpointId endpoint, ClusterId clusterId, uint16_t manufacturerCode,
114                                         AttributeId attributeId)
115 {
116     return true;
117 }
118
119 /** @brief Attribute Write Access
120  *
121  * This function is called whenever the Application Framework needs to check
122  * access permission for an attribute write.
123  *
124  * @param endpoint   Ver.: always
125  * @param clusterId   Ver.: always
126  * @param manufacturerCode   Ver.: always
127  * @param attributeId   Ver.: always
128  */
129 bool emberAfAttributeWriteAccessCallback(EndpointId endpoint, ClusterId clusterId, uint16_t manufacturerCode,
130                                          AttributeId attributeId)
131 {
132     return true;
133 }
134
135 /** @brief Default Response
136  *
137  * This function is called by the application framework when a Default Response
138  * command is received from an external device.  The application should return
139  * true if the message was processed or false if it was not.
140  *
141  * @param clusterId The cluster identifier of this response.  Ver.: always
142  * @param commandId The command identifier to which this is a response.  Ver.:
143  * always
144  * @param status Specifies either SUCCESS or the nature of the error that was
145  * detected in the received command.  Ver.: always
146  */
147 bool emberAfDefaultResponseCallback(ClusterId clusterId, CommandId commandId, EmberAfStatus status)
148 {
149     return false;
150 }
151
152 /** @brief Discover Attributes Response
153  *
154  * This function is called by the application framework when a Discover
155  * Attributes Response or Discover Attributes Extended Response command is
156  * received from an external device.  The Discover Attributes Response command
157  * contains a bool indicating if discovery is complete and a list of zero or
158  * more attribute identifier/type records. The final argument indicates whether
159  * the response is in the extended format or not.  The application should return
160  * true if the message was processed or false if it was not.
161  *
162  * @param clusterId The cluster identifier of this response.  Ver.: always
163  * @param discoveryComplete Indicates whether there are more attributes to be
164  * discovered.  true if there are no more attributes to be discovered.  Ver.:
165  * always
166  * @param buffer Buffer containing the list of attribute identifier/type
167  * records.  Ver.: always
168  * @param bufLen The length in bytes of the list.  Ver.: always
169  * @param extended Indicates whether the response is in the extended format or
170  * not.  Ver.: always
171  */
172 bool emberAfDiscoverAttributesResponseCallback(ClusterId clusterId, bool discoveryComplete, uint8_t * buffer,
173                                                uint16_t bufLen, bool extended)
174 {
175     return false;
176 }
177
178 /** @brief Discover Commands Generated Response
179  *
180  * This function is called by the framework when Discover Commands Generated
181  * Response is received.
182  *
183  * @param clusterId The cluster identifier of this response.  Ver.: always
184  * @param manufacturerCode Manufacturer code  Ver.: always
185  * @param discoveryComplete Indicates whether there are more commands to be
186  * discovered.  Ver.: always
187  * @param commandIds Buffer containing the list of command identifiers.  Ver.:
188  * always
189  * @param commandIdCount The length of bytes of the list, whish is the same as
190  * the number of identifiers.  Ver.: always
191  */
192 bool emberAfDiscoverCommandsGeneratedResponseCallback(ClusterId clusterId, uint16_t manufacturerCode, bool discoveryComplete,
193                                                       CommandId * commandIds, uint16_t commandIdCount)
194 {
195     return false;
196 }
197
198 /** @brief Discover Commands Received Response
199  *
200  * This function is called by the framework when Discover Commands Received
201  * Response is received.
202  *
203  * @param clusterId The cluster identifier of this response.  Ver.: always
204  * @param manufacturerCode Manufacturer code  Ver.: always
205  * @param discoveryComplete Indicates whether there are more commands to be
206  * discovered.  Ver.: always
207  * @param commandIds Buffer containing the list of command identifiers.  Ver.:
208  * always
209  * @param commandIdCount The length of bytes of the list, whish is the same as
210  * the number of identifiers.  Ver.: always
211  */
212 bool emberAfDiscoverCommandsReceivedResponseCallback(ClusterId clusterId, uint16_t manufacturerCode, bool discoveryComplete,
213                                                      CommandId * commandIds, uint16_t commandIdCount)
214 {
215     return false;
216 }
217
218 /** @brief Pre Command Received
219  *
220  * This callback is the second in the Application Framework's message processing
221  * chain. At this point in the processing of incoming over-the-air messages, the
222  * application has determined that the incoming message is a ZCL command. It
223  * parses enough of the message to populate an EmberAfClusterCommand struct. The
224  * Application Framework defines this struct value in a local scope to the
225  * command processing but also makes it available through a global pointer
226  * called emberAfCurrentCommand, in app/framework/util/util.c. When command
227  * processing is complete, this pointer is cleared.
228  *
229  * @param cmd   Ver.: always
230  */
231 bool emberAfPreCommandReceivedCallback(EmberAfClusterCommand * cmd)
232 {
233     return false;
234 }
235
236 /** @brief Pre Message Send
237  *
238  * This function is called by the framework when it is about to pass a message
239  * to the stack primitives for sending.   This message may or may not be ZCL,
240  * ZDO, or some other protocol.  This is called prior to
241         any ZigBee
242  * fragmentation that may be done.  If the function returns true it is assumed
243  * the callback has consumed and processed the message.  The callback must also
244  * set the EmberStatus status code to be passed back to the caller.  The
245  * framework will do no further processing on the message.
246         If the
247  * function returns false then it is assumed that the callback has not processed
248  * the mesasge and the framework will continue to process accordingly.
249  *
250  * @param messageStruct The structure containing the parameters of the APS
251  * message to be sent.  Ver.: always
252  * @param status A pointer to the status code value that will be returned to the
253  * caller.  Ver.: always
254  */
255 bool emberAfPreMessageSendCallback(EmberAfMessageStruct * messageStruct, EmberStatus * status)
256 {
257     return false;
258 }
259
260 /** @brief Message Sent
261  *
262  * This function is called by the application framework from the message sent
263  * handler, when it is informed by the stack regarding the message sent status.
264  * All of the values passed to the emberMessageSentHandler are passed on to this
265  * callback. This provides an opportunity for the application to verify that its
266  * message has been sent successfully and take the appropriate action. This
267  * callback should return a bool value of true or false. A value of true
268  * indicates that the message sent notification has been handled and should not
269  * be handled by the application framework.
270  *
271  * @param type   Ver.: always
272  * @param indexOrDestination   Ver.: always
273  * @param apsFrame   Ver.: always
274  * @param msgLen   Ver.: always
275  * @param message   Ver.: always
276  * @param status   Ver.: always
277  */
278 bool emberAfMessageSentCallback(EmberOutgoingMessageType type, uint16_t indexOrDestination, EmberApsFrame * apsFrame,
279                                 uint16_t msgLen, uint8_t * message, EmberStatus status)
280 {
281     return false;
282 }
283
284 /** @brief Pre Attribute Change
285  *
286  * This function is called by the application framework before it changes an
287  * attribute value.  The value passed into this callback is the value to which
288  * the attribute is to be set by the framework.  The application should return
289  * ::EMBER_ZCL_STATUS_SUCCESS to permit the change or any other ::EmberAfStatus
290  * to reject it.
291  *
292  * @param endpoint   Ver.: always
293  * @param clusterId   Ver.: always
294  * @param attributeId   Ver.: always
295  * @param mask   Ver.: always
296  * @param manufacturerCode   Ver.: always
297  * @param type   Ver.: always
298  * @param size   Ver.: always
299  * @param value   Ver.: always
300  */
301 EmberAfStatus emberAfPreAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId,
302                                                 uint8_t mask, uint16_t manufacturerCode, uint8_t type, uint8_t size,
303                                                 uint8_t * value)
304 {
305     return EMBER_ZCL_STATUS_SUCCESS;
306 }
307
308 /** @brief Post Attribute Change
309  *
310  * This function is called by the application framework after it changes an
311  * attribute value. The value passed into this callback is the value to which
312  * the attribute was set by the framework.
313  *
314  * @param endpoint   Ver.: always
315  * @param clusterId   Ver.: always
316  * @param attributeId   Ver.: always
317  * @param mask   Ver.: always
318  * @param manufacturerCode   Ver.: always
319  * @param type   Ver.: always
320  * @param size   Ver.: always
321  * @param value   Ver.: always
322  */
323 void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
324                                         uint16_t manufacturerCode, uint8_t type, uint8_t size, uint8_t * value) {}
325
326 /** @brief Read Attributes Response
327  *
328  * This function is called by the application framework when a Read Attributes
329  * Response command is received from an external device.  The application should
330  * return true if the message was processed or false if it was not.
331  *
332  * @param clusterId The cluster identifier of this response.  Ver.: always
333  * @param buffer Buffer containing the list of read attribute status records.
334  * Ver.: always
335  * @param bufLen The length in bytes of the list.  Ver.: always
336  */
337 bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * buffer, uint16_t bufLen)
338 {
339     return false;
340 }
341
342 /** @brief External Attribute Read
343  *
344  * Like emberAfExternalAttributeWriteCallback above, this function is called
345  * when the framework needs to read an attribute that is not stored within the
346  * Application Framework's data structures.
347         All of the important
348  * information about the attribute itself is passed as a pointer to an
349  * EmberAfAttributeMetadata struct, which is stored within the application and
350  * used to manage the attribute. A complete description of the
351  * EmberAfAttributeMetadata struct is provided in
352  * app/framework/include/af-types.h
353         This function assumes that the
354  * application is able to read the attribute, write it into the passed buffer,
355  * and return immediately. Any attributes that require a state machine for
356  * reading and writing are not really candidates for externalization at the
357  * present time. The Application Framework does not currently include a state
358  * machine for reading or writing attributes that must take place across a
359  * series of application ticks. Attributes that cannot be read in a timely
360  * manner should be stored within the Application Framework and updated
361  * occasionally by the application code from within the
362  * emberAfMainTickCallback.
363         If the application was successfully able to
364  * read the attribute and write it into the passed buffer, it should return a
365  * value of EMBER_ZCL_STATUS_SUCCESS. Ensure that the size of the externally
366  * managed attribute value is smaller than what the buffer can hold. In the case
367  * of a buffer overflow throw an appropriate error such as
368  * EMBER_ZCL_STATUS_INSUFFICIENT_SPACE. Any other return value indicates the
369  * application was not able to read the attribute.
370  *
371  * @param endpoint   Ver.: always
372  * @param clusterId   Ver.: always
373  * @param attributeMetadata   Ver.: always
374  * @param manufacturerCode   Ver.: always
375  * @param buffer   Ver.: always
376  * @param maxReadLength   Ver.: always
377  */
378 EmberAfStatus emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterId clusterId,
379                                                    EmberAfAttributeMetadata * attributeMetadata, uint16_t manufacturerCode,
380                                                    uint8_t * buffer, uint16_t maxReadLength)
381 {
382     return EMBER_ZCL_STATUS_FAILURE;
383 }
384
385 /** @brief Write Attributes Response
386  *
387  * This function is called by the application framework when a Write Attributes
388  * Response command is received from an external device.  The application should
389  * return true if the message was processed or false if it was not.
390  *
391  * @param clusterId The cluster identifier of this response.  Ver.: always
392  * @param buffer Buffer containing the list of write attribute status records.
393  * Ver.: always
394  * @param bufLen The length in bytes of the list.  Ver.: always
395  */
396 bool emberAfWriteAttributesResponseCallback(ClusterId clusterId, uint8_t * buffer, uint16_t bufLen)
397 {
398     return false;
399 }
400
401 /** @brief External Attribute Write
402  *
403  * This function is called whenever the Application Framework needs to write an
404  * attribute which is not stored within the data structures of the Application
405  * Framework itself. One of the new features in Version 2 is the ability to
406  * store attributes outside the Framework. This is particularly useful for
407  * attributes that do not need to be stored because they can be read off the
408  * hardware when they are needed, or are stored in some central location used by
409  * many modules within the system. In this case, you can indicate that the
410  * attribute is stored externally. When the framework needs to write an external
411  * attribute, it makes a call to this callback.
412         This callback is very
413  * useful for host micros which need to store attributes in persistent memory.
414  * Because each host micro (used with an Ember NCP) has its own type of
415  * persistent memory storage, the Application Framework does not include the
416  * ability to mark attributes as stored in flash the way that it does for Ember
417  * SoCs like the EM35x. On a host micro, any attributes that need to be stored
418  * in persistent memory should be marked as external and accessed through the
419  * external read and write callbacks. Any host code associated with the
420  * persistent storage should be implemented within this callback.
421         All of
422  * the important information about the attribute itself is passed as a pointer
423  * to an EmberAfAttributeMetadata struct, which is stored within the application
424  * and used to manage the attribute. A complete description of the
425  * EmberAfAttributeMetadata struct is provided in
426  * app/framework/include/af-types.h.
427         This function assumes that the
428  * application is able to write the attribute and return immediately. Any
429  * attributes that require a state machine for reading and writing are not
430  * candidates for externalization at the present time. The Application Framework
431  * does not currently include a state machine for reading or writing attributes
432  * that must take place across a series of application ticks. Attributes that
433  * cannot be written immediately should be stored within the Application
434  * Framework and updated occasionally by the application code from within the
435  * emberAfMainTickCallback.
436         If the application was successfully able to
437  * write the attribute, it returns a value of EMBER_ZCL_STATUS_SUCCESS. Any
438  * other return value indicates the application was not able to write the
439  * attribute.
440  *
441  * @param endpoint   Ver.: always
442  * @param clusterId   Ver.: always
443  * @param attributeMetadata   Ver.: always
444  * @param manufacturerCode   Ver.: always
445  * @param buffer   Ver.: always
446  */
447 EmberAfStatus emberAfExternalAttributeWriteCallback(EndpointId endpoint, ClusterId clusterId,
448                                                     EmberAfAttributeMetadata * attributeMetadata, uint16_t manufacturerCode,
449                                                     uint8_t * buffer)
450 {
451     return EMBER_ZCL_STATUS_FAILURE;
452 }
453
454 /** @brief Report Attributes
455  *
456  * This function is called by the application framework when a Report Attributes
457  * command is received from an external device.  The application should return
458  * true if the message was processed or false if it was not.
459  *
460  * @param clusterId The cluster identifier of this command.  Ver.: always
461  * @param buffer Buffer containing the list of attribute report records.  Ver.:
462  * always
463  * @param bufLen The length in bytes of the list.  Ver.: always
464  */
465 bool emberAfReportAttributesCallback(ClusterId clusterId, uint8_t * buffer, uint16_t bufLen)
466 {
467     return false;
468 }
469
470 /** @brief Get Current Time
471  *
472  * This callback is called when device attempts to get current time from the
473  * hardware. If this device has means to retrieve exact time, then this method
474  * should implement it. If the callback can't provide the exact time it should
475  * return 0 to indicate failure. Default action is to return 0, which indicates
476  * that device does not have access to real time.
477  *
478  */
479 uint32_t emberAfGetCurrentTimeCallback()
480 {
481     return 0;
482 }
483
484 /** @brief Get Endpoint Info
485  *
486  * This function is a callback to an application implemented endpoint that
487  * operates outside the normal application framework.  When the framework wishes
488  * to perform operations with that endpoint it uses this callback to retrieve
489  * the endpoint's information.  If the endpoint exists and the application can
490  * provide data then true shall be returned.  Otherwise the callback must return
491  * false.
492  *
493  * @param endpoint The endpoint to retrieve data for.  Ver.: always
494  * @param returnNetworkIndex The index corresponding to the ZigBee network the
495  * endpoint belongs to.  If not using a multi-network device, 0 must be
496  * returned.  Otherwise on a multi-network device the stack will switch to this
497  * network before sending the message.  Ver.: always
498  * @param returnEndpointInfo A pointer to a data struct that will be written
499  * with information about the endpoint.  Ver.: always
500  */
501 bool emberAfGetEndpointInfoCallback(EndpointId endpoint, uint8_t * returnNetworkIndex, EmberAfEndpointInfoStruct * returnEndpointInfo)
502 {
503     return false;
504 }
505
506 /** @brief Get Source Route Overhead
507  *
508  * This function is called by the framework to determine the overhead required
509  * in the network frame for source routing to a particular destination.
510  *
511  * @param destination The node id of the destination  Ver.: always
512  */
513 uint8_t emberAfGetSourceRouteOverheadCallback(EmberNodeId destination)
514 {
515     return 0;
516 }
517
518 /** @brief Registration Abort
519  *
520  * This callback is called when the device should abort the registration
521  * process.
522  *
523  */
524 void emberAfRegistrationAbortCallback() {}
525
526 /** @brief Interpan Send Message
527  *
528  * This function will send a raw MAC message with interpan frame format using
529  * the passed parameters.
530  *
531  * @param header Interpan header info  Ver.: always
532  * @param messageLength The length of the message received or to send  Ver.:
533  * always
534  * @param message The message data received or to send.  Ver.: always
535  */
536 EmberStatus emberAfInterpanSendMessageCallback(EmberAfInterpanHeader * header, uint16_t messageLength, uint8_t * message)
537 {
538     return EMBER_LIBRARY_NOT_PRESENT;
539 }
540
541 /** @brief Start Move
542  *
543  * This function is called to initiate the process for a device to move (rejoin)
544  * to a new parent.
545  *
546  */
547 bool emberAfStartMoveCallback()
548 {
549     return false;
550 }