1/* 2 * PowerMgr.c 3 * 4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name Texas Instruments nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34/** \file PowerMgr.c 35 * \brief This is the PowerMgr module implementation. 36 * \ 37 * \date 24-Oct-2005 38 */ 39 40/**************************************************************************** 41 * * 42 * MODULE: PowerMgr * 43 * PURPOSE: PowerMgr Module implementation. * 44 * * 45 ****************************************************************************/ 46 47#define __FILE_ID__ FILE_ID_71 48#include "tidef.h" 49#include "osApi.h" 50#include "timer.h" 51#include "paramOut.h" 52#include "report.h" 53#include "PowerMgr.h" 54#include "PowerMgr_API.h" 55#include "TrafficMonitorAPI.h" 56#include "qosMngr_API.h" 57#include "siteMgrApi.h" 58#include "TWDriver.h" 59#include "SoftGeminiApi.h" 60#include "DrvMainModules.h" 61#include "PowerMgrKeepAlive.h" 62#include "CmdBld.h" 63 64 65/***************************************************************************** 66 ** Defines ** 67 *****************************************************************************/ 68#define DEFAULT_LISTEN_INTERVAL (1) 69#define BET_DISABLE 0 70#define BET_ENABLE 1 71 72 73/***************************************************************************** 74 ** Private Function prototypes ** 75 *****************************************************************************/ 76 77static void powerSaveCompleteCB(TI_HANDLE hPowerMgr,TI_UINT8 PSMode,TI_UINT8 transStatus); 78static void PowerMgrTMThresholdCrossCB( TI_HANDLE hPowerMgr, TI_UINT32 cookie ); 79static void powerMgrDisableThresholdsIndications(TI_HANDLE hPowerMgr); 80static void powerMgrEnableThresholdsIndications(TI_HANDLE hPowerMgr); 81static void powerMgrStartAutoPowerMode(TI_HANDLE hPowerMgr); 82static void powerMgrRetryPsTimeout(TI_HANDLE hPowerMgr, TI_BOOL bTwdInitOccured); 83static void powerMgrPowerProfileConfiguration(TI_HANDLE hPowerMgr, PowerMgr_PowerMode_e desiredPowerMode); 84static void PowerMgr_setDozeModeInAuto(TI_HANDLE hPowerMgr,PowerMgr_PowerMode_e dozeMode); 85static void PowerMgrConfigBetToFw( TI_HANDLE hPowerMgr, TI_UINT32 cookie ); 86static void PowerMgr_PsPollFailureCB( TI_HANDLE hPowerMgr ); 87static void powerMgr_PsPollFailureTimeout( TI_HANDLE hPowerMgr, TI_BOOL bTwdInitOccured ); 88static void powerMgr_SGSetUserDesiredwakeUpCond( TI_HANDLE hPowerMgr ); 89static TI_STATUS powerMgrSendMBXWakeUpConditions(TI_HANDLE hPowerMgr,TI_UINT8 listenInterval, ETnetWakeOn tnetWakeupOn); 90static TI_STATUS powerMgrNullPacketRateConfiguration(TI_HANDLE hPowerMgr); 91static PowerMgr_PowerMode_e powerMgrGetHighestPriority(TI_HANDLE hPowerMgr); 92 93 94/***************************************************************************** 95 ** Public Function prototypes ** 96 *****************************************************************************/ 97 98 99/**************************************************************************************** 100 * PowerMgr_create * 101 **************************************************************************************** 102DESCRIPTION: Creates the object of the power Manager. 103 performs the following: 104 - Allocate the Power Manager handle 105 - Creates the retry timer 106 107INPUT: - hOs - Handle to OS 108OUTPUT: 109RETURN: Handle to the Power Manager module on success, NULL otherwise 110****************************************************************************************/ 111TI_HANDLE PowerMgr_create(TI_HANDLE hOs) 112{ 113 114 PowerMgr_t * pPowerMgr = NULL; 115 pPowerMgr = (PowerMgr_t*) os_memoryAlloc (hOs, sizeof(PowerMgr_t)); 116 if ( pPowerMgr == NULL ) 117 { 118 WLAN_OS_REPORT(("PowerMgr_create - Memory Allocation Error!\n")); 119 return NULL; 120 } 121 122 os_memoryZero (hOs, pPowerMgr, sizeof(PowerMgr_t)); 123 124 pPowerMgr->hOS = hOs; 125 126 /* create the power manager keep-alive sub module */ 127 pPowerMgr->hPowerMgrKeepAlive = powerMgrKL_create (hOs); 128 129 return pPowerMgr; 130 131} 132 133 134/**************************************************************************************** 135* powerSrv_destroy * 136**************************************************************************************** 137DESCRIPTION: Destroy the object of the power Manager. 138 - delete Power Manager alocation 139 - call the destroy function of the timer 140 141INPUT: - hPowerMgr - Handle to the Power Manager 142OUTPUT: 143RETURN: TI_STATUS - TI_OK on success else TI_NOK. 144****************************************************************************************/ 145TI_STATUS PowerMgr_destroy(TI_HANDLE hPowerMgr) 146{ 147 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 148 149 /* destroy the power manager keep-alive sub module */ 150 powerMgrKL_destroy (pPowerMgr->hPowerMgrKeepAlive); 151 152 if (pPowerMgr->hRetryPsTimer) 153 { 154 tmr_DestroyTimer (pPowerMgr->hRetryPsTimer); 155 } 156 157 if ( pPowerMgr->hPsPollFailureTimer != NULL ) 158 { 159 tmr_DestroyTimer(pPowerMgr->hPsPollFailureTimer); 160 } 161 os_memoryFree(pPowerMgr->hOS, pPowerMgr, sizeof(PowerMgr_t)); 162 163 return TI_OK; 164} 165 166 167/**************************************************************************************** 168* PowerMgr_init * 169**************************************************************************************** 170DESCRIPTION: Power Manager init function, called in init phase. 171 172INPUT: pStadHandles - The driver modules handles 173 174OUTPUT: 175 176RETURN: void 177****************************************************************************************/ 178void PowerMgr_init (TStadHandlesList *pStadHandles) 179{ 180 PowerMgr_t *pPowerMgr = (PowerMgr_t*)(pStadHandles->hPowerMgr); 181 182 pPowerMgr->hReport = pStadHandles->hReport; 183 pPowerMgr->hTrafficMonitor = pStadHandles->hTrafficMon; 184 pPowerMgr->hSiteMgr = pStadHandles->hSiteMgr; 185 pPowerMgr->hTWD = pStadHandles->hTWD; 186 pPowerMgr->hSoftGemini = pStadHandles->hSoftGemini; 187 pPowerMgr->hTimer = pStadHandles->hTimer; 188 pPowerMgr->psEnable = TI_FALSE; 189 190 /* initialize the power manager keep-alive sub module */ 191 powerMgrKL_init (pPowerMgr->hPowerMgrKeepAlive, pStadHandles); 192 193} 194 195 196TI_STATUS PowerMgr_SetDefaults (TI_HANDLE hPowerMgr, PowerMgrInitParams_t* pPowerMgrInitParams) 197{ 198 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 199 TI_UINT8 index; 200 /* used to initialize the Traffic Monitor for Auto Ps events */ 201 TrafficAlertRegParm_t tmRegParam; 202 TI_STATUS status; 203 204 pPowerMgr->reAuthActivePriority = pPowerMgrInitParams->reAuthActivePriority; 205 206 /* init power management options */ 207 pPowerMgr->beaconListenInterval = pPowerMgrInitParams->beaconListenInterval; 208 pPowerMgr->dtimListenInterval = pPowerMgrInitParams->dtimListenInterval; 209 pPowerMgr->defaultPowerLevel = pPowerMgrInitParams->defaultPowerLevel; 210 pPowerMgr->PowerSavePowerLevel = pPowerMgrInitParams->PowerSavePowerLevel; 211 pPowerMgr->powerMngPriority = POWER_MANAGER_USER_PRIORITY; 212 pPowerMgr->maxFullBeaconInterval = pPowerMgrInitParams->MaximalFullBeaconReceptionInterval; 213 pPowerMgr->PsPollDeliveryFailureRecoveryPeriod = pPowerMgrInitParams->PsPollDeliveryFailureRecoveryPeriod; 214 215 /* 216 set AUTO PS parameters 217 */ 218 pPowerMgr->autoModeInterval = pPowerMgrInitParams->autoModeInterval; 219 pPowerMgr->autoModeActiveTH = pPowerMgrInitParams->autoModeActiveTH; 220 pPowerMgr->autoModeDozeTH = pPowerMgrInitParams->autoModeDozeTH; 221 pPowerMgr->autoModeDozeMode = pPowerMgrInitParams->autoModeDozeMode; 222 223 /* 224 register threshold in the traffic monitor. 225 */ 226 pPowerMgr->betEnable = pPowerMgrInitParams->BetEnable; /* save BET enable flag for CLI configuration */ 227 pPowerMgr->betTrafficEnable = TI_FALSE; /* starting without BET */ 228 229 /* BET thresholds */ 230 /* general parameters */ 231 tmRegParam.Context = pPowerMgr; 232 tmRegParam.TimeIntervalMs = BET_INTERVAL_VALUE; 233 tmRegParam.Trigger = TRAFF_EDGE; 234 tmRegParam.MonitorType = TX_RX_ALL_802_11_DATA_FRAMES; 235 tmRegParam.CallBack = PowerMgrConfigBetToFw; 236 237 /* BET enable event */ 238 tmRegParam.Direction = TRAFF_DOWN; 239 tmRegParam.Threshold = pPowerMgrInitParams->BetEnableThreshold; 240 pPowerMgr->BetEnableThreshold = pPowerMgrInitParams->BetEnableThreshold; 241 tmRegParam.Cookie = (TI_UINT32)BET_ENABLE; 242 pPowerMgr->betEnableTMEvent = TrafficMonitor_RegEvent (pPowerMgr->hTrafficMonitor, 243 &tmRegParam, 244 TI_FALSE); 245 /* BET disable event */ 246 tmRegParam.Direction = TRAFF_UP; 247 tmRegParam.Threshold = pPowerMgrInitParams->BetDisableThreshold; 248 pPowerMgr->BetDisableThreshold = pPowerMgrInitParams->BetDisableThreshold; 249 tmRegParam.Cookie = (TI_UINT32)BET_DISABLE; 250 pPowerMgr->betDisableTMEvent = TrafficMonitor_RegEvent (pPowerMgr->hTrafficMonitor, 251 &tmRegParam, 252 TI_FALSE); 253 254 if ( (pPowerMgr->betDisableTMEvent == NULL) || 255 (pPowerMgr->betEnableTMEvent == NULL)) 256 { 257 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INIT, "PowerMgr_init - TM - ERROR registering BET events - ABROTING init!\n"); 258 return TI_NOK; 259 } 260 /* 261 set the events as resets for one another 262 */ 263 status = TrafficMonitor_SetRstCondition (pPowerMgr->hTrafficMonitor, 264 pPowerMgr->betDisableTMEvent, 265 pPowerMgr->betEnableTMEvent, 266 TI_TRUE); 267 if ( status != TI_OK ) 268 { 269 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INIT, "PowerMgr_init - PowerMgr_init - ERROR binding BET events - ABROTING init!\n"); 270 return TI_NOK; 271 } 272 273 /* general parameters */ 274 tmRegParam.Context = pPowerMgr; 275 276 tmRegParam.Cookie = (TI_UINT32)POWER_MODE_ACTIVE; 277 tmRegParam.TimeIntervalMs = pPowerMgr->autoModeInterval; 278 tmRegParam.Trigger = TRAFF_EDGE; 279 tmRegParam.MonitorType = TX_RX_ALL_802_11_DATA_FRAMES; 280 281 /* Active threshold */ 282 tmRegParam.CallBack = PowerMgrTMThresholdCrossCB; 283 tmRegParam.Direction = TRAFF_UP; 284 tmRegParam.Threshold = pPowerMgr->autoModeActiveTH; 285 pPowerMgr->passToActiveTMEvent = TrafficMonitor_RegEvent (pPowerMgr->hTrafficMonitor, 286 &tmRegParam, 287 TI_FALSE); 288 /* Doze threshold */ 289 tmRegParam.Direction = TRAFF_DOWN; 290 tmRegParam.Threshold = pPowerMgr->autoModeDozeTH; 291 tmRegParam.Cookie = (TI_UINT32)POWER_MODE_SHORT_DOZE; /* diffrentiation between long / short doze is done at the 292 CB, according to configuration at time of CB invokation */ 293 pPowerMgr->passToDozeTMEvent = TrafficMonitor_RegEvent (pPowerMgr->hTrafficMonitor, 294 &tmRegParam, 295 TI_FALSE); 296 297 if ( (pPowerMgr->passToActiveTMEvent == NULL) || 298 (pPowerMgr->passToDozeTMEvent == NULL)) 299 { 300 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INIT, "PowerMgr_init - PowerMgr_init - ERROR registering Auto mode events - ABROTING init!\n"); 301 return TI_NOK; 302 } 303 304 /* 305 set the events as resets for one another 306 */ 307 status = TrafficMonitor_SetRstCondition (pPowerMgr->hTrafficMonitor, 308 pPowerMgr->passToActiveTMEvent, 309 pPowerMgr->passToDozeTMEvent, 310 TI_TRUE); 311 if ( status != TI_OK ) 312 { 313 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INIT, "PowerMgr_init - PowerMgr_init - ERROR binding Auto mode events - ABROTING init!\n"); 314 return TI_NOK; 315 } 316 317 /* 318 configure the initialize power mode 319 */ 320 pPowerMgr->desiredPowerModeProfile = pPowerMgrInitParams->powerMode; 321 for ( index = 0;index < POWER_MANAGER_MAX_PRIORITY;index++ ) 322 { 323 pPowerMgr->powerMngModePriority[index].powerMode = pPowerMgr->desiredPowerModeProfile; 324 pPowerMgr->powerMngModePriority[index].priorityEnable = TI_FALSE; 325 } 326 pPowerMgr->powerMngModePriority[POWER_MANAGER_USER_PRIORITY].priorityEnable = TI_TRUE; 327 328 if (pPowerMgr->reAuthActivePriority) 329 pPowerMgr->powerMngModePriority[POWER_MANAGER_REAUTH_PRIORITY].powerMode = POWER_MODE_ACTIVE; 330 331 /* set the defualt power policy */ 332 TWD_CfgSleepAuth (pPowerMgr->hTWD, pPowerMgr->defaultPowerLevel); 333 334 335 /*create the timers */ 336 pPowerMgr->hRetryPsTimer = tmr_CreateTimer(pPowerMgr->hTimer); 337 338 pPowerMgr->hPsPollFailureTimer = tmr_CreateTimer(pPowerMgr->hTimer); 339 340 if ( (pPowerMgr->hPsPollFailureTimer == NULL) || (pPowerMgr->hRetryPsTimer == NULL)) 341 { 342TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INIT, "PowerMgr_SetDefaults - ERROR creating timers - ABROTING init!\n"); 343 return TI_NOK; 344 } 345 346 /* Register and Enable the PsPoll failure */ 347 TWD_RegisterEvent (pPowerMgr->hTWD, 348 TWD_OWN_EVENT_PSPOLL_DELIVERY_FAILURE, 349 (void *)PowerMgr_PsPollFailureCB, 350 hPowerMgr); 351 TWD_EnableEvent (pPowerMgr->hTWD, TWD_OWN_EVENT_PSPOLL_DELIVERY_FAILURE); 352 353 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INIT, "PowerMgr_init - PowerMgr Initialized\n"); 354 355 /* set defaults for the power manager keep-alive sub module */ 356 powerMgrKL_setDefaults (pPowerMgr->hPowerMgrKeepAlive); 357 358 return TI_OK; 359} 360 361/**************************************************************************************** 362 * PowerMgr_startPS * 363 **************************************************************************************** 364DESCRIPTION: Start the power save algorithm of the driver and also the 802.11 PS. 365 366INPUT: - hPowerMgr - Handle to the Power Manager 367 368OUTPUT: 369RETURN: TI_STATUS - TI_OK or PENDING on success else TI_NOK.\n 370****************************************************************************************/ 371TI_STATUS PowerMgr_startPS(TI_HANDLE hPowerMgr) 372{ 373 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 374 int frameCount; 375 376 377 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgr_startPS - called\n"); 378 379 if ( pPowerMgr->psEnable == TI_TRUE ) 380 { 381 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgr_startPS - PS mechanism is already Enable! Aborting psEnable=%d !\n", pPowerMgr->psEnable); 382 /* 383 this is a FATAL ERROR of the power manager! 384 already enable power-save! thus return TI_OK, but there is an error in the upper 385 layer that call tp PowerMgr_startPS() twice - should know that power-save 386 is already enable therefor print the Error message. 387 or 388 the state machine while NOT in PS can be only in ACTIVE state and in some cases in 389 PS_PENDING state. therefore the state machine is out of sync from it logic! 390 */ 391 return TI_OK; 392 } 393 394 pPowerMgr->psEnable = TI_TRUE; 395 /*set the correct rate after connection*/ 396 powerMgrNullPacketRateConfiguration(hPowerMgr); 397 /* 398 if in auto mode then need to refer to the threshold cross indication from the traffic monitor, 399 else it need to refer to the configured power mode profile from the user. 400 */ 401 pPowerMgr->desiredPowerModeProfile = powerMgrGetHighestPriority(hPowerMgr); 402 403 if ( pPowerMgr->desiredPowerModeProfile == POWER_MODE_AUTO ) 404 { 405 powerMgrStartAutoPowerMode(hPowerMgr); 406 } 407 else /*not auto mode - according to the current profle*/ 408 { 409 powerMgrPowerProfileConfiguration(hPowerMgr, pPowerMgr->desiredPowerModeProfile); 410 } 411 412 TWD_CfgSleepAuth (pPowerMgr->hTWD, pPowerMgr->PowerSavePowerLevel); 413 414 if ((pPowerMgr->betEnable)&&( pPowerMgr->desiredPowerModeProfile != POWER_MODE_ACTIVE )) 415 { 416 TrafficMonitor_StartEventNotif(pPowerMgr->hTrafficMonitor, 417 pPowerMgr->betEnableTMEvent); 418 419 TrafficMonitor_StartEventNotif(pPowerMgr->hTrafficMonitor, 420 pPowerMgr->betDisableTMEvent); 421 422 423 frameCount = TrafficMonitor_GetFrameBandwidth(pPowerMgr->hTrafficMonitor); 424 425 if (frameCount < pPowerMgr->BetEnableThreshold) 426 { 427 pPowerMgr->betTrafficEnable = TI_TRUE; 428 429 } 430 else if (frameCount > pPowerMgr->BetDisableThreshold) 431 { 432 pPowerMgr->betTrafficEnable = TI_FALSE; 433 } 434 435 PowerMgrConfigBetToFw(hPowerMgr,pPowerMgr->betTrafficEnable); 436 } 437 438 /* also start the power manager keep-alive sub module */ 439 powerMgrKL_start (pPowerMgr->hPowerMgrKeepAlive); 440 441 return TI_OK; 442} 443 444 445/**************************************************************************************** 446 * PowerMgr_stopPS * 447 **************************************************************************************** 448DESCRIPTION: Stop the power save algorithm of the driver and also the 802.11 PS. 449 450INPUT: - hPowerMgr - Handle to the Power Manager 451 452OUTPUT: 453RETURN: TI_STATUS - TI_OK or PENDING on success else TI_NOK.\n 454****************************************************************************************/ 455TI_STATUS PowerMgr_stopPS(TI_HANDLE hPowerMgr, TI_BOOL bDisconnect) 456{ 457 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 458 /*TI_STATUS status;*/ 459 460 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgr_stopPS - called\n"); 461 462 if ( pPowerMgr->psEnable == TI_FALSE ) 463 { 464 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgr_stopPS - PS is already Disable! Aborting!\n"); 465 /* 466 Print Info message incase callng PowerMgr_stopPS() more than once in a row, without 467 calling to PowerMgr_startPS() in the middle. 468 this will return with TI_OK and not doing the Stop action! 469 */ 470 return TI_OK; 471 } 472 473 pPowerMgr->psEnable = TI_FALSE; 474 tmr_StopTimer (pPowerMgr->hRetryPsTimer); 475 476 /* Check if PsPoll work-around is currently enabled */ 477 if ( pPowerMgr->powerMngModePriority[POWER_MANAGER_PS_POLL_FAILURE_PRIORITY].priorityEnable == TI_TRUE) 478 { 479 tmr_StopTimer(pPowerMgr->hPsPollFailureTimer); 480 /* Exit the PsPoll work-around */ 481 powerMgr_PsPollFailureTimeout( hPowerMgr, TI_FALSE ); 482 } 483 484 if ( pPowerMgr->desiredPowerModeProfile == POWER_MODE_AUTO ) 485 { 486 powerMgrDisableThresholdsIndications(hPowerMgr); 487 } 488 489 TWD_SetPsMode (pPowerMgr->hTWD, POWER_SAVE_OFF, TI_FALSE, NULL, NULL, NULL); 490 491 /* set the power policy of the system */ 492 TWD_CfgSleepAuth (pPowerMgr->hTWD, pPowerMgr->defaultPowerLevel); 493 if ((pPowerMgr->betEnable)&&( pPowerMgr->desiredPowerModeProfile != POWER_MODE_ACTIVE )) 494 { 495 TrafficMonitor_StopEventNotif(pPowerMgr->hTrafficMonitor, 496 pPowerMgr->betEnableTMEvent); 497 498 TrafficMonitor_StopEventNotif(pPowerMgr->hTrafficMonitor, 499 pPowerMgr->betDisableTMEvent); 500 } 501 502 /* also stop the power manager keep-alive sub module */ 503 powerMgrKL_stop (pPowerMgr->hPowerMgrKeepAlive, bDisconnect); 504 505 return TI_OK; 506} 507 508 509/**************************************************************************************** 510 * PowerMgr_getPsStatus * 511 **************************************************************************************** 512DESCRIPTION: returns the 802.11 power save status (enable / disable). 513 514INPUT: - hPowerMgr - Handle to the Power Manager 515 516OUTPUT: 517RETURN: TI_BOOL - TI_TRUE if enable else TI_FALSE.\n 518****************************************************************************************/ 519TI_BOOL PowerMgr_getPsStatus(TI_HANDLE hPowerMgr) 520{ 521 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 522 523 return TWD_GetPsStatus (pPowerMgr->hTWD); 524} 525 526 527/**************************************************************************************** 528 * PowerMgr_setPowerMode * 529 **************************************************************************************** 530DESCRIPTION: Configure of the PowerMode profile (auto / active / short doze / long doze). 531 532INPUT: - hPowerMgr - Handle to the Power Manager 533 - thePowerMode - the requested power mode (auto / active / short doze / long doze). 534OUTPUT: 535RETURN: TI_STATUS - TI_OK on success else TI_NOK.\n 536****************************************************************************************/ 537TI_STATUS PowerMgr_setPowerMode(TI_HANDLE hPowerMgr) 538{ 539 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 540 PowerMgr_PowerMode_e powerMode; 541 542 /*in this way we will run with the highest priority that is enabled*/ 543 powerMode = powerMgrGetHighestPriority(hPowerMgr); 544 545 /* sanity checking */ 546 if ( powerMode >= POWER_MODE_MAX) 547 { 548 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgr_setPowerMode - unknown parameter: %d\n", powerMode); 549 return TI_NOK; 550 } 551 552 TRACE1( pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgr_setPowerMode, power mode = %d\n", powerMode); 553 554 if ( pPowerMgr->desiredPowerModeProfile != powerMode ) 555 { 556 PowerMgr_PowerMode_e previousPowerModeProfile; 557 previousPowerModeProfile = pPowerMgr->desiredPowerModeProfile; 558 pPowerMgr->desiredPowerModeProfile = powerMode; 559 560 if ( pPowerMgr->desiredPowerModeProfile == POWER_MODE_AUTO ) 561 { 562 if ( pPowerMgr->psEnable == TI_TRUE ) 563 { 564 powerMgrStartAutoPowerMode(hPowerMgr); 565 } 566 567 /* 568 the transitions of state will be done according to the events from the 569 traffic monitor - therefor abort and wait event from the traffic monitor. 570 */ 571 return TI_OK; 572 } 573 else if ( previousPowerModeProfile == POWER_MODE_AUTO ) 574 { 575 /* 576 if the old power mode is AUTO and the new power mode is NOT then need 577 to disable the thresholds indications from the traffic monitor. 578 */ 579 powerMgrDisableThresholdsIndications(hPowerMgr); 580 } 581 if ( pPowerMgr->psEnable == TI_TRUE ) 582 { 583 powerMgrPowerProfileConfiguration(hPowerMgr, powerMode); 584 } 585 } 586 else 587 { 588 /* 589 the power mode is already configure to the module - don't need to do anything! 590 */ 591 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_WARNING, "PowerMgr_setPowerMode - desiredPowerModeProfile == thePowerMode (=%d), ABORTING!\n", powerMode); 592 } 593 594 return TI_OK; 595} 596 597 598/**************************************************************************************** 599 * PowerMgr_setDozeModeInAuto * 600 **************************************************************************************** 601DESCRIPTION: Configure the doze mode (short-doze / long-doze) that auto mode will toggle between doze vs active. 602INPUT: - hPowerMgr - Handle to the Power Manager 603 - dozeMode - the requested doze mode when Mgr is in Auto mode (short-doze / long-doze) 604OUTPUT: 605RETURN: 606****************************************************************************************/ 607void PowerMgr_setDozeModeInAuto(TI_HANDLE hPowerMgr, PowerMgr_PowerMode_e dozeMode) 608{ 609 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 610 PowerMgr_PowerMode_e powerMode = powerMgrGetHighestPriority(hPowerMgr); 611 612 /* check if we are trying to configure the same Doze mode */ 613 if ( dozeMode != pPowerMgr->autoModeDozeMode ) 614 { 615 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgr_setDozeModeInAuto - autoModeDozeMode == %d \n", dozeMode); 616 617 pPowerMgr->autoModeDozeMode = dozeMode; 618 619 /* in case we are already in Auto mode, we have to set the wake up condition MIB */ 620 if ( powerMode == POWER_MODE_AUTO ) 621 { 622 if ( dozeMode == POWER_MODE_SHORT_DOZE ) 623 { 624 if ( pPowerMgr->beaconListenInterval > 1 ) 625 { 626 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_N_BEACON); 627 } 628 else 629 { 630 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_BEACON); 631 } 632 } 633 else /* POWER_MODE_LONG_DOZE */ 634 { 635 if ( pPowerMgr->dtimListenInterval > 1 ) 636 { 637 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_N_DTIM); 638 } 639 else 640 { 641 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_DTIM); 642 } 643 } 644 645 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgr_setDozeModeInAuto - already in Auto\n"); 646 } 647 } 648 else 649 { 650 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_WARNING, "PowerMgr_setDozeModeInAuto - autoModeDozeMode == %d (same same ...)\n", dozeMode); 651 } 652} 653 654/**************************************************************************************** 655 * PowerMgr_getPowerMode * 656 **************************************************************************************** 657DESCRIPTION: Get the current PowerMode of the PowerMgr module. 658 659INPUT: - hPowerMgr - Handle to the Power Manager 660OUTPUT: 661RETURN: PowerMgr_PowerMode_e - (auto / active / short doze / long doze).\n 662****************************************************************************************/ 663PowerMgr_PowerMode_e PowerMgr_getPowerMode(TI_HANDLE hPowerMgr) 664{ 665 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 666 667 return pPowerMgr->desiredPowerModeProfile; 668} 669 670 671TI_STATUS powerMgr_setParam(TI_HANDLE thePowerMgrHandle, 672 paramInfo_t *theParamP) 673{ 674 PowerMgr_t *pPowerMgr = (PowerMgr_t*)thePowerMgrHandle; 675 676 switch ( theParamP->paramType ) 677 { 678 case POWER_MGR_POWER_MODE: 679 pPowerMgr->powerMngModePriority[theParamP->content.powerMngPowerMode.PowerMngPriority].powerMode 680 = theParamP->content.powerMngPowerMode.PowerMode; 681 PowerMgr_setPowerMode(thePowerMgrHandle); 682 if (pPowerMgr->betEnable) 683 PowerMgrConfigBetToFw(thePowerMgrHandle, pPowerMgr->betEnable ); 684 break; 685 686 case POWER_MGR_DISABLE_PRIORITY: 687 pPowerMgr->powerMngModePriority[theParamP->content.powerMngPriority].priorityEnable = TI_FALSE; 688 PowerMgr_setPowerMode(thePowerMgrHandle); 689 break; 690 691 case POWER_MGR_ENABLE_PRIORITY: 692 pPowerMgr->powerMngModePriority[theParamP->content.powerMngPriority].priorityEnable = TI_TRUE; 693 PowerMgr_setPowerMode(thePowerMgrHandle); 694 break; 695 696 case POWER_MGR_POWER_LEVEL_PS: 697 pPowerMgr->PowerSavePowerLevel = theParamP->content.PowerSavePowerLevel; 698 /* If we are connected, config the new power level (this param is for connected state) */ 699 if (pPowerMgr->psEnable) 700 { 701 TWD_CfgSleepAuth (pPowerMgr->hTWD, pPowerMgr->PowerSavePowerLevel); 702 } 703 break; 704 705 case POWER_MGR_POWER_LEVEL_DEFAULT: 706 pPowerMgr->defaultPowerLevel = theParamP->content.DefaultPowerLevel; 707 /* If we are NOT connected, config the new power level (this param is for disconnected state) */ 708 if (!pPowerMgr->psEnable) 709 { 710 TWD_CfgSleepAuth (pPowerMgr->hTWD, pPowerMgr->defaultPowerLevel); 711 } 712 break; 713 714 case POWER_MGR_POWER_LEVEL_DOZE_MODE: 715 PowerMgr_setDozeModeInAuto(thePowerMgrHandle,theParamP->content.powerMngDozeMode); 716 if (pPowerMgr->betEnable) 717 PowerMgrConfigBetToFw(thePowerMgrHandle, pPowerMgr->betEnable ); 718 break; 719 720 case POWER_MGR_KEEP_ALIVE_ENA_DIS: 721 case POWER_MGR_KEEP_ALIVE_ADD_REM: 722 return powerMgrKL_setParam (pPowerMgr->hPowerMgrKeepAlive, theParamP); 723 break; 724 725 default: 726 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgr_setParam - ERROR - Param is not supported, %d\n\n", theParamP->paramType); 727 728 return PARAM_NOT_SUPPORTED; 729 } 730 731 return TI_OK; 732} 733 734 735 736TI_STATUS powerMgr_getParam(TI_HANDLE thePowerMgrHandle, 737 paramInfo_t *theParamP) 738{ 739 PowerMgr_t *pPowerMgr = (PowerMgr_t*)thePowerMgrHandle; 740 741 switch ( theParamP->paramType ) 742 { 743 case POWER_MGR_POWER_MODE: 744 theParamP->content.PowerMode = PowerMgr_getPowerMode(thePowerMgrHandle); 745 break; 746 747 case POWER_MGR_POWER_LEVEL_PS: 748 theParamP->content.PowerSavePowerLevel = pPowerMgr->PowerSavePowerLevel; 749 break; 750 751 case POWER_MGR_POWER_LEVEL_DEFAULT: 752 theParamP->content.DefaultPowerLevel = pPowerMgr->defaultPowerLevel; 753 break; 754 755 case POWER_MGR_POWER_LEVEL_DOZE_MODE: 756 theParamP->content.powerMngDozeMode = pPowerMgr->autoModeDozeMode; 757 break; 758 759 case POWER_MGR_KEEP_ALIVE_GET_CONFIG: 760 return powerMgrKL_getParam (pPowerMgr->hPowerMgrKeepAlive, theParamP); 761 break; 762 763 case POWER_MGR_GET_POWER_CONSUMPTION_STATISTICS: 764 765 return cmdBld_ItrPowerConsumptionstat (pPowerMgr->hTWD, 766 theParamP->content.interogateCmdCBParams.fCb, 767 theParamP->content.interogateCmdCBParams.hCb, 768 (void*)theParamP->content.interogateCmdCBParams.pCb); 769 770 771 772 break; 773 774 775 default: 776 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgr_getParam - ERROR - Param is not supported, %d\n\n", theParamP->paramType); 777 return PARAM_NOT_SUPPORTED; 778 } 779 780 return TI_OK; 781} 782 783 784/***************************************************************************** 785 ** Private Function prototypes ** 786 *****************************************************************************/ 787 788 789/**************************************************************************************** 790 * powerSaveCompleteCB * 791 **************************************************************************************** 792DESCRIPTION: Callback for the Power server complete - gets the result of the request 793 for PS or exit PS. 794 795INPUT: - hPowerMgr - Handle to the Power Manager 796 - PSMode 797 - trasStatus - result string form the FW. 798OUTPUT: 799RETURN: void.\n 800****************************************************************************************/ 801static void powerSaveCompleteCB(TI_HANDLE hPowerMgr,TI_UINT8 PSMode,TI_UINT8 transStatus) 802{ 803 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 804 805 TRACE1( pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "powerSaveCompleteCB, statud = %d\n", transStatus); 806 807 /* Handling the event*/ 808 switch ( (EventsPowerSave_e)transStatus ) 809 { 810 case ENTER_POWER_SAVE_FAIL: 811 case EXIT_POWER_SAVE_FAIL: 812 pPowerMgr->lastPsTransaction = transStatus; 813 tmr_StartTimer (pPowerMgr->hRetryPsTimer, 814 powerMgrRetryPsTimeout, 815 (TI_HANDLE)pPowerMgr, 816 RE_ENTER_PS_TIMEOUT, 817 TI_FALSE); 818 break; 819 820 case ENTER_POWER_SAVE_SUCCESS: 821 case EXIT_POWER_SAVE_SUCCESS: 822 break; 823 824 default: 825 TRACE1( pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "powerSaveCompleteCB: invliad status: %d\n", transStatus); 826 break; 827 } 828} 829 830/** 831 * \\n 832 * \date 30-Aug-2006\n 833 * \brief Power manager callback fro TM event notification 834 * 835 * Function Scope \e Public.\n 836 * \param hPowerMgr - handle to the power maanger object.\n 837 * \param cookie - values supplied during event registration (active / doze).\n 838 */ 839static void PowerMgrTMThresholdCrossCB( TI_HANDLE hPowerMgr, TI_UINT32 cookie ) 840{ 841 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 842 843 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgrTMThresholdCrossCB - TM notified threshold crossed, cookie: %d\n", cookie); 844 845 /* sanity cehcking - TM notifications should only be received when PM is enabled and in auto mode */ 846 if ( (pPowerMgr->psEnable == TI_TRUE) && (pPowerMgr->desiredPowerModeProfile == POWER_MODE_AUTO)) 847 { 848 switch ((PowerMgr_PowerMode_e)cookie) 849 { 850 case POWER_MODE_ACTIVE: 851 powerMgrPowerProfileConfiguration( hPowerMgr, POWER_MODE_ACTIVE ); 852 break; 853 854 /* threshold crossed down - need to enter configured doze mode */ 855 case POWER_MODE_SHORT_DOZE: 856 powerMgrPowerProfileConfiguration( hPowerMgr, pPowerMgr->autoModeDozeMode ); 857 break; 858 859 default: 860 TRACE1( pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgrTMThresholdCrossCB: TM notification with invalid cookie: %d!\n", cookie); 861 break; 862 } 863 } 864 else 865 { 866 TRACE2( pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgrTMThresholdCrossCB: TM motification when psEnable is :%d or desired profile is: %d\n", pPowerMgr->psEnable, pPowerMgr->desiredPowerModeProfile); 867 } 868 869} 870 871/**************************************************************************************** 872* powerMgrDisableThresholdsIndications * 873***************************************************************************************** 874DESCRIPTION: This will send a disable message to the traffic monitor, 875 to stop sending indications on threshold pass. 876 877 878INPUT: - hPowerMgr - Handle to the Power Manager 879OUTPUT: 880RETURN: void.\n 881****************************************************************************************/ 882static void powerMgrDisableThresholdsIndications(TI_HANDLE hPowerMgr) 883{ 884 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 885 886 /* 887 auto is not a static/fix state, else its a dynamic state that flows between 888 the 3 static/fix states: active, short-doze and long-doze. 889 */ 890 TrafficMonitor_StopEventNotif(pPowerMgr->hTrafficMonitor, 891 pPowerMgr->passToActiveTMEvent); 892 893 TrafficMonitor_StopEventNotif(pPowerMgr->hTrafficMonitor, 894 pPowerMgr->passToDozeTMEvent); 895 896} 897 898 899/**************************************************************************************** 900* powerMgrEnableThresholdsIndications * 901***************************************************************************************** 902DESCRIPTION: TThis will send an enable message to the traffic monitor, 903 to start sending indications on threshold pass. 904 905 906INPUT: - hPowerMgr - Handle to the Power Manager 907OUTPUT: 908RETURN: void.\n 909****************************************************************************************/ 910static void powerMgrEnableThresholdsIndications(TI_HANDLE hPowerMgr) 911{ 912 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 913 914 TRACE0( pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "powerMgrEnableThresholdsIndications called\n"); 915 /* 916 auto is not a static/fix state, but rather a dynamic state that flows between 917 the 3 static/fix states: active, short-doze and long-doze. 918 */ 919 TrafficMonitor_StartEventNotif(pPowerMgr->hTrafficMonitor, 920 pPowerMgr->passToActiveTMEvent); 921 922 TrafficMonitor_StartEventNotif(pPowerMgr->hTrafficMonitor, 923 pPowerMgr->passToDozeTMEvent); 924 925} 926 927 928/**************************************************************************************** 929* powerMgrStartAutoPowerMode * 930***************************************************************************************** 931DESCRIPTION: configure the power manager to enter into AUTO power mode. 932 The power manager will deside what power level will be applied 933 acording to the traffic monitor. 934 935INPUT: - hPowerMgr - Handle to the Power Manager 936OUTPUT: 937RETURN: void.\n 938****************************************************************************************/ 939static void powerMgrStartAutoPowerMode(TI_HANDLE hPowerMgr) 940{ 941 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 942 int frameCount; 943 944 frameCount = TrafficMonitor_GetFrameBandwidth(pPowerMgr->hTrafficMonitor); 945 946 TRACE0( pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "powerMgrStartAutoPowerMode: Starting auto power mode,"); 947 948 /*Activates the correct profile*/ 949 if ( frameCount >= pPowerMgr->autoModeActiveTH ) 950 { 951 powerMgrPowerProfileConfiguration(hPowerMgr, POWER_MODE_ACTIVE); 952 } 953 else 954 { 955 powerMgrPowerProfileConfiguration(hPowerMgr, pPowerMgr->autoModeDozeMode); 956 957 } 958 /* Activates the Trafic monitoe Events*/ 959 powerMgrEnableThresholdsIndications(hPowerMgr); 960} 961 962/**************************************************************************************** 963* powerMgrRetryPsTimeout * 964***************************************************************************************** 965DESCRIPTION: Retry function if a PS/exit PS request failed 966 967INPUT: hPowerMgr - Handle to the Power Manager 968 bTwdInitOccured - Indicates if TWDriver recovery occured since timer started 969 970OUTPUT: 971 972RETURN: void.\n 973****************************************************************************************/ 974static void powerMgrRetryPsTimeout(TI_HANDLE hPowerMgr, TI_BOOL bTwdInitOccured) 975{ 976 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 977 TI_STATUS powerStatus; 978 979 TRACE0( pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "powerMgrRetryPsTimeout: timer expired.\n"); 980 981 if ( pPowerMgr->lastPsTransaction == ENTER_POWER_SAVE_FAIL ) 982 { 983 powerStatus = TWD_SetPsMode (pPowerMgr->hTWD, POWER_SAVE_ON, TI_TRUE, hPowerMgr,powerSaveCompleteCB, NULL);/*NULL as GWSI callback*/ 984 } 985 else 986 { 987 powerStatus = TWD_SetPsMode (pPowerMgr->hTWD, POWER_SAVE_OFF, TI_TRUE, hPowerMgr, powerSaveCompleteCB, NULL);/*NULL as GWSI callback*/ 988 } 989 return; 990} 991 992 993/**************************************************************************************** 994* powerMgrPowerProfileConfiguration * 995***************************************************************************************** 996DESCRIPTION: This function is the " builder " of the Power Save profiles. 997 acording to the desired Power mode. 998 999INPUT: - hPowerMgr - Handle to the Power Manager 1000OUTPUT: 1001RETURN: void.\n 1002****************************************************************************************/ 1003static void powerMgrPowerProfileConfiguration(TI_HANDLE hPowerMgr, PowerMgr_PowerMode_e desiredPowerMode) 1004{ 1005 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 1006 TI_STATUS powerStatus; 1007 1008 tmr_StopTimer (pPowerMgr->hRetryPsTimer); 1009 1010 pPowerMgr->lastPowerModeProfile = desiredPowerMode; 1011 1012 switch ( desiredPowerMode ) 1013 { 1014 case POWER_MODE_AUTO: 1015 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMode==AUTO - This mode should not be sent to the GWSI - we send AUTO instead\n"); 1016 break; 1017 1018 case POWER_MODE_ACTIVE: 1019 /* set AWAKE through */ 1020 powerStatus = TWD_SetPsMode (pPowerMgr->hTWD, 1021 POWER_SAVE_OFF, 1022 TI_TRUE, 1023 hPowerMgr, 1024 powerSaveCompleteCB, 1025 NULL); 1026 1027 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMode==ACTIVE\n"); 1028 break; 1029 1030 case POWER_MODE_SHORT_DOZE: 1031 if ( pPowerMgr->beaconListenInterval > 1 ) 1032 { 1033 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_N_BEACON); 1034 } 1035 else 1036 { 1037 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_BEACON); 1038 } 1039 1040 powerStatus = TWD_SetPsMode (pPowerMgr->hTWD, 1041 POWER_SAVE_ON, 1042 TI_TRUE, 1043 hPowerMgr, 1044 powerSaveCompleteCB, 1045 NULL); 1046 1047 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMode==SHORT_DOZE\n"); 1048 break; 1049 1050 case POWER_MODE_LONG_DOZE: 1051 if ( pPowerMgr->dtimListenInterval > 1 ) 1052 { 1053 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_N_DTIM); 1054 } 1055 else 1056 { 1057 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_DTIM); 1058 } 1059 powerStatus = TWD_SetPsMode (pPowerMgr->hTWD, 1060 POWER_SAVE_ON, 1061 TI_TRUE, 1062 hPowerMgr, 1063 powerSaveCompleteCB, 1064 NULL); 1065 1066 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMode==LONG_DOZE\n"); 1067 break; 1068 1069 case POWER_MODE_PS_ONLY: 1070 /* When in SG PS mode, configure the user desired wake-up condition */ 1071 powerMgr_SGSetUserDesiredwakeUpCond(pPowerMgr); 1072 1073 powerStatus = TWD_SetPsMode (pPowerMgr->hTWD, 1074 POWER_SAVE_ON, 1075 TI_TRUE, 1076 hPowerMgr, 1077 powerSaveCompleteCB, 1078 NULL); 1079 1080 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMode==PS_ONLY\n"); 1081 break; 1082 1083 default: 1084 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgr_setWakeUpConfiguration - ERROR - PowerMode - unknown parameter: %d\n", desiredPowerMode); 1085 return; 1086 } 1087 1088} 1089 1090 1091/**************************************************************************************** 1092* powerMgrSendMBXWakeUpConditions * 1093***************************************************************************************** 1094DESCRIPTION: Tsend configuration of the power management option that holds in the command 1095 mailbox inner sturcture. 1096 1097INPUT: - hPowerMgr - Handle to the Power Manager 1098OUTPUT: 1099RETURN: TI_STATUS - TI_OK on success else TI_NOK.\n 1100****************************************************************************************/ 1101static TI_STATUS powerMgrSendMBXWakeUpConditions(TI_HANDLE hPowerMgr, 1102 TI_UINT8 listenInterval, 1103 ETnetWakeOn tnetWakeupOn) 1104{ 1105 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 1106 TPowerMgmtConfig powerMgmtConfig; 1107 TI_STATUS status = TI_OK; 1108 1109 powerMgmtConfig.listenInterval = listenInterval; 1110 powerMgmtConfig.tnetWakeupOn = tnetWakeupOn; 1111 1112 TRACE2(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "powerMgrSendMBXWakeUpConditions: listenInterval = %d, tnetWakeupOn = %d\n", listenInterval,tnetWakeupOn); 1113 1114 status = TWD_CfgWakeUpCondition (pPowerMgr->hTWD, &powerMgmtConfig); 1115 1116 if ( status != TI_OK ) 1117 { 1118 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "powerMgrSendMBXWakeUpConditions - Error in wae up condition IE!\n"); 1119 } 1120 return status; 1121} 1122 1123 1124 1125 1126static TI_STATUS powerMgrNullPacketRateConfiguration(TI_HANDLE hPowerMgr) 1127{ 1128 paramInfo_t param; 1129 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 1130 1131 param.paramType = SITE_MGR_CURRENT_RATE_PAIR_PARAM; 1132 if ( siteMgr_getParam(pPowerMgr->hSiteMgr, ¶m) == TI_OK ) 1133 { 1134 TWD_SetNullRateModulation (pPowerMgr->hTWD, (TI_UINT16)param.content.siteMgrCurrentRateMask.basicRateMask); 1135 } 1136 else 1137 { 1138 TWD_SetNullRateModulation (pPowerMgr->hTWD, (DRV_RATE_MASK_1_BARKER | DRV_RATE_MASK_2_BARKER)); 1139 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "powerMgrNullPacketRateConfiguration: error - faild to set rate so default was seted!\n"); 1140 } 1141 return TI_OK; 1142 1143} 1144 1145 1146static PowerMgr_PowerMode_e powerMgrGetHighestPriority(TI_HANDLE hPowerMgr) 1147{ 1148 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 1149 int index; 1150 for ( index = POWER_MANAGER_MAX_PRIORITY-1;index >= 0;index-- ) 1151 { 1152 if ( pPowerMgr->powerMngModePriority[index].priorityEnable ) 1153 { 1154 1155 return pPowerMgr->powerMngModePriority[index].powerMode; 1156 } 1157 1158 } 1159 1160 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "powerMgrGetHighestPriority - error - faild to get highest priority! sefault deseired mode was returned !!!\n"); 1161 return pPowerMgr->desiredPowerModeProfile; 1162} 1163 1164 1165 /**************************************************************************************** 1166 * PowerMgr_notifyFWReset * 1167 **************************************************************************************** 1168DESCRIPTION: Notify the object of the power Manager about FW reset (recovery). 1169 Calls PowerSrv module to Set Ps Mode 1170 1171INPUT: - hPowerMgr - Handle to the Power Manager 1172OUTPUT: 1173RETURN: TI_STATUS - TI_OK on success else TI_NOK. 1174****************************************************************************************/ 1175TI_STATUS PowerMgr_notifyFWReset(TI_HANDLE hPowerMgr) 1176{ 1177 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 1178 1179 TRACE2(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgr_notifyFWReset(): psEnable = %d, lastPowerModeProfile = %d\n", pPowerMgr->psEnable, pPowerMgr->lastPowerModeProfile); 1180 1181 if (pPowerMgr->psEnable) 1182 { 1183 powerMgrPowerProfileConfiguration(hPowerMgr, pPowerMgr->lastPowerModeProfile); 1184 } 1185 1186 return TI_OK; 1187} 1188 1189 1190/**************************************************************************************** 1191 * PowerMgrConfigBetToFw * 1192 **************************************************************************************** 1193DESCRIPTION: callback from TM event notification. 1194 - call PowerSrv module to Set Ps Mode 1195 1196INPUT: - hPowerMgr - Handle to the Power Manager 1197 - BetEnable - cookie:values supplied during event registration 1198OUTPUT: 1199RETURN: None. 1200****************************************************************************************/ 1201static void PowerMgrConfigBetToFw( TI_HANDLE hPowerMgr, TI_UINT32 BetEnable ) 1202{ 1203 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 1204 TI_UINT8 MaximumConsecutiveET; 1205 TI_UINT32 listenInterval; 1206 paramInfo_t param; 1207 TI_UINT32 beaconInterval; 1208 TI_UINT32 dtimPeriod; 1209 PowerMgr_PowerMode_e powerMode; 1210 1211 param.paramType = SITE_MGR_BEACON_INTERVAL_PARAM; 1212 siteMgr_getParam(pPowerMgr->hSiteMgr, ¶m); 1213 beaconInterval = param.content.beaconInterval; 1214 1215 param.paramType = SITE_MGR_DTIM_PERIOD_PARAM; 1216 siteMgr_getParam(pPowerMgr->hSiteMgr, ¶m); 1217 dtimPeriod = param.content.siteMgrDtimPeriod; 1218 1219 /* get actual Power Mode */ 1220 if (pPowerMgr->desiredPowerModeProfile == POWER_MODE_AUTO) 1221 { 1222 powerMode = pPowerMgr->autoModeDozeMode; 1223 } 1224 else 1225 { 1226 powerMode = pPowerMgr->lastPowerModeProfile; 1227 } 1228 1229 /* calc ListenInterval */ 1230 if (powerMode == POWER_MODE_SHORT_DOZE) 1231 { 1232 listenInterval = beaconInterval * pPowerMgr->beaconListenInterval; 1233 } 1234 else if (powerMode == POWER_MODE_LONG_DOZE) 1235 { 1236 listenInterval = dtimPeriod * beaconInterval * pPowerMgr->dtimListenInterval; 1237 } 1238 else 1239 { 1240 listenInterval = beaconInterval; 1241 } 1242 1243 if (listenInterval == 0) 1244 { 1245 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_WARNING, "PowerMgrConfigBetToFw: listenInterval is ZERO\n"); 1246 return; 1247 } 1248 1249 /* MaximumConsecutiveET = MaximalFullBeaconReceptionInterval / MAX( BeaconInterval, ListenInterval) */ 1250 MaximumConsecutiveET = pPowerMgr->maxFullBeaconInterval / listenInterval; 1251 1252 TRACE5(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgrConfigBetToFw:\n Power Mode = %d\n beaconInterval = %d\n listenInterval = %d\n Bet Enable = %d\n MaximumConsecutiveET = %d\n", powerMode, beaconInterval, listenInterval, BetEnable, MaximumConsecutiveET); 1253 1254 pPowerMgr->betEnable = BetEnable; /* save BET enable flag for CLI configuration */ 1255 1256 TWD_CfgBet(pPowerMgr->hTWD, BetEnable, MaximumConsecutiveET); 1257} 1258 1259/** 1260 * \date 10-April-2007\n 1261 * \brief Returns to the configured wakeup condition, when SG protective mode is done 1262 * 1263 * Function Scope \e Public.\n 1264 * Parameters:\n 1265 * 1) TI_HANDLE - handle to the PowerMgr object.\n 1266 * Return Value: void.\n 1267 */ 1268static void powerMgr_SGSetUserDesiredwakeUpCond( TI_HANDLE hPowerMgr ) 1269{ 1270 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 1271 1272 if (pPowerMgr->psEnable) 1273 { 1274 /* set wakeup condition according to user mode power save profile */ 1275 switch ( pPowerMgr->powerMngModePriority[ POWER_MANAGER_USER_PRIORITY ].powerMode ) 1276 { 1277 case POWER_MODE_AUTO: 1278 /*set wakeup condition according to doze mode in auto and wakup interval */ 1279 if ( pPowerMgr->autoModeDozeMode == POWER_MODE_SHORT_DOZE ) 1280 { 1281 /* short doze */ 1282 if ( pPowerMgr->beaconListenInterval > 1 ) 1283 { 1284 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_N_BEACON); 1285 } 1286 else 1287 { 1288 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_BEACON); 1289 } 1290 } 1291 else 1292 { 1293 /* long doze */ 1294 if ( pPowerMgr->dtimListenInterval > 1 ) 1295 { 1296 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_N_DTIM); 1297 } 1298 else 1299 { 1300 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_DTIM); 1301 } 1302 } 1303 break; 1304 1305 case POWER_MODE_ACTIVE: 1306 break; 1307 1308 case POWER_MODE_SHORT_DOZE: 1309 if ( pPowerMgr->beaconListenInterval > 1 ) 1310 { 1311 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_N_BEACON); 1312 } 1313 else 1314 { 1315 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_BEACON); 1316 } 1317 break; 1318 1319 case POWER_MODE_LONG_DOZE: 1320 if ( pPowerMgr->dtimListenInterval > 1 ) 1321 { 1322 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_N_DTIM); 1323 } 1324 else 1325 { 1326 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_DTIM); 1327 } 1328 break; 1329 1330 default: 1331TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, ": ERROR - PowerMode for user prioirty is: %d\n", pPowerMgr->powerMngModePriority[ POWER_MANAGER_USER_PRIORITY ].powerMode); 1332 } 1333 }/*end of if (psEnable)*/ 1334} 1335 1336 1337 1338/**************************************************************************************** 1339* PowerMgr_PsPollFailureCB * 1340**************************************************************************************** 1341DESCRIPTION: Work around to solve AP bad behavior. 1342 Some old AP's have trouble with Ps-Poll - The solution will be to exit PS for a 1343 period of time 1344 1345INPUT: - hPowerMgr - Handle to the Power Manager 1346OUTPUT: 1347RETURN: 1348****************************************************************************************/ 1349static void PowerMgr_PsPollFailureCB( TI_HANDLE hPowerMgr ) 1350{ 1351 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 1352 1353 if ( pPowerMgr->PsPollDeliveryFailureRecoveryPeriod ) 1354 { 1355 paramInfo_t param; 1356 1357 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_WARNING, " Oh boy, AP is not answering Ps-Poll's. enter active PS for %d Ms\n", pPowerMgr->PsPollDeliveryFailureRecoveryPeriod); 1358 1359 /* 1360 * Set the system to Active power save 1361 */ 1362 param.paramType = POWER_MGR_POWER_MODE; 1363 param.content.powerMngPowerMode.PowerMode = POWER_MODE_ACTIVE; 1364 param.content.powerMngPowerMode.PowerMngPriority = POWER_MANAGER_PS_POLL_FAILURE_PRIORITY; 1365 powerMgr_setParam(hPowerMgr,¶m); 1366 1367 param.paramType = POWER_MGR_ENABLE_PRIORITY; 1368 param.content.powerMngPriority = POWER_MANAGER_PS_POLL_FAILURE_PRIORITY; 1369 powerMgr_setParam(hPowerMgr,¶m); 1370 1371 /* 1372 * Set timer to exit the active mode 1373 */ 1374 tmr_StartTimer(pPowerMgr->hPsPollFailureTimer, 1375 powerMgr_PsPollFailureTimeout, 1376 (TI_HANDLE)pPowerMgr, 1377 pPowerMgr->PsPollDeliveryFailureRecoveryPeriod, 1378 TI_FALSE); 1379 } 1380 else /* Work-around is disabled */ 1381 { 1382 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_WARNING, " Oh boy, AP is not answering Ps-Poll's !!!\n"); 1383 } 1384 return; 1385} 1386 1387/**************************************************************************************** 1388* powerMgr_PsPollFailureTimeout * 1389**************************************************************************************** 1390DESCRIPTION: After the timeout of ps-poll failure - return to normal behavior 1391 1392INPUT: - hPowerMgr - Handle to the Power Manager 1393OUTPUT: 1394RETURN: 1395****************************************************************************************/ 1396static void powerMgr_PsPollFailureTimeout( TI_HANDLE hPowerMgr, TI_BOOL bTwdInitOccured ) 1397{ 1398 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr; 1399 paramInfo_t param; 1400 1401 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, " \n"); 1402 1403 /* disable Ps-Poll priority */ 1404 param.paramType = POWER_MGR_DISABLE_PRIORITY; 1405 param.content.powerMngPriority = POWER_MANAGER_PS_POLL_FAILURE_PRIORITY; 1406 powerMgr_setParam(hPowerMgr,¶m); 1407 1408 return; 1409} 1410 1411TI_BOOL PowerMgr_getReAuthActivePriority(TI_HANDLE thePowerMgrHandle) 1412{ 1413 PowerMgr_t *pPowerMgr = (PowerMgr_t*)thePowerMgrHandle; 1414 return pPowerMgr->reAuthActivePriority; 1415} 1416