wlanutilities/wlansniffer/engine/server/src/wsfwlanscanner.cpp
branchRCL_3
changeset 25 f28ada11abbf
equal deleted inserted replaced
24:63be7eb3fc78 25:f28ada11abbf
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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 "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 CWsfWlanScanner
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  EXTERNAL INCLUDES
       
    21 #include <wlanmgmtclient.h>
       
    22 #include <centralrepository.h>
       
    23 #include <utf.h>
       
    24 #include <wlancontainer.h>
       
    25 #include <commsdattypeinfov1_1.h>
       
    26 #include <wlanscaninfo.h>
       
    27 #include <cmdestinationext.h>
       
    28 #include <commdb.h>
       
    29 
       
    30 #ifdef __WINS__
       
    31 #include <e32math.h>
       
    32 #endif
       
    33 
       
    34 //  CLASS HEADER
       
    35 #include "wsfwlanscanner.h"
       
    36 
       
    37 //  INTERNAL INCLUDES
       
    38 #include "wsfwlaninfoarray.h"
       
    39 #include "wsfwlanscaninfodefines.h"
       
    40 #include "wsfwlanconnectiondetailsprovider.h"
       
    41 #include "wsfwlansettingsaccessor.h"
       
    42 
       
    43 #include "wsflogger.h"
       
    44 
       
    45 //  LOCAL DEFINITIONS
       
    46 using namespace CMManager;
       
    47 
       
    48 
       
    49 /**
       
    50 * Microseconds in a second 
       
    51 */
       
    52 static const TInt KMicrosecPerSecond = 1000 * 1000;
       
    53 
       
    54 
       
    55 //  CONSTRUCTION AND DESTRUCTION
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CWsfWlanScanner::NewL
       
    59 // ---------------------------------------------------------------------------
       
    60 //    
       
    61 CWsfWlanScanner* CWsfWlanScanner::NewL( CommsDat::CMDBSession& aDbSession )
       
    62     {
       
    63     CWsfWlanScanner* self = CWsfWlanScanner::NewLC( aDbSession );
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CWsfWlanScanner::NewLC
       
    71 // ---------------------------------------------------------------------------
       
    72 //    
       
    73 CWsfWlanScanner* CWsfWlanScanner::NewLC( CommsDat::CMDBSession& aDbSession )
       
    74     {
       
    75     CWsfWlanScanner* self = new( ELeave ) CWsfWlanScanner( aDbSession );
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     return self;
       
    79     }
       
    80 
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CWsfWlanScanner::~CWsfWlanScanner
       
    84 // ---------------------------------------------------------------------------
       
    85 //    
       
    86 CWsfWlanScanner::~CWsfWlanScanner()
       
    87     {
       
    88     LOG_ENTERFN( "CWsfWlanScanner::~CWsfWlanScanner" );
       
    89     StopScanning();
       
    90     Cancel();
       
    91     iTimer.Close();
       
    92     iCmManagerExt.Close();
       
    93     delete iActiveConnectionName;
       
    94     delete iScanResults;
       
    95     delete iWlanMgmtClient;
       
    96     delete iWlanSettingsAccessor;
       
    97     delete iScanInfo;
       
    98     delete iScanArray;
       
    99     iDirectScanSsids.Close();
       
   100     iDirectScanIapIDs.Close();
       
   101     iAvailableIaps.Close();
       
   102     iDbSession = NULL; // not owning
       
   103     iConnectionDetailsProvider = NULL;
       
   104     }
       
   105 
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CWsfWlanScanner::CWsfWlanScanner
       
   109 // ---------------------------------------------------------------------------
       
   110 //    
       
   111 CWsfWlanScanner::CWsfWlanScanner( CommsDat::CMDBSession& aDbSession ): 
       
   112     CActive( EPriorityStandard ),
       
   113     iDbSession( &aDbSession ),
       
   114     iScanState( EIdle )
       
   115     {
       
   116     }
       
   117 
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CWsfWlanScanner::ConstructL
       
   121 // ---------------------------------------------------------------------------
       
   122 //    
       
   123 void CWsfWlanScanner::ConstructL()
       
   124     {
       
   125     LOG_ENTERFN( "CWsfWlanScanner::ConstructL" );
       
   126     
       
   127 #ifndef __WINS__ // client is not available on wins
       
   128     iWlanMgmtClient = CWlanMgmtClient::NewL();
       
   129 
       
   130     iScanInfo = CWlanScanInfo::NewL();
       
   131 #endif
       
   132 
       
   133     iCmManagerExt.OpenL();
       
   134     
       
   135     iScanArray = CWsfWlanInfoArray::NewL();
       
   136     
       
   137     User::LeaveIfError( iTimer.CreateLocal() );
       
   138     iScanResults = KNullDesC8().AllocL();
       
   139 
       
   140     iWlanSettingsAccessor = CWsfWlanSettingsAccessor::NewL( *iDbSession );
       
   141     iScanningInterval = iWlanSettingsAccessor->ScanInterval() * 
       
   142                                                           KMicrosecPerSecond;
       
   143     iShowAvailability = iWlanSettingsAccessor->ShowAvailability();
       
   144     
       
   145     LOG_WRITEF( "initial bgScanInterval = %d sec", 
       
   146                 iWlanSettingsAccessor->ScanInterval() );
       
   147     LOG_WRITEF( "initial showAvailability = %d", iShowAvailability );
       
   148     
       
   149     CActiveScheduler::Add( this );
       
   150     }
       
   151 
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CWsfWlanScanner::DoCancel
       
   155 // ---------------------------------------------------------------------------
       
   156 //    
       
   157 void CWsfWlanScanner::DoCancel()
       
   158     {
       
   159     LOG_ENTERFN( "CWsfWlanScanner::DoCancel" );
       
   160     iTimer.Cancel();
       
   161 #ifndef __WINS__
       
   162     iWlanMgmtClient->CancelGetAvailableIaps();
       
   163     iWlanMgmtClient->CancelGetScanResults();
       
   164 #endif    
       
   165     iScanState = EIdle;    
       
   166     }
       
   167  
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // CWsfWlanScanner::RunL
       
   171 // ---------------------------------------------------------------------------
       
   172 //    
       
   173 void CWsfWlanScanner::RunL()
       
   174     {
       
   175     LOG_ENTERFN( "CWsfWlanScanner::RunL" );
       
   176     
       
   177     /*
       
   178      * Scan logic
       
   179      * 1. Get available IAPs - state = EIdle
       
   180      * 2. Do broadcast scan - state = EBroadcastScan
       
   181      * 3. Process broadcast scan results - state = EProcessBroadcastScan
       
   182      * 4. Do direct scans for remaining known networks
       
   183      *    from step 2. Get available IAPs - state = EDirectScan
       
   184      * 5. Add connected network - state = EFinished
       
   185      * 6. Set names and priorities for known networks - state = EFinished
       
   186      */
       
   187 
       
   188     if ( iScanState == EIdle )
       
   189         {
       
   190         LOG_WRITE( "Get available IAPs scan phase" );
       
   191 
       
   192         // prepare things for direct scans
       
   193         PrepareDirectScan();
       
   194           
       
   195         // notify clients
       
   196         if ( iObserver )
       
   197             {
       
   198             iObserver->WlanScanStarted();
       
   199             }
       
   200         
       
   201 #ifndef __WINS__
       
   202         // get available iaps
       
   203         // (this only shows iaps with security mode matching to scan results
       
   204         // and  also finds hidden wlans for which an iap has been configured)
       
   205         iAvailableIaps.Reset();
       
   206         iWlanMgmtClient->GetAvailableIaps( iCacheLifetime, 
       
   207                                            iMaxDelay, 
       
   208                                            EFalse, 
       
   209                                            iStatus, 
       
   210                                            iAvailableIaps );
       
   211         SetActive();
       
   212 #else
       
   213         // for testing
       
   214         SetActive();
       
   215         TRequestStatus* status = &iStatus;
       
   216         User::RequestComplete( status, KErrNone );
       
   217 #endif 
       
   218         iScanState = EBroadcastScan;
       
   219         }
       
   220         
       
   221     else if ( iScanState == EBroadcastScan )
       
   222         {
       
   223         LOG_WRITEF( "GetAvailableIaps returned iStatus=%d", iStatus.Int() );
       
   224         if ( iStatus.Int() )
       
   225             {
       
   226             LOG_WRITE( "Error in getting available IAPs - leave" );
       
   227             User::Leave( iStatus.Int() );
       
   228             }
       
   229         
       
   230 #ifdef _DEBUG
       
   231         for ( TInt i = 0; i < iAvailableIaps.Count(); ++i )
       
   232             {
       
   233             LOG_WRITEF( "iAvailableIaps array index[%d] IapId[%d] rssi[%d]", i,
       
   234                         iAvailableIaps[i].iIapId, iAvailableIaps[i].iRssi );
       
   235             }
       
   236 #endif
       
   237     
       
   238 #ifndef __WINS__ 
       
   239         // do broadcast scan
       
   240         iWlanMgmtClient->GetScanResults( iStatus, *iScanInfo );
       
   241         SetActive();
       
   242 #else
       
   243         // for testing
       
   244         SetActive();
       
   245         TRequestStatus* status = &iStatus;
       
   246         User::RequestComplete( status, KErrNone );
       
   247 #endif 
       
   248         iScanState = EProcessBroadcastScan;
       
   249         }
       
   250         
       
   251     else if ( iScanState == EProcessBroadcastScan )
       
   252         {
       
   253         // process broadcast scan results
       
   254         DoScanForNetworksL();
       
   255         
       
   256         // now it's time to initiate direct scan 
       
   257         // for remaining known networks
       
   258         if ( iDirectScanSsids.Count() )
       
   259             {
       
   260 #ifdef _DEBUG
       
   261             HBufC* ssid = TWsfWlanInfo::GetSsidAsUnicodeLC( 
       
   262                                                         iDirectScanSsids[0] );
       
   263             LOG_WRITEF( "requesting direct scan for [%S]", ssid );
       
   264             CleanupStack::PopAndDestroy( ssid );
       
   265 #endif
       
   266             
       
   267 #ifndef __WINS__
       
   268             // run direct scan
       
   269             iWlanMgmtClient->GetScanResults( iDirectScanSsids[0], 
       
   270                                              iStatus, *iScanInfo );
       
   271             SetActive();
       
   272 #else
       
   273             // for testing
       
   274             SetActive();
       
   275             TRequestStatus* status = &iStatus;
       
   276             User::RequestComplete( status, KErrNone );
       
   277 #endif                                             
       
   278 
       
   279             iScanState = EDirectScan;
       
   280             }
       
   281         else
       
   282             {
       
   283             LOG_WRITE( "direct scan skipped" );
       
   284             iScanState = EFinished;
       
   285             }
       
   286         }
       
   287         
       
   288     else if ( iScanState == EDirectScan )
       
   289         {
       
   290         LOG_WRITE( "direct scan results" );
       
   291 
       
   292 #ifndef __WINS__
       
   293         ProcessDirectScanResultL();
       
   294 #endif
       
   295  
       
   296         // delete the processed item (first)
       
   297         iDirectScanSsids.Remove( 0 );
       
   298         iDirectScanIapIDs.Remove( 0 );
       
   299 
       
   300         if ( iDirectScanSsids.Count() )
       
   301             {
       
   302             // repeated direct scans for known networks
       
   303 #ifdef _DEBUG
       
   304             HBufC* ssid = TWsfWlanInfo::GetSsidAsUnicodeLC( 
       
   305                                                         iDirectScanSsids[0] );
       
   306             LOG_WRITEF( "requesting direct scan for [%S]", ssid );
       
   307             CleanupStack::PopAndDestroy( ssid );
       
   308 #endif
       
   309             
       
   310 #ifndef __WINS__
       
   311             // run direct scan
       
   312             iWlanMgmtClient->GetScanResults( iDirectScanSsids[0], 
       
   313                                              iStatus, *iScanInfo );        
       
   314             SetActive();
       
   315 #else
       
   316             // for testing
       
   317             SetActive();
       
   318             TRequestStatus* status = &iStatus;
       
   319             User::RequestComplete( status, KErrNone );
       
   320 #endif                                             
       
   321             }
       
   322         else
       
   323             {
       
   324             // there is nothing more to do
       
   325             iScanState = EFinished;
       
   326             }
       
   327         }
       
   328     
       
   329     if ( iScanState == EFinished )
       
   330         {
       
   331         LOG_WRITE( "scanning finished" );
       
   332 #ifndef __WINS__
       
   333         AddConnectedWLANInfoL();
       
   334         
       
   335         TWsfWlanInfo* info(NULL);
       
   336         TInt scanArrayCount( iScanArray->Count() );
       
   337         
       
   338         for ( TInt i(0) ; i < scanArrayCount ; i++ )
       
   339             {  
       
   340             info = (*iScanArray)[ i ];
       
   341             
       
   342             if( info->iIapId )
       
   343                 {
       
   344                 TRAPD( error, UpdatePriorityL( *info ) );
       
   345                 if ( error )
       
   346                     {
       
   347                     // Ignore error and just continue
       
   348                     LOG_WRITE( "Prio update failed" );
       
   349                     }
       
   350                 }
       
   351             
       
   352             if( info->iIapId && info->iConnectionState != EConnected )
       
   353                 {
       
   354                 ReplaceSsidsWithIapName( *info );
       
   355                 }
       
   356             }
       
   357 #endif //_WINS_
       
   358         
       
   359         // sort the array
       
   360         iScanArray->SortArrayL();
       
   361         
       
   362         HBufC8* results = iScanArray->SerializeContentLC();
       
   363         CleanupStack::Pop( results );
       
   364         delete iScanResults;
       
   365         iScanResults = results;
       
   366 
       
   367 #ifdef _DEBUG
       
   368         DumpScanResultsL( iScanArray );
       
   369 #endif
       
   370         
       
   371         // we may let go the scan array contents...
       
   372         iScanArray->Reset();
       
   373     
       
   374         // notify clients that data is ready
       
   375         if ( iObserver )
       
   376             {
       
   377             iObserver->WlanScanCompleteL();
       
   378             }
       
   379 
       
   380         if ( !iShowAvailability )
       
   381             {
       
   382             // reset the timer if we are responsible for scheduling scans
       
   383             iTimer.Cancel();
       
   384             iTimer.After( iStatus, 
       
   385                           TTimeIntervalMicroSeconds32( iScanningInterval ) );
       
   386             Cancel();
       
   387             iCacheLifetime = 0;
       
   388             iMaxDelay = 0;
       
   389             SetActive();
       
   390             }
       
   391         
       
   392         iScanState = EIdle;
       
   393         }
       
   394     }
       
   395 
       
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // CWsfWlanScanner::AddConnectedWLANInfo
       
   399 // ---------------------------------------------------------------------------
       
   400 //    
       
   401 void CWsfWlanScanner::AddConnectedWLANInfoL()
       
   402     {
       
   403     LOG_ENTERFN( "CWsfWlanScanner::AddConnectedWLANInfoL" );
       
   404     // Get the possible connection
       
   405     if ( iConnectionDetailsProvider )
       
   406         {
       
   407         TWlanSsid connectedSsid;
       
   408         TInt error = iWlanMgmtClient->GetConnectionSsid( connectedSsid );
       
   409         
       
   410         LOG_WRITEF( "GetConnectionSsid returned=%d", error );
       
   411         
       
   412         TBool connected = ( error == KErrNone && connectedSsid.Length() );
       
   413     
       
   414         if ( !connected && !iConnectionDetailsProvider->IsConnected() )
       
   415             {
       
   416             LOG_WRITEF( "Not connected [connected=%d]", connected );
       
   417             return;
       
   418             }
       
   419         
       
   420         TWsfWlanInfo* connectedInfo = new (ELeave) TWsfWlanInfo();
       
   421         CleanupStack::PushL( connectedInfo );
       
   422         
       
   423         if ( iConnectionDetailsProvider->ConnectedWlanConnectionDetailsL(
       
   424                 connectedInfo) )
       
   425             {
       
   426             TBuf8<KWlanMaxAccessPointNameLength> connectedSsidOrIap;
       
   427             connectedSsidOrIap.Copy( connectedInfo->iSsid );
       
   428             // ConnectedWlanConnectionDetailsL() may have returned an IAP name instead of SSID.
       
   429             // make sure that we really have SSID in connectedInfo->iSSID at this phase.
       
   430             
       
   431             connectedInfo->iRawSsid.Copy( connectedSsid );
       
   432             connectedInfo->iSsid.Copy( connectedSsid );
       
   433             connectedInfo->iCoverage = 0;
       
   434             connectedInfo->iVisibility = 1;
       
   435 
       
   436             TBool connectedInfoAppended = EFalse;
       
   437 
       
   438             RPointerArray<TWsfWlanInfo> matchArray;
       
   439             CleanupClosePushL( matchArray );
       
   440 
       
   441             if ( connectedInfo->iIapId )
       
   442                 {
       
   443                 LOG_WRITEF( "Connected iap [%d]", connectedInfo->iIapId );
       
   444                 iScanArray->MatchWithIapIDL( connectedInfo->iIapId,
       
   445                         iScanArray->Count(), matchArray );
       
   446                 
       
   447                 if ( !matchArray.Count() )
       
   448                     {
       
   449                     LOG_WRITE( "Not found with Iap id" );
       
   450                     iScanArray->MatchL( connectedInfo->iSsid,
       
   451                                         connectedInfo->iSecurityMode,
       
   452                                         connectedInfo->iNetMode, 
       
   453                                         connectedInfo->UsesPreSharedKey(),
       
   454                                         iScanArray->Count(),
       
   455                                         matchArray );
       
   456                     }
       
   457                 
       
   458                 }
       
   459             else
       
   460                 {
       
   461                 LOG_WRITE( "Easy WLAN connection" );
       
   462                 iScanArray->MatchL( connectedInfo->iSsid,
       
   463                         connectedInfo->iSecurityMode,
       
   464                         connectedInfo->iNetMode, 
       
   465                         connectedInfo->UsesPreSharedKey(),
       
   466                         iScanArray->Count(),
       
   467                         matchArray );
       
   468                 }
       
   469 
       
   470             if ( matchArray.Count() )
       
   471                 {
       
   472                 LOG_WRITE( "Info found" );
       
   473                 TWsfWlanInfo* temp = matchArray[0];
       
   474                 temp->iConnectionState = EConnected;
       
   475                 temp->iIapId = connectedInfo->iIapId;
       
   476                 temp->iSsid.Copy( connectedSsidOrIap );
       
   477                 temp->iNetworkName.Zero();
       
   478                 }
       
   479             else
       
   480                 {
       
   481                 LOG_WRITE( "Info not found - append" );
       
   482                 connectedInfo->iSsid.Copy( connectedSsidOrIap );
       
   483                 iScanArray->AppendL( connectedInfo );
       
   484                 connectedInfoAppended = ETrue;
       
   485                 }
       
   486 
       
   487             CleanupStack::PopAndDestroy( &matchArray );
       
   488             if ( connectedInfoAppended )
       
   489                 {
       
   490                 CleanupStack::Pop( connectedInfo );
       
   491                 }
       
   492             else
       
   493                 {
       
   494                 CleanupStack::PopAndDestroy( connectedInfo );
       
   495                 }
       
   496             }
       
   497         else
       
   498             {
       
   499             CleanupStack::PopAndDestroy( connectedInfo );
       
   500             }
       
   501         }
       
   502     else
       
   503         {
       
   504         LOG_WRITE( "No connection details provider" );
       
   505         }
       
   506     }
       
   507 
       
   508 
       
   509 #ifdef _DEBUG
       
   510 // ---------------------------------------------------------------------------
       
   511 // CWsfWlanScanner::DumpScanResultsL
       
   512 // ---------------------------------------------------------------------------
       
   513 //    
       
   514 void CWsfWlanScanner::DumpScanResultsL( CWsfWlanInfoArray* aArray )
       
   515     {
       
   516     LOG_ENTERFN( "CWsfWlanScanner::DumpScanResultsL" );
       
   517     _LIT( Kopen, "open" );
       
   518     _LIT( Kwep, "wep" );
       
   519     _LIT( Kwpa, "wpa" );
       
   520     _LIT( Kwpa2, "wpa2" );        
       
   521     _LIT( K802, "802.1x" );
       
   522     _LIT( KWAPI, "WAPI" );
       
   523     _LIT( KUnknown, "Unknown" );
       
   524 
       
   525     _LIT( Kpsk, "psk" );
       
   526     _LIT( Keap, "eap" );
       
   527     _LIT( Khidden, "<hidden>" );
       
   528 
       
   529     for ( TInt i( 0 ); i < aArray->Count(); ++i )
       
   530         {
       
   531         TWsfWlanInfo* wi( (*aArray)[i] );
       
   532         const TDesC* sm( 0 );
       
   533 
       
   534         switch ( wi->iSecurityMode )
       
   535             {
       
   536             case EWlanSecModeOpen:
       
   537                 sm = &Kopen;
       
   538                 break;
       
   539             case EWlanSecModeWep:
       
   540                 sm = &Kwep;
       
   541                 break;
       
   542             case EWlanSecModeWpa:
       
   543                 sm = &Kwpa;
       
   544                 break;
       
   545             case EWlanSecModeWpa2:
       
   546                 sm = &Kwpa2;
       
   547                 break;
       
   548             case EWlanSecMode802_1x:
       
   549                 sm = &K802;
       
   550                 break;
       
   551             case EWlanSecModeWAPI:
       
   552                 sm = &KWAPI;
       
   553                 break;
       
   554             default:
       
   555                 sm = &KUnknown;
       
   556                 break;
       
   557             }
       
   558         
       
   559         const TDesC* psk = wi->UsesPreSharedKey()? &Kpsk:             
       
   560                                ( ( wi->iSecurityMode == EWlanSecMode802_1x || 
       
   561                                    wi->iSecurityMode == EWlanSecModeWpa ||
       
   562                                    wi->iSecurityMode == EWlanSecModeWpa2 )? 
       
   563                                       &Keap: &KNullDesC );
       
   564         HBufC16 *ssid = TWsfWlanInfo::GetSsidAsUnicodeLC( wi->iSsid );
       
   565         
       
   566         LOG_WRITEF( "[%S] IapId=%d %S %S %S", ssid, wi->iIapId, sm, psk, 
       
   567                     wi->iVisibility? &KNullDesC: &Khidden );
       
   568         CleanupStack::PopAndDestroy( ssid );
       
   569         }
       
   570     
       
   571     }
       
   572 #endif // _DEBUG
       
   573 
       
   574 
       
   575 // ---------------------------------------------------------------------------
       
   576 // CWsfWlanScanner::RunError
       
   577 // ---------------------------------------------------------------------------
       
   578 //    
       
   579 TInt CWsfWlanScanner::RunError( TInt aError )
       
   580     {
       
   581     LOG_ENTERFN( "CWsfWlanScanner::RunError" );
       
   582     LOG_WRITEF( "error = %d", aError );
       
   583     
       
   584     iScanArray->Reset();
       
   585     
       
   586     if ( iObserver && aError != KErrNotReady )
       
   587         {
       
   588         // KErrNotReady is excluded as it indicates that the WLAN engine
       
   589         // has not yet set up itself, which we cannot help
       
   590         iObserver->NotifyError( aError );    
       
   591         }
       
   592 
       
   593     iScanState = EIdle;
       
   594     
       
   595     if ( !iShowAvailability )
       
   596         {
       
   597         // the scanning has failed, re-issue the scan timer
       
   598         iTimer.Cancel();
       
   599         iTimer.After( iStatus, 
       
   600                       TTimeIntervalMicroSeconds32( iScanningInterval ) );
       
   601         iCacheLifetime = 0;
       
   602         iMaxDelay = 0;
       
   603         SetActive();    
       
   604         }
       
   605         
       
   606     return KErrNone;    
       
   607     }
       
   608 
       
   609 
       
   610 // ---------------------------------------------------------------------------
       
   611 // CWsfWlanScanner::SetObserver
       
   612 // ---------------------------------------------------------------------------
       
   613 //    
       
   614 void CWsfWlanScanner::SetObserver( MWsfWlanScannerObserver& aObserver )
       
   615     {
       
   616     iObserver = &aObserver;
       
   617     }
       
   618 
       
   619 
       
   620 // ---------------------------------------------------------------------------
       
   621 // CWsfWlanScanner::StartScanningL
       
   622 // ---------------------------------------------------------------------------
       
   623 //    
       
   624 void CWsfWlanScanner::StartScanningL()
       
   625     {
       
   626     LOG_ENTERFN( "CWsfWlanScanner::StartScanningL" );
       
   627 
       
   628     if ( iScanState == EIdle && !IsActive() )
       
   629         {
       
   630         LOG_WRITE( "request notifications" );
       
   631 #ifndef __WINS__
       
   632         iWlanMgmtClient->CancelNotifications();
       
   633         iWlanMgmtClient->ActivateNotificationsL( *this );
       
   634 #endif
       
   635         iWlanSettingsAccessor->RequestNotificationL( *this );
       
   636         
       
   637         iScanState = EIdle;
       
   638 
       
   639         if ( !iShowAvailability )
       
   640             {
       
   641             // in case show wlan availability is off, carry out a scan now
       
   642             iCacheLifetime = 0;
       
   643             iMaxDelay = 0;
       
   644             SetActive();
       
   645             TRequestStatus* status = &iStatus;
       
   646             User::RequestComplete( status, KErrNone );
       
   647             }
       
   648         }
       
   649     }
       
   650 
       
   651 
       
   652 // ---------------------------------------------------------------------------
       
   653 // CWsfWlanScanner::StartScanningL
       
   654 // ---------------------------------------------------------------------------
       
   655 //    
       
   656 void CWsfWlanScanner::StopScanning()
       
   657     {
       
   658     LOG_ENTERFN( "CWsfWlanScanner::StopScanning" );
       
   659 
       
   660     Cancel();
       
   661 
       
   662 #ifndef __WINS__       
       
   663     if ( iWlanMgmtClient )
       
   664         {
       
   665         iWlanMgmtClient->CancelNotifications();
       
   666         }
       
   667 #endif
       
   668   
       
   669     if ( iWlanSettingsAccessor )
       
   670         {
       
   671         iWlanSettingsAccessor->CancelNotifications();
       
   672         }
       
   673     }
       
   674 
       
   675 
       
   676 // ---------------------------------------------------------------------------
       
   677 // CWsfWlanScanner::RestartScanning
       
   678 // ---------------------------------------------------------------------------
       
   679 //    
       
   680 TBool CWsfWlanScanner::RestartScanning()
       
   681     {
       
   682     LOG_ENTERFN( "CWsfWlanScanner::RestartScanning" );
       
   683 
       
   684     TBool restarted( EFalse );
       
   685     LOG_WRITEF( "iScanState = %d isActive = %d iShowAvailability = %d",
       
   686                iScanState, IsActive(), iShowAvailability );
       
   687     
       
   688     if ( iScanState == EIdle && ( IsActive() || iShowAvailability ) )
       
   689         {
       
   690         // we have been waiting for the timer to complete
       
   691         // cancel it manually
       
   692         Cancel();
       
   693         iCacheLifetime = 0;
       
   694         iMaxDelay = 0;
       
   695         // then complete ourselves
       
   696         SetActive();
       
   697         TRequestStatus* status = &iStatus;
       
   698         User::RequestComplete( status, KErrNone );
       
   699         restarted = ETrue;
       
   700         }
       
   701     
       
   702     LOG_WRITEF( "restarted = %d", restarted );
       
   703     return restarted;
       
   704     }
       
   705 
       
   706 
       
   707 // ---------------------------------------------------------------------------
       
   708 // CWsfWlanScanner::AbortScanning
       
   709 // ---------------------------------------------------------------------------
       
   710 //    
       
   711 void CWsfWlanScanner::AbortScanning()
       
   712     {
       
   713     LOG_ENTERFN( "CWsfWlanScanner::AbortScanning" );
       
   714     
       
   715     if ( iScanState != EIdle )
       
   716         {
       
   717         // cancel the current scanning
       
   718         Cancel();
       
   719 
       
   720         if ( !iShowAvailability )
       
   721             {
       
   722             // still, life goes on
       
   723             iTimer.After( iStatus, TTimeIntervalMicroSeconds32( 
       
   724                                                         iScanningInterval ) );
       
   725             iCacheLifetime = 0;
       
   726             iMaxDelay = 0;
       
   727             SetActive();        
       
   728             }
       
   729         }
       
   730     }
       
   731 
       
   732 
       
   733 // ---------------------------------------------------------------------------
       
   734 // CWsfWlanScanner::ConnectionStateChanged
       
   735 // ---------------------------------------------------------------------------
       
   736 //    
       
   737 void CWsfWlanScanner::ConnectionStateChanged( 
       
   738                                             TWlanConnectionMode /*aNewState*/ )
       
   739     {
       
   740     LOG_ENTERFN( "CWsfWlanScanner::ConnectionStateChanged" );
       
   741     }
       
   742     
       
   743 
       
   744 // ---------------------------------------------------------------------------
       
   745 // CWsfWlanScanner::BssidChanged
       
   746 // ---------------------------------------------------------------------------
       
   747 //    
       
   748 void CWsfWlanScanner::BssidChanged( TWlanBssid& /*aNewBSsid*/ )
       
   749     {
       
   750     LOG_ENTERFN( "CWsfWlanScanner::BssidChanged" );
       
   751     if ( iScanState == EIdle && !IsActive() )
       
   752         {
       
   753         iCacheLifetime = -1;
       
   754         iMaxDelay = 0;
       
   755         // complete ourselves
       
   756         SetActive();
       
   757         TRequestStatus* status = &iStatus;
       
   758         User::RequestComplete( status, KErrNone );
       
   759         }
       
   760     }
       
   761 
       
   762 
       
   763 // ---------------------------------------------------------------------------
       
   764 // CWsfWlanScanner::BssLost
       
   765 // ---------------------------------------------------------------------------
       
   766 //    
       
   767 void CWsfWlanScanner::BssLost()
       
   768     {
       
   769     LOG_ENTERFN( "CWsfWlanScanner::BssLost" );
       
   770     if ( iScanState == EIdle && !IsActive() )
       
   771         {
       
   772         iCacheLifetime = -1;
       
   773         iMaxDelay = 0;
       
   774         // complete ourselves
       
   775         SetActive();
       
   776         TRequestStatus* status = &iStatus;
       
   777         User::RequestComplete( status, KErrNone );
       
   778         }
       
   779     }
       
   780 
       
   781 
       
   782 // ---------------------------------------------------------------------------
       
   783 // CWsfWlanScanner::BssRegained
       
   784 // ---------------------------------------------------------------------------
       
   785 //    
       
   786 void CWsfWlanScanner::BssRegained()
       
   787     {
       
   788     LOG_ENTERFN( "CWsfWlanScanner::BssRegained" );
       
   789     if ( iScanState == EIdle && !IsActive() )
       
   790         {
       
   791         iCacheLifetime = -1;
       
   792         iMaxDelay = 0;
       
   793         // complete ourselves
       
   794         SetActive();
       
   795         TRequestStatus* status = &iStatus;
       
   796         User::RequestComplete( status, KErrNone );
       
   797         }
       
   798     }
       
   799 
       
   800 
       
   801 // ---------------------------------------------------------------------------
       
   802 // CWsfWlanScanner::NewNetworksDetected
       
   803 // ---------------------------------------------------------------------------
       
   804 //    
       
   805 void CWsfWlanScanner::NewNetworksDetected()
       
   806     {
       
   807     LOG_ENTERFN( "CWsfWlanScanner::NewNetworksDetected" );
       
   808     if ( iScanState == EIdle && !IsActive() )
       
   809         {
       
   810         iCacheLifetime = -1;
       
   811         iMaxDelay = 0;
       
   812         // complete ourselves
       
   813         SetActive();
       
   814         TRequestStatus* status = &iStatus;
       
   815         User::RequestComplete( status, KErrNone );
       
   816         }
       
   817     }
       
   818 
       
   819 
       
   820 // ---------------------------------------------------------------------------
       
   821 // CWsfWlanScanner::OldNetworksLost
       
   822 // ---------------------------------------------------------------------------
       
   823 //    
       
   824 void CWsfWlanScanner::OldNetworksLost()
       
   825     {
       
   826     LOG_ENTERFN( "CWsfWlanScanner::OldNetworksLost" );
       
   827     if ( iScanState == EIdle && !IsActive() )
       
   828         {
       
   829         iCacheLifetime = -1;
       
   830         iMaxDelay = 0;
       
   831         // complete ourselves
       
   832         SetActive();
       
   833         TRequestStatus* status = &iStatus;
       
   834         User::RequestComplete( status, KErrNone );
       
   835         }
       
   836     }
       
   837 
       
   838 
       
   839 // ---------------------------------------------------------------------------
       
   840 // CWsfWlanScanner::TransmitPowerChanged
       
   841 // ---------------------------------------------------------------------------
       
   842 //    
       
   843 void CWsfWlanScanner::TransmitPowerChanged( TUint /*aPower*/ )
       
   844     {
       
   845     LOG_ENTERFN( "CWsfWlanScanner::TransmitPowerChanged" );
       
   846     if ( iScanState == EIdle && !IsActive() )
       
   847         {
       
   848         iCacheLifetime = -1;
       
   849         iMaxDelay = 0;
       
   850         // complete ourselves
       
   851         SetActive();
       
   852         TRequestStatus* status = &iStatus;
       
   853         User::RequestComplete( status, KErrNone );
       
   854         }
       
   855     }
       
   856         
       
   857 
       
   858 // ---------------------------------------------------------------------------
       
   859 // CWsfWlanScanner::RssChanged
       
   860 // ---------------------------------------------------------------------------
       
   861 //    
       
   862 void CWsfWlanScanner::RssChanged( TWlanRssClass /*aRssClass*/, TUint /*aRss*/ )
       
   863     {
       
   864     LOG_ENTERFN( "CWsfWlanScanner::RssChanged" );
       
   865     if ( iScanState == EIdle && !IsActive() )
       
   866         {
       
   867         iCacheLifetime = -1;
       
   868         iMaxDelay = 0;
       
   869         // complete ourselves
       
   870         SetActive();
       
   871         TRequestStatus* status = &iStatus;
       
   872         User::RequestComplete( status, KErrNone );
       
   873         }
       
   874     }
       
   875 
       
   876 
       
   877 // ---------------------------------------------------------------------------
       
   878 // CWsfWlanScanner::PrepareDirectScan
       
   879 // ---------------------------------------------------------------------------
       
   880 //    
       
   881 void CWsfWlanScanner::PrepareDirectScan()
       
   882     {
       
   883     LOG_ENTERFN( "CWsfWlanScanner::PrepareDirectScanL" );
       
   884 
       
   885     // flush the arrays
       
   886     iDirectScanSsids.Reset();
       
   887     iDirectScanIapIDs.Reset();
       
   888     }
       
   889     
       
   890     
       
   891 // ---------------------------------------------------------------------------
       
   892 // CWsfWlanScanner::ProcessDirectScanResultL
       
   893 // ---------------------------------------------------------------------------
       
   894 //   
       
   895 void CWsfWlanScanner::ProcessDirectScanResultL()
       
   896     {
       
   897     LOG_ENTERFN( "CWsfWlanScanner::ProcessDirectScanResultL" );
       
   898     
       
   899     for ( iScanInfo->First(); !iScanInfo->IsDone(); iScanInfo->Next() )
       
   900         {
       
   901         RPointerArray<TWsfWlanInfo> matchArray;
       
   902         CleanupClosePushL(matchArray);
       
   903         iScanArray->MatchWithIapIDL( iDirectScanIapIDs[0], iScanArray->Count(), matchArray );
       
   904   
       
   905         TInt matchcount = matchArray.Count();
       
   906 
       
   907         if ( matchcount == 0 )
       
   908             {
       
   909             // not found yet
       
   910 #ifdef _DEBUG
       
   911             HBufC* ssid = TWsfWlanInfo::GetSsidAsUnicodeLC( iDirectScanSsids[0] );
       
   912             LOG_WRITEF( "[%S] found in direct scan", ssid ); 
       
   913             CleanupStack::PopAndDestroy( ssid );
       
   914 #endif       
       
   915             }
       
   916         else
       
   917             {
       
   918             LOG_WRITEF( "[%d] iap id is in scanarray", iDirectScanIapIDs[0] ); 
       
   919             for( TInt i(0); i < matchcount; i++ )
       
   920             	{
       
   921             	//if already found increase coverage
       
   922                 TWsfWlanInfo* temp = matchArray[i];
       
   923                 ++temp->iCoverage;
       
   924                 RefreshSignalStrength( *temp );
       
   925                 RefreshTechnology( *temp );
       
   926              	}
       
   927             }
       
   928         // Close() for matchArray
       
   929         CleanupStack::PopAndDestroy( &matchArray );  
       
   930         } // for iScanInfo              
       
   931     }
       
   932 
       
   933 
       
   934 // ---------------------------------------------------------------------------
       
   935 // CWsfWlanScanner::ReplaceSsidsWithIapName
       
   936 // ---------------------------------------------------------------------------
       
   937 //   
       
   938 void CWsfWlanScanner::ReplaceSsidsWithIapName(TWsfWlanInfo& aWlanInfo)
       
   939     {	
       
   940     LOG_ENTERFN( "CWsfWlanScanner::ReplaceSsidsWithIapName" );
       
   941     if ( aWlanInfo.iNetworkName.Length() )
       
   942         {
       
   943         LOG_WRITE( "Replace ssid" );
       
   944         aWlanInfo.iSsid.Copy( aWlanInfo.iNetworkName );
       
   945         aWlanInfo.iNetworkName.Zero();
       
   946         }
       
   947     }
       
   948 
       
   949 
       
   950 // ---------------------------------------------------------------------------
       
   951 // CWsfWlanScanner::UpdatePriorityL
       
   952 // ---------------------------------------------------------------------------
       
   953 //    
       
   954 void CWsfWlanScanner::UpdatePriorityL( TWsfWlanInfo& aWlanInfo )
       
   955     {
       
   956     LOG_WRITE( "CWsfWlanScanner::updatePriority" );
       
   957 
       
   958     TUint32 priority( 0 );
       
   959     TInt exists( KErrNotFound );
       
   960     TInt count( 0 );   
       
   961 
       
   962     // search for the destination of it                                                        
       
   963     RArray<TUint32> destinations;                                                              
       
   964     CleanupClosePushL( destinations );
       
   965 
       
   966     LOG_WRITE( "CWsfWlanScanner::updatePriority get all destinations" );
       
   967     iCmManagerExt.AllDestinationsL(destinations);                                              
       
   968 
       
   969     count = destinations.Count();                                                         
       
   970     LOG_WRITEF( "destination count %d", count);
       
   971 
       
   972     for( TInt i = 0; i < count && exists != KErrNone; i++ )                                    
       
   973         {
       
   974         RCmDestinationExt destination;                                                              
       
   975         destination = iCmManagerExt.DestinationL( destinations[ i ] );                         
       
   976         CleanupClosePushL( destination );  
       
   977 
       
   978         LOG_WRITE( "check if connection method belongs to destination" );
       
   979 
       
   980         RCmConnectionMethodExt connectionMethod;
       
   981         TRAP( exists,                                                                      
       
   982                 connectionMethod = destination.ConnectionMethodByIDL(                            
       
   983                         aWlanInfo.iIapId ) ); 
       
   984 
       
   985         LOG_WRITEF( "exists %d", exists );
       
   986         if( exists == KErrNone )                                                           
       
   987             {   
       
   988             CleanupClosePushL( connectionMethod ); 
       
   989             // correct destination found                                                   
       
   990             priority = destination.PriorityL( connectionMethod );
       
   991             aWlanInfo.SetPriority( priority );
       
   992 
       
   993             LOG_WRITEF( "priority %d", priority );
       
   994             CleanupStack::PopAndDestroy( &connectionMethod ); 
       
   995             }
       
   996         CleanupStack::PopAndDestroy( &destination );                                           
       
   997         }                                                                                      
       
   998     CleanupStack::PopAndDestroy( &destinations );
       
   999     }
       
  1000 
       
  1001 
       
  1002 #ifndef __WINS__
       
  1003 // ---------------------------------------------------------------------------
       
  1004 // CWsfWlanScanner::DoScanForNetworksL
       
  1005 // ---------------------------------------------------------------------------
       
  1006 //   
       
  1007 void CWsfWlanScanner::DoScanForNetworksL()
       
  1008     {
       
  1009     LOG_ENTERFN( "CWsfWlanScanner::DoScanForNetworksL" );
       
  1010         
       
  1011     // start by making sure the scan array is empty
       
  1012     iScanArray->Reset();    
       
  1013 
       
  1014     LOG_WRITEF( "GetScanResults returned iStatus=%d", iStatus.Int() );
       
  1015     
       
  1016     if ( iStatus.Int() )
       
  1017         {
       
  1018         // if the status is not KErrNone, we cannot be sure that iScanInfo
       
  1019         // doesn't cause a crash, so it's better to leave
       
  1020         LOG_WRITE( "Error in getting scan result - leave" );
       
  1021         User::Leave( iStatus.Int() );
       
  1022         }
       
  1023    
       
  1024     TInt nElem = 0;
       
  1025     TBool isHidden( EFalse );
       
  1026 
       
  1027     TInt avIapCount = iAvailableIaps.Count();
       
  1028 
       
  1029     LOG_WRITEF( "Available iap count %d", avIapCount ); 
       
  1030 
       
  1031     for( TInt i(0); i < avIapCount; i++ )
       
  1032         {
       
  1033         TBool addToArray( ETrue ); 
       
  1034         TWsfWlanInfo* availableInfo = new ( ELeave ) TWsfWlanInfo();       
       
  1035         CleanupStack::PushL( availableInfo );
       
  1036         availableInfo->iIapId = iAvailableIaps[i].iIapId;
       
  1037         TRAPD( error, GetWlanInfoFromIapL( *availableInfo ) );
       
  1038 
       
  1039         if ( error == KErrNotFound )
       
  1040             {
       
  1041             LOG_WRITEF( "Iap id = %d does not exist", availableInfo->iIapId );
       
  1042             addToArray = EFalse;
       
  1043             }
       
  1044         else if ( error )
       
  1045             {
       
  1046             LOG_WRITEF( "GetWlanInfoFromIapL failed err = %d", error );
       
  1047             User::Leave( error );
       
  1048             }
       
  1049 
       
  1050         if( addToArray )
       
  1051             { 
       
  1052             LOG_WRITE( "Add to array" );
       
  1053             availableInfo->iCoverage = 0;
       
  1054             availableInfo->iVisibility = 1;
       
  1055             availableInfo->iStrengthLevel = iAvailableIaps[i].iRssi;
       
  1056             availableInfo->iTransferRate = 0;
       
  1057             availableInfo->iConnectionState = ENotConnected;
       
  1058             iScanArray->AppendL(availableInfo);
       
  1059             nElem++;
       
  1060 
       
  1061             if ( availableInfo->iIapId )
       
  1062                 {
       
  1063                 LOG_WRITEF( "Append available iap[%d] rssi[%d] for direct scan", 
       
  1064                          availableInfo->iIapId, availableInfo->iStrengthLevel );
       
  1065                 iDirectScanIapIDs.Append( availableInfo->iIapId );
       
  1066                 iDirectScanSsids.Append( availableInfo->iSsid );
       
  1067                 }
       
  1068 
       
  1069             CleanupStack::Pop( availableInfo );
       
  1070             }
       
  1071         else
       
  1072             {
       
  1073             LOG_WRITE( "Info not added" );
       
  1074             CleanupStack::PopAndDestroy( availableInfo );
       
  1075             }
       
  1076         }
       
  1077     
       
  1078 #ifdef _DEBUG
       
  1079         LOG_WRITE( "Dump scan results - available IAPs" );
       
  1080         DumpScanResultsL( iScanArray );
       
  1081 #endif
       
  1082       
       
  1083     // Process the scanned results
       
  1084     for( iScanInfo->First(); !iScanInfo->IsDone(); iScanInfo->Next() )
       
  1085         {
       
  1086         TWsfWlanInfo* wlanInfo = iScanArray->At( nElem );
       
  1087         if ( !wlanInfo )
       
  1088             {
       
  1089             wlanInfo = new ( ELeave ) TWsfWlanInfo();
       
  1090             CleanupStack::PushL( wlanInfo );
       
  1091             iScanArray->AppendL( wlanInfo );
       
  1092             CleanupStack::Pop( wlanInfo );
       
  1093             }
       
  1094         isHidden = RefreshNetworkNameL( *wlanInfo );
       
  1095         wlanInfo->iVisibility = !isHidden;
       
  1096         wlanInfo->iStrengthLevel = EWlanSignalUnavailable;
       
  1097         wlanInfo->iTransferRate = 0;
       
  1098         wlanInfo->iConnectionState = ENotConnected;
       
  1099 
       
  1100         if( !isHidden )
       
  1101             {
       
  1102             // not hidden
       
  1103             RefreshNetworkMode( *wlanInfo );
       
  1104             RefreshSecurityMode( *wlanInfo );
       
  1105             RefreshTechnology( *wlanInfo );
       
  1106 
       
  1107             // check if we already have an entry/entries corresponding to a scan result
       
  1108             // (multiple entries for one scan result possible if GetAvailableIaps()
       
  1109             // found several iaps configured for same wlan)
       
  1110             RPointerArray<TWsfWlanInfo> matchArray;
       
  1111             CleanupClosePushL(matchArray);
       
  1112             iScanArray->MatchL( wlanInfo->iSsid, 
       
  1113                                 wlanInfo->iSecurityMode, 
       
  1114                                 wlanInfo->iNetMode, 
       
  1115                                 wlanInfo->UsesPreSharedKey(), 
       
  1116                                 nElem, 
       
  1117                                 matchArray );
       
  1118 
       
  1119             TInt matchcount = matchArray.Count();
       
  1120 
       
  1121             // if not found
       
  1122             if( matchcount == 0 )
       
  1123                 {
       
  1124                 wlanInfo->iCoverage = 1;
       
  1125                 RefreshSignalStrength( *wlanInfo );
       
  1126                 RefreshTechnology( *wlanInfo );
       
  1127                 ++nElem; // new entry, inc index in array
       
  1128                 }
       
  1129             else // if found inc coverage and refresh signal strength and rate
       
  1130                 {
       
  1131                 for( TInt i(0); i < matchcount; i++ )
       
  1132                     {
       
  1133                     TWsfWlanInfo* temp = matchArray[i];
       
  1134                     ++temp->iCoverage;
       
  1135                     RefreshSignalStrength( *temp );
       
  1136                     RefreshTechnology( *temp );
       
  1137 
       
  1138                     if ( temp->iIapId )
       
  1139                         {
       
  1140                         TInt index( KErrNone );
       
  1141                         do {
       
  1142                             LOG_WRITE( "Not hidden - Searching from direct scan list.." );
       
  1143                             // remove this item from the direct scan list, if found 
       
  1144                             index = iDirectScanIapIDs.Find( temp->iIapId  );
       
  1145                             if ( index != KErrNotFound )
       
  1146                                 {
       
  1147                                 LOG_WRITEF( "Found - removing iap id [%d]", iDirectScanIapIDs[index] );
       
  1148                                 iDirectScanSsids.Remove( index );
       
  1149                                 iDirectScanIapIDs.Remove( index );
       
  1150                                 }
       
  1151                         } while ( index != KErrNotFound );
       
  1152                         }
       
  1153                     }
       
  1154                 }
       
  1155             CleanupStack::PopAndDestroy(); // results in Close() being called on matchArray
       
  1156             }
       
  1157         }
       
  1158     //get rid of excess items
       
  1159     iScanArray->DeleteFromTail(iScanArray->Count() - nElem);
       
  1160     }
       
  1161 
       
  1162 #else // __WINS__
       
  1163 
       
  1164 // ---------------------------------------------------------------------------
       
  1165 // CWsfWlanScanner::DoScanForNetworksL
       
  1166 // ---------------------------------------------------------------------------
       
  1167 //   
       
  1168 void CWsfWlanScanner::DoScanForNetworksL()
       
  1169     {
       
  1170     LOG_ENTERFN( "CWsfWlanScanner::DoScanForNetworksL" );
       
  1171         
       
  1172     // start by making sure the scan array is empty
       
  1173     iScanArray->Reset();    
       
  1174 
       
  1175     TWsfWlanInfo* wlan0 = new (ELeave) TWsfWlanInfo();
       
  1176     CleanupStack::PushL( wlan0 );    
       
  1177     wlan0->iConnectionState = EConnected;
       
  1178     wlan0->iIapId = 666;
       
  1179     wlan0->iNetMode = EInfra;
       
  1180     wlan0->iSecurityMode = EWlanSecModeWep;
       
  1181     wlan0->iSsid = _L8("[C]Known WEP");
       
  1182     wlan0->iStrengthLevel = EWlanSignalStrengthMax;  
       
  1183     wlan0->iVisibility = ETrue;
       
  1184     wlan0->iCoverage = 1;
       
  1185     if ( Math::Random() % 2 == 0 )
       
  1186         {
       
  1187         iScanArray->AppendL( wlan0 );
       
  1188         }
       
  1189     else 
       
  1190         {
       
  1191         delete wlan0;
       
  1192         }
       
  1193         
       
  1194     CleanupStack::Pop( wlan0 );
       
  1195 
       
  1196     TWsfWlanInfo* wlan1 = new (ELeave) TWsfWlanInfo();
       
  1197     CleanupStack::PushL( wlan1 );    
       
  1198     wlan1->iConnectionState = ENotConnected;
       
  1199     wlan1->iIapId = 666;
       
  1200     wlan1->iNetMode = EInfra;
       
  1201     wlan1->iSecurityMode = EWlanSecModeOpen;
       
  1202     wlan1->iSsid = _L8("Known open");
       
  1203     wlan1->iStrengthLevel = EWlanSignalStrengthMin;  
       
  1204     wlan1->iVisibility = ETrue;
       
  1205     wlan1->iCoverage = 3;
       
  1206     if ( Math::Random() % 2 == 0 )
       
  1207         {
       
  1208         iScanArray->AppendL( wlan1 );
       
  1209         }
       
  1210     else
       
  1211         {
       
  1212         delete wlan1;
       
  1213         }
       
  1214 
       
  1215     CleanupStack::Pop( wlan1 );
       
  1216 
       
  1217     TWsfWlanInfo* wlan2 = new (ELeave) TWsfWlanInfo();
       
  1218     CleanupStack::PushL( wlan2 );    
       
  1219     wlan2->iConnectionState = ENotConnected;
       
  1220     wlan2->iIapId = 0;
       
  1221     wlan2->iNetMode = EInfra;
       
  1222     wlan2->iSecurityMode = EWlanSecModeWpa2;
       
  1223     wlan2->iSsid = _L8("Known WPA2 PSK");
       
  1224     wlan2->iStrengthLevel = EWlanSignalStrengthLow-7;  
       
  1225     wlan2->iVisibility = ETrue;
       
  1226     wlan2->iCoverage = 1;
       
  1227     wlan2->SetUsesPreSharedKey( ETrue );
       
  1228     if ( Math::Random() % 2 == 0 )
       
  1229         {
       
  1230         iScanArray->AppendL( wlan2 );
       
  1231         }
       
  1232     else
       
  1233         {
       
  1234         delete wlan2;
       
  1235         }
       
  1236     CleanupStack::Pop( wlan2 );
       
  1237 
       
  1238     TWsfWlanInfo* wlan3 = new (ELeave) TWsfWlanInfo();
       
  1239     CleanupStack::PushL( wlan3 );    
       
  1240     wlan3->iConnectionState = ENotConnected;
       
  1241     wlan3->iIapId = 0;
       
  1242     wlan3->iNetMode = EInfra;
       
  1243     wlan3->iSecurityMode = EWlanSecModeOpen;
       
  1244     wlan3->iSsid = _L8("Unknown open");
       
  1245     wlan3->iStrengthLevel = EWlanSignalStrengthMax;  
       
  1246     wlan3->iVisibility = 1;
       
  1247     wlan3->iCoverage = 1;    
       
  1248     if ( Math::Random() % 2 == 0 )
       
  1249         {
       
  1250         iScanArray->AppendL( wlan3 );
       
  1251         }
       
  1252     else
       
  1253         {
       
  1254         delete wlan3;
       
  1255         }
       
  1256     CleanupStack::Pop( wlan3 );
       
  1257     
       
  1258     TWsfWlanInfo* wlan4 = new (ELeave) TWsfWlanInfo();
       
  1259     CleanupStack::PushL( wlan4 );    
       
  1260     wlan4->iConnectionState = ENotConnected;
       
  1261     wlan4->iIapId = 0;
       
  1262     wlan4->iNetMode = EAdhoc;
       
  1263     wlan4->iSecurityMode = EWlanSecModeWpa;
       
  1264     wlan4->iSsid = _L8("Unknown WPA");
       
  1265     wlan4->iStrengthLevel = EWlanSignalStrengthMin;  
       
  1266     wlan4->iVisibility = 1;
       
  1267     wlan4->iCoverage = 1;
       
  1268     wlan2->SetUsesPreSharedKey( ETrue );
       
  1269 
       
  1270     if ( Math::Random() % 2 == 0 )
       
  1271         {
       
  1272         iScanArray->AppendL( wlan4 );    
       
  1273         }
       
  1274     else
       
  1275         {
       
  1276         delete wlan4;
       
  1277         }
       
  1278     CleanupStack::Pop( wlan4 );
       
  1279 
       
  1280     TWsfWlanInfo* wlan5 = new (ELeave) TWsfWlanInfo();
       
  1281     CleanupStack::PushL( wlan5 );    
       
  1282     wlan5->iConnectionState = ENotConnected;
       
  1283     wlan5->iIapId = 12;
       
  1284     wlan5->iNetMode = EInfra;
       
  1285     wlan5->iSecurityMode = EWlanSecModeOpen;
       
  1286     wlan5->iSsid = _L8("SES");
       
  1287     wlan5->iStrengthLevel = EWlanSignalStrengthLow-5;  
       
  1288     wlan5->iVisibility = 0;
       
  1289     wlan5->iCoverage = 1;    
       
  1290     if ( Math::Random() % 2 == 0 )
       
  1291         {
       
  1292         iScanArray->AppendL( wlan5 );
       
  1293         }
       
  1294     else
       
  1295         {
       
  1296         delete wlan5;
       
  1297         }
       
  1298     
       
  1299     CleanupStack::Pop( wlan5 );
       
  1300     
       
  1301     TWsfWlanInfo* wlan6 = new (ELeave) TWsfWlanInfo();
       
  1302     CleanupStack::PushL( wlan6 );    
       
  1303     wlan6->iConnectionState = ENotConnected;
       
  1304     wlan6->iIapId = 666;
       
  1305     wlan6->iNetMode = EInfra;
       
  1306     wlan6->iSecurityMode = EWlanSecModeWpa;
       
  1307     wlan6->iSsid = _L8("Sunny 22");
       
  1308     wlan6->iStrengthLevel = EWlanSignalStrengthMin;  
       
  1309     wlan6->iVisibility = 1;
       
  1310     wlan6->iCoverage = 2;    
       
  1311     if ( Math::Random() % 2 == 0 )
       
  1312         {
       
  1313         iScanArray->AppendL( wlan6 );
       
  1314         }
       
  1315     else
       
  1316         {
       
  1317         delete wlan6;
       
  1318         }
       
  1319     CleanupStack::Pop( wlan6 );
       
  1320 
       
  1321 
       
  1322     wlan5 = new (ELeave) TWsfWlanInfo();
       
  1323     CleanupStack::PushL( wlan5 );    
       
  1324     wlan5->iConnectionState = ENotConnected;
       
  1325     wlan5->iIapId = 0;
       
  1326     wlan5->iNetMode = EInfra;
       
  1327     wlan5->iSecurityMode = EWlanSecModeOpen;
       
  1328     wlan5->iSsid = _L8("FON_accesspoint");
       
  1329     wlan5->iStrengthLevel = EWlanSignalStrengthLow-8;  
       
  1330     wlan5->iVisibility = 1;
       
  1331     wlan5->iCoverage = 1;    
       
  1332     if ( Math::Random() % 2 == 0 )
       
  1333         {
       
  1334         iScanArray->AppendL( wlan5 );
       
  1335         }
       
  1336     else
       
  1337         {
       
  1338         delete wlan5;
       
  1339         }
       
  1340     CleanupStack::Pop( wlan5 );
       
  1341     
       
  1342     
       
  1343     TWsfWlanInfo* wlan7 = new (ELeave) TWsfWlanInfo();
       
  1344     CleanupStack::PushL( wlan7 );    
       
  1345     wlan7->iConnectionState = ENotConnected;
       
  1346     wlan7->iIapId = 667;
       
  1347     wlan7->iNetMode = EAdhoc;
       
  1348     wlan7->iSecurityMode = EWlanSecModeWpa;
       
  1349     wlan7->iSsid = _L8("Ad-hoc WPA");
       
  1350     wlan7->iStrengthLevel = EWlanSignalStrengthMax;  
       
  1351     wlan7->iVisibility = ETrue;
       
  1352     wlan7->iCoverage = 1;    
       
  1353     if ( Math::Random() % 2 == 0 )
       
  1354         {
       
  1355         iScanArray->AppendL( wlan7 );
       
  1356         }
       
  1357     else
       
  1358         {
       
  1359         delete wlan7;
       
  1360         }
       
  1361     CleanupStack::Pop( wlan7 );
       
  1362     
       
  1363     TWsfWlanInfo* wlan8 = new (ELeave) TWsfWlanInfo();
       
  1364     CleanupStack::PushL( wlan8 );    
       
  1365     wlan8->iConnectionState = ENotConnected;
       
  1366     wlan8->iIapId = 667;
       
  1367     wlan8->iNetMode = EInfra;
       
  1368     wlan8->iSecurityMode = EWlanSecModeOpen;
       
  1369     wlan8->iSsid = _L8("Known pri 1");
       
  1370     wlan8->iStrengthLevel = EWlanSignalStrengthMax;  
       
  1371     wlan8->iVisibility = ETrue;
       
  1372     wlan8->iCoverage = 1;   
       
  1373     wlan8->iPriority = 1;
       
  1374     if ( Math::Random() % 2 == 0 )
       
  1375         {
       
  1376         iScanArray->AppendL( wlan8 );
       
  1377         }
       
  1378     else
       
  1379         {
       
  1380         delete wlan8;
       
  1381         }
       
  1382     CleanupStack::Pop( wlan8 );
       
  1383     
       
  1384     TWsfWlanInfo* wlan9 = new (ELeave) TWsfWlanInfo();
       
  1385     CleanupStack::PushL( wlan9 );    
       
  1386     wlan9->iConnectionState = ENotConnected;
       
  1387     wlan9->iIapId = 668;
       
  1388     wlan9->iNetMode = EInfra;
       
  1389     wlan9->iSecurityMode = EWlanSecModeOpen;
       
  1390     wlan9->iSsid = _L8("Known pri 2");
       
  1391     wlan9->iStrengthLevel = EWlanSignalStrengthMax;  
       
  1392     wlan9->iVisibility = ETrue;
       
  1393     wlan9->iCoverage = 1;  
       
  1394     wlan9->iPriority = 2;
       
  1395     if ( Math::Random() % 2 == 0 )
       
  1396         {
       
  1397         iScanArray->AppendL( wlan9 );
       
  1398         }
       
  1399     else
       
  1400         {
       
  1401         delete wlan9;
       
  1402         }
       
  1403     CleanupStack::Pop( wlan9 );
       
  1404     
       
  1405 
       
  1406     }
       
  1407 
       
  1408 #endif // __WINS__
       
  1409 
       
  1410 // ---------------------------------------------------------------------------
       
  1411 // CWsfWlanScanner::GetWlanInfoFromIapL()
       
  1412 // ---------------------------------------------------------------------------
       
  1413 //
       
  1414 void CWsfWlanScanner::GetWlanInfoFromIapL( TWsfWlanInfo& aWlanInfo )
       
  1415     {
       
  1416     LOG_ENTERFN( "CWsfWlanScanner::GetWlanInfoFromIapL" );
       
  1417     LOG_WRITEF( "Iap Id = %d", aWlanInfo.iIapId );
       
  1418 
       
  1419     CCommsDatabase* commsDb = CCommsDatabase::NewL();    
       
  1420     CleanupStack::PushL( commsDb );
       
  1421     
       
  1422     CCommsDbTableView* commsDbIapTableView = commsDb->OpenViewMatchingUintLC(
       
  1423         TPtrC( IAP ), TPtrC( COMMDB_ID ), aWlanInfo.iIapId );
       
  1424     User::LeaveIfError( commsDbIapTableView->GotoFirstRecord() );
       
  1425     
       
  1426     // network name
       
  1427     TBuf<KCommsDbSvrMaxFieldLength> iapName;
       
  1428     commsDbIapTableView->ReadTextL( TPtrC( COMMDB_NAME ), iapName);
       
  1429 
       
  1430     TInt error = CnvUtfConverter::ConvertFromUnicodeToUtf8( 
       
  1431                                                         aWlanInfo.iNetworkName, 
       
  1432                                                         iapName  );
       
  1433     if ( error )
       
  1434         {
       
  1435         LOG_WRITE( "ConvertFromUnicodeToUtf8 failed");
       
  1436         aWlanInfo.iNetworkName.Copy( iapName );
       
  1437         }
       
  1438     
       
  1439 	// service Id
       
  1440     TUint32 serviceId(0);
       
  1441     commsDbIapTableView->ReadUintL(TPtrC( IAP_SERVICE), serviceId);
       
  1442     CCommsDbTableView* wlanTableView = commsDb->OpenViewMatchingUintLC(
       
  1443              TPtrC( WLAN_SERVICE), TPtrC( WLAN_SERVICE_ID), serviceId);
       
  1444     User::LeaveIfError(wlanTableView->GotoFirstRecord() );
       
  1445 
       
  1446     // ssid
       
  1447     wlanTableView->ReadTextL( TPtrC( NU_WLAN_SSID ), aWlanInfo.iSsid );
       
  1448     aWlanInfo.iRawSsid.Copy( aWlanInfo.iSsid );
       
  1449     
       
  1450     // security mode
       
  1451     TUint32 secMode(0);
       
  1452     wlanTableView->ReadUintL(TPtrC( WLAN_SECURITY_MODE), secMode);
       
  1453     // Map Wpa2 to Wpa
       
  1454     secMode = ( secMode == EWlanSecModeWpa2 )? EWlanSecModeWpa : secMode;
       
  1455     aWlanInfo.iSecurityMode = static_cast<TWlanSecMode>(secMode);
       
  1456     
       
  1457     TUint32 usePsk(0);
       
  1458     TRAP_IGNORE( wlanTableView->ReadUintL(TPtrC( WLAN_ENABLE_WPA_PSK ), 
       
  1459                  usePsk ) );
       
  1460     
       
  1461     aWlanInfo.SetUsesPreSharedKey( usePsk );
       
  1462 
       
  1463     // net mode
       
  1464     TUint32 netMode(0);
       
  1465     wlanTableView->ReadUintL(TPtrC( WLAN_CONNECTION_MODE), netMode);
       
  1466     aWlanInfo.iNetMode = static_cast<TWlanNetMode>(netMode);
       
  1467     
       
  1468     CleanupStack::PopAndDestroy(wlanTableView);
       
  1469     CleanupStack::PopAndDestroy(commsDbIapTableView);
       
  1470     CleanupStack::PopAndDestroy(commsDb); 
       
  1471     }
       
  1472 
       
  1473 
       
  1474 // ---------------------------------------------------------------------------
       
  1475 // CWsfWlanScanner::SsidIdentity
       
  1476 // ---------------------------------------------------------------------------
       
  1477 //
       
  1478 TBool CWsfWlanScanner::SsidIdentity( const TWlanSsid& aSsid1, 
       
  1479                                      const TWlanSsid& aSsid2 )
       
  1480     {
       
  1481     return !aSsid1.Compare( aSsid2 );
       
  1482     }
       
  1483 
       
  1484 
       
  1485 // ---------------------------------------------------------------------------
       
  1486 // CWsfWlanScanner::RefreshNetworkNameL
       
  1487 // ---------------------------------------------------------------------------
       
  1488 //
       
  1489 TBool CWsfWlanScanner::RefreshNetworkNameL( TWsfWlanInfo& aWlanInfo )
       
  1490     {
       
  1491     LOG_ENTERFN( "CWsfWlanScanner::RefreshNetworkNameL" );
       
  1492 
       
  1493     TBool isHidden( EFalse );
       
  1494 
       
  1495     TUint8 ieLen( 0 );
       
  1496     const TUint8* ieData;
       
  1497     TBuf8<KWlanMaxSsidLength> ssid8;
       
  1498 
       
  1499     TInt ret = iScanInfo->InformationElement( E802Dot11SsidIE, ieLen,
       
  1500                                               &ieData );
       
  1501 
       
  1502     if ( ret == KErrNone )
       
  1503         {
       
  1504         isHidden = IsHiddenSsid( ieLen, ieData );
       
  1505 
       
  1506         if ( ieLen )
       
  1507             {
       
  1508             ssid8.Copy( ieData, ieLen );
       
  1509             aWlanInfo.iSsid.Copy( ssid8 );
       
  1510             aWlanInfo.iRawSsid.Copy( ssid8 );
       
  1511             TBuf<KWlanMaxSsidLength> ssid16;
       
  1512             ssid16.Copy( ssid8 );
       
  1513             LOG_WRITEF( "SSID: [%S]", &ssid16 );
       
  1514             }
       
  1515         else
       
  1516             {
       
  1517             LOG_WRITE( "SSID: <hidden>" );
       
  1518             }
       
  1519         }
       
  1520     else
       
  1521         {
       
  1522         User::Leave( ret );
       
  1523         }
       
  1524 
       
  1525     return isHidden;
       
  1526     }
       
  1527 
       
  1528 
       
  1529 // ---------------------------------------------------------------------------
       
  1530 // CWsfWlanScanner::IsHiddenSsid
       
  1531 // ---------------------------------------------------------------------------
       
  1532 //
       
  1533 TBool CWsfWlanScanner::IsHiddenSsid( TUint aSsidLength, const TUint8* aSsid )
       
  1534     {
       
  1535     LOG_ENTERFN( "CWsfWlanScanner::IsHiddenSsid" );
       
  1536 
       
  1537 
       
  1538     if ( !aSsidLength )
       
  1539         {
       
  1540         LOG_WRITEF( "result: %d", ETrue );
       
  1541         return ETrue;
       
  1542         }
       
  1543 
       
  1544     TInt count( 0 );
       
  1545     for ( TUint i( 0 ); i < aSsidLength; ++i )
       
  1546         {
       
  1547         count |= aSsid[i]; // in hidden networks characters are: 0x00
       
  1548         }
       
  1549 
       
  1550     LOG_WRITEF( "result: %d", !count );
       
  1551 
       
  1552     return !count;
       
  1553     }
       
  1554     
       
  1555     
       
  1556 // ---------------------------------------------------------------------------
       
  1557 // CWsfWlanScanner::RefreshSignalStrength
       
  1558 // ---------------------------------------------------------------------------
       
  1559 //
       
  1560 void CWsfWlanScanner::RefreshSignalStrength( TWsfWlanInfo& aWlanInfo  )
       
  1561     {
       
  1562     LOG_ENTERFN( "CWsfWlanScanner::RefreshSignalStrength" );
       
  1563 
       
  1564     TInt rxLevel = iScanInfo->RXLevel();
       
  1565     
       
  1566     LOG_WRITEF( "rxLevel = %d", rxLevel );
       
  1567     
       
  1568     // yes, it is < and not >, because smaller value means stronger signal
       
  1569 
       
  1570     if ( rxLevel < aWlanInfo.iStrengthLevel )
       
  1571         {
       
  1572         LOG_WRITEF( "updating %d to %d", aWlanInfo.iStrengthLevel, rxLevel );
       
  1573         aWlanInfo.iStrengthLevel = rxLevel;
       
  1574         }
       
  1575     }
       
  1576 
       
  1577 
       
  1578 // ---------------------------------------------------------------------------
       
  1579 // CWsfWlanScanner::RefreshNetworkMode
       
  1580 // ---------------------------------------------------------------------------
       
  1581 //
       
  1582 void CWsfWlanScanner::RefreshNetworkMode( TWsfWlanInfo& aWlanInfo )
       
  1583     {
       
  1584     LOG_ENTERFN( "CWsfWlanScanner::RefreshNetworkMode" );
       
  1585 
       
  1586     aWlanInfo.iNetMode = ( iScanInfo->Capability() & 
       
  1587                                E802Dot11CapabilityEssMask ) ?
       
  1588                                    EInfra : EAdhoc ;
       
  1589 
       
  1590     LOG_WRITEF( "netmode = %d", TInt( aWlanInfo.iNetMode ) );
       
  1591     }
       
  1592 
       
  1593 
       
  1594 // ---------------------------------------------------------------------------
       
  1595 // CWsfWlanScanner::RefreshSecurityMode
       
  1596 // ---------------------------------------------------------------------------
       
  1597 //
       
  1598 void CWsfWlanScanner::RefreshSecurityMode( TWsfWlanInfo& aWlanInfo )
       
  1599     {
       
  1600     LOG_ENTERFN( "CWsfWlanScanner::RefreshSecurityMode" );
       
  1601     
       
  1602   	TWlanConnectionExtentedSecurityMode extSecMode = iScanInfo->ExtendedSecurityMode(); 
       
  1603         
       
  1604     switch ( extSecMode )
       
  1605         {
       
  1606         case EWlanConnectionExtentedSecurityModeWepOpen:
       
  1607         case EWlanConnectionExtentedSecurityModeWepShared:
       
  1608             {
       
  1609             aWlanInfo.iSecurityMode = EWlanSecModeWep;
       
  1610             break;
       
  1611             }
       
  1612 
       
  1613         case EWlanConnectionExtentedSecurityMode802d1x:
       
  1614             {
       
  1615             aWlanInfo.iSecurityMode = EWlanSecMode802_1x;
       
  1616             break;
       
  1617             }
       
  1618 
       
  1619         case EWlanConnectionExtentedSecurityModeWpa:
       
  1620         case EWlanConnectionExtentedSecurityModeWpa2:
       
  1621             {
       
  1622             aWlanInfo.iSecurityMode = EWlanSecModeWpa;
       
  1623             break;
       
  1624             }
       
  1625 
       
  1626         case EWlanConnectionExtentedSecurityModeWpaPsk:
       
  1627         case EWlanConnectionExtentedSecurityModeWpa2Psk:
       
  1628             {
       
  1629             aWlanInfo.iSecurityMode = EWlanSecModeWpa;
       
  1630             break;
       
  1631             }
       
  1632             
       
  1633         case EWlanConnectionExtentedSecurityModeWapi:
       
  1634         case EWlanConnectionExtentedSecurityModeWapiPsk:
       
  1635             {
       
  1636             aWlanInfo.iSecurityMode = EWlanSecModeWAPI;
       
  1637             break;
       
  1638             }
       
  1639 
       
  1640         case EWlanConnectionExtentedSecurityModeOpen:
       
  1641         default:
       
  1642             {
       
  1643             aWlanInfo.iSecurityMode = EWlanSecModeOpen;
       
  1644             }
       
  1645         }
       
  1646 
       
  1647     aWlanInfo.SetUsesPreSharedKey( 
       
  1648             extSecMode == EWlanConnectionExtentedSecurityModeWpa2Psk || 
       
  1649             extSecMode == EWlanConnectionExtentedSecurityModeWpaPsk );
       
  1650 
       
  1651     LOG_WRITEF( "security mode %d (PSK: %d)", 
       
  1652                 (TInt)aWlanInfo.iSecurityMode,
       
  1653                 (TInt)aWlanInfo.UsesPreSharedKey() );
       
  1654     }
       
  1655 
       
  1656 
       
  1657 // -----------------------------------------------------------------------------
       
  1658 // CWsfWlanScanner::ConvertTxRateToTxRateEnum
       
  1659 // -----------------------------------------------------------------------------
       
  1660 //
       
  1661 core_tx_rate_e CWsfWlanScanner::ConvertTxRateToTxRateEnum( TUint8 aRate )
       
  1662     {
       
  1663     LOG_ENTERFN( "CWsfWlanScanner::ConvertTxRateToTxRateEnum" );
       
  1664 
       
  1665     switch ( aRate )
       
  1666         {
       
  1667         case core_tx_rate_value_1mbit:
       
  1668             return core_tx_rate_1mbit;
       
  1669         case core_tx_rate_value_2mbit:
       
  1670             return core_tx_rate_2mbit;
       
  1671         case core_tx_rate_value_5p5mbit:
       
  1672             return core_tx_rate_5p5mbit;
       
  1673         case core_tx_rate_value_6mbit:
       
  1674             return core_tx_rate_6mbit;
       
  1675         case core_tx_rate_value_9mbit:
       
  1676             return core_tx_rate_9mbit;
       
  1677         case core_tx_rate_value_11mbit:
       
  1678             return core_tx_rate_11mbit;
       
  1679         case core_tx_rate_value_12mbit:
       
  1680             return core_tx_rate_12mbit;
       
  1681         case core_tx_rate_value_18mbit:
       
  1682             return core_tx_rate_18mbit;
       
  1683         case core_tx_rate_value_22mbit:
       
  1684             return core_tx_rate_22mbit;
       
  1685         case core_tx_rate_value_24mbit:
       
  1686             return core_tx_rate_24mbit;
       
  1687         case core_tx_rate_value_33mbit:
       
  1688             return core_tx_rate_33mbit;
       
  1689         case core_tx_rate_value_36mbit:
       
  1690             return core_tx_rate_36mbit;
       
  1691         case core_tx_rate_value_48mbit:
       
  1692             return core_tx_rate_48mbit;
       
  1693         case core_tx_rate_value_54mbit:
       
  1694             return core_tx_rate_54mbit;
       
  1695         default:
       
  1696             return core_tx_rate_none;
       
  1697         }
       
  1698     }
       
  1699 
       
  1700 
       
  1701 // ---------------------------------------------------------------------------
       
  1702 // CWsfWlanScanner::RefreshTechnology
       
  1703 // ---------------------------------------------------------------------------
       
  1704 //
       
  1705 void CWsfWlanScanner::RefreshTechnology( TWsfWlanInfo& aWlanInfo )
       
  1706     {
       
  1707     LOG_ENTERFN( "CWsfWlanScanner::RefreshTechnology" );
       
  1708 
       
  1709     TUint8 ieLen(0);
       
  1710     const TUint8* ieData;
       
  1711     TUint8 dataRates[KMaxNumberOfRates];
       
  1712 
       
  1713     if ( iScanInfo->InformationElement( E802Dot11HtCapabilitiesIE, ieLen,
       
  1714             &ieData ) == 0 )
       
  1715         {
       
  1716         // 802.11n supported
       
  1717         aWlanInfo.iTransferRate = 0x8;
       
  1718         }
       
  1719     else
       
  1720         {
       
  1721         Mem::FillZ( &dataRates[0], sizeof( dataRates ) );
       
  1722         core_tx_rate_e rate( core_tx_rate_none );
       
  1723         TUint32 basic_rates( 0 );
       
  1724         TUint32 supported_rates( 0 );
       
  1725 
       
  1726         // Supported Rates
       
  1727         iScanInfo->InformationElement( E802Dot11SupportedRatesIE, ieLen,
       
  1728                 &ieData );
       
  1729 
       
  1730         Mem::Copy( dataRates, ieData, ieLen );
       
  1731 
       
  1732         TUint32 temp_basic_rates( 0 );
       
  1733         TUint32 temp_supported_rates( 0 );
       
  1734 
       
  1735         for ( TInt a = 0; a < ieLen; a++ )
       
  1736             {
       
  1737             rate = ConvertTxRateToTxRateEnum( dataRates[a]
       
  1738                     & ~TX_RATE_BASIC_MASK );
       
  1739 
       
  1740             temp_supported_rates |= rate;
       
  1741 
       
  1742             if ( dataRates[a] & TX_RATE_BASIC_MASK )
       
  1743                 {
       
  1744                 /**
       
  1745                  * The highest bit is enabled, the rate is both a basic rate
       
  1746                  * and a supported rate.
       
  1747                  */
       
  1748                 temp_basic_rates |= rate;
       
  1749                 }
       
  1750             }
       
  1751 
       
  1752         basic_rates |= temp_basic_rates;
       
  1753         supported_rates |= temp_supported_rates;
       
  1754 
       
  1755         // Extended Supported Rates
       
  1756         Mem::FillZ( &dataRates[0], sizeof( dataRates ) );
       
  1757 
       
  1758         iScanInfo->InformationElement( E802Dot11ExtendedRatesIE, ieLen,
       
  1759                 &ieData );
       
  1760 
       
  1761         Mem::Copy( dataRates, ieData, ieLen );
       
  1762 
       
  1763         if ( ieData )
       
  1764             {
       
  1765             temp_basic_rates = 0;
       
  1766             temp_supported_rates = 0;
       
  1767 
       
  1768             for ( TInt a = 0; a < ieLen; a++ )
       
  1769                 {
       
  1770                 rate = ConvertTxRateToTxRateEnum( dataRates[a]
       
  1771                         & ~TX_RATE_BASIC_MASK );
       
  1772 
       
  1773                 temp_supported_rates |= rate;
       
  1774 
       
  1775                 if ( dataRates[a] & TX_RATE_BASIC_MASK )
       
  1776                     {
       
  1777                     /**
       
  1778                      * The highest bit is enabled, the rate is both a basic rate
       
  1779                      * and a supported rate.
       
  1780                      */
       
  1781                     temp_basic_rates |= rate;
       
  1782                     }
       
  1783                 }
       
  1784 
       
  1785             basic_rates |= temp_basic_rates;
       
  1786             supported_rates |= temp_supported_rates;
       
  1787             }
       
  1788 
       
  1789         aWlanInfo.iTransferRate = 0x4; // 802.11bg
       
  1790 
       
  1791         // AP is 802.11b only if only 802.11b rates 
       
  1792         // are advertised as supported rates.
       
  1793         if ( !( supported_rates & ~CORE_TX_RATES_802P11B ) )
       
  1794             {
       
  1795             aWlanInfo.iTransferRate = 0x1; // 802.11b
       
  1796             }
       
  1797         // AP is 802.11g only if any of the 802.11g rates is a basic rate.
       
  1798         else if ( basic_rates & CORE_TX_RATES_802P11G )
       
  1799             {
       
  1800             aWlanInfo.iTransferRate = 0x2; // 802.11g
       
  1801             }
       
  1802         }
       
  1803 
       
  1804     LOG_WRITEF( "technology = %d", aWlanInfo.iTransferRate );
       
  1805     }
       
  1806 
       
  1807 
       
  1808 // ---------------------------------------------------------------------------
       
  1809 // CWsfWlanScanner::ConnectionEstablishedL
       
  1810 // ---------------------------------------------------------------------------
       
  1811 //
       
  1812 void CWsfWlanScanner::ConnectionEstablishedL( const TDesC& aConnectionName )
       
  1813     {
       
  1814     LOG_ENTERFN( "CWsfWlanScanner::ConnectionEstablishedL" );
       
  1815     LOG_WRITEF( "aConnectionName: [%S]", &aConnectionName );
       
  1816     
       
  1817     HBufC* temp = aConnectionName.AllocL();
       
  1818     if ( iActiveConnectionName )
       
  1819         {
       
  1820         delete iActiveConnectionName;
       
  1821         iActiveConnectionName = NULL;
       
  1822         }
       
  1823     iActiveConnectionName = temp;
       
  1824     }
       
  1825 
       
  1826 
       
  1827 // ---------------------------------------------------------------------------
       
  1828 // CWsfWlanScanner::ConnectionLostL
       
  1829 // ---------------------------------------------------------------------------
       
  1830 //
       
  1831 void CWsfWlanScanner::ConnectionLostL()
       
  1832     {
       
  1833     LOG_ENTERFN( "CWsfWlanScanner::ConnectionLostL" );
       
  1834     if ( iActiveConnectionName )
       
  1835         {
       
  1836         delete iActiveConnectionName;
       
  1837         iActiveConnectionName = NULL;
       
  1838         }
       
  1839     }
       
  1840 
       
  1841 
       
  1842 // ---------------------------------------------------------------------------
       
  1843 // CWsfWlanScanner::ConnectingFailedL
       
  1844 // ---------------------------------------------------------------------------
       
  1845 //
       
  1846 void CWsfWlanScanner::ConnectingFailedL( TInt /*aError*/ )
       
  1847     {
       
  1848     // no implementation required
       
  1849     }
       
  1850 
       
  1851 
       
  1852 // ---------------------------------------------------------------------------
       
  1853 // CWsfWlanScanner::ConnectedIapReleasedL
       
  1854 // ---------------------------------------------------------------------------
       
  1855 //
       
  1856 void CWsfWlanScanner::ConnectedIapReleasedL()
       
  1857     {
       
  1858     // no implementation required
       
  1859     }
       
  1860     
       
  1861 
       
  1862 // ---------------------------------------------------------------------------
       
  1863 // CWsfWlanScanner::ScanResults
       
  1864 // ---------------------------------------------------------------------------
       
  1865 //
       
  1866 HBufC8* CWsfWlanScanner::ScanResults()
       
  1867     {
       
  1868     return iScanResults;
       
  1869     }
       
  1870 
       
  1871 
       
  1872 // ---------------------------------------------------------------------------
       
  1873 // CWsfWlanScanner::SetConnectionDetailProvider
       
  1874 // ---------------------------------------------------------------------------
       
  1875 //
       
  1876 void CWsfWlanScanner::SetConnectionDetailProvider( 
       
  1877                                 MWsfWlanConnectionDetailsProvider& aProvider )
       
  1878     {
       
  1879     iConnectionDetailsProvider = &aProvider;
       
  1880     }
       
  1881 
       
  1882 
       
  1883 // ---------------------------------------------------------------------------
       
  1884 // CWsfWlanScanner::WlanScanIntervalChangedL
       
  1885 // ---------------------------------------------------------------------------
       
  1886 //
       
  1887 void CWsfWlanScanner::WlanScanIntervalChangedL( TUint aNewScanInterval,
       
  1888                                                 TBool aShowAvailability )
       
  1889     {
       
  1890     LOG_ENTERFN( "CWsfWlanScanner::WlanScanIntervalChangedL" );
       
  1891     LOG_WRITEF( "bgScanInterval = %d sec", aNewScanInterval );
       
  1892     LOG_WRITEF( "showAvailability = %d", aShowAvailability );
       
  1893     iScanningInterval = aNewScanInterval * KMicrosecPerSecond;
       
  1894     
       
  1895     if ( iShowAvailability != aShowAvailability )
       
  1896         {
       
  1897         // background WLAN scanning status changed
       
  1898         iShowAvailability = aShowAvailability;        
       
  1899 
       
  1900         if ( iShowAvailability )
       
  1901             {
       
  1902             // bgscan is now enabled
       
  1903             // no reissuing, we rely on the WLAN engine callbacks 
       
  1904             // from now on
       
  1905             LOG_WRITE( "background scan enabled" );
       
  1906 
       
  1907             if ( iScanState == EIdle && IsActive() )
       
  1908                 {
       
  1909                 // reset the timer only if we are not in the middle 
       
  1910                 // of another scanning
       
  1911                 iTimer.Cancel();
       
  1912                 }
       
  1913             }
       
  1914         else
       
  1915             {
       
  1916             // bgscan is now disabled
       
  1917             // reset the timer with the new interval
       
  1918             LOG_WRITE( "background scan disabled" );
       
  1919 
       
  1920             if ( iScanState == EIdle )
       
  1921                 {
       
  1922                 LOG_WRITE( "reissuing timer request" );
       
  1923                 // reset the timer only if we are not in the middle 
       
  1924                 // of another scanning 
       
  1925                 // otherwise RunL will take care of the timer
       
  1926                 // doCancel resets timer
       
  1927                 if ( IsActive() )
       
  1928                     {
       
  1929                     Cancel();
       
  1930                     }
       
  1931                 iTimer.After( iStatus, TTimeIntervalMicroSeconds32( 
       
  1932                         iScanningInterval ) );
       
  1933                 iCacheLifetime = 0;
       
  1934                 iMaxDelay = 0;
       
  1935                 SetActive();
       
  1936                 } 
       
  1937             }
       
  1938         }
       
  1939     else if ( !iShowAvailability )
       
  1940         {
       
  1941         // only the scan interval has changed
       
  1942         LOG_WRITE( "scan interval changed" );
       
  1943         if ( iScanState == EIdle && IsActive() )
       
  1944             {
       
  1945             // reset the timer only if we are not in the middle of 
       
  1946             // another scanning 
       
  1947             // doCancel resets timer
       
  1948             LOG_WRITE( "reissuing timer request" );
       
  1949             Cancel();
       
  1950             iTimer.After( iStatus, TTimeIntervalMicroSeconds32( 
       
  1951                     iScanningInterval ) );
       
  1952             iCacheLifetime = 0;
       
  1953             iMaxDelay = 0;
       
  1954             SetActive();
       
  1955             }        
       
  1956         }
       
  1957     }
       
  1958 
       
  1959 // End of file
       
  1960