1 /*
2 * PowerMgr.c
3 *
4 * Copyright(c) 1998 - 2010 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
77 static void powerSaveCompleteCB(TI_HANDLE hPowerMgr,TI_UINT8 PSMode,TI_UINT8 transStatus);
78 static void PowerMgrTMThresholdCrossCB( TI_HANDLE hPowerMgr, TI_UINT32 cookie );
79 static void powerMgrDisableThresholdsIndications(TI_HANDLE hPowerMgr);
80 static void powerMgrEnableThresholdsIndications(TI_HANDLE hPowerMgr);
81 static void powerMgrStartAutoPowerMode(TI_HANDLE hPowerMgr);
82 static void powerMgrRetryPsTimeout(TI_HANDLE hPowerMgr, TI_BOOL bTwdInitOccured);
83 static void powerMgrPowerProfileConfiguration(TI_HANDLE hPowerMgr, PowerMgr_PowerMode_e desiredPowerMode);
84 static void PowerMgr_setDozeModeInAuto(TI_HANDLE hPowerMgr,PowerMgr_PowerMode_e dozeMode);
85 static void PowerMgrConfigBetToFw( TI_HANDLE hPowerMgr, TI_UINT32 cookie );
86 static void PowerMgr_PsPollFailureCB( TI_HANDLE hPowerMgr );
87 static void powerMgr_PsPollFailureTimeout( TI_HANDLE hPowerMgr, TI_BOOL bTwdInitOccured );
88 static void powerMgr_SGSetUserDesiredwakeUpCond( TI_HANDLE hPowerMgr );
89 static TI_STATUS powerMgrSendMBXWakeUpConditions(TI_HANDLE hPowerMgr,TI_UINT8 listenInterval, ETnetWakeOn tnetWakeupOn);
90 static TI_STATUS powerMgrNullPacketRateConfiguration(TI_HANDLE hPowerMgr);
91 static PowerMgr_PowerMode_e powerMgrGetHighestPriority(TI_HANDLE hPowerMgr);
92
93
94 /*****************************************************************************
95 ** Public Function prototypes **
96 *****************************************************************************/
97
98
99 /****************************************************************************************
100 * PowerMgr_create *
101 ****************************************************************************************
102 DESCRIPTION: Creates the object of the power Manager.
103 performs the following:
104 - Allocate the Power Manager handle
105 - Creates the retry timer
106
107 INPUT: - hOs - Handle to OS
108 OUTPUT:
109 RETURN: Handle to the Power Manager module on success, NULL otherwise
110 ****************************************************************************************/
PowerMgr_create(TI_HANDLE hOs)111 TI_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 ****************************************************************************************
137 DESCRIPTION: Destroy the object of the power Manager.
138 - delete Power Manager alocation
139 - call the destroy function of the timer
140
141 INPUT: - hPowerMgr - Handle to the Power Manager
142 OUTPUT:
143 RETURN: TI_STATUS - TI_OK on success else TI_NOK.
144 ****************************************************************************************/
PowerMgr_destroy(TI_HANDLE hPowerMgr)145 TI_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 ****************************************************************************************
170 DESCRIPTION: Power Manager init function, called in init phase.
171
172 INPUT: pStadHandles - The driver modules handles
173
174 OUTPUT:
175
176 RETURN: void
177 ****************************************************************************************/
PowerMgr_init(TStadHandlesList * pStadHandles)178 void 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
PowerMgr_SetDefaults(TI_HANDLE hPowerMgr,PowerMgrInitParams_t * pPowerMgrInitParams)196 TI_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 {
342 TRACE0(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 ****************************************************************************************
364 DESCRIPTION: Start the power save algorithm of the driver and also the 802.11 PS.
365
366 INPUT: - hPowerMgr - Handle to the Power Manager
367
368 OUTPUT:
369 RETURN: TI_STATUS - TI_OK or PENDING on success else TI_NOK.\n
370 ****************************************************************************************/
PowerMgr_startPS(TI_HANDLE hPowerMgr)371 TI_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 ****************************************************************************************
448 DESCRIPTION: Stop the power save algorithm of the driver and also the 802.11 PS.
449
450 INPUT: - hPowerMgr - Handle to the Power Manager
451
452 OUTPUT:
453 RETURN: TI_STATUS - TI_OK or PENDING on success else TI_NOK.\n
454 ****************************************************************************************/
PowerMgr_stopPS(TI_HANDLE hPowerMgr,TI_BOOL bDisconnect)455 TI_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 ****************************************************************************************
512 DESCRIPTION: returns the 802.11 power save status (enable / disable).
513
514 INPUT: - hPowerMgr - Handle to the Power Manager
515
516 OUTPUT:
517 RETURN: TI_BOOL - TI_TRUE if enable else TI_FALSE.\n
518 ****************************************************************************************/
PowerMgr_getPsStatus(TI_HANDLE hPowerMgr)519 TI_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 ****************************************************************************************
530 DESCRIPTION: Configure of the PowerMode profile (auto / active / short doze / long doze).
531
532 INPUT: - hPowerMgr - Handle to the Power Manager
533 - thePowerMode - the requested power mode (auto / active / short doze / long doze).
534 OUTPUT:
535 RETURN: TI_STATUS - TI_OK on success else TI_NOK.\n
536 ****************************************************************************************/
PowerMgr_setPowerMode(TI_HANDLE hPowerMgr)537 TI_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 ****************************************************************************************
601 DESCRIPTION: Configure the doze mode (short-doze / long-doze) that auto mode will toggle between doze vs active.
602 INPUT: - hPowerMgr - Handle to the Power Manager
603 - dozeMode - the requested doze mode when Mgr is in Auto mode (short-doze / long-doze)
604 OUTPUT:
605 RETURN:
606 ****************************************************************************************/
PowerMgr_setDozeModeInAuto(TI_HANDLE hPowerMgr,PowerMgr_PowerMode_e dozeMode)607 void 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 ****************************************************************************************
657 DESCRIPTION: Get the current PowerMode of the PowerMgr module.
658
659 INPUT: - hPowerMgr - Handle to the Power Manager
660 OUTPUT:
661 RETURN: PowerMgr_PowerMode_e - (auto / active / short doze / long doze).\n
662 ****************************************************************************************/
PowerMgr_getPowerMode(TI_HANDLE hPowerMgr)663 PowerMgr_PowerMode_e PowerMgr_getPowerMode(TI_HANDLE hPowerMgr)
664 {
665 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
666
667 return pPowerMgr->desiredPowerModeProfile;
668 }
669
670
powerMgr_setParam(TI_HANDLE thePowerMgrHandle,paramInfo_t * theParamP)671 TI_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
724 default:
725 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgr_setParam - ERROR - Param is not supported, %d\n\n", theParamP->paramType);
726
727 return PARAM_NOT_SUPPORTED;
728 }
729
730 return TI_OK;
731 }
732
733
734
powerMgr_getParam(TI_HANDLE thePowerMgrHandle,paramInfo_t * theParamP)735 TI_STATUS powerMgr_getParam(TI_HANDLE thePowerMgrHandle,
736 paramInfo_t *theParamP)
737 {
738 PowerMgr_t *pPowerMgr = (PowerMgr_t*)thePowerMgrHandle;
739
740 switch ( theParamP->paramType )
741 {
742 case POWER_MGR_POWER_MODE:
743 theParamP->content.PowerMode = PowerMgr_getPowerMode(thePowerMgrHandle);
744 break;
745
746 case POWER_MGR_POWER_LEVEL_PS:
747 theParamP->content.PowerSavePowerLevel = pPowerMgr->PowerSavePowerLevel;
748 break;
749
750 case POWER_MGR_POWER_LEVEL_DEFAULT:
751 theParamP->content.DefaultPowerLevel = pPowerMgr->defaultPowerLevel;
752 break;
753
754 case POWER_MGR_POWER_LEVEL_DOZE_MODE:
755 theParamP->content.powerMngDozeMode = pPowerMgr->autoModeDozeMode;
756 break;
757
758 case POWER_MGR_KEEP_ALIVE_GET_CONFIG:
759 return powerMgrKL_getParam (pPowerMgr->hPowerMgrKeepAlive, theParamP);
760
761 case POWER_MGR_GET_POWER_CONSUMPTION_STATISTICS:
762
763 return cmdBld_ItrPowerConsumptionstat (pPowerMgr->hTWD,
764 theParamP->content.interogateCmdCBParams.fCb,
765 theParamP->content.interogateCmdCBParams.hCb,
766 (void*)theParamP->content.interogateCmdCBParams.pCb);
767
768
769
770
771
772 default:
773 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgr_getParam - ERROR - Param is not supported, %d\n\n", theParamP->paramType);
774 return PARAM_NOT_SUPPORTED;
775 }
776
777 return TI_OK;
778 }
779
780
781 /*****************************************************************************
782 ** Private Function prototypes **
783 *****************************************************************************/
784
785
786 /****************************************************************************************
787 * powerSaveCompleteCB *
788 ****************************************************************************************
789 DESCRIPTION: Callback for the Power server complete - gets the result of the request
790 for PS or exit PS.
791
792 INPUT: - hPowerMgr - Handle to the Power Manager
793 - PSMode
794 - trasStatus - result string form the FW.
795 OUTPUT:
796 RETURN: void.\n
797 ****************************************************************************************/
powerSaveCompleteCB(TI_HANDLE hPowerMgr,TI_UINT8 PSMode,TI_UINT8 transStatus)798 static void powerSaveCompleteCB(TI_HANDLE hPowerMgr,TI_UINT8 PSMode,TI_UINT8 transStatus)
799 {
800 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
801
802 TRACE1( pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "powerSaveCompleteCB, statud = %d\n", transStatus);
803
804 /* Handling the event*/
805 switch ( (EventsPowerSave_e)transStatus )
806 {
807 case ENTER_POWER_SAVE_FAIL:
808 case EXIT_POWER_SAVE_FAIL:
809 pPowerMgr->lastPsTransaction = transStatus;
810 tmr_StartTimer (pPowerMgr->hRetryPsTimer,
811 powerMgrRetryPsTimeout,
812 (TI_HANDLE)pPowerMgr,
813 RE_ENTER_PS_TIMEOUT,
814 TI_FALSE);
815 break;
816
817 case ENTER_POWER_SAVE_SUCCESS:
818 case EXIT_POWER_SAVE_SUCCESS:
819 break;
820
821 default:
822 TRACE1( pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "powerSaveCompleteCB: invliad status: %d\n", transStatus);
823 break;
824 }
825 }
826
827 /**
828 * \\n
829 * \date 30-Aug-2006\n
830 * \brief Power manager callback fro TM event notification
831 *
832 * Function Scope \e Public.\n
833 * \param hPowerMgr - handle to the power maanger object.\n
834 * \param cookie - values supplied during event registration (active / doze).\n
835 */
PowerMgrTMThresholdCrossCB(TI_HANDLE hPowerMgr,TI_UINT32 cookie)836 static void PowerMgrTMThresholdCrossCB( TI_HANDLE hPowerMgr, TI_UINT32 cookie )
837 {
838 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
839
840 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgrTMThresholdCrossCB - TM notified threshold crossed, cookie: %d\n", cookie);
841
842 /* sanity cehcking - TM notifications should only be received when PM is enabled and in auto mode */
843 if ( (pPowerMgr->psEnable == TI_TRUE) && (pPowerMgr->desiredPowerModeProfile == POWER_MODE_AUTO))
844 {
845 switch ((PowerMgr_PowerMode_e)cookie)
846 {
847 case POWER_MODE_ACTIVE:
848 powerMgrPowerProfileConfiguration( hPowerMgr, POWER_MODE_ACTIVE );
849 break;
850
851 /* threshold crossed down - need to enter configured doze mode */
852 case POWER_MODE_SHORT_DOZE:
853 powerMgrPowerProfileConfiguration( hPowerMgr, pPowerMgr->autoModeDozeMode );
854 break;
855
856 default:
857 TRACE1( pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgrTMThresholdCrossCB: TM notification with invalid cookie: %d!\n", cookie);
858 break;
859 }
860 }
861 else
862 {
863 TRACE2( pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgrTMThresholdCrossCB: TM motification when psEnable is :%d or desired profile is: %d\n", pPowerMgr->psEnable, pPowerMgr->desiredPowerModeProfile);
864 }
865
866 }
867
868 /****************************************************************************************
869 * powerMgrDisableThresholdsIndications *
870 *****************************************************************************************
871 DESCRIPTION: This will send a disable message to the traffic monitor,
872 to stop sending indications on threshold pass.
873
874
875 INPUT: - hPowerMgr - Handle to the Power Manager
876 OUTPUT:
877 RETURN: void.\n
878 ****************************************************************************************/
powerMgrDisableThresholdsIndications(TI_HANDLE hPowerMgr)879 static void powerMgrDisableThresholdsIndications(TI_HANDLE hPowerMgr)
880 {
881 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
882
883 /*
884 auto is not a static/fix state, else its a dynamic state that flows between
885 the 3 static/fix states: active, short-doze and long-doze.
886 */
887 TrafficMonitor_StopEventNotif(pPowerMgr->hTrafficMonitor,
888 pPowerMgr->passToActiveTMEvent);
889
890 TrafficMonitor_StopEventNotif(pPowerMgr->hTrafficMonitor,
891 pPowerMgr->passToDozeTMEvent);
892
893 }
894
895
896 /****************************************************************************************
897 * powerMgrEnableThresholdsIndications *
898 *****************************************************************************************
899 DESCRIPTION: TThis will send an enable message to the traffic monitor,
900 to start sending indications on threshold pass.
901
902
903 INPUT: - hPowerMgr - Handle to the Power Manager
904 OUTPUT:
905 RETURN: void.\n
906 ****************************************************************************************/
powerMgrEnableThresholdsIndications(TI_HANDLE hPowerMgr)907 static void powerMgrEnableThresholdsIndications(TI_HANDLE hPowerMgr)
908 {
909 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
910
911 TRACE0( pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "powerMgrEnableThresholdsIndications called\n");
912 /*
913 auto is not a static/fix state, but rather a dynamic state that flows between
914 the 3 static/fix states: active, short-doze and long-doze.
915 */
916 TrafficMonitor_StartEventNotif(pPowerMgr->hTrafficMonitor,
917 pPowerMgr->passToActiveTMEvent);
918
919 TrafficMonitor_StartEventNotif(pPowerMgr->hTrafficMonitor,
920 pPowerMgr->passToDozeTMEvent);
921
922 }
923
924
925 /****************************************************************************************
926 * powerMgrStartAutoPowerMode *
927 *****************************************************************************************
928 DESCRIPTION: configure the power manager to enter into AUTO power mode.
929 The power manager will deside what power level will be applied
930 acording to the traffic monitor.
931
932 INPUT: - hPowerMgr - Handle to the Power Manager
933 OUTPUT:
934 RETURN: void.\n
935 ****************************************************************************************/
powerMgrStartAutoPowerMode(TI_HANDLE hPowerMgr)936 static void powerMgrStartAutoPowerMode(TI_HANDLE hPowerMgr)
937 {
938 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
939 int frameCount;
940
941 frameCount = TrafficMonitor_GetFrameBandwidth(pPowerMgr->hTrafficMonitor);
942
943 TRACE0( pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "powerMgrStartAutoPowerMode: Starting auto power mode,");
944
945 /*Activates the correct profile*/
946 if ( frameCount >= pPowerMgr->autoModeActiveTH )
947 {
948 powerMgrPowerProfileConfiguration(hPowerMgr, POWER_MODE_ACTIVE);
949 }
950 else
951 {
952 powerMgrPowerProfileConfiguration(hPowerMgr, pPowerMgr->autoModeDozeMode);
953
954 }
955 /* Activates the Trafic monitoe Events*/
956 powerMgrEnableThresholdsIndications(hPowerMgr);
957 }
958
959 /****************************************************************************************
960 * powerMgrRetryPsTimeout *
961 *****************************************************************************************
962 DESCRIPTION: Retry function if a PS/exit PS request failed
963
964 INPUT: hPowerMgr - Handle to the Power Manager
965 bTwdInitOccured - Indicates if TWDriver recovery occured since timer started
966
967 OUTPUT:
968
969 RETURN: void.\n
970 ****************************************************************************************/
powerMgrRetryPsTimeout(TI_HANDLE hPowerMgr,TI_BOOL bTwdInitOccured)971 static void powerMgrRetryPsTimeout(TI_HANDLE hPowerMgr, TI_BOOL bTwdInitOccured)
972 {
973 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
974
975 TRACE0( pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "powerMgrRetryPsTimeout: timer expired.\n");
976
977 if ( pPowerMgr->lastPsTransaction == ENTER_POWER_SAVE_FAIL )
978 {
979 TWD_SetPsMode (pPowerMgr->hTWD, POWER_SAVE_ON, TI_TRUE, hPowerMgr,powerSaveCompleteCB, NULL);/*NULL as GWSI callback*/
980 }
981 else
982 {
983 TWD_SetPsMode (pPowerMgr->hTWD, POWER_SAVE_OFF, TI_TRUE, hPowerMgr, powerSaveCompleteCB, NULL);/*NULL as GWSI callback*/
984 }
985 return;
986 }
987
988
989 /****************************************************************************************
990 * powerMgrPowerProfileConfiguration *
991 *****************************************************************************************
992 DESCRIPTION: This function is the " builder " of the Power Save profiles.
993 acording to the desired Power mode.
994
995 INPUT: - hPowerMgr - Handle to the Power Manager
996 OUTPUT:
997 RETURN: void.\n
998 ****************************************************************************************/
powerMgrPowerProfileConfiguration(TI_HANDLE hPowerMgr,PowerMgr_PowerMode_e desiredPowerMode)999 static void powerMgrPowerProfileConfiguration(TI_HANDLE hPowerMgr, PowerMgr_PowerMode_e desiredPowerMode)
1000 {
1001 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
1002
1003 tmr_StopTimer (pPowerMgr->hRetryPsTimer);
1004
1005 pPowerMgr->lastPowerModeProfile = desiredPowerMode;
1006
1007 switch ( desiredPowerMode )
1008 {
1009 case POWER_MODE_AUTO:
1010 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMode==AUTO - This mode should not be sent to the GWSI - we send AUTO instead\n");
1011 break;
1012
1013 case POWER_MODE_ACTIVE:
1014 /* set AWAKE through */
1015 TWD_SetPsMode (pPowerMgr->hTWD,
1016 POWER_SAVE_OFF,
1017 TI_TRUE,
1018 hPowerMgr,
1019 powerSaveCompleteCB,
1020 NULL);
1021
1022 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMode==ACTIVE\n");
1023 break;
1024
1025 case POWER_MODE_SHORT_DOZE:
1026 if ( pPowerMgr->beaconListenInterval > 1 )
1027 {
1028 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_N_BEACON);
1029 }
1030 else
1031 {
1032 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_BEACON);
1033 }
1034
1035 TWD_SetPsMode (pPowerMgr->hTWD,
1036 POWER_SAVE_ON,
1037 TI_TRUE,
1038 hPowerMgr,
1039 powerSaveCompleteCB,
1040 NULL);
1041
1042 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMode==SHORT_DOZE\n");
1043 break;
1044
1045 case POWER_MODE_LONG_DOZE:
1046 if ( pPowerMgr->dtimListenInterval > 1 )
1047 {
1048 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_N_DTIM);
1049 }
1050 else
1051 {
1052 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_DTIM);
1053 }
1054 TWD_SetPsMode (pPowerMgr->hTWD,
1055 POWER_SAVE_ON,
1056 TI_TRUE,
1057 hPowerMgr,
1058 powerSaveCompleteCB,
1059 NULL);
1060
1061 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMode==LONG_DOZE\n");
1062 break;
1063
1064 case POWER_MODE_PS_ONLY:
1065 /* When in SG PS mode, configure the user desired wake-up condition */
1066 powerMgr_SGSetUserDesiredwakeUpCond(pPowerMgr);
1067
1068 TWD_SetPsMode (pPowerMgr->hTWD,
1069 POWER_SAVE_ON,
1070 TI_TRUE,
1071 hPowerMgr,
1072 powerSaveCompleteCB,
1073 NULL);
1074
1075 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMode==PS_ONLY\n");
1076 break;
1077
1078 default:
1079 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "PowerMgr_setWakeUpConfiguration - ERROR - PowerMode - unknown parameter: %d\n", desiredPowerMode);
1080 return;
1081 }
1082
1083 }
1084
1085
1086 /****************************************************************************************
1087 * powerMgrSendMBXWakeUpConditions *
1088 *****************************************************************************************
1089 DESCRIPTION: Tsend configuration of the power management option that holds in the command
1090 mailbox inner sturcture.
1091
1092 INPUT: - hPowerMgr - Handle to the Power Manager
1093 OUTPUT:
1094 RETURN: TI_STATUS - TI_OK on success else TI_NOK.\n
1095 ****************************************************************************************/
powerMgrSendMBXWakeUpConditions(TI_HANDLE hPowerMgr,TI_UINT8 listenInterval,ETnetWakeOn tnetWakeupOn)1096 static TI_STATUS powerMgrSendMBXWakeUpConditions(TI_HANDLE hPowerMgr,
1097 TI_UINT8 listenInterval,
1098 ETnetWakeOn tnetWakeupOn)
1099 {
1100 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
1101 TPowerMgmtConfig powerMgmtConfig;
1102 TI_STATUS status = TI_OK;
1103
1104 powerMgmtConfig.listenInterval = listenInterval;
1105 powerMgmtConfig.tnetWakeupOn = tnetWakeupOn;
1106
1107 TRACE2(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "powerMgrSendMBXWakeUpConditions: listenInterval = %d, tnetWakeupOn = %d\n", listenInterval,tnetWakeupOn);
1108
1109 status = TWD_CfgWakeUpCondition (pPowerMgr->hTWD, &powerMgmtConfig);
1110
1111 if ( status != TI_OK )
1112 {
1113 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "powerMgrSendMBXWakeUpConditions - Error in wae up condition IE!\n");
1114 }
1115 return status;
1116 }
1117
1118
1119
1120
powerMgrNullPacketRateConfiguration(TI_HANDLE hPowerMgr)1121 static TI_STATUS powerMgrNullPacketRateConfiguration(TI_HANDLE hPowerMgr)
1122 {
1123 paramInfo_t param;
1124 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
1125
1126 param.paramType = SITE_MGR_CURRENT_RATE_PAIR_PARAM;
1127 if ( siteMgr_getParam(pPowerMgr->hSiteMgr, ¶m) == TI_OK )
1128 {
1129 TWD_SetNullRateModulation (pPowerMgr->hTWD, (TI_UINT16)param.content.siteMgrCurrentRateMask.basicRateMask);
1130 }
1131 else
1132 {
1133 TWD_SetNullRateModulation (pPowerMgr->hTWD, (DRV_RATE_MASK_1_BARKER | DRV_RATE_MASK_2_BARKER));
1134 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "powerMgrNullPacketRateConfiguration: error - faild to set rate so default was seted!\n");
1135 }
1136 return TI_OK;
1137
1138 }
1139
1140
powerMgrGetHighestPriority(TI_HANDLE hPowerMgr)1141 static PowerMgr_PowerMode_e powerMgrGetHighestPriority(TI_HANDLE hPowerMgr)
1142 {
1143 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
1144 int index;
1145 for ( index = POWER_MANAGER_MAX_PRIORITY-1;index >= 0;index-- )
1146 {
1147 if ( pPowerMgr->powerMngModePriority[index].priorityEnable )
1148 {
1149
1150 return pPowerMgr->powerMngModePriority[index].powerMode;
1151 }
1152
1153 }
1154
1155 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, "powerMgrGetHighestPriority - error - faild to get highest priority! sefault deseired mode was returned !!!\n");
1156 return pPowerMgr->desiredPowerModeProfile;
1157 }
1158
1159
1160 /****************************************************************************************
1161 * PowerMgr_notifyFWReset *
1162 ****************************************************************************************
1163 DESCRIPTION: Notify the object of the power Manager about FW reset (recovery).
1164 Calls PowerSrv module to Set Ps Mode
1165
1166 INPUT: - hPowerMgr - Handle to the Power Manager
1167 OUTPUT:
1168 RETURN: TI_STATUS - TI_OK on success else TI_NOK.
1169 ****************************************************************************************/
PowerMgr_notifyFWReset(TI_HANDLE hPowerMgr)1170 TI_STATUS PowerMgr_notifyFWReset(TI_HANDLE hPowerMgr)
1171 {
1172 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
1173
1174 TRACE2(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, "PowerMgr_notifyFWReset(): psEnable = %d, lastPowerModeProfile = %d\n", pPowerMgr->psEnable, pPowerMgr->lastPowerModeProfile);
1175
1176 if (pPowerMgr->psEnable)
1177 {
1178 powerMgrPowerProfileConfiguration(hPowerMgr, pPowerMgr->lastPowerModeProfile);
1179 }
1180
1181 return TI_OK;
1182 }
1183
1184
1185 /****************************************************************************************
1186 * PowerMgrConfigBetToFw *
1187 ****************************************************************************************
1188 DESCRIPTION: callback from TM event notification.
1189 - call PowerSrv module to Set Ps Mode
1190
1191 INPUT: - hPowerMgr - Handle to the Power Manager
1192 - BetEnable - cookie:values supplied during event registration
1193 OUTPUT:
1194 RETURN: None.
1195 ****************************************************************************************/
PowerMgrConfigBetToFw(TI_HANDLE hPowerMgr,TI_UINT32 BetEnable)1196 static void PowerMgrConfigBetToFw( TI_HANDLE hPowerMgr, TI_UINT32 BetEnable )
1197 {
1198 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
1199 TI_UINT8 MaximumConsecutiveET;
1200 TI_UINT32 listenInterval;
1201 paramInfo_t param;
1202 TI_UINT32 beaconInterval;
1203 TI_UINT32 dtimPeriod;
1204 PowerMgr_PowerMode_e powerMode;
1205
1206 param.paramType = SITE_MGR_BEACON_INTERVAL_PARAM;
1207 siteMgr_getParam(pPowerMgr->hSiteMgr, ¶m);
1208 beaconInterval = param.content.beaconInterval;
1209
1210 param.paramType = SITE_MGR_DTIM_PERIOD_PARAM;
1211 siteMgr_getParam(pPowerMgr->hSiteMgr, ¶m);
1212 dtimPeriod = param.content.siteMgrDtimPeriod;
1213
1214 /* get actual Power Mode */
1215 if (pPowerMgr->desiredPowerModeProfile == POWER_MODE_AUTO)
1216 {
1217 powerMode = pPowerMgr->autoModeDozeMode;
1218 }
1219 else
1220 {
1221 powerMode = pPowerMgr->lastPowerModeProfile;
1222 }
1223
1224 /* calc ListenInterval */
1225 if (powerMode == POWER_MODE_SHORT_DOZE)
1226 {
1227 listenInterval = beaconInterval * pPowerMgr->beaconListenInterval;
1228 }
1229 else if (powerMode == POWER_MODE_LONG_DOZE)
1230 {
1231 listenInterval = dtimPeriod * beaconInterval * pPowerMgr->dtimListenInterval;
1232 }
1233 else
1234 {
1235 listenInterval = beaconInterval;
1236 }
1237
1238 if (listenInterval == 0)
1239 {
1240 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_WARNING, "PowerMgrConfigBetToFw: listenInterval is ZERO\n");
1241 return;
1242 }
1243
1244 /* MaximumConsecutiveET = MaximalFullBeaconReceptionInterval / MAX( BeaconInterval, ListenInterval) */
1245 MaximumConsecutiveET = pPowerMgr->maxFullBeaconInterval / listenInterval;
1246
1247 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);
1248
1249 pPowerMgr->betEnable = BetEnable; /* save BET enable flag for CLI configuration */
1250
1251 TWD_CfgBet(pPowerMgr->hTWD, BetEnable, MaximumConsecutiveET);
1252 }
1253
1254 /**
1255 * \date 10-April-2007\n
1256 * \brief Returns to the configured wakeup condition, when SG protective mode is done
1257 *
1258 * Function Scope \e Public.\n
1259 * Parameters:\n
1260 * 1) TI_HANDLE - handle to the PowerMgr object.\n
1261 * Return Value: void.\n
1262 */
powerMgr_SGSetUserDesiredwakeUpCond(TI_HANDLE hPowerMgr)1263 static void powerMgr_SGSetUserDesiredwakeUpCond( TI_HANDLE hPowerMgr )
1264 {
1265 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
1266
1267 if (pPowerMgr->psEnable)
1268 {
1269 /* set wakeup condition according to user mode power save profile */
1270 switch ( pPowerMgr->powerMngModePriority[ POWER_MANAGER_USER_PRIORITY ].powerMode )
1271 {
1272 case POWER_MODE_AUTO:
1273 /*set wakeup condition according to doze mode in auto and wakup interval */
1274 if ( pPowerMgr->autoModeDozeMode == POWER_MODE_SHORT_DOZE )
1275 {
1276 /* short doze */
1277 if ( pPowerMgr->beaconListenInterval > 1 )
1278 {
1279 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_N_BEACON);
1280 }
1281 else
1282 {
1283 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_BEACON);
1284 }
1285 }
1286 else
1287 {
1288 /* long doze */
1289 if ( pPowerMgr->dtimListenInterval > 1 )
1290 {
1291 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_N_DTIM);
1292 }
1293 else
1294 {
1295 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_DTIM);
1296 }
1297 }
1298 break;
1299
1300 case POWER_MODE_ACTIVE:
1301 break;
1302
1303 case POWER_MODE_SHORT_DOZE:
1304 if ( pPowerMgr->beaconListenInterval > 1 )
1305 {
1306 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_N_BEACON);
1307 }
1308 else
1309 {
1310 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->beaconListenInterval,TNET_WAKE_ON_BEACON);
1311 }
1312 break;
1313
1314 case POWER_MODE_LONG_DOZE:
1315 if ( pPowerMgr->dtimListenInterval > 1 )
1316 {
1317 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_N_DTIM);
1318 }
1319 else
1320 {
1321 powerMgrSendMBXWakeUpConditions(hPowerMgr,pPowerMgr->dtimListenInterval,TNET_WAKE_ON_DTIM);
1322 }
1323 break;
1324
1325 default:
1326 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_ERROR, ": ERROR - PowerMode for user prioirty is: %d\n", pPowerMgr->powerMngModePriority[ POWER_MANAGER_USER_PRIORITY ].powerMode);
1327 }
1328 }/*end of if (psEnable)*/
1329 }
1330
1331
1332
1333 /****************************************************************************************
1334 * PowerMgr_PsPollFailureCB *
1335 ****************************************************************************************
1336 DESCRIPTION: Work around to solve AP bad behavior.
1337 Some old AP's have trouble with Ps-Poll - The solution will be to exit PS for a
1338 period of time
1339
1340 INPUT: - hPowerMgr - Handle to the Power Manager
1341 OUTPUT:
1342 RETURN:
1343 ****************************************************************************************/
PowerMgr_PsPollFailureCB(TI_HANDLE hPowerMgr)1344 static void PowerMgr_PsPollFailureCB( TI_HANDLE hPowerMgr )
1345 {
1346 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
1347
1348 if ( pPowerMgr->PsPollDeliveryFailureRecoveryPeriod )
1349 {
1350 paramInfo_t param;
1351
1352 TRACE1(pPowerMgr->hReport, REPORT_SEVERITY_WARNING, " Oh boy, AP is not answering Ps-Poll's. enter active PS for %d Ms\n", pPowerMgr->PsPollDeliveryFailureRecoveryPeriod);
1353
1354 /*
1355 * Set the system to Active power save
1356 */
1357 param.paramType = POWER_MGR_POWER_MODE;
1358 param.content.powerMngPowerMode.PowerMode = POWER_MODE_ACTIVE;
1359 param.content.powerMngPowerMode.PowerMngPriority = POWER_MANAGER_PS_POLL_FAILURE_PRIORITY;
1360 powerMgr_setParam(hPowerMgr,¶m);
1361
1362 param.paramType = POWER_MGR_ENABLE_PRIORITY;
1363 param.content.powerMngPriority = POWER_MANAGER_PS_POLL_FAILURE_PRIORITY;
1364 powerMgr_setParam(hPowerMgr,¶m);
1365
1366 /*
1367 * Set timer to exit the active mode
1368 */
1369 tmr_StartTimer(pPowerMgr->hPsPollFailureTimer,
1370 powerMgr_PsPollFailureTimeout,
1371 (TI_HANDLE)pPowerMgr,
1372 pPowerMgr->PsPollDeliveryFailureRecoveryPeriod,
1373 TI_FALSE);
1374 }
1375 else /* Work-around is disabled */
1376 {
1377 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_WARNING, " Oh boy, AP is not answering Ps-Poll's !!!\n");
1378 }
1379 return;
1380 }
1381
1382 /****************************************************************************************
1383 * powerMgr_PsPollFailureTimeout *
1384 ****************************************************************************************
1385 DESCRIPTION: After the timeout of ps-poll failure - return to normal behavior
1386
1387 INPUT: - hPowerMgr - Handle to the Power Manager
1388 OUTPUT:
1389 RETURN:
1390 ****************************************************************************************/
powerMgr_PsPollFailureTimeout(TI_HANDLE hPowerMgr,TI_BOOL bTwdInitOccured)1391 static void powerMgr_PsPollFailureTimeout( TI_HANDLE hPowerMgr, TI_BOOL bTwdInitOccured )
1392 {
1393 PowerMgr_t *pPowerMgr = (PowerMgr_t*)hPowerMgr;
1394 paramInfo_t param;
1395
1396 TRACE0(pPowerMgr->hReport, REPORT_SEVERITY_INFORMATION, " \n");
1397
1398 /* disable Ps-Poll priority */
1399 param.paramType = POWER_MGR_DISABLE_PRIORITY;
1400 param.content.powerMngPriority = POWER_MANAGER_PS_POLL_FAILURE_PRIORITY;
1401 powerMgr_setParam(hPowerMgr,¶m);
1402
1403 return;
1404 }
1405
PowerMgr_getReAuthActivePriority(TI_HANDLE thePowerMgrHandle)1406 TI_BOOL PowerMgr_getReAuthActivePriority(TI_HANDLE thePowerMgrHandle)
1407 {
1408 PowerMgr_t *pPowerMgr = (PowerMgr_t*)thePowerMgrHandle;
1409 return pPowerMgr->reAuthActivePriority;
1410 }
1411