blob: 689aa5f5106e0e3def5ed883a60413a8f0c0c6c8 [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
117//*** This is temporary work around. It need to call CCM api to get to CFG later
118/// Get string parameter value
119extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
120
121void csrScanGetResultTimerHandler(void *);
122void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800123static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700124void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700125static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700126#ifdef WLAN_AP_STA_CONCURRENCY
127static void csrStaApConcTimerHandler(void *);
128#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700129tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700130eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
131void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
132void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
133void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
134void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
135//if bgPeriod is 0, background scan is disabled. It is in millisecond units
136eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
137eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
138void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
139static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
140 tANI_U8 numChn, tSirBssDescription *pBssDesc,
141 tDot11fBeaconIEs **ppIes );
142eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
143void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
144tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700145void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700146
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700147#define CSR_IS_SOCIAL_CHANNEL(channel) (((channel) == 1) || ((channel) == 6) || ((channel) == 11) )
148
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700149
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700150
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800151static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
152{
153 tListElem *pEntry;
154 tSmeCmd *pCommand;
155
156 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
157 {
158 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
159 if ( eSmeCsrCommandMask & pCommand->command )
160 {
161 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
162 }
163 else
164 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800165 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800166 }
167 }
168}
Jeff Johnson295189b2012-06-20 16:38:30 -0700169//pResult is invalid calling this function.
170void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
171{
172 if( NULL != pResult->Result.pvIes )
173 {
174 palFreeMemory( pMac->hHdd, pResult->Result.pvIes );
175 }
176 palFreeMemory(pMac->hHdd, pResult);
177}
178
179
180static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
181{
182 eHalStatus status = eHAL_STATUS_SUCCESS;
183 tListElem *pEntry;
184 tCsrScanResult *pBssDesc;
185
186 csrLLLock(pList);
187
188 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
189 {
190 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
191 csrFreeScanResultEntry( pMac, pBssDesc );
192 }
193
194 csrLLUnlock(pList);
195
196 return (status);
197}
198
199
200int csrCheckValidateLists(void * dest, const void *src, v_SIZE_t num, int idx)
201{
202#ifdef CSR_VALIDATE_LIST
203
204 int ii = 1;
205
206 if( (NULL == g_pMac) || (!g_pMac->scan.fValidateList ) )
207 {
208 return ii;
209 }
210 if(g_pchannelPowerInfoList24)
211 {
212 //check 2.4 list
213 tListElem *pElem, *pHead;
214 int count;
215
216 count = (int)(g_pchannelPowerInfoList24->Count);
217 pHead = &g_pchannelPowerInfoList24->ListHead;
218 pElem = pHead->next;
219 if((tANI_U32)(pHead->next) > 0x00010000) //Assuming kernel address is not that low.
220 {
221 //this loop crashes if the pointer is not right
222 while(pElem->next != pHead)
223 {
224 if((tANI_U32)(pElem->next) > 0x00010000)
225 {
226 pElem = pElem->next;
227 VOS_ASSERT(count > 0);
228 count--;
229 }
230 else
231 {
232 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL,
233 " %d Detect 1 list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
234 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
235 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
236 (unsigned int)dest, (unsigned int)src, (int)num);
237 VOS_ASSERT(0);
238 ii = 0;
239 break;
240 }
241 }
242 }
243 else
244 {
245 //Bad list
246 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)",
247 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
248 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
249 (unsigned int)dest, (unsigned int)src, (int)num);
250 VOS_ASSERT(0);
251 ii = 0;
252 }
253 }
254 else
255 {
256 //list ok
257 ii = 1;
258 }
259
260
261 return ii;
262
263#else
264 return 1;
265#endif //#ifdef CSR_VALIDATE_LIST
266}
267
268
269eHalStatus csrScanOpen( tpAniSirGlobal pMac )
270{
271 eHalStatus status;
272
273 do
274 {
275 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
276 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
277 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
278 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
279#ifdef WLAN_AP_STA_CONCURRENCY
280 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
281#endif
282#ifdef CSR_VALIDATE_LIST
283 g_pchannelPowerInfoList5 = &pMac->scan.channelPowerInfoList5G;
284 g_pMac = pMac;
285 g_pchannelPowerInfoList24 = &pMac->scan.channelPowerInfoList24;
286#endif
287 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
288 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
289 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerGetResult, csrScanGetResultTimerHandler, pMac);
290 if(!HAL_STATUS_SUCCESS(status))
291 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800292 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700293 break;
294 }
295#ifdef WLAN_AP_STA_CONCURRENCY
296 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerStaApConcTimer, csrStaApConcTimerHandler, pMac);
297 if(!HAL_STATUS_SUCCESS(status))
298 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800299 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700300 break;
301 }
302#endif
303 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerIdleScan, csrScanIdleScanTimerHandler, pMac);
304 if(!HAL_STATUS_SUCCESS(status))
305 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800306 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700307 break;
308 }
309 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerResultAging, csrScanResultAgingTimerHandler, pMac);
310 if(!HAL_STATUS_SUCCESS(status))
311 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800312 smsLog(pMac, LOGE, FL("cannot allocate memory for ResultAging timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700313 break;
314 }
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800315 status = palTimerAlloc(pMac->hHdd, &pMac->scan.hTimerResultCfgAging,
316 csrScanResultCfgAgingTimerHandler, pMac);
317 if(!HAL_STATUS_SUCCESS(status))
318 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800319 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800320 break;
321 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700322 }while(0);
323
324 return (status);
325}
326
327
328eHalStatus csrScanClose( tpAniSirGlobal pMac )
329{
330#ifdef CSR_VALIDATE_LIST
331 g_pchannelPowerInfoList24 = NULL;
332 g_pchannelPowerInfoList5 = NULL;
333 g_pMac = NULL;
334#endif
335 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
336 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
337#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800338 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700339#endif
340 csrLLClose(&pMac->scan.scanResultList);
341 csrLLClose(&pMac->scan.tempScanResults);
342#ifdef WLAN_AP_STA_CONCURRENCY
343 csrLLClose(&pMac->scan.scanCmdPendingList);
344#endif
345 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
346 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
347 csrLLClose(&pMac->scan.channelPowerInfoList24);
348 csrLLClose(&pMac->scan.channelPowerInfoList5G);
349 csrScanDisable(pMac);
350 palTimerFree(pMac->hHdd, pMac->scan.hTimerResultAging);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800351 palTimerFree(pMac->hHdd, pMac->scan.hTimerResultCfgAging);
Jeff Johnson295189b2012-06-20 16:38:30 -0700352 palTimerFree(pMac->hHdd, pMac->scan.hTimerGetResult);
353#ifdef WLAN_AP_STA_CONCURRENCY
354 palTimerFree(pMac->hHdd, pMac->scan.hTimerStaApConcTimer);
355#endif
356 palTimerFree(pMac->hHdd, pMac->scan.hTimerIdleScan);
357 return eHAL_STATUS_SUCCESS;
358}
359
360
361eHalStatus csrScanEnable( tpAniSirGlobal pMac )
362{
363
364 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
365 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
366
367 return eHAL_STATUS_SUCCESS;
368}
369
370
371eHalStatus csrScanDisable( tpAniSirGlobal pMac )
372{
373
374 csrScanStopTimers(pMac);
375 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
376
377 return eHAL_STATUS_SUCCESS;
378}
379
380
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700381//Set scan timing parameters according to state of other driver sessions
382//No validation of the parameters is performed.
383static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
384{
385#ifdef WLAN_AP_STA_CONCURRENCY
386 if(csrIsAnySessionConnected(pMac))
387 {
388 //If multi-session, use the appropriate default scan times
389 if(scanType == eSIR_ACTIVE_SCAN)
390 {
391 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
392 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
393 }
394 else
395 {
396 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
397 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
398 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800399 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
400 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700401
402 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
403
404 //Return so that fields set above will not be overwritten.
405 return;
406 }
407#endif
408
409 //This portion of the code executed if multi-session not supported
410 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
411 //Use the "regular" (non-concurrency) default scan timing.
412 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
413 {
414 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
415 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
416 }
417 else
418 {
419 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
420 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
421 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800422 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
423 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700424
425#ifdef WLAN_AP_STA_CONCURRENCY
426 //No rest time if no sessions are connected.
427 pScanRequest->restTime = 0;
428#endif
429}
430
Jeff Johnson295189b2012-06-20 16:38:30 -0700431#ifdef WLAN_AP_STA_CONCURRENCY
432//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
433eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
434{
435 eHalStatus status = eHAL_STATUS_SUCCESS;
436
437 tANI_BOOLEAN fNoCmdPending;
438 tSmeCmd *pQueueScanCmd=NULL;
439 tSmeCmd *pSendScanCmd=NULL;
440
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700441 if (NULL == pScanCmd)
442 {
443 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
444 return eHAL_STATUS_FAILURE;
445 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800446 /* split scan if any one of the following:
447 * - STA session is connected and the scan is not a P2P search
448 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800449 * Do not split scans if no concurrent infra connections are
450 * active and if the scan is a BG scan triggered by LFR (OR)
451 * any scan if LFR is in the middle of a BG scan. Splitting
452 * the scan is delaying the time it takes for LFR to find
453 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800454 */
Srikant Kuppa866893f2012-12-27 17:28:14 -0800455 if ( (csrIsStaSessionConnected(pMac) &&
456#ifdef FEATURE_WLAN_LFR
457 (csrIsConcurrentInfraConnected(pMac) ||
458 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
459 (pMac->roam.neighborRoamInfo.neighborRoamState !=
460 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
461#endif
462 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800463 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700464 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700465 tCsrScanRequest scanReq;
466 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
467 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
468 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700469 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
470
471 if (numChn == 0)
472 {
473
474 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700475
Vinay Malekal05fdc812012-12-17 13:04:30 -0800476 status = palAllocateMemory( pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn );
477 if( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700478 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800479 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800480 return eHAL_STATUS_FAILURE;
481 }
482 bMemAlloc = eANI_BOOLEAN_TRUE;
483 status = palCopyMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
484 pMac->scan.baseChannels.channelList, numChn );
485 if( !HAL_STATUS_SUCCESS( status ) )
486 {
487 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
488 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800489 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800490 return eHAL_STATUS_FAILURE;
491 }
492 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
493 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700494
Vinay Malekal05fdc812012-12-17 13:04:30 -0800495 //Whenever we get a scan request with multiple channels we break it up into 2 requests
496 //First request for first channel to scan and second request to scan remaining channels
497 if (numChn > pMac->roam.configParam.nNumChanCombinedConc)
498 {
499 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
500
501 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
502 if (!pQueueScanCmd)
503 {
504 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700505 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800506 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
507 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
508
Jeff Johnson295189b2012-06-20 16:38:30 -0700509 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800510 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800511 return eHAL_STATUS_FAILURE;
512 }
513 pQueueScanCmd->command = pScanCmd->command;
514 pQueueScanCmd->sessionId = pScanCmd->sessionId;
515 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
516 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
517 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
518 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700519
Vinay Malekal05fdc812012-12-17 13:04:30 -0800520 /* First copy all the parameters to local variable of scan request */
521 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700522
Vinay Malekal05fdc812012-12-17 13:04:30 -0800523 /* Now modify the elements of local var scan request required to be modified for split scan */
524 if(scanReq.ChannelInfo.ChannelList != NULL)
525 {
526 palFreeMemory(pMac->hHdd, scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800527 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800528 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700529
Vinay Malekal05fdc812012-12-17 13:04:30 -0800530 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - pMac->roam.configParam.nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700531
Vinay Malekal05fdc812012-12-17 13:04:30 -0800532 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
533 FL(" &channelToScan %0x pScanCmd(0x%X) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(0x%X)numChn(%d)"),
534 &channelToScan[0], (unsigned int)pScanCmd,
535 (unsigned int)pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700536
Vinay Malekal05fdc812012-12-17 13:04:30 -0800537 palCopyMemory(pMac->hHdd, &channelToScan[0], &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pMac->roam.configParam.nNumChanCombinedConc],
538 pChnInfo->numOfChannels * sizeof(tANI_U8));
539
540 pChnInfo->ChannelList = &channelToScan[0];
541
542 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
543 //Modify callers parameters in case of concurrency
544 scanReq.scanType = eSIR_ACTIVE_SCAN;
545 //Use concurrency values for min/maxChnTime.
546 //We know csrIsAnySessionConnected(pMac) returns TRUE here
547 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
548
549 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
550
551 if(!HAL_STATUS_SUCCESS(status))
552 {
553 if (bMemAlloc)
554 {
555 palFreeMemory( pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList );
556 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
557
558 }
559 if( scanReq.pIEField != NULL)
560 {
561 palFreeMemory(pMac->hHdd, scanReq.pIEField);
562 scanReq.pIEField = NULL;
563 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800564 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800565 return eHAL_STATUS_FAILURE;
566 }
567 /* Clean the local scan variable */
568 scanReq.ChannelInfo.ChannelList = NULL;
569 scanReq.ChannelInfo.numOfChannels = 0;
570 csrScanFreeRequest(pMac, &scanReq);
571
572 /* setup the command to scan 2 channels */
573 pSendScanCmd = pScanCmd;
574 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = pMac->roam.configParam.nNumChanCombinedConc;
575 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
576 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
577 //Use concurrency values for min/maxChnTime.
578 //We know csrIsAnySessionConnected(pMac) returns TRUE here
579 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
580 pSendScanCmd->u.scanCmd.callback = NULL;
581 } else {
582 pSendScanCmd = pScanCmd;
583 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
584 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
585 //Use concurrency values for min/maxChnTime.
586 //We know csrIsAnySessionConnected(pMac) returns TRUE here
587 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
588 }
589
590 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
591
592 //Logic Below is as follows
593 // If the scanCmdPendingList is empty then we directly send that command
594 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
595 if( fNoCmdPending )
596 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700597 if (pQueueScanCmd != NULL)
598 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800599 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700600 }
601
602 if (pSendScanCmd != NULL)
603 {
604 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
605 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800606 }
607 else
608 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700609 if (pSendScanCmd != NULL)
610 {
611 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
612 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800613
Jeff Johnson295189b2012-06-20 16:38:30 -0700614 if (pQueueScanCmd != NULL)
615 {
616 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
617 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800618 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700619 }
620 else
621 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800622 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800623 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800624 pScanCmd->u.scanCmd.reason,
625 pMac->roam.neighborRoamInfo.neighborRoamState,
626 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700627 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
628 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700629
630 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700631}
632#endif
633
Jeff Johnsone7245742012-09-05 17:12:55 -0700634/* ---------------------------------------------------------------------------
635 \fn csrScan2GOnyRequest
636 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800637 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700638 \param pMac
639 \param pScanCmd
640 \param pScanRequest
641 \return None
642 -------------------------------------------------------------------------------*/
643static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
644 tCsrScanRequest *pScanRequest)
645{
646 tANI_U8 index, channelId, channelListSize = 0;
647 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
648 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
649
650 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700651 /* To silence the KW tool null check is added */
652 if((pScanCmd == NULL) || (pScanRequest == NULL))
653 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800654 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700655 return;
656 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700657
658 if (pScanCmd->u.scanCmd.scanID ||
659 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
660 return;
661
662 //Contsruct valid Supported 2.4 GHz Channel List
663 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
664 {
665 channelId = channelList2G[index];
666 if ( csrIsSupportedChannel( pMac, channelId ) )
667 {
668 validchannelList[channelListSize++] = channelId;
669 }
670 }
671
672 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
673 pScanRequest->ChannelInfo.ChannelList = validchannelList;
674}
675
Jeff Johnson295189b2012-06-20 16:38:30 -0700676eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
677 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
678 csrScanCompleteCallback callback, void *pContext)
679{
680 eHalStatus status = eHAL_STATUS_FAILURE;
681 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700682 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700683
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800684 if(pScanRequest == NULL)
685 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800686 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800687 VOS_ASSERT(0);
688 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700689
Jeff Johnson295189b2012-06-20 16:38:30 -0700690 do
691 {
692 if(pMac->scan.fScanEnable)
693 {
694 pScanCmd = csrGetCommandBuffer(pMac);
695 if(pScanCmd)
696 {
697 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
698 pScanCmd->command = eSmeCommandScan;
699 pScanCmd->sessionId = sessionId;
700 pScanCmd->u.scanCmd.callback = callback;
701 pScanCmd->u.scanCmd.pContext = pContext;
702 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
703 {
704 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
705 }
706 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
707 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
708#ifdef SOFTAP_CHANNEL_RANGE
709 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
710#endif
711 )
712 {
713 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
714 }
715 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
716 {
717 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
718 }
719 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
720 {
721 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
722 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700723 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
724 {
725 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
726 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700727 else
728 {
729 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
730 }
731 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
732 {
733 //The caller doesn't set the time correctly. Set it here
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700734 csrSetDefaultScanTiming(pMac, pScanRequest->scanType, pScanRequest);
735 }
736#ifdef WLAN_AP_STA_CONCURRENCY
737 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800738 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700739 //Need to set restTime only if at least one session is connected
740 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700741 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700742 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700743 }
744 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700745#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700746 /*For Standalone wlan : channel time will remain the same.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800747 For BTC with A2DP up: Channel time = Channel time * 2 , if station is not already associated.
748 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
749 to take a long time.
750 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
751 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700752 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800753 if (HAL_STATUS_SUCCESS(status) &&
754 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700755 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
756 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
757 {
758 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
759 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
760 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800761
762 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
763 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700764 //Need to make the following atomic
765 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
766
767 if(pScanRequestID)
768 {
769 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
770 }
771
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800772 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700773 // If it is not, CSR will save the scan request in the pending cmd queue
774 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800775 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700776 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
777#ifdef SOFTAP_CHANNEL_RANGE
778 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
779#endif
780 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
781 )
782 {
783 tSmeCmd *p11dScanCmd;
784 tCsrScanRequest scanReq;
785 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
786
787 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
788
789 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800790 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700791 {
792 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
793
794 palZeroMemory(pMac->hHdd, &p11dScanCmd->u.scanCmd, sizeof(tScanCmd));
795 status = palAllocateMemory( pMac->hHdd, (void **)&pChnInfo->ChannelList, numChn );
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800796 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700797 {
798 break;
799 }
800 status = palCopyMemory( pMac->hHdd, pChnInfo->ChannelList,
801 pMac->scan.baseChannels.channelList, numChn );
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800802 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700803 {
804 palFreeMemory( pMac->hHdd, pChnInfo->ChannelList );
805 pChnInfo->ChannelList = NULL;
806 break;
807 }
808 pChnInfo->numOfChannels = (tANI_U8)numChn;
809 p11dScanCmd->command = eSmeCommandScan;
810 p11dScanCmd->u.scanCmd.callback = NULL;
811 p11dScanCmd->u.scanCmd.pContext = NULL;
812 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++;
813 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
814
815 if ( csrIs11dSupported(pMac) )
816 {
817 scanReq.scanType = eSIR_PASSIVE_SCAN;
818 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
819 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
820 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
821 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
822 }
823 else
824 {
825 scanReq.scanType = eSIR_ACTIVE_SCAN;
826 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
827 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
828 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
829 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800830
831 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
832 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700833 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700834
Jeff Johnson295189b2012-06-20 16:38:30 -0700835 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
836 //Free the channel list
837 palFreeMemory( pMac->hHdd, pChnInfo->ChannelList );
838
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800839 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700840 {
841 //Start process the command
842#ifdef WLAN_AP_STA_CONCURRENCY
843 status = csrQueueScanRequest(pMac, p11dScanCmd);
844#else
845 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
846#endif
847 if( !HAL_STATUS_SUCCESS( status ) )
848 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800849 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700850 break;
851 }
852 }
853 else
854 {
855 break;
856 }
857 }
858 else
859 {
860 //error
861 break;
862 }
863 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700864
865 //Scan only 2G Channels if set in ini file
866 //This is mainly to reduce the First Scan duration
867 //Once we turn on Wifi
868 if(pMac->scan.fFirstScanOnly2GChnl)
869 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800870 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700871 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
872 }
873
Jeff Johnson295189b2012-06-20 16:38:30 -0700874 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
875 if(HAL_STATUS_SUCCESS(status))
876 {
877 //Start process the command
878#ifdef WLAN_AP_STA_CONCURRENCY
879 status = csrQueueScanRequest(pMac,pScanCmd);
880#else
881 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
882#endif
883 if( !HAL_STATUS_SUCCESS( status ) )
884 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800885 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700886 break;
887 }
888 }
889 else
890 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800891 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700892 break;
893 }
894 }
895 else
896 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800897 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700898 break;
899 }
900 }
901 } while(0);
902 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
903 {
904 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
905 {
906 //Set the flag back for restarting idle scan
907 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
908 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800909 smsLog( pMac, LOGE, FL(" failed with status = %d, releasing scan cmd"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700910 csrReleaseCommandScan(pMac, pScanCmd);
911 }
912
913 return (status);
914}
915
916
917eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
918{
919 eHalStatus status = eHAL_STATUS_SUCCESS;
920 tSmeCmd *pScanCmd;
921
922 if(pMac->scan.fScanEnable)
923 {
924 pScanCmd = csrGetCommandBuffer(pMac);
925 if(pScanCmd)
926 {
927 pScanCmd->command = eSmeCommandScan;
928 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
929 pScanCmd->u.scanCmd.callback = NULL;
930 pScanCmd->u.scanCmd.pContext = NULL;
931 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
932 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700933 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700934 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
935 if( !HAL_STATUS_SUCCESS( status ) )
936 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800937 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700938 csrReleaseCommandScan(pMac, pScanCmd);
939 }
940 }
941 else
942 {
943 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800944 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700945 status = eHAL_STATUS_RESOURCES;
946 }
947 }
948
949 return (status);
950}
951
952
953eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
954{
955 eHalStatus status = eHAL_STATUS_SUCCESS;
956 tANI_U32 scanId;
957 tCsrScanRequest scanReq;
958
959 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
960 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
961 scanReq.scanType = eSIR_ACTIVE_SCAN;
962 scanReq.requestType = reqType;
963 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
964 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800965 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
966 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700967 //Scan with invalid sessionId.
968 //This results in SME using the first available session to scan.
969 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
970 &scanId, NULL, NULL);
971
972 return (status);
973}
974
975
976
977
978eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
979{
980 eHalStatus status = eHAL_STATUS_FAILURE;
981 tScanResultHandle hBSSList = NULL;
982 tCsrScanResultFilter *pScanFilter = NULL;
983 tANI_U32 roamId = 0;
984 tCsrRoamProfile *pProfile = NULL;
985 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
986
Jeff Johnson32d95a32012-09-10 13:15:23 -0700987 if(!pSession)
988 {
989 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
990 return eHAL_STATUS_FAILURE;
991 }
992
Jeff Johnson295189b2012-06-20 16:38:30 -0700993 do
994 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800995 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -0700996 if(pSession->fCancelRoaming)
997 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800998 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -0700999 csrScanStartIdleScan(pMac);
1000 status = eHAL_STATUS_SUCCESS;
1001 break;
1002 }
1003 //Here is the profile we need to connect to
1004 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1005 if(!HAL_STATUS_SUCCESS(status))
1006 break;
1007 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1008 if(NULL == pSession->pCurRoamProfile)
1009 {
1010 pScanFilter->EncryptionType.numEntries = 1;
1011 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1012 }
1013 else
1014 {
1015 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
1016 status = palAllocateMemory(pMac->hHdd, (void **)&pProfile, sizeof(tCsrRoamProfile));
1017 if(!HAL_STATUS_SUCCESS(status))
1018 break;
1019 palZeroMemory(pMac->hHdd, pProfile, sizeof(tCsrRoamProfile));
1020 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1021 if(!HAL_STATUS_SUCCESS(status))
1022 break;
1023 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1024 }//We have a profile
1025 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1026 if(HAL_STATUS_SUCCESS(status))
1027 {
1028 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1029 if(HAL_STATUS_SUCCESS(status))
1030 {
1031 if(eCsrLostLink1 == reason)
1032 {
1033 //we want to put the last connected BSS to the very beginning, if possible
1034 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1035 }
1036 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1037 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1038 if(!HAL_STATUS_SUCCESS(status))
1039 {
1040 csrScanResultPurge(pMac, hBSSList);
1041 }
1042 }//Have scan result
1043 }
1044 }while(0);
1045 if(pScanFilter)
1046 {
1047 //we need to free memory for filter if profile exists
1048 csrFreeScanFilter(pMac, pScanFilter);
1049 palFreeMemory(pMac->hHdd, pScanFilter);
1050 }
1051 if(NULL != pProfile)
1052 {
1053 csrReleaseProfile(pMac, pProfile);
1054 palFreeMemory(pMac->hHdd, (void *)pProfile);
1055 }
1056
1057 return (status);
1058}
1059
1060
Jeff Johnson32d95a32012-09-10 13:15:23 -07001061eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, void *callback, void *pContext)
Jeff Johnson295189b2012-06-20 16:38:30 -07001062{
1063 eHalStatus status = eHAL_STATUS_SUCCESS;
1064 tSmeCmd *pScanCmd;
1065
1066 if(pMac->scan.fScanEnable)
1067 {
1068 pScanCmd = csrGetCommandBuffer(pMac);
1069 if(pScanCmd)
1070 {
1071 pScanCmd->command = eSmeCommandScan;
1072 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
Jeff Johnson32d95a32012-09-10 13:15:23 -07001073 pScanCmd->u.scanCmd.callback = callback;
1074 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001075 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1076 //Need to make the following atomic
1077 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
1078 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1079 if( !HAL_STATUS_SUCCESS( status ) )
1080 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001081 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001082 csrReleaseCommandScan(pMac, pScanCmd);
1083 }
1084 }
1085 else
1086 {
1087 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001088 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001089 status = eHAL_STATUS_RESOURCES;
1090 }
1091 }
1092
1093 return (status);
1094}
1095
1096
1097eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1098{
1099 eHalStatus status = eHAL_STATUS_FAILURE;
1100 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1101
Jeff Johnson32d95a32012-09-10 13:15:23 -07001102 if(!pSession)
1103 {
1104 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1105 return eHAL_STATUS_FAILURE;
1106 }
1107
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001108 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001109 if(pSession->fCancelRoaming)
1110 {
1111 csrScanStartIdleScan(pMac);
1112 }
1113 else if(pSession->pCurRoamProfile)
1114 {
1115 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1116 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1117 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1118 {
1119 //try lostlink scan2
1120 status = csrScanRequestLostLink2(pMac, sessionId);
1121 }
1122 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1123 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1124 {
1125 //go straight to lostlink scan3
1126 status = csrScanRequestLostLink3(pMac, sessionId);
1127 }
1128 else
1129 {
1130 //we are done with lostlink
1131 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1132 {
1133 csrScanStartIdleScan(pMac);
1134 }
1135 status = eHAL_STATUS_SUCCESS;
1136 }
1137 }
1138 else
1139 {
1140 status = csrScanRequestLostLink3(pMac, sessionId);
1141 }
1142
1143 return (status);
1144}
1145
1146
1147
1148eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1149{
1150 eHalStatus status = eHAL_STATUS_FAILURE;
1151 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1152
Jeff Johnson32d95a32012-09-10 13:15:23 -07001153 if(!pSession)
1154 {
1155 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1156 return eHAL_STATUS_FAILURE;
1157 }
1158
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001159 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001160 if(pSession->fCancelRoaming)
1161 {
1162 csrScanStartIdleScan(pMac);
1163 }
1164 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1165 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1166 {
1167 //try lostlink scan3
1168 status = csrScanRequestLostLink3(pMac, sessionId);
1169 }
1170 else
1171 {
1172 //we are done with lostlink
1173 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1174 {
1175 csrScanStartIdleScan(pMac);
1176 }
1177 }
1178
1179 return (status);
1180}
1181
1182
1183
1184eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1185{
1186 eHalStatus status = eHAL_STATUS_SUCCESS;
1187
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001188 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001189 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1190 {
1191 //we are done with lostlink
1192 csrScanStartIdleScan(pMac);
1193 }
1194
1195 return (status);
1196}
1197
1198
1199
1200
1201//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1202//If no roam profile (it should not), it is like lostlinkscan3
1203eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1204{
1205 eHalStatus status = eHAL_STATUS_SUCCESS;
1206 tSmeCmd *pCommand = NULL;
1207 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1208 tCsrScanResultFilter *pScanFilter = NULL;
1209 tScanResultHandle hBSSList = NULL;
1210 tCsrScanResultInfo *pScanResult = NULL;
1211 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1212
Jeff Johnson32d95a32012-09-10 13:15:23 -07001213 if(!pSession)
1214 {
1215 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1216 return eHAL_STATUS_FAILURE;
1217 }
1218
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001219 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001220 do
1221 {
1222 pCommand = csrGetCommandBuffer(pMac);
1223 if(!pCommand)
1224 {
1225 status = eHAL_STATUS_RESOURCES;
1226 break;
1227 }
1228 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1229 pCommand->command = eSmeCommandScan;
1230 pCommand->sessionId = (tANI_U8)sessionId;
1231 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1232 pCommand->u.scanCmd.callback = NULL;
1233 pCommand->u.scanCmd.pContext = NULL;
1234 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1235 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001236 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1237 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001238 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1239 if(pSession->connectedProfile.SSID.length)
1240 {
1241 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
1242 if(!HAL_STATUS_SUCCESS(status))
1243 {
1244 break;
1245 }
1246 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
1247 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1248 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
1249 }
1250 else
1251 {
1252 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1253 }
1254 if(pSession->pCurRoamProfile)
1255 {
1256 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1257 if(!HAL_STATUS_SUCCESS(status))
1258 {
1259 break;
1260 }
1261 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1262 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1263 if(!HAL_STATUS_SUCCESS(status))
1264 {
1265 break;
1266 }
1267 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1268 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1269 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1270 {
1271 tANI_U8 i, nChn = 0;
1272 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1273 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1274 if(!HAL_STATUS_SUCCESS(status))
1275 {
1276 break;
1277 }
1278 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1279 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1280 {
1281 for(i = 0; i < nChn; i++)
1282 {
1283 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1284 pScanResult->BssDescriptor.channelId)
1285 {
1286 break;
1287 }
1288 }
1289 if(i == nChn)
1290 {
1291 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1292 }
1293 }
1294 //Include the last connected BSS' channel
1295 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1296 {
1297 for(i = 0; i < nChn; i++)
1298 {
1299 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1300 pSession->connectedProfile.operationChannel)
1301 {
1302 break;
1303 }
1304 }
1305 if(i == nChn)
1306 {
1307 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1308 }
1309 }
1310 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1311 }
1312 else
1313 {
1314 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1315 {
1316 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1317 1);
1318 //just try the last connected channel
1319 if(HAL_STATUS_SUCCESS(status))
1320 {
1321 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1322 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1323 }
1324 else
1325 {
1326 break;
1327 }
1328 }
1329 }
1330 }
1331 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1332 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1333 if( !HAL_STATUS_SUCCESS( status ) )
1334 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001335 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001336 break;
1337 }
1338 } while( 0 );
1339
1340 if(!HAL_STATUS_SUCCESS(status))
1341 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001342 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001343 if(pCommand)
1344 {
1345 csrReleaseCommandScan(pMac, pCommand);
1346 }
1347 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1348 }
1349 if(pScanFilter)
1350 {
1351 csrFreeScanFilter(pMac, pScanFilter);
1352 palFreeMemory(pMac->hHdd, pScanFilter);
1353 }
1354 if(hBSSList)
1355 {
1356 csrScanResultPurge(pMac, hBSSList);
1357 }
1358
1359 return( status );
1360}
1361
1362
1363//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1364//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1365eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1366{
1367 eHalStatus status = eHAL_STATUS_SUCCESS;
1368 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1369 tCsrScanResultFilter *pScanFilter = NULL;
1370 tScanResultHandle hBSSList = NULL;
1371 tCsrScanResultInfo *pScanResult = NULL;
1372 tSmeCmd *pCommand = NULL;
1373 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1374
Jeff Johnson32d95a32012-09-10 13:15:23 -07001375 if(!pSession)
1376 {
1377 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1378 return eHAL_STATUS_FAILURE;
1379 }
1380
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001381 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001382 do
1383 {
1384 pCommand = csrGetCommandBuffer(pMac);
1385 if(!pCommand)
1386 {
1387 status = eHAL_STATUS_RESOURCES;
1388 break;
1389 }
1390 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1391 pCommand->command = eSmeCommandScan;
1392 pCommand->sessionId = (tANI_U8)sessionId;
1393 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1394 pCommand->u.scanCmd.callback = NULL;
1395 pCommand->u.scanCmd.pContext = NULL;
1396 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1397 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001398 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1399 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001400 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1401 if(pSession->pCurRoamProfile)
1402 {
1403 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1404 if(!HAL_STATUS_SUCCESS(status))
1405 {
1406 break;
1407 }
1408 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1409 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1410 if(!HAL_STATUS_SUCCESS(status))
1411 {
1412 break;
1413 }
1414 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1415 if(!HAL_STATUS_SUCCESS(status))
1416 {
1417 break;
1418 }
1419 if(hBSSList)
1420 {
1421 tANI_U8 i, nChn = 0;
1422 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
1423 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1424 if(!HAL_STATUS_SUCCESS(status))
1425 {
1426 break;
1427 }
1428 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1429 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1430 {
1431 for(i = 0; i < nChn; i++)
1432 {
1433 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1434 pScanResult->BssDescriptor.channelId)
1435 {
1436 break;
1437 }
1438 }
1439 if(i == nChn)
1440 {
1441 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1442 }
1443 }
1444 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1445 }
1446 }
1447 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1448 //Put to the head in pending queue
1449 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1450 if( !HAL_STATUS_SUCCESS( status ) )
1451 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001452 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001453 break;
1454 }
1455 } while( 0 );
1456
1457 if(!HAL_STATUS_SUCCESS(status))
1458 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001459 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001460 if(pCommand)
1461 {
1462 csrReleaseCommandScan(pMac, pCommand);
1463 }
1464 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1465 }
1466 if(pScanFilter)
1467 {
1468 csrFreeScanFilter(pMac, pScanFilter);
1469 palFreeMemory(pMac->hHdd, pScanFilter);
1470 }
1471 if(hBSSList)
1472 {
1473 csrScanResultPurge(pMac, hBSSList);
1474 }
1475
1476 return( status );
1477}
1478
1479
1480//To actively scan all valid channels
1481eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1482{
1483 eHalStatus status = eHAL_STATUS_SUCCESS;
1484 tSmeCmd *pCommand;
1485 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1486
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001487 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001488 do
1489 {
1490 pCommand = csrGetCommandBuffer(pMac);
1491 if(!pCommand)
1492 {
1493 status = eHAL_STATUS_RESOURCES;
1494 break;
1495 }
1496 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
1497 pCommand->command = eSmeCommandScan;
1498 pCommand->sessionId = (tANI_U8)sessionId;
1499 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1500 pCommand->u.scanCmd.callback = NULL;
1501 pCommand->u.scanCmd.pContext = NULL;
1502 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1503 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001504 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1505 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001506 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1507 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
1508 //Put to the head of pending queue
1509 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1510 if( !HAL_STATUS_SUCCESS( status ) )
1511 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001512 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001513 break;
1514 }
1515 } while( 0 );
1516 if(!HAL_STATUS_SUCCESS(status))
1517 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001518 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001519 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1520 {
1521 csrScanStartIdleScan(pMac);
1522 }
1523 if(pCommand)
1524 {
1525 csrReleaseCommandScan(pMac, pCommand);
1526 }
1527 }
1528
1529 return( status );
1530}
1531
1532
1533eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1534{
1535 eHalStatus status = eHAL_STATUS_FAILURE;
1536 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1537 tCsrScanResultFilter *pScanFilter = NULL;
1538 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1539 tANI_U32 sessionId = pCommand->sessionId;
1540#ifdef FEATURE_WLAN_BTAMP_UT_RF
1541 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1542#endif
1543 do
1544 {
1545 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1546 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1547 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001548 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001549 break;
1550 }
1551 if(pProfile == NULL)
1552 break;
1553 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1554 if(!HAL_STATUS_SUCCESS(status))
1555 break;
1556 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1557 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1558 if(!HAL_STATUS_SUCCESS(status))
1559 break;
1560 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1561 if(!HAL_STATUS_SUCCESS(status))
1562 break;
1563 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1564 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1565 if(!HAL_STATUS_SUCCESS(status))
1566 {
1567 break;
1568 }
1569 }while(0);
1570 if(!HAL_STATUS_SUCCESS(status))
1571 {
1572 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1573 {
1574 csrScanResultPurge(pMac, hBSSList);
1575 }
1576 //We haven't done anything to this profile
1577 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1578 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1579 //In case we have nothing else to do, restart idle scan
1580 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1581 {
1582 status = csrScanStartIdleScan(pMac);
1583 }
1584#ifdef FEATURE_WLAN_BTAMP_UT_RF
1585 //In case of WDS station, let it retry.
1586 if( CSR_IS_WDS_STA(pProfile) )
1587 {
1588 //Save the roma profile so we can retry
1589 csrFreeRoamProfile( pMac, sessionId );
1590 if (HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd,
1591 (void **)&pSession->pCurRoamProfile,
1592 sizeof(tCsrRoamProfile))))
1593 {
1594 palZeroMemory(pMac->hHdd, pSession->pCurRoamProfile, sizeof(tCsrRoamProfile));
1595 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1596 }
1597 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1598 }
1599#endif
1600 }
1601 if(pScanFilter)
1602 {
1603 csrFreeScanFilter(pMac, pScanFilter);
1604 palFreeMemory(pMac->hHdd, pScanFilter);
1605 }
1606
1607 return (status);
1608}
1609
1610
1611eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1612{
1613 eHalStatus status = eHAL_STATUS_SUCCESS;
1614 tANI_U32 sessionId = pCommand->sessionId;
1615 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1616 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1617
Jeff Johnson32d95a32012-09-10 13:15:23 -07001618 if(!pSession)
1619 {
1620 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1621 return eHAL_STATUS_FAILURE;
1622 }
1623
Jeff Johnson295189b2012-06-20 16:38:30 -07001624#if defined(WLAN_DEBUG)
1625 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1626 {
1627 char str[36];
1628 palCopyMemory(pMac->hHdd, str, pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1629 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
1630 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001631 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001632 }
1633#endif
1634 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1635 if(pProfile && CSR_IS_START_IBSS(pProfile))
1636 {
1637 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1638 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1639 if(!HAL_STATUS_SUCCESS(status))
1640 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001641 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001642 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1643 }
1644 }
1645 else
1646 {
1647 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1648
1649 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1650 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1651 {
1652 status = csrScanStartIdleScan(pMac);
1653 }
1654 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1655 {
1656 //Only indicate assoc_completion if we indicate assoc_start.
1657 if(pSession->bRefAssocStartCnt > 0)
1658 {
1659 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
1660 palZeroMemory(pMac->hHdd, &roamInfo, sizeof(tCsrRoamInfo));
1661 pRoamInfo = &roamInfo;
1662 if(pCommand->u.roamCmd.pRoamBssEntry)
1663 {
1664 tCsrScanResult *pScanResult =
1665 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1666 tCsrScanResult, Link);
1667 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1668 }
1669 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1670 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1671 pSession->bRefAssocStartCnt--;
1672 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1673 pCommand->u.scanCmd.roamId,
1674 eCSR_ROAM_ASSOCIATION_COMPLETION,
1675 eCSR_ROAM_RESULT_FAILURE);
1676 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001677 else
1678 {
1679 csrRoamCallCallback(pMac, sessionId, NULL,
1680 pCommand->u.scanCmd.roamId,
1681 eCSR_ROAM_ASSOCIATION_FAILURE,
1682 eCSR_ROAM_RESULT_FAILURE);
1683 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001684#ifdef FEATURE_WLAN_BTAMP_UT_RF
1685 //In case of WDS station, let it retry.
1686 if( CSR_IS_WDS_STA(pProfile) )
1687 {
1688 //Save the roma profile so we can retry
1689 csrFreeRoamProfile( pMac, sessionId );
1690 if (HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd,
1691 (void **)&pSession->pCurRoamProfile,
1692 sizeof(tCsrRoamProfile))))
1693 {
1694 palZeroMemory(pMac->hHdd, pSession->pCurRoamProfile, sizeof(tCsrRoamProfile));
1695 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1696 }
1697 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1698 }
1699#endif
1700 }
1701 else
1702 {
1703 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1704 }
1705 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1706 }
1707
1708 return (status);
1709}
1710
1711
1712//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1713eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1714{
1715 eHalStatus status = eHAL_STATUS_FAILURE;
1716 tScanResultHandle hBSSList = NULL;
1717 tCsrScanResultFilter *pScanFilter = NULL;
1718 tANI_U32 roamId = 0;
1719 tCsrRoamProfile *pProfile = NULL;
1720 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1721
1722 do
1723 {
1724 //Here is the profile we need to connect to
1725 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
1726 if(!HAL_STATUS_SUCCESS(status))
1727 break;
1728 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
1729 if(NULL == pSession) break;
1730 if(NULL == pSession->pCurRoamProfile)
1731 {
1732 pScanFilter->EncryptionType.numEntries = 1;
1733 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1734 }
1735 else
1736 {
1737 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
1738 status = palAllocateMemory(pMac->hHdd, (void **)&pProfile, sizeof(tCsrRoamProfile));
1739 if(!HAL_STATUS_SUCCESS(status))
1740 break;
1741 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1742 if(!HAL_STATUS_SUCCESS(status))
1743 break;
1744 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1745 }//We have a profile
1746 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1747 if(HAL_STATUS_SUCCESS(status))
1748 {
1749 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1750 if(HAL_STATUS_SUCCESS(status))
1751 {
1752 //we want to put the last connected BSS to the very beginning, if possible
1753 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1754 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1755 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1756 if(!HAL_STATUS_SUCCESS(status))
1757 {
1758 csrScanResultPurge(pMac, hBSSList);
1759 }
1760 }//Have scan result
1761 else
1762 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001763 smsLog(pMac, LOGW, FL("cannot find matching BSS of %02X-%02X-%02X-%02X-%02X-%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001764 pSession->connectedProfile.bssid[0],
1765 pSession->connectedProfile.bssid[1],
1766 pSession->connectedProfile.bssid[2],
1767 pSession->connectedProfile.bssid[3],
1768 pSession->connectedProfile.bssid[4],
1769 pSession->connectedProfile.bssid[5]);
1770 //Disconnect
1771 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1772 }
1773 }
1774 }while(0);
1775 if(pScanFilter)
1776 {
1777 csrFreeScanFilter(pMac, pScanFilter);
1778 palFreeMemory(pMac->hHdd, pScanFilter);
1779 }
1780 if(NULL != pProfile)
1781 {
1782 csrReleaseProfile(pMac, pProfile);
1783 palFreeMemory(pMac->hHdd, pProfile);
1784 }
1785
1786 return (status);
1787}
1788
1789
1790
1791eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1792{
1793 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1794 tScanResultList *pScanList = (tScanResultList *)hScanList;
1795
1796 if(pScanList)
1797 {
1798 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1799 csrLLClose(&pScanList->List);
1800 palFreeMemory(pMac->hHdd, pScanList);
1801 }
1802 return (status);
1803}
1804
1805
1806static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1807{
1808 tANI_U32 ret = 0;
1809 int i = CSR_NUM_RSSI_CAT - 1;
1810
1811 while(i >= 0)
1812 {
1813 if(rssi >= pMac->roam.configParam.RSSICat[i])
1814 {
1815 ret = pMac->roam.configParam.BssPreferValue[i];
1816 break;
1817 }
1818 i--;
1819 };
1820
1821 return (ret);
1822}
1823
1824
1825//Return a CapValue base on the capabilities of a BSS
1826static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
1827{
1828 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08001829#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
1830 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
1831 {
1832 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
1833 {
1834 ret += CSR_BSS_CAP_VALUE_5GHZ;
1835 }
1836 }
1837#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001838 if( pIes )
1839 {
1840 //We only care about 11N capability
1841 if(pIes->HTCaps.present)
1842 {
1843 ret += CSR_BSS_CAP_VALUE_HT;
1844 }
1845 if(CSR_IS_QOS_BSS(pIes))
1846 {
1847 ret += CSR_BSS_CAP_VALUE_WMM;
1848 //Give advantage to UAPSD
1849 if(CSR_IS_UAPSD_BSS(pIes))
1850 {
1851 ret += CSR_BSS_CAP_VALUE_UAPSD;
1852 }
1853 }
1854 }
1855
1856 return (ret);
1857}
1858
1859
1860//To check whther pBss1 is better than pBss2
1861static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
1862{
1863 tANI_BOOLEAN ret;
1864
1865 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
1866 {
1867 ret = eANI_BOOLEAN_TRUE;
1868 }
1869 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
1870 {
1871 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
1872 {
1873 ret = eANI_BOOLEAN_TRUE;
1874 }
1875 else
1876 {
1877 ret = eANI_BOOLEAN_FALSE;
1878 }
1879 }
1880 else
1881 {
1882 ret = eANI_BOOLEAN_FALSE;
1883 }
1884
1885 return (ret);
1886}
1887
1888
Srikant Kuppa866893f2012-12-27 17:28:14 -08001889#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001890//Add the channel to the occupiedChannels array
1891static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08001892 tpAniSirGlobal pMac,
1893 tCsrScanResult *pResult,
1894 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001895 tDot11fBeaconIEs *pIes)
1896{
1897 eHalStatus status;
1898 tANI_U8 channel;
1899 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
1900 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
1901
1902 channel = pResult->Result.BssDescriptor.channelId;
1903
1904 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08001905 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001906 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08001907 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001908 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08001909 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001910 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001911 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08001912 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08001913 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
1914 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
1915 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001916 }
1917}
1918#endif
1919
Jeff Johnson295189b2012-06-20 16:38:30 -07001920//Put the BSS into the scan result list
1921//pIes can not be NULL
1922static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
1923{
Srinivas28b5b4e2012-12-12 13:07:53 -08001924#ifdef FEATURE_WLAN_LFR
1925 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
1926#endif
1927
Jeff Johnson295189b2012-06-20 16:38:30 -07001928 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
1929 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
1930 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08001931#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08001932 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
1933 {
1934 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
1935 NOT set in the cfg.ini file */
1936 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
1937 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07001938#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001939}
1940
1941
1942eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
1943{
1944 eHalStatus status;
1945 tScanResultList *pRetList;
1946 tCsrScanResult *pResult, *pBssDesc;
1947 tANI_U32 count = 0;
1948 tListElem *pEntry;
1949 tANI_U32 bssLen, allocLen;
1950 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
1951 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
1952 tDot11fBeaconIEs *pIes, *pNewIes;
1953 tANI_BOOLEAN fMatch;
1954
1955 if(phResult)
1956 {
1957 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
1958 }
1959 status = palAllocateMemory(pMac->hHdd, (void **)&pRetList, sizeof(tScanResultList));
1960 if(HAL_STATUS_SUCCESS(status))
1961 {
1962 palZeroMemory(pMac->hHdd, pRetList, sizeof(tScanResultList));
1963 csrLLOpen(pMac->hHdd, &pRetList->List);
1964 pRetList->pCurEntry = NULL;
1965
1966 csrLLLock(&pMac->scan.scanResultList);
1967 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
1968 while( pEntry )
1969 {
1970 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
1971 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
1972 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
1973 //for any error condition, otherwiase, it will be freed later.
1974 //reset
1975 fMatch = eANI_BOOLEAN_FALSE;
1976 pNewIes = NULL;
1977
1978 if(pFilter)
1979 {
1980 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
1981 if( NULL != pIes )
1982 {
1983 //Only save it when matching
1984 if(fMatch)
1985 {
1986 if( !pBssDesc->Result.pvIes )
1987 {
1988 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
1989 pNewIes = pIes;
1990 }
1991 else
1992 {
1993 //The pIes is allocated by someone else. make a copy
1994 //Only to save parsed IEs if caller provides a filter. Most likely the caller
1995 //is using to for association, hence save the parsed IEs
1996 status = palAllocateMemory(pMac->hHdd, (void **)&pNewIes, sizeof(tDot11fBeaconIEs));
1997 if( HAL_STATUS_SUCCESS( status ) )
1998 {
1999 palCopyMemory( pMac->hHdd, pNewIes, pIes, sizeof( tDot11fBeaconIEs ) );
2000 }
2001 else
2002 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002003 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002004 //Need to free memory allocated by csrMatchBSS
2005 if( !pBssDesc->Result.pvIes )
2006 {
2007 palFreeMemory(pMac->hHdd, pIes);
2008 }
2009 break;
2010 }
2011 }
2012 }//fMatch
2013 else if( !pBssDesc->Result.pvIes )
2014 {
2015 palFreeMemory(pMac->hHdd, pIes);
2016 }
2017 }
2018 }
2019 if(NULL == pFilter || fMatch)
2020 {
2021 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2022 allocLen = sizeof( tCsrScanResult ) + bssLen;
2023 status = palAllocateMemory(pMac->hHdd, (void **)&pResult, allocLen);
2024 if(!HAL_STATUS_SUCCESS(status))
2025 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002026 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002027 if(pNewIes)
2028 {
2029 palFreeMemory(pMac->hHdd, pNewIes);
2030 }
2031 break;
2032 }
2033 palZeroMemory(pMac->hHdd, pResult, allocLen);
2034 pResult->capValue = pBssDesc->capValue;
2035 pResult->preferValue = pBssDesc->preferValue;
2036 pResult->ucEncryptionType = uc;
2037 pResult->mcEncryptionType = mc;
2038 pResult->authType = auth;
2039 pResult->Result.ssId = pBssDesc->Result.ssId;
2040 pResult->Result.timer = 0;
2041 //save the pIes for later use
2042 pResult->Result.pvIes = pNewIes;
2043 //save bss description
2044 status = palCopyMemory(pMac->hHdd, &pResult->Result.BssDescriptor, &pBssDesc->Result.BssDescriptor, bssLen);
2045 if(!HAL_STATUS_SUCCESS(status))
2046 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002047 smsLog(pMac, LOGE, FL(" fail to copy memory for scan result"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002048 palFreeMemory(pMac->hHdd, pResult);
2049 if(pNewIes)
2050 {
2051 palFreeMemory(pMac->hHdd, pNewIes);
2052 }
2053 break;
2054 }
2055 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2056 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2057 {
2058 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2059 }
2060 else
2061 {
2062 //To sort the list
2063 tListElem *pTmpEntry;
2064 tCsrScanResult *pTmpResult;
2065
2066 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2067 while(pTmpEntry)
2068 {
2069 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2070 if(csrIsBetterBss(pResult, pTmpResult))
2071 {
2072 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2073 //To indicate we are done
2074 pResult = NULL;
2075 break;
2076 }
2077 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2078 }
2079 if(pResult != NULL)
2080 {
2081 //This one is not better than any one
2082 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2083 }
2084 }
2085 count++;
2086 }
2087 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2088 }//while
2089 csrLLUnlock(&pMac->scan.scanResultList);
2090
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002091 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002092
2093 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2094 {
2095 //Fail or No one wants the result.
2096 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2097 }
2098 else
2099 {
2100 if(0 == count)
2101 {
2102 //We are here meaning the there is no match
2103 csrLLClose(&pRetList->List);
2104 palFreeMemory(pMac->hHdd, pRetList);
2105 status = eHAL_STATUS_E_NULL_VALUE;
2106 }
2107 else if(phResult)
2108 {
2109 *phResult = pRetList;
2110 }
2111 }
2112 }//Allocated pRetList
2113
2114 return (status);
2115}
2116
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002117/*
2118 * NOTE: This routine is being added to make
2119 * sure that scan results are not being flushed
2120 * while roaming. If the scan results are flushed,
2121 * we are unable to recover from
2122 * csrRoamRoamingStateDisassocRspProcessor.
2123 * If it is needed to remove this routine,
2124 * first ensure that we recover gracefully from
2125 * csrRoamRoamingStateDisassocRspProcessor if
2126 * csrScanGetResult returns with a failure because
2127 * of not being able to find the roaming BSS.
2128 */
2129tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2130{
2131 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2132 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2133 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2134 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2135 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2136 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2137 default:
2138 return 0;
2139 }
2140}
2141
Jeff Johnson295189b2012-06-20 16:38:30 -07002142eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2143{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002144 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
2145 if (isFlushDenied) {
2146 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2147 __func__, isFlushDenied);
2148 return eHAL_STATUS_FAILURE;
2149 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002150 return ( csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList) );
2151}
2152
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302153eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002154{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302155 eHalStatus status = eHAL_STATUS_SUCCESS;
2156 tListElem *pEntry,*pFreeElem;
2157 tCsrScanResult *pBssDesc;
2158 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002159
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302160 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002161
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302162 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2163 while( pEntry != NULL)
2164 {
2165 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2166 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2167 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002168 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302169 pFreeElem = pEntry;
2170 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2171 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2172 csrFreeScanResultEntry( pMac, pBssDesc );
2173 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002174 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302175 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2176 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002177
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302178 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002179
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302180 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002181}
2182
Jeff Johnson295189b2012-06-20 16:38:30 -07002183/**
2184 * csrCheck11dChannel
2185 *
2186 *FUNCTION:
2187 * This function is called from csrScanFilter11dResult function and
2188 * compare channel number with given channel list.
2189 *
2190 *LOGIC:
2191 * Check Scan result channel number with CFG channel list
2192 *
2193 *ASSUMPTIONS:
2194 *
2195 *
2196 *NOTE:
2197 *
2198 * @param channelId channel number
2199 * @param pChannelList Pointer to channel list
2200 * @param numChannels Number of channel in channel list
2201 *
2202 * @return Status
2203 */
2204
2205eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2206{
2207 eHalStatus status = eHAL_STATUS_FAILURE;
2208 tANI_U8 i = 0;
2209
2210 for (i = 0; i < numChannels; i++)
2211 {
2212 if(pChannelList[ i ] == channelId)
2213 {
2214 status = eHAL_STATUS_SUCCESS;
2215 break;
2216 }
2217 }
2218 return status;
2219}
2220
2221/**
2222 * csrScanFilter11dResult
2223 *
2224 *FUNCTION:
2225 * This function is called from csrApplyCountryInformation function and
2226 * filter scan result based on valid channel list number.
2227 *
2228 *LOGIC:
2229 * Get scan result from scan list and Check Scan result channel number
2230 * with 11d channel list if channel number is found in 11d channel list
2231 * then do not remove scan result entry from scan list
2232 *
2233 *ASSUMPTIONS:
2234 *
2235 *
2236 *NOTE:
2237 *
2238 * @param pMac Pointer to Global MAC structure
2239 *
2240 * @return Status
2241 */
2242
2243eHalStatus csrScanFilter11dResult(tpAniSirGlobal pMac)
2244{
2245 eHalStatus status = eHAL_STATUS_SUCCESS;
2246 tListElem *pEntry,*pTempEntry;
2247 tCsrScanResult *pBssDesc;
2248 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2249
2250 /* Get valid channels list from CFG */
2251 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2252 pMac->roam.validChannelList, &len)))
2253 {
2254 smsLog( pMac, LOG1, "Failed to get Channel list from CFG");
2255 }
2256
2257 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2258 while( pEntry )
2259 {
2260 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2261 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2262 LL_ACCESS_LOCK );
2263 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2264 pMac->roam.validChannelList, len))
2265 {
2266 /* Remove Scan result which does not have 11d channel */
2267 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2268 LL_ACCESS_LOCK ))
2269 {
2270 csrFreeScanResultEntry( pMac, pBssDesc );
2271 }
2272 }
2273 pEntry = pTempEntry;
2274 }
2275 return status;
2276}
2277
2278
2279eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2280{
2281 eHalStatus status = eHAL_STATUS_SUCCESS;
2282 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2283 tCsrScanResult *pResult, *pScanResult;
2284 tANI_U32 count = 0;
2285 tListElem *pEntry;
2286 tANI_U32 bssLen, allocLen;
2287
2288 if(phResult)
2289 {
2290 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2291 }
2292 status = palAllocateMemory(pMac->hHdd, (void **)&pRetList, sizeof(tScanResultList));
2293 if(HAL_STATUS_SUCCESS(status))
2294 {
2295 palZeroMemory(pMac->hHdd, pRetList, sizeof(tScanResultList));
2296 csrLLOpen(pMac->hHdd, &pRetList->List);
2297 pRetList->pCurEntry = NULL;
2298 csrLLLock(&pMac->scan.scanResultList);
2299 csrLLLock(&pInList->List);
2300
2301 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2302 while( pEntry )
2303 {
2304 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2305 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2306 allocLen = sizeof( tCsrScanResult ) + bssLen;
2307 status = palAllocateMemory(pMac->hHdd, (void **)&pResult, allocLen);
2308 if(!HAL_STATUS_SUCCESS(status))
2309 {
2310 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2311 count = 0;
2312 break;
2313 }
2314 palZeroMemory(pMac->hHdd, pResult, allocLen);
2315 status = palCopyMemory(pMac->hHdd, &pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
2316 if(!HAL_STATUS_SUCCESS(status))
2317 {
2318 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2319 count = 0;
2320 break;
2321 }
2322 if( pScanResult->Result.pvIes )
2323 {
2324 status = palAllocateMemory(pMac->hHdd, (void **)&pResult->Result.pvIes, sizeof( tDot11fBeaconIEs ));
2325 if(!HAL_STATUS_SUCCESS(status))
2326 {
2327 //Free the memory we allocate above first
2328 palFreeMemory( pMac->hHdd, pResult );
2329 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2330 count = 0;
2331 break;
2332 }
2333 status = palCopyMemory(pMac->hHdd, pResult->Result.pvIes,
2334 pScanResult->Result.pvIes, sizeof( tDot11fBeaconIEs ));
2335 if(!HAL_STATUS_SUCCESS(status))
2336 {
2337 //Free the memory we allocate above first
2338 palFreeMemory( pMac->hHdd, pResult );
2339 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2340 count = 0;
2341 break;
2342 }
2343 }
2344 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2345 count++;
2346 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2347 }//while
2348 csrLLUnlock(&pInList->List);
2349 csrLLUnlock(&pMac->scan.scanResultList);
2350
2351 if(HAL_STATUS_SUCCESS(status))
2352 {
2353 if(0 == count)
2354 {
2355 csrLLClose(&pRetList->List);
2356 palFreeMemory(pMac->hHdd, pRetList);
2357 status = eHAL_STATUS_E_NULL_VALUE;
2358 }
2359 else if(phResult)
2360 {
2361 *phResult = pRetList;
2362 }
2363 }
2364 }//Allocated pRetList
2365
2366 return (status);
2367}
2368
2369
2370
2371eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2372{
2373 eHalStatus status = eHAL_STATUS_SUCCESS;
2374 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2375
2376 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2377 {
2378 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2379 }
2380 else
2381 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002382 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002383 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002384 tCsrRoamSession *pSession;
2385 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2386 tCsrRoamInfo roamInfo;
2387 tCsrRoamInfo *pRoamInfo = NULL;
2388 tANI_U32 sessionId;
2389 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002390 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002391 palZeroMemory(pMac->hHdd, &roamInfo, sizeof(tCsrRoamInfo));
2392 pRoamInfo = &roamInfo;
2393 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2394 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2395 pSession = CSR_GET_SESSION(pMac, sessionId);
2396
2397 if(!pSession)
2398 {
2399 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2400 return eHAL_STATUS_FAILURE;
2401 }
2402
2403 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2404 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2405 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2406 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2407 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2408 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2409 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
2410 palCopyMemory(pMac->hHdd, pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2411 palCopyMemory(pMac->hHdd, &pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
2412 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2413 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2414 {
2415 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2416 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2417 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2418 }
2419 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2420 {
2421 vos_sleep( 100 );
2422 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2423 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2424 }
2425
Jeff Johnson295189b2012-06-20 16:38:30 -07002426 }
2427 else
2428 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002429
2430 if( csrIsAnySessionInConnectState( pMac ) )
2431 {
2432 //In case of we are connected, we need to check whether connect status changes
2433 //because scan may also run while connected.
2434 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2435 }
2436 else
2437 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002438 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002439 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002440 }
2441 }
2442
2443 return (status);
2444}
2445
2446
2447
2448void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2449{
2450 int idx, len;
2451 tANI_U8 *pbIe;
2452
2453 //If failed to remove, assuming someone else got it.
2454 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2455 (0 == pNewBssDescr->WscIeLen))
2456 {
2457 idx = 0;
2458 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2459 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2460 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2461 //Save WPS IE if it exists
2462 pNewBssDescr->WscIeLen = 0;
2463 while(idx < len)
2464 {
2465 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2466 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2467 {
2468 //Founrd it
2469 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2470 {
2471 palCopyMemory(pMac->hHdd, pNewBssDescr->WscIeProbeRsp,
2472 pbIe, pbIe[1] + 2);
2473 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2474 }
2475 break;
2476 }
2477 idx += pbIe[1] + 2;
2478 pbIe += pbIe[1] + 2;
2479 }
2480 }
2481}
2482
2483
2484
2485//pIes may be NULL
2486tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
2487 tDot11fBeaconIEs *pIes, tAniSSID *pSsid , v_TIME_t *timer )
2488{
2489 tListElem *pEntry;
2490
2491 tCsrScanResult *pBssDesc;
2492 tANI_BOOLEAN fRC = FALSE;
2493
2494 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2495 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2496 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2497 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2498
2499 while( pEntry )
2500 {
2501 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2502
2503 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2504 // matches
2505 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
2506 pSirBssDescr, pIes ) )
2507 {
2508 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2509 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2510 // Remove the 'old' entry from the list....
2511 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2512 {
2513 // !we need to free the memory associated with this node
2514 //If failed to remove, assuming someone else got it.
2515 *pSsid = pBssDesc->Result.ssId;
2516 *timer = pBssDesc->Result.timer;
2517 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2518
2519 csrFreeScanResultEntry( pMac, pBssDesc );
2520 }
2521 else
2522 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002523 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002524 }
2525 fRC = TRUE;
2526
2527 // If we found a match, we can stop looking through the list.
2528 break;
2529 }
2530
2531 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2532 }
2533
2534 return fRC;
2535}
2536
2537
2538eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2539 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2540{
2541 eHalStatus status = eHAL_STATUS_FAILURE;
2542 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2543
Jeff Johnson32d95a32012-09-10 13:15:23 -07002544 if(!pSession)
2545 {
2546 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2547 return eHAL_STATUS_FAILURE;
2548 }
2549
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002550 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002551 if( pIes )
2552 {
2553 // check if this is a RSN BSS
2554 if( pIes->RSN.present )
2555 {
2556 // Check if the BSS is capable of doing pre-authentication
2557 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2558 {
2559
2560#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2561 {
2562 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
2563 palZeroMemory(pMac->hHdd, &secEvent, sizeof(vos_event_wlan_security_payload_type));
2564 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2565 secEvent.encryptionModeMulticast =
2566 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2567 secEvent.encryptionModeUnicast =
2568 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
2569 palCopyMemory( pMac->hHdd, secEvent.bssid, pSession->connectedProfile.bssid, 6 );
2570 secEvent.authMode =
2571 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2572 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2573 }
2574#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2575
2576 // if yes, then add to PMKIDCandidateList
2577 status = palCopyMemory(pMac->hHdd, pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2578 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2579
2580 if( HAL_STATUS_SUCCESS( status ) )
2581 {
Venkata Prathyusha Kuntupalliea7098e2013-01-31 16:08:13 -08002582 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 ) // Bit 0 offirst byte - PreAuthentication Capability
Jeff Johnson295189b2012-06-20 16:38:30 -07002583 {
2584 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported = eANI_BOOLEAN_TRUE;
2585 }
2586 else
2587 {
2588 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported = eANI_BOOLEAN_FALSE;
2589 }
2590 pSession->NumPmkidCandidate++;
2591 }
2592 }
2593 else
2594 {
2595 status = eHAL_STATUS_FAILURE;
2596 }
2597 }
2598 }
2599
2600 return (status);
2601}
2602
2603//This function checks whether new AP is found for the current connected profile
2604//If it is found, it return the sessionId, else it return invalid sessionID
2605tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2606 tSirBssDescription *pBssDesc,
2607 tDot11fBeaconIEs *pIes)
2608{
2609 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2610 tCsrRoamSession *pSession;
2611 tDot11fBeaconIEs *pIesLocal = pIes;
2612
2613 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2614 {
2615 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2616 {
2617 if( CSR_IS_SESSION_VALID( pMac, i ) )
2618 {
2619 pSession = CSR_GET_SESSION( pMac, i );
2620 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2621 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2622 {
2623 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2624 {
2625 //this new BSS fits the current profile connected
2626 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2627 {
2628 bRet = i;
2629 }
2630 break;
2631 }
2632 }
2633 }
2634 }
2635 if( !pIes )
2636 {
2637 palFreeMemory(pMac->hHdd, pIesLocal);
2638 }
2639 }
2640
2641 return (tANI_U8)bRet;
2642}
2643
2644#ifdef FEATURE_WLAN_WAPI
2645eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2646 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2647{
2648 eHalStatus status = eHAL_STATUS_FAILURE;
2649 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2650
Jeff Johnson32d95a32012-09-10 13:15:23 -07002651 if(!pSession)
2652 {
2653 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2654 return eHAL_STATUS_FAILURE;
2655 }
2656
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002657 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002658 if( pIes )
2659 {
2660 // check if this is a WAPI BSS
2661 if( pIes->WAPI.present )
2662 {
2663 // Check if the BSS is capable of doing pre-authentication
2664 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
2665 {
2666
2667 // if yes, then add to BKIDCandidateList
2668 status = palCopyMemory(pMac->hHdd, pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
2669 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2670
2671 if( HAL_STATUS_SUCCESS( status ) )
2672 {
2673 if ( pIes->WAPI.preauth )
2674 {
2675 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported = eANI_BOOLEAN_TRUE;
2676 }
2677 else
2678 {
2679 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported = eANI_BOOLEAN_FALSE;
2680 }
2681 pSession->NumBkidCandidate++;
2682 }
2683 }
2684 else
2685 {
2686 status = eHAL_STATUS_FAILURE;
2687 }
2688 }
2689 }
2690
2691 return (status);
2692}
2693
2694//This function checks whether new AP is found for the current connected profile
2695//if so add to BKIDCandidateList
2696tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
2697 tDot11fBeaconIEs *pIes)
2698{
2699 tANI_BOOLEAN fRC = FALSE;
2700 tDot11fBeaconIEs *pIesLocal = pIes;
2701 tANI_U32 sessionId;
2702 tCsrRoamSession *pSession;
2703
2704 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2705 {
2706 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
2707 {
2708 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
2709 {
2710 pSession = CSR_GET_SESSION( pMac, sessionId );
2711 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
2712 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
2713 {
2714 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
2715 {
2716 //this new BSS fits the current profile connected
2717 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
2718 {
2719 fRC = TRUE;
2720 }
2721 }
2722 }
2723 }
2724 }
2725 if(!pIes)
2726 {
2727 palFreeMemory(pMac->hHdd, pIesLocal);
2728 }
2729
2730 }
2731 return fRC;
2732}
2733
2734#endif
2735
2736
2737static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac )
2738{
2739 tListElem *pEntry;
2740 tCsrScanResult *pBssDescription;
2741 tANI_S8 cand_Bss_rssi;
2742 tANI_BOOLEAN fDupBss;
2743#ifdef FEATURE_WLAN_WAPI
2744 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
2745#endif /* FEATURE_WLAN_WAPI */
2746 tDot11fBeaconIEs *pIesLocal = NULL;
2747 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
2748 tAniSSID tmpSsid;
2749 v_TIME_t timer=0;
2750
2751 tmpSsid.length = 0;
2752 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
2753
2754 // remove the BSS descriptions from temporary list
2755 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
2756 {
2757 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2758
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002759 smsLog( pMac, LOGW, "...Bssid= %02x-%02x-%02x-%02x-%02x-%02x chan= %d, rssi = -%d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002760 pBssDescription->Result.BssDescriptor.bssId[ 0 ], pBssDescription->Result.BssDescriptor.bssId[ 1 ],
2761 pBssDescription->Result.BssDescriptor.bssId[ 2 ], pBssDescription->Result.BssDescriptor.bssId[ 3 ],
2762 pBssDescription->Result.BssDescriptor.bssId[ 4 ], pBssDescription->Result.BssDescriptor.bssId[ 5 ],
2763 pBssDescription->Result.BssDescriptor.channelId,
2764 pBssDescription->Result.BssDescriptor.rssi * (-1) );
2765
2766 //At this time, pBssDescription->Result.pvIes may be NULL
2767 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
2768 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
2769 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002770 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002771 csrFreeScanResultEntry(pMac, pBssDescription);
2772 continue;
2773 }
2774 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid , &timer );
2775 //Check whether we have reach out limit
2776 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
2777 {
2778 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002779 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002780 //Free the resources
2781 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2782 {
2783 palFreeMemory(pMac->hHdd, pIesLocal);
2784 }
2785 csrFreeScanResultEntry(pMac, pBssDescription);
2786 //Continue because there may be duplicated BSS
2787 continue;
2788 }
2789 // check for duplicate scan results
2790 if ( !fDupBss )
2791 {
2792 //Found a new BSS
2793 sessionId = csrProcessBSSDescForPMKIDList(pMac,
2794 &pBssDescription->Result.BssDescriptor, pIesLocal);
2795 if( CSR_SESSION_ID_INVALID != sessionId)
2796 {
2797 csrRoamCallCallback(pMac, sessionId, NULL, 0,
2798 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
2799 }
2800 }
2801 else
2802 {
2803 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
2804 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
2805 {
2806 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
2807 //if diff of saved SSID time and current time is less than 1 min to avoid
2808 //side effect of saving SSID with old one is that if AP changes its SSID while remain
2809 //hidden, we may never see it and also to address the requirement of
2810 //When we remove hidden ssid from the profile i.e., forget the SSID via
2811 // GUI that SSID shouldn't see in the profile
2812 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
2813 {
2814 pBssDescription->Result.timer = timer;
2815 pBssDescription->Result.ssId = tmpSsid;
2816 }
2817 }
2818 }
2819
2820 //Tush: find a good AP for 11d info
2821 if( csrIs11dSupported( pMac ) )
2822 {
2823 if(cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
2824 {
2825 // check if country information element is present
2826 if(pIesLocal->Country.present)
2827 {
2828 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
2829 // learn country information
2830 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
2831 pIesLocal, eANI_BOOLEAN_FALSE );
2832 }
2833
2834 }
2835 }
2836
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08002837
Jeff Johnson295189b2012-06-20 16:38:30 -07002838 // append to main list
2839 csrScanAddResult(pMac, pBssDescription, pIesLocal);
2840 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2841 {
2842 palFreeMemory(pMac->hHdd, pIesLocal);
2843 }
2844 }
2845
2846 //Tush: If we can find the current 11d info in any of the scan results, or
2847 // a good enough AP with the 11d info from the scan results then no need to
2848 // get into ambiguous state
2849 if(pMac->scan.fAmbiguous11dInfoFound)
2850 {
2851 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
2852 {
2853 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
2854 }
2855 }
2856
2857#ifdef FEATURE_WLAN_WAPI
2858 if(fNewWapiBSSForCurConnection)
2859 {
2860 //remember it first
2861 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
2862 }
2863#endif /* FEATURE_WLAN_WAPI */
2864
2865 return;
2866}
2867
2868
2869static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
2870 tDot11fBeaconIEs *pIes)
2871{
2872 tCsrScanResult *pCsrBssDescription = NULL;
2873 tANI_U32 cbBSSDesc;
2874 tANI_U32 cbAllocated;
2875 eHalStatus halStatus;
2876
2877 // figure out how big the BSS description is (the BSSDesc->length does NOT
2878 // include the size of the length field itself).
2879 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
2880
2881 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
2882
2883 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pCsrBssDescription, cbAllocated );
2884 if ( HAL_STATUS_SUCCESS(halStatus) )
2885 {
2886 palZeroMemory( pMac->hHdd, pCsrBssDescription, cbAllocated );
2887 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
2888 palCopyMemory(pMac->hHdd, &pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
2889#if defined(VOSS_ENSBALED)
2890 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
2891#endif
2892 csrScanAddResult(pMac, pCsrBssDescription, pIes);
2893 }
2894
2895 return( pCsrBssDescription );
2896}
2897
2898// Append a Bss Description...
2899tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
2900 tSirBssDescription *pSirBssDescription,
2901 tDot11fBeaconIEs *pIes )
2902{
2903 tCsrScanResult *pCsrBssDescription = NULL;
2904 tAniSSID tmpSsid;
2905 v_TIME_t timer = 0;
2906 int result;
2907
2908 tmpSsid.length = 0;
2909 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer );
2910 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
2911 if (result && (pCsrBssDescription != NULL))
2912 {
2913 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
2914 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
2915 {
2916 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
2917 //if diff of saved SSID time and current time is less than 1 min to avoid
2918 //side effect of saving SSID with old one is that if AP changes its SSID while remain
2919 //hidden, we may never see it and also to address the requirement of
2920 //When we remove hidden ssid from the profile i.e., forget the SSID via
2921 // GUI that SSID shouldn't see in the profile
2922 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
2923 {
2924 pCsrBssDescription->Result.ssId = tmpSsid;
2925 pCsrBssDescription->Result.timer = timer;
2926 }
2927 }
2928 }
2929
2930
2931 return( pCsrBssDescription );
2932}
2933
2934
2935
2936void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
2937{
2938 tCsrChannelPowerInfo *pChannelSet;
2939 tListElem *pEntry;
2940
2941 csrLLLock(pChannelList);
2942 // Remove the channel sets from the learned list and put them in the free list
2943 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
2944 {
2945 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
2946 if( pChannelSet )
2947 {
2948 palFreeMemory( pMac->hHdd, pChannelSet );
2949 }
2950 }
2951 csrLLUnlock(pChannelList);
2952 return;
2953}
2954
2955
2956/*
2957 * Save the channelList into the ultimate storage as the final stage of channel
2958 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
2959 */
Jeff Johnsone7245742012-09-05 17:12:55 -07002960eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07002961{
2962 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
2963 tSirMacChanInfo *pChannelInfo;
2964 tCsrChannelPowerInfo *pChannelSet;
2965 tANI_BOOLEAN f2GHzInfoFound = FALSE;
2966 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
2967 eHalStatus halStatus;
2968
2969 pChannelInfo = channelTable;
2970 // atleast 3 bytes have to be remaining -- from "countryString"
2971 while ( i-- )
2972 {
2973 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pChannelSet, sizeof(tCsrChannelPowerInfo) );
2974 if ( eHAL_STATUS_SUCCESS == halStatus )
2975 {
2976 palZeroMemory(pMac->hHdd, pChannelSet, sizeof(tCsrChannelPowerInfo));
2977 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
2978 pChannelSet->numChannels = pChannelInfo->numChannels;
2979
2980 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07002981 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07002982 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07002983
Jeff Johnson295189b2012-06-20 16:38:30 -07002984 {
2985 pChannelSet->interChannelOffset = 1;
2986 f2GHzInfoFound = TRUE;
2987 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002988 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07002989 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002990 {
2991 pChannelSet->interChannelOffset = 4;
2992 f2GHzInfoFound = FALSE;
2993 }
Jeff Johnsone7245742012-09-05 17:12:55 -07002994 else
2995 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07002996 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07002997 pChannelSet->firstChannel);
2998 palFreeMemory(pMac->hHdd, pChannelSet);
2999 return eHAL_STATUS_FAILURE;
3000 }
3001
Jeff Johnson295189b2012-06-20 16:38:30 -07003002 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3003
3004 if( f2GHzInfoFound )
3005 {
3006 if( !f2GListPurged )
3007 {
3008 // purge previous results if found new
3009 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3010 f2GListPurged = TRUE;
3011 }
3012
3013 if(CSR_IS_OPERATING_BG_BAND(pMac))
3014 {
3015 // add to the list of 2.4 GHz channel sets
3016 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3017 }
3018 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003019 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003020 pChannelSet->firstChannel);
3021 palFreeMemory(pMac->hHdd, pChannelSet);
3022 }
3023 }
3024 else
3025 {
3026 // 5GHz info found
3027 if( !f5GListPurged )
3028 {
3029 // purge previous results if found new
3030 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3031 f5GListPurged = TRUE;
3032 }
3033
3034 if(CSR_IS_OPERATING_A_BAND(pMac))
3035 {
3036 // add to the list of 5GHz channel sets
3037 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3038 }
3039 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003040 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003041 pChannelSet->firstChannel);
3042 palFreeMemory(pMac->hHdd, pChannelSet);
3043 }
3044 }
3045 }
3046
3047 pChannelInfo++; // move to next entry
3048 }
3049
Jeff Johnsone7245742012-09-05 17:12:55 -07003050 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003051}
3052
3053
3054
3055void csrApplyPower2Current( tpAniSirGlobal pMac )
3056{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003057 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003058 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3059 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3060}
3061
3062
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003063void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003064{
3065 int i;
3066 eNVChannelEnabledType channelEnabledType;
3067 tANI_U8 numChannels = 0;
3068 tANI_U8 tempNumChannels = 0;
3069 tCsrChannel ChannelList;
3070 if( pChannelList->numChannels )
3071 {
3072 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3073 /* If user doesn't want to scan the DFS channels lets trim them from
3074 the valid channel list*/
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003075 for(i = 0; i< tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003076 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003077 if(FALSE == pMac->scan.fEnableDFSChnlScan)
3078 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003079 channelEnabledType =
3080 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003081 }
3082 else
3083 {
3084 channelEnabledType = NV_CHANNEL_ENABLE;
3085 }
3086 if( NV_CHANNEL_ENABLE == channelEnabledType)
3087 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08003088 // Ignore the channel 165 for the country INDONESIA
Madan Mohan Koyyalamudi895cdee2012-11-06 19:13:19 -08003089 if (( pChannelList->channelList[i] == 165 )
3090 && ( pMac->scan.fIgnore_chan165 == VOS_TRUE )
3091 && vos_mem_compare(countryCode, "ID", VOS_COUNTRY_CODE_LEN ))
Jeff Johnson295189b2012-06-20 16:38:30 -07003092 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003093 continue;
3094 }
3095 else
3096 {
3097 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
Jeff Johnson295189b2012-06-20 16:38:30 -07003098 numChannels++;
3099 }
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003100 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003101 }
Srikant Kuppa866893f2012-12-27 17:28:14 -08003102 ChannelList.numChannels = numChannels;
3103
Jeff Johnson295189b2012-06-20 16:38:30 -07003104 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3105 // extend scan capability
3106 csrSetCfgScanControlList(pMac, countryCode, &ChannelList); // build a scan list based on the channel list : channel# + active/passive scan
3107#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003108 if (updateRiva)
3109 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003110 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003111 // Send HAL UpdateScanParams message
3112 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3113 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003114#endif // FEATURE_WLAN_SCAN_PNO
3115 }
3116 else
3117 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003118 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003119 }
3120 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3121 csrSetCfgCountryCode(pMac, countryCode);
3122}
3123
3124
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003125void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003126{
3127 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3128 {
3129
3130#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3131 {
3132 vos_log_802_11d_pkt_type *p11dLog;
3133 int Index;
3134
3135 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3136 if(p11dLog)
3137 {
3138 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
3139 palCopyMemory(pMac->hHdd, p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
3140 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3141 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3142 {
3143 palCopyMemory(pMac->hHdd, p11dLog->Channels, pMac->scan.base20MHzChannels.channelList,
3144 p11dLog->numChannel);
3145 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3146 {
3147 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3148 }
3149 }
3150 if(!pMac->roam.configParam.Is11dSupportEnabled)
3151 {
3152 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3153 }
3154 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3155 {
3156 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3157 }
3158 else
3159 {
3160 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3161 }
3162 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3163 }
3164 }
3165#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3166
3167 // switch to passive scans only when 11d is enabled
3168 if( csrIs11dSupported( pMac ) )
3169 {
3170 pMac->scan.curScanType = eSIR_PASSIVE_SCAN;
3171 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003172
3173 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3174 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3175
Jeff Johnson295189b2012-06-20 16:38:30 -07003176 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3177 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3178 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003179 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003180 // clear the 11d channel list
3181 palZeroMemory( pMac->hHdd, &pMac->scan.channels11d, sizeof(pMac->scan.channels11d) );
3182 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3183 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3184 }
3185
3186 return;
3187}
3188
3189
3190eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3191{
3192 eHalStatus status = eHAL_STATUS_SUCCESS;
3193 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3194
3195 //Use the Country code and domain from EEPROM
3196 palCopyMemory(pMac->hHdd, pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault, WNI_CFG_COUNTRY_CODE_LEN);
3197 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003198 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3199 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003200 {
3201 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003202 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003203 }
3204 if(pfRestartNeeded)
3205 {
3206 *pfRestartNeeded = fRestart;
3207 }
3208
3209 return (status);
3210}
3211
3212
3213eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3214{
3215 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3216 v_REGDOMAIN_t domainId;
3217
3218 if(pCountry)
3219 {
3220 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId);
3221 if(HAL_STATUS_SUCCESS(status))
3222 {
3223 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3224 if(HAL_STATUS_SUCCESS(status))
3225 {
3226 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3227 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
3228 palCopyMemory(pMac->hHdd, pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
3229 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3230 {
3231 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3232 csrSetCfgCountryCode(pMac, pCountry);
3233 }
3234 }
3235 }
3236 }
3237
3238 return (status);
3239}
3240
3241
3242
3243//caller allocated memory for pNumChn and pChnPowerInfo
3244//As input, *pNumChn has the size of the array of pChnPowerInfo
3245//Upon return, *pNumChn has the number of channels assigned.
3246void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3247 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3248{
3249 tListElem *pEntry;
3250 tANI_U32 chnIdx = 0, idx;
3251 tCsrChannelPowerInfo *pChannelSet;
3252
3253 //Get 2.4Ghz first
3254 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3255 while( pEntry && (chnIdx < *pNumChn) )
3256 {
3257 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3258 if ( 1 != pChannelSet->interChannelOffset )
3259 {
3260 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3261 {
3262 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3263 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3264 }
3265 }
3266 else
3267 {
3268 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3269 {
3270 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3271 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3272 }
3273 }
3274
3275 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3276 }
3277 *pNumChn = chnIdx;
3278
3279 return ;
3280}
3281
3282
3283
3284void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3285{
3286 v_REGDOMAIN_t domainId;
3287 eHalStatus status = eHAL_STATUS_SUCCESS;
3288
3289 do
3290 {
3291 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3292 if( pMac->scan.fAmbiguous11dInfoFound )
3293 {
3294 // ambiguous info found
3295 //Restore te default domain as well
3296 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCodeCurrent, &domainId )))
3297 {
3298 pMac->scan.domainIdCurrent = domainId;
3299 }
3300 else
3301 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003302 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003303 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3304 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003305 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003306 break;
3307 }
3308 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
3309 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCode11d, &domainId )))
3310 {
3311 //Check whether we need to enforce default domain
3312 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3313 (pMac->scan.domainIdCurrent == domainId) )
3314 {
3315
3316#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3317 {
3318 vos_log_802_11d_pkt_type *p11dLog;
3319 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3320 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3321
3322 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3323 if(p11dLog)
3324 {
3325 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
3326 palCopyMemory(pMac->hHdd, p11dLog->countryCode, pMac->scan.countryCode11d, 3);
3327 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3328 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3329 {
3330 palCopyMemory(pMac->hHdd, p11dLog->Channels, pMac->scan.channels11d.channelList,
3331 p11dLog->numChannel);
3332 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3333 &nChnInfo, chnPwrInfo);
3334 nTmp = nChnInfo;
3335 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3336 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3337 &nChnInfo, &chnPwrInfo[nTmp]);
3338 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3339 {
3340 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3341 {
3342 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3343 {
3344 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3345 break;
3346 }
3347 }
3348 }
3349 }
3350 if(!pMac->roam.configParam.Is11dSupportEnabled)
3351 {
3352 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3353 }
3354 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3355 {
3356 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3357 }
3358 else
3359 {
3360 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3361 }
3362 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3363 }
3364 }
3365#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3366 if(pMac->scan.domainIdCurrent != domainId)
3367 {
3368 /* Regulatory Domain Changed, Purge Only scan result
3369 * which does not have channel number belong to 11d
3370 * channel list
3371 * */
3372 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3373 pMac->scan.domainIdCurrent, domainId);
3374 csrScanFilter11dResult(pMac);
3375 }
3376 status = WDA_SetRegDomain(pMac, domainId);
3377 if (status != eHAL_STATUS_SUCCESS)
3378 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003379 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003380 }
3381 pMac->scan.domainIdCurrent = domainId;
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003382 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.channels11d, pMac->scan.countryCode11d, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003383 // switch to active scans using this new channel list
3384 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3385 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3386 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3387 }
3388 }
3389
3390 } while( 0 );
3391
3392 return;
3393}
3394
3395
3396
3397tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3398 tANI_BOOLEAN fForce)
3399{
3400 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3401 tANI_U32 i;
3402
3403 // convert to UPPER here so we are assured the strings are always in upper case.
3404 for( i = 0; i < 3; i++ )
3405 {
3406 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3407 }
3408
3409 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3410 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3411 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3412 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3413 // 11d information element, let's default to US.
3414 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pCountryCode, NULL ) ) )
3415 {
3416 // Check the enforcement first
3417 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3418 {
3419 fUnknownCountryCode = TRUE;
3420 }
3421 else
3422 {
3423 pCountryCode[ 0 ] = 'U';
3424 pCountryCode[ 1 ] = 'S';
3425 }
3426 }
3427
3428 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3429 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3430 // if we see a 0 in this third character, let's change it to a ' '.
3431 if ( 0 == pCountryCode[ 2 ] )
3432 {
3433 pCountryCode[ 2 ] = ' ';
3434 }
3435
3436 if( !fUnknownCountryCode )
3437 {
3438 fCountryStringChanged = (!palEqualMemory( pMac->hHdd,
3439 pMac->scan.countryCode11d, pCountryCode, 2));
3440
3441
3442 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3443 || (fForce))
3444 {
3445 // this is the first .11d information
3446 palCopyMemory( pMac->hHdd, pMac->scan.countryCode11d, pCountryCode, sizeof( pMac->scan.countryCode11d ) );
3447 }
3448 }
3449
3450 return( fCountryStringChanged );
3451}
3452
3453
3454void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3455{
3456 tANI_U32 Index, count=0;
3457 tSirMacChanInfo *pChanInfo;
3458 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003459 tANI_S32 maxChannelIndex;
3460
3461 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3462 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003463
3464 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN)))
3465 {
3466 palZeroMemory(pMac->hHdd, pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3467 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003468 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003469 {
3470 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3471 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3472 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003473 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3474 {
3475 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3476 break;
3477 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003478 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3479 pChanInfo->numChannels = 1;
3480 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3481 pChanInfo++;
3482 count++;
3483 }
3484 }
3485 if(count)
3486 {
3487 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3488 }
3489 palFreeMemory(pMac->hHdd, pChanInfoStart);
3490 }
3491}
3492
3493
3494void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3495{
3496 tANI_BOOLEAN fPopulate5GBand = FALSE;
3497
3498 do
3499 {
3500 // if this is not a dual band product, then we don't need to set the opposite
3501 // band info. We only work in one band so no need to look in the other band.
3502 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3503 // if we found channel info on the 5.0 band and...
3504 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3505 {
3506 // and the 2.4 band is empty, then populate the 2.4 channel info
Jeff Johnson295189b2012-06-20 16:38:30 -07003507 fPopulate5GBand = FALSE;
3508 }
3509 else
3510 {
3511 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3512 // set the 5.0 band info from the 2.4 country code.
Jeff Johnson295189b2012-06-20 16:38:30 -07003513 fPopulate5GBand = TRUE;
3514 }
3515 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3516
3517 } while( 0 );
3518}
3519
3520
3521tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3522{
3523 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3524 tANI_U32 i;
3525
3526 //Make sure it is a channel that is in our supported list.
3527 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3528 {
3529 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3530 {
3531 fRet = eANI_BOOLEAN_TRUE;
3532 break;
3533 }
3534 }
3535
3536 //If it is configured to limit a set of the channels
3537 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3538 {
3539 fRet = eANI_BOOLEAN_FALSE;
3540 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3541 {
3542 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3543 {
3544 fRet = eANI_BOOLEAN_TRUE;
3545 break;
3546 }
3547 }
3548 }
3549
3550 return (fRet);
3551}
3552
3553
3554
3555//bSize specify the buffer size of pChannelList
3556tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3557{
3558 tANI_U8 i, j = 0, chnId;
3559
3560 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3561 for( i = 0; i < bSize; i++ )
3562 {
3563 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3564 if ( csrIsSupportedChannel( pMac, chnId ) )
3565 {
3566 pChannelList[j++] = chnId;
3567 }
3568 }
3569
3570 return (j);
3571}
3572
3573
3574
3575//bSize -- specify the buffer size of pChannelList
3576void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3577 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3578{
3579 tListElem *pEntry;
3580 tCsrChannelPowerInfo *pChannelSet;
3581 tANI_U8 numChannels;
3582 tANI_U8 *pChannels;
3583
3584 if( pChannelSetList && pChannelList && pNumChannels )
3585 {
3586 pChannels = pChannelList;
3587 *pNumChannels = 0;
3588 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3589 while( pEntry )
3590 {
3591 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3592 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3593 pChannels += numChannels;
3594 *pNumChannels += numChannels;
3595 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3596 }
3597 }
3598}
3599
3600
3601/*
3602 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
3603*/
3604tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
3605 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
3606{
3607 tANI_U8 Num2GChannels, bMaxNumChn;
3608 eHalStatus status;
3609 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3610 v_REGDOMAIN_t domainId;
3611 tDot11fBeaconIEs *pIesLocal = pIes;
3612
Jeff Johnson295189b2012-06-20 16:38:30 -07003613 if (VOS_STA_SAP_MODE == vos_get_conparam ())
3614 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003615
3616 do
3617 {
3618 // check if .11d support is enabled
3619 if( !csrIs11dSupported( pMac ) ) break;
3620 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
3621 {
3622 break;
3623 }
3624 // check if country information element is present
3625 if(!pIesLocal->Country.present)
3626 {
3627 //No country info
3628 break;
3629 }
3630
3631 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
3632 {
3633 // country string changed, this should not happen
3634 //Need to check whether we care about this BSS' domain info
3635 //If it doesn't match of the connected profile or roaming profile, let's ignore it
3636 tANI_U32 i;
3637 tCsrRoamSession *pSession;
3638
3639 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3640 {
3641 if( CSR_IS_SESSION_VALID( pMac, i ) )
3642 {
3643 pSession = CSR_GET_SESSION( pMac, i );
3644 if(pSession->pCurRoamProfile)
3645 {
3646 tCsrScanResultFilter filter;
3647
3648 palZeroMemory(pMac->hHdd, &filter, sizeof(tCsrScanResultFilter));
3649 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
3650 if(HAL_STATUS_SUCCESS(status))
3651 {
3652 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
3653 //Free the resource first
3654 csrFreeScanFilter( pMac, &filter );
3655 if(fMatch)
3656 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003657 smsLog(pMac, LOGW, " Matching roam profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003658 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3659 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3660 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3661 break;
3662 }
3663 }
3664 }
3665 else if( csrIsConnStateConnected(pMac, i))
3666 {
3667 //Reach here only when the currention is base on no profile.
3668 //User doesn't give profile and just connect to anything.
3669 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
3670 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003671 smsLog(pMac, LOGW, " Matching connect profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003672 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3673 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3674 //Tush
3675 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3676 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
3677 &pSession->connectedProfile.bssid))
3678 {
3679 //AP changed the 11d info on the fly, modify cfg
3680 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3681 fRet = eANI_BOOLEAN_TRUE;
3682 }
3683 break;
3684 }
3685 }
3686 } //valid session
3687 } //for
3688 if ( i == CSR_ROAM_SESSION_MAX )
3689 {
3690 //Check whether we can use this country's 11d information
3691 if( !pMac->roam.configParam.fEnforceDefaultDomain )
3692 {
3693 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3694 }
3695 else
3696 {
3697 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
3698 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3699 pMac, pIesLocal->Country.country, &domainId )) &&
3700 ( domainId == pMac->scan.domainIdCurrent ) )
3701 {
3702 //Two countries in the same domain
3703 }
3704 }
3705 }
3706 }
3707 else //Tush
3708 {
3709 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
3710 }
3711
3712 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
3713 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
3714 {
3715 tANI_U8 iC;
3716 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
3717
3718 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
3719 {
3720 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
3721 {
3722 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
3723 }
3724 }
3725 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003726 smsLog(pMac, LOG3, FL(" %d sets each one is %d"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07003727 // save the channel/power information from the Channel IE.
3728 //sizeof(tSirMacChanInfo) has to be 3
Jeff Johnsone7245742012-09-05 17:12:55 -07003729 if (eHAL_STATUS_SUCCESS != csrSaveToChannelPower2G_5G( pMac, pIesLocal->Country.num_triplets * sizeof(tSirMacChanInfo),
3730 (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]) ))
3731 {
3732 fRet = eANI_BOOLEAN_FALSE;
3733 return fRet;
3734 }
3735
Jeff Johnson295189b2012-06-20 16:38:30 -07003736 // set the indicator of the channel where the country IE was found...
3737 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07003738 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country, &domainId );
3739 // Checking for Domain Id change
3740 if ( domainId != pMac->scan.domainIdCurrent )
3741 {
3742 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
3743 WDA_SetRegDomain(pMac, domainId);
3744 // Check weather AP provided the 2.4GHZ list or 5GHZ list
3745 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[0].firstChanNum))
3746 {
3747 // AP Provided the 2.4 Channels, Update the 5GHz channels from nv.bin
3748 csrGet5GChannels(pMac );
3749 }
3750 else
3751 {
3752 // AP Provided the 5G Channels, Update the 2.4GHZ channel list from nv.bin
3753 csrGet24GChannels(pMac );
3754 }
3755 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003756 // Populate both band channel lists based on what we found in the country information...
3757 csrSetOppositeBandChannelInfo( pMac );
3758 bMaxNumChn = WNI_CFG_VALID_CHANNEL_LIST_LEN;
3759 // construct 2GHz channel list first
3760 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList24, pMac->scan.channels11d.channelList,
3761 bMaxNumChn, &Num2GChannels );
3762 // construct 5GHz channel list now
3763 if(bMaxNumChn > Num2GChannels)
3764 {
3765 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList5G, pMac->scan.channels11d.channelList + Num2GChannels,
3766 bMaxNumChn - Num2GChannels,
3767 &pMac->scan.channels11d.numChannels );
3768 }
3769
3770 pMac->scan.channels11d.numChannels += Num2GChannels;
3771 fRet = eANI_BOOLEAN_TRUE;
3772
3773 } while( 0 );
3774
3775 if( !pIes && pIesLocal )
3776 {
3777 //locally allocated
3778 palFreeMemory(pMac->hHdd, pIesLocal);
3779 }
3780
3781 return( fRet );
3782}
3783
3784
3785static void csrSaveScanResults( tpAniSirGlobal pMac )
3786{
3787 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
3788 // will set this to the channel where an .11d beacon is seen
3789 pMac->scan.channelOf11dInfo = 0;
3790 // if we get any ambiguous .11d information then this will be set to TRUE
3791 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3792 //Tush
3793 // if we get any ambiguous .11d information, then this will be set to TRUE
3794 // only if the applied 11d info could be found in one of the scan results
3795 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
3796 // move the scan results from interim list to the main scan list
3797 csrMoveTempScanResultsToMainList( pMac );
3798
3799 // Now check if we gathered any domain/country specific information
3800 // If so, we should update channel list and apply Tx power settings
Jeff Johnsone7245742012-09-05 17:12:55 -07003801 if( csrIs11dSupported(pMac) )
3802 {
3803 csrApplyCountryInformation( pMac, FALSE );
3804 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003805}
3806
3807
3808void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
3809{
3810 switch (pCommand->u.scanCmd.reason)
3811 {
3812 case eCsrScanSetBGScanParam:
3813 case eCsrScanAbortBgScan:
3814 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
3815 {
3816 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
3817 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
3818 }
3819 break;
3820 case eCsrScanBGScanAbort:
3821 case eCsrScanBGScanEnable:
3822 case eCsrScanGetScanChnInfo:
3823 break;
3824 case eCsrScanAbortNormalScan:
3825 default:
3826 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
3827 break;
3828 }
3829 if(pCommand->u.scanCmd.pToRoamProfile)
3830 {
3831 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
3832 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.pToRoamProfile);
3833 }
3834 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
3835}
3836
3837
3838tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
3839{
3840 tANI_U32 index11dChannels, index;
3841 tANI_U32 indexCurrentChannels;
3842 tANI_BOOLEAN fChannelAlreadyScanned;
3843 tANI_U32 len = sizeof(pMac->roam.validChannelList);
3844
3845 *pcChannels = 0;
3846 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
3847 {
3848 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
3849 {
3850 //Find the channel index where we found the 11d info
3851 for(index = 0; index < len; index++)
3852 {
3853 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
3854 break;
3855 }
3856 //check whether we found the channel index
3857 if(index < len)
3858 {
3859 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
3860 // NOT in the current channel list. This gives us a list of the new channels that have not been
3861 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
3862 // initially.
3863 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
3864 {
3865 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
3866
3867 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
3868 {
3869 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
3870 {
3871 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
3872 break;
3873 }
3874 }
3875
3876 if ( !fChannelAlreadyScanned )
3877 {
3878 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
3879 ( *pcChannels )++;
3880 }
3881 }
3882 }
3883 }//GetCFG
3884 }
3885 return( *pcChannels );
3886}
3887
3888
3889eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
3890{
3891 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
3892
3893 switch( pCommand->u.scanCmd.reason )
3894 {
3895 case eCsrScan11d1:
3896 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
3897 break;
3898 case eCsrScan11d2:
3899 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
3900 break;
3901 case eCsrScan11dDone:
3902 NextCommand = eCsrNext11dScanComplete;
3903 break;
3904 case eCsrScanLostLink1:
3905 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
3906 break;
3907 case eCsrScanLostLink2:
3908 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
3909 break;
3910 case eCsrScanLostLink3:
3911 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
3912 break;
3913 case eCsrScanForSsid:
3914 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
3915 break;
3916 case eCsrScanForCapsChange:
3917 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
3918 break;
3919 case eCsrScanIdleScan:
3920 NextCommand = eCsrNextIdleScanComplete;
3921 break;
3922 default:
3923 NextCommand = eCsrNextScanNothing;
3924 break;
3925 }
3926 return( NextCommand );
3927}
3928
3929
3930//Return whether the pCommand is finished.
3931tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
3932{
3933 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
3934
3935 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003936 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003937 pCommand->u.scanCmd.reason = eCsrScan11d2;
3938 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
3939 {
3940 fRet = eANI_BOOLEAN_FALSE;
3941 }
3942
3943 return (fRet);
3944}
3945
3946
3947tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
3948{
3949 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
3950 tANI_U8 *pChannels;
3951 tANI_U8 cChannels;
3952
3953 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN)))
3954 {
3955 palZeroMemory(pMac->hHdd, pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3956 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
3957 {
3958 pCommand->u.scanCmd.reason = eCsrScan11dDone;
3959 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
3960 {
3961 palFreeMemory(pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
3962 }
3963 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, cChannels)))
3964 {
3965 palCopyMemory(pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, pChannels, cChannels);
3966 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
3967 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
3968 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
3969 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
3970 {
3971 //Reuse the same command buffer
3972 fRet = eANI_BOOLEAN_FALSE;
3973 }
3974 }
3975 }
3976 palFreeMemory(pMac->hHdd, pChannels);
3977 }
3978
3979 return (fRet);
3980}
3981
3982//Return whether the command should be removed
3983tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
3984{
3985 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
3986 tListElem *pEntry;
3987 tSmeCmd *pCommand;
3988 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
3989 tANI_BOOLEAN fSuccess;
3990
3991 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
3992
3993 if ( pEntry )
3994 {
3995 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
3996
3997 // If the head of the queue is Active and it is a SCAN command, remove
3998 // and put this on the Free queue.
3999 if ( eSmeCommandScan == pCommand->command )
4000 {
4001 tANI_U32 sessionId = pCommand->sessionId;
4002
4003 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4004 {
4005 fSuccess = eANI_BOOLEAN_FALSE;
4006 }
4007 else
4008 {
4009 //pMac->scan.tempScanResults is not empty meaning the scan found something
4010 //This check only valid here because csrSaveScanresults is not yet called
4011 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4012 }
4013 csrSaveScanResults(pMac);
4014
4015#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4016 {
4017 vos_log_scan_pkt_type *pScanLog = NULL;
4018 tScanResultHandle hScanResult;
4019 tCsrScanResultInfo *pScanResult;
4020 tDot11fBeaconIEs *pIes;
4021 int n = 0, c = 0;
4022
4023 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4024 if(pScanLog)
4025 {
4026 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4027 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4028 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4029 {
4030 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4031 }
4032 else
4033 {
4034 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4035 {
4036 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4037 }
4038 else
4039 {
4040 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4041 }
4042 }
4043 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4044 {
4045 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4046 {
4047 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4048 {
4049 if( n < VOS_LOG_MAX_NUM_BSSID )
4050 {
4051 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4052 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004053 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004054 break;
4055 }
4056 palCopyMemory(pMac->hHdd, pScanLog->bssid[n], pScanResult->BssDescriptor.bssId, 6);
4057 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4058 {
4059 palCopyMemory(pMac->hHdd, pScanLog->ssid[n],
4060 pIes->SSID.ssid, pIes->SSID.num_ssid);
4061 }
4062 palFreeMemory(pMac->hHdd, pIes);
4063 n++;
4064 }
4065 c++;
4066 }
4067 pScanLog->numSsid = (v_U8_t)n;
4068 pScanLog->totalSsid = (v_U8_t)c;
4069 csrScanResultPurge(pMac, hScanResult);
4070 }
4071 }
4072 else
4073 {
4074 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4075 }
4076 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4077 }
4078 }
4079#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4080
4081 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4082 //We reuse the command here instead reissue a new command
4083 switch(NextCommand)
4084 {
4085 case eCsrNext11dScan1Success:
4086 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004087 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004088 // if we found country information, no need to continue scanning further, bail out
4089 fRemoveCommand = eANI_BOOLEAN_TRUE;
4090 NextCommand = eCsrNext11dScanComplete;
4091 break;
4092 case eCsrNext11dScan1Failure:
4093 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4094 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4095 //we clear the "old" 11d info and give it once more chance
4096 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4097 if(fRemoveCommand)
4098 {
4099 NextCommand = eCsrNext11dScanComplete;
4100 }
4101 break;
4102 case eCsrNextLostLinkScan1Success:
4103 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4104 {
4105 csrScanHandleFailedLostlink1(pMac, sessionId);
4106 }
4107 break;
4108 case eCsrNextLostLinkScan2Success:
4109 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4110 {
4111 csrScanHandleFailedLostlink2(pMac, sessionId);
4112 }
4113 break;
4114 case eCsrNextLostLinkScan3Success:
4115 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4116 {
4117 csrScanHandleFailedLostlink3(pMac, sessionId);
4118 }
4119 break;
4120 case eCsrNextLostLinkScan1Failed:
4121 csrScanHandleFailedLostlink1(pMac, sessionId);
4122 break;
4123 case eCsrNextLostLinkScan2Failed:
4124 csrScanHandleFailedLostlink2(pMac, sessionId);
4125 break;
4126 case eCsrNextLostLinkScan3Failed:
4127 csrScanHandleFailedLostlink3(pMac, sessionId);
4128 break;
4129 case eCsrNexteScanForSsidSuccess:
4130 csrScanHandleSearchForSSID(pMac, pCommand);
4131 break;
4132 case eCsrNexteScanForSsidFailure:
4133 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4134 break;
4135 case eCsrNextIdleScanComplete:
4136 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4137 break;
4138 case eCsrNextCapChangeScanComplete:
4139 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4140 break;
4141 default:
4142
4143 break;
4144 }
4145 }
4146 else
4147 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004148 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004149 fRemoveCommand = eANI_BOOLEAN_FALSE;
4150 }
4151 }
4152 else
4153 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004154 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004155 fRemoveCommand = eANI_BOOLEAN_FALSE;
4156 }
4157
4158 return( fRemoveCommand );
4159}
4160
4161
4162
4163static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4164 tSirBssDescription *pSirBssDescr,
4165 tDot11fBeaconIEs *pIes)
4166{
4167 tListElem *pEntry;
4168 tCsrScanResult *pCsrBssDescription;
4169
4170 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4171 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4172 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4173 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4174 while( pEntry )
4175 {
4176 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4177
4178 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4179 // matches
4180
4181 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
4182 pSirBssDescr, pIes ) )
4183 {
4184 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4185 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4186
4187 // Remove the 'old' entry from the list....
4188 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4189 {
4190 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4191 // we need to free the memory associated with this node
4192 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4193 }
4194
4195 // If we found a match, we can stop looking through the list.
4196 break;
4197 }
4198
4199 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4200 }
4201}
4202
4203
4204
4205//Caller allocated memory pfNewBssForConn to return whether new candidate for
4206//current connection is found. Cannot be NULL
4207tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4208 tSirBssDescription *pBSSDescription,
4209 tDot11fBeaconIEs *pIes)
4210{
4211 tCsrScanResult *pCsrBssDescription = NULL;
4212 tANI_U32 cbBSSDesc;
4213 tANI_U32 cbAllocated;
4214 eHalStatus halStatus;
4215
4216 // figure out how big the BSS description is (the BSSDesc->length does NOT
4217 // include the size of the length field itself).
4218 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4219
4220 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4221
4222 halStatus = palAllocateMemory( pMac->hHdd, (void **)&pCsrBssDescription, cbAllocated );
4223 if ( HAL_STATUS_SUCCESS(halStatus) )
4224 {
4225 palZeroMemory(pMac->hHdd, pCsrBssDescription, cbAllocated);
4226 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
4227 palCopyMemory(pMac->hHdd, &pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
4228 //Save SSID separately for later use
4229 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4230 {
4231 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004232 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004233 if (len > SIR_MAC_MAX_SSID_LENGTH)
4234 {
4235 // truncate to fit in our struct
4236 len = SIR_MAC_MAX_SSID_LENGTH;
4237 }
4238 pCsrBssDescription->Result.ssId.length = len;
4239 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
4240 palCopyMemory(pMac->hHdd, pCsrBssDescription->Result.ssId.ssId,
4241 pIes->SSID.ssid, len );
4242 }
4243 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4244 }
4245
4246 return( pCsrBssDescription );
4247}
4248
4249
4250
4251
4252tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
4253 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2 )
4254{
4255 tANI_BOOLEAN fMatch = FALSE;
4256 tSirMacCapabilityInfo *pCap1, *pCap2;
4257 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004258 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004259
4260 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4261 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4262 if(pCap1->ess == pCap2->ess)
4263 {
4264 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004265 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
4266 (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
Jeff Johnson295189b2012-06-20 16:38:30 -07004267 {
4268 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004269 // Check for SSID match, if exists
4270 do
4271 {
4272 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4273 {
4274 break;
4275 }
4276 if( NULL == pIesTemp )
4277 {
4278 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4279 {
4280 break;
4281 }
4282 }
4283 if(pIes1->SSID.present && pIesTemp->SSID.present)
4284 {
4285 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4286 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4287 }
4288 }while(0);
4289
Jeff Johnson295189b2012-06-20 16:38:30 -07004290 }
4291 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4292 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004293
4294 do
4295 {
4296 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4297 {
4298 break;
4299 }
4300 if( NULL == pIesTemp )
4301 {
4302 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4303 {
4304 break;
4305 }
4306 }
4307 //Same channel cannot have same SSID for different IBSS
4308 if(pIes1->SSID.present && pIesTemp->SSID.present)
4309 {
4310 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4311 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4312 }
4313 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004314 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004315 /* In case of P2P devices, ess and ibss will be set to zero */
4316 else if (!pCap1->ess &&
4317 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4318 {
4319 fMatch = TRUE;
4320 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004321 }
4322
4323 if(pIes1)
4324 {
4325 palFreeMemory(pMac->hHdd, pIes1);
4326 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004327
4328 if( (NULL == pIes2) && pIesTemp )
4329 {
4330 //locally allocated
4331 palFreeMemory(pMac->hHdd, pIesTemp);
4332 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004333
4334 return( fMatch );
4335}
4336
4337
4338tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4339{
4340 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4341}
4342
4343
4344//to check whether the BSS matches the dot11Mode
4345static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4346 tDot11fBeaconIEs *pIes)
4347{
4348 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4349 eCsrPhyMode phyMode;
4350
4351 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4352 {
4353 switch(pMac->roam.configParam.phyMode)
4354 {
4355 case eCSR_DOT11_MODE_11b:
4356 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4357 break;
4358 case eCSR_DOT11_MODE_11g:
4359 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4360 break;
4361 case eCSR_DOT11_MODE_11g_ONLY:
4362 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4363 break;
4364 case eCSR_DOT11_MODE_11a:
4365 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4366 break;
4367 case eCSR_DOT11_MODE_11n_ONLY:
4368 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4369 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004370
4371#ifdef WLAN_FEATURE_11AC
4372 case eCSR_DOT11_MODE_11ac_ONLY:
4373 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4374 break;
4375#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004376 case eCSR_DOT11_MODE_11b_ONLY:
4377 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4378 break;
4379 case eCSR_DOT11_MODE_11a_ONLY:
4380 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4381 break;
4382 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004383#ifdef WLAN_FEATURE_11AC
4384 case eCSR_DOT11_MODE_11ac:
4385#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004386 case eCSR_DOT11_MODE_TAURUS:
4387 default:
4388 fAllowed = eANI_BOOLEAN_TRUE;
4389 break;
4390 }
4391 }
4392
4393 return (fAllowed);
4394}
4395
4396
4397
4398//Return pIes to caller for future use when returning TRUE.
4399static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4400 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4401 tDot11fBeaconIEs **ppIes )
4402{
4403 tANI_BOOLEAN fValidChannel = FALSE;
4404 tDot11fBeaconIEs *pIes = NULL;
4405 tANI_U8 index;
4406
4407 for( index = 0; index < numChn; index++ )
4408 {
4409 // This check relies on the fact that a single BSS description is returned in each
4410 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4411 // to this model when we ran with a large number of APs. If this were to change, then
4412 // this check would have to mess with removing the bssDescription from somewhere in an
4413 // arbitrary index in the bssDescription array.
4414 if ( pChannels[ index ] == pBssDesc->channelId )
4415 {
4416 fValidChannel = TRUE;
4417 break;
4418 }
4419 }
4420 *ppIes = NULL;
4421 if(fValidChannel)
4422 {
4423 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4424 {
4425 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4426 if( fValidChannel )
4427 {
4428 *ppIes = pIes;
4429 }
4430 else
4431 {
4432 palFreeMemory( pMac->hHdd, pIes );
4433 }
4434 }
4435 else
4436 {
4437 fValidChannel = FALSE;
4438 }
4439 }
4440
4441 return( fValidChannel );
4442}
4443
4444
4445//Return whether last scan result is received
4446static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4447 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4448{
4449 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4450 tDot11fBeaconIEs *pIes = NULL;
4451 tANI_U32 cbParsed;
4452 tSirBssDescription *pSirBssDescription;
4453 tANI_U32 cbBssDesc;
4454 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4455 + sizeof(tSirBssDescription); //We need at least one CB
4456
4457 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4458 // is returned when the scan could not find anything. so if we get scan failure return that
4459 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4460 // BssDescriptions....
4461 do
4462 {
4463 if ( ( cbScanResult <= pScanRsp->length ) &&
4464 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4465 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4466 {
4467 tANI_U8 *pChannelList = NULL;
4468 tANI_U8 cChannels = 0;
4469
4470 //Different scan type can reach this point, we need to distinguish it
4471 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4472 {
4473 //eCsrScanSetBGScanParam uses different structure
4474 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4475
4476 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4477 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4478 }
4479 else
4480 {
4481 //the rest use generic scan request
4482 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4483 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4484 }
4485
4486 // if the scan result is not on one of the channels in the Valid channel list, then it
4487 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4488 // let's drop the scan result.
4489 //
4490 // The other situation is where the scan request is for a scan on a particular channel set
4491 // and the scan result is from a
4492
4493 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4494 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4495 // as the valid channels.
4496 if ( 0 == cChannels )
4497 {
4498 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4499
4500 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4501 {
4502 pChannelList = pMac->roam.validChannelList;
4503 cChannels = (tANI_U8)len;
4504 }
4505 else
4506 {
4507 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004508 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004509 break;
4510 }
4511 }
4512
4513 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4514 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4515 pSirBssDescription = pScanRsp->bssDescription;
4516 while( cbParsed < pScanRsp->length )
4517 {
4518 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4519 {
4520 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4521 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4522 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4523 {
4524 if( csrIs11dSupported( pMac) )
4525 {
4526 //Check whether the BSS is acceptable base on 11d info and our configs.
4527 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4528 {
4529 //Double check whether the channel is acceptable by us.
4530 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4531 {
4532 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4533 }
4534 }
4535 }
4536 else
4537 {
4538 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4539 }
4540 }
4541 //Free the resource
4542 palFreeMemory( pMac->hHdd, pIes );
4543 }
4544 // skip over the BSS description to the next one...
4545 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
4546
4547 cbParsed += cbBssDesc;
4548 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
4549
4550 } //while
4551 }
4552 else
4553 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004554 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08004555 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004556 //HO bg scan/probe failed no need to try autonomously
4557 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4558 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4559 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4560 {
4561 fRemoveCommand = eANI_BOOLEAN_TRUE;
4562 }
4563 }
4564 }while(0);
4565 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4566 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004567 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 -07004568 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
4569 fRet = eANI_BOOLEAN_TRUE;
4570 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4571 if(pfRemoveCommand)
4572 {
4573 *pfRemoveCommand = fRemoveCommand;
4574 }
4575
4576#ifdef WLAN_AP_STA_CONCURRENCY
4577 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
4578 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004579 /* Pending scan commands in the list because the previous scan command
4580 * was split into a scan command on one channel + a scan command for all
4581 * remaining channels.
4582 *
4583 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08004584 * NOTE for LFR:
4585 * Do not split scans if no concurrent infra connections are
4586 * active and if the scan is a BG scan triggered by LFR (OR)
4587 * any scan if LFR is in the middle of a BG scan. Splitting
4588 * the scan is delaying the time it takes for LFR to find
4589 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004590 */
Srikant Kuppa866893f2012-12-27 17:28:14 -08004591 if ( (csrIsStaSessionConnected(pMac) &&
4592#ifdef FEATURE_WLAN_LFR
4593 (csrIsConcurrentInfraConnected(pMac) ||
4594 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
4595 (pMac->roam.neighborRoamInfo.neighborRoamState !=
4596 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
4597#endif
4598 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004599 (csrIsP2pSessionConnected(pMac)) )
4600 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004601 /* if active connected sessions present then continue to split scan
4602 * with specified interval between consecutive scans */
4603 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Srikant Kuppa866893f2012-12-27 17:28:14 -08004604 palTimerStart(pMac->hHdd, pMac->scan.hTimerStaApConcTimer,
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004605 pCommand->u.scanCmd.u.scanRequest.restTime * PAL_TIMER_TO_MS_UNIT, eANI_BOOLEAN_FALSE);
4606 } else {
4607 /* if no connected sessions present then initiate next scan command immediately */
4608 /* minimum timer granularity is 10ms */
4609 palTimerStart(pMac->hHdd, pMac->scan.hTimerStaApConcTimer, 10 * 1000, eANI_BOOLEAN_FALSE);
4610 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004611 }
4612#endif
4613 return (fRet);
4614}
4615
4616
4617tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
4618{
4619 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
4620 tANI_BOOLEAN f = palEqualMemory( pMac->hHdd, pCommand->u.scanCmd.u.scanRequest.bssid,
4621 bssid, sizeof(tCsrBssid) );
4622
4623 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
4624 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
4625 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
4626}
4627
4628
4629eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
4630{
4631 eHalStatus status = eHAL_STATUS_SUCCESS;
4632 tListElem *pEntry;
4633 tSmeCmd *pCommand;
4634 eCsrScanStatus scanStatus;
4635 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
4636 tSmeGetScanChnRsp *pScanChnInfo;
4637 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4638 eCsrScanReason reason = eCsrScanOther;
4639
4640 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
4641
4642 if ( pEntry )
4643 {
4644 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4645 if ( eSmeCommandScan == pCommand->command )
4646 {
4647 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
4648 reason = pCommand->u.scanCmd.reason;
4649 switch(pCommand->u.scanCmd.reason)
4650 {
4651 case eCsrScanAbortBgScan:
4652 case eCsrScanAbortNormalScan:
4653 case eCsrScanBGScanAbort:
4654 case eCsrScanBGScanEnable:
4655 break;
4656 case eCsrScanGetScanChnInfo:
4657 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004658 /*
4659 * status code not available in tSmeGetScanChnRsp, so
4660 * by default considereing it to be success
4661 */
4662 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004663 csrScanAgeResults(pMac, pScanChnInfo);
4664 break;
4665 case eCsrScanForCapsChange:
4666 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
4667 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004668 case eCsrScanP2PFindPeer:
4669 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
4670 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
4671 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004672 case eCsrScanSetBGScanParam:
4673 default:
4674 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
4675 {
4676 //Not to get channel info if the scan is not a wildcard scan because
4677 //it may cause scan results got aged out incorrectly.
4678 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch) )
4679 {
4680 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07004681 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
4682 {
4683 csrScanGetScanChnInfo(pMac, NULL, NULL);
4684 }
4685 else
4686 {
4687 csrScanGetScanChnInfo(pMac, pCommand->u.scanCmd.callback, pCommand->u.scanCmd.pContext);
4688 pCommand->u.scanCmd.callback = NULL;
4689 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004690 }
4691 }
4692 break;
4693 }//switch
4694 if(fRemoveCommand)
4695 {
4696
4697 csrReleaseScanCommand(pMac, pCommand, scanStatus);
4698
Srikant Kuppa866893f2012-12-27 17:28:14 -08004699 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004700 smeProcessPendingQueue( pMac );
4701 }
4702 else
4703 {
4704 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
4705 status = eHAL_STATUS_FAILURE;
4706 }
4707 }
4708 else
4709 {
4710 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
4711 status = eHAL_STATUS_FAILURE;
4712 }
4713
4714 return (status);
4715}
4716
4717
4718
4719
4720tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
4721{
4722 tListElem *pEntry;
4723 tCsrScanResult *pResult;
4724 tCsrScanResultInfo *pRet = NULL;
4725 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4726
4727 if(pResultList)
4728 {
4729 csrLLLock(&pResultList->List);
4730 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4731 if(pEntry)
4732 {
4733 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4734 pRet = &pResult->Result;
4735 }
4736 pResultList->pCurEntry = pEntry;
4737 csrLLUnlock(&pResultList->List);
4738 }
4739
4740 return pRet;
4741}
4742
4743
4744tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
4745{
4746 tListElem *pEntry = NULL;
4747 tCsrScanResult *pResult = NULL;
4748 tCsrScanResultInfo *pRet = NULL;
4749 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4750
4751 if(pResultList)
4752 {
4753 csrLLLock(&pResultList->List);
4754 if(NULL == pResultList->pCurEntry)
4755 {
4756 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4757 }
4758 else
4759 {
4760 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
4761 }
4762 if(pEntry)
4763 {
4764 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4765 pRet = &pResult->Result;
4766 }
4767 pResultList->pCurEntry = pEntry;
4768 csrLLUnlock(&pResultList->List);
4769 }
4770
4771 return pRet;
4772}
4773
4774
4775//This function moves the first BSS that matches the bssid to the head of the result
4776eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
4777{
4778 eHalStatus status = eHAL_STATUS_FAILURE;
4779 tScanResultList *pResultList = (tScanResultList *)hScanResult;
4780 tCsrScanResult *pResult = NULL;
4781 tListElem *pEntry = NULL;
4782
4783 if(pResultList && bssid)
4784 {
4785 csrLLLock(&pResultList->List);
4786 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
4787 while(pEntry)
4788 {
4789 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
4790 if(palEqualMemory(pMac->hHdd, bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
4791 {
4792 status = eHAL_STATUS_SUCCESS;
4793 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
4794 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
4795 break;
4796 }
4797 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
4798 }
4799 csrLLUnlock(&pResultList->List);
4800 }
4801
4802 return (status);
4803}
4804
4805
4806//Remove the BSS if possible.
4807//Return -- TRUE == the BSS is remove. False == Fail to remove it
4808//This function is called when list lock is held. Be caution what functions it can call.
4809tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
4810{
4811 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4812 tANI_U32 i;
4813 tCsrRoamSession *pSession;
4814
4815 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4816 {
4817 if( CSR_IS_SESSION_VALID( pMac, i ) )
4818 {
4819 pSession = CSR_GET_SESSION( pMac, i );
4820 //Not to remove the BSS we are connected to.
4821 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
4822 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
4823 pSession->pConnectBssDesc, NULL))
4824 )
4825 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004826 smsLog(pMac, LOGW, "Aging out BSS %02X-%02X-%02X-%02X-%02X-%02X Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07004827 pResult->Result.BssDescriptor.bssId[0],
4828 pResult->Result.BssDescriptor.bssId[1],
4829 pResult->Result.BssDescriptor.bssId[2],
4830 pResult->Result.BssDescriptor.bssId[3],
4831 pResult->Result.BssDescriptor.bssId[4],
4832 pResult->Result.BssDescriptor.bssId[5],
4833 pResult->Result.BssDescriptor.channelId);
4834 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
4835 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
4836 {
4837 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07004838 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004839 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004840 break;
4841 }
4842 } //valid session
4843 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07004844 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07004845 {
4846 //reset the counter so this won't hapeen too soon
4847 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
4848 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
4849 }
4850
4851 return (fRet);
4852}
4853
4854
4855eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
4856{
4857 eHalStatus status = eHAL_STATUS_SUCCESS;
4858 tListElem *pEntry, *tmpEntry;
4859 tCsrScanResult *pResult;
4860 tLimScanChn *pChnInfo;
4861 tANI_U8 i;
4862
4863 csrLLLock(&pMac->scan.scanResultList);
4864 for(i = 0; i < pScanChnInfo->numChn; i++)
4865 {
4866 pChnInfo = &pScanChnInfo->scanChn[i];
4867 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
4868 while( pEntry )
4869 {
4870 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
4871 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4872 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
4873 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004874 if(pResult->AgingCount <= 0)
4875 {
4876 smsLog(pMac, LOGW, " age out due to ref count");
4877 csrScanAgeOutBss(pMac, pResult);
4878 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07004879 else
4880 {
4881 pResult->AgingCount--;
4882 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004883 }
4884 pEntry = tmpEntry;
4885 }
4886 }
4887 csrLLUnlock(&pMac->scan.scanResultList);
4888
4889 return (status);
4890}
4891
4892
4893eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
4894 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
4895{
4896 eHalStatus status = eHAL_STATUS_SUCCESS;
4897 tSirSmeScanReq *pMsg;
4898 tANI_U16 msgLen;
4899 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
4900 tSirScanType scanType = pScanReq->scanType;
4901 tANI_U32 minChnTime; //in units of milliseconds
4902 tANI_U32 maxChnTime; //in units of milliseconds
4903 tANI_U32 i;
4904 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
4905 tANI_U8 *pSelfMac = NULL;
4906
4907 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
4908 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
4909 ( pScanReq->uIEFieldLen ) ;
4910
4911 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
4912 if(HAL_STATUS_SUCCESS(status))
4913 {
4914 do
4915 {
4916 palZeroMemory(pMac->hHdd, pMsg, msgLen);
4917 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
4918 pMsg->length = pal_cpu_to_be16(msgLen);
4919 //ToDO: Fill in session info when we need to do scan base on session.
4920 pMsg->sessionId = 0;
4921 pMsg->transactionId = 0;
4922 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
4923 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
4924
4925 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
4926 {
4927 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
4928 }
4929 else
4930 {
4931 // Since we don't have session for the scanning, we find a valid session. In case we fail to
4932 // do so, get the WNI_CFG_STA_ID
4933 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4934 {
4935 if( CSR_IS_SESSION_VALID( pMac, i ) )
4936 {
4937 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
4938 break;
4939 }
4940 }
4941 if( CSR_ROAM_SESSION_MAX == i )
4942 {
4943 tANI_U32 len = WNI_CFG_BSSID_LEN;
4944 pSelfMac = selfMacAddr;
4945 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
4946 if( !HAL_STATUS_SUCCESS( status ) ||
4947 ( len < WNI_CFG_BSSID_LEN ) )
4948 {
4949 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
4950 //Force failed status
4951 status = eHAL_STATUS_FAILURE;
4952 break;
4953 }
4954 }
4955 }
4956 palCopyMemory( pMac->hHdd, (tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr) );
4957
4958 //sirCopyMacAddr
4959 palCopyMemory( pMac->hHdd, (tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr) );
4960 if( palEqualMemory( pMac->hHdd, pScanReq->bssid, bssid, sizeof(tCsrBssid) ) )
4961 {
4962 palFillMemory( pMac->hHdd, pMsg->bssId, sizeof(tSirMacAddr), 0xff );
4963 }
4964 else
4965 {
4966 palCopyMemory(pMac->hHdd, pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
4967 }
4968 minChnTime = pScanReq->minChnTime;
4969 maxChnTime = pScanReq->maxChnTime;
4970
4971 //Verify the scan type first, if the scan is active scan, we need to make sure we
4972 //are allowed to do so.
4973 /* if 11d is enabled & we don't see any beacon around, scan type falls
4974 back to passive. But in BT AMP STA mode we need to send out a
4975 directed probe*/
4976 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
4977 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
4978 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
4979 {
4980 scanType = pMac->scan.curScanType;
4981 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
4982 {
4983 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
4984 {
4985 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
4986 }
4987 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
4988 {
4989 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
4990 }
4991 }
4992 }
4993 pMsg->scanType = pal_cpu_to_be32(scanType);
4994
4995 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ? pScanReq->SSIDs.numOfSSIDs :
4996 SIR_SCAN_MAX_NUM_SSID;
4997 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
4998 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07004999 for (i = 0; i < pMsg->numSsid; i++)
5000 {
5001 palCopyMemory(pMac->hHdd, &pMsg->ssId[i], &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
5002 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005003 }
5004 else
5005 {
5006 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005007 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5008 {
5009 pMsg->ssId[i].length = 0;
5010 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005011 }
5012
Jeff Johnson295189b2012-06-20 16:38:30 -07005013 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5014 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005015 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5016 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005017 //hidden SSID option
5018 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5019 //rest time
5020 //pMsg->restTime = pScanReq->restTime;
5021 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5022 // All the scan results caching will be done by Roaming
5023 // We do not want LIM to do any caching of scan results,
5024 // so delete the LIM cache on all scan requests
5025 pMsg->returnFreshResults = pScanReqParam->freshScan;
5026 //Always ask for unique result
5027 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5028 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5029 if(pScanReq->ChannelInfo.numOfChannels)
5030 {
5031 //Assuming the channelNumber is tANI_U8 (1 byte)
5032 status = palCopyMemory(pMac->hHdd, pMsg->channelList.channelNumber, pScanReq->ChannelInfo.ChannelList,
5033 pScanReq->ChannelInfo.numOfChannels);
5034 }
5035
5036 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5037 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5038 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5039 if(pScanReq->uIEFieldLen != 0)
5040 {
5041 palCopyMemory(pMac->hHdd, (tANI_U8 *)pMsg+pMsg->uIEFieldOffset,
5042 pScanReq->pIEField, pScanReq->uIEFieldLen );
5043 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005044 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005045
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005046 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5047 {
5048 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5049 }
5050
Jeff Johnson295189b2012-06-20 16:38:30 -07005051 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005052 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005053 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5054 pScanReq->requestType, pMsg->channelList.numChannels);
5055
5056 for(i = 0; i < pMsg->channelList.numChannels; i++)
5057 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005058 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005059 }
5060
Jeff Johnson295189b2012-06-20 16:38:30 -07005061 if(HAL_STATUS_SUCCESS(status))
5062 {
5063 status = palSendMBMessage(pMac->hHdd, pMsg);
5064 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005065 else
5066 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005067 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005068 palFreeMemory(pMac->hHdd, pMsg);
5069 }
5070 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005071 else
5072 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005073 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005074 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005075
5076 return( status );
5077}
5078
5079eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tScanReqParam *pScanReqParam )
5080{
5081 eHalStatus status = eHAL_STATUS_SUCCESS;
5082 tSirSmeScanReq *pMsg;
5083 tANI_U16 msgLen;
5084
5085 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
5086 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
5087 if(HAL_STATUS_SUCCESS(status))
5088 {
5089 palZeroMemory(pMac->hHdd, pMsg, msgLen);
5090 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5091 pMsg->length = pal_cpu_to_be16(msgLen);
5092 pMsg->sessionId = 0;
5093 pMsg->returnFreshResults = pScanReqParam->freshScan;
5094 //Always ask for unique result
5095 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5096 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5097 status = palSendMBMessage(pMac->hHdd, pMsg);
5098 }
5099
5100 return( status );
5101}
5102
5103
5104
5105eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5106{
5107 eHalStatus status = eHAL_STATUS_FAILURE;
5108 tScanReqParam scanReq;
5109
5110 do
5111 {
5112 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5113 scanReq.fUniqueResult = TRUE;
5114 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5115 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5116 {
5117 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5118 }
5119 else
5120 {
5121 // Basically do scan on all channels even for 11D 1st scan case.
5122 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5123 }
5124 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5125 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5126 {
5127 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5128 }
5129
5130#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5131 {
5132 vos_log_scan_pkt_type *pScanLog = NULL;
5133
5134 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5135 if(pScanLog)
5136 {
5137 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5138 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5139 {
5140 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5141 }
5142 else
5143 {
5144 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5145 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5146 {
5147 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5148 }
5149 else
5150 {
5151 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5152 }
5153 }
5154 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5155 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5156 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5157 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5158 {
5159 palCopyMemory(pMac->hHdd, pScanLog->channels,
5160 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5161 pScanLog->numChannel);
5162 }
5163 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5164 }
5165 }
5166#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5167
5168
5169 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5170 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5171 }while(0);
5172
5173 return( status );
5174}
5175
5176
5177eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac)
5178{
5179 eHalStatus status = eHAL_STATUS_FAILURE;
5180 tScanReqParam scanReq;
5181
5182 do
5183 {
5184 //not a fresh scan
5185 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5186 scanReq.fUniqueResult = TRUE;
5187 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5188 status = csrSendMBScanResultReq(pMac, &scanReq);
5189 }while(0);
5190
5191 return (status);
5192}
5193
5194
5195
5196eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5197{
5198 eHalStatus status = eHAL_STATUS_SUCCESS;
5199 tCsrChannelInfo newChannelInfo = {0, NULL};
5200 int i, j;
5201 tANI_U8 *pChannel = NULL;
5202 tANI_U32 len = 0;
5203
5204 // Transition to Scanning state...
5205 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5206 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005207 pCommand->u.scanCmd.lastRoamState[i] = csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005208 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 -07005209 }
5210
5211 switch(pCommand->u.scanCmd.reason)
5212 {
5213 case eCsrScanGetResult:
5214 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
5215 status = csrScanRetrieveResult(pMac);
5216 break;
5217 case eCsrScanSetBGScanParam:
5218 status = csrProcessSetBGScanParam(pMac, pCommand);
5219 break;
5220 case eCsrScanBGScanAbort:
5221 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5222 break;
5223 case eCsrScanBGScanEnable:
5224 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5225 break;
5226 case eCsrScanGetScanChnInfo:
5227 status = csrScanGetScanChannelInfo(pMac);
5228 break;
5229 case eCsrScanUserRequest:
5230 if(pMac->roam.configParam.fScanTwice)
5231 {
5232 //We scan 2.4 channel twice
5233 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5234 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5235 {
5236 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5237 //allocate twice the channel
5238 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5239 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5240 }
5241 else
5242 {
5243 //get the valid channel list to scan all.
5244 len = sizeof(pMac->roam.validChannelList);
5245
5246 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5247 {
5248 //allocate twice the channel
5249 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5250 pChannel = pMac->roam.validChannelList;
5251 }
5252 }
5253 if(NULL == newChannelInfo.ChannelList)
5254 {
5255 newChannelInfo.numOfChannels = 0;
5256 }
5257 else
5258 {
5259 j = 0;
5260 for(i = 0; i < len; i++)
5261 {
5262 newChannelInfo.ChannelList[j++] = pChannel[i];
5263 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5264 {
5265 newChannelInfo.ChannelList[j++] = pChannel[i];
5266 }
5267 }
5268 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5269 {
5270 //pChannel points to the channellist from the command, free it.
5271 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
5272 }
5273 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5274 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5275 }
5276 } //if(pMac->roam.configParam.fScanTwice)
5277
5278 status = csrScanChannels(pMac, pCommand);
5279
5280 break;
5281 default:
5282 status = csrScanChannels(pMac, pCommand);
5283 break;
5284 }
5285
5286 if(!HAL_STATUS_SUCCESS(status))
5287 {
5288 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5289 }
5290
5291 return (status);
5292}
5293
5294
5295eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5296{
5297 eHalStatus status = eHAL_STATUS_SUCCESS;
5298 tSmeCmd *pCommand = NULL;
5299
5300 if(pScanReq)
5301 {
5302 do
5303 {
5304 pCommand = csrGetCommandBuffer(pMac);
5305 if(!pCommand)
5306 {
5307 status = eHAL_STATUS_RESOURCES;
5308 break;
5309 }
5310 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5311 pCommand->command = eSmeCommandScan;
5312 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5313 pCommand->u.scanCmd.callback = NULL;
5314 pCommand->u.scanCmd.pContext = NULL;
5315 palCopyMemory(pMac->hHdd, &pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
5316 //we have to do the follow
5317 if(pScanReq->ChannelInfo.numOfChannels == 0)
5318 {
5319 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5320 }
5321 else
5322 {
5323 status = palAllocateMemory(pMac->hHdd, (void **)&pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5324 pScanReq->ChannelInfo.numOfChannels);
5325 if(HAL_STATUS_SUCCESS(status))
5326 {
5327 palCopyMemory(pMac->hHdd, pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5328 pScanReq->ChannelInfo.ChannelList, pScanReq->ChannelInfo.numOfChannels);
5329 }
5330 else
5331 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005332 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005333 csrReleaseCommandScan(pMac, pCommand);
5334 break;
5335 }
5336 }
5337
5338 //scan req for SSID
5339 if(pScanReq->SSID.length)
5340 {
5341 palCopyMemory(pMac->hHdd,
5342 pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5343 pScanReq->SSID.ssId,
5344 pScanReq->SSID.length);
5345 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5346
5347 }
5348 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5349 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5350 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5351
5352
5353 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5354 if( !HAL_STATUS_SUCCESS( status ) )
5355 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005356 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005357 csrReleaseCommandScan( pMac, pCommand );
5358 break;
5359 }
5360 }while(0);
5361 }
5362
5363 return (status);
5364}
5365
5366eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5367{
5368 eHalStatus status = eHAL_STATUS_SUCCESS;
5369 tSmeCmd *pCommand = NULL;
5370
5371 do
5372 {
5373 pCommand = csrGetCommandBuffer(pMac);
5374 if(!pCommand)
5375 {
5376 status = eHAL_STATUS_RESOURCES;
5377 break;
5378 }
5379 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5380 pCommand->command = eSmeCommandScan;
5381 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5382 pCommand->u.scanCmd.callback = NULL;
5383 pCommand->u.scanCmd.pContext = NULL;
5384 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5385 if( !HAL_STATUS_SUCCESS( status ) )
5386 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005387 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005388 csrReleaseCommandScan( pMac, pCommand );
5389 break;
5390 }
5391 }while(0);
5392
5393 return (status);
5394}
5395
5396
5397//This will enable the background scan with the non-zero interval
5398eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5399{
5400 eHalStatus status = eHAL_STATUS_SUCCESS;
5401 tSmeCmd *pCommand = NULL;
5402
5403 if(pMac->roam.configParam.bgScanInterval)
5404 {
5405 do
5406 {
5407 pCommand = csrGetCommandBuffer(pMac);
5408 if(!pCommand)
5409 {
5410 status = eHAL_STATUS_RESOURCES;
5411 break;
5412 }
5413 palZeroMemory(pMac->hHdd, &pCommand->u.scanCmd, sizeof(tScanCmd));
5414 pCommand->command = eSmeCommandScan;
5415 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5416 pCommand->u.scanCmd.callback = NULL;
5417 pCommand->u.scanCmd.pContext = NULL;
5418 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5419 if( !HAL_STATUS_SUCCESS( status ) )
5420 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005421 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005422 csrReleaseCommandScan( pMac, pCommand );
5423 break;
5424 }
5425 }while(0);
5426 //BG scan results are reported automatically by PE to SME once the scan is done.
5427 //No need to fetch the results explicitly.
5428 //csrScanStartGetResultTimer(pMac);
5429 csrScanStartResultAgingTimer(pMac);
5430 }
5431 else
5432 {
5433 //We don't have BG scan so stop the aging timer
5434 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005435 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005436 status = eHAL_STATUS_INVALID_PARAMETER;
5437 }
5438
5439 return (status);
5440}
5441
5442
5443eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5444{
5445 eHalStatus status = eHAL_STATUS_SUCCESS;
5446 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5447 tANI_U32 index = 0;
5448 tANI_U32 new_index = 0;
5449
5450 do
5451 {
5452 status = csrScanFreeRequest(pMac, pDstReq);
5453 if(HAL_STATUS_SUCCESS(status))
5454 {
5455 status = palCopyMemory(pMac->hHdd, pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08005456 /* Re-initialize the pointers to NULL since we did a copy */
5457 pDstReq->pIEField = NULL;
5458 pDstReq->ChannelInfo.ChannelList = NULL;
5459 pDstReq->SSIDs.SSIDList = NULL;
5460
Jeff Johnson295189b2012-06-20 16:38:30 -07005461 if(pSrcReq->uIEFieldLen == 0)
5462 {
5463 pDstReq->pIEField = NULL;
5464 }
5465 else
5466 {
5467 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->pIEField, pSrcReq->uIEFieldLen);
5468 if(HAL_STATUS_SUCCESS(status))
5469 {
5470 palCopyMemory(pMac->hHdd, pDstReq->pIEField, pSrcReq->pIEField, pSrcReq->uIEFieldLen);
5471 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
5472 }
5473 else
5474 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005475 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnson295189b2012-06-20 16:38:30 -07005476 break;
5477 }
5478 }//Allocate memory for IE field
5479 {
5480 if(pSrcReq->ChannelInfo.numOfChannels == 0)
5481 {
5482 pDstReq->ChannelInfo.ChannelList = NULL;
5483 pDstReq->ChannelInfo.numOfChannels = 0;
5484 }
5485 else
5486 {
5487 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->ChannelInfo.ChannelList,
5488 pSrcReq->ChannelInfo.numOfChannels * sizeof(*pDstReq->ChannelInfo.ChannelList));
5489 if(!HAL_STATUS_SUCCESS(status))
5490 {
5491 pDstReq->ChannelInfo.numOfChannels = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005492 smsLog(pMac, LOGE, "No memory for scanning Channel List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005493 break;
5494 }
5495
5496 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
5497 {
5498 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5499 {
5500 pDstReq->ChannelInfo.ChannelList[new_index] =
5501 pSrcReq->ChannelInfo.ChannelList[index];
5502 new_index++;
5503 }
5504 pDstReq->ChannelInfo.numOfChannels = new_index;
5505 }
5506 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
5507 {
5508 new_index = 0;
5509 pMac->roam.numValidChannels = len;
5510 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5511 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005512 /* Allow scan on valid channels only.
5513 * If it is p2p scan and valid channel list doesnt contain
5514 * social channels, enforce scan on social channels because
5515 * that is the only way to find p2p peers.
5516 * This can happen only if band is set to 5Ghz mode.
5517 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005518 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
5519 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005520 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07005521 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08005522 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005523 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08005524#ifdef FEATURE_WLAN_LFR
5525 /*
5526 * If LFR is requesting a contiguous scan
5527 * (i.e. numOfChannels > 1), then ignore
5528 * DFS channels.
5529 * TODO: vos_nv_getChannelEnabledState is returning
5530 * 120, 124 and 128 as non-DFS channels. Hence, the
5531 * use of direct check for channels below.
5532 */
5533 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5534 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08005535 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08005536#endif
5537 )
5538 {
5539#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005540 smsLog(pMac, LOG2,
Srikant Kuppa866893f2012-12-27 17:28:14 -08005541 "%s: reqType=%d, numOfChannels=%d,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005542 " ignoring DFS channel %d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005543 __func__, pSrcReq->requestType,
5544 pSrcReq->ChannelInfo.numOfChannels,
5545 pSrcReq->ChannelInfo.ChannelList[index]);
5546#endif
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005547 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005548 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005549
Jeff Johnson295189b2012-06-20 16:38:30 -07005550 pDstReq->ChannelInfo.ChannelList[new_index] =
5551 pSrcReq->ChannelInfo.ChannelList[index];
5552 new_index++;
5553 }
5554 }
5555 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005556#ifdef FEATURE_WLAN_LFR
5557 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5558 (0 == pDstReq->ChannelInfo.numOfChannels))
5559 {
5560 /*
5561 * No valid channels found in the request.
5562 * Only perform scan on the channels passed
5563 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
5564 * Passing 0 to LIM will trigger a scan on
5565 * all valid channels which is not desirable.
5566 */
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005567 smsLog(pMac, LOGE, "%s: no valid channels found (request=%d)",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005568 __func__, pSrcReq->requestType);
5569 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5570 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005571 smsLog(pMac, LOGE, "pSrcReq index=%d channel=%d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005572 index, pSrcReq->ChannelInfo.ChannelList[index]);
5573 }
5574 status = eHAL_STATUS_FAILURE;
5575 break;
5576 }
5577#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005578 }
5579 else
5580 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005581 smsLog(pMac, LOGE, "Couldn't get the valid Channel List, keeping requester's list");
Jeff Johnson295189b2012-06-20 16:38:30 -07005582 palCopyMemory(pMac->hHdd, pDstReq->ChannelInfo.ChannelList, pSrcReq->ChannelInfo.ChannelList,
5583 pSrcReq->ChannelInfo.numOfChannels * sizeof(*pDstReq->ChannelInfo.ChannelList));
5584 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
5585 }
5586 }//Allocate memory for Channel List
5587 }
5588 if(pSrcReq->SSIDs.numOfSSIDs == 0)
5589 {
5590 pDstReq->SSIDs.numOfSSIDs = 0;
5591 pDstReq->SSIDs.SSIDList = NULL;
5592 }
5593 else
5594 {
5595 status = palAllocateMemory(pMac->hHdd, (void **)&pDstReq->SSIDs.SSIDList,
5596 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5597 if(HAL_STATUS_SUCCESS(status))
5598 {
5599 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
5600 palCopyMemory(pMac->hHdd, pDstReq->SSIDs.SSIDList, pSrcReq->SSIDs.SSIDList,
5601 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5602 }
5603 else
5604 {
5605 pDstReq->SSIDs.numOfSSIDs = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005606 smsLog(pMac, LOGE, "No memory for scanning SSID List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005607 break;
5608 }
5609 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07005610 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07005611 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005612
5613 }
5614 }while(0);
5615
5616 if(!HAL_STATUS_SUCCESS(status))
5617 {
5618 csrScanFreeRequest(pMac, pDstReq);
5619 }
5620
5621 return (status);
5622}
5623
5624
5625eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
5626{
5627 eHalStatus status = eHAL_STATUS_SUCCESS;
5628
5629 if(pReq->ChannelInfo.ChannelList)
5630 {
5631 status = palFreeMemory(pMac->hHdd, pReq->ChannelInfo.ChannelList);
5632 pReq->ChannelInfo.ChannelList = NULL;
5633 }
5634 pReq->ChannelInfo.numOfChannels = 0;
5635 if(pReq->pIEField)
5636 {
5637 status = palFreeMemory(pMac->hHdd, pReq->pIEField);
5638 pReq->pIEField = NULL;
5639 }
5640 pReq->uIEFieldLen = 0;
5641 if(pReq->SSIDs.SSIDList)
5642 {
5643 palFreeMemory(pMac->hHdd, pReq->SSIDs.SSIDList);
5644 pReq->SSIDs.SSIDList = NULL;
5645 }
5646 pReq->SSIDs.numOfSSIDs = 0;
5647
5648 return (status);
5649}
5650
5651
5652void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
5653{
5654 if(pCommand->u.scanCmd.callback)
5655 {
5656// sme_ReleaseGlobalLock( &pMac->sme );
5657 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
5658// sme_AcquireGlobalLock( &pMac->sme );
5659 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005660 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07005661 }
5662}
5663
5664
5665void csrScanStopTimers(tpAniSirGlobal pMac)
5666{
5667 csrScanStopResultAgingTimer(pMac);
5668 csrScanStopIdleScanTimer(pMac);
5669 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005670 if(0 != pMac->scan.scanResultCfgAgingTime )
5671 {
5672 csrScanStopResultCfgAgingTimer(pMac);
5673 }
5674
Jeff Johnson295189b2012-06-20 16:38:30 -07005675}
5676
5677
5678eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
5679{
5680 eHalStatus status;
5681
5682 if(pMac->scan.fScanEnable)
5683 {
5684 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL, eANI_BOOLEAN_TRUE);
5685 }
5686 else
5687 {
5688 status = eHAL_STATUS_FAILURE;
5689 }
5690
5691 return (status);
5692}
5693
5694
5695eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
5696{
5697 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerGetResult));
5698}
5699
5700
5701void csrScanGetResultTimerHandler(void *pv)
5702{
5703 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5704
5705 csrScanRequestResult(pMac);
5706}
5707
5708#ifdef WLAN_AP_STA_CONCURRENCY
5709static void csrStaApConcTimerHandler(void *pv)
5710{
5711 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5712 tListElem *pEntry;
5713 tSmeCmd *pScanCmd;
5714
5715 csrLLLock(&pMac->scan.scanCmdPendingList);
5716
5717 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
5718 {
5719 tCsrScanRequest scanReq;
5720 tSmeCmd *pSendScanCmd = NULL;
5721 tANI_U8 numChn = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08005722 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07005723 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
5724 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
5725 eHalStatus status;
5726
Jeff Johnson295189b2012-06-20 16:38:30 -07005727 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5728 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005729
5730 /* if any session is connected and the number of channels to scan is
5731 * greater than 1 then split the scan into multiple scan operations
5732 * on each individual channel else continue to perform scan on all
5733 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005734
5735 /* split scan if number of channels to scan is greater than 1 and
5736 * any one of the following:
5737 * - STA session is connected and the scan is not a P2P search
5738 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08005739 * Do not split scans if no concurrent infra connections are
5740 * active and if the scan is a BG scan triggered by LFR (OR)
5741 * any scan if LFR is in the middle of a BG scan. Splitting
5742 * the scan is delaying the time it takes for LFR to find
5743 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005744 */
Vinay Malekal05fdc812012-12-17 13:04:30 -08005745 if ( (numChn > pMac->roam.configParam.nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005746 ((csrIsStaSessionConnected(pMac) &&
5747#ifdef FEATURE_WLAN_LFR
5748 (csrIsConcurrentInfraConnected(pMac) ||
5749 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
5750 (pMac->roam.neighborRoamInfo.neighborRoamState !=
5751 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5752#endif
5753 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005754 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005755 {
5756 palZeroMemory(pMac->hHdd, &scanReq, sizeof(tCsrScanRequest));
5757
5758 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
5759 if (!pSendScanCmd)
5760 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005761 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07005762 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5763 return;
5764 }
5765 pSendScanCmd->command = pScanCmd->command;
5766 pSendScanCmd->sessionId = pScanCmd->sessionId;
5767 pSendScanCmd->u.scanCmd.callback = NULL;
5768 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
5769 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
5770 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
5771
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07005772 /* First copy all the parameters to local variable of scan request */
5773 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
5774
5775 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08005776 if(scanReq.ChannelInfo.ChannelList != NULL)
5777 {
5778 palFreeMemory(pMac->hHdd,scanReq.ChannelInfo.ChannelList);
5779 scanReq.ChannelInfo.ChannelList = NULL;
5780 }
5781
Vinay Malekal05fdc812012-12-17 13:04:30 -08005782 pChnInfo->numOfChannels = pMac->roam.configParam.nNumChanCombinedConc;
5783 palCopyMemory(pMac->hHdd, &channelToScan[0], &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
5784 pChnInfo->numOfChannels * sizeof(tANI_U8)); //just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07005785 pChnInfo->ChannelList = &channelToScan[0];
5786
Vinay Malekal05fdc812012-12-17 13:04:30 -08005787 for (i = 0, j = pMac->roam.configParam.nNumChanCombinedConc; i < (numChn-pMac->roam.configParam.nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07005788 {
5789 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08005790 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07005791 }
5792
Vinay Malekal05fdc812012-12-17 13:04:30 -08005793 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 -07005794
5795 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
5796 //Modify callers parameters in case of concurrency
5797 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07005798 //Use concurrency values for min/maxChnTime.
5799 //We know csrIsAnySessionConnected(pMac) returns TRUE here
5800 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005801
5802 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
5803 if(!HAL_STATUS_SUCCESS(status))
5804 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005805 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005806 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5807 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08005808 }
5809 /* Clean the local scan variable */
5810 scanReq.ChannelInfo.ChannelList = NULL;
5811 scanReq.ChannelInfo.numOfChannels = 0;
5812 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005813 }
5814 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005815 {
5816 /* no active connected session present or numChn == 1
5817 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07005818 pSendScanCmd = pScanCmd;
5819 //remove this command from pending list
5820 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
5821 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005822 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005823 }
5824
5825 }
5826 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
5827
5828 }
5829
Jeff Johnson295189b2012-06-20 16:38:30 -07005830 csrLLUnlock(&pMac->scan.scanCmdPendingList);
5831
5832}
5833#endif
5834
5835eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
5836{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005837 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005838
5839 if(pMac->scan.fScanEnable)
5840 {
5841 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL, eANI_BOOLEAN_TRUE);
5842 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005843 return (status);
5844}
5845
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005846eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
5847{
5848 eHalStatus status = eHAL_STATUS_FAILURE;
5849
5850 if(pMac->scan.fScanEnable)
5851 {
5852 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerResultCfgAging,
5853 CSR_SCAN_RESULT_CFG_AGING_INTERVAL, eANI_BOOLEAN_TRUE);
5854 }
5855 return (status);
5856}
Jeff Johnson295189b2012-06-20 16:38:30 -07005857
5858eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
5859{
5860 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerResultAging));
5861}
5862
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005863eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
5864{
5865 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerResultCfgAging));
5866}
Jeff Johnson295189b2012-06-20 16:38:30 -07005867
5868//This function returns the maximum time a BSS is allowed in the scan result.
5869//The time varies base on connection and power saving factors.
5870//Not connected, No PS
5871//Not connected, with PS
5872//Connected w/o traffic, No PS
5873//Connected w/o traffic, with PS
5874//Connected w/ traffic, no PS -- Not supported
5875//Connected w/ traffic, with PS -- Not supported
5876//the return unit is in seconds.
5877tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
5878{
5879 tANI_U32 nRet;
5880
5881 if(pMac->scan.nAgingCountDown)
5882 {
5883 //Calculate what should be the timeout value for this
5884 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
5885 pMac->scan.nAgingCountDown--;
5886 }
5887 else
5888 {
5889 if( csrIsAllSessionDisconnected( pMac ) )
5890 {
5891 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
5892 {
5893 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
5894 }
5895 else
5896 {
5897 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
5898 }
5899 }
5900 else
5901 {
5902 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
5903 {
5904 nRet = pMac->roam.configParam.scanAgeTimeCPS;
5905 }
5906 else
5907 {
5908 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
5909 }
5910 }
5911 //If state-change causing aging time out change, we want to delay it somewhat to avoid
5912 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
5913 if(pMac->scan.nLastAgeTimeOut > nRet)
5914 {
5915 if(nRet)
5916 {
5917 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
5918 }
5919 pMac->scan.nLastAgeTimeOut = nRet;
5920 nRet *= pMac->scan.nAgingCountDown;
5921 }
5922 else
5923 {
5924 pMac->scan.nLastAgeTimeOut = nRet;
5925 }
5926 }
5927
5928 return (nRet);
5929}
5930
5931
5932void csrScanResultAgingTimerHandler(void *pv)
5933{
5934 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5935 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
5936
5937 //no scan, no aging
5938 if(pMac->scan.fScanEnable &&
5939 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
5940 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
5941 )
5942 {
5943 tListElem *pEntry, *tmpEntry;
5944 tCsrScanResult *pResult;
5945 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
5946 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5947
5948 csrLLLock(&pMac->scan.scanResultList);
5949 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5950 while( pEntry )
5951 {
5952 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5953 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5954 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
5955 {
5956 smsLog(pMac, LOGW, " age out due to time out");
5957 csrScanAgeOutBss(pMac, pResult);
5958 }
5959 pEntry = tmpEntry;
5960 }
5961 csrLLUnlock(&pMac->scan.scanResultList);
5962 }
5963}
5964
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08005965static void csrScanResultCfgAgingTimerHandler(void *pv)
5966{
5967 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
5968 tListElem *pEntry, *tmpEntry;
5969 tCsrScanResult *pResult;
5970 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
5971 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5972
5973 csrLLLock(&pMac->scan.scanResultList);
5974 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5975 while( pEntry )
5976 {
5977 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5978 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5979 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
5980 {
5981 smsLog(pMac, LOGW, " age out due to time out");
5982 csrScanAgeOutBss(pMac, pResult);
5983 }
5984 pEntry = tmpEntry;
5985 }
5986 csrLLUnlock(&pMac->scan.scanResultList);
5987}
Jeff Johnson295189b2012-06-20 16:38:30 -07005988
5989eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
5990{
5991 eHalStatus status;
5992
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005993 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07005994 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
5995 {
5996 pMac->scan.nIdleScanTimeGap += interval;
5997 palTimerStop(pMac->hHdd, pMac->scan.hTimerIdleScan);
5998 status = palTimerStart(pMac->hHdd, pMac->scan.hTimerIdleScan, interval, eANI_BOOLEAN_FALSE);
5999 if( !HAL_STATUS_SUCCESS(status) )
6000 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006001 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006002 //This should not happen but set the flag to restart when ready
6003 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6004 }
6005 }
6006 else
6007 {
6008 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6009 {
6010 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6011 }
6012 status = eHAL_STATUS_FAILURE;
6013 }
6014
6015 return (status);
6016}
6017
6018
6019eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6020{
6021 return (palTimerStop(pMac->hHdd, pMac->scan.hTimerIdleScan));
6022}
6023
6024
6025//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6026void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6027{
6028 csrScanCancelIdleScan(pMac);
6029}
6030
6031
6032//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6033//because IMPS maybe disabled.
6034void csrScanResumeIMPS( tpAniSirGlobal pMac )
6035{
6036 csrScanStartIdleScan( pMac );
6037}
6038
6039
6040void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6041{
6042 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6043
6044 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6045 {
6046 if(pMac->roam.configParam.IsIdleScanEnabled)
6047 {
6048 if(HAL_STATUS_SUCCESS(status))
6049 {
6050 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6051 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006052 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006053 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6054 }
6055 else
6056 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006057 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006058 //even though we are in timer handle, calling stop timer will make sure the timer
6059 //doesn't get to restart.
6060 csrScanStopIdleScanTimer(pMac);
6061 }
6062 }
6063 else
6064 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006065 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006066 }
6067 }
6068 else
6069 {//we might need another flag to check if CSR needs to request imps at all
6070
6071 tANI_U32 nTime = 0;
6072
6073 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6074 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6075 {
6076 csrScanStartIdleScanTimer(pMac, nTime);
6077 }
6078 }
6079 }
6080}
6081
6082
6083//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6084//idle scan timer interval
6085//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6086eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6087{
6088 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6089
6090 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006091 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6092 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006093 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006094 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006095 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006096
6097 if(pTimeInterval)
6098 {
6099 *pTimeInterval = 0;
6100 }
6101
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006102 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006103 if( smeCommandPending( pMac ) )
6104 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006105 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006106 //Not to enter IMPS because more work to do
6107 if(pTimeInterval)
6108 {
6109 *pTimeInterval = 0;
6110 }
6111 //restart when ready
6112 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6113
6114 return (status);
6115 }
6116
6117 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6118 /*&& pMac->roam.configParam.impsSleepTime*/)
6119 {
6120 //Stop get result timer because idle scan gets scan result out of PE
6121 csrScanStopGetResultTimer(pMac);
6122 if(pTimeInterval)
6123 {
6124 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6125 }
6126 //pmcRequestImps take a period in millisecond unit.
6127 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6128 if(!HAL_STATUS_SUCCESS(status))
6129 {
6130 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6131 {
6132 //Do restart the timer if CSR thinks it cannot do IMPS
6133 if( !csrCheckPSReady( pMac ) )
6134 {
6135 if(pTimeInterval)
6136 {
6137 *pTimeInterval = 0;
6138 }
6139 //Set the restart flag to true because that idle scan
6140 //can be restarted even though the timer will not be running
6141 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6142 }
6143 else
6144 {
6145 //For not now, we do a quicker retry
6146 if(pTimeInterval)
6147 {
6148 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6149 }
6150 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006151 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006152 }
6153 else
6154 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006155 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006156 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6157 //the callback will be called in the future. Should not happen though.
6158 status = eHAL_STATUS_SUCCESS;
6159 pMac->scan.nIdleScanTimeGap = 0;
6160 }
6161 }
6162 else
6163 {
6164 //requested so let's reset the value
6165 pMac->scan.nIdleScanTimeGap = 0;
6166 }
6167 }
6168
6169 return (status);
6170}
6171
6172
6173eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6174{
6175 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6176 tANI_U32 nTime = 0;
6177
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006178 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006179 if(pMac->roam.configParam.IsIdleScanEnabled)
6180 {
6181 //stop bg scan first
6182 csrScanBGScanAbort(pMac);
6183 //Stop get result timer because idle scan gets scan result out of PE
6184 csrScanStopGetResultTimer(pMac);
6185 //Enable aging timer since idle scan is going on
6186 csrScanStartResultAgingTimer(pMac);
6187 }
6188 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6189 status = csrScanTriggerIdleScan(pMac, &nTime);
6190 if(!HAL_STATUS_SUCCESS(status))
6191 {
6192 csrScanStartIdleScanTimer(pMac, nTime);
6193 }
6194
6195 return (status);
6196}
6197
6198
6199void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6200{
6201 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6202 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006203 if (vos_concurrent_sessions_running()) {
6204 return;
6205 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006206 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006207 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6208 //Set the restart flag in case later on it is uncancelled
6209 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6210 csrScanStopIdleScanTimer(pMac);
6211 csrScanRemoveNotRoamingScanCommand(pMac);
6212 }
6213}
6214
6215
6216void csrScanIdleScanTimerHandler(void *pv)
6217{
6218 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6219 eHalStatus status;
6220 tANI_U32 nTime = 0;
6221
6222 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
6223 status = csrScanTriggerIdleScan(pMac, &nTime);
6224 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6225 {
6226 //Check whether it is time to actually do an idle scan
6227 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6228 {
6229 pMac->scan.nIdleScanTimeGap = 0;
6230 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6231 }
6232 else
6233 {
6234 csrScanStartIdleScanTimer(pMac, nTime);
6235 }
6236 }
6237}
6238
6239
6240
6241
6242tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6243{
6244 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6245 tListElem *pEntry, *pEntryTmp;
6246 tSmeCmd *pCommand;
6247 tDblLinkList localList;
6248
6249 vos_mem_zero(&localList, sizeof(tDblLinkList));
6250 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6251 {
6252 smsLog(pMac, LOGE, FL(" failed to open list"));
6253 return fRet;
6254 }
6255
6256 csrLLLock(&pMac->sme.smeCmdPendingList);
6257 pEntry = csrLLPeekHead(&pMac->sme.smeCmdPendingList, LL_ACCESS_NOLOCK);
6258 while(pEntry)
6259 {
6260 pEntryTmp = csrLLNext(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK);
6261 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6262 if( eSmeCommandScan == pCommand->command )
6263 {
6264 switch( pCommand->u.scanCmd.reason )
6265 {
6266 case eCsrScanIdleScan:
6267 if( csrLLRemoveEntry(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK) )
6268 {
6269 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6270 }
6271 fRet = eANI_BOOLEAN_TRUE;
6272 break;
6273
6274 default:
6275 break;
6276 } //switch
6277 }
6278 pEntry = pEntryTmp;
6279 }
6280
6281 csrLLUnlock(&pMac->sme.smeCmdPendingList);
6282
6283 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6284 {
6285 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6286 csrReleaseCommandScan( pMac, pCommand );
6287 }
6288
6289 csrLLClose(&localList);
6290
6291 return (fRet);
6292}
6293
6294
6295tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6296{
6297 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6298 tListElem *pEntry, *pEntryTmp;
6299 tSmeCmd *pCommand;
6300 tDblLinkList localList;
6301
6302 vos_mem_zero(&localList, sizeof(tDblLinkList));
6303 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6304 {
6305 smsLog(pMac, LOGE, FL(" failed to open list"));
6306 return fRet;
6307 }
6308
6309 csrLLLock(&pMac->sme.smeCmdPendingList);
6310 pEntry = csrLLPeekHead(&pMac->sme.smeCmdPendingList, LL_ACCESS_NOLOCK);
6311 while(pEntry)
6312 {
6313 pEntryTmp = csrLLNext(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK);
6314 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6315 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6316 {
6317 switch(pCommand->u.scanCmd.reason)
6318 {
6319 case eCsrScanGetResult:
6320 case eCsrScanSetBGScanParam:
6321 case eCsrScanBGScanAbort:
6322 case eCsrScanBGScanEnable:
6323 case eCsrScanGetScanChnInfo:
6324 break;
6325 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006326 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006327 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006328 //The rest are fresh scan requests
6329 if( csrLLRemoveEntry(&pMac->sme.smeCmdPendingList, pEntry, LL_ACCESS_NOLOCK) )
6330 {
6331 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6332 }
6333 fRet = eANI_BOOLEAN_TRUE;
6334 break;
6335 }
6336 }
6337 pEntry = pEntryTmp;
6338 }
6339
6340 csrLLUnlock(&pMac->sme.smeCmdPendingList);
6341
6342 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6343 {
6344 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6345 if (pCommand->u.scanCmd.callback)
6346 {
6347 /* User scan request is pending,
6348 * send response with status eCSR_SCAN_ABORT*/
6349 pCommand->u.scanCmd.callback(pMac,
6350 pCommand->u.scanCmd.pContext,
6351 pCommand->u.scanCmd.scanID,
6352 eCSR_SCAN_ABORT);
6353 }
6354 csrReleaseCommandScan( pMac, pCommand );
6355 }
6356 csrLLClose(&localList);
6357
6358 return (fRet);
6359}
6360
6361
6362void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6363{
6364 eCsrScanReason reason = pCommand->u.scanCmd.reason;
6365 tANI_U32 i;
6366 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6367 {
Jeff Johnson43971f52012-07-17 12:26:56 -07006368 csrRoamStateChange( pMac, pCommand->u.scanCmd.lastRoamState[i], i);
Jeff Johnson295189b2012-06-20 16:38:30 -07006369 }
6370
6371 csrScanCallCallback(pMac, pCommand, scanStatus);
6372
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006373 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006374 if( csrLLRemoveEntry( &pMac->sme.smeCmdActiveList, &pCommand->Link, LL_ACCESS_LOCK ) )
6375 {
6376 csrReleaseCommandScan( pMac, pCommand );
6377 }
6378 else
6379 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006380 smsLog(pMac, LOGE, " ********csrReleaseScanCommand cannot release command reason %d", pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006381 }
6382}
6383
6384
6385eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6386 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
6387{
6388 eHalStatus status = eHAL_STATUS_SUCCESS;
6389 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6390
Jeff Johnson32d95a32012-09-10 13:15:23 -07006391 if(!pSession)
6392 {
6393 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6394 return eHAL_STATUS_FAILURE;
6395 }
6396
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006397 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006398 csrResetPMKIDCandidateList(pMac, sessionId);
6399 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6400 {
6401 tCsrScanResultFilter *pScanFilter;
6402 tCsrScanResultInfo *pScanResult;
6403 tScanResultHandle hBSSList;
6404 tANI_U32 nItems = *pNumItems;
6405
6406 *pNumItems = 0;
6407 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
6408 if(HAL_STATUS_SUCCESS(status))
6409 {
6410 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
6411 //Here is the profile we need to connect to
6412 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6413 if(HAL_STATUS_SUCCESS(status))
6414 {
6415 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6416 if(HAL_STATUS_SUCCESS(status))
6417 {
6418 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
6419 {
6420 //NumPmkidCandidate adds up here
6421 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
6422 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6423 }
6424 if(pSession->NumPmkidCandidate)
6425 {
6426 *pNumItems = pSession->NumPmkidCandidate;
6427 palCopyMemory(pMac->hHdd, pPmkidList, pSession->PmkidCandidateInfo,
6428 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
6429 }
6430 csrScanResultPurge(pMac, hBSSList);
6431 }//Have scan result
6432 csrFreeScanFilter(pMac, pScanFilter);
6433 }
6434 palFreeMemory(pMac->hHdd, pScanFilter);
6435 }
6436 }
6437
6438 return (status);
6439}
6440
6441
6442
6443#ifdef FEATURE_WLAN_WAPI
6444eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6445 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
6446{
6447 eHalStatus status = eHAL_STATUS_SUCCESS;
6448 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6449
Jeff Johnson32d95a32012-09-10 13:15:23 -07006450 if(!pSession)
6451 {
6452 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6453 return eHAL_STATUS_FAILURE;
6454 }
6455
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006456 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006457 csrResetBKIDCandidateList(pMac, sessionId);
6458 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6459 {
6460 tCsrScanResultFilter *pScanFilter;
6461 tCsrScanResultInfo *pScanResult;
6462 tScanResultHandle hBSSList;
6463 tANI_U32 nItems = *pNumItems;
6464 *pNumItems = 0;
6465 status = palAllocateMemory(pMac->hHdd, (void **)&pScanFilter, sizeof(tCsrScanResultFilter));
6466 if(HAL_STATUS_SUCCESS(status))
6467 {
6468 palZeroMemory(pMac->hHdd, pScanFilter, sizeof(tCsrScanResultFilter));
6469 //Here is the profile we need to connect to
6470 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6471 if(HAL_STATUS_SUCCESS(status))
6472 {
6473 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6474 if(HAL_STATUS_SUCCESS(status))
6475 {
6476 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
6477 {
6478 //pMac->scan.NumBkidCandidate adds up here
6479 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
6480 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6481
6482 }
6483 if(pSession->NumBkidCandidate)
6484 {
6485 *pNumItems = pSession->NumBkidCandidate;
6486 palCopyMemory(pMac->hHdd, pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
6487 }
6488 csrScanResultPurge(pMac, hBSSList);
6489 }//Have scan result
6490 }
6491 palFreeMemory(pMac->hHdd, pScanFilter);
6492 }
6493 }
6494
6495 return (status);
6496}
6497#endif /* FEATURE_WLAN_WAPI */
6498
6499
6500
6501//This function is usually used for BSSs that suppresses SSID so the profile
6502//shall have one and only one SSID
6503eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId)
6504{
6505 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6506 tSmeCmd *pScanCmd = NULL;
6507 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
6508 tANI_U8 index = 0;
6509 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
6510
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006511 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006512 //For WDS, we use the index 0. There must be at least one in there
6513 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
6514 {
6515 numSsid = 1;
6516 }
6517 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
6518 {
6519 do
6520 {
6521 pScanCmd = csrGetCommandBuffer(pMac);
6522 if(!pScanCmd)
6523 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006524 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006525 break;
6526 }
6527 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
6528 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.pToRoamProfile, sizeof(tCsrRoamProfile));
6529 if(!HAL_STATUS_SUCCESS(status))
6530 break;
6531 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
6532 if(!HAL_STATUS_SUCCESS(status))
6533 break;
6534 pScanCmd->u.scanCmd.roamId = roamId;
6535 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07006536 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07006537 pScanCmd->u.scanCmd.callback = NULL;
6538 pScanCmd->u.scanCmd.pContext = NULL;
6539 pScanCmd->u.scanCmd.reason = eCsrScanForSsid;
6540 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6541 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest));
6542 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07006543 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07006544 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
6545 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
6546 {
6547 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
6548 }
6549 if(pProfile->pAddIEScan)
6550 {
6551 status = palAllocateMemory(pMac->hHdd,
6552 (void **)&pScanCmd->u.scanCmd.u.scanRequest.pIEField,
6553 pProfile->nAddIEScanLength);
6554 palZeroMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.pIEField, pProfile->nAddIEScanLength);
6555 if(HAL_STATUS_SUCCESS(status))
6556 {
6557 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.pIEField, pProfile->pAddIEScan, pProfile->nAddIEScanLength);
6558 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
6559 }
6560 else
6561 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006562 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07006563 }
6564 } //Allocate memory for IE field
6565 else
6566 {
6567 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
6568 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07006569 /* For one channel be good enpugh time to receive beacon atleast */
6570 if( 1 == pProfile->ChannelInfo.numOfChannels )
6571 {
6572 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
6573 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
6574 }
6575 else
6576 {
6577 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
6578 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
6579 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08006580 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
6581 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07006582 if(pProfile->BSSIDs.numOfBSSIDs == 1)
6583 {
6584 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.bssid, pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
6585 }
6586 else
6587 {
6588 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
6589 }
6590 if(pProfile->ChannelInfo.numOfChannels)
6591 {
6592 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList) * pProfile->ChannelInfo.numOfChannels);
6593 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
6594 if(HAL_STATUS_SUCCESS(status))
6595 {
6596 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
6597 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
6598 {
6599 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
6600 {
6601 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
6602 = pProfile->ChannelInfo.ChannelList[index];
6603 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
6604 }
6605 else
6606 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006607 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07006608 }
6609
6610 }
6611 }
6612 else
6613 {
6614 break;
6615 }
6616
6617 }
6618 else
6619 {
6620 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
6621 }
6622 if(pProfile->SSIDs.numOfSSIDs)
6623 {
6624 status = palAllocateMemory(pMac->hHdd, (void **)&pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
6625 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
6626 if(!HAL_STATUS_SUCCESS(status))
6627 {
6628 break;
6629 }
6630 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
6631 palCopyMemory(pMac->hHdd, pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList, pProfile->SSIDs.SSIDList,
6632 sizeof(tCsrSSIDInfo));
6633 }
6634 //Start process the command
6635 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
6636 if( !HAL_STATUS_SUCCESS( status ) )
6637 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006638 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006639 break;
6640 }
6641 }while(0);
6642 if(!HAL_STATUS_SUCCESS(status))
6643 {
6644 if(pScanCmd)
6645 {
6646 csrReleaseCommandScan(pMac, pScanCmd);
6647 //TODO:free the memory that is allocated in this function
6648 }
6649 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
6650 }
6651 }//valid
6652 else
6653 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006654 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07006655 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
6656 }
6657
6658 return (status);
6659}
6660
6661
6662//Issue a scan base on the new capability infomation
6663//This should only happen when the associated AP changes its capability.
6664//After this scan is done, CSR reroams base on the new scan results
6665eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
6666{
6667 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6668 tSmeCmd *pScanCmd = NULL;
6669
6670 if(pNewCaps)
6671 {
6672 do
6673 {
6674 pScanCmd = csrGetCommandBuffer(pMac);
6675 if(!pScanCmd)
6676 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006677 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006678 status = eHAL_STATUS_RESOURCES;
6679 break;
6680 }
6681 palZeroMemory(pMac->hHdd, &pScanCmd->u.scanCmd, sizeof(tScanCmd));
6682 status = eHAL_STATUS_SUCCESS;
6683 pScanCmd->u.scanCmd.roamId = 0;
6684 pScanCmd->command = eSmeCommandScan;
6685 pScanCmd->u.scanCmd.callback = NULL;
6686 pScanCmd->u.scanCmd.pContext = NULL;
6687 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
6688 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6689 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
6690 if( !HAL_STATUS_SUCCESS( status ) )
6691 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006692 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006693 break;
6694 }
6695 }while(0);
6696 if(!HAL_STATUS_SUCCESS(status))
6697 {
6698 if(pScanCmd)
6699 {
6700 csrReleaseCommandScan(pMac, pScanCmd);
6701 }
6702 }
6703 }
6704
6705 return (status);
6706}
6707
6708
6709
6710void csrInitBGScanChannelList(tpAniSirGlobal pMac)
6711{
6712 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
6713
6714 palZeroMemory(pMac->hHdd, pMac->scan.bgScanChannelList, len);
6715 pMac->scan.numBGScanChannel = 0;
6716
6717 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6718 {
6719 pMac->roam.numValidChannels = len;
6720 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
6721 palCopyMemory(pMac->hHdd, pMac->scan.bgScanChannelList, pMac->roam.validChannelList, pMac->scan.numBGScanChannel);
6722 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
6723 }
6724}
6725
6726
6727//This function return TRUE if background scan channel list is adjusted.
6728//this function will only shrink the background scan channel list
6729tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
6730 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
6731{
6732 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6733 tANI_U8 i, j, count = *pNumAdjustChannels;
6734
6735 i = 0;
6736 while(i < count)
6737 {
6738 for(j = 0; j < NumChannels; j++)
6739 {
6740 if(pChannelList[j] == pAdjustChannels[i])
6741 break;
6742 }
6743 if(j == NumChannels)
6744 {
6745 //This channel is not in the list, remove it
6746 fRet = eANI_BOOLEAN_TRUE;
6747 count--;
6748 if(count - i)
6749 {
6750 palCopyMemory(pMac->hHdd, &pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
6751 }
6752 else
6753 {
6754 //already remove the last one. Done.
6755 break;
6756 }
6757 }
6758 else
6759 {
6760 i++;
6761 }
6762 }//while(i<count)
6763 *pNumAdjustChannels = count;
6764
6765 return (fRet);
6766}
6767
6768
6769//Get the list of the base channels to scan for passively 11d info
6770eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
6771{
6772 eHalStatus status = eHAL_STATUS_SUCCESS;
6773 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
6774
6775 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
6776 if( HAL_STATUS_SUCCESS(status) )
6777 {
6778 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
6779 }
6780 else
6781 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006782 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006783 pMac->scan.baseChannels.numChannels = 0;
6784 }
6785
6786 return ( status );
6787}
6788
6789//This function use the input pChannelList to validate the current saved channel list
6790eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
6791{
6792 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
6793
6794 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
6795}
6796
6797
6798void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
6799{
6800 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
6801
6802
6803 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
6804
6805 return;
6806}
6807
6808
6809
6810/*
6811 * The Tx power limits are saved in the cfg for future usage.
6812 */
6813void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
6814{
6815 tListElem *pEntry;
6816 tANI_U32 cbLen = 0, dataLen;
6817 tCsrChannelPowerInfo *pChannelSet;
6818 tANI_U32 idx;
6819 tSirMacChanInfo *pChannelPowerSet;
6820 tANI_U8 *pBuf = NULL;
6821
6822 //allocate maximum space for all channels
6823 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
6824 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pBuf, dataLen)))
6825 {
6826 palZeroMemory(pMac->hHdd, pBuf, dataLen);
6827 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
6828
6829 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
6830 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
6831 while( pEntry )
6832 {
6833 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
6834 if ( 1 != pChannelSet->interChannelOffset )
6835 {
6836 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
6837 // to the right format... (inter channel offset of 1 is the only option for the triplets
6838 // that 11d advertises.
6839 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
6840 {
6841 // expanding this entry will overflow our allocation
6842 smsLog(pMac, LOGE,
6843 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006844 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006845 pChannelSet->firstChannel,
6846 pChannelSet->numChannels,
6847 pChannelSet->interChannelOffset);
6848 break;
6849 }
6850
6851 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
6852 {
6853 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006854 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07006855 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07006856 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006857 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07006858 cbLen += sizeof( tSirMacChanInfo );
6859 pChannelPowerSet++;
6860 }
6861 }
6862 else
6863 {
6864 if (cbLen >= dataLen)
6865 {
6866 // this entry will overflow our allocation
6867 smsLog(pMac, LOGE,
6868 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006869 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07006870 pChannelSet->firstChannel,
6871 pChannelSet->numChannels,
6872 pChannelSet->interChannelOffset);
6873 break;
6874 }
6875 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006876 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07006877 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07006878 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006879 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07006880
6881
6882 cbLen += sizeof( tSirMacChanInfo );
6883 pChannelPowerSet++;
6884 }
6885
6886 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
6887 }
6888
6889 if(cbLen)
6890 {
6891 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
6892 }
6893 palFreeMemory( pMac->hHdd, pBuf );
6894 }//Allocate memory
6895}
6896
6897
6898void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
6899{
6900 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
6901 ///v_REGDOMAIN_t DomainId;
6902
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006903 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Jeff Johnson295189b2012-06-20 16:38:30 -07006904 palCopyMemory( pMac->hHdd, cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN );
6905
6906 // don't program the bogus country codes that we created for Korea in the MAC. if we see
6907 // the bogus country codes, program the MAC with the right country code.
6908 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
6909 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
6910 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
6911 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
6912 {
6913 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
6914 cc[ 1 ] = 'R';
6915 }
6916 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
6917
6918 //Need to let HALPHY know about the current domain so it can apply some
6919 //domain-specific settings (TX filter...)
6920 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
6921 {
6922 halPhySetRegDomain(pMac, DomainId);
6923 }*/
6924}
6925
6926
6927
6928eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
6929{
6930 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6931 tANI_U32 len;
6932
6933 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
6934 {
6935 len = *pbLen;
6936 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
6937 if(HAL_STATUS_SUCCESS(status))
6938 {
6939 *pbLen = (tANI_U8)len;
6940 }
6941 }
6942
6943 return (status);
6944}
6945
6946
6947void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
6948{
6949 tANI_U8 i, j;
6950 tANI_BOOLEAN found=FALSE;
6951 tANI_U8 *pControlList = NULL;
6952 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
6953
6954 if(HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, (void **)&pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN)))
6955 {
6956 palZeroMemory(pMac->hHdd, (void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN);
6957 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
6958 {
6959 for (i = 0; i < pChannelList->numChannels; i++)
6960 {
6961 for (j = 0; j < len; j += 2)
6962 {
6963 if (pControlList[j] == pChannelList->channelList[i])
6964 {
6965 found = TRUE;
6966 break;
6967 }
6968 }
6969
6970 if (found) // insert a pair(channel#, flag)
6971 {
6972 if (CSR_IS_CHANNEL_5GHZ(pControlList[j]))
6973 {
6974 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
6975 }
6976 else
6977 {
6978 pControlList[j+1] = eSIR_ACTIVE_SCAN;
6979 }
6980
6981 found = FALSE; // reset the flag
6982 }
6983
6984 }
6985
6986 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
6987 }//Successfully getting scan control list
6988 palFreeMemory(pMac->hHdd, pControlList);
6989 }//AllocateMemory
6990}
6991
6992
6993//if bgPeriod is 0, background scan is disabled. It is in millisecond units
6994eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
6995{
6996 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
6997}
6998
6999
7000void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7001{
7002 tListElem *pEntry = NULL;
7003 tSmeCmd *pCommand = NULL;
7004 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
7005
7006 pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
7007 if ( pEntry )
7008 {
7009 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7010 if ( eSmeCommandScan == pCommand->command )
7011 {
7012 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7013 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7014 }
7015 else
7016 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007017 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007018 }
7019 }
7020 smeProcessPendingQueue( pMac );
7021}
7022
7023eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7024{
7025 eHalStatus status;
7026 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7027 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7028
7029 //***setcfg for background scan channel list
7030 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7031 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7032 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7033 if(!csrIsAllSessionDisconnected(pMac))
7034 {
7035 //If disbaling BG scan here, we need to stop aging as well
7036 if(pScanReq->scanInterval == 0)
7037 {
7038 //Stop aging because no new result is coming in
7039 csrScanStopResultAgingTimer(pMac);
7040 }
7041
7042#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7043 {
7044 vos_log_scan_pkt_type *pScanLog = NULL;
7045
7046 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7047 if(pScanLog)
7048 {
7049 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7050 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7051 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7052 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7053 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7054 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7055 {
7056 palCopyMemory(pMac->hHdd, pScanLog->channels, pScanReq->ChannelInfo.ChannelList,
7057 pScanLog->numChannel);
7058 }
7059 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7060 }
7061 }
7062#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7063
7064 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7065 }
7066 else
7067 {
7068 //No need to stop aging because IDLE scan is still running
7069 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7070 }
7071
7072 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7073 {
7074 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7075 }
7076
7077 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7078 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7079
7080
7081
7082 return (status);
7083}
7084
7085
7086eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac)
7087{
7088 eHalStatus status = eHAL_STATUS_SUCCESS;
7089 tSirMbMsg *pMsg;
7090 tANI_U16 msgLen;
7091 tListElem *pEntry;
7092 tSmeCmd *pCommand;
7093
7094#ifdef WLAN_AP_STA_CONCURRENCY
7095 csrLLLock(&pMac->scan.scanCmdPendingList);
7096 while( NULL != ( pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7097 {
7098
7099 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7100 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7101 }
7102 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7103#endif
7104
7105 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7106 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7107 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7108 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7109
7110 //We need to abort scan only if we are scanning
7111 if(NULL != (pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK)))
7112 {
7113 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7114 if(eSmeCommandScan == pCommand->command)
7115 {
7116 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
7117 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
7118 if(HAL_STATUS_SUCCESS(status))
7119 {
7120 palZeroMemory(pMac->hHdd, (void *)pMsg, msgLen);
7121 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7122 pMsg->msgLen = pal_cpu_to_be16(msgLen);
7123 status = palSendMBMessage(pMac->hHdd, pMsg);
7124 }
7125 }
7126 }
7127
7128 return( status );
7129}
7130
7131void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7132 eSmeCommandType commandType )
7133{
7134 tDblLinkList localList;
7135 tListElem *pEntry;
7136 tSmeCmd *pCommand;
7137 tListElem *pEntryToRemove;
7138
7139 vos_mem_zero(&localList, sizeof(tDblLinkList));
7140 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7141 {
7142 smsLog(pMac, LOGE, FL(" failed to open list"));
7143 return;
7144 }
7145
7146 csrLLLock(pList);
7147 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7148 {
7149 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7150
7151 // Have to make sure we don't loop back to the head of the list, which will
7152 // happen if the entry is NOT on the list...
7153 while( pEntry )
7154 {
7155 pEntryToRemove = pEntry;
7156 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7157 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7158 if ( pCommand->command == commandType )
7159 {
7160 // Remove that entry only
7161 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7162 {
7163 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7164 }
7165 }
7166 }
7167
7168
7169 }
7170 csrLLUnlock(pList);
7171
7172 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7173 {
7174 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7175 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7176 }
7177 csrLLClose(&localList);
7178
7179}
7180
7181
7182eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac)
7183{
7184 eHalStatus status = eHAL_STATUS_SUCCESS;
7185
7186 if( !csrIsScanForRoamCommandActive( pMac ) )
7187 {
7188 //Only abort the scan if it is not used for other roam/connect purpose
7189 status = csrScanAbortMacScan(pMac);
7190 }
7191
7192 return (status);
7193}
7194
7195
7196eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac)
7197{
7198 eHalStatus status = eHAL_STATUS_SUCCESS;
7199 tSirMbMsg *pMsg;
7200 tANI_U16 msgLen;
7201
7202 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
7203 status = palAllocateMemory(pMac->hHdd, (void **)&pMsg, msgLen);
7204 if(HAL_STATUS_SUCCESS(status))
7205 {
7206 palZeroMemory(pMac->hHdd, pMsg, msgLen);
7207 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7208 pMsg->msgLen = msgLen;
7209 status = palSendMBMessage(pMac->hHdd, pMsg);
7210 }
7211
7212 return( status );
7213}
7214
7215tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7216{
7217 tANI_BOOLEAN fValid = FALSE;
7218 tANI_U32 idxValidChannels;
7219 tANI_U32 len = pMac->roam.numValidChannels;
7220
7221 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
7222 {
7223 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
7224 {
7225 fValid = TRUE;
7226 break;
7227 }
7228 }
7229
7230 return fValid;
7231}
7232
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007233#ifdef FEATURE_WLAN_LFR
7234void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
7235{
7236 tListElem *pEntry = NULL;
7237 tCsrScanResult *pBssDesc = NULL;
7238 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08007239 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
7240
7241 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
7242 {
7243 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007244 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08007245 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
7246 return;
7247 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007248
7249 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
7250 {
7251 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007252 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007253 __func__, pMac->scan.occupiedChannels.numChannels);
7254 return;
7255 }
7256
7257 /* Empty occupied channels here */
7258 pMac->scan.occupiedChannels.numChannels = 0;
7259
7260 csrLLLock(&pMac->scan.scanResultList);
7261 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
7262 while( pEntry )
7263 {
7264 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7265 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
7266
7267 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08007268 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007269 &pBssDesc->Result.BssDescriptor, &pIes))) )
7270 {
7271 continue;
7272 }
7273
7274 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
7275
7276 /*
7277 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
7278 */
7279 if( (pBssDesc->Result.pvIes == NULL) && pIes )
7280 {
7281 palFreeMemory(pMac->hHdd, pIes);
7282 }
7283
7284 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
7285 }//while
7286 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08007287
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007288}
7289#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007290