1 /* 2 * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021-2022 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: defines driver functions interfacing with linux kernel 22 */ 23 24 #include <qdf_list.h> 25 #include <qdf_status.h> 26 #include <qdf_module.h> 27 #include <linux/wireless.h> 28 #include <linux/netdevice.h> 29 #include <net/cfg80211.h> 30 #include <wlan_scan_utils_api.h> 31 #include <wlan_cfg80211.h> 32 #include <wlan_cfg80211_scan.h> 33 #include <wlan_osif_priv.h> 34 #include <wlan_scan_public_structs.h> 35 #include <wlan_scan_ucfg_api.h> 36 #include <wlan_cfg80211_scan.h> 37 #include <qdf_mem.h> 38 #include <wlan_utility.h> 39 #include "cfg_ucfg_api.h" 40 #ifdef WLAN_POLICY_MGR_ENABLE 41 #include <wlan_policy_mgr_api.h> 42 #endif 43 #include <wlan_reg_services_api.h> 44 #ifdef FEATURE_WLAN_DIAG_SUPPORT 45 #include "host_diag_core_event.h" 46 #endif 47 48 const struct nla_policy cfg80211_scan_policy[ 49 QCA_WLAN_VENDOR_ATTR_SCAN_MAX + 1] = { 50 [QCA_WLAN_VENDOR_ATTR_SCAN_FLAGS] = {.type = NLA_U32}, 51 [QCA_WLAN_VENDOR_ATTR_SCAN_TX_NO_CCK_RATE] = {.type = NLA_FLAG}, 52 [QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE] = {.type = NLA_U64}, 53 }; 54 55 /** 56 * wlan_cfg80211_is_colocated_6ghz_scan_supported() - Check whether colocated 57 * 6ghz scan flag present in scan request or not 58 * @scan_flag: Flags bitmap comming from kernel 59 * 60 * Return: True if colocated 6ghz scan flag present in scan req 61 */ 62 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) 63 static bool 64 wlan_cfg80211_is_colocated_6ghz_scan_supported(uint32_t scan_flag) 65 { 66 return !!(scan_flag & NL80211_SCAN_FLAG_COLOCATED_6GHZ); 67 } 68 #else 69 static inline bool 70 wlan_cfg80211_is_colocated_6ghz_scan_supported(uint32_t scan_flag) 71 { 72 return false; 73 } 74 #endif 75 76 #if defined(CFG80211_SCAN_RANDOM_MAC_ADDR) || \ 77 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) 78 /** 79 * wlan_fill_scan_rand_attrs() - Populate the scan randomization attrs 80 * @vdev: pointer to objmgr vdev 81 * @flags: cfg80211 scan flags 82 * @mac_addr: random mac addr from cfg80211 83 * @mac_addr_mask: mac addr mask from cfg80211 84 * @randomize: output variable to check scan randomization status 85 * @addr: output variable to hold random addr 86 * @mask: output variable to hold mac mask 87 * 88 * Return: None 89 */ 90 static void wlan_fill_scan_rand_attrs(struct wlan_objmgr_vdev *vdev, 91 uint32_t flags, 92 uint8_t *mac_addr, 93 uint8_t *mac_addr_mask, 94 bool *randomize, 95 uint8_t *addr, 96 uint8_t *mask) 97 { 98 *randomize = false; 99 if (!(flags & NL80211_SCAN_FLAG_RANDOM_ADDR)) 100 return; 101 102 if (wlan_vdev_mlme_get_opmode(vdev) != QDF_STA_MODE) 103 return; 104 105 if (wlan_vdev_is_up(vdev) == QDF_STATUS_SUCCESS) 106 return; 107 108 *randomize = true; 109 memcpy(addr, mac_addr, QDF_MAC_ADDR_SIZE); 110 memcpy(mask, mac_addr_mask, QDF_MAC_ADDR_SIZE); 111 osif_debug("Random mac addr: "QDF_MAC_ADDR_FMT" and Random mac mask: "QDF_FULL_MAC_FMT, 112 QDF_MAC_ADDR_REF(addr), QDF_FULL_MAC_REF(mask)); 113 } 114 115 /** 116 * wlan_scan_rand_attrs() - Wrapper function to fill scan random attrs 117 * @vdev: pointer to objmgr vdev 118 * @request: pointer to cfg80211 scan request 119 * @req: pointer to cmn module scan request 120 * 121 * This is a wrapper function which invokes wlan_fill_scan_rand_attrs() 122 * to fill random attributes of internal scan request with cfg80211_scan_request 123 * 124 * Return: None 125 */ 126 static void wlan_scan_rand_attrs(struct wlan_objmgr_vdev *vdev, 127 struct cfg80211_scan_request *request, 128 struct scan_start_request *req) 129 { 130 bool *randomize = &req->scan_req.scan_random.randomize; 131 uint8_t *mac_addr = req->scan_req.scan_random.mac_addr; 132 uint8_t *mac_mask = req->scan_req.scan_random.mac_mask; 133 134 wlan_fill_scan_rand_attrs(vdev, request->flags, request->mac_addr, 135 request->mac_addr_mask, randomize, mac_addr, 136 mac_mask); 137 if (!*randomize) 138 return; 139 140 req->scan_req.scan_f_add_spoofed_mac_in_probe = true; 141 req->scan_req.scan_f_add_rand_seq_in_probe = true; 142 } 143 #else 144 /** 145 * wlan_scan_rand_attrs() - Wrapper function to fill scan random attrs 146 * @vdev: pointer to objmgr vdev 147 * @request: pointer to cfg80211 scan request 148 * @req: pointer to cmn module scan request 149 * 150 * This is a wrapper function which invokes wlan_fill_scan_rand_attrs() 151 * to fill random attributes of internal scan request with cfg80211_scan_request 152 * 153 * Return: None 154 */ 155 static void wlan_scan_rand_attrs(struct wlan_objmgr_vdev *vdev, 156 struct cfg80211_scan_request *request, 157 struct scan_start_request *req) 158 { 159 } 160 #endif 161 162 #ifdef FEATURE_WLAN_SCAN_PNO 163 #if ((LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) || \ 164 defined(CFG80211_MULTI_SCAN_PLAN_BACKPORT)) 165 166 /** 167 * wlan_config_sched_scan_plan() - configures the sched scan plans 168 * from the framework. 169 * @pno_req: pointer to PNO scan request 170 * @request: pointer to scan request from framework 171 * 172 * Return: None 173 */ 174 static void 175 wlan_config_sched_scan_plan(struct wlan_objmgr_psoc *psoc, 176 struct pno_scan_req_params *pno_req, 177 struct cfg80211_sched_scan_request *request) 178 { 179 if (!ucfg_scan_get_user_config_sched_scan_plan(psoc) || 180 request->n_scan_plans == 1) { 181 pno_req->fast_scan_period = 182 request->scan_plans[0].interval * MSEC_PER_SEC; 183 /* 184 * if only one scan plan is configured from framework 185 * then both fast and slow scan should be configured with the 186 * same value that is why fast scan cycles are hardcoded to one 187 */ 188 pno_req->fast_scan_max_cycles = 1; 189 pno_req->slow_scan_period = 190 request->scan_plans[0].interval * MSEC_PER_SEC; 191 } 192 /* 193 * As of now max 2 scan plans were supported by firmware 194 * if number of scan plan supported by firmware increased below logic 195 * must change. 196 */ 197 else if (request->n_scan_plans == SCAN_PNO_MAX_PLAN_REQUEST) { 198 pno_req->fast_scan_period = 199 request->scan_plans[0].interval * MSEC_PER_SEC; 200 pno_req->fast_scan_max_cycles = 201 request->scan_plans[0].iterations; 202 pno_req->slow_scan_period = 203 request->scan_plans[1].interval * MSEC_PER_SEC; 204 } else { 205 osif_err("Invalid number of scan plans %d !!", 206 request->n_scan_plans); 207 } 208 } 209 #else 210 #define wlan_config_sched_scan_plan(psoc, pno_req, request) \ 211 __wlan_config_sched_scan_plan(pno_req, request, psoc) 212 213 static void 214 __wlan_config_sched_scan_plan(struct pno_scan_req_params *pno_req, 215 struct cfg80211_sched_scan_request *request, 216 struct wlan_objmgr_psoc *psoc) 217 { 218 uint32_t scan_timer_repeat_value, slow_scan_multiplier; 219 220 scan_timer_repeat_value = ucfg_scan_get_scan_timer_repeat_value(psoc); 221 slow_scan_multiplier = ucfg_scan_get_slow_scan_multiplier(psoc); 222 223 pno_req->fast_scan_period = request->interval; 224 pno_req->fast_scan_max_cycles = scan_timer_repeat_value; 225 pno_req->slow_scan_period = 226 (slow_scan_multiplier * pno_req->fast_scan_period); 227 } 228 #endif 229 230 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0) 231 static inline void 232 wlan_cfg80211_sched_scan_results(struct wiphy *wiphy, uint64_t reqid) 233 { 234 cfg80211_sched_scan_results(wiphy); 235 } 236 #else 237 static inline void 238 wlan_cfg80211_sched_scan_results(struct wiphy *wiphy, uint64_t reqid) 239 { 240 cfg80211_sched_scan_results(wiphy, reqid); 241 } 242 #endif 243 244 /** 245 * wlan_cfg80211_pno_callback() - pno callback function to handle 246 * pno events. 247 * @vdev: vdev ptr 248 * @event: scan events 249 * @args: argument 250 * 251 * Return: void 252 */ 253 static void wlan_cfg80211_pno_callback(struct wlan_objmgr_vdev *vdev, 254 struct scan_event *event, 255 void *args) 256 { 257 struct wlan_objmgr_pdev *pdev; 258 struct pdev_osif_priv *pdev_ospriv; 259 260 if (event->type != SCAN_EVENT_TYPE_NLO_COMPLETE) 261 return; 262 263 osif_debug("vdev id = %d", event->vdev_id); 264 265 pdev = wlan_vdev_get_pdev(vdev); 266 if (!pdev) { 267 osif_err("pdev is NULL"); 268 return; 269 } 270 271 pdev_ospriv = wlan_pdev_get_ospriv(pdev); 272 if (!pdev_ospriv) { 273 osif_err("pdev_ospriv is NULL"); 274 return; 275 } 276 wlan_cfg80211_sched_scan_results(pdev_ospriv->wiphy, 0); 277 } 278 279 #ifdef WLAN_POLICY_MGR_ENABLE 280 static bool wlan_cfg80211_is_ap_go_present(struct wlan_objmgr_psoc *psoc) 281 { 282 return policy_mgr_mode_specific_connection_count(psoc, 283 PM_SAP_MODE, 284 NULL) || 285 policy_mgr_mode_specific_connection_count(psoc, 286 PM_P2P_GO_MODE, 287 NULL); 288 } 289 290 static QDF_STATUS wlan_cfg80211_is_chan_ok_for_dnbs( 291 struct wlan_objmgr_psoc *psoc, 292 u16 chan_freq, bool *ok) 293 { 294 QDF_STATUS status = policy_mgr_is_chan_ok_for_dnbs( 295 psoc, chan_freq, ok); 296 297 if (QDF_IS_STATUS_ERROR(status)) { 298 osif_err("DNBS check failed"); 299 return status; 300 } 301 302 return QDF_STATUS_SUCCESS; 303 } 304 #else 305 static bool wlan_cfg80211_is_ap_go_present(struct wlan_objmgr_psoc *psoc) 306 { 307 return false; 308 } 309 310 static QDF_STATUS wlan_cfg80211_is_chan_ok_for_dnbs( 311 struct wlan_objmgr_psoc *psoc, 312 u16 chan_freq, 313 bool *ok) 314 { 315 if (!ok) 316 return QDF_STATUS_E_INVAL; 317 318 *ok = true; 319 return QDF_STATUS_SUCCESS; 320 } 321 #endif 322 323 #if defined(CFG80211_SCAN_RANDOM_MAC_ADDR) || \ 324 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) 325 /** 326 * wlan_pno_scan_rand_attr() - Wrapper function to fill sched scan random attrs 327 * @vdev: pointer to objmgr vdev 328 * @request: pointer to cfg80211 sched scan request 329 * @req: pointer to cmn module pno scan request 330 * 331 * This is a wrapper function which invokes wlan_fill_scan_rand_attrs() 332 * to fill random attributes of internal pno scan 333 * with cfg80211_sched_scan_request 334 * 335 * Return: None 336 */ 337 static void wlan_pno_scan_rand_attr(struct wlan_objmgr_vdev *vdev, 338 struct cfg80211_sched_scan_request *request, 339 struct pno_scan_req_params *req) 340 { 341 bool *randomize = &req->scan_random.randomize; 342 uint8_t *mac_addr = req->scan_random.mac_addr; 343 uint8_t *mac_mask = req->scan_random.mac_mask; 344 345 wlan_fill_scan_rand_attrs(vdev, request->flags, request->mac_addr, 346 request->mac_addr_mask, randomize, mac_addr, 347 mac_mask); 348 } 349 #else 350 /** 351 * wlan_pno_scan_rand_attr() - Wrapper function to fill sched scan random attrs 352 * @vdev: pointer to objmgr vdev 353 * @request: pointer to cfg80211 sched scan request 354 * @req: pointer to cmn module pno scan request 355 * 356 * This is a wrapper function which invokes wlan_fill_scan_rand_attrs() 357 * to fill random attributes of internal pno scan 358 * with cfg80211_sched_scan_request 359 * 360 * Return: None 361 */ 362 static void wlan_pno_scan_rand_attr(struct wlan_objmgr_vdev *vdev, 363 struct cfg80211_sched_scan_request *request, 364 struct pno_scan_req_params *req) 365 { 366 } 367 #endif 368 369 /** 370 * wlan_hdd_sched_scan_update_relative_rssi() - update CPNO params 371 * @pno_request: pointer to PNO scan request 372 * @request: Pointer to cfg80211 scheduled scan start request 373 * 374 * This function is used to update Connected PNO params sent by kernel 375 * 376 * Return: None 377 */ 378 #if defined(CFG80211_REPORT_BETTER_BSS_IN_SCHED_SCAN) || \ 379 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)) 380 static inline void wlan_hdd_sched_scan_update_relative_rssi( 381 struct pno_scan_req_params *pno_request, 382 struct cfg80211_sched_scan_request *request) 383 { 384 pno_request->relative_rssi_set = request->relative_rssi_set; 385 pno_request->relative_rssi = request->relative_rssi; 386 if (NL80211_BAND_2GHZ == request->rssi_adjust.band) 387 pno_request->band_rssi_pref.band = WLAN_BAND_2_4_GHZ; 388 else if (NL80211_BAND_5GHZ == request->rssi_adjust.band) 389 pno_request->band_rssi_pref.band = WLAN_BAND_5_GHZ; 390 pno_request->band_rssi_pref.rssi = request->rssi_adjust.delta; 391 } 392 #else 393 static inline void wlan_hdd_sched_scan_update_relative_rssi( 394 struct pno_scan_req_params *pno_request, 395 struct cfg80211_sched_scan_request *request) 396 { 397 } 398 #endif 399 400 #ifdef FEATURE_WLAN_SCAN_PNO 401 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) 402 static uint32_t wlan_config_sched_scan_start_delay( 403 struct cfg80211_sched_scan_request *request) 404 { 405 return request->delay; 406 } 407 #else 408 static uint32_t wlan_config_sched_scan_start_delay( 409 struct cfg80211_sched_scan_request *request) 410 { 411 return 0; 412 } 413 #endif /*(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) */ 414 #endif /* FEATURE_WLAN_SCAN_PNO */ 415 416 int wlan_cfg80211_sched_scan_start(struct wlan_objmgr_vdev *vdev, 417 struct cfg80211_sched_scan_request *request, 418 uint8_t scan_backoff_multiplier) 419 { 420 struct pno_scan_req_params *req; 421 int i, j, ret = 0; 422 QDF_STATUS status; 423 uint8_t num_chan = 0; 424 uint8_t updated_num_chan = 0; 425 uint16_t chan_freq; 426 struct wlan_objmgr_pdev *pdev = wlan_vdev_get_pdev(vdev); 427 struct wlan_objmgr_psoc *psoc; 428 uint32_t valid_ch[SCAN_PNO_MAX_NETW_CHANNELS_EX] = {0}; 429 bool enable_dfs_pno_chnl_scan; 430 431 if (ucfg_scan_get_pno_in_progress(vdev)) { 432 osif_debug("pno is already in progress"); 433 return -EBUSY; 434 } 435 436 if (ucfg_scan_get_pdev_status(pdev) != 437 SCAN_NOT_IN_PROGRESS) { 438 status = wlan_abort_scan(pdev, 439 wlan_objmgr_pdev_get_pdev_id(pdev), 440 INVAL_VDEV_ID, INVAL_SCAN_ID, true); 441 if (QDF_IS_STATUS_ERROR(status)) 442 return -EBUSY; 443 } 444 445 req = qdf_mem_malloc(sizeof(*req)); 446 if (!req) 447 return -ENOMEM; 448 449 wlan_pdev_obj_lock(pdev); 450 psoc = wlan_pdev_get_psoc(pdev); 451 wlan_pdev_obj_unlock(pdev); 452 453 req->networks_cnt = request->n_match_sets; 454 req->vdev_id = wlan_vdev_get_id(vdev); 455 req->vdev = vdev; 456 req->scan_policy_colocated_6ghz = 457 wlan_cfg80211_is_colocated_6ghz_scan_supported(request->flags); 458 459 if ((!req->networks_cnt) || 460 (req->networks_cnt > SCAN_PNO_MAX_SUPP_NETWORKS)) { 461 osif_err("Network input is not correct %d", 462 req->networks_cnt); 463 ret = -EINVAL; 464 goto error; 465 } 466 467 if (request->n_channels > SCAN_PNO_MAX_NETW_CHANNELS_EX) { 468 osif_err("Incorrect number of channels %d", 469 request->n_channels); 470 ret = -EINVAL; 471 goto error; 472 } 473 474 enable_dfs_pno_chnl_scan = ucfg_scan_is_dfs_chnl_scan_enabled(psoc); 475 if (request->n_channels) { 476 uint32_t buff_len; 477 char *chl; 478 int len = 0; 479 bool ap_or_go_present = wlan_cfg80211_is_ap_go_present(psoc); 480 481 buff_len = (request->n_channels * 5) + 1; 482 chl = qdf_mem_malloc(buff_len); 483 if (!chl) { 484 ret = -ENOMEM; 485 goto error; 486 } 487 for (i = 0; i < request->n_channels; i++) { 488 chan_freq = request->channels[i]->center_freq; 489 if ((!enable_dfs_pno_chnl_scan) && 490 (wlan_reg_is_dfs_for_freq(pdev, chan_freq))) { 491 osif_debug("Dropping DFS channel freq :%d", 492 chan_freq); 493 continue; 494 } 495 if (wlan_reg_is_dsrc_freq(chan_freq)) 496 continue; 497 498 if (ap_or_go_present) { 499 bool ok; 500 501 status = 502 wlan_cfg80211_is_chan_ok_for_dnbs(psoc, 503 chan_freq, 504 &ok); 505 if (QDF_IS_STATUS_ERROR(status)) { 506 osif_err("DNBS check failed"); 507 qdf_mem_free(chl); 508 chl = NULL; 509 ret = -EINVAL; 510 goto error; 511 } 512 if (!ok) 513 continue; 514 } 515 len += qdf_scnprintf(chl + len, buff_len - len, " %d", chan_freq); 516 valid_ch[num_chan++] = chan_freq; 517 } 518 osif_debug("Channel-List[%d]:%s", num_chan, chl); 519 qdf_mem_free(chl); 520 chl = NULL; 521 /* If all channels are DFS and dropped, 522 * then ignore the PNO request 523 */ 524 if (!num_chan) { 525 osif_notice("Channel list empty due to filtering of DSRC"); 526 ret = -EINVAL; 527 goto error; 528 } 529 } 530 531 /* Filling per profile params */ 532 for (i = 0; i < req->networks_cnt; i++) { 533 struct cfg80211_match_set *user_req = &request->match_sets[i]; 534 struct pno_nw_type *tgt_req = &req->networks_list[i]; 535 536 tgt_req->ssid.length = user_req->ssid.ssid_len; 537 538 if (!tgt_req->ssid.length || 539 tgt_req->ssid.length > WLAN_SSID_MAX_LEN) { 540 osif_err(" SSID Len %d is not correct for network %d", 541 tgt_req->ssid.length, i); 542 ret = -EINVAL; 543 goto error; 544 } 545 546 qdf_mem_copy(tgt_req->ssid.ssid, user_req->ssid.ssid, 547 tgt_req->ssid.length); 548 tgt_req->authentication = 0; /*eAUTH_TYPE_ANY */ 549 tgt_req->encryption = 0; /*eED_ANY */ 550 tgt_req->bc_new_type = 0; /*eBCAST_UNKNOWN */ 551 552 553 /*Copying list of valid channel into request */ 554 for (j = 0; j < num_chan; j++) 555 tgt_req->pno_chan_list.chan[j].freq = valid_ch[j]; 556 tgt_req->pno_chan_list.num_chan = num_chan; 557 558 if (ucfg_is_6ghz_pno_scan_optimization_supported(psoc)) { 559 uint32_t short_ssid = 560 wlan_construct_shortssid(tgt_req->ssid.ssid, 561 tgt_req->ssid.length); 562 updated_num_chan = num_chan; 563 ucfg_scan_add_flags_to_pno_chan_list(vdev, req, 564 &updated_num_chan, 565 short_ssid, i); 566 } 567 568 tgt_req->rssi_thresh = user_req->rssi_thold; 569 } 570 571 /* set scan to passive if no SSIDs are specified in the request */ 572 if (0 == request->n_ssids) 573 req->do_passive_scan = true; 574 else 575 req->do_passive_scan = false; 576 577 for (i = 0; i < request->n_ssids; i++) { 578 j = 0; 579 while (j < req->networks_cnt) { 580 if ((req->networks_list[j].ssid.length == 581 request->ssids[i].ssid_len) && 582 (!qdf_mem_cmp(req->networks_list[j].ssid.ssid, 583 request->ssids[i].ssid, 584 req->networks_list[j].ssid.length))) { 585 req->networks_list[j].bc_new_type = 586 SSID_BC_TYPE_HIDDEN; 587 break; 588 } 589 j++; 590 } 591 } 592 593 /* 594 * Before Kernel 4.4 595 * Driver gets only one time interval which is hard coded in 596 * supplicant for 10000ms. 597 * 598 * After Kernel 4.4 599 * User can configure multiple scan_plans, each scan would have 600 * separate scan cycle and interval. (interval is in unit of second.) 601 * For our use case, we would only have supplicant set one scan_plan, 602 * and firmware also support only one as well, so pick up the first 603 * index. 604 * 605 * Taking power consumption into account 606 * firmware after gPNOScanTimerRepeatValue times fast_scan_period 607 * switches slow_scan_period. This is less frequent scans and firmware 608 * shall be in slow_scan_period mode until next PNO Start. 609 */ 610 wlan_config_sched_scan_plan(psoc, req, request); 611 req->delay_start_time = wlan_config_sched_scan_start_delay(request); 612 req->scan_backoff_multiplier = scan_backoff_multiplier; 613 614 wlan_hdd_sched_scan_update_relative_rssi(req, request); 615 616 psoc = wlan_pdev_get_psoc(pdev); 617 ucfg_scan_register_pno_cb(psoc, 618 wlan_cfg80211_pno_callback, NULL); 619 ucfg_scan_get_pno_def_params(vdev, req); 620 621 if (req->scan_random.randomize) 622 wlan_pno_scan_rand_attr(vdev, request, req); 623 624 if (ucfg_ie_allowlist_enabled(psoc, vdev)) 625 ucfg_copy_ie_allowlist_attrs(psoc, &req->ie_allowlist); 626 627 osif_debug("Network count %d n_ssids %d fast_scan_period: %d msec slow_scan_period: %d msec, fast_scan_max_cycles: %d, relative_rssi %d band_pref %d, rssi_pref %d", 628 req->networks_cnt, request->n_ssids, req->fast_scan_period, 629 req->slow_scan_period, req->fast_scan_max_cycles, 630 req->relative_rssi, req->band_rssi_pref.band, 631 req->band_rssi_pref.rssi); 632 633 for (i = 0; i < req->networks_cnt; i++) 634 osif_debug("[%d] ssid: %.*s, RSSI th %d bc NW type %u", 635 i, req->networks_list[i].ssid.length, 636 req->networks_list[i].ssid.ssid, 637 req->networks_list[i].rssi_thresh, 638 req->networks_list[i].bc_new_type); 639 640 status = ucfg_scan_pno_start(vdev, req); 641 if (QDF_IS_STATUS_ERROR(status)) { 642 osif_err("Failed to enable PNO"); 643 ret = -EINVAL; 644 goto error; 645 } 646 647 error: 648 qdf_mem_free(req); 649 return ret; 650 } 651 652 int wlan_cfg80211_sched_scan_stop(struct wlan_objmgr_vdev *vdev) 653 { 654 QDF_STATUS status; 655 656 status = ucfg_scan_pno_stop(vdev); 657 if (QDF_IS_STATUS_ERROR(status)) 658 osif_debug("Failed to disable PNO"); 659 660 return 0; 661 } 662 #endif /*FEATURE_WLAN_SCAN_PNO */ 663 664 /** 665 * wlan_copy_bssid_scan_request() - API to copy the bssid to Scan request 666 * @scan_req: Pointer to scan_start_request 667 * @request: scan request from Supplicant 668 * 669 * This API copies the BSSID in scan request from Supplicant and copies it to 670 * the scan_start_request 671 * 672 * Return: None 673 */ 674 #if defined(CFG80211_SCAN_BSSID) || \ 675 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)) 676 static inline void 677 wlan_copy_bssid_scan_request(struct scan_start_request *scan_req, 678 struct cfg80211_scan_request *request) 679 { 680 qdf_mem_copy(scan_req->scan_req.bssid_list[0].bytes, 681 request->bssid, QDF_MAC_ADDR_SIZE); 682 } 683 #else 684 static inline void 685 wlan_copy_bssid_scan_request(struct scan_start_request *scan_req, 686 struct cfg80211_scan_request *request) 687 { 688 689 } 690 #endif 691 692 /** 693 * wlan_schedule_scan_start_request() - Schedule scan start request 694 * @pdev: pointer to pdev object 695 * @req: Pointer to the scan request 696 * @source: source of the scan request 697 * @scan_start_req: pointer to scan start request 698 * 699 * Schedule scan start request and enqueue scan request in the global scan 700 * list. This list stores the active scan request information. 701 * 702 * Return: QDF_STATUS 703 */ 704 static QDF_STATUS 705 wlan_schedule_scan_start_request(struct wlan_objmgr_pdev *pdev, 706 struct cfg80211_scan_request *req, 707 uint8_t source, 708 struct scan_start_request *scan_start_req) 709 { 710 struct scan_req *scan_req; 711 QDF_STATUS status; 712 struct pdev_osif_priv *osif_ctx; 713 struct osif_scan_pdev *osif_scan; 714 715 scan_req = qdf_mem_malloc(sizeof(*scan_req)); 716 if (!scan_req) { 717 ucfg_scm_scan_free_scan_request_mem(scan_start_req); 718 return QDF_STATUS_E_NOMEM; 719 } 720 721 /* Get NL global context from objmgr*/ 722 osif_ctx = wlan_pdev_get_ospriv(pdev); 723 osif_scan = osif_ctx->osif_scan; 724 scan_req->scan_request = req; 725 scan_req->source = source; 726 scan_req->scan_id = scan_start_req->scan_req.scan_id; 727 scan_req->dev = req->wdev->netdev; 728 scan_req->scan_start_timestamp = qdf_get_time_of_the_day_ms(); 729 730 qdf_mutex_acquire(&osif_scan->scan_req_q_lock); 731 if (qdf_list_size(&osif_scan->scan_req_q) < WLAN_MAX_SCAN_COUNT) { 732 status = ucfg_scan_start(scan_start_req); 733 if (QDF_IS_STATUS_SUCCESS(status)) { 734 qdf_list_insert_back(&osif_scan->scan_req_q, 735 &scan_req->node); 736 } else { 737 osif_err("scan req failed with error %d", status); 738 if (status == QDF_STATUS_E_RESOURCES) 739 osif_err("HO is in progress.So defer the scan by informing busy"); 740 } 741 } else { 742 ucfg_scm_scan_free_scan_request_mem(scan_start_req); 743 status = QDF_STATUS_E_RESOURCES; 744 } 745 746 qdf_mutex_release(&osif_scan->scan_req_q_lock); 747 if (QDF_IS_STATUS_ERROR(status)) { 748 osif_rl_debug("Failed to enqueue Scan Req as max scan %d already queued", 749 qdf_list_size(&osif_scan->scan_req_q)); 750 qdf_mem_free(scan_req); 751 } 752 753 return status; 754 } 755 756 /** 757 * wlan_scan_request_dequeue() - dequeue scan request 758 * @nl_ctx: Global HDD context 759 * @scan_id: scan id 760 * @req: scan request 761 * @dev: net device 762 * @source : returns source of the scan request 763 * 764 * Return: QDF_STATUS 765 */ 766 static QDF_STATUS wlan_scan_request_dequeue( 767 struct wlan_objmgr_pdev *pdev, 768 uint32_t scan_id, struct cfg80211_scan_request **req, 769 uint8_t *source, struct net_device **dev, 770 qdf_time_t *scan_start_timestamp) 771 { 772 QDF_STATUS status = QDF_STATUS_E_FAILURE; 773 struct scan_req *scan_req; 774 qdf_list_node_t *node = NULL, *next_node = NULL; 775 struct pdev_osif_priv *osif_ctx; 776 struct osif_scan_pdev *scan_priv; 777 778 if ((!source) || (!req)) { 779 osif_err("source or request is NULL"); 780 return QDF_STATUS_E_NULL_VALUE; 781 } 782 783 /* Get NL global context from objmgr*/ 784 osif_ctx = wlan_pdev_get_ospriv(pdev); 785 if (!osif_ctx) { 786 osif_err("Failed to retrieve osif context"); 787 return status; 788 } 789 scan_priv = osif_ctx->osif_scan; 790 791 qdf_mutex_acquire(&scan_priv->scan_req_q_lock); 792 if (qdf_list_empty(&scan_priv->scan_req_q)) { 793 osif_info("Scan List is empty"); 794 qdf_mutex_release(&scan_priv->scan_req_q_lock); 795 return QDF_STATUS_E_FAILURE; 796 } 797 798 if (QDF_STATUS_SUCCESS != 799 qdf_list_peek_front(&scan_priv->scan_req_q, &next_node)) { 800 qdf_mutex_release(&scan_priv->scan_req_q_lock); 801 osif_err("Failed to remove Scan Req from queue"); 802 return QDF_STATUS_E_FAILURE; 803 } 804 805 do { 806 node = next_node; 807 scan_req = qdf_container_of(node, struct scan_req, node); 808 if (scan_req->scan_id == scan_id) { 809 status = qdf_list_remove_node(&scan_priv->scan_req_q, 810 node); 811 if (status == QDF_STATUS_SUCCESS) { 812 *req = scan_req->scan_request; 813 *source = scan_req->source; 814 *dev = scan_req->dev; 815 *scan_start_timestamp = 816 scan_req->scan_start_timestamp; 817 qdf_mem_free(scan_req); 818 qdf_mutex_release(&scan_priv->scan_req_q_lock); 819 osif_debug("removed Scan id: %d, req = %pK, pending scans %d", 820 scan_id, req, 821 qdf_list_size(&scan_priv->scan_req_q)); 822 return QDF_STATUS_SUCCESS; 823 } else { 824 qdf_mutex_release(&scan_priv->scan_req_q_lock); 825 osif_err("Failed to remove scan id %d, pending scans %d", 826 scan_id, 827 qdf_list_size(&scan_priv->scan_req_q)); 828 return status; 829 } 830 } 831 } while (QDF_STATUS_SUCCESS == 832 qdf_list_peek_next(&scan_priv->scan_req_q, node, &next_node)); 833 qdf_mutex_release(&scan_priv->scan_req_q_lock); 834 osif_debug("Failed to find scan id %d", scan_id); 835 836 return status; 837 } 838 839 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)) 840 /** 841 * wlan_cfg80211_scan_done() - Scan completed callback to cfg80211 842 * @netdev: Net device 843 * @req : Scan request 844 * @aborted : true scan aborted false scan success 845 * @osif_priv: OS private structure 846 * 847 * This function notifies scan done to cfg80211 848 * 849 * Return: none 850 */ 851 void wlan_cfg80211_scan_done(struct net_device *netdev, 852 struct cfg80211_scan_request *req, 853 bool aborted, struct pdev_osif_priv *osif_priv) 854 { 855 struct cfg80211_scan_info info = { 856 .aborted = aborted 857 }; 858 bool driver_internal_netdev_state; 859 860 driver_internal_netdev_state = netdev->flags & IFF_UP; 861 if (osif_priv->osif_check_netdev_state) 862 driver_internal_netdev_state = 863 osif_priv->osif_check_netdev_state(netdev); 864 865 if (driver_internal_netdev_state) 866 cfg80211_scan_done(req, &info); 867 else 868 osif_debug("scan done callback has been dropped :%s", 869 (netdev)->name); 870 } 871 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) 872 /** 873 * wlan_cfg80211_scan_done() - Scan completed callback to cfg80211 874 * @netdev: Net device 875 * @req : Scan request 876 * @aborted : true scan aborted false scan success 877 * @osif_priv - OS private structure 878 * 879 * This function notifies scan done to cfg80211 880 * 881 * Return: none 882 */ 883 void wlan_cfg80211_scan_done(struct net_device *netdev, 884 struct cfg80211_scan_request *req, 885 bool aborted, struct pdev_osif_priv *osif_priv) 886 { 887 bool driver_internal_net_state; 888 889 driver_internal_netdev_state = netdev->flags & IFF_UP; 890 if (osif_priv->osif_check_netdev_state) 891 driver_internal_net_state = 892 osif_priv->osif_check_netdev_state(netdev); 893 894 if (driver_internal_netdev_state) 895 cfg80211_scan_done(req, aborted); 896 else 897 osif_debug("scan request has been dropped :%s", (netdev)->name); 898 } 899 #endif 900 901 /** 902 * wlan_vendor_scan_callback() - Scan completed callback event 903 * 904 * @req : Scan request 905 * @aborted : true scan aborted false scan success 906 * 907 * This function sends scan completed callback event to NL. 908 * 909 * Return: none 910 */ 911 static void wlan_vendor_scan_callback(struct cfg80211_scan_request *req, 912 bool aborted) 913 { 914 struct sk_buff *skb; 915 struct nlattr *attr; 916 int i; 917 uint8_t scan_status; 918 uint64_t cookie; 919 int index = QCA_NL80211_VENDOR_SUBCMD_SCAN_DONE_INDEX; 920 921 skb = wlan_cfg80211_vendor_event_alloc(req->wdev->wiphy, req->wdev, 922 SCAN_DONE_EVENT_BUF_SIZE + 4 + 923 NLMSG_HDRLEN, 924 index, 925 GFP_ATOMIC); 926 927 if (!skb) { 928 osif_err("skb alloc failed"); 929 qdf_mem_free(req); 930 return; 931 } 932 933 cookie = (uintptr_t)req; 934 935 attr = nla_nest_start(skb, QCA_WLAN_VENDOR_ATTR_SCAN_SSIDS); 936 if (!attr) 937 goto nla_put_failure; 938 for (i = 0; i < req->n_ssids; i++) { 939 if (nla_put(skb, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) 940 goto nla_put_failure; 941 } 942 nla_nest_end(skb, attr); 943 944 attr = nla_nest_start(skb, QCA_WLAN_VENDOR_ATTR_SCAN_FREQUENCIES); 945 if (!attr) 946 goto nla_put_failure; 947 for (i = 0; i < req->n_channels; i++) { 948 if (nla_put_u32(skb, i, req->channels[i]->center_freq)) 949 goto nla_put_failure; 950 } 951 nla_nest_end(skb, attr); 952 953 if (req->ie && 954 nla_put(skb, QCA_WLAN_VENDOR_ATTR_SCAN_IE, req->ie_len, 955 req->ie)) 956 goto nla_put_failure; 957 958 if (req->flags && 959 nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_SCAN_FLAGS, req->flags)) 960 goto nla_put_failure; 961 962 if (wlan_cfg80211_nla_put_u64(skb, QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE, 963 cookie)) 964 goto nla_put_failure; 965 966 scan_status = (aborted == true) ? VENDOR_SCAN_STATUS_ABORTED : 967 VENDOR_SCAN_STATUS_NEW_RESULTS; 968 if (nla_put_u8(skb, QCA_WLAN_VENDOR_ATTR_SCAN_STATUS, scan_status)) 969 goto nla_put_failure; 970 971 wlan_cfg80211_vendor_event(skb, GFP_ATOMIC); 972 qdf_mem_free(req); 973 974 return; 975 976 nla_put_failure: 977 wlan_cfg80211_vendor_free_skb(skb); 978 qdf_mem_free(req); 979 } 980 981 /** 982 * wlan_scan_acquire_wake_lock_timeout() - acquire scan wake lock 983 * @psoc: psoc ptr 984 * @scan_wake_lock: Scan wake lock 985 * @timeout: timeout in ms 986 * 987 * Return: void 988 */ 989 static inline 990 void wlan_scan_acquire_wake_lock_timeout(struct wlan_objmgr_psoc *psoc, 991 qdf_wake_lock_t *scan_wake_lock, 992 uint32_t timeout) 993 { 994 if (!psoc || !scan_wake_lock) 995 return; 996 997 if (ucfg_scan_wake_lock_in_user_scan(psoc)) 998 qdf_wake_lock_timeout_acquire(scan_wake_lock, timeout); 999 } 1000 1001 1002 /** 1003 * wlan_scan_release_wake_lock() - release scan wake lock 1004 * @psoc: psoc ptr 1005 * @scan_wake_lock: Scan wake lock 1006 * 1007 * Return: void 1008 */ 1009 #ifdef FEATURE_WLAN_DIAG_SUPPORT 1010 static inline 1011 void wlan_scan_release_wake_lock(struct wlan_objmgr_psoc *psoc, 1012 qdf_wake_lock_t *scan_wake_lock) 1013 { 1014 if (!psoc || !scan_wake_lock) 1015 return; 1016 1017 if (ucfg_scan_wake_lock_in_user_scan(psoc)) 1018 qdf_wake_lock_release(scan_wake_lock, 1019 WIFI_POWER_EVENT_WAKELOCK_SCAN); 1020 } 1021 #else 1022 static inline 1023 void wlan_scan_release_wake_lock(struct wlan_objmgr_psoc *psoc, 1024 qdf_wake_lock_t *scan_wake_lock) 1025 { 1026 if (!psoc || !scan_wake_lock) 1027 return; 1028 1029 if (ucfg_scan_wake_lock_in_user_scan(psoc)) 1030 qdf_wake_lock_release(scan_wake_lock, 0); 1031 } 1032 #endif 1033 1034 static 1035 uint32_t wlan_scan_get_bss_count_for_scan(struct wlan_objmgr_pdev *pdev, 1036 qdf_time_t scan_start_ts) 1037 { 1038 struct scan_filter *filter; 1039 qdf_list_t *list = NULL; 1040 uint32_t count = 0; 1041 1042 if (!scan_start_ts) 1043 return count; 1044 1045 filter = qdf_mem_malloc(sizeof(*filter)); 1046 if (!filter) 1047 return count; 1048 1049 filter->ignore_auth_enc_type = true; 1050 filter->age_threshold = qdf_get_time_of_the_day_ms() - scan_start_ts; 1051 1052 list = ucfg_scan_get_result(pdev, filter); 1053 1054 qdf_mem_free(filter); 1055 1056 if (list) { 1057 count = qdf_list_size(list); 1058 ucfg_scan_purge_results(list); 1059 } 1060 1061 return count; 1062 } 1063 1064 /** 1065 * wlan_cfg80211_scan_done_callback() - scan done callback function called after 1066 * scan is finished 1067 * @vdev: vdev ptr 1068 * @event: Scan event 1069 * @args: Scan cb arg 1070 * 1071 * Return: void 1072 */ 1073 static void wlan_cfg80211_scan_done_callback( 1074 struct wlan_objmgr_vdev *vdev, 1075 struct scan_event *event, 1076 void *args) 1077 { 1078 struct cfg80211_scan_request *req = NULL; 1079 bool success = false; 1080 uint32_t scan_id; 1081 uint8_t source = NL_SCAN; 1082 struct wlan_objmgr_pdev *pdev; 1083 struct pdev_osif_priv *osif_priv; 1084 struct net_device *netdev = NULL; 1085 QDF_STATUS status; 1086 qdf_time_t scan_start_timestamp = 0; 1087 uint32_t unique_bss_count = 0; 1088 1089 if (!event) { 1090 osif_nofl_err("Invalid scan event received"); 1091 return; 1092 } 1093 1094 scan_id = event->scan_id; 1095 1096 qdf_mtrace(QDF_MODULE_ID_SCAN, QDF_MODULE_ID_OS_IF, event->type, 1097 event->vdev_id, scan_id); 1098 1099 if (event->type == SCAN_EVENT_TYPE_STARTED) 1100 osif_nofl_info("scan start scan id %d", scan_id); 1101 1102 if (!util_is_scan_completed(event, &success)) 1103 return; 1104 1105 pdev = wlan_vdev_get_pdev(vdev); 1106 osif_priv = wlan_pdev_get_ospriv(pdev); 1107 status = wlan_scan_request_dequeue( 1108 pdev, scan_id, &req, &source, &netdev, 1109 &scan_start_timestamp); 1110 if (QDF_IS_STATUS_ERROR(status)) { 1111 osif_err("Dequeue of scan request failed ID: %d", scan_id); 1112 goto allow_suspend; 1113 } 1114 1115 if (!netdev) { 1116 osif_err("net dev is NULL,Drop scan event Id: %d", scan_id); 1117 /* 1118 * Free scan request in case of VENDOR_SCAN as it is 1119 * allocated in driver. 1120 */ 1121 if (source == VENDOR_SCAN) 1122 qdf_mem_free(req); 1123 goto allow_suspend; 1124 } 1125 1126 /* Make sure vdev is active */ 1127 status = wlan_objmgr_vdev_try_get_ref(vdev, WLAN_OSIF_ID); 1128 if (QDF_IS_STATUS_ERROR(status)) { 1129 osif_err("Failed to get vdev reference: scan Id: %d", scan_id); 1130 /* 1131 * Free scan request in case of VENDOR_SCAN as it is 1132 * allocated in driver. 1133 */ 1134 if (source == VENDOR_SCAN) 1135 qdf_mem_free(req); 1136 goto allow_suspend; 1137 } 1138 1139 /* 1140 * Scan can be triggred from NL or vendor scan 1141 * - If scan is triggered from NL then cfg80211 scan done should be 1142 * called to updated scan completion to NL. 1143 * - If scan is triggred through vendor command then 1144 * scan done event will be posted 1145 */ 1146 if (NL_SCAN == source) 1147 wlan_cfg80211_scan_done(netdev, req, !success, osif_priv); 1148 else 1149 wlan_vendor_scan_callback(req, !success); 1150 1151 wlan_objmgr_vdev_release_ref(vdev, WLAN_OSIF_ID); 1152 1153 unique_bss_count = wlan_scan_get_bss_count_for_scan(pdev, 1154 scan_start_timestamp); 1155 osif_nofl_info("vdev %d, scan id %d type %s(%d) reason %s(%d) scan found %d bss", 1156 event->vdev_id, scan_id, 1157 util_scan_get_ev_type_name(event->type), event->type, 1158 util_scan_get_ev_reason_name(event->reason), 1159 event->reason, unique_bss_count); 1160 allow_suspend: 1161 qdf_mutex_acquire(&osif_priv->osif_scan->scan_req_q_lock); 1162 if (qdf_list_empty(&osif_priv->osif_scan->scan_req_q)) { 1163 struct wlan_objmgr_psoc *psoc; 1164 1165 qdf_mutex_release(&osif_priv->osif_scan->scan_req_q_lock); 1166 qdf_runtime_pm_allow_suspend( 1167 &osif_priv->osif_scan->runtime_pm_lock); 1168 1169 psoc = wlan_pdev_get_psoc(pdev); 1170 wlan_scan_release_wake_lock(psoc, 1171 &osif_priv->osif_scan->scan_wake_lock); 1172 /* 1173 * Acquire wakelock to handle the case where APP's tries 1174 * to suspend immediately after the driver gets connect 1175 * request(i.e after scan) from supplicant, this result in 1176 * app's is suspending and not able to process the connect 1177 * request to AP 1178 */ 1179 wlan_scan_acquire_wake_lock_timeout(psoc, 1180 &osif_priv->osif_scan->scan_wake_lock, 1181 SCAN_WAKE_LOCK_CONNECT_DURATION); 1182 } else { 1183 qdf_mutex_release(&osif_priv->osif_scan->scan_req_q_lock); 1184 } 1185 1186 } 1187 1188 QDF_STATUS wlan_scan_runtime_pm_init(struct wlan_objmgr_pdev *pdev) 1189 { 1190 struct pdev_osif_priv *osif_priv; 1191 struct osif_scan_pdev *scan_priv; 1192 1193 wlan_pdev_obj_lock(pdev); 1194 osif_priv = wlan_pdev_get_ospriv(pdev); 1195 wlan_pdev_obj_unlock(pdev); 1196 1197 scan_priv = osif_priv->osif_scan; 1198 1199 return qdf_runtime_lock_init(&scan_priv->runtime_pm_lock); 1200 } 1201 1202 void wlan_scan_runtime_pm_deinit(struct wlan_objmgr_pdev *pdev) 1203 { 1204 struct pdev_osif_priv *osif_priv; 1205 struct osif_scan_pdev *scan_priv; 1206 1207 wlan_pdev_obj_lock(pdev); 1208 osif_priv = wlan_pdev_get_ospriv(pdev); 1209 wlan_pdev_obj_unlock(pdev); 1210 1211 scan_priv = osif_priv->osif_scan; 1212 qdf_runtime_lock_deinit(&scan_priv->runtime_pm_lock); 1213 } 1214 1215 QDF_STATUS wlan_cfg80211_scan_priv_init(struct wlan_objmgr_pdev *pdev) 1216 { 1217 struct pdev_osif_priv *osif_priv; 1218 struct osif_scan_pdev *scan_priv; 1219 struct wlan_objmgr_psoc *psoc; 1220 wlan_scan_requester req_id; 1221 1222 psoc = wlan_pdev_get_psoc(pdev); 1223 1224 req_id = ucfg_scan_register_requester(psoc, "CFG", 1225 wlan_cfg80211_scan_done_callback, NULL); 1226 1227 osif_priv = wlan_pdev_get_ospriv(pdev); 1228 scan_priv = qdf_mem_malloc(sizeof(*scan_priv)); 1229 if (!scan_priv) 1230 return QDF_STATUS_E_NOMEM; 1231 1232 /* Initialize the scan request queue */ 1233 osif_priv->osif_scan = scan_priv; 1234 scan_priv->req_id = req_id; 1235 qdf_list_create(&scan_priv->scan_req_q, WLAN_MAX_SCAN_COUNT); 1236 qdf_mutex_create(&scan_priv->scan_req_q_lock); 1237 qdf_wake_lock_create(&scan_priv->scan_wake_lock, "scan_wake_lock"); 1238 1239 return QDF_STATUS_SUCCESS; 1240 } 1241 1242 QDF_STATUS wlan_cfg80211_scan_priv_deinit(struct wlan_objmgr_pdev *pdev) 1243 { 1244 struct pdev_osif_priv *osif_priv; 1245 struct osif_scan_pdev *scan_priv; 1246 struct wlan_objmgr_psoc *psoc; 1247 1248 psoc = wlan_pdev_get_psoc(pdev); 1249 osif_priv = wlan_pdev_get_ospriv(pdev); 1250 1251 wlan_cfg80211_cleanup_scan_queue(pdev, NULL); 1252 scan_priv = osif_priv->osif_scan; 1253 qdf_wake_lock_destroy(&scan_priv->scan_wake_lock); 1254 qdf_mutex_destroy(&scan_priv->scan_req_q_lock); 1255 qdf_list_destroy(&scan_priv->scan_req_q); 1256 ucfg_scan_unregister_requester(psoc, scan_priv->req_id); 1257 osif_priv->osif_scan = NULL; 1258 qdf_mem_free(scan_priv); 1259 1260 return QDF_STATUS_SUCCESS; 1261 } 1262 1263 /** 1264 * wlan_cfg80211_enqueue_for_cleanup() - Function to populate scan cleanup queue 1265 * @scan_cleanup_q: Scan cleanup queue to be populated 1266 * @scan_priv: Pointer to scan related data used by cfg80211 scan 1267 * @dev: Netdevice pointer 1268 * 1269 * The function synchrounously iterates through the global scan queue to 1270 * identify entries that have to be cleaned up, copies identified entries 1271 * to another queue(to send scan complete event to NL later) and removes the 1272 * entry from the global scan queue. 1273 * 1274 * Return: None 1275 */ 1276 static void 1277 wlan_cfg80211_enqueue_for_cleanup(qdf_list_t *scan_cleanup_q, 1278 struct osif_scan_pdev *scan_priv, 1279 struct net_device *dev) 1280 { 1281 struct scan_req *scan_req, *scan_cleanup; 1282 qdf_list_node_t *node = NULL, *next_node = NULL; 1283 1284 qdf_mutex_acquire(&scan_priv->scan_req_q_lock); 1285 if (QDF_STATUS_SUCCESS != 1286 qdf_list_peek_front(&scan_priv->scan_req_q, 1287 &node)) { 1288 qdf_mutex_release(&scan_priv->scan_req_q_lock); 1289 return; 1290 } 1291 1292 while (node) { 1293 /* 1294 * Keep track of the next node, to traverse through the list 1295 * in the event of the current node being deleted. 1296 */ 1297 qdf_list_peek_next(&scan_priv->scan_req_q, 1298 node, &next_node); 1299 scan_req = qdf_container_of(node, struct scan_req, node); 1300 if (!dev || (dev == scan_req->dev)) { 1301 scan_cleanup = qdf_mem_malloc(sizeof(struct scan_req)); 1302 if (!scan_cleanup) { 1303 qdf_mutex_release(&scan_priv->scan_req_q_lock); 1304 return; 1305 } 1306 scan_cleanup->scan_request = scan_req->scan_request; 1307 scan_cleanup->scan_id = scan_req->scan_id; 1308 scan_cleanup->source = scan_req->source; 1309 scan_cleanup->dev = scan_req->dev; 1310 qdf_list_insert_back(scan_cleanup_q, 1311 &scan_cleanup->node); 1312 if (QDF_STATUS_SUCCESS != 1313 qdf_list_remove_node(&scan_priv->scan_req_q, 1314 node)) { 1315 qdf_mutex_release(&scan_priv->scan_req_q_lock); 1316 osif_err("Failed to remove scan request"); 1317 return; 1318 } 1319 qdf_mem_free(scan_req); 1320 } 1321 node = next_node; 1322 next_node = NULL; 1323 } 1324 qdf_mutex_release(&scan_priv->scan_req_q_lock); 1325 } 1326 1327 void wlan_cfg80211_cleanup_scan_queue(struct wlan_objmgr_pdev *pdev, 1328 struct net_device *dev) 1329 { 1330 struct scan_req *scan_req; 1331 struct cfg80211_scan_request *req; 1332 uint8_t source; 1333 bool aborted = true; 1334 struct pdev_osif_priv *osif_priv; 1335 qdf_list_t scan_cleanup_q; 1336 qdf_list_node_t *node = NULL; 1337 1338 if (!pdev) { 1339 osif_err("pdev is Null"); 1340 return; 1341 } 1342 1343 osif_priv = wlan_pdev_get_ospriv(pdev); 1344 1345 /* 1346 * To avoid any race conditions, create a local list to copy all the 1347 * scan entries to be removed and then send scan complete for each of 1348 * the identified entries to NL. 1349 */ 1350 qdf_list_create(&scan_cleanup_q, WLAN_MAX_SCAN_COUNT); 1351 wlan_cfg80211_enqueue_for_cleanup(&scan_cleanup_q, 1352 osif_priv->osif_scan, dev); 1353 1354 while (!qdf_list_empty(&scan_cleanup_q)) { 1355 if (QDF_STATUS_SUCCESS != qdf_list_remove_front(&scan_cleanup_q, 1356 &node)) { 1357 osif_err("Failed to remove scan request"); 1358 return; 1359 } 1360 scan_req = container_of(node, struct scan_req, node); 1361 req = scan_req->scan_request; 1362 source = scan_req->source; 1363 if (NL_SCAN == source) 1364 wlan_cfg80211_scan_done(scan_req->dev, req, 1365 aborted, osif_priv); 1366 else 1367 wlan_vendor_scan_callback(req, aborted); 1368 1369 qdf_mem_free(scan_req); 1370 } 1371 qdf_list_destroy(&scan_cleanup_q); 1372 1373 return; 1374 } 1375 1376 /** 1377 * wlan_cfg80211_update_scan_policy_type_flags() - Set scan flags according to 1378 * scan request 1379 * @scan_req: Pointer to csr scan req 1380 * 1381 * Return: None 1382 */ 1383 #if defined(CFG80211_SCAN_DBS_CONTROL_SUPPORT) || \ 1384 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)) 1385 static void wlan_cfg80211_update_scan_policy_type_flags( 1386 struct cfg80211_scan_request *req, 1387 struct scan_req_params *scan_req) 1388 { 1389 if (req->flags & NL80211_SCAN_FLAG_HIGH_ACCURACY) 1390 scan_req->scan_policy_high_accuracy = true; 1391 if (req->flags & NL80211_SCAN_FLAG_LOW_SPAN) 1392 scan_req->scan_policy_low_span = true; 1393 if (req->flags & NL80211_SCAN_FLAG_LOW_POWER) 1394 scan_req->scan_policy_low_power = true; 1395 1396 if (wlan_cfg80211_is_colocated_6ghz_scan_supported(req->flags)) 1397 scan_req->scan_policy_colocated_6ghz = true; 1398 } 1399 #else 1400 static inline void wlan_cfg80211_update_scan_policy_type_flags( 1401 struct cfg80211_scan_request *req, 1402 struct scan_req_params *scan_req) 1403 { 1404 } 1405 #endif 1406 1407 #ifdef WLAN_POLICY_MGR_ENABLE 1408 static bool 1409 wlan_cfg80211_allow_simultaneous_scan(struct wlan_objmgr_psoc *psoc) 1410 { 1411 return policy_mgr_is_scan_simultaneous_capable(psoc); 1412 } 1413 #else 1414 static bool 1415 wlan_cfg80211_allow_simultaneous_scan(struct wlan_objmgr_psoc *psoc) 1416 { 1417 return true; 1418 } 1419 #endif 1420 1421 enum scan_priority convert_nl_scan_priority_to_internal( 1422 enum qca_wlan_vendor_scan_priority nl_scan_priority) 1423 { 1424 switch (nl_scan_priority) { 1425 case QCA_WLAN_VENDOR_SCAN_PRIORITY_VERY_LOW: 1426 return SCAN_PRIORITY_VERY_LOW; 1427 1428 case QCA_WLAN_VENDOR_SCAN_PRIORITY_LOW: 1429 return SCAN_PRIORITY_LOW; 1430 1431 case QCA_WLAN_VENDOR_SCAN_PRIORITY_MEDIUM: 1432 return SCAN_PRIORITY_MEDIUM; 1433 1434 case QCA_WLAN_VENDOR_SCAN_PRIORITY_HIGH: 1435 return SCAN_PRIORITY_HIGH; 1436 1437 case QCA_WLAN_VENDOR_SCAN_PRIORITY_VERY_HIGH: 1438 return SCAN_PRIORITY_VERY_HIGH; 1439 1440 default: 1441 return SCAN_PRIORITY_COUNT; 1442 } 1443 } 1444 1445 int wlan_cfg80211_scan(struct wlan_objmgr_vdev *vdev, 1446 struct cfg80211_scan_request *request, 1447 struct scan_params *params) 1448 { 1449 struct scan_start_request *req; 1450 struct wlan_ssid *pssid; 1451 uint8_t i; 1452 int ret = 0; 1453 uint8_t num_chan = 0; 1454 uint32_t c_freq; 1455 struct wlan_objmgr_pdev *pdev = wlan_vdev_get_pdev(vdev); 1456 wlan_scan_requester req_id; 1457 struct pdev_osif_priv *osif_priv; 1458 struct wlan_objmgr_psoc *psoc; 1459 wlan_scan_id scan_id; 1460 bool is_p2p_scan = false; 1461 enum wlan_band band; 1462 QDF_STATUS qdf_status; 1463 enum QDF_OPMODE opmode; 1464 uint32_t extra_ie_len = 0; 1465 1466 psoc = wlan_pdev_get_psoc(pdev); 1467 if (!psoc) { 1468 osif_err("Invalid psoc object"); 1469 return -EINVAL; 1470 } 1471 opmode = wlan_vdev_mlme_get_opmode(vdev); 1472 1473 osif_debug("%s(vdev%d): mode %d", request->wdev->netdev->name, 1474 wlan_vdev_get_id(vdev), opmode); 1475 1476 /* Get NL global context from objmgr*/ 1477 osif_priv = wlan_pdev_get_ospriv(pdev); 1478 if (!osif_priv) { 1479 osif_err("Invalid osif priv object"); 1480 return -EINVAL; 1481 } 1482 1483 /* 1484 * For a non-SAP vdevs, if a scan is already going on i.e the scan queue 1485 * is not empty, and the simultaneous scan is disabled, dont allow 2nd 1486 * scan. 1487 */ 1488 qdf_mutex_acquire(&osif_priv->osif_scan->scan_req_q_lock); 1489 if (!wlan_cfg80211_allow_simultaneous_scan(psoc) && 1490 !qdf_list_empty(&osif_priv->osif_scan->scan_req_q) && 1491 opmode != QDF_SAP_MODE) { 1492 qdf_mutex_release(&osif_priv->osif_scan->scan_req_q_lock); 1493 osif_err("Simultaneous scan disabled, reject scan"); 1494 return -EBUSY; 1495 } 1496 qdf_mutex_release(&osif_priv->osif_scan->scan_req_q_lock); 1497 1498 req = qdf_mem_malloc(sizeof(*req)); 1499 if (!req) 1500 return -EINVAL; 1501 1502 /* Initialize the scan global params */ 1503 ucfg_scan_init_default_params(vdev, req); 1504 1505 req_id = osif_priv->osif_scan->req_id; 1506 scan_id = ucfg_scan_get_scan_id(psoc); 1507 if (!scan_id) { 1508 osif_err("Invalid scan id"); 1509 qdf_mem_free(req); 1510 return -EINVAL; 1511 } 1512 1513 /* fill the scan request structure */ 1514 req->vdev = vdev; 1515 req->scan_req.vdev_id = wlan_vdev_get_id(vdev); 1516 req->scan_req.scan_id = scan_id; 1517 req->scan_req.scan_req_id = req_id; 1518 1519 /* Update scan policy type flags according to cfg scan request */ 1520 wlan_cfg80211_update_scan_policy_type_flags(request, 1521 &req->scan_req); 1522 /* 1523 * Even though supplicant doesn't provide any SSIDs, n_ssids is 1524 * set to 1. Because of this, driver is assuming that this is not 1525 * wildcard scan and so is not aging out the scan results. 1526 */ 1527 if ((request->ssids) && (request->n_ssids == 1) && 1528 ('\0' == request->ssids->ssid[0])) { 1529 request->n_ssids = 0; 1530 } 1531 1532 if ((request->ssids) && (0 < request->n_ssids)) { 1533 int j; 1534 req->scan_req.num_ssids = request->n_ssids; 1535 1536 if (req->scan_req.num_ssids > WLAN_SCAN_MAX_NUM_SSID) { 1537 osif_info("number of ssid %d greater than MAX %d", 1538 req->scan_req.num_ssids, 1539 WLAN_SCAN_MAX_NUM_SSID); 1540 req->scan_req.num_ssids = WLAN_SCAN_MAX_NUM_SSID; 1541 } 1542 /* copy all the ssid's and their length */ 1543 for (j = 0; j < req->scan_req.num_ssids; j++) { 1544 pssid = &req->scan_req.ssid[j]; 1545 /* get the ssid length */ 1546 pssid->length = request->ssids[j].ssid_len; 1547 if (pssid->length > WLAN_SSID_MAX_LEN) 1548 pssid->length = WLAN_SSID_MAX_LEN; 1549 qdf_mem_copy(pssid->ssid, 1550 &request->ssids[j].ssid[0], 1551 pssid->length); 1552 } 1553 } 1554 if (request->ssids || 1555 (opmode == QDF_P2P_GO_MODE) || (opmode == QDF_P2P_DEVICE_MODE)) 1556 req->scan_req.scan_f_passive = false; 1557 1558 if (params->half_rate) 1559 req->scan_req.scan_f_half_rate = true; 1560 else if (params->quarter_rate) 1561 req->scan_req.scan_f_quarter_rate = true; 1562 1563 if (params->strict_pscan) 1564 req->scan_req.scan_f_strict_passive_pch = true; 1565 1566 if ((request->n_ssids == 1) && request->ssids && 1567 !qdf_mem_cmp(&request->ssids[0], "DIRECT-", 7)) 1568 is_p2p_scan = true; 1569 1570 if (is_p2p_scan && request->no_cck) 1571 req->scan_req.scan_type = SCAN_TYPE_P2P_SEARCH; 1572 1573 if (params->dwell_time_active) 1574 req->scan_req.dwell_time_active = params->dwell_time_active; 1575 1576 if (params->dwell_time_active_2g) 1577 req->scan_req.dwell_time_active_2g = 1578 params->dwell_time_active_2g; 1579 1580 if (params->dwell_time_passive) 1581 req->scan_req.dwell_time_passive = params->dwell_time_passive; 1582 1583 if (params->dwell_time_active_6g) 1584 req->scan_req.dwell_time_active_6g = 1585 params->dwell_time_active_6g; 1586 1587 if (params->dwell_time_passive_6g) 1588 req->scan_req.dwell_time_passive_6g = 1589 params->dwell_time_passive_6g; 1590 1591 /* Set dwell time mode according to scan policy type flags */ 1592 if (ucfg_scan_cfg_honour_nl_scan_policy_flags(psoc)) { 1593 if (req->scan_req.scan_policy_high_accuracy) 1594 req->scan_req.adaptive_dwell_time_mode = 1595 SCAN_DWELL_MODE_STATIC; 1596 if (req->scan_req.scan_policy_low_power) 1597 req->scan_req.adaptive_dwell_time_mode = 1598 SCAN_DWELL_MODE_AGGRESSIVE; 1599 } 1600 1601 /* 1602 * FW require at least 1 MAC to send probe request. 1603 * If MAC is all 0 set it to BC addr as this is the address on 1604 * which fw will send probe req. 1605 */ 1606 req->scan_req.num_bssid = 1; 1607 wlan_copy_bssid_scan_request(req, request); 1608 if (qdf_is_macaddr_zero(&req->scan_req.bssid_list[0])) 1609 qdf_set_macaddr_broadcast(&req->scan_req.bssid_list[0]); 1610 1611 if (params->scan_f_2ghz && !params->scan_f_5ghz) { 1612 req->scan_req.scan_f_2ghz = true; 1613 req->scan_req.scan_f_5ghz = false; 1614 } else if (!params->scan_f_2ghz && params->scan_f_5ghz) { 1615 req->scan_req.scan_f_2ghz = false; 1616 req->scan_req.scan_f_5ghz = true; 1617 } 1618 1619 if (request->n_channels) { 1620 #ifdef WLAN_POLICY_MGR_ENABLE 1621 bool ap_or_go_present = 1622 policy_mgr_mode_specific_connection_count( 1623 psoc, PM_SAP_MODE, NULL) || 1624 policy_mgr_mode_specific_connection_count( 1625 psoc, PM_P2P_GO_MODE, NULL); 1626 #endif 1627 for (i = 0; i < request->n_channels; i++) { 1628 c_freq = request->channels[i]->center_freq; 1629 if (wlan_reg_is_dsrc_freq(c_freq)) 1630 continue; 1631 #ifdef WLAN_POLICY_MGR_ENABLE 1632 if (ap_or_go_present) { 1633 bool ok; 1634 1635 qdf_status = policy_mgr_is_chan_ok_for_dnbs( 1636 psoc, c_freq, &ok); 1637 1638 if (QDF_IS_STATUS_ERROR(qdf_status)) { 1639 osif_err("DNBS check failed"); 1640 ret = -EINVAL; 1641 goto err; 1642 } 1643 if (!ok) 1644 continue; 1645 } 1646 #endif 1647 1648 if ((req->scan_req.scan_f_2ghz && 1649 WLAN_REG_IS_24GHZ_CH_FREQ(c_freq)) || 1650 (req->scan_req.scan_f_5ghz && 1651 (WLAN_REG_IS_5GHZ_CH_FREQ(c_freq) || 1652 WLAN_REG_IS_49GHZ_FREQ(c_freq) || 1653 WLAN_REG_IS_6GHZ_CHAN_FREQ(c_freq)))) { 1654 req->scan_req.chan_list.chan[num_chan].freq = 1655 c_freq; 1656 band = util_scan_scm_freq_to_band(c_freq); 1657 if (band == WLAN_BAND_2_4_GHZ) 1658 req->scan_req.chan_list.chan[num_chan].phymode = 1659 SCAN_PHY_MODE_11G; 1660 else 1661 req->scan_req.chan_list.chan[num_chan].phymode = 1662 SCAN_PHY_MODE_11A; 1663 num_chan++; 1664 if (num_chan >= NUM_CHANNELS) 1665 break; 1666 } 1667 } 1668 } 1669 if (!num_chan) { 1670 osif_err("Received zero non-dsrc channels"); 1671 ret = -EINVAL; 1672 goto err; 1673 } 1674 req->scan_req.chan_list.num_chan = num_chan; 1675 1676 /* P2P increase the scan priority */ 1677 if (is_p2p_scan) 1678 req->scan_req.scan_priority = SCAN_PRIORITY_HIGH; 1679 1680 if (params->priority != SCAN_PRIORITY_COUNT) 1681 req->scan_req.scan_priority = params->priority; 1682 1683 if (request->ie_len) 1684 extra_ie_len = request->ie_len; 1685 else if (params->default_ie.ptr && params->default_ie.len) 1686 extra_ie_len = params->default_ie.len; 1687 1688 if (params->vendor_ie.ptr && params->vendor_ie.len) 1689 extra_ie_len += params->vendor_ie.len; 1690 1691 if (extra_ie_len) { 1692 req->scan_req.extraie.ptr = qdf_mem_malloc(extra_ie_len); 1693 if (!req->scan_req.extraie.ptr) { 1694 ret = -ENOMEM; 1695 goto err; 1696 } 1697 } 1698 1699 if (request->ie_len) { 1700 req->scan_req.extraie.len = request->ie_len; 1701 qdf_mem_copy(req->scan_req.extraie.ptr, request->ie, 1702 request->ie_len); 1703 } else if (params->default_ie.ptr && params->default_ie.len) { 1704 req->scan_req.extraie.len = params->default_ie.len; 1705 qdf_mem_copy(req->scan_req.extraie.ptr, params->default_ie.ptr, 1706 params->default_ie.len); 1707 } 1708 1709 if (params->vendor_ie.ptr && params->vendor_ie.len) { 1710 qdf_mem_copy((req->scan_req.extraie.ptr + 1711 req->scan_req.extraie.len), 1712 params->vendor_ie.ptr, params->vendor_ie.len); 1713 1714 req->scan_req.extraie.len += params->vendor_ie.len; 1715 } 1716 1717 if (!is_p2p_scan) { 1718 if (req->scan_req.scan_random.randomize) 1719 wlan_scan_rand_attrs(vdev, request, req); 1720 if (ucfg_ie_allowlist_enabled(psoc, vdev) && 1721 ucfg_copy_ie_allowlist_attrs(psoc, 1722 &req->scan_req.ie_allowlist)) 1723 req->scan_req.scan_f_en_ie_allowlist_in_probe = true; 1724 } 1725 1726 if (request->flags & NL80211_SCAN_FLAG_FLUSH) 1727 ucfg_scan_flush_results(pdev, NULL); 1728 1729 if (params->scan_probe_unicast_ra) 1730 req->scan_req.scan_ctrl_flags_ext |= 1731 SCAN_FLAG_EXT_FORCE_UNICAST_RA; 1732 1733 osif_debug("scan_ctrl_flags_ext %0x", 1734 req->scan_req.scan_ctrl_flags_ext); 1735 1736 /* 1737 * Acquire wakelock to handle the case where APP's send scan to connect. 1738 * If suspend is received during scan scan will be aborted and APP will 1739 * not get scan result and not connect. eg if PNO is implemented in 1740 * framework. 1741 */ 1742 wlan_scan_acquire_wake_lock_timeout(psoc, 1743 &osif_priv->osif_scan->scan_wake_lock, 1744 SCAN_WAKE_LOCK_SCAN_DURATION); 1745 1746 qdf_runtime_pm_prevent_suspend( 1747 &osif_priv->osif_scan->runtime_pm_lock); 1748 1749 qdf_status = wlan_schedule_scan_start_request(pdev, request, 1750 params->source, req); 1751 if (QDF_IS_STATUS_ERROR(qdf_status)) { 1752 qdf_mutex_acquire(&osif_priv->osif_scan->scan_req_q_lock); 1753 if (qdf_list_empty(&osif_priv->osif_scan->scan_req_q)) { 1754 qdf_mutex_release( 1755 &osif_priv->osif_scan->scan_req_q_lock); 1756 qdf_runtime_pm_allow_suspend( 1757 &osif_priv->osif_scan->runtime_pm_lock); 1758 wlan_scan_release_wake_lock( 1759 psoc, 1760 &osif_priv->osif_scan->scan_wake_lock); 1761 } else { 1762 qdf_mutex_release( 1763 &osif_priv->osif_scan->scan_req_q_lock); 1764 } 1765 } 1766 1767 return qdf_status_to_os_return(qdf_status); 1768 1769 err: 1770 qdf_mem_free(req); 1771 return ret; 1772 } 1773 1774 /** 1775 * wlan_get_scanid() - API to get the scan id 1776 * from the scan cookie attribute. 1777 * @pdev: Pointer to pdev object 1778 * @scan_id: Pointer to scan id 1779 * @cookie : Scan cookie attribute 1780 * 1781 * API to get the scan id from the scan cookie attribute 1782 * sent from supplicant by matching scan request. 1783 * 1784 * Return: 0 for success, non zero for failure 1785 */ 1786 static int wlan_get_scanid(struct wlan_objmgr_pdev *pdev, 1787 uint32_t *scan_id, uint64_t cookie) 1788 { 1789 struct scan_req *scan_req; 1790 qdf_list_node_t *node = NULL; 1791 qdf_list_node_t *ptr_node = NULL; 1792 int ret = -EINVAL; 1793 struct pdev_osif_priv *osif_ctx; 1794 struct osif_scan_pdev *scan_priv; 1795 1796 /* Get NL global context from objmgr*/ 1797 osif_ctx = wlan_pdev_get_ospriv(pdev); 1798 if (!osif_ctx) { 1799 osif_err("Failed to retrieve osif context"); 1800 return ret; 1801 } 1802 scan_priv = osif_ctx->osif_scan; 1803 qdf_mutex_acquire(&scan_priv->scan_req_q_lock); 1804 if (qdf_list_empty(&scan_priv->scan_req_q)) { 1805 qdf_mutex_release(&scan_priv->scan_req_q_lock); 1806 osif_err("Failed to retrieve scan id"); 1807 return ret; 1808 } 1809 1810 if (QDF_STATUS_SUCCESS != 1811 qdf_list_peek_front(&scan_priv->scan_req_q, 1812 &ptr_node)) { 1813 qdf_mutex_release(&scan_priv->scan_req_q_lock); 1814 return ret; 1815 } 1816 1817 do { 1818 node = ptr_node; 1819 scan_req = qdf_container_of(node, struct scan_req, node); 1820 if (cookie == 1821 (uintptr_t)(scan_req->scan_request)) { 1822 *scan_id = scan_req->scan_id; 1823 ret = 0; 1824 break; 1825 } 1826 } while (QDF_STATUS_SUCCESS == 1827 qdf_list_peek_next(&scan_priv->scan_req_q, 1828 node, &ptr_node)); 1829 1830 qdf_mutex_release(&scan_priv->scan_req_q_lock); 1831 1832 return ret; 1833 } 1834 1835 QDF_STATUS wlan_abort_scan(struct wlan_objmgr_pdev *pdev, 1836 uint32_t pdev_id, uint32_t vdev_id, 1837 wlan_scan_id scan_id, bool sync) 1838 { 1839 struct scan_cancel_request *req; 1840 struct pdev_osif_priv *osif_ctx; 1841 struct osif_scan_pdev *scan_priv; 1842 QDF_STATUS status; 1843 struct wlan_objmgr_vdev *vdev; 1844 1845 req = qdf_mem_malloc(sizeof(*req)); 1846 if (!req) 1847 return QDF_STATUS_E_NOMEM; 1848 1849 /* Get NL global context from objmgr*/ 1850 osif_ctx = wlan_pdev_get_ospriv(pdev); 1851 if (!osif_ctx) { 1852 osif_err("Failed to retrieve osif context"); 1853 qdf_mem_free(req); 1854 return QDF_STATUS_E_FAILURE; 1855 } 1856 if (vdev_id == INVAL_VDEV_ID) 1857 vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_OSIF_ID); 1858 else 1859 vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev, 1860 vdev_id, WLAN_OSIF_ID); 1861 1862 if (!vdev) { 1863 qdf_mem_free(req); 1864 return QDF_STATUS_E_INVAL; 1865 } 1866 scan_priv = osif_ctx->osif_scan; 1867 req->cancel_req.requester = scan_priv->req_id; 1868 req->vdev = vdev; 1869 req->cancel_req.scan_id = scan_id; 1870 req->cancel_req.pdev_id = pdev_id; 1871 req->cancel_req.vdev_id = vdev_id; 1872 if (scan_id != INVAL_SCAN_ID && scan_id != CANCEL_HOST_SCAN_ID) 1873 req->cancel_req.req_type = WLAN_SCAN_CANCEL_SINGLE; 1874 else if (scan_id == CANCEL_HOST_SCAN_ID) 1875 req->cancel_req.req_type = WLAN_SCAN_CANCEL_HOST_VDEV_ALL; 1876 else if (vdev_id == INVAL_VDEV_ID) 1877 req->cancel_req.req_type = WLAN_SCAN_CANCEL_PDEV_ALL; 1878 else 1879 req->cancel_req.req_type = WLAN_SCAN_CANCEL_VDEV_ALL; 1880 1881 osif_debug("Type %d Vdev %d pdev %d scan id %d sync %d", 1882 req->cancel_req.req_type, req->cancel_req.vdev_id, 1883 req->cancel_req.pdev_id, req->cancel_req.scan_id, sync); 1884 1885 if (sync) 1886 status = ucfg_scan_cancel_sync(req); 1887 else 1888 status = ucfg_scan_cancel(req); 1889 if (QDF_IS_STATUS_ERROR(status)) 1890 osif_err("Cancel scan request failed"); 1891 1892 wlan_objmgr_vdev_release_ref(vdev, WLAN_OSIF_ID); 1893 1894 return status; 1895 } 1896 1897 qdf_export_symbol(wlan_abort_scan); 1898 1899 int wlan_cfg80211_abort_scan(struct wlan_objmgr_pdev *pdev) 1900 { 1901 uint8_t pdev_id; 1902 1903 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 1904 1905 if (ucfg_scan_get_pdev_status(pdev) != 1906 SCAN_NOT_IN_PROGRESS) 1907 wlan_abort_scan(pdev, pdev_id, 1908 INVAL_VDEV_ID, INVAL_SCAN_ID, true); 1909 1910 return 0; 1911 } 1912 1913 int wlan_vendor_abort_scan(struct wlan_objmgr_pdev *pdev, 1914 const void *data, int data_len) 1915 { 1916 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SCAN_MAX + 1]; 1917 int ret = -EINVAL; 1918 wlan_scan_id scan_id; 1919 uint64_t cookie; 1920 uint8_t pdev_id; 1921 1922 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev); 1923 if (wlan_cfg80211_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SCAN_MAX, data, 1924 data_len, cfg80211_scan_policy)) { 1925 osif_err("Invalid ATTR"); 1926 return ret; 1927 } 1928 1929 if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE]) { 1930 cookie = nla_get_u64( 1931 tb[QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE]); 1932 ret = wlan_get_scanid(pdev, &scan_id, cookie); 1933 if (ret != 0) 1934 return ret; 1935 if (ucfg_scan_get_pdev_status(pdev) != 1936 SCAN_NOT_IN_PROGRESS) 1937 wlan_abort_scan(pdev, INVAL_PDEV_ID, 1938 INVAL_VDEV_ID, scan_id, true); 1939 } 1940 return 0; 1941 } 1942 1943 static inline struct ieee80211_channel * 1944 wlan_get_ieee80211_channel(struct wiphy *wiphy, 1945 struct wlan_objmgr_pdev *pdev, 1946 int chan_freq) 1947 { 1948 struct ieee80211_channel *chan; 1949 1950 chan = ieee80211_get_channel(wiphy, chan_freq); 1951 if (!chan) 1952 osif_err_rl("chan is NULL, freq: %d", chan_freq); 1953 1954 return chan; 1955 } 1956 1957 #ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS 1958 static inline int wlan_get_frame_len(struct scan_cache_entry *scan_params) 1959 { 1960 return util_scan_entry_frame_len(scan_params) + sizeof(qcom_ie_age); 1961 } 1962 1963 static inline void wlan_add_age_ie(uint8_t *mgmt_frame, 1964 struct scan_cache_entry *scan_params) 1965 { 1966 qcom_ie_age *qie_age = NULL; 1967 1968 /* GPS Requirement: need age ie per entry. Using vendor specific. */ 1969 /* Assuming this is the last IE, copy at the end */ 1970 qie_age = (qcom_ie_age *) (mgmt_frame + 1971 util_scan_entry_frame_len(scan_params)); 1972 qie_age->element_id = QCOM_VENDOR_IE_ID; 1973 qie_age->len = QCOM_VENDOR_IE_AGE_LEN; 1974 qie_age->oui_1 = QCOM_OUI1; 1975 qie_age->oui_2 = QCOM_OUI2; 1976 qie_age->oui_3 = QCOM_OUI3; 1977 qie_age->type = QCOM_VENDOR_IE_AGE_TYPE; 1978 /* 1979 * Lowi expects the timestamp of bss in units of 1/10 ms. In driver 1980 * all bss related timestamp is in units of ms. Due to this when scan 1981 * results are sent to lowi the scan age is high.To address this, 1982 * send age in units of 1/10 ms. 1983 */ 1984 qie_age->age = 1985 (uint32_t)(qdf_mc_timer_get_system_time() - 1986 scan_params->scan_entry_time)/10; 1987 qie_age->tsf_delta = scan_params->tsf_delta; 1988 memcpy(&qie_age->beacon_tsf, scan_params->tsf_info.data, 1989 sizeof(qie_age->beacon_tsf)); 1990 memcpy(&qie_age->seq_ctrl, &scan_params->seq_num, 1991 sizeof(qie_age->seq_ctrl)); 1992 } 1993 #else 1994 static inline int wlan_get_frame_len(struct scan_cache_entry *scan_params) 1995 { 1996 return util_scan_entry_frame_len(scan_params); 1997 } 1998 1999 static inline void wlan_add_age_ie(uint8_t *mgmt_frame, 2000 struct scan_cache_entry *scan_params) 2001 { 2002 } 2003 #endif /* WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS */ 2004 2005 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) || \ 2006 defined(CFG80211_INFORM_BSS_FRAME_DATA) 2007 /** 2008 * wlan_fill_per_chain_rssi() - fill per chain RSSI in inform bss 2009 * @data: bss data 2010 * @per_chain_snr: per chain RSSI 2011 * 2012 * Return: void 2013 */ 2014 #if defined(CFG80211_SCAN_PER_CHAIN_RSSI_SUPPORT) || \ 2015 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)) 2016 static void wlan_fill_per_chain_rssi(struct cfg80211_inform_bss *data, 2017 struct wlan_cfg80211_inform_bss *bss) 2018 { 2019 2020 uint32_t i; 2021 2022 if (!bss || !data) { 2023 osif_err("Received bss is NULL"); 2024 return; 2025 } 2026 for (i = 0; i < WLAN_MGMT_TXRX_HOST_MAX_ANTENNA; i++) { 2027 if (!bss->per_chain_rssi[i] || 2028 (bss->per_chain_rssi[i] == WLAN_INVALID_PER_CHAIN_RSSI)) 2029 continue; 2030 data->chain_signal[i] = bss->per_chain_rssi[i]; 2031 data->chains |= BIT(i); 2032 } 2033 } 2034 #else 2035 static inline void 2036 wlan_fill_per_chain_rssi(struct cfg80211_inform_bss *data, 2037 struct wlan_cfg80211_inform_bss *bss) 2038 { 2039 } 2040 #endif 2041 2042 struct cfg80211_bss * 2043 wlan_cfg80211_inform_bss_frame_data(struct wiphy *wiphy, 2044 struct wlan_cfg80211_inform_bss *bss) 2045 { 2046 struct cfg80211_inform_bss data = {0}; 2047 2048 if (!bss) { 2049 osif_err("bss is null"); 2050 return NULL; 2051 } 2052 wlan_fill_per_chain_rssi(&data, bss); 2053 2054 data.chan = bss->chan; 2055 data.boottime_ns = bss->boottime_ns; 2056 data.signal = bss->rssi; 2057 return cfg80211_inform_bss_frame_data(wiphy, &data, bss->mgmt, 2058 bss->frame_len, GFP_ATOMIC); 2059 } 2060 #else 2061 struct cfg80211_bss * 2062 wlan_cfg80211_inform_bss_frame_data(struct wiphy *wiphy, 2063 struct wlan_cfg80211_inform_bss *bss) 2064 2065 { 2066 return cfg80211_inform_bss_frame(wiphy, bss->chan, bss->mgmt, 2067 bss->frame_len, 2068 bss->rssi, GFP_ATOMIC); 2069 } 2070 #endif 2071 2072 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)) 2073 static inline void wlan_cfg80211_put_bss(struct wiphy *wiphy, 2074 struct cfg80211_bss *bss) 2075 { 2076 cfg80211_put_bss(wiphy, bss); 2077 } 2078 #else 2079 static inline void wlan_cfg80211_put_bss(struct wiphy *wiphy, 2080 struct cfg80211_bss *bss) 2081 { 2082 cfg80211_put_bss(bss); 2083 } 2084 #endif 2085 2086 #ifdef WLAN_FEATURE_MBSSID 2087 /** 2088 * wlan_cfg80211_is_nontx_scan_entry() - check if the scan_entry correspond 2089 * nontx profile 2090 * @scan_params: scan entry 2091 * 2092 * Return: true - if nontx profile, false - if tx profile 2093 */ 2094 static inline bool 2095 wlan_cfg80211_is_nontx_scan_entry(struct scan_cache_entry *scan_params) 2096 { 2097 if (scan_params->mbssid_info.profile_count && 2098 qdf_mem_cmp(scan_params->bssid.bytes, 2099 scan_params->mbssid_info.trans_bssid, 2100 QDF_MAC_ADDR_SIZE) != 0) 2101 return true; 2102 2103 return false; 2104 } 2105 #else 2106 static inline bool 2107 wlan_cfg80211_is_nontx_scan_entry(struct scan_cache_entry *scan_params) 2108 { 2109 return false; 2110 } 2111 #endif 2112 2113 void wlan_cfg80211_inform_bss_frame(struct wlan_objmgr_pdev *pdev, 2114 struct scan_cache_entry *scan_params) 2115 { 2116 struct pdev_osif_priv *pdev_ospriv = wlan_pdev_get_ospriv(pdev); 2117 struct wiphy *wiphy; 2118 struct cfg80211_bss *bss = NULL; 2119 struct wlan_cfg80211_inform_bss bss_data = {0}; 2120 2121 if (!pdev_ospriv) { 2122 osif_err("os_priv is NULL"); 2123 return; 2124 } 2125 2126 wiphy = pdev_ospriv->wiphy; 2127 2128 if (!wiphy) { 2129 osif_err("wiphy is NULL"); 2130 return; 2131 } 2132 2133 if (wlan_cfg80211_is_nontx_scan_entry(scan_params)) 2134 return; 2135 2136 bss_data.frame_len = wlan_get_frame_len(scan_params); 2137 bss_data.mgmt = qdf_mem_malloc_atomic(bss_data.frame_len); 2138 if (!bss_data.mgmt) { 2139 osif_err("bss mem alloc failed for seq %d", 2140 scan_params->seq_num); 2141 return; 2142 } 2143 qdf_mem_copy(bss_data.mgmt, 2144 util_scan_entry_frame_ptr(scan_params), 2145 util_scan_entry_frame_len(scan_params)); 2146 /* 2147 * Android does not want the timestamp from the frame. 2148 * Instead it wants a monotonic increasing value 2149 */ 2150 bss_data.mgmt->u.probe_resp.timestamp = qdf_get_monotonic_boottime(); 2151 wlan_add_age_ie((uint8_t *)bss_data.mgmt, scan_params); 2152 /* 2153 * Based on .ini configuration, raw rssi can be reported for bss. 2154 * Raw rssi is typically used for estimating power. 2155 */ 2156 bss_data.rssi = scan_params->rssi_raw; 2157 2158 bss_data.chan = wlan_get_ieee80211_channel(wiphy, pdev, 2159 scan_params->channel.chan_freq); 2160 if (!bss_data.chan) { 2161 osif_err_rl("Channel not found for bss " QDF_MAC_ADDR_FMT " seq %d chan_freq %d", 2162 QDF_MAC_ADDR_REF(bss_data.mgmt->bssid), 2163 scan_params->seq_num, 2164 scan_params->channel.chan_freq); 2165 qdf_mem_free(bss_data.mgmt); 2166 return; 2167 } 2168 2169 /* 2170 * Supplicant takes the signal strength in terms of 2171 * mBm (1 dBm = 100 mBm). 2172 */ 2173 bss_data.rssi = QDF_MIN(bss_data.rssi, 0) * 100; 2174 2175 bss_data.boottime_ns = scan_params->boottime_ns; 2176 2177 qdf_mem_copy(bss_data.per_chain_rssi, scan_params->per_chain_rssi, 2178 WLAN_MGMT_TXRX_HOST_MAX_ANTENNA); 2179 2180 bss = wlan_cfg80211_inform_bss_frame_data(wiphy, &bss_data); 2181 if (!bss) 2182 osif_err("failed to inform bss "QDF_MAC_ADDR_FMT" seq %d", 2183 QDF_MAC_ADDR_REF(bss_data.mgmt->bssid), 2184 scan_params->seq_num); 2185 else 2186 wlan_cfg80211_put_bss(wiphy, bss); 2187 2188 qdf_mem_free(bss_data.mgmt); 2189 } 2190 2191 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) && \ 2192 !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY) 2193 struct cfg80211_bss *wlan_cfg80211_get_bss(struct wiphy *wiphy, 2194 struct ieee80211_channel *channel, 2195 const u8 *bssid, const u8 *ssid, 2196 size_t ssid_len) 2197 { 2198 return cfg80211_get_bss(wiphy, channel, bssid, 2199 ssid, ssid_len, 2200 WLAN_CAPABILITY_ESS, 2201 WLAN_CAPABILITY_ESS); 2202 } 2203 #else 2204 struct cfg80211_bss *wlan_cfg80211_get_bss(struct wiphy *wiphy, 2205 struct ieee80211_channel *channel, 2206 const u8 *bssid, const u8 *ssid, 2207 size_t ssid_len) 2208 { 2209 return cfg80211_get_bss(wiphy, channel, bssid, 2210 ssid, ssid_len, 2211 IEEE80211_BSS_TYPE_ESS, 2212 IEEE80211_PRIVACY_ANY); 2213 } 2214 #endif 2215 2216 QDF_STATUS __wlan_cfg80211_unlink_bss_list(struct wiphy *wiphy, 2217 struct wlan_objmgr_pdev *pdev, 2218 uint8_t *bssid, uint8_t *ssid, 2219 uint8_t ssid_len) 2220 { 2221 struct cfg80211_bss *bss = NULL; 2222 uint8_t vdev_id; 2223 2224 if (bssid && wlan_get_connected_vdev_by_bssid(pdev, bssid, &vdev_id)) { 2225 osif_debug("BSS "QDF_MAC_ADDR_FMT" connected on vdev %d dont unlink", 2226 QDF_MAC_ADDR_REF(bssid), vdev_id); 2227 return QDF_STATUS_E_FAILURE; 2228 } 2229 2230 bss = wlan_cfg80211_get_bss(wiphy, NULL, bssid, 2231 ssid, ssid_len); 2232 if (!bss) { 2233 osif_info("BSS "QDF_MAC_ADDR_FMT" not found", 2234 QDF_MAC_ADDR_REF(bssid)); 2235 } else { 2236 osif_debug("unlink entry for ssid:%.*s and BSSID "QDF_MAC_ADDR_FMT, 2237 ssid_len, ssid, QDF_MAC_ADDR_REF(bssid)); 2238 cfg80211_unlink_bss(wiphy, bss); 2239 wlan_cfg80211_put_bss(wiphy, bss); 2240 } 2241 2242 /* 2243 * Kernel creates separate entries into it's bss list for probe resp 2244 * and beacon for hidden AP. Both have separate ref count and thus 2245 * deleting one will not delete other entry. 2246 * If beacon entry of the hidden AP is not deleted and AP switch to 2247 * broadcasting SSID from Hiding SSID, kernel will reject the beacon 2248 * entry. So unlink the hidden beacon entry (if present) as well from 2249 * kernel, to avoid such issue. 2250 */ 2251 bss = wlan_cfg80211_get_bss(wiphy, NULL, bssid, NULL, 0); 2252 if (!bss) { 2253 osif_debug("Hidden bss not found for Ssid:%.*s BSSID: "QDF_MAC_ADDR_FMT" sid_len %d", 2254 ssid_len, ssid, QDF_MAC_ADDR_REF(bssid), ssid_len); 2255 } else { 2256 osif_debug("unlink entry for Hidden ssid:%.*s and BSSID "QDF_MAC_ADDR_FMT, 2257 ssid_len, ssid, QDF_MAC_ADDR_REF(bssid)); 2258 2259 cfg80211_unlink_bss(wiphy, bss); 2260 /* cfg80211_get_bss get bss with ref count so release it */ 2261 wlan_cfg80211_put_bss(wiphy, bss); 2262 } 2263 2264 return QDF_STATUS_SUCCESS; 2265 } 2266 void wlan_cfg80211_unlink_bss_list(struct wlan_objmgr_pdev *pdev, 2267 struct scan_cache_entry *scan_entry) 2268 { 2269 struct pdev_osif_priv *pdev_ospriv = wlan_pdev_get_ospriv(pdev); 2270 struct wiphy *wiphy; 2271 2272 if (!pdev_ospriv) { 2273 osif_err("os_priv is NULL"); 2274 return; 2275 } 2276 2277 wiphy = pdev_ospriv->wiphy; 2278 2279 __wlan_cfg80211_unlink_bss_list(wiphy, pdev, scan_entry->bssid.bytes, 2280 scan_entry->ssid.ssid, 2281 scan_entry->ssid.length); 2282 } 2283 2284 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)) 2285 /* 2286 * wlan_scan_wiphy_set_max_sched_scans() - set maximum number of scheduled scans 2287 * to wiphy. 2288 * @wiphy: pointer to wiphy 2289 * @max_scans: max num scans to be configured 2290 * 2291 */ 2292 static inline void 2293 wlan_scan_wiphy_set_max_sched_scans(struct wiphy *wiphy, uint8_t max_scans) 2294 { 2295 if (max_scans == 0) 2296 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_SCHED_SCAN; 2297 else 2298 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; 2299 } 2300 #else 2301 static inline void 2302 wlan_scan_wiphy_set_max_sched_scans(struct wiphy *wiphy, uint8_t max_scans) 2303 { 2304 wiphy->max_sched_scan_reqs = max_scans; 2305 } 2306 #endif /* KERNEL_VERSION(4, 12, 0) */ 2307 2308 #if defined(CFG80211_REPORT_BETTER_BSS_IN_SCHED_SCAN) || \ 2309 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)) 2310 void wlan_scan_cfg80211_add_connected_pno_support(struct wiphy *wiphy) 2311 { 2312 wiphy_ext_feature_set(wiphy, 2313 NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI); 2314 } 2315 #endif 2316 2317 #if ((LINUX_VERSION_CODE > KERNEL_VERSION(4, 4, 0)) || \ 2318 defined(CFG80211_MULTI_SCAN_PLAN_BACKPORT)) && \ 2319 defined(FEATURE_WLAN_SCAN_PNO) 2320 void wlan_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy, 2321 struct wlan_objmgr_psoc *psoc) 2322 { 2323 if (ucfg_scan_get_pno_scan_support(psoc)) { 2324 wlan_scan_wiphy_set_max_sched_scans(wiphy, 1); 2325 wiphy->max_sched_scan_ssids = SCAN_PNO_MAX_SUPP_NETWORKS; 2326 wiphy->max_match_sets = SCAN_PNO_MAX_SUPP_NETWORKS; 2327 wiphy->max_sched_scan_ie_len = SCAN_MAX_IE_LENGTH; 2328 wiphy->max_sched_scan_plans = SCAN_PNO_MAX_PLAN_REQUEST; 2329 2330 wiphy->max_sched_scan_plan_interval = 2331 ucfg_scan_get_max_sched_scan_plan_interval(psoc); 2332 2333 wiphy->max_sched_scan_plan_iterations = 2334 ucfg_scan_get_max_sched_scan_plan_iterations(psoc); 2335 } 2336 } 2337 #endif 2338