eapol/eapol_framework/eapol_symbian/am/core/symbian/eapol_am_wlan_authentication_symbian.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 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:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // This is enumeration of EAPOL source code.
       
    20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    21 	#undef EAP_FILE_NUMBER_ENUM
       
    22 	#define EAP_FILE_NUMBER_ENUM 151 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 #include "eapol_am_wlan_authentication_symbian.h"
       
    28 #include "abs_eapol_am_wlan_authentication.h"
       
    29 
       
    30 #include "eap_header_string.h"
       
    31 //#include "eap_type_all.h"
       
    32 #include "eap_config.h"
       
    33 #include "eap_file_config.h"
       
    34 #include "eap_am_file_input_symbian.h"
       
    35 #include "eap_type_selection.h"
       
    36 #include "eapol_key_types.h"
       
    37 #include "eap_timer_queue.h"
       
    38 #include "eap_crypto_api.h"
       
    39 #include "abs_eapol_wlan_database_reference_if.h"
       
    40 #include "abs_eap_state_notification.h"
       
    41 #include "eap_state_notification.h"
       
    42 #include "eap_automatic_variable.h"
       
    43 #include "eap_base_type.h"
       
    44 
       
    45 #include "EapolDbDefaults.h"
       
    46 #include "EapolDbParameterNames.h"
       
    47 
       
    48 const TUint KMaxSqlQueryLength = 2048;
       
    49 
       
    50 #ifdef USE_EAP_EXPANDED_TYPES
       
    51 
       
    52 const TUint KExpandedEAPSize = 8;
       
    53 
       
    54 #else
       
    55 
       
    56 const TUint KMaxEapCueLength = 3;
       
    57 
       
    58 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
    59 
       
    60 //--------------------------------------------------
       
    61 
       
    62 // 
       
    63 EAP_FUNC_EXPORT eapol_am_wlan_authentication_symbian_c::~eapol_am_wlan_authentication_symbian_c()
       
    64 {
       
    65 	EAP_TRACE_DEBUG(
       
    66 		m_am_tools, 
       
    67 		TRACE_FLAGS_DEFAULT, 
       
    68 		(EAPL("eapol_am_wlan_authentication_symbian_c::~eapol_am_wlan_authentication_symbian_c(): this = 0x%08x\n"),
       
    69 		this));
       
    70 }
       
    71 
       
    72 //--------------------------------------------------
       
    73 
       
    74 // 
       
    75 EAP_FUNC_EXPORT eapol_am_wlan_authentication_symbian_c::eapol_am_wlan_authentication_symbian_c(
       
    76 	abs_eap_am_tools_c * const tools,
       
    77 	const bool is_client_when_true,
       
    78 	const abs_eapol_wlan_database_reference_if_c * const wlan_database_reference)
       
    79 : CActive(CActive::EPriorityStandard)
       
    80 , m_am_partner(0)
       
    81 #if defined(USE_EAP_SIMPLE_CONFIG)
       
    82 , m_configuration_if(0)
       
    83 #endif // #if defined(USE_EAP_SIMPLE_CONFIG)
       
    84 , m_am_tools(tools)
       
    85 , m_fileconfig(0)
       
    86 , m_SSID(tools)
       
    87 , m_wpa_preshared_key(tools)
       
    88 , m_wpa_preshared_key_hash(tools)
       
    89 , m_wlan_database_reference(wlan_database_reference)
       
    90 #ifdef USE_EAP_EXPANDED_TYPES
       
    91 , m_eap_type_array(tools)
       
    92 #endif
       
    93 , m_receive_network_id(tools)
       
    94 , m_security_mode(Wpa)
       
    95 , m_selected_eapol_key_authentication_type(eapol_key_authentication_type_none)
       
    96 , m_WPA_override_enabled(false)
       
    97 , m_is_client(is_client_when_true)
       
    98 , m_is_valid(false)
       
    99 
       
   100 {
       
   101 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   102 
       
   103 	m_is_valid = true;
       
   104 
       
   105 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   106 }
       
   107 
       
   108 //--------------------------------------------------
       
   109 
       
   110 EAP_FUNC_EXPORT bool eapol_am_wlan_authentication_symbian_c::get_is_valid()
       
   111 {
       
   112 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   113 
       
   114 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   115 	return m_is_valid;
       
   116 }
       
   117 
       
   118 //--------------------------------------------------
       
   119 
       
   120 void eapol_am_wlan_authentication_symbian_c::TryInitDatabaseL()
       
   121 {
       
   122 	EAP_TRACE_DEBUG(
       
   123 		m_am_tools,
       
   124 		TRACE_FLAGS_DEFAULT,
       
   125 		(EAPL("eapol_am_wlan_authentication_symbian_c::TryOpenDatabaseL()\n")));	
       
   126 		
       
   127 	// 1. Open/create a database	
       
   128 	RDbNamedDatabase db;
       
   129 
       
   130 #ifdef SYMBIAN_SECURE_DBMS
       
   131 	
       
   132 	// Create the secure shared database (if necessary) with the specified secure policy.
       
   133 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
       
   134 	
       
   135 	TInt err = db.Create(m_session, KDatabaseName, KSecureUIDFormat);
       
   136 	
       
   137 	EAP_TRACE_DEBUG(
       
   138 		m_am_tools,
       
   139 		TRACE_FLAGS_DEFAULT,
       
   140 		(EAPL("TryOpenDatabaseL() - Created Secure DB for eapol.dat. err=%d\n"), err ));	
       
   141 		
       
   142 	if(err == KErrNone)
       
   143 	{	
       
   144 		db.Close();
       
   145 		
       
   146 	} else if (err != KErrAlreadyExists) 
       
   147 	{
       
   148 		User::LeaveIfError(err);
       
   149 	}
       
   150 	
       
   151 	User::LeaveIfError(db.Open(m_session, KDatabaseName, KSecureUIDFormat));	
       
   152 		
       
   153 #else
       
   154 	// For non-secured database. The database will be created in the old location (c:\system\data).
       
   155 	
       
   156 	// Create the database (if necessary)		
       
   157 	TInt err = db.Create(m_fs, KDatabaseName);
       
   158 	
       
   159 	EAP_TRACE_DEBUG(
       
   160 		m_am_tools,
       
   161 		TRACE_FLAGS_DEFAULT,
       
   162 		(EAPL("TryOpenDatabaseL() - Created Non-Secure DB for eapol.dat. err=%d\n"), err ));	
       
   163 	
       
   164 	if(err == KErrNone)
       
   165 	{
       
   166 		db.Close();
       
   167 		
       
   168 	} else if (err != KErrAlreadyExists) 
       
   169 	{
       
   170 		User::LeaveIfError(err);
       
   171 	}
       
   172 		
       
   173 	User::LeaveIfError(db.Open(m_session, KDatabaseName));
       
   174 	    
       
   175 #endif // #ifdef SYMBIAN_SECURE_DBMS		
       
   176 
       
   177 	CleanupClosePushL(db);
       
   178 
       
   179 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
   180 	TPtr sqlStatement = buf->Des();
       
   181 
       
   182 	// 2. Create the table for pre-shared keys in database (ignore error if exists)
       
   183 
       
   184 	//// NAME /////////////////////////////////////////////////// TYPE ////////////// Constant ///////
       
   185 	//| ServiceType											  | UNSIGNED INTEGER | KServiceType    |//
       
   186 	//| ServiceIndex										  | UNSIGNED INTEGER | KServiceIndex   |//
       
   187 	//| SSID												  | VARBINARY(255)	 | KSSID		   |//	
       
   188 	//| Password											  | VARBINARY(255)	 | KPassword	   |//	
       
   189 	//| PSK												      | VARBINARY(255)   | KPSK			   |//	
       
   190 	//////////////////////////////////////////////////////////////////////////////////////////////////	
       
   191 	_LIT(KSQLCreateTable2, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
   192 											 %S UNSIGNED INTEGER, \
       
   193 											 %S VARBINARY(255), \
       
   194 											 %S VARBINARY(255), \
       
   195 											 %S VARBINARY(255))");
       
   196 	sqlStatement.Format(KSQLCreateTable2, &KEapolPSKTableName, 
       
   197 		&KServiceType, &KServiceIndex, &KSSID, &KPassword, &KPSK);
       
   198 	err = db.Execute(sqlStatement);
       
   199 	if (err != KErrNone && err != KErrAlreadyExists)
       
   200 	{
       
   201 		User::Leave(err);
       
   202 	}
       
   203 	
       
   204 	CleanupStack::PopAndDestroy(); // buf
       
   205 	
       
   206 	// If compacting is not done the database will start growing
       
   207 	db.Compact();
       
   208 	
       
   209 	CleanupStack::PopAndDestroy(); // Close database
       
   210 }
       
   211 
       
   212 //--------------------------------------------------
       
   213 
       
   214 void eapol_am_wlan_authentication_symbian_c::InitDatabaseL()
       
   215 {
       
   216 	EAP_TRACE_DEBUG(
       
   217 		m_am_tools,
       
   218 		TRACE_FLAGS_DEFAULT,
       
   219 		(EAPL("eapol_am_wlan_authentication_symbian_c::OpenDatabaseL()\n")));
       
   220 
       
   221 	// Create the database (if necessary)
       
   222 	TRAPD(err, TryInitDatabaseL());
       
   223 	if (err != KErrNone)
       
   224 	{
       
   225 		// Because of error remove the database file.
       
   226 		err = m_fs.Delete(KDatabaseName);
       
   227 		if(err != KErrNone)
       
   228 		{
       
   229 			User::Leave(KErrCorrupt);
       
   230 		}		
       
   231 
       
   232 		// Try open database again. This will leave if fails second time.
       
   233 		TryInitDatabaseL();
       
   234 	}
       
   235 }
       
   236 
       
   237 //--------------------------------------------------
       
   238 
       
   239 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::configure()
       
   240 {
       
   241 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   242 
       
   243 	EAP_TRACE_DEBUG(
       
   244 		m_am_tools, 
       
   245 		TRACE_FLAGS_DEFAULT, 
       
   246 		(EAPL("eapol_am_wlan_authentication_symbian_c::configure(): %s, this = 0x%08x => 0x%08x\n"),
       
   247 		 (m_is_client == true) ? "client": "server",
       
   248 		 this,
       
   249 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   250 
       
   251 	TInt error(KErrNone);
       
   252 
       
   253 	// Open the database session
       
   254 	error = m_session.Connect();
       
   255 	if (error != KErrNone)
       
   256 	{
       
   257 		eap_status_e status(m_am_tools->convert_am_error_to_eapol_error(error));
       
   258 
       
   259 		EAP_TRACE_DEBUG(
       
   260 			m_am_tools,
       
   261 			TRACE_FLAGS_DEFAULT,
       
   262 			(EAPL("RDbs::Connect() failed %d.\n"),
       
   263 			status));
       
   264 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   265 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   266 	}
       
   267 
       
   268 	EAP_TRACE_DEBUG(
       
   269 		m_am_tools,
       
   270 		TRACE_FLAGS_DEFAULT,
       
   271 		(EAPL("Database session initialized...\n")));
       
   272 
       
   273 	// Connect to FS
       
   274 	error = m_fs.Connect();
       
   275 	if (error != KErrNone)
       
   276 	{
       
   277 		eap_status_e status(m_am_tools->convert_am_error_to_eapol_error(error));
       
   278 
       
   279 		EAP_TRACE_DEBUG(
       
   280 			m_am_tools,
       
   281 			TRACE_FLAGS_DEFAULT,
       
   282 			(EAPL("RFs::Connect() failed %d.\n"),
       
   283 			status));
       
   284 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   285 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   286 	}
       
   287 
       
   288 	EAP_TRACE_DEBUG(
       
   289 		m_am_tools,
       
   290 		TRACE_FLAGS_DEFAULT,
       
   291 		(EAPL("Fileserver session initialized...\n")));
       
   292 
       
   293 	// Initialize database
       
   294 	TRAPD(err, InitDatabaseL());
       
   295 	if (err != KErrNone)
       
   296 	{
       
   297 		eap_status_e status(m_am_tools->convert_am_error_to_eapol_error(error));
       
   298 
       
   299 		EAP_TRACE_DEBUG(
       
   300 			m_am_tools,
       
   301 			TRACE_FLAGS_DEFAULT,
       
   302 			(EAPL("InitDatabaseL failed %d.\n"),
       
   303 			status));
       
   304 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   305 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   306 	}
       
   307 
       
   308 	EAP_TRACE_DEBUG(
       
   309 		m_am_tools,
       
   310 		TRACE_FLAGS_DEFAULT,
       
   311 		(EAPL("Database initialized...\n")));
       
   312 
       
   313 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   314 
       
   315 #if defined(USE_EAP_FILECONFIG)
       
   316 	{
       
   317 		eap_am_file_input_symbian_c * const fileio = new eap_am_file_input_symbian_c(m_am_tools);
       
   318 
       
   319 		eap_automatic_variable_c<eap_am_file_input_symbian_c> automatic_fileio(m_am_tools, fileio);
       
   320 
       
   321 		if (fileio != 0
       
   322 			&& fileio->get_is_valid() == true)
       
   323 		{
       
   324 			EAP_TRACE_DEBUG(
       
   325 				m_am_tools,
       
   326 				TRACE_FLAGS_DEFAULT,
       
   327 				(EAPL("Initialize file configuration.\n")));
       
   328 
       
   329 			eap_variable_data_c file_name_c_data(m_am_tools);
       
   330 
       
   331 			eap_status_e status(eap_status_process_general_error);
       
   332 
       
   333 			{
       
   334 				#if defined(EAPOL_SYMBIAN_VERSION_7_0_s)
       
   335 					eap_const_string const FILECONFIG_FILENAME_C
       
   336 						= "c:\\system\\data\\eap.conf";
       
   337 				#else
       
   338 					eap_const_string const FILECONFIG_FILENAME_C
       
   339 						= "c:\\private\\101F8EC5\\eap.conf";
       
   340 				#endif
       
   341 
       
   342 				status = file_name_c_data.set_copy_of_buffer(
       
   343 					FILECONFIG_FILENAME_C,
       
   344 					m_am_tools->strlen(FILECONFIG_FILENAME_C));
       
   345 				if (status != eap_status_ok)
       
   346 				{
       
   347 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   348 					return EAP_STATUS_RETURN(m_am_tools, status);
       
   349 				}
       
   350 
       
   351 				status = file_name_c_data.add_end_null();
       
   352 				if (status != eap_status_ok)
       
   353 				{
       
   354 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   355 					return EAP_STATUS_RETURN(m_am_tools, status);
       
   356 				}
       
   357 			}
       
   358 
       
   359 			eap_variable_data_c file_name_z_data(m_am_tools);
       
   360 
       
   361 			{
       
   362 				#if defined(EAPOL_SYMBIAN_VERSION_7_0_s)
       
   363 					eap_const_string const FILECONFIG_FILENAME_Z
       
   364 						= "z:\\system\\data\\eap.conf";
       
   365 				#else
       
   366 					eap_const_string const FILECONFIG_FILENAME_Z
       
   367 						= "z:\\private\\101F8EC5\\eap.conf";
       
   368 				#endif
       
   369 
       
   370 				status = file_name_z_data.set_copy_of_buffer(
       
   371 					FILECONFIG_FILENAME_Z,
       
   372 					m_am_tools->strlen(FILECONFIG_FILENAME_Z));
       
   373 				if (status != eap_status_ok)
       
   374 				{
       
   375 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   376 					return EAP_STATUS_RETURN(m_am_tools, status);
       
   377 				}
       
   378 
       
   379 				status = file_name_z_data.add_end_null();
       
   380 				if (status != eap_status_ok)
       
   381 				{
       
   382 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   383 					return EAP_STATUS_RETURN(m_am_tools, status);
       
   384 				}
       
   385 			}
       
   386 
       
   387 
       
   388 
       
   389 			if (status == eap_status_ok)
       
   390 			{
       
   391 				// First try open from C: disk.
       
   392 				status = fileio->file_open(
       
   393 					&file_name_c_data,
       
   394 					eap_file_io_direction_read);
       
   395 				if (status == eap_status_ok)
       
   396 				{
       
   397 					EAP_TRACE_DEBUG(
       
   398 						m_am_tools,
       
   399 						TRACE_FLAGS_DEFAULT,
       
   400 						(EAPL("Opens configure file %s\n"),
       
   401 						file_name_c_data.get_data(file_name_c_data.get_data_length())));
       
   402 				}
       
   403 				else if (status != eap_status_ok)
       
   404 				{
       
   405 					// Second try open from Z: disk.
       
   406 					status = fileio->file_open(
       
   407 						&file_name_z_data,
       
   408 						eap_file_io_direction_read);
       
   409 					if (status == eap_status_ok)
       
   410 					{
       
   411 						EAP_TRACE_DEBUG(
       
   412 							m_am_tools,
       
   413 							TRACE_FLAGS_DEFAULT,
       
   414 							(EAPL("Opens configure file %s\n"),
       
   415 							 file_name_z_data.get_data(file_name_z_data.get_data_length())));
       
   416 					}
       
   417 				}
       
   418 
       
   419 				if (status == eap_status_ok)
       
   420 				{
       
   421 					// Some of the files were opened.
       
   422 
       
   423 					m_fileconfig = new eap_file_config_c(m_am_tools);
       
   424 					if (m_fileconfig != 0
       
   425 						&& m_fileconfig->get_is_valid() == true)
       
   426 					{
       
   427 						status = m_fileconfig->configure(fileio);
       
   428 						if (status != eap_status_ok)
       
   429 						{
       
   430 							EAP_TRACE_DEBUG(
       
   431 								m_am_tools,
       
   432 								TRACE_FLAGS_DEFAULT,
       
   433 								(EAPL("ERROR: Configure read from %s failed.\n"),
       
   434 								file_name_c_data.get_data(file_name_c_data.get_data_length())));
       
   435 						}
       
   436 						else
       
   437 						{
       
   438 							EAP_TRACE_DEBUG(
       
   439 								m_am_tools,
       
   440 								TRACE_FLAGS_DEFAULT,
       
   441 								(EAPL("Configure read from %s\n"),
       
   442 								file_name_c_data.get_data(file_name_c_data.get_data_length())));
       
   443 						}
       
   444 					}
       
   445 					else
       
   446 					{
       
   447 						// No file configuration.
       
   448 						delete m_fileconfig;
       
   449 						m_fileconfig = 0;
       
   450 
       
   451 						EAP_TRACE_DEBUG(
       
   452 							m_am_tools,
       
   453 							TRACE_FLAGS_DEFAULT,
       
   454 							(EAPL("ERROR: Cannot create configure object for file %s\n"),
       
   455 							file_name_c_data.get_data(file_name_c_data.get_data_length())));
       
   456 					}
       
   457 				}
       
   458 				else
       
   459 				{
       
   460 					EAP_TRACE_DEBUG(
       
   461 						m_am_tools,
       
   462 						TRACE_FLAGS_DEFAULT,
       
   463 						(EAPL("ERROR: Cannot open configure file neither %s nor %s\n"),
       
   464 						file_name_c_data.get_data(file_name_c_data.get_data_length()),
       
   465 						file_name_z_data.get_data(file_name_z_data.get_data_length())));
       
   466 				}
       
   467 			}
       
   468 		}
       
   469 		else
       
   470 		{
       
   471 			EAP_TRACE_DEBUG(
       
   472 				m_am_tools,
       
   473 				TRACE_FLAGS_DEFAULT,
       
   474 				(EAPL("Skips file configuration.\n")));
       
   475 		}
       
   476 	}
       
   477 #endif //#if defined(USE_EAP_FILECONFIG)
       
   478 
       
   479 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   480 
       
   481 #if defined(USE_EAP_FILE_TRACE)
       
   482 	{
       
   483 		eap_variable_data_c trace_output_file(m_am_tools);
       
   484 
       
   485 		eap_status_e status = read_configure(
       
   486 			cf_str_EAP_TRACE_output_file_name.get_field(),
       
   487 			&trace_output_file);
       
   488 		if (status == eap_status_ok
       
   489 			&& trace_output_file.get_is_valid_data() == true)
       
   490 		{
       
   491 			status = m_am_tools->set_trace_file_name(&trace_output_file);
       
   492 			if (status == eap_status_ok)
       
   493 			{
       
   494 				// OK, set the default trace mask.
       
   495 				m_am_tools->set_trace_mask(
       
   496 					eap_am_tools_c::eap_trace_mask_debug
       
   497 					| eap_am_tools_c::eap_trace_mask_always
       
   498 					| eap_am_tools_c::eap_trace_mask_error
       
   499 					| eap_am_tools_c::eap_trace_mask_message_data);
       
   500 			}
       
   501 		}
       
   502 	}
       
   503 #endif //#if defined(USE_EAP_FILE_TRACE)
       
   504 
       
   505 
       
   506 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   507 
       
   508 	{
       
   509 		eap_variable_data_c EAP_TRACE_enable_timer_queue_traces(m_am_tools);
       
   510 
       
   511 		eap_status_e status = read_configure(
       
   512 			cf_str_EAP_TRACE_enable_timer_queue_traces.get_field(),
       
   513 			&EAP_TRACE_enable_timer_queue_traces);
       
   514 		if (status == eap_status_ok
       
   515 			&& EAP_TRACE_enable_timer_queue_traces.get_is_valid_data() == true)
       
   516 		{
       
   517 			u32_t *enable_timer_queue_traces = reinterpret_cast<u32_t *>(
       
   518 				EAP_TRACE_enable_timer_queue_traces.get_data(sizeof(u32_t)));
       
   519 			if (enable_timer_queue_traces != 0
       
   520 				&& *enable_timer_queue_traces != 0)
       
   521 			{
       
   522 				m_am_tools->set_trace_mask(
       
   523 					m_am_tools->get_trace_mask()
       
   524 					| eap_am_tools_c::eap_trace_mask_timer_queue
       
   525 					);
       
   526 			}
       
   527 		}
       
   528 	}
       
   529 
       
   530 	{
       
   531 		eap_variable_data_c EAP_TRACE_enable_function_traces(m_am_tools);
       
   532 
       
   533 		eap_status_e status = read_configure(
       
   534 			cf_str_EAP_TRACE_enable_function_traces.get_field(),
       
   535 			&EAP_TRACE_enable_function_traces);
       
   536 		if (status == eap_status_ok
       
   537 			&& EAP_TRACE_enable_function_traces.get_is_valid_data() == true)
       
   538 		{
       
   539 			u32_t *enable_function_traces = reinterpret_cast<u32_t *>(
       
   540 				EAP_TRACE_enable_function_traces.get_data(sizeof(u32_t)));
       
   541 			if (enable_function_traces != 0
       
   542 				&& *enable_function_traces != 0)
       
   543 			{
       
   544 				m_am_tools->set_trace_mask(
       
   545 					m_am_tools->get_trace_mask()
       
   546 					| eap_am_tools_c::eap_trace_mask_functions
       
   547 					);
       
   548 			}
       
   549 		}
       
   550 	}
       
   551 
       
   552 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   553 
       
   554 	EAP_TRACE_DEBUG(
       
   555 		m_am_tools,
       
   556 		TRACE_FLAGS_DEFAULT,
       
   557 		(EAPL("Created timer...\n")));
       
   558 
       
   559 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   560 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   561 }
       
   562 
       
   563 //--------------------------------------------------
       
   564 
       
   565 eap_status_e eapol_am_wlan_authentication_symbian_c::reset_eap_plugins()
       
   566 {
       
   567 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   568 
       
   569 	EAP_TRACE_DEBUG(
       
   570 		m_am_tools, 
       
   571 		TRACE_FLAGS_DEFAULT, 
       
   572 		(EAPL("eapol_am_wlan_authentication_symbian_c::reset_eap_plugins(): %s, this = 0x%08x => 0x%08x\n"),
       
   573 		 (m_is_client == true) ? "client": "server",
       
   574 		 this,
       
   575 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   576 
       
   577 	// Unload all loaded plugins
       
   578 	for(int ind = 0; ind < m_plugin_if_array.Count(); ind++)
       
   579 	{
       
   580 		delete m_plugin_if_array[ind];
       
   581 	}
       
   582 
       
   583 	m_plugin_if_array.Close();
       
   584 
       
   585 #ifdef USE_EAP_EXPANDED_TYPES
       
   586 
       
   587 	m_enabled_expanded_eap_array.ResetAndDestroy();
       
   588 
       
   589 	m_disabled_expanded_eap_array.ResetAndDestroy();
       
   590 	
       
   591 	m_eap_type_array.reset();
       
   592 	
       
   593 #else
       
   594 
       
   595 	// Delete the IAP EAP type info array
       
   596 	m_iap_eap_array.ResetAndDestroy();
       
   597 	
       
   598 	m_eap_type_array.Close();	
       
   599 	
       
   600 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
   601 
       
   602 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   603 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   604 }
       
   605 
       
   606 
       
   607 //--------------------------------------------------
       
   608 
       
   609 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::shutdown()
       
   610 {
       
   611 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   612 
       
   613 	EAP_TRACE_ALWAYS(
       
   614 		m_am_tools, 
       
   615 		TRACE_FLAGS_DEFAULT, 
       
   616 		(EAPL("eapol_am_wlan_authentication_symbian_c::shutdown(): %s, this = 0x%08x => 0x%08x\n"),
       
   617 		 (m_is_client == true) ? "client": "server",
       
   618 		 this,
       
   619 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   620 
       
   621 	m_session.Close();
       
   622 	m_fs.Close();
       
   623 
       
   624 	delete m_fileconfig;
       
   625 	m_fileconfig = 0;
       
   626 
       
   627 	(void) reset_eap_plugins();
       
   628 
       
   629 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   630 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   631 }
       
   632 
       
   633 //--------------------------------------------------
       
   634 
       
   635 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::set_am_partner(
       
   636 	abs_eapol_am_wlan_authentication_c * am_partner
       
   637 #if defined(USE_EAP_SIMPLE_CONFIG)
       
   638 	, abs_eap_configuration_if_c * const configuration_if
       
   639 #endif // #if defined(USE_EAP_SIMPLE_CONFIG)
       
   640 	)
       
   641 {
       
   642 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   643 
       
   644 	EAP_TRACE_DEBUG(
       
   645 		m_am_tools, 
       
   646 		TRACE_FLAGS_DEFAULT, 
       
   647 		(EAPL("eapol_am_wlan_authentication_simulator_c::set_am_partner(): %s, this = 0x%08x\n"),
       
   648 		 (m_is_client == true) ? "client": "server",
       
   649 		 this));
       
   650 
       
   651 	m_am_partner = am_partner;
       
   652 
       
   653 #if defined(USE_EAP_SIMPLE_CONFIG)
       
   654 	m_configuration_if = configuration_if;
       
   655 #endif // #if defined(USE_EAP_SIMPLE_CONFIG)
       
   656 
       
   657 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   658 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   659 }
       
   660 
       
   661 //--------------------------------------------------
       
   662 
       
   663 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::reset_eap_configuration()
       
   664 {
       
   665 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   666 
       
   667 	EAP_TRACE_DEBUG(
       
   668 		m_am_tools, 
       
   669 		TRACE_FLAGS_DEFAULT, 
       
   670 		(EAPL("eapol_am_wlan_authentication_symbian_c::reset_eap_configuration(): %s, this = 0x%08x\n"),
       
   671 		 (m_is_client == true) ? "client": "server",
       
   672 		 this));
       
   673 
       
   674 	TRAPD(error, ReadEAPSettingsL());
       
   675 	if (error != KErrNone)
       
   676 	{
       
   677 		EAP_TRACE_ERROR(
       
   678 			m_am_tools,
       
   679 			TRACE_FLAGS_DEFAULT,
       
   680 			(EAPL("EAP settings reading from CommDb failed or cancelled(err %d).\n"), error));
       
   681 
       
   682 		eap_status_e status(m_am_tools->convert_am_error_to_eapol_error(error));
       
   683 
       
   684 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   685 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   686 	}
       
   687 
       
   688 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   689 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   690 }
       
   691 
       
   692 //--------------------------------------------------
       
   693 
       
   694 void eapol_am_wlan_authentication_symbian_c::send_error_notification(const eap_status_e error)
       
   695 {
       
   696 	EAP_TRACE_DEBUG(m_am_tools, 
       
   697 		TRACE_FLAGS_DEFAULT, 
       
   698 		(EAPL("eapol_am_wlan_authentication_symbian_c::send_error_notification, error=%d\n"),
       
   699 		error));	
       
   700 
       
   701 	eap_general_state_variable_e general_state_variable(eap_general_state_authentication_error);
       
   702 	
       
   703 	if (error == eap_status_user_cancel_authentication)
       
   704 		{
       
   705 		general_state_variable = eap_general_state_authentication_cancelled;
       
   706 		}
       
   707 	// Here we swap the addresses.
       
   708 	eap_am_network_id_c send_network_id(m_am_tools,
       
   709 		m_receive_network_id.get_destination_id(),
       
   710 		m_receive_network_id.get_source_id(),
       
   711 		m_receive_network_id.get_type());
       
   712 
       
   713 	// Notifies the lower level of an authentication error.
       
   714 	eap_state_notification_c notification(
       
   715 		m_am_tools,
       
   716 		&send_network_id,
       
   717 		m_is_client,
       
   718 		eap_state_notification_eap,
       
   719 		eap_protocol_layer_general,
       
   720 		eap_type_none,
       
   721 		eap_state_none,
       
   722 		general_state_variable,
       
   723 		0,
       
   724 		false);
       
   725 
       
   726 	notification.set_authentication_error(error);
       
   727 
       
   728 	m_am_partner->state_notification(&notification);
       
   729 }
       
   730 
       
   731 //--------------------------------------------------
       
   732 
       
   733 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::set_wlan_parameters(
       
   734 	const eap_variable_data_c * const SSID,
       
   735 	const bool WPA_override_enabled,
       
   736 	const eap_variable_data_c * const wpa_preshared_key,
       
   737 	const eapol_key_authentication_type_e selected_eapol_key_authentication_type)
       
   738 {
       
   739 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   740 
       
   741 	EAP_TRACE_DEBUG(
       
   742 		m_am_tools, 
       
   743 		TRACE_FLAGS_DEFAULT, 
       
   744 		(EAPL("eapol_am_wlan_authentication_symbian_c::set_wlan_parameters(): %s, this = 0x%08x => 0x%08x\n"),
       
   745 		 (m_is_client == true) ? "client": "server",
       
   746 		 this,
       
   747 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   748 
       
   749 	m_WPA_override_enabled = WPA_override_enabled;
       
   750 
       
   751 	m_selected_eapol_key_authentication_type = selected_eapol_key_authentication_type;
       
   752 
       
   753 	eap_status_e status = m_SSID.set_copy_of_buffer(SSID);
       
   754 	if (status != eap_status_ok)
       
   755 	{
       
   756 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   757 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   758 	}
       
   759 
       
   760 	status = m_wpa_preshared_key.set_copy_of_buffer(wpa_preshared_key);
       
   761 	if (status != eap_status_ok)
       
   762 	{
       
   763 		send_error_notification(eap_status_key_error);
       
   764 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   765 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   766 	}
       
   767 
       
   768 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   769 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   770 }
       
   771 
       
   772 //--------------------------------------------------
       
   773 
       
   774 //
       
   775 void eapol_am_wlan_authentication_symbian_c::state_notification(
       
   776 	const abs_eap_state_notification_c * const state)
       
   777 {
       
   778 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   779 
       
   780 	EAP_UNREFERENCED_PARAMETER(state);
       
   781 
       
   782 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   783 }
       
   784 
       
   785 //--------------------------------------------------
       
   786 
       
   787 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::association(
       
   788 	const eap_am_network_id_c * const receive_network_id)
       
   789 {
       
   790 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   791 
       
   792 	EAP_TRACE_DEBUG(
       
   793 		m_am_tools, 
       
   794 		TRACE_FLAGS_DEFAULT, 
       
   795 		(EAPL("eapol_am_wlan_authentication_symbian_c::association(): %s, this = 0x%08x => 0x%08x\n"),
       
   796 		 (m_is_client == true) ? "client": "server",
       
   797 		 this,
       
   798 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   799 
       
   800 	eap_status_e status = m_receive_network_id.set_copy_of_network_id(receive_network_id);
       
   801 
       
   802 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   803 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   804 }
       
   805 
       
   806 //--------------------------------------------------
       
   807 
       
   808 //
       
   809 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::disassociation(
       
   810 	const eap_am_network_id_c * const /* receive_network_id */ ///< source includes remote address, destination includes local address.
       
   811 	)
       
   812 {
       
   813 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   814 
       
   815 	EAP_TRACE_DEBUG(
       
   816 		m_am_tools, 
       
   817 		TRACE_FLAGS_DEFAULT, 
       
   818 		(EAPL("eapol_am_wlan_authentication_symbian_c::disassociation(): %s, this = 0x%08x => 0x%08x\n"),
       
   819 		 (m_is_client == true) ? "client": "server",
       
   820 		 this,
       
   821 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   822 
       
   823 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   824 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   825 }
       
   826 
       
   827 //--------------------------------------------------
       
   828 
       
   829 #ifdef USE_EAP_EXPANDED_TYPES
       
   830 
       
   831 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::get_selected_eap_types(
       
   832 	eap_array_c<eap_type_selection_c> * const selected_eap_types)
       
   833 {
       
   834 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   835 
       
   836 	EAP_TRACE_DEBUG(
       
   837 		m_am_tools, 
       
   838 		TRACE_FLAGS_DEFAULT, 
       
   839 		(EAPL("eapol_am_wlan_authentication_symbian_c::get_selected_eap_types(): %s, this = 0x%08x => 0x%08x\n"),
       
   840 		 (m_is_client == true) ? "client": "server",
       
   841 		 this,
       
   842 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   843 
       
   844 	eap_status_e status = selected_eap_types->reset();
       
   845 	if (status != eap_status_ok)
       
   846 	{
       
   847 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   848 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   849 	}
       
   850 
       
   851 	eap_header_string_c eap_string;
       
   852 	EAP_UNREFERENCED_PARAMETER(eap_string);
       
   853 
       
   854 	// We need to return only the EAP types available as enabled types.
       
   855 	// It means only the ones available in m_enabled_expanded_eap_array.
       
   856 	
       
   857 	for (TInt i = 0; i < m_enabled_expanded_eap_array.Count(); i++)
       
   858 	{	
       
   859 		TBuf8<KExpandedEAPSize> tmpExpEAP(m_enabled_expanded_eap_array[i]->EapExpandedType);
       
   860 
       
   861 		EAP_TRACE_DEBUG(
       
   862 			m_am_tools, 
       
   863 			TRACE_FLAGS_DEFAULT, 
       
   864 			(EAPL("eapol_am_wlan_authentication_symbian_c::get_selected_eap_types:Enabled expanded EAP type at index=%d\n"),
       
   865 			 i));
       
   866 
       
   867 		EAP_TRACE_DATA_DEBUG(
       
   868 			m_am_tools,
       
   869 			TRACE_FLAGS_DEFAULT,
       
   870 			(EAPL("Enabled expanded EAP type"),
       
   871 			tmpExpEAP.Ptr(),
       
   872 			tmpExpEAP.Size()));
       
   873 
       
   874 		// This is for one expanded EAP type (for the above one).
       
   875 		eap_expanded_type_c expandedEAPType;
       
   876 				
       
   877 		// Read the expanded EAP type details from an item in m_enabled_expanded_eap_array.
       
   878 		status = eap_expanded_type_c::read_type(m_am_tools,
       
   879 												0,
       
   880 												tmpExpEAP.Ptr(),
       
   881 												tmpExpEAP.Size(),
       
   882 												&expandedEAPType);
       
   883 		if (status != eap_status_ok)
       
   884 		{
       
   885 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   886 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   887 		}
       
   888 
       
   889 		// Add EAP-type to list.
       
   890 		eap_type_selection_c * selection = new eap_type_selection_c(
       
   891 			m_am_tools,
       
   892 			expandedEAPType,
       
   893 			true);
       
   894 		if (selection != 0)
       
   895 		{
       
   896 			status = selected_eap_types->add_object(selection, true);
       
   897 			if (status != eap_status_ok)
       
   898 			{
       
   899 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   900 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   901 			}
       
   902 			
       
   903 			EAP_TRACE_DEBUG(
       
   904 				m_am_tools,
       
   905 				TRACE_FLAGS_DEFAULT,
       
   906 				(EAPL("get_selected_eap_types(): added EAP-type=0x%08x=%s\n"),
       
   907 				expandedEAPType.get_vendor_type(),
       
   908 				eap_string.get_eap_type_string(expandedEAPType)));			
       
   909 		}
       
   910 		else
       
   911 		{
       
   912 			// On error we ignore this EAP-type.
       
   913 			EAP_TRACE_DEBUG(
       
   914 				m_am_tools, 
       
   915 				TRACE_FLAGS_DEFAULT, 
       
   916 				(EAPL("Some problem with EAP type at index %d in m_enabled_expanded_eap_array\n"),
       
   917 				 i));
       
   918 		}
       
   919 	}
       
   920 
       
   921 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   922 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   923 }
       
   924 
       
   925 //--------------------------------------------------
       
   926 
       
   927 #else // for non-expanded (normal EAP types)
       
   928 
       
   929 //--------------------------------------------------
       
   930 
       
   931 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::get_selected_eap_types(
       
   932 	eap_array_c<eap_type_selection_c> * const selected_eap_types)
       
   933 {
       
   934 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   935 
       
   936 	EAP_TRACE_DEBUG(
       
   937 		m_am_tools, 
       
   938 		TRACE_FLAGS_DEFAULT, 
       
   939 		(EAPL("eapol_am_wlan_authentication_symbian_c::get_selected_eap_types(): %s, this = 0x%08x => 0x%08x\n"),
       
   940 		 (m_is_client == true) ? "client": "server",
       
   941 		 this,
       
   942 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   943 
       
   944 	eap_status_e status = selected_eap_types->reset();
       
   945 	if (status != eap_status_ok)
       
   946 	{
       
   947 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   948 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   949 	}
       
   950 
       
   951 	eap_header_string_c eap_string;
       
   952 	EAP_UNREFERENCED_PARAMETER(eap_string);
       
   953 
       
   954 	TEap *eapType = 0; 
       
   955 
       
   956 	for (TInt i = 0; i < m_iap_eap_array.Count(); i++)
       
   957 	{
       
   958 		// Check if type is enabled
       
   959 		eapType = m_iap_eap_array[i];
       
   960 		if (eapType->Enabled == 1)
       
   961 		{	
       
   962 			TLex8 tmp(eapType->UID);
       
   963 			TInt val(0);
       
   964 			tmp.Val(val);
       
   965 
       
   966 			EAP_TRACE_DEBUG(
       
   967 				m_am_tools,
       
   968 				TRACE_FLAGS_DEFAULT,
       
   969 				(EAPL("get_selected_eap_types(): adds EAP-type=0x%08x=%s\n"),
       
   970 				static_cast<eap_type_ietf_values_e>(val),
       
   971 				eap_string.get_eap_type_string(
       
   972 					static_cast<eap_type_value_e>(
       
   973 						static_cast<eap_type_ietf_values_e>(val)))));
       
   974 
       
   975 			// Add EAP-type to list.
       
   976 			eap_type_selection_c * selection = new eap_type_selection_c(
       
   977 				m_am_tools,
       
   978 				static_cast<eap_type_value_e>(static_cast<eap_type_ietf_values_e>(val)),
       
   979 				true);
       
   980 			if (selection != 0)
       
   981 			{
       
   982 				status = selected_eap_types->add_object(selection, true);
       
   983 				if (status != eap_status_ok)
       
   984 				{
       
   985 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   986 					return EAP_STATUS_RETURN(m_am_tools, status);
       
   987 				}
       
   988 			}
       
   989 			else
       
   990 			{
       
   991 				// On error we ignore this EAP-type.
       
   992 			}
       
   993 		}
       
   994 	}
       
   995 
       
   996 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   997 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   998 }
       
   999 
       
  1000 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  1001 
       
  1002 //--------------------------------------------------
       
  1003 
       
  1004 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::get_wlan_configuration(
       
  1005 	eap_variable_data_c * const wpa_preshared_key_hash)
       
  1006 {
       
  1007 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1008 
       
  1009 	EAP_TRACE_DEBUG(
       
  1010 		m_am_tools, 
       
  1011 		TRACE_FLAGS_DEFAULT, 
       
  1012 		(EAPL("eapol_am_wlan_authentication_symbian_c::get_wlan_configuration(): %s, this = 0x%08x => 0x%08x\n"),
       
  1013 		 (m_is_client == true) ? "client": "server",
       
  1014 		 this,
       
  1015 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
  1016 
       
  1017 	eap_status_e status = wpa_preshared_key_hash->set_copy_of_buffer(&m_wpa_preshared_key_hash);
       
  1018 
       
  1019 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1020 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1021 }
       
  1022 
       
  1023 //--------------------------------------------------
       
  1024 
       
  1025 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::authentication_finished(
       
  1026 	const bool when_true_successfull,
       
  1027 	const eap_type_value_e eap_type,
       
  1028 	const eapol_key_authentication_type_e authentication_type)
       
  1029 {
       
  1030 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1031 
       
  1032 	EAP_TRACE_DEBUG(
       
  1033 		m_am_tools, 
       
  1034 		TRACE_FLAGS_DEFAULT, 
       
  1035 		(EAPL("eapol_am_wlan_authentication_symbian_c::authentication_finished(): %s, this = 0x%08x => 0x%08x\n"),
       
  1036 		 (m_is_client == true) ? "client": "server",
       
  1037 		 this,
       
  1038 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
  1039 
       
  1040 	if (when_true_successfull == true)
       
  1041 	{
       
  1042 		if (authentication_type != eapol_key_authentication_type_RSNA_PSK
       
  1043 			&& authentication_type != eapol_key_authentication_type_WPA_PSK)
       
  1044 		{
       
  1045 
       
  1046 #ifdef USE_EAP_EXPANDED_TYPES
       
  1047 
       
  1048 			// This moves the successful type to be the top priority type in IAP settings.
       
  1049 			TRAPD(err, SetToTopPriorityL(eap_type));
       
  1050 			if (err != KErrNone)
       
  1051 			{
       
  1052 				// Just log the error. 
       
  1053 				EAP_TRACE_DEBUG(
       
  1054 					m_am_tools,
       
  1055 					TRACE_FLAGS_DEFAULT, 
       
  1056 					(EAPL("state_notification: SetToTopPriorityL() Expanded EAP type - leave with error=%d!\n"),
       
  1057 					err));
       
  1058 			}
       
  1059 
       
  1060 #else // For normal EAP types
       
  1061 					
       
  1062 			TEap eap;
       
  1063 			eap.Enabled = ETrue;
       
  1064 			eap.UID.Num(static_cast<TInt>(convert_eap_type_to_u32_t(eap_type)));
       
  1065 			
       
  1066 			// This moves the successful type to be the top priority type in IAP settings.
       
  1067 			TRAPD(err, SetToTopPriorityL(&eap));
       
  1068 			if (err != KErrNone)
       
  1069 			{
       
  1070 				// Just log the error. 
       
  1071 				EAP_TRACE_DEBUG(
       
  1072 					m_am_tools,
       
  1073 					TRACE_FLAGS_DEFAULT, 
       
  1074 					(EAPL("state_notification: SetToTopPriorityL leaved!\n")));
       
  1075 			}
       
  1076 
       
  1077 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  1078 
       
  1079 			// Move the active eap type index to the first type
       
  1080 			m_am_partner->set_current_eap_index(0ul);
       
  1081 		}
       
  1082 	}
       
  1083 
       
  1084 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1085 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  1086 }
       
  1087 
       
  1088 //--------------------------------------------------
       
  1089 
       
  1090 eap_status_e eapol_am_wlan_authentication_symbian_c::read_database_reference_values(
       
  1091 	TIndexType * const type,
       
  1092 	TUint * const index)
       
  1093 {
       
  1094 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1095 
       
  1096 	EAP_TRACE_DEBUG(
       
  1097 		m_am_tools, 
       
  1098 		TRACE_FLAGS_DEFAULT, 
       
  1099 		(EAPL("eapol_am_wlan_authentication_symbian_c::read_database_reference_values(): %s, this = 0x%08x => 0x%08x\n"),
       
  1100 		 (m_is_client == true) ? "client": "server",
       
  1101 		 this,
       
  1102 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
  1103 
       
  1104 	eap_variable_data_c database_reference(m_am_tools);
       
  1105 
       
  1106 	eap_status_e status = m_wlan_database_reference->get_wlan_database_reference_values(&database_reference);
       
  1107 	if (status != eap_status_ok)
       
  1108 	{
       
  1109 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1110 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1111 	}
       
  1112 
       
  1113 	const eapol_wlan_database_reference_values_s * const database_reference_values
       
  1114 		= reinterpret_cast<eapol_wlan_database_reference_values_s *>(
       
  1115 		database_reference.get_data(sizeof(eapol_wlan_database_reference_values_s)));
       
  1116 	if (database_reference_values == 0)
       
  1117 	{
       
  1118 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1119 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1120 	}
       
  1121 
       
  1122 	*type = static_cast<TIndexType>(database_reference_values->m_database_index_type);
       
  1123 	*index = database_reference_values->m_database_index;
       
  1124 
       
  1125 	EAP_TRACE_DEBUG(
       
  1126 		m_am_tools,
       
  1127 		TRACE_FLAGS_DEFAULT,
       
  1128 		(EAPL("eapol_am_wlan_authentication_symbian_c::read_database_reference_values(): Type=%d, Index=%d.\n"),
       
  1129 		 *type,
       
  1130 		 *index));
       
  1131 
       
  1132 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1133 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  1134 }
       
  1135 
       
  1136 //--------------------------------------------------
       
  1137 
       
  1138 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::load_module(
       
  1139 	const eap_type_value_e type,
       
  1140 	const eap_type_value_e tunneling_type,
       
  1141 	abs_eap_base_type_c * const partner,
       
  1142 	eap_base_type_c ** const eap_type_if,
       
  1143 	const bool is_client_when_true,
       
  1144 	const eap_am_network_id_c * const receive_network_id ///< source includes remote address, destination includes local address.
       
  1145 	)
       
  1146 {
       
  1147 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1148 
       
  1149 	EAP_TRACE_DEBUG(
       
  1150 		m_am_tools,
       
  1151 		TRACE_FLAGS_DEFAULT,
       
  1152 		(EAPL("eapol_am_wlan_authentication_symbian_c::load_module(type %d=%s, tunneling_type %d=%s)\n"),
       
  1153 		convert_eap_type_to_u32_t(type),
       
  1154 		eap_header_string_c::get_eap_type_string(type),
       
  1155 		convert_eap_type_to_u32_t(tunneling_type),
       
  1156 		eap_header_string_c::get_eap_type_string(tunneling_type)));
       
  1157 
       
  1158 	eap_status_e status(eap_status_process_general_error);
       
  1159 	
       
  1160 #ifdef USE_EAP_EXPANDED_TYPES
       
  1161 
       
  1162 	CEapType* eapType = 0;
       
  1163 	TInt error(KErrNone);
       
  1164 
       
  1165 	// Check if this EAP type has already been loaded
       
  1166 	TInt eapArrayIndex = find<eap_type_value_e>(
       
  1167 		&m_eap_type_array,
       
  1168 		&type,
       
  1169 		m_am_tools);
       
  1170 
       
  1171 	if (eapArrayIndex >= 0)
       
  1172 	{
       
  1173 		// We found the entry in the array.
       
  1174 		EAP_TRACE_DEBUG(
       
  1175 			m_am_tools,
       
  1176 			TRACE_FLAGS_DEFAULT,
       
  1177 			(EAPL("eapol_am_wlan_authentication_symbian_c::load_module(type %d=%s, tunneling_type %d=%s) already loaded.\n"),
       
  1178 			convert_eap_type_to_u32_t(type),
       
  1179 			eap_header_string_c::get_eap_type_string(type),
       
  1180 			convert_eap_type_to_u32_t(tunneling_type),
       
  1181 			eap_header_string_c::get_eap_type_string(tunneling_type)));
       
  1182 
       
  1183 		// Yep. It was loaded already.
       
  1184 		eapType = m_plugin_if_array[eapArrayIndex];		
       
  1185 	}
       
  1186 	else 
       
  1187 	{
       
  1188 		TIndexType index_type(ELan);
       
  1189 		TUint index(0UL);
       
  1190 
       
  1191 		status = read_database_reference_values(
       
  1192 			&index_type,
       
  1193 			&index);
       
  1194 		if (status != eap_status_ok)
       
  1195 		{
       
  1196 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1197 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1198 		}
       
  1199 
       
  1200 		EAP_TRACE_DEBUG(
       
  1201 			m_am_tools,
       
  1202 			TRACE_FLAGS_DEFAULT,
       
  1203 			(EAPL("eapol_am_wlan_authentication_symbian_c::load_module(type %d=%s, tunneling_type %d=%s) load new, index type=%d, index=%d.\n"),
       
  1204 			convert_eap_type_to_u32_t(type),
       
  1205 			eap_header_string_c::get_eap_type_string(type),
       
  1206 			convert_eap_type_to_u32_t(tunneling_type),
       
  1207 			eap_header_string_c::get_eap_type_string(tunneling_type),
       
  1208 			index_type,
       
  1209 			index));
       
  1210 
       
  1211 		TBuf8<KExpandedEAPSize> ExpandedCue;
       
  1212 		
       
  1213 		// Some indirect way of forming the 8 byte string of an EAP type for the cue is needed here.		
       
  1214 		TUint8 tmpExpCue[KExpandedEAPSize];
       
  1215 
       
  1216 		// This is to make the tmpExpCue in 8 byte string with correct vendor type and vendor id details.
       
  1217 		status = eap_expanded_type_c::write_type(m_am_tools,
       
  1218 												0, // index should be zero here.
       
  1219 												tmpExpCue,
       
  1220 												KExpandedEAPSize,
       
  1221 												true,
       
  1222 												type);
       
  1223 		if (status != eap_status_ok)
       
  1224 		{
       
  1225 			EAP_TRACE_DEBUG(
       
  1226 				m_am_tools,
       
  1227 				TRACE_FLAGS_DEFAULT,
       
  1228 				(EAPL("load_module: eap_expanded_type_c::write_type failed \n")));
       
  1229 		
       
  1230 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1231 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1232 		}
       
  1233 		
       
  1234 		// Now copy the 8 byte string to the real expanded cue.
       
  1235 		ExpandedCue.Copy(tmpExpCue, KExpandedEAPSize);
       
  1236 
       
  1237 		EAP_TRACE_DATA_DEBUG(
       
  1238 			m_am_tools,
       
  1239 			TRACE_FLAGS_DEFAULT,
       
  1240 			(EAPL("EAPOL:eapol_am_wlan_authentication_symbian_c::load_module: Expanded CUE:"),
       
  1241 			ExpandedCue.Ptr(),
       
  1242 			ExpandedCue.Size()));
       
  1243 
       
  1244 
       
  1245 		// We must have a trap here since the EAPOL core knows nothing about Symbian.
       
  1246 		TRAP(error, (eapType = CEapType::NewL(
       
  1247 			ExpandedCue,
       
  1248 			index_type,
       
  1249 			index)));	
       
  1250 		if (error != KErrNone
       
  1251 			|| eapType == 0)
       
  1252 		{
       
  1253 			// Interface not found or implementation creation function failed
       
  1254 			EAP_TRACE_DEBUG(
       
  1255 				m_am_tools,
       
  1256 				TRACE_FLAGS_DEFAULT,
       
  1257 				(EAPL("ECom could not find/initiate implementation.\n")));
       
  1258 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1259 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1260 		}
       
  1261 	}
       
  1262 
       
  1263 #else // For normal EAP types
       
  1264 	
       
  1265 	TBuf8<KMaxEapCueLength> cue;
       
  1266 	cue.Num(static_cast<TInt>(convert_eap_type_to_u32_t(type)));
       
  1267 	CEapType* eapType = 0;
       
  1268 	TInt error(KErrNone);
       
  1269 
       
  1270 	// Check if this EAP type has already been loaded
       
  1271 	TInt eapArrayIndex = m_eap_type_array.Find(type);
       
  1272 	if (eapArrayIndex != KErrNotFound)
       
  1273 	{
       
  1274 		EAP_TRACE_DEBUG(
       
  1275 			m_am_tools,
       
  1276 			TRACE_FLAGS_DEFAULT,
       
  1277 			(EAPL("eapol_am_wlan_authentication_symbian_c::load_module(type %d=%s, tunneling_type %d=%s) already loaded.\n"),
       
  1278 			convert_eap_type_to_u32_t(type),
       
  1279 			eap_header_string_c::get_eap_type_string(type),
       
  1280 			convert_eap_type_to_u32_t(tunneling_type),
       
  1281 			eap_header_string_c::get_eap_type_string(tunneling_type)));
       
  1282 
       
  1283 		// Yep. It was loaded already.
       
  1284 		eapType = m_plugin_if_array[eapArrayIndex];		
       
  1285 	}
       
  1286 	else 
       
  1287 	{
       
  1288 		TIndexType index_type(ELan);
       
  1289 		TUint index(0UL);
       
  1290 
       
  1291 		status = read_database_reference_values(
       
  1292 			&index_type,
       
  1293 			&index);
       
  1294 		if (status != eap_status_ok)
       
  1295 		{
       
  1296 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1297 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1298 		}
       
  1299 
       
  1300 		EAP_TRACE_DEBUG(
       
  1301 			m_am_tools,
       
  1302 			TRACE_FLAGS_DEFAULT,
       
  1303 			(EAPL("eapol_am_wlan_authentication_symbian_c::load_module(type %d=%s, tunneling_type %d=%s) load new, index type=%d, index=%d.\n"),
       
  1304 			convert_eap_type_to_u32_t(type),
       
  1305 			eap_header_string_c::get_eap_type_string(type),
       
  1306 			convert_eap_type_to_u32_t(tunneling_type),
       
  1307 			eap_header_string_c::get_eap_type_string(tunneling_type),
       
  1308 			index_type,
       
  1309 			index));
       
  1310 
       
  1311 		// We must have a trap here since the EAPOL core knows nothing about Symbian.
       
  1312 		TRAP(error, (eapType = CEapType::NewL(
       
  1313 			cue,
       
  1314 			index_type,
       
  1315 			index)));	
       
  1316 		if (error != KErrNone
       
  1317 			|| eapType == 0)
       
  1318 		{
       
  1319 			// Interface not found or implementation creation function failed
       
  1320 			EAP_TRACE_DEBUG(
       
  1321 				m_am_tools,
       
  1322 				TRACE_FLAGS_DEFAULT,
       
  1323 				(EAPL("ECom could not find/initiate implementation.\n")));
       
  1324 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1325 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1326 		}
       
  1327 	}
       
  1328 
       
  1329 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  1330 
       
  1331 	// Set the tunneling type
       
  1332 	eapType->SetTunnelingType(convert_eap_type_to_u32_t(tunneling_type));
       
  1333 
       
  1334 	// Create the EAP protocol interface implementation.
       
  1335 	
       
  1336 #ifdef USE_EAP_SIMPLE_CONFIG
       
  1337 
       
  1338 	TRAP(error, (*eap_type_if = eapType->GetStackInterfaceL(m_am_tools, 
       
  1339 		partner, 
       
  1340 		is_client_when_true, 
       
  1341 		receive_network_id,
       
  1342 		this)));
       
  1343 
       
  1344 #else
       
  1345 
       
  1346 	TRAP(error, (*eap_type_if = eapType->GetStackInterfaceL(m_am_tools, 
       
  1347 		partner, 
       
  1348 		is_client_when_true, 
       
  1349 		receive_network_id)));
       
  1350 
       
  1351 #endif // #ifdef USE_EAP_SIMPLE_CONFIG
       
  1352 	
       
  1353 		
       
  1354 	if (error != KErrNone 
       
  1355 		|| *eap_type_if == 0 
       
  1356 		|| (*eap_type_if)->get_is_valid() == false)
       
  1357 	{
       
  1358 		EAP_TRACE_DEBUG(
       
  1359 			m_am_tools,
       
  1360 			TRACE_FLAGS_DEFAULT,
       
  1361 			(EAPL("Could not create EAP type interface instance. Error: %d\n"), error));
       
  1362 
       
  1363 		status = eap_status_allocation_error;
       
  1364 		// Unload DLL (two ways, depending whether this type was already loaded...)
       
  1365 		if  (eapArrayIndex == KErrNotFound)
       
  1366 		{
       
  1367 			// No need to call shutdown here because GetStackInterfaceL has done it.
       
  1368 			delete eapType;
       
  1369 		}
       
  1370 		else
       
  1371 		{
       
  1372 			unload_module(type);
       
  1373 		}
       
  1374 		// Note: even in error cases eap_core_c deletes eap_type_if
       
  1375 	}
       
  1376 	else
       
  1377 	{
       
  1378 		status = eap_status_ok;
       
  1379 		if (eapArrayIndex  == KErrNotFound)
       
  1380 		{
       
  1381 			// Add plugin information to the member arrays. There is no need to store eap_type pointer because
       
  1382 			// the stack takes care of its deletion.
       
  1383 			if (m_plugin_if_array.Append(eapType) != KErrNone)
       
  1384 			{
       
  1385 				delete eapType;
       
  1386 				status = eap_status_allocation_error;
       
  1387 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1388 				return EAP_STATUS_RETURN(m_am_tools, status);				
       
  1389 			}
       
  1390 			
       
  1391 #ifdef USE_EAP_EXPANDED_TYPES
       
  1392 
       
  1393 			eap_type_value_e * tmpEAPType = new eap_type_value_e();
       
  1394 			if(tmpEAPType == NULL)
       
  1395 			{
       
  1396 				EAP_TRACE_DEBUG(
       
  1397 					m_am_tools,
       
  1398 					TRACE_FLAGS_DEFAULT,
       
  1399 					(EAPL("eapol_am_wlan_authentication_symbian_c::load_module() eap_type_value_e creation failed\n")));
       
  1400 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1401 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);				
       
  1402 			}
       
  1403 			
       
  1404 			*tmpEAPType = type;
       
  1405 			
       
  1406 			status = m_eap_type_array.add_object(tmpEAPType, true);
       
  1407 			
       
  1408 			if (status != eap_status_ok)			
       
  1409 
       
  1410 #else // For normal EAP type.			
       
  1411 			
       
  1412 			if (m_eap_type_array.Append(type) != KErrNone)
       
  1413 
       
  1414 #endif // #ifdef USE_EAP_EXPANDED_TYPES			
       
  1415 			{
       
  1416 				// Remove the eap type added just previously
       
  1417 				m_plugin_if_array.Remove(m_plugin_if_array.Count() - 1);
       
  1418 				delete eapType;
       
  1419 				status = eap_status_allocation_error;
       
  1420 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1421 				return EAP_STATUS_RETURN(m_am_tools, status);				
       
  1422 			}
       
  1423 		} 
       
  1424 	}
       
  1425 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1426 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1427 }
       
  1428 
       
  1429 //--------------------------------------------------
       
  1430 
       
  1431 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::unload_module(
       
  1432 	const eap_type_value_e type)
       
  1433 {
       
  1434 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1435 
       
  1436 	EAP_TRACE_DEBUG(
       
  1437 		m_am_tools, 
       
  1438 		TRACE_FLAGS_DEFAULT, 
       
  1439 		(EAPL("eapol_am_wlan_authentication_symbian_c::unload_module(): %s, this = 0x%08x => 0x%08x\n"),
       
  1440 		 (m_is_client == true) ? "client": "server",
       
  1441 		 this,
       
  1442 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
  1443 
       
  1444 	eap_status_e status(eap_status_type_does_not_exists_error);
       
  1445 
       
  1446 #ifdef USE_EAP_EXPANDED_TYPES
       
  1447 
       
  1448 	// Check if this EAP type has already been loaded
       
  1449 	TInt index = find<eap_type_value_e>(
       
  1450 		&m_eap_type_array,
       
  1451 		&type,
       
  1452 		m_am_tools);
       
  1453 		
       
  1454 	if (index >= 0)
       
  1455 	{
       
  1456 		// EAP was loaded before.
       
  1457 		
       
  1458 		delete m_plugin_if_array[index];
       
  1459 		m_plugin_if_array.Remove(index);
       
  1460 		
       
  1461 		status = m_eap_type_array.remove_object(index);
       
  1462 	}
       
  1463 
       
  1464 #else // For normal EAP types.
       
  1465 
       
  1466 	TInt index = m_eap_type_array.Find(type);
       
  1467 	if (index != KErrNotFound)
       
  1468 	{
       
  1469 		delete m_plugin_if_array[index];
       
  1470 		m_plugin_if_array.Remove(index);
       
  1471 		m_eap_type_array.Remove(index);
       
  1472 		status = eap_status_ok;			
       
  1473 	}
       
  1474 
       
  1475 #endif // #ifdef USE_EAP_EXPANDED_TYPES
       
  1476 
       
  1477 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1478 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1479 }
       
  1480 
       
  1481 //--------------------------------------------------
       
  1482 
       
  1483 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::read_configure(
       
  1484 	const eap_configuration_field_c * const field,
       
  1485 	eap_variable_data_c * const data)
       
  1486 {
       
  1487 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1488 	EAP_ASSERT_ALWAYS(data != NULL);
       
  1489 	
       
  1490 	EAP_TRACE_DEBUG(
       
  1491 		m_am_tools, 
       
  1492 		TRACE_FLAGS_DEFAULT, 
       
  1493 		(EAPL("eapol_am_wlan_authentication_symbian_c::read_configure(): %s, this = 0x%08x => 0x%08x\n"),
       
  1494 		 (m_is_client == true) ? "client": "server",
       
  1495 		 this,
       
  1496 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
  1497 	
       
  1498 	// Trap must be set here because the OS independent portion of EAPOL
       
  1499 	// that calls this function does not know anything about Symbian.	
       
  1500 	eap_status_e status(eap_status_ok);
       
  1501 
       
  1502 	// Check if the wanted parameter is default type
       
  1503 
       
  1504 	eap_variable_data_c wanted_field(m_am_tools);
       
  1505 	eap_variable_data_c type_field(m_am_tools);
       
  1506 	
       
  1507 	status = wanted_field.set_buffer(
       
  1508 		field->get_field(),
       
  1509 		field->get_field_length(),
       
  1510 		false,
       
  1511 		false);
       
  1512 	if (status != eap_status_ok)
       
  1513 	{
       
  1514 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1515 		return status;
       
  1516 	}
       
  1517 	
       
  1518 	status = type_field.set_buffer(
       
  1519 		cf_str_EAP_default_type_hex_data.get_field()->get_field(),
       
  1520 		cf_str_EAP_default_type_hex_data.get_field()->get_field_length(),
       
  1521 		false,
       
  1522 		false);
       
  1523 	if (status != eap_status_ok)
       
  1524 	{
       
  1525 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1526 		return status;
       
  1527 	}
       
  1528 
       
  1529 	eap_type_value_e aSelectedEapType;
       
  1530 	
       
  1531 #ifdef USE_EAP_EXPANDED_TYPES
       
  1532 
       
  1533 	if (!wanted_field.compare(&type_field))
       
  1534 	{
       
  1535 		TInt ind; 
       
  1536 
       
  1537 		// First check do we have read configuration from databases.
       
  1538 		if (m_enabled_expanded_eap_array.Count() == 0)
       
  1539 		{
       
  1540 			EAP_TRACE_ERROR(
       
  1541 				m_am_tools,
       
  1542 				TRACE_FLAGS_DEFAULT,
       
  1543 				(EAPL("EAP settings not read from CommsDat\n")));
       
  1544 
       
  1545 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  1546 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
  1547 		}
       
  1548 
       
  1549 		// Now we need to return here the next EAP type we should try		
       
  1550 		for (ind = m_am_partner->get_current_eap_index(); ind < m_enabled_expanded_eap_array.Count(); ind++)
       
  1551 		{
       
  1552 			// Find the highest priority EAP with index "ind".
       
  1553 			
       
  1554 			TBuf8<KExpandedEAPSize> tmpExpEAP(m_enabled_expanded_eap_array[ind]->EapExpandedType);
       
  1555 			
       
  1556 			status = data->set_copy_of_buffer(tmpExpEAP.Ptr(), tmpExpEAP.Size());			
       
  1557 			if (status != eap_status_ok)
       
  1558 			{
       
  1559 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1560 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);			
       
  1561 			}
       
  1562 
       
  1563 			EAP_TRACE_DATA_DEBUG(
       
  1564 				m_am_tools,
       
  1565 				TRACE_FLAGS_DEFAULT,
       
  1566 				(EAPL("EAPOL:eapol_am_wlan_authentication_symbian_c::read_configure: Trying EAP type:"),
       
  1567 				tmpExpEAP.Ptr(),
       
  1568 				tmpExpEAP.Size()));
       
  1569 			status = eap_expanded_type_c::read_type(m_am_tools,
       
  1570 					0,
       
  1571 					tmpExpEAP.Ptr(),
       
  1572 					tmpExpEAP.Size(),
       
  1573 					&aSelectedEapType);
       
  1574 			if (status == eap_status_ok)
       
  1575 			{
       
  1576 				break;
       
  1577 			}
       
  1578 		}
       
  1579 
       
  1580 		// Set the index of new EAP type we are trying now.
       
  1581 		m_am_partner->set_current_eap_index(ind);
       
  1582 		
       
  1583 		if (ind >= m_enabled_expanded_eap_array.Count())
       
  1584 		{
       
  1585 			// Not found any other EAP type as enabled.
       
  1586 			// Send WLM notification because there is no way that the authentication
       
  1587 			// can be successful if we don't have any EAP types to use...
       
  1588 			if (m_is_client)
       
  1589 			{
       
  1590 				EAP_TRACE_ERROR(
       
  1591 					m_am_tools,
       
  1592 					TRACE_FLAGS_DEFAULT,
       
  1593 					(EAPL("ERROR: read_configure: No configured EAP types or all tried unsuccessfully.\n")));
       
  1594 			}
       
  1595 
       
  1596 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1597 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_configure_field);
       
  1598 		}
       
  1599 	
       
  1600 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1601 		return EAP_STATUS_RETURN(m_am_tools, status);		
       
  1602 	}
       
  1603 
       
  1604 #else // For normal non-expanded EAP
       
  1605 
       
  1606 	if (!wanted_field.compare(&type_field))
       
  1607 	{
       
  1608 		TInt ind; 
       
  1609 
       
  1610 		// First check do we have read configuration from databases.
       
  1611 		if (m_iap_eap_array.Count() == 0)
       
  1612 		{
       
  1613 			EAP_TRACE_ERROR(
       
  1614 				m_am_tools,
       
  1615 				TRACE_FLAGS_DEFAULT,
       
  1616 				(EAPL("EAP settings not read from CommDb\n")));
       
  1617 
       
  1618 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  1619 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
  1620 		}
       
  1621 
       
  1622 		// We need to return here the next EAP type we should try		
       
  1623 		for (ind = m_am_partner->get_current_eap_index(); ind < m_iap_eap_array.Count(); ind++)
       
  1624 		{
       
  1625 			// Find the first enabled EAP type (highest priority)
       
  1626 			TEap *eapType = m_iap_eap_array[ind];			
       
  1627 			if (eapType->Enabled == 1)
       
  1628 			{
       
  1629 				// Convert the string to integer
       
  1630 				TLex8 tmp(eapType->UID);
       
  1631 				TInt val(0);
       
  1632 				tmp.Val(val);
       
  1633 				status = data->set_copy_of_buffer(reinterpret_cast<u8_t *>(&val), sizeof(TUint));
       
  1634 				if (status != eap_status_ok)
       
  1635 				{
       
  1636 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1637 					return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);			
       
  1638 				}
       
  1639 
       
  1640 				EAP_TRACE_DEBUG(
       
  1641 					m_am_tools,
       
  1642 					TRACE_FLAGS_DEFAULT,
       
  1643 					(EAPL("EAPOL: Trying EAP type: %d.\n"), val));
       
  1644 				aSelectedEapType = val;
       
  1645 				break;
       
  1646 			}
       
  1647 		}
       
  1648 
       
  1649 		m_am_partner->set_current_eap_index(ind);
       
  1650 		if (ind >= m_iap_eap_array.Count())
       
  1651 		{
       
  1652 			// Not found
       
  1653 			// Send WLM notification because there is no way that the authentication
       
  1654 			// can be successful if we don't have any EAP types to use...
       
  1655 			if (m_is_client)
       
  1656 			{
       
  1657 				EAP_TRACE_ERROR(
       
  1658 					m_am_tools,
       
  1659 					TRACE_FLAGS_DEFAULT,
       
  1660 					(EAPL("ERROR: No configured EAP types or all tried unsuccessfully.\n")));
       
  1661 			}
       
  1662 
       
  1663 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1664 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_configure_field);
       
  1665 		}
       
  1666 	
       
  1667 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1668 		return EAP_STATUS_RETURN(m_am_tools, status);		
       
  1669 	}
       
  1670 
       
  1671 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  1672 
       
  1673 	// It was something else than EAP type. Read it from eapol DB.
       
  1674 	_LIT( KEapolTableName, "eapol" );
       
  1675 	TRAPD( err, read_configureL(
       
  1676 		KDatabaseName,
       
  1677 		KEapolTableName,
       
  1678 		field->get_field(),
       
  1679 		field->get_field_length(),
       
  1680 		data) );
       
  1681 	// Try to read it for eap fast DB	
       
  1682 	HBufC8* fieldBuf = HBufC8::NewLC( field->get_field_length() );
       
  1683 	TPtr8 fieldPtr = fieldBuf->Des();
       
  1684 	fieldPtr.Copy( reinterpret_cast<const TUint8 *> ( field->get_field() ));
       
  1685 
       
  1686 	_LIT8(cf_str_EAP_TLS_PEAP_use_identity_privacy_literal, "EAP_TLS_PEAP_use_identity_privacy");
       
  1687 	
       
  1688 	if ( err != KErrNone &&
       
  1689 		 fieldPtr.Compare( cf_str_EAP_TLS_PEAP_use_identity_privacy_literal() ) == 0 ) 
       
  1690 		{
       
  1691 		if (aSelectedEapType == eap_type_tls)
       
  1692 			{
       
  1693 			_LIT(KGeneralSettingsDBTableName, "KTlsDatabaseTableName");
       
  1694 			TRAP( err, read_configureL(
       
  1695 					KDatabaseName,
       
  1696 					KGeneralSettingsDBTableName,
       
  1697 					field->get_field(),
       
  1698 					field->get_field_length(),
       
  1699 					data) );		
       
  1700 
       
  1701 			}
       
  1702 		if (aSelectedEapType == eap_type_peap)
       
  1703 			{
       
  1704 			_LIT(KGeneralSettingsDBTableName, "KPeapDatabaseTableName"); 
       
  1705 			TRAP( err, read_configureL(
       
  1706 					KDatabaseName,
       
  1707 					KGeneralSettingsDBTableName,
       
  1708 					field->get_field(),
       
  1709 					field->get_field_length(),
       
  1710 					data) );		
       
  1711 			}
       
  1712 		if (aSelectedEapType == eap_type_ttls)
       
  1713 			{
       
  1714 			_LIT(KGeneralSettingsDBTableName, "KTtlsDatabaseTableName"); 
       
  1715 			TRAP( err, read_configureL(
       
  1716 					KDatabaseName,
       
  1717 					KGeneralSettingsDBTableName,
       
  1718 					field->get_field(),
       
  1719 					field->get_field_length(),
       
  1720 					data) );		
       
  1721 			}
       
  1722 #if defined (USE_FAST_EAP_TYPE)
       
  1723 		if ( aSelectedEapType == eap_type_fast)
       
  1724 			{
       
  1725 			_LIT(KFastGeneralSettingsDBTableName, "eapfast_general_settings"); 
       
  1726 			TRAP( err, read_configureL(
       
  1727 			KFastDatabaseName,
       
  1728 			KFastGeneralSettingsDBTableName,
       
  1729 			field->get_field(),
       
  1730 			field->get_field_length(),
       
  1731 			data) );		
       
  1732 			}
       
  1733 #endif
       
  1734 		}
       
  1735 	CleanupStack::PopAndDestroy( fieldBuf );
       
  1736 
       
  1737 	if (err != KErrNone) 
       
  1738 	{
       
  1739 		status = m_am_tools->convert_am_error_to_eapol_error(err);
       
  1740 
       
  1741 #if defined(USE_EAP_FILECONFIG)
       
  1742 		if (m_fileconfig != 0
       
  1743 			&& m_fileconfig->get_is_valid() == true)
       
  1744 		{
       
  1745 			// Here we could try the final configuration option.
       
  1746 			status = m_fileconfig->read_configure(
       
  1747 				field,
       
  1748 				data);
       
  1749 		}
       
  1750 #endif //#if defined(USE_EAP_FILECONFIG)
       
  1751 	}
       
  1752 	m_am_tools->trace_configuration(
       
  1753 		status,
       
  1754 		field,
       
  1755 		data);
       
  1756 
       
  1757 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1758 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1759 }
       
  1760 
       
  1761 //--------------------------------------------------
       
  1762 
       
  1763 void eapol_am_wlan_authentication_symbian_c::read_configureL(
       
  1764 	const TDesC& aDbName,
       
  1765 	const TDesC& aTableName,
       
  1766 	eap_config_string field,
       
  1767 	const u32_t /*field_length*/,
       
  1768 	eap_variable_data_c * const data)
       
  1769 {	
       
  1770 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1771 	
       
  1772 	// Open database
       
  1773 	RDbNamedDatabase db;
       
  1774 
       
  1775 #ifdef SYMBIAN_SECURE_DBMS
       
  1776 	User::LeaveIfError(db.Open(m_session, aDbName, KSecureUIDFormat));	
       
  1777 #else			
       
  1778 	User::LeaveIfError(db.Open(m_session, aDbName));
       
  1779 #endif // #ifdef SYMBIAN_SECURE_DBMS		
       
  1780 	
       
  1781 	CleanupClosePushL(db);
       
  1782 
       
  1783 
       
  1784 	// Create a buffer for the ascii strings - initialised with the argument
       
  1785 	HBufC8* asciibuf = HBufC8::NewLC(128);
       
  1786 	TPtr8 asciiString = asciibuf->Des();
       
  1787 	asciiString.Copy(reinterpret_cast<const unsigned char *>(field));
       
  1788 		
       
  1789 	// Buffer for unicode parameter
       
  1790 	HBufC* unicodebuf = HBufC::NewLC(128);
       
  1791 	TPtr unicodeString = unicodebuf->Des();
       
  1792 	
       
  1793 	// Convert to unicode 
       
  1794 	unicodeString.Copy(asciiString);
       
  1795 
       
  1796 	// Now do the database query
       
  1797 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  1798 	TPtr sqlStatement = buf->Des();
       
  1799 	_LIT(KSQLQueryRow, "SELECT %S FROM %S");
       
  1800 	sqlStatement.Format( KSQLQueryRow, &unicodeString, &aTableName );
       
  1801 	
       
  1802 	RDbView view;
       
  1803 	User::LeaveIfError(view.Prepare(db, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  1804 	CleanupClosePushL(view);
       
  1805 	User::LeaveIfError(view.EvaluateAll());	
       
  1806 	if (view.FirstL())
       
  1807 	{
       
  1808 		eap_status_e status(eap_status_process_general_error);
       
  1809 		view.GetL();		
       
  1810 		switch (view.ColType(1))
       
  1811 		{
       
  1812 		case EDbColText:				
       
  1813 			{
       
  1814 				unicodeString = view.ColDes(1);
       
  1815 				// Convert to 8-bit
       
  1816 				asciiString.Copy(unicodeString);
       
  1817 				if (asciiString.Size() > 0)
       
  1818 				{
       
  1819 					status = data->set_copy_of_buffer(asciiString.Ptr(), asciiString.Size());
       
  1820 					if (status != eap_status_ok)
       
  1821 					{
       
  1822 						User::Leave(KErrNoMemory);
       
  1823 					}
       
  1824 				} 
       
  1825 				else 
       
  1826 				{
       
  1827 					// Empty field. Do nothing...data remains invalid and the stack knows what to do hopefully.
       
  1828 					break;
       
  1829 				}
       
  1830 			}
       
  1831 			break;
       
  1832 		case EDbColUint32:
       
  1833 			{
       
  1834 				TUint value;
       
  1835 				value = view.ColUint32(1);
       
  1836 				status = data->set_copy_of_buffer((const unsigned char *) &value, sizeof(value));
       
  1837 				if (status != eap_status_ok)
       
  1838 				{
       
  1839 					User::Leave(KErrNoMemory);
       
  1840 				}
       
  1841 			}
       
  1842 			break;
       
  1843 		default:
       
  1844 			EAP_TRACE_DEBUG(
       
  1845 				m_am_tools,
       
  1846 				TRACE_FLAGS_DEFAULT,
       
  1847 				(EAPL("read_configureL: Unexpected column type.\n")));
       
  1848 			User::Panic(_L("EAPOL"), 1);			
       
  1849 		}
       
  1850 	} 
       
  1851 	else 
       
  1852 	{
       
  1853 		// Could not find parameter
       
  1854 		EAP_TRACE_DEBUG(
       
  1855 			m_am_tools,
       
  1856 			TRACE_FLAGS_DEFAULT,
       
  1857 			(EAPL("read_configureL: Could not find configuration parameter.\n")));
       
  1858 		User::Leave(KErrNotFound);
       
  1859 	}		
       
  1860 	
       
  1861 	// Close database
       
  1862 	CleanupStack::PopAndDestroy(5); // view, 3 buffers and database
       
  1863 
       
  1864 
       
  1865 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1866 }
       
  1867 
       
  1868 //--------------------------------------------------
       
  1869 
       
  1870 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::write_configure(
       
  1871 	const eap_configuration_field_c * const /* field */,
       
  1872 	eap_variable_data_c * const /* data */)
       
  1873 {
       
  1874 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1875 
       
  1876 	const eap_status_e status = eap_status_illegal_configure_field;
       
  1877 
       
  1878 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1879 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1880 }
       
  1881 
       
  1882 //--------------------------------------------------
       
  1883 
       
  1884 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::set_timer(
       
  1885 	abs_eap_base_timer_c * const p_initializer, 
       
  1886 	const u32_t p_id, 
       
  1887 	void * const p_data,
       
  1888 	const u32_t p_time_ms)
       
  1889 {
       
  1890 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1891 
       
  1892 	const eap_status_e status = m_am_tools->am_set_timer(
       
  1893 		p_initializer, 
       
  1894 		p_id, 
       
  1895 		p_data,
       
  1896 		p_time_ms);
       
  1897 
       
  1898 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1899 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1900 }
       
  1901 
       
  1902 //--------------------------------------------------
       
  1903 
       
  1904 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::cancel_timer(
       
  1905 	abs_eap_base_timer_c * const p_initializer, 
       
  1906 	const u32_t p_id)
       
  1907 {
       
  1908 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1909 
       
  1910 	const eap_status_e status = m_am_tools->am_cancel_timer(
       
  1911 		p_initializer, 
       
  1912 		p_id);
       
  1913 
       
  1914 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1915 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1916 }
       
  1917 
       
  1918 //--------------------------------------------------
       
  1919 
       
  1920 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::cancel_all_timers()
       
  1921 {
       
  1922 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1923 
       
  1924 	const eap_status_e status = m_am_tools->am_cancel_all_timers();
       
  1925 
       
  1926 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1927 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1928 }
       
  1929 
       
  1930 //--------------------------------------------------
       
  1931 
       
  1932 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::check_is_valid_eap_type(const eap_type_value_e eap_type)
       
  1933 {
       
  1934 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1935 
       
  1936 	eap_header_string_c eap_string;
       
  1937 	EAP_UNREFERENCED_PARAMETER(eap_string);
       
  1938 
       
  1939 	EAP_TRACE_DEBUG(
       
  1940 		m_am_tools,
       
  1941 		TRACE_FLAGS_DEFAULT,
       
  1942 		(EAPL("eapol_am_wlan_authentication_symbian_c::check_is_valid_eap_type():  %s, this = 0x%08x => 0x%08x, EAP-type=0x%08x=%s\n"),
       
  1943 		 (m_is_client == true) ? "client": "server",
       
  1944 		 this,
       
  1945 		 dynamic_cast<abs_eap_base_timer_c *>(this),
       
  1946 		convert_eap_type_to_u32_t(eap_type),
       
  1947 		eap_string.get_eap_type_string(eap_type)));
       
  1948 
       
  1949 #ifdef USE_EAP_EXPANDED_TYPES
       
  1950 
       
  1951 	for (int i = 0; i < m_enabled_expanded_eap_array.Count(); i++)
       
  1952 	{
       
  1953 		TBuf8<KExpandedEAPSize> tmpExpEAP(m_enabled_expanded_eap_array[i]->EapExpandedType);
       
  1954 
       
  1955 		EAP_TRACE_DEBUG(
       
  1956 			m_am_tools, 
       
  1957 			TRACE_FLAGS_DEFAULT, 
       
  1958 			(EAPL("eapol_am_wlan_authentication_symbian_c::check_is_valid_eap_type:Enabled expanded EAP type at index=%d\n"),
       
  1959 			 i));
       
  1960 
       
  1961 		EAP_TRACE_DATA_DEBUG(
       
  1962 			m_am_tools,
       
  1963 			TRACE_FLAGS_DEFAULT,
       
  1964 			(EAPL("Enabled expanded EAP type:"),
       
  1965 			tmpExpEAP.Ptr(),
       
  1966 			tmpExpEAP.Size()));
       
  1967 
       
  1968 		// This is for one expanded EAP type (for the above one).
       
  1969 		eap_expanded_type_c expandedEAPType;
       
  1970 				
       
  1971 		// Read the expanded EAP type details for this item in m_enabled_expanded_eap_array.
       
  1972 		eap_status_e status = eap_expanded_type_c::read_type(m_am_tools,
       
  1973 												0,
       
  1974 												tmpExpEAP.Ptr(),
       
  1975 												tmpExpEAP.Size(),
       
  1976 												&expandedEAPType);
       
  1977 		if (status != eap_status_ok)
       
  1978 		{
       
  1979 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1980 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1981 		}
       
  1982 
       
  1983 		if (eap_type == expandedEAPType)
       
  1984 		{
       
  1985 			// This is Allowed and Valid.
       
  1986 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1987 			return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  1988 		}
       
  1989 	}
       
  1990 		 
       
  1991 #else // For normal unexpanded EAP type
       
  1992 
       
  1993 	TEap *eapType = 0; 
       
  1994 	
       
  1995 	for (int i = 0; i < m_iap_eap_array.Count(); i++)
       
  1996 	{
       
  1997 		// Try next EAP type
       
  1998 		eapType = m_iap_eap_array[i];
       
  1999 		if (eapType->Enabled == 1)
       
  2000 		{	
       
  2001 			// Convert the string to integer
       
  2002 			TLex8 tmp(eapType->UID);
       
  2003 			TInt val(0);
       
  2004 			tmp.Val(val);
       
  2005 
       
  2006 			if (eap_type == static_cast<eap_type_ietf_values_e>(val))
       
  2007 			{
       
  2008 				// Allowed
       
  2009 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2010 				return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  2011 			}
       
  2012 		}
       
  2013 	}
       
  2014 	
       
  2015 #endif // #ifdef USE_EAP_EXPANDED_TYPES
       
  2016 	
       
  2017 	EAP_TRACE_DEBUG(
       
  2018 		m_am_tools,
       
  2019 		TRACE_FLAGS_DEFAULT,
       
  2020 		(EAPL("ERROR: %s: check_is_valid_eap_type(): not supported EAP-type=0x%08x=%s\n"),
       
  2021 		 (m_is_client == true ? "client": "server"),
       
  2022 		 convert_eap_type_to_u32_t(eap_type),
       
  2023 		 eap_string.get_eap_type_string(eap_type)));
       
  2024 
       
  2025 	
       
  2026 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2027 	return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_eap_type);
       
  2028 }
       
  2029 
       
  2030 //--------------------------------------------------
       
  2031 
       
  2032 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::get_eap_type_list(
       
  2033 	eap_array_c<eap_type_value_e> * const eap_type_list)
       
  2034 {
       
  2035 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2036 
       
  2037 	EAP_TRACE_DEBUG(
       
  2038 		m_am_tools, 
       
  2039 		TRACE_FLAGS_DEFAULT, 
       
  2040 		(EAPL("eapol_am_wlan_authentication_symbian_c::get_eap_type_list(): %s, this = 0x%08x => 0x%08x\n"),
       
  2041 		 (m_is_client == true) ? "client": "server",
       
  2042 		 this,
       
  2043 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
  2044 
       
  2045 
       
  2046 	eap_status_e status(eap_status_illegal_eap_type);
       
  2047 
       
  2048 	status = eap_type_list->reset();
       
  2049 	if (status != eap_status_ok)
       
  2050 	{
       
  2051 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2052 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2053 	}
       
  2054 
       
  2055 	eap_header_string_c eap_string;
       
  2056 	EAP_UNREFERENCED_PARAMETER(eap_string);
       
  2057 
       
  2058 #ifdef USE_EAP_EXPANDED_TYPES
       
  2059 
       
  2060 	// This function is same as get_selected_eap_types in behavior.
       
  2061 
       
  2062 	// We need to return only the EAP types available as enabled types.
       
  2063 	// It means only the ones available in m_enabled_expanded_eap_array.
       
  2064 	
       
  2065 	for (TInt i = 0; i < m_enabled_expanded_eap_array.Count(); i++)
       
  2066 	{	
       
  2067 		TBuf8<KExpandedEAPSize> tmpExpEAP(m_enabled_expanded_eap_array[i]->EapExpandedType);
       
  2068 
       
  2069 		EAP_TRACE_DEBUG(
       
  2070 			m_am_tools, 
       
  2071 			TRACE_FLAGS_DEFAULT, 
       
  2072 			(EAPL("eapol_am_wlan_authentication_symbian_c::get_eap_type_list:Enabled expanded EAP type at index=%d\n"),
       
  2073 			 i));
       
  2074 
       
  2075 		EAP_TRACE_DATA_DEBUG(
       
  2076 			m_am_tools,
       
  2077 			TRACE_FLAGS_DEFAULT,
       
  2078 			(EAPL("Enabled expanded EAP type:"),
       
  2079 			tmpExpEAP.Ptr(),
       
  2080 			tmpExpEAP.Size()));
       
  2081 
       
  2082 		// This is for one expanded EAP type (for the above one).
       
  2083 		eap_expanded_type_c * expandedEAPType = new eap_type_value_e();
       
  2084 				
       
  2085 		// Read the expanded EAP type details from an item in m_enabled_expanded_eap_array.
       
  2086 		status = eap_expanded_type_c::read_type(m_am_tools,
       
  2087 												0,
       
  2088 												tmpExpEAP.Ptr(),
       
  2089 												tmpExpEAP.Size(),
       
  2090 												expandedEAPType);
       
  2091 		if (status != eap_status_ok)
       
  2092 		{
       
  2093 			delete expandedEAPType;
       
  2094 			expandedEAPType = 0;
       
  2095 
       
  2096 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2097 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2098 		}
       
  2099 
       
  2100 		// Add EAP-type to list.		
       
  2101 		status = eap_type_list->add_object(expandedEAPType, true);
       
  2102 		if (status != eap_status_ok)
       
  2103 		{
       
  2104 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2105 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2106 		}		
       
  2107 			
       
  2108 		EAP_TRACE_DEBUG(
       
  2109 			m_am_tools,
       
  2110 			TRACE_FLAGS_DEFAULT,
       
  2111 			(EAPL("get_eap_type_list():added EAP-type=0x%08x=%s\n"),
       
  2112 			expandedEAPType->get_vendor_type(),
       
  2113 			eap_string.get_eap_type_string(*expandedEAPType)));			
       
  2114 	}
       
  2115 
       
  2116 #else // for normal EAP types.
       
  2117 
       
  2118 	TEap *eapType = 0; 
       
  2119 
       
  2120 	for (TInt i = 0; i < m_iap_eap_array.Count(); i++)
       
  2121 	{
       
  2122 		// Check if type is enabled
       
  2123 		eapType = m_iap_eap_array[i];
       
  2124 		if (eapType->Enabled == 1)
       
  2125 		{	
       
  2126 			TLex8 tmp(eapType->UID);
       
  2127 			TInt val(0);
       
  2128 			tmp.Val(val);
       
  2129 
       
  2130 			EAP_TRACE_DEBUG(
       
  2131 				m_am_tools,
       
  2132 				TRACE_FLAGS_DEFAULT,
       
  2133 				(EAPL("get_eap_type_list(): adds EAP-type=0x%08x=%s\n"),
       
  2134 				static_cast<eap_type_ietf_values_e>(val),
       
  2135 				eap_string.get_eap_type_string(
       
  2136 					static_cast<eap_type_value_e>(
       
  2137 						static_cast<eap_type_ietf_values_e>(val)))));
       
  2138 
       
  2139 			eap_type_value_e * const eap_type = new eap_type_value_e(
       
  2140 				static_cast<eap_type_ietf_values_e>(val));
       
  2141 			if (eap_type == 0)
       
  2142 			{
       
  2143 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2144 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  2145 			}
       
  2146 
       
  2147 			status = eap_type_list->add_object(eap_type, true);
       
  2148 			if (status != eap_status_ok)
       
  2149 			{
       
  2150 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2151 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2152 			}
       
  2153 		}
       
  2154 	}
       
  2155 
       
  2156 #endif // #ifdef USE_EAP_EXPANDED_TYPES
       
  2157 
       
  2158 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2159 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2160 }
       
  2161 
       
  2162 //--------------------------------------------------
       
  2163 
       
  2164 //
       
  2165 void eapol_am_wlan_authentication_symbian_c::RunL()
       
  2166 {
       
  2167 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  2168 	EAP_TRACE_DEBUG(
       
  2169 		m_am_tools,
       
  2170 		TRACE_FLAGS_DEFAULT,
       
  2171 		(EAPL("eapol_am_wlan_authentication_symbian_c::RunL(): iStatus.Int() = %d\n"),
       
  2172 		iStatus.Int()));
       
  2173 
       
  2174 	if (iStatus.Int() != KErrNone)
       
  2175 	{
       
  2176 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2177 		return;
       
  2178 	}
       
  2179 
       
  2180 	// Authentication cancelled.
       
  2181 	EAP_TRACE_ALWAYS(
       
  2182 		m_am_tools,
       
  2183 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
  2184 		(EAPL("Authentication cancelled.\n")));
       
  2185 
       
  2186 	eap_status_e status = m_am_partner->disassociation(
       
  2187 		&m_receive_network_id);
       
  2188 	if (status != eap_status_ok)
       
  2189 	{
       
  2190 		EAP_TRACE_DEBUG(
       
  2191 			m_am_tools,
       
  2192 			TRACE_FLAGS_DEFAULT,
       
  2193 			(EAPL("set_timer(EAPOL_AM_CORE_TIMER_DELETE_STACK_ID) failed in RunL().\n")));
       
  2194 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2195 		return;
       
  2196 	}
       
  2197 	
       
  2198 	// Reset index of current EAP-type.
       
  2199 	m_am_partner->set_current_eap_index(0ul);
       
  2200 
       
  2201 	EAP_TRACE_ALWAYS(
       
  2202 		m_am_tools,
       
  2203 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
  2204 		(EAPL("Indication sent to WLM: EFailedCompletely.\n")));
       
  2205 
       
  2206 	m_am_partner->eapol_indication(
       
  2207 		&m_receive_network_id,
       
  2208 		eapol_wlan_authentication_state_failed_completely);
       
  2209 
       
  2210 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  2211 }
       
  2212 
       
  2213 //--------------------------------------------------
       
  2214 
       
  2215 //
       
  2216 void eapol_am_wlan_authentication_symbian_c::DoCancel()
       
  2217 {	
       
  2218 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2219 
       
  2220 	EAP_TRACE_DEBUG(
       
  2221 		m_am_tools,
       
  2222 		TRACE_FLAGS_DEFAULT,
       
  2223 		(EAPL("eapol_am_wlan_authentication_symbian_c::DoCancel()\n")));
       
  2224 
       
  2225 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  2226 }
       
  2227 
       
  2228 //--------------------------------------------------
       
  2229 
       
  2230 void eapol_am_wlan_authentication_symbian_c::RetrievePSKL(TPSKEntry& entry)
       
  2231 {
       
  2232 
       
  2233 	// Open database
       
  2234 	RDbNamedDatabase db;
       
  2235 
       
  2236 #ifdef SYMBIAN_SECURE_DBMS
       
  2237 	User::LeaveIfError(db.Open(m_session, KDatabaseName, KSecureUIDFormat));	
       
  2238 #else			
       
  2239 	User::LeaveIfError(db.Open(m_session, KDatabaseName));
       
  2240 #endif // #ifdef SYMBIAN_SECURE_DBMS		
       
  2241 	
       
  2242 	CleanupClosePushL(db);
       
  2243 
       
  2244 	HBufC* sqlbuf = HBufC::NewLC(KMaxSqlQueryLength);
       
  2245 	TPtr sqlStatement = sqlbuf->Des();
       
  2246 
       
  2247 	RDbView view;
       
  2248 
       
  2249 	CleanupClosePushL(view);
       
  2250 
       
  2251 	_LIT(KSQL, "SELECT %S, %S, %S, %S, %S FROM %S WHERE %S=%d AND %S=%d");
       
  2252 
       
  2253 	sqlStatement.Format(KSQL, &KServiceType, &KServiceIndex, &KSSID, &KPassword, &KPSK,
       
  2254 		&KEapolPSKTableName, &KServiceType, entry.indexType, &KServiceIndex, entry.index);
       
  2255 		
       
  2256 	User::LeaveIfError(view.Prepare(db, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  2257 	User::LeaveIfError(view.EvaluateAll());	
       
  2258 
       
  2259 	TInt rows = view.CountL();
       
  2260 	
       
  2261 	if (rows == 0)
       
  2262 	{
       
  2263 		// No saved PSK
       
  2264 		User::Leave(KErrNotFound);
       
  2265 	}
       
  2266 	view.FirstL();
       
  2267 	view.GetL();
       
  2268 
       
  2269 	entry.ssid.Copy(view.ColDes8(3));
       
  2270 	entry.password.Copy(view.ColDes8(4));
       
  2271 	entry.psk.Copy(view.ColDes8(5));
       
  2272 
       
  2273 	CleanupStack::PopAndDestroy(3); // view, buf, database
       
  2274 }
       
  2275 
       
  2276 //--------------------------------------------------
       
  2277 
       
  2278 void eapol_am_wlan_authentication_symbian_c::SavePSKL(TPSKEntry& entry)
       
  2279 {
       
  2280 	// Connect to CommDBif so that we can delete PSK entries that have no IAP associated anymore.
       
  2281 	CWLanSettings* wlan_settings = new(ELeave) CWLanSettings;
       
  2282 	CleanupStack::PushL(wlan_settings);
       
  2283 	
       
  2284 	SWLANSettings wlanSettings;
       
  2285 
       
  2286 	if (wlan_settings->Connect() != KErrNone)
       
  2287 	{
       
  2288 		// Could not connect to CommDB			
       
  2289 		User::Leave(KErrCouldNotConnect);
       
  2290 	}
       
  2291 
       
  2292 	// Open database
       
  2293 	RDbNamedDatabase db;
       
  2294 
       
  2295 #ifdef SYMBIAN_SECURE_DBMS
       
  2296 	User::LeaveIfError(db.Open(m_session, KDatabaseName, KSecureUIDFormat));	
       
  2297 #else			
       
  2298 	User::LeaveIfError(db.Open(m_session, KDatabaseName));
       
  2299 #endif // #ifdef SYMBIAN_SECURE_DBMS		
       
  2300 	
       
  2301 	CleanupClosePushL(db);
       
  2302 
       
  2303 	HBufC* sqlbuf = HBufC::NewLC(KMaxSqlQueryLength);
       
  2304 	TPtr sqlStatement = sqlbuf->Des();
       
  2305 
       
  2306 	RDbView view;
       
  2307 
       
  2308 	_LIT(KSQL, "SELECT %S, %S, %S, %S, %S FROM %S");
       
  2309 	
       
  2310 	sqlStatement.Format(KSQL, &KServiceType, &KServiceIndex, &KSSID, &KPassword, &KPSK,
       
  2311 		&KEapolPSKTableName);
       
  2312 
       
  2313 	User::LeaveIfError(view.Prepare(db, TDbQuery(sqlStatement), TDbWindow::EUnlimited));	
       
  2314 	CleanupClosePushL(view);
       
  2315 	User::LeaveIfError(view.EvaluateAll());
       
  2316 	
       
  2317 	// Get column set so we get the correct column numbers
       
  2318 	CDbColSet* colSet = view.ColSetL();		
       
  2319 	CleanupStack::PushL(colSet);
       
  2320 	
       
  2321 	// Delete old row and also rows that have no associated IAP settings.
       
  2322 	if (view.FirstL())
       
  2323 	{		
       
  2324 		do {
       
  2325 			view.GetL();
       
  2326 
       
  2327 			if ((wlan_settings->GetWlanSettingsForService(view.ColUint32(colSet->ColNo(KServiceIndex)), wlanSettings) != KErrNone)
       
  2328 				|| (view.ColUint32(colSet->ColNo(KServiceType)) == static_cast<TUint>(entry.indexType)
       
  2329 					&& view.ColUint32(colSet->ColNo(KServiceIndex)) == static_cast<TUint>(entry.index)))
       
  2330 			{	
       
  2331 				// Not found or current IAP
       
  2332 				view.DeleteL();	
       
  2333 			}
       
  2334 			
       
  2335 		} while (view.NextL() != EFalse);
       
  2336 	}
       
  2337 
       
  2338 	wlan_settings->Disconnect();
       
  2339 	
       
  2340 	view.InsertL();
       
  2341 	
       
  2342 	view.SetColL(colSet->ColNo(KServiceType), (TUint)entry.indexType);
       
  2343 	view.SetColL(colSet->ColNo(KServiceIndex), (TUint)entry.index);
       
  2344 	view.SetColL(colSet->ColNo(KSSID), entry.ssid);
       
  2345 	view.SetColL(colSet->ColNo(KPassword), entry.password);
       
  2346 	view.SetColL(colSet->ColNo(KPSK), entry.psk);	
       
  2347 	
       
  2348 	view.PutL();
       
  2349 	
       
  2350 	CleanupStack::PopAndDestroy( colSet ); // Delete colSet.	
       
  2351 
       
  2352 	CleanupStack::PopAndDestroy(4); // CWLanSettings, database, buffer, view
       
  2353 
       
  2354 }
       
  2355 														 
       
  2356 //--------------------------------------------------
       
  2357 
       
  2358 //
       
  2359 void eapol_am_wlan_authentication_symbian_c::ReadEAPSettingsL()
       
  2360 {
       
  2361 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2362 
       
  2363 	EAP_TRACE_DEBUG(
       
  2364 		m_am_tools, 
       
  2365 		TRACE_FLAGS_DEFAULT, 
       
  2366 		(EAPL("eapol_am_wlan_authentication_symbian_c::ReadEAPSettingsL(): %s, this = 0x%08x => 0x%08x\n"),
       
  2367 		 (m_is_client == true) ? "client": "server",
       
  2368 		 this,
       
  2369 		 dynamic_cast<abs_eap_base_timer_c *>(this)));
       
  2370 
       
  2371 	eap_status_e status(eap_status_ok);
       
  2372 
       
  2373 	status = reset_eap_plugins();
       
  2374 	if (status != eap_status_ok)
       
  2375 	{
       
  2376 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2377 		User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2378 	}
       
  2379 
       
  2380 	TIndexType index_type(ELan);
       
  2381 	TUint index(0UL);
       
  2382 
       
  2383 	status = read_database_reference_values(
       
  2384 		&index_type,
       
  2385 		&index);
       
  2386 	if (status != eap_status_ok)
       
  2387 	{
       
  2388 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2389 		User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2390 	}
       
  2391 
       
  2392 	if (index_type == ELan)
       
  2393 	{
       
  2394 		EAP_TRACE_DEBUG(
       
  2395 			m_am_tools,
       
  2396 			TRACE_FLAGS_DEFAULT,
       
  2397 			(EAPL("Beginning to read IAP settings - Type: %d, Index: %d.\n"), index_type, index));
       
  2398 
       
  2399 		CWLanSettings* wlan_settings = new(ELeave) CWLanSettings;
       
  2400 		CleanupStack::PushL(wlan_settings);
       
  2401 		SWLANSettings wlanSettings;
       
  2402 		if (wlan_settings->Connect() != KErrNone)
       
  2403 		{
       
  2404 			// Could not connect to CommDB			
       
  2405 			User::Leave(KErrCouldNotConnect);
       
  2406 		}
       
  2407 
       
  2408 		EAP_TRACE_DEBUG(
       
  2409 			m_am_tools,
       
  2410 			TRACE_FLAGS_DEFAULT, (EAPL("Connected to CommDbIf.\n")));
       
  2411 
       
  2412 		if (wlan_settings->GetWlanSettingsForService(index, wlanSettings) != KErrNone)
       
  2413 		{
       
  2414 			wlan_settings->Disconnect();
       
  2415 			User::Leave(KErrUnknown);
       
  2416 		}
       
  2417 
       
  2418 		EAP_TRACE_DEBUG(
       
  2419 			m_am_tools,
       
  2420 			TRACE_FLAGS_DEFAULT,
       
  2421 			(EAPL("Got WLAN settings: wlanSettings.EnableWpaPsk=%d, m_WPA_override_enabled=%d\n"),
       
  2422 			wlanSettings.EnableWpaPsk,
       
  2423 			m_WPA_override_enabled));
       
  2424 
       
  2425 		EAP_TRACE_DATA_DEBUG(
       
  2426 			m_am_tools,
       
  2427 			TRACE_FLAGS_DEFAULT,
       
  2428 			(EAPL("WPA-PSK"),
       
  2429 			wlanSettings.WPAPreSharedKey.Ptr(),
       
  2430 			wlanSettings.WPAPreSharedKey.Size()));
       
  2431 
       
  2432 #ifdef USE_EAP_EXPANDED_TYPES
       
  2433 
       
  2434 		EAP_TRACE_DEBUG(
       
  2435 			m_am_tools,
       
  2436 			TRACE_FLAGS_DEFAULT,
       
  2437 			(EAPL("Beginning to read EAP Data using new Comm_DB_if for expanded eap type\n")));
       
  2438 
       
  2439 		wlan_settings->GetEapDataL(m_enabled_expanded_eap_array, m_disabled_expanded_eap_array);
       
  2440 
       
  2441 		EAP_TRACE_DEBUG(
       
  2442 			m_am_tools,
       
  2443 			TRACE_FLAGS_DEFAULT,
       
  2444 			(EAPL("Enabled EAP count=%d, Disabled EAP count=%d\n"),
       
  2445 			m_enabled_expanded_eap_array.Count(), m_disabled_expanded_eap_array.Count()));
       
  2446 
       
  2447 			
       
  2448 	
       
  2449 #else
       
  2450 		// Without expanded EAP type. Normal EAP type stuff.
       
  2451 		wlan_settings->GetEapDataL(m_iap_eap_array);
       
  2452 
       
  2453 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  2454 
       
  2455 		
       
  2456 		EAP_TRACE_DEBUG(
       
  2457 			m_am_tools,
       
  2458 			TRACE_FLAGS_DEFAULT,
       
  2459 			(EAPL("Got EAP data:\n")));
       
  2460 
       
  2461 #ifdef USE_EAP_EXPANDED_TYPES
       
  2462 
       
  2463 		// Reading enabled.
       
  2464 		for (TInt i = 0; i < m_enabled_expanded_eap_array.Count(); i++)
       
  2465 		{	
       
  2466 			TBuf8<KExpandedEAPSize> tmpExpEAP(m_enabled_expanded_eap_array[i]->EapExpandedType);
       
  2467 
       
  2468 			EAP_TRACE_DEBUG(
       
  2469 				m_am_tools, 
       
  2470 				TRACE_FLAGS_DEFAULT, 
       
  2471 				(EAPL("eapol_am_wlan_authentication_symbian_c::ReadEAPSettingsL:Enabled expanded EAP type at index=%d\n"),
       
  2472 				 i));
       
  2473 
       
  2474 			EAP_TRACE_DATA_DEBUG(
       
  2475 				m_am_tools,
       
  2476 				TRACE_FLAGS_DEFAULT,
       
  2477 				(EAPL("Enabled expanded EAP type:"),
       
  2478 				tmpExpEAP.Ptr(),
       
  2479 				tmpExpEAP.Size()));
       
  2480 		}
       
  2481 
       
  2482 		// Now reading disabled.
       
  2483 		for (TInt i = 0; i < m_disabled_expanded_eap_array.Count(); i++)
       
  2484 		{	
       
  2485 			TBuf8<KExpandedEAPSize> tmpExpEAP(m_disabled_expanded_eap_array[i]->EapExpandedType);
       
  2486 
       
  2487 			EAP_TRACE_DEBUG(
       
  2488 				m_am_tools, 
       
  2489 				TRACE_FLAGS_DEFAULT, 
       
  2490 				(EAPL("eapol_am_wlan_authentication_symbian_c::ReadEAPSettingsL:Disabled expanded EAP type at index=%d\n"),
       
  2491 				 i));
       
  2492 
       
  2493 			EAP_TRACE_DATA_DEBUG(
       
  2494 				m_am_tools,
       
  2495 				TRACE_FLAGS_DEFAULT,
       
  2496 				(EAPL("Disabled expanded EAP type:"),
       
  2497 				tmpExpEAP.Ptr(),
       
  2498 				tmpExpEAP.Size()));
       
  2499 		}
       
  2500 
       
  2501 #else // Normal EAP type.
       
  2502 
       
  2503 		for (TInt i = 0; i < m_iap_eap_array.Count(); i++)
       
  2504 		{
       
  2505 			EAP_TRACE_DEBUG(
       
  2506 				m_am_tools,
       
  2507 				TRACE_FLAGS_DEFAULT,
       
  2508 				(EAPL("EAP type %d\n"),
       
  2509 				i));
       
  2510 
       
  2511 			TLex8 tmp(m_iap_eap_array[i]->UID);
       
  2512 			TInt val(0);
       
  2513 			tmp.Val(val);
       
  2514 		
       
  2515 			EAP_TRACE_DEBUG(
       
  2516 				m_am_tools,
       
  2517 				TRACE_FLAGS_DEFAULT,
       
  2518 				(EAPL("  UID: %d\n"), val));
       
  2519 			EAP_TRACE_DEBUG(
       
  2520 				m_am_tools,
       
  2521 				TRACE_FLAGS_DEFAULT,
       
  2522 				(EAPL("  Enabled: %d\n"),
       
  2523 				m_iap_eap_array[i]->Enabled));
       
  2524 		}
       
  2525 
       
  2526 #endif // #ifdef USE_EAP_EXPANDED_TYPES
       
  2527 
       
  2528 		EAP_TRACE_DEBUG(
       
  2529 			m_am_tools,
       
  2530 			TRACE_FLAGS_DEFAULT,
       
  2531 			(EAPL("End EAP data:\n")));
       
  2532 
       
  2533 
       
  2534 #ifndef USE_EAP_EXPANDED_TYPES
       
  2535 
       
  2536 // There can not be a situation where all EAPs are disabled.
       
  2537 
       
  2538 		if (m_iap_eap_array.Count() == 0)
       
  2539 		{
       
  2540 
       
  2541 #if defined(USE_EAP_ALLOW_ALL_EAP_TYPES_WHEN_NONE_IS_ACTIVATED_IN_CONFIGURATION)
       
  2542 
       
  2543 			// The EAP field was empty. Allow all types.
       
  2544 
       
  2545 			EAP_TRACE_DEBUG(
       
  2546 				m_am_tools,
       
  2547 				TRACE_FLAGS_DEFAULT,
       
  2548 				(EAPL("Empty EAP field -> enable all types.\n")));
       
  2549 
       
  2550 			RImplInfoPtrArray eapArray;
       
  2551 			
       
  2552 			REComSession::ListImplementationsL(KEapTypeInterfaceUid, eapArray);
       
  2553 		
       
  2554 			TEap *eap;
       
  2555 			for (TInt i = 0; i < eapArray.Count(); i++)
       
  2556 			{
       
  2557 				eap = new(ELeave) TEap;
       
  2558 				eap->UID.Copy(eapArray[i]->DataType());
       
  2559 				eap->Enabled = ETrue;
       
  2560 				m_iap_eap_array.Append(eap);
       
  2561 			}
       
  2562 
       
  2563 			eapArray.ResetAndDestroy();
       
  2564 
       
  2565 #else
       
  2566 
       
  2567 			// The EAP field was empty. Allow EAP-SIM only.
       
  2568 
       
  2569 			EAP_TRACE_DEBUG(
       
  2570 				m_am_tools,
       
  2571 				TRACE_FLAGS_DEFAULT,
       
  2572 				(EAPL("Empty EAP field -> enable EAP-SIM only.\n")));
       
  2573 
       
  2574 			{
       
  2575 				TBuf8<3> eap_sim_uid = _L8("018");
       
  2576 
       
  2577 				TEap *eap = new(ELeave) TEap;
       
  2578 				eap->UID.Copy(eap_sim_uid);
       
  2579 				eap->Enabled = ETrue;
       
  2580 				m_iap_eap_array.Append(eap);
       
  2581 			}
       
  2582 
       
  2583 #endif //#if defined(USE_EAP_ALLOW_ALL_EAP_TYPES_WHEN_NONE_IS_ACTIVATED_IN_CONFIGURATION)
       
  2584 
       
  2585 		}
       
  2586 
       
  2587 #endif // #ifndef USE_EAP_EXPANDED_TYPES
       
  2588 
       
  2589 		// Get security mode
       
  2590 		if (m_WPA_override_enabled == false)
       
  2591 		{
       
  2592 			m_security_mode = static_cast<EWlanSecurityMode>(wlanSettings.SecurityMode);
       
  2593 		}
       
  2594 		else
       
  2595 		{
       
  2596 			// WPA override is enabled
       
  2597 			m_security_mode = Wpa;
       
  2598 		}
       
  2599 
       
  2600 		// Get WPA pre shared key & SSID
       
  2601 		if (m_is_client == true
       
  2602 			&& (wlanSettings.EnableWpaPsk
       
  2603 				|| m_WPA_override_enabled == true)
       
  2604 			&& (m_selected_eapol_key_authentication_type == eapol_key_authentication_type_RSNA_PSK
       
  2605 				|| m_selected_eapol_key_authentication_type == eapol_key_authentication_type_WPA_PSK))
       
  2606 		{
       
  2607 			EAP_TRACE_DEBUG(
       
  2608 				m_am_tools,
       
  2609 				TRACE_FLAGS_DEFAULT,
       
  2610 				(EAPL("Uses WPAPSK: wlanSettings.EnableWpaPsk=%d\n"),
       
  2611 				wlanSettings.EnableWpaPsk));
       
  2612 
       
  2613 			// When not using easy WLAN there is no WPA PSK override.
       
  2614 			if (m_WPA_override_enabled == false)
       
  2615 			{
       
  2616 				status = m_wpa_preshared_key.set_copy_of_buffer(
       
  2617 					wlanSettings.WPAPreSharedKey.Ptr(),
       
  2618 					wlanSettings.WPAPreSharedKey.Size());
       
  2619 				if (status != eap_status_ok)
       
  2620 				{
       
  2621 					send_error_notification(eap_status_key_error);
       
  2622 					wlan_settings->Disconnect();
       
  2623 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2624 					User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2625 				}
       
  2626 
       
  2627 				// Here we copy the SSID read from IAP.
       
  2628 				TBuf8<K_Max_SSID_Length> tmp;
       
  2629 				tmp.Copy(wlanSettings.SSID);
       
  2630 				status = m_SSID.set_copy_of_buffer(tmp.Ptr(), tmp.Size());
       
  2631 				if (status != eap_status_ok)
       
  2632 				{
       
  2633 					wlan_settings->Disconnect();
       
  2634 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2635 					User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2636 				}
       
  2637 			}
       
  2638 			else
       
  2639 			{
       
  2640 				// In override mode SSID is stored to m_SSID
       
  2641 				// and password is stored to m_wpa_preshared_key.
       
  2642 			}
       
  2643 
       
  2644 			TPSKEntry pskEntry;
       
  2645 			pskEntry.indexType = index_type;
       
  2646 			pskEntry.index = index;
       
  2647 			pskEntry.ssid.Zero();
       
  2648 			pskEntry.password.Zero();
       
  2649 			pskEntry.psk.Zero();
       
  2650 
       
  2651             TInt err(KErrNone);
       
  2652 
       
  2653 			// Retrieve saved PSK only when override is not in effect
       
  2654 			TRAP(err, RetrievePSKL(pskEntry));
       
  2655 			
       
  2656 			if (err != KErrNone
       
  2657 				|| m_SSID.compare(pskEntry.ssid.Ptr(), pskEntry.ssid.Size()) != 0
       
  2658 				|| m_wpa_preshared_key.compare(pskEntry.password.Ptr(), pskEntry.password.Size()) != 0)
       
  2659 			{
       
  2660 				// No previous PSK or parameters were changed.
       
  2661 				// We need to calculate PSK again
       
  2662 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("No previous PSK found...\n")));
       
  2663 
       
  2664 				crypto_wpa_psk_password_hash_c password_hash(m_am_tools);
       
  2665 
       
  2666 				if (m_wpa_preshared_key.get_data_length() == 2ul*EAPOL_WPA_PSK_LENGTH_BYTES)
       
  2667 				{
       
  2668 					// This is hex ascii 64-digit WWPA-PSK.
       
  2669 					// Convert it to 32 octets.
       
  2670 					u32_t target_length(EAPOL_WPA_PSK_LENGTH_BYTES);
       
  2671 
       
  2672 					status = m_wpa_preshared_key_hash.set_buffer_length(EAPOL_WPA_PSK_LENGTH_BYTES);
       
  2673 					if (status != eap_status_ok)
       
  2674 					{
       
  2675 						send_error_notification(eap_status_key_error);
       
  2676 						wlan_settings->Disconnect();							
       
  2677 						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2678 						User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2679 					}
       
  2680 
       
  2681 					status = m_wpa_preshared_key_hash.set_data_length(EAPOL_WPA_PSK_LENGTH_BYTES);
       
  2682 					if (status != eap_status_ok)
       
  2683 					{
       
  2684 						send_error_notification(eap_status_key_error);
       
  2685 						wlan_settings->Disconnect();							
       
  2686 						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2687 						User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2688 					}
       
  2689 
       
  2690 					status = m_am_tools->convert_hex_ascii_to_bytes(
       
  2691 						m_wpa_preshared_key.get_data(m_wpa_preshared_key.get_data_length()),
       
  2692 						m_wpa_preshared_key.get_data_length(),
       
  2693 						m_wpa_preshared_key_hash.get_data(EAPOL_WPA_PSK_LENGTH_BYTES),
       
  2694 						&target_length);
       
  2695 					if (status != eap_status_ok
       
  2696 						|| target_length != EAPOL_WPA_PSK_LENGTH_BYTES)
       
  2697 					{
       
  2698 						send_error_notification(eap_status_key_error);
       
  2699 						wlan_settings->Disconnect();							
       
  2700 						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2701 						User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2702 					}
       
  2703 				}
       
  2704 				else
       
  2705 				{
       
  2706 					status = password_hash.password_hash(
       
  2707 						&m_wpa_preshared_key,
       
  2708 						&m_SSID,	
       
  2709 						&m_wpa_preshared_key_hash,
       
  2710 						0,
       
  2711 						0);
       
  2712 
       
  2713 					if (status != eap_status_ok)
       
  2714 					{
       
  2715 						send_error_notification(eap_status_key_error);
       
  2716 						wlan_settings->Disconnect();							
       
  2717 						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2718 						User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2719 					}
       
  2720 				}
       
  2721 
       
  2722 				EAP_TRACE_DATA_DEBUG(
       
  2723 					m_am_tools,
       
  2724 					TRACE_FLAGS_DEFAULT,
       
  2725 					(EAPL("new WPA-PSK SSID"),
       
  2726 					m_SSID.get_data(),
       
  2727 					m_SSID.get_data_length()));
       
  2728 				
       
  2729 				EAP_TRACE_DATA_DEBUG(
       
  2730 					m_am_tools,
       
  2731 					TRACE_FLAGS_DEFAULT,
       
  2732 					(EAPL("new WPA-PSK preshared key"),
       
  2733 					m_wpa_preshared_key.get_data(),
       
  2734 					m_wpa_preshared_key.get_data_length()));
       
  2735 				
       
  2736 				EAP_TRACE_DATA_DEBUG(
       
  2737 					m_am_tools,
       
  2738 					TRACE_FLAGS_DEFAULT,
       
  2739 					(EAPL("new WPA-PSK hash"),
       
  2740 					m_wpa_preshared_key_hash.get_data(),
       
  2741 					m_wpa_preshared_key_hash.get_data_length()));
       
  2742 				
       
  2743 				// Save new PSK.
       
  2744 				pskEntry.ssid.Copy(
       
  2745 					m_SSID.get_data(),
       
  2746 					m_SSID.get_data_length()
       
  2747 					);
       
  2748 			
       
  2749 				pskEntry.password.Copy(
       
  2750 					m_wpa_preshared_key.get_data(),
       
  2751 					m_wpa_preshared_key.get_data_length()
       
  2752 					);
       
  2753 				
       
  2754 				pskEntry.psk.Copy(
       
  2755 					m_wpa_preshared_key_hash.get_data(),
       
  2756 					m_wpa_preshared_key_hash.get_data_length()
       
  2757 					);
       
  2758 
       
  2759 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Saving PSK.\n")));
       
  2760 
       
  2761 				SavePSKL(pskEntry);
       
  2762 			}
       
  2763 			else
       
  2764 			{
       
  2765 				// Copy retrieved WPAPSK hash to member variable
       
  2766 				status = m_wpa_preshared_key_hash.set_copy_of_buffer(pskEntry.psk.Ptr(), pskEntry.psk.Size());
       
  2767 				if (status != eap_status_ok)
       
  2768 				{
       
  2769 					send_error_notification(eap_status_key_error);
       
  2770 					wlan_settings->Disconnect();
       
  2771 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2772 					User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2773 				}
       
  2774 
       
  2775 				EAP_TRACE_DATA_DEBUG(
       
  2776 					m_am_tools,
       
  2777 					TRACE_FLAGS_DEFAULT,
       
  2778 					(EAPL("old WPA-PSK SSID"),
       
  2779 					m_SSID.get_data(),
       
  2780 					m_SSID.get_data_length()));
       
  2781 				
       
  2782 				EAP_TRACE_DATA_DEBUG(
       
  2783 					m_am_tools,
       
  2784 					TRACE_FLAGS_DEFAULT,
       
  2785 					(EAPL("old WPA-PSK preshared key"),
       
  2786 					m_wpa_preshared_key.get_data(),
       
  2787 					m_wpa_preshared_key.get_data_length()));
       
  2788 				
       
  2789 				EAP_TRACE_DATA_DEBUG(
       
  2790 					m_am_tools,
       
  2791 					TRACE_FLAGS_DEFAULT,
       
  2792 					(EAPL("old WPA-PSK hash"),
       
  2793 					m_wpa_preshared_key_hash.get_data(),
       
  2794 					m_wpa_preshared_key_hash.get_data_length()));
       
  2795 			}
       
  2796 		}
       
  2797 		
       
  2798 		wlan_settings->Disconnect();
       
  2799 		CleanupStack::PopAndDestroy(wlan_settings);
       
  2800 
       
  2801 		if (m_security_mode != Wlan8021x
       
  2802 			&& m_security_mode != Wpa
       
  2803 			&& m_security_mode != Wpa2Only)
       
  2804 		{
       
  2805 			// Unsupported mode
       
  2806 			User::Leave(KErrNotSupported);
       
  2807 		}
       
  2808 	} 
       
  2809 	else
       
  2810 	{
       
  2811 		// At the moment only LAN bearer is supported.
       
  2812 		User::Leave(KErrNotSupported);
       
  2813 	}
       
  2814 
       
  2815 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2816 }
       
  2817 
       
  2818 //--------------------------------------------------
       
  2819 
       
  2820 #ifdef USE_EAP_EXPANDED_TYPES
       
  2821 
       
  2822 void eapol_am_wlan_authentication_symbian_c::SetToTopPriorityL(const eap_type_value_e aEapType)
       
  2823 {
       
  2824 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2825 
       
  2826 	EAP_TRACE_DEBUG(
       
  2827 		m_am_tools,
       
  2828 		TRACE_FLAGS_DEFAULT,
       
  2829 		(EAPL("eapol_am_wlan_authentication_symbian_c::SetToTopPriorityL() - for EXP EAP types\n")));
       
  2830 
       
  2831 	TIndexType index_type(ELan);
       
  2832 	TUint index(0UL);
       
  2833 	TInt priorityIndex (0);
       
  2834 
       
  2835 	eap_status_e status = read_database_reference_values(
       
  2836 		&index_type,
       
  2837 		&index);
       
  2838 	if (status != eap_status_ok)
       
  2839 	{
       
  2840 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2841 		User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2842 	}
       
  2843 
       
  2844 	if (index_type == ELan)
       
  2845 	{
       
  2846 		for (TInt i = 0; i < m_enabled_expanded_eap_array.Count(); i++)
       
  2847 		{
       
  2848 			TBuf8<KExpandedEAPSize> tmpExpEAP(m_enabled_expanded_eap_array[i]->EapExpandedType);
       
  2849 
       
  2850 			EAP_TRACE_DEBUG(
       
  2851 				m_am_tools, 
       
  2852 				TRACE_FLAGS_DEFAULT, 
       
  2853 				(EAPL("eapol_am_wlan_authentication_symbian_c::SetToTopPriorityL:Enabled expanded EAP type at index=%d\n"),
       
  2854 				 i));
       
  2855 
       
  2856 			EAP_TRACE_DATA_DEBUG(
       
  2857 				m_am_tools,
       
  2858 				TRACE_FLAGS_DEFAULT,
       
  2859 				(EAPL("Enabled expanded EAP type:"),
       
  2860 				tmpExpEAP.Ptr(),
       
  2861 				tmpExpEAP.Size()));
       
  2862 
       
  2863 			// This is for one expanded EAP type (for the above one).
       
  2864 			eap_expanded_type_c expandedEAPType;
       
  2865 					
       
  2866 			// Read the expanded EAP type details for this item in m_enabled_expanded_eap_array.
       
  2867 			eap_status_e status = eap_expanded_type_c::read_type(m_am_tools,
       
  2868 													0,
       
  2869 													tmpExpEAP.Ptr(),
       
  2870 													tmpExpEAP.Size(),
       
  2871 													&expandedEAPType);
       
  2872 			if (status != eap_status_ok)
       
  2873 			{
       
  2874 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2875 				User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2876 			}
       
  2877 
       
  2878 			if (aEapType == expandedEAPType)
       
  2879 			{
       
  2880 				// Found it. This is the EAP type which should be at top priority.
       
  2881 				priorityIndex = i;
       
  2882 				break;
       
  2883 			}
       
  2884 		}	
       
  2885 				
       
  2886 		if(priorityIndex == 0)
       
  2887 		{
       
  2888 			// This means this EAP type is already at the top priority.
       
  2889 
       
  2890 			EAP_TRACE_DEBUG(
       
  2891 				m_am_tools,
       
  2892 				TRACE_FLAGS_DEFAULT,
       
  2893 				(EAPL("eapol_am_wlan_authentication_symbian_c::SetToTopPriorityL() - This is already at top\n")));
       
  2894 			
       
  2895 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2896 			return;
       
  2897 		}
       
  2898 
       
  2899 		if (priorityIndex >= m_enabled_expanded_eap_array.Count())
       
  2900 		{
       
  2901 			// No such EAP type in enabled list. This should never happen.
       
  2902 			EAP_TRACE_DEBUG(
       
  2903 				m_am_tools,
       
  2904 				TRACE_FLAGS_DEFAULT,
       
  2905 				(EAPL("ERROR: eapol_am_wlan_authentication_symbian_c::SetToTopPriorityL() - No such EAP in the enabled list\n")));
       
  2906 			
       
  2907 			User::Leave(KErrNotFound);					
       
  2908 		}
       
  2909 
       
  2910 		CWLanSettings* wlan = new(ELeave) CWLanSettings;
       
  2911 		CleanupStack::PushL(wlan);
       
  2912 		SWLANSettings wlanSettings;
       
  2913 		if (wlan->Connect() != KErrNone)
       
  2914 		{
       
  2915 			// Could not connect to CommDB			
       
  2916 			User::Leave(KErrCouldNotConnect);
       
  2917 		}
       
  2918 		
       
  2919 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("SetToTopPriorityL():Connected to CommDbIf.\n")));
       
  2920 
       
  2921 		if (wlan->GetWlanSettingsForService(index, wlanSettings) != KErrNone)
       
  2922 		{
       
  2923 			wlan->Disconnect();
       
  2924 			User::Leave(KErrUnknown);
       
  2925 		}
       
  2926 		
       
  2927 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("SetToTopPriorityL():Got WLAN settings.\n")));
       
  2928 		
       
  2929 		// Change the order
       
  2930 		SEapExpandedType* TopPriorityEAP(m_enabled_expanded_eap_array[priorityIndex]);
       
  2931 
       
  2932 		m_enabled_expanded_eap_array.Remove(priorityIndex); // This does not delete the object	
       
  2933 				
       
  2934 		m_enabled_expanded_eap_array.Insert(TopPriorityEAP, 0); // Insert in the beginning.
       
  2935 
       
  2936 		wlan->SetEapDataL(m_enabled_expanded_eap_array, m_disabled_expanded_eap_array);
       
  2937 		
       
  2938 		wlan->Disconnect();
       
  2939 
       
  2940 		CleanupStack::PopAndDestroy(wlan);		
       
  2941 	} 
       
  2942 	else
       
  2943 	{
       
  2944 		// At the moment only LAN bearer is supported.
       
  2945 
       
  2946 		EAP_TRACE_DEBUG(
       
  2947 			m_am_tools,
       
  2948 			TRACE_FLAGS_DEFAULT,
       
  2949 			(EAPL("eapol_am_wlan_authentication_symbian_c::SetToTopPriorityL() - LEAVE - only LAN bearer is supported\n")));
       
  2950 		
       
  2951 		User::Leave(KErrNotSupported);
       
  2952 	}
       
  2953 		
       
  2954 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2955 }
       
  2956 
       
  2957 #else // For normal EAP types
       
  2958 
       
  2959 void eapol_am_wlan_authentication_symbian_c::SetToTopPriorityL(const TEap* const aEapType)
       
  2960 {
       
  2961 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2962 
       
  2963 	EAP_TRACE_DEBUG(
       
  2964 		m_am_tools,
       
  2965 		TRACE_FLAGS_DEFAULT,
       
  2966 		(EAPL("eapol_am_wlan_authentication_symbian_c::SetToTopPriorityL()\n")));
       
  2967 
       
  2968 	TIndexType index_type(ELan);
       
  2969 	TUint index(0UL);
       
  2970 
       
  2971 	eap_status_e status = read_database_reference_values(
       
  2972 		&index_type,
       
  2973 		&index);
       
  2974 	if (status != eap_status_ok)
       
  2975 	{
       
  2976 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2977 		User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
       
  2978 	}
       
  2979 
       
  2980 	if (index_type == ELan)
       
  2981 	{
       
  2982 		TInt i(0);
       
  2983 		TBuf8<3> uid;
       
  2984 		for (i = 0; i < m_iap_eap_array.Count(); i++)
       
  2985 		{
       
  2986 			TEap* eap = m_iap_eap_array[i];
       
  2987 			if (eap->UID[0] == '0')
       
  2988 			{
       
  2989 				// Cut the leading zero
       
  2990 				uid.Copy(eap->UID.Right(eap->UID.Length()-1));				
       
  2991 			}
       
  2992 			else
       
  2993 			{
       
  2994 				uid.Copy(eap->UID);
       
  2995 			}
       
  2996 			if (eap->Enabled == aEapType->Enabled
       
  2997 				&& uid.Compare(aEapType->UID) == 0)
       
  2998 			{
       
  2999 				// Found
       
  3000 				break;
       
  3001 			}
       
  3002 		}
       
  3003 		if (i >= m_iap_eap_array.Count())
       
  3004 		{
       
  3005 			// This should never happen
       
  3006 			User::Leave(KErrNotFound);					
       
  3007 		}
       
  3008 	
       
  3009 		TLex8 tmp(aEapType->UID);
       
  3010 		TInt val(0);
       
  3011 		tmp.Val(val);
       
  3012 
       
  3013 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Setting to top priority:\n")));
       
  3014 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Old index: %d\n"), i));
       
  3015 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("  UID: %d\n"), val));
       
  3016 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("  Enabled: %d\n"), aEapType->Enabled));
       
  3017 	
       
  3018 		if (i == 0)
       
  3019 		{
       
  3020 			// Already at the highest priority
       
  3021 			return;
       
  3022 		}
       
  3023 
       
  3024 		CWLanSettings* wlan = new(ELeave) CWLanSettings;
       
  3025 		CleanupStack::PushL(wlan);
       
  3026 		SWLANSettings wlanSettings;
       
  3027 		if (wlan->Connect() != KErrNone)
       
  3028 		{
       
  3029 			// Could not connect to CommDB			
       
  3030 			User::Leave(KErrCouldNotConnect);
       
  3031 		}
       
  3032 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Connected to CommDbIf.\n")));
       
  3033 
       
  3034 		if (wlan->GetWlanSettingsForService(index, wlanSettings) != KErrNone)
       
  3035 		{
       
  3036 			wlan->Disconnect();
       
  3037 			User::Leave(KErrUnknown);
       
  3038 		}
       
  3039 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Got WLAN settings.\n")));
       
  3040 		
       
  3041 		// Change the order
       
  3042 		TEap* eap = m_iap_eap_array[i];
       
  3043 
       
  3044 		m_iap_eap_array.Remove(i); // This does not delete the object	
       
  3045 				
       
  3046 		m_iap_eap_array.Insert(eap, 0);
       
  3047 
       
  3048 		wlan->SetEapDataL(m_iap_eap_array);
       
  3049 		
       
  3050 		wlan->Disconnect();
       
  3051 
       
  3052 		CleanupStack::PopAndDestroy(wlan);		
       
  3053 	} 
       
  3054 	else
       
  3055 	{
       
  3056 		// At the moment only LAN bearer is supported.
       
  3057 		User::Leave(KErrNotSupported);
       
  3058 	}
       
  3059 		
       
  3060 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3061 }
       
  3062 
       
  3063 #endif // #ifdef USE_EAP_EXPANDED_TYPES 
       
  3064 
       
  3065 //--------------------------------------------------
       
  3066 
       
  3067 #if defined(USE_EAP_SIMPLE_CONFIG)
       
  3068 
       
  3069 EAP_FUNC_EXPORT eap_status_e eapol_am_wlan_authentication_symbian_c::save_simple_config_session(
       
  3070 	const simple_config_state_e state,
       
  3071 	EAP_TEMPLATE_CONST eap_array_c<simple_config_credential_c> * const credential_array,
       
  3072 	const eap_variable_data_c * const new_password,
       
  3073 	const simple_config_Device_Password_ID_e Device_Password_ID,
       
  3074 	const simple_config_payloads_c * const other_configuration)
       
  3075 {
       
  3076 	EAP_TRACE_DEBUG(
       
  3077 		m_am_tools,
       
  3078 		TRACE_FLAGS_DEFAULT,
       
  3079 		(EAPL("%s: eapol_am_wlan_authentication_simulator_c::save_simple_config_session()\n"),
       
  3080 		(m_is_client == true ? "client": "server")));
       
  3081 
       
  3082 	eap_status_e status(eap_status_ok);
       
  3083 
       
  3084 	status = m_configuration_if->save_simple_config_session(
       
  3085 		state,
       
  3086 		credential_array,
       
  3087 		new_password,
       
  3088 		Device_Password_ID,
       
  3089 		other_configuration);
       
  3090 
       
  3091 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3092 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3093 }
       
  3094 
       
  3095 #endif // #if defined(USE_EAP_SIMPLE_CONFIG)
       
  3096 
       
  3097 //--------------------------------------------------
       
  3098 
       
  3099 EAP_FUNC_EXPORT eapol_am_wlan_authentication_c * eapol_am_wlan_authentication_c::new_eapol_am_wlan_authentication(
       
  3100 	abs_eap_am_tools_c * const tools,
       
  3101 	const bool is_client_when_true,
       
  3102 	const abs_eapol_wlan_database_reference_if_c * const wlan_database_reference)
       
  3103 {
       
  3104 	EAP_TRACE_BEGIN(tools, TRACE_FLAGS_DEFAULT);
       
  3105 
       
  3106 	eapol_am_wlan_authentication_c * const wauth = new eapol_am_wlan_authentication_symbian_c(
       
  3107 		tools,
       
  3108 		is_client_when_true,
       
  3109 		wlan_database_reference);
       
  3110 
       
  3111 	EAP_TRACE_END(tools, TRACE_FLAGS_DEFAULT);
       
  3112 	return wauth;
       
  3113 }
       
  3114 
       
  3115 
       
  3116 //--------------------------------------------------
       
  3117 //--------------------------------------------------
       
  3118 //--------------------------------------------------
       
  3119 // End.