summaryrefslogtreecommitdiff
path: root/wilink_6_1/TWD/MacServices/PowerSrvSM.c
blob: 173a080fad190d715e75b5bf28786327f676d447 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
/*
 * PowerSrvSM.c
 *
 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.      
 * All rights reserved.                                                  
 *                                                                       
 * Redistribution and use in source and binary forms, with or without    
 * modification, are permitted provided that the following conditions    
 * are met:                                                              
 *                                                                       
 *  * Redistributions of source code must retain the above copyright     
 *    notice, this list of conditions and the following disclaimer.      
 *  * Redistributions in binary form must reproduce the above copyright  
 *    notice, this list of conditions and the following disclaimer in    
 *    the documentation and/or other materials provided with the         
 *    distribution.                                                      
 *  * Neither the name Texas Instruments nor the names of its            
 *    contributors may be used to endorse or promote products derived    
 *    from this software without specific prior written permission.      
 *                                                                       
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/** \file PowerSrvSM.c
 *  \brief This is the PowerSrvSM module implementation.
 *  \author Assaf Azulay
 *  \date 19-OCT-2005
 */

/****************************************************************************
 *                                                                          *
 *   MODULE:  PowerSrvSM                                                    *
 *   PURPOSE: PowerSrvSM Module implementation.                             *
 *                                                                          *
 ****************************************************************************/

#define __FILE_ID__  FILE_ID_114
#include "tidef.h"
#include "osApi.h"
#include "timer.h"
#include "fsm.h"
#include "report.h"
#include "TWDriver.h"
#include "PowerSrvSM.h"
#include "CmdBld.h"


/*****************************************************************************
 **         Defines                                                         **
 *****************************************************************************/


/*****************************************************************************
 **         structs                                                         **
 *****************************************************************************/


/*****************************************************************************
 **         Private Function prototypes                                     **
 *****************************************************************************/

static TI_STATUS powerSrvSmSMEvent(TI_UINT8* pCurrentState,
                                   TI_UINT8 event,
                                   TI_HANDLE hPowerSrvSM);
static TI_STATUS powerSrvSmDoUpdateRequest(TI_HANDLE hPowerSrvSM);
static TI_STATUS powerSrvSmDoEnterPowerSave(TI_HANDLE hPowerSrvSM);
static TI_STATUS powerSrvSmDoExitPowerSave(TI_HANDLE hPowerSrvSM);
static TI_STATUS powerSrvSmDoPending(TI_HANDLE hPowerSrvSM);
static TI_STATUS powerSrvSmDoAllready(TI_HANDLE hPowerSrvSM);
static TI_STATUS powerSrvSMActionUnexpected(TI_HANDLE hPowerSrvSM);
static TI_STATUS powerSrvSMSendMBXConfiguration(TI_HANDLE hPowerSrvSM, TI_BOOL PS_disableEnable);
static void      powerSrvSMTimerExpired (TI_HANDLE hPowerSrvSM, TI_BOOL bTwdInitOccured);

/***************************************************************************************
 **         Public Function prototypes                                      **
 ****************************************************************************************/


/****************************************************************************************
 *                        powerSrvSM_create                                                         *
 ****************************************************************************************
DESCRIPTION: Power Server SM module creation function, called by the Power Server create in creation phase 
                performs the following:
                -   Allocate the Power Server SM handle
                -   Creates the fsm.
                                                                                                                   
INPUT:          - hOs - Handle to OS        


OUTPUT:     

RETURN:     Handle to the Power Server SM module on success, NULL otherwise
****************************************************************************************/
TI_HANDLE powerSrvSM_create(TI_HANDLE hOsHandle)
{
    PowerSrvSM_t *pPowerSrvSM = NULL;
    fsm_stateMachine_t *pFsm = NULL;
    TI_STATUS status;

    pPowerSrvSM = (PowerSrvSM_t*) os_memoryAlloc (hOsHandle, sizeof(PowerSrvSM_t));
    if ( pPowerSrvSM == NULL )
    {
        WLAN_OS_REPORT(("%s(%d) - Memory Allocation Error!\n",__FUNCTION__,__LINE__));
        return NULL;
    }

    os_memoryZero (hOsHandle, pPowerSrvSM, sizeof(PowerSrvSM_t));

    pPowerSrvSM->hOS = hOsHandle;

    /* create the generic state-machine */
    status = fsm_Create(hOsHandle,
                        &pFsm,
                        (TI_UINT8)POWER_SRV_SM_STATE_NUM,
                        (TI_UINT8)POWER_SRV_SM_EVENT_NUM);
    if ( status != TI_OK )
    {
        WLAN_OS_REPORT(("%s(%d) - Error in create FSM!\n",__FUNCTION__,__LINE__));
        powerSrvSM_destroy(pPowerSrvSM);
        return NULL;
    }

    pPowerSrvSM->hFSM = (TI_HANDLE)pFsm;

    return pPowerSrvSM;
}

 
/****************************************************************************************
 *                        powerSrvSM_destroy                                                            *
 ****************************************************************************************
DESCRIPTION: Power Server SM module destroy function, 
                -   delete Power Server SM allocation
                
                                                                                                                   
INPUT:          - hPowerSrvSM - Handle to the Power Server  SM


OUTPUT:     

RETURN:    TI_STATUS - TI_OK on success else TI_NOK.
****************************************************************************************/
TI_STATUS powerSrvSM_destroy(TI_HANDLE hPowerSrvSM)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;

    TI_HANDLE osHandle = pPowerSrvSM->hOS;

    /* free the timer */
    if (pPowerSrvSM->hPwrSrvSmTimer)
    {
        tmr_DestroyTimer (pPowerSrvSM->hPwrSrvSmTimer);
    }

    /* free the generic SM */
    if ( pPowerSrvSM->hFSM != NULL )
    {
        fsm_Unload(osHandle, (fsm_stateMachine_t*)pPowerSrvSM->hFSM);
    }

    /* free the Power Save SRV object */
    os_memoryFree(osHandle , pPowerSrvSM , sizeof(PowerSrvSM_t));

    return TI_OK;
}


/****************************************************************************************
*                        powerSrvSM_init                                                           *
****************************************************************************************
DESCRIPTION: Power Server SM module initialize function, called by the Power Server init in configure phase 
               performs the following:
               -   init the Stet machine states.
               -   set Active as start state.
                                                                                                                  
INPUT:     - hPowerSrvSM       - handle to the PowerSrvSM object.
           - hReport           - handle to the Report object.
           - hCmdBld           - handle to the Command Builder object.    
           - hTimer            - handle to the Timer module object.    

OUTPUT: 
RETURN:    TI_STATUS - TI_OK on success else TI_NOK.
****************************************************************************************/
TI_STATUS powerSrvSM_init (TI_HANDLE hPowerSrvSM,
                           TI_HANDLE hReport,
                           TI_HANDLE hCmdBld,
                           TI_HANDLE hTimer)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;

    fsm_actionCell_t smMatrix[POWER_SRV_SM_STATE_NUM][POWER_SRV_SM_EVENT_NUM] =
    {
        /*
        next state and transition action for POWER_SRV_STATE_ACTIVE state
        */
        {
            /* POWER_SRV_EVENT_REQUEST_ACTIVE */
            {POWER_SRV_STATE_ACTIVE             , powerSrvSmDoAllready},

            /* POWER_SRV_EVENT_REQUEST_PS */
            {POWER_SRV_STATE_PEND_PS                , powerSrvSmDoEnterPowerSave},

            /* POWER_SRV_EVENT_SUCCESS */
            {POWER_SRV_STATE_ACTIVE                 , powerSrvSMActionUnexpected},

            /* POWER_SRV_EVENT_FAIL */
            {POWER_SRV_STATE_ACTIVE                 , powerSrvSMActionUnexpected}

        },

        /*
        next state and transition action for POWER_SRV_STATE_PEND_PS state
        */
        {
            /* POWER_SRV_EVENT_REQUEST_ACTIVE */
            {POWER_SRV_STATE_PEND_PS            , powerSrvSmDoPending},

            /* POWER_SRV_EVENT_REQUEST_PS */
            {POWER_SRV_STATE_PEND_PS        , powerSrvSmDoPending},

            /* POWER_SRV_EVENT_SUCCESS */
            {POWER_SRV_STATE_PS                 , powerSrvSmDoUpdateRequest},

            /* POWER_SRV_EVENT_FAIL */
            {POWER_SRV_STATE_ACTIVE             , powerSrvSmDoUpdateRequest}

        },
        /*
        next state and transition action for POWER_SRV_STATE_PS state
        */
        {
            /* POWER_SRV_EVENT_REQUEST_ACTIVE */
            {POWER_SRV_STATE_PEND_ACTIVE        , powerSrvSmDoExitPowerSave},

            /* POWER_SRV_EVENT_REQUEST_PS */
            {POWER_SRV_STATE_PS                 , powerSrvSmDoAllready},

            /* POWER_SRV_EVENT_SUCCESS */
            {POWER_SRV_STATE_PS                 , powerSrvSMActionUnexpected},

            /* POWER_SRV_EVENT_FAIL */
            {POWER_SRV_STATE_PS                 , powerSrvSMActionUnexpected}

        },
        /*
        next state and transition action for POWER_SRV_STATE_PEND_ACTIVE state
        */
        {
            /* POWER_SRV_EVENT_REQUEST_ACTIVE */
            {POWER_SRV_STATE_PEND_ACTIVE            , powerSrvSmDoPending},

            /* POWER_SRV_EVENT_REQUEST_PS */
            {POWER_SRV_STATE_PEND_ACTIVE        , powerSrvSmDoPending},

            /* POWER_SRV_EVENT_SUCCESS */
            {POWER_SRV_STATE_ACTIVE             , powerSrvSmDoUpdateRequest},

            /* POWER_SRV_EVENT_FAIL */
            {POWER_SRV_STATE_ERROR_ACTIVE       , powerSrvSmDoUpdateRequest}

        },
        /*
        next state and transition action for POWER_SRV_STATE_ERROR_ACTIVE state
        */
        {
            /* POWER_SRV_EVENT_REQUEST_ACTIVE */
            {POWER_SRV_STATE_PEND_ACTIVE            , powerSrvSmDoExitPowerSave},

            /* POWER_SRV_EVENT_REQUEST_PS */
            {POWER_SRV_STATE_PEND_PS        , powerSrvSmDoEnterPowerSave},

            /* POWER_SRV_EVENT_SUCCESS */
            {POWER_SRV_STATE_ERROR_ACTIVE       , powerSrvSMActionUnexpected},

            /* POWER_SRV_EVENT_FAIL */
            {POWER_SRV_STATE_ERROR_ACTIVE       , powerSrvSMActionUnexpected}

        },

    };

    pPowerSrvSM->hReport = hReport;
    pPowerSrvSM->hCmdBld = hCmdBld;
    pPowerSrvSM->hTimer  = hTimer;

    /* create the timer */
    pPowerSrvSM->hPwrSrvSmTimer = tmr_CreateTimer (pPowerSrvSM->hTimer);
	if (pPowerSrvSM->hPwrSrvSmTimer == NULL)
	{
        TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_ERROR, "powerSrvSM_init(): Failed to create hPwrSrvSmTimer!\n");
		return TI_NOK;
	}

    fsm_Config(pPowerSrvSM->hFSM,
               (fsm_Matrix_t)smMatrix,
               POWER_SRV_SM_STATE_NUM,
               POWER_SRV_SM_EVENT_NUM,
               powerSrvSmSMEvent,
               pPowerSrvSM->hOS);

    /*
    the PowerSrvSM start in active mode (POWER_SRV_STATE_ACTIVE)
    the PowerSrvSM::currentState must be sync with the PowerSrv::desiredPowerModeProfile (POWER_MODE_ACTIVE).
    */
    pPowerSrvSM->currentState = POWER_SRV_STATE_ACTIVE;


    /*
    Null packet rate : 2,5.5 M
    Probe Request : Not PBCC modulation, Long Preamble */
    pPowerSrvSM->NullPktRateModulation= (DRV_RATE_MASK_1_BARKER | DRV_RATE_MASK_2_BARKER); 

    TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_INIT, "PowerSrvSM Initialized\n");

    return TI_OK;
}

/****************************************************************************************
*                        powerSrvSM_config                                                         *
****************************************************************************************
DESCRIPTION: Power Server SM module configuration function, called by the Power Server init in configure phase 
               performs the following:
               -   init the Stet machine states.
               -   set Active as start state.
                                                                                                                  
INPUT:      - hPowerSrvSM       - handle to the PowerSrvSM object.  
           - pPowerSrvInitParams   - the Power Server initialize parameters.

OUTPUT: 
RETURN:    TI_STATUS - TI_OK on success else TI_NOK.
****************************************************************************************/
TI_STATUS powerSrvSM_config(TI_HANDLE hPowerSrvSM,
                            TPowerSrvInitParams *pPowerSrvInitParams)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;

    /*
    init PowerMgmtConfigration
    */
    pPowerSrvSM->hangOverPeriod =   pPowerSrvInitParams->hangOverPeriod;
    pPowerSrvSM->numNullPktRetries =    pPowerSrvInitParams->numNullPktRetries;

    return TI_OK;
}
/****************************************************************************************
 *                        powerSrvSM_SMApi                                                           *
 *****************************************************************************************
DESCRIPTION: This function triggers events from the outside of the module into the state machine.
              
                                                                                                                                                                       
INPUT:      - hPowerSrvSM                   - handle to the PowerSrvSM object.  
            - theSMEvent                    - event from TWD.
            

OUTPUT: 
RETURN:    TI_STATUS TI_OK / PENDING / TI_NOK
****************************************************************************************/
TI_STATUS powerSrvSM_SMApi(TI_HANDLE hPowerSrvSM,
                           PowerSrvSMEvents_e theSMEvent)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;
    TI_STATUS status;

    switch ( theSMEvent )
    {
    case POWER_SRV_EVENT_REQUEST_ACTIVE :
    case POWER_SRV_EVENT_REQUEST_PS :
    case POWER_SRV_EVENT_FAIL :
    case POWER_SRV_EVENT_SUCCESS :

        TRACE1(pPowerSrvSM->hReport, REPORT_SEVERITY_INFORMATION, "powerSrvSM_SMApi(%d) called - legal input parameter.\n",theSMEvent);
        break;

    default:
        TRACE1(pPowerSrvSM->hReport, REPORT_SEVERITY_WARNING, "powerSrvSM_SMApi(%d) called,                            input parameter is illegal.",theSMEvent);
        return TI_NOK;
    }


    status = powerSrvSmSMEvent((TI_UINT8*)&pPowerSrvSM->currentState,
                               (TI_UINT8)theSMEvent,
                               hPowerSrvSM);

    return status;
}


/****************************************************************************************
 *                        powerSrvSm_setSmRequest                                                    *
 *****************************************************************************************
DESCRIPTION: This function sets the current SM working request.
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.
            -powerSrvRequest_t*                 - pointer to the correct request in the Power server.

OUTPUT: 
RETURN:    TI_STATUS -  TI_OK
****************************************************************************************/
TI_STATUS powerSrvSm_setSmRequest(TI_HANDLE hPowerSrvSM,powerSrvRequest_t* pSmRequest)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;
    pPowerSrvSM->pSmRequest = pSmRequest;
    return TI_OK;
}


/****************************************************************************************
 *                        powerSrvSM_getCurrentState                                                         *
 *****************************************************************************************
DESCRIPTION: This function returns the current state of the SM.
                                                       
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.      
            

OUTPUT: 
RETURN:    PowerSrvSMStates_e current state
****************************************************************************************/
PowerSrvSMStates_e powerSrvSM_getCurrentState(TI_HANDLE hPowerSrvSM)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;

    return pPowerSrvSM->currentState; 
}

/****************************************************************************************
 *                        powerSrvSM_setRateModulation                                               *
 *****************************************************************************************
DESCRIPTION: This function sets the Rate Modulation
                                                       
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.      
            - rateModulation                        - desired rate

OUTPUT: 
RETURN:      void
****************************************************************************************/

void powerSrvSM_setRateModulation(TI_HANDLE hPowerSrvSM, TI_UINT16 rateModulation)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;
    pPowerSrvSM->NullPktRateModulation= rateModulation; 
}

/****************************************************************************************
 *                        powerSrvSM_getRateModulation                                               *
 *****************************************************************************************
DESCRIPTION: This function sets the Rate Modulation
                                                       
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.      

OUTPUT: 
RETURN:      -  desired rate
****************************************************************************************/

TI_UINT32 powerSrvSM_getRateModulation(TI_HANDLE hPowerSrvSM)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;
    return pPowerSrvSM->NullPktRateModulation;
}

/****************************************************************************************
 *                        powerSrvSM_printObject                                                         *
 *****************************************************************************************
DESCRIPTION: This function prints the SM object
                                                       
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.      
            

OUTPUT: 
RETURN:   void
****************************************************************************************/
void powerSrvSM_printObject(TI_HANDLE hPowerSrvSM)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;
    char *pString;

    WLAN_OS_REPORT(("\n+++++ powerSrvSM_printObject +++++\n"));
    WLAN_OS_REPORT(("Handle to the CmdBld is 0x%08X\n", pPowerSrvSM->hCmdBld));
    WLAN_OS_REPORT(("Handle to the OS is 0x%08X\n", pPowerSrvSM->hOS));
    WLAN_OS_REPORT(("Handle to the Report is 0x%08X\n", pPowerSrvSM->hReport));
    WLAN_OS_REPORT(("Handle to the FSM is 0x%08X\n", pPowerSrvSM->hFSM));

    switch ( pPowerSrvSM->currentState )
    {
    case POWER_SRV_STATE_ACTIVE:
        pString = "POWER_SRV_STATE_ACTIVE";
        break;

    case POWER_SRV_STATE_PEND_PS:
        pString = "POWER_SRV_STATE_PEND_PS";
        break;

    case POWER_SRV_STATE_PS:
        pString = "POWER_SRV_STATE_PS";
        break;

    case POWER_SRV_STATE_PEND_ACTIVE:
        pString = "POWER_SRV_STATE_PEND_ACTIVE";
        break;

    case POWER_SRV_STATE_ERROR_ACTIVE:
        pString = "POWER_SRV_STATE_ERROR_ACTIVE";
        break;


    default:
        pString = "UNKWON PARAMETER";
        break;
    }
    WLAN_OS_REPORT(("The current state of the state machine is %s (=%d)\n",
                    pString,
                    pPowerSrvSM->currentState));

}




/*****************************************************************************
 **         Private Function prototypes                                                             **
 *****************************************************************************/






/****************************************************************************************
 *                        powerSrvSmDoEnterPowerSave                                                 *
 *****************************************************************************************
DESCRIPTION: This function is an action of the state machine to move from active state to PS
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.

OUTPUT: 
RETURN:    TI_STATUS - TI_OK / TI_NOK
****************************************************************************************/

static TI_STATUS powerSrvSmDoEnterPowerSave(TI_HANDLE hPowerSrvSM)
{
    TI_STATUS status;
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;
    pPowerSrvSM->pSmRequest->requestState = RUNNING_REQUEST;
    status = powerSrvSMSendMBXConfiguration(hPowerSrvSM, TI_TRUE);
    return status;
}


/****************************************************************************************
 *                        powerSrvSmDoExitPowerSave                                              *
 *****************************************************************************************
DESCRIPTION: This function is an action of the state machine to move from PS state to Active
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.

OUTPUT: 
RETURN:    TI_STATUS - TI_OK / TI_NOK
****************************************************************************************/
static TI_STATUS powerSrvSmDoExitPowerSave(TI_HANDLE hPowerSrvSM)
{
    TI_STATUS status;
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;
    pPowerSrvSM->pSmRequest->requestState = RUNNING_REQUEST;
    status = powerSrvSMSendMBXConfiguration(hPowerSrvSM, TI_FALSE);
    return status;
}


/****************************************************************************************
 *                        powerSrvSmDoUpdateRequest                                                  *
 *****************************************************************************************
DESCRIPTION: This function is an action of the state machine to update a request when the SM 
              is already in the requested state is already 
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.

OUTPUT: 
RETURN:    TI_STATUS - TI_OK / TI_NOK
****************************************************************************************/

static TI_STATUS powerSrvSmDoUpdateRequest(TI_HANDLE hPowerSrvSM)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;

    /* request has completed - stop the guard timer */
    tmr_StopTimer (pPowerSrvSM->hPwrSrvSmTimer);

    /*powerSrv_SetRequestState  will update the correct request (acording to the current active request)*/
    if ( pPowerSrvSM->pSmRequest->requestState == RUNNING_REQUEST )
    {
        pPowerSrvSM->pSmRequest->requestState = HANDLED_REQUEST;
    }

    return TI_OK;
}


/****************************************************************************************
 *                        powerSrvSmDoPending                                                        *
 *****************************************************************************************
DESCRIPTION: This function is an action of the state machine returns Pending in case that there is a request 
              waiting to be finished (already sent to FW)
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.

OUTPUT: 
RETURN:    TI_STATUS - PENDING
****************************************************************************************/

static TI_STATUS powerSrvSmDoPending(TI_HANDLE hPowerSrvSM)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;

    /*powerSrv_SetRequestState will check the mode and will update the correct request (Driver of user)*/
    pPowerSrvSM->pSmRequest->requestState = PENDING_REQUEST;
    return POWER_SAVE_802_11_PENDING;
}



/****************************************************************************************
 *                        powerSrvSmDoAllready                                                       *
 *****************************************************************************************
DESCRIPTION: This function is an action of the state machine stays in the same state since it the requested
              one in the request
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.

OUTPUT: 
RETURN:    TI_STATUS - TI_OK
****************************************************************************************/
static TI_STATUS powerSrvSmDoAllready(TI_HANDLE hPowerSrvSM)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;

    /*powerSrv_SetRequestState will check the mode and will update the correct request (Driver of user)*/
    pPowerSrvSM->pSmRequest->requestState = HANDLED_REQUEST;
    return POWER_SAVE_802_11_IS_CURRENT;
}


/****************************************************************************************
 *                        powerSrvSMActionUnexpected                                                 *
 *****************************************************************************************
DESCRIPTION: This function is an action of the state machine stays in the same state and return that action
              was not expected
                                                                                                                   
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.

OUTPUT: 
RETURN:    TI_STATUS - TI_OK
****************************************************************************************/
static TI_STATUS powerSrvSMActionUnexpected(TI_HANDLE hPowerSrvSM)
{
#ifdef TI_DBG
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;

    TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_ERROR, "called: powerSrvSMActionUnexpected");
#endif /* TI_DBG */

    return TI_OK;
}


/****************************************************************************************
 *                        powerSrvSmSMEvent                                                      *
 *****************************************************************************************
DESCRIPTION: This function is the manager of the state macine. its move the state machine
              from one state to the other depend on the receive event, and call to the appropriate
              action (function) for the move between the states.
                                                                                                                   
INPUT:      - pCurrentState
            - event
            - hPowerSrvSM                       - handle to the PowerSrvSM object.

OUTPUT: 
RETURN:    TI_STATUS 
****************************************************************************************/
static TI_STATUS powerSrvSmSMEvent(TI_UINT8* pCurrentState,
                                   TI_UINT8 event,
                                   TI_HANDLE hPowerSrvSM)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;
    TI_STATUS status = TI_OK;
    TI_UINT8 nextState;

    status = fsm_GetNextState((fsm_stateMachine_t*)pPowerSrvSM->hFSM,
                              (TI_UINT8)pPowerSrvSM->currentState,
                              event,
                              &nextState);
    if ( status != TI_OK )
    {
        TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_SM, "PowerSrvSM - State machine error, failed getting next state\n");
        return(status);
    }


	TRACE3( pPowerSrvSM->hReport, REPORT_SEVERITY_INFORMATION, "powerSrvSmSMEvent: <currentState = %d, event = %d> --> nextState = %d\n", *pCurrentState, event, nextState);

    status = fsm_Event(pPowerSrvSM->hFSM,
                       pCurrentState,
                       event,
                       (void*)pPowerSrvSM);

    return status;
}


/****************************************************************************************
*                        powerSrvSMSendMBXConfiguration                                             *
*****************************************************************************************
DESCRIPTION: This function send configuration of the power save option that holds in the command
                mailbox inner sturcture.
                                                                                                                  
INPUT:      - hPowerSrvSM                       - handle to the PowerSrvSM object.
           - PS_disableEnable                      - true = PS , false = active

OUTPUT: 
RETURN:    TI_STATUS 
****************************************************************************************/
static TI_STATUS    powerSrvSMSendMBXConfiguration(TI_HANDLE hPowerSrvSM, TI_BOOL PS_disableEnable)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;
    TPowerSaveParams powerSaveParams;
    TI_STATUS status;

    /*setting the params for the Hal*/
    powerSaveParams.hangOverPeriod          = pPowerSrvSM->hangOverPeriod;
    powerSaveParams.numNullPktRetries       = pPowerSrvSM->numNullPktRetries;
    powerSaveParams.NullPktRateModulation   = pPowerSrvSM->NullPktRateModulation;
    powerSaveParams.needToSendNullData      = pPowerSrvSM->pSmRequest->sendNullDataOnExit;
    powerSaveParams.ps802_11Enable          = PS_disableEnable;

    /* start the FW guard timer, which is used to protect from FW stuck */
    tmr_StartTimer (pPowerSrvSM->hPwrSrvSmTimer,
                    powerSrvSMTimerExpired,
                    (TI_HANDLE)pPowerSrvSM,
                    POWER_SAVE_GUARD_TIME_MS,
                    TI_FALSE);

    /* that command should be sent to FW just in case we moved from Active to one of the PS modes
     * and vice versa, it shoul not be sent when moving between different PS modes */
    status = cmdBld_CmdSetPsMode (pPowerSrvSM->hCmdBld, 
                                  &powerSaveParams,
                                  (void *)pPowerSrvSM->pSmRequest->powerSaveCmdResponseCB,
                                  (pPowerSrvSM->pSmRequest->powerSaveCmdResponseCB == NULL) ? NULL : pPowerSrvSM->pSmRequest->powerSaveCBObject);
                                      
    if ( status != TI_OK )
    {
        TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_ERROR, "Error in configuring Power Manager paramters!\n");
    }

    return status;
}

/****************************************************************************************
*                               powerSrvSMTimerExpired                                  *
*****************************************************************************************
DESCRIPTION: This function is called upon timer expiry - when the FW has not returned
             a response within the defined tme (50 ms)
                                                                                                                  
INPUT:      hPowerSrvSM     - handle to the PowerSrvSM object.
            bTwdInitOccured - Indicates if TWDriver recovery occured since timer started 

OUTPUT:    None

RETURN:    None
****************************************************************************************/
static void powerSrvSMTimerExpired (TI_HANDLE hPowerSrvSM, TI_BOOL bTwdInitOccured)
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;

    /* Print an error message */
    TRACE0(pPowerSrvSM->hReport, REPORT_SEVERITY_ERROR, "PS guard timer expired!\n");

    /* Call the error notification callback (triggering recovery) */
    pPowerSrvSM->failureEventCB( pPowerSrvSM->hFailureEventObj ,POWER_SAVE_FAILURE );
}

/****************************************************************************************
 *                        powerSrvRegisterFailureEventCB                                                    *
 ****************************************************************************************
DESCRIPTION: Registers a failure event callback for PS SM error notifications.
                
                                                                                                                   
INPUT:      - hPowerSrv         - handle to the PowerSrv object.        
            - failureEventCB    - the failure event callback function.\n
            - hFailureEventObj - handle to the object passed to the failure event callback function.

OUTPUT: 
RETURN:    void.
****************************************************************************************/
void powerSrvSM_RegisterFailureEventCB( TI_HANDLE hPowerSrvSM, 
                                        void *failureEventCB, TI_HANDLE hFailureEventObj )
{
    PowerSrvSM_t *pPowerSrvSM = (PowerSrvSM_t*)hPowerSrvSM;

    pPowerSrvSM->failureEventCB = (TFailureEventCb)failureEventCB;
    pPowerSrvSM->hFailureEventObj = hFailureEventObj;
}