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