blob: cfe1481b85a2f65f0cb38db989089c942c65dc19 [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
120#define MAX_COUNTRY_IGNORE 3
121
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},
133 { {'I','D'}, { 165}, 1 }
134 };
135
Jeff Johnson295189b2012-06-20 16:38:30 -0700136//*** This is temporary work around. It need to call CCM api to get to CFG later
137/// Get string parameter value
138extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530139
Jeff Johnson295189b2012-06-20 16:38:30 -0700140void csrScanGetResultTimerHandler(void *);
141void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800142static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700143void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700144static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700145#ifdef WLAN_AP_STA_CONCURRENCY
146static void csrStaApConcTimerHandler(void *);
147#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700148tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700149eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
150void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
151void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
152void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
153void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
154//if bgPeriod is 0, background scan is disabled. It is in millisecond units
155eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
156eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
157void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
158static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
159 tANI_U8 numChn, tSirBssDescription *pBssDesc,
160 tDot11fBeaconIEs **ppIes );
161eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
162void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
163tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700164void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700165
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700166#define CSR_IS_SOCIAL_CHANNEL(channel) (((channel) == 1) || ((channel) == 6) || ((channel) == 11) )
167
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700168
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700169
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800170static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
171{
172 tListElem *pEntry;
173 tSmeCmd *pCommand;
174
175 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
176 {
177 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
178 if ( eSmeCsrCommandMask & pCommand->command )
179 {
180 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
181 }
182 else
183 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800184 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800185 }
186 }
187}
Jeff Johnson295189b2012-06-20 16:38:30 -0700188//pResult is invalid calling this function.
189void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
190{
191 if( NULL != pResult->Result.pvIes )
192 {
193 palFreeMemory( pMac->hHdd, pResult->Result.pvIes );
194 }
195 palFreeMemory(pMac->hHdd, pResult);
196}
197
198
199static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
200{
201 eHalStatus status = eHAL_STATUS_SUCCESS;
202 tListElem *pEntry;
203 tCsrScanResult *pBssDesc;
204
205 csrLLLock(pList);
206
207 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
208 {
209 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
210 csrFreeScanResultEntry( pMac, pBssDesc );
211 }
212
213 csrLLUnlock(pList);
214
215 return (status);
216}
217
218
219int csrCheckValidateLists(void * dest, const void *src, v_SIZE_t num, int idx)
220{
221#ifdef CSR_VALIDATE_LIST
222
223 int ii = 1;
224
225 if( (NULL == g_pMac) || (!g_pMac->scan.fValidateList ) )
226 {
227 return ii;
228 }
229 if(g_pchannelPowerInfoList24)
230 {
231 //check 2.4 list
232 tListElem *pElem, *pHead;
233 int count;
234
235 count = (int)(g_pchannelPowerInfoList24->Count);
236 pHead = &g_pchannelPowerInfoList24->ListHead;
237 pElem = pHead->next;
238 if((tANI_U32)(pHead->next) > 0x00010000) //Assuming kernel address is not that low.
239 {
240 //this loop crashes if the pointer is not right
241 while(pElem->next != pHead)
242 {
243 if((tANI_U32)(pElem->next) > 0x00010000)
244 {
245 pElem = pElem->next;
246 VOS_ASSERT(count > 0);
247 count--;
248 }
249 else
250 {
251 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL,
252 " %d Detect 1 list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
253 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
254 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
255 (unsigned int)dest, (unsigned int)src, (int)num);
256 VOS_ASSERT(0);
257 ii = 0;
258 break;
259 }
260 }
261 }
262 else
263 {
264 //Bad list
265 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)",
266 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
267 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
268 (unsigned int)dest, (unsigned int)src, (int)num);
269 VOS_ASSERT(0);
270 ii = 0;
271 }
272 }
273 else
274 {
275 //list ok
276 ii = 1;
277 }
278
279
280 return ii;
281
282#else
283 return 1;
284#endif //#ifdef CSR_VALIDATE_LIST
285}
286
287
288eHalStatus csrScanOpen( tpAniSirGlobal pMac )
289{
290 eHalStatus status;
291
292 do
293 {
294 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
295 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
296 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
297 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
298#ifdef WLAN_AP_STA_CONCURRENCY
299 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
300#endif
301#ifdef CSR_VALIDATE_LIST
302 g_pchannelPowerInfoList5 = &pMac->scan.channelPowerInfoList5G;
303 g_pMac = pMac;
304 g_pchannelPowerInfoList24 = &pMac->scan.channelPowerInfoList24;
305#endif
306 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
307 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
308 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerGetResult, csrScanGetResultTimerHandler, pMac);
309 if(!HAL_STATUS_SUCCESS(status))
310 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800311 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700312 break;
313 }
314#ifdef WLAN_AP_STA_CONCURRENCY
315 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerStaApConcTimer, csrStaApConcTimerHandler, pMac);
316 if(!HAL_STATUS_SUCCESS(status))
317 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800318 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700319 break;
320 }
321#endif
322 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerIdleScan, csrScanIdleScanTimerHandler, pMac);
323 if(!HAL_STATUS_SUCCESS(status))
324 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800325 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700326 break;
327 }
328 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerResultAging, csrScanResultAgingTimerHandler, pMac);
329 if(!HAL_STATUS_SUCCESS(status))
330 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800331 smsLog(pMac, LOGE, FL("cannot allocate memory for ResultAging timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700332 break;
333 }
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800334 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerResultCfgAging,
335 csrScanResultCfgAgingTimerHandler, pMac);
336 if(!HAL_STATUS_SUCCESS(status))
337 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800338 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800339 break;
340 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700341 }while(0);
342
343 return (status);
344}
345
346
347eHalStatus csrScanClose( tpAniSirGlobal pMac )
348{
349#ifdef CSR_VALIDATE_LIST
350 g_pchannelPowerInfoList24 = NULL;
351 g_pchannelPowerInfoList5 = NULL;
352 g_pMac = NULL;
353#endif
354 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
355 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
356#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800357 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700358#endif
359 csrLLClose(&pMac->scan.scanResultList);
360 csrLLClose(&pMac->scan.tempScanResults);
361#ifdef WLAN_AP_STA_CONCURRENCY
362 csrLLClose(&pMac->scan.scanCmdPendingList);
363#endif
364 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
365 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
366 csrLLClose(&pMac->scan.channelPowerInfoList24);
367 csrLLClose(&pMac->scan.channelPowerInfoList5G);
368 csrScanDisable(pMac);
369 palTimerFree(pMac->hHdd, pMac->scan.hTimerResultAging);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800370 palTimerFree(pMac->hHdd, pMac->scan.hTimerResultCfgAging);
Jeff Johnson295189b2012-06-20 16:38:30 -0700371 palTimerFree(pMac->hHdd, pMac->scan.hTimerGetResult);
372#ifdef WLAN_AP_STA_CONCURRENCY
373 palTimerFree(pMac->hHdd, pMac->scan.hTimerStaApConcTimer);
374#endif
375 palTimerFree(pMac->hHdd, pMac->scan.hTimerIdleScan);
376 return eHAL_STATUS_SUCCESS;
377}
378
379
380eHalStatus csrScanEnable( tpAniSirGlobal pMac )
381{
382
383 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
384 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
385
386 return eHAL_STATUS_SUCCESS;
387}
388
389
390eHalStatus csrScanDisable( tpAniSirGlobal pMac )
391{
392
393 csrScanStopTimers(pMac);
394 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
395
396 return eHAL_STATUS_SUCCESS;
397}
398
399
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700400//Set scan timing parameters according to state of other driver sessions
401//No validation of the parameters is performed.
402static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
403{
404#ifdef WLAN_AP_STA_CONCURRENCY
405 if(csrIsAnySessionConnected(pMac))
406 {
407 //If multi-session, use the appropriate default scan times
408 if(scanType == eSIR_ACTIVE_SCAN)
409 {
410 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
411 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
412 }
413 else
414 {
415 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
416 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
417 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800418 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
419 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700420
421 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
422
423 //Return so that fields set above will not be overwritten.
424 return;
425 }
426#endif
427
428 //This portion of the code executed if multi-session not supported
429 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
430 //Use the "regular" (non-concurrency) default scan timing.
431 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
432 {
433 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
434 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
435 }
436 else
437 {
438 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
439 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
440 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800441 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
442 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700443
444#ifdef WLAN_AP_STA_CONCURRENCY
445 //No rest time if no sessions are connected.
446 pScanRequest->restTime = 0;
447#endif
448}
449
Jeff Johnson295189b2012-06-20 16:38:30 -0700450#ifdef WLAN_AP_STA_CONCURRENCY
451//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
452eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
453{
454 eHalStatus status = eHAL_STATUS_SUCCESS;
455
456 tANI_BOOLEAN fNoCmdPending;
457 tSmeCmd *pQueueScanCmd=NULL;
458 tSmeCmd *pSendScanCmd=NULL;
459
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700460 if (NULL == pScanCmd)
461 {
462 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
463 return eHAL_STATUS_FAILURE;
464 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800465 /* split scan if any one of the following:
466 * - STA session is connected and the scan is not a P2P search
467 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800468 * Do not split scans if no concurrent infra connections are
469 * active and if the scan is a BG scan triggered by LFR (OR)
470 * any scan if LFR is in the middle of a BG scan. Splitting
471 * the scan is delaying the time it takes for LFR to find
472 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800473 */
Srikant Kuppa866893f2012-12-27 17:28:14 -0800474 if ( (csrIsStaSessionConnected(pMac) &&
475#ifdef FEATURE_WLAN_LFR
476 (csrIsConcurrentInfraConnected(pMac) ||
477 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
478 (pMac->roam.neighborRoamInfo.neighborRoamState !=
479 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
480#endif
481 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800482 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700483 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700484 tCsrScanRequest scanReq;
485 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
486 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
487 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700488 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
489
490 if (numChn == 0)
491 {
492
493 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700494
Vinay Malekal05fdc812012-12-17 13:04:30 -0800495 status = palAllocateMemory( pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn );
496 if( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700497 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800498 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800499 return eHAL_STATUS_FAILURE;
500 }
501 bMemAlloc = eANI_BOOLEAN_TRUE;
502 status = palCopyMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
503 pMac->scan.baseChannels.channelList, numChn );
504 if( !HAL_STATUS_SUCCESS( status ) )
505 {
506 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
507 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800508 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800509 return eHAL_STATUS_FAILURE;
510 }
511 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
512 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700513
Vinay Malekal05fdc812012-12-17 13:04:30 -0800514 //Whenever we get a scan request with multiple channels we break it up into 2 requests
515 //First request for first channel to scan and second request to scan remaining channels
516 if (numChn > pMac->roam.configParam.nNumChanCombinedConc)
517 {
518 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
519
520 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
521 if (!pQueueScanCmd)
522 {
523 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700524 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800525 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
526 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
527
Jeff Johnson295189b2012-06-20 16:38:30 -0700528 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800529 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800530 return eHAL_STATUS_FAILURE;
531 }
532 pQueueScanCmd->command = pScanCmd->command;
533 pQueueScanCmd->sessionId = pScanCmd->sessionId;
534 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
535 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
536 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
537 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700538
Vinay Malekal05fdc812012-12-17 13:04:30 -0800539 /* First copy all the parameters to local variable of scan request */
540 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700541
Vinay Malekal05fdc812012-12-17 13:04:30 -0800542 /* Now modify the elements of local var scan request required to be modified for split scan */
543 if(scanReq.ChannelInfo.ChannelList != NULL)
544 {
545 palFreeMemory(pMac->hHdd, scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800546 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800547 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700548
Vinay Malekal05fdc812012-12-17 13:04:30 -0800549 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - pMac->roam.configParam.nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700550
Vinay Malekal05fdc812012-12-17 13:04:30 -0800551 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530552 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
553 &channelToScan[0], pScanCmd,
554 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700555
Vinay Malekal05fdc812012-12-17 13:04:30 -0800556 palCopyMemory(pMac->hHdd, &channelToScan[0], &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pMac->roam.configParam.nNumChanCombinedConc],
557 pChnInfo->numOfChannels * sizeof(tANI_U8));
558
559 pChnInfo->ChannelList = &channelToScan[0];
560
561 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
562 //Modify callers parameters in case of concurrency
563 scanReq.scanType = eSIR_ACTIVE_SCAN;
564 //Use concurrency values for min/maxChnTime.
565 //We know csrIsAnySessionConnected(pMac) returns TRUE here
566 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
567
568 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
569
570 if(!HAL_STATUS_SUCCESS(status))
571 {
572 if (bMemAlloc)
573 {
574 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
575 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
576
577 }
578 if( scanReq.pIEField != NULL)
579 {
580 palFreeMemory(pMac->hHdd, scanReq.pIEField);
581 scanReq.pIEField = NULL;
582 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800583 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800584 return eHAL_STATUS_FAILURE;
585 }
586 /* Clean the local scan variable */
587 scanReq.ChannelInfo.ChannelList = NULL;
588 scanReq.ChannelInfo.numOfChannels = 0;
589 csrScanFreeRequest(pMac, &scanReq);
590
591 /* setup the command to scan 2 channels */
592 pSendScanCmd = pScanCmd;
593 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = pMac->roam.configParam.nNumChanCombinedConc;
594 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
595 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
596 //Use concurrency values for min/maxChnTime.
597 //We know csrIsAnySessionConnected(pMac) returns TRUE here
598 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
599 pSendScanCmd->u.scanCmd.callback = NULL;
600 } else {
601 pSendScanCmd = pScanCmd;
602 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
603 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
604 //Use concurrency values for min/maxChnTime.
605 //We know csrIsAnySessionConnected(pMac) returns TRUE here
606 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
607 }
608
609 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
610
611 //Logic Below is as follows
612 // If the scanCmdPendingList is empty then we directly send that command
613 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
614 if( fNoCmdPending )
615 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700616 if (pQueueScanCmd != NULL)
617 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800618 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700619 }
620
621 if (pSendScanCmd != NULL)
622 {
623 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
624 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800625 }
626 else
627 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700628 if (pSendScanCmd != NULL)
629 {
630 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
631 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800632
Jeff Johnson295189b2012-06-20 16:38:30 -0700633 if (pQueueScanCmd != NULL)
634 {
635 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
636 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800637 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700638 }
639 else
640 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800641 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800642 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800643 pScanCmd->u.scanCmd.reason,
644 pMac->roam.neighborRoamInfo.neighborRoamState,
645 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700646 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
647 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700648
649 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700650}
651#endif
652
Jeff Johnsone7245742012-09-05 17:12:55 -0700653/* ---------------------------------------------------------------------------
654 \fn csrScan2GOnyRequest
655 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800656 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700657 \param pMac
658 \param pScanCmd
659 \param pScanRequest
660 \return None
661 -------------------------------------------------------------------------------*/
662static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
663 tCsrScanRequest *pScanRequest)
664{
665 tANI_U8 index, channelId, channelListSize = 0;
666 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
667 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
668
669 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700670 /* To silence the KW tool null check is added */
671 if((pScanCmd == NULL) || (pScanRequest == NULL))
672 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800673 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700674 return;
675 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700676
677 if (pScanCmd->u.scanCmd.scanID ||
678 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
679 return;
680
681 //Contsruct valid Supported 2.4 GHz Channel List
682 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
683 {
684 channelId = channelList2G[index];
685 if ( csrIsSupportedChannel( pMac, channelId ) )
686 {
687 validchannelList[channelListSize++] = channelId;
688 }
689 }
690
691 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
692 pScanRequest->ChannelInfo.ChannelList = validchannelList;
693}
694
Jeff Johnson295189b2012-06-20 16:38:30 -0700695eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
696 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
697 csrScanCompleteCallback callback, void *pContext)
698{
699 eHalStatus status = eHAL_STATUS_FAILURE;
700 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700701 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700702
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800703 if(pScanRequest == NULL)
704 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800705 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800706 VOS_ASSERT(0);
707 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700708
Jeff Johnson295189b2012-06-20 16:38:30 -0700709 do
710 {
711 if(pMac->scan.fScanEnable)
712 {
713 pScanCmd = csrGetCommandBuffer(pMac);
714 if(pScanCmd)
715 {
716 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
717 pScanCmd->command = eSmeCommandScan;
718 pScanCmd->sessionId = sessionId;
719 pScanCmd->u.scanCmd.callback = callback;
720 pScanCmd->u.scanCmd.pContext = pContext;
721 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
722 {
723 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
724 }
725 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
726 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
727#ifdef SOFTAP_CHANNEL_RANGE
728 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
729#endif
730 )
731 {
732 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
733 }
734 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
735 {
736 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
737 }
738 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
739 {
740 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
741 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700742 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
743 {
744 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
745 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700746 else
747 {
748 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
749 }
750 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
751 {
752 //The caller doesn't set the time correctly. Set it here
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700753 csrSetDefaultScanTiming(pMac, pScanRequest->scanType, pScanRequest);
754 }
755#ifdef WLAN_AP_STA_CONCURRENCY
756 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800757 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700758 //Need to set restTime only if at least one session is connected
759 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700760 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700761 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700762 }
763 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700764#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700765 /*For Standalone wlan : channel time will remain the same.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800766 For BTC with A2DP up: Channel time = Channel time * 2 , if station is not already associated.
767 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
768 to take a long time.
769 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
770 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700771 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800772 if (HAL_STATUS_SUCCESS(status) &&
773 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700774 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
775 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
776 {
777 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
778 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
779 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800780
781 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
782 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700783 //Need to make the following atomic
784 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
785
786 if(pScanRequestID)
787 {
788 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
789 }
790
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800791 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700792 // If it is not, CSR will save the scan request in the pending cmd queue
793 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800794 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700795 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
796#ifdef SOFTAP_CHANNEL_RANGE
797 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
798#endif
799 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
800 )
801 {
802 tSmeCmd *p11dScanCmd;
803 tCsrScanRequest scanReq;
804 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
805
806 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
807
808 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800809 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700810 {
811 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
812
813 palZeroMemory(pMac->hHdd, &p11dScanCmd->u.scanCmd, sizeof(tScanCmd));
814 status = palAllocateMemory( pMac->hHdd, (void **)&pChnInfo->ChannelList, numChn );
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800815 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700816 {
817 break;
818 }
819 status = palCopyMemory( pMac->hHdd, pChnInfo->ChannelList,
820 pMac->scan.baseChannels.channelList, numChn );
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800821 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700822 {
823 palFreeMemory( pMac->hHdd, pChnInfo->ChannelList );
824 pChnInfo->ChannelList = NULL;
825 break;
826 }
827 pChnInfo->numOfChannels = (tANI_U8)numChn;
828 p11dScanCmd->command = eSmeCommandScan;
829 p11dScanCmd->u.scanCmd.callback = NULL;
830 p11dScanCmd->u.scanCmd.pContext = NULL;
831 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++;
832 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
833
834 if ( csrIs11dSupported(pMac) )
835 {
836 scanReq.scanType = eSIR_PASSIVE_SCAN;
837 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
838 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
839 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
840 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
841 }
842 else
843 {
844 scanReq.scanType = eSIR_ACTIVE_SCAN;
845 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
846 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
847 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
848 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800849
850 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
851 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700852 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700853
Jeff Johnson295189b2012-06-20 16:38:30 -0700854 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
855 //Free the channel list
856 palFreeMemory( pMac->hHdd, pChnInfo->ChannelList );
James Zmuda9ea1edd2013-04-18 18:20:54 -0700857 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700858
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800859 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700860 {
861 //Start process the command
862#ifdef WLAN_AP_STA_CONCURRENCY
863 status = csrQueueScanRequest(pMac, p11dScanCmd);
864#else
865 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
866#endif
867 if( !HAL_STATUS_SUCCESS( status ) )
868 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800869 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700870 break;
871 }
872 }
873 else
874 {
875 break;
876 }
877 }
878 else
879 {
880 //error
881 break;
882 }
883 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700884
885 //Scan only 2G Channels if set in ini file
886 //This is mainly to reduce the First Scan duration
887 //Once we turn on Wifi
888 if(pMac->scan.fFirstScanOnly2GChnl)
889 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800890 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700891 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
892 }
893
Jeff Johnson295189b2012-06-20 16:38:30 -0700894 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
895 if(HAL_STATUS_SUCCESS(status))
896 {
897 //Start process the command
898#ifdef WLAN_AP_STA_CONCURRENCY
899 status = csrQueueScanRequest(pMac,pScanCmd);
900#else
901 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
902#endif
903 if( !HAL_STATUS_SUCCESS( status ) )
904 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800905 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700906 break;
907 }
908 }
909 else
910 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800911 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700912 break;
913 }
914 }
915 else
916 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800917 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700918 break;
919 }
920 }
921 } while(0);
922 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
923 {
924 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
925 {
926 //Set the flag back for restarting idle scan
927 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
928 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800929 smsLog( pMac, LOGE, FL(" failed with status = %d, releasing scan cmd"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700930 csrReleaseCommandScan(pMac, pScanCmd);
931 }
932
933 return (status);
934}
935
936
937eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
938{
939 eHalStatus status = eHAL_STATUS_SUCCESS;
940 tSmeCmd *pScanCmd;
941
942 if(pMac->scan.fScanEnable)
943 {
944 pScanCmd = csrGetCommandBuffer(pMac);
945 if(pScanCmd)
946 {
947 pScanCmd->command = eSmeCommandScan;
948 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
949 pScanCmd->u.scanCmd.callback = NULL;
950 pScanCmd->u.scanCmd.pContext = NULL;
951 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
952 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700953 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700954 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
955 if( !HAL_STATUS_SUCCESS( status ) )
956 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800957 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700958 csrReleaseCommandScan(pMac, pScanCmd);
959 }
960 }
961 else
962 {
963 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800964 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700965 status = eHAL_STATUS_RESOURCES;
966 }
967 }
968
969 return (status);
970}
971
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -0700972#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
973eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
974 csrScanCompleteCallback callback, void *pContext)
975{
976 eHalStatus status = eHAL_STATUS_SUCCESS;
977 tSmeCmd *pScanCmd;
978
979 if (pMac->scan.fScanEnable)
980 {
981 pScanCmd = csrGetCommandBuffer(pMac);
982 if (pScanCmd)
983 {
984 pScanCmd->command = eSmeCommandScan;
985 pScanCmd->sessionId = sessionId;
986 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
987 pScanCmd->u.scanCmd.callback = callback;
988 pScanCmd->u.scanCmd.pContext = pContext;
989 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
990 //Need to make the following atomic
991 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
992 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
993 if ( !HAL_STATUS_SUCCESS( status ) )
994 {
995 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
996 csrReleaseCommandScan(pMac, pScanCmd);
997 }
998 }
999 else
1000 {
1001 //log error
1002 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1003 status = eHAL_STATUS_RESOURCES;
1004 }
1005 }
1006
1007 return (status);
1008}
1009#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001010
1011eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1012{
1013 eHalStatus status = eHAL_STATUS_SUCCESS;
1014 tANI_U32 scanId;
1015 tCsrScanRequest scanReq;
1016
1017 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
1018 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1019 scanReq.scanType = eSIR_ACTIVE_SCAN;
1020 scanReq.requestType = reqType;
1021 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1022 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001023 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1024 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001025 //Scan with invalid sessionId.
1026 //This results in SME using the first available session to scan.
1027 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1028 &scanId, NULL, NULL);
1029
1030 return (status);
1031}
1032
1033
1034
1035
1036eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1037{
1038 eHalStatus status = eHAL_STATUS_FAILURE;
1039 tScanResultHandle hBSSList = NULL;
1040 tCsrScanResultFilter *pScanFilter = NULL;
1041 tANI_U32 roamId = 0;
1042 tCsrRoamProfile *pProfile = NULL;
1043 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1044
Jeff Johnson32d95a32012-09-10 13:15:23 -07001045 if(!pSession)
1046 {
1047 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1048 return eHAL_STATUS_FAILURE;
1049 }
1050
Jeff Johnson295189b2012-06-20 16:38:30 -07001051 do
1052 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001053 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001054 if(pSession->fCancelRoaming)
1055 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001056 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001057 csrScanStartIdleScan(pMac);
1058 status = eHAL_STATUS_SUCCESS;
1059 break;
1060 }
1061 //Here is the profile we need to connect to
1062 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1063 if(!HAL_STATUS_SUCCESS(status))
1064 break;
1065 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1066 if(NULL == pSession->pCurRoamProfile)
1067 {
1068 pScanFilter->EncryptionType.numEntries = 1;
1069 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1070 }
1071 else
1072 {
1073 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
1074 status = palAllocateMemory(pMac->hHdd, (void **)&pProfile, sizeof(tCsrRoamProfile));
1075 if(!HAL_STATUS_SUCCESS(status))
1076 break;
1077 palZeroMemory(pMac->hHdd, pProfile, sizeof(tCsrRoamProfile));
1078 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1079 if(!HAL_STATUS_SUCCESS(status))
1080 break;
1081 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1082 }//We have a profile
1083 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1084 if(HAL_STATUS_SUCCESS(status))
1085 {
1086 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1087 if(HAL_STATUS_SUCCESS(status))
1088 {
1089 if(eCsrLostLink1 == reason)
1090 {
1091 //we want to put the last connected BSS to the very beginning, if possible
1092 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1093 }
1094 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1095 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1096 if(!HAL_STATUS_SUCCESS(status))
1097 {
1098 csrScanResultPurge(pMac, hBSSList);
1099 }
1100 }//Have scan result
1101 }
1102 }while(0);
1103 if(pScanFilter)
1104 {
1105 //we need to free memory for filter if profile exists
1106 csrFreeScanFilter(pMac, pScanFilter);
1107 palFreeMemory(pMac->hHdd, pScanFilter);
1108 }
1109 if(NULL != pProfile)
1110 {
1111 csrReleaseProfile(pMac, pProfile);
1112 palFreeMemory(pMac->hHdd, (void *)pProfile);
1113 }
1114
1115 return (status);
1116}
1117
1118
Jeff Johnson32d95a32012-09-10 13:15:23 -07001119eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, void *callback, void *pContext)
Jeff Johnson295189b2012-06-20 16:38:30 -07001120{
1121 eHalStatus status = eHAL_STATUS_SUCCESS;
1122 tSmeCmd *pScanCmd;
1123
1124 if(pMac->scan.fScanEnable)
1125 {
1126 pScanCmd = csrGetCommandBuffer(pMac);
1127 if(pScanCmd)
1128 {
1129 pScanCmd->command = eSmeCommandScan;
1130 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
Jeff Johnson32d95a32012-09-10 13:15:23 -07001131 pScanCmd->u.scanCmd.callback = callback;
1132 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001133 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1134 //Need to make the following atomic
1135 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
1136 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1137 if( !HAL_STATUS_SUCCESS( status ) )
1138 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001139 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001140 csrReleaseCommandScan(pMac, pScanCmd);
1141 }
1142 }
1143 else
1144 {
1145 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001146 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001147 status = eHAL_STATUS_RESOURCES;
1148 }
1149 }
1150
1151 return (status);
1152}
1153
1154
1155eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1156{
1157 eHalStatus status = eHAL_STATUS_FAILURE;
1158 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1159
Jeff Johnson32d95a32012-09-10 13:15:23 -07001160 if(!pSession)
1161 {
1162 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1163 return eHAL_STATUS_FAILURE;
1164 }
1165
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001166 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001167 if(pSession->fCancelRoaming)
1168 {
1169 csrScanStartIdleScan(pMac);
1170 }
1171 else if(pSession->pCurRoamProfile)
1172 {
1173 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1174 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1175 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1176 {
1177 //try lostlink scan2
1178 status = csrScanRequestLostLink2(pMac, sessionId);
1179 }
1180 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1181 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1182 {
1183 //go straight to lostlink scan3
1184 status = csrScanRequestLostLink3(pMac, sessionId);
1185 }
1186 else
1187 {
1188 //we are done with lostlink
1189 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1190 {
1191 csrScanStartIdleScan(pMac);
1192 }
1193 status = eHAL_STATUS_SUCCESS;
1194 }
1195 }
1196 else
1197 {
1198 status = csrScanRequestLostLink3(pMac, sessionId);
1199 }
1200
1201 return (status);
1202}
1203
1204
1205
1206eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1207{
1208 eHalStatus status = eHAL_STATUS_FAILURE;
1209 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1210
Jeff Johnson32d95a32012-09-10 13:15:23 -07001211 if(!pSession)
1212 {
1213 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1214 return eHAL_STATUS_FAILURE;
1215 }
1216
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001217 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001218 if(pSession->fCancelRoaming)
1219 {
1220 csrScanStartIdleScan(pMac);
1221 }
1222 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1223 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1224 {
1225 //try lostlink scan3
1226 status = csrScanRequestLostLink3(pMac, sessionId);
1227 }
1228 else
1229 {
1230 //we are done with lostlink
1231 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1232 {
1233 csrScanStartIdleScan(pMac);
1234 }
1235 }
1236
1237 return (status);
1238}
1239
1240
1241
1242eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1243{
1244 eHalStatus status = eHAL_STATUS_SUCCESS;
1245
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001246 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001247 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1248 {
1249 //we are done with lostlink
1250 csrScanStartIdleScan(pMac);
1251 }
1252
1253 return (status);
1254}
1255
1256
1257
1258
1259//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1260//If no roam profile (it should not), it is like lostlinkscan3
1261eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1262{
1263 eHalStatus status = eHAL_STATUS_SUCCESS;
1264 tSmeCmd *pCommand = NULL;
1265 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1266 tCsrScanResultFilter *pScanFilter = NULL;
1267 tScanResultHandle hBSSList = NULL;
1268 tCsrScanResultInfo *pScanResult = NULL;
1269 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1270
Jeff Johnson32d95a32012-09-10 13:15:23 -07001271 if(!pSession)
1272 {
1273 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1274 return eHAL_STATUS_FAILURE;
1275 }
1276
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001277 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001278 do
1279 {
1280 pCommand = csrGetCommandBuffer(pMac);
1281 if(!pCommand)
1282 {
1283 status = eHAL_STATUS_RESOURCES;
1284 break;
1285 }
1286 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1287 pCommand->command = eSmeCommandScan;
1288 pCommand->sessionId = (tANI_U8)sessionId;
1289 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1290 pCommand->u.scanCmd.callback = NULL;
1291 pCommand->u.scanCmd.pContext = NULL;
1292 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1293 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001294 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1295 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001296 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1297 if(pSession->connectedProfile.SSID.length)
1298 {
1299 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
1300 if(!HAL_STATUS_SUCCESS(status))
1301 {
1302 break;
1303 }
1304 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
1305 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1306 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
1307 }
1308 else
1309 {
1310 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1311 }
1312 if(pSession->pCurRoamProfile)
1313 {
1314 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1315 if(!HAL_STATUS_SUCCESS(status))
1316 {
1317 break;
1318 }
1319 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1320 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1321 if(!HAL_STATUS_SUCCESS(status))
1322 {
1323 break;
1324 }
1325 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1326 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1327 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1328 {
1329 tANI_U8 i, nChn = 0;
1330 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1331 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1332 if(!HAL_STATUS_SUCCESS(status))
1333 {
1334 break;
1335 }
1336 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1337 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1338 {
1339 for(i = 0; i < nChn; i++)
1340 {
1341 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1342 pScanResult->BssDescriptor.channelId)
1343 {
1344 break;
1345 }
1346 }
1347 if(i == nChn)
1348 {
1349 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1350 }
1351 }
1352 //Include the last connected BSS' channel
1353 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1354 {
1355 for(i = 0; i < nChn; i++)
1356 {
1357 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1358 pSession->connectedProfile.operationChannel)
1359 {
1360 break;
1361 }
1362 }
1363 if(i == nChn)
1364 {
1365 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1366 }
1367 }
1368 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1369 }
1370 else
1371 {
1372 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1373 {
1374 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1375 1);
1376 //just try the last connected channel
1377 if(HAL_STATUS_SUCCESS(status))
1378 {
1379 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1380 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1381 }
1382 else
1383 {
1384 break;
1385 }
1386 }
1387 }
1388 }
1389 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1390 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1391 if( !HAL_STATUS_SUCCESS( status ) )
1392 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001393 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001394 break;
1395 }
1396 } while( 0 );
1397
1398 if(!HAL_STATUS_SUCCESS(status))
1399 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001400 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001401 if(pCommand)
1402 {
1403 csrReleaseCommandScan(pMac, pCommand);
1404 }
1405 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1406 }
1407 if(pScanFilter)
1408 {
1409 csrFreeScanFilter(pMac, pScanFilter);
1410 palFreeMemory(pMac->hHdd, pScanFilter);
1411 }
1412 if(hBSSList)
1413 {
1414 csrScanResultPurge(pMac, hBSSList);
1415 }
1416
1417 return( status );
1418}
1419
1420
1421//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1422//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1423eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1424{
1425 eHalStatus status = eHAL_STATUS_SUCCESS;
1426 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1427 tCsrScanResultFilter *pScanFilter = NULL;
1428 tScanResultHandle hBSSList = NULL;
1429 tCsrScanResultInfo *pScanResult = NULL;
1430 tSmeCmd *pCommand = NULL;
1431 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1432
Jeff Johnson32d95a32012-09-10 13:15:23 -07001433 if(!pSession)
1434 {
1435 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1436 return eHAL_STATUS_FAILURE;
1437 }
1438
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001439 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001440 do
1441 {
1442 pCommand = csrGetCommandBuffer(pMac);
1443 if(!pCommand)
1444 {
1445 status = eHAL_STATUS_RESOURCES;
1446 break;
1447 }
1448 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1449 pCommand->command = eSmeCommandScan;
1450 pCommand->sessionId = (tANI_U8)sessionId;
1451 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1452 pCommand->u.scanCmd.callback = NULL;
1453 pCommand->u.scanCmd.pContext = NULL;
1454 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1455 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001456 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1457 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001458 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1459 if(pSession->pCurRoamProfile)
1460 {
1461 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1462 if(!HAL_STATUS_SUCCESS(status))
1463 {
1464 break;
1465 }
1466 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1467 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1468 if(!HAL_STATUS_SUCCESS(status))
1469 {
1470 break;
1471 }
1472 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1473 if(!HAL_STATUS_SUCCESS(status))
1474 {
1475 break;
1476 }
1477 if(hBSSList)
1478 {
1479 tANI_U8 i, nChn = 0;
1480 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1481 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1482 if(!HAL_STATUS_SUCCESS(status))
1483 {
1484 break;
1485 }
1486 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1487 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1488 {
1489 for(i = 0; i < nChn; i++)
1490 {
1491 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1492 pScanResult->BssDescriptor.channelId)
1493 {
1494 break;
1495 }
1496 }
1497 if(i == nChn)
1498 {
1499 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1500 }
1501 }
1502 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1503 }
1504 }
1505 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1506 //Put to the head in pending queue
1507 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1508 if( !HAL_STATUS_SUCCESS( status ) )
1509 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001510 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001511 break;
1512 }
1513 } while( 0 );
1514
1515 if(!HAL_STATUS_SUCCESS(status))
1516 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001517 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001518 if(pCommand)
1519 {
1520 csrReleaseCommandScan(pMac, pCommand);
1521 }
1522 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1523 }
1524 if(pScanFilter)
1525 {
1526 csrFreeScanFilter(pMac, pScanFilter);
1527 palFreeMemory(pMac->hHdd, pScanFilter);
1528 }
1529 if(hBSSList)
1530 {
1531 csrScanResultPurge(pMac, hBSSList);
1532 }
1533
1534 return( status );
1535}
1536
1537
1538//To actively scan all valid channels
1539eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1540{
1541 eHalStatus status = eHAL_STATUS_SUCCESS;
1542 tSmeCmd *pCommand;
1543 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1544
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001545 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001546 do
1547 {
1548 pCommand = csrGetCommandBuffer(pMac);
1549 if(!pCommand)
1550 {
1551 status = eHAL_STATUS_RESOURCES;
1552 break;
1553 }
1554 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1555 pCommand->command = eSmeCommandScan;
1556 pCommand->sessionId = (tANI_U8)sessionId;
1557 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1558 pCommand->u.scanCmd.callback = NULL;
1559 pCommand->u.scanCmd.pContext = NULL;
1560 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1561 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001562 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1563 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001564 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1565 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1566 //Put to the head of pending queue
1567 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1568 if( !HAL_STATUS_SUCCESS( status ) )
1569 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001570 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001571 break;
1572 }
1573 } while( 0 );
1574 if(!HAL_STATUS_SUCCESS(status))
1575 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001576 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001577 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1578 {
1579 csrScanStartIdleScan(pMac);
1580 }
1581 if(pCommand)
1582 {
1583 csrReleaseCommandScan(pMac, pCommand);
1584 }
1585 }
1586
1587 return( status );
1588}
1589
1590
1591eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1592{
1593 eHalStatus status = eHAL_STATUS_FAILURE;
1594 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1595 tCsrScanResultFilter *pScanFilter = NULL;
1596 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1597 tANI_U32 sessionId = pCommand->sessionId;
1598#ifdef FEATURE_WLAN_BTAMP_UT_RF
1599 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1600#endif
1601 do
1602 {
1603 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1604 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1605 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001606 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001607 break;
1608 }
1609 if(pProfile == NULL)
1610 break;
1611 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1612 if(!HAL_STATUS_SUCCESS(status))
1613 break;
1614 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1615 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1616 if(!HAL_STATUS_SUCCESS(status))
1617 break;
1618 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1619 if(!HAL_STATUS_SUCCESS(status))
1620 break;
1621 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1622 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1623 if(!HAL_STATUS_SUCCESS(status))
1624 {
1625 break;
1626 }
1627 }while(0);
1628 if(!HAL_STATUS_SUCCESS(status))
1629 {
1630 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1631 {
1632 csrScanResultPurge(pMac, hBSSList);
1633 }
1634 //We haven't done anything to this profile
1635 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1636 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1637 //In case we have nothing else to do, restart idle scan
1638 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1639 {
1640 status = csrScanStartIdleScan(pMac);
1641 }
1642#ifdef FEATURE_WLAN_BTAMP_UT_RF
1643 //In case of WDS station, let it retry.
1644 if( CSR_IS_WDS_STA(pProfile) )
1645 {
1646 //Save the roma profile so we can retry
1647 csrFreeRoamProfile( pMac, sessionId );
1648 if (HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd,
1649 (void **)&pSession->pCurRoamProfile,
1650 sizeof(tCsrRoamProfile))))
1651 {
1652 palZeroMemory(pMac->hHdd, pSession->pCurRoamProfile, sizeof(tCsrRoamProfile));
1653 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1654 }
1655 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1656 }
1657#endif
1658 }
1659 if(pScanFilter)
1660 {
1661 csrFreeScanFilter(pMac, pScanFilter);
1662 palFreeMemory(pMac->hHdd, pScanFilter);
1663 }
1664
1665 return (status);
1666}
1667
1668
1669eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1670{
1671 eHalStatus status = eHAL_STATUS_SUCCESS;
1672 tANI_U32 sessionId = pCommand->sessionId;
1673 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1674 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1675
Jeff Johnson32d95a32012-09-10 13:15:23 -07001676 if(!pSession)
1677 {
1678 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1679 return eHAL_STATUS_FAILURE;
1680 }
1681
Jeff Johnson295189b2012-06-20 16:38:30 -07001682#if defined(WLAN_DEBUG)
1683 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1684 {
1685 char str[36];
1686 palCopyMemory(pMac->hHdd, str, pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1687 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
1688 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001689 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001690 }
1691#endif
1692 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1693 if(pProfile && CSR_IS_START_IBSS(pProfile))
1694 {
1695 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1696 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1697 if(!HAL_STATUS_SUCCESS(status))
1698 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001699 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001700 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1701 }
1702 }
1703 else
1704 {
1705 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1706
1707 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1708 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1709 {
1710 status = csrScanStartIdleScan(pMac);
1711 }
1712 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1713 {
1714 //Only indicate assoc_completion if we indicate assoc_start.
1715 if(pSession->bRefAssocStartCnt > 0)
1716 {
1717 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
1718 palZeroMemory(pMac->hHdd, &roamInfo, sizeof(tCsrRoamInfo));
1719 pRoamInfo = &roamInfo;
1720 if(pCommand->u.roamCmd.pRoamBssEntry)
1721 {
1722 tCsrScanResult *pScanResult =
1723 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1724 tCsrScanResult, Link);
1725 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1726 }
1727 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1728 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1729 pSession->bRefAssocStartCnt--;
1730 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1731 pCommand->u.scanCmd.roamId,
1732 eCSR_ROAM_ASSOCIATION_COMPLETION,
1733 eCSR_ROAM_RESULT_FAILURE);
1734 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001735 else
1736 {
1737 csrRoamCallCallback(pMac, sessionId, NULL,
1738 pCommand->u.scanCmd.roamId,
1739 eCSR_ROAM_ASSOCIATION_FAILURE,
1740 eCSR_ROAM_RESULT_FAILURE);
1741 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001742#ifdef FEATURE_WLAN_BTAMP_UT_RF
1743 //In case of WDS station, let it retry.
1744 if( CSR_IS_WDS_STA(pProfile) )
1745 {
1746 //Save the roma profile so we can retry
1747 csrFreeRoamProfile( pMac, sessionId );
1748 if (HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd,
1749 (void **)&pSession->pCurRoamProfile,
1750 sizeof(tCsrRoamProfile))))
1751 {
1752 palZeroMemory(pMac->hHdd, pSession->pCurRoamProfile, sizeof(tCsrRoamProfile));
1753 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1754 }
1755 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1756 }
1757#endif
1758 }
1759 else
1760 {
1761 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1762 }
1763 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1764 }
1765
1766 return (status);
1767}
1768
1769
1770//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1771eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1772{
1773 eHalStatus status = eHAL_STATUS_FAILURE;
1774 tScanResultHandle hBSSList = NULL;
1775 tCsrScanResultFilter *pScanFilter = NULL;
1776 tANI_U32 roamId = 0;
1777 tCsrRoamProfile *pProfile = NULL;
1778 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1779
1780 do
1781 {
1782 //Here is the profile we need to connect to
1783 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1784 if(!HAL_STATUS_SUCCESS(status))
1785 break;
1786 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1787 if(NULL == pSession) break;
1788 if(NULL == pSession->pCurRoamProfile)
1789 {
1790 pScanFilter->EncryptionType.numEntries = 1;
1791 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1792 }
1793 else
1794 {
1795 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
1796 status = palAllocateMemory(pMac->hHdd, (void **)&pProfile, sizeof(tCsrRoamProfile));
1797 if(!HAL_STATUS_SUCCESS(status))
1798 break;
1799 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1800 if(!HAL_STATUS_SUCCESS(status))
1801 break;
1802 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1803 }//We have a profile
1804 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1805 if(HAL_STATUS_SUCCESS(status))
1806 {
1807 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1808 if(HAL_STATUS_SUCCESS(status))
1809 {
1810 //we want to put the last connected BSS to the very beginning, if possible
1811 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1812 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1813 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1814 if(!HAL_STATUS_SUCCESS(status))
1815 {
1816 csrScanResultPurge(pMac, hBSSList);
1817 }
1818 }//Have scan result
1819 else
1820 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001821 smsLog(pMac, LOGW, FL("cannot find matching BSS of %02X-%02X-%02X-%02X-%02X-%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001822 pSession->connectedProfile.bssid[0],
1823 pSession->connectedProfile.bssid[1],
1824 pSession->connectedProfile.bssid[2],
1825 pSession->connectedProfile.bssid[3],
1826 pSession->connectedProfile.bssid[4],
1827 pSession->connectedProfile.bssid[5]);
1828 //Disconnect
1829 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1830 }
1831 }
1832 }while(0);
1833 if(pScanFilter)
1834 {
1835 csrFreeScanFilter(pMac, pScanFilter);
1836 palFreeMemory(pMac->hHdd, pScanFilter);
1837 }
1838 if(NULL != pProfile)
1839 {
1840 csrReleaseProfile(pMac, pProfile);
1841 palFreeMemory(pMac->hHdd, pProfile);
1842 }
1843
1844 return (status);
1845}
1846
1847
1848
1849eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1850{
1851 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1852 tScanResultList *pScanList = (tScanResultList *)hScanList;
1853
1854 if(pScanList)
1855 {
1856 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1857 csrLLClose(&pScanList->List);
1858 palFreeMemory(pMac->hHdd, pScanList);
1859 }
1860 return (status);
1861}
1862
1863
1864static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1865{
1866 tANI_U32 ret = 0;
1867 int i = CSR_NUM_RSSI_CAT - 1;
1868
1869 while(i >= 0)
1870 {
1871 if(rssi >= pMac->roam.configParam.RSSICat[i])
1872 {
1873 ret = pMac->roam.configParam.BssPreferValue[i];
1874 break;
1875 }
1876 i--;
1877 };
1878
1879 return (ret);
1880}
1881
1882
1883//Return a CapValue base on the capabilities of a BSS
1884static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
1885{
1886 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08001887#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
1888 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
1889 {
1890 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
1891 {
1892 ret += CSR_BSS_CAP_VALUE_5GHZ;
1893 }
1894 }
1895#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001896 if( pIes )
1897 {
1898 //We only care about 11N capability
1899 if(pIes->HTCaps.present)
1900 {
1901 ret += CSR_BSS_CAP_VALUE_HT;
1902 }
1903 if(CSR_IS_QOS_BSS(pIes))
1904 {
1905 ret += CSR_BSS_CAP_VALUE_WMM;
1906 //Give advantage to UAPSD
1907 if(CSR_IS_UAPSD_BSS(pIes))
1908 {
1909 ret += CSR_BSS_CAP_VALUE_UAPSD;
1910 }
1911 }
1912 }
1913
1914 return (ret);
1915}
1916
1917
1918//To check whther pBss1 is better than pBss2
1919static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
1920{
1921 tANI_BOOLEAN ret;
1922
1923 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
1924 {
1925 ret = eANI_BOOLEAN_TRUE;
1926 }
1927 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
1928 {
1929 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
1930 {
1931 ret = eANI_BOOLEAN_TRUE;
1932 }
1933 else
1934 {
1935 ret = eANI_BOOLEAN_FALSE;
1936 }
1937 }
1938 else
1939 {
1940 ret = eANI_BOOLEAN_FALSE;
1941 }
1942
1943 return (ret);
1944}
1945
1946
Srikant Kuppa866893f2012-12-27 17:28:14 -08001947#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001948//Add the channel to the occupiedChannels array
1949static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08001950 tpAniSirGlobal pMac,
1951 tCsrScanResult *pResult,
1952 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001953 tDot11fBeaconIEs *pIes)
1954{
1955 eHalStatus status;
1956 tANI_U8 channel;
1957 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
1958 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
1959
1960 channel = pResult->Result.BssDescriptor.channelId;
1961
1962 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08001963 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001964 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08001965 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001966 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08001967 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001968 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001969 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08001970 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08001971 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
1972 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
1973 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001974 }
1975}
1976#endif
1977
Jeff Johnson295189b2012-06-20 16:38:30 -07001978//Put the BSS into the scan result list
1979//pIes can not be NULL
1980static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
1981{
Srinivas28b5b4e2012-12-12 13:07:53 -08001982#ifdef FEATURE_WLAN_LFR
1983 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
1984#endif
1985
Jeff Johnson295189b2012-06-20 16:38:30 -07001986 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
1987 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
1988 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08001989#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08001990 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
1991 {
1992 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
1993 NOT set in the cfg.ini file */
1994 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
1995 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001996#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001997}
1998
1999
2000eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2001{
2002 eHalStatus status;
2003 tScanResultList *pRetList;
2004 tCsrScanResult *pResult, *pBssDesc;
2005 tANI_U32 count = 0;
2006 tListElem *pEntry;
2007 tANI_U32 bssLen, allocLen;
2008 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2009 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2010 tDot11fBeaconIEs *pIes, *pNewIes;
2011 tANI_BOOLEAN fMatch;
2012
2013 if(phResult)
2014 {
2015 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2016 }
2017 status = palAllocateMemory(pMac->hHdd, (void **)&pRetList, sizeof(tScanResultList));
2018 if(HAL_STATUS_SUCCESS(status))
2019 {
2020 palZeroMemory(pMac->hHdd, pRetList, sizeof(tScanResultList));
2021 csrLLOpen(pMac->hHdd, &pRetList->List);
2022 pRetList->pCurEntry = NULL;
2023
2024 csrLLLock(&pMac->scan.scanResultList);
2025 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2026 while( pEntry )
2027 {
2028 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2029 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2030 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2031 //for any error condition, otherwiase, it will be freed later.
2032 //reset
2033 fMatch = eANI_BOOLEAN_FALSE;
2034 pNewIes = NULL;
2035
2036 if(pFilter)
2037 {
2038 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2039 if( NULL != pIes )
2040 {
2041 //Only save it when matching
2042 if(fMatch)
2043 {
2044 if( !pBssDesc->Result.pvIes )
2045 {
2046 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2047 pNewIes = pIes;
2048 }
2049 else
2050 {
2051 //The pIes is allocated by someone else. make a copy
2052 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2053 //is using to for association, hence save the parsed IEs
2054 status = palAllocateMemory(pMac->hHdd, (void **)&pNewIes, sizeof(tDot11fBeaconIEs));
2055 if( HAL_STATUS_SUCCESS( status ) )
2056 {
2057 palCopyMemory( pMac->hHdd, pNewIes, pIes, sizeof( tDot11fBeaconIEs ) );
2058 }
2059 else
2060 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002061 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002062 //Need to free memory allocated by csrMatchBSS
2063 if( !pBssDesc->Result.pvIes )
2064 {
2065 palFreeMemory(pMac->hHdd, pIes);
2066 }
2067 break;
2068 }
2069 }
2070 }//fMatch
2071 else if( !pBssDesc->Result.pvIes )
2072 {
2073 palFreeMemory(pMac->hHdd, pIes);
2074 }
2075 }
2076 }
2077 if(NULL == pFilter || fMatch)
2078 {
2079 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2080 allocLen = sizeof( tCsrScanResult ) + bssLen;
2081 status = palAllocateMemory(pMac->hHdd, (void **)&pResult, allocLen);
2082 if(!HAL_STATUS_SUCCESS(status))
2083 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002084 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002085 if(pNewIes)
2086 {
2087 palFreeMemory(pMac->hHdd, pNewIes);
2088 }
2089 break;
2090 }
2091 palZeroMemory(pMac->hHdd, pResult, allocLen);
2092 pResult->capValue = pBssDesc->capValue;
2093 pResult->preferValue = pBssDesc->preferValue;
2094 pResult->ucEncryptionType = uc;
2095 pResult->mcEncryptionType = mc;
2096 pResult->authType = auth;
2097 pResult->Result.ssId = pBssDesc->Result.ssId;
2098 pResult->Result.timer = 0;
2099 //save the pIes for later use
2100 pResult->Result.pvIes = pNewIes;
2101 //save bss description
2102 status = palCopyMemory(pMac->hHdd, &pResult->Result.BssDescriptor, &pBssDesc->Result.BssDescriptor, bssLen);
2103 if(!HAL_STATUS_SUCCESS(status))
2104 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002105 smsLog(pMac, LOGE, FL(" fail to copy memory for scan result"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002106 palFreeMemory(pMac->hHdd, pResult);
2107 if(pNewIes)
2108 {
2109 palFreeMemory(pMac->hHdd, pNewIes);
2110 }
2111 break;
2112 }
2113 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2114 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2115 {
2116 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2117 }
2118 else
2119 {
2120 //To sort the list
2121 tListElem *pTmpEntry;
2122 tCsrScanResult *pTmpResult;
2123
2124 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2125 while(pTmpEntry)
2126 {
2127 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2128 if(csrIsBetterBss(pResult, pTmpResult))
2129 {
2130 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2131 //To indicate we are done
2132 pResult = NULL;
2133 break;
2134 }
2135 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2136 }
2137 if(pResult != NULL)
2138 {
2139 //This one is not better than any one
2140 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2141 }
2142 }
2143 count++;
2144 }
2145 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2146 }//while
2147 csrLLUnlock(&pMac->scan.scanResultList);
2148
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002149 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002150
2151 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2152 {
2153 //Fail or No one wants the result.
2154 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2155 }
2156 else
2157 {
2158 if(0 == count)
2159 {
2160 //We are here meaning the there is no match
2161 csrLLClose(&pRetList->List);
2162 palFreeMemory(pMac->hHdd, pRetList);
2163 status = eHAL_STATUS_E_NULL_VALUE;
2164 }
2165 else if(phResult)
2166 {
2167 *phResult = pRetList;
2168 }
2169 }
2170 }//Allocated pRetList
2171
2172 return (status);
2173}
2174
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002175/*
2176 * NOTE: This routine is being added to make
2177 * sure that scan results are not being flushed
2178 * while roaming. If the scan results are flushed,
2179 * we are unable to recover from
2180 * csrRoamRoamingStateDisassocRspProcessor.
2181 * If it is needed to remove this routine,
2182 * first ensure that we recover gracefully from
2183 * csrRoamRoamingStateDisassocRspProcessor if
2184 * csrScanGetResult returns with a failure because
2185 * of not being able to find the roaming BSS.
2186 */
2187tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2188{
2189 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2190 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2191 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2192 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2193 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2194 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2195 default:
2196 return 0;
2197 }
2198}
2199
Jeff Johnson295189b2012-06-20 16:38:30 -07002200eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2201{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002202 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
2203 if (isFlushDenied) {
2204 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2205 __func__, isFlushDenied);
2206 return eHAL_STATUS_FAILURE;
2207 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002208 return ( csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList) );
2209}
2210
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302211eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002212{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302213 eHalStatus status = eHAL_STATUS_SUCCESS;
2214 tListElem *pEntry,*pFreeElem;
2215 tCsrScanResult *pBssDesc;
2216 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002217
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302218 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002219
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302220 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2221 while( pEntry != NULL)
2222 {
2223 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2224 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2225 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002226 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302227 pFreeElem = pEntry;
2228 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2229 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2230 csrFreeScanResultEntry( pMac, pBssDesc );
2231 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002232 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302233 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2234 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002235
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302236 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002237
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302238 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002239}
2240
Jeff Johnson295189b2012-06-20 16:38:30 -07002241/**
2242 * csrCheck11dChannel
2243 *
2244 *FUNCTION:
2245 * This function is called from csrScanFilter11dResult function and
2246 * compare channel number with given channel list.
2247 *
2248 *LOGIC:
2249 * Check Scan result channel number with CFG channel list
2250 *
2251 *ASSUMPTIONS:
2252 *
2253 *
2254 *NOTE:
2255 *
2256 * @param channelId channel number
2257 * @param pChannelList Pointer to channel list
2258 * @param numChannels Number of channel in channel list
2259 *
2260 * @return Status
2261 */
2262
2263eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2264{
2265 eHalStatus status = eHAL_STATUS_FAILURE;
2266 tANI_U8 i = 0;
2267
2268 for (i = 0; i < numChannels; i++)
2269 {
2270 if(pChannelList[ i ] == channelId)
2271 {
2272 status = eHAL_STATUS_SUCCESS;
2273 break;
2274 }
2275 }
2276 return status;
2277}
2278
2279/**
2280 * csrScanFilter11dResult
2281 *
2282 *FUNCTION:
2283 * This function is called from csrApplyCountryInformation function and
2284 * filter scan result based on valid channel list number.
2285 *
2286 *LOGIC:
2287 * Get scan result from scan list and Check Scan result channel number
2288 * with 11d channel list if channel number is found in 11d channel list
2289 * then do not remove scan result entry from scan list
2290 *
2291 *ASSUMPTIONS:
2292 *
2293 *
2294 *NOTE:
2295 *
2296 * @param pMac Pointer to Global MAC structure
2297 *
2298 * @return Status
2299 */
2300
2301eHalStatus csrScanFilter11dResult(tpAniSirGlobal pMac)
2302{
2303 eHalStatus status = eHAL_STATUS_SUCCESS;
2304 tListElem *pEntry,*pTempEntry;
2305 tCsrScanResult *pBssDesc;
2306 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2307
2308 /* Get valid channels list from CFG */
2309 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2310 pMac->roam.validChannelList, &len)))
2311 {
2312 smsLog( pMac, LOG1, "Failed to get Channel list from CFG");
2313 }
2314
2315 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2316 while( pEntry )
2317 {
2318 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2319 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2320 LL_ACCESS_LOCK );
2321 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2322 pMac->roam.validChannelList, len))
2323 {
2324 /* Remove Scan result which does not have 11d channel */
2325 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2326 LL_ACCESS_LOCK ))
2327 {
2328 csrFreeScanResultEntry( pMac, pBssDesc );
2329 }
2330 }
2331 pEntry = pTempEntry;
2332 }
2333 return status;
2334}
2335
2336
2337eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2338{
2339 eHalStatus status = eHAL_STATUS_SUCCESS;
2340 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2341 tCsrScanResult *pResult, *pScanResult;
2342 tANI_U32 count = 0;
2343 tListElem *pEntry;
2344 tANI_U32 bssLen, allocLen;
2345
2346 if(phResult)
2347 {
2348 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2349 }
2350 status = palAllocateMemory(pMac->hHdd, (void **)&pRetList, sizeof(tScanResultList));
2351 if(HAL_STATUS_SUCCESS(status))
2352 {
2353 palZeroMemory(pMac->hHdd, pRetList, sizeof(tScanResultList));
2354 csrLLOpen(pMac->hHdd, &pRetList->List);
2355 pRetList->pCurEntry = NULL;
2356 csrLLLock(&pMac->scan.scanResultList);
2357 csrLLLock(&pInList->List);
2358
2359 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2360 while( pEntry )
2361 {
2362 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2363 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2364 allocLen = sizeof( tCsrScanResult ) + bssLen;
2365 status = palAllocateMemory(pMac->hHdd, (void **)&pResult, allocLen);
2366 if(!HAL_STATUS_SUCCESS(status))
2367 {
2368 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2369 count = 0;
2370 break;
2371 }
2372 palZeroMemory(pMac->hHdd, pResult, allocLen);
2373 status = palCopyMemory(pMac->hHdd, &pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
2374 if(!HAL_STATUS_SUCCESS(status))
2375 {
2376 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2377 count = 0;
2378 break;
2379 }
2380 if( pScanResult->Result.pvIes )
2381 {
2382 status = palAllocateMemory(pMac->hHdd, (void **)&pResult->Result.pvIes, sizeof( tDot11fBeaconIEs ));
2383 if(!HAL_STATUS_SUCCESS(status))
2384 {
2385 //Free the memory we allocate above first
2386 palFreeMemory( pMac->hHdd, pResult );
2387 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2388 count = 0;
2389 break;
2390 }
2391 status = palCopyMemory(pMac->hHdd, pResult->Result.pvIes,
2392 pScanResult->Result.pvIes, sizeof( tDot11fBeaconIEs ));
2393 if(!HAL_STATUS_SUCCESS(status))
2394 {
2395 //Free the memory we allocate above first
2396 palFreeMemory( pMac->hHdd, pResult );
2397 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2398 count = 0;
2399 break;
2400 }
2401 }
2402 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2403 count++;
2404 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2405 }//while
2406 csrLLUnlock(&pInList->List);
2407 csrLLUnlock(&pMac->scan.scanResultList);
2408
2409 if(HAL_STATUS_SUCCESS(status))
2410 {
2411 if(0 == count)
2412 {
2413 csrLLClose(&pRetList->List);
2414 palFreeMemory(pMac->hHdd, pRetList);
2415 status = eHAL_STATUS_E_NULL_VALUE;
2416 }
2417 else if(phResult)
2418 {
2419 *phResult = pRetList;
2420 }
2421 }
2422 }//Allocated pRetList
2423
2424 return (status);
2425}
2426
2427
2428
2429eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2430{
2431 eHalStatus status = eHAL_STATUS_SUCCESS;
2432 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2433
2434 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2435 {
2436 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2437 }
2438 else
2439 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002440 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002441 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002442 tCsrRoamSession *pSession;
2443 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2444 tCsrRoamInfo roamInfo;
2445 tCsrRoamInfo *pRoamInfo = NULL;
2446 tANI_U32 sessionId;
2447 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002448 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002449 palZeroMemory(pMac->hHdd, &roamInfo, sizeof(tCsrRoamInfo));
2450 pRoamInfo = &roamInfo;
2451 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2452 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2453 pSession = CSR_GET_SESSION(pMac, sessionId);
2454
2455 if(!pSession)
2456 {
2457 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2458 return eHAL_STATUS_FAILURE;
2459 }
2460
2461 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2462 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2463 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2464 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2465 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2466 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2467 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
2468 palCopyMemory(pMac->hHdd, pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2469 palCopyMemory(pMac->hHdd, &pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
2470 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2471 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2472 {
2473 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2474 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2475 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2476 }
2477 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2478 {
2479 vos_sleep( 100 );
2480 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2481 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2482 }
2483
Jeff Johnson295189b2012-06-20 16:38:30 -07002484 }
2485 else
2486 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002487
2488 if( csrIsAnySessionInConnectState( pMac ) )
2489 {
2490 //In case of we are connected, we need to check whether connect status changes
2491 //because scan may also run while connected.
2492 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2493 }
2494 else
2495 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002496 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002497 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002498 }
2499 }
2500
2501 return (status);
2502}
2503
2504
2505
2506void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2507{
2508 int idx, len;
2509 tANI_U8 *pbIe;
2510
2511 //If failed to remove, assuming someone else got it.
2512 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2513 (0 == pNewBssDescr->WscIeLen))
2514 {
2515 idx = 0;
2516 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2517 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2518 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2519 //Save WPS IE if it exists
2520 pNewBssDescr->WscIeLen = 0;
2521 while(idx < len)
2522 {
2523 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2524 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2525 {
2526 //Founrd it
2527 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2528 {
2529 palCopyMemory(pMac->hHdd, pNewBssDescr->WscIeProbeRsp,
2530 pbIe, pbIe[1] + 2);
2531 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2532 }
2533 break;
2534 }
2535 idx += pbIe[1] + 2;
2536 pbIe += pbIe[1] + 2;
2537 }
2538 }
2539}
2540
2541
2542
2543//pIes may be NULL
2544tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
2545 tDot11fBeaconIEs *pIes, tAniSSID *pSsid , v_TIME_t *timer )
2546{
2547 tListElem *pEntry;
2548
2549 tCsrScanResult *pBssDesc;
2550 tANI_BOOLEAN fRC = FALSE;
2551
2552 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2553 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2554 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2555 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2556
2557 while( pEntry )
2558 {
2559 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2560
2561 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2562 // matches
2563 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
2564 pSirBssDescr, pIes ) )
2565 {
2566 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2567 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2568 // Remove the 'old' entry from the list....
2569 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2570 {
2571 // !we need to free the memory associated with this node
2572 //If failed to remove, assuming someone else got it.
2573 *pSsid = pBssDesc->Result.ssId;
2574 *timer = pBssDesc->Result.timer;
2575 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2576
2577 csrFreeScanResultEntry( pMac, pBssDesc );
2578 }
2579 else
2580 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002581 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002582 }
2583 fRC = TRUE;
2584
2585 // If we found a match, we can stop looking through the list.
2586 break;
2587 }
2588
2589 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2590 }
2591
2592 return fRC;
2593}
2594
2595
2596eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2597 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2598{
2599 eHalStatus status = eHAL_STATUS_FAILURE;
2600 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2601
Jeff Johnson32d95a32012-09-10 13:15:23 -07002602 if(!pSession)
2603 {
2604 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2605 return eHAL_STATUS_FAILURE;
2606 }
2607
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002608 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002609 if( pIes )
2610 {
2611 // check if this is a RSN BSS
2612 if( pIes->RSN.present )
2613 {
2614 // Check if the BSS is capable of doing pre-authentication
2615 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2616 {
2617
2618#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2619 {
2620 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
2621 palZeroMemory(pMac->hHdd, &secEvent, sizeof(vos_event_wlan_security_payload_type));
2622 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2623 secEvent.encryptionModeMulticast =
2624 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2625 secEvent.encryptionModeUnicast =
2626 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
2627 palCopyMemory( pMac->hHdd, secEvent.bssid, pSession->connectedProfile.bssid, 6 );
2628 secEvent.authMode =
2629 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2630 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2631 }
2632#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2633
2634 // if yes, then add to PMKIDCandidateList
2635 status = palCopyMemory(pMac->hHdd, pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2636 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2637
2638 if( HAL_STATUS_SUCCESS( status ) )
2639 {
Venkata Prathyusha Kuntupalliea7098e2013-01-31 16:08:13 -08002640 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 ) // Bit 0 offirst byte - PreAuthentication Capability
Jeff Johnson295189b2012-06-20 16:38:30 -07002641 {
2642 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported = eANI_BOOLEAN_TRUE;
2643 }
2644 else
2645 {
2646 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported = eANI_BOOLEAN_FALSE;
2647 }
2648 pSession->NumPmkidCandidate++;
2649 }
2650 }
2651 else
2652 {
2653 status = eHAL_STATUS_FAILURE;
2654 }
2655 }
2656 }
2657
2658 return (status);
2659}
2660
2661//This function checks whether new AP is found for the current connected profile
2662//If it is found, it return the sessionId, else it return invalid sessionID
2663tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2664 tSirBssDescription *pBssDesc,
2665 tDot11fBeaconIEs *pIes)
2666{
2667 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2668 tCsrRoamSession *pSession;
2669 tDot11fBeaconIEs *pIesLocal = pIes;
2670
2671 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2672 {
2673 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2674 {
2675 if( CSR_IS_SESSION_VALID( pMac, i ) )
2676 {
2677 pSession = CSR_GET_SESSION( pMac, i );
2678 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2679 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2680 {
2681 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2682 {
2683 //this new BSS fits the current profile connected
2684 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2685 {
2686 bRet = i;
2687 }
2688 break;
2689 }
2690 }
2691 }
2692 }
2693 if( !pIes )
2694 {
2695 palFreeMemory(pMac->hHdd, pIesLocal);
2696 }
2697 }
2698
2699 return (tANI_U8)bRet;
2700}
2701
2702#ifdef FEATURE_WLAN_WAPI
2703eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2704 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2705{
2706 eHalStatus status = eHAL_STATUS_FAILURE;
2707 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2708
Jeff Johnson32d95a32012-09-10 13:15:23 -07002709 if(!pSession)
2710 {
2711 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2712 return eHAL_STATUS_FAILURE;
2713 }
2714
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002715 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002716 if( pIes )
2717 {
2718 // check if this is a WAPI BSS
2719 if( pIes->WAPI.present )
2720 {
2721 // Check if the BSS is capable of doing pre-authentication
2722 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
2723 {
2724
2725 // if yes, then add to BKIDCandidateList
2726 status = palCopyMemory(pMac->hHdd, pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
2727 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2728
2729 if( HAL_STATUS_SUCCESS( status ) )
2730 {
2731 if ( pIes->WAPI.preauth )
2732 {
2733 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported = eANI_BOOLEAN_TRUE;
2734 }
2735 else
2736 {
2737 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported = eANI_BOOLEAN_FALSE;
2738 }
2739 pSession->NumBkidCandidate++;
2740 }
2741 }
2742 else
2743 {
2744 status = eHAL_STATUS_FAILURE;
2745 }
2746 }
2747 }
2748
2749 return (status);
2750}
2751
2752//This function checks whether new AP is found for the current connected profile
2753//if so add to BKIDCandidateList
2754tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
2755 tDot11fBeaconIEs *pIes)
2756{
2757 tANI_BOOLEAN fRC = FALSE;
2758 tDot11fBeaconIEs *pIesLocal = pIes;
2759 tANI_U32 sessionId;
2760 tCsrRoamSession *pSession;
2761
2762 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2763 {
2764 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
2765 {
2766 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
2767 {
2768 pSession = CSR_GET_SESSION( pMac, sessionId );
2769 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
2770 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
2771 {
2772 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
2773 {
2774 //this new BSS fits the current profile connected
2775 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
2776 {
2777 fRC = TRUE;
2778 }
2779 }
2780 }
2781 }
2782 }
2783 if(!pIes)
2784 {
2785 palFreeMemory(pMac->hHdd, pIesLocal);
2786 }
2787
2788 }
2789 return fRC;
2790}
2791
2792#endif
2793
2794
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002795static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07002796{
2797 tListElem *pEntry;
2798 tCsrScanResult *pBssDescription;
2799 tANI_S8 cand_Bss_rssi;
2800 tANI_BOOLEAN fDupBss;
2801#ifdef FEATURE_WLAN_WAPI
2802 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
2803#endif /* FEATURE_WLAN_WAPI */
2804 tDot11fBeaconIEs *pIesLocal = NULL;
2805 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
2806 tAniSSID tmpSsid;
2807 v_TIME_t timer=0;
2808
2809 tmpSsid.length = 0;
2810 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
2811
2812 // remove the BSS descriptions from temporary list
2813 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
2814 {
2815 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2816
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002817 smsLog( pMac, LOGW, "...Bssid= %02x-%02x-%02x-%02x-%02x-%02x chan= %d, rssi = -%d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002818 pBssDescription->Result.BssDescriptor.bssId[ 0 ], pBssDescription->Result.BssDescriptor.bssId[ 1 ],
2819 pBssDescription->Result.BssDescriptor.bssId[ 2 ], pBssDescription->Result.BssDescriptor.bssId[ 3 ],
2820 pBssDescription->Result.BssDescriptor.bssId[ 4 ], pBssDescription->Result.BssDescriptor.bssId[ 5 ],
2821 pBssDescription->Result.BssDescriptor.channelId,
2822 pBssDescription->Result.BssDescriptor.rssi * (-1) );
2823
2824 //At this time, pBssDescription->Result.pvIes may be NULL
2825 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
2826 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
2827 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002828 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002829 csrFreeScanResultEntry(pMac, pBssDescription);
2830 continue;
2831 }
2832 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid , &timer );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002833 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
2834 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
2835#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2836 && !( eCsrScanGetLfrResult == reason )
2837#endif
2838 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002839 {
2840 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002841 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002842 //Free the resources
2843 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2844 {
2845 palFreeMemory(pMac->hHdd, pIesLocal);
2846 }
2847 csrFreeScanResultEntry(pMac, pBssDescription);
2848 //Continue because there may be duplicated BSS
2849 continue;
2850 }
2851 // check for duplicate scan results
2852 if ( !fDupBss )
2853 {
2854 //Found a new BSS
2855 sessionId = csrProcessBSSDescForPMKIDList(pMac,
2856 &pBssDescription->Result.BssDescriptor, pIesLocal);
2857 if( CSR_SESSION_ID_INVALID != sessionId)
2858 {
2859 csrRoamCallCallback(pMac, sessionId, NULL, 0,
2860 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
2861 }
2862 }
2863 else
2864 {
2865 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
2866 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
2867 {
2868 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
2869 //if diff of saved SSID time and current time is less than 1 min to avoid
2870 //side effect of saving SSID with old one is that if AP changes its SSID while remain
2871 //hidden, we may never see it and also to address the requirement of
2872 //When we remove hidden ssid from the profile i.e., forget the SSID via
2873 // GUI that SSID shouldn't see in the profile
2874 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
2875 {
2876 pBssDescription->Result.timer = timer;
2877 pBssDescription->Result.ssId = tmpSsid;
2878 }
2879 }
2880 }
2881
2882 //Tush: find a good AP for 11d info
2883 if( csrIs11dSupported( pMac ) )
2884 {
2885 if(cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
2886 {
2887 // check if country information element is present
2888 if(pIesLocal->Country.present)
2889 {
2890 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
2891 // learn country information
2892 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
2893 pIesLocal, eANI_BOOLEAN_FALSE );
2894 }
2895
2896 }
2897 }
2898
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08002899
Jeff Johnson295189b2012-06-20 16:38:30 -07002900 // append to main list
2901 csrScanAddResult(pMac, pBssDescription, pIesLocal);
2902 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2903 {
2904 palFreeMemory(pMac->hHdd, pIesLocal);
2905 }
2906 }
2907
2908 //Tush: If we can find the current 11d info in any of the scan results, or
2909 // a good enough AP with the 11d info from the scan results then no need to
2910 // get into ambiguous state
2911 if(pMac->scan.fAmbiguous11dInfoFound)
2912 {
2913 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
2914 {
2915 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
2916 }
2917 }
2918
2919#ifdef FEATURE_WLAN_WAPI
2920 if(fNewWapiBSSForCurConnection)
2921 {
2922 //remember it first
2923 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
2924 }
2925#endif /* FEATURE_WLAN_WAPI */
2926
2927 return;
2928}
2929
2930
2931static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
2932 tDot11fBeaconIEs *pIes)
2933{
2934 tCsrScanResult *pCsrBssDescription = NULL;
2935 tANI_U32 cbBSSDesc;
2936 tANI_U32 cbAllocated;
2937 eHalStatus halStatus;
2938
2939 // figure out how big the BSS description is (the BSSDesc->length does NOT
2940 // include the size of the length field itself).
2941 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
2942
2943 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
2944
2945 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pCsrBssDescription, cbAllocated );
2946 if ( HAL_STATUS_SUCCESS(halStatus) )
2947 {
2948 palZeroMemory( pMac->hHdd, pCsrBssDescription, cbAllocated );
2949 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
2950 palCopyMemory(pMac->hHdd, &pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
2951#if defined(VOSS_ENSBALED)
2952 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
2953#endif
2954 csrScanAddResult(pMac, pCsrBssDescription, pIes);
2955 }
2956
2957 return( pCsrBssDescription );
2958}
2959
2960// Append a Bss Description...
2961tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
2962 tSirBssDescription *pSirBssDescription,
2963 tDot11fBeaconIEs *pIes )
2964{
2965 tCsrScanResult *pCsrBssDescription = NULL;
2966 tAniSSID tmpSsid;
2967 v_TIME_t timer = 0;
2968 int result;
2969
2970 tmpSsid.length = 0;
2971 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer );
2972 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
2973 if (result && (pCsrBssDescription != NULL))
2974 {
2975 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
2976 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
2977 {
2978 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
2979 //if diff of saved SSID time and current time is less than 1 min to avoid
2980 //side effect of saving SSID with old one is that if AP changes its SSID while remain
2981 //hidden, we may never see it and also to address the requirement of
2982 //When we remove hidden ssid from the profile i.e., forget the SSID via
2983 // GUI that SSID shouldn't see in the profile
2984 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
2985 {
2986 pCsrBssDescription->Result.ssId = tmpSsid;
2987 pCsrBssDescription->Result.timer = timer;
2988 }
2989 }
2990 }
2991
2992
2993 return( pCsrBssDescription );
2994}
2995
2996
2997
2998void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
2999{
3000 tCsrChannelPowerInfo *pChannelSet;
3001 tListElem *pEntry;
3002
3003 csrLLLock(pChannelList);
3004 // Remove the channel sets from the learned list and put them in the free list
3005 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3006 {
3007 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3008 if( pChannelSet )
3009 {
3010 palFreeMemory( pMac->hHdd, pChannelSet );
3011 }
3012 }
3013 csrLLUnlock(pChannelList);
3014 return;
3015}
3016
3017
3018/*
3019 * Save the channelList into the ultimate storage as the final stage of channel
3020 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3021 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003022eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003023{
3024 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3025 tSirMacChanInfo *pChannelInfo;
3026 tCsrChannelPowerInfo *pChannelSet;
3027 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3028 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
3029 eHalStatus halStatus;
3030
3031 pChannelInfo = channelTable;
3032 // atleast 3 bytes have to be remaining -- from "countryString"
3033 while ( i-- )
3034 {
3035 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pChannelSet, sizeof(tCsrChannelPowerInfo) );
3036 if ( eHAL_STATUS_SUCCESS == halStatus )
3037 {
3038 palZeroMemory(pMac->hHdd, pChannelSet, sizeof(tCsrChannelPowerInfo));
3039 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3040 pChannelSet->numChannels = pChannelInfo->numChannels;
3041
3042 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003043 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003044 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003045
Jeff Johnson295189b2012-06-20 16:38:30 -07003046 {
3047 pChannelSet->interChannelOffset = 1;
3048 f2GHzInfoFound = TRUE;
3049 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003050 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003051 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003052 {
3053 pChannelSet->interChannelOffset = 4;
3054 f2GHzInfoFound = FALSE;
3055 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003056 else
3057 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003058 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003059 pChannelSet->firstChannel);
3060 palFreeMemory(pMac->hHdd, pChannelSet);
3061 return eHAL_STATUS_FAILURE;
3062 }
3063
Jeff Johnson295189b2012-06-20 16:38:30 -07003064 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3065
3066 if( f2GHzInfoFound )
3067 {
3068 if( !f2GListPurged )
3069 {
3070 // purge previous results if found new
3071 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3072 f2GListPurged = TRUE;
3073 }
3074
3075 if(CSR_IS_OPERATING_BG_BAND(pMac))
3076 {
3077 // add to the list of 2.4 GHz channel sets
3078 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3079 }
3080 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003081 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003082 pChannelSet->firstChannel);
3083 palFreeMemory(pMac->hHdd, pChannelSet);
3084 }
3085 }
3086 else
3087 {
3088 // 5GHz info found
3089 if( !f5GListPurged )
3090 {
3091 // purge previous results if found new
3092 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3093 f5GListPurged = TRUE;
3094 }
3095
3096 if(CSR_IS_OPERATING_A_BAND(pMac))
3097 {
3098 // add to the list of 5GHz channel sets
3099 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3100 }
3101 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003102 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003103 pChannelSet->firstChannel);
3104 palFreeMemory(pMac->hHdd, pChannelSet);
3105 }
3106 }
3107 }
3108
3109 pChannelInfo++; // move to next entry
3110 }
3111
Jeff Johnsone7245742012-09-05 17:12:55 -07003112 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003113}
3114
3115
3116
3117void csrApplyPower2Current( tpAniSirGlobal pMac )
3118{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003119 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003120 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3121 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3122}
3123
3124
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003125void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003126{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303127 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003128 eNVChannelEnabledType channelEnabledType;
3129 tANI_U8 numChannels = 0;
3130 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303131 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003132 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303133
Jeff Johnson295189b2012-06-20 16:38:30 -07003134 if( pChannelList->numChannels )
3135 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303136 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3137 {
3138 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3139 VOS_COUNTRY_CODE_LEN))
3140 {
3141 countryIndex = count;
3142 break;
3143 }
3144 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003145 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3146 /* If user doesn't want to scan the DFS channels lets trim them from
3147 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303148 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003149 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303150 channelIgnore = FALSE;
3151 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3152 {
3153 channelEnabledType =
3154 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3155 }
3156 else
3157 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003158 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303159 }
3160 if( NV_CHANNEL_ENABLE == channelEnabledType )
3161 {
3162 if( countryIndex != -1 )
3163 {
3164 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3165 {
3166 if( pChannelList->channelList[i] ==
3167 countryIgnoreList[countryIndex].channelList[j] )
3168 {
3169 channelIgnore = TRUE;
3170 break;
3171 }
3172 }
3173 }
3174 if( FALSE == channelIgnore )
3175 {
3176 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3177 numChannels++;
3178 }
3179 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003180 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303181 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003182 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3183 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303184 // build a scan list based on the channel list : channel# + active/passive scan
3185 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07003186#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003187 if (updateRiva)
3188 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003189 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003190 // Send HAL UpdateScanParams message
3191 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3192 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003193#endif // FEATURE_WLAN_SCAN_PNO
3194 }
3195 else
3196 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003197 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003198 }
3199 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3200 csrSetCfgCountryCode(pMac, countryCode);
3201}
3202
3203
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003204void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003205{
3206 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3207 {
3208
3209#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3210 {
3211 vos_log_802_11d_pkt_type *p11dLog;
3212 int Index;
3213
3214 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3215 if(p11dLog)
3216 {
3217 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
3218 palCopyMemory(pMac->hHdd, p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
3219 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3220 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3221 {
3222 palCopyMemory(pMac->hHdd, p11dLog->Channels, pMac->scan.base20MHzChannels.channelList,
3223 p11dLog->numChannel);
3224 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3225 {
3226 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3227 }
3228 }
3229 if(!pMac->roam.configParam.Is11dSupportEnabled)
3230 {
3231 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3232 }
3233 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3234 {
3235 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3236 }
3237 else
3238 {
3239 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3240 }
3241 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3242 }
3243 }
3244#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3245
3246 // switch to passive scans only when 11d is enabled
3247 if( csrIs11dSupported( pMac ) )
3248 {
3249 pMac->scan.curScanType = eSIR_PASSIVE_SCAN;
3250 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003251
3252 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3253 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3254
Jeff Johnson295189b2012-06-20 16:38:30 -07003255 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3256 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3257 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003258 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003259 // clear the 11d channel list
3260 palZeroMemory( pMac->hHdd, &pMac->scan.channels11d, sizeof(pMac->scan.channels11d) );
3261 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3262 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3263 }
3264
3265 return;
3266}
3267
3268
3269eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3270{
3271 eHalStatus status = eHAL_STATUS_SUCCESS;
3272 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3273
3274 //Use the Country code and domain from EEPROM
3275 palCopyMemory(pMac->hHdd, pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault, WNI_CFG_COUNTRY_CODE_LEN);
3276 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003277 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3278 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003279 {
3280 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003281 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003282 }
3283 if(pfRestartNeeded)
3284 {
3285 *pfRestartNeeded = fRestart;
3286 }
3287
3288 return (status);
3289}
3290
3291
3292eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3293{
3294 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3295 v_REGDOMAIN_t domainId;
3296
3297 if(pCountry)
3298 {
3299 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId);
3300 if(HAL_STATUS_SUCCESS(status))
3301 {
3302 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3303 if(HAL_STATUS_SUCCESS(status))
3304 {
3305 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3306 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
3307 palCopyMemory(pMac->hHdd, pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
3308 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3309 {
3310 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3311 csrSetCfgCountryCode(pMac, pCountry);
3312 }
3313 }
3314 }
3315 }
3316
3317 return (status);
3318}
3319
3320
3321
3322//caller allocated memory for pNumChn and pChnPowerInfo
3323//As input, *pNumChn has the size of the array of pChnPowerInfo
3324//Upon return, *pNumChn has the number of channels assigned.
3325void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3326 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3327{
3328 tListElem *pEntry;
3329 tANI_U32 chnIdx = 0, idx;
3330 tCsrChannelPowerInfo *pChannelSet;
3331
3332 //Get 2.4Ghz first
3333 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3334 while( pEntry && (chnIdx < *pNumChn) )
3335 {
3336 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3337 if ( 1 != pChannelSet->interChannelOffset )
3338 {
3339 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3340 {
3341 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3342 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3343 }
3344 }
3345 else
3346 {
3347 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3348 {
3349 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3350 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3351 }
3352 }
3353
3354 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3355 }
3356 *pNumChn = chnIdx;
3357
3358 return ;
3359}
3360
3361
3362
3363void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3364{
3365 v_REGDOMAIN_t domainId;
3366 eHalStatus status = eHAL_STATUS_SUCCESS;
3367
3368 do
3369 {
3370 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3371 if( pMac->scan.fAmbiguous11dInfoFound )
3372 {
3373 // ambiguous info found
3374 //Restore te default domain as well
3375 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCodeCurrent, &domainId )))
3376 {
3377 pMac->scan.domainIdCurrent = domainId;
3378 }
3379 else
3380 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003381 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003382 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3383 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003384 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003385 break;
3386 }
3387 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
3388 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCode11d, &domainId )))
3389 {
3390 //Check whether we need to enforce default domain
3391 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3392 (pMac->scan.domainIdCurrent == domainId) )
3393 {
3394
3395#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3396 {
3397 vos_log_802_11d_pkt_type *p11dLog;
3398 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3399 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3400
3401 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3402 if(p11dLog)
3403 {
3404 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
3405 palCopyMemory(pMac->hHdd, p11dLog->countryCode, pMac->scan.countryCode11d, 3);
3406 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3407 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3408 {
3409 palCopyMemory(pMac->hHdd, p11dLog->Channels, pMac->scan.channels11d.channelList,
3410 p11dLog->numChannel);
3411 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3412 &nChnInfo, chnPwrInfo);
3413 nTmp = nChnInfo;
3414 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3415 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3416 &nChnInfo, &chnPwrInfo[nTmp]);
3417 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3418 {
3419 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3420 {
3421 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3422 {
3423 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3424 break;
3425 }
3426 }
3427 }
3428 }
3429 if(!pMac->roam.configParam.Is11dSupportEnabled)
3430 {
3431 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3432 }
3433 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3434 {
3435 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3436 }
3437 else
3438 {
3439 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3440 }
3441 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3442 }
3443 }
3444#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3445 if(pMac->scan.domainIdCurrent != domainId)
3446 {
3447 /* Regulatory Domain Changed, Purge Only scan result
3448 * which does not have channel number belong to 11d
3449 * channel list
3450 * */
3451 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3452 pMac->scan.domainIdCurrent, domainId);
3453 csrScanFilter11dResult(pMac);
3454 }
3455 status = WDA_SetRegDomain(pMac, domainId);
3456 if (status != eHAL_STATUS_SUCCESS)
3457 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003458 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003459 }
3460 pMac->scan.domainIdCurrent = domainId;
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003461 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.channels11d, pMac->scan.countryCode11d, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003462 // switch to active scans using this new channel list
3463 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3464 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3465 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3466 }
3467 }
3468
3469 } while( 0 );
3470
3471 return;
3472}
3473
3474
3475
3476tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3477 tANI_BOOLEAN fForce)
3478{
3479 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3480 tANI_U32 i;
3481
3482 // convert to UPPER here so we are assured the strings are always in upper case.
3483 for( i = 0; i < 3; i++ )
3484 {
3485 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3486 }
3487
3488 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3489 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3490 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3491 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3492 // 11d information element, let's default to US.
3493 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pCountryCode, NULL ) ) )
3494 {
3495 // Check the enforcement first
3496 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3497 {
3498 fUnknownCountryCode = TRUE;
3499 }
3500 else
3501 {
3502 pCountryCode[ 0 ] = 'U';
3503 pCountryCode[ 1 ] = 'S';
3504 }
3505 }
3506
3507 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3508 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3509 // if we see a 0 in this third character, let's change it to a ' '.
3510 if ( 0 == pCountryCode[ 2 ] )
3511 {
3512 pCountryCode[ 2 ] = ' ';
3513 }
3514
3515 if( !fUnknownCountryCode )
3516 {
3517 fCountryStringChanged = (!palEqualMemory( pMac->hHdd,
3518 pMac->scan.countryCode11d, pCountryCode, 2));
3519
3520
3521 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3522 || (fForce))
3523 {
3524 // this is the first .11d information
3525 palCopyMemory( pMac->hHdd, pMac->scan.countryCode11d, pCountryCode, sizeof( pMac->scan.countryCode11d ) );
3526 }
3527 }
3528
3529 return( fCountryStringChanged );
3530}
3531
3532
3533void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3534{
3535 tANI_U32 Index, count=0;
3536 tSirMacChanInfo *pChanInfo;
3537 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003538 tANI_S32 maxChannelIndex;
3539
3540 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3541 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003542
3543 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN)))
3544 {
3545 palZeroMemory(pMac->hHdd, pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3546 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003547 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003548 {
3549 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3550 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3551 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003552 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3553 {
3554 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3555 break;
3556 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003557 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3558 pChanInfo->numChannels = 1;
3559 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3560 pChanInfo++;
3561 count++;
3562 }
3563 }
3564 if(count)
3565 {
3566 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3567 }
3568 palFreeMemory(pMac->hHdd, pChanInfoStart);
3569 }
3570}
3571
3572
3573void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3574{
3575 tANI_BOOLEAN fPopulate5GBand = FALSE;
3576
3577 do
3578 {
3579 // if this is not a dual band product, then we don't need to set the opposite
3580 // band info. We only work in one band so no need to look in the other band.
3581 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3582 // if we found channel info on the 5.0 band and...
3583 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3584 {
3585 // and the 2.4 band is empty, then populate the 2.4 channel info
Jeff Johnson295189b2012-06-20 16:38:30 -07003586 fPopulate5GBand = FALSE;
3587 }
3588 else
3589 {
3590 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3591 // set the 5.0 band info from the 2.4 country code.
Jeff Johnson295189b2012-06-20 16:38:30 -07003592 fPopulate5GBand = TRUE;
3593 }
3594 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3595
3596 } while( 0 );
3597}
3598
3599
3600tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3601{
3602 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3603 tANI_U32 i;
3604
3605 //Make sure it is a channel that is in our supported list.
3606 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3607 {
3608 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3609 {
3610 fRet = eANI_BOOLEAN_TRUE;
3611 break;
3612 }
3613 }
3614
3615 //If it is configured to limit a set of the channels
3616 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3617 {
3618 fRet = eANI_BOOLEAN_FALSE;
3619 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3620 {
3621 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3622 {
3623 fRet = eANI_BOOLEAN_TRUE;
3624 break;
3625 }
3626 }
3627 }
3628
3629 return (fRet);
3630}
3631
3632
3633
3634//bSize specify the buffer size of pChannelList
3635tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3636{
3637 tANI_U8 i, j = 0, chnId;
3638
3639 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3640 for( i = 0; i < bSize; i++ )
3641 {
3642 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3643 if ( csrIsSupportedChannel( pMac, chnId ) )
3644 {
3645 pChannelList[j++] = chnId;
3646 }
3647 }
3648
3649 return (j);
3650}
3651
3652
3653
3654//bSize -- specify the buffer size of pChannelList
3655void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3656 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3657{
3658 tListElem *pEntry;
3659 tCsrChannelPowerInfo *pChannelSet;
3660 tANI_U8 numChannels;
3661 tANI_U8 *pChannels;
3662
3663 if( pChannelSetList && pChannelList && pNumChannels )
3664 {
3665 pChannels = pChannelList;
3666 *pNumChannels = 0;
3667 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3668 while( pEntry )
3669 {
3670 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3671 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3672 pChannels += numChannels;
3673 *pNumChannels += numChannels;
3674 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3675 }
3676 }
3677}
3678
3679
3680/*
3681 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
3682*/
3683tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
3684 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
3685{
3686 tANI_U8 Num2GChannels, bMaxNumChn;
3687 eHalStatus status;
3688 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3689 v_REGDOMAIN_t domainId;
3690 tDot11fBeaconIEs *pIesLocal = pIes;
3691
Jeff Johnson295189b2012-06-20 16:38:30 -07003692 if (VOS_STA_SAP_MODE == vos_get_conparam ())
3693 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003694
3695 do
3696 {
3697 // check if .11d support is enabled
3698 if( !csrIs11dSupported( pMac ) ) break;
3699 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
3700 {
3701 break;
3702 }
3703 // check if country information element is present
3704 if(!pIesLocal->Country.present)
3705 {
3706 //No country info
3707 break;
3708 }
3709
3710 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
3711 {
3712 // country string changed, this should not happen
3713 //Need to check whether we care about this BSS' domain info
3714 //If it doesn't match of the connected profile or roaming profile, let's ignore it
3715 tANI_U32 i;
3716 tCsrRoamSession *pSession;
3717
3718 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3719 {
3720 if( CSR_IS_SESSION_VALID( pMac, i ) )
3721 {
3722 pSession = CSR_GET_SESSION( pMac, i );
3723 if(pSession->pCurRoamProfile)
3724 {
3725 tCsrScanResultFilter filter;
3726
3727 palZeroMemory(pMac->hHdd, &filter, sizeof(tCsrScanResultFilter));
3728 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
3729 if(HAL_STATUS_SUCCESS(status))
3730 {
3731 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
3732 //Free the resource first
3733 csrFreeScanFilter( pMac, &filter );
3734 if(fMatch)
3735 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003736 smsLog(pMac, LOGW, " Matching roam profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003737 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3738 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3739 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3740 break;
3741 }
3742 }
3743 }
3744 else if( csrIsConnStateConnected(pMac, i))
3745 {
3746 //Reach here only when the currention is base on no profile.
3747 //User doesn't give profile and just connect to anything.
3748 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
3749 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003750 smsLog(pMac, LOGW, " Matching connect profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003751 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3752 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3753 //Tush
3754 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3755 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
3756 &pSession->connectedProfile.bssid))
3757 {
3758 //AP changed the 11d info on the fly, modify cfg
3759 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3760 fRet = eANI_BOOLEAN_TRUE;
3761 }
3762 break;
3763 }
3764 }
3765 } //valid session
3766 } //for
3767 if ( i == CSR_ROAM_SESSION_MAX )
3768 {
3769 //Check whether we can use this country's 11d information
3770 if( !pMac->roam.configParam.fEnforceDefaultDomain )
3771 {
3772 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3773 }
3774 else
3775 {
3776 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
3777 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3778 pMac, pIesLocal->Country.country, &domainId )) &&
3779 ( domainId == pMac->scan.domainIdCurrent ) )
3780 {
3781 //Two countries in the same domain
3782 }
3783 }
3784 }
3785 }
3786 else //Tush
3787 {
3788 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
3789 }
3790
3791 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
3792 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
3793 {
3794 tANI_U8 iC;
3795 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
3796
3797 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
3798 {
3799 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
3800 {
3801 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
3802 }
3803 }
3804 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003805 smsLog(pMac, LOG3, FL(" %d sets each one is %d"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07003806 // save the channel/power information from the Channel IE.
3807 //sizeof(tSirMacChanInfo) has to be 3
Jeff Johnsone7245742012-09-05 17:12:55 -07003808 if (eHAL_STATUS_SUCCESS != csrSaveToChannelPower2G_5G( pMac, pIesLocal->Country.num_triplets * sizeof(tSirMacChanInfo),
3809 (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]) ))
3810 {
3811 fRet = eANI_BOOLEAN_FALSE;
3812 return fRet;
3813 }
3814
Jeff Johnson295189b2012-06-20 16:38:30 -07003815 // set the indicator of the channel where the country IE was found...
3816 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07003817 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country, &domainId );
3818 // Checking for Domain Id change
3819 if ( domainId != pMac->scan.domainIdCurrent )
3820 {
3821 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
3822 WDA_SetRegDomain(pMac, domainId);
3823 // Check weather AP provided the 2.4GHZ list or 5GHZ list
3824 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[0].firstChanNum))
3825 {
3826 // AP Provided the 2.4 Channels, Update the 5GHz channels from nv.bin
3827 csrGet5GChannels(pMac );
3828 }
3829 else
3830 {
3831 // AP Provided the 5G Channels, Update the 2.4GHZ channel list from nv.bin
3832 csrGet24GChannels(pMac );
3833 }
3834 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003835 // Populate both band channel lists based on what we found in the country information...
3836 csrSetOppositeBandChannelInfo( pMac );
3837 bMaxNumChn = WNI_CFG_VALID_CHANNEL_LIST_LEN;
3838 // construct 2GHz channel list first
3839 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList24, pMac->scan.channels11d.channelList,
3840 bMaxNumChn, &Num2GChannels );
3841 // construct 5GHz channel list now
3842 if(bMaxNumChn > Num2GChannels)
3843 {
3844 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList5G, pMac->scan.channels11d.channelList + Num2GChannels,
3845 bMaxNumChn - Num2GChannels,
3846 &pMac->scan.channels11d.numChannels );
3847 }
3848
3849 pMac->scan.channels11d.numChannels += Num2GChannels;
3850 fRet = eANI_BOOLEAN_TRUE;
3851
3852 } while( 0 );
3853
3854 if( !pIes && pIesLocal )
3855 {
3856 //locally allocated
3857 palFreeMemory(pMac->hHdd, pIesLocal);
3858 }
3859
3860 return( fRet );
3861}
3862
3863
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003864static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003865{
3866 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
3867 // will set this to the channel where an .11d beacon is seen
3868 pMac->scan.channelOf11dInfo = 0;
3869 // if we get any ambiguous .11d information then this will be set to TRUE
3870 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3871 //Tush
3872 // if we get any ambiguous .11d information, then this will be set to TRUE
3873 // only if the applied 11d info could be found in one of the scan results
3874 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
3875 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003876 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07003877
3878 // Now check if we gathered any domain/country specific information
3879 // If so, we should update channel list and apply Tx power settings
Jeff Johnsone7245742012-09-05 17:12:55 -07003880 if( csrIs11dSupported(pMac) )
3881 {
3882 csrApplyCountryInformation( pMac, FALSE );
3883 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003884}
3885
3886
3887void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
3888{
3889 switch (pCommand->u.scanCmd.reason)
3890 {
3891 case eCsrScanSetBGScanParam:
3892 case eCsrScanAbortBgScan:
3893 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
3894 {
3895 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
3896 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
3897 }
3898 break;
3899 case eCsrScanBGScanAbort:
3900 case eCsrScanBGScanEnable:
3901 case eCsrScanGetScanChnInfo:
3902 break;
3903 case eCsrScanAbortNormalScan:
3904 default:
3905 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
3906 break;
3907 }
3908 if(pCommand->u.scanCmd.pToRoamProfile)
3909 {
3910 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
3911 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.pToRoamProfile);
3912 }
3913 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
3914}
3915
3916
3917tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
3918{
3919 tANI_U32 index11dChannels, index;
3920 tANI_U32 indexCurrentChannels;
3921 tANI_BOOLEAN fChannelAlreadyScanned;
3922 tANI_U32 len = sizeof(pMac->roam.validChannelList);
3923
3924 *pcChannels = 0;
3925 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
3926 {
3927 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
3928 {
3929 //Find the channel index where we found the 11d info
3930 for(index = 0; index < len; index++)
3931 {
3932 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
3933 break;
3934 }
3935 //check whether we found the channel index
3936 if(index < len)
3937 {
3938 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
3939 // NOT in the current channel list. This gives us a list of the new channels that have not been
3940 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
3941 // initially.
3942 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
3943 {
3944 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
3945
3946 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
3947 {
3948 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
3949 {
3950 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
3951 break;
3952 }
3953 }
3954
3955 if ( !fChannelAlreadyScanned )
3956 {
3957 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
3958 ( *pcChannels )++;
3959 }
3960 }
3961 }
3962 }//GetCFG
3963 }
3964 return( *pcChannels );
3965}
3966
3967
3968eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
3969{
3970 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
3971
3972 switch( pCommand->u.scanCmd.reason )
3973 {
3974 case eCsrScan11d1:
3975 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
3976 break;
3977 case eCsrScan11d2:
3978 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
3979 break;
3980 case eCsrScan11dDone:
3981 NextCommand = eCsrNext11dScanComplete;
3982 break;
3983 case eCsrScanLostLink1:
3984 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
3985 break;
3986 case eCsrScanLostLink2:
3987 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
3988 break;
3989 case eCsrScanLostLink3:
3990 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
3991 break;
3992 case eCsrScanForSsid:
3993 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
3994 break;
3995 case eCsrScanForCapsChange:
3996 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
3997 break;
3998 case eCsrScanIdleScan:
3999 NextCommand = eCsrNextIdleScanComplete;
4000 break;
4001 default:
4002 NextCommand = eCsrNextScanNothing;
4003 break;
4004 }
4005 return( NextCommand );
4006}
4007
4008
4009//Return whether the pCommand is finished.
4010tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4011{
4012 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4013
4014 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004015 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004016 pCommand->u.scanCmd.reason = eCsrScan11d2;
4017 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4018 {
4019 fRet = eANI_BOOLEAN_FALSE;
4020 }
4021
4022 return (fRet);
4023}
4024
4025
4026tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4027{
4028 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4029 tANI_U8 *pChannels;
4030 tANI_U8 cChannels;
4031
4032 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN)))
4033 {
4034 palZeroMemory(pMac->hHdd, pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
4035 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4036 {
4037 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4038 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4039 {
4040 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004041 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004042 }
4043 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, cChannels)))
4044 {
4045 palCopyMemory(pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, pChannels, cChannels);
4046 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4047 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4048 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4049 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4050 {
4051 //Reuse the same command buffer
4052 fRet = eANI_BOOLEAN_FALSE;
4053 }
4054 }
4055 }
4056 palFreeMemory(pMac->hHdd, pChannels);
4057 }
4058
4059 return (fRet);
4060}
4061
4062//Return whether the command should be removed
4063tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4064{
4065 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4066 tListElem *pEntry;
4067 tSmeCmd *pCommand;
4068 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4069 tANI_BOOLEAN fSuccess;
4070
4071 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
4072
4073 if ( pEntry )
4074 {
4075 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4076
4077 // If the head of the queue is Active and it is a SCAN command, remove
4078 // and put this on the Free queue.
4079 if ( eSmeCommandScan == pCommand->command )
4080 {
4081 tANI_U32 sessionId = pCommand->sessionId;
4082
4083 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4084 {
4085 fSuccess = eANI_BOOLEAN_FALSE;
4086 }
4087 else
4088 {
4089 //pMac->scan.tempScanResults is not empty meaning the scan found something
4090 //This check only valid here because csrSaveScanresults is not yet called
4091 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4092 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004093 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004094
4095#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4096 {
4097 vos_log_scan_pkt_type *pScanLog = NULL;
4098 tScanResultHandle hScanResult;
4099 tCsrScanResultInfo *pScanResult;
4100 tDot11fBeaconIEs *pIes;
4101 int n = 0, c = 0;
4102
4103 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4104 if(pScanLog)
4105 {
4106 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4107 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4108 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4109 {
4110 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4111 }
4112 else
4113 {
4114 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4115 {
4116 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4117 }
4118 else
4119 {
4120 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4121 }
4122 }
4123 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4124 {
4125 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4126 {
4127 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4128 {
4129 if( n < VOS_LOG_MAX_NUM_BSSID )
4130 {
4131 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4132 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004133 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004134 break;
4135 }
4136 palCopyMemory(pMac->hHdd, pScanLog->bssid[n], pScanResult->BssDescriptor.bssId, 6);
4137 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4138 {
4139 palCopyMemory(pMac->hHdd, pScanLog->ssid[n],
4140 pIes->SSID.ssid, pIes->SSID.num_ssid);
4141 }
4142 palFreeMemory(pMac->hHdd, pIes);
4143 n++;
4144 }
4145 c++;
4146 }
4147 pScanLog->numSsid = (v_U8_t)n;
4148 pScanLog->totalSsid = (v_U8_t)c;
4149 csrScanResultPurge(pMac, hScanResult);
4150 }
4151 }
4152 else
4153 {
4154 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4155 }
4156 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4157 }
4158 }
4159#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4160
4161 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4162 //We reuse the command here instead reissue a new command
4163 switch(NextCommand)
4164 {
4165 case eCsrNext11dScan1Success:
4166 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004167 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004168 // if we found country information, no need to continue scanning further, bail out
4169 fRemoveCommand = eANI_BOOLEAN_TRUE;
4170 NextCommand = eCsrNext11dScanComplete;
4171 break;
4172 case eCsrNext11dScan1Failure:
4173 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4174 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4175 //we clear the "old" 11d info and give it once more chance
4176 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4177 if(fRemoveCommand)
4178 {
4179 NextCommand = eCsrNext11dScanComplete;
4180 }
4181 break;
4182 case eCsrNextLostLinkScan1Success:
4183 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4184 {
4185 csrScanHandleFailedLostlink1(pMac, sessionId);
4186 }
4187 break;
4188 case eCsrNextLostLinkScan2Success:
4189 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4190 {
4191 csrScanHandleFailedLostlink2(pMac, sessionId);
4192 }
4193 break;
4194 case eCsrNextLostLinkScan3Success:
4195 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4196 {
4197 csrScanHandleFailedLostlink3(pMac, sessionId);
4198 }
4199 break;
4200 case eCsrNextLostLinkScan1Failed:
4201 csrScanHandleFailedLostlink1(pMac, sessionId);
4202 break;
4203 case eCsrNextLostLinkScan2Failed:
4204 csrScanHandleFailedLostlink2(pMac, sessionId);
4205 break;
4206 case eCsrNextLostLinkScan3Failed:
4207 csrScanHandleFailedLostlink3(pMac, sessionId);
4208 break;
4209 case eCsrNexteScanForSsidSuccess:
4210 csrScanHandleSearchForSSID(pMac, pCommand);
4211 break;
4212 case eCsrNexteScanForSsidFailure:
4213 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4214 break;
4215 case eCsrNextIdleScanComplete:
4216 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4217 break;
4218 case eCsrNextCapChangeScanComplete:
4219 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4220 break;
4221 default:
4222
4223 break;
4224 }
4225 }
4226 else
4227 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004228 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004229 fRemoveCommand = eANI_BOOLEAN_FALSE;
4230 }
4231 }
4232 else
4233 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004234 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004235 fRemoveCommand = eANI_BOOLEAN_FALSE;
4236 }
4237
4238 return( fRemoveCommand );
4239}
4240
4241
4242
4243static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4244 tSirBssDescription *pSirBssDescr,
4245 tDot11fBeaconIEs *pIes)
4246{
4247 tListElem *pEntry;
4248 tCsrScanResult *pCsrBssDescription;
4249
4250 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4251 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4252 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4253 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4254 while( pEntry )
4255 {
4256 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4257
4258 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4259 // matches
4260
4261 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
4262 pSirBssDescr, pIes ) )
4263 {
4264 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4265 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4266
4267 // Remove the 'old' entry from the list....
4268 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4269 {
4270 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4271 // we need to free the memory associated with this node
4272 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4273 }
4274
4275 // If we found a match, we can stop looking through the list.
4276 break;
4277 }
4278
4279 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4280 }
4281}
4282
4283
4284
4285//Caller allocated memory pfNewBssForConn to return whether new candidate for
4286//current connection is found. Cannot be NULL
4287tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4288 tSirBssDescription *pBSSDescription,
4289 tDot11fBeaconIEs *pIes)
4290{
4291 tCsrScanResult *pCsrBssDescription = NULL;
4292 tANI_U32 cbBSSDesc;
4293 tANI_U32 cbAllocated;
4294 eHalStatus halStatus;
4295
4296 // figure out how big the BSS description is (the BSSDesc->length does NOT
4297 // include the size of the length field itself).
4298 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4299
4300 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4301
4302 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pCsrBssDescription, cbAllocated );
4303 if ( HAL_STATUS_SUCCESS(halStatus) )
4304 {
4305 palZeroMemory(pMac->hHdd, pCsrBssDescription, cbAllocated);
4306 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
4307 palCopyMemory(pMac->hHdd, &pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
4308 //Save SSID separately for later use
4309 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4310 {
4311 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004312 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004313 if (len > SIR_MAC_MAX_SSID_LENGTH)
4314 {
4315 // truncate to fit in our struct
4316 len = SIR_MAC_MAX_SSID_LENGTH;
4317 }
4318 pCsrBssDescription->Result.ssId.length = len;
4319 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
4320 palCopyMemory(pMac->hHdd, pCsrBssDescription->Result.ssId.ssId,
4321 pIes->SSID.ssid, len );
4322 }
4323 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4324 }
4325
4326 return( pCsrBssDescription );
4327}
4328
4329
4330
4331
4332tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
4333 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2 )
4334{
4335 tANI_BOOLEAN fMatch = FALSE;
4336 tSirMacCapabilityInfo *pCap1, *pCap2;
4337 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004338 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004339
4340 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4341 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4342 if(pCap1->ess == pCap2->ess)
4343 {
4344 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004345 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
4346 (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
Jeff Johnson295189b2012-06-20 16:38:30 -07004347 {
4348 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004349 // Check for SSID match, if exists
4350 do
4351 {
4352 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4353 {
4354 break;
4355 }
4356 if( NULL == pIesTemp )
4357 {
4358 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4359 {
4360 break;
4361 }
4362 }
4363 if(pIes1->SSID.present && pIesTemp->SSID.present)
4364 {
4365 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4366 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4367 }
4368 }while(0);
4369
Jeff Johnson295189b2012-06-20 16:38:30 -07004370 }
4371 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4372 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004373
4374 do
4375 {
4376 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4377 {
4378 break;
4379 }
4380 if( NULL == pIesTemp )
4381 {
4382 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4383 {
4384 break;
4385 }
4386 }
4387 //Same channel cannot have same SSID for different IBSS
4388 if(pIes1->SSID.present && pIesTemp->SSID.present)
4389 {
4390 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4391 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4392 }
4393 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004394 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004395 /* In case of P2P devices, ess and ibss will be set to zero */
4396 else if (!pCap1->ess &&
4397 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4398 {
4399 fMatch = TRUE;
4400 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004401 }
4402
4403 if(pIes1)
4404 {
4405 palFreeMemory(pMac->hHdd, pIes1);
4406 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004407
4408 if( (NULL == pIes2) && pIesTemp )
4409 {
4410 //locally allocated
4411 palFreeMemory(pMac->hHdd, pIesTemp);
4412 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004413
4414 return( fMatch );
4415}
4416
4417
4418tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4419{
4420 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4421}
4422
4423
4424//to check whether the BSS matches the dot11Mode
4425static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4426 tDot11fBeaconIEs *pIes)
4427{
4428 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4429 eCsrPhyMode phyMode;
4430
4431 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4432 {
4433 switch(pMac->roam.configParam.phyMode)
4434 {
4435 case eCSR_DOT11_MODE_11b:
4436 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4437 break;
4438 case eCSR_DOT11_MODE_11g:
4439 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4440 break;
4441 case eCSR_DOT11_MODE_11g_ONLY:
4442 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4443 break;
4444 case eCSR_DOT11_MODE_11a:
4445 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4446 break;
4447 case eCSR_DOT11_MODE_11n_ONLY:
4448 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4449 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004450
4451#ifdef WLAN_FEATURE_11AC
4452 case eCSR_DOT11_MODE_11ac_ONLY:
4453 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4454 break;
4455#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004456 case eCSR_DOT11_MODE_11b_ONLY:
4457 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4458 break;
4459 case eCSR_DOT11_MODE_11a_ONLY:
4460 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4461 break;
4462 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004463#ifdef WLAN_FEATURE_11AC
4464 case eCSR_DOT11_MODE_11ac:
4465#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004466 case eCSR_DOT11_MODE_TAURUS:
4467 default:
4468 fAllowed = eANI_BOOLEAN_TRUE;
4469 break;
4470 }
4471 }
4472
4473 return (fAllowed);
4474}
4475
4476
4477
4478//Return pIes to caller for future use when returning TRUE.
4479static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4480 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4481 tDot11fBeaconIEs **ppIes )
4482{
4483 tANI_BOOLEAN fValidChannel = FALSE;
4484 tDot11fBeaconIEs *pIes = NULL;
4485 tANI_U8 index;
4486
4487 for( index = 0; index < numChn; index++ )
4488 {
4489 // This check relies on the fact that a single BSS description is returned in each
4490 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4491 // to this model when we ran with a large number of APs. If this were to change, then
4492 // this check would have to mess with removing the bssDescription from somewhere in an
4493 // arbitrary index in the bssDescription array.
4494 if ( pChannels[ index ] == pBssDesc->channelId )
4495 {
4496 fValidChannel = TRUE;
4497 break;
4498 }
4499 }
4500 *ppIes = NULL;
4501 if(fValidChannel)
4502 {
4503 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4504 {
4505 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4506 if( fValidChannel )
4507 {
4508 *ppIes = pIes;
4509 }
4510 else
4511 {
4512 palFreeMemory( pMac->hHdd, pIes );
4513 }
4514 }
4515 else
4516 {
4517 fValidChannel = FALSE;
4518 }
4519 }
4520
4521 return( fValidChannel );
4522}
4523
4524
4525//Return whether last scan result is received
4526static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4527 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4528{
4529 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4530 tDot11fBeaconIEs *pIes = NULL;
4531 tANI_U32 cbParsed;
4532 tSirBssDescription *pSirBssDescription;
4533 tANI_U32 cbBssDesc;
4534 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4535 + sizeof(tSirBssDescription); //We need at least one CB
4536
4537 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4538 // is returned when the scan could not find anything. so if we get scan failure return that
4539 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4540 // BssDescriptions....
4541 do
4542 {
4543 if ( ( cbScanResult <= pScanRsp->length ) &&
4544 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4545 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4546 {
4547 tANI_U8 *pChannelList = NULL;
4548 tANI_U8 cChannels = 0;
4549
4550 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004551#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4552 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4553 {
4554 pChannelList = NULL;
4555 cChannels = 0;
4556 }
4557 else
4558#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004559 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4560 {
4561 //eCsrScanSetBGScanParam uses different structure
4562 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4563
4564 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4565 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4566 }
4567 else
4568 {
4569 //the rest use generic scan request
4570 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4571 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4572 }
4573
4574 // if the scan result is not on one of the channels in the Valid channel list, then it
4575 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4576 // let's drop the scan result.
4577 //
4578 // The other situation is where the scan request is for a scan on a particular channel set
4579 // and the scan result is from a
4580
4581 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4582 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4583 // as the valid channels.
4584 if ( 0 == cChannels )
4585 {
4586 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4587
4588 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4589 {
4590 pChannelList = pMac->roam.validChannelList;
4591 cChannels = (tANI_U8)len;
4592 }
4593 else
4594 {
4595 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004596 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004597 break;
4598 }
4599 }
4600
4601 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4602 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4603 pSirBssDescription = pScanRsp->bssDescription;
4604 while( cbParsed < pScanRsp->length )
4605 {
4606 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4607 {
4608 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4609 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4610 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4611 {
4612 if( csrIs11dSupported( pMac) )
4613 {
4614 //Check whether the BSS is acceptable base on 11d info and our configs.
4615 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4616 {
4617 //Double check whether the channel is acceptable by us.
4618 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4619 {
4620 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4621 }
4622 }
4623 }
4624 else
4625 {
4626 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4627 }
4628 }
4629 //Free the resource
4630 palFreeMemory( pMac->hHdd, pIes );
4631 }
4632 // skip over the BSS description to the next one...
4633 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
4634
4635 cbParsed += cbBssDesc;
4636 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
4637
4638 } //while
4639 }
4640 else
4641 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004642 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08004643 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004644 //HO bg scan/probe failed no need to try autonomously
4645 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4646 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004647#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4648 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
4649#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004650 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4651 {
4652 fRemoveCommand = eANI_BOOLEAN_TRUE;
4653 }
4654 }
4655 }while(0);
4656 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4657 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004658 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 -07004659 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
4660 fRet = eANI_BOOLEAN_TRUE;
4661 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4662 if(pfRemoveCommand)
4663 {
4664 *pfRemoveCommand = fRemoveCommand;
4665 }
4666
4667#ifdef WLAN_AP_STA_CONCURRENCY
4668 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
4669 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004670 /* Pending scan commands in the list because the previous scan command
4671 * was split into a scan command on one channel + a scan command for all
4672 * remaining channels.
4673 *
4674 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08004675 * NOTE for LFR:
4676 * Do not split scans if no concurrent infra connections are
4677 * active and if the scan is a BG scan triggered by LFR (OR)
4678 * any scan if LFR is in the middle of a BG scan. Splitting
4679 * the scan is delaying the time it takes for LFR to find
4680 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004681 */
Srikant Kuppa866893f2012-12-27 17:28:14 -08004682 if ( (csrIsStaSessionConnected(pMac) &&
4683#ifdef FEATURE_WLAN_LFR
4684 (csrIsConcurrentInfraConnected(pMac) ||
4685 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
4686 (pMac->roam.neighborRoamInfo.neighborRoamState !=
4687 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
4688#endif
4689 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004690 (csrIsP2pSessionConnected(pMac)) )
4691 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004692 /* if active connected sessions present then continue to split scan
4693 * with specified interval between consecutive scans */
4694 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Srikant Kuppa866893f2012-12-27 17:28:14 -08004695 palTimerStart(pMac->hHdd, pMac->scan.hTimerStaApConcTimer,
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004696 pCommand->u.scanCmd.u.scanRequest.restTime * PAL_TIMER_TO_MS_UNIT, eANI_BOOLEAN_FALSE);
4697 } else {
4698 /* if no connected sessions present then initiate next scan command immediately */
4699 /* minimum timer granularity is 10ms */
4700 palTimerStart(pMac->hHdd, pMac->scan.hTimerStaApConcTimer, 10 * 1000, eANI_BOOLEAN_FALSE);
4701 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004702 }
4703#endif
4704 return (fRet);
4705}
4706
4707
4708tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
4709{
4710 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
4711 tANI_BOOLEAN f = palEqualMemory( pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.bssid,
4712 bssid, sizeof(tCsrBssid) );
4713
4714 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
4715 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
4716 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
4717}
4718
4719
4720eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
4721{
4722 eHalStatus status = eHAL_STATUS_SUCCESS;
4723 tListElem *pEntry;
4724 tSmeCmd *pCommand;
4725 eCsrScanStatus scanStatus;
4726 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
4727 tSmeGetScanChnRsp *pScanChnInfo;
4728 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4729 eCsrScanReason reason = eCsrScanOther;
4730
4731 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
4732
4733 if ( pEntry )
4734 {
4735 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4736 if ( eSmeCommandScan == pCommand->command )
4737 {
4738 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
4739 reason = pCommand->u.scanCmd.reason;
4740 switch(pCommand->u.scanCmd.reason)
4741 {
4742 case eCsrScanAbortBgScan:
4743 case eCsrScanAbortNormalScan:
4744 case eCsrScanBGScanAbort:
4745 case eCsrScanBGScanEnable:
4746 break;
4747 case eCsrScanGetScanChnInfo:
4748 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004749 /*
4750 * status code not available in tSmeGetScanChnRsp, so
4751 * by default considereing it to be success
4752 */
4753 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004754 csrScanAgeResults(pMac, pScanChnInfo);
4755 break;
4756 case eCsrScanForCapsChange:
4757 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
4758 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004759 case eCsrScanP2PFindPeer:
4760 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
4761 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
4762 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004763 case eCsrScanSetBGScanParam:
4764 default:
4765 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
4766 {
4767 //Not to get channel info if the scan is not a wildcard scan because
4768 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004769 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
4770#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4771 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
4772#endif
4773 )
Jeff Johnson295189b2012-06-20 16:38:30 -07004774 {
4775 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07004776 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
4777 {
4778 csrScanGetScanChnInfo(pMac, NULL, NULL);
4779 }
4780 else
4781 {
4782 csrScanGetScanChnInfo(pMac, pCommand->u.scanCmd.callback, pCommand->u.scanCmd.pContext);
4783 pCommand->u.scanCmd.callback = NULL;
4784 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004785 }
4786 }
4787 break;
4788 }//switch
4789 if(fRemoveCommand)
4790 {
4791
4792 csrReleaseScanCommand(pMac, pCommand, scanStatus);
4793
Srikant Kuppa866893f2012-12-27 17:28:14 -08004794 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004795 smeProcessPendingQueue( pMac );
4796 }
4797 else
4798 {
4799 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
4800 status = eHAL_STATUS_FAILURE;
4801 }
4802 }
4803 else
4804 {
4805 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
4806 status = eHAL_STATUS_FAILURE;
4807 }
4808
4809 return (status);
4810}
4811
4812
4813
4814
4815tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
4816{
4817 tListElem *pEntry;
4818 tCsrScanResult *pResult;
4819 tCsrScanResultInfo *pRet = NULL;
4820 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4821
4822 if(pResultList)
4823 {
4824 csrLLLock(&pResultList->List);
4825 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4826 if(pEntry)
4827 {
4828 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4829 pRet = &pResult->Result;
4830 }
4831 pResultList->pCurEntry = pEntry;
4832 csrLLUnlock(&pResultList->List);
4833 }
4834
4835 return pRet;
4836}
4837
4838
4839tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
4840{
4841 tListElem *pEntry = NULL;
4842 tCsrScanResult *pResult = NULL;
4843 tCsrScanResultInfo *pRet = NULL;
4844 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4845
4846 if(pResultList)
4847 {
4848 csrLLLock(&pResultList->List);
4849 if(NULL == pResultList->pCurEntry)
4850 {
4851 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4852 }
4853 else
4854 {
4855 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
4856 }
4857 if(pEntry)
4858 {
4859 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4860 pRet = &pResult->Result;
4861 }
4862 pResultList->pCurEntry = pEntry;
4863 csrLLUnlock(&pResultList->List);
4864 }
4865
4866 return pRet;
4867}
4868
4869
4870//This function moves the first BSS that matches the bssid to the head of the result
4871eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
4872{
4873 eHalStatus status = eHAL_STATUS_FAILURE;
4874 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4875 tCsrScanResult *pResult = NULL;
4876 tListElem *pEntry = NULL;
4877
4878 if(pResultList && bssid)
4879 {
4880 csrLLLock(&pResultList->List);
4881 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4882 while(pEntry)
4883 {
4884 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4885 if(palEqualMemory(pMac->hHdd, bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
4886 {
4887 status = eHAL_STATUS_SUCCESS;
4888 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
4889 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
4890 break;
4891 }
4892 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
4893 }
4894 csrLLUnlock(&pResultList->List);
4895 }
4896
4897 return (status);
4898}
4899
4900
4901//Remove the BSS if possible.
4902//Return -- TRUE == the BSS is remove. False == Fail to remove it
4903//This function is called when list lock is held. Be caution what functions it can call.
4904tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
4905{
4906 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4907 tANI_U32 i;
4908 tCsrRoamSession *pSession;
4909
4910 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4911 {
4912 if( CSR_IS_SESSION_VALID( pMac, i ) )
4913 {
4914 pSession = CSR_GET_SESSION( pMac, i );
4915 //Not to remove the BSS we are connected to.
4916 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
4917 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
4918 pSession->pConnectBssDesc, NULL))
4919 )
4920 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004921 smsLog(pMac, LOGW, "Aging out BSS %02X-%02X-%02X-%02X-%02X-%02X Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004922 pResult->Result.BssDescriptor.bssId[0],
4923 pResult->Result.BssDescriptor.bssId[1],
4924 pResult->Result.BssDescriptor.bssId[2],
4925 pResult->Result.BssDescriptor.bssId[3],
4926 pResult->Result.BssDescriptor.bssId[4],
4927 pResult->Result.BssDescriptor.bssId[5],
4928 pResult->Result.BssDescriptor.channelId);
4929 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
4930 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
4931 {
4932 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07004933 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004934 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004935 break;
4936 }
4937 } //valid session
4938 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07004939 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07004940 {
4941 //reset the counter so this won't hapeen too soon
4942 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
4943 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
4944 }
4945
4946 return (fRet);
4947}
4948
4949
4950eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
4951{
4952 eHalStatus status = eHAL_STATUS_SUCCESS;
4953 tListElem *pEntry, *tmpEntry;
4954 tCsrScanResult *pResult;
4955 tLimScanChn *pChnInfo;
4956 tANI_U8 i;
4957
4958 csrLLLock(&pMac->scan.scanResultList);
4959 for(i = 0; i < pScanChnInfo->numChn; i++)
4960 {
4961 pChnInfo = &pScanChnInfo->scanChn[i];
4962 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
4963 while( pEntry )
4964 {
4965 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
4966 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4967 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
4968 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004969 if(pResult->AgingCount <= 0)
4970 {
4971 smsLog(pMac, LOGW, " age out due to ref count");
4972 csrScanAgeOutBss(pMac, pResult);
4973 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07004974 else
4975 {
4976 pResult->AgingCount--;
4977 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004978 }
4979 pEntry = tmpEntry;
4980 }
4981 }
4982 csrLLUnlock(&pMac->scan.scanResultList);
4983
4984 return (status);
4985}
4986
4987
4988eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
4989 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
4990{
4991 eHalStatus status = eHAL_STATUS_SUCCESS;
4992 tSirSmeScanReq *pMsg;
4993 tANI_U16 msgLen;
4994 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
4995 tSirScanType scanType = pScanReq->scanType;
4996 tANI_U32 minChnTime; //in units of milliseconds
4997 tANI_U32 maxChnTime; //in units of milliseconds
4998 tANI_U32 i;
4999 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5000 tANI_U8 *pSelfMac = NULL;
5001
5002 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5003 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5004 ( pScanReq->uIEFieldLen ) ;
5005
5006 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
5007 if(HAL_STATUS_SUCCESS(status))
5008 {
5009 do
5010 {
5011 palZeroMemory(pMac->hHdd, pMsg, msgLen);
5012 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5013 pMsg->length = pal_cpu_to_be16(msgLen);
5014 //ToDO: Fill in session info when we need to do scan base on session.
5015 pMsg->sessionId = 0;
5016 pMsg->transactionId = 0;
5017 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5018 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5019
5020 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5021 {
5022 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5023 }
5024 else
5025 {
5026 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5027 // do so, get the WNI_CFG_STA_ID
5028 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5029 {
5030 if( CSR_IS_SESSION_VALID( pMac, i ) )
5031 {
5032 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5033 break;
5034 }
5035 }
5036 if( CSR_ROAM_SESSION_MAX == i )
5037 {
5038 tANI_U32 len = WNI_CFG_BSSID_LEN;
5039 pSelfMac = selfMacAddr;
5040 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5041 if( !HAL_STATUS_SUCCESS( status ) ||
5042 ( len < WNI_CFG_BSSID_LEN ) )
5043 {
5044 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5045 //Force failed status
5046 status = eHAL_STATUS_FAILURE;
5047 break;
5048 }
5049 }
5050 }
5051 palCopyMemory( pMac->hHdd, (tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr) );
5052
5053 //sirCopyMacAddr
5054 palCopyMemory( pMac->hHdd, (tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr) );
5055 if( palEqualMemory( pMac->hHdd, pScanReq->bssid, bssid, sizeof(tCsrBssid) ) )
5056 {
5057 palFillMemory( pMac->hHdd, pMsg->bssId, sizeof(tSirMacAddr), 0xff );
5058 }
5059 else
5060 {
5061 palCopyMemory(pMac->hHdd, pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
5062 }
5063 minChnTime = pScanReq->minChnTime;
5064 maxChnTime = pScanReq->maxChnTime;
5065
5066 //Verify the scan type first, if the scan is active scan, we need to make sure we
5067 //are allowed to do so.
5068 /* if 11d is enabled & we don't see any beacon around, scan type falls
5069 back to passive. But in BT AMP STA mode we need to send out a
5070 directed probe*/
5071 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5072 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5073 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5074 {
5075 scanType = pMac->scan.curScanType;
5076 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5077 {
5078 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5079 {
5080 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5081 }
5082 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5083 {
5084 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5085 }
5086 }
5087 }
5088 pMsg->scanType = pal_cpu_to_be32(scanType);
5089
5090 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ? pScanReq->SSIDs.numOfSSIDs :
5091 SIR_SCAN_MAX_NUM_SSID;
5092 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5093 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005094 for (i = 0; i < pMsg->numSsid; i++)
5095 {
5096 palCopyMemory(pMac->hHdd, &pMsg->ssId[i], &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
5097 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005098 }
5099 else
5100 {
5101 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005102 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5103 {
5104 pMsg->ssId[i].length = 0;
5105 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005106 }
5107
Jeff Johnson295189b2012-06-20 16:38:30 -07005108 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5109 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005110 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5111 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005112 //hidden SSID option
5113 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5114 //rest time
5115 //pMsg->restTime = pScanReq->restTime;
5116 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5117 // All the scan results caching will be done by Roaming
5118 // We do not want LIM to do any caching of scan results,
5119 // so delete the LIM cache on all scan requests
5120 pMsg->returnFreshResults = pScanReqParam->freshScan;
5121 //Always ask for unique result
5122 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5123 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5124 if(pScanReq->ChannelInfo.numOfChannels)
5125 {
5126 //Assuming the channelNumber is tANI_U8 (1 byte)
5127 status = palCopyMemory(pMac->hHdd, pMsg->channelList.channelNumber, pScanReq->ChannelInfo.ChannelList,
5128 pScanReq->ChannelInfo.numOfChannels);
5129 }
5130
5131 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5132 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5133 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5134 if(pScanReq->uIEFieldLen != 0)
5135 {
5136 palCopyMemory(pMac->hHdd, (tANI_U8 *)pMsg+pMsg->uIEFieldOffset,
5137 pScanReq->pIEField, pScanReq->uIEFieldLen );
5138 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005139 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005140
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005141 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5142 {
5143 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5144 }
5145
Jeff Johnson295189b2012-06-20 16:38:30 -07005146 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005147 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005148 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5149 pScanReq->requestType, pMsg->channelList.numChannels);
5150
5151 for(i = 0; i < pMsg->channelList.numChannels; i++)
5152 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005153 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005154 }
5155
Jeff Johnson295189b2012-06-20 16:38:30 -07005156 if(HAL_STATUS_SUCCESS(status))
5157 {
5158 status = palSendMBMessage(pMac->hHdd, pMsg);
5159 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005160 else
5161 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005162 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005163 palFreeMemory(pMac->hHdd, pMsg);
5164 }
5165 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005166 else
5167 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005168 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005169 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005170
5171 return( status );
5172}
5173
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005174eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005175{
5176 eHalStatus status = eHAL_STATUS_SUCCESS;
5177 tSirSmeScanReq *pMsg;
5178 tANI_U16 msgLen;
5179
5180 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
5181 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
5182 if(HAL_STATUS_SUCCESS(status))
5183 {
5184 palZeroMemory(pMac->hHdd, pMsg, msgLen);
5185 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5186 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005187 pMsg->sessionId = sessionId;
5188 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005189 pMsg->returnFreshResults = pScanReqParam->freshScan;
5190 //Always ask for unique result
5191 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5192 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5193 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005194 if (!HAL_STATUS_SUCCESS(status))
5195 {
5196 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5197 }
5198
Jeff Johnson295189b2012-06-20 16:38:30 -07005199 }
5200
5201 return( status );
5202}
5203
5204
5205
5206eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5207{
5208 eHalStatus status = eHAL_STATUS_FAILURE;
5209 tScanReqParam scanReq;
5210
5211 do
5212 {
5213 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5214 scanReq.fUniqueResult = TRUE;
5215 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5216 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5217 {
5218 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5219 }
5220 else
5221 {
5222 // Basically do scan on all channels even for 11D 1st scan case.
5223 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5224 }
5225 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5226 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5227 {
5228 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5229 }
5230
5231#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5232 {
5233 vos_log_scan_pkt_type *pScanLog = NULL;
5234
5235 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5236 if(pScanLog)
5237 {
5238 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5239 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5240 {
5241 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5242 }
5243 else
5244 {
5245 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5246 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5247 {
5248 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5249 }
5250 else
5251 {
5252 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5253 }
5254 }
5255 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5256 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5257 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5258 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5259 {
5260 palCopyMemory(pMac->hHdd, pScanLog->channels,
5261 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5262 pScanLog->numChannel);
5263 }
5264 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5265 }
5266 }
5267#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5268
5269
5270 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5271 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5272 }while(0);
5273
5274 return( status );
5275}
5276
5277
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005278eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005279{
5280 eHalStatus status = eHAL_STATUS_FAILURE;
5281 tScanReqParam scanReq;
5282
5283 do
5284 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005285#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5286 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5287 {
5288 //to get the LFR candidates from PE cache
5289 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5290 scanReq.fUniqueResult = TRUE;
5291 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5292 }
5293 else
5294#endif
5295 {
5296 //not a fresh scan
5297 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5298 scanReq.fUniqueResult = TRUE;
5299 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5300 }
5301 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005302 }while(0);
5303
5304 return (status);
5305}
5306
5307
5308
5309eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5310{
5311 eHalStatus status = eHAL_STATUS_SUCCESS;
5312 tCsrChannelInfo newChannelInfo = {0, NULL};
5313 int i, j;
5314 tANI_U8 *pChannel = NULL;
5315 tANI_U32 len = 0;
5316
5317 // Transition to Scanning state...
5318 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5319 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005320 pCommand->u.scanCmd.lastRoamState[i] = csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005321 smsLog( pMac, LOG3, "starting SCAN command from %d state.... reason is %d", pCommand->u.scanCmd.lastRoamState[i], pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005322 }
5323
5324 switch(pCommand->u.scanCmd.reason)
5325 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005326#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5327 case eCsrScanGetLfrResult:
5328#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005329 case eCsrScanGetResult:
5330 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005331 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005332 break;
5333 case eCsrScanSetBGScanParam:
5334 status = csrProcessSetBGScanParam(pMac, pCommand);
5335 break;
5336 case eCsrScanBGScanAbort:
5337 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5338 break;
5339 case eCsrScanBGScanEnable:
5340 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5341 break;
5342 case eCsrScanGetScanChnInfo:
5343 status = csrScanGetScanChannelInfo(pMac);
5344 break;
5345 case eCsrScanUserRequest:
5346 if(pMac->roam.configParam.fScanTwice)
5347 {
5348 //We scan 2.4 channel twice
5349 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5350 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5351 {
5352 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5353 //allocate twice the channel
5354 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5355 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5356 }
5357 else
5358 {
5359 //get the valid channel list to scan all.
5360 len = sizeof(pMac->roam.validChannelList);
5361
5362 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5363 {
5364 //allocate twice the channel
5365 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5366 pChannel = pMac->roam.validChannelList;
5367 }
5368 }
5369 if(NULL == newChannelInfo.ChannelList)
5370 {
5371 newChannelInfo.numOfChannels = 0;
5372 }
5373 else
5374 {
5375 j = 0;
5376 for(i = 0; i < len; i++)
5377 {
5378 newChannelInfo.ChannelList[j++] = pChannel[i];
5379 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5380 {
5381 newChannelInfo.ChannelList[j++] = pChannel[i];
5382 }
5383 }
5384 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5385 {
5386 //pChannel points to the channellist from the command, free it.
5387 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005388 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005389 }
5390 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5391 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5392 }
5393 } //if(pMac->roam.configParam.fScanTwice)
5394
5395 status = csrScanChannels(pMac, pCommand);
5396
5397 break;
5398 default:
5399 status = csrScanChannels(pMac, pCommand);
5400 break;
5401 }
5402
5403 if(!HAL_STATUS_SUCCESS(status))
5404 {
5405 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5406 }
5407
5408 return (status);
5409}
5410
5411
5412eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5413{
5414 eHalStatus status = eHAL_STATUS_SUCCESS;
5415 tSmeCmd *pCommand = NULL;
5416
5417 if(pScanReq)
5418 {
5419 do
5420 {
5421 pCommand = csrGetCommandBuffer(pMac);
5422 if(!pCommand)
5423 {
5424 status = eHAL_STATUS_RESOURCES;
5425 break;
5426 }
5427 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5428 pCommand->command = eSmeCommandScan;
5429 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5430 pCommand->u.scanCmd.callback = NULL;
5431 pCommand->u.scanCmd.pContext = NULL;
5432 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
5433 //we have to do the follow
5434 if(pScanReq->ChannelInfo.numOfChannels == 0)
5435 {
5436 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5437 }
5438 else
5439 {
5440 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5441 pScanReq->ChannelInfo.numOfChannels);
5442 if(HAL_STATUS_SUCCESS(status))
5443 {
5444 palCopyMemory(pMac->hHdd, pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5445 pScanReq->ChannelInfo.ChannelList, pScanReq->ChannelInfo.numOfChannels);
5446 }
5447 else
5448 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005449 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005450 csrReleaseCommandScan(pMac, pCommand);
5451 break;
5452 }
5453 }
5454
5455 //scan req for SSID
5456 if(pScanReq->SSID.length)
5457 {
5458 palCopyMemory(pMac->hHdd,
5459 pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5460 pScanReq->SSID.ssId,
5461 pScanReq->SSID.length);
5462 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5463
5464 }
5465 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5466 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5467 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5468
5469
5470 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5471 if( !HAL_STATUS_SUCCESS( status ) )
5472 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005473 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005474 csrReleaseCommandScan( pMac, pCommand );
5475 break;
5476 }
5477 }while(0);
5478 }
5479
5480 return (status);
5481}
5482
5483eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5484{
5485 eHalStatus status = eHAL_STATUS_SUCCESS;
5486 tSmeCmd *pCommand = NULL;
5487
5488 do
5489 {
5490 pCommand = csrGetCommandBuffer(pMac);
5491 if(!pCommand)
5492 {
5493 status = eHAL_STATUS_RESOURCES;
5494 break;
5495 }
5496 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5497 pCommand->command = eSmeCommandScan;
5498 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5499 pCommand->u.scanCmd.callback = NULL;
5500 pCommand->u.scanCmd.pContext = NULL;
5501 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5502 if( !HAL_STATUS_SUCCESS( status ) )
5503 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005504 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005505 csrReleaseCommandScan( pMac, pCommand );
5506 break;
5507 }
5508 }while(0);
5509
5510 return (status);
5511}
5512
5513
5514//This will enable the background scan with the non-zero interval
5515eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5516{
5517 eHalStatus status = eHAL_STATUS_SUCCESS;
5518 tSmeCmd *pCommand = NULL;
5519
5520 if(pMac->roam.configParam.bgScanInterval)
5521 {
5522 do
5523 {
5524 pCommand = csrGetCommandBuffer(pMac);
5525 if(!pCommand)
5526 {
5527 status = eHAL_STATUS_RESOURCES;
5528 break;
5529 }
5530 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5531 pCommand->command = eSmeCommandScan;
5532 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5533 pCommand->u.scanCmd.callback = NULL;
5534 pCommand->u.scanCmd.pContext = NULL;
5535 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5536 if( !HAL_STATUS_SUCCESS( status ) )
5537 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005538 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005539 csrReleaseCommandScan( pMac, pCommand );
5540 break;
5541 }
5542 }while(0);
5543 //BG scan results are reported automatically by PE to SME once the scan is done.
5544 //No need to fetch the results explicitly.
5545 //csrScanStartGetResultTimer(pMac);
5546 csrScanStartResultAgingTimer(pMac);
5547 }
5548 else
5549 {
5550 //We don't have BG scan so stop the aging timer
5551 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005552 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005553 status = eHAL_STATUS_INVALID_PARAMETER;
5554 }
5555
5556 return (status);
5557}
5558
5559
5560eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5561{
5562 eHalStatus status = eHAL_STATUS_SUCCESS;
5563 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5564 tANI_U32 index = 0;
5565 tANI_U32 new_index = 0;
5566
5567 do
5568 {
5569 status = csrScanFreeRequest(pMac, pDstReq);
5570 if(HAL_STATUS_SUCCESS(status))
5571 {
5572 status = palCopyMemory(pMac->hHdd, pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08005573 /* Re-initialize the pointers to NULL since we did a copy */
5574 pDstReq->pIEField = NULL;
5575 pDstReq->ChannelInfo.ChannelList = NULL;
5576 pDstReq->SSIDs.SSIDList = NULL;
5577
Jeff Johnson295189b2012-06-20 16:38:30 -07005578 if(pSrcReq->uIEFieldLen == 0)
5579 {
5580 pDstReq->pIEField = NULL;
5581 }
5582 else
5583 {
5584 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->pIEField, pSrcReq->uIEFieldLen);
5585 if(HAL_STATUS_SUCCESS(status))
5586 {
5587 palCopyMemory(pMac->hHdd, pDstReq->pIEField, pSrcReq->pIEField, pSrcReq->uIEFieldLen);
5588 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
5589 }
5590 else
5591 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005592 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnson295189b2012-06-20 16:38:30 -07005593 break;
5594 }
5595 }//Allocate memory for IE field
5596 {
5597 if(pSrcReq->ChannelInfo.numOfChannels == 0)
5598 {
5599 pDstReq->ChannelInfo.ChannelList = NULL;
5600 pDstReq->ChannelInfo.numOfChannels = 0;
5601 }
5602 else
5603 {
5604 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->ChannelInfo.ChannelList,
5605 pSrcReq->ChannelInfo.numOfChannels * sizeof(*pDstReq->ChannelInfo.ChannelList));
5606 if(!HAL_STATUS_SUCCESS(status))
5607 {
5608 pDstReq->ChannelInfo.numOfChannels = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005609 smsLog(pMac, LOGE, "No memory for scanning Channel List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005610 break;
5611 }
5612
5613 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
5614 {
5615 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5616 {
5617 pDstReq->ChannelInfo.ChannelList[new_index] =
5618 pSrcReq->ChannelInfo.ChannelList[index];
5619 new_index++;
5620 }
5621 pDstReq->ChannelInfo.numOfChannels = new_index;
5622 }
5623 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
5624 {
5625 new_index = 0;
5626 pMac->roam.numValidChannels = len;
5627 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5628 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005629 /* Allow scan on valid channels only.
5630 * If it is p2p scan and valid channel list doesnt contain
5631 * social channels, enforce scan on social channels because
5632 * that is the only way to find p2p peers.
5633 * This can happen only if band is set to 5Ghz mode.
5634 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005635 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
5636 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005637 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07005638 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08005639 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005640 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08005641#ifdef FEATURE_WLAN_LFR
5642 /*
5643 * If LFR is requesting a contiguous scan
5644 * (i.e. numOfChannels > 1), then ignore
5645 * DFS channels.
5646 * TODO: vos_nv_getChannelEnabledState is returning
5647 * 120, 124 and 128 as non-DFS channels. Hence, the
5648 * use of direct check for channels below.
5649 */
5650 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5651 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08005652 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08005653#endif
5654 )
5655 {
5656#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005657 smsLog(pMac, LOG2,
Srikant Kuppa866893f2012-12-27 17:28:14 -08005658 "%s: reqType=%d, numOfChannels=%d,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005659 " ignoring DFS channel %d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005660 __func__, pSrcReq->requestType,
5661 pSrcReq->ChannelInfo.numOfChannels,
5662 pSrcReq->ChannelInfo.ChannelList[index]);
5663#endif
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005664 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005665 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005666
Jeff Johnson295189b2012-06-20 16:38:30 -07005667 pDstReq->ChannelInfo.ChannelList[new_index] =
5668 pSrcReq->ChannelInfo.ChannelList[index];
5669 new_index++;
5670 }
5671 }
5672 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005673#ifdef FEATURE_WLAN_LFR
5674 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5675 (0 == pDstReq->ChannelInfo.numOfChannels))
5676 {
5677 /*
5678 * No valid channels found in the request.
5679 * Only perform scan on the channels passed
5680 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
5681 * Passing 0 to LIM will trigger a scan on
5682 * all valid channels which is not desirable.
5683 */
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005684 smsLog(pMac, LOGE, "%s: no valid channels found (request=%d)",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005685 __func__, pSrcReq->requestType);
5686 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5687 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005688 smsLog(pMac, LOGE, "pSrcReq index=%d channel=%d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005689 index, pSrcReq->ChannelInfo.ChannelList[index]);
5690 }
5691 status = eHAL_STATUS_FAILURE;
5692 break;
5693 }
5694#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005695 }
5696 else
5697 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005698 smsLog(pMac, LOGE, "Couldn't get the valid Channel List, keeping requester's list");
Jeff Johnson295189b2012-06-20 16:38:30 -07005699 palCopyMemory(pMac->hHdd, pDstReq->ChannelInfo.ChannelList, pSrcReq->ChannelInfo.ChannelList,
5700 pSrcReq->ChannelInfo.numOfChannels * sizeof(*pDstReq->ChannelInfo.ChannelList));
5701 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
5702 }
5703 }//Allocate memory for Channel List
5704 }
5705 if(pSrcReq->SSIDs.numOfSSIDs == 0)
5706 {
5707 pDstReq->SSIDs.numOfSSIDs = 0;
5708 pDstReq->SSIDs.SSIDList = NULL;
5709 }
5710 else
5711 {
5712 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->SSIDs.SSIDList,
5713 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5714 if(HAL_STATUS_SUCCESS(status))
5715 {
5716 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
5717 palCopyMemory(pMac->hHdd, pDstReq->SSIDs.SSIDList, pSrcReq->SSIDs.SSIDList,
5718 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5719 }
5720 else
5721 {
5722 pDstReq->SSIDs.numOfSSIDs = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005723 smsLog(pMac, LOGE, "No memory for scanning SSID List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005724 break;
5725 }
5726 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07005727 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07005728 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005729
5730 }
5731 }while(0);
5732
5733 if(!HAL_STATUS_SUCCESS(status))
5734 {
5735 csrScanFreeRequest(pMac, pDstReq);
5736 }
5737
5738 return (status);
5739}
5740
5741
5742eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
5743{
5744 eHalStatus status = eHAL_STATUS_SUCCESS;
5745
5746 if(pReq->ChannelInfo.ChannelList)
5747 {
5748 status = palFreeMemory(pMac->hHdd, pReq->ChannelInfo.ChannelList);
5749 pReq->ChannelInfo.ChannelList = NULL;
5750 }
5751 pReq->ChannelInfo.numOfChannels = 0;
5752 if(pReq->pIEField)
5753 {
5754 status = palFreeMemory(pMac->hHdd, pReq->pIEField);
5755 pReq->pIEField = NULL;
5756 }
5757 pReq->uIEFieldLen = 0;
5758 if(pReq->SSIDs.SSIDList)
5759 {
5760 palFreeMemory(pMac->hHdd, pReq->SSIDs.SSIDList);
5761 pReq->SSIDs.SSIDList = NULL;
5762 }
5763 pReq->SSIDs.numOfSSIDs = 0;
5764
5765 return (status);
5766}
5767
5768
5769void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
5770{
5771 if(pCommand->u.scanCmd.callback)
5772 {
5773// sme_ReleaseGlobalLock( &pMac->sme );
5774 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
5775// sme_AcquireGlobalLock( &pMac->sme );
5776 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005777 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005778 }
5779}
5780
5781
5782void csrScanStopTimers(tpAniSirGlobal pMac)
5783{
5784 csrScanStopResultAgingTimer(pMac);
5785 csrScanStopIdleScanTimer(pMac);
5786 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005787 if(0 != pMac->scan.scanResultCfgAgingTime )
5788 {
5789 csrScanStopResultCfgAgingTimer(pMac);
5790 }
5791
Jeff Johnson295189b2012-06-20 16:38:30 -07005792}
5793
5794
5795eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
5796{
5797 eHalStatus status;
5798
5799 if(pMac->scan.fScanEnable)
5800 {
5801 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL, eANI_BOOLEAN_TRUE);
5802 }
5803 else
5804 {
5805 status = eHAL_STATUS_FAILURE;
5806 }
5807
5808 return (status);
5809}
5810
5811
5812eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
5813{
5814 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerGetResult));
5815}
5816
5817
5818void csrScanGetResultTimerHandler(void *pv)
5819{
5820 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5821
5822 csrScanRequestResult(pMac);
5823}
5824
5825#ifdef WLAN_AP_STA_CONCURRENCY
5826static void csrStaApConcTimerHandler(void *pv)
5827{
5828 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5829 tListElem *pEntry;
5830 tSmeCmd *pScanCmd;
5831
5832 csrLLLock(&pMac->scan.scanCmdPendingList);
5833
5834 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
5835 {
5836 tCsrScanRequest scanReq;
5837 tSmeCmd *pSendScanCmd = NULL;
5838 tANI_U8 numChn = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08005839 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07005840 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
5841 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
5842 eHalStatus status;
5843
Jeff Johnson295189b2012-06-20 16:38:30 -07005844 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5845 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005846
5847 /* if any session is connected and the number of channels to scan is
5848 * greater than 1 then split the scan into multiple scan operations
5849 * on each individual channel else continue to perform scan on all
5850 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005851
5852 /* split scan if number of channels to scan is greater than 1 and
5853 * any one of the following:
5854 * - STA session is connected and the scan is not a P2P search
5855 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08005856 * Do not split scans if no concurrent infra connections are
5857 * active and if the scan is a BG scan triggered by LFR (OR)
5858 * any scan if LFR is in the middle of a BG scan. Splitting
5859 * the scan is delaying the time it takes for LFR to find
5860 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005861 */
Vinay Malekal05fdc812012-12-17 13:04:30 -08005862 if ( (numChn > pMac->roam.configParam.nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005863 ((csrIsStaSessionConnected(pMac) &&
5864#ifdef FEATURE_WLAN_LFR
5865 (csrIsConcurrentInfraConnected(pMac) ||
5866 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
5867 (pMac->roam.neighborRoamInfo.neighborRoamState !=
5868 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5869#endif
5870 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005871 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005872 {
5873 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
5874
5875 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
5876 if (!pSendScanCmd)
5877 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005878 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07005879 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5880 return;
5881 }
5882 pSendScanCmd->command = pScanCmd->command;
5883 pSendScanCmd->sessionId = pScanCmd->sessionId;
5884 pSendScanCmd->u.scanCmd.callback = NULL;
5885 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
5886 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
5887 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
5888
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07005889 /* First copy all the parameters to local variable of scan request */
5890 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
5891
5892 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08005893 if(scanReq.ChannelInfo.ChannelList != NULL)
5894 {
5895 palFreeMemory(pMac->hHdd,scanReq.ChannelInfo.ChannelList);
5896 scanReq.ChannelInfo.ChannelList = NULL;
5897 }
5898
Vinay Malekal05fdc812012-12-17 13:04:30 -08005899 pChnInfo->numOfChannels = pMac->roam.configParam.nNumChanCombinedConc;
5900 palCopyMemory(pMac->hHdd, &channelToScan[0], &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
5901 pChnInfo->numOfChannels * sizeof(tANI_U8)); //just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07005902 pChnInfo->ChannelList = &channelToScan[0];
5903
Vinay Malekal05fdc812012-12-17 13:04:30 -08005904 for (i = 0, j = pMac->roam.configParam.nNumChanCombinedConc; i < (numChn-pMac->roam.configParam.nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07005905 {
5906 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08005907 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07005908 }
5909
Vinay Malekal05fdc812012-12-17 13:04:30 -08005910 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - pMac->roam.configParam.nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07005911
5912 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
5913 //Modify callers parameters in case of concurrency
5914 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07005915 //Use concurrency values for min/maxChnTime.
5916 //We know csrIsAnySessionConnected(pMac) returns TRUE here
5917 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005918
5919 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
5920 if(!HAL_STATUS_SUCCESS(status))
5921 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005922 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005923 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5924 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08005925 }
5926 /* Clean the local scan variable */
5927 scanReq.ChannelInfo.ChannelList = NULL;
5928 scanReq.ChannelInfo.numOfChannels = 0;
5929 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005930 }
5931 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005932 {
5933 /* no active connected session present or numChn == 1
5934 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07005935 pSendScanCmd = pScanCmd;
5936 //remove this command from pending list
5937 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
5938 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005939 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005940 }
5941
5942 }
5943 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
5944
5945 }
5946
Jeff Johnson295189b2012-06-20 16:38:30 -07005947 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5948
5949}
5950#endif
5951
5952eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
5953{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005954 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005955
5956 if(pMac->scan.fScanEnable)
5957 {
5958 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL, eANI_BOOLEAN_TRUE);
5959 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005960 return (status);
5961}
5962
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005963eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
5964{
5965 eHalStatus status = eHAL_STATUS_FAILURE;
5966
5967 if(pMac->scan.fScanEnable)
5968 {
5969 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerResultCfgAging,
5970 CSR_SCAN_RESULT_CFG_AGING_INTERVAL, eANI_BOOLEAN_TRUE);
5971 }
5972 return (status);
5973}
Jeff Johnson295189b2012-06-20 16:38:30 -07005974
5975eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
5976{
5977 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerResultAging));
5978}
5979
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005980eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
5981{
5982 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerResultCfgAging));
5983}
Jeff Johnson295189b2012-06-20 16:38:30 -07005984
5985//This function returns the maximum time a BSS is allowed in the scan result.
5986//The time varies base on connection and power saving factors.
5987//Not connected, No PS
5988//Not connected, with PS
5989//Connected w/o traffic, No PS
5990//Connected w/o traffic, with PS
5991//Connected w/ traffic, no PS -- Not supported
5992//Connected w/ traffic, with PS -- Not supported
5993//the return unit is in seconds.
5994tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
5995{
5996 tANI_U32 nRet;
5997
5998 if(pMac->scan.nAgingCountDown)
5999 {
6000 //Calculate what should be the timeout value for this
6001 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6002 pMac->scan.nAgingCountDown--;
6003 }
6004 else
6005 {
6006 if( csrIsAllSessionDisconnected( pMac ) )
6007 {
6008 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6009 {
6010 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6011 }
6012 else
6013 {
6014 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6015 }
6016 }
6017 else
6018 {
6019 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6020 {
6021 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6022 }
6023 else
6024 {
6025 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6026 }
6027 }
6028 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6029 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6030 if(pMac->scan.nLastAgeTimeOut > nRet)
6031 {
6032 if(nRet)
6033 {
6034 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6035 }
6036 pMac->scan.nLastAgeTimeOut = nRet;
6037 nRet *= pMac->scan.nAgingCountDown;
6038 }
6039 else
6040 {
6041 pMac->scan.nLastAgeTimeOut = nRet;
6042 }
6043 }
6044
6045 return (nRet);
6046}
6047
6048
6049void csrScanResultAgingTimerHandler(void *pv)
6050{
6051 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6052 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6053
6054 //no scan, no aging
6055 if(pMac->scan.fScanEnable &&
6056 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6057 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6058 )
6059 {
6060 tListElem *pEntry, *tmpEntry;
6061 tCsrScanResult *pResult;
6062 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6063 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6064
6065 csrLLLock(&pMac->scan.scanResultList);
6066 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6067 while( pEntry )
6068 {
6069 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6070 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6071 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6072 {
6073 smsLog(pMac, LOGW, " age out due to time out");
6074 csrScanAgeOutBss(pMac, pResult);
6075 }
6076 pEntry = tmpEntry;
6077 }
6078 csrLLUnlock(&pMac->scan.scanResultList);
6079 }
6080}
6081
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006082static void csrScanResultCfgAgingTimerHandler(void *pv)
6083{
6084 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6085 tListElem *pEntry, *tmpEntry;
6086 tCsrScanResult *pResult;
6087 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6088 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6089
6090 csrLLLock(&pMac->scan.scanResultList);
6091 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6092 while( pEntry )
6093 {
6094 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6095 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6096 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6097 {
6098 smsLog(pMac, LOGW, " age out due to time out");
6099 csrScanAgeOutBss(pMac, pResult);
6100 }
6101 pEntry = tmpEntry;
6102 }
6103 csrLLUnlock(&pMac->scan.scanResultList);
6104}
Jeff Johnson295189b2012-06-20 16:38:30 -07006105
6106eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6107{
6108 eHalStatus status;
6109
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006110 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006111 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6112 {
6113 pMac->scan.nIdleScanTimeGap += interval;
6114 palTimerStop(pMac->hHdd, pMac->scan.hTimerIdleScan);
6115 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerIdleScan, interval, eANI_BOOLEAN_FALSE);
6116 if( !HAL_STATUS_SUCCESS(status) )
6117 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006118 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006119 //This should not happen but set the flag to restart when ready
6120 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6121 }
6122 }
6123 else
6124 {
6125 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6126 {
6127 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6128 }
6129 status = eHAL_STATUS_FAILURE;
6130 }
6131
6132 return (status);
6133}
6134
6135
6136eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6137{
6138 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerIdleScan));
6139}
6140
6141
6142//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6143void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6144{
6145 csrScanCancelIdleScan(pMac);
6146}
6147
6148
6149//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6150//because IMPS maybe disabled.
6151void csrScanResumeIMPS( tpAniSirGlobal pMac )
6152{
6153 csrScanStartIdleScan( pMac );
6154}
6155
6156
6157void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6158{
6159 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6160
6161 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6162 {
6163 if(pMac->roam.configParam.IsIdleScanEnabled)
6164 {
6165 if(HAL_STATUS_SUCCESS(status))
6166 {
6167 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6168 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006169 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006170 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6171 }
6172 else
6173 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006174 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006175 //even though we are in timer handle, calling stop timer will make sure the timer
6176 //doesn't get to restart.
6177 csrScanStopIdleScanTimer(pMac);
6178 }
6179 }
6180 else
6181 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006182 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006183 }
6184 }
6185 else
6186 {//we might need another flag to check if CSR needs to request imps at all
6187
6188 tANI_U32 nTime = 0;
6189
6190 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6191 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6192 {
6193 csrScanStartIdleScanTimer(pMac, nTime);
6194 }
6195 }
6196 }
6197}
6198
6199
6200//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6201//idle scan timer interval
6202//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6203eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6204{
6205 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6206
6207 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006208 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6209 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006210 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006211 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006212 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006213
6214 if(pTimeInterval)
6215 {
6216 *pTimeInterval = 0;
6217 }
6218
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006219 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006220 if( smeCommandPending( pMac ) )
6221 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006222 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006223 //Not to enter IMPS because more work to do
6224 if(pTimeInterval)
6225 {
6226 *pTimeInterval = 0;
6227 }
6228 //restart when ready
6229 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6230
6231 return (status);
6232 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006233 if (IsPmcImpsReqFailed (pMac))
6234 {
6235 if(pTimeInterval)
6236 {
6237 *pTimeInterval = 1000000; //usec
6238 }
6239 //restart when ready
6240 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006241
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006242 return status;
6243 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006244 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6245 /*&& pMac->roam.configParam.impsSleepTime*/)
6246 {
6247 //Stop get result timer because idle scan gets scan result out of PE
6248 csrScanStopGetResultTimer(pMac);
6249 if(pTimeInterval)
6250 {
6251 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6252 }
6253 //pmcRequestImps take a period in millisecond unit.
6254 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6255 if(!HAL_STATUS_SUCCESS(status))
6256 {
6257 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6258 {
6259 //Do restart the timer if CSR thinks it cannot do IMPS
6260 if( !csrCheckPSReady( pMac ) )
6261 {
6262 if(pTimeInterval)
6263 {
6264 *pTimeInterval = 0;
6265 }
6266 //Set the restart flag to true because that idle scan
6267 //can be restarted even though the timer will not be running
6268 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6269 }
6270 else
6271 {
6272 //For not now, we do a quicker retry
6273 if(pTimeInterval)
6274 {
6275 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6276 }
6277 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006278 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006279 }
6280 else
6281 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006282 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006283 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6284 //the callback will be called in the future. Should not happen though.
6285 status = eHAL_STATUS_SUCCESS;
6286 pMac->scan.nIdleScanTimeGap = 0;
6287 }
6288 }
6289 else
6290 {
6291 //requested so let's reset the value
6292 pMac->scan.nIdleScanTimeGap = 0;
6293 }
6294 }
6295
6296 return (status);
6297}
6298
6299
6300eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6301{
6302 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6303 tANI_U32 nTime = 0;
6304
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006305 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006306 if(pMac->roam.configParam.IsIdleScanEnabled)
6307 {
6308 //stop bg scan first
6309 csrScanBGScanAbort(pMac);
6310 //Stop get result timer because idle scan gets scan result out of PE
6311 csrScanStopGetResultTimer(pMac);
6312 //Enable aging timer since idle scan is going on
6313 csrScanStartResultAgingTimer(pMac);
6314 }
6315 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6316 status = csrScanTriggerIdleScan(pMac, &nTime);
6317 if(!HAL_STATUS_SUCCESS(status))
6318 {
6319 csrScanStartIdleScanTimer(pMac, nTime);
6320 }
6321
6322 return (status);
6323}
6324
6325
6326void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6327{
6328 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6329 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006330 if (vos_concurrent_sessions_running()) {
6331 return;
6332 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006333 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006334 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6335 //Set the restart flag in case later on it is uncancelled
6336 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6337 csrScanStopIdleScanTimer(pMac);
6338 csrScanRemoveNotRoamingScanCommand(pMac);
6339 }
6340}
6341
6342
6343void csrScanIdleScanTimerHandler(void *pv)
6344{
6345 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6346 eHalStatus status;
6347 tANI_U32 nTime = 0;
6348
6349 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006350 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006351 status = csrScanTriggerIdleScan(pMac, &nTime);
6352 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6353 {
6354 //Check whether it is time to actually do an idle scan
6355 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6356 {
6357 pMac->scan.nIdleScanTimeGap = 0;
6358 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6359 }
6360 else
6361 {
6362 csrScanStartIdleScanTimer(pMac, nTime);
6363 }
6364 }
6365}
6366
6367
6368
6369
6370tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6371{
6372 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6373 tListElem *pEntry, *pEntryTmp;
6374 tSmeCmd *pCommand;
6375 tDblLinkList localList;
6376
6377 vos_mem_zero(&localList, sizeof(tDblLinkList));
6378 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6379 {
6380 smsLog(pMac, LOGE, FL(" failed to open list"));
6381 return fRet;
6382 }
6383
6384 csrLLLock(&pMac->sme.smeCmdPendingList);
6385 pEntry = csrLLPeekHead(&pMac->sme.smeCmdPendingList, LL_ACCESS_NOLOCK);
6386 while(pEntry)
6387 {
6388 pEntryTmp = csrLLNext(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK);
6389 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6390 if( eSmeCommandScan == pCommand->command )
6391 {
6392 switch( pCommand->u.scanCmd.reason )
6393 {
6394 case eCsrScanIdleScan:
6395 if( csrLLRemoveEntry(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK) )
6396 {
6397 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6398 }
6399 fRet = eANI_BOOLEAN_TRUE;
6400 break;
6401
6402 default:
6403 break;
6404 } //switch
6405 }
6406 pEntry = pEntryTmp;
6407 }
6408
6409 csrLLUnlock(&pMac->sme.smeCmdPendingList);
6410
6411 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6412 {
6413 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6414 csrReleaseCommandScan( pMac, pCommand );
6415 }
6416
6417 csrLLClose(&localList);
6418
6419 return (fRet);
6420}
6421
6422
6423tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6424{
6425 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6426 tListElem *pEntry, *pEntryTmp;
6427 tSmeCmd *pCommand;
6428 tDblLinkList localList;
6429
6430 vos_mem_zero(&localList, sizeof(tDblLinkList));
6431 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6432 {
6433 smsLog(pMac, LOGE, FL(" failed to open list"));
6434 return fRet;
6435 }
6436
6437 csrLLLock(&pMac->sme.smeCmdPendingList);
6438 pEntry = csrLLPeekHead(&pMac->sme.smeCmdPendingList, LL_ACCESS_NOLOCK);
6439 while(pEntry)
6440 {
6441 pEntryTmp = csrLLNext(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK);
6442 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6443 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6444 {
6445 switch(pCommand->u.scanCmd.reason)
6446 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006447#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6448 case eCsrScanGetLfrResult:
6449#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006450 case eCsrScanGetResult:
6451 case eCsrScanSetBGScanParam:
6452 case eCsrScanBGScanAbort:
6453 case eCsrScanBGScanEnable:
6454 case eCsrScanGetScanChnInfo:
6455 break;
6456 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006457 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006458 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006459 //The rest are fresh scan requests
6460 if( csrLLRemoveEntry(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK) )
6461 {
6462 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6463 }
6464 fRet = eANI_BOOLEAN_TRUE;
6465 break;
6466 }
6467 }
6468 pEntry = pEntryTmp;
6469 }
6470
6471 csrLLUnlock(&pMac->sme.smeCmdPendingList);
6472
6473 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6474 {
6475 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6476 if (pCommand->u.scanCmd.callback)
6477 {
6478 /* User scan request is pending,
6479 * send response with status eCSR_SCAN_ABORT*/
6480 pCommand->u.scanCmd.callback(pMac,
6481 pCommand->u.scanCmd.pContext,
6482 pCommand->u.scanCmd.scanID,
6483 eCSR_SCAN_ABORT);
6484 }
6485 csrReleaseCommandScan( pMac, pCommand );
6486 }
6487 csrLLClose(&localList);
6488
6489 return (fRet);
6490}
6491
6492
6493void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6494{
6495 eCsrScanReason reason = pCommand->u.scanCmd.reason;
6496 tANI_U32 i;
6497 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6498 {
Jeff Johnson43971f52012-07-17 12:26:56 -07006499 csrRoamStateChange( pMac, pCommand->u.scanCmd.lastRoamState[i], i);
Jeff Johnson295189b2012-06-20 16:38:30 -07006500 }
6501
6502 csrScanCallCallback(pMac, pCommand, scanStatus);
6503
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006504 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006505 if( csrLLRemoveEntry( &pMac->sme.smeCmdActiveList, &pCommand->Link, LL_ACCESS_LOCK ) )
6506 {
6507 csrReleaseCommandScan( pMac, pCommand );
6508 }
6509 else
6510 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006511 smsLog(pMac, LOGE, " ********csrReleaseScanCommand cannot release command reason %d", pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006512 }
6513}
6514
6515
6516eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6517 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
6518{
6519 eHalStatus status = eHAL_STATUS_SUCCESS;
6520 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6521
Jeff Johnson32d95a32012-09-10 13:15:23 -07006522 if(!pSession)
6523 {
6524 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6525 return eHAL_STATUS_FAILURE;
6526 }
6527
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006528 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006529 csrResetPMKIDCandidateList(pMac, sessionId);
6530 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6531 {
6532 tCsrScanResultFilter *pScanFilter;
6533 tCsrScanResultInfo *pScanResult;
6534 tScanResultHandle hBSSList;
6535 tANI_U32 nItems = *pNumItems;
6536
6537 *pNumItems = 0;
6538 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
6539 if(HAL_STATUS_SUCCESS(status))
6540 {
6541 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
6542 //Here is the profile we need to connect to
6543 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6544 if(HAL_STATUS_SUCCESS(status))
6545 {
6546 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6547 if(HAL_STATUS_SUCCESS(status))
6548 {
6549 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
6550 {
6551 //NumPmkidCandidate adds up here
6552 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
6553 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6554 }
6555 if(pSession->NumPmkidCandidate)
6556 {
6557 *pNumItems = pSession->NumPmkidCandidate;
6558 palCopyMemory(pMac->hHdd, pPmkidList, pSession->PmkidCandidateInfo,
6559 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
6560 }
6561 csrScanResultPurge(pMac, hBSSList);
6562 }//Have scan result
6563 csrFreeScanFilter(pMac, pScanFilter);
6564 }
6565 palFreeMemory(pMac->hHdd, pScanFilter);
6566 }
6567 }
6568
6569 return (status);
6570}
6571
6572
6573
6574#ifdef FEATURE_WLAN_WAPI
6575eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6576 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
6577{
6578 eHalStatus status = eHAL_STATUS_SUCCESS;
6579 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6580
Jeff Johnson32d95a32012-09-10 13:15:23 -07006581 if(!pSession)
6582 {
6583 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6584 return eHAL_STATUS_FAILURE;
6585 }
6586
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006587 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006588 csrResetBKIDCandidateList(pMac, sessionId);
6589 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6590 {
6591 tCsrScanResultFilter *pScanFilter;
6592 tCsrScanResultInfo *pScanResult;
6593 tScanResultHandle hBSSList;
6594 tANI_U32 nItems = *pNumItems;
6595 *pNumItems = 0;
6596 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
6597 if(HAL_STATUS_SUCCESS(status))
6598 {
6599 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
6600 //Here is the profile we need to connect to
6601 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6602 if(HAL_STATUS_SUCCESS(status))
6603 {
6604 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6605 if(HAL_STATUS_SUCCESS(status))
6606 {
6607 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
6608 {
6609 //pMac->scan.NumBkidCandidate adds up here
6610 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
6611 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6612
6613 }
6614 if(pSession->NumBkidCandidate)
6615 {
6616 *pNumItems = pSession->NumBkidCandidate;
6617 palCopyMemory(pMac->hHdd, pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
6618 }
6619 csrScanResultPurge(pMac, hBSSList);
6620 }//Have scan result
6621 }
6622 palFreeMemory(pMac->hHdd, pScanFilter);
6623 }
6624 }
6625
6626 return (status);
6627}
6628#endif /* FEATURE_WLAN_WAPI */
6629
6630
6631
6632//This function is usually used for BSSs that suppresses SSID so the profile
6633//shall have one and only one SSID
6634eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId)
6635{
6636 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6637 tSmeCmd *pScanCmd = NULL;
6638 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
6639 tANI_U8 index = 0;
6640 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
6641
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006642 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006643 //For WDS, we use the index 0. There must be at least one in there
6644 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
6645 {
6646 numSsid = 1;
6647 }
6648 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
6649 {
6650 do
6651 {
6652 pScanCmd = csrGetCommandBuffer(pMac);
6653 if(!pScanCmd)
6654 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006655 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006656 break;
6657 }
6658 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
6659 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.pToRoamProfile, sizeof(tCsrRoamProfile));
6660 if(!HAL_STATUS_SUCCESS(status))
6661 break;
6662 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
6663 if(!HAL_STATUS_SUCCESS(status))
6664 break;
6665 pScanCmd->u.scanCmd.roamId = roamId;
6666 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07006667 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07006668 pScanCmd->u.scanCmd.callback = NULL;
6669 pScanCmd->u.scanCmd.pContext = NULL;
6670 pScanCmd->u.scanCmd.reason = eCsrScanForSsid;
6671 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6672 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest));
6673 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07006674 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07006675 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
6676 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
6677 {
6678 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
6679 }
6680 if(pProfile->pAddIEScan)
6681 {
6682 status = palAllocateMemory(pMac->hHdd,
6683 (void **)&pScanCmd->u.scanCmd.u.scanRequest.pIEField,
6684 pProfile->nAddIEScanLength);
6685 palZeroMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.pIEField, pProfile->nAddIEScanLength);
6686 if(HAL_STATUS_SUCCESS(status))
6687 {
6688 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.pIEField, pProfile->pAddIEScan, pProfile->nAddIEScanLength);
6689 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
6690 }
6691 else
6692 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006693 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07006694 }
6695 } //Allocate memory for IE field
6696 else
6697 {
6698 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
6699 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07006700 /* For one channel be good enpugh time to receive beacon atleast */
6701 if( 1 == pProfile->ChannelInfo.numOfChannels )
6702 {
6703 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
6704 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
6705 }
6706 else
6707 {
6708 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
6709 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
6710 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08006711 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
6712 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07006713 if(pProfile->BSSIDs.numOfBSSIDs == 1)
6714 {
6715 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.bssid, pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
6716 }
6717 else
6718 {
6719 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
6720 }
6721 if(pProfile->ChannelInfo.numOfChannels)
6722 {
6723 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList) * pProfile->ChannelInfo.numOfChannels);
6724 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
6725 if(HAL_STATUS_SUCCESS(status))
6726 {
6727 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
6728 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
6729 {
6730 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
6731 {
6732 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
6733 = pProfile->ChannelInfo.ChannelList[index];
6734 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
6735 }
6736 else
6737 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006738 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07006739 }
6740
6741 }
6742 }
6743 else
6744 {
6745 break;
6746 }
6747
6748 }
6749 else
6750 {
6751 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
6752 }
6753 if(pProfile->SSIDs.numOfSSIDs)
6754 {
6755 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
6756 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
6757 if(!HAL_STATUS_SUCCESS(status))
6758 {
6759 break;
6760 }
6761 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
6762 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList, pProfile->SSIDs.SSIDList,
6763 sizeof(tCsrSSIDInfo));
6764 }
6765 //Start process the command
6766 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
6767 if( !HAL_STATUS_SUCCESS( status ) )
6768 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006769 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006770 break;
6771 }
6772 }while(0);
6773 if(!HAL_STATUS_SUCCESS(status))
6774 {
6775 if(pScanCmd)
6776 {
6777 csrReleaseCommandScan(pMac, pScanCmd);
6778 //TODO:free the memory that is allocated in this function
6779 }
6780 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
6781 }
6782 }//valid
6783 else
6784 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006785 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07006786 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
6787 }
6788
6789 return (status);
6790}
6791
6792
6793//Issue a scan base on the new capability infomation
6794//This should only happen when the associated AP changes its capability.
6795//After this scan is done, CSR reroams base on the new scan results
6796eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
6797{
6798 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6799 tSmeCmd *pScanCmd = NULL;
6800
6801 if(pNewCaps)
6802 {
6803 do
6804 {
6805 pScanCmd = csrGetCommandBuffer(pMac);
6806 if(!pScanCmd)
6807 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006808 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006809 status = eHAL_STATUS_RESOURCES;
6810 break;
6811 }
6812 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
6813 status = eHAL_STATUS_SUCCESS;
6814 pScanCmd->u.scanCmd.roamId = 0;
6815 pScanCmd->command = eSmeCommandScan;
6816 pScanCmd->u.scanCmd.callback = NULL;
6817 pScanCmd->u.scanCmd.pContext = NULL;
6818 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
6819 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6820 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
6821 if( !HAL_STATUS_SUCCESS( status ) )
6822 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006823 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006824 break;
6825 }
6826 }while(0);
6827 if(!HAL_STATUS_SUCCESS(status))
6828 {
6829 if(pScanCmd)
6830 {
6831 csrReleaseCommandScan(pMac, pScanCmd);
6832 }
6833 }
6834 }
6835
6836 return (status);
6837}
6838
6839
6840
6841void csrInitBGScanChannelList(tpAniSirGlobal pMac)
6842{
6843 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
6844
6845 palZeroMemory(pMac->hHdd, pMac->scan.bgScanChannelList, len);
6846 pMac->scan.numBGScanChannel = 0;
6847
6848 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6849 {
6850 pMac->roam.numValidChannels = len;
6851 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
6852 palCopyMemory(pMac->hHdd, pMac->scan.bgScanChannelList, pMac->roam.validChannelList, pMac->scan.numBGScanChannel);
6853 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
6854 }
6855}
6856
6857
6858//This function return TRUE if background scan channel list is adjusted.
6859//this function will only shrink the background scan channel list
6860tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
6861 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
6862{
6863 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6864 tANI_U8 i, j, count = *pNumAdjustChannels;
6865
6866 i = 0;
6867 while(i < count)
6868 {
6869 for(j = 0; j < NumChannels; j++)
6870 {
6871 if(pChannelList[j] == pAdjustChannels[i])
6872 break;
6873 }
6874 if(j == NumChannels)
6875 {
6876 //This channel is not in the list, remove it
6877 fRet = eANI_BOOLEAN_TRUE;
6878 count--;
6879 if(count - i)
6880 {
6881 palCopyMemory(pMac->hHdd, &pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
6882 }
6883 else
6884 {
6885 //already remove the last one. Done.
6886 break;
6887 }
6888 }
6889 else
6890 {
6891 i++;
6892 }
6893 }//while(i<count)
6894 *pNumAdjustChannels = count;
6895
6896 return (fRet);
6897}
6898
6899
6900//Get the list of the base channels to scan for passively 11d info
6901eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
6902{
6903 eHalStatus status = eHAL_STATUS_SUCCESS;
6904 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6905
6906 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
6907 if( HAL_STATUS_SUCCESS(status) )
6908 {
6909 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
6910 }
6911 else
6912 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006913 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006914 pMac->scan.baseChannels.numChannels = 0;
6915 }
6916
6917 return ( status );
6918}
6919
6920//This function use the input pChannelList to validate the current saved channel list
6921eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
6922{
6923 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
6924
6925 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
6926}
6927
6928
6929void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
6930{
6931 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
6932
6933
6934 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
6935
6936 return;
6937}
6938
6939
6940
6941/*
6942 * The Tx power limits are saved in the cfg for future usage.
6943 */
6944void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
6945{
6946 tListElem *pEntry;
6947 tANI_U32 cbLen = 0, dataLen;
6948 tCsrChannelPowerInfo *pChannelSet;
6949 tANI_U32 idx;
6950 tSirMacChanInfo *pChannelPowerSet;
6951 tANI_U8 *pBuf = NULL;
6952
6953 //allocate maximum space for all channels
6954 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
6955 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pBuf, dataLen)))
6956 {
6957 palZeroMemory(pMac->hHdd, pBuf, dataLen);
6958 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
6959
6960 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
6961 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
6962 while( pEntry )
6963 {
6964 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
6965 if ( 1 != pChannelSet->interChannelOffset )
6966 {
6967 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
6968 // to the right format... (inter channel offset of 1 is the only option for the triplets
6969 // that 11d advertises.
6970 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
6971 {
6972 // expanding this entry will overflow our allocation
6973 smsLog(pMac, LOGE,
6974 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006975 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006976 pChannelSet->firstChannel,
6977 pChannelSet->numChannels,
6978 pChannelSet->interChannelOffset);
6979 break;
6980 }
6981
6982 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
6983 {
6984 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006985 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07006986 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07006987 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006988 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07006989 cbLen += sizeof( tSirMacChanInfo );
6990 pChannelPowerSet++;
6991 }
6992 }
6993 else
6994 {
6995 if (cbLen >= dataLen)
6996 {
6997 // this entry will overflow our allocation
6998 smsLog(pMac, LOGE,
6999 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007000 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007001 pChannelSet->firstChannel,
7002 pChannelSet->numChannels,
7003 pChannelSet->interChannelOffset);
7004 break;
7005 }
7006 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007007 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007008 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007009 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007010 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007011
7012
7013 cbLen += sizeof( tSirMacChanInfo );
7014 pChannelPowerSet++;
7015 }
7016
7017 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7018 }
7019
7020 if(cbLen)
7021 {
7022 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7023 }
7024 palFreeMemory( pMac->hHdd, pBuf );
7025 }//Allocate memory
7026}
7027
7028
7029void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7030{
7031 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7032 ///v_REGDOMAIN_t DomainId;
7033
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007034 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Jeff Johnson295189b2012-06-20 16:38:30 -07007035 palCopyMemory( pMac->hHdd, cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN );
7036
7037 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7038 // the bogus country codes, program the MAC with the right country code.
7039 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7040 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7041 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7042 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7043 {
7044 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7045 cc[ 1 ] = 'R';
7046 }
7047 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7048
7049 //Need to let HALPHY know about the current domain so it can apply some
7050 //domain-specific settings (TX filter...)
7051 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7052 {
7053 halPhySetRegDomain(pMac, DomainId);
7054 }*/
7055}
7056
7057
7058
7059eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7060{
7061 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7062 tANI_U32 len;
7063
7064 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7065 {
7066 len = *pbLen;
7067 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7068 if(HAL_STATUS_SUCCESS(status))
7069 {
7070 *pbLen = (tANI_U8)len;
7071 }
7072 }
7073
7074 return (status);
7075}
7076
7077
7078void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7079{
7080 tANI_U8 i, j;
7081 tANI_BOOLEAN found=FALSE;
7082 tANI_U8 *pControlList = NULL;
7083 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7084
7085 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN)))
7086 {
7087 palZeroMemory(pMac->hHdd, (void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN);
7088 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7089 {
7090 for (i = 0; i < pChannelList->numChannels; i++)
7091 {
7092 for (j = 0; j < len; j += 2)
7093 {
7094 if (pControlList[j] == pChannelList->channelList[i])
7095 {
7096 found = TRUE;
7097 break;
7098 }
7099 }
7100
7101 if (found) // insert a pair(channel#, flag)
7102 {
7103 if (CSR_IS_CHANNEL_5GHZ(pControlList[j]))
7104 {
7105 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
7106 }
7107 else
7108 {
7109 pControlList[j+1] = eSIR_ACTIVE_SCAN;
7110 }
7111
7112 found = FALSE; // reset the flag
7113 }
7114
7115 }
7116
7117 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7118 }//Successfully getting scan control list
7119 palFreeMemory(pMac->hHdd, pControlList);
7120 }//AllocateMemory
7121}
7122
7123
7124//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7125eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7126{
7127 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7128}
7129
7130
7131void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7132{
7133 tListElem *pEntry = NULL;
7134 tSmeCmd *pCommand = NULL;
7135 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
7136
7137 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
7138 if ( pEntry )
7139 {
7140 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7141 if ( eSmeCommandScan == pCommand->command )
7142 {
7143 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7144 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7145 }
7146 else
7147 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007148 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007149 }
7150 }
7151 smeProcessPendingQueue( pMac );
7152}
7153
7154eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7155{
7156 eHalStatus status;
7157 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7158 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7159
7160 //***setcfg for background scan channel list
7161 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7162 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7163 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7164 if(!csrIsAllSessionDisconnected(pMac))
7165 {
7166 //If disbaling BG scan here, we need to stop aging as well
7167 if(pScanReq->scanInterval == 0)
7168 {
7169 //Stop aging because no new result is coming in
7170 csrScanStopResultAgingTimer(pMac);
7171 }
7172
7173#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7174 {
7175 vos_log_scan_pkt_type *pScanLog = NULL;
7176
7177 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7178 if(pScanLog)
7179 {
7180 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7181 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7182 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7183 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7184 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7185 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7186 {
7187 palCopyMemory(pMac->hHdd, pScanLog->channels, pScanReq->ChannelInfo.ChannelList,
7188 pScanLog->numChannel);
7189 }
7190 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7191 }
7192 }
7193#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7194
7195 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7196 }
7197 else
7198 {
7199 //No need to stop aging because IDLE scan is still running
7200 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7201 }
7202
7203 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7204 {
7205 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7206 }
7207
7208 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7209 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7210
7211
7212
7213 return (status);
7214}
7215
7216
7217eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac)
7218{
7219 eHalStatus status = eHAL_STATUS_SUCCESS;
7220 tSirMbMsg *pMsg;
7221 tANI_U16 msgLen;
7222 tListElem *pEntry;
7223 tSmeCmd *pCommand;
7224
7225#ifdef WLAN_AP_STA_CONCURRENCY
7226 csrLLLock(&pMac->scan.scanCmdPendingList);
7227 while( NULL != ( pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7228 {
7229
7230 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7231 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7232 }
7233 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7234#endif
7235
7236 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7237 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7238 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7239 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7240
7241 //We need to abort scan only if we are scanning
7242 if(NULL != (pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK)))
7243 {
7244 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7245 if(eSmeCommandScan == pCommand->command)
7246 {
7247 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
7248 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
7249 if(HAL_STATUS_SUCCESS(status))
7250 {
7251 palZeroMemory(pMac->hHdd, (void *)pMsg, msgLen);
7252 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7253 pMsg->msgLen = pal_cpu_to_be16(msgLen);
7254 status = palSendMBMessage(pMac->hHdd, pMsg);
7255 }
7256 }
7257 }
7258
7259 return( status );
7260}
7261
7262void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7263 eSmeCommandType commandType )
7264{
7265 tDblLinkList localList;
7266 tListElem *pEntry;
7267 tSmeCmd *pCommand;
7268 tListElem *pEntryToRemove;
7269
7270 vos_mem_zero(&localList, sizeof(tDblLinkList));
7271 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7272 {
7273 smsLog(pMac, LOGE, FL(" failed to open list"));
7274 return;
7275 }
7276
7277 csrLLLock(pList);
7278 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7279 {
7280 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7281
7282 // Have to make sure we don't loop back to the head of the list, which will
7283 // happen if the entry is NOT on the list...
7284 while( pEntry )
7285 {
7286 pEntryToRemove = pEntry;
7287 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7288 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7289 if ( pCommand->command == commandType )
7290 {
7291 // Remove that entry only
7292 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7293 {
7294 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7295 }
7296 }
7297 }
7298
7299
7300 }
7301 csrLLUnlock(pList);
7302
7303 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7304 {
7305 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7306 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7307 }
7308 csrLLClose(&localList);
7309
7310}
7311
7312
7313eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac)
7314{
7315 eHalStatus status = eHAL_STATUS_SUCCESS;
7316
7317 if( !csrIsScanForRoamCommandActive( pMac ) )
7318 {
7319 //Only abort the scan if it is not used for other roam/connect purpose
7320 status = csrScanAbortMacScan(pMac);
7321 }
7322
7323 return (status);
7324}
7325
7326
7327eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac)
7328{
7329 eHalStatus status = eHAL_STATUS_SUCCESS;
7330 tSirMbMsg *pMsg;
7331 tANI_U16 msgLen;
7332
7333 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
7334 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
7335 if(HAL_STATUS_SUCCESS(status))
7336 {
7337 palZeroMemory(pMac->hHdd, pMsg, msgLen);
7338 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7339 pMsg->msgLen = msgLen;
7340 status = palSendMBMessage(pMac->hHdd, pMsg);
7341 }
7342
7343 return( status );
7344}
7345
7346tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7347{
7348 tANI_BOOLEAN fValid = FALSE;
7349 tANI_U32 idxValidChannels;
7350 tANI_U32 len = pMac->roam.numValidChannels;
7351
7352 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
7353 {
7354 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
7355 {
7356 fValid = TRUE;
7357 break;
7358 }
7359 }
7360
7361 return fValid;
7362}
7363
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007364#ifdef FEATURE_WLAN_LFR
7365void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
7366{
7367 tListElem *pEntry = NULL;
7368 tCsrScanResult *pBssDesc = NULL;
7369 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08007370 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
7371
7372 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
7373 {
7374 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007375 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08007376 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
7377 return;
7378 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007379
7380 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
7381 {
7382 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007383 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007384 __func__, pMac->scan.occupiedChannels.numChannels);
7385 return;
7386 }
7387
7388 /* Empty occupied channels here */
7389 pMac->scan.occupiedChannels.numChannels = 0;
7390
7391 csrLLLock(&pMac->scan.scanResultList);
7392 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
7393 while( pEntry )
7394 {
7395 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7396 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
7397
7398 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08007399 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007400 &pBssDesc->Result.BssDescriptor, &pIes))) )
7401 {
7402 continue;
7403 }
7404
7405 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
7406
7407 /*
7408 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
7409 */
7410 if( (pBssDesc->Result.pvIes == NULL) && pIes )
7411 {
7412 palFreeMemory(pMac->hHdd, pIes);
7413 }
7414
7415 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
7416 }//while
7417 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08007418
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007419}
7420#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007421