blob: f73a4bc980136eac1c45d73bd45b0c2e82a2a85f [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002 * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
Kiet Lam0fb93dd2014-02-19 00:32:59 -08003 *
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.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam0fb93dd2014-02-19 00:32:59 -080021
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
Jeff Johnson40b59aa2013-03-19 14:43:18 -070028/** ------------------------------------------------------------------------- *
29 ------------------------------------------------------------------------- *
Jeff Johnson295189b2012-06-20 16:38:30 -070030
Jeff Johnson40b59aa2013-03-19 14:43:18 -070031
Jeff Johnson295189b2012-06-20 16:38:30 -070032 \file csrApiScan.c
Jeff Johnson40b59aa2013-03-19 14:43:18 -070033
Jeff Johnson295189b2012-06-20 16:38:30 -070034 Implementation for the Common Scan interfaces.
Jeff Johnson295189b2012-06-20 16:38:30 -070035 ========================================================================== */
36
37#include "aniGlobal.h"
38
39#include "palApi.h"
40#include "csrInsideApi.h"
41#include "smeInside.h"
42#include "smsDebug.h"
43
44#include "csrSupport.h"
45#include "wlan_qct_tl.h"
46
47#include "vos_diag_core_log.h"
48#include "vos_diag_core_event.h"
49
50#include "vos_nvitem.h"
51#include "wlan_qct_wda.h"
Jeff Johnson40b59aa2013-03-19 14:43:18 -070052
Kiet Lamd1f3dc82013-11-05 20:45:04 +053053#define MIN_CHN_TIME_TO_FIND_GO 100
54#define MAX_CHN_TIME_TO_FIND_GO 100
55#define DIRECT_SSID_LEN 7
Jeff Johnson295189b2012-06-20 16:38:30 -070056
Jeff Johnson295189b2012-06-20 16:38:30 -070057
58/* Purpose of HIDDEN_TIMER
59** When we remove hidden ssid from the profile i.e., forget the SSID via GUI that SSID shouldn't see in the profile
60** For above requirement we used timer limit, logic is explained below
61** Timer value is initialsed to current time when it receives corresponding probe response of hidden SSID (The probe request is
62** received regularly till SSID in the profile. Once it is removed from profile probe request is not sent.) when we receive probe response
63** for broadcast probe request, during update SSID with saved SSID we will diff current time with saved SSID time if it is greater than 1 min
64** then we are not updating with old one
65*/
66
67#define HIDDEN_TIMER (1*60*1000)
68#define CSR_SCAN_RESULT_RSSI_WEIGHT 80 // must be less than 100, represent the persentage of new RSSI
69
70/*---------------------------------------------------------------------------
71 PER filter constant fraction: it is a %
72---------------------------------------------------------------------------*/
73#define CSR_SCAN_PER_FILTER_FRAC 100
74
75/*---------------------------------------------------------------------------
76 RSSI filter constant fraction: it is a %
77---------------------------------------------------------------------------*/
78#define CSR_SCAN_RSSI_FILTER_FRAC 100
79
80/*---------------------------------------------------------------------------
81Convert RSSI into overall score: Since RSSI is in -dBm values, and the
82overall needs to be weighted inversely (where greater value means better
83system), we convert.
84RSSI *cannot* be more than 0xFF or less than 0 for meaningful WLAN operation
85---------------------------------------------------------------------------*/
86#define CSR_SCAN_MAX_SCORE_VAL 0xFF
87#define CSR_SCAN_MIN_SCORE_VAL 0x0
88#define CSR_SCAN_HANDOFF_DELTA 10
Jeff Johnson32d95a32012-09-10 13:15:23 -070089#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL 140
90#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL 120
Madan Mohan Koyyalamudia53c4dc2012-11-13 10:35:42 -080091#define CSR_SCAN_OVERALL_SCORE( rssi ) \
92 (( rssi < CSR_SCAN_MAX_SCORE_VAL ) \
93 ? (CSR_SCAN_MAX_SCORE_VAL-rssi) : CSR_SCAN_MIN_SCORE_VAL)
Jeff Johnson295189b2012-06-20 16:38:30 -070094
95
96#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
97 ( (pMac)->scan.nBssLimit <= (csrLLCount(&(pMac)->scan.scanResultList)) )
98
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +053099/* Maximum number of channels per country can be ignored */
100#define MAX_CHANNELS_IGNORE 10
101
Wilson Yange3d2b292013-10-09 00:35:43 -0700102#define MAX_COUNTRY_IGNORE 5
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530103
Agarwal Ashishd9d72602013-09-13 00:06:17 +0530104#define THIRTY_PERCENT(x) (x*30/100);
105
krunal soni5f112f02013-11-25 15:00:11 -0800106#define MANDATORY_BG_CHANNEL 11
107
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530108/*struct to hold the ignored channel list based on country */
109typedef struct sCsrIgnoreChannels
110{
111 tANI_U8 countryCode[NV_FIELD_COUNTRY_CODE_SIZE];
112 tANI_U16 channelList[MAX_CHANNELS_IGNORE];
113 tANI_U16 channelCount;
114}tCsrIgnoreChannels;
115
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800116#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530117static tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
118 { {'U','A'}, { 136, 140}, 2},
119 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
Madan Mohan Koyyalamudi28dd0422013-08-12 15:06:21 +0530120 { {'I','D'}, { 165}, 1 },
Wilson Yange3d2b292013-10-09 00:35:43 -0700121 { {'A','U'}, { 120, 124, 128}, 3 },
Wilson Yangce31eaf2013-11-11 14:40:34 -0800122 { {'A','R'}, { 120, 124, 128}, 3 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530123 };
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800124#else
125static tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = { };
126#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530127
Jeff Johnson295189b2012-06-20 16:38:30 -0700128//*** This is temporary work around. It need to call CCM api to get to CFG later
129/// Get string parameter value
130extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530131
Jeff Johnson295189b2012-06-20 16:38:30 -0700132void csrScanGetResultTimerHandler(void *);
133void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800134static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700135void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700136static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700137#ifdef WLAN_AP_STA_CONCURRENCY
138static void csrStaApConcTimerHandler(void *);
139#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700140tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700141eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
142void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
143void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
144void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
145void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
146//if bgPeriod is 0, background scan is disabled. It is in millisecond units
147eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
148eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
149void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
150static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
151 tANI_U8 numChn, tSirBssDescription *pBssDesc,
152 tDot11fBeaconIEs **ppIes );
153eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
154void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
155tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700156void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700157
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700158#define CSR_IS_SOCIAL_CHANNEL(channel) (((channel) == 1) || ((channel) == 6) || ((channel) == 11) )
159
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700160
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700161
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800162static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
163{
164 tListElem *pEntry;
165 tSmeCmd *pCommand;
166
167 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
168 {
169 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
170 if ( eSmeCsrCommandMask & pCommand->command )
171 {
172 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
173 }
174 else
175 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800176 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800177 }
178 }
179}
Jeff Johnson295189b2012-06-20 16:38:30 -0700180//pResult is invalid calling this function.
181void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
182{
183 if( NULL != pResult->Result.pvIes )
184 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530185 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700186 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530187 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700188}
189
190
191static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
192{
193 eHalStatus status = eHAL_STATUS_SUCCESS;
194 tListElem *pEntry;
195 tCsrScanResult *pBssDesc;
196
197 csrLLLock(pList);
198
199 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
200 {
201 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
202 csrFreeScanResultEntry( pMac, pBssDesc );
203 }
204
205 csrLLUnlock(pList);
206
207 return (status);
208}
209
Jeff Johnson295189b2012-06-20 16:38:30 -0700210eHalStatus csrScanOpen( tpAniSirGlobal pMac )
211{
212 eHalStatus status;
213
214 do
215 {
216 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
217 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
218 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
219 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
220#ifdef WLAN_AP_STA_CONCURRENCY
221 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
222#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700223 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
224 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530225 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
226 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700227 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800228 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700229 break;
230 }
231#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530232 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
233 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700234 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800235 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700236 break;
237 }
238#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530239 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
240 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700241 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800242 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700243 break;
244 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530245 status = vos_timer_init(&pMac->scan.hTimerResultAging, VOS_TIMER_TYPE_SW, csrScanResultAgingTimerHandler, pMac);
246 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700247 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800248 smsLog(pMac, LOGE, FL("cannot allocate memory for ResultAging timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700249 break;
250 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530251 status = vos_timer_init(&pMac->scan.hTimerResultCfgAging, VOS_TIMER_TYPE_SW,
252 csrScanResultCfgAgingTimerHandler, pMac);
253 if (!HAL_STATUS_SUCCESS(status))
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800254 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800255 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800256 break;
257 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700258 }while(0);
259
260 return (status);
261}
262
263
264eHalStatus csrScanClose( tpAniSirGlobal pMac )
265{
Jeff Johnson295189b2012-06-20 16:38:30 -0700266 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
267 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
268#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800269 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700270#endif
271 csrLLClose(&pMac->scan.scanResultList);
272 csrLLClose(&pMac->scan.tempScanResults);
273#ifdef WLAN_AP_STA_CONCURRENCY
274 csrLLClose(&pMac->scan.scanCmdPendingList);
275#endif
276 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
277 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
278 csrLLClose(&pMac->scan.channelPowerInfoList24);
279 csrLLClose(&pMac->scan.channelPowerInfoList5G);
280 csrScanDisable(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530281 vos_timer_destroy(&pMac->scan.hTimerResultAging);
282 vos_timer_destroy(&pMac->scan.hTimerResultCfgAging);
283 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700284#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530285 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700286#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530287 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Jeff Johnson295189b2012-06-20 16:38:30 -0700288 return eHAL_STATUS_SUCCESS;
289}
290
291
292eHalStatus csrScanEnable( tpAniSirGlobal pMac )
293{
294
295 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
296 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
297
298 return eHAL_STATUS_SUCCESS;
299}
300
301
302eHalStatus csrScanDisable( tpAniSirGlobal pMac )
303{
304
305 csrScanStopTimers(pMac);
306 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
307
308 return eHAL_STATUS_SUCCESS;
309}
310
311
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700312//Set scan timing parameters according to state of other driver sessions
313//No validation of the parameters is performed.
314static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
315{
316#ifdef WLAN_AP_STA_CONCURRENCY
317 if(csrIsAnySessionConnected(pMac))
318 {
319 //If multi-session, use the appropriate default scan times
320 if(scanType == eSIR_ACTIVE_SCAN)
321 {
322 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
323 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
324 }
325 else
326 {
327 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
328 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
329 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530330 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
331 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700332
333 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
334
335 //Return so that fields set above will not be overwritten.
336 return;
337 }
338#endif
339
340 //This portion of the code executed if multi-session not supported
341 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
342 //Use the "regular" (non-concurrency) default scan timing.
343 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
344 {
345 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
346 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
347 }
348 else
349 {
350 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
351 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
352 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530353 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
354 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700355
356#ifdef WLAN_AP_STA_CONCURRENCY
357 //No rest time if no sessions are connected.
358 pScanRequest->restTime = 0;
359#endif
360}
361
Jeff Johnson295189b2012-06-20 16:38:30 -0700362#ifdef WLAN_AP_STA_CONCURRENCY
363//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
364eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
365{
366 eHalStatus status = eHAL_STATUS_SUCCESS;
367
368 tANI_BOOLEAN fNoCmdPending;
369 tSmeCmd *pQueueScanCmd=NULL;
370 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700371 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700372 if (NULL == pScanCmd)
373 {
374 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
375 return eHAL_STATUS_FAILURE;
376 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800377 /* split scan if any one of the following:
378 * - STA session is connected and the scan is not a P2P search
379 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800380 * Do not split scans if no concurrent infra connections are
381 * active and if the scan is a BG scan triggered by LFR (OR)
382 * any scan if LFR is in the middle of a BG scan. Splitting
383 * the scan is delaying the time it takes for LFR to find
384 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800385 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700386
387 if(csrIsStaSessionConnected(pMac) &&
388 !csrIsP2pSessionConnected(pMac))
389 {
390 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
391 }
392 else if(csrIsP2pSessionConnected(pMac))
393 {
394 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
395 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800396 if ( (csrIsStaSessionConnected(pMac) &&
397#ifdef FEATURE_WLAN_LFR
398 (csrIsConcurrentInfraConnected(pMac) ||
399 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
400 (pMac->roam.neighborRoamInfo.neighborRoamState !=
401 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
402#endif
403 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800404 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700405 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700406 tCsrScanRequest scanReq;
407 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
408 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
409 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700410 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
411
412 if (numChn == 0)
413 {
414
415 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700416
Kiet Lam64c1b492013-07-12 13:56:44 +0530417 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
418 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700419 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800420 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800421 return eHAL_STATUS_FAILURE;
422 }
423 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530424 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
425 pMac->scan.baseChannels.channelList, numChn);
426 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800427 if( !HAL_STATUS_SUCCESS( status ) )
428 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530429 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800430 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800431 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800432 return eHAL_STATUS_FAILURE;
433 }
434 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
435 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700436
Vinay Malekal05fdc812012-12-17 13:04:30 -0800437 //Whenever we get a scan request with multiple channels we break it up into 2 requests
438 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700439 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800440 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530441 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800442
443 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
444 if (!pQueueScanCmd)
445 {
446 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700447 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530448 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800449 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
450
Jeff Johnson295189b2012-06-20 16:38:30 -0700451 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800452 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800453 return eHAL_STATUS_FAILURE;
454 }
455 pQueueScanCmd->command = pScanCmd->command;
456 pQueueScanCmd->sessionId = pScanCmd->sessionId;
457 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
458 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
459 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
460 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700461
Vinay Malekal05fdc812012-12-17 13:04:30 -0800462 /* First copy all the parameters to local variable of scan request */
463 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700464
Vinay Malekal05fdc812012-12-17 13:04:30 -0800465 /* Now modify the elements of local var scan request required to be modified for split scan */
466 if(scanReq.ChannelInfo.ChannelList != NULL)
467 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530468 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800469 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800470 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700471
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700472 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700473
Vinay Malekal05fdc812012-12-17 13:04:30 -0800474 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530475 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
476 &channelToScan[0], pScanCmd,
477 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700478
Kiet Lam64c1b492013-07-12 13:56:44 +0530479 vos_mem_copy(&channelToScan[0],
480 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
481 nNumChanCombinedConc],
482 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800483
484 pChnInfo->ChannelList = &channelToScan[0];
485
486 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
487 //Modify callers parameters in case of concurrency
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530488 if (!pScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
489 scanReq.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800490 //Use concurrency values for min/maxChnTime.
491 //We know csrIsAnySessionConnected(pMac) returns TRUE here
492 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
493
494 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
495
496 if(!HAL_STATUS_SUCCESS(status))
497 {
498 if (bMemAlloc)
499 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530500 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800501 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
502
503 }
504 if( scanReq.pIEField != NULL)
505 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530506 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800507 scanReq.pIEField = NULL;
508 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800509 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800510 return eHAL_STATUS_FAILURE;
511 }
512 /* Clean the local scan variable */
513 scanReq.ChannelInfo.ChannelList = NULL;
514 scanReq.ChannelInfo.numOfChannels = 0;
515 csrScanFreeRequest(pMac, &scanReq);
516
517 /* setup the command to scan 2 channels */
518 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700519 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800520 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530521 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
522 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800523 //Use concurrency values for min/maxChnTime.
524 //We know csrIsAnySessionConnected(pMac) returns TRUE here
525 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
526 pSendScanCmd->u.scanCmd.callback = NULL;
527 } else {
528 pSendScanCmd = pScanCmd;
529 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530530 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
531 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800532 //Use concurrency values for min/maxChnTime.
533 //We know csrIsAnySessionConnected(pMac) returns TRUE here
534 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
535 }
536
537 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
538
539 //Logic Below is as follows
540 // If the scanCmdPendingList is empty then we directly send that command
541 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
542 if( fNoCmdPending )
543 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700544 if (pQueueScanCmd != NULL)
545 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800546 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700547 }
548
549 if (pSendScanCmd != NULL)
550 {
551 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
552 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800553 }
554 else
555 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700556 if (pSendScanCmd != NULL)
557 {
558 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
559 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800560
Jeff Johnson295189b2012-06-20 16:38:30 -0700561 if (pQueueScanCmd != NULL)
562 {
563 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
564 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800565 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700566 }
567 else
568 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800569 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800570 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800571 pScanCmd->u.scanCmd.reason,
572 pMac->roam.neighborRoamInfo.neighborRoamState,
573 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700574 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
575 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700576
577 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700578}
579#endif
580
Jeff Johnsone7245742012-09-05 17:12:55 -0700581/* ---------------------------------------------------------------------------
582 \fn csrScan2GOnyRequest
583 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800584 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700585 \param pMac
586 \param pScanCmd
587 \param pScanRequest
588 \return None
589 -------------------------------------------------------------------------------*/
590static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
591 tCsrScanRequest *pScanRequest)
592{
593 tANI_U8 index, channelId, channelListSize = 0;
594 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
595 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
596
597 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700598 /* To silence the KW tool null check is added */
599 if((pScanCmd == NULL) || (pScanRequest == NULL))
600 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800601 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700602 return;
603 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700604
605 if (pScanCmd->u.scanCmd.scanID ||
606 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
607 return;
608
609 //Contsruct valid Supported 2.4 GHz Channel List
610 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
611 {
612 channelId = channelList2G[index];
613 if ( csrIsSupportedChannel( pMac, channelId ) )
614 {
615 validchannelList[channelListSize++] = channelId;
616 }
617 }
618
619 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
620 pScanRequest->ChannelInfo.ChannelList = validchannelList;
621}
622
Jeff Johnson295189b2012-06-20 16:38:30 -0700623eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
624 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
625 csrScanCompleteCallback callback, void *pContext)
626{
627 eHalStatus status = eHAL_STATUS_FAILURE;
628 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700629 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700630
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800631 if(pScanRequest == NULL)
632 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800633 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800634 VOS_ASSERT(0);
635 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700636
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530637 /* During group formation, the P2P client scans for GO with the specific SSID.
638 * There will be chances of GO switching to other channels because of scan or
639 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
640 * of client to find the GO, the dwell time of scan is increased to 100ms.
641 */
642 if(pScanRequest->p2pSearch)
643 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530644 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530645 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530646 //If the scan request is for specific SSId the length of SSID will be
647 //greater than 7 as SSID for p2p search contains "DIRECT-")
648 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
649 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530650 smsLog( pMac, LOG1, FL("P2P: Increasing the min and max Dwell"
651 " time to %d for specific SSID scan %.*s"),
652 MAX_CHN_TIME_TO_FIND_GO,
653 pScanRequest->SSIDs.SSIDList->SSID.length,
654 pScanRequest->SSIDs.SSIDList->SSID.ssId);
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530655 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
656 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
657 }
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530658 }
659 }
660
Jeff Johnson295189b2012-06-20 16:38:30 -0700661 do
662 {
663 if(pMac->scan.fScanEnable)
664 {
665 pScanCmd = csrGetCommandBuffer(pMac);
666 if(pScanCmd)
667 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530668 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700669 pScanCmd->command = eSmeCommandScan;
670 pScanCmd->sessionId = sessionId;
671 pScanCmd->u.scanCmd.callback = callback;
672 pScanCmd->u.scanCmd.pContext = pContext;
673 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
674 {
675 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
676 }
677 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
678 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
679#ifdef SOFTAP_CHANNEL_RANGE
680 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
681#endif
682 )
683 {
684 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
685 }
686 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
687 {
688 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
689 }
690 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
691 {
692 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
693 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700694 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
695 {
696 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
697 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700698 else
699 {
700 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
701 }
702 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
703 {
704 //The caller doesn't set the time correctly. Set it here
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530705 csrSetDefaultScanTiming(pMac, pScanRequest->scanType,
706 pScanRequest);
707 smsLog(pMac, LOG1, FL("Setting default min %d and max %d"
708 " ChnTime"), pScanRequest->minChnTime,
709 pScanRequest->maxChnTime);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700710 }
711#ifdef WLAN_AP_STA_CONCURRENCY
712 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800713 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700714 //Need to set restTime only if at least one session is connected
715 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700716 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700717 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700718 }
719 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700720#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700721 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530722 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800723 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
724 to take a long time.
725 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
726 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700727 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800728 if (HAL_STATUS_SUCCESS(status) &&
729 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700730 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
731 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
732 {
733 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
734 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530735 smsLog( pMac, LOG1, FL("BTC A2DP up, doubling max and min"
736 " ChnTime (Max=%d Min=%d)"),
737 pScanRequest->maxChnTime,
738 pScanRequest->minChnTime);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700739 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800740
Kiet Lam64c1b492013-07-12 13:56:44 +0530741 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
742 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700743 //Need to make the following atomic
744 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
745
746 if(pScanRequestID)
747 {
748 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
749 }
750
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800751 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700752 // If it is not, CSR will save the scan request in the pending cmd queue
753 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800754 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700755 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
756#ifdef SOFTAP_CHANNEL_RANGE
757 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
758#endif
759 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
760 )
761 {
762 tSmeCmd *p11dScanCmd;
763 tCsrScanRequest scanReq;
764 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
765
Kiet Lam64c1b492013-07-12 13:56:44 +0530766 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700767
768 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800769 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700770 {
771 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
772
Kiet Lam64c1b492013-07-12 13:56:44 +0530773 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
774 pChnInfo->ChannelList = vos_mem_malloc(numChn);
775 if ( NULL == pChnInfo->ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700776 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530777 smsLog(pMac, LOGE, FL("Failed to allocate memory"));
778 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700779 break;
780 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530781 vos_mem_copy(pChnInfo->ChannelList,
782 pMac->scan.baseChannels.channelList,
783 numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700784 pChnInfo->numOfChannels = (tANI_U8)numChn;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530785
Jeff Johnson295189b2012-06-20 16:38:30 -0700786 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetefc7ff5b2014-01-27 11:30:05 +0530787 p11dScanCmd->u.scanCmd.callback = pMac->scan.callback11dScanDone;
Jeff Johnson295189b2012-06-20 16:38:30 -0700788 p11dScanCmd->u.scanCmd.pContext = NULL;
789 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++;
790 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
791
792 if ( csrIs11dSupported(pMac) )
793 {
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530794 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
795 if (pScanRequest->bcnRptReqScan)
796 scanReq.scanType = pScanRequest->scanType ?
797 eSIR_PASSIVE_SCAN :
798 pScanRequest->scanType;
799 else
800 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700801 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
802 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
803 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
804 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
805 }
806 else
807 {
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530808 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
809 if (pScanRequest->bcnRptReqScan)
810 scanReq.scanType = pScanRequest->scanType;
811 else
812 scanReq.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700813 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
814 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
815 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
816 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800817
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530818 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
819 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700820 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700821
Jeff Johnson295189b2012-06-20 16:38:30 -0700822 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
823 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530824 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700825 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700826
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800827 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700828 {
krunal soni5f112f02013-11-25 15:00:11 -0800829 pMac->scan.scanProfile.numOfChannels =
830 p11dScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700831 //Start process the command
832#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530833 if (!pMac->fScanOffload)
834 status = csrQueueScanRequest(pMac, p11dScanCmd);
835 else
836 status = csrQueueSmeCommand(pMac, p11dScanCmd,
837 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700838#else
839 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
840#endif
841 if( !HAL_STATUS_SUCCESS( status ) )
842 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530843 smsLog(pMac, LOGE, FL("Failed to send message"
844 " status = %d"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700845 break;
846 }
847 }
848 else
849 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530850 smsLog(pMac, LOGE, FL("csrScanCopyRequest failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700851 break;
852 }
853 }
854 else
855 {
856 //error
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530857 smsLog( pMac, LOGE, FL("p11dScanCmd failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -0700858 break;
859 }
860 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700861
862 //Scan only 2G Channels if set in ini file
863 //This is mainly to reduce the First Scan duration
864 //Once we turn on Wifi
865 if(pMac->scan.fFirstScanOnly2GChnl)
866 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800867 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700868 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
869 }
870
Jeff Johnson295189b2012-06-20 16:38:30 -0700871 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
872 if(HAL_STATUS_SUCCESS(status))
873 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530874 tCsrScanRequest *pTempScanReq =
875 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800876 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530877 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800878
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530879 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
880 " Scan reason=%u numSSIDs=%d"
881 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
882 " minCBtc=%d maxCBtx=%d"),
883 sessionId, pScanCmd->u.scanCmd.scanID,
884 pScanCmd->u.scanCmd.reason,
885 pTempScanReq->SSIDs.numOfSSIDs,
886 pTempScanReq->ChannelInfo.numOfChannels,
887 pTempScanReq->p2pSearch,
888 pTempScanReq->minChnTime,
889 pTempScanReq->maxChnTime,
890 pTempScanReq->minChnTimeBtc,
891 pTempScanReq->maxChnTimeBtc );
Jeff Johnson295189b2012-06-20 16:38:30 -0700892 //Start process the command
893#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530894 if (!pMac->fScanOffload)
895 status = csrQueueScanRequest(pMac,pScanCmd);
896 else
897 status = csrQueueSmeCommand(pMac, pScanCmd,
898 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700899#else
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530900 status = csrQueueSmeCommand(pMac, pScanCmd,
901 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700902#endif
903 if( !HAL_STATUS_SUCCESS( status ) )
904 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800905 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700906 break;
907 }
908 }
909 else
910 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800911 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700912 break;
913 }
914 }
915 else
916 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800917 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700918 break;
919 }
920 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530921 else
922 {
923 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
924 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
925 sessionId, pScanRequest->requestType,
926 pScanRequest->SSIDs.numOfSSIDs,
927 pScanRequest->p2pSearch );
928 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700929 } while(0);
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530930
931
Jeff Johnson295189b2012-06-20 16:38:30 -0700932 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
933 {
934 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
935 {
936 //Set the flag back for restarting idle scan
937 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
938 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530939 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
940 " Scan reason=%u numOfSSIDs=%d"
941 " P2P search=%d scanId=%d"),
942 sessionId, status, pScanCmd->u.scanCmd.reason,
943 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
944 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -0700945 csrReleaseCommandScan(pMac, pScanCmd);
946 }
947
948 return (status);
949}
950
951
952eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
953{
954 eHalStatus status = eHAL_STATUS_SUCCESS;
955 tSmeCmd *pScanCmd;
956
957 if(pMac->scan.fScanEnable)
958 {
959 pScanCmd = csrGetCommandBuffer(pMac);
960 if(pScanCmd)
961 {
962 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +0530963 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700964 pScanCmd->u.scanCmd.callback = NULL;
965 pScanCmd->u.scanCmd.pContext = NULL;
966 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
967 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700968 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700969 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
970 if( !HAL_STATUS_SUCCESS( status ) )
971 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800972 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700973 csrReleaseCommandScan(pMac, pScanCmd);
974 }
975 }
976 else
977 {
978 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800979 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700980 status = eHAL_STATUS_RESOURCES;
981 }
982 }
983
984 return (status);
985}
986
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -0700987#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
988eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
989 csrScanCompleteCallback callback, void *pContext)
990{
991 eHalStatus status = eHAL_STATUS_SUCCESS;
992 tSmeCmd *pScanCmd;
993
994 if (pMac->scan.fScanEnable)
995 {
996 pScanCmd = csrGetCommandBuffer(pMac);
997 if (pScanCmd)
998 {
999 pScanCmd->command = eSmeCommandScan;
1000 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301001 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001002 pScanCmd->u.scanCmd.callback = callback;
1003 pScanCmd->u.scanCmd.pContext = pContext;
1004 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1005 //Need to make the following atomic
1006 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1007 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1008 if ( !HAL_STATUS_SUCCESS( status ) )
1009 {
1010 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1011 csrReleaseCommandScan(pMac, pScanCmd);
1012 }
1013 }
1014 else
1015 {
1016 //log error
1017 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1018 status = eHAL_STATUS_RESOURCES;
1019 }
1020 }
1021
1022 return (status);
1023}
1024#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001025
1026eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1027{
1028 eHalStatus status = eHAL_STATUS_SUCCESS;
1029 tANI_U32 scanId;
1030 tCsrScanRequest scanReq;
1031
Kiet Lam64c1b492013-07-12 13:56:44 +05301032 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001033 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1034 scanReq.scanType = eSIR_ACTIVE_SCAN;
1035 scanReq.requestType = reqType;
1036 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1037 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001038 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1039 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001040 //Scan with invalid sessionId.
1041 //This results in SME using the first available session to scan.
1042 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1043 &scanId, NULL, NULL);
1044
1045 return (status);
1046}
1047
1048
1049
1050
1051eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1052{
1053 eHalStatus status = eHAL_STATUS_FAILURE;
1054 tScanResultHandle hBSSList = NULL;
1055 tCsrScanResultFilter *pScanFilter = NULL;
1056 tANI_U32 roamId = 0;
1057 tCsrRoamProfile *pProfile = NULL;
1058 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1059
Jeff Johnson32d95a32012-09-10 13:15:23 -07001060 if(!pSession)
1061 {
1062 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1063 return eHAL_STATUS_FAILURE;
1064 }
1065
Jeff Johnson295189b2012-06-20 16:38:30 -07001066 do
1067 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001068 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001069 if(pSession->fCancelRoaming)
1070 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001071 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001072 csrScanStartIdleScan(pMac);
1073 status = eHAL_STATUS_SUCCESS;
1074 break;
1075 }
1076 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301077 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1078 if ( NULL == pScanFilter)
1079 status = eHAL_STATUS_FAILURE;
1080 else
1081 status = eHAL_STATUS_SUCCESS;
1082 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001083 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301084 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001085 if(NULL == pSession->pCurRoamProfile)
1086 {
1087 pScanFilter->EncryptionType.numEntries = 1;
1088 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1089 }
1090 else
1091 {
1092 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301093 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1094 if ( NULL == pProfile )
1095 status = eHAL_STATUS_FAILURE;
1096 else
1097 status = eHAL_STATUS_SUCCESS;
1098 if (!HAL_STATUS_SUCCESS(status))
1099 break;
1100 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001101 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1102 if(!HAL_STATUS_SUCCESS(status))
1103 break;
1104 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1105 }//We have a profile
1106 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1107 if(HAL_STATUS_SUCCESS(status))
1108 {
1109 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1110 if(HAL_STATUS_SUCCESS(status))
1111 {
1112 if(eCsrLostLink1 == reason)
1113 {
1114 //we want to put the last connected BSS to the very beginning, if possible
1115 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1116 }
1117 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1118 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1119 if(!HAL_STATUS_SUCCESS(status))
1120 {
1121 csrScanResultPurge(pMac, hBSSList);
1122 }
1123 }//Have scan result
1124 }
1125 }while(0);
1126 if(pScanFilter)
1127 {
1128 //we need to free memory for filter if profile exists
1129 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301130 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001131 }
1132 if(NULL != pProfile)
1133 {
1134 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301135 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001136 }
1137
1138 return (status);
1139}
1140
1141
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301142eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tANI_U8 sessionId,
1143 void *pContext, void *callback)
Jeff Johnson295189b2012-06-20 16:38:30 -07001144{
1145 eHalStatus status = eHAL_STATUS_SUCCESS;
1146 tSmeCmd *pScanCmd;
1147
1148 if(pMac->scan.fScanEnable)
1149 {
1150 pScanCmd = csrGetCommandBuffer(pMac);
1151 if(pScanCmd)
1152 {
1153 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301154 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001155 pScanCmd->u.scanCmd.callback = callback;
1156 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001157 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1158 //Need to make the following atomic
1159 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301160 pScanCmd->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001161 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1162 if( !HAL_STATUS_SUCCESS( status ) )
1163 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001164 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001165 csrReleaseCommandScan(pMac, pScanCmd);
1166 }
1167 }
1168 else
1169 {
1170 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001171 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001172 status = eHAL_STATUS_RESOURCES;
1173 }
1174 }
1175
1176 return (status);
1177}
1178
1179
1180eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1181{
1182 eHalStatus status = eHAL_STATUS_FAILURE;
1183 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1184
Jeff Johnson32d95a32012-09-10 13:15:23 -07001185 if(!pSession)
1186 {
1187 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1188 return eHAL_STATUS_FAILURE;
1189 }
1190
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001191 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001192 if(pSession->fCancelRoaming)
1193 {
1194 csrScanStartIdleScan(pMac);
1195 }
1196 else if(pSession->pCurRoamProfile)
1197 {
1198 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1199 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1200 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1201 {
1202 //try lostlink scan2
1203 status = csrScanRequestLostLink2(pMac, sessionId);
1204 }
1205 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1206 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1207 {
1208 //go straight to lostlink scan3
1209 status = csrScanRequestLostLink3(pMac, sessionId);
1210 }
1211 else
1212 {
1213 //we are done with lostlink
1214 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1215 {
1216 csrScanStartIdleScan(pMac);
1217 }
1218 status = eHAL_STATUS_SUCCESS;
1219 }
1220 }
1221 else
1222 {
1223 status = csrScanRequestLostLink3(pMac, sessionId);
1224 }
1225
1226 return (status);
1227}
1228
1229
1230
1231eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1232{
1233 eHalStatus status = eHAL_STATUS_FAILURE;
1234 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1235
Jeff Johnson32d95a32012-09-10 13:15:23 -07001236 if(!pSession)
1237 {
1238 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1239 return eHAL_STATUS_FAILURE;
1240 }
1241
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001242 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001243 if(pSession->fCancelRoaming)
1244 {
1245 csrScanStartIdleScan(pMac);
1246 }
1247 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1248 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1249 {
1250 //try lostlink scan3
1251 status = csrScanRequestLostLink3(pMac, sessionId);
1252 }
1253 else
1254 {
1255 //we are done with lostlink
1256 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1257 {
1258 csrScanStartIdleScan(pMac);
1259 }
1260 }
1261
1262 return (status);
1263}
1264
1265
1266
1267eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1268{
1269 eHalStatus status = eHAL_STATUS_SUCCESS;
1270
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001271 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001272 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1273 {
1274 //we are done with lostlink
1275 csrScanStartIdleScan(pMac);
1276 }
1277
1278 return (status);
1279}
1280
1281
1282
1283
1284//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1285//If no roam profile (it should not), it is like lostlinkscan3
1286eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1287{
1288 eHalStatus status = eHAL_STATUS_SUCCESS;
1289 tSmeCmd *pCommand = NULL;
1290 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1291 tCsrScanResultFilter *pScanFilter = NULL;
1292 tScanResultHandle hBSSList = NULL;
1293 tCsrScanResultInfo *pScanResult = NULL;
1294 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1295
Jeff Johnson32d95a32012-09-10 13:15:23 -07001296 if(!pSession)
1297 {
1298 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1299 return eHAL_STATUS_FAILURE;
1300 }
1301
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001302 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001303 do
1304 {
1305 pCommand = csrGetCommandBuffer(pMac);
1306 if(!pCommand)
1307 {
1308 status = eHAL_STATUS_RESOURCES;
1309 break;
1310 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301311 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001312 pCommand->command = eSmeCommandScan;
1313 pCommand->sessionId = (tANI_U8)sessionId;
1314 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1315 pCommand->u.scanCmd.callback = NULL;
1316 pCommand->u.scanCmd.pContext = NULL;
1317 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1318 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001319 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1320 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001321 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1322 if(pSession->connectedProfile.SSID.length)
1323 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301324 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1325 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1326 status = eHAL_STATUS_FAILURE;
1327 else
1328 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001329 if(!HAL_STATUS_SUCCESS(status))
1330 {
1331 break;
1332 }
1333 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301334 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1335 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001336 }
1337 else
1338 {
1339 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1340 }
1341 if(pSession->pCurRoamProfile)
1342 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301343 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1344 if ( NULL == pScanFilter )
1345 status = eHAL_STATUS_FAILURE;
1346 else
1347 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001348 if(!HAL_STATUS_SUCCESS(status))
1349 {
1350 break;
1351 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301352 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001353 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1354 if(!HAL_STATUS_SUCCESS(status))
1355 {
1356 break;
1357 }
1358 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1359 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1360 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1361 {
1362 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301363 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1364 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1365 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1366 status = eHAL_STATUS_FAILURE;
1367 else
1368 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001369 if(!HAL_STATUS_SUCCESS(status))
1370 {
1371 break;
1372 }
1373 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1374 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1375 {
1376 for(i = 0; i < nChn; i++)
1377 {
1378 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1379 pScanResult->BssDescriptor.channelId)
1380 {
1381 break;
1382 }
1383 }
1384 if(i == nChn)
1385 {
1386 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1387 }
1388 }
1389 //Include the last connected BSS' channel
1390 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1391 {
1392 for(i = 0; i < nChn; i++)
1393 {
1394 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1395 pSession->connectedProfile.operationChannel)
1396 {
1397 break;
1398 }
1399 }
1400 if(i == nChn)
1401 {
1402 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1403 }
1404 }
1405 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1406 }
1407 else
1408 {
1409 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1410 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301411 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1412 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1413 status = eHAL_STATUS_FAILURE;
1414 else
1415 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001416 //just try the last connected channel
1417 if(HAL_STATUS_SUCCESS(status))
1418 {
1419 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1420 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1421 }
1422 else
1423 {
1424 break;
1425 }
1426 }
1427 }
1428 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301429 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001430 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1431 if( !HAL_STATUS_SUCCESS( status ) )
1432 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001433 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001434 break;
1435 }
1436 } while( 0 );
1437
1438 if(!HAL_STATUS_SUCCESS(status))
1439 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001440 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001441 if(pCommand)
1442 {
1443 csrReleaseCommandScan(pMac, pCommand);
1444 }
1445 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1446 }
1447 if(pScanFilter)
1448 {
1449 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301450 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001451 }
1452 if(hBSSList)
1453 {
1454 csrScanResultPurge(pMac, hBSSList);
1455 }
1456
1457 return( status );
1458}
1459
1460
1461//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1462//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1463eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1464{
1465 eHalStatus status = eHAL_STATUS_SUCCESS;
1466 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1467 tCsrScanResultFilter *pScanFilter = NULL;
1468 tScanResultHandle hBSSList = NULL;
1469 tCsrScanResultInfo *pScanResult = NULL;
1470 tSmeCmd *pCommand = NULL;
1471 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1472
Jeff Johnson32d95a32012-09-10 13:15:23 -07001473 if(!pSession)
1474 {
1475 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1476 return eHAL_STATUS_FAILURE;
1477 }
1478
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001479 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001480 do
1481 {
1482 pCommand = csrGetCommandBuffer(pMac);
1483 if(!pCommand)
1484 {
1485 status = eHAL_STATUS_RESOURCES;
1486 break;
1487 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301488 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001489 pCommand->command = eSmeCommandScan;
1490 pCommand->sessionId = (tANI_U8)sessionId;
1491 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1492 pCommand->u.scanCmd.callback = NULL;
1493 pCommand->u.scanCmd.pContext = NULL;
1494 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1495 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001496 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1497 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001498 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1499 if(pSession->pCurRoamProfile)
1500 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301501 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1502 if ( NULL == pScanFilter )
1503 status = eHAL_STATUS_FAILURE;
1504 else
1505 status = eHAL_STATUS_SUCCESS;
1506 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001507 {
1508 break;
1509 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301510 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001511 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1512 if(!HAL_STATUS_SUCCESS(status))
1513 {
1514 break;
1515 }
1516 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1517 if(!HAL_STATUS_SUCCESS(status))
1518 {
1519 break;
1520 }
1521 if(hBSSList)
1522 {
1523 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301524 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1525 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1526 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1527 status = eHAL_STATUS_FAILURE;
1528 else
1529 status = eHAL_STATUS_SUCCESS;
1530 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001531 {
1532 break;
1533 }
1534 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1535 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1536 {
1537 for(i = 0; i < nChn; i++)
1538 {
1539 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1540 pScanResult->BssDescriptor.channelId)
1541 {
1542 break;
1543 }
1544 }
1545 if(i == nChn)
1546 {
1547 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1548 }
1549 }
1550 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1551 }
1552 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301553 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001554 //Put to the head in pending queue
1555 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1556 if( !HAL_STATUS_SUCCESS( status ) )
1557 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001558 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001559 break;
1560 }
1561 } while( 0 );
1562
1563 if(!HAL_STATUS_SUCCESS(status))
1564 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001565 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001566 if(pCommand)
1567 {
1568 csrReleaseCommandScan(pMac, pCommand);
1569 }
1570 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1571 }
1572 if(pScanFilter)
1573 {
1574 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301575 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001576 }
1577 if(hBSSList)
1578 {
1579 csrScanResultPurge(pMac, hBSSList);
1580 }
1581
1582 return( status );
1583}
1584
1585
1586//To actively scan all valid channels
1587eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1588{
1589 eHalStatus status = eHAL_STATUS_SUCCESS;
1590 tSmeCmd *pCommand;
1591 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1592
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001593 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001594 do
1595 {
1596 pCommand = csrGetCommandBuffer(pMac);
1597 if(!pCommand)
1598 {
1599 status = eHAL_STATUS_RESOURCES;
1600 break;
1601 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301602 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001603 pCommand->command = eSmeCommandScan;
1604 pCommand->sessionId = (tANI_U8)sessionId;
1605 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1606 pCommand->u.scanCmd.callback = NULL;
1607 pCommand->u.scanCmd.pContext = NULL;
1608 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1609 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001610 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1611 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001612 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301613 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001614 //Put to the head of pending queue
1615 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1616 if( !HAL_STATUS_SUCCESS( status ) )
1617 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001618 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001619 break;
1620 }
1621 } while( 0 );
1622 if(!HAL_STATUS_SUCCESS(status))
1623 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001624 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001625 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1626 {
1627 csrScanStartIdleScan(pMac);
1628 }
1629 if(pCommand)
1630 {
1631 csrReleaseCommandScan(pMac, pCommand);
1632 }
1633 }
1634
1635 return( status );
1636}
1637
1638
1639eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1640{
1641 eHalStatus status = eHAL_STATUS_FAILURE;
1642 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1643 tCsrScanResultFilter *pScanFilter = NULL;
1644 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1645 tANI_U32 sessionId = pCommand->sessionId;
1646#ifdef FEATURE_WLAN_BTAMP_UT_RF
1647 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1648#endif
1649 do
1650 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001651#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1652 //if this scan is for LFR
1653 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1654 {
1655 //notify LFR state m/c
1656 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1657 {
Varun Reddy Yeturue3af4282013-06-07 00:56:52 -07001658 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001659 }
1660 status = eHAL_STATUS_SUCCESS;
1661 break;
1662 }
1663#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001664 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1665 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1666 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001667 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001668 break;
1669 }
1670 if(pProfile == NULL)
1671 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301672 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1673 if ( NULL == pScanFilter )
1674 status = eHAL_STATUS_FAILURE;
1675 else
1676 status = eHAL_STATUS_SUCCESS;
1677 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001678 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301679 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001680 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1681 if(!HAL_STATUS_SUCCESS(status))
1682 break;
1683 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1684 if(!HAL_STATUS_SUCCESS(status))
1685 break;
1686 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1687 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1688 if(!HAL_STATUS_SUCCESS(status))
1689 {
1690 break;
1691 }
1692 }while(0);
1693 if(!HAL_STATUS_SUCCESS(status))
1694 {
1695 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1696 {
1697 csrScanResultPurge(pMac, hBSSList);
1698 }
1699 //We haven't done anything to this profile
1700 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1701 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1702 //In case we have nothing else to do, restart idle scan
1703 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1704 {
1705 status = csrScanStartIdleScan(pMac);
1706 }
1707#ifdef FEATURE_WLAN_BTAMP_UT_RF
1708 //In case of WDS station, let it retry.
1709 if( CSR_IS_WDS_STA(pProfile) )
1710 {
1711 //Save the roma profile so we can retry
1712 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301713 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1714 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001715 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301716 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001717 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1718 }
1719 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1720 }
1721#endif
1722 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301723 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001724 {
1725 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301726 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001727 }
1728
1729 return (status);
1730}
1731
1732
1733eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1734{
1735 eHalStatus status = eHAL_STATUS_SUCCESS;
1736 tANI_U32 sessionId = pCommand->sessionId;
1737 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1738 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001739#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1740 //if this scan is for LFR
1741 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1742 {
1743 //notify LFR state m/c
1744 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1745 {
Varun Reddy Yeturue3af4282013-06-07 00:56:52 -07001746 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001747 }
1748 return eHAL_STATUS_SUCCESS;
1749 }
1750#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001751 if(!pSession)
1752 {
1753 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1754 return eHAL_STATUS_FAILURE;
1755 }
1756
Jeff Johnson295189b2012-06-20 16:38:30 -07001757#if defined(WLAN_DEBUG)
1758 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1759 {
1760 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301761 vos_mem_copy(str,
1762 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1763 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001764 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001765 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001766 }
1767#endif
1768 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1769 if(pProfile && CSR_IS_START_IBSS(pProfile))
1770 {
1771 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1772 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1773 if(!HAL_STATUS_SUCCESS(status))
1774 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001775 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001776 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1777 }
1778 }
1779 else
1780 {
1781 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1782
1783 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1784 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1785 {
1786 status = csrScanStartIdleScan(pMac);
1787 }
1788 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1789 {
1790 //Only indicate assoc_completion if we indicate assoc_start.
1791 if(pSession->bRefAssocStartCnt > 0)
1792 {
1793 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301794 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001795 pRoamInfo = &roamInfo;
1796 if(pCommand->u.roamCmd.pRoamBssEntry)
1797 {
1798 tCsrScanResult *pScanResult =
1799 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1800 tCsrScanResult, Link);
1801 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1802 }
1803 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1804 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1805 pSession->bRefAssocStartCnt--;
1806 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1807 pCommand->u.scanCmd.roamId,
1808 eCSR_ROAM_ASSOCIATION_COMPLETION,
1809 eCSR_ROAM_RESULT_FAILURE);
1810 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001811 else
1812 {
1813 csrRoamCallCallback(pMac, sessionId, NULL,
1814 pCommand->u.scanCmd.roamId,
1815 eCSR_ROAM_ASSOCIATION_FAILURE,
1816 eCSR_ROAM_RESULT_FAILURE);
1817 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001818#ifdef FEATURE_WLAN_BTAMP_UT_RF
1819 //In case of WDS station, let it retry.
1820 if( CSR_IS_WDS_STA(pProfile) )
1821 {
1822 //Save the roma profile so we can retry
1823 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301824 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1825 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001826 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301827 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001828 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1829 }
1830 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1831 }
1832#endif
1833 }
1834 else
1835 {
1836 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1837 }
1838 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1839 }
1840
1841 return (status);
1842}
1843
1844
1845//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1846eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1847{
1848 eHalStatus status = eHAL_STATUS_FAILURE;
1849 tScanResultHandle hBSSList = NULL;
1850 tCsrScanResultFilter *pScanFilter = NULL;
1851 tANI_U32 roamId = 0;
1852 tCsrRoamProfile *pProfile = NULL;
1853 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1854
1855 do
1856 {
1857 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301858 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1859 if ( NULL == pScanFilter )
1860 status = eHAL_STATUS_FAILURE;
1861 else
1862 status = eHAL_STATUS_SUCCESS;
1863 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001864 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301865 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1866 if (NULL == pSession) break;
1867 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001868 {
1869 pScanFilter->EncryptionType.numEntries = 1;
1870 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1871 }
1872 else
1873 {
1874 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301875 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1876 if ( NULL == pProfile )
1877 status = eHAL_STATUS_FAILURE;
1878 else
1879 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001880 if(!HAL_STATUS_SUCCESS(status))
1881 break;
1882 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1883 if(!HAL_STATUS_SUCCESS(status))
1884 break;
1885 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1886 }//We have a profile
1887 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1888 if(HAL_STATUS_SUCCESS(status))
1889 {
1890 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1891 if(HAL_STATUS_SUCCESS(status))
1892 {
1893 //we want to put the last connected BSS to the very beginning, if possible
1894 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1895 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1896 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1897 if(!HAL_STATUS_SUCCESS(status))
1898 {
1899 csrScanResultPurge(pMac, hBSSList);
1900 }
1901 }//Have scan result
1902 else
1903 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001904 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1905 MAC_ADDRESS_STR),
1906 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001907 //Disconnect
1908 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1909 }
1910 }
1911 }while(0);
1912 if(pScanFilter)
1913 {
1914 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301915 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001916 }
1917 if(NULL != pProfile)
1918 {
1919 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301920 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001921 }
1922
1923 return (status);
1924}
1925
1926
1927
1928eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1929{
1930 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1931 tScanResultList *pScanList = (tScanResultList *)hScanList;
1932
1933 if(pScanList)
1934 {
1935 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1936 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05301937 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07001938 }
1939 return (status);
1940}
1941
1942
1943static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1944{
1945 tANI_U32 ret = 0;
1946 int i = CSR_NUM_RSSI_CAT - 1;
1947
1948 while(i >= 0)
1949 {
1950 if(rssi >= pMac->roam.configParam.RSSICat[i])
1951 {
1952 ret = pMac->roam.configParam.BssPreferValue[i];
1953 break;
1954 }
1955 i--;
1956 };
1957
1958 return (ret);
1959}
1960
1961
1962//Return a CapValue base on the capabilities of a BSS
1963static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
1964{
1965 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08001966#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08001967 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
1968 {
1969 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
1970 {
1971 ret += CSR_BSS_CAP_VALUE_5GHZ;
1972 }
1973 }
1974#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07001975 /* if strict select 5GHz is non-zero then ignore the capability checking */
1976 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07001977 {
1978 //We only care about 11N capability
1979 if(pIes->HTCaps.present)
1980 {
1981 ret += CSR_BSS_CAP_VALUE_HT;
1982 }
1983 if(CSR_IS_QOS_BSS(pIes))
1984 {
1985 ret += CSR_BSS_CAP_VALUE_WMM;
1986 //Give advantage to UAPSD
1987 if(CSR_IS_UAPSD_BSS(pIes))
1988 {
1989 ret += CSR_BSS_CAP_VALUE_UAPSD;
1990 }
1991 }
1992 }
1993
1994 return (ret);
1995}
1996
1997
1998//To check whther pBss1 is better than pBss2
1999static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2000{
2001 tANI_BOOLEAN ret;
2002
2003 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2004 {
2005 ret = eANI_BOOLEAN_TRUE;
2006 }
2007 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2008 {
2009 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2010 {
2011 ret = eANI_BOOLEAN_TRUE;
2012 }
2013 else
2014 {
2015 ret = eANI_BOOLEAN_FALSE;
2016 }
2017 }
2018 else
2019 {
2020 ret = eANI_BOOLEAN_FALSE;
2021 }
2022
2023 return (ret);
2024}
2025
2026
Srikant Kuppa866893f2012-12-27 17:28:14 -08002027#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002028//Add the channel to the occupiedChannels array
2029static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002030 tpAniSirGlobal pMac,
2031 tCsrScanResult *pResult,
2032 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002033 tDot11fBeaconIEs *pIes)
2034{
2035 eHalStatus status;
2036 tANI_U8 channel;
2037 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2038 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2039
2040 channel = pResult->Result.BssDescriptor.channelId;
2041
2042 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002043 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002044 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002045 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002046 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002047 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002048 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002049 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002050 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002051 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2052 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2053 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002054 }
2055}
2056#endif
2057
Jeff Johnson295189b2012-06-20 16:38:30 -07002058//Put the BSS into the scan result list
2059//pIes can not be NULL
2060static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2061{
Srinivas28b5b4e2012-12-12 13:07:53 -08002062#ifdef FEATURE_WLAN_LFR
2063 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2064#endif
2065
Jeff Johnson295189b2012-06-20 16:38:30 -07002066 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2067 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2068 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002069#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002070 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2071 {
2072 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2073 NOT set in the cfg.ini file */
2074 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2075 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002076#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002077}
2078
2079
2080eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2081{
2082 eHalStatus status;
2083 tScanResultList *pRetList;
2084 tCsrScanResult *pResult, *pBssDesc;
2085 tANI_U32 count = 0;
2086 tListElem *pEntry;
2087 tANI_U32 bssLen, allocLen;
2088 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2089 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2090 tDot11fBeaconIEs *pIes, *pNewIes;
2091 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002092 tANI_U16 i = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07002093
2094 if(phResult)
2095 {
2096 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2097 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002098
2099 if (pMac->roam.configParam.nSelect5GHzMargin)
2100 {
2101 pMac->scan.inScanResultBestAPRssi = -128;
2102 csrLLLock(&pMac->scan.scanResultList);
2103
2104 /* Find out the best AP Rssi going thru the scan results */
2105 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2106 while ( NULL != pEntry)
2107 {
2108 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002109 fMatch = FALSE;
2110
2111 if (pFilter)
2112 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002113 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002114 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2115 pBssDesc->Result.ssId.ssId,
2116 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2117 if (fMatch)
2118 {
2119 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2120
2121 //At this time, pBssDescription->Result.pvIes may be NULL
2122 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2123 &pBssDesc->Result.BssDescriptor, &pIes))) )
2124 {
2125 continue;
2126 }
2127
2128 smsLog(pMac, LOG1, FL("SSID Matched"));
2129 fMatch = csrIsSecurityMatch( pMac, &pFilter->authType, &pFilter->EncryptionType, &pFilter->mcEncryptionType,
2130 &pBssDesc->Result.BssDescriptor, pIes, NULL, NULL, NULL );
2131 if ((pBssDesc->Result.pvIes == NULL) && pIes)
Kiet Lamf2f201e2013-11-16 21:24:16 +05302132 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002133
2134 if (fMatch)
2135 smsLog(pMac, LOG1, FL(" Security Matched"));
2136 }
2137 }
2138
2139 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2140 {
2141 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2142 pMac->scan.inScanResultBestAPRssi,
2143 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002144 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2145 }
2146 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2147 }
2148
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002149 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002150 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002151 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2152 /* Modify Rssi category based on best AP Rssi */
2153 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2154 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2155 while ( NULL != pEntry)
2156 {
2157 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002158
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002159 /* re-assign preference value based on modified rssi bucket */
2160 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002161
Arif Hussaina7c8e412013-11-20 11:06:42 -08002162 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002163 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002164 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2165 pBssDesc->Result.BssDescriptor.rssi,
2166 pBssDesc->Result.BssDescriptor.channelId,
2167 pBssDesc->preferValue,
2168 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002169
2170 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2171 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002172 }
2173
2174 csrLLUnlock(&pMac->scan.scanResultList);
2175 }
2176
Kiet Lam64c1b492013-07-12 13:56:44 +05302177 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2178 if ( NULL == pRetList )
2179 status = eHAL_STATUS_FAILURE;
2180 else
2181 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002182 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002183 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302184 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002185 csrLLOpen(pMac->hHdd, &pRetList->List);
2186 pRetList->pCurEntry = NULL;
2187
2188 csrLLLock(&pMac->scan.scanResultList);
2189 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2190 while( pEntry )
2191 {
2192 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2193 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2194 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2195 //for any error condition, otherwiase, it will be freed later.
2196 //reset
2197 fMatch = eANI_BOOLEAN_FALSE;
2198 pNewIes = NULL;
2199
2200 if(pFilter)
2201 {
2202 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2203 if( NULL != pIes )
2204 {
2205 //Only save it when matching
2206 if(fMatch)
2207 {
2208 if( !pBssDesc->Result.pvIes )
2209 {
2210 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2211 pNewIes = pIes;
2212 }
2213 else
2214 {
2215 //The pIes is allocated by someone else. make a copy
2216 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2217 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302218 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2219 if ( NULL == pNewIes )
2220 status = eHAL_STATUS_FAILURE;
2221 else
2222 status = eHAL_STATUS_SUCCESS;
2223 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002224 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302225 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002226 }
2227 else
2228 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002229 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002230 //Need to free memory allocated by csrMatchBSS
2231 if( !pBssDesc->Result.pvIes )
2232 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302233 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002234 }
2235 break;
2236 }
2237 }
2238 }//fMatch
2239 else if( !pBssDesc->Result.pvIes )
2240 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302241 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002242 }
2243 }
2244 }
2245 if(NULL == pFilter || fMatch)
2246 {
2247 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2248 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302249 pResult = vos_mem_malloc(allocLen);
2250 if ( NULL == pResult )
2251 status = eHAL_STATUS_FAILURE;
2252 else
2253 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002254 if(!HAL_STATUS_SUCCESS(status))
2255 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002256 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002257 if(pNewIes)
2258 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302259 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002260 }
2261 break;
2262 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302263 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002264 pResult->capValue = pBssDesc->capValue;
2265 pResult->preferValue = pBssDesc->preferValue;
2266 pResult->ucEncryptionType = uc;
2267 pResult->mcEncryptionType = mc;
2268 pResult->authType = auth;
2269 pResult->Result.ssId = pBssDesc->Result.ssId;
2270 pResult->Result.timer = 0;
2271 //save the pIes for later use
2272 pResult->Result.pvIes = pNewIes;
2273 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302274 vos_mem_copy(&pResult->Result.BssDescriptor,
2275 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002276 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2277 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2278 {
2279 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2280 }
2281 else
2282 {
2283 //To sort the list
2284 tListElem *pTmpEntry;
2285 tCsrScanResult *pTmpResult;
2286
2287 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2288 while(pTmpEntry)
2289 {
2290 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2291 if(csrIsBetterBss(pResult, pTmpResult))
2292 {
2293 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2294 //To indicate we are done
2295 pResult = NULL;
2296 break;
2297 }
2298 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2299 }
2300 if(pResult != NULL)
2301 {
2302 //This one is not better than any one
2303 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2304 }
2305 }
2306 count++;
2307 }
2308 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2309 }//while
2310 csrLLUnlock(&pMac->scan.scanResultList);
2311
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002312 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002313
2314 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2315 {
2316 //Fail or No one wants the result.
2317 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2318 }
2319 else
2320 {
2321 if(0 == count)
2322 {
2323 //We are here meaning the there is no match
2324 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302325 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002326 status = eHAL_STATUS_E_NULL_VALUE;
2327 }
2328 else if(phResult)
2329 {
2330 *phResult = pRetList;
2331 }
2332 }
2333 }//Allocated pRetList
2334
2335 return (status);
2336}
2337
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002338/*
2339 * NOTE: This routine is being added to make
2340 * sure that scan results are not being flushed
2341 * while roaming. If the scan results are flushed,
2342 * we are unable to recover from
2343 * csrRoamRoamingStateDisassocRspProcessor.
2344 * If it is needed to remove this routine,
2345 * first ensure that we recover gracefully from
2346 * csrRoamRoamingStateDisassocRspProcessor if
2347 * csrScanGetResult returns with a failure because
2348 * of not being able to find the roaming BSS.
2349 */
2350tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2351{
2352 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2353 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2354 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2355 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2356 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2357 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2358 default:
2359 return 0;
2360 }
2361}
2362
Jeff Johnson295189b2012-06-20 16:38:30 -07002363eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2364{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002365 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302366 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002367 if (isFlushDenied) {
2368 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2369 __func__, isFlushDenied);
2370 return eHAL_STATUS_FAILURE;
2371 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302372 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2373 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2374 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002375}
2376
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302377eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002378{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302379 eHalStatus status = eHAL_STATUS_SUCCESS;
2380 tListElem *pEntry,*pFreeElem;
2381 tCsrScanResult *pBssDesc;
2382 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002383
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302384 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002385
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302386 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2387 while( pEntry != NULL)
2388 {
2389 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2390 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2391 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002392 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302393 pFreeElem = pEntry;
2394 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2395 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2396 csrFreeScanResultEntry( pMac, pBssDesc );
2397 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002398 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302399 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2400 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002401
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302402 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002403
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302404 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002405}
2406
Jeff Johnson295189b2012-06-20 16:38:30 -07002407/**
2408 * csrCheck11dChannel
2409 *
2410 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302411 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002412 * compare channel number with given channel list.
2413 *
2414 *LOGIC:
2415 * Check Scan result channel number with CFG channel list
2416 *
2417 *ASSUMPTIONS:
2418 *
2419 *
2420 *NOTE:
2421 *
2422 * @param channelId channel number
2423 * @param pChannelList Pointer to channel list
2424 * @param numChannels Number of channel in channel list
2425 *
2426 * @return Status
2427 */
2428
2429eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2430{
2431 eHalStatus status = eHAL_STATUS_FAILURE;
2432 tANI_U8 i = 0;
2433
2434 for (i = 0; i < numChannels; i++)
2435 {
2436 if(pChannelList[ i ] == channelId)
2437 {
2438 status = eHAL_STATUS_SUCCESS;
2439 break;
2440 }
2441 }
2442 return status;
2443}
2444
2445/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302446 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002447 *
2448 *FUNCTION:
2449 * This function is called from csrApplyCountryInformation function and
2450 * filter scan result based on valid channel list number.
2451 *
2452 *LOGIC:
2453 * Get scan result from scan list and Check Scan result channel number
2454 * with 11d channel list if channel number is found in 11d channel list
2455 * then do not remove scan result entry from scan list
2456 *
2457 *ASSUMPTIONS:
2458 *
2459 *
2460 *NOTE:
2461 *
2462 * @param pMac Pointer to Global MAC structure
2463 *
2464 * @return Status
2465 */
2466
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302467eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002468{
2469 eHalStatus status = eHAL_STATUS_SUCCESS;
2470 tListElem *pEntry,*pTempEntry;
2471 tCsrScanResult *pBssDesc;
2472 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2473
2474 /* Get valid channels list from CFG */
2475 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2476 pMac->roam.validChannelList, &len)))
2477 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302478 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002479 }
2480
2481 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2482 while( pEntry )
2483 {
2484 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302485 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002486 LL_ACCESS_LOCK );
2487 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302488 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002489 {
2490 /* Remove Scan result which does not have 11d channel */
2491 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2492 LL_ACCESS_LOCK ))
2493 {
2494 csrFreeScanResultEntry( pMac, pBssDesc );
2495 }
2496 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302497 else
2498 {
2499 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2500 pBssDesc->Result.BssDescriptor.channelId);
2501 }
2502 pEntry = pTempEntry;
2503 }
2504
2505 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2506 while( pEntry )
2507 {
2508 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2509 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2510 LL_ACCESS_LOCK );
2511 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2512 pMac->roam.validChannelList, len))
2513 {
2514 /* Remove Scan result which does not have 11d channel */
2515 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2516 LL_ACCESS_LOCK ))
2517 {
2518 csrFreeScanResultEntry( pMac, pBssDesc );
2519 }
2520 }
2521 else
2522 {
2523 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2524 pBssDesc->Result.BssDescriptor.channelId);
2525 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002526 pEntry = pTempEntry;
2527 }
2528 return status;
2529}
2530
2531
2532eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2533{
2534 eHalStatus status = eHAL_STATUS_SUCCESS;
2535 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2536 tCsrScanResult *pResult, *pScanResult;
2537 tANI_U32 count = 0;
2538 tListElem *pEntry;
2539 tANI_U32 bssLen, allocLen;
2540
2541 if(phResult)
2542 {
2543 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2544 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302545 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2546 if ( NULL == pRetList )
2547 status = eHAL_STATUS_FAILURE;
2548 else
Jeff Johnson295189b2012-06-20 16:38:30 -07002549 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302550 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002551 csrLLOpen(pMac->hHdd, &pRetList->List);
2552 pRetList->pCurEntry = NULL;
2553 csrLLLock(&pMac->scan.scanResultList);
2554 csrLLLock(&pInList->List);
2555
2556 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2557 while( pEntry )
2558 {
2559 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2560 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2561 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302562 pResult = vos_mem_malloc(allocLen);
2563 if ( NULL == pResult )
2564 status = eHAL_STATUS_FAILURE;
2565 else
2566 status = eHAL_STATUS_SUCCESS;
2567 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002568 {
2569 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2570 count = 0;
2571 break;
2572 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302573 vos_mem_set(pResult, allocLen , 0);
2574 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002575 if( pScanResult->Result.pvIes )
2576 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302577 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
2578 if ( NULL == pResult->Result.pvIes )
2579 status = eHAL_STATUS_FAILURE;
2580 else
2581 status = eHAL_STATUS_SUCCESS;
2582 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002583 {
2584 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05302585 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07002586 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2587 count = 0;
2588 break;
2589 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302590 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
2591 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002592 }
2593 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2594 count++;
2595 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2596 }//while
2597 csrLLUnlock(&pInList->List);
2598 csrLLUnlock(&pMac->scan.scanResultList);
2599
2600 if(HAL_STATUS_SUCCESS(status))
2601 {
2602 if(0 == count)
2603 {
2604 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302605 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002606 status = eHAL_STATUS_E_NULL_VALUE;
2607 }
2608 else if(phResult)
2609 {
2610 *phResult = pRetList;
2611 }
2612 }
2613 }//Allocated pRetList
2614
2615 return (status);
2616}
2617
2618
2619
2620eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2621{
2622 eHalStatus status = eHAL_STATUS_SUCCESS;
2623 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2624
2625 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2626 {
2627 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2628 }
2629 else
2630 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002631 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002632 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002633 tCsrRoamSession *pSession;
2634 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2635 tCsrRoamInfo roamInfo;
2636 tCsrRoamInfo *pRoamInfo = NULL;
2637 tANI_U32 sessionId;
2638 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002639 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Kiet Lam64c1b492013-07-12 13:56:44 +05302640 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002641 pRoamInfo = &roamInfo;
2642 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2643 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2644 pSession = CSR_GET_SESSION(pMac, sessionId);
2645
2646 if(!pSession)
2647 {
2648 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2649 return eHAL_STATUS_FAILURE;
2650 }
2651
2652 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2653 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2654 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2655 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2656 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2657 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2658 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
Kiet Lam64c1b492013-07-12 13:56:44 +05302659 vos_mem_copy(pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2660 vos_mem_copy(&pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002661 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2662 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2663 {
2664 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2665 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2666 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2667 }
2668 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2669 {
2670 vos_sleep( 100 );
2671 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2672 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2673 }
2674
Jeff Johnson295189b2012-06-20 16:38:30 -07002675 }
2676 else
2677 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002678
2679 if( csrIsAnySessionInConnectState( pMac ) )
2680 {
2681 //In case of we are connected, we need to check whether connect status changes
2682 //because scan may also run while connected.
2683 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2684 }
2685 else
2686 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002687 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002688 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002689 }
2690 }
2691
2692 return (status);
2693}
2694
2695
2696
2697void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2698{
2699 int idx, len;
2700 tANI_U8 *pbIe;
2701
2702 //If failed to remove, assuming someone else got it.
2703 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2704 (0 == pNewBssDescr->WscIeLen))
2705 {
2706 idx = 0;
2707 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2708 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2709 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2710 //Save WPS IE if it exists
2711 pNewBssDescr->WscIeLen = 0;
2712 while(idx < len)
2713 {
2714 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2715 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2716 {
2717 //Founrd it
2718 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2719 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302720 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07002721 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2722 }
2723 break;
2724 }
2725 idx += pbIe[1] + 2;
2726 pbIe += pbIe[1] + 2;
2727 }
2728 }
2729}
2730
2731
2732
2733//pIes may be NULL
2734tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302735 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002736{
2737 tListElem *pEntry;
2738
2739 tCsrScanResult *pBssDesc;
2740 tANI_BOOLEAN fRC = FALSE;
2741
2742 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2743 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2744 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2745 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2746
2747 while( pEntry )
2748 {
2749 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2750
2751 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2752 // matches
2753 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07002754 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002755 {
2756 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2757 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2758 // Remove the 'old' entry from the list....
2759 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2760 {
2761 // !we need to free the memory associated with this node
2762 //If failed to remove, assuming someone else got it.
2763 *pSsid = pBssDesc->Result.ssId;
2764 *timer = pBssDesc->Result.timer;
2765 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2766
2767 csrFreeScanResultEntry( pMac, pBssDesc );
2768 }
2769 else
2770 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002771 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002772 }
2773 fRC = TRUE;
2774
2775 // If we found a match, we can stop looking through the list.
2776 break;
2777 }
2778
2779 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2780 }
2781
2782 return fRC;
2783}
2784
2785
2786eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2787 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2788{
2789 eHalStatus status = eHAL_STATUS_FAILURE;
2790 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2791
Jeff Johnson32d95a32012-09-10 13:15:23 -07002792 if(!pSession)
2793 {
2794 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2795 return eHAL_STATUS_FAILURE;
2796 }
2797
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002798 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002799 if( pIes )
2800 {
2801 // check if this is a RSN BSS
2802 if( pIes->RSN.present )
2803 {
2804 // Check if the BSS is capable of doing pre-authentication
2805 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2806 {
2807
2808#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2809 {
2810 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05302811 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002812 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2813 secEvent.encryptionModeMulticast =
2814 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2815 secEvent.encryptionModeUnicast =
2816 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05302817 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07002818 secEvent.authMode =
2819 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2820 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2821 }
2822#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2823
2824 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302825 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2826 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2827 // Bit 0 offirst byte - PreAuthentication Capability
2828 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002829 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302830 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2831 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002832 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302833 else
2834 {
2835 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2836 = eANI_BOOLEAN_FALSE;
2837 }
2838 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002839 }
2840 else
2841 {
2842 status = eHAL_STATUS_FAILURE;
2843 }
2844 }
2845 }
2846
2847 return (status);
2848}
2849
2850//This function checks whether new AP is found for the current connected profile
2851//If it is found, it return the sessionId, else it return invalid sessionID
2852tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2853 tSirBssDescription *pBssDesc,
2854 tDot11fBeaconIEs *pIes)
2855{
2856 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2857 tCsrRoamSession *pSession;
2858 tDot11fBeaconIEs *pIesLocal = pIes;
2859
2860 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2861 {
2862 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2863 {
2864 if( CSR_IS_SESSION_VALID( pMac, i ) )
2865 {
2866 pSession = CSR_GET_SESSION( pMac, i );
2867 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2868 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2869 {
2870 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2871 {
2872 //this new BSS fits the current profile connected
2873 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2874 {
2875 bRet = i;
2876 }
2877 break;
2878 }
2879 }
2880 }
2881 }
2882 if( !pIes )
2883 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302884 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002885 }
2886 }
2887
2888 return (tANI_U8)bRet;
2889}
2890
2891#ifdef FEATURE_WLAN_WAPI
2892eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2893 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2894{
2895 eHalStatus status = eHAL_STATUS_FAILURE;
2896 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2897
Jeff Johnson32d95a32012-09-10 13:15:23 -07002898 if(!pSession)
2899 {
2900 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2901 return eHAL_STATUS_FAILURE;
2902 }
2903
Kiet Lam64c1b492013-07-12 13:56:44 +05302904 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
2905 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002906 if( pIes )
2907 {
2908 // check if this is a WAPI BSS
2909 if( pIes->WAPI.present )
2910 {
2911 // Check if the BSS is capable of doing pre-authentication
2912 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
2913 {
2914
2915 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302916 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
2917 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2918 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07002919 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302920 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
2921 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002922 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302923 else
2924 {
2925 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
2926 = eANI_BOOLEAN_FALSE;
2927 }
2928 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002929 }
2930 else
2931 {
2932 status = eHAL_STATUS_FAILURE;
2933 }
2934 }
2935 }
2936
2937 return (status);
2938}
2939
2940//This function checks whether new AP is found for the current connected profile
2941//if so add to BKIDCandidateList
2942tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
2943 tDot11fBeaconIEs *pIes)
2944{
2945 tANI_BOOLEAN fRC = FALSE;
2946 tDot11fBeaconIEs *pIesLocal = pIes;
2947 tANI_U32 sessionId;
2948 tCsrRoamSession *pSession;
2949
2950 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2951 {
2952 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
2953 {
2954 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
2955 {
2956 pSession = CSR_GET_SESSION( pMac, sessionId );
2957 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
2958 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
2959 {
2960 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
2961 {
2962 //this new BSS fits the current profile connected
2963 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
2964 {
2965 fRC = TRUE;
2966 }
2967 }
2968 }
2969 }
2970 }
2971 if(!pIes)
2972 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302973 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002974 }
2975
2976 }
2977 return fRC;
2978}
2979
2980#endif
2981
2982
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002983static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07002984{
2985 tListElem *pEntry;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302986 tListElem *pEntryTemp;
2987 tListElem *pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -07002988 tCsrScanResult *pBssDescription;
2989 tANI_S8 cand_Bss_rssi;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302990 tANI_S8 rssi_of_current_country;
Jeff Johnson295189b2012-06-20 16:38:30 -07002991 tANI_BOOLEAN fDupBss;
2992#ifdef FEATURE_WLAN_WAPI
2993 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
2994#endif /* FEATURE_WLAN_WAPI */
2995 tDot11fBeaconIEs *pIesLocal = NULL;
2996 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
2997 tAniSSID tmpSsid;
2998 v_TIME_t timer=0;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302999 tCsrBssid bssid_temp = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jeff Johnson295189b2012-06-20 16:38:30 -07003000
3001 tmpSsid.length = 0;
3002 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
Mihir Shetebc866f62014-02-13 16:08:53 +05303003 rssi_of_current_country = pMac->scan.currentCountryRSSI;
Jeff Johnson295189b2012-06-20 16:38:30 -07003004
3005 // remove the BSS descriptions from temporary list
3006 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3007 {
3008 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3009
Arif Hussain24bafea2013-11-15 15:10:03 -08003010 smsLog( pMac, LOGW, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
3011 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003012 pBssDescription->Result.BssDescriptor.channelId,
3013 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3014
3015 //At this time, pBssDescription->Result.pvIes may be NULL
3016 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3017 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3018 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003019 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003020 csrFreeScanResultEntry(pMac, pBssDescription);
3021 continue;
3022 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303023 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003024 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3025 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3026#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3027 && !( eCsrScanGetLfrResult == reason )
3028#endif
3029 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003030 {
3031 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003032 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003033 //Free the resources
3034 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
3035 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303036 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003037 }
3038 csrFreeScanResultEntry(pMac, pBssDescription);
3039 //Continue because there may be duplicated BSS
3040 continue;
3041 }
3042 // check for duplicate scan results
3043 if ( !fDupBss )
3044 {
3045 //Found a new BSS
3046 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3047 &pBssDescription->Result.BssDescriptor, pIesLocal);
3048 if( CSR_SESSION_ID_INVALID != sessionId)
3049 {
3050 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3051 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3052 }
3053 }
3054 else
3055 {
3056 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3057 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3058 {
3059 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3060 //if diff of saved SSID time and current time is less than 1 min to avoid
3061 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3062 //hidden, we may never see it and also to address the requirement of
3063 //When we remove hidden ssid from the profile i.e., forget the SSID via
3064 // GUI that SSID shouldn't see in the profile
3065 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3066 {
3067 pBssDescription->Result.timer = timer;
3068 pBssDescription->Result.ssId = tmpSsid;
3069 }
3070 }
3071 }
3072
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303073 //Find a good AP for 11d info
3074 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003075 {
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303076 if (cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
Jeff Johnson295189b2012-06-20 16:38:30 -07003077 {
3078 // check if country information element is present
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303079 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003080 {
3081 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303082 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3083 " chan= %d, rssi = -%d, countryCode %c%c"),
3084 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3085 pBssDescription->Result.BssDescriptor.channelId,
3086 pBssDescription->Result.BssDescriptor.rssi * (-1),
3087 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3088 //Getting BSSID for best AP in scan result.
Kiet Lamf2f201e2013-11-16 21:24:16 +05303089 vos_mem_copy(bssid_temp,
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303090 pBssDescription->Result.BssDescriptor.bssId, sizeof(tSirMacAddr));
3091
Jeff Johnson295189b2012-06-20 16:38:30 -07003092 }
3093
3094 }
3095 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303096 //get current rssi for BSS from which country code is acquired.
3097 if ( csrIs11dSupported(pMac) && (csrIsMacAddressEqual(pMac,
3098 &pMac->scan.currentCountryBssid,
3099 &pBssDescription->Result.BssDescriptor.bssId) ))
3100 {
3101 smsLog(pMac, LOGW, FL("Information about current country Bssid "
3102 MAC_ADDRESS_STR
3103 " chan= %d, rssi = -%d, countryCode %c%c"),
3104 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3105 pBssDescription->Result.BssDescriptor.channelId,
3106 pBssDescription->Result.BssDescriptor.rssi * (-1),
3107 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3108 rssi_of_current_country = pBssDescription->Result.BssDescriptor.rssi ;
Mihir Shetebc866f62014-02-13 16:08:53 +05303109 pMac->scan.currentCountryRSSI = rssi_of_current_country;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303110 }
3111
Jeff Johnson295189b2012-06-20 16:38:30 -07003112
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003113
Jeff Johnson295189b2012-06-20 16:38:30 -07003114 // append to main list
3115 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303116 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003117 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303118 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003119 }
3120 }
3121
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003122 //we don't need to update CC while connected to an AP which is advertising CC already
3123 if (csrIs11dSupported(pMac))
3124 {
3125 tANI_U32 i;
3126 tCsrRoamSession *pSession;
3127
3128 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3129 {
3130 if (CSR_IS_SESSION_VALID( pMac, i ) )
3131 {
3132 pSession = CSR_GET_SESSION( pMac, i );
3133 if (csrIsConnStateConnected(pMac, i))
3134 {
3135 if (csrIsBssidMatch(pMac, (tCsrBssid *)&pMac->scan.currentCountryBssid,
3136 &pSession->connectedProfile.bssid))
3137 {
3138 smsLog(pMac, LOGW, FL("No need for updating CC, we will"
3139 "continue with current AP's CC"));
3140 goto end;
3141 }
3142 }
3143 }
3144 }
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003145
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003146 // Calculating 30% of current rssi is an idea for not to change
3147 // country code so freq.
3148 if (rssi_of_current_country != -128)
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303149 {
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003150 rssi_of_current_country = rssi_of_current_country
3151 - THIRTY_PERCENT(rssi_of_current_country);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303152 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003153 //if new candidate AP has 30% better RSSI or this is the first time or
3154 //AP aged out of CSR cache or we are in world CC now
krunal soni5f112f02013-11-25 15:00:11 -08003155 if ((rssi_of_current_country <= cand_Bss_rssi &&
3156 rssi_of_current_country != -128) ||
3157 (rssi_of_current_country == -128 &&
3158 pMac->scan.scanProfile.numOfChannels >= MANDATORY_BG_CHANNEL) ||
3159 ('0' == pMac->scan.countryCode11d[ 0 ] &&
3160 '0' == pMac->scan.countryCode11d[ 1 ]))
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003161 {
3162 csrLLLock(&pMac->scan.scanResultList);
3163 pEntryTemp = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
3164 while ( NULL != pEntryTemp)
3165 {
3166 pNext = csrLLNext(&pMac->scan.scanResultList, pEntryTemp,
3167 LL_ACCESS_NOLOCK);
3168 pBssDescription = GET_BASE_ADDR( pEntryTemp, tCsrScanResult, Link );
3169 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3170 // Need to traverse whole scan list to get description for best 11d AP.
3171 if (csrIsMacAddressEqual(pMac, (tCsrBssid *)&bssid_temp,
3172 (tCsrBssid *) pBssDescription->Result.BssDescriptor.bssId))
3173 {
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003174 // Best AP should be passed to update reg domain.
3175 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
3176 pIesLocal, eANI_BOOLEAN_TRUE );
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003177 //this check is to avoid the case of invalid CC set via 11d
3178 //In that case we move to world CC & we are open to any new
3179 //valid CC we can get during scan
3180 if(( '0' != pMac->scan.countryCode11d[ 0 ] && '0' != pMac->scan.countryCode11d[ 1 ] ))
3181 {
Kiet Lamf2f201e2013-11-16 21:24:16 +05303182 vos_mem_copy(pMac->scan.currentCountryBssid,
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003183 bssid_temp, sizeof(tSirMacAddr));
3184 }
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003185 break;
3186 }
3187 pEntryTemp = pNext;
3188 }
3189 csrLLUnlock(&pMac->scan.scanResultList);
3190 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303191 }
3192
3193
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003194end:
3195 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003196 // a good enough AP with the 11d info from the scan results then no need to
3197 // get into ambiguous state
3198 if(pMac->scan.fAmbiguous11dInfoFound)
3199 {
3200 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
3201 {
3202 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3203 }
3204 }
3205
3206#ifdef FEATURE_WLAN_WAPI
3207 if(fNewWapiBSSForCurConnection)
3208 {
3209 //remember it first
3210 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3211 }
3212#endif /* FEATURE_WLAN_WAPI */
3213
3214 return;
3215}
3216
3217
3218static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3219 tDot11fBeaconIEs *pIes)
3220{
3221 tCsrScanResult *pCsrBssDescription = NULL;
3222 tANI_U32 cbBSSDesc;
3223 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07003224
3225 // figure out how big the BSS description is (the BSSDesc->length does NOT
3226 // include the size of the length field itself).
3227 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3228
3229 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3230
Kiet Lam64c1b492013-07-12 13:56:44 +05303231 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3232 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003233 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303234 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003235 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303236 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003237#if defined(VOSS_ENSBALED)
3238 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3239#endif
3240 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3241 }
3242
3243 return( pCsrBssDescription );
3244}
3245
3246// Append a Bss Description...
3247tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3248 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003249 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003250{
3251 tCsrScanResult *pCsrBssDescription = NULL;
3252 tAniSSID tmpSsid;
3253 v_TIME_t timer = 0;
3254 int result;
3255
3256 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003257 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003258 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3259 if (result && (pCsrBssDescription != NULL))
3260 {
3261 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3262 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3263 {
3264 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3265 //if diff of saved SSID time and current time is less than 1 min to avoid
3266 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3267 //hidden, we may never see it and also to address the requirement of
3268 //When we remove hidden ssid from the profile i.e., forget the SSID via
3269 // GUI that SSID shouldn't see in the profile
3270 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3271 {
3272 pCsrBssDescription->Result.ssId = tmpSsid;
3273 pCsrBssDescription->Result.timer = timer;
3274 }
3275 }
3276 }
3277
3278
3279 return( pCsrBssDescription );
3280}
3281
3282
3283
3284void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3285{
3286 tCsrChannelPowerInfo *pChannelSet;
3287 tListElem *pEntry;
3288
3289 csrLLLock(pChannelList);
3290 // Remove the channel sets from the learned list and put them in the free list
3291 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3292 {
3293 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3294 if( pChannelSet )
3295 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303296 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003297 }
3298 }
3299 csrLLUnlock(pChannelList);
3300 return;
3301}
3302
3303
3304/*
3305 * Save the channelList into the ultimate storage as the final stage of channel
3306 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3307 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003308eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003309{
3310 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3311 tSirMacChanInfo *pChannelInfo;
3312 tCsrChannelPowerInfo *pChannelSet;
3313 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3314 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003315
3316 pChannelInfo = channelTable;
3317 // atleast 3 bytes have to be remaining -- from "countryString"
3318 while ( i-- )
3319 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303320 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3321 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003322 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303323 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003324 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3325 pChannelSet->numChannels = pChannelInfo->numChannels;
3326
3327 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003328 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003329 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003330
Jeff Johnson295189b2012-06-20 16:38:30 -07003331 {
3332 pChannelSet->interChannelOffset = 1;
3333 f2GHzInfoFound = TRUE;
3334 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003335 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003336 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003337 {
3338 pChannelSet->interChannelOffset = 4;
3339 f2GHzInfoFound = FALSE;
3340 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003341 else
3342 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003343 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003344 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303345 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003346 return eHAL_STATUS_FAILURE;
3347 }
3348
Jeff Johnson295189b2012-06-20 16:38:30 -07003349 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3350
3351 if( f2GHzInfoFound )
3352 {
3353 if( !f2GListPurged )
3354 {
3355 // purge previous results if found new
3356 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3357 f2GListPurged = TRUE;
3358 }
3359
3360 if(CSR_IS_OPERATING_BG_BAND(pMac))
3361 {
3362 // add to the list of 2.4 GHz channel sets
3363 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3364 }
3365 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003366 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003367 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303368 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003369 }
3370 }
3371 else
3372 {
3373 // 5GHz info found
3374 if( !f5GListPurged )
3375 {
3376 // purge previous results if found new
3377 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3378 f5GListPurged = TRUE;
3379 }
3380
3381 if(CSR_IS_OPERATING_A_BAND(pMac))
3382 {
3383 // add to the list of 5GHz channel sets
3384 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3385 }
3386 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003387 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003388 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303389 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003390 }
3391 }
3392 }
3393
3394 pChannelInfo++; // move to next entry
3395 }
3396
Jeff Johnsone7245742012-09-05 17:12:55 -07003397 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003398}
3399
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303400static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3401{
3402 tSirMbMsg *pMsg;
3403 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003404
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303405 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303406 pMsg = vos_mem_malloc(msgLen);
3407 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303408 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303409 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303410 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3411 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3412 palSendMBMessage(pMac->hHdd, pMsg);
3413 }
3414}
Jeff Johnson295189b2012-06-20 16:38:30 -07003415
3416void csrApplyPower2Current( tpAniSirGlobal pMac )
3417{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003418 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003419 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3420 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3421}
3422
3423
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003424void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003425{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303426 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003427 eNVChannelEnabledType channelEnabledType;
3428 tANI_U8 numChannels = 0;
3429 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303430 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003431 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303432
Jeff Johnson295189b2012-06-20 16:38:30 -07003433 if( pChannelList->numChannels )
3434 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303435 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3436 {
3437 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3438 VOS_COUNTRY_CODE_LEN))
3439 {
3440 countryIndex = count;
3441 break;
3442 }
3443 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003444 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3445 /* If user doesn't want to scan the DFS channels lets trim them from
3446 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303447 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003448 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303449 channelIgnore = FALSE;
3450 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3451 {
3452 channelEnabledType =
3453 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3454 }
3455 else
3456 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003457 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303458 }
3459 if( NV_CHANNEL_ENABLE == channelEnabledType )
3460 {
3461 if( countryIndex != -1 )
3462 {
3463 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3464 {
3465 if( pChannelList->channelList[i] ==
3466 countryIgnoreList[countryIndex].channelList[j] )
3467 {
3468 channelIgnore = TRUE;
3469 break;
3470 }
3471 }
3472 }
3473 if( FALSE == channelIgnore )
3474 {
3475 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3476 numChannels++;
3477 }
3478 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003479 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303480 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003481 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3482 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303483 // build a scan list based on the channel list : channel# + active/passive scan
3484 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303485 /*Send msg to Lim to clear DFS channel list */
3486 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003487#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003488 if (updateRiva)
3489 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003490 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003491 // Send HAL UpdateScanParams message
3492 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3493 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003494#endif // FEATURE_WLAN_SCAN_PNO
3495 }
3496 else
3497 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003498 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003499 }
3500 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3501 csrSetCfgCountryCode(pMac, countryCode);
3502}
3503
3504
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003505void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003506{
3507 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3508 {
3509
3510#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3511 {
3512 vos_log_802_11d_pkt_type *p11dLog;
3513 int Index;
3514
3515 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3516 if(p11dLog)
3517 {
3518 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303519 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003520 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3521 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3522 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303523 vos_mem_copy(p11dLog->Channels,
3524 pMac->scan.base20MHzChannels.channelList,
3525 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003526 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3527 {
3528 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3529 }
3530 }
3531 if(!pMac->roam.configParam.Is11dSupportEnabled)
3532 {
3533 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3534 }
3535 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3536 {
3537 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3538 }
3539 else
3540 {
3541 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3542 }
3543 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3544 }
3545 }
3546#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3547
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003548 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3549 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3550
Jeff Johnson295189b2012-06-20 16:38:30 -07003551 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3552 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3553 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003554 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003555 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303556 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003557 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3558 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3559 }
3560
3561 return;
3562}
3563
3564
3565eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3566{
3567 eHalStatus status = eHAL_STATUS_SUCCESS;
3568 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3569
3570 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303571 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3572 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003573 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003574 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3575 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003576 {
3577 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003578 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003579 }
3580 if(pfRestartNeeded)
3581 {
3582 *pfRestartNeeded = fRestart;
3583 }
3584
3585 return (status);
3586}
3587
3588
3589eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3590{
3591 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3592 v_REGDOMAIN_t domainId;
3593
3594 if(pCountry)
3595 {
Kiet Lam6c583332013-10-14 05:37:09 +05303596 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07003597 if(HAL_STATUS_SUCCESS(status))
3598 {
3599 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3600 if(HAL_STATUS_SUCCESS(status))
3601 {
3602 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3603 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303604 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003605 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3606 {
3607 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3608 csrSetCfgCountryCode(pMac, pCountry);
3609 }
3610 }
3611 }
3612 }
3613
3614 return (status);
3615}
3616
3617
3618
3619//caller allocated memory for pNumChn and pChnPowerInfo
3620//As input, *pNumChn has the size of the array of pChnPowerInfo
3621//Upon return, *pNumChn has the number of channels assigned.
3622void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3623 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3624{
3625 tListElem *pEntry;
3626 tANI_U32 chnIdx = 0, idx;
3627 tCsrChannelPowerInfo *pChannelSet;
3628
3629 //Get 2.4Ghz first
3630 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3631 while( pEntry && (chnIdx < *pNumChn) )
3632 {
3633 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3634 if ( 1 != pChannelSet->interChannelOffset )
3635 {
3636 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3637 {
3638 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3639 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3640 }
3641 }
3642 else
3643 {
3644 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3645 {
3646 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3647 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3648 }
3649 }
3650
3651 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3652 }
3653 *pNumChn = chnIdx;
3654
3655 return ;
3656}
3657
3658
3659
3660void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3661{
3662 v_REGDOMAIN_t domainId;
3663 eHalStatus status = eHAL_STATUS_SUCCESS;
3664
3665 do
3666 {
3667 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3668 if( pMac->scan.fAmbiguous11dInfoFound )
3669 {
3670 // ambiguous info found
3671 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05303672 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3673 pMac, pMac->scan.countryCodeCurrent,
3674 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003675 {
3676 pMac->scan.domainIdCurrent = domainId;
3677 }
3678 else
3679 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003680 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003681 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3682 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003683 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003684 break;
3685 }
3686 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05303687 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3688 pMac, pMac->scan.countryCode11d,
3689 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003690 {
3691 //Check whether we need to enforce default domain
3692 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3693 (pMac->scan.domainIdCurrent == domainId) )
3694 {
3695
3696#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3697 {
3698 vos_log_802_11d_pkt_type *p11dLog;
3699 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3700 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3701
3702 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3703 if(p11dLog)
3704 {
3705 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303706 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003707 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3708 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3709 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303710 vos_mem_copy(p11dLog->Channels,
3711 pMac->scan.channels11d.channelList,
3712 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003713 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3714 &nChnInfo, chnPwrInfo);
3715 nTmp = nChnInfo;
3716 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3717 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3718 &nChnInfo, &chnPwrInfo[nTmp]);
3719 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3720 {
3721 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3722 {
3723 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3724 {
3725 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3726 break;
3727 }
3728 }
3729 }
3730 }
3731 if(!pMac->roam.configParam.Is11dSupportEnabled)
3732 {
3733 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3734 }
3735 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3736 {
3737 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3738 }
3739 else
3740 {
3741 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3742 }
3743 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3744 }
3745 }
3746#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3747 if(pMac->scan.domainIdCurrent != domainId)
3748 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003749 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3750 pMac->scan.domainIdCurrent, domainId);
Abhishek Singha306a442013-11-07 18:39:01 +05303751 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003752 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003753 if (status != eHAL_STATUS_SUCCESS)
3754 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003755 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003756 }
3757 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05303758#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05303759 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
3760 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05303761#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003762 // switch to active scans using this new channel list
3763 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3764 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3765 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3766 }
3767 }
3768
3769 } while( 0 );
3770
3771 return;
3772}
3773
3774
3775
3776tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3777 tANI_BOOLEAN fForce)
3778{
3779 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3780 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05303781 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003782 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003783
3784 // convert to UPPER here so we are assured the strings are always in upper case.
3785 for( i = 0; i < 3; i++ )
3786 {
3787 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3788 }
3789
3790 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3791 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3792 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3793 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3794 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05303795 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
3796 pCountryCode,
3797 &regd,
3798 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003799 {
3800 // Check the enforcement first
3801 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3802 {
3803 fUnknownCountryCode = TRUE;
3804 }
3805 else
3806 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003807 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003808 }
3809 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003810 //right now, even if we don't find the CC in driver we set to world. Making
3811 //sure countryCode11d doesn't get updated with the invalid CC, instead
3812 //reflect the world CC
3813 else if (REGDOMAIN_WORLD == regd)
3814 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003815 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003816 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003817
3818 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3819 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3820 // if we see a 0 in this third character, let's change it to a ' '.
3821 if ( 0 == pCountryCode[ 2 ] )
3822 {
3823 pCountryCode[ 2 ] = ' ';
3824 }
3825
3826 if( !fUnknownCountryCode )
3827 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303828 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07003829
3830
3831 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3832 || (fForce))
3833 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003834 if (!fCountryNotPresentInDriver)
3835 {
3836 // this is the first .11d information
3837 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05303838 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003839
3840 }
3841 else
3842 {
3843 pMac->scan.countryCode11d[0] = '0';
3844 pMac->scan.countryCode11d[1] = '0';
3845 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003846 }
3847 }
3848
3849 return( fCountryStringChanged );
3850}
3851
3852
3853void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3854{
3855 tANI_U32 Index, count=0;
3856 tSirMacChanInfo *pChanInfo;
3857 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003858 tANI_S32 maxChannelIndex;
3859
3860 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3861 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003862
Kiet Lam64c1b492013-07-12 13:56:44 +05303863 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3864 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07003865 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303866 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003867 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003868 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003869 {
3870 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3871 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3872 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003873 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3874 {
3875 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3876 break;
3877 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003878 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3879 pChanInfo->numChannels = 1;
3880 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3881 pChanInfo++;
3882 count++;
3883 }
3884 }
3885 if(count)
3886 {
3887 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3888 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303889 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07003890 }
3891}
3892
3893
3894void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3895{
3896 tANI_BOOLEAN fPopulate5GBand = FALSE;
3897
3898 do
3899 {
3900 // if this is not a dual band product, then we don't need to set the opposite
3901 // band info. We only work in one band so no need to look in the other band.
3902 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3903 // if we found channel info on the 5.0 band and...
3904 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3905 {
3906 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05303907 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003908 fPopulate5GBand = FALSE;
3909 }
3910 else
3911 {
3912 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3913 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05303914 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003915 fPopulate5GBand = TRUE;
3916 }
3917 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3918
3919 } while( 0 );
3920}
3921
3922
3923tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3924{
3925 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3926 tANI_U32 i;
3927
3928 //Make sure it is a channel that is in our supported list.
3929 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3930 {
3931 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3932 {
3933 fRet = eANI_BOOLEAN_TRUE;
3934 break;
3935 }
3936 }
3937
3938 //If it is configured to limit a set of the channels
3939 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3940 {
3941 fRet = eANI_BOOLEAN_FALSE;
3942 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3943 {
3944 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3945 {
3946 fRet = eANI_BOOLEAN_TRUE;
3947 break;
3948 }
3949 }
3950 }
3951
3952 return (fRet);
3953}
3954
3955
3956
3957//bSize specify the buffer size of pChannelList
3958tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3959{
3960 tANI_U8 i, j = 0, chnId;
3961
3962 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3963 for( i = 0; i < bSize; i++ )
3964 {
3965 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3966 if ( csrIsSupportedChannel( pMac, chnId ) )
3967 {
3968 pChannelList[j++] = chnId;
3969 }
3970 }
3971
3972 return (j);
3973}
3974
3975
3976
3977//bSize -- specify the buffer size of pChannelList
3978void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3979 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3980{
3981 tListElem *pEntry;
3982 tCsrChannelPowerInfo *pChannelSet;
3983 tANI_U8 numChannels;
3984 tANI_U8 *pChannels;
3985
3986 if( pChannelSetList && pChannelList && pNumChannels )
3987 {
3988 pChannels = pChannelList;
3989 *pNumChannels = 0;
3990 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3991 while( pEntry )
3992 {
3993 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3994 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3995 pChannels += numChannels;
3996 *pNumChannels += numChannels;
3997 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3998 }
3999 }
4000}
4001
4002
4003/*
4004 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4005*/
4006tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4007 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
4008{
Jeff Johnson295189b2012-06-20 16:38:30 -07004009 eHalStatus status;
4010 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4011 v_REGDOMAIN_t domainId;
4012 tDot11fBeaconIEs *pIesLocal = pIes;
4013
Jeff Johnson295189b2012-06-20 16:38:30 -07004014 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4015 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004016
4017 do
4018 {
4019 // check if .11d support is enabled
4020 if( !csrIs11dSupported( pMac ) ) break;
4021 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
4022 {
4023 break;
4024 }
4025 // check if country information element is present
4026 if(!pIesLocal->Country.present)
4027 {
4028 //No country info
4029 break;
4030 }
4031
4032 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
4033 {
4034 // country string changed, this should not happen
4035 //Need to check whether we care about this BSS' domain info
4036 //If it doesn't match of the connected profile or roaming profile, let's ignore it
4037 tANI_U32 i;
4038 tCsrRoamSession *pSession;
4039
4040 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4041 {
4042 if( CSR_IS_SESSION_VALID( pMac, i ) )
4043 {
4044 pSession = CSR_GET_SESSION( pMac, i );
4045 if(pSession->pCurRoamProfile)
4046 {
4047 tCsrScanResultFilter filter;
4048
Kiet Lam64c1b492013-07-12 13:56:44 +05304049 vos_mem_set(&filter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004050 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
4051 if(HAL_STATUS_SUCCESS(status))
4052 {
4053 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
4054 //Free the resource first
4055 csrFreeScanFilter( pMac, &filter );
4056 if(fMatch)
4057 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08004058 smsLog(pMac, LOGW, "Matching roam profile "
4059 "BSSID " MAC_ADDRESS_STR
4060 " causing ambiguous domain info",
4061 MAC_ADDR_ARRAY(pSirBssDesc->bssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07004062 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4063 break;
4064 }
4065 }
4066 }
4067 else if( csrIsConnStateConnected(pMac, i))
4068 {
4069 //Reach here only when the currention is base on no profile.
4070 //User doesn't give profile and just connect to anything.
4071 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
4072 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08004073 smsLog(pMac, LOGW, "Matching connect profile BSSID "
4074 MAC_ADDRESS_STR
4075 " causing ambiguous domain info",
4076 MAC_ADDR_ARRAY(pSirBssDesc->bssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07004077 //Tush
4078 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4079 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
4080 &pSession->connectedProfile.bssid))
4081 {
4082 //AP changed the 11d info on the fly, modify cfg
4083 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4084 fRet = eANI_BOOLEAN_TRUE;
4085 }
4086 break;
4087 }
4088 }
4089 } //valid session
4090 } //for
4091 if ( i == CSR_ROAM_SESSION_MAX )
4092 {
4093 //Check whether we can use this country's 11d information
4094 if( !pMac->roam.configParam.fEnforceDefaultDomain )
4095 {
4096 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4097 }
4098 else
4099 {
4100 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
4101 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
Kiet Lam6c583332013-10-14 05:37:09 +05304102 pMac, pIesLocal->Country.country, &domainId,
4103 COUNTRY_QUERY)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004104 ( domainId == pMac->scan.domainIdCurrent ) )
4105 {
4106 //Two countries in the same domain
4107 }
4108 }
4109 }
Kiet Lam6c583332013-10-14 05:37:09 +05304110#ifdef CONFIG_ENABLE_LINUX_REG
4111 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country,
4112 &domainId, COUNTRY_IE);
4113#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004114 }
4115 else //Tush
4116 {
4117 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
4118 }
4119
4120 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
4121 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
4122 {
4123 tANI_U8 iC;
4124 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
4125
4126 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
4127 {
4128 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
4129 {
4130 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
4131 }
4132 }
4133 }
Jeff Johnsonafeb9582013-11-22 18:39:00 -08004134 smsLog(pMac, LOG3, FL(" %d sets each one is %zu"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnsone7245742012-09-05 17:12:55 -07004135
Jeff Johnson295189b2012-06-20 16:38:30 -07004136 // set the indicator of the channel where the country IE was found...
4137 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Kiet Lam6c583332013-10-14 05:37:09 +05304138#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lam8d985a02013-10-11 03:39:41 +05304139 status = csrGetRegulatoryDomainForCountry(pMac,
Kiet Lam6c583332013-10-14 05:37:09 +05304140 pIesLocal->Country.country, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304141 if ( status != eHAL_STATUS_SUCCESS )
4142 {
4143 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4144 fRet = eANI_BOOLEAN_FALSE;
4145 break;
4146 }
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004147 // Checking for Domain Id change
4148 if ( domainId != pMac->scan.domainIdCurrent )
4149 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304150 vos_mem_copy(pMac->scan.countryCode11d,
4151 pIesLocal->Country.country,
4152 sizeof( pMac->scan.countryCode11d ) );
4153 /* Set Current Country code and Current Regulatory domain */
4154 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4155 if (eHAL_STATUS_SUCCESS != status)
4156 {
4157 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4158 fRet = eANI_BOOLEAN_FALSE;
4159 return fRet;
4160 }
4161 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4162 vos_mem_copy(pMac->scan.countryCodeCurrent,
4163 pIesLocal->Country.country, WNI_CFG_COUNTRY_CODE_LEN);
4164 //Simply set it to cfg.
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304165 csrSetCfgCountryCode(pMac, pIesLocal->Country.country);
Kiet Lam8d985a02013-10-11 03:39:41 +05304166
4167 /* overwrite the defualt country code */
4168 vos_mem_copy(pMac->scan.countryCodeDefault,
4169 pMac->scan.countryCodeCurrent,
4170 WNI_CFG_COUNTRY_CODE_LEN);
4171 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304172 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304173 if ( status != eHAL_STATUS_SUCCESS )
4174 {
4175 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4176 fRet = eANI_BOOLEAN_FALSE;
4177 return fRet;
4178 }
4179 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304180 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304181 /* get the channels based on new cc */
4182 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004183
Kiet Lam8d985a02013-10-11 03:39:41 +05304184 if ( status != eHAL_STATUS_SUCCESS )
4185 {
4186 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4187 fRet = eANI_BOOLEAN_FALSE;
4188 return fRet;
4189 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004190
Kiet Lam8d985a02013-10-11 03:39:41 +05304191 /* reset info based on new cc, and we are done */
4192 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304193 /* Regulatory Domain Changed, Purge Only scan result
4194 * which does not have channel number belong to 11d
4195 * channel list
4196 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304197 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304198 }
Kiet Lam6c583332013-10-14 05:37:09 +05304199#endif
4200 fRet = eANI_BOOLEAN_TRUE;
4201
Jeff Johnson295189b2012-06-20 16:38:30 -07004202 } while( 0 );
4203
4204 if( !pIes && pIesLocal )
4205 {
4206 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304207 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07004208 }
4209
4210 return( fRet );
4211}
4212
4213
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004214static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004215{
4216 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4217 // will set this to the channel where an .11d beacon is seen
4218 pMac->scan.channelOf11dInfo = 0;
4219 // if we get any ambiguous .11d information then this will be set to TRUE
4220 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4221 //Tush
4222 // if we get any ambiguous .11d information, then this will be set to TRUE
4223 // only if the applied 11d info could be found in one of the scan results
4224 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4225 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004226 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004227}
4228
4229
4230void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4231{
4232 switch (pCommand->u.scanCmd.reason)
4233 {
4234 case eCsrScanSetBGScanParam:
4235 case eCsrScanAbortBgScan:
4236 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4237 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304238 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004239 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4240 }
4241 break;
4242 case eCsrScanBGScanAbort:
4243 case eCsrScanBGScanEnable:
4244 case eCsrScanGetScanChnInfo:
4245 break;
4246 case eCsrScanAbortNormalScan:
4247 default:
4248 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4249 break;
4250 }
4251 if(pCommand->u.scanCmd.pToRoamProfile)
4252 {
4253 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304254 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004255 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304256 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004257}
4258
4259
4260tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4261{
4262 tANI_U32 index11dChannels, index;
4263 tANI_U32 indexCurrentChannels;
4264 tANI_BOOLEAN fChannelAlreadyScanned;
4265 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4266
4267 *pcChannels = 0;
4268 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4269 {
4270 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4271 {
4272 //Find the channel index where we found the 11d info
4273 for(index = 0; index < len; index++)
4274 {
4275 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4276 break;
4277 }
4278 //check whether we found the channel index
4279 if(index < len)
4280 {
4281 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4282 // NOT in the current channel list. This gives us a list of the new channels that have not been
4283 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4284 // initially.
4285 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4286 {
4287 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4288
4289 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4290 {
4291 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4292 {
4293 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4294 break;
4295 }
4296 }
4297
4298 if ( !fChannelAlreadyScanned )
4299 {
4300 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4301 ( *pcChannels )++;
4302 }
4303 }
4304 }
4305 }//GetCFG
4306 }
4307 return( *pcChannels );
4308}
4309
4310
4311eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4312{
4313 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4314
4315 switch( pCommand->u.scanCmd.reason )
4316 {
4317 case eCsrScan11d1:
4318 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4319 break;
4320 case eCsrScan11d2:
4321 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4322 break;
4323 case eCsrScan11dDone:
4324 NextCommand = eCsrNext11dScanComplete;
4325 break;
4326 case eCsrScanLostLink1:
4327 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4328 break;
4329 case eCsrScanLostLink2:
4330 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4331 break;
4332 case eCsrScanLostLink3:
4333 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4334 break;
4335 case eCsrScanForSsid:
4336 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4337 break;
4338 case eCsrScanForCapsChange:
4339 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4340 break;
4341 case eCsrScanIdleScan:
4342 NextCommand = eCsrNextIdleScanComplete;
4343 break;
4344 default:
4345 NextCommand = eCsrNextScanNothing;
4346 break;
4347 }
4348 return( NextCommand );
4349}
4350
4351
4352//Return whether the pCommand is finished.
4353tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4354{
4355 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4356
4357 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004358 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004359 pCommand->u.scanCmd.reason = eCsrScan11d2;
4360 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4361 {
4362 fRet = eANI_BOOLEAN_FALSE;
4363 }
4364
4365 return (fRet);
4366}
4367
4368
4369tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4370{
4371 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4372 tANI_U8 *pChannels;
4373 tANI_U8 cChannels;
4374
Kiet Lam64c1b492013-07-12 13:56:44 +05304375 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4376 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004377 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304378 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004379 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4380 {
4381 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4382 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4383 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304384 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004385 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004386 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304387 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4388 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004389 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304390 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4391 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004392 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4393 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4394 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4395 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4396 {
4397 //Reuse the same command buffer
4398 fRet = eANI_BOOLEAN_FALSE;
4399 }
4400 }
4401 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304402 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004403 }
4404
4405 return (fRet);
4406}
4407
4408//Return whether the command should be removed
4409tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4410{
4411 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4412 tListElem *pEntry;
4413 tSmeCmd *pCommand;
4414 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4415 tANI_BOOLEAN fSuccess;
4416
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304417 if (pMac->fScanOffload)
4418 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4419 else
4420 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004421
4422 if ( pEntry )
4423 {
4424 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4425
4426 // If the head of the queue is Active and it is a SCAN command, remove
4427 // and put this on the Free queue.
4428 if ( eSmeCommandScan == pCommand->command )
4429 {
4430 tANI_U32 sessionId = pCommand->sessionId;
4431
4432 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4433 {
4434 fSuccess = eANI_BOOLEAN_FALSE;
4435 }
4436 else
4437 {
4438 //pMac->scan.tempScanResults is not empty meaning the scan found something
4439 //This check only valid here because csrSaveScanresults is not yet called
4440 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4441 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05304442 if (pCommand->u.scanCmd.abortScanDueToBandChange)
4443 {
4444 /*
4445 * Scan aborted due to band change
4446 * The scan results need to be flushed
4447 */
4448 if (pCommand->u.scanCmd.callback
4449 != pMac->scan.callback11dScanDone)
4450 {
4451 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
4452 "results may belong to wrong band"));
4453 csrScanFilterResults(pMac);
4454 }
4455 else
4456 {
4457 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
4458 " results"));
4459 }
4460 pCommand->u.scanCmd.abortScanDueToBandChange
4461 = eANI_BOOLEAN_FALSE;
4462 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004463 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004464
4465#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4466 {
4467 vos_log_scan_pkt_type *pScanLog = NULL;
4468 tScanResultHandle hScanResult;
4469 tCsrScanResultInfo *pScanResult;
4470 tDot11fBeaconIEs *pIes;
4471 int n = 0, c = 0;
4472
4473 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4474 if(pScanLog)
4475 {
4476 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4477 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4478 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4479 {
4480 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4481 }
4482 else
4483 {
4484 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4485 {
4486 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4487 }
4488 else
4489 {
4490 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4491 }
4492 }
4493 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4494 {
4495 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4496 {
4497 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4498 {
4499 if( n < VOS_LOG_MAX_NUM_BSSID )
4500 {
4501 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4502 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004503 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004504 break;
4505 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304506 vos_mem_copy(pScanLog->bssid[n],
4507 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004508 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4509 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304510 vos_mem_copy(pScanLog->ssid[n],
4511 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004512 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304513 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004514 n++;
4515 }
4516 c++;
4517 }
4518 pScanLog->numSsid = (v_U8_t)n;
4519 pScanLog->totalSsid = (v_U8_t)c;
4520 csrScanResultPurge(pMac, hScanResult);
4521 }
4522 }
4523 else
4524 {
4525 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4526 }
4527 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4528 }
4529 }
4530#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4531
4532 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4533 //We reuse the command here instead reissue a new command
4534 switch(NextCommand)
4535 {
4536 case eCsrNext11dScan1Success:
4537 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004538 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004539 // if we found country information, no need to continue scanning further, bail out
4540 fRemoveCommand = eANI_BOOLEAN_TRUE;
4541 NextCommand = eCsrNext11dScanComplete;
4542 break;
4543 case eCsrNext11dScan1Failure:
4544 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4545 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4546 //we clear the "old" 11d info and give it once more chance
4547 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4548 if(fRemoveCommand)
4549 {
4550 NextCommand = eCsrNext11dScanComplete;
4551 }
4552 break;
4553 case eCsrNextLostLinkScan1Success:
4554 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4555 {
4556 csrScanHandleFailedLostlink1(pMac, sessionId);
4557 }
4558 break;
4559 case eCsrNextLostLinkScan2Success:
4560 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4561 {
4562 csrScanHandleFailedLostlink2(pMac, sessionId);
4563 }
4564 break;
4565 case eCsrNextLostLinkScan3Success:
4566 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4567 {
4568 csrScanHandleFailedLostlink3(pMac, sessionId);
4569 }
4570 break;
4571 case eCsrNextLostLinkScan1Failed:
4572 csrScanHandleFailedLostlink1(pMac, sessionId);
4573 break;
4574 case eCsrNextLostLinkScan2Failed:
4575 csrScanHandleFailedLostlink2(pMac, sessionId);
4576 break;
4577 case eCsrNextLostLinkScan3Failed:
4578 csrScanHandleFailedLostlink3(pMac, sessionId);
4579 break;
4580 case eCsrNexteScanForSsidSuccess:
4581 csrScanHandleSearchForSSID(pMac, pCommand);
4582 break;
4583 case eCsrNexteScanForSsidFailure:
4584 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4585 break;
4586 case eCsrNextIdleScanComplete:
4587 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4588 break;
4589 case eCsrNextCapChangeScanComplete:
4590 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4591 break;
4592 default:
4593
4594 break;
4595 }
4596 }
4597 else
4598 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004599 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004600 fRemoveCommand = eANI_BOOLEAN_FALSE;
4601 }
4602 }
4603 else
4604 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004605 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004606 fRemoveCommand = eANI_BOOLEAN_FALSE;
4607 }
4608
4609 return( fRemoveCommand );
4610}
4611
4612
4613
4614static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4615 tSirBssDescription *pSirBssDescr,
4616 tDot11fBeaconIEs *pIes)
4617{
4618 tListElem *pEntry;
4619 tCsrScanResult *pCsrBssDescription;
4620
4621 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4622 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4623 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4624 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4625 while( pEntry )
4626 {
4627 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4628
4629 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4630 // matches
4631
4632 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004633 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004634 {
4635 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4636 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4637
4638 // Remove the 'old' entry from the list....
4639 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4640 {
4641 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4642 // we need to free the memory associated with this node
4643 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4644 }
4645
4646 // If we found a match, we can stop looking through the list.
4647 break;
4648 }
4649
4650 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4651 }
4652}
4653
4654
4655
4656//Caller allocated memory pfNewBssForConn to return whether new candidate for
4657//current connection is found. Cannot be NULL
4658tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4659 tSirBssDescription *pBSSDescription,
4660 tDot11fBeaconIEs *pIes)
4661{
4662 tCsrScanResult *pCsrBssDescription = NULL;
4663 tANI_U32 cbBSSDesc;
4664 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004665
4666 // figure out how big the BSS description is (the BSSDesc->length does NOT
4667 // include the size of the length field itself).
4668 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4669
4670 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4671
Kiet Lam64c1b492013-07-12 13:56:44 +05304672 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4673 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004674 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304675 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004676 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304677 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004678 //Save SSID separately for later use
4679 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4680 {
4681 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004682 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004683 if (len > SIR_MAC_MAX_SSID_LENGTH)
4684 {
4685 // truncate to fit in our struct
4686 len = SIR_MAC_MAX_SSID_LENGTH;
4687 }
4688 pCsrBssDescription->Result.ssId.length = len;
4689 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304690 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004691 }
4692 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4693 }
4694
4695 return( pCsrBssDescription );
4696}
4697
4698
4699
4700
4701tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004702 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004703{
4704 tANI_BOOLEAN fMatch = FALSE;
4705 tSirMacCapabilityInfo *pCap1, *pCap2;
4706 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004707 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004708
4709 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4710 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4711 if(pCap1->ess == pCap2->ess)
4712 {
4713 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004714 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004715 (fForced || (pSirBssDesc1->channelId == pSirBssDesc2->channelId)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004716 {
4717 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004718 // Check for SSID match, if exists
4719 do
4720 {
4721 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4722 {
4723 break;
4724 }
4725 if( NULL == pIesTemp )
4726 {
4727 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4728 {
4729 break;
4730 }
4731 }
4732 if(pIes1->SSID.present && pIesTemp->SSID.present)
4733 {
4734 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4735 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4736 }
4737 }while(0);
4738
Jeff Johnson295189b2012-06-20 16:38:30 -07004739 }
4740 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4741 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004742
4743 do
4744 {
4745 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4746 {
4747 break;
4748 }
4749 if( NULL == pIesTemp )
4750 {
4751 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4752 {
4753 break;
4754 }
4755 }
4756 //Same channel cannot have same SSID for different IBSS
4757 if(pIes1->SSID.present && pIesTemp->SSID.present)
4758 {
4759 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4760 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4761 }
4762 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004763 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004764 /* In case of P2P devices, ess and ibss will be set to zero */
4765 else if (!pCap1->ess &&
4766 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4767 {
4768 fMatch = TRUE;
4769 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004770 }
4771
4772 if(pIes1)
4773 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304774 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004775 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004776
4777 if( (NULL == pIes2) && pIesTemp )
4778 {
4779 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304780 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004781 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004782
4783 return( fMatch );
4784}
4785
4786
4787tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4788{
4789 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4790}
4791
4792
4793//to check whether the BSS matches the dot11Mode
4794static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4795 tDot11fBeaconIEs *pIes)
4796{
4797 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4798 eCsrPhyMode phyMode;
4799
4800 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4801 {
4802 switch(pMac->roam.configParam.phyMode)
4803 {
4804 case eCSR_DOT11_MODE_11b:
4805 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4806 break;
4807 case eCSR_DOT11_MODE_11g:
4808 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4809 break;
4810 case eCSR_DOT11_MODE_11g_ONLY:
4811 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4812 break;
4813 case eCSR_DOT11_MODE_11a:
4814 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4815 break;
4816 case eCSR_DOT11_MODE_11n_ONLY:
4817 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4818 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004819
4820#ifdef WLAN_FEATURE_11AC
4821 case eCSR_DOT11_MODE_11ac_ONLY:
4822 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4823 break;
4824#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004825 case eCSR_DOT11_MODE_11b_ONLY:
4826 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4827 break;
4828 case eCSR_DOT11_MODE_11a_ONLY:
4829 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4830 break;
4831 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004832#ifdef WLAN_FEATURE_11AC
4833 case eCSR_DOT11_MODE_11ac:
4834#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004835 case eCSR_DOT11_MODE_TAURUS:
4836 default:
4837 fAllowed = eANI_BOOLEAN_TRUE;
4838 break;
4839 }
4840 }
4841
4842 return (fAllowed);
4843}
4844
4845
4846
4847//Return pIes to caller for future use when returning TRUE.
4848static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4849 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4850 tDot11fBeaconIEs **ppIes )
4851{
4852 tANI_BOOLEAN fValidChannel = FALSE;
4853 tDot11fBeaconIEs *pIes = NULL;
4854 tANI_U8 index;
4855
4856 for( index = 0; index < numChn; index++ )
4857 {
4858 // This check relies on the fact that a single BSS description is returned in each
4859 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4860 // to this model when we ran with a large number of APs. If this were to change, then
4861 // this check would have to mess with removing the bssDescription from somewhere in an
4862 // arbitrary index in the bssDescription array.
4863 if ( pChannels[ index ] == pBssDesc->channelId )
4864 {
4865 fValidChannel = TRUE;
4866 break;
4867 }
4868 }
4869 *ppIes = NULL;
4870 if(fValidChannel)
4871 {
4872 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4873 {
4874 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4875 if( fValidChannel )
4876 {
4877 *ppIes = pIes;
4878 }
4879 else
4880 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304881 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004882 }
4883 }
4884 else
4885 {
4886 fValidChannel = FALSE;
4887 }
4888 }
4889
4890 return( fValidChannel );
4891}
4892
4893
4894//Return whether last scan result is received
4895static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4896 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4897{
4898 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4899 tDot11fBeaconIEs *pIes = NULL;
4900 tANI_U32 cbParsed;
4901 tSirBssDescription *pSirBssDescription;
4902 tANI_U32 cbBssDesc;
4903 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4904 + sizeof(tSirBssDescription); //We need at least one CB
4905
4906 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4907 // is returned when the scan could not find anything. so if we get scan failure return that
4908 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4909 // BssDescriptions....
4910 do
4911 {
4912 if ( ( cbScanResult <= pScanRsp->length ) &&
4913 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4914 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4915 {
4916 tANI_U8 *pChannelList = NULL;
4917 tANI_U8 cChannels = 0;
4918
4919 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004920#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4921 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4922 {
4923 pChannelList = NULL;
4924 cChannels = 0;
4925 }
4926 else
4927#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004928 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4929 {
4930 //eCsrScanSetBGScanParam uses different structure
4931 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4932
4933 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4934 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4935 }
4936 else
4937 {
4938 //the rest use generic scan request
4939 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4940 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4941 }
4942
4943 // if the scan result is not on one of the channels in the Valid channel list, then it
4944 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4945 // let's drop the scan result.
4946 //
4947 // The other situation is where the scan request is for a scan on a particular channel set
4948 // and the scan result is from a
4949
4950 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4951 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4952 // as the valid channels.
4953 if ( 0 == cChannels )
4954 {
4955 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4956
4957 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4958 {
4959 pChannelList = pMac->roam.validChannelList;
4960 cChannels = (tANI_U8)len;
4961 }
4962 else
4963 {
4964 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004965 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004966 break;
4967 }
4968 }
4969
4970 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4971 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4972 pSirBssDescription = pScanRsp->bssDescription;
4973 while( cbParsed < pScanRsp->length )
4974 {
4975 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4976 {
4977 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4978 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4979 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4980 {
4981 if( csrIs11dSupported( pMac) )
4982 {
4983 //Check whether the BSS is acceptable base on 11d info and our configs.
4984 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4985 {
4986 //Double check whether the channel is acceptable by us.
4987 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4988 {
4989 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4990 }
4991 }
4992 }
4993 else
4994 {
4995 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4996 }
4997 }
4998 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05304999 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005000 }
5001 // skip over the BSS description to the next one...
5002 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5003
5004 cbParsed += cbBssDesc;
5005 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5006
5007 } //while
5008 }
5009 else
5010 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005011 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005012 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005013 //HO bg scan/probe failed no need to try autonomously
5014 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5015 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005016#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5017 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5018#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005019 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5020 {
5021 fRemoveCommand = eANI_BOOLEAN_TRUE;
5022 }
5023 }
5024 }while(0);
5025 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5026 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005027 smsLog(pMac, LOG1, " Scan received %d unique BSS scan reason is %d", csrLLCount(&pMac->scan.tempScanResults), pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005028 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5029 fRet = eANI_BOOLEAN_TRUE;
5030 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5031 if(pfRemoveCommand)
5032 {
5033 *pfRemoveCommand = fRemoveCommand;
5034 }
5035
5036#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305037 if (pMac->fScanOffload)
5038 return fRet;
5039
Jeff Johnson295189b2012-06-20 16:38:30 -07005040 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5041 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005042 /* Pending scan commands in the list because the previous scan command
5043 * was split into a scan command on one channel + a scan command for all
5044 * remaining channels.
5045 *
5046 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005047 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305048 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005049 * active and if the scan is a BG scan triggered by LFR (OR)
5050 * any scan if LFR is in the middle of a BG scan. Splitting
5051 * the scan is delaying the time it takes for LFR to find
5052 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005053 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305054 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005055#ifdef FEATURE_WLAN_LFR
5056 (csrIsConcurrentInfraConnected(pMac) ||
5057 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305058 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005059 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5060#endif
5061 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305062 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005063 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005064 /* if active connected sessions present then continue to split scan
5065 * with specified interval between consecutive scans */
5066 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305067 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5068 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005069 } else {
5070 /* if no connected sessions present then initiate next scan command immediately */
5071 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305072 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005073 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005074 }
5075#endif
5076 return (fRet);
5077}
5078
5079
5080tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5081{
5082 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305083 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5084 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005085
5086 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5087 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5088 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5089}
5090
5091
5092eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5093{
5094 eHalStatus status = eHAL_STATUS_SUCCESS;
5095 tListElem *pEntry;
5096 tSmeCmd *pCommand;
5097 eCsrScanStatus scanStatus;
5098 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5099 tSmeGetScanChnRsp *pScanChnInfo;
5100 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5101 eCsrScanReason reason = eCsrScanOther;
5102
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305103 if (pMac->fScanOffload)
5104 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5105 LL_ACCESS_LOCK);
5106 else
5107 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005108
5109 if ( pEntry )
5110 {
5111 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5112 if ( eSmeCommandScan == pCommand->command )
5113 {
5114 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5115 reason = pCommand->u.scanCmd.reason;
5116 switch(pCommand->u.scanCmd.reason)
5117 {
5118 case eCsrScanAbortBgScan:
5119 case eCsrScanAbortNormalScan:
5120 case eCsrScanBGScanAbort:
5121 case eCsrScanBGScanEnable:
5122 break;
5123 case eCsrScanGetScanChnInfo:
5124 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005125 /*
5126 * status code not available in tSmeGetScanChnRsp, so
5127 * by default considereing it to be success
5128 */
5129 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005130 csrScanAgeResults(pMac, pScanChnInfo);
5131 break;
5132 case eCsrScanForCapsChange:
5133 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5134 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005135 case eCsrScanP2PFindPeer:
5136 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5137 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5138 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005139 case eCsrScanSetBGScanParam:
5140 default:
5141 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5142 {
5143 //Not to get channel info if the scan is not a wildcard scan because
5144 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005145 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
5146#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5147 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5148#endif
5149 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005150 {
5151 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005152 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5153 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305154 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5155 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005156 }
5157 else
5158 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305159 csrScanGetScanChnInfo(pMac,
5160 pCommand->sessionId,
5161 pCommand->u.scanCmd.pContext,
5162 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005163 pCommand->u.scanCmd.callback = NULL;
5164 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005165 }
5166 }
5167 break;
5168 }//switch
5169 if(fRemoveCommand)
5170 {
5171
5172 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5173
Srikant Kuppa866893f2012-12-27 17:28:14 -08005174 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005175 smeProcessPendingQueue( pMac );
5176 }
5177 else
5178 {
5179 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5180 status = eHAL_STATUS_FAILURE;
5181 }
5182 }
5183 else
5184 {
5185 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5186 status = eHAL_STATUS_FAILURE;
5187 }
5188
5189 return (status);
5190}
5191
5192
5193
5194
5195tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5196{
5197 tListElem *pEntry;
5198 tCsrScanResult *pResult;
5199 tCsrScanResultInfo *pRet = NULL;
5200 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5201
5202 if(pResultList)
5203 {
5204 csrLLLock(&pResultList->List);
5205 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5206 if(pEntry)
5207 {
5208 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5209 pRet = &pResult->Result;
5210 }
5211 pResultList->pCurEntry = pEntry;
5212 csrLLUnlock(&pResultList->List);
5213 }
5214
5215 return pRet;
5216}
5217
5218
5219tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5220{
5221 tListElem *pEntry = NULL;
5222 tCsrScanResult *pResult = NULL;
5223 tCsrScanResultInfo *pRet = NULL;
5224 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5225
5226 if(pResultList)
5227 {
5228 csrLLLock(&pResultList->List);
5229 if(NULL == pResultList->pCurEntry)
5230 {
5231 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5232 }
5233 else
5234 {
5235 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5236 }
5237 if(pEntry)
5238 {
5239 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5240 pRet = &pResult->Result;
5241 }
5242 pResultList->pCurEntry = pEntry;
5243 csrLLUnlock(&pResultList->List);
5244 }
5245
5246 return pRet;
5247}
5248
5249
5250//This function moves the first BSS that matches the bssid to the head of the result
5251eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5252{
5253 eHalStatus status = eHAL_STATUS_FAILURE;
5254 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5255 tCsrScanResult *pResult = NULL;
5256 tListElem *pEntry = NULL;
5257
5258 if(pResultList && bssid)
5259 {
5260 csrLLLock(&pResultList->List);
5261 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5262 while(pEntry)
5263 {
5264 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305265 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005266 {
5267 status = eHAL_STATUS_SUCCESS;
5268 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5269 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5270 break;
5271 }
5272 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5273 }
5274 csrLLUnlock(&pResultList->List);
5275 }
5276
5277 return (status);
5278}
5279
5280
5281//Remove the BSS if possible.
5282//Return -- TRUE == the BSS is remove. False == Fail to remove it
5283//This function is called when list lock is held. Be caution what functions it can call.
5284tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5285{
5286 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5287 tANI_U32 i;
5288 tCsrRoamSession *pSession;
5289
5290 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5291 {
5292 if( CSR_IS_SESSION_VALID( pMac, i ) )
5293 {
5294 pSession = CSR_GET_SESSION( pMac, i );
5295 //Not to remove the BSS we are connected to.
5296 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
5297 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005298 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005299 )
5300 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08005301 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5302 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5303 pResult->Result.BssDescriptor.channelId);
Mihir Shetebc866f62014-02-13 16:08:53 +05305304
Jeff Johnson295189b2012-06-20 16:38:30 -07005305 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5306 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5307 {
Mihir Shetebc866f62014-02-13 16:08:53 +05305308 if (csrIsMacAddressEqual(pMac,
5309 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5310 (tCsrBssid *) pMac->scan.currentCountryBssid))
5311 {
5312 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5313 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5314 pMac->scan.currentCountryRSSI = -128;
5315 }
5316
Jeff Johnson295189b2012-06-20 16:38:30 -07005317 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005318 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005319 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005320 break;
5321 }
5322 } //valid session
5323 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005324 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07005325 {
5326 //reset the counter so this won't hapeen too soon
5327 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5328 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5329 }
5330
5331 return (fRet);
5332}
5333
5334
5335eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5336{
5337 eHalStatus status = eHAL_STATUS_SUCCESS;
5338 tListElem *pEntry, *tmpEntry;
5339 tCsrScanResult *pResult;
5340 tLimScanChn *pChnInfo;
5341 tANI_U8 i;
5342
5343 csrLLLock(&pMac->scan.scanResultList);
5344 for(i = 0; i < pScanChnInfo->numChn; i++)
5345 {
5346 pChnInfo = &pScanChnInfo->scanChn[i];
5347 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5348 while( pEntry )
5349 {
5350 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5351 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5352 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5353 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005354 if(pResult->AgingCount <= 0)
5355 {
5356 smsLog(pMac, LOGW, " age out due to ref count");
5357 csrScanAgeOutBss(pMac, pResult);
5358 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005359 else
5360 {
5361 pResult->AgingCount--;
5362 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005363 }
5364 pEntry = tmpEntry;
5365 }
5366 }
5367 csrLLUnlock(&pMac->scan.scanResultList);
5368
5369 return (status);
5370}
5371
5372
5373eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5374 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5375{
5376 eHalStatus status = eHAL_STATUS_SUCCESS;
5377 tSirSmeScanReq *pMsg;
5378 tANI_U16 msgLen;
5379 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5380 tSirScanType scanType = pScanReq->scanType;
5381 tANI_U32 minChnTime; //in units of milliseconds
5382 tANI_U32 maxChnTime; //in units of milliseconds
5383 tANI_U32 i;
5384 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5385 tANI_U8 *pSelfMac = NULL;
5386
5387 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5388 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5389 ( pScanReq->uIEFieldLen ) ;
5390
Kiet Lam64c1b492013-07-12 13:56:44 +05305391 pMsg = vos_mem_malloc(msgLen);
5392 if ( NULL == pMsg )
5393 status = eHAL_STATUS_FAILURE;
5394 else
5395 status = eHAL_STATUS_SUCCESS;
5396 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005397 {
5398 do
5399 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305400 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005401 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5402 pMsg->length = pal_cpu_to_be16(msgLen);
5403 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305404 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5405 {
5406 pMsg->sessionId = sessionId;
5407 }
5408 else
5409 {
5410 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5411 request on first available session */
5412 pMsg->sessionId = 0;
5413 }
5414
Jeff Johnson295189b2012-06-20 16:38:30 -07005415 pMsg->transactionId = 0;
5416 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5417 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5418
5419 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5420 {
5421 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5422 }
5423 else
5424 {
5425 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5426 // do so, get the WNI_CFG_STA_ID
5427 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5428 {
5429 if( CSR_IS_SESSION_VALID( pMac, i ) )
5430 {
5431 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5432 break;
5433 }
5434 }
5435 if( CSR_ROAM_SESSION_MAX == i )
5436 {
5437 tANI_U32 len = WNI_CFG_BSSID_LEN;
5438 pSelfMac = selfMacAddr;
5439 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5440 if( !HAL_STATUS_SUCCESS( status ) ||
5441 ( len < WNI_CFG_BSSID_LEN ) )
5442 {
5443 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5444 //Force failed status
5445 status = eHAL_STATUS_FAILURE;
5446 break;
5447 }
5448 }
5449 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305450 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005451
5452 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305453 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5454 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005455 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305456 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005457 }
5458 else
5459 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305460 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005461 }
5462 minChnTime = pScanReq->minChnTime;
5463 maxChnTime = pScanReq->maxChnTime;
5464
5465 //Verify the scan type first, if the scan is active scan, we need to make sure we
5466 //are allowed to do so.
5467 /* if 11d is enabled & we don't see any beacon around, scan type falls
5468 back to passive. But in BT AMP STA mode we need to send out a
5469 directed probe*/
5470 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5471 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5472 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5473 {
5474 scanType = pMac->scan.curScanType;
5475 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5476 {
5477 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5478 {
5479 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5480 }
5481 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5482 {
5483 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5484 }
5485 }
5486 }
5487 pMsg->scanType = pal_cpu_to_be32(scanType);
5488
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305489 pMsg->numSsid =
5490 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
5491 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07005492 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5493 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005494 for (i = 0; i < pMsg->numSsid; i++)
5495 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305496 vos_mem_copy(&pMsg->ssId[i],
5497 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005498 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005499 }
5500 else
5501 {
5502 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005503 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5504 {
5505 pMsg->ssId[i].length = 0;
5506 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005507 }
5508
Jeff Johnson295189b2012-06-20 16:38:30 -07005509 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5510 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005511 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5512 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005513 //hidden SSID option
5514 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5515 //rest time
5516 //pMsg->restTime = pScanReq->restTime;
5517 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5518 // All the scan results caching will be done by Roaming
5519 // We do not want LIM to do any caching of scan results,
5520 // so delete the LIM cache on all scan requests
5521 pMsg->returnFreshResults = pScanReqParam->freshScan;
5522 //Always ask for unique result
5523 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5524 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5525 if(pScanReq->ChannelInfo.numOfChannels)
5526 {
5527 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305528 vos_mem_copy(pMsg->channelList.channelNumber,
5529 pScanReq->ChannelInfo.ChannelList,
5530 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005531 }
5532
5533 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5534 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5535 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5536 if(pScanReq->uIEFieldLen != 0)
5537 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305538 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5539 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005540 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005541 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005542
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005543 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5544 {
5545 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5546 }
5547
Jeff Johnson295189b2012-06-20 16:38:30 -07005548 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005549 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005550 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5551 pScanReq->requestType, pMsg->channelList.numChannels);
5552
5553 for(i = 0; i < pMsg->channelList.numChannels; i++)
5554 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005555 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005556 }
5557
Jeff Johnson295189b2012-06-20 16:38:30 -07005558 if(HAL_STATUS_SUCCESS(status))
5559 {
5560 status = palSendMBMessage(pMac->hHdd, pMsg);
5561 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005562 else
5563 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005564 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305565 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005566 }
5567 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005568 else
5569 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005570 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005571 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005572
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305573 if(!HAL_STATUS_SUCCESS(status))
5574 {
5575 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
5576 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
5577 sessionId, pScanReqParam->bReturnAfter1stMatch,
5578 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
5579 pScanReqParam->hiddenSsid );
5580 smsLog( pMac, LOG1, FL("scanType = %u BSSType = %u numOfSSIDs = %d"
5581 " numOfChannels = %d requestType = %d p2pSearch = %d\n"),
5582 pScanReq->scanType, pScanReq->BSSType,
5583 pScanReq->SSIDs.numOfSSIDs,
5584 pScanReq->ChannelInfo.numOfChannels, pScanReq->requestType,
5585 pScanReq->p2pSearch );
5586
5587 }
5588
Jeff Johnson295189b2012-06-20 16:38:30 -07005589 return( status );
5590}
5591
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005592eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005593{
5594 eHalStatus status = eHAL_STATUS_SUCCESS;
5595 tSirSmeScanReq *pMsg;
5596 tANI_U16 msgLen;
5597
5598 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305599 pMsg = vos_mem_malloc(msgLen);
5600 if ( NULL == pMsg )
5601 status = eHAL_STATUS_FAILURE;
5602 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005603 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305604 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005605 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5606 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005607 pMsg->sessionId = sessionId;
5608 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005609 pMsg->returnFreshResults = pScanReqParam->freshScan;
5610 //Always ask for unique result
5611 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5612 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5613 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005614 if (!HAL_STATUS_SUCCESS(status))
5615 {
5616 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5617 }
5618
Jeff Johnson295189b2012-06-20 16:38:30 -07005619 }
5620
5621 return( status );
5622}
5623
5624
5625
5626eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5627{
5628 eHalStatus status = eHAL_STATUS_FAILURE;
5629 tScanReqParam scanReq;
5630
5631 do
5632 {
5633 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5634 scanReq.fUniqueResult = TRUE;
5635 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5636 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5637 {
5638 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5639 }
5640 else
5641 {
5642 // Basically do scan on all channels even for 11D 1st scan case.
5643 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5644 }
5645 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5646 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5647 {
5648 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5649 }
5650
5651#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5652 {
5653 vos_log_scan_pkt_type *pScanLog = NULL;
5654
5655 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5656 if(pScanLog)
5657 {
5658 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5659 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5660 {
5661 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5662 }
5663 else
5664 {
5665 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5666 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5667 {
5668 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5669 }
5670 else
5671 {
5672 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5673 }
5674 }
5675 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5676 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5677 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5678 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5679 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305680 vos_mem_copy(pScanLog->channels,
5681 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5682 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005683 }
5684 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5685 }
5686 }
5687#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5688
5689
5690 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5691 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5692 }while(0);
5693
5694 return( status );
5695}
5696
5697
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005698eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005699{
5700 eHalStatus status = eHAL_STATUS_FAILURE;
5701 tScanReqParam scanReq;
5702
5703 do
5704 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005705#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5706 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5707 {
5708 //to get the LFR candidates from PE cache
5709 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5710 scanReq.fUniqueResult = TRUE;
5711 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5712 }
5713 else
5714#endif
5715 {
5716 //not a fresh scan
5717 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5718 scanReq.fUniqueResult = TRUE;
5719 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5720 }
5721 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005722 }while(0);
5723
5724 return (status);
5725}
5726
5727
5728
5729eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5730{
5731 eHalStatus status = eHAL_STATUS_SUCCESS;
5732 tCsrChannelInfo newChannelInfo = {0, NULL};
5733 int i, j;
5734 tANI_U8 *pChannel = NULL;
5735 tANI_U32 len = 0;
5736
5737 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305738 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005739 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305740 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5741 {
5742 pCommand->u.scanCmd.lastRoamState[i] =
5743 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5744 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5745 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5746 pCommand->u.scanCmd.reason );
5747 }
5748 }
5749 else
5750 {
5751 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5752 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5753 pCommand->sessionId);
5754 smsLog( pMac, LOG3,
5755 "starting SCAN command from %d state.... reason is %d",
5756 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5757 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005758 }
5759
5760 switch(pCommand->u.scanCmd.reason)
5761 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005762#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5763 case eCsrScanGetLfrResult:
5764#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005765 case eCsrScanGetResult:
5766 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005767 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005768 break;
5769 case eCsrScanSetBGScanParam:
5770 status = csrProcessSetBGScanParam(pMac, pCommand);
5771 break;
5772 case eCsrScanBGScanAbort:
5773 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5774 break;
5775 case eCsrScanBGScanEnable:
5776 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5777 break;
5778 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305779 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005780 break;
5781 case eCsrScanUserRequest:
5782 if(pMac->roam.configParam.fScanTwice)
5783 {
5784 //We scan 2.4 channel twice
5785 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5786 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5787 {
5788 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5789 //allocate twice the channel
5790 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5791 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5792 }
5793 else
5794 {
5795 //get the valid channel list to scan all.
5796 len = sizeof(pMac->roam.validChannelList);
5797
5798 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5799 {
5800 //allocate twice the channel
5801 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5802 pChannel = pMac->roam.validChannelList;
5803 }
5804 }
5805 if(NULL == newChannelInfo.ChannelList)
5806 {
5807 newChannelInfo.numOfChannels = 0;
5808 }
5809 else
5810 {
5811 j = 0;
5812 for(i = 0; i < len; i++)
5813 {
5814 newChannelInfo.ChannelList[j++] = pChannel[i];
5815 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5816 {
5817 newChannelInfo.ChannelList[j++] = pChannel[i];
5818 }
5819 }
5820 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5821 {
5822 //pChannel points to the channellist from the command, free it.
5823 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005824 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005825 }
5826 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5827 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5828 }
5829 } //if(pMac->roam.configParam.fScanTwice)
5830
5831 status = csrScanChannels(pMac, pCommand);
5832
5833 break;
5834 default:
5835 status = csrScanChannels(pMac, pCommand);
5836 break;
5837 }
5838
5839 if(!HAL_STATUS_SUCCESS(status))
5840 {
5841 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5842 }
5843
5844 return (status);
5845}
5846
5847
5848eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5849{
5850 eHalStatus status = eHAL_STATUS_SUCCESS;
5851 tSmeCmd *pCommand = NULL;
5852
5853 if(pScanReq)
5854 {
5855 do
5856 {
5857 pCommand = csrGetCommandBuffer(pMac);
5858 if(!pCommand)
5859 {
5860 status = eHAL_STATUS_RESOURCES;
5861 break;
5862 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305863 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005864 pCommand->command = eSmeCommandScan;
5865 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5866 pCommand->u.scanCmd.callback = NULL;
5867 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05305868 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07005869 //we have to do the follow
5870 if(pScanReq->ChannelInfo.numOfChannels == 0)
5871 {
5872 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5873 }
5874 else
5875 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305876 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
5877 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
5878 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005879 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305880 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5881 pScanReq->ChannelInfo.ChannelList,
5882 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005883 }
5884 else
5885 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005886 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005887 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05305888 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005889 }
5890 }
5891
5892 //scan req for SSID
5893 if(pScanReq->SSID.length)
5894 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305895 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5896 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07005897 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5898
5899 }
5900 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5901 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5902 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5903
5904
5905 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5906 if( !HAL_STATUS_SUCCESS( status ) )
5907 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005908 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005909 csrReleaseCommandScan( pMac, pCommand );
5910 break;
5911 }
5912 }while(0);
5913 }
5914
5915 return (status);
5916}
5917
5918eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5919{
5920 eHalStatus status = eHAL_STATUS_SUCCESS;
5921 tSmeCmd *pCommand = NULL;
5922
5923 do
5924 {
5925 pCommand = csrGetCommandBuffer(pMac);
5926 if(!pCommand)
5927 {
5928 status = eHAL_STATUS_RESOURCES;
5929 break;
5930 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305931 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005932 pCommand->command = eSmeCommandScan;
5933 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5934 pCommand->u.scanCmd.callback = NULL;
5935 pCommand->u.scanCmd.pContext = NULL;
5936 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5937 if( !HAL_STATUS_SUCCESS( status ) )
5938 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005939 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005940 csrReleaseCommandScan( pMac, pCommand );
5941 break;
5942 }
5943 }while(0);
5944
5945 return (status);
5946}
5947
5948
5949//This will enable the background scan with the non-zero interval
5950eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5951{
5952 eHalStatus status = eHAL_STATUS_SUCCESS;
5953 tSmeCmd *pCommand = NULL;
5954
5955 if(pMac->roam.configParam.bgScanInterval)
5956 {
5957 do
5958 {
5959 pCommand = csrGetCommandBuffer(pMac);
5960 if(!pCommand)
5961 {
5962 status = eHAL_STATUS_RESOURCES;
5963 break;
5964 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305965 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005966 pCommand->command = eSmeCommandScan;
5967 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5968 pCommand->u.scanCmd.callback = NULL;
5969 pCommand->u.scanCmd.pContext = NULL;
5970 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5971 if( !HAL_STATUS_SUCCESS( status ) )
5972 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005973 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005974 csrReleaseCommandScan( pMac, pCommand );
5975 break;
5976 }
5977 }while(0);
5978 //BG scan results are reported automatically by PE to SME once the scan is done.
5979 //No need to fetch the results explicitly.
5980 //csrScanStartGetResultTimer(pMac);
5981 csrScanStartResultAgingTimer(pMac);
5982 }
5983 else
5984 {
5985 //We don't have BG scan so stop the aging timer
5986 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005987 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005988 status = eHAL_STATUS_INVALID_PARAMETER;
5989 }
5990
5991 return (status);
5992}
5993
5994
5995eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5996{
5997 eHalStatus status = eHAL_STATUS_SUCCESS;
5998 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5999 tANI_U32 index = 0;
6000 tANI_U32 new_index = 0;
6001
6002 do
6003 {
6004 status = csrScanFreeRequest(pMac, pDstReq);
6005 if(HAL_STATUS_SUCCESS(status))
6006 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306007 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006008 /* Re-initialize the pointers to NULL since we did a copy */
6009 pDstReq->pIEField = NULL;
6010 pDstReq->ChannelInfo.ChannelList = NULL;
6011 pDstReq->SSIDs.SSIDList = NULL;
6012
Jeff Johnson295189b2012-06-20 16:38:30 -07006013 if(pSrcReq->uIEFieldLen == 0)
6014 {
6015 pDstReq->pIEField = NULL;
6016 }
6017 else
6018 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306019 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6020 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006021 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306022 status = eHAL_STATUS_FAILURE;
6023 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6024 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006025 }
6026 else
6027 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306028 status = eHAL_STATUS_SUCCESS;
6029 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6030 pSrcReq->uIEFieldLen);
6031 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006032 }
6033 }//Allocate memory for IE field
6034 {
6035 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6036 {
6037 pDstReq->ChannelInfo.ChannelList = NULL;
6038 pDstReq->ChannelInfo.numOfChannels = 0;
6039 }
6040 else
6041 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306042 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6043 pSrcReq->ChannelInfo.numOfChannels
6044 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6045 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006046 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306047 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006048 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306049 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6050 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006051 break;
6052 }
6053
6054 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6055 {
6056 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6057 {
6058 pDstReq->ChannelInfo.ChannelList[new_index] =
6059 pSrcReq->ChannelInfo.ChannelList[index];
6060 new_index++;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306061 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006062 pDstReq->ChannelInfo.numOfChannels = new_index;
6063 }
6064 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6065 {
6066 new_index = 0;
6067 pMac->roam.numValidChannels = len;
6068 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6069 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006070 /* Allow scan on valid channels only.
6071 * If it is p2p scan and valid channel list doesnt contain
6072 * social channels, enforce scan on social channels because
6073 * that is the only way to find p2p peers.
6074 * This can happen only if band is set to 5Ghz mode.
6075 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006076 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
6077 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006078 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07006079 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08006080 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006081 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006082#ifdef FEATURE_WLAN_LFR
6083 /*
6084 * If LFR is requesting a contiguous scan
6085 * (i.e. numOfChannels > 1), then ignore
6086 * DFS channels.
6087 * TODO: vos_nv_getChannelEnabledState is returning
6088 * 120, 124 and 128 as non-DFS channels. Hence, the
6089 * use of direct check for channels below.
6090 */
6091 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6092 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08006093 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08006094#endif
6095 )
6096 {
6097#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006098 smsLog(pMac, LOG2,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306099 FL(" reqType=%d, numOfChannels=%d,"
6100 " ignoring DFS channel %d"),
6101 pSrcReq->requestType,
Srikant Kuppa866893f2012-12-27 17:28:14 -08006102 pSrcReq->ChannelInfo.numOfChannels,
6103 pSrcReq->ChannelInfo.ChannelList[index]);
6104#endif
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306105 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006106 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006107
Jeff Johnson295189b2012-06-20 16:38:30 -07006108 pDstReq->ChannelInfo.ChannelList[new_index] =
6109 pSrcReq->ChannelInfo.ChannelList[index];
6110 new_index++;
6111 }
6112 }
6113 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006114#ifdef FEATURE_WLAN_LFR
6115 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6116 (0 == pDstReq->ChannelInfo.numOfChannels))
6117 {
6118 /*
6119 * No valid channels found in the request.
6120 * Only perform scan on the channels passed
6121 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
6122 * Passing 0 to LIM will trigger a scan on
6123 * all valid channels which is not desirable.
6124 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306125 smsLog(pMac, LOGE, FL(" no valid channels found"
6126 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006127 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6128 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306129 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6130 " channel=%d"), index,
6131 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006132 }
6133 status = eHAL_STATUS_FAILURE;
6134 break;
6135 }
6136#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006137 }
6138 else
6139 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306140 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6141 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306142 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6143 pSrcReq->ChannelInfo.ChannelList,
6144 pSrcReq->ChannelInfo.numOfChannels
6145 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006146 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6147 }
6148 }//Allocate memory for Channel List
6149 }
6150 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6151 {
6152 pDstReq->SSIDs.numOfSSIDs = 0;
6153 pDstReq->SSIDs.SSIDList = NULL;
6154 }
6155 else
6156 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306157 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6158 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6159 if ( NULL == pDstReq->SSIDs.SSIDList )
6160 status = eHAL_STATUS_FAILURE;
6161 else
6162 status = eHAL_STATUS_SUCCESS;
6163 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006164 {
6165 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306166 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6167 pSrcReq->SSIDs.SSIDList,
6168 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006169 }
6170 else
6171 {
6172 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306173 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006174 break;
6175 }
6176 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006177 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006178 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006179
6180 }
6181 }while(0);
6182
6183 if(!HAL_STATUS_SUCCESS(status))
6184 {
6185 csrScanFreeRequest(pMac, pDstReq);
6186 }
6187
6188 return (status);
6189}
6190
6191
6192eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6193{
Jeff Johnson295189b2012-06-20 16:38:30 -07006194
6195 if(pReq->ChannelInfo.ChannelList)
6196 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306197 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006198 pReq->ChannelInfo.ChannelList = NULL;
6199 }
6200 pReq->ChannelInfo.numOfChannels = 0;
6201 if(pReq->pIEField)
6202 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306203 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006204 pReq->pIEField = NULL;
6205 }
6206 pReq->uIEFieldLen = 0;
6207 if(pReq->SSIDs.SSIDList)
6208 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306209 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006210 pReq->SSIDs.SSIDList = NULL;
6211 }
6212 pReq->SSIDs.numOfSSIDs = 0;
6213
Kiet Lam64c1b492013-07-12 13:56:44 +05306214 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006215}
6216
6217
6218void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6219{
6220 if(pCommand->u.scanCmd.callback)
6221 {
6222// sme_ReleaseGlobalLock( &pMac->sme );
6223 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6224// sme_AcquireGlobalLock( &pMac->sme );
6225 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006226 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006227 }
6228}
6229
6230
6231void csrScanStopTimers(tpAniSirGlobal pMac)
6232{
6233 csrScanStopResultAgingTimer(pMac);
6234 csrScanStopIdleScanTimer(pMac);
6235 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006236 if(0 != pMac->scan.scanResultCfgAgingTime )
6237 {
6238 csrScanStopResultCfgAgingTimer(pMac);
6239 }
6240
Jeff Johnson295189b2012-06-20 16:38:30 -07006241}
6242
6243
6244eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6245{
6246 eHalStatus status;
6247
6248 if(pMac->scan.fScanEnable)
6249 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306250 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006251 }
6252 else
6253 {
6254 status = eHAL_STATUS_FAILURE;
6255 }
6256
6257 return (status);
6258}
6259
6260
6261eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6262{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306263 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006264}
6265
6266
6267void csrScanGetResultTimerHandler(void *pv)
6268{
6269 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6270
6271 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306272
6273 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006274}
6275
6276#ifdef WLAN_AP_STA_CONCURRENCY
6277static void csrStaApConcTimerHandler(void *pv)
6278{
6279 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6280 tListElem *pEntry;
6281 tSmeCmd *pScanCmd;
6282
6283 csrLLLock(&pMac->scan.scanCmdPendingList);
6284
6285 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6286 {
6287 tCsrScanRequest scanReq;
6288 tSmeCmd *pSendScanCmd = NULL;
6289 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006290 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006291 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006292 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6293 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6294 eHalStatus status;
6295
Jeff Johnson295189b2012-06-20 16:38:30 -07006296 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6297 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006298
6299 /* if any session is connected and the number of channels to scan is
6300 * greater than 1 then split the scan into multiple scan operations
6301 * on each individual channel else continue to perform scan on all
6302 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006303
6304 /* split scan if number of channels to scan is greater than 1 and
6305 * any one of the following:
6306 * - STA session is connected and the scan is not a P2P search
6307 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006308 * Do not split scans if no concurrent infra connections are
6309 * active and if the scan is a BG scan triggered by LFR (OR)
6310 * any scan if LFR is in the middle of a BG scan. Splitting
6311 * the scan is delaying the time it takes for LFR to find
6312 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006313 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006314
6315 if((csrIsStaSessionConnected(pMac) &&
6316 !csrIsP2pSessionConnected(pMac)))
6317 {
6318 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6319 }
6320 else if(csrIsP2pSessionConnected(pMac))
6321 {
6322 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6323 }
6324
6325 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006326 ((csrIsStaSessionConnected(pMac) &&
6327#ifdef FEATURE_WLAN_LFR
6328 (csrIsConcurrentInfraConnected(pMac) ||
6329 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6330 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6331 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6332#endif
6333 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006334 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006335 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306336 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006337
6338 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6339 if (!pSendScanCmd)
6340 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006341 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006342 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6343 return;
6344 }
6345 pSendScanCmd->command = pScanCmd->command;
6346 pSendScanCmd->sessionId = pScanCmd->sessionId;
6347 pSendScanCmd->u.scanCmd.callback = NULL;
6348 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6349 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6350 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6351
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006352 /* First copy all the parameters to local variable of scan request */
6353 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6354
6355 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006356 if(scanReq.ChannelInfo.ChannelList != NULL)
6357 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306358 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006359 scanReq.ChannelInfo.ChannelList = NULL;
6360 }
6361
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006362 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306363 vos_mem_copy(&channelToScan[0],
6364 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6365 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006366 pChnInfo->ChannelList = &channelToScan[0];
6367
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006368 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006369 {
6370 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006371 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006372 }
6373
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006374 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006375
6376 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
6377 //Modify callers parameters in case of concurrency
6378 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006379 //Use concurrency values for min/maxChnTime.
6380 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6381 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006382
6383 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6384 if(!HAL_STATUS_SUCCESS(status))
6385 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006386 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006387 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6388 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006389 }
6390 /* Clean the local scan variable */
6391 scanReq.ChannelInfo.ChannelList = NULL;
6392 scanReq.ChannelInfo.numOfChannels = 0;
6393 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006394 }
6395 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006396 {
6397 /* no active connected session present or numChn == 1
6398 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006399 pSendScanCmd = pScanCmd;
6400 //remove this command from pending list
6401 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6402 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006403 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006404 }
6405
6406 }
6407 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6408
6409 }
6410
Jeff Johnson295189b2012-06-20 16:38:30 -07006411 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6412
6413}
6414#endif
6415
6416eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6417{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006418 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006419
6420 if(pMac->scan.fScanEnable)
6421 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306422 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006423 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006424 return (status);
6425}
6426
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006427eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6428{
6429 eHalStatus status = eHAL_STATUS_FAILURE;
6430
6431 if(pMac->scan.fScanEnable)
6432 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306433 status = vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006434 }
6435 return (status);
6436}
Jeff Johnson295189b2012-06-20 16:38:30 -07006437
6438eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6439{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306440 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006441}
6442
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006443eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6444{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306445 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006446}
Jeff Johnson295189b2012-06-20 16:38:30 -07006447
6448//This function returns the maximum time a BSS is allowed in the scan result.
6449//The time varies base on connection and power saving factors.
6450//Not connected, No PS
6451//Not connected, with PS
6452//Connected w/o traffic, No PS
6453//Connected w/o traffic, with PS
6454//Connected w/ traffic, no PS -- Not supported
6455//Connected w/ traffic, with PS -- Not supported
6456//the return unit is in seconds.
6457tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6458{
6459 tANI_U32 nRet;
6460
6461 if(pMac->scan.nAgingCountDown)
6462 {
6463 //Calculate what should be the timeout value for this
6464 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6465 pMac->scan.nAgingCountDown--;
6466 }
6467 else
6468 {
6469 if( csrIsAllSessionDisconnected( pMac ) )
6470 {
6471 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6472 {
6473 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6474 }
6475 else
6476 {
6477 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6478 }
6479 }
6480 else
6481 {
6482 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6483 {
6484 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6485 }
6486 else
6487 {
6488 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6489 }
6490 }
6491 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6492 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6493 if(pMac->scan.nLastAgeTimeOut > nRet)
6494 {
6495 if(nRet)
6496 {
6497 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6498 }
6499 pMac->scan.nLastAgeTimeOut = nRet;
6500 nRet *= pMac->scan.nAgingCountDown;
6501 }
6502 else
6503 {
6504 pMac->scan.nLastAgeTimeOut = nRet;
6505 }
6506 }
6507
6508 return (nRet);
6509}
6510
6511
6512void csrScanResultAgingTimerHandler(void *pv)
6513{
6514 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6515 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6516
6517 //no scan, no aging
6518 if(pMac->scan.fScanEnable &&
6519 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6520 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6521 )
6522 {
6523 tListElem *pEntry, *tmpEntry;
6524 tCsrScanResult *pResult;
6525 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6526 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6527
6528 csrLLLock(&pMac->scan.scanResultList);
6529 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6530 while( pEntry )
6531 {
6532 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6533 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6534 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6535 {
6536 smsLog(pMac, LOGW, " age out due to time out");
6537 csrScanAgeOutBss(pMac, pResult);
6538 }
6539 pEntry = tmpEntry;
6540 }
6541 csrLLUnlock(&pMac->scan.scanResultList);
6542 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306543 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006544}
6545
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006546static void csrScanResultCfgAgingTimerHandler(void *pv)
6547{
6548 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6549 tListElem *pEntry, *tmpEntry;
6550 tCsrScanResult *pResult;
6551 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6552 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6553
6554 csrLLLock(&pMac->scan.scanResultList);
6555 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6556 while( pEntry )
6557 {
6558 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6559 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6560 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6561 {
6562 smsLog(pMac, LOGW, " age out due to time out");
6563 csrScanAgeOutBss(pMac, pResult);
6564 }
6565 pEntry = tmpEntry;
6566 }
6567 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306568 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006569}
Jeff Johnson295189b2012-06-20 16:38:30 -07006570
6571eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6572{
6573 eHalStatus status;
6574
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006575 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006576 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6577 {
6578 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306579 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6580 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006581 if( !HAL_STATUS_SUCCESS(status) )
6582 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006583 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006584 //This should not happen but set the flag to restart when ready
6585 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6586 }
6587 }
6588 else
6589 {
6590 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6591 {
6592 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6593 }
6594 status = eHAL_STATUS_FAILURE;
6595 }
6596
6597 return (status);
6598}
6599
6600
6601eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6602{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306603 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006604}
6605
6606
6607//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6608void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6609{
6610 csrScanCancelIdleScan(pMac);
6611}
6612
6613
6614//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6615//because IMPS maybe disabled.
6616void csrScanResumeIMPS( tpAniSirGlobal pMac )
6617{
6618 csrScanStartIdleScan( pMac );
6619}
6620
6621
6622void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6623{
6624 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6625
6626 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6627 {
6628 if(pMac->roam.configParam.IsIdleScanEnabled)
6629 {
6630 if(HAL_STATUS_SUCCESS(status))
6631 {
6632 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6633 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006634 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006635 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6636 }
6637 else
6638 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006639 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006640 //even though we are in timer handle, calling stop timer will make sure the timer
6641 //doesn't get to restart.
6642 csrScanStopIdleScanTimer(pMac);
6643 }
6644 }
6645 else
6646 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006647 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006648 }
6649 }
6650 else
6651 {//we might need another flag to check if CSR needs to request imps at all
6652
6653 tANI_U32 nTime = 0;
6654
6655 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6656 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6657 {
6658 csrScanStartIdleScanTimer(pMac, nTime);
6659 }
6660 }
6661 }
6662}
6663
6664
6665//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6666//idle scan timer interval
6667//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6668eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6669{
6670 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6671
6672 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006673 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6674 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006675 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006676 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006677 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006678
6679 if(pTimeInterval)
6680 {
6681 *pTimeInterval = 0;
6682 }
6683
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006684 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006685 if( smeCommandPending( pMac ) )
6686 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006687 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006688 //Not to enter IMPS because more work to do
6689 if(pTimeInterval)
6690 {
6691 *pTimeInterval = 0;
6692 }
6693 //restart when ready
6694 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6695
6696 return (status);
6697 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006698 if (IsPmcImpsReqFailed (pMac))
6699 {
6700 if(pTimeInterval)
6701 {
6702 *pTimeInterval = 1000000; //usec
6703 }
6704 //restart when ready
6705 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006706
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006707 return status;
6708 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006709 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6710 /*&& pMac->roam.configParam.impsSleepTime*/)
6711 {
6712 //Stop get result timer because idle scan gets scan result out of PE
6713 csrScanStopGetResultTimer(pMac);
6714 if(pTimeInterval)
6715 {
6716 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6717 }
6718 //pmcRequestImps take a period in millisecond unit.
6719 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6720 if(!HAL_STATUS_SUCCESS(status))
6721 {
6722 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6723 {
6724 //Do restart the timer if CSR thinks it cannot do IMPS
6725 if( !csrCheckPSReady( pMac ) )
6726 {
6727 if(pTimeInterval)
6728 {
6729 *pTimeInterval = 0;
6730 }
6731 //Set the restart flag to true because that idle scan
6732 //can be restarted even though the timer will not be running
6733 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6734 }
6735 else
6736 {
6737 //For not now, we do a quicker retry
6738 if(pTimeInterval)
6739 {
6740 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6741 }
6742 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006743 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006744 }
6745 else
6746 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006747 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006748 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6749 //the callback will be called in the future. Should not happen though.
6750 status = eHAL_STATUS_SUCCESS;
6751 pMac->scan.nIdleScanTimeGap = 0;
6752 }
6753 }
6754 else
6755 {
6756 //requested so let's reset the value
6757 pMac->scan.nIdleScanTimeGap = 0;
6758 }
6759 }
6760
6761 return (status);
6762}
6763
6764
6765eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6766{
6767 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6768 tANI_U32 nTime = 0;
6769
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006770 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006771 if(pMac->roam.configParam.IsIdleScanEnabled)
6772 {
6773 //stop bg scan first
6774 csrScanBGScanAbort(pMac);
6775 //Stop get result timer because idle scan gets scan result out of PE
6776 csrScanStopGetResultTimer(pMac);
6777 //Enable aging timer since idle scan is going on
6778 csrScanStartResultAgingTimer(pMac);
6779 }
6780 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6781 status = csrScanTriggerIdleScan(pMac, &nTime);
6782 if(!HAL_STATUS_SUCCESS(status))
6783 {
6784 csrScanStartIdleScanTimer(pMac, nTime);
6785 }
6786
6787 return (status);
6788}
6789
6790
6791void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6792{
6793 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6794 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006795 if (vos_concurrent_sessions_running()) {
6796 return;
6797 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006798 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006799 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6800 //Set the restart flag in case later on it is uncancelled
6801 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6802 csrScanStopIdleScanTimer(pMac);
6803 csrScanRemoveNotRoamingScanCommand(pMac);
6804 }
6805}
6806
6807
6808void csrScanIdleScanTimerHandler(void *pv)
6809{
6810 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6811 eHalStatus status;
6812 tANI_U32 nTime = 0;
6813
6814 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006815 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006816 status = csrScanTriggerIdleScan(pMac, &nTime);
6817 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6818 {
6819 //Check whether it is time to actually do an idle scan
6820 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6821 {
6822 pMac->scan.nIdleScanTimeGap = 0;
6823 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6824 }
6825 else
6826 {
6827 csrScanStartIdleScanTimer(pMac, nTime);
6828 }
6829 }
6830}
6831
6832
6833
6834
6835tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6836{
6837 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6838 tListElem *pEntry, *pEntryTmp;
6839 tSmeCmd *pCommand;
6840 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306841 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006842
6843 vos_mem_zero(&localList, sizeof(tDblLinkList));
6844 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6845 {
6846 smsLog(pMac, LOGE, FL(" failed to open list"));
6847 return fRet;
6848 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306849 if (!pMac->fScanOffload)
6850 pCmdList = &pMac->sme.smeCmdPendingList;
6851 else
6852 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006853
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306854 csrLLLock(pCmdList);
6855 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006856 while(pEntry)
6857 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306858 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006859 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6860 if( eSmeCommandScan == pCommand->command )
6861 {
6862 switch( pCommand->u.scanCmd.reason )
6863 {
6864 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306865 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006866 {
6867 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6868 }
6869 fRet = eANI_BOOLEAN_TRUE;
6870 break;
6871
6872 default:
6873 break;
6874 } //switch
6875 }
6876 pEntry = pEntryTmp;
6877 }
6878
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306879 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006880
6881 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6882 {
6883 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6884 csrReleaseCommandScan( pMac, pCommand );
6885 }
6886
6887 csrLLClose(&localList);
6888
6889 return (fRet);
6890}
6891
6892
6893tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6894{
6895 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6896 tListElem *pEntry, *pEntryTmp;
6897 tSmeCmd *pCommand;
6898 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306899 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006900
6901 vos_mem_zero(&localList, sizeof(tDblLinkList));
6902 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6903 {
6904 smsLog(pMac, LOGE, FL(" failed to open list"));
6905 return fRet;
6906 }
6907
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306908 if (!pMac->fScanOffload)
6909 pCmdList = &pMac->sme.smeCmdPendingList;
6910 else
6911 pCmdList = &pMac->sme.smeScanCmdPendingList;
6912
6913 csrLLLock(pCmdList);
6914 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006915 while(pEntry)
6916 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306917 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006918 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6919 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6920 {
6921 switch(pCommand->u.scanCmd.reason)
6922 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006923#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6924 case eCsrScanGetLfrResult:
6925#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006926 case eCsrScanGetResult:
6927 case eCsrScanSetBGScanParam:
6928 case eCsrScanBGScanAbort:
6929 case eCsrScanBGScanEnable:
6930 case eCsrScanGetScanChnInfo:
6931 break;
6932 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006933 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006934 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006935 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306936 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006937 {
6938 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6939 }
6940 fRet = eANI_BOOLEAN_TRUE;
6941 break;
6942 }
6943 }
6944 pEntry = pEntryTmp;
6945 }
6946
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306947 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006948
6949 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6950 {
6951 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6952 if (pCommand->u.scanCmd.callback)
6953 {
6954 /* User scan request is pending,
6955 * send response with status eCSR_SCAN_ABORT*/
6956 pCommand->u.scanCmd.callback(pMac,
6957 pCommand->u.scanCmd.pContext,
6958 pCommand->u.scanCmd.scanID,
6959 eCSR_SCAN_ABORT);
6960 }
6961 csrReleaseCommandScan( pMac, pCommand );
6962 }
6963 csrLLClose(&localList);
6964
6965 return (fRet);
6966}
6967
6968
6969void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6970{
6971 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306972 tANI_BOOLEAN status;
6973
6974 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006975 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306976 tANI_U32 i;
6977 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
6978 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
6979 }
6980 else
6981 {
6982 csrRoamStateChange(pMac,
6983 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
6984 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006985 }
6986
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306987 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07006988
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006989 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306990 if (pMac->fScanOffload)
6991 {
6992 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
6993 &pCommand->Link, LL_ACCESS_LOCK);
6994 }
6995 else
6996 {
6997 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
6998 &pCommand->Link, LL_ACCESS_LOCK);
6999 }
7000
7001 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007002 {
7003 csrReleaseCommandScan( pMac, pCommand );
7004 }
7005 else
7006 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307007 smsLog(pMac, LOGE,
7008 " ********csrReleaseScanCommand cannot release command reason %d",
7009 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007010 }
7011}
7012
7013
7014eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7015 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7016{
7017 eHalStatus status = eHAL_STATUS_SUCCESS;
7018 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7019
Jeff Johnson32d95a32012-09-10 13:15:23 -07007020 if(!pSession)
7021 {
7022 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7023 return eHAL_STATUS_FAILURE;
7024 }
7025
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007026 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007027 csrResetPMKIDCandidateList(pMac, sessionId);
7028 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7029 {
7030 tCsrScanResultFilter *pScanFilter;
7031 tCsrScanResultInfo *pScanResult;
7032 tScanResultHandle hBSSList;
7033 tANI_U32 nItems = *pNumItems;
7034
7035 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307036 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7037 if ( NULL == pScanFilter )
7038 status = eHAL_STATUS_FAILURE;
7039 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007040 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307041 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007042 //Here is the profile we need to connect to
7043 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7044 if(HAL_STATUS_SUCCESS(status))
7045 {
7046 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7047 if(HAL_STATUS_SUCCESS(status))
7048 {
7049 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7050 {
7051 //NumPmkidCandidate adds up here
7052 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7053 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7054 }
7055 if(pSession->NumPmkidCandidate)
7056 {
7057 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307058 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7059 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007060 }
7061 csrScanResultPurge(pMac, hBSSList);
7062 }//Have scan result
7063 csrFreeScanFilter(pMac, pScanFilter);
7064 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307065 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007066 }
7067 }
7068
7069 return (status);
7070}
7071
7072
7073
7074#ifdef FEATURE_WLAN_WAPI
7075eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7076 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7077{
7078 eHalStatus status = eHAL_STATUS_SUCCESS;
7079 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7080
Jeff Johnson32d95a32012-09-10 13:15:23 -07007081 if(!pSession)
7082 {
7083 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7084 return eHAL_STATUS_FAILURE;
7085 }
7086
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007087 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007088 csrResetBKIDCandidateList(pMac, sessionId);
7089 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7090 {
7091 tCsrScanResultFilter *pScanFilter;
7092 tCsrScanResultInfo *pScanResult;
7093 tScanResultHandle hBSSList;
7094 tANI_U32 nItems = *pNumItems;
7095 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307096 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7097 if ( NULL == pScanFilter )
7098 status = eHAL_STATUS_FAILURE;
7099 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007100 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307101 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007102 //Here is the profile we need to connect to
7103 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7104 if(HAL_STATUS_SUCCESS(status))
7105 {
7106 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7107 if(HAL_STATUS_SUCCESS(status))
7108 {
7109 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7110 {
7111 //pMac->scan.NumBkidCandidate adds up here
7112 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7113 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7114
7115 }
7116 if(pSession->NumBkidCandidate)
7117 {
7118 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307119 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007120 }
7121 csrScanResultPurge(pMac, hBSSList);
7122 }//Have scan result
7123 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307124 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007125 }
7126 }
7127
7128 return (status);
7129}
7130#endif /* FEATURE_WLAN_WAPI */
7131
7132
7133
7134//This function is usually used for BSSs that suppresses SSID so the profile
7135//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007136eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007137{
7138 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7139 tSmeCmd *pScanCmd = NULL;
7140 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7141 tANI_U8 index = 0;
7142 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7143
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007144 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007145 //For WDS, we use the index 0. There must be at least one in there
7146 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7147 {
7148 numSsid = 1;
7149 }
7150 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7151 {
7152 do
7153 {
7154 pScanCmd = csrGetCommandBuffer(pMac);
7155 if(!pScanCmd)
7156 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007157 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007158 break;
7159 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307160 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7161 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7162 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007163 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307164 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007165 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307166 else
krunal soni587bf012014-02-04 12:35:11 -08007167 {
7168 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7169 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007170 if(!HAL_STATUS_SUCCESS(status))
7171 break;
7172 pScanCmd->u.scanCmd.roamId = roamId;
7173 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007174 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007175 pScanCmd->u.scanCmd.callback = NULL;
7176 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007177 pScanCmd->u.scanCmd.reason = eCsrScanForSsid;//Need to check: might need a new reason for SSID scan for LFR during multisession with p2p
Jeff Johnson295189b2012-06-20 16:38:30 -07007178 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307179 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007180 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007181 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007182 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7183 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7184 {
7185 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7186 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307187 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007188 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307189 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7190 pProfile->nAddIEScanLength);
7191 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7192 status = eHAL_STATUS_FAILURE;
7193 else
7194 status = eHAL_STATUS_SUCCESS;
7195 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7196 pProfile->nAddIEScanLength, 0);
7197 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007198 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307199 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307200 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007201 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7202 }
7203 else
7204 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007205 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007206 }
7207 } //Allocate memory for IE field
7208 else
7209 {
7210 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7211 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007212 /* For one channel be good enpugh time to receive beacon atleast */
7213 if( 1 == pProfile->ChannelInfo.numOfChannels )
7214 {
7215 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7216 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7217 }
7218 else
7219 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307220 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7221 pMac->roam.configParam.nActiveMaxChnTime;
7222 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7223 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007224 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307225 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7226 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7227 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7228 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007229 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7230 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307231 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7232 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007233 }
7234 else
7235 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307236 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007237 }
7238 if(pProfile->ChannelInfo.numOfChannels)
7239 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307240 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7241 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7242 * pProfile->ChannelInfo.numOfChannels);
7243 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7244 status = eHAL_STATUS_FAILURE;
7245 else
7246 status = eHAL_STATUS_SUCCESS;
7247 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7248 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007249 {
7250 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7251 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7252 {
7253 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7254 {
7255 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7256 = pProfile->ChannelInfo.ChannelList[index];
7257 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7258 }
7259 else
7260 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007261 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007262 }
7263
7264 }
7265 }
7266 else
7267 {
7268 break;
7269 }
7270
7271 }
7272 else
7273 {
7274 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7275 }
7276 if(pProfile->SSIDs.numOfSSIDs)
7277 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307278 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7279 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7280 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7281 status = eHAL_STATUS_FAILURE;
7282 else
7283 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007284 if(!HAL_STATUS_SUCCESS(status))
7285 {
7286 break;
7287 }
7288 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307289 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7290 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007291 }
7292 //Start process the command
7293 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7294 if( !HAL_STATUS_SUCCESS( status ) )
7295 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007296 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007297 break;
7298 }
7299 }while(0);
7300 if(!HAL_STATUS_SUCCESS(status))
7301 {
7302 if(pScanCmd)
7303 {
7304 csrReleaseCommandScan(pMac, pScanCmd);
7305 //TODO:free the memory that is allocated in this function
7306 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007307 if(notify)
7308 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007309 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7310 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007311 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007312 }//valid
7313 else
7314 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007315 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007316 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7317 }
7318
7319 return (status);
7320}
7321
7322
7323//Issue a scan base on the new capability infomation
7324//This should only happen when the associated AP changes its capability.
7325//After this scan is done, CSR reroams base on the new scan results
7326eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7327{
7328 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7329 tSmeCmd *pScanCmd = NULL;
7330
7331 if(pNewCaps)
7332 {
7333 do
7334 {
7335 pScanCmd = csrGetCommandBuffer(pMac);
7336 if(!pScanCmd)
7337 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007338 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007339 status = eHAL_STATUS_RESOURCES;
7340 break;
7341 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307342 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007343 status = eHAL_STATUS_SUCCESS;
7344 pScanCmd->u.scanCmd.roamId = 0;
7345 pScanCmd->command = eSmeCommandScan;
7346 pScanCmd->u.scanCmd.callback = NULL;
7347 pScanCmd->u.scanCmd.pContext = NULL;
7348 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7349 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7350 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7351 if( !HAL_STATUS_SUCCESS( status ) )
7352 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007353 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007354 break;
7355 }
7356 }while(0);
7357 if(!HAL_STATUS_SUCCESS(status))
7358 {
7359 if(pScanCmd)
7360 {
7361 csrReleaseCommandScan(pMac, pScanCmd);
7362 }
7363 }
7364 }
7365
7366 return (status);
7367}
7368
7369
7370
7371void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7372{
7373 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7374
Kiet Lam64c1b492013-07-12 13:56:44 +05307375 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007376 pMac->scan.numBGScanChannel = 0;
7377
7378 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7379 {
7380 pMac->roam.numValidChannels = len;
7381 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307382 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7383 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007384 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7385 }
7386}
7387
7388
7389//This function return TRUE if background scan channel list is adjusted.
7390//this function will only shrink the background scan channel list
7391tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7392 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7393{
7394 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7395 tANI_U8 i, j, count = *pNumAdjustChannels;
7396
7397 i = 0;
7398 while(i < count)
7399 {
7400 for(j = 0; j < NumChannels; j++)
7401 {
7402 if(pChannelList[j] == pAdjustChannels[i])
7403 break;
7404 }
7405 if(j == NumChannels)
7406 {
7407 //This channel is not in the list, remove it
7408 fRet = eANI_BOOLEAN_TRUE;
7409 count--;
7410 if(count - i)
7411 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307412 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007413 }
7414 else
7415 {
7416 //already remove the last one. Done.
7417 break;
7418 }
7419 }
7420 else
7421 {
7422 i++;
7423 }
7424 }//while(i<count)
7425 *pNumAdjustChannels = count;
7426
7427 return (fRet);
7428}
7429
7430
7431//Get the list of the base channels to scan for passively 11d info
7432eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7433{
7434 eHalStatus status = eHAL_STATUS_SUCCESS;
7435 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7436
7437 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7438 if( HAL_STATUS_SUCCESS(status) )
7439 {
7440 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7441 }
7442 else
7443 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007444 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007445 pMac->scan.baseChannels.numChannels = 0;
7446 }
7447
7448 return ( status );
7449}
7450
7451//This function use the input pChannelList to validate the current saved channel list
7452eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7453{
7454 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7455
7456 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7457}
7458
7459
7460void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7461{
7462 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307463 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007464
Mihir Shete31c435d2014-02-12 13:13:34 +05307465 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7466 "%s: dump valid channel list(NumChannels(%d))",
7467 __func__,NumChannels);
7468 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7469 pChannelList, NumChannels);
7470
Jeff Johnson295189b2012-06-20 16:38:30 -07007471 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007472#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307473 if (pMac->fScanOffload)
7474 {
7475 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7476 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007477 status = csrUpdateChannelList(pMac);
7478 }
7479#else
7480 status = csrUpdateChannelList(pMac);
7481#endif
7482
7483 if (eHAL_STATUS_SUCCESS != status)
7484 {
7485 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7486 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307487 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007488 return;
7489}
7490
7491
7492
7493/*
7494 * The Tx power limits are saved in the cfg for future usage.
7495 */
7496void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7497{
7498 tListElem *pEntry;
7499 tANI_U32 cbLen = 0, dataLen;
7500 tCsrChannelPowerInfo *pChannelSet;
7501 tANI_U32 idx;
7502 tSirMacChanInfo *pChannelPowerSet;
7503 tANI_U8 *pBuf = NULL;
7504
7505 //allocate maximum space for all channels
7506 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307507 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007508 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307509 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007510 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7511
7512 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7513 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7514 while( pEntry )
7515 {
7516 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7517 if ( 1 != pChannelSet->interChannelOffset )
7518 {
7519 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7520 // to the right format... (inter channel offset of 1 is the only option for the triplets
7521 // that 11d advertises.
7522 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7523 {
7524 // expanding this entry will overflow our allocation
7525 smsLog(pMac, LOGE,
7526 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007527 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007528 pChannelSet->firstChannel,
7529 pChannelSet->numChannels,
7530 pChannelSet->interChannelOffset);
7531 break;
7532 }
7533
7534 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7535 {
7536 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007537 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007538 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007539 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007540 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007541 cbLen += sizeof( tSirMacChanInfo );
7542 pChannelPowerSet++;
7543 }
7544 }
7545 else
7546 {
7547 if (cbLen >= dataLen)
7548 {
7549 // this entry will overflow our allocation
7550 smsLog(pMac, LOGE,
7551 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007552 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007553 pChannelSet->firstChannel,
7554 pChannelSet->numChannels,
7555 pChannelSet->interChannelOffset);
7556 break;
7557 }
7558 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007559 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007560 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007561 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007562 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007563
7564
7565 cbLen += sizeof( tSirMacChanInfo );
7566 pChannelPowerSet++;
7567 }
7568
7569 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7570 }
7571
7572 if(cbLen)
7573 {
7574 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7575 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307576 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007577 }//Allocate memory
7578}
7579
7580
7581void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7582{
7583 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7584 ///v_REGDOMAIN_t DomainId;
7585
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007586 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307587 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007588
7589 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7590 // the bogus country codes, program the MAC with the right country code.
7591 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7592 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7593 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7594 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7595 {
7596 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7597 cc[ 1 ] = 'R';
7598 }
7599 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7600
7601 //Need to let HALPHY know about the current domain so it can apply some
7602 //domain-specific settings (TX filter...)
7603 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7604 {
7605 halPhySetRegDomain(pMac, DomainId);
7606 }*/
7607}
7608
7609
7610
7611eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7612{
7613 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7614 tANI_U32 len;
7615
7616 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7617 {
7618 len = *pbLen;
7619 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7620 if(HAL_STATUS_SUCCESS(status))
7621 {
7622 *pbLen = (tANI_U8)len;
7623 }
7624 }
7625
7626 return (status);
7627}
7628
7629
7630void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7631{
7632 tANI_U8 i, j;
7633 tANI_BOOLEAN found=FALSE;
7634 tANI_U8 *pControlList = NULL;
7635 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7636
Kiet Lam64c1b492013-07-12 13:56:44 +05307637 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007638 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307639 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007640 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7641 {
7642 for (i = 0; i < pChannelList->numChannels; i++)
7643 {
7644 for (j = 0; j < len; j += 2)
7645 {
7646 if (pControlList[j] == pChannelList->channelList[i])
7647 {
7648 found = TRUE;
7649 break;
7650 }
7651 }
7652
7653 if (found) // insert a pair(channel#, flag)
7654 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307655 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007656 found = FALSE; // reset the flag
7657 }
7658
7659 }
7660
Mihir Shete31c435d2014-02-12 13:13:34 +05307661 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7662 "%s: dump scan control list",__func__);
7663 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7664 pControlList, len);
7665
Jeff Johnson295189b2012-06-20 16:38:30 -07007666 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7667 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307668 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007669 }//AllocateMemory
7670}
7671
7672
7673//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7674eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7675{
7676 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7677}
7678
7679
7680void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7681{
7682 tListElem *pEntry = NULL;
7683 tSmeCmd *pCommand = NULL;
7684 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307685 tDblLinkList *pCmdList ;
7686
7687 if (!pMac->fScanOffload)
7688 pCmdList = &pMac->sme.smeCmdActiveList;
7689 else
7690 pCmdList = &pMac->sme.smeScanCmdActiveList;
7691
7692 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007693 if ( pEntry )
7694 {
7695 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7696 if ( eSmeCommandScan == pCommand->command )
7697 {
7698 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7699 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7700 }
7701 else
7702 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007703 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007704 }
7705 }
7706 smeProcessPendingQueue( pMac );
7707}
7708
7709eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7710{
7711 eHalStatus status;
7712 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7713 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7714
7715 //***setcfg for background scan channel list
7716 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7717 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7718 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7719 if(!csrIsAllSessionDisconnected(pMac))
7720 {
7721 //If disbaling BG scan here, we need to stop aging as well
7722 if(pScanReq->scanInterval == 0)
7723 {
7724 //Stop aging because no new result is coming in
7725 csrScanStopResultAgingTimer(pMac);
7726 }
7727
7728#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7729 {
7730 vos_log_scan_pkt_type *pScanLog = NULL;
7731
7732 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7733 if(pScanLog)
7734 {
7735 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7736 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7737 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7738 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7739 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7740 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7741 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307742 vos_mem_copy(pScanLog->channels,
7743 pScanReq->ChannelInfo.ChannelList,
7744 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007745 }
7746 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7747 }
7748 }
7749#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7750
7751 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7752 }
7753 else
7754 {
7755 //No need to stop aging because IDLE scan is still running
7756 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7757 }
7758
7759 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7760 {
7761 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7762 }
7763
7764 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7765 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7766
7767
7768
7769 return (status);
7770}
7771
7772
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05307773eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac, tANI_U8 sessionId,
7774 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07007775{
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307776 eHalStatus status = eHAL_STATUS_FAILURE;
7777 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007778 tANI_U16 msgLen;
7779 tListElem *pEntry;
7780 tSmeCmd *pCommand;
7781
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307782 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007783 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307784#ifdef WLAN_AP_STA_CONCURRENCY
7785 csrLLLock(&pMac->scan.scanCmdPendingList);
7786 while(NULL !=
7787 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7788 LL_ACCESS_NOLOCK)))
7789 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007790
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307791 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7792 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7793 }
7794 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007795#endif
7796
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307797 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7798 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7799 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7800 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7801
7802 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7803 }
7804 else
7805 {
7806 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7807 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7808 sessionId,
7809 &pMac->sme.smeScanCmdPendingList,
7810 eSmeCommandScan);
7811 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7812
7813 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7814 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007815
7816 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307817 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007818 {
7819 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307820 if(eSmeCommandScan == pCommand->command &&
7821 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007822 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307823 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05307824 pMsg = vos_mem_malloc(msgLen);
7825 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07007826 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307827 status = eHAL_STATUS_FAILURE;
7828 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
7829 }
7830 else
7831 {
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05307832 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
7833 {
7834 pCommand->u.scanCmd.abortScanDueToBandChange
7835 = eANI_BOOLEAN_TRUE;
7836 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307837 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007838 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7839 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307840 pMsg->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007841 status = palSendMBMessage(pMac->hHdd, pMsg);
7842 }
7843 }
7844 }
7845
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307846 return(status);
7847}
7848
7849void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
7850 tANI_U8 sessionId,
7851 tDblLinkList *pList,
7852 eSmeCommandType commandType)
7853{
7854 tDblLinkList localList;
7855 tListElem *pEntry;
7856 tSmeCmd *pCommand;
7857 tListElem *pEntryToRemove;
7858
7859 vos_mem_zero(&localList, sizeof(tDblLinkList));
7860 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7861 {
7862 smsLog(pMac, LOGE, FL(" failed to open list"));
7863 return;
7864 }
7865
7866 csrLLLock(pList);
7867 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
7868 {
7869
7870 /* Have to make sure we don't loop back to the head of the list,
7871 * which will happen if the entry is NOT on the list */
7872 while (pEntry)
7873 {
7874 pEntryToRemove = pEntry;
7875 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7876 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7877 if ((pCommand->command == commandType) &&
7878 (pCommand->sessionId == sessionId))
7879 {
7880 /* Remove that entry only */
7881 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7882 {
7883 csrLLInsertTail(&localList, pEntryToRemove,
7884 LL_ACCESS_NOLOCK);
7885 }
7886 }
7887 }
7888 }
7889 csrLLUnlock(pList);
7890
7891 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
7892 {
7893 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7894 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
7895 }
7896
7897 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007898}
7899
7900void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7901 eSmeCommandType commandType )
7902{
7903 tDblLinkList localList;
7904 tListElem *pEntry;
7905 tSmeCmd *pCommand;
7906 tListElem *pEntryToRemove;
7907
7908 vos_mem_zero(&localList, sizeof(tDblLinkList));
7909 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7910 {
7911 smsLog(pMac, LOGE, FL(" failed to open list"));
7912 return;
7913 }
7914
7915 csrLLLock(pList);
7916 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7917 {
7918 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7919
7920 // Have to make sure we don't loop back to the head of the list, which will
7921 // happen if the entry is NOT on the list...
7922 while( pEntry )
7923 {
7924 pEntryToRemove = pEntry;
7925 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7926 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7927 if ( pCommand->command == commandType )
7928 {
7929 // Remove that entry only
7930 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7931 {
7932 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7933 }
7934 }
7935 }
7936
7937
7938 }
7939 csrLLUnlock(pList);
7940
7941 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7942 {
7943 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7944 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7945 }
7946 csrLLClose(&localList);
7947
7948}
7949
7950
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307951eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
7952 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007953{
7954 eHalStatus status = eHAL_STATUS_SUCCESS;
7955
7956 if( !csrIsScanForRoamCommandActive( pMac ) )
7957 {
7958 //Only abort the scan if it is not used for other roam/connect purpose
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05307959 status = csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007960 }
7961
7962 return (status);
7963}
7964
7965
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307966eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007967{
7968 eHalStatus status = eHAL_STATUS_SUCCESS;
7969 tSirMbMsg *pMsg;
7970 tANI_U16 msgLen;
7971
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307972 if (pMac->fScanOffload)
7973 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
7974 else
7975 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
7976
Kiet Lam64c1b492013-07-12 13:56:44 +05307977 pMsg = vos_mem_malloc(msgLen);
7978 if ( NULL == pMsg )
7979 status = eHAL_STATUS_FAILURE;
7980 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007981 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307982 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007983 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7984 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307985 if (pMac->fScanOffload)
7986 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007987 status = palSendMBMessage(pMac->hHdd, pMsg);
7988 }
7989
7990 return( status );
7991}
7992
7993tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7994{
7995 tANI_BOOLEAN fValid = FALSE;
7996 tANI_U32 idxValidChannels;
7997 tANI_U32 len = pMac->roam.numValidChannels;
7998
7999 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8000 {
8001 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8002 {
8003 fValid = TRUE;
8004 break;
8005 }
8006 }
8007
8008 return fValid;
8009}
8010
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008011#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008012eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8013 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8014{
8015 v_U32_t uLen = 0;
8016 tpSirProbeRespBeacon pParsedFrame;
8017 tCsrScanResult *pScanResult = NULL;
8018 tSirBssDescription *pBssDescr = NULL;
8019 tANI_BOOLEAN fDupBss;
8020 tDot11fBeaconIEs *pIesLocal = NULL;
8021 tAniSSID tmpSsid;
8022 v_TIME_t timer=0;
8023 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
8024
8025 pParsedFrame =
Kiet Lam64c1b492013-07-12 13:56:44 +05308026 (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008027
8028 if (NULL == pParsedFrame)
8029 {
8030 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8031 return eHAL_STATUS_RESOURCES;
8032 }
8033
8034 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8035 {
8036 smsLog(pMac, LOGE,
8037 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8038 pPrefNetworkFoundInd->frameLength);
8039 vos_mem_free(pParsedFrame);
8040 return eHAL_STATUS_FAILURE;
8041 }
8042
8043 if (sirConvertProbeFrame2Struct(pMac,
8044 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8045 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8046 pParsedFrame) != eSIR_SUCCESS ||
8047 !pParsedFrame->ssidPresent)
8048 {
8049 smsLog(pMac, LOGE,
8050 FL("Parse error ProbeResponse, length=%d"),
8051 pPrefNetworkFoundInd->frameLength);
8052 vos_mem_free(pParsedFrame);
8053 return eHAL_STATUS_FAILURE;
8054 }
8055 //24 byte MAC header and 12 byte to ssid IE
8056 if (pPrefNetworkFoundInd->frameLength >
8057 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8058 {
8059 uLen = pPrefNetworkFoundInd->frameLength -
8060 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8061 }
8062
Kiet Lam64c1b492013-07-12 13:56:44 +05308063 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8064 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008065 {
8066 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8067 vos_mem_free(pParsedFrame);
8068 return eHAL_STATUS_RESOURCES;
8069 }
8070
Kiet Lam64c1b492013-07-12 13:56:44 +05308071 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008072 pBssDescr = &pScanResult->Result.BssDescriptor;
8073 /**
8074 * Length of BSS desription is without length of
8075 * length itself and length of pointer
8076 * that holds the next BSS description
8077 */
8078 pBssDescr->length = (tANI_U16)(
8079 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8080 sizeof(tANI_U32) + uLen);
8081 if (pParsedFrame->dsParamsPresent)
8082 {
8083 pBssDescr->channelId = pParsedFrame->channelNumber;
8084 }
8085 else if (pParsedFrame->HTInfo.present)
8086 {
8087 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8088 }
8089 else
8090 {
8091 pBssDescr->channelId = pParsedFrame->channelNumber;
8092 }
8093
8094 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
8095 {
8096 int i;
8097 // 11b or 11g packet
8098 // 11g iff extended Rate IE is present or
8099 // if there is an A rate in suppRate IE
8100 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
8101 {
8102 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
8103 {
8104 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8105 break;
8106 }
8107 }
8108 if (pParsedFrame->extendedRatesPresent)
8109 {
8110 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8111 }
8112 }
8113 else
8114 {
8115 // 11a packet
8116 pBssDescr->nwType = eSIR_11A_NW_TYPE;
8117 }
8118
8119 pBssDescr->sinr = 0;
8120 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8121 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05308122 if (!pBssDescr->beaconInterval)
8123 {
8124 smsLog(pMac, LOGW,
8125 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
8126 MAC_ADDR_ARRAY(pBssDescr->bssId) );
8127 pBssDescr->beaconInterval = 100;
8128 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07008129 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8130 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8131 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308132 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008133 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
8134
Arif Hussain24bafea2013-11-15 15:10:03 -08008135 smsLog( pMac, LOG2, "(%s):Bssid= "MAC_ADDRESS_STR
8136 " chan= %d, rssi = %d", __func__,
8137 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07008138 pBssDescr->channelId,
8139 pBssDescr->rssi );
8140
8141 //IEs
8142 if (uLen)
8143 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308144 vos_mem_copy(&pBssDescr->ieFields,
8145 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
8146 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008147 }
8148
8149 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
8150 if ( !pIesLocal &&
8151 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8152 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8153 {
8154 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8155 csrFreeScanResultEntry(pMac, pScanResult);
8156 vos_mem_free(pParsedFrame);
8157 return eHAL_STATUS_RESOURCES;
8158 }
8159
8160 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05308161 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008162 //Check whether we have reach out limit
8163 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8164 {
8165 //Limit reach
8166 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8167 //Free the resources
8168 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8169 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308170 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008171 }
8172 csrFreeScanResultEntry(pMac, pScanResult);
8173 vos_mem_free(pParsedFrame);
8174 return eHAL_STATUS_RESOURCES;
8175 }
8176 //Add to scan cache
8177 csrScanAddResult(pMac, pScanResult, pIesLocal);
8178
Kiet Lamb537cfb2013-11-07 12:56:49 +05308179 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8180 {
8181 vos_mem_free(pIesLocal);
8182 }
8183
Srikant Kuppa066904f2013-05-07 13:56:02 -07008184 vos_mem_free(pParsedFrame);
8185
8186 return eHAL_STATUS_SUCCESS;
8187}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008188#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008189
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008190#ifdef FEATURE_WLAN_LFR
8191void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8192{
8193 tListElem *pEntry = NULL;
8194 tCsrScanResult *pBssDesc = NULL;
8195 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008196 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8197
8198 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8199 {
8200 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008201 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008202 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8203 return;
8204 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008205
8206 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8207 {
8208 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008209 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008210 __func__, pMac->scan.occupiedChannels.numChannels);
8211 return;
8212 }
8213
8214 /* Empty occupied channels here */
8215 pMac->scan.occupiedChannels.numChannels = 0;
8216
8217 csrLLLock(&pMac->scan.scanResultList);
8218 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8219 while( pEntry )
8220 {
8221 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8222 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8223
8224 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008225 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008226 &pBssDesc->Result.BssDescriptor, &pIes))) )
8227 {
8228 continue;
8229 }
8230
8231 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8232
8233 /*
8234 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8235 */
8236 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8237 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308238 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008239 }
8240
8241 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8242 }//while
8243 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008244
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008245}
8246#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008247
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008248eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8249 tCsrBssid bssid, tANI_U8 channel)
8250{
8251 eHalStatus status = eHAL_STATUS_SUCCESS;
8252 tDot11fBeaconIEs *pNewIes = NULL;
8253 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008254 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008255 tANI_U32 size = 0;
8256
8257 if(NULL == pSession)
8258 {
8259 status = eHAL_STATUS_FAILURE;
8260 return status;
8261 }
8262 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008263 MAC_ADDRESS_STR),
8264 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008265 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008266 MAC_ADDRESS_STR" channel %d"),
8267 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008268
8269 do
8270 {
8271 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8272 pSession->pConnectBssDesc, &pNewIes)))
8273 {
8274 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8275 __func__);
8276 status = eHAL_STATUS_FAILURE;
8277 break;
8278 }
8279
8280 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308281 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008282 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308283 pNewBssDescriptor = vos_mem_malloc(size);
8284 if ( NULL == pNewBssDescriptor )
8285 status = eHAL_STATUS_FAILURE;
8286 else
8287 status = eHAL_STATUS_SUCCESS;
8288 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008289 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308290 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008291 }
8292 else
8293 {
8294 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8295 __func__);
8296 status = eHAL_STATUS_FAILURE;
8297 break;
8298 }
8299
8300 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308301 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008302 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008303 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008304 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008305 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008306 __func__);
8307 status = eHAL_STATUS_FAILURE;
8308 break;
8309 }
8310 }
8311 else
8312 {
8313 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8314 __func__);
8315 status = eHAL_STATUS_FAILURE;
8316 break;
8317 }
8318 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8319 __func__);
8320 }while(0);
8321
8322 if(pNewIes)
8323 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308324 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008325 }
8326 if(pNewBssDescriptor)
8327 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308328 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008329 }
8330 return status;
8331}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008332
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08008333#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008334// Update the TSF with the difference in system time
8335void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8336{
8337 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8338
8339 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8340 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8341 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8342}
8343#endif