telephonyserver/etelmultimode/DTsy/MMTSYSMARTCARDEAP.cpp
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Dummy TSY testing functionality for Smart Card Application EAP support.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 
       
    23 #include "mmtsy.h"
       
    24 #include "testdef.h"
       
    25 #include "ETELMM.H"
       
    26 #include <et_clsvr.h>
       
    27 #include "Dmmlog.h"
       
    28 #include <etelext.h>
       
    29 
       
    30 //
       
    31 //	CSmartCardEapDMmTsy
       
    32 //
       
    33 CSmartCardEapDMmTsy* CSmartCardEapDMmTsy::NewL(CPhoneDMmTsy *aPhone, RMobilePhone::TAID& aAID, RMobileSmartCardEap::TEapType& aEapType, CPhoneFactoryDummyBase* aFac)
       
    34 	{
       
    35 	CSmartCardEapDMmTsy* phone=new(ELeave) CSmartCardEapDMmTsy(aPhone, aAID, aEapType, aFac);
       
    36 	CleanupStack::PushL(phone);
       
    37 	phone->ConstructL();
       
    38 	CleanupStack::Pop();
       
    39 	return phone;
       
    40 	}
       
    41 
       
    42 CSmartCardEapDMmTsy::CSmartCardEapDMmTsy(CPhoneDMmTsy *aPhone, RMobilePhone::TAID& aAID, RMobileSmartCardEap::TEapType& aEapType, CPhoneFactoryDummyBase* aFac)
       
    43 : CSubSessionExtDummyBase(aFac), iPhone(aPhone), iSSInitialised(EFalse),
       
    44   iAccessStatus(RMobileSmartCardEap::EEapMethodAvailable), iCliTerminationNotifier(NULL)
       
    45 	{
       
    46 	iAID = aAID;
       
    47 	iEapType = aEapType;
       
    48 	}
       
    49 
       
    50 void CSmartCardEapDMmTsy::ConstructL()
       
    51 	{
       
    52 	iSemaphr.CreateGlobal(KNullDesC, EOwnerThread);
       
    53 	LOGTEXT(_L8("CSmartCardEapDMmTsy created"));
       
    54 	}
       
    55 
       
    56 CSmartCardEapDMmTsy::~CSmartCardEapDMmTsy()
       
    57 	{
       
    58 	delete iCliTerminationNotifier;
       
    59 	iSemaphr.Close();
       
    60 	LOGTEXT(_L8("CSmartCardEapDMmTsy destroyed"));
       
    61 	}
       
    62 
       
    63 void CSmartCardEapDMmTsy::Init()
       
    64 	{
       
    65 	// server calls this function once it has created the sub-session
       
    66 	// it gives the TSY chance to do any initialisation it may need to do for
       
    67 	// this sub-session
       
    68 	}
       
    69 
       
    70 CTelObject* CSmartCardEapDMmTsy::OpenNewObjectByNameL(const TDesC& /*aName*/)
       
    71 	{
       
    72 	// Server calls this function when a client is opening an object from the phone
       
    73 	// for the first time.
       
    74 	// Multiple clients opening handles to the same sub-session object will be dealt with
       
    75 	// by the server - i.e. by reference counting
       
    76 	User::Leave(KErrNotSupported);
       
    77 	return NULL;
       
    78 	}
       
    79 
       
    80 CTelObject* CSmartCardEapDMmTsy::OpenNewObjectL(TDes& /*aNewName*/)
       
    81 	{
       
    82 	// all objects opened from the phone are opened by name, hence this method
       
    83 	// is not supported
       
    84 	User::Leave(KErrNotSupported);
       
    85 	return NULL;
       
    86 	}
       
    87 
       
    88 CTelObject::TReqMode CSmartCardEapDMmTsy::ReqModeL(const TInt aIpc)
       
    89 	{
       
    90 	// ReqModeL is called from the server's CTelObject::ReqAnalyserL
       
    91 	// in order to check the type of request it has
       
    92 
       
    93 	// The following are example request types for this dummy TSY
       
    94 	// All TSYs do not have to have these request types but they have been given
       
    95 	// "sensible" values in this test code
       
    96 
       
    97 	CTelObject::TReqMode ret = 0;
       
    98 
       
    99 	switch (aIpc)
       
   100 		{
       
   101 	// Non flow-controlled requests
       
   102 	case EMobileSmartCardEapInitialiseEapMethod:
       
   103 	case EMobileSmartCardEapGetUserIdentity:
       
   104 	case EMobileSmartCardEapGetAuthenticationStatus:
       
   105 	case EMobileSmartCardEapGetEapKey:
       
   106 	case EMobileSmartCardEapAuthenticationPhase1:
       
   107 	case EMobileSmartCardEapAuthenticationPhase2:
       
   108 	case EMobileSmartCardEapReleaseEapMethod:
       
   109 	case EMobileSmartCardEapGetEapMethodAccessStatus:
       
   110 		break;
       
   111 
       
   112 	case EMobileSmartCardEapNotifyEapMethodAccessStatusChange:
       
   113 		ret = KReqModeMultipleCompletionEnabled;
       
   114 		break;
       
   115 
       
   116 	default:
       
   117 		User::Leave(KErrNotSupported);
       
   118 		break;
       
   119 		}
       
   120 
       
   121 	return ret;
       
   122 	}
       
   123 
       
   124 TInt CSmartCardEapDMmTsy::RegisterNotification(const TInt /*aIpc*/)
       
   125 	{
       
   126 	// RegisterNotification is called when the server recognises that this notification
       
   127 	// is being posted for the first time on this sub-session object.
       
   128 
       
   129 	// It enables the TSY to "turn on" any regular notification messages that it may 
       
   130 	// receive from the phone
       
   131 
       
   132 	return KErrNone;
       
   133 	}
       
   134 
       
   135 TInt CSmartCardEapDMmTsy::DeregisterNotification(const TInt /*aIpc*/)
       
   136 	{
       
   137 	// DeregisterNotification is called when the server recognises that this notification
       
   138 	// will not be posted again because the last client to have a handle on this sub-session
       
   139 	// object has just closed the handle.
       
   140 
       
   141 	// It enables the TSY to "turn off" any regular notification messages that it may
       
   142 	// receive from the phone
       
   143 
       
   144 	return KErrNone;
       
   145 	}
       
   146 
       
   147 TInt CSmartCardEapDMmTsy::NumberOfSlotsL(const TInt aIpc)
       
   148 	{
       
   149 	// NumberOfSlotsL is called by the server when it is registering a new notification
       
   150 	// It enables the TSY to tell the server how many buffer slots to allocate for
       
   151 	// "repost immediately" notifications that may trigger before clients collect them
       
   152 
       
   153 	TInt numberOfSlots = 1;
       
   154 
       
   155 	switch (aIpc)
       
   156 		{
       
   157 	case EMobileSmartCardEapNotifyEapMethodAccessStatusChange:
       
   158 		numberOfSlots = 3;
       
   159 		break;
       
   160 
       
   161 	default:
       
   162 		// Unknown or invalid Phone IPC
       
   163 		User::Leave(KErrNotSupported);
       
   164 		break;
       
   165 		}
       
   166 
       
   167 	return numberOfSlots;
       
   168 	}
       
   169 
       
   170 TInt CSmartCardEapDMmTsy::ExtFunc(const TTsyReqHandle aTsyReqHandle,const TInt aIpc,
       
   171                                   const TDataPackage& aPackage)
       
   172 	{
       
   173 	// ExtFunc is called by the server when it has a "extended", i.e. non-core ETel request 
       
   174 	// for the TSY to process
       
   175 	// A request handle, request type and request data are passed to the TSY
       
   176 
       
   177 	TAny* dataPtr = aPackage.Ptr1();
       
   178 	TAny* dataPtr2 = aPackage.Ptr2();
       
   179 
       
   180 	// The request data has to extracted from TDataPackage and the TAny* pointers have to
       
   181 	// be "cast" to the expected request data type
       
   182 
       
   183 	switch(aIpc)
       
   184 		{
       
   185 	// Non-Flow controlled requests
       
   186 
       
   187 	case EMobileSmartCardEapInitialiseEapMethod:
       
   188 		return DMmInitialiseEapMethod(aTsyReqHandle,
       
   189 		         reinterpret_cast<TThreadId*>(dataPtr));
       
   190 
       
   191 	case EMobileSmartCardEapGetUserIdentity:
       
   192 		return DMmGetUserIdentity(aTsyReqHandle,
       
   193 		         reinterpret_cast<RMobileSmartCardEap::TEapUserIdType*>(dataPtr),
       
   194 		         aPackage.Des2n());
       
   195 
       
   196 	case EMobileSmartCardEapGetAuthenticationStatus:
       
   197 		return DMmGetAuthenticationStatus(aTsyReqHandle, 
       
   198 		         reinterpret_cast<RMobileSmartCardEap::TEapAuthStatus*>(dataPtr));
       
   199 
       
   200 	case EMobileSmartCardEapGetEapKey:
       
   201 		return DMmGetEapKey(aTsyReqHandle,
       
   202 		         reinterpret_cast<RMobileSmartCardEap::TEapKeyTag*>(dataPtr),
       
   203 		         aPackage.Des2n());
       
   204 
       
   205 	case EMobileSmartCardEapAuthenticationPhase1:
       
   206 		return DMmSetAuthenticateDataForPhase1(aTsyReqHandle,
       
   207 		         aPackage.Des1n(), reinterpret_cast<TInt*>(dataPtr2));
       
   208 
       
   209 	case EMobileSmartCardEapAuthenticationPhase2:
       
   210 		return DMmGetAuthenticateDataForPhase2(aTsyReqHandle,
       
   211 		         aPackage.Des1n(), aPackage.Des2n());
       
   212 
       
   213 	case EMobileSmartCardEapReleaseEapMethod:
       
   214 		return DMmReleaseEapMethod(aTsyReqHandle);
       
   215 
       
   216 	case EMobileSmartCardEapGetEapMethodAccessStatus:
       
   217 		return DMmGetEapMethodAccessStatus(aTsyReqHandle,
       
   218 		         reinterpret_cast<RMobileSmartCardEap::TEapMethodAccessStatus*>(dataPtr));
       
   219 
       
   220 	case EMobileSmartCardEapNotifyEapMethodAccessStatusChange:
       
   221 		return DMmNotifyEapMethodAccessStatusChange(aTsyReqHandle,
       
   222 		         reinterpret_cast<RMobileSmartCardEap::TEapMethodAccessStatus*>(dataPtr));
       
   223 
       
   224 	default:
       
   225 		return KErrNotSupported;
       
   226 		}
       
   227 	}
       
   228 
       
   229 TInt CSmartCardEapDMmTsy::CancelService(const TInt aIpc,const TTsyReqHandle aTsyReqHandle)
       
   230 	{
       
   231 	// CancelService is called by the server when it is "cleaning-up" any still outstanding
       
   232 	// asynchronous requests before closing a client's sub-session.
       
   233 	// This will happen if a client closes its R-class handle without cancelling outstanding
       
   234 	// asynchronous requests.
       
   235 
       
   236 	switch (aIpc)
       
   237 		{
       
   238 	case EMobileSmartCardEapGetUserIdentity:
       
   239 		return DMmGetUserIdentityCancel(aTsyReqHandle);
       
   240 	case EMobileSmartCardEapGetAuthenticationStatus:
       
   241 		return DMmGetAuthenticationStatusCancel(aTsyReqHandle);
       
   242 	case EMobileSmartCardEapGetEapKey:
       
   243 		return DMmGetEapKeyCancel(aTsyReqHandle);
       
   244 	case EMobileSmartCardEapInitialiseEapMethod:
       
   245 		return DMmInitialiseEapMethodCancel(aTsyReqHandle);
       
   246 	case EMobileSmartCardEapAuthenticationPhase1:
       
   247 	case EMobileSmartCardEapAuthenticationPhase2:
       
   248 		return DMmSmartCardEapAuthenticationCancel(aTsyReqHandle);
       
   249 	case EMobileSmartCardEapNotifyEapMethodAccessStatusChange:
       
   250 		return DMmNotifyEapMethodAccessStatusChangeCancel(aTsyReqHandle);
       
   251 	default:
       
   252 		return KErrNotSupported;
       
   253 		}
       
   254 	}
       
   255 
       
   256 TInt CSmartCardEapDMmTsy::DMmInitialiseEapMethod(const TTsyReqHandle aTsyReqHandle, TThreadId* aThreadId)
       
   257 	{
       
   258 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmInitialiseEapMethod called"));
       
   259 
       
   260 	if (iAID != DMMTSY_PHONE_EAPAPP_AID() || iEapType != DMMTSY_PHONE_EAP_METHOD)
       
   261 		{
       
   262 		ReqCompleted(aTsyReqHandle, KErrNotFound);
       
   263 		}
       
   264 	else if (iSSInitialised)
       
   265 		{
       
   266 		ReqCompleted(aTsyReqHandle, KErrNone);
       
   267 		}
       
   268 	else
       
   269 		{
       
   270 		delete iCliTerminationNotifier;
       
   271 		TRAPD(err, iCliTerminationNotifier = CThreadTerminationNotifier::NewL(this, *aThreadId));
       
   272 		if (err != KErrNone)
       
   273 			{
       
   274 			ReqCompleted(aTsyReqHandle, err);
       
   275 			}
       
   276 		else
       
   277 			{
       
   278 			iSSInitialised = ETrue;
       
   279 			iCliTerminationNotifier->Start();
       
   280 			iAccessStatus = RMobileSmartCardEap::EEapMethodInUseApplicationActive;
       
   281 			DMmCompleteNotifyEapMethodAccessStatusChange();
       
   282 			iPhone->AddDelayedReq(aTsyReqHandle, this);
       
   283 			}
       
   284 		}
       
   285 
       
   286 	return KErrNone;
       
   287 	}
       
   288 
       
   289 TInt CSmartCardEapDMmTsy::DMmInitialiseEapMethodCancel(const TTsyReqHandle aTsyReqHandle)
       
   290 	{
       
   291 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmInitialiseEapMethodCancel called"));
       
   292 	iPhone->RemoveDelayedReq(aTsyReqHandle);
       
   293 	iSSInitialised = EFalse;
       
   294 	iAccessStatus = RMobileSmartCardEap::EEapMethodAvailable;
       
   295 	DMmCompleteNotifyEapMethodAccessStatusChange();
       
   296 	ReqCompleted(aTsyReqHandle, KErrCancel);
       
   297 	return KErrNone;
       
   298 	}
       
   299 
       
   300 TInt CSmartCardEapDMmTsy::DMmGetUserIdentity(const TTsyReqHandle aTsyReqHandle, RMobileSmartCardEap::TEapUserIdType* aEapIdType, TDes8* aUserId)
       
   301 	{
       
   302 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmGetUserIdentity called"));
       
   303 	RMobileSmartCardEap::TEapUserIdentityV6Pckg *userIdPckg = reinterpret_cast<RMobileSmartCardEap::TEapUserIdentityV6Pckg*>(aUserId);
       
   304 	RMobileSmartCardEap::TEapUserIdentityV6 &userId = (*userIdPckg)();
       
   305 
       
   306 	if (*aEapIdType == DMMTSY_PHONE1_EAP_IDTYPE)
       
   307 		{
       
   308 		userId.iEapId = DMMTSY_PHONE1_EAP_UID;
       
   309 		iPhone->AddDelayedReq(aTsyReqHandle, this);
       
   310 		}
       
   311 	else if (*aEapIdType == DMMTSY_PHONE2_EAP_IDTYPE)
       
   312 		{
       
   313 		userId.iEapId = DMMTSY_PHONE2_EAP_UID;
       
   314 		iPhone->AddDelayedReq(aTsyReqHandle, this);
       
   315 		}
       
   316 	else
       
   317 		{
       
   318 		ReqCompleted(aTsyReqHandle, KErrArgument);
       
   319 		}
       
   320 
       
   321 	return KErrNone;
       
   322 	}
       
   323 
       
   324 TInt CSmartCardEapDMmTsy::DMmGetUserIdentityCancel(const TTsyReqHandle aTsyReqHandle)
       
   325 	{
       
   326 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmGetUserIdentityCancel called"));
       
   327 	iPhone->RemoveDelayedReq(aTsyReqHandle);
       
   328 	ReqCompleted(aTsyReqHandle, KErrCancel);
       
   329 	return KErrNone;
       
   330 	}
       
   331 	
       
   332 TInt CSmartCardEapDMmTsy::DMmGetAuthenticationStatus(const TTsyReqHandle aTsyReqHandle, RMobileSmartCardEap::TEapAuthStatus* aAuthStatus)
       
   333 	{
       
   334 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmGetAuthenticationStatus called"));
       
   335 
       
   336 	*aAuthStatus = DMMTSY_PHONE_EAPAUTHSTATUS;
       
   337 	iPhone->AddDelayedReq(aTsyReqHandle, this);
       
   338 
       
   339 	return KErrNone;
       
   340 	}
       
   341 	
       
   342 TInt CSmartCardEapDMmTsy::DMmGetAuthenticationStatusCancel(const TTsyReqHandle aTsyReqHandle)
       
   343 	{
       
   344 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmGetAuthenticationStatusCancel called"));
       
   345 	iPhone->RemoveDelayedReq(aTsyReqHandle);
       
   346 	ReqCompleted(aTsyReqHandle, KErrCancel);
       
   347 	return KErrNone;
       
   348 	}
       
   349 
       
   350 TInt CSmartCardEapDMmTsy::DMmGetEapKey(const TTsyReqHandle aTsyReqHandle, RMobileSmartCardEap::TEapKeyTag* aEapKeyTag, TDes8* aKey)
       
   351 	{
       
   352 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmGetEapKey called"));
       
   353 
       
   354 	RMobileSmartCardEap::TEapKeyV6Pckg *keyPckg = reinterpret_cast<RMobileSmartCardEap::TEapKeyV6Pckg*>(aKey);
       
   355 	RMobileSmartCardEap::TEapKeyV6 &key = (*keyPckg)();
       
   356 
       
   357 	if (*aEapKeyTag == DMMTSY_PHONE1_EAPKEYTAG)
       
   358 		{
       
   359 		key.iEapKey = DMMTSY_PHONE1_EAPKEY;
       
   360 		iPhone->AddDelayedReq(aTsyReqHandle, this);
       
   361 		}
       
   362 	else if (*aEapKeyTag == DMMTSY_PHONE2_EAPKEYTAG)
       
   363 		{
       
   364 		key.iEapKey = DMMTSY_PHONE2_EAPKEY;
       
   365 		iPhone->AddDelayedReq(aTsyReqHandle, this);
       
   366 		}
       
   367 	else
       
   368 		{
       
   369 		ReqCompleted(aTsyReqHandle, KErrArgument);
       
   370 		}
       
   371 
       
   372 	return KErrNone;
       
   373 	}
       
   374 
       
   375 TInt CSmartCardEapDMmTsy::DMmGetEapKeyCancel(const TTsyReqHandle aTsyReqHandle)
       
   376 	{
       
   377 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmGetEapKeyCancel called"));
       
   378 	iPhone->RemoveDelayedReq(aTsyReqHandle);
       
   379 	ReqCompleted(aTsyReqHandle, KErrCancel);
       
   380 	return KErrNone;
       
   381 	}
       
   382 
       
   383 TInt CSmartCardEapDMmTsy::DMmSetAuthenticateDataForPhase1(const TTsyReqHandle aTsyReqHandle, TDes8* aEapAuthData, TInt* aPhase1Size)
       
   384 	{
       
   385 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmSetAuthenticateDataForPhase1 called"));
       
   386 
       
   387 	RMobileSmartCardEap::CEapAuthenticateRequestDataV6* authReq = NULL;
       
   388 	TRAPD(err, authReq = RMobileSmartCardEap::CEapAuthenticateRequestDataV6::NewL());
       
   389 	if (err != KErrNone)
       
   390 		{
       
   391 		ReqCompleted(aTsyReqHandle, err);
       
   392 		return KErrNone;
       
   393 		}
       
   394 
       
   395 	TRAP(err, authReq->InternalizeL(*aEapAuthData));
       
   396 	if (err != KErrNone)
       
   397 		{
       
   398 		ReqCompleted(aTsyReqHandle, err);
       
   399 		return KErrNone;
       
   400 		}
       
   401 
       
   402 	TPtr8 reqPacket = authReq->GetEapReqPacket();
       
   403 	if (reqPacket == DMMTSY_PHONE1_EAPPACKET)
       
   404 		{
       
   405 		iRespPtrC.Set(DMMTSY_PHONE2_EAPPACKET);
       
   406 		*aPhase1Size = iRespPtrC.Length();
       
   407 		}
       
   408 	else if (reqPacket == DMMTSY_PHONE1_EAPPACKET2)
       
   409 		{
       
   410 		iRespPtrC.Set(DMMTSY_PHONE2_EAPPACKET2);
       
   411 		*aPhase1Size = iRespPtrC.Length();
       
   412 		}
       
   413 	else
       
   414 		{
       
   415 		ReqCompleted(aTsyReqHandle, KErrCorrupt);
       
   416 		return KErrNone;
       
   417 		}
       
   418 
       
   419 	iPhone->AddDelayedReq(aTsyReqHandle, this);
       
   420 	return KErrNone;
       
   421 	}
       
   422 
       
   423 TInt CSmartCardEapDMmTsy::DMmGetAuthenticateDataForPhase2(const TTsyReqHandle aTsyReqHandle, TDes8* aEapAuthData, TDes8* aPhase2Resp)
       
   424 	{
       
   425 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmSetAuthenticateDataForPhase2 called"));
       
   426 
       
   427 	RMobileSmartCardEap::CEapAuthenticateRequestDataV6* authReq = NULL;
       
   428 	TRAPD(err, authReq = RMobileSmartCardEap::CEapAuthenticateRequestDataV6::NewL());
       
   429 	if (err != KErrNone)
       
   430 		{
       
   431 		ReqCompleted(aTsyReqHandle, err);
       
   432 		return KErrNone;
       
   433 		}
       
   434 
       
   435 	TRAP(err, authReq->InternalizeL(*aEapAuthData));
       
   436 	if (err != KErrNone)
       
   437 		{
       
   438 		ReqCompleted(aTsyReqHandle, err);
       
   439 		return KErrNone;
       
   440 		}
       
   441 
       
   442 	TPtr8 reqPacket = authReq->GetEapReqPacket();
       
   443 	if (reqPacket != DMMTSY_PHONE1_EAPPACKET &&
       
   444 	    reqPacket != DMMTSY_PHONE1_EAPPACKET2)
       
   445 		{
       
   446 		ReqCompleted(aTsyReqHandle, KErrCorrupt);
       
   447 		return KErrNone;
       
   448 		}
       
   449 
       
   450 	aPhase2Resp->Copy(iRespPtrC);
       
   451 
       
   452 	iPhone->AddDelayedReq(aTsyReqHandle, this);
       
   453  
       
   454 	return KErrNone;
       
   455 	}
       
   456 
       
   457 TInt CSmartCardEapDMmTsy::DMmSmartCardEapAuthenticationCancel(const TTsyReqHandle aTsyReqHandle)
       
   458 	{
       
   459 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmSmartCardEapAuthenticationCancel called"));
       
   460 	iPhone->RemoveDelayedReq(aTsyReqHandle);
       
   461 	ReqCompleted(aTsyReqHandle, KErrCancel);
       
   462 	iRespPtrC.Set(NULL, 0);
       
   463 	return KErrNone;
       
   464 	}
       
   465 
       
   466 TInt CSmartCardEapDMmTsy::DMmReleaseEapMethod(const TTsyReqHandle aTsyReqHandle)
       
   467 	{
       
   468 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmReleaseEapMethod called"));
       
   469 	iSSInitialised = EFalse;
       
   470 	iAccessStatus = RMobileSmartCardEap::EEapMethodUnableToInitialise;
       
   471 	ReqCompleted(aTsyReqHandle, KErrNone);
       
   472 
       
   473 	DMmCompleteNotifyEapMethodAccessStatusChange();
       
   474 
       
   475 	// Simulate availability after 2 secs.
       
   476 	User::After(2000000);
       
   477 	iAccessStatus = RMobileSmartCardEap::EEapMethodAvailable;
       
   478 	DMmCompleteNotifyEapMethodAccessStatusChange();
       
   479 
       
   480 	return KErrNone;
       
   481 	}
       
   482 
       
   483 TInt CSmartCardEapDMmTsy::DMmGetEapMethodAccessStatus(const TTsyReqHandle aTsyReqHandle, RMobileSmartCardEap::TEapMethodAccessStatus* aEapState)
       
   484 	{
       
   485 	LOGTEXT(_L8("CSmartCardEapDMmTsy::DMmGetEapMethodAccessStatus called"));
       
   486 	*aEapState = iAccessStatus;
       
   487 	ReqCompleted(aTsyReqHandle, KErrNone);
       
   488 	return KErrNone;
       
   489 	}
       
   490 
       
   491 TInt CSmartCardEapDMmTsy::DMmNotifyEapMethodAccessStatusChange(const TTsyReqHandle aTsyReqHandle, RMobileSmartCardEap::TEapMethodAccessStatus* aEapState)
       
   492 	{
       
   493 	__ASSERT_ALWAYS(!iEapAccessNotifyData.iNotifyPending, PanicClient(EEtelPanicRequestAsyncTwice));
       
   494 
       
   495 	iEapAccessNotifyData.iNotifyPending = ETrue;
       
   496 	iEapAccessNotifyData.iNotifyHandle = aTsyReqHandle;
       
   497 	iEapAccessNotifyData.iNotifyData = aEapState;
       
   498 
       
   499 	return KErrNone;
       
   500 	}
       
   501 
       
   502 TInt CSmartCardEapDMmTsy::DMmNotifyEapMethodAccessStatusChangeCancel(const TTsyReqHandle aTsyReqHandle)
       
   503 	{
       
   504 	if(iEapAccessNotifyData.iNotifyPending)
       
   505 		{
       
   506 		iEapAccessNotifyData.iNotifyPending = EFalse;
       
   507 		ReqCompleted(aTsyReqHandle, KErrCancel);
       
   508 		return KErrNone;
       
   509 		}	
       
   510 
       
   511 	iPhone->ReqCompleted(aTsyReqHandle,KErrNone);
       
   512 	return KErrNone;
       
   513 	}
       
   514 
       
   515 void CSmartCardEapDMmTsy::DMmCompleteNotifyEapMethodAccessStatusChange()
       
   516 	{
       
   517 	if(iEapAccessNotifyData.iNotifyPending)
       
   518 		{
       
   519 		iEapAccessNotifyData.iNotifyPending = EFalse;
       
   520 		*(reinterpret_cast<RMobileSmartCardEap::TEapMethodAccessStatus*>(iEapAccessNotifyData.iNotifyData)) = iAccessStatus;
       
   521 		ReqCompleted(iEapAccessNotifyData.iNotifyHandle, KErrNone);
       
   522 		}
       
   523 	}
       
   524 
       
   525 RHandleBase* CSmartCardEapDMmTsy::GlobalKernelObjectHandle()
       
   526 	{
       
   527 	return &iSemaphr;
       
   528 	}
       
   529 
       
   530 void CSmartCardEapDMmTsy::ClientHasTerminated(TInt aExitReason)
       
   531 	{
       
   532 	// Can TSY do anything with the thread's exit reason?
       
   533 	// Exit code can be a zero (e.g. for KERN-EXEC 0) a positive value
       
   534 	// (e.g. for KERN-EXEC 3) or a negative error.
       
   535 	(void) aExitReason;
       
   536 
       
   537 	switch (iAccessStatus)
       
   538 		{
       
   539 	case RMobileSmartCardEap::EEapMethodInUseApplicationActive:
       
   540 		iSSInitialised = EFalse;
       
   541 		iAccessStatus = RMobileSmartCardEap::EEapMethodUnableToInitialise;
       
   542 		DMmCompleteNotifyEapMethodAccessStatusChange();
       
   543 		iSemaphr.Signal();
       
   544 
       
   545 		// Simulate availability after 2 secs.
       
   546 		User::After(2000000);
       
   547 		iAccessStatus = RMobileSmartCardEap::EEapMethodAvailable;
       
   548 		DMmCompleteNotifyEapMethodAccessStatusChange();
       
   549 		break;
       
   550 
       
   551 	case RMobileSmartCardEap::EEapMethodInUseApplicationInactive:
       
   552 		iAccessStatus = RMobileSmartCardEap::EEapMethodAvailable;
       
   553 		DMmCompleteNotifyEapMethodAccessStatusChange();
       
   554 		iSemaphr.Signal();
       
   555 		break;
       
   556 
       
   557 	default:
       
   558 		;
       
   559 		}
       
   560 	
       
   561 	//iSemaphr.Signal();
       
   562 	}
       
   563 
       
   564 //
       
   565 // Class definition for monitoring thread termination
       
   566 //
       
   567 
       
   568 CSmartCardEapDMmTsy::CThreadTerminationNotifier* CSmartCardEapDMmTsy::CThreadTerminationNotifier::NewL(CSmartCardEapDMmTsy* aSubSess, const TThreadId& aId)
       
   569 	{
       
   570 	CThreadTerminationNotifier* self = new(ELeave) CThreadTerminationNotifier(aSubSess);
       
   571 	CleanupStack::PushL(self);
       
   572 	self->ConstructL(aId);
       
   573 	CleanupStack::Pop(self);
       
   574 	return self;
       
   575 	}
       
   576 
       
   577 CSmartCardEapDMmTsy::CThreadTerminationNotifier::CThreadTerminationNotifier(CSmartCardEapDMmTsy* aSubSess)
       
   578 : CActive(EPriorityStandard), iSubSess(aSubSess)
       
   579 	{
       
   580 	}
       
   581 
       
   582 void CSmartCardEapDMmTsy::CThreadTerminationNotifier::ConstructL(const TThreadId& aId)
       
   583 	{
       
   584 	TInt openTh = iCliThread.Open(aId);
       
   585 	User::LeaveIfError(openTh);
       
   586     CActiveScheduler::Add(this);
       
   587 	}
       
   588 
       
   589 void CSmartCardEapDMmTsy::CThreadTerminationNotifier::Start()
       
   590 	{
       
   591 	iCliThread.Logon(iStatus);
       
   592 	SetActive();
       
   593 	}
       
   594 
       
   595 void CSmartCardEapDMmTsy::CThreadTerminationNotifier::RunL()
       
   596 	{
       
   597 	iSubSess->ClientHasTerminated(iStatus.Int());
       
   598 	}
       
   599 
       
   600 void CSmartCardEapDMmTsy::CThreadTerminationNotifier::DoCancel()
       
   601 	{
       
   602 	iCliThread.LogonCancel(iStatus);
       
   603 	}
       
   604 
       
   605 CSmartCardEapDMmTsy::CThreadTerminationNotifier::~CThreadTerminationNotifier()
       
   606 	{
       
   607 	Cancel();
       
   608 	iCliThread.Close();
       
   609 	}
       
   610 
       
   611 //
       
   612 // methods for CActiveListNode
       
   613 //
       
   614 
       
   615 CSmartCardEapDMmTsy::CActiveListNode::CActiveListNode(CActive *aActive, const TTsyReqHandle aTsyReqHandle) :
       
   616 	iActive(aActive), iTsyReqHandle(aTsyReqHandle)
       
   617 	{
       
   618 	}
       
   619 
       
   620 CSmartCardEapDMmTsy::CActiveListNode::~CActiveListNode()
       
   621 	{
       
   622 	delete iActive;
       
   623 	}