eapol/eapol_framework/eapol_symbian/am/type/ttls_pap/symbian/src/eap_ttls_pap_active.cpp
branchGCC_SURGE
changeset 40 60f08993dad0
parent 29 77618ad58aba
parent 39 fe6b6762fccd
equal deleted inserted replaced
29:77618ad58aba 40:60f08993dad0
     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 the License "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:  Provide synch/asynch services used by the caller to show
       
    15 *                EAP-TTLS-PAP related notes.
       
    16 *
       
    17 */
       
    18 
       
    19 /*
       
    20 * %version: 13.1.2 %
       
    21 */
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include "eap_tools.h"
       
    25 #include "eap_ttls_pap_active.h"
       
    26 #include "eap_am_type_tls_peap_symbian.h"
       
    27 #include "eap_am_trace_symbian.h"
       
    28 #include "eap_variable_data.h"
       
    29 
       
    30 // ================= public:  Constructors and destructor =======================
       
    31 
       
    32 // ---------------------------------------------------------
       
    33 // CEapTtlsPapActive::NewL()
       
    34 // ---------------------------------------------------------
       
    35 //
       
    36 CEapTtlsPapActive* CEapTtlsPapActive::NewL(
       
    37     eap_am_type_tls_peap_symbian_c* aCaller,
       
    38     eap_am_tools_symbian_c* aAmTools )
       
    39     {
       
    40     DEBUG( "CEapTtlsPapActive::NewL()" );
       
    41     CEapTtlsPapActive* self = new(ELeave) CEapTtlsPapActive(
       
    42     	aCaller, aAmTools );
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop();
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------
       
    50 // CEapTtlsPapActive::~CEapTtlsPapActive()
       
    51 // ---------------------------------------------------------
       
    52 //    
       
    53 CEapTtlsPapActive::~CEapTtlsPapActive()
       
    54     {
       
    55     DEBUG( "CEapTtlsPapActive::~CEapTtlsPapActive()" );	
       
    56 	if ( !iCancelCalled )
       
    57 	    {
       
    58 	    Clean();
       
    59 	   	}
       
    60     }
       
    61 
       
    62 // ================= public:  new =======================
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CEapTtlsPapActive::Start()
       
    66 // ---------------------------------------------------------
       
    67 //    
       
    68 TBool CEapTtlsPapActive::Start( TEapTtlsPapActiveState aState )
       
    69     {
       
    70     DEBUG1( "CEapTtlsPapActive::Start() aState=%d.", aState );
       
    71     TBool status = ETrue;
       
    72 
       
    73     if( IsActive() )
       
    74 		{
       
    75 		DEBUG2( "CEapTtlsPapActive::Start() ERROR: AO is active, iActiveState=%d, aState=%d.",
       
    76             iActiveState, aState );
       
    77 		return EFalse;
       
    78 		}
       
    79 	if ( iCancelCalled )
       
    80 		{
       
    81 		DEBUG( "CEapTtlsPapActive::Start() cancel was called." );
       
    82 		return EFalse;
       
    83 		}
       
    84     iActiveState = aState;    
       
    85     switch ( iActiveState )
       
    86         {
       
    87         case EEapTtlsPapActiveQueryUserNameAndPassword:
       
    88         	{
       
    89         	// nothing to do here, we should return asap;
       
    90         	// the job is done in RunL() method;
       
    91         	// therefore we complete here
       
    92         	SetActive();    
       
    93             iRequestStatus = &iStatus;
       
    94             User::RequestComplete( iRequestStatus, KErrNone );
       
    95             break;
       
    96         	}
       
    97         case EEapTtlsPapActiveShowAuthQueryDialog: // asynch. call
       
    98         	{
       
    99         	StartAuthenticationQueryDialog();
       
   100             SetActive();
       
   101         	break;
       
   102         	}        	
       
   103         case EEapTtlsPapActiveShowPapChallengeMsgDialog:
       
   104         	{
       
   105         	StartPapChallengeMsgDialog();
       
   106         	SetActive();
       
   107         	break;
       
   108         	}
       
   109         case EEapTtlsPapActiveShowPapChallengeReplyQueryDialog:
       
   110         	{
       
   111         	StartPapChallengeReplyQueryDialog();
       
   112         	SetActive();
       
   113         	break;
       
   114         	}
       
   115         default:
       
   116         	{
       
   117     		DEBUG1( "CEapTtlsPapActive::Start() ERROR: State is not supported, iActiveState = %d.",
       
   118     	            iActiveState );
       
   119     		status = EFalse;
       
   120             break;
       
   121         	}
       
   122         }
       
   123     return status;
       
   124     } // EapTtlsPapActive::Start()
       
   125 
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // CEapTtlsPapActive::UpdateSrvChallenge()
       
   129 // ---------------------------------------------------------
       
   130 // 
       
   131 eap_status_e CEapTtlsPapActive::UpdateSrvChallenge(
       
   132 	const eap_variable_data_c& aSrvChallengeUtf8 )
       
   133 	{
       
   134 	DEBUG( "CEapTtlsPapActive::UpdateSrvChallenge()" );
       
   135 
       
   136 	eap_status_e status = eap_status_ok;
       
   137 	
       
   138 	if ( iSrvChallengeUnicode != NULL )
       
   139 		{
       
   140 		// delete
       
   141 		delete iSrvChallengeUnicode ;
       
   142 		iSrvChallengeUnicode = NULL;
       
   143 		}
       
   144 	// convert utf8->unicode,
       
   145 	// aSrvChallengeUtf8 is UTF8 string, unicode max length is
       
   146 	// then the length of UTF8 string.
       
   147 	// NOTE, HBufC16 length means count of 16-bit objects.
       
   148 	TRAPD( err, iSrvChallengeUnicode = HBufC16::NewL( aSrvChallengeUtf8.get_data_length() ); );
       
   149 	if ( err != KErrNone )
       
   150 	    {
       
   151 		status = iCaller->ConvertAmErrorToEapolError( err );
       
   152 		return status;
       
   153 	    } 
       
   154 	TPtr16 srvChallengeUnicodePtr = iSrvChallengeUnicode->Des();
       
   155 
       
   156 	const TPtrC8 ptrUtf8(
       
   157 		aSrvChallengeUtf8.get_data( aSrvChallengeUtf8.get_data_length() ),
       
   158 		aSrvChallengeUtf8.get_data_length() ); // Length in bytes
       
   159 
       
   160 	CnvUtfConverter::ConvertToUnicodeFromUtf8(
       
   161 		srvChallengeUnicodePtr, ptrUtf8 );
       
   162 	// print data
       
   163 	EAP_TRACE_DATA_DEBUG( iAmTools, TRACE_FLAGS_DEFAULT, (
       
   164 		EAPL( "iSrvChallengeUnicode" ),
       
   165 		iSrvChallengeUnicode->Ptr(),
       
   166 		iSrvChallengeUnicode->Size() ) );
       
   167 	
       
   168 	return status;
       
   169 	}
       
   170 
       
   171 
       
   172 // ================= protected: from CActive =======================
       
   173 
       
   174 // ---------------------------------------------------------
       
   175 // CEapTtlsPapActive::DoCancel()
       
   176 // ---------------------------------------------------------
       
   177 // 
       
   178 void CEapTtlsPapActive::DoCancel()
       
   179     {
       
   180     DEBUG( "CEapTtlsPapActive::DoCancel()" );
       
   181     DEBUG( "CEapTtlsPapActive::DoCancel() iNotifier.CancelNotifier() called." );
       
   182 	iNotifier.CancelNotifier( KPapNotifierUid );
       
   183     }
       
   184  
       
   185 // ---------------------------------------------------------
       
   186 // CEapTtlsPapActive::RunL()
       
   187 // ---------------------------------------------------------
       
   188 //     
       
   189 void CEapTtlsPapActive::RunL()
       
   190     {
       
   191     DEBUG1( "CEapTtlsPapActive::RunL() iStatus=%d", iStatus.Int() );
       
   192     
       
   193     switch ( iActiveState )
       
   194         {
       
   195         case EEapTtlsPapActiveQueryUserNameAndPassword:
       
   196         	{
       
   197         	CompleteQueryUserNameAndPassword();
       
   198         	break;
       
   199         	}
       
   200         case EEapTtlsPapActiveShowAuthQueryDialog:
       
   201     	    {
       
   202     	    CompleteAuthenticationQueryDialog();
       
   203     	    break;
       
   204     	    }	    
       
   205         case EEapTtlsPapActiveShowPapChallengeMsgDialog:
       
   206         	{
       
   207         	CompletePapChallengeMsgDialog();
       
   208         	break;
       
   209         	}
       
   210         case EEapTtlsPapActiveShowPapChallengeReplyQueryDialog:
       
   211         	{
       
   212         	CompletePapChallengeReplyQueryDialog();
       
   213         	break;
       
   214         	}
       
   215         default:
       
   216         	{
       
   217     		DEBUG1( "CEapTtlsPapActive::RunL() ERROR: State is not supported, iActiveState = %d.",
       
   218     	            iActiveState);
       
   219             break;
       
   220         	}
       
   221         }
       
   222     }
       
   223 
       
   224 // ================= private: new, for AO =======================
       
   225    
       
   226 // ---------------------------------------------------------
       
   227 // CEapTtlsPapActive::CompleteQueryUserNameAndPassword()
       
   228 // ---------------------------------------------------------
       
   229 //    
       
   230 void CEapTtlsPapActive::CompleteQueryUserNameAndPassword()
       
   231 	{
       
   232 	DEBUG( "CEapTtlsPapActive::CompleteQueryUserNameAndPassword()" );	
       
   233     
       
   234 	if ( iSrvChallengeUnicode == NULL )
       
   235 		{
       
   236 		CompleteWithSrvChallengeNull();
       
   237 		}
       
   238 	else
       
   239 		{
       
   240 		CompleteWithSrvChallengeNotNull();
       
   241 		}	
       
   242 	} // CEapTtlsPapActive::CompleteQueryUserNameAndPassword()
       
   243 
       
   244 
       
   245 // ---------------------------------------------------------
       
   246 // CEapTtlsPapActive::CompleteWithSrvChallengeNull()
       
   247 // ---------------------------------------------------------
       
   248 //    
       
   249 void CEapTtlsPapActive::CompleteWithSrvChallengeNull()
       
   250 	{
       
   251 	DEBUG( "CEapTtlsPapActive::CompleteWithSrvChallengeNull()" );	
       
   252 
       
   253 	if ( !iCaller )
       
   254 		{
       
   255 		DEBUG( "CEapTtlsPapActive::CompleteWithSrvChallengeNull() ERROR: iCaller==NULL." );	
       
   256 		return;
       
   257 		}
       
   258 	
       
   259 	if ( !iIsTtlsPapDbInfoInitialized )
       
   260 		{
       
   261 	    // Read prompt, user name, password, and time stamps from database.
       
   262 	    TRAPD( err,  iCaller->ReadTtlsPapDbL( iTtlsPapDbInfo ) );	
       
   263 	    if ( err != KErrNone )
       
   264 		    {
       
   265 		    DEBUG1( "CEapTtlsPapActive::CompleteWithSrvChallengeNull() \
       
   266 			    ERROR: Leave, err==%d.", err );			
       
   267 		    iCaller->CompleteQueryTtlsPapUserNameAndPassword(
       
   268 			    iCaller->ConvertAmErrorToEapolError( err ),
       
   269 			    KNullDesC8(), KNullDesC8() );
       
   270 		    return;
       
   271 		    }
       
   272 	    iIsTtlsPapDbInfoInitialized = ETrue;
       
   273 		}
       
   274 	
       
   275     if ( iTtlsPapDbInfo.iUsrPwdInfo.iPasswordPromptEnabled )
       
   276     	{
       
   277     	// set password to null value
       
   278     	TRAPD(err, iCaller->SetTtlsPapColumnToNullL( cf_str_EAP_TLS_PEAP_ttls_pap_password_literal ));
       
   279 
       
   280     	if (err != KErrNone)
       
   281     	    {
       
   282     	    DEBUG1( "CEapTtlsPapActive::CompleteWithSrvChallengeNull() \
       
   283     	        ERROR: Leave, err==%d.", err );         
       
   284     	    iCaller->CompleteQueryTtlsPapUserNameAndPassword(
       
   285     	        iCaller->ConvertAmErrorToEapolError( err ),
       
   286     	        KNullDesC8(), KNullDesC8() );
       
   287     	    return;
       
   288     	    }
       
   289 
       
   290     	// display query dialog
       
   291     	Start( EEapTtlsPapActiveShowAuthQueryDialog );
       
   292     	}
       
   293     else // prompt not active
       
   294     	{
       
   295     	if ( iTtlsPapDbInfo.iUsrPwdInfo.iUserName.Length() != 0  &&
       
   296     		 iTtlsPapDbInfo.iUsrPwdInfo.iPassword.Length() != 0  )
       
   297     		{
       
   298             // complete query with user name and password from database;
       
   299     		// first, convert from unicode to utf8.
       
   300         	TBuf8<KMaxPapUserNameLength> userNameUtf8;
       
   301         	CnvUtfConverter::ConvertFromUnicodeToUtf8( userNameUtf8,
       
   302         		iTtlsPapDbInfo.iUsrPwdInfo.iUserName );
       
   303         	EAP_TRACE_DATA_DEBUG( iAmTools, TRACE_FLAGS_DEFAULT, (
       
   304         		EAPL( "userNameUtf8" ),
       
   305         		userNameUtf8.Ptr(),
       
   306         		userNameUtf8.Size() ) );
       
   307 
       
   308         	TBuf8<KMaxPapPasswordLength> passwordUtf8;
       
   309         	CnvUtfConverter::ConvertFromUnicodeToUtf8( passwordUtf8,
       
   310         		iTtlsPapDbInfo.iUsrPwdInfo.iPassword );   	
       
   311         	EAP_TRACE_DATA_DEBUG( iAmTools, TRACE_FLAGS_DEFAULT, (
       
   312         		EAPL( "passwordUtf8" ),
       
   313         		passwordUtf8.Ptr(),
       
   314         		passwordUtf8.Size() ) );
       
   315        	
       
   316         	iCaller->CompleteQueryTtlsPapUserNameAndPassword(
       
   317             	eap_status_ok, userNameUtf8, passwordUtf8 );    		
       
   318     		}
       
   319     	else // user name or password is empty
       
   320     		{
       
   321         	// display query dialog
       
   322         	Start( EEapTtlsPapActiveShowAuthQueryDialog );
       
   323     		}   	
       
   324     	} // if ( iPrompt )
       
   325 	} // CEapTtlsPapActive::CompleteWithSrvChallengeNull()
       
   326 
       
   327 // ---------------------------------------------------------
       
   328 // CEapTtlsPapActive::CompleteWithSrvChallengeNotNull()
       
   329 // ---------------------------------------------------------
       
   330 //    
       
   331 void CEapTtlsPapActive::CompleteWithSrvChallengeNotNull()
       
   332 	{
       
   333 	DEBUG( "CEapTtlsPapActive::CompleteWithSrvChallengeNotNull()" );	
       
   334 	if ( !iCaller )
       
   335 		{
       
   336 		DEBUG( "CEapTtlsPapActive::CompleteWithSrvChallengeNotNull() ERROR: iCaller==NULL." );	
       
   337 		return;
       
   338 		}
       
   339 	
       
   340 	if ( !iIsTtlsPapDbInfoInitialized )
       
   341 		{
       
   342 	    // Read prompt, user name, password, and time stamps from database.
       
   343 	    TRAPD( err,  iCaller->ReadTtlsPapDbL( iTtlsPapDbInfo ) );	
       
   344 	    if ( err != KErrNone )
       
   345 		    {
       
   346 		    DEBUG1( "CEapTtlsPapActive::CompleteWithSrvChallengeNotNull() \
       
   347 			    ERROR: Leave, err==%d.", err );			
       
   348 		    iCaller->CompleteQueryTtlsPapUserNameAndPassword(
       
   349 			    iCaller->ConvertAmErrorToEapolError( err ),
       
   350 			    KNullDesC8(), KNullDesC8() );
       
   351 		    return;
       
   352 		    }
       
   353 	    iIsTtlsPapDbInfoInitialized = ETrue;
       
   354 		}
       
   355 	
       
   356 	// display PAP challenge message dialog
       
   357 	Start( EEapTtlsPapActiveShowPapChallengeMsgDialog );
       
   358 	} // CEapTtlsPapActive::CompleteWithSrvChallengeNotNull()
       
   359 
       
   360 // ---------------------------------------------------------
       
   361 // CEapTtlsPapActive::StartAuthenticationQueryDialog()
       
   362 // ---------------------------------------------------------
       
   363 //    
       
   364 void CEapTtlsPapActive::StartAuthenticationQueryDialog()
       
   365 	{
       
   366 	DEBUG( "CEapTtlsPapActive::StartAuthenticationQueryDialog()" );
       
   367 	
       
   368 	if ( iNotifierDataPckgToUser == NULL ||
       
   369 		 iNotifierDataPckgFromUser == NULL ||
       
   370 		 iNotifierDataToUser == NULL ||
       
   371 		 iNotifierDataFromUser == NULL )
       
   372 		{
       
   373 		DEBUG( "CEapTtlsPapActive::StartAuthenticationQueryDialog() \
       
   374 				ERROR: data pointer is NULL." );
       
   375 		return;
       
   376 		}
       
   377 	
       
   378 	// set user name, copy data
       
   379 	( *iNotifierDataPckgToUser )().iUsrPwdInfo.iUserName = iTtlsPapDbInfo.iUsrPwdInfo.iUserName;
       
   380 	EAP_TRACE_DATA_DEBUG( iAmTools, TRACE_FLAGS_DEFAULT, (
       
   381 		EAPL( "iUserName" ),
       
   382 		iTtlsPapDbInfo.iUsrPwdInfo.iUserName.Ptr(),
       
   383 		iTtlsPapDbInfo.iUsrPwdInfo.iUserName.Size() ) );
       
   384 		
       
   385 	iNotifierDataToUser->iState = TPapUiNotifierInfo::
       
   386 	    EPapUiNotifierAuthQueryDialog;
       
   387 	iNotifier.StartNotifierAndGetResponse( 
       
   388         iStatus,
       
   389         KPapNotifierUid,
       
   390         *iNotifierDataPckgToUser,
       
   391 		*iNotifierDataPckgFromUser );
       
   392    	} // CEapTtlsPapActive::StartAuthenticationQueryDialog()
       
   393 
       
   394 // ---------------------------------------------------------
       
   395 // CEapTtlsPapActive::CompleteAuthenticationQueryDialog()
       
   396 // ---------------------------------------------------------
       
   397 // 
       
   398 // called in RunL()
       
   399 void CEapTtlsPapActive::CompleteAuthenticationQueryDialog()
       
   400 	{
       
   401 	DEBUG( "CEapTtlsPapActive::CompleteAuthenticationQueryDialog()" );
       
   402 	
       
   403     if ( iStatus == KErrNone )
       
   404     	{
       
   405     	iUserAction = EPapNotifierUserActionOk;
       
   406     	}
       
   407     else if ( iStatus == KErrCancel )
       
   408 		{
       
   409 		iUserAction = EPapNotifierUserActionCancel;	
       
   410 		}		
       
   411 	else
       
   412 		{
       
   413 	    DEBUG1( "CEapTtlsPapActive::CompleteAuthenticationQueryDialog() \
       
   414 	        ERROR: iStatus=%d", iStatus.Int() );
       
   415 		return;
       
   416 		}
       
   417     DEBUG1( "CEapTtlsPapActive::CompleteAuthenticationQueryDialog() \
       
   418         iUserAction=%d", iStatus.Int() );   
       
   419 	
       
   420 	if ( !iCaller )
       
   421 		{
       
   422 		DEBUG( "CEapTtlsPapActive::CompleteAuthenticationQueryDialog() \
       
   423 	        ERROR: iCaller==NULL." );
       
   424 		return;
       
   425 		}
       
   426 	if ( !iNotifierDataFromUser )
       
   427 		{
       
   428 		DEBUG( "CEapTtlsPapActive::CompleteAuthenticationQueryDialog() \
       
   429             ERROR: iNotifierDataFromUser==NULL." );		
       
   430 		return;
       
   431 		}
       
   432 	if ( iUserAction == EPapNotifierUserActionOk )
       
   433 		{		
       
   434 		// just update last cache time in db
       
   435 		iTtlsPapDbInfo.iLastFullAuthTime = GetCurrentTime();	
       
   436 		
       
   437 		if ( !iTtlsPapDbInfo.iUsrPwdInfo.iPasswordPromptEnabled )
       
   438 			{
       
   439 			// prompt is not active;
       
   440 			// update user name, and password
       
   441 			iTtlsPapDbInfo.iUsrPwdInfo.iUserName = iNotifierDataFromUser->
       
   442 			    iUsrPwdInfo.iUserName;
       
   443 			iTtlsPapDbInfo.iUsrPwdInfo.iPassword = iNotifierDataFromUser->
       
   444 			    iUsrPwdInfo.iPassword;			
       
   445 			}
       
   446 		
       
   447 		// update database
       
   448 	    TRAPD( err, iCaller->WriteTtlsPapDbL( iTtlsPapDbInfo ) );
       
   449 
       
   450 	    if (err != KErrNone)
       
   451 	        {
       
   452 	        DEBUG1( "CEapTtlsPapActive::CompleteAuthenticationQueryDialog() \
       
   453 	            ERROR: Leave, err==%d.", err );         
       
   454 	        iCaller->CompleteQueryTtlsPapUserNameAndPassword(
       
   455 	            iCaller->ConvertAmErrorToEapolError( err ),
       
   456 	            KNullDesC8(), KNullDesC8() );
       
   457 	        return;
       
   458 	        }
       
   459 		
       
   460         // convert from unicode to utf8
       
   461 		TBuf8<KMaxPapUserNameLength> userNameUtf8;
       
   462     	CnvUtfConverter::ConvertFromUnicodeToUtf8( userNameUtf8,
       
   463     		iNotifierDataFromUser->iUsrPwdInfo.iUserName );
       
   464     	EAP_TRACE_DATA_DEBUG( iAmTools, TRACE_FLAGS_DEFAULT, (
       
   465     		EAPL( "userNameUtf8" ),
       
   466     		userNameUtf8.Ptr(),
       
   467     		userNameUtf8.Size() ) );
       
   468 
       
   469     	TBuf8<KMaxPapPasswordLength> passwordUtf8;
       
   470     	CnvUtfConverter::ConvertFromUnicodeToUtf8( passwordUtf8,
       
   471     		iNotifierDataFromUser->iUsrPwdInfo.iPassword );   	
       
   472     	EAP_TRACE_DATA_DEBUG( iAmTools, TRACE_FLAGS_DEFAULT, (
       
   473     		EAPL( "passwordUtf8" ),
       
   474     		passwordUtf8.Ptr(),
       
   475     		passwordUtf8.Size() ) );
       
   476    	
       
   477     	// complete query with user name and password from UI
       
   478     	iCaller->CompleteQueryTtlsPapUserNameAndPassword(
       
   479         	eap_status_ok, userNameUtf8, passwordUtf8 );
       
   480 		}
       
   481   	else //if (userAction == EPapNotifierUserActionCancel)
       
   482   		{
       
   483   		// user name and password are not used
       
   484 		iCaller->CompleteQueryTtlsPapUserNameAndPassword(
       
   485 			eap_status_user_cancel_authentication,
       
   486 			KNullDesC8(),
       
   487 			KNullDesC8() );
       
   488   		} 
       
   489 	} // CEapTtlsPapActive::CompleteAuthenticationQueryDialog()
       
   490 
       
   491 
       
   492 // ---------------------------------------------------------
       
   493 // CEapTtlsPapActive::StartPapChallengeMsgDialog()
       
   494 // ---------------------------------------------------------
       
   495 // 
       
   496 void CEapTtlsPapActive::StartPapChallengeMsgDialog()
       
   497 	{
       
   498 	DEBUG( "CEapTtlsPapActive::StartPapChallengeMsgDialog()" );
       
   499 	
       
   500 	if ( iNotifierDataPckgToUser == NULL ||
       
   501 		 iNotifierDataPckgFromUser == NULL ||
       
   502 		 iNotifierDataToUser == NULL ||
       
   503 		 iNotifierDataFromUser == NULL )
       
   504 		{
       
   505 		DEBUG( "CEapTtlsPapActive::StartPapChallengeMsgDialog() \
       
   506 				ERROR: data pointer is NULL." );
       
   507 		return;
       
   508 		}	
       
   509 
       
   510 	TPtrC16 ptr = iSrvChallengeUnicode->Des();
       
   511 	iNotifierDataToUser->iSrvChallengeSize = ptr.Size(); // number of bytes
       
   512 			
       
   513 	iNotifierDataToUser->iState = TPapUiNotifierInfo::
       
   514 	    EPapUiNotifierPapChallengeMsgDialog;
       
   515 	
       
   516 	// set srv challenge
       
   517 	iNotifierDataToUser->iPapChallenge.Copy( *iSrvChallengeUnicode);
       
   518 	iNotifier.StartNotifierAndGetResponse( 
       
   519         iStatus,
       
   520         KPapNotifierUid,
       
   521         *iNotifierDataPckgToUser,
       
   522         *iNotifierDataPckgFromUser );
       
   523 	
       
   524 	} // CEapTtlsPapActive::StartPapChallengeMsgDialog()
       
   525 
       
   526 
       
   527 // ---------------------------------------------------------
       
   528 // CEapTtlsPapActive::CompletePapChallengeMsgDialog()
       
   529 // ---------------------------------------------------------
       
   530 // 
       
   531 void CEapTtlsPapActive::CompletePapChallengeMsgDialog()
       
   532 	{
       
   533 	DEBUG( "CEapTtlsPapActive::CompletePapChallengeMsgDialog()" );
       
   534 
       
   535 	// display query dialog
       
   536 	Start( EEapTtlsPapActiveShowPapChallengeReplyQueryDialog );
       
   537 
       
   538 	} // CEapTtlsPapActive::CompletePapChallengeMsgDialog()
       
   539 
       
   540 
       
   541 // ---------------------------------------------------------
       
   542 // CEapTtlsPapActive::StartPapChallengeReplyQueryDialog()
       
   543 // ---------------------------------------------------------
       
   544 // 
       
   545 void CEapTtlsPapActive::StartPapChallengeReplyQueryDialog()
       
   546 	{
       
   547 	DEBUG( "CEapTtlsPapActive::StartPapChallengeReplyQueryDialog()" );
       
   548 	
       
   549 	if ( iNotifierDataPckgToUser == NULL ||
       
   550 		 iNotifierDataPckgFromUser == NULL ||
       
   551 		 iNotifierDataToUser == NULL ||
       
   552 		 iNotifierDataFromUser == NULL )
       
   553         {
       
   554 		DEBUG( "CEapTtlsPapActive::StartPapChallengeMsgDialog() \
       
   555 			ERROR: data pointer is NULL." );
       
   556 		return;
       
   557 		}
       
   558 
       
   559 	iNotifierDataToUser->iState = TPapUiNotifierInfo::
       
   560 	    EPapUiNotifierPapChallengeReplyQueryDialog;
       
   561 
       
   562 	iNotifier.StartNotifierAndGetResponse( 
       
   563 	    iStatus,
       
   564 	    KPapNotifierUid,
       
   565 	    *iNotifierDataPckgToUser,
       
   566 		*iNotifierDataPckgFromUser );
       
   567 	
       
   568 	} // CEapTtlsPapActive::StartPapChallengeReplyQueryDialog()
       
   569 
       
   570 
       
   571 // ---------------------------------------------------------
       
   572 // CEapTtlsPapActive::CompletePapChallengeMsgDialog()
       
   573 // ---------------------------------------------------------
       
   574 // 
       
   575 void CEapTtlsPapActive::CompletePapChallengeReplyQueryDialog()
       
   576 	{
       
   577 	DEBUG( "CEapTtlsPapActive::CompletePapChallengeReplyQueryDialog()" );
       
   578 	
       
   579     if ( iStatus == KErrNone )
       
   580     	{
       
   581     	iUserAction = EPapNotifierUserActionOk;
       
   582     	}
       
   583     else if ( iStatus == KErrCancel )
       
   584 		{
       
   585 		iUserAction = EPapNotifierUserActionCancel;	
       
   586 		}		
       
   587 	else
       
   588 		{
       
   589 	    DEBUG1( "CEapTtlsPapActive::CompletePapChallengeReplyQueryDialog() \
       
   590 	        ERROR: iStatus=%d", iStatus.Int() );
       
   591 		return;
       
   592 		}
       
   593     DEBUG1( "CEapTtlsPapActive::CompletePapChallengeReplyQueryDialog() \
       
   594         iUserAction=%d", iStatus.Int() );   
       
   595 	
       
   596 	if ( !iCaller )
       
   597 		{
       
   598 		DEBUG( "CEapTtlsPapActive::CompletePapChallengeReplyQueryDialog() \
       
   599 	        ERROR: iCaller==NULL." );
       
   600 		return;
       
   601 		}
       
   602 	if ( !iNotifierDataFromUser )
       
   603 		{
       
   604 		DEBUG( "CEapTtlsPapActive::CompletePapChallengeReplyQueryDialog() \
       
   605             ERROR: iNotifierDataFromUser==NULL." );		
       
   606 		return;
       
   607 		}
       
   608 	if ( iUserAction == EPapNotifierUserActionOk )
       
   609 		{
       
   610 		// update password with user challenge reply
       
   611 		iTtlsPapDbInfo.iUsrPwdInfo.iPassword = iNotifierDataFromUser->
       
   612 		    iUsrPwdInfo.iPassword;			
       
   613 		
       
   614         // convert from unicode to utf8
       
   615 		TBuf8<KMaxPapUserNameLength> userNameUtf8;
       
   616     	CnvUtfConverter::ConvertFromUnicodeToUtf8( userNameUtf8,
       
   617    			iTtlsPapDbInfo.iUsrPwdInfo.iUserName ); 	
       
   618     	EAP_TRACE_DATA_DEBUG( iAmTools, TRACE_FLAGS_DEFAULT, (
       
   619     		EAPL( "userNameUtf8" ),
       
   620     		userNameUtf8.Ptr(),
       
   621     		userNameUtf8.Size() ) );
       
   622 
       
   623     	TBuf8<KMaxPapPasswordLength> passwordUtf8;
       
   624     	CnvUtfConverter::ConvertFromUnicodeToUtf8( passwordUtf8,
       
   625     		iNotifierDataFromUser->iUsrPwdInfo.iPassword );   	
       
   626     	EAP_TRACE_DATA_DEBUG( iAmTools, TRACE_FLAGS_DEFAULT, (
       
   627     		EAPL( "passwordUtf8" ),
       
   628     		passwordUtf8.Ptr(),
       
   629     		passwordUtf8.Size() ) );
       
   630    	
       
   631     	// complete query with user name and password from UI
       
   632     	iCaller->CompleteQueryTtlsPapUserNameAndPassword(
       
   633         	eap_status_ok, userNameUtf8, passwordUtf8 );
       
   634 		}
       
   635   	else //if (userAction == EPapNotifierUserActionCancel)
       
   636   		{
       
   637   		// user name and password are not used
       
   638 		iCaller->CompleteQueryTtlsPapUserNameAndPassword(
       
   639 			eap_status_user_cancel_authentication,
       
   640 			KNullDesC8(),
       
   641 			KNullDesC8() );
       
   642   		} 
       
   643 	} // CEapTtlsPapActive::CompletePapChallengeReplyQueryDialog()
       
   644 
       
   645 
       
   646 // ================= private: new, other =======================
       
   647 
       
   648 
       
   649 // ---------------------------------------------------------
       
   650 // CEapTtlsPapActive::GetCurrentTime()
       
   651 // ---------------------------------------------------------
       
   652 // 
       
   653 TInt64 CEapTtlsPapActive::GetCurrentTime()
       
   654 	{
       
   655 	DEBUG( "CEapTtlsPapActive::GetCurrentTime()" );
       
   656 	
       
   657 	TTime currentTime;
       
   658 	currentTime.UniversalTime();
       
   659 		
       
   660 #if defined(_DEBUG) || defined(DEBUG)	
       
   661 	
       
   662 	TDateTime currentDateTime = currentTime.DateTime();
       
   663 	
       
   664 	EAP_TRACE_DEBUG( iAmTools, TRACE_FLAGS_DEFAULT,
       
   665 	(EAPL("eap_am_type_tls_peap_symbian_c::GetCurrentTime(), %2d-%2d-%4d : %2d-%2d-%2d-%d\n"), 
       
   666 	currentDateTime.Day()+1, currentDateTime.Month()+1,currentDateTime.Year(), currentDateTime.Hour(),
       
   667 	currentDateTime.Minute(), currentDateTime.Second(), currentDateTime.MicroSecond()));
       
   668 
       
   669 #endif
       
   670 
       
   671 	return currentTime.Int64();
       
   672 	}
       
   673 
       
   674 // ---------------------------------------------------------
       
   675 // CEapTtlsPapActive::Clean()
       
   676 // ---------------------------------------------------------
       
   677 // 
       
   678 void CEapTtlsPapActive::Clean()
       
   679 	{
       
   680     DEBUG( "CEapTtlsPapActive::Clean() IN" );
       
   681     
       
   682     iCancelCalled = ETrue;
       
   683 
       
   684     DEBUG( "CEapTtlsPapActive::Clean() iActiveState set to EEapTtlsPapActiveStatesNumber" );
       
   685     iActiveState = EEapTtlsPapActiveStatesNumber;
       
   686     
       
   687 	DEBUG( "CEapFastActive::Clean() close notifier." );
       
   688 	iNotifier.Close();
       
   689 
       
   690     DEBUG( "CEapTtlsPapActive::Clean() delete iNotifierDataToUser." );
       
   691     delete iNotifierDataToUser;
       
   692     iNotifierDataToUser = NULL;
       
   693     
       
   694     DEBUG( "CEapTtlsPapActive::Clean() delete iNotifierDataPckgToUser." );
       
   695     delete iNotifierDataPckgToUser;	
       
   696     iNotifierDataPckgToUser = NULL;
       
   697     
       
   698     DEBUG( "CEapTtlsPapActive::Clean() delete iNotifierDataFromUser." );
       
   699 	delete iNotifierDataFromUser;
       
   700 	iNotifierDataFromUser = NULL;
       
   701 
       
   702 	DEBUG( "CEapTtlsPapActive::Clean() delete iNotifierDataFromUser." );
       
   703 	delete iNotifierDataPckgFromUser;
       
   704 	iNotifierDataPckgFromUser = NULL;
       
   705 	
       
   706     DEBUG( "CEapTtlsPapActive::Clean() OUT." );	
       
   707 	}
       
   708 
       
   709 // ================= private: private constructors =======================
       
   710 
       
   711 // ---------------------------------------------------------
       
   712 // CEapTtlsPapActive::CEapTtlsPapActive()
       
   713 // ---------------------------------------------------------
       
   714 //
       
   715 CEapTtlsPapActive::CEapTtlsPapActive(
       
   716 	eap_am_type_tls_peap_symbian_c* aCaller,
       
   717 	eap_am_tools_symbian_c* aAmTools )
       
   718     :
       
   719 	CActive( CActive::EPriorityStandard ),
       
   720     iAmTools( aAmTools ),
       
   721 	iCaller( aCaller ),
       
   722     //iPartner( aPartner ),
       
   723     iActiveState( EEapTtlsPapActiveStatesNumber ),
       
   724     iNotifier(),
       
   725     iNotifierDataToUser( NULL ),
       
   726 	iNotifierDataPckgToUser( NULL ),	
       
   727 	iNotifierDataFromUser( NULL ),
       
   728 	iNotifierDataPckgFromUser( NULL ),
       
   729 	iUserAction( EPapNotifierUserActionCancel ),
       
   730 	iSrvChallengeUnicode( NULL ),
       
   731 	iRequestStatus( NULL ),
       
   732 	iIsTtlsPapDbInfoInitialized( EFalse ),
       
   733 	iCancelCalled( EFalse )
       
   734     {
       
   735     DEBUG( "CEapTtlsPapActive::CEapTtlsPapActive()" );
       
   736     }
       
   737 	
       
   738 // ---------------------------------------------------------
       
   739 // CEapTtlsPapActive::ConstructL()
       
   740 // ---------------------------------------------------------
       
   741 //
       
   742 void CEapTtlsPapActive::ConstructL()
       
   743     {
       
   744 	DEBUG( "CEapTtlsPapActive::ConstructL()" );
       
   745 	CActiveScheduler::Add( this );
       
   746 	
       
   747     DEBUG( "CEapTtlsPapActive::ConstructL() connecting to notifier server");
       
   748     TInt err = iNotifier.Connect();
       
   749     if ( err != KErrNone )
       
   750         {
       
   751         DEBUG1( "CEapTtlsPapActive::Start() ERROR: Failed to connect to notifier server, err=%d",
       
   752 	        err );
       
   753         return;
       
   754         }
       
   755     if ( !iNotifierDataToUser )
       
   756     	{
       
   757     	iNotifierDataToUser = new(ELeave) TPapUiNotifierInfo;	
       
   758     	}
       
   759 	if ( !iNotifierDataPckgToUser )
       
   760 		{
       
   761 		iNotifierDataPckgToUser = new(ELeave) TPckg<TPapUiNotifierInfo> (*iNotifierDataToUser);	
       
   762 		}
       
   763 	if ( !iNotifierDataFromUser )
       
   764 		{
       
   765 		iNotifierDataFromUser = new(ELeave) TPapUiNotifierInfo;
       
   766 		}
       
   767 	if ( !iNotifierDataPckgFromUser )
       
   768 		{
       
   769 		iNotifierDataPckgFromUser = new(ELeave) TPckg<TPapUiNotifierInfo> (*iNotifierDataFromUser);			
       
   770 		}	
       
   771     }
       
   772 
       
   773 // End of File