eapol/eapol_framework/eapol_symbian/am/type/tls_peap/symbian/plugin/src/EapTlsPeapUtils.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 438 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 
       
    28 // INCLUDE FILES
       
    29 #include "EapTlsPeapUtils.h"
       
    30 #include "EapTlsPeapDbDefaults.h"
       
    31 #include "EapTlsPeapDbParameterNames.h"
       
    32 #include <x500dn.h>
       
    33 #include <x509cert.h>
       
    34 #include <x509certext.h>
       
    35 
       
    36 #ifdef USE_FAST_EAP_TYPE
       
    37 #include "pac_store_db_parameters.h"
       
    38 #endif //#ifdef USE_FAST_EAP_TYPE
       
    39 
       
    40 #include "eap_am_trace_symbian.h"
       
    41 #include "EapTlsPeapCertFetcher.h"
       
    42 
       
    43 const TUint KMaxSqlQueryLength = 2048;
       
    44 const TInt	KMicroSecsInAMinute = 60000000; // 60000000 micro seconds is 1 minute.
       
    45 const TInt	KDefaultColumnInView_One = 1; // For DB view.
       
    46 const TInt 	KMaxEapDbTableNameLength = 64;
       
    47 // ================= MEMBER FUNCTIONS =======================
       
    48 
       
    49 void EapTlsPeapUtils::OpenDatabaseL(
       
    50 	RDbNamedDatabase& aDatabase, 
       
    51 	RDbs& aSession, 
       
    52 	const TIndexType aIndexType,
       
    53 	const TInt aIndex, 
       
    54 	const eap_type_value_e aTunnelingType,
       
    55 	eap_type_value_e aEapType)
       
    56 {
       
    57 #ifdef USE_EAP_EXPANDED_TYPES
       
    58 
       
    59 	EAP_TRACE_DEBUG_SYMBIAN(
       
    60 		(_L("EapTlsPeapUtils::OpenDatabaseL -Start- aIndexType=%d, aIndex=%d, Tunneling vendor type=%d, Eap vendor type=%d \n"),
       
    61 		aIndexType,aIndex, aTunnelingType.get_vendor_type(), aEapType.get_vendor_type()));
       
    62 #else
       
    63 
       
    64 	EAP_TRACE_DEBUG_SYMBIAN(
       
    65 		(_L("EapTlsPeapUtils::OpenDatabaseL -Start- aIndexType=%d, aIndex=%d, aTunnelingType=%d, aEapType=%d \n"),
       
    66 		aIndexType,aIndex, aTunnelingType, aEapType));
       
    67 
       
    68 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
    69 
       
    70 	if (aEapType == eap_type_tls)
       
    71 	{
       
    72 		OpenTlsDatabaseL(aDatabase, aSession, aIndexType, aIndex, aTunnelingType);
       
    73 	} 
       
    74 	else if (aEapType == eap_type_peap)
       
    75 	{
       
    76 		OpenPeapDatabaseL(aDatabase, aSession, aIndexType, aIndex, aTunnelingType);
       
    77 	} 
       
    78 #if defined(USE_TTLS_EAP_TYPE)
       
    79 	else if (aEapType == eap_type_ttls)
       
    80 	{
       
    81 		OpenTtlsDatabaseL(aDatabase, aSession, aIndexType, aIndex, aTunnelingType);
       
    82 	} 
       
    83 #endif // #if defined(USE_TTLS_EAP_TYPE)
       
    84 #if defined(USE_FAST_EAP_TYPE)
       
    85 	else if (aEapType == eap_type_fast)
       
    86 	{
       
    87 		OpenFastDatabaseL(aDatabase, aSession, aIndexType, aIndex, aTunnelingType);
       
    88 	} 
       
    89 #endif // #if defined(USE_FAST_EAP_TYPE)
       
    90 	
       
    91 	else if ( aEapType == eap_type_ttls_plain_pap )
       
    92 		{
       
    93 		OpenTtlsDatabaseL( aDatabase, aSession, aIndexType, aIndex, aTunnelingType);
       
    94 		}
       
    95 	
       
    96 	else
       
    97 	{
       
    98 		// Unsupported EAP type
       
    99 		User::Leave(KErrNotSupported);
       
   100 	}	
       
   101 } // EapTlsPeapUtils::OpenDatabaseL()
       
   102 
       
   103 void EapTlsPeapUtils::OpenTlsDatabaseL(
       
   104 		RDbNamedDatabase& aDatabase, 
       
   105 		RDbs& aSession, 
       
   106 		const TIndexType aIndexType, 
       
   107 		const TInt aIndex,
       
   108 		const eap_type_value_e aTunnelingType)
       
   109 {
       
   110 #ifdef USE_EAP_EXPANDED_TYPES
       
   111 
       
   112 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
   113 
       
   114 #else
       
   115 
       
   116 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
   117 
       
   118 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
   119 
       
   120 	EAP_TRACE_DEBUG_SYMBIAN(
       
   121 		(_L("EapTlsPeapUtils::OpenTlsDatabaseL -Start- aIndexType=%d, aIndex=%d, Tunneling vendor type=%d \n"),
       
   122 		aIndexType,aIndex, aTunnelingVendorType));
       
   123 
       
   124 	// 1. Open/create a database	
       
   125 	
       
   126 	// Connect to the DBMS server.
       
   127 	User::LeaveIfError(aSession.Connect());		
       
   128 	CleanupClosePushL(aSession);	
       
   129 	// aSession and aDatabase are pushed to the cleanup stack even though they may be member
       
   130 	// variables of the calling class and would be closed in the destructor anyway. This ensures
       
   131 	// that if they are not member variables they will be closed. Closing the handle twice
       
   132 	// does no harm.	
       
   133 	
       
   134 #ifdef SYMBIAN_SECURE_DBMS
       
   135 	
       
   136 	// Create the secure shared database with the specified secure policy.
       
   137 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
       
   138 	
       
   139 	TInt err = aDatabase.Create(aSession, KTlsDatabaseName, KSecureUIDFormat);
       
   140 	
       
   141 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::OpenTlsDatabaseL - Created Secure DB for eaptls.dat. err=%d\n"), err) );
       
   142 	
       
   143 	if(err == KErrNone)
       
   144 	{
       
   145 		aDatabase.Close();
       
   146 		
       
   147 	} else if (err != KErrAlreadyExists) 
       
   148 	{
       
   149 		User::LeaveIfError(err);
       
   150 	}
       
   151 	
       
   152 	User::LeaveIfError(aDatabase.Open(aSession, KTlsDatabaseName, KSecureUIDFormat));
       
   153 	CleanupClosePushL(aDatabase);		
       
   154 		
       
   155 #else
       
   156 	// For non-secured database. The database will be created in the old location (c:\system\data).
       
   157 	
       
   158 	RFs fsSession;		
       
   159 	User::LeaveIfError(fsSession.Connect());
       
   160 	CleanupClosePushL(fsSession);	
       
   161 	TInt err = aDatabase.Create(fsSession, KTlsDatabaseName);
       
   162 
       
   163 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::OpenTlsDatabaseL - Created Non-Secure DB for eaptls.dat. err=%d\n"), err) );
       
   164 	
       
   165 	if(err == KErrNone)
       
   166 	{
       
   167 		aDatabase.Close();
       
   168 		
       
   169 	} else if (err != KErrAlreadyExists) 
       
   170 	{
       
   171 		User::LeaveIfError(err);
       
   172 	}
       
   173 	
       
   174 	User::LeaveIfError(aDatabase.Open(fsSession, KTlsDatabaseName));
       
   175 	
       
   176 	CleanupStack::PopAndDestroy(); // close fsSession
       
   177 	
       
   178 	CleanupClosePushL(aDatabase);		
       
   179 	    
       
   180 #endif // #ifdef SYMBIAN_SECURE_DBMS
       
   181 
       
   182 	// 2. Create the eaptls table to database (ignore error if exists)
       
   183 	
       
   184 // Table columns:
       
   185 //// NAME ////////////////////////////////////////// TYPE //////////// Constant ////////////////////
       
   186 //| ServiceType									| UNSIGNED INTEGER | KServiceType         |//
       
   187 //| ServiceIndex								| UNSIGNED INTEGER | KServiceIndex        |//
       
   188 //| TunnelingType								| UNSIGNED INTEGER | KTunnelingType		|//
       
   189 //| EAP_TLS_PEAP_use_manual_realm				| UNSIGNED INTEGER | cf_str_EAP_TLS_PEAP_use_manual_realm_literal      |//
       
   190 //| EAP_TLS_PEAP_manual_realm					| VARCHAR(255)     | cf_str_EAP_TLS_PEAP_manual_realm_literal				|//
       
   191 //| EAP_TLS_PEAP_use_manual_username			| UNSIGNED INTEGER | cf_str_EAP_TLS_PEAP_use_manual_username_literal   |//
       
   192 //| EAP_TLS_PEAP_manual_username				| VARCHAR(255)     | cf_str_EAP_TLS_PEAP_manual_username_literal			|//
       
   193 //| EAP_TLS_PEAP_cipher_suite					| UNSIGNED INTEGER | cf_str_EAP_TLS_PEAP_cipher_suite_literal	    |//
       
   194 //| EAP_TLS_server_authenticates_client			| UNSIGNED INTEGER | cf_str_TLS_server_authenticates_client_policy_in_client_literal |//
       
   195 //| CA_cert_label								| VARCHAR(255)     | KCACertLabelOld	    |//
       
   196 //| client_cert_label							| VARCHAR(255)     | KClientCertLabel	    |//
       
   197 //| EAP_TLS_PEAP_saved_session_id				| BINARY(32)       | cf_str_EAP_TLS_PEAP_saved_session_id_literal		    |//
       
   198 //| EAP_TLS_PEAP_saved_master_secret			| BINARY(48)       | cf_str_EAP_TLS_PEAP_saved_master_secret_literal	    |//
       
   199 //| EAP_TLS_PEAP_saved_cipher_suite				| UNSIGNED INTEGER | cf_str_EAP_TLS_PEAP_saved_cipher_suite_literal    |//
       
   200 //| EAP_TLS_PEAP_verify_certificate_realm		| UNSIGNED INTEGER | cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal		    |//
       
   201 //| EAP_TLS_max_session_validity_time			| BIGINT	   	 	| cf_str_EAP_TLS_max_session_validity_time_literal   |//
       
   202 //| EAP_TLS_last_full_authentication_time		| BIGINT	   		| KTLSLastFullAuthTime	   	|//	
       
   203 //| EAP_TLS_PEAP_use_identity_privacy	    	| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_use_identity_privacy_literal|//
       
   204 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////	
       
   205 
       
   206 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
   207 	TPtr sqlStatement = buf->Des();
       
   208 	
       
   209 	// Table creation is divided into two parts because otherwise the SQL string would get too long
       
   210 	_LIT(KSQLCreateTable1, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
   211 											 %S UNSIGNED INTEGER, \
       
   212 											 %S UNSIGNED INTEGER, \
       
   213 											 %S UNSIGNED INTEGER, \
       
   214 											 %S VARCHAR(%d),     \
       
   215 											 %S UNSIGNED INTEGER, \
       
   216 											 %S VARCHAR(%d),     \
       
   217 											 %S UNSIGNED INTEGER, \
       
   218 											 %S UNSIGNED INTEGER, \
       
   219 											 %S VARCHAR(%d),	  \
       
   220 											 %S VARCHAR(%d),     \
       
   221 											 %S BINARY(%d),		  \
       
   222 											 %S BINARY(%d),		  \
       
   223 											 %S UNSIGNED INTEGER, \
       
   224 											 %S UNSIGNED INTEGER, \
       
   225 											 %S BIGINT, \
       
   226 											 %S BIGINT, \
       
   227 											 %S UNSIGNED INTEGER)");
       
   228 											 
       
   229 	sqlStatement.Format(KSQLCreateTable1,
       
   230 		&KTlsDatabaseTableName,
       
   231 		&KServiceType,
       
   232 		&KServiceIndex,
       
   233 		&KTunnelingType,
       
   234 		&cf_str_EAP_TLS_PEAP_use_manual_realm_literal,
       
   235 		&cf_str_EAP_TLS_PEAP_manual_realm_literal, KMaxManualRealmLengthInDB,
       
   236 		&cf_str_EAP_TLS_PEAP_use_manual_username_literal,
       
   237 		&cf_str_EAP_TLS_PEAP_manual_username_literal, KMaxManualUsernameLengthInDB,
       
   238 		&cf_str_EAP_TLS_PEAP_cipher_suite_literal, 
       
   239 		&cf_str_TLS_server_authenticates_client_policy_in_client_literal,
       
   240 		&KCACertLabelOld, KMaxCertLabelLengthInDB,
       
   241 		&KClientCertLabel, KMaxCertLabelLengthInDB,
       
   242 		&cf_str_EAP_TLS_PEAP_saved_session_id_literal, KMaxSessionIdLengthInDB,
       
   243 		&cf_str_EAP_TLS_PEAP_saved_master_secret_literal, KMaxMasterSecretLengthInDB,
       
   244 		&cf_str_EAP_TLS_PEAP_saved_cipher_suite_literal,
       
   245 		&cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal,		
       
   246 		&cf_str_EAP_TLS_max_session_validity_time_literal,
       
   247 		&KTLSLastFullAuthTime,
       
   248 		&cf_str_EAP_TLS_PEAP_use_identity_privacy_literal);	
       
   249 	
       
   250 	err = aDatabase.Execute(sqlStatement);
       
   251 	if (err == KErrAlreadyExists)
       
   252 	{
       
   253 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::OpenTlsDatabaseL - Alter Table err=%d\n"), err) );
       
   254 	_LIT( KColumnDef, "UNSIGNED INTEGER" );
       
   255 	AlterTableL( aDatabase, EAddColumn , KTlsDatabaseTableName,
       
   256 			cf_str_EAP_TLS_PEAP_use_identity_privacy_literal, KColumnDef);
       
   257 	}
       
   258 	else if (err != KErrNone)
       
   259 		{
       
   260 		User::Leave(err);
       
   261 		}
       
   262 
       
   263 	// Create table for _allowed_ user certificates
       
   264 	
       
   265 //// NAME ////////////////// TYPE ////////////// Constant ///////////
       
   266 //| ServiceType			| UNSIGNED INTEGER | KServiceType        |//
       
   267 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
   268 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
   269 //| CertLabel			| VARCHAR(255)     | KCertLabel        |//	
       
   270 //| SubjectKeyId		| BINARY(20)	   | KSubjectKeyIdentifier |// This is Symbian subjectkey id
       
   271 //| ActualSubjectKeyId  | BINARY(20)	   | KActualSubjectKeyIdentifier |// This is the actual subjectkeyid present in the certificate.
       
   272 //| SubjectName			| VARCHAR(255)     | KSubjectName        |//	
       
   273 //| IssuerName			| VARCHAR(255)     | KIssuerName        |//	
       
   274 //| SerialNumber		| VARCHAR(255)     | KSerialNumber        |//	
       
   275 //| Thumbprint			| BINARY(64)	   | KThumbprint        |//	
       
   276 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
   277 	
       
   278 	_LIT(KSQLCreateTable2, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
   279 											 %S UNSIGNED INTEGER, \
       
   280 											 %S UNSIGNED INTEGER, \
       
   281 											 %S VARCHAR(%d), \
       
   282 											 %S BINARY(%d), \
       
   283 											 %S BINARY(%d), \
       
   284 											 %S VARCHAR(%d), \
       
   285 											 %S VARCHAR(%d), \
       
   286 											 %S VARCHAR(%d), \
       
   287 											 %S BINARY(%d))");											 
       
   288 											 
       
   289 	sqlStatement.Format(KSQLCreateTable2, &KTlsAllowedUserCertsDatabaseTableName, 
       
   290 		&KServiceType, 
       
   291 		&KServiceIndex, 
       
   292 		&KTunnelingType, 
       
   293 		&KCertLabel, KMaxCertLabelLengthInDB,
       
   294 		&KSubjectKeyIdentifier, KMaxSubjectKeyIdLengthInDB,
       
   295 		&KActualSubjectKeyIdentifier, KKeyIdentifierLength,
       
   296 		&KSubjectName, KGeneralStringMaxLength,
       
   297 		&KIssuerName, KGeneralStringMaxLength,
       
   298 		&KSerialNumber, KGeneralStringMaxLength,
       
   299 		&KThumbprint, KThumbprintMaxLength);
       
   300 				
       
   301 	err = aDatabase.Execute(sqlStatement);
       
   302 	if (err != KErrNone && err != KErrAlreadyExists)
       
   303 	{
       
   304 		User::Leave(err);
       
   305 	}
       
   306 
       
   307 	// Create table for _allowed_ CA certs
       
   308 
       
   309 //// NAME ////////////////// TYPE ////////////// Constant ///////////
       
   310 //| ServiceType		    | UNSIGNED INTEGER | KServiceType        |//
       
   311 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
   312 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
   313 //| CertLabel			| VARCHAR(255)     | KCACertLabel        |//	
       
   314 //| SubjectKeyId		| BINARY(255)	   | KSubjectKeyIdentifier |// This is Symbian subjectkey id
       
   315 //| ActualSubjectKeyId  | BINARY(20)	   | KActualSubjectKeyIdentifier |// This is the actual subjectkeyid present in the certificate.
       
   316 //| SubjectName			| VARCHAR(255)     | KSubjectName        |//	
       
   317 //| IssuerName			| VARCHAR(255)     | KIssuerName        |//	
       
   318 //| SerialNumber		| VARCHAR(255)     | KSerialNumber        |//	
       
   319 //| Thumbprint			| BINARY(64)	   | KThumbprint        |//	
       
   320 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
   321 
       
   322 	_LIT(KSQLCreateTable3, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
   323 											 %S UNSIGNED INTEGER, \
       
   324 											 %S UNSIGNED INTEGER, \
       
   325 											 %S VARCHAR(%d), \
       
   326 											 %S BINARY(%d), \
       
   327 											 %S BINARY(%d), \
       
   328 											 %S VARCHAR(%d), \
       
   329 											 %S VARCHAR(%d), \
       
   330 											 %S VARCHAR(%d), \
       
   331 											 %S BINARY(%d))");											 
       
   332 											 
       
   333 	sqlStatement.Format(KSQLCreateTable3, &KTlsAllowedCACertsDatabaseTableName, 
       
   334 		&KServiceType, 
       
   335 		&KServiceIndex, 
       
   336 		&KTunnelingType, 
       
   337 		&KCertLabel, KMaxCertLabelLengthInDB,
       
   338 		&KSubjectKeyIdentifier, KMaxSubjectKeyIdLengthInDB,
       
   339 		&KActualSubjectKeyIdentifier, KKeyIdentifierLength,
       
   340 		&KSubjectName, KGeneralStringMaxLength,
       
   341 		&KIssuerName, KGeneralStringMaxLength,
       
   342 		&KSerialNumber, KGeneralStringMaxLength,
       
   343 		&KThumbprint, KThumbprintMaxLength);
       
   344 		
       
   345 	err = aDatabase.Execute(sqlStatement);
       
   346 	if (err != KErrNone && err != KErrAlreadyExists)
       
   347 	{
       
   348 		User::Leave(err);
       
   349 	}
       
   350 
       
   351 	// Create table for allowed cipher suites
       
   352 
       
   353 //// NAME ///////////////// TYPE ////////////// Constant ///////////
       
   354 //| ServiceType			| UNSIGNED INTEGER | KServiceType        |//
       
   355 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
   356 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
   357 //| CipherSuite			| UNSIGNED INTEGER | KCipherSuite        |//	
       
   358 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
   359 	
       
   360 	_LIT(KSQLCreateTable4, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
   361 											 %S UNSIGNED INTEGER, \
       
   362 											 %S UNSIGNED INTEGER, \
       
   363 											 %S UNSIGNED INTEGER)");
       
   364 
       
   365 	sqlStatement.Format(KSQLCreateTable4, &KTlsAllowedCipherSuitesDatabaseTableName, 
       
   366 		&KServiceType, 
       
   367 		&KServiceIndex, 
       
   368 		&KTunnelingType, 
       
   369 		&KCipherSuite);
       
   370 		
       
   371 	err = aDatabase.Execute(sqlStatement);
       
   372 	if (err != KErrNone && err != KErrAlreadyExists)
       
   373 	{
       
   374 		User::Leave(err);
       
   375 	}
       
   376 	
       
   377 	// 4. Check if database table contains a row for this service type and id 
       
   378 		
       
   379 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
   380 	
       
   381 	sqlStatement.Format(KSQLQueryRow, &cf_str_EAP_TLS_PEAP_cipher_suite_literal, &KTlsDatabaseTableName, 
       
   382 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);	
       
   383 	
       
   384 	RDbView view;
       
   385 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
   386 	// View must be closed when no longer needed
       
   387 	CleanupClosePushL(view);
       
   388 	User::LeaveIfError(view.EvaluateAll());
       
   389 	
       
   390 	// 5. If row is not found then add it
       
   391 	
       
   392 	TInt rows = view.CountL();
       
   393 	CleanupStack::PopAndDestroy(); // view
       
   394 	if (rows == 0)
       
   395 	{
       
   396 		_LIT(KSQLInsert, "SELECT * FROM %S");
       
   397 		sqlStatement.Format(KSQLInsert, &KTlsDatabaseTableName);	
       
   398 
       
   399 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly));
       
   400 		CleanupClosePushL(view);
       
   401 		view.InsertL();
       
   402 
       
   403 		// Get column set so we get the correct column numbers
       
   404 		CDbColSet* colSet = view.ColSetL();
       
   405 		CleanupStack::PushL(colSet);
       
   406 
       
   407 		// Set the default values. The other three tables (certs, ca certs & cipher suites) are empty by default.
       
   408 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
       
   409 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);
       
   410 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
       
   411 		
       
   412 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_realm_literal), default_EAP_TLS_PEAP_use_manual_realm);
       
   413 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_realm_literal), default_EAP_TLS_PEAP_manual_realm);
       
   414 		
       
   415 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_username_literal), default_EAP_TLS_PEAP_use_manual_username);
       
   416 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_username_literal), default_EAP_TLS_PEAP_manual_username);
       
   417 		
       
   418 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_cipher_suite_literal), default_EAP_TLS_PEAP_cipher_suite);
       
   419 		
       
   420 		view.SetColL(colSet->ColNo(cf_str_TLS_server_authenticates_client_policy_in_client_literal), default_EAP_TLS_server_authenticates_client);
       
   421 		
       
   422 		view.SetColL(colSet->ColNo(KCACertLabelOld), default_CA_cert_label);
       
   423 		view.SetColL(colSet->ColNo(KClientCertLabel), default_client_cert_label);
       
   424 		
       
   425 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal), default_EAP_TLS_PEAP_verify_certificate_realm);
       
   426 		
       
   427 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_max_session_validity_time_literal), default_MaxSessionTime);		
       
   428 		
       
   429 		view.SetColL(colSet->ColNo(KTLSLastFullAuthTime), default_FullAuthTime);		
       
   430 
       
   431 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_identity_privacy_literal), default_EAP_TLS_PEAP_TLS_Privacy);		
       
   432 		view.PutL();
       
   433 
       
   434 		CleanupStack::PopAndDestroy( colSet ); // Delete colSet.		
       
   435 		CleanupStack::PopAndDestroy( &view ); // Close view.
       
   436 		
       
   437 		// Add default disabled cipher suites
       
   438 		_LIT(KSQLInsert2, "SELECT * FROM %S");
       
   439 		sqlStatement.Format(KSQLInsert2, &KTlsAllowedCipherSuitesDatabaseTableName);
       
   440 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly));
       
   441 		CleanupClosePushL(view);
       
   442 
       
   443 		// Get column set so we get the correct column numbers
       
   444 		colSet = view.ColSetL();
       
   445 		CleanupStack::PushL(colSet);
       
   446 
       
   447 		TInt i(0);
       
   448 		while (default_allowed_cipher_suites[i] != 0)
       
   449 		{
       
   450 			view.InsertL();
       
   451 			view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
       
   452 			view.SetColL(colSet->ColNo(KServiceIndex), aIndex);			
       
   453 			view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
       
   454 			view.SetColL(colSet->ColNo(KCipherSuite), default_allowed_cipher_suites[i]);
       
   455 			view.PutL();
       
   456 			i++;
       
   457 		}
       
   458 		
       
   459 		CleanupStack::PopAndDestroy( colSet ); // Delete colSet.		
       
   460 		CleanupStack::PopAndDestroy( &view ); // Close view.
       
   461 	}
       
   462 	
       
   463 	// 6. Do the altering of tables here. 
       
   464 	//    Add columns to existing certificate DB tables for Serial number, Issuer name etc. 
       
   465 
       
   466 	TBufC<KDbMaxColName> tableName;
       
   467 
       
   468 	// For the table _allowed_ USER certificates
       
   469 	tableName = KTlsAllowedUserCertsDatabaseTableName;	
       
   470 	AddExtraCertColumnsL(aDatabase,tableName);
       
   471 	
       
   472 	// For the table _allowed_ CA certificates	
       
   473 	tableName = KTlsAllowedCACertsDatabaseTableName;	
       
   474 	AddExtraCertColumnsL(aDatabase,tableName);
       
   475 	
       
   476 	CleanupStack::PopAndDestroy( buf ); // Delete buf or sqlStatement	
       
   477 	CleanupStack::Pop( &aDatabase );	
       
   478 	CleanupStack::Pop( &aSession );	
       
   479 	
       
   480 	aDatabase.Compact();
       
   481 }
       
   482 
       
   483 void EapTlsPeapUtils::OpenPeapDatabaseL(
       
   484 		RDbNamedDatabase& aDatabase, 
       
   485 		RDbs& aSession, 
       
   486 		const TIndexType aIndexType, 
       
   487 		const TInt aIndex,
       
   488 		const eap_type_value_e aTunnelingType)
       
   489 {
       
   490 #ifdef USE_EAP_EXPANDED_TYPES
       
   491 
       
   492 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
   493 
       
   494 #else
       
   495 
       
   496 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
   497 
       
   498 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
   499 
       
   500 	EAP_TRACE_DEBUG_SYMBIAN(
       
   501 		(_L("EapTlsPeapUtils::OpenPeapDatabaseL -Start- aIndexType=%d, aIndex=%d, Tunneling vendor type=%d \n"),
       
   502 		aIndexType,aIndex, aTunnelingVendorType));
       
   503 
       
   504 	// 1. Open/create a database	
       
   505 	
       
   506 	// Connect to the DBMS server.
       
   507 	User::LeaveIfError(aSession.Connect());		
       
   508 	CleanupClosePushL(aSession);	
       
   509 	// aSession and aDatabase are pushed to the cleanup stack even though they may be member
       
   510 	// variables of the calling class and would be closed in the destructor anyway. This ensures
       
   511 	// that if they are not member variables they will be closed. Closing the handle twice
       
   512 	// does no harm.	
       
   513 	
       
   514 #ifdef SYMBIAN_SECURE_DBMS
       
   515 	
       
   516 	// Create the secure shared database with the specified secure policy.
       
   517 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
       
   518 	
       
   519 	TInt err = aDatabase.Create(aSession, KPeapDatabaseName, KSecureUIDFormat);
       
   520 	
       
   521 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::OpenPeapDatabaseL - Created Secure DB for eappeap.dat. err=%d\n"), err) );
       
   522 	
       
   523 	if(err == KErrNone)
       
   524 	{
       
   525 		aDatabase.Close();
       
   526 		
       
   527 	} else if (err != KErrAlreadyExists) 
       
   528 	{
       
   529 		User::LeaveIfError(err);
       
   530 	}
       
   531 	
       
   532 	User::LeaveIfError(aDatabase.Open(aSession, KPeapDatabaseName, KSecureUIDFormat));
       
   533 	CleanupClosePushL(aDatabase);		
       
   534 		
       
   535 #else
       
   536 	// For non-secured database. The database will be created in the old location (c:\system\data).
       
   537 	
       
   538 	RFs fsSession;		
       
   539 	User::LeaveIfError(fsSession.Connect());
       
   540 	CleanupClosePushL(fsSession);	
       
   541 	TInt err = aDatabase.Create(fsSession, KPeapDatabaseName);
       
   542 	
       
   543 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::OpenPeapDatabaseL - Created Non-Secure DB for eappeap.dat. err=%d\n"), err) );
       
   544 	
       
   545 	if(err == KErrNone)
       
   546 	{
       
   547 		aDatabase.Close();
       
   548 		
       
   549 	} else if (err != KErrAlreadyExists) 
       
   550 	{
       
   551 		User::LeaveIfError(err);
       
   552 	}
       
   553 	
       
   554 	User::LeaveIfError(aDatabase.Open(fsSession, KPeapDatabaseName));
       
   555 	
       
   556 	CleanupStack::PopAndDestroy(); // close fsSession
       
   557 	
       
   558 	CleanupClosePushL(aDatabase);		
       
   559 	    
       
   560 #endif // #ifdef SYMBIAN_SECURE_DBMS
       
   561 
       
   562 	// 2. Create the eappeap table to database (ignore error if exists)
       
   563 	
       
   564 // Table columns:
       
   565 //// NAME /////////////////////////////////////////////// TYPE ////////////// Constant ///////////////////
       
   566 //| ServiceType										| UNSIGNED INTEGER 	| KServiceType        |//
       
   567 //| ServiceIndex									| UNSIGNED INTEGER 	| KServiceIndex       |//
       
   568 //| TunnelingType									| UNSIGNED INTEGER 	| KTunnelingType		|//
       
   569 //| EAP_TLS_PEAP_use_manual_realm					| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_use_manual_realm_literal      |//
       
   570 //| EAP_TLS_PEAP_manual_realm						| VARCHAR(255)     	| cf_str_EAP_TLS_PEAP_manual_realm_literal				|//
       
   571 //| EAP_TLS_PEAP_use_manual_username				| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_use_manual_username_literal   |//
       
   572 //| EAP_TLS_PEAP_manual_username					| VARCHAR(255)     	| cf_str_EAP_TLS_PEAP_manual_username_literal			|//
       
   573 //| EAP_TLS_PEAP_max_count_of_session_resumes		| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_max_count_of_session_resumes_literal    |//
       
   574 //| EAP_TLS_PEAP_cipher_suite						| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_cipher_suite_literal	   |//
       
   575 //| EAP_TLS_PEAP_used_PEAP_version					| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_used_PEAP_version_literal		    |//
       
   576 //| EAP_TLS_PEAP_accepted_PEAP_versions				| BINARY(12)	    | cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal|//
       
   577 //| PEAP_accepted_tunneled_client_types			   	| VARBINARY(240) 	| cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal      |//
       
   578 //| PEAP_unaccepted_tunneled_client_types		   	| VARBINARY(240) 	| cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal      |//
       
   579 //| EAP_TLS_server_authenticates_client		        | UNSIGNED INTEGER 	| cf_str_TLS_server_authenticates_client_policy_in_client_literal|//
       
   580 //| CA_cert_label								    | VARCHAR(255)     	| KCACertLabelOld	   |//
       
   581 //| client_cert_label							    | VARCHAR(255)     	| KClientCertLabel	   |//
       
   582 //| EAP_TLS_PEAP_saved_session_id				    | BINARY(32)       	| cf_str_EAP_TLS_PEAP_saved_session_id_literal		   |//
       
   583 //| EAP_TLS_PEAP_saved_master_secret			    | BINARY(48)       	| cf_str_EAP_TLS_PEAP_saved_master_secret_literal	   |//
       
   584 //| EAP_TLS_PEAP_saved_cipher_suite				    | UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_saved_cipher_suite_literal   |//
       
   585 //| EAP_TLS_PEAP_verify_certificate_realm			| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal		   |//
       
   586 //| EAP_PEAP_max_session_validity_time				| BIGINT	   		| cf_str_EAP_PEAP_max_session_validity_time_literal   |//
       
   587 //| EAP_PEAP_last_full_authentication_time			| BIGINT	   		| KPEAPLastFullAuthTime	   	|//	
       
   588 //| EAP_TLS_PEAP_use_identity_privacy	    	    | UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_use_identity_privacy_literal|//
       
   589 //////////////////////////////////////////////////////////////////////////////////////////////////////////////	
       
   590 
       
   591 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
   592 	TPtr sqlStatement = buf->Des();
       
   593 
       
   594 	// Table creation is divided into two parts because otherwise the SQL string would get too long
       
   595 	_LIT(KSQLCreateTable1, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
   596 											 %S UNSIGNED INTEGER, \
       
   597 											 %S UNSIGNED INTEGER, \
       
   598 											 %S UNSIGNED INTEGER, \
       
   599 											 %S VARCHAR(%d),     \
       
   600 											 %S UNSIGNED INTEGER, \
       
   601 											 %S VARCHAR(%d),     \
       
   602 											 %S UNSIGNED INTEGER, \
       
   603 											 %S UNSIGNED INTEGER, \
       
   604 											 %S BINARY(%d),		  \
       
   605 											 %S VARBINARY(%d),	  \
       
   606 											 %S VARBINARY(%d),	  \
       
   607 											 %S UNSIGNED INTEGER, \
       
   608 											 %S VARCHAR(%d),	  \
       
   609 											 %S VARCHAR(%d),     \
       
   610 											 %S BINARY(%d),		  \
       
   611 											 %S BINARY(%d),		  \
       
   612 											 %S UNSIGNED INTEGER, \
       
   613 											 %S UNSIGNED INTEGER, \
       
   614 											 %S BIGINT, \
       
   615 											 %S BIGINT, \
       
   616 											 %S UNSIGNED INTEGER)");
       
   617 	sqlStatement.Format(KSQLCreateTable1,
       
   618 		&KPeapDatabaseTableName,
       
   619 		&KServiceType,
       
   620 		&KServiceIndex,
       
   621 		&KTunnelingType,
       
   622 		&cf_str_EAP_TLS_PEAP_use_manual_realm_literal,
       
   623 		&cf_str_EAP_TLS_PEAP_manual_realm_literal, KMaxManualRealmLengthInDB,
       
   624 		&cf_str_EAP_TLS_PEAP_use_manual_username_literal,
       
   625 		&cf_str_EAP_TLS_PEAP_manual_username_literal, KMaxManualUsernameLengthInDB,
       
   626 		&cf_str_EAP_TLS_PEAP_cipher_suite_literal,
       
   627 		&cf_str_EAP_TLS_PEAP_used_PEAP_version_literal,
       
   628 		&cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal, KMaxPEAPVersionsStringLengthInDB,
       
   629 		&cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, KMaxTunneledTypeStringLengthInDB,
       
   630 		&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal, KMaxTunneledTypeStringLengthInDB,
       
   631 		&cf_str_TLS_server_authenticates_client_policy_in_client_literal,
       
   632 		&KCACertLabelOld, KMaxCertLabelLengthInDB,
       
   633 		&KClientCertLabel, KMaxCertLabelLengthInDB,
       
   634 		&cf_str_EAP_TLS_PEAP_saved_session_id_literal, KMaxSessionIdLengthInDB,
       
   635 		&cf_str_EAP_TLS_PEAP_saved_master_secret_literal,  KMaxMasterSecretLengthInDB,
       
   636 		&cf_str_EAP_TLS_PEAP_saved_cipher_suite_literal,
       
   637 		&cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal,
       
   638 		&cf_str_EAP_PEAP_max_session_validity_time_literal,
       
   639 		&KPEAPLastFullAuthTime,	
       
   640 		&cf_str_EAP_TLS_PEAP_use_identity_privacy_literal);		
       
   641 					
       
   642 	err = aDatabase.Execute(sqlStatement);
       
   643 	if (err == KErrAlreadyExists)
       
   644 		{
       
   645 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::OpenPeapDatabaseL - Alter Table err=%d\n"), err) );
       
   646 		_LIT( KColumnDef, "UNSIGNED INTEGER" );
       
   647 		AlterTableL( aDatabase, EAddColumn , KPeapDatabaseTableName,
       
   648 				cf_str_EAP_TLS_PEAP_use_identity_privacy_literal, KColumnDef);
       
   649 		}
       
   650 		else if (err != KErrNone)
       
   651 			{
       
   652 			User::Leave(err);
       
   653 			}
       
   654 
       
   655 	// Create table for _allowed_ user certificates
       
   656 	
       
   657 //// NAME ////////////////// TYPE ////////////// Constant ///////////
       
   658 //| ServiceType			| UNSIGNED INTEGER | KServiceType        |//
       
   659 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
   660 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
   661 //| CertLabel			| VARCHAR(255)     | KCACertLabel        |//	
       
   662 //| SubjectKeyId		| BINARY(20)	   | KSubjectKeyIdentifier |// This is Symbian subjectkey id
       
   663 //| ActualSubjectKeyId  | BINARY(20)	   | KActualSubjectKeyIdentifier |// This is the actual subjectkeyid present in the certificate.
       
   664 //| SubjectName			| VARCHAR(255)     | KSubjectName        |//	
       
   665 //| IssuerName			| VARCHAR(255)     | KIssuerName        |//	
       
   666 //| SerialNumber		| VARCHAR(255)     | KSerialNumber        |//	
       
   667 //| Thumbprint			| BINARY(64)	   | KThumbprint        |//	
       
   668 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
   669 	
       
   670 	_LIT(KSQLCreateTable2, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
   671 											 %S UNSIGNED INTEGER, \
       
   672 											 %S UNSIGNED INTEGER, \
       
   673 											 %S VARCHAR(%d), \
       
   674 											 %S BINARY(%d), \
       
   675 											 %S BINARY(%d), \
       
   676 											 %S VARCHAR(%d), \
       
   677 											 %S VARCHAR(%d), \
       
   678 											 %S VARCHAR(%d), \
       
   679 											 %S BINARY(%d))");											 
       
   680 											 
       
   681 	sqlStatement.Format(KSQLCreateTable2, &KPeapAllowedUserCertsDatabaseTableName, 
       
   682 		&KServiceType, 
       
   683 		&KServiceIndex, 
       
   684 		&KTunnelingType, 
       
   685 		&KCertLabel, KMaxCertLabelLengthInDB,
       
   686 		&KSubjectKeyIdentifier, KMaxSubjectKeyIdLengthInDB,
       
   687 		&KActualSubjectKeyIdentifier, KKeyIdentifierLength,
       
   688 		&KSubjectName, KGeneralStringMaxLength,
       
   689 		&KIssuerName, KGeneralStringMaxLength,
       
   690 		&KSerialNumber, KGeneralStringMaxLength,
       
   691 		&KThumbprint, KThumbprintMaxLength);
       
   692 		
       
   693 	err = aDatabase.Execute(sqlStatement);
       
   694 	if (err != KErrNone && err != KErrAlreadyExists)
       
   695 	{
       
   696 		User::Leave(err);
       
   697 	}	
       
   698 
       
   699 	// Create table for _allowed_ CA certs
       
   700 
       
   701 //// NAME ////////////////// TYPE ////////////// Constant ///////////
       
   702 //| ServiceType			| UNSIGNED INTEGER | KServiceType        |//
       
   703 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
   704 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
   705 //| CACertLabel			| VARCHAR(255)     | KCACertLabel        |//	
       
   706 //| SubjectKeyId		| BINARY(20)	   | KSubjectKeyIdentifier |// This is Symbian subjectkey id
       
   707 //| ActualSubjectKeyId  | BINARY(20)	   | KActualSubjectKeyIdentifier |// This is the actual subjectkeyid present in the certificate.
       
   708 //| SubjectName			| VARCHAR(255)     | KSubjectName        |//	
       
   709 //| IssuerName			| VARCHAR(255)     | KIssuerName        |//	
       
   710 //| SerialNumber		| VARCHAR(255)     | KSerialNumber        |//	
       
   711 //| Thumbprint			| BINARY(64)	   | KThumbprint        |//	
       
   712 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
   713 
       
   714 	_LIT(KSQLCreateTable3, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
   715 											 %S UNSIGNED INTEGER, \
       
   716 											 %S UNSIGNED INTEGER, \
       
   717 											 %S VARCHAR(%d), \
       
   718 											 %S BINARY(%d), \
       
   719 											 %S BINARY(%d), \
       
   720 											 %S VARCHAR(%d), \
       
   721 											 %S VARCHAR(%d), \
       
   722 											 %S VARCHAR(%d), \
       
   723 											 %S BINARY(%d))");
       
   724 											 											 
       
   725 	sqlStatement.Format(KSQLCreateTable3, &KPeapAllowedCACertsDatabaseTableName, 
       
   726 		&KServiceType, 
       
   727 		&KServiceIndex, 
       
   728 		&KTunnelingType, 
       
   729 		&KCertLabel, KMaxCertLabelLengthInDB,
       
   730 		&KSubjectKeyIdentifier, KMaxSubjectKeyIdLengthInDB,
       
   731 		&KActualSubjectKeyIdentifier, KKeyIdentifierLength,
       
   732 		&KSubjectName, KGeneralStringMaxLength,
       
   733 		&KIssuerName, KGeneralStringMaxLength,
       
   734 		&KSerialNumber, KGeneralStringMaxLength,
       
   735 		&KThumbprint, KThumbprintMaxLength);
       
   736 		
       
   737 	err = aDatabase.Execute(sqlStatement);
       
   738 	if (err != KErrNone && err != KErrAlreadyExists)
       
   739 	{
       
   740 		User::Leave(err);
       
   741 	}
       
   742 
       
   743 	// Create table for _allowed_ cipher suites
       
   744 
       
   745 //// NAME ///////////////// TYPE ////////////// Constant ///////////
       
   746 //| ServiceType			| UNSIGNED INTEGER | KServiceType        |//
       
   747 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
   748 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
   749 //| CipherSuite			| UNSIGNED INTEGER | KCipherSuite        |//	
       
   750 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
   751 	
       
   752 	_LIT(KSQLCreateTable4, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
   753 											 %S UNSIGNED INTEGER, \
       
   754 											 %S UNSIGNED INTEGER, \
       
   755 											 %S UNSIGNED INTEGER)");
       
   756 
       
   757 	sqlStatement.Format(KSQLCreateTable4, &KPeapAllowedCipherSuitesDatabaseTableName, 
       
   758 		&KServiceType, &KServiceIndex, &KTunnelingType, &KCipherSuite);
       
   759 	err = aDatabase.Execute(sqlStatement);
       
   760 	if (err != KErrNone && err != KErrAlreadyExists)
       
   761 	{
       
   762 		User::Leave(err);
       
   763 	}
       
   764 
       
   765 	// 4. Check if database table contains a row for this service type and id 
       
   766 	 	
       
   767 	_LIT(KSQLQueryRow, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
   768 	
       
   769 	sqlStatement.Format(KSQLQueryRow, &KPeapDatabaseTableName, 
       
   770 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
   771 			
       
   772 	RDbView view;
       
   773 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
   774 	// View must be closed when no longer needed
       
   775 	CleanupClosePushL(view);
       
   776 	User::LeaveIfError(view.EvaluateAll());
       
   777 	
       
   778 	// 5. If row is not found then add it
       
   779 	
       
   780 	TInt rows = view.CountL();
       
   781 	CleanupStack::PopAndDestroy(); // view
       
   782 	if (rows == 0)
       
   783 	{
       
   784 		_LIT(KSQLInsert, "SELECT * FROM %S");
       
   785 		sqlStatement.Format(KSQLInsert, &KPeapDatabaseTableName);	
       
   786 
       
   787 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly));
       
   788 		CleanupClosePushL(view);
       
   789 		view.InsertL();
       
   790 
       
   791 		// Get column set so we get the correct column numbers
       
   792 		CDbColSet* colSet = view.ColSetL();
       
   793 		CleanupStack::PushL(colSet);
       
   794 
       
   795 		// Set the default values. The other three tables (certs, ca certs & cipher suites) are empty by default.
       
   796 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
       
   797 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);
       
   798 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
       
   799 		
       
   800 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_realm_literal), default_EAP_TLS_PEAP_use_manual_realm);
       
   801 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_realm_literal), default_EAP_TLS_PEAP_manual_realm);
       
   802 		
       
   803 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_username_literal), default_EAP_TLS_PEAP_use_manual_username);
       
   804 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_username_literal), default_EAP_TLS_PEAP_manual_username);
       
   805 		
       
   806 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_cipher_suite_literal), default_EAP_TLS_PEAP_cipher_suite);
       
   807 		
       
   808 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_used_PEAP_version_literal), default_EAP_TLS_PEAP_used_PEAP_version);
       
   809 
       
   810 		TInt i(0);
       
   811 
       
   812 		while (default_EAP_TLS_PEAP_accepted_PEAP_versions[i] != -1)
       
   813 		{
       
   814 			i++;
       
   815 		}
       
   816 		
       
   817 		TBuf8<KMaxPEAPVersionsStringLengthInDB> tmp;
       
   818 		
       
   819 		tmp.Copy(reinterpret_cast<const TUint8 *> (default_EAP_TLS_PEAP_accepted_PEAP_versions), i * sizeof(TInt));
       
   820 		
       
   821 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal), tmp);
       
   822 
       
   823 		view.SetColL(colSet->ColNo(cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal), default_PEAP_tunneled_types);
       
   824 		view.SetColL(colSet->ColNo(cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal), default_PEAP_tunneled_types);
       
   825 		
       
   826 		view.SetColL(colSet->ColNo(cf_str_TLS_server_authenticates_client_policy_in_client_literal), default_EAP_PEAP_TTLS_server_authenticates_client);
       
   827 		view.SetColL(colSet->ColNo(KCACertLabelOld), default_CA_cert_label);
       
   828 		view.SetColL(colSet->ColNo(KClientCertLabel), default_client_cert_label);	
       
   829 
       
   830 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal), default_EAP_TLS_PEAP_verify_certificate_realm);
       
   831 
       
   832 		view.SetColL(colSet->ColNo(cf_str_EAP_PEAP_max_session_validity_time_literal), default_MaxSessionTime);
       
   833 		
       
   834 		view.SetColL(colSet->ColNo(KPEAPLastFullAuthTime), default_FullAuthTime);
       
   835 
       
   836 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_identity_privacy_literal), default_EAP_TLS_PEAP_TLS_Privacy);						
       
   837 
       
   838 		view.PutL();
       
   839 		
       
   840 		CleanupStack::PopAndDestroy(colSet); 
       
   841 		CleanupStack::PopAndDestroy( &view ); // Close view.
       
   842 
       
   843 		// Add default disabled cipher suites
       
   844 		_LIT(KSQLInsert2, "SELECT * FROM %S");
       
   845 		sqlStatement.Format(KSQLInsert2, &KPeapAllowedCipherSuitesDatabaseTableName);
       
   846 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly));
       
   847 		CleanupClosePushL(view);
       
   848 
       
   849 		// Get column set so we get the correct column numbers
       
   850 		colSet = view.ColSetL();
       
   851 		CleanupStack::PushL(colSet);
       
   852 
       
   853 		i = 0;
       
   854 		while (default_allowed_cipher_suites[i] != 0)
       
   855 		{
       
   856 			view.InsertL();
       
   857 			view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
       
   858 			view.SetColL(colSet->ColNo(KServiceIndex), aIndex);
       
   859 			view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
       
   860 			view.SetColL(colSet->ColNo(KCipherSuite), default_allowed_cipher_suites[i]);
       
   861 			view.PutL();
       
   862 			i++;
       
   863 		}
       
   864 		
       
   865 		CleanupStack::PopAndDestroy( colSet ); // Delete colSet.		
       
   866 		CleanupStack::PopAndDestroy( &view ); // Close view.
       
   867 	} 
       
   868 	
       
   869 	// 6. Do the altering of tables here. 
       
   870 	//    Add columns to existing certificate DB tables for Serial number, Issuer name etc. 
       
   871 
       
   872 	TBufC<KDbMaxColName> tableName;
       
   873 
       
   874 	// For the table _allowed_ USER certificates
       
   875 	tableName = KPeapAllowedUserCertsDatabaseTableName;	
       
   876 	AddExtraCertColumnsL(aDatabase,tableName);
       
   877 	
       
   878 	// For the table _allowed_ CA certificates	
       
   879 	tableName = KPeapAllowedCACertsDatabaseTableName;	
       
   880 	AddExtraCertColumnsL(aDatabase,tableName);
       
   881 
       
   882 	CleanupStack::PopAndDestroy( buf ); // Delete buf or sqlStatement
       
   883 	CleanupStack::Pop( &aDatabase );	
       
   884 	CleanupStack::Pop( &aSession );	
       
   885 	
       
   886 	aDatabase.Compact();
       
   887 }
       
   888 
       
   889 #if defined(USE_TTLS_EAP_TYPE)
       
   890 
       
   891 // ---------------------------------------------------------
       
   892 // EapTlsPeapUtils::OpenTtlsDatabaseL()
       
   893 // ---------------------------------------------------------
       
   894 //
       
   895 void EapTlsPeapUtils::OpenTtlsDatabaseL(
       
   896 		RDbNamedDatabase& aDatabase, 
       
   897 		RDbs& aSession, 
       
   898 		const TIndexType aIndexType, 
       
   899 		const TInt aIndex,
       
   900 		const eap_type_value_e aTunnelingType)
       
   901 {
       
   902 #ifdef USE_EAP_EXPANDED_TYPES
       
   903 
       
   904 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
   905 
       
   906 #else
       
   907 
       
   908 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
   909 
       
   910 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
   911 
       
   912 	EAP_TRACE_DEBUG_SYMBIAN(
       
   913 		(_L("EapTlsPeapUtils::OpenTtlsDatabaseL -Start- aIndexType=%d, aIndex=%d, Tunneling vendor type=%d \n"),
       
   914 		aIndexType,aIndex, aTunnelingVendorType));
       
   915 
       
   916 	// 1. Open/create a database	
       
   917 	
       
   918 	// Connect to the DBMS server.
       
   919 	User::LeaveIfError(aSession.Connect());		
       
   920 	CleanupClosePushL(aSession);	
       
   921 	// aSession and aDatabase are pushed to the cleanup stack even though they may be member
       
   922 	// variables of the calling class and would be closed in the destructor anyway. This ensures
       
   923 	// that if they are not member variables they will be closed. Closing the handle twice
       
   924 	// does no harm.	
       
   925 	
       
   926 #ifdef SYMBIAN_SECURE_DBMS
       
   927 	
       
   928 	// Create the secure shared database with the specified secure policy.
       
   929 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
       
   930 	
       
   931 	TInt err = aDatabase.Create(aSession, KTtlsDatabaseName, KSecureUIDFormat);
       
   932 
       
   933 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::OpenTtlsDatabaseL - Created Secure DB for eapttls.dat. err=%d\n"), err) );
       
   934 	
       
   935 	if(err == KErrNone)
       
   936 	{
       
   937 		aDatabase.Close();
       
   938 		
       
   939 	} else if (err != KErrAlreadyExists) 
       
   940 	{
       
   941 		User::LeaveIfError(err);
       
   942 	}
       
   943 	
       
   944 	User::LeaveIfError(aDatabase.Open(aSession, KTtlsDatabaseName, KSecureUIDFormat));
       
   945 	CleanupClosePushL(aDatabase);		
       
   946 		
       
   947 #else
       
   948 	// For non-secured database. The database will be created in the old location (c:\system\data).
       
   949 	
       
   950 	RFs fsSession;		
       
   951 	User::LeaveIfError(fsSession.Connect());
       
   952 	CleanupClosePushL(fsSession);	
       
   953 	TInt err = aDatabase.Create(fsSession, KTtlsDatabaseName);
       
   954 
       
   955 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::OpenTtlsDatabaseL - Created Non-Secure DB for eapttls.dat. err=%d\n"), err) );
       
   956 	
       
   957 	if(err == KErrNone)
       
   958 	{
       
   959 		aDatabase.Close();
       
   960 		
       
   961 	} else if (err != KErrAlreadyExists) 
       
   962 	{
       
   963 		User::LeaveIfError(err);
       
   964 	}
       
   965 	
       
   966 	User::LeaveIfError(aDatabase.Open(fsSession, KTtlsDatabaseName));
       
   967 	
       
   968 	CleanupStack::PopAndDestroy(); // close fsSession
       
   969 	
       
   970 	CleanupClosePushL(aDatabase);		
       
   971 	    
       
   972 #endif // #ifdef SYMBIAN_SECURE_DBMS
       
   973 
       
   974 	// 2. Create the eapttls table to database (ignore error if exists)
       
   975 	
       
   976 // Table columns:
       
   977 //// NAME //////////////////////////////////////////// TYPE ////////////// Constant ///////////////////
       
   978 //| ServiceType									| UNSIGNED INTEGER 	| KServiceType        |//
       
   979 //| ServiceIndex								| UNSIGNED INTEGER 	| KServiceIndex       |//
       
   980 //| TunnelingType								| UNSIGNED INTEGER 	| KTunnelingType		|//
       
   981 //| EAP_TLS_PEAP_use_manual_realm				| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_use_manual_realm_literal      |//
       
   982 //| EAP_TLS_PEAP_manual_realm					| VARCHAR(255)     	| cf_str_EAP_TLS_PEAP_manual_realm_literal				|//
       
   983 //| EAP_TLS_PEAP_use_manual_username			| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_use_manual_username_literal   |//
       
   984 //| EAP_TLS_PEAP_manual_username				| VARCHAR(255)     	| cf_str_EAP_TLS_PEAP_manual_username_literal			|//
       
   985 //| EAP_TLS_PEAP_cipher_suite					| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_cipher_suite_literal	   |//
       
   986 //| EAP_TLS_PEAP_used_PEAP_version				| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_used_PEAP_version_literal		    |//
       
   987 //| EAP_TLS_PEAP_accepted_PEAP_versions			| BINARY(12)	    | cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal|//
       
   988 //| PEAP_accepted_tunneled_client_types			| VARBINARY(240) 	| cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal      |//
       
   989 //| PEAP_unaccepted_tunneled_client_types		| VARBINARY(240) 	| cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal      |//
       
   990 //| EAP_TLS_server_authenticates_client		    | UNSIGNED INTEGER 	| cf_str_TLS_server_authenticates_client_policy_in_client_literal|//
       
   991 //| CA_cert_label								| VARCHAR(255)     	| KCACertLabelOld	   |//
       
   992 //| client_cert_label							| VARCHAR(255)     	| KClientCertLabel	   |//
       
   993 //| EAP_TLS_PEAP_saved_session_id				| BINARY(32)       	| cf_str_EAP_TLS_PEAP_saved_session_id_literal		   |//
       
   994 //| EAP_TLS_PEAP_saved_master_secret			| BINARY(48)       	| cf_str_EAP_TLS_PEAP_saved_master_secret_literal	   |//
       
   995 //| EAP_TLS_PEAP_saved_cipher_suite				| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_saved_cipher_suite_literal   |//
       
   996 //| EAP_TLS_PEAP_verify_certificate_realm		| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal		   |//
       
   997 //| EAP_TTLS_max_session_validity_time			| BIGINT	   		| cf_str_EAP_TTLS_max_session_validity_time_literal   |//
       
   998 //| EAP_TTLS_last_full_authentication_time		| BIGINT	   		| KTTLSLastFullAuthTime	   	|//	
       
   999 //| EAP_TLS_PEAP_use_identity_privacy			| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_use_identity_privacy_literal		   |//
       
  1000 
       
  1001 
       
  1002 //| EAP_TLS_PEAP_ttls_pap_password_prompt               | UNSIGNED INTEGER  | cf_str_EAP_TLS_PEAP_ttls_pap_password_prompt_literal           |//
       
  1003 //| EAP_TLS_PEAP_ttls_pap_username                      | VARCHAR(253)      | cf_str_EAP_TLS_PEAP_ttls_pap_username_literal                  |//
       
  1004 //| EAP_TLS_PEAP_ttls_pap_password                      | VARCHAR(128)      | cf_str_EAP_TLS_PEAP_ttls_pap_password_literal                  |//
       
  1005 //| EAP_TLS_PEAP_ttls_pap_max_session_validity_time		| BIGINT		   	| cf_str_EAP_TLS_PEAP_ttls_pap_max_session_validity_time_literal |//
       
  1006 //| EAP_TLS_PEAP_ttls_pap_last_full_authentication_time	| BIGINT		   	| KTTLSPAPLastFullAuthTime	                             |//
       
  1007 
       
  1008 
       
  1009 //////////////////////////////////////////////////////////////////////////////////////////////////////////////	
       
  1010 	
       
  1011 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  1012 	TPtr sqlStatement = buf->Des();
       
  1013 	
       
  1014 // Table creation is divided into two parts because otherwise the SQL string would get too long
       
  1015 	_LIT(KSQLCreateTable1,
       
  1016 		"CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
  1017 			              %S UNSIGNED INTEGER, \
       
  1018 			              %S UNSIGNED INTEGER, \
       
  1019 			              %S UNSIGNED INTEGER, \
       
  1020 			              %S VARCHAR(%d),     \
       
  1021 			              %S UNSIGNED INTEGER, \
       
  1022 			              %S VARCHAR(%d),     \
       
  1023 			              %S UNSIGNED INTEGER, \
       
  1024 			              %S UNSIGNED INTEGER, \
       
  1025 			              %S BINARY(%d),		  \
       
  1026 			              %S VARBINARY(%d),	  \
       
  1027 			              %S VARBINARY(%d),	  \
       
  1028 			              %S UNSIGNED INTEGER, \
       
  1029 			              %S VARCHAR(%d),	  \
       
  1030 			              %S VARCHAR(%d),     \
       
  1031 			              %S BINARY(%d),		  \
       
  1032 			              %S BINARY(%d),		  \
       
  1033 			              %S UNSIGNED INTEGER, \
       
  1034 			              %S UNSIGNED INTEGER, \
       
  1035 			              %S BIGINT, \
       
  1036 			              %S BIGINT, \
       
  1037 				      			%S UNSIGNED INTEGER, \
       
  1038 			              %S UNSIGNED INTEGER, \
       
  1039 			              %S VARCHAR(%d), \
       
  1040 			              %S VARCHAR(%d), \
       
  1041                     %S BIGINT, \
       
  1042                     %S BIGINT)");
       
  1043 
       
  1044     sqlStatement.Format( KSQLCreateTable1,
       
  1045         &KTtlsDatabaseTableName,
       
  1046         &KServiceType,
       
  1047         &KServiceIndex,
       
  1048         &KTunnelingType,
       
  1049         &cf_str_EAP_TLS_PEAP_use_manual_realm_literal,
       
  1050         &cf_str_EAP_TLS_PEAP_manual_realm_literal, KMaxManualRealmLengthInDB,
       
  1051         &cf_str_EAP_TLS_PEAP_use_manual_username_literal,
       
  1052         &cf_str_EAP_TLS_PEAP_manual_username_literal, KMaxManualUsernameLengthInDB,
       
  1053         &cf_str_EAP_TLS_PEAP_cipher_suite_literal,
       
  1054         &cf_str_EAP_TLS_PEAP_used_PEAP_version_literal,
       
  1055         &cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal, KMaxPEAPVersionsStringLengthInDB,
       
  1056         &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, KMaxTunneledTypeStringLengthInDB,
       
  1057         &cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,	KMaxTunneledTypeStringLengthInDB,	
       
  1058         &cf_str_TLS_server_authenticates_client_policy_in_client_literal,
       
  1059         &KCACertLabelOld, KMaxCertLabelLengthInDB,
       
  1060         &KClientCertLabel, KMaxCertLabelLengthInDB,
       
  1061         &cf_str_EAP_TLS_PEAP_saved_session_id_literal, KMaxSessionIdLengthInDB,
       
  1062         &cf_str_EAP_TLS_PEAP_saved_master_secret_literal, KMaxMasterSecretLengthInDB,
       
  1063         &cf_str_EAP_TLS_PEAP_saved_cipher_suite_literal,
       
  1064         &cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal,
       
  1065         &cf_str_EAP_TTLS_max_session_validity_time_literal,
       
  1066         &KTTLSLastFullAuthTime,
       
  1067 		&cf_str_EAP_TLS_PEAP_use_identity_privacy_literal,		
       
  1068         &cf_str_EAP_TLS_PEAP_ttls_pap_password_prompt_literal,
       
  1069         &cf_str_EAP_TLS_PEAP_ttls_pap_username_literal, KMaxPapUserNameLengthInDb,
       
  1070         &cf_str_EAP_TLS_PEAP_ttls_pap_password_literal, KMaxPapPasswordLengthInDb,
       
  1071         &cf_str_EAP_TLS_PEAP_ttls_pap_max_session_validity_time_literal,
       
  1072         &KTTLSPAPLastFullAuthTime );	
       
  1073 
       
  1074 
       
  1075 	
       
  1076 	err = aDatabase.Execute(sqlStatement);
       
  1077 	if (err == KErrAlreadyExists)
       
  1078 		{
       
  1079 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::OpenTtlsDatabaseL - Alter Table err=%d\n"), err) );
       
  1080 		
       
  1081 		_LIT( KColumnDef, "UNSIGNED INTEGER" );
       
  1082 		AlterTableL( aDatabase, EAddColumn , KTtlsDatabaseTableName,
       
  1083 				cf_str_EAP_TLS_PEAP_use_identity_privacy_literal, KColumnDef);
       
  1084 
       
  1085 		_LIT( KColumnDef1, "UNSIGNED INTEGER" );
       
  1086 		AlterTableL( aDatabase, EAddColumn , KTtlsDatabaseTableName,
       
  1087 				cf_str_EAP_TLS_PEAP_ttls_pap_password_prompt_literal, KColumnDef1);
       
  1088 
       
  1089         HBufC* buf1 = HBufC::NewLC(KMaxSqlQueryLength);
       
  1090         TPtr sqlStatement = buf1->Des();
       
  1091        
       
  1092         _LIT(KSQLAlterTableForVar, "VARCHAR (%d)");                                          
       
  1093     
       
  1094         sqlStatement.Format(KSQLAlterTableForVar, KMaxPapUserNameLengthInDb);
       
  1095  
       
  1096 		AlterTableL( aDatabase, EAddColumn , KTtlsDatabaseTableName,
       
  1097 				cf_str_EAP_TLS_PEAP_ttls_pap_username_literal, sqlStatement);
       
  1098 
       
  1099         sqlStatement.Format(KSQLAlterTableForVar, KMaxPapPasswordLengthInDb);
       
  1100         
       
  1101 		AlterTableL( aDatabase, EAddColumn , KTtlsDatabaseTableName,
       
  1102 				cf_str_EAP_TLS_PEAP_ttls_pap_password_literal, sqlStatement);
       
  1103 
       
  1104 		CleanupStack::PopAndDestroy(buf1);
       
  1105 		
       
  1106 		_LIT( KColumnDef4, "BIGINT" );
       
  1107 		AlterTableL( aDatabase, EAddColumn , KTtlsDatabaseTableName,
       
  1108 				cf_str_EAP_TLS_PEAP_ttls_pap_max_session_validity_time_literal, KColumnDef4);
       
  1109 				
       
  1110 		_LIT( KColumnDef5, "BIGINT" );
       
  1111 		AlterTableL( aDatabase, EAddColumn , KTtlsDatabaseTableName,
       
  1112 				KTTLSPAPLastFullAuthTime, KColumnDef5);
       
  1113 				
       
  1114 		}
       
  1115 	else if (err != KErrNone)
       
  1116 		{
       
  1117 		User::Leave(err);
       
  1118 		}
       
  1119 
       
  1120 	// Create table for _allowed_ user certificates
       
  1121 	
       
  1122 //// NAME ////////////////// TYPE ////////////// Constant ///////////
       
  1123 //| ServiceType		  	| UNSIGNED INTEGER | KServiceType        |//
       
  1124 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
  1125 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
  1126 //| CertLabel			| VARCHAR(255)     | KCACertLabel        |//	
       
  1127 //| SubjectKeyId		| BINARY(20)	   | KSubjectKeyIdentifier |// This is Symbian subjectkey id
       
  1128 //| ActualSubjectKeyId  | BINARY(20)	   | KActualSubjectKeyIdentifier |// This is the actual subjectkeyid present in the certificate.
       
  1129 //| SubjectName			| VARCHAR(255)     | KSubjectName        |//	
       
  1130 //| IssuerName			| VARCHAR(255)     | KIssuerName        |//	
       
  1131 //| SerialNumber		| VARCHAR(255)     | KSerialNumber        |//	
       
  1132 //| Thumbprint			| BINARY(64)	   | KThumbprint        |//	
       
  1133 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
  1134 	
       
  1135 	_LIT(KSQLCreateTable2, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
  1136 											 %S UNSIGNED INTEGER, \
       
  1137 											 %S UNSIGNED INTEGER, \
       
  1138 											 %S VARCHAR(%d), \
       
  1139 											 %S BINARY(%d), \
       
  1140 											 %S BINARY(%d), \
       
  1141 											 %S VARCHAR(%d), \
       
  1142 											 %S VARCHAR(%d), \
       
  1143 											 %S VARCHAR(%d), \
       
  1144 											 %S BINARY(%d))");											 
       
  1145 											 
       
  1146 	sqlStatement.Format(KSQLCreateTable2, &KTtlsAllowedUserCertsDatabaseTableName, 
       
  1147 		&KServiceType, 
       
  1148 		&KServiceIndex, 
       
  1149 		&KTunnelingType, 
       
  1150 		&KCertLabel, KMaxCertLabelLengthInDB,
       
  1151 		&KSubjectKeyIdentifier, KMaxSubjectKeyIdLengthInDB,
       
  1152 		&KActualSubjectKeyIdentifier, KKeyIdentifierLength,
       
  1153 		&KSubjectName, KGeneralStringMaxLength,
       
  1154 		&KIssuerName, KGeneralStringMaxLength,
       
  1155 		&KSerialNumber, KGeneralStringMaxLength,
       
  1156 		&KThumbprint, KThumbprintMaxLength);
       
  1157 		
       
  1158 	err = aDatabase.Execute(sqlStatement);
       
  1159 	if (err != KErrNone && err != KErrAlreadyExists)
       
  1160 	{
       
  1161 		User::Leave(err);
       
  1162 	}	
       
  1163 
       
  1164 	// Create table for _allowed_ CA certs
       
  1165 
       
  1166 //// NAME ////////////////// TYPE ////////////// Constant ///////////
       
  1167 //| ServiceType			| UNSIGNED INTEGER | KServiceType        |//
       
  1168 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
  1169 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
  1170 //| CACertLabel			| VARCHAR(255)     | KCACertLabel        |//	
       
  1171 //| SubjectKeyId		| BINARY(20)	   | KSubjectKeyIdentifier |// This is Symbian subjectkey id
       
  1172 //| ActualSubjectKeyId  | BINARY(20)	   | KActualSubjectKeyIdentifier |// This is the actual subjectkeyid present in the certificate.
       
  1173 //| SubjectName			| VARCHAR(255)     | KSubjectName        |//	
       
  1174 //| IssuerName			| VARCHAR(255)     | KIssuerName        |//	
       
  1175 //| SerialNumber		| VARCHAR(255)     | KSerialNumber        |//	
       
  1176 //| Thumbprint			| BINARY(64)	   | KThumbprint        |//	
       
  1177 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
  1178 
       
  1179 	_LIT(KSQLCreateTable3, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
  1180 											 %S UNSIGNED INTEGER, \
       
  1181 											 %S UNSIGNED INTEGER, \
       
  1182 											 %S VARCHAR(%d), \
       
  1183 											 %S BINARY(%d), \
       
  1184 											 %S BINARY(%d), \
       
  1185 											 %S VARCHAR(%d), \
       
  1186 											 %S VARCHAR(%d), \
       
  1187 											 %S VARCHAR(%d), \
       
  1188 											 %S BINARY(%d))");
       
  1189 											 
       
  1190 	sqlStatement.Format(KSQLCreateTable3, &KTtlsAllowedCACertsDatabaseTableName, 
       
  1191 		&KServiceType, 
       
  1192 		&KServiceIndex, 
       
  1193 		&KTunnelingType, 
       
  1194 		&KCertLabel, KMaxCertLabelLengthInDB,
       
  1195 		&KSubjectKeyIdentifier, KMaxSubjectKeyIdLengthInDB,
       
  1196 		&KActualSubjectKeyIdentifier, KKeyIdentifierLength,
       
  1197 		&KSubjectName, KGeneralStringMaxLength,
       
  1198 		&KIssuerName, KGeneralStringMaxLength,
       
  1199 		&KSerialNumber, KGeneralStringMaxLength,
       
  1200 		&KThumbprint, KThumbprintMaxLength);
       
  1201 		
       
  1202 	err = aDatabase.Execute(sqlStatement);
       
  1203 	if (err != KErrNone && err != KErrAlreadyExists)
       
  1204 	{
       
  1205 		User::Leave(err);
       
  1206 	}
       
  1207 
       
  1208 	// Create table for _allowed_ cipher suites
       
  1209 
       
  1210 //// NAME ///////////////// TYPE ////////////// Constant ///////////
       
  1211 //| ServiceType			| UNSIGNED INTEGER | KServiceType        |//
       
  1212 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
  1213 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
  1214 //| CipherSuite			| UNSIGNED INTEGER | KCipherSuite        |//	
       
  1215 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
  1216 	
       
  1217 	_LIT(KSQLCreateTable4, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
  1218 											 %S UNSIGNED INTEGER, \
       
  1219 											 %S UNSIGNED INTEGER, \
       
  1220 											 %S UNSIGNED INTEGER)");
       
  1221 
       
  1222 	sqlStatement.Format(KSQLCreateTable4, &KTtlsAllowedCipherSuitesDatabaseTableName, 
       
  1223 		&KServiceType, &KServiceIndex, &KTunnelingType, &KCipherSuite);
       
  1224 	err = aDatabase.Execute(sqlStatement);
       
  1225 	if (err != KErrNone && err != KErrAlreadyExists)
       
  1226 	{
       
  1227 		User::Leave(err);
       
  1228 	}
       
  1229 
       
  1230 	// 4. Check if database table contains a row for this service type and id  	
       
  1231 	
       
  1232 	_LIT(KSQLQueryRow, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  1233 
       
  1234 	sqlStatement.Format(KSQLQueryRow, &KTtlsDatabaseTableName, 
       
  1235 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);	
       
  1236 			
       
  1237 	RDbView view;
       
  1238 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  1239 	// View must be closed when no longer needed
       
  1240 	CleanupClosePushL(view);
       
  1241 	User::LeaveIfError(view.EvaluateAll());
       
  1242 	
       
  1243 	// 5. If row is not found then add it
       
  1244 	
       
  1245 	TInt rows = view.CountL();
       
  1246 	CleanupStack::PopAndDestroy(); // view
       
  1247 	if (rows == 0)
       
  1248 	{
       
  1249 		_LIT(KSQLInsert, "SELECT * FROM %S");
       
  1250 		sqlStatement.Format(KSQLInsert, &KTtlsDatabaseTableName);	
       
  1251 
       
  1252 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly));
       
  1253 		CleanupClosePushL(view);
       
  1254 		view.InsertL();
       
  1255 
       
  1256 		// Get column set so we get the correct column numbers
       
  1257 		CDbColSet* colSet = view.ColSetL();
       
  1258 		CleanupStack::PushL(colSet);
       
  1259 
       
  1260 		// Set the default values. The other three tables (certs, ca certs & cipher suites) are empty by default.
       
  1261 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
       
  1262 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);		
       
  1263 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
       
  1264 		
       
  1265 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_realm_literal), default_EAP_TLS_PEAP_use_manual_realm);
       
  1266 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_realm_literal), default_EAP_TLS_PEAP_manual_realm);
       
  1267 		
       
  1268 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_username_literal), default_EAP_TLS_PEAP_use_manual_username);
       
  1269 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_username_literal), default_EAP_TLS_PEAP_manual_username);
       
  1270 		
       
  1271 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_cipher_suite_literal), default_EAP_TLS_PEAP_cipher_suite);
       
  1272 
       
  1273 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_used_PEAP_version_literal), default_EAP_TLS_PEAP_used_PEAP_version);
       
  1274 
       
  1275 		TInt i(0);
       
  1276 
       
  1277 		while (default_EAP_TLS_PEAP_accepted_PEAP_versions[i] != -1)
       
  1278 		{
       
  1279 			i++;
       
  1280 		}
       
  1281 		
       
  1282 		TBuf8<KMaxPEAPVersionsStringLengthInDB> tmp;
       
  1283 		
       
  1284 		tmp.Copy(reinterpret_cast<const TUint8 *> (default_EAP_TLS_PEAP_accepted_PEAP_versions), i * sizeof(TInt));
       
  1285 		
       
  1286 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal), tmp);
       
  1287 
       
  1288 		view.SetColL(colSet->ColNo(cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal), default_PEAP_tunneled_types);
       
  1289 		view.SetColL(colSet->ColNo(cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal), default_PEAP_tunneled_types);		
       
  1290 		
       
  1291 		view.SetColL(colSet->ColNo(cf_str_TLS_server_authenticates_client_policy_in_client_literal), default_EAP_PEAP_TTLS_server_authenticates_client);
       
  1292 		view.SetColL(colSet->ColNo(KCACertLabelOld), default_CA_cert_label);
       
  1293 		
       
  1294 		view.SetColL(colSet->ColNo(KClientCertLabel), default_client_cert_label);	
       
  1295 
       
  1296 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal), default_EAP_TLS_PEAP_verify_certificate_realm);
       
  1297 		
       
  1298 		view.SetColL(colSet->ColNo(cf_str_EAP_TTLS_max_session_validity_time_literal), default_MaxSessionTime);
       
  1299 		
       
  1300 		view.SetColL(colSet->ColNo(KTTLSLastFullAuthTime), default_FullAuthTime);				
       
  1301 
       
  1302 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_identity_privacy_literal), default_EAP_TLS_PEAP_TLS_Privacy);
       
  1303 
       
  1304 
       
  1305 		view.SetColL( colSet->ColNo(
       
  1306 			cf_str_EAP_TLS_PEAP_ttls_pap_password_prompt_literal ),
       
  1307 			KDefaultPapPasswordPrompt );
       
  1308 		
       
  1309 		view.SetColL( colSet->ColNo(
       
  1310 			cf_str_EAP_TLS_PEAP_ttls_pap_username_literal ),
       
  1311 			KDefaultPapUserName );
       
  1312 		
       
  1313 		view.SetColL( colSet->ColNo(
       
  1314 			cf_str_EAP_TLS_PEAP_ttls_pap_password_literal ),
       
  1315 			KDefaultPapPassword );
       
  1316 		
       
  1317 		view.SetColL( colSet->ColNo(
       
  1318 			cf_str_EAP_TLS_PEAP_ttls_pap_max_session_validity_time_literal ),
       
  1319 			KDefaultMaxPapSessionTime );
       
  1320 		
       
  1321 		view.SetColL(
       
  1322 			colSet->ColNo( KTTLSPAPLastFullAuthTime ),
       
  1323 			KDefaultFullPapAuthTime );		
       
  1324 
       
  1325 		
       
  1326 		view.PutL();
       
  1327 		
       
  1328 		CleanupStack::PopAndDestroy(colSet); 
       
  1329 		CleanupStack::PopAndDestroy( &view ); // Close view.
       
  1330 
       
  1331 		// Add default disabled cipher suites
       
  1332 		_LIT(KSQLInsert2, "SELECT * FROM %S");
       
  1333 		sqlStatement.Format(KSQLInsert2, &KTtlsAllowedCipherSuitesDatabaseTableName);
       
  1334 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly));
       
  1335 		CleanupClosePushL(view);
       
  1336 
       
  1337 		// Get column set so we get the correct column numbers
       
  1338 		colSet = view.ColSetL();
       
  1339 		CleanupStack::PushL(colSet);
       
  1340 
       
  1341 		i = 0;
       
  1342 		while (default_allowed_cipher_suites[i] != 0)
       
  1343 		{
       
  1344 			view.InsertL();
       
  1345 			view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
       
  1346 			view.SetColL(colSet->ColNo(KServiceIndex), aIndex);		
       
  1347 			view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);			
       
  1348 			view.SetColL(colSet->ColNo(KCipherSuite), default_allowed_cipher_suites[i]);
       
  1349 			view.PutL();
       
  1350 			i++;
       
  1351 		}
       
  1352 		
       
  1353 		CleanupStack::PopAndDestroy( colSet ); // Delete colSet.		
       
  1354 		CleanupStack::PopAndDestroy( &view ); // Close view.
       
  1355 	}
       
  1356 	 
       
  1357 	// 6. Do the altering of tables here. 
       
  1358 	//    Add columns to existing certificate DB tables for Serial number, Issuer name etc. 
       
  1359 
       
  1360 	TBufC<KDbMaxColName> tableName;
       
  1361 
       
  1362 	// For the table _allowed_ USER certificates
       
  1363 	tableName = KTtlsAllowedUserCertsDatabaseTableName;	
       
  1364 	AddExtraCertColumnsL(aDatabase,tableName);
       
  1365 	
       
  1366 	// For the table _allowed_ CA certificates	
       
  1367 	tableName = KTtlsAllowedCACertsDatabaseTableName;	
       
  1368 	AddExtraCertColumnsL(aDatabase,tableName);
       
  1369 
       
  1370 	CleanupStack::PopAndDestroy( buf ); // Delete buf or sqlStatement
       
  1371 	CleanupStack::Pop( &aDatabase );	
       
  1372 	CleanupStack::Pop( &aSession );
       
  1373 	
       
  1374 	aDatabase.Compact();
       
  1375 	
       
  1376 } // EapTlsPeapUtils::OpenTtlsDatabaseL()
       
  1377 
       
  1378 #endif // #if defined(USE_TTLS_EAP_TYPE)
       
  1379 
       
  1380 #if defined(USE_FAST_EAP_TYPE)
       
  1381 
       
  1382 // ---------------------------------------------------------
       
  1383 // EapTlsPeapUtils::OpenFastDatabaseL()
       
  1384 // ---------------------------------------------------------
       
  1385 //
       
  1386 void EapTlsPeapUtils::OpenFastDatabaseL(
       
  1387 	RDbNamedDatabase& aDatabase, 
       
  1388 	RDbs& aSession, 
       
  1389 	const TIndexType aIndexType, 
       
  1390 	const TInt aIndex,
       
  1391 	const eap_type_value_e aTunnelingType)
       
  1392     {
       
  1393 #ifdef USE_EAP_EXPANDED_TYPES
       
  1394 
       
  1395 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  1396 
       
  1397 #else
       
  1398 
       
  1399 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  1400 
       
  1401 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  1402 
       
  1403 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1404 		(_L("EapTlsPeapUtils::OpenFastDatabaseL -Start- aIndexType=%d, aIndex=%d, Tunneling vendor type=%d \n"),
       
  1405 		aIndexType,aIndex, aTunnelingVendorType));
       
  1406 
       
  1407 	// 1. Open/create a database	
       
  1408 	
       
  1409 	// Connect to the DBMS server.
       
  1410 	User::LeaveIfError(aSession.Connect());		
       
  1411 	CleanupClosePushL(aSession);	
       
  1412 	// aSession and aDatabase are pushed to the cleanup stack even though they may be member
       
  1413 	// variables of the calling class and would be closed in the destructor anyway. This ensures
       
  1414 	// that if they are not member variables they will be closed. Closing the handle twice
       
  1415 	// does no harm.	
       
  1416 	
       
  1417 #ifdef SYMBIAN_SECURE_DBMS
       
  1418 	
       
  1419 	// Create the secure shared database with the specified secure policy.
       
  1420 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
       
  1421 	
       
  1422 	TInt err = aDatabase.Create(aSession, KFastDatabaseName, KSecureUIDFormat);
       
  1423 
       
  1424 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1425 		(_L("EapTlsPeapUtils::OpenFastDatabaseL - Created Secure DB for eapfast.dat. err=%d (-11=DB created before)\n"),
       
  1426 		err) );
       
  1427 	
       
  1428 	if(err == KErrNone)
       
  1429 	{
       
  1430 		aDatabase.Close();
       
  1431 		
       
  1432 	} else if (err != KErrAlreadyExists) 
       
  1433 	{
       
  1434 		User::LeaveIfError(err);
       
  1435 	}
       
  1436 	
       
  1437 	User::LeaveIfError(aDatabase.Open(aSession, KFastDatabaseName, KSecureUIDFormat));
       
  1438 	CleanupClosePushL(aDatabase);		
       
  1439 		
       
  1440 #else
       
  1441 	// For non-secured database. The database will be created in the old location (c:\system\data).
       
  1442 	
       
  1443 	RFs fsSession;		
       
  1444 	User::LeaveIfError(fsSession.Connect());
       
  1445 	CleanupClosePushL(fsSession);	
       
  1446 	TInt err = aDatabase.Create(fsSession, KFastDatabaseName);
       
  1447 
       
  1448 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::OpenFastDatabaseL - Created Non-Secure DB for eapfast.dat. err=%d\n"), err) );
       
  1449 	
       
  1450 	if(err == KErrNone)
       
  1451 	{
       
  1452 		aDatabase.Close();
       
  1453 		
       
  1454 	} else if (err != KErrAlreadyExists) 
       
  1455 	{
       
  1456 		User::LeaveIfError(err);
       
  1457 	}
       
  1458 	
       
  1459 	User::LeaveIfError(aDatabase.Open(fsSession, KFastDatabaseName));
       
  1460 	
       
  1461 	CleanupStack::PopAndDestroy(); // close fsSession
       
  1462 	
       
  1463 	CleanupClosePushL(aDatabase);		
       
  1464 	    
       
  1465 #endif // #ifdef SYMBIAN_SECURE_DBMS
       
  1466 
       
  1467 	// 2. Create the eapfast tables to database (ignore error if exists)
       
  1468 	
       
  1469 	// Table 1: Create table for general settings of EAP-FAST.
       
  1470 	
       
  1471 // Table columns:
       
  1472 //// NAME //////////////////////////////////////////// TYPE ////////////// Constant ///////////////////
       
  1473 //| ServiceType									| UNSIGNED INTEGER 	| KServiceType        |//
       
  1474 //| ServiceIndex								| UNSIGNED INTEGER 	| KServiceIndex       |//
       
  1475 //| TunnelingType								| UNSIGNED INTEGER 	| KTunnelingType		|//
       
  1476 //| EAP_TLS_PEAP_use_manual_realm				| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_use_manual_realm_literal      |//
       
  1477 //| EAP_TLS_PEAP_manual_realm					| VARCHAR(255)     	| cf_str_EAP_TLS_PEAP_manual_realm_literal				|//
       
  1478 //| EAP_TLS_PEAP_use_manual_username			| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_use_manual_username_literal   |//
       
  1479 //| EAP_TLS_PEAP_manual_username				| VARCHAR(255)     	| cf_str_EAP_TLS_PEAP_manual_username_literal			|//
       
  1480 //| EAP_TLS_PEAP_cipher_suite					| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_cipher_suite_literal	   |//
       
  1481 //| EAP_TLS_PEAP_used_PEAP_version				| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_used_PEAP_version_literal		    |//
       
  1482 //| EAP_TLS_PEAP_accepted_PEAP_versions			| BINARY(12)	    | cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal|//
       
  1483 //| PEAP_accepted_tunneled_client_types			| VARBINARY(240) 	| cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal      |//
       
  1484 //| PEAP_unaccepted_tunneled_client_types		| VARBINARY(240) 	| cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal      |//
       
  1485 //| EAP_TLS_server_authenticates_client		    | UNSIGNED INTEGER 	| cf_str_TLS_server_authenticates_client_policy_in_client_literal|//
       
  1486 //| EAP_TLS_PEAP_saved_session_id				| BINARY(32)       	| cf_str_EAP_TLS_PEAP_saved_session_id_literal		   |//
       
  1487 //| EAP_TLS_PEAP_saved_master_secret			| BINARY(48)       	| cf_str_EAP_TLS_PEAP_saved_master_secret_literal	   |//
       
  1488 //| EAP_TLS_PEAP_saved_cipher_suite				| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_saved_cipher_suite_literal   |//
       
  1489 //| EAP_TLS_PEAP_verify_certificate_realm		| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal		   |//
       
  1490 //| EAP_FAST_max_session_validity_time			| BIGINT	   		| cf_str_EAP_FAST_max_session_validity_time_literal   |//
       
  1491 //| EAP_FAST_last_full_authentication_time		| BIGINT	   		| KFASTLastFullAuthTime	   	|//	
       
  1492 //| EAP_TLS_PEAP_use_identity_privacy			| UNSIGNED INTEGER 	| cf_str_EAP_TLS_PEAP_use_identity_privacy_literal		   |//
       
  1493 //////////////////////////////////////////////////////////////////////////////////////////////////////////////	
       
  1494 
       
  1495 /** moved to PAC store db, because time is the same for all IAPs **/	
       
  1496 //| EAP_FAST_last_password_identity_time	| BIGINT	   		| KFASTLastPasswordIdentityTime	   	|//	
       
  1497 //////////////////////////////////////////////////////////////////////////////////////////////////////////////		
       
  1498 	
       
  1499 	
       
  1500 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  1501 	TPtr sqlStatement = buf->Des();
       
  1502 	
       
  1503 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1504 		(_L("EapTlsPeapUtils::OpenFastDatabaseL - Creating the tables for EAP-FAST\n")));
       
  1505 	
       
  1506 	_LIT(KSQLCreateTable1, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
  1507 											 %S UNSIGNED INTEGER, \
       
  1508 											 %S UNSIGNED INTEGER, \
       
  1509 											 %S UNSIGNED INTEGER, \
       
  1510 											 %S VARCHAR(%d),     \
       
  1511 											 %S UNSIGNED INTEGER, \
       
  1512 											 %S VARCHAR(%d),     \
       
  1513 											 %S UNSIGNED INTEGER, \
       
  1514 											 %S UNSIGNED INTEGER, \
       
  1515 											 %S BINARY(%d),		  \
       
  1516 											 %S VARBINARY(%d),	  \
       
  1517 											 %S VARBINARY(%d),	  \
       
  1518 											 %S UNSIGNED INTEGER, \
       
  1519 											 %S BINARY(%d),		  \
       
  1520 											 %S BINARY(%d),		  \
       
  1521 											 %S UNSIGNED INTEGER, \
       
  1522 											 %S UNSIGNED INTEGER, \
       
  1523 											 %S BIGINT, \
       
  1524 											 %S BIGINT, \
       
  1525 											 %S UNSIGNED INTEGER)");
       
  1526 	
       
  1527 	sqlStatement.Format(KSQLCreateTable1, &KFastGeneralSettingsDBTableName,
       
  1528 		&KServiceType,
       
  1529 		&KServiceIndex,
       
  1530 		&KTunnelingType,
       
  1531 		&cf_str_EAP_TLS_PEAP_use_manual_realm_literal,
       
  1532 		&cf_str_EAP_TLS_PEAP_manual_realm_literal, KMaxManualRealmLengthInDB,
       
  1533 		&cf_str_EAP_TLS_PEAP_use_manual_username_literal,
       
  1534 		&cf_str_EAP_TLS_PEAP_manual_username_literal, KMaxManualUsernameLengthInDB,
       
  1535 		&cf_str_EAP_TLS_PEAP_cipher_suite_literal,
       
  1536 		&cf_str_EAP_TLS_PEAP_used_PEAP_version_literal,
       
  1537 		&cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal, KMaxPEAPVersionsStringLengthInDB,
       
  1538 		&cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, KMaxTunneledTypeStringLengthInDB,
       
  1539 		&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,	KMaxTunneledTypeStringLengthInDB,	
       
  1540 		&cf_str_TLS_server_authenticates_client_policy_in_client_literal,
       
  1541 		&cf_str_EAP_TLS_PEAP_saved_session_id_literal, KMaxSessionIdLengthInDB,
       
  1542 		&cf_str_EAP_TLS_PEAP_saved_master_secret_literal, KMaxMasterSecretLengthInDB,
       
  1543 		&cf_str_EAP_TLS_PEAP_saved_cipher_suite_literal,
       
  1544 		&cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal,
       
  1545 		&cf_str_EAP_FAST_max_session_validity_time_literal,
       
  1546 		&KFASTLastFullAuthTime,
       
  1547 		&cf_str_EAP_TLS_PEAP_use_identity_privacy_literal);		
       
  1548 	
       
  1549 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1550 		(_L("EapTlsPeapUtils::OpenFastDatabaseL - SQL query formated OK\n")));
       
  1551 	
       
  1552 	err = aDatabase.Execute(sqlStatement);
       
  1553 	if (err != KErrNone && err != KErrAlreadyExists)
       
  1554 	{
       
  1555 		User::Leave(err);
       
  1556 	}
       
  1557 
       
  1558 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1559 		(_L("EapTlsPeapUtils::OpenFastDatabaseL Created General settings table\n")));
       
  1560 
       
  1561 	// Table 2: Create table for Special settings of EAP-FAST.
       
  1562 	
       
  1563 // Table columns:
       
  1564 //// NAME //////////////////////////////////////////// TYPE ////////////// Constant ///////////////////
       
  1565 //| ServiceType									| UNSIGNED INTEGER 	| KServiceType        |//
       
  1566 //| ServiceIndex								| UNSIGNED INTEGER 	| KServiceIndex       |//
       
  1567 //| TunnelingType								| UNSIGNED INTEGER 	| KTunnelingType		|//
       
  1568 //| EAP_FAST_allow_server_authenticated_provisioning_mode| UNSIGNED INTEGER	| cf_str_EAP_FAST_allow_server_authenticated_provisioning_mode_literal	   	|//	
       
  1569 //| EAP_FAST_allow_server_unauthenticated_provisioning_mode_ADHP| UNSIGNED INTEGER	| cf_str_EAP_FAST_allow_server_unauthenticated_provisioning_mode_ADHP_literal	   	|//	
       
  1570 //| EAP_FAST_Warn_ADHP_No_PAC					| UNSIGNED INTEGER	| KFASTWarnADHPNoPACP|//	
       
  1571 //| EAP_FAST_Warn_ADHP_No_Matching_PAC			| UNSIGNED INTEGER	| KFASTWarnADHPNoMatchingPAC|//	
       
  1572 //| EAP_FAST_Warn_Not_Default_Server			| UNSIGNED INTEGER	| KFASTWarnNotDefaultServer|//	
       
  1573 //| EAP_FAST_PAC_Group_Import_Reference_Collection| VARCHAR(255)	| KFASTPACGroupImportReferenceCollection	   	|//	
       
  1574 //| EAP_FAST_PAC_Group_DB_Reference_Collection	| BINARY(255)		| KFASTPACGroupDBReferenceCollection	   	|//		
       
  1575 //////////////////////////////////////////////////////////////////////////////////////////////////////////////	
       
  1576 
       
  1577 	
       
  1578 	_LIT(KSQLCreateTable2, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
  1579 											 %S UNSIGNED INTEGER, \
       
  1580 											 %S UNSIGNED INTEGER, \
       
  1581 											 %S UNSIGNED INTEGER, \
       
  1582 											 %S UNSIGNED INTEGER, \
       
  1583 											 %S UNSIGNED INTEGER, \
       
  1584 											 %S UNSIGNED INTEGER, \
       
  1585 											 %S UNSIGNED INTEGER, \
       
  1586 											 %S VARCHAR(%d),     \
       
  1587 											 %S BINARY(%d)		  )");
       
  1588 											 
       
  1589 	sqlStatement.Format(KSQLCreateTable2, &KFastSpecialSettingsDBTableName,
       
  1590 		&KServiceType,
       
  1591 		&KServiceIndex,
       
  1592 		&KTunnelingType,
       
  1593 		&cf_str_EAP_FAST_allow_server_authenticated_provisioning_mode_literal,
       
  1594 		&cf_str_EAP_FAST_allow_server_unauthenticated_provisioning_mode_ADHP_literal,
       
  1595 		&KFASTWarnADHPNoPAC,
       
  1596 		&KFASTWarnADHPNoMatchingPAC,
       
  1597 		&KFASTWarnNotDefaultServer,
       
  1598 		&KFASTPACGroupImportReferenceCollection, KMaxPACGroupRefCollectionLengthInDB,
       
  1599 		&KFASTPACGroupDBReferenceCollection, KMaxPACGroupRefCollectionLengthInDB);
       
  1600 	
       
  1601 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1602 		(_L("EapTlsPeapUtils::OpenFastDatabaseL - SQL query formated OK\n")));
       
  1603 	
       
  1604 	err = aDatabase.Execute(sqlStatement);
       
  1605 	if (err != KErrNone && err != KErrAlreadyExists)
       
  1606 	{
       
  1607 		User::Leave(err);
       
  1608 	}
       
  1609 
       
  1610 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1611 		(_L("EapTlsPeapUtils::OpenFastDatabaseL Created Specific settings table\n")));
       
  1612 	
       
  1613 	// Table 3: Create table for _allowed_ user certificates
       
  1614 	
       
  1615 //// NAME ////////////////// TYPE ////////////// Constant ///////////
       
  1616 //| ServiceType		  	| UNSIGNED INTEGER | KServiceType        |//
       
  1617 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
  1618 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
  1619 //| CertLabel			| VARCHAR(255)     | KCACertLabel        |//	
       
  1620 //| SubjectKeyId		| BINARY(20)	   | KSubjectKeyIdentifier |// This is Symbian subjectkey id
       
  1621 //| ActualSubjectKeyId  | BINARY(20)	   | KActualSubjectKeyIdentifier |// This is the actual subjectkeyid present in the certificate.
       
  1622 //| SubjectName			| VARCHAR(255)     | KSubjectName        |//	
       
  1623 //| IssuerName			| VARCHAR(255)     | KIssuerName        |//	
       
  1624 //| SerialNumber		| VARCHAR(255)     | KSerialNumber        |//	
       
  1625 //| Thumbprint			| BINARY(64)	   | KThumbprint        |//	
       
  1626 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
  1627 	
       
  1628 	_LIT(KSQLCreateTable3, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
  1629 											 %S UNSIGNED INTEGER, \
       
  1630 											 %S UNSIGNED INTEGER, \
       
  1631 											 %S VARCHAR(%d), \
       
  1632 											 %S BINARY(%d), \
       
  1633 											 %S BINARY(%d), \
       
  1634 											 %S VARCHAR(%d), \
       
  1635 											 %S VARCHAR(%d), \
       
  1636 											 %S VARCHAR(%d), \
       
  1637 											 %S BINARY(%d))");											 
       
  1638 											 
       
  1639 	sqlStatement.Format(KSQLCreateTable3, &KFastAllowedUserCertsDatabaseTableName, 
       
  1640 		&KServiceType, 
       
  1641 		&KServiceIndex, 
       
  1642 		&KTunnelingType, 
       
  1643 		&KCertLabel, KMaxCertLabelLengthInDB,
       
  1644 		&KSubjectKeyIdentifier, KMaxSubjectKeyIdLengthInDB,
       
  1645 		&KActualSubjectKeyIdentifier, KKeyIdentifierLength,
       
  1646 		&KSubjectName, KGeneralStringMaxLength,
       
  1647 		&KIssuerName, KGeneralStringMaxLength,
       
  1648 		&KSerialNumber, KGeneralStringMaxLength,
       
  1649 		&KThumbprint, KThumbprintMaxLength);
       
  1650 
       
  1651 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1652 		(_L("EapTlsPeapUtils::OpenFastDatabaseL - SQL query formated OK\n")));
       
  1653 	
       
  1654 	err = aDatabase.Execute(sqlStatement);
       
  1655 	if (err != KErrNone && err != KErrAlreadyExists)
       
  1656 	{
       
  1657 		User::Leave(err);
       
  1658 	}	
       
  1659 
       
  1660 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1661 		(_L("EapTlsPeapUtils::OpenFastDatabaseL Created User certificates table\n")));
       
  1662 	
       
  1663 	// Table 4: Create table for _allowed_ CA certs
       
  1664 
       
  1665 //// NAME ////////////////// TYPE ////////////// Constant ///////////
       
  1666 //| ServiceType			| UNSIGNED INTEGER | KServiceType        |//
       
  1667 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
  1668 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
  1669 //| CACertLabel			| VARCHAR(255)     | KCACertLabel        |//	
       
  1670 //| SubjectKeyId		| BINARY(20)	   | KSubjectKeyIdentifier |// This is Symbian subjectkey id
       
  1671 //| ActualSubjectKeyId  | BINARY(20)	   | KActualSubjectKeyIdentifier |// This is the actual subjectkeyid present in the certificate.
       
  1672 //| SubjectName			| VARCHAR(255)     | KSubjectName        |//	
       
  1673 //| IssuerName			| VARCHAR(255)     | KIssuerName        |//	
       
  1674 //| SerialNumber		| VARCHAR(255)     | KSerialNumber        |//	
       
  1675 //| Thumbprint			| BINARY(64)	   | KThumbprint        |//	
       
  1676 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
  1677 
       
  1678 	_LIT(KSQLCreateTable4, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
  1679 											 %S UNSIGNED INTEGER, \
       
  1680 											 %S UNSIGNED INTEGER, \
       
  1681 											 %S VARCHAR(%d), \
       
  1682 											 %S BINARY(%d), \
       
  1683 											 %S BINARY(%d), \
       
  1684 											 %S VARCHAR(%d), \
       
  1685 											 %S VARCHAR(%d), \
       
  1686 											 %S VARCHAR(%d), \
       
  1687 											 %S BINARY(%d))");
       
  1688 											 
       
  1689 	sqlStatement.Format(KSQLCreateTable4, &KFastAllowedCACertsDatabaseTableName, 
       
  1690 		&KServiceType, 
       
  1691 		&KServiceIndex, 
       
  1692 		&KTunnelingType, 
       
  1693 		&KCertLabel, KMaxCertLabelLengthInDB,
       
  1694 		&KSubjectKeyIdentifier, KMaxSubjectKeyIdLengthInDB,
       
  1695 		&KActualSubjectKeyIdentifier, KKeyIdentifierLength,
       
  1696 		&KSubjectName, KGeneralStringMaxLength,
       
  1697 		&KIssuerName, KGeneralStringMaxLength,
       
  1698 		&KSerialNumber, KGeneralStringMaxLength,
       
  1699 		&KThumbprint, KThumbprintMaxLength);
       
  1700 
       
  1701 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1702 		(_L("EapTlsPeapUtils::OpenFastDatabaseL - SQL query formated OK\n")));
       
  1703 		
       
  1704 	err = aDatabase.Execute(sqlStatement);
       
  1705 	if (err != KErrNone && err != KErrAlreadyExists)
       
  1706 	{
       
  1707 		User::Leave(err);
       
  1708 	}
       
  1709 
       
  1710 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1711 		(_L("EapTlsPeapUtils::OpenFastDatabaseL Created CA certificates table\n")));
       
  1712 	
       
  1713 	// Table 5: Create table for _allowed_ cipher suites
       
  1714 
       
  1715 //// NAME ///////////////// TYPE ////////////// Constant ///////////
       
  1716 //| ServiceType			| UNSIGNED INTEGER | KServiceType        |//
       
  1717 //| ServiceIndex		| UNSIGNED INTEGER | KServiceIndex       |//
       
  1718 //| TunnelingType		| UNSIGNED INTEGER | KTunnelingType		|//
       
  1719 //| CipherSuite			| UNSIGNED INTEGER | KCipherSuite        |//	
       
  1720 //////////////////////////////////////////////////////////////////////////////////////////////////////	
       
  1721 	
       
  1722 	_LIT(KSQLCreateTable5, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
       
  1723 											 %S UNSIGNED INTEGER, \
       
  1724 											 %S UNSIGNED INTEGER, \
       
  1725 											 %S UNSIGNED INTEGER)");
       
  1726 
       
  1727 	sqlStatement.Format(KSQLCreateTable5, &KFastAllowedCipherSuitesDatabaseTableName, 
       
  1728 		&KServiceType, &KServiceIndex, &KTunnelingType, &KCipherSuite);
       
  1729 	err = aDatabase.Execute(sqlStatement);
       
  1730 	if (err != KErrNone && err != KErrAlreadyExists)
       
  1731 	{
       
  1732 		User::Leave(err);
       
  1733 	}
       
  1734 
       
  1735 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1736 		(_L("EapTlsPeapUtils::OpenFastDatabaseL Created Cipher suites table\n")));
       
  1737 	
       
  1738 	// 4. Check if database table contains a row for this service type and id  	
       
  1739 	
       
  1740 	_LIT(KSQLQueryRow, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  1741 
       
  1742 	sqlStatement.Format(KSQLQueryRow, &KFastGeneralSettingsDBTableName, 
       
  1743 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);	
       
  1744 			
       
  1745 	RDbView view;
       
  1746 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  1747 	// View must be closed when no longer needed
       
  1748 	CleanupClosePushL(view);
       
  1749 	User::LeaveIfError(view.EvaluateAll());
       
  1750 	
       
  1751 	// 5. If a row is not found then add it
       
  1752 	
       
  1753 	TInt rows = view.CountL();
       
  1754 	CleanupStack::PopAndDestroy(); // view
       
  1755 	if (rows == 0)
       
  1756 	{
       
  1757 		// This is to add default values to the General settings table.
       
  1758 		_LIT(KSQLInsert, "SELECT * FROM %S");
       
  1759 		sqlStatement.Format(KSQLInsert, &KFastGeneralSettingsDBTableName);	
       
  1760 
       
  1761 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly));
       
  1762 		CleanupClosePushL(view);
       
  1763 		view.InsertL();
       
  1764 
       
  1765 		// Get column set so we get the correct column numbers
       
  1766 		CDbColSet* colSet = view.ColSetL();
       
  1767 		CleanupStack::PushL(colSet);
       
  1768 
       
  1769 		// Set the default values. The other three tables (certs, ca certs & cipher suites) are empty by default.
       
  1770 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
       
  1771 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);		
       
  1772 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
       
  1773 		
       
  1774 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_realm_literal), default_EAP_TLS_PEAP_use_manual_realm);
       
  1775 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_realm_literal), default_EAP_TLS_PEAP_manual_realm);
       
  1776 		
       
  1777 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_username_literal), default_EAP_TLS_PEAP_use_manual_username);
       
  1778 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_username_literal), default_EAP_TLS_PEAP_manual_username);
       
  1779 		
       
  1780 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_cipher_suite_literal), default_EAP_TLS_PEAP_cipher_suite);
       
  1781 
       
  1782 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_used_PEAP_version_literal), default_EAP_TLS_PEAP_used_PEAP_version);
       
  1783 
       
  1784 		TInt i(0);
       
  1785 
       
  1786 		while (default_EAP_TLS_PEAP_accepted_PEAP_versions[i] != -1)
       
  1787 		{
       
  1788 			i++;
       
  1789 		}
       
  1790 		
       
  1791 		TBuf8<KMaxPEAPVersionsStringLengthInDB> tmp;
       
  1792 		
       
  1793 		tmp.Copy(reinterpret_cast<const TUint8 *> (default_EAP_TLS_PEAP_accepted_PEAP_versions), i * sizeof(TInt));
       
  1794 		
       
  1795 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal), tmp);
       
  1796 
       
  1797 		view.SetColL(colSet->ColNo(cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal), default_PEAP_tunneled_types);
       
  1798 		view.SetColL(colSet->ColNo(cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal), default_PEAP_tunneled_types);		
       
  1799 		
       
  1800 		view.SetColL(colSet->ColNo(cf_str_TLS_server_authenticates_client_policy_in_client_literal), default_EAP_PEAP_TTLS_server_authenticates_client);
       
  1801 
       
  1802 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal), default_EAP_TLS_PEAP_verify_certificate_realm);
       
  1803 		
       
  1804 		view.SetColL(colSet->ColNo(cf_str_EAP_FAST_max_session_validity_time_literal), default_MaxSessionTime);
       
  1805 		
       
  1806 		view.SetColL(colSet->ColNo(KFASTLastFullAuthTime), default_FullAuthTime);
       
  1807 		
       
  1808 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_identity_privacy_literal), default_EAP_TLS_PEAP_TLS_Privacy);		
       
  1809 
       
  1810 		view.PutL();
       
  1811 		
       
  1812 		CleanupStack::PopAndDestroy(colSet); 
       
  1813 		CleanupStack::PopAndDestroy( &view ); // Close view.
       
  1814 
       
  1815 		//--------------------------------------------------------//
       
  1816 		
       
  1817 		// This is to add default values to the Specific settings table.
       
  1818 		// KSQLInsert is "SELECT * FROM %S"
       
  1819 		sqlStatement.Format(KSQLInsert, &KFastSpecialSettingsDBTableName);	
       
  1820 
       
  1821 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly));
       
  1822 		CleanupClosePushL(view);
       
  1823 		view.InsertL();
       
  1824 
       
  1825 		// Get column set so we get the correct column numbers
       
  1826 		colSet = view.ColSetL();
       
  1827 		CleanupStack::PushL(colSet);
       
  1828 
       
  1829 		// Set the default values.
       
  1830 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
       
  1831 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);		
       
  1832 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
       
  1833 
       
  1834 		view.SetColL(colSet->ColNo(cf_str_EAP_FAST_allow_server_authenticated_provisioning_mode_literal),
       
  1835 				default_EAP_FAST_Auth_Prov_Mode_Allowed);		
       
  1836 	 	view.SetColL(colSet->ColNo(cf_str_EAP_FAST_allow_server_unauthenticated_provisioning_mode_ADHP_literal),
       
  1837 	 			default_EAP_FAST_Unauth_Prov_Mode_Allowed);
       
  1838 	 	
       
  1839         view.SetColL(colSet->ColNo(KFASTWarnADHPNoPAC),
       
  1840                 default_EAP_FAST_Warn_ADHP_No_PAC);
       
  1841 
       
  1842         view.SetColL(colSet->ColNo(KFASTWarnADHPNoMatchingPAC),
       
  1843                 default_EAP_FAST_Warn_ADHP_No_Matching_PAC);
       
  1844 
       
  1845         view.SetColL(colSet->ColNo(KFASTWarnNotDefaultServer),
       
  1846                 default_EAP_FAST_Warn_Not_Default_Server);
       
  1847 
       
  1848 	 	
       
  1849 							
       
  1850 		view.PutL();
       
  1851 		
       
  1852 		CleanupStack::PopAndDestroy(colSet); 
       
  1853 		CleanupStack::PopAndDestroy( &view ); // Close view.		
       
  1854 		
       
  1855 		//--------------------------------------------------------//
       
  1856 		
       
  1857 		// Add default disabled cipher suites to cipher suites table.
       
  1858 		_LIT(KSQLInsert2, "SELECT * FROM %S");
       
  1859 		sqlStatement.Format(KSQLInsert2, &KFastAllowedCipherSuitesDatabaseTableName);
       
  1860 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly));
       
  1861 		CleanupClosePushL(view);
       
  1862 
       
  1863 		// Get column set so we get the correct column numbers
       
  1864 		colSet = view.ColSetL();
       
  1865 		CleanupStack::PushL(colSet);
       
  1866 
       
  1867 		i = 0;
       
  1868 		while (default_allowed_cipher_suites[i] != 0)
       
  1869 		{
       
  1870 			view.InsertL();
       
  1871 			view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
       
  1872 			view.SetColL(colSet->ColNo(KServiceIndex), aIndex);		
       
  1873 			view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);			
       
  1874 			view.SetColL(colSet->ColNo(KCipherSuite), default_allowed_cipher_suites[i]);
       
  1875 			view.PutL();
       
  1876 			i++;
       
  1877 		}
       
  1878 		
       
  1879 		CleanupStack::PopAndDestroy( colSet ); // Delete colSet.		
       
  1880 		CleanupStack::PopAndDestroy( &view ); // Close view.
       
  1881 	}
       
  1882 	
       
  1883 	CleanupStack::PopAndDestroy( buf ); // Delete buf or sqlStatement
       
  1884 	CleanupStack::Pop( &aDatabase );	
       
  1885 	CleanupStack::Pop( &aSession );
       
  1886 	
       
  1887 	aDatabase.Compact();
       
  1888 	
       
  1889     } // EapTlsPeapUtils::OpenFastDatabaseL()
       
  1890 
       
  1891 #endif // #if defined(USE_FAST_EAP_TYPE)
       
  1892 
       
  1893 void EapTlsPeapUtils::SetIndexL(
       
  1894 	RDbNamedDatabase& aDatabase,
       
  1895 	const TDesC& aTableName,
       
  1896 	const TIndexType aIndexType,
       
  1897 	const TInt aIndex,
       
  1898 	const eap_type_value_e aTunnelingType,
       
  1899 	const TIndexType aNewIndexType,
       
  1900 	const TInt aNewIndex,
       
  1901 	const eap_type_value_e aNewTunnelingType)
       
  1902 {
       
  1903 #ifdef USE_EAP_EXPANDED_TYPES
       
  1904 
       
  1905 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  1906 	TUint aNewTunnelingVendorType = aNewTunnelingType.get_vendor_type();
       
  1907 
       
  1908 #else
       
  1909 
       
  1910 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  1911 	TUint aNewTunnelingVendorType = static_cast<TUint>(aNewTunnelingType);
       
  1912 
       
  1913 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  1914 
       
  1915 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1916 		(_L("EapTlsPeapUtils::SetIndexL -Start- aIndexType=%d, aIndex=%d, Tunneling vendor type=%d \n"),
       
  1917 		aIndexType, aIndex, aTunnelingVendorType));
       
  1918 	
       
  1919 	EAP_TRACE_DEBUG_SYMBIAN(
       
  1920 		(_L("EapTlsPeapUtils::SetIndexL -Start- aNewIndexType=%d, aNewIndex=%d, New Tunneling vendor type=%d \n"),
       
  1921 		aNewIndexType, aNewIndex, aNewTunnelingVendorType));
       
  1922 
       
  1923 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  1924 	TPtr sqlStatement = buf->Des();
       
  1925 
       
  1926 	// First delete the target
       
  1927 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  1928 
       
  1929 	sqlStatement.Format(KSQL, &aTableName, 
       
  1930 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);		
       
  1931 
       
  1932 	RDbView view;
       
  1933 	
       
  1934 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  1935 	
       
  1936 	// View must be closed when no longer needed
       
  1937 	CleanupClosePushL(view);
       
  1938 	
       
  1939 	User::LeaveIfError(view.EvaluateAll());
       
  1940 
       
  1941 	// Get column set so we get the correct column numbers
       
  1942 	CDbColSet* colSet = view.ColSetL();
       
  1943 	CleanupStack::PushL(colSet);
       
  1944 
       
  1945 	if (view.FirstL())
       
  1946 	{		
       
  1947 		do {
       
  1948 			view.GetL();
       
  1949 			{
       
  1950 				view.UpdateL();
       
  1951 				
       
  1952 			    view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aNewIndexType));
       
  1953     
       
  1954     			view.SetColL(colSet->ColNo(KServiceIndex), static_cast<TUint>(aNewIndex));
       
  1955 
       
  1956     			view.SetColL(colSet->ColNo(KTunnelingType), aNewTunnelingVendorType);
       
  1957 				
       
  1958 				view.PutL();
       
  1959 			}
       
  1960 		} while (view.NextL() != EFalse);
       
  1961 	}
       
  1962 			
       
  1963     CleanupStack::PopAndDestroy(3); // view, colset
       
  1964 }
       
  1965 
       
  1966 void EapTlsPeapUtils::ReadCertRowsToArrayL(
       
  1967 	RDbNamedDatabase& aDatabase,
       
  1968 	eap_am_tools_symbian_c * const /*aTools*/,
       
  1969 	const TDesC& aTableName, 
       
  1970 	const TIndexType aIndexType,
       
  1971 	const TInt aIndex,
       
  1972 	const eap_type_value_e aTunnelingType,
       
  1973 	RArray<SCertEntry>& aArray)
       
  1974 {
       
  1975 #ifdef USE_EAP_EXPANDED_TYPES
       
  1976 
       
  1977 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  1978 
       
  1979 #else
       
  1980 
       
  1981 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  1982 
       
  1983 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  1984 
       
  1985 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::ReadCertRowsToArrayL -Start")) );
       
  1986 
       
  1987 	HBufC* buf = HBufC::NewLC(512);
       
  1988 	TPtr sqlStatement = buf->Des();
       
  1989 	
       
  1990 	_LIT(KSQLQueryRow, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  1991 	
       
  1992 	sqlStatement.Format(KSQLQueryRow, &aTableName, &KServiceType, 
       
  1993 		aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  1994 	
       
  1995 	RDbView view;
       
  1996 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  1997 	CleanupClosePushL(view);
       
  1998 	User::LeaveIfError(view.EvaluateAll());	
       
  1999 
       
  2000 	// Get column set so we get the correct column numbers
       
  2001 	CDbColSet* colSet = view.ColSetL();
       
  2002 	CleanupStack::PushL(colSet);
       
  2003 
       
  2004 	if (view.FirstL())
       
  2005 	{
       
  2006 		do {
       
  2007 
       
  2008 			view.GetL();
       
  2009 			
       
  2010 			{
       
  2011 				SCertEntry certInfo;
       
  2012 				// Store the line
       
  2013 				TPtrC ptr = view.ColDes(colSet->ColNo(KCertLabel));
       
  2014 	
       
  2015 				certInfo.iLabel.Copy(ptr);
       
  2016 				
       
  2017 				TPtrC8 ptr2 = view.ColDes8(colSet->ColNo(KSubjectKeyIdentifier)); // This is for authentication and uses Symbian subjectkey id.
       
  2018 				certInfo.iSubjectKeyId.Copy(ptr2);
       
  2019 
       
  2020 				aArray.Append(certInfo);
       
  2021 				
       
  2022 				EAP_TRACE_DEBUG_SYMBIAN((_L("ReadCertRowsToArrayL - Appended Cert with label=%S\n"),
       
  2023 				&(certInfo.iLabel)));
       
  2024 				
       
  2025 				EAP_TRACE_DATA_DEBUG_SYMBIAN(("ReadCertRowsToArrayL - Appended Cert's SubjectKeyID:",
       
  2026 					certInfo.iSubjectKeyId.Ptr(), certInfo.iSubjectKeyId.Size()));
       
  2027 			}	
       
  2028 
       
  2029 		} while (view.NextL() != EFalse);		
       
  2030 	}
       
  2031 
       
  2032 	// Close database
       
  2033 	CleanupStack::PopAndDestroy(colSet); 
       
  2034 	CleanupStack::PopAndDestroy(2); // view, buf
       
  2035 }
       
  2036 
       
  2037 void EapTlsPeapUtils::ReadUintRowsToArrayL(
       
  2038 	RDbNamedDatabase& aDatabase,
       
  2039 	eap_am_tools_symbian_c * const /*aTools*/,
       
  2040 	const TDesC& aTableName, 
       
  2041 	const TDesC& aColumnName,	
       
  2042 	const TIndexType aIndexType,
       
  2043 	const TInt aIndex,
       
  2044 	const eap_type_value_e aTunnelingType,
       
  2045 	RArray<TUint>& aArray)
       
  2046 {
       
  2047 #ifdef USE_EAP_EXPANDED_TYPES
       
  2048 
       
  2049 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  2050 
       
  2051 #else
       
  2052 
       
  2053 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  2054 
       
  2055 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  2056 	
       
  2057 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::ReadUintRowsToArrayL -Start")) );
       
  2058 
       
  2059 	HBufC* buf = HBufC::NewLC(512);
       
  2060 	TPtr sqlStatement = buf->Des();
       
  2061 	
       
  2062 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  2063 	
       
  2064 	sqlStatement.Format(KSQLQueryRow, &aColumnName, &aTableName, 
       
  2065 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  2066 	
       
  2067 	RDbView view;
       
  2068 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  2069 	CleanupClosePushL(view);
       
  2070 	User::LeaveIfError(view.EvaluateAll());	
       
  2071 	
       
  2072 	if (view.FirstL())
       
  2073 	{		
       
  2074 		do {
       
  2075 			view.GetL();
       
  2076 
       
  2077 			switch (view.ColType(KDefaultColumnInView_One))
       
  2078 			{
       
  2079 			case EDbColUint32:
       
  2080 				{
       
  2081 					// Store the line
       
  2082 					TUint tmp = view.ColUint(KDefaultColumnInView_One);				
       
  2083 					aArray.Append(tmp);
       
  2084 				}
       
  2085 				break;
       
  2086 			default:
       
  2087 				User::Leave(KErrArgument);
       
  2088 			}		
       
  2089 
       
  2090 		} while (view.NextL() != EFalse);
       
  2091 	}
       
  2092 
       
  2093 	// Close database
       
  2094 	CleanupStack::PopAndDestroy(2); // view, buf
       
  2095 }
       
  2096 
       
  2097 // Don't use this finction as Label is not saved for certificates saved by SetConfigurationL().
       
  2098 // Provisioning (OMA DM etc) use SetConfigurationL() to save certificate details.
       
  2099 
       
  2100 TBool EapTlsPeapUtils::CompareTCertLabels(const TCertLabel& item1, const TCertLabel& item2)
       
  2101 {
       
  2102 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::CompareTCertLabels-Start")) );
       
  2103 
       
  2104 	if (item1 == item2)
       
  2105 	{
       
  2106 		return ETrue;
       
  2107 	} 
       
  2108 	else
       
  2109 	{
       
  2110 		return EFalse;
       
  2111 	}
       
  2112 }
       
  2113 
       
  2114 TBool EapTlsPeapUtils::CompareSCertEntries(const SCertEntry& item1, const SCertEntry& item2)
       
  2115 {
       
  2116 	EAP_TRACE_DEBUG_SYMBIAN((_L("\nEapTlsPeapUtils::CompareSCertEntries, Label_1=%S, Label_2=%S"),
       
  2117 	&(item1.iLabel), &(item2.iLabel)));
       
  2118 
       
  2119 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::CompareSCertEntries, SubjectKeyID_1:",
       
  2120 		item1.iSubjectKeyId.Ptr(), item1.iSubjectKeyId.Size()));
       
  2121 
       
  2122 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::CompareSCertEntries, SubjectKeyID_2:",
       
  2123 		item2.iSubjectKeyId.Ptr(), item2.iSubjectKeyId.Size()));
       
  2124 
       
  2125 	if (item1.iLabel == item2.iLabel ||
       
  2126 		item1.iLabel.Length() == 0 ||
       
  2127 		item2.iLabel.Length() == 0 ) // Label is not saved when certs are saved using OMA DM.
       
  2128 	{
       
  2129 		if (item1.iSubjectKeyId == item2.iSubjectKeyId)
       
  2130 		{
       
  2131 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::CompareSCertEntries, Certs matched\n")));
       
  2132 		
       
  2133 			return ETrue;
       
  2134 		}
       
  2135 	}
       
  2136 	
       
  2137 	return EFalse;
       
  2138 }
       
  2139 
       
  2140 
       
  2141 #ifndef USE_EAP_EXPANDED_TYPES 
       
  2142 // There are separate functions (SetTunnelingExpandedEapDataL and GetTunnelingExpandedEapDataL) if USE_EAP_EXPANDED_TYPES is defined.
       
  2143 
       
  2144 /**
       
  2145 * Sets EAP data to a binary string record in commsdat.
       
  2146 * The old format (NOT USED NOW) is "+123,- 34", + means enabled, - disabled, then id, id is always 3 characters for easy parsing.
       
  2147 * In the new format each EAP type is saved as an unsigned integer of 32 bits ( TUint).
       
  2148 * There is separate binary strings for accepted (enabled) and unaccepted (disabled) tunneled EAP types.
       
  2149 */
       
  2150  
       
  2151 void EapTlsPeapUtils::SetEapDataL(
       
  2152 	RDbNamedDatabase& aDatabase,
       
  2153 	eap_am_tools_symbian_c * const /*aTools*/,
       
  2154 	TEapArray &aEaps,
       
  2155 	const TIndexType aIndexType,
       
  2156 	const TInt aIndex,
       
  2157 	const eap_type_value_e aTunnelingType,
       
  2158 	const eap_type_value_e aEapType)
       
  2159 {
       
  2160 #ifdef USE_EAP_EXPANDED_TYPES
       
  2161 
       
  2162 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  2163 	TUint aEapVendorType = aEapType.get_vendor_type();
       
  2164 
       
  2165 #else
       
  2166 
       
  2167 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  2168 	TUint aEapVendorType = static_cast<TUint>(aEapType);
       
  2169 
       
  2170 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  2171 
       
  2172 	EAP_TRACE_DEBUG_SYMBIAN(
       
  2173 		(_L("EapTlsPeapUtils::SetEapDataL aIndexType=%d, aIndex=%d, Tunneling vendor type=%d, Eap vendor type=%d, No: of tunneled EAP types=%d \n"),
       
  2174 		aIndexType,aIndex, aTunnelingVendorType, aEapVendorType, aEaps.Count()) );
       
  2175 
       
  2176 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  2177 	TPtr sqlStatement = buf->Des();
       
  2178 	
       
  2179 	_LIT(KSQLQueryRow, "SELECT %S, %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  2180 	
       
  2181 	if (aEapType == eap_type_peap)
       
  2182 	{
       
  2183 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal,
       
  2184 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2185 			&KPeapDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2186 			&KTunnelingType, aTunnelingVendorType);		
       
  2187 	} 
       
  2188 #if defined(USE_TTLS_EAP_TYPE)
       
  2189 	else if (aEapType == eap_type_ttls)
       
  2190 	{
       
  2191 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2192 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2193 			&KTtlsDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2194 			&KTunnelingType, aTunnelingVendorType);		
       
  2195 	} 
       
  2196 #endif
       
  2197 
       
  2198 	else if (aEapType == eap_type_ttls_plain_pap)
       
  2199 	{
       
  2200 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2201 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2202 			&KTtlsDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2203 			&KTunnelingType, aTunnelingVendorType);		
       
  2204 	} 
       
  2205 
       
  2206 #if defined(USE_FAST_EAP_TYPE)
       
  2207 	else if (aEapType == eap_type_fast)
       
  2208 	{
       
  2209 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2210 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2211 			&KFastGeneralSettingsDBTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2212 			&KTunnelingType, aTunnelingVendorType);		
       
  2213 	} 
       
  2214 #endif
       
  2215 	else
       
  2216 	{
       
  2217 		EAP_TRACE_DEBUG_SYMBIAN(
       
  2218 			(_L("EapTlsPeapUtils::SetEapDataL - Unsupported EAP type =%d \n"),
       
  2219 			 aEapVendorType));
       
  2220 			 
       
  2221 		// Unsupported EAP type
       
  2222 		User::Leave(KErrNotSupported);
       
  2223 	}	
       
  2224 			
       
  2225 	RDbView view;
       
  2226 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  2227 	CleanupClosePushL(view);
       
  2228 	User::LeaveIfError(view.EvaluateAll());	
       
  2229 	User::LeaveIfError(view.FirstL());	
       
  2230 	view.UpdateL();
       
  2231 
       
  2232 	TInt eapCount = aEaps.Count();
       
  2233 	
       
  2234 	HBufC8 *acceptedDbText = HBufC8::NewLC( (sizeof(TUint)) * eapCount ); // 4 bytes (32 bits) for an EAP type, Need to save as TUInt (4 bytes).
       
  2235 	HBufC8 *unacceptedDbText = HBufC8::NewLC( (sizeof(TUint)) * eapCount ); // 4 bytes (32 bits) for an EAP type, Need to save as TUInt (4 bytes).
       
  2236 	
       
  2237 	TPtr8 acceptedPtr(acceptedDbText->Des());
       
  2238 	TPtr8 unacceptedPtr(unacceptedDbText->Des());
       
  2239 	
       
  2240 	TBuf8<3> UidTmp;
       
  2241 		
       
  2242 	for(TInt i = 0 ; i< eapCount; i++)
       
  2243 	{
       
  2244 		UidTmp.Copy(aEaps[i]->UID);
       
  2245 		
       
  2246 		TLex8 eapUidLex( UidTmp.Right(2) ); // Only last two characters determines the EAP type.
       
  2247 		TUint eapTypeUint = 0;
       
  2248 		
       
  2249 		User::LeaveIfError( eapUidLex.Val(eapTypeUint, EDecimal) );	
       
  2250 		
       
  2251 		TPtrC8 tempEAPtype( reinterpret_cast<TUint8*>(&eapTypeUint), sizeof(TUint) );
       
  2252 		
       
  2253 		if( aEaps[i]->Enabled )
       
  2254 		{
       
  2255 			// Fill in accepted tunneled type.
       
  2256 			acceptedPtr.Append( tempEAPtype );			
       
  2257 		}
       
  2258 		else
       
  2259 		{
       
  2260 			// Fill in unaccepted tunneled type.
       
  2261 			unacceptedPtr.Append( tempEAPtype);			
       
  2262 		}			
       
  2263 	}
       
  2264 	
       
  2265 	// Save the strings in the DB.
       
  2266 	
       
  2267 	// Get column set so we get the correct column numbers
       
  2268 	CDbColSet* colSet = view.ColSetL();
       
  2269 	CleanupStack::PushL(colSet);			
       
  2270 	
       
  2271 	// Validate length of strings
       
  2272 	if(acceptedPtr.Length() > KMaxTunneledTypeStringLengthInDB 
       
  2273 		|| unacceptedPtr.Length() > KMaxTunneledTypeStringLengthInDB)
       
  2274 	{
       
  2275 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetEapDataL - Too long Tunneled EAP type string \n") ) );
       
  2276 
       
  2277 		User::Leave(KErrArgument);		
       
  2278 	}
       
  2279 	
       
  2280 	view.SetColL(colSet->ColNo(cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal), acceptedPtr);
       
  2281 	view.SetColL(colSet->ColNo(cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal), unacceptedPtr);	
       
  2282 
       
  2283 	CleanupStack::PopAndDestroy( colSet ); // Delete colSet.	
       
  2284 
       
  2285 	view.PutL();
       
  2286 
       
  2287 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::SetEapDataL- Enabled extended EAP type data added to DB:",
       
  2288 		acceptedPtr.Ptr(), 
       
  2289 		acceptedPtr.Size() ) );
       
  2290 
       
  2291 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::SetEapDataL- Disabled extended EAP type data added to DB:",
       
  2292 		unacceptedPtr.Ptr(), 
       
  2293 		unacceptedPtr.Size() ) );
       
  2294 
       
  2295 	CleanupStack::PopAndDestroy(unacceptedDbText); // Delete unacceptedDbText
       
  2296 	CleanupStack::PopAndDestroy(acceptedDbText); // Delete acceptedDbText	
       
  2297 	CleanupStack::PopAndDestroy(&view); // Close view
       
  2298 	CleanupStack::PopAndDestroy(buf); // Delete buf
       
  2299 }
       
  2300 
       
  2301 /**
       
  2302 * Gets Eapdata from corresponding table in commdb
       
  2303 * see format in SetEapDAtaL
       
  2304 */
       
  2305 void EapTlsPeapUtils::GetEapDataL(
       
  2306 	RDbNamedDatabase& aDatabase,
       
  2307 	eap_am_tools_symbian_c * const /*aTools*/,
       
  2308 	TEapArray &aEaps, 
       
  2309 	const TIndexType aIndexType,
       
  2310 	const TInt aIndex,
       
  2311 	const eap_type_value_e aTunnelingType,
       
  2312 	const eap_type_value_e aEapType)
       
  2313 {
       
  2314 #ifdef USE_EAP_EXPANDED_TYPES
       
  2315 
       
  2316 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  2317 	TUint aEapVendorType = aEapType.get_vendor_type();
       
  2318 
       
  2319 #else
       
  2320 
       
  2321 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  2322 	TUint aEapVendorType = static_cast<TUint>(aEapType);
       
  2323 
       
  2324 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  2325 	
       
  2326 	EAP_TRACE_DEBUG_SYMBIAN(
       
  2327 		(_L("EapTlsPeapUtils::GetEapDataL aIndexType=%d, aIndex=%d, Tunneling vendor type=%d, Eap vendor type=%d \n"),
       
  2328 		aIndexType,aIndex, aTunnelingVendorType, aEapVendorType));
       
  2329 
       
  2330 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  2331 	TPtr sqlStatement = buf->Des();
       
  2332 	
       
  2333 	_LIT(KSQLQueryRow, "SELECT %S, %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  2334 
       
  2335 	if (aEapType == eap_type_peap)
       
  2336 	{
       
  2337 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2338 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2339 			&KPeapDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2340 			&KTunnelingType, aTunnelingVendorType);		
       
  2341 	} 
       
  2342 #if defined(USE_TTLS_EAP_TYPE)
       
  2343 	else if (aEapType == eap_type_ttls)
       
  2344 	{
       
  2345 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2346 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2347 			&KTtlsDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2348 			&KTunnelingType, aTunnelingVendorType);		
       
  2349 	} 
       
  2350 #endif
       
  2351 
       
  2352 	else if (aEapType == eap_type_ttls_plain_pap)
       
  2353 	{
       
  2354 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2355 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2356 			&KTtlsDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2357 			&KTunnelingType, aTunnelingVendorType);		
       
  2358 	} 
       
  2359 	
       
  2360 #if defined(USE_FAST_EAP_TYPE)
       
  2361 	else if (aEapType == eap_type_fast)
       
  2362 	{
       
  2363 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2364 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2365 			&KFastGeneralSettingsDBTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2366 			&KTunnelingType, aTunnelingVendorType);		
       
  2367 	} 
       
  2368 #endif
       
  2369 	else
       
  2370 	{
       
  2371 		EAP_TRACE_DEBUG_SYMBIAN(
       
  2372 			(_L("EapTlsPeapUtils::GetEapDataL - Unsupported EAP type=%d \n"),
       
  2373 			 aEapVendorType));
       
  2374 			 
       
  2375 		// Unsupported EAP type
       
  2376 		User::Leave(KErrNotSupported);
       
  2377 	}	
       
  2378 	
       
  2379 	RDbView view;
       
  2380 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  2381 	CleanupClosePushL(view);
       
  2382 	User::LeaveIfError(view.EvaluateAll());	
       
  2383 	
       
  2384 	User::LeaveIfError(view.FirstL());
       
  2385 	
       
  2386 	view.GetL();
       
  2387 	
       
  2388 	// Get column set so we get the correct column numbers
       
  2389 	CDbColSet* colSet = view.ColSetL();
       
  2390 	CleanupStack::PushL(colSet);			
       
  2391 	
       
  2392 	TPtrC8 acceptedEAPData = view.ColDes8(colSet->ColNo(cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal));
       
  2393 	TPtrC8 unacceptedEAPData = view.ColDes8(colSet->ColNo(cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal));
       
  2394 	
       
  2395 	CleanupStack::PopAndDestroy( colSet ); // Delete colSet.	
       
  2396 
       
  2397 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::GetEapDataL- Enabled extended EAP type data from DB:",
       
  2398 		acceptedEAPData.Ptr(), 
       
  2399 		acceptedEAPData.Size() ) );
       
  2400 	
       
  2401 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::GetEapDataL- Disabled extended EAP type data from DB:",
       
  2402 		unacceptedEAPData.Ptr(), 
       
  2403 		unacceptedEAPData.Size() ) );
       
  2404 	
       
  2405 	aEaps.ResetAndDestroy();
       
  2406 		
       
  2407 	TUint acceptedLength = acceptedEAPData.Length();
       
  2408 	TUint unacceptedLength = unacceptedEAPData.Length();
       
  2409 	
       
  2410 	TEap *eapTmp;
       
  2411 
       
  2412 	TUint index = 0;
       
  2413 	
       
  2414 	_LIT8(KUIDFormat,"%u");
       
  2415 	
       
  2416 	// For accepted or enabled tunneled EAP types. 	
       
  2417 	while(index < acceptedLength)
       
  2418 	{		
       
  2419 		eapTmp = new (ELeave)TEap;
       
  2420 
       
  2421 		eapTmp->Enabled=ETrue; // All EAP types in here are enabled.
       
  2422 		
       
  2423 		eapTmp->UID.Zero();
       
  2424 
       
  2425 		// Get the UID from data from the DB.				
       
  2426 		TPtrC8 tempEAPtype( acceptedEAPData.Mid(index, sizeof(TUint)) );
       
  2427 		
       
  2428 		EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::GetEapDataL- extracted EAP type:",
       
  2429 			tempEAPtype.Ptr(), 
       
  2430 			tempEAPtype.Size() ) );
       
  2431 						
       
  2432 		TUint eapTypeUint = *(tempEAPtype.Ptr()); // All EAP types are saved as TUInt. 
       
  2433 		
       
  2434 		eapTmp->UID.Format(KUIDFormat,eapTypeUint);
       
  2435 				
       
  2436 		aEaps.Append(eapTmp);
       
  2437 
       
  2438 		index = index + sizeof(TUint);
       
  2439 		
       
  2440 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetEapDataL - Appended enabled-EAP type=%s \n"),eapTmp->UID.Ptr()) );
       
  2441 	}
       
  2442 	
       
  2443 	index = 0;
       
  2444 	
       
  2445 	// For unaccepted or disabled tunneled EAP types. 	
       
  2446 	while(index < unacceptedLength)
       
  2447 	{		
       
  2448 		eapTmp = new (ELeave)TEap;
       
  2449 
       
  2450 		eapTmp->Enabled=EFalse; // All EAP types in here are disabled.
       
  2451 		
       
  2452 		eapTmp->UID.Zero();
       
  2453 
       
  2454 		// Get the UID from data from the DB.				
       
  2455 		TPtrC8 tempEAPtype( unacceptedEAPData.Mid(index, sizeof(TUint)) );
       
  2456 		
       
  2457 		EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::GetEapDataL- extracted EAP type:",
       
  2458 			tempEAPtype.Ptr(), 
       
  2459 			tempEAPtype.Size() ) );
       
  2460 						
       
  2461 		TUint eapTypeUint = *(tempEAPtype.Ptr()); // All EAP types are saved as TUint. 
       
  2462 		
       
  2463 		eapTmp->UID.Format(KUIDFormat,eapTypeUint);
       
  2464 				
       
  2465 		aEaps.Append(eapTmp);
       
  2466 
       
  2467 		index = index + sizeof(TUint);
       
  2468 		
       
  2469 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetEapDataL - Appended disabled-EAP type=%s \n"),eapTmp->UID.Ptr()) );
       
  2470 	}
       
  2471 	
       
  2472 	CleanupStack::PopAndDestroy(&view); // Close view
       
  2473 	CleanupStack::PopAndDestroy(buf); // Delete buf	
       
  2474 }
       
  2475 
       
  2476 #endif // #ifndef USE_EAP_EXPANDED_TYPES
       
  2477 
       
  2478 //--------------------------------------------------
       
  2479 
       
  2480 #ifdef USE_EAP_EXPANDED_TYPES
       
  2481 
       
  2482 // Stores the tunneled EAP type (expanded) to the database.
       
  2483 void EapTlsPeapUtils::SetTunnelingExpandedEapDataL(
       
  2484 	RDbNamedDatabase& aDatabase,
       
  2485 	eap_am_tools_symbian_c * const /*aTools*/,
       
  2486 	RExpandedEapTypePtrArray &aEnabledEAPArrary,
       
  2487 	RExpandedEapTypePtrArray &aDisabledEAPArrary,
       
  2488 	const TIndexType aIndexType,
       
  2489 	const TInt aIndex,
       
  2490 	const eap_type_value_e aTunnelingType,
       
  2491 	const eap_type_value_e aEapType)
       
  2492 {
       
  2493 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  2494 	TUint aEapVendorType = aEapType.get_vendor_type();
       
  2495 
       
  2496 	EAP_TRACE_DEBUG_SYMBIAN(
       
  2497 		(_L("EapTlsPeapUtils::SetTunnelingExpandedEapDataL:aIndexType=%d, aIndex=%d, Tunneling vendor type=%d, Eap vendor type=%d\n"),
       
  2498 		aIndexType,aIndex, aTunnelingVendorType, aEapVendorType));
       
  2499 
       
  2500 	EAP_TRACE_DEBUG_SYMBIAN(
       
  2501 		(_L("Number of Tunneled EAP types: Enabled=%d, Disabled=%d\n"),
       
  2502 		aEnabledEAPArrary.Count(), aDisabledEAPArrary.Count()));
       
  2503 
       
  2504 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  2505 	TPtr sqlStatement = buf->Des();
       
  2506 	
       
  2507 	_LIT(KSQLQueryRow, "SELECT %S, %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  2508 	
       
  2509 	if (aEapType == eap_type_peap)
       
  2510 	{
       
  2511 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal,
       
  2512 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2513 			&KPeapDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2514 			&KTunnelingType, aTunnelingVendorType);		
       
  2515 	} 
       
  2516 #if defined(USE_TTLS_EAP_TYPE)
       
  2517 	else if (aEapType == eap_type_ttls)
       
  2518 	{
       
  2519 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2520 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2521 			&KTtlsDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2522 			&KTunnelingType, aTunnelingVendorType);		
       
  2523 	} 
       
  2524 #endif
       
  2525 #if defined(USE_FAST_EAP_TYPE)
       
  2526 	else if (aEapType == eap_type_fast)
       
  2527 	{
       
  2528 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2529 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2530 			&KFastGeneralSettingsDBTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2531 			&KTunnelingType, aTunnelingVendorType);		
       
  2532 	} 
       
  2533 #endif
       
  2534 
       
  2535 	else if ( aEapType == eap_type_ttls_plain_pap )
       
  2536 	{
       
  2537 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2538 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2539 			&KTtlsDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2540 			&KTunnelingType, aTunnelingVendorType);		
       
  2541 	} 
       
  2542 
       
  2543 	else
       
  2544 	{
       
  2545 		EAP_TRACE_DEBUG_SYMBIAN(
       
  2546 			(_L("EapTlsPeapUtils::SetTunnelingExpandedEapDataL - Unsupported EAP type =%d \n"),
       
  2547 			 aEapVendorType));
       
  2548 			 
       
  2549 		// Unsupported EAP type
       
  2550 		User::Leave(KErrNotSupported);
       
  2551 	}	
       
  2552 			
       
  2553 	RDbView view;
       
  2554 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  2555 	CleanupClosePushL(view);
       
  2556 	User::LeaveIfError(view.EvaluateAll());	
       
  2557 	User::LeaveIfError(view.FirstL());	
       
  2558 	view.UpdateL();
       
  2559 
       
  2560 	TInt enabledEAPCount = aEnabledEAPArrary.Count();
       
  2561 	TInt disabledEAPCount = aDisabledEAPArrary.Count();
       
  2562 	
       
  2563 	HBufC8 *acceptedDbText = HBufC8::NewLC( KExpandedEAPTypeSize * enabledEAPCount ); // 8 bytes (64 bits) for an EAP type.
       
  2564 	HBufC8 *unacceptedDbText = HBufC8::NewLC( KExpandedEAPTypeSize * disabledEAPCount ); // 8 bytes (64 bits) for an EAP type.
       
  2565 	
       
  2566 	TPtr8 acceptedPtr(acceptedDbText->Des());
       
  2567 	TPtr8 unacceptedPtr(unacceptedDbText->Des());
       
  2568 	
       
  2569 	// Fill in accepted tunneled type.		
       
  2570 	for(TInt i = 0 ; i< enabledEAPCount; i++)
       
  2571 	{
       
  2572 		acceptedPtr.Append(aEnabledEAPArrary[i]->iExpandedEAPType);					
       
  2573 	}
       
  2574 	
       
  2575 	// Fill in unaccepted tunneled type.		
       
  2576 	for(TInt i = 0 ; i< disabledEAPCount; i++)
       
  2577 	{
       
  2578 		unacceptedPtr.Append(aDisabledEAPArrary[i]->iExpandedEAPType);					
       
  2579 	}
       
  2580 	
       
  2581 	// Save the strings in the DB.
       
  2582 	
       
  2583 	// Get column set so we get the correct column numbers
       
  2584 	CDbColSet* colSet = view.ColSetL();
       
  2585 	CleanupStack::PushL(colSet);			
       
  2586 	
       
  2587 	// Validate length of strings
       
  2588 	if(acceptedPtr.Length() > KMaxTunneledTypeStringLengthInDB 
       
  2589 		|| unacceptedPtr.Length() > KMaxTunneledTypeStringLengthInDB)
       
  2590 	{
       
  2591 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetTunnelingExpandedEapDataL - Too long Tunneled EAP type string \n") ) );
       
  2592 
       
  2593 		User::Leave(KErrArgument);		
       
  2594 	}
       
  2595 	
       
  2596 	view.SetColL(colSet->ColNo(cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal), acceptedPtr);
       
  2597 	view.SetColL(colSet->ColNo(cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal), unacceptedPtr);	
       
  2598 
       
  2599 	CleanupStack::PopAndDestroy( colSet ); // Delete colSet.	
       
  2600 
       
  2601 	view.PutL();
       
  2602 
       
  2603 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::SetTunnelingExpandedEapDataL- Enabled extended EAP type data added to DB:",
       
  2604 		acceptedPtr.Ptr(), 
       
  2605 		acceptedPtr.Size() ) );
       
  2606 
       
  2607 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::SetTunnelingExpandedEapDataL- Disabled extended EAP type data added to DB:",
       
  2608 		unacceptedPtr.Ptr(), 
       
  2609 		unacceptedPtr.Size() ) );
       
  2610 
       
  2611 	CleanupStack::PopAndDestroy(unacceptedDbText); // Delete unacceptedDbText
       
  2612 	CleanupStack::PopAndDestroy(acceptedDbText); // Delete acceptedDbText	
       
  2613 	CleanupStack::PopAndDestroy(&view); // Close view
       
  2614 	CleanupStack::PopAndDestroy(buf); // Delete buf	
       
  2615 }
       
  2616 
       
  2617 // Retrieves the tunneled EAP type (expanded) from the database	.
       
  2618 void EapTlsPeapUtils::GetTunnelingExpandedEapDataL(
       
  2619 	RDbNamedDatabase& aDatabase,
       
  2620 	eap_am_tools_symbian_c * const /*aTools*/,
       
  2621 	RExpandedEapTypePtrArray &aEnabledEAPArrary,
       
  2622 	RExpandedEapTypePtrArray &aDisabledEAPArrary,
       
  2623 	const TIndexType aIndexType,
       
  2624 	const TInt aIndex,
       
  2625 	const eap_type_value_e aTunnelingType,
       
  2626 	const eap_type_value_e aEapType)
       
  2627 {
       
  2628 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  2629 	TUint aEapVendorType = aEapType.get_vendor_type();
       
  2630 	
       
  2631 	EAP_TRACE_DEBUG_SYMBIAN(
       
  2632 		(_L("EapTlsPeapUtils::GetTunnelingExpandedEapDataL aIndexType=%d, aIndex=%d, Tunneling vendor type=%d, Eap vendor type=%d \n"),
       
  2633 		aIndexType,aIndex, aTunnelingVendorType, aEapVendorType));
       
  2634 
       
  2635 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  2636 	TPtr sqlStatement = buf->Des();
       
  2637 	
       
  2638 	_LIT(KSQLQueryRow, "SELECT %S, %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  2639 
       
  2640 	if (aEapType == eap_type_peap)
       
  2641 	{
       
  2642 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2643 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2644 			&KPeapDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2645 			&KTunnelingType, aTunnelingVendorType);		
       
  2646 	} 
       
  2647 #if defined(USE_TTLS_EAP_TYPE)
       
  2648 	else if (aEapType == eap_type_ttls)
       
  2649 	{
       
  2650 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2651 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2652 			&KTtlsDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2653 			&KTunnelingType, aTunnelingVendorType);		
       
  2654 	} 
       
  2655 #endif
       
  2656 #if defined(USE_FAST_EAP_TYPE)
       
  2657 	else if (aEapType == eap_type_fast)
       
  2658 	{
       
  2659 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2660 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2661 			&KFastGeneralSettingsDBTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2662 			&KTunnelingType, aTunnelingVendorType);		
       
  2663 	} 
       
  2664 #endif
       
  2665 
       
  2666 	else if (aEapType == eap_type_ttls_plain_pap )
       
  2667 	{
       
  2668 		sqlStatement.Format(KSQLQueryRow, &cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal, 
       
  2669 			&cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal,
       
  2670 			&KTtlsDatabaseTableName, &KServiceType, aIndexType, &KServiceIndex, aIndex, 
       
  2671 			&KTunnelingType, aTunnelingVendorType);		
       
  2672 	} 
       
  2673 
       
  2674 	else
       
  2675 	{
       
  2676 		EAP_TRACE_DEBUG_SYMBIAN(
       
  2677 			(_L("EapTlsPeapUtils::GetTunnelingExpandedEapDataL - Unsupported EAP type=%d \n"),
       
  2678 			 aEapVendorType));
       
  2679 			 
       
  2680 		// Unsupported EAP type
       
  2681 		User::Leave(KErrNotSupported);
       
  2682 	}	
       
  2683 	
       
  2684 	RDbView view;
       
  2685 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  2686 	CleanupClosePushL(view);
       
  2687 	User::LeaveIfError(view.EvaluateAll());	
       
  2688 	
       
  2689 	User::LeaveIfError(view.FirstL());
       
  2690 	
       
  2691 	view.GetL();
       
  2692 	
       
  2693 	// Get column set so we get the correct column numbers
       
  2694 	CDbColSet* colSet = view.ColSetL();
       
  2695 	CleanupStack::PushL(colSet);			
       
  2696 	
       
  2697 	TPtrC8 acceptedEAPData = view.ColDes8(colSet->ColNo(cf_str_PEAP_accepted_tunneled_client_types_hex_data_literal));
       
  2698 	TPtrC8 unacceptedEAPData = view.ColDes8(colSet->ColNo(cf_str_PEAP_unaccepted_tunneled_client_types_hex_data_literal));
       
  2699 	
       
  2700 	CleanupStack::PopAndDestroy( colSet ); // Delete colSet.	
       
  2701 
       
  2702 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::GetTunnelingExpandedEapDataL- Enabled extended EAP type data from DB:",
       
  2703 		acceptedEAPData.Ptr(), 
       
  2704 		acceptedEAPData.Size() ) );
       
  2705 	
       
  2706 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("EapTlsPeapUtils::GetTunnelingExpandedEapDataL- Disabled extended EAP type data from DB:",
       
  2707 		unacceptedEAPData.Ptr(), 
       
  2708 		unacceptedEAPData.Size() ) );
       
  2709 	
       
  2710 	aEnabledEAPArrary.ResetAndDestroy();
       
  2711 	aDisabledEAPArrary.ResetAndDestroy();
       
  2712 		
       
  2713 	TUint acceptedLength = acceptedEAPData.Length();
       
  2714 	TUint unacceptedLength = unacceptedEAPData.Length();
       
  2715 	
       
  2716 	SExpandedEAPType *expandedEAPTmp = 0;
       
  2717 	TUint index = 0;
       
  2718 	
       
  2719 	// For accepted or enabled tunneled EAP types. 	
       
  2720 	while(index < acceptedLength)
       
  2721 	{		
       
  2722 		expandedEAPTmp = new SExpandedEAPType;
       
  2723 
       
  2724 		if (expandedEAPTmp == 0)
       
  2725 		{
       
  2726 			aEnabledEAPArrary.ResetAndDestroy();
       
  2727 			aDisabledEAPArrary.ResetAndDestroy();
       
  2728 			User::LeaveIfError(KErrNoMemory);
       
  2729 		}
       
  2730 
       
  2731 		expandedEAPTmp->iExpandedEAPType = acceptedEAPData.Mid(index, KExpandedEAPTypeSize);
       
  2732 						
       
  2733 		EAP_TRACE_DATA_DEBUG_SYMBIAN(("Extracted EAP type:",
       
  2734 			expandedEAPTmp->iExpandedEAPType.Ptr(), 
       
  2735 			expandedEAPTmp->iExpandedEAPType.Size() ) );
       
  2736 
       
  2737 		aEnabledEAPArrary.Append(expandedEAPTmp);
       
  2738 
       
  2739 		index = index + KExpandedEAPTypeSize;
       
  2740 	}
       
  2741 	
       
  2742 	index = 0;
       
  2743 	
       
  2744 	// For unaccepted or disabled tunneled EAP types.
       
  2745 	while(index < unacceptedLength)
       
  2746 	{		
       
  2747 		expandedEAPTmp = new SExpandedEAPType;
       
  2748 
       
  2749 		if (expandedEAPTmp == 0)
       
  2750 		{
       
  2751 			aEnabledEAPArrary.ResetAndDestroy();
       
  2752 			aDisabledEAPArrary.ResetAndDestroy();
       
  2753 			User::LeaveIfError(KErrNoMemory);
       
  2754 		}
       
  2755 
       
  2756 		expandedEAPTmp->iExpandedEAPType = unacceptedEAPData.Mid(index, KExpandedEAPTypeSize);
       
  2757 						
       
  2758 		EAP_TRACE_DATA_DEBUG_SYMBIAN(("Extracted EAP type:",
       
  2759 			expandedEAPTmp->iExpandedEAPType.Ptr(), 
       
  2760 			expandedEAPTmp->iExpandedEAPType.Size() ) );
       
  2761 
       
  2762 		aDisabledEAPArrary.Append(expandedEAPTmp);
       
  2763 
       
  2764 		index = index + KExpandedEAPTypeSize;
       
  2765 	}
       
  2766 
       
  2767 	CleanupStack::PopAndDestroy(&view); // Close view
       
  2768 	CleanupStack::PopAndDestroy(buf); // Delete buf
       
  2769 }
       
  2770 
       
  2771 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  2772 
       
  2773 //--------------------------------------------------
       
  2774 
       
  2775 TBool EapTlsPeapUtils::CipherSuiteUseRSAKeys(tls_cipher_suites_e aCipherSuite)
       
  2776 {
       
  2777 	if (aCipherSuite == tls_cipher_suites_TLS_RSA_WITH_3DES_EDE_CBC_SHA
       
  2778 		|| aCipherSuite == tls_cipher_suites_TLS_RSA_WITH_AES_128_CBC_SHA
       
  2779 		|| aCipherSuite == tls_cipher_suites_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
       
  2780 		|| aCipherSuite == tls_cipher_suites_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
       
  2781 		|| aCipherSuite == tls_cipher_suites_TLS_RSA_WITH_RC4_128_MD5
       
  2782 		|| aCipherSuite == tls_cipher_suites_TLS_RSA_WITH_RC4_128_SHA)
       
  2783 	{
       
  2784 		return ETrue;
       
  2785 	}
       
  2786 
       
  2787 	return EFalse;
       
  2788 
       
  2789 }
       
  2790 
       
  2791 //--------------------------------------------------
       
  2792 
       
  2793 TBool EapTlsPeapUtils::CipherSuiteUseDSAKeys(tls_cipher_suites_e aCipherSuite)
       
  2794 {
       
  2795 	if (aCipherSuite == tls_cipher_suites_TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
       
  2796 		|| aCipherSuite == tls_cipher_suites_TLS_DHE_DSS_WITH_AES_128_CBC_SHA)
       
  2797 	{
       
  2798 		return ETrue;
       
  2799 	}
       
  2800 
       
  2801 	return EFalse;
       
  2802 }
       
  2803 
       
  2804 //--------------------------------------------------
       
  2805 
       
  2806 TBool EapTlsPeapUtils::CipherSuiteIsEphemeralDHKeyExchange(tls_cipher_suites_e aCipherSuite)
       
  2807 {
       
  2808 	if (aCipherSuite == tls_cipher_suites_TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
       
  2809 		|| aCipherSuite == tls_cipher_suites_TLS_DHE_DSS_WITH_AES_128_CBC_SHA
       
  2810 		|| aCipherSuite == tls_cipher_suites_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
       
  2811 		|| aCipherSuite == tls_cipher_suites_TLS_DHE_RSA_WITH_AES_128_CBC_SHA)
       
  2812 	{
       
  2813 		return ETrue;
       
  2814 	}
       
  2815 
       
  2816 	return EFalse;
       
  2817 }
       
  2818 
       
  2819 
       
  2820 // ---------------------------------------------------------
       
  2821 // EapTlsPeapUtils::SetConfigurationL()
       
  2822 // ---------------------------------------------------------
       
  2823 //
       
  2824 void EapTlsPeapUtils::SetConfigurationL(
       
  2825 	RDbNamedDatabase& aDatabase,
       
  2826 	const EAPSettings& aSettings, 
       
  2827 	const TIndexType aIndexType,
       
  2828 	const TInt aIndex,
       
  2829 	const eap_type_value_e aTunnelingType,
       
  2830 	const eap_type_value_e aEapType)
       
  2831 {
       
  2832 #ifdef USE_EAP_EXPANDED_TYPES
       
  2833 
       
  2834 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  2835 	TUint aEapVendorType = aEapType.get_vendor_type();
       
  2836 
       
  2837 #else
       
  2838 
       
  2839 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  2840 	TUint aEapVendorType = static_cast<TUint>(aEapType);
       
  2841 
       
  2842 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  2843 
       
  2844 // The current values for TTLS-PAP:
       
  2845 // TTLS: aEapVendorType = TTLS, aTunnelingVendorType = None
       
  2846 // TTLS/plain-PAP: aEapVendorType = ttls_plain_pap, aTunnelingVendorType = TTLS
       
  2847 	
       
  2848 	EAP_TRACE_DEBUG_SYMBIAN(
       
  2849 		(_L("EapTlsPeapUtils::SetConfigurationL -Start- aIndexType=%d, aIndex=%d, Tunneling vendor type=%d, Eap vendor type=%d \n"),
       
  2850 		aIndexType,aIndex, aTunnelingVendorType, aEapVendorType));
       
  2851 	
       
  2852 	EAP_TRACE_DEBUG_SYMBIAN((_L("*************************** SetConfigurationL - Set the below values: ***************************\n")) );
       
  2853 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - Set these values for EAPType=%d"),aSettings.iEAPType) );
       
  2854 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, Username=%S"),aSettings.iUsernamePresent, &(aSettings.iUsername)) );
       
  2855 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, Password=%S"),aSettings.iPasswordPresent, &(aSettings.iPassword)) );
       
  2856 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, Realm=%S"),aSettings.iRealmPresent, &(aSettings.iRealm)) );
       
  2857 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, UsePseudonyms=%d"),aSettings.iUsePseudonymsPresent, aSettings.iUsePseudonyms) );
       
  2858 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, VerifyServerRealm=%d"),
       
  2859 						aSettings.iVerifyServerRealmPresent, aSettings.iVerifyServerRealm) );
       
  2860 
       
  2861 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, RequireClientAuthentication=%d"),
       
  2862 						aSettings.iRequireClientAuthenticationPresent, aSettings.iRequireClientAuthentication) );
       
  2863 						
       
  2864 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, SessionValidityTime=%d minutes"),
       
  2865 						aSettings.iSessionValidityTimePresent, aSettings.iSessionValidityTime) );
       
  2866 
       
  2867 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, CipherSuites Count=%d"),
       
  2868 						aSettings.iCipherSuitesPresent, aSettings.iCipherSuites.Count()) );
       
  2869 	
       
  2870 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, PEAPv0Allowed=%d, PEAPv1Allowed=%d, PEAPv2Allowed=%d"),
       
  2871 						aSettings.iPEAPVersionsPresent, aSettings.iPEAPv0Allowed,aSettings.iPEAPv1Allowed, aSettings.iPEAPv2Allowed ) );
       
  2872 	
       
  2873 	// Validate length of inputs.
       
  2874 	if(aSettings.iUsername.Length() > KMaxManualUsernameLengthInDB
       
  2875 		|| aSettings.iRealm.Length() > KMaxManualRealmLengthInDB )
       
  2876 	{
       
  2877 		// Some inputs are too long. Can not be stored in DB.
       
  2878 		
       
  2879 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL: Too long arguments\n")));
       
  2880 		
       
  2881 		User::Leave(KErrArgument);
       
  2882 	}
       
  2883 	
       
  2884 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, Certificates Count=%d"),
       
  2885 						aSettings.iCertificatesPresent, aSettings.iCertificates.Count()) );
       
  2886 						
       
  2887 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - Certificate details below: \n")) );
       
  2888 	
       
  2889 	for( TInt n=0; n < aSettings.iCertificates.Count(); n++ )
       
  2890 	{
       
  2891 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - Certificate type:%d \n"), aSettings.iCertificates[n].iCertType) );
       
  2892 		
       
  2893 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - certificates - present=%d, SubjectName=%S"),
       
  2894 						aSettings.iCertificates[n].iSubjectNamePresent, &(aSettings.iCertificates[n].iSubjectName) ) );
       
  2895 						
       
  2896 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - certificates - present=%d, IssuerName=%S"),
       
  2897 						aSettings.iCertificates[n].iIssuerNamePresent, &(aSettings.iCertificates[n].iIssuerName) ) );
       
  2898 						
       
  2899 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - certificates - present=%d, SerialNumber=%S"),
       
  2900 						aSettings.iCertificates[n].iSerialNumberPresent, &(aSettings.iCertificates[n].iSerialNumber) ) );
       
  2901 						
       
  2902 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - certificates - SubjectKeyID present=%d"),
       
  2903 						aSettings.iCertificates[n].iSubjectKeyIDPresent ) );						
       
  2904 						
       
  2905 		EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "SubjectKeyID:", aSettings.iCertificates[n].iSubjectKeyID.Ptr(), 
       
  2906 													aSettings.iCertificates[n].iSubjectKeyID.Size() ) );
       
  2907 
       
  2908 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - certificates - Thumbprint present=%d"),
       
  2909 						aSettings.iCertificates[n].iThumbprintPresent ) );						
       
  2910 						
       
  2911 		EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "Thumbprint:", aSettings.iCertificates[n].iThumbprint.Ptr(), 
       
  2912 													aSettings.iCertificates[n].iThumbprint.Size() ) );
       
  2913 	}						
       
  2914 
       
  2915 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, EncapsulatedEAPTypes Count=%d"),
       
  2916 						aSettings.iEncapsulatedEAPTypesPresent, aSettings.iEncapsulatedEAPTypes.Count()) );
       
  2917 	
       
  2918 	for( TInt m=0; m < aSettings.iEncapsulatedEAPTypes.Count(); m++ )
       
  2919 	{	
       
  2920 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - EncapsulatedEAPTypes=%d"),
       
  2921 						aSettings.iEncapsulatedEAPTypes[m]) );
       
  2922 	}						
       
  2923 
       
  2924 #ifdef USE_FAST_EAP_TYPE		
       
  2925 
       
  2926 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, AuthProvModeAllowed=%d"),
       
  2927 						aSettings.iAuthProvModeAllowedPresent, aSettings.iAuthProvModeAllowed) );
       
  2928 
       
  2929 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, UnauthProvModeAllowed=%d"),
       
  2930 						aSettings.iUnauthProvModeAllowedPresent, aSettings.iUnauthProvModeAllowed) );
       
  2931 
       
  2932 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, WarnADHPNoPAC=%d"),
       
  2933 			aSettings.iWarnADHPNoPACPresent, aSettings.iWarnADHPNoPAC) );
       
  2934 
       
  2935 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, WarnADHPNoMatchingPAC=%d"),
       
  2936 			aSettings.iWarnADHPNoMatchingPACPresent, aSettings.iWarnADHPNoMatchingPAC) );
       
  2937 
       
  2938 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, WarnNotDefaultServer=%d"),
       
  2939 			aSettings.iWarnNotDefaultServerPresent, aSettings.iWarnNotDefaultServer) );
       
  2940 	
       
  2941 	// Validate length of PAC Group Ref.
       
  2942 	if(aSettings.iPACGroupReference.Length() > KMaxPACGroupRefCollectionLengthInDB)
       
  2943 	{
       
  2944 		// Too long PAC Group Reference. Can not be stored in DB.
       
  2945 		
       
  2946 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL: Too long PAC Group Ref!\n")));
       
  2947 		
       
  2948 		User::Leave(KErrArgument);
       
  2949 	}
       
  2950 
       
  2951 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, PAC Group Ref=%S"),
       
  2952 						aSettings.iPACGroupReferencePresent, &(aSettings.iPACGroupReference)) );
       
  2953 
       
  2954 #endif //#ifdef USE_FAST_EAP_TYPE		
       
  2955 
       
  2956 	EAP_TRACE_DEBUG_SYMBIAN((_L("*************************** SetConfigurationL - Set the above values: ***************************\n")) );
       
  2957 
       
  2958 
       
  2959 	// Check if the settings are for the correct type
       
  2960 	if ((aSettings.iEAPType != EAPSettings::EEapTls
       
  2961 		&& aSettings.iEAPType != EAPSettings::EEapPeap
       
  2962 		&& aSettings.iEAPType != EAPSettings::EEapTtls
       
  2963 #ifdef USE_FAST_EAP_TYPE		
       
  2964 		&& aSettings.iEAPType != EAPSettings::EEapFast
       
  2965 #endif	
       
  2966 		&& aSettings.iEAPType != EAPSettings::ETtlsPlainPap
       
  2967 		)
       
  2968 		|| static_cast<TUint>(aSettings.iEAPType) != aEapVendorType)
       
  2969 	{
       
  2970 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - LEAVE - Unsupported EAP type\n")) );
       
  2971 		
       
  2972 		User::Leave(KErrNotSupported);
       
  2973 	}
       
  2974 		
       
  2975 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  2976 	TPtr sqlStatement = buf->Des();	
       
  2977 
       
  2978 	TPtrC settings;
       
  2979 	TPtrC usercerts;
       
  2980 	TPtrC cacerts;
       
  2981 	TPtrC ciphersuites;
       
  2982 	TPtrC maxSessionTime;
       
  2983 	TPtrC lastFullAuthTime;
       
  2984 
       
  2985 #ifdef USE_FAST_EAP_TYPE
       
  2986 	TPtrC fastSpecialSettings;		
       
  2987 #endif
       
  2988 	
       
  2989 	switch (aEapVendorType)
       
  2990 	{
       
  2991 	case eap_type_tls:
       
  2992 		{
       
  2993 			settings.Set(KTlsDatabaseTableName);
       
  2994 			usercerts.Set(KTlsAllowedUserCertsDatabaseTableName);
       
  2995 			cacerts.Set(KTlsAllowedCACertsDatabaseTableName);
       
  2996 			ciphersuites.Set(KTlsAllowedCipherSuitesDatabaseTableName);
       
  2997 			maxSessionTime.Set(cf_str_EAP_TLS_max_session_validity_time_literal);
       
  2998 			lastFullAuthTime.Set(KTLSLastFullAuthTime);
       
  2999 		}
       
  3000 		break;
       
  3001 
       
  3002 	case eap_type_peap:
       
  3003 		{
       
  3004 			settings.Set(KPeapDatabaseTableName);
       
  3005 			usercerts.Set(KPeapAllowedUserCertsDatabaseTableName);
       
  3006 			cacerts.Set(KPeapAllowedCACertsDatabaseTableName);
       
  3007 			ciphersuites.Set(KPeapAllowedCipherSuitesDatabaseTableName);
       
  3008 			maxSessionTime.Set(cf_str_EAP_PEAP_max_session_validity_time_literal);
       
  3009 			lastFullAuthTime.Set(KPEAPLastFullAuthTime);
       
  3010 		}
       
  3011 		break;
       
  3012 
       
  3013 	case eap_type_ttls:
       
  3014 		{
       
  3015 			settings.Set(KTtlsDatabaseTableName);
       
  3016 			usercerts.Set(KTtlsAllowedUserCertsDatabaseTableName);
       
  3017 			cacerts.Set(KTtlsAllowedCACertsDatabaseTableName);
       
  3018 			ciphersuites.Set(KTtlsAllowedCipherSuitesDatabaseTableName);
       
  3019 			maxSessionTime.Set(cf_str_EAP_TTLS_max_session_validity_time_literal);
       
  3020 			lastFullAuthTime.Set(KTTLSLastFullAuthTime);
       
  3021 		}
       
  3022 		break;
       
  3023 
       
  3024 #ifdef USE_FAST_EAP_TYPE		
       
  3025 	case eap_type_fast:
       
  3026 		{
       
  3027 			settings.Set(KFastGeneralSettingsDBTableName); // This is general settings for FAST.
       
  3028 			fastSpecialSettings.Set(KFastSpecialSettingsDBTableName);
       
  3029 			
       
  3030 			usercerts.Set(KFastAllowedUserCertsDatabaseTableName);
       
  3031 			cacerts.Set(KFastAllowedCACertsDatabaseTableName);
       
  3032 			ciphersuites.Set(KFastAllowedCipherSuitesDatabaseTableName);
       
  3033 			maxSessionTime.Set(cf_str_EAP_FAST_max_session_validity_time_literal);
       
  3034 			lastFullAuthTime.Set(KFASTLastFullAuthTime);
       
  3035 		}
       
  3036 		break;
       
  3037 #endif
       
  3038 
       
  3039 	case eap_type_ttls_plain_pap:
       
  3040 		{
       
  3041 			settings.Set( KTtlsDatabaseTableName );
       
  3042 			maxSessionTime.Set( cf_str_EAP_TLS_PEAP_ttls_pap_max_session_validity_time_literal );
       
  3043 			lastFullAuthTime.Set( KTTLSPAPLastFullAuthTime );
       
  3044 		}
       
  3045 		break;
       
  3046 
       
  3047 	default:
       
  3048 		{
       
  3049 			EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - LEAVE - Unsupported EAP type =%d\n"),
       
  3050 				aEapVendorType) );
       
  3051 
       
  3052 			// Should never happen
       
  3053 			User::Leave(KErrArgument);
       
  3054 		}
       
  3055 	}	
       
  3056 	
       
  3057 	RDbView view;
       
  3058 
       
  3059 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  3060 	
       
  3061 	//////////////////////////////////////////
       
  3062 	// This is for settings for all EAP types.
       
  3063 	// For EAP-FAST it is General settings.
       
  3064 	//////////////////////////////////////////
       
  3065 	
       
  3066 	sqlStatement.Format( KSQL, &settings, 
       
  3067 		&KServiceType, aIndexType, &KServiceIndex, aIndex,
       
  3068 		&KTunnelingType, aTunnelingVendorType );		
       
  3069 		
       
  3070 	// Evaluate view
       
  3071 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
       
  3072 	
       
  3073 	CleanupClosePushL(view);
       
  3074 	
       
  3075 	User::LeaveIfError(view.EvaluateAll());	
       
  3076 
       
  3077 	view.FirstL();
       
  3078 	
       
  3079 	view.UpdateL();
       
  3080 	
       
  3081 	// Get column set so we get the correct column numbers
       
  3082 	CDbColSet* colSet = view.ColSetL();
       
  3083 	CleanupStack::PushL(colSet);
       
  3084 
       
  3085 	// Database view is ready for setting now. Set items one by one, if needed.
       
  3086 
       
  3087 
       
  3088 	//////////////////////////////////////////
       
  3089 	// This is only for plain PAP settings. //
       
  3090 	//////////////////////////////////////////
       
  3091 	if ( aEapVendorType == eap_type_ttls_plain_pap )
       
  3092 		{
       
  3093 		// Username
       
  3094 		if ( aSettings.iUsernamePresent )
       
  3095 		    {
       
  3096 			// Validate length.
       
  3097 			if( aSettings.iUsername.Length() > KMaxPapUserNameLengthInDb )
       
  3098 			    {
       
  3099 				// Username too long. Can not be stored in DB.				
       
  3100 				EAP_TRACE_DEBUG_SYMBIAN( ( _L( 
       
  3101 					"EapTlsPeapUtils::SetConfigurationL: Too long Username. Length=%d \n" ),
       
  3102 				aSettings.iUsername.Length() ) );
       
  3103 				CleanupStack::PopAndDestroy( 3 ); // colset, view, buf
       
  3104 				User::Leave( KErrArgument );
       
  3105 			    }
       
  3106 			
       
  3107 			// Length is ok. Set the value in DB.
       
  3108 			view.SetColL( colSet->ColNo( cf_str_EAP_TLS_PEAP_ttls_pap_username_literal ),
       
  3109 				aSettings.iUsername);		
       
  3110 		    }
       
  3111 		// Password
       
  3112 		if ( aSettings.iPasswordPresent )
       
  3113 		    {
       
  3114 			// Validate length.
       
  3115 			if ( aSettings.iPassword.Length() > KMaxPapPasswordLengthInDb )
       
  3116 			    {
       
  3117 				// Password too long. Can not be stored in DB.				
       
  3118 				EAP_TRACE_DEBUG_SYMBIAN( ( _L(
       
  3119 					"EapTlsPeapUtils::SetConfigurationL: Too long Password. Length=%d \n" ),
       
  3120 				aSettings.iPassword.Length() ) );
       
  3121 				CleanupStack::PopAndDestroy( 3 ); // colset, view, buf
       
  3122 				User::Leave( KErrArgument );
       
  3123 			    }
       
  3124 						
       
  3125 			// Length is ok. Set the value in DB.	
       
  3126 			view.SetColL( colSet->ColNo(
       
  3127 				cf_str_EAP_TLS_PEAP_ttls_pap_password_literal ),
       
  3128 				aSettings.iPassword );
       
  3129 			
       
  3130 			// If password was supplied set password prompting off
       
  3131 			view.SetColL( colSet->ColNo(
       
  3132 				cf_str_EAP_TLS_PEAP_ttls_pap_password_prompt_literal ),
       
  3133 				EPapPasswordPromptOff );
       
  3134 		    }
       
  3135 				
       
  3136 		// Session validity time
       
  3137 		if ( aSettings.iSessionValidityTimePresent )
       
  3138 		    {
       
  3139 			// User or device management wants to store the session validity time.
       
  3140 			// Convert the time to micro seconds and save.			
       
  3141 			TInt64 validityInMicro =
       
  3142 			    ( aSettings.iSessionValidityTime )
       
  3143 			    *
       
  3144 			    KMicroSecsInAMinute;			
       
  3145 			view.SetColL( colSet->ColNo( maxSessionTime ), validityInMicro );
       
  3146 			
       
  3147 			// If max session validity time is supplied and non-zero, set password prompting ON.
       
  3148 			// It doesn't matter even if the password is supplied. If max session validity is supplied,
       
  3149 			// it means user needs to provide a password hence prompt should appear.			
       
  3150 			if( validityInMicro != 0)
       
  3151 			    {
       
  3152 				view.SetColL( colSet->ColNo(
       
  3153 					cf_str_EAP_TLS_PEAP_ttls_pap_password_prompt_literal ),
       
  3154 					EPapPasswordPromptOn );
       
  3155 			    }		
       
  3156 		    }
       
  3157 		
       
  3158 		// Last full authentication time should be made zero when EAP configurations are modified.
       
  3159 		// This makes sure that the next authentication with this EAP would be full authentication
       
  3160 		// instead of reauthentication even if the session is still valid.		
       
  3161 		view.SetColL( colSet->ColNo( lastFullAuthTime ), default_FullAuthTime );
       
  3162 		EAP_TRACE_DEBUG_SYMBIAN( ( _L(
       
  3163 			"Session Validity: EAP-Type=%d, Resetting Full Auth Time since settings are modified\n" ),
       
  3164 			aSettings.iEAPType ));
       
  3165 	    
       
  3166 		view.PutL();		
       
  3167 		CleanupStack::PopAndDestroy( 3 ); // colset, view, buf
       
  3168 		
       
  3169 	    EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL - Return \n") ) );		
       
  3170 	    return; 
       
  3171         } // if ( aEapVendorType == eap_type_ttls_plain_pap )
       
  3172 	
       
  3173 	// Manual username
       
  3174 	{
       
  3175 		// Set the value in DB. Value could be empty. It doesn't matter.
       
  3176 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_username_literal), aSettings.iUsername);
       
  3177 		
       
  3178 		// This is to set the automatic or manual status.
       
  3179 		TUint useManualUsernameStatus;
       
  3180 		
       
  3181 		if (aSettings.iUsernamePresent)
       
  3182 		{
       
  3183 			useManualUsernameStatus = ETLSPEAPUseManualUsernameYes;
       
  3184 		}
       
  3185 		else
       
  3186 		{
       
  3187 			useManualUsernameStatus = ETLSPEAPUseManualUsernameNo;
       
  3188 		}
       
  3189 		
       
  3190 		// Set the value.
       
  3191 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_username_literal), 
       
  3192 			useManualUsernameStatus);
       
  3193 		
       
  3194 	}
       
  3195 		
       
  3196 	// Manual realm
       
  3197 	{
       
  3198 		// Set the value in DB. Value could be empty. It doesn't matter.
       
  3199 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_realm_literal), aSettings.iRealm);
       
  3200 
       
  3201 		// This is to set the automatic or manual status.
       
  3202 		TUint useManualRealmStatus;
       
  3203 		
       
  3204 		if (aSettings.iRealmPresent)
       
  3205 		{
       
  3206 			useManualRealmStatus = ETLSPEAPUseManualRealmYes;
       
  3207 		}
       
  3208 		else
       
  3209 		{
       
  3210 			useManualRealmStatus = ETLSPEAPUseManualRealmNo;
       
  3211 		}
       
  3212 		
       
  3213 		// Set the value.
       
  3214 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_realm_literal),
       
  3215 			useManualRealmStatus);	
       
  3216 	}
       
  3217 	
       
  3218 	// Verify server realm
       
  3219 	if (aSettings.iVerifyServerRealmPresent)
       
  3220 	{
       
  3221 		if (aSettings.iVerifyServerRealm)
       
  3222 		{
       
  3223 			view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal), 
       
  3224 				ETLSPEAPVerifyCertRealmYes);
       
  3225 		}
       
  3226 		else
       
  3227 		{			
       
  3228 			view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal), 
       
  3229 				ETLSPEAPVerifyCertRealmNo);
       
  3230 		}
       
  3231 	}
       
  3232 	
       
  3233 	// Require client authentication
       
  3234 	if (aSettings.iRequireClientAuthenticationPresent)
       
  3235 	{
       
  3236 		if (aSettings.iRequireClientAuthentication)
       
  3237 		{
       
  3238 			view.SetColL(colSet->ColNo(cf_str_TLS_server_authenticates_client_policy_in_client_literal),
       
  3239 				ETLSPEAPServerAuthenticatesClientPolicyYes);
       
  3240 		}
       
  3241 		else
       
  3242 		{			
       
  3243 			view.SetColL(colSet->ColNo(cf_str_TLS_server_authenticates_client_policy_in_client_literal),
       
  3244 				ETLSPEAPServerAuthenticatesClientPolicyNo);
       
  3245 		}
       
  3246 	}
       
  3247 	
       
  3248 	// Session validity time
       
  3249 	if (aSettings.iSessionValidityTimePresent)
       
  3250 	{
       
  3251 		// User or device management wants to store the session validity time.
       
  3252 		// Convert the time to micro seconds and save.
       
  3253 		
       
  3254 		TInt64 validityInMicro = (aSettings.iSessionValidityTime) *  KMicroSecsInAMinute;
       
  3255 		
       
  3256 		view.SetColL(colSet->ColNo(maxSessionTime), validityInMicro);
       
  3257 	}
       
  3258 	
       
  3259 	// Last full authentication time should be made zero when EAP configurations are modified.
       
  3260 	// This makes sure that the next authentication with this EAP would be full authentication
       
  3261 	// instead of reauthentication even if the session is still valid.
       
  3262 	
       
  3263 	view.SetColL(colSet->ColNo(lastFullAuthTime), default_FullAuthTime);
       
  3264 
       
  3265 	EAP_TRACE_DEBUG_SYMBIAN((_L("Session Validity: EAP-Type=%d, Resetting Full Auth Time since settings are modified\n"),
       
  3266 								aSettings.iEAPType ));	
       
  3267 	
       
  3268 	// PEAP versions
       
  3269 		
       
  3270 	if (aSettings.iPEAPVersionsPresent
       
  3271 		&& (aEapType == eap_type_peap
       
  3272 		|| aEapType == eap_type_ttls
       
  3273 #ifdef USE_FAST_EAP_TYPE		
       
  3274 		|| aEapType == eap_type_fast
       
  3275 #endif	
       
  3276 		))
       
  3277 	{
       
  3278 		TBuf8<KMaxPEAPVersionsStringLengthInDB> acceptedPEAPVersions;
       
  3279 		
       
  3280 		if (aSettings.iPEAPv0Allowed)
       
  3281 		{
       
  3282 			TInt tmp(0);
       
  3283 			acceptedPEAPVersions.Append(reinterpret_cast<const TUint8*>(&tmp), sizeof(TInt));
       
  3284 		}
       
  3285 		if (aSettings.iPEAPv1Allowed)
       
  3286 		{
       
  3287 			TInt tmp(1);
       
  3288 			acceptedPEAPVersions.Append(reinterpret_cast<const TUint8*>(&tmp), sizeof(TInt));
       
  3289 		}
       
  3290 		if (aSettings.iPEAPv2Allowed)
       
  3291 		{
       
  3292 			TInt tmp(2);
       
  3293 			acceptedPEAPVersions.Append(reinterpret_cast<const TUint8*>(&tmp), sizeof(TInt));
       
  3294 		}
       
  3295 		view.SetColL(colSet->ColNo(cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal), acceptedPEAPVersions); 	
       
  3296 	}
       
  3297 	
       
  3298 	view.PutL();
       
  3299 	
       
  3300 	CleanupStack::PopAndDestroy(2); // view, colset	
       
  3301 	
       
  3302 #ifdef USE_FAST_EAP_TYPE		
       
  3303 
       
  3304 	///////////////////////////////////////////////////////
       
  3305 	// This is only for EAP-FAST specific, Special settings.
       
  3306 	///////////////////////////////////////////////////////
       
  3307 	
       
  3308 	if(aEapType == eap_type_fast)
       
  3309 	{
       
  3310 		sqlStatement.Format(KSQL, &fastSpecialSettings, 
       
  3311 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  3312 		
       
  3313 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
       
  3314 		
       
  3315 		CleanupClosePushL(view);
       
  3316 		
       
  3317 		User::LeaveIfError(view.EvaluateAll());	
       
  3318 
       
  3319 		view.FirstL();
       
  3320 		
       
  3321 		view.UpdateL();	
       
  3322 		
       
  3323 		// Get column set so we get the correct column numbers
       
  3324 		colSet = view.ColSetL();
       
  3325 		CleanupStack::PushL(colSet);	
       
  3326 
       
  3327 		// Database view is ready for setting now. Set items one by one, if needed.
       
  3328 		
       
  3329 		// For provisioning modes.
       
  3330 		if (aSettings.iAuthProvModeAllowedPresent)
       
  3331 		{
       
  3332 			if (aSettings.iAuthProvModeAllowed)
       
  3333 			{
       
  3334 				view.SetColL(colSet->ColNo(cf_str_EAP_FAST_allow_server_authenticated_provisioning_mode_literal), 
       
  3335 					EFASTAuthProvModeAllowedYes);
       
  3336 			}
       
  3337 			else
       
  3338 			{			
       
  3339 				view.SetColL(colSet->ColNo(cf_str_EAP_FAST_allow_server_authenticated_provisioning_mode_literal), 
       
  3340 					EFASTAuthProvModeAllowedNo);
       
  3341 			}
       
  3342 		}
       
  3343 		
       
  3344 		if (aSettings.iUnauthProvModeAllowedPresent)
       
  3345 		{
       
  3346 			if (aSettings.iUnauthProvModeAllowed)
       
  3347 			{
       
  3348 				view.SetColL(colSet->ColNo(cf_str_EAP_FAST_allow_server_unauthenticated_provisioning_mode_ADHP_literal), 
       
  3349 					EFASTUnauthProvModeAllowedYes);
       
  3350 			}
       
  3351 			else
       
  3352 			{			
       
  3353 				view.SetColL(colSet->ColNo(cf_str_EAP_FAST_allow_server_unauthenticated_provisioning_mode_ADHP_literal), 
       
  3354 					EFASTUnauthProvModeAllowedNo);
       
  3355 			}
       
  3356 		}
       
  3357 		
       
  3358 		// For the warnings and prompts
       
  3359 		if (aSettings.iWarnADHPNoPACPresent)
       
  3360 		{
       
  3361 			if (aSettings.iWarnADHPNoPAC)
       
  3362 			{
       
  3363 				view.SetColL(colSet->ColNo(KFASTWarnADHPNoPAC), 
       
  3364 						EFASTWarnADHPNoPACYes);
       
  3365 			}
       
  3366 			else
       
  3367 			{			
       
  3368 				view.SetColL(colSet->ColNo(KFASTWarnADHPNoPAC), 
       
  3369 						EFASTWarnADHPNoPACNo);
       
  3370 			}
       
  3371 		}	
       
  3372 		
       
  3373 		if (aSettings.iWarnADHPNoMatchingPACPresent)
       
  3374 		{
       
  3375 			if (aSettings.iWarnADHPNoMatchingPAC)
       
  3376 			{
       
  3377 				view.SetColL(colSet->ColNo(KFASTWarnADHPNoMatchingPAC), 
       
  3378 						EFASTWarnADHPNoMatchingPACYes);
       
  3379 			}
       
  3380 			else
       
  3381 			{			
       
  3382 				view.SetColL(colSet->ColNo(KFASTWarnADHPNoMatchingPAC), 
       
  3383 						EFASTWarnADHPNoMatchingPACNo);
       
  3384 			}
       
  3385 		}	
       
  3386 		
       
  3387 		if (aSettings.iWarnNotDefaultServerPresent)
       
  3388 		{
       
  3389 			if (aSettings.iWarnADHPNoMatchingPAC)
       
  3390 			{
       
  3391 				view.SetColL(colSet->ColNo(KFASTWarnNotDefaultServer), 
       
  3392 						EFASTWarnNotDefaultServerYes);
       
  3393 			}
       
  3394 			else
       
  3395 			{			
       
  3396 				view.SetColL(colSet->ColNo(KFASTWarnNotDefaultServer), 
       
  3397 						EFASTWarnNotDefaultServerNo);
       
  3398 			}
       
  3399 		}	
       
  3400 		
       
  3401 		// For PAC group reference.
       
  3402 		if (aSettings.iPACGroupReferencePresent)
       
  3403 		{
       
  3404 			// The length of iPACGroupReference is already checked for max length.
       
  3405 			// So just store it in the DB.
       
  3406 			view.SetColL(colSet->ColNo(KFASTPACGroupImportReferenceCollection),
       
  3407 				aSettings.iPACGroupReference);
       
  3408 		}			
       
  3409 		
       
  3410 		view.PutL();
       
  3411 		
       
  3412 		CleanupStack::PopAndDestroy(2); // view, colset			
       
  3413 	
       
  3414 	} // End: if(aEapType == eap_type_fast)
       
  3415 	
       
  3416 #endif // #ifdef USE_FAST_EAP_TYPE		
       
  3417 	
       
  3418 	//////////////////
       
  3419 	// Cipher suites
       
  3420 	//////////////////
       
  3421 	
       
  3422 	if (aSettings.iCipherSuitesPresent)
       
  3423 	{
       
  3424 		sqlStatement.Format(KSQL, &ciphersuites, 
       
  3425 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  3426 		
       
  3427 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
       
  3428 		
       
  3429 		CleanupClosePushL(view);
       
  3430 		
       
  3431 		User::LeaveIfError(view.EvaluateAll());	
       
  3432 
       
  3433 		// Delete old rows
       
  3434 		if (view.FirstL())
       
  3435 		{		
       
  3436 			do {
       
  3437 				view.DeleteL();
       
  3438 			} while (view.NextL() != EFalse);
       
  3439 		}	
       
  3440 		
       
  3441 		// Get column set so we get the correct column numbers
       
  3442 		colSet = view.ColSetL();
       
  3443 		CleanupStack::PushL(colSet);
       
  3444 
       
  3445 		// Database view is ready for setting now. Set items one by one, if needed.
       
  3446 		
       
  3447 		for (TInt i = 0; i < aSettings.iCipherSuites.Count(); i++)
       
  3448 		{
       
  3449 			view.InsertL();			
       
  3450 			view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aIndexType));
       
  3451 			view.SetColL(colSet->ColNo(KServiceIndex), static_cast<TUint>(aIndex));			
       
  3452 			view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
       
  3453 			view.SetColL(colSet->ColNo(KCipherSuite), aSettings.iCipherSuites[i]);
       
  3454 			view.PutL();	
       
  3455 		}
       
  3456 		
       
  3457 		CleanupStack::PopAndDestroy(2); // view, colset
       
  3458 	}
       
  3459 	
       
  3460 	/////////////////////////
       
  3461 	// User + CA Certificates
       
  3462 	/////////////////////////
       
  3463 	
       
  3464 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL - aSettings.iCertificatesPresent=%d \n"), aSettings.iCertificatesPresent ) );
       
  3465 	
       
  3466 	if (aSettings.iCertificatesPresent)
       
  3467 	{
       
  3468 		// Needed for getting the Symbian's subject key id.
       
  3469 		CEapTlsPeapCertFetcher* certFetcher = CEapTlsPeapCertFetcher::NewL();
       
  3470 		CleanupStack::PushL(certFetcher);
       
  3471 				
       
  3472 		TBuf8<KKeyIdentifierLength> symbianSubjectKeyID;		
       
  3473 		
       
  3474 		// For USER certificate.		
       
  3475 		sqlStatement.Format(KSQL, &usercerts, 
       
  3476 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  3477 			
       
  3478 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
       
  3479 	
       
  3480 		CleanupClosePushL(view);
       
  3481 	
       
  3482 		User::LeaveIfError(view.EvaluateAll());	
       
  3483 
       
  3484 		// Delete old rows
       
  3485 		if (view.FirstL())
       
  3486 		{		
       
  3487 			do {
       
  3488 				view.DeleteL();
       
  3489 			} while (view.NextL() != EFalse);
       
  3490 		}	
       
  3491 		
       
  3492 		// Get column set so we get the correct column numbers
       
  3493 		colSet = view.ColSetL();
       
  3494 		CleanupStack::PushL(colSet);
       
  3495 
       
  3496     	// Database view is ready for setting now. Set items one by one, if needed.
       
  3497 		
       
  3498 		TInt i(0);
       
  3499 		
       
  3500 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL - aSettings.iCertificates.Count()=%d \n"), aSettings.iCertificates.Count() ) );
       
  3501 
       
  3502 		for (i = 0; i < aSettings.iCertificates.Count(); i++)
       
  3503 		{
       
  3504 			if (aSettings.iCertificates[i].iCertType == CertificateEntry::EUser)
       
  3505 			{	
       
  3506 				// Validate the length and save other certificate details to the DB.
       
  3507 				if(aSettings.iCertificates[i].iSubjectName.Length() > KKeyIdentifierLength
       
  3508 				   || aSettings.iCertificates[i].iIssuerName.Length() > KGeneralStringMaxLength
       
  3509 				   || aSettings.iCertificates[i].iSerialNumber.Length() > KGeneralStringMaxLength
       
  3510 				   || aSettings.iCertificates[i].iSubjectKeyID.Length() > KGeneralStringMaxLength
       
  3511 				   || aSettings.iCertificates[i].iThumbprint.Length() > KThumbprintMaxLength)
       
  3512 				{
       
  3513 					// Too long data. Can not be stored in DB.
       
  3514 
       
  3515 					EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL : Too long USER cert details.\n")));
       
  3516 										
       
  3517 					User::Leave(KErrArgument);
       
  3518 				}					
       
  3519 						
       
  3520 				EAP_TRACE_DATA_DEBUG_SYMBIAN(("THIS IS SubjectKeyID:",
       
  3521 						aSettings.iCertificates[i].iSubjectKeyID.Ptr(), aSettings.iCertificates[i].iSubjectKeyID.Size()));
       
  3522 
       
  3523 				// The cert label column is left empty
       
  3524 
       
  3525 				view.InsertL();			
       
  3526 				view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aIndexType));
       
  3527 				view.SetColL(colSet->ColNo(KServiceIndex), static_cast<TUint>(aIndex));
       
  3528 				view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);				
       
  3529 																
       
  3530 				view.SetColL(colSet->ColNo(KSubjectName), aSettings.iCertificates[i].iSubjectName);
       
  3531 				view.SetColL(colSet->ColNo(KIssuerName), aSettings.iCertificates[i].iIssuerName);
       
  3532 				view.SetColL(colSet->ColNo(KSerialNumber), aSettings.iCertificates[i].iSerialNumber);
       
  3533 				view.SetColL(colSet->ColNo(KActualSubjectKeyIdentifier), aSettings.iCertificates[i].iSubjectKeyID);					
       
  3534 				
       
  3535 				// Special for thumb print (finger print). Need to convert it to 8 bits before storing in DB
       
  3536 				TBuf8<KThumbprintMaxLength> thumbPrint8Bit;
       
  3537 				thumbPrint8Bit.Copy(aSettings.iCertificates[i].iThumbprint);
       
  3538 				
       
  3539 				view.SetColL(colSet->ColNo(KThumbprint), thumbPrint8Bit);
       
  3540 				
       
  3541 				view.SetColL(colSet->ColNo(KSubjectKeyIdentifier), aSettings.iCertificates[i].iSubjectKeyID);
       
  3542 			
       
  3543 				view.PutL();	
       
  3544 				}
       
  3545 		}
       
  3546 		CleanupStack::PopAndDestroy(2); // view, colset			
       
  3547 
       
  3548 		// Do the same for CA certificates.		
       
  3549 		sqlStatement.Format(KSQL, &cacerts, 
       
  3550 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  3551 		
       
  3552 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
       
  3553 		
       
  3554 		CleanupClosePushL(view);
       
  3555 		
       
  3556 		User::LeaveIfError(view.EvaluateAll());	
       
  3557 		
       
  3558 		// Delete old rows
       
  3559 		if (view.FirstL())
       
  3560 		{		
       
  3561 			do {
       
  3562 				view.DeleteL();
       
  3563 			} while (view.NextL() != EFalse);
       
  3564 		}	
       
  3565 			
       
  3566 		// Get column set so we get the correct column numbers
       
  3567 		colSet = view.ColSetL();
       
  3568 		CleanupStack::PushL(colSet);
       
  3569 
       
  3570 		for (i = 0; i < aSettings.iCertificates.Count(); i++)
       
  3571 		{
       
  3572 			if (aSettings.iCertificates[i].iCertType == CertificateEntry::ECA)
       
  3573 			{
       
  3574 				// Validate the length and save other certificate details to the DB.
       
  3575 				if(aSettings.iCertificates[i].iSubjectName.Length() > KKeyIdentifierLength
       
  3576 				   || aSettings.iCertificates[i].iIssuerName.Length() > KGeneralStringMaxLength
       
  3577 				   || aSettings.iCertificates[i].iSerialNumber.Length() > KGeneralStringMaxLength
       
  3578 				   || aSettings.iCertificates[i].iSubjectKeyID.Length() > KGeneralStringMaxLength
       
  3579 				   || aSettings.iCertificates[i].iThumbprint.Length() > KThumbprintMaxLength)
       
  3580 				{
       
  3581 					// Too long data. Can not be stored in DB.
       
  3582 
       
  3583 					EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL:Too long CA cert details.\n")));
       
  3584 										
       
  3585 					User::Leave(KErrArgument);
       
  3586 				}					
       
  3587 					
       
  3588 				// The cert label column is left empty
       
  3589 				
       
  3590 				view.InsertL();			
       
  3591 				view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aIndexType));
       
  3592 				view.SetColL(colSet->ColNo(KServiceIndex), static_cast<TUint>(aIndex));				
       
  3593 				view.SetColL(colSet->ColNo(KTunnelingType),aTunnelingVendorType);
       
  3594 								
       
  3595 				view.SetColL(colSet->ColNo(KSubjectName), aSettings.iCertificates[i].iSubjectName);
       
  3596 				view.SetColL(colSet->ColNo(KIssuerName), aSettings.iCertificates[i].iIssuerName);
       
  3597 				view.SetColL(colSet->ColNo(KSerialNumber), aSettings.iCertificates[i].iSerialNumber);
       
  3598 				view.SetColL(colSet->ColNo(KActualSubjectKeyIdentifier), aSettings.iCertificates[i].iSubjectKeyID);					
       
  3599 				
       
  3600 				// Special for thumb print (finger print). Need to convert it to 8 bits before storing in DB
       
  3601 				TBuf8<KThumbprintMaxLength> thumbPrint8Bit;
       
  3602 				thumbPrint8Bit.Copy(aSettings.iCertificates[i].iThumbprint);
       
  3603 				
       
  3604 				view.SetColL(colSet->ColNo(KThumbprint), thumbPrint8Bit);
       
  3605 				
       
  3606 				// Get the "symbian's subject key id" using symbian API.
       
  3607 				// We use this subject key id for authentication.
       
  3608 
       
  3609 				view.SetColL(colSet->ColNo(KSubjectKeyIdentifier), aSettings.iCertificates[i].iSubjectKeyID);
       
  3610 
       
  3611 				EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "EapTlsPeapUtils::SetConfigurationL - Adding CA cert to DB, Supplied (Actual) SubjectKeyID:",
       
  3612 					aSettings.iCertificates[i].iSubjectKeyID.Ptr(), aSettings.iCertificates[i].iSubjectKeyID.Size() ) );				
       
  3613 				
       
  3614 				view.PutL();
       
  3615 				}
       
  3616 		}
       
  3617 		
       
  3618 		CleanupStack::PopAndDestroy(2); // view, colset	
       
  3619 		
       
  3620 		CleanupStack::PopAndDestroy(certFetcher);
       
  3621 		
       
  3622 	} // End of if (aSettings.iCertificatesPresent)
       
  3623 	
       
  3624 	CleanupStack::PopAndDestroy(); // buf
       
  3625 		
       
  3626 	/////////////////////
       
  3627 	// Encapsulated types
       
  3628 	/////////////////////
       
  3629 	
       
  3630 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL - aSettings.iEncapsulatedEAPTypesPresent=%d \n"), aSettings.iEncapsulatedEAPTypesPresent ) );
       
  3631 
       
  3632 	// Encapsulated types are only for EAP-PEAP, EAP-TTLS and EAP-FAST. Not for EAP-TLS.
       
  3633 	// This is just to be on safe side. In case if iEncapsulatedEAPTypesPresent is set true for EAP-TLS by the caller.
       
  3634 	if ( aEapType != eap_type_peap 
       
  3635 		 && aEapType != eap_type_ttls
       
  3636 #ifdef USE_FAST_EAP_TYPE
       
  3637 		 && aEapType != eap_type_fast
       
  3638 #endif		  		 
       
  3639 		  )
       
  3640 	{
       
  3641 		EAP_TRACE_DEBUG_SYMBIAN(
       
  3642 			(_L("EapTlsPeapUtils::SetConfigurationL - End - Since no encapsulated type for the EAPType =%d \n"),
       
  3643 			aEapVendorType  ) );
       
  3644 			
       
  3645 		return; // No need to proceed. No encapsulated type for EAP-TLS..
       
  3646 	}
       
  3647 	
       
  3648 #ifdef USE_EAP_EXPANDED_TYPES
       
  3649 
       
  3650 	if (aSettings.iEncapsulatedEAPTypesPresent)
       
  3651 	{
       
  3652 		RExpandedEapTypePtrArray enabledEAPTypes;
       
  3653 		// This is just for dummy. All EAP types available here are enabled as default.
       
  3654 		RExpandedEapTypePtrArray disabledEAPTypes;
       
  3655 		SExpandedEAPType* expandedEAPTmp = 0;
       
  3656 	
       
  3657 		for (TInt i = 0; i < aSettings.iEncapsulatedEAPTypes.Count(); i++)
       
  3658 		{
       
  3659 			expandedEAPTmp = new SExpandedEAPType;
       
  3660 
       
  3661 			if (expandedEAPTmp == 0)
       
  3662 			{
       
  3663 				enabledEAPTypes.ResetAndDestroy();
       
  3664 				disabledEAPTypes.ResetAndDestroy();
       
  3665 				enabledEAPTypes.Close();
       
  3666 				disabledEAPTypes.Close();
       
  3667 				User::Leave(KErrNoMemory);				
       
  3668 			}
       
  3669 			
       
  3670 			// This fills the needed values for vendor id etc.
       
  3671 			eap_expanded_type_c tmpExpEAP(static_cast <eap_type_ietf_values_e> (aSettings.iEncapsulatedEAPTypes[i]));
       
  3672 			
       
  3673 			// This is only for plain-MSCHAPv2 as long as we are using the value 99 for it.
       
  3674 			if(aSettings.iEncapsulatedEAPTypes[i] == EAPSettings::EPlainMschapv2)
       
  3675 			{
       
  3676 				tmpExpEAP.set_eap_type_values(
       
  3677 					eap_type_vendor_id_hack,
       
  3678 					eap_type_vendor_type_plain_MSCHAPv2_hack);
       
  3679 			}
       
  3680 			
       
  3681 			// And this is for TTLS-PAP as long as we are using the value 98 for it.
       
  3682 			if(aSettings.iEncapsulatedEAPTypes[i] == EAPSettings::ETtlsPlainPap)
       
  3683 			{
       
  3684 				tmpExpEAP.set_eap_type_values(
       
  3685 					eap_type_vendor_id_hack,
       
  3686 					eap_type_vendor_type_ttls_plain_pap_hack);
       
  3687 			}
       
  3688 			
       
  3689 			// Some indirect way of forming the 8 byte string of an EAP type is needed here.
       
  3690 			TUint8 tmpExpBuffer[KExpandedEAPTypeSize]; // This is for the eap_expanded_type_c::write_type
       
  3691 			
       
  3692 			// This copies the 8 byte string of EAP type to tmpExpBuffer. 
       
  3693 			eap_status_e status = eap_expanded_type_c::write_type(0,
       
  3694 											0, // index should be zero here.
       
  3695 											tmpExpBuffer,
       
  3696 											KExpandedEAPTypeSize,
       
  3697 											true,
       
  3698 											tmpExpEAP);
       
  3699 											
       
  3700 			// Now copy the 8 byte string to expandedEAPTmp.
       
  3701 			expandedEAPTmp->iExpandedEAPType.Copy(tmpExpBuffer, KExpandedEAPTypeSize);
       
  3702 			
       
  3703 			EAP_TRACE_DATA_DEBUG_SYMBIAN(
       
  3704 				("EapTlsPeapUtils::SetConfigurationL: Expanded EAp type string",
       
  3705 				expandedEAPTmp->iExpandedEAPType.Ptr(), 
       
  3706 				expandedEAPTmp->iExpandedEAPType.Size() ) );						
       
  3707 														
       
  3708 
       
  3709 			enabledEAPTypes.Append(expandedEAPTmp);
       
  3710 		}	
       
  3711 	
       
  3712 	TRAPD(error, SetTunnelingExpandedEapDataL(
       
  3713 			aDatabase, 
       
  3714 			0, 
       
  3715 			enabledEAPTypes,
       
  3716 			disabledEAPTypes, 
       
  3717 			aIndexType,
       
  3718 			aIndex,
       
  3719 			aTunnelingType,
       
  3720 			aEapType));
       
  3721 			
       
  3722 		if( error != KErrNone )
       
  3723 		{
       
  3724 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL - ########### Setting Expanded Tunneling types in the DB failed ############ \n") ) );
       
  3725 
       
  3726 			enabledEAPTypes.ResetAndDestroy();
       
  3727 			disabledEAPTypes.ResetAndDestroy();
       
  3728 			enabledEAPTypes.Close();
       
  3729 			disabledEAPTypes.Close();
       
  3730 
       
  3731 			User::Leave(KErrArgument); // There could be some problem in the encapsulated EAP type argument.
       
  3732 		}
       
  3733 
       
  3734 		enabledEAPTypes.ResetAndDestroy();
       
  3735 		disabledEAPTypes.ResetAndDestroy();
       
  3736 		enabledEAPTypes.Close();
       
  3737 		disabledEAPTypes.Close();
       
  3738 
       
  3739 	}
       
  3740 
       
  3741 #else // For normal unexpanded EAP type.
       
  3742 	
       
  3743 	if (aSettings.iEncapsulatedEAPTypesPresent)
       
  3744 	{
       
  3745 		TEapArray eapArray;
       
  3746 		
       
  3747 		TEap *eap;
       
  3748 		for (TInt i = 0; i < aSettings.iEncapsulatedEAPTypes.Count(); i++)
       
  3749 		{
       
  3750 			eap = new TEap;
       
  3751 			if (eap == 0)
       
  3752 			{
       
  3753 				eapArray.ResetAndDestroy();
       
  3754 				eapArray.Close();
       
  3755 				User::Leave(KErrNoMemory);				
       
  3756 			}
       
  3757 			
       
  3758 			eap->UID.NumFixedWidth(aSettings.iEncapsulatedEAPTypes[i], EDecimal, 2);
       
  3759 			eap->Enabled = ETrue;
       
  3760 			eapArray.Append(eap);
       
  3761 		}	
       
  3762 	
       
  3763 		TInt err(KErrNone);
       
  3764 		TRAP(err, SetEapDataL(
       
  3765 			aDatabase,
       
  3766 			0,
       
  3767 			eapArray,
       
  3768 			aIndexType,
       
  3769 			aIndex,
       
  3770 			aTunnelingType,
       
  3771 			aEapType));
       
  3772 
       
  3773 		if( err != KErrNone )
       
  3774 		{
       
  3775 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL - ########### Setting Tunneling types in the DB failed ############ \n") ) );
       
  3776 
       
  3777 			eapArray.ResetAndDestroy();
       
  3778 			eapArray.Close();			
       
  3779 
       
  3780 			User::Leave(KErrArgument); // There could be some problem in the encapsulated EAP type argument.
       
  3781 		}
       
  3782 
       
  3783 		eapArray.ResetAndDestroy();
       
  3784 		eapArray.Close();			
       
  3785 	}
       
  3786 
       
  3787 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  3788 	
       
  3789 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::SetConfigurationL - End \n") ) );		
       
  3790 
       
  3791 } // EapTlsPeapUtils::SetConfigurationL()
       
  3792 
       
  3793 
       
  3794 // ---------------------------------------------------------
       
  3795 // EapTlsPeapUtils::GetConfigurationL()
       
  3796 // ---------------------------------------------------------
       
  3797 //
       
  3798 void EapTlsPeapUtils::GetConfigurationL(
       
  3799 	RDbNamedDatabase& aDatabase,
       
  3800 	EAPSettings& aSettings, 
       
  3801 	const TIndexType aIndexType,
       
  3802 	const TInt aIndex,
       
  3803 	const eap_type_value_e aTunnelingType,
       
  3804 	const eap_type_value_e aEapType)
       
  3805 {
       
  3806 #ifdef USE_EAP_EXPANDED_TYPES
       
  3807 
       
  3808 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  3809 	TUint aEapVendorType = aEapType.get_vendor_type();
       
  3810 
       
  3811 #else
       
  3812 
       
  3813 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  3814 	TUint aEapVendorType = static_cast<TUint>(aEapType);
       
  3815 
       
  3816 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  3817 		
       
  3818 	EAP_TRACE_DEBUG_SYMBIAN(
       
  3819 		(_L("EapTlsPeapUtils::GetConfigurationL aIndexType=%d, aIndex=%d, Tunneling vendor type=%d, Eap vendor type=%d \n"),
       
  3820 		aIndexType,aIndex, aTunnelingVendorType, aEapVendorType));
       
  3821 
       
  3822 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  3823 	TPtr sqlStatement = buf->Des();	
       
  3824 
       
  3825 	TPtrC settings;
       
  3826 	TPtrC usercerts;
       
  3827 	TPtrC cacerts;
       
  3828 	TPtrC ciphersuites;
       
  3829 	TPtrC maxSessionTime;
       
  3830 	
       
  3831 #ifdef USE_FAST_EAP_TYPE
       
  3832 	TPtrC fastSpecialSettings;		
       
  3833 #endif
       
  3834 	
       
  3835 	switch (aEapVendorType)
       
  3836 	{
       
  3837 	case eap_type_tls:
       
  3838 		{
       
  3839 			settings.Set(KTlsDatabaseTableName);
       
  3840 			usercerts.Set(KTlsAllowedUserCertsDatabaseTableName);
       
  3841 			cacerts.Set(KTlsAllowedCACertsDatabaseTableName);
       
  3842 			ciphersuites.Set(KTlsAllowedCipherSuitesDatabaseTableName);
       
  3843 			maxSessionTime.Set(cf_str_EAP_TLS_max_session_validity_time_literal);
       
  3844 		}
       
  3845 		break;
       
  3846 
       
  3847 	case eap_type_peap:
       
  3848 		{
       
  3849 			settings.Set(KPeapDatabaseTableName);
       
  3850 			usercerts.Set(KPeapAllowedUserCertsDatabaseTableName);
       
  3851 			cacerts.Set(KPeapAllowedCACertsDatabaseTableName);
       
  3852 			ciphersuites.Set(KPeapAllowedCipherSuitesDatabaseTableName);
       
  3853 			maxSessionTime.Set(cf_str_EAP_PEAP_max_session_validity_time_literal);
       
  3854 		}
       
  3855 		break;
       
  3856 
       
  3857 	case eap_type_ttls:
       
  3858 		{
       
  3859 			settings.Set(KTtlsDatabaseTableName);
       
  3860 			usercerts.Set(KTtlsAllowedUserCertsDatabaseTableName);
       
  3861 			cacerts.Set(KTtlsAllowedCACertsDatabaseTableName);
       
  3862 			ciphersuites.Set(KTtlsAllowedCipherSuitesDatabaseTableName);
       
  3863 			maxSessionTime.Set(cf_str_EAP_TTLS_max_session_validity_time_literal);
       
  3864 		}
       
  3865 		break;
       
  3866 
       
  3867 #ifdef USE_FAST_EAP_TYPE
       
  3868 	case eap_type_fast:
       
  3869 		{
       
  3870 			settings.Set(KFastGeneralSettingsDBTableName); // This is general settings for FAST.
       
  3871 			fastSpecialSettings.Set(KFastSpecialSettingsDBTableName);
       
  3872 			
       
  3873 			usercerts.Set(KFastAllowedUserCertsDatabaseTableName);
       
  3874 			cacerts.Set(KFastAllowedCACertsDatabaseTableName);
       
  3875 			ciphersuites.Set(KFastAllowedCipherSuitesDatabaseTableName);
       
  3876 			maxSessionTime.Set(cf_str_EAP_FAST_max_session_validity_time_literal);
       
  3877 		}
       
  3878 		break;
       
  3879 #endif
       
  3880 
       
  3881 
       
  3882 	case eap_type_ttls_plain_pap:
       
  3883 		{
       
  3884 		settings.Set( KTtlsDatabaseTableName );
       
  3885 		maxSessionTime.Set( cf_str_EAP_TLS_PEAP_ttls_pap_max_session_validity_time_literal );
       
  3886 		}
       
  3887 		break;
       
  3888 		
       
  3889 	default:
       
  3890 		// Should never happen
       
  3891 		User::Leave(KErrArgument);
       
  3892 	}	
       
  3893 	
       
  3894 	RDbView view;
       
  3895 
       
  3896 	// Form the query
       
  3897 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  3898 	
       
  3899 	//////////////////////////////////////////
       
  3900 	// This is for settings for all EAP types.
       
  3901 	// For EAP-FAST it is General settings.
       
  3902 	//////////////////////////////////////////
       
  3903 	
       
  3904 	sqlStatement.Format(KSQL, &settings, 
       
  3905 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  3906 
       
  3907 	// Evaluate view
       
  3908 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
       
  3909 	
       
  3910 	CleanupClosePushL(view);
       
  3911 	
       
  3912 	User::LeaveIfError(view.EvaluateAll());	
       
  3913 
       
  3914 	// Get the first (and only) row
       
  3915 	view.FirstL();
       
  3916 	view.GetL();				
       
  3917 	
       
  3918 	// Get column set so we get the correct column numbers
       
  3919 	CDbColSet* colSet = view.ColSetL();
       
  3920 	CleanupStack::PushL(colSet);
       
  3921 
       
  3922 	aSettings.iEAPType = static_cast<EAPSettings::TEapType>(aEapVendorType);
       
  3923 	
       
  3924 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - aSettings.iEAPType=%d \n"),aSettings.iEAPType) );
       
  3925 	
       
  3926 	//////////////////////////////////////////
       
  3927 	// This is only for plain PAP settings. //
       
  3928 	//////////////////////////////////////////
       
  3929 	if ( aEapType == eap_type_ttls_plain_pap )
       
  3930 		{		
       
  3931 	    // Username
       
  3932 	    TPtrC username = view.ColDes( colSet->ColNo(
       
  3933 	   		cf_str_EAP_TLS_PEAP_ttls_pap_username_literal ) );
       
  3934 	    aSettings.iUsername.Copy( username );
       
  3935 	    aSettings.iUsernamePresent = ETrue;
       
  3936 	
       
  3937         // Password
       
  3938 	    TPtrC password = view.ColDes( colSet->ColNo(
       
  3939     		cf_str_EAP_TLS_PEAP_ttls_pap_password_literal ) );
       
  3940 	    aSettings.iPassword.Copy( password );
       
  3941 	    aSettings.iPasswordPresent = ETrue;
       
  3942 
       
  3943 	    // Session validity time	
       
  3944 	    TInt64 maxSessionTimeMicro = view.ColInt64( colSet->ColNo(
       
  3945 	    	cf_str_EAP_TLS_PEAP_ttls_pap_max_session_validity_time_literal ) );
       
  3946 	
       
  3947 	    // Convert the time to minutes.	
       
  3948 	    TInt64 maxSessionTimeMin = maxSessionTimeMicro / KMicroSecsInAMinute;
       
  3949 	
       
  3950 	    aSettings.iSessionValidityTime = static_cast<TUint>( maxSessionTimeMin );
       
  3951 	    aSettings.iSessionValidityTimePresent = ETrue;
       
  3952 		
       
  3953 	    CleanupStack::PopAndDestroy(3); // view, colset, buf
       
  3954 
       
  3955 		return;
       
  3956 		}
       
  3957 
       
  3958 	
       
  3959 	// Username
       
  3960 	TPtrC username = view.ColDes(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_username_literal));
       
  3961 	aSettings.iUsername.Copy(username);
       
  3962 
       
  3963 	// For manual or automatic status.
       
  3964 	TUint useUsername = view.ColUint(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_username_literal));
       
  3965 	if(useUsername == ETLSPEAPUseManualUsernameNo)
       
  3966 	{
       
  3967 		aSettings.iUsernamePresent = EFalse;		
       
  3968 	}
       
  3969 	else
       
  3970 	{
       
  3971 		aSettings.iUsernamePresent = ETrue;		
       
  3972 	}
       
  3973 	
       
  3974 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - Settings.iUsername=%S \n"), &(aSettings.iUsername) ) );
       
  3975 		
       
  3976 	// Realm
       
  3977 	TPtrC realm = view.ColDes(colSet->ColNo(cf_str_EAP_TLS_PEAP_manual_realm_literal));
       
  3978 	aSettings.iRealm.Copy(realm);
       
  3979 
       
  3980 	// For manual or automatic status.
       
  3981 	TUint useRealm = view.ColUint(colSet->ColNo(cf_str_EAP_TLS_PEAP_use_manual_realm_literal));
       
  3982 	if(useRealm == ETLSPEAPUseManualRealmNo)
       
  3983 	{
       
  3984 		aSettings.iRealmPresent = EFalse;
       
  3985 	}
       
  3986 	else
       
  3987 	{
       
  3988 		aSettings.iRealmPresent = ETrue;
       
  3989 	}
       
  3990 	
       
  3991 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - aSettings.iRealm=%S \n"),&(aSettings.iRealm)) );
       
  3992 
       
  3993 	// Verify server realm	
       
  3994 	TInt verifyrealm = view.ColUint(colSet->ColNo(cf_str_EAP_TLS_PEAP_verify_certificate_realm_literal));
       
  3995 	if (verifyrealm == 0)
       
  3996 	{
       
  3997 		aSettings.iVerifyServerRealm = EFalse;
       
  3998 	}
       
  3999 	else
       
  4000 	{
       
  4001 		aSettings.iVerifyServerRealm = ETrue;
       
  4002 	}
       
  4003 	aSettings.iVerifyServerRealmPresent = ETrue;
       
  4004 	
       
  4005 	// Require client authentication
       
  4006 	TInt requireclientauth = view.ColUint(colSet->ColNo(cf_str_TLS_server_authenticates_client_policy_in_client_literal));
       
  4007 	if (requireclientauth == 0)
       
  4008 	{
       
  4009 		aSettings.iRequireClientAuthentication = EFalse;
       
  4010 	}
       
  4011 	else
       
  4012 	{
       
  4013 		aSettings.iRequireClientAuthentication = ETrue;
       
  4014 	}
       
  4015 	aSettings.iRequireClientAuthenticationPresent = ETrue;
       
  4016 
       
  4017 	// Session validity time	
       
  4018 	TInt64 maxSessionTimeMicro = view.ColInt64(colSet->ColNo(maxSessionTime));
       
  4019 	
       
  4020 	// Convert the time to minutes.	
       
  4021 	TInt64 maxSessionTimeMin = maxSessionTimeMicro / KMicroSecsInAMinute;
       
  4022 	
       
  4023 	aSettings.iSessionValidityTime = static_cast<TUint>(maxSessionTimeMin);
       
  4024 	aSettings.iSessionValidityTimePresent = ETrue;
       
  4025 
       
  4026 	// PEAP versions
       
  4027 	if (aEapType == eap_type_peap
       
  4028 		|| aEapType == eap_type_ttls
       
  4029 #ifdef USE_FAST_EAP_TYPE
       
  4030 		|| aEapType == eap_type_fast
       
  4031 #endif		
       
  4032 		)
       
  4033 	{
       
  4034 		TPtrC8 binaryValue = view.ColDes8(colSet->ColNo(cf_str_EAP_TLS_PEAP_accepted_PEAP_versions_literal));
       
  4035 		
       
  4036 		const TInt* allowedVersions = reinterpret_cast<const TInt *>(binaryValue.Ptr());
       
  4037 
       
  4038 		TInt i;
       
  4039 		for (i = 0; i < static_cast<TInt>(binaryValue.Length() / sizeof(TInt)); i++)
       
  4040 		{
       
  4041 			switch(allowedVersions[i])
       
  4042 			{
       
  4043 			case 0:
       
  4044 				aSettings.iPEAPv0Allowed = ETrue;
       
  4045 				break;
       
  4046 			case 1:
       
  4047 				aSettings.iPEAPv1Allowed = ETrue;			
       
  4048 				break;
       
  4049 			case 2:
       
  4050 				aSettings.iPEAPv2Allowed = ETrue;
       
  4051 				
       
  4052 				break;		
       
  4053 			}
       
  4054 		}
       
  4055 		aSettings.iPEAPVersionsPresent = ETrue;
       
  4056 	}
       
  4057 	
       
  4058 	CleanupStack::PopAndDestroy(2); // view, colset
       
  4059 	
       
  4060 #ifdef USE_FAST_EAP_TYPE		
       
  4061 
       
  4062 	///////////////////////////////////////////////////////
       
  4063 	// This is only for EAP-FAST specific, Special settings.
       
  4064 	///////////////////////////////////////////////////////	
       
  4065 	
       
  4066 	if(aEapType == eap_type_fast)
       
  4067 	{
       
  4068 		sqlStatement.Format(KSQL, &fastSpecialSettings, 
       
  4069 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  4070 	
       
  4071 		// Evaluate view
       
  4072 		User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
       
  4073 		
       
  4074 		CleanupClosePushL(view);
       
  4075 		
       
  4076 		User::LeaveIfError(view.EvaluateAll());	
       
  4077 	
       
  4078 		// Get the first (and only) row
       
  4079 		view.FirstL();
       
  4080 		view.GetL();				
       
  4081 		
       
  4082 		// Get column set so we get the correct column numbers
       
  4083 		CDbColSet* colSet = view.ColSetL();
       
  4084 		CleanupStack::PushL(colSet);
       
  4085 	
       
  4086 		// For provisioning modes.
       
  4087 		TUint authProvMode = view.ColUint(colSet->ColNo(cf_str_EAP_FAST_allow_server_authenticated_provisioning_mode_literal));
       
  4088 		if(authProvMode == EFASTAuthProvModeAllowedNo)
       
  4089 		{
       
  4090 			aSettings.iAuthProvModeAllowed = EFalse;
       
  4091 		}
       
  4092 		else
       
  4093 		{
       
  4094 			aSettings.iAuthProvModeAllowed = ETrue;
       
  4095 		}
       
  4096 		
       
  4097 		aSettings.iAuthProvModeAllowedPresent = ETrue;
       
  4098 
       
  4099 		TUint unauthProvMode = view.ColUint(colSet->ColNo(cf_str_EAP_FAST_allow_server_unauthenticated_provisioning_mode_ADHP_literal));
       
  4100 		if(unauthProvMode == EFASTUnauthProvModeAllowedNo)
       
  4101 		{
       
  4102 			aSettings.iUnauthProvModeAllowed = EFalse;
       
  4103 		}
       
  4104 		else
       
  4105 		{
       
  4106 			aSettings.iUnauthProvModeAllowed = ETrue;
       
  4107 		}
       
  4108 		
       
  4109 		aSettings.iUnauthProvModeAllowedPresent = ETrue;		
       
  4110 		
       
  4111 		// For no PAC warning	
       
  4112 		TUint warn = view.ColUint(colSet->ColNo(KFASTWarnADHPNoPAC));
       
  4113 		if(warn == EFASTWarnADHPNoPACNo)
       
  4114 		{
       
  4115 			aSettings.iWarnADHPNoPAC = EFalse;
       
  4116 		}
       
  4117 		else
       
  4118 		{
       
  4119 			aSettings.iWarnADHPNoPAC = ETrue;
       
  4120 		}
       
  4121 		
       
  4122 		aSettings.iWarnADHPNoPACPresent = ETrue;
       
  4123 		
       
  4124 		// For no matching PAC warning		
       
  4125 		warn = view.ColUint(colSet->ColNo(KFASTWarnADHPNoMatchingPAC));
       
  4126 		if(warn == EFASTWarnADHPNoMatchingPACNo)
       
  4127 		{
       
  4128 			aSettings.iWarnADHPNoMatchingPAC = EFalse;
       
  4129 		}
       
  4130 		else
       
  4131 		{
       
  4132 			aSettings.iWarnADHPNoMatchingPAC = ETrue;
       
  4133 		}
       
  4134 		
       
  4135 		aSettings.iWarnADHPNoMatchingPACPresent = ETrue;		
       
  4136 		
       
  4137 		// For no default server warning
       
  4138 		warn = view.ColUint(colSet->ColNo(KFASTWarnNotDefaultServer));
       
  4139 		if(warn == EFASTWarnNotDefaultServerNo)
       
  4140 		{
       
  4141 			aSettings.iWarnNotDefaultServer = EFalse;
       
  4142 		}
       
  4143 		else
       
  4144 		{
       
  4145 			aSettings.iWarnNotDefaultServer = ETrue;
       
  4146 		}
       
  4147 		
       
  4148 		aSettings.iWarnNotDefaultServerPresent = ETrue;
       
  4149 		
       
  4150 		// For PAC group reference.
       
  4151 		TPtrC pacGroupRef = view.ColDes(colSet->ColNo(KFASTPACGroupImportReferenceCollection));
       
  4152 		if(pacGroupRef.Length())
       
  4153 		{
       
  4154 			aSettings.iPACGroupReference.Copy(pacGroupRef);
       
  4155 			
       
  4156 			aSettings.iPACGroupReferencePresent = ETrue;
       
  4157 		}
       
  4158 		
       
  4159 		CleanupStack::PopAndDestroy(2); // view, colset		
       
  4160 				
       
  4161 	} // End: if(aEapType == eap_type_fast) 
       
  4162 
       
  4163 #endif //#ifdef USE_FAST_EAP_TYPE		
       
  4164 		
       
  4165 	
       
  4166 	//////////////////
       
  4167 	// Cipher suites
       
  4168 	//////////////////
       
  4169 	
       
  4170 	sqlStatement.Format(KSQL, &ciphersuites, 
       
  4171 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  4172 	
       
  4173 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
       
  4174 	
       
  4175 	CleanupClosePushL(view);
       
  4176 	
       
  4177 	User::LeaveIfError(view.EvaluateAll());	
       
  4178 		
       
  4179 	// Get column set so we get the correct column numbers
       
  4180 	colSet = view.ColSetL();
       
  4181 	CleanupStack::PushL(colSet);
       
  4182 
       
  4183 	if (view.FirstL())
       
  4184 	{		
       
  4185 		do {
       
  4186 			view.GetL();
       
  4187 			{				
       
  4188 				aSettings.iCipherSuites.Append(view.ColUint(colSet->ColNo(KCipherSuite)));
       
  4189 			}
       
  4190 		} while (view.NextL() != EFalse);
       
  4191 	}
       
  4192 	
       
  4193 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - Total cipher suites appended=%d \n"),aSettings.iCipherSuites.Count()) );
       
  4194 	
       
  4195 	aSettings.iCipherSuitesPresent = ETrue;
       
  4196 	
       
  4197 	CleanupStack::PopAndDestroy(2); // view, colset
       
  4198 	
       
  4199 	/////////////////
       
  4200 	// User Certificates
       
  4201 	/////////////////
       
  4202 
       
  4203 	sqlStatement.Format(KSQL, &usercerts, 
       
  4204 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  4205 	
       
  4206 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
       
  4207 	
       
  4208 	CleanupClosePushL(view);
       
  4209 	
       
  4210 	User::LeaveIfError(view.EvaluateAll());	
       
  4211 		
       
  4212 	// Get column set so we get the correct column numbers
       
  4213 	colSet = view.ColSetL();
       
  4214 	CleanupStack::PushL(colSet);
       
  4215 
       
  4216 	if (view.FirstL())
       
  4217 	{		
       
  4218 		do {
       
  4219 			view.GetL();
       
  4220 			{
       
  4221 				// This is big object.
       
  4222 				CertificateEntry * certEntry = new (ELeave) CertificateEntry;
       
  4223 				CleanupStack::PushL(certEntry);
       
  4224 
       
  4225 				certEntry->iCertType = CertificateEntry::EUser;
       
  4226 				
       
  4227 				certEntry->iSubjectName.Copy(view.ColDes(colSet->ColNo(KSubjectName)));
       
  4228 				if(certEntry->iSubjectName.Length())
       
  4229 				{
       
  4230 					certEntry->iSubjectNamePresent = ETrue;
       
  4231 				}
       
  4232 				
       
  4233 				certEntry->iIssuerName.Copy(view.ColDes(colSet->ColNo(KIssuerName)));
       
  4234 				if(certEntry->iIssuerName.Length())
       
  4235 				{
       
  4236 					certEntry->iIssuerNamePresent = ETrue;
       
  4237 				}
       
  4238 
       
  4239 				certEntry->iSerialNumber.Copy(view.ColDes(colSet->ColNo(KSerialNumber)));
       
  4240 				if(certEntry->iSerialNumber.Length())
       
  4241 				{
       
  4242 					certEntry->iSerialNumberPresent = ETrue;
       
  4243 				}
       
  4244 
       
  4245 				certEntry->iSubjectKeyID.Copy(view.ColDes8(colSet->ColNo(KActualSubjectKeyIdentifier))); // This is the subjectkey id we got in SetConfigurationL
       
  4246 				if(certEntry->iSubjectKeyID.Length())
       
  4247 				{
       
  4248 					certEntry->iSubjectKeyIDPresent = ETrue;
       
  4249 				}
       
  4250 
       
  4251 				certEntry->iThumbprint.Copy(view.ColDes8(colSet->ColNo(KThumbprint)));				
       
  4252 				if(certEntry->iThumbprint.Length())
       
  4253 				{
       
  4254 					certEntry->iThumbprintPresent = ETrue;
       
  4255 				}
       
  4256 
       
  4257 				aSettings.iCertificates.AppendL(*certEntry);
       
  4258 
       
  4259 				EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "EapTlsPeapUtils::GetConfigurationL - Filling User cert entry, SubjectKeyID:",
       
  4260 					certEntry->iSubjectKeyID.Ptr(), certEntry->iSubjectKeyID.Size() ) );
       
  4261 
       
  4262 				CleanupStack::PopAndDestroy(certEntry);
       
  4263 			}
       
  4264 		} while (view.NextL() != EFalse);
       
  4265 	}
       
  4266 	
       
  4267 	CleanupStack::PopAndDestroy(2); // view, colset
       
  4268 	
       
  4269 	/////////////////
       
  4270 	// CA Certificates
       
  4271 	/////////////////
       
  4272 
       
  4273 	sqlStatement.Format(KSQL, &cacerts, 
       
  4274 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  4275 	
       
  4276 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
       
  4277 	
       
  4278 	CleanupClosePushL(view);
       
  4279 	
       
  4280 	User::LeaveIfError(view.EvaluateAll());	
       
  4281 		
       
  4282 	// Get column set so we get the correct column numbers
       
  4283 	colSet = view.ColSetL();
       
  4284 	CleanupStack::PushL(colSet);
       
  4285 
       
  4286 	if (view.FirstL())
       
  4287 	{		
       
  4288 		do {
       
  4289 			view.GetL();
       
  4290 			{	
       
  4291 				// This is big object.
       
  4292 				CertificateEntry * certEntry = new (ELeave) CertificateEntry;
       
  4293 				CleanupStack::PushL(certEntry);
       
  4294 
       
  4295 				certEntry->iCertType = CertificateEntry::ECA;
       
  4296 				
       
  4297 				certEntry->iSubjectName.Copy(view.ColDes(colSet->ColNo(KSubjectName)));
       
  4298 				if(certEntry->iSubjectName.Length())
       
  4299 				{
       
  4300 					certEntry->iSubjectNamePresent = ETrue;
       
  4301 				}
       
  4302 				
       
  4303 				certEntry->iIssuerName.Copy(view.ColDes(colSet->ColNo(KIssuerName)));
       
  4304 				if(certEntry->iIssuerName.Length())
       
  4305 				{
       
  4306 					certEntry->iIssuerNamePresent = ETrue;
       
  4307 				}
       
  4308 
       
  4309 				certEntry->iSerialNumber.Copy(view.ColDes(colSet->ColNo(KSerialNumber)));
       
  4310 				if(certEntry->iSerialNumber.Length())
       
  4311 				{
       
  4312 					certEntry->iSerialNumberPresent = ETrue;
       
  4313 				}
       
  4314 
       
  4315 				certEntry->iSubjectKeyID.Copy(view.ColDes8(colSet->ColNo(KActualSubjectKeyIdentifier))); // This is the subjectkey id we got in SetConfigurationL
       
  4316 				if(certEntry->iSubjectKeyID.Length())
       
  4317 				{
       
  4318 					certEntry->iSubjectKeyIDPresent = ETrue;
       
  4319 				}
       
  4320 
       
  4321 				certEntry->iThumbprint.Copy(view.ColDes8(colSet->ColNo(KThumbprint)));				
       
  4322 				if(certEntry->iThumbprint.Length())
       
  4323 				{
       
  4324 					certEntry->iThumbprintPresent = ETrue;
       
  4325 				}
       
  4326 				
       
  4327 				aSettings.iCertificates.AppendL(*certEntry);
       
  4328 
       
  4329 				EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "EapTlsPeapUtils::GetConfigurationL - Filling CA cert entry, SubjectKeyID:",
       
  4330 					certEntry->iSubjectKeyID.Ptr(), certEntry->iSubjectKeyID.Size() ) );
       
  4331 
       
  4332 				CleanupStack::PopAndDestroy(certEntry);
       
  4333 			}
       
  4334 		} while (view.NextL() != EFalse);
       
  4335 	}
       
  4336 	
       
  4337 	CleanupStack::PopAndDestroy(3); // view, colset, buf
       
  4338 	
       
  4339 	aSettings.iCertificatesPresent = ETrue;
       
  4340 	
       
  4341 	EAP_TRACE_DEBUG_SYMBIAN((_L("**************** GetConfigurationL - Returning the below values: ***************\n")) );
       
  4342 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - Return these values for EAPType=%d"),aSettings.iEAPType) );
       
  4343 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, Username=%S"),aSettings.iUsernamePresent, &(aSettings.iUsername)) );
       
  4344 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, Password=%S"),aSettings.iPasswordPresent, &(aSettings.iPassword)) );
       
  4345 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, Realm=%S"),aSettings.iRealmPresent, &(aSettings.iRealm)) );
       
  4346 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, UsePseudonyms=%d"),aSettings.iUsePseudonymsPresent, aSettings.iUsePseudonyms) );
       
  4347 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, VerifyServerRealm=%d"),
       
  4348 						aSettings.iVerifyServerRealmPresent, aSettings.iVerifyServerRealm) );
       
  4349 
       
  4350 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, RequireClientAuthentication=%d"),
       
  4351 						aSettings.iRequireClientAuthenticationPresent, aSettings.iRequireClientAuthentication) );
       
  4352 						
       
  4353 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, SessionValidityTime=%d minutes"),
       
  4354 						aSettings.iSessionValidityTimePresent, aSettings.iSessionValidityTime) );
       
  4355 						
       
  4356 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, CipherSuites Count=%d"),
       
  4357 						aSettings.iCipherSuitesPresent, aSettings.iCipherSuites.Count()) );
       
  4358 	
       
  4359 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, PEAPv0Allowed=%d, PEAPv1Allowed=%d, PEAPv2Allowed=%d"),
       
  4360 						aSettings.iPEAPVersionsPresent, aSettings.iPEAPv0Allowed,aSettings.iPEAPv1Allowed, aSettings.iPEAPv2Allowed ) );
       
  4361 	
       
  4362 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, Certificates Count=%d"),
       
  4363 						aSettings.iCertificatesPresent, aSettings.iCertificates.Count()) );
       
  4364 						
       
  4365 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - Certificate details below: \n")) );
       
  4366 	for( TInt n=0; n < aSettings.iCertificates.Count(); n++ )
       
  4367 	{
       
  4368 		EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - Certificate type:%d \n"), aSettings.iCertificates[n].iCertType) );
       
  4369 		
       
  4370 		EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - certificates - present=%d, SubjectName=%S"),
       
  4371 						aSettings.iCertificates[n].iSubjectNamePresent, &(aSettings.iCertificates[n].iSubjectName)) );
       
  4372 						
       
  4373 		EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - certificates - present=%d, IssuerName=%S"),
       
  4374 						aSettings.iCertificates[n].iIssuerNamePresent, &(aSettings.iCertificates[n].iIssuerName)) );
       
  4375 						
       
  4376 		EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - certificates - present=%d, SerialNumber=%S"),
       
  4377 						aSettings.iCertificates[n].iSerialNumberPresent, &(aSettings.iCertificates[n].iSerialNumber)) );
       
  4378 						
       
  4379 		EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - certificates - SubjectKeyID present=%d"),
       
  4380 						aSettings.iCertificates[n].iSubjectKeyIDPresent ) );
       
  4381 						
       
  4382 		EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "SubjectKeyID:", aSettings.iCertificates[n].iSubjectKeyID.Ptr(), 
       
  4383 													aSettings.iCertificates[n].iSubjectKeyID.Size() ) );						
       
  4384 
       
  4385 		EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - certificates - Thumbprint present=%d"),
       
  4386 						aSettings.iCertificates[n].iThumbprintPresent ) );
       
  4387 						
       
  4388 		EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "Thumbprint:", aSettings.iCertificates[n].iThumbprint.Ptr(), 
       
  4389 													aSettings.iCertificates[n].iThumbprint.Size() ) );						
       
  4390 	}
       
  4391 	
       
  4392 #ifdef USE_FAST_EAP_TYPE		
       
  4393 
       
  4394 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, AuthProvModeAllowed=%d"),
       
  4395 						aSettings.iAuthProvModeAllowedPresent, aSettings.iAuthProvModeAllowed) );
       
  4396 
       
  4397 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, UnauthProvModeAllowed=%d"),
       
  4398 						aSettings.iUnauthProvModeAllowedPresent, aSettings.iUnauthProvModeAllowed) );
       
  4399 
       
  4400 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, WarnADHPNoPAC=%d"),
       
  4401 			aSettings.iWarnADHPNoPACPresent, aSettings.iWarnADHPNoPAC) );
       
  4402 
       
  4403 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, WarnADHPNoMatchingPAC=%d"),
       
  4404 			aSettings.iWarnADHPNoMatchingPACPresent, aSettings.iWarnADHPNoMatchingPAC) );
       
  4405 
       
  4406 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, WarnNotDefaultServer=%d"),
       
  4407 			aSettings.iWarnNotDefaultServerPresent, aSettings.iWarnNotDefaultServer) );
       
  4408 	
       
  4409 	EAP_TRACE_DEBUG_SYMBIAN((_L("GetConfigurationL - present=%d, PAC Group Ref=%S"),
       
  4410 						aSettings.iPACGroupReferencePresent, &(aSettings.iPACGroupReference)) );
       
  4411 
       
  4412 #endif //#ifdef USE_FAST_EAP_TYPE		
       
  4413 					
       
  4414 	EAP_TRACE_DEBUG_SYMBIAN((_L("**************** GetConfigurationL - Returning the above values: ***************\n")) );
       
  4415 
       
  4416 	
       
  4417 	//////////////////////	
       
  4418 	// Encapsulated types
       
  4419 	//////////////////////
       
  4420 	
       
  4421 	// Encapsulated types are only for EAP-PEAP, EAP-TTLS and EAP-FAST. Not for EAP-TLS.
       
  4422 	if ( aEapType != eap_type_peap 
       
  4423 		 && aEapType != eap_type_ttls
       
  4424 #ifdef USE_FAST_EAP_TYPE
       
  4425 		 && aEapType != eap_type_fast
       
  4426 #endif		 
       
  4427 		 )
       
  4428 	{
       
  4429 		aSettings.iEncapsulatedEAPTypesPresent = EFalse;
       
  4430 		
       
  4431 		EAP_TRACE_DEBUG_SYMBIAN(
       
  4432 			(_L("EapTlsPeapUtils::GetConfigurationL - End - Since no encapsulated type for the EAPType =%d \n"),
       
  4433 			aEapVendorType));
       
  4434 		
       
  4435 		return; // No need to proceed. Nothing more to provide.
       
  4436 	}
       
  4437 		
       
  4438 #ifdef USE_EAP_EXPANDED_TYPES
       
  4439 
       
  4440 	RExpandedEapTypePtrArray enabledEAPTypes;
       
  4441 	RExpandedEapTypePtrArray disabledEAPTypes;
       
  4442 	
       
  4443 	TRAPD(error, GetTunnelingExpandedEapDataL(
       
  4444 			aDatabase, 
       
  4445 			0, 
       
  4446 			enabledEAPTypes,
       
  4447 			disabledEAPTypes, 
       
  4448 			aIndexType,
       
  4449 			aIndex,
       
  4450 			aTunnelingType,
       
  4451 			aEapType));
       
  4452 			
       
  4453 		if( error != KErrNone )
       
  4454 		{
       
  4455 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - ########### Getting Expanded Tunneling types from the DB failed ############ \n") ) );
       
  4456 
       
  4457 			enabledEAPTypes.ResetAndDestroy();
       
  4458 			disabledEAPTypes.ResetAndDestroy();
       
  4459 			enabledEAPTypes.Close();
       
  4460 			disabledEAPTypes.Close();
       
  4461 
       
  4462 			User::Leave(KErrGeneral);
       
  4463 		}
       
  4464 
       
  4465 	// There should be some enabled EAP types (atleast one).
       
  4466 	if (enabledEAPTypes.Count() == 0)
       
  4467 	{
       
  4468 		// Nothing enabled. Some problem. 
       
  4469 		// We should get all the available EAP plugins on the device and make them enabled as default.
       
  4470 		
       
  4471 		RImplInfoPtrArray eapImplArray;
       
  4472 
       
  4473 		TRAP(error, REComSession::ListImplementationsL(KEapTypeInterfaceUid, eapImplArray));
       
  4474 		if (error != KErrNone)
       
  4475 		{
       
  4476 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - ########### Getting Expanded Tunneling types - Listing ECOM plugins failed ############ \n") ) );
       
  4477 
       
  4478 			enabledEAPTypes.ResetAndDestroy();
       
  4479 			disabledEAPTypes.ResetAndDestroy();
       
  4480 			enabledEAPTypes.Close();
       
  4481 			disabledEAPTypes.Close();
       
  4482 
       
  4483 			User::Leave(KErrNotFound);
       
  4484 		}
       
  4485 		
       
  4486 		EAP_TRACE_DEBUG_SYMBIAN(
       
  4487 			(_L("GetConfigurationL - ListImplementationsL - No: of available EAP plugin implementations=%d \n"),
       
  4488 		 	eapImplArray.Count() ) );
       
  4489 		
       
  4490 		SExpandedEAPType* expandedEAPTmp;
       
  4491 		
       
  4492 		// Add the EAP types to enabledEAPTypes array now.
       
  4493 		
       
  4494 		for (TInt i = 0; i < eapImplArray.Count(); i++)
       
  4495 		{		
       
  4496 			if (aEapType == eap_type_peap)
       
  4497 			{
       
  4498 				// Some EAP types are not allowed inside EAP-PEAP.
       
  4499 				if (CEapType::IsDisallowedInsidePEAP(*eapImplArray[i]))
       
  4500 				{			
       
  4501 					continue;	
       
  4502 				}
       
  4503 				
       
  4504 				expandedEAPTmp = new SExpandedEAPType;
       
  4505 				if (expandedEAPTmp == 0)
       
  4506 				{
       
  4507 					enabledEAPTypes.ResetAndDestroy();
       
  4508 					disabledEAPTypes.ResetAndDestroy();
       
  4509 					enabledEAPTypes.Close();
       
  4510 					disabledEAPTypes.Close();
       
  4511 
       
  4512 					eapImplArray.ResetAndDestroy();
       
  4513 					eapImplArray.Close();				
       
  4514 
       
  4515 					User::Leave(KErrNoMemory);				
       
  4516 				}
       
  4517 				
       
  4518 				CleanupStack::PushL(expandedEAPTmp);
       
  4519 				
       
  4520 				expandedEAPTmp->iExpandedEAPType.Copy(eapImplArray[i]->DataType());
       
  4521 
       
  4522 				enabledEAPTypes.Append(expandedEAPTmp);				
       
  4523 				
       
  4524 				CleanupStack::Pop(expandedEAPTmp);
       
  4525 			}
       
  4526 
       
  4527 			if (aEapType == eap_type_ttls)
       
  4528 			{
       
  4529 				// Some EAP types are not allowed inside EAP-TTLS.
       
  4530 				if (CEapType::IsDisallowedInsideTTLS(*eapImplArray[i]))
       
  4531 				{			
       
  4532 					continue;	
       
  4533 				}
       
  4534 				
       
  4535 				expandedEAPTmp = new SExpandedEAPType;
       
  4536 				if (expandedEAPTmp == 0)
       
  4537 				{
       
  4538 					enabledEAPTypes.ResetAndDestroy();
       
  4539 					disabledEAPTypes.ResetAndDestroy();
       
  4540 					enabledEAPTypes.Close();
       
  4541 					disabledEAPTypes.Close();
       
  4542 
       
  4543 					eapImplArray.ResetAndDestroy();
       
  4544 					eapImplArray.Close();				
       
  4545 
       
  4546 					User::Leave(KErrNoMemory);				
       
  4547 				}
       
  4548 				
       
  4549 				CleanupStack::PushL(expandedEAPTmp);
       
  4550 				
       
  4551 				expandedEAPTmp->iExpandedEAPType.Copy(eapImplArray[i]->DataType());
       
  4552 
       
  4553 				enabledEAPTypes.Append(expandedEAPTmp);				
       
  4554 				
       
  4555 				CleanupStack::Pop(expandedEAPTmp);
       
  4556 			}
       
  4557 
       
  4558 #ifdef USE_FAST_EAP_TYPE
       
  4559 
       
  4560 			if (aEapType == eap_type_fast)
       
  4561 			{
       
  4562 				// Some EAP types are not allowed inside EAP-FAST.
       
  4563 				if (CEapType::IsDisallowedInsidePEAP(*eapImplArray[i]))
       
  4564 				{			
       
  4565 					continue;	
       
  4566 				}
       
  4567 				
       
  4568 				expandedEAPTmp = new SExpandedEAPType;
       
  4569 				if (expandedEAPTmp == 0)
       
  4570 				{
       
  4571 					enabledEAPTypes.ResetAndDestroy();
       
  4572 					disabledEAPTypes.ResetAndDestroy();
       
  4573 					enabledEAPTypes.Close();
       
  4574 					disabledEAPTypes.Close();
       
  4575 
       
  4576 					eapImplArray.ResetAndDestroy();
       
  4577 					eapImplArray.Close();				
       
  4578 
       
  4579 					User::Leave(KErrNoMemory);				
       
  4580 				}
       
  4581 				
       
  4582 				CleanupStack::PushL(expandedEAPTmp);
       
  4583 				
       
  4584 				expandedEAPTmp->iExpandedEAPType.Copy(eapImplArray[i]->DataType());
       
  4585 
       
  4586 				enabledEAPTypes.Append(expandedEAPTmp);				
       
  4587 				
       
  4588 				CleanupStack::Pop(expandedEAPTmp);
       
  4589 			}
       
  4590 #endif // #ifdef USE_FAST_EAP_TYPE
       
  4591 
       
  4592 		} // End: for (TInt i = 0; i < eapImplArray.Count(); i++)
       
  4593 		
       
  4594 		eapImplArray.ResetAndDestroy();
       
  4595 		eapImplArray.Close();
       
  4596 							
       
  4597 	} // End: if (enabledEAPTypes.Count() == 0)
       
  4598 
       
  4599 	EAP_TRACE_DEBUG_SYMBIAN(
       
  4600 		(_L("EapTlsPeapUtils::GetConfigurationL - No: of available tunneled types for this EAP=%d \n"),
       
  4601 		enabledEAPTypes.Count()));
       
  4602 
       
  4603 	// enabledEAPTypes contains the EAP types now (expanded).
       
  4604 	// Fill aSettings.iEncapsulatedEAPTypes here.
       
  4605 	
       
  4606 	for (TInt i = 0; i < enabledEAPTypes.Count(); i++)
       
  4607 	{
       
  4608 		eap_expanded_type_c expEAPTmp;
       
  4609 		
       
  4610 		// This will read the expanded EAP from enabledEAPTypes[i]->iExpandedEAPType to expEAPTmp.
       
  4611 		// This makes easy to get the vendor type.
       
  4612 		eap_expanded_type_c::read_type( 0,
       
  4613 										0,
       
  4614 										enabledEAPTypes[i]->iExpandedEAPType.Ptr(),
       
  4615 										KExpandedEAPTypeSize,
       
  4616 										&expEAPTmp);
       
  4617 	
       
  4618 		// We need to fill only the vendor type to aSettings.iEncapsulatedEAPTypes
       
  4619 		aSettings.iEncapsulatedEAPTypes.Append(expEAPTmp.get_vendor_type());
       
  4620 		
       
  4621 		EAP_TRACE_DEBUG_SYMBIAN(
       
  4622 			(_L("EapTlsPeapUtils::GetConfigurationL - Available encapsulated type for this EAP(%d)=%d\n"),
       
  4623 			aEapVendorType, expEAPTmp.get_vendor_type()));
       
  4624 	}
       
  4625 	
       
  4626 	EAP_TRACE_DEBUG_SYMBIAN(
       
  4627 		(_L("EapTlsPeapUtils::GetConfigurationL - aSettings.iEncapsulatedEAPTypes.Count()=%d \n"),
       
  4628 		aSettings.iEncapsulatedEAPTypes.Count()));
       
  4629 
       
  4630 	enabledEAPTypes.ResetAndDestroy();
       
  4631 	disabledEAPTypes.ResetAndDestroy();
       
  4632 	enabledEAPTypes.Close();
       
  4633 	disabledEAPTypes.Close();
       
  4634 
       
  4635 	aSettings.iEncapsulatedEAPTypesPresent = ETrue;
       
  4636 
       
  4637 #else // for Normal EAP types.
       
  4638 			
       
  4639 	TEapArray eapArray;
       
  4640 		
       
  4641 	TRAPD(err, GetEapDataL(
       
  4642 		aDatabase,
       
  4643 		0,
       
  4644 		eapArray, 
       
  4645 		aIndexType,
       
  4646 		aIndex,
       
  4647 		aTunnelingType,	
       
  4648 		aEapType));
       
  4649 	if (err != KErrNone)
       
  4650 	{
       
  4651 		eapArray.ResetAndDestroy();
       
  4652 		eapArray.Close();
       
  4653 		User::Leave(KErrGeneral);
       
  4654 	}
       
  4655 	
       
  4656 	RImplInfoPtrArray eapImplArray;
       
  4657 	
       
  4658 	if (eapArray.Count() == 0)
       
  4659 	{
       
  4660 		// The array was empty. By default all types are enabled.
       
  4661 		TRAP(err, REComSession::ListImplementationsL(KEapTypeInterfaceUid, eapImplArray));
       
  4662 		if (err != KErrNone)
       
  4663 		{
       
  4664 			eapArray.ResetAndDestroy();
       
  4665 			eapArray.Close();
       
  4666 			User::Leave(KErrGeneral);
       
  4667 		}
       
  4668 		
       
  4669 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - ListImplementationsL - No: of available implementations=%d \n"), eapImplArray.Count() ) );
       
  4670 		
       
  4671 		TEap *eap;
       
  4672 		for (TInt i = 0; i < eapImplArray.Count(); i++)
       
  4673 		{
       
  4674 			if (CEapType::IsDisallowedInsidePEAP(*eapImplArray[i]))
       
  4675 			{			
       
  4676 				continue;	
       
  4677 			}
       
  4678 			
       
  4679 			eap = new TEap;
       
  4680 			if (eap == 0)
       
  4681 			{
       
  4682 				eapArray.ResetAndDestroy();
       
  4683 				eapArray.Close();
       
  4684 				eapImplArray.ResetAndDestroy();
       
  4685 				eapImplArray.Close();				
       
  4686 				User::Leave(KErrGeneral);				
       
  4687 			}
       
  4688 			eap->UID.Copy(eapImplArray[i]->DataType());
       
  4689 			eap->Enabled = ETrue;
       
  4690 			eapArray.Append(eap);
       
  4691 		}	
       
  4692 	}
       
  4693 
       
  4694 	TInt i(0);
       
  4695 
       
  4696 	for (i = 0; i < eapArray.Count(); i++)
       
  4697 	{
       
  4698 		if (eapArray[i]->Enabled)
       
  4699 		{
       
  4700 			TLex8 tmp(eapArray[i]->UID);
       
  4701 			TUint val(0);
       
  4702 			tmp.Val(val);
       
  4703 			aSettings.iEncapsulatedEAPTypes.Append(val);
       
  4704 
       
  4705 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - Available encapsulated type for this EAP =%d \n"), val ) );
       
  4706 		}	
       
  4707 	}
       
  4708 	
       
  4709 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - eapArray.Count()=%d \n"),eapArray.Count() ) );
       
  4710 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - aSettings.iEncapsulatedEAPTypes.Count()=%d \n"),aSettings.iEncapsulatedEAPTypes.Count() ) );	
       
  4711 
       
  4712 	eapArray.ResetAndDestroy();
       
  4713 	eapArray.Close();
       
  4714 	eapImplArray.ResetAndDestroy();
       
  4715 	eapImplArray.Close();				
       
  4716 		
       
  4717 	aSettings.iEncapsulatedEAPTypesPresent = ETrue;
       
  4718 	
       
  4719 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  4720 	
       
  4721 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::GetConfigurationL - End \n") ) );	
       
  4722 
       
  4723 } // EapTlsPeapUtils::GetConfigurationL()
       
  4724 
       
  4725 
       
  4726 void EapTlsPeapUtils::CopySettingsL(
       
  4727 	RDbNamedDatabase& aDatabase,
       
  4728 	const TDesC& aTableName,
       
  4729 	const TIndexType aSrcIndexType,
       
  4730 	const TInt aSrcIndex,
       
  4731 	const eap_type_value_e aSrcTunnelingType,
       
  4732 	const TIndexType aDestIndexType,
       
  4733 	const TInt aDestIndex,
       
  4734 	const eap_type_value_e aDestTunnelingType)
       
  4735 {
       
  4736 #ifdef USE_EAP_EXPANDED_TYPES
       
  4737 
       
  4738 	TUint aSrcTunnelingVendorType = aSrcTunnelingType.get_vendor_type();
       
  4739 	TUint aDestTunnelingVendorType = aDestTunnelingType.get_vendor_type();
       
  4740 
       
  4741 #else
       
  4742 
       
  4743 	TUint aSrcTunnelingVendorType = static_cast<TUint>(aSrcTunnelingType);
       
  4744 	TUint aDestTunnelingVendorType = static_cast<TUint>(aDestTunnelingType);
       
  4745 
       
  4746 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  4747 
       
  4748     EAP_TRACE_DEBUG_SYMBIAN(
       
  4749         (_L("EapTlsPeapUtils::CopySettingsL table=%s, aSrcIndexType=%d, aDestIndexType=%d, aSrcIndex=%d, aDestIndex=%d, SrcTunneling vendor type=%d, DestTunneling vendor type=%d \n"),
       
  4750                 aTableName.Ptr(), aSrcIndexType, aDestIndexType, aSrcIndex, aDestIndex, aSrcTunnelingVendorType, aDestTunnelingVendorType));
       
  4751 
       
  4752 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  4753 	TPtr sqlStatement = buf->Des();
       
  4754 
       
  4755 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  4756 
       
  4757 	sqlStatement.Format(KSQL, &aTableName, 
       
  4758 		&KServiceType, aDestIndexType, &KServiceIndex, aDestIndex, &KTunnelingType, aDestTunnelingVendorType);
       
  4759 	
       
  4760 	RDbView view;
       
  4761 	
       
  4762 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EUpdatable));
       
  4763 	
       
  4764 	// View must be closed when no longer needed
       
  4765 	CleanupClosePushL(view);
       
  4766 	
       
  4767 	User::LeaveIfError(view.EvaluateAll());
       
  4768 
       
  4769 	// Get column set so we get the correct column numbers
       
  4770 	CDbColSet* colSet = view.ColSetL();
       
  4771 	CleanupStack::PushL(colSet);
       
  4772 
       
  4773   if (view.FirstL())
       
  4774   	{       
       
  4775   	do 
       
  4776   		{
       
  4777   		view.GetL();
       
  4778 			if (view.ColUint(colSet->ColNo(KServiceType)) == static_cast<TUint>(aDestIndexType)
       
  4779 				&& view.ColUint(colSet->ColNo(KServiceIndex)) == static_cast<TUint>(aDestIndex)
       
  4780 				&& view.ColUint(colSet->ColNo(KTunnelingType)) == aDestTunnelingVendorType)
       
  4781 				{  		
       
  4782       			EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::CopySettingsL - Delete old records\n") ) );
       
  4783       			view.DeleteL();
       
  4784     			}
       
  4785       		} while (view.NextL() != EFalse);
       
  4786   		}
       
  4787 	
       
  4788 	view.Close();
       
  4789 	CleanupStack::PopAndDestroy(2); // view, colset
       
  4790 	
       
  4791   	sqlStatement.Format(KSQL, &aTableName, 
       
  4792         &KServiceType, aSrcIndexType, &KServiceIndex, aSrcIndex, &KTunnelingType, aSrcTunnelingVendorType);
       
  4793 
       
  4794   	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited , RDbView::EUpdatable));
       
  4795 
       
  4796 	// View must be closed when no longer needed
       
  4797 	CleanupClosePushL(view);
       
  4798 
       
  4799   	User::LeaveIfError(view.EvaluateAll());
       
  4800 
       
  4801 	// Get column set so we get the correct column numbers
       
  4802 	colSet = view.ColSetL();
       
  4803 	CleanupStack::PushL(colSet);
       
  4804 			
       
  4805 	TDbBookmark bookmark;
       
  4806 
       
  4807 	if (view.FirstL())
       
  4808 	{		
       
  4809 		do {
       
  4810 			// Get the next line
       
  4811 			view.GetL();
       
  4812 
       
  4813 			// Check if it was already copied			
       
  4814 			if (view.ColUint(colSet->ColNo(KServiceType)) != static_cast<TUint>(aDestIndexType)
       
  4815 				|| view.ColUint(colSet->ColNo(KServiceIndex)) != static_cast<TUint>(aDestIndex)
       
  4816 				|| view.ColUint(colSet->ColNo(KTunnelingType)) != aDestTunnelingVendorType)
       
  4817 			{
       
  4818 				bookmark = view.Bookmark();
       
  4819 				
       
  4820 				view.InsertCopyL();
       
  4821 				
       
  4822 				view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aDestIndexType));
       
  4823     
       
  4824 	    		view.SetColL(colSet->ColNo(KServiceIndex), static_cast<TUint>(aDestIndex));
       
  4825 
       
  4826 	    		view.SetColL(colSet->ColNo(KTunnelingType), aDestTunnelingVendorType);
       
  4827 				
       
  4828 				view.PutL();
       
  4829 			
       
  4830 				view.GotoL(bookmark);
       
  4831 			}
       
  4832 		} while (view.NextL() != EFalse);
       
  4833 	}
       
  4834 	else
       
  4835 		{
       
  4836 		EAP_TRACE_DEBUG_SYMBIAN(
       
  4837 			(_L("EapTlsPeapUtils::CopySettingsL - Nothing to Copy\n")));
       
  4838 		
       
  4839 		}
       
  4840 	
       
  4841 	view.Close();
       
  4842 	
       
  4843 	CleanupStack::PopAndDestroy(3); // view, colset, buf
       
  4844 
       
  4845 } // EapTlsPeapUtils::CopySettingsL()
       
  4846 
       
  4847 
       
  4848 // ---------------------------------------------------------
       
  4849 // EapTlsPeapUtils::DeleteConfigurationL()
       
  4850 // ---------------------------------------------------------
       
  4851 //
       
  4852 void EapTlsPeapUtils::DeleteConfigurationL(	
       
  4853 	const TIndexType aIndexType,
       
  4854 	const TInt aIndex,
       
  4855 	const eap_type_value_e aTunnelingType,
       
  4856 	const eap_type_value_e aEapType)
       
  4857 {
       
  4858 #ifdef USE_EAP_EXPANDED_TYPES
       
  4859 
       
  4860 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  4861 	TUint aEapVendorType = aEapType.get_vendor_type();
       
  4862 
       
  4863 #else
       
  4864 
       
  4865 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  4866 	TUint aEapVendorType = static_cast<TUint>(aEapType);
       
  4867 
       
  4868 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  4869 	
       
  4870 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::DeleteConfigurationL:Start:aIndexType=%d,aIndex=%d,aTunnelingVendorType=%d,aEapVendorType=%d"),
       
  4871 			aIndexType, aIndex, aTunnelingVendorType, aEapVendorType));
       
  4872 	
       
  4873 	TPtrC dbname;
       
  4874 	TPtrC settings;
       
  4875 	TPtrC usercerts;
       
  4876 	TPtrC cacerts;
       
  4877 	TPtrC ciphersuites;
       
  4878 
       
  4879 #ifdef USE_FAST_EAP_TYPE
       
  4880 	TPtrC fastSpecialSettings;
       
  4881 #endif
       
  4882 	
       
  4883 	switch (aEapVendorType)
       
  4884 	{
       
  4885 	case eap_type_tls:
       
  4886 		{
       
  4887 			dbname.Set(KTlsDatabaseName);
       
  4888 			settings.Set(KTlsDatabaseTableName);
       
  4889 			usercerts.Set(KTlsAllowedUserCertsDatabaseTableName);
       
  4890 			cacerts.Set(KTlsAllowedCACertsDatabaseTableName);
       
  4891 			ciphersuites.Set(KTlsAllowedCipherSuitesDatabaseTableName);
       
  4892 		}
       
  4893 		break;
       
  4894 
       
  4895 	case eap_type_peap:
       
  4896 		{
       
  4897 			dbname.Set(KPeapDatabaseName);
       
  4898 			settings.Set(KPeapDatabaseTableName);
       
  4899 			usercerts.Set(KPeapAllowedUserCertsDatabaseTableName);
       
  4900 			cacerts.Set(KPeapAllowedCACertsDatabaseTableName);
       
  4901 			ciphersuites.Set(KPeapAllowedCipherSuitesDatabaseTableName);
       
  4902 		}
       
  4903 		break;
       
  4904 
       
  4905 	case eap_type_ttls:
       
  4906 		{
       
  4907 			dbname.Set(KTtlsDatabaseName);
       
  4908 			settings.Set(KTtlsDatabaseTableName);
       
  4909 			usercerts.Set(KTtlsAllowedUserCertsDatabaseTableName);
       
  4910 			cacerts.Set(KTtlsAllowedCACertsDatabaseTableName);
       
  4911 			ciphersuites.Set(KTtlsAllowedCipherSuitesDatabaseTableName);
       
  4912 		}
       
  4913 		break;
       
  4914 
       
  4915 #ifdef USE_FAST_EAP_TYPE
       
  4916 
       
  4917 	case eap_type_fast:
       
  4918 		{
       
  4919 			dbname.Set(KFastDatabaseName);
       
  4920 			settings.Set(KFastGeneralSettingsDBTableName); // This is general settings for FAST.
       
  4921 			fastSpecialSettings.Set(KFastSpecialSettingsDBTableName);
       
  4922 			
       
  4923 			usercerts.Set(KFastAllowedUserCertsDatabaseTableName);
       
  4924 			cacerts.Set(KFastAllowedCACertsDatabaseTableName);
       
  4925 			ciphersuites.Set(KFastAllowedCipherSuitesDatabaseTableName);
       
  4926 		}
       
  4927 		break;
       
  4928 #endif
       
  4929 
       
  4930 	case eap_type_ttls_plain_pap:
       
  4931 		{
       
  4932 			dbname.Set( KTtlsDatabaseName );
       
  4933 			settings.Set( KTtlsDatabaseTableName );
       
  4934 		}
       
  4935 	break;
       
  4936 	
       
  4937 	default:
       
  4938 		// Should never happen
       
  4939 		User::Leave(KErrArgument);
       
  4940 	}	
       
  4941 
       
  4942 	RDbs session;
       
  4943 	RDbNamedDatabase database;
       
  4944 	
       
  4945 	// Connect to the DBMS server.
       
  4946 	User::LeaveIfError(session.Connect());
       
  4947 	CleanupClosePushL(session);	
       
  4948 		
       
  4949 #ifdef SYMBIAN_SECURE_DBMS
       
  4950 	
       
  4951 	// Create the secure shared database with the specified secure policy.
       
  4952 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
       
  4953 	
       
  4954 	TInt err = database.Create(session, dbname, KSecureUIDFormat);
       
  4955 	
       
  4956 	if(err == KErrNone)
       
  4957 	{
       
  4958 		// Database was created so it was empty. No need for further actions.
       
  4959 		database.Destroy();
       
  4960 		CleanupStack::PopAndDestroy();
       
  4961 		return;
       
  4962 		
       
  4963 	} 
       
  4964 	else if (err != KErrAlreadyExists) 
       
  4965 	{
       
  4966 		User::LeaveIfError(err);
       
  4967 	}
       
  4968 	
       
  4969 	// Database existed, open it.
       
  4970 	User::LeaveIfError(database.Open(session, dbname, KSecureUIDFormat));
       
  4971 	CleanupClosePushL(database);
       
  4972 		
       
  4973 #else
       
  4974 	// For non-secured database. The database will be created in the old location (c:\system\data).
       
  4975 	
       
  4976 	RFs fsSession;		
       
  4977 	User::LeaveIfError(fsSession.Connect());
       
  4978 	CleanupClosePushL(fsSession);	
       
  4979 	TInt err = database.Create(fsSession, dbname);
       
  4980 
       
  4981 	if(err == KErrNone)
       
  4982 	{
       
  4983 		// Database was created so it was empty. No need for further actions.
       
  4984 		database.Destroy();
       
  4985 		CleanupStack::PopAndDestroy(2); // fsSession, database session
       
  4986 		return;
       
  4987 		
       
  4988 	} 
       
  4989 	else if (err != KErrAlreadyExists) 
       
  4990 	{
       
  4991 		User::LeaveIfError(err);
       
  4992 	}
       
  4993 	
       
  4994 	CleanupStack::PopAndDestroy(); // close fsSession
       
  4995 	
       
  4996 	User::LeaveIfError(database.Open(session, dbname));
       
  4997 	CleanupClosePushL(database);		
       
  4998 	    
       
  4999 #endif // #ifdef SYMBIAN_SECURE_DBMS
       
  5000 
       
  5001 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  5002 	TPtr sqlStatement = buf->Des();
       
  5003 
       
  5004 	EAP_TRACE_DEBUG_SYMBIAN(
       
  5005 		(_L("EapTlsPeapUtils::DeleteConfigurationL - Deleting the tables\n")));
       
  5006 
       
  5007 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
  5008 	
       
  5009 	//--------------------- Deletion 1 ----------------------------//
       
  5010 	
       
  5011 	// For all EAPs delete the settings table. 
       
  5012 	// For EAP-FAST, this is delting the general settings table.
       
  5013 	
       
  5014 	sqlStatement.Format(KSQL, &settings, 
       
  5015 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  5016 	
       
  5017 	// Evaluate view
       
  5018 	RDbView view;
       
  5019 	User::LeaveIfError(view.Prepare(database,TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  5020 	CleanupClosePushL(view);
       
  5021 	User::LeaveIfError(view.EvaluateAll());
       
  5022 
       
  5023 	// Delete rows
       
  5024 	if (view.FirstL())
       
  5025 	{		
       
  5026 		do {
       
  5027 			view.DeleteL();
       
  5028 		} while (view.NextL() != EFalse);
       
  5029 	}
       
  5030 	
       
  5031 	CleanupStack::PopAndDestroy(); // view
       
  5032 	
       
  5033 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::DeleteConfigurationL: Deleted %s (general) settings table"), settings.Ptr()));	
       
  5034 
       
  5035 	//////////////////////////////////////////
       
  5036 	// This is only for plain PAP settings. //
       
  5037 	//////////////////////////////////////////
       
  5038 	if ( aEapVendorType == eap_type_ttls_plain_pap )
       
  5039 		{
       
  5040         CleanupStack::PopAndDestroy(3); // buf, database, session
       
  5041         EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::DeleteConfigurationL: Return")));	
       
  5042         // we return here in case of pap because there is nothing to do else.
       
  5043         return;
       
  5044 		}
       
  5045 	
       
  5046 	//--------------------- Deletion 2 ----------------------------//
       
  5047 	
       
  5048 	// For all EAPs delte the User cert table
       
  5049 
       
  5050 //	KSQL2 is "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"
       
  5051 	
       
  5052 	sqlStatement.Format(KSQL, &usercerts, 
       
  5053 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  5054 
       
  5055 	// Evaluate view
       
  5056 	
       
  5057 	User::LeaveIfError(view.Prepare(database,TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  5058 	CleanupClosePushL(view);
       
  5059 	User::LeaveIfError(view.EvaluateAll());
       
  5060 	
       
  5061 	if (view.FirstL())
       
  5062 	{		
       
  5063 		do {
       
  5064 			view.DeleteL();
       
  5065 		} while (view.NextL() != EFalse);
       
  5066 	}
       
  5067 
       
  5068 	CleanupStack::PopAndDestroy(); // view
       
  5069 
       
  5070 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::DeleteConfigurationL: Deleted USER certs table")));	
       
  5071 
       
  5072 	//--------------------- Deletion 3 ----------------------------//
       
  5073 	
       
  5074 	// For all EAPs delete the CA cert table
       
  5075 
       
  5076 //	KSQL3 is "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"
       
  5077 	
       
  5078 	sqlStatement.Format(KSQL, &cacerts, 
       
  5079 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  5080 	
       
  5081 	// Evaluate view
       
  5082 	
       
  5083 	User::LeaveIfError(view.Prepare(database,TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  5084 	CleanupClosePushL(view);
       
  5085 	User::LeaveIfError(view.EvaluateAll());
       
  5086 	
       
  5087 	if (view.FirstL())
       
  5088 	{		
       
  5089 		do {
       
  5090 			view.DeleteL();
       
  5091 		} while (view.NextL() != EFalse);
       
  5092 	}
       
  5093 
       
  5094 	CleanupStack::PopAndDestroy(); // view
       
  5095 
       
  5096 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::DeleteConfigurationL: Deleted CA certs table")));
       
  5097 
       
  5098 	//--------------------- Deletion 4 ----------------------------//
       
  5099 	
       
  5100 	// For all EAPs delete the Cipher suite table
       
  5101 
       
  5102 //	KSQL4 is "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"
       
  5103 	
       
  5104 	sqlStatement.Format(KSQL, &ciphersuites, 
       
  5105 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  5106 
       
  5107 	// Evaluate view
       
  5108 	
       
  5109 	User::LeaveIfError(view.Prepare(database,TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  5110 	CleanupClosePushL(view);
       
  5111 	User::LeaveIfError(view.EvaluateAll());
       
  5112 	
       
  5113 	if (view.FirstL())
       
  5114 	{		
       
  5115 		do {
       
  5116 			view.DeleteL();
       
  5117 		} while (view.NextL() != EFalse);
       
  5118 	}
       
  5119 	
       
  5120 	CleanupStack::PopAndDestroy(&view); // Close view
       
  5121 		
       
  5122 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::DeleteConfigurationL: Deleted cipher suits table")));	
       
  5123 
       
  5124 	
       
  5125 #ifdef USE_FAST_EAP_TYPE	
       
  5126 
       
  5127 	if(aEapVendorType == eap_type_fast)
       
  5128 	{
       
  5129 		//--------------------- Deletion 5 ----------------------------//
       
  5130 		
       
  5131 		// For EAP-FAST, delete the special settings table
       
  5132 		
       
  5133 		sqlStatement.Format(KSQL, &fastSpecialSettings, 
       
  5134 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
       
  5135 	
       
  5136 		// Evaluate view
       
  5137 		
       
  5138 		User::LeaveIfError(view.Prepare(database,TDbQuery(sqlStatement), TDbWindow::EUnlimited));
       
  5139 		CleanupClosePushL(view);
       
  5140 		User::LeaveIfError(view.EvaluateAll());
       
  5141 		
       
  5142 		if (view.FirstL())
       
  5143 		{		
       
  5144 			do {
       
  5145 				view.DeleteL();
       
  5146 			} while (view.NextL() != EFalse);
       
  5147 		}
       
  5148 		
       
  5149 		CleanupStack::PopAndDestroy(&view); // Close view
       
  5150 			
       
  5151 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::DeleteConfigurationL: Deleted EAP-FAST Special settings table")));	
       
  5152 				
       
  5153 	} // End: if(aEapVendorType == eap_type_fast)
       
  5154 
       
  5155 #endif // End: #ifdef USE_FAST_EAP_TYPE	
       
  5156 	
       
  5157 	// Close database
       
  5158 	CleanupStack::PopAndDestroy(3); // buf, database, session
       
  5159 	
       
  5160 EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::DeleteConfigurationL: End")));	
       
  5161 
       
  5162 } // EapTlsPeapUtils::DeleteConfigurationL()
       
  5163 
       
  5164 
       
  5165 // ---------------------------------------------------------
       
  5166 // EapTlsPeapUtils::AddExtraCertColumnsL()
       
  5167 // ---------------------------------------------------------
       
  5168 //
       
  5169 void EapTlsPeapUtils::AddExtraCertColumnsL(
       
  5170 	RDbNamedDatabase& aDatabase, 
       
  5171 	TDesC& aTableName)
       
  5172 {
       
  5173 	// Check if the EXTRA cert columns are already in the table.
       
  5174 	
       
  5175 	CDbColSet* colSetCertTable = aDatabase.ColSetL(aTableName);
       
  5176 	User::LeaveIfNull(colSetCertTable);
       
  5177 	CleanupStack::PushL(colSetCertTable);	
       
  5178 	
       
  5179 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::AddExtraCertColumnsL - Number of columns in %S table before addition=%d\n"),
       
  5180 	&aTableName, colSetCertTable->Count()));
       
  5181 		
       
  5182 	// Check if there is a column for Serial Number, for example.
       
  5183 	if(colSetCertTable->ColNo(KSerialNumber) == KDbNullColNo)
       
  5184 	{
       
  5185 		// The column is missing. Add all the EXTRA columns to the table.
       
  5186 
       
  5187 		// EXTRA COLUMNS
       
  5188 		//// NAME //////////////// TYPE //////////// Constant /////////////////////
       
  5189 		//| ActualSubjectKeyId  | BINARY(20)	| KActualSubjectKeyIdentifier |//
       
  5190 		//| SubjectName			| VARCHAR(255)  | KSubjectName        |//	
       
  5191 		//| IssuerName			| VARCHAR(255)  | KIssuerName        |//	
       
  5192 		//| SerialNumber		| VARCHAR(255)  | KSerialNumber        |//	
       
  5193 		//| Thumbprint			| BINARY(64)	| KThumbprint        |//	
       
  5194 		//////////////////////////////////////////////////////////////////////////////
       
  5195 			
       
  5196 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::AddExtraCertColumnsL - EXTRA cert columns missing from the table %S. Adding now.\n"),
       
  5197 		&aTableName));			
       
  5198 
       
  5199 		HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  5200 		TPtr sqlStatement = buf->Des();
       
  5201 		
       
  5202 		_LIT(KSQLAlterTableForBin, "ALTER TABLE %S ADD %S BINARY(%d)");											 
       
  5203 	
       
  5204 		sqlStatement.Format(KSQLAlterTableForBin, &aTableName, 
       
  5205 			&KActualSubjectKeyIdentifier, KKeyIdentifierLength);
       
  5206 			
       
  5207 		User::LeaveIfError( aDatabase.Execute(sqlStatement));
       
  5208 
       
  5209 		_LIT(KSQLAlterTableForVarChar, "ALTER TABLE %S ADD %S VARCHAR(%d)");											 
       
  5210 	
       
  5211 		sqlStatement.Format(KSQLAlterTableForVarChar, &aTableName, 
       
  5212 			&KSubjectName, KGeneralStringMaxLength);
       
  5213 			
       
  5214 		User::LeaveIfError( aDatabase.Execute(sqlStatement));
       
  5215 
       
  5216 		sqlStatement.Format(KSQLAlterTableForVarChar, &aTableName, 
       
  5217 			&KIssuerName, KGeneralStringMaxLength);
       
  5218 			
       
  5219 		User::LeaveIfError( aDatabase.Execute(sqlStatement));
       
  5220 	
       
  5221 		sqlStatement.Format(KSQLAlterTableForVarChar, &aTableName, 
       
  5222 			&KSerialNumber, KGeneralStringMaxLength);
       
  5223 			
       
  5224 		User::LeaveIfError( aDatabase.Execute(sqlStatement));
       
  5225 	
       
  5226 		sqlStatement.Format(KSQLAlterTableForBin, &aTableName, 
       
  5227 			&KThumbprint, KThumbprintMaxLength);
       
  5228 			
       
  5229 		User::LeaveIfError( aDatabase.Execute(sqlStatement));
       
  5230 	
       
  5231 		CleanupStack::PopAndDestroy( buf ); // Delete buf or sqlStatement
       
  5232 	}
       
  5233 
       
  5234 	CleanupStack::PopAndDestroy( colSetCertTable ); // Delete colSetCertTable.
       
  5235 
       
  5236 	CDbColSet* colSetCertTableAfterAdd = aDatabase.ColSetL(aTableName);
       
  5237 	User::LeaveIfNull(colSetCertTableAfterAdd);
       
  5238 
       
  5239 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapTlsPeapUtils::AddExtraCertColumnsL - Number of columns in %S table after addition=%d\n"),
       
  5240 	&aTableName, colSetCertTableAfterAdd->Count()));
       
  5241 	
       
  5242 	delete colSetCertTableAfterAdd;
       
  5243 } // EapTlsPeapUtils::AddExtraCertColumnsL()
       
  5244 
       
  5245 	
       
  5246 // ---------------------------------------------------------
       
  5247 // EapTlsPeapUtils::GetEapSettingsDataL()
       
  5248 // ---------------------------------------------------------
       
  5249 //
       
  5250 void EapTlsPeapUtils::GetEapSettingsDataL(
       
  5251 	RDbNamedDatabase& aDatabase,
       
  5252 	const TIndexType aIndexType,
       
  5253 	const TInt aIndex,
       
  5254 	const eap_type_value_e aTunnelingType,
       
  5255 	const eap_type_value_e aEapType,
       
  5256 	const TDesC& aDbColumnName,
       
  5257 	eap_variable_data_c * const aDbColumnValue)
       
  5258 {
       
  5259 #ifdef USE_EAP_EXPANDED_TYPES
       
  5260 
       
  5261 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  5262 	TUint aEapVendorType = aEapType.get_vendor_type();
       
  5263 
       
  5264 #else
       
  5265 
       
  5266 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  5267 	TUint aEapVendorType = static_cast<TUint>(aEapType);
       
  5268 
       
  5269 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  5270 
       
  5271 	
       
  5272 	EAP_TRACE_DEBUG_SYMBIAN(
       
  5273 	(_L("EapTlsPeapUtils::GetEapSettingsDataL-Start- aIndexType=%d, aIndex=%d, Tunneling vendor type=%d, Eap vendor type=%d \n"),
       
  5274 	aIndexType,aIndex, aTunnelingVendorType, aEapVendorType));
       
  5275 	
       
  5276 	EAP_TRACE_DEBUG_SYMBIAN(
       
  5277 	(_L("EapTlsPeapUtils::GetEapSettingsDataL Get Column Name:%S \n"),
       
  5278 	&aDbColumnName));	
       
  5279 
       
  5280 	TBufC<KMaxEapDbTableNameLength> generalSettingsTableName;
       
  5281 	
       
  5282 #if defined (USE_FAST_EAP_TYPE)	
       
  5283 	TBufC<KMaxEapDbTableNameLength> specialSettingsTableName;
       
  5284 #endif
       
  5285 
       
  5286 	// Set the database table name based on the type
       
  5287 	switch (aEapVendorType)
       
  5288 	{
       
  5289 		case eap_type_tls:
       
  5290 			generalSettingsTableName = KTlsDatabaseTableName;
       
  5291 			break;
       
  5292 		
       
  5293 		case eap_type_peap:
       
  5294 			generalSettingsTableName = KPeapDatabaseTableName;	
       
  5295 			break;
       
  5296 				
       
  5297 		case eap_type_ttls:
       
  5298 		case eap_type_ttls_plain_pap:
       
  5299 			generalSettingsTableName = KTtlsDatabaseTableName;
       
  5300 			break;
       
  5301 			
       
  5302 #if defined (USE_FAST_EAP_TYPE)
       
  5303 		case eap_type_fast:
       
  5304 			generalSettingsTableName = KFastGeneralSettingsDBTableName; // General settings
       
  5305 			specialSettingsTableName = KFastSpecialSettingsDBTableName; // Special settings  for only FAST
       
  5306 			break;
       
  5307 #endif // #if defined (USE_FAST_EAP_TYPE)
       
  5308 
       
  5309 		default:
       
  5310 			{
       
  5311 				// Unsupported EAP type		
       
  5312 				// Should never happen
       
  5313 				
       
  5314 				EAP_TRACE_DEBUG_SYMBIAN(
       
  5315 					(_L("EapTlsPeapUtils::GetEapSettingsDataL: ERROR: Unsupported EAP type=%d"),
       
  5316 					aEapVendorType));
       
  5317 
       
  5318 				User::Leave(KErrArgument);
       
  5319 			}
       
  5320 	}
       
  5321 	
       
  5322 	if(aDbColumnName.Size() <= 0)	
       
  5323 	{
       
  5324 		EAP_TRACE_DEBUG_SYMBIAN(
       
  5325 			(_L("EapTlsPeapUtils::GetEapSettingsDataL: ERROR: No Column Name!\n")));
       
  5326 		
       
  5327 		User::Leave(KErrArgument);
       
  5328 	}
       
  5329 	
       
  5330 	// Now do the database query
       
  5331 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  5332 	TPtr sqlStatement = buf->Des();
       
  5333 	
       
  5334 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");	
       
  5335 	
       
  5336 #if defined(USE_FAST_EAP_TYPE)
       
  5337 	
       
  5338 	// Unlike other EAP types, EAP-FAST has some settings in special settings table
       
  5339 	// (in KFastSpecialSettingsDBTableName)
       
  5340 	
       
  5341 	if(aEapType == eap_type_fast
       
  5342 	   && ((aDbColumnName.Compare(cf_str_EAP_FAST_allow_server_authenticated_provisioning_mode_literal) == 0)
       
  5343 	   || (aDbColumnName.Compare(cf_str_EAP_FAST_allow_server_unauthenticated_provisioning_mode_ADHP_literal) == 0)
       
  5344 	   || (aDbColumnName.Compare(KFASTWarnADHPNoPAC) == 0)
       
  5345 	   || (aDbColumnName.Compare(KFASTWarnADHPNoMatchingPAC) == 0)
       
  5346 	   || (aDbColumnName.Compare(KFASTWarnNotDefaultServer) == 0)
       
  5347 	   || (aDbColumnName.Compare(KFASTPACGroupImportReferenceCollection) == 0)
       
  5348 	   || (aDbColumnName.Compare(KFASTPACGroupDBReferenceCollection) == 0)))
       
  5349 	{
       
  5350 		EAP_TRACE_DEBUG_SYMBIAN(
       
  5351 			(_L("EapTlsPeapUtils::GetEapSettingsDataL: This field will be read from EAP-FAST's special table")));
       
  5352 
       
  5353 		sqlStatement.Format(KSQLQueryRow, &aDbColumnName, &specialSettingsTableName, 
       
  5354 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);		
       
  5355 	}
       
  5356 	else
       
  5357 	{
       
  5358 		sqlStatement.Format(KSQLQueryRow, &aDbColumnName, &generalSettingsTableName, 
       
  5359 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);		
       
  5360 	}
       
  5361 
       
  5362 #else
       
  5363 
       
  5364 	{
       
  5365 		sqlStatement.Format(KSQLQueryRow, &aDbColumnName, &generalSettingsTableName, 
       
  5366 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);		
       
  5367 	}
       
  5368 
       
  5369 #endif // End: #if defined(USE_FAST_EAP_TYPE)	
       
  5370 
       
  5371 	EAP_TRACE_DEBUG_SYMBIAN(
       
  5372 	(_L("EapTlsPeapUtils::GetEapSettingsDataL - SQL query formated OK")));
       
  5373 
       
  5374 	RDbView view;
       
  5375 	
       
  5376 	User::LeaveIfError(view.Prepare(
       
  5377 			aDatabase, 
       
  5378 			TDbQuery(sqlStatement), 
       
  5379 			TDbWindow::EUnlimited,
       
  5380 			RDbView::EReadOnly));	
       
  5381 		
       
  5382     CleanupStack::PopAndDestroy(buf); // We don't need buf or sqlStatement any more.
       
  5383     
       
  5384 	CleanupClosePushL(view);
       
  5385 	
       
  5386 	User::LeaveIfError(view.EvaluateAll());
       
  5387 	
       
  5388 	eap_status_e status(eap_status_ok);
       
  5389 			
       
  5390 	if (view.FirstL())
       
  5391 	{
       
  5392 		view.GetL();
       
  5393 					
       
  5394 		switch (view.ColType(KDefaultColumnInView_One))
       
  5395 		{
       
  5396 		case EDbColText:				
       
  5397 			{
       
  5398 			EAP_TRACE_DEBUG_SYMBIAN(
       
  5399 					(_L("EapTlsPeapUtils::GetEapSettingsDataL: EDbColText\n")));	
       
  5400 		    if ( !view.IsColNull( KDefaultColumnInView_One ) )
       
  5401 		    	{
       
  5402 			    status = aDbColumnValue->set_copy_of_buffer(
       
  5403 				    view.ColDes(KDefaultColumnInView_One).Ptr(),
       
  5404 				    view.ColDes(KDefaultColumnInView_One).Size());
       
  5405 		    	}
       
  5406 		    else
       
  5407 		    	{
       
  5408 		    	aDbColumnValue->reset();
       
  5409 		    	}
       
  5410      		}
       
  5411 			break;
       
  5412 
       
  5413 		case EDbColBinary:
       
  5414 			{				
       
  5415 			EAP_TRACE_DEBUG_SYMBIAN(
       
  5416 					(_L("EapTlsPeapUtils::GetEapSettingsDataL: EDbColBinary\n")));
       
  5417 			if ( !view.IsColNull( KDefaultColumnInView_One ) )
       
  5418 		    	{			
       
  5419 		    	status = aDbColumnValue->set_copy_of_buffer(
       
  5420 		    		view.ColDes8(KDefaultColumnInView_One).Ptr(),
       
  5421 					view.ColDes8(KDefaultColumnInView_One).Size());
       
  5422 		    	}
       
  5423 		    else
       
  5424 		    	{
       
  5425 		    	aDbColumnValue->reset();
       
  5426 		    	}
       
  5427 			}
       
  5428 			break;
       
  5429 			
       
  5430 		case EDbColUint32:
       
  5431 			{
       
  5432 			EAP_TRACE_DEBUG_SYMBIAN(
       
  5433 					(_L("EapTlsPeapUtils::GetEapSettingsDataL: EDbColUint32\n")));			
       
  5434 		    if ( !view.IsColNull( KDefaultColumnInView_One ) )
       
  5435 		    	{			
       
  5436 			    TUint value;
       
  5437 				value = view.ColUint32(KDefaultColumnInView_One);
       
  5438 				status = aDbColumnValue->set_copy_of_buffer(&value, sizeof(value));
       
  5439 		    	}
       
  5440 		    else
       
  5441 		    	{
       
  5442 		    	aDbColumnValue->reset();
       
  5443 		    	}
       
  5444 		    }
       
  5445 			break;
       
  5446 			
       
  5447 		case EDbColInt64:
       
  5448 			{
       
  5449 			EAP_TRACE_DEBUG_SYMBIAN(
       
  5450 					(_L("EapTlsPeapUtils::GetEapSettingsDataL: EDbColInt64\n")));			
       
  5451 		    if ( !view.IsColNull( KDefaultColumnInView_One ) )
       
  5452 		    	{			
       
  5453 			    TInt64 value;
       
  5454 				value = view.ColInt64(KDefaultColumnInView_One);
       
  5455 				status = aDbColumnValue->set_copy_of_buffer(&value, sizeof(value));
       
  5456 		    	}
       
  5457 		    else
       
  5458 		    	{
       
  5459 		    	aDbColumnValue->reset();
       
  5460 		    	}
       
  5461 			}
       
  5462 			break;
       
  5463 			
       
  5464 		case EDbColLongBinary:
       
  5465 			{
       
  5466 			// This needs special handling. (readstream). Not needed in this DB yet.	
       
  5467 				EAP_TRACE_DEBUG_SYMBIAN(
       
  5468 					(_L("EapTlsPeapUtils::GetEapSettingsDataL: ERROR: EDbColLongBinary not supported in this DB!\n")));	
       
  5469 				
       
  5470 				User::Leave(KErrNotSupported);
       
  5471 			}
       
  5472 			break;			
       
  5473 			
       
  5474 		default:
       
  5475 			EAP_TRACE_DEBUG_SYMBIAN(
       
  5476 				(_L("EapTlsPeapUtils::GetEapSettingsDataL: ERROR: Unsupported DB field! \n")));	
       
  5477 			
       
  5478 			User::Leave(KErrNotSupported);
       
  5479 			break;
       
  5480 		}
       
  5481 	}
       
  5482 
       
  5483 	CleanupStack::PopAndDestroy( &view ); // Close view.
       
  5484 	
       
  5485 	if (status != eap_status_ok)
       
  5486 	{
       
  5487 		EAP_TRACE_DEBUG_SYMBIAN(
       
  5488 				(_L("EapTlsPeapUtils::GetEapSettingsDataL: Status=%d\n"), status));
       
  5489 	}
       
  5490 	
       
  5491 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("GetEapSettingsDataL:DbColumnValue:",
       
  5492 		aDbColumnValue->get_data(aDbColumnValue->get_data_length()),
       
  5493 		aDbColumnValue->get_data_length()));
       
  5494 
       
  5495 	EAP_TRACE_DEBUG_SYMBIAN(
       
  5496 		(_L("EapTlsPeapUtils::GetEapSettingsDataL: End \n")));
       
  5497 
       
  5498 } // EapTlsPeapUtils::GetEapSettingsDataL()
       
  5499 
       
  5500 
       
  5501 // ---------------------------------------------------------
       
  5502 // EapTlsPeapUtils::SetEapSettingsDataL()
       
  5503 // ---------------------------------------------------------
       
  5504 //
       
  5505 void EapTlsPeapUtils::SetEapSettingsDataL(
       
  5506 	RDbNamedDatabase& aDatabase,
       
  5507 	const TIndexType aIndexType,
       
  5508 	const TInt aIndex,
       
  5509 	const eap_type_value_e aTunnelingType,
       
  5510 	const eap_type_value_e aEapType,
       
  5511 	const TDesC& aDbColumnName,
       
  5512 	const eap_variable_data_c * const aDbColumnValue)
       
  5513 {
       
  5514 #ifdef USE_EAP_EXPANDED_TYPES
       
  5515 
       
  5516 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
       
  5517 	TUint aEapVendorType = aEapType.get_vendor_type();
       
  5518 
       
  5519 #else
       
  5520 
       
  5521 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
       
  5522 	TUint aEapVendorType = static_cast<TUint>(aEapType);
       
  5523 
       
  5524 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
  5525 	
       
  5526 	EAP_TRACE_DEBUG_SYMBIAN(
       
  5527 	(_L("EapTlsPeapUtils::SetEapSettingsDataL-Start- aIndexType=%d, aIndex=%d, Tunneling vendor type=%d, Eap vendor type=%d \n"),
       
  5528 	aIndexType,aIndex, aTunnelingVendorType, aEapVendorType));
       
  5529 	
       
  5530 	EAP_TRACE_DEBUG_SYMBIAN(
       
  5531 	(_L("EapTlsPeapUtils::SetEapSettingsDataL Set Column Name:%S \n"),
       
  5532 	&aDbColumnName));	
       
  5533 
       
  5534 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("SetEapSettingsDataL:DbColumnValue:",
       
  5535 		aDbColumnValue->get_data(aDbColumnValue->get_data_length()),
       
  5536 		aDbColumnValue->get_data_length()));
       
  5537 	
       
  5538 	TBufC<KMaxEapDbTableNameLength> generalSettingsTableName;
       
  5539 	
       
  5540 #if defined (USE_FAST_EAP_TYPE)	
       
  5541 	TBufC<KMaxEapDbTableNameLength> specialSettingsTableName;
       
  5542 #endif
       
  5543 
       
  5544 	// Set the database table name based on the type
       
  5545 	switch (aEapVendorType)
       
  5546 	{
       
  5547 		case eap_type_tls:
       
  5548 			generalSettingsTableName = KTlsDatabaseTableName;	
       
  5549 			break;
       
  5550 		
       
  5551 		case eap_type_peap:
       
  5552 			generalSettingsTableName = KPeapDatabaseTableName;
       
  5553 			break;
       
  5554 				
       
  5555 		case eap_type_ttls:
       
  5556 		case eap_type_ttls_plain_pap:
       
  5557 			generalSettingsTableName = KTtlsDatabaseTableName;
       
  5558 			break;
       
  5559 			
       
  5560 #if defined (USE_FAST_EAP_TYPE)
       
  5561 		case eap_type_fast:
       
  5562 			generalSettingsTableName = KFastGeneralSettingsDBTableName; // General settings
       
  5563 			specialSettingsTableName = KFastSpecialSettingsDBTableName; // Special settings  for only FAST
       
  5564 			break;
       
  5565 #endif // #if defined (USE_FAST_EAP_TYPE)
       
  5566 			
       
  5567 		default:
       
  5568 			{
       
  5569 				// Unsupported EAP type		
       
  5570 				// Should never happen
       
  5571 				
       
  5572 				EAP_TRACE_DEBUG_SYMBIAN(
       
  5573 					(_L("EapTlsPeapUtils::SetEapSettingsDataL: ERROR: Unsupported EAP type=%d"),
       
  5574 					aEapVendorType));
       
  5575 
       
  5576 				User::Leave(KErrArgument);
       
  5577 			}
       
  5578 	}
       
  5579 	
       
  5580 	if(aDbColumnName.Size() <= 0)	
       
  5581 	{
       
  5582 		EAP_TRACE_DEBUG_SYMBIAN(
       
  5583 			(_L("EapTlsPeapUtils::SetEapSettingsDataL: ERROR: No Column Name!\n")));
       
  5584 		
       
  5585 		User::Leave(KErrArgument);
       
  5586 	}
       
  5587 	
       
  5588 	// Now do the database query
       
  5589 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
  5590 	TPtr sqlStatement = buf->Des();
       
  5591 	
       
  5592 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");	
       
  5593 	
       
  5594 #if defined(USE_FAST_EAP_TYPE)
       
  5595 	
       
  5596 	// Unlike other EAP types, EAP-FAST has some settings in special settings table
       
  5597 	// (in KFastSpecialSettingsDBTableName)
       
  5598 	
       
  5599 	if(aEapType == eap_type_fast
       
  5600 	   && ((aDbColumnName.Compare(cf_str_EAP_FAST_allow_server_authenticated_provisioning_mode_literal) == 0)
       
  5601 	   || (aDbColumnName.Compare(cf_str_EAP_FAST_allow_server_unauthenticated_provisioning_mode_ADHP_literal) == 0)
       
  5602 	   || (aDbColumnName.Compare(KFASTWarnADHPNoPAC) == 0)
       
  5603 	   || (aDbColumnName.Compare(KFASTWarnADHPNoMatchingPAC) == 0)
       
  5604 	   || (aDbColumnName.Compare(KFASTWarnNotDefaultServer) == 0)
       
  5605 	   || (aDbColumnName.Compare(KFASTPACGroupImportReferenceCollection) == 0)
       
  5606 	   || (aDbColumnName.Compare(KFASTPACGroupDBReferenceCollection) == 0)))
       
  5607 	{
       
  5608 		EAP_TRACE_DEBUG_SYMBIAN(
       
  5609 			(_L("EapTlsPeapUtils::SetEapSettingsDataL: This field will be read from EAP-FAST's special table")));
       
  5610 
       
  5611 		sqlStatement.Format(KSQLQueryRow, &aDbColumnName, &specialSettingsTableName, 
       
  5612 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);		
       
  5613 	}
       
  5614 	else
       
  5615 	{
       
  5616 		sqlStatement.Format(KSQLQueryRow, &aDbColumnName, &generalSettingsTableName, 
       
  5617 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);		
       
  5618 	}
       
  5619 
       
  5620 #else
       
  5621 
       
  5622 	{
       
  5623 		sqlStatement.Format(KSQLQueryRow, &aDbColumnName, &generalSettingsTableName, 
       
  5624 			&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);		
       
  5625 	}
       
  5626 
       
  5627 #endif // End: #if defined(USE_FAST_EAP_TYPE)	
       
  5628 
       
  5629 	EAP_TRACE_DEBUG_SYMBIAN(
       
  5630 	(_L("EapTlsPeapUtils::SetEapSettingsDataL - SQL query formated OK")));
       
  5631 
       
  5632 	RDbView view;
       
  5633 	
       
  5634 	User::LeaveIfError(view.Prepare(
       
  5635 			aDatabase, 
       
  5636 			TDbQuery(sqlStatement), 
       
  5637 			TDbWindow::EUnlimited,
       
  5638 			RDbView::EUpdatable));
       
  5639 	
       
  5640 	CleanupStack::PopAndDestroy(buf); // We don't need buf or sqlStatement any more.
       
  5641    
       
  5642 	CleanupClosePushL(view);
       
  5643 	
       
  5644 	User::LeaveIfError(view.EvaluateAll());
       
  5645 	
       
  5646 	if (view.FirstL())
       
  5647 	{
       
  5648 		view.UpdateL(); // Here it is update.
       
  5649 				
       
  5650 		if(view.ColCount() == KDefaultColumnInView_One)
       
  5651 		{
       
  5652 			// There should be one column (only one) with the specified column name.
       
  5653 			
       
  5654 			HBufC8* dbColVal8 = HBufC8::NewLC(aDbColumnValue->get_data_length());			
       
  5655 			TPtr8 dbColValPtr8 = dbColVal8->Des();
       
  5656 
       
  5657 			dbColValPtr8.Copy(
       
  5658 				aDbColumnValue->get_data( aDbColumnValue->get_data_length() ),
       
  5659 				aDbColumnValue->get_data_length() );
       
  5660 			
       
  5661 			switch (view.ColType(KDefaultColumnInView_One))
       
  5662 			{
       
  5663 			case EDbColText:				
       
  5664 				{
       
  5665 					TPtr dbColValPtr(0,dbColValPtr8.Size());
       
  5666 					dbColValPtr.Copy(dbColValPtr8);
       
  5667 
       
  5668 					view.SetColL(KDefaultColumnInView_One, dbColValPtr);
       
  5669 				}
       
  5670 				break;
       
  5671 	
       
  5672 			case EDbColBinary:
       
  5673 				{
       
  5674 					view.SetColL(KDefaultColumnInView_One, dbColValPtr8);
       
  5675 				}
       
  5676 				break;
       
  5677 				
       
  5678 			case EDbColUint32:
       
  5679 				{
       
  5680 
       
  5681 #if defined (USE_FAST_EAP_TYPE)
       
  5682 					
       
  5683 					EAP_TRACE_DEBUG_SYMBIAN(
       
  5684 							(_L("eap_am_type_tls_peap_symbian_c::authentication_finishedL WARNING, HACK to set Unauth Prov mode set to default (NO)!")));					
       
  5685 	
       
  5686 					view.SetColL(KDefaultColumnInView_One, EFASTUnauthProvModeAllowedNo);
       
  5687 				
       
  5688 #endif // End: #if defined (USE_FAST_EAP_TYPE)
       
  5689 				}
       
  5690 				break;
       
  5691 				
       
  5692 			case EDbColInt64:
       
  5693 				{
       
  5694 					// Do some lexical analysis to get TInt64 value here and set it in DB.
       
  5695 					
       
  5696 					EAP_TRACE_DEBUG_SYMBIAN(
       
  5697 						(_L("EapTlsPeapUtils::SetEapSettingsDataL: ERROR: EDbColInt64 not supported here yet!\n")));	
       
  5698 					
       
  5699 					User::Leave(KErrNotSupported);					
       
  5700 				}
       
  5701 				break;
       
  5702 				
       
  5703 			case EDbColLongBinary:
       
  5704 				{
       
  5705 					// This needs special handling. (readstream). Not needed in this DB yet.	
       
  5706 					EAP_TRACE_DEBUG_SYMBIAN(
       
  5707 						(_L("EapTlsPeapUtils::SetEapSettingsDataL: ERROR: EDbColLongBinary not supported in this DB!\n")));	
       
  5708 					
       
  5709 					User::Leave(KErrNotSupported);
       
  5710 				}
       
  5711 				break;			
       
  5712 				
       
  5713 			default:
       
  5714 				EAP_TRACE_DEBUG_SYMBIAN(
       
  5715 					(_L("EapTlsPeapUtils::SetEapSettingsDataL: ERROR: Unsupported DB field! \n")));	
       
  5716 				
       
  5717 				User::Leave(KErrNotSupported);
       
  5718 				break;
       
  5719 			}
       
  5720 			
       
  5721 			CleanupStack::PopAndDestroy(dbColVal8);		
       
  5722 			
       
  5723 		} // End: if(view.ColCount() == KDefaultColumnInView_One)
       
  5724 		else
       
  5725 		{
       
  5726 			EAP_TRACE_DEBUG_SYMBIAN(
       
  5727 				(_L("EapTlsPeapUtils::SetEapSettingsDataL: ERROR: Too many columns in DB view, count=%d \n"),
       
  5728 				view.ColCount()));	
       
  5729 			
       
  5730 			User::Leave(KErrNotFound);
       
  5731 		}
       
  5732 	} // End: if (view.FirstL())
       
  5733 	
       
  5734 	// Now it should go to the DB.
       
  5735 	view.PutL();	
       
  5736 	
       
  5737 	CleanupStack::PopAndDestroy( &view ); // Close view.		
       
  5738 
       
  5739 	EAP_TRACE_DEBUG_SYMBIAN(
       
  5740 		(_L("EapTlsPeapUtils::SetEapSettingsDataL: End \n")));	
       
  5741 }
       
  5742 
       
  5743 /*
       
  5744  * Alter table for added column, if doesn't exist
       
  5745  * 
       
  5746  */
       
  5747 void EapTlsPeapUtils::AlterTableL(
       
  5748 		RDbNamedDatabase& aDb,
       
  5749 		TAlterTableCmd aCmd,
       
  5750 		const TDesC& aTableName,
       
  5751 		const TDesC& aColumnName,
       
  5752 		const TDesC& aColumnDef )
       
  5753 		{
       
  5754 	
       
  5755 		CDbColSet* colSet = aDb.ColSetL( aTableName );
       
  5756 		User::LeaveIfNull( colSet );
       
  5757 		CleanupStack::PushL( colSet );	
       
  5758 			
       
  5759 		EAP_TRACE_DEBUG_SYMBIAN( ( _L(
       
  5760 	        "EapTlsPeapUtils::AlterTableL() \
       
  5761 	        Number of columns in %S table is %d.\n" ),
       
  5762 			&aTableName, colSet->Count() ) );
       
  5763 		
       
  5764 	    if ( aCmd == EAddColumn )
       
  5765 	    	{
       
  5766 	    	// Check if there is a target column
       
  5767 	    	if( colSet->ColNo( aColumnName ) != KDbNullColNo )
       
  5768 	    		{
       
  5769 	    		EAP_TRACE_DEBUG_SYMBIAN( ( _L(
       
  5770 	   		        "EapTlsPeapUtils::AlterTableL() \
       
  5771 	   		        Column %S exists already in table %S.\n" ),
       
  5772 	    			&aColumnName, &aTableName ) );
       
  5773 	    		CleanupStack::PopAndDestroy( colSet );
       
  5774 	    		return;
       
  5775 	    		}
       
  5776 	    	}
       
  5777 	    else
       
  5778 	    	{
       
  5779 	    	// Check if there is a target column
       
  5780 	    	if( colSet->ColNo( aColumnName ) == KDbNullColNo )
       
  5781 	    		{
       
  5782 	    		EAP_TRACE_DEBUG_SYMBIAN( ( _L(
       
  5783 	   		        "EapTlsPeapUtils::AlterTableL() \
       
  5784 	   		        Column %S does not exists already in table %S.\n" ),
       
  5785 	    			&aColumnName, &aTableName ) );
       
  5786 	    		CleanupStack::PopAndDestroy( colSet );
       
  5787 	    		return;
       
  5788 	    		}
       
  5789 	    	}
       
  5790 
       
  5791 		HBufC* buf = HBufC::NewLC( KMaxSqlQueryLength );
       
  5792 		TPtr sqlStatement = buf->Des();
       
  5793 			
       
  5794 		_LIT( KSqlAddCol, "ALTER TABLE %S ADD %S %S" );
       
  5795 		_LIT( KSqlRemoveCol, "ALTER TABLE %S DROP %S" );
       
  5796 		
       
  5797 		if ( aCmd == EAddColumn )
       
  5798 			{
       
  5799 			sqlStatement.Format( KSqlAddCol, &aTableName, 
       
  5800 			    &aColumnName, &aColumnDef );
       
  5801 			}
       
  5802 		else
       
  5803 			{
       
  5804 			sqlStatement.Format( KSqlRemoveCol, &aTableName, 
       
  5805 		        &aColumnName );
       
  5806 			}
       
  5807 			
       
  5808 		EAP_TRACE_DEBUG_SYMBIAN( ( _L(
       
  5809 			"EapTlsPeapUtils::AlterTableL(): sqlStatement=%S\n"),
       
  5810 			&sqlStatement ) );
       
  5811 		
       
  5812 		User::LeaveIfError( aDb.Execute( sqlStatement ) );		
       
  5813 		CleanupStack::PopAndDestroy( buf );
       
  5814 		CleanupStack::PopAndDestroy( colSet );
       
  5815 
       
  5816 		CDbColSet* alteredColSet = aDb.ColSetL( aTableName );
       
  5817 		User::LeaveIfNull( alteredColSet );
       
  5818 		EAP_TRACE_DEBUG_SYMBIAN( ( _L(
       
  5819 	        "EapTlsPeapUtils::AlterTableL() \
       
  5820 	        Number of columns in %S table after adding is %d.\n" ),
       
  5821 			&aTableName, alteredColSet->Count() ) );
       
  5822 		delete alteredColSet;
       
  5823 			
       
  5824 		} // EapTlsPeapUtils::AlterTableL()
       
  5825 
       
  5826 // End of file
       
  5827 
       
  5828