Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Jeff Johnson | 32d95a3 | 2012-09-10 13:15:23 -0700 | [diff] [blame] | 2 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /*=========================================================================== |
| 23 | |
| 24 | s a p C h S e l e c t . C |
| 25 | |
| 26 | OVERVIEW: |
| 27 | |
| 28 | This software unit holds the implementation of the WLAN SAP modules |
| 29 | functions for channel selection. |
| 30 | |
| 31 | DEPENDENCIES: |
| 32 | |
| 33 | Are listed for each API below. |
| 34 | |
| 35 | |
| 36 | Copyright (c) 2010 QUALCOMM Incorporated. |
| 37 | All Rights Reserved. |
| 38 | Qualcomm Confidential and Proprietary |
| 39 | ===========================================================================*/ |
| 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 | ---------- --- -------------------------------------------------------- |
| 53 | 2010-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" |
| 66 | |
| 67 | /*-------------------------------------------------------------------------- |
| 68 | Function definitions |
| 69 | --------------------------------------------------------------------------*/ |
| 70 | |
| 71 | /*-------------------------------------------------------------------------- |
| 72 | Defines |
| 73 | --------------------------------------------------------------------------*/ |
| 74 | #define SAP_DEBUG |
| 75 | |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 76 | |
| 77 | /*========================================================================== |
| 78 | FUNCTION sapCleanupChannelList |
| 79 | |
| 80 | DESCRIPTION |
| 81 | Function sapCleanupChannelList frees up the memory allocated to the channel list. |
| 82 | |
| 83 | DEPENDENCIES |
| 84 | NA. |
| 85 | |
| 86 | PARAMETERS |
| 87 | |
| 88 | IN |
| 89 | NULL |
| 90 | |
| 91 | RETURN VALUE |
| 92 | NULL |
| 93 | ============================================================================*/ |
| 94 | |
| 95 | void sapCleanupChannelList(void) |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 96 | { |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 97 | v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL); |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 98 | ptSapContext pSapCtx = VOS_GET_SAP_CB(pvosGCtx); |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 99 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 100 | VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO, |
| 101 | "Cleaning up the channel list structure"); |
| 102 | |
| 103 | pSapCtx->SapChnlList.numChannel =0; |
| 104 | vos_mem_free(pSapCtx->SapChnlList.channelList); |
| 105 | pSapCtx->SapChnlList.channelList = NULL; |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /*========================================================================== |
| 109 | FUNCTION sapSetPreferredChannel |
| 110 | |
| 111 | DESCRIPTION |
| 112 | Function sapSetPreferredChannel sets the channel list which has been configured |
| 113 | into sap context (pSapCtx) which will be used at the time of best channel selection. |
| 114 | |
| 115 | DEPENDENCIES |
| 116 | NA. |
| 117 | |
| 118 | PARAMETERS |
| 119 | |
| 120 | IN |
| 121 | *ptr: pointer having the command followed by the arguments in string format |
| 122 | *dev: not used. |
| 123 | |
| 124 | RETURN VALUE |
| 125 | int: return 0 when success else returns error code. |
| 126 | ============================================================================*/ |
| 127 | |
| 128 | int sapSetPreferredChannel(struct net_device *dev, tANI_U8* ptr) |
| 129 | { |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 130 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 131 | v_PVOID_t pvosGCtx = vos_get_global_context(VOS_MODULE_ID_SAP, NULL); |
| 132 | ptSapContext pSapCtx = VOS_GET_SAP_CB(pvosGCtx); |
| 133 | tANI_U8* param; |
| 134 | int tempInt; |
| 135 | int j; |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 136 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 137 | VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 138 | "Enter: %s", __func__); |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 139 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 140 | if (NULL != pSapCtx->SapChnlList.channelList) |
| 141 | { |
| 142 | sapCleanupChannelList(); |
| 143 | } |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 144 | |
Madan Mohan Koyyalamudi | d8ac866 | 2012-11-06 19:04:56 -0800 | [diff] [blame^] | 145 | param = strnchr(ptr, strlen(ptr), ' '); |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 146 | /*no argument after the command*/ |
| 147 | if (NULL == param) |
| 148 | { |
| 149 | return -EINVAL; |
| 150 | } |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 151 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 152 | /*no space after the command*/ |
| 153 | else if (SPACE_ASCII_VALUE != *param) |
| 154 | { |
| 155 | return -EINVAL; |
| 156 | } |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 157 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 158 | param++; |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 159 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 160 | /*removing empty spaces*/ |
| 161 | while((SPACE_ASCII_VALUE == *param)&& ('\0' != *param) ) param++; |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 162 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 163 | /*no argument followed by spaces*/ |
| 164 | if('\0' == *param) |
| 165 | { |
| 166 | return -EINVAL; |
| 167 | } |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 168 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 169 | /*getting the first argument ie the number of channels*/ |
| 170 | sscanf(param, "%d ", &tempInt); |
| 171 | pSapCtx->SapChnlList.numChannel = tempInt; |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 172 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 173 | VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, |
| 174 | "Number of channel added are: %d", |
| 175 | pSapCtx->SapChnlList.numChannel); |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 176 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 177 | /*allocating space for the desired number of channels*/ |
| 178 | pSapCtx->SapChnlList.channelList = |
| 179 | (v_U8_t *)vos_mem_malloc(pSapCtx->SapChnlList.numChannel); |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 180 | |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 181 | for(j=0;j<pSapCtx->SapChnlList.numChannel;j++) |
| 182 | { |
| 183 | |
| 184 | /*param pointing to the beginning of first space after number of channels*/ |
| 185 | param = strpbrk( param, " " ); |
| 186 | /*no channel list after the number of channels argument*/ |
| 187 | if (NULL == param) |
| 188 | { |
| 189 | sapCleanupChannelList(); |
| 190 | return -EINVAL; |
| 191 | } |
| 192 | |
| 193 | param++; |
| 194 | |
| 195 | /*removing empty space*/ |
| 196 | while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++; |
| 197 | |
| 198 | /*no channel list after the number of channels argument and spaces*/ |
| 199 | if( '\0' == *param ) |
| 200 | { |
| 201 | sapCleanupChannelList(); |
| 202 | return -EINVAL; |
| 203 | } |
| 204 | |
| 205 | sscanf(param, "%d ", &tempInt); |
| 206 | pSapCtx->SapChnlList.channelList[j] = tempInt; |
| 207 | |
| 208 | VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, |
| 209 | "Channel %d added to preferred channel list", |
| 210 | pSapCtx->SapChnlList.channelList[j] ); |
| 211 | |
| 212 | } |
| 213 | |
| 214 | /*extra arguments check*/ |
| 215 | param = strpbrk( param, " " ); |
| 216 | if (NULL != param) |
| 217 | { |
| 218 | while((SPACE_ASCII_VALUE == *param) && ('\0' != *param) ) param++; |
| 219 | |
| 220 | if('\0' != *param) |
| 221 | { |
| 222 | sapCleanupChannelList(); |
| 223 | return -EINVAL; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 228 | "Exit: %s", __func__); |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 229 | |
| 230 | return 0; |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /*========================================================================== |
| 234 | FUNCTION sapSelectPreferredChannelFromChannelList |
| 235 | |
| 236 | DESCRIPTION |
| 237 | Function sapSelectPreferredChannelFromChannelList calculates the best channel |
| 238 | among the configured channel list. If channel list not configured then returns |
| 239 | the best channel calculated among all the channel list. |
| 240 | |
| 241 | DEPENDENCIES |
| 242 | NA. |
| 243 | |
| 244 | PARAMETERS |
| 245 | |
| 246 | IN |
| 247 | *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure |
| 248 | bestChNum: best channel already calculated among all the chanels |
| 249 | pSapCtx: having info of channel list from which best channel is selected |
| 250 | |
| 251 | RETURN VALUE |
| 252 | v_U8_t: best channel |
| 253 | ============================================================================*/ |
| 254 | v_U8_t sapSelectPreferredChannelFromChannelList(v_U8_t bestChNum, |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 255 | ptSapContext pSapCtx, |
| 256 | tSapChSelSpectInfo *pSpectInfoParams) |
| 257 | { |
| 258 | v_U8_t j = 0; |
| 259 | v_U8_t count = 0; |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 260 | |
| 261 | //If Channel List is not Configured don't do anything |
| 262 | //Else return the Best Channel from the Channel List |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 263 | if((NULL == pSapCtx->SapChnlList.channelList) || |
| 264 | (NULL == pSpectInfoParams) || |
| 265 | (0 == pSapCtx->SapChnlList.numChannel)) |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 266 | { |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 267 | return bestChNum; |
| 268 | } |
| 269 | |
| 270 | if (bestChNum > 0 && bestChNum <= 252) |
| 271 | { |
| 272 | for(count=0; count < pSpectInfoParams->numSpectChans ; count++) |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 273 | { |
| 274 | bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum; |
| 275 | // Select the best channel from allowed list |
| 276 | for(j=0;j< pSapCtx->SapChnlList.numChannel;j++) |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 277 | { |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 278 | if( (pSapCtx->SapChnlList.channelList[j]) == bestChNum) |
| 279 | { |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 280 | VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, |
| 281 | "Best channel computed from Channel List is: %d", |
| 282 | bestChNum); |
| 283 | return bestChNum; |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | return SAP_CHANNEL_NOT_SELECTED; |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 289 | } |
| 290 | else |
| 291 | return SAP_CHANNEL_NOT_SELECTED; |
| 292 | } |
| 293 | |
| 294 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 295 | /*========================================================================== |
| 296 | FUNCTION sapChanSelInit |
| 297 | |
| 298 | DESCRIPTION |
| 299 | Function sapChanSelInit allocates the memory, intializes the |
| 300 | structures used by the channel selection algorithm |
| 301 | |
| 302 | DEPENDENCIES |
| 303 | NA. |
| 304 | |
| 305 | PARAMETERS |
| 306 | |
| 307 | IN |
| 308 | *pSpectInfoParams : Pointer to tSapChSelSpectInfo structure |
| 309 | |
| 310 | RETURN VALUE |
| 311 | v_BOOL_t: Success or FAIL |
| 312 | |
| 313 | SIDE EFFECTS |
| 314 | ============================================================================*/ |
| 315 | v_BOOL_t sapChanSelInit(tHalHandle halHandle, tSapChSelSpectInfo *pSpectInfoParams) |
| 316 | { |
| 317 | tSapSpectChInfo *pSpectCh = NULL; |
| 318 | v_U8_t *pChans = NULL; |
| 319 | v_U16_t channelnum = 0; |
| 320 | tpAniSirGlobal pMac = PMAC_STRUCT(halHandle); |
| 321 | |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 322 | VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 323 | |
| 324 | // Channels for that 2.4GHz band |
| 325 | //Considered only for 2.4GHz need to change in future to support 5GHz support |
| 326 | pSpectInfoParams->numSpectChans = pMac->scan.base20MHzChannels.numChannels; |
| 327 | |
| 328 | // Allocate memory for weight computation of 2.4GHz |
| 329 | pSpectCh = (tSapSpectChInfo *)vos_mem_malloc((pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh)); |
| 330 | |
| 331 | if(pSpectCh == NULL) { |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 332 | VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, VOS_MALLOC_ERR", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 333 | return eSAP_FALSE; |
| 334 | } |
| 335 | |
| 336 | vos_mem_zero(pSpectCh, (pSpectInfoParams->numSpectChans) * sizeof(*pSpectCh)); |
| 337 | |
| 338 | // Initialize the pointers in the DfsParams to the allocated memory |
| 339 | pSpectInfoParams->pSpectCh = pSpectCh; |
| 340 | |
| 341 | pChans = pMac->scan.base20MHzChannels.channelList; |
| 342 | |
| 343 | // Fill the channel number in the spectrum in the operating freq band |
| 344 | for (channelnum = 0; channelnum < pSpectInfoParams->numSpectChans; channelnum++) { |
| 345 | |
| 346 | if(*pChans == 14 ) //OFDM rates are not supported on channel 14 |
| 347 | continue; |
| 348 | pSpectCh->chNum = *pChans; |
| 349 | pSpectCh->valid = eSAP_TRUE; |
| 350 | pSpectCh->rssiAgr = SOFTAP_MIN_RSSI;// Initialise for all channels |
| 351 | pSpectCh++; |
| 352 | pChans++; |
| 353 | } |
| 354 | return eSAP_TRUE; |
| 355 | } |
| 356 | |
| 357 | /*========================================================================== |
| 358 | FUNCTION sapweightRssiCount |
| 359 | |
| 360 | DESCRIPTION |
| 361 | Function weightRssiCount calculates the channel weight due to rssi |
| 362 | and data count(here number of BSS observed) |
| 363 | |
| 364 | DEPENDENCIES |
| 365 | NA. |
| 366 | |
| 367 | PARAMETERS |
| 368 | |
| 369 | IN |
| 370 | rssi : Max signal strength receieved from a BSS for the channel |
| 371 | count : Number of BSS observed in the channel |
| 372 | |
| 373 | RETURN VALUE |
| 374 | v_U32_t : Calculated channel weight based on above two |
| 375 | |
| 376 | SIDE EFFECTS |
| 377 | ============================================================================*/ |
| 378 | v_U32_t sapweightRssiCount(v_S7_t rssi, v_U16_t count) |
| 379 | { |
| 380 | v_S31_t rssiWeight=0; |
| 381 | v_S31_t countWeight=0; |
| 382 | v_U32_t rssicountWeight=0; |
| 383 | |
| 384 | // Weight from RSSI |
| 385 | rssiWeight = SOFTAP_RSSI_WEIGHT * (rssi - SOFTAP_MIN_RSSI) |
| 386 | /(SOFTAP_MAX_RSSI - SOFTAP_MIN_RSSI); |
| 387 | |
| 388 | if(rssiWeight > SOFTAP_RSSI_WEIGHT) |
| 389 | rssiWeight = SOFTAP_RSSI_WEIGHT; |
| 390 | else if (rssiWeight < 0) |
| 391 | rssiWeight = 0; |
| 392 | |
| 393 | // Weight from data count |
| 394 | countWeight = SOFTAP_COUNT_WEIGHT * (count - SOFTAP_MIN_COUNT) |
| 395 | /(SOFTAP_MAX_COUNT - SOFTAP_MIN_COUNT); |
| 396 | |
| 397 | if(countWeight > SOFTAP_COUNT_WEIGHT) |
| 398 | countWeight = SOFTAP_COUNT_WEIGHT; |
| 399 | else if (countWeight < 0) |
| 400 | countWeight = 0; |
| 401 | |
| 402 | rssicountWeight = rssiWeight + countWeight; |
| 403 | |
| 404 | VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, rssiWeight=%d, countWeight=%d, rssicountWeight=%d", |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 405 | __func__, rssiWeight, countWeight, rssicountWeight); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 406 | |
| 407 | return(rssicountWeight); |
| 408 | } |
| 409 | |
| 410 | /*========================================================================== |
| 411 | FUNCTION sapComputeSpectWeight |
| 412 | |
| 413 | DESCRIPTION |
| 414 | Main function for computing the weight of each channel in the |
| 415 | spectrum based on the RSSI value of the BSSes on the channel |
| 416 | and number of BSS |
| 417 | |
| 418 | DEPENDENCIES |
| 419 | NA. |
| 420 | |
| 421 | PARAMETERS |
| 422 | |
| 423 | IN |
| 424 | pSpectInfoParams : Pointer to the tSpectInfoParams structure |
| 425 | halHandle : Pointer to HAL handle |
| 426 | pResult : Pointer to tScanResultHandle |
| 427 | |
| 428 | RETURN VALUE |
| 429 | void : NULL |
| 430 | |
| 431 | SIDE EFFECTS |
| 432 | ============================================================================*/ |
| 433 | void sapComputeSpectWeight( tSapChSelSpectInfo* pSpectInfoParams, |
| 434 | tHalHandle halHandle, tScanResultHandle pResult) |
| 435 | { |
| 436 | v_S7_t rssi = 0; |
| 437 | v_U8_t chn_num = 0; |
| 438 | v_U8_t channel_id = 0; |
| 439 | |
| 440 | tCsrScanResultInfo *pScanResult; |
| 441 | tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh; |
| 442 | |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 443 | VOS_TRACE( VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Computing spectral weight", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 444 | |
| 445 | /** |
| 446 | * Soft AP specific channel weight calculation using DFS formula |
| 447 | */ |
| 448 | |
| 449 | pScanResult = sme_ScanResultGetFirst(halHandle, pResult); |
| 450 | |
| 451 | while (pScanResult) { |
| 452 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 453 | // Processing for each tCsrScanResultInfo in the tCsrScanResult DLink list |
| 454 | for (chn_num = 0; chn_num < pSpectInfoParams->numSpectChans; chn_num++) { |
| 455 | |
| 456 | /* |
| 457 | * if the Beacon has channel ID, use it other wise we will |
| 458 | * rely on the channelIdSelf |
| 459 | */ |
| 460 | if(pScanResult->BssDescriptor.channelId == 0) |
| 461 | channel_id = pScanResult->BssDescriptor.channelIdSelf; |
| 462 | else |
| 463 | channel_id = pScanResult->BssDescriptor.channelId; |
| 464 | |
| 465 | if (channel_id == pSpectCh->chNum) { |
| 466 | if (pSpectCh->rssiAgr < pScanResult->BssDescriptor.rssi) |
| 467 | pSpectCh->rssiAgr = pScanResult->BssDescriptor.rssi; |
| 468 | |
| 469 | ++pSpectCh->bssCount; // Increment the count of BSS |
| 470 | |
| 471 | VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, |
| 472 | "In %s, bssdes.ch_self=%d, bssdes.ch_ID=%d, bssdes.rssi=%d, SpectCh.bssCount=%d, pScanResult=0x%x", |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 473 | __func__, pScanResult->BssDescriptor.channelIdSelf, pScanResult->BssDescriptor.channelId, |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 474 | pScanResult->BssDescriptor.rssi, pSpectCh->bssCount, pScanResult); |
| 475 | |
| 476 | pSpectCh++; |
| 477 | break; |
| 478 | } else { |
| 479 | pSpectCh++; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | pScanResult = sme_ScanResultGetNext(halHandle, pResult); |
| 484 | } |
| 485 | |
| 486 | // Calculate the weights for all channels in the spectrum pSpectCh |
| 487 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 488 | |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 489 | VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Spectrum Channels Weight", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 490 | |
| 491 | for (chn_num = 0; chn_num < (pSpectInfoParams->numSpectChans); chn_num++) { |
| 492 | |
| 493 | /* |
| 494 | rssi : Maximum received signal strength among all BSS on that channel |
| 495 | bssCount : Number of BSS on that channel |
| 496 | */ |
| 497 | |
| 498 | rssi = (v_S7_t)pSpectCh->rssiAgr; |
| 499 | |
| 500 | pSpectCh->weight = SAPDFS_NORMALISE_1000 * sapweightRssiCount(rssi, pSpectCh->bssCount); |
| 501 | |
| 502 | //------ Debug Info ------ |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 503 | VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Chan=%d Weight= %d rssiAgr=%d bssCount=%d", __func__, pSpectCh->chNum, |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 504 | pSpectCh->weight, pSpectCh->rssiAgr, pSpectCh->bssCount); |
| 505 | //------ Debug Info ------ |
| 506 | pSpectCh++; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | /*========================================================================== |
| 511 | FUNCTION sapChanSelExit |
| 512 | |
| 513 | DESCRIPTION |
| 514 | Exit function for free out the allocated memory, to be called |
| 515 | at the end of the dfsSelectChannel function |
| 516 | |
| 517 | DEPENDENCIES |
| 518 | NA. |
| 519 | |
| 520 | PARAMETERS |
| 521 | |
| 522 | IN |
| 523 | pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure |
| 524 | |
| 525 | RETURN VALUE |
| 526 | void : NULL |
| 527 | |
| 528 | SIDE EFFECTS |
| 529 | ============================================================================*/ |
| 530 | void sapChanSelExit( tSapChSelSpectInfo *pSpectInfoParams ) |
| 531 | { |
| 532 | // Free all the allocated memory |
| 533 | vos_mem_free(pSpectInfoParams->pSpectCh); |
| 534 | } |
| 535 | |
| 536 | /*========================================================================== |
| 537 | FUNCTION sapSortChlWeight |
| 538 | |
| 539 | DESCRIPTION |
| 540 | Funtion to sort the channels with the least weight first |
| 541 | |
| 542 | DEPENDENCIES |
| 543 | NA. |
| 544 | |
| 545 | PARAMETERS |
| 546 | |
| 547 | IN |
| 548 | pSpectInfoParams : Pointer to the tSapChSelSpectInfo structure |
| 549 | |
| 550 | RETURN VALUE |
| 551 | void : NULL |
| 552 | |
| 553 | SIDE EFFECTS |
| 554 | ============================================================================*/ |
| 555 | void sapSortChlWeight(tSapChSelSpectInfo *pSpectInfoParams) |
| 556 | { |
| 557 | tSapSpectChInfo temp; |
| 558 | |
| 559 | tSapSpectChInfo *pSpectCh = NULL; |
| 560 | v_U32_t i = 0, j = 0, minWeightIndex = 0; |
| 561 | |
| 562 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 563 | #ifdef SOFTAP_CHANNEL_RANGE |
| 564 | // Sorting the channels as per weights |
| 565 | for (i = 0; i < pSpectInfoParams->numSpectChans; i++) { |
| 566 | minWeightIndex = i; |
| 567 | for( j = i + 1; j < pSpectInfoParams->numSpectChans; j++) { |
| 568 | if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) { |
| 569 | minWeightIndex = j; |
| 570 | } |
| 571 | } |
| 572 | if(minWeightIndex != i) { |
| 573 | vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh)); |
| 574 | vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh)); |
| 575 | vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh)); |
| 576 | } |
| 577 | } |
| 578 | #else |
| 579 | // Sorting the channels as per weights |
| 580 | for (i = 0; i < SPECT_24GHZ_CH_COUNT; i++) { |
| 581 | minWeightIndex = i; |
| 582 | for( j = i + 1; j < SPECT_24GHZ_CH_COUNT; j++) { |
| 583 | if(pSpectCh[j].weight < pSpectCh[minWeightIndex].weight) { |
| 584 | minWeightIndex = j; |
| 585 | } |
| 586 | } |
| 587 | if(minWeightIndex != i) { |
| 588 | vos_mem_copy(&temp, &pSpectCh[minWeightIndex], sizeof(*pSpectCh)); |
| 589 | vos_mem_copy(&pSpectCh[minWeightIndex], &pSpectCh[i], sizeof(*pSpectCh)); |
| 590 | vos_mem_copy(&pSpectCh[i], &temp, sizeof(*pSpectCh)); |
| 591 | } |
| 592 | } |
| 593 | #endif |
| 594 | |
| 595 | /* For testing */ |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 596 | VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Sorted Spectrum Channels Weight", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 597 | pSpectCh = pSpectInfoParams->pSpectCh; |
| 598 | for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) { |
| 599 | VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d", |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 600 | __func__, pSpectCh->chNum, pSpectCh->weight, pSpectCh->rssiAgr, pSpectCh->bssCount); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 601 | pSpectCh++; |
| 602 | } |
| 603 | |
| 604 | } |
| 605 | |
| 606 | /*========================================================================== |
| 607 | FUNCTION sapSelectChannel |
| 608 | |
| 609 | DESCRIPTION |
| 610 | Runs a algorithm to select the best channel to operate in based on BSS |
| 611 | rssi and bss count on each channel |
| 612 | |
| 613 | DEPENDENCIES |
| 614 | NA. |
| 615 | |
| 616 | PARAMETERS |
| 617 | |
| 618 | IN |
| 619 | halHandle : Pointer to HAL handle |
| 620 | pResult : Pointer to tScanResultHandle |
| 621 | |
| 622 | RETURN VALUE |
| 623 | v_U8_t : Success - channel number, Fail - zero |
| 624 | |
| 625 | SIDE EFFECTS |
| 626 | ============================================================================*/ |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 627 | v_U8_t sapSelectChannel(tHalHandle halHandle, ptSapContext pSapCtx, tScanResultHandle pScanResult) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 628 | { |
| 629 | // DFS param object holding all the data req by the algo |
| 630 | tSapChSelSpectInfo oSpectInfoParams = {NULL,0}; |
| 631 | tSapChSelSpectInfo *pSpectInfoParams = &oSpectInfoParams; // Memory? NB |
| 632 | |
| 633 | v_U8_t bestChNum = 0; |
| 634 | #ifdef SOFTAP_CHANNEL_RANGE |
| 635 | v_U32_t startChannelNum; |
| 636 | v_U32_t endChannelNum; |
| 637 | v_U32_t operatingBand; |
| 638 | v_U8_t count = 0; |
| 639 | #endif |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 640 | VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Running SAP Ch Select", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 641 | |
| 642 | // Set to zero tSapChSelParams |
| 643 | //vos_mem_zero(&sapChSelParams, sizeof(sapChSelParams)); |
| 644 | |
| 645 | // Initialize the structure pointed by pSpectInfoParams |
| 646 | if(sapChanSelInit( halHandle, pSpectInfoParams) != eSAP_TRUE ) { |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 647 | VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR, "In %s, Ch Select initialization failed", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 648 | return SAP_CHANNEL_NOT_SELECTED; |
| 649 | } |
| 650 | |
| 651 | // Compute the weight of the entire spectrum in the operating band |
| 652 | sapComputeSpectWeight( pSpectInfoParams, halHandle, pScanResult); |
| 653 | |
| 654 | // Sort the 20M channel list as per the computed weights, lesser weight first. |
| 655 | sapSortChlWeight(pSpectInfoParams); |
| 656 | |
| 657 | #ifdef SOFTAP_CHANNEL_RANGE |
| 658 | ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_START_CHANNEL, &startChannelNum); |
| 659 | ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_END_CHANNEL, &endChannelNum); |
| 660 | ccmCfgGetInt( halHandle, WNI_CFG_SAP_CHANNEL_SELECT_OPERATING_BAND, &operatingBand); |
| 661 | |
| 662 | /*Loop till get the best channel in the given range */ |
| 663 | for(count=0; count < pSpectInfoParams->numSpectChans ; count++) |
| 664 | { |
| 665 | if((startChannelNum <= pSpectInfoParams->pSpectCh[count].chNum)&& |
| 666 | ( endChannelNum >= pSpectInfoParams->pSpectCh[count].chNum)) |
| 667 | { |
| 668 | bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[count].chNum; |
| 669 | break; |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | #else |
| 674 | // Get the first channel in sorted array as best 20M Channel |
| 675 | bestChNum = (v_U8_t)pSpectInfoParams->pSpectCh[0].chNum; |
| 676 | |
| 677 | #endif |
Madan Mohan Koyyalamudi | 5aef2af | 2012-10-05 11:56:27 -0700 | [diff] [blame] | 678 | |
| 679 | //Select Best Channel from Channel List if Configured |
Madan Mohan Koyyalamudi | 1bed598 | 2012-10-22 14:38:06 -0700 | [diff] [blame] | 680 | bestChNum = sapSelectPreferredChannelFromChannelList(bestChNum, pSapCtx, pSpectInfoParams); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 681 | |
| 682 | // Free all the allocated memory |
| 683 | sapChanSelExit(pSpectInfoParams); |
| 684 | |
| 685 | VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_INFO_HIGH, "In %s, Running SAP Ch select Completed, Ch=%d", |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 686 | __func__, bestChNum); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 687 | |
| 688 | if (bestChNum > 0 && bestChNum <= 252) |
| 689 | return bestChNum; |
| 690 | else |
| 691 | return SAP_CHANNEL_NOT_SELECTED; |
| 692 | } |