blob: dc363bc7c80f66b6433dccd2de676c9668db5c54 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Kiet Lam0fb93dd2014-02-19 00:32:59 -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.
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
Jeff Johnson295189b2012-06-20 16:38:30 -070069
70/*--------------------------------------------------------------------------
71 Function definitions
72--------------------------------------------------------------------------*/
73
74/*--------------------------------------------------------------------------
75 Defines
76--------------------------------------------------------------------------*/
77#define SAP_DEBUG
78
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -070079#define IS_RSSI_VALID( extRssi, rssi ) \
80( \
81 ((extRssi < rssi)?eANI_BOOLEAN_TRUE:eANI_BOOLEAN_FALSE) \
82)
83
Leo Chang0b0e45a2013-12-15 15:18:55 -080084#ifdef FEATURE_WLAN_CH_AVOID
85extern safeChannelType safeChannels[];
86#endif /* FEATURE_WLAN_CH_AVOID */
87
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070088/*==========================================================================
89 FUNCTION sapCleanupChannelList
90
91 DESCRIPTION
92 Function sapCleanupChannelList frees up the memory allocated to the channel list.
93
94 DEPENDENCIES
95 NA.
96
97 PARAMETERS
98
99 IN
100 NULL
101
102 RETURN VALUE
103 NULL
104============================================================================*/
105
106void sapCleanupChannelList(void)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700107{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700108 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530109 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700110
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700111 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
112 "Cleaning up the channel list structure");
113
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530114 if (NULL == pvosGCtx)
115 {
116 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
117 "SAP Global Context is NULL");
118 return ;
119 }
120
121 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
122 if (NULL == pSapCtx)
123 {
124 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
125 "SAP Context is NULL");
126 return ;
127 }
128
129 pSapCtx->SapChnlList.numChannel = 0;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700130 vos_mem_free(pSapCtx->SapChnlList.channelList);
131 pSapCtx->SapChnlList.channelList = NULL;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700132}
133
134/*==========================================================================
135 FUNCTION sapSetPreferredChannel
136
137 DESCRIPTION
138 Function sapSetPreferredChannel sets the channel list which has been configured
139 into sap context (pSapCtx) which will be used at the time of best channel selection.
140
141 DEPENDENCIES
142 NA.
143
144 PARAMETERS
145
146 IN
147 *ptr: pointer having the command followed by the arguments in string format
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700148
149 RETURN VALUE
150 int: return 0 when success else returns error code.
151============================================================================*/
152
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800153int sapSetPreferredChannel(tANI_U8* ptr)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700154{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700155
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700156 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530157 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700158 tANI_U8* param;
159 int tempInt;
160 int j;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700161
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700162 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700163 "Enter: %s", __func__);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700164
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530165 if (NULL == pvosGCtx)
166 {
167 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
168 "SAP Global Context is NULL");
169 return -EINVAL;
170 }
171
172 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
173 if (NULL == pSapCtx)
174 {
175 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
176 "SAP Context is NULL");
177 return -EINVAL;
178 }
179
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700180 if (NULL != pSapCtx->SapChnlList.channelList)
181 {
182 sapCleanupChannelList();
183 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700184
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800185 param = strchr(ptr, ' ');
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700186 /*no argument after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800187 if (NULL == param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700188 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800189 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700190 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700191
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700192 /*no space after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800193 else if (SPACE_ASCII_VALUE != *param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700194 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800195 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700196 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700197
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700198 param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700199
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700200 /*removing empty spaces*/
201 while((SPACE_ASCII_VALUE == *param)&& ('\0' != *param) ) param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700202
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700203 /*no argument followed by spaces*/
204 if('\0' == *param)
205 {
206 return -EINVAL;
207 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700208
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700209 /*getting the first argument ie the number of channels*/
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800210 if (sscanf(param, "%d ", &tempInt) != 1)
211 {
212 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800213 "%s: Cannot get number of channels from input", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800214 return -EINVAL;
215 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700216
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700217 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800218 "%s: Number of channel added are: %d", __func__, tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700219
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800220 if (tempInt <= 0 || tempInt > 255)
221 {
222 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800223 "%s: Invalid Number of channel received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800224 return -EINVAL;
225 }
226
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700227 /*allocating space for the desired number of channels*/
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530228 pSapCtx->SapChnlList.channelList = (v_U8_t *)vos_mem_malloc(tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700229
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530230 if (NULL == pSapCtx->SapChnlList.channelList)
231 {
232 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
233 "In %s, VOS_MALLOC_ERR", __func__);
234 return -EINVAL;
235 }
236
237 pSapCtx->SapChnlList.numChannel = tempInt;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700238 for(j=0;j<pSapCtx->SapChnlList.numChannel;j++)
239 {
240
241 /*param pointing to the beginning of first space after number of channels*/
242 param = strpbrk( param, " " );
243 /*no channel list after the number of channels argument*/
244 if (NULL == param)
245 {
246 sapCleanupChannelList();
247 return -EINVAL;
248 }
249
250 param++;
251
252 /*removing empty space*/
253 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
254
255 /*no channel list after the number of channels argument and spaces*/
256 if( '\0' == *param )
257 {
258 sapCleanupChannelList();
259 return -EINVAL;
260 }
261
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800262 if (sscanf(param, "%d ", &tempInt) != 1)
263 {
264 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800265 "%s: Cannot read channel number", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800266 sapCleanupChannelList();
267 return -EINVAL;
268 }
269 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 channel number received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800273 sapCleanupChannelList();
274 return -EINVAL;
275 }
276
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700277 pSapCtx->SapChnlList.channelList[j] = tempInt;
278
279 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800280 "%s: Channel %d added to preferred channel list",
281 __func__, pSapCtx->SapChnlList.channelList[j] );
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700282
283 }
284
285 /*extra arguments check*/
286 param = strpbrk( param, " " );
287 if (NULL != param)
288 {
289 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
290
291 if('\0' != *param)
292 {
293 sapCleanupChannelList();
294 return -EINVAL;
295 }
296 }
297
298 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700299 "Exit: %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700300
301 return 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700302}
303
304/*==========================================================================
305 FUNCTION sapSelectPreferredChannelFromChannelList
306
307 DESCRIPTION
308 Function sapSelectPreferredChannelFromChannelList calculates the best channel
309 among the configured channel list. If channel list not configured then returns
310 the best channel calculated among all the channel list.
311
312 DEPENDENCIES
313 NA.
314
315 PARAMETERS
316
317 IN
318 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
319 bestChNum: best channel already calculated among all the chanels
320 pSapCtx: having info of channel list from which best channel is selected
321
322 RETURN VALUE
323 v_U8_t: best channel
324============================================================================*/
325v_U8_t sapSelectPreferredChannelFromChannelList(v_U8_t bestChNum,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700326 ptSapContext pSapCtx,
327 tSapChSelSpectInfo *pSpectInfoParams)
328{
329 v_U8_t j = 0;
330 v_U8_t count = 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700331
332 //If Channel List is not Configured don't do anything
333 //Else return the Best Channel from the Channel List
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700334 if((NULL == pSapCtx->SapChnlList.channelList) ||
335 (NULL == pSpectInfoParams) ||
336 (0 == pSapCtx->SapChnlList.numChannel))
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700337 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700338 return bestChNum;
339 }
340
341 if (bestChNum > 0 && bestChNum <= 252)
342 {
343 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700344 {
345 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
346 // Select the best channel from allowed list
347 for(j=0;j< pSapCtx->SapChnlList.numChannel;j++)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700348 {
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700349 if( (pSapCtx->SapChnlList.channelList[j]) == bestChNum)
350 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700351 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
352 "Best channel computed from Channel List is: %d",
353 bestChNum);
354 return bestChNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700355 }
356 }
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700357 }
358
359 return SAP_CHANNEL_NOT_SELECTED;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700360 }
361 else
362 return SAP_CHANNEL_NOT_SELECTED;
363}
364
365
Jeff Johnson295189b2012-06-20 16:38:30 -0700366/*==========================================================================
367 FUNCTION sapChanSelInit
368
369 DESCRIPTION
370 Function sapChanSelInit allocates the memory, intializes the
371 structures used by the channel selection algorithm
372
373 DEPENDENCIES
374 NA.
375
376 PARAMETERS
377
378 IN
379 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
380
381 RETURN VALUE
382 v_BOOL_t: Success or FAIL
383
384 SIDE EFFECTS
385============================================================================*/
386v_BOOL_t sapChanSelInit(tHalHandle halHandle, tSapChSelSpectInfo *pSpectInfoParams)
387{
388 tSapSpectChInfo *pSpectCh = NULL;
389 v_U8_t *pChans = NULL;
390 v_U16_t channelnum = 0;
391 tpAniSirGlobal pMac = PMAC_STRUCT(halHandle);
Leo Chang0b0e45a2013-12-15 15:18:55 -0800392#ifdef FEATURE_WLAN_CH_AVOID
393 v_U16_t i;
394 v_BOOL_t chSafe = VOS_TRUE;
395#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700396
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700397 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700398
399 // Channels for that 2.4GHz band
400 //Considered only for 2.4GHz need to change in future to support 5GHz support
401 pSpectInfoParams->numSpectChans = pMac->scan.base20MHzChannels.numChannels;
402
403 // Allocate memory for weight computation of 2.4GHz
404 pSpectCh = (tSapSpectChInfo *)vos_mem_malloc((pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
405
406 if(pSpectCh == NULL) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700407 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, VOS_MALLOC_ERR", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700408 return eSAP_FALSE;
409 }
410
411 vos_mem_zero(pSpectCh, (pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
412
413 // Initialize the pointers in the DfsParams to the allocated memory
414 pSpectInfoParams->pSpectCh = pSpectCh;
415
416 pChans = pMac->scan.base20MHzChannels.channelList;
417
418 // Fill the channel number in the spectrum in the operating freq band
419 for (channelnum = 0; channelnum < pSpectInfoParams->numSpectChans; channelnum++) {
Leo Chang0b0e45a2013-12-15 15:18:55 -0800420#ifdef FEATURE_WLAN_CH_AVOID
421 chSafe = VOS_TRUE;
422 for(i = 0; i < NUM_20MHZ_RF_CHANNELS; i++)
423 {
424 if((safeChannels[i].channelNumber == *pChans) &&
425 (VOS_FALSE == safeChannels[i].isSafe))
426 {
427 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
428 "%s : CH %d is not safe", __func__, *pChans);
429 chSafe = VOS_FALSE;
430 break;
431 }
432 }
433#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700434
435 if(*pChans == 14 ) //OFDM rates are not supported on channel 14
Abhishek Singhb51853c2014-03-13 18:26:41 +0530436 {
437 pChans++;
Jeff Johnson295189b2012-06-20 16:38:30 -0700438 continue;
Abhishek Singhb51853c2014-03-13 18:26:41 +0530439 }
Leo Chang0b0e45a2013-12-15 15:18:55 -0800440#ifdef FEATURE_WLAN_CH_AVOID
441 if (VOS_TRUE == chSafe)
442 {
443#endif /* FEATURE_WLAN_CH_AVOID */
444 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_DEBUG,
445 "%s : Available Ch %d",
446 __func__, *pChans);
447 pSpectCh->chNum = *pChans;
448 pSpectCh->valid = eSAP_TRUE;
449 // Initialise for all channels
450 pSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
451 // Initialise 20MHz for all the Channels
452 pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH;
453 pSpectCh++;
454#ifdef FEATURE_WLAN_CH_AVOID
455 }
456#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700457 pChans++;
458 }
459 return eSAP_TRUE;
460}
461
462/*==========================================================================
463 FUNCTION sapweightRssiCount
464
465 DESCRIPTION
466 Function weightRssiCount calculates the channel weight due to rssi
467 and data count(here number of BSS observed)
468
469 DEPENDENCIES
470 NA.
471
472 PARAMETERS
473
474 IN
475 rssi : Max signal strength receieved from a BSS for the channel
476 count : Number of BSS observed in the channel
477
478 RETURN VALUE
479 v_U32_t : Calculated channel weight based on above two
480
481 SIDE EFFECTS
482============================================================================*/
483v_U32_t sapweightRssiCount(v_S7_t rssi, v_U16_t count)
484{
485 v_S31_t rssiWeight=0;
486 v_S31_t countWeight=0;
487 v_U32_t rssicountWeight=0;
488
489 // Weight from RSSI
490 rssiWeight = SOFTAP_RSSI_WEIGHT * (rssi - SOFTAP_MIN_RSSI)
491 /(SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530492
Jeff Johnson295189b2012-06-20 16:38:30 -0700493 if(rssiWeight > SOFTAP_RSSI_WEIGHT)
494 rssiWeight = SOFTAP_RSSI_WEIGHT;
495 else if (rssiWeight < 0)
496 rssiWeight = 0;
497
498 // Weight from data count
499 countWeight = SOFTAP_COUNT_WEIGHT * (count - SOFTAP_MIN_COUNT)
500 /(SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530501
Jeff Johnson295189b2012-06-20 16:38:30 -0700502 if(countWeight > SOFTAP_COUNT_WEIGHT)
503 countWeight = SOFTAP_COUNT_WEIGHT;
504 else if (countWeight < 0)
505 countWeight = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530506
Jeff Johnson295189b2012-06-20 16:38:30 -0700507 rssicountWeight = rssiWeight + countWeight;
508
509 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 -0700510 __func__, rssiWeight, countWeight, rssicountWeight);
Jeff Johnson295189b2012-06-20 16:38:30 -0700511
512 return(rssicountWeight);
513}
514
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800515
516/*==========================================================================
517 FUNCTION sapInterferenceRssiCount
518
519 DESCRIPTION
520 Function sapInterferenceRssiCount Considers the Adjacent channel rssi
521 and data count(here number of BSS observed)
522
523 DEPENDENCIES
524 NA.
525
526 PARAMETERS
527
528 pSpectCh : Channel Information
529
530 RETURN VALUE
531 NA.
532
533 SIDE EFFECTS
534============================================================================*/
535void sapInterferenceRssiCount(tSapSpectChInfo *pSpectCh)
536{
537 tSapSpectChInfo *pExtSpectCh = NULL;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700538 v_S31_t rssi;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530539
Abhishek Singh4eb79062014-04-10 14:48:14 +0530540 if (NULL == pSpectCh)
541 {
542 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
543 "%s: pSpectCh is NULL", __func__);
544 return;
545 }
546
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800547 switch(pSpectCh->chNum)
548 {
549 case CHANNEL_1:
550 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530551 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800552 {
553 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530554 rssi = pSpectCh->rssiAgr +
555 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700556 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
557 {
558 pExtSpectCh->rssiAgr = rssi;
559 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530560 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800561 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
562 }
563 pExtSpectCh = (pSpectCh + 2);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530564 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800565 {
566 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530567 rssi = pSpectCh->rssiAgr +
568 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700569 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
570 {
571 pExtSpectCh->rssiAgr = rssi;
572 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800573 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
574 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
575 }
576 pExtSpectCh = (pSpectCh + 3);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530577 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800578 {
579 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530580 rssi = pSpectCh->rssiAgr +
581 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700582 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
583 {
584 pExtSpectCh->rssiAgr = rssi;
585 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800586 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
587 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
588 }
589 pExtSpectCh = (pSpectCh + 4);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530590 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800591 {
592 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530593 rssi = pSpectCh->rssiAgr +
594 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700595 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
596 {
597 pExtSpectCh->rssiAgr = rssi;
598 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530599 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800600 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
601 }
602 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530603
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800604 case CHANNEL_2:
605 pExtSpectCh = (pSpectCh - 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530606 if (pExtSpectCh != NULL)
607 {
608 ++pExtSpectCh->bssCount;
609 rssi = pSpectCh->rssiAgr +
610 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
611 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
612 {
613 pExtSpectCh->rssiAgr = rssi;
614 }
615 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
616 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
617 }
618 pExtSpectCh = (pSpectCh + 1);
619 if (pExtSpectCh != NULL)
620 {
621 ++pExtSpectCh->bssCount;
622 rssi = pSpectCh->rssiAgr +
623 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
624 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
625 {
626 pExtSpectCh->rssiAgr = rssi;
627 }
628 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
629 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
630 }
631 pExtSpectCh = (pSpectCh + 2);
632 if (pExtSpectCh != NULL)
633 {
634 ++pExtSpectCh->bssCount;
635 rssi = pSpectCh->rssiAgr +
636 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
637 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
638 {
639 pExtSpectCh->rssiAgr = rssi;
640 }
641 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
642 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
643 }
644 pExtSpectCh = (pSpectCh + 3);
645 if (pExtSpectCh != NULL)
646 {
647 ++pExtSpectCh->bssCount;
648 rssi = pSpectCh->rssiAgr +
649 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
650 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
651 {
652 pExtSpectCh->rssiAgr = rssi;
653 }
654 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
655 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
656 }
657 pExtSpectCh = (pSpectCh + 4);
658 if (pExtSpectCh != NULL)
659 {
660 ++pExtSpectCh->bssCount;
661 rssi = pSpectCh->rssiAgr +
662 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
663 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
664 {
665 pExtSpectCh->rssiAgr = rssi;
666 }
667 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
668 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
669 }
670 break;
671 case CHANNEL_3:
672 pExtSpectCh = (pSpectCh - 2);
673 if (pExtSpectCh != NULL)
674 {
675 ++pExtSpectCh->bssCount;
676 rssi = pSpectCh->rssiAgr +
677 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
678 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
679 {
680 pExtSpectCh->rssiAgr = rssi;
681 }
682 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
683 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
684 }
685 pExtSpectCh = (pSpectCh - 1);
686 if (pExtSpectCh != NULL)
687 {
688 ++pExtSpectCh->bssCount;
689 rssi = pSpectCh->rssiAgr +
690 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
691 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
692 {
693 pExtSpectCh->rssiAgr = rssi;
694 }
695 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
696 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
697 }
698 pExtSpectCh = (pSpectCh + 1);
699 if (pExtSpectCh != NULL)
700 {
701 ++pExtSpectCh->bssCount;
702 rssi = pSpectCh->rssiAgr +
703 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
704 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
705 {
706 pExtSpectCh->rssiAgr = rssi;
707 }
708 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
709 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
710 }
711 pExtSpectCh = (pSpectCh + 2);
712 if (pExtSpectCh != NULL)
713 {
714 ++pExtSpectCh->bssCount;
715 rssi = pSpectCh->rssiAgr +
716 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
717 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
718 {
719 pExtSpectCh->rssiAgr = rssi;
720 }
721 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
722 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
723 }
724 pExtSpectCh = (pSpectCh + 3);
725 if (pExtSpectCh != NULL)
726 {
727 ++pExtSpectCh->bssCount;
728 rssi = pSpectCh->rssiAgr +
729 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
730 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
731 {
732 pExtSpectCh->rssiAgr = rssi;
733 }
734 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
735 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
736 }
737 pExtSpectCh = (pSpectCh + 4);
738 if (pExtSpectCh != NULL)
739 {
740 ++pExtSpectCh->bssCount;
741 rssi = pSpectCh->rssiAgr +
742 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
743 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
744 {
745 pExtSpectCh->rssiAgr = rssi;
746 }
747 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
748 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
749 }
750 break;
751 case CHANNEL_4:
752 pExtSpectCh = (pSpectCh - 3);
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800753 if(pExtSpectCh != NULL)
754 {
755 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530756 rssi = pSpectCh->rssiAgr +
757 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
758 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
759 {
760 pExtSpectCh->rssiAgr = rssi;
761 }
762 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
763 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
764 }
765 pExtSpectCh = (pSpectCh - 2);
766 if (pExtSpectCh != NULL)
767 {
768 ++pExtSpectCh->bssCount;
769 rssi = pSpectCh->rssiAgr +
770 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
771 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
772 {
773 pExtSpectCh->rssiAgr = rssi;
774 }
775 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
776 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
777 }
778 pExtSpectCh = (pSpectCh - 1);
779 if (pExtSpectCh != NULL)
780 {
781 ++pExtSpectCh->bssCount;
782 rssi = pSpectCh->rssiAgr +
783 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700784 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
785 {
786 pExtSpectCh->rssiAgr = rssi;
787 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800788 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
789 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
790 }
791 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530792 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800793 {
794 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530795 rssi = pSpectCh->rssiAgr +
796 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
797 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
798 {
799 pExtSpectCh->rssiAgr = rssi;
800 }
801 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
802 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
803 }
804 pExtSpectCh = (pSpectCh + 2);
805 if (pExtSpectCh != NULL)
806 {
807 ++pExtSpectCh->bssCount;
808 rssi = pSpectCh->rssiAgr +
809 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
810 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
811 {
812 pExtSpectCh->rssiAgr = rssi;
813 }
814 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
815 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
816 }
817 pExtSpectCh = (pSpectCh + 3);
818 if (pExtSpectCh != NULL)
819 {
820 ++pExtSpectCh->bssCount;
821 rssi = pSpectCh->rssiAgr +
822 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
823 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
824 {
825 pExtSpectCh->rssiAgr = rssi;
826 }
827 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
828 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
829 }
830 pExtSpectCh = (pSpectCh + 4);
831 if (pExtSpectCh != NULL)
832 {
833 ++pExtSpectCh->bssCount;
834 rssi = pSpectCh->rssiAgr +
835 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
836 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
837 {
838 pExtSpectCh->rssiAgr = rssi;
839 }
840 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
841 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
842 }
843 break;
844
845 case CHANNEL_5:
846 case CHANNEL_6:
847 case CHANNEL_7:
848 pExtSpectCh = (pSpectCh - 4);
849 if (pExtSpectCh != NULL)
850 {
851 ++pExtSpectCh->bssCount;
852 rssi = pSpectCh->rssiAgr +
853 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700854 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
855 {
856 pExtSpectCh->rssiAgr = rssi;
857 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800858 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
859 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
860 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530861 pExtSpectCh = (pSpectCh - 3);
862 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800863 {
864 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530865 rssi = pSpectCh->rssiAgr +
866 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700867 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
868 {
869 pExtSpectCh->rssiAgr = rssi;
870 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800871 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
872 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
873 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530874 pExtSpectCh = (pSpectCh - 2);
875 if (pExtSpectCh != NULL)
876 {
877 ++pExtSpectCh->bssCount;
878 rssi = pSpectCh->rssiAgr +
879 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
880 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
881 {
882 pExtSpectCh->rssiAgr = rssi;
883 }
884 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
885 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
886 }
887 pExtSpectCh = (pSpectCh - 1);
888 if(pExtSpectCh != NULL)
889 {
890 ++pExtSpectCh->bssCount;
891 rssi = pSpectCh->rssiAgr +
892 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
893 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
894 {
895 pExtSpectCh->rssiAgr = rssi;
896 }
897 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
898 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
899 }
900 pExtSpectCh = (pSpectCh + 1);
901 if (pExtSpectCh != NULL)
902 {
903 ++pExtSpectCh->bssCount;
904 rssi = pSpectCh->rssiAgr +
905 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
906 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
907 {
908 pExtSpectCh->rssiAgr = rssi;
909 }
910 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
911 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
912 }
913 pExtSpectCh = (pSpectCh + 2);
914 if(pExtSpectCh != NULL)
915 {
916 ++pExtSpectCh->bssCount;
917 rssi = pSpectCh->rssiAgr +
918 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
919 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
920 {
921 pExtSpectCh->rssiAgr = rssi;
922 }
923 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
924 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
925 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800926 pExtSpectCh = (pSpectCh + 3);
927 if(pExtSpectCh != NULL)
928 {
929 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530930 rssi = pSpectCh->rssiAgr +
931 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
932 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
933 {
934 pExtSpectCh->rssiAgr = rssi;
935 }
936 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
937 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
938 }
939 pExtSpectCh = (pSpectCh + 4);
940 if (pExtSpectCh != NULL)
941 {
942 ++pExtSpectCh->bssCount;
943 rssi = pSpectCh->rssiAgr +
944 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700945 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
946 {
947 pExtSpectCh->rssiAgr = rssi;
948 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800949 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
950 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
951 }
952 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530953
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800954 case CHANNEL_8:
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800955 pExtSpectCh = (pSpectCh - 4);
956 if(pExtSpectCh != NULL)
957 {
958 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530959 rssi = pSpectCh->rssiAgr +
960 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
961 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
962 {
963 pExtSpectCh->rssiAgr = rssi;
964 }
965 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
966 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
967 }
968
969 pExtSpectCh = (pSpectCh - 3);
970 if (pExtSpectCh != NULL)
971 {
972 ++pExtSpectCh->bssCount;
973 rssi = pSpectCh->rssiAgr +
974 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
975 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
976 {
977 pExtSpectCh->rssiAgr = rssi;
978 }
979 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
980 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
981 }
982 pExtSpectCh = (pSpectCh - 2);
983 if (pExtSpectCh != NULL)
984 {
985 ++pExtSpectCh->bssCount;
986 rssi = pSpectCh->rssiAgr +
987 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
988 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
989 {
990 pExtSpectCh->rssiAgr = rssi;
991 }
992 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
993 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
994 }
995 pExtSpectCh = (pSpectCh - 1);
996 if (pExtSpectCh != NULL)
997 {
998 ++pExtSpectCh->bssCount;
999 rssi = pSpectCh->rssiAgr +
1000 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1001 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1002 {
1003 pExtSpectCh->rssiAgr = rssi;
1004 }
1005 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1006 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1007 }
1008 pExtSpectCh = (pSpectCh + 1);
1009 if (pExtSpectCh != NULL)
1010 {
1011 ++pExtSpectCh->bssCount;
1012 rssi = pSpectCh->rssiAgr +
1013 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1014 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1015 {
1016 pExtSpectCh->rssiAgr = rssi;
1017 }
1018 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1019 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1020 }
1021 pExtSpectCh = (pSpectCh + 2);
1022 if (pExtSpectCh != NULL)
1023 {
1024 ++pExtSpectCh->bssCount;
1025 rssi = pSpectCh->rssiAgr +
1026 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1027 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1028 {
1029 pExtSpectCh->rssiAgr = rssi;
1030 }
1031 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1032 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1033 }
1034 pExtSpectCh = (pSpectCh + 3);
1035 if (pExtSpectCh != NULL)
1036 {
1037 ++pExtSpectCh->bssCount;
1038 rssi = pSpectCh->rssiAgr +
1039 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1040 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1041 {
1042 pExtSpectCh->rssiAgr = rssi;
1043 }
1044 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1045 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1046 }
1047 break;
1048
1049 case CHANNEL_9:
1050 pExtSpectCh = (pSpectCh - 4);
1051 if (pExtSpectCh != NULL)
1052 {
1053 ++pExtSpectCh->bssCount;
1054 rssi = pSpectCh->rssiAgr +
1055 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001056 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1057 {
1058 pExtSpectCh->rssiAgr = rssi;
1059 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001060 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1061 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1062 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301063
1064 pExtSpectCh = (pSpectCh - 3);
1065 if (pExtSpectCh != NULL)
1066 {
1067 ++pExtSpectCh->bssCount;
1068 rssi = pSpectCh->rssiAgr +
1069 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1070 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1071 {
1072 pExtSpectCh->rssiAgr = rssi;
1073 }
1074 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1075 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1076 }
1077 pExtSpectCh = (pSpectCh - 2);
1078 if (pExtSpectCh != NULL)
1079 {
1080 ++pExtSpectCh->bssCount;
1081 rssi = pSpectCh->rssiAgr +
1082 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1083 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1084 {
1085 pExtSpectCh->rssiAgr = rssi;
1086 }
1087 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1088 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1089 }
1090 pExtSpectCh = (pSpectCh - 1);
1091 if (pExtSpectCh != NULL)
1092 {
1093 ++pExtSpectCh->bssCount;
1094 rssi = pSpectCh->rssiAgr +
1095 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1096 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1097 {
1098 pExtSpectCh->rssiAgr = rssi;
1099 }
1100 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1101 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1102 }
1103 pExtSpectCh = (pSpectCh + 1);
1104 if (pExtSpectCh != NULL)
1105 {
1106 ++pExtSpectCh->bssCount;
1107 rssi = pSpectCh->rssiAgr +
1108 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1109 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1110 {
1111 pExtSpectCh->rssiAgr = rssi;
1112 }
1113 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1114 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1115 }
1116 pExtSpectCh = (pSpectCh + 2);
1117 if (pExtSpectCh != NULL)
1118 {
1119 ++pExtSpectCh->bssCount;
1120 rssi = pSpectCh->rssiAgr +
1121 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1122 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1123 {
1124 pExtSpectCh->rssiAgr = rssi;
1125 }
1126 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1127 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1128 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001129 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301130
1131 case CHANNEL_10:
1132 pExtSpectCh = (pSpectCh - 4);
1133 if (pExtSpectCh != NULL)
1134 {
1135 ++pExtSpectCh->bssCount;
1136 rssi = pSpectCh->rssiAgr +
1137 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1138 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1139 {
1140 pExtSpectCh->rssiAgr = rssi;
1141 }
1142 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1143 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1144 }
1145
1146 pExtSpectCh = (pSpectCh - 3);
1147 if (pExtSpectCh != NULL)
1148 {
1149 ++pExtSpectCh->bssCount;
1150 rssi = pSpectCh->rssiAgr +
1151 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1152 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1153 {
1154 pExtSpectCh->rssiAgr = rssi;
1155 }
1156 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1157 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1158 }
1159 pExtSpectCh = (pSpectCh - 2);
1160 if(pExtSpectCh != NULL)
1161 {
1162 ++pExtSpectCh->bssCount;
1163 rssi = pSpectCh->rssiAgr +
1164 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1165 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1166 {
1167 pExtSpectCh->rssiAgr = rssi;
1168 }
1169 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1170 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1171 }
1172 pExtSpectCh = (pSpectCh - 1);
1173 if (pExtSpectCh != NULL)
1174 {
1175 ++pExtSpectCh->bssCount;
1176 rssi = pSpectCh->rssiAgr +
1177 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1178 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1179 {
1180 pExtSpectCh->rssiAgr = rssi;
1181 }
1182 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1183 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1184 }
1185 pExtSpectCh = (pSpectCh + 1);
1186 if (pExtSpectCh != NULL)
1187 {
1188 ++pExtSpectCh->bssCount;
1189 rssi = pSpectCh->rssiAgr +
1190 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1191 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1192 {
1193 pExtSpectCh->rssiAgr = rssi;
1194 }
1195 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1196 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1197 }
1198 break;
1199
1200 case CHANNEL_11:
1201 pExtSpectCh = (pSpectCh - 1);
1202 if (pExtSpectCh != NULL)
1203 {
1204 ++pExtSpectCh->bssCount;
1205 rssi = pSpectCh->rssiAgr +
1206 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1207 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1208 {
1209 pExtSpectCh->rssiAgr = rssi;
1210 }
1211 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1212 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1213 }
1214 pExtSpectCh = (pSpectCh - 2);
1215 if (pExtSpectCh != NULL)
1216 {
1217 ++pExtSpectCh->bssCount;
1218 rssi = pSpectCh->rssiAgr +
1219 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1220 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1221 {
1222 pExtSpectCh->rssiAgr = rssi;
1223 }
1224 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1225 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1226 }
1227 pExtSpectCh = (pSpectCh - 3);
1228 if (pExtSpectCh != NULL)
1229 {
1230 ++pExtSpectCh->bssCount;
1231 rssi = pSpectCh->rssiAgr +
1232 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1233 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1234 {
1235 pExtSpectCh->rssiAgr = rssi;
1236 }
1237 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1238 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1239 }
1240 pExtSpectCh = (pSpectCh - 4);
1241 if (pExtSpectCh != NULL)
1242 {
1243 ++pExtSpectCh->bssCount;
1244 rssi = pSpectCh->rssiAgr +
1245 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1246 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1247 {
1248 pExtSpectCh->rssiAgr = rssi;
1249 }
1250 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1251 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1252 }
1253 break;
1254
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001255 default:
1256 break;
1257 }
1258}
1259
Jeff Johnson295189b2012-06-20 16:38:30 -07001260/*==========================================================================
1261 FUNCTION sapComputeSpectWeight
1262
1263 DESCRIPTION
1264 Main function for computing the weight of each channel in the
1265 spectrum based on the RSSI value of the BSSes on the channel
1266 and number of BSS
1267
1268 DEPENDENCIES
1269 NA.
1270
1271 PARAMETERS
1272
1273 IN
1274 pSpectInfoParams : Pointer to the tSpectInfoParams structure
1275 halHandle : Pointer to HAL handle
1276 pResult : Pointer to tScanResultHandle
1277
1278 RETURN VALUE
1279 void : NULL
1280
1281 SIDE EFFECTS
1282============================================================================*/
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301283void sapComputeSpectWeight( tSapChSelSpectInfo* pSpectInfoParams,
1284 tHalHandle halHandle, tScanResultHandle pResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001285{
1286 v_S7_t rssi = 0;
1287 v_U8_t chn_num = 0;
1288 v_U8_t channel_id = 0;
1289
1290 tCsrScanResultInfo *pScanResult;
1291 tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001292 v_U32_t operatingBand;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001293 v_U16_t channelWidth;
1294 v_U16_t secondaryChannelOffset;
1295 v_U16_t centerFreq;
1296 v_U16_t vhtSupport;
1297 v_U32_t ieLen = 0;
1298 tSirProbeRespBeacon *pBeaconStruct;
1299 tpAniSirGlobal pMac = (tpAniSirGlobal) halHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -07001300
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301301 pBeaconStruct = vos_mem_malloc(sizeof(tSirProbeRespBeacon));
1302 if ( NULL == pBeaconStruct )
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001303 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301304 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1305 "Unable to allocate memory in sapComputeSpectWeight\n");
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001306 return;
1307 }
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001308 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Computing spectral weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001309
1310 /**
1311 * Soft AP specific channel weight calculation using DFS formula
1312 */
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001313 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
Jeff Johnson295189b2012-06-20 16:38:30 -07001314
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301315 pScanResult = sme_ScanResultGetFirst(halHandle, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07001316
1317 while (pScanResult) {
1318 pSpectCh = pSpectInfoParams->pSpectCh;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001319 // Defining the default values, so that any value will hold the default values
1320 channelWidth = eHT_CHANNEL_WIDTH_20MHZ;
1321 secondaryChannelOffset = PHY_SINGLE_CHANNEL_CENTERED;
1322 vhtSupport = 0;
1323 centerFreq = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301324
1325 if (pScanResult->BssDescriptor.ieFields != NULL)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001326 {
1327 ieLen = (pScanResult->BssDescriptor.length + sizeof(tANI_U16) + sizeof(tANI_U32) - sizeof(tSirBssDescription));
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301328 vos_mem_set((tANI_U8 *) pBeaconStruct, sizeof(tSirProbeRespBeacon), 0);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301329
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001330 if ((sirParseBeaconIE(pMac, pBeaconStruct,(tANI_U8 *)( pScanResult->BssDescriptor.ieFields), ieLen)) == eSIR_SUCCESS)
1331 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301332 if (pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001333 {
1334 channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet;
1335 secondaryChannelOffset = pBeaconStruct->HTInfo.secondaryChannelOffset;
1336 if(pBeaconStruct->VHTOperation.present)
1337 {
1338 vhtSupport = pBeaconStruct->VHTOperation.present;
1339 if(pBeaconStruct->VHTOperation.chanWidth > WNI_CFG_VHT_CHANNEL_WIDTH_20_40MHZ)
1340 {
1341 channelWidth = eHT_CHANNEL_WIDTH_80MHZ;
1342 centerFreq = pBeaconStruct->VHTOperation.chanCenterFreqSeg1;
1343 }
1344 }
1345 }
1346 }
1347 }
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001348 // Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list
Jeff Johnson295189b2012-06-20 16:38:30 -07001349 for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; chn_num++) {
1350
1351 /*
1352 * if the Beacon has channel ID, use it other wise we will
1353 * rely on the channelIdSelf
1354 */
1355 if(pScanResult->BssDescriptor.channelId == 0)
1356 channel_id = pScanResult->BssDescriptor.channelIdSelf;
1357 else
1358 channel_id = pScanResult->BssDescriptor.channelId;
1359
krunal sonic39d9592014-02-04 11:54:24 -08001360 if (pSpectCh && (channel_id == pSpectCh->chNum)) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001361 if (pSpectCh->rssiAgr < pScanResult->BssDescriptor.rssi)
1362 pSpectCh->rssiAgr = pScanResult->BssDescriptor.rssi;
1363
1364 ++pSpectCh->bssCount; // Increment the count of BSS
1365
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001366 if(operatingBand) // Connsidering the Extension Channel only in a channels
1367 {
1368 /* Updating the received ChannelWidth */
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301369 if (pSpectCh->channelWidth != channelWidth)
1370 pSpectCh->channelWidth = channelWidth;
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001371 /* If received ChannelWidth is other than HT20, we need to update the extension channel Params as well */
1372 /* channelWidth == 0, HT20 */
1373 /* channelWidth == 1, HT40 */
1374 /* channelWidth == 2, VHT80*/
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001375 switch(pSpectCh->channelWidth)
1376 {
1377 case eHT_CHANNEL_WIDTH_40MHZ: //HT40
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001378 switch( secondaryChannelOffset)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001379 {
1380 tSapSpectChInfo *pExtSpectCh = NULL;
1381 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY: // Above the Primary Channel
1382 pExtSpectCh = (pSpectCh + 1);
1383 if(pExtSpectCh != NULL)
1384 {
1385 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001386 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001387 // REducing the rssi by -20 and assigning it to Extension channel
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001388 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1389 {
1390 pExtSpectCh->rssiAgr = rssi;
1391 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001392 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1393 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1394 }
1395 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301396
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001397 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY: // Below the Primary channel
1398 pExtSpectCh = (pSpectCh - 1);
1399 if(pExtSpectCh != NULL)
1400 {
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001401 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1402 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1403 {
1404 pExtSpectCh->rssiAgr = rssi;
1405 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001406 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1407 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1408 ++pExtSpectCh->bssCount;
1409 }
1410 break;
1411 }
1412 break;
1413 case eHT_CHANNEL_WIDTH_80MHZ: // VHT80
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001414 if((centerFreq - channel_id) == 6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001415 {
1416 tSapSpectChInfo *pExtSpectCh = NULL;
1417 pExtSpectCh = (pSpectCh + 1);
1418 if(pExtSpectCh != NULL)
1419 {
1420 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001421 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1422 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1423 {
1424 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -20 and assigning it to Subband 1
1425 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001426 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1427 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1428 }
1429 pExtSpectCh = (pSpectCh + 2);
1430 if(pExtSpectCh != NULL)
1431 {
1432 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001433 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1434 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1435 {
1436 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -30 and assigning it to Subband 2
1437 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001438 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1439 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1440 }
1441 pExtSpectCh = (pSpectCh + 3);
1442 if(pExtSpectCh != NULL)
1443 {
1444 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001445 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1446 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1447 {
1448 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -40 and assigning it to Subband 3
1449 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001450 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1451 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301452 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001453 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001454 else if((centerFreq - channel_id) == 2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001455 {
1456 tSapSpectChInfo *pExtSpectCh = NULL;
1457 pExtSpectCh = (pSpectCh - 1 );
1458 if(pExtSpectCh != NULL)
1459 {
1460 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001461 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1462 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1463 {
1464 pExtSpectCh->rssiAgr = rssi;
1465 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001466 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1467 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1468 }
1469 pExtSpectCh = (pSpectCh + 1);
1470 if(pExtSpectCh != NULL)
1471 {
1472 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001473 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1474 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1475 {
1476 pExtSpectCh->rssiAgr = rssi;
1477 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001478 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1479 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1480 }
1481 pExtSpectCh = (pSpectCh + 2);
1482 if(pExtSpectCh != NULL)
1483 {
1484 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001485 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1486 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1487 {
1488 pExtSpectCh->rssiAgr = rssi;
1489 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001490 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1491 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1492 }
1493 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001494 else if((centerFreq - channel_id) == -2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001495 {
1496 tSapSpectChInfo *pExtSpectCh = NULL;
1497 pExtSpectCh = (pSpectCh - 1 );
1498 if(pExtSpectCh != NULL)
1499 {
1500 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001501 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1502 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1503 {
1504 pExtSpectCh->rssiAgr = rssi;
1505 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001506 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1507 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1508 }
1509 pExtSpectCh = (pSpectCh - 2);
1510 if(pExtSpectCh != NULL)
1511 {
1512 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001513 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1514 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1515 {
1516 pExtSpectCh->rssiAgr = rssi;
1517 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001518 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1519 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1520 }
1521 pExtSpectCh = (pSpectCh + 1);
1522 if(pExtSpectCh != NULL)
1523 {
1524 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001525 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1526 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1527 {
1528 pExtSpectCh->rssiAgr = rssi;
1529 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001530 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1531 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1532 }
1533 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001534 else if((centerFreq - channel_id) == -6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001535 {
1536 tSapSpectChInfo *pExtSpectCh = NULL;
1537 pExtSpectCh = (pSpectCh - 1 );
1538 if(pExtSpectCh != NULL)
1539 {
1540 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001541 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1542 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1543 {
1544 pExtSpectCh->rssiAgr = rssi;
1545 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001546 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1547 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1548 }
1549 pExtSpectCh = (pSpectCh - 2);
1550 if(pExtSpectCh != NULL)
1551 {
1552 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001553 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1554 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1555 {
1556 pExtSpectCh->rssiAgr = rssi;
1557 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001558 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1559 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1560 }
1561 pExtSpectCh = (pSpectCh - 3);
1562 if(pExtSpectCh != NULL)
1563 {
1564 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001565 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1566 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1567 {
1568 pExtSpectCh->rssiAgr = rssi;
1569 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001570 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1571 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1572 }
1573 }
1574 break;
1575 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301576 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001577 else if(operatingBand == RF_SUBBAND_2_4_GHZ)
1578 {
1579 sapInterferenceRssiCount(pSpectCh);
1580 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001581
Jeff Johnson295189b2012-06-20 16:38:30 -07001582 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301583 "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 -08001584 __func__, pScanResult->BssDescriptor.channelIdSelf, pScanResult->BssDescriptor.channelId, pScanResult->BssDescriptor.rssi, pSpectCh->bssCount, pScanResult,pSpectCh->channelWidth,secondaryChannelOffset,centerFreq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001585 pSpectCh++;
1586 break;
1587 } else {
1588 pSpectCh++;
1589 }
1590 }
1591
1592 pScanResult = sme_ScanResultGetNext(halHandle, pResult);
1593 }
1594
1595 // Calculate the weights for all channels in the spectrum pSpectCh
1596 pSpectCh = pSpectInfoParams->pSpectCh;
1597
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001598 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001599
1600 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); chn_num++) {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301601
Jeff Johnson295189b2012-06-20 16:38:30 -07001602 /*
1603 rssi : Maximum received signal strength among all BSS on that channel
1604 bssCount : Number of BSS on that channel
1605 */
1606
1607 rssi = (v_S7_t)pSpectCh->rssiAgr;
1608
1609 pSpectCh->weight = SAPDFS_NORMALISE_1000 * sapweightRssiCount(rssi, pSpectCh->bssCount);
1610
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301611 //------ Debug Info ------
1612 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1613 "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d", __func__,
1614 pSpectCh->chNum, pSpectCh->weight,
1615 pSpectCh->rssiAgr, pSpectCh->bssCount);
1616 //------ Debug Info ------
Jeff Johnson295189b2012-06-20 16:38:30 -07001617 pSpectCh++;
1618 }
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301619 vos_mem_free(pBeaconStruct);
Jeff Johnson295189b2012-06-20 16:38:30 -07001620}
1621
1622/*==========================================================================
1623 FUNCTION sapChanSelExit
1624
1625 DESCRIPTION
1626 Exit function for free out the allocated memory, to be called
1627 at the end of the dfsSelectChannel function
1628
1629 DEPENDENCIES
1630 NA.
1631
1632 PARAMETERS
1633
1634 IN
1635 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1636
1637 RETURN VALUE
1638 void : NULL
1639
1640 SIDE EFFECTS
1641============================================================================*/
1642void sapChanSelExit( tSapChSelSpectInfo *pSpectInfoParams )
1643{
1644 // Free all the allocated memory
1645 vos_mem_free(pSpectInfoParams->pSpectCh);
1646}
1647
1648/*==========================================================================
1649 FUNCTION sapSortChlWeight
1650
1651 DESCRIPTION
1652 Funtion to sort the channels with the least weight first
1653
1654 DEPENDENCIES
1655 NA.
1656
1657 PARAMETERS
1658
1659 IN
1660 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1661
1662 RETURN VALUE
1663 void : NULL
1664
1665 SIDE EFFECTS
1666============================================================================*/
1667void sapSortChlWeight(tSapChSelSpectInfo *pSpectInfoParams)
1668{
1669 tSapSpectChInfo temp;
1670
1671 tSapSpectChInfo *pSpectCh = NULL;
1672 v_U32_t i = 0, j = 0, minWeightIndex = 0;
1673
1674 pSpectCh = pSpectInfoParams->pSpectCh;
1675#ifdef SOFTAP_CHANNEL_RANGE
1676 // Sorting the channels as per weights
1677 for (i = 0; i < pSpectInfoParams->numSpectChans; i++) {
1678 minWeightIndex = i;
1679 for( j = i + 1; j < pSpectInfoParams->numSpectChans; j++) {
1680 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1681 minWeightIndex = j;
1682 }
1683 }
1684 if(minWeightIndex != i) {
1685 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1686 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1687 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1688 }
1689 }
1690#else
1691 // Sorting the channels as per weights
1692 for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) {
1693 minWeightIndex = i;
1694 for( j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) {
1695 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1696 minWeightIndex = j;
1697 }
1698 }
1699 if(minWeightIndex != i) {
1700 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1701 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1702 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1703 }
1704 }
1705#endif
1706
1707 /* For testing */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001708 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 -07001709 pSpectCh = pSpectInfoParams->pSpectCh;
1710 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
1711 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 -07001712 __func__, pSpectCh->chNum, pSpectCh->weight, pSpectCh->rssiAgr, pSpectCh->bssCount);
Jeff Johnson295189b2012-06-20 16:38:30 -07001713 pSpectCh++;
1714 }
1715
1716}
1717
1718/*==========================================================================
1719 FUNCTION sapSelectChannel
1720
1721 DESCRIPTION
1722 Runs a algorithm to select the best channel to operate in based on BSS
1723 rssi and bss count on each channel
1724
1725 DEPENDENCIES
1726 NA.
1727
1728 PARAMETERS
1729
1730 IN
1731 halHandle : Pointer to HAL handle
1732 pResult : Pointer to tScanResultHandle
1733
1734 RETURN VALUE
1735 v_U8_t : Success - channel number, Fail - zero
1736
1737 SIDE EFFECTS
1738============================================================================*/
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07001739v_U8_t sapSelectChannel(tHalHandle halHandle, ptSapContext pSapCtx, tScanResultHandle pScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001740{
1741 // DFS param object holding all the data req by the algo
1742 tSapChSelSpectInfo oSpectInfoParams = {NULL,0};
1743 tSapChSelSpectInfo *pSpectInfoParams = &oSpectInfoParams; // Memory? NB
Jeff Johnson295189b2012-06-20 16:38:30 -07001744 v_U8_t bestChNum = 0;
1745#ifdef SOFTAP_CHANNEL_RANGE
1746 v_U32_t startChannelNum;
1747 v_U32_t endChannelNum;
Gopichand Nakkala936715f2013-03-18 19:48:10 +05301748 v_U32_t operatingBand = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001749 v_U8_t count = 0;
1750#endif
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001751 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 -07001752
1753 // Set to zero tSapChSelParams
1754 //vos_mem_zero(&sapChSelParams, sizeof(sapChSelParams));
1755
1756 // Initialize the structure pointed by pSpectInfoParams
1757 if(sapChanSelInit( halHandle, pSpectInfoParams) != eSAP_TRUE ) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001758 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, Ch Select initialization failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001759 return SAP_CHANNEL_NOT_SELECTED;
1760 }
1761
1762 // Compute the weight of the entire spectrum in the operating band
1763 sapComputeSpectWeight( pSpectInfoParams, halHandle, pScanResult);
1764
1765 // Sort the 20M channel list as per the computed weights, lesser weight first.
1766 sapSortChlWeight(pSpectInfoParams);
1767
1768#ifdef SOFTAP_CHANNEL_RANGE
1769 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_START_CHANNEL, &startChannelNum);
1770 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_END_CHANNEL, &endChannelNum);
1771 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
1772
1773 /*Loop till get the best channel in the given range */
1774 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
1775 {
1776 if((startChannelNum <= pSpectInfoParams->pSpectCh[count].chNum)&&
1777 ( endChannelNum >= pSpectInfoParams->pSpectCh[count].chNum))
1778 {
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05301779 if(bestChNum == 0)
1780 {
1781 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
1782 }
1783 else
1784 {
1785 if(operatingBand == RF_SUBBAND_2_4_GHZ)
1786 {
1787 /* Give preference to Non-overlap channels */
1788 if(((pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_1) ||
1789 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_6) ||
1790 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_11))&&
1791 (pSpectInfoParams->pSpectCh[count].weight == 0))
1792 {
1793 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
1794 break;
1795 }
1796 }
1797 }
1798 }
1799 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001800#else
1801 // Get the first channel in sorted array as best 20M Channel
1802 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[0].chNum;
Jeff Johnson295189b2012-06-20 16:38:30 -07001803#endif
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001804
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07001805 //Select Best Channel from Channel List if Configured
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07001806 bestChNum = sapSelectPreferredChannelFromChannelList(bestChNum, pSapCtx, pSpectInfoParams);
Jeff Johnson295189b2012-06-20 16:38:30 -07001807
1808 // Free all the allocated memory
1809 sapChanSelExit(pSpectInfoParams);
1810
1811 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 -07001812 __func__, bestChNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07001813 if (bestChNum > 0 && bestChNum <= 252)
1814 return bestChNum;
1815 else
1816 return SAP_CHANNEL_NOT_SELECTED;
1817}
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001818