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:

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#

sl_status_t
sl_zigbee_scan_for_unused_pan_id(uint32_t channelMask, uint8_t duration)

Find an unused PAN ID.

sl_status_t
sl_zigbee_scan_for_joinable_network(uint32_t channelMask, uint8_t *extendedPanId)

Find a joinable network.

bool

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.

bool

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().

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.

void
sl_zigbee_scan_error_handler(sl_status_t status)

A callback the application needs to implement.

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.

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.

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.

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.

void

When processor idling is desired on the SOC, this must be called to properly initialize the form and join library.

void

When processor idling is desired on the SOC, this should be called regularly instead of sl_zigbee_form_and_join_tick()

void

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.

void
sl_zigbee_af_form_and_join_network_found_cb(sl_zigbee_zigbee_network_t *networkFound, uint8_t lqi, int8_t rssi)

Network found.

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.

Macros#

#define

Number of bytes required to store relevant info for a saved network.

#define

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.

Parameters
N/AchannelMask
N/Aduration

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.


Definition at line 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.

Parameters
N/AchannelMask
N/AextendedPanId

Performs an active scan on the specified channels looking for networks that:

  1. currently permit joining,

  2. match the stack profile of the application,

  3. 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.


Definition at line 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().

Parameters
N/A

Definition at line 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.

Parameters
N/A

Definition at line 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().

Parameters
N/A

Definition at line 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.

Parameters
N/AnetworkFound
N/Alqi

The LQI value of the received beacon.

N/Arssi

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().


Definition at line 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.

Parameters
N/Astatus

If an error occurs while scanning, this function is called and the scan effort is aborted.

Possible return status values are:


Definition at line 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.

Parameters
N/Achannel
N/Astatus

Returns

  • true if the library made use of the call.


Definition at line 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.

Parameters
N/AnetworkFound
N/Alqi
N/Arssi

Returns

  • true if the library made use of the call.


Definition at line 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.

Parameters
N/Achannel
N/AmaxRssiValue

Returns

  • true if the library made use of the call.


Definition at line 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.

Parameters
N/ApanId
N/Achannel

Definition at line 240 of file app/util/common/form-and-join.h

sl_zigbee_form_and_join_tick#

void sl_zigbee_form_and_join_tick (void )
Parameters
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.


Definition at line 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.

Parameters
N/A

Definition at line 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()

Parameters
N/A

Definition at line 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.

Parameters
N/Astatus

Definition at line 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.

Parameters
N/AnetworkFound

Ver.: always

N/Alqi

Ver.: always

N/Arssi

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.


Definition at line 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.

Parameters
N/ApanId

A randomly generated PAN ID without other devices on it. Ver.: always

N/Achannel

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.


Definition at line 289 of file app/util/common/form-and-join.h

Macro Definition Documentation#

NETWORK_STORAGE_SIZE#

#define NETWORK_STORAGE_SIZE
Value:
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).


Definition at line 80 of file app/util/common/form-and-join.h

NETWORK_STORAGE_SIZE_SHIFT#

#define NETWORK_STORAGE_SIZE_SHIFT
Value:
4

Log_base2 of NETWORK_STORAGE_SIZE.


Definition at line 84 of file app/util/common/form-and-join.h

FORM_AND_JOIN_MAX_NETWORKS#

#define FORM_AND_JOIN_MAX_NETWORKS
Value:
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.


Definition at line 101 of file app/util/common/form-and-join.h