Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Tushnim Bhattacharyya | ca50b32 | 2015-12-28 17:14:36 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * DOC: wlan_hdd_scan.c |
| 30 | * |
| 31 | * WLAN Host Device Driver scan implementation |
| 32 | */ |
| 33 | |
| 34 | #include <linux/wireless.h> |
| 35 | #include <net/cfg80211.h> |
| 36 | |
| 37 | #include "wlan_hdd_includes.h" |
| 38 | #include "cds_api.h" |
| 39 | #include "cds_api.h" |
| 40 | #include "ani_global.h" |
| 41 | #include "dot11f.h" |
| 42 | #include "cds_sched.h" |
| 43 | #include "wlan_hdd_p2p.h" |
| 44 | #include "wlan_hdd_trace.h" |
| 45 | #include "wlan_hdd_scan.h" |
| 46 | #include "cds_concurrency.h" |
| 47 | #include "wma_api.h" |
| 48 | |
| 49 | #define MAX_RATES 12 |
| 50 | #define HDD_WAKE_LOCK_SCAN_DURATION (5 * 1000) /* in msec */ |
| 51 | |
| 52 | #define SCAN_DONE_EVENT_BUF_SIZE 4096 |
| 53 | #define RATE_MASK 0x7f |
| 54 | |
| 55 | /** |
| 56 | * typedef tSSIDBcastType - SSID broadcast type |
| 57 | * @eBCAST_UNKNOWN: Broadcast unknown |
| 58 | * @eBCAST_NORMAL: Broadcast normal |
| 59 | * @eBCAST_HIDDEN: Broadcast hidden |
| 60 | */ |
| 61 | typedef enum eSSIDBcastType { |
| 62 | eBCAST_UNKNOWN = 0, |
| 63 | eBCAST_NORMAL = 1, |
| 64 | eBCAST_HIDDEN = 2, |
| 65 | } tSSIDBcastType; |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * typedef hdd_scan_info_t - HDD scan info |
| 70 | * @dev: Pointer to net device |
| 71 | * @info: Pointer to request info |
| 72 | * @start: Start pointer |
| 73 | * @end: End pointer |
| 74 | */ |
| 75 | typedef struct hdd_scan_info { |
| 76 | struct net_device *dev; |
| 77 | struct iw_request_info *info; |
| 78 | char *start; |
| 79 | char *end; |
| 80 | } hdd_scan_info_t, *hdd_scan_info_tp; |
| 81 | |
| 82 | /** |
| 83 | * hdd_translate_abg_rate_to_mbps_rate() - translate abg rate to Mbps rate |
| 84 | * @pFcRate: Rate pointer |
| 85 | * |
| 86 | * Return: Mbps rate in integer |
| 87 | */ |
| 88 | static int32_t hdd_translate_abg_rate_to_mbps_rate(uint8_t *pFcRate) |
| 89 | { |
| 90 | /* Slightly more sophisticated processing has to take place here. |
| 91 | * Basic rates are rounded DOWN. HT rates are rounded UP |
| 92 | */ |
| 93 | return ((((int32_t) *pFcRate) & 0x007f) * 1000000) / 2; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * hdd_add_iw_stream_event() - add iw stream event |
| 98 | * @cmd: Command |
| 99 | * @length: Length |
| 100 | * @data: Pointer to data |
| 101 | * @pscanInfo: Pointer to scan info |
| 102 | * @last_event: Pointer to pointer to last event |
| 103 | * @current_event: Pointer to pointer to current event |
| 104 | * |
| 105 | * Return: 0 for success, non zero for failure |
| 106 | */ |
| 107 | static int hdd_add_iw_stream_event(int cmd, int length, char *data, |
| 108 | hdd_scan_info_t *pscanInfo, |
| 109 | char **last_event, |
| 110 | char **current_event) |
| 111 | { |
| 112 | struct iw_event event; |
| 113 | |
| 114 | *last_event = *current_event; |
| 115 | cdf_mem_zero(&event, sizeof(struct iw_event)); |
| 116 | event.cmd = cmd; |
| 117 | event.u.data.flags = 1; |
| 118 | event.u.data.length = length; |
| 119 | *current_event = |
| 120 | iwe_stream_add_point(pscanInfo->info, *current_event, |
| 121 | pscanInfo->end, &event, data); |
| 122 | |
| 123 | if (*last_event == *current_event) { |
| 124 | /* no space to add event */ |
| 125 | hddLog(LOGE, "%s: no space left to add event", __func__); |
| 126 | return -E2BIG; /* Error code, may be E2BIG */ |
| 127 | } |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * hdd_get_wparsn_ies() - get wpa RSN IEs |
| 134 | * @ieFields: Pointer to the Bss Descriptor IEs |
| 135 | * @ie_length: IE Length |
| 136 | * @last_event: Points to last event |
| 137 | * @current_event: Points to current event |
| 138 | * |
| 139 | * This function extract the WPA/RSN IE from the Bss descriptor IEs fields |
| 140 | * |
| 141 | * Return: 0 for success, non zero for failure |
| 142 | */ |
| 143 | static int hdd_get_wparsn_ies(uint8_t *ieFields, uint16_t ie_length, |
| 144 | char **last_event, char **current_event, |
| 145 | hdd_scan_info_t *pscanInfo) |
| 146 | { |
| 147 | uint8_t eid, elen, *element; |
| 148 | uint16_t tie_length = 0; |
| 149 | |
| 150 | ENTER(); |
| 151 | |
| 152 | element = ieFields; |
| 153 | tie_length = ie_length; |
| 154 | |
| 155 | while (tie_length > 2 && element != NULL) { |
| 156 | eid = element[0]; |
| 157 | elen = element[1]; |
| 158 | |
| 159 | /* If element length is greater than total remaining ie length, |
| 160 | * break the loop |
| 161 | */ |
| 162 | if ((elen + 2) > tie_length) |
| 163 | break; |
| 164 | |
| 165 | switch (eid) { |
| 166 | case DOT11F_EID_WPA: |
| 167 | case DOT11F_EID_RSN: |
| 168 | #ifdef FEATURE_WLAN_WAPI |
| 169 | case DOT11F_EID_WAPI: |
| 170 | #endif |
| 171 | if (hdd_add_iw_stream_event |
| 172 | (IWEVGENIE, elen + 2, (char *)element, pscanInfo, |
| 173 | last_event, current_event) < 0) |
| 174 | return -E2BIG; |
| 175 | break; |
| 176 | |
| 177 | default: |
| 178 | break; |
| 179 | } |
| 180 | |
| 181 | /* Next element */ |
| 182 | tie_length -= (2 + elen); |
| 183 | element += 2 + elen; |
| 184 | } |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * hdd_indicate_scan_result() - indicate scan results |
| 191 | * @scanInfo: Pointer to the scan info structure. |
| 192 | * @descriptor: Pointer to the Bss Descriptor. |
| 193 | * |
| 194 | * This function returns the scan results to the wpa_supplicant |
| 195 | * |
| 196 | * @Return: 0 for success, non zero for failure |
| 197 | */ |
| 198 | #define MAX_CUSTOM_LEN 64 |
| 199 | static int hdd_indicate_scan_result(hdd_scan_info_t *scanInfo, |
| 200 | tCsrScanResultInfo *scan_result) |
| 201 | { |
| 202 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(scanInfo->dev); |
| 203 | tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); |
| 204 | tSirBssDescription *descriptor = &scan_result->BssDescriptor; |
| 205 | struct iw_event event; |
| 206 | char *current_event = scanInfo->start; |
| 207 | char *end = scanInfo->end; |
| 208 | char *last_event; |
| 209 | char *current_pad; |
| 210 | uint16_t ie_length = 0; |
| 211 | uint16_t capabilityInfo; |
| 212 | char *modestr; |
| 213 | int error; |
| 214 | char custom[MAX_CUSTOM_LEN]; |
| 215 | char *p; |
| 216 | |
| 217 | hddLog(LOG1, "hdd_indicate_scan_result " MAC_ADDRESS_STR, |
| 218 | MAC_ADDR_ARRAY(descriptor->bssId)); |
| 219 | |
| 220 | error = 0; |
| 221 | last_event = current_event; |
| 222 | cdf_mem_zero(&event, sizeof(event)); |
| 223 | |
| 224 | /* BSSID */ |
| 225 | event.cmd = SIOCGIWAP; |
| 226 | event.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 227 | cdf_mem_copy(event.u.ap_addr.sa_data, descriptor->bssId, |
| 228 | sizeof(descriptor->bssId)); |
| 229 | current_event = iwe_stream_add_event(scanInfo->info, current_event, end, |
| 230 | &event, IW_EV_ADDR_LEN); |
| 231 | |
| 232 | if (last_event == current_event) { |
| 233 | /* no space to add event */ |
| 234 | /* Error code may be E2BIG */ |
| 235 | hddLog(LOGE, "hdd_indicate_scan_result: no space for SIOCGIWAP "); |
| 236 | return -E2BIG; |
| 237 | } |
| 238 | |
| 239 | last_event = current_event; |
| 240 | cdf_mem_zero(&event, sizeof(struct iw_event)); |
| 241 | |
| 242 | /* Protocol Name */ |
| 243 | event.cmd = SIOCGIWNAME; |
| 244 | |
| 245 | switch (descriptor->nwType) { |
| 246 | case eSIR_11A_NW_TYPE: |
| 247 | modestr = "a"; |
| 248 | break; |
| 249 | case eSIR_11B_NW_TYPE: |
| 250 | modestr = "b"; |
| 251 | break; |
| 252 | case eSIR_11G_NW_TYPE: |
| 253 | modestr = "g"; |
| 254 | break; |
| 255 | case eSIR_11N_NW_TYPE: |
| 256 | modestr = "n"; |
| 257 | break; |
| 258 | default: |
| 259 | hddLog(LOGW, "%s: Unknown network type [%d]", |
| 260 | __func__, descriptor->nwType); |
| 261 | modestr = "?"; |
| 262 | break; |
| 263 | } |
| 264 | snprintf(event.u.name, IFNAMSIZ, "IEEE 802.11%s", modestr); |
| 265 | current_event = iwe_stream_add_event(scanInfo->info, current_event, end, |
| 266 | &event, IW_EV_CHAR_LEN); |
| 267 | |
| 268 | if (last_event == current_event) { /* no space to add event */ |
| 269 | hddLog(LOGE, |
| 270 | "hdd_indicate_scan_result: no space for SIOCGIWNAME"); |
| 271 | /* Error code, may be E2BIG */ |
| 272 | return -E2BIG; |
| 273 | } |
| 274 | |
| 275 | last_event = current_event; |
| 276 | cdf_mem_zero(&event, sizeof(struct iw_event)); |
| 277 | |
| 278 | /*Freq */ |
| 279 | event.cmd = SIOCGIWFREQ; |
| 280 | |
| 281 | event.u.freq.m = descriptor->channelId; |
| 282 | event.u.freq.e = 0; |
| 283 | event.u.freq.i = 0; |
| 284 | current_event = iwe_stream_add_event(scanInfo->info, current_event, end, |
| 285 | &event, IW_EV_FREQ_LEN); |
| 286 | |
| 287 | if (last_event == current_event) { /* no space to add event */ |
| 288 | hddLog(LOGE, |
| 289 | "hdd_indicate_scan_result: no space for SIOCGIWFREQ"); |
| 290 | return -E2BIG; |
| 291 | } |
| 292 | |
| 293 | last_event = current_event; |
| 294 | cdf_mem_zero(&event, sizeof(struct iw_event)); |
| 295 | |
| 296 | /* BSS Mode */ |
| 297 | event.cmd = SIOCGIWMODE; |
| 298 | |
| 299 | capabilityInfo = descriptor->capabilityInfo; |
| 300 | |
| 301 | if (SIR_MAC_GET_ESS(capabilityInfo)) { |
| 302 | event.u.mode = IW_MODE_MASTER; |
| 303 | } else if (SIR_MAC_GET_IBSS(capabilityInfo)) { |
| 304 | event.u.mode = IW_MODE_ADHOC; |
| 305 | } else { |
| 306 | /* neither ESS or IBSS */ |
| 307 | event.u.mode = IW_MODE_AUTO; |
| 308 | } |
| 309 | |
| 310 | current_event = iwe_stream_add_event(scanInfo->info, current_event, end, |
| 311 | &event, IW_EV_UINT_LEN); |
| 312 | |
| 313 | if (last_event == current_event) { /* no space to add event */ |
| 314 | hddLog(LOGE, |
| 315 | "hdd_indicate_scan_result: no space for SIOCGIWMODE"); |
| 316 | return -E2BIG; |
| 317 | } |
| 318 | /* To extract SSID */ |
| 319 | ie_length = GET_IE_LEN_IN_BSS(descriptor->length); |
| 320 | |
| 321 | if (ie_length > 0) { |
| 322 | /* dot11BeaconIEs is a large struct, so we make it static to |
| 323 | avoid stack overflow. This API is only invoked via ioctl, |
| 324 | so it is serialized by the kernel rtnl_lock and hence does |
| 325 | not need to be reentrant */ |
| 326 | static tDot11fBeaconIEs dot11BeaconIEs; |
| 327 | tDot11fIESSID *pDot11SSID; |
| 328 | tDot11fIESuppRates *pDot11SuppRates; |
| 329 | tDot11fIEExtSuppRates *pDot11ExtSuppRates; |
| 330 | tDot11fIEHTCaps *pDot11IEHTCaps; |
| 331 | int numBasicRates = 0; |
| 332 | int maxNumRates = 0; |
| 333 | |
| 334 | pDot11IEHTCaps = NULL; |
| 335 | |
| 336 | dot11f_unpack_beacon_i_es((tpAniSirGlobal) |
| 337 | hHal, (uint8_t *) descriptor->ieFields, |
| 338 | ie_length, &dot11BeaconIEs); |
| 339 | |
| 340 | pDot11SSID = &dot11BeaconIEs.SSID; |
| 341 | |
| 342 | if (pDot11SSID->present) { |
| 343 | last_event = current_event; |
| 344 | cdf_mem_zero(&event, sizeof(struct iw_event)); |
| 345 | |
| 346 | event.cmd = SIOCGIWESSID; |
| 347 | event.u.data.flags = 1; |
| 348 | event.u.data.length = scan_result->ssId.length; |
| 349 | current_event = |
| 350 | iwe_stream_add_point(scanInfo->info, current_event, |
| 351 | end, &event, |
| 352 | (char *)scan_result->ssId. |
| 353 | ssId); |
| 354 | |
| 355 | if (last_event == current_event) { /* no space to add event */ |
| 356 | hddLog(LOGE, |
| 357 | "hdd_indicate_scan_result: no space for SIOCGIWESSID"); |
| 358 | return -E2BIG; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | if (hdd_get_wparsn_ies |
| 363 | ((uint8_t *) descriptor->ieFields, ie_length, &last_event, |
| 364 | ¤t_event, scanInfo) < 0) { |
| 365 | hddLog(LOGE, |
| 366 | "hdd_indicate_scan_result: no space for SIOCGIWESSID"); |
| 367 | return -E2BIG; |
| 368 | } |
| 369 | |
| 370 | last_event = current_event; |
| 371 | current_pad = current_event + IW_EV_LCP_LEN; |
| 372 | cdf_mem_zero(&event, sizeof(struct iw_event)); |
| 373 | |
| 374 | /*Rates */ |
| 375 | event.cmd = SIOCGIWRATE; |
| 376 | |
| 377 | pDot11SuppRates = &dot11BeaconIEs.SuppRates; |
| 378 | |
| 379 | if (pDot11SuppRates->present) { |
| 380 | int i; |
| 381 | |
| 382 | numBasicRates = pDot11SuppRates->num_rates; |
| 383 | for (i = 0; i < pDot11SuppRates->num_rates; i++) { |
| 384 | if (0 != (pDot11SuppRates->rates[i] & 0x7F)) { |
| 385 | event.u.bitrate.value = |
| 386 | hdd_translate_abg_rate_to_mbps_rate |
| 387 | (&pDot11SuppRates->rates[i]); |
| 388 | |
| 389 | current_pad = |
| 390 | iwe_stream_add_value(scanInfo->info, |
| 391 | current_event, |
| 392 | current_pad, |
| 393 | end, &event, |
| 394 | IW_EV_PARAM_LEN); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | } |
| 399 | |
| 400 | pDot11ExtSuppRates = &dot11BeaconIEs.ExtSuppRates; |
| 401 | |
| 402 | if (pDot11ExtSuppRates->present) { |
| 403 | int i, no_of_rates; |
| 404 | maxNumRates = |
| 405 | numBasicRates + pDot11ExtSuppRates->num_rates; |
| 406 | |
| 407 | /* Check to make sure the total number of rates |
| 408 | * doesn't exceed IW_MAX_BITRATES |
| 409 | */ |
| 410 | |
| 411 | maxNumRates = CDF_MIN(maxNumRates, IW_MAX_BITRATES); |
| 412 | |
| 413 | if ((maxNumRates - numBasicRates) > MAX_RATES) { |
| 414 | no_of_rates = MAX_RATES; |
| 415 | hddLog(LOGW, |
| 416 | "Accessing array out of bound that array is pDot11ExtSuppRates->rates "); |
| 417 | } else { |
| 418 | no_of_rates = maxNumRates - numBasicRates; |
| 419 | } |
| 420 | for (i = 0; i < no_of_rates; i++) { |
| 421 | if (0 != (pDot11ExtSuppRates->rates[i] & 0x7F)) { |
| 422 | event.u.bitrate.value = |
| 423 | hdd_translate_abg_rate_to_mbps_rate |
| 424 | (&pDot11ExtSuppRates->rates[i]); |
| 425 | |
| 426 | current_pad = |
| 427 | iwe_stream_add_value(scanInfo->info, |
| 428 | current_event, |
| 429 | current_pad, |
| 430 | end, &event, |
| 431 | IW_EV_PARAM_LEN); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if ((current_pad - current_event) >= IW_EV_LCP_LEN) { |
| 437 | current_event = current_pad; |
| 438 | } else { |
| 439 | if (last_event == current_event) { /* no space to add event */ |
| 440 | hddLog(LOGE, |
| 441 | "hdd_indicate_scan_result: no space for SIOCGIWRATE"); |
| 442 | return -E2BIG; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | last_event = current_event; |
| 447 | cdf_mem_zero(&event, sizeof(struct iw_event)); |
| 448 | |
| 449 | event.cmd = SIOCGIWENCODE; |
| 450 | |
| 451 | if (SIR_MAC_GET_PRIVACY(capabilityInfo)) { |
| 452 | event.u.data.flags = |
| 453 | IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 454 | } else { |
| 455 | event.u.data.flags = IW_ENCODE_DISABLED; |
| 456 | } |
| 457 | event.u.data.length = 0; |
| 458 | |
| 459 | current_event = |
| 460 | iwe_stream_add_point(scanInfo->info, current_event, end, |
| 461 | &event, (char *)pDot11SSID->ssid); |
| 462 | if (last_event == current_event) { |
| 463 | hddLog(LOGE, |
| 464 | "hdd_indicate_scan_result: no space for SIOCGIWENCODE"); |
| 465 | return -E2BIG; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | last_event = current_event; |
| 470 | cdf_mem_zero(&event, sizeof(struct iw_event)); |
| 471 | |
| 472 | /* RSSI */ |
| 473 | event.cmd = IWEVQUAL; |
| 474 | event.u.qual.qual = descriptor->rssi; |
| 475 | event.u.qual.noise = descriptor->sinr; |
| 476 | event.u.qual.level = CDF_MIN((descriptor->rssi + descriptor->sinr), 0); |
| 477 | |
| 478 | event.u.qual.updated = IW_QUAL_ALL_UPDATED; |
| 479 | |
| 480 | current_event = iwe_stream_add_event(scanInfo->info, current_event, |
| 481 | end, &event, IW_EV_QUAL_LEN); |
| 482 | |
| 483 | if (last_event == current_event) { /* no space to add event */ |
| 484 | hddLog(LOGE, "hdd_indicate_scan_result: no space for IWEVQUAL"); |
| 485 | return -E2BIG; |
| 486 | } |
| 487 | |
| 488 | /* AGE */ |
| 489 | event.cmd = IWEVCUSTOM; |
| 490 | p = custom; |
| 491 | p += scnprintf(p, MAX_CUSTOM_LEN, " Age: %lu", |
| 492 | cdf_mc_timer_get_system_ticks() - |
| 493 | descriptor->nReceivedTime); |
| 494 | event.u.data.length = p - custom; |
| 495 | current_event = iwe_stream_add_point(scanInfo->info, current_event, end, |
| 496 | &event, custom); |
| 497 | if (last_event == current_event) { /* no space to add event */ |
| 498 | hddLog(LOGE, |
| 499 | "hdd_indicate_scan_result: no space for IWEVCUSTOM (age)"); |
| 500 | return -E2BIG; |
| 501 | } |
| 502 | |
| 503 | scanInfo->start = current_event; |
| 504 | |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | |
| 509 | /** |
| 510 | * wlan_hdd_scan_request_enqueue() - enqueue Scan Request |
| 511 | * @adapter: Pointer to the adapter |
| 512 | * @scan_req: Pointer to the scan request |
| 513 | * |
| 514 | * Enqueue scan request in the global HDD scan list.This list |
| 515 | * stores the active scan request information. |
| 516 | * |
| 517 | * Return: 0 on success, error number otherwise |
| 518 | */ |
| 519 | static int wlan_hdd_scan_request_enqueue(hdd_adapter_t *adapter, |
| 520 | struct cfg80211_scan_request *scan_req, |
| 521 | uint8_t source, uint32_t scan_id, |
| 522 | uint32_t timestamp) |
| 523 | { |
| 524 | hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 525 | struct hdd_scan_req *hdd_scan_req; |
| 526 | CDF_STATUS status; |
| 527 | |
| 528 | ENTER(); |
| 529 | hdd_scan_req = cdf_mem_malloc(sizeof(*hdd_scan_req)); |
| 530 | if (NULL == hdd_scan_req) { |
| 531 | hddLog(LOGP, FL("malloc failed for Scan req")); |
| 532 | return -ENOMEM; |
| 533 | } |
| 534 | |
| 535 | hdd_scan_req->adapter = adapter; |
| 536 | hdd_scan_req->scan_request = scan_req; |
| 537 | hdd_scan_req->source = source; |
| 538 | hdd_scan_req->scan_id = scan_id; |
| 539 | hdd_scan_req->timestamp = timestamp; |
| 540 | |
| 541 | cdf_spin_lock(&hdd_ctx->hdd_scan_req_q_lock); |
| 542 | status = cdf_list_insert_back(&hdd_ctx->hdd_scan_req_q, |
| 543 | &hdd_scan_req->node); |
| 544 | cdf_spin_unlock(&hdd_ctx->hdd_scan_req_q_lock); |
| 545 | |
| 546 | if (CDF_STATUS_SUCCESS != status) { |
| 547 | hdd_err("Failed to enqueue Scan Req"); |
| 548 | cdf_mem_free(hdd_scan_req); |
| 549 | return -EINVAL; |
| 550 | } |
| 551 | EXIT(); |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * wlan_hdd_scan_request_dequeue() - dequeue scan request |
| 557 | * @hdd_ctx: Global HDD context |
| 558 | * @scan_id: scan id |
| 559 | * @req: scan request |
| 560 | * @source : returns source of the scan request |
| 561 | * @timestamp: scan request timestamp |
| 562 | * |
| 563 | * Return: CDF_STATUS |
| 564 | */ |
| 565 | CDF_STATUS wlan_hdd_scan_request_dequeue(hdd_context_t *hdd_ctx, |
| 566 | uint32_t scan_id, struct cfg80211_scan_request **req, uint8_t *source, |
| 567 | uint32_t *timestamp) |
| 568 | { |
| 569 | CDF_STATUS status = CDF_STATUS_E_FAILURE; |
| 570 | struct hdd_scan_req *hdd_scan_req; |
| 571 | cdf_list_node_t *pNode = NULL, *ppNode = NULL; |
| 572 | |
| 573 | hdd_info("Dequeue Scan id: %d", scan_id); |
| 574 | |
| 575 | if ((source == NULL) && (timestamp == NULL) && (req == NULL)) |
| 576 | return CDF_STATUS_E_NULL_VALUE; |
| 577 | |
| 578 | cdf_spin_lock(&hdd_ctx->hdd_scan_req_q_lock); |
| 579 | |
| 580 | if (list_empty(&hdd_ctx->hdd_scan_req_q.anchor)) { |
| 581 | cdf_spin_unlock(&hdd_ctx->hdd_scan_req_q_lock); |
| 582 | return CDF_STATUS_E_FAILURE; |
| 583 | } |
| 584 | |
| 585 | if (CDF_STATUS_SUCCESS != |
| 586 | cdf_list_peek_front(&hdd_ctx->hdd_scan_req_q, &ppNode)) { |
| 587 | cdf_spin_unlock(&hdd_ctx->hdd_scan_req_q_lock); |
| 588 | hdd_err("Failed to remove Scan Req from queue"); |
| 589 | return CDF_STATUS_E_FAILURE; |
| 590 | } |
| 591 | |
| 592 | do { |
| 593 | pNode = ppNode; |
| 594 | hdd_scan_req = (struct hdd_scan_req *)pNode; |
| 595 | if (hdd_scan_req->scan_id == scan_id) { |
| 596 | status = cdf_list_remove_node(&hdd_ctx->hdd_scan_req_q, |
| 597 | pNode); |
| 598 | if (status == CDF_STATUS_SUCCESS) { |
| 599 | *req = hdd_scan_req->scan_request; |
| 600 | *source = hdd_scan_req->source; |
| 601 | *timestamp = hdd_scan_req->timestamp; |
| 602 | cdf_mem_free(hdd_scan_req); |
| 603 | cdf_spin_unlock(&hdd_ctx->hdd_scan_req_q_lock); |
| 604 | hdd_info("removed Scan id: %d, req = %p", |
| 605 | scan_id, req); |
| 606 | return CDF_STATUS_SUCCESS; |
| 607 | } else { |
| 608 | cdf_spin_unlock(&hdd_ctx->hdd_scan_req_q_lock); |
| 609 | hdd_err("Failed to remove node scan id %d", |
| 610 | scan_id); |
| 611 | return status; |
| 612 | } |
| 613 | } |
| 614 | } while (CDF_STATUS_SUCCESS == |
| 615 | cdf_list_peek_next(&hdd_ctx->hdd_scan_req_q, pNode, &ppNode)); |
| 616 | |
| 617 | cdf_spin_unlock(&hdd_ctx->hdd_scan_req_q_lock); |
| 618 | hdd_err("Failed to find scan id %d", scan_id); |
| 619 | return status; |
| 620 | } |
| 621 | |
| 622 | /** |
| 623 | * hdd_scan_request_callback() - scan complete callback from SME |
| 624 | * @halHandle: Pointer to the Hal Handle |
| 625 | * @pContext: Pointer to the data context |
| 626 | * @sessionId: Session identifier |
| 627 | * @scanId: Scan ID |
| 628 | * @status: CSR Status |
| 629 | * |
| 630 | * The sme module calls this callback function once it finish the scan request |
| 631 | * and this function notifies the scan complete event to the wpa_supplicant. |
| 632 | * |
| 633 | * Return: 0 for success, non zero for failure |
| 634 | */ |
| 635 | |
| 636 | static CDF_STATUS |
| 637 | hdd_scan_request_callback(tHalHandle halHandle, void *pContext, |
| 638 | uint8_t sessionId, uint32_t scanId, |
| 639 | eCsrScanStatus status) |
| 640 | { |
| 641 | struct net_device *dev = (struct net_device *)pContext; |
| 642 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 643 | hdd_context_t *hddctx = WLAN_HDD_GET_CTX(pAdapter); |
| 644 | union iwreq_data wrqu; |
| 645 | int we_event; |
| 646 | char *msg; |
| 647 | uint8_t source; |
| 648 | struct cfg80211_scan_request *req; |
| 649 | uint32_t timestamp; |
| 650 | uint32_t size = 0; |
| 651 | |
| 652 | ENTER(); |
| 653 | hddLog(LOGW, |
| 654 | "%s called with halHandle = %p, pContext = %p, scanID = %d," |
| 655 | " returned status = %d", __func__, halHandle, pContext, |
| 656 | (int)scanId, (int)status); |
| 657 | |
| 658 | /* if there is a scan request pending when the wlan driver is unloaded |
| 659 | * we may be invoked as SME flushes its pending queue. If that is the |
| 660 | * case, the underlying net_device may have already been destroyed, so |
| 661 | * do some quick sanity before proceeding |
| 662 | */ |
| 663 | if (pAdapter->dev != dev) { |
| 664 | hddLog(LOGW, "%s: device mismatch %p vs %p", |
| 665 | __func__, pAdapter->dev, dev); |
| 666 | return CDF_STATUS_SUCCESS; |
| 667 | } |
| 668 | |
| 669 | wlan_hdd_scan_request_dequeue(hddctx, scanId, &req, &source, |
| 670 | ×tamp); |
| 671 | |
| 672 | if (req != NULL) |
| 673 | hdd_err("Got unexpected request struct for Scan id %d", |
| 674 | scanId); |
| 675 | |
| 676 | cdf_spin_lock(&hddctx->hdd_scan_req_q_lock); |
| 677 | cdf_list_size(&(hddctx->hdd_scan_req_q), &size); |
| 678 | if (!size) |
| 679 | /* Scan is no longer pending */ |
| 680 | pAdapter->scan_info.mScanPending = false; |
| 681 | cdf_spin_unlock(&hddctx->hdd_scan_req_q_lock); |
| 682 | |
| 683 | /* notify any applications that may be interested */ |
| 684 | memset(&wrqu, '\0', sizeof(wrqu)); |
| 685 | we_event = SIOCGIWSCAN; |
| 686 | msg = NULL; |
| 687 | wireless_send_event(dev, we_event, &wrqu, msg); |
| 688 | |
| 689 | EXIT(); |
| 690 | return CDF_STATUS_SUCCESS; |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * __iw_set_scan() - set scan request |
| 695 | * @dev: Pointer to the net device |
| 696 | * @info: Pointer to the iw_request_info |
| 697 | * @wrqu: Pointer to the iwreq_data |
| 698 | * @extra: Pointer to the data |
| 699 | * |
| 700 | * This function process the scan request from the wpa_supplicant |
| 701 | * and set the scan request to the SME |
| 702 | * |
| 703 | * Return: 0 for success, non zero for failure |
| 704 | */ |
| 705 | |
| 706 | static int __iw_set_scan(struct net_device *dev, struct iw_request_info *info, |
| 707 | union iwreq_data *wrqu, char *extra) |
| 708 | { |
| 709 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 710 | hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); |
| 711 | hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter); |
| 712 | tCsrScanRequest scanRequest; |
| 713 | CDF_STATUS status = CDF_STATUS_SUCCESS; |
| 714 | struct iw_scan_req *scanReq = (struct iw_scan_req *)extra; |
| 715 | hdd_adapter_t *con_sap_adapter; |
| 716 | uint16_t con_dfs_ch; |
| 717 | int ret; |
| 718 | |
| 719 | ENTER(); |
| 720 | |
| 721 | hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); |
| 722 | ret = wlan_hdd_validate_context(hdd_ctx); |
| 723 | if (0 != ret) |
| 724 | return ret; |
| 725 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 726 | /* Block All Scan during DFS operation and send null scan result */ |
| 727 | con_sap_adapter = hdd_get_con_sap_adapter(pAdapter, true); |
| 728 | if (con_sap_adapter) { |
| 729 | con_dfs_ch = con_sap_adapter->sessionCtx.ap.operatingChannel; |
| 730 | |
| 731 | if (CDS_IS_DFS_CH(con_dfs_ch)) { |
| 732 | hddLog(LOGW, FL("##In DFS Master mode. Scan aborted")); |
| 733 | return -EOPNOTSUPP; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | cdf_mem_zero(&scanRequest, sizeof(scanRequest)); |
| 738 | |
| 739 | if (NULL != wrqu->data.pointer) { |
| 740 | /* set scanType, active or passive */ |
| 741 | if ((IW_SCAN_TYPE_ACTIVE == scanReq->scan_type) || |
| 742 | (eSIR_ACTIVE_SCAN == hdd_ctx->ioctl_scan_mode)) { |
| 743 | scanRequest.scanType = eSIR_ACTIVE_SCAN; |
| 744 | } else { |
| 745 | scanRequest.scanType = eSIR_PASSIVE_SCAN; |
| 746 | } |
| 747 | |
| 748 | /* set bssid using sockaddr from iw_scan_req */ |
| 749 | cdf_mem_copy(scanRequest.bssid.bytes, |
| 750 | &scanReq->bssid.sa_data, |
| 751 | CDF_MAC_ADDR_SIZE); |
| 752 | |
| 753 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
| 754 | |
| 755 | if (scanReq->essid_len) { |
| 756 | scanRequest.SSIDs.numOfSSIDs = 1; |
| 757 | scanRequest.SSIDs.SSIDList = |
| 758 | (tCsrSSIDInfo *) |
| 759 | cdf_mem_malloc(sizeof(tCsrSSIDInfo)); |
| 760 | if (scanRequest.SSIDs.SSIDList) { |
| 761 | scanRequest.SSIDs.SSIDList->SSID. |
| 762 | length = scanReq->essid_len; |
| 763 | cdf_mem_copy(scanRequest.SSIDs. |
| 764 | SSIDList->SSID.ssId, |
| 765 | scanReq->essid, |
| 766 | scanReq->essid_len); |
| 767 | } else { |
| 768 | scanRequest.SSIDs.numOfSSIDs = 0; |
| 769 | CDF_TRACE(CDF_MODULE_ID_HDD, |
| 770 | CDF_TRACE_LEVEL_ERROR, |
| 771 | "%s: Unable to allocate memory", |
| 772 | __func__); |
| 773 | CDF_ASSERT(0); |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | /* set min and max channel time */ |
| 779 | scanRequest.minChnTime = scanReq->min_channel_time; |
| 780 | scanRequest.maxChnTime = scanReq->max_channel_time; |
| 781 | |
| 782 | } else { |
| 783 | if (hdd_ctx->ioctl_scan_mode == eSIR_ACTIVE_SCAN) { |
| 784 | /* set the scan type to active */ |
| 785 | scanRequest.scanType = eSIR_ACTIVE_SCAN; |
| 786 | } else { |
| 787 | scanRequest.scanType = eSIR_PASSIVE_SCAN; |
| 788 | } |
| 789 | |
| 790 | cdf_set_macaddr_broadcast(&scanRequest.bssid); |
| 791 | |
| 792 | /* set min and max channel time to zero */ |
| 793 | scanRequest.minChnTime = 0; |
| 794 | scanRequest.maxChnTime = 0; |
| 795 | } |
| 796 | |
| 797 | /* set BSSType to default type */ |
| 798 | scanRequest.BSSType = eCSR_BSS_TYPE_ANY; |
| 799 | |
| 800 | /*Scan all the channels */ |
| 801 | scanRequest.ChannelInfo.numOfChannels = 0; |
| 802 | |
| 803 | scanRequest.ChannelInfo.ChannelList = NULL; |
| 804 | |
| 805 | /* set requestType to full scan */ |
| 806 | scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN; |
| 807 | |
| 808 | /* if previous genIE is not NULL, update ScanIE */ |
| 809 | if (0 != pwextBuf->genIE.length) { |
| 810 | memset(&pAdapter->scan_info.scanAddIE, 0, |
| 811 | sizeof(pAdapter->scan_info.scanAddIE)); |
| 812 | memcpy(pAdapter->scan_info.scanAddIE.addIEdata, |
| 813 | pwextBuf->genIE.addIEdata, pwextBuf->genIE.length); |
| 814 | pAdapter->scan_info.scanAddIE.length = pwextBuf->genIE.length; |
| 815 | |
| 816 | pwextBuf->roamProfile.pAddIEScan = |
| 817 | pAdapter->scan_info.scanAddIE.addIEdata; |
| 818 | pwextBuf->roamProfile.nAddIEScanLength = |
| 819 | pAdapter->scan_info.scanAddIE.length; |
| 820 | |
| 821 | /* clear previous genIE after use it */ |
| 822 | memset(&pwextBuf->genIE, 0, sizeof(pwextBuf->genIE)); |
| 823 | } |
| 824 | |
| 825 | /* push addIEScan in scanRequset if exist */ |
| 826 | if (pAdapter->scan_info.scanAddIE.addIEdata && |
| 827 | pAdapter->scan_info.scanAddIE.length) { |
| 828 | scanRequest.uIEFieldLen = pAdapter->scan_info.scanAddIE.length; |
| 829 | scanRequest.pIEField = pAdapter->scan_info.scanAddIE.addIEdata; |
| 830 | } |
| 831 | scanRequest.timestamp = cdf_mc_timer_get_system_ticks(); |
| 832 | status = sme_scan_request((WLAN_HDD_GET_CTX(pAdapter))->hHal, |
| 833 | pAdapter->sessionId, &scanRequest, |
| 834 | &hdd_scan_request_callback, dev); |
| 835 | if (!CDF_IS_STATUS_SUCCESS(status)) { |
| 836 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_FATAL, |
| 837 | "%s:sme_scan_request fail %d!!!", __func__, status); |
| 838 | goto error; |
| 839 | } |
| 840 | |
| 841 | wlan_hdd_scan_request_enqueue(pAdapter, NULL, NL_SCAN, |
| 842 | scanRequest.scan_id, |
| 843 | scanRequest.timestamp); |
| 844 | |
| 845 | pAdapter->scan_info.mScanPending = true; |
| 846 | error: |
| 847 | if ((wrqu->data.flags & IW_SCAN_THIS_ESSID) && (scanReq->essid_len)) |
| 848 | cdf_mem_free(scanRequest.SSIDs.SSIDList); |
| 849 | EXIT(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 850 | return status; |
| 851 | } |
| 852 | |
| 853 | /** |
| 854 | * iw_set_scan() - SSR wrapper for __iw_set_scan |
| 855 | * @dev: Pointer to the net device. |
| 856 | * @info: Pointer to the iw_request_info. |
| 857 | * @wrqu: Pointer to the iwreq_data. |
| 858 | * @extra: Pointer to the data. |
| 859 | * |
| 860 | * Return: 0 on success, error number otherwise |
| 861 | */ |
| 862 | int iw_set_scan(struct net_device *dev, struct iw_request_info *info, |
| 863 | union iwreq_data *wrqu, char *extra) |
| 864 | { |
| 865 | int ret; |
| 866 | |
| 867 | cds_ssr_protect(__func__); |
| 868 | ret = __iw_set_scan(dev, info, wrqu, extra); |
| 869 | cds_ssr_unprotect(__func__); |
| 870 | |
| 871 | return ret; |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * __iw_get_scan() - get scan |
| 876 | * @dev: Pointer to the net device. |
| 877 | * @info: Pointer to the iw_request_info. |
| 878 | * @wrqu: Pointer to the iwreq_data. |
| 879 | * @extra: Pointer to the data. |
| 880 | * |
| 881 | * This function returns the scan results to the wpa_supplicant |
| 882 | * |
| 883 | * Return: 0 for success, non zero for failure |
| 884 | */ |
| 885 | |
| 886 | static int __iw_get_scan(struct net_device *dev, |
| 887 | struct iw_request_info *info, |
| 888 | union iwreq_data *wrqu, char *extra) |
| 889 | { |
| 890 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 891 | hdd_context_t *hdd_ctx; |
| 892 | tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); |
| 893 | tCsrScanResultInfo *pScanResult; |
| 894 | CDF_STATUS status = CDF_STATUS_SUCCESS; |
| 895 | hdd_scan_info_t scanInfo; |
| 896 | tScanResultHandle pResult; |
| 897 | int i = 0; |
| 898 | int ret; |
| 899 | |
| 900 | ENTER(); |
| 901 | |
| 902 | hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); |
| 903 | ret = wlan_hdd_validate_context(hdd_ctx); |
| 904 | if (0 != ret) |
| 905 | return ret; |
| 906 | |
| 907 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_INFO, |
| 908 | "%s: enter buffer length %d!!!", __func__, |
| 909 | (wrqu->data.length) ? wrqu->data.length : IW_SCAN_MAX_DATA); |
| 910 | |
| 911 | if (true == pAdapter->scan_info.mScanPending) { |
| 912 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_FATAL, |
| 913 | "%s:mScanPending is true !!!", __func__); |
| 914 | return -EAGAIN; |
| 915 | } |
| 916 | |
| 917 | scanInfo.dev = dev; |
| 918 | scanInfo.start = extra; |
| 919 | scanInfo.info = info; |
| 920 | |
| 921 | if (0 == wrqu->data.length) { |
| 922 | scanInfo.end = extra + IW_SCAN_MAX_DATA; |
| 923 | } else { |
| 924 | scanInfo.end = extra + wrqu->data.length; |
| 925 | } |
| 926 | |
| 927 | status = sme_scan_get_result(hHal, pAdapter->sessionId, NULL, &pResult); |
| 928 | |
| 929 | if (NULL == pResult) { |
| 930 | /* no scan results */ |
| 931 | hddLog(LOG1, "iw_get_scan: NULL Scan Result "); |
| 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | pScanResult = sme_scan_result_get_first(hHal, pResult); |
| 936 | |
| 937 | while (pScanResult) { |
| 938 | status = hdd_indicate_scan_result(&scanInfo, pScanResult); |
| 939 | if (0 != status) { |
| 940 | break; |
| 941 | } |
| 942 | i++; |
| 943 | pScanResult = sme_scan_result_get_next(hHal, pResult); |
| 944 | } |
| 945 | |
| 946 | sme_scan_result_purge(hHal, pResult); |
| 947 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 948 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_INFO, |
| 949 | "%s: exit total %d BSS reported !!!", __func__, i); |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 950 | EXIT(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 951 | return status; |
| 952 | } |
| 953 | |
| 954 | /** |
| 955 | * iw_get_scan() - SSR wrapper function for __iw_get_scan |
| 956 | * @dev: Pointer to the net device. |
| 957 | * @info: Pointer to the iw_request_info. |
| 958 | * @wrqu: Pointer to the iwreq_data. |
| 959 | * @extra: Pointer to the data. |
| 960 | * |
| 961 | * Return: 0 on success, error number otherwise |
| 962 | */ |
| 963 | int iw_get_scan(struct net_device *dev, |
| 964 | struct iw_request_info *info, |
| 965 | union iwreq_data *wrqu, char *extra) |
| 966 | { |
| 967 | int ret; |
| 968 | |
| 969 | cds_ssr_protect(__func__); |
| 970 | ret = __iw_get_scan(dev, info, wrqu, extra); |
| 971 | cds_ssr_unprotect(__func__); |
| 972 | |
| 973 | return ret; |
| 974 | } |
| 975 | |
| 976 | /** |
| 977 | * hdd_abort_mac_scan() - aborts ongoing mac scan |
| 978 | * @pHddCtx: Pointer to hdd context |
| 979 | * @sessionId: session id |
| 980 | * @reason: abort reason |
| 981 | * |
| 982 | * Abort any MAC scan if in progress |
| 983 | * |
| 984 | * Return: none |
| 985 | */ |
| 986 | void hdd_abort_mac_scan(hdd_context_t *pHddCtx, uint8_t sessionId, |
| 987 | eCsrAbortReason reason) |
| 988 | { |
| 989 | sme_abort_mac_scan(pHddCtx->hHal, sessionId, reason); |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * hdd_vendor_scan_callback() - Scan completed callback event |
| 994 | * @hddctx: HDD context |
| 995 | * @req : Scan request |
| 996 | * @aborted : true scan aborted false scan success |
| 997 | * |
| 998 | * This function sends scan completed callback event to NL. |
| 999 | * |
| 1000 | * Return: none |
| 1001 | */ |
| 1002 | static void hdd_vendor_scan_callback(hdd_adapter_t *adapter, |
| 1003 | struct cfg80211_scan_request *req, |
| 1004 | bool aborted) |
| 1005 | { |
| 1006 | hdd_context_t *hddctx = WLAN_HDD_GET_CTX(adapter); |
| 1007 | struct sk_buff *skb; |
| 1008 | struct nlattr *attr; |
| 1009 | int i; |
| 1010 | uint8_t scan_status; |
| 1011 | uint64_t cookie; |
| 1012 | |
| 1013 | ENTER(); |
| 1014 | |
| 1015 | if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) { |
| 1016 | hdd_err("Invalid adapter magic"); |
Sandeep Puligilla | a8d2f52 | 2016-01-19 18:24:35 -0800 | [diff] [blame^] | 1017 | cdf_mem_free(req); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1018 | return; |
| 1019 | } |
| 1020 | skb = cfg80211_vendor_event_alloc(hddctx->wiphy, NULL, |
| 1021 | SCAN_DONE_EVENT_BUF_SIZE + 4 + NLMSG_HDRLEN, |
| 1022 | QCA_NL80211_VENDOR_SUBCMD_SCAN_DONE_INDEX, |
| 1023 | GFP_KERNEL); |
| 1024 | |
| 1025 | if (!skb) { |
| 1026 | hdd_err("skb alloc failed"); |
Sandeep Puligilla | a8d2f52 | 2016-01-19 18:24:35 -0800 | [diff] [blame^] | 1027 | cdf_mem_free(req); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1028 | return; |
| 1029 | } |
| 1030 | |
| 1031 | if (0 != hdd_vendor_put_ifindex(skb, adapter->dev->ifindex)) |
| 1032 | goto nla_put_failure; |
| 1033 | |
| 1034 | cookie = (uintptr_t)req; |
| 1035 | |
| 1036 | attr = nla_nest_start(skb, QCA_WLAN_VENDOR_ATTR_SCAN_SSIDS); |
| 1037 | if (!attr) |
| 1038 | goto nla_put_failure; |
| 1039 | for (i = 0; i < req->n_ssids; i++) { |
| 1040 | if (nla_put(skb, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 1041 | goto nla_put_failure; |
| 1042 | } |
| 1043 | nla_nest_end(skb, attr); |
| 1044 | |
| 1045 | attr = nla_nest_start(skb, QCA_WLAN_VENDOR_ATTR_SCAN_FREQUENCIES); |
| 1046 | if (!attr) |
| 1047 | goto nla_put_failure; |
| 1048 | for (i = 0; i < req->n_channels; i++) { |
| 1049 | if (nla_put_u32(skb, i, req->channels[i]->center_freq)) |
| 1050 | goto nla_put_failure; |
| 1051 | } |
| 1052 | nla_nest_end(skb, attr); |
| 1053 | |
| 1054 | if (req->ie && |
| 1055 | nla_put(skb, QCA_WLAN_VENDOR_ATTR_SCAN_IE, req->ie_len, |
| 1056 | req->ie)) |
| 1057 | goto nla_put_failure; |
| 1058 | |
| 1059 | if (req->flags && |
| 1060 | nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_SCAN_FLAGS, req->flags)) |
| 1061 | goto nla_put_failure; |
| 1062 | |
| 1063 | if (nla_put_u64(skb, QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE, cookie)) |
| 1064 | goto nla_put_failure; |
| 1065 | |
| 1066 | scan_status = (aborted == true) ? VENDOR_SCAN_STATUS_ABORTED : |
| 1067 | VENDOR_SCAN_STATUS_NEW_RESULTS; |
| 1068 | if (nla_put_u8(skb, QCA_WLAN_VENDOR_ATTR_SCAN_STATUS, scan_status)) |
| 1069 | goto nla_put_failure; |
| 1070 | |
| 1071 | cfg80211_vendor_event(skb, GFP_KERNEL); |
Sandeep Puligilla | a8d2f52 | 2016-01-19 18:24:35 -0800 | [diff] [blame^] | 1072 | cdf_mem_free(req); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1073 | return; |
| 1074 | |
| 1075 | nla_put_failure: |
| 1076 | kfree_skb(skb); |
Sandeep Puligilla | a8d2f52 | 2016-01-19 18:24:35 -0800 | [diff] [blame^] | 1077 | cdf_mem_free(req); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1078 | return; |
| 1079 | } |
| 1080 | |
| 1081 | /** |
| 1082 | * hdd_cfg80211_scan_done_callback() - scan done callback function called after |
| 1083 | * scan is finished |
| 1084 | * @halHandle: Pointer to handle |
| 1085 | * @pContext: Pointer to context |
| 1086 | * @sessionId: Session Id |
| 1087 | * @scanId: Scan Id |
| 1088 | * @status: Scan status |
| 1089 | * |
| 1090 | * Return: CDF status |
| 1091 | */ |
| 1092 | static CDF_STATUS hdd_cfg80211_scan_done_callback(tHalHandle halHandle, |
| 1093 | void *pContext, |
| 1094 | uint8_t sessionId, |
| 1095 | uint32_t scanId, |
| 1096 | eCsrScanStatus status) |
| 1097 | { |
| 1098 | struct net_device *dev = (struct net_device *)pContext; |
| 1099 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 1100 | hdd_scaninfo_t *pScanInfo = &pAdapter->scan_info; |
| 1101 | struct cfg80211_scan_request *req = NULL; |
| 1102 | bool aborted = false; |
| 1103 | hdd_context_t *hddctx = WLAN_HDD_GET_CTX(pAdapter); |
| 1104 | int ret = 0; |
| 1105 | uint8_t source; |
| 1106 | uint32_t scan_time; |
| 1107 | uint32_t size = 0; |
| 1108 | |
Bhargav Shah | 1efa55c | 2015-11-04 11:58:27 +0530 | [diff] [blame] | 1109 | ret = wlan_hdd_validate_context(hddctx); |
| 1110 | if (0 != ret) |
| 1111 | return CDF_STATUS_E_INVAL; |
| 1112 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1113 | hddLog(CDF_TRACE_LEVEL_INFO, |
| 1114 | "%s called with hal = %p, pContext = %p, ID = %d, status = %d", |
| 1115 | __func__, halHandle, pContext, (int)scanId, (int)status); |
| 1116 | |
| 1117 | pScanInfo->mScanPendingCounter = 0; |
| 1118 | |
| 1119 | if (pScanInfo->mScanPending != true) { |
| 1120 | CDF_ASSERT(pScanInfo->mScanPending); |
| 1121 | goto allow_suspend; |
| 1122 | } |
| 1123 | |
| 1124 | if (CDF_STATUS_SUCCESS != |
| 1125 | wlan_hdd_scan_request_dequeue(hddctx, scanId, &req, &source, |
| 1126 | &scan_time)) { |
| 1127 | hdd_err("Dequeue of scan request failed ID: %d", scanId); |
| 1128 | goto allow_suspend; |
| 1129 | } |
| 1130 | |
| 1131 | ret = wlan_hdd_cfg80211_update_bss((WLAN_HDD_GET_CTX(pAdapter))->wiphy, |
| 1132 | pAdapter, scan_time); |
| 1133 | if (0 > ret) |
| 1134 | hddLog(CDF_TRACE_LEVEL_INFO, "%s: NO SCAN result", __func__); |
| 1135 | |
| 1136 | /* |
| 1137 | * cfg80211_scan_done informing NL80211 about completion |
| 1138 | * of scanning |
| 1139 | */ |
| 1140 | if (status == eCSR_SCAN_ABORT || status == eCSR_SCAN_FAILURE) { |
| 1141 | aborted = true; |
| 1142 | } |
| 1143 | |
| 1144 | cdf_spin_lock(&hddctx->hdd_scan_req_q_lock); |
| 1145 | cdf_list_size(&(hddctx->hdd_scan_req_q), &size); |
| 1146 | if (!size) { |
| 1147 | /* Scan is no longer pending */ |
| 1148 | pScanInfo->mScanPending = false; |
| 1149 | complete(&pScanInfo->abortscan_event_var); |
| 1150 | } |
| 1151 | cdf_spin_unlock(&hddctx->hdd_scan_req_q_lock); |
| 1152 | /* |
| 1153 | * Scan can be triggred from NL or vendor scan |
| 1154 | * - If scan is triggered from NL then cfg80211 scan done should be |
| 1155 | * called to updated scan completion to NL. |
| 1156 | * - If scan is triggred through vendor command then |
| 1157 | * scan done event will be posted |
| 1158 | */ |
| 1159 | if (NL_SCAN == source) |
| 1160 | cfg80211_scan_done(req, aborted); |
| 1161 | else |
| 1162 | hdd_vendor_scan_callback(pAdapter, req, aborted); |
| 1163 | |
| 1164 | allow_suspend: |
| 1165 | if (!size) { |
| 1166 | /* release the wake lock at the end of the scan */ |
| 1167 | hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_SCAN); |
| 1168 | |
| 1169 | /* Acquire wakelock to handle the case where APP's tries |
| 1170 | * to suspend immediatly after the driver gets connect |
| 1171 | * request(i.e after scan) from supplicant, this result in |
| 1172 | * app's is suspending and not ableto process the connect |
| 1173 | * request to AP |
| 1174 | */ |
| 1175 | hdd_prevent_suspend_timeout(1000, |
| 1176 | WIFI_POWER_EVENT_WAKELOCK_SCAN); |
| 1177 | } |
| 1178 | |
| 1179 | #ifdef FEATURE_WLAN_TDLS |
| 1180 | wlan_hdd_tdls_scan_done_callback(pAdapter); |
| 1181 | #endif |
| 1182 | |
| 1183 | EXIT(); |
| 1184 | return 0; |
| 1185 | } |
| 1186 | |
| 1187 | |
| 1188 | /** |
| 1189 | * wlan_hdd_cfg80211_scan_block_cb() - scan block work handler |
| 1190 | * @work: Pointer to work |
| 1191 | * |
| 1192 | * Return: none |
| 1193 | */ |
| 1194 | static void wlan_hdd_cfg80211_scan_block_cb(struct work_struct *work) |
| 1195 | { |
| 1196 | hdd_adapter_t *adapter = container_of(work, |
| 1197 | hdd_adapter_t, scan_block_work); |
Mukul Sharma | 06adf26 | 2015-10-30 21:26:40 +0530 | [diff] [blame] | 1198 | struct cfg80211_scan_request *request; |
| 1199 | if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) { |
| 1200 | hddLog(LOGE, |
| 1201 | "%s: HDD adapter context is invalid", __func__); |
| 1202 | return; |
| 1203 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1204 | |
Mukul Sharma | 06adf26 | 2015-10-30 21:26:40 +0530 | [diff] [blame] | 1205 | request = adapter->request; |
| 1206 | if (request) { |
| 1207 | request->n_ssids = 0; |
| 1208 | request->n_channels = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1209 | |
Mukul Sharma | 06adf26 | 2015-10-30 21:26:40 +0530 | [diff] [blame] | 1210 | hddLog(LOGE, |
| 1211 | FL("##In DFS Master mode. Scan aborted. Null result sent")); |
| 1212 | cfg80211_scan_done(request, true); |
| 1213 | adapter->request = NULL; |
| 1214 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | /** |
| 1218 | * __wlan_hdd_cfg80211_scan() - API to process cfg80211 scan request |
| 1219 | * @wiphy: Pointer to wiphy |
| 1220 | * @dev: Pointer to net device |
| 1221 | * @request: Pointer to scan request |
| 1222 | * @source: scan request source(NL/Vendor scan) |
| 1223 | * |
| 1224 | * This API responds to scan trigger and update cfg80211 scan database |
| 1225 | * later, scan dump command can be used to recieve scan results |
| 1226 | * |
| 1227 | * Return: 0 for success, non zero for failure |
| 1228 | */ |
| 1229 | static int __wlan_hdd_cfg80211_scan(struct wiphy *wiphy, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1230 | struct cfg80211_scan_request *request, |
| 1231 | uint8_t source) |
| 1232 | { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1233 | struct net_device *dev = request->wdev->netdev; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1234 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 1235 | hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 1236 | hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter); |
| 1237 | struct hdd_config *cfg_param = NULL; |
| 1238 | tCsrScanRequest scan_req; |
| 1239 | uint8_t *channelList = NULL, i; |
| 1240 | int status; |
| 1241 | hdd_scaninfo_t *pScanInfo = NULL; |
| 1242 | uint8_t *pP2pIe = NULL; |
| 1243 | hdd_adapter_t *con_sap_adapter; |
| 1244 | uint16_t con_dfs_ch; |
| 1245 | |
| 1246 | ENTER(); |
| 1247 | |
Peng Xu | f5d60c8 | 2015-10-02 17:17:03 -0700 | [diff] [blame] | 1248 | if (CDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1249 | hddLog(LOGE, FL("Command not allowed in FTM mode")); |
| 1250 | return -EINVAL; |
| 1251 | } |
| 1252 | |
| 1253 | MTRACE(cdf_trace(CDF_MODULE_ID_HDD, |
| 1254 | TRACE_CODE_HDD_CFG80211_SCAN, |
| 1255 | pAdapter->sessionId, request->n_channels)); |
| 1256 | |
| 1257 | hddLog(LOG1, FL("Device_mode %s(%d)"), |
| 1258 | hdd_device_mode_to_string(pAdapter->device_mode), |
| 1259 | pAdapter->device_mode); |
| 1260 | |
| 1261 | status = wlan_hdd_validate_context(pHddCtx); |
| 1262 | |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 1263 | if (0 != status) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1264 | return status; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1265 | |
| 1266 | cfg_param = pHddCtx->config; |
| 1267 | pScanInfo = &pAdapter->scan_info; |
| 1268 | |
| 1269 | /* Block All Scan during DFS operation and send null scan result */ |
| 1270 | con_sap_adapter = hdd_get_con_sap_adapter(pAdapter, true); |
| 1271 | if (con_sap_adapter) { |
| 1272 | con_dfs_ch = con_sap_adapter->sessionCtx.ap.sapConfig.channel; |
| 1273 | if (con_dfs_ch == AUTO_CHANNEL_SELECT) |
| 1274 | con_dfs_ch = |
| 1275 | con_sap_adapter->sessionCtx.ap.operatingChannel; |
| 1276 | |
| 1277 | if (CDS_IS_DFS_CH(con_dfs_ch)) { |
| 1278 | /* Provide empty scan result during DFS operation since |
| 1279 | * scanning not supported during DFS. Reason is |
| 1280 | * following case: |
| 1281 | * DFS is supported only in SCC for MBSSID Mode. |
| 1282 | * We shall not return EBUSY or ENOTSUPP as when Primary |
| 1283 | * AP is operating in DFS channel and secondary AP is |
| 1284 | * started. Though we force SCC in driver, the hostapd |
| 1285 | * issues obss scan before starting secAP. This results |
| 1286 | * in MCC in DFS mode. Thus we return null scan result. |
| 1287 | * If we return scan failure hostapd fails secondary AP |
| 1288 | * startup. |
| 1289 | */ |
| 1290 | pAdapter->request = request; |
| 1291 | |
| 1292 | #ifdef CONFIG_CNSS |
| 1293 | cnss_init_work(&pAdapter->scan_block_work, |
| 1294 | wlan_hdd_cfg80211_scan_block_cb); |
| 1295 | #else |
| 1296 | INIT_WORK(&pAdapter->scan_block_work, |
| 1297 | wlan_hdd_cfg80211_scan_block_cb); |
| 1298 | #endif |
| 1299 | schedule_work(&pAdapter->scan_block_work); |
| 1300 | return 0; |
| 1301 | } |
| 1302 | } |
| 1303 | if (!wma_is_hw_dbs_capable()) { |
| 1304 | if (true == pScanInfo->mScanPending) { |
| 1305 | if (MAX_PENDING_LOG > |
| 1306 | pScanInfo->mScanPendingCounter++) { |
| 1307 | hddLog(LOGE, FL("mScanPending is true")); |
| 1308 | } |
| 1309 | return -EBUSY; |
| 1310 | } |
| 1311 | |
| 1312 | /* Don't Allow Scan and return busy if Remain On |
| 1313 | * Channel and action frame is pending |
| 1314 | * Otherwise Cancel Remain On Channel and allow Scan |
| 1315 | * If no action frame pending |
| 1316 | */ |
| 1317 | if (0 != wlan_hdd_check_remain_on_channel(pAdapter)) { |
| 1318 | hddLog(LOGE, FL("Remain On Channel Pending")); |
| 1319 | return -EBUSY; |
| 1320 | } |
| 1321 | } |
| 1322 | #ifdef FEATURE_WLAN_TDLS |
| 1323 | /* if tdls disagree scan right now, return immediately. |
| 1324 | * tdls will schedule the scan when scan is allowed. |
| 1325 | * (return SUCCESS) |
| 1326 | * or will reject the scan if any TDLS is in progress. |
| 1327 | * (return -EBUSY) |
| 1328 | */ |
| 1329 | status = wlan_hdd_tdls_scan_callback(pAdapter, wiphy, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1330 | request); |
| 1331 | if (status <= 0) { |
| 1332 | if (!status) |
| 1333 | hddLog(LOGE, |
| 1334 | FL("TDLS in progress.scan rejected %d"), |
| 1335 | status); |
| 1336 | else |
| 1337 | hddLog(LOGE, FL("TDLS teardown is ongoing %d"), |
| 1338 | status); |
| 1339 | return status; |
| 1340 | } |
| 1341 | #endif |
| 1342 | |
| 1343 | /* Check if scan is allowed at this point of time */ |
Tushnim Bhattacharyya | ca50b32 | 2015-12-28 17:14:36 -0800 | [diff] [blame] | 1344 | if (cds_is_connection_in_progress()) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1345 | hddLog(LOGE, FL("Scan not allowed")); |
| 1346 | return -EBUSY; |
| 1347 | } |
| 1348 | |
| 1349 | cdf_mem_zero(&scan_req, sizeof(scan_req)); |
| 1350 | |
| 1351 | hddLog(LOG1, "scan request for ssid = %d", request->n_ssids); |
| 1352 | scan_req.timestamp = cdf_mc_timer_get_system_ticks(); |
| 1353 | |
| 1354 | /* Even though supplicant doesn't provide any SSIDs, n_ssids is |
| 1355 | * set to 1. Because of this, driver is assuming that this is not |
| 1356 | * wildcard scan and so is not aging out the scan results. |
| 1357 | */ |
| 1358 | if ((request->ssids) && (request->n_ssids == 1) && |
| 1359 | ('\0' == request->ssids->ssid[0])) { |
| 1360 | request->n_ssids = 0; |
| 1361 | } |
| 1362 | |
| 1363 | if ((request->ssids) && (0 < request->n_ssids)) { |
| 1364 | tCsrSSIDInfo *SsidInfo; |
| 1365 | int j; |
| 1366 | scan_req.SSIDs.numOfSSIDs = request->n_ssids; |
| 1367 | /* Allocate num_ssid tCsrSSIDInfo structure */ |
| 1368 | SsidInfo = scan_req.SSIDs.SSIDList = |
| 1369 | cdf_mem_malloc(request->n_ssids * sizeof(tCsrSSIDInfo)); |
| 1370 | |
| 1371 | if (NULL == scan_req.SSIDs.SSIDList) { |
| 1372 | hddLog(LOGE, FL("memory alloc failed SSIDInfo buffer")); |
| 1373 | return -ENOMEM; |
| 1374 | } |
| 1375 | |
| 1376 | /* copy all the ssid's and their length */ |
| 1377 | for (j = 0; j < request->n_ssids; j++, SsidInfo++) { |
| 1378 | /* get the ssid length */ |
| 1379 | SsidInfo->SSID.length = request->ssids[j].ssid_len; |
| 1380 | cdf_mem_copy(SsidInfo->SSID.ssId, |
| 1381 | &request->ssids[j].ssid[0], |
| 1382 | SsidInfo->SSID.length); |
| 1383 | SsidInfo->SSID.ssId[SsidInfo->SSID.length] = '\0'; |
| 1384 | hddLog(LOG1, FL("SSID number %d: %s"), j, |
| 1385 | SsidInfo->SSID.ssId); |
| 1386 | } |
| 1387 | /* set the scan type to active */ |
| 1388 | scan_req.scanType = eSIR_ACTIVE_SCAN; |
| 1389 | } else if (WLAN_HDD_P2P_GO == pAdapter->device_mode) { |
| 1390 | /* set the scan type to active */ |
| 1391 | scan_req.scanType = eSIR_ACTIVE_SCAN; |
| 1392 | } else { |
| 1393 | /* |
| 1394 | * Set the scan type to passive if there is no ssid list |
| 1395 | * provided else set default type configured in the driver. |
| 1396 | */ |
| 1397 | if (!request->ssids) |
| 1398 | scan_req.scanType = eSIR_PASSIVE_SCAN; |
| 1399 | else |
| 1400 | scan_req.scanType = pHddCtx->ioctl_scan_mode; |
| 1401 | } |
| 1402 | scan_req.minChnTime = cfg_param->nActiveMinChnTime; |
| 1403 | scan_req.maxChnTime = cfg_param->nActiveMaxChnTime; |
| 1404 | |
| 1405 | /* set BSSType to default type */ |
| 1406 | scan_req.BSSType = eCSR_BSS_TYPE_ANY; |
| 1407 | |
| 1408 | if (MAX_CHANNEL < request->n_channels) { |
| 1409 | hddLog(LOGW, FL("No of Scan Channels exceeded limit: %d"), |
| 1410 | request->n_channels); |
| 1411 | request->n_channels = MAX_CHANNEL; |
| 1412 | } |
| 1413 | |
| 1414 | hddLog(LOG1, FL("No of Scan Channels: %d"), request->n_channels); |
| 1415 | |
| 1416 | if (request->n_channels) { |
| 1417 | char chList[(request->n_channels * 5) + 1]; |
| 1418 | int len; |
| 1419 | channelList = cdf_mem_malloc(request->n_channels); |
| 1420 | if (NULL == channelList) { |
| 1421 | hddLog(LOGE, |
| 1422 | FL("channelList malloc failed channelList")); |
| 1423 | status = -ENOMEM; |
| 1424 | goto free_mem; |
| 1425 | } |
| 1426 | for (i = 0, len = 0; i < request->n_channels; i++) { |
| 1427 | channelList[i] = request->channels[i]->hw_value; |
| 1428 | len += snprintf(chList + len, 5, "%d ", channelList[i]); |
| 1429 | } |
| 1430 | |
| 1431 | hddLog(LOG1, FL("Channel-List: %s"), chList); |
| 1432 | |
| 1433 | } |
| 1434 | scan_req.ChannelInfo.numOfChannels = request->n_channels; |
| 1435 | scan_req.ChannelInfo.ChannelList = channelList; |
| 1436 | |
| 1437 | /* set requestType to full scan */ |
| 1438 | scan_req.requestType = eCSR_SCAN_REQUEST_FULL_SCAN; |
| 1439 | |
| 1440 | /* Flush the scan results(only p2p beacons) for STA scan and P2P |
| 1441 | * search (Flush on both full scan and social scan but not on single |
| 1442 | * channel scan).P2P search happens on 3 social channels (1, 6, 11) |
| 1443 | */ |
| 1444 | |
| 1445 | /* Supplicant does single channel scan after 8-way handshake |
| 1446 | * and in that case driver shoudnt flush scan results. If |
| 1447 | * driver flushes the scan results here and unfortunately if |
| 1448 | * the AP doesnt respond to our probe req then association |
| 1449 | * fails which is not desired |
| 1450 | */ |
| 1451 | |
| 1452 | if (request->n_channels != WLAN_HDD_P2P_SINGLE_CHANNEL_SCAN) { |
| 1453 | hddLog(CDF_TRACE_LEVEL_DEBUG, "Flushing P2P Results"); |
| 1454 | sme_scan_flush_p2p_result(WLAN_HDD_GET_HAL_CTX(pAdapter), |
| 1455 | pAdapter->sessionId); |
| 1456 | } |
| 1457 | |
| 1458 | if (request->ie_len) { |
| 1459 | /* save this for future association (join requires this) */ |
| 1460 | memset(&pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE)); |
| 1461 | memcpy(pScanInfo->scanAddIE.addIEdata, request->ie, |
| 1462 | request->ie_len); |
| 1463 | pScanInfo->scanAddIE.length = request->ie_len; |
| 1464 | |
| 1465 | if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) || |
| 1466 | (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode) || |
| 1467 | (WLAN_HDD_P2P_DEVICE == pAdapter->device_mode) |
| 1468 | ) { |
| 1469 | pwextBuf->roamProfile.pAddIEScan = |
| 1470 | pScanInfo->scanAddIE.addIEdata; |
| 1471 | pwextBuf->roamProfile.nAddIEScanLength = |
| 1472 | pScanInfo->scanAddIE.length; |
| 1473 | } |
| 1474 | |
| 1475 | scan_req.uIEFieldLen = pScanInfo->scanAddIE.length; |
| 1476 | scan_req.pIEField = pScanInfo->scanAddIE.addIEdata; |
| 1477 | |
| 1478 | pP2pIe = wlan_hdd_get_p2p_ie_ptr((uint8_t *) request->ie, |
| 1479 | request->ie_len); |
| 1480 | if (pP2pIe != NULL) { |
| 1481 | #ifdef WLAN_FEATURE_P2P_DEBUG |
| 1482 | if (((global_p2p_connection_status == P2P_GO_NEG_COMPLETED) |
| 1483 | || (global_p2p_connection_status == |
| 1484 | P2P_GO_NEG_PROCESS)) |
| 1485 | && (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode)) { |
| 1486 | global_p2p_connection_status = |
| 1487 | P2P_CLIENT_CONNECTING_STATE_1; |
| 1488 | hddLog(LOGE, |
| 1489 | FL("[P2P State] Changing state from Go nego completed to Connection is started")); |
| 1490 | hddLog(LOGE, |
| 1491 | FL("[P2P]P2P Scanning is started for 8way Handshake")); |
| 1492 | } else |
| 1493 | if ((global_p2p_connection_status == |
| 1494 | P2P_CLIENT_DISCONNECTED_STATE) |
| 1495 | && (WLAN_HDD_P2P_CLIENT == |
| 1496 | pAdapter->device_mode)) { |
| 1497 | global_p2p_connection_status = |
| 1498 | P2P_CLIENT_CONNECTING_STATE_2; |
| 1499 | hddLog(LOGE, |
| 1500 | FL("[P2P State] Changing state from Disconnected state to Connection is started")); |
| 1501 | hddLog(LOGE, |
| 1502 | FL("[P2P]P2P Scanning is started for 4way Handshake")); |
| 1503 | } |
| 1504 | #endif |
| 1505 | |
| 1506 | /* no_cck will be set during p2p find to disable 11b rates */ |
| 1507 | if (request->no_cck) { |
| 1508 | hddLog(CDF_TRACE_LEVEL_INFO, |
| 1509 | "%s: This is a P2P Search", __func__); |
| 1510 | scan_req.p2pSearch = 1; |
| 1511 | |
| 1512 | if (request->n_channels == |
| 1513 | WLAN_HDD_P2P_SOCIAL_CHANNELS) { |
| 1514 | /* set requestType to P2P Discovery */ |
| 1515 | scan_req.requestType = |
| 1516 | eCSR_SCAN_P2P_DISCOVERY; |
| 1517 | } |
| 1518 | |
| 1519 | /* |
| 1520 | * Skip Dfs Channel in case of P2P Search if it is set in |
| 1521 | * ini file |
| 1522 | */ |
| 1523 | if (cfg_param->skipDfsChnlInP2pSearch) { |
| 1524 | scan_req.skipDfsChnlInP2pSearch = 1; |
| 1525 | } else { |
| 1526 | scan_req.skipDfsChnlInP2pSearch = 0; |
| 1527 | } |
| 1528 | |
| 1529 | } |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | /* acquire the wakelock to avoid the apps suspend during the scan. To |
| 1534 | * address the following issues. |
| 1535 | * 1) Disconnected scenario: we are not allowing the suspend as WLAN is not in |
| 1536 | * BMPS/IMPS this result in android trying to suspend aggressively and backing off |
| 1537 | * for long time, this result in apps running at full power for long time. |
| 1538 | * 2) Connected scenario: If we allow the suspend during the scan, RIVA will |
| 1539 | * be stuck in full power because of resume BMPS |
| 1540 | */ |
| 1541 | hdd_prevent_suspend_timeout(HDD_WAKE_LOCK_SCAN_DURATION, |
| 1542 | WIFI_POWER_EVENT_WAKELOCK_SCAN); |
| 1543 | |
| 1544 | hddLog(LOG2, |
| 1545 | FL("requestType %d, scanType %d, minChnTime %d, maxChnTime %d,p2pSearch %d, skipDfsChnlIn P2pSearch %d"), |
| 1546 | scan_req.requestType, scan_req.scanType, |
| 1547 | scan_req.minChnTime, scan_req.maxChnTime, |
| 1548 | scan_req.p2pSearch, scan_req.skipDfsChnlInP2pSearch); |
Edhar, Mahesh Kumar | 6a50152 | 2015-11-20 10:14:13 +0530 | [diff] [blame] | 1549 | #if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 7, 0)) |
| 1550 | if (request->flags & NL80211_SCAN_FLAG_FLUSH) |
| 1551 | sme_scan_flush_result(WLAN_HDD_GET_HAL_CTX(pAdapter)); |
| 1552 | #endif |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1553 | status = sme_scan_request(WLAN_HDD_GET_HAL_CTX(pAdapter), |
| 1554 | pAdapter->sessionId, &scan_req, |
| 1555 | &hdd_cfg80211_scan_done_callback, dev); |
| 1556 | |
| 1557 | if (CDF_STATUS_SUCCESS != status) { |
| 1558 | hddLog(LOGE, FL("sme_scan_request returned error %d"), status); |
| 1559 | if (CDF_STATUS_E_RESOURCES == status) { |
| 1560 | hddLog(LOGE, |
| 1561 | FL("HO is in progress.So defer the scan by informing busy")); |
| 1562 | status = -EBUSY; |
| 1563 | } else { |
| 1564 | status = -EIO; |
| 1565 | } |
| 1566 | |
| 1567 | hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_SCAN); |
| 1568 | goto free_mem; |
| 1569 | } |
| 1570 | wlan_hdd_scan_request_enqueue(pAdapter, request, source, |
| 1571 | scan_req.scan_id, scan_req.timestamp); |
| 1572 | pAdapter->scan_info.mScanPending = true; |
| 1573 | |
| 1574 | free_mem: |
| 1575 | if (scan_req.SSIDs.SSIDList) |
| 1576 | cdf_mem_free(scan_req.SSIDs.SSIDList); |
| 1577 | |
| 1578 | if (channelList) |
| 1579 | cdf_mem_free(channelList); |
| 1580 | |
| 1581 | EXIT(); |
| 1582 | return status; |
| 1583 | } |
| 1584 | |
| 1585 | /** |
| 1586 | * wlan_hdd_cfg80211_scan() - API to process cfg80211 scan request |
| 1587 | * @wiphy: Pointer to wiphy |
| 1588 | * @dev: Pointer to net device |
| 1589 | * @request: Pointer to scan request |
| 1590 | * |
| 1591 | * This API responds to scan trigger and update cfg80211 scan database |
| 1592 | * later, scan dump command can be used to recieve scan results |
| 1593 | * |
| 1594 | * Return: 0 for success, non zero for failure |
| 1595 | */ |
| 1596 | int wlan_hdd_cfg80211_scan(struct wiphy *wiphy, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1597 | struct cfg80211_scan_request *request) |
| 1598 | { |
| 1599 | int ret; |
| 1600 | cds_ssr_protect(__func__); |
| 1601 | ret = __wlan_hdd_cfg80211_scan(wiphy, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1602 | request, NL_SCAN); |
| 1603 | cds_ssr_unprotect(__func__); |
| 1604 | return ret; |
| 1605 | } |
| 1606 | |
| 1607 | /** |
| 1608 | * wlan_hdd_get_rates() -API to get the rates from scan request |
| 1609 | * @wiphy: Pointer to wiphy |
| 1610 | * @band: Band |
| 1611 | * @rates: array of rates |
| 1612 | * @rate_count: number of rates |
| 1613 | * |
| 1614 | * Return: o for failure, rate bitmap for success |
| 1615 | */ |
| 1616 | static uint32_t wlan_hdd_get_rates(struct wiphy *wiphy, |
| 1617 | enum ieee80211_band band, |
| 1618 | const u8 *rates, unsigned int rate_count) |
| 1619 | { |
| 1620 | uint32_t j, count, rate_bitmap = 0; |
| 1621 | uint32_t rate; |
| 1622 | bool found; |
| 1623 | |
| 1624 | for (count = 0; count < rate_count; count++) { |
| 1625 | rate = ((rates[count]) & RATE_MASK) * 5; |
| 1626 | found = false; |
| 1627 | for (j = 0; j < wiphy->bands[band]->n_bitrates; j++) { |
| 1628 | if (wiphy->bands[band]->bitrates[j].bitrate == rate) { |
| 1629 | found = true; |
| 1630 | rate_bitmap |= (1 << j); |
| 1631 | break; |
| 1632 | } |
| 1633 | } |
| 1634 | if (!found) |
| 1635 | return 0; |
| 1636 | } |
| 1637 | return rate_bitmap; |
| 1638 | } |
| 1639 | |
| 1640 | /** |
| 1641 | * wlan_hdd_send_scan_start_event() -API to send the scan start event |
| 1642 | * @wiphy: Pointer to wiphy |
| 1643 | * @wdev: Pointer to net device |
| 1644 | * @cookie: scan identifier |
| 1645 | * |
| 1646 | * Return: return 0 on success and negative error code on failure |
| 1647 | */ |
| 1648 | static int wlan_hdd_send_scan_start_event(struct wiphy *wiphy, |
| 1649 | struct wireless_dev *wdev, uint64_t cookie) |
| 1650 | { |
| 1651 | struct sk_buff *skb; |
| 1652 | int ret; |
| 1653 | |
| 1654 | skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, sizeof(u64) + |
| 1655 | NLA_HDRLEN + NLMSG_HDRLEN); |
| 1656 | if (!skb) { |
| 1657 | hddLog(LOGE, FL(" reply skb alloc failed")); |
| 1658 | return -ENOMEM; |
| 1659 | } |
| 1660 | |
| 1661 | if (nla_put_u64(skb, QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE, cookie)) { |
| 1662 | hddLog(LOGE, FL("nla put fail")); |
| 1663 | kfree_skb(skb); |
| 1664 | return -EINVAL; |
| 1665 | } |
| 1666 | |
| 1667 | ret = cfg80211_vendor_cmd_reply(skb); |
| 1668 | |
| 1669 | /* Send a scan started event to supplicant */ |
| 1670 | skb = cfg80211_vendor_event_alloc(wiphy, wdev, |
| 1671 | sizeof(u64) + 4 + NLMSG_HDRLEN, |
| 1672 | QCA_NL80211_VENDOR_SUBCMD_SCAN_INDEX, GFP_KERNEL); |
| 1673 | if (!skb) { |
| 1674 | hddLog(LOGE, FL("skb alloc failed")); |
| 1675 | return -ENOMEM; |
| 1676 | } |
| 1677 | |
| 1678 | ret = hdd_vendor_put_ifindex(skb, wdev->netdev->ifindex); |
| 1679 | if (ret) { |
| 1680 | kfree_skb(skb); |
| 1681 | return -EINVAL; |
| 1682 | } |
| 1683 | |
| 1684 | if (nla_put_u64(skb, QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE, cookie)) { |
| 1685 | kfree_skb(skb); |
| 1686 | return -EINVAL; |
| 1687 | } |
| 1688 | cfg80211_vendor_event(skb, GFP_KERNEL); |
| 1689 | |
| 1690 | return ret; |
| 1691 | } |
| 1692 | /** |
| 1693 | * __wlan_hdd_cfg80211_vendor_scan() - API to process venor scan request |
| 1694 | * @wiphy: Pointer to wiphy |
| 1695 | * @wdev: Pointer to net device |
| 1696 | * @data : Pointer to the data |
| 1697 | * @data_len : length of the data |
| 1698 | * |
| 1699 | * API to process venor scan request. |
| 1700 | * |
| 1701 | * Return: return 0 on success and negative error code on failure |
| 1702 | */ |
| 1703 | static int __wlan_hdd_cfg80211_vendor_scan(struct wiphy *wiphy, |
| 1704 | struct wireless_dev *wdev, const void *data, |
| 1705 | int data_len) |
| 1706 | { |
| 1707 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SCAN_MAX + 1]; |
| 1708 | struct cfg80211_scan_request *request = NULL; |
| 1709 | struct nlattr *attr; |
| 1710 | enum ieee80211_band band; |
| 1711 | uint8_t n_channels = 0, n_ssid = 0, ie_len = 0; |
| 1712 | uint32_t tmp, count, j; |
| 1713 | unsigned int len; |
| 1714 | struct ieee80211_channel *chan; |
| 1715 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
| 1716 | int ret; |
| 1717 | |
| 1718 | ENTER(); |
| 1719 | |
| 1720 | ret = wlan_hdd_validate_context(hdd_ctx); |
| 1721 | if (0 != ret) |
| 1722 | return ret; |
| 1723 | |
| 1724 | if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SCAN_MAX, data, |
| 1725 | data_len, NULL)) { |
| 1726 | hdd_err("Invalid ATTR"); |
| 1727 | return -EINVAL; |
| 1728 | } |
| 1729 | |
| 1730 | if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_FREQUENCIES]) { |
| 1731 | nla_for_each_nested(attr, |
| 1732 | tb[QCA_WLAN_VENDOR_ATTR_SCAN_FREQUENCIES], tmp) |
| 1733 | n_channels++; |
| 1734 | } else { |
| 1735 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 1736 | if (wiphy->bands[band]) |
| 1737 | n_channels += wiphy->bands[band]->n_channels; |
| 1738 | } |
| 1739 | |
| 1740 | if (MAX_CHANNEL < n_channels) { |
| 1741 | hdd_err("Exceed max number of channels: %d", n_channels); |
| 1742 | return -EINVAL; |
| 1743 | } |
| 1744 | if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_SSIDS]) |
| 1745 | nla_for_each_nested(attr, |
| 1746 | tb[QCA_WLAN_VENDOR_ATTR_SCAN_SSIDS], tmp) |
| 1747 | n_ssid++; |
| 1748 | |
| 1749 | if (MAX_SCAN_SSID < n_ssid) { |
| 1750 | hdd_err("Exceed max number of SSID: %d", n_ssid); |
| 1751 | return -EINVAL; |
| 1752 | } |
| 1753 | |
| 1754 | if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_IE]) |
| 1755 | ie_len = nla_len(tb[QCA_WLAN_VENDOR_ATTR_SCAN_IE]); |
| 1756 | else |
| 1757 | ie_len = 0; |
| 1758 | |
| 1759 | len = sizeof(*request) + (sizeof(*request->ssids) * n_ssid) + |
| 1760 | (sizeof(*request->channels) * n_channels) + ie_len; |
| 1761 | |
| 1762 | request = cdf_mem_malloc(len); |
| 1763 | if (!request) |
| 1764 | goto error; |
| 1765 | if (n_ssid) |
| 1766 | request->ssids = (void *)&request->channels[n_channels]; |
| 1767 | request->n_ssids = n_ssid; |
| 1768 | if (ie_len) { |
| 1769 | if (request->ssids) |
| 1770 | request->ie = (void *)(request->ssids + n_ssid); |
| 1771 | else |
| 1772 | request->ie = (void *)(request->channels + n_channels); |
| 1773 | } |
| 1774 | |
| 1775 | count = 0; |
| 1776 | if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_FREQUENCIES]) { |
| 1777 | nla_for_each_nested(attr, |
| 1778 | tb[QCA_WLAN_VENDOR_ATTR_SCAN_FREQUENCIES], |
| 1779 | tmp) { |
| 1780 | chan = __ieee80211_get_channel(wiphy, |
| 1781 | nla_get_u32(attr)); |
| 1782 | if (!chan) |
| 1783 | goto error; |
| 1784 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 1785 | continue; |
| 1786 | request->channels[count] = chan; |
| 1787 | count++; |
| 1788 | } |
| 1789 | } else { |
| 1790 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1791 | if (!wiphy->bands[band]) |
| 1792 | continue; |
| 1793 | for (j = 0; j < wiphy->bands[band]->n_channels; |
| 1794 | j++) { |
| 1795 | chan = &wiphy->bands[band]->channels[j]; |
| 1796 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 1797 | continue; |
| 1798 | request->channels[count] = chan; |
| 1799 | count++; |
| 1800 | } |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | if (!count) |
| 1805 | goto error; |
| 1806 | |
| 1807 | request->n_channels = count; |
| 1808 | count = 0; |
| 1809 | if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_SSIDS]) { |
| 1810 | nla_for_each_nested(attr, tb[QCA_WLAN_VENDOR_ATTR_SCAN_SSIDS], |
| 1811 | tmp) { |
| 1812 | request->ssids[count].ssid_len = nla_len(attr); |
| 1813 | memcpy(request->ssids[count].ssid, nla_data(attr), |
| 1814 | nla_len(attr)); |
| 1815 | count++; |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_IE]) { |
| 1820 | request->ie_len = nla_len(tb[QCA_WLAN_VENDOR_ATTR_SCAN_IE]); |
| 1821 | memcpy((void *)request->ie, |
| 1822 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_SCAN_IE]), |
| 1823 | request->ie_len); |
| 1824 | } |
| 1825 | |
| 1826 | for (count = 0; count < IEEE80211_NUM_BANDS; count++) |
| 1827 | if (wiphy->bands[count]) |
| 1828 | request->rates[count] = |
| 1829 | (1 << wiphy->bands[count]->n_bitrates) - 1; |
| 1830 | |
| 1831 | if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_SUPP_RATES]) { |
| 1832 | nla_for_each_nested(attr, |
| 1833 | tb[QCA_WLAN_VENDOR_ATTR_SCAN_SUPP_RATES], |
| 1834 | tmp) { |
| 1835 | band = nla_type(attr); |
| 1836 | if (!wiphy->bands[band]) |
| 1837 | continue; |
| 1838 | request->rates[band] = wlan_hdd_get_rates(wiphy, |
| 1839 | band, nla_data(attr), |
| 1840 | nla_len(attr)); |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_FLAGS]) { |
| 1845 | request->flags = |
| 1846 | nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_SCAN_FLAGS]); |
| 1847 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 1848 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
| 1849 | hddLog(LOGE, FL("LOW PRIORITY SCAN not supported")); |
| 1850 | goto error; |
| 1851 | } |
| 1852 | } |
| 1853 | request->no_cck = |
| 1854 | nla_get_flag(tb[QCA_WLAN_VENDOR_ATTR_SCAN_TX_NO_CCK_RATE]); |
| 1855 | request->wdev = wdev; |
| 1856 | request->wiphy = wiphy; |
| 1857 | request->scan_start = jiffies; |
| 1858 | |
| 1859 | if (0 != __wlan_hdd_cfg80211_scan(wiphy, request, VENDOR_SCAN)) |
| 1860 | goto error; |
| 1861 | |
| 1862 | ret = wlan_hdd_send_scan_start_event(wiphy, wdev, (uintptr_t)request); |
| 1863 | |
| 1864 | return ret; |
| 1865 | error: |
| 1866 | hdd_err("Scan Request Failed"); |
| 1867 | cdf_mem_free(request); |
| 1868 | return -EINVAL; |
| 1869 | } |
| 1870 | |
| 1871 | /** |
| 1872 | * wlan_hdd_cfg80211_vendor_scan() -API to process venor scan request |
| 1873 | * @wiphy: Pointer to wiphy |
| 1874 | * @dev: Pointer to net device |
| 1875 | * @data : Pointer to the data |
| 1876 | * @data_len : length of the data |
| 1877 | * |
| 1878 | * This is called from userspace to request scan. |
| 1879 | * |
| 1880 | * Return: Return the Success or Failure code. |
| 1881 | */ |
| 1882 | int wlan_hdd_cfg80211_vendor_scan(struct wiphy *wiphy, |
| 1883 | struct wireless_dev *wdev, const void *data, |
| 1884 | int data_len) |
| 1885 | { |
| 1886 | int ret; |
| 1887 | |
| 1888 | cds_ssr_protect(__func__); |
| 1889 | ret = __wlan_hdd_cfg80211_vendor_scan(wiphy, wdev, |
| 1890 | data, data_len); |
| 1891 | cds_ssr_unprotect(__func__); |
| 1892 | |
| 1893 | return ret; |
| 1894 | } |
| 1895 | /** |
| 1896 | * wlan_hdd_scan_abort() - abort ongoing scan |
| 1897 | * @pAdapter: Pointer to interface adapter |
| 1898 | * |
| 1899 | * Return: 0 for success, non zero for failure |
| 1900 | */ |
| 1901 | #ifdef FEATURE_WLAN_SCAN_PNO |
| 1902 | int wlan_hdd_scan_abort(hdd_adapter_t *pAdapter) |
| 1903 | { |
| 1904 | hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 1905 | hdd_scaninfo_t *pScanInfo = NULL; |
| 1906 | unsigned long rc; |
| 1907 | |
| 1908 | pScanInfo = &pAdapter->scan_info; |
| 1909 | |
| 1910 | if (pScanInfo->mScanPending) { |
| 1911 | INIT_COMPLETION(pScanInfo->abortscan_event_var); |
| 1912 | hdd_abort_mac_scan(pHddCtx, pAdapter->sessionId, |
| 1913 | eCSR_SCAN_ABORT_DEFAULT); |
| 1914 | |
| 1915 | rc = wait_for_completion_timeout( |
| 1916 | &pScanInfo->abortscan_event_var, |
| 1917 | msecs_to_jiffies(5000)); |
| 1918 | if (!rc) { |
| 1919 | hddLog(LOGE, |
| 1920 | FL("Timeout occurred while waiting for abort scan")); |
| 1921 | return -ETIME; |
| 1922 | } |
| 1923 | } |
| 1924 | return 0; |
| 1925 | } |
| 1926 | |
| 1927 | /** |
| 1928 | * hdd_sched_scan_callback - scheduled scan callback |
| 1929 | * @callbackContext: Callback context |
| 1930 | * @pPrefNetworkFoundInd: Preferred network found indication |
| 1931 | * |
| 1932 | * This is a callback function that is registerd with SME that is |
| 1933 | * invoked when a preferred network is discovered by firmware. |
| 1934 | * |
| 1935 | * Return: none |
| 1936 | */ |
| 1937 | static void |
| 1938 | hdd_sched_scan_callback(void *callbackContext, |
| 1939 | tSirPrefNetworkFoundInd *pPrefNetworkFoundInd) |
| 1940 | { |
| 1941 | int ret; |
| 1942 | hdd_adapter_t *pAdapter = (hdd_adapter_t *) callbackContext; |
| 1943 | hdd_context_t *pHddCtx; |
| 1944 | |
| 1945 | ENTER(); |
| 1946 | |
| 1947 | if (NULL == pAdapter) { |
| 1948 | hddLog(LOGE, FL("HDD adapter is Null")); |
| 1949 | return; |
| 1950 | } |
| 1951 | |
| 1952 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 1953 | if (NULL == pHddCtx) { |
| 1954 | hddLog(LOGE, FL("HDD context is Null!!!")); |
| 1955 | return; |
| 1956 | } |
| 1957 | |
Prashanth Bhatta | 915b9d3 | 2016-01-08 11:58:15 -0800 | [diff] [blame] | 1958 | cdf_spin_lock(&pHddCtx->sched_scan_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1959 | if (true == pHddCtx->isWiphySuspended) { |
| 1960 | pHddCtx->isSchedScanUpdatePending = true; |
Prashanth Bhatta | 915b9d3 | 2016-01-08 11:58:15 -0800 | [diff] [blame] | 1961 | cdf_spin_unlock(&pHddCtx->sched_scan_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1962 | hddLog(LOG1, |
| 1963 | FL("Update cfg80211 scan database after it resume")); |
| 1964 | return; |
| 1965 | } |
Prashanth Bhatta | 915b9d3 | 2016-01-08 11:58:15 -0800 | [diff] [blame] | 1966 | cdf_spin_unlock(&pHddCtx->sched_scan_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1967 | |
| 1968 | ret = wlan_hdd_cfg80211_update_bss(pHddCtx->wiphy, pAdapter, 0); |
| 1969 | |
| 1970 | if (0 > ret) |
| 1971 | hddLog(LOG1, FL("NO SCAN result")); |
| 1972 | |
| 1973 | cfg80211_sched_scan_results(pHddCtx->wiphy); |
| 1974 | hddLog(LOG1, |
| 1975 | FL("cfg80211 scan result database updated")); |
| 1976 | } |
| 1977 | |
| 1978 | /** |
| 1979 | * wlan_hdd_is_pno_allowed() - Check if PNO is allowed |
| 1980 | * @adapter: HDD Device Adapter |
| 1981 | * |
| 1982 | * The PNO Start request is coming from upper layers. |
| 1983 | * It is to be allowed only for Infra STA device type |
| 1984 | * and the link should be in a disconnected state. |
| 1985 | * |
| 1986 | * Return: Success if PNO is allowed, Failure otherwise. |
| 1987 | */ |
| 1988 | static CDF_STATUS wlan_hdd_is_pno_allowed(hdd_adapter_t *adapter) |
| 1989 | { |
| 1990 | hddLog(LOG1, |
| 1991 | FL("dev_mode=%d, conn_state=%d, session ID=%d"), |
| 1992 | adapter->device_mode, |
| 1993 | adapter->sessionCtx.station.conn_info.connState, |
| 1994 | adapter->sessionId); |
| 1995 | if ((adapter->device_mode == WLAN_HDD_INFRA_STATION) && |
| 1996 | (eConnectionState_NotConnected == |
| 1997 | adapter->sessionCtx.station.conn_info.connState)) |
| 1998 | return CDF_STATUS_SUCCESS; |
| 1999 | else |
| 2000 | return CDF_STATUS_E_FAILURE; |
| 2001 | |
| 2002 | } |
| 2003 | |
| 2004 | /** |
| 2005 | * __wlan_hdd_cfg80211_sched_scan_start() - cfg80211 scheduled scan(pno) start |
| 2006 | * @wiphy: Pointer to wiphy |
| 2007 | * @dev: Pointer network device |
| 2008 | * @request: Pointer to cfg80211 scheduled scan start request |
| 2009 | * |
| 2010 | * Return: 0 for success, non zero for failure |
| 2011 | */ |
| 2012 | static int __wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy, |
| 2013 | struct net_device *dev, |
| 2014 | struct |
| 2015 | cfg80211_sched_scan_request |
| 2016 | *request) |
| 2017 | { |
| 2018 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 2019 | tpSirPNOScanReq pPnoRequest = NULL; |
| 2020 | hdd_context_t *pHddCtx; |
| 2021 | tHalHandle hHal; |
Srinivas Girigowda | bdc9816 | 2015-09-17 11:06:07 -0700 | [diff] [blame] | 2022 | uint32_t i, indx, num_ch, j; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2023 | u8 valid_ch[WNI_CFG_VALID_CHANNEL_LIST_LEN] = { 0 }; |
| 2024 | u8 channels_allowed[WNI_CFG_VALID_CHANNEL_LIST_LEN] = { 0 }; |
| 2025 | uint32_t num_channels_allowed = WNI_CFG_VALID_CHANNEL_LIST_LEN; |
| 2026 | CDF_STATUS status = CDF_STATUS_E_FAILURE; |
| 2027 | int ret = 0; |
| 2028 | hdd_scaninfo_t *pScanInfo = &pAdapter->scan_info; |
| 2029 | struct hdd_config *config = NULL; |
| 2030 | uint32_t num_ignore_dfs_ch = 0; |
| 2031 | |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 2032 | ENTER(); |
| 2033 | |
Peng Xu | f5d60c8 | 2015-10-02 17:17:03 -0700 | [diff] [blame] | 2034 | if (CDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2035 | hddLog(LOGE, FL("Command not allowed in FTM mode")); |
| 2036 | return -EINVAL; |
| 2037 | } |
| 2038 | |
| 2039 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 2040 | ret = wlan_hdd_validate_context(pHddCtx); |
| 2041 | |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 2042 | if (0 != ret) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2043 | return ret; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2044 | |
| 2045 | config = pHddCtx->config; |
| 2046 | hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); |
| 2047 | if (NULL == hHal) { |
| 2048 | hddLog(LOGE, FL("HAL context is Null!!!")); |
| 2049 | return -EINVAL; |
| 2050 | } |
| 2051 | |
| 2052 | if ((WLAN_HDD_INFRA_STATION == pAdapter->device_mode) && |
| 2053 | (eConnectionState_Connecting == |
| 2054 | (WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))->conn_info.connState)) { |
| 2055 | hddLog(LOGE, |
| 2056 | FL("%p(%d) Connection in progress: sched_scan_start denied (EBUSY)"), |
| 2057 | WLAN_HDD_GET_STATION_CTX_PTR(pAdapter), |
| 2058 | pAdapter->sessionId); |
| 2059 | return -EBUSY; |
| 2060 | } |
| 2061 | |
Sreelakshmi Konamki | 6744cff | 2015-09-07 12:10:39 +0530 | [diff] [blame] | 2062 | MTRACE(cdf_trace(CDF_MODULE_ID_HDD, |
| 2063 | TRACE_CODE_HDD_CFG80211_SCHED_SCAN_START, |
| 2064 | pAdapter->sessionId, pAdapter->device_mode)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2065 | /* |
| 2066 | * The current umac is unable to handle the SCAN_PREEMPT and SCAN_DEQUEUED |
| 2067 | * so its necessary to terminate the existing scan which is already issued |
| 2068 | * otherwise the host won't enter into the suspend state due to the reason |
| 2069 | * that the wlan wakelock which was held in the wlan_hdd_cfg80211_scan |
| 2070 | * function. |
| 2071 | */ |
| 2072 | sme_scan_flush_result(hHal); |
| 2073 | if (true == pScanInfo->mScanPending) { |
| 2074 | ret = wlan_hdd_scan_abort(pAdapter); |
| 2075 | if (ret < 0) { |
| 2076 | hddLog(LOGE, |
| 2077 | FL("aborting the existing scan is unsuccessful")); |
| 2078 | return -EBUSY; |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | if (CDF_STATUS_E_FAILURE == wlan_hdd_is_pno_allowed(pAdapter)) { |
| 2083 | hddLog(LOGE, FL("pno is not allowed")); |
| 2084 | return -ENOTSUPP; |
| 2085 | } |
| 2086 | |
| 2087 | pPnoRequest = (tpSirPNOScanReq) cdf_mem_malloc(sizeof(tSirPNOScanReq)); |
| 2088 | if (NULL == pPnoRequest) { |
| 2089 | hddLog(LOGE, FL("cdf_mem_malloc failed")); |
| 2090 | return -ENOMEM; |
| 2091 | } |
| 2092 | |
| 2093 | memset(pPnoRequest, 0, sizeof(tSirPNOScanReq)); |
| 2094 | pPnoRequest->enable = 1; /*Enable PNO */ |
| 2095 | pPnoRequest->ucNetworksCount = request->n_match_sets; |
| 2096 | |
| 2097 | if ((!pPnoRequest->ucNetworksCount) || |
| 2098 | (pPnoRequest->ucNetworksCount > SIR_PNO_MAX_SUPP_NETWORKS)) { |
| 2099 | hddLog(LOGE, FL("Network input is not correct %d"), |
| 2100 | pPnoRequest->ucNetworksCount); |
| 2101 | ret = -EINVAL; |
| 2102 | goto error; |
| 2103 | } |
| 2104 | |
| 2105 | if (SIR_PNO_MAX_NETW_CHANNELS_EX < request->n_channels) { |
| 2106 | hddLog(LOGE, FL("Incorrect number of channels %d"), |
| 2107 | request->n_channels); |
| 2108 | ret = -EINVAL; |
| 2109 | goto error; |
| 2110 | } |
| 2111 | |
| 2112 | /* Framework provides one set of channels(all) |
| 2113 | * common for all saved profile */ |
| 2114 | if (0 != sme_cfg_get_str(hHal, WNI_CFG_VALID_CHANNEL_LIST, |
| 2115 | channels_allowed, &num_channels_allowed)) { |
| 2116 | hddLog(LOGE, |
| 2117 | FL("failed to get valid channel list")); |
| 2118 | ret = -EINVAL; |
| 2119 | goto error; |
| 2120 | } |
| 2121 | /* Checking each channel against allowed channel list */ |
| 2122 | num_ch = 0; |
| 2123 | if (request->n_channels) { |
| 2124 | char chList[(request->n_channels * 5) + 1]; |
| 2125 | int len; |
| 2126 | for (i = 0, len = 0; i < request->n_channels; i++) { |
| 2127 | for (indx = 0; indx < num_channels_allowed; indx++) { |
| 2128 | if (request->channels[i]->hw_value == |
| 2129 | channels_allowed[indx]) { |
| 2130 | |
| 2131 | if ((!config->enable_dfs_pno_chnl_scan) |
| 2132 | && (CHANNEL_STATE_DFS == |
| 2133 | cds_get_channel_state( |
| 2134 | channels_allowed[indx]))) { |
| 2135 | CDF_TRACE(CDF_MODULE_ID_HDD, |
| 2136 | CDF_TRACE_LEVEL_INFO, |
| 2137 | "%s : Dropping DFS channel : %d", |
| 2138 | __func__, |
| 2139 | channels_allowed[indx]); |
| 2140 | num_ignore_dfs_ch++; |
| 2141 | break; |
| 2142 | } |
| 2143 | |
| 2144 | valid_ch[num_ch++] = |
| 2145 | request->channels[i]->hw_value; |
| 2146 | len += |
| 2147 | snprintf(chList + len, 5, "%d ", |
| 2148 | request->channels[i]-> |
| 2149 | hw_value); |
| 2150 | break; |
| 2151 | } |
| 2152 | } |
| 2153 | } |
| 2154 | hddLog(LOG1, FL("Channel-List: %s "), chList); |
| 2155 | |
| 2156 | /* If all channels are DFS and dropped, |
| 2157 | * then ignore the PNO request |
| 2158 | */ |
| 2159 | if (num_ignore_dfs_ch == request->n_channels) { |
| 2160 | CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_INFO, |
| 2161 | "%s : All requested channels are DFS channels", |
| 2162 | __func__); |
| 2163 | ret = -EINVAL; |
| 2164 | goto error; |
| 2165 | } |
| 2166 | |
| 2167 | } |
| 2168 | /* Filling per profile params */ |
| 2169 | for (i = 0; i < pPnoRequest->ucNetworksCount; i++) { |
| 2170 | pPnoRequest->aNetworks[i].ssId.length = |
| 2171 | request->match_sets[i].ssid.ssid_len; |
| 2172 | |
| 2173 | if ((0 == pPnoRequest->aNetworks[i].ssId.length) || |
| 2174 | (pPnoRequest->aNetworks[i].ssId.length > 32)) { |
| 2175 | hddLog(LOGE, |
| 2176 | FL(" SSID Len %d is not correct for network %d"), |
| 2177 | pPnoRequest->aNetworks[i].ssId.length, i); |
| 2178 | ret = -EINVAL; |
| 2179 | goto error; |
| 2180 | } |
| 2181 | |
| 2182 | memcpy(pPnoRequest->aNetworks[i].ssId.ssId, |
| 2183 | request->match_sets[i].ssid.ssid, |
| 2184 | request->match_sets[i].ssid.ssid_len); |
| 2185 | pPnoRequest->aNetworks[i].authentication = 0; /*eAUTH_TYPE_ANY */ |
| 2186 | pPnoRequest->aNetworks[i].encryption = 0; /*eED_ANY */ |
| 2187 | pPnoRequest->aNetworks[i].bcastNetwType = 0; /*eBCAST_UNKNOWN */ |
| 2188 | |
| 2189 | /*Copying list of valid channel into request */ |
| 2190 | memcpy(pPnoRequest->aNetworks[i].aChannels, valid_ch, num_ch); |
| 2191 | pPnoRequest->aNetworks[i].ucChannelCount = num_ch; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2192 | pPnoRequest->aNetworks[i].rssiThreshold = |
| 2193 | request->match_sets[i].rssi_thold; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | for (i = 0; i < request->n_ssids; i++) { |
| 2197 | j = 0; |
| 2198 | while (j < pPnoRequest->ucNetworksCount) { |
| 2199 | if ((pPnoRequest->aNetworks[j].ssId.length == |
| 2200 | request->ssids[i].ssid_len) && |
| 2201 | (0 == memcmp(pPnoRequest->aNetworks[j].ssId.ssId, |
| 2202 | request->ssids[i].ssid, |
| 2203 | pPnoRequest->aNetworks[j].ssId. |
| 2204 | length))) { |
| 2205 | pPnoRequest->aNetworks[j].bcastNetwType = |
| 2206 | eBCAST_HIDDEN; |
| 2207 | break; |
| 2208 | } |
| 2209 | j++; |
| 2210 | } |
| 2211 | } |
| 2212 | hddLog(LOG1, FL("Number of hidden networks being Configured = %d"), |
| 2213 | request->n_ssids); |
| 2214 | |
| 2215 | hddLog(LOG1, FL("request->ie_len = %zu"), request->ie_len); |
| 2216 | if ((0 < request->ie_len) && (NULL != request->ie)) { |
| 2217 | pPnoRequest->us24GProbeTemplateLen = request->ie_len; |
| 2218 | memcpy(&pPnoRequest->p24GProbeTemplate, request->ie, |
| 2219 | pPnoRequest->us24GProbeTemplateLen); |
| 2220 | |
| 2221 | pPnoRequest->us5GProbeTemplateLen = request->ie_len; |
| 2222 | memcpy(&pPnoRequest->p5GProbeTemplate, request->ie, |
| 2223 | pPnoRequest->us5GProbeTemplateLen); |
| 2224 | } |
| 2225 | |
Srinivas Girigowda | bdc9816 | 2015-09-17 11:06:07 -0700 | [diff] [blame] | 2226 | /* |
| 2227 | * Driver gets only one time interval which is hard coded in |
| 2228 | * supplicant for 10000ms. Taking power consumption into account |
| 2229 | * firmware after gPNOScanTimerRepeatValue times fast_scan_period |
| 2230 | * switches slow_scan_period. This is less frequent scans and firmware |
| 2231 | * shall be in slow_scan_period mode until next PNO Start. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2232 | */ |
Srinivas Girigowda | bdc9816 | 2015-09-17 11:06:07 -0700 | [diff] [blame] | 2233 | pPnoRequest->fast_scan_period = request->interval; |
| 2234 | pPnoRequest->fast_scan_max_cycles = |
| 2235 | config->configPNOScanTimerRepeatValue; |
| 2236 | pPnoRequest->slow_scan_period = |
| 2237 | config->pno_slow_scan_multiplier * |
| 2238 | pPnoRequest->fast_scan_period; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2239 | |
Srinivas Girigowda | bdc9816 | 2015-09-17 11:06:07 -0700 | [diff] [blame] | 2240 | hdd_info("Base scan interval: %d sec PNOScanTimerRepeatValue: %d", |
| 2241 | (request->interval / 1000), |
| 2242 | config->configPNOScanTimerRepeatValue); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2243 | |
| 2244 | pPnoRequest->modePNO = SIR_PNO_MODE_IMMEDIATE; |
| 2245 | |
Srinivas Girigowda | bdc9816 | 2015-09-17 11:06:07 -0700 | [diff] [blame] | 2246 | hdd_info("SessionId %d, enable %d, modePNO %d", |
| 2247 | pAdapter->sessionId, pPnoRequest->enable, pPnoRequest->modePNO); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2248 | |
| 2249 | status = sme_set_preferred_network_list(WLAN_HDD_GET_HAL_CTX(pAdapter), |
| 2250 | pPnoRequest, |
| 2251 | pAdapter->sessionId, |
| 2252 | hdd_sched_scan_callback, |
| 2253 | pAdapter); |
| 2254 | if (CDF_STATUS_SUCCESS != status) { |
| 2255 | hddLog(LOGE, FL("Failed to enable PNO")); |
| 2256 | ret = -EINVAL; |
| 2257 | goto error; |
| 2258 | } |
| 2259 | |
| 2260 | hddLog(LOG1, FL("PNO scanRequest offloaded")); |
| 2261 | |
| 2262 | error: |
| 2263 | cdf_mem_free(pPnoRequest); |
Hanumantha Reddy Pothula | 2db50ed | 2015-11-23 10:48:33 +0530 | [diff] [blame] | 2264 | EXIT(); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2265 | return ret; |
| 2266 | } |
| 2267 | |
| 2268 | /** |
| 2269 | * wlan_hdd_cfg80211_sched_scan_start() - cfg80211 scheduled scan(pno) start |
| 2270 | * @wiphy: Pointer to wiphy |
| 2271 | * @dev: Pointer network device |
| 2272 | * @request: Pointer to cfg80211 scheduled scan start request |
| 2273 | * |
| 2274 | * Return: 0 for success, non zero for failure |
| 2275 | */ |
| 2276 | int wlan_hdd_cfg80211_sched_scan_start(struct wiphy *wiphy, |
| 2277 | struct net_device *dev, |
| 2278 | struct cfg80211_sched_scan_request |
| 2279 | *request) |
| 2280 | { |
| 2281 | int ret; |
| 2282 | |
| 2283 | cds_ssr_protect(__func__); |
| 2284 | ret = __wlan_hdd_cfg80211_sched_scan_start(wiphy, dev, request); |
| 2285 | cds_ssr_unprotect(__func__); |
| 2286 | |
| 2287 | return ret; |
| 2288 | } |
| 2289 | |
| 2290 | /** |
| 2291 | * __wlan_hdd_cfg80211_sched_scan_stop() - stop cfg80211 scheduled scan(pno) |
| 2292 | * @wiphy: Pointer to wiphy |
| 2293 | * @dev: Pointer network device |
| 2294 | * |
| 2295 | * Return: 0 for success, non zero for failure |
| 2296 | */ |
| 2297 | static int __wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy, |
| 2298 | struct net_device *dev) |
| 2299 | { |
| 2300 | CDF_STATUS status = CDF_STATUS_E_FAILURE; |
| 2301 | hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 2302 | hdd_context_t *pHddCtx; |
| 2303 | tHalHandle hHal; |
| 2304 | tpSirPNOScanReq pPnoRequest = NULL; |
| 2305 | int ret = 0; |
| 2306 | |
| 2307 | ENTER(); |
| 2308 | |
Peng Xu | f5d60c8 | 2015-10-02 17:17:03 -0700 | [diff] [blame] | 2309 | if (CDF_GLOBAL_FTM_MODE == hdd_get_conparam()) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2310 | hddLog(LOGE, FL("Command not allowed in FTM mode")); |
| 2311 | return -EINVAL; |
| 2312 | } |
| 2313 | |
| 2314 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 2315 | |
| 2316 | if (NULL == pHddCtx) { |
| 2317 | hddLog(LOGE, FL("HDD context is Null")); |
| 2318 | return -ENODEV; |
| 2319 | } |
| 2320 | |
Prashanth Bhatta | 9e14305 | 2015-12-04 11:56:47 -0800 | [diff] [blame] | 2321 | /* The return 0 is intentional when Recovery and Load/Unload in |
| 2322 | * progress. We did observe a crash due to a return of |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2323 | * failure in sched_scan_stop , especially for a case where the unload |
| 2324 | * of the happens at the same time. The function __cfg80211_stop_sched_scan |
| 2325 | * was clearing rdev->sched_scan_req only when the sched_scan_stop returns |
| 2326 | * success. If it returns a failure , then its next invocation due to the |
| 2327 | * clean up of the second interface will have the dev pointer corresponding |
| 2328 | * to the first one leading to a crash. |
| 2329 | */ |
Prashanth Bhatta | 9e14305 | 2015-12-04 11:56:47 -0800 | [diff] [blame] | 2330 | if (cds_is_driver_recovering()) { |
| 2331 | hdd_err("Recovery in Progress. State: 0x%x Ignore!!!", |
| 2332 | cds_get_driver_state()); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2333 | return ret; |
| 2334 | } |
| 2335 | |
Prashanth Bhatta | 9e14305 | 2015-12-04 11:56:47 -0800 | [diff] [blame] | 2336 | if (cds_is_load_unload_in_progress()) { |
| 2337 | hdd_err("Unload/Load in Progress, state: 0x%x. Ignore!!!", |
| 2338 | cds_get_driver_state()); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2339 | return ret; |
| 2340 | } |
| 2341 | |
| 2342 | hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); |
| 2343 | if (NULL == hHal) { |
| 2344 | hddLog(LOGE, FL(" HAL context is Null!!!")); |
| 2345 | return -EINVAL; |
| 2346 | } |
| 2347 | |
| 2348 | pPnoRequest = (tpSirPNOScanReq) cdf_mem_malloc(sizeof(tSirPNOScanReq)); |
| 2349 | if (NULL == pPnoRequest) { |
| 2350 | hddLog(LOGE, FL("cdf_mem_malloc failed")); |
| 2351 | return -ENOMEM; |
| 2352 | } |
| 2353 | |
| 2354 | memset(pPnoRequest, 0, sizeof(tSirPNOScanReq)); |
| 2355 | pPnoRequest->enable = 0; /* Disable PNO */ |
| 2356 | pPnoRequest->ucNetworksCount = 0; |
| 2357 | |
Sreelakshmi Konamki | 6744cff | 2015-09-07 12:10:39 +0530 | [diff] [blame] | 2358 | MTRACE(cdf_trace(CDF_MODULE_ID_HDD, |
| 2359 | TRACE_CODE_HDD_CFG80211_SCHED_SCAN_STOP, |
| 2360 | pAdapter->sessionId, pAdapter->device_mode)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2361 | status = sme_set_preferred_network_list(hHal, pPnoRequest, |
| 2362 | pAdapter->sessionId, |
| 2363 | NULL, pAdapter); |
| 2364 | if (CDF_STATUS_SUCCESS != status) { |
| 2365 | hddLog(LOGE, FL("Failed to disabled PNO")); |
| 2366 | ret = -EINVAL; |
| 2367 | } |
| 2368 | |
| 2369 | hddLog(LOG1, FL("PNO scan disabled")); |
| 2370 | |
| 2371 | cdf_mem_free(pPnoRequest); |
| 2372 | |
| 2373 | EXIT(); |
| 2374 | return ret; |
| 2375 | } |
| 2376 | |
| 2377 | /** |
| 2378 | * wlan_hdd_cfg80211_sched_scan_stop() - stop cfg80211 scheduled scan(pno) |
| 2379 | * @wiphy: Pointer to wiphy |
| 2380 | * @dev: Pointer network device |
| 2381 | * |
| 2382 | * Return: 0 for success, non zero for failure |
| 2383 | */ |
| 2384 | int wlan_hdd_cfg80211_sched_scan_stop(struct wiphy *wiphy, |
| 2385 | struct net_device *dev) |
| 2386 | { |
| 2387 | int ret; |
| 2388 | |
| 2389 | cds_ssr_protect(__func__); |
| 2390 | ret = __wlan_hdd_cfg80211_sched_scan_stop(wiphy, dev); |
| 2391 | cds_ssr_unprotect(__func__); |
| 2392 | |
| 2393 | return ret; |
| 2394 | } |
| 2395 | #endif /*FEATURE_WLAN_SCAN_PNO */ |
| 2396 | |
| 2397 | /** |
| 2398 | * hdd_vendor_put_ifindex() -send interface index |
| 2399 | * @skb: buffer pointer |
| 2400 | * @ifindex: interface index |
| 2401 | * |
| 2402 | * Send the IF index to differentiate the events on each interface |
| 2403 | * Return: 0 for success, non zero for failure |
| 2404 | */ |
| 2405 | int hdd_vendor_put_ifindex(struct sk_buff *skb, int ifindex) |
| 2406 | { |
| 2407 | struct nlattr *attr; |
| 2408 | |
| 2409 | nla_nest_cancel(skb, ((void **)skb->cb)[2]); |
| 2410 | if (nla_put_u32(skb, NL80211_ATTR_IFINDEX, ifindex)) |
| 2411 | return -EINVAL; |
| 2412 | |
| 2413 | attr = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 2414 | ((void **)skb->cb)[2] = attr; |
| 2415 | |
| 2416 | return 0; |
| 2417 | } |