eapol/eapol_framework/eapol_symbian/am/type/mschapv2/symbian/eap_am_type_mschapv2_symbian.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
equal deleted inserted replaced
45:bad0cc58d154 46:c74b3d9f6b9e
    14 * Description:  EAP and WLAN authentication protocols.
    14 * Description:  EAP and WLAN authentication protocols.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 34 %
    19 * %version: 33 %
    20 */
    20 */
    21 
    21 
    22 // This is enumeration of EAPOL source code.
    22 // This is enumeration of EAPOL source code.
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    24 	#undef EAP_FILE_NUMBER_ENUM
    24 	#undef EAP_FILE_NUMBER_ENUM
    40 #include "EapMsChapV2DbDefaults.h"
    40 #include "EapMsChapV2DbDefaults.h"
    41 #include "EapMsChapV2DbUtils.h"
    41 #include "EapMsChapV2DbUtils.h"
    42 #include "EapMsChapV2NotifierUids.h"
    42 #include "EapMsChapV2NotifierUids.h"
    43 #include "eap_state_notification.h"
    43 #include "eap_state_notification.h"
    44 
    44 
    45 #include "EapTraceSymbian.h"
    45 #include "eap_am_trace_symbian.h"
    46 
    46 
    47 const TUint KMaxSqlQueryLength = 256;
    47 const TUint KMaxSqlQueryLength = 256;
    48 const TUint KMaxDBFieldNameLength = 255;
    48 const TUint KMaxDBFieldNameLength = 255;
    49 const char EAP_MSCHAPV2_CREDENTIAL_HANDLE_KEY[] = "eap_type_mschapv2_c credential_store";
    49 const char EAP_MSCHAPV2_CREDENTIAL_HANDLE_KEY[] = "eap_type_mschapv2_c credential_store";
    50 const TInt 	KDefaultColumnInView_One = 1; // For DB view.
    50 const TInt 	KDefaultColumnInView_One = 1; // For DB view.
    68 	m_session.Close();
    68 	m_session.Close();
    69 
    69 
    70 	delete m_username_password_io_ptr;
    70 	delete m_username_password_io_ptr;
    71 	delete m_username_password_io_pckg_ptr;
    71 	delete m_username_password_io_pckg_ptr;
    72 
    72 
    73 	if (iEapAuthNotifier != 0)
       
    74 		{
       
    75 		delete iEapAuthNotifier;
       
    76 		iEapAuthNotifier = 0;
       
    77 		}
       
    78 
       
    79 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
    73 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
    80 }
    74 }
    81 
    75 
    82 //--------------------------------------------------
    76 //--------------------------------------------------
    83 
    77 
    89 		m_am_tools, 
    83 		m_am_tools, 
    90 		TRACE_FLAGS_DEFAULT, 
    84 		TRACE_FLAGS_DEFAULT, 
    91 		(EAPL("eap_am_type_mschapv2_symbian_c::shutdown(): this = 0x%08x\n"),
    85 		(EAPL("eap_am_type_mschapv2_symbian_c::shutdown(): this = 0x%08x\n"),
    92 		this));
    86 		this));
    93 		
    87 		
    94 
    88 	if( IsActive() )
    95 
    89 	{
    96 
    90 		Cancel(); // Cancel only if active.
       
    91 	}  
       
    92 	else
       
    93 	{
       
    94 		if( m_is_notifier_connected )
       
    95 		{
       
    96 		
       
    97 		EAP_TRACE_DEBUG(
       
    98 			m_am_tools, 
       
    99 			TRACE_FLAGS_DEFAULT, 
       
   100 			(EAPL("eap_am_type_mschapv2_symbian_c::shutdown - calling m_notifier.CancelNotifier(..)\n")));
       
   101 			
       
   102 		TInt error = KErrNone;			
       
   103 		EAP_UNREFERENCED_PARAMETER(error);
       
   104 		error = m_notifier.CancelNotifier(KEapMsChapV2UsernamePasswordUid);
       
   105 	
       
   106 		EAP_TRACE_DEBUG(
       
   107 			m_am_tools, 
       
   108 			TRACE_FLAGS_DEFAULT, 
       
   109 			(EAPL("eap_am_type_mschapv2_symbian_c::shutdown - calling m_notifier.Close(), prev error=%d\n"),
       
   110 			error));
       
   111 		
       
   112 		m_notifier.Close(); // Call close only if it is connected.	
       
   113 		
       
   114 		m_is_notifier_connected = false;
       
   115 		}
       
   116 	}
       
   117 	
    97 	m_shutdown_was_called = true;
   118 	m_shutdown_was_called = true;
    98 
   119 
    99 	EAP_TRACE_DEBUG(
   120 	EAP_TRACE_DEBUG(
   100 		m_am_tools, 
   121 		m_am_tools, 
   101 		TRACE_FLAGS_DEFAULT, 
   122 		TRACE_FLAGS_DEFAULT, 
   133 , m_index(aIndex)
   154 , m_index(aIndex)
   134 , m_tunneling_type(aTunnelingType)
   155 , m_tunneling_type(aTunnelingType)
   135 , m_is_client(aIsClient)
   156 , m_is_client(aIsClient)
   136 , m_is_valid(false)
   157 , m_is_valid(false)
   137 , m_shutdown_was_called(false)
   158 , m_shutdown_was_called(false)
   138 
   159 , m_is_notifier_connected(false)
   139 , m_max_session_time(0)
   160 , m_max_session_time(0)
   140 	, iEapAuthNotifier(0)	
       
   141 
       
   142 
       
   143 {
   161 {
   144 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   162 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   145 	
   163 	
       
   164 #ifdef USE_EAP_EXPANDED_TYPES
       
   165 
       
   166 	m_tunneling_vendor_type = m_tunneling_type.get_vendor_type();
       
   167 
       
   168 #else
       
   169 
       
   170 	m_tunneling_vendor_type = static_cast<TUint>(m_tunneling_type);
       
   171 
       
   172 #endif //#ifdef USE_EAP_EXPANDED_TYPES	
       
   173 
   146 	if (receive_network_id != 0
   174 	if (receive_network_id != 0
   147 		&& receive_network_id->get_is_valid_data() == true)
   175 		&& receive_network_id->get_is_valid_data() == true)
   148 	{
   176 	{
   149 		eap_status_e status = m_receive_network_id.set_copy_of_network_id(
   177 		eap_status_e status = m_receive_network_id.set_copy_of_network_id(
   150 			receive_network_id);
   178 			receive_network_id);
   199 
   227 
   200 void eap_am_type_mschapv2_symbian_c::ConstructL()
   228 void eap_am_type_mschapv2_symbian_c::ConstructL()
   201 {
   229 {
   202 	// NOTE: Do not use m_partner here without null check
   230 	// NOTE: Do not use m_partner here without null check
   203 
   231 
   204 	TInt error = m_session.Connect();
       
   205 	EAP_TRACE_DEBUG_SYMBIAN((_L("eap_am_type_mschapv2_symbian_c::ConstructL(): - m_session.Connect(), error=%d\n"), error));
       
   206 	User::LeaveIfError(error);
       
   207 
       
   208 	// Open/create the database
   232 	// Open/create the database
   209 	EapMsChapV2DbUtils::OpenDatabaseL(m_database, m_session, m_index_type, m_index, m_tunneling_type);
   233 	EapMsChapV2DbUtils::OpenDatabaseL(m_database, m_session, m_index_type, m_index, m_tunneling_type);
   210 
   234 
   211 	m_username_password_io_ptr = new(ELeave) CEapAuthNotifier::TEapDialogInfo;
   235 	m_username_password_io_ptr = new(ELeave) TEapMsChapV2UsernamePasswordInfo;
   212 	m_username_password_io_pckg_ptr = new(ELeave) TPckg<CEapAuthNotifier::TEapDialogInfo> (*m_username_password_io_ptr);
   236 	m_username_password_io_pckg_ptr = new(ELeave) TPckg<TEapMsChapV2UsernamePasswordInfo> (*m_username_password_io_ptr);
   213 
   237 
   214 	CActiveScheduler::Add(this);
   238 	CActiveScheduler::Add(this);
   215 
   239 
   216 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   240 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   217 }
   241 }
   263 
   287 
   264 	m_partner->state_notification(&notification);
   288 	m_partner->state_notification(&notification);
   265 }
   289 }
   266 
   290 
   267 //--------------------------------------------------
   291 //--------------------------------------------------
   268 EAP_FUNC_EXPORT void eap_am_type_mschapv2_symbian_c::DlgComplete( TInt aStatus )
   292 
   269 	{
   293 void eap_am_type_mschapv2_symbian_c::RunL()
   270 	if (aStatus == KErrCancel)
   294 {
   271 		{
   295 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   296 	
       
   297 	EAP_TRACE_DEBUG(
       
   298 		m_am_tools,
       
   299 		TRACE_FLAGS_DEFAULT,
       
   300 		(EAPL("eap_am_type_mschapv2_symbian_c::RunL - start")
       
   301 		 EAPL("m_state, iStatus.Int()=%d\n"),
       
   302 		 m_state, iStatus.Int()));
       
   303 
       
   304 	if (iStatus.Int() == KErrCancel)
       
   305 	{
   272 		EAP_TRACE_DEBUG(
   306 		EAP_TRACE_DEBUG(
   273 			m_am_tools, 
   307 			m_am_tools, 
   274 			TRACE_FLAGS_DEFAULT, 
   308 			TRACE_FLAGS_DEFAULT, 
   275 			(EAPL("eap_am_type_mschapv2_symbian_c::RunL - User seems to have cancelled the prompt. Stop Immediately.\n")));
   309 			(EAPL("eap_am_type_mschapv2_symbian_c::RunL - User seems to have cancelled the prompt. Stop Immediately.\n")));
   276 		
   310 		
   278 		// Appropriate error notification is sent from finish_unsuccessful_authentication.
   312 		// Appropriate error notification is sent from finish_unsuccessful_authentication.
   279 		get_am_partner()->finish_unsuccessful_authentication(true);
   313 		get_am_partner()->finish_unsuccessful_authentication(true);
   280 		
   314 		
   281 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   315 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   282 		return;
   316 		return;
   283 		}
   317 	}
   284 
   318 
   285 	if (aStatus != KErrNone)
   319 	if (iStatus.Int() != KErrNone)
   286 		{
   320 	{
   287 		// Something is very wrong...
   321 		// Something is very wrong...
   288 		EAP_TRACE_ERROR(
   322 		EAP_TRACE_ERROR(
   289 			m_am_tools,
   323 			m_am_tools,
   290 			TRACE_FLAGS_DEFAULT,
   324 			TRACE_FLAGS_DEFAULT,
   291 			(EAPL("ERROR: EAP - MS-Chap-V2 notifier or dialog, aStatus=%d\n"), aStatus));
   325 			(EAPL("ERROR: EAP - MS-Chap-V2 notifier or dialog, iStatus.Int()=%d\n"), iStatus.Int()));
   292 
   326 
   293 		send_error_notification(eap_status_authentication_failure);
   327 		send_error_notification(eap_status_authentication_failure);
   294 
   328 
   295 		get_am_partner()->finish_unsuccessful_authentication(false);
   329 		get_am_partner()->finish_unsuccessful_authentication(false);
   296 
   330 
   297 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   331 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   298 		return;
   332 		return;
   299 		}
   333 	}
   300 
   334 
   301 	eap_status_e status(eap_status_ok);
   335 	eap_status_e status(eap_status_ok);
   302 
   336 
   303 	switch (m_state)
   337 	switch (m_state)
   304 		{
   338 	{
   305 		case EHandlingUsernamePasswordQuery:
   339 	case EHandlingUsernamePasswordQuery:
   306 			{
   340 		{
   307 			if (m_username_password_io_ptr->iPasswordPromptEnabled)
   341 			if (m_username_password_io_ptr->iPasswordPromptEnabled)
   308 				{
   342 			{
   309 				*m_password_prompt_enabled = true;
   343 				*m_password_prompt_enabled = true;
   310 				}
   344 			}
   311 			else
   345 			else
   312 				{
   346 			{
   313 				*m_password_prompt_enabled = false;
   347 				*m_password_prompt_enabled = false;
   314 				}
   348 			}
   315 
   349 
   316 				{
   350 			{
   317 				eap_variable_data_c tmp_username_unicode(
   351 				eap_variable_data_c tmp_username_unicode(
   318 					m_am_tools);
   352 					m_am_tools);
   319 
   353 
   320 				status = tmp_username_unicode.set_buffer(
   354 				status = tmp_username_unicode.set_buffer(
   321 					m_username_password_io_ptr->iUsername.Ptr(),
   355 					m_username_password_io_ptr->iUsername.Ptr(),
   322 					m_username_password_io_ptr->iUsername.Size(),
   356 					m_username_password_io_ptr->iUsername.Size(),
   323 					false,
   357 					false,
   324 					false);
   358 					false);
   325 				if (status != eap_status_ok)
   359 				if (status != eap_status_ok)
   326 					{
   360 				{
   327 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   361 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   328 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   362 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   329 					return;
   363 					return;
   330 					}
   364 				}
   331 
   365 
   332 				eap_variable_data_c tmp_username_utf8(m_am_tools);
   366 				eap_variable_data_c tmp_username_utf8(m_am_tools);
   333 				status = m_am_tools->convert_unicode_to_utf8(tmp_username_utf8, tmp_username_unicode);
   367 				status = m_am_tools->convert_unicode_to_utf8(tmp_username_utf8, tmp_username_unicode);
   334 				if (status != eap_status_ok)
   368 				if (status != eap_status_ok)
   335 					{
   369 				{
   336 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   370 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   337 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   371 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   338 					return;
   372 					return;
   339 					}
   373 				}
   340 
   374 
   341 				status = m_username_utf8->set_copy_of_buffer(&tmp_username_utf8);
   375 				status = m_username_utf8->set_copy_of_buffer(&tmp_username_utf8);
   342 				if (status != eap_status_ok)
   376 				if (status != eap_status_ok)
   343 					{
   377 				{
   344 					get_am_partner()->finish_unsuccessful_authentication(false);
   378 					get_am_partner()->finish_unsuccessful_authentication(false);
   345 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   379 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   346 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   380 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   347 					return;
   381 					return;
   348 					}
       
   349 				}
   382 				}
   350 
   383 			}
   351 				{
   384 
       
   385 			{
   352 				eap_variable_data_c tmp_password_unicode(
   386 				eap_variable_data_c tmp_password_unicode(
   353 					m_am_tools);
   387 					m_am_tools);
   354 
   388 
   355 				status = tmp_password_unicode.set_buffer(
   389 				status = tmp_password_unicode.set_buffer(
   356 					m_username_password_io_ptr->iPassword.Ptr(),
   390 					m_username_password_io_ptr->iPassword.Ptr(),
   357 					m_username_password_io_ptr->iPassword.Size(),
   391 					m_username_password_io_ptr->iPassword.Size(),
   358 					false,
   392 					false,
   359 					false);
   393 					false);
   360 				if (status != eap_status_ok)
   394 				if (status != eap_status_ok)
   361 					{
   395 				{
   362 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   396 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   363 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   397 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   364 					return;
   398 					return;
   365 					}
   399 				}
   366 
   400 
   367 				eap_variable_data_c tmp_password_utf8(m_am_tools);
   401 				eap_variable_data_c tmp_password_utf8(m_am_tools);
   368 				status = m_am_tools->convert_unicode_to_utf8(tmp_password_utf8, tmp_password_unicode);
   402 				status = m_am_tools->convert_unicode_to_utf8(tmp_password_utf8, tmp_password_unicode);
   369 				if (status != eap_status_ok)
   403 				if (status != eap_status_ok)
   370 					{
   404 				{
   371 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   405 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   372 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   406 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   373 					return;
   407 					return;
   374 					}
   408 				}
   375 
   409 
   376 				status = m_password_utf8->set_copy_of_buffer(&tmp_password_utf8);
   410 				status = m_password_utf8->set_copy_of_buffer(&tmp_password_utf8);
   377 				if (status != eap_status_ok)
   411 				if (status != eap_status_ok)
   378 					{
   412 				{
   379 					get_am_partner()->finish_unsuccessful_authentication(false);
   413 					get_am_partner()->finish_unsuccessful_authentication(false);
   380 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   414 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   381 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   415 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   382 					return;
   416 					return;
   383 					}
       
   384 				}
   417 				}
       
   418 			}
   385 
   419 
   386 			// Store username and/or password if "Prompt for username" is enabled
   420 			// Store username and/or password if "Prompt for username" is enabled
   387 			status = update_username_password();
   421 			status = update_username_password();
   388 			if (status != eap_status_ok)
   422 			if (status != eap_status_ok)
   389 				{
   423 			{
   390 				get_am_partner()->finish_unsuccessful_authentication(false);
   424 				get_am_partner()->finish_unsuccessful_authentication(false);
   391 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   425 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   392 				return;
   426 				return;
   393 				}
   427 			}
   394 
   428 
   395 			if (m_is_identity_query)
   429 			if (m_is_identity_query)
   396 				{
   430 			{
   397 				status = get_am_partner()->complete_eap_identity_query();
   431 				status = get_am_partner()->complete_eap_identity_query();
   398 				}
   432 			}
   399 			else
   433 			else
   400 				{
   434 			{
   401 				status = get_am_partner()->complete_failure_retry_response();
   435 				status = get_am_partner()->complete_failure_retry_response();
   402 				}
   436 			}
   403 			}
   437 		}
   404 		break;
   438 		break;
   405 
   439 
   406 	case EHandlingChangePasswordQuery:
   440 	case EHandlingChangePasswordQuery:
   407 		{
   441 		{
   408 				{
   442 			{
   409 				eap_variable_data_c tmp_password_unicode(
   443 				eap_variable_data_c tmp_password_unicode(
   410 					m_am_tools);
   444 					m_am_tools);
   411 
   445 
   412 				status = tmp_password_unicode.set_buffer(
   446 				status = tmp_password_unicode.set_buffer(
   413 					m_username_password_io_ptr->iPassword.Ptr(),
   447 					m_username_password_io_ptr->iPassword.Ptr(),
   414 					m_username_password_io_ptr->iPassword.Size(),
   448 					m_username_password_io_ptr->iPassword.Size(),
   415 					false,
   449 					false,
   416 					false);
   450 					false);
   417 				if (status != eap_status_ok)
   451 				if (status != eap_status_ok)
   418 					{
   452 				{
   419 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   453 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   420 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   454 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   421 					return;
   455 					return;
   422 					}
   456 				}
   423 
   457 
   424 				eap_variable_data_c tmp_password_utf8(m_am_tools);
   458 				eap_variable_data_c tmp_password_utf8(m_am_tools);
   425 				status = m_am_tools->convert_unicode_to_utf8(tmp_password_utf8, tmp_password_unicode);
   459 				status = m_am_tools->convert_unicode_to_utf8(tmp_password_utf8, tmp_password_unicode);
   426 				if (status != eap_status_ok)
   460 				if (status != eap_status_ok)
   427 					{
   461 				{
   428 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   462 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   429 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   463 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   430 					return;
   464 					return;
   431 					}
   465 				}
   432 
   466 
   433 				eap_status_e status = m_password_utf8->set_copy_of_buffer(&tmp_password_utf8);
   467 				eap_status_e status = m_password_utf8->set_copy_of_buffer(&tmp_password_utf8);
   434 				if (status != eap_status_ok)
   468 				if (status != eap_status_ok)
   435 					{
   469 				{
   436 					get_am_partner()->finish_unsuccessful_authentication(false);
   470 					get_am_partner()->finish_unsuccessful_authentication(false);
   437 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   471 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   438 					return;
   472 					return;
   439 					}
       
   440 				}
   473 				}
   441 
   474 			}
   442 				{
   475 
       
   476 			{
   443 				eap_variable_data_c tmp_old_password_unicode(
   477 				eap_variable_data_c tmp_old_password_unicode(
   444 					m_am_tools);
   478 					m_am_tools);
   445 
   479 
   446 				status = tmp_old_password_unicode.set_buffer(
   480 				status = tmp_old_password_unicode.set_buffer(
   447 					m_username_password_io_ptr->iOldPassword.Ptr(),
   481 					m_username_password_io_ptr->iOldPassword.Ptr(),
   448 					m_username_password_io_ptr->iOldPassword.Size(),
   482 					m_username_password_io_ptr->iOldPassword.Size(),
   449 					false,
   483 					false,
   450 					false);
   484 					false);
   451 				if (status != eap_status_ok)
   485 				if (status != eap_status_ok)
   452 					{
   486 				{
   453 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   487 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   454 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   488 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   455 					return;
   489 					return;
   456 					}
   490 				}
   457 
   491 
   458 				eap_variable_data_c tmp_old_password_utf8(m_am_tools);
   492 				eap_variable_data_c tmp_old_password_utf8(m_am_tools);
   459 				status = m_am_tools->convert_unicode_to_utf8(tmp_old_password_utf8, tmp_old_password_unicode);
   493 				status = m_am_tools->convert_unicode_to_utf8(tmp_old_password_utf8, tmp_old_password_unicode);
   460 				if (status != eap_status_ok)
   494 				if (status != eap_status_ok)
   461 					{
   495 				{
   462 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   496 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   463 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   497 					(void) EAP_STATUS_RETURN(m_am_tools, status);
   464 					return;
   498 					return;
   465 					}
   499 				}
   466 
   500 
   467 				status = m_old_password_utf8->set_copy_of_buffer(&tmp_old_password_utf8);
   501 				status = m_old_password_utf8->set_copy_of_buffer(&tmp_old_password_utf8);
   468 				if (status != eap_status_ok)
   502 				if (status != eap_status_ok)
   469 					{
   503 				{
   470 					get_am_partner()->finish_unsuccessful_authentication(false);
   504 					get_am_partner()->finish_unsuccessful_authentication(false);
   471 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   505 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   472 					return;
   506 					return;
   473 					}
       
   474 				}
   507 				}
       
   508 			}
   475 
   509 
   476 			status = get_am_partner()->complete_change_password_query();
   510 			status = get_am_partner()->complete_change_password_query();
   477 			}
   511 		}
   478 		break;
   512 		break;
   479 
   513 
   480 	default:
   514 	default:
   481 		EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: EAP - MS-Chap-V2 illegal state in RunL.\n")));
   515 		EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: EAP - MS-Chap-V2 illegal state in RunL.\n")));
   482 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   516 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   483 		return;		
   517 		return;		
   484 
   518 	}
   485 		}
   519 
   486 	}
   520 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   487 
   521 }
   488 //--------------------------------------------------
   522 
   489 
   523 //--------------------------------------------------
   490 void eap_am_type_mschapv2_symbian_c::RunL()
   524 
   491 {
   525 void eap_am_type_mschapv2_symbian_c::DoCancel()
   492 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   526 {
   493 	
   527 	if( m_is_notifier_connected )
       
   528 	{
   494 	EAP_TRACE_DEBUG(
   529 	EAP_TRACE_DEBUG(
   495 		m_am_tools,
   530 		m_am_tools, 
   496 		TRACE_FLAGS_DEFAULT,
   531 		TRACE_FLAGS_DEFAULT, 
   497 		(EAPL("eap_am_type_mschapv2_symbian_c::RunL - start")
   532 		(EAPL("eap_am_type_mschapv2_symbian_c::DoCancel - calling m_notifier.CancelNotifier(..)\n")));
   498 		 EAPL("m_state, iStatus.Int()=%d\n"),
   533 			
   499 		 m_state, iStatus.Int()));
   534 		TInt error = KErrNone;
   500 
   535 		EAP_UNREFERENCED_PARAMETER(error);
   501 
   536 		error = m_notifier.CancelNotifier(KEapMsChapV2UsernamePasswordUid);
   502 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
   537 
   503 }
   538 	EAP_TRACE_DEBUG(
   504 
   539 		m_am_tools, 
   505 //--------------------------------------------------
   540 		TRACE_FLAGS_DEFAULT, 
   506 
   541 		(EAPL("eap_am_type_mschapv2_symbian_c::DoCancel - calling m_notifier.Close(), prev error=%d\n"),
   507 void eap_am_type_mschapv2_symbian_c::DoCancel()
   542 		error));
   508 {
   543 		
   509 	if (iEapAuthNotifier != 0)
   544 		m_notifier.Close(); // Call close only if it is connected.	
   510 		{
   545 		
   511 		iEapAuthNotifier->Cancel();
   546 		m_is_notifier_connected = false;
   512 		}
   547 	}
   513 
   548 }
   514 
       
   515 	}
       
   516 
   549 
   517 //--------------------------------------------------
   550 //--------------------------------------------------
   518 
   551 
   519 
   552 
   520 EAP_FUNC_EXPORT eap_status_e eap_am_type_mschapv2_symbian_c::type_configure_read(
   553 EAP_FUNC_EXPORT eap_status_e eap_am_type_mschapv2_symbian_c::type_configure_read(
   569 			
   602 			
   570 	// Now do the database query
   603 	// Now do the database query
   571 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   604 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   572 	TPtr sqlStatement = buf->Des();
   605 	TPtr sqlStatement = buf->Des();
   573 
   606 
   574 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   607 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   575 	sqlStatement.Format(
   608 	sqlStatement.Format(KSQLQueryRow,
   576 		KSQLQueryRow,
   609 						&unicodeString,
   577 		&unicodeString,
   610 						&KMsChapV2TableName,
   578 		&KMsChapV2TableName,
   611 						&KServiceType,
   579 		&KServiceType,
   612 						m_index_type,
   580 		m_index_type,
   613 						&KServiceIndex,
   581 		&KServiceIndex,
   614 						m_index,
   582 		m_index,
   615 						&KTunnelingType, 
   583 		&KTunnelingTypeVendorId,
   616 						m_tunneling_vendor_type);
   584 		m_tunneling_type.get_vendor_id(),
       
   585 		&KTunnelingType, 
       
   586 		m_tunneling_type.get_vendor_type());
       
   587 	
   617 	
   588 	RDbView view;
   618 	RDbView view;
   589 	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   619 	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   590 	CleanupClosePushL(view);
   620 	CleanupClosePushL(view);
   591 	User::LeaveIfError(view.EvaluateAll());	
   621 	User::LeaveIfError(view.EvaluateAll());	
   679 	return status;
   709 	return status;
   680 }
   710 }
   681 
   711 
   682 //--------------------------------------------------
   712 //--------------------------------------------------
   683 
   713 
   684 EAP_FUNC_EXPORT eap_status_e eap_am_type_mschapv2_symbian_c::update_username_password()
   714 eap_status_e eap_am_type_mschapv2_symbian_c::update_username_password()
   685 {
   715 {
   686 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   716 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
   687 	eap_status_e status(eap_status_ok);
   717 	eap_status_e status(eap_status_ok);
   688 	TRAPD(err, type_configure_updateL());
   718 	TRAPD(err, type_configure_updateL());
   689 	if (err != KErrNone) 
   719 	if (err != KErrNone) 
   718 
   748 
   719 	// Now do the database update
   749 	// Now do the database update
   720 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   750 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   721 	TPtr sqlStatement = buf->Des();
   751 	TPtr sqlStatement = buf->Des();
   722 
   752 
   723 	_LIT(KSQLUpdate, "SELECT %S,%S,%S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   753 	_LIT(KSQLUpdate, "SELECT %S,%S,%S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   724 	sqlStatement.Format(
   754 	sqlStatement.Format(KSQLUpdate,
   725 		KSQLUpdate,
   755 						&cf_str_EAP_MSCHAPV2_username_literal,
   726 		&cf_str_EAP_MSCHAPV2_username_literal,
   756 						&cf_str_EAP_MSCHAPV2_password_prompt_literal,
   727 		&cf_str_EAP_MSCHAPV2_password_prompt_literal,
   757 						&cf_str_EAP_MSCHAPV2_password_literal,
   728 		&cf_str_EAP_MSCHAPV2_password_literal,
   758 						&KMsChapV2TableName,
   729 		&KMsChapV2TableName,
   759 						&KServiceType,
   730 		&KServiceType,
   760 						m_index_type,
   731 		m_index_type,
   761 						&KServiceIndex,
   732 		&KServiceIndex,
   762 						m_index,
   733 		m_index,
   763 						&KTunnelingType, 
   734 		&KTunnelingTypeVendorId,
   764 						m_tunneling_vendor_type);
   735 		m_tunneling_type.get_vendor_id(),
       
   736 		&KTunnelingType, 
       
   737 		m_tunneling_type.get_vendor_type());
       
   738 	
   765 	
   739 	RDbView view;
   766 	RDbView view;
   740 	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), RDbView::EUpdatable));
   767 	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), RDbView::EUpdatable));
   741 	CleanupClosePushL(view);
   768 	CleanupClosePushL(view);
   742 
   769 
   792 	}
   819 	}
   793 
   820 
   794 	if (*m_password_prompt_enabled)
   821 	if (*m_password_prompt_enabled)
   795 	{
   822 	{
   796 		// Username and password prompt flag is stored, password is cleared
   823 		// Username and password prompt flag is stored, password is cleared
   797 		view.SetColL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_prompt_literal), EEapDbTrue);
   824 		view.SetColL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_prompt_literal), EMSCHAPV2PasswordPromptOn);
   798 		view.SetColNullL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_literal));
   825 		view.SetColNullL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_literal));
   799 	}
   826 	}
   800 	else
   827 	else
   801 	{
   828 	{
   802 		eap_variable_data_c tmp_password_unicode(m_am_tools);
   829 		eap_variable_data_c tmp_password_unicode(m_am_tools);
   824 			password.Length()));
   851 			password.Length()));
   825 			
   852 			
   826 			User::Leave(KErrArgument);
   853 			User::Leave(KErrArgument);
   827 		}
   854 		}
   828 
   855 
   829 		view.SetColL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_prompt_literal), EEapDbFalse);
   856 		view.SetColL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_prompt_literal), EMSCHAPV2PasswordPromptOff);
   830 
   857 
   831 		// Length is ok. Set the value in DB.			
   858 		// Length is ok. Set the value in DB.			
   832 		view.SetColL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_literal), password);
   859 		view.SetColL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_literal), password);
   833 	}
   860 	}
   834 
   861 
   849 
   876 
   850 	{
   877 	{
   851 		// Read Maximum Session Validity Time from the config file
   878 		// Read Maximum Session Validity Time from the config file
   852 		eap_variable_data_c sessionTimeFromFile(m_am_tools);
   879 		eap_variable_data_c sessionTimeFromFile(m_am_tools);
   853 		
   880 		
   854 		eap_status_e status = type_configure_read(
   881 		eap_status_e status = m_partner->read_configure(
   855 			cf_str_EAP_MSCHAPv2_max_session_validity_time.get_field(),
   882 			cf_str_EAP_MSCHAPv2_max_session_validity_time.get_field(),
   856 			&sessionTimeFromFile);
   883 			&sessionTimeFromFile);
   857 		
   884 		
   858 		if (status == eap_status_ok
   885 		if (status == eap_status_ok
   859 			&& sessionTimeFromFile.get_is_valid_data() == true
   886 			&& sessionTimeFromFile.get_is_valid_data() == true
   887 		eap_variable_data_c & username_utf8,
   914 		eap_variable_data_c & username_utf8,
   888 		eap_variable_data_c & password_utf8,
   915 		eap_variable_data_c & password_utf8,
   889 		bool & password_prompt_enabled,
   916 		bool & password_prompt_enabled,
   890 		bool is_identity_query)    
   917 		bool is_identity_query)    
   891 {
   918 {
   892 	eap_status_e status = eap_status_ok;
       
   893 
   919 
   894 	EAP_TRACE_DEBUG(
   920 	EAP_TRACE_DEBUG(
   895 		m_am_tools, 
   921 		m_am_tools, 
   896 		TRACE_FLAGS_DEFAULT, 
   922 		TRACE_FLAGS_DEFAULT, 
   897 		(EAPL("eap_am_type_mschapv2_symbian_c::show_username_password_dialog - start, password_prompt_enabled=%d,is_identity_query=%d\n"),
   923 		(EAPL("eap_am_type_mschapv2_symbian_c::show_username_password_dialog - start, password_prompt_enabled=%d,is_identity_query=%d\n"),
   898 		password_prompt_enabled, is_identity_query));
   924 		password_prompt_enabled, is_identity_query));
   899 
   925 			
   900 	m_username_utf8 = &username_utf8;
   926 	m_username_utf8 = &username_utf8;
   901 	m_password_utf8 = &password_utf8;
   927 	m_password_utf8 = &password_utf8;
   902 	m_password_prompt_enabled = &password_prompt_enabled;
   928 	m_password_prompt_enabled = &password_prompt_enabled;
   903 	m_is_identity_query = is_identity_query;
   929 	m_is_identity_query = is_identity_query;
   904 
   930 
   905 	if (*m_password_prompt_enabled == true)
   931 	if (!IsActive())
   906 	{
   932 	{
   907 		m_username_password_io_ptr->iPasswordPromptEnabled = ETrue; 
   933 		if (*m_password_prompt_enabled == true)
   908 	}
   934 		{
   909 	else
   935 			m_username_password_io_ptr->iPasswordPromptEnabled = ETrue; 
   910 	{
   936 		}
   911 		m_username_password_io_ptr->iPasswordPromptEnabled = EFalse; 
   937 		else
   912 	}
   938 		{
   913 
   939 			m_username_password_io_ptr->iPasswordPromptEnabled = EFalse; 
   914 	if (m_is_identity_query == true)
   940 		}
   915 	{
   941 
   916 		m_username_password_io_ptr->iIsIdentityQuery = ETrue; 
   942 		if (m_is_identity_query == true)
   917 	}
   943 		{
   918 	else
   944 			m_username_password_io_ptr->iIsIdentityQuery = ETrue; 
   919 	{
   945 		}
   920 		m_username_password_io_ptr->iIsIdentityQuery = EFalse; 
   946 		else
   921 	}
   947 		{
   922 
   948 			m_username_password_io_ptr->iIsIdentityQuery = EFalse; 
   923 
   949 		}
   924 	eap_variable_data_c tmp_username_unicode(m_am_tools);
   950 
   925 	status = m_am_tools->convert_utf8_to_unicode(tmp_username_unicode, *m_username_utf8);
   951 
   926 	if (status != eap_status_ok)
   952 		{
   927 	{
   953 			eap_variable_data_c tmp_username_unicode(m_am_tools);
   928 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   954 			eap_status_e status = m_am_tools->convert_utf8_to_unicode(tmp_username_unicode, *m_username_utf8);
   929 		return EAP_STATUS_RETURN(m_am_tools, status);
   955 			if (status != eap_status_ok)
   930 	}
   956 			{
   931 
   957 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   932 	m_username_password_io_ptr->iUsername.Copy(
   958 				return EAP_STATUS_RETURN(m_am_tools, status);
   933 		reinterpret_cast<TUint16 *> (
   959 			}
   934 		tmp_username_unicode.get_data(tmp_username_unicode.get_data_length())),
   960 
   935 		tmp_username_unicode.get_data_length() / 2); // 8bit -> 16bit
   961 			m_username_password_io_ptr->iUsername.Copy(
   936 
   962 				reinterpret_cast<TUint16 *> (
   937 
   963 					tmp_username_unicode.get_data(tmp_username_unicode.get_data_length())),
   938 	m_state = EHandlingUsernamePasswordQuery;
   964 					tmp_username_unicode.get_data_length() / 2); // 8bit -> 16bit
       
   965 		}
       
   966 
       
   967 
       
   968 		m_state = EHandlingUsernamePasswordQuery;
       
   969 		
       
   970 	EAP_TRACE_DEBUG(
       
   971 		m_am_tools, 
       
   972 		TRACE_FLAGS_DEFAULT, 
       
   973 		(EAPL(" eap_am_type_mschapv2_symbian_c::show_username_password_dialog - before m_notifier.Connect(), m_is_notifier_connected=%d\n"),
       
   974 		m_is_notifier_connected));
       
   975 		
       
   976 		if( !m_is_notifier_connected )
       
   977 		{
       
   978 			TInt error = m_notifier.Connect();
       
   979 
       
   980 	EAP_TRACE_DEBUG(
       
   981 		m_am_tools, 
       
   982 		TRACE_FLAGS_DEFAULT, 
       
   983 		(EAPL(" eap_am_type_mschapv2_symbian_c::show_username_password_dialog - m_notifier.Connect() returned error=%d\n"),
       
   984 		error));
       
   985 			
       
   986 			if( error != KErrNone)
       
   987 			{
       
   988 				// Can not connect to notifier.
       
   989 				return EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(error));		
       
   990 			}
       
   991 			
       
   992 			m_is_notifier_connected = true; // Got connectted to notifier.
       
   993 		}
   939 
   994 
   940 	EAP_TRACE_DEBUG(
   995 	EAP_TRACE_DEBUG(
   941 		m_am_tools, 
   996 		m_am_tools, 
   942 		TRACE_FLAGS_DEFAULT, 
   997 		TRACE_FLAGS_DEFAULT, 
   943 		(EAPL(" eap_am_type_mschapv2_symbian_c::show_username_password_dialog - before m_notifier.StartNotifierAndGetResponse()\n")));		
   998 		(EAPL(" eap_am_type_mschapv2_symbian_c::show_username_password_dialog - before m_notifier.StartNotifierAndGetResponse()\n")));		
   944 
   999 
   945 	TInt err1 = KErrNone;
  1000 		m_notifier.StartNotifierAndGetResponse(
   946 
  1001 			iStatus, 
   947 	TRAPD(err, err1 = IsDlgReadyToCompleteL());
  1002 			KEapMsChapV2UsernamePasswordUid, 
   948 
  1003 			*m_username_password_io_pckg_ptr, 
   949 	EAP_TRACE_DEBUG(
  1004 			*m_username_password_io_pckg_ptr);
   950 		m_am_tools, 
  1005 
   951 		TRACE_FLAGS_DEFAULT,
  1006 		SetActive();
   952 		(EAPL("eap_am_type_mschapv2_symbian_c::show_username_password_dialog(): err=%d, result= %d\n"),
  1007 	} 
   953 		err,
       
   954 		err1));
       
   955 
       
   956 	if (*m_password_prompt_enabled == true || err || err1 == KErrCancel)
       
   957 	{
       
   958 		TEapExpandedType aEapType(*EapExpandedTypeMsChapv2.GetType());
       
   959 		m_username_password_io_ptr->iPassword.Zero();
       
   960 		if (iEapAuthNotifier == 0)
       
   961 		{
       
   962 			TRAPD(err, iEapAuthNotifier = CEapAuthNotifier::NewL( *this ));
       
   963 			if (err)
       
   964 			{
       
   965 				return eap_status_authentication_failure;
       
   966 			}
       
   967 		}
       
   968 		else
       
   969 		{
       
   970 			iEapAuthNotifier->Cancel();
       
   971 		}
       
   972 
       
   973 		TRAPD(err1, iEapAuthNotifier->StartL(CEapAuthNotifier::EEapNotifierTypeMsChapV2UsernamePasswordDialog, m_username_password_io_ptr, aEapType));
       
   974 		if (err1)
       
   975 		{
       
   976 			return eap_status_authentication_failure;
       
   977 		}
       
   978 	}
       
   979 	else
  1008 	else
   980 	{
  1009 	{
   981 		DlgComplete( status );
  1010 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("eap_am_type_mschapv2_symbian_c: Already active when tried to show username/password dialog.\n")));
   982 		return status;	
  1011 		return eap_status_process_general_error;
   983 	}
  1012 	}
   984 
  1013 
   985 	return eap_status_pending_request;
  1014 	return eap_status_pending_request;
   986 }
  1015 }
   987 
  1016 
   988 //--------------------------------------------------
  1017 //--------------------------------------------------
   989 
  1018 
   990 TInt eap_am_type_mschapv2_symbian_c::IsDlgReadyToCompleteL()
       
   991 	{
       
   992 
       
   993 	EAP_TRACE_DEBUG(
       
   994 		m_am_tools, 
       
   995 		TRACE_FLAGS_DEFAULT,
       
   996 		(EAPL("eap_am_type_mschapv2_symbian_c::IsDlgReadyToCompleteL(): m_index_type=%d, m_index=%d, m_tunneling_type=0xfe%06x%08x\n"),
       
   997 		m_index_type,
       
   998 		m_index,
       
   999 		m_tunneling_type.get_vendor_id(),
       
  1000 		m_tunneling_type.get_vendor_type()));
       
  1001 
       
  1002 	TInt status = KErrNone;
       
  1003 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  1004 	TPtr sqlStatement = buf->Des();
       
  1005 	
       
  1006 	// Query all the relevant parameters
       
  1007 	_LIT(KSQLQuery, "SELECT %S, %S, %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
       
  1008 	
       
  1009 	sqlStatement.Format(
       
  1010 		KSQLQuery,
       
  1011 		&cf_str_EAP_MSCHAPV2_password_prompt_literal,
       
  1012 		&cf_str_EAP_MSCHAPV2_username_literal,
       
  1013 		&cf_str_EAP_MSCHAPV2_password_literal,
       
  1014 		&KMsChapV2TableName,
       
  1015 		&KServiceType,
       
  1016 		m_index_type, 
       
  1017 		&KServiceIndex,
       
  1018 		m_index,
       
  1019 		&KTunnelingTypeVendorId,
       
  1020 		m_tunneling_type.get_vendor_id(),
       
  1021 		&KTunnelingType, 
       
  1022 		m_tunneling_type.get_vendor_type());
       
  1023 	
       
  1024 
       
  1025 	EAP_TRACE_DEBUG(
       
  1026 		m_am_tools, 
       
  1027 		TRACE_FLAGS_DEFAULT,
       
  1028 		(EAPL("eap_am_type_mschapv2_symbian_c::IsDlgReadyToCompleteL(): Opens view\n")));
       
  1029 
       
  1030 	RDbView view;
       
  1031 	// Evaluate view
       
  1032 	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  1033 	CleanupClosePushL(view);
       
  1034 	
       
  1035 	User::LeaveIfError(view.EvaluateAll());
       
  1036 	
       
  1037 	// Get the first (and only) row
       
  1038 	view.FirstL();
       
  1039 	view.GetL();
       
  1040 	
       
  1041 	// Get column set so we get the correct column numbers
       
  1042 	CDbColSet* colSet = view.ColSetL();
       
  1043 	CleanupStack::PushL(colSet);
       
  1044 
       
  1045 	EAP_TRACE_DEBUG(
       
  1046 		m_am_tools, 
       
  1047 		TRACE_FLAGS_DEFAULT,
       
  1048 		(EAPL("eap_am_type_leap_symbian_c::IsDlgReadyToCompleteL(): Reads database\n")));
       
  1049 
       
  1050 	TPtrC username = view.ColDes(colSet->ColNo( cf_str_EAP_MSCHAPV2_username_literal ) );
       
  1051 
       
  1052 	EAP_TRACE_DATA_DEBUG(
       
  1053 		m_am_tools,
       
  1054 		TRACE_FLAGS_DEFAULT,
       
  1055 		(EAPL("eap_am_type_mschapv2_symbian_c::IsDlgReadyToCompleteL(): username"),
       
  1056 		username.Ptr(),
       
  1057 		username.Size()));
       
  1058 
       
  1059 	TPtrC password = view.ColDes(colSet->ColNo( cf_str_EAP_MSCHAPV2_password_literal ) );
       
  1060 
       
  1061 	EAP_TRACE_DATA_DEBUG(
       
  1062 		m_am_tools,
       
  1063 		TRACE_FLAGS_DEFAULT,
       
  1064 		(EAPL("eap_am_type_mschapv2_symbian_c::IsDlgReadyToCompleteL(): password"),
       
  1065 		password.Ptr(),
       
  1066 		password.Size()));
       
  1067 
       
  1068 	TUint prompt = view.ColUint(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_prompt_literal));
       
  1069 
       
  1070 	EAP_TRACE_DEBUG(
       
  1071 		m_am_tools, 
       
  1072 		TRACE_FLAGS_DEFAULT,
       
  1073 		(EAPL("eap_am_type_mschapv2_symbian_c::IsDlgReadyToCompleteL(): prompt=%d\n"),
       
  1074 		prompt));
       
  1075 
       
  1076 
       
  1077 	if ((EEapDbFalse != prompt)
       
  1078 		 || (username.Size() == 0) 
       
  1079 		 || (password.Size() == 0))
       
  1080 		{
       
  1081 
       
  1082 		if (username.Size() == 0)
       
  1083 			{
       
  1084 			m_username_password_io_ptr->iUsername.Zero();
       
  1085 			}
       
  1086 		else
       
  1087 			{
       
  1088 			m_username_password_io_ptr->iUsername.Copy(username);
       
  1089 			}
       
  1090 
       
  1091 		status = KErrCancel;
       
  1092 		}
       
  1093 	else
       
  1094 		{
       
  1095 		status = KErrNone;	
       
  1096 		m_username_password_io_ptr->iUsername.Copy(username);
       
  1097 		m_username_password_io_ptr->iPassword.Copy(password);
       
  1098 		}
       
  1099 		
       
  1100 	CleanupStack::PopAndDestroy(colSet); // Delete colSet.
       
  1101 	CleanupStack::PopAndDestroy(&view); // Close view.
       
  1102 	CleanupStack::PopAndDestroy(buf); // Delete buf.
       
  1103 		
       
  1104 	EAP_TRACE_DEBUG(
       
  1105 		m_am_tools, 
       
  1106 		TRACE_FLAGS_DEFAULT,
       
  1107 		(EAPL("eap_am_type_mschapv2_symbian_c::IsDlgReadyToCompleteL(): status=%d\n"),
       
  1108 		status));
       
  1109 
       
  1110 	return status;
       
  1111 	}
       
  1112 	
       
  1113 eap_status_e eap_am_type_mschapv2_symbian_c::show_change_password_dialog(
  1019 eap_status_e eap_am_type_mschapv2_symbian_c::show_change_password_dialog(
  1114 		eap_variable_data_c & /* username */,
  1020 		eap_variable_data_c & /* username */,
  1115 		eap_variable_data_c & /* old_password */,
  1021 		eap_variable_data_c & /* old_password */,
  1116 		eap_variable_data_c & /* password */,
  1022 		eap_variable_data_c & /* password */,
  1117 		bool & /* password_prompt_enabled */)
  1023 		bool & /* password_prompt_enabled */)
  1136 	m_username_utf8 = &username;
  1042 	m_username_utf8 = &username;
  1137 	m_password_utf8 = &password;
  1043 	m_password_utf8 = &password;
  1138 	m_old_password_utf8 = &old_password;
  1044 	m_old_password_utf8 = &old_password;
  1139 	m_password_prompt_enabled = &password_prompt_enabled;
  1045 	m_password_prompt_enabled = &password_prompt_enabled;
  1140 
  1046 
  1141 
  1047 	if (!IsActive())
  1142 
  1048 	{
       
  1049 		{
       
  1050 			eap_variable_data_c tmp_username_unicode(m_am_tools);
       
  1051 			eap_status_e status = m_am_tools->convert_utf8_to_unicode(tmp_username_unicode, *m_username_utf8);
       
  1052 			if (status != eap_status_ok)
       
  1053 			{
       
  1054 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1055 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  1056 			}
       
  1057 
       
  1058 			m_username_password_io_ptr->iUsername.Copy(
       
  1059 				reinterpret_cast<TUint16 *> (
       
  1060 					tmp_username_unicode.get_data(tmp_username_unicode.get_data_length())),
       
  1061 					tmp_username_unicode.get_data_length() / 2); // 8bit -> 16bit
       
  1062 		}
       
  1063 
       
  1064 		m_state = EHandlingChangePasswordQuery;
       
  1065 		
       
  1066 	EAP_TRACE_DEBUG(
       
  1067 		m_am_tools, 
       
  1068 		TRACE_FLAGS_DEFAULT, 
       
  1069 		(EAPL(" eap_am_type_mschapv2_symbian_c::show_change_password_dialog - before m_notifier.Connect(), m_is_notifier_connected=%d\n"),
       
  1070 		m_is_notifier_connected));
       
  1071 		
       
  1072 		if( !m_is_notifier_connected )
       
  1073 		{
       
  1074 			TInt error = m_notifier.Connect();
       
  1075 
       
  1076 	EAP_TRACE_DEBUG(
       
  1077 		m_am_tools, 
       
  1078 		TRACE_FLAGS_DEFAULT, 
       
  1079 		(EAPL(" eap_am_type_mschapv2_symbian_c::show_change_password_dialog - m_notifier.Connect() returned error=%d\n"),
       
  1080 		error));
       
  1081 			
       
  1082 			if( error != KErrNone)
       
  1083 			{
       
  1084 				// Can not connect to notifier.
       
  1085 				return EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(error));		
       
  1086 			}
       
  1087 			
       
  1088 			m_is_notifier_connected = true; // Got connectted to notifier.
       
  1089 		}
       
  1090 
       
  1091 	EAP_TRACE_DEBUG(
       
  1092 		m_am_tools, 
       
  1093 		TRACE_FLAGS_DEFAULT, 
       
  1094 		(EAPL(" eap_am_type_mschapv2_symbian_c::show_change_password_dialog - before m_notifier.StartNotifierAndGetResponse()\n")));	
       
  1095 
       
  1096 		m_notifier.StartNotifierAndGetResponse(
       
  1097 			iStatus, 
       
  1098 			KEapMsChapV2ChangePasswordUid, 
       
  1099 			*m_username_password_io_pckg_ptr, 
       
  1100 			*m_username_password_io_pckg_ptr);
       
  1101 
       
  1102 		SetActive();
       
  1103 	} 
       
  1104 	else
       
  1105 	{
       
  1106 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("eap_am_type_mschapv2_symbian_c: Already active when tried to show change password dialog.\n")));
       
  1107 		return eap_status_process_general_error;
       
  1108 	}
  1143 
  1109 
  1144 	return eap_status_pending_request;
  1110 	return eap_status_pending_request;
  1145 	
  1111 	
  1146 #endif	
  1112 #endif	
  1147 }
  1113 }
  1211 	{
  1177 	{
  1212 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1178 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1213 		return EAP_STATUS_RETURN(m_am_tools, status);
  1179 		return EAP_STATUS_RETURN(m_am_tools, status);
  1214 	}
  1180 	}
  1215 
  1181 
  1216 	{
  1182 	status = memory_store_key->add_data(
  1217 		u32_t vendor_id = m_tunneling_type.get_vendor_id();
  1183 		&m_tunneling_vendor_type,
  1218 
  1184 		sizeof(m_tunneling_vendor_type));
  1219 		status = memory_store_key->add_data(
  1185 	if (status != eap_status_ok)
  1220 			&vendor_id,
  1186 	{
  1221 			sizeof(vendor_id));
  1187 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1222 		if (status != eap_status_ok)
  1188 		return EAP_STATUS_RETURN(m_am_tools, status);
  1223 		{
       
  1224 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1225 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1226 		}
       
  1227 	}
       
  1228 
       
  1229 	{
       
  1230 		u32_t vendor_type = m_tunneling_type.get_vendor_type();
       
  1231 		status = memory_store_key->add_data(
       
  1232 			&vendor_type,
       
  1233 			sizeof(vendor_type));
       
  1234 		if (status != eap_status_ok)
       
  1235 		{
       
  1236 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1237 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1238 		}
       
  1239 	}
  1189 	}
  1240 
  1190 
  1241 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1191 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1242 	return EAP_STATUS_RETURN(m_am_tools, status);
  1192 	return EAP_STATUS_RETURN(m_am_tools, status);
  1243 }
  1193 }
  1276 
  1226 
  1277 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
  1227 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
  1278 	TPtr sqlStatement = buf->Des();
  1228 	TPtr sqlStatement = buf->Des();
  1279 	
  1229 	
  1280 	// Query all the relevant parameters
  1230 	// Query all the relevant parameters
  1281 	_LIT(KSQLQuery, "SELECT %S, %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
  1231 	_LIT(KSQLQuery, "SELECT %S, %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
  1282 	sqlStatement.Format(
  1232 	sqlStatement.Format(KSQLQuery, &cf_str_EAP_MSCHAPv2_max_session_validity_time_literal,
  1283 		KSQLQuery,
  1233 						&KMSCHAPv2LastFullAuthTime, &KMsChapV2TableName,
  1284 		&cf_str_EAP_MSCHAPv2_max_session_validity_time_literal,
  1234 						&KServiceType, m_index_type, 
  1285 		&KMSCHAPv2LastFullAuthTime,
  1235 						&KServiceIndex, m_index, &KTunnelingType, m_tunneling_vendor_type);
  1286 		&KMsChapV2TableName,
       
  1287 		&KServiceType,
       
  1288 		m_index_type, 
       
  1289 		&KServiceIndex,
       
  1290 		m_index,
       
  1291 		&KTunnelingTypeVendorId,
       
  1292 		m_tunneling_type.get_vendor_id(),
       
  1293 		&KTunnelingType, 
       
  1294 		m_tunneling_type.get_vendor_type());
       
  1295 
  1236 
  1296 	RDbView view;
  1237 	RDbView view;
  1297 	// Evaluate view
  1238 	// Evaluate view
  1298 	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement)));
  1239 	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement)));
  1299 	CleanupClosePushL(view);
  1240 	CleanupClosePushL(view);
  1426 
  1367 
  1427 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
  1368 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
  1428 	TPtr sqlStatement = buf->Des();
  1369 	TPtr sqlStatement = buf->Des();
  1429 	
  1370 	
  1430 	// Query all the relevant parameters
  1371 	// Query all the relevant parameters
  1431 	_LIT(KSQLQuery, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
  1372 	_LIT(KSQLQuery, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
  1432 	sqlStatement.Format(
  1373 	sqlStatement.Format(KSQLQuery, &KMSCHAPv2LastFullAuthTime, &KMsChapV2TableName,
  1433 		KSQLQuery,
  1374 						&KServiceType, m_index_type, 
  1434 		&KMSCHAPv2LastFullAuthTime,
  1375 						&KServiceIndex, m_index, &KTunnelingType, m_tunneling_vendor_type);
  1435 		&KMsChapV2TableName,
       
  1436 		&KServiceType,
       
  1437 		m_index_type, 
       
  1438 		&KServiceIndex,
       
  1439 		m_index,
       
  1440 		&KTunnelingTypeVendorId,
       
  1441 		m_tunneling_type.get_vendor_id(),
       
  1442 		&KTunnelingType, 
       
  1443 		m_tunneling_type.get_vendor_type());
       
  1444 
  1376 
  1445 	RDbView view;
  1377 	RDbView view;
  1446 	// Evaluate view
  1378 	// Evaluate view
  1447 	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
  1379 	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
  1448 	CleanupClosePushL(view);
  1380 	CleanupClosePushL(view);