cmmanager/cmmgr/Plugins/cmpluginwlan/src/cmwlancoveragecheck.cpp
branchRCL_3
changeset 58 83ca720e2b9a
parent 0 5a93021fdf25
equal deleted inserted replaced
57:05bc53fe583b 58:83ca720e2b9a
       
     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 Coverage Check class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <wlanmgmtclient.h>
       
    20 
       
    21 #include "cmwlancoveragecheck.h"
       
    22 #include "cmpluginwlan.h"
       
    23 #include "cmpluginwlandata.h"
       
    24 #include "cmpluginwlandataarray.h"
       
    25 #include "cmlogger.h"
       
    26 
       
    27 
       
    28 /**
       
    29 * Management frame information element IDs.
       
    30 * needed to determine coverage
       
    31 */
       
    32 enum T802Dot11InformationElementID
       
    33     {
       
    34     E802Dot11SsidIE                 = 0,
       
    35     E802Dot11SupportedRatesIE       = 1,
       
    36     E802Dot11FhParameterSetIE       = 2,
       
    37     E802Dot11DsParameterSetIE       = 3,
       
    38     E802Dot11CfParameterSetIE       = 4,
       
    39     E802Dot11TimIE                  = 5,
       
    40     E802Dot11IbssParameterSetIE     = 6,
       
    41     E802Dot11CountryIE              = 7,
       
    42     E802Dot11HoppingPatternParamIE  = 8,
       
    43     E802Dot11HoppingPatternTableIE  = 9,
       
    44     E802Dot11RequestIE              = 10,
       
    45 
       
    46     E802Dot11ChallengeTextIE        = 16,
       
    47     // Reserved for challenge text extension 17 - 31
       
    48     E802Dot11ErpInformationIE       = 42,
       
    49     E802Dot11ExtendedRatesIE        = 50,
       
    50     E802Dot11AironetIE              = 133,
       
    51     E802Dot11ApIpAddressIE          = 149,
       
    52     E802Dot11RsnIE                  = 221
       
    53     };
       
    54 
       
    55 
       
    56 /**
       
    57 * Bit masks for Capability Information field.
       
    58 */
       
    59 enum T802Dot11CapabilityBitMask
       
    60     {
       
    61     E802Dot11CapabilityEssMask          = 0x0001,
       
    62     E802Dot11CapabilityIbssMask         = 0x0002,
       
    63     E802Dot11CapabilityCfPollableMask   = 0x0004,
       
    64     E802Dot11CapabilityCfPollRequestMask= 0x0008,
       
    65     E802Dot11CapabilityPrivacyMask      = 0x0010,
       
    66     E802Dot11ShortPreambleMask          = 0x0020,
       
    67     E802Dot11PbccMask                   = 0x0040,      
       
    68     E802Dot11ChannelAgilityMask         = 0x0080
       
    69     };
       
    70 
       
    71 
       
    72 // ======================= MEMBER FUNCTIONS =================================
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // CCmWlanCoverageCheck::CCmWlanCoverageCheck()
       
    76 // ----------------------------------------------------------------------------
       
    77 //
       
    78 CCmWlanCoverageCheck::CCmWlanCoverageCheck() : CActive( EPriorityStandard )
       
    79     {
       
    80     CActiveScheduler::Add( this );
       
    81     }
       
    82     
       
    83 // ----------------------------------------------------------------------------
       
    84 // CCmWlanCoverageCheck::~CCmWlanCoverageCheck()
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 CCmWlanCoverageCheck::~CCmWlanCoverageCheck()
       
    88     {
       
    89     Cancel();
       
    90     }
       
    91     
       
    92 // ----------------------------------------------------------------------------
       
    93 // CCmWlanCoverageCheck::DoCancel
       
    94 // ----------------------------------------------------------------------------
       
    95 //
       
    96 void CCmWlanCoverageCheck::DoCancel()
       
    97     {
       
    98     iWait.AsyncStop();
       
    99     }
       
   100     
       
   101 // ----------------------------------------------------------------------------
       
   102 // CCmWlanCoverageCheck::RunL
       
   103 // ----------------------------------------------------------------------------
       
   104 //
       
   105 void CCmWlanCoverageCheck::RunL()
       
   106     {
       
   107     CLOG_WRITE( "RunL entered" );
       
   108     switch( iProgState )
       
   109         {
       
   110         case EScanning:
       
   111             {
       
   112              if( !iStatus.Int() )
       
   113                 // The list is ready 
       
   114                 {
       
   115                 iProgState = EDone;
       
   116                 iWait.AsyncStop();
       
   117                 }
       
   118             else
       
   119                 // something went wrong -> no coverage.
       
   120                 {
       
   121                 iWait.AsyncStop();
       
   122                 }
       
   123             }
       
   124             break;            
       
   125         case EDone:
       
   126             {
       
   127             iWait.AsyncStop();
       
   128             }
       
   129             break;
       
   130             
       
   131         default:
       
   132             {
       
   133             User::Leave( KErrCorrupt );
       
   134             }
       
   135         }
       
   136     }
       
   137 
       
   138 
       
   139 
       
   140 // ----------------------------------------------------------------------------
       
   141 // CCmWlanCoverageCheck::GetCoverageL
       
   142 // ----------------------------------------------------------------------------
       
   143 //
       
   144 TInt CCmWlanCoverageCheck::GetCoverageL()
       
   145     {
       
   146     LOGGER_ENTERFN( "CCmWlanCoverageCheck::GetCoverageL" );
       
   147 
       
   148     iProgState = EServiceStatus;
       
   149     iCoverage = 0;
       
   150     
       
   151     CWlanMgmtClient* wlanMgmt = CWlanMgmtClient::NewL();
       
   152     CleanupStack::PushL( wlanMgmt );
       
   153 
       
   154     CWlanScanInfo* scanInfo = CWlanScanInfo::NewL();
       
   155     CleanupStack::PushL( scanInfo );
       
   156 
       
   157     iProgState = EScanning;
       
   158     
       
   159     wlanMgmt->GetScanResults( iStatus, *scanInfo );
       
   160     
       
   161     SetActive();
       
   162     iWait.Start();
       
   163     
       
   164     // now we have the results and might start to work on them...
       
   165     if ( iProgState == EDone )
       
   166         { //finished without error, work on the result...
       
   167         CCmPluginWlanDataArray* wlandataarray = new ( ELeave ) 
       
   168             CCmPluginWlanDataArray();
       
   169         CleanupStack::PushL( wlandataarray );
       
   170 
       
   171         for ( scanInfo->First(); !scanInfo->IsDone(); scanInfo->Next() )
       
   172             {
       
   173             // iWlanNetworks cannot be modified 'directly' in
       
   174             // a const method (like GetBoolAttributeL), so we have to
       
   175             // cast away the constness.
       
   176             
       
   177             // not simply count as before, but check if it is hidden,
       
   178             // and do not allow duplicates...
       
   179             TBool isHidden( EFalse );
       
   180             
       
   181             TUint8 ieLen( 0 );
       
   182             const TUint8* ieData;
       
   183             TBuf8<KWlanMaxSsidLength> ssid8;
       
   184             
       
   185             TInt ret = scanInfo->InformationElement( E802Dot11SsidIE, ieLen, 
       
   186                                                       &ieData );
       
   187             if ( ret == KErrNone ) 
       
   188                 {               
       
   189                 isHidden = IsHiddenSsid( ieLen, ieData );
       
   190                 if ( !isHidden )
       
   191                     {
       
   192                     // get the ssid
       
   193                     ssid8.Copy( ieData, ieLen );
       
   194                     HBufC* tmp = HBufC::NewLC(KWlanMaxSsidLength);
       
   195                     TPtr tmpptr( tmp->Des() );
       
   196                     
       
   197                     tmpptr.Copy(ssid8);
       
   198                     // get the signal strength                        
       
   199                     TUint8 rxLevel8 = scanInfo->RXLevel();
       
   200                     TInt rxLevel = static_cast< TInt >( rxLevel8 );
       
   201                     
       
   202                     // now add it to an array of CCmPluginWlanData,
       
   203                     // as it is not hidden
       
   204                     // the adding function should handle uniqeness and 
       
   205                     // signal strength checking, it should contain only
       
   206                     // the strongest signal!                        
       
   207                     AddToArrayIfNeededL( *wlandataarray, rxLevel, tmpptr );
       
   208                     
       
   209                     CleanupStack::PopAndDestroy( tmp );
       
   210                     }                
       
   211                 }
       
   212             else
       
   213                 {
       
   214                 User::Leave( ret );
       
   215                 }
       
   216             }
       
   217         iCoverage = wlandataarray->Count();
       
   218         
       
   219         CleanupStack::PopAndDestroy( wlandataarray );
       
   220 
       
   221         CleanupStack::PopAndDestroy( 2, wlanMgmt );
       
   222         }
       
   223     else
       
   224         {
       
   225         User::LeaveIfError( iStatus.Int() );        
       
   226         }        
       
   227         
       
   228     return iCoverage;
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------
       
   232 // CCmWlanCoverageCheck::IsHiddenSsid
       
   233 // ---------------------------------------------------------
       
   234 //    
       
   235 TBool CCmWlanCoverageCheck::IsHiddenSsid( TUint aSsidLength, 
       
   236                                    const TUint8* aSsid ) const
       
   237     {
       
   238     LOGGER_ENTERFN( "CCmWlanCoverageCheck::IsHiddenSsid" );
       
   239     
       
   240     const TUint8 CSPACE = 0x20; 
       
   241     TBool result( EFalse );
       
   242     TBool result2( ETrue );
       
   243 
       
   244     if ( !aSsidLength )
       
   245         {
       
   246         result = ETrue;
       
   247         }
       
   248 
       
   249     TInt count( 0 );
       
   250     TUint8 temp( 0x00 );
       
   251     
       
   252     for ( TUint i( 0 ); i < aSsidLength; ++i )
       
   253         {
       
   254         temp = aSsid[i];
       
   255         count += temp; // in hidden networks characters are: 0x00
       
   256         result2 &= temp == CSPACE ;
       
   257         }
       
   258 
       
   259     if( !count || result2 )
       
   260         {
       
   261         result = ETrue;
       
   262         }
       
   263         
       
   264     return result;    
       
   265     }
       
   266 
       
   267 
       
   268 // ---------------------------------------------------------
       
   269 // CCmWlanCoverageCheck::AddToArrayIfNeededL
       
   270 // ---------------------------------------------------------
       
   271 //    
       
   272 void CCmWlanCoverageCheck::AddToArrayIfNeededL( 
       
   273                             CCmPluginWlanDataArray& aArray, 
       
   274                             TInt aRXLevel, 
       
   275                             TDesC& aNetworkName ) const
       
   276     {
       
   277     LOGGER_ENTERFN( "CCmWlanCoverageCheck::AddToArrayIfNeededL" );
       
   278 
       
   279     // first check if it is already in the array
       
   280     
       
   281     TBool found( EFalse );
       
   282     TInt index( 0 );
       
   283     TInt count = aArray.Count();
       
   284     
       
   285     while( ( index <  count ) && !found  )
       
   286         {
       
   287         if( ( aArray )[index]->iNetworkName->Compare( aNetworkName ) )
       
   288             {
       
   289             ++index;   
       
   290             }
       
   291         else
       
   292             {
       
   293             found = ETrue;
       
   294             }
       
   295         }
       
   296 
       
   297     TSignalStrength strength = ( TSignalStrength )aRXLevel;
       
   298     if ( found )
       
   299         {
       
   300         // if already exists, check signal strengths
       
   301         TSignalStrength signal = ( aArray )[index]->iSignalStrength;
       
   302         
       
   303         // set to higher value
       
   304         ( aArray )[index]->iSignalStrength = 
       
   305                               signal < strength ? signal : strength ;
       
   306         }
       
   307     else
       
   308         {
       
   309         // new element, add it to array with signal strength!!
       
   310         CCmPluginWlanData* data = CCmPluginWlanData::NewLC();
       
   311         data->iNetworkName = aNetworkName.AllocL();
       
   312         data->iSignalStrength = strength;
       
   313         aArray.AppendL( data );
       
   314         CleanupStack::Pop( data ); // item owned by list!
       
   315         }    
       
   316     }
       
   317 
       
   318 
       
   319 // ----------------------------------------------------------------------------
       
   320 // CCmWlanCoverageCheck::ScanForPromptedSsidL
       
   321 // ----------------------------------------------------------------------------
       
   322 //
       
   323 TBool CCmWlanCoverageCheck::ScanForPromptedSsidL( TWlanSsid aEnteredSsid,
       
   324                                 TBool aBroadcast,
       
   325                                 TWlanNetMode& aNetworkMode, 
       
   326                                 TWlanConnectionExtentedSecurityMode& aSecurityMode,
       
   327                                 TBool& aProtectedSetupSupported )
       
   328     {
       
   329     LOGGER_ENTERFN( "CCmWlanCoverageCheck::ScanForPromptedSsidL" );
       
   330     
       
   331     TBool found = EFalse;
       
   332 
       
   333     iProgState = EServiceStatus;
       
   334        
       
   335     CWlanMgmtClient* wlanMgmt = CWlanMgmtClient::NewL();
       
   336     CleanupStack::PushL( wlanMgmt );
       
   337 
       
   338     CWlanScanInfo* scanInfo = CWlanScanInfo::NewL();
       
   339     CleanupStack::PushL( scanInfo );
       
   340 
       
   341     iProgState = EScanning;
       
   342     
       
   343     if ( aBroadcast )
       
   344         {
       
   345         wlanMgmt->GetScanResults( iStatus, *scanInfo );
       
   346         }
       
   347     else
       
   348         {
       
   349         wlanMgmt->GetScanResults( aEnteredSsid, iStatus, *scanInfo );
       
   350         }
       
   351 
       
   352     SetActive();
       
   353     iWait.Start();
       
   354     
       
   355     // now we have the results and might start to work on them...
       
   356     if ( iProgState == EDone )
       
   357         {       //finished without error, work on the result...
       
   358         TSignalStrength signalStrength = ESignalStrengthMin;
       
   359 
       
   360         for ( scanInfo->First(); !scanInfo->IsDone(); scanInfo->Next() )
       
   361             {
       
   362             TUint8 ieLen( 0 );
       
   363             const TUint8* ieData;
       
   364             TBuf8<KWlanMaxSsidLength> ssid8;
       
   365             
       
   366             TInt ret = scanInfo->InformationElement( E802Dot11SsidIE, ieLen, 
       
   367                                                      &ieData );
       
   368             if ( ret == KErrNone ) 
       
   369                 {               
       
   370                 // get the ssid
       
   371                 ssid8.Copy( ieData, ieLen );
       
   372                 
       
   373                 if ( !aEnteredSsid.Compare( ssid8 ) )
       
   374                     {
       
   375                     // get the signal strength                        
       
   376                     TUint8 rxLevel8 = scanInfo->RXLevel();
       
   377                     TInt rxLevel = static_cast< TInt >( rxLevel8 );
       
   378             
       
   379                     TSignalStrength strength = ( TSignalStrength )rxLevel;
       
   380                     if ( !found || ( found && strength < signalStrength ) )
       
   381                         {
       
   382                         found = ETrue;
       
   383                         signalStrength = strength;
       
   384 
       
   385                         aNetworkMode = ( scanInfo->Capability() & 
       
   386                                          E802Dot11CapabilityEssMask ) ?
       
   387                                        EInfra : EAdhoc;
       
   388                         aSecurityMode = scanInfo->ExtendedSecurityMode();
       
   389 
       
   390                         aProtectedSetupSupported = 
       
   391                                         scanInfo->IsProtectedSetupSupported();
       
   392                         }
       
   393                     }
       
   394                 }
       
   395             else
       
   396                 {
       
   397                 User::Leave( ret );
       
   398                 }
       
   399         
       
   400             }
       
   401         
       
   402         CleanupStack::PopAndDestroy( scanInfo );
       
   403         CleanupStack::PopAndDestroy( wlanMgmt );
       
   404         }
       
   405     else
       
   406         {
       
   407         User::LeaveIfError( iStatus.Int() );        
       
   408         }
       
   409     
       
   410     return found;
       
   411     }
       
   412 
       
   413