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