blob: 46d2766bf996b4b75464e2618d0d18cbdbf6c7c7 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Peng Xu2446a892014-09-05 17:21:18 +05302 * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
Kiet Lam0fb93dd2014-02-19 00:32:59 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam0fb93dd2014-02-19 00:32:59 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Jeff Johnson295189b2012-06-20 16:38:30 -070028/*===========================================================================
29
30 s a p C h S e l e c t . C
Jeff Johnson295189b2012-06-20 16:38:30 -070031 OVERVIEW:
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053032
Jeff Johnson295189b2012-06-20 16:38:30 -070033 This software unit holds the implementation of the WLAN SAP modules
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053034 functions for channel selection.
Jeff Johnson295189b2012-06-20 16:38:30 -070035
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053036 DEPENDENCIES:
Jeff Johnson295189b2012-06-20 16:38:30 -070037
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +053038 Are listed for each API below.
Jeff Johnson295189b2012-06-20 16:38:30 -070039===========================================================================*/
40
41/*===========================================================================
42
43 EDIT HISTORY FOR FILE
44
45
46 This section contains comments describing changes made to the module.
47 Notice that changes are listed in reverse chronological order.
48
49
50
51 when who what, where, why
52---------- --- --------------------------------------------------------
532010-03-15 SOFTAP Created module
54
55===========================================================================*/
56
57
58/*--------------------------------------------------------------------------
59 Include Files
60------------------------------------------------------------------------*/
61#include "vos_trace.h"
62#include "csrApi.h"
63#include "sme_Api.h"
64#include "sapChSelect.h"
65#include "sapInternal.h"
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -080066#ifdef ANI_OS_TYPE_QNX
67#include "stdio.h"
68#endif
Peng Xuafc34e32014-09-25 13:23:55 +053069#include "wlan_hdd_main.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070070
71/*--------------------------------------------------------------------------
72 Function definitions
73--------------------------------------------------------------------------*/
74
75/*--------------------------------------------------------------------------
76 Defines
77--------------------------------------------------------------------------*/
78#define SAP_DEBUG
79
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -070080#define IS_RSSI_VALID( extRssi, rssi ) \
81( \
82 ((extRssi < rssi)?eANI_BOOLEAN_TRUE:eANI_BOOLEAN_FALSE) \
83)
84
Leo Chang0b0e45a2013-12-15 15:18:55 -080085#ifdef FEATURE_WLAN_CH_AVOID
86extern safeChannelType safeChannels[];
87#endif /* FEATURE_WLAN_CH_AVOID */
88
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -070089/*==========================================================================
90 FUNCTION sapCleanupChannelList
91
92 DESCRIPTION
93 Function sapCleanupChannelList frees up the memory allocated to the channel list.
94
95 DEPENDENCIES
96 NA.
97
98 PARAMETERS
99
100 IN
101 NULL
102
103 RETURN VALUE
104 NULL
105============================================================================*/
106
107void sapCleanupChannelList(void)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700108{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700109 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530110 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700111
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700112 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
113 "Cleaning up the channel list structure");
114
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530115 if (NULL == pvosGCtx)
116 {
117 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
118 "SAP Global Context is NULL");
119 return ;
120 }
121
122 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
123 if (NULL == pSapCtx)
124 {
125 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
126 "SAP Context is NULL");
127 return ;
128 }
129
130 pSapCtx->SapChnlList.numChannel = 0;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700131 vos_mem_free(pSapCtx->SapChnlList.channelList);
132 pSapCtx->SapChnlList.channelList = NULL;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700133}
134
135/*==========================================================================
136 FUNCTION sapSetPreferredChannel
137
138 DESCRIPTION
139 Function sapSetPreferredChannel sets the channel list which has been configured
140 into sap context (pSapCtx) which will be used at the time of best channel selection.
141
142 DEPENDENCIES
143 NA.
144
145 PARAMETERS
146
147 IN
148 *ptr: pointer having the command followed by the arguments in string format
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700149
150 RETURN VALUE
151 int: return 0 when success else returns error code.
152============================================================================*/
153
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800154int sapSetPreferredChannel(tANI_U8* ptr)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700155{
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700156
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700157 v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL);
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530158 ptSapContext pSapCtx;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700159 tANI_U8* param;
160 int tempInt;
161 int j;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700162
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700163 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700164 "Enter: %s", __func__);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700165
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530166 if (NULL == pvosGCtx)
167 {
168 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
169 "SAP Global Context is NULL");
170 return -EINVAL;
171 }
172
173 pSapCtx = VOS_GET_SAP_CB(pvosGCtx);
174 if (NULL == pSapCtx)
175 {
176 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_FATAL,
177 "SAP Context is NULL");
178 return -EINVAL;
179 }
180
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700181 if (NULL != pSapCtx->SapChnlList.channelList)
182 {
183 sapCleanupChannelList();
184 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700185
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800186 param = strchr(ptr, ' ');
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700187 /*no argument after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800188 if (NULL == param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700189 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800190 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700191 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700192
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700193 /*no space after the command*/
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800194 else if (SPACE_ASCII_VALUE != *param)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700195 {
Mahesh Kumar Kalikot Veetil2aad8d82013-02-07 12:31:28 -0800196 return -EINVAL;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700197 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700198
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700199 param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700200
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700201 /*removing empty spaces*/
202 while((SPACE_ASCII_VALUE == *param)&& ('\0' != *param) ) param++;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700203
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700204 /*no argument followed by spaces*/
205 if('\0' == *param)
206 {
207 return -EINVAL;
208 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700209
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700210 /*getting the first argument ie the number of channels*/
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800211 if (sscanf(param, "%d ", &tempInt) != 1)
212 {
213 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800214 "%s: Cannot get number of channels from input", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800215 return -EINVAL;
216 }
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700217
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700218 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800219 "%s: Number of channel added are: %d", __func__, tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700220
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800221 if (tempInt <= 0 || tempInt > 255)
222 {
223 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800224 "%s: Invalid Number of channel received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800225 return -EINVAL;
226 }
227
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700228 /*allocating space for the desired number of channels*/
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530229 pSapCtx->SapChnlList.channelList = (v_U8_t *)vos_mem_malloc(tempInt);
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700230
Gopichand Nakkala936715f2013-03-18 19:48:10 +0530231 if (NULL == pSapCtx->SapChnlList.channelList)
232 {
233 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
234 "In %s, VOS_MALLOC_ERR", __func__);
235 return -EINVAL;
236 }
237
238 pSapCtx->SapChnlList.numChannel = tempInt;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700239 for(j=0;j<pSapCtx->SapChnlList.numChannel;j++)
240 {
241
242 /*param pointing to the beginning of first space after number of channels*/
243 param = strpbrk( param, " " );
244 /*no channel list after the number of channels argument*/
245 if (NULL == param)
246 {
247 sapCleanupChannelList();
248 return -EINVAL;
249 }
250
251 param++;
252
253 /*removing empty space*/
254 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
255
256 /*no channel list after the number of channels argument and spaces*/
257 if( '\0' == *param )
258 {
259 sapCleanupChannelList();
260 return -EINVAL;
261 }
262
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800263 if (sscanf(param, "%d ", &tempInt) != 1)
264 {
265 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800266 "%s: Cannot read channel number", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800267 sapCleanupChannelList();
268 return -EINVAL;
269 }
270 if (tempInt < 0 || tempInt > 255)
271 {
272 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800273 "%s: Invalid channel number received", __func__);
Mingcheng Zhuc7608ae2013-11-04 15:11:01 -0800274 sapCleanupChannelList();
275 return -EINVAL;
276 }
277
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700278 pSapCtx->SapChnlList.channelList[j] = tempInt;
279
280 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Jeff Johnsona47e9922013-11-05 12:01:42 -0800281 "%s: Channel %d added to preferred channel list",
282 __func__, pSapCtx->SapChnlList.channelList[j] );
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700283
284 }
285
286 /*extra arguments check*/
287 param = strpbrk( param, " " );
288 if (NULL != param)
289 {
290 while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++;
291
292 if('\0' != *param)
293 {
294 sapCleanupChannelList();
295 return -EINVAL;
296 }
297 }
298
299 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700300 "Exit: %s", __func__);
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700301
302 return 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700303}
304
305/*==========================================================================
306 FUNCTION sapSelectPreferredChannelFromChannelList
307
308 DESCRIPTION
309 Function sapSelectPreferredChannelFromChannelList calculates the best channel
310 among the configured channel list. If channel list not configured then returns
311 the best channel calculated among all the channel list.
312
313 DEPENDENCIES
314 NA.
315
316 PARAMETERS
317
318 IN
319 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
320 bestChNum: best channel already calculated among all the chanels
321 pSapCtx: having info of channel list from which best channel is selected
322
323 RETURN VALUE
324 v_U8_t: best channel
325============================================================================*/
326v_U8_t sapSelectPreferredChannelFromChannelList(v_U8_t bestChNum,
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700327 ptSapContext pSapCtx,
328 tSapChSelSpectInfo *pSpectInfoParams)
329{
330 v_U8_t j = 0;
331 v_U8_t count = 0;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700332
333 //If Channel List is not Configured don't do anything
334 //Else return the Best Channel from the Channel List
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700335 if((NULL == pSapCtx->SapChnlList.channelList) ||
336 (NULL == pSpectInfoParams) ||
337 (0 == pSapCtx->SapChnlList.numChannel))
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700338 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700339 return bestChNum;
340 }
341
342 if (bestChNum > 0 && bestChNum <= 252)
343 {
344 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700345 {
346 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum;
347 // Select the best channel from allowed list
348 for(j=0;j< pSapCtx->SapChnlList.numChannel;j++)
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700349 {
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700350 if( (pSapCtx->SapChnlList.channelList[j]) == bestChNum)
351 {
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700352 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
353 "Best channel computed from Channel List is: %d",
354 bestChNum);
355 return bestChNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700356 }
357 }
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -0700358 }
359
360 return SAP_CHANNEL_NOT_SELECTED;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -0700361 }
362 else
363 return SAP_CHANNEL_NOT_SELECTED;
364}
365
366
Jeff Johnson295189b2012-06-20 16:38:30 -0700367/*==========================================================================
368 FUNCTION sapChanSelInit
369
370 DESCRIPTION
371 Function sapChanSelInit allocates the memory, intializes the
372 structures used by the channel selection algorithm
373
374 DEPENDENCIES
375 NA.
376
377 PARAMETERS
378
379 IN
380 *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure
381
382 RETURN VALUE
383 v_BOOL_t: Success or FAIL
384
385 SIDE EFFECTS
386============================================================================*/
387v_BOOL_t sapChanSelInit(tHalHandle halHandle, tSapChSelSpectInfo *pSpectInfoParams)
388{
389 tSapSpectChInfo *pSpectCh = NULL;
390 v_U8_t *pChans = NULL;
391 v_U16_t channelnum = 0;
392 tpAniSirGlobal pMac = PMAC_STRUCT(halHandle);
Leo Chang0b0e45a2013-12-15 15:18:55 -0800393#ifdef FEATURE_WLAN_CH_AVOID
394 v_U16_t i;
395 v_BOOL_t chSafe = VOS_TRUE;
396#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700397
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700398 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700399
400 // Channels for that 2.4GHz band
401 //Considered only for 2.4GHz need to change in future to support 5GHz support
402 pSpectInfoParams->numSpectChans = pMac->scan.base20MHzChannels.numChannels;
403
404 // Allocate memory for weight computation of 2.4GHz
405 pSpectCh = (tSapSpectChInfo *)vos_mem_malloc((pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
406
407 if(pSpectCh == NULL) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700408 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, VOS_MALLOC_ERR", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700409 return eSAP_FALSE;
410 }
411
412 vos_mem_zero(pSpectCh, (pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh));
413
414 // Initialize the pointers in the DfsParams to the allocated memory
415 pSpectInfoParams->pSpectCh = pSpectCh;
416
417 pChans = pMac->scan.base20MHzChannels.channelList;
418
419 // Fill the channel number in the spectrum in the operating freq band
420 for (channelnum = 0; channelnum < pSpectInfoParams->numSpectChans; channelnum++) {
Leo Chang0b0e45a2013-12-15 15:18:55 -0800421#ifdef FEATURE_WLAN_CH_AVOID
422 chSafe = VOS_TRUE;
423 for(i = 0; i < NUM_20MHZ_RF_CHANNELS; i++)
424 {
425 if((safeChannels[i].channelNumber == *pChans) &&
426 (VOS_FALSE == safeChannels[i].isSafe))
427 {
428 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO,
429 "%s : CH %d is not safe", __func__, *pChans);
430 chSafe = VOS_FALSE;
431 break;
432 }
433 }
434#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700435
436 if(*pChans == 14 ) //OFDM rates are not supported on channel 14
Abhishek Singhb51853c2014-03-13 18:26:41 +0530437 {
438 pChans++;
Jeff Johnson295189b2012-06-20 16:38:30 -0700439 continue;
Abhishek Singhb51853c2014-03-13 18:26:41 +0530440 }
Leo Chang0b0e45a2013-12-15 15:18:55 -0800441#ifdef FEATURE_WLAN_CH_AVOID
442 if (VOS_TRUE == chSafe)
443 {
444#endif /* FEATURE_WLAN_CH_AVOID */
445 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_DEBUG,
446 "%s : Available Ch %d",
447 __func__, *pChans);
448 pSpectCh->chNum = *pChans;
449 pSpectCh->valid = eSAP_TRUE;
450 // Initialise for all channels
451 pSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
452 // Initialise 20MHz for all the Channels
453 pSpectCh->channelWidth = SOFTAP_HT20_CHANNELWIDTH;
454 pSpectCh++;
455#ifdef FEATURE_WLAN_CH_AVOID
456 }
457#endif /* FEATURE_WLAN_CH_AVOID */
Jeff Johnson295189b2012-06-20 16:38:30 -0700458 pChans++;
459 }
460 return eSAP_TRUE;
461}
462
463/*==========================================================================
464 FUNCTION sapweightRssiCount
465
466 DESCRIPTION
467 Function weightRssiCount calculates the channel weight due to rssi
468 and data count(here number of BSS observed)
469
470 DEPENDENCIES
471 NA.
472
473 PARAMETERS
474
475 IN
476 rssi : Max signal strength receieved from a BSS for the channel
477 count : Number of BSS observed in the channel
478
479 RETURN VALUE
480 v_U32_t : Calculated channel weight based on above two
481
482 SIDE EFFECTS
483============================================================================*/
484v_U32_t sapweightRssiCount(v_S7_t rssi, v_U16_t count)
485{
486 v_S31_t rssiWeight=0;
487 v_S31_t countWeight=0;
488 v_U32_t rssicountWeight=0;
489
490 // Weight from RSSI
491 rssiWeight = SOFTAP_RSSI_WEIGHT * (rssi - SOFTAP_MIN_RSSI)
492 /(SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530493
Jeff Johnson295189b2012-06-20 16:38:30 -0700494 if(rssiWeight > SOFTAP_RSSI_WEIGHT)
495 rssiWeight = SOFTAP_RSSI_WEIGHT;
496 else if (rssiWeight < 0)
497 rssiWeight = 0;
498
499 // Weight from data count
500 countWeight = SOFTAP_COUNT_WEIGHT * (count - SOFTAP_MIN_COUNT)
501 /(SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530502
Jeff Johnson295189b2012-06-20 16:38:30 -0700503 if(countWeight > SOFTAP_COUNT_WEIGHT)
504 countWeight = SOFTAP_COUNT_WEIGHT;
505 else if (countWeight < 0)
506 countWeight = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530507
Jeff Johnson295189b2012-06-20 16:38:30 -0700508 rssicountWeight = rssiWeight + countWeight;
509
510 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 -0700511 __func__, rssiWeight, countWeight, rssicountWeight);
Jeff Johnson295189b2012-06-20 16:38:30 -0700512
513 return(rssicountWeight);
514}
515
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800516
517/*==========================================================================
518 FUNCTION sapInterferenceRssiCount
519
520 DESCRIPTION
521 Function sapInterferenceRssiCount Considers the Adjacent channel rssi
522 and data count(here number of BSS observed)
523
524 DEPENDENCIES
525 NA.
526
527 PARAMETERS
528
529 pSpectCh : Channel Information
530
531 RETURN VALUE
532 NA.
533
534 SIDE EFFECTS
535============================================================================*/
536void sapInterferenceRssiCount(tSapSpectChInfo *pSpectCh)
537{
538 tSapSpectChInfo *pExtSpectCh = NULL;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700539 v_S31_t rssi;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530540
Abhishek Singh4eb79062014-04-10 14:48:14 +0530541 if (NULL == pSpectCh)
542 {
543 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
544 "%s: pSpectCh is NULL", __func__);
545 return;
546 }
547
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800548 switch(pSpectCh->chNum)
549 {
550 case CHANNEL_1:
551 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530552 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800553 {
554 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530555 rssi = pSpectCh->rssiAgr +
556 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700557 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
558 {
559 pExtSpectCh->rssiAgr = rssi;
560 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530561 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800562 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
563 }
564 pExtSpectCh = (pSpectCh + 2);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530565 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800566 {
567 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530568 rssi = pSpectCh->rssiAgr +
569 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700570 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
571 {
572 pExtSpectCh->rssiAgr = rssi;
573 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800574 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
575 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
576 }
577 pExtSpectCh = (pSpectCh + 3);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530578 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800579 {
580 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530581 rssi = pSpectCh->rssiAgr +
582 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700583 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
584 {
585 pExtSpectCh->rssiAgr = rssi;
586 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800587 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
588 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
589 }
590 pExtSpectCh = (pSpectCh + 4);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530591 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800592 {
593 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530594 rssi = pSpectCh->rssiAgr +
595 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700596 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
597 {
598 pExtSpectCh->rssiAgr = rssi;
599 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530600 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800601 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
602 }
603 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530604
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800605 case CHANNEL_2:
606 pExtSpectCh = (pSpectCh - 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530607 if (pExtSpectCh != NULL)
608 {
609 ++pExtSpectCh->bssCount;
610 rssi = pSpectCh->rssiAgr +
611 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
612 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
613 {
614 pExtSpectCh->rssiAgr = rssi;
615 }
616 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
617 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
618 }
619 pExtSpectCh = (pSpectCh + 1);
620 if (pExtSpectCh != NULL)
621 {
622 ++pExtSpectCh->bssCount;
623 rssi = pSpectCh->rssiAgr +
624 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
625 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
626 {
627 pExtSpectCh->rssiAgr = rssi;
628 }
629 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
630 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
631 }
632 pExtSpectCh = (pSpectCh + 2);
633 if (pExtSpectCh != NULL)
634 {
635 ++pExtSpectCh->bssCount;
636 rssi = pSpectCh->rssiAgr +
637 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
638 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
639 {
640 pExtSpectCh->rssiAgr = rssi;
641 }
642 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
643 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
644 }
645 pExtSpectCh = (pSpectCh + 3);
646 if (pExtSpectCh != NULL)
647 {
648 ++pExtSpectCh->bssCount;
649 rssi = pSpectCh->rssiAgr +
650 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
651 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
652 {
653 pExtSpectCh->rssiAgr = rssi;
654 }
655 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
656 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
657 }
658 pExtSpectCh = (pSpectCh + 4);
659 if (pExtSpectCh != NULL)
660 {
661 ++pExtSpectCh->bssCount;
662 rssi = pSpectCh->rssiAgr +
663 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
664 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
665 {
666 pExtSpectCh->rssiAgr = rssi;
667 }
668 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
669 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
670 }
671 break;
672 case CHANNEL_3:
673 pExtSpectCh = (pSpectCh - 2);
674 if (pExtSpectCh != NULL)
675 {
676 ++pExtSpectCh->bssCount;
677 rssi = pSpectCh->rssiAgr +
678 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
679 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
680 {
681 pExtSpectCh->rssiAgr = rssi;
682 }
683 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
684 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
685 }
686 pExtSpectCh = (pSpectCh - 1);
687 if (pExtSpectCh != NULL)
688 {
689 ++pExtSpectCh->bssCount;
690 rssi = pSpectCh->rssiAgr +
691 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
692 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
693 {
694 pExtSpectCh->rssiAgr = rssi;
695 }
696 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
697 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
698 }
699 pExtSpectCh = (pSpectCh + 1);
700 if (pExtSpectCh != NULL)
701 {
702 ++pExtSpectCh->bssCount;
703 rssi = pSpectCh->rssiAgr +
704 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
705 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
706 {
707 pExtSpectCh->rssiAgr = rssi;
708 }
709 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
710 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
711 }
712 pExtSpectCh = (pSpectCh + 2);
713 if (pExtSpectCh != NULL)
714 {
715 ++pExtSpectCh->bssCount;
716 rssi = pSpectCh->rssiAgr +
717 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
718 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
719 {
720 pExtSpectCh->rssiAgr = rssi;
721 }
722 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
723 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
724 }
725 pExtSpectCh = (pSpectCh + 3);
726 if (pExtSpectCh != NULL)
727 {
728 ++pExtSpectCh->bssCount;
729 rssi = pSpectCh->rssiAgr +
730 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
731 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
732 {
733 pExtSpectCh->rssiAgr = rssi;
734 }
735 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
736 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
737 }
738 pExtSpectCh = (pSpectCh + 4);
739 if (pExtSpectCh != NULL)
740 {
741 ++pExtSpectCh->bssCount;
742 rssi = pSpectCh->rssiAgr +
743 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
744 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
745 {
746 pExtSpectCh->rssiAgr = rssi;
747 }
748 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
749 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
750 }
751 break;
752 case CHANNEL_4:
753 pExtSpectCh = (pSpectCh - 3);
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800754 if(pExtSpectCh != NULL)
755 {
756 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530757 rssi = pSpectCh->rssiAgr +
758 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
759 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
760 {
761 pExtSpectCh->rssiAgr = rssi;
762 }
763 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
764 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
765 }
766 pExtSpectCh = (pSpectCh - 2);
767 if (pExtSpectCh != NULL)
768 {
769 ++pExtSpectCh->bssCount;
770 rssi = pSpectCh->rssiAgr +
771 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
772 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
773 {
774 pExtSpectCh->rssiAgr = rssi;
775 }
776 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
777 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
778 }
779 pExtSpectCh = (pSpectCh - 1);
780 if (pExtSpectCh != NULL)
781 {
782 ++pExtSpectCh->bssCount;
783 rssi = pSpectCh->rssiAgr +
784 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700785 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
786 {
787 pExtSpectCh->rssiAgr = rssi;
788 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800789 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
790 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
791 }
792 pExtSpectCh = (pSpectCh + 1);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530793 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800794 {
795 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530796 rssi = pSpectCh->rssiAgr +
797 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
798 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
799 {
800 pExtSpectCh->rssiAgr = rssi;
801 }
802 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
803 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
804 }
805 pExtSpectCh = (pSpectCh + 2);
806 if (pExtSpectCh != NULL)
807 {
808 ++pExtSpectCh->bssCount;
809 rssi = pSpectCh->rssiAgr +
810 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
811 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
812 {
813 pExtSpectCh->rssiAgr = rssi;
814 }
815 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
816 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
817 }
818 pExtSpectCh = (pSpectCh + 3);
819 if (pExtSpectCh != NULL)
820 {
821 ++pExtSpectCh->bssCount;
822 rssi = pSpectCh->rssiAgr +
823 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
824 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
825 {
826 pExtSpectCh->rssiAgr = rssi;
827 }
828 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
829 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
830 }
831 pExtSpectCh = (pSpectCh + 4);
832 if (pExtSpectCh != NULL)
833 {
834 ++pExtSpectCh->bssCount;
835 rssi = pSpectCh->rssiAgr +
836 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
837 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
838 {
839 pExtSpectCh->rssiAgr = rssi;
840 }
841 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
842 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
843 }
844 break;
845
846 case CHANNEL_5:
847 case CHANNEL_6:
848 case CHANNEL_7:
849 pExtSpectCh = (pSpectCh - 4);
850 if (pExtSpectCh != NULL)
851 {
852 ++pExtSpectCh->bssCount;
853 rssi = pSpectCh->rssiAgr +
854 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700855 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
856 {
857 pExtSpectCh->rssiAgr = rssi;
858 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800859 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
860 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
861 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530862 pExtSpectCh = (pSpectCh - 3);
863 if (pExtSpectCh != NULL)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800864 {
865 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530866 rssi = pSpectCh->rssiAgr +
867 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700868 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
869 {
870 pExtSpectCh->rssiAgr = rssi;
871 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800872 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
873 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
874 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530875 pExtSpectCh = (pSpectCh - 2);
876 if (pExtSpectCh != NULL)
877 {
878 ++pExtSpectCh->bssCount;
879 rssi = pSpectCh->rssiAgr +
880 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
881 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
882 {
883 pExtSpectCh->rssiAgr = rssi;
884 }
885 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
886 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
887 }
888 pExtSpectCh = (pSpectCh - 1);
889 if(pExtSpectCh != NULL)
890 {
891 ++pExtSpectCh->bssCount;
892 rssi = pSpectCh->rssiAgr +
893 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
894 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
895 {
896 pExtSpectCh->rssiAgr = rssi;
897 }
898 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
899 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
900 }
901 pExtSpectCh = (pSpectCh + 1);
902 if (pExtSpectCh != NULL)
903 {
904 ++pExtSpectCh->bssCount;
905 rssi = pSpectCh->rssiAgr +
906 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
907 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
908 {
909 pExtSpectCh->rssiAgr = rssi;
910 }
911 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
912 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
913 }
914 pExtSpectCh = (pSpectCh + 2);
915 if(pExtSpectCh != NULL)
916 {
917 ++pExtSpectCh->bssCount;
918 rssi = pSpectCh->rssiAgr +
919 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
920 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
921 {
922 pExtSpectCh->rssiAgr = rssi;
923 }
924 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
925 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
926 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800927 pExtSpectCh = (pSpectCh + 3);
928 if(pExtSpectCh != NULL)
929 {
930 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530931 rssi = pSpectCh->rssiAgr +
932 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
933 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
934 {
935 pExtSpectCh->rssiAgr = rssi;
936 }
937 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
938 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
939 }
940 pExtSpectCh = (pSpectCh + 4);
941 if (pExtSpectCh != NULL)
942 {
943 ++pExtSpectCh->bssCount;
944 rssi = pSpectCh->rssiAgr +
945 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -0700946 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
947 {
948 pExtSpectCh->rssiAgr = rssi;
949 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800950 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
951 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
952 }
953 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530954
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800955 case CHANNEL_8:
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -0800956 pExtSpectCh = (pSpectCh - 4);
957 if(pExtSpectCh != NULL)
958 {
959 ++pExtSpectCh->bssCount;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +0530960 rssi = pSpectCh->rssiAgr +
961 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
962 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
963 {
964 pExtSpectCh->rssiAgr = rssi;
965 }
966 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
967 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
968 }
969
970 pExtSpectCh = (pSpectCh - 3);
971 if (pExtSpectCh != NULL)
972 {
973 ++pExtSpectCh->bssCount;
974 rssi = pSpectCh->rssiAgr +
975 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
976 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
977 {
978 pExtSpectCh->rssiAgr = rssi;
979 }
980 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
981 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
982 }
983 pExtSpectCh = (pSpectCh - 2);
984 if (pExtSpectCh != NULL)
985 {
986 ++pExtSpectCh->bssCount;
987 rssi = pSpectCh->rssiAgr +
988 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
989 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
990 {
991 pExtSpectCh->rssiAgr = rssi;
992 }
993 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
994 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
995 }
996 pExtSpectCh = (pSpectCh - 1);
997 if (pExtSpectCh != NULL)
998 {
999 ++pExtSpectCh->bssCount;
1000 rssi = pSpectCh->rssiAgr +
1001 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1002 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1003 {
1004 pExtSpectCh->rssiAgr = rssi;
1005 }
1006 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1007 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1008 }
1009 pExtSpectCh = (pSpectCh + 1);
1010 if (pExtSpectCh != NULL)
1011 {
1012 ++pExtSpectCh->bssCount;
1013 rssi = pSpectCh->rssiAgr +
1014 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1015 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1016 {
1017 pExtSpectCh->rssiAgr = rssi;
1018 }
1019 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1020 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1021 }
1022 pExtSpectCh = (pSpectCh + 2);
1023 if (pExtSpectCh != NULL)
1024 {
1025 ++pExtSpectCh->bssCount;
1026 rssi = pSpectCh->rssiAgr +
1027 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1028 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1029 {
1030 pExtSpectCh->rssiAgr = rssi;
1031 }
1032 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1033 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1034 }
1035 pExtSpectCh = (pSpectCh + 3);
1036 if (pExtSpectCh != NULL)
1037 {
1038 ++pExtSpectCh->bssCount;
1039 rssi = pSpectCh->rssiAgr +
1040 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1041 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1042 {
1043 pExtSpectCh->rssiAgr = rssi;
1044 }
1045 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1046 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1047 }
1048 break;
1049
1050 case CHANNEL_9:
1051 pExtSpectCh = (pSpectCh - 4);
1052 if (pExtSpectCh != NULL)
1053 {
1054 ++pExtSpectCh->bssCount;
1055 rssi = pSpectCh->rssiAgr +
1056 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001057 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1058 {
1059 pExtSpectCh->rssiAgr = rssi;
1060 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001061 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1062 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1063 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301064
1065 pExtSpectCh = (pSpectCh - 3);
1066 if (pExtSpectCh != NULL)
1067 {
1068 ++pExtSpectCh->bssCount;
1069 rssi = pSpectCh->rssiAgr +
1070 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1071 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1072 {
1073 pExtSpectCh->rssiAgr = rssi;
1074 }
1075 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1076 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1077 }
1078 pExtSpectCh = (pSpectCh - 2);
1079 if (pExtSpectCh != NULL)
1080 {
1081 ++pExtSpectCh->bssCount;
1082 rssi = pSpectCh->rssiAgr +
1083 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1084 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1085 {
1086 pExtSpectCh->rssiAgr = rssi;
1087 }
1088 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1089 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1090 }
1091 pExtSpectCh = (pSpectCh - 1);
1092 if (pExtSpectCh != NULL)
1093 {
1094 ++pExtSpectCh->bssCount;
1095 rssi = pSpectCh->rssiAgr +
1096 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1097 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1098 {
1099 pExtSpectCh->rssiAgr = rssi;
1100 }
1101 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1102 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1103 }
1104 pExtSpectCh = (pSpectCh + 1);
1105 if (pExtSpectCh != NULL)
1106 {
1107 ++pExtSpectCh->bssCount;
1108 rssi = pSpectCh->rssiAgr +
1109 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1110 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1111 {
1112 pExtSpectCh->rssiAgr = rssi;
1113 }
1114 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1115 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1116 }
1117 pExtSpectCh = (pSpectCh + 2);
1118 if (pExtSpectCh != NULL)
1119 {
1120 ++pExtSpectCh->bssCount;
1121 rssi = pSpectCh->rssiAgr +
1122 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1123 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1124 {
1125 pExtSpectCh->rssiAgr = rssi;
1126 }
1127 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1128 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1129 }
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001130 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301131
1132 case CHANNEL_10:
1133 pExtSpectCh = (pSpectCh - 4);
1134 if (pExtSpectCh != NULL)
1135 {
1136 ++pExtSpectCh->bssCount;
1137 rssi = pSpectCh->rssiAgr +
1138 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1139 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1140 {
1141 pExtSpectCh->rssiAgr = rssi;
1142 }
1143 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1144 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1145 }
1146
1147 pExtSpectCh = (pSpectCh - 3);
1148 if (pExtSpectCh != NULL)
1149 {
1150 ++pExtSpectCh->bssCount;
1151 rssi = pSpectCh->rssiAgr +
1152 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1153 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1154 {
1155 pExtSpectCh->rssiAgr = rssi;
1156 }
1157 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1158 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1159 }
1160 pExtSpectCh = (pSpectCh - 2);
1161 if(pExtSpectCh != NULL)
1162 {
1163 ++pExtSpectCh->bssCount;
1164 rssi = pSpectCh->rssiAgr +
1165 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1166 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1167 {
1168 pExtSpectCh->rssiAgr = rssi;
1169 }
1170 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1171 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1172 }
1173 pExtSpectCh = (pSpectCh - 1);
1174 if (pExtSpectCh != NULL)
1175 {
1176 ++pExtSpectCh->bssCount;
1177 rssi = pSpectCh->rssiAgr +
1178 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1179 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1180 {
1181 pExtSpectCh->rssiAgr = rssi;
1182 }
1183 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1184 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1185 }
1186 pExtSpectCh = (pSpectCh + 1);
1187 if (pExtSpectCh != NULL)
1188 {
1189 ++pExtSpectCh->bssCount;
1190 rssi = pSpectCh->rssiAgr +
1191 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1192 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1193 {
1194 pExtSpectCh->rssiAgr = rssi;
1195 }
1196 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1197 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1198 }
1199 break;
1200
1201 case CHANNEL_11:
1202 pExtSpectCh = (pSpectCh - 1);
1203 if (pExtSpectCh != NULL)
1204 {
1205 ++pExtSpectCh->bssCount;
1206 rssi = pSpectCh->rssiAgr +
1207 SAP_24GHZ_FIRST_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1208 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1209 {
1210 pExtSpectCh->rssiAgr = rssi;
1211 }
1212 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1213 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1214 }
1215 pExtSpectCh = (pSpectCh - 2);
1216 if (pExtSpectCh != NULL)
1217 {
1218 ++pExtSpectCh->bssCount;
1219 rssi = pSpectCh->rssiAgr +
1220 SAP_24GHZ_SEC_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1221 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1222 {
1223 pExtSpectCh->rssiAgr = rssi;
1224 }
1225 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1226 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1227 }
1228 pExtSpectCh = (pSpectCh - 3);
1229 if (pExtSpectCh != NULL)
1230 {
1231 ++pExtSpectCh->bssCount;
1232 rssi = pSpectCh->rssiAgr +
1233 SAP_24GHZ_THIRD_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1234 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1235 {
1236 pExtSpectCh->rssiAgr = rssi;
1237 }
1238 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1239 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1240 }
1241 pExtSpectCh = (pSpectCh - 4);
1242 if (pExtSpectCh != NULL)
1243 {
1244 ++pExtSpectCh->bssCount;
1245 rssi = pSpectCh->rssiAgr +
1246 SAP_24GHZ_FOURTH_OVERLAP_CHAN_RSSI_EFFECT_PRIMARY;
1247 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1248 {
1249 pExtSpectCh->rssiAgr = rssi;
1250 }
1251 if (pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1252 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1253 }
1254 break;
1255
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001256 default:
1257 break;
1258 }
1259}
1260
Jeff Johnson295189b2012-06-20 16:38:30 -07001261/*==========================================================================
1262 FUNCTION sapComputeSpectWeight
1263
1264 DESCRIPTION
1265 Main function for computing the weight of each channel in the
1266 spectrum based on the RSSI value of the BSSes on the channel
1267 and number of BSS
1268
1269 DEPENDENCIES
1270 NA.
1271
1272 PARAMETERS
1273
1274 IN
1275 pSpectInfoParams : Pointer to the tSpectInfoParams structure
1276 halHandle : Pointer to HAL handle
1277 pResult : Pointer to tScanResultHandle
1278
1279 RETURN VALUE
1280 void : NULL
1281
1282 SIDE EFFECTS
1283============================================================================*/
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301284void sapComputeSpectWeight( tSapChSelSpectInfo* pSpectInfoParams,
1285 tHalHandle halHandle, tScanResultHandle pResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001286{
1287 v_S7_t rssi = 0;
1288 v_U8_t chn_num = 0;
1289 v_U8_t channel_id = 0;
1290
1291 tCsrScanResultInfo *pScanResult;
1292 tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001293 v_U32_t operatingBand;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001294 v_U16_t channelWidth;
1295 v_U16_t secondaryChannelOffset;
1296 v_U16_t centerFreq;
1297 v_U16_t vhtSupport;
1298 v_U32_t ieLen = 0;
1299 tSirProbeRespBeacon *pBeaconStruct;
1300 tpAniSirGlobal pMac = (tpAniSirGlobal) halHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -07001301
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301302 pBeaconStruct = vos_mem_malloc(sizeof(tSirProbeRespBeacon));
1303 if ( NULL == pBeaconStruct )
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001304 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301305 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1306 "Unable to allocate memory in sapComputeSpectWeight\n");
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001307 return;
1308 }
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001309 VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Computing spectral weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001310
1311 /**
1312 * Soft AP specific channel weight calculation using DFS formula
1313 */
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001314 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand);
Jeff Johnson295189b2012-06-20 16:38:30 -07001315
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301316 pScanResult = sme_ScanResultGetFirst(halHandle, pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07001317
1318 while (pScanResult) {
1319 pSpectCh = pSpectInfoParams->pSpectCh;
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001320 // Defining the default values, so that any value will hold the default values
1321 channelWidth = eHT_CHANNEL_WIDTH_20MHZ;
1322 secondaryChannelOffset = PHY_SINGLE_CHANNEL_CENTERED;
1323 vhtSupport = 0;
1324 centerFreq = 0;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301325
1326 if (pScanResult->BssDescriptor.ieFields != NULL)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001327 {
1328 ieLen = (pScanResult->BssDescriptor.length + sizeof(tANI_U16) + sizeof(tANI_U32) - sizeof(tSirBssDescription));
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301329 vos_mem_set((tANI_U8 *) pBeaconStruct, sizeof(tSirProbeRespBeacon), 0);
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301330
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001331 if ((sirParseBeaconIE(pMac, pBeaconStruct,(tANI_U8 *)( pScanResult->BssDescriptor.ieFields), ieLen)) == eSIR_SUCCESS)
1332 {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301333 if (pBeaconStruct->HTCaps.present && pBeaconStruct->HTInfo.present)
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001334 {
1335 channelWidth = pBeaconStruct->HTCaps.supportedChannelWidthSet;
1336 secondaryChannelOffset = pBeaconStruct->HTInfo.secondaryChannelOffset;
1337 if(pBeaconStruct->VHTOperation.present)
1338 {
1339 vhtSupport = pBeaconStruct->VHTOperation.present;
1340 if(pBeaconStruct->VHTOperation.chanWidth > WNI_CFG_VHT_CHANNEL_WIDTH_20_40MHZ)
1341 {
1342 channelWidth = eHT_CHANNEL_WIDTH_80MHZ;
1343 centerFreq = pBeaconStruct->VHTOperation.chanCenterFreqSeg1;
1344 }
1345 }
1346 }
1347 }
1348 }
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001349 // Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list
Jeff Johnson295189b2012-06-20 16:38:30 -07001350 for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; chn_num++) {
1351
1352 /*
1353 * if the Beacon has channel ID, use it other wise we will
1354 * rely on the channelIdSelf
1355 */
1356 if(pScanResult->BssDescriptor.channelId == 0)
1357 channel_id = pScanResult->BssDescriptor.channelIdSelf;
1358 else
1359 channel_id = pScanResult->BssDescriptor.channelId;
1360
krunal sonic39d9592014-02-04 11:54:24 -08001361 if (pSpectCh && (channel_id == pSpectCh->chNum)) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001362 if (pSpectCh->rssiAgr < pScanResult->BssDescriptor.rssi)
1363 pSpectCh->rssiAgr = pScanResult->BssDescriptor.rssi;
1364
1365 ++pSpectCh->bssCount; // Increment the count of BSS
1366
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001367 if(operatingBand) // Connsidering the Extension Channel only in a channels
1368 {
1369 /* Updating the received ChannelWidth */
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301370 if (pSpectCh->channelWidth != channelWidth)
1371 pSpectCh->channelWidth = channelWidth;
Madan Mohan Koyyalamudi1e02f7f2012-12-04 16:46:45 -08001372 /* If received ChannelWidth is other than HT20, we need to update the extension channel Params as well */
1373 /* channelWidth == 0, HT20 */
1374 /* channelWidth == 1, HT40 */
1375 /* channelWidth == 2, VHT80*/
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001376 switch(pSpectCh->channelWidth)
1377 {
1378 case eHT_CHANNEL_WIDTH_40MHZ: //HT40
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001379 switch( secondaryChannelOffset)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001380 {
1381 tSapSpectChInfo *pExtSpectCh = NULL;
1382 case PHY_DOUBLE_CHANNEL_LOW_PRIMARY: // Above the Primary Channel
1383 pExtSpectCh = (pSpectCh + 1);
1384 if(pExtSpectCh != NULL)
1385 {
1386 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001387 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001388 // REducing the rssi by -20 and assigning it to Extension channel
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001389 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1390 {
1391 pExtSpectCh->rssiAgr = rssi;
1392 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001393 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1394 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1395 }
1396 break;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301397
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001398 case PHY_DOUBLE_CHANNEL_HIGH_PRIMARY: // Below the Primary channel
1399 pExtSpectCh = (pSpectCh - 1);
1400 if(pExtSpectCh != NULL)
1401 {
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001402 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1403 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1404 {
1405 pExtSpectCh->rssiAgr = rssi;
1406 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001407 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1408 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1409 ++pExtSpectCh->bssCount;
1410 }
1411 break;
1412 }
1413 break;
1414 case eHT_CHANNEL_WIDTH_80MHZ: // VHT80
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001415 if((centerFreq - channel_id) == 6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001416 {
1417 tSapSpectChInfo *pExtSpectCh = NULL;
1418 pExtSpectCh = (pSpectCh + 1);
1419 if(pExtSpectCh != NULL)
1420 {
1421 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001422 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1423 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1424 {
1425 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -20 and assigning it to Subband 1
1426 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001427 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1428 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1429 }
1430 pExtSpectCh = (pSpectCh + 2);
1431 if(pExtSpectCh != NULL)
1432 {
1433 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001434 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1435 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1436 {
1437 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -30 and assigning it to Subband 2
1438 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001439 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1440 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1441 }
1442 pExtSpectCh = (pSpectCh + 3);
1443 if(pExtSpectCh != NULL)
1444 {
1445 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001446 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1447 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1448 {
1449 pExtSpectCh->rssiAgr = rssi; // Reducing the rssi by -40 and assigning it to Subband 3
1450 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001451 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1452 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301453 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001454 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001455 else if((centerFreq - channel_id) == 2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001456 {
1457 tSapSpectChInfo *pExtSpectCh = NULL;
1458 pExtSpectCh = (pSpectCh - 1 );
1459 if(pExtSpectCh != NULL)
1460 {
1461 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001462 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1463 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1464 {
1465 pExtSpectCh->rssiAgr = rssi;
1466 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001467 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1468 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1469 }
1470 pExtSpectCh = (pSpectCh + 1);
1471 if(pExtSpectCh != NULL)
1472 {
1473 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001474 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1475 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1476 {
1477 pExtSpectCh->rssiAgr = rssi;
1478 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001479 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1480 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1481 }
1482 pExtSpectCh = (pSpectCh + 2);
1483 if(pExtSpectCh != NULL)
1484 {
1485 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001486 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1487 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1488 {
1489 pExtSpectCh->rssiAgr = rssi;
1490 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001491 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1492 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1493 }
1494 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001495 else if((centerFreq - channel_id) == -2)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001496 {
1497 tSapSpectChInfo *pExtSpectCh = NULL;
1498 pExtSpectCh = (pSpectCh - 1 );
1499 if(pExtSpectCh != NULL)
1500 {
1501 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001502 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1503 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1504 {
1505 pExtSpectCh->rssiAgr = rssi;
1506 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001507 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1508 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1509 }
1510 pExtSpectCh = (pSpectCh - 2);
1511 if(pExtSpectCh != NULL)
1512 {
1513 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001514 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1515 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1516 {
1517 pExtSpectCh->rssiAgr = rssi;
1518 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001519 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1520 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1521 }
1522 pExtSpectCh = (pSpectCh + 1);
1523 if(pExtSpectCh != NULL)
1524 {
1525 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001526 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1527 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1528 {
1529 pExtSpectCh->rssiAgr = rssi;
1530 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001531 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1532 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1533 }
1534 }
Prathyusha Kuntupalli7b8f6aa2012-12-10 13:17:35 -08001535 else if((centerFreq - channel_id) == -6)
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001536 {
1537 tSapSpectChInfo *pExtSpectCh = NULL;
1538 pExtSpectCh = (pSpectCh - 1 );
1539 if(pExtSpectCh != NULL)
1540 {
1541 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001542 rssi = pSpectCh->rssiAgr + SAP_SUBBAND1_RSSI_EFFECT_PRIMARY;
1543 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1544 {
1545 pExtSpectCh->rssiAgr = rssi;
1546 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001547 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1548 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1549 }
1550 pExtSpectCh = (pSpectCh - 2);
1551 if(pExtSpectCh != NULL)
1552 {
1553 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001554 rssi = pSpectCh->rssiAgr + SAP_SUBBAND2_RSSI_EFFECT_PRIMARY;
1555 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1556 {
1557 pExtSpectCh->rssiAgr = rssi;
1558 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001559 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1560 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1561 }
1562 pExtSpectCh = (pSpectCh - 3);
1563 if(pExtSpectCh != NULL)
1564 {
1565 ++pExtSpectCh->bssCount;
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001566 rssi = pSpectCh->rssiAgr + SAP_SUBBAND3_RSSI_EFFECT_PRIMARY;
1567 if (IS_RSSI_VALID(pExtSpectCh->rssiAgr, rssi))
1568 {
1569 pExtSpectCh->rssiAgr = rssi;
1570 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001571 if(pExtSpectCh->rssiAgr < SOFTAP_MIN_RSSI)
1572 pExtSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
1573 }
1574 }
1575 break;
1576 }
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301577 }
Leela Venkata Kiran Kumar Reddy Chirala9f6566c2014-09-05 19:06:58 +05301578 else if(operatingBand == eSAP_RF_SUBBAND_2_4_GHZ)
Venkata Prathyusha Kuntupallie2e72082013-01-30 17:37:50 -08001579 {
1580 sapInterferenceRssiCount(pSpectCh);
1581 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08001582
Jeff Johnson295189b2012-06-20 16:38:30 -07001583 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +05301584 "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 -08001585 __func__, pScanResult->BssDescriptor.channelIdSelf, pScanResult->BssDescriptor.channelId, pScanResult->BssDescriptor.rssi, pSpectCh->bssCount, pScanResult,pSpectCh->channelWidth,secondaryChannelOffset,centerFreq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001586 pSpectCh++;
1587 break;
1588 } else {
1589 pSpectCh++;
1590 }
1591 }
1592
1593 pScanResult = sme_ScanResultGetNext(halHandle, pResult);
1594 }
1595
1596 // Calculate the weights for all channels in the spectrum pSpectCh
1597 pSpectCh = pSpectInfoParams->pSpectCh;
1598
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001599 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Spectrum Channels Weight", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001600
1601 for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); chn_num++) {
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301602
Jeff Johnson295189b2012-06-20 16:38:30 -07001603 /*
1604 rssi : Maximum received signal strength among all BSS on that channel
1605 bssCount : Number of BSS on that channel
1606 */
1607
1608 rssi = (v_S7_t)pSpectCh->rssiAgr;
1609
1610 pSpectCh->weight = SAPDFS_NORMALISE_1000 * sapweightRssiCount(rssi, pSpectCh->bssCount);
1611
Madan Mohan Koyyalamudi8c8bb1e2013-08-26 23:13:07 +05301612 //------ Debug Info ------
1613 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH,
1614 "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d", __func__,
1615 pSpectCh->chNum, pSpectCh->weight,
1616 pSpectCh->rssiAgr, pSpectCh->bssCount);
1617 //------ Debug Info ------
Jeff Johnson295189b2012-06-20 16:38:30 -07001618 pSpectCh++;
1619 }
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +05301620 vos_mem_free(pBeaconStruct);
Jeff Johnson295189b2012-06-20 16:38:30 -07001621}
1622
1623/*==========================================================================
1624 FUNCTION sapChanSelExit
1625
1626 DESCRIPTION
1627 Exit function for free out the allocated memory, to be called
1628 at the end of the dfsSelectChannel function
1629
1630 DEPENDENCIES
1631 NA.
1632
1633 PARAMETERS
1634
1635 IN
1636 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1637
1638 RETURN VALUE
1639 void : NULL
1640
1641 SIDE EFFECTS
1642============================================================================*/
1643void sapChanSelExit( tSapChSelSpectInfo *pSpectInfoParams )
1644{
1645 // Free all the allocated memory
1646 vos_mem_free(pSpectInfoParams->pSpectCh);
1647}
1648
1649/*==========================================================================
1650 FUNCTION sapSortChlWeight
1651
1652 DESCRIPTION
1653 Funtion to sort the channels with the least weight first
1654
1655 DEPENDENCIES
1656 NA.
1657
1658 PARAMETERS
1659
1660 IN
1661 pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure
1662
1663 RETURN VALUE
1664 void : NULL
1665
1666 SIDE EFFECTS
1667============================================================================*/
1668void sapSortChlWeight(tSapChSelSpectInfo *pSpectInfoParams)
1669{
1670 tSapSpectChInfo temp;
1671
1672 tSapSpectChInfo *pSpectCh = NULL;
1673 v_U32_t i = 0, j = 0, minWeightIndex = 0;
1674
1675 pSpectCh = pSpectInfoParams->pSpectCh;
1676#ifdef SOFTAP_CHANNEL_RANGE
1677 // Sorting the channels as per weights
1678 for (i = 0; i < pSpectInfoParams->numSpectChans; i++) {
1679 minWeightIndex = i;
1680 for( j = i + 1; j < pSpectInfoParams->numSpectChans; j++) {
1681 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1682 minWeightIndex = j;
1683 }
1684 }
1685 if(minWeightIndex != i) {
1686 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1687 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1688 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1689 }
1690 }
1691#else
1692 // Sorting the channels as per weights
1693 for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) {
1694 minWeightIndex = i;
1695 for( j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) {
1696 if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) {
1697 minWeightIndex = j;
1698 }
1699 }
1700 if(minWeightIndex != i) {
1701 vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh));
1702 vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh));
1703 vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh));
1704 }
1705 }
1706#endif
1707
1708 /* For testing */
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001709 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 -07001710 pSpectCh = pSpectInfoParams->pSpectCh;
1711 for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
1712 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 -07001713 __func__, pSpectCh->chNum, pSpectCh->weight, pSpectCh->rssiAgr, pSpectCh->bssCount);
Jeff Johnson295189b2012-06-20 16:38:30 -07001714 pSpectCh++;
1715 }
1716
1717}
1718
1719/*==========================================================================
1720 FUNCTION sapSelectChannel
1721
1722 DESCRIPTION
1723 Runs a algorithm to select the best channel to operate in based on BSS
1724 rssi and bss count on each channel
1725
1726 DEPENDENCIES
1727 NA.
1728
1729 PARAMETERS
1730
1731 IN
1732 halHandle : Pointer to HAL handle
1733 pResult : Pointer to tScanResultHandle
1734
1735 RETURN VALUE
1736 v_U8_t : Success - channel number, Fail - zero
1737
1738 SIDE EFFECTS
1739============================================================================*/
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07001740v_U8_t sapSelectChannel(tHalHandle halHandle, ptSapContext pSapCtx, tScanResultHandle pScanResult)
Jeff Johnson295189b2012-06-20 16:38:30 -07001741{
1742 // DFS param object holding all the data req by the algo
1743 tSapChSelSpectInfo oSpectInfoParams = {NULL,0};
1744 tSapChSelSpectInfo *pSpectInfoParams = &oSpectInfoParams; // Memory? NB
Peng Xuafc34e32014-09-25 13:23:55 +05301745 v_U8_t bestChNum = SAP_CHANNEL_NOT_SELECTED;
Jeff Johnson295189b2012-06-20 16:38:30 -07001746#ifdef SOFTAP_CHANNEL_RANGE
1747 v_U32_t startChannelNum;
1748 v_U32_t endChannelNum;
Gopichand Nakkala936715f2013-03-18 19:48:10 +05301749 v_U32_t operatingBand = 0;
Peng Xuafc34e32014-09-25 13:23:55 +05301750 v_U32_t tmpChNum;
1751 v_U8_t count;
1752#endif
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001753 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 -07001754
1755 // Set to zero tSapChSelParams
1756 //vos_mem_zero(&sapChSelParams, sizeof(sapChSelParams));
1757
1758 // Initialize the structure pointed by pSpectInfoParams
1759 if(sapChanSelInit( halHandle, pSpectInfoParams) != eSAP_TRUE ) {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001760 VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, Ch Select initialization failed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001761 return SAP_CHANNEL_NOT_SELECTED;
1762 }
1763
1764 // Compute the weight of the entire spectrum in the operating band
1765 sapComputeSpectWeight( pSpectInfoParams, halHandle, pScanResult);
1766
1767 // Sort the 20M channel list as per the computed weights, lesser weight first.
1768 sapSortChlWeight(pSpectInfoParams);
1769
1770#ifdef SOFTAP_CHANNEL_RANGE
Peng Xufc6ad8e2014-09-25 13:16:43 +05301771 if (eCSR_BAND_ALL == pSapCtx->scanBandPreference)
Peng Xu2446a892014-09-05 17:21:18 +05301772 {
Peng Xuafc34e32014-09-25 13:23:55 +05301773 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_START_CHANNEL,
1774 &startChannelNum);
1775 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_END_CHANNEL,
1776 &endChannelNum);
1777 ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND,
1778 &operatingBand);
Peng Xufc6ad8e2014-09-25 13:16:43 +05301779 }
1780 else
1781 {
1782 if (eCSR_BAND_24 == pSapCtx->currentPreferredBand)
1783 {
Peng Xu2446a892014-09-05 17:21:18 +05301784 startChannelNum = rfChannels[RF_CHAN_1].channelNum;
1785 endChannelNum = rfChannels[RF_CHAN_14].channelNum;
Leela Venkata Kiran Kumar Reddy Chirala9f6566c2014-09-05 19:06:58 +05301786 operatingBand = eSAP_RF_SUBBAND_2_4_GHZ;
Peng Xufc6ad8e2014-09-25 13:16:43 +05301787 }
1788 else
1789 {
Peng Xu2446a892014-09-05 17:21:18 +05301790 startChannelNum = rfChannels[RF_CHAN_36].channelNum;
1791 endChannelNum = rfChannels[RF_CHAN_165].channelNum;
1792 operatingBand = RF_BAND_5_GHZ;
Peng Xufc6ad8e2014-09-25 13:16:43 +05301793 }
1794 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001795
Peng Xuafc34e32014-09-25 13:23:55 +05301796 pSapCtx->acsBestChannelInfo.channelNum = 0;
1797 pSapCtx->acsBestChannelInfo.weight = CFG_ACS_BAND_SWITCH_THRESHOLD_MAX;
1798
Jeff Johnson295189b2012-06-20 16:38:30 -07001799 /*Loop till get the best channel in the given range */
1800 for(count=0; count < pSpectInfoParams->numSpectChans ; count++)
1801 {
1802 if((startChannelNum <= pSpectInfoParams->pSpectCh[count].chNum)&&
1803 ( endChannelNum >= pSpectInfoParams->pSpectCh[count].chNum))
1804 {
Deepthi Gowri38c219d2014-08-05 19:34:08 +05301805 if (NV_CHANNEL_ENABLE !=
1806 vos_nv_getChannelEnabledState(pSpectInfoParams->pSpectCh[count].chNum))
1807 {
1808 continue; //skip this channel, continue to next channel
1809 }
Peng Xuafc34e32014-09-25 13:23:55 +05301810 if(bestChNum == SAP_CHANNEL_NOT_SELECTED)
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05301811 {
Peng Xuafc34e32014-09-25 13:23:55 +05301812 bestChNum = pSpectInfoParams->pSpectCh[count].chNum;
1813 /* check if bestChNum is in preferred channel list */
1814 bestChNum = sapSelectPreferredChannelFromChannelList(
1815 bestChNum, pSapCtx, pSpectInfoParams);
1816 if (bestChNum == SAP_CHANNEL_NOT_SELECTED)
1817 {
1818 /* not in preferred channel list, go to next best channel*/
1819 continue;
1820 }
1821
1822 if (pSpectInfoParams->pSpectCh[count].weight >
1823 pSapCtx->acsBandSwitchThreshold)
1824 {
1825 /* the best channel exceeds the threshold
1826 check if need to scan next band */
1827 if ((eCSR_BAND_ALL != pSapCtx->scanBandPreference) &&
1828 !pSapCtx->allBandScanned)
1829 {
1830 /* store best channel for later comparison */
1831 pSapCtx->acsBestChannelInfo.channelNum = bestChNum;
1832 pSapCtx->acsBestChannelInfo.weight =
1833 pSpectInfoParams->pSpectCh[count].weight;
1834 bestChNum = SAP_CHANNEL_NOT_SELECTED;
1835 break;
1836 }
1837 else
1838 {
1839 /* all bands are scanned, compare current best channel
1840 with channel scanned previously */
1841 if ( pSpectInfoParams->pSpectCh[count].weight >
1842 pSapCtx->acsBestChannelInfo.weight)
1843 {
1844 /* previous stored channel is better */
1845 bestChNum = pSapCtx->acsBestChannelInfo.channelNum;
1846 }
1847 else
1848 {
1849 pSapCtx->acsBestChannelInfo.channelNum = bestChNum;
1850 pSapCtx->acsBestChannelInfo.weight =
1851 pSpectInfoParams->pSpectCh[count].weight;
1852 }
1853 }
1854 }
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05301855 }
1856 else
1857 {
1858 if(operatingBand == RF_SUBBAND_2_4_GHZ)
1859 {
1860 /* Give preference to Non-overlap channels */
1861 if(((pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_1) ||
Peng Xuafc34e32014-09-25 13:23:55 +05301862 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_6) ||
1863 (pSpectInfoParams->pSpectCh[count].chNum == CHANNEL_11))&&
1864 (pSpectInfoParams->pSpectCh[count].weight ==
1865 pSapCtx->acsBestChannelInfo.weight))
1866 {
1867 tmpChNum = pSpectInfoParams->pSpectCh[count].chNum;
1868 tmpChNum =
1869 sapSelectPreferredChannelFromChannelList(tmpChNum,
1870 pSapCtx, pSpectInfoParams);
1871 if ( tmpChNum != SAP_CHANNEL_NOT_SELECTED)
1872 {
1873 bestChNum = tmpChNum;
1874 break;
1875 }
1876
1877 }
Bansidhar Gopalachari1e56faa2013-07-25 19:30:20 +05301878 }
1879 }
1880 }
1881 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001882#else
1883 // Get the first channel in sorted array as best 20M Channel
1884 bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[0].chNum;
Madan Mohan Koyyalamudi5aef2af2012-10-05 11:56:27 -07001885 //Select Best Channel from Channel List if Configured
Peng Xuafc34e32014-09-25 13:23:55 +05301886 bestChNum = sapSelectPreferredChannelFromChannelList(bestChNum,
1887 pSapCtx, pSpectInfoParams);
1888#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001889
1890 // Free all the allocated memory
1891 sapChanSelExit(pSpectInfoParams);
1892
1893 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 -07001894 __func__, bestChNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07001895 if (bestChNum > 0 && bestChNum <= 252)
1896 return bestChNum;
1897 else
1898 return SAP_CHANNEL_NOT_SELECTED;
1899}
Venkata Prathyusha Kuntupalli5c9e4e82013-04-15 13:10:09 -07001900