eapol/eapol_framework/eapol_symbian/am/type/gsmsim/symbian/EapSimInterface.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 195 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 
       
    28 // INCLUDE FILES
       
    29 #include "EapSimInterface.h"
       
    30 
       
    31 #include <mmtsy_names.h>
       
    32 #include "eap_sim_triplets.h" // For SIM_SRES_LENGTH.
       
    33 
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 CEapSimIsaInterface::CEapSimIsaInterface(abs_eap_am_tools_c* const aTools, eap_am_type_gsmsim_symbian_c* const aParent)
       
    38 : CActive(CActive::EPriorityStandard)
       
    39 , iParent(aParent)
       
    40 , m_am_tools(aTools)
       
    41 , iAuthenticationData(NULL)
       
    42 , iQueryId(EQueryNone)
       
    43 , iMMETELConnectionStatus(EFalse)
       
    44 {
       
    45 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    46 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    47 }
       
    48 
       
    49 //--------------------------------------------------
       
    50 
       
    51 CEapSimIsaInterface* CEapSimIsaInterface::NewL(abs_eap_am_tools_c* const aTools, 
       
    52 											   eap_am_type_gsmsim_symbian_c* const aParent)
       
    53 {
       
    54 	CEapSimIsaInterface* self = new(ELeave) CEapSimIsaInterface(aTools, aParent);
       
    55 	CleanupStack::PushL(self);
       
    56 	self->ConstructL();
       
    57 	CleanupStack::Pop();
       
    58 	return self;
       
    59 }
       
    60 
       
    61 //--------------------------------------------------
       
    62 
       
    63 void CEapSimIsaInterface::ConstructL()
       
    64 {
       
    65 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    66 	
       
    67 	CActiveScheduler::Add(this);	
       
    68 	
       
    69 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    70 }
       
    71 
       
    72 //--------------------------------------------------
       
    73 
       
    74 CEapSimIsaInterface::~CEapSimIsaInterface()
       
    75 {
       
    76 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    77 
       
    78 	if(IsActive())
       
    79 	{
       
    80 		Cancel();		
       
    81 	}
       
    82 	
       
    83 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Closing RMobilePhone and MMETEL.\n")));
       
    84 	
       
    85 	iPhone.Close();
       
    86 	iServer.Close(); // Phone module is unloaded automatically when RTelServer session is closed
       
    87 		
       
    88 	delete iAuthenticationData;
       
    89 	iAuthenticationData = NULL;
       
    90 		
       
    91 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    92 }
       
    93 
       
    94 //--------------------------------------------------
       
    95 
       
    96 void CEapSimIsaInterface::QueryIMSIL()
       
    97 {	
       
    98 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    99 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ISA interface: Querying IMSI.\n")));
       
   100 	
       
   101 	iQueryId = EQueryIMSI;
       
   102 
       
   103 	// Create MMETEl connection.
       
   104 	User::LeaveIfError( CreateMMETelConnectionL() );
       
   105 	
       
   106    	iPhone.GetSubscriberId( iStatus, iSubscriberId ); 
       
   107  	
       
   108 	if( !IsActive() )
       
   109 	{
       
   110 		SetActive();
       
   111 	}  
       
   112 
       
   113 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   114 }
       
   115 
       
   116 //--------------------------------------------------
       
   117 
       
   118 void CEapSimIsaInterface::QueryKcAndSRESL(const TDesC8& aRand)
       
   119 {
       
   120 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   121 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ISA interface: Querying Kc and SRES.\n")));
       
   122 
       
   123 	iQueryId = EQuerySRESandKC;
       
   124 
       
   125 	EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("RAND"),
       
   126 			aRand.Ptr(),
       
   127 			aRand.Size()));
       
   128 
       
   129 	// Rand must be 16 bytes
       
   130 	if (static_cast<u16_t>(aRand.Length()) != SIM_RAND_LENGTH)
       
   131 	{
       
   132 		EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ISA interface: Illegal RAND - Incorrect length.\n")));
       
   133 		User::Leave(KErrArgument);
       
   134 	}
       
   135 	
       
   136 	// Create MMETEL connection.
       
   137 	User::LeaveIfError( CreateMMETelConnectionL() );
       
   138 	
       
   139 	// Open CustomAPI.
       
   140 	User::LeaveIfError( iCustomAPI.Open(iPhone) );		
       
   141 	
       
   142 	iEAPSim.iRandomParameters.Copy( aRand ); //Copy the rand to iEAPSim
       
   143 
       
   144 	//Pack iEAPSim to iAuthenticationData for passing it to the custom API.
       
   145 	iAuthenticationData = new (ELeave) RMmCustomAPI::TSimDataPckg( iEAPSim );
       
   146 	
       
   147     iCustomAPI.GetWlanSimAuthenticationData( iStatus, *iAuthenticationData );	
       
   148 	
       
   149 	if( !IsActive() )
       
   150 	{
       
   151 		SetActive();
       
   152 	}  
       
   153 
       
   154 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   155 }
       
   156 
       
   157 //--------------------------------------------------
       
   158  
       
   159 void CEapSimIsaInterface::DoCancel()
       
   160 {
       
   161 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("CEapSimIsaInterface::DoCancel() - Cancelling MMETEL query.\n") ) );
       
   162 	
       
   163 	// Cancel the request.
       
   164 	iCustomAPI.CancelAsyncRequest( ECustomGetSimAuthenticationDataIPC );
       
   165 }
       
   166 
       
   167 //--------------------------------------------------
       
   168 
       
   169 void CEapSimIsaInterface::RunL()
       
   170 {
       
   171 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   172 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("CEapSimIsaInterface::RunL(). iStatus.Int() =%d \n"), iStatus.Int() ));
       
   173 	
       
   174 	TInt error = KErrNone;
       
   175 	eap_variable_data_c imsi(m_am_tools); // Keeping it here to avoid "error" in ARMV5 build.
       
   176 	
       
   177 	// This is to store the IMSI, which is in Unicode form.
       
   178 	eap_variable_data_c imsiInUnicode(m_am_tools); // Keeping it here to avoid "error" in ARMV5 build.
       
   179 	
       
   180 	// Keeping it here to remove compiler warning.
       
   181 	eap_status_e completion_status(eap_status_ok);
       
   182 	
       
   183 	if (iStatus.Int() == KErrNone)
       
   184 	{	
       
   185 		switch( iQueryId )
       
   186 		{
       
   187 			case EQueryIMSI:
       
   188 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ISA interface: Got IMSI reply.\n")));
       
   189 						
       
   190 				EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("IMSI"),
       
   191 						iSubscriberId.Ptr(),
       
   192 						iSubscriberId.Size()));
       
   193 				
       
   194 				// Convert the IMSI from unicode to UTF8 characters.
       
   195 
       
   196 				completion_status = imsiInUnicode.set_buffer(iSubscriberId.Ptr(), iSubscriberId.Size(), false, false);
       
   197 
       
   198 				if (completion_status != eap_status_ok)
       
   199 				{
       
   200 					imsiInUnicode.reset();
       
   201 					EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ISA interface: Could not set buffer for IMSI. Not proceeding further here.\n")));
       
   202 				}
       
   203 				else
       
   204 				{				
       
   205 					completion_status = m_am_tools->convert_unicode_to_utf8(imsi, imsiInUnicode);
       
   206 					
       
   207 					if (completion_status != eap_status_ok)
       
   208 					{
       
   209 						imsi.reset();
       
   210 						EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ISA interface: Could not convert IMSI from UNICODE to UTF8. Not proceeding further here.\n")));
       
   211 					}
       
   212 				}
       
   213 							
       
   214 				TRAP(error, iParent->complete_SIM_imsi_L(&imsi, completion_status));
       
   215 			
       
   216 			break;
       
   217 			
       
   218 			case EQuerySRESandKC:
       
   219 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("####ISA interface: Got KC and SRES reply. ####\n")));			
       
   220 				
       
   221 				EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("SRES before trimming"),
       
   222 						iEAPSim.iSRES.Ptr(),
       
   223 						iEAPSim.iSRES.Size()));
       
   224 						
       
   225 				EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("KC"),
       
   226 						iEAPSim.iKC.Ptr(),
       
   227 						iEAPSim.iKC.Size()));
       
   228 						
       
   229 				// Trim the length of SRES -  Remove once the correct length is set for SRES, may be by the API or some where else.
       
   230 				iEAPSim.iSRES.SetLength(SIM_SRES_LENGTH);
       
   231 				EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("SRES after Trimming"),
       
   232 						iEAPSim.iSRES.Ptr(),
       
   233 						iEAPSim.iSRES.Size()));				
       
   234 								
       
   235 				delete iAuthenticationData;
       
   236 				iAuthenticationData = NULL;
       
   237 							
       
   238 				// Close the custom API since we don't need it any more.
       
   239 				iCustomAPI.Close();
       
   240 			
       
   241 				// Complete
       
   242 				TRAP(error, iParent->complete_SIM_kc_and_sres_L(iEAPSim.iKC, iEAPSim.iSRES, completion_status));			
       
   243 			
       
   244 			break;
       
   245 		}
       
   246 	} 
       
   247 	else 
       
   248 	{
       
   249 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ISA interface: Got error reply.\n")));
       
   250 		
       
   251 		if( EQuerySRESandKC == iQueryId )
       
   252 		{
       
   253 			// We have to close the custom API anyway. 
       
   254 			// Rest will be taken care in destructor.
       
   255 			iCustomAPI.Close();	
       
   256 			
       
   257 			// Handle duplicate RAND values.
       
   258 			// If duplicate RAND values are being used, we get KErrArgument here.
       
   259 			if(iStatus.Int() == KErrArgument)
       
   260 			{
       
   261 				completion_status = eap_status_not_fresh_challenges;
       
   262 			}
       
   263 			else
       
   264 			{
       
   265 				// For all other errors.
       
   266 				completion_status = m_am_tools->convert_am_error_to_eapol_error(iStatus.Int());
       
   267 			}
       
   268 			
       
   269 			// Complete the request.
       
   270 			TRAP(error, iParent->complete_SIM_kc_and_sres_L(iEAPSim.iKC, iEAPSim.iSRES, completion_status));							
       
   271 		}
       
   272 		else if(EQueryIMSI == iQueryId)
       
   273 		{
       
   274 			completion_status = m_am_tools->convert_am_error_to_eapol_error(iStatus.Int());
       
   275 			
       
   276 			TRAP(error, iParent->complete_SIM_imsi_L(&imsi, completion_status));
       
   277 		}
       
   278 	}	
       
   279 	
       
   280 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   281 }
       
   282 
       
   283 TInt CEapSimIsaInterface::CreateMMETelConnectionL()
       
   284 {
       
   285 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   286 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Creating MMETel connection.\n")));
       
   287 
       
   288 	TInt errorCode = KErrNone;
       
   289 	
       
   290 	// MMETel need to be connected only once.    
       
   291     if( !iMMETELConnectionStatus )
       
   292     {
       
   293 		RTelServer::TPhoneInfo phoneInfo;
       
   294 		TInt phoneCount = 0;
       
   295 
       
   296 		// Connect to ETel server
       
   297 		User::LeaveIfError( iServer.Connect() ); 	
       
   298 		
       
   299 	    EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Connected to ETel server.\n")));	
       
   300 
       
   301 		//This function loads an ETel TSY module. mmtsy.
       
   302 		errorCode = iServer.LoadPhoneModule( KMmTsyModuleName );	
       
   303 		
       
   304 	    EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Loaded phone module.\n")));	    
       
   305 		
       
   306 		if ( errorCode != KErrNone && errorCode != KErrAlreadyExists )
       
   307 		{
       
   308 			User::Leave( errorCode );
       
   309 		}
       
   310 
       
   311 		iServer.SetExtendedErrorGranularity( RTelServer::EErrorExtended );
       
   312 
       
   313 		//This function retrieves the total number of phones supported by all 
       
   314 		//the currently loaded ETel (TSY) modules.
       
   315 		User::LeaveIfError( iServer.EnumeratePhones( phoneCount ) );	
       
   316 		
       
   317 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Number of phones supported by the loaded ETel = %d.\n"), phoneCount));
       
   318 		
       
   319 		// This function retrieves information associated with the specified phone
       
   320 		while ( ( phoneCount-- ) && ( phoneInfo.iName != KMmTsyPhoneName ) ) 
       
   321 		{ 
       
   322 			User::LeaveIfError( iServer.GetPhoneInfo( phoneCount, phoneInfo ) );		
       
   323 			
       
   324 		    EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Got phone info.\n")));
       
   325 		} 
       
   326 
       
   327 		// This function opens a phone subsession by name, 
       
   328 		User::LeaveIfError( iPhone.Open( iServer, phoneInfo.iName ) );	
       
   329 		
       
   330 	    EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Opened phone subsession.\n")));
       
   331 		
       
   332 		// MMETel connected and the phone module loaded fine.	
       
   333 		iMMETELConnectionStatus = ETrue; 	
       
   334     }
       
   335     else
       
   336     {
       
   337     	// MMETel already connected.
       
   338 	    EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("MMETel connected once already.\n")));
       
   339     }
       
   340 	    
       
   341 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   342     
       
   343     return errorCode;	
       
   344 }
       
   345 
       
   346 // End of file