wlan_bearer/wlanldd/wlan_common/umac_common/src/umacconfiguretxautoratepolicy.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Implementation of WlanConfigureTxAutoRatePolicy class
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 6 %
       
    20 */
       
    21 
       
    22 #include "config.h"
       
    23 #include "umacconfiguretxautoratepolicy.h"
       
    24 #include "UmacContextImpl.h"
       
    25 #include "UmacWsaWriteMib.h"
       
    26 
       
    27 #ifndef RD_WLAN_DDK
       
    28 #include <wha_mib.h>
       
    29 #else
       
    30 #include <wlanwha_mib.h>
       
    31 #endif
       
    32 
       
    33 
       
    34 #ifndef NDEBUG
       
    35 const TInt8 WlanConfigureTxAutoRatePolicy::iName[] 
       
    36     = "whacomplex-configuretxautoratepolicy";
       
    37 
       
    38 const TUint8 WlanConfigureTxAutoRatePolicy::iStateName
       
    39     [ESTATEMAX][KMaxStateStringLength] = 
       
    40     {
       
    41         {"EINIT"}, 
       
    42         {"ESETAUTORATEPOLICY"},
       
    43         {"EFINIT"}
       
    44     };
       
    45 
       
    46 const TUint8 WlanConfigureTxAutoRatePolicy::iEventName
       
    47     [EEVENTMAX][KMaxEventStringLength] = 
       
    48     {
       
    49         {"ESTATEENTRY"}, 
       
    50         {"ETXCOMPLETE"},
       
    51         {"EABORT"}
       
    52     };
       
    53 #endif // !NDEBUG
       
    54 
       
    55 // length of txAutoRatePolicy MIB
       
    56 const TUint16 KtxAutoRatePolicyMibLen = sizeof( WHA::StxAutoRatePolicy );
       
    57 
       
    58 // ============================ MEMBER FUNCTIONS ===============================
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // 
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 WlanConfigureTxAutoRatePolicy::WlanConfigureTxAutoRatePolicy() : 
       
    66      iState ( EINIT ),
       
    67      iCompleteMgmtRequest ( EFalse ),
       
    68      iTxAutoRatePolicyMib ( NULL ),
       
    69      iNumberOfPolicyClassesToConfigure ( 0 ),
       
    70      iRatePolicyClass ( 0 )
       
    71     {
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // 
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 WlanConfigureTxAutoRatePolicy::~WlanConfigureTxAutoRatePolicy() 
       
    79     { 
       
    80     iTxAutoRatePolicyMib = NULL;
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // 
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void WlanConfigureTxAutoRatePolicy::Set( TBool aCompleteMgmtRequest  )
       
    88     {
       
    89     iCompleteMgmtRequest = aCompleteMgmtRequest;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // 
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void WlanConfigureTxAutoRatePolicy::Fsm( 
       
    97     WlanContextImpl& aCtxImpl, 
       
    98     TEvent aEvent )
       
    99     {
       
   100 #ifndef NDEBUG
       
   101     OsTracePrint( KUmacDetails, (TUint8*)
       
   102         ("UMAC: WlanConfigureTxAutoRatePolicy::Fsm: event:"));
       
   103     OsTracePrint( KUmacDetails, iEventName[aEvent] );
       
   104     OsTracePrint( KUmacDetails, (TUint8*)
       
   105         ("UMAC: WlanConfigureTxAutoRatePolicy::Fsm: state:"));
       
   106     OsTracePrint( KUmacDetails, iStateName[iState] );
       
   107 #endif
       
   108 
       
   109     switch ( aEvent )
       
   110         {
       
   111         case ESTATEENTRY:
       
   112             OnStateEntryEvent( aCtxImpl );
       
   113             break;
       
   114         case ETXCOMPLETE:
       
   115             OnTxCompleteEvent( aCtxImpl );
       
   116             break;
       
   117         case EABORT:
       
   118             OnAbortEvent( aCtxImpl );
       
   119             break;
       
   120         default:
       
   121             // catch internal FSM programming error
       
   122 #ifndef NDEBUG
       
   123             OsTracePrint( KErrorLevel, (TUint8*)("UMAC: event:"));
       
   124             OsTracePrint( KErrorLevel, iEventName[aEvent] );                
       
   125 #endif 
       
   126             OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   127         }
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // 
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void WlanConfigureTxAutoRatePolicy::OnStateEntryEvent( 
       
   135     WlanContextImpl& aCtxImpl )
       
   136     {
       
   137     switch ( iState )
       
   138         {
       
   139         case EINIT:
       
   140             // determine the number of rate policy classes to set
       
   141             iNumberOfPolicyClassesToConfigure = 
       
   142                 (aCtxImpl.RatePolicy()).numOfPolicyObjects;
       
   143             OsTracePrint( KUmacDetails, (TUint8*)
       
   144                 ("UMAC: WlanConfigureTxAutoRatePolicy::OnStateEntryEvent: nbr of policy classes to configure: %d"),
       
   145                 iNumberOfPolicyClassesToConfigure );
       
   146 
       
   147             // rate policy class IDs start from 1, so that's the 1st to 
       
   148             // configure
       
   149             iRatePolicyClass = 1;
       
   150             // allocate memory for the MIB to write
       
   151             iTxAutoRatePolicyMib = 
       
   152                 static_cast<WHA::StxAutoRatePolicy*>(
       
   153                     os_alloc( KtxAutoRatePolicyMibLen ) ); 
       
   154 
       
   155             if ( iTxAutoRatePolicyMib )
       
   156                 {
       
   157                 // start the FSM traversal
       
   158                 ChangeInternalState( aCtxImpl, ESETAUTORATEPOLICY );
       
   159                 }
       
   160             else
       
   161                 {
       
   162                 // allocation failure, abort processing
       
   163                 Fsm( aCtxImpl, EABORT );                
       
   164                 }
       
   165             break;
       
   166         case ESETAUTORATEPOLICY:
       
   167             SetAutoRatePolicy( aCtxImpl );                
       
   168             break;
       
   169         case EFINIT:
       
   170             // fsm execution complete. 
       
   171             
       
   172             // complete WLAN Mgmt Client request, if necessary
       
   173             if ( iCompleteMgmtRequest )
       
   174                 {
       
   175                 OnOidComplete( aCtxImpl, KErrNone );
       
   176                 }
       
   177                 
       
   178             // Traverse back to history state
       
   179             TraverseToHistoryState( aCtxImpl );
       
   180             break;
       
   181         default:
       
   182             // cath internal FSM programming error
       
   183 #ifndef NDEBUG
       
   184             OsTracePrint( KErrorLevel, (TUint8*)("UMAC: state:"));
       
   185             OsTracePrint( KErrorLevel, iStateName[iState] );
       
   186 #endif 
       
   187             OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   188         }
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // 
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void WlanConfigureTxAutoRatePolicy::OnTxCompleteEvent( 
       
   196     WlanContextImpl& aCtxImpl )
       
   197     {
       
   198     switch ( iState )
       
   199         {
       
   200         case ESETAUTORATEPOLICY:
       
   201             
       
   202             // one (more) rate policy class has been set
       
   203             ++iRatePolicyClass;
       
   204             
       
   205             if ( iRatePolicyClass <= iNumberOfPolicyClassesToConfigure )
       
   206                 {
       
   207                 // we haven't configured all the rate policy classes, yet
       
   208                 // so proceed with the next one by re-entering the current
       
   209                 // internal state
       
   210                 ChangeInternalState( aCtxImpl, ESETAUTORATEPOLICY );
       
   211                 }
       
   212             else
       
   213                 {
       
   214                 // all rate policy classes have been set. We are done
       
   215                 ChangeInternalState( aCtxImpl, EFINIT );                
       
   216                 }
       
   217 
       
   218             break;
       
   219         default:
       
   220             // cath internal FSM programming error
       
   221 #ifndef NDEBUG
       
   222             OsTracePrint( KErrorLevel, (TUint8*)("UMAC: state:"));
       
   223             OsTracePrint( KErrorLevel, iStateName[iState] );
       
   224 #endif             
       
   225             OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   226         }
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // simulate macnotresponding error
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void WlanConfigureTxAutoRatePolicy::OnAbortEvent( 
       
   234     WlanContextImpl& aCtxImpl )
       
   235     {
       
   236     OsTracePrint( KWarningLevel, 
       
   237         (TUint8*)("UMAC: WlanConfigureTxAutoRatePolicy::OnAbortEvent") );
       
   238 
       
   239     DoErrorIndication( aCtxImpl, WHA::KErrorMacNotResponding );
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // 
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void WlanConfigureTxAutoRatePolicy::ChangeInternalState( 
       
   247     WlanContextImpl& aCtxImpl, 
       
   248     TState aNewState )
       
   249     {
       
   250     iState = aNewState;
       
   251     Fsm( aCtxImpl, ESTATEENTRY );
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // 
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void WlanConfigureTxAutoRatePolicy::SetAutoRatePolicy( 
       
   259     WlanContextImpl& aCtxImpl )
       
   260     {
       
   261     OsTracePrint( KUmacDetails, (TUint8*)
       
   262         ("UMAC: WlanConfigureTxAutoRatePolicy::SetAutoRatePolicy") );
       
   263 
       
   264     // retrieve reference to the stored rate policy information
       
   265     const TTxRatePolicy& ratePolicy ( aCtxImpl.RatePolicy() );
       
   266     // ... and to the stored auto rate policy
       
   267     TTxAutoRatePolicy& autoRatePolicy ( aCtxImpl.AutoRatePolicy() );
       
   268     // ... and to the stored HT MCS policy information
       
   269     const THtMcsPolicy& htMcsPolicy ( aCtxImpl.HtMcsPolicy() );
       
   270 
       
   271     // 1st clear
       
   272     os_memset( iTxAutoRatePolicyMib, 0, KtxAutoRatePolicyMibLen );
       
   273     
       
   274     // set the mib contents. Note that because rate policy class IDs start from
       
   275     // 1 and array indexes from 0 we need to subtract one from the rate policy
       
   276     // class ID when accessing corresponding arrays
       
   277     
       
   278     iTxAutoRatePolicyMib->iBAndGRates = autoRatePolicy[iRatePolicyClass - 1];
       
   279     iTxAutoRatePolicyMib->iTxRateClassId = iRatePolicyClass;
       
   280     iTxAutoRatePolicyMib->iShortRetryLimit = 
       
   281         ratePolicy.txRateClass[iRatePolicyClass - 1].shortRetryLimit;
       
   282     iTxAutoRatePolicyMib->iLongRetryLimit = 
       
   283         ratePolicy.txRateClass[iRatePolicyClass - 1].longRetryLimit;
       
   284 
       
   285     os_memcpy( 
       
   286         iTxAutoRatePolicyMib->iMcsSet,
       
   287         &(htMcsPolicy[iRatePolicyClass - 1]),
       
   288         sizeof( WHA::THtMcsSet ) );
       
   289     
       
   290     WlanWsaWriteMib& whaCmd = aCtxImpl.WsaWriteMib();
       
   291     whaCmd.Set( 
       
   292         aCtxImpl, 
       
   293         WHA::KMibTxAutoRatePolicy, 
       
   294         KtxAutoRatePolicyMibLen, 
       
   295         iTxAutoRatePolicyMib );
       
   296 
       
   297     // change global state: entry procedure triggers action
       
   298     ChangeState( aCtxImpl, 
       
   299         *this,              // prev state
       
   300         whaCmd              // next state
       
   301         );           
       
   302     }
       
   303     
       
   304 // -----------------------------------------------------------------------------
       
   305 // 
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void WlanConfigureTxAutoRatePolicy::Entry( 
       
   309     WlanContextImpl& aCtxImpl )
       
   310     {
       
   311     if ( aCtxImpl.WsaCmdActive() )
       
   312         {
       
   313         // sanity checking code
       
   314         OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   315         }
       
   316 
       
   317     if ( iState != EINIT )
       
   318         {
       
   319         // this is NOT the start of the the FSM actions
       
   320         // note that we send the ETXCOMPLETE event as the states
       
   321         // that wait for it are the only ones that can be interrupted
       
   322         // as they are asynchronous operations by nature
       
   323         // and wait for corresponding WHA completion method
       
   324         Fsm( aCtxImpl, ETXCOMPLETE );
       
   325         }
       
   326     else
       
   327         {
       
   328         // this is the start of the the FSM actions
       
   329         Fsm( aCtxImpl, ESTATEENTRY );
       
   330         }
       
   331     }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // 
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 void WlanConfigureTxAutoRatePolicy::Exit( 
       
   338     WlanContextImpl& /*aCtxImpl*/ )
       
   339     {
       
   340     iState = EINIT;
       
   341     os_free( iTxAutoRatePolicyMib );
       
   342     iTxAutoRatePolicyMib = NULL;
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // 
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 #ifndef NDEBUG 
       
   350 const TInt8* WlanConfigureTxAutoRatePolicy::GetStateName( 
       
   351     TUint8& aLength ) const
       
   352     {
       
   353     aLength = sizeof( iName );
       
   354     return iName;
       
   355     }
       
   356 #endif