blob: 48ea3881e194d45c33dfe45ee7c33fb85bfef887 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08002 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21/*
Jeff Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
24 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
25 *
26 *
27 * Permission to use, copy, modify, and/or distribute this software for
28 * any purpose with or without fee is hereby granted, provided that the
29 * above copyright notice and this permission notice appear in all
30 * copies.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
33 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
35 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
36 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
37 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 * PERFORMANCE OF THIS SOFTWARE.
40 */
41
Jeff Johnson40b59aa2013-03-19 14:43:18 -070042/** ------------------------------------------------------------------------- *
43 ------------------------------------------------------------------------- *
Jeff Johnson295189b2012-06-20 16:38:30 -070044
Jeff Johnson40b59aa2013-03-19 14:43:18 -070045
Jeff Johnson295189b2012-06-20 16:38:30 -070046 \file csrApiScan.c
Jeff Johnson40b59aa2013-03-19 14:43:18 -070047
Jeff Johnson295189b2012-06-20 16:38:30 -070048 Implementation for the Common Scan interfaces.
Jeff Johnson40b59aa2013-03-19 14:43:18 -070049
50 Copyright (C) 2006 Airgo Networks, Incorporated
Jeff Johnson295189b2012-06-20 16:38:30 -070051 ========================================================================== */
52
53#include "aniGlobal.h"
54
55#include "palApi.h"
56#include "csrInsideApi.h"
57#include "smeInside.h"
58#include "smsDebug.h"
59
60#include "csrSupport.h"
61#include "wlan_qct_tl.h"
62
63#include "vos_diag_core_log.h"
64#include "vos_diag_core_event.h"
65
66#include "vos_nvitem.h"
67#include "wlan_qct_wda.h"
Jeff Johnson40b59aa2013-03-19 14:43:18 -070068
Jeff Johnson295189b2012-06-20 16:38:30 -070069#define CSR_VALIDATE_LIST //This portion of code need to be removed once the issue is resolved.
70
71#ifdef CSR_VALIDATE_LIST
72tDblLinkList *g_pchannelPowerInfoList24 = NULL, * g_pchannelPowerInfoList5 = NULL;
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -070073tpAniSirGlobal g_pMac;
Jeff Johnson295189b2012-06-20 16:38:30 -070074#endif
75
76/* Purpose of HIDDEN_TIMER
77** When we remove hidden ssid from the profile i.e., forget the SSID via GUI that SSID shouldn't see in the profile
78** For above requirement we used timer limit, logic is explained below
79** Timer value is initialsed to current time when it receives corresponding probe response of hidden SSID (The probe request is
80** received regularly till SSID in the profile. Once it is removed from profile probe request is not sent.) when we receive probe response
81** 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
82** then we are not updating with old one
83*/
84
85#define HIDDEN_TIMER (1*60*1000)
86#define CSR_SCAN_RESULT_RSSI_WEIGHT 80 // must be less than 100, represent the persentage of new RSSI
87
88/*---------------------------------------------------------------------------
89 PER filter constant fraction: it is a %
90---------------------------------------------------------------------------*/
91#define CSR_SCAN_PER_FILTER_FRAC 100
92
93/*---------------------------------------------------------------------------
94 RSSI filter constant fraction: it is a %
95---------------------------------------------------------------------------*/
96#define CSR_SCAN_RSSI_FILTER_FRAC 100
97
98/*---------------------------------------------------------------------------
99Convert RSSI into overall score: Since RSSI is in -dBm values, and the
100overall needs to be weighted inversely (where greater value means better
101system), we convert.
102RSSI *cannot* be more than 0xFF or less than 0 for meaningful WLAN operation
103---------------------------------------------------------------------------*/
104#define CSR_SCAN_MAX_SCORE_VAL 0xFF
105#define CSR_SCAN_MIN_SCORE_VAL 0x0
106#define CSR_SCAN_HANDOFF_DELTA 10
Jeff Johnson32d95a32012-09-10 13:15:23 -0700107#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL 140
108#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL 120
Madan Mohan Koyyalamudia53c4dc2012-11-13 10:35:42 -0800109#define CSR_SCAN_OVERALL_SCORE( rssi ) \
110 (( rssi < CSR_SCAN_MAX_SCORE_VAL ) \
111 ? (CSR_SCAN_MAX_SCORE_VAL-rssi) : CSR_SCAN_MIN_SCORE_VAL)
Jeff Johnson295189b2012-06-20 16:38:30 -0700112
113
114#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
115 ( (pMac)->scan.nBssLimit <= (csrLLCount(&(pMac)->scan.scanResultList)) )
116
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530117/* Maximum number of channels per country can be ignored */
118#define MAX_CHANNELS_IGNORE 10
119
Madan Mohan Koyyalamudi28dd0422013-08-12 15:06:21 +0530120#define MAX_COUNTRY_IGNORE 4
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530121
122/*struct to hold the ignored channel list based on country */
123typedef struct sCsrIgnoreChannels
124{
125 tANI_U8 countryCode[NV_FIELD_COUNTRY_CODE_SIZE];
126 tANI_U16 channelList[MAX_CHANNELS_IGNORE];
127 tANI_U16 channelCount;
128}tCsrIgnoreChannels;
129
130static tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
131 { {'U','A'}, { 136, 140}, 2},
132 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
Madan Mohan Koyyalamudi28dd0422013-08-12 15:06:21 +0530133 { {'I','D'}, { 165}, 1 },
134 { {'A','U'}, { 120, 124, 128}, 3 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530135 };
136
Jeff Johnson295189b2012-06-20 16:38:30 -0700137//*** This is temporary work around. It need to call CCM api to get to CFG later
138/// Get string parameter value
139extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530140
Jeff Johnson295189b2012-06-20 16:38:30 -0700141void csrScanGetResultTimerHandler(void *);
142void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800143static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700144void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700145static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700146#ifdef WLAN_AP_STA_CONCURRENCY
147static void csrStaApConcTimerHandler(void *);
148#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700149tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700150eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
151void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
152void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
153void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
154void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
155//if bgPeriod is 0, background scan is disabled. It is in millisecond units
156eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
157eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
158void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
159static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
160 tANI_U8 numChn, tSirBssDescription *pBssDesc,
161 tDot11fBeaconIEs **ppIes );
162eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
163void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
164tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700165void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700166
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700167#define CSR_IS_SOCIAL_CHANNEL(channel) (((channel) == 1) || ((channel) == 6) || ((channel) == 11) )
168
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700169
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700170
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800171static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
172{
173 tListElem *pEntry;
174 tSmeCmd *pCommand;
175
176 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
177 {
178 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
179 if ( eSmeCsrCommandMask & pCommand->command )
180 {
181 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
182 }
183 else
184 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800185 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800186 }
187 }
188}
Jeff Johnson295189b2012-06-20 16:38:30 -0700189//pResult is invalid calling this function.
190void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
191{
192 if( NULL != pResult->Result.pvIes )
193 {
194 palFreeMemory( pMac->hHdd, pResult->Result.pvIes );
195 }
196 palFreeMemory(pMac->hHdd, pResult);
197}
198
199
200static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
201{
202 eHalStatus status = eHAL_STATUS_SUCCESS;
203 tListElem *pEntry;
204 tCsrScanResult *pBssDesc;
205
206 csrLLLock(pList);
207
208 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
209 {
210 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
211 csrFreeScanResultEntry( pMac, pBssDesc );
212 }
213
214 csrLLUnlock(pList);
215
216 return (status);
217}
218
219
220int csrCheckValidateLists(void * dest, const void *src, v_SIZE_t num, int idx)
221{
222#ifdef CSR_VALIDATE_LIST
223
224 int ii = 1;
225
226 if( (NULL == g_pMac) || (!g_pMac->scan.fValidateList ) )
227 {
228 return ii;
229 }
230 if(g_pchannelPowerInfoList24)
231 {
232 //check 2.4 list
233 tListElem *pElem, *pHead;
234 int count;
235
236 count = (int)(g_pchannelPowerInfoList24->Count);
237 pHead = &g_pchannelPowerInfoList24->ListHead;
238 pElem = pHead->next;
239 if((tANI_U32)(pHead->next) > 0x00010000) //Assuming kernel address is not that low.
240 {
241 //this loop crashes if the pointer is not right
242 while(pElem->next != pHead)
243 {
244 if((tANI_U32)(pElem->next) > 0x00010000)
245 {
246 pElem = pElem->next;
247 VOS_ASSERT(count > 0);
248 count--;
249 }
250 else
251 {
252 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL,
253 " %d Detect 1 list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
254 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
255 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
256 (unsigned int)dest, (unsigned int)src, (int)num);
257 VOS_ASSERT(0);
258 ii = 0;
259 break;
260 }
261 }
262 }
263 else
264 {
265 //Bad list
266 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL, " %d Detect list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
267 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
268 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
269 (unsigned int)dest, (unsigned int)src, (int)num);
270 VOS_ASSERT(0);
271 ii = 0;
272 }
273 }
274 else
275 {
276 //list ok
277 ii = 1;
278 }
279
280
281 return ii;
282
283#else
284 return 1;
285#endif //#ifdef CSR_VALIDATE_LIST
286}
287
288
289eHalStatus csrScanOpen( tpAniSirGlobal pMac )
290{
291 eHalStatus status;
292
293 do
294 {
295 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
296 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
297 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
298 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
299#ifdef WLAN_AP_STA_CONCURRENCY
300 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
301#endif
302#ifdef CSR_VALIDATE_LIST
303 g_pchannelPowerInfoList5 = &pMac->scan.channelPowerInfoList5G;
304 g_pMac = pMac;
305 g_pchannelPowerInfoList24 = &pMac->scan.channelPowerInfoList24;
306#endif
307 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
308 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530309 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
310 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700311 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800312 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700313 break;
314 }
315#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530316 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
317 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700318 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800319 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700320 break;
321 }
322#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530323 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
324 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700325 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800326 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700327 break;
328 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530329 status = vos_timer_init(&pMac->scan.hTimerResultAging, VOS_TIMER_TYPE_SW, csrScanResultAgingTimerHandler, pMac);
330 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700331 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800332 smsLog(pMac, LOGE, FL("cannot allocate memory for ResultAging timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700333 break;
334 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530335 status = vos_timer_init(&pMac->scan.hTimerResultCfgAging, VOS_TIMER_TYPE_SW,
336 csrScanResultCfgAgingTimerHandler, pMac);
337 if (!HAL_STATUS_SUCCESS(status))
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800338 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800339 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800340 break;
341 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700342 }while(0);
343
344 return (status);
345}
346
347
348eHalStatus csrScanClose( tpAniSirGlobal pMac )
349{
350#ifdef CSR_VALIDATE_LIST
351 g_pchannelPowerInfoList24 = NULL;
352 g_pchannelPowerInfoList5 = NULL;
353 g_pMac = NULL;
354#endif
355 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
356 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
357#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800358 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700359#endif
360 csrLLClose(&pMac->scan.scanResultList);
361 csrLLClose(&pMac->scan.tempScanResults);
362#ifdef WLAN_AP_STA_CONCURRENCY
363 csrLLClose(&pMac->scan.scanCmdPendingList);
364#endif
365 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
366 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
367 csrLLClose(&pMac->scan.channelPowerInfoList24);
368 csrLLClose(&pMac->scan.channelPowerInfoList5G);
369 csrScanDisable(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530370 vos_timer_destroy(&pMac->scan.hTimerResultAging);
371 vos_timer_destroy(&pMac->scan.hTimerResultCfgAging);
372 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700373#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530374 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700375#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530376 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Jeff Johnson295189b2012-06-20 16:38:30 -0700377 return eHAL_STATUS_SUCCESS;
378}
379
380
381eHalStatus csrScanEnable( tpAniSirGlobal pMac )
382{
383
384 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
385 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
386
387 return eHAL_STATUS_SUCCESS;
388}
389
390
391eHalStatus csrScanDisable( tpAniSirGlobal pMac )
392{
393
394 csrScanStopTimers(pMac);
395 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
396
397 return eHAL_STATUS_SUCCESS;
398}
399
400
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700401//Set scan timing parameters according to state of other driver sessions
402//No validation of the parameters is performed.
403static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
404{
405#ifdef WLAN_AP_STA_CONCURRENCY
406 if(csrIsAnySessionConnected(pMac))
407 {
408 //If multi-session, use the appropriate default scan times
409 if(scanType == eSIR_ACTIVE_SCAN)
410 {
411 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
412 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
413 }
414 else
415 {
416 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
417 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
418 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800419 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
420 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700421
422 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
423
424 //Return so that fields set above will not be overwritten.
425 return;
426 }
427#endif
428
429 //This portion of the code executed if multi-session not supported
430 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
431 //Use the "regular" (non-concurrency) default scan timing.
432 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
433 {
434 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
435 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
436 }
437 else
438 {
439 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
440 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
441 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800442 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
443 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700444
445#ifdef WLAN_AP_STA_CONCURRENCY
446 //No rest time if no sessions are connected.
447 pScanRequest->restTime = 0;
448#endif
449}
450
Jeff Johnson295189b2012-06-20 16:38:30 -0700451#ifdef WLAN_AP_STA_CONCURRENCY
452//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
453eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
454{
455 eHalStatus status = eHAL_STATUS_SUCCESS;
456
457 tANI_BOOLEAN fNoCmdPending;
458 tSmeCmd *pQueueScanCmd=NULL;
459 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700460 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700461 if (NULL == pScanCmd)
462 {
463 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
464 return eHAL_STATUS_FAILURE;
465 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800466 /* split scan if any one of the following:
467 * - STA session is connected and the scan is not a P2P search
468 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800469 * Do not split scans if no concurrent infra connections are
470 * active and if the scan is a BG scan triggered by LFR (OR)
471 * any scan if LFR is in the middle of a BG scan. Splitting
472 * the scan is delaying the time it takes for LFR to find
473 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800474 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700475
476 if(csrIsStaSessionConnected(pMac) &&
477 !csrIsP2pSessionConnected(pMac))
478 {
479 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
480 }
481 else if(csrIsP2pSessionConnected(pMac))
482 {
483 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
484 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800485 if ( (csrIsStaSessionConnected(pMac) &&
486#ifdef FEATURE_WLAN_LFR
487 (csrIsConcurrentInfraConnected(pMac) ||
488 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
489 (pMac->roam.neighborRoamInfo.neighborRoamState !=
490 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
491#endif
492 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800493 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700494 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700495 tCsrScanRequest scanReq;
496 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
497 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
498 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700499 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
500
501 if (numChn == 0)
502 {
503
504 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700505
Vinay Malekal05fdc812012-12-17 13:04:30 -0800506 status = palAllocateMemory( pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn );
507 if( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700508 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800509 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800510 return eHAL_STATUS_FAILURE;
511 }
512 bMemAlloc = eANI_BOOLEAN_TRUE;
513 status = palCopyMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
514 pMac->scan.baseChannels.channelList, numChn );
515 if( !HAL_STATUS_SUCCESS( status ) )
516 {
517 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
518 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800519 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800520 return eHAL_STATUS_FAILURE;
521 }
522 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
523 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700524
Vinay Malekal05fdc812012-12-17 13:04:30 -0800525 //Whenever we get a scan request with multiple channels we break it up into 2 requests
526 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700527 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800528 {
529 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
530
531 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
532 if (!pQueueScanCmd)
533 {
534 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700535 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800536 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
537 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
538
Jeff Johnson295189b2012-06-20 16:38:30 -0700539 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800540 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800541 return eHAL_STATUS_FAILURE;
542 }
543 pQueueScanCmd->command = pScanCmd->command;
544 pQueueScanCmd->sessionId = pScanCmd->sessionId;
545 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
546 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
547 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
548 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700549
Vinay Malekal05fdc812012-12-17 13:04:30 -0800550 /* First copy all the parameters to local variable of scan request */
551 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700552
Vinay Malekal05fdc812012-12-17 13:04:30 -0800553 /* Now modify the elements of local var scan request required to be modified for split scan */
554 if(scanReq.ChannelInfo.ChannelList != NULL)
555 {
556 palFreeMemory(pMac->hHdd, scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800557 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800558 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700559
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700560 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700561
Vinay Malekal05fdc812012-12-17 13:04:30 -0800562 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530563 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
564 &channelToScan[0], pScanCmd,
565 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700566
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700567 palCopyMemory(pMac->hHdd, &channelToScan[0], &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nNumChanCombinedConc],
Vinay Malekal05fdc812012-12-17 13:04:30 -0800568 pChnInfo->numOfChannels * sizeof(tANI_U8));
569
570 pChnInfo->ChannelList = &channelToScan[0];
571
572 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
573 //Modify callers parameters in case of concurrency
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530574 if (!pScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
575 scanReq.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800576 //Use concurrency values for min/maxChnTime.
577 //We know csrIsAnySessionConnected(pMac) returns TRUE here
578 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
579
580 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
581
582 if(!HAL_STATUS_SUCCESS(status))
583 {
584 if (bMemAlloc)
585 {
586 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
587 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
588
589 }
590 if( scanReq.pIEField != NULL)
591 {
592 palFreeMemory(pMac->hHdd, scanReq.pIEField);
593 scanReq.pIEField = NULL;
594 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800595 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800596 return eHAL_STATUS_FAILURE;
597 }
598 /* Clean the local scan variable */
599 scanReq.ChannelInfo.ChannelList = NULL;
600 scanReq.ChannelInfo.numOfChannels = 0;
601 csrScanFreeRequest(pMac, &scanReq);
602
603 /* setup the command to scan 2 channels */
604 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700605 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800606 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530607 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
608 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800609 //Use concurrency values for min/maxChnTime.
610 //We know csrIsAnySessionConnected(pMac) returns TRUE here
611 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
612 pSendScanCmd->u.scanCmd.callback = NULL;
613 } else {
614 pSendScanCmd = pScanCmd;
615 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530616 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
617 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800618 //Use concurrency values for min/maxChnTime.
619 //We know csrIsAnySessionConnected(pMac) returns TRUE here
620 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
621 }
622
623 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
624
625 //Logic Below is as follows
626 // If the scanCmdPendingList is empty then we directly send that command
627 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
628 if( fNoCmdPending )
629 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700630 if (pQueueScanCmd != NULL)
631 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800632 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700633 }
634
635 if (pSendScanCmd != NULL)
636 {
637 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
638 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800639 }
640 else
641 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700642 if (pSendScanCmd != NULL)
643 {
644 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
645 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800646
Jeff Johnson295189b2012-06-20 16:38:30 -0700647 if (pQueueScanCmd != NULL)
648 {
649 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
650 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800651 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700652 }
653 else
654 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800655 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800656 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800657 pScanCmd->u.scanCmd.reason,
658 pMac->roam.neighborRoamInfo.neighborRoamState,
659 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700660 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
661 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700662
663 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700664}
665#endif
666
Jeff Johnsone7245742012-09-05 17:12:55 -0700667/* ---------------------------------------------------------------------------
668 \fn csrScan2GOnyRequest
669 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800670 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700671 \param pMac
672 \param pScanCmd
673 \param pScanRequest
674 \return None
675 -------------------------------------------------------------------------------*/
676static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
677 tCsrScanRequest *pScanRequest)
678{
679 tANI_U8 index, channelId, channelListSize = 0;
680 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
681 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
682
683 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700684 /* To silence the KW tool null check is added */
685 if((pScanCmd == NULL) || (pScanRequest == NULL))
686 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800687 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700688 return;
689 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700690
691 if (pScanCmd->u.scanCmd.scanID ||
692 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
693 return;
694
695 //Contsruct valid Supported 2.4 GHz Channel List
696 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
697 {
698 channelId = channelList2G[index];
699 if ( csrIsSupportedChannel( pMac, channelId ) )
700 {
701 validchannelList[channelListSize++] = channelId;
702 }
703 }
704
705 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
706 pScanRequest->ChannelInfo.ChannelList = validchannelList;
707}
708
Jeff Johnson295189b2012-06-20 16:38:30 -0700709eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
710 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
711 csrScanCompleteCallback callback, void *pContext)
712{
713 eHalStatus status = eHAL_STATUS_FAILURE;
714 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700715 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700716
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800717 if(pScanRequest == NULL)
718 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800719 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800720 VOS_ASSERT(0);
721 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700722
Jeff Johnson295189b2012-06-20 16:38:30 -0700723 do
724 {
725 if(pMac->scan.fScanEnable)
726 {
727 pScanCmd = csrGetCommandBuffer(pMac);
728 if(pScanCmd)
729 {
730 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
731 pScanCmd->command = eSmeCommandScan;
732 pScanCmd->sessionId = sessionId;
733 pScanCmd->u.scanCmd.callback = callback;
734 pScanCmd->u.scanCmd.pContext = pContext;
735 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
736 {
737 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
738 }
739 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
740 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
741#ifdef SOFTAP_CHANNEL_RANGE
742 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
743#endif
744 )
745 {
746 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
747 }
748 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
749 {
750 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
751 }
752 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
753 {
754 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
755 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700756 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
757 {
758 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
759 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700760 else
761 {
762 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
763 }
764 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
765 {
766 //The caller doesn't set the time correctly. Set it here
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700767 csrSetDefaultScanTiming(pMac, pScanRequest->scanType, pScanRequest);
768 }
769#ifdef WLAN_AP_STA_CONCURRENCY
770 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800771 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700772 //Need to set restTime only if at least one session is connected
773 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700774 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700775 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700776 }
777 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700778#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700779 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530780 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800781 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
782 to take a long time.
783 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
784 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700785 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800786 if (HAL_STATUS_SUCCESS(status) &&
787 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700788 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
789 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
790 {
791 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
792 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
793 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800794
795 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
796 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700797 //Need to make the following atomic
798 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
799
800 if(pScanRequestID)
801 {
802 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
803 }
804
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800805 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700806 // If it is not, CSR will save the scan request in the pending cmd queue
807 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800808 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700809 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
810#ifdef SOFTAP_CHANNEL_RANGE
811 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
812#endif
813 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
814 )
815 {
816 tSmeCmd *p11dScanCmd;
817 tCsrScanRequest scanReq;
818 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
819
820 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
821
822 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800823 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700824 {
825 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
826
827 palZeroMemory(pMac->hHdd, &p11dScanCmd->u.scanCmd, sizeof(tScanCmd));
828 status = palAllocateMemory( pMac->hHdd, (void **)&pChnInfo->ChannelList, numChn );
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800829 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700830 {
831 break;
832 }
833 status = palCopyMemory( pMac->hHdd, pChnInfo->ChannelList,
834 pMac->scan.baseChannels.channelList, numChn );
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800835 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700836 {
837 palFreeMemory( pMac->hHdd, pChnInfo->ChannelList );
838 pChnInfo->ChannelList = NULL;
839 break;
840 }
841 pChnInfo->numOfChannels = (tANI_U8)numChn;
842 p11dScanCmd->command = eSmeCommandScan;
843 p11dScanCmd->u.scanCmd.callback = NULL;
844 p11dScanCmd->u.scanCmd.pContext = NULL;
845 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++;
846 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
847
848 if ( csrIs11dSupported(pMac) )
849 {
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530850 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
851 if (pScanRequest->bcnRptReqScan)
852 scanReq.scanType = pScanRequest->scanType ?
853 eSIR_PASSIVE_SCAN :
854 pScanRequest->scanType;
855 else
856 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700857 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
858 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
859 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
860 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
861 }
862 else
863 {
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530864 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
865 if (pScanRequest->bcnRptReqScan)
866 scanReq.scanType = pScanRequest->scanType;
867 else
868 scanReq.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700869 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
870 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
871 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
872 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800873
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530874 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
875 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700876 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700877
Jeff Johnson295189b2012-06-20 16:38:30 -0700878 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
879 //Free the channel list
880 palFreeMemory( pMac->hHdd, pChnInfo->ChannelList );
James Zmuda9ea1edd2013-04-18 18:20:54 -0700881 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700882
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800883 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700884 {
885 //Start process the command
886#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530887 if (!pMac->fScanOffload)
888 status = csrQueueScanRequest(pMac, p11dScanCmd);
889 else
890 status = csrQueueSmeCommand(pMac, p11dScanCmd,
891 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700892#else
893 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
894#endif
895 if( !HAL_STATUS_SUCCESS( status ) )
896 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800897 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700898 break;
899 }
900 }
901 else
902 {
903 break;
904 }
905 }
906 else
907 {
908 //error
909 break;
910 }
911 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700912
913 //Scan only 2G Channels if set in ini file
914 //This is mainly to reduce the First Scan duration
915 //Once we turn on Wifi
916 if(pMac->scan.fFirstScanOnly2GChnl)
917 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800918 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700919 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
920 }
921
Jeff Johnson295189b2012-06-20 16:38:30 -0700922 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
923 if(HAL_STATUS_SUCCESS(status))
924 {
925 //Start process the command
926#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530927 if (!pMac->fScanOffload)
928 status = csrQueueScanRequest(pMac,pScanCmd);
929 else
930 status = csrQueueSmeCommand(pMac, pScanCmd,
931 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700932#else
933 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
934#endif
935 if( !HAL_STATUS_SUCCESS( status ) )
936 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800937 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700938 break;
939 }
940 }
941 else
942 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800943 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700944 break;
945 }
946 }
947 else
948 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800949 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700950 break;
951 }
952 }
953 } while(0);
954 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
955 {
956 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
957 {
958 //Set the flag back for restarting idle scan
959 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
960 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800961 smsLog( pMac, LOGE, FL(" failed with status = %d, releasing scan cmd"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700962 csrReleaseCommandScan(pMac, pScanCmd);
963 }
964
965 return (status);
966}
967
968
969eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
970{
971 eHalStatus status = eHAL_STATUS_SUCCESS;
972 tSmeCmd *pScanCmd;
973
974 if(pMac->scan.fScanEnable)
975 {
976 pScanCmd = csrGetCommandBuffer(pMac);
977 if(pScanCmd)
978 {
979 pScanCmd->command = eSmeCommandScan;
980 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
981 pScanCmd->u.scanCmd.callback = NULL;
982 pScanCmd->u.scanCmd.pContext = NULL;
983 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
984 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700985 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700986 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
987 if( !HAL_STATUS_SUCCESS( status ) )
988 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800989 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700990 csrReleaseCommandScan(pMac, pScanCmd);
991 }
992 }
993 else
994 {
995 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800996 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700997 status = eHAL_STATUS_RESOURCES;
998 }
999 }
1000
1001 return (status);
1002}
1003
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001004#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1005eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1006 csrScanCompleteCallback callback, void *pContext)
1007{
1008 eHalStatus status = eHAL_STATUS_SUCCESS;
1009 tSmeCmd *pScanCmd;
1010
1011 if (pMac->scan.fScanEnable)
1012 {
1013 pScanCmd = csrGetCommandBuffer(pMac);
1014 if (pScanCmd)
1015 {
1016 pScanCmd->command = eSmeCommandScan;
1017 pScanCmd->sessionId = sessionId;
1018 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
1019 pScanCmd->u.scanCmd.callback = callback;
1020 pScanCmd->u.scanCmd.pContext = pContext;
1021 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1022 //Need to make the following atomic
1023 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1024 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1025 if ( !HAL_STATUS_SUCCESS( status ) )
1026 {
1027 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1028 csrReleaseCommandScan(pMac, pScanCmd);
1029 }
1030 }
1031 else
1032 {
1033 //log error
1034 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1035 status = eHAL_STATUS_RESOURCES;
1036 }
1037 }
1038
1039 return (status);
1040}
1041#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001042
1043eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1044{
1045 eHalStatus status = eHAL_STATUS_SUCCESS;
1046 tANI_U32 scanId;
1047 tCsrScanRequest scanReq;
1048
1049 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
1050 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1051 scanReq.scanType = eSIR_ACTIVE_SCAN;
1052 scanReq.requestType = reqType;
1053 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1054 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001055 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1056 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001057 //Scan with invalid sessionId.
1058 //This results in SME using the first available session to scan.
1059 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1060 &scanId, NULL, NULL);
1061
1062 return (status);
1063}
1064
1065
1066
1067
1068eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1069{
1070 eHalStatus status = eHAL_STATUS_FAILURE;
1071 tScanResultHandle hBSSList = NULL;
1072 tCsrScanResultFilter *pScanFilter = NULL;
1073 tANI_U32 roamId = 0;
1074 tCsrRoamProfile *pProfile = NULL;
1075 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1076
Jeff Johnson32d95a32012-09-10 13:15:23 -07001077 if(!pSession)
1078 {
1079 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1080 return eHAL_STATUS_FAILURE;
1081 }
1082
Jeff Johnson295189b2012-06-20 16:38:30 -07001083 do
1084 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001085 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001086 if(pSession->fCancelRoaming)
1087 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001088 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001089 csrScanStartIdleScan(pMac);
1090 status = eHAL_STATUS_SUCCESS;
1091 break;
1092 }
1093 //Here is the profile we need to connect to
1094 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1095 if(!HAL_STATUS_SUCCESS(status))
1096 break;
1097 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1098 if(NULL == pSession->pCurRoamProfile)
1099 {
1100 pScanFilter->EncryptionType.numEntries = 1;
1101 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1102 }
1103 else
1104 {
1105 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
1106 status = palAllocateMemory(pMac->hHdd, (void **)&pProfile, sizeof(tCsrRoamProfile));
1107 if(!HAL_STATUS_SUCCESS(status))
1108 break;
1109 palZeroMemory(pMac->hHdd, pProfile, sizeof(tCsrRoamProfile));
1110 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1111 if(!HAL_STATUS_SUCCESS(status))
1112 break;
1113 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1114 }//We have a profile
1115 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1116 if(HAL_STATUS_SUCCESS(status))
1117 {
1118 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1119 if(HAL_STATUS_SUCCESS(status))
1120 {
1121 if(eCsrLostLink1 == reason)
1122 {
1123 //we want to put the last connected BSS to the very beginning, if possible
1124 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1125 }
1126 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1127 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1128 if(!HAL_STATUS_SUCCESS(status))
1129 {
1130 csrScanResultPurge(pMac, hBSSList);
1131 }
1132 }//Have scan result
1133 }
1134 }while(0);
1135 if(pScanFilter)
1136 {
1137 //we need to free memory for filter if profile exists
1138 csrFreeScanFilter(pMac, pScanFilter);
1139 palFreeMemory(pMac->hHdd, pScanFilter);
1140 }
1141 if(NULL != pProfile)
1142 {
1143 csrReleaseProfile(pMac, pProfile);
1144 palFreeMemory(pMac->hHdd, (void *)pProfile);
1145 }
1146
1147 return (status);
1148}
1149
1150
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301151eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tANI_U8 sessionId,
1152 void *pContext, void *callback)
Jeff Johnson295189b2012-06-20 16:38:30 -07001153{
1154 eHalStatus status = eHAL_STATUS_SUCCESS;
1155 tSmeCmd *pScanCmd;
1156
1157 if(pMac->scan.fScanEnable)
1158 {
1159 pScanCmd = csrGetCommandBuffer(pMac);
1160 if(pScanCmd)
1161 {
1162 pScanCmd->command = eSmeCommandScan;
1163 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
Jeff Johnson32d95a32012-09-10 13:15:23 -07001164 pScanCmd->u.scanCmd.callback = callback;
1165 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001166 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1167 //Need to make the following atomic
1168 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301169 pScanCmd->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001170 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1171 if( !HAL_STATUS_SUCCESS( status ) )
1172 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001173 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001174 csrReleaseCommandScan(pMac, pScanCmd);
1175 }
1176 }
1177 else
1178 {
1179 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001180 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001181 status = eHAL_STATUS_RESOURCES;
1182 }
1183 }
1184
1185 return (status);
1186}
1187
1188
1189eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1190{
1191 eHalStatus status = eHAL_STATUS_FAILURE;
1192 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1193
Jeff Johnson32d95a32012-09-10 13:15:23 -07001194 if(!pSession)
1195 {
1196 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1197 return eHAL_STATUS_FAILURE;
1198 }
1199
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001200 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001201 if(pSession->fCancelRoaming)
1202 {
1203 csrScanStartIdleScan(pMac);
1204 }
1205 else if(pSession->pCurRoamProfile)
1206 {
1207 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1208 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1209 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1210 {
1211 //try lostlink scan2
1212 status = csrScanRequestLostLink2(pMac, sessionId);
1213 }
1214 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1215 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1216 {
1217 //go straight to lostlink scan3
1218 status = csrScanRequestLostLink3(pMac, sessionId);
1219 }
1220 else
1221 {
1222 //we are done with lostlink
1223 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1224 {
1225 csrScanStartIdleScan(pMac);
1226 }
1227 status = eHAL_STATUS_SUCCESS;
1228 }
1229 }
1230 else
1231 {
1232 status = csrScanRequestLostLink3(pMac, sessionId);
1233 }
1234
1235 return (status);
1236}
1237
1238
1239
1240eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1241{
1242 eHalStatus status = eHAL_STATUS_FAILURE;
1243 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1244
Jeff Johnson32d95a32012-09-10 13:15:23 -07001245 if(!pSession)
1246 {
1247 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1248 return eHAL_STATUS_FAILURE;
1249 }
1250
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001251 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001252 if(pSession->fCancelRoaming)
1253 {
1254 csrScanStartIdleScan(pMac);
1255 }
1256 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1257 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1258 {
1259 //try lostlink scan3
1260 status = csrScanRequestLostLink3(pMac, sessionId);
1261 }
1262 else
1263 {
1264 //we are done with lostlink
1265 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1266 {
1267 csrScanStartIdleScan(pMac);
1268 }
1269 }
1270
1271 return (status);
1272}
1273
1274
1275
1276eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1277{
1278 eHalStatus status = eHAL_STATUS_SUCCESS;
1279
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001280 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001281 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1282 {
1283 //we are done with lostlink
1284 csrScanStartIdleScan(pMac);
1285 }
1286
1287 return (status);
1288}
1289
1290
1291
1292
1293//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1294//If no roam profile (it should not), it is like lostlinkscan3
1295eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1296{
1297 eHalStatus status = eHAL_STATUS_SUCCESS;
1298 tSmeCmd *pCommand = NULL;
1299 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1300 tCsrScanResultFilter *pScanFilter = NULL;
1301 tScanResultHandle hBSSList = NULL;
1302 tCsrScanResultInfo *pScanResult = NULL;
1303 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1304
Jeff Johnson32d95a32012-09-10 13:15:23 -07001305 if(!pSession)
1306 {
1307 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1308 return eHAL_STATUS_FAILURE;
1309 }
1310
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001311 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001312 do
1313 {
1314 pCommand = csrGetCommandBuffer(pMac);
1315 if(!pCommand)
1316 {
1317 status = eHAL_STATUS_RESOURCES;
1318 break;
1319 }
1320 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1321 pCommand->command = eSmeCommandScan;
1322 pCommand->sessionId = (tANI_U8)sessionId;
1323 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1324 pCommand->u.scanCmd.callback = NULL;
1325 pCommand->u.scanCmd.pContext = NULL;
1326 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1327 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001328 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1329 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001330 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1331 if(pSession->connectedProfile.SSID.length)
1332 {
1333 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
1334 if(!HAL_STATUS_SUCCESS(status))
1335 {
1336 break;
1337 }
1338 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
1339 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1340 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
1341 }
1342 else
1343 {
1344 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1345 }
1346 if(pSession->pCurRoamProfile)
1347 {
1348 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1349 if(!HAL_STATUS_SUCCESS(status))
1350 {
1351 break;
1352 }
1353 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1354 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1355 if(!HAL_STATUS_SUCCESS(status))
1356 {
1357 break;
1358 }
1359 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1360 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1361 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1362 {
1363 tANI_U8 i, nChn = 0;
1364 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1365 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1366 if(!HAL_STATUS_SUCCESS(status))
1367 {
1368 break;
1369 }
1370 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1371 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1372 {
1373 for(i = 0; i < nChn; i++)
1374 {
1375 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1376 pScanResult->BssDescriptor.channelId)
1377 {
1378 break;
1379 }
1380 }
1381 if(i == nChn)
1382 {
1383 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1384 }
1385 }
1386 //Include the last connected BSS' channel
1387 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1388 {
1389 for(i = 0; i < nChn; i++)
1390 {
1391 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1392 pSession->connectedProfile.operationChannel)
1393 {
1394 break;
1395 }
1396 }
1397 if(i == nChn)
1398 {
1399 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1400 }
1401 }
1402 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1403 }
1404 else
1405 {
1406 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1407 {
1408 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1409 1);
1410 //just try the last connected channel
1411 if(HAL_STATUS_SUCCESS(status))
1412 {
1413 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1414 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1415 }
1416 else
1417 {
1418 break;
1419 }
1420 }
1421 }
1422 }
1423 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1424 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1425 if( !HAL_STATUS_SUCCESS( status ) )
1426 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001427 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001428 break;
1429 }
1430 } while( 0 );
1431
1432 if(!HAL_STATUS_SUCCESS(status))
1433 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001434 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001435 if(pCommand)
1436 {
1437 csrReleaseCommandScan(pMac, pCommand);
1438 }
1439 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1440 }
1441 if(pScanFilter)
1442 {
1443 csrFreeScanFilter(pMac, pScanFilter);
1444 palFreeMemory(pMac->hHdd, pScanFilter);
1445 }
1446 if(hBSSList)
1447 {
1448 csrScanResultPurge(pMac, hBSSList);
1449 }
1450
1451 return( status );
1452}
1453
1454
1455//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1456//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1457eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1458{
1459 eHalStatus status = eHAL_STATUS_SUCCESS;
1460 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1461 tCsrScanResultFilter *pScanFilter = NULL;
1462 tScanResultHandle hBSSList = NULL;
1463 tCsrScanResultInfo *pScanResult = NULL;
1464 tSmeCmd *pCommand = NULL;
1465 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1466
Jeff Johnson32d95a32012-09-10 13:15:23 -07001467 if(!pSession)
1468 {
1469 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1470 return eHAL_STATUS_FAILURE;
1471 }
1472
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001473 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001474 do
1475 {
1476 pCommand = csrGetCommandBuffer(pMac);
1477 if(!pCommand)
1478 {
1479 status = eHAL_STATUS_RESOURCES;
1480 break;
1481 }
1482 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1483 pCommand->command = eSmeCommandScan;
1484 pCommand->sessionId = (tANI_U8)sessionId;
1485 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1486 pCommand->u.scanCmd.callback = NULL;
1487 pCommand->u.scanCmd.pContext = NULL;
1488 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1489 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001490 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1491 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001492 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1493 if(pSession->pCurRoamProfile)
1494 {
1495 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1496 if(!HAL_STATUS_SUCCESS(status))
1497 {
1498 break;
1499 }
1500 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1501 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1502 if(!HAL_STATUS_SUCCESS(status))
1503 {
1504 break;
1505 }
1506 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1507 if(!HAL_STATUS_SUCCESS(status))
1508 {
1509 break;
1510 }
1511 if(hBSSList)
1512 {
1513 tANI_U8 i, nChn = 0;
1514 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1515 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1516 if(!HAL_STATUS_SUCCESS(status))
1517 {
1518 break;
1519 }
1520 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1521 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1522 {
1523 for(i = 0; i < nChn; i++)
1524 {
1525 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1526 pScanResult->BssDescriptor.channelId)
1527 {
1528 break;
1529 }
1530 }
1531 if(i == nChn)
1532 {
1533 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1534 }
1535 }
1536 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1537 }
1538 }
1539 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1540 //Put to the head in pending queue
1541 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1542 if( !HAL_STATUS_SUCCESS( status ) )
1543 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001544 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001545 break;
1546 }
1547 } while( 0 );
1548
1549 if(!HAL_STATUS_SUCCESS(status))
1550 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001551 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001552 if(pCommand)
1553 {
1554 csrReleaseCommandScan(pMac, pCommand);
1555 }
1556 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1557 }
1558 if(pScanFilter)
1559 {
1560 csrFreeScanFilter(pMac, pScanFilter);
1561 palFreeMemory(pMac->hHdd, pScanFilter);
1562 }
1563 if(hBSSList)
1564 {
1565 csrScanResultPurge(pMac, hBSSList);
1566 }
1567
1568 return( status );
1569}
1570
1571
1572//To actively scan all valid channels
1573eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1574{
1575 eHalStatus status = eHAL_STATUS_SUCCESS;
1576 tSmeCmd *pCommand;
1577 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1578
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001579 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001580 do
1581 {
1582 pCommand = csrGetCommandBuffer(pMac);
1583 if(!pCommand)
1584 {
1585 status = eHAL_STATUS_RESOURCES;
1586 break;
1587 }
1588 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1589 pCommand->command = eSmeCommandScan;
1590 pCommand->sessionId = (tANI_U8)sessionId;
1591 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1592 pCommand->u.scanCmd.callback = NULL;
1593 pCommand->u.scanCmd.pContext = NULL;
1594 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1595 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001596 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1597 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001598 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1599 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1600 //Put to the head of pending queue
1601 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1602 if( !HAL_STATUS_SUCCESS( status ) )
1603 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001604 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001605 break;
1606 }
1607 } while( 0 );
1608 if(!HAL_STATUS_SUCCESS(status))
1609 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001610 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001611 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1612 {
1613 csrScanStartIdleScan(pMac);
1614 }
1615 if(pCommand)
1616 {
1617 csrReleaseCommandScan(pMac, pCommand);
1618 }
1619 }
1620
1621 return( status );
1622}
1623
1624
1625eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1626{
1627 eHalStatus status = eHAL_STATUS_FAILURE;
1628 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1629 tCsrScanResultFilter *pScanFilter = NULL;
1630 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1631 tANI_U32 sessionId = pCommand->sessionId;
1632#ifdef FEATURE_WLAN_BTAMP_UT_RF
1633 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1634#endif
1635 do
1636 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001637#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1638 //if this scan is for LFR
1639 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1640 {
1641 //notify LFR state m/c
1642 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1643 {
Varun Reddy Yeturue3af4282013-06-07 00:56:52 -07001644 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001645 }
1646 status = eHAL_STATUS_SUCCESS;
1647 break;
1648 }
1649#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001650 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1651 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1652 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001653 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001654 break;
1655 }
1656 if(pProfile == NULL)
1657 break;
1658 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1659 if(!HAL_STATUS_SUCCESS(status))
1660 break;
1661 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1662 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1663 if(!HAL_STATUS_SUCCESS(status))
1664 break;
1665 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1666 if(!HAL_STATUS_SUCCESS(status))
1667 break;
1668 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1669 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1670 if(!HAL_STATUS_SUCCESS(status))
1671 {
1672 break;
1673 }
1674 }while(0);
1675 if(!HAL_STATUS_SUCCESS(status))
1676 {
1677 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1678 {
1679 csrScanResultPurge(pMac, hBSSList);
1680 }
1681 //We haven't done anything to this profile
1682 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1683 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1684 //In case we have nothing else to do, restart idle scan
1685 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1686 {
1687 status = csrScanStartIdleScan(pMac);
1688 }
1689#ifdef FEATURE_WLAN_BTAMP_UT_RF
1690 //In case of WDS station, let it retry.
1691 if( CSR_IS_WDS_STA(pProfile) )
1692 {
1693 //Save the roma profile so we can retry
1694 csrFreeRoamProfile( pMac, sessionId );
1695 if (HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd,
1696 (void **)&pSession->pCurRoamProfile,
1697 sizeof(tCsrRoamProfile))))
1698 {
1699 palZeroMemory(pMac->hHdd, pSession->pCurRoamProfile, sizeof(tCsrRoamProfile));
1700 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1701 }
1702 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1703 }
1704#endif
1705 }
1706 if(pScanFilter)
1707 {
1708 csrFreeScanFilter(pMac, pScanFilter);
1709 palFreeMemory(pMac->hHdd, pScanFilter);
1710 }
1711
1712 return (status);
1713}
1714
1715
1716eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1717{
1718 eHalStatus status = eHAL_STATUS_SUCCESS;
1719 tANI_U32 sessionId = pCommand->sessionId;
1720 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1721 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001722#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1723 //if this scan is for LFR
1724 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1725 {
1726 //notify LFR state m/c
1727 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1728 {
Varun Reddy Yeturue3af4282013-06-07 00:56:52 -07001729 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001730 }
1731 return eHAL_STATUS_SUCCESS;
1732 }
1733#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001734 if(!pSession)
1735 {
1736 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1737 return eHAL_STATUS_FAILURE;
1738 }
1739
Jeff Johnson295189b2012-06-20 16:38:30 -07001740#if defined(WLAN_DEBUG)
1741 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1742 {
1743 char str[36];
1744 palCopyMemory(pMac->hHdd, str, pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1745 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
1746 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001747 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001748 }
1749#endif
1750 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1751 if(pProfile && CSR_IS_START_IBSS(pProfile))
1752 {
1753 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1754 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1755 if(!HAL_STATUS_SUCCESS(status))
1756 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001757 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001758 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1759 }
1760 }
1761 else
1762 {
1763 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1764
1765 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1766 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1767 {
1768 status = csrScanStartIdleScan(pMac);
1769 }
1770 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1771 {
1772 //Only indicate assoc_completion if we indicate assoc_start.
1773 if(pSession->bRefAssocStartCnt > 0)
1774 {
1775 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
1776 palZeroMemory(pMac->hHdd, &roamInfo, sizeof(tCsrRoamInfo));
1777 pRoamInfo = &roamInfo;
1778 if(pCommand->u.roamCmd.pRoamBssEntry)
1779 {
1780 tCsrScanResult *pScanResult =
1781 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1782 tCsrScanResult, Link);
1783 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1784 }
1785 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1786 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1787 pSession->bRefAssocStartCnt--;
1788 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1789 pCommand->u.scanCmd.roamId,
1790 eCSR_ROAM_ASSOCIATION_COMPLETION,
1791 eCSR_ROAM_RESULT_FAILURE);
1792 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001793 else
1794 {
1795 csrRoamCallCallback(pMac, sessionId, NULL,
1796 pCommand->u.scanCmd.roamId,
1797 eCSR_ROAM_ASSOCIATION_FAILURE,
1798 eCSR_ROAM_RESULT_FAILURE);
1799 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001800#ifdef FEATURE_WLAN_BTAMP_UT_RF
1801 //In case of WDS station, let it retry.
1802 if( CSR_IS_WDS_STA(pProfile) )
1803 {
1804 //Save the roma profile so we can retry
1805 csrFreeRoamProfile( pMac, sessionId );
1806 if (HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd,
1807 (void **)&pSession->pCurRoamProfile,
1808 sizeof(tCsrRoamProfile))))
1809 {
1810 palZeroMemory(pMac->hHdd, pSession->pCurRoamProfile, sizeof(tCsrRoamProfile));
1811 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1812 }
1813 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1814 }
1815#endif
1816 }
1817 else
1818 {
1819 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1820 }
1821 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1822 }
1823
1824 return (status);
1825}
1826
1827
1828//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1829eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1830{
1831 eHalStatus status = eHAL_STATUS_FAILURE;
1832 tScanResultHandle hBSSList = NULL;
1833 tCsrScanResultFilter *pScanFilter = NULL;
1834 tANI_U32 roamId = 0;
1835 tCsrRoamProfile *pProfile = NULL;
1836 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1837
1838 do
1839 {
1840 //Here is the profile we need to connect to
1841 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1842 if(!HAL_STATUS_SUCCESS(status))
1843 break;
1844 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1845 if(NULL == pSession) break;
1846 if(NULL == pSession->pCurRoamProfile)
1847 {
1848 pScanFilter->EncryptionType.numEntries = 1;
1849 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1850 }
1851 else
1852 {
1853 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
1854 status = palAllocateMemory(pMac->hHdd, (void **)&pProfile, sizeof(tCsrRoamProfile));
1855 if(!HAL_STATUS_SUCCESS(status))
1856 break;
1857 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1858 if(!HAL_STATUS_SUCCESS(status))
1859 break;
1860 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1861 }//We have a profile
1862 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1863 if(HAL_STATUS_SUCCESS(status))
1864 {
1865 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1866 if(HAL_STATUS_SUCCESS(status))
1867 {
1868 //we want to put the last connected BSS to the very beginning, if possible
1869 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1870 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1871 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1872 if(!HAL_STATUS_SUCCESS(status))
1873 {
1874 csrScanResultPurge(pMac, hBSSList);
1875 }
1876 }//Have scan result
1877 else
1878 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001879 smsLog(pMac, LOGW, FL("cannot find matching BSS of %02X-%02X-%02X-%02X-%02X-%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001880 pSession->connectedProfile.bssid[0],
1881 pSession->connectedProfile.bssid[1],
1882 pSession->connectedProfile.bssid[2],
1883 pSession->connectedProfile.bssid[3],
1884 pSession->connectedProfile.bssid[4],
1885 pSession->connectedProfile.bssid[5]);
1886 //Disconnect
1887 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1888 }
1889 }
1890 }while(0);
1891 if(pScanFilter)
1892 {
1893 csrFreeScanFilter(pMac, pScanFilter);
1894 palFreeMemory(pMac->hHdd, pScanFilter);
1895 }
1896 if(NULL != pProfile)
1897 {
1898 csrReleaseProfile(pMac, pProfile);
1899 palFreeMemory(pMac->hHdd, pProfile);
1900 }
1901
1902 return (status);
1903}
1904
1905
1906
1907eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1908{
1909 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1910 tScanResultList *pScanList = (tScanResultList *)hScanList;
1911
1912 if(pScanList)
1913 {
1914 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1915 csrLLClose(&pScanList->List);
1916 palFreeMemory(pMac->hHdd, pScanList);
1917 }
1918 return (status);
1919}
1920
1921
1922static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1923{
1924 tANI_U32 ret = 0;
1925 int i = CSR_NUM_RSSI_CAT - 1;
1926
1927 while(i >= 0)
1928 {
1929 if(rssi >= pMac->roam.configParam.RSSICat[i])
1930 {
1931 ret = pMac->roam.configParam.BssPreferValue[i];
1932 break;
1933 }
1934 i--;
1935 };
1936
1937 return (ret);
1938}
1939
1940
1941//Return a CapValue base on the capabilities of a BSS
1942static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
1943{
1944 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08001945#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
1946 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
1947 {
1948 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
1949 {
1950 ret += CSR_BSS_CAP_VALUE_5GHZ;
1951 }
1952 }
1953#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001954 if( pIes )
1955 {
1956 //We only care about 11N capability
1957 if(pIes->HTCaps.present)
1958 {
1959 ret += CSR_BSS_CAP_VALUE_HT;
1960 }
1961 if(CSR_IS_QOS_BSS(pIes))
1962 {
1963 ret += CSR_BSS_CAP_VALUE_WMM;
1964 //Give advantage to UAPSD
1965 if(CSR_IS_UAPSD_BSS(pIes))
1966 {
1967 ret += CSR_BSS_CAP_VALUE_UAPSD;
1968 }
1969 }
1970 }
1971
1972 return (ret);
1973}
1974
1975
1976//To check whther pBss1 is better than pBss2
1977static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
1978{
1979 tANI_BOOLEAN ret;
1980
1981 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
1982 {
1983 ret = eANI_BOOLEAN_TRUE;
1984 }
1985 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
1986 {
1987 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
1988 {
1989 ret = eANI_BOOLEAN_TRUE;
1990 }
1991 else
1992 {
1993 ret = eANI_BOOLEAN_FALSE;
1994 }
1995 }
1996 else
1997 {
1998 ret = eANI_BOOLEAN_FALSE;
1999 }
2000
2001 return (ret);
2002}
2003
2004
Srikant Kuppa866893f2012-12-27 17:28:14 -08002005#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002006//Add the channel to the occupiedChannels array
2007static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002008 tpAniSirGlobal pMac,
2009 tCsrScanResult *pResult,
2010 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002011 tDot11fBeaconIEs *pIes)
2012{
2013 eHalStatus status;
2014 tANI_U8 channel;
2015 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2016 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2017
2018 channel = pResult->Result.BssDescriptor.channelId;
2019
2020 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002021 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002022 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002023 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002024 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002025 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002026 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002027 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002028 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002029 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2030 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2031 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002032 }
2033}
2034#endif
2035
Jeff Johnson295189b2012-06-20 16:38:30 -07002036//Put the BSS into the scan result list
2037//pIes can not be NULL
2038static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2039{
Srinivas28b5b4e2012-12-12 13:07:53 -08002040#ifdef FEATURE_WLAN_LFR
2041 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2042#endif
2043
Jeff Johnson295189b2012-06-20 16:38:30 -07002044 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2045 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2046 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002047#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002048 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2049 {
2050 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2051 NOT set in the cfg.ini file */
2052 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2053 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002054#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002055}
2056
2057
2058eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2059{
2060 eHalStatus status;
2061 tScanResultList *pRetList;
2062 tCsrScanResult *pResult, *pBssDesc;
2063 tANI_U32 count = 0;
2064 tListElem *pEntry;
2065 tANI_U32 bssLen, allocLen;
2066 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2067 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2068 tDot11fBeaconIEs *pIes, *pNewIes;
2069 tANI_BOOLEAN fMatch;
2070
2071 if(phResult)
2072 {
2073 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2074 }
2075 status = palAllocateMemory(pMac->hHdd, (void **)&pRetList, sizeof(tScanResultList));
2076 if(HAL_STATUS_SUCCESS(status))
2077 {
2078 palZeroMemory(pMac->hHdd, pRetList, sizeof(tScanResultList));
2079 csrLLOpen(pMac->hHdd, &pRetList->List);
2080 pRetList->pCurEntry = NULL;
2081
2082 csrLLLock(&pMac->scan.scanResultList);
2083 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2084 while( pEntry )
2085 {
2086 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2087 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2088 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2089 //for any error condition, otherwiase, it will be freed later.
2090 //reset
2091 fMatch = eANI_BOOLEAN_FALSE;
2092 pNewIes = NULL;
2093
2094 if(pFilter)
2095 {
2096 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2097 if( NULL != pIes )
2098 {
2099 //Only save it when matching
2100 if(fMatch)
2101 {
2102 if( !pBssDesc->Result.pvIes )
2103 {
2104 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2105 pNewIes = pIes;
2106 }
2107 else
2108 {
2109 //The pIes is allocated by someone else. make a copy
2110 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2111 //is using to for association, hence save the parsed IEs
2112 status = palAllocateMemory(pMac->hHdd, (void **)&pNewIes, sizeof(tDot11fBeaconIEs));
2113 if( HAL_STATUS_SUCCESS( status ) )
2114 {
2115 palCopyMemory( pMac->hHdd, pNewIes, pIes, sizeof( tDot11fBeaconIEs ) );
2116 }
2117 else
2118 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002119 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002120 //Need to free memory allocated by csrMatchBSS
2121 if( !pBssDesc->Result.pvIes )
2122 {
2123 palFreeMemory(pMac->hHdd, pIes);
2124 }
2125 break;
2126 }
2127 }
2128 }//fMatch
2129 else if( !pBssDesc->Result.pvIes )
2130 {
2131 palFreeMemory(pMac->hHdd, pIes);
2132 }
2133 }
2134 }
2135 if(NULL == pFilter || fMatch)
2136 {
2137 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2138 allocLen = sizeof( tCsrScanResult ) + bssLen;
2139 status = palAllocateMemory(pMac->hHdd, (void **)&pResult, allocLen);
2140 if(!HAL_STATUS_SUCCESS(status))
2141 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002142 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002143 if(pNewIes)
2144 {
2145 palFreeMemory(pMac->hHdd, pNewIes);
2146 }
2147 break;
2148 }
2149 palZeroMemory(pMac->hHdd, pResult, allocLen);
2150 pResult->capValue = pBssDesc->capValue;
2151 pResult->preferValue = pBssDesc->preferValue;
2152 pResult->ucEncryptionType = uc;
2153 pResult->mcEncryptionType = mc;
2154 pResult->authType = auth;
2155 pResult->Result.ssId = pBssDesc->Result.ssId;
2156 pResult->Result.timer = 0;
2157 //save the pIes for later use
2158 pResult->Result.pvIes = pNewIes;
2159 //save bss description
2160 status = palCopyMemory(pMac->hHdd, &pResult->Result.BssDescriptor, &pBssDesc->Result.BssDescriptor, bssLen);
2161 if(!HAL_STATUS_SUCCESS(status))
2162 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002163 smsLog(pMac, LOGE, FL(" fail to copy memory for scan result"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002164 palFreeMemory(pMac->hHdd, pResult);
2165 if(pNewIes)
2166 {
2167 palFreeMemory(pMac->hHdd, pNewIes);
2168 }
2169 break;
2170 }
2171 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2172 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2173 {
2174 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2175 }
2176 else
2177 {
2178 //To sort the list
2179 tListElem *pTmpEntry;
2180 tCsrScanResult *pTmpResult;
2181
2182 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2183 while(pTmpEntry)
2184 {
2185 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2186 if(csrIsBetterBss(pResult, pTmpResult))
2187 {
2188 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2189 //To indicate we are done
2190 pResult = NULL;
2191 break;
2192 }
2193 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2194 }
2195 if(pResult != NULL)
2196 {
2197 //This one is not better than any one
2198 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2199 }
2200 }
2201 count++;
2202 }
2203 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2204 }//while
2205 csrLLUnlock(&pMac->scan.scanResultList);
2206
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002207 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002208
2209 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2210 {
2211 //Fail or No one wants the result.
2212 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2213 }
2214 else
2215 {
2216 if(0 == count)
2217 {
2218 //We are here meaning the there is no match
2219 csrLLClose(&pRetList->List);
2220 palFreeMemory(pMac->hHdd, pRetList);
2221 status = eHAL_STATUS_E_NULL_VALUE;
2222 }
2223 else if(phResult)
2224 {
2225 *phResult = pRetList;
2226 }
2227 }
2228 }//Allocated pRetList
2229
2230 return (status);
2231}
2232
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002233/*
2234 * NOTE: This routine is being added to make
2235 * sure that scan results are not being flushed
2236 * while roaming. If the scan results are flushed,
2237 * we are unable to recover from
2238 * csrRoamRoamingStateDisassocRspProcessor.
2239 * If it is needed to remove this routine,
2240 * first ensure that we recover gracefully from
2241 * csrRoamRoamingStateDisassocRspProcessor if
2242 * csrScanGetResult returns with a failure because
2243 * of not being able to find the roaming BSS.
2244 */
2245tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2246{
2247 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2248 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2249 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2250 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2251 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2252 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2253 default:
2254 return 0;
2255 }
2256}
2257
Jeff Johnson295189b2012-06-20 16:38:30 -07002258eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2259{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002260 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
2261 if (isFlushDenied) {
2262 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2263 __func__, isFlushDenied);
2264 return eHAL_STATUS_FAILURE;
2265 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002266 return ( csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList) );
2267}
2268
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302269eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002270{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302271 eHalStatus status = eHAL_STATUS_SUCCESS;
2272 tListElem *pEntry,*pFreeElem;
2273 tCsrScanResult *pBssDesc;
2274 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002275
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302276 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002277
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302278 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2279 while( pEntry != NULL)
2280 {
2281 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2282 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2283 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002284 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302285 pFreeElem = pEntry;
2286 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2287 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2288 csrFreeScanResultEntry( pMac, pBssDesc );
2289 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002290 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302291 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2292 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002293
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302294 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002295
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302296 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002297}
2298
Jeff Johnson295189b2012-06-20 16:38:30 -07002299/**
2300 * csrCheck11dChannel
2301 *
2302 *FUNCTION:
2303 * This function is called from csrScanFilter11dResult function and
2304 * compare channel number with given channel list.
2305 *
2306 *LOGIC:
2307 * Check Scan result channel number with CFG channel list
2308 *
2309 *ASSUMPTIONS:
2310 *
2311 *
2312 *NOTE:
2313 *
2314 * @param channelId channel number
2315 * @param pChannelList Pointer to channel list
2316 * @param numChannels Number of channel in channel list
2317 *
2318 * @return Status
2319 */
2320
2321eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2322{
2323 eHalStatus status = eHAL_STATUS_FAILURE;
2324 tANI_U8 i = 0;
2325
2326 for (i = 0; i < numChannels; i++)
2327 {
2328 if(pChannelList[ i ] == channelId)
2329 {
2330 status = eHAL_STATUS_SUCCESS;
2331 break;
2332 }
2333 }
2334 return status;
2335}
2336
2337/**
2338 * csrScanFilter11dResult
2339 *
2340 *FUNCTION:
2341 * This function is called from csrApplyCountryInformation function and
2342 * filter scan result based on valid channel list number.
2343 *
2344 *LOGIC:
2345 * Get scan result from scan list and Check Scan result channel number
2346 * with 11d channel list if channel number is found in 11d channel list
2347 * then do not remove scan result entry from scan list
2348 *
2349 *ASSUMPTIONS:
2350 *
2351 *
2352 *NOTE:
2353 *
2354 * @param pMac Pointer to Global MAC structure
2355 *
2356 * @return Status
2357 */
2358
2359eHalStatus csrScanFilter11dResult(tpAniSirGlobal pMac)
2360{
2361 eHalStatus status = eHAL_STATUS_SUCCESS;
2362 tListElem *pEntry,*pTempEntry;
2363 tCsrScanResult *pBssDesc;
2364 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2365
2366 /* Get valid channels list from CFG */
2367 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2368 pMac->roam.validChannelList, &len)))
2369 {
2370 smsLog( pMac, LOG1, "Failed to get Channel list from CFG");
2371 }
2372
2373 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2374 while( pEntry )
2375 {
2376 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2377 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2378 LL_ACCESS_LOCK );
2379 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2380 pMac->roam.validChannelList, len))
2381 {
2382 /* Remove Scan result which does not have 11d channel */
2383 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2384 LL_ACCESS_LOCK ))
2385 {
2386 csrFreeScanResultEntry( pMac, pBssDesc );
2387 }
2388 }
2389 pEntry = pTempEntry;
2390 }
2391 return status;
2392}
2393
2394
2395eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2396{
2397 eHalStatus status = eHAL_STATUS_SUCCESS;
2398 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2399 tCsrScanResult *pResult, *pScanResult;
2400 tANI_U32 count = 0;
2401 tListElem *pEntry;
2402 tANI_U32 bssLen, allocLen;
2403
2404 if(phResult)
2405 {
2406 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2407 }
2408 status = palAllocateMemory(pMac->hHdd, (void **)&pRetList, sizeof(tScanResultList));
2409 if(HAL_STATUS_SUCCESS(status))
2410 {
2411 palZeroMemory(pMac->hHdd, pRetList, sizeof(tScanResultList));
2412 csrLLOpen(pMac->hHdd, &pRetList->List);
2413 pRetList->pCurEntry = NULL;
2414 csrLLLock(&pMac->scan.scanResultList);
2415 csrLLLock(&pInList->List);
2416
2417 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2418 while( pEntry )
2419 {
2420 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2421 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2422 allocLen = sizeof( tCsrScanResult ) + bssLen;
2423 status = palAllocateMemory(pMac->hHdd, (void **)&pResult, allocLen);
2424 if(!HAL_STATUS_SUCCESS(status))
2425 {
2426 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2427 count = 0;
2428 break;
2429 }
2430 palZeroMemory(pMac->hHdd, pResult, allocLen);
2431 status = palCopyMemory(pMac->hHdd, &pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
2432 if(!HAL_STATUS_SUCCESS(status))
2433 {
2434 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2435 count = 0;
2436 break;
2437 }
2438 if( pScanResult->Result.pvIes )
2439 {
2440 status = palAllocateMemory(pMac->hHdd, (void **)&pResult->Result.pvIes, sizeof( tDot11fBeaconIEs ));
2441 if(!HAL_STATUS_SUCCESS(status))
2442 {
2443 //Free the memory we allocate above first
2444 palFreeMemory( pMac->hHdd, pResult );
2445 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2446 count = 0;
2447 break;
2448 }
2449 status = palCopyMemory(pMac->hHdd, pResult->Result.pvIes,
2450 pScanResult->Result.pvIes, sizeof( tDot11fBeaconIEs ));
2451 if(!HAL_STATUS_SUCCESS(status))
2452 {
2453 //Free the memory we allocate above first
2454 palFreeMemory( pMac->hHdd, pResult );
2455 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2456 count = 0;
2457 break;
2458 }
2459 }
2460 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2461 count++;
2462 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2463 }//while
2464 csrLLUnlock(&pInList->List);
2465 csrLLUnlock(&pMac->scan.scanResultList);
2466
2467 if(HAL_STATUS_SUCCESS(status))
2468 {
2469 if(0 == count)
2470 {
2471 csrLLClose(&pRetList->List);
2472 palFreeMemory(pMac->hHdd, pRetList);
2473 status = eHAL_STATUS_E_NULL_VALUE;
2474 }
2475 else if(phResult)
2476 {
2477 *phResult = pRetList;
2478 }
2479 }
2480 }//Allocated pRetList
2481
2482 return (status);
2483}
2484
2485
2486
2487eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2488{
2489 eHalStatus status = eHAL_STATUS_SUCCESS;
2490 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2491
2492 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2493 {
2494 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2495 }
2496 else
2497 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002498 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002499 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002500 tCsrRoamSession *pSession;
2501 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2502 tCsrRoamInfo roamInfo;
2503 tCsrRoamInfo *pRoamInfo = NULL;
2504 tANI_U32 sessionId;
2505 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002506 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002507 palZeroMemory(pMac->hHdd, &roamInfo, sizeof(tCsrRoamInfo));
2508 pRoamInfo = &roamInfo;
2509 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2510 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2511 pSession = CSR_GET_SESSION(pMac, sessionId);
2512
2513 if(!pSession)
2514 {
2515 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2516 return eHAL_STATUS_FAILURE;
2517 }
2518
2519 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2520 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2521 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2522 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2523 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2524 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2525 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
2526 palCopyMemory(pMac->hHdd, pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2527 palCopyMemory(pMac->hHdd, &pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
2528 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2529 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2530 {
2531 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2532 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2533 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2534 }
2535 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2536 {
2537 vos_sleep( 100 );
2538 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2539 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2540 }
2541
Jeff Johnson295189b2012-06-20 16:38:30 -07002542 }
2543 else
2544 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002545
2546 if( csrIsAnySessionInConnectState( pMac ) )
2547 {
2548 //In case of we are connected, we need to check whether connect status changes
2549 //because scan may also run while connected.
2550 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2551 }
2552 else
2553 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002554 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002555 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002556 }
2557 }
2558
2559 return (status);
2560}
2561
2562
2563
2564void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2565{
2566 int idx, len;
2567 tANI_U8 *pbIe;
2568
2569 //If failed to remove, assuming someone else got it.
2570 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2571 (0 == pNewBssDescr->WscIeLen))
2572 {
2573 idx = 0;
2574 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2575 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2576 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2577 //Save WPS IE if it exists
2578 pNewBssDescr->WscIeLen = 0;
2579 while(idx < len)
2580 {
2581 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2582 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2583 {
2584 //Founrd it
2585 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2586 {
2587 palCopyMemory(pMac->hHdd, pNewBssDescr->WscIeProbeRsp,
2588 pbIe, pbIe[1] + 2);
2589 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2590 }
2591 break;
2592 }
2593 idx += pbIe[1] + 2;
2594 pbIe += pbIe[1] + 2;
2595 }
2596 }
2597}
2598
2599
2600
2601//pIes may be NULL
2602tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302603 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002604{
2605 tListElem *pEntry;
2606
2607 tCsrScanResult *pBssDesc;
2608 tANI_BOOLEAN fRC = FALSE;
2609
2610 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2611 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2612 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2613 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2614
2615 while( pEntry )
2616 {
2617 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2618
2619 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2620 // matches
2621 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07002622 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002623 {
2624 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2625 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2626 // Remove the 'old' entry from the list....
2627 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2628 {
2629 // !we need to free the memory associated with this node
2630 //If failed to remove, assuming someone else got it.
2631 *pSsid = pBssDesc->Result.ssId;
2632 *timer = pBssDesc->Result.timer;
2633 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2634
2635 csrFreeScanResultEntry( pMac, pBssDesc );
2636 }
2637 else
2638 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002639 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002640 }
2641 fRC = TRUE;
2642
2643 // If we found a match, we can stop looking through the list.
2644 break;
2645 }
2646
2647 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2648 }
2649
2650 return fRC;
2651}
2652
2653
2654eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2655 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2656{
2657 eHalStatus status = eHAL_STATUS_FAILURE;
2658 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2659
Jeff Johnson32d95a32012-09-10 13:15:23 -07002660 if(!pSession)
2661 {
2662 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2663 return eHAL_STATUS_FAILURE;
2664 }
2665
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002666 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002667 if( pIes )
2668 {
2669 // check if this is a RSN BSS
2670 if( pIes->RSN.present )
2671 {
2672 // Check if the BSS is capable of doing pre-authentication
2673 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2674 {
2675
2676#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2677 {
2678 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
2679 palZeroMemory(pMac->hHdd, &secEvent, sizeof(vos_event_wlan_security_payload_type));
2680 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2681 secEvent.encryptionModeMulticast =
2682 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2683 secEvent.encryptionModeUnicast =
2684 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
2685 palCopyMemory( pMac->hHdd, secEvent.bssid, pSession->connectedProfile.bssid, 6 );
2686 secEvent.authMode =
2687 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2688 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2689 }
2690#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2691
2692 // if yes, then add to PMKIDCandidateList
2693 status = palCopyMemory(pMac->hHdd, pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2694 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2695
2696 if( HAL_STATUS_SUCCESS( status ) )
2697 {
Venkata Prathyusha Kuntupalliea7098e2013-01-31 16:08:13 -08002698 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 ) // Bit 0 offirst byte - PreAuthentication Capability
Jeff Johnson295189b2012-06-20 16:38:30 -07002699 {
2700 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported = eANI_BOOLEAN_TRUE;
2701 }
2702 else
2703 {
2704 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported = eANI_BOOLEAN_FALSE;
2705 }
2706 pSession->NumPmkidCandidate++;
2707 }
2708 }
2709 else
2710 {
2711 status = eHAL_STATUS_FAILURE;
2712 }
2713 }
2714 }
2715
2716 return (status);
2717}
2718
2719//This function checks whether new AP is found for the current connected profile
2720//If it is found, it return the sessionId, else it return invalid sessionID
2721tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2722 tSirBssDescription *pBssDesc,
2723 tDot11fBeaconIEs *pIes)
2724{
2725 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2726 tCsrRoamSession *pSession;
2727 tDot11fBeaconIEs *pIesLocal = pIes;
2728
2729 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2730 {
2731 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2732 {
2733 if( CSR_IS_SESSION_VALID( pMac, i ) )
2734 {
2735 pSession = CSR_GET_SESSION( pMac, i );
2736 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2737 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2738 {
2739 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2740 {
2741 //this new BSS fits the current profile connected
2742 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2743 {
2744 bRet = i;
2745 }
2746 break;
2747 }
2748 }
2749 }
2750 }
2751 if( !pIes )
2752 {
2753 palFreeMemory(pMac->hHdd, pIesLocal);
2754 }
2755 }
2756
2757 return (tANI_U8)bRet;
2758}
2759
2760#ifdef FEATURE_WLAN_WAPI
2761eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2762 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2763{
2764 eHalStatus status = eHAL_STATUS_FAILURE;
2765 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2766
Jeff Johnson32d95a32012-09-10 13:15:23 -07002767 if(!pSession)
2768 {
2769 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2770 return eHAL_STATUS_FAILURE;
2771 }
2772
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002773 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002774 if( pIes )
2775 {
2776 // check if this is a WAPI BSS
2777 if( pIes->WAPI.present )
2778 {
2779 // Check if the BSS is capable of doing pre-authentication
2780 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
2781 {
2782
2783 // if yes, then add to BKIDCandidateList
2784 status = palCopyMemory(pMac->hHdd, pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
2785 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2786
2787 if( HAL_STATUS_SUCCESS( status ) )
2788 {
2789 if ( pIes->WAPI.preauth )
2790 {
2791 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported = eANI_BOOLEAN_TRUE;
2792 }
2793 else
2794 {
2795 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported = eANI_BOOLEAN_FALSE;
2796 }
2797 pSession->NumBkidCandidate++;
2798 }
2799 }
2800 else
2801 {
2802 status = eHAL_STATUS_FAILURE;
2803 }
2804 }
2805 }
2806
2807 return (status);
2808}
2809
2810//This function checks whether new AP is found for the current connected profile
2811//if so add to BKIDCandidateList
2812tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
2813 tDot11fBeaconIEs *pIes)
2814{
2815 tANI_BOOLEAN fRC = FALSE;
2816 tDot11fBeaconIEs *pIesLocal = pIes;
2817 tANI_U32 sessionId;
2818 tCsrRoamSession *pSession;
2819
2820 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2821 {
2822 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
2823 {
2824 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
2825 {
2826 pSession = CSR_GET_SESSION( pMac, sessionId );
2827 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
2828 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
2829 {
2830 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
2831 {
2832 //this new BSS fits the current profile connected
2833 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
2834 {
2835 fRC = TRUE;
2836 }
2837 }
2838 }
2839 }
2840 }
2841 if(!pIes)
2842 {
2843 palFreeMemory(pMac->hHdd, pIesLocal);
2844 }
2845
2846 }
2847 return fRC;
2848}
2849
2850#endif
2851
2852
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002853static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07002854{
2855 tListElem *pEntry;
2856 tCsrScanResult *pBssDescription;
2857 tANI_S8 cand_Bss_rssi;
2858 tANI_BOOLEAN fDupBss;
2859#ifdef FEATURE_WLAN_WAPI
2860 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
2861#endif /* FEATURE_WLAN_WAPI */
2862 tDot11fBeaconIEs *pIesLocal = NULL;
2863 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
2864 tAniSSID tmpSsid;
2865 v_TIME_t timer=0;
2866
2867 tmpSsid.length = 0;
2868 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
2869
2870 // remove the BSS descriptions from temporary list
2871 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
2872 {
2873 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2874
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002875 smsLog( pMac, LOGW, "...Bssid= %02x-%02x-%02x-%02x-%02x-%02x chan= %d, rssi = -%d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002876 pBssDescription->Result.BssDescriptor.bssId[ 0 ], pBssDescription->Result.BssDescriptor.bssId[ 1 ],
2877 pBssDescription->Result.BssDescriptor.bssId[ 2 ], pBssDescription->Result.BssDescriptor.bssId[ 3 ],
2878 pBssDescription->Result.BssDescriptor.bssId[ 4 ], pBssDescription->Result.BssDescriptor.bssId[ 5 ],
2879 pBssDescription->Result.BssDescriptor.channelId,
2880 pBssDescription->Result.BssDescriptor.rssi * (-1) );
2881
2882 //At this time, pBssDescription->Result.pvIes may be NULL
2883 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
2884 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
2885 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002886 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002887 csrFreeScanResultEntry(pMac, pBssDescription);
2888 continue;
2889 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302890 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002891 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
2892 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
2893#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2894 && !( eCsrScanGetLfrResult == reason )
2895#endif
2896 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002897 {
2898 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002899 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002900 //Free the resources
2901 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2902 {
2903 palFreeMemory(pMac->hHdd, pIesLocal);
2904 }
2905 csrFreeScanResultEntry(pMac, pBssDescription);
2906 //Continue because there may be duplicated BSS
2907 continue;
2908 }
2909 // check for duplicate scan results
2910 if ( !fDupBss )
2911 {
2912 //Found a new BSS
2913 sessionId = csrProcessBSSDescForPMKIDList(pMac,
2914 &pBssDescription->Result.BssDescriptor, pIesLocal);
2915 if( CSR_SESSION_ID_INVALID != sessionId)
2916 {
2917 csrRoamCallCallback(pMac, sessionId, NULL, 0,
2918 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
2919 }
2920 }
2921 else
2922 {
2923 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
2924 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
2925 {
2926 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
2927 //if diff of saved SSID time and current time is less than 1 min to avoid
2928 //side effect of saving SSID with old one is that if AP changes its SSID while remain
2929 //hidden, we may never see it and also to address the requirement of
2930 //When we remove hidden ssid from the profile i.e., forget the SSID via
2931 // GUI that SSID shouldn't see in the profile
2932 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
2933 {
2934 pBssDescription->Result.timer = timer;
2935 pBssDescription->Result.ssId = tmpSsid;
2936 }
2937 }
2938 }
2939
2940 //Tush: find a good AP for 11d info
2941 if( csrIs11dSupported( pMac ) )
2942 {
2943 if(cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
2944 {
2945 // check if country information element is present
2946 if(pIesLocal->Country.present)
2947 {
2948 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
2949 // learn country information
2950 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
Leela Venkata Kiran Kumar Reddy Chirala4d8f56d2013-09-05 15:21:31 -07002951 pIesLocal, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07002952 }
2953
2954 }
2955 }
2956
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08002957
Jeff Johnson295189b2012-06-20 16:38:30 -07002958 // append to main list
2959 csrScanAddResult(pMac, pBssDescription, pIesLocal);
2960 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2961 {
2962 palFreeMemory(pMac->hHdd, pIesLocal);
2963 }
2964 }
2965
2966 //Tush: If we can find the current 11d info in any of the scan results, or
2967 // a good enough AP with the 11d info from the scan results then no need to
2968 // get into ambiguous state
2969 if(pMac->scan.fAmbiguous11dInfoFound)
2970 {
2971 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
2972 {
2973 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
2974 }
2975 }
2976
2977#ifdef FEATURE_WLAN_WAPI
2978 if(fNewWapiBSSForCurConnection)
2979 {
2980 //remember it first
2981 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
2982 }
2983#endif /* FEATURE_WLAN_WAPI */
2984
2985 return;
2986}
2987
2988
2989static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
2990 tDot11fBeaconIEs *pIes)
2991{
2992 tCsrScanResult *pCsrBssDescription = NULL;
2993 tANI_U32 cbBSSDesc;
2994 tANI_U32 cbAllocated;
2995 eHalStatus halStatus;
2996
2997 // figure out how big the BSS description is (the BSSDesc->length does NOT
2998 // include the size of the length field itself).
2999 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3000
3001 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3002
3003 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pCsrBssDescription, cbAllocated );
3004 if ( HAL_STATUS_SUCCESS(halStatus) )
3005 {
3006 palZeroMemory( pMac->hHdd, pCsrBssDescription, cbAllocated );
3007 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
3008 palCopyMemory(pMac->hHdd, &pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
3009#if defined(VOSS_ENSBALED)
3010 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3011#endif
3012 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3013 }
3014
3015 return( pCsrBssDescription );
3016}
3017
3018// Append a Bss Description...
3019tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3020 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003021 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003022{
3023 tCsrScanResult *pCsrBssDescription = NULL;
3024 tAniSSID tmpSsid;
3025 v_TIME_t timer = 0;
3026 int result;
3027
3028 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003029 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003030 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3031 if (result && (pCsrBssDescription != NULL))
3032 {
3033 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3034 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3035 {
3036 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3037 //if diff of saved SSID time and current time is less than 1 min to avoid
3038 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3039 //hidden, we may never see it and also to address the requirement of
3040 //When we remove hidden ssid from the profile i.e., forget the SSID via
3041 // GUI that SSID shouldn't see in the profile
3042 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3043 {
3044 pCsrBssDescription->Result.ssId = tmpSsid;
3045 pCsrBssDescription->Result.timer = timer;
3046 }
3047 }
3048 }
3049
3050
3051 return( pCsrBssDescription );
3052}
3053
3054
3055
3056void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3057{
3058 tCsrChannelPowerInfo *pChannelSet;
3059 tListElem *pEntry;
3060
3061 csrLLLock(pChannelList);
3062 // Remove the channel sets from the learned list and put them in the free list
3063 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3064 {
3065 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3066 if( pChannelSet )
3067 {
3068 palFreeMemory( pMac->hHdd, pChannelSet );
3069 }
3070 }
3071 csrLLUnlock(pChannelList);
3072 return;
3073}
3074
3075
3076/*
3077 * Save the channelList into the ultimate storage as the final stage of channel
3078 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3079 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003080eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003081{
3082 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3083 tSirMacChanInfo *pChannelInfo;
3084 tCsrChannelPowerInfo *pChannelSet;
3085 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3086 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
3087 eHalStatus halStatus;
3088
3089 pChannelInfo = channelTable;
3090 // atleast 3 bytes have to be remaining -- from "countryString"
3091 while ( i-- )
3092 {
3093 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pChannelSet, sizeof(tCsrChannelPowerInfo) );
3094 if ( eHAL_STATUS_SUCCESS == halStatus )
3095 {
3096 palZeroMemory(pMac->hHdd, pChannelSet, sizeof(tCsrChannelPowerInfo));
3097 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3098 pChannelSet->numChannels = pChannelInfo->numChannels;
3099
3100 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003101 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003102 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003103
Jeff Johnson295189b2012-06-20 16:38:30 -07003104 {
3105 pChannelSet->interChannelOffset = 1;
3106 f2GHzInfoFound = TRUE;
3107 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003108 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003109 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003110 {
3111 pChannelSet->interChannelOffset = 4;
3112 f2GHzInfoFound = FALSE;
3113 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003114 else
3115 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003116 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003117 pChannelSet->firstChannel);
3118 palFreeMemory(pMac->hHdd, pChannelSet);
3119 return eHAL_STATUS_FAILURE;
3120 }
3121
Jeff Johnson295189b2012-06-20 16:38:30 -07003122 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3123
3124 if( f2GHzInfoFound )
3125 {
3126 if( !f2GListPurged )
3127 {
3128 // purge previous results if found new
3129 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3130 f2GListPurged = TRUE;
3131 }
3132
3133 if(CSR_IS_OPERATING_BG_BAND(pMac))
3134 {
3135 // add to the list of 2.4 GHz channel sets
3136 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3137 }
3138 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003139 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003140 pChannelSet->firstChannel);
3141 palFreeMemory(pMac->hHdd, pChannelSet);
3142 }
3143 }
3144 else
3145 {
3146 // 5GHz info found
3147 if( !f5GListPurged )
3148 {
3149 // purge previous results if found new
3150 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3151 f5GListPurged = TRUE;
3152 }
3153
3154 if(CSR_IS_OPERATING_A_BAND(pMac))
3155 {
3156 // add to the list of 5GHz channel sets
3157 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3158 }
3159 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003160 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003161 pChannelSet->firstChannel);
3162 palFreeMemory(pMac->hHdd, pChannelSet);
3163 }
3164 }
3165 }
3166
3167 pChannelInfo++; // move to next entry
3168 }
3169
Jeff Johnsone7245742012-09-05 17:12:55 -07003170 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003171}
3172
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303173static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3174{
3175 tSirMbMsg *pMsg;
3176 tANI_U16 msgLen;
3177 eHalStatus status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003178
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303179 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
3180 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
3181 if(HAL_STATUS_SUCCESS(status))
3182 {
3183 palZeroMemory(pMac->hHdd, (void *)pMsg, msgLen);
3184 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3185 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3186 palSendMBMessage(pMac->hHdd, pMsg);
3187 }
3188}
Jeff Johnson295189b2012-06-20 16:38:30 -07003189
3190void csrApplyPower2Current( tpAniSirGlobal pMac )
3191{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003192 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003193 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3194 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3195}
3196
3197
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003198void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003199{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303200 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003201 eNVChannelEnabledType channelEnabledType;
3202 tANI_U8 numChannels = 0;
3203 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303204 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003205 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303206
Jeff Johnson295189b2012-06-20 16:38:30 -07003207 if( pChannelList->numChannels )
3208 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303209 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3210 {
3211 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3212 VOS_COUNTRY_CODE_LEN))
3213 {
3214 countryIndex = count;
3215 break;
3216 }
3217 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003218 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3219 /* If user doesn't want to scan the DFS channels lets trim them from
3220 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303221 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003222 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303223 channelIgnore = FALSE;
3224 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3225 {
3226 channelEnabledType =
3227 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3228 }
3229 else
3230 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003231 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303232 }
3233 if( NV_CHANNEL_ENABLE == channelEnabledType )
3234 {
3235 if( countryIndex != -1 )
3236 {
3237 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3238 {
3239 if( pChannelList->channelList[i] ==
3240 countryIgnoreList[countryIndex].channelList[j] )
3241 {
3242 channelIgnore = TRUE;
3243 break;
3244 }
3245 }
3246 }
3247 if( FALSE == channelIgnore )
3248 {
3249 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3250 numChannels++;
3251 }
3252 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003253 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303254 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003255 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3256 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303257 // build a scan list based on the channel list : channel# + active/passive scan
3258 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303259 /*Send msg to Lim to clear DFS channel list */
3260 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003261#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003262 if (updateRiva)
3263 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003264 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003265 // Send HAL UpdateScanParams message
3266 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3267 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003268#endif // FEATURE_WLAN_SCAN_PNO
3269 }
3270 else
3271 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003272 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003273 }
3274 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3275 csrSetCfgCountryCode(pMac, countryCode);
3276}
3277
3278
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003279void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003280{
3281 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3282 {
3283
3284#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3285 {
3286 vos_log_802_11d_pkt_type *p11dLog;
3287 int Index;
3288
3289 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3290 if(p11dLog)
3291 {
3292 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
3293 palCopyMemory(pMac->hHdd, p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
3294 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3295 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3296 {
3297 palCopyMemory(pMac->hHdd, p11dLog->Channels, pMac->scan.base20MHzChannels.channelList,
3298 p11dLog->numChannel);
3299 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3300 {
3301 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3302 }
3303 }
3304 if(!pMac->roam.configParam.Is11dSupportEnabled)
3305 {
3306 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3307 }
3308 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3309 {
3310 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3311 }
3312 else
3313 {
3314 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3315 }
3316 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3317 }
3318 }
3319#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3320
3321 // switch to passive scans only when 11d is enabled
3322 if( csrIs11dSupported( pMac ) )
3323 {
3324 pMac->scan.curScanType = eSIR_PASSIVE_SCAN;
3325 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003326
3327 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3328 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3329
Jeff Johnson295189b2012-06-20 16:38:30 -07003330 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3331 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3332 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003333 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003334 // clear the 11d channel list
3335 palZeroMemory( pMac->hHdd, &pMac->scan.channels11d, sizeof(pMac->scan.channels11d) );
3336 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3337 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3338 }
3339
3340 return;
3341}
3342
3343
3344eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3345{
3346 eHalStatus status = eHAL_STATUS_SUCCESS;
3347 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3348
3349 //Use the Country code and domain from EEPROM
3350 palCopyMemory(pMac->hHdd, pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault, WNI_CFG_COUNTRY_CODE_LEN);
3351 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003352 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3353 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003354 {
3355 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003356 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003357 }
3358 if(pfRestartNeeded)
3359 {
3360 *pfRestartNeeded = fRestart;
3361 }
3362
3363 return (status);
3364}
3365
3366
3367eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3368{
3369 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3370 v_REGDOMAIN_t domainId;
3371
3372 if(pCountry)
3373 {
3374 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId);
3375 if(HAL_STATUS_SUCCESS(status))
3376 {
3377 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3378 if(HAL_STATUS_SUCCESS(status))
3379 {
3380 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3381 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
3382 palCopyMemory(pMac->hHdd, pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
3383 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3384 {
3385 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3386 csrSetCfgCountryCode(pMac, pCountry);
3387 }
3388 }
3389 }
3390 }
3391
3392 return (status);
3393}
3394
3395
3396
3397//caller allocated memory for pNumChn and pChnPowerInfo
3398//As input, *pNumChn has the size of the array of pChnPowerInfo
3399//Upon return, *pNumChn has the number of channels assigned.
3400void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3401 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3402{
3403 tListElem *pEntry;
3404 tANI_U32 chnIdx = 0, idx;
3405 tCsrChannelPowerInfo *pChannelSet;
3406
3407 //Get 2.4Ghz first
3408 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3409 while( pEntry && (chnIdx < *pNumChn) )
3410 {
3411 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3412 if ( 1 != pChannelSet->interChannelOffset )
3413 {
3414 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3415 {
3416 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3417 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3418 }
3419 }
3420 else
3421 {
3422 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3423 {
3424 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3425 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3426 }
3427 }
3428
3429 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3430 }
3431 *pNumChn = chnIdx;
3432
3433 return ;
3434}
3435
3436
3437
3438void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3439{
3440 v_REGDOMAIN_t domainId;
3441 eHalStatus status = eHAL_STATUS_SUCCESS;
3442
3443 do
3444 {
3445 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3446 if( pMac->scan.fAmbiguous11dInfoFound )
3447 {
3448 // ambiguous info found
3449 //Restore te default domain as well
3450 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCodeCurrent, &domainId )))
3451 {
3452 pMac->scan.domainIdCurrent = domainId;
3453 }
3454 else
3455 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003456 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003457 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3458 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003459 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003460 break;
3461 }
3462 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
3463 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCode11d, &domainId )))
3464 {
3465 //Check whether we need to enforce default domain
3466 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3467 (pMac->scan.domainIdCurrent == domainId) )
3468 {
3469
3470#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3471 {
3472 vos_log_802_11d_pkt_type *p11dLog;
3473 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3474 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3475
3476 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3477 if(p11dLog)
3478 {
3479 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
3480 palCopyMemory(pMac->hHdd, p11dLog->countryCode, pMac->scan.countryCode11d, 3);
3481 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3482 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3483 {
3484 palCopyMemory(pMac->hHdd, p11dLog->Channels, pMac->scan.channels11d.channelList,
3485 p11dLog->numChannel);
3486 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3487 &nChnInfo, chnPwrInfo);
3488 nTmp = nChnInfo;
3489 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3490 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3491 &nChnInfo, &chnPwrInfo[nTmp]);
3492 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3493 {
3494 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3495 {
3496 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3497 {
3498 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3499 break;
3500 }
3501 }
3502 }
3503 }
3504 if(!pMac->roam.configParam.Is11dSupportEnabled)
3505 {
3506 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3507 }
3508 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3509 {
3510 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3511 }
3512 else
3513 {
3514 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3515 }
3516 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3517 }
3518 }
3519#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3520 if(pMac->scan.domainIdCurrent != domainId)
3521 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003522 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3523 pMac->scan.domainIdCurrent, domainId);
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05303524 status = WDA_SetRegDomain(pMac, domainId);
Jeff Johnson295189b2012-06-20 16:38:30 -07003525 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003526 if (status != eHAL_STATUS_SUCCESS)
3527 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003528 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003529 }
3530 pMac->scan.domainIdCurrent = domainId;
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003531 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.channels11d, pMac->scan.countryCode11d, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003532 // switch to active scans using this new channel list
3533 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3534 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3535 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3536 }
3537 }
3538
3539 } while( 0 );
3540
3541 return;
3542}
3543
3544
3545
3546tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3547 tANI_BOOLEAN fForce)
3548{
3549 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3550 tANI_U32 i;
3551
3552 // convert to UPPER here so we are assured the strings are always in upper case.
3553 for( i = 0; i < 3; i++ )
3554 {
3555 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3556 }
3557
3558 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3559 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3560 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3561 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3562 // 11d information element, let's default to US.
3563 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pCountryCode, NULL ) ) )
3564 {
3565 // Check the enforcement first
3566 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3567 {
3568 fUnknownCountryCode = TRUE;
3569 }
3570 else
3571 {
3572 pCountryCode[ 0 ] = 'U';
3573 pCountryCode[ 1 ] = 'S';
3574 }
3575 }
3576
3577 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3578 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3579 // if we see a 0 in this third character, let's change it to a ' '.
3580 if ( 0 == pCountryCode[ 2 ] )
3581 {
3582 pCountryCode[ 2 ] = ' ';
3583 }
3584
3585 if( !fUnknownCountryCode )
3586 {
3587 fCountryStringChanged = (!palEqualMemory( pMac->hHdd,
3588 pMac->scan.countryCode11d, pCountryCode, 2));
3589
3590
3591 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3592 || (fForce))
3593 {
3594 // this is the first .11d information
3595 palCopyMemory( pMac->hHdd, pMac->scan.countryCode11d, pCountryCode, sizeof( pMac->scan.countryCode11d ) );
3596 }
3597 }
3598
3599 return( fCountryStringChanged );
3600}
3601
3602
3603void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3604{
3605 tANI_U32 Index, count=0;
3606 tSirMacChanInfo *pChanInfo;
3607 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003608 tANI_S32 maxChannelIndex;
3609
3610 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3611 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003612
3613 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN)))
3614 {
3615 palZeroMemory(pMac->hHdd, pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3616 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003617 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003618 {
3619 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3620 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3621 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003622 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3623 {
3624 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3625 break;
3626 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003627 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3628 pChanInfo->numChannels = 1;
3629 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3630 pChanInfo++;
3631 count++;
3632 }
3633 }
3634 if(count)
3635 {
3636 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3637 }
3638 palFreeMemory(pMac->hHdd, pChanInfoStart);
3639 }
3640}
3641
3642
3643void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3644{
3645 tANI_BOOLEAN fPopulate5GBand = FALSE;
3646
3647 do
3648 {
3649 // if this is not a dual band product, then we don't need to set the opposite
3650 // band info. We only work in one band so no need to look in the other band.
3651 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3652 // if we found channel info on the 5.0 band and...
3653 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3654 {
3655 // and the 2.4 band is empty, then populate the 2.4 channel info
Jeff Johnson295189b2012-06-20 16:38:30 -07003656 fPopulate5GBand = FALSE;
3657 }
3658 else
3659 {
3660 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3661 // set the 5.0 band info from the 2.4 country code.
Jeff Johnson295189b2012-06-20 16:38:30 -07003662 fPopulate5GBand = TRUE;
3663 }
3664 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3665
3666 } while( 0 );
3667}
3668
3669
3670tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3671{
3672 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3673 tANI_U32 i;
3674
3675 //Make sure it is a channel that is in our supported list.
3676 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3677 {
3678 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3679 {
3680 fRet = eANI_BOOLEAN_TRUE;
3681 break;
3682 }
3683 }
3684
3685 //If it is configured to limit a set of the channels
3686 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3687 {
3688 fRet = eANI_BOOLEAN_FALSE;
3689 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3690 {
3691 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3692 {
3693 fRet = eANI_BOOLEAN_TRUE;
3694 break;
3695 }
3696 }
3697 }
3698
3699 return (fRet);
3700}
3701
3702
3703
3704//bSize specify the buffer size of pChannelList
3705tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3706{
3707 tANI_U8 i, j = 0, chnId;
3708
3709 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3710 for( i = 0; i < bSize; i++ )
3711 {
3712 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3713 if ( csrIsSupportedChannel( pMac, chnId ) )
3714 {
3715 pChannelList[j++] = chnId;
3716 }
3717 }
3718
3719 return (j);
3720}
3721
3722
3723
3724//bSize -- specify the buffer size of pChannelList
3725void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3726 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3727{
3728 tListElem *pEntry;
3729 tCsrChannelPowerInfo *pChannelSet;
3730 tANI_U8 numChannels;
3731 tANI_U8 *pChannels;
3732
3733 if( pChannelSetList && pChannelList && pNumChannels )
3734 {
3735 pChannels = pChannelList;
3736 *pNumChannels = 0;
3737 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3738 while( pEntry )
3739 {
3740 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3741 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3742 pChannels += numChannels;
3743 *pNumChannels += numChannels;
3744 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3745 }
3746 }
3747}
3748
3749
3750/*
3751 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
3752*/
3753tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
3754 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
3755{
3756 tANI_U8 Num2GChannels, bMaxNumChn;
3757 eHalStatus status;
3758 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3759 v_REGDOMAIN_t domainId;
3760 tDot11fBeaconIEs *pIesLocal = pIes;
3761
Jeff Johnson295189b2012-06-20 16:38:30 -07003762 if (VOS_STA_SAP_MODE == vos_get_conparam ())
3763 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003764
3765 do
3766 {
3767 // check if .11d support is enabled
3768 if( !csrIs11dSupported( pMac ) ) break;
3769 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
3770 {
3771 break;
3772 }
3773 // check if country information element is present
3774 if(!pIesLocal->Country.present)
3775 {
3776 //No country info
3777 break;
3778 }
3779
3780 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
3781 {
3782 // country string changed, this should not happen
3783 //Need to check whether we care about this BSS' domain info
3784 //If it doesn't match of the connected profile or roaming profile, let's ignore it
3785 tANI_U32 i;
3786 tCsrRoamSession *pSession;
3787
3788 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3789 {
3790 if( CSR_IS_SESSION_VALID( pMac, i ) )
3791 {
3792 pSession = CSR_GET_SESSION( pMac, i );
3793 if(pSession->pCurRoamProfile)
3794 {
3795 tCsrScanResultFilter filter;
3796
3797 palZeroMemory(pMac->hHdd, &filter, sizeof(tCsrScanResultFilter));
3798 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
3799 if(HAL_STATUS_SUCCESS(status))
3800 {
3801 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
3802 //Free the resource first
3803 csrFreeScanFilter( pMac, &filter );
3804 if(fMatch)
3805 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003806 smsLog(pMac, LOGW, " Matching roam profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003807 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3808 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3809 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3810 break;
3811 }
3812 }
3813 }
3814 else if( csrIsConnStateConnected(pMac, i))
3815 {
3816 //Reach here only when the currention is base on no profile.
3817 //User doesn't give profile and just connect to anything.
3818 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
3819 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003820 smsLog(pMac, LOGW, " Matching connect profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003821 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3822 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3823 //Tush
3824 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3825 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
3826 &pSession->connectedProfile.bssid))
3827 {
3828 //AP changed the 11d info on the fly, modify cfg
3829 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3830 fRet = eANI_BOOLEAN_TRUE;
3831 }
3832 break;
3833 }
3834 }
3835 } //valid session
3836 } //for
3837 if ( i == CSR_ROAM_SESSION_MAX )
3838 {
3839 //Check whether we can use this country's 11d information
3840 if( !pMac->roam.configParam.fEnforceDefaultDomain )
3841 {
3842 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3843 }
3844 else
3845 {
3846 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
3847 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3848 pMac, pIesLocal->Country.country, &domainId )) &&
3849 ( domainId == pMac->scan.domainIdCurrent ) )
3850 {
3851 //Two countries in the same domain
3852 }
3853 }
3854 }
3855 }
3856 else //Tush
3857 {
3858 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
3859 }
3860
3861 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
3862 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
3863 {
3864 tANI_U8 iC;
3865 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
3866
3867 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
3868 {
3869 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
3870 {
3871 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
3872 }
3873 }
3874 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003875 smsLog(pMac, LOG3, FL(" %d sets each one is %d"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07003876 // save the channel/power information from the Channel IE.
3877 //sizeof(tSirMacChanInfo) has to be 3
Jeff Johnsone7245742012-09-05 17:12:55 -07003878 if (eHAL_STATUS_SUCCESS != csrSaveToChannelPower2G_5G( pMac, pIesLocal->Country.num_triplets * sizeof(tSirMacChanInfo),
3879 (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]) ))
3880 {
3881 fRet = eANI_BOOLEAN_FALSE;
3882 return fRet;
3883 }
3884
Jeff Johnson295189b2012-06-20 16:38:30 -07003885 // set the indicator of the channel where the country IE was found...
3886 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07003887 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country, &domainId );
3888 // Checking for Domain Id change
3889 if ( domainId != pMac->scan.domainIdCurrent )
3890 {
3891 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05303892 palCopyMemory( pMac->hHdd, pMac->scan.countryCode11d, pIesLocal->Country.country,
3893 sizeof( pMac->scan.countryCode11d ) );
3894 csrSetCfgCountryCode(pMac, pIesLocal->Country.country);
3895 WDA_SetRegDomain(pMac, domainId);
3896 pMac->scan.domainIdCurrent = domainId;
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05303897 // Check whether AP provided the 2.4GHZ list or 5GHZ list
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07003898 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[0].firstChanNum))
3899 {
3900 // AP Provided the 2.4 Channels, Update the 5GHz channels from nv.bin
3901 csrGet5GChannels(pMac );
3902 }
3903 else
3904 {
3905 // AP Provided the 5G Channels, Update the 2.4GHZ channel list from nv.bin
3906 csrGet24GChannels(pMac );
3907 }
3908 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003909 // Populate both band channel lists based on what we found in the country information...
3910 csrSetOppositeBandChannelInfo( pMac );
3911 bMaxNumChn = WNI_CFG_VALID_CHANNEL_LIST_LEN;
3912 // construct 2GHz channel list first
3913 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList24, pMac->scan.channels11d.channelList,
3914 bMaxNumChn, &Num2GChannels );
3915 // construct 5GHz channel list now
3916 if(bMaxNumChn > Num2GChannels)
3917 {
3918 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList5G, pMac->scan.channels11d.channelList + Num2GChannels,
3919 bMaxNumChn - Num2GChannels,
3920 &pMac->scan.channels11d.numChannels );
3921 }
3922
3923 pMac->scan.channels11d.numChannels += Num2GChannels;
3924 fRet = eANI_BOOLEAN_TRUE;
3925
3926 } while( 0 );
3927
3928 if( !pIes && pIesLocal )
3929 {
3930 //locally allocated
3931 palFreeMemory(pMac->hHdd, pIesLocal);
3932 }
3933
3934 return( fRet );
3935}
3936
3937
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003938static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003939{
3940 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
3941 // will set this to the channel where an .11d beacon is seen
3942 pMac->scan.channelOf11dInfo = 0;
3943 // if we get any ambiguous .11d information then this will be set to TRUE
3944 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3945 //Tush
3946 // if we get any ambiguous .11d information, then this will be set to TRUE
3947 // only if the applied 11d info could be found in one of the scan results
3948 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
3949 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003950 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07003951
3952 // Now check if we gathered any domain/country specific information
3953 // If so, we should update channel list and apply Tx power settings
Jeff Johnsone7245742012-09-05 17:12:55 -07003954 if( csrIs11dSupported(pMac) )
3955 {
3956 csrApplyCountryInformation( pMac, FALSE );
3957 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003958}
3959
3960
3961void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
3962{
3963 switch (pCommand->u.scanCmd.reason)
3964 {
3965 case eCsrScanSetBGScanParam:
3966 case eCsrScanAbortBgScan:
3967 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
3968 {
3969 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
3970 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
3971 }
3972 break;
3973 case eCsrScanBGScanAbort:
3974 case eCsrScanBGScanEnable:
3975 case eCsrScanGetScanChnInfo:
3976 break;
3977 case eCsrScanAbortNormalScan:
3978 default:
3979 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
3980 break;
3981 }
3982 if(pCommand->u.scanCmd.pToRoamProfile)
3983 {
3984 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
3985 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.pToRoamProfile);
3986 }
3987 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
3988}
3989
3990
3991tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
3992{
3993 tANI_U32 index11dChannels, index;
3994 tANI_U32 indexCurrentChannels;
3995 tANI_BOOLEAN fChannelAlreadyScanned;
3996 tANI_U32 len = sizeof(pMac->roam.validChannelList);
3997
3998 *pcChannels = 0;
3999 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4000 {
4001 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4002 {
4003 //Find the channel index where we found the 11d info
4004 for(index = 0; index < len; index++)
4005 {
4006 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4007 break;
4008 }
4009 //check whether we found the channel index
4010 if(index < len)
4011 {
4012 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4013 // NOT in the current channel list. This gives us a list of the new channels that have not been
4014 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4015 // initially.
4016 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4017 {
4018 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4019
4020 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4021 {
4022 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4023 {
4024 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4025 break;
4026 }
4027 }
4028
4029 if ( !fChannelAlreadyScanned )
4030 {
4031 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4032 ( *pcChannels )++;
4033 }
4034 }
4035 }
4036 }//GetCFG
4037 }
4038 return( *pcChannels );
4039}
4040
4041
4042eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4043{
4044 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4045
4046 switch( pCommand->u.scanCmd.reason )
4047 {
4048 case eCsrScan11d1:
4049 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4050 break;
4051 case eCsrScan11d2:
4052 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4053 break;
4054 case eCsrScan11dDone:
4055 NextCommand = eCsrNext11dScanComplete;
4056 break;
4057 case eCsrScanLostLink1:
4058 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4059 break;
4060 case eCsrScanLostLink2:
4061 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4062 break;
4063 case eCsrScanLostLink3:
4064 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4065 break;
4066 case eCsrScanForSsid:
4067 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4068 break;
4069 case eCsrScanForCapsChange:
4070 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4071 break;
4072 case eCsrScanIdleScan:
4073 NextCommand = eCsrNextIdleScanComplete;
4074 break;
4075 default:
4076 NextCommand = eCsrNextScanNothing;
4077 break;
4078 }
4079 return( NextCommand );
4080}
4081
4082
4083//Return whether the pCommand is finished.
4084tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4085{
4086 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4087
4088 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004089 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004090 pCommand->u.scanCmd.reason = eCsrScan11d2;
4091 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4092 {
4093 fRet = eANI_BOOLEAN_FALSE;
4094 }
4095
4096 return (fRet);
4097}
4098
4099
4100tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4101{
4102 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4103 tANI_U8 *pChannels;
4104 tANI_U8 cChannels;
4105
4106 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN)))
4107 {
4108 palZeroMemory(pMac->hHdd, pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
4109 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4110 {
4111 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4112 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4113 {
4114 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004115 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004116 }
4117 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, cChannels)))
4118 {
4119 palCopyMemory(pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, pChannels, cChannels);
4120 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4121 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4122 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4123 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4124 {
4125 //Reuse the same command buffer
4126 fRet = eANI_BOOLEAN_FALSE;
4127 }
4128 }
4129 }
4130 palFreeMemory(pMac->hHdd, pChannels);
4131 }
4132
4133 return (fRet);
4134}
4135
4136//Return whether the command should be removed
4137tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4138{
4139 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4140 tListElem *pEntry;
4141 tSmeCmd *pCommand;
4142 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4143 tANI_BOOLEAN fSuccess;
4144
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304145 if (pMac->fScanOffload)
4146 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4147 else
4148 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004149
4150 if ( pEntry )
4151 {
4152 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4153
4154 // If the head of the queue is Active and it is a SCAN command, remove
4155 // and put this on the Free queue.
4156 if ( eSmeCommandScan == pCommand->command )
4157 {
4158 tANI_U32 sessionId = pCommand->sessionId;
4159
4160 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4161 {
4162 fSuccess = eANI_BOOLEAN_FALSE;
4163 }
4164 else
4165 {
4166 //pMac->scan.tempScanResults is not empty meaning the scan found something
4167 //This check only valid here because csrSaveScanresults is not yet called
4168 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4169 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004170 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004171
4172#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4173 {
4174 vos_log_scan_pkt_type *pScanLog = NULL;
4175 tScanResultHandle hScanResult;
4176 tCsrScanResultInfo *pScanResult;
4177 tDot11fBeaconIEs *pIes;
4178 int n = 0, c = 0;
4179
4180 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4181 if(pScanLog)
4182 {
4183 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4184 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4185 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4186 {
4187 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4188 }
4189 else
4190 {
4191 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4192 {
4193 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4194 }
4195 else
4196 {
4197 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4198 }
4199 }
4200 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4201 {
4202 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4203 {
4204 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4205 {
4206 if( n < VOS_LOG_MAX_NUM_BSSID )
4207 {
4208 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4209 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004210 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004211 break;
4212 }
4213 palCopyMemory(pMac->hHdd, pScanLog->bssid[n], pScanResult->BssDescriptor.bssId, 6);
4214 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4215 {
4216 palCopyMemory(pMac->hHdd, pScanLog->ssid[n],
4217 pIes->SSID.ssid, pIes->SSID.num_ssid);
4218 }
4219 palFreeMemory(pMac->hHdd, pIes);
4220 n++;
4221 }
4222 c++;
4223 }
4224 pScanLog->numSsid = (v_U8_t)n;
4225 pScanLog->totalSsid = (v_U8_t)c;
4226 csrScanResultPurge(pMac, hScanResult);
4227 }
4228 }
4229 else
4230 {
4231 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4232 }
4233 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4234 }
4235 }
4236#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4237
4238 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4239 //We reuse the command here instead reissue a new command
4240 switch(NextCommand)
4241 {
4242 case eCsrNext11dScan1Success:
4243 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004244 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004245 // if we found country information, no need to continue scanning further, bail out
4246 fRemoveCommand = eANI_BOOLEAN_TRUE;
4247 NextCommand = eCsrNext11dScanComplete;
4248 break;
4249 case eCsrNext11dScan1Failure:
4250 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4251 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4252 //we clear the "old" 11d info and give it once more chance
4253 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4254 if(fRemoveCommand)
4255 {
4256 NextCommand = eCsrNext11dScanComplete;
4257 }
4258 break;
4259 case eCsrNextLostLinkScan1Success:
4260 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4261 {
4262 csrScanHandleFailedLostlink1(pMac, sessionId);
4263 }
4264 break;
4265 case eCsrNextLostLinkScan2Success:
4266 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4267 {
4268 csrScanHandleFailedLostlink2(pMac, sessionId);
4269 }
4270 break;
4271 case eCsrNextLostLinkScan3Success:
4272 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4273 {
4274 csrScanHandleFailedLostlink3(pMac, sessionId);
4275 }
4276 break;
4277 case eCsrNextLostLinkScan1Failed:
4278 csrScanHandleFailedLostlink1(pMac, sessionId);
4279 break;
4280 case eCsrNextLostLinkScan2Failed:
4281 csrScanHandleFailedLostlink2(pMac, sessionId);
4282 break;
4283 case eCsrNextLostLinkScan3Failed:
4284 csrScanHandleFailedLostlink3(pMac, sessionId);
4285 break;
4286 case eCsrNexteScanForSsidSuccess:
4287 csrScanHandleSearchForSSID(pMac, pCommand);
4288 break;
4289 case eCsrNexteScanForSsidFailure:
4290 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4291 break;
4292 case eCsrNextIdleScanComplete:
4293 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4294 break;
4295 case eCsrNextCapChangeScanComplete:
4296 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4297 break;
4298 default:
4299
4300 break;
4301 }
4302 }
4303 else
4304 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004305 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004306 fRemoveCommand = eANI_BOOLEAN_FALSE;
4307 }
4308 }
4309 else
4310 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004311 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004312 fRemoveCommand = eANI_BOOLEAN_FALSE;
4313 }
4314
4315 return( fRemoveCommand );
4316}
4317
4318
4319
4320static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4321 tSirBssDescription *pSirBssDescr,
4322 tDot11fBeaconIEs *pIes)
4323{
4324 tListElem *pEntry;
4325 tCsrScanResult *pCsrBssDescription;
4326
4327 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4328 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4329 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4330 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4331 while( pEntry )
4332 {
4333 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4334
4335 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4336 // matches
4337
4338 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004339 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004340 {
4341 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4342 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4343
4344 // Remove the 'old' entry from the list....
4345 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4346 {
4347 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4348 // we need to free the memory associated with this node
4349 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4350 }
4351
4352 // If we found a match, we can stop looking through the list.
4353 break;
4354 }
4355
4356 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4357 }
4358}
4359
4360
4361
4362//Caller allocated memory pfNewBssForConn to return whether new candidate for
4363//current connection is found. Cannot be NULL
4364tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4365 tSirBssDescription *pBSSDescription,
4366 tDot11fBeaconIEs *pIes)
4367{
4368 tCsrScanResult *pCsrBssDescription = NULL;
4369 tANI_U32 cbBSSDesc;
4370 tANI_U32 cbAllocated;
4371 eHalStatus halStatus;
4372
4373 // figure out how big the BSS description is (the BSSDesc->length does NOT
4374 // include the size of the length field itself).
4375 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4376
4377 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4378
4379 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pCsrBssDescription, cbAllocated );
4380 if ( HAL_STATUS_SUCCESS(halStatus) )
4381 {
4382 palZeroMemory(pMac->hHdd, pCsrBssDescription, cbAllocated);
4383 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
4384 palCopyMemory(pMac->hHdd, &pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
4385 //Save SSID separately for later use
4386 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4387 {
4388 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004389 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004390 if (len > SIR_MAC_MAX_SSID_LENGTH)
4391 {
4392 // truncate to fit in our struct
4393 len = SIR_MAC_MAX_SSID_LENGTH;
4394 }
4395 pCsrBssDescription->Result.ssId.length = len;
4396 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
4397 palCopyMemory(pMac->hHdd, pCsrBssDescription->Result.ssId.ssId,
4398 pIes->SSID.ssid, len );
4399 }
4400 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4401 }
4402
4403 return( pCsrBssDescription );
4404}
4405
4406
4407
4408
4409tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004410 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004411{
4412 tANI_BOOLEAN fMatch = FALSE;
4413 tSirMacCapabilityInfo *pCap1, *pCap2;
4414 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004415 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004416
4417 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4418 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4419 if(pCap1->ess == pCap2->ess)
4420 {
4421 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004422 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004423 (fForced || (pSirBssDesc1->channelId == pSirBssDesc2->channelId)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004424 {
4425 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004426 // Check for SSID match, if exists
4427 do
4428 {
4429 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4430 {
4431 break;
4432 }
4433 if( NULL == pIesTemp )
4434 {
4435 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4436 {
4437 break;
4438 }
4439 }
4440 if(pIes1->SSID.present && pIesTemp->SSID.present)
4441 {
4442 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4443 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4444 }
4445 }while(0);
4446
Jeff Johnson295189b2012-06-20 16:38:30 -07004447 }
4448 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4449 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004450
4451 do
4452 {
4453 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4454 {
4455 break;
4456 }
4457 if( NULL == pIesTemp )
4458 {
4459 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4460 {
4461 break;
4462 }
4463 }
4464 //Same channel cannot have same SSID for different IBSS
4465 if(pIes1->SSID.present && pIesTemp->SSID.present)
4466 {
4467 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4468 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4469 }
4470 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004471 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004472 /* In case of P2P devices, ess and ibss will be set to zero */
4473 else if (!pCap1->ess &&
4474 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4475 {
4476 fMatch = TRUE;
4477 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004478 }
4479
4480 if(pIes1)
4481 {
4482 palFreeMemory(pMac->hHdd, pIes1);
4483 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004484
4485 if( (NULL == pIes2) && pIesTemp )
4486 {
4487 //locally allocated
4488 palFreeMemory(pMac->hHdd, pIesTemp);
4489 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004490
4491 return( fMatch );
4492}
4493
4494
4495tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4496{
4497 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4498}
4499
4500
4501//to check whether the BSS matches the dot11Mode
4502static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4503 tDot11fBeaconIEs *pIes)
4504{
4505 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4506 eCsrPhyMode phyMode;
4507
4508 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4509 {
4510 switch(pMac->roam.configParam.phyMode)
4511 {
4512 case eCSR_DOT11_MODE_11b:
4513 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4514 break;
4515 case eCSR_DOT11_MODE_11g:
4516 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4517 break;
4518 case eCSR_DOT11_MODE_11g_ONLY:
4519 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4520 break;
4521 case eCSR_DOT11_MODE_11a:
4522 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4523 break;
4524 case eCSR_DOT11_MODE_11n_ONLY:
4525 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4526 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004527
4528#ifdef WLAN_FEATURE_11AC
4529 case eCSR_DOT11_MODE_11ac_ONLY:
4530 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4531 break;
4532#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004533 case eCSR_DOT11_MODE_11b_ONLY:
4534 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4535 break;
4536 case eCSR_DOT11_MODE_11a_ONLY:
4537 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4538 break;
4539 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004540#ifdef WLAN_FEATURE_11AC
4541 case eCSR_DOT11_MODE_11ac:
4542#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004543 case eCSR_DOT11_MODE_TAURUS:
4544 default:
4545 fAllowed = eANI_BOOLEAN_TRUE;
4546 break;
4547 }
4548 }
4549
4550 return (fAllowed);
4551}
4552
4553
4554
4555//Return pIes to caller for future use when returning TRUE.
4556static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4557 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4558 tDot11fBeaconIEs **ppIes )
4559{
4560 tANI_BOOLEAN fValidChannel = FALSE;
4561 tDot11fBeaconIEs *pIes = NULL;
4562 tANI_U8 index;
4563
4564 for( index = 0; index < numChn; index++ )
4565 {
4566 // This check relies on the fact that a single BSS description is returned in each
4567 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4568 // to this model when we ran with a large number of APs. If this were to change, then
4569 // this check would have to mess with removing the bssDescription from somewhere in an
4570 // arbitrary index in the bssDescription array.
4571 if ( pChannels[ index ] == pBssDesc->channelId )
4572 {
4573 fValidChannel = TRUE;
4574 break;
4575 }
4576 }
4577 *ppIes = NULL;
4578 if(fValidChannel)
4579 {
4580 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4581 {
4582 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4583 if( fValidChannel )
4584 {
4585 *ppIes = pIes;
4586 }
4587 else
4588 {
4589 palFreeMemory( pMac->hHdd, pIes );
4590 }
4591 }
4592 else
4593 {
4594 fValidChannel = FALSE;
4595 }
4596 }
4597
4598 return( fValidChannel );
4599}
4600
4601
4602//Return whether last scan result is received
4603static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4604 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4605{
4606 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4607 tDot11fBeaconIEs *pIes = NULL;
4608 tANI_U32 cbParsed;
4609 tSirBssDescription *pSirBssDescription;
4610 tANI_U32 cbBssDesc;
4611 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4612 + sizeof(tSirBssDescription); //We need at least one CB
4613
4614 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4615 // is returned when the scan could not find anything. so if we get scan failure return that
4616 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4617 // BssDescriptions....
4618 do
4619 {
4620 if ( ( cbScanResult <= pScanRsp->length ) &&
4621 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4622 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4623 {
4624 tANI_U8 *pChannelList = NULL;
4625 tANI_U8 cChannels = 0;
4626
4627 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004628#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4629 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4630 {
4631 pChannelList = NULL;
4632 cChannels = 0;
4633 }
4634 else
4635#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004636 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4637 {
4638 //eCsrScanSetBGScanParam uses different structure
4639 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4640
4641 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4642 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4643 }
4644 else
4645 {
4646 //the rest use generic scan request
4647 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4648 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4649 }
4650
4651 // if the scan result is not on one of the channels in the Valid channel list, then it
4652 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4653 // let's drop the scan result.
4654 //
4655 // The other situation is where the scan request is for a scan on a particular channel set
4656 // and the scan result is from a
4657
4658 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4659 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4660 // as the valid channels.
4661 if ( 0 == cChannels )
4662 {
4663 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4664
4665 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4666 {
4667 pChannelList = pMac->roam.validChannelList;
4668 cChannels = (tANI_U8)len;
4669 }
4670 else
4671 {
4672 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004673 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004674 break;
4675 }
4676 }
4677
4678 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4679 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4680 pSirBssDescription = pScanRsp->bssDescription;
4681 while( cbParsed < pScanRsp->length )
4682 {
4683 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4684 {
4685 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4686 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4687 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4688 {
4689 if( csrIs11dSupported( pMac) )
4690 {
4691 //Check whether the BSS is acceptable base on 11d info and our configs.
4692 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4693 {
4694 //Double check whether the channel is acceptable by us.
4695 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4696 {
4697 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4698 }
4699 }
4700 }
4701 else
4702 {
4703 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4704 }
4705 }
4706 //Free the resource
4707 palFreeMemory( pMac->hHdd, pIes );
4708 }
4709 // skip over the BSS description to the next one...
4710 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
4711
4712 cbParsed += cbBssDesc;
4713 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
4714
4715 } //while
4716 }
4717 else
4718 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004719 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08004720 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004721 //HO bg scan/probe failed no need to try autonomously
4722 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4723 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004724#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4725 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
4726#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004727 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4728 {
4729 fRemoveCommand = eANI_BOOLEAN_TRUE;
4730 }
4731 }
4732 }while(0);
4733 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4734 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004735 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 -07004736 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
4737 fRet = eANI_BOOLEAN_TRUE;
4738 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4739 if(pfRemoveCommand)
4740 {
4741 *pfRemoveCommand = fRemoveCommand;
4742 }
4743
4744#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304745 if (pMac->fScanOffload)
4746 return fRet;
4747
Jeff Johnson295189b2012-06-20 16:38:30 -07004748 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
4749 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004750 /* Pending scan commands in the list because the previous scan command
4751 * was split into a scan command on one channel + a scan command for all
4752 * remaining channels.
4753 *
4754 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08004755 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304756 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08004757 * active and if the scan is a BG scan triggered by LFR (OR)
4758 * any scan if LFR is in the middle of a BG scan. Splitting
4759 * the scan is delaying the time it takes for LFR to find
4760 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004761 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304762 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08004763#ifdef FEATURE_WLAN_LFR
4764 (csrIsConcurrentInfraConnected(pMac) ||
4765 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304766 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08004767 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
4768#endif
4769 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304770 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004771 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004772 /* if active connected sessions present then continue to split scan
4773 * with specified interval between consecutive scans */
4774 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05304775 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
4776 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004777 } else {
4778 /* if no connected sessions present then initiate next scan command immediately */
4779 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05304780 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004781 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004782 }
4783#endif
4784 return (fRet);
4785}
4786
4787
4788tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
4789{
4790 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
4791 tANI_BOOLEAN f = palEqualMemory( pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.bssid,
4792 bssid, sizeof(tCsrBssid) );
4793
4794 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
4795 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
4796 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
4797}
4798
4799
4800eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
4801{
4802 eHalStatus status = eHAL_STATUS_SUCCESS;
4803 tListElem *pEntry;
4804 tSmeCmd *pCommand;
4805 eCsrScanStatus scanStatus;
4806 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
4807 tSmeGetScanChnRsp *pScanChnInfo;
4808 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4809 eCsrScanReason reason = eCsrScanOther;
4810
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304811 if (pMac->fScanOffload)
4812 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
4813 LL_ACCESS_LOCK);
4814 else
4815 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004816
4817 if ( pEntry )
4818 {
4819 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4820 if ( eSmeCommandScan == pCommand->command )
4821 {
4822 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
4823 reason = pCommand->u.scanCmd.reason;
4824 switch(pCommand->u.scanCmd.reason)
4825 {
4826 case eCsrScanAbortBgScan:
4827 case eCsrScanAbortNormalScan:
4828 case eCsrScanBGScanAbort:
4829 case eCsrScanBGScanEnable:
4830 break;
4831 case eCsrScanGetScanChnInfo:
4832 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004833 /*
4834 * status code not available in tSmeGetScanChnRsp, so
4835 * by default considereing it to be success
4836 */
4837 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004838 csrScanAgeResults(pMac, pScanChnInfo);
4839 break;
4840 case eCsrScanForCapsChange:
4841 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
4842 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004843 case eCsrScanP2PFindPeer:
4844 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
4845 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
4846 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004847 case eCsrScanSetBGScanParam:
4848 default:
4849 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
4850 {
4851 //Not to get channel info if the scan is not a wildcard scan because
4852 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004853 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
4854#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4855 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
4856#endif
4857 )
Jeff Johnson295189b2012-06-20 16:38:30 -07004858 {
4859 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07004860 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
4861 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05304862 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
4863 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07004864 }
4865 else
4866 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05304867 csrScanGetScanChnInfo(pMac,
4868 pCommand->sessionId,
4869 pCommand->u.scanCmd.pContext,
4870 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07004871 pCommand->u.scanCmd.callback = NULL;
4872 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004873 }
4874 }
4875 break;
4876 }//switch
4877 if(fRemoveCommand)
4878 {
4879
4880 csrReleaseScanCommand(pMac, pCommand, scanStatus);
4881
Srikant Kuppa866893f2012-12-27 17:28:14 -08004882 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004883 smeProcessPendingQueue( pMac );
4884 }
4885 else
4886 {
4887 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
4888 status = eHAL_STATUS_FAILURE;
4889 }
4890 }
4891 else
4892 {
4893 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
4894 status = eHAL_STATUS_FAILURE;
4895 }
4896
4897 return (status);
4898}
4899
4900
4901
4902
4903tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
4904{
4905 tListElem *pEntry;
4906 tCsrScanResult *pResult;
4907 tCsrScanResultInfo *pRet = NULL;
4908 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4909
4910 if(pResultList)
4911 {
4912 csrLLLock(&pResultList->List);
4913 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4914 if(pEntry)
4915 {
4916 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4917 pRet = &pResult->Result;
4918 }
4919 pResultList->pCurEntry = pEntry;
4920 csrLLUnlock(&pResultList->List);
4921 }
4922
4923 return pRet;
4924}
4925
4926
4927tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
4928{
4929 tListElem *pEntry = NULL;
4930 tCsrScanResult *pResult = NULL;
4931 tCsrScanResultInfo *pRet = NULL;
4932 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4933
4934 if(pResultList)
4935 {
4936 csrLLLock(&pResultList->List);
4937 if(NULL == pResultList->pCurEntry)
4938 {
4939 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4940 }
4941 else
4942 {
4943 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
4944 }
4945 if(pEntry)
4946 {
4947 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4948 pRet = &pResult->Result;
4949 }
4950 pResultList->pCurEntry = pEntry;
4951 csrLLUnlock(&pResultList->List);
4952 }
4953
4954 return pRet;
4955}
4956
4957
4958//This function moves the first BSS that matches the bssid to the head of the result
4959eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
4960{
4961 eHalStatus status = eHAL_STATUS_FAILURE;
4962 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4963 tCsrScanResult *pResult = NULL;
4964 tListElem *pEntry = NULL;
4965
4966 if(pResultList && bssid)
4967 {
4968 csrLLLock(&pResultList->List);
4969 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4970 while(pEntry)
4971 {
4972 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4973 if(palEqualMemory(pMac->hHdd, bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
4974 {
4975 status = eHAL_STATUS_SUCCESS;
4976 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
4977 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
4978 break;
4979 }
4980 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
4981 }
4982 csrLLUnlock(&pResultList->List);
4983 }
4984
4985 return (status);
4986}
4987
4988
4989//Remove the BSS if possible.
4990//Return -- TRUE == the BSS is remove. False == Fail to remove it
4991//This function is called when list lock is held. Be caution what functions it can call.
4992tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
4993{
4994 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4995 tANI_U32 i;
4996 tCsrRoamSession *pSession;
4997
4998 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4999 {
5000 if( CSR_IS_SESSION_VALID( pMac, i ) )
5001 {
5002 pSession = CSR_GET_SESSION( pMac, i );
5003 //Not to remove the BSS we are connected to.
5004 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
5005 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005006 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005007 )
5008 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005009 smsLog(pMac, LOGW, "Aging out BSS %02X-%02X-%02X-%02X-%02X-%02X Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005010 pResult->Result.BssDescriptor.bssId[0],
5011 pResult->Result.BssDescriptor.bssId[1],
5012 pResult->Result.BssDescriptor.bssId[2],
5013 pResult->Result.BssDescriptor.bssId[3],
5014 pResult->Result.BssDescriptor.bssId[4],
5015 pResult->Result.BssDescriptor.bssId[5],
5016 pResult->Result.BssDescriptor.channelId);
5017 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5018 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5019 {
5020 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005021 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005022 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005023 break;
5024 }
5025 } //valid session
5026 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005027 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07005028 {
5029 //reset the counter so this won't hapeen too soon
5030 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5031 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5032 }
5033
5034 return (fRet);
5035}
5036
5037
5038eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5039{
5040 eHalStatus status = eHAL_STATUS_SUCCESS;
5041 tListElem *pEntry, *tmpEntry;
5042 tCsrScanResult *pResult;
5043 tLimScanChn *pChnInfo;
5044 tANI_U8 i;
5045
5046 csrLLLock(&pMac->scan.scanResultList);
5047 for(i = 0; i < pScanChnInfo->numChn; i++)
5048 {
5049 pChnInfo = &pScanChnInfo->scanChn[i];
5050 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5051 while( pEntry )
5052 {
5053 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5054 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5055 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5056 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005057 if(pResult->AgingCount <= 0)
5058 {
5059 smsLog(pMac, LOGW, " age out due to ref count");
5060 csrScanAgeOutBss(pMac, pResult);
5061 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005062 else
5063 {
5064 pResult->AgingCount--;
5065 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005066 }
5067 pEntry = tmpEntry;
5068 }
5069 }
5070 csrLLUnlock(&pMac->scan.scanResultList);
5071
5072 return (status);
5073}
5074
5075
5076eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5077 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5078{
5079 eHalStatus status = eHAL_STATUS_SUCCESS;
5080 tSirSmeScanReq *pMsg;
5081 tANI_U16 msgLen;
5082 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5083 tSirScanType scanType = pScanReq->scanType;
5084 tANI_U32 minChnTime; //in units of milliseconds
5085 tANI_U32 maxChnTime; //in units of milliseconds
5086 tANI_U32 i;
5087 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5088 tANI_U8 *pSelfMac = NULL;
5089
5090 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5091 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5092 ( pScanReq->uIEFieldLen ) ;
5093
5094 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
5095 if(HAL_STATUS_SUCCESS(status))
5096 {
5097 do
5098 {
5099 palZeroMemory(pMac->hHdd, pMsg, msgLen);
5100 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5101 pMsg->length = pal_cpu_to_be16(msgLen);
5102 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305103 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5104 {
5105 pMsg->sessionId = sessionId;
5106 }
5107 else
5108 {
5109 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5110 request on first available session */
5111 pMsg->sessionId = 0;
5112 }
5113
Jeff Johnson295189b2012-06-20 16:38:30 -07005114 pMsg->transactionId = 0;
5115 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5116 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5117
5118 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5119 {
5120 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5121 }
5122 else
5123 {
5124 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5125 // do so, get the WNI_CFG_STA_ID
5126 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5127 {
5128 if( CSR_IS_SESSION_VALID( pMac, i ) )
5129 {
5130 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5131 break;
5132 }
5133 }
5134 if( CSR_ROAM_SESSION_MAX == i )
5135 {
5136 tANI_U32 len = WNI_CFG_BSSID_LEN;
5137 pSelfMac = selfMacAddr;
5138 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5139 if( !HAL_STATUS_SUCCESS( status ) ||
5140 ( len < WNI_CFG_BSSID_LEN ) )
5141 {
5142 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5143 //Force failed status
5144 status = eHAL_STATUS_FAILURE;
5145 break;
5146 }
5147 }
5148 }
5149 palCopyMemory( pMac->hHdd, (tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr) );
5150
5151 //sirCopyMacAddr
5152 palCopyMemory( pMac->hHdd, (tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr) );
5153 if( palEqualMemory( pMac->hHdd, pScanReq->bssid, bssid, sizeof(tCsrBssid) ) )
5154 {
5155 palFillMemory( pMac->hHdd, pMsg->bssId, sizeof(tSirMacAddr), 0xff );
5156 }
5157 else
5158 {
5159 palCopyMemory(pMac->hHdd, pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
5160 }
5161 minChnTime = pScanReq->minChnTime;
5162 maxChnTime = pScanReq->maxChnTime;
5163
5164 //Verify the scan type first, if the scan is active scan, we need to make sure we
5165 //are allowed to do so.
5166 /* if 11d is enabled & we don't see any beacon around, scan type falls
5167 back to passive. But in BT AMP STA mode we need to send out a
5168 directed probe*/
5169 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5170 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5171 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5172 {
5173 scanType = pMac->scan.curScanType;
5174 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5175 {
5176 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5177 {
5178 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5179 }
5180 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5181 {
5182 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5183 }
5184 }
5185 }
5186 pMsg->scanType = pal_cpu_to_be32(scanType);
5187
5188 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ? pScanReq->SSIDs.numOfSSIDs :
5189 SIR_SCAN_MAX_NUM_SSID;
5190 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5191 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005192 for (i = 0; i < pMsg->numSsid; i++)
5193 {
5194 palCopyMemory(pMac->hHdd, &pMsg->ssId[i], &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
5195 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005196 }
5197 else
5198 {
5199 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005200 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5201 {
5202 pMsg->ssId[i].length = 0;
5203 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005204 }
5205
Jeff Johnson295189b2012-06-20 16:38:30 -07005206 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5207 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005208 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5209 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005210 //hidden SSID option
5211 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5212 //rest time
5213 //pMsg->restTime = pScanReq->restTime;
5214 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5215 // All the scan results caching will be done by Roaming
5216 // We do not want LIM to do any caching of scan results,
5217 // so delete the LIM cache on all scan requests
5218 pMsg->returnFreshResults = pScanReqParam->freshScan;
5219 //Always ask for unique result
5220 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5221 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5222 if(pScanReq->ChannelInfo.numOfChannels)
5223 {
5224 //Assuming the channelNumber is tANI_U8 (1 byte)
5225 status = palCopyMemory(pMac->hHdd, pMsg->channelList.channelNumber, pScanReq->ChannelInfo.ChannelList,
5226 pScanReq->ChannelInfo.numOfChannels);
5227 }
5228
5229 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5230 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5231 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5232 if(pScanReq->uIEFieldLen != 0)
5233 {
5234 palCopyMemory(pMac->hHdd, (tANI_U8 *)pMsg+pMsg->uIEFieldOffset,
5235 pScanReq->pIEField, pScanReq->uIEFieldLen );
5236 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005237 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005238
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005239 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5240 {
5241 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5242 }
5243
Jeff Johnson295189b2012-06-20 16:38:30 -07005244 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005245 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005246 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5247 pScanReq->requestType, pMsg->channelList.numChannels);
5248
5249 for(i = 0; i < pMsg->channelList.numChannels; i++)
5250 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005251 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005252 }
5253
Jeff Johnson295189b2012-06-20 16:38:30 -07005254 if(HAL_STATUS_SUCCESS(status))
5255 {
5256 status = palSendMBMessage(pMac->hHdd, pMsg);
5257 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005258 else
5259 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005260 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005261 palFreeMemory(pMac->hHdd, pMsg);
5262 }
5263 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005264 else
5265 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005266 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005267 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005268
5269 return( status );
5270}
5271
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005272eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005273{
5274 eHalStatus status = eHAL_STATUS_SUCCESS;
5275 tSirSmeScanReq *pMsg;
5276 tANI_U16 msgLen;
5277
5278 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
5279 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
5280 if(HAL_STATUS_SUCCESS(status))
5281 {
5282 palZeroMemory(pMac->hHdd, pMsg, msgLen);
5283 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5284 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005285 pMsg->sessionId = sessionId;
5286 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005287 pMsg->returnFreshResults = pScanReqParam->freshScan;
5288 //Always ask for unique result
5289 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5290 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5291 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005292 if (!HAL_STATUS_SUCCESS(status))
5293 {
5294 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5295 }
5296
Jeff Johnson295189b2012-06-20 16:38:30 -07005297 }
5298
5299 return( status );
5300}
5301
5302
5303
5304eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5305{
5306 eHalStatus status = eHAL_STATUS_FAILURE;
5307 tScanReqParam scanReq;
5308
5309 do
5310 {
5311 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5312 scanReq.fUniqueResult = TRUE;
5313 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5314 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5315 {
5316 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5317 }
5318 else
5319 {
5320 // Basically do scan on all channels even for 11D 1st scan case.
5321 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5322 }
5323 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5324 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5325 {
5326 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5327 }
5328
5329#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5330 {
5331 vos_log_scan_pkt_type *pScanLog = NULL;
5332
5333 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5334 if(pScanLog)
5335 {
5336 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5337 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5338 {
5339 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5340 }
5341 else
5342 {
5343 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5344 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5345 {
5346 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5347 }
5348 else
5349 {
5350 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5351 }
5352 }
5353 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5354 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5355 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5356 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5357 {
5358 palCopyMemory(pMac->hHdd, pScanLog->channels,
5359 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5360 pScanLog->numChannel);
5361 }
5362 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5363 }
5364 }
5365#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5366
5367
5368 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5369 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5370 }while(0);
5371
5372 return( status );
5373}
5374
5375
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005376eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005377{
5378 eHalStatus status = eHAL_STATUS_FAILURE;
5379 tScanReqParam scanReq;
5380
5381 do
5382 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005383#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5384 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5385 {
5386 //to get the LFR candidates from PE cache
5387 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5388 scanReq.fUniqueResult = TRUE;
5389 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5390 }
5391 else
5392#endif
5393 {
5394 //not a fresh scan
5395 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5396 scanReq.fUniqueResult = TRUE;
5397 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5398 }
5399 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005400 }while(0);
5401
5402 return (status);
5403}
5404
5405
5406
5407eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5408{
5409 eHalStatus status = eHAL_STATUS_SUCCESS;
5410 tCsrChannelInfo newChannelInfo = {0, NULL};
5411 int i, j;
5412 tANI_U8 *pChannel = NULL;
5413 tANI_U32 len = 0;
5414
5415 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305416 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005417 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305418 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5419 {
5420 pCommand->u.scanCmd.lastRoamState[i] =
5421 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5422 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5423 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5424 pCommand->u.scanCmd.reason );
5425 }
5426 }
5427 else
5428 {
5429 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5430 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5431 pCommand->sessionId);
5432 smsLog( pMac, LOG3,
5433 "starting SCAN command from %d state.... reason is %d",
5434 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5435 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005436 }
5437
5438 switch(pCommand->u.scanCmd.reason)
5439 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005440#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5441 case eCsrScanGetLfrResult:
5442#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005443 case eCsrScanGetResult:
5444 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005445 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005446 break;
5447 case eCsrScanSetBGScanParam:
5448 status = csrProcessSetBGScanParam(pMac, pCommand);
5449 break;
5450 case eCsrScanBGScanAbort:
5451 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5452 break;
5453 case eCsrScanBGScanEnable:
5454 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5455 break;
5456 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305457 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005458 break;
5459 case eCsrScanUserRequest:
5460 if(pMac->roam.configParam.fScanTwice)
5461 {
5462 //We scan 2.4 channel twice
5463 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5464 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5465 {
5466 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5467 //allocate twice the channel
5468 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5469 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5470 }
5471 else
5472 {
5473 //get the valid channel list to scan all.
5474 len = sizeof(pMac->roam.validChannelList);
5475
5476 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5477 {
5478 //allocate twice the channel
5479 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5480 pChannel = pMac->roam.validChannelList;
5481 }
5482 }
5483 if(NULL == newChannelInfo.ChannelList)
5484 {
5485 newChannelInfo.numOfChannels = 0;
5486 }
5487 else
5488 {
5489 j = 0;
5490 for(i = 0; i < len; i++)
5491 {
5492 newChannelInfo.ChannelList[j++] = pChannel[i];
5493 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5494 {
5495 newChannelInfo.ChannelList[j++] = pChannel[i];
5496 }
5497 }
5498 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5499 {
5500 //pChannel points to the channellist from the command, free it.
5501 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005502 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005503 }
5504 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5505 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5506 }
5507 } //if(pMac->roam.configParam.fScanTwice)
5508
5509 status = csrScanChannels(pMac, pCommand);
5510
5511 break;
5512 default:
5513 status = csrScanChannels(pMac, pCommand);
5514 break;
5515 }
5516
5517 if(!HAL_STATUS_SUCCESS(status))
5518 {
5519 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5520 }
5521
5522 return (status);
5523}
5524
5525
5526eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5527{
5528 eHalStatus status = eHAL_STATUS_SUCCESS;
5529 tSmeCmd *pCommand = NULL;
5530
5531 if(pScanReq)
5532 {
5533 do
5534 {
5535 pCommand = csrGetCommandBuffer(pMac);
5536 if(!pCommand)
5537 {
5538 status = eHAL_STATUS_RESOURCES;
5539 break;
5540 }
5541 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5542 pCommand->command = eSmeCommandScan;
5543 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5544 pCommand->u.scanCmd.callback = NULL;
5545 pCommand->u.scanCmd.pContext = NULL;
5546 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
5547 //we have to do the follow
5548 if(pScanReq->ChannelInfo.numOfChannels == 0)
5549 {
5550 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5551 }
5552 else
5553 {
5554 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5555 pScanReq->ChannelInfo.numOfChannels);
5556 if(HAL_STATUS_SUCCESS(status))
5557 {
5558 palCopyMemory(pMac->hHdd, pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5559 pScanReq->ChannelInfo.ChannelList, pScanReq->ChannelInfo.numOfChannels);
5560 }
5561 else
5562 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005563 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005564 csrReleaseCommandScan(pMac, pCommand);
5565 break;
5566 }
5567 }
5568
5569 //scan req for SSID
5570 if(pScanReq->SSID.length)
5571 {
5572 palCopyMemory(pMac->hHdd,
5573 pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5574 pScanReq->SSID.ssId,
5575 pScanReq->SSID.length);
5576 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5577
5578 }
5579 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5580 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5581 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5582
5583
5584 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5585 if( !HAL_STATUS_SUCCESS( status ) )
5586 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005587 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005588 csrReleaseCommandScan( pMac, pCommand );
5589 break;
5590 }
5591 }while(0);
5592 }
5593
5594 return (status);
5595}
5596
5597eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5598{
5599 eHalStatus status = eHAL_STATUS_SUCCESS;
5600 tSmeCmd *pCommand = NULL;
5601
5602 do
5603 {
5604 pCommand = csrGetCommandBuffer(pMac);
5605 if(!pCommand)
5606 {
5607 status = eHAL_STATUS_RESOURCES;
5608 break;
5609 }
5610 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5611 pCommand->command = eSmeCommandScan;
5612 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5613 pCommand->u.scanCmd.callback = NULL;
5614 pCommand->u.scanCmd.pContext = NULL;
5615 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5616 if( !HAL_STATUS_SUCCESS( status ) )
5617 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005618 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005619 csrReleaseCommandScan( pMac, pCommand );
5620 break;
5621 }
5622 }while(0);
5623
5624 return (status);
5625}
5626
5627
5628//This will enable the background scan with the non-zero interval
5629eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5630{
5631 eHalStatus status = eHAL_STATUS_SUCCESS;
5632 tSmeCmd *pCommand = NULL;
5633
5634 if(pMac->roam.configParam.bgScanInterval)
5635 {
5636 do
5637 {
5638 pCommand = csrGetCommandBuffer(pMac);
5639 if(!pCommand)
5640 {
5641 status = eHAL_STATUS_RESOURCES;
5642 break;
5643 }
5644 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5645 pCommand->command = eSmeCommandScan;
5646 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5647 pCommand->u.scanCmd.callback = NULL;
5648 pCommand->u.scanCmd.pContext = NULL;
5649 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5650 if( !HAL_STATUS_SUCCESS( status ) )
5651 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005652 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005653 csrReleaseCommandScan( pMac, pCommand );
5654 break;
5655 }
5656 }while(0);
5657 //BG scan results are reported automatically by PE to SME once the scan is done.
5658 //No need to fetch the results explicitly.
5659 //csrScanStartGetResultTimer(pMac);
5660 csrScanStartResultAgingTimer(pMac);
5661 }
5662 else
5663 {
5664 //We don't have BG scan so stop the aging timer
5665 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005666 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005667 status = eHAL_STATUS_INVALID_PARAMETER;
5668 }
5669
5670 return (status);
5671}
5672
5673
5674eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5675{
5676 eHalStatus status = eHAL_STATUS_SUCCESS;
5677 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5678 tANI_U32 index = 0;
5679 tANI_U32 new_index = 0;
5680
5681 do
5682 {
5683 status = csrScanFreeRequest(pMac, pDstReq);
5684 if(HAL_STATUS_SUCCESS(status))
5685 {
5686 status = palCopyMemory(pMac->hHdd, pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08005687 /* Re-initialize the pointers to NULL since we did a copy */
5688 pDstReq->pIEField = NULL;
5689 pDstReq->ChannelInfo.ChannelList = NULL;
5690 pDstReq->SSIDs.SSIDList = NULL;
5691
Jeff Johnson295189b2012-06-20 16:38:30 -07005692 if(pSrcReq->uIEFieldLen == 0)
5693 {
5694 pDstReq->pIEField = NULL;
5695 }
5696 else
5697 {
5698 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->pIEField, pSrcReq->uIEFieldLen);
5699 if(HAL_STATUS_SUCCESS(status))
5700 {
5701 palCopyMemory(pMac->hHdd, pDstReq->pIEField, pSrcReq->pIEField, pSrcReq->uIEFieldLen);
5702 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
5703 }
5704 else
5705 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005706 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnson295189b2012-06-20 16:38:30 -07005707 break;
5708 }
5709 }//Allocate memory for IE field
5710 {
5711 if(pSrcReq->ChannelInfo.numOfChannels == 0)
5712 {
5713 pDstReq->ChannelInfo.ChannelList = NULL;
5714 pDstReq->ChannelInfo.numOfChannels = 0;
5715 }
5716 else
5717 {
5718 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->ChannelInfo.ChannelList,
5719 pSrcReq->ChannelInfo.numOfChannels * sizeof(*pDstReq->ChannelInfo.ChannelList));
5720 if(!HAL_STATUS_SUCCESS(status))
5721 {
5722 pDstReq->ChannelInfo.numOfChannels = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005723 smsLog(pMac, LOGE, "No memory for scanning Channel List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005724 break;
5725 }
5726
5727 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
5728 {
5729 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5730 {
5731 pDstReq->ChannelInfo.ChannelList[new_index] =
5732 pSrcReq->ChannelInfo.ChannelList[index];
5733 new_index++;
5734 }
5735 pDstReq->ChannelInfo.numOfChannels = new_index;
5736 }
5737 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
5738 {
5739 new_index = 0;
5740 pMac->roam.numValidChannels = len;
5741 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5742 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005743 /* Allow scan on valid channels only.
5744 * If it is p2p scan and valid channel list doesnt contain
5745 * social channels, enforce scan on social channels because
5746 * that is the only way to find p2p peers.
5747 * This can happen only if band is set to 5Ghz mode.
5748 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005749 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
5750 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005751 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07005752 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08005753 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005754 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08005755#ifdef FEATURE_WLAN_LFR
5756 /*
5757 * If LFR is requesting a contiguous scan
5758 * (i.e. numOfChannels > 1), then ignore
5759 * DFS channels.
5760 * TODO: vos_nv_getChannelEnabledState is returning
5761 * 120, 124 and 128 as non-DFS channels. Hence, the
5762 * use of direct check for channels below.
5763 */
5764 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5765 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08005766 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08005767#endif
5768 )
5769 {
5770#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005771 smsLog(pMac, LOG2,
Srikant Kuppa866893f2012-12-27 17:28:14 -08005772 "%s: reqType=%d, numOfChannels=%d,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005773 " ignoring DFS channel %d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005774 __func__, pSrcReq->requestType,
5775 pSrcReq->ChannelInfo.numOfChannels,
5776 pSrcReq->ChannelInfo.ChannelList[index]);
5777#endif
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005778 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005779 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005780
Jeff Johnson295189b2012-06-20 16:38:30 -07005781 pDstReq->ChannelInfo.ChannelList[new_index] =
5782 pSrcReq->ChannelInfo.ChannelList[index];
5783 new_index++;
5784 }
5785 }
5786 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005787#ifdef FEATURE_WLAN_LFR
5788 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5789 (0 == pDstReq->ChannelInfo.numOfChannels))
5790 {
5791 /*
5792 * No valid channels found in the request.
5793 * Only perform scan on the channels passed
5794 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
5795 * Passing 0 to LIM will trigger a scan on
5796 * all valid channels which is not desirable.
5797 */
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005798 smsLog(pMac, LOGE, "%s: no valid channels found (request=%d)",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005799 __func__, pSrcReq->requestType);
5800 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5801 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005802 smsLog(pMac, LOGE, "pSrcReq index=%d channel=%d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005803 index, pSrcReq->ChannelInfo.ChannelList[index]);
5804 }
5805 status = eHAL_STATUS_FAILURE;
5806 break;
5807 }
5808#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005809 }
5810 else
5811 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005812 smsLog(pMac, LOGE, "Couldn't get the valid Channel List, keeping requester's list");
Jeff Johnson295189b2012-06-20 16:38:30 -07005813 palCopyMemory(pMac->hHdd, pDstReq->ChannelInfo.ChannelList, pSrcReq->ChannelInfo.ChannelList,
5814 pSrcReq->ChannelInfo.numOfChannels * sizeof(*pDstReq->ChannelInfo.ChannelList));
5815 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
5816 }
5817 }//Allocate memory for Channel List
5818 }
5819 if(pSrcReq->SSIDs.numOfSSIDs == 0)
5820 {
5821 pDstReq->SSIDs.numOfSSIDs = 0;
5822 pDstReq->SSIDs.SSIDList = NULL;
5823 }
5824 else
5825 {
5826 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->SSIDs.SSIDList,
5827 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5828 if(HAL_STATUS_SUCCESS(status))
5829 {
5830 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
5831 palCopyMemory(pMac->hHdd, pDstReq->SSIDs.SSIDList, pSrcReq->SSIDs.SSIDList,
5832 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5833 }
5834 else
5835 {
5836 pDstReq->SSIDs.numOfSSIDs = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005837 smsLog(pMac, LOGE, "No memory for scanning SSID List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005838 break;
5839 }
5840 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07005841 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07005842 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005843
5844 }
5845 }while(0);
5846
5847 if(!HAL_STATUS_SUCCESS(status))
5848 {
5849 csrScanFreeRequest(pMac, pDstReq);
5850 }
5851
5852 return (status);
5853}
5854
5855
5856eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
5857{
5858 eHalStatus status = eHAL_STATUS_SUCCESS;
5859
5860 if(pReq->ChannelInfo.ChannelList)
5861 {
5862 status = palFreeMemory(pMac->hHdd, pReq->ChannelInfo.ChannelList);
5863 pReq->ChannelInfo.ChannelList = NULL;
5864 }
5865 pReq->ChannelInfo.numOfChannels = 0;
5866 if(pReq->pIEField)
5867 {
5868 status = palFreeMemory(pMac->hHdd, pReq->pIEField);
5869 pReq->pIEField = NULL;
5870 }
5871 pReq->uIEFieldLen = 0;
5872 if(pReq->SSIDs.SSIDList)
5873 {
5874 palFreeMemory(pMac->hHdd, pReq->SSIDs.SSIDList);
5875 pReq->SSIDs.SSIDList = NULL;
5876 }
5877 pReq->SSIDs.numOfSSIDs = 0;
5878
5879 return (status);
5880}
5881
5882
5883void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
5884{
5885 if(pCommand->u.scanCmd.callback)
5886 {
5887// sme_ReleaseGlobalLock( &pMac->sme );
5888 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
5889// sme_AcquireGlobalLock( &pMac->sme );
5890 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005891 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005892 }
5893}
5894
5895
5896void csrScanStopTimers(tpAniSirGlobal pMac)
5897{
5898 csrScanStopResultAgingTimer(pMac);
5899 csrScanStopIdleScanTimer(pMac);
5900 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005901 if(0 != pMac->scan.scanResultCfgAgingTime )
5902 {
5903 csrScanStopResultCfgAgingTimer(pMac);
5904 }
5905
Jeff Johnson295189b2012-06-20 16:38:30 -07005906}
5907
5908
5909eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
5910{
5911 eHalStatus status;
5912
5913 if(pMac->scan.fScanEnable)
5914 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305915 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07005916 }
5917 else
5918 {
5919 status = eHAL_STATUS_FAILURE;
5920 }
5921
5922 return (status);
5923}
5924
5925
5926eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
5927{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305928 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07005929}
5930
5931
5932void csrScanGetResultTimerHandler(void *pv)
5933{
5934 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5935
5936 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305937
5938 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07005939}
5940
5941#ifdef WLAN_AP_STA_CONCURRENCY
5942static void csrStaApConcTimerHandler(void *pv)
5943{
5944 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5945 tListElem *pEntry;
5946 tSmeCmd *pScanCmd;
5947
5948 csrLLLock(&pMac->scan.scanCmdPendingList);
5949
5950 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
5951 {
5952 tCsrScanRequest scanReq;
5953 tSmeCmd *pSendScanCmd = NULL;
5954 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07005955 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08005956 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07005957 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
5958 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
5959 eHalStatus status;
5960
Jeff Johnson295189b2012-06-20 16:38:30 -07005961 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5962 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005963
5964 /* if any session is connected and the number of channels to scan is
5965 * greater than 1 then split the scan into multiple scan operations
5966 * on each individual channel else continue to perform scan on all
5967 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005968
5969 /* split scan if number of channels to scan is greater than 1 and
5970 * any one of the following:
5971 * - STA session is connected and the scan is not a P2P search
5972 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08005973 * Do not split scans if no concurrent infra connections are
5974 * active and if the scan is a BG scan triggered by LFR (OR)
5975 * any scan if LFR is in the middle of a BG scan. Splitting
5976 * the scan is delaying the time it takes for LFR to find
5977 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005978 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07005979
5980 if((csrIsStaSessionConnected(pMac) &&
5981 !csrIsP2pSessionConnected(pMac)))
5982 {
5983 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
5984 }
5985 else if(csrIsP2pSessionConnected(pMac))
5986 {
5987 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
5988 }
5989
5990 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005991 ((csrIsStaSessionConnected(pMac) &&
5992#ifdef FEATURE_WLAN_LFR
5993 (csrIsConcurrentInfraConnected(pMac) ||
5994 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
5995 (pMac->roam.neighborRoamInfo.neighborRoamState !=
5996 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5997#endif
5998 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005999 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006000 {
6001 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
6002
6003 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6004 if (!pSendScanCmd)
6005 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006006 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006007 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6008 return;
6009 }
6010 pSendScanCmd->command = pScanCmd->command;
6011 pSendScanCmd->sessionId = pScanCmd->sessionId;
6012 pSendScanCmd->u.scanCmd.callback = NULL;
6013 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6014 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6015 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6016
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006017 /* First copy all the parameters to local variable of scan request */
6018 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6019
6020 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006021 if(scanReq.ChannelInfo.ChannelList != NULL)
6022 {
6023 palFreeMemory(pMac->hHdd,scanReq.ChannelInfo.ChannelList);
6024 scanReq.ChannelInfo.ChannelList = NULL;
6025 }
6026
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006027 pChnInfo->numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006028 palCopyMemory(pMac->hHdd, &channelToScan[0], &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6029 pChnInfo->numOfChannels * sizeof(tANI_U8)); //just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006030 pChnInfo->ChannelList = &channelToScan[0];
6031
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006032 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006033 {
6034 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006035 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006036 }
6037
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006038 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006039
6040 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
6041 //Modify callers parameters in case of concurrency
6042 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006043 //Use concurrency values for min/maxChnTime.
6044 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6045 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006046
6047 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6048 if(!HAL_STATUS_SUCCESS(status))
6049 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006050 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006051 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6052 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006053 }
6054 /* Clean the local scan variable */
6055 scanReq.ChannelInfo.ChannelList = NULL;
6056 scanReq.ChannelInfo.numOfChannels = 0;
6057 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006058 }
6059 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006060 {
6061 /* no active connected session present or numChn == 1
6062 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006063 pSendScanCmd = pScanCmd;
6064 //remove this command from pending list
6065 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6066 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006067 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006068 }
6069
6070 }
6071 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6072
6073 }
6074
Jeff Johnson295189b2012-06-20 16:38:30 -07006075 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6076
6077}
6078#endif
6079
6080eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6081{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006082 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006083
6084 if(pMac->scan.fScanEnable)
6085 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306086 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006087 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006088 return (status);
6089}
6090
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006091eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6092{
6093 eHalStatus status = eHAL_STATUS_FAILURE;
6094
6095 if(pMac->scan.fScanEnable)
6096 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306097 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 -08006098 }
6099 return (status);
6100}
Jeff Johnson295189b2012-06-20 16:38:30 -07006101
6102eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6103{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306104 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006105}
6106
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006107eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6108{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306109 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006110}
Jeff Johnson295189b2012-06-20 16:38:30 -07006111
6112//This function returns the maximum time a BSS is allowed in the scan result.
6113//The time varies base on connection and power saving factors.
6114//Not connected, No PS
6115//Not connected, with PS
6116//Connected w/o traffic, No PS
6117//Connected w/o traffic, with PS
6118//Connected w/ traffic, no PS -- Not supported
6119//Connected w/ traffic, with PS -- Not supported
6120//the return unit is in seconds.
6121tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6122{
6123 tANI_U32 nRet;
6124
6125 if(pMac->scan.nAgingCountDown)
6126 {
6127 //Calculate what should be the timeout value for this
6128 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6129 pMac->scan.nAgingCountDown--;
6130 }
6131 else
6132 {
6133 if( csrIsAllSessionDisconnected( pMac ) )
6134 {
6135 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6136 {
6137 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6138 }
6139 else
6140 {
6141 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6142 }
6143 }
6144 else
6145 {
6146 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6147 {
6148 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6149 }
6150 else
6151 {
6152 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6153 }
6154 }
6155 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6156 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6157 if(pMac->scan.nLastAgeTimeOut > nRet)
6158 {
6159 if(nRet)
6160 {
6161 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6162 }
6163 pMac->scan.nLastAgeTimeOut = nRet;
6164 nRet *= pMac->scan.nAgingCountDown;
6165 }
6166 else
6167 {
6168 pMac->scan.nLastAgeTimeOut = nRet;
6169 }
6170 }
6171
6172 return (nRet);
6173}
6174
6175
6176void csrScanResultAgingTimerHandler(void *pv)
6177{
6178 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6179 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6180
6181 //no scan, no aging
6182 if(pMac->scan.fScanEnable &&
6183 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6184 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6185 )
6186 {
6187 tListElem *pEntry, *tmpEntry;
6188 tCsrScanResult *pResult;
6189 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6190 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6191
6192 csrLLLock(&pMac->scan.scanResultList);
6193 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6194 while( pEntry )
6195 {
6196 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6197 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6198 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6199 {
6200 smsLog(pMac, LOGW, " age out due to time out");
6201 csrScanAgeOutBss(pMac, pResult);
6202 }
6203 pEntry = tmpEntry;
6204 }
6205 csrLLUnlock(&pMac->scan.scanResultList);
6206 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306207 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006208}
6209
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006210static void csrScanResultCfgAgingTimerHandler(void *pv)
6211{
6212 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6213 tListElem *pEntry, *tmpEntry;
6214 tCsrScanResult *pResult;
6215 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6216 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6217
6218 csrLLLock(&pMac->scan.scanResultList);
6219 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6220 while( pEntry )
6221 {
6222 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6223 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6224 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6225 {
6226 smsLog(pMac, LOGW, " age out due to time out");
6227 csrScanAgeOutBss(pMac, pResult);
6228 }
6229 pEntry = tmpEntry;
6230 }
6231 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306232 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006233}
Jeff Johnson295189b2012-06-20 16:38:30 -07006234
6235eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6236{
6237 eHalStatus status;
6238
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006239 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006240 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6241 {
6242 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306243 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6244 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006245 if( !HAL_STATUS_SUCCESS(status) )
6246 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006247 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006248 //This should not happen but set the flag to restart when ready
6249 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6250 }
6251 }
6252 else
6253 {
6254 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6255 {
6256 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6257 }
6258 status = eHAL_STATUS_FAILURE;
6259 }
6260
6261 return (status);
6262}
6263
6264
6265eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6266{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306267 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006268}
6269
6270
6271//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6272void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6273{
6274 csrScanCancelIdleScan(pMac);
6275}
6276
6277
6278//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6279//because IMPS maybe disabled.
6280void csrScanResumeIMPS( tpAniSirGlobal pMac )
6281{
6282 csrScanStartIdleScan( pMac );
6283}
6284
6285
6286void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6287{
6288 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6289
6290 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6291 {
6292 if(pMac->roam.configParam.IsIdleScanEnabled)
6293 {
6294 if(HAL_STATUS_SUCCESS(status))
6295 {
6296 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6297 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006298 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006299 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6300 }
6301 else
6302 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006303 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006304 //even though we are in timer handle, calling stop timer will make sure the timer
6305 //doesn't get to restart.
6306 csrScanStopIdleScanTimer(pMac);
6307 }
6308 }
6309 else
6310 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006311 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006312 }
6313 }
6314 else
6315 {//we might need another flag to check if CSR needs to request imps at all
6316
6317 tANI_U32 nTime = 0;
6318
6319 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6320 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6321 {
6322 csrScanStartIdleScanTimer(pMac, nTime);
6323 }
6324 }
6325 }
6326}
6327
6328
6329//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6330//idle scan timer interval
6331//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6332eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6333{
6334 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6335
6336 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006337 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6338 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006339 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006340 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006341 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006342
6343 if(pTimeInterval)
6344 {
6345 *pTimeInterval = 0;
6346 }
6347
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006348 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006349 if( smeCommandPending( pMac ) )
6350 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006351 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006352 //Not to enter IMPS because more work to do
6353 if(pTimeInterval)
6354 {
6355 *pTimeInterval = 0;
6356 }
6357 //restart when ready
6358 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6359
6360 return (status);
6361 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006362 if (IsPmcImpsReqFailed (pMac))
6363 {
6364 if(pTimeInterval)
6365 {
6366 *pTimeInterval = 1000000; //usec
6367 }
6368 //restart when ready
6369 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006370
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006371 return status;
6372 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006373 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6374 /*&& pMac->roam.configParam.impsSleepTime*/)
6375 {
6376 //Stop get result timer because idle scan gets scan result out of PE
6377 csrScanStopGetResultTimer(pMac);
6378 if(pTimeInterval)
6379 {
6380 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6381 }
6382 //pmcRequestImps take a period in millisecond unit.
6383 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6384 if(!HAL_STATUS_SUCCESS(status))
6385 {
6386 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6387 {
6388 //Do restart the timer if CSR thinks it cannot do IMPS
6389 if( !csrCheckPSReady( pMac ) )
6390 {
6391 if(pTimeInterval)
6392 {
6393 *pTimeInterval = 0;
6394 }
6395 //Set the restart flag to true because that idle scan
6396 //can be restarted even though the timer will not be running
6397 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6398 }
6399 else
6400 {
6401 //For not now, we do a quicker retry
6402 if(pTimeInterval)
6403 {
6404 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6405 }
6406 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006407 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006408 }
6409 else
6410 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006411 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006412 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6413 //the callback will be called in the future. Should not happen though.
6414 status = eHAL_STATUS_SUCCESS;
6415 pMac->scan.nIdleScanTimeGap = 0;
6416 }
6417 }
6418 else
6419 {
6420 //requested so let's reset the value
6421 pMac->scan.nIdleScanTimeGap = 0;
6422 }
6423 }
6424
6425 return (status);
6426}
6427
6428
6429eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6430{
6431 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6432 tANI_U32 nTime = 0;
6433
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006434 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006435 if(pMac->roam.configParam.IsIdleScanEnabled)
6436 {
6437 //stop bg scan first
6438 csrScanBGScanAbort(pMac);
6439 //Stop get result timer because idle scan gets scan result out of PE
6440 csrScanStopGetResultTimer(pMac);
6441 //Enable aging timer since idle scan is going on
6442 csrScanStartResultAgingTimer(pMac);
6443 }
6444 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6445 status = csrScanTriggerIdleScan(pMac, &nTime);
6446 if(!HAL_STATUS_SUCCESS(status))
6447 {
6448 csrScanStartIdleScanTimer(pMac, nTime);
6449 }
6450
6451 return (status);
6452}
6453
6454
6455void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6456{
6457 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6458 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006459 if (vos_concurrent_sessions_running()) {
6460 return;
6461 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006462 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006463 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6464 //Set the restart flag in case later on it is uncancelled
6465 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6466 csrScanStopIdleScanTimer(pMac);
6467 csrScanRemoveNotRoamingScanCommand(pMac);
6468 }
6469}
6470
6471
6472void csrScanIdleScanTimerHandler(void *pv)
6473{
6474 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6475 eHalStatus status;
6476 tANI_U32 nTime = 0;
6477
6478 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006479 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006480 status = csrScanTriggerIdleScan(pMac, &nTime);
6481 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6482 {
6483 //Check whether it is time to actually do an idle scan
6484 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6485 {
6486 pMac->scan.nIdleScanTimeGap = 0;
6487 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6488 }
6489 else
6490 {
6491 csrScanStartIdleScanTimer(pMac, nTime);
6492 }
6493 }
6494}
6495
6496
6497
6498
6499tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6500{
6501 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6502 tListElem *pEntry, *pEntryTmp;
6503 tSmeCmd *pCommand;
6504 tDblLinkList localList;
6505
6506 vos_mem_zero(&localList, sizeof(tDblLinkList));
6507 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6508 {
6509 smsLog(pMac, LOGE, FL(" failed to open list"));
6510 return fRet;
6511 }
6512
6513 csrLLLock(&pMac->sme.smeCmdPendingList);
6514 pEntry = csrLLPeekHead(&pMac->sme.smeCmdPendingList, LL_ACCESS_NOLOCK);
6515 while(pEntry)
6516 {
6517 pEntryTmp = csrLLNext(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK);
6518 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6519 if( eSmeCommandScan == pCommand->command )
6520 {
6521 switch( pCommand->u.scanCmd.reason )
6522 {
6523 case eCsrScanIdleScan:
6524 if( csrLLRemoveEntry(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK) )
6525 {
6526 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6527 }
6528 fRet = eANI_BOOLEAN_TRUE;
6529 break;
6530
6531 default:
6532 break;
6533 } //switch
6534 }
6535 pEntry = pEntryTmp;
6536 }
6537
6538 csrLLUnlock(&pMac->sme.smeCmdPendingList);
6539
6540 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6541 {
6542 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6543 csrReleaseCommandScan( pMac, pCommand );
6544 }
6545
6546 csrLLClose(&localList);
6547
6548 return (fRet);
6549}
6550
6551
6552tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6553{
6554 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6555 tListElem *pEntry, *pEntryTmp;
6556 tSmeCmd *pCommand;
6557 tDblLinkList localList;
6558
6559 vos_mem_zero(&localList, sizeof(tDblLinkList));
6560 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6561 {
6562 smsLog(pMac, LOGE, FL(" failed to open list"));
6563 return fRet;
6564 }
6565
6566 csrLLLock(&pMac->sme.smeCmdPendingList);
6567 pEntry = csrLLPeekHead(&pMac->sme.smeCmdPendingList, LL_ACCESS_NOLOCK);
6568 while(pEntry)
6569 {
6570 pEntryTmp = csrLLNext(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK);
6571 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6572 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6573 {
6574 switch(pCommand->u.scanCmd.reason)
6575 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006576#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6577 case eCsrScanGetLfrResult:
6578#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006579 case eCsrScanGetResult:
6580 case eCsrScanSetBGScanParam:
6581 case eCsrScanBGScanAbort:
6582 case eCsrScanBGScanEnable:
6583 case eCsrScanGetScanChnInfo:
6584 break;
6585 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006586 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006587 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006588 //The rest are fresh scan requests
6589 if( csrLLRemoveEntry(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK) )
6590 {
6591 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6592 }
6593 fRet = eANI_BOOLEAN_TRUE;
6594 break;
6595 }
6596 }
6597 pEntry = pEntryTmp;
6598 }
6599
6600 csrLLUnlock(&pMac->sme.smeCmdPendingList);
6601
6602 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6603 {
6604 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6605 if (pCommand->u.scanCmd.callback)
6606 {
6607 /* User scan request is pending,
6608 * send response with status eCSR_SCAN_ABORT*/
6609 pCommand->u.scanCmd.callback(pMac,
6610 pCommand->u.scanCmd.pContext,
6611 pCommand->u.scanCmd.scanID,
6612 eCSR_SCAN_ABORT);
6613 }
6614 csrReleaseCommandScan( pMac, pCommand );
6615 }
6616 csrLLClose(&localList);
6617
6618 return (fRet);
6619}
6620
6621
6622void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6623{
6624 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306625 tANI_BOOLEAN status;
6626
6627 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006628 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306629 tANI_U32 i;
6630 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
6631 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
6632 }
6633 else
6634 {
6635 csrRoamStateChange(pMac,
6636 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
6637 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006638 }
6639
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306640 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07006641
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006642 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306643 if (pMac->fScanOffload)
6644 {
6645 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
6646 &pCommand->Link, LL_ACCESS_LOCK);
6647 }
6648 else
6649 {
6650 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
6651 &pCommand->Link, LL_ACCESS_LOCK);
6652 }
6653
6654 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006655 {
6656 csrReleaseCommandScan( pMac, pCommand );
6657 }
6658 else
6659 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306660 smsLog(pMac, LOGE,
6661 " ********csrReleaseScanCommand cannot release command reason %d",
6662 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006663 }
6664}
6665
6666
6667eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6668 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
6669{
6670 eHalStatus status = eHAL_STATUS_SUCCESS;
6671 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6672
Jeff Johnson32d95a32012-09-10 13:15:23 -07006673 if(!pSession)
6674 {
6675 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6676 return eHAL_STATUS_FAILURE;
6677 }
6678
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006679 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006680 csrResetPMKIDCandidateList(pMac, sessionId);
6681 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6682 {
6683 tCsrScanResultFilter *pScanFilter;
6684 tCsrScanResultInfo *pScanResult;
6685 tScanResultHandle hBSSList;
6686 tANI_U32 nItems = *pNumItems;
6687
6688 *pNumItems = 0;
6689 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
6690 if(HAL_STATUS_SUCCESS(status))
6691 {
6692 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
6693 //Here is the profile we need to connect to
6694 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6695 if(HAL_STATUS_SUCCESS(status))
6696 {
6697 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6698 if(HAL_STATUS_SUCCESS(status))
6699 {
6700 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
6701 {
6702 //NumPmkidCandidate adds up here
6703 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
6704 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6705 }
6706 if(pSession->NumPmkidCandidate)
6707 {
6708 *pNumItems = pSession->NumPmkidCandidate;
6709 palCopyMemory(pMac->hHdd, pPmkidList, pSession->PmkidCandidateInfo,
6710 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
6711 }
6712 csrScanResultPurge(pMac, hBSSList);
6713 }//Have scan result
6714 csrFreeScanFilter(pMac, pScanFilter);
6715 }
6716 palFreeMemory(pMac->hHdd, pScanFilter);
6717 }
6718 }
6719
6720 return (status);
6721}
6722
6723
6724
6725#ifdef FEATURE_WLAN_WAPI
6726eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6727 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
6728{
6729 eHalStatus status = eHAL_STATUS_SUCCESS;
6730 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6731
Jeff Johnson32d95a32012-09-10 13:15:23 -07006732 if(!pSession)
6733 {
6734 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6735 return eHAL_STATUS_FAILURE;
6736 }
6737
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006738 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006739 csrResetBKIDCandidateList(pMac, sessionId);
6740 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6741 {
6742 tCsrScanResultFilter *pScanFilter;
6743 tCsrScanResultInfo *pScanResult;
6744 tScanResultHandle hBSSList;
6745 tANI_U32 nItems = *pNumItems;
6746 *pNumItems = 0;
6747 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
6748 if(HAL_STATUS_SUCCESS(status))
6749 {
6750 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
6751 //Here is the profile we need to connect to
6752 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6753 if(HAL_STATUS_SUCCESS(status))
6754 {
6755 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6756 if(HAL_STATUS_SUCCESS(status))
6757 {
6758 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
6759 {
6760 //pMac->scan.NumBkidCandidate adds up here
6761 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
6762 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6763
6764 }
6765 if(pSession->NumBkidCandidate)
6766 {
6767 *pNumItems = pSession->NumBkidCandidate;
6768 palCopyMemory(pMac->hHdd, pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
6769 }
6770 csrScanResultPurge(pMac, hBSSList);
6771 }//Have scan result
6772 }
6773 palFreeMemory(pMac->hHdd, pScanFilter);
6774 }
6775 }
6776
6777 return (status);
6778}
6779#endif /* FEATURE_WLAN_WAPI */
6780
6781
6782
6783//This function is usually used for BSSs that suppresses SSID so the profile
6784//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07006785eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07006786{
6787 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6788 tSmeCmd *pScanCmd = NULL;
6789 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
6790 tANI_U8 index = 0;
6791 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
6792
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006793 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006794 //For WDS, we use the index 0. There must be at least one in there
6795 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
6796 {
6797 numSsid = 1;
6798 }
6799 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
6800 {
6801 do
6802 {
6803 pScanCmd = csrGetCommandBuffer(pMac);
6804 if(!pScanCmd)
6805 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006806 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006807 break;
6808 }
6809 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
6810 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.pToRoamProfile, sizeof(tCsrRoamProfile));
6811 if(!HAL_STATUS_SUCCESS(status))
6812 break;
6813 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
6814 if(!HAL_STATUS_SUCCESS(status))
6815 break;
6816 pScanCmd->u.scanCmd.roamId = roamId;
6817 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07006818 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07006819 pScanCmd->u.scanCmd.callback = NULL;
6820 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07006821 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 -07006822 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6823 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest));
6824 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07006825 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07006826 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
6827 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
6828 {
6829 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
6830 }
6831 if(pProfile->pAddIEScan)
6832 {
6833 status = palAllocateMemory(pMac->hHdd,
6834 (void **)&pScanCmd->u.scanCmd.u.scanRequest.pIEField,
6835 pProfile->nAddIEScanLength);
6836 palZeroMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.pIEField, pProfile->nAddIEScanLength);
6837 if(HAL_STATUS_SUCCESS(status))
6838 {
6839 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.pIEField, pProfile->pAddIEScan, pProfile->nAddIEScanLength);
6840 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
6841 }
6842 else
6843 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006844 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07006845 }
6846 } //Allocate memory for IE field
6847 else
6848 {
6849 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
6850 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07006851 /* For one channel be good enpugh time to receive beacon atleast */
6852 if( 1 == pProfile->ChannelInfo.numOfChannels )
6853 {
6854 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
6855 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
6856 }
6857 else
6858 {
6859 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
6860 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
6861 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08006862 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
6863 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07006864 if(pProfile->BSSIDs.numOfBSSIDs == 1)
6865 {
6866 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.bssid, pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
6867 }
6868 else
6869 {
6870 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
6871 }
6872 if(pProfile->ChannelInfo.numOfChannels)
6873 {
6874 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList) * pProfile->ChannelInfo.numOfChannels);
6875 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
6876 if(HAL_STATUS_SUCCESS(status))
6877 {
6878 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
6879 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
6880 {
6881 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
6882 {
6883 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
6884 = pProfile->ChannelInfo.ChannelList[index];
6885 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
6886 }
6887 else
6888 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006889 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07006890 }
6891
6892 }
6893 }
6894 else
6895 {
6896 break;
6897 }
6898
6899 }
6900 else
6901 {
6902 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
6903 }
6904 if(pProfile->SSIDs.numOfSSIDs)
6905 {
6906 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
6907 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
6908 if(!HAL_STATUS_SUCCESS(status))
6909 {
6910 break;
6911 }
6912 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
6913 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList, pProfile->SSIDs.SSIDList,
6914 sizeof(tCsrSSIDInfo));
6915 }
6916 //Start process the command
6917 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
6918 if( !HAL_STATUS_SUCCESS( status ) )
6919 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006920 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006921 break;
6922 }
6923 }while(0);
6924 if(!HAL_STATUS_SUCCESS(status))
6925 {
6926 if(pScanCmd)
6927 {
6928 csrReleaseCommandScan(pMac, pScanCmd);
6929 //TODO:free the memory that is allocated in this function
6930 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07006931 if(notify)
6932 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006933 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
6934 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07006935 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006936 }//valid
6937 else
6938 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006939 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07006940 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
6941 }
6942
6943 return (status);
6944}
6945
6946
6947//Issue a scan base on the new capability infomation
6948//This should only happen when the associated AP changes its capability.
6949//After this scan is done, CSR reroams base on the new scan results
6950eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
6951{
6952 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6953 tSmeCmd *pScanCmd = NULL;
6954
6955 if(pNewCaps)
6956 {
6957 do
6958 {
6959 pScanCmd = csrGetCommandBuffer(pMac);
6960 if(!pScanCmd)
6961 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006962 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006963 status = eHAL_STATUS_RESOURCES;
6964 break;
6965 }
6966 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
6967 status = eHAL_STATUS_SUCCESS;
6968 pScanCmd->u.scanCmd.roamId = 0;
6969 pScanCmd->command = eSmeCommandScan;
6970 pScanCmd->u.scanCmd.callback = NULL;
6971 pScanCmd->u.scanCmd.pContext = NULL;
6972 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
6973 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6974 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
6975 if( !HAL_STATUS_SUCCESS( status ) )
6976 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006977 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006978 break;
6979 }
6980 }while(0);
6981 if(!HAL_STATUS_SUCCESS(status))
6982 {
6983 if(pScanCmd)
6984 {
6985 csrReleaseCommandScan(pMac, pScanCmd);
6986 }
6987 }
6988 }
6989
6990 return (status);
6991}
6992
6993
6994
6995void csrInitBGScanChannelList(tpAniSirGlobal pMac)
6996{
6997 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
6998
6999 palZeroMemory(pMac->hHdd, pMac->scan.bgScanChannelList, len);
7000 pMac->scan.numBGScanChannel = 0;
7001
7002 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7003 {
7004 pMac->roam.numValidChannels = len;
7005 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
7006 palCopyMemory(pMac->hHdd, pMac->scan.bgScanChannelList, pMac->roam.validChannelList, pMac->scan.numBGScanChannel);
7007 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7008 }
7009}
7010
7011
7012//This function return TRUE if background scan channel list is adjusted.
7013//this function will only shrink the background scan channel list
7014tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7015 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7016{
7017 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7018 tANI_U8 i, j, count = *pNumAdjustChannels;
7019
7020 i = 0;
7021 while(i < count)
7022 {
7023 for(j = 0; j < NumChannels; j++)
7024 {
7025 if(pChannelList[j] == pAdjustChannels[i])
7026 break;
7027 }
7028 if(j == NumChannels)
7029 {
7030 //This channel is not in the list, remove it
7031 fRet = eANI_BOOLEAN_TRUE;
7032 count--;
7033 if(count - i)
7034 {
7035 palCopyMemory(pMac->hHdd, &pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
7036 }
7037 else
7038 {
7039 //already remove the last one. Done.
7040 break;
7041 }
7042 }
7043 else
7044 {
7045 i++;
7046 }
7047 }//while(i<count)
7048 *pNumAdjustChannels = count;
7049
7050 return (fRet);
7051}
7052
7053
7054//Get the list of the base channels to scan for passively 11d info
7055eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7056{
7057 eHalStatus status = eHAL_STATUS_SUCCESS;
7058 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7059
7060 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7061 if( HAL_STATUS_SUCCESS(status) )
7062 {
7063 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7064 }
7065 else
7066 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007067 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007068 pMac->scan.baseChannels.numChannels = 0;
7069 }
7070
7071 return ( status );
7072}
7073
7074//This function use the input pChannelList to validate the current saved channel list
7075eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7076{
7077 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7078
7079 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7080}
7081
7082
7083void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7084{
7085 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307086 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007087
7088 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7089
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307090 if (pMac->fScanOffload)
7091 {
7092 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7093 "Scan offload is enabled, update default chan list");
7094 status = csrUpdateChannelList(&pMac->scan);
7095 if (eHAL_STATUS_SUCCESS != status)
7096 {
7097 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7098 "failed to update the supported channel list");
7099 }
7100 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007101 return;
7102}
7103
7104
7105
7106/*
7107 * The Tx power limits are saved in the cfg for future usage.
7108 */
7109void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7110{
7111 tListElem *pEntry;
7112 tANI_U32 cbLen = 0, dataLen;
7113 tCsrChannelPowerInfo *pChannelSet;
7114 tANI_U32 idx;
7115 tSirMacChanInfo *pChannelPowerSet;
7116 tANI_U8 *pBuf = NULL;
7117
7118 //allocate maximum space for all channels
7119 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
7120 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pBuf, dataLen)))
7121 {
7122 palZeroMemory(pMac->hHdd, pBuf, dataLen);
7123 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7124
7125 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7126 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7127 while( pEntry )
7128 {
7129 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7130 if ( 1 != pChannelSet->interChannelOffset )
7131 {
7132 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7133 // to the right format... (inter channel offset of 1 is the only option for the triplets
7134 // that 11d advertises.
7135 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7136 {
7137 // expanding this entry will overflow our allocation
7138 smsLog(pMac, LOGE,
7139 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007140 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007141 pChannelSet->firstChannel,
7142 pChannelSet->numChannels,
7143 pChannelSet->interChannelOffset);
7144 break;
7145 }
7146
7147 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7148 {
7149 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007150 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007151 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007152 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007153 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007154 cbLen += sizeof( tSirMacChanInfo );
7155 pChannelPowerSet++;
7156 }
7157 }
7158 else
7159 {
7160 if (cbLen >= dataLen)
7161 {
7162 // this entry will overflow our allocation
7163 smsLog(pMac, LOGE,
7164 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007165 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007166 pChannelSet->firstChannel,
7167 pChannelSet->numChannels,
7168 pChannelSet->interChannelOffset);
7169 break;
7170 }
7171 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007172 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007173 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007174 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007175 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007176
7177
7178 cbLen += sizeof( tSirMacChanInfo );
7179 pChannelPowerSet++;
7180 }
7181
7182 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7183 }
7184
7185 if(cbLen)
7186 {
7187 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7188 }
7189 palFreeMemory( pMac->hHdd, pBuf );
7190 }//Allocate memory
7191}
7192
7193
7194void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7195{
7196 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7197 ///v_REGDOMAIN_t DomainId;
7198
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007199 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Jeff Johnson295189b2012-06-20 16:38:30 -07007200 palCopyMemory( pMac->hHdd, cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN );
7201
7202 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7203 // the bogus country codes, program the MAC with the right country code.
7204 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7205 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7206 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7207 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7208 {
7209 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7210 cc[ 1 ] = 'R';
7211 }
7212 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7213
7214 //Need to let HALPHY know about the current domain so it can apply some
7215 //domain-specific settings (TX filter...)
7216 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7217 {
7218 halPhySetRegDomain(pMac, DomainId);
7219 }*/
7220}
7221
7222
7223
7224eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7225{
7226 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7227 tANI_U32 len;
7228
7229 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7230 {
7231 len = *pbLen;
7232 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7233 if(HAL_STATUS_SUCCESS(status))
7234 {
7235 *pbLen = (tANI_U8)len;
7236 }
7237 }
7238
7239 return (status);
7240}
7241
7242
7243void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7244{
7245 tANI_U8 i, j;
7246 tANI_BOOLEAN found=FALSE;
7247 tANI_U8 *pControlList = NULL;
7248 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7249
7250 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN)))
7251 {
7252 palZeroMemory(pMac->hHdd, (void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN);
7253 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7254 {
7255 for (i = 0; i < pChannelList->numChannels; i++)
7256 {
7257 for (j = 0; j < len; j += 2)
7258 {
7259 if (pControlList[j] == pChannelList->channelList[i])
7260 {
7261 found = TRUE;
7262 break;
7263 }
7264 }
7265
7266 if (found) // insert a pair(channel#, flag)
7267 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307268 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007269 found = FALSE; // reset the flag
7270 }
7271
7272 }
7273
7274 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7275 }//Successfully getting scan control list
7276 palFreeMemory(pMac->hHdd, pControlList);
7277 }//AllocateMemory
7278}
7279
7280
7281//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7282eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7283{
7284 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7285}
7286
7287
7288void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7289{
7290 tListElem *pEntry = NULL;
7291 tSmeCmd *pCommand = NULL;
7292 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
7293
7294 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
7295 if ( pEntry )
7296 {
7297 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7298 if ( eSmeCommandScan == pCommand->command )
7299 {
7300 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7301 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7302 }
7303 else
7304 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007305 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007306 }
7307 }
7308 smeProcessPendingQueue( pMac );
7309}
7310
7311eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7312{
7313 eHalStatus status;
7314 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7315 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7316
7317 //***setcfg for background scan channel list
7318 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7319 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7320 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7321 if(!csrIsAllSessionDisconnected(pMac))
7322 {
7323 //If disbaling BG scan here, we need to stop aging as well
7324 if(pScanReq->scanInterval == 0)
7325 {
7326 //Stop aging because no new result is coming in
7327 csrScanStopResultAgingTimer(pMac);
7328 }
7329
7330#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7331 {
7332 vos_log_scan_pkt_type *pScanLog = NULL;
7333
7334 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7335 if(pScanLog)
7336 {
7337 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7338 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7339 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7340 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7341 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7342 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7343 {
7344 palCopyMemory(pMac->hHdd, pScanLog->channels, pScanReq->ChannelInfo.ChannelList,
7345 pScanLog->numChannel);
7346 }
7347 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7348 }
7349 }
7350#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7351
7352 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7353 }
7354 else
7355 {
7356 //No need to stop aging because IDLE scan is still running
7357 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7358 }
7359
7360 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7361 {
7362 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7363 }
7364
7365 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7366 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7367
7368
7369
7370 return (status);
7371}
7372
7373
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307374eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007375{
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307376 eHalStatus status = eHAL_STATUS_FAILURE;
7377 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007378 tANI_U16 msgLen;
7379 tListElem *pEntry;
7380 tSmeCmd *pCommand;
7381
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307382 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007383 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307384#ifdef WLAN_AP_STA_CONCURRENCY
7385 csrLLLock(&pMac->scan.scanCmdPendingList);
7386 while(NULL !=
7387 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7388 LL_ACCESS_NOLOCK)))
7389 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007390
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307391 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7392 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7393 }
7394 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007395#endif
7396
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307397 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7398 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7399 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7400 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7401
7402 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7403 }
7404 else
7405 {
7406 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7407 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7408 sessionId,
7409 &pMac->sme.smeScanCmdPendingList,
7410 eSmeCommandScan);
7411 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7412
7413 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7414 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007415
7416 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307417 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007418 {
7419 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307420 if(eSmeCommandScan == pCommand->command &&
7421 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007422 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307423 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Jeff Johnson295189b2012-06-20 16:38:30 -07007424 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
7425 if(HAL_STATUS_SUCCESS(status))
7426 {
7427 palZeroMemory(pMac->hHdd, (void *)pMsg, msgLen);
7428 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7429 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307430 pMsg->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007431 status = palSendMBMessage(pMac->hHdd, pMsg);
7432 }
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307433 else
7434 smsLog(pMac, LOGE, FL("Failed to allocate memory for"
7435 " SmeScanAbortReq"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007436 }
7437 }
7438
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307439 return(status);
7440}
7441
7442void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
7443 tANI_U8 sessionId,
7444 tDblLinkList *pList,
7445 eSmeCommandType commandType)
7446{
7447 tDblLinkList localList;
7448 tListElem *pEntry;
7449 tSmeCmd *pCommand;
7450 tListElem *pEntryToRemove;
7451
7452 vos_mem_zero(&localList, sizeof(tDblLinkList));
7453 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7454 {
7455 smsLog(pMac, LOGE, FL(" failed to open list"));
7456 return;
7457 }
7458
7459 csrLLLock(pList);
7460 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
7461 {
7462
7463 /* Have to make sure we don't loop back to the head of the list,
7464 * which will happen if the entry is NOT on the list */
7465 while (pEntry)
7466 {
7467 pEntryToRemove = pEntry;
7468 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7469 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7470 if ((pCommand->command == commandType) &&
7471 (pCommand->sessionId == sessionId))
7472 {
7473 /* Remove that entry only */
7474 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7475 {
7476 csrLLInsertTail(&localList, pEntryToRemove,
7477 LL_ACCESS_NOLOCK);
7478 }
7479 }
7480 }
7481 }
7482 csrLLUnlock(pList);
7483
7484 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
7485 {
7486 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7487 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
7488 }
7489
7490 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007491}
7492
7493void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7494 eSmeCommandType commandType )
7495{
7496 tDblLinkList localList;
7497 tListElem *pEntry;
7498 tSmeCmd *pCommand;
7499 tListElem *pEntryToRemove;
7500
7501 vos_mem_zero(&localList, sizeof(tDblLinkList));
7502 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7503 {
7504 smsLog(pMac, LOGE, FL(" failed to open list"));
7505 return;
7506 }
7507
7508 csrLLLock(pList);
7509 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7510 {
7511 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7512
7513 // Have to make sure we don't loop back to the head of the list, which will
7514 // happen if the entry is NOT on the list...
7515 while( pEntry )
7516 {
7517 pEntryToRemove = pEntry;
7518 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7519 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7520 if ( pCommand->command == commandType )
7521 {
7522 // Remove that entry only
7523 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7524 {
7525 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7526 }
7527 }
7528 }
7529
7530
7531 }
7532 csrLLUnlock(pList);
7533
7534 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7535 {
7536 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7537 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7538 }
7539 csrLLClose(&localList);
7540
7541}
7542
7543
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307544eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
7545 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007546{
7547 eHalStatus status = eHAL_STATUS_SUCCESS;
7548
7549 if( !csrIsScanForRoamCommandActive( pMac ) )
7550 {
7551 //Only abort the scan if it is not used for other roam/connect purpose
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307552 status = csrScanAbortMacScan(pMac, sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007553 }
7554
7555 return (status);
7556}
7557
7558
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307559eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007560{
7561 eHalStatus status = eHAL_STATUS_SUCCESS;
7562 tSirMbMsg *pMsg;
7563 tANI_U16 msgLen;
7564
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307565 if (pMac->fScanOffload)
7566 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
7567 else
7568 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
7569
Jeff Johnson295189b2012-06-20 16:38:30 -07007570 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
7571 if(HAL_STATUS_SUCCESS(status))
7572 {
7573 palZeroMemory(pMac->hHdd, pMsg, msgLen);
7574 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7575 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307576 if (pMac->fScanOffload)
7577 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007578 status = palSendMBMessage(pMac->hHdd, pMsg);
7579 }
7580
7581 return( status );
7582}
7583
7584tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7585{
7586 tANI_BOOLEAN fValid = FALSE;
7587 tANI_U32 idxValidChannels;
7588 tANI_U32 len = pMac->roam.numValidChannels;
7589
7590 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
7591 {
7592 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
7593 {
7594 fValid = TRUE;
7595 break;
7596 }
7597 }
7598
7599 return fValid;
7600}
7601
Srikant Kuppa066904f2013-05-07 13:56:02 -07007602eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
7603 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7604{
7605 v_U32_t uLen = 0;
7606 tpSirProbeRespBeacon pParsedFrame;
7607 tCsrScanResult *pScanResult = NULL;
7608 tSirBssDescription *pBssDescr = NULL;
7609 tANI_BOOLEAN fDupBss;
7610 tDot11fBeaconIEs *pIesLocal = NULL;
7611 tAniSSID tmpSsid;
7612 v_TIME_t timer=0;
7613 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
7614
7615 pParsedFrame =
7616 (tpSirProbeRespBeacon) vos_mem_malloc(sizeof(tSirProbeRespBeacon));
7617
7618 if (NULL == pParsedFrame)
7619 {
7620 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7621 return eHAL_STATUS_RESOURCES;
7622 }
7623
7624 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
7625 {
7626 smsLog(pMac, LOGE,
7627 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
7628 pPrefNetworkFoundInd->frameLength);
7629 vos_mem_free(pParsedFrame);
7630 return eHAL_STATUS_FAILURE;
7631 }
7632
7633 if (sirConvertProbeFrame2Struct(pMac,
7634 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
7635 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
7636 pParsedFrame) != eSIR_SUCCESS ||
7637 !pParsedFrame->ssidPresent)
7638 {
7639 smsLog(pMac, LOGE,
7640 FL("Parse error ProbeResponse, length=%d"),
7641 pPrefNetworkFoundInd->frameLength);
7642 vos_mem_free(pParsedFrame);
7643 return eHAL_STATUS_FAILURE;
7644 }
7645 //24 byte MAC header and 12 byte to ssid IE
7646 if (pPrefNetworkFoundInd->frameLength >
7647 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
7648 {
7649 uLen = pPrefNetworkFoundInd->frameLength -
7650 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
7651 }
7652
7653 if ( !HAL_STATUS_SUCCESS(palAllocateMemory( pMac->hHdd,
7654 (void **)&pScanResult, sizeof(tCsrScanResult) + uLen )) )
7655 {
7656 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7657 vos_mem_free(pParsedFrame);
7658 return eHAL_STATUS_RESOURCES;
7659 }
7660
7661 palZeroMemory( pMac->hHdd, pScanResult, sizeof(tCsrScanResult) + uLen );
7662 pBssDescr = &pScanResult->Result.BssDescriptor;
7663 /**
7664 * Length of BSS desription is without length of
7665 * length itself and length of pointer
7666 * that holds the next BSS description
7667 */
7668 pBssDescr->length = (tANI_U16)(
7669 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
7670 sizeof(tANI_U32) + uLen);
7671 if (pParsedFrame->dsParamsPresent)
7672 {
7673 pBssDescr->channelId = pParsedFrame->channelNumber;
7674 }
7675 else if (pParsedFrame->HTInfo.present)
7676 {
7677 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
7678 }
7679 else
7680 {
7681 pBssDescr->channelId = pParsedFrame->channelNumber;
7682 }
7683
7684 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
7685 {
7686 int i;
7687 // 11b or 11g packet
7688 // 11g iff extended Rate IE is present or
7689 // if there is an A rate in suppRate IE
7690 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
7691 {
7692 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
7693 {
7694 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7695 break;
7696 }
7697 }
7698 if (pParsedFrame->extendedRatesPresent)
7699 {
7700 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7701 }
7702 }
7703 else
7704 {
7705 // 11a packet
7706 pBssDescr->nwType = eSIR_11A_NW_TYPE;
7707 }
7708
7709 pBssDescr->sinr = 0;
7710 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
7711 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
7712 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
7713 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
7714 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
7715 palCopyMemory( pMac->hHdd, (tANI_U8 *) &pBssDescr->bssId,
7716 (tANI_U8 *) macHeader->bssId,
7717 sizeof(tSirMacAddr));
7718 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
7719
7720 smsLog( pMac, LOG2, "(%s):Bssid= %02x-%02x-%02x-%02x-%02x-%02x "
7721 "chan= %d, rssi = %d", __func__,
7722 pBssDescr->bssId[ 0 ], pBssDescr->bssId[ 1 ],
7723 pBssDescr->bssId[ 2 ], pBssDescr->bssId[ 3 ],
7724 pBssDescr->bssId[ 4 ], pBssDescr->bssId[ 5 ],
7725 pBssDescr->channelId,
7726 pBssDescr->rssi );
7727
7728 //IEs
7729 if (uLen)
7730 {
7731 vos_mem_copy( &pBssDescr->ieFields,
7732 pPrefNetworkFoundInd->data +
7733 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
7734 uLen);
7735 }
7736
7737 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
7738 if ( !pIesLocal &&
7739 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
7740 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
7741 {
7742 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
7743 csrFreeScanResultEntry(pMac, pScanResult);
7744 vos_mem_free(pParsedFrame);
7745 return eHAL_STATUS_RESOURCES;
7746 }
7747
7748 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307749 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007750 //Check whether we have reach out limit
7751 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
7752 {
7753 //Limit reach
7754 smsLog(pMac, LOGE, FL(" BSS limit reached"));
7755 //Free the resources
7756 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
7757 {
7758 palFreeMemory(pMac->hHdd, pIesLocal);
7759 }
7760 csrFreeScanResultEntry(pMac, pScanResult);
7761 vos_mem_free(pParsedFrame);
7762 return eHAL_STATUS_RESOURCES;
7763 }
7764 //Add to scan cache
7765 csrScanAddResult(pMac, pScanResult, pIesLocal);
7766
7767 vos_mem_free(pParsedFrame);
7768
7769 return eHAL_STATUS_SUCCESS;
7770}
7771
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007772#ifdef FEATURE_WLAN_LFR
7773void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
7774{
7775 tListElem *pEntry = NULL;
7776 tCsrScanResult *pBssDesc = NULL;
7777 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08007778 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
7779
7780 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
7781 {
7782 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007783 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08007784 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
7785 return;
7786 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007787
7788 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
7789 {
7790 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007791 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007792 __func__, pMac->scan.occupiedChannels.numChannels);
7793 return;
7794 }
7795
7796 /* Empty occupied channels here */
7797 pMac->scan.occupiedChannels.numChannels = 0;
7798
7799 csrLLLock(&pMac->scan.scanResultList);
7800 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
7801 while( pEntry )
7802 {
7803 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7804 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
7805
7806 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08007807 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007808 &pBssDesc->Result.BssDescriptor, &pIes))) )
7809 {
7810 continue;
7811 }
7812
7813 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
7814
7815 /*
7816 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
7817 */
7818 if( (pBssDesc->Result.pvIes == NULL) && pIes )
7819 {
7820 palFreeMemory(pMac->hHdd, pIes);
7821 }
7822
7823 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
7824 }//while
7825 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08007826
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007827}
7828#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007829
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007830eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
7831 tCsrBssid bssid, tANI_U8 channel)
7832{
7833 eHalStatus status = eHAL_STATUS_SUCCESS;
7834 tDot11fBeaconIEs *pNewIes = NULL;
7835 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7836 tSirBssDescription *pNewBssDescriptor;
7837 tANI_U32 size = 0;
7838
7839 if(NULL == pSession)
7840 {
7841 status = eHAL_STATUS_FAILURE;
7842 return status;
7843 }
7844 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
7845 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x"),
7846 pSession->pConnectBssDesc->bssId[0],
7847 pSession->pConnectBssDesc->bssId[1],
7848 pSession->pConnectBssDesc->bssId[2],
7849 pSession->pConnectBssDesc->bssId[3],
7850 pSession->pConnectBssDesc->bssId[4],
7851 pSession->pConnectBssDesc->bssId[5]);
7852 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
7853 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x channel %d"),
7854 bssid[0],bssid[1],bssid[2],
7855 bssid[3],bssid[4],bssid[5],channel);
7856
7857 do
7858 {
7859 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
7860 pSession->pConnectBssDesc, &pNewIes)))
7861 {
7862 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
7863 __func__);
7864 status = eHAL_STATUS_FAILURE;
7865 break;
7866 }
7867
7868 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
7869 if(size)
7870 {
7871 status = palAllocateMemory(pMac->hHdd, (void **)&pNewBssDescriptor, size);
7872 if(HAL_STATUS_SUCCESS(status))
7873 {
7874 palCopyMemory(pMac->hHdd, pNewBssDescriptor, pSession->pConnectBssDesc, size);
7875 }
7876 else
7877 {
7878 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
7879 __func__);
7880 status = eHAL_STATUS_FAILURE;
7881 break;
7882 }
7883
7884 //change the BSSID & channel as passed
7885 palCopyMemory( pMac->hHdd, pNewBssDescriptor->bssId, bssid,
7886 sizeof(tSirMacAddr) );
7887 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07007888 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007889 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07007890 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007891 __func__);
7892 status = eHAL_STATUS_FAILURE;
7893 break;
7894 }
7895 }
7896 else
7897 {
7898 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
7899 __func__);
7900 status = eHAL_STATUS_FAILURE;
7901 break;
7902 }
7903 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
7904 __func__);
7905 }while(0);
7906
7907 if(pNewIes)
7908 {
7909 palFreeMemory(pMac->hHdd, pNewIes);
7910 }
7911 if(pNewBssDescriptor)
7912 {
7913 palFreeMemory(pMac->hHdd, pNewBssDescriptor);
7914 }
7915 return status;
7916}