eapol/eapol_framework/eapol_symbian/am/type/protected_setup/EapProtectedSetupInterface.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 174 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 // INCLUDE FILES
       
    28 #include "EapProtectedSetupInterface.h"
       
    29 #include "eap_am_type_protected_setup_symbian.h"
       
    30 
       
    31 #include <mmtsy_names.h>
       
    32 #include <etelmmerr.h>
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 CEapProtectedSetupInterface::CEapProtectedSetupInterface(abs_eap_am_tools_c* const aTools, eap_am_type_protected_setup_symbian_c* const aParent)
       
    37 : CActive(CActive::EPriorityStandard)
       
    38 , iParent(aParent)
       
    39 , m_am_tools(aTools)
       
    40 , iQueryId(EQueryNone)
       
    41 , iMMETELConnectionStatus(EFalse)
       
    42 {
       
    43 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    44 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    45 }
       
    46 
       
    47 //--------------------------------------------------
       
    48 
       
    49 CEapProtectedSetupInterface* CEapProtectedSetupInterface::NewL(abs_eap_am_tools_c* const aTools, 
       
    50 											   eap_am_type_protected_setup_symbian_c* const aParent)
       
    51 {
       
    52 	CEapProtectedSetupInterface* self = new(ELeave) CEapProtectedSetupInterface(aTools, aParent);
       
    53 	CleanupStack::PushL(self);
       
    54 	self->ConstructL();
       
    55 	CleanupStack::Pop();
       
    56 	return self;
       
    57 }
       
    58 
       
    59 //--------------------------------------------------
       
    60 
       
    61 void CEapProtectedSetupInterface::ConstructL()
       
    62 {
       
    63 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    64 	
       
    65 	CActiveScheduler::Add(this);	
       
    66 	
       
    67 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    68 }
       
    69 
       
    70 //--------------------------------------------------
       
    71 
       
    72 CEapProtectedSetupInterface::~CEapProtectedSetupInterface()
       
    73 {
       
    74 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    75 
       
    76 	if(IsActive())
       
    77 	{
       
    78 		Cancel();		
       
    79 	}
       
    80 	
       
    81 	DisconnectMMETel();	
       
    82 	
       
    83 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    84 }
       
    85 
       
    86 //--------------------------------------------------
       
    87 
       
    88 void CEapProtectedSetupInterface::QueryDeviceParametersL()
       
    89 {	
       
    90 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    91 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ProtectedSetup interface: Querying Device Parametes.\n")));
       
    92 	
       
    93 	iQueryId = EQueryDeviceParams;
       
    94 		
       
    95 	// Create MMETEl connection.
       
    96 	User::LeaveIfError( CreateMMETelConnectionL() );
       
    97 	
       
    98   iPhone.GetPhoneId( iStatus, iDeviceId ); 
       
    99  	
       
   100 	if( !IsActive() )
       
   101 	{
       
   102 		SetActive();
       
   103 	}  
       
   104 
       
   105 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   106 }
       
   107 
       
   108 //--------------------------------------------------
       
   109  
       
   110 void CEapProtectedSetupInterface::DoCancel()
       
   111 {
       
   112 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("CEapProtectedSetupInterface::DoCancel() - Cancelling MMETEL query.\n") ) );
       
   113 
       
   114 	if(iQueryId == EQueryDeviceParams)
       
   115 	{
       
   116 		// Cancel the request for device id.
       
   117 		iPhone.CancelAsyncRequest(EMobilePhoneGetPhoneId);
       
   118 	}
       
   119 	else
       
   120 	{
       
   121 		// This should not happen.
       
   122 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: CEapProtectedSetupInterface::DoCancel(): SOME BIG PROBLEM \n")));	
       
   123 	}
       
   124 	
       
   125 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("CEapProtectedSetupInterface::DoCancel(): CANCELLED the REQUEST \n")));
       
   126 }
       
   127 
       
   128 //--------------------------------------------------
       
   129 
       
   130 void CEapProtectedSetupInterface::RunL()
       
   131 {
       
   132 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   133 	
       
   134 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("CEapProtectedSetupInterface::RunL(). iStatus.Int() =%d \n"), iStatus.Int() ));
       
   135 	
       
   136 	TInt error = KErrNone;
       
   137 	eap_status_e completion_status(eap_status_ok);
       
   138 	
       
   139 	if (iStatus.Int() == KErrNone)
       
   140 	{	
       
   141 		switch( iQueryId )
       
   142 		{
       
   143 			case EQueryDeviceParams:
       
   144 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("CEapProtectedSetupInterface::RunL():: Got Device ID reply.\n")));
       
   145 						
       
   146 				EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Manufacturer"),
       
   147 						iDeviceId.iManufacturer.Ptr(),
       
   148 						iDeviceId.iManufacturer.Size()));
       
   149 
       
   150 				EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Model"),
       
   151 						iDeviceId.iModel.Ptr(),
       
   152 						iDeviceId.iModel.Size()));
       
   153 
       
   154 				EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Revision"),
       
   155 						iDeviceId.iRevision.Ptr(),
       
   156 						iDeviceId.iRevision.Size()));
       
   157 
       
   158 				EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("SerialNumber"),
       
   159 						iDeviceId.iSerialNumber .Ptr(),
       
   160 						iDeviceId.iSerialNumber .Size()));
       
   161 						
       
   162 				// Complete. This happens only if completion_status is eap_status_ok so far.
       
   163 				TRAP(error, iParent->complete_protected_setup_device_paramsL(iDeviceId, completion_status));
       
   164 			
       
   165 				break;
       
   166 			
       
   167 			default:
       
   168 			
       
   169 				// Some problem 
       
   170 				// This should not happen.
       
   171 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: CEapProtectedSetupInterface::RunL(): Unknown query completed.\n")));	
       
   172 				break;
       
   173 		}
       
   174 	} 
       
   175 	else 
       
   176 	{
       
   177 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: CEapProtectedSetupInterface::RunL(): Got error reply.\n")));	
       
   178 	
       
   179 		switch( iQueryId )
       
   180 		{
       
   181 			case EQueryDeviceParams:
       
   182 			
       
   183 				// Error with Device id request. Complete the request with error.			
       
   184 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: CEapProtectedSetupInterface::RunL(): Error in device parameters query.\n")));
       
   185 							
       
   186 				TRAP(error, iParent->complete_protected_setup_device_paramsL(
       
   187 					iDeviceId, 
       
   188 					m_am_tools->convert_am_error_to_eapol_error(iStatus.Int())));
       
   189 				break;
       
   190 			
       
   191 			default:
       
   192 			
       
   193 				// Some problem 
       
   194 				// This should not happen.
       
   195 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: CEapProtectedSetupInterface::RunL(): Unknown query failed.\n")));	
       
   196 				
       
   197 			break;
       
   198 			
       
   199 		}
       
   200 	}
       
   201 
       
   202 	DisconnectMMETel();
       
   203 	
       
   204 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   205 }
       
   206 
       
   207 //--------------------------------------------------
       
   208 
       
   209 TInt CEapProtectedSetupInterface::CreateMMETelConnectionL()
       
   210 {
       
   211 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   212 	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Creating MMETel connection.\n")));
       
   213 
       
   214 	TInt errorCode = KErrNone;
       
   215 	
       
   216 	// MMETel need to be connected only once.    
       
   217   if( !iMMETELConnectionStatus )
       
   218   {
       
   219 		RTelServer::TPhoneInfo phoneInfo;
       
   220 		TInt phoneCount = 0;
       
   221 
       
   222 		// Connect to ETel server
       
   223 		User::LeaveIfError( iServer.Connect() ); 	
       
   224 	
       
   225     EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Connected to ETel server.\n")));	
       
   226 
       
   227 		// This function loads an ETel TSY module, mmtsy.
       
   228 		errorCode = iServer.LoadPhoneModule( KMmTsyModuleName );	
       
   229 	
       
   230     EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Loaded phone module.\n")));	    
       
   231 	
       
   232 		if ( errorCode != KErrNone && errorCode != KErrAlreadyExists )
       
   233 		{
       
   234 			User::Leave( errorCode );
       
   235 		}
       
   236 
       
   237 		iServer.SetExtendedErrorGranularity( RTelServer::EErrorExtended );
       
   238 
       
   239 		// This function retrieves the total number of phones supported by all 
       
   240 		// the currently loaded ETel (TSY) modules.
       
   241 		User::LeaveIfError( iServer.EnumeratePhones( phoneCount ) );	
       
   242 	
       
   243 		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Number of phones supported by the loaded ETel = %d.\n"), phoneCount));
       
   244 	
       
   245 		// This function retrieves information associated with the specified phone
       
   246 		while ( ( phoneCount-- ) && ( phoneInfo.iName != KMmTsyPhoneName ) ) 
       
   247 		{ 
       
   248 			User::LeaveIfError( iServer.GetPhoneInfo( phoneCount, phoneInfo ) );		
       
   249 	    EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Got phone info.\n")));
       
   250 		} 
       
   251 
       
   252 		// This function opens a phone subsession by name. ("DefaultPhone").
       
   253 		User::LeaveIfError( iPhone.Open( iServer, phoneInfo.iName ) );	
       
   254     EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Opened phone subsession.\n")));
       
   255 	
       
   256 		// MMETel connected and the phone module loaded fine.	
       
   257 		iMMETELConnectionStatus = ETrue; 	
       
   258   }
       
   259   else
       
   260   {
       
   261   	// MMETel already connected.
       
   262     EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("MMETel connected once already.\n")));
       
   263   }
       
   264 	    
       
   265 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   266   return errorCode;	
       
   267 }
       
   268 
       
   269 //--------------------------------------------------
       
   270 
       
   271 void CEapProtectedSetupInterface::DisconnectMMETel()
       
   272 {
       
   273     if( iMMETELConnectionStatus )
       
   274     {
       
   275 			EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Closing RMobilePhone and MMETEL.\n")));
       
   276 			
       
   277 			iPhone.Close();
       
   278 			iServer.Close(); // Phone module is unloaded automatically when RTelServer session is closed
       
   279 			
       
   280 			iMMETELConnectionStatus = EFalse;
       
   281     }
       
   282     else
       
   283     {
       
   284 			EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("RMobilePhone and MMETEL already closed.\n")));    	
       
   285     }	
       
   286 }
       
   287 
       
   288 //--------------------------------------------------
       
   289 
       
   290 // End of file.