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