wlanutilities/wlansniffer/engine/server/src/wsfict.cpp
branchRCL_3
changeset 44 a9524956f6b5
equal deleted inserted replaced
35:aaabc7526ded 44:a9524956f6b5
       
     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 CWsfIct
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  EXTERNAL INCLUDES
       
    20 #include <apgcli.h>
       
    21 #include <apgtask.h>
       
    22 #include <ictsclientinterface.h>
       
    23 #include <cmmanagerext.h>
       
    24 #include <cmdestinationext.h>
       
    25 #include <cmpluginwlandef.h>
       
    26 
       
    27 //  CLASS HEADER
       
    28 #include "wsfict.h"
       
    29 #include "wsflogger.h"
       
    30 
       
    31 //  INTERNAL INCLUDES
       
    32 
       
    33 using namespace CMManager;
       
    34 
       
    35 /**
       
    36 * UID of Wlan Login application (hsbrowser)
       
    37 * used when launching WLAN Login application
       
    38 */
       
    39 static const TInt KBrowserUid = { 0x2000AFCC };
       
    40 
       
    41 /**
       
    42 * Length of a needed separators
       
    43 * used when launching WLAN Login application
       
    44 */
       
    45 const TInt KSeparatorsLength = 4;
       
    46 
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // CWsfIct::NewL
       
    50 // ----------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C CWsfIct* CWsfIct::NewL()
       
    53     {
       
    54     CWsfIct* self = CWsfIct::NewLC();
       
    55     CleanupStack::Pop( self );
       
    56     return self;
       
    57     }
       
    58 
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // CWsfIct::NewLC
       
    62 // ----------------------------------------------------------------------------
       
    63 //
       
    64 EXPORT_C CWsfIct* CWsfIct::NewLC()
       
    65     {
       
    66     CWsfIct* self = new( ELeave ) CWsfIct;
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // CWsfIct::~CWsfIct
       
    75 // ----------------------------------------------------------------------------
       
    76 //
       
    77 EXPORT_C CWsfIct::~CWsfIct()
       
    78     {
       
    79     LOG_ENTERFN( "CWsfIct::~CWsfIct" );
       
    80     if ( iIct )
       
    81         {
       
    82         LOG_WRITE( "ict cancel" );
       
    83         TRAP_IGNORE( iIct->CancelStartL() );
       
    84         delete iIct;
       
    85         iIct = NULL;
       
    86         }
       
    87     }
       
    88 
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // CWsfIct::CWsfIct
       
    92 // ----------------------------------------------------------------------------
       
    93 //
       
    94 CWsfIct::CWsfIct(): iConnectOnly( EFalse )
       
    95     {
       
    96     }
       
    97 
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // CWsfIct::ConstructL
       
   101 // ----------------------------------------------------------------------------
       
   102 //
       
   103 void CWsfIct::ConstructL()
       
   104     {
       
   105     }
       
   106 
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // CWsfIct::ConnectivityObserver
       
   110 // ----------------------------------------------------------------------------
       
   111 //
       
   112 void CWsfIct::ConnectivityObserver( TIctsTestResult aResult, 
       
   113                                     const TDesC& aString )
       
   114     {
       
   115     LOG_ENTERFN( "CWsfIct::ConnectivityObserver" );
       
   116     LOG_WRITEF( "ICTS result: %d", aResult );
       
   117     
       
   118     // check the result
       
   119     switch ( aResult )
       
   120         {
       
   121         case EConnectionOk:
       
   122             {
       
   123             // test succeeded
       
   124             TRAP_IGNORE( MoveToInternetSnapL( iIapId ) );
       
   125             LOG_WRITE( "ICT: EConnectionOk" );
       
   126             break;            
       
   127             }
       
   128             
       
   129         case EConnectionNotOk:
       
   130             {
       
   131             // test was run but it failed
       
   132             LOG_WRITE( "ICT: EConnectionNotOk" );
       
   133             break;
       
   134             }
       
   135         case EHttpAuthenticationNeeded:
       
   136             {
       
   137             // test was run but HTTP authentication is required
       
   138             LOG_WRITE( "ICT: EHttpAuthenticationNeeded" );
       
   139             if ( iConnectOnly )
       
   140                 {
       
   141                 // Connect selected. WLAN Login needed.
       
   142                 TRAP_IGNORE( LaunchWlanLoginL(aString) );
       
   143                 }    
       
   144             break;
       
   145             }    
       
   146         case ETimeout:
       
   147             {
       
   148             LOG_WRITE( "ICT: ETimeout" );
       
   149             break;
       
   150             }
       
   151             
       
   152         default:
       
   153             {
       
   154             _LIT( KIctPanic, "ICT result" );
       
   155             User::Panic( KIctPanic, aResult );
       
   156             }
       
   157         }
       
   158     }
       
   159 
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CWsfIct::LaunchWlanLoginL()
       
   163 // -----------------------------------------------------------------------------
       
   164 //    
       
   165 void CWsfIct::LaunchWlanLoginL( const TDesC& aString )
       
   166     {   
       
   167     LOG_ENTERFN( "CWsfIct::LaunchWlanLoginL" );
       
   168       
       
   169     // Count IAP Id length
       
   170     TInt iapIdLength ( 1 );
       
   171     TInt iapId = iIapId;
       
   172     while ( iapId >= 10 )
       
   173         {
       
   174         iapId = iapId/10;
       
   175         iapIdLength++;
       
   176         }
       
   177   
       
   178     // Count Network Id length
       
   179     TInt netIdLength ( 1 );
       
   180     TInt netId = iNetId;
       
   181     while ( netId >= 10 )
       
   182         {
       
   183         netId = netId/10;
       
   184         netIdLength++;
       
   185         }
       
   186     
       
   187     TInt length = aString.Length() + 
       
   188                   iapIdLength + 
       
   189                   netIdLength + 
       
   190                   KSeparatorsLength;
       
   191     HBufC* param = HBufC::NewLC( length );
       
   192     _LIT(tmpString, "%d, %d, %S");
       
   193     param->Des().Format( tmpString, 
       
   194                          iIapId, 
       
   195                          iNetId, 
       
   196                          &aString );
       
   197     TUid uid( TUid::Uid( KBrowserUid ) );
       
   198     TThreadId id;
       
   199     
       
   200     RApaLsSession appArcSession;
       
   201     User::LeaveIfError( appArcSession.Connect() ); 
       
   202     CleanupClosePushL( appArcSession );
       
   203         
       
   204     TInt err = appArcSession.StartDocument( *param, TUid::Uid( KBrowserUid ), id );
       
   205     if ( err != KErrNone )
       
   206         {
       
   207         LOG_ENTERFN( "CWsfIct::LaunchWlanLoginL failed" );
       
   208         }
       
   209     CleanupStack::PopAndDestroy( &appArcSession );
       
   210     CleanupStack::PopAndDestroy( param );
       
   211     }
       
   212 
       
   213 
       
   214 // ----------------------------------------------------------------------------
       
   215 // CWsfIct::MoveToInternetSnapL
       
   216 // ----------------------------------------------------------------------------
       
   217 //
       
   218 void CWsfIct::MoveToInternetSnapL( const TUint32 aIapId )
       
   219     {
       
   220 	LOG_ENTERFN( "CWsfIct::MoveToInternetSnapL" );
       
   221     RCmManagerExt cmManager;
       
   222     cmManager.OpenL();
       
   223     CleanupClosePushL( cmManager );
       
   224     
       
   225     // Check that is IAP uncategorized
       
   226     RArray<TUint32> cmIds;
       
   227     CleanupClosePushL( cmIds );
       
   228     cmManager.ConnectionMethodL( cmIds, ETrue, ETrue, EFalse );
       
   229     TBool foundFromUncategorized = EFalse;
       
   230     
       
   231     for ( TInt k = 0; k < cmIds.Count(); k++ )
       
   232         {
       
   233         RCmConnectionMethodExt cm;
       
   234         TRAPD( error, cm = cmManager.ConnectionMethodL( cmIds[k] ) );
       
   235         if ( KErrNone == error )
       
   236             {
       
   237             CleanupClosePushL( cm );
       
   238 
       
   239             TUint iapId = cm.GetIntAttributeL( CMManager::ECmIapId );
       
   240             if ( iapId == aIapId )
       
   241                 {
       
   242                 LOG_WRITE( "IAP is uncategorized" );
       
   243                 foundFromUncategorized = ETrue;
       
   244                 }
       
   245             CleanupStack::PopAndDestroy( &cm );
       
   246             }
       
   247         }
       
   248     
       
   249     CleanupStack::PopAndDestroy( &cmIds );
       
   250     
       
   251     if ( !foundFromUncategorized )
       
   252         {
       
   253         LOG_WRITE( "Not moving IAP since it is in SNAP" );
       
   254         CleanupStack::PopAndDestroy( &cmManager );
       
   255         return;
       
   256         }
       
   257     
       
   258     // Read all destination(SNAP) settings into an array
       
   259     RArray<TUint32> destinations;
       
   260     CleanupClosePushL( destinations );
       
   261     
       
   262     cmManager.AllDestinationsL( destinations );
       
   263     RCmDestinationExt destination;
       
   264     // Loop through each destination
       
   265     for( TInt i = 0; i < destinations.Count(); i++ )
       
   266         {
       
   267         destination = cmManager.DestinationL( destinations[i] );
       
   268         CleanupClosePushL( destination ); 
       
   269         // Internet destination will always exist in the system.
       
   270         // Internet destination will have ESnapPurposeInternet 
       
   271         // set in its metadata.
       
   272         if ( destination.MetadataL( CMManager::ESnapMetadataPurpose ) == 
       
   273                                     CMManager::ESnapPurposeInternet )
       
   274             {
       
   275             RCmConnectionMethodExt iap = cmManager.ConnectionMethodL( aIapId );
       
   276             CleanupClosePushL( iap );     
       
   277             LOG_WRITE( "Move Iap to internet destination" );
       
   278             destination.AddConnectionMethodL( iap );
       
   279             destination.UpdateL();
       
   280             CleanupStack::PopAndDestroy( &iap ); 
       
   281             }
       
   282         CleanupStack::PopAndDestroy( &destination ); 
       
   283         }
       
   284     CleanupStack::PopAndDestroy( &destinations ); 
       
   285     CleanupStack::PopAndDestroy( &cmManager ); 
       
   286     }
       
   287 
       
   288 
       
   289 // ----------------------------------------------------------------------------
       
   290 // CWsfIct::TestConnectedAccessPointL
       
   291 // ----------------------------------------------------------------------------
       
   292 //
       
   293 void CWsfIct::TestConnectedAccessPointL( TUint aIapId )
       
   294     {
       
   295     LOG_ENTERFN( "CWsfIct::TestConnectedAccessPointL" );
       
   296     if ( !aIapId || aIapId != iIapId )
       
   297         {
       
   298         // the wlaninfo must already contain a valid IAP id
       
   299         LOG_WRITE( "invalid IAP id" );
       
   300         return;
       
   301         }
       
   302 
       
   303     if ( iIct )
       
   304         {
       
   305         iIct->CancelStartL();
       
   306         delete iIct;
       
   307         iIct = NULL;
       
   308         }
       
   309 
       
   310     LOG_WRITE( "starting ICT test..." );
       
   311 
       
   312     iIct = CIctsClientInterface::NewL( iIapId, iNetId, *this );
       
   313     LOG_WRITE( "ICT created" );
       
   314     iIct->StartL();
       
   315     LOG_WRITE( "ICT: started" );
       
   316     }
       
   317 
       
   318 
       
   319 // ----------------------------------------------------------------------------
       
   320 // CWsfIct::InitializeIctL
       
   321 // ----------------------------------------------------------------------------
       
   322 //
       
   323 void CWsfIct::InitializeIctL( TBool aTestAccessPoint,
       
   324                               TUint aIapId,
       
   325                               TBool aConnectOnly )
       
   326     {
       
   327     LOG_ENTERFN( "CWsfIct::InitializeIct" );
       
   328 
       
   329     LOG_WRITEF( "IAP id = %d aTestAccessPoint = %d aConnectOnly = %d", 
       
   330                 aIapId, aTestAccessPoint, aConnectOnly );
       
   331     
       
   332     if ( !aIapId || !aTestAccessPoint )
       
   333         {
       
   334         // the wlaninfo must already contain a valid IAP id 
       
   335         // and check that IAP needs testing
       
   336         LOG_WRITE( "ICT not initialized" );
       
   337         iConnectOnly = EFalse;
       
   338         iIapId = 0;
       
   339         iNetId = 0;
       
   340         return;
       
   341         }
       
   342     
       
   343     // set variables
       
   344     iConnectOnly = aConnectOnly;
       
   345     iIapId = aIapId;
       
   346 
       
   347     if ( iIct )
       
   348         {
       
   349         iIct->CancelStartL();
       
   350         delete iIct;
       
   351         iIct = NULL;
       
   352         }
       
   353 
       
   354     // get network Id
       
   355     RCmManagerExt cmManager;
       
   356     cmManager.OpenL();
       
   357     CleanupClosePushL(cmManager);
       
   358 
       
   359     RCmConnectionMethodExt cm = cmManager.ConnectionMethodL(iIapId);
       
   360     CleanupClosePushL(cm);
       
   361 
       
   362     iNetId = cm.GetIntAttributeL(CMManager::ECmNetworkId);
       
   363     
       
   364     LOG_WRITEF( "Network Id=%d ", iNetId );
       
   365 
       
   366     CleanupStack::PopAndDestroy(&cm);
       
   367     CleanupStack::PopAndDestroy(&cmManager);
       
   368     }
       
   369     
       
   370 // End of file
       
   371