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#
Generic callback for Wi-Fi group events of type sl_wifi_event_group_t.
Callback for SL_WIFI_SCAN_RESULT_EVENTS group event of type sl_wifi_event_group_t.
Callback for SL_WIFI_STATS_RESPONSE_EVENTS group events of type sl_wifi_event_group_t.
Callback for SL_WIFI_JOIN_EVENTS group events of type sl_wifi_event_group_t.
Callback for SL_WIFI_TWT_RESPONSE_EVENTS group events.
Callback for SL_WIFI_TRANSCEIVER_EVENTS group events.
Functions#
Register a callback for a selected event group.
Default Wi-Fi event handler to be passed to sl_wifi_init.
Register a callback for the SL_WIFI_SCAN_RESULT_EVENTS group event from sl_wifi_event_group_t.
Register a callback for SL_WIFI_JOIN_EVENTS group event from sl_wifi_event_group_t.
Register a callback for SL_WIFI_TWT_RESPONSE_EVENTS group event from sl_wifi_event_group_t.
Register a callback for SL_WIFI_STATS_RESPONSE_EVENTS group event from sl_wifi_event_group_t.
Register a callback for SL_WIFI_TRANSCEIVER_EVENTS group event of tye sl_wifi_event_group_t.
Macros#
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.
N/A | event | Wi-Fi event of type sl_wifi_event_t. This parameter indicates the specific Wi-Fi event that triggered the callback. |
N/A | data | Pointer to the data received. The type and content of this data depend on the specific event. |
N/A | data_length | Length of the data received in bytes. |
N/A | optional_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
sl_status_t. See Status Codes and Additional Status Codes for details.
Note
In case of event failure, the
SL_WIFI_FAIL_EVENT_STATUS_INDICATION
bit is set in theevent
parameter. When this bit is set, thedata
parameter will be of typesl_status_t
, and thedata_length
parameter can be ignored.
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.
N/A | event | Wi-Fi event of type sl_wifi_event_t. This parameter indicates the specific Wi-Fi event that triggered the callback.
| ||||
N/A | data | 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/A | data_length | Length of the scan results data received in bytes. | ||||
N/A | optional_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.
Wi-Fi module must call sl_wifi_start_scan to receive SL_WIFI_SCAN_RESULT_EVENTS event.
Returns
sl_status_t. See Status Codes and Additional Status Codes for details.
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 typesl_status_t
, and thedata_length
parameter can be ignored.
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.
N/A | event | 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:
| ||||||||||||
N/A | data | Pointer to the payload received. | ||||||||||||
N/A | data_length | Length of the payload received in bytes. | ||||||||||||
N/A | optional_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
sl_status_t. See Status Codes and Additional Status Codes for details.
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 theevent
parameter. When this bit is set, thedata
parameter will be of typesl_status_t
, and thedata_length
parameter can be ignored.
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.
N/A | event | Wi-Fi event of type sl_wifi_event_t that triggered the callback. | ||||||
N/A | data | Pointer to the response data received (1 byte). The possible values and their descriptions are as follows:
| ||||||
N/A | data_length | Length of the data received in bytes. This parameter indicates the size of the data buffer pointed to by the | ||||||
N/A | optional_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
sl_status_t. See Status Codes and Additional Status Codes for details.
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 theevent
parameter. When this bit is set, thedata
parameter will be of typesl_status_t
, and thedata_length
parameter can be ignored.
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.
N/A | event | 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:
| ||||||||||||||||||||||||||||
N/A | data | 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/A | data_length | Length of the data received in bytes. | ||||||||||||||||||||||||||||
N/A | optional_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
sl_status_t. See Status Codes and Additional Status Codes for details.
Note
In case of event failure, the
SL_WIFI_FAIL_EVENT_STATUS_INDICATION
bit is set in theevent
parameter. When this bit is set, thedata
parameter will be of typesl_status_t
, and thedata_length
parameter can be ignored.
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.
[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:
| ||||||
[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
sl_status_t. See Status Codes and Additional Status Codes for details.
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 theevent
parameter. When this bit is set, thedata
parameter will be of typesl_status_t
, and thedata_length
parameter can be ignored.
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.
[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
sl_status_t. See Status Codes and Additional Status Codes for details.
Note
Callbacks can be set only for event groups defined in sl_wifi_event_group_t, not for individual events defined in sl_wifi_event_t.
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.
[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
sl_status_t. See Status Codes and Additional Status Codes for details.
Note
Passing the event handler is optional. User can implement their own event dispatching handler if they prefer.
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.
[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:
sl_wifi_init should be called before this API.
Returns
sl_status_t. See Status Codes and Additional Status Codes for details.
Note
All the individual Wi-Fi events related to this group would be triggered via this callback.
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.
[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
sl_status_t. See Status Codes and Additional Status Codes for details.
Note
All the individual Wi-Fi events related to this group will be triggered via this callback.
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.
[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
sl_status_t. See Status Codes and Additional Status Codes for details.
Note
All the individual Wi-Fi events related to this group would be triggered via this callback.
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.
[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
sl_status_t. See Status Codes and Additional Status Codes for details.
Note
All the individual Wi-Fi events related to this group would be triggered via this callback.
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.
[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:
sl_wifi_init should be called before this API.
Returns
sl_status_t. See Status Codes and Additional Status Codes for details.
Note
All the individual Wi-Fi events related to this group will be triggered via this callback.
443
of file components/protocol/wifi/inc/sl_wifi_callback_framework.h