blob: f7111cd20b2a4afc7faba410f6709d8e87f6e3ee [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Peng Xu2446a892014-09-05 17:21:18 +05302 * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
Kiet Lam0fb93dd2014-02-19 00:32:59 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam0fb93dd2014-02-19 00:32:59 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Jeff Johnson295189b2012-06-20 16:38:30 -070028/*===========================================================================
29
30 s a p C h S e l e c t . C
Jeff Johnson295189b2012-06-20 16:38:30 -070031 OVERVIEW:
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053032
Jeff Johnson295189b2012-06-20 16:38:30 -070033 This software unit holds the implementation of the WLAN SAP modules
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053034 functions for channel selection.
Jeff Johnson295189b2012-06-20 16:38:30 -070035
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053036 DEPENDENCIES:
Jeff Johnson295189b2012-06-20 16:38:30 -070037
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053038 Are listed for each API below.
Jeff Johnson295189b2012-06-20 16:38:30 -070039===========================================================================*/
40
41/*===========================================================================
42
43 EDIT HISTORY FOR FILE
44
45
46 This section contains comments describing changes made to the module.
47 Notice that changes are listed in reverse chronological order.
48
49
50
51 when who what, where, why
52---------- --- --------------------------------------------------------
532010-03-15 SOFTAP Created module
54
55===========================================================================*/
56
57
58/*--------------------------------------------------------------------------
59 Include Files
60------------------------------------------------------------------------*/
61#include "vos_trace.h"
62#include "csrApi.h"
63#include "sme_Api.h"
64#include "sapChSelect.h"
65#include "sapInternal.h"
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -080066#ifdef ANI_OS_TYPE_QNX
67#include "stdio.h"
68#endif
Peng Xuafc34e32014-09-25 13:23:55 +053069#include "wlan_hdd_main.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070070
71/*--------------------------------------------------------------------------
72 Function definitions
73--------------------------------------------------------------------------*/
74
75/*--------------------------------------------------------------------------
76 Defines
77--------------------------------------------------------------------------*/
78#define SAP_DEBUG
79
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -070080#define IS_RSSI_VALID( extRssi, rssi ) \
81( \
82 ((extRssi < rssi)?eANI_BOOLEAN_TRUE:eANI_BOOLEAN_FALSE) \
83)
84
Leo Chang0b0e45a2013-12-15 15:18:55 -080085#ifdef FEATURE_WLAN_CH_AVOID
86extern safeChannelType safeChannels[];
87#endif /* FEATURE_WLAN_CH_AVOID */
88
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070089/*==========================================================================
90 FUNCTION sapCleanupChannelList
91
92 DESCRIPTION
93 Function sapCleanupChannelList frees up the memory allocated to the channel list.
94
95 DEPENDENCIES
96 NA.
97
98 PARAMETERS
99
100 IN
101 NULL
102
103 RETURN VALUE
104 NULL
105============================================================================*/
106
107void sapCleanupChannelList(void)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700108{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700109 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530110 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700111
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700112 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
113 "Cleaning up the channel list structure");
114
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530115 if (NULL == pvosGCtx)
116 {
117 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
118 "SAP Global Context is NULL");
119 return ;
120 }
121
122 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
123 if (NULL == pSapCtx)
124 {
125 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
126 "SAP Context is NULL");
127 return ;
128 }
129
130 pSapCtx->SapChnlList.numChannel = 0;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700131 vos_mem_free(pSapCtx->SapChnlList.channelList);
132 pSapCtx->SapChnlList.channelList = NULL;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700133}
134
Peng Xu7d410f42014-09-09 12:15:47 +0530135typedef struct
136{
137 v_U16_t chStartNum;
138 v_U32_t weight;
139} sapAcsChannelInfo;
140
141#define ACS_WEIGHT_MAX 4444
142
Peng Xu117eab42014-09-25 13:33:27 +0530143sapAcsChannelInfo acsHT40Channels5G[ ] = {
Peng Xu7d410f42014-09-09 12:15:47 +0530144 {36, ACS_WEIGHT_MAX},
145 {44, ACS_WEIGHT_MAX},
146 {52, ACS_WEIGHT_MAX},
147 {60, ACS_WEIGHT_MAX},
148 {100, ACS_WEIGHT_MAX},
149 {108, ACS_WEIGHT_MAX},
150 {116, ACS_WEIGHT_MAX},
151 {124, ACS_WEIGHT_MAX},
152 {132, ACS_WEIGHT_MAX},
153 {140, ACS_WEIGHT_MAX},
154 {149, ACS_WEIGHT_MAX},
155 {157, ACS_WEIGHT_MAX},
156};
157
158sapAcsChannelInfo acsHT80Channels[ ] = {
159 {36, ACS_WEIGHT_MAX},
160 {52, ACS_WEIGHT_MAX},
161 {100, ACS_WEIGHT_MAX},
162 {116, ACS_WEIGHT_MAX},
163 {132, ACS_WEIGHT_MAX},
164 {149, ACS_WEIGHT_MAX},
165};
166
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +0530167sapAcsChannelInfo acsHT40Channels24G[ ] = {
168 {1, ACS_WEIGHT_MAX},
169 {2, ACS_WEIGHT_MAX},
170 {3, ACS_WEIGHT_MAX},
171 {4, ACS_WEIGHT_MAX},
172 {9, ACS_WEIGHT_MAX},
173};
174
Peng Xu117eab42014-09-25 13:33:27 +0530175typedef enum {
176 CHWIDTH_HT20,
177 CHWIDTH_HT40,
178 CHWIDTH_HT80,
179} eChannelWidthInfo;
180
181#define CHANNEL_165 165
182
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700183/*==========================================================================
184 FUNCTION sapSetPreferredChannel
185
186 DESCRIPTION
187 Function sapSetPreferredChannel sets the channel list which has been configured
188 into sap context (pSapCtx) which will be used at the time of best channel selection.
189
190 DEPENDENCIES
191 NA.
192
193 PARAMETERS
194
195 IN
196 *ptr: pointer having the command followed by the arguments in string format
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700197
198 RETURN VALUE
199 int: return 0 when success else returns error code.
200============================================================================*/
201
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800202int sapSetPreferredChannel(tANI_U8* ptr)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700203{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700204
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700205 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530206 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700207 tANI_U8* param;
208 int tempInt;
209 int j;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700210
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700211 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700212 "Enter: %s", __func__);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700213
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530214 if (NULL == pvosGCtx)
215 {
216 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
217 "SAP Global Context is NULL");
218 return -EINVAL;
219 }
220
221 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
222 if (NULL == pSapCtx)
223 {
224 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
225 "SAP Context is NULL");
226 return -EINVAL;
227 }
228
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700229 if (NULL != pSapCtx->SapChnlList.channelList)
230 {
231 sapCleanupChannelList();
232 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700233
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800234 param = strchr(ptr, ' ');
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700235 /*no argument after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800236 if (NULL == param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700237 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800238 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700239 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700240
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700241 /*no space after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800242 else if (SPACE_ASCII_VALUE != *param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700243 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800244 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700245 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700246
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700247 param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700248
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700249 /*removing empty spaces*/
250 while((SPACE_ASCII_VALUE == *param)&& ('\0' != *param) ) param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700251
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700252 /*no argument followed by spaces*/
253 if('\0' == *param)
254 {
255 return -EINVAL;
256 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700257
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700258 /*getting the first argument ie the number of channels*/
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800259 if (sscanf(param, "%d ", &tempInt) != 1)
260 {
261 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800262 "%s: Cannot get number of channels from input", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800263 return -EINVAL;
264 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700265
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700266 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800267 "%s: Number of channel added are: %d", __func__, tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700268
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800269 if (tempInt <= 0 || tempInt > 255)
270 {
271 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800272 "%s: Invalid Number of channel received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800273 return -EINVAL;
274 }
275
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700276 /*allocating space for the desired number of channels*/
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530277 pSapCtx->SapChnlList.channelList = (v_U8_t *)vos_mem_malloc(tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700278
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530279 if (NULL == pSapCtx->SapChnlList.channelList)
280 {
281 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
282 "In %s, VOS_MALLOC_ERR", __func__);
283 return -EINVAL;
284 }
285
286 pSapCtx->SapChnlList.numChannel = tempInt;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700287 for(j=0;j<pSapCtx->SapChnlList.numChannel;j++)
288 {
289
290 /*param pointing to the beginning of first space after number of channels*/
291 param = strpbrk( param, " " );
292 /*no channel list after the number of channels argument*/
293 if (NULL == param)
294 {
295 sapCleanupChannelList();
296 return -EINVAL;
297 }
298
299 param++;
300
301 /*removing empty space*/
302 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
303
304 /*no channel list after the number of channels argument and spaces*/
305 if( '\0' == *param )
306 {
307 sapCleanupChannelList();
308 return -EINVAL;
309 }
310
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800311 if (sscanf(param, "%d ", &tempInt) != 1)
312 {
313 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800314 "%s: Cannot read channel number", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800315 sapCleanupChannelList();
316 return -EINVAL;
317 }
318 if (tempInt < 0 || tempInt > 255)
319 {
320 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800321 "%s: Invalid channel number received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800322 sapCleanupChannelList();
323 return -EINVAL;
324 }
325
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700326 pSapCtx->SapChnlList.channelList[j] = tempInt;
327
328 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800329 "%s: Channel %d added to preferred channel list",
330 __func__, pSapCtx->SapChnlList.channelList[j] );
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700331
332 }
333
334 /*extra arguments check*/
335 param = strpbrk( param, " " );
336 if (NULL != param)
337 {
338 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
339
340 if('\0' != *param)
341 {
342 sapCleanupChannelList();
343 return -EINVAL;
344 }
345 }
346
347 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700348 "Exit: %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700349
350 return 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700351}
352
353/*==========================================================================
354 FUNCTION sapSelectPreferredChannelFromChannelList
355
356 DESCRIPTION
357 Function sapSelectPreferredChannelFromChannelList calculates the best channel
358 among the configured channel list. If channel list not configured then returns
359 the best channel calculated among all the channel list.
360
361 DEPENDENCIES
362 NA.
363
364 PARAMETERS
365
366 IN
367 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
368 bestChNum: best channel already calculated among all the chanels
369 pSapCtx: having info of channel list from which best channel is selected
370
371 RETURN VALUE
372 v_U8_t: best channel
373============================================================================*/
374v_U8_t sapSelectPreferredChannelFromChannelList(v_U8_t bestChNum,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700375 ptSapContext pSapCtx,
376 tSapChSelSpectInfo *pSpectInfoParams)
377{
378 v_U8_t j = 0;
379 v_U8_t count = 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700380
381 //If Channel List is not Configured don't do anything
382 //Else return the Best Channel from the Channel List
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700383 if((NULL == pSapCtx->SapChnlList.channelList) ||
384 (NULL == pSpectInfoParams) ||
385 (0 == pSapCtx->SapChnlList.numChannel))
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700386 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700387 return bestChNum;
388 }
389
390 if (bestChNum > 0 && bestChNum <= 252)
391 {
392 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700393 {
394 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
395 // Select the best channel from allowed list
396 for(j=0;j< pSapCtx->SapChnlList.numChannel;j++)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700397 {
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700398 if( (pSapCtx->SapChnlList.channelList[j]) == bestChNum)
399 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700400 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
401 "Best channel computed from Channel List is: %d",
402 bestChNum);
403 return bestChNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700404 }
405 }
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700406 }
407
408 return SAP_CHANNEL_NOT_SELECTED;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700409 }
410 else
411 return SAP_CHANNEL_NOT_SELECTED;
412}
413
414
Jeff Johnson295189b2012-06-20 16:38:30 -0700415/*==========================================================================
416 FUNCTION sapChanSelInit
417
418 DESCRIPTION
419 Function sapChanSelInit allocates the memory, intializes the
420 structures used by the channel selection algorithm
421
422 DEPENDENCIES
423 NA.
424
425 PARAMETERS
426
427 IN
428 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
429
430 RETURN VALUE
431 v_BOOL_t: Success or FAIL
432
433 SIDE EFFECTS
434============================================================================*/
435v_BOOL_t sapChanSelInit(tHalHandle halHandle, tSapChSelSpectInfo *pSpectInfoParams)
436{
437 tSapSpectChInfo *pSpectCh = NULL;
438 v_U8_t *pChans = NULL;
439 v_U16_t channelnum = 0;
440 tpAniSirGlobal pMac = PMAC_STRUCT(halHandle);
Leo Chang0b0e45a2013-12-15 15:18:55 -0800441#ifdef FEATURE_WLAN_CH_AVOID
442 v_U16_t i;
443 v_BOOL_t chSafe = VOS_TRUE;
444#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700445
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700446 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700447
448 // Channels for that 2.4GHz band
449 //Considered only for 2.4GHz need to change in future to support 5GHz support
450 pSpectInfoParams->numSpectChans = pMac->scan.base20MHzChannels.numChannels;
451
452 // Allocate memory for weight computation of 2.4GHz
453 pSpectCh = (tSapSpectChInfo *)vos_mem_malloc((pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
454
455 if(pSpectCh == NULL) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700456 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, VOS_MALLOC_ERR", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700457 return eSAP_FALSE;
458 }
459
460 vos_mem_zero(pSpectCh, (pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
461
462 // Initialize the pointers in the DfsParams to the allocated memory
463 pSpectInfoParams->pSpectCh = pSpectCh;
464
465 pChans = pMac->scan.base20MHzChannels.channelList;
466
467 // Fill the channel number in the spectrum in the operating freq band
468 for (channelnum = 0; channelnum < pSpectInfoParams->numSpectChans; channelnum++) {
Leo Chang0b0e45a2013-12-15 15:18:55 -0800469#ifdef FEATURE_WLAN_CH_AVOID
470 chSafe = VOS_TRUE;
471 for(i = 0; i < NUM_20MHZ_RF_CHANNELS; i++)
472 {
473 if((safeChannels[i].channelNumber == *pChans) &&
474 (VOS_FALSE == safeChannels[i].isSafe))
475 {
476 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
477 "%s : CH %d is not safe", __func__, *pChans);
478 chSafe = VOS_FALSE;
479 break;
480 }
481 }
482#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700483
484 if(*pChans == 14 ) //OFDM rates are not supported on channel 14
Abhishek Singhb51853c2014-03-13 18:26:41 +0530485 {
486 pChans++;
Kaushik, Sushante054e472014-09-26 19:45:48 +0530487 pSpectCh++;
Jeff Johnson295189b2012-06-20 16:38:30 -0700488 continue;
Abhishek Singhb51853c2014-03-13 18:26:41 +0530489 }
Leo Chang0b0e45a2013-12-15 15:18:55 -0800490#ifdef FEATURE_WLAN_CH_AVOID
491 if (VOS_TRUE == chSafe)
492 {
493#endif /* FEATURE_WLAN_CH_AVOID */
494 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_DEBUG,
495 "%s : Available Ch %d",
496 __func__, *pChans);
497 pSpectCh->chNum = *pChans;
498 pSpectCh->valid = eSAP_TRUE;
499 // Initialise for all channels
500 pSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
501 // Initialise 20MHz for all the Channels
502 pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH;
Leo Chang0b0e45a2013-12-15 15:18:55 -0800503#ifdef FEATURE_WLAN_CH_AVOID
504 }
505#endif /* FEATURE_WLAN_CH_AVOID */
Kaushik, Sushante054e472014-09-26 19:45:48 +0530506 pSpectCh++;
Jeff Johnson295189b2012-06-20 16:38:30 -0700507 pChans++;
508 }
509 return eSAP_TRUE;
510}
511
512/*==========================================================================
513 FUNCTION sapweightRssiCount
514
515 DESCRIPTION
516 Function weightRssiCount calculates the channel weight due to rssi
517 and data count(here number of BSS observed)
518
519 DEPENDENCIES
520 NA.
521
522 PARAMETERS
523
524 IN
525 rssi : Max signal strength receieved from a BSS for the channel
526 count : Number of BSS observed in the channel
527
528 RETURN VALUE
529 v_U32_t : Calculated channel weight based on above two
530
531 SIDE EFFECTS
532============================================================================*/
533v_U32_t sapweightRssiCount(v_S7_t rssi, v_U16_t count)
534{
535 v_S31_t rssiWeight=0;
536 v_S31_t countWeight=0;
537 v_U32_t rssicountWeight=0;
538
539 // Weight from RSSI
540 rssiWeight = SOFTAP_RSSI_WEIGHT * (rssi - SOFTAP_MIN_RSSI)
541 /(SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530542
Jeff Johnson295189b2012-06-20 16:38:30 -0700543 if(rssiWeight > SOFTAP_RSSI_WEIGHT)
544 rssiWeight = SOFTAP_RSSI_WEIGHT;
545 else if (rssiWeight < 0)
546 rssiWeight = 0;
547
548 // Weight from data count
549 countWeight = SOFTAP_COUNT_WEIGHT * (count - SOFTAP_MIN_COUNT)
550 /(SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530551
Jeff Johnson295189b2012-06-20 16:38:30 -0700552 if(countWeight > SOFTAP_COUNT_WEIGHT)
553 countWeight = SOFTAP_COUNT_WEIGHT;
554 else if (countWeight < 0)
555 countWeight = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530556
Jeff Johnson295189b2012-06-20 16:38:30 -0700557 rssicountWeight = rssiWeight + countWeight;
558
559 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, rssiWeight=%d, countWeight=%d, rssicountWeight=%d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700560 __func__, rssiWeight, countWeight, rssicountWeight);
Jeff Johnson295189b2012-06-20 16:38:30 -0700561
562 return(rssicountWeight);
563}
564
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800565
566/*==========================================================================
567 FUNCTION sapInterferenceRssiCount
568
569 DESCRIPTION
570 Function sapInterferenceRssiCount Considers the Adjacent channel rssi
571 and data count(here number of BSS observed)
572
573 DEPENDENCIES
574 NA.
575
576 PARAMETERS
577
578 pSpectCh : Channel Information
579
580 RETURN VALUE
581 NA.
582
583 SIDE EFFECTS
584============================================================================*/
585void sapInterferenceRssiCount(tSapSpectChInfo *pSpectCh)
586{
587 tSapSpectChInfo *pExtSpectCh = NULL;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700588 v_S31_t rssi;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530589
Abhishek Singh4eb79062014-04-10 14:48:14 +0530590 if (NULL == pSpectCh)
591 {
592 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
593 "%s: pSpectCh is NULL", __func__);
594 return;
595 }
596
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800597 switch(pSpectCh->chNum)
598 {
599 case CHANNEL_1:
600 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530601 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800602 {
603 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530604 rssi = pSpectCh->rssiAgr +
605 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700606 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
607 {
608 pExtSpectCh->rssiAgr = rssi;
609 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530610 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800611 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
612 }
613 pExtSpectCh = (pSpectCh + 2);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530614 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800615 {
616 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530617 rssi = pSpectCh->rssiAgr +
618 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700619 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
620 {
621 pExtSpectCh->rssiAgr = rssi;
622 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800623 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
624 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
625 }
626 pExtSpectCh = (pSpectCh + 3);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530627 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800628 {
629 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530630 rssi = pSpectCh->rssiAgr +
631 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700632 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
633 {
634 pExtSpectCh->rssiAgr = rssi;
635 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800636 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
637 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
638 }
639 pExtSpectCh = (pSpectCh + 4);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530640 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800641 {
642 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530643 rssi = pSpectCh->rssiAgr +
644 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700645 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
646 {
647 pExtSpectCh->rssiAgr = rssi;
648 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530649 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800650 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
651 }
652 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530653
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800654 case CHANNEL_2:
655 pExtSpectCh = (pSpectCh - 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530656 if (pExtSpectCh != NULL)
657 {
658 ++pExtSpectCh->bssCount;
659 rssi = pSpectCh->rssiAgr +
660 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
661 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
662 {
663 pExtSpectCh->rssiAgr = rssi;
664 }
665 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
666 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
667 }
668 pExtSpectCh = (pSpectCh + 1);
669 if (pExtSpectCh != NULL)
670 {
671 ++pExtSpectCh->bssCount;
672 rssi = pSpectCh->rssiAgr +
673 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
674 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
675 {
676 pExtSpectCh->rssiAgr = rssi;
677 }
678 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
679 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
680 }
681 pExtSpectCh = (pSpectCh + 2);
682 if (pExtSpectCh != NULL)
683 {
684 ++pExtSpectCh->bssCount;
685 rssi = pSpectCh->rssiAgr +
686 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
687 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
688 {
689 pExtSpectCh->rssiAgr = rssi;
690 }
691 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
692 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
693 }
694 pExtSpectCh = (pSpectCh + 3);
695 if (pExtSpectCh != NULL)
696 {
697 ++pExtSpectCh->bssCount;
698 rssi = pSpectCh->rssiAgr +
699 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
700 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
701 {
702 pExtSpectCh->rssiAgr = rssi;
703 }
704 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
705 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
706 }
707 pExtSpectCh = (pSpectCh + 4);
708 if (pExtSpectCh != NULL)
709 {
710 ++pExtSpectCh->bssCount;
711 rssi = pSpectCh->rssiAgr +
712 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
713 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
714 {
715 pExtSpectCh->rssiAgr = rssi;
716 }
717 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
718 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
719 }
720 break;
721 case CHANNEL_3:
722 pExtSpectCh = (pSpectCh - 2);
723 if (pExtSpectCh != NULL)
724 {
725 ++pExtSpectCh->bssCount;
726 rssi = pSpectCh->rssiAgr +
727 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
728 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
729 {
730 pExtSpectCh->rssiAgr = rssi;
731 }
732 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
733 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
734 }
735 pExtSpectCh = (pSpectCh - 1);
736 if (pExtSpectCh != NULL)
737 {
738 ++pExtSpectCh->bssCount;
739 rssi = pSpectCh->rssiAgr +
740 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
741 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
742 {
743 pExtSpectCh->rssiAgr = rssi;
744 }
745 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
746 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
747 }
748 pExtSpectCh = (pSpectCh + 1);
749 if (pExtSpectCh != NULL)
750 {
751 ++pExtSpectCh->bssCount;
752 rssi = pSpectCh->rssiAgr +
753 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
754 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
755 {
756 pExtSpectCh->rssiAgr = rssi;
757 }
758 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
759 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
760 }
761 pExtSpectCh = (pSpectCh + 2);
762 if (pExtSpectCh != NULL)
763 {
764 ++pExtSpectCh->bssCount;
765 rssi = pSpectCh->rssiAgr +
766 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
767 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
768 {
769 pExtSpectCh->rssiAgr = rssi;
770 }
771 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
772 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
773 }
774 pExtSpectCh = (pSpectCh + 3);
775 if (pExtSpectCh != NULL)
776 {
777 ++pExtSpectCh->bssCount;
778 rssi = pSpectCh->rssiAgr +
779 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
780 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
781 {
782 pExtSpectCh->rssiAgr = rssi;
783 }
784 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
785 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
786 }
787 pExtSpectCh = (pSpectCh + 4);
788 if (pExtSpectCh != NULL)
789 {
790 ++pExtSpectCh->bssCount;
791 rssi = pSpectCh->rssiAgr +
792 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
793 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
794 {
795 pExtSpectCh->rssiAgr = rssi;
796 }
797 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
798 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
799 }
800 break;
801 case CHANNEL_4:
802 pExtSpectCh = (pSpectCh - 3);
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800803 if(pExtSpectCh != NULL)
804 {
805 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530806 rssi = pSpectCh->rssiAgr +
807 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
808 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
809 {
810 pExtSpectCh->rssiAgr = rssi;
811 }
812 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
813 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
814 }
815 pExtSpectCh = (pSpectCh - 2);
816 if (pExtSpectCh != NULL)
817 {
818 ++pExtSpectCh->bssCount;
819 rssi = pSpectCh->rssiAgr +
820 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
821 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
822 {
823 pExtSpectCh->rssiAgr = rssi;
824 }
825 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
826 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
827 }
828 pExtSpectCh = (pSpectCh - 1);
829 if (pExtSpectCh != NULL)
830 {
831 ++pExtSpectCh->bssCount;
832 rssi = pSpectCh->rssiAgr +
833 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700834 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
835 {
836 pExtSpectCh->rssiAgr = rssi;
837 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800838 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
839 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
840 }
841 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530842 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800843 {
844 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530845 rssi = pSpectCh->rssiAgr +
846 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
847 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
848 {
849 pExtSpectCh->rssiAgr = rssi;
850 }
851 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
852 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
853 }
854 pExtSpectCh = (pSpectCh + 2);
855 if (pExtSpectCh != NULL)
856 {
857 ++pExtSpectCh->bssCount;
858 rssi = pSpectCh->rssiAgr +
859 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
860 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
861 {
862 pExtSpectCh->rssiAgr = rssi;
863 }
864 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
865 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
866 }
867 pExtSpectCh = (pSpectCh + 3);
868 if (pExtSpectCh != NULL)
869 {
870 ++pExtSpectCh->bssCount;
871 rssi = pSpectCh->rssiAgr +
872 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
873 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
874 {
875 pExtSpectCh->rssiAgr = rssi;
876 }
877 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
878 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
879 }
880 pExtSpectCh = (pSpectCh + 4);
881 if (pExtSpectCh != NULL)
882 {
883 ++pExtSpectCh->bssCount;
884 rssi = pSpectCh->rssiAgr +
885 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
886 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
887 {
888 pExtSpectCh->rssiAgr = rssi;
889 }
890 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
891 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
892 }
893 break;
894
895 case CHANNEL_5:
896 case CHANNEL_6:
897 case CHANNEL_7:
898 pExtSpectCh = (pSpectCh - 4);
899 if (pExtSpectCh != NULL)
900 {
901 ++pExtSpectCh->bssCount;
902 rssi = pSpectCh->rssiAgr +
903 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700904 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
905 {
906 pExtSpectCh->rssiAgr = rssi;
907 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800908 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
909 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
910 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530911 pExtSpectCh = (pSpectCh - 3);
912 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800913 {
914 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530915 rssi = pSpectCh->rssiAgr +
916 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700917 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
918 {
919 pExtSpectCh->rssiAgr = rssi;
920 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800921 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
922 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
923 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530924 pExtSpectCh = (pSpectCh - 2);
925 if (pExtSpectCh != NULL)
926 {
927 ++pExtSpectCh->bssCount;
928 rssi = pSpectCh->rssiAgr +
929 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
930 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
931 {
932 pExtSpectCh->rssiAgr = rssi;
933 }
934 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
935 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
936 }
937 pExtSpectCh = (pSpectCh - 1);
938 if(pExtSpectCh != NULL)
939 {
940 ++pExtSpectCh->bssCount;
941 rssi = pSpectCh->rssiAgr +
942 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
943 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
944 {
945 pExtSpectCh->rssiAgr = rssi;
946 }
947 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
948 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
949 }
950 pExtSpectCh = (pSpectCh + 1);
951 if (pExtSpectCh != NULL)
952 {
953 ++pExtSpectCh->bssCount;
954 rssi = pSpectCh->rssiAgr +
955 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
956 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
957 {
958 pExtSpectCh->rssiAgr = rssi;
959 }
960 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
961 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
962 }
963 pExtSpectCh = (pSpectCh + 2);
964 if(pExtSpectCh != NULL)
965 {
966 ++pExtSpectCh->bssCount;
967 rssi = pSpectCh->rssiAgr +
968 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
969 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
970 {
971 pExtSpectCh->rssiAgr = rssi;
972 }
973 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
974 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
975 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800976 pExtSpectCh = (pSpectCh + 3);
977 if(pExtSpectCh != NULL)
978 {
979 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530980 rssi = pSpectCh->rssiAgr +
981 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
982 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
983 {
984 pExtSpectCh->rssiAgr = rssi;
985 }
986 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
987 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
988 }
989 pExtSpectCh = (pSpectCh + 4);
990 if (pExtSpectCh != NULL)
991 {
992 ++pExtSpectCh->bssCount;
993 rssi = pSpectCh->rssiAgr +
994 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700995 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
996 {
997 pExtSpectCh->rssiAgr = rssi;
998 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800999 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1000 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1001 }
1002 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301003
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001004 case CHANNEL_8:
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001005 pExtSpectCh = (pSpectCh - 4);
1006 if(pExtSpectCh != NULL)
1007 {
1008 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301009 rssi = pSpectCh->rssiAgr +
1010 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1011 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1012 {
1013 pExtSpectCh->rssiAgr = rssi;
1014 }
1015 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1016 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1017 }
1018
1019 pExtSpectCh = (pSpectCh - 3);
1020 if (pExtSpectCh != NULL)
1021 {
1022 ++pExtSpectCh->bssCount;
1023 rssi = pSpectCh->rssiAgr +
1024 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1025 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1026 {
1027 pExtSpectCh->rssiAgr = rssi;
1028 }
1029 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1030 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1031 }
1032 pExtSpectCh = (pSpectCh - 2);
1033 if (pExtSpectCh != NULL)
1034 {
1035 ++pExtSpectCh->bssCount;
1036 rssi = pSpectCh->rssiAgr +
1037 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1038 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1039 {
1040 pExtSpectCh->rssiAgr = rssi;
1041 }
1042 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1043 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1044 }
1045 pExtSpectCh = (pSpectCh - 1);
1046 if (pExtSpectCh != NULL)
1047 {
1048 ++pExtSpectCh->bssCount;
1049 rssi = pSpectCh->rssiAgr +
1050 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1051 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1052 {
1053 pExtSpectCh->rssiAgr = rssi;
1054 }
1055 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1056 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1057 }
1058 pExtSpectCh = (pSpectCh + 1);
1059 if (pExtSpectCh != NULL)
1060 {
1061 ++pExtSpectCh->bssCount;
1062 rssi = pSpectCh->rssiAgr +
1063 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1064 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1065 {
1066 pExtSpectCh->rssiAgr = rssi;
1067 }
1068 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1069 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1070 }
1071 pExtSpectCh = (pSpectCh + 2);
1072 if (pExtSpectCh != NULL)
1073 {
1074 ++pExtSpectCh->bssCount;
1075 rssi = pSpectCh->rssiAgr +
1076 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1077 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1078 {
1079 pExtSpectCh->rssiAgr = rssi;
1080 }
1081 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1082 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1083 }
1084 pExtSpectCh = (pSpectCh + 3);
1085 if (pExtSpectCh != NULL)
1086 {
1087 ++pExtSpectCh->bssCount;
1088 rssi = pSpectCh->rssiAgr +
1089 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1090 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1091 {
1092 pExtSpectCh->rssiAgr = rssi;
1093 }
1094 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1095 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1096 }
1097 break;
1098
1099 case CHANNEL_9:
1100 pExtSpectCh = (pSpectCh - 4);
1101 if (pExtSpectCh != NULL)
1102 {
1103 ++pExtSpectCh->bssCount;
1104 rssi = pSpectCh->rssiAgr +
1105 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001106 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1107 {
1108 pExtSpectCh->rssiAgr = rssi;
1109 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001110 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1111 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1112 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301113
1114 pExtSpectCh = (pSpectCh - 3);
1115 if (pExtSpectCh != NULL)
1116 {
1117 ++pExtSpectCh->bssCount;
1118 rssi = pSpectCh->rssiAgr +
1119 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1120 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1121 {
1122 pExtSpectCh->rssiAgr = rssi;
1123 }
1124 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1125 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1126 }
1127 pExtSpectCh = (pSpectCh - 2);
1128 if (pExtSpectCh != NULL)
1129 {
1130 ++pExtSpectCh->bssCount;
1131 rssi = pSpectCh->rssiAgr +
1132 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1133 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1134 {
1135 pExtSpectCh->rssiAgr = rssi;
1136 }
1137 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1138 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1139 }
1140 pExtSpectCh = (pSpectCh - 1);
1141 if (pExtSpectCh != NULL)
1142 {
1143 ++pExtSpectCh->bssCount;
1144 rssi = pSpectCh->rssiAgr +
1145 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1146 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1147 {
1148 pExtSpectCh->rssiAgr = rssi;
1149 }
1150 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1151 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1152 }
1153 pExtSpectCh = (pSpectCh + 1);
1154 if (pExtSpectCh != NULL)
1155 {
1156 ++pExtSpectCh->bssCount;
1157 rssi = pSpectCh->rssiAgr +
1158 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1159 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1160 {
1161 pExtSpectCh->rssiAgr = rssi;
1162 }
1163 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1164 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1165 }
1166 pExtSpectCh = (pSpectCh + 2);
1167 if (pExtSpectCh != NULL)
1168 {
1169 ++pExtSpectCh->bssCount;
1170 rssi = pSpectCh->rssiAgr +
1171 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1172 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1173 {
1174 pExtSpectCh->rssiAgr = rssi;
1175 }
1176 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1177 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1178 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001179 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301180
1181 case CHANNEL_10:
1182 pExtSpectCh = (pSpectCh - 4);
1183 if (pExtSpectCh != NULL)
1184 {
1185 ++pExtSpectCh->bssCount;
1186 rssi = pSpectCh->rssiAgr +
1187 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1188 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1189 {
1190 pExtSpectCh->rssiAgr = rssi;
1191 }
1192 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1193 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1194 }
1195
1196 pExtSpectCh = (pSpectCh - 3);
1197 if (pExtSpectCh != NULL)
1198 {
1199 ++pExtSpectCh->bssCount;
1200 rssi = pSpectCh->rssiAgr +
1201 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1202 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1203 {
1204 pExtSpectCh->rssiAgr = rssi;
1205 }
1206 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1207 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1208 }
1209 pExtSpectCh = (pSpectCh - 2);
1210 if(pExtSpectCh != NULL)
1211 {
1212 ++pExtSpectCh->bssCount;
1213 rssi = pSpectCh->rssiAgr +
1214 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1215 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1216 {
1217 pExtSpectCh->rssiAgr = rssi;
1218 }
1219 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1220 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1221 }
1222 pExtSpectCh = (pSpectCh - 1);
1223 if (pExtSpectCh != NULL)
1224 {
1225 ++pExtSpectCh->bssCount;
1226 rssi = pSpectCh->rssiAgr +
1227 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1228 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1229 {
1230 pExtSpectCh->rssiAgr = rssi;
1231 }
1232 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1233 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1234 }
1235 pExtSpectCh = (pSpectCh + 1);
1236 if (pExtSpectCh != NULL)
1237 {
1238 ++pExtSpectCh->bssCount;
1239 rssi = pSpectCh->rssiAgr +
1240 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1241 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1242 {
1243 pExtSpectCh->rssiAgr = rssi;
1244 }
1245 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1246 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1247 }
1248 break;
1249
1250 case CHANNEL_11:
1251 pExtSpectCh = (pSpectCh - 1);
1252 if (pExtSpectCh != NULL)
1253 {
1254 ++pExtSpectCh->bssCount;
1255 rssi = pSpectCh->rssiAgr +
1256 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1257 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1258 {
1259 pExtSpectCh->rssiAgr = rssi;
1260 }
1261 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1262 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1263 }
1264 pExtSpectCh = (pSpectCh - 2);
1265 if (pExtSpectCh != NULL)
1266 {
1267 ++pExtSpectCh->bssCount;
1268 rssi = pSpectCh->rssiAgr +
1269 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1270 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1271 {
1272 pExtSpectCh->rssiAgr = rssi;
1273 }
1274 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1275 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1276 }
1277 pExtSpectCh = (pSpectCh - 3);
1278 if (pExtSpectCh != NULL)
1279 {
1280 ++pExtSpectCh->bssCount;
1281 rssi = pSpectCh->rssiAgr +
1282 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1283 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1284 {
1285 pExtSpectCh->rssiAgr = rssi;
1286 }
1287 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1288 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1289 }
1290 pExtSpectCh = (pSpectCh - 4);
1291 if (pExtSpectCh != NULL)
1292 {
1293 ++pExtSpectCh->bssCount;
1294 rssi = pSpectCh->rssiAgr +
1295 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1296 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1297 {
1298 pExtSpectCh->rssiAgr = rssi;
1299 }
1300 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1301 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1302 }
1303 break;
1304
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001305 default:
1306 break;
1307 }
1308}
1309
Jeff Johnson295189b2012-06-20 16:38:30 -07001310/*==========================================================================
1311 FUNCTION sapComputeSpectWeight
1312
1313 DESCRIPTION
1314 Main function for computing the weight of each channel in the
1315 spectrum based on the RSSI value of the BSSes on the channel
1316 and number of BSS
1317
1318 DEPENDENCIES
1319 NA.
1320
1321 PARAMETERS
1322
1323 IN
1324 pSpectInfoParams : Pointer to the tSpectInfoParams structure
1325 halHandle : Pointer to HAL handle
1326 pResult : Pointer to tScanResultHandle
1327
1328 RETURN VALUE
1329 void : NULL
1330
1331 SIDE EFFECTS
1332============================================================================*/
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301333void sapComputeSpectWeight( tSapChSelSpectInfo* pSpectInfoParams,
1334 tHalHandle halHandle, tScanResultHandle pResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001335{
1336 v_S7_t rssi = 0;
1337 v_U8_t chn_num = 0;
1338 v_U8_t channel_id = 0;
1339
1340 tCsrScanResultInfo *pScanResult;
1341 tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001342 v_U32_t operatingBand;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001343 v_U16_t channelWidth;
1344 v_U16_t secondaryChannelOffset;
1345 v_U16_t centerFreq;
1346 v_U16_t vhtSupport;
1347 v_U32_t ieLen = 0;
1348 tSirProbeRespBeacon *pBeaconStruct;
1349 tpAniSirGlobal pMac = (tpAniSirGlobal) halHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -07001350
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301351 pBeaconStruct = vos_mem_malloc(sizeof(tSirProbeRespBeacon));
1352 if ( NULL == pBeaconStruct )
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001353 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301354 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1355 "Unable to allocate memory in sapComputeSpectWeight\n");
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001356 return;
1357 }
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001358 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Computing spectral weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001359
1360 /**
1361 * Soft AP specific channel weight calculation using DFS formula
1362 */
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001363 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
Jeff Johnson295189b2012-06-20 16:38:30 -07001364
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301365 pScanResult = sme_ScanResultGetFirst(halHandle, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07001366
1367 while (pScanResult) {
1368 pSpectCh = pSpectInfoParams->pSpectCh;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001369 // Defining the default values, so that any value will hold the default values
1370 channelWidth = eHT_CHANNEL_WIDTH_20MHZ;
1371 secondaryChannelOffset = PHY_SINGLE_CHANNEL_CENTERED;
1372 vhtSupport = 0;
1373 centerFreq = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301374
1375 if (pScanResult->BssDescriptor.ieFields != NULL)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001376 {
1377 ieLen = (pScanResult->BssDescriptor.length + sizeof(tANI_U16) + sizeof(tANI_U32) - sizeof(tSirBssDescription));
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301378 vos_mem_set((tANI_U8 *) pBeaconStruct, sizeof(tSirProbeRespBeacon), 0);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301379
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001380 if ((sirParseBeaconIE(pMac, pBeaconStruct,(tANI_U8 *)( pScanResult->BssDescriptor.ieFields), ieLen)) == eSIR_SUCCESS)
1381 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301382 if (pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001383 {
1384 channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet;
1385 secondaryChannelOffset = pBeaconStruct->HTInfo.secondaryChannelOffset;
1386 if(pBeaconStruct->VHTOperation.present)
1387 {
1388 vhtSupport = pBeaconStruct->VHTOperation.present;
1389 if(pBeaconStruct->VHTOperation.chanWidth > WNI_CFG_VHT_CHANNEL_WIDTH_20_40MHZ)
1390 {
1391 channelWidth = eHT_CHANNEL_WIDTH_80MHZ;
1392 centerFreq = pBeaconStruct->VHTOperation.chanCenterFreqSeg1;
1393 }
1394 }
1395 }
1396 }
1397 }
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001398 // Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list
Jeff Johnson295189b2012-06-20 16:38:30 -07001399 for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; chn_num++) {
1400
1401 /*
1402 * if the Beacon has channel ID, use it other wise we will
1403 * rely on the channelIdSelf
1404 */
1405 if(pScanResult->BssDescriptor.channelId == 0)
1406 channel_id = pScanResult->BssDescriptor.channelIdSelf;
1407 else
1408 channel_id = pScanResult->BssDescriptor.channelId;
1409
krunal sonic39d9592014-02-04 11:54:24 -08001410 if (pSpectCh && (channel_id == pSpectCh->chNum)) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001411 if (pSpectCh->rssiAgr < pScanResult->BssDescriptor.rssi)
1412 pSpectCh->rssiAgr = pScanResult->BssDescriptor.rssi;
1413
1414 ++pSpectCh->bssCount; // Increment the count of BSS
1415
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001416 if(operatingBand) // Connsidering the Extension Channel only in a channels
1417 {
1418 /* Updating the received ChannelWidth */
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301419 if (pSpectCh->channelWidth != channelWidth)
1420 pSpectCh->channelWidth = channelWidth;
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001421 /* If received ChannelWidth is other than HT20, we need to update the extension channel Params as well */
1422 /* channelWidth == 0, HT20 */
1423 /* channelWidth == 1, HT40 */
1424 /* channelWidth == 2, VHT80*/
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001425 switch(pSpectCh->channelWidth)
1426 {
1427 case eHT_CHANNEL_WIDTH_40MHZ: //HT40
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001428 switch( secondaryChannelOffset)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001429 {
1430 tSapSpectChInfo *pExtSpectCh = NULL;
1431 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY: // Above the Primary Channel
1432 pExtSpectCh = (pSpectCh + 1);
1433 if(pExtSpectCh != NULL)
1434 {
1435 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001436 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001437 // REducing the rssi by -20 and assigning it to Extension channel
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001438 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1439 {
1440 pExtSpectCh->rssiAgr = rssi;
1441 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001442 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1443 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1444 }
1445 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301446
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001447 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY: // Below the Primary channel
1448 pExtSpectCh = (pSpectCh - 1);
1449 if(pExtSpectCh != NULL)
1450 {
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001451 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1452 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1453 {
1454 pExtSpectCh->rssiAgr = rssi;
1455 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001456 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1457 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1458 ++pExtSpectCh->bssCount;
1459 }
1460 break;
1461 }
1462 break;
1463 case eHT_CHANNEL_WIDTH_80MHZ: // VHT80
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001464 if((centerFreq - channel_id) == 6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001465 {
1466 tSapSpectChInfo *pExtSpectCh = NULL;
1467 pExtSpectCh = (pSpectCh + 1);
1468 if(pExtSpectCh != NULL)
1469 {
1470 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001471 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1472 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1473 {
1474 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -20 and assigning it to Subband 1
1475 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001476 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1477 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1478 }
1479 pExtSpectCh = (pSpectCh + 2);
1480 if(pExtSpectCh != NULL)
1481 {
1482 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001483 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1484 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1485 {
1486 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -30 and assigning it to Subband 2
1487 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001488 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1489 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1490 }
1491 pExtSpectCh = (pSpectCh + 3);
1492 if(pExtSpectCh != NULL)
1493 {
1494 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001495 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1496 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1497 {
1498 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -40 and assigning it to Subband 3
1499 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001500 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1501 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301502 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001503 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001504 else if((centerFreq - channel_id) == 2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001505 {
1506 tSapSpectChInfo *pExtSpectCh = NULL;
1507 pExtSpectCh = (pSpectCh - 1 );
1508 if(pExtSpectCh != NULL)
1509 {
1510 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001511 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1512 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1513 {
1514 pExtSpectCh->rssiAgr = rssi;
1515 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001516 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1517 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1518 }
1519 pExtSpectCh = (pSpectCh + 1);
1520 if(pExtSpectCh != NULL)
1521 {
1522 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001523 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1524 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1525 {
1526 pExtSpectCh->rssiAgr = rssi;
1527 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001528 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1529 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1530 }
1531 pExtSpectCh = (pSpectCh + 2);
1532 if(pExtSpectCh != NULL)
1533 {
1534 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001535 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1536 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1537 {
1538 pExtSpectCh->rssiAgr = rssi;
1539 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001540 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1541 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1542 }
1543 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001544 else if((centerFreq - channel_id) == -2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001545 {
1546 tSapSpectChInfo *pExtSpectCh = NULL;
1547 pExtSpectCh = (pSpectCh - 1 );
1548 if(pExtSpectCh != NULL)
1549 {
1550 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001551 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1552 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1553 {
1554 pExtSpectCh->rssiAgr = rssi;
1555 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001556 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1557 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1558 }
1559 pExtSpectCh = (pSpectCh - 2);
1560 if(pExtSpectCh != NULL)
1561 {
1562 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001563 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1564 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1565 {
1566 pExtSpectCh->rssiAgr = rssi;
1567 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001568 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1569 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1570 }
1571 pExtSpectCh = (pSpectCh + 1);
1572 if(pExtSpectCh != NULL)
1573 {
1574 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001575 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1576 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1577 {
1578 pExtSpectCh->rssiAgr = rssi;
1579 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001580 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1581 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1582 }
1583 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001584 else if((centerFreq - channel_id) == -6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001585 {
1586 tSapSpectChInfo *pExtSpectCh = NULL;
1587 pExtSpectCh = (pSpectCh - 1 );
1588 if(pExtSpectCh != NULL)
1589 {
1590 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001591 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1592 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1593 {
1594 pExtSpectCh->rssiAgr = rssi;
1595 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001596 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1597 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1598 }
1599 pExtSpectCh = (pSpectCh - 2);
1600 if(pExtSpectCh != NULL)
1601 {
1602 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001603 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1604 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1605 {
1606 pExtSpectCh->rssiAgr = rssi;
1607 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001608 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1609 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1610 }
1611 pExtSpectCh = (pSpectCh - 3);
1612 if(pExtSpectCh != NULL)
1613 {
1614 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001615 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1616 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1617 {
1618 pExtSpectCh->rssiAgr = rssi;
1619 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001620 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1621 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1622 }
1623 }
1624 break;
1625 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301626 }
Leela Venkata Kiran Kumar Reddy Chirala9f6566c2014-09-05 19:06:58 +05301627 else if(operatingBand == eSAP_RF_SUBBAND_2_4_GHZ)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001628 {
1629 sapInterferenceRssiCount(pSpectCh);
1630 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001631
Jeff Johnson295189b2012-06-20 16:38:30 -07001632 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301633 "In %s, bssdes.ch_self=%d, bssdes.ch_ID=%d, bssdes.rssi=%d, SpectCh.bssCount=%d, pScanResult=%p, ChannelWidth %d, secondaryChanOffset %d, center frequency %d \n",
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001634 __func__, pScanResult->BssDescriptor.channelIdSelf, pScanResult->BssDescriptor.channelId, pScanResult->BssDescriptor.rssi, pSpectCh->bssCount, pScanResult,pSpectCh->channelWidth,secondaryChannelOffset,centerFreq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001635 pSpectCh++;
1636 break;
1637 } else {
1638 pSpectCh++;
1639 }
1640 }
1641
1642 pScanResult = sme_ScanResultGetNext(halHandle, pResult);
1643 }
1644
1645 // Calculate the weights for all channels in the spectrum pSpectCh
1646 pSpectCh = pSpectInfoParams->pSpectCh;
1647
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001648 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001649
1650 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); chn_num++) {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301651
Jeff Johnson295189b2012-06-20 16:38:30 -07001652 /*
1653 rssi : Maximum received signal strength among all BSS on that channel
1654 bssCount : Number of BSS on that channel
1655 */
1656
1657 rssi = (v_S7_t)pSpectCh->rssiAgr;
1658
1659 pSpectCh->weight = SAPDFS_NORMALISE_1000 * sapweightRssiCount(rssi, pSpectCh->bssCount);
1660
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301661 //------ Debug Info ------
1662 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1663 "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d", __func__,
1664 pSpectCh->chNum, pSpectCh->weight,
1665 pSpectCh->rssiAgr, pSpectCh->bssCount);
1666 //------ Debug Info ------
Jeff Johnson295189b2012-06-20 16:38:30 -07001667 pSpectCh++;
1668 }
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301669 vos_mem_free(pBeaconStruct);
Jeff Johnson295189b2012-06-20 16:38:30 -07001670}
1671
1672/*==========================================================================
1673 FUNCTION sapChanSelExit
1674
1675 DESCRIPTION
1676 Exit function for free out the allocated memory, to be called
1677 at the end of the dfsSelectChannel function
1678
1679 DEPENDENCIES
1680 NA.
1681
1682 PARAMETERS
1683
1684 IN
1685 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1686
1687 RETURN VALUE
1688 void : NULL
1689
1690 SIDE EFFECTS
1691============================================================================*/
1692void sapChanSelExit( tSapChSelSpectInfo *pSpectInfoParams )
1693{
1694 // Free all the allocated memory
1695 vos_mem_free(pSpectInfoParams->pSpectCh);
1696}
1697
1698/*==========================================================================
1699 FUNCTION sapSortChlWeight
1700
1701 DESCRIPTION
1702 Funtion to sort the channels with the least weight first
1703
1704 DEPENDENCIES
1705 NA.
1706
1707 PARAMETERS
1708
1709 IN
1710 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1711
1712 RETURN VALUE
1713 void : NULL
1714
1715 SIDE EFFECTS
1716============================================================================*/
1717void sapSortChlWeight(tSapChSelSpectInfo *pSpectInfoParams)
1718{
1719 tSapSpectChInfo temp;
1720
1721 tSapSpectChInfo *pSpectCh = NULL;
1722 v_U32_t i = 0, j = 0, minWeightIndex = 0;
1723
1724 pSpectCh = pSpectInfoParams->pSpectCh;
Jeff Johnson295189b2012-06-20 16:38:30 -07001725 for (i = 0; i < pSpectInfoParams->numSpectChans; i++) {
1726 minWeightIndex = i;
1727 for( j = i + 1; j < pSpectInfoParams->numSpectChans; j++) {
1728 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1729 minWeightIndex = j;
1730 }
1731 }
1732 if(minWeightIndex != i) {
1733 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1734 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1735 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1736 }
1737 }
Peng Xu7d410f42014-09-09 12:15:47 +05301738}
1739
1740/*==========================================================================
1741 FUNCTION sapSortChlWeightHT80
1742
1743 DESCRIPTION
1744 Funtion to sort the channels with the least weight first for HT80 channels
1745
1746 DEPENDENCIES
1747 NA.
1748
1749 PARAMETERS
1750
1751 IN
1752 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1753
1754 RETURN VALUE
1755 void : NULL
1756
1757 SIDE EFFECTS
1758============================================================================*/
1759void sapSortChlWeightHT80(tSapChSelSpectInfo *pSpectInfoParams)
1760{
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301761 v_U8_t i, j, n;
Peng Xu7d410f42014-09-09 12:15:47 +05301762 tSapSpectChInfo *pSpectInfo;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301763 v_U8_t minIdx;
Peng Xu7d410f42014-09-09 12:15:47 +05301764
1765 pSpectInfo = pSpectInfoParams->pSpectCh;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301766 /* for each HT80 channel, calculate the combined weight of the
1767 four 20MHz weight */
Peng Xu7d410f42014-09-09 12:15:47 +05301768 for (i = 0; i < ARRAY_SIZE(acsHT80Channels); i++)
1769 {
1770 for (j = 0; j < pSpectInfoParams->numSpectChans; j++)
1771 {
1772 if ( pSpectInfo[j].chNum == acsHT80Channels[i].chStartNum )
1773 break;
1774 }
Peng Xu117eab42014-09-25 13:33:27 +05301775 if (j == pSpectInfoParams->numSpectChans)
1776 continue;
Peng Xu7d410f42014-09-09 12:15:47 +05301777
1778 /*found the channel, add the 4 adjacent channels' weight*/
1779 if (((pSpectInfo[j].chNum +4) == pSpectInfo[j+1].chNum) &&
1780 ((pSpectInfo[j].chNum +8) == pSpectInfo[j+2].chNum) &&
1781 ((pSpectInfo[j].chNum +12) == pSpectInfo[j+3].chNum))
1782 {
1783 acsHT80Channels[i].weight = pSpectInfo[j].weight +
1784 pSpectInfo[j+1].weight +
1785 pSpectInfo[j+2].weight +
1786 pSpectInfo[j+3].weight;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301787 /* find best channel among 4 channels as the primary channel */
Rajesh Babu Prathipati32ddabf2014-09-11 16:08:59 +05301788 if ((pSpectInfo[j].weight + pSpectInfo[j+1].weight) <
1789 (pSpectInfo[j+2].weight + pSpectInfo[j+3].weight))
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301790 {
Rajesh Babu Prathipati32ddabf2014-09-11 16:08:59 +05301791 /* lower 2 channels are better choice */
1792 if (pSpectInfo[j].weight < pSpectInfo[j+1].weight)
1793 minIdx = 0;
1794 else
1795 minIdx = 1;
1796 }
1797 else
1798 {
1799 /* upper 2 channels are better choice */
1800 if (pSpectInfo[j+2].weight <= pSpectInfo[j+3].weight)
1801 minIdx = 2;
1802 else
1803 minIdx = 3;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301804 }
1805
1806 /* set all 4 channels to max value first, then reset the
1807 best channel as the selected primary channel, update its
1808 weightage with the combined weight value */
1809 for (n=0; n<4; n++)
1810 pSpectInfo[j+n].weight = ACS_WEIGHT_MAX;
1811
1812 pSpectInfo[j+minIdx].weight = acsHT80Channels[i].weight;
Peng Xu7d410f42014-09-09 12:15:47 +05301813 }
Rajesh Babu Prathipati2bc30592014-09-09 13:05:26 +05301814 else
1815 {
1816 /* some channels does not exist in pSectInfo array,
1817 skip this channel and those in the same HT80 width*/
1818 pSpectInfo[j].weight = ACS_WEIGHT_MAX;
1819 if ((pSpectInfo[j].chNum +4) == pSpectInfo[j+1].chNum)
1820 pSpectInfo[j+1].weight = ACS_WEIGHT_MAX;
1821 if ((pSpectInfo[j].chNum +8) == pSpectInfo[j+2].chNum)
1822 pSpectInfo[j+2].weight = ACS_WEIGHT_MAX;
1823 if ((pSpectInfo[j].chNum +12) == pSpectInfo[j+3].chNum)
1824 pSpectInfo[j+3].weight = ACS_WEIGHT_MAX;
1825 }
Peng Xu7d410f42014-09-09 12:15:47 +05301826 }
1827
1828 pSpectInfo = pSpectInfoParams->pSpectCh;
1829 for (j = 0; j < pSpectInfoParams->numSpectChans; j++)
1830 {
Peng Xu117eab42014-09-25 13:33:27 +05301831 if ( CHANNEL_165 == pSpectInfo[j].chNum )
Peng Xu7d410f42014-09-09 12:15:47 +05301832 {
1833 pSpectInfo[j].weight = ACS_WEIGHT_MAX;
1834 break;
1835 }
1836 }
1837
Rajesh Babu Prathipati2bc30592014-09-09 13:05:26 +05301838 pSpectInfo = pSpectInfoParams->pSpectCh;
1839 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
1840 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1841 "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
1842 __func__, pSpectInfo->chNum, pSpectInfo->weight,
1843 pSpectInfo->rssiAgr, pSpectInfo->bssCount);
1844 pSpectInfo++;
1845 }
1846
Peng Xu7d410f42014-09-09 12:15:47 +05301847 sapSortChlWeight(pSpectInfoParams);
1848}
1849
1850/*==========================================================================
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301851 FUNCTION sapSortChlWeightHT40_24G
Peng Xu7d410f42014-09-09 12:15:47 +05301852
1853 DESCRIPTION
1854 Funtion to sort the channels with the least weight first for 20MHz channels
1855
1856 DEPENDENCIES
1857 NA.
1858
1859 PARAMETERS
1860
1861 IN
1862 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1863
1864 RETURN VALUE
1865 void : NULL
1866
1867 SIDE EFFECTS
1868============================================================================*/
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301869void sapSortChlWeightHT40_24G(tSapChSelSpectInfo *pSpectInfoParams)
1870{
1871 v_U8_t i, j;
1872 tSapSpectChInfo *pSpectInfo;
1873 v_U32_t tmpWeight1, tmpWeight2;
1874
1875 pSpectInfo = pSpectInfoParams->pSpectCh;
1876 /*for each HT40 channel, calculate the combined weight of the
1877 two 20MHz weight */
1878 for (i = 0; i < ARRAY_SIZE(acsHT40Channels24G); i++)
1879 {
1880 for (j = 0; j < pSpectInfoParams->numSpectChans; j++)
1881 {
1882 if (pSpectInfo[j].chNum == acsHT40Channels24G[i].chStartNum)
1883 break;
1884 }
1885 if (j == pSpectInfoParams->numSpectChans)
1886 continue;
1887
1888 if ((pSpectInfo[j].chNum +4) == pSpectInfo[j+4].chNum)
1889 {
1890 /* check if there is another channel combination possiblity
1891 e.g., {1, 5} & {5, 9} */
1892 if ((pSpectInfo[j+4].chNum + 4)== pSpectInfo[j+8].chNum)
1893 {
1894 /* need to compare two channel pairs */
1895 tmpWeight1 = pSpectInfo[j].weight + pSpectInfo[j+4].weight;
1896 tmpWeight2 = pSpectInfo[j+4].weight + pSpectInfo[j+8].weight;
1897 if (tmpWeight1 <= tmpWeight2)
1898 {
1899 if (pSpectInfo[j].weight <= pSpectInfo[j+4].weight)
1900 {
1901 pSpectInfo[j].weight = tmpWeight1;
1902 pSpectInfo[j+4].weight = ACS_WEIGHT_MAX;
1903 pSpectInfo[j+8].weight = ACS_WEIGHT_MAX;
1904 }
1905 else
1906 {
1907 pSpectInfo[j+4].weight = tmpWeight1;
1908 pSpectInfo[j].weight = ACS_WEIGHT_MAX;
1909 pSpectInfo[j+8].weight = ACS_WEIGHT_MAX;
1910 }
1911 }
1912 else
1913 {
1914 if (pSpectInfo[j+4].weight <= pSpectInfo[j+8].weight)
1915 {
1916 pSpectInfo[j+4].weight = tmpWeight2;
1917 pSpectInfo[j].weight = ACS_WEIGHT_MAX;
1918 pSpectInfo[j+8].weight = ACS_WEIGHT_MAX;
1919 }
1920 else
1921 {
1922 pSpectInfo[j+8].weight = tmpWeight2;
1923 pSpectInfo[j].weight = ACS_WEIGHT_MAX;
1924 pSpectInfo[j+4].weight = ACS_WEIGHT_MAX;
1925 }
1926 }
1927 }
1928 else
1929 {
1930 tmpWeight1 = pSpectInfo[j].weight + pSpectInfo[j+4].weight;
1931 if (pSpectInfo[j].weight <= pSpectInfo[j+4].weight)
1932 {
1933 pSpectInfo[j].weight = tmpWeight1;
1934 pSpectInfo[j+4].weight = ACS_WEIGHT_MAX;
1935 }
1936 else
1937 {
1938 pSpectInfo[j+4].weight = tmpWeight1;
1939 pSpectInfo[j].weight = ACS_WEIGHT_MAX;
1940 }
1941 }
1942 }
1943 else
1944 pSpectInfo[j].weight = ACS_WEIGHT_MAX;
1945 }
Rajesh Babu Prathipati684ad722014-09-11 16:14:05 +05301946
1947 sapSortChlWeight(pSpectInfoParams);
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05301948}
1949
1950
1951/*==========================================================================
1952 FUNCTION sapSortChlWeightHT40_5G
1953
1954 DESCRIPTION
1955 Funtion to sort the channels with the least weight first for HT40 channels
1956
1957 DEPENDENCIES
1958 NA.
1959
1960 PARAMETERS
1961
1962 IN
1963 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1964
1965 RETURN VALUE
1966 void : NULL
1967
1968 SIDE EFFECTS
1969============================================================================*/
1970void sapSortChlWeightHT40_5G(tSapChSelSpectInfo *pSpectInfoParams)
Peng Xu7d410f42014-09-09 12:15:47 +05301971{
1972 v_U8_t i, j;
1973 tSapSpectChInfo *pSpectInfo;
1974
1975 pSpectInfo = pSpectInfoParams->pSpectCh;
1976 /*for each HT40 channel, calculate the combined weight of the
1977 two 20MHz weight */
Peng Xu117eab42014-09-25 13:33:27 +05301978 for (i = 0; i < ARRAY_SIZE(acsHT40Channels5G); i++)
Peng Xu7d410f42014-09-09 12:15:47 +05301979 {
1980 for (j = 0; j < pSpectInfoParams->numSpectChans; j++)
1981 {
Peng Xu117eab42014-09-25 13:33:27 +05301982 if (pSpectInfo[j].chNum == acsHT40Channels5G[i].chStartNum)
Peng Xu7d410f42014-09-09 12:15:47 +05301983 break;
1984 }
Peng Xu117eab42014-09-25 13:33:27 +05301985 if (j == pSpectInfoParams->numSpectChans)
1986 continue;
Peng Xu7d410f42014-09-09 12:15:47 +05301987
1988 /* found the channel, add the two adjacent channels' weight */
1989 if ( (pSpectInfo[j].chNum +4) == pSpectInfo[j+1].chNum)
1990 {
Peng Xu117eab42014-09-25 13:33:27 +05301991 acsHT40Channels5G[i].weight = pSpectInfo[j].weight +
Peng Xu7d410f42014-09-09 12:15:47 +05301992 pSpectInfo[j+1].weight;
Rajesh Babu Prathipatiaf5ceac2014-09-09 13:10:25 +05301993 /* select better of the adjact channel as the primary channel */
1994 if (pSpectInfo[j].weight <= pSpectInfo[j+1].weight)
1995 {
1996 pSpectInfo[j].weight = acsHT40Channels5G[i].weight;
1997 /* mark the adjacent channel's weight as max value so
1998 that it will be sorted to the bottom */
1999 pSpectInfo[j+1].weight = ACS_WEIGHT_MAX;
2000 }
2001 else
2002 {
2003 pSpectInfo[j+1].weight = acsHT40Channels5G[i].weight;
2004 /* mark the adjacent channel's weight as max value so
2005 that it will be sorted to the bottom */
2006 pSpectInfo[j].weight = ACS_WEIGHT_MAX;
2007 }
2008
Peng Xu7d410f42014-09-09 12:15:47 +05302009 }
Rajesh Babu Prathipati2bc30592014-09-09 13:05:26 +05302010 else
2011 pSpectInfo[j].weight = ACS_WEIGHT_MAX;
Peng Xu7d410f42014-09-09 12:15:47 +05302012 }
2013
2014 /* avoid channel 165 by setting its weight to max */
2015 pSpectInfo = pSpectInfoParams->pSpectCh;
2016 for (j = 0; j < pSpectInfoParams->numSpectChans; j++)
2017 {
Peng Xu117eab42014-09-25 13:33:27 +05302018 if ( CHANNEL_165 == pSpectInfo[j].chNum )
Peng Xu7d410f42014-09-09 12:15:47 +05302019 {
2020 pSpectInfo[j].weight = ACS_WEIGHT_MAX;
2021 break;
2022 }
2023 }
2024
Peng Xu117eab42014-09-25 13:33:27 +05302025 pSpectInfo = pSpectInfoParams->pSpectCh;
2026 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
2027 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
2028 "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
2029 __func__, pSpectInfo->chNum, pSpectInfo->weight,
2030 pSpectInfo->rssiAgr, pSpectInfo->bssCount);
2031 pSpectInfo++;
2032 }
2033
Peng Xu7d410f42014-09-09 12:15:47 +05302034 sapSortChlWeight(pSpectInfoParams);
2035}
2036
2037/*==========================================================================
2038 FUNCTION sapSortChlWeightAll
2039
2040 DESCRIPTION
2041 Funtion to sort the channels with the least weight first
2042
2043 DEPENDENCIES
2044 NA.
2045
2046 PARAMETERS
2047
2048 IN
2049 ptSapContext : Pointer to the ptSapContext structure
2050 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
2051
2052 RETURN VALUE
2053 void : NULL
2054
2055 SIDE EFFECTS
2056============================================================================*/
2057void sapSortChlWeightAll(ptSapContext pSapCtx,
Peng Xu117eab42014-09-25 13:33:27 +05302058 tSapChSelSpectInfo *pSpectInfoParams,
2059 eChannelWidthInfo chWidth,
2060 v_U32_t operatingBand)
Peng Xu7d410f42014-09-09 12:15:47 +05302061{
2062 tSapSpectChInfo *pSpectCh = NULL;
2063 v_U32_t j = 0;
2064#ifndef SOFTAP_CHANNEL_RANGE
2065 v_U32_t i = 0;
2066#endif
2067
2068 pSpectCh = pSpectInfoParams->pSpectCh;
2069#ifdef SOFTAP_CHANNEL_RANGE
2070
Peng Xu117eab42014-09-25 13:33:27 +05302071 switch (chWidth)
2072 {
2073 case CHWIDTH_HT40:
Rajesh Babu Prathipatiff748c02014-09-09 13:19:57 +05302074 if (eSAP_RF_SUBBAND_2_4_GHZ == operatingBand)
2075 sapSortChlWeightHT40_24G(pSpectInfoParams);
2076 else
2077 sapSortChlWeightHT40_5G(pSpectInfoParams);
Peng Xu117eab42014-09-25 13:33:27 +05302078 break;
2079
2080 case CHWIDTH_HT80:
Peng Xu7d410f42014-09-09 12:15:47 +05302081 sapSortChlWeightHT80(pSpectInfoParams);
Peng Xu117eab42014-09-25 13:33:27 +05302082 break;
2083
2084 case CHWIDTH_HT20:
2085 default:
Peng Xu7d410f42014-09-09 12:15:47 +05302086 /* Sorting the channels as per weights as 20MHz channels */
2087 sapSortChlWeight(pSpectInfoParams);
2088 }
Peng Xu117eab42014-09-25 13:33:27 +05302089
Jeff Johnson295189b2012-06-20 16:38:30 -07002090#else
Peng Xu7d410f42014-09-09 12:15:47 +05302091 /* Sorting the channels as per weights */
Jeff Johnson295189b2012-06-20 16:38:30 -07002092 for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) {
2093 minWeightIndex = i;
2094 for( j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) {
2095 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
2096 minWeightIndex = j;
2097 }
2098 }
2099 if(minWeightIndex != i) {
2100 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
Peng Xu7d410f42014-09-09 12:15:47 +05302101 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i],
2102 sizeof(*pSpectCh));
Jeff Johnson295189b2012-06-20 16:38:30 -07002103 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
2104 }
2105 }
2106#endif
2107
2108 /* For testing */
Peng Xu7d410f42014-09-09 12:15:47 +05302109 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
2110 "In %s, Sorted Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002111 pSpectCh = pSpectInfoParams->pSpectCh;
2112 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
Peng Xu7d410f42014-09-09 12:15:47 +05302113 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
2114 "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
2115 __func__, pSpectCh->chNum, pSpectCh->weight,
2116 pSpectCh->rssiAgr, pSpectCh->bssCount);
Jeff Johnson295189b2012-06-20 16:38:30 -07002117 pSpectCh++;
2118 }
2119
2120}
2121
Peng Xu117eab42014-09-25 13:33:27 +05302122eChannelWidthInfo sapGetChannelWidthInfo(tHalHandle halHandle, ptSapContext pSapCtx,
2123 v_U32_t operatingBand, eSapPhyMode phyMode)
2124{
2125 v_U32_t cbMode;
2126 eChannelWidthInfo chWidth = CHWIDTH_HT20;
2127
Hardik Kantilal Pateldd107952014-11-20 15:24:52 +05302128#ifdef WLAN_FEATURE_AP_HT40_24G
Peng Xu117eab42014-09-25 13:33:27 +05302129 if (eSAP_RF_SUBBAND_2_4_GHZ == operatingBand)
2130 cbMode = sme_GetChannelBondingMode24G(halHandle);
2131 else
Hardik Kantilal Pateldd107952014-11-20 15:24:52 +05302132#endif
Peng Xu117eab42014-09-25 13:33:27 +05302133 cbMode = sme_GetChannelBondingMode5G(halHandle);
2134
2135 if (phyMode == eSAP_DOT11_MODE_11n ||
2136 phyMode == eSAP_DOT11_MODE_11n_ONLY)
2137 {
2138 if (cbMode)
2139 chWidth = CHWIDTH_HT40;
2140 else
2141 chWidth = CHWIDTH_HT20;
2142 }
2143 else if (pSapCtx->csrRoamProfile.phyMode == eSAP_DOT11_MODE_11ac ||
2144 pSapCtx->csrRoamProfile.phyMode == eSAP_DOT11_MODE_11ac_ONLY) {
2145 chWidth = CHWIDTH_HT80;
2146 }
2147 else {
2148 /* Sorting the channels as per weights as 20MHz channels */
2149 chWidth = CHWIDTH_HT20;
2150 }
2151
2152 return chWidth;
2153}
Jeff Johnson295189b2012-06-20 16:38:30 -07002154/*==========================================================================
2155 FUNCTION sapSelectChannel
2156
2157 DESCRIPTION
2158 Runs a algorithm to select the best channel to operate in based on BSS
2159 rssi and bss count on each channel
2160
2161 DEPENDENCIES
2162 NA.
2163
2164 PARAMETERS
2165
2166 IN
2167 halHandle : Pointer to HAL handle
2168 pResult : Pointer to tScanResultHandle
2169
2170 RETURN VALUE
2171 v_U8_t : Success - channel number, Fail - zero
2172
2173 SIDE EFFECTS
2174============================================================================*/
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07002175v_U8_t sapSelectChannel(tHalHandle halHandle, ptSapContext pSapCtx, tScanResultHandle pScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07002176{
2177 // DFS param object holding all the data req by the algo
2178 tSapChSelSpectInfo oSpectInfoParams = {NULL,0};
2179 tSapChSelSpectInfo *pSpectInfoParams = &oSpectInfoParams; // Memory? NB
Peng Xuafc34e32014-09-25 13:23:55 +05302180 v_U8_t bestChNum = SAP_CHANNEL_NOT_SELECTED;
Jeff Johnson295189b2012-06-20 16:38:30 -07002181#ifdef SOFTAP_CHANNEL_RANGE
2182 v_U32_t startChannelNum;
2183 v_U32_t endChannelNum;
Gopichand Nakkala936715f2013-03-18 19:48:10 +05302184 v_U32_t operatingBand = 0;
Peng Xuafc34e32014-09-25 13:23:55 +05302185 v_U32_t tmpChNum;
2186 v_U8_t count;
Peng Xu117eab42014-09-25 13:33:27 +05302187 eChannelWidthInfo chWidth;
Peng Xuafc34e32014-09-25 13:23:55 +05302188#endif
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002189 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Running SAP Ch Select", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002190
Peng Xu0d6dfd02014-09-10 20:18:48 +05302191 if (NULL == pScanResult)
2192 {
2193 //scan is successfull, but no AP is present, select the first channel is channel range
2194 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_START_CHANNEL, &startChannelNum);
2195 return startChannelNum;
2196 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002197
2198 // Initialize the structure pointed by pSpectInfoParams
2199 if(sapChanSelInit( halHandle, pSpectInfoParams) != eSAP_TRUE ) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002200 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, Ch Select initialization failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002201 return SAP_CHANNEL_NOT_SELECTED;
2202 }
2203
2204 // Compute the weight of the entire spectrum in the operating band
2205 sapComputeSpectWeight( pSpectInfoParams, halHandle, pScanResult);
2206
Jeff Johnson295189b2012-06-20 16:38:30 -07002207#ifdef SOFTAP_CHANNEL_RANGE
Peng Xufc6ad8e2014-09-25 13:16:43 +05302208 if (eCSR_BAND_ALL == pSapCtx->scanBandPreference)
Peng Xu2446a892014-09-05 17:21:18 +05302209 {
Peng Xuafc34e32014-09-25 13:23:55 +05302210 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_START_CHANNEL,
2211 &startChannelNum);
2212 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_END_CHANNEL,
2213 &endChannelNum);
2214 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND,
2215 &operatingBand);
Peng Xufc6ad8e2014-09-25 13:16:43 +05302216 }
2217 else
2218 {
2219 if (eCSR_BAND_24 == pSapCtx->currentPreferredBand)
2220 {
Peng Xu2446a892014-09-05 17:21:18 +05302221 startChannelNum = rfChannels[RF_CHAN_1].channelNum;
2222 endChannelNum = rfChannels[RF_CHAN_14].channelNum;
Leela Venkata Kiran Kumar Reddy Chirala9f6566c2014-09-05 19:06:58 +05302223 operatingBand = eSAP_RF_SUBBAND_2_4_GHZ;
Peng Xufc6ad8e2014-09-25 13:16:43 +05302224 }
2225 else
2226 {
Peng Xu2446a892014-09-05 17:21:18 +05302227 startChannelNum = rfChannels[RF_CHAN_36].channelNum;
2228 endChannelNum = rfChannels[RF_CHAN_165].channelNum;
Deepthi Gowri7db41f32014-10-13 17:02:29 +05302229 operatingBand = eSAP_RF_SUBBAND_5_ALL_GHZ;
Peng Xufc6ad8e2014-09-25 13:16:43 +05302230 }
2231 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002232
Peng Xuafc34e32014-09-25 13:23:55 +05302233 pSapCtx->acsBestChannelInfo.channelNum = 0;
2234 pSapCtx->acsBestChannelInfo.weight = CFG_ACS_BAND_SWITCH_THRESHOLD_MAX;
Peng Xu117eab42014-09-25 13:33:27 +05302235 /* find the channel width info */
2236 chWidth = sapGetChannelWidthInfo(halHandle, pSapCtx, operatingBand, pSapCtx->csrRoamProfile.phyMode);
2237 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
2238 "In %s, chWidth=%u", __func__, chWidth);
2239
2240 /* Sort the channel list as per the computed weights, lesser weight first.*/
2241 sapSortChlWeightAll(pSapCtx, pSpectInfoParams, chWidth, operatingBand);
Peng Xuafc34e32014-09-25 13:23:55 +05302242
Jeff Johnson295189b2012-06-20 16:38:30 -07002243 /*Loop till get the best channel in the given range */
2244 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
2245 {
2246 if((startChannelNum <= pSpectInfoParams->pSpectCh[count].chNum)&&
2247 ( endChannelNum >= pSpectInfoParams->pSpectCh[count].chNum))
2248 {
Deepthi Gowri38c219d2014-08-05 19:34:08 +05302249 if (NV_CHANNEL_ENABLE !=
2250 vos_nv_getChannelEnabledState(pSpectInfoParams->pSpectCh[count].chNum))
2251 {
2252 continue; //skip this channel, continue to next channel
2253 }
Peng Xuafc34e32014-09-25 13:23:55 +05302254 if(bestChNum == SAP_CHANNEL_NOT_SELECTED)
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05302255 {
Peng Xuafc34e32014-09-25 13:23:55 +05302256 bestChNum = pSpectInfoParams->pSpectCh[count].chNum;
2257 /* check if bestChNum is in preferred channel list */
2258 bestChNum = sapSelectPreferredChannelFromChannelList(
2259 bestChNum, pSapCtx, pSpectInfoParams);
2260 if (bestChNum == SAP_CHANNEL_NOT_SELECTED)
2261 {
2262 /* not in preferred channel list, go to next best channel*/
2263 continue;
2264 }
2265
2266 if (pSpectInfoParams->pSpectCh[count].weight >
2267 pSapCtx->acsBandSwitchThreshold)
2268 {
2269 /* the best channel exceeds the threshold
2270 check if need to scan next band */
2271 if ((eCSR_BAND_ALL != pSapCtx->scanBandPreference) &&
2272 !pSapCtx->allBandScanned)
2273 {
2274 /* store best channel for later comparison */
2275 pSapCtx->acsBestChannelInfo.channelNum = bestChNum;
2276 pSapCtx->acsBestChannelInfo.weight =
2277 pSpectInfoParams->pSpectCh[count].weight;
2278 bestChNum = SAP_CHANNEL_NOT_SELECTED;
2279 break;
2280 }
2281 else
2282 {
2283 /* all bands are scanned, compare current best channel
2284 with channel scanned previously */
2285 if ( pSpectInfoParams->pSpectCh[count].weight >
2286 pSapCtx->acsBestChannelInfo.weight)
2287 {
2288 /* previous stored channel is better */
2289 bestChNum = pSapCtx->acsBestChannelInfo.channelNum;
2290 }
2291 else
2292 {
2293 pSapCtx->acsBestChannelInfo.channelNum = bestChNum;
2294 pSapCtx->acsBestChannelInfo.weight =
2295 pSpectInfoParams->pSpectCh[count].weight;
2296 }
2297 }
2298 }
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05302299 }
2300 else
2301 {
2302 if(operatingBand == RF_SUBBAND_2_4_GHZ)
2303 {
2304 /* Give preference to Non-overlap channels */
2305 if(((pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_1) ||
Peng Xuafc34e32014-09-25 13:23:55 +05302306 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_6) ||
2307 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_11))&&
2308 (pSpectInfoParams->pSpectCh[count].weight ==
2309 pSapCtx->acsBestChannelInfo.weight))
2310 {
2311 tmpChNum = pSpectInfoParams->pSpectCh[count].chNum;
2312 tmpChNum =
2313 sapSelectPreferredChannelFromChannelList(tmpChNum,
2314 pSapCtx, pSpectInfoParams);
2315 if ( tmpChNum != SAP_CHANNEL_NOT_SELECTED)
2316 {
2317 bestChNum = tmpChNum;
2318 break;
2319 }
2320
2321 }
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05302322 }
2323 }
2324 }
2325 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002326#else
Peng Xu117eab42014-09-25 13:33:27 +05302327 // Sort the channel list as per the computed weights, lesser weight first.
2328 sapSortChlWeightAll(pSapCtx, halHandle, pSpectInfoParams);
Jeff Johnson295189b2012-06-20 16:38:30 -07002329 // Get the first channel in sorted array as best 20M Channel
2330 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[0].chNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07002331 //Select Best Channel from Channel List if Configured
Peng Xuafc34e32014-09-25 13:23:55 +05302332 bestChNum = sapSelectPreferredChannelFromChannelList(bestChNum,
2333 pSapCtx, pSpectInfoParams);
2334#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002335
2336 // Free all the allocated memory
2337 sapChanSelExit(pSpectInfoParams);
2338
2339 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Running SAP Ch select Completed, Ch=%d",
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07002340 __func__, bestChNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07002341 if (bestChNum > 0 && bestChNum <= 252)
2342 return bestChNum;
2343 else
2344 return SAP_CHANNEL_NOT_SELECTED;
2345}
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07002346