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: wlan_cm_api.c
20  *
21  * This file maintains definitaions public apis.
22  */
23 
24 #include <wlan_cm_api.h>
25 #include "connection_mgr/core/src/wlan_cm_main_api.h"
26 #include "connection_mgr/core/src/wlan_cm_roam.h"
27 #include <wlan_vdev_mgr_utils_api.h>
28 #ifdef WLAN_FEATURE_11BE_MLO
29 #ifdef WLAN_FEATURE_11BE_MLO_ADV_FEATURE
30 #include "wlan_mlo_mgr_roam.h"
31 #endif
32 #endif
33 
wlan_cm_start_connect(struct wlan_objmgr_vdev * vdev,struct wlan_cm_connect_req * req)34 QDF_STATUS wlan_cm_start_connect(struct wlan_objmgr_vdev *vdev,
35 				 struct wlan_cm_connect_req *req)
36 {
37 	return cm_connect_start_req(vdev, req);
38 }
39 
wlan_cm_disconnect(struct wlan_objmgr_vdev * vdev,enum wlan_cm_source source,enum wlan_reason_code reason_code,struct qdf_mac_addr * bssid)40 QDF_STATUS wlan_cm_disconnect(struct wlan_objmgr_vdev *vdev,
41 			      enum wlan_cm_source source,
42 			      enum wlan_reason_code reason_code,
43 			      struct qdf_mac_addr *bssid)
44 {
45 	struct wlan_cm_disconnect_req req = {0};
46 
47 	req.vdev_id = wlan_vdev_get_id(vdev);
48 	req.source = source;
49 	req.reason_code = reason_code;
50 	if (bssid)
51 		qdf_copy_macaddr(&req.bssid, bssid);
52 
53 	return cm_disconnect_start_req(vdev, &req);
54 }
55 
wlan_cm_disconnect_sync(struct wlan_objmgr_vdev * vdev,enum wlan_cm_source source,enum wlan_reason_code reason_code)56 QDF_STATUS wlan_cm_disconnect_sync(struct wlan_objmgr_vdev *vdev,
57 				   enum wlan_cm_source source,
58 				   enum wlan_reason_code reason_code)
59 {
60 	struct wlan_cm_disconnect_req req = {0};
61 
62 	req.vdev_id = wlan_vdev_get_id(vdev);
63 	req.source = source;
64 	req.reason_code = reason_code;
65 
66 	return cm_disconnect_start_req_sync(vdev, &req);
67 }
68 
wlan_cm_bss_select_ind_rsp(struct wlan_objmgr_vdev * vdev,QDF_STATUS status)69 QDF_STATUS wlan_cm_bss_select_ind_rsp(struct wlan_objmgr_vdev *vdev,
70 				      QDF_STATUS status)
71 {
72 	return cm_bss_select_ind_rsp(vdev, status);
73 }
74 
wlan_cm_bss_peer_create_rsp(struct wlan_objmgr_vdev * vdev,QDF_STATUS status,struct qdf_mac_addr * peer_mac)75 QDF_STATUS wlan_cm_bss_peer_create_rsp(struct wlan_objmgr_vdev *vdev,
76 				       QDF_STATUS status,
77 				       struct qdf_mac_addr *peer_mac)
78 {
79 	uint32_t prefix;
80 	struct cnx_mgr *cm_ctx = cm_get_cm_ctx(vdev);
81 
82 	if (!cm_ctx)
83 		return QDF_STATUS_E_INVAL;
84 
85 	prefix = CM_ID_GET_PREFIX(cm_ctx->active_cm_id);
86 	if (prefix == ROAM_REQ_PREFIX)
87 		return cm_roam_bss_peer_create_rsp(vdev, status, peer_mac);
88 	else
89 		return cm_bss_peer_create_rsp(vdev, status, peer_mac);
90 }
91 
wlan_cm_update_scan_mlme_info(struct wlan_objmgr_vdev * vdev,struct wlan_cm_connect_resp * resp)92 void wlan_cm_update_scan_mlme_info(struct wlan_objmgr_vdev *vdev,
93 				   struct wlan_cm_connect_resp *resp)
94 {
95 	struct cnx_mgr *cm_ctx = cm_get_cm_ctx(vdev);
96 
97 	if (!cm_ctx)
98 		return;
99 
100 	return cm_update_scan_mlme_info(cm_ctx, resp);
101 }
102 
wlan_cm_connect_rsp(struct wlan_objmgr_vdev * vdev,struct wlan_cm_connect_resp * resp)103 QDF_STATUS wlan_cm_connect_rsp(struct wlan_objmgr_vdev *vdev,
104 			       struct wlan_cm_connect_resp *resp)
105 {
106 	return cm_connect_rsp(vdev, resp);
107 }
108 
wlan_cm_bss_peer_delete_ind(struct wlan_objmgr_vdev * vdev,struct qdf_mac_addr * peer_mac)109 QDF_STATUS wlan_cm_bss_peer_delete_ind(struct wlan_objmgr_vdev *vdev,
110 				       struct qdf_mac_addr *peer_mac)
111 {
112 	return cm_bss_peer_delete_req(vdev, peer_mac);
113 }
114 
wlan_cm_bss_peer_delete_rsp(struct wlan_objmgr_vdev * vdev,uint32_t status)115 QDF_STATUS wlan_cm_bss_peer_delete_rsp(struct wlan_objmgr_vdev *vdev,
116 				       uint32_t status)
117 {
118 	return cm_vdev_down_req(vdev, status);
119 }
120 
wlan_cm_disconnect_rsp(struct wlan_objmgr_vdev * vdev,struct wlan_cm_discon_rsp * resp)121 QDF_STATUS wlan_cm_disconnect_rsp(struct wlan_objmgr_vdev *vdev,
122 				  struct wlan_cm_discon_rsp *resp)
123 {
124 	uint32_t prefix;
125 	struct cnx_mgr *cm_ctx = cm_get_cm_ctx(vdev);
126 
127 	if (!cm_ctx)
128 		return QDF_STATUS_E_INVAL;
129 
130 	prefix = CM_ID_GET_PREFIX(cm_ctx->active_cm_id);
131 	if (prefix == ROAM_REQ_PREFIX)
132 		return cm_roam_disconnect_rsp(vdev, resp);
133 	else
134 		return cm_disconnect_rsp(vdev, resp);
135 }
136 
137 #ifdef WLAN_FEATURE_HOST_ROAM
wlan_cm_reassoc_rsp(struct wlan_objmgr_vdev * vdev,struct wlan_cm_connect_resp * resp)138 QDF_STATUS wlan_cm_reassoc_rsp(struct wlan_objmgr_vdev *vdev,
139 			       struct wlan_cm_connect_resp *resp)
140 {
141 	return cm_reassoc_rsp(vdev, resp);
142 }
143 #endif
144 
wlan_cm_free_connect_req(struct wlan_cm_connect_req * connect_req)145 void wlan_cm_free_connect_req(struct wlan_cm_connect_req *connect_req)
146 {
147 	if (!connect_req)
148 		return;
149 
150 	cm_free_connect_req(connect_req);
151 }
152 
wlan_cm_free_connect_resp(struct wlan_cm_connect_resp * connect_rsp)153 void wlan_cm_free_connect_resp(struct wlan_cm_connect_resp *connect_rsp)
154 {
155 	if (!connect_rsp)
156 		return;
157 
158 	cm_free_connect_rsp(connect_rsp);
159 }
160 
wlan_cm_free_connect_req_param(struct wlan_cm_connect_req * req)161 void wlan_cm_free_connect_req_param(struct wlan_cm_connect_req *req)
162 {
163 	if (!req)
164 		return;
165 
166 	cm_free_connect_req_param(req);
167 }
168 
wlan_cm_set_max_connect_attempts(struct wlan_objmgr_vdev * vdev,uint8_t max_connect_attempts)169 void wlan_cm_set_max_connect_attempts(struct wlan_objmgr_vdev *vdev,
170 				      uint8_t max_connect_attempts)
171 {
172 	cm_set_max_connect_attempts(vdev, max_connect_attempts);
173 }
174 
wlan_cm_set_max_connect_timeout(struct wlan_objmgr_vdev * vdev,uint32_t max_connect_timeout)175 void wlan_cm_set_max_connect_timeout(struct wlan_objmgr_vdev *vdev,
176 				     uint32_t max_connect_timeout)
177 {
178 	cm_set_max_connect_timeout(vdev, max_connect_timeout);
179 }
180 
wlan_cm_is_vdev_connecting(struct wlan_objmgr_vdev * vdev)181 bool wlan_cm_is_vdev_connecting(struct wlan_objmgr_vdev *vdev)
182 {
183 	return cm_is_vdev_connecting(vdev);
184 }
185 
wlan_cm_is_vdev_connected(struct wlan_objmgr_vdev * vdev)186 bool wlan_cm_is_vdev_connected(struct wlan_objmgr_vdev *vdev)
187 {
188 	return cm_is_vdev_connected(vdev);
189 }
190 
wlan_cm_is_vdev_active(struct wlan_objmgr_vdev * vdev)191 bool wlan_cm_is_vdev_active(struct wlan_objmgr_vdev *vdev)
192 {
193 	return cm_is_vdev_active(vdev);
194 }
195 
wlan_cm_is_vdev_disconnecting(struct wlan_objmgr_vdev * vdev)196 bool wlan_cm_is_vdev_disconnecting(struct wlan_objmgr_vdev *vdev)
197 {
198 	return cm_is_vdev_disconnecting(vdev);
199 }
200 
wlan_cm_is_vdev_disconnected(struct wlan_objmgr_vdev * vdev)201 bool wlan_cm_is_vdev_disconnected(struct wlan_objmgr_vdev *vdev)
202 {
203 	return cm_is_vdev_disconnected(vdev);
204 }
205 
wlan_cm_is_vdev_idle_due_to_link_switch(struct wlan_objmgr_vdev * vdev)206 bool wlan_cm_is_vdev_idle_due_to_link_switch(struct wlan_objmgr_vdev *vdev)
207 {
208 	return cm_is_vdev_idle_due_to_link_switch(vdev);
209 }
210 
wlan_cm_is_vdev_roaming(struct wlan_objmgr_vdev * vdev)211 bool wlan_cm_is_vdev_roaming(struct wlan_objmgr_vdev *vdev)
212 {
213 	return cm_is_vdev_roaming(vdev);
214 }
215 
216 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
wlan_cm_is_vdev_roam_started(struct wlan_objmgr_vdev * vdev)217 bool wlan_cm_is_vdev_roam_started(struct wlan_objmgr_vdev *vdev)
218 {
219 	return cm_is_vdev_roam_started(vdev);
220 }
221 
wlan_cm_is_vdev_roam_sync_inprogress(struct wlan_objmgr_vdev * vdev)222 bool wlan_cm_is_vdev_roam_sync_inprogress(struct wlan_objmgr_vdev *vdev)
223 {
224 	return cm_is_vdev_roam_sync_inprogress(vdev);
225 }
226 #endif
227 
228 #ifdef WLAN_FEATURE_HOST_ROAM
wlan_cm_is_vdev_roam_preauth_state(struct wlan_objmgr_vdev * vdev)229 bool wlan_cm_is_vdev_roam_preauth_state(struct wlan_objmgr_vdev *vdev)
230 {
231 	return cm_is_vdev_roam_preauth_state(vdev);
232 }
233 
wlan_cm_is_vdev_roam_reassoc_state(struct wlan_objmgr_vdev * vdev)234 bool wlan_cm_is_vdev_roam_reassoc_state(struct wlan_objmgr_vdev *vdev)
235 {
236 	return cm_is_vdev_roam_reassoc_state(vdev);
237 }
238 #endif
239 
240 enum wlan_cm_active_request_type
wlan_cm_get_active_req_type(struct wlan_objmgr_vdev * vdev)241 wlan_cm_get_active_req_type(struct wlan_objmgr_vdev *vdev)
242 {
243 	return cm_get_active_req_type(vdev);
244 }
245 
wlan_cm_get_active_connect_req(struct wlan_objmgr_vdev * vdev,struct wlan_cm_vdev_connect_req * req)246 bool wlan_cm_get_active_connect_req(struct wlan_objmgr_vdev *vdev,
247 				    struct wlan_cm_vdev_connect_req *req)
248 {
249 	return cm_get_active_connect_req(vdev, req);
250 }
251 
252 QDF_STATUS
wlan_cm_get_active_connect_req_param(struct wlan_objmgr_vdev * vdev,struct wlan_cm_connect_req * req)253 wlan_cm_get_active_connect_req_param(struct wlan_objmgr_vdev *vdev,
254 				     struct wlan_cm_connect_req *req)
255 {
256 	return cm_get_active_connect_req_param(vdev, req);
257 }
258 
wlan_cm_get_ext_hdl(struct wlan_objmgr_vdev * vdev)259 cm_ext_t *wlan_cm_get_ext_hdl(struct wlan_objmgr_vdev *vdev)
260 {
261 	return cm_get_ext_hdl(vdev);
262 }
263 
wlan_cm_is_first_candidate_connect_attempt(struct wlan_objmgr_vdev * vdev)264 bool wlan_cm_is_first_candidate_connect_attempt(struct wlan_objmgr_vdev *vdev)
265 {
266 	return cm_is_first_candidate_connect_attempt(vdev);
267 }
268 
wlan_cm_is_link_switch_disconnect_resp(struct wlan_cm_discon_rsp * resp)269 bool wlan_cm_is_link_switch_disconnect_resp(struct wlan_cm_discon_rsp *resp)
270 {
271 	return cm_is_link_switch_disconnect_resp(resp);
272 }
273 
wlan_cm_is_link_switch_connect_resp(struct wlan_cm_connect_resp * resp)274 bool wlan_cm_is_link_switch_connect_resp(struct wlan_cm_connect_resp *resp)
275 {
276 	return cm_is_link_switch_connect_resp(resp);
277 }
278 
wlan_cm_trigger_panic_on_cmd_timeout(struct wlan_objmgr_vdev * vdev,enum qdf_hang_reason reason)279 void wlan_cm_trigger_panic_on_cmd_timeout(struct wlan_objmgr_vdev *vdev,
280 					  enum qdf_hang_reason reason)
281 {
282 	cm_trigger_panic_on_cmd_timeout(vdev, reason);
283 }
284 
285 #ifdef WLAN_FEATURE_HOST_ROAM
wlan_cm_get_active_reassoc_req(struct wlan_objmgr_vdev * vdev,struct wlan_cm_vdev_reassoc_req * req)286 bool wlan_cm_get_active_reassoc_req(struct wlan_objmgr_vdev *vdev,
287 				    struct wlan_cm_vdev_reassoc_req *req)
288 {
289 	return cm_get_active_reassoc_req(vdev, req);
290 }
291 #endif
292 
wlan_cm_get_active_disconnect_req(struct wlan_objmgr_vdev * vdev,struct wlan_cm_vdev_discon_req * req)293 bool wlan_cm_get_active_disconnect_req(struct wlan_objmgr_vdev *vdev,
294 				       struct wlan_cm_vdev_discon_req *req)
295 {
296 	return cm_get_active_disconnect_req(vdev, req);
297 }
298 
wlan_cm_reason_code_to_str(enum wlan_reason_code reason)299 const char *wlan_cm_reason_code_to_str(enum wlan_reason_code reason)
300 {
301 	if (reason > REASON_PROP_START)
302 		return "";
303 
304 	switch (reason) {
305 	CASE_RETURN_STRING(REASON_UNSPEC_FAILURE);
306 	CASE_RETURN_STRING(REASON_PREV_AUTH_NOT_VALID);
307 	CASE_RETURN_STRING(REASON_DEAUTH_NETWORK_LEAVING);
308 	CASE_RETURN_STRING(REASON_DISASSOC_DUE_TO_INACTIVITY);
309 	CASE_RETURN_STRING(REASON_DISASSOC_AP_BUSY);
310 	CASE_RETURN_STRING(REASON_CLASS2_FRAME_FROM_NON_AUTH_STA);
311 	CASE_RETURN_STRING(REASON_CLASS3_FRAME_FROM_NON_ASSOC_STA);
312 	CASE_RETURN_STRING(REASON_DISASSOC_NETWORK_LEAVING);
313 	CASE_RETURN_STRING(REASON_STA_NOT_AUTHENTICATED);
314 	CASE_RETURN_STRING(REASON_BAD_PWR_CAPABILITY);
315 	CASE_RETURN_STRING(REASON_BAD_SUPPORTED_CHANNELS);
316 	CASE_RETURN_STRING(REASON_DISASSOC_BSS_TRANSITION);
317 	CASE_RETURN_STRING(REASON_INVALID_IE);
318 	CASE_RETURN_STRING(REASON_MIC_FAILURE);
319 	CASE_RETURN_STRING(REASON_4WAY_HANDSHAKE_TIMEOUT);
320 	CASE_RETURN_STRING(REASON_GROUP_KEY_UPDATE_TIMEOUT);
321 	CASE_RETURN_STRING(REASON_IN_4WAY_DIFFERS);
322 	CASE_RETURN_STRING(REASON_INVALID_GROUP_CIPHER);
323 	CASE_RETURN_STRING(REASON_INVALID_PAIRWISE_CIPHER);
324 	CASE_RETURN_STRING(REASON_INVALID_AKMP);
325 	CASE_RETURN_STRING(REASON_UNSUPPORTED_RSNE_VER);
326 	CASE_RETURN_STRING(REASON_INVALID_RSNE_CAPABILITIES);
327 	CASE_RETURN_STRING(REASON_1X_AUTH_FAILURE);
328 	CASE_RETURN_STRING(REASON_CIPHER_SUITE_REJECTED);
329 	CASE_RETURN_STRING(REASON_TDLS_PEER_UNREACHABLE);
330 	CASE_RETURN_STRING(REASON_TDLS_UNSPEC);
331 	CASE_RETURN_STRING(REASON_DISASSOC_SSP_REQUESTED);
332 	CASE_RETURN_STRING(REASON_NO_SSP_ROAMING_AGREEMENT);
333 	CASE_RETURN_STRING(REASON_BAD_CIPHER_OR_AKM);
334 	CASE_RETURN_STRING(REASON_LOCATION_NOT_AUTHORIZED);
335 	CASE_RETURN_STRING(REASON_SERVICE_CHANGE_PRECLUDES_TS);
336 	CASE_RETURN_STRING(REASON_QOS_UNSPECIFIED);
337 	CASE_RETURN_STRING(REASON_NO_BANDWIDTH);
338 	CASE_RETURN_STRING(REASON_XS_UNACKED_FRAMES);
339 	CASE_RETURN_STRING(REASON_EXCEEDED_TXOP);
340 	CASE_RETURN_STRING(REASON_STA_LEAVING);
341 	CASE_RETURN_STRING(REASON_END_TS_BA_DLS);
342 	CASE_RETURN_STRING(REASON_UNKNOWN_TS_BA);
343 	CASE_RETURN_STRING(REASON_TIMEDOUT);
344 	CASE_RETURN_STRING(REASON_PEERKEY_MISMATCH);
345 	CASE_RETURN_STRING(REASON_AUTHORIZED_ACCESS_LIMIT_REACHED);
346 	CASE_RETURN_STRING(REASON_EXTERNAL_SERVICE_REQUIREMENTS);
347 	CASE_RETURN_STRING(REASON_INVALID_FT_ACTION_FRAME_COUNT);
348 	CASE_RETURN_STRING(REASON_INVALID_PMKID);
349 	CASE_RETURN_STRING(REASON_INVALID_MDE);
350 	CASE_RETURN_STRING(REASON_INVALID_FTE);
351 	CASE_RETURN_STRING(REASON_MESH_PEERING_CANCELLED);
352 	CASE_RETURN_STRING(REASON_MESH_MAX_PEERS);
353 	CASE_RETURN_STRING(REASON_MESH_CONFIG_POLICY_VIOLATION);
354 	CASE_RETURN_STRING(REASON_MESH_CLOSE_RCVD);
355 	CASE_RETURN_STRING(REASON_MESH_MAX_RETRIES);
356 	CASE_RETURN_STRING(REASON_MESH_CONFIRM_TIMEOUT);
357 	CASE_RETURN_STRING(REASON_MESH_INVALID_GTK);
358 	CASE_RETURN_STRING(REASON_MESH_INCONSISTENT_PARAMS);
359 	CASE_RETURN_STRING(REASON_MESH_INVALID_SECURITY_CAP);
360 	CASE_RETURN_STRING(REASON_MESH_PATH_ERROR_NO_PROXY_INFO);
361 	CASE_RETURN_STRING(REASON_MESH_PATH_ERROR_NO_FORWARDING_INFO);
362 	CASE_RETURN_STRING(REASON_MESH_PATH_ERROR_DEST_UNREACHABLE);
363 	CASE_RETURN_STRING(REASON_MAC_ADDRESS_ALREADY_EXISTS_IN_MBSS);
364 	CASE_RETURN_STRING(REASON_MESH_CHANNEL_SWITCH_REGULATORY_REQ);
365 	CASE_RETURN_STRING(REASON_MESH_CHANNEL_SWITCH_UNSPECIFIED);
366 	CASE_RETURN_STRING(REASON_POOR_RSSI_CONDITIONS);
367 	default:
368 		return "Unknown";
369 	}
370 }
371 
372 #ifdef WLAN_POLICY_MGR_ENABLE
wlan_cm_hw_mode_change_resp(struct wlan_objmgr_pdev * pdev,uint8_t vdev_id,wlan_cm_id cm_id,QDF_STATUS status)373 void wlan_cm_hw_mode_change_resp(struct wlan_objmgr_pdev *pdev, uint8_t vdev_id,
374 				 wlan_cm_id cm_id, QDF_STATUS status)
375 {
376 	uint32_t prefix;
377 
378 	prefix = CM_ID_GET_PREFIX(cm_id);
379 	if (prefix == ROAM_REQ_PREFIX)
380 		cm_reassoc_hw_mode_change_resp(pdev, vdev_id, cm_id, status);
381 	else
382 		cm_hw_mode_change_resp(pdev, vdev_id, cm_id, status);
383 }
384 #endif /* ifdef POLICY_MGR_ENABLE */
385 
386 #ifdef WLAN_FEATURE_LL_LT_SAP
wlan_cm_bearer_switch_resp(struct wlan_objmgr_psoc * psoc,uint8_t vdev_id,wlan_cm_id cm_id,QDF_STATUS status)387 void wlan_cm_bearer_switch_resp(struct wlan_objmgr_psoc *psoc, uint8_t vdev_id,
388 				wlan_cm_id cm_id, QDF_STATUS status)
389 {
390 	cm_bearer_switch_resp(psoc, vdev_id, cm_id, status);
391 }
392 #endif
393 
394 #ifdef SM_ENG_HIST_ENABLE
wlan_cm_sm_history_print(struct wlan_objmgr_vdev * vdev)395 void wlan_cm_sm_history_print(struct wlan_objmgr_vdev *vdev)
396 {
397 	return cm_sm_history_print(vdev);
398 }
399 
wlan_cm_req_history_print(struct wlan_objmgr_vdev * vdev)400 void wlan_cm_req_history_print(struct wlan_objmgr_vdev *vdev)
401 {
402 	struct cnx_mgr *cm_ctx = cm_get_cm_ctx(vdev);
403 
404 	if (!cm_ctx)
405 		return;
406 
407 	cm_req_history_print(cm_ctx);
408 }
409 #endif /* SM_ENG_HIST_ENABLE */
410 
411 #ifndef CONN_MGR_ADV_FEATURE
wlan_cm_set_candidate_advance_filter_cb(struct wlan_objmgr_vdev * vdev,void (* filter_fun)(struct wlan_objmgr_vdev * vdev,struct scan_filter * filter))412 void wlan_cm_set_candidate_advance_filter_cb(
413 		struct wlan_objmgr_vdev *vdev,
414 		void (*filter_fun)(struct wlan_objmgr_vdev *vdev,
415 				   struct scan_filter *filter))
416 {
417 	cm_set_candidate_advance_filter_cb(vdev, filter_fun);
418 }
419 
wlan_cm_set_candidate_custom_sort_cb(struct wlan_objmgr_vdev * vdev,void (* sort_fun)(struct wlan_objmgr_vdev * vdev,qdf_list_t * list))420 void wlan_cm_set_candidate_custom_sort_cb(
421 		struct wlan_objmgr_vdev *vdev,
422 		void (*sort_fun)(struct wlan_objmgr_vdev *vdev,
423 				 qdf_list_t *list))
424 {
425 	cm_set_candidate_custom_sort_cb(vdev, sort_fun);
426 }
427 
428 #endif
429 
wlan_cm_get_rnr(struct wlan_objmgr_vdev * vdev,wlan_cm_id cm_id,struct reduced_neighbor_report * rnr)430 QDF_STATUS wlan_cm_get_rnr(struct wlan_objmgr_vdev *vdev, wlan_cm_id cm_id,
431 			   struct reduced_neighbor_report *rnr)
432 {
433 	enum QDF_OPMODE op_mode = wlan_vdev_mlme_get_opmode(vdev);
434 
435 	if (op_mode != QDF_STA_MODE && op_mode != QDF_P2P_CLIENT_MODE) {
436 		mlme_err("vdev %d Invalid mode %d",
437 			 wlan_vdev_get_id(vdev), op_mode);
438 		return QDF_STATUS_E_NOSUPPORT;
439 	}
440 
441 	return cm_get_rnr(vdev, cm_id, rnr);
442 }
443 
444 struct scan_cache_entry *
wlan_cm_get_curr_candidate_entry(struct wlan_objmgr_vdev * vdev,wlan_cm_id cm_id)445 wlan_cm_get_curr_candidate_entry(struct wlan_objmgr_vdev *vdev,
446 				 wlan_cm_id cm_id)
447 {
448 	return cm_get_curr_candidate_entry(vdev, cm_id);
449 }
450 
451 void
wlan_cm_connect_resp_fill_mld_addr_from_cm_id(struct wlan_objmgr_vdev * vdev,wlan_cm_id cm_id,struct wlan_cm_connect_resp * rsp)452 wlan_cm_connect_resp_fill_mld_addr_from_cm_id(struct wlan_objmgr_vdev *vdev,
453 					     wlan_cm_id cm_id,
454 					     struct wlan_cm_connect_resp *rsp)
455 {
456 	return cm_connect_resp_fill_mld_addr_from_cm_id(vdev, cm_id, rsp);
457 }
458 
459 #ifdef WLAN_FEATURE_11BE_MLO
460 void
wlan_cm_connect_resp_fill_mld_addr_from_vdev_id(struct wlan_objmgr_psoc * psoc,uint8_t vdev_id,struct scan_cache_entry * entry,struct wlan_cm_connect_resp * rsp)461 wlan_cm_connect_resp_fill_mld_addr_from_vdev_id(struct wlan_objmgr_psoc *psoc,
462 						uint8_t vdev_id,
463 						struct scan_cache_entry *entry,
464 						struct wlan_cm_connect_resp *rsp)
465 {
466 	struct wlan_objmgr_vdev *vdev;
467 
468 	vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc, vdev_id,
469 						    WLAN_MLME_CM_ID);
470 	if (!vdev)
471 		return;
472 
473 	cm_connect_resp_fill_mld_addr_from_candidate(vdev, entry, rsp);
474 	wlan_objmgr_vdev_release_ref(vdev, WLAN_MLME_CM_ID);
475 }
476 #endif
477 
478 QDF_STATUS
wlan_cm_disc_cont_after_rso_stop(struct wlan_objmgr_vdev * vdev,struct wlan_cm_vdev_discon_req * req)479 wlan_cm_disc_cont_after_rso_stop(struct wlan_objmgr_vdev *vdev,
480 				 struct wlan_cm_vdev_discon_req *req)
481 {
482 	return cm_handle_rso_stop_rsp(vdev, req);
483 }
484 
485 #ifdef WLAN_FEATURE_11BE
wlan_cm_sta_set_chan_param(struct wlan_objmgr_vdev * vdev,qdf_freq_t ch_freq,enum phy_ch_width ori_bw,uint16_t ori_punc,uint8_t ccfs0,uint8_t ccfs1,struct ch_params * chan_param)486 QDF_STATUS wlan_cm_sta_set_chan_param(struct wlan_objmgr_vdev *vdev,
487 				      qdf_freq_t ch_freq,
488 				      enum phy_ch_width ori_bw,
489 				      uint16_t ori_punc,
490 				      uint8_t ccfs0, uint8_t ccfs1,
491 				      struct ch_params *chan_param)
492 {
493 	uint16_t primary_puncture_bitmap = 0;
494 	struct wlan_objmgr_pdev *pdev;
495 	struct reg_channel_list chan_list;
496 	qdf_freq_t sec_ch_2g_freq = 0;
497 	qdf_freq_t center_freq_320 = 0;
498 	qdf_freq_t center_freq_40 = 0;
499 	uint8_t band_mask;
500 	uint16_t new_punc = 0;
501 
502 	if (!vdev || !chan_param) {
503 		mlme_err("invalid input parameters");
504 		return QDF_STATUS_E_INVAL;
505 	}
506 	pdev = wlan_vdev_get_pdev(vdev);
507 	if (!pdev) {
508 		mlme_err("invalid pdev");
509 		return QDF_STATUS_E_INVAL;
510 	}
511 	if (ori_bw == CH_WIDTH_320MHZ) {
512 		if (WLAN_REG_IS_6GHZ_CHAN_FREQ(ch_freq))
513 			band_mask = BIT(REG_BAND_6G);
514 		else
515 			band_mask = BIT(REG_BAND_5G);
516 		center_freq_320 = wlan_reg_chan_band_to_freq(pdev, ccfs1,
517 							     band_mask);
518 	} else if (ori_bw == CH_WIDTH_40MHZ) {
519 		if (WLAN_REG_IS_24GHZ_CH_FREQ(ch_freq)) {
520 			band_mask = BIT(REG_BAND_2G);
521 			center_freq_40 = wlan_reg_chan_band_to_freq(pdev,
522 								    ccfs0,
523 								    band_mask);
524 			if (center_freq_40 == ch_freq + BW_10_MHZ)
525 				sec_ch_2g_freq = ch_freq + BW_20_MHZ;
526 			if (center_freq_40 == ch_freq - BW_10_MHZ)
527 				sec_ch_2g_freq = ch_freq - BW_20_MHZ;
528 		}
529 	}
530 	wlan_reg_extract_puncture_by_bw(ori_bw, ori_punc,
531 					ch_freq,
532 					center_freq_320,
533 					CH_WIDTH_20MHZ,
534 					&primary_puncture_bitmap);
535 	if (primary_puncture_bitmap) {
536 		mlme_err("sta vdev %d freq %d RX bw %d puncture 0x%x primary chan is punctured",
537 			 wlan_vdev_get_id(vdev), ch_freq,
538 			 ori_bw, ori_punc);
539 		return QDF_STATUS_E_FAULT;
540 	}
541 	if (chan_param->ch_width != CH_WIDTH_320MHZ)
542 		center_freq_320 = 0;
543 	qdf_mem_zero(&chan_list, sizeof(chan_list));
544 	wlan_reg_fill_channel_list_for_pwrmode(pdev, ch_freq,
545 					       sec_ch_2g_freq,
546 					       chan_param->ch_width,
547 					       center_freq_320, &chan_list,
548 					       REG_CURRENT_PWR_MODE, true);
549 	*chan_param = chan_list.chan_param[0];
550 	if (chan_param->ch_width == ori_bw)
551 		new_punc = ori_punc;
552 	else
553 		wlan_reg_extract_puncture_by_bw(ori_bw, ori_punc,
554 						ch_freq,
555 						chan_param->mhz_freq_seg1,
556 						chan_param->ch_width,
557 						&new_punc);
558 
559 	chan_param->reg_punc_bitmap = new_punc;
560 
561 	return QDF_STATUS_SUCCESS;
562 }
563 
wlan_cm_sta_update_bw_puncture(struct wlan_objmgr_vdev * vdev,uint8_t * peer_mac,uint16_t ori_punc,enum phy_ch_width ori_bw,uint8_t ccfs0,uint8_t ccfs1,enum phy_ch_width new_bw)564 QDF_STATUS wlan_cm_sta_update_bw_puncture(struct wlan_objmgr_vdev *vdev,
565 					  uint8_t *peer_mac,
566 					  uint16_t ori_punc,
567 					  enum phy_ch_width ori_bw,
568 					  uint8_t ccfs0, uint8_t ccfs1,
569 					  enum phy_ch_width new_bw)
570 {
571 	struct wlan_channel *des_chan;
572 	struct ch_params ch_param;
573 	uint32_t bw_puncture = 0;
574 	QDF_STATUS status = QDF_STATUS_E_INVAL;
575 
576 	if (!vdev || !peer_mac) {
577 		mlme_err("invalid input parameters");
578 		return status;
579 	}
580 	des_chan = wlan_vdev_mlme_get_des_chan(vdev);
581 	if (!des_chan) {
582 		mlme_err("invalid des chan");
583 		return status;
584 	}
585 	qdf_mem_zero(&ch_param, sizeof(ch_param));
586 	ch_param.ch_width = new_bw;
587 	status = wlan_cm_sta_set_chan_param(vdev, des_chan->ch_freq,
588 					    ori_bw, ori_punc, ccfs0,
589 					    ccfs1, &ch_param);
590 	if (QDF_IS_STATUS_ERROR(status))
591 		return status;
592 
593 	if (des_chan->puncture_bitmap == ch_param.reg_punc_bitmap &&
594 	    des_chan->ch_width == ch_param.ch_width)
595 		return status;
596 
597 	des_chan->ch_freq_seg1 = ch_param.center_freq_seg0;
598 	des_chan->ch_freq_seg2 = ch_param.center_freq_seg1;
599 	des_chan->ch_cfreq1 = ch_param.mhz_freq_seg0;
600 	des_chan->ch_cfreq2 = ch_param.mhz_freq_seg1;
601 	des_chan->puncture_bitmap = ch_param.reg_punc_bitmap;
602 	des_chan->ch_width = ch_param.ch_width;
603 	mlme_debug("sta vdev %d freq %d bw %d puncture 0x%x ch_cfreq1 %d ch_cfreq2 %d",
604 		   wlan_vdev_get_id(vdev), des_chan->ch_freq,
605 		   des_chan->ch_width, des_chan->puncture_bitmap,
606 		   des_chan->ch_cfreq1, des_chan->ch_cfreq2);
607 	QDF_SET_BITS(bw_puncture, 0, 8, des_chan->ch_width);
608 	QDF_SET_BITS(bw_puncture, 8, 16, des_chan->puncture_bitmap);
609 	return wlan_util_vdev_peer_set_param_send(vdev, peer_mac,
610 						  WLAN_MLME_PEER_BW_PUNCTURE,
611 						  bw_puncture);
612 }
613 #endif /* WLAN_FEATURE_11BE */
614 
615 #ifdef WLAN_FEATURE_11BE_MLO
616 #ifdef WLAN_FEATURE_11BE_MLO_ADV_FEATURE
617 bool
wlan_cm_check_mlo_roam_auth_status(struct wlan_objmgr_vdev * vdev)618 wlan_cm_check_mlo_roam_auth_status(struct wlan_objmgr_vdev *vdev)
619 {
620 	return mlo_roam_is_auth_status_connected(wlan_vdev_get_psoc(vdev),
621 					  wlan_vdev_get_id(vdev));
622 }
623 #endif
624 #endif
625 enum MLO_TYPE
wlan_cm_bss_mlo_type(struct wlan_objmgr_psoc * psoc,struct scan_cache_entry * entry,qdf_list_t * scan_list)626 wlan_cm_bss_mlo_type(struct wlan_objmgr_psoc *psoc,
627 		     struct scan_cache_entry *entry,
628 		     qdf_list_t *scan_list)
629 {
630 	return cm_bss_mlo_type(psoc, entry, scan_list);
631 }
632