xref: /wlan-driver/qca-wifi-host-cmn/os_if/linux/mlme/inc/osif_cm_util.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2012-2015, 2020-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2024 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 #ifdef CONN_MGR_ADV_FEATURE
144 typedef void (*osif_cm_connect_active_notify_cb)(uint8_t vdev_id);
145 #endif
146 
147 /**
148  * typedef osif_cm_connect_comp_cb  - Connect complete callback
149  * @vdev: vdev pointer
150  * @rsp: connect response
151  * @type: indicates update type
152  *
153  * This callback indicates connect complete to the legacy module
154  *
155  * Context: Any context.
156  * Return: QDF_STATUS
157  */
158 typedef QDF_STATUS
159 	(*osif_cm_connect_comp_cb)(struct wlan_objmgr_vdev *vdev,
160 				   struct wlan_cm_connect_resp *rsp,
161 				   enum osif_cb_type type);
162 
163 #ifdef WLAN_VENDOR_HANDOFF_CONTROL
164 /**
165  * typedef osif_cm_get_vendor_handoff_params_cb  - process vendor handoff cb
166  * @psoc: psoc pointer
167  * @rsp: vendor handoff response
168  * @vendor_handoff_context: vendor handoff context
169  *
170  * return: none
171  */
172 typedef QDF_STATUS
173 (*osif_cm_get_vendor_handoff_params_cb)(struct wlan_objmgr_psoc *psoc,
174 					void *vendor_handoff_context);
175 #endif
176 
177 #ifdef WLAN_FEATURE_FILS_SK
178 /**
179  * typedef osif_cm_save_gtk_cb  - save gtk callback
180  * @vdev: vdev pointer
181  * @rsp: connect response
182  *
183  * this callback save gtk to the legacy module
184  *
185  * context: any context.
186  * return: qdf_status
187  */
188 typedef QDF_STATUS (*osif_cm_save_gtk_cb)(struct wlan_objmgr_vdev *vdev,
189 					  struct wlan_cm_connect_resp *rsp);
190 
191 /**
192  * typedef osif_cm_set_hlp_data_cb  - set hlp data for dhcp callback
193  * @dev: pointer to net device
194  * @vdev: vdev pointer
195  * @rsp: connect response
196  *
197  * this callback sets hlp data for dhcp to the legacy module
198  *
199  * context: any context.
200  * return: qdf_status
201  */
202 typedef QDF_STATUS (*osif_cm_set_hlp_data_cb)(struct net_device *dev,
203 					      struct wlan_objmgr_vdev *vdev,
204 					      struct wlan_cm_connect_resp *rsp);
205 #endif
206 
207 /**
208  * typedef  osif_cm_disconnect_comp_cb: Disconnect complete callback
209  * @vdev: vdev pointer
210  * @rsp: disconnect response
211  * @type: indicates update type
212  *
213  * This callback indicates disconnect complete to the legacy module
214  *
215  * Context: Any context.
216  * Return: QDF_STATUS
217  */
218 typedef QDF_STATUS
219 	(*osif_cm_disconnect_comp_cb)(struct wlan_objmgr_vdev *vdev,
220 				      struct wlan_cm_discon_rsp *rsp,
221 				      enum osif_cb_type type);
222 
223 #ifdef CONN_MGR_ADV_FEATURE
224 /**
225  * typedef osif_cm_get_scan_ie_params_cb  - get scan ie params cb
226  * @vdev: vdev pointer
227  * @scan_ie: pointer to scan ie element struct
228  * @dot11mode_filter: Pointer to dot11mode_filter enum
229  *
230  * Return: QDF_STATUS
231  */
232 typedef QDF_STATUS
233 (*osif_cm_get_scan_ie_params_cb)(struct wlan_objmgr_vdev *vdev,
234 				 struct element_info *scan_ie,
235 				 enum dot11_mode_filter *dot11mode_filter);
236 
237 /**
238  * typedef osif_cm_netif_queue_ctrl_cb: Callback to update netif queue
239  * @vdev: vdev pointer
240  * @action: Action to take on netif queue
241  * @reason: netif reason type
242  *
243  * This callback indicates legacy modules to take the actions related to netif
244  * queue
245  *
246  * Context: Any context.
247  * Return: QDF_STATUS
248  */
249 typedef QDF_STATUS
250 	(*osif_cm_netif_queue_ctrl_cb)(struct wlan_objmgr_vdev *vdev,
251 				       enum netif_action_type action,
252 				       enum netif_reason_type reason);
253 
254 /**
255  * typedef os_if_cm_napi_serialize_ctrl_cb: Callback to update
256  * NAPI serialization
257  * @action: bool action to take on napi serialization
258  *
259  * This callback indicates legacy modules to take the actions
260  * related to napi serialization
261  *
262  * Context: Any context.
263  * Return: QDF_STATUS
264  */
265 typedef QDF_STATUS
266 	(*os_if_cm_napi_serialize_ctrl_cb)(bool action);
267 
268 /**
269  * typedef osif_cm_send_vdev_keys_cb  - send vdev keys cb
270  * @vdev: vdev pointer
271  * @key_index: key index value
272  * @pairwise: pairwise boolean value
273  * @cipher_type: cipher type enum value
274  *
275  * return: none
276  */
277 typedef QDF_STATUS
278 (*osif_cm_send_vdev_keys_cb)(struct wlan_objmgr_vdev *vdev,
279 			     uint8_t key_index,
280 			     bool pairwise,
281 			     enum wlan_crypto_cipher_type cipher_type);
282 
283 /**
284  * osif_cm_unlink_bss() - function to unlink bss from kernel and scan database
285  * on connect timeouts reasons
286  * @vdev: vdev pointer
287  * @bssid: bssid to flush
288  *
289  * This function flush the bss from scan db of kernel and driver matching the
290  * bssid.
291  *
292  * Return: void
293  */
294 void osif_cm_unlink_bss(struct wlan_objmgr_vdev *vdev,
295 			struct qdf_mac_addr *bssid);
296 #else
297 static inline
osif_cm_unlink_bss(struct wlan_objmgr_vdev * vdev,struct qdf_mac_addr * bssid)298 void osif_cm_unlink_bss(struct wlan_objmgr_vdev *vdev,
299 			struct qdf_mac_addr *bssid) {}
300 #endif
301 
302 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
303 /**
304  * typedef osif_cm_roam_rt_stats_cb: Callback to send roam
305  * stats event
306  * @roam_stats: roam_stats_event pointer
307  * @idx: TLV idx for roam stats event
308  *
309  * This callback sends roam_stats_event to userspace
310  *
311  * Context: Any context.
312  * Return: void
313  */
314 typedef void
315 	(*osif_cm_roam_rt_stats_cb)(struct roam_stats_event *roam_stats,
316 				    uint8_t idx);
317 #endif
318 
319 #ifdef WLAN_FEATURE_PREAUTH_ENABLE
320 /**
321  * typedef osif_cm_ft_preauth_complete_cb: Callback to send fast
322  * transition event
323  * @vdev: vdev pointer
324  * @rsp: preauth response pointer
325  *
326  * This callback indicates legacy modules to send fast transition event
327  *
328  * Context: Any context.
329  * Return: QDF_STATUS
330  */
331 typedef QDF_STATUS
332 	(*osif_cm_ft_preauth_complete_cb)(struct wlan_objmgr_vdev *vdev,
333 					  struct wlan_preauth_rsp *rsp);
334 #ifdef FEATURE_WLAN_ESE
335 /**
336  * typedef osif_cm_cckm_preauth_complete_cb: Callback to send cckm preauth
337  * indication to the supplicant via wireless custom event
338  * @vdev: vdev pointer
339  * @rsp: preauth response pointer
340  *
341  * This callback indicates legacy modules to send cckm preauth indication
342  * to the supplicant via wireless custom event
343  *
344  * Context: Any context.
345  * Return: QDF_STATUS
346  */
347 typedef QDF_STATUS
348 	(*osif_cm_cckm_preauth_complete_cb)(struct wlan_objmgr_vdev *vdev,
349 					    struct wlan_preauth_rsp *rsp);
350 #endif
351 #endif
352 
353 #ifdef WLAN_BOOST_CPU_FREQ_IN_ROAM
354 /**
355  * typedef os_if_cm_perfd_set_cpufreq_ctrl_cb: Callback to update
356  * CPU min freq
357  * @action: bool action to set or reset the CPU freq
358  *
359  * This callback indicates legacy modules to take the actions
360  * related to set/reset CPU freq
361  *
362  * Context: Any context.
363  * Return: QDF_STATUS
364  */
365 typedef QDF_STATUS
366 	(*os_if_cm_perfd_set_cpufreq_ctrl_cb)(bool action);
367 #endif
368 
369 /**
370  * struct osif_cm_ops - connection manager legacy callbacks
371  * @connect_active_notify_cb: callback for connect active to legacy modules
372  * @connect_complete_cb: callback for connect complete to legacy
373  * modules
374  * @disconnect_complete_cb: callback for disconnect complete to
375  * legacy modules
376  * @netif_queue_control_cb: callback to legacy module to take
377  * actions on netif queue
378  * @napi_serialize_control_cb: callback to legacy module to take
379  * actions on napi serialization
380  * @save_gtk_cb : callback to legacy module to save gtk
381  * @send_vdev_keys_cb: callback to send vdev keys
382  * @get_scan_ie_params_cb: callback to get scan ie params
383  * @set_hlp_data_cb: callback to legacy module to save hlp data
384  * @roam_rt_stats_event_cb: callback to send roam stats to userspace
385  * @ft_preauth_complete_cb: callback to legacy module to send fast
386  * transition event
387  * @cckm_preauth_complete_cb: callback to legacy module to send cckm
388  * preauth indication to the supplicant via wireless custom event.
389  * @vendor_handoff_params_cb: callback to legacy module to send vendor handoff
390  * parameters to upper layer
391  * @perfd_set_cpufreq_cb: callback to update CPU min freq
392  */
393 struct osif_cm_ops {
394 #ifdef CONN_MGR_ADV_FEATURE
395 	osif_cm_connect_active_notify_cb connect_active_notify_cb;
396 #endif
397 	osif_cm_connect_comp_cb connect_complete_cb;
398 	osif_cm_disconnect_comp_cb disconnect_complete_cb;
399 #ifdef CONN_MGR_ADV_FEATURE
400 	osif_cm_netif_queue_ctrl_cb netif_queue_control_cb;
401 	os_if_cm_napi_serialize_ctrl_cb napi_serialize_control_cb;
402 	osif_cm_save_gtk_cb save_gtk_cb;
403 	osif_cm_send_vdev_keys_cb send_vdev_keys_cb;
404 	osif_cm_get_scan_ie_params_cb get_scan_ie_params_cb;
405 #endif
406 #ifdef WLAN_FEATURE_FILS_SK
407 	osif_cm_set_hlp_data_cb set_hlp_data_cb;
408 #endif
409 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
410 	osif_cm_roam_rt_stats_cb roam_rt_stats_event_cb;
411 #endif
412 #ifdef WLAN_FEATURE_PREAUTH_ENABLE
413 	osif_cm_ft_preauth_complete_cb ft_preauth_complete_cb;
414 #ifdef FEATURE_WLAN_ESE
415 	osif_cm_cckm_preauth_complete_cb cckm_preauth_complete_cb;
416 #endif
417 #endif
418 #ifdef WLAN_VENDOR_HANDOFF_CONTROL
419 	osif_cm_get_vendor_handoff_params_cb vendor_handoff_params_cb;
420 #endif
421 #ifdef WLAN_BOOST_CPU_FREQ_IN_ROAM
422 	os_if_cm_perfd_set_cpufreq_ctrl_cb perfd_set_cpufreq_cb;
423 #endif
424 };
425 
426 #ifdef CONN_MGR_ADV_FEATURE
427 /**
428  * osif_cm_connect_active_notify() - Function to notify connect active
429  * @vdev_id: VDEV ID on which connect req is active
430  *
431  * This API notifies connect active to legacy module
432  */
433 void osif_cm_connect_active_notify(uint8_t vdev_id);
434 #endif
435 
436 /**
437  * osif_cm_connect_comp_ind() - Function to indicate connect
438  * complete to legacy module
439  * @vdev: vdev pointer
440  * @rsp: connect response
441  * @type: indicates update type
442  *
443  * This function indicates connect complete to the legacy module
444  *
445  * Context: Any context.
446  * Return: QDF_STATUS
447  */
448 QDF_STATUS osif_cm_connect_comp_ind(struct wlan_objmgr_vdev *vdev,
449 				    struct wlan_cm_connect_resp *rsp,
450 				    enum osif_cb_type type);
451 
452 #ifdef WLAN_VENDOR_HANDOFF_CONTROL
453 /**
454  * osif_cm_vendor_handoff_params_cb() - Function to process vendor handoff
455  * event callback
456  * @psoc: psoc object pointer
457  * @vendor_handoff_context: vendor handoff context
458  *
459  * Return: QDF_STATUS
460  */
461 QDF_STATUS osif_cm_vendor_handoff_params_cb(struct wlan_objmgr_psoc *psoc,
462 					    void *vendor_handoff_context);
463 #endif
464 
465 /**
466  * osif_cm_disconnect_comp_ind() - Function to indicate disconnect
467  * complete to legacy module
468  * @vdev: vdev pointer
469  * @rsp: disconnect response
470  * @type: indicates update type
471  *
472  * This function indicates disconnect complete to the legacy module
473  *
474  * Context: Any context.
475  * Return: QDF_STATUS
476  */
477 QDF_STATUS osif_cm_disconnect_comp_ind(struct wlan_objmgr_vdev *vdev,
478 				       struct wlan_cm_discon_rsp *rsp,
479 				       enum osif_cb_type type);
480 
481 #ifdef CONN_MGR_ADV_FEATURE
482 /**
483  * osif_cm_netif_queue_ind() - Function to indicate netif queue update
484  * complete to legacy module
485  * @vdev: vdev pointer
486  * @action: Action to take on netif queue
487  * @reason: netif reason type
488  *
489  * This function indicates to take the actions related to netif queue
490  *
491  * Context: Any context.
492  * Return: QDF_STATUS
493  */
494 QDF_STATUS osif_cm_netif_queue_ind(struct wlan_objmgr_vdev *vdev,
495 				   enum netif_action_type action,
496 				   enum netif_reason_type reason);
497 
498 /**
499  * osif_cm_napi_serialize() - Function to indicate napi serialize
500  * action to legacy module
501  * @action: Action to take on napi serialization
502  *
503  * This function indicates to take the actions related to napi activities
504  *
505  * Context: Any context.
506  * Return: QDF_STATUS
507  */
508 QDF_STATUS osif_cm_napi_serialize(bool action);
509 
510 /**
511  * osif_cm_save_gtk() - Function to save gtk in legacy module
512  * @vdev: vdev pointer
513  * @rsp: Pointer to connect response
514  *
515  * This function saves gtk in legacy module
516  *
517  * Context: Any context.
518  * Return: QDF_STATUS
519  */
520 QDF_STATUS osif_cm_save_gtk(struct wlan_objmgr_vdev *vdev,
521 			    struct wlan_cm_connect_resp *rsp);
522 
523 /**
524  * osif_cm_send_vdev_keys() - Function to send vdev keys
525  * @vdev: vdev pointer
526  * @key_index: key index value
527  * @pairwise: pairwise bool value
528  * @cipher_type: cipher type value
529  *
530  * This function to send vdev keys
531  *
532  * Context: Any context.
533  * Return: QDF_STATUS
534  */
535 QDF_STATUS
536 osif_cm_send_vdev_keys(struct wlan_objmgr_vdev *vdev,
537 		       uint8_t key_index,
538 		       bool pairwise,
539 		       enum wlan_crypto_cipher_type cipher_type);
540 #else
osif_cm_save_gtk(struct wlan_objmgr_vdev * vdev,struct wlan_cm_connect_resp * rsp)541 static inline QDF_STATUS osif_cm_save_gtk(struct wlan_objmgr_vdev *vdev,
542 					  struct wlan_cm_connect_resp *rsp)
543 {
544 	return QDF_STATUS_SUCCESS;
545 }
546 #endif
547 
548 #ifdef WLAN_FEATURE_FILS_SK
549 /**
550  * osif_cm_set_hlp_data() - Function to set hlp data for dhcp in legacy module
551  * @dev: Pointer to net device
552  * @vdev: vdev pointer
553  * @rsp: Pointer to connect response
554  *
555  * This function sets hlp data for dhcp in legacy module
556  *
557  * Context: Any context.
558  * Return: QDF_STATUS
559  */
560 QDF_STATUS osif_cm_set_hlp_data(struct net_device *dev,
561 				struct wlan_objmgr_vdev *vdev,
562 				struct wlan_cm_connect_resp *rsp);
563 #else
osif_cm_set_hlp_data(struct net_device * dev,struct wlan_objmgr_vdev * vdev,struct wlan_cm_connect_resp * rsp)564 static inline QDF_STATUS osif_cm_set_hlp_data(struct net_device *dev,
565 					      struct wlan_objmgr_vdev *vdev,
566 					      struct wlan_cm_connect_resp *rsp)
567 {
568 	return QDF_STATUS_SUCCESS;
569 }
570 #endif
571 
572 /**
573  * osif_cm_set_legacy_cb() - Sets legacy callbacks to osif
574  * @osif_legacy_ops:  Function pointer to legacy ops structure
575  *
576  * API to set legacy callbacks to osif
577  * Context: Any context.
578  *
579  * Return: void
580  */
581 void osif_cm_set_legacy_cb(struct osif_cm_ops *osif_legacy_ops);
582 
583 /**
584  * osif_cm_reset_legacy_cb() - Resets legacy callbacks to osif
585  *
586  * API to reset legacy callbacks to osif
587  * Context: Any context.
588  *
589  * Return: void
590  */
591 void osif_cm_reset_legacy_cb(void);
592 
593 #ifdef WLAN_BOOST_CPU_FREQ_IN_ROAM
594 /**
595  * osif_cm_perfd_set_cpufreq() - Function to CPU min freq
596  * action to legacy module
597  * @action: Action to set or reset the CPU freq
598  *
599  * This function indicates to take the actions related to set/reset the CPU freq
600  *
601  * Context: Any context.
602  * Return: QDF_STATUS
603  */
604 QDF_STATUS osif_cm_perfd_set_cpufreq(bool action);
605 #else
606 static inline
osif_cm_perfd_set_cpufreq(bool action)607 QDF_STATUS osif_cm_perfd_set_cpufreq(bool action)
608 {
609 	return QDF_STATUS_SUCCESS;
610 }
611 #endif
612 
613 #endif /* __OSIF_CM_UTIL_H */
614