blob: ecbc08e5727060ec36d5fd3dfd92fbf09ecb6256 [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
42/*===========================================================================
43
44 s a p C h S e l e c t . C
Jeff Johnson295189b2012-06-20 16:38:30 -070045 OVERVIEW:
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053046
Jeff Johnson295189b2012-06-20 16:38:30 -070047 This software unit holds the implementation of the WLAN SAP modules
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053048 functions for channel selection.
Jeff Johnson295189b2012-06-20 16:38:30 -070049
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053050 DEPENDENCIES:
Jeff Johnson295189b2012-06-20 16:38:30 -070051
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053052 Are listed for each API below.
Jeff Johnson295189b2012-06-20 16:38:30 -070053===========================================================================*/
54
55/*===========================================================================
56
57 EDIT HISTORY FOR FILE
58
59
60 This section contains comments describing changes made to the module.
61 Notice that changes are listed in reverse chronological order.
62
63
64
65 when who what, where, why
66---------- --- --------------------------------------------------------
672010-03-15 SOFTAP Created module
68
69===========================================================================*/
70
71
72/*--------------------------------------------------------------------------
73 Include Files
74------------------------------------------------------------------------*/
75#include "vos_trace.h"
76#include "csrApi.h"
77#include "sme_Api.h"
78#include "sapChSelect.h"
79#include "sapInternal.h"
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -080080#ifdef ANI_OS_TYPE_QNX
81#include "stdio.h"
82#endif
Jeff Johnson295189b2012-06-20 16:38:30 -070083
84/*--------------------------------------------------------------------------
85 Function definitions
86--------------------------------------------------------------------------*/
87
88/*--------------------------------------------------------------------------
89 Defines
90--------------------------------------------------------------------------*/
91#define SAP_DEBUG
92
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -070093#define IS_RSSI_VALID( extRssi, rssi ) \
94( \
95 ((extRssi < rssi)?eANI_BOOLEAN_TRUE:eANI_BOOLEAN_FALSE) \
96)
97
Leo Chang0b0e45a2013-12-15 15:18:55 -080098#ifdef FEATURE_WLAN_CH_AVOID
99extern safeChannelType safeChannels[];
100#endif /* FEATURE_WLAN_CH_AVOID */
101
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700102/*==========================================================================
103 FUNCTION sapCleanupChannelList
104
105 DESCRIPTION
106 Function sapCleanupChannelList frees up the memory allocated to the channel list.
107
108 DEPENDENCIES
109 NA.
110
111 PARAMETERS
112
113 IN
114 NULL
115
116 RETURN VALUE
117 NULL
118============================================================================*/
119
120void sapCleanupChannelList(void)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700121{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700122 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530123 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700124
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700125 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
126 "Cleaning up the channel list structure");
127
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530128 if (NULL == pvosGCtx)
129 {
130 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
131 "SAP Global Context is NULL");
132 return ;
133 }
134
135 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
136 if (NULL == pSapCtx)
137 {
138 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
139 "SAP Context is NULL");
140 return ;
141 }
142
143 pSapCtx->SapChnlList.numChannel = 0;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700144 vos_mem_free(pSapCtx->SapChnlList.channelList);
145 pSapCtx->SapChnlList.channelList = NULL;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700146}
147
148/*==========================================================================
149 FUNCTION sapSetPreferredChannel
150
151 DESCRIPTION
152 Function sapSetPreferredChannel sets the channel list which has been configured
153 into sap context (pSapCtx) which will be used at the time of best channel selection.
154
155 DEPENDENCIES
156 NA.
157
158 PARAMETERS
159
160 IN
161 *ptr: pointer having the command followed by the arguments in string format
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700162
163 RETURN VALUE
164 int: return 0 when success else returns error code.
165============================================================================*/
166
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800167int sapSetPreferredChannel(tANI_U8* ptr)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700168{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700169
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700170 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530171 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700172 tANI_U8* param;
173 int tempInt;
174 int j;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700175
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700176 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700177 "Enter: %s", __func__);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700178
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530179 if (NULL == pvosGCtx)
180 {
181 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
182 "SAP Global Context is NULL");
183 return -EINVAL;
184 }
185
186 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
187 if (NULL == pSapCtx)
188 {
189 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
190 "SAP Context is NULL");
191 return -EINVAL;
192 }
193
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700194 if (NULL != pSapCtx->SapChnlList.channelList)
195 {
196 sapCleanupChannelList();
197 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700198
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800199 param = strchr(ptr, ' ');
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700200 /*no argument after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800201 if (NULL == param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700202 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800203 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700204 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700205
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700206 /*no space after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800207 else if (SPACE_ASCII_VALUE != *param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700208 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800209 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700210 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700211
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700212 param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700213
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700214 /*removing empty spaces*/
215 while((SPACE_ASCII_VALUE == *param)&& ('\0' != *param) ) param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700216
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700217 /*no argument followed by spaces*/
218 if('\0' == *param)
219 {
220 return -EINVAL;
221 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700222
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700223 /*getting the first argument ie the number of channels*/
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800224 if (sscanf(param, "%d ", &tempInt) != 1)
225 {
226 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800227 "%s: Cannot get number of channels from input", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800228 return -EINVAL;
229 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700230
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700231 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800232 "%s: Number of channel added are: %d", __func__, tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700233
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800234 if (tempInt <= 0 || tempInt > 255)
235 {
236 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800237 "%s: Invalid Number of channel received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800238 return -EINVAL;
239 }
240
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700241 /*allocating space for the desired number of channels*/
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530242 pSapCtx->SapChnlList.channelList = (v_U8_t *)vos_mem_malloc(tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700243
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530244 if (NULL == pSapCtx->SapChnlList.channelList)
245 {
246 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
247 "In %s, VOS_MALLOC_ERR", __func__);
248 return -EINVAL;
249 }
250
251 pSapCtx->SapChnlList.numChannel = tempInt;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700252 for(j=0;j<pSapCtx->SapChnlList.numChannel;j++)
253 {
254
255 /*param pointing to the beginning of first space after number of channels*/
256 param = strpbrk( param, " " );
257 /*no channel list after the number of channels argument*/
258 if (NULL == param)
259 {
260 sapCleanupChannelList();
261 return -EINVAL;
262 }
263
264 param++;
265
266 /*removing empty space*/
267 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
268
269 /*no channel list after the number of channels argument and spaces*/
270 if( '\0' == *param )
271 {
272 sapCleanupChannelList();
273 return -EINVAL;
274 }
275
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800276 if (sscanf(param, "%d ", &tempInt) != 1)
277 {
278 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800279 "%s: Cannot read channel number", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800280 sapCleanupChannelList();
281 return -EINVAL;
282 }
283 if (tempInt < 0 || tempInt > 255)
284 {
285 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800286 "%s: Invalid channel number received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800287 sapCleanupChannelList();
288 return -EINVAL;
289 }
290
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700291 pSapCtx->SapChnlList.channelList[j] = tempInt;
292
293 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800294 "%s: Channel %d added to preferred channel list",
295 __func__, pSapCtx->SapChnlList.channelList[j] );
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700296
297 }
298
299 /*extra arguments check*/
300 param = strpbrk( param, " " );
301 if (NULL != param)
302 {
303 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
304
305 if('\0' != *param)
306 {
307 sapCleanupChannelList();
308 return -EINVAL;
309 }
310 }
311
312 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700313 "Exit: %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700314
315 return 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700316}
317
318/*==========================================================================
319 FUNCTION sapSelectPreferredChannelFromChannelList
320
321 DESCRIPTION
322 Function sapSelectPreferredChannelFromChannelList calculates the best channel
323 among the configured channel list. If channel list not configured then returns
324 the best channel calculated among all the channel list.
325
326 DEPENDENCIES
327 NA.
328
329 PARAMETERS
330
331 IN
332 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
333 bestChNum: best channel already calculated among all the chanels
334 pSapCtx: having info of channel list from which best channel is selected
335
336 RETURN VALUE
337 v_U8_t: best channel
338============================================================================*/
339v_U8_t sapSelectPreferredChannelFromChannelList(v_U8_t bestChNum,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700340 ptSapContext pSapCtx,
341 tSapChSelSpectInfo *pSpectInfoParams)
342{
343 v_U8_t j = 0;
344 v_U8_t count = 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700345
346 //If Channel List is not Configured don't do anything
347 //Else return the Best Channel from the Channel List
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700348 if((NULL == pSapCtx->SapChnlList.channelList) ||
349 (NULL == pSpectInfoParams) ||
350 (0 == pSapCtx->SapChnlList.numChannel))
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700351 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700352 return bestChNum;
353 }
354
355 if (bestChNum > 0 && bestChNum <= 252)
356 {
357 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700358 {
359 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
360 // Select the best channel from allowed list
361 for(j=0;j< pSapCtx->SapChnlList.numChannel;j++)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700362 {
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700363 if( (pSapCtx->SapChnlList.channelList[j]) == bestChNum)
364 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700365 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
366 "Best channel computed from Channel List is: %d",
367 bestChNum);
368 return bestChNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700369 }
370 }
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700371 }
372
373 return SAP_CHANNEL_NOT_SELECTED;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700374 }
375 else
376 return SAP_CHANNEL_NOT_SELECTED;
377}
378
379
Jeff Johnson295189b2012-06-20 16:38:30 -0700380/*==========================================================================
381 FUNCTION sapChanSelInit
382
383 DESCRIPTION
384 Function sapChanSelInit allocates the memory, intializes the
385 structures used by the channel selection algorithm
386
387 DEPENDENCIES
388 NA.
389
390 PARAMETERS
391
392 IN
393 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
394
395 RETURN VALUE
396 v_BOOL_t: Success or FAIL
397
398 SIDE EFFECTS
399============================================================================*/
400v_BOOL_t sapChanSelInit(tHalHandle halHandle, tSapChSelSpectInfo *pSpectInfoParams)
401{
402 tSapSpectChInfo *pSpectCh = NULL;
403 v_U8_t *pChans = NULL;
404 v_U16_t channelnum = 0;
405 tpAniSirGlobal pMac = PMAC_STRUCT(halHandle);
Leo Chang0b0e45a2013-12-15 15:18:55 -0800406#ifdef FEATURE_WLAN_CH_AVOID
407 v_U16_t i;
408 v_BOOL_t chSafe = VOS_TRUE;
409#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700410
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700411 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700412
413 // Channels for that 2.4GHz band
414 //Considered only for 2.4GHz need to change in future to support 5GHz support
415 pSpectInfoParams->numSpectChans = pMac->scan.base20MHzChannels.numChannels;
416
417 // Allocate memory for weight computation of 2.4GHz
418 pSpectCh = (tSapSpectChInfo *)vos_mem_malloc((pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
419
420 if(pSpectCh == NULL) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700421 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, VOS_MALLOC_ERR", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700422 return eSAP_FALSE;
423 }
424
425 vos_mem_zero(pSpectCh, (pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
426
427 // Initialize the pointers in the DfsParams to the allocated memory
428 pSpectInfoParams->pSpectCh = pSpectCh;
429
430 pChans = pMac->scan.base20MHzChannels.channelList;
431
432 // Fill the channel number in the spectrum in the operating freq band
433 for (channelnum = 0; channelnum < pSpectInfoParams->numSpectChans; channelnum++) {
Leo Chang0b0e45a2013-12-15 15:18:55 -0800434#ifdef FEATURE_WLAN_CH_AVOID
435 chSafe = VOS_TRUE;
436 for(i = 0; i < NUM_20MHZ_RF_CHANNELS; i++)
437 {
438 if((safeChannels[i].channelNumber == *pChans) &&
439 (VOS_FALSE == safeChannels[i].isSafe))
440 {
441 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
442 "%s : CH %d is not safe", __func__, *pChans);
443 chSafe = VOS_FALSE;
444 break;
445 }
446 }
447#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700448
449 if(*pChans == 14 ) //OFDM rates are not supported on channel 14
450 continue;
Leo Chang0b0e45a2013-12-15 15:18:55 -0800451#ifdef FEATURE_WLAN_CH_AVOID
452 if (VOS_TRUE == chSafe)
453 {
454#endif /* FEATURE_WLAN_CH_AVOID */
455 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_DEBUG,
456 "%s : Available Ch %d",
457 __func__, *pChans);
458 pSpectCh->chNum = *pChans;
459 pSpectCh->valid = eSAP_TRUE;
460 // Initialise for all channels
461 pSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
462 // Initialise 20MHz for all the Channels
463 pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH;
464 pSpectCh++;
465#ifdef FEATURE_WLAN_CH_AVOID
466 }
467#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700468 pChans++;
469 }
470 return eSAP_TRUE;
471}
472
473/*==========================================================================
474 FUNCTION sapweightRssiCount
475
476 DESCRIPTION
477 Function weightRssiCount calculates the channel weight due to rssi
478 and data count(here number of BSS observed)
479
480 DEPENDENCIES
481 NA.
482
483 PARAMETERS
484
485 IN
486 rssi : Max signal strength receieved from a BSS for the channel
487 count : Number of BSS observed in the channel
488
489 RETURN VALUE
490 v_U32_t : Calculated channel weight based on above two
491
492 SIDE EFFECTS
493============================================================================*/
494v_U32_t sapweightRssiCount(v_S7_t rssi, v_U16_t count)
495{
496 v_S31_t rssiWeight=0;
497 v_S31_t countWeight=0;
498 v_U32_t rssicountWeight=0;
499
500 // Weight from RSSI
501 rssiWeight = SOFTAP_RSSI_WEIGHT * (rssi - SOFTAP_MIN_RSSI)
502 /(SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530503
Jeff Johnson295189b2012-06-20 16:38:30 -0700504 if(rssiWeight > SOFTAP_RSSI_WEIGHT)
505 rssiWeight = SOFTAP_RSSI_WEIGHT;
506 else if (rssiWeight < 0)
507 rssiWeight = 0;
508
509 // Weight from data count
510 countWeight = SOFTAP_COUNT_WEIGHT * (count - SOFTAP_MIN_COUNT)
511 /(SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530512
Jeff Johnson295189b2012-06-20 16:38:30 -0700513 if(countWeight > SOFTAP_COUNT_WEIGHT)
514 countWeight = SOFTAP_COUNT_WEIGHT;
515 else if (countWeight < 0)
516 countWeight = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530517
Jeff Johnson295189b2012-06-20 16:38:30 -0700518 rssicountWeight = rssiWeight + countWeight;
519
520 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 -0700521 __func__, rssiWeight, countWeight, rssicountWeight);
Jeff Johnson295189b2012-06-20 16:38:30 -0700522
523 return(rssicountWeight);
524}
525
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800526
527/*==========================================================================
528 FUNCTION sapInterferenceRssiCount
529
530 DESCRIPTION
531 Function sapInterferenceRssiCount Considers the Adjacent channel rssi
532 and data count(here number of BSS observed)
533
534 DEPENDENCIES
535 NA.
536
537 PARAMETERS
538
539 pSpectCh : Channel Information
540
541 RETURN VALUE
542 NA.
543
544 SIDE EFFECTS
545============================================================================*/
546void sapInterferenceRssiCount(tSapSpectChInfo *pSpectCh)
547{
548 tSapSpectChInfo *pExtSpectCh = NULL;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700549 v_S31_t rssi;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530550
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800551 switch(pSpectCh->chNum)
552 {
553 case CHANNEL_1:
554 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530555 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800556 {
557 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530558 rssi = pSpectCh->rssiAgr +
559 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700560 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
561 {
562 pExtSpectCh->rssiAgr = rssi;
563 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530564 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800565 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
566 }
567 pExtSpectCh = (pSpectCh + 2);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530568 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800569 {
570 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530571 rssi = pSpectCh->rssiAgr +
572 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700573 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
574 {
575 pExtSpectCh->rssiAgr = rssi;
576 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800577 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
578 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
579 }
580 pExtSpectCh = (pSpectCh + 3);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530581 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800582 {
583 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530584 rssi = pSpectCh->rssiAgr +
585 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700586 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
587 {
588 pExtSpectCh->rssiAgr = rssi;
589 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800590 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
591 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
592 }
593 pExtSpectCh = (pSpectCh + 4);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530594 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800595 {
596 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530597 rssi = pSpectCh->rssiAgr +
598 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700599 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
600 {
601 pExtSpectCh->rssiAgr = rssi;
602 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530603 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800604 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
605 }
606 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530607
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800608 case CHANNEL_2:
609 pExtSpectCh = (pSpectCh - 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530610 if (pExtSpectCh != NULL)
611 {
612 ++pExtSpectCh->bssCount;
613 rssi = pSpectCh->rssiAgr +
614 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
615 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
616 {
617 pExtSpectCh->rssiAgr = rssi;
618 }
619 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
620 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
621 }
622 pExtSpectCh = (pSpectCh + 1);
623 if (pExtSpectCh != NULL)
624 {
625 ++pExtSpectCh->bssCount;
626 rssi = pSpectCh->rssiAgr +
627 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
628 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
629 {
630 pExtSpectCh->rssiAgr = rssi;
631 }
632 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
633 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
634 }
635 pExtSpectCh = (pSpectCh + 2);
636 if (pExtSpectCh != NULL)
637 {
638 ++pExtSpectCh->bssCount;
639 rssi = pSpectCh->rssiAgr +
640 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
641 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
642 {
643 pExtSpectCh->rssiAgr = rssi;
644 }
645 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
646 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
647 }
648 pExtSpectCh = (pSpectCh + 3);
649 if (pExtSpectCh != NULL)
650 {
651 ++pExtSpectCh->bssCount;
652 rssi = pSpectCh->rssiAgr +
653 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
654 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
655 {
656 pExtSpectCh->rssiAgr = rssi;
657 }
658 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
659 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
660 }
661 pExtSpectCh = (pSpectCh + 4);
662 if (pExtSpectCh != NULL)
663 {
664 ++pExtSpectCh->bssCount;
665 rssi = pSpectCh->rssiAgr +
666 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
667 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
668 {
669 pExtSpectCh->rssiAgr = rssi;
670 }
671 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
672 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
673 }
674 break;
675 case CHANNEL_3:
676 pExtSpectCh = (pSpectCh - 2);
677 if (pExtSpectCh != NULL)
678 {
679 ++pExtSpectCh->bssCount;
680 rssi = pSpectCh->rssiAgr +
681 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
682 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
683 {
684 pExtSpectCh->rssiAgr = rssi;
685 }
686 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
687 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
688 }
689 pExtSpectCh = (pSpectCh - 1);
690 if (pExtSpectCh != NULL)
691 {
692 ++pExtSpectCh->bssCount;
693 rssi = pSpectCh->rssiAgr +
694 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
695 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
696 {
697 pExtSpectCh->rssiAgr = rssi;
698 }
699 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
700 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
701 }
702 pExtSpectCh = (pSpectCh + 1);
703 if (pExtSpectCh != NULL)
704 {
705 ++pExtSpectCh->bssCount;
706 rssi = pSpectCh->rssiAgr +
707 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
708 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
709 {
710 pExtSpectCh->rssiAgr = rssi;
711 }
712 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
713 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
714 }
715 pExtSpectCh = (pSpectCh + 2);
716 if (pExtSpectCh != NULL)
717 {
718 ++pExtSpectCh->bssCount;
719 rssi = pSpectCh->rssiAgr +
720 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
721 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
722 {
723 pExtSpectCh->rssiAgr = rssi;
724 }
725 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
726 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
727 }
728 pExtSpectCh = (pSpectCh + 3);
729 if (pExtSpectCh != NULL)
730 {
731 ++pExtSpectCh->bssCount;
732 rssi = pSpectCh->rssiAgr +
733 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
734 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
735 {
736 pExtSpectCh->rssiAgr = rssi;
737 }
738 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
739 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
740 }
741 pExtSpectCh = (pSpectCh + 4);
742 if (pExtSpectCh != NULL)
743 {
744 ++pExtSpectCh->bssCount;
745 rssi = pSpectCh->rssiAgr +
746 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
747 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
748 {
749 pExtSpectCh->rssiAgr = rssi;
750 }
751 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
752 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
753 }
754 break;
755 case CHANNEL_4:
756 pExtSpectCh = (pSpectCh - 3);
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800757 if(pExtSpectCh != NULL)
758 {
759 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530760 rssi = pSpectCh->rssiAgr +
761 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
762 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
763 {
764 pExtSpectCh->rssiAgr = rssi;
765 }
766 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
767 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
768 }
769 pExtSpectCh = (pSpectCh - 2);
770 if (pExtSpectCh != NULL)
771 {
772 ++pExtSpectCh->bssCount;
773 rssi = pSpectCh->rssiAgr +
774 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
775 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
776 {
777 pExtSpectCh->rssiAgr = rssi;
778 }
779 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
780 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
781 }
782 pExtSpectCh = (pSpectCh - 1);
783 if (pExtSpectCh != NULL)
784 {
785 ++pExtSpectCh->bssCount;
786 rssi = pSpectCh->rssiAgr +
787 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700788 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
789 {
790 pExtSpectCh->rssiAgr = rssi;
791 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800792 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
793 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
794 }
795 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530796 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800797 {
798 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530799 rssi = pSpectCh->rssiAgr +
800 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
801 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
802 {
803 pExtSpectCh->rssiAgr = rssi;
804 }
805 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
806 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
807 }
808 pExtSpectCh = (pSpectCh + 2);
809 if (pExtSpectCh != NULL)
810 {
811 ++pExtSpectCh->bssCount;
812 rssi = pSpectCh->rssiAgr +
813 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
814 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
815 {
816 pExtSpectCh->rssiAgr = rssi;
817 }
818 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
819 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
820 }
821 pExtSpectCh = (pSpectCh + 3);
822 if (pExtSpectCh != NULL)
823 {
824 ++pExtSpectCh->bssCount;
825 rssi = pSpectCh->rssiAgr +
826 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
827 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
828 {
829 pExtSpectCh->rssiAgr = rssi;
830 }
831 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
832 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
833 }
834 pExtSpectCh = (pSpectCh + 4);
835 if (pExtSpectCh != NULL)
836 {
837 ++pExtSpectCh->bssCount;
838 rssi = pSpectCh->rssiAgr +
839 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
840 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
841 {
842 pExtSpectCh->rssiAgr = rssi;
843 }
844 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
845 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
846 }
847 break;
848
849 case CHANNEL_5:
850 case CHANNEL_6:
851 case CHANNEL_7:
852 pExtSpectCh = (pSpectCh - 4);
853 if (pExtSpectCh != NULL)
854 {
855 ++pExtSpectCh->bssCount;
856 rssi = pSpectCh->rssiAgr +
857 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700858 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
859 {
860 pExtSpectCh->rssiAgr = rssi;
861 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800862 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
863 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
864 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530865 pExtSpectCh = (pSpectCh - 3);
866 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800867 {
868 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530869 rssi = pSpectCh->rssiAgr +
870 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700871 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
872 {
873 pExtSpectCh->rssiAgr = rssi;
874 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800875 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
876 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
877 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530878 pExtSpectCh = (pSpectCh - 2);
879 if (pExtSpectCh != NULL)
880 {
881 ++pExtSpectCh->bssCount;
882 rssi = pSpectCh->rssiAgr +
883 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
884 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
885 {
886 pExtSpectCh->rssiAgr = rssi;
887 }
888 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
889 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
890 }
891 pExtSpectCh = (pSpectCh - 1);
892 if(pExtSpectCh != NULL)
893 {
894 ++pExtSpectCh->bssCount;
895 rssi = pSpectCh->rssiAgr +
896 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
897 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
898 {
899 pExtSpectCh->rssiAgr = rssi;
900 }
901 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
902 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
903 }
904 pExtSpectCh = (pSpectCh + 1);
905 if (pExtSpectCh != NULL)
906 {
907 ++pExtSpectCh->bssCount;
908 rssi = pSpectCh->rssiAgr +
909 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
910 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
911 {
912 pExtSpectCh->rssiAgr = rssi;
913 }
914 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
915 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
916 }
917 pExtSpectCh = (pSpectCh + 2);
918 if(pExtSpectCh != NULL)
919 {
920 ++pExtSpectCh->bssCount;
921 rssi = pSpectCh->rssiAgr +
922 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
923 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
924 {
925 pExtSpectCh->rssiAgr = rssi;
926 }
927 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
928 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
929 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800930 pExtSpectCh = (pSpectCh + 3);
931 if(pExtSpectCh != NULL)
932 {
933 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530934 rssi = pSpectCh->rssiAgr +
935 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
936 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
937 {
938 pExtSpectCh->rssiAgr = rssi;
939 }
940 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
941 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
942 }
943 pExtSpectCh = (pSpectCh + 4);
944 if (pExtSpectCh != NULL)
945 {
946 ++pExtSpectCh->bssCount;
947 rssi = pSpectCh->rssiAgr +
948 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700949 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
950 {
951 pExtSpectCh->rssiAgr = rssi;
952 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800953 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
954 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
955 }
956 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530957
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800958 case CHANNEL_8:
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800959 pExtSpectCh = (pSpectCh - 4);
960 if(pExtSpectCh != NULL)
961 {
962 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530963 rssi = pSpectCh->rssiAgr +
964 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
965 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
966 {
967 pExtSpectCh->rssiAgr = rssi;
968 }
969 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
970 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
971 }
972
973 pExtSpectCh = (pSpectCh - 3);
974 if (pExtSpectCh != NULL)
975 {
976 ++pExtSpectCh->bssCount;
977 rssi = pSpectCh->rssiAgr +
978 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
979 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
980 {
981 pExtSpectCh->rssiAgr = rssi;
982 }
983 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
984 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
985 }
986 pExtSpectCh = (pSpectCh - 2);
987 if (pExtSpectCh != NULL)
988 {
989 ++pExtSpectCh->bssCount;
990 rssi = pSpectCh->rssiAgr +
991 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
992 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
993 {
994 pExtSpectCh->rssiAgr = rssi;
995 }
996 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
997 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
998 }
999 pExtSpectCh = (pSpectCh - 1);
1000 if (pExtSpectCh != NULL)
1001 {
1002 ++pExtSpectCh->bssCount;
1003 rssi = pSpectCh->rssiAgr +
1004 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1005 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1006 {
1007 pExtSpectCh->rssiAgr = rssi;
1008 }
1009 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1010 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1011 }
1012 pExtSpectCh = (pSpectCh + 1);
1013 if (pExtSpectCh != NULL)
1014 {
1015 ++pExtSpectCh->bssCount;
1016 rssi = pSpectCh->rssiAgr +
1017 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1018 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1019 {
1020 pExtSpectCh->rssiAgr = rssi;
1021 }
1022 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1023 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1024 }
1025 pExtSpectCh = (pSpectCh + 2);
1026 if (pExtSpectCh != NULL)
1027 {
1028 ++pExtSpectCh->bssCount;
1029 rssi = pSpectCh->rssiAgr +
1030 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1031 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1032 {
1033 pExtSpectCh->rssiAgr = rssi;
1034 }
1035 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1036 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1037 }
1038 pExtSpectCh = (pSpectCh + 3);
1039 if (pExtSpectCh != NULL)
1040 {
1041 ++pExtSpectCh->bssCount;
1042 rssi = pSpectCh->rssiAgr +
1043 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1044 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1045 {
1046 pExtSpectCh->rssiAgr = rssi;
1047 }
1048 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1049 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1050 }
1051 break;
1052
1053 case CHANNEL_9:
1054 pExtSpectCh = (pSpectCh - 4);
1055 if (pExtSpectCh != NULL)
1056 {
1057 ++pExtSpectCh->bssCount;
1058 rssi = pSpectCh->rssiAgr +
1059 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001060 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1061 {
1062 pExtSpectCh->rssiAgr = rssi;
1063 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001064 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1065 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1066 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301067
1068 pExtSpectCh = (pSpectCh - 3);
1069 if (pExtSpectCh != NULL)
1070 {
1071 ++pExtSpectCh->bssCount;
1072 rssi = pSpectCh->rssiAgr +
1073 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1074 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1075 {
1076 pExtSpectCh->rssiAgr = rssi;
1077 }
1078 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1079 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1080 }
1081 pExtSpectCh = (pSpectCh - 2);
1082 if (pExtSpectCh != NULL)
1083 {
1084 ++pExtSpectCh->bssCount;
1085 rssi = pSpectCh->rssiAgr +
1086 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1087 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1088 {
1089 pExtSpectCh->rssiAgr = rssi;
1090 }
1091 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1092 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1093 }
1094 pExtSpectCh = (pSpectCh - 1);
1095 if (pExtSpectCh != NULL)
1096 {
1097 ++pExtSpectCh->bssCount;
1098 rssi = pSpectCh->rssiAgr +
1099 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1100 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1101 {
1102 pExtSpectCh->rssiAgr = rssi;
1103 }
1104 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1105 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1106 }
1107 pExtSpectCh = (pSpectCh + 1);
1108 if (pExtSpectCh != NULL)
1109 {
1110 ++pExtSpectCh->bssCount;
1111 rssi = pSpectCh->rssiAgr +
1112 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1113 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1114 {
1115 pExtSpectCh->rssiAgr = rssi;
1116 }
1117 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1118 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1119 }
1120 pExtSpectCh = (pSpectCh + 2);
1121 if (pExtSpectCh != NULL)
1122 {
1123 ++pExtSpectCh->bssCount;
1124 rssi = pSpectCh->rssiAgr +
1125 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1126 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1127 {
1128 pExtSpectCh->rssiAgr = rssi;
1129 }
1130 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1131 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1132 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001133 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301134
1135 case CHANNEL_10:
1136 pExtSpectCh = (pSpectCh - 4);
1137 if (pExtSpectCh != NULL)
1138 {
1139 ++pExtSpectCh->bssCount;
1140 rssi = pSpectCh->rssiAgr +
1141 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1142 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1143 {
1144 pExtSpectCh->rssiAgr = rssi;
1145 }
1146 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1147 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1148 }
1149
1150 pExtSpectCh = (pSpectCh - 3);
1151 if (pExtSpectCh != NULL)
1152 {
1153 ++pExtSpectCh->bssCount;
1154 rssi = pSpectCh->rssiAgr +
1155 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1156 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1157 {
1158 pExtSpectCh->rssiAgr = rssi;
1159 }
1160 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1161 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1162 }
1163 pExtSpectCh = (pSpectCh - 2);
1164 if(pExtSpectCh != NULL)
1165 {
1166 ++pExtSpectCh->bssCount;
1167 rssi = pSpectCh->rssiAgr +
1168 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1169 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1170 {
1171 pExtSpectCh->rssiAgr = rssi;
1172 }
1173 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1174 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1175 }
1176 pExtSpectCh = (pSpectCh - 1);
1177 if (pExtSpectCh != NULL)
1178 {
1179 ++pExtSpectCh->bssCount;
1180 rssi = pSpectCh->rssiAgr +
1181 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1182 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1183 {
1184 pExtSpectCh->rssiAgr = rssi;
1185 }
1186 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1187 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1188 }
1189 pExtSpectCh = (pSpectCh + 1);
1190 if (pExtSpectCh != NULL)
1191 {
1192 ++pExtSpectCh->bssCount;
1193 rssi = pSpectCh->rssiAgr +
1194 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1195 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1196 {
1197 pExtSpectCh->rssiAgr = rssi;
1198 }
1199 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1200 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1201 }
1202 break;
1203
1204 case CHANNEL_11:
1205 pExtSpectCh = (pSpectCh - 1);
1206 if (pExtSpectCh != NULL)
1207 {
1208 ++pExtSpectCh->bssCount;
1209 rssi = pSpectCh->rssiAgr +
1210 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1211 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1212 {
1213 pExtSpectCh->rssiAgr = rssi;
1214 }
1215 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1216 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1217 }
1218 pExtSpectCh = (pSpectCh - 2);
1219 if (pExtSpectCh != NULL)
1220 {
1221 ++pExtSpectCh->bssCount;
1222 rssi = pSpectCh->rssiAgr +
1223 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1224 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1225 {
1226 pExtSpectCh->rssiAgr = rssi;
1227 }
1228 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1229 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1230 }
1231 pExtSpectCh = (pSpectCh - 3);
1232 if (pExtSpectCh != NULL)
1233 {
1234 ++pExtSpectCh->bssCount;
1235 rssi = pSpectCh->rssiAgr +
1236 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1237 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1238 {
1239 pExtSpectCh->rssiAgr = rssi;
1240 }
1241 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1242 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1243 }
1244 pExtSpectCh = (pSpectCh - 4);
1245 if (pExtSpectCh != NULL)
1246 {
1247 ++pExtSpectCh->bssCount;
1248 rssi = pSpectCh->rssiAgr +
1249 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1250 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1251 {
1252 pExtSpectCh->rssiAgr = rssi;
1253 }
1254 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1255 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1256 }
1257 break;
1258
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001259 default:
1260 break;
1261 }
1262}
1263
Jeff Johnson295189b2012-06-20 16:38:30 -07001264/*==========================================================================
1265 FUNCTION sapComputeSpectWeight
1266
1267 DESCRIPTION
1268 Main function for computing the weight of each channel in the
1269 spectrum based on the RSSI value of the BSSes on the channel
1270 and number of BSS
1271
1272 DEPENDENCIES
1273 NA.
1274
1275 PARAMETERS
1276
1277 IN
1278 pSpectInfoParams : Pointer to the tSpectInfoParams structure
1279 halHandle : Pointer to HAL handle
1280 pResult : Pointer to tScanResultHandle
1281
1282 RETURN VALUE
1283 void : NULL
1284
1285 SIDE EFFECTS
1286============================================================================*/
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301287void sapComputeSpectWeight( tSapChSelSpectInfo* pSpectInfoParams,
1288 tHalHandle halHandle, tScanResultHandle pResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001289{
1290 v_S7_t rssi = 0;
1291 v_U8_t chn_num = 0;
1292 v_U8_t channel_id = 0;
1293
1294 tCsrScanResultInfo *pScanResult;
1295 tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001296 v_U32_t operatingBand;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001297 v_U16_t channelWidth;
1298 v_U16_t secondaryChannelOffset;
1299 v_U16_t centerFreq;
1300 v_U16_t vhtSupport;
1301 v_U32_t ieLen = 0;
1302 tSirProbeRespBeacon *pBeaconStruct;
1303 tpAniSirGlobal pMac = (tpAniSirGlobal) halHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -07001304
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301305 pBeaconStruct = vos_mem_malloc(sizeof(tSirProbeRespBeacon));
1306 if ( NULL == pBeaconStruct )
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001307 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301308 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1309 "Unable to allocate memory in sapComputeSpectWeight\n");
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001310 return;
1311 }
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001312 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Computing spectral weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001313
1314 /**
1315 * Soft AP specific channel weight calculation using DFS formula
1316 */
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001317 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
Jeff Johnson295189b2012-06-20 16:38:30 -07001318
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301319 pScanResult = sme_ScanResultGetFirst(halHandle, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07001320
1321 while (pScanResult) {
1322 pSpectCh = pSpectInfoParams->pSpectCh;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001323 // Defining the default values, so that any value will hold the default values
1324 channelWidth = eHT_CHANNEL_WIDTH_20MHZ;
1325 secondaryChannelOffset = PHY_SINGLE_CHANNEL_CENTERED;
1326 vhtSupport = 0;
1327 centerFreq = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301328
1329 if (pScanResult->BssDescriptor.ieFields != NULL)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001330 {
1331 ieLen = (pScanResult->BssDescriptor.length + sizeof(tANI_U16) + sizeof(tANI_U32) - sizeof(tSirBssDescription));
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301332 vos_mem_set((tANI_U8 *) pBeaconStruct, sizeof(tSirProbeRespBeacon), 0);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301333
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001334 if ((sirParseBeaconIE(pMac, pBeaconStruct,(tANI_U8 *)( pScanResult->BssDescriptor.ieFields), ieLen)) == eSIR_SUCCESS)
1335 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301336 if (pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001337 {
1338 channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet;
1339 secondaryChannelOffset = pBeaconStruct->HTInfo.secondaryChannelOffset;
1340 if(pBeaconStruct->VHTOperation.present)
1341 {
1342 vhtSupport = pBeaconStruct->VHTOperation.present;
1343 if(pBeaconStruct->VHTOperation.chanWidth > WNI_CFG_VHT_CHANNEL_WIDTH_20_40MHZ)
1344 {
1345 channelWidth = eHT_CHANNEL_WIDTH_80MHZ;
1346 centerFreq = pBeaconStruct->VHTOperation.chanCenterFreqSeg1;
1347 }
1348 }
1349 }
1350 }
1351 }
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001352 // Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list
Jeff Johnson295189b2012-06-20 16:38:30 -07001353 for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; chn_num++) {
1354
1355 /*
1356 * if the Beacon has channel ID, use it other wise we will
1357 * rely on the channelIdSelf
1358 */
1359 if(pScanResult->BssDescriptor.channelId == 0)
1360 channel_id = pScanResult->BssDescriptor.channelIdSelf;
1361 else
1362 channel_id = pScanResult->BssDescriptor.channelId;
1363
krunal sonic39d9592014-02-04 11:54:24 -08001364 if (pSpectCh && (channel_id == pSpectCh->chNum)) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001365 if (pSpectCh->rssiAgr < pScanResult->BssDescriptor.rssi)
1366 pSpectCh->rssiAgr = pScanResult->BssDescriptor.rssi;
1367
1368 ++pSpectCh->bssCount; // Increment the count of BSS
1369
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001370 if(operatingBand) // Connsidering the Extension Channel only in a channels
1371 {
1372 /* Updating the received ChannelWidth */
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301373 if (pSpectCh->channelWidth != channelWidth)
1374 pSpectCh->channelWidth = channelWidth;
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001375 /* If received ChannelWidth is other than HT20, we need to update the extension channel Params as well */
1376 /* channelWidth == 0, HT20 */
1377 /* channelWidth == 1, HT40 */
1378 /* channelWidth == 2, VHT80*/
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001379 switch(pSpectCh->channelWidth)
1380 {
1381 case eHT_CHANNEL_WIDTH_40MHZ: //HT40
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001382 switch( secondaryChannelOffset)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001383 {
1384 tSapSpectChInfo *pExtSpectCh = NULL;
1385 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY: // Above the Primary Channel
1386 pExtSpectCh = (pSpectCh + 1);
1387 if(pExtSpectCh != NULL)
1388 {
1389 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001390 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001391 // REducing the rssi by -20 and assigning it to Extension channel
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001392 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1393 {
1394 pExtSpectCh->rssiAgr = rssi;
1395 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001396 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1397 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1398 }
1399 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301400
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001401 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY: // Below the Primary channel
1402 pExtSpectCh = (pSpectCh - 1);
1403 if(pExtSpectCh != NULL)
1404 {
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001405 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1406 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1407 {
1408 pExtSpectCh->rssiAgr = rssi;
1409 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001410 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1411 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1412 ++pExtSpectCh->bssCount;
1413 }
1414 break;
1415 }
1416 break;
1417 case eHT_CHANNEL_WIDTH_80MHZ: // VHT80
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001418 if((centerFreq - channel_id) == 6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001419 {
1420 tSapSpectChInfo *pExtSpectCh = NULL;
1421 pExtSpectCh = (pSpectCh + 1);
1422 if(pExtSpectCh != NULL)
1423 {
1424 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001425 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1426 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1427 {
1428 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -20 and assigning it to Subband 1
1429 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001430 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1431 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1432 }
1433 pExtSpectCh = (pSpectCh + 2);
1434 if(pExtSpectCh != NULL)
1435 {
1436 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001437 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1438 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1439 {
1440 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -30 and assigning it to Subband 2
1441 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001442 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1443 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1444 }
1445 pExtSpectCh = (pSpectCh + 3);
1446 if(pExtSpectCh != NULL)
1447 {
1448 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001449 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1450 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1451 {
1452 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -40 and assigning it to Subband 3
1453 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001454 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1455 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301456 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001457 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001458 else if((centerFreq - channel_id) == 2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001459 {
1460 tSapSpectChInfo *pExtSpectCh = NULL;
1461 pExtSpectCh = (pSpectCh - 1 );
1462 if(pExtSpectCh != NULL)
1463 {
1464 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001465 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1466 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1467 {
1468 pExtSpectCh->rssiAgr = rssi;
1469 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001470 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1471 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1472 }
1473 pExtSpectCh = (pSpectCh + 1);
1474 if(pExtSpectCh != NULL)
1475 {
1476 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001477 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1478 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1479 {
1480 pExtSpectCh->rssiAgr = rssi;
1481 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001482 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1483 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1484 }
1485 pExtSpectCh = (pSpectCh + 2);
1486 if(pExtSpectCh != NULL)
1487 {
1488 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001489 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1490 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1491 {
1492 pExtSpectCh->rssiAgr = rssi;
1493 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001494 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1495 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1496 }
1497 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001498 else if((centerFreq - channel_id) == -2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001499 {
1500 tSapSpectChInfo *pExtSpectCh = NULL;
1501 pExtSpectCh = (pSpectCh - 1 );
1502 if(pExtSpectCh != NULL)
1503 {
1504 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001505 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1506 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1507 {
1508 pExtSpectCh->rssiAgr = rssi;
1509 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001510 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1511 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1512 }
1513 pExtSpectCh = (pSpectCh - 2);
1514 if(pExtSpectCh != NULL)
1515 {
1516 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001517 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1518 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1519 {
1520 pExtSpectCh->rssiAgr = rssi;
1521 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001522 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1523 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1524 }
1525 pExtSpectCh = (pSpectCh + 1);
1526 if(pExtSpectCh != NULL)
1527 {
1528 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001529 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1530 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1531 {
1532 pExtSpectCh->rssiAgr = rssi;
1533 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001534 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1535 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1536 }
1537 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001538 else if((centerFreq - channel_id) == -6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001539 {
1540 tSapSpectChInfo *pExtSpectCh = NULL;
1541 pExtSpectCh = (pSpectCh - 1 );
1542 if(pExtSpectCh != NULL)
1543 {
1544 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001545 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1546 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1547 {
1548 pExtSpectCh->rssiAgr = rssi;
1549 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001550 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1551 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1552 }
1553 pExtSpectCh = (pSpectCh - 2);
1554 if(pExtSpectCh != NULL)
1555 {
1556 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001557 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1558 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1559 {
1560 pExtSpectCh->rssiAgr = rssi;
1561 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001562 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1563 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1564 }
1565 pExtSpectCh = (pSpectCh - 3);
1566 if(pExtSpectCh != NULL)
1567 {
1568 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001569 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1570 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1571 {
1572 pExtSpectCh->rssiAgr = rssi;
1573 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001574 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1575 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1576 }
1577 }
1578 break;
1579 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301580 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001581 else if(operatingBand == RF_SUBBAND_2_4_GHZ)
1582 {
1583 sapInterferenceRssiCount(pSpectCh);
1584 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001585
Jeff Johnson295189b2012-06-20 16:38:30 -07001586 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301587 "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 -08001588 __func__, pScanResult->BssDescriptor.channelIdSelf, pScanResult->BssDescriptor.channelId, pScanResult->BssDescriptor.rssi, pSpectCh->bssCount, pScanResult,pSpectCh->channelWidth,secondaryChannelOffset,centerFreq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001589 pSpectCh++;
1590 break;
1591 } else {
1592 pSpectCh++;
1593 }
1594 }
1595
1596 pScanResult = sme_ScanResultGetNext(halHandle, pResult);
1597 }
1598
1599 // Calculate the weights for all channels in the spectrum pSpectCh
1600 pSpectCh = pSpectInfoParams->pSpectCh;
1601
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001602 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001603
1604 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); chn_num++) {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301605
Jeff Johnson295189b2012-06-20 16:38:30 -07001606 /*
1607 rssi : Maximum received signal strength among all BSS on that channel
1608 bssCount : Number of BSS on that channel
1609 */
1610
1611 rssi = (v_S7_t)pSpectCh->rssiAgr;
1612
1613 pSpectCh->weight = SAPDFS_NORMALISE_1000 * sapweightRssiCount(rssi, pSpectCh->bssCount);
1614
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301615 //------ Debug Info ------
1616 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1617 "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d", __func__,
1618 pSpectCh->chNum, pSpectCh->weight,
1619 pSpectCh->rssiAgr, pSpectCh->bssCount);
1620 //------ Debug Info ------
Jeff Johnson295189b2012-06-20 16:38:30 -07001621 pSpectCh++;
1622 }
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301623 vos_mem_free(pBeaconStruct);
Jeff Johnson295189b2012-06-20 16:38:30 -07001624}
1625
1626/*==========================================================================
1627 FUNCTION sapChanSelExit
1628
1629 DESCRIPTION
1630 Exit function for free out the allocated memory, to be called
1631 at the end of the dfsSelectChannel function
1632
1633 DEPENDENCIES
1634 NA.
1635
1636 PARAMETERS
1637
1638 IN
1639 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1640
1641 RETURN VALUE
1642 void : NULL
1643
1644 SIDE EFFECTS
1645============================================================================*/
1646void sapChanSelExit( tSapChSelSpectInfo *pSpectInfoParams )
1647{
1648 // Free all the allocated memory
1649 vos_mem_free(pSpectInfoParams->pSpectCh);
1650}
1651
1652/*==========================================================================
1653 FUNCTION sapSortChlWeight
1654
1655 DESCRIPTION
1656 Funtion to sort the channels with the least weight first
1657
1658 DEPENDENCIES
1659 NA.
1660
1661 PARAMETERS
1662
1663 IN
1664 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1665
1666 RETURN VALUE
1667 void : NULL
1668
1669 SIDE EFFECTS
1670============================================================================*/
1671void sapSortChlWeight(tSapChSelSpectInfo *pSpectInfoParams)
1672{
1673 tSapSpectChInfo temp;
1674
1675 tSapSpectChInfo *pSpectCh = NULL;
1676 v_U32_t i = 0, j = 0, minWeightIndex = 0;
1677
1678 pSpectCh = pSpectInfoParams->pSpectCh;
1679#ifdef SOFTAP_CHANNEL_RANGE
1680 // Sorting the channels as per weights
1681 for (i = 0; i < pSpectInfoParams->numSpectChans; i++) {
1682 minWeightIndex = i;
1683 for( j = i + 1; j < pSpectInfoParams->numSpectChans; j++) {
1684 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1685 minWeightIndex = j;
1686 }
1687 }
1688 if(minWeightIndex != i) {
1689 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1690 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1691 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1692 }
1693 }
1694#else
1695 // Sorting the channels as per weights
1696 for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) {
1697 minWeightIndex = i;
1698 for( j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) {
1699 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1700 minWeightIndex = j;
1701 }
1702 }
1703 if(minWeightIndex != i) {
1704 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1705 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1706 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1707 }
1708 }
1709#endif
1710
1711 /* For testing */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001712 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Sorted Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001713 pSpectCh = pSpectInfoParams->pSpectCh;
1714 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
1715 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001716 __func__, pSpectCh->chNum, pSpectCh->weight, pSpectCh->rssiAgr, pSpectCh->bssCount);
Jeff Johnson295189b2012-06-20 16:38:30 -07001717 pSpectCh++;
1718 }
1719
1720}
1721
1722/*==========================================================================
1723 FUNCTION sapSelectChannel
1724
1725 DESCRIPTION
1726 Runs a algorithm to select the best channel to operate in based on BSS
1727 rssi and bss count on each channel
1728
1729 DEPENDENCIES
1730 NA.
1731
1732 PARAMETERS
1733
1734 IN
1735 halHandle : Pointer to HAL handle
1736 pResult : Pointer to tScanResultHandle
1737
1738 RETURN VALUE
1739 v_U8_t : Success - channel number, Fail - zero
1740
1741 SIDE EFFECTS
1742============================================================================*/
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07001743v_U8_t sapSelectChannel(tHalHandle halHandle, ptSapContext pSapCtx, tScanResultHandle pScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001744{
1745 // DFS param object holding all the data req by the algo
1746 tSapChSelSpectInfo oSpectInfoParams = {NULL,0};
1747 tSapChSelSpectInfo *pSpectInfoParams = &oSpectInfoParams; // Memory? NB
Jeff Johnson295189b2012-06-20 16:38:30 -07001748 v_U8_t bestChNum = 0;
1749#ifdef SOFTAP_CHANNEL_RANGE
1750 v_U32_t startChannelNum;
1751 v_U32_t endChannelNum;
Gopichand Nakkala936715f2013-03-18 19:48:10 +05301752 v_U32_t operatingBand = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001753 v_U8_t count = 0;
1754#endif
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001755 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 -07001756
1757 // Set to zero tSapChSelParams
1758 //vos_mem_zero(&sapChSelParams, sizeof(sapChSelParams));
1759
1760 // Initialize the structure pointed by pSpectInfoParams
1761 if(sapChanSelInit( halHandle, pSpectInfoParams) != eSAP_TRUE ) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001762 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, Ch Select initialization failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001763 return SAP_CHANNEL_NOT_SELECTED;
1764 }
1765
1766 // Compute the weight of the entire spectrum in the operating band
1767 sapComputeSpectWeight( pSpectInfoParams, halHandle, pScanResult);
1768
1769 // Sort the 20M channel list as per the computed weights, lesser weight first.
1770 sapSortChlWeight(pSpectInfoParams);
1771
1772#ifdef SOFTAP_CHANNEL_RANGE
1773 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_START_CHANNEL, &startChannelNum);
1774 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_END_CHANNEL, &endChannelNum);
1775 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
1776
1777 /*Loop till get the best channel in the given range */
1778 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
1779 {
1780 if((startChannelNum <= pSpectInfoParams->pSpectCh[count].chNum)&&
1781 ( endChannelNum >= pSpectInfoParams->pSpectCh[count].chNum))
1782 {
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05301783 if(bestChNum == 0)
1784 {
1785 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
1786 }
1787 else
1788 {
1789 if(operatingBand == RF_SUBBAND_2_4_GHZ)
1790 {
1791 /* Give preference to Non-overlap channels */
1792 if(((pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_1) ||
1793 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_6) ||
1794 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_11))&&
1795 (pSpectInfoParams->pSpectCh[count].weight == 0))
1796 {
1797 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
1798 break;
1799 }
1800 }
1801 }
1802 }
1803 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001804#else
1805 // Get the first channel in sorted array as best 20M Channel
1806 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[0].chNum;
Jeff Johnson295189b2012-06-20 16:38:30 -07001807#endif
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001808
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07001809 //Select Best Channel from Channel List if Configured
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07001810 bestChNum = sapSelectPreferredChannelFromChannelList(bestChNum, pSapCtx, pSpectInfoParams);
Jeff Johnson295189b2012-06-20 16:38:30 -07001811
1812 // Free all the allocated memory
1813 sapChanSelExit(pSpectInfoParams);
1814
1815 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 -07001816 __func__, bestChNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07001817 if (bestChNum > 0 && bestChNum <= 252)
1818 return bestChNum;
1819 else
1820 return SAP_CHANNEL_NOT_SELECTED;
1821}
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001822