1 /***************************************************************************/ /**
2  * @file  sl_wifi_callback_framework.h
3  *******************************************************************************
4  * # License
5  * <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
6  *******************************************************************************
7  *
8  * SPDX-License-Identifier: Zlib
9  *
10  * The licensor of this software is Silicon Laboratories Inc.
11  *
12  * This software is provided 'as-is', without any express or implied
13  * warranty. In no event will the authors be held liable for any damages
14  * arising from the use of this software.
15  *
16  * Permission is granted to anyone to use this software for any purpose,
17  * including commercial applications, and to alter it and redistribute it
18  * freely, subject to the following restrictions:
19  *
20  * 1. The origin of this software must not be misrepresented; you must not
21  *    claim that you wrote the original software. If you use this software
22  *    in a product, an acknowledgment in the product documentation would be
23  *    appreciated but is not required.
24  * 2. Altered source versions must be plainly marked as such, and must not be
25  *    misrepresented as being the original software.
26  * 3. This notice may not be removed or altered from any source distribution.
27  *
28  ******************************************************************************/
29 
30 #pragma once
31 
32 #include "sl_wifi_host_interface.h"
33 #include "sl_wifi_device.h" // To access the device specific structs
34 #include <stdint.h>
35 
36 /** \addtogroup WIFI_CALLBACK_FRAMEWORK Callback Framework
37   * \ingroup SL_WIFI
38   * @{ */
39 
40 /// Generic macro for callback functions to check if the event has failed.
41 #define SL_WIFI_CHECK_IF_EVENT_FAILED(event) ((event & SL_WIFI_EVENT_FAIL_INDICATION) ? true : false)
42 
43 /**
44  * @typedef sl_wifi_callback_function_t
45  * @brief Generic callback for Wi-Fi group events of type @ref sl_wifi_event_group_t.
46  *
47  *   This typedef defines a callback function that handles Wi-Fi events of type @ref sl_wifi_event_t.
48  *   The callback is invoked when a Wi-Fi event occurs, providing the event details and any associated data.
49  *
50  * @param event
51  *   Wi-Fi event of type @ref sl_wifi_event_t. This parameter indicates the specific Wi-Fi event that triggered the callback.
52  * @param data
53  *   Pointer to the data received. The type and content of this data depend on the specific event.
54  * @param data_length
55  *   Length of the data received in bytes.
56  * @param optional_arg
57  *   Optional user-provided argument passed in @ref sl_wifi_set_callback. This parameter allows the user to pass additional context or information to the callback function.
58  * @return
59  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
60  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
61  * @note
62  *   In case of event failure, the `SL_WIFI_FAIL_EVENT_STATUS_INDICATION` bit is set in the `event` parameter.
63  *   When this bit is set, the `data` parameter will be of type `sl_status_t`, and the `data_length` parameter can be ignored.
64  */
65 typedef sl_status_t (*sl_wifi_callback_function_t)(sl_wifi_event_t event,
66                                                    void *data,
67                                                    uint32_t data_length,
68                                                    void *optional_arg);
69 
70 /**
71  * @typedef sl_wifi_scan_callback_t
72  * @brief Callback for SL_WIFI_SCAN_RESULT_EVENTS group event of type @ref sl_wifi_event_group_t.
73  *
74  *   This typedef defines a callback function that handles Wi-Fi scan result events of type @ref sl_wifi_event_t.
75  *   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.
76  *
77  * @param event
78  *   Wi-Fi event of type @ref sl_wifi_event_t. This parameter indicates the specific Wi-Fi event that triggered the callback.
79  *   | @ref sl_wifi_event_t                 | Description                                                          |
80  *   |:-------------------------------------|:---------------------------------------------------------------------|
81  *   | SL_WIFI_SCAN_RESULT_EVENTS           | It is an indication to host that the scan was successful or failed   |
82  * @param data
83  *   Pointer to the scan results of type @ref sl_wifi_scan_result_t. This parameter provides the scan results obtained from the Wi-Fi scan operation.
84  * @param data_length
85  *   Length of the scan results data received in bytes.
86  * @param optional_arg
87  *   Optional user provided argument passed in [sl_wifi_set_scan_callback](../wiseconnect-api-reference-guide-wi-fi/wifi-callback-framework#sl-wifi-set-scan-callback).
88  *
89  * @pre Wi-Fi module must call @ref sl_wifi_start_scan to receive SL_WIFI_SCAN_RESULT_EVENTS event.
90  *
91  * @return
92  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
93  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
94  * @note
95  *   In case of event failure, SL_WIFI_FAIL_EVENT_STATUS_INDICATION bit is set in the event.
96  *   When this bit is set, the `data` parameter will be of type `sl_status_t`, and the `data_length` parameter can be ignored.
97  */
98 typedef sl_status_t (*sl_wifi_scan_callback_t)(sl_wifi_event_t event,
99                                                sl_wifi_scan_result_t *data,
100                                                uint32_t data_length,
101                                                void *optional_arg);
102 
103 /**
104  * @typedef sl_wifi_stats_callback_t
105  * @brief Callback for SL_WIFI_STATS_RESPONSE_EVENTS group events of type @ref sl_wifi_event_group_t.
106  *
107  *   This typedef defines a callback function that handles Wi-Fi statistics response events of type @ref sl_wifi_event_t.
108  *   The callback is invoked when a Wi-Fi statistics response event occurs, providing the event details and any associated data.
109  *
110  * @param event
111  *   Wi-Fi event of type @ref sl_wifi_event_t that triggered the callback.
112  *   Individual Wi-Fi events related to SL_WIFI_STATS_RESPONSE_EVENTS is as follows:
113  *   | @ref sl_wifi_event_t                 | DataType                                    |
114  *   |:-------------------------------------|:--------------------------------------------|
115  *   | SL_WIFI_STATS_EVENT                  | Not supported in current release            |
116  *   | SL_WIFI_STATS_ASYNC_EVENT            | [sl_si91x_async_stats_response_t](../wiseconnect-api-reference-guide-si91x-driver/sl-si91x-async-stats-response-t)        |
117  *   | SL_WIFI_STATS_ADVANCE_EVENT          | Not supported in current release            |
118  *   | SL_WIFI_STATS_TEST_MODE_EVENT        | Not supported in current release            |
119  *   | SL_WIFI_STATS_MODULE_STATE_EVENT     | [sl_si91x_module_state_stats_response_t](../wiseconnect-api-reference-guide-si91x-driver/sl-si91x-module-state-stats-response-t) |
120  * @param data
121  *   Pointer to the payload received.
122  * @param data_length
123  *   Length of the payload received in bytes.
124  * @param optional_arg
125  *   Optional user provided argument passed in [sl_wifi_set_stats_callback](../wiseconnect-api-reference-guide-wi-fi/wifi-callback-framework#sl-wifi-set-stats-callback).
126  * @return
127  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
128  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
129  *
130  * @note
131  *  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.
132  *  For the event SL_WIFI_STATS_MODULE_STATE_EVENT response structure refer [sl_si91x_module_state_stats_response_t](../wiseconnect-api-reference-guide-si91x-driver/sl-si91x-module-state-stats-response-t).
133  * - state_code of this response  (1 byte), indicates the state of the module. `state_code` contains two parts, the upper nibble and lower nibble.
134  *  The state code is formed by combining the upper nibble and the lower nibble using a bitwise OR operation, i.e., State code = upper nibble | lower nibble
135  *  For example, if the state code is 82 but isn’t found in the table, it can be divided as follows: state_code = 80 | 02, where 80 is the upper nibble and 02 is the lower nibble.
136  *
137  *  The upper nibble indicates the state of the rejoin process.
138  *  The following table documents the possible values of the upper nibble of the state_code.
139  *  | Module state code                   | upper nibble | Description                                                                |
140  *  |:------------------------------------|------------- |----------------------------------------------------------------------------|
141  *  |     Scan Trigger (State I)          | 0x00         | Startup (Initial state or idle state).                                     |
142  *  | Indicates the reason for the scan   |--------------|----------------------------------------------------------------------------|
143  *  |         triggered.                  | 0x10         | Beacon Loss (Failover Roam).                                               |
144  *  |                                     |--------------|----------------------------------------------------------------------------|
145  *  |                                     | 0x20         | De-authentication from AP.                                                 |
146  *  |-------------------------------------|--------------|----------------------------------------------------------------------------|
147  *  |   Scan Result/Decision (State II)   | 0x50         | Current AP is best.                                                        |
148  *  | Indicates a state change based on   |--------------|--------------------------------------------------------------------------- |
149  *  | the scan result.                    | 0x60         | Better AP found while roaming.                                             |
150  *  |                                     |--------------|----------------------------------------------------------------------------|
151  *  |                                     | 0x70         | No AP found.                                                               |
152  *  |-------------------------------------|--------------|----------------------------------------------------------------------------|
153  *  | Final Connection or Join (State III)| 0x80         | Associated or joined to an Access point.                                   |
154  *  |Indicates the connection state       |--------------|----------------------------------------------------------------------------|
155  *  |change                               | 0x90         | Unassociated(Disconnected from host or join failure).                      |
156  *
157  * @note
158  *  The lower nibble of state_code indicates the reason for a state change.
159  *  The table below lists the possible values of the lower nibble of the state_code.
160  *  | Module state code lower nibble | Description                                   |
161  *  |:-------------------------------|:----------------------------------------------|
162  *  | 0x00                           | No reason specified (Initial state or idle state). |
163  *  | 0x01                           | No response from AP for authentication request(Authentication denial).   |
164  *  | 0x02                           | Association denial (Association timeout or Association failure due to unknown reasons). |
165  *  | 0x03                           | User configured AP is not present.            |
166  *  | 0x05                           | Four-way Handshake failure.                   |
167  *  | 0x06                           | Deauthentication from user.                   |
168  *  | 0x07                           | PSK not configured.                           |
169  *  | 0x08                           | key-handshake failure during rejoin/roaming/after connection(Disconnection from supplicant). |
170  *  | 0x09                           | Roaming not enabled.                          |
171  *
172  * @note
173  *  | Module reason code | Description                                                |
174  *  |:-------------------|:-----------------------------------------------------------|
175  *  | 0x00               | No reason specified (Initial state or idle state).         |
176  *  | 0x01               | No response from AP for authentication request(Authentication denial). |
177  *  | 0x02               | Association denial (caused by Association timeout or Association failure due to unknown reasons). |
178  *  | 0x03               | User configured AP is not present.                         |
179  *  | 0x05               | Four-way Handshake failure.                                |
180  *  | 0x06               | Deauthentication from user.                                |
181  *  | 0x07               | PSK not configured.                                        |
182  *  | 0x08               | key-handshake failure during rejoin/roaming/after connection(Disconnection from supplicant). |
183  *  | 0x09               | Roaming not enabled                                        |
184  *  | 0x10               | Beacon Loss (Failover Roam).                               |
185  *  | 0x20               | De-authentication from AP.                                 |
186  *  | 0x28               | TLS CA Cert not present                                    |
187  *  | 0x29               | TLS PRIVATE key not present.                               |
188  *  | 0x2A               | TLS Client Cert not present.                               |
189  *  | 0x2B               | TLS no Cert present.                                       |
190  *  | 0x2C               | PEAP CA Cert not present.                                  |
191  *  | 0x2D               | Server Cert Invalid Key Type.                              |
192  *  | 0x2E               | Server Intermediate CA Invalid Key Type.                   |
193  *  | 0x2F               | Server Root CA Invalid Key Type.                           |
194  *  | 0x30               | Client Cert Invalid Key Type.                              |
195  *  | 0x31               | Client Root CA Invalid Key Type.                           |
196  *  | 0x37               | Server Cert 4096-bit length support is not enabled.        |
197  *  | 0x38               | Server Intermediate CA 4096-bit length support is not enabled. |
198  *  | 0x39               | Server Root CA 4096-bit length support is not enabled.     |
199  *  | 0x3A               | Client Cert 4096-bit length support is not enabled.        |
200  *  | 0x3B               | Client Root CA 4096-bit length support is not enabled.     |
201  *  | 0x3C               | Server Cert Invalid Sign Alg.                              |
202  *  | 0x3D               | Server Intermediate CA Invalid Sign Alg.                   |
203  *  | 0x3E               | Server Root CA Invalid Sign Length.                        |
204  *  | 0x3F               | Client Cert Invalid Sign Alg.                              |
205  *  | 0x40               | Client Root CA Invalid Sign Length.                        |
206  *  | 0x41               | Server Intermediate CA not Present.                        |
207  *  | 0x42               | Server Root CA Parse Error.                                |
208  *  | 0x43               | Server Intermediate Root CA Parse Error.                   |
209  *  | 0x44               | Sever Cert Parse Error.                                    |
210  *  | 0x45               | Client Cert Parse Error.                                   |
211  *  | 0x46               | Incorrect Private Key Password.                            |
212  *  | 0x47               | EAP Failure Received.                                      |
213  *  | 0x48               | Client Cert Bad Date Error.                                |
214  *  | 0x49               | Server Cert Bad Date Error.                                |
215  *  | 0x4A               | Server Root CA Bad Date Error.                             |
216  *  | 0x4B               | Client Root CA Bad Date Error.                             |
217  *  | 0x4C               | Server Intermediate Root CA Bad Date Error.                |
218  *  | 0x4D               | Pem Header Error.                                          |
219  *  | 0x4E               | Pem Footer Error.                                          |
220  *  | 0x4F               | Client Intermediate CA Invalid Sign Length.                |
221  *  | 0x50               | Client Intermediate CA Invalid Length.                     |
222  *  | 0x52               | Client Intermediate CA invalid Key Type.                   |
223  *  | 0x53               | Pem Error.                                                 |
224  *  | 0x54               | Pathlen certificate is Invalid.                            |
225  *
226  * @note
227  *   In addition to the above, the reason code received in the Deauthentication/Disassociation frame from the AP is modified by setting the most significant bit (MSB) of the reason code.
228  *   If the MSB (Most Significant Bit) is set in the reason code, it should be masked with 0x7F to extract the actual reason code received in the Deauthentication/Disassociation frame.
229  *   Pem Header Error (0x4D) and Pem Footer Error (0x4E) apply only when certificates are loaded individually.
230  *   If certificates are loaded together in a single file, only the Pem Error (0x53) will be triggered for any header or footer errors.
231  * @note
232  *   In case of event failure, the `SL_WIFI_FAIL_EVENT_STATUS_INDICATION` bit is set in the `event` parameter.
233  *   When this bit is set, the `data` parameter will be of type `sl_status_t`, and the `data_length` parameter can be ignored.
234  */
235 typedef sl_status_t (*sl_wifi_stats_callback_t)(sl_wifi_event_t event,
236                                                 void *data,
237                                                 uint32_t data_length,
238                                                 void *optional_arg);
239 
240 /**
241  * @typedef sl_wifi_join_callback_t
242  * @brief Callback for SL_WIFI_JOIN_EVENTS group events of type @ref sl_wifi_event_group_t.
243  *
244  *   This typedef defines a callback function that handles Wi-Fi join events of type @ref sl_wifi_event_t.
245  *   The callback is invoked when a Wi-Fi join event occurs, providing the event details and any associated data.
246  *
247  * @param event
248  *   Wi-Fi event of type @ref sl_wifi_event_t that triggered the callback.
249  * @param data
250  *   Pointer to the response data received (1 byte).
251  *   The possible values and their descriptions are as follows:
252  *   | Data received   | Description                |
253  *   |:----------------|:---------------------------|
254  *   | C               | Module connection success  |
255  *   | F               | Module connection failed   |
256  * @param data_length
257  *   Length of the data received in bytes. This parameter indicates the size of the data buffer pointed to by the `data` parameter.
258  * @param optional_arg
259  *   Optional user provided argument passed in [sl_wifi_set_join_callback](../wiseconnect-api-reference-guide-wi-fi/wifi-callback-framework#sl-wifi-set-join-callback).
260  * @return
261  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
262  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
263  *
264  * @note This is valid in WiFi client mode only
265  * @note
266  *   In case of event failure, the `SL_WIFI_FAIL_EVENT_STATUS_INDICATION` bit is set in the `event` parameter.
267  *   When this bit is set, the `data` parameter will be of type `sl_status_t`, and the `data_length` parameter can be ignored.
268  */
269 typedef sl_status_t (*sl_wifi_join_callback_t)(sl_wifi_event_t event,
270                                                char *data,
271                                                uint32_t data_length,
272                                                void *optional_arg);
273 
274 /**
275  * @typedef sl_wifi_twt_config_callback_t
276  * @brief Callback for SL_WIFI_TWT_RESPONSE_EVENTS group events
277  *
278  *   This typedef defines a callback function that handles Wi-Fi Target Wake Time (TWT) configuration response events.
279  *   The callback is invoked when a TWT response event occurs, providing the event details and any associated data.
280  *
281  * @param event
282  *   Wi-Fi event of type @ref sl_wifi_event_t that triggered the callback.
283  *   Individual Wi-Fi events related to SL_WIFI_TWT_RESPONSE_EVENTS is as follows:
284  *   | @ref sl_wifi_event_t                          | Description                                             |
285  *   |:----------------------------------------------|:--------------------------------------------------------|
286  *   | SL_WIFI_TWT_UNSOLICITED_SESSION_SUCCESS_EVENT | Unsolicited TWT session was successfully established.   |
287  *   | SL_WIFI_TWT_AP_REJECTED_EVENT                 | TWT request was rejected by the Access Point (AP).      |
288  *   | SL_WIFI_TWT_OUT_OF_TOLERANCE_EVENT            | TWT response out of tolerance limits                    |
289  *   | SL_WIFI_TWT_RESPONSE_NOT_MATCHED_EVENT        | TWT response did not match the request.                 |
290  *   | SL_WIFI_TWT_UNSUPPORTED_RESPONSE_EVENT        | TWT response is unsupported.                            |
291  *   | SL_WIFI_TWT_TEARDOWN_SUCCESS_EVENT            | TWT session teardown was successful.                    |
292  *   | SL_WIFI_TWT_AP_TEARDOWN_SUCCESS_EVENT         | AP successfully tore down the TWT session.              |
293  *   | SL_WIFI_TWT_FAIL_MAX_RETRIES_REACHED_EVENT    | Reached maximum number of retries for TWT setup.        |
294  *   | SL_WIFI_TWT_INACTIVE_DUE_TO_ROAMING_EVENT     | TWT session became inactive due to roaming.             |
295  *   | SL_WIFI_TWT_INACTIVE_DUE_TO_DISCONNECT_EVENT  | TWT session became inactive due to disconnection.       |
296  *   | SL_WIFI_TWT_INACTIVE_NO_AP_SUPPORT_EVENT      | Connected AP does not support TWT                       |
297  *   | SL_WIFI_RESCHEDULE_TWT_SUCCESS_EVENT          | TWT session was successfully rescheduled.               |
298  *   | SL_WIFI_TWT_INFO_FRAME_EXCHANGE_FAILED_EVENT  | TWT information frame exchange failed.                  |
299  * @param data
300  *   Pointer to the data received of type [sl_si91x_twt_response_t](../wiseconnect-api-reference-guide-si91x-driver/sl-si91x-twt-response-t).
301  *   This parameter provides detailed information about the TWT response event. The structure contains various fields that describe the TWT session parameters and status.
302  * @param data_length
303  *   Length of the data received in bytes.
304  * @param optional_arg
305  *   Optional user provided argument passed in [sl_wifi_set_twt_config_callback](../wiseconnect-api-reference-guide-wi-fi/wifi-callback-framework#sl-wifi-set-twt-config-callback).
306  * @return
307  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
308  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
309  * @note
310  *   In case of event failure, the `SL_WIFI_FAIL_EVENT_STATUS_INDICATION` bit is set in the `event` parameter.
311  *   When this bit is set, the `data` parameter will be of type `sl_status_t`, and the `data_length` parameter can be ignored.
312  */
313 typedef sl_status_t (*sl_wifi_twt_config_callback_t)(sl_wifi_event_t event,
314                                                      sl_si91x_twt_response_t *data,
315                                                      uint32_t data_length,
316                                                      void *optional_arg);
317 
318 /**
319  * @typedef sl_wifi_transceiver_callback_t
320  * @brief Callback for SL_WIFI_TRANSCEIVER_EVENTS group events
321  *
322  *   This typedef defines a callback function that handles Wi-Fi transceiver events.
323  *   The callback is invoked when a transceiver event occurs, providing the event details and any associated data.
324  *
325  * @param[out] event
326  *   Wi-Fi event of type @ref sl_wifi_event_t. This parameter indicates the specific Wi-Fi event that triggered the callback.
327  *   Individual Wi-Fi events related to SL_WIFI_TRANSCEIVER_EVENTS are as follows:
328  *   | @ref sl_wifi_event_t                   | Description                                                 |
329  *   |:---------------------------------------|:------------------------------------------------------------|
330  *   | SL_WIFI_TRANSCEIVER_RX_DATA_RECEIVE_CB | Indicates that data has been received by the transceiver.   |
331  *   | SL_WIFI_TRANSCEIVER_TX_DATA_STATUS_CB  | Indicates the status of the data sent by the transceiver.   |
332  * @param[out] data
333  *   - Data received is of type @ref sl_wifi_transceiver_rx_data_t for SL_WIFI_TRANSCEIVER_RX_DATA_RECEIVE_CB event.
334  *   - Data received is of type @ref sl_wifi_transceiver_tx_data_confirmation_t for SL_WIFI_TRANSCEIVER_TX_DATA_STATUS_CB event.
335  * @param[out] data_length
336  *   Reserved.
337  * @param[out] optional_arg
338  *   Optional user provided argument passed in [sl_wifi_set_transceiver_callback](../pages/wifi-callback-framework#sl-wifi-set-transceiver-callback)
339  * @return
340  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/4.1/common/api/group-status)
341  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
342  *
343  * @note This API is only supported in Wi-Fi Transceiver opermode (7).
344  * @note
345  *   In case of event failure, the `SL_WIFI_FAIL_EVENT_STATUS_INDICATION` bit is set in the `event` parameter.
346  *   When this bit is set, the `data` parameter will be of type `sl_status_t`, and the `data_length` parameter can be ignored.
347  */
348 typedef sl_status_t (*sl_wifi_transceiver_callback_t)(sl_wifi_event_t event,
349                                                       void *data,
350                                                       uint32_t data_length,
351                                                       void *optional_arg);
352 
353 /***************************************************************************/
354 /**
355  * @brief
356  *   Register a callback for a selected event group. All the individual Wi-Fi events related to specific group would be triggered via this group callback.
357  *
358  *   This function allows the user to register a callback function for a specific group of Wi-Fi events @ref sl_wifi_event_group_t.
359  *   When any event within the specified group occurs, the registered callback function will be invoked, providing the event details and any associated data.
360  *
361  * @param[in] group
362  *   Group ID of the event for which the callback is registered. See @ref sl_wifi_event_group_t for possible values.
363  * @param[in] function
364  *   Function pointer to callback of type @ref sl_wifi_callback_function_t that would be invoked when an event in the specified group occurs.
365  * @param[in] optional_arg
366  *   Optional user provided argument to pass additional context or information to the callback function. This would be passed back to callback handler of type @ref sl_wifi_callback_function_t.
367  * @pre Pre-conditions:
368  * - The Wi-Fi module must be initialized by calling @ref sl_wifi_init before this API can be used.
369  * @return
370  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
371  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
372  * @note
373  *   Callbacks can be set only for event groups defined in @ref sl_wifi_event_group_t, not for individual events defined in @ref sl_wifi_event_t.
374  ******************************************************************************/
375 sl_status_t sl_wifi_set_callback(sl_wifi_event_group_t group, sl_wifi_callback_function_t function, void *optional_arg);
376 
377 /***************************************************************************/ /**
378  * @brief
379  *   Default Wi-Fi event handler to be passed to @ref sl_wifi_init. This event handler would dispatch all the Wi-Fi events and invoke respective Wi-Fi group event.
380  *
381  *   This function serves as the default event handler for Wi-Fi events.
382  *   When passed to the @ref sl_wifi_init function, it would handle incoming Wi-Fi events by dispatching them to the appropriate group event functions.
383  *
384  * @param[in] event
385  * 	 Wi-Fi event of type of @ref sl_wifi_event_t.
386  * @param[in] buffer
387  *  Buffer containing raw data from NWP firmware
388  * @return
389  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
390  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
391  *
392  * @note
393  *   Passing the event handler is optional. User can implement their own event dispatching handler if they prefer.
394  ******************************************************************************/
395 extern sl_status_t sl_wifi_default_event_handler(sl_wifi_event_t event, sl_wifi_buffer_t *buffer);
396 
397 /***************************************************************************/
398 /**
399  * @brief
400  *   Register a callback for the SL_WIFI_SCAN_RESULT_EVENTS group event from @ref sl_wifi_event_group_t.
401  *
402  *   This function allows the user to register a callback function for the SL_WIFI_SCAN_RESULT_EVENTS group.
403  *   When any event within this group occurs, the registered callback function would be invoked, providing the event details and any associated data.
404  *
405  * @param[in] function
406  *   Callback function to register. This parameter specifies the callback function of type @ref sl_wifi_scan_callback_t that would be invoked when an event in the SL_WIFI_SCAN_RESULT_EVENTS group occurs.
407  * @param[in] optional_arg
408  *   Optional user provided argument. This would be passed back to callback handler of type @ref sl_wifi_scan_callback_t.
409  * @pre Pre-conditions:
410  *   - @ref sl_wifi_init should be called before this API.
411  * @return
412  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
413  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
414  * @note
415  *   All the individual Wi-Fi events related to this group would be triggered via this callback.
416  ******************************************************************************/
sl_wifi_set_scan_callback(sl_wifi_scan_callback_t function,void * optional_arg)417 static inline sl_status_t sl_wifi_set_scan_callback(sl_wifi_scan_callback_t function, void *optional_arg)
418 {
419   return sl_wifi_set_callback(SL_WIFI_SCAN_RESULT_EVENTS, (sl_wifi_callback_function_t)function, optional_arg);
420 }
421 
422 /***************************************************************************/
423 /**
424  * @brief
425  *   Register a callback for SL_WIFI_JOIN_EVENTS group event from @ref sl_wifi_event_group_t.
426  *
427  *   This function allows the user to register a callback function for the SL_WIFI_JOIN_EVENTS group.
428  *   When any event within this group occurs, the registered callback function would be invoked, providing the event details and any associated data.
429  *
430  * @param[in] function
431  *   Function pointer to callback of type @ref 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.
432  * @param[in] optional_arg
433  *   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 @ref sl_wifi_twt_config_callback_t.
434  * @pre Pre-conditions:
435  *   @ref sl_wifi_init should be called before this API.
436  * @return
437  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
438  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
439  * @note
440  *   All the individual Wi-Fi events related to this group will be triggered via this callback.
441  ******************************************************************************/
sl_wifi_set_join_callback(sl_wifi_join_callback_t function,void * optional_arg)442 static inline sl_status_t sl_wifi_set_join_callback(sl_wifi_join_callback_t function, void *optional_arg)
443 {
444   return sl_wifi_set_callback(SL_WIFI_JOIN_EVENTS, (sl_wifi_callback_function_t)function, optional_arg);
445 }
446 
447 /***************************************************************************/
448 /**
449  * @brief
450  *   Register a callback for SL_WIFI_TWT_RESPONSE_EVENTS group event from @ref sl_wifi_event_group_t.
451  *
452  *   This function allows the user to register a callback function for the SL_WIFI_TWT_RESPONSE_EVENTS group.
453  *   When any event within this group occurs, the registered callback function will be invoked, providing the event details and any associated data.
454  *
455  * @param[in] function
456  *   Function pointer to the callback of type @ref 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.
457  * @param[in] optional_arg
458  *   Optional user provided argument. This would be passed back to callback handler.
459  * @pre Pre-conditions:
460  *   @ref sl_wifi_init should be called before this API.
461  * @return
462  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
463  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
464  * @note
465  *   All the individual Wi-Fi events related to this group would be triggered via this callback.
466  ******************************************************************************/
sl_wifi_set_twt_config_callback(sl_wifi_twt_config_callback_t function,void * optional_arg)467 static inline sl_status_t sl_wifi_set_twt_config_callback(sl_wifi_twt_config_callback_t function, void *optional_arg)
468 {
469   return sl_wifi_set_callback(SL_WIFI_TWT_RESPONSE_EVENTS, (sl_wifi_callback_function_t)function, optional_arg);
470 }
471 
472 /***************************************************************************/
473 /**
474  * @brief
475  *   Register a callback for SL_WIFI_STATS_RESPONSE_EVENTS group event from @ref sl_wifi_event_group_t.
476  *
477  *   This function allows the user to register a callback function for the SL_WIFI_STATS_RESPONSE_EVENTS group.
478  *   When any event within this group occurs, the registered callback function would be invoked, providing the event details and any associated data.
479  *
480  * @param[in] function
481  *   Function pointer to the callback of type @ref 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.
482  * @param[in] optional_arg
483  *   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.
484  * @pre Pre-conditions:
485  *   @ref sl_wifi_init should be called before this API.
486  * @return
487  *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/latest/platform-common/status)
488  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
489  * @note
490  *   All the individual Wi-Fi events related to this group would be triggered via this callback.
491  ******************************************************************************/
sl_wifi_set_stats_callback(sl_wifi_stats_callback_t function,void * optional_arg)492 static inline sl_status_t sl_wifi_set_stats_callback(sl_wifi_stats_callback_t function, void *optional_arg)
493 {
494   return sl_wifi_set_callback(SL_WIFI_STATS_RESPONSE_EVENTS, (sl_wifi_callback_function_t)function, optional_arg);
495 }
496 
497 /***************************************************************************/ /**
498  * @brief
499  *   Register a callback for SL_WIFI_TRANSCEIVER_EVENTS group event of tye @ref sl_wifi_event_group_t.
500  *
501  *   This function allows the user to register a callback function for the SL_WIFI_TRANSCEIVER_EVENTS group.
502  *   When any event within this group occurs, the registered callback function would be invoked, providing the event details and any associated data.
503  *
504  * @param[in] function
505  *   Function pointer to the callback of type @ref 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.
506  * @param[in] optional_arg
507  *   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.
508  * @pre Pre-conditions:
509  * - @ref sl_wifi_init should be called before this API.
510  * @return
511 *   sl_status_t. See [Status Codes](https://docs.silabs.com/gecko-platform/4.1/common/api/group-status)
512  *   and [Additional Status Codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) for details.
513  * @note
514  *   All the individual Wi-Fi events related to this group will be triggered via this callback.
515  ******************************************************************************/
sl_wifi_set_transceiver_callback(sl_wifi_transceiver_callback_t function,void * optional_arg)516 static inline sl_status_t sl_wifi_set_transceiver_callback(sl_wifi_transceiver_callback_t function, void *optional_arg)
517 {
518   return sl_wifi_set_callback(SL_WIFI_TRANSCEIVER_EVENTS, (sl_wifi_callback_function_t)function, optional_arg);
519 }
520 
521 /** @} */
522