eapol/eapol_framework/eapol_symbian/am/type/tls_peap/symbian/plugin/src/EapTlsPeapUiConnection.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
--- a/eapol/eapol_framework/eapol_symbian/am/type/tls_peap/symbian/plugin/src/EapTlsPeapUiConnection.cpp	Tue Aug 31 15:16:37 2010 +0300
+++ b/eapol/eapol_framework/eapol_symbian/am/type/tls_peap/symbian/plugin/src/EapTlsPeapUiConnection.cpp	Wed Sep 01 12:23:57 2010 +0100
@@ -16,7 +16,7 @@
 */
 
 /*
-* %version: 35 %
+* %version: 24.1.2 %
 */
 
 // This is enumeration of EAPOL source code.
@@ -27,136 +27,137 @@
 	#define EAP_FILE_NUMBER_DATE 1127594498 
 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
 
-//#include "EapTlsPeapUtils.h"
+#include "EapTlsPeapUtils.h"
 #include <EapTlsPeapUiConnection.h>
 #include <EapTlsPeapUiDataConnection.h>
 #include <EapTlsPeapUiCipherSuites.h>
 #include <EapTlsPeapUiEapTypes.h>
 #include <EapTlsPeapUiCertificates.h>
 #include <AbsEapTlsPeapUiCertificates.h>
-#include "EapTraceSymbian.h"
+#include "eap_am_trace_symbian.h"
 
 #ifdef USE_PAC_STORE
-#include "EapFastPacStore.h"
+#include "pac_store_db_symbian.h"
 #endif
 
-// ----------------------------------------------------------
-
 CEapTlsPeapUiConnection::CEapTlsPeapUiConnection(
     const TIndexType aIndexType,
     const TInt aIndex,
-    const TEapExpandedType aTunnelingType,
-	const TEapExpandedType aEapType)
+    const TInt aTunnelingType,
+	const TInt aEapType)
     : iIndexType(aIndexType)
     , iIndex(aIndex)
     , iTunnelingType(aTunnelingType)
     , iEapType(aEapType)
+    , iIsConnected(EFalse)
     , iDataConn(NULL)
     , iCipherSuites(NULL)
     , iEapTypes(NULL)
     , iCertificates(NULL)
     , iPacStoreDb(NULL)
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::CEapTlsPeapUiConnection()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::CEapTlsPeapUiConnection()\n"));
-
 }
 
-// ----------------------------------------------------------
 
 CEapTlsPeapUiConnection::~CEapTlsPeapUiConnection()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::~CEapTlsPeapUiConnection()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::~CEapTlsPeapUiConnection()\n"));
-
 #ifdef USE_PAC_STORE
 	delete iPacStoreDb;
 #endif
 }
 
-// ----------------------------------------------------------
-
 TInt CEapTlsPeapUiConnection::Connect()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::Connect()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::Connect()\n"));
-
+	if(iIsConnected)
+	{
+		// Already connected.
+		return KErrNone;
+	}
+	
 	TRAPD(err, ConnectL());
 	if(err == KErrNone)
 	{
+		iIsConnected = ETrue;
 	}
 	
 	return err;
 }
 
-// ----------------------------------------------------------
-
 void CEapTlsPeapUiConnection::ConnectL()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::ConnectL()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::ConnectL()\n"));
+#ifdef USE_EAP_EXPANDED_TYPES
+
+	eap_type_value_e tunnelingType(static_cast<eap_type_ietf_values_e>(iTunnelingType));
+	eap_type_value_e eapType(static_cast<eap_type_ietf_values_e>(iEapType));
+
+#else
+
+	eap_type_value_e tunnelingType = static_cast<eap_type_value_e>(iTunnelingType);
+	eap_type_value_e eapType = static_cast<eap_type_value_e>(iEapType);
+
+#endif //#ifdef USE_EAP_EXPANDED_TYPES
 
 #ifdef USE_PAC_STORE
 #ifdef USE_FAST_EAP_TYPE
 	
-	if(iEapType == *EapExpandedTypeFast.GetType() && iPacStoreDb == NULL)
+	if(iEapType == eap_type_fast && iPacStoreDb == NULL)
 	{
-		EAP_TRACE_DEBUG_SYMBIAN(
-			(_L("CEapTlsPeapUiConnection::ConnectL() CEapFastPacStore::NewL()")));	
-		iPacStoreDb = CEapFastPacStore::NewL();
+		iPacStoreDb = CPacStoreDatabase::NewL();
 		User::LeaveIfNull(iPacStoreDb);
 		
 		EAP_TRACE_DEBUG_SYMBIAN(
 			(_L("CEapTlsPeapUiConnection::Connect Created PAC store")));	
 		
 		iPacStoreDb->OpenPacStoreL();
-
+		iPacStoreDb->CreateDeviceSeed( NULL );
 		EAP_TRACE_DEBUG_SYMBIAN(
 			(_L("CEapTlsPeapUiConnection::Connect Opened PAC store")));	
-
-		iPacStoreDb->CreateDeviceSeedL();
-
-		EAP_TRACE_DEBUG_SYMBIAN(
-			(_L("CEapTlsPeapUiConnection::Connect Created device seed")));	
 	}
 	
 #endif	// End: #ifdef USE_FAST_EAP_TYPE
 #endif // End: 	#ifdef USE_PAC_STORE
 
+	// Open or create the databse where all the settings are stored.
+	EapTlsPeapUtils::OpenDatabaseL(
+		iDbNamedDatabase, 
+		iDbs, 
+		iIndexType,
+		iIndex, 
+		tunnelingType, 
+		eapType);
 }
 
-// ----------------------------------------------------------
 
 TInt CEapTlsPeapUiConnection::Close()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::Close()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::Close()\n"));
+    if (iIsConnected)
+    {    	
 
 #ifdef USE_PAC_STORE    	
 
 #ifdef USE_FAST_EAP_TYPE
 	
-	if(iEapType == *EapExpandedTypeFast.GetType()
-		&& iPacStoreDb != NULL)
-	{
-		delete iPacStoreDb;
-		iPacStoreDb = NULL;
-	}
-
+		if(iEapType == eap_type_fast && iPacStoreDb != NULL)
+		{
+			iPacStoreDb->Close();
+		}
 #endif	// End: #ifdef USE_FAST_EAP_TYPE		
 	
 #endif	// End: #ifdef USE_PAC_STORE
+	
+        iDbNamedDatabase.Close();
+        
+        iDbs.Close(); // Both the Dbs are closed and server can be closed now.
+    }
     
+    iIsConnected = EFalse;
+
     return KErrNone;
 }
 
-// ----------------------------------------------------------
 
 CEapTlsPeapUiDataConnection * CEapTlsPeapUiConnection::GetDataConnection()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::GetDataConnection()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::GetDataConnection()\n"));
-
     if (!iDataConn)
     {
         iDataConn = new CEapTlsPeapUiDataConnection(this);
@@ -165,13 +166,9 @@
     return iDataConn;
 }
 
-// ----------------------------------------------------------
 
 CEapTlsPeapUiCipherSuites * CEapTlsPeapUiConnection::GetCipherSuiteConnection()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::GetCipherSuiteConnection()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::GetCipherSuiteConnection()\n"));
-
     if (!iCipherSuites)
     {
         iCipherSuites = new CEapTlsPeapUiCipherSuites(this);
@@ -180,13 +177,9 @@
     return iCipherSuites;
 }
 	
-// ----------------------------------------------------------
-
+	
 CEapTlsPeapUiCertificates * CEapTlsPeapUiConnection::GetCertificateConnection(MEapTlsPeapUiCertificates * const aParent)
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::GetCertificateConnection()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::GetCertificateConnection()\n"));
-
     if (!iCertificates)
     {
         iCertificates = new CEapTlsPeapUiCertificates(this, aParent);
@@ -195,14 +188,9 @@
     return iCertificates;
 }
 	
-// ----------------------------------------------------------
-
-
+	
 CEapTlsPeapUiEapTypes * CEapTlsPeapUiConnection::GetEapTypeConnection()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::GetEapTypeConnection()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::GetEapTypeConnection()\n"));
-
     if (!iEapTypes)
     {
         iEapTypes = new CEapTlsPeapUiEapTypes(this);
@@ -211,60 +199,50 @@
     return iEapTypes;
 }
 	
-// ----------------------------------------------------------
+	
+TInt CEapTlsPeapUiConnection::GetDatabase(RDbNamedDatabase & aDatabase)
+{
+    if (iIsConnected == EFalse)
+    {
+        return KErrSessionClosed;
+    }
+
+    aDatabase = iDbNamedDatabase;
+    return KErrNone;
+}
+
 
 TIndexType CEapTlsPeapUiConnection::GetIndexType()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::GetIndexType()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::GetIndexType()\n"));
-
     return iIndexType;
 }
 
-// ----------------------------------------------------------
 
 TInt CEapTlsPeapUiConnection::GetIndex()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::GetIndex()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::GetIndex()\n"));
-
     return iIndex;
 }
 
-// ----------------------------------------------------------
-
-TEapExpandedType CEapTlsPeapUiConnection::GetTunnelingType()
+TInt CEapTlsPeapUiConnection::GetTunnelingType()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::GetTunnelingType()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::GetTunnelingType()\n"));
-
     return iTunnelingType;
 }
 
-// ----------------------------------------------------------
-
-TEapExpandedType CEapTlsPeapUiConnection::GetEapType()
+TInt CEapTlsPeapUiConnection::GetEapType()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::GetEapType()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::GetEapType()\n"));
-
     return iEapType;
 }
 
-// ----------------------------------------------------------
 
 TBool CEapTlsPeapUiConnection::IsPacStoreMasterKeyPresentL()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::IsPacStoreMasterKeyPresentL()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::IsPacStoreMasterKeyPresentL()\n"));
-
 	TBool status(EFalse);
 		
 #ifdef USE_FAST_EAP_TYPE	
 	
-	if(iEapType == *EapExpandedTypeFast.GetType())
+	if(iEapType == eap_type_fast)
 	{
-	    if (iPacStoreDb == 0)
+	    if (iIsConnected == EFalse)
 	    {
 	        User::Leave(KErrSessionClosed);
 	    }
@@ -288,18 +266,13 @@
 	return status;
 }
 
-// ----------------------------------------------------------
-
 TInt CEapTlsPeapUiConnection::DestroyPacStore()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::DestroyPacStore()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::DestroyPacStore()\n"));
-
 #ifdef USE_FAST_EAP_TYPE
 	
-	if(iEapType == *EapExpandedTypeFast.GetType())
+	if(iEapType == eap_type_fast)
 	{
-	    if (iPacStoreDb == 0)
+	    if (iIsConnected == EFalse)
 	    {
 	        return KErrSessionClosed;
 	    }
@@ -315,18 +288,13 @@
 	}	
 }
 	
-// ----------------------------------------------------------
-
 TBool CEapTlsPeapUiConnection::VerifyPacStorePasswordL(
 	const TDesC& aPacStorePw)
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::VerifyPacStorePasswordL()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::VerifyPacStorePasswordL()\n"));
-
-	if(aPacStorePw.Length() <= 0)	
+	if(aPacStorePw.Size() <= 0)	
 	{
 		EAP_TRACE_DEBUG_SYMBIAN(
-			(_L("ERROR: CEapTlsPeapUiConnection::VerifyPacStorePasswordL(): PAC store PW can not be EMPTY!")));				
+			(_L("CEapTlsPeapUiConnection::VerifyPacStorePasswordL: PAC store PW can not be EMPTY!")));				
 		
 		User::Leave(KErrArgument);
 	}
@@ -335,15 +303,15 @@
 		
 #ifdef USE_FAST_EAP_TYPE	
 	
-	if(iEapType == *EapExpandedTypeFast.GetType())
+	if(iEapType == eap_type_fast)
 	{
-	    if (iPacStoreDb == 0)
+	    if (iIsConnected == EFalse)
 	    {
 	        User::Leave(KErrSessionClosed);
 	    }
 	    
 		EAP_TRACE_DATA_DEBUG_SYMBIAN(
-		("CEapTlsPeapUiConnection::VerifyPacStorePasswordL(): PW from caller (16bits)",
+		("CEapTlsPeapUiConnection::VerifyPacStorePasswordL:PW from caller (16bits)",
 		aPacStorePw.Ptr(), 
 		aPacStorePw.Size()));
 		
@@ -352,7 +320,7 @@
 		pacStorePWPtr8.Copy(aPacStorePw);
 	    
 		EAP_TRACE_DATA_DEBUG_SYMBIAN(
-		("CEapTlsPeapUiConnection::VerifyPacStorePasswordL(): PW used for masterkey verification (8bits)",
+		("CEapTlsPeapUiConnection::VerifyPacStorePasswordL:PW used for masterkey verification (8bits)",
 		pacStorePWPtr8.Ptr(), 
 		pacStorePWPtr8.Size()));	    
 	    
@@ -365,7 +333,7 @@
 			// Password and master key are matching.
 			// Means, This is the password used to create the master key.
 			EAP_TRACE_DEBUG_SYMBIAN(
-				(_L("CEapTlsPeapUiConnection::VerifyPacStorePasswordL(): PAC store PW verified OK (true) \n")));				
+				(_L("CEapTlsPeapUiConnection::VerifyPacStorePasswordL PAC store PW verified OK (true) \n")));				
 		}
 	}
 	else
@@ -377,44 +345,39 @@
 	return status;
 }
 
-// ----------------------------------------------------------
-
 TInt CEapTlsPeapUiConnection::CreatePacStoreMasterKey(
 	const TDesC& aPacStorePw)
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::CreatePacStoreMasterKey()\n"));
-
-	if(aPacStorePw.Length() <= 0)	
+	if(aPacStorePw.Size() <= 0)	
 	{
 		EAP_TRACE_DEBUG_SYMBIAN(
-			(_L("ERROR: CEapTlsPeapUiConnection::CreatePacStoreMasterKey(): PAC store PW can not be EMPTY!")));				
+			(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey PAC store PW can not be EMPTY!")));				
 		
 		return KErrArgument;
 	}
 		
 #ifdef USE_FAST_EAP_TYPE	
 	
-	if(iEapType == *EapExpandedTypeFast.GetType())
+	if(iEapType == eap_type_fast)
 	{
-	    if (iPacStoreDb == 0)
+	    if (iIsConnected == EFalse)
 	    {
 	        return KErrSessionClosed;
 	    }
 	    
-		TInt creationStatus(KErrNone);
+	  TInt creationStatus(KErrNone);
 	  	  
 		EAP_TRACE_DATA_DEBUG_SYMBIAN(
-			("CEapTlsPeapUiConnection::CreatePacStoreMasterKey(): PW from caller (16bits)",
-			aPacStorePw.Ptr(), 
-			aPacStorePw.Size()));
+		("CEapTlsPeapUiConnection::CreatePacStoreMasterKey:PW from caller (16bits)",
+		aPacStorePw.Ptr(), 
+		aPacStorePw.Size()));
 		
 		HBufC8* pacStorePWBuf8 = NULL;
 		TRAPD(err, pacStorePWBuf8 = HBufC8::NewL(aPacStorePw.Size()));
 		if (err != KErrNone)
 		{
 			EAP_TRACE_DEBUG_SYMBIAN(
-				(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey(): Allocation failed\n")));
+				(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey:Allocation failed\n")));
 			return KErrNoMemory;
 		}
 		
@@ -422,24 +385,24 @@
 		pacStorePWPtr8.Copy(aPacStorePw);
 	    
 		EAP_TRACE_DATA_DEBUG_SYMBIAN(
-			("CEapTlsPeapUiConnection::CreatePacStoreMasterKey(): PW used for masterkey creation (8bits)",
-			pacStorePWPtr8.Ptr(), 
-			pacStorePWPtr8.Size()));
+		("CEapTlsPeapUiConnection::CreatePacStoreMasterKey:PW used for masterkey creation (8bits)",
+		pacStorePWPtr8.Ptr(), 
+		pacStorePWPtr8.Size()));
 		
-		TRAPD(error, creationStatus = iPacStoreDb->CreateAndSaveMasterKeyL(pacStorePWPtr8));
+		TRAPD(err1, creationStatus = iPacStoreDb->CreateAndSaveMasterKeyL(pacStorePWPtr8));
 	    
 		delete pacStorePWBuf8;
 		
-		if(error != KErrNone)
+		if(err1 != KErrNone)
 		{
 			EAP_TRACE_DEBUG_SYMBIAN(
-				(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey(): Creation failed %d\n"), error));
+				(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey:Creation failed %d\n"), err1));
 		}
 				
 		if (creationStatus == KErrNone)
 		{
 			EAP_TRACE_DEBUG_SYMBIAN(
-				(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey(): Master key created OK\n")));				
+				(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey Master key created OK\n")));				
 		}
 		return creationStatus;
 	}
@@ -450,54 +413,19 @@
 	}
 }
 
-// ----------------------------------------------------------
-
-void CEapTlsPeapUiConnection::GetPacStorePasswordL(
-	TDes8 & /* aPassword8 */)
+CPacStoreDatabase * CEapTlsPeapUiConnection::GetPacStoreDb()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::GetPacStorePasswordL()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::GetPacStorePasswordL()\n"));
-
-#ifdef USE_FAST_EAP_TYPE	
-	if(iEapType == *EapExpandedTypeFast.GetType())
+#ifdef USE_FAST_EAP_TYPE
+	
+	if(iEapType == eap_type_fast)
 	{
-		//iPacStoreDb->GetPacStorePasswordL(aPassword8);
+	    return iPacStoreDb;
 	}
 	else
 #endif	// End: #ifdef USE_FAST_EAP_TYPE		
 	{
-		User::Leave(KErrNotSupported);
-	}
+		return NULL;
+	}	
 }
 
-// ----------------------------------------------------------
-
-void CEapTlsPeapUiConnection::SetPacStorePasswordL(
-	const TDesC8 & aPassword8)
-{
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiConnection::SetPacStorePasswordL()\n")));
-	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiConnection::SetPacStorePasswordL()\n"));
-
-	if(aPassword8.Length() <= 0)	
-	{
-		EAP_TRACE_DEBUG_SYMBIAN(
-			(_L("ERROR: CEapTlsPeapUiConnection::SetPacStorePasswordL(): PAC store PW can not be EMPTY!")));				
-		return;
-		//User::Leave(KErrArgument);
-	}
-
-#ifdef USE_FAST_EAP_TYPE	
-	if(iEapType == *EapExpandedTypeFast.GetType())
-	{
-		iPacStoreDb->SetPacStorePasswordL(aPassword8);
-	}
-	else
-#endif	// End: #ifdef USE_FAST_EAP_TYPE		
-	{
-		User::Leave(KErrNotSupported);
-	}
-}
-
-
-// ----------------------------------------------------------
 // End of file