Callback Framework#

This section provides a reference to Wi-Fi API callback handling functions.

Note

  • Event/Callback handlers must not contain function calls or code which can block or delay the execution of the event/callback handler as it will cause all the other events to queue up and delay the execution of other events since all the events are invoked and handled from a single thread.

  • Do not call any synchronous SDK APIs from within the Event/Callback handlers.

Typedefs#

typedef sl_status_t(*
sl_wifi_callback_function_t)(sl_wifi_event_t event, void *data, uint32_t data_length, void *optional_arg)

Generic callback for Wi-Fi group events of type sl_wifi_event_group_t.

typedef sl_status_t(*
sl_wifi_scan_callback_t)(sl_wifi_event_t event, sl_wifi_scan_result_t *data, uint32_t data_length, void *optional_arg)

Callback for SL_WIFI_SCAN_RESULT_EVENTS group event of type sl_wifi_event_group_t.

typedef sl_status_t(*
sl_wifi_stats_callback_t)(sl_wifi_event_t event, void *data, uint32_t data_length, void *optional_arg)

Callback for SL_WIFI_STATS_RESPONSE_EVENTS group events of type sl_wifi_event_group_t.

typedef sl_status_t(*
sl_wifi_join_callback_t)(sl_wifi_event_t event, char *data, uint32_t data_length, void *optional_arg)

Callback for SL_WIFI_JOIN_EVENTS group events of type sl_wifi_event_group_t.

typedef sl_status_t(*
sl_wifi_twt_config_callback_t)(sl_wifi_event_t event, sl_si91x_twt_response_t *data, uint32_t data_length, void *optional_arg)

Callback for SL_WIFI_TWT_RESPONSE_EVENTS group events.

typedef sl_status_t(*
sl_wifi_transceiver_callback_t)(sl_wifi_event_t event, void *data, uint32_t data_length, void *optional_arg)

Callback for SL_WIFI_TRANSCEIVER_EVENTS group events.

Functions#

sl_status_t
sl_wifi_set_callback(sl_wifi_event_group_t group, sl_wifi_callback_function_t function, void *optional_arg)

Register a callback for a selected event group.

sl_status_t
sl_wifi_default_event_handler(sl_wifi_event_t event, sl_wifi_buffer_t *buffer)

Default Wi-Fi event handler to be passed to sl_wifi_init.

sl_status_t
sl_wifi_set_scan_callback(sl_wifi_scan_callback_t function, void *optional_arg)

Register a callback for the SL_WIFI_SCAN_RESULT_EVENTS group event from sl_wifi_event_group_t.

sl_status_t
sl_wifi_set_join_callback(sl_wifi_join_callback_t function, void *optional_arg)

Register a callback for SL_WIFI_JOIN_EVENTS group event from sl_wifi_event_group_t.

sl_status_t
sl_wifi_set_twt_config_callback(sl_wifi_twt_config_callback_t function, void *optional_arg)

Register a callback for SL_WIFI_TWT_RESPONSE_EVENTS group event from sl_wifi_event_group_t.

sl_status_t
sl_wifi_set_stats_callback(sl_wifi_stats_callback_t function, void *optional_arg)

Register a callback for SL_WIFI_STATS_RESPONSE_EVENTS group event from sl_wifi_event_group_t.

sl_status_t
sl_wifi_set_transceiver_callback(sl_wifi_transceiver_callback_t function, void *optional_arg)

Register a callback for SL_WIFI_TRANSCEIVER_EVENTS group event of tye sl_wifi_event_group_t.

Macros#

#define

Generic macro for callback functions to check if the event has failed.

Typedef Documentation#

sl_wifi_callback_function_t#

sl_wifi_callback_function_t )(sl_wifi_event_t event, void *data, uint32_t data_length, void *optional_arg)

Generic callback for Wi-Fi group events of type sl_wifi_event_group_t.

Parameters
N/Aevent

Wi-Fi event of type sl_wifi_event_t. This parameter indicates the specific Wi-Fi event that triggered the callback.

N/Adata

Pointer to the data received. The type and content of this data depend on the specific event.

N/Adata_length

Length of the data received in bytes.

N/Aoptional_arg

Optional user-provided argument passed in sl_wifi_set_callback. This parameter allows the user to pass additional context or information to the callback function.

This typedef defines a callback function that handles Wi-Fi events of type sl_wifi_event_t. The callback is invoked when a Wi-Fi event occurs, providing the event details and any associated data.

Returns

Note

  • In case of event failure, the SL_WIFI_FAIL_EVENT_STATUS_INDICATION bit is set in the event parameter. When this bit is set, the data parameter will be of type sl_status_t, and the data_length parameter can be ignored.


Definition at line 53 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_scan_callback_t#

sl_wifi_scan_callback_t )(sl_wifi_event_t event, sl_wifi_scan_result_t *data, uint32_t data_length, void *optional_arg)

Callback for SL_WIFI_SCAN_RESULT_EVENTS group event of type sl_wifi_event_group_t.

Parameters
N/Aevent

Wi-Fi event of type sl_wifi_event_t. This parameter indicates the specific Wi-Fi event that triggered the callback.

sl_wifi_event_t

Description

SL_WIFI_SCAN_RESULT_EVENTS

It is an indication to host that the scan was successful or failed

N/Adata

Pointer to the scan results of type sl_wifi_scan_result_t. This parameter provides the scan results obtained from the Wi-Fi scan operation.

N/Adata_length

Length of the scan results data received in bytes.

N/Aoptional_arg

Optional user provided argument passed in sl_wifi_set_scan_callback.

This typedef defines a callback function that handles Wi-Fi scan result events of type sl_wifi_event_t. The callback is triggered when a Wi-Fi module tries to scan and receive the response, providing the event details and any associated scan results.

Returns

Note

  • In case of event failure, SL_WIFI_FAIL_EVENT_STATUS_INDICATION bit is set in the event. When this bit is set, the data parameter will be of type sl_status_t, and the data_length parameter can be ignored.


Definition at line 86 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_stats_callback_t#

sl_wifi_stats_callback_t )(sl_wifi_event_t event, void *data, uint32_t data_length, void *optional_arg)

Callback for SL_WIFI_STATS_RESPONSE_EVENTS group events of type sl_wifi_event_group_t.

Parameters
N/Aevent

Wi-Fi event of type sl_wifi_event_t that triggered the callback. Individual Wi-Fi events related to SL_WIFI_STATS_RESPONSE_EVENTS is as follows:

sl_wifi_event_t

DataType

SL_WIFI_STATS_EVENT

Not supported in current release

SL_WIFI_STATS_AYSNC_EVENT

sl_si91x_async_stats_response_t

SL_WIFI_STATS_ADVANCE_EVENT

Not supported in current release

SL_WIFI_STATS_TEST_MODE_EVENT

Not supported in current release

SL_WIFI_STATS_MODULE_STATE_EVENT

sl_si91x_module_state_stats_response_t

N/Adata

Pointer to the payload received.

N/Adata_length

Length of the payload received in bytes.

N/Aoptional_arg

Optional user provided argument passed in sl_wifi_set_stats_callback.

This typedef defines a callback function that handles Wi-Fi statistics response events of type sl_wifi_event_t. The callback is invoked when a Wi-Fi statistics response event occurs, providing the event details and any associated data.

Returns

Note

  • SL_WIFI_STATS_MODULE_STATE_EVENT messages are used to indicate module state to the host. These messages are enabled by setting the 10th bit of the custom feature bitmap in opermode. For the event SL_WIFI_STATS_MODULE_STATE_EVENT response structure refer sl_si91x_module_state_stats_response_t.

    • state_code of this response (1 byte), indicates the state of the module. state_code contains two parts, the upper nibble and lower nibble.

      The upper nibble indicates the state of the rejoin process. The following table documents the possible values of the upper nibble of the state_code.

      Module state code upper nibble

      Description

      0x00

      Startup (Initial Roam). Indicates the reason for scan triggered(state-I).

      0x10

      Beacon Loss (Failover Roam). Indicates the reason for scan triggered(state-I).

      0x20

      De-authentication (AP induced Roam / Disconnect from supplicant). Indicates the reason for scan triggered(state-I).

      0x50

      Current AP is best. Indicates a state change based on scan result(state-II).

      0x60

      Better AP found. Indicates a state change based on scan result(state-II).

      0x70

      No AP found. Indicates a state change based on scan result(state-II).

      0x80

      Associated. Indicates the connection state change(state – III).

      0x90

      Unassociated. Indicates the connection state change(state – III).

  • The lower nibble of state_code indicates the reason for a state change. The table below lists the possible values of the lower nibble of the state_code.

    Module state code lower nibble

    Description

    0x00

    No reason specified.

    0x01

    Authentication denial.

    0x02

    Association denial.

    0x03

    AP not present.

    0x05

    WPA2 key exchange failed.

  • Module reason code

    Description

    0x00

    No reason specified.

    0x01

    Authentication denial.

    0x02

    Association denial.

    0x07

    PSK not configured

    0x09

    Roaming not enabled

    0x10

    Beacon Loss (Failover Roam)

    0x20

    De-authentication (AP induced Roam/Deauth from supplicant)

  • In case of event failure, the SL_WIFI_FAIL_EVENT_STATUS_INDICATION bit is set in the event parameter. When this bit is set, the data parameter will be of type sl_status_t, and the data_length parameter can be ignored.


Definition at line 162 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_join_callback_t#

sl_wifi_join_callback_t )(sl_wifi_event_t event, char *data, uint32_t data_length, void *optional_arg)

Callback for SL_WIFI_JOIN_EVENTS group events of type sl_wifi_event_group_t.

Parameters
N/Aevent

Wi-Fi event of type sl_wifi_event_t that triggered the callback.

N/Adata

Pointer to the response data received (1 byte). The possible values and their descriptions are as follows:

Data received

Description

C

Module connection success

F

Module connection failed

N/Adata_length

Length of the data received in bytes. This parameter indicates the size of the data buffer pointed to by the data parameter.

N/Aoptional_arg

Optional user provided argument passed in sl_wifi_set_join_callback.

This typedef defines a callback function that handles Wi-Fi join events of type sl_wifi_event_t. The callback is invoked when a Wi-Fi join event occurs, providing the event details and any associated data.

Returns

Note

  • This is valid in WiFi client mode only

  • In case of event failure, the SL_WIFI_FAIL_EVENT_STATUS_INDICATION bit is set in the event parameter. When this bit is set, the data parameter will be of type sl_status_t, and the data_length parameter can be ignored.


Definition at line 196 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_twt_config_callback_t#

sl_wifi_twt_config_callback_t )(sl_wifi_event_t event, sl_si91x_twt_response_t *data, uint32_t data_length, void *optional_arg)

Callback for SL_WIFI_TWT_RESPONSE_EVENTS group events.

Parameters
N/Aevent

Wi-Fi event of type sl_wifi_event_t that triggered the callback. Individual Wi-Fi events related to SL_WIFI_TWT_RESPONSE_EVENTS is as follows:

sl_wifi_event_t

Description

SL_WIFI_TWT_UNSOLICITED_SESSION_SUCCESS_EVENT

Unsolicited TWT session was successfully established.

SL_WIFI_TWT_AP_REJECTED_EVENT

TWT request was rejected by the Access Point (AP).

SL_WIFI_TWT_OUT_OF_TOLERANCE_EVENT

TWT response out of tolerance limits

SL_WIFI_TWT_RESPONSE_NOT_MATCHED_EVENT

TWT response did not match the request.

SL_WIFI_TWT_UNSUPPORTED_RESPONSE_EVENT

TWT response is unsupported.

SL_WIFI_TWT_TEARDOWN_SUCCESS_EVENT

TWT session teardown was successful.

SL_WIFI_TWT_AP_TEARDOWN_SUCCESS_EVENT

AP successfully tore down the TWT session.

SL_WIFI_TWT_FAIL_MAX_RETRIES_REACHED_EVENT

Reached maximum number of retries for TWT setup.

SL_WIFI_TWT_INACTIVE_DUE_TO_ROAMING_EVENT

TWT session became inactive due to roaming.

SL_WIFI_TWT_INACTIVE_DUE_TO_DISCONNECT_EVENT

TWT session became inactive due to disconnection.

SL_WIFI_TWT_INACTIVE_NO_AP_SUPPORT_EVENT

Connected AP does not support TWT

SL_WIFI_RESCHEDULE_TWT_SUCCESS_EVENT

TWT session was successfully rescheduled.

SL_WIFI_TWT_INFO_FRAME_EXCHANGE_FAILED_EVENT

TWT information frame exchange failed.

N/Adata

Pointer to the data received of type sl_si91x_twt_response_t. This parameter provides detailed information about the TWT response event. The structure contains various fields that describe the TWT session parameters and status.

N/Adata_length

Length of the data received in bytes.

N/Aoptional_arg

Optional user provided argument passed in sl_wifi_set_twt_config_callback.

This typedef defines a callback function that handles Wi-Fi Target Wake Time (TWT) configuration response events. The callback is invoked when a TWT response event occurs, providing the event details and any associated data.

Returns

Note

  • In case of event failure, the SL_WIFI_FAIL_EVENT_STATUS_INDICATION bit is set in the event parameter. When this bit is set, the data parameter will be of type sl_status_t, and the data_length parameter can be ignored.


Definition at line 240 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_transceiver_callback_t#

sl_wifi_transceiver_callback_t )(sl_wifi_event_t event, void *data, uint32_t data_length, void *optional_arg)

Callback for SL_WIFI_TRANSCEIVER_EVENTS group events.

Parameters
[out]event

Wi-Fi event of type sl_wifi_event_t. This parameter indicates the specific Wi-Fi event that triggered the callback. Individual Wi-Fi events related to SL_WIFI_TRANSCEIVER_EVENTS are as follows:

sl_wifi_event_t

Description

SL_WIFI_TRANSCEIVER_RX_DATA_RECEIVE_CB

Indicates that data has been received by the transceiver.

SL_WIFI_TRANSCEIVER_TX_DATA_STATUS_CB

Indicates the status of the data sent by the transceiver.

[out]data
[out]data_length

Reserved.

[out]optional_arg

Optional user provided argument passed in sl_wifi_set_transceiver_callback

This typedef defines a callback function that handles Wi-Fi transceiver events. The callback is invoked when a transceiver event occurs, providing the event details and any associated data.

Returns

Note

  • This API is only supported in Wi-Fi Transceiver opermode (7).

  • In case of event failure, the SL_WIFI_FAIL_EVENT_STATUS_INDICATION bit is set in the event parameter. When this bit is set, the data parameter will be of type sl_status_t, and the data_length parameter can be ignored.


Definition at line 275 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

Function Documentation#

sl_wifi_set_callback#

sl_status_t sl_wifi_set_callback (sl_wifi_event_group_t group, sl_wifi_callback_function_t function, void * optional_arg)

Register a callback for a selected event group.

Parameters
[in]group

Group ID of the event for which the callback is registered. See sl_wifi_event_group_t for possible values.

[in]function

Function pointer to callback of type sl_wifi_callback_function_t that would be invoked when an event in the specified group occurs.

[in]optional_arg

Optional user provided argument to pass additional context or information to the callback function. This would be passed back to callback handler of type sl_wifi_callback_function_t.

All the individual Wi-Fi events related to specific group would be triggered via this group callback.

This function allows the user to register a callback function for a specific group of Wi-Fi events sl_wifi_event_group_t. When any event within the specified group occurs, the registered callback function will be invoked, providing the event details and any associated data.

  • Pre-conditions:

    • The Wi-Fi module must be initialized by calling sl_wifi_init before this API can be used.

Returns

Note


Definition at line 302 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_default_event_handler#

sl_status_t sl_wifi_default_event_handler (sl_wifi_event_t event, sl_wifi_buffer_t * buffer)

Default Wi-Fi event handler to be passed to sl_wifi_init.

Parameters
[in]event

Wi-Fi event of type of sl_wifi_event_t.

[in]buffer

Buffer containing raw data from NWP firmware

This event handler would dispatch all the Wi-Fi events and invoke respective Wi-Fi group event.

This function serves as the default event handler for Wi-Fi events. When passed to the sl_wifi_init function, it would handle incoming Wi-Fi events by dispatching them to the appropriate group event functions.

Returns

Note

  • Passing the event handler is optional. User can implement their own event dispatching handler if they prefer.


Definition at line 322 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_set_scan_callback#

static sl_status_t sl_wifi_set_scan_callback (sl_wifi_scan_callback_t function, void * optional_arg)

Register a callback for the SL_WIFI_SCAN_RESULT_EVENTS group event from sl_wifi_event_group_t.

Parameters
[in]function

Callback function to register. This parameter specifies the callback function of type sl_wifi_scan_callback_t that would be invoked when an event in the SL_WIFI_SCAN_RESULT_EVENTS group occurs.

[in]optional_arg

Optional user provided argument. This would be passed back to callback handler of type sl_wifi_scan_callback_t.

This function allows the user to register a callback function for the SL_WIFI_SCAN_RESULT_EVENTS group. When any event within this group occurs, the registered callback function would be invoked, providing the event details and any associated data.

  • Pre-conditions:

Returns

Note

  • All the individual Wi-Fi events related to this group would be triggered via this callback.


Definition at line 344 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_set_join_callback#

static sl_status_t sl_wifi_set_join_callback (sl_wifi_join_callback_t function, void * optional_arg)

Register a callback for SL_WIFI_JOIN_EVENTS group event from sl_wifi_event_group_t.

Parameters
[in]function

Function pointer to callback of type sl_wifi_join_callback_t. This parameter specifies the callback function that would be invoked when an event in the SL_WIFI_JOIN_EVENTS group occurs.

[in]optional_arg

Optional user provided argument. This parameter allows the user to pass additional context or information to the callback function. This would be passed back to callback handler of type sl_wifi_twt_config_callback_t.

This function allows the user to register a callback function for the SL_WIFI_JOIN_EVENTS group. When any event within this group occurs, the registered callback function would be invoked, providing the event details and any associated data.

  • Pre-conditions: sl_wifi_init should be called before this API.

Returns

Note

  • All the individual Wi-Fi events related to this group will be triggered via this callback.


Definition at line 369 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_set_twt_config_callback#

static sl_status_t sl_wifi_set_twt_config_callback (sl_wifi_twt_config_callback_t function, void * optional_arg)

Register a callback for SL_WIFI_TWT_RESPONSE_EVENTS group event from sl_wifi_event_group_t.

Parameters
[in]function

Function pointer to the callback of type sl_wifi_twt_config_callback_t. This parameter specifies the callback function that would be invoked when an event in the SL_WIFI_TWT_RESPONSE_EVENTS group occurs.

[in]optional_arg

Optional user provided argument. This would be passed back to callback handler.

This function allows the user to register a callback function for the SL_WIFI_TWT_RESPONSE_EVENTS group. When any event within this group occurs, the registered callback function will be invoked, providing the event details and any associated data.

  • Pre-conditions: sl_wifi_init should be called before this API.

Returns

Note

  • All the individual Wi-Fi events related to this group would be triggered via this callback.


Definition at line 394 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_set_stats_callback#

static sl_status_t sl_wifi_set_stats_callback (sl_wifi_stats_callback_t function, void * optional_arg)

Register a callback for SL_WIFI_STATS_RESPONSE_EVENTS group event from sl_wifi_event_group_t.

Parameters
[in]function

Function pointer to the callback of type sl_wifi_stats_callback_t. This parameter specifies the callback function that would be invoked when an event in the SL_WIFI_STATS_RESPONSE_EVENTS group occurs.

[in]optional_arg

Optional user provided argument. This parameter allows the user to pass additional context or information to the callback function. This would be passed back to callback handler.

This function allows the user to register a callback function for the SL_WIFI_STATS_RESPONSE_EVENTS group. When any event within this group occurs, the registered callback function would be invoked, providing the event details and any associated data.

  • Pre-conditions: sl_wifi_init should be called before this API.

Returns

Note

  • All the individual Wi-Fi events related to this group would be triggered via this callback.


Definition at line 419 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

sl_wifi_set_transceiver_callback#

static sl_status_t sl_wifi_set_transceiver_callback (sl_wifi_transceiver_callback_t function, void * optional_arg)

Register a callback for SL_WIFI_TRANSCEIVER_EVENTS group event of tye sl_wifi_event_group_t.

Parameters
[in]function

Function pointer to the callback of type sl_wifi_transceiver_callback_t. This parameter specifies the callback function that would be invoked when an event in the SL_WIFI_TRANSCEIVER_EVENTS group occurs.

[in]optional_arg

Optional user provided argument. This parameter allows the user to pass additional context or information to the callback function. This would be passed back to callback handler.

This function allows the user to register a callback function for the SL_WIFI_TRANSCEIVER_EVENTS group. When any event within this group occurs, the registered callback function would be invoked, providing the event details and any associated data.

  • Pre-conditions:

Returns

Note

  • All the individual Wi-Fi events related to this group will be triggered via this callback.


Definition at line 443 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h

Macro Definition Documentation#

SL_WIFI_CHECK_IF_EVENT_FAILED#

#define SL_WIFI_CHECK_IF_EVENT_FAILED
Value:
(event)

Generic macro for callback functions to check if the event has failed.


Definition at line 29 of file components/protocol/wifi/inc/sl_wifi_callback_framework.h