connectionutilities/ConnectionDialogs/ConnectionUiUtilities/NotifSrc/WlanNetworkDataProvider.cpp
changeset 0 5a93021fdf25
child 24 05bc53fe583b
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2005 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:  This class provides available wlan network array.
       
    15 *     
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "WlanNetworkDataProvider.h"
       
    22 #include "NetworkInfoArray.h"
       
    23 #include "NetworkInfoBase.h"
       
    24 #include "NetworkInfoKey.h"
       
    25 #include "ConnectionDialogsLogger.h"
       
    26 
       
    27 #include <featmgr.h>
       
    28 #include <centralrepository.h>
       
    29 #include <CoreApplicationUIsSDKCRKeys.h> // KCRUidCoreApplicationUIs
       
    30 
       
    31 
       
    32 // CONSTANTS 
       
    33 
       
    34 /**
       
    35 * Management frame information element IDs.
       
    36 */
       
    37 enum T802Dot11InformationElementID
       
    38     {
       
    39     E802Dot11SsidIE                 = 0,
       
    40     E802Dot11SupportedRatesIE       = 1,
       
    41     E802Doi11FhParameterSetIE       = 2,
       
    42     E802Dot11DsParameterSetIE       = 3,
       
    43     E802Dot11CfParameterSetIE       = 4,
       
    44     E802Dot11TimIE                  = 5,
       
    45     E802Dot11IbssParameterSetIE     = 6,
       
    46     E802Dot11CountryIE              = 7,
       
    47     E802Dot11HoppingPatternParamIE  = 8,
       
    48     E802Dot11HoppingPatternTableIE  = 9,
       
    49     E802Dot11RequestIE              = 10,
       
    50 
       
    51     E802Dot11ChallengeTextIE        = 16,
       
    52     // Reserved for challenge text extension 17 - 31
       
    53     E802Dot11ErpInformationIE       = 42,
       
    54     E802Dot11ExtendedRatesIE        = 50,
       
    55     E802Dot11AironetIE              = 133,
       
    56     E802Dot11ApIpAddressIE          = 149,
       
    57     E802Dot11RsnIE                  = 221
       
    58     };
       
    59 
       
    60 // ================= MEMBER FUNCTIONS =======================
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CWlanNetworkDataProvider::CWlanNetworkDataProvider
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 CWlanNetworkDataProvider::CWlanNetworkDataProvider() 
       
    67 : CBase()
       
    68     {
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CWlanNetworkDataProvider::~CWlanNetworkDataProvider
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 CWlanNetworkDataProvider::~CWlanNetworkDataProvider()
       
    77     {
       
    78     CLOG_ENTERFN( "CWlanNetworkDataProvider::~CWlanNetworkDataProvider" );
       
    79     delete iNetworkInfoArray;
       
    80 
       
    81 #ifndef __WINS__
       
    82     if  ( iWlanMgmt )
       
    83         {
       
    84         iWlanMgmt->CancelGetScanResults();
       
    85         }
       
    86     delete iWlanMgmt;
       
    87     delete iScanInfo;
       
    88 #endif
       
    89 
       
    90     CLOG_LEAVEFN( "CWlanNetworkDataProvider::~CWlanNetworkDataProvider" );
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // CWlanNetworkDataProvider::NewL
       
    96 // ---------------------------------------------------------
       
    97 //
       
    98 CWlanNetworkDataProvider* CWlanNetworkDataProvider::NewL()
       
    99     {
       
   100     CLOG_ENTERFN( "CWlanNetworkDataProvider::NewL" );  
       
   101 
       
   102     CWlanNetworkDataProvider* self = new ( ELeave ) CWlanNetworkDataProvider();
       
   103 
       
   104     CleanupStack::PushL( self );
       
   105     self->ConstructL();
       
   106     CleanupStack::Pop( self );
       
   107 
       
   108     CLOG_LEAVEFN( "CWlanNetworkDataProvider::NewL" );
       
   109 
       
   110     return self;
       
   111     }
       
   112 
       
   113 
       
   114 // ---------------------------------------------------------
       
   115 // CWlanNetworkDataProvider::CWlanNetworkDataProvider
       
   116 // ---------------------------------------------------------
       
   117 //
       
   118 void CWlanNetworkDataProvider::ConstructL()
       
   119     {
       
   120     CLOG_ENTERFN( "CWlanNetworkDataProvider::ConstructL" );
       
   121 
       
   122 #ifndef __WINS__
       
   123     iWlanMgmt = CWlanMgmtClient::NewL();
       
   124     iScanInfo = CWlanScanInfo::NewL();
       
   125 #endif // !__WINS__
       
   126 
       
   127     iNetworkInfoArray = CNetworkInfoArray::NewL();
       
   128 
       
   129     CLOG_LEAVEFN( "CWlanNetworkDataProvider::ConstructL" );
       
   130     }
       
   131 
       
   132 
       
   133 // ---------------------------------------------------------
       
   134 // CWlanNetworkDataProvider::OnTimerExpiredL
       
   135 // ---------------------------------------------------------
       
   136 //
       
   137 void CWlanNetworkDataProvider::OnTimerExpiredL()
       
   138     {
       
   139     CLOG_ENTERFN( "CWlanNetworkDataProvider::OnTimerExpiredL" );
       
   140 
       
   141     TBool hideOtherEntry( EFalse );
       
   142 
       
   143     iNetworkInfoArray->Reset();
       
   144 
       
   145 #ifdef __WINS__
       
   146 
       
   147     TBuf8<KWlanMaxSsidLength> ssid8_a( _L8( "Test SSID" ) );
       
   148     TBuf8<KWlanMaxSsidLength> ssid8_c( _L8( "Another SSID" ) );
       
   149     TInt rxLevel_a = ESignalStrengthMax;
       
   150     TInt rxLevel_b = ESignalStrengthMin;
       
   151     TInt rxLevel_c = ESignalStrengthMax;
       
   152 
       
   153     AddNetworkL( ssid8_a, ( TSignalStrength )rxLevel_a, 
       
   154                  ENetworkModeInfrastructure, EWlanConnectionSecurityWep,
       
   155                  EWlanConnectionExtentedSecurityModeWepOpen,
       
   156                  ETrue );
       
   157     AddNetworkL( ssid8_a, ( TSignalStrength )rxLevel_b, 
       
   158                  ENetworkModeInfrastructure, EWlanConnectionSecurityWep,
       
   159                  EWlanConnectionExtentedSecurityModeWepOpen,
       
   160                  ETrue );
       
   161     AddNetworkL( ssid8_c, ( TSignalStrength )rxLevel_c, 
       
   162                  ENetworkModeInfrastructure, EWlanConnectionSecurityWpa,
       
   163                  EWlanConnectionExtentedSecurityModeWpa,
       
   164                  ETrue );
       
   165 
       
   166 #else
       
   167 
       
   168     TUint8 ieLen( 0 );
       
   169     const TUint8* ieData;
       
   170     TBuf8<KWlanMaxSsidLength> ssid8;
       
   171     TUint8 rxLevel8( 0 );
       
   172     TInt rxLevel( 0 );
       
   173 
       
   174     for( iScanInfo->First(); !iScanInfo->IsDone(); iScanInfo->Next() )
       
   175         {
       
   176         User::LeaveIfError( iScanInfo->InformationElement( E802Dot11SsidIE, 
       
   177                                                            ieLen, &ieData ) );
       
   178         if( !IsHiddenSsid( ieLen, ieData ) )
       
   179             {
       
   180             rxLevel8 = iScanInfo->RXLevel();
       
   181             rxLevel = static_cast< TInt >( rxLevel8 );
       
   182 
       
   183             ssid8.Copy( ieData, ieLen );
       
   184             AddNetworkL( ssid8, 
       
   185                          ( TSignalStrength )rxLevel, 
       
   186                          ( iScanInfo->Capability() & 
       
   187                            E802Dot11CapabilityEssMask ) ?
       
   188                             ENetworkModeInfrastructure : ENetworkModeAdHoc,
       
   189                          iScanInfo->SecurityMode(),
       
   190                          iScanInfo->ExtendedSecurityMode(),
       
   191                          iScanInfo->IsProtectedSetupSupported()
       
   192                           );
       
   193             }
       
   194         }
       
   195 
       
   196     hideOtherEntry = IsPhoneOfflineL();
       
   197 
       
   198 #endif
       
   199 
       
   200     SortNetworkInfoArrayL();
       
   201 
       
   202     if ( !hideOtherEntry )
       
   203         {
       
   204         AddOthersEntryL();
       
   205         }
       
   206 
       
   207     CLOG_LEAVEFN( "CWlanNetworkDataProvider::OnTimerExpiredL" );      
       
   208     }
       
   209 
       
   210 
       
   211 // ---------------------------------------------------------
       
   212 // CWlanNetworkDataProvider::SortNetworkInfoArray
       
   213 // ---------------------------------------------------------
       
   214 //    
       
   215 void CWlanNetworkDataProvider::SortNetworkInfoArrayL()
       
   216     {
       
   217     CLOG_ENTERFN( "CWlanNetworkDataProvider::SortNetworkInfoArrayL" );      
       
   218 
       
   219     CNetworkInfoKey* networkInfoKey = new( ELeave ) CNetworkInfoKey();
       
   220     networkInfoKey->SetPtr( iNetworkInfoArray );
       
   221     CleanupStack::PushL( networkInfoKey );
       
   222 
       
   223     // Sort returns KErrGeneral if stack overflow, otherwise, returns
       
   224     // KErrNone. So we will Leave only if stack overflow,
       
   225     // but than that really does not matter...
       
   226     User::LeaveIfError( iNetworkInfoArray->Sort( *networkInfoKey ) );
       
   227 
       
   228     CleanupStack::PopAndDestroy( networkInfoKey );
       
   229 
       
   230     CLOG_LEAVEFN( "CWlanNetworkDataProvider::SortNetworkInfoArrayL" );
       
   231     }
       
   232 
       
   233 
       
   234 #ifndef __WINS__
       
   235 // ---------------------------------------------------------
       
   236 // CWlanNetworkDataProvider::IsHiddenSsid
       
   237 // ---------------------------------------------------------
       
   238 //    
       
   239 TBool CWlanNetworkDataProvider::IsHiddenSsid( TUint aSsidLength, 
       
   240                                               const TUint8* aSsid )
       
   241     {
       
   242     CLOG_ENTERFN( "CWlanNetworkDataProvider::IsHiddenSsid" );
       
   243     
       
   244     if ( !aSsidLength )
       
   245         {
       
   246         return ETrue;
       
   247         }
       
   248 
       
   249     const TUint8 CSPACE = 0x20; 
       
   250     TBool result( ETrue );
       
   251 
       
   252     TInt count( 0 );
       
   253     TUint8 temp( 0x00 );
       
   254     for ( TUint i( 0 ); i < aSsidLength; ++i )
       
   255         {
       
   256         temp = aSsid[i];
       
   257         count += temp; // in hidden networks characters are: 0x00
       
   258         result &= temp == CSPACE;
       
   259 
       
   260         CLOG_WRITEF( _L( "temp %x" ), temp );
       
   261         }
       
   262 
       
   263     return ( !count || result );
       
   264     }
       
   265 
       
   266 #endif // !__WINS__
       
   267 
       
   268 
       
   269 // ---------------------------------------------------------
       
   270 // CWlanNetworkDataProvider::AddNetworkL
       
   271 // ---------------------------------------------------------
       
   272 //
       
   273 void CWlanNetworkDataProvider::AddNetworkL( TDes8& aNetworkName, 
       
   274                                    TSignalStrength aStrength, 
       
   275                                    TNetworkMode aNetworkMode,
       
   276                                    TWlanConnectionSecurityMode aSecurityMode,
       
   277                                    TWlanConnectionExtentedSecurityMode aExtSecurityMode,
       
   278                                    TBool aProtectedSetupSupported )
       
   279     {
       
   280     TBuf<KWlanMaxSsidLength> networkName16;
       
   281     networkName16.Copy( aNetworkName );
       
   282     TInt index = iNetworkInfoArray->GetArrayIndex( networkName16 );
       
   283 
       
   284     // if not found
       
   285     if ( index == KErrNotFound )
       
   286         {
       
   287         CNetworkInfoBase* networkInfoBase = new( ELeave )CNetworkInfoBase();
       
   288 
       
   289         networkInfoBase->SetNetworkName( aNetworkName );
       
   290         networkInfoBase->SetSignalStrength( aStrength );
       
   291 
       
   292         networkInfoBase->SetNetworkMode( aNetworkMode );
       
   293         networkInfoBase->SetSecurityMode( aSecurityMode );
       
   294         networkInfoBase->SetExtendedSecurityMode( aExtSecurityMode );
       
   295 
       
   296         networkInfoBase->SetOthersEntry( EFalse );
       
   297         CLOG_WRITEF( _L( "Protected Setup in CWlanNetworkDataProvider::AddNetworkL: %d" ), aProtectedSetupSupported );
       
   298         networkInfoBase->SetProtectedSetupSupported( 
       
   299                                                     aProtectedSetupSupported );
       
   300 
       
   301         CleanupStack::PushL( networkInfoBase );
       
   302         networkInfoBase->RefreshNetworksListBoxItemTextL();
       
   303 
       
   304         iNetworkInfoArray->AppendL( networkInfoBase );
       
   305         CleanupStack::Pop( networkInfoBase );
       
   306         }
       
   307     else    // if found show highest strength
       
   308         {
       
   309         TSignalStrength signal = ( *iNetworkInfoArray )[index]->
       
   310                                                             SignalStrength();
       
   311         if ( signal )
       
   312             {
       
   313             ( *iNetworkInfoArray )[index]->SetSignalStrength( 
       
   314                                                         signal < aStrength ?
       
   315                                                         signal : aStrength );
       
   316             }
       
   317         }
       
   318     }
       
   319 
       
   320 
       
   321 // ---------------------------------------------------------
       
   322 // CWlanNetworkDataProvider::AddOthersEntryL
       
   323 // ---------------------------------------------------------
       
   324 //    
       
   325 void CWlanNetworkDataProvider::AddOthersEntryL()
       
   326     {
       
   327     CNetworkInfoBase* networkInfoBase = new( ELeave )CNetworkInfoBase();
       
   328     networkInfoBase->SetOthersEntry( ETrue );
       
   329 
       
   330     CleanupStack::PushL( networkInfoBase );
       
   331     networkInfoBase->RefreshNetworksListBoxItemTextL();
       
   332 
       
   333     iNetworkInfoArray->AppendL( networkInfoBase );
       
   334     CleanupStack::Pop( networkInfoBase );
       
   335     }
       
   336 
       
   337 
       
   338 // ---------------------------------------------------------
       
   339 // CWlanNetworkDataProvider::IsPhoneOfflineL
       
   340 // 
       
   341 // Checks if phone is in offline mode or not.
       
   342 // Return ETrue if phone is in offline mode.
       
   343 // Return EFalse if phone is not in offline mode.
       
   344 // ---------------------------------------------------------
       
   345 //
       
   346 TBool CWlanNetworkDataProvider::IsPhoneOfflineL() const
       
   347     {
       
   348     if ( FeatureManager::FeatureSupported( KFeatureIdOfflineMode ) )
       
   349         {
       
   350         CRepository* repository = CRepository::NewLC( 
       
   351                                                     KCRUidCoreApplicationUIs );
       
   352         TInt connAllowed = 1;
       
   353         repository->Get( KCoreAppUIsNetworkConnectionAllowed, connAllowed );
       
   354         CleanupStack::PopAndDestroy();  // repository
       
   355         if ( !connAllowed )
       
   356             {
       
   357             return ETrue;
       
   358             }
       
   359         }
       
   360     return EFalse;
       
   361     }
       
   362 
       
   363 
       
   364 // End of File