1 /*
2 * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for
6 * any purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 /**
21 * DOC: contains interface definitions for OS_IF layer
22 */
23
24 #include "nan_ucfg_api.h"
25 #include "nan_public_structs.h"
26 #include "wlan_nan_api.h"
27 #include "../../core/src/nan_main_i.h"
28 #include "scheduler_api.h"
29 #include "wlan_objmgr_psoc_obj.h"
30 #include "wlan_objmgr_pdev_obj.h"
31 #include "wlan_objmgr_vdev_obj.h"
32 #include "wlan_osif_request_manager.h"
33 #include "wlan_policy_mgr_api.h"
34 #include "cfg_ucfg_api.h"
35 #include "cfg_nan.h"
36 #include "wlan_mlme_api.h"
37 #include "cfg_nan_api.h"
38 #include "wlan_tdls_ucfg_api.h"
39 #include "wlan_nan_api_i.h"
40
41 struct wlan_objmgr_psoc;
42 struct wlan_objmgr_vdev;
43
44 #ifdef WLAN_FEATURE_NAN
45 /**
46 * nan_cfg_init() - Initialize NAN config params
47 * @psoc: Pointer to PSOC Object
48 * @nan_obj: Pointer to NAN private object
49 *
50 * This function initialize NAN config params
51 */
nan_cfg_init(struct wlan_objmgr_psoc * psoc,struct nan_psoc_priv_obj * nan_obj)52 static void nan_cfg_init(struct wlan_objmgr_psoc *psoc,
53 struct nan_psoc_priv_obj *nan_obj)
54 {
55 nan_obj->cfg_param.enable = cfg_get(psoc, CFG_NAN_ENABLE);
56 nan_obj->cfg_param.support_mp0_discovery =
57 cfg_get(psoc,
58 CFG_SUPPORT_MP0_DISCOVERY);
59 nan_obj->cfg_param.ndp_keep_alive_period =
60 cfg_get(psoc,
61 CFG_NDP_KEEP_ALIVE_PERIOD);
62 nan_obj->cfg_param.max_ndp_sessions = cfg_get(psoc,
63 CFG_NDP_MAX_SESSIONS);
64 nan_obj->cfg_param.max_ndi = cfg_get(psoc, CFG_NDI_MAX_SUPPORT);
65 nan_obj->cfg_param.nan_feature_config =
66 cfg_get(psoc, CFG_NAN_FEATURE_CONFIG);
67 nan_obj->cfg_param.disable_6g_nan = cfg_get(psoc, CFG_DISABLE_6G_NAN);
68 nan_obj->cfg_param.enable_nan_eht_cap =
69 cfg_get(psoc, CFG_NAN_ENABLE_EHT_CAP);
70 }
71
72 /**
73 * nan_cfg_dp_init() - Initialize NAN Datapath config params
74 * @psoc: Pointer to PSOC Object
75 * @nan_obj: Pointer to NAN private object
76 *
77 * This function initialize NAN config params
78 */
nan_cfg_dp_init(struct wlan_objmgr_psoc * psoc,struct nan_psoc_priv_obj * nan_obj)79 static void nan_cfg_dp_init(struct wlan_objmgr_psoc *psoc,
80 struct nan_psoc_priv_obj *nan_obj)
81 {
82 nan_obj->cfg_param.dp_enable = cfg_get(psoc,
83 CFG_NAN_DATAPATH_ENABLE);
84 nan_obj->cfg_param.ndi_mac_randomize =
85 cfg_get(psoc, CFG_NAN_RANDOMIZE_NDI_MAC);
86 nan_obj->cfg_param.ndp_inactivity_timeout =
87 cfg_get(psoc, CFG_NAN_NDP_INACTIVITY_TIMEOUT);
88 nan_obj->cfg_param.nan_separate_iface_support =
89 cfg_get(psoc, CFG_NAN_SEPARATE_IFACE_SUPP);
90
91 }
92 #else
nan_cfg_init(struct wlan_objmgr_psoc * psoc,struct nan_psoc_priv_obj * nan_obj)93 static void nan_cfg_init(struct wlan_objmgr_psoc *psoc,
94 struct nan_psoc_priv_obj *nan_obj)
95 {
96 }
97
nan_cfg_dp_init(struct wlan_objmgr_psoc * psoc,struct nan_psoc_priv_obj * nan_obj)98 static void nan_cfg_dp_init(struct wlan_objmgr_psoc *psoc,
99 struct nan_psoc_priv_obj *nan_obj)
100 {
101 }
102 #endif
103
ucfg_get_disable_6g_nan(struct wlan_objmgr_psoc * psoc)104 bool ucfg_get_disable_6g_nan(struct wlan_objmgr_psoc *psoc)
105 {
106 struct nan_psoc_priv_obj *nan_obj = nan_get_psoc_priv_obj(psoc);
107
108 if (!nan_obj) {
109 nan_err("nan psoc priv object is NULL");
110 return cfg_default(CFG_DISABLE_6G_NAN);
111 }
112
113 return nan_obj->cfg_param.disable_6g_nan;
114 }
115
ucfg_nan_psoc_open(struct wlan_objmgr_psoc * psoc)116 QDF_STATUS ucfg_nan_psoc_open(struct wlan_objmgr_psoc *psoc)
117 {
118 struct nan_psoc_priv_obj *nan_obj = nan_get_psoc_priv_obj(psoc);
119
120 if (!nan_obj) {
121 nan_err("nan psoc priv object is NULL");
122 return QDF_STATUS_E_NULL_VALUE;
123 }
124
125 nan_cfg_init(psoc, nan_obj);
126 nan_cfg_dp_init(psoc, nan_obj);
127
128 return QDF_STATUS_SUCCESS;
129 }
130
ucfg_nan_psoc_close(struct wlan_objmgr_psoc * psoc)131 void ucfg_nan_psoc_close(struct wlan_objmgr_psoc *psoc)
132 {
133 /* No cleanup required on psoc close for NAN */
134 }
135
__ucfg_nan_set_ndi_state(struct wlan_objmgr_vdev * vdev,enum nan_datapath_state state,const char * func)136 inline QDF_STATUS __ucfg_nan_set_ndi_state(struct wlan_objmgr_vdev *vdev,
137 enum nan_datapath_state state,
138 const char *func)
139 {
140 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
141 enum nan_datapath_state current_state;
142
143 if (!priv_obj) {
144 nan_err("priv_obj is null");
145 return QDF_STATUS_E_NULL_VALUE;
146 }
147 qdf_spin_lock_bh(&priv_obj->lock);
148 current_state = priv_obj->state;
149 priv_obj->state = state;
150 qdf_spin_unlock_bh(&priv_obj->lock);
151 nan_nofl_debug("%s: ndi state: current: %u, new: %u", func,
152 current_state, state);
153
154 return QDF_STATUS_SUCCESS;
155 }
156
ucfg_nan_get_ndi_state(struct wlan_objmgr_vdev * vdev)157 inline enum nan_datapath_state ucfg_nan_get_ndi_state(
158 struct wlan_objmgr_vdev *vdev)
159 {
160 return wlan_nan_get_ndi_state(vdev);
161 }
162
ucfg_nan_set_active_peers(struct wlan_objmgr_vdev * vdev,uint32_t val)163 inline QDF_STATUS ucfg_nan_set_active_peers(struct wlan_objmgr_vdev *vdev,
164 uint32_t val)
165 {
166 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
167
168 if (!priv_obj) {
169 nan_err("priv_obj is null");
170 return QDF_STATUS_E_NULL_VALUE;
171 }
172
173 qdf_spin_lock_bh(&priv_obj->lock);
174 priv_obj->active_ndp_peers = val;
175 qdf_spin_unlock_bh(&priv_obj->lock);
176
177 return QDF_STATUS_SUCCESS;
178 }
179
180 /**
181 * ucfg_nan_update_mc_list() - update the multicast list
182 * @vdev: Pointer to VDEV Object
183 *
184 * This function will update the multicast list for NDP peer
185 */
ucfg_nan_update_mc_list(struct wlan_objmgr_vdev * vdev)186 static void ucfg_nan_update_mc_list(struct wlan_objmgr_vdev *vdev)
187 {
188 struct nan_callbacks cb_obj;
189 QDF_STATUS status;
190 struct wlan_objmgr_psoc *psoc = wlan_vdev_get_psoc(vdev);
191
192 if (!psoc) {
193 nan_err("psoc is null");
194 return;
195 }
196
197 status = ucfg_nan_get_callbacks(psoc, &cb_obj);
198 if (QDF_IS_STATUS_ERROR(status)) {
199 nan_err("Couldn't get callback object");
200 return;
201 }
202
203 if (!cb_obj.set_mc_list) {
204 nan_err("set_mc_list callback not registered");
205 return;
206 }
207
208 cb_obj.set_mc_list(vdev);
209 }
210
ucfg_nan_set_peer_mc_list(struct wlan_objmgr_vdev * vdev,struct qdf_mac_addr peer_mac_addr)211 inline void ucfg_nan_set_peer_mc_list(struct wlan_objmgr_vdev *vdev,
212 struct qdf_mac_addr peer_mac_addr)
213 {
214 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
215 uint32_t max_ndp_sessions = 0;
216 struct wlan_objmgr_psoc *psoc = wlan_vdev_get_psoc(vdev);
217 int i, list_idx = 0;
218
219 if (!priv_obj) {
220 nan_err("priv_obj is null");
221 return;
222 }
223
224 if (!psoc) {
225 nan_err("psoc is null");
226 return;
227 }
228
229 cfg_nan_get_ndp_max_sessions(psoc, &max_ndp_sessions);
230
231 qdf_spin_lock_bh(&priv_obj->lock);
232 for (i = 0; i < max_ndp_sessions; i++) {
233 if (qdf_is_macaddr_zero(&priv_obj->peer_mc_addr_list[i])) {
234 list_idx = i;
235 break;
236 }
237 }
238 if (list_idx == max_ndp_sessions) {
239 nan_err("Peer multicast address list is full");
240 qdf_spin_unlock_bh(&priv_obj->lock);
241 }
242 /* Derive peer multicast addr */
243 peer_mac_addr.bytes[0] = 0x33;
244 peer_mac_addr.bytes[1] = 0x33;
245 peer_mac_addr.bytes[2] = 0xff;
246 priv_obj->peer_mc_addr_list[list_idx] = peer_mac_addr;
247
248 qdf_spin_unlock_bh(&priv_obj->lock);
249
250 ucfg_nan_update_mc_list(vdev);
251 }
252
ucfg_nan_get_peer_mc_list(struct wlan_objmgr_vdev * vdev,struct qdf_mac_addr ** peer_mc_addr_list)253 inline void ucfg_nan_get_peer_mc_list(
254 struct wlan_objmgr_vdev *vdev,
255 struct qdf_mac_addr **peer_mc_addr_list)
256 {
257 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
258
259 if (!priv_obj) {
260 nan_err("priv_obj is null");
261 return;
262 }
263
264 *peer_mc_addr_list = priv_obj->peer_mc_addr_list;
265 }
266
ucfg_nan_clear_peer_mc_list(struct wlan_objmgr_psoc * psoc,struct wlan_objmgr_vdev * vdev,struct qdf_mac_addr * peer_mac_addr)267 inline void ucfg_nan_clear_peer_mc_list(struct wlan_objmgr_psoc *psoc,
268 struct wlan_objmgr_vdev *vdev,
269 struct qdf_mac_addr *peer_mac_addr)
270 {
271 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
272 int i;
273 uint32_t max_ndp_sessions = 0;
274 struct qdf_mac_addr derived_peer_mc_addr;
275
276 if (!priv_obj) {
277 nan_err("priv_obj is null");
278 return;
279 }
280
281 /* Derive peer multicast addr */
282 derived_peer_mc_addr = *peer_mac_addr;
283 derived_peer_mc_addr.bytes[0] = 0x33;
284 derived_peer_mc_addr.bytes[1] = 0x33;
285 derived_peer_mc_addr.bytes[2] = 0xff;
286 qdf_spin_lock_bh(&priv_obj->lock);
287 cfg_nan_get_ndp_max_sessions(psoc, &max_ndp_sessions);
288 for (i = 0; i < max_ndp_sessions; i++) {
289 if (qdf_is_macaddr_equal(&priv_obj->peer_mc_addr_list[i],
290 &derived_peer_mc_addr)) {
291 qdf_zero_macaddr(&priv_obj->peer_mc_addr_list[i]);
292 break;
293 }
294 }
295
296 qdf_spin_unlock_bh(&priv_obj->lock);
297
298 ucfg_nan_update_mc_list(vdev);
299 }
300
ucfg_nan_get_active_peers(struct wlan_objmgr_vdev * vdev)301 inline uint32_t ucfg_nan_get_active_peers(struct wlan_objmgr_vdev *vdev)
302 {
303 uint32_t val;
304 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
305
306 if (!priv_obj) {
307 nan_err("priv_obj is null");
308 return 0;
309 }
310
311 qdf_spin_lock_bh(&priv_obj->lock);
312 val = priv_obj->active_ndp_peers;
313 qdf_spin_unlock_bh(&priv_obj->lock);
314
315 return val;
316 }
ucfg_nan_set_ndp_create_transaction_id(struct wlan_objmgr_vdev * vdev,uint16_t val)317 inline QDF_STATUS ucfg_nan_set_ndp_create_transaction_id(
318 struct wlan_objmgr_vdev *vdev, uint16_t val)
319 {
320 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
321
322 if (!priv_obj) {
323 nan_err("priv_obj is null");
324 return QDF_STATUS_E_NULL_VALUE;
325 }
326
327 qdf_spin_lock_bh(&priv_obj->lock);
328 priv_obj->ndp_create_transaction_id = val;
329 qdf_spin_unlock_bh(&priv_obj->lock);
330
331 return QDF_STATUS_SUCCESS;
332 }
333
ucfg_nan_get_ndp_create_transaction_id(struct wlan_objmgr_vdev * vdev)334 inline uint16_t ucfg_nan_get_ndp_create_transaction_id(
335 struct wlan_objmgr_vdev *vdev)
336 {
337 uint16_t val;
338 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
339
340 if (!priv_obj) {
341 nan_err("priv_obj is null");
342 return 0;
343 }
344
345 qdf_spin_lock_bh(&priv_obj->lock);
346 val = priv_obj->ndp_create_transaction_id;
347 qdf_spin_unlock_bh(&priv_obj->lock);
348
349 return val;
350 }
351
ucfg_nan_set_ndp_delete_transaction_id(struct wlan_objmgr_vdev * vdev,uint16_t val)352 inline QDF_STATUS ucfg_nan_set_ndp_delete_transaction_id(
353 struct wlan_objmgr_vdev *vdev, uint16_t val)
354 {
355 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
356
357 if (!priv_obj) {
358 nan_err("priv_obj is null");
359 return QDF_STATUS_E_NULL_VALUE;
360 }
361
362 qdf_spin_lock_bh(&priv_obj->lock);
363 priv_obj->ndp_delete_transaction_id = val;
364 qdf_spin_unlock_bh(&priv_obj->lock);
365
366 return QDF_STATUS_SUCCESS;
367 }
368
ucfg_nan_get_ndp_delete_transaction_id(struct wlan_objmgr_vdev * vdev)369 inline uint16_t ucfg_nan_get_ndp_delete_transaction_id(
370 struct wlan_objmgr_vdev *vdev)
371 {
372 uint16_t val;
373 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
374
375 if (!priv_obj) {
376 nan_err("priv_obj is null");
377 return 0;
378 }
379
380 qdf_spin_lock_bh(&priv_obj->lock);
381 val = priv_obj->ndp_delete_transaction_id;
382 qdf_spin_unlock_bh(&priv_obj->lock);
383
384 return val;
385 }
386
ucfg_nan_set_ndi_delete_rsp_reason(struct wlan_objmgr_vdev * vdev,uint32_t val)387 inline QDF_STATUS ucfg_nan_set_ndi_delete_rsp_reason(
388 struct wlan_objmgr_vdev *vdev, uint32_t val)
389 {
390 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
391
392 if (!priv_obj) {
393 nan_err("priv_obj is null");
394 return QDF_STATUS_E_NULL_VALUE;
395 }
396
397 qdf_spin_lock_bh(&priv_obj->lock);
398 priv_obj->ndi_delete_rsp_reason = val;
399 qdf_spin_unlock_bh(&priv_obj->lock);
400
401 return QDF_STATUS_SUCCESS;
402 }
403
ucfg_nan_get_ndi_delete_rsp_reason(struct wlan_objmgr_vdev * vdev)404 inline uint32_t ucfg_nan_get_ndi_delete_rsp_reason(
405 struct wlan_objmgr_vdev *vdev)
406 {
407 uint32_t val;
408 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
409
410 if (!priv_obj) {
411 nan_err("priv_obj is null");
412 return 0;
413 }
414
415 qdf_spin_lock_bh(&priv_obj->lock);
416 val = priv_obj->ndi_delete_rsp_reason;
417 qdf_spin_unlock_bh(&priv_obj->lock);
418
419 return val;
420 }
421
ucfg_nan_set_ndi_delete_rsp_status(struct wlan_objmgr_vdev * vdev,uint32_t val)422 inline QDF_STATUS ucfg_nan_set_ndi_delete_rsp_status(
423 struct wlan_objmgr_vdev *vdev, uint32_t val)
424 {
425 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
426
427 if (!priv_obj) {
428 nan_err("priv_obj is null");
429 return QDF_STATUS_E_NULL_VALUE;
430 }
431
432 qdf_spin_lock_bh(&priv_obj->lock);
433 priv_obj->ndi_delete_rsp_status = val;
434 qdf_spin_unlock_bh(&priv_obj->lock);
435
436 return QDF_STATUS_SUCCESS;
437 }
438
ucfg_nan_get_ndi_delete_rsp_status(struct wlan_objmgr_vdev * vdev)439 inline uint32_t ucfg_nan_get_ndi_delete_rsp_status(
440 struct wlan_objmgr_vdev *vdev)
441 {
442 uint32_t val;
443 struct nan_vdev_priv_obj *priv_obj = nan_get_vdev_priv_obj(vdev);
444
445 if (!priv_obj) {
446 nan_err("priv_obj is null");
447 return QDF_STATUS_E_NULL_VALUE;
448 }
449
450 qdf_spin_lock_bh(&priv_obj->lock);
451 val = priv_obj->ndi_delete_rsp_status;
452 qdf_spin_unlock_bh(&priv_obj->lock);
453
454 return val;
455 }
456
ucfg_nan_get_callbacks(struct wlan_objmgr_psoc * psoc,struct nan_callbacks * cb_obj)457 inline QDF_STATUS ucfg_nan_get_callbacks(struct wlan_objmgr_psoc *psoc,
458 struct nan_callbacks *cb_obj)
459 {
460 struct nan_psoc_priv_obj *psoc_obj = nan_get_psoc_priv_obj(psoc);
461
462 if (!psoc_obj) {
463 nan_err("nan psoc priv object is NULL");
464 return QDF_STATUS_E_NULL_VALUE;
465 }
466 qdf_spin_lock_bh(&psoc_obj->lock);
467 qdf_mem_copy(cb_obj, &psoc_obj->cb_obj, sizeof(*cb_obj));
468 qdf_spin_unlock_bh(&psoc_obj->lock);
469
470 return QDF_STATUS_SUCCESS;
471 }
472
ucfg_nan_sch_msg_flush_cb(struct scheduler_msg * msg)473 static QDF_STATUS ucfg_nan_sch_msg_flush_cb(struct scheduler_msg *msg)
474 {
475 struct wlan_objmgr_vdev *vdev = NULL;
476
477 if (!msg || !msg->bodyptr)
478 return QDF_STATUS_E_NULL_VALUE;
479
480 switch (msg->type) {
481 case NDP_INITIATOR_REQ:
482 vdev = ((struct nan_datapath_initiator_req *)
483 msg->bodyptr)->vdev;
484 break;
485 case NDP_RESPONDER_REQ:
486 vdev = ((struct nan_datapath_responder_req *)
487 msg->bodyptr)->vdev;
488 break;
489 case NDP_END_REQ:
490 vdev = ((struct nan_datapath_end_req *)msg->bodyptr)->vdev;
491 break;
492 case NDP_END_ALL:
493 vdev = ((struct nan_datapath_end_all_ndps *)msg->bodyptr)->vdev;
494 break;
495 default:
496 nan_err("Invalid NAN msg type during sch flush");
497 return QDF_STATUS_E_INVAL;
498 }
499
500 if (vdev) {
501 wlan_objmgr_vdev_release_ref(vdev, WLAN_NAN_ID);
502 qdf_mem_free(msg->bodyptr);
503 }
504
505 return QDF_STATUS_SUCCESS;
506 }
507
ucfg_nan_req_processor(struct wlan_objmgr_vdev * vdev,void * in_req,uint32_t req_type)508 QDF_STATUS ucfg_nan_req_processor(struct wlan_objmgr_vdev *vdev,
509 void *in_req, uint32_t req_type)
510 {
511 uint32_t len;
512 QDF_STATUS status;
513 struct scheduler_msg msg = {0};
514 int err;
515 struct nan_psoc_priv_obj *psoc_obj = NULL;
516 struct osif_request *request = NULL;
517 static const struct osif_request_params params = {
518 .priv_size = 0,
519 .timeout_ms = WLAN_WAIT_TIME_NDP_END,
520 };
521
522 if (!in_req) {
523 nan_alert("req is null");
524 return QDF_STATUS_E_NULL_VALUE;
525 }
526
527 switch (req_type) {
528 case NDP_INITIATOR_REQ:
529 len = sizeof(struct nan_datapath_initiator_req);
530 break;
531 case NDP_RESPONDER_REQ:
532 len = sizeof(struct nan_datapath_responder_req);
533 break;
534 case NDP_END_REQ:
535 len = sizeof(struct nan_datapath_end_req);
536 psoc_obj = nan_get_psoc_priv_obj(wlan_vdev_get_psoc(vdev));
537 if (!psoc_obj) {
538 nan_err("nan psoc priv object is NULL");
539 return QDF_STATUS_E_INVAL;
540 }
541 request = osif_request_alloc(¶ms);
542 if (!request) {
543 nan_err("Request allocation failure");
544 return QDF_STATUS_E_NOMEM;
545 }
546 psoc_obj->ndp_request_ctx = osif_request_cookie(request);
547 break;
548 case NDP_END_ALL:
549 len = sizeof(struct nan_datapath_end_all_ndps);
550 break;
551 default:
552 nan_err("in correct message req type: %d", req_type);
553 return QDF_STATUS_E_INVAL;
554 }
555
556 msg.bodyptr = qdf_mem_malloc(len);
557 if (!msg.bodyptr) {
558 status = QDF_STATUS_E_NOMEM;
559 goto fail;
560 }
561
562 qdf_mem_copy(msg.bodyptr, in_req, len);
563 msg.type = req_type;
564 msg.callback = nan_scheduled_msg_handler;
565 msg.flush_callback = ucfg_nan_sch_msg_flush_cb;
566 status = scheduler_post_message(QDF_MODULE_ID_HDD,
567 QDF_MODULE_ID_NAN,
568 QDF_MODULE_ID_OS_IF, &msg);
569 if (QDF_IS_STATUS_ERROR(status)) {
570 nan_err("failed to post msg to NAN component, status: %d",
571 status);
572 goto fail;
573 }
574
575 if (req_type == NDP_END_REQ) {
576 nan_debug("Wait for NDP END indication");
577 err = osif_request_wait_for_response(request);
578 if (err)
579 nan_debug("NAN request timed out: %d", err);
580 osif_request_put(request);
581 psoc_obj->ndp_request_ctx = NULL;
582 }
583
584 return QDF_STATUS_SUCCESS;
585
586 fail:
587 qdf_mem_free(msg.bodyptr);
588 if (req_type == NDP_END_REQ) {
589 osif_request_put(request);
590 psoc_obj->ndp_request_ctx = NULL;
591 }
592 return status;
593 }
594
ucfg_nan_datapath_event_handler(struct wlan_objmgr_psoc * psoc,struct wlan_objmgr_vdev * vdev,uint32_t type,void * msg)595 void ucfg_nan_datapath_event_handler(struct wlan_objmgr_psoc *psoc,
596 struct wlan_objmgr_vdev *vdev,
597 uint32_t type, void *msg)
598 {
599 struct nan_psoc_priv_obj *psoc_obj = nan_get_psoc_priv_obj(psoc);
600
601 if (!psoc_obj) {
602 nan_err("nan psoc priv object is NULL");
603 return;
604 }
605
606 psoc_obj->cb_obj.os_if_ndp_event_handler(psoc, vdev, type, msg);
607 }
608
ucfg_nan_request_process_cb(void * cookie)609 static void ucfg_nan_request_process_cb(void *cookie)
610 {
611 struct osif_request *request;
612
613 request = osif_request_get(cookie);
614 if (request) {
615 osif_request_complete(request);
616 osif_request_put(request);
617 } else {
618 nan_debug("Obsolete request (cookie:0x%pK), do nothing",
619 cookie);
620 }
621 }
622
623 #ifdef WLAN_FEATURE_SR
624 static void
nan_register_sr_concurrency_callback(struct nan_psoc_priv_obj * psoc_obj,struct nan_callbacks * cb_obj)625 nan_register_sr_concurrency_callback(struct nan_psoc_priv_obj *psoc_obj,
626 struct nan_callbacks *cb_obj)
627 {
628 psoc_obj->cb_obj.nan_sr_concurrency_update =
629 cb_obj->nan_sr_concurrency_update;
630 }
631 #else
632 static inline void
nan_register_sr_concurrency_callback(struct nan_psoc_priv_obj * psoc_obj,struct nan_callbacks * cb_obj)633 nan_register_sr_concurrency_callback(struct nan_psoc_priv_obj *psoc_obj,
634 struct nan_callbacks *cb_obj)
635 {}
636 #endif
637
ucfg_nan_register_hdd_callbacks(struct wlan_objmgr_psoc * psoc,struct nan_callbacks * cb_obj)638 int ucfg_nan_register_hdd_callbacks(struct wlan_objmgr_psoc *psoc,
639 struct nan_callbacks *cb_obj)
640 {
641 struct nan_psoc_priv_obj *psoc_obj = nan_get_psoc_priv_obj(psoc);
642
643 if (!psoc_obj) {
644 nan_err("nan psoc priv object is NULL");
645 return -EINVAL;
646 }
647
648 psoc_obj->cb_obj.ndi_open = cb_obj->ndi_open;
649 psoc_obj->cb_obj.ndi_set_mode = cb_obj->ndi_set_mode;
650 psoc_obj->cb_obj.ndi_start = cb_obj->ndi_start;
651 psoc_obj->cb_obj.ndi_delete = cb_obj->ndi_delete;
652 psoc_obj->cb_obj.ndi_close = cb_obj->ndi_close;
653 psoc_obj->cb_obj.drv_ndi_create_rsp_handler =
654 cb_obj->drv_ndi_create_rsp_handler;
655 psoc_obj->cb_obj.drv_ndi_delete_rsp_handler =
656 cb_obj->drv_ndi_delete_rsp_handler;
657
658 psoc_obj->cb_obj.new_peer_ind = cb_obj->new_peer_ind;
659 psoc_obj->cb_obj.peer_departed_ind = cb_obj->peer_departed_ind;
660 psoc_obj->cb_obj.os_if_ndp_event_handler =
661 cb_obj->os_if_ndp_event_handler;
662 psoc_obj->cb_obj.os_if_nan_event_handler =
663 cb_obj->os_if_nan_event_handler;
664 psoc_obj->cb_obj.ucfg_nan_request_process_cb =
665 ucfg_nan_request_process_cb;
666 psoc_obj->cb_obj.nan_concurrency_update =
667 cb_obj->nan_concurrency_update;
668 psoc_obj->cb_obj.set_mc_list = cb_obj->set_mc_list;
669
670 nan_register_sr_concurrency_callback(psoc_obj, cb_obj);
671 return 0;
672 }
673
ucfg_nan_register_lim_callbacks(struct wlan_objmgr_psoc * psoc,struct nan_callbacks * cb_obj)674 int ucfg_nan_register_lim_callbacks(struct wlan_objmgr_psoc *psoc,
675 struct nan_callbacks *cb_obj)
676 {
677 struct nan_psoc_priv_obj *psoc_obj = nan_get_psoc_priv_obj(psoc);
678
679 if (!psoc_obj) {
680 nan_err("nan psoc priv object is NULL");
681 return -EINVAL;
682 }
683
684 psoc_obj->cb_obj.add_ndi_peer = cb_obj->add_ndi_peer;
685 psoc_obj->cb_obj.ndp_delete_peers = cb_obj->ndp_delete_peers;
686 psoc_obj->cb_obj.delete_peers_by_addr = cb_obj->delete_peers_by_addr;
687
688 return 0;
689 }
690
ucfg_nan_register_wma_callbacks(struct wlan_objmgr_psoc * psoc,struct nan_callbacks * cb_obj)691 int ucfg_nan_register_wma_callbacks(struct wlan_objmgr_psoc *psoc,
692 struct nan_callbacks *cb_obj)
693 {
694 struct nan_psoc_priv_obj *psoc_obj = nan_get_psoc_priv_obj(psoc);
695
696 if (!psoc_obj) {
697 nan_err("nan psoc priv object is NULL");
698 return -EINVAL;
699 }
700
701 psoc_obj->cb_obj.update_ndi_conn = cb_obj->update_ndi_conn;
702
703 return 0;
704 }
705
ucfg_nan_set_tgt_caps(struct wlan_objmgr_psoc * psoc,struct nan_tgt_caps * nan_caps)706 void ucfg_nan_set_tgt_caps(struct wlan_objmgr_psoc *psoc,
707 struct nan_tgt_caps *nan_caps)
708 {
709 struct nan_psoc_priv_obj *psoc_priv = nan_get_psoc_priv_obj(psoc);
710
711 if (!psoc_priv) {
712 nan_err("nan psoc priv object is NULL");
713 return;
714 }
715
716 psoc_priv->nan_caps = *nan_caps;
717 }
718
ucfg_is_nan_conc_control_supported(struct wlan_objmgr_psoc * psoc)719 bool ucfg_is_nan_conc_control_supported(struct wlan_objmgr_psoc *psoc)
720 {
721 struct nan_psoc_priv_obj *psoc_priv;
722
723 psoc_priv = nan_get_psoc_priv_obj(psoc);
724 if (!psoc_priv) {
725 nan_err("nan psoc priv object is NULL");
726 return false;
727 }
728
729 return (psoc_priv->nan_caps.nan_conc_control == 1);
730 }
731
ucfg_is_nan_dbs_supported(struct wlan_objmgr_psoc * psoc)732 bool ucfg_is_nan_dbs_supported(struct wlan_objmgr_psoc *psoc)
733 {
734 struct nan_psoc_priv_obj *psoc_priv;
735
736 psoc_priv = nan_get_psoc_priv_obj(psoc);
737 if (!psoc_priv) {
738 nan_err("nan psoc priv object is NULL");
739 return false;
740 }
741
742 return (psoc_priv->nan_caps.nan_dbs_supported == 1);
743 }
744
ucfg_is_ndi_dbs_supported(struct wlan_objmgr_psoc * psoc)745 bool ucfg_is_ndi_dbs_supported(struct wlan_objmgr_psoc *psoc)
746 {
747 struct nan_psoc_priv_obj *psoc_priv;
748
749 psoc_priv = nan_get_psoc_priv_obj(psoc);
750 if (!psoc_priv) {
751 nan_err("nan psoc priv object is NULL");
752 return false;
753 }
754
755 return (psoc_priv->nan_caps.ndi_dbs_supported == 1);
756 }
757
ucfg_is_nan_enable_allowed(struct wlan_objmgr_psoc * psoc,uint32_t nan_ch_freq,uint8_t vdev_id)758 bool ucfg_is_nan_enable_allowed(struct wlan_objmgr_psoc *psoc,
759 uint32_t nan_ch_freq, uint8_t vdev_id)
760 {
761 return nan_is_enable_allowed(psoc, nan_ch_freq, vdev_id);
762 }
763
ucfg_is_nan_disc_active(struct wlan_objmgr_psoc * psoc)764 bool ucfg_is_nan_disc_active(struct wlan_objmgr_psoc *psoc)
765 {
766 return nan_is_disc_active(psoc);
767 }
768
ucfg_nan_discovery_req(void * in_req,uint32_t req_type)769 QDF_STATUS ucfg_nan_discovery_req(void *in_req, uint32_t req_type)
770 {
771 struct wlan_objmgr_psoc *psoc;
772 struct scheduler_msg msg = {0};
773 uint32_t len;
774 QDF_STATUS status;
775 struct nan_psoc_priv_obj *psoc_priv;
776 struct osif_request *request = NULL;
777 static const struct osif_request_params params = {
778 .priv_size = 0,
779 .timeout_ms = 4000,
780 };
781 int err = 0;
782 bool recovery;
783
784 if (!in_req) {
785 nan_alert("NAN Discovery req is null");
786 return QDF_STATUS_E_NULL_VALUE;
787 }
788
789 switch (req_type) {
790 case NAN_ENABLE_REQ: {
791 struct nan_enable_req *req = in_req;
792
793 psoc = req->psoc;
794 psoc_priv = nan_get_psoc_priv_obj(psoc);
795 if (!psoc_priv) {
796 nan_err("nan psoc priv object is NULL");
797 return QDF_STATUS_E_INVAL;
798 }
799
800 if (policy_mgr_is_sta_mon_concurrency(psoc))
801 return QDF_STATUS_E_INVAL;
802
803 /*
804 * Take a psoc reference while it is being used by the
805 * NAN requests.
806 */
807 status = wlan_objmgr_psoc_try_get_ref(psoc,
808 WLAN_NAN_ID);
809 if (QDF_IS_STATUS_ERROR(status)) {
810 nan_err("Couldn't obtain psoc ref");
811 return status;
812 }
813
814 status = nan_discovery_pre_enable(req->pdev,
815 req->social_chan_2g_freq);
816 if (QDF_IS_STATUS_SUCCESS(status)) {
817 len = sizeof(struct nan_enable_req) +
818 req->params.request_data_len;
819 } else {
820 wlan_objmgr_psoc_release_ref(psoc,
821 WLAN_NAN_ID);
822 return status;
823 }
824 break;
825 }
826 case NAN_DISABLE_REQ: {
827 struct nan_disable_req *req = in_req;
828
829 psoc = req->psoc;
830 psoc_priv = nan_get_psoc_priv_obj(psoc);
831 if (!psoc_priv) {
832 nan_err("nan psoc priv object is NULL");
833 return QDF_STATUS_E_INVAL;
834 }
835
836 status = wlan_objmgr_psoc_try_get_ref(psoc,
837 WLAN_NAN_ID);
838 if (QDF_IS_STATUS_ERROR(status)) {
839 nan_err("Couldn't obtain psoc ref");
840 return status;
841 }
842
843 status =
844 nan_set_discovery_state(req->psoc,
845 NAN_DISC_DISABLE_IN_PROGRESS);
846 if (QDF_IS_STATUS_SUCCESS(status)) {
847 len = sizeof(struct nan_disable_req) +
848 req->params.request_data_len;
849 } else {
850 wlan_objmgr_psoc_release_ref(psoc,
851 WLAN_NAN_ID);
852 return status;
853 }
854 break;
855 }
856 case NAN_GENERIC_REQ: {
857 struct nan_generic_req *req = in_req;
858
859 psoc = req->psoc;
860 psoc_priv = nan_get_psoc_priv_obj(psoc);
861 if (!psoc_priv) {
862 nan_err("nan psoc priv object is NULL");
863 return QDF_STATUS_E_INVAL;
864 }
865
866 status = wlan_objmgr_psoc_try_get_ref(psoc,
867 WLAN_NAN_ID);
868 if (QDF_IS_STATUS_ERROR(status)) {
869 nan_err("Couldn't obtain psoc ref");
870 return status;
871 }
872 len = sizeof(struct nan_generic_req) +
873 req->params.request_data_len;
874 break;
875 }
876 default:
877 nan_err("in correct message req type: %d", req_type);
878 return QDF_STATUS_E_INVAL;
879 }
880
881 msg.bodyptr = qdf_mem_malloc(len);
882 if (!msg.bodyptr) {
883 wlan_objmgr_psoc_release_ref(psoc, WLAN_NAN_ID);
884 return QDF_STATUS_E_NOMEM;
885 }
886
887 qdf_mem_copy(msg.bodyptr, in_req, len);
888 msg.type = req_type;
889 msg.callback = nan_discovery_scheduled_handler;
890 msg.flush_callback = nan_discovery_flush_callback;
891
892 if (req_type == NAN_GENERIC_REQ)
893 goto post_msg;
894
895 request = osif_request_alloc(¶ms);
896 if (!request) {
897 nan_err("Request allocation failure");
898 nan_discovery_flush_callback(&msg);
899 return QDF_STATUS_E_NOMEM;
900 }
901
902 psoc_priv->nan_disc_request_ctx = osif_request_cookie(request);
903 if (req_type == NAN_DISABLE_REQ)
904 psoc_priv->is_explicit_disable = true;
905
906 post_msg:
907 status = scheduler_post_message(QDF_MODULE_ID_NAN,
908 QDF_MODULE_ID_NAN,
909 QDF_MODULE_ID_OS_IF, &msg);
910 if (QDF_IS_STATUS_ERROR(status)) {
911 nan_err("failed to post msg to NAN component, status: %d",
912 status);
913 nan_discovery_flush_callback(&msg);
914 }
915
916 if (req_type != NAN_GENERIC_REQ) {
917 recovery = cds_is_driver_recovering();
918 if (!recovery)
919 err = osif_request_wait_for_response(request);
920 if (recovery || err) {
921 nan_debug("NAN request: %u recovery %d or timed out %d",
922 req_type, recovery, err);
923
924 if (req_type == NAN_ENABLE_REQ) {
925 nan_set_discovery_state(psoc,
926 NAN_DISC_DISABLED);
927 if (ucfg_is_nan_dbs_supported(psoc))
928 policy_mgr_check_n_start_opportunistic_timer(psoc);
929 nan_handle_emlsr_concurrency(psoc, false);
930
931 /*
932 * If FW respond with NAN enable failure, then
933 * TDLS should be enable again if there is TDLS
934 * connection exist earlier.
935 * decrement the active TDLS session.
936 */
937 ucfg_tdls_notify_connect_failure(psoc);
938 } else if (req_type == NAN_DISABLE_REQ) {
939 nan_disable_cleanup(psoc);
940 }
941 }
942 if (req_type == NAN_DISABLE_REQ)
943 psoc_priv->is_explicit_disable = false;
944 osif_request_put(request);
945 }
946
947 return status;
948 }
949
ucfg_nan_disable_concurrency(struct wlan_objmgr_psoc * psoc)950 void ucfg_nan_disable_concurrency(struct wlan_objmgr_psoc *psoc)
951 {
952 struct nan_disable_req nan_req = {0};
953 enum nan_disc_state curr_nan_state;
954 struct nan_psoc_priv_obj *psoc_priv;
955 QDF_STATUS status;
956
957 if (!psoc) {
958 nan_err("psoc object is NULL, no action will be taken");
959 return;
960 }
961
962 psoc_priv = nan_get_psoc_priv_obj(psoc);
963 if (!psoc_priv) {
964 nan_err("nan psoc priv object is NULL");
965 return;
966 }
967
968 if (!ucfg_is_nan_conc_control_supported(psoc))
969 return;
970
971 qdf_spin_lock_bh(&psoc_priv->lock);
972 curr_nan_state = nan_get_discovery_state(psoc);
973
974 if (curr_nan_state == NAN_DISC_DISABLED ||
975 curr_nan_state == NAN_DISC_DISABLE_IN_PROGRESS) {
976 qdf_spin_unlock_bh(&psoc_priv->lock);
977 return;
978 }
979 qdf_spin_unlock_bh(&psoc_priv->lock);
980
981 nan_req.psoc = psoc;
982 nan_req.disable_2g_discovery = true;
983 nan_req.disable_5g_discovery = true;
984
985 status = ucfg_nan_discovery_req(&nan_req, NAN_DISABLE_REQ);
986 if (QDF_IS_STATUS_ERROR(status)) {
987 nan_err("Unable to disable NAN Discovery");
988 return;
989 }
990
991 nan_debug("NAN Disabled successfully");
992 }
993
994 QDF_STATUS
ucfg_nan_disable_ndi(struct wlan_objmgr_psoc * psoc,uint32_t ndi_vdev_id)995 ucfg_nan_disable_ndi(struct wlan_objmgr_psoc *psoc, uint32_t ndi_vdev_id)
996 {
997 enum nan_datapath_state curr_ndi_state;
998 struct nan_vdev_priv_obj *ndi_vdev_priv;
999 struct nan_datapath_end_all_ndps req = {0};
1000 struct wlan_objmgr_vdev *ndi_vdev;
1001 struct osif_request *request;
1002 QDF_STATUS status;
1003 int err;
1004 static const struct osif_request_params params = {
1005 .priv_size = 0,
1006 .timeout_ms = 2000,
1007 };
1008
1009 if (!ucfg_is_ndi_dbs_supported(psoc))
1010 return QDF_STATUS_SUCCESS;
1011
1012 ndi_vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc, ndi_vdev_id,
1013 WLAN_NAN_ID);
1014 if (!ndi_vdev) {
1015 nan_err("Cannot obtain NDI vdev object!");
1016 return QDF_STATUS_E_INVAL;
1017 }
1018
1019 ndi_vdev_priv = nan_get_vdev_priv_obj(ndi_vdev);
1020 if (!ndi_vdev_priv) {
1021 nan_err("ndi vdev priv object is NULL");
1022 wlan_objmgr_vdev_release_ref(ndi_vdev, WLAN_NAN_ID);
1023 return QDF_STATUS_E_INVAL;
1024 }
1025 curr_ndi_state = ucfg_nan_get_ndi_state(ndi_vdev);
1026
1027 /*
1028 * Nothing to do if NDI is in DATA_END state.
1029 * Continue cleanup in NAN_DATA_NDI_DELETING_STATE as this API
1030 * can be called from hdd_ndi_delete.
1031 */
1032 if (curr_ndi_state == NAN_DATA_END_STATE) {
1033 wlan_objmgr_vdev_release_ref(ndi_vdev, WLAN_NAN_ID);
1034 return QDF_STATUS_SUCCESS;
1035 }
1036 ucfg_nan_set_ndi_state(ndi_vdev, NAN_DATA_END_STATE);
1037
1038 request = osif_request_alloc(¶ms);
1039 if (!request) {
1040 nan_err("Request allocation failure");
1041 status = QDF_STATUS_E_NOMEM;
1042 goto cleanup;
1043 }
1044 ndi_vdev_priv->disable_context = osif_request_cookie(request);
1045
1046 req.vdev = ndi_vdev;
1047 status = ucfg_nan_req_processor(NULL, &req, NDP_END_ALL);
1048
1049 if (QDF_IS_STATUS_ERROR(status)) {
1050 nan_err("Unable to disable NDP's on NDI");
1051 wlan_objmgr_vdev_release_ref(ndi_vdev, WLAN_NAN_ID);
1052 goto cleanup;
1053 }
1054
1055 nan_debug("Disabling all NDP's on NDI vdev id - %d", ndi_vdev_id);
1056
1057 err = osif_request_wait_for_response(request);
1058 if (err) {
1059 nan_err("Disabling NDP's timed out waiting for confirmation");
1060 status = QDF_STATUS_E_TIMEOUT;
1061 }
1062
1063 cleanup:
1064 /*
1065 * Host can assume NDP delete is successful and
1066 * remove policy mgr entry
1067 */
1068 policy_mgr_decr_session_set_pcl(psoc, QDF_NDI_MODE, ndi_vdev_id);
1069
1070 ucfg_nan_set_ndi_state(ndi_vdev, NAN_DATA_DISCONNECTED_STATE);
1071
1072 if (request)
1073 osif_request_put(request);
1074
1075 return status;
1076 }
1077
1078 QDF_STATUS
ucfg_nan_check_and_disable_unsupported_ndi(struct wlan_objmgr_psoc * psoc,bool force)1079 ucfg_nan_check_and_disable_unsupported_ndi(struct wlan_objmgr_psoc *psoc,
1080 bool force)
1081 {
1082 uint32_t ndi_count, first_ndi_vdev_id, i;
1083 QDF_STATUS status;
1084
1085 if (!psoc) {
1086 nan_err("psoc object is NULL, no action will be taken");
1087 return QDF_STATUS_E_INVAL;
1088 }
1089
1090 if (!ucfg_is_ndi_dbs_supported(psoc))
1091 return QDF_STATUS_SUCCESS;
1092
1093 ndi_count = policy_mgr_mode_specific_connection_count(psoc, PM_NDI_MODE,
1094 NULL);
1095 /* NDP force disable is done for unsupported concurrencies: NDI+SAP */
1096 if (force) {
1097 nan_debug("Force disable all NDPs");
1098 for (i = 0; i < ndi_count; i++) {
1099 first_ndi_vdev_id =
1100 policy_mgr_mode_specific_vdev_id(psoc,
1101 PM_NDI_MODE);
1102 status = ucfg_nan_disable_ndi(psoc, first_ndi_vdev_id);
1103 if (QDF_IS_STATUS_ERROR(status))
1104 return status;
1105 }
1106 return QDF_STATUS_SUCCESS;
1107 }
1108
1109 if (ndi_count < 2) {
1110 nan_debug("No more than one NDI is active, nothing to do...");
1111 return QDF_STATUS_SUCCESS;
1112 }
1113
1114 /*
1115 * At least 2 NDI active concurrencies exist. Disable all NDP's on the
1116 * first NDI to support an incoming connection.
1117 */
1118 first_ndi_vdev_id = policy_mgr_mode_specific_vdev_id(psoc, PM_NDI_MODE);
1119 status = ucfg_nan_disable_ndi(psoc, first_ndi_vdev_id);
1120
1121 return status;
1122 }
1123
ucfg_ndi_remove_entry_from_policy_mgr(struct wlan_objmgr_vdev * vdev)1124 QDF_STATUS ucfg_ndi_remove_entry_from_policy_mgr(struct wlan_objmgr_vdev *vdev)
1125 {
1126 struct wlan_objmgr_psoc *psoc;
1127 struct nan_psoc_priv_obj *psoc_priv_obj;
1128 struct nan_vdev_priv_obj *vdev_priv_obj = nan_get_vdev_priv_obj(vdev);
1129 enum nan_datapath_state state;
1130 uint32_t active_ndp_peers;
1131
1132 psoc = wlan_vdev_get_psoc(vdev);
1133 if (!psoc) {
1134 nan_err("can't get psoc");
1135 return QDF_STATUS_E_FAILURE;
1136 }
1137
1138 psoc_priv_obj = nan_get_psoc_priv_obj(psoc);
1139 if (!psoc_priv_obj) {
1140 nan_err("psoc_priv_obj is null");
1141 return QDF_STATUS_E_NULL_VALUE;
1142 }
1143
1144 if (!vdev_priv_obj) {
1145 nan_err("priv_obj is null");
1146 return QDF_STATUS_E_NULL_VALUE;
1147 }
1148
1149 qdf_spin_lock_bh(&vdev_priv_obj->lock);
1150 state = vdev_priv_obj->state;
1151 active_ndp_peers = vdev_priv_obj->active_ndp_peers;
1152 qdf_spin_unlock_bh(&vdev_priv_obj->lock);
1153
1154 if (state == NAN_DATA_NDI_DELETED_STATE &&
1155 NDI_CONCURRENCY_SUPPORTED(psoc) &&
1156 active_ndp_peers) {
1157 nan_info("Delete NDP peers: %u and remove NDI from policy mgr",
1158 active_ndp_peers);
1159 policy_mgr_decr_session_set_pcl(psoc, QDF_NDI_MODE,
1160 wlan_vdev_get_id(vdev));
1161 }
1162
1163 return QDF_STATUS_SUCCESS;
1164 }
1165
ucfg_nan_is_enable_disable_in_progress(struct wlan_objmgr_psoc * psoc)1166 bool ucfg_nan_is_enable_disable_in_progress(struct wlan_objmgr_psoc *psoc)
1167 {
1168 enum nan_disc_state nan_state;
1169
1170 nan_state = nan_get_discovery_state(psoc);
1171 if (nan_state == NAN_DISC_ENABLE_IN_PROGRESS ||
1172 nan_state == NAN_DISC_DISABLE_IN_PROGRESS) {
1173 nan_info("NAN enable/disable is in progress, state: %u",
1174 nan_state);
1175 return true;
1176 }
1177
1178 return false;
1179 }
1180
1181 #ifdef NDP_SAP_CONCURRENCY_ENABLE
1182 /**
1183 * is_sap_ndp_concurrency_allowed() - Is SAP+NDP allowed
1184 *
1185 * Return: True if the NDP_SAP_CONCURRENCY_ENABLE feature define
1186 * is enabled, false otherwise.
1187 */
is_sap_ndp_concurrency_allowed(void)1188 static inline bool is_sap_ndp_concurrency_allowed(void)
1189 {
1190 return true;
1191 }
1192 #else
is_sap_ndp_concurrency_allowed(void)1193 static inline bool is_sap_ndp_concurrency_allowed(void)
1194 {
1195 return false;
1196 }
1197 #endif
1198
ucfg_nan_is_sta_ndp_concurrency_allowed(struct wlan_objmgr_psoc * psoc,struct wlan_objmgr_vdev * vdev)1199 bool ucfg_nan_is_sta_ndp_concurrency_allowed(struct wlan_objmgr_psoc *psoc,
1200 struct wlan_objmgr_vdev *vdev)
1201 {
1202 uint8_t vdev_id_list[MAX_NUMBER_OF_CONC_CONNECTIONS];
1203 uint32_t freq_list[MAX_NUMBER_OF_CONC_CONNECTIONS];
1204 uint32_t ndi_cnt, id, conc_ext_flags;
1205
1206 if (nan_is_sta_sta_concurrency_present(psoc)) {
1207 nan_err("STA+STA+NDP concurrency is not allowed");
1208 return false;
1209 }
1210
1211 /*
1212 * SAP+NDP concurrency is already validated in hdd_is_ndp_allowed().
1213 * If SAP+NDP concurrency is enabled, return true from here to avoid
1214 * failure.
1215 */
1216 if (is_sap_ndp_concurrency_allowed())
1217 return true;
1218
1219 /* ML STA + NAN + NDP concurrency is allowed only if firmware
1220 * support is present
1221 */
1222 if (policy_mgr_is_mlo_sta_present(psoc) &&
1223 !wlan_is_mlo_sta_nan_ndi_allowed(psoc))
1224 return false;
1225
1226 ndi_cnt = policy_mgr_get_mode_specific_conn_info(psoc,
1227 freq_list,
1228 vdev_id_list,
1229 PM_NDI_MODE);
1230
1231 /* Allow if no other NDP peers are present on the NDIs */
1232 if (!ndi_cnt)
1233 return true;
1234
1235 /*
1236 * Allow NDP creation if the current NDP request is on
1237 * the NDI which already has an NDP by checking the vdev id of
1238 * the NDIs
1239 */
1240 for (id = 0; id < ndi_cnt; id++)
1241 if (wlan_vdev_get_id(vdev) == vdev_id_list[id])
1242 return true;
1243
1244 /* If the flow reaches here then it is 4th NDI with STA */
1245 if (!ucfg_nan_is_sta_nan_ndi_4_port_allowed(psoc))
1246 return false;
1247
1248 conc_ext_flags = policy_mgr_get_conc_ext_flags(vdev, false);
1249
1250 /* The final freq would be provided by FW, it is not known now */
1251 return policy_mgr_allow_concurrency(psoc, PM_NDI_MODE, 0,
1252 HW_MODE_20_MHZ, conc_ext_flags,
1253 wlan_vdev_get_id(vdev));
1254 }
1255
1256 bool
ucfg_nan_is_sta_nan_ndi_4_port_allowed(struct wlan_objmgr_psoc * psoc)1257 ucfg_nan_is_sta_nan_ndi_4_port_allowed(struct wlan_objmgr_psoc *psoc)
1258 {
1259 struct nan_psoc_priv_obj *psoc_nan_obj;
1260
1261 psoc_nan_obj = nan_get_psoc_priv_obj(psoc);
1262 if (!psoc_nan_obj) {
1263 nan_err("psoc_nan_obj is null");
1264 return false;
1265 }
1266
1267 return psoc_nan_obj->nan_caps.sta_nan_ndi_ndi_allowed;
1268 }
1269
ucfg_nan_is_beamforming_supported(struct wlan_objmgr_psoc * psoc)1270 bool ucfg_nan_is_beamforming_supported(struct wlan_objmgr_psoc *psoc)
1271 {
1272 struct nan_psoc_priv_obj *psoc_nan_obj;
1273
1274 psoc_nan_obj = nan_get_psoc_priv_obj(psoc);
1275 if (!psoc_nan_obj) {
1276 nan_err("psoc_nan_obj is null");
1277 return false;
1278 }
1279
1280 return psoc_nan_obj->nan_caps.ndi_txbf_supported;
1281 }
1282
1283 static inline bool
ucfg_is_nan_enabled(struct nan_psoc_priv_obj * psoc_nan_obj)1284 ucfg_is_nan_enabled(struct nan_psoc_priv_obj *psoc_nan_obj)
1285 {
1286 return psoc_nan_obj->cfg_param.enable;
1287 }
1288
1289 static inline bool
ucfg_nan_is_vdev_creation_supp_by_fw(struct nan_psoc_priv_obj * psoc_nan_obj)1290 ucfg_nan_is_vdev_creation_supp_by_fw(struct nan_psoc_priv_obj *psoc_nan_obj)
1291 {
1292 return psoc_nan_obj->nan_caps.nan_vdev_allowed;
1293 }
1294
1295 static inline bool
ucfg_nan_is_vdev_creation_supp_by_host(struct nan_psoc_priv_obj * nan_obj)1296 ucfg_nan_is_vdev_creation_supp_by_host(struct nan_psoc_priv_obj *nan_obj)
1297 {
1298 return nan_obj->cfg_param.nan_separate_iface_support;
1299 }
1300
ucfg_nan_cleanup_all_ndps(struct wlan_objmgr_psoc * psoc)1301 static void ucfg_nan_cleanup_all_ndps(struct wlan_objmgr_psoc *psoc)
1302 {
1303 QDF_STATUS status;
1304 uint32_t ndi_count, vdev_id, i;
1305
1306 ndi_count = policy_mgr_mode_specific_connection_count(psoc, PM_NDI_MODE,
1307 NULL);
1308 for (i = 0; i < ndi_count; i++) {
1309 vdev_id = policy_mgr_mode_specific_vdev_id(psoc, PM_NDI_MODE);
1310 status = ucfg_nan_disable_ndi(psoc, vdev_id);
1311 if (status == QDF_STATUS_E_TIMEOUT)
1312 policy_mgr_decr_session_set_pcl(psoc, QDF_NDI_MODE,
1313 vdev_id);
1314 }
1315 }
1316
ucfg_disable_nan_discovery(struct wlan_objmgr_psoc * psoc,uint8_t * data,uint32_t data_len)1317 QDF_STATUS ucfg_disable_nan_discovery(struct wlan_objmgr_psoc *psoc,
1318 uint8_t *data, uint32_t data_len)
1319 {
1320 struct nan_disable_req *nan_req;
1321 QDF_STATUS status;
1322
1323 ucfg_nan_cleanup_all_ndps(psoc);
1324
1325 nan_req = qdf_mem_malloc(sizeof(*nan_req) + data_len);
1326 if (!nan_req)
1327 return -ENOMEM;
1328 qdf_mem_zero(nan_req, sizeof(*nan_req) + data_len);
1329
1330 nan_req->psoc = psoc;
1331 nan_req->disable_2g_discovery = true;
1332 nan_req->disable_5g_discovery = true;
1333 if (data_len && data) {
1334 nan_req->params.request_data_len = data_len;
1335 qdf_mem_copy(nan_req->params.request_data, data, data_len);
1336 }
1337
1338 status = ucfg_nan_discovery_req(nan_req, NAN_DISABLE_REQ);
1339
1340 if (QDF_IS_STATUS_SUCCESS(status))
1341 nan_debug("Successfully sent NAN Disable request");
1342 else
1343 nan_debug("Unable to send NAN Disable request: %u", status);
1344
1345 qdf_mem_free(nan_req);
1346 return status;
1347 }
1348
ucfg_nan_is_vdev_creation_allowed(struct wlan_objmgr_psoc * psoc)1349 bool ucfg_nan_is_vdev_creation_allowed(struct wlan_objmgr_psoc *psoc)
1350 {
1351 struct nan_psoc_priv_obj *psoc_nan_obj;
1352 bool host_support, fw_support;
1353
1354 psoc_nan_obj = nan_get_psoc_priv_obj(psoc);
1355 if (!psoc_nan_obj) {
1356 nan_err("psoc_nan_obj is null");
1357 return false;
1358 }
1359
1360 if (!ucfg_is_nan_enabled(psoc_nan_obj)) {
1361 nan_debug("NAN is not enabled");
1362 return false;
1363 }
1364
1365 host_support = ucfg_nan_is_vdev_creation_supp_by_host(psoc_nan_obj);
1366 fw_support = ucfg_nan_is_vdev_creation_supp_by_fw(psoc_nan_obj);
1367 if (!host_support || !fw_support) {
1368 nan_debug("NAN separate vdev%s supported by host,%s supported by firmware",
1369 host_support ? "" : " not", fw_support ? "" : " not");
1370 return false;
1371 }
1372
1373 return true;
1374 }
1375
1376 void
ucfg_nan_set_vdev_creation_supp_by_fw(struct wlan_objmgr_psoc * psoc,bool set)1377 ucfg_nan_set_vdev_creation_supp_by_fw(struct wlan_objmgr_psoc *psoc, bool set)
1378 {
1379 struct nan_psoc_priv_obj *psoc_nan_obj;
1380
1381 psoc_nan_obj = nan_get_psoc_priv_obj(psoc);
1382 if (!psoc_nan_obj) {
1383 nan_err("psoc_nan_obj is null");
1384 return;
1385 }
1386
1387 psoc_nan_obj->nan_caps.nan_vdev_allowed = set;
1388 }
1389
ucfg_get_nan_feature_config(struct wlan_objmgr_psoc * psoc,uint32_t * nan_feature_config)1390 QDF_STATUS ucfg_get_nan_feature_config(struct wlan_objmgr_psoc *psoc,
1391 uint32_t *nan_feature_config)
1392 {
1393 struct nan_psoc_priv_obj *psoc_nan_obj;
1394
1395 psoc_nan_obj = nan_get_psoc_priv_obj(psoc);
1396 if (!psoc_nan_obj) {
1397 nan_err("psoc_nan_obj is null");
1398 *nan_feature_config = cfg_default(CFG_NAN_FEATURE_CONFIG);
1399 return QDF_STATUS_E_INVAL;
1400 }
1401
1402 *nan_feature_config = psoc_nan_obj->cfg_param.nan_feature_config;
1403 return QDF_STATUS_SUCCESS;
1404 }
1405
ucfg_is_nan_vdev(struct wlan_objmgr_vdev * vdev)1406 bool ucfg_is_nan_vdev(struct wlan_objmgr_vdev *vdev)
1407 {
1408 if (wlan_vdev_mlme_get_opmode(vdev) == QDF_NAN_DISC_MODE ||
1409 (!ucfg_nan_is_vdev_creation_allowed(wlan_vdev_get_psoc(vdev)) &&
1410 wlan_vdev_mlme_get_opmode(vdev) == QDF_STA_MODE))
1411 return true;
1412
1413 return false;
1414 }
1415
ucfg_nan_disable_ind_to_userspace(struct wlan_objmgr_psoc * psoc)1416 QDF_STATUS ucfg_nan_disable_ind_to_userspace(struct wlan_objmgr_psoc *psoc)
1417 {
1418 struct nan_psoc_priv_obj *psoc_nan_obj;
1419 struct nan_event_params *disable_ind;
1420 struct nan_disable_ind_msg msg = {
1421 .msg_hdr.msg_id = NAN_MSG_ID_DISABLE_INDICATION,
1422 .reason = 0, /* success */ };
1423
1424 psoc_nan_obj = nan_get_psoc_priv_obj(psoc);
1425 if (!psoc_nan_obj) {
1426 nan_err("psoc_nan_obj is null");
1427 return QDF_STATUS_E_INVAL;
1428 }
1429
1430 disable_ind = qdf_mem_malloc(sizeof(struct nan_event_params) +
1431 sizeof(msg));
1432 if (!disable_ind)
1433 return QDF_STATUS_E_NOMEM;
1434
1435 disable_ind->psoc = psoc,
1436 disable_ind->evt_type = nan_event_id_disable_ind;
1437 disable_ind->buf_len = sizeof(msg);
1438 qdf_mem_copy(disable_ind->buf, &msg, disable_ind->buf_len);
1439
1440 psoc_nan_obj->cb_obj.os_if_nan_event_handler(disable_ind);
1441
1442 qdf_mem_free(disable_ind);
1443 return QDF_STATUS_SUCCESS;
1444 }
1445
ucfg_is_nan_allowed_on_freq(struct wlan_objmgr_pdev * pdev,uint32_t freq)1446 bool ucfg_is_nan_allowed_on_freq(struct wlan_objmgr_pdev *pdev, uint32_t freq)
1447 {
1448 return wlan_is_nan_allowed_on_freq(pdev, freq);
1449 }
1450
ucfg_is_mlo_sta_nan_ndi_allowed(struct wlan_objmgr_psoc * psoc)1451 bool ucfg_is_mlo_sta_nan_ndi_allowed(struct wlan_objmgr_psoc *psoc)
1452 {
1453 return wlan_is_mlo_sta_nan_ndi_allowed(psoc);
1454 }
1455