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