Home | History | Annotate | Download | only in MacServices
      1 /*
      2  * PowerSrv.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 powerSrv.c
     35  *  \brief This is the powerSrv module implementation.
     36  *  \author Assaf Azulay
     37  *  \date 19-Oct-2005
     38  */
     39 
     40 /****************************************************************************
     41  *                                                                                                           *
     42  *   MODULE:  powerSrv                                                                                  *
     43  *   PURPOSE: powerSrv Module implementation.                                                   *
     44  *                                                                                                              *
     45  ****************************************************************************/
     46 
     47 #define __FILE_ID__  FILE_ID_113
     48 #include "tidef.h"
     49 #include "osApi.h"
     50 #include "report.h"
     51 #include "timer.h"
     52 #include "PowerSrv.h"
     53 #include "PowerSrv_API.h"
     54 #include "PowerSrvSM.h"
     55 #include "eventMbox_api.h"
     56 
     57 
     58 /*****************************************************************************
     59  **         Defines                                                         **
     60  *****************************************************************************/
     61 
     62 
     63 
     64 /****************************************************************************************
     65 **         Private Function prototypes                                                                              **
     66 ****************************************************************************************/
     67 static void     powerSrv802_11PsReport  (TI_HANDLE hPowerSrv, char* str , TI_UINT32 strLen);
     68 TI_STATUS   powerSrvProcessRequest  (TI_HANDLE hPowerSrv, powerSrvMode_e requestMode);
     69 void powerSrvCreatePssRequest (TI_HANDLE                    hPowerSrv,
     70                                powerSrvMode_e              requestMode,
     71                                powerSrvRequestState_e      requestState,
     72                                E80211PsMode                psMode,
     73                                TI_BOOL                        sendNullDataOnExit,
     74                                void *                      powerSaveCBObject,
     75                                powerSaveCmpltCB_t          powerSaveCompleteCB,
     76                                powerSaveCmdResponseCB_t    powerSaveCmdResponseCB);
     77 
     78 /***************************************************************************************
     79 **                                 Functions                                                                    **
     80 ****************************************************************************************/
     81 
     82 
     83 
     84 /****************************************************************************************
     85  *                        powerSrv_create                                                           *
     86  ****************************************************************************************
     87 DESCRIPTION: Power Server module creation function, called by the MAC Services create in creation phase
     88                 performs the following:
     89                 -   Allocate the Power Server handle
     90                 -   Creates the Power Server State Machine
     91 
     92 INPUT:          - hOs - Handle to OS
     93 
     94 
     95 OUTPUT:
     96 
     97 RETURN:     Handle to the Power Server module on success, NULL otherwise
     98 ****************************************************************************************/
     99 TI_HANDLE powerSrv_create(TI_HANDLE hOs)
    100 {
    101     powerSrv_t * pPowerSrv = NULL;
    102     pPowerSrv = (powerSrv_t*) os_memoryAlloc (hOs, sizeof(powerSrv_t));
    103     if ( pPowerSrv == NULL )
    104     {
    105         WLAN_OS_REPORT(("powerSrv_create - Memory Allocation Error!\n"));
    106         return NULL;
    107     }
    108 
    109     os_memoryZero (hOs, pPowerSrv, sizeof(powerSrv_t));
    110 
    111     pPowerSrv->hOS = hOs;
    112 
    113     /*creation of the State Machine*/
    114     pPowerSrv->hPowerSrvSM = powerSrvSM_create(hOs);
    115     if ( pPowerSrv->hPowerSrvSM == NULL )
    116     {
    117         WLAN_OS_REPORT(("powerSrv_create - Error in create PowerSrvSM module!\n"));
    118         powerSrv_destroy(pPowerSrv);
    119         return NULL;
    120     }
    121 
    122     return pPowerSrv;
    123 
    124 }
    125 
    126 
    127 /****************************************************************************************
    128  *                        powerSrv_destroy                                                          *
    129  ****************************************************************************************
    130 DESCRIPTION: Power Server module destroy function, c
    131                 -   delete Power Server allocation
    132                 -   call the destroy function of the State machine
    133 
    134 INPUT:          - hPowerSrv - Handle to the Power Server
    135 
    136 
    137 OUTPUT:
    138 
    139 RETURN:    TI_STATUS - TI_OK on success else TI_NOK.
    140 ****************************************************************************************/
    141 TI_STATUS powerSrv_destroy(TI_HANDLE hPowerSrv)
    142 {
    143     powerSrv_t *pPowerSrv = (powerSrv_t*)hPowerSrv;
    144 
    145     if ( pPowerSrv->hPowerSrvSM != NULL )
    146     {
    147         powerSrvSM_destroy(pPowerSrv->hPowerSrvSM);
    148     }
    149 
    150     os_memoryFree(pPowerSrv->hOS , pPowerSrv , sizeof(powerSrv_t));
    151 
    152     return TI_OK;
    153 }
    154 
    155 
    156 /****************************************************************************************
    157  *                        powerSrvSM_init                                                           *
    158  ****************************************************************************************
    159 DESCRIPTION: Power Server module initialize function, called by the MAC Services in initialization phase
    160                 performs the following:
    161                 -   init the Power server to active state.
    162                 -   call the init function of the state machine.
    163 
    164 INPUT:      - hPowerSrv         - handle to the PowerSrv object.
    165             - hReport           - handle to the Report object.
    166             - hEventMbox        - handle to the Event Mbox object.
    167             - hCmdBld           - handle to the Command Builder object.
    168 
    169 OUTPUT:
    170 RETURN:    TI_STATUS - TI_OK on success else TI_NOK.
    171 ****************************************************************************************/
    172 TI_STATUS powerSrv_init (TI_HANDLE hPowerSrv,
    173                          TI_HANDLE hReport,
    174                          TI_HANDLE hEventMbox,
    175                          TI_HANDLE hCmdBld,
    176                          TI_HANDLE hTimer)
    177 {
    178     powerSrv_t* pPowerSrv = (powerSrv_t*)hPowerSrv;
    179 
    180     pPowerSrv->hReport = hReport;
    181     pPowerSrv->hEventMbox = hEventMbox;
    182 
    183     /*
    184     init PowerSrv state machine.
    185     */
    186     powerSrvSM_init (pPowerSrv->hPowerSrvSM, hReport, hCmdBld, hTimer);
    187 
    188     pPowerSrv->currentMode = USER_MODE;
    189 
    190     /*init all request with init values*/
    191     powerSrvCreatePssRequest(hPowerSrv,
    192                              USER_MODE,
    193                              HANDLED_REQUEST,
    194                              POWER_SAVE_OFF,
    195                              TI_FALSE,
    196                              NULL,
    197                              NULL,
    198                              NULL);
    199     powerSrvCreatePssRequest(hPowerSrv,
    200                              DRIVER_MODE,
    201                              HANDLED_REQUEST,
    202                              POWER_SAVE_OFF,
    203                              TI_FALSE,
    204                              NULL,
    205                              NULL,
    206                              NULL);
    207     pPowerSrv->userLastRequestMode = (powerSrvMode_e)POWER_SAVE_OFF;
    208     pPowerSrv->pCurrentRequest  = & pPowerSrv->userRequest;
    209 
    210     /*
    211     register for Event
    212     */
    213 
    214 	eventMbox_RegisterEvent (hEventMbox,
    215                              TWD_OWN_EVENT_PS_REPORT,
    216                              (void *)powerSrv802_11PsReport,
    217                              hPowerSrv);
    218 
    219     eventMbox_UnMaskEvent (hEventMbox, TWD_OWN_EVENT_PS_REPORT, NULL, NULL);
    220 
    221     TRACE0(pPowerSrv->hReport, REPORT_SEVERITY_INIT, "powerSrv Initialized \n");
    222 
    223     return TI_OK;
    224 }
    225 
    226 /****************************************************************************************
    227  *                        powerSrv_restart															*
    228  ****************************************************************************************
    229 DESCRIPTION: Restart the scan SRV module upon recovery.
    230 				-	init the Power server to active state.
    231 				-	call the init function of the state machine.
    232 
    233 INPUT:     	- hPowerSrv 			- handle to the PowerSrv object.
    234 
    235 OUTPUT:
    236 RETURN:    TI_STATUS - TI_OK on success else TI_NOK.
    237 ****************************************************************************************/
    238 TI_STATUS powerSrv_restart(	TI_HANDLE hPowerSrv)
    239 {
    240     powerSrv_t* pPowerSrv = (powerSrv_t*)hPowerSrv;
    241 	PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)pPowerSrv->hPowerSrvSM;
    242     /*
    243     init PowerSrv state machine.
    244     */
    245 	/*
    246 	the PowerSrvSM start in active mode (POWER_SRV_STATE_ACTIVE)
    247 	the PowerSrvSM::currentState must be sync with the PowerSrv::desiredPowerModeProfile (POWER_MODE_ACTIVE).
    248 	*/
    249 	pPowerSrvSM->currentState = POWER_SRV_STATE_ACTIVE;
    250     pPowerSrv->currentMode = USER_MODE;
    251     tmr_StopTimer (pPowerSrvSM->hPwrSrvSmTimer);
    252 
    253     /*init all request with init values*/
    254     powerSrvCreatePssRequest(hPowerSrv,
    255 							USER_MODE,
    256 							HANDLED_REQUEST,
    257 							POWER_SAVE_OFF,
    258 							TI_FALSE,
    259 							NULL,
    260 							NULL,
    261 							NULL);
    262     powerSrvCreatePssRequest(hPowerSrv,
    263 							DRIVER_MODE,
    264 							HANDLED_REQUEST,
    265 							POWER_SAVE_OFF,
    266 							TI_FALSE,
    267 							NULL,
    268 							NULL,
    269 							NULL);
    270 	pPowerSrv->userLastRequestMode = (powerSrvMode_e)POWER_SAVE_OFF;
    271     pPowerSrv->pCurrentRequest 	= & pPowerSrv->userRequest;
    272 
    273 	/*
    274 	register for Event
    275 	*/
    276 	eventMbox_RegisterEvent (pPowerSrv->hEventMbox,
    277 							 TWD_OWN_EVENT_PS_REPORT,
    278 							 (void *)powerSrv802_11PsReport,
    279 							 hPowerSrv);
    280 
    281 	eventMbox_UnMaskEvent (pPowerSrv->hEventMbox, TWD_OWN_EVENT_PS_REPORT, NULL, NULL);
    282 
    283     return TI_OK;
    284 }
    285 
    286 /****************************************************************************************
    287  *                        powerSrv_config                                                           *
    288  ****************************************************************************************
    289 DESCRIPTION: Power Server module configuration function, called by the MAC Services in configure phase
    290                 performs the following:
    291                 -   init the Power server to active state.
    292                 -   call the init function of the state machine.
    293 
    294 INPUT:      - hPowerSrv             - handle to the PowerSrv object.
    295             - pPowerSrvInitParams   - the Power Server initialize parameters.
    296 
    297 OUTPUT:
    298 RETURN:    TI_STATUS - TI_OK on success else TI_NOK.
    299 ****************************************************************************************/
    300 TI_STATUS powerSrv_config(  TI_HANDLE               hPowerSrv,
    301                             TPowerSrvInitParams    *pPowerSrvInitParams)
    302 {
    303     powerSrv_t* pPowerSrv = (powerSrv_t*)hPowerSrv;
    304 
    305     /*
    306     config PowerSrv state machine.
    307     */
    308     powerSrvSM_config(   pPowerSrv->hPowerSrvSM,
    309                          pPowerSrvInitParams);
    310 
    311     return TI_OK;
    312 }
    313 /****************************************************************************************
    314  *                        powerSrv_SetPsMode                                                            *
    315  ****************************************************************************************
    316 DESCRIPTION: This function is a user mode request from the Power Save Server.
    317               it will create a Request from the "USER_REQUEST" and will try to perform the user request for PS/Active.
    318               this will be done in respect of priority to Driver request.
    319 
    320 INPUT:      - hPowerSrv                         - handle to the PowerSrv object.
    321             - psMode                            - Power save/Active request
    322             - sendNullDataOnExit                -
    323             - powerSaveCBObject     - handle to the Callback function module.
    324             - powerSaveCompleteCB           - Callback function - for success/faild notification.
    325 OUTPUT:
    326 RETURN:    TI_STATUS - TI_OK / PENDING / TI_NOK.
    327 ****************************************************************************************/
    328 TI_STATUS powerSrv_SetPsMode(   TI_HANDLE                   hPowerSrv,
    329                                 E80211PsMode                psMode,
    330                                 TI_BOOL                        sendNullDataOnExit,
    331                                 void *                      powerSaveCBObject,
    332                                 powerSaveCmpltCB_t          powerSaveCompleteCB,
    333                                 powerSaveCmdResponseCB_t    powerSavecmdResponseCB)
    334 
    335 {
    336     powerSrv_t *pPowerSrv = (powerSrv_t*)hPowerSrv;
    337     TI_STATUS status;
    338 /*creating the request from type - "user"*/
    339     powerSrvCreatePssRequest(hPowerSrv,
    340                              USER_MODE,
    341                              NEW_REQUEST,
    342                              psMode,
    343                              sendNullDataOnExit,
    344                              powerSaveCBObject,
    345                              powerSaveCompleteCB,
    346                              powerSavecmdResponseCB);
    347 
    348 /*the request will be handled if the Power server is not in Driver mode.*/
    349     if ( pPowerSrv->currentMode==USER_MODE )
    350     {
    351         status = powerSrvProcessRequest(hPowerSrv,pPowerSrv->userRequest.requestMode);
    352     }
    353     else/*driver mode*/
    354     {
    355         pPowerSrv->userRequest.requestState = PENDING_REQUEST;
    356         status = POWER_SAVE_802_11_PENDING;
    357     }
    358     return status;
    359 
    360 }
    361 
    362 
    363 /****************************************************************************************
    364  *                        powerSrv_ReservePS                                                        *
    365  ****************************************************************************************
    366 DESCRIPTION: This function is a driver mode request to set the 802.11 Power Save state and reserve the module.
    367               The module should not be in driver mode when this request is made.
    368               If this function is called when the module is already in driver mode the result is unexpected.
    369               If the request cannot be fulfilled because of currently executing user mode request,
    370               then the function will return PENDING and the powerSaveCompleteCB function will be called when the request is fulfilled.
    371               If the request can be fulfilled immediately and the Power Save state required is the current state
    372               (This is always the case when PSMode = KEEP_CURRENT),
    373               then the module will be reserved and the function will return TI_OK - the callback function will not be called.??
    374               If the request can be fulfilled immediately and requires a Power Save state transition,
    375               then the return value will be TI_OK and the powerSaveCompleteCB function will be called by the Power Save Server
    376               when the request is complete.
    377 
    378 INPUT:      - hPowerSrv                         - handle to the PowerSrv object.
    379             - psMode                            - Power save/Active request
    380             - sendNullDataOnExit                -
    381             - powerSaveCBObject     - handle to the Callback function module.
    382             - powerSaveCompleteCB           - Callback function - for success/faild notification.
    383 OUTPUT:
    384 RETURN:    TI_STATUS - TI_OK / PENDING / TI_NOK.
    385 ****************************************************************************************/
    386 TI_STATUS powerSrv_ReservePS(   TI_HANDLE               hPowerSrv,
    387                                 E80211PsMode            psMode,
    388                                 TI_BOOL                    sendNullDataOnExit,
    389                                 void *                  powerSaveCBObject,
    390                                 powerSaveCmpltCB_t      powerSaveCompleteCB)
    391 {
    392     powerSrv_t *pPowerSrv = (powerSrv_t*)hPowerSrv;
    393     TI_STATUS status;
    394 
    395     /*creating the request from type - "driver"*/
    396     if ( psMode == POWER_SAVE_KEEP_CURRENT )
    397     {
    398         psMode = pPowerSrv->userRequest.psMode;
    399     }
    400 
    401     powerSrvCreatePssRequest(hPowerSrv,
    402                              DRIVER_MODE,
    403                              NEW_REQUEST,
    404                              psMode,
    405                              sendNullDataOnExit,
    406                              powerSaveCBObject,
    407                              powerSaveCompleteCB,
    408                              NULL);
    409     /*try to execute the request*/
    410     status = powerSrvProcessRequest(hPowerSrv,pPowerSrv->driverRequest.requestMode);
    411     return status;
    412 
    413 }
    414 
    415 
    416 /****************************************************************************************
    417  *                        powerSrv_ReleasePS                                                        *
    418  ****************************************************************************************
    419 DESCRIPTION: This function is used to release a previous driver mode request issued with the ReservPS API.
    420               it creates a Driver request and the server act like it is a normal driver request.
    421               the server will send the request with a simple optimization - if there is a pending or
    422               new user request - the request will be added in the driver request, in this way when the
    423               user request  will be executed there will be nothing to do, in the same manner if there
    424               are no user / driver request to execute we will send the last user request in Driver mode.
    425 
    426 
    427 
    428 
    429 INPUT:      - hPowerSrv                         - handle to the PowerSrv object.
    430             - sendNullDataOnExit                -
    431             - powerSaveCBObject     - handle to the Callback function module.
    432             - powerSaveCompleteCB           - Callback function - for success/faild notification.
    433 OUTPUT:
    434 RETURN:    TI_STATUS - TI_OK / PENDING / TI_NOK.
    435 ****************************************************************************************/
    436 TI_STATUS powerSrv_ReleasePS(   TI_HANDLE                   hPowerSrv,
    437                                 TI_BOOL                        sendNullDataOnExit,
    438                                 void *                          powerSaveCBObject,
    439                                 powerSaveCmpltCB_t              powerSaveCompleteCB)
    440 {
    441     powerSrv_t *pPowerSrv = (powerSrv_t*)hPowerSrv;
    442     TI_STATUS status;
    443 
    444     /*creating the request from type - "driver"*/
    445 
    446     if (pPowerSrv->driverRequest.requestMode == POWER_SAVE_802_11_PENDING)
    447     {
    448         powerSrvCreatePssRequest(hPowerSrv,
    449                                  DRIVER_MODE,
    450                                  HANDLED_REQUEST,
    451                                  POWER_SAVE_OFF,
    452                                  TI_FALSE,
    453                                  NULL,
    454                                  NULL,
    455                                  NULL);
    456         return POWER_SAVE_802_11_IS_CURRENT;
    457     }
    458 
    459     /*creating the request from type - "driver"*/
    460     powerSrvCreatePssRequest(hPowerSrv,
    461                              DRIVER_MODE,
    462                              NEW_REQUEST,
    463                              POWER_SAVE_KEEP_CURRENT,
    464                              sendNullDataOnExit,
    465                              powerSaveCBObject,
    466                              powerSaveCompleteCB,
    467                              NULL);
    468     if ( pPowerSrv->userRequest.requestState == NEW_REQUEST ||
    469          pPowerSrv->userRequest.requestState == PENDING_REQUEST )
    470     {
    471         pPowerSrv->driverRequest.psMode = pPowerSrv->userRequest.psMode;
    472     }
    473     else
    474     {
    475         pPowerSrv->driverRequest.psMode = (E80211PsMode)pPowerSrv->userLastRequestMode;
    476     }
    477 
    478 
    479 
    480     status = powerSrvProcessRequest(hPowerSrv,pPowerSrv->driverRequest.requestMode);
    481     /*if the request was not executed we should not change the mode*/
    482     if (status != POWER_SAVE_802_11_PENDING)
    483     {
    484         pPowerSrv->currentMode = USER_MODE;
    485     }
    486     return status;
    487 }
    488 
    489 
    490 
    491 /****************************************************************************************
    492  *                        powerSrv_getPsStatus                                                       *
    493  *****************************************************************************************
    494 DESCRIPTION: This function returns the true state of power.
    495 
    496 INPUT:      - hPowerSrv                         - handle to the PowerSrv object.
    497 
    498 OUTPUT:
    499 RETURN:    TI_BOOL - true if the SM is in PS state -  false otherwise
    500 ****************************************************************************************/
    501 TI_BOOL powerSrv_getPsStatus(TI_HANDLE hPowerSrv)
    502 {
    503     powerSrv_t *pPowerSrv = (powerSrv_t*)hPowerSrv;
    504     PowerSrvSMStates_e smState;
    505     smState = powerSrvSM_getCurrentState(pPowerSrv->hPowerSrvSM);
    506     return(smState == POWER_SRV_STATE_PS );
    507 }
    508 
    509 
    510 /****************************************************************************************
    511 *                        powerSrv_SetRateModulation                                                         *
    512 *****************************************************************************************
    513 DESCRIPTION: Sets the rate modulation according to the current Radio Mode.
    514 
    515 INPUT:      - hPowerSrv                         - handle to the PowerSrv object.
    516            - dot11mode_e - The current radio mode (A or G)
    517 
    518 OUTPUT:
    519 RETURN:    TI_BOOL - true if the SM is in PS state -  false otherwise
    520 ****************************************************************************************/
    521 void powerSrv_SetRateModulation(TI_HANDLE hPowerSrv, TI_UINT16  rate)
    522 {
    523     powerSrv_t *pPowerSrv = (powerSrv_t*)hPowerSrv;
    524     powerSrvSM_setRateModulation(pPowerSrv->hPowerSrvSM,rate);
    525 
    526     return;
    527 }
    528 
    529 /**
    530  * \Gets the rate modulation.
    531  *
    532  * Function Scope \e Public.\n
    533  * Parameters:\n
    534  * 1) TI_HANDLE - handle to the PowerSrvSM object.\n
    535  * 2) dot11mode_e - The current radio mode (A or G)
    536  * Return: None.\n
    537  */
    538 TI_UINT32 powerSrv_GetRateModulation(TI_HANDLE hPowerSrv)
    539 {
    540     powerSrv_t *pPowerSrv = (powerSrv_t*)hPowerSrv;
    541     return powerSrvSM_getRateModulation(pPowerSrv->hPowerSrvSM);
    542 }
    543 
    544 
    545 
    546 
    547 /*****************************************************************************
    548  **         Private Function prototypes                                                             **
    549  *****************************************************************************/
    550 
    551 
    552 /****************************************************************************************
    553  *                        powerSrv802_11PsReport                                                    *
    554  ****************************************************************************************
    555 DESCRIPTION:  This function is the call back for the TWD control when a PS event triggered
    556               This function is responsible for the process "keep alive".
    557               the function handles the event and sends it to the state machine, after sending the events
    558               the function handles the next request with respect to driver request priority.
    559               if a request is already done then we will call the request call back (if exist!).
    560 
    561 
    562 
    563 
    564 INPUT:      - hPowerSrv                         - handle to the PowerSrv object.
    565             - str                               - Event string
    566             - strLen                            - string length
    567 
    568 OUTPUT:
    569 RETURN:    void.
    570 ****************************************************************************************/
    571 static void powerSrv802_11PsReport(TI_HANDLE hPowerSrv, char* str , TI_UINT32 strLen)
    572 {
    573     powerSrv_t *    pPowerSrv = (powerSrv_t*)hPowerSrv;
    574     TI_UINT8           PowerSaveStatus;
    575     E80211PsMode    currentPsMode;
    576     TI_STATUS       status = TI_OK;
    577 
    578     /*copy the event*/
    579     os_memoryCopy(pPowerSrv->hOS, (void *)&PowerSaveStatus, (void *)str, strLen);
    580 
    581     TRACE1( pPowerSrv->hReport, REPORT_SEVERITY_INFORMATION, "PS callback with status: %d\n", PowerSaveStatus);
    582 
    583     /* Handling the event*/
    584     switch ( (EventsPowerSave_e)PowerSaveStatus )
    585     {
    586     case ENTER_POWER_SAVE_FAIL:
    587     case EXIT_POWER_SAVE_FAIL:
    588         TRACE0( pPowerSrv->hReport, REPORT_SEVERITY_WARNING, "Power save enter or exit failed!\n");
    589         powerSrvSM_SMApi(pPowerSrv->hPowerSrvSM,POWER_SRV_EVENT_FAIL);
    590         break;
    591 
    592     case ENTER_POWER_SAVE_SUCCESS:
    593 	case EXIT_POWER_SAVE_SUCCESS:
    594         powerSrvSM_SMApi(pPowerSrv->hPowerSrvSM,POWER_SRV_EVENT_SUCCESS);
    595         /*update the last user request if the request was a user request*/
    596         if ( pPowerSrv->currentMode == USER_MODE )
    597         {
    598             pPowerSrv->userLastRequestMode= (powerSrvMode_e)pPowerSrv->userRequest.psMode;
    599         }
    600         break;
    601 
    602     default:
    603         TRACE1( pPowerSrv->hReport, REPORT_SEVERITY_ERROR, "Unrecognized status at PS callback %d\n", PowerSaveStatus );
    604         break;
    605     }
    606 
    607     /*this reflects the true power save state - power save IFF state machine in PS state.*/
    608     if ( (EventsPowerSave_e)PowerSaveStatus == ENTER_POWER_SAVE_SUCCESS )
    609     {
    610         currentPsMode = POWER_SAVE_ON;
    611     }
    612     else
    613     {
    614         currentPsMode = POWER_SAVE_OFF;
    615     }
    616 
    617     /*in case of  request has been already handled - calling the CB*/
    618     if ( pPowerSrv->pCurrentRequest->requestState == HANDLED_REQUEST )
    619     {
    620         if ( pPowerSrv->pCurrentRequest->powerSrvCompleteCB != NULL )
    621         {
    622             pPowerSrv->pCurrentRequest->powerSrvCompleteCB( pPowerSrv->pCurrentRequest->powerSaveCBObject,
    623                                                             currentPsMode,
    624                                                             (EventsPowerSave_e)PowerSaveStatus);
    625 
    626         }
    627     }
    628 
    629     /*starting again to handle waiting requests  */
    630     /*priority to driver request*/
    631     if ( pPowerSrv->driverRequest.requestState == NEW_REQUEST ||
    632          pPowerSrv->driverRequest.requestState == PENDING_REQUEST )
    633     {
    634         status = powerSrvProcessRequest(hPowerSrv,pPowerSrv->driverRequest.requestMode);
    635     }
    636     else/*user request*/
    637     {
    638         if ( pPowerSrv->currentMode==USER_MODE )
    639         {
    640             if ( pPowerSrv->userRequest.requestState == NEW_REQUEST||
    641                  pPowerSrv->userRequest.requestState == PENDING_REQUEST )
    642             {
    643                 status = powerSrvProcessRequest(hPowerSrv,pPowerSrv->userRequest.requestMode);
    644             }
    645 
    646         }
    647     }
    648     if ( status == POWER_SAVE_802_11_IS_CURRENT )/*in case of already or habdled*/
    649     {
    650         if ( pPowerSrv->pCurrentRequest->powerSrvCompleteCB != NULL )
    651         {
    652             pPowerSrv->pCurrentRequest->powerSrvCompleteCB(pPowerSrv->pCurrentRequest->powerSaveCBObject,
    653                                                            pPowerSrv->pCurrentRequest->psMode,
    654                                                            ((pPowerSrv->pCurrentRequest->psMode == POWER_SAVE_ON) ?
    655                                                             ENTER_POWER_SAVE_SUCCESS :
    656                                                             EXIT_POWER_SAVE_SUCCESS));
    657         }
    658     }
    659 
    660 
    661 }
    662 
    663 
    664 /****************************************************************************************
    665  *                        powerSrvProcessRequest                                                    *
    666  ****************************************************************************************
    667 DESCRIPTION: This function receive the request before sending it to the state machine, checks if it
    668               possible to be applied and pass it to the state machine.
    669 
    670 
    671 
    672 INPUT:      - hPowerSrv                         - handle to the PowerSrv object.
    673             - requestMode                   - Driver or User mode
    674 
    675 
    676 OUTPUT:
    677 RETURN:    TI_STATUS - TI_OK / PENDING / TI_NOK.
    678 ****************************************************************************************/
    679 TI_STATUS powerSrvProcessRequest (TI_HANDLE hPowerSrv, powerSrvMode_e requestMode)
    680 {
    681     PowerSrvSMStates_e powerSrvSmState;
    682     powerSrvRequest_t*      pPrcessedRequest;
    683     TI_STATUS smApiStatus;
    684     powerSrv_t *pPowerSrv = (powerSrv_t*)hPowerSrv;
    685 
    686 
    687 
    688 /*determine what is the current request*/
    689     if ( requestMode == DRIVER_MODE )
    690     {
    691         pPrcessedRequest = &(pPowerSrv->driverRequest);
    692     }
    693     else
    694     {
    695         pPrcessedRequest = &(pPowerSrv->userRequest);
    696     }
    697 
    698 /*in case that the state machine is in a pending state and it is a driver
    699    request we will return Pending and not call the SM. the request will
    700    be processed in the next event - according to the 802_11_Report.*/
    701     powerSrvSmState = powerSrvSM_getCurrentState(pPowerSrv->hPowerSrvSM);
    702 
    703     if ( (powerSrvSmState == POWER_SRV_STATE_PEND_ACTIVE ||
    704           powerSrvSmState == POWER_SRV_STATE_PEND_PS) &&
    705          pPowerSrv->pCurrentRequest->requestMode == DRIVER_MODE )
    706     {
    707         pPrcessedRequest->requestState = PENDING_REQUEST;
    708         return POWER_SAVE_802_11_PENDING;
    709     }
    710     /*Set the correct request to the SM*/
    711     powerSrvSm_setSmRequest(pPowerSrv->hPowerSrvSM ,pPrcessedRequest);
    712 
    713     /*call the SM with the correct request*/
    714 
    715     if ( pPrcessedRequest->psMode == POWER_SAVE_ON )
    716     {
    717         smApiStatus = powerSrvSM_SMApi(pPowerSrv->hPowerSrvSM,POWER_SRV_EVENT_REQUEST_PS);
    718     }
    719     else
    720     {
    721         smApiStatus = powerSrvSM_SMApi(pPowerSrv->hPowerSrvSM,POWER_SRV_EVENT_REQUEST_ACTIVE);
    722     }
    723 
    724     /*if =! pending updating the current request pointer.*/
    725     if ( pPrcessedRequest->requestState != PENDING_REQUEST )
    726     {
    727         pPowerSrv->pCurrentRequest = pPrcessedRequest;
    728         pPowerSrv->currentMode = pPowerSrv->pCurrentRequest->requestMode;
    729     }
    730 
    731 
    732     return smApiStatus;
    733 }
    734 
    735 
    736 /****************************************************************************************
    737  *                        powerSrvCreatePssRequest                                                  *
    738  ****************************************************************************************
    739 DESCRIPTION: This function create a request acording to it's type:
    740                                                         - User
    741                                                         -Driver
    742 
    743 
    744 INPUT:      - hPowerSrv                         - handle to the PowerSrv object.
    745             - requestMode                   - request type : Driver/User
    746             - psMode                            - Power save/Active request
    747             - sendNullDataOnExit                -
    748             - powerSaveCBObject     - handle to the Callback functin module.
    749             - powerSaveCompleteCB           - Calback function - for success/faild notification.
    750 
    751 OUTPUT:
    752 RETURN:    void.
    753 ****************************************************************************************/
    754 void powerSrvCreatePssRequest (TI_HANDLE                    hPowerSrv,
    755                                powerSrvMode_e              requestMode,
    756                                powerSrvRequestState_e      requestState,
    757                                E80211PsMode                psMode,
    758                                TI_BOOL                        sendNullDataOnExit,
    759                                void *                      powerSaveCBObject,
    760                                powerSaveCmpltCB_t          powerSaveCompleteCB,
    761                                powerSaveCmdResponseCB_t    powerSaveCmdResponseCB)
    762 {
    763     powerSrv_t *pPowerSrv = (powerSrv_t*)hPowerSrv;
    764     if ( requestMode==USER_MODE )
    765     {
    766         pPowerSrv->userRequest.requestState             = requestState;
    767         pPowerSrv->userRequest.requestMode              = requestMode;
    768         pPowerSrv->userRequest.psMode                   = psMode;
    769         pPowerSrv->userRequest.sendNullDataOnExit           = sendNullDataOnExit;
    770         pPowerSrv->userRequest.powerSaveCBObject            = powerSaveCBObject;
    771         pPowerSrv->userRequest.powerSrvCompleteCB       = powerSaveCompleteCB;
    772         pPowerSrv->userRequest.powerSaveCmdResponseCB   = powerSaveCmdResponseCB;
    773     }
    774     else /*driver request*/
    775     {
    776         pPowerSrv->driverRequest.requestState               = requestState;
    777         pPowerSrv->driverRequest.requestMode                = requestMode;
    778         pPowerSrv->driverRequest.psMode                 = psMode;
    779         pPowerSrv->driverRequest.sendNullDataOnExit             = sendNullDataOnExit;
    780         pPowerSrv->driverRequest.powerSaveCBObject      = powerSaveCBObject;
    781         pPowerSrv->driverRequest.powerSrvCompleteCB         = powerSaveCompleteCB;
    782         pPowerSrv->driverRequest.powerSaveCmdResponseCB     = NULL;
    783     }
    784 }
    785 
    786 
    787 
    788 /****************************************************************************************
    789  *                        powerSrvRegisterFailureEventCB                                                    *
    790  ****************************************************************************************
    791 DESCRIPTION: Registers a failure event callback for scan error notifications.
    792 
    793 
    794 INPUT:      - hPowerSrv         - handle to the PowerSrv object.
    795             - failureEventCB    - the failure event callback function.\n
    796             - hFailureEventObj - handle to the object passed to the failure event callback function.
    797 
    798 OUTPUT:
    799 RETURN:    void.
    800 ****************************************************************************************/
    801 void powerSrvRegisterFailureEventCB( TI_HANDLE hPowerSrv,
    802                                      void * failureEventCB, TI_HANDLE hFailureEventObj )
    803 {
    804     powerSrv_t *pPowerSrv = (powerSrv_t*)hPowerSrv;
    805 
    806     pPowerSrv->failureEventFunc = (TFailureEventCb)failureEventCB;
    807     pPowerSrv->failureEventObj  = hFailureEventObj;
    808 
    809     /* register the failure event CB also with the PS SM */
    810     powerSrvSM_RegisterFailureEventCB( pPowerSrv->hPowerSrvSM, failureEventCB, hFailureEventObj );
    811 }
    812 
    813