Forming and Joining Networks#
Functions for finding an existing network to join and for finding an unused PAN id with which to form a network.
Summary of application requirements:
For the SoC:
Define ::SL_ZIGBEE_APPLICATION_HAS_ENERGY_SCAN_RESULT_HANDLER in the configuration header.
Call sl_zigbee_form_and_join_tick() regularly in the main loop.
Include form-and-join.c and form-and-join-node-adapter.c in the build.
Optionally include form-and-join-node-callbacks.c in the build.
If processor idling is desired: – Call sl_zigbee_form_and_join_task_init() to initialize the form and join task – Call sl_zigbee_form_and_join_run_task() regularly in the main loop instead of sl_zigbee_form_and_join_tick()
For an EZSP Host:
Define ::EZSP_APPLICATION_HAS_ENERGY_SCAN_RESULT_HANDLER in the configuration header.
Include form-and-join.c and form-and-join-host-adapter.c in the build.
Optionally include form-and-join-host-callbacks.c in the build.
For either platform, the application can omit the form-and-join-*-callback.c file from the build and implement the callbacks itself if necessary. In this case, the appropriate form-and-join callback function must be called from within each callback as within the form-and-join-*-callback.c files.
On either platform, FORM_AND_JOIN_MAX_NETWORKS can be explicitly defined to limit (or expand) the number of joinable networks that the library will save for consideration during the scan process.
The library can resume scanning for joinable networks from where it left off, via a call to sl_zigbee_scan_for_next_joinable_network(). Therefore, if the first joinable network found is not the correct one, the application can continue scanning without starting from the beginning and without finding the same network that it has already rejected. The library can also be used on the host processor.
Functions#
Find an unused PAN ID.
Find a joinable network.
Return true if and only if the form and join library is in the process of scanning and is therefore expecting scan results to be passed to it from the application.
Return true if and only if the application can continue a joinable network scan by calling sl_zigbee_scan_for_next_joinable_network(). See sl_zigbee_scan_for_joinable_network().
A callback the application needs to implement.
A callback the application needs to implement.
The application must call this function from within its sl_zigbee_scan_complete_handler() (on the node) or sl_zigbee_ezsp_scan_complete_handler() (on an EZSP host). Default callback implementations are provided in the form-and-join-*-callbacks.c files.
The application must call this function from within its sl_zigbee_network_found_handler() (on the node) or sl_zigbee_ezsp_network_found_handler() (on an EZSP host). Default callback implementations are provided in the form-and-join-*-callbacks.c files.
The application must call this function from within its sl_zigbee_energy_scan_result_handler() (on the node) or sl_zigbee_ezsp_energy_scan_result_handler() (on an EZSP host). Default callback implementations are provided in the form-and-join-*-callbacks.c files.
The application must call this function from within its sl_zigbee_unused_pand_id_found_handler() (on the node) or sl_zigbee_ezsp_energy_scan_result_handler() (on an EZSP host). Default callback implementations are provided in the form-and-join-*-callbacks.c files.
When processor idling is desired on the SOC, this must be called to properly initialize the form and join library.
When processor idling is desired on the SOC, this should be called regularly instead of sl_zigbee_form_and_join_tick()
When form-and-join state is no longer needed, the application can call this routine to cleanup and free resources. On the SOC platforms this will free the allocated message buffer.
Network found.
Unused Pan ID found.
Macros#
Number of bytes required to store relevant info for a saved network.
Log_base2 of NETWORK_STORAGE_SIZE.
Number of joinable networks that can be remembered during the scan process.
Function Documentation#
sl_zigbee_scan_for_unused_pan_id#
sl_status_t sl_zigbee_scan_for_unused_pan_id (uint32_t channelMask, uint8_t duration)
Find an unused PAN ID.
N/A | channelMask | |
N/A | duration | The duration of the energy scan. See the documentation for sl_zigbee_start_scan() in stack/include/network-formation.h for information on duration values. |
Does an energy scan on the indicated channels and randomly chooses one from amongst those with the least average energy. Then picks a short PAN ID that does not appear during an active scan on the chosen channel. The chosen PAN ID and channel are returned via the sl_zigbee_unused_pan_id_found_handler() callback. If an error occurs, the application is informed via the sl_zigbee_scan_error_handler().
Returns
SL_STATUS_NOT_AVAILABLE if the form and join library is not available.
121
of file app/util/common/form-and-join.h
sl_zigbee_scan_for_joinable_network#
sl_status_t sl_zigbee_scan_for_joinable_network (uint32_t channelMask, uint8_t * extendedPanId)
Find a joinable network.
N/A | channelMask | |
N/A | extendedPanId |
Performs an active scan on the specified channels looking for networks that:
currently permit joining,
match the stack profile of the application,
match the extended PAN id argument if it is not NULL.
Upon finding a matching network, the application is notified via the sl_zigbee_joinable_network_found_handler() callback, and scanning stops. If an error occurs during the scanning process, the application is informed via the sl_zigbee_scan_error_handler(), and scanning stops.
If the application determines that the discovered network is not the correct one, it may call sl_zigbee_scan_for_next_joinable_network() to continue the scanning process where it was left off and find a different joinable network. If the next network is not the correct one, the application can continue to call sl_zigbee_scan_for_next_joinable_network(). Each call must occur within 30 seconds of the previous one, otherwise the state of the scan process is deleted to free up memory. Calling sl_zigbee_scan_for_joinable_network() causes any old state to be forgotten and starts scanning from the beginning.
Returns
SL_STATUS_NOT_AVAILABLE if the form and join library is not available.
149
of file app/util/common/form-and-join.h
sl_zigbee_scan_for_next_joinable_network#
sl_status_t sl_zigbee_scan_for_next_joinable_network (void )
See sl_zigbee_scan_for_joinable_network().
N/A |
152
of file app/util/common/form-and-join.h
sl_zigbee_form_and_join_is_scanning#
bool sl_zigbee_form_and_join_is_scanning (void )
Return true if and only if the form and join library is in the process of scanning and is therefore expecting scan results to be passed to it from the application.
N/A |
158
of file app/util/common/form-and-join.h
sl_zigbee_form_and_join_can_continue_joinable_network_scan#
bool sl_zigbee_form_and_join_can_continue_joinable_network_scan (void )
Return true if and only if the application can continue a joinable network scan by calling sl_zigbee_scan_for_next_joinable_network(). See sl_zigbee_scan_for_joinable_network().
N/A |
164
of file app/util/common/form-and-join.h
sl_zigbee_joinable_network_found_handler#
void sl_zigbee_joinable_network_found_handler (sl_zigbee_zigbee_network_t * networkFound, uint8_t lqi, int8_t rssi)
A callback the application needs to implement.
N/A | networkFound | |
N/A | lqi | The LQI value of the received beacon. |
N/A | rssi | The RSSI value of the received beacon. |
Notifies the application of the network found after a call to sl_zigbee_scan_for_joinable_network() or sl_zigbee_scan_for_next_joinable_network().
179
of file app/util/common/form-and-join.h
sl_zigbee_scan_error_handler#
void sl_zigbee_scan_error_handler (sl_status_t status)
A callback the application needs to implement.
N/A | status |
If an error occurs while scanning, this function is called and the scan effort is aborted.
Possible return status values are:
SL_STATUS_INVALID_STATE: if sl_zigbee_scan_for_next_joinable_network() is called more than 30 seconds after a previous call to sl_zigbee_scan_for_joinable_network() or sl_zigbee_scan_for_next_joinable_network().
SL_STATUS_ALLOCATION_FAILED: if there is not enough memory to start a scan.
SL_STATUS_NO_BEACONS: if no joinable beacons are found.
SL_STATUS_MAC_SCANNING: if a scan is already in progress.
200
of file app/util/common/form-and-join.h
sl_zigbee_form_and_join_scan_complete_handler#
bool sl_zigbee_form_and_join_scan_complete_handler (uint8_t channel, sl_status_t status)
The application must call this function from within its sl_zigbee_scan_complete_handler() (on the node) or sl_zigbee_ezsp_scan_complete_handler() (on an EZSP host). Default callback implementations are provided in the form-and-join-*-callbacks.c files.
N/A | channel | |
N/A | status |
Returns
true if the library made use of the call.
213
of file app/util/common/form-and-join.h
sl_zigbee_form_and_join_network_found_handler#
bool sl_zigbee_form_and_join_network_found_handler (sl_zigbee_zigbee_network_t * networkFound, uint8_t lqi, int8_t rssi)
The application must call this function from within its sl_zigbee_network_found_handler() (on the node) or sl_zigbee_ezsp_network_found_handler() (on an EZSP host). Default callback implementations are provided in the form-and-join-*-callbacks.c files.
N/A | networkFound | |
N/A | lqi | |
N/A | rssi |
Returns
true if the library made use of the call.
222
of file app/util/common/form-and-join.h
sl_zigbee_form_and_join_energy_scan_result_handler#
bool sl_zigbee_form_and_join_energy_scan_result_handler (uint8_t channel, int8_t maxRssiValue)
The application must call this function from within its sl_zigbee_energy_scan_result_handler() (on the node) or sl_zigbee_ezsp_energy_scan_result_handler() (on an EZSP host). Default callback implementations are provided in the form-and-join-*-callbacks.c files.
N/A | channel | |
N/A | maxRssiValue |
Returns
true if the library made use of the call.
233
of file app/util/common/form-and-join.h
sl_zigbee_form_and_join_unused_pan_id_found_handler#
bool sl_zigbee_form_and_join_unused_pan_id_found_handler (sl_802154_pan_id_t panId, uint8_t channel)
The application must call this function from within its sl_zigbee_unused_pand_id_found_handler() (on the node) or sl_zigbee_ezsp_energy_scan_result_handler() (on an EZSP host). Default callback implementations are provided in the form-and-join-*-callbacks.c files.
N/A | panId | |
N/A | channel |
240
of file app/util/common/form-and-join.h
sl_zigbee_form_and_join_tick#
void sl_zigbee_form_and_join_tick (void )
N/A |
Used by the form and join code on the node to time out a joinable scan after 30 seconds of inactivity. The application must call sl_zigbee_form_and_join_tick() regularly. This function does not exist for the EZSP host library.
246
of file app/util/common/form-and-join.h
sl_zigbee_form_and_join_task_init#
void sl_zigbee_form_and_join_task_init (void )
When processor idling is desired on the SOC, this must be called to properly initialize the form and join library.
N/A |
251
of file app/util/common/form-and-join.h
sl_zigbee_form_and_join_run_task#
void sl_zigbee_form_and_join_run_task (void )
When processor idling is desired on the SOC, this should be called regularly instead of sl_zigbee_form_and_join_tick()
N/A |
256
of file app/util/common/form-and-join.h
sl_zigbee_form_and_join_cleanup#
void sl_zigbee_form_and_join_cleanup (sl_status_t status)
When form-and-join state is no longer needed, the application can call this routine to cleanup and free resources. On the SOC platforms this will free the allocated message buffer.
N/A | status |
262
of file app/util/common/form-and-join.h
sl_zigbee_af_form_and_join_network_found_cb#
void sl_zigbee_af_form_and_join_network_found_cb (sl_zigbee_zigbee_network_t * networkFound, uint8_t lqi, int8_t rssi)
Network found.
N/A | networkFound | Ver.: always |
N/A | lqi | Ver.: always |
N/A | rssi | Ver.: always |
This is called by the form-and-join library to notify the application of the network found after a call to sl_zigbee_scan_for_joinable_network() or sl_zigbee_scan_for_next_joinable_network(). See form-and-join documentation for more information.
275
of file app/util/common/form-and-join.h
sl_zigbee_af_form_and_join_unused_pan_id_found_cb#
void sl_zigbee_af_form_and_join_unused_pan_id_found_cb (sl_802154_pan_id_t panId, uint8_t channel)
Unused Pan ID found.
N/A | panId | A randomly generated PAN ID without other devices on it. Ver.: always |
N/A | channel | The channel where the PAN ID can be used to form a new network. Ver.: always |
This function is called when the form-and-join library finds an unused PAN ID that can be used to form a new network on.
289
of file app/util/common/form-and-join.h
Macro Definition Documentation#
NETWORK_STORAGE_SIZE#
#define NETWORK_STORAGE_SIZEValue:
16
Number of bytes required to store relevant info for a saved network.
This constant represents the minimum number of bytes required to store all members of the sli_zigbee_network_info_t struct used in the adapter code. Its value should not be changed unless the underlying adapter code is updated accordingly. Note that this constant's value may be different than sizeof(sli_zigbee_network_info_t) because some compilers pad the structs to align on word boundaries. Thus, the adapter code stores/retrieves these pieces of data individually (to be platform-agnostic) rather than as a struct.
For efficiency's sake, this number should be kept to a power of 2 and not and not exceed 32 (PACKET_BUFFER_SIZE).
80
of file app/util/common/form-and-join.h
NETWORK_STORAGE_SIZE_SHIFT#
#define NETWORK_STORAGE_SIZE_SHIFTValue:
4
Log_base2 of NETWORK_STORAGE_SIZE.
84
of file app/util/common/form-and-join.h
FORM_AND_JOIN_MAX_NETWORKS#
#define FORM_AND_JOIN_MAX_NETWORKSValue:
5
Number of joinable networks that can be remembered during the scan process.
Note for EZSP Host Platforms: In the host implementation of this library, the storage size for the detected networks buffer is controlled by ::EZSP_HOST_FORM_AND_JOIN_BUFFER_SIZE, so that limits the highest value that the host can set for FORM_AND_JOIN_MAX_NETWORKS.
101
of file app/util/common/form-and-join.h