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