UG391: Zigbee Application Framework Developer's Guide
Application Framework Callback Interface
silabs.com | Building a more connected world. Rev. 0.1 | 8
6 Application Framework Callback Interface
The Zigbee application framework callbacks are intended to be used as a means to remove all customer code from the Zigbee application
framework. If any of your application code needs to be put into the Zigbee application framework, Silicon Labs views this as a bug with
the Zigbee application framework, because it means that a callback that would satisfy your application requirement is missing. In this
case, please open a ticket through the Contact Support link at https://www.silabs.com/support.
Generally, when a callback is called the Zigbee application framework is giving the application code a first crack at some incoming
message or requesting some piece of application data. Within the callback API, some callbacks return a Boolean value indicating that
the message has been handled and no further processing should be done. If you are doing something that conflicts with the Zigbee
application framework’s handling of a particular message, return TRUE to indicate that the message was complete. This ensures that the
Zigbee application framework does not interfere with your handling of the message.
6.1 Callback Generation
AppBuilder has the ability to generate a stub callback file for you. By default, AppBuilder chooses not to generate the callback stub file if
it finds that the file already exists in the generation directory. You must specifically tell the application to overwrite an existing file.
When you regenerate files in the future, AppBuilder protects your generated callbacks file from being overwritten by asking if you want to
overwrite it. By default, AppBuilder will not overwrite any previously created callbacks file. If you choose to overwrite the file, AppBuilder
backs up the previous version to the file <appname>_callbacks.bak.
Note: You can implement your callbacks wherever you want; they do not need to be implemented in the generated callbacks file.
However, if you implement them in a different location, clear them out of the generated callback file so that your linker won’t
complain about duplicate definitions for the callback functions.
6.2 Non-Cluster-Related Callbacks
The callback interface is divided up into sections within the AppBuilder GUI for ease of use. The first section, Non-Cluster-Related
Callbacks, is made up of callbacks that are described in the callbacks.xml document located at tool/appbuilder/callbacks.xml. These
callbacks have been manually inserted into the Zigbee application framework code in locations where customers have indicated that they
wish to receive information about the function of the Zigbee application framework.
All global commands fall into this category. The Zigbee application framework contains handling code for global commands. If any global
command callback returns TRUE, this indicates that the command has been handled by the application and no further command handling
should take place. If the callback returns FALSE, then the Zigbee application framework continues to process the command normally.
Example
The pre-command received callback (emberAfPreCommandReceivedCallback(EmberAfClusterCommand* cmd,
boolean isInterpan
) is called after a ZCL command has been received but has not yet been processed by the Zigbee application
framework’s command handling code. The command is parsed into a useful struct
EmberAfClusterCommand, which provides an
easy way to access relevant data about the command including its EmberApsFrame, message type, source, buffer, length, and any
relevant flags for the command. This callback also returns a Boolean value indicating if the command has been handled. If the callback
returns TRUE, then it is assumed that the command has been handled by the application and no further action is taken.
6.3 Cluster-Specific Command Handling Callbacks
The cluster-related callbacks are generated by the Zigbee application framework to allow receipt of a pre-parsed command coming over
the air. Generally, a one-to-one relationship exists between ZCL commands and the cluster-specific callbacks.
The cluster-specific command callbacks all return a Boolean value. This return value allows you to short-circuit command handling in-
cluded in the application framework. If you implement a cluster-specific command callback and it returns a value of TRUE to the Zigbee
application framework, the framework assumes that the command has been handled outside the framework and that any required com-
mand or default response has been sent. If the cluster-specific command returns FALSE, the framework assumes that the application
code did not understand the command and sends a default response with a status of ‘unsupported cluster command’.