bearermanagement/mpm/src/mpmwlanquerydialog.cpp
branchRCL_3
changeset 58 83ca720e2b9a
child 62 bb1f80fb7db2
equal deleted inserted replaced
57:05bc53fe583b 58:83ca720e2b9a
       
     1 /*
       
     2 * Copyright (c) 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: Handles displaying wlan dialogs
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <wlanmgmtcommon.h>
       
    20 #include <e32std.h>
       
    21 #include <utf.h>
       
    22 #include <cmpluginwlandef.h>
       
    23 #include <ctsydomainpskeys.h>
       
    24 
       
    25 #include "mpmwlanquerydialog.h"
       
    26 #include "mpmiapselection.h"
       
    27 #include "mpmconnmonevents.h"
       
    28 #include "mpmlogger.h"
       
    29 
       
    30 // valid Wep key lengths, to check wep key format
       
    31 // (wep key format depends on key length)
       
    32 const TInt KConnUiUtilsWepLengthASCII5 = 5;
       
    33 const TInt KConnUiUtilsWepLengthASCII13 = 13;
       
    34 const TInt KConnUiUtilsWepLengthASCII29 = 29;
       
    35 const TInt KConnUiUtilsWepLengthHEX10 = 10;
       
    36 const TInt KConnUiUtilsWepLengthHEX26 = 26;
       
    37 const TInt KConnUiUtilsWepLengthHEX58 = 58; 
       
    38 
       
    39 // Retry count and delay for storing Easy WLAN data
       
    40 const TInt KStoreRetryCount = 10;
       
    41 const TInt KStoreRetryDelay = 100000;
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CMPMWlanQueryDialog::CMPMWlanQueryDialog
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CMPMWlanQueryDialog::CMPMWlanQueryDialog( CMPMIapSelection&  aSession,
       
    50                                           TUint32            aWlanIapId )
       
    51   : CActive( CActive::EPriorityStandard ),
       
    52     iIapSelection( aSession ),
       
    53     iNetworkPrefs(),
       
    54     iNotifWep(),
       
    55     iWlanQueryState( EWlanNetwork ),
       
    56     iWlanIapId( aWlanIapId ),
       
    57     iEasyWlanSelected( EFalse ),
       
    58     iOverrideStatus( KErrNone ),
       
    59     iConnUiUtils( NULL ), 
       
    60     iWps( NULL ),
       
    61     iWpsReturn( WiFiProt::EWiFiOK ),
       
    62     iWpsCompleted( EFalse ),
       
    63     iRetryCount( 0 )
       
    64     {
       
    65     
       
    66     }
       
    67     
       
    68 // ---------------------------------------------------------------------------
       
    69 // CMPMWlanQueryDialog::ConstructL
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CMPMWlanQueryDialog::ConstructL()
       
    73     {
       
    74     User::LeaveIfError(iNotifier.Connect());
       
    75     CActiveScheduler::Add( this );
       
    76     iConnUiUtils = CConnectionUiUtilities::NewL();
       
    77     User::LeaveIfError( iTimer.CreateLocal() );
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CMPMWlanQueryDialog::NewL
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CMPMWlanQueryDialog* CMPMWlanQueryDialog::NewL( CMPMIapSelection&  aSession,
       
    85                                                 TUint32            aWlanIapElementId )
       
    86     {
       
    87     CMPMWlanQueryDialog* self = new( ELeave ) CMPMWlanQueryDialog( aSession,
       
    88                                                                    aWlanIapElementId );
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL();
       
    91     CleanupStack::Pop( self );
       
    92     return self;
       
    93     }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CMPMWlanQueryDialog::~CMPMWlanQueryDialog
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 CMPMWlanQueryDialog::~CMPMWlanQueryDialog()
       
   101     {
       
   102     MPMLOGSTRING( "CMPMWlanQueryDialog::~CMPMWlanQueryDialog enters" )
       
   103     // Check if this dialog instance was not started but only added to the queue
       
   104     if ( iIapSelection.Session()->MyServer().FirstInWlanQueryQueue() != this )
       
   105         {
       
   106         MPMLOGSTRING( "CMPMWlanQueryDialog::~CMPMWlanQueryDialog, not a active delete" )
       
   107 
       
   108         // Close notifier and timer
       
   109         iNotifier.Close();
       
   110         iTimer.Close();
       
   111         
       
   112         // We're not first in the queue, thus we can just delete.
       
   113         // But remember the pointer in the array.
       
   114         iIapSelection.Session()->MyServer().RemoveFromWlanQueryQueue( this );
       
   115         MPMLOGSTRING( "CMPMWlanQueryDialog::~CMPMWlanQueryDialog exits (break)" )
       
   116         return;
       
   117         }
       
   118 
       
   119     // Cancel previous dialogs if any.
       
   120     Cancel();
       
   121 
       
   122     // Close notifier and timer
       
   123     iNotifier.Close();
       
   124     iTimer.Close();
       
   125 
       
   126     delete iConnUiUtils;
       
   127 
       
   128     delete iWps;
       
   129     // Remove self from the queue
       
   130     iIapSelection.Session()->MyServer().RemoveFromWlanQueryQueue( this );
       
   131     
       
   132     // Start the next query
       
   133     CMPMWlanQueryDialog* dlg = iIapSelection.Session()->MyServer().FirstInWlanQueryQueue();
       
   134     if ( dlg )
       
   135         {
       
   136         MPMLOGSTRING( "CMPMWlanQueryDialog::~CMPMWlanQueryDialog starts new dialog" )
       
   137         dlg->OfferInformation( iWlanIapId, 
       
   138                                iStatus.Int() );
       
   139         // In destructor we cannot let the query leave
       
   140         TRAPD( err, dlg->StartWlanQueryL(); )
       
   141         if ( err != KErrNone )
       
   142             {
       
   143             MPMLOGSTRING2( "CMPMWlanQueryDialog::~CMPMWlanQueryDialog caught Leave %d, executing RunError()", err )
       
   144             dlg->RunError( err );
       
   145             }
       
   146         }
       
   147 
       
   148     MPMLOGSTRING( "CMPMWlanQueryDialog::~CMPMWlanQueryDialog exits" )
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CMPMWlanQueryDialog::DoCancel
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CMPMWlanQueryDialog::DoCancel()
       
   156     {
       
   157     MPMLOGSTRING2( "CMPMWlanQueryDialog::DoCancel state %d", iWlanQueryState )
       
   158     if ( iWlanQueryState == EOffline )
       
   159         {
       
   160         iNotifier.CancelNotifier( KUidCOfflineWlanNoteDlg );
       
   161         }
       
   162     else if ( iWlanQueryState == EWlanNetwork )    
       
   163         {
       
   164         iConnUiUtils->CancelSearchWLANNetwork();
       
   165         }
       
   166     else if ( iWlanQueryState == EWepSettings )    
       
   167         {
       
   168         iNotifier.CancelNotifier( KUidEasyWepDlg );
       
   169         }
       
   170     else if( iWlanQueryState == EWPS )
       
   171         {
       
   172         iWps->CancelWiFiProt();
       
   173         }
       
   174     else if ( iWlanQueryState == EWpaSettings )
       
   175         {
       
   176         iNotifier.CancelNotifier( KUidEasyWpaDlg );
       
   177         }
       
   178     else // ERetrySettingsStorage
       
   179         {
       
   180         iTimer.Cancel();
       
   181         }
       
   182     }
       
   183     
       
   184 // ---------------------------------------------------------------------------
       
   185 // CMPMWlanQueryDialog::RunL
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void CMPMWlanQueryDialog::RunL()
       
   189     {
       
   190     MPMLOGSTRING3( "CMPMWlanQueryDialog::RunL status %d state %d", 
       
   191                    iStatus.Int(), 
       
   192                    iWlanQueryState )
       
   193     if( iWlanQueryState == EOffline )
       
   194         {
       
   195         if( iStatus.Int() == KErrNone )
       
   196             {
       
   197             iIapSelection.Session()->MyServer().SetOfflineWlanQueryResponse(
       
   198                     EOfflineResponseYes );
       
   199             if( iIapSelection.Session()->MyServer().CommsDatAccess()->CheckEasyWLanL( iWlanIapId ) )
       
   200                 {
       
   201                 MPMLOGSTRING( "CMPMWlanQueryDialog::RunL starting wlan network query" )
       
   202                 GetNetworkPrefs();
       
   203                 return;
       
   204                 }
       
   205             }
       
   206         else if ( iStatus.Int() == KErrCancel )
       
   207             {
       
   208             iIapSelection.Session()->MyServer().SetOfflineWlanQueryResponse(
       
   209                     EOfflineResponseNo );
       
   210             MPMLOGSTRING2( "CMPMWlanQueryDialog::RunL offline query returned %d", 
       
   211                            iStatus.Int() )
       
   212             }
       
   213         else
       
   214             {
       
   215             MPMLOGSTRING2( "CMPMWlanQueryDialog::RunL offline query returned %d", 
       
   216                            iStatus.Int() )
       
   217             }
       
   218         }
       
   219     else if( iWlanQueryState == EWlanNetwork )
       
   220         {
       
   221         if( iStatus.Int() == KErrNone )
       
   222             {
       
   223             
       
   224             TUint secMode( 0 );
       
   225             TWlanNetMode connMode( EInfra );
       
   226             TInt err = ConnSecModeToCommsDatSecMode( iNetworkPrefs().iSecMode,
       
   227                                                      secMode );
       
   228             if( err != KErrNone )
       
   229        	    	{
       
   230        	    	MPMLOGSTRING( "CMPMWlanQueryDialog::RunL, Unknown security mode" )
       
   231        	    	iWlanIapId = 0;
       
   232                 iWlanQueryState = EWlanNetwork;
       
   233        	    	iIapSelection.UserWlanSelectionDoneL( KErrCouldNotConnect, iWlanIapId );
       
   234        	    	return;
       
   235        	    	}
       
   236             
       
   237             TUint32 configuredIap = iIapSelection.Session()->MyServer().
       
   238                 CommsDatAccess()->CheckWLANIapWithSsidL( iNetworkPrefs().iSsId, 
       
   239                                                          secMode,
       
   240                                                          connMode );
       
   241             // If previously unknown IAP, query wep/wpa parameters
       
   242             //
       
   243             if( !configuredIap )
       
   244                 {
       
   245                 iEasyWlanSelected = ETrue;
       
   246                 if ( iNetworkPrefs().iProtectedSetupSupported && 
       
   247                      iNetworkPrefs().iNetworkMode != EWlanConnectionModeAdhoc )
       
   248                     {
       
   249                     StartWpsDlgL();
       
   250                     return;                                    
       
   251                     }         
       
   252                 // WEP
       
   253                 //
       
   254                 if( iNetworkPrefs().iSecMode == EWlanConnectionSecurityWep )
       
   255                     {
       
   256                     MPMLOGSTRING( "CMPMWlanQueryDialog::RunL unknown wep network" )
       
   257                     iWlanQueryState = EWepSettings;
       
   258                     iNotifier.StartNotifierAndGetResponse( iStatus, 
       
   259                                                            KUidEasyWepDlg, 
       
   260                                                            iNotifWep, 
       
   261                                                            iNotifWep );
       
   262                     SetActive();
       
   263                     return;
       
   264                     }
       
   265                 // WPA
       
   266                 //
       
   267                 else if ( iNetworkPrefs().iSecMode == EWlanConnectionSecurityWpaPsk )
       
   268                     {
       
   269                     MPMLOGSTRING( "CMPMWlanQueryDialog::RunL unknown wpa network" )
       
   270                     iWlanQueryState = EWpaSettings;
       
   271                     iNotifier.StartNotifierAndGetResponse( iStatus, 
       
   272                                                            KUidEasyWpaDlg, 
       
   273                                                            iNotifWpaKey, 
       
   274                                                            iNotifWpaKey );
       
   275                     SetActive();
       
   276                     return;
       
   277 
       
   278                     }
       
   279                 else
       
   280                     {
       
   281                     MPMLOGSTRING2( "CMPMWlanQueryDialog::RunL security mode %d", 
       
   282                                    iNetworkPrefs().iSecMode )
       
   283                     }
       
   284                 }
       
   285         	
       
   286         	else
       
   287         	    {
       
   288         	    iWlanIapId = configuredIap;
       
   289         	    MPMLOGSTRING2( "CMPMWlanQueryDialog::RunL found configured iap matching ssid, id %d", 
       
   290         	                   iWlanIapId )
       
   291         	    
       
   292         	    }
       
   293             }
       
   294         else if( iStatus.Int() == KErrCancel )
       
   295             {
       
   296             iEasyWlanSelected = EFalse;
       
   297             MPMLOGSTRING( "CMPMWlanQueryDialog::RunL easy wlan dialog cancelled, \
       
   298 setting easy wlan as not selected" )
       
   299             }
       
   300         else
       
   301             {
       
   302             MPMLOGSTRING2( "CMPMWlanQueryDialog::RunL EWlanNetwork error %d", 
       
   303                 iStatus.Int() )
       
   304             }
       
   305         
       
   306         }
       
   307     else if( iWlanQueryState == EWepSettings || iWlanQueryState == EWpaSettings )
       
   308         {
       
   309         if( iStatus.Int() == KErrCancel )
       
   310       	   {
       
   311             MPMLOGSTRING( "CMPMWlanQueryDialog::Key dialog cancelled,back to easy wlan" )
       
   312             iNetworkPrefs().iSsId.FillZ();
       
   313             iNetworkPrefs().iNetworkMode = EWlanConnectionModeNotConnected;
       
   314             iNetworkPrefs().iSecMode = EWlanConnectionSecurityOpen;
       
   315             GetNetworkPrefs();
       
   316             return;
       
   317             }
       
   318         }
       
   319     else if( iWlanQueryState == EWPS )
       
   320         {
       
   321         MPMLOGSTRING2( "CMPMWlanQueryDialog::RunL WPS, status %d", iStatus.Int() )
       
   322         if( iStatus.Int()  == KErrNone )
       
   323             {
       
   324             if( iWpsReturn == WiFiProt::EWiFiOK)
       
   325                 {
       
   326                 MPMLOGSTRING( "CMPMWlanQueryDialog::RunL WPS ok" )
       
   327                 iWpsCompleted = ETrue;
       
   328                 }
       
   329             else if ( iWpsReturn == WiFiProt::EWiFiCancel )
       
   330                 {
       
   331                 MPMLOGSTRING( "CMPMWlanQueryDialog::RunL WPS cancelled" )
       
   332                 iStatus = KErrCancel;
       
   333                 }
       
   334             else // WiFiProt::EWiFiNoAuto
       
   335                 {
       
   336                 if( iNetworkPrefs().iSecMode == EWlanConnectionSecurityWep )
       
   337                     {
       
   338                     MPMLOGSTRING( "CMPMWlanQueryDialog::RunL: No WPS, starting WEP key query" );
       
   339                     iWlanQueryState = EWepSettings;
       
   340                     iNotifier.StartNotifierAndGetResponse( iStatus, 
       
   341                             KUidEasyWepDlg, 
       
   342                             iNotifWep, 
       
   343                             iNotifWep );
       
   344                     SetActive();
       
   345                     return;
       
   346                     }
       
   347                 else if ( iNetworkPrefs().iSecMode == EWlanConnectionSecurityWpaPsk )
       
   348                     {
       
   349                     MPMLOGSTRING( "CMPMWlanQueryDialog::RunL: No WPS, starting WPA key query" );
       
   350                     iWlanQueryState = EWpaSettings;
       
   351                     iNotifier.StartNotifierAndGetResponse( iStatus, 
       
   352                             KUidEasyWpaDlg, 
       
   353                             iNotifWpaKey, 
       
   354                             iNotifWpaKey );
       
   355                     SetActive();
       
   356                     return;
       
   357                     }
       
   358                 else if ( iNetworkPrefs().iSecMode == EWlanConnectionSecurityOpen )
       
   359                     {
       
   360                     MPMLOGSTRING( "CMPMWlanQueryDialog::RunL: No WPS, sec mode open" );
       
   361 					iStatus = KErrNone;
       
   362                     }
       
   363                 else
       
   364                     {
       
   365                     MPMLOGSTRING2( "CMPMWlanQueryDialog::RunL: No WPS, unsupported sec mode %d", 
       
   366                             iNetworkPrefs().iSecMode );
       
   367                     iStatus = KErrNotSupported;
       
   368                     }
       
   369                 }
       
   370             }
       
   371         }
       
   372     else if ( iWlanQueryState == ERetrySettingsStorage )
       
   373         {
       
   374         // Retry settings storage
       
   375         MPMLOGSTRING( "CMPMWlanQueryDialog::RunL Retry settings storage" )
       
   376         }
       
   377     else
       
   378         {
       
   379 		MPMLOGSTRING2( "CMPMWlanQueryDialog::RunL, unknown state: %d", iWlanQueryState )
       
   380         User::Leave( KErrCancel );
       
   381         }
       
   382         
       
   383     TRAPD( leaveCode, iIapSelection.UserWlanSelectionDoneL( iStatus.Int(), iWlanIapId ) );
       
   384     if( leaveCode != KErrNone )
       
   385         {
       
   386         // Something caused method to leave, if CommsDat was locked we should retry 
       
   387         if ( iStatus.Int() == KErrNone &&
       
   388              leaveCode == KErrLocked &&
       
   389              iRetryCount > 0 )
       
   390             {
       
   391             MPMLOGSTRING2( "CMPMWlanQueryDialog::RunL Start retry timer, retry count %d", iRetryCount )
       
   392             iWlanQueryState = ERetrySettingsStorage;
       
   393             iRetryCount--;
       
   394             iTimer.After( iStatus, KStoreRetryDelay );
       
   395             SetActive();
       
   396             return;
       
   397             }
       
   398         else
       
   399             {
       
   400             User::Leave( leaveCode );
       
   401             }
       
   402         }
       
   403     
       
   404     iWlanIapId = 0;
       
   405     iWlanQueryState = EWlanNetwork;
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // CMPMWlanQueryDialog::RunError
       
   410 // ---------------------------------------------------------------------------
       
   411 //
       
   412 TInt CMPMWlanQueryDialog::RunError( TInt aError )
       
   413     {
       
   414     MPMLOGSTRING2( "CMPMWlanQueryDialog::RunError failed with %d", aError )
       
   415     iEasyWlanSelected = EFalse;    
       
   416     iIapSelection.ChooseIapComplete( aError, NULL );    
       
   417     return KErrNone;
       
   418     }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CMPMWlanQueryDialog::StartWlanQueryL
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CMPMWlanQueryDialog::StartWlanQueryL()
       
   425     {
       
   426     MPMLOGSTRING( "CMPMWlanQueryDialog::StartWlanQuery" )
       
   427 
       
   428     iRetryCount = KStoreRetryCount;
       
   429     
       
   430     // if first dialog user, add it to the array and continue.
       
   431     //
       
   432     if ( iIapSelection.Session()->MyServer().WlanQueryQueue()->Count() == 0 )
       
   433         {
       
   434         MPMLOGSTRING( "CMPMWlanQueryDialog::StartWlanQuery First one, start immediately" )
       
   435         iIapSelection.Session()->MyServer().AppendWlanQueryQueueL( this );
       
   436         }
       
   437     // if another dialog should be processed before this, just add and return.
       
   438     //
       
   439     else if ( iIapSelection.Session()->MyServer().FirstInWlanQueryQueue() != this )
       
   440         {
       
   441         MPMLOGSTRING( "CMPMWlanQueryDialog::StartWlanQuery Latter, process later" )
       
   442         iIapSelection.Session()->MyServer().AppendWlanQueryQueueL( this );
       
   443         return;
       
   444         }
       
   445     // else Continue to process the first dialog.(this one)
       
   446     // FirstInWlanQueryQueue() == this && Count() > 0
       
   447     
       
   448     TUint32 activeWlanIap = iIapSelection.Session()->MyServer().IsWlanConnectionStartedL( 
       
   449         iIapSelection.Session()->MyServer().CommsDatAccess() );
       
   450 
       
   451     // Get EmergencyCallInfo via Publish & Subscribe
       
   452     // 
       
   453     TInt emergencyCallEstablished( 0 );
       
   454     RProperty::Get( KPSUidCtsyEmergencyCallInfo, 
       
   455                     KCTSYEmergencyCallInfo, 
       
   456                     emergencyCallEstablished );  
       
   457     MPMLOGSTRING2( "CMPMWlanQueryDialog::StartWlanQuery KCTSYEmergencyCallInfo = %d", 
       
   458                    emergencyCallEstablished )
       
   459 
       
   460     // Get note behaviour setting
       
   461     TUint32 noteBehaviour( 0 );
       
   462     noteBehaviour = iIapSelection.MpmConnPref().NoteBehaviour();
       
   463     MPMLOGSTRING2( "CMPMWlanQueryDialog::StartWlanQuery noteBehaviour = %d", noteBehaviour )
       
   464     
       
   465     if( !emergencyCallEstablished && 
       
   466         iIapSelection.Session()->MyServer().IsPhoneOffline() && 
       
   467         !activeWlanIap && 
       
   468         iIapSelection.Session()->MyServer().OfflineWlanQueryResponse() != EOfflineResponseYes &&
       
   469         iOverrideStatus == KErrNone )
       
   470         {
       
   471         if ( noteBehaviour & TExtendedConnPref::ENoteBehaviourConnDisableQueries )
       
   472             {
       
   473             MPMLOGSTRING( "CMPMWlanQueryDialog::StartWlanQuery offline note query not shown due to disabled queries" )
       
   474             iIapSelection.UserWlanSelectionDoneL( KErrPermissionDenied, iWlanIapId );
       
   475             }
       
   476         else
       
   477             {
       
   478             MPMLOGSTRING( "CMPMWlanQueryDialog::StartWlanQuery, starting offline note" )            
       
   479             iWlanQueryState = EOffline;
       
   480             iNotifier.StartNotifierAndGetResponse( iStatus, 
       
   481                                                    KUidCOfflineWlanNoteDlg, 
       
   482                                                    KNullDesC8(), 
       
   483                                                    iOfflineReply );
       
   484             SetActive();
       
   485             }
       
   486         }
       
   487     // if easy wlan iap and some wlan iap started, use existing connection
       
   488     //
       
   489     else if( iIapSelection.Session()->MyServer().CommsDatAccess()->CheckEasyWLanL( iWlanIapId )  && 
       
   490              activeWlanIap )
       
   491         {
       
   492         MPMLOGSTRING2( "CMPMWlanQueryDialog::StartWlanQuery using active WLAN IAP %d", 
       
   493                       activeWlanIap )
       
   494         iIapSelection.UserWlanSelectionDoneL( KErrNone, activeWlanIap );      
       
   495         }
       
   496     // if easy wlan iap and easy wlan is not already started
       
   497     // 
       
   498     else if( iIapSelection.Session()->MyServer().CommsDatAccess()->CheckEasyWLanL( iWlanIapId ) && 
       
   499              iIapSelection.Session()->MyServer().CheckUsageOfIap(
       
   500                      iWlanIapId, iIapSelection.Session()->ConnectionId() ) != EStarted &&
       
   501              iNetworkPrefs().iSsId.Length() == 0 &&
       
   502              iOverrideStatus == KErrNone )
       
   503         {
       
   504         MPMLOGSTRING( "CMPMWlanQueryDialog::StartWlanQuery starting network query" )
       
   505         GetNetworkPrefs();
       
   506         }
       
   507     // if an error was given through OfferInformation() -call we abort the execution.
       
   508     //
       
   509     else if ( iOverrideStatus != KErrNone )
       
   510         {
       
   511         MPMLOGSTRING2( "CMPMWlanQueryDialog::StartWlanQuery inherited error %d", iOverrideStatus )
       
   512         iIapSelection.UserWlanSelectionDoneL( iOverrideStatus, iWlanIapId );
       
   513         }
       
   514     else
       
   515         {
       
   516         MPMLOGSTRING( "CMPMWlanQueryDialog::StartWlanQuery no wlan dialog to show" )
       
   517         iIapSelection.UserWlanSelectionDoneL( KErrNone, iWlanIapId );
       
   518         }
       
   519     }
       
   520 
       
   521 
       
   522 // -----------------------------------------------------------------------------
       
   523 // CMPMWlanQueryDialog::OfferInformation
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 void CMPMWlanQueryDialog::OfferInformation(
       
   527                 TUint32 aWlanIapId,
       
   528                 TInt aDialogStatus )
       
   529     {
       
   530     TBool isEasyWlan( EFalse );
       
   531     // Take information from earlier note into use
       
   532     // if the selected IAP is EasyWLAN or Offline note response was No.
       
   533     //
       
   534     TRAP_IGNORE( isEasyWlan = 
       
   535         iIapSelection.Session()->MyServer().CommsDatAccess()->CheckEasyWLanL( iWlanIapId ); )
       
   536     if ( isEasyWlan ) 
       
   537         {
       
   538         // iEasyWlanSelected is not passed as only the first connection 
       
   539         // should write the easy wlan settings to commsdat if easy wlan is used.
       
   540         // 
       
   541         MPMLOGSTRING3( "CMPMWlanQueryDialog<0x%x>::OfferInformation: EasyWLAN, iap %d", 
       
   542                        iIapSelection.Session()->ConnectionId(),
       
   543                        aWlanIapId ) 
       
   544 
       
   545         iWlanIapId      = aWlanIapId;
       
   546         iOverrideStatus = aDialogStatus;
       
   547         }
       
   548     TOfflineWlanQueryResponse offlineResponse =
       
   549             iIapSelection.Session()->MyServer().OfflineWlanQueryResponse();
       
   550     if ( offlineResponse != EOfflineResponseUndefined )
       
   551         {
       
   552         MPMLOGSTRING3( "CMPMWlanQueryDialog<0x%x>::OfferInformation: offline response %d",
       
   553                        iIapSelection.Session()->ConnectionId(),
       
   554                        offlineResponse )
       
   555         iOverrideStatus = aDialogStatus;
       
   556         }
       
   557 
       
   558 #ifdef _LOG
       
   559     else
       
   560         {
       
   561         MPMLOGSTRING( "CMPMWlanQueryDialog::OfferInformation, information not taken." ) 
       
   562         }
       
   563 #endif 
       
   564     }
       
   565 
       
   566 
       
   567 // -----------------------------------------------------------------------------
       
   568 // CMPMWlanQueryDialog::StoreEasyWlanSelectionL
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 void CMPMWlanQueryDialog::StoreEasyWlanSelectionL()
       
   572     {
       
   573     if( iEasyWlanSelected )
       
   574         {
       
   575         TWlanSsid ssid;
       
   576         TWepKeyData wepData;
       
   577         TUint wpaPskEnabled( 0 );
       
   578         TUint wpaPskLen( 0 );
       
   579         TBuf8<KWLMMaxWpaPskLength> wpa;       
       
   580         TUint secMode( 0 );
       
   581         TWlanNetMode connMode( EInfra );
       
   582 
       
   583         if( iWpsCompleted )
       
   584             {
       
   585             GetEasyWlanDataForWpsL( ssid,
       
   586                                     secMode,
       
   587                                     connMode, 
       
   588                                     wepData,
       
   589                                     wpaPskEnabled, 
       
   590                                     wpa, 
       
   591                                     wpaPskLen );
       
   592             MPMLOGSTRING3( "CMPMWlanQueryDialog::StoreEasyWlanSelection: \
       
   593 wps used, connection iap %d, ssid %S", iWlanIapId, &iWpsAttribute.iSsid )
       
   594             iIapSelection.Session()->MyServer().Events()->
       
   595                 SetConnInfoIapSsid( iWlanIapId, 
       
   596                                     iWpsAttribute.iSsid );
       
   597             iIapSelection.Session()->MyServer().CommsDatAccess()->SetEasyWlanDataL( ssid,
       
   598                                                                          secMode,
       
   599                                                                          connMode, 
       
   600                                                                          wepData,
       
   601                                                                          wpaPskEnabled, 
       
   602                                                                          wpa, 
       
   603                                                                          wpaPskLen );
       
   604             return;
       
   605             }
       
   606 
       
   607         MPMLOGSTRING( "CMPMWlanQueryDialog::StoreEasyWlanSelection: setting easy wlan data" )
       
   608         GetEasyWlanDataL( ssid,
       
   609                           secMode,
       
   610                           connMode, 
       
   611                           wepData,
       
   612                           wpaPskEnabled, 
       
   613                           wpa, 
       
   614                           wpaPskLen );
       
   615 
       
   616         MPMLOGSTRING3( "CMPMWlanQueryDialog::StoreEasyWlanSelection: \
       
   617 setting easy wlan iap %d ssid %S in connmon events", iWlanIapId, &iNetworkPrefs().iSsId )
       
   618         iIapSelection.Session()->MyServer().Events()->SetConnInfoIapSsid( iWlanIapId, 
       
   619                                                                           iNetworkPrefs().iSsId );
       
   620         iIapSelection.Session()->MyServer().CommsDatAccess()->SetEasyWlanDataL( ssid,
       
   621                                                                      secMode,
       
   622                                                                      connMode, 
       
   623                                                                      wepData,
       
   624                                                                      wpaPskEnabled, 
       
   625                                                                      wpa, 
       
   626                                                                      wpaPskLen );
       
   627                     
       
   628         }
       
   629     else
       
   630         {
       
   631         MPMLOGSTRING( "CMPMWlanQueryDialog::StoreEasyWlanSelection: no easy wlan selected by user" )
       
   632         }
       
   633     }
       
   634 
       
   635 
       
   636 // -----------------------------------------------------------------------------
       
   637 // CMPMWlanQueryDialog::GetEasyWlanDataL
       
   638 // -----------------------------------------------------------------------------
       
   639 //
       
   640 void CMPMWlanQueryDialog::GetEasyWlanDataL( TWlanSsid&    aSsid,
       
   641                                             TUint&        aSecMode,
       
   642                                             TWlanNetMode& aConnMode,
       
   643                                             TWepKeyData&  aWepData,
       
   644                                             TUint&        aEnableWpaPsk,
       
   645                                             TDes8&        aWpaPsk,
       
   646                                             TUint&        aWpaKeyLen  )
       
   647     {
       
   648     aSsid.Copy( iNetworkPrefs().iSsId );
       
   649     if ( iNetworkPrefs().iNetworkMode == EWlanConnectionModeAdhoc )
       
   650         {
       
   651         aConnMode = EAdhoc;
       
   652         }
       
   653 
       
   654     // Set security mode
       
   655     TInt err = ConnSecModeToCommsDatSecMode( iNetworkPrefs().iSecMode,
       
   656                                              aSecMode );
       
   657 
       
   658     if( err != KErrNone )
       
   659         {
       
   660         MPMLOGSTRING2( "CMPMWlanQueryDialog::StoreEasyWlanSelection: \
       
   661 unsupported sec mode %d. leaving", iNetworkPrefs().iSecMode )
       
   662         User::Leave( KErrNotSupported );
       
   663         }
       
   664 
       
   665     if( iNetworkPrefs().iSecMode == EWlanConnectionSecurityWep )
       
   666         {
       
   667         CnvUtfConverter::ConvertFromUnicodeToUtf8( aWepData.iWep1, iNotifWep().iKey );
       
   668         //MPMLOG8STRING2( "CMPMWlanQueryDialog::StoreEasyWlanSelection:wep-key8:%S ", &aWepData.iWep1 )
       
   669         if( iNotifWep().iHex )
       
   670             {
       
   671         	aWepData.iWepFormat1 = 1;
       
   672         	MPMLOGSTRING( "CMPMWlanQueryDialog::StoreEasyWlanSelection: wep format is 1 (hex)") 
       
   673         	}
       
   674         aWepData.iDefaultWep = EWlanDefaultWepKey1;
       
   675         }
       
   676     else if( iNetworkPrefs().iSecMode == EWlanConnectionSecurityWpaPsk )
       
   677         {        
       
   678         CnvUtfConverter::ConvertFromUnicodeToUtf8( aWpaPsk, iNotifWpaKey() );
       
   679         aEnableWpaPsk = 1;
       
   680         aWpaKeyLen = aWpaPsk.Length();
       
   681         MPMLOGSTRING3( "CMPMWlanQueryDialog::StoreEasyWlanSelection:wpapsk-key:%s, len:%d", 
       
   682                        &iNotifWpaKey(), 
       
   683                        aWpaKeyLen )
       
   684         }
       
   685     else
       
   686         {
       
   687         MPMLOGSTRING2( "CMPMWlanQueryDialog::StoreEasyWlanSelection: \
       
   688 no key handling needed for sec mode %d", iNetworkPrefs().iSecMode )
       
   689         }
       
   690     }
       
   691 
       
   692 // ---------------------------------------------------------------------------
       
   693 // CMPMWlanQueryDialog::ConnSecModeToCommsDatSecMode
       
   694 // ---------------------------------------------------------------------------
       
   695 //
       
   696 TInt CMPMWlanQueryDialog::ConnSecModeToCommsDatSecMode( TWlanConnectionSecurityMode aConnSecmode,
       
   697                                                         TUint& aCommsdatSecMode ) const
       
   698     {
       
   699 
       
   700     if ( aConnSecmode == EWlanConnectionSecurityOpen )
       
   701         {
       
   702         aCommsdatSecMode = EWlanSecModeOpen;
       
   703         }
       
   704     else if ( aConnSecmode == EWlanConnectionSecurityWep )
       
   705         {
       
   706         aCommsdatSecMode = EWlanSecModeWep;
       
   707         }
       
   708     else if ( aConnSecmode == EWlanConnectionSecurityWpaPsk )
       
   709        	{
       
   710        	aCommsdatSecMode = EWlanSecModeWpa2;
       
   711        	}
       
   712     else if ( aConnSecmode == EWlanConnectionSecurityWpa )
       
   713        	{
       
   714        	aCommsdatSecMode = EWlanSecModeWpa;
       
   715         }
       
   716     else
       
   717        	{
       
   718        	MPMLOGSTRING( "CMPMWlanQueryDialog::RunL, Unknown security mode" )
       
   719        	return KErrCouldNotConnect;
       
   720        	}
       
   721     return KErrNone;    
       
   722     }
       
   723 
       
   724 
       
   725 // ---------------------------------------------------------------------------
       
   726 // CMPMWlanQueryDialog::IapSecModeToCommsDatSecMode
       
   727 // ---------------------------------------------------------------------------
       
   728 //
       
   729 TInt CMPMWlanQueryDialog::IapSecModeToCommsDatSecMode( TWlanIapSecurityMode aIapSecmode,
       
   730                                                        TUint& aCommsdatSecMode ) const
       
   731     {
       
   732     switch( aIapSecmode )
       
   733         {
       
   734         case EWlanIapSecurityModeAllowUnsecure:
       
   735     	    aCommsdatSecMode |= EWlanSecModeOpen;
       
   736             break;
       
   737         case EWlanIapSecurityModeWep:
       
   738             aCommsdatSecMode |= EWlanSecModeWep;
       
   739             break;
       
   740         case EWlanIapSecurityModeWpa:
       
   741             aCommsdatSecMode |= EWlanSecModeWpa;
       
   742             break;
       
   743         case EWlanIapSecurityModeWpa2Only:
       
   744             aCommsdatSecMode |= EWlanSecModeWpa2;
       
   745             break;
       
   746         default:
       
   747             MPMLOGSTRING2( "CMPMWlanQueryDialog::IapSecModeToCommsDatSecMode: \
       
   748 unsupported sec mode %d ", aIapSecmode )
       
   749             return KErrNotSupported;
       
   750         }
       
   751     return KErrNone;    
       
   752     }
       
   753 
       
   754 // -----------------------------------------------------------------------------
       
   755 // CMPMWlanQueryDialog::GetEasyWlanDataForWpsL
       
   756 // -----------------------------------------------------------------------------
       
   757 //
       
   758 void CMPMWlanQueryDialog::GetEasyWlanDataForWpsL( TWlanSsid&    aSsid,
       
   759                                                   TUint&        aSecMode,
       
   760                                                   TWlanNetMode& aConnMode,
       
   761                                                   TWepKeyData&  aWepKeyData, 
       
   762                                                   TUint&        aEnableWpaPsk,
       
   763                                                   TDes8&        aWpaPsk,
       
   764                                                   TUint&        aWpaKeyLen  )
       
   765     {
       
   766     aSsid.Copy( iWpsAttribute.iSsid );
       
   767     if ( iWpsAttribute.iOperatingMode == EWlanOperatingModeAdhoc )
       
   768         {
       
   769         aConnMode = EAdhoc;
       
   770         }
       
   771     TInt err = IapSecModeToCommsDatSecMode( iWpsAttribute.iSecurityMode, 
       
   772                                             aSecMode );
       
   773     if( err != KErrNone )
       
   774         {
       
   775         MPMLOGSTRING( "CMPMWlanQueryDialog::GetEasyWlanDataForWpsL: \
       
   776 unsupported wps sec mode leaving" )
       
   777         User::Leave( KErrNotSupported );
       
   778         }
       
   779 
       
   780     if( iWpsAttribute.iSecurityMode == EWlanIapSecurityModeWep )
       
   781         {
       
   782         if( iWpsAttribute.iWepKey1.Length() && 
       
   783             IsWepFormatHexL( iWpsAttribute.iWepKey1.Length() ) )
       
   784             {
       
   785             aWepKeyData.iWepFormat1 = 1;
       
   786             }
       
   787         if( iWpsAttribute.iWepKey2.Length() && 
       
   788             IsWepFormatHexL( iWpsAttribute.iWepKey2.Length() ) )
       
   789             {
       
   790             aWepKeyData.iWepFormat2 = 1;
       
   791             }
       
   792         if( iWpsAttribute.iWepKey3.Length() && 
       
   793             IsWepFormatHexL( iWpsAttribute.iWepKey3.Length() ) )
       
   794             {
       
   795             aWepKeyData.iWepFormat3 = 1;
       
   796             }
       
   797         if( iWpsAttribute.iWepKey4.Length() && 
       
   798             IsWepFormatHexL( iWpsAttribute.iWepKey4.Length() ) )
       
   799             {
       
   800             aWepKeyData.iWepFormat4 = 1;
       
   801             }
       
   802         aWepKeyData.iWep1.Copy( iWpsAttribute.iWepKey1 );
       
   803         aWepKeyData.iWep2.Copy( iWpsAttribute.iWepKey2 );
       
   804         aWepKeyData.iWep3.Copy( iWpsAttribute.iWepKey3 );
       
   805         aWepKeyData.iWep4.Copy( iWpsAttribute.iWepKey4 );
       
   806         aWepKeyData.iDefaultWep = iWpsAttribute.iWepDefaultKey;        
       
   807         }
       
   808     if( iWpsAttribute.iWpaPreSharedKey.Length() )
       
   809         {
       
   810         aEnableWpaPsk = 1;
       
   811         aWpaPsk.Copy( iWpsAttribute.iWpaPreSharedKey );
       
   812         aWpaKeyLen = aWpaPsk.Length();
       
   813         }
       
   814 
       
   815     }
       
   816 
       
   817 // ---------------------------------------------------------------------------
       
   818 // CMPMWlanQueryDialog::StartWpsDlgL
       
   819 // ---------------------------------------------------------------------------
       
   820 //
       
   821 void CMPMWlanQueryDialog::StartWpsDlgL()
       
   822     {
       
   823     MPMLOGSTRING( "CMPMWlanQueryDialog::StartWpsDlgL, Starting WPS" )
       
   824     iWlanQueryState = EWPS;
       
   825     iWps = CWiFiProtUiClient::NewL();
       
   826     iWps->StartWiFiProtConnL( iNetworkPrefs().iSsId, // TWlanSsid&,
       
   827                               iWpsAttribute,
       
   828                               iWpsReturn,
       
   829                               iStatus );
       
   830     SetActive();
       
   831     }
       
   832 
       
   833 // ---------------------------------------------------------------------------
       
   834 // CMPMWlanQueryDialog::IsWepFormatHexL
       
   835 // ---------------------------------------------------------------------------
       
   836 //
       
   837 TBool CMPMWlanQueryDialog::IsWepFormatHexL( TInt aLength ) const
       
   838     {
       
   839     MPMLOGSTRING2( "CMPMWlanQueryDialog::IsWepFormatHexL length %d", aLength )
       
   840 
       
   841     if ( ( aLength == KConnUiUtilsWepLengthASCII5 ) ||
       
   842         ( aLength == KConnUiUtilsWepLengthASCII13 ) ||
       
   843         ( aLength == KConnUiUtilsWepLengthASCII29 ) )
       
   844         {
       
   845         return EFalse;
       
   846         }
       
   847     else if ( ( aLength == KConnUiUtilsWepLengthHEX10 ) ||
       
   848         ( aLength == KConnUiUtilsWepLengthHEX26 ) ||
       
   849         ( aLength == KConnUiUtilsWepLengthHEX58 ) )
       
   850         {
       
   851         return ETrue;
       
   852         }
       
   853     else
       
   854         {
       
   855         User::Leave( KErrNotSupported );
       
   856         }            
       
   857     return EFalse;
       
   858     }
       
   859     
       
   860 // ---------------------------------------------------------------------------
       
   861 // CMPMWlanQueryDialog::GetNetworkPrefs
       
   862 // ---------------------------------------------------------------------------
       
   863 //
       
   864 void CMPMWlanQueryDialog::GetNetworkPrefs()
       
   865     {
       
   866     iWlanQueryState = EWlanNetwork;
       
   867     iConnUiUtils->SearchWLANNetworkAsync( iStatus,
       
   868                                           iNetworkPrefs().iSsId,
       
   869                                           iNetworkPrefs().iNetworkMode,
       
   870                                           iNetworkPrefs().iSecMode, 
       
   871                                           iNetworkPrefs().iProtectedSetupSupported
       
   872                                         );
       
   873     SetActive();
       
   874     }
       
   875