wlan_bearer/wlanldd/wlan_common/umac_common/src/UmacDot11InfrastructureModeInit.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2005-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 WlanDot11InfrastructureModeInit class
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 40 %
       
    20 */
       
    21 
       
    22 #include "config.h"
       
    23 #include "UmacDot11InfrastructureModeInit.h"
       
    24 #include "UmacContextImpl.h"
       
    25 #include "UmacWsaWriteMib.h"
       
    26 #include "UmacWsaSetBssParameters.h"
       
    27 #include "umacelementlocator.h"
       
    28 
       
    29 
       
    30 // amount of memory allocated in the mib write buffer
       
    31 const TUint KMibBufferAllocLen( 100 );
       
    32 
       
    33 #ifndef NDEBUG
       
    34 const TInt8 WlanDot11InfrastructureModeInit::iName[] 
       
    35     = "dot11-infrastructuremodeinit";
       
    36 
       
    37 const TUint8 WlanDot11InfrastructureModeInit::iStateName
       
    38     [ESTATEMAX][KMaxStateStringLength] = 
       
    39     {
       
    40         {"EINIT"}, 
       
    41         {"EENABLEBEACONRX"}, 
       
    42         {"ESETNULLDATAFRAMETEMPLATE"},
       
    43         {"ESETQOSNULLDATAFRAMETEMPLATE"},
       
    44         {"ESETPSPOLLTEMPLATE"},
       
    45         {"EWAIT4BEACON"}, 
       
    46         {"EDISABLEBEACONRX"},                         
       
    47         {"ESETBSSPARAMS"}, 
       
    48         {"ECONFBEACONFILTERIETABLE"}, 
       
    49         {"EWAIT4USERDATAENABLE"}, 
       
    50         {"ECONTINUEDOT11TRAVERSE"}
       
    51     };
       
    52 
       
    53 const TUint8 WlanDot11InfrastructureModeInit::iEventName
       
    54     [EEVENTMAX][KMaxEventStringLength] = 
       
    55     {
       
    56         {"ESTATEENTRY"}, 
       
    57         {"ETXCOMPLETE"}, 
       
    58         {"EBEACONPROCESSED"},
       
    59         {"EUSERDATAENABLE"}, 
       
    60         {"EABORT"} 
       
    61     };
       
    62 #endif
       
    63 
       
    64 // beacon has been processed
       
    65 const TUint32 KBeaconHandled        = (1 << 0);
       
    66 // scan OID has been issued
       
    67 const TUint32 KScanning             = (1 << 1);
       
    68 // BSS Parameters have been set
       
    69 const TUint32 KBssParamsSet       	= (1 << 2);
       
    70 
       
    71 // ============================ MEMBER FUNCTIONS ===============================
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // 
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 WlanDot11InfrastructureModeInit::~WlanDot11InfrastructureModeInit()
       
    78     {
       
    79     iMibMemoryBuffer = NULL;
       
    80     }
       
    81 
       
    82 #ifndef NDEBUG 
       
    83 // -----------------------------------------------------------------------------
       
    84 // 
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 const TInt8* WlanDot11InfrastructureModeInit::GetStateName( 
       
    88     TUint8& aLength ) const
       
    89     {
       
    90     aLength = sizeof( iName );
       
    91     return iName;
       
    92     }
       
    93 #endif
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // 
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void WlanDot11InfrastructureModeInit::Entry( 
       
   100     WlanContextImpl& aCtxImpl)
       
   101     {
       
   102     if ( aCtxImpl.WsaCmdActive() )
       
   103         {
       
   104         // sanity checking code
       
   105         OsAssert( (TUint8*)("UMAC* panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   106         }
       
   107 
       
   108     if ( !(aCtxImpl.DispatchEvent()) )
       
   109         {
       
   110         // no state transition occurred
       
   111         // dispatcher might or might not have had an event to be dispatched
       
   112         // in any case we are still in the current state and can continue...
       
   113         if ( iState != EINIT )
       
   114             {
       
   115             // this is NOT the start of the the FSM actions
       
   116             // note that we send the ETXCOMPLETE event as the states
       
   117             // that wait for it are the only ones that can be interrupted
       
   118             // as they are asynchronous operations by nature
       
   119             // and wait for corresponding WHA completion method
       
   120             Fsm( aCtxImpl, ETXCOMPLETE );
       
   121             }
       
   122         else
       
   123             {
       
   124             // this is the start of the the FSM actions
       
   125             Fsm( aCtxImpl, ESTATEENTRY );
       
   126             }
       
   127         }
       
   128     else    // --- !(aCtxImpl.DispatchEvent())
       
   129         {
       
   130         // state transition occurred
       
   131         // we are no longer in the current state,
       
   132         // so we won't do anything as we might mess things up
       
   133         }   
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // 
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void WlanDot11InfrastructureModeInit::Exit( 
       
   141     WlanContextImpl& /*aCtxImpl*/ )
       
   142     {
       
   143     if ( !(iFlags & KScanning) )
       
   144         {
       
   145         // we are about to make a transition to another dot11 state
       
   146         // and that state is not the scanning state
       
   147         // from scanning state we shall come back to this dot11 state
       
   148         // so basically this means that
       
   149         // only thing we shall do is to reset our FSM for the next round...
       
   150         iState = EINIT; 
       
   151         os_free( iMibMemoryBuffer );
       
   152         iMibMemoryBuffer = NULL;
       
   153         }
       
   154     else
       
   155         {
       
   156         iFlags &= ~KScanning;
       
   157 
       
   158         OsTracePrint( KScan, (TUint8*)
       
   159             ("UMAC * dot11-infrastructuremodeinit * switch to scan mode") );
       
   160         }
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // 
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 inline void WlanDot11InfrastructureModeInit::ChangeInternalState( 
       
   168     WlanContextImpl& aCtxImpl, 
       
   169     TState aNewState )
       
   170     {
       
   171     iState = aNewState;
       
   172     Fsm( aCtxImpl, ESTATEENTRY );
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // 
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void WlanDot11InfrastructureModeInit::Fsm( 
       
   180     WlanContextImpl& aCtxImpl, 
       
   181     TEvent aEvent )
       
   182     {
       
   183     OsTracePrint( KUmacDetails, 
       
   184         (TUint8*)("UMAC * dot11-infrastructuremodeinit * FSM EVENT") );
       
   185 #ifndef NDEBUG
       
   186     OsTracePrint( KUmacDetails, (TUint8*)("event:"));
       
   187     OsTracePrint( KUmacDetails, iEventName[aEvent] );
       
   188     OsTracePrint( KUmacDetails, (TUint8*)("state:"));
       
   189     OsTracePrint( KUmacDetails, iStateName[iState] );
       
   190 #endif
       
   191 
       
   192     switch ( aEvent )
       
   193         {
       
   194         case ESTATEENTRY:
       
   195             OnStateEntryEvent( aCtxImpl );
       
   196             break;
       
   197         case ETXCOMPLETE:
       
   198             OnTxCompleteEvent( aCtxImpl );
       
   199             break;
       
   200         case EBEACONPROCESSED:
       
   201             OnBeaconProcessedEvent( aCtxImpl );
       
   202             break;
       
   203         case EUSERDATAENABLE:
       
   204             OnUserDataEnableEvent( aCtxImpl );
       
   205             break;
       
   206         case EABORT:
       
   207             OnAbortEvent( aCtxImpl );            
       
   208             break;
       
   209         default:
       
   210             // catch internal FSM programming error
       
   211 #ifndef NDEBUG
       
   212             OsTracePrint( KErrorLevel, (TUint8*)("event:"));
       
   213             OsTracePrint( KErrorLevel, iEventName[aEvent] );                
       
   214 #endif
       
   215             OsAssert( (TUint8*)("* UMAC * panic"), 
       
   216                 (TUint8*)(WLAN_FILE), __LINE__ );
       
   217             break;
       
   218         }
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // 
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 void WlanDot11InfrastructureModeInit::OnStateEntryEvent( 
       
   226     WlanContextImpl& aCtxImpl )
       
   227     {
       
   228     switch ( iState )
       
   229         {
       
   230         case EINIT:                
       
   231             iMibMemoryBuffer = os_alloc( KMibBufferAllocLen );
       
   232             if ( iMibMemoryBuffer )
       
   233                 {
       
   234                 // reset event flag and continue with the state traversal
       
   235                 iFlags = 0;
       
   236                 ChangeInternalState( aCtxImpl, EENABLEBEACONRX );
       
   237                 }
       
   238             else
       
   239                 {
       
   240                 // allocation failure
       
   241                 Fsm( aCtxImpl, EABORT );
       
   242                 }
       
   243             break;
       
   244         case EENABLEBEACONRX:
       
   245             // enable beacon frame reception
       
   246             EnableBeaconRx( aCtxImpl );
       
   247             break;
       
   248         case ESETNULLDATAFRAMETEMPLATE:
       
   249             // configure NULL data frame template
       
   250             SetNullDataFrameTemplate( aCtxImpl );
       
   251             break;
       
   252         case ESETQOSNULLDATAFRAMETEMPLATE:
       
   253             // configure NULL data frame template
       
   254             SetQosNullDataFrameTemplate( aCtxImpl );
       
   255             break;
       
   256         case ESETPSPOLLTEMPLATE:
       
   257             // configure ps poll frame template
       
   258             SetPsPollFrameTemplate( aCtxImpl );
       
   259             break;
       
   260         case ESETBSSPARAMS:
       
   261             // set the BSS parameters
       
   262             SetBssParams( aCtxImpl );
       
   263             break;
       
   264         case EDISABLEBEACONRX:
       
   265             // disable beacon frame reception
       
   266             DisableBeaconRx( aCtxImpl );
       
   267             break;
       
   268         case ECONFBEACONFILTERIETABLE:
       
   269             // configure beaconfiltertable MIB
       
   270             ConfigureBeaconFilterIeTable( aCtxImpl );
       
   271             break;
       
   272         case ECONTINUEDOT11TRAVERSE:
       
   273             // continue dot11 state traversal to dot11awake mode
       
   274             // or to dot11eneterdoze state
       
   275             ContinueDot11StateTraversal( aCtxImpl );
       
   276             break;        
       
   277         // these critters don't have an entry action
       
   278         // but the entry event gets sent automatically by the framework 
       
   279         // from state traversal method so they have to be defined here
       
   280         case EWAIT4BEACON:
       
   281         case EWAIT4USERDATAENABLE:
       
   282             break;
       
   283         default:
       
   284             // catch internal FSM programming error
       
   285             OsTracePrint( 
       
   286                 KErrorLevel, 
       
   287                 (TUint8*)
       
   288                 ("UMAC: WlanDot11InfrastructureModeInit::OnStateEntryEvent(): state: %d"), 
       
   289                 iState);        
       
   290             OsAssert( 
       
   291                 (TUint8*)
       
   292                 ("UMAC: WlanDot11InfrastructureModeInit::OnStateEntryEvent(): panic"), 
       
   293                 (TUint8*)(WLAN_FILE), __LINE__ );
       
   294             break;
       
   295         }
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // 
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 void WlanDot11InfrastructureModeInit::OnTxCompleteEvent( 
       
   303     WlanContextImpl& aCtxImpl )
       
   304     {
       
   305     switch ( iState )
       
   306         {
       
   307         case EWAIT4BEACON:
       
   308             // event handler for this state is needed
       
   309             // as we may re-enter this dot11 state (e.g. from scanning state 
       
   310             // or because we autonomously requested a WHA cmd to be executed)
       
   311             // while waiting for this event to occur
       
   312             if ( iFlags & KBeaconHandled )
       
   313                 {
       
   314                 // give a correct event for the FSM critter
       
   315                 Fsm( aCtxImpl, EBEACONPROCESSED );
       
   316                 }
       
   317             break;
       
   318         case EWAIT4USERDATAENABLE:
       
   319             // event handler for this state is needed
       
   320             // as we may re-enter this dot11 state (e.g. from scanning state 
       
   321             // or because we autonomously requested a WHA cmd to be executed)
       
   322             // while waiting for this event to occur
       
   323             if ( aCtxImpl.ProtocolStackTxDataAllowed() )
       
   324                 {
       
   325                 // give a correct event for the FSM critter
       
   326                 Fsm( aCtxImpl, EUSERDATAENABLE );
       
   327                 }
       
   328             break;
       
   329         case EENABLEBEACONRX:
       
   330             ChangeInternalState( aCtxImpl, 
       
   331                 ESETNULLDATAFRAMETEMPLATE );
       
   332             break;
       
   333         case ESETNULLDATAFRAMETEMPLATE:
       
   334             ChangeInternalState( aCtxImpl, 
       
   335                 ESETQOSNULLDATAFRAMETEMPLATE );
       
   336             break;
       
   337         case ESETQOSNULLDATAFRAMETEMPLATE:
       
   338             ChangeInternalState( aCtxImpl, 
       
   339                 ESETPSPOLLTEMPLATE );
       
   340             break;
       
   341         case ESETPSPOLLTEMPLATE:
       
   342             // as we have configured the ps poll frame we shall now
       
   343             // complete the request
       
   344             CompleteConnectRequest( aCtxImpl, KErrNone );
       
   345             ChangeInternalState( aCtxImpl, 
       
   346                 EWAIT4BEACON );
       
   347             break;
       
   348         case EDISABLEBEACONRX:
       
   349             ChangeInternalState( aCtxImpl, 
       
   350                 ESETBSSPARAMS );
       
   351             break;
       
   352         case ESETBSSPARAMS:
       
   353             ChangeInternalState( aCtxImpl, 
       
   354                 ECONFBEACONFILTERIETABLE );
       
   355             break;
       
   356         case ECONFBEACONFILTERIETABLE:
       
   357             if ( aCtxImpl.ProtocolStackTxDataAllowed() )
       
   358                 {
       
   359                 // user data enabled continue
       
   360                 // state traversal
       
   361                 ChangeInternalState( aCtxImpl, 
       
   362                     ECONTINUEDOT11TRAVERSE );
       
   363                 }
       
   364             else
       
   365                 {
       
   366                 // user data is not enabled wait 4 it
       
   367                 ChangeInternalState( aCtxImpl, 
       
   368                     EWAIT4USERDATAENABLE );
       
   369                 }
       
   370 
       
   371             break;
       
   372         default:
       
   373             // catch internal FSM programming error
       
   374             OsTracePrint( KErrorLevel, (TUint8*)("state: %d"), iState);        
       
   375             OsAssert( (TUint8*)("UMAC * panic"), 
       
   376                 (TUint8*)(WLAN_FILE), __LINE__ );
       
   377             break;
       
   378         }
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // 
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 void WlanDot11InfrastructureModeInit::OnBeaconProcessedEvent( 
       
   386     WlanContextImpl& aCtxImpl )
       
   387     {
       
   388     switch ( iState )
       
   389         {
       
   390         case EWAIT4BEACON:
       
   391             // continue state traversal
       
   392             ChangeInternalState( aCtxImpl, EDISABLEBEACONRX );
       
   393             break;        
       
   394         default:
       
   395             // if the beacon gets processed in an earlier internal
       
   396             // state than EWAIT4BEACON, we won't change to 
       
   397             // EDISABLEBEACONRX as it would disrupt the sequence 
       
   398             // of actions. So we will do this internal state change
       
   399             // later in its due time            
       
   400             break;
       
   401         }
       
   402     }
       
   403 
       
   404 // -----------------------------------------------------------------------------
       
   405 // 
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 void WlanDot11InfrastructureModeInit::OnUserDataEnableEvent( 
       
   409     WlanContextImpl& aCtxImpl )
       
   410     {
       
   411     // continue state traversal
       
   412     ChangeInternalState( aCtxImpl, ECONTINUEDOT11TRAVERSE );
       
   413     }
       
   414 
       
   415 // ---------------------------------------------------------
       
   416 // simulate macnotresponding error
       
   417 // ---------------------------------------------------------
       
   418 //
       
   419 void WlanDot11InfrastructureModeInit::OnAbortEvent( 
       
   420     WlanContextImpl& aCtxImpl )
       
   421     {
       
   422     OsTracePrint( KWarningLevel, 
       
   423         (TUint8*)("UMAC * dot11-infrastructuremodeinit * abort") );
       
   424 
       
   425     DoErrorIndication( aCtxImpl, WHA::KErrorMacNotResponding );
       
   426     }
       
   427 
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 // 
       
   431 // -----------------------------------------------------------------------------
       
   432 //
       
   433 void WlanDot11InfrastructureModeInit::EnableBeaconRx( 
       
   434     WlanContextImpl& aCtxImpl )
       
   435     {    
       
   436     const TUint32 KBeaconRxEnableValue( 1 );
       
   437 
       
   438     WHA::SbeaconFilterEnable* mib 
       
   439         = static_cast<WHA::SbeaconFilterEnable*>(iMibMemoryBuffer);
       
   440 
       
   441     // enable reception of every beacon from the BSS 
       
   442     mib->iEnable = EFalse;
       
   443     // even though this attribute is nowadays deprecated, we still continue to
       
   444     // set it in this case; to be on the safe side
       
   445     mib->iCount = KBeaconRxEnableValue;
       
   446            
       
   447     WlanWsaWriteMib& wsa_cmd = aCtxImpl.WsaWriteMib();
       
   448         
       
   449     wsa_cmd.Set( 
       
   450         aCtxImpl, WHA::KMibBeaconFilterEnable, sizeof(*mib), mib );
       
   451         
       
   452     // change global state: entry procedure triggers action
       
   453     ChangeState( aCtxImpl, 
       
   454         *this,              // prev state
       
   455         wsa_cmd             // next state
       
   456         );   
       
   457     }
       
   458 
       
   459 // -----------------------------------------------------------------------------
       
   460 // 
       
   461 // -----------------------------------------------------------------------------
       
   462 //
       
   463 void WlanDot11InfrastructureModeInit::DisableBeaconRx( 
       
   464     WlanContextImpl& aCtxImpl )
       
   465     {    
       
   466     const TUint32 KBeaconRxDisableValue( 0 );
       
   467 
       
   468     WHA::SbeaconFilterEnable* mib 
       
   469         = static_cast<WHA::SbeaconFilterEnable*>(iMibMemoryBuffer);
       
   470 
       
   471     // disable reception of beacons except those specified 
       
   472     // by beaconFilterIeTable
       
   473     mib->iEnable = ETrue;
       
   474     mib->iCount = KBeaconRxDisableValue;
       
   475 
       
   476     WlanWsaWriteMib& wsa_cmd = aCtxImpl.WsaWriteMib();
       
   477 
       
   478     wsa_cmd.Set( 
       
   479         aCtxImpl, WHA::KMibBeaconFilterEnable, sizeof(*mib), mib );
       
   480 
       
   481     // change global state: entry procedure triggers action
       
   482     ChangeState( aCtxImpl, 
       
   483         *this,              // prev state
       
   484         wsa_cmd             // next state
       
   485         );           
       
   486     }
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // 
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 void WlanDot11InfrastructureModeInit::SetNullDataFrameTemplate( 
       
   493     WlanContextImpl& aCtxImpl )
       
   494     {
       
   495     TUint32 mibLength( 
       
   496         WHA::StemplateFrame::KHeaderSize
       
   497         + sizeof( SNullDataFrame ) ); 
       
   498 
       
   499     // align length of MIB to 4-byte boundary
       
   500     mibLength = Align4( mibLength );
       
   501 
       
   502     if ( mibLength > KMibBufferAllocLen )
       
   503         {
       
   504         // programming error
       
   505         OsTracePrint( KErrorLevel, (TUint8*)("UMAC: mib length: %d"), mibLength);
       
   506         OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   507         }
       
   508                             
       
   509     WHA::StemplateFrame* mib 
       
   510         = static_cast<WHA::StemplateFrame*>(iMibMemoryBuffer);
       
   511 
       
   512     mib->iFrameType = WHA::KNullDataTemplate;
       
   513 
       
   514     mib->iInitialTransmitRate = InitialSpecialFrameTxRate( aCtxImpl );
       
   515     mib->iLength = sizeof( SNullDataFrame );
       
   516 
       
   517     // copy the null data frame after the mib header
       
   518     os_memcpy( mib->iTemplateData,
       
   519                reinterpret_cast<TUint8*>(&(aCtxImpl.NullDataFrame())),
       
   520                sizeof( SNullDataFrame ) );
       
   521               
       
   522     WlanWsaWriteMib& wsa_cmd = aCtxImpl.WsaWriteMib();
       
   523 
       
   524     wsa_cmd.Set( 
       
   525         aCtxImpl, 
       
   526         WHA::KMibTemplateFrame, 
       
   527         mibLength,
       
   528         mib );
       
   529    
       
   530     // change global state: entry procedure triggers action
       
   531     ChangeState( aCtxImpl, 
       
   532         *this,              // prev state
       
   533         wsa_cmd             // next state
       
   534         );     
       
   535     }
       
   536 
       
   537 // -----------------------------------------------------------------------------
       
   538 // 
       
   539 // -----------------------------------------------------------------------------
       
   540 //
       
   541 void WlanDot11InfrastructureModeInit::SetQosNullDataFrameTemplate( 
       
   542     WlanContextImpl& aCtxImpl )
       
   543     {
       
   544     const TUint16 KQosNullDataFrameLength ( aCtxImpl.QosNullDataFrameLength() );
       
   545     TUint16 mibLength( 
       
   546         WHA::StemplateFrame::KHeaderSize
       
   547         + KQosNullDataFrameLength ); 
       
   548 
       
   549     // align length of MIB to 4-byte boundary
       
   550     mibLength = Align4( mibLength );
       
   551 
       
   552     if ( mibLength > KMibBufferAllocLen )
       
   553         {
       
   554         // programming error
       
   555         OsTracePrint( KErrorLevel, (TUint8*)("UMAC: mib length: %d"), mibLength);
       
   556         OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   557         }
       
   558                             
       
   559     WHA::StemplateFrame* mib 
       
   560         = static_cast<WHA::StemplateFrame*>(iMibMemoryBuffer);
       
   561 
       
   562     mib->iFrameType = WHA::KQosNullDataTemplate;
       
   563     mib->iInitialTransmitRate = InitialSpecialFrameTxRate( aCtxImpl );
       
   564     mib->iLength = KQosNullDataFrameLength;
       
   565 
       
   566     // note that the Order bit of the Frame Control field of the QoS Null data
       
   567     // frame template has already been given the correct value in 
       
   568     // WlanMacActionState::OnDot11InfrastructureModeStateSpaceEntry() method
       
   569     
       
   570     // copy the QoS null data frame after the mib header
       
   571     os_memcpy( mib->iTemplateData,
       
   572                reinterpret_cast<TUint8*>(&(aCtxImpl.QosNullDataFrame())),
       
   573                KQosNullDataFrameLength );
       
   574               
       
   575     WlanWsaWriteMib& wsa_cmd = aCtxImpl.WsaWriteMib();
       
   576 
       
   577     wsa_cmd.Set( 
       
   578         aCtxImpl, 
       
   579         WHA::KMibTemplateFrame, 
       
   580         mibLength,
       
   581         mib );
       
   582    
       
   583     // change global state: entry procedure triggers action
       
   584     ChangeState( aCtxImpl, 
       
   585         *this,              // prev state
       
   586         wsa_cmd             // next state
       
   587         );     
       
   588     }
       
   589 
       
   590 // -----------------------------------------------------------------------------
       
   591 // 
       
   592 // -----------------------------------------------------------------------------
       
   593 //
       
   594 void WlanDot11InfrastructureModeInit::SetPsPollFrameTemplate( 
       
   595     WlanContextImpl& aCtxImpl )
       
   596     {
       
   597     TUint32 mibLength( 
       
   598         WHA::StemplateFrame::KHeaderSize
       
   599         + sizeof( SPsPoll ) ); 
       
   600 
       
   601     // align length of MIB to 4-byte boundary
       
   602     mibLength = Align4( mibLength );
       
   603 
       
   604     if ( mibLength > KMibBufferAllocLen )
       
   605         {
       
   606         // programming error
       
   607         OsTracePrint( KErrorLevel, (TUint8*)("UMAC: mib length: %d"), mibLength);
       
   608         OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   609         }
       
   610 
       
   611     WHA::StemplateFrame* mib 
       
   612         = static_cast<WHA::StemplateFrame*>(iMibMemoryBuffer);
       
   613 
       
   614     mib->iFrameType = WHA::KPSPollTemplate;
       
   615 
       
   616     mib->iInitialTransmitRate = InitialSpecialFrameTxRate( aCtxImpl );
       
   617     mib->iLength = sizeof( SPsPoll );
       
   618 
       
   619     // construct the ps poll frame after the mib header
       
   620     new (mib->iTemplateData) SPsPoll( 
       
   621         static_cast<TUint16>(aCtxImpl.Aid()), 
       
   622         aCtxImpl.GetBssId(),
       
   623         aCtxImpl.iWlanMib.dot11StationId );
       
   624               
       
   625     WlanWsaWriteMib& wsa_cmd = aCtxImpl.WsaWriteMib();
       
   626 
       
   627     wsa_cmd.Set( 
       
   628         aCtxImpl, 
       
   629         WHA::KMibTemplateFrame, 
       
   630         mibLength,
       
   631         mib );
       
   632    
       
   633     // change global state: entry procedure triggers action
       
   634     ChangeState( aCtxImpl, 
       
   635         *this,              // prev state
       
   636         wsa_cmd             // next state
       
   637         );     
       
   638     }
       
   639 
       
   640 // -----------------------------------------------------------------------------
       
   641 // 
       
   642 // -----------------------------------------------------------------------------
       
   643 //
       
   644 void WlanDot11InfrastructureModeInit::SetBssParams( 
       
   645     WlanContextImpl& aCtxImpl )
       
   646     {
       
   647     WlanWsaSetBssParameters& wsa_cmd = aCtxImpl.WsaSetBssParameters();
       
   648 
       
   649     OsTracePrint( KDot11StateTransit | KUmacDetails, (TUint8*)
       
   650         ("UMAC * dot11-infrastructuremodeinit * DTIM period: %d"), iDtim );
       
   651     OsTracePrint( KDot11StateTransit | KUmacDetails, 
       
   652         (TUint8*)("UMAC * dot11-infrastructuremodeinit * AID: 0x%04x"), 
       
   653         aCtxImpl.Aid() );
       
   654 
       
   655     wsa_cmd.Set( aCtxImpl, iDtim, aCtxImpl.Aid() );
       
   656 
       
   657     // change global state: entry procedure triggers action
       
   658     ChangeState( aCtxImpl, 
       
   659         *this,              // prev state
       
   660         wsa_cmd             // next state
       
   661         );   
       
   662 
       
   663     iFlags |= KBssParamsSet;
       
   664     }
       
   665 
       
   666 // -----------------------------------------------------------------------------
       
   667 // 
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 void WlanDot11InfrastructureModeInit::OnBeaconFrameRx( 
       
   671     WlanContextImpl& aCtxImpl,
       
   672     const TAny* aFrame,
       
   673     const TUint32 aLength,
       
   674     WHA::TRcpi aRcpi,
       
   675     TUint8* aBuffer )
       
   676     {
       
   677     OsTracePrint( KUmacDetails, (TUint8*)
       
   678         ("UMAC: WlanDot11InfrastructureModeInit::OnBeaconFrameRx()") );
       
   679 
       
   680     if ( !(iFlags & KBeaconHandled) )
       
   681         {
       
   682         OsTracePrint( KDot11StateTransit | KUmacDetails, (TUint8*)
       
   683             ("UMAC: WlanDot11InfrastructureModeInit::OnBeaconFrameRx: process beacon frame") );
       
   684 
       
   685         // buffer begin
       
   686         const TUint8* ptr = reinterpret_cast<const TUint8*>(aFrame);
       
   687 
       
   688         // bypass mac header, timestamp fixed field, beacon interval fixed field
       
   689         // and capability fixed field
       
   690         const TUint8 offset = 
       
   691             KMacHeaderLength 
       
   692             + KTimeStampFixedFieldLength 
       
   693             + KBeaconIntervalFixedFieldLength
       
   694             + KCapabilityInformationFixedFieldLength;        
       
   695         ptr += offset; // we now point to the beginning of IEs
       
   696         
       
   697         // ---- begin: extract DTIM period ----
       
   698 
       
   699         WlanElementLocator elementLocator( ptr, aLength - offset );
       
   700         TUint8 elementDatalength( 0 );
       
   701         const TUint8* elementData( NULL );
       
   702 
       
   703         // if TIM IE is not found or the value of DTIM period in the IE is 
       
   704         // zero, we use this value for DTIM period
       
   705         const TUint8 KRecoveryDtimPeriod ( 1 );
       
   706         
       
   707         if ( WlanElementLocator::EWlanLocateOk == 
       
   708              elementLocator.InformationElement( 
       
   709                  E802Dot11TimIE, 
       
   710                  elementDatalength, 
       
   711                  &elementData ) )        
       
   712             {            
       
   713             // extract DTIM period
       
   714             
       
   715             const TUint KDtimOffset ( 1 );
       
   716             iDtim = elementData[KDtimOffset] ? 
       
   717                 elementData[KDtimOffset] : KRecoveryDtimPeriod;
       
   718 
       
   719             OsTracePrint( KDot11StateTransit | KUmacDetails, (TUint8*)  
       
   720                 ("UMAC:  WlanDot11InfrastructureModeInit::OnBeaconFrameRx: DTIM period: %d"), 
       
   721                 iDtim );
       
   722             }
       
   723         else
       
   724             {
       
   725             // TIM IE not found
       
   726             OsTracePrint( KWarningLevel, (TUint8*)
       
   727                 ("UMAC: WlanDot11InfrastructureModeInit::OnBeaconFrameRx: WARNING: TIM IE extraction failure") );
       
   728 
       
   729             iDtim = KRecoveryDtimPeriod;
       
   730 
       
   731             OsTracePrint( KWarningLevel, (TUint8*)
       
   732                 ("UMAC: WlanDot11InfrastructureModeInit::OnBeaconFrameRx: fake DTIM period to %d"), 
       
   733                 iDtim );
       
   734             }
       
   735         
       
   736         // ---- end: extract DTIM period ----
       
   737 
       
   738         // we now point just after TIM IE
       
   739 
       
   740         iFlags |= KBeaconHandled;   // mark us handled
       
   741         
       
   742         // forward the beacon frame to Wlan Mgmt client
       
   743         OsTracePrint( KUmacDetails, (TUint8*)
       
   744             ("UMAC: WlanDot11InfrastructureModeInit::OnBeaconFrameRx: fwd the beacon to Wlan Mgmt client") );
       
   745         XferDot11FrameToMgmtClient( aCtxImpl, aFrame, aLength, aRcpi, aBuffer );
       
   746 
       
   747         if ( !(aCtxImpl.WsaCmdActive()) )
       
   748             {
       
   749             // no WHA command pending send event to the fsm
       
   750             Fsm( aCtxImpl, EBEACONPROCESSED );
       
   751             }
       
   752 
       
   753         }
       
   754     else    // --- !(iFlags & KBeaconHandled) ---
       
   755         {
       
   756         // we have already processed a beacon in this dot11 state
       
   757         // so we have nothing to do
       
   758 
       
   759         // except to release the Rx buffer
       
   760         aCtxImpl.iUmac.MarkRxBufFree( aBuffer );
       
   761         }
       
   762     }
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // 
       
   766 // -----------------------------------------------------------------------------
       
   767 //
       
   768 void WlanDot11InfrastructureModeInit::ConfigureBeaconFilterIeTable( 
       
   769     WlanContextImpl& aCtxImpl )
       
   770     {
       
   771     TUint32 mibLength = WHA::SbeaconFilterIeTable::KHeaderSize;
       
   772     
       
   773     WHA::SbeaconFilterIeTable* mib 
       
   774         = static_cast<WHA::SbeaconFilterIeTable*>(iMibMemoryBuffer);
       
   775 
       
   776     // =================================================================
       
   777     // track ERP information IE for change
       
   778     // =================================================================
       
   779     //
       
   780     WHA::SDefaultIeFilterTable* filter_table( 
       
   781         reinterpret_cast<WHA::SDefaultIeFilterTable*>(mib->iIeTable) );
       
   782 
       
   783     filter_table->iIe = E802Dot11ErpInformationIE;
       
   784     filter_table->iTreatMeant = WHA::SDefaultIeFilterTable::KTrackChange;
       
   785 
       
   786     mibLength += sizeof( WHA::SDefaultIeFilterTable );
       
   787     
       
   788     // =================================================================
       
   789     // track WMM Parameter Element for change
       
   790     // =================================================================
       
   791     //
       
   792     WHA::SIe221FilterTable* filterTableEntry( 
       
   793         reinterpret_cast<WHA::SIe221FilterTable*>(filter_table + 1) );
       
   794 
       
   795     filterTableEntry->iIe = E802Dot11VendorSpecificIE;    
       
   796     filterTableEntry->iTreatMeant = WHA::SIe221FilterTable::KTrackChange;
       
   797 
       
   798     os_memcpy( filterTableEntry->iOui, KWmmElemOui, sizeof( KWmmElemOui ) );
       
   799     filterTableEntry->iType = KWmmElemOuiType;
       
   800     
       
   801     // For this element we have to assign both
       
   802     // OUI Subtype (1 byte) and Version (1 byte) into the same 
       
   803     // iVersion (2 bytes) field of the SIe221FilterTable struct
       
   804     // and in such a way that the OUI Subtype is in the lower memory
       
   805     // address
       
   806     //
       
   807     TUint16 version = static_cast<TUint16>(KWmmParamElemVersion) << 8;
       
   808     version |= static_cast<TUint16>(KWmmParamElemOuiSubtype);
       
   809     WriteHtoUint16( &(filterTableEntry->iVersion), version );
       
   810     
       
   811     mibLength += sizeof( WHA::SIe221FilterTable ); 
       
   812     mib->iNumofElems = 2;   // at this point
       
   813 
       
   814     // =================================================================
       
   815     // track HT Operation element for change, if relevant
       
   816     // =================================================================
       
   817     //
       
   818     if ( aCtxImpl.HtSupportedByNw() )
       
   819         {
       
   820         filter_table = reinterpret_cast<WHA::SDefaultIeFilterTable*>(
       
   821             filterTableEntry + 1);
       
   822     
       
   823         filter_table->iIe = E802Dot11HtOperationIE;
       
   824         filter_table->iTreatMeant = WHA::SDefaultIeFilterTable::KTrackChange;
       
   825 
       
   826         mibLength += sizeof( WHA::SDefaultIeFilterTable );
       
   827         ++(mib->iNumofElems);
       
   828         }
       
   829 
       
   830     WlanWsaWriteMib& wsa_cmd = aCtxImpl.WsaWriteMib();
       
   831 
       
   832     // align length of MIB to 4-byte boundary
       
   833     mibLength = Align4( mibLength );
       
   834         
       
   835     wsa_cmd.Set( 
       
   836         aCtxImpl, 
       
   837         WHA::KMibBeaconFilterIeTable, 
       
   838         mibLength,
       
   839         mib );        
       
   840    
       
   841     // change global state: entry procedure triggers action
       
   842     ChangeState( aCtxImpl, 
       
   843         *this,              // prev state
       
   844         wsa_cmd             // next state
       
   845         );     
       
   846     }
       
   847 
       
   848 // -----------------------------------------------------------------------------
       
   849 // 
       
   850 // -----------------------------------------------------------------------------
       
   851 //
       
   852 TBool WlanDot11InfrastructureModeInit::EnableUserData( 
       
   853     WlanContextImpl& aCtxImpl )
       
   854     {
       
   855     OsTracePrint( KUmacDetails, (TUint8*)
       
   856         ("UMAC: WlanDot11InfrastructureModeInit::EnableUserData"));
       
   857 
       
   858     TBool stateChange( EFalse );
       
   859     aCtxImpl.iEnableUserData = ETrue;
       
   860     OnOidComplete( aCtxImpl );
       
   861     aCtxImpl.iUmac.UserDataReEnabled();
       
   862     
       
   863     if ( iState == EWAIT4USERDATAENABLE )
       
   864         {
       
   865         // we shall continue travesal
       
   866         stateChange = ETrue;
       
   867         Fsm( aCtxImpl, EUSERDATAENABLE );
       
   868         }
       
   869 
       
   870     // signal global state transition event
       
   871     return stateChange;
       
   872     }
       
   873 
       
   874 // -----------------------------------------------------------------------------
       
   875 // 
       
   876 // -----------------------------------------------------------------------------
       
   877 //
       
   878 TBool WlanDot11InfrastructureModeInit::RealScan(
       
   879     WlanContextImpl& aCtxImpl,
       
   880     TScanMode aMode,                    
       
   881     const TSSID& aSSID,                 
       
   882     TUint32 aScanRate,                    
       
   883     SChannels& aChannels,
       
   884     TUint32 aMinChannelTime,            
       
   885     TUint32 aMaxChannelTime,
       
   886     TBool aSplitScan )    
       
   887     {    
       
   888     // scanning mode requested
       
   889     // set parameters
       
   890     // NOTE: OID command parameters are guaranteed to be valid
       
   891     // to the point a correcponding completion method is called
       
   892 
       
   893     // marker for Exit() method -> see it to believe it
       
   894     iFlags |= KScanning;    
       
   895 
       
   896     aCtxImpl.iStates.iInfrastructureScanningMode.Set( 
       
   897         aMode, aSSID, aScanRate, aChannels,
       
   898         aMinChannelTime, aMaxChannelTime, aSplitScan,
       
   899         // if we have not yet set the BSS parameters, we need to use 
       
   900         // foreground scan instead of background scan (which we normally 
       
   901         // use in infrastructure mode). This is to avoid a situation where the
       
   902         // WLAN vendor sw would need to send a PS Poll frame, when the AID is
       
   903         // not set yet
       
   904         iFlags & KBssParamsSet ? WHA::EForcedBgScan : WHA::EFgScan );
       
   905 
       
   906     // mark dot11 state backtrack
       
   907     aCtxImpl.iStates.iInfrastructureScanningMode.Dot11StateBackTrack();
       
   908 
       
   909     ChangeState( aCtxImpl, 
       
   910         *this,                                          // prev state
       
   911         aCtxImpl.iStates.iInfrastructureScanningMode    // next state
       
   912         );                      
       
   913 
       
   914     return ETrue; // global statemachine transition will occur 
       
   915     }
       
   916 
       
   917 // -----------------------------------------------------------------------------
       
   918 // 
       
   919 // -----------------------------------------------------------------------------
       
   920 //
       
   921 void WlanDot11InfrastructureModeInit::ContinueDot11StateTraversal( 
       
   922     WlanContextImpl& aCtxImpl )
       
   923     {
       
   924     // Start Voice over WLAN Call maintenance
       
   925     aCtxImpl.StartVoiceOverWlanCallMaintenance();
       
   926         
       
   927     // start to keep the WLAN connection alive
       
   928     aCtxImpl.StartKeepAlive();    
       
   929 
       
   930     if ( aCtxImpl.CurrentDot11PwrMgmtMode() != 
       
   931          aCtxImpl.DesiredDot11PwrMgmtMode() )
       
   932         {
       
   933         // dot11 power management mode change is needed 
       
   934         
       
   935         // initialize the counter which we use to determine if we should 
       
   936         // indicate BSS lost if we continuously are unsuccessful in changing the
       
   937         // power mgmt mode
       
   938         aCtxImpl.InitializeSetPsModeCount();
       
   939         
       
   940         ChangeState( aCtxImpl,
       
   941             *this,
       
   942             aCtxImpl.iStates.iPwrMgmtTransitionMode );
       
   943         }
       
   944     else
       
   945         {
       
   946         // no power management mode change is needed 
       
   947         ChangeState( aCtxImpl,
       
   948             *this,
       
   949             aCtxImpl.iStates.iInfrastructureNormalMode );
       
   950         }
       
   951     }
       
   952 
       
   953 // -----------------------------------------------------------------------------
       
   954 // 
       
   955 // -----------------------------------------------------------------------------
       
   956 //
       
   957 void WlanDot11InfrastructureModeInit::CompleteConnectRequest( 
       
   958     WlanContextImpl& aCtxImpl, 
       
   959     TInt aCompletionCode ) const
       
   960     {
       
   961     OnOidComplete( aCtxImpl, aCompletionCode );
       
   962     }