eapol/eapol_framework/eapol_symbian/am/type/gsmsim/symbian/plugin/src/EapSimDbUtils.cpp
branchRCL_3
changeset 18 bad0cc58d154
parent 2 1c7bc153c08e
child 19 c74b3d9f6b9e
equal deleted inserted replaced
17:30e048a7b597 18: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: 31.1.2 %
    19 * %version: 57 %
    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
    31 // INCLUDES
    31 // INCLUDES
    32 #include "EapSimDbUtils.h"
    32 #include "EapSimDbUtils.h"
    33 #include "EapSimDbDefaults.h"
    33 #include "EapSimDbDefaults.h"
    34 #include "EapSimDbParameterNames.h"
    34 #include "EapSimDbParameterNames.h"
    35 
    35 
    36 #include "eap_am_trace_symbian.h"
    36 #include <EapTraceSymbian.h>
       
    37 #include "EapPluginTools.h"
    37 
    38 
    38 const TInt KMaxSqlQueryLength = 2048;
    39 const TInt KMaxSqlQueryLength = 2048;
    39 const TInt KMicroSecsInAMinute = 60000000; // 60000000 micro seconds is 1 minute.
    40 const TInt KMicroSecsInAMinute = 60000000; // 60000000 micro seconds is 1 minute.
    40 
    41 
    41 // ================= MEMBER FUNCTIONS =======================
    42 // ================= MEMBER FUNCTIONS =======================
    42 
    43 
    43 void EapSimDbUtils::OpenDatabaseL(RDbNamedDatabase& aDatabase, RDbs& aSession, const TIndexType aIndexType,
    44 void EapSimDbUtils::OpenDatabaseL(
    44 	const TInt aIndex, const eap_type_value_e aTunnelingType)
    45 	RDbNamedDatabase& aDatabase,
       
    46 	RFs& aFileServerSession,
       
    47 	const TIndexType aIndexType,
       
    48 	const TInt aIndex,
       
    49 	const eap_type_value_e aTunnelingType)
    45 {
    50 {
    46 #ifdef USE_EAP_EXPANDED_TYPES
    51 	EAP_TRACE_DEBUG_SYMBIAN(
    47 
    52 		(_L("EapSimDbUtils::OpenDatabaseL(): Start - aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
    48 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
    53 		aIndexType,
    49 
    54 		aIndex,
    50 #else
    55 		aTunnelingType.get_vendor_id(),
    51 
    56 		aTunnelingType.get_vendor_type()));
    52 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
    57 
    53 
    58     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapSimDbUtils::OpenDatabaseL()\n"));
    54 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
    55 
       
    56 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::OpenDatabaseL -Start- aIndexType=%d, aIndex=%d, aTunnelingVendorType=%d \n"),
       
    57 	aIndexType,aIndex,aTunnelingVendorType) );
       
    58 
    59 
    59 	// 1. Open/create a database	
    60 	// 1. Open/create a database	
    60 	
    61 	
    61 	// Connect to the DBMS server.
    62 	TInt error(KErrNone);
    62 	User::LeaveIfError(aSession.Connect());		
    63 	TFileName aPrivateDatabasePathName;
    63 	CleanupClosePushL(aSession);	
    64 
    64 	// aSession and aDatabase are pushed to the cleanup stack even though they may be member
    65 	EapPluginTools::CreateDatabaseLC(
    65 	// variables of the calling class and would be closed in the destructor anyway. This ensures
    66 		aDatabase,
    66 	// that if they are not member variables they will be closed. Closing the handle twice
    67 		aFileServerSession,
    67 	// does no harm.	
    68 		error,
    68 	
    69 		KEapSimDatabaseName,
    69 #ifdef SYMBIAN_SECURE_DBMS
    70 		aPrivateDatabasePathName);
    70 	
    71 
    71 	// Create the secure shared database with the specified secure policy.
    72 	if(error == KErrNone)
    72 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
       
    73 	
       
    74 	TInt err = aDatabase.Create(aSession, KDatabaseName, KSecureUIDFormat);
       
    75 	
       
    76 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::OpenDatabaseL - Created Secure DB for eapsim.dat. err=%d\n"), err));
       
    77 
       
    78 	
       
    79 	if(err == KErrNone)
       
    80 	{
    73 	{
    81 		aDatabase.Close();
    74 		aDatabase.Close();
    82 		
    75 	}
    83 	} else if (err != KErrAlreadyExists) 
    76 	else if (error != KErrAlreadyExists) 
    84 	{
    77 	{
    85 		User::LeaveIfError(err);
    78 		User::LeaveIfError(error);
    86 	}
    79 	}
    87 	
    80 	
    88 	User::LeaveIfError(aDatabase.Open(aSession, KDatabaseName, KSecureUIDFormat));
    81 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::OpenDatabaseL(): calls aDatabase.Open()\n")));
    89 	CleanupClosePushL(aDatabase);		
    82 
    90 		
    83 	error = aDatabase.Open(aFileServerSession, aPrivateDatabasePathName);
    91 #else
    84 
    92 	// Non secured database. The database will be created in the old location (c:\system\data).
    85 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::OpenDatabaseL(): Opened private DB for EAP-SIM. error=%d\n"), error));
    93 	
    86 
    94 	RFs fsSession;		
    87 	User::LeaveIfError(error);
    95 	User::LeaveIfError(fsSession.Connect());
       
    96 	CleanupClosePushL(fsSession);	
       
    97 	TInt err = aDatabase.Create(fsSession, KDatabaseName);
       
    98 	
       
    99 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::OpenDatabaseL - Created Non-Secure DB for eapsim.dat. err=%d\n"), err));
       
   100 	
       
   101 	
       
   102 	if(err == KErrNone)
       
   103 	{
       
   104 		aDatabase.Close();
       
   105 		
       
   106 	} else if (err != KErrAlreadyExists) 
       
   107 	{
       
   108 		User::LeaveIfError(err);
       
   109 	}
       
   110 	CleanupStack::PopAndDestroy( &fsSession ); // close fsSession
       
   111 	
       
   112 	User::LeaveIfError(aDatabase.Open(aSession, KDatabaseName));
       
   113 	CleanupClosePushL(aDatabase);		
       
   114 	    
       
   115 #endif // #ifdef SYMBIAN_SECURE_DBMS
       
   116 
    88 
   117 	// 2. Create the eapsim table to database (ignore error if exists)
    89 	// 2. Create the eapsim table to database (ignore error if exists)
   118 	
    90 	
   119 // Table columns:
    91 	// Table columns:
   120 //// NAME ///////////////////////////////////////////////// TYPE ////////////// Constant /////////
    92 	//// NAME ///////////////////////////////////////////////// TYPE ////////////// Constant /////////
   121 //| ServiceType									| UNSIGNED INTEGER | KServiceType      |//
    93 	//| ServiceType									| UNSIGNED INTEGER | KServiceType      |//
   122 //| ServiceIndex								| UNSIGNED INTEGER | KServiceIndex     |//
    94 	//| ServiceIndex								| UNSIGNED INTEGER | KServiceIndex     |//
   123 //| TunnelingType								| UNSIGNED INTEGER | KTunnelingType    |//
    95 	//| TunnelingTypeVendorId                       | UNSIGNED INTEGER  | KTunnelingTypeVendorId    |//
   124 //| EAP_GSMSIM_use_manual_realm					| UNSIGNED INTEGER | cf_str_EAP_GSMSIM_use_manual_realm_literal   |//
    96 	//| TunnelingType								| UNSIGNED INTEGER | KTunnelingType    |//
   125 //| EAP_GSMSIM_manual_realm						| VARCHAR(255)	   | cf_str_EAP_GSMSIM_manual_realm_literal			   |//
    97 	//| EAP_GSMSIM_use_manual_realm					| UNSIGNED INTEGER | cf_str_EAP_GSMSIM_use_manual_realm_literal   |//
   126 //| EAP_GSMSIM_use_manual_username				| UNSIGNED INTEGER | cf_str_EAP_GSMSIM_use_manual_username_literal|//
    98 	//| EAP_GSMSIM_manual_realm						| VARCHAR(255)	   | cf_str_EAP_GSMSIM_manual_realm_literal			   |//
   127 //| EAP_GSMSIM_manual_username					| VARCHAR(255)	   | cf_str_EAP_GSMSIM_manual_username_literal		   |//
    99 	//| EAP_GSMSIM_use_manual_username				| UNSIGNED INTEGER | cf_str_EAP_GSMSIM_use_manual_username_literal|//
   128 //| PseudonymId									| LONG VARBINARY   | KPseudonymId      |//
   100 	//| EAP_GSMSIM_manual_username					| VARCHAR(255)	   | cf_str_EAP_GSMSIM_manual_username_literal		   |//
   129 //| XKEY										| BINARY(20)       | KXKey             |//
   101 	//| PseudonymId									| LONG VARBINARY   | KPseudonymId      |//
   130 //| K_aut										| BINARY(16)       | KK_aut            |//
   102 	//| XKEY										| BINARY(20)       | KXKey             |//
   131 //| K_encr										| BINARY(16)       | KK_encr           |//
   103 	//| K_aut										| BINARY(16)       | KK_aut            |//
   132 //| ReauthCounter								| UNSIGNED INTEGER | KReauthCounter    |//
   104 	//| K_encr										| BINARY(16)       | KK_encr           |//
   133 //| ReauthId									| LONG VARBINARY   | KReauthId         |//
   105 	//| ReauthCounter								| UNSIGNED INTEGER | KReauthCounter    |//
   134 //| PreviousIMSI								| VARBINARY(15)	   | KPreviousIMSI	   |//
   106 	//| ReauthId									| LONG VARBINARY   | KReauthId         |//
   135 //| EAP_GSMSIM_use_pseudonym_identity 			| UNSIGNED INTEGER | cf_str_EAP_GSMSIM_use_pseudonym_identity_literal	   	|//
   107 	//| PreviousIMSI								| VARBINARY(15)	   | KPreviousIMSI	   |//
   136 //| EAP_GSMSIM_max_session_validity_time		| BIGINT		   | cf_str_EAP_GSMSIM_max_session_validity_time_literal   |//
   108 	//| EAP_GSMSIM_use_pseudonym_identity 			| UNSIGNED INTEGER | cf_str_EAP_GSMSIM_use_pseudonym_identity_literal	   	|//
   137 //| EAP_GSMSIM_last_full_authentication_time	| BIGINT		   | KGSMSIMLastFullAuthTime	|//
   109 	//| EAP_GSMSIM_max_session_validity_time		| BIGINT		   | cf_str_EAP_GSMSIM_max_session_validity_time_literal   |//
   138 //////////////////////////////////////////////////////////////////////////////////////////////////
   110 	//| EAP_GSMSIM_last_full_authentication_time	| BIGINT		   | KGSMSIMLastFullAuthTime	|//
       
   111 	//////////////////////////////////////////////////////////////////////////////////////////////////
   139 
   112 
   140 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   113 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   141 	TPtr sqlStatement = buf->Des();
   114 	TPtr sqlStatement = buf->Des();
   142 	
   115 	
   143 	_LIT(KSQLCreateTable, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
   116 	_LIT(KSQLCreateTable, "CREATE TABLE %S \
   144 												 %S UNSIGNED INTEGER, \
   117 		(%S UNSIGNED INTEGER, \
   145 												 %S UNSIGNED INTEGER, \
   118 		 %S UNSIGNED INTEGER, \
   146 												 %S UNSIGNED INTEGER, \
   119 		 %S UNSIGNED INTEGER, \
   147 												 %S VARCHAR(%d), \
   120 		 %S UNSIGNED INTEGER, \
   148 												 %S UNSIGNED INTEGER, \
   121 		 %S UNSIGNED INTEGER, \
   149 												 %S VARCHAR(%d), \
   122 		 %S VARCHAR(%d), \
   150 												 %S LONG VARBINARY, \
   123 		 %S UNSIGNED INTEGER, \
   151 												 %S BINARY(%d), \
   124 		 %S VARCHAR(%d), \
   152 												 %S BINARY(%d), \
   125 		 %S LONG VARBINARY, \
   153 												 %S BINARY(%d), \
   126 		 %S BINARY(%d), \
   154 												 %S UNSIGNED INTEGER, \
   127 		 %S BINARY(%d), \
   155 												 %S LONG VARBINARY, \
   128 		 %S BINARY(%d), \
   156 												 %S VARBINARY(%d), \
   129 		 %S UNSIGNED INTEGER, \
   157 												 %S UNSIGNED INTEGER, \
   130 		 %S LONG VARBINARY, \
   158 												 %S BIGINT, \
   131 		 %S VARBINARY(%d), \
   159 												 %S BIGINT)");
   132 		 %S UNSIGNED INTEGER, \
       
   133 		 %S BIGINT, \
       
   134 		 %S BIGINT)");
   160 												 
   135 												 
   161 	sqlStatement.Format(KSQLCreateTable, &KSimTableName, &KServiceType,
   136 	sqlStatement.Format(KSQLCreateTable,
   162 														 &KServiceIndex, 
   137 		&KSimTableName,
   163 														 &KTunnelingType,
   138 		&KServiceType,
   164 														 &cf_str_EAP_GSMSIM_use_manual_realm_literal, 
   139 		&KServiceIndex, 
   165 														 &cf_str_EAP_GSMSIM_manual_realm_literal, KMaxManualRealmLengthInDB, 
   140 		&KTunnelingTypeVendorId,
   166 														 &cf_str_EAP_GSMSIM_use_manual_username_literal, 
   141 		&KTunnelingType,
   167 														 &cf_str_EAP_GSMSIM_manual_username_literal, KMaxManualUsernameLengthInDB, 
   142 		&cf_str_EAP_GSMSIM_use_manual_realm_literal, 
   168 														 &KPseudonymId,
   143 		&cf_str_EAP_GSMSIM_manual_realm_literal, KMaxRealmLengthInDB, 
   169 														 &KXKey, KMaxXKeyLengthInDB, 
   144 		&cf_str_EAP_GSMSIM_use_manual_username_literal, 
   170 														 &KK_aut, KMaxK_autLengthInDB, 
   145 		&cf_str_EAP_GSMSIM_manual_username_literal, KMaxUsernameLengthInDB, 
   171 														 &KK_encr, KMaxK_encrLengthInDB, 
   146 		&KPseudonymId,
   172 														 &KReauthCounter, 
   147 		&KXKey, KMaxXKeyLengthInDB, 
   173 														 &KReauthId, 
   148 		&KK_aut, KMaxK_autLengthInDB, 
   174 														 &KPreviousIMSI, KMaxIMSILengthInDB,
   149 		&KK_encr, KMaxK_encrLengthInDB, 
   175 														 &cf_str_EAP_GSMSIM_use_pseudonym_identity_literal,														 
   150 		&KReauthCounter, 
   176 														 &cf_str_EAP_GSMSIM_max_session_validity_time_literal, 
   151 		&KReauthId, 
   177 														 &KGSMSIMLastFullAuthTime);
   152 		&KPreviousIMSI, KMaxIMSILengthInDB,
       
   153 		&cf_str_EAP_GSMSIM_use_pseudonym_identity_literal,														 
       
   154 		&cf_str_EAP_GSMSIM_max_session_validity_time_literal, 
       
   155 		&KGSMSIMLastFullAuthTime);
   178 																					
   156 																					
   179 	err = aDatabase.Execute(sqlStatement);
   157 	error = aDatabase.Execute(sqlStatement);
   180 	if (err != KErrNone && err != KErrAlreadyExists)
   158 	if (error != KErrNone && error != KErrAlreadyExists)
   181 	{
   159 	{
   182 		User::Leave(err);
   160 		User::Leave(error);
   183 	}
   161 	}
   184 	
   162 	
   185 	// 4. Check if database table contains a row for this service type and id  
   163 	// 4. Check if database table contains a row for this service type and id  
   186 	
   164 	
   187 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   165 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   188 	sqlStatement.Format(KSQLQueryRow, &cf_str_EAP_GSMSIM_manual_realm_literal, &KSimTableName, 
   166 
   189 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   167 	sqlStatement.Format(KSQLQueryRow,
   190 		
   168 		&cf_str_EAP_GSMSIM_manual_realm_literal,
       
   169 		&KSimTableName, 
       
   170 		&KServiceType,
       
   171 		aIndexType,
       
   172 		&KServiceIndex,
       
   173 		aIndex,
       
   174 		&KTunnelingTypeVendorId,
       
   175 		aTunnelingType.get_vendor_id(),
       
   176 		&KTunnelingType, 
       
   177 		aTunnelingType.get_vendor_type());
       
   178 
   191 	RDbView view;
   179 	RDbView view;
   192 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   180 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   193 	// View must be closed when no longer needed
   181 	// View must be closed when no longer needed
   194 	CleanupClosePushL(view);
   182 	CleanupClosePushL(view);
   195 	
   183 	
   212 		CleanupStack::PushL(colSet);
   200 		CleanupStack::PushL(colSet);
   213 		
   201 		
   214 		view.InsertL();
   202 		view.InsertL();
   215 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
   203 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt>(aIndexType));
   216 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);
   204 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);
   217 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
   205 		view.SetColL(colSet->ColNo(KTunnelingTypeVendorId), aTunnelingType.get_vendor_id());
       
   206 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingType.get_vendor_type());
   218 		
   207 		
   219 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_realm_literal), default_EAP_GSMSIM_use_manual_realm);	
   208 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_realm_literal), default_EAP_GSMSIM_use_manual_realm);	
   220 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_manual_realm_literal), default_EAP_GSMSIM_manual_realm);
   209 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_manual_realm_literal), default_EAP_realm);
   221 		
   210 		
   222 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_username_literal), default_EAP_GSMSIM_use_manual_username);
   211 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_username_literal), default_EAP_GSMSIM_use_manual_username);
   223 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_manual_username_literal), default_EAP_GSMSIM_manual_username);
   212 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_manual_username_literal), default_EAP_username);
   224 		
   213 		
   225 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_pseudonym_identity_literal), default_EAP_GSMSIM_use_pseudonym_identity);			
   214 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_pseudonym_identity_literal), default_EAP_GSMSIM_use_pseudonym_identity);			
   226 		
   215 		
   227 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_max_session_validity_time_literal), default_MaxSessionTime);
   216 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_max_session_validity_time_literal), default_MaxSessionTime);
   228 		
   217 		
   229 		view.SetColL(colSet->ColNo(KGSMSIMLastFullAuthTime), default_FullAuthTime);				
   218 		view.SetColL(colSet->ColNo(KGSMSIMLastFullAuthTime), default_FullAuthTime);				
   230 
   219 
   231 		view.PutL();
   220 		view.PutL();
   232 		
   221 		
   233 		CleanupStack::PopAndDestroy( colSet ); // Delete colSet.
   222 		CleanupStack::PopAndDestroy( colSet );
   234 		
   223 		
   235 		CleanupStack::PopAndDestroy( &view ); // Close view.
   224 		CleanupStack::PopAndDestroy( &view );
   236 	}
   225 	}
   237 	
   226 	
   238 	CleanupStack::PopAndDestroy( buf ); // Delete buf	
   227 	aDatabase.Compact();
       
   228 
       
   229 	CleanupStack::PopAndDestroy( buf );
   239 	CleanupStack::Pop( &aDatabase );	
   230 	CleanupStack::Pop( &aDatabase );	
   240 	CleanupStack::Pop( &aSession );	
   231 	CleanupStack::Pop( &aFileServerSession );
   241 	
       
   242 	aDatabase.Compact();
       
   243 }
   232 }
       
   233 
       
   234 // ----------------------------------------------------------
   244 
   235 
   245 void EapSimDbUtils::SetIndexL(
   236 void EapSimDbUtils::SetIndexL(
   246 	RDbNamedDatabase& aDatabase, 		
   237 	RDbNamedDatabase& aDatabase, 		
   247 	const TIndexType aIndexType,
   238 	const TIndexType aIndexType,
   248 	const TInt aIndex,
   239 	const TInt aIndex,
   249 	const eap_type_value_e aTunnelingType,
   240 	const eap_type_value_e aTunnelingType,
   250 	const TIndexType aNewIndexType,
   241 	const TIndexType aNewIndexType,
   251 	const TInt aNewIndex,
   242 	const TInt aNewIndex,
   252 	const eap_type_value_e aNewTunnelingType)
   243 	const eap_type_value_e aNewTunnelingType)
   253 {
   244 {
   254 #ifdef USE_EAP_EXPANDED_TYPES
   245 	EAP_TRACE_DEBUG_SYMBIAN(
   255 
   246 		(_L("EapSimDbUtils::SetIndexL(): -Start- aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
   256 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
   247 		aIndexType,
   257 	TUint aNewTunnelingVendorType = aNewTunnelingType.get_vendor_type();
   248 		aIndex,
   258 
   249 		aTunnelingType.get_vendor_id(),
   259 #else
   250 		aTunnelingType.get_vendor_type()));
   260 
   251 	
   261 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
   252 	EAP_TRACE_DEBUG_SYMBIAN(
   262 	TUint aNewTunnelingVendorType = static_cast<TUint>(aNewTunnelingType);
   253 		(_L("EapSimDbUtils::SetIndexL(): -Start- aNewIndexType=%d, aNewIndex=%d, aNewTunnelingType=0xfe%06x%08x\n"),
   263 
   254 		aNewIndexType,
   264 #endif //#ifdef USE_EAP_EXPANDED_TYPES
   255 		aNewIndex,
       
   256 		aNewTunnelingType.get_vendor_id(),
       
   257 		aNewTunnelingType.get_vendor_type()));
       
   258 
       
   259     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapSimDbUtils::SetIndexL()\n"));
   265 
   260 
   266 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   261 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   267 	TPtr sqlStatement = buf->Des();
   262 	TPtr sqlStatement = buf->Des();
   268 
   263 
   269 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   264 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   270 
   265 
   271 	sqlStatement.Format(KSQL, &KSimTableName, 
   266 	sqlStatement.Format(KSQL,
   272 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   267 		&KSimTableName, 
       
   268 		&KServiceType,
       
   269 		aIndexType,
       
   270 		&KServiceIndex,
       
   271 		aIndex,
       
   272 		&KTunnelingTypeVendorId,
       
   273 		aTunnelingType.get_vendor_id(),
       
   274 		&KTunnelingType, 
       
   275 		aTunnelingType.get_vendor_type());
   273 	
   276 	
   274 	RDbView view;
   277 	RDbView view;
   275 	
   278 	
   276 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   279 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   277 	
   280 	
   296 	CleanupStack::PushL(colSet);
   299 	CleanupStack::PushL(colSet);
   297 	
   300 	
   298 	view.UpdateL();
   301 	view.UpdateL();
   299 	
   302 	
   300     view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aNewIndexType));
   303     view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aNewIndexType));
   301     
       
   302     view.SetColL(colSet->ColNo(KServiceIndex), aNewIndex);
   304     view.SetColL(colSet->ColNo(KServiceIndex), aNewIndex);
   303     
   305 	view.SetColL(colSet->ColNo(KTunnelingTypeVendorId), aNewTunnelingType.get_vendor_id());
   304     view.SetColL(colSet->ColNo(KTunnelingType), aNewTunnelingVendorType);
   306 	view.SetColL(colSet->ColNo(KTunnelingType), aNewTunnelingType.get_vendor_type());
   305 
   307 
   306     view.PutL();
   308     view.PutL();
   307     	
   309     	
   308 	CleanupStack::PopAndDestroy(3); // view, colset, buf
   310 	CleanupStack::PopAndDestroy(colSet);
       
   311 	CleanupStack::PopAndDestroy(&view);
       
   312 	CleanupStack::PopAndDestroy(buf);
   309 }
   313 }
       
   314 
       
   315 // ----------------------------------------------------------
   310 
   316 
   311 void EapSimDbUtils::SetConfigurationL(
   317 void EapSimDbUtils::SetConfigurationL(
   312 	RDbNamedDatabase& aDatabase,
   318 	RDbNamedDatabase& aDatabase,
   313 	const EAPSettings& aSettings, 
   319 	const EAPSettings& aSettings, 
   314 	const TIndexType aIndexType,
   320 	const TIndexType aIndexType,
   315 	const TInt aIndex,
   321 	const TInt aIndex,
   316 	const eap_type_value_e aTunnelingType)
   322 	const eap_type_value_e aTunnelingType)
   317 {
   323 {
   318 #ifdef USE_EAP_EXPANDED_TYPES
   324 	EAP_TRACE_DEBUG_SYMBIAN(
   319 
   325 		(_L("EapSimDbUtils::SetConfigurationL(): -Start- aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
   320 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
   326 		aIndexType,
   321 
   327 		aIndex,
   322 #else
   328 		aTunnelingType.get_vendor_id(),
   323 
   329 		aTunnelingType.get_vendor_type()));
   324 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
   330 
   325 
   331     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapSimDbUtils::SetConfigurationL()\n"));
   326 #endif //#ifdef USE_EAP_EXPANDED_TYPES
   332 
   327 
   333 	EAP_TRACE_DEBUG_SYMBIAN((_L("*************************** SetConfigurationL(): Set the below values: ***************************\n")) );
   328 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::SetConfigurationL -Start- aIndexType=%d, aIndex=%d, aTunnelingVendorType=%d\n"),
   334 
   329 						aIndexType,aIndex, aTunnelingVendorType));
   335 	EAP_TRACE_SETTINGS(&aSettings);
   330 	
   336 
   331 	EAP_TRACE_DEBUG_SYMBIAN((_L("*************************** SetConfigurationL - Set the below values: ***************************\n")) );
   337 	EAP_TRACE_DEBUG_SYMBIAN((_L("*************************** SetConfigurationL(): Set the above values: ***************************\n")) );
   332 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - Set these values for EAPType=%d"),aSettings.iEAPType) );
       
   333 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, Username=%S"),aSettings.iUsernamePresent, &(aSettings.iUsername)) );
       
   334 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, Password=%S"),aSettings.iPasswordPresent, &(aSettings.iPassword)) );
       
   335 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, Realm=%S"),aSettings.iRealmPresent, &(aSettings.iRealm)) );
       
   336 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, UsePseudonyms=%d"),aSettings.iUsePseudonymsPresent, aSettings.iUsePseudonyms) );
       
   337 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, VerifyServerRealm=%d"),
       
   338 						aSettings.iVerifyServerRealmPresent, aSettings.iVerifyServerRealm) );
       
   339 
       
   340 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, RequireClientAuthentication=%d"),
       
   341 						aSettings.iRequireClientAuthenticationPresent, aSettings.iRequireClientAuthentication) );
       
   342 						
       
   343 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, SessionValidityTime=%d minutes"),
       
   344 						aSettings.iSessionValidityTimePresent, aSettings.iSessionValidityTime) );
       
   345 												
       
   346 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, CipherSuites Count=%d"),
       
   347 						aSettings.iCipherSuitesPresent, aSettings.iCipherSuites.Count()) );
       
   348 	
       
   349 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, PEAPv0Allowed=%d, PEAPv1Allowed=%d, PEAPv2Allowed=%d"),
       
   350 						aSettings.iPEAPVersionsPresent, aSettings.iPEAPv0Allowed,aSettings.iPEAPv1Allowed, aSettings.iPEAPv2Allowed ) );
       
   351 		
       
   352 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, Certificates Count=%d"),
       
   353 						aSettings.iCertificatesPresent, aSettings.iCertificates.Count()) );
       
   354 						
       
   355 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - Certificate details below: \n")) );
       
   356 	
       
   357 	for( TInt n=0; n < aSettings.iCertificates.Count(); n++ )
       
   358 	{
       
   359 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - Certificate type:%d \n"), aSettings.iCertificates[n].iCertType) );
       
   360 		
       
   361 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - certificates - present=%d, SubjectName=%S"),
       
   362 						aSettings.iCertificates[n].iSubjectNamePresent, &(aSettings.iCertificates[n].iSubjectName) ) );
       
   363 						
       
   364 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - certificates - present=%d, IssuerName=%S"),
       
   365 						aSettings.iCertificates[n].iIssuerNamePresent, &(aSettings.iCertificates[n].iIssuerName) ) );
       
   366 						
       
   367 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - certificates - present=%d, SerialNumber=%S"),
       
   368 						aSettings.iCertificates[n].iSerialNumberPresent, &(aSettings.iCertificates[n].iSerialNumber) ) );
       
   369 						
       
   370 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - certificates - SubjectKeyID present=%d"),
       
   371 						aSettings.iCertificates[n].iSubjectKeyIDPresent ) );						
       
   372 						
       
   373 		EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "SubjectKeyID:", aSettings.iCertificates[n].iSubjectKeyID.Ptr(), 
       
   374 													aSettings.iCertificates[n].iSubjectKeyID.Size() ) );
       
   375 						
       
   376 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - certificates - present=%d, Thumbprint=%S"),
       
   377 						aSettings.iCertificates[n].iThumbprintPresent, &(aSettings.iCertificates[n].iThumbprint) ) );
       
   378 	}						
       
   379 
       
   380 	EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - present=%d, EncapsulatedEAPTypes Count=%d"),
       
   381 						aSettings.iEncapsulatedEAPTypesPresent, aSettings.iEncapsulatedEAPTypes.Count()) );
       
   382 	for( TInt m=0; m < aSettings.iEncapsulatedEAPTypes.Count(); m++ )
       
   383 	{	
       
   384 		EAP_TRACE_DEBUG_SYMBIAN((_L("SetConfigurationL - EncapsulatedEAPTypes=%d"),
       
   385 						aSettings.iEncapsulatedEAPTypes[m]) );
       
   386 	}						
       
   387 
       
   388 	EAP_TRACE_DEBUG_SYMBIAN((_L("*************************** SetConfigurationL - Set the above values: ***************************\n")) );
       
   389 
   338 
   390 	// Check if the settings are for the correct type
   339 	// Check if the settings are for the correct type
   391 	if (aSettings.iEAPType != EAPSettings::EEapSim)
   340 	if (aSettings.iEAPExpandedType != (*EapExpandedTypeSim.GetType()))
   392 	{
   341 	{
   393 		User::Leave(KErrNotSupported);
   342 		User::Leave(KErrNotSupported);
   394 	}
   343 	}
   395 	
   344 	
   396 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   345 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   397 	TPtr sqlStatement = buf->Des();	
   346 	TPtr sqlStatement = buf->Des();	
   398 
   347 
   399 	RDbView view;
   348 	RDbView view;
   400 
   349 
   401 	_LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   350 	_LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   402 	sqlStatement.Format(KSQLQuery, &KSimTableName, 
   351 
   403 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   352 	sqlStatement.Format(KSQLQuery,
       
   353 		&KSimTableName, 
       
   354 		&KServiceType,
       
   355 		aIndexType,
       
   356 		&KServiceIndex,
       
   357 		aIndex,
       
   358 		&KTunnelingTypeVendorId,
       
   359 		aTunnelingType.get_vendor_id(),
       
   360 		&KTunnelingType, 
       
   361 		aTunnelingType.get_vendor_type());
   404 	
   362 	
   405 	// Evaluate view
   363 	// Evaluate view
   406 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
   364 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
   407 	
   365 	
   408 	CleanupClosePushL(view);
   366 	CleanupClosePushL(view);
   415 	
   373 	
   416 	// Get column set so we get the correct column numbers
   374 	// Get column set so we get the correct column numbers
   417 	CDbColSet* colSet = view.ColSetL();
   375 	CDbColSet* colSet = view.ColSetL();
   418 	CleanupStack::PushL(colSet);
   376 	CleanupStack::PushL(colSet);
   419 
   377 
       
   378 
       
   379 	if (aSettings.iUseAutomaticUsernamePresent)
       
   380 	{
       
   381 		// This is to set the automatic or manual status.
       
   382 		TUint useManualUsernameStatus;
       
   383 		
       
   384 		if (aSettings.iUseAutomaticUsername)
       
   385 		{
       
   386 			useManualUsernameStatus = EEapDbFalse;
       
   387 		}
       
   388 		else
       
   389 		{
       
   390 			useManualUsernameStatus = EEapDbTrue;
       
   391 		}
       
   392 		
       
   393 		// Set the value.
       
   394 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_username_literal), useManualUsernameStatus);
       
   395 	}
       
   396 
       
   397 
       
   398 	if (aSettings.iUseAutomaticRealmPresent)
       
   399 	{
       
   400 		// This is to set the automatic or manual status.
       
   401 		TUint useManualRealmStatus;
       
   402 		
       
   403 		if (aSettings.iUseAutomaticRealm)
       
   404 		{
       
   405 			useManualRealmStatus = EEapDbFalse;
       
   406 		}
       
   407 		else
       
   408 		{
       
   409 			useManualRealmStatus = EEapDbTrue;
       
   410 		}
       
   411 
       
   412 		// Set the value.
       
   413 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_realm_literal), useManualRealmStatus);
       
   414 	}
       
   415 
       
   416 
   420 	// Manual username
   417 	// Manual username
   421 	//if (aSettings.iUsernamePresent) // no need to check as there may be empty usernames with the present status is EFlase.
   418 	if (aSettings.iUsernamePresent) // no need to check as there may be empty usernames with the present status is EFlase.
   422 	{
   419 	{
   423 		// Check if length of username is less than the max length.
   420 		// Check if length of username is less than the max length.
   424 		if(aSettings.iUsername.Length() > KMaxManualUsernameLengthInDB)
   421 		if(aSettings.iUsername.Length() > KMaxUsernameLengthInDB)
   425 		{
   422 		{
   426 			// Username too long. Can not be stored in DB.
   423 			// Username too long. Can not be stored in DB.
   427 			
   424 			
   428 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::SetConfigurationL: Too long Username. Length=%d \n"),
   425 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::SetConfigurationL: Too long Username. Length=%d \n"),
   429 			aSettings.iUsername.Length()));
   426 			aSettings.iUsername.Length()));
   431 			User::Leave(KErrArgument);
   428 			User::Leave(KErrArgument);
   432 		}
   429 		}
   433 		
   430 		
   434 		// Length is ok. Set the value in DB. Value could be empty. It doesn't matter.
   431 		// Length is ok. Set the value in DB. Value could be empty. It doesn't matter.
   435 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_manual_username_literal), aSettings.iUsername);
   432 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_manual_username_literal), aSettings.iUsername);
   436 		
       
   437 		// This is to set the automatic or manual status.
       
   438 		TUint useManualUsernameStatus;
       
   439 		
       
   440 		if (aSettings.iUsernamePresent)
       
   441 		{
       
   442 			useManualUsernameStatus = EGSMSIMUseManualUsernameYes;
       
   443 		}
       
   444 		else
       
   445 		{
       
   446 			useManualUsernameStatus = EGSMSIMUseManualUsernameNo;
       
   447 		}
       
   448 		
       
   449 		// Set the value.
       
   450 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_username_literal), useManualUsernameStatus);
       
   451 	}
   433 	}
   452 		
   434 		
   453 	// Manual realm
   435 	// Manual realm
   454 	//if (aSettings.iRealmPresent)  // no need to check as there may be empty realms with the present status is EFlase.
   436 	if (aSettings.iRealmPresent)  // no need to check as there may be empty realms with the present status is EFlase.
   455 	{
   437 	{
   456 		// Check if length of realm is less than the max length.
   438 		// Check if length of realm is less than the max length.
   457 		if(aSettings.iRealm.Length() > KMaxManualRealmLengthInDB)
   439 		if(aSettings.iRealm.Length() > KMaxRealmLengthInDB)
   458 		{
   440 		{
   459 			// Realm too long. Can not be stored in DB.
   441 			// Realm too long. Can not be stored in DB.
   460 
   442 
   461 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::SetConfigurationL: Too long Realm. Length=%d \n"),
   443 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::SetConfigurationL: Too long Realm. Length=%d \n"),
   462 			aSettings.iRealm.Length()));
   444 			aSettings.iRealm.Length()));
   464 			User::Leave(KErrArgument);
   446 			User::Leave(KErrArgument);
   465 		}
   447 		}
   466 
   448 
   467 		// Length is ok. Set the value in DB. Value could be empty. It doesn't matter.
   449 		// Length is ok. Set the value in DB. Value could be empty. It doesn't matter.
   468 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_manual_realm_literal), aSettings.iRealm);
   450 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_manual_realm_literal), aSettings.iRealm);
   469 		
       
   470 		// This is to set the automatic or manual status.
       
   471 		TUint useManualRealmStatus;
       
   472 		
       
   473 		if (aSettings.iRealmPresent)
       
   474 		{
       
   475 			useManualRealmStatus = EGSMSIMUseManualRealmYes;
       
   476 		}
       
   477 		else
       
   478 		{
       
   479 			useManualRealmStatus = EGSMSIMUseManualRealmNo;
       
   480 		}
       
   481 		
       
   482 		// Set the value.
       
   483 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_realm_literal), useManualRealmStatus);	
       
   484 	}
   451 	}
   485 	
   452 	
   486 	// UsePseudonym
   453 	// UsePseudonym
   487 	if (aSettings.iUsePseudonymsPresent)
   454 	if (aSettings.iUsePseudonymsPresent)
   488 	{
   455 	{
   489 		if (aSettings.iUsePseudonyms)
   456 		if (aSettings.iUsePseudonyms)
   490 		{
   457 		{
   491 			// Use pseudonym.
   458 			// Use pseudonym.
   492 			view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_pseudonym_identity_literal), EGSMSIMUsePseudonymIdYes);
   459 			view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_pseudonym_identity_literal), EEapDbTrue);
   493 		}
   460 		}
   494 		else
   461 		else
   495 		{			
   462 		{			
   496 			// Don't use pseudonym.
   463 			// Don't use pseudonym.
   497 			view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_pseudonym_identity_literal), EGSMSIMUsePseudonymIdNo);			
   464 			view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_pseudonym_identity_literal), EEapDbFalse);			
   498 		}
   465 		}
   499 	}
   466 	}
   500 	else
   467 	else
   501 	{
   468 	{
   502 		// Value is not configured. Value is read from config file if needed.
   469 		// Value is not configured. Value is read from config file if needed.
   503 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_pseudonym_identity_literal), EGSMSIMUsePseudonymIdNotValid);		
   470 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_use_pseudonym_identity_literal), EEapDbNotValid);		
   504 	}
   471 	}
   505 	
   472 
   506 	// Session validity time
   473 	// Session validity time
   507 	if (aSettings.iSessionValidityTimePresent)
   474 	if (aSettings.iSessionValidityTimePresent)
   508 	{
   475 	{
   509 		// User or device management wants to store the session validity time.
   476 		// User or device management wants to store the session validity time.
   510 		// Convert the time to micro seconds and save.
   477 		// Convert the time to micro seconds and save.
   511 		
   478 		
   512 		TInt64 validityInMicro = (aSettings.iSessionValidityTime) *  KMicroSecsInAMinute;
   479 		TInt64 validityInMicro = (aSettings.iSessionValidityTime) *  KMicroSecsInAMinute;
   513 		
   480 		
   514 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_max_session_validity_time_literal), validityInMicro);
   481 		view.SetColL(colSet->ColNo(cf_str_EAP_GSMSIM_max_session_validity_time_literal), validityInMicro);
   515 	}
   482 	}
   516 	
   483 
   517 	if (aIndexType != EVpn) // This allows current VPN IF to use reauthentication. VPN does not zero last full authentication time.
   484 	if (aIndexType != EVpn) // This allows current VPN IF to use reauthentication. VPN does not zero last full authentication time.
   518 	{
   485 	{
   519 		// Last full authentication time should be made zero when EAP configurations are modified.
   486 		// Last full authentication time should be made zero when EAP configurations are modified.
   520 		// This makes sure that the next authentication with this EAP would be full authentication
   487 		// This makes sure that the next authentication with this EAP would be full authentication
   521 		// instead of reauthentication even if the session is still valid.
   488 		// instead of reauthentication even if the session is still valid.
   522 		
   489 
   523 		view.SetColL(colSet->ColNo(KGSMSIMLastFullAuthTime), default_FullAuthTime);
   490 		view.SetColL(colSet->ColNo(KGSMSIMLastFullAuthTime), default_FullAuthTime);
   524 
   491 
   525 		EAP_TRACE_DEBUG_SYMBIAN((_L("Session Validity: EAP-Type=%d, Resetting Full Auth Time since settings are modified\n"),
   492 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::SetConfigurationL(): Session Validity: Resetting Full Auth Time since settings are modified\n")));
   526 									aSettings.iEAPType ));
   493 	}
   527 	}
   494 
   528 	
       
   529 	view.PutL();
   495 	view.PutL();
   530 	CleanupStack::PopAndDestroy(3); // view, colset, buf
   496 
       
   497 	CleanupStack::PopAndDestroy(colSet);
       
   498 	CleanupStack::PopAndDestroy(&view);
       
   499 	CleanupStack::PopAndDestroy(buf);
   531 }
   500 }
       
   501 
       
   502 // ----------------------------------------------------------
   532 
   503 
   533 void EapSimDbUtils::GetConfigurationL(
   504 void EapSimDbUtils::GetConfigurationL(
   534 	RDbNamedDatabase& aDatabase,
   505 	RDbNamedDatabase& aDatabase,
   535 	EAPSettings& aSettings, 
   506 	EAPSettings& aSettings, 
   536 	const TIndexType aIndexType,
   507 	const TIndexType aIndexType,
   537 	const TInt aIndex,
   508 	const TInt aIndex,
   538 	const eap_type_value_e aTunnelingType)
   509 	const eap_type_value_e aTunnelingType)
   539 {
   510 {
   540 #ifdef USE_EAP_EXPANDED_TYPES
   511 	EAP_TRACE_DEBUG_SYMBIAN(
   541 
   512 		(_L("EapSimDbUtils::GetConfigurationL(): -Start- aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
   542 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
   513 		aIndexType,
   543 
   514 		aIndex,
   544 #else
   515 		aTunnelingType.get_vendor_id(),
   545 
   516 		aTunnelingType.get_vendor_type()));
   546 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
   517 
   547 
   518     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapSimDbUtils::GetConfigurationL()\n"));
   548 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
   549 
   519 
   550 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   520 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   551 	TPtr sqlStatement = buf->Des();	
   521 	TPtr sqlStatement = buf->Des();	
   552 
   522 
   553 	RDbView view;
   523 	RDbView view;
   554 
   524 
   555 	// Form the query
   525 	// Form the query
   556 	_LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   526 	_LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   557 	sqlStatement.Format(KSQLQuery, &KSimTableName, 
   527 
   558 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   528 	sqlStatement.Format(KSQLQuery,
       
   529 		&KSimTableName, 
       
   530 		&KServiceType,
       
   531 		aIndexType,
       
   532 		&KServiceIndex,
       
   533 		aIndex,
       
   534 		&KTunnelingTypeVendorId,
       
   535 		aTunnelingType.get_vendor_id(),
       
   536 		&KTunnelingType, 
       
   537 		aTunnelingType.get_vendor_type());
   559 	
   538 	
   560 	// Evaluate view
   539 	// Evaluate view
   561 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
   540 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
   562 	
   541 	
   563 	CleanupClosePushL(view);
   542 	CleanupClosePushL(view);
   570 	
   549 	
   571 	// Get column set so we get the correct column numbers
   550 	// Get column set so we get the correct column numbers
   572 	CDbColSet* colSet = view.ColSetL();
   551 	CDbColSet* colSet = view.ColSetL();
   573 	CleanupStack::PushL(colSet);
   552 	CleanupStack::PushL(colSet);
   574 
   553 
   575 	aSettings.iEAPType = EAPSettings::EEapSim;
   554 	aSettings.iEAPExpandedType = *EapExpandedTypeSim.GetType();
   576 	
   555 
   577 	// Username
   556 	{
   578 	TPtrC username = view.ColDes(colSet->ColNo(cf_str_EAP_GSMSIM_manual_username_literal));
   557 		// For manual or automatic username.
   579 	aSettings.iUsername.Copy(username);
   558 		TUint useUsername = view.ColUint(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_username_literal));
   580 	
   559 
   581 	// For manual or automatic status.
   560 		aSettings.iUseAutomaticUsernamePresent = ETrue;
   582 	TUint useUsername = view.ColUint(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_username_literal));
   561 
   583 	if(useUsername == EGSMSIMUseManualUsernameNo)
   562 		if(useUsername == EEapDbTrue)
   584 	{
   563 		{
   585 		aSettings.iUsernamePresent = EFalse;		
   564 			aSettings.iUseAutomaticUsername = EFalse;		
   586 	}
   565 		}
   587 	else
   566 		else
   588 	{
   567 		{
   589 		aSettings.iUsernamePresent = ETrue;		
   568 			aSettings.iUseAutomaticUsername = ETrue;		
   590 	}
   569 		}
   591 	
   570 	}
   592 	// Realm
   571 
   593 	TPtrC realm = view.ColDes(colSet->ColNo(cf_str_EAP_GSMSIM_manual_realm_literal));
   572 	{
   594 	aSettings.iRealm.Copy(realm);
   573 		// For manual or automatic realm.
   595 	
   574 		TUint useRealm = view.ColUint(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_realm_literal));
   596 	// For manual or automatic status.
   575 
   597 	TUint useRealm = view.ColUint(colSet->ColNo(cf_str_EAP_GSMSIM_use_manual_realm_literal));
   576 		aSettings.iUseAutomaticRealmPresent = ETrue;
   598 	if(useRealm == EGSMSIMUseManualRealmNo)
   577 
   599 	{
   578 		if(useRealm == EEapDbTrue)
   600 		aSettings.iRealmPresent = EFalse;
   579 		{
   601 	}
   580 			aSettings.iUseAutomaticRealm = EFalse;
   602 	else
   581 		}
   603 	{
   582 		else
       
   583 		{
       
   584 			aSettings.iUseAutomaticRealm = ETrue;
       
   585 		}
       
   586 	}
       
   587 
       
   588 	{
       
   589 		// Username
       
   590 		TPtrC username = view.ColDes(colSet->ColNo(cf_str_EAP_GSMSIM_manual_username_literal));
       
   591 
       
   592 		aSettings.iUsernamePresent = ETrue;
       
   593 
       
   594 		aSettings.iUsername.Copy(username);
       
   595 	}
       
   596 
       
   597 	{
       
   598 		// Realm
       
   599 		TPtrC realm = view.ColDes(colSet->ColNo(cf_str_EAP_GSMSIM_manual_realm_literal));
       
   600 
   604 		aSettings.iRealmPresent = ETrue;
   601 		aSettings.iRealmPresent = ETrue;
   605 	}
   602 
   606 	
   603 		aSettings.iRealm.Copy(realm);
   607 	TInt usePseudonym = view.ColUint(colSet->ColNo(cf_str_EAP_GSMSIM_use_pseudonym_identity_literal));
   604 	}
   608 	
   605 
   609 	if (usePseudonym == EGSMSIMUsePseudonymIdNotValid)
   606 	{
   610 	{
   607 		TInt usePseudonym = view.ColUint(colSet->ColNo(cf_str_EAP_GSMSIM_use_pseudonym_identity_literal));
   611 		aSettings.iUsePseudonymsPresent = EFalse;
   608 		
   612 	}
   609 		if (usePseudonym == EEapDbNotValid)
   613 	else
   610 		{
   614 	{
   611 			aSettings.iUsePseudonymsPresent = EFalse;
   615 		if (usePseudonym == EGSMSIMUsePseudonymIdNo)
       
   616 		{
       
   617 			aSettings.iUsePseudonyms = EFalse;
       
   618 		}
   612 		}
   619 		else
   613 		else
   620 		{
   614 		{
   621 			aSettings.iUsePseudonyms = ETrue;
   615 			if (usePseudonym == EEapDbFalse)
   622 		}
   616 			{
   623 		
   617 				aSettings.iUsePseudonyms = EFalse;
   624 		aSettings.iUsePseudonymsPresent = ETrue;		
   618 			}
   625 	}	
   619 			else
   626 	
   620 			{
   627 	// Session validity time	
   621 				aSettings.iUsePseudonyms = ETrue;
   628 	TInt64 maxSessionTimeMicro = view.ColInt64(colSet->ColNo(cf_str_EAP_GSMSIM_max_session_validity_time_literal));
   622 			}
   629 	
   623 			
   630 	// Convert the time to minutes.	
   624 			aSettings.iUsePseudonymsPresent = ETrue;		
   631 	TInt64 maxSessionTimeMin = maxSessionTimeMicro / KMicroSecsInAMinute;
   625 		}	
   632 	
   626 	}
   633 	aSettings.iSessionValidityTime = static_cast<TUint>(maxSessionTimeMin);
   627 
   634 	aSettings.iSessionValidityTimePresent = ETrue;
   628 	{
   635 	
   629 		// Session validity time	
   636 	CleanupStack::PopAndDestroy(3); // view, colset, buf
   630 		TInt64 maxSessionTimeMicro = view.ColInt64(colSet->ColNo(cf_str_EAP_GSMSIM_max_session_validity_time_literal));
       
   631 		
       
   632 		// Convert the time to minutes.	
       
   633 		TInt64 maxSessionTimeMin = maxSessionTimeMicro / KMicroSecsInAMinute;
       
   634 		
       
   635 		aSettings.iSessionValidityTime = static_cast<TUint>(maxSessionTimeMin);
       
   636 		aSettings.iSessionValidityTimePresent = ETrue;
       
   637 	}
       
   638 
       
   639 	CleanupStack::PopAndDestroy(colSet);
       
   640 	CleanupStack::PopAndDestroy(&view);
       
   641 	CleanupStack::PopAndDestroy(buf);
       
   642 
       
   643 	EAP_TRACE_SETTINGS(&aSettings);
   637 }
   644 }
       
   645 
       
   646 // ----------------------------------------------------------
   638 
   647 
   639 void EapSimDbUtils::CopySettingsL(
   648 void EapSimDbUtils::CopySettingsL(
   640 	RDbNamedDatabase& aDatabase, 		
   649 	RDbNamedDatabase& aDatabase, 		
   641 	const TIndexType aSrcIndexType,
   650 	const TIndexType aSrcIndexType,
   642 	const TInt aSrcIndex,
   651 	const TInt aSrcIndex,
   643 	const eap_type_value_e aSrcTunnelingType,
   652 	const eap_type_value_e aSrcTunnelingType,
   644 	const TIndexType aDestIndexType,
   653 	const TIndexType aDestIndexType,
   645 	const TInt aDestIndex,
   654 	const TInt aDestIndex,
   646 	const eap_type_value_e aDestTunnelingType)
   655 	const eap_type_value_e aDestTunnelingType)
   647 {
   656 {
   648 #ifdef USE_EAP_EXPANDED_TYPES
   657 	EAP_TRACE_DEBUG_SYMBIAN(
   649 
   658 		(_L("EapSimDbUtils::CopySettingsL(): -Start- aSrcIndexType=%d, aSrcIndex=%d, aSrcTunnelingType=0xfe%06x%08x\n"),
   650 	TUint aSrcTunnelingVendorType = aSrcTunnelingType.get_vendor_type();
   659 		aSrcIndexType,
   651 	TUint aDestTunnelingVendorType = aDestTunnelingType.get_vendor_type();
   660 		aSrcIndex,
   652 
   661 		aSrcTunnelingType.get_vendor_id(),
   653 #else
   662 		aSrcTunnelingType.get_vendor_type()));
   654 
   663 	
   655 	TUint aSrcTunnelingVendorType = static_cast<TUint>(aSrcTunnelingType);
   664 	EAP_TRACE_DEBUG_SYMBIAN(
   656 	TUint aDestTunnelingVendorType = static_cast<TUint>(aDestTunnelingType);
   665 		(_L("EapSimDbUtils::CopySettingsL(): -Start- aDestIndexType=%d, aDestTunnelingType=0xfe%06x%08x\n"),
   657 
   666 		aDestIndexType,
   658 #endif //#ifdef USE_EAP_EXPANDED_TYPES
   667 		aDestIndex,
       
   668 		aDestTunnelingType.get_vendor_id(),
       
   669 		aDestTunnelingType.get_vendor_type()));
       
   670 
       
   671     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapSimDbUtils::CopySettingsL()\n"));
   659 
   672 
   660 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   673 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   661 	TPtr sqlStatement = buf->Des();
   674 	TPtr sqlStatement = buf->Des();
   662 
   675 
   663 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   676 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   664 
   677 
   665 	sqlStatement.Format(KSQL, &KSimTableName, 
   678 	sqlStatement.Format(KSQL,
   666 		&KServiceType, aSrcIndexType, &KServiceIndex, aSrcIndex, &KTunnelingType, aSrcTunnelingVendorType);
   679 		&KSimTableName, 
       
   680 		&KServiceType,
       
   681 		aSrcIndexType,
       
   682 		&KServiceIndex,
       
   683 		aSrcIndex,
       
   684 		&KTunnelingTypeVendorId,
       
   685 		aSrcTunnelingType.get_vendor_id(),
       
   686 		&KTunnelingType, 
       
   687 		aSrcTunnelingType.get_vendor_type());
   667 	
   688 	
   668 	RDbView view;
   689 	RDbView view;
   669 	
   690 	
   670 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   691 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   671 	
   692 	
   692 	CDbColSet* colSet = view.ColSetL();
   713 	CDbColSet* colSet = view.ColSetL();
   693 	
   714 	
   694 	CleanupStack::PushL(colSet);
   715 	CleanupStack::PushL(colSet);
   695 		
   716 		
   696 	view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aDestIndexType));
   717 	view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aDestIndexType));
   697     
       
   698     view.SetColL(colSet->ColNo(KServiceIndex), aDestIndex);
   718     view.SetColL(colSet->ColNo(KServiceIndex), aDestIndex);
   699     
   719 	view.SetColL(colSet->ColNo(KTunnelingTypeVendorId), aDestTunnelingType.get_vendor_id());
   700     view.SetColL(colSet->ColNo(KTunnelingType), aDestTunnelingVendorType);
   720 	view.SetColL(colSet->ColNo(KTunnelingType), aDestTunnelingType.get_vendor_type());
   701 
   721 
   702     view.PutL();
   722     view.PutL();
   703     	
   723     	
   704 	CleanupStack::PopAndDestroy(3); // view, colset, buf
   724 	CleanupStack::PopAndDestroy(colSet);
       
   725 	CleanupStack::PopAndDestroy(&view);
       
   726 	CleanupStack::PopAndDestroy(buf);
   705 }
   727 }
       
   728 
       
   729 // ----------------------------------------------------------
   706 
   730 
   707 void EapSimDbUtils::DeleteConfigurationL(	
   731 void EapSimDbUtils::DeleteConfigurationL(	
   708 	const TIndexType aIndexType,
   732 	const TIndexType aIndexType,
   709 	const TInt aIndex,
   733 	const TInt aIndex,
   710 	const eap_type_value_e aTunnelingType)
   734 	const eap_type_value_e aTunnelingType)
   711 {
   735 {
   712 #ifdef USE_EAP_EXPANDED_TYPES
   736 	EAP_TRACE_DEBUG_SYMBIAN(
   713 
   737 		(_L("EapSimDbUtils::DeleteConfigurationL(): -Start- aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
   714 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
   738 		aIndexType,
   715 
   739 		aIndex,
   716 #else
   740 		aTunnelingType.get_vendor_id(),
   717 
   741 		aTunnelingType.get_vendor_type()));
   718 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
   742 
   719 
   743     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapSimDbUtils::DeleteConfigurationL()\n"));
   720 #endif //#ifdef USE_EAP_EXPANDED_TYPES
   744 
   721 
   745 	RDbNamedDatabase aDatabase;
   722 	RDbs session;
   746 	RFs aFileServerSession;
   723 	RDbNamedDatabase database;
   747 
   724 	// Connect to the DBMS server.
   748 	TInt error(KErrNone);
   725 	User::LeaveIfError(session.Connect());
   749 	TFileName aPrivateDatabasePathName;
   726 	CleanupClosePushL(session);	
   750 	
   727 		
   751 	error = aFileServerSession.Connect();
   728 #ifdef SYMBIAN_SECURE_DBMS
   752 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::DeleteConfigurationL(): - aFileServerSession.Connect(), error=%d\n"), error));
   729 	
   753 	User::LeaveIfError(error);
   730 	// Create the secure shared database with the specified secure policy.
   754 
   731 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
   755 	EapPluginTools::CreateDatabaseLC(
   732 	
   756 		aDatabase,
   733 	TInt err = database.Create(session, KDatabaseName, KSecureUIDFormat);
   757 		aFileServerSession,
   734 	
   758 		error,
   735 	if(err == KErrNone)
   759 		KEapSimDatabaseName,
       
   760 		aPrivateDatabasePathName);
       
   761 
       
   762 	if(error == KErrNone)
   736 	{
   763 	{
   737 		// Database was created so it was empty. No need for further actions.
   764 		// Database was created so it was empty. No need for further actions.
   738 		database.Destroy();
   765 		aDatabase.Destroy();
   739 		CleanupStack::PopAndDestroy();
   766 		CleanupStack::PopAndDestroy(&aDatabase);
       
   767 		CleanupStack::PopAndDestroy(&aFileServerSession);
   740 		return;
   768 		return;
   741 		
   769 	}
   742 	} 
   770 	else if (error != KErrAlreadyExists) 
   743 	else if (err != KErrAlreadyExists) 
   771 	{
   744 	{
   772 		User::LeaveIfError(error);
   745 		User::LeaveIfError(err);
   773 	}
   746 	}
   774 	
   747 	
   775 	error = aDatabase.Open(aFileServerSession, aPrivateDatabasePathName);
   748 	// Database existed, open it.
   776 
   749 	User::LeaveIfError(database.Open(session, KDatabaseName, KSecureUIDFormat));
   777 	User::LeaveIfError(error);
   750 	CleanupClosePushL(database);
       
   751 		
       
   752 #else
       
   753 	// For non-secured database. The database will be created in the old location (c:\system\data).
       
   754 	
       
   755 	RFs fsSession;		
       
   756 	User::LeaveIfError(fsSession.Connect());
       
   757 	CleanupClosePushL(fsSession);	
       
   758 	TInt err = database.Create(fsSession, KDatabaseName);
       
   759 
       
   760 	if(err == KErrNone)
       
   761 	{
       
   762 		// Database was created so it was empty. No need for further actions.
       
   763 		database.Destroy();
       
   764 		CleanupStack::PopAndDestroy(2); // fsSession, database session
       
   765 		return;
       
   766 		
       
   767 	} 
       
   768 	else if (err != KErrAlreadyExists) 
       
   769 	{
       
   770 		User::LeaveIfError(err);
       
   771 	}
       
   772 	
       
   773 	CleanupStack::PopAndDestroy(); // close fsSession
       
   774 	
       
   775 	User::LeaveIfError(database.Open(session, KDatabaseName));
       
   776 	CleanupClosePushL(database);		
       
   777 	    
       
   778 #endif // #ifdef SYMBIAN_SECURE_DBMS
       
   779 
   778 
   780 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   779 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   781 	TPtr sqlStatement = buf->Des();
   780 	TPtr sqlStatement = buf->Des();
   782 
   781 
   783 	// Main settings table
   782 	// Main settings table
   784 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   783 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   785 	sqlStatement.Format(KSQL, &KSimTableName, 
   784 
   786 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   785 	sqlStatement.Format(
       
   786 		KSQL,
       
   787 		&KSimTableName, 
       
   788 		&KServiceType,
       
   789 		aIndexType,
       
   790 		&KServiceIndex,
       
   791 		aIndex,
       
   792 		&KTunnelingTypeVendorId,
       
   793 		aTunnelingType.get_vendor_id(),
       
   794 		&KTunnelingType, 
       
   795 		aTunnelingType.get_vendor_type());
       
   796 
   787 	// Evaluate view
   797 	// Evaluate view
   788 	RDbView view;
   798 	RDbView view;
   789 	User::LeaveIfError(view.Prepare(database,TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   799 
       
   800 	error = view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited);
       
   801 
       
   802 	User::LeaveIfError(error);
       
   803 
   790 	CleanupClosePushL(view);
   804 	CleanupClosePushL(view);
   791 	User::LeaveIfError(view.EvaluateAll());
   805 
       
   806 	error = view.EvaluateAll();
       
   807 
       
   808 	User::LeaveIfError(error);
   792 
   809 
   793 	// Delete rows
   810 	// Delete rows
   794 	if (view.FirstL())
   811 	if (view.FirstL())
   795 	{		
   812 	{		
   796 		do {
   813 		do
       
   814 		{
       
   815 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::DeleteConfigurationL(): calls view.DeleteL()\n")));
       
   816 
   797 			view.DeleteL();
   817 			view.DeleteL();
   798 		} while (view.NextL() != EFalse);
   818 		}
   799 	}
   819 		while (view.NextL() != EFalse);
   800 
   820 
   801 	// Close database
   821 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::DeleteConfigurationL(): All rows deleted.\n")));
   802 	CleanupStack::PopAndDestroy(4); // view, buf, database, session
   822 	}
       
   823 	else
       
   824 	{
       
   825 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapSimDbUtils::DeleteConfigurationL(): No rows to delete.\n")));
       
   826 	}
       
   827 
       
   828 	CleanupStack::PopAndDestroy(&view);
       
   829 	CleanupStack::PopAndDestroy(buf);
       
   830 	CleanupStack::PopAndDestroy(&aDatabase);
       
   831 	CleanupStack::PopAndDestroy(&aFileServerSession);
   803 }
   832 }
   804 
   833 
       
   834 // ----------------------------------------------------------
       
   835 
   805 // End of file
   836 // End of file