eapol/eapol_framework/eapol_symbian/am/type/gsmsim/symbian/plugin/src/EapSim.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // This is enumeration of EAPOL source code.
       
    20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    21 	#undef EAP_FILE_NUMBER_ENUM
       
    22 	#define EAP_FILE_NUMBER_ENUM 207 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 
       
    28 // INCLUDE FILES
       
    29 
       
    30 #include "EapSim.h"
       
    31 #include "eap_base_type.h"
       
    32 #include "eap_am_type_gsmsim_symbian.h"
       
    33 #include "eap_type_gsmsim.h"
       
    34 #include "EapSimGlobal.h"
       
    35 #include <EapTypeInfo.h>
       
    36 #include "EapSimDbUtils.h"
       
    37 
       
    38 #include <EapSimUiConnection.h>
       
    39 #include "EapSimUi.h"
       
    40 
       
    41 #include "eap_am_tools_symbian.h"
       
    42 
       
    43 // LOCAL CONSTANTS
       
    44 
       
    45 // The version number of this interface.
       
    46 const TUint KInterfaceVersion = 1;
       
    47 
       
    48 
       
    49 // ================= MEMBER FUNCTIONS =======================
       
    50 
       
    51 
       
    52 CEapSim::CEapSim(const TIndexType aIndexType,	
       
    53 				 const TInt aIndex)
       
    54 : iIndexType(aIndexType)
       
    55 , iIndex(aIndex)
       
    56 , iTunnelingType(eap_type_none)
       
    57 {
       
    58 }
       
    59 
       
    60 // ----------------------------------------------------------
       
    61 
       
    62 CEapSim* CEapSim::NewL(const SIapInfo *aIapInfo)
       
    63 {
       
    64 	return new (ELeave) CEapSim(aIapInfo->indexType, aIapInfo->index);
       
    65 }
       
    66 
       
    67 // ----------------------------------------------------------
       
    68 
       
    69 CEapSim::~CEapSim()
       
    70 {
       
    71 }
       
    72 
       
    73 // ----------------------------------------------------------
       
    74 
       
    75 #ifdef USE_EAP_SIMPLE_CONFIG
       
    76 
       
    77 eap_base_type_c* CEapSim::GetStackInterfaceL(abs_eap_am_tools_c* const aTools, 
       
    78 											   abs_eap_base_type_c* const aPartner,
       
    79 											   const bool is_client_when_true,
       
    80 											   const eap_am_network_id_c * const receive_network_id,
       
    81 											   abs_eap_configuration_if_c * const /*configuration_if*/)
       
    82 	
       
    83 #else
       
    84 	
       
    85 eap_base_type_c* CEapSim::GetStackInterfaceL(abs_eap_am_tools_c* const aTools, 
       
    86 											abs_eap_base_type_c* const aPartner,
       
    87 											const bool is_client_when_true,
       
    88 											const eap_am_network_id_c * const receive_network_id)
       
    89 	
       
    90 #endif // #ifdef USE_EAP_SIMPLE_CONFIG
       
    91 {
       
    92 	// Create AM
       
    93 	eap_am_type_gsmsim_symbian_c* amEapType = eap_am_type_gsmsim_symbian_c::NewL(
       
    94 		aTools, 
       
    95 		aPartner, 
       
    96 		iIndexType, 
       
    97 		iIndex, 
       
    98 		iTunnelingType,
       
    99 		is_client_when_true,
       
   100 		receive_network_id);
       
   101 
       
   102 	if (amEapType->get_is_valid() == false)
       
   103 	{
       
   104 		amEapType->shutdown();
       
   105 		delete amEapType;
       
   106 		User::Leave(KErrGeneral);
       
   107 	}	
       
   108 	
       
   109 	eap_base_type_c* type = 0;
       
   110 
       
   111 	type = new eap_type_gsmsim_c(
       
   112 		aTools, 
       
   113 		aPartner, 
       
   114 		amEapType, 
       
   115 		true /* free_am */, 
       
   116 		is_client_when_true,
       
   117 		receive_network_id);
       
   118 	
       
   119 	if (type == 0)
       
   120 	{
       
   121 		// Out of memory
       
   122 		amEapType->shutdown();
       
   123 		delete amEapType;
       
   124 		User::Leave(KErrNoMemory);
       
   125 	}
       
   126 	else if (type->get_is_valid() == false) 
       
   127 	{		
       
   128 		type->shutdown();
       
   129 		// amEapType is freed by eap_type_gsmsim_c
       
   130 		delete type;		
       
   131 		User::Leave(KErrGeneral);
       
   132 	}
       
   133 	return type;
       
   134 }
       
   135 
       
   136 // ----------------------------------------------------------
       
   137 TInt CEapSim::InvokeUiL()
       
   138 {
       
   139 	TInt buttonId(0);
       
   140 	
       
   141 #ifdef USE_EAP_EXPANDED_TYPES
       
   142 
       
   143     CEapSimUiConnection uiConn(iIndexType, iIndex, iTunnelingType.get_vendor_type());
       
   144 	
       
   145 #else
       
   146 
       
   147     CEapSimUiConnection uiConn(iIndexType, iIndex, iTunnelingType);
       
   148 
       
   149 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
   150 	
       
   151 	CEapSimUi* ui = CEapSimUi::NewL(&uiConn);
       
   152 	CleanupStack::PushL(ui);
       
   153 	buttonId = ui->InvokeUiL();
       
   154 	CleanupStack::PopAndDestroy(ui);
       
   155 	return buttonId;
       
   156 }
       
   157 // ----------------------------------------------------------
       
   158 CEapTypeInfo* CEapSim::GetInfoLC()
       
   159 {
       
   160 	CEapTypeInfo* info = new(ELeave) CEapTypeInfo(
       
   161 		(TDesC&)KReleaseDate, 
       
   162 		(TDesC&)KEapTypeVersion,
       
   163 		(TDesC&)KManufacturer);
       
   164 
       
   165 	CleanupStack::PushL(info);
       
   166 	return info;
       
   167 }
       
   168 
       
   169 // ----------------------------------------------------------
       
   170 
       
   171 void CEapSim::DeleteConfigurationL()
       
   172 {		
       
   173 	EapSimDbUtils::DeleteConfigurationL(iIndexType, iIndex, iTunnelingType);
       
   174 }
       
   175 
       
   176 // ----------------------------------------------------------
       
   177 
       
   178 TUint CEapSim::GetInterfaceVersion()
       
   179 {
       
   180 	return KInterfaceVersion;
       
   181 }
       
   182 
       
   183 // ----------------------------------------------------------
       
   184 
       
   185 void CEapSim::SetTunnelingType(const TInt aTunnelingType)
       
   186 {
       
   187 #ifdef USE_EAP_EXPANDED_TYPES
       
   188 
       
   189 	// Vendor id is eap_type_vendor_id_ietf always in this plugin.
       
   190 	iTunnelingType.set_eap_type_values(eap_type_vendor_id_ietf, aTunnelingType);
       
   191 
       
   192 #else
       
   193 
       
   194 	iTunnelingType = static_cast<eap_type_value_e>(aTunnelingType);
       
   195 
       
   196 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
   197 }
       
   198 
       
   199 
       
   200 // ----------------------------------------------------------
       
   201 void CEapSim::SetIndexL(
       
   202 		const TIndexType aIndexType, 
       
   203 		const TInt aIndex)
       
   204 {		
       
   205 	// First delete the target configuration
       
   206 	TIndexType tmpIndexType = iIndexType;
       
   207 	TInt tmpIndex = iIndex;
       
   208 		
       
   209 	iIndexType = aIndexType;
       
   210 	iIndex = aIndex;
       
   211 	
       
   212 	TInt err(KErrNone);
       
   213 	TRAP(err, DeleteConfigurationL());
       
   214 	// Ignore error on purpose
       
   215 	
       
   216 	// Return the indices
       
   217 	iIndexType = tmpIndexType;
       
   218 	iIndex = tmpIndex;
       
   219 
       
   220 	RDbNamedDatabase db;
       
   221 
       
   222 	RDbs session;
       
   223 	
       
   224 	EapSimDbUtils::OpenDatabaseL(db, session, iIndexType, iIndex, iTunnelingType);
       
   225 	
       
   226 	CleanupClosePushL(session);
       
   227 	CleanupClosePushL(db);
       
   228 		
       
   229 	EapSimDbUtils::SetIndexL(
       
   230 		db, 
       
   231 		iIndexType, 
       
   232 		iIndex, 
       
   233 		iTunnelingType, 
       
   234 		aIndexType, 
       
   235 		aIndex, 
       
   236 		iTunnelingType);
       
   237 	
       
   238 	iIndexType = aIndexType;
       
   239 	iIndex = aIndex;
       
   240 	
       
   241 	CleanupStack::PopAndDestroy(2); // db
       
   242 }
       
   243 
       
   244 void CEapSim::SetConfigurationL(const EAPSettings& aSettings)
       
   245 {
       
   246 	RDbNamedDatabase db;
       
   247 
       
   248 	RDbs session;	
       
   249 	
       
   250 	// This also creates the IAP entry if it doesn't exist
       
   251 	EapSimDbUtils::OpenDatabaseL(db, session, iIndexType, iIndex, iTunnelingType);
       
   252 	
       
   253 	CleanupClosePushL(session);
       
   254 	CleanupClosePushL(db);
       
   255 
       
   256 	EapSimDbUtils::SetConfigurationL(
       
   257 		db,
       
   258 		aSettings, 
       
   259 		iIndexType,
       
   260 		iIndex,
       
   261 		iTunnelingType);		
       
   262 		
       
   263 	CleanupStack::PopAndDestroy(2); // db, session
       
   264 }
       
   265 
       
   266 void CEapSim::GetConfigurationL(EAPSettings& aSettings)
       
   267 {
       
   268 	RDbNamedDatabase db;
       
   269 
       
   270 	RDbs session;
       
   271 	
       
   272 	// This also creates the IAP entry if it doesn't exist
       
   273 	EapSimDbUtils::OpenDatabaseL(db, session, iIndexType, iIndex, iTunnelingType);
       
   274 	
       
   275 	CleanupClosePushL(session);
       
   276 	CleanupClosePushL(db);
       
   277 
       
   278 	EapSimDbUtils::GetConfigurationL(
       
   279 		db,
       
   280 		aSettings, 
       
   281 		iIndexType,
       
   282 		iIndex,
       
   283 		iTunnelingType);
       
   284 		
       
   285 	CleanupStack::PopAndDestroy(2); // db, session
       
   286 }
       
   287 
       
   288 void CEapSim::CopySettingsL(
       
   289 	const TIndexType aDestinationIndexType,
       
   290 	const TInt aDestinationIndex)
       
   291 {
       
   292 	// First delete the target configuration
       
   293 	TIndexType tmpIndexType = iIndexType;
       
   294 	TInt tmpIndex = iIndex;
       
   295 		
       
   296 	iIndexType = aDestinationIndexType;
       
   297 	iIndex = aDestinationIndex;
       
   298 	
       
   299 	TInt err(KErrNone);
       
   300 	TRAP(err, DeleteConfigurationL());
       
   301 	// Ignore error on purpose
       
   302 	
       
   303 	// Return the indices
       
   304 	iIndexType = tmpIndexType;
       
   305 	iIndex = tmpIndex;
       
   306 
       
   307 	RDbNamedDatabase db;
       
   308 
       
   309 	RDbs session;
       
   310 	
       
   311 	EapSimDbUtils::OpenDatabaseL(db, session, iIndexType, iIndex, iTunnelingType);
       
   312 	
       
   313 	CleanupClosePushL(session);
       
   314 	CleanupClosePushL(db);
       
   315 		
       
   316 	EapSimDbUtils::CopySettingsL(
       
   317 		db,
       
   318 		iIndexType,
       
   319 		iIndex,
       
   320 		iTunnelingType, 
       
   321 		aDestinationIndexType, 
       
   322 		aDestinationIndex, 
       
   323 		iTunnelingType);
       
   324 		
       
   325 	CleanupStack::PopAndDestroy(2); // db
       
   326 	
       
   327 }
       
   328 
       
   329 	
       
   330 // End of file