wlanutilities/wlansniffer/apwizard/src/wsfwlanssiddiscovery.cpp
branchRCL_3
changeset 25 f28ada11abbf
parent 0 56b72877c1cb
equal deleted inserted replaced
24:63be7eb3fc78 25:f28ada11abbf
       
     1 /*
       
     2 * Copyright (c) 2006 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 WLAN SSID discovery class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  EXTERNAL INCLUDES
       
    21 #include <wlanmgmtclient.h>
       
    22 #include <wlanmgmtcommon.h>
       
    23 
       
    24 //  CLASS HEADER
       
    25 #include "wsfwlanssiddiscovery.h"
       
    26 
       
    27 //  INTERNAL INCLUDES
       
    28 #include "wsflogger.h"
       
    29 
       
    30 
       
    31 using namespace CMManager;
       
    32 
       
    33 
       
    34 /**
       
    35 * Management frame information element IDs.
       
    36 * needed to determine SSID
       
    37 * (from \S60\osext\wlan\wlanldd\wlan_common\umac_common\inc\802dot11.h)
       
    38 */
       
    39 enum TWsf802Dot11InformationElementID
       
    40     {
       
    41     E802Dot11SsidIE                 = 0,
       
    42     E802Dot11SupportedRatesIE       = 1,
       
    43     E802Dot11FhParameterSetIE       = 2,
       
    44     E802Dot11DsParameterSetIE       = 3,
       
    45     E802Dot11CfParameterSetIE       = 4,
       
    46     E802Dot11TimIE                  = 5,
       
    47     E802Dot11IbssParameterSetIE     = 6,
       
    48     E802Dot11CountryIE              = 7,
       
    49     E802Dot11HoppingPatternParamIE  = 8,
       
    50     E802Dot11HoppingPatternTableIE  = 9,
       
    51     E802Dot11RequestIE              = 10,
       
    52 
       
    53     E802Dot11ChallengeTextIE        = 16,
       
    54     // Reserved for challenge text extension 17 - 31
       
    55     E802Dot11ErpInformationIE       = 42,
       
    56     E802Dot11ExtendedRatesIE        = 50,
       
    57     E802Dot11AironetIE              = 133,
       
    58     E802Dot11ApIpAddressIE          = 149,
       
    59     E802Dot11RsnIE                  = 221
       
    60     };
       
    61 
       
    62 
       
    63 /**
       
    64 * Bit masks for Capability Information field.
       
    65 * (from \S60\osext\wlan\wlanldd\wlan_common\umac_common\inc\802dot11.h)
       
    66 */
       
    67 enum TWsf802Dot11CapabilityBitMask
       
    68     {
       
    69     E802Dot11CapabilityEssMask          = 0x0001,
       
    70     E802Dot11CapabilityIbssMask         = 0x0002,
       
    71     E802Dot11CapabilityCfPollableMask   = 0x0004,
       
    72     E802Dot11CapabilityCfPollRequestMask= 0x0008,
       
    73     E802Dot11CapabilityPrivacyMask      = 0x0010,
       
    74     E802Dot11ShortPreambleMask          = 0x0020,
       
    75     E802Dot11PbccMask                   = 0x0040,      
       
    76     E802Dot11ChannelAgilityMask         = 0x0080
       
    77     };
       
    78 
       
    79 
       
    80 // ======================= MEMBER FUNCTIONS =================================
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // CWsfWlanSsidDiscovery::NewL
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 CWsfWlanSsidDiscovery* CWsfWlanSsidDiscovery::NewL()
       
    87     {
       
    88     CWsfWlanSsidDiscovery* self = new (ELeave) CWsfWlanSsidDiscovery();
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL();
       
    91     CleanupStack::Pop( self );
       
    92     return self;
       
    93     }
       
    94 
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // CWsfWlanSsidDiscovery::CWsfWlanSsidDiscovery
       
    98 // ----------------------------------------------------------------------------
       
    99 //
       
   100 CWsfWlanSsidDiscovery::CWsfWlanSsidDiscovery(): CActive( EPriorityStandard )
       
   101     {
       
   102     CActiveScheduler::Add( this );
       
   103     }
       
   104 
       
   105 
       
   106 // ----------------------------------------------------------------------------
       
   107 // CWsfWlanSsidDiscovery::ConstructL
       
   108 // ----------------------------------------------------------------------------
       
   109 //
       
   110 void CWsfWlanSsidDiscovery::ConstructL()
       
   111     {
       
   112     LOG_ENTERFN( "CWsfWlanSsidDiscovery::ConstructL" );
       
   113 #ifndef __WINS__
       
   114     iWlanMgmt = CWlanMgmtClient::NewL();
       
   115     iScanInfo = CWlanScanInfo::NewL();
       
   116 #endif    
       
   117     }
       
   118     
       
   119     
       
   120 // ----------------------------------------------------------------------------
       
   121 // CWsfWlanSsidDiscovery::~CWsfWlanSsidDiscovery()
       
   122 // ----------------------------------------------------------------------------
       
   123 //
       
   124 CWsfWlanSsidDiscovery::~CWsfWlanSsidDiscovery()
       
   125     {
       
   126     LOG_ENTERFN( "CWsfWlanSsidDiscovery::~CWsfWlanSsidDiscovery" );
       
   127     Cancel();
       
   128     delete iWlanMgmt;
       
   129     delete iScanInfo;    
       
   130     }
       
   131     
       
   132     
       
   133 // ----------------------------------------------------------------------------
       
   134 // CWsfWlanSsidDiscovery::DoCancel
       
   135 // ----------------------------------------------------------------------------
       
   136 //
       
   137 void CWsfWlanSsidDiscovery::DoCancel()
       
   138     {
       
   139     LOG_ENTERFN( "CWsfWlanSsidDiscovery::DoCancel" );
       
   140 #ifndef __WINS__    
       
   141     iWlanMgmt->CancelGetScanResults();
       
   142 #endif    
       
   143     }
       
   144     
       
   145     
       
   146 // ----------------------------------------------------------------------------
       
   147 // CWsfWlanSsidDiscovery::AbortScanning
       
   148 // ----------------------------------------------------------------------------
       
   149 //
       
   150 void CWsfWlanSsidDiscovery::AbortScanning()
       
   151     {
       
   152     LOG_ENTERFN( "CWsfWlanSsidDiscovery::AbortScanning" );
       
   153     if ( iWait.IsStarted() )
       
   154         {
       
   155         LOG_WRITE( "aborting..." );
       
   156         Cancel();
       
   157 
       
   158         iProgState = EAborted;
       
   159         iWait.AsyncStop();
       
   160         }    
       
   161     }
       
   162     
       
   163     
       
   164 // ----------------------------------------------------------------------------
       
   165 // CWsfWlanSsidDiscovery::RunL
       
   166 // ----------------------------------------------------------------------------
       
   167 //
       
   168 void CWsfWlanSsidDiscovery::RunL()
       
   169     {
       
   170     LOG_ENTERFN( "CWsfWlanSsidDiscovery::RunL" );
       
   171 
       
   172     if ( iProgState == EScanning )
       
   173         {
       
   174         if ( !iStatus.Int() )
       
   175             // The list is ready 
       
   176             {
       
   177             LOG_WRITE( "No error" );
       
   178             iProgState = EDone;
       
   179             }
       
   180         else
       
   181             // something went wrong -> no coverage.
       
   182             {
       
   183             LOG_WRITE( "error" );
       
   184             }
       
   185         }
       
   186         
       
   187     // stop blocking
       
   188     if ( iWait.IsStarted() )
       
   189         {
       
   190         iWait.AsyncStop();
       
   191         }
       
   192     
       
   193     }
       
   194 
       
   195 
       
   196 // ----------------------------------------------------------------------------
       
   197 // CWsfWlanSsidDiscovery::ScanForSsidL
       
   198 // ----------------------------------------------------------------------------
       
   199 //
       
   200 TBool CWsfWlanSsidDiscovery::ScanForSsidL( TWlanSsid& aEnteredSsid,
       
   201                                 TBool aBroadcast,
       
   202                                 CMManager::TWlanNetMode& aNetworkMode, 
       
   203                                 CMManager::TWlanSecMode& aSecurityMode,
       
   204                                 TBool& aUsesPsk )
       
   205     {
       
   206     LOG_ENTERFN( "CWsfWlanSsidDiscovery::ScanForSsidL" );
       
   207     
       
   208     if ( IsActive() )
       
   209         {
       
   210         return EFalse;
       
   211         }
       
   212     
       
   213     TBool found = EFalse;
       
   214 #ifndef __WINS__
       
   215     iProgState = EScanning;
       
   216 
       
   217     if ( aBroadcast )
       
   218         {
       
   219         LOG_WRITE( "performing broadcast scan" );
       
   220         iWlanMgmt->GetScanResults( iStatus, *iScanInfo );
       
   221         }
       
   222     else
       
   223         {
       
   224         LOG_WRITE( "performing direct scan" );        
       
   225         iWlanMgmt->GetScanResults( aEnteredSsid, iStatus, *iScanInfo );
       
   226         }
       
   227 
       
   228     SetActive();
       
   229     iWait.Start();
       
   230     
       
   231     // now we have the results and might start to work on them...
       
   232     if ( iProgState == EDone )
       
   233         {
       
   234         LOG_WRITE( "iProgState = EDone" );
       
   235         //finished without error, work on the result...
       
   236         for ( iScanInfo->First(); !found && !iScanInfo->IsDone(); 
       
   237                                                           iScanInfo->Next() )
       
   238             {
       
   239             TUint8 ieLen( 0 );
       
   240             const TUint8* ieData;
       
   241             
       
   242             TInt ret = iScanInfo->InformationElement( E802Dot11SsidIE, ieLen, 
       
   243                                                      &ieData );
       
   244             User::LeaveIfError( ret );
       
   245             
       
   246             // get the ssid
       
   247             TWlanSsid ssid;
       
   248             ssid.Copy( ieData, ieLen );
       
   249             
       
   250             if ( !aEnteredSsid.Compare( ssid ) )
       
   251                 {
       
   252                 // SSID matched
       
   253                 LOG_WRITE( "SSID matched, processing security settings" );
       
   254                 found = ETrue;
       
   255 
       
   256                 // adhoc or infrastructure
       
   257                 aNetworkMode = ( iScanInfo->Capability() & 
       
   258                                  E802Dot11CapabilityEssMask ) ?
       
   259                                         EInfra : EAdhoc;
       
   260                 
       
   261                 // security mode
       
   262                 TWlanConnectionSecurityMode connSec = 
       
   263                                                    iScanInfo->SecurityMode();
       
   264                 
       
   265                 // convert TWlanConnectionSecurityMode to 
       
   266                 // CMManager::TWlanSecMode
       
   267                 switch ( connSec )
       
   268                     {
       
   269                     case EWlanConnectionSecurityOpen:
       
   270                         {
       
   271                         aSecurityMode = EWlanSecModeOpen;
       
   272                         break;
       
   273                         }
       
   274                     case EWlanConnectionSecurityWep:
       
   275                         {
       
   276                         aSecurityMode = EWlanSecModeWep;
       
   277                         break;
       
   278                         }
       
   279                     case EWlanConnectionSecurity802d1x:
       
   280                         {
       
   281                         aSecurityMode = EWlanSecMode802_1x;
       
   282                         break;
       
   283                         }
       
   284                     case EWlanConnectionSecurityWpa:
       
   285                     case EWlanConnectionSecurityWpaPsk:
       
   286                         {
       
   287                         aSecurityMode = EWlanSecModeWpa;
       
   288                         break;
       
   289                         }
       
   290                     default:
       
   291                         {
       
   292                         }
       
   293                     }
       
   294 
       
   295                 aUsesPsk = ( connSec == EWlanConnectionSecurityWpaPsk );
       
   296 
       
   297                 } // if aEnteredSsid
       
   298         
       
   299             } // for
       
   300         
       
   301         }
       
   302     else if ( iProgState == EAborted )
       
   303         {
       
   304         LOG_WRITE( "iProgState = EAborted" );
       
   305         User::Leave( KErrCancel );
       
   306         }
       
   307     else
       
   308         {
       
   309         LOG_WRITEF( "iProgState = ???, iStatus = %d", iStatus.Int() );
       
   310         User::LeaveIfError( iStatus.Int() );
       
   311         }
       
   312         
       
   313 #else // __WINS__
       
   314 
       
   315     // we don't like warnings
       
   316     aEnteredSsid, aBroadcast, aNetworkMode, aSecurityMode, aUsesPsk;
       
   317     
       
   318 #endif // __WINS__
       
   319 
       
   320     return found;
       
   321     }
       
   322 
       
   323