xref: /wlan-dirver/qca-wifi-host-cmn/os_if/linux/mlme/inc/osif_cm_util.h (revision 93830f424d9ddc2ed54b338975b4f4fb38ca46e6)
1 /*
2  * Copyright (c) 2012-2015, 2020-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /**
19  * DOC: osif_cm_util.h
20  *
21  * This header file maintains declarations of connect, disconnect, roam
22  * common apis.
23  */
24 
25 #ifndef __OSIF_CM_UTIL_H
26 #define __OSIF_CM_UTIL_H
27 
28 #include <qca_vendor.h>
29 #include "wlan_cm_ucfg_api.h"
30 #include "wlan_cm_public_struct.h"
31 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
32 #include "wlan_cm_roam_public_struct.h"
33 #endif
34 #ifdef CONN_MGR_ADV_FEATURE
35 #include <cdp_txrx_mob_def.h>
36 #endif
37 
38 /**
39  * osif_cm_mac_to_qca_connect_fail_reason() - Convert to qca internal connect
40  * fail reason
41  * @internal_reason: Mac reason code of type @wlan_status_code
42  *
43  * Check if it is internal status code and convert it to the
44  * enum qca_sta_connect_fail_reason_codes.
45  *
46  * Return: Reason code of type enum qca_sta_connect_fail_reason_codes
47  */
48 enum qca_sta_connect_fail_reason_codes
49 osif_cm_mac_to_qca_connect_fail_reason(enum wlan_status_code internal_reason);
50 
51 /**
52  * osif_cm_qca_reason_to_str() - return string conversion of qca reason code
53  * @reason: enum qca_disconnect_reason_codes
54  *
55  * This utility function helps log string conversion of qca reason code.
56  *
57  * Return: string conversion of reason code, if match found;
58  *         "Unknown" otherwise.
59  */
60 const char *
61 osif_cm_qca_reason_to_str(enum qca_disconnect_reason_codes reason);
62 
63 /**
64  * osif_cm_mac_to_qca_reason() - Convert to qca internal disconnect reason
65  * @internal_reason: Mac reason code of type @wlan_reason_code
66  *
67  * Check if it is internal reason code and convert it to the
68  * enum qca_disconnect_reason_codes.
69  *
70  * Return: Reason code of type enum qca_disconnect_reason_codes
71  */
72 enum qca_disconnect_reason_codes
73 osif_cm_mac_to_qca_reason(enum wlan_reason_code internal_reason);
74 
75 /**
76  * osif_cm_register_cb() - API to register connection manager
77  * callbacks.
78  *
79  * Return: QDF_STATUS
80  */
81 QDF_STATUS osif_cm_register_cb(void);
82 
83 /**
84  * osif_cm_osif_priv_init() - API to init osif priv data for connection manager
85  * @vdev: vdev pointer
86  *
87  * Return: QDF_STATUS
88  */
89 QDF_STATUS osif_cm_osif_priv_init(struct wlan_objmgr_vdev *vdev);
90 
91 /**
92  * osif_cm_osif_priv_deinit() - API to deinit osif priv data for connection
93  * manager
94  * @vdev: vdev pointer
95  *
96  * Return: QDF_STATUS
97  */
98 QDF_STATUS osif_cm_osif_priv_deinit(struct wlan_objmgr_vdev *vdev);
99 
100 /**
101  * osif_cm_reset_id_and_src_no_lock() - Function to resets last
102  * connection manager command id and source in osif
103  * @osif_priv: Pointer to vdev osif priv
104  *
105  * This function resets the last connection manager command id
106  * and source.
107  *
108  * Context: Any context. This function should be called by holding
109  * cmd id spinlock
110  * Return: None
111  */
112 
113 void osif_cm_reset_id_and_src_no_lock(struct vdev_osif_priv *osif_priv);
114 
115 /**
116  * osif_cm_reset_id_and_src() - Function to resets last
117  * connection manager command id and source in osif
118  * @vdev: vdev pointer
119  *
120  * This function resets the last connection manager command id
121  * and source.
122  *
123  * Context: Any context. Takes and release cmd id spinlock
124  * Return: None
125  */
126 QDF_STATUS osif_cm_reset_id_and_src(struct wlan_objmgr_vdev *vdev);
127 
128 /**
129  * enum osif_cb_type - Type of the update from osif to legacy module
130  * @OSIF_POST_USERSPACE_UPDATE: Indicates that when this update is received
131  * userspace is already updated.
132  * @OSIF_PRE_USERSPACE_UPDATE: Indicates that when this update is received
133  * userspace is not yet updated.
134  * @OSIF_NOT_HANDLED: Indicates that last command is not handled
135  */
136 
137 enum osif_cb_type {
138 	OSIF_POST_USERSPACE_UPDATE,
139 	OSIF_PRE_USERSPACE_UPDATE,
140 	OSIF_NOT_HANDLED,
141 };
142 
143 /**
144  * typedef osif_cm_connect_comp_cb  - Connect complete callback
145  * @vdev: vdev pointer
146  * @rsp: connect response
147  * @type: indicates update type
148  *
149  * This callback indicates connect complete to the legacy module
150  *
151  * Context: Any context.
152  * Return: QDF_STATUS
153  */
154 typedef QDF_STATUS
155 	(*osif_cm_connect_comp_cb)(struct wlan_objmgr_vdev *vdev,
156 				   struct wlan_cm_connect_resp *rsp,
157 				   enum osif_cb_type type);
158 
159 #ifdef WLAN_VENDOR_HANDOFF_CONTROL
160 /**
161  * typedef osif_cm_get_vendor_handoff_params_cb  - process vendor handoff cb
162  * @psoc: psoc pointer
163  * @rsp: vendor handoff response
164  * @vendor_handoff_context: vendor handoff context
165  *
166  * return: none
167  */
168 typedef QDF_STATUS
169 (*osif_cm_get_vendor_handoff_params_cb)(struct wlan_objmgr_psoc *psoc,
170 					void *vendor_handoff_context);
171 #endif
172 
173 #ifdef WLAN_FEATURE_FILS_SK
174 /**
175  * typedef osif_cm_save_gtk_cb  - save gtk callback
176  * @vdev: vdev pointer
177  * @rsp: connect response
178  *
179  * this callback save gtk to the legacy module
180  *
181  * context: any context.
182  * return: qdf_status
183  */
184 typedef QDF_STATUS (*osif_cm_save_gtk_cb)(struct wlan_objmgr_vdev *vdev,
185 					  struct wlan_cm_connect_resp *rsp);
186 
187 /**
188  * typedef osif_cm_set_hlp_data_cb  - set hlp data for dhcp callback
189  * @dev: pointer to net device
190  * @vdev: vdev pointer
191  * @rsp: connect response
192  *
193  * this callback sets hlp data for dhcp to the legacy module
194  *
195  * context: any context.
196  * return: qdf_status
197  */
198 typedef QDF_STATUS (*osif_cm_set_hlp_data_cb)(struct net_device *dev,
199 					      struct wlan_objmgr_vdev *vdev,
200 					      struct wlan_cm_connect_resp *rsp);
201 #endif
202 
203 /**
204  * typedef  osif_cm_disconnect_comp_cb: Disconnect complete callback
205  * @vdev: vdev pointer
206  * @rsp: disconnect response
207  * @type: indicates update type
208  *
209  * This callback indicates disconnect complete to the legacy module
210  *
211  * Context: Any context.
212  * Return: QDF_STATUS
213  */
214 typedef QDF_STATUS
215 	(*osif_cm_disconnect_comp_cb)(struct wlan_objmgr_vdev *vdev,
216 				      struct wlan_cm_discon_rsp *rsp,
217 				      enum osif_cb_type type);
218 
219 #ifdef CONN_MGR_ADV_FEATURE
220 /**
221  * typedef osif_cm_get_scan_ie_params_cb  - get scan ie params cb
222  * @vdev: vdev pointer
223  * @scan_ie: pointer to scan ie element struct
224  * @dot11mode_filter: Pointer to dot11mode_filter enum
225  *
226  * Return: QDF_STATUS
227  */
228 typedef QDF_STATUS
229 (*osif_cm_get_scan_ie_params_cb)(struct wlan_objmgr_vdev *vdev,
230 				 struct element_info *scan_ie,
231 				 enum dot11_mode_filter *dot11mode_filter);
232 
233 /**
234  * typedef osif_cm_netif_queue_ctrl_cb: Callback to update netif queue
235  * @vdev: vdev pointer
236  * @action: Action to take on netif queue
237  * @reason: netif reason type
238  *
239  * This callback indicates legacy modules to take the actions related to netif
240  * queue
241  *
242  * Context: Any context.
243  * Return: QDF_STATUS
244  */
245 typedef QDF_STATUS
246 	(*osif_cm_netif_queue_ctrl_cb)(struct wlan_objmgr_vdev *vdev,
247 				       enum netif_action_type action,
248 				       enum netif_reason_type reason);
249 
250 /**
251  * typedef os_if_cm_napi_serialize_ctrl_cb: Callback to update
252  * NAPI serialization
253  * @action: bool action to take on napi serialization
254  *
255  * This callback indicates legacy modules to take the actions
256  * related to napi serialization
257  *
258  * Context: Any context.
259  * Return: QDF_STATUS
260  */
261 typedef QDF_STATUS
262 	(*os_if_cm_napi_serialize_ctrl_cb)(bool action);
263 
264 /**
265  * typedef osif_cm_send_vdev_keys_cb  - send vdev keys cb
266  * @vdev: vdev pointer
267  * @key_index: key index value
268  * @pairwise: pairwise boolean value
269  * @cipher_type: cipher type enum value
270  *
271  * return: none
272  */
273 typedef QDF_STATUS
274 (*osif_cm_send_vdev_keys_cb)(struct wlan_objmgr_vdev *vdev,
275 			     uint8_t key_index,
276 			     bool pairwise,
277 			     enum wlan_crypto_cipher_type cipher_type);
278 
279 /**
280  * osif_cm_unlink_bss() - function to unlink bss from kernel and scan database
281  * on connect timeouts reasons
282  * @vdev: vdev pointer
283  * @bssid: bssid to flush
284  *
285  * This function flush the bss from scan db of kernel and driver matching the
286  * bssid.
287  *
288  * Return: void
289  */
290 void osif_cm_unlink_bss(struct wlan_objmgr_vdev *vdev,
291 			struct qdf_mac_addr *bssid);
292 #else
293 static inline
294 void osif_cm_unlink_bss(struct wlan_objmgr_vdev *vdev,
295 			struct qdf_mac_addr *bssid) {}
296 #endif
297 
298 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
299 /**
300  * typedef osif_cm_roam_rt_stats_cb: Callback to send roam
301  * stats event
302  * @roam_stats: roam_stats_event pointer
303  * @idx: TLV idx for roam stats event
304  *
305  * This callback sends roam_stats_event to userspace
306  *
307  * Context: Any context.
308  * Return: void
309  */
310 typedef void
311 	(*osif_cm_roam_rt_stats_cb)(struct roam_stats_event *roam_stats,
312 				    uint8_t idx);
313 #endif
314 
315 #ifdef WLAN_FEATURE_PREAUTH_ENABLE
316 /**
317  * typedef osif_cm_ft_preauth_complete_cb: Callback to send fast
318  * transition event
319  * @vdev: vdev pointer
320  * @rsp: preauth response pointer
321  *
322  * This callback indicates legacy modules to send fast transition event
323  *
324  * Context: Any context.
325  * Return: QDF_STATUS
326  */
327 typedef QDF_STATUS
328 	(*osif_cm_ft_preauth_complete_cb)(struct wlan_objmgr_vdev *vdev,
329 					  struct wlan_preauth_rsp *rsp);
330 #ifdef FEATURE_WLAN_ESE
331 /**
332  * typedef osif_cm_cckm_preauth_complete_cb: Callback to send cckm preauth
333  * indication to the supplicant via wireless custom event
334  * @vdev: vdev pointer
335  * @rsp: preauth response pointer
336  *
337  * This callback indicates legacy modules to send cckm preauth indication
338  * to the supplicant via wireless custom event
339  *
340  * Context: Any context.
341  * Return: QDF_STATUS
342  */
343 typedef QDF_STATUS
344 	(*osif_cm_cckm_preauth_complete_cb)(struct wlan_objmgr_vdev *vdev,
345 					    struct wlan_preauth_rsp *rsp);
346 #endif
347 #endif
348 
349 #ifdef WLAN_BOOST_CPU_FREQ_IN_ROAM
350 /**
351  * typedef os_if_cm_perfd_set_cpufreq_ctrl_cb: Callback to update
352  * CPU min freq
353  * @action: bool action to set or reset the CPU freq
354  *
355  * This callback indicates legacy modules to take the actions
356  * related to set/reset CPU freq
357  *
358  * Context: Any context.
359  * Return: QDF_STATUS
360  */
361 typedef QDF_STATUS
362 	(*os_if_cm_perfd_set_cpufreq_ctrl_cb)(bool action);
363 #endif
364 
365 /**
366  * struct osif_cm_ops - connection manager legacy callbacks
367  * @connect_complete_cb: callback for connect complete to legacy
368  * modules
369  * @disconnect_complete_cb: callback for disconnect complete to
370  * legacy modules
371  * @netif_queue_control_cb: callback to legacy module to take
372  * actions on netif queue
373  * @napi_serialize_control_cb: callback to legacy module to take
374  * actions on napi serialization
375  * @save_gtk_cb : callback to legacy module to save gtk
376  * @send_vdev_keys_cb: callback to send vdev keys
377  * @get_scan_ie_params_cb: callback to get scan ie params
378  * @set_hlp_data_cb: callback to legacy module to save hlp data
379  * @roam_rt_stats_event_cb: callback to send roam stats to userspace
380  * @ft_preauth_complete_cb: callback to legacy module to send fast
381  * transition event
382  * @cckm_preauth_complete_cb: callback to legacy module to send cckm
383  * preauth indication to the supplicant via wireless custom event.
384  * @vendor_handoff_params_cb: callback to legacy module to send vendor handoff
385  * parameters to upper layer
386  * @perfd_set_cpufreq_cb: callback to update CPU min freq
387  */
388 struct osif_cm_ops {
389 	osif_cm_connect_comp_cb connect_complete_cb;
390 	osif_cm_disconnect_comp_cb disconnect_complete_cb;
391 #ifdef CONN_MGR_ADV_FEATURE
392 	osif_cm_netif_queue_ctrl_cb netif_queue_control_cb;
393 	os_if_cm_napi_serialize_ctrl_cb napi_serialize_control_cb;
394 	osif_cm_save_gtk_cb save_gtk_cb;
395 	osif_cm_send_vdev_keys_cb send_vdev_keys_cb;
396 	osif_cm_get_scan_ie_params_cb get_scan_ie_params_cb;
397 #endif
398 #ifdef WLAN_FEATURE_FILS_SK
399 	osif_cm_set_hlp_data_cb set_hlp_data_cb;
400 #endif
401 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
402 	osif_cm_roam_rt_stats_cb roam_rt_stats_event_cb;
403 #endif
404 #ifdef WLAN_FEATURE_PREAUTH_ENABLE
405 	osif_cm_ft_preauth_complete_cb ft_preauth_complete_cb;
406 #ifdef FEATURE_WLAN_ESE
407 	osif_cm_cckm_preauth_complete_cb cckm_preauth_complete_cb;
408 #endif
409 #endif
410 #ifdef WLAN_VENDOR_HANDOFF_CONTROL
411 	osif_cm_get_vendor_handoff_params_cb vendor_handoff_params_cb;
412 #endif
413 #ifdef WLAN_BOOST_CPU_FREQ_IN_ROAM
414 	os_if_cm_perfd_set_cpufreq_ctrl_cb perfd_set_cpufreq_cb;
415 #endif
416 };
417 
418 /**
419  * osif_cm_connect_comp_ind() - Function to indicate connect
420  * complete to legacy module
421  * @vdev: vdev pointer
422  * @rsp: connect response
423  * @type: indicates update type
424  *
425  * This function indicates connect complete to the legacy module
426  *
427  * Context: Any context.
428  * Return: QDF_STATUS
429  */
430 QDF_STATUS osif_cm_connect_comp_ind(struct wlan_objmgr_vdev *vdev,
431 				    struct wlan_cm_connect_resp *rsp,
432 				    enum osif_cb_type type);
433 
434 #ifdef WLAN_VENDOR_HANDOFF_CONTROL
435 /**
436  * osif_cm_vendor_handoff_params_cb() - Function to process vendor handoff
437  * event callback
438  * @psoc: psoc object pointer
439  * @vendor_handoff_context: vendor handoff context
440  *
441  * Return: QDF_STATUS
442  */
443 QDF_STATUS osif_cm_vendor_handoff_params_cb(struct wlan_objmgr_psoc *psoc,
444 					    void *vendor_handoff_context);
445 #endif
446 
447 /**
448  * osif_cm_disconnect_comp_ind() - Function to indicate disconnect
449  * complete to legacy module
450  * @vdev: vdev pointer
451  * @rsp: disconnect response
452  * @type: indicates update type
453  *
454  * This function indicates disconnect complete to the legacy module
455  *
456  * Context: Any context.
457  * Return: QDF_STATUS
458  */
459 QDF_STATUS osif_cm_disconnect_comp_ind(struct wlan_objmgr_vdev *vdev,
460 				       struct wlan_cm_discon_rsp *rsp,
461 				       enum osif_cb_type type);
462 
463 #ifdef CONN_MGR_ADV_FEATURE
464 /**
465  * osif_cm_netif_queue_ind() - Function to indicate netif queue update
466  * complete to legacy module
467  * @vdev: vdev pointer
468  * @action: Action to take on netif queue
469  * @reason: netif reason type
470  *
471  * This function indicates to take the actions related to netif queue
472  *
473  * Context: Any context.
474  * Return: QDF_STATUS
475  */
476 QDF_STATUS osif_cm_netif_queue_ind(struct wlan_objmgr_vdev *vdev,
477 				   enum netif_action_type action,
478 				   enum netif_reason_type reason);
479 
480 /**
481  * osif_cm_napi_serialize() - Function to indicate napi serialize
482  * action to legacy module
483  * @action: Action to take on napi serialization
484  *
485  * This function indicates to take the actions related to napi activities
486  *
487  * Context: Any context.
488  * Return: QDF_STATUS
489  */
490 QDF_STATUS osif_cm_napi_serialize(bool action);
491 
492 /**
493  * osif_cm_save_gtk() - Function to save gtk in legacy module
494  * @vdev: vdev pointer
495  * @rsp: Pointer to connect response
496  *
497  * This function saves gtk in legacy module
498  *
499  * Context: Any context.
500  * Return: QDF_STATUS
501  */
502 QDF_STATUS osif_cm_save_gtk(struct wlan_objmgr_vdev *vdev,
503 			    struct wlan_cm_connect_resp *rsp);
504 
505 /**
506  * osif_cm_send_vdev_keys() - Function to send vdev keys
507  * @vdev: vdev pointer
508  * @key_index: key index value
509  * @pairwise: pairwise bool value
510  * @cipher_type: cipher type value
511  *
512  * This function to send vdev keys
513  *
514  * Context: Any context.
515  * Return: QDF_STATUS
516  */
517 QDF_STATUS
518 osif_cm_send_vdev_keys(struct wlan_objmgr_vdev *vdev,
519 		       uint8_t key_index,
520 		       bool pairwise,
521 		       enum wlan_crypto_cipher_type cipher_type);
522 #else
523 static inline QDF_STATUS osif_cm_save_gtk(struct wlan_objmgr_vdev *vdev,
524 					  struct wlan_cm_connect_resp *rsp)
525 {
526 	return QDF_STATUS_SUCCESS;
527 }
528 #endif
529 
530 #ifdef WLAN_FEATURE_FILS_SK
531 /**
532  * osif_cm_set_hlp_data() - Function to set hlp data for dhcp in legacy module
533  * @dev: Pointer to net device
534  * @vdev: vdev pointer
535  * @rsp: Pointer to connect response
536  *
537  * This function sets hlp data for dhcp in legacy module
538  *
539  * Context: Any context.
540  * Return: QDF_STATUS
541  */
542 QDF_STATUS osif_cm_set_hlp_data(struct net_device *dev,
543 				struct wlan_objmgr_vdev *vdev,
544 				struct wlan_cm_connect_resp *rsp);
545 #else
546 static inline QDF_STATUS osif_cm_set_hlp_data(struct net_device *dev,
547 					      struct wlan_objmgr_vdev *vdev,
548 					      struct wlan_cm_connect_resp *rsp)
549 {
550 	return QDF_STATUS_SUCCESS;
551 }
552 #endif
553 
554 /**
555  * osif_cm_set_legacy_cb() - Sets legacy callbacks to osif
556  * @osif_legacy_ops:  Function pointer to legacy ops structure
557  *
558  * API to set legacy callbacks to osif
559  * Context: Any context.
560  *
561  * Return: void
562  */
563 void osif_cm_set_legacy_cb(struct osif_cm_ops *osif_legacy_ops);
564 
565 /**
566  * osif_cm_reset_legacy_cb() - Resets legacy callbacks to osif
567  *
568  * API to reset legacy callbacks to osif
569  * Context: Any context.
570  *
571  * Return: void
572  */
573 void osif_cm_reset_legacy_cb(void);
574 
575 #ifdef WLAN_BOOST_CPU_FREQ_IN_ROAM
576 /**
577  * osif_cm_perfd_set_cpufreq() - Function to CPU min freq
578  * action to legacy module
579  * @action: Action to set or reset the CPU freq
580  *
581  * This function indicates to take the actions related to set/reset the CPU freq
582  *
583  * Context: Any context.
584  * Return: QDF_STATUS
585  */
586 QDF_STATUS osif_cm_perfd_set_cpufreq(bool action);
587 #else
588 static inline
589 QDF_STATUS osif_cm_perfd_set_cpufreq(bool action)
590 {
591 	return QDF_STATUS_SUCCESS;
592 }
593 #endif
594 
595 #endif /* __OSIF_CM_UTIL_H */
596