/**
This function opens a RMobileSmartCardEap sub-session from RMobilePhone
that will refer to the application referenced by aAID.  It will be
assumed that the application exists and contains a DF_EAP for the
aEapType specified.  The client must call
RMobileSmartCardEap::InitialiseEapMethod() to ensure correct
functionality of this sub-session.

@param aPhone The RMobilePhone sub-session relative to which this
              sub-session will open.
@param aAId The UICC Application ID, which should be of one that has
            EAP support.
@param aEapType The EAP method type that this sub-session will use
                under the aAID application.

@return KErrNone if successful, otherwise a system-wide error code.
@see RMobileSmartCardEap::InitialiseEapMethod()

@capability None

@publishedPartner
@released
*/
EXPORT_C TInt RMobileSmartCardEap::Open(RMobilePhone& aPhone, const RMobilePhone::TAID& aAID, const TEapType& aEapType)
	{
	RSessionBase* session = &aPhone.SessionHandle();
	__ASSERT_ALWAYS(session != NULL, PanicClient(EEtelPanicNullHandle));
	TInt subSessionHandle = aPhone.SubSessionHandle();
	__ASSERT_ALWAYS(subSessionHandle != NULL, PanicClient(EEtelPanicNullHandle));

	TRAPD(ret, ConstructL());
	if (ret != KErrNone)
		{
		Destruct();
		return ret;
		}

	// Appending the application ID and Eap Type to the name of the
	// subsession; plus two one-byte delimeters indicating lengths.
	// See var appIdbuf for why KAIDSize is multiplied by 2.
	TBufC<SCEAP_SSN_LENGTH + RMobilePhone::KAIDSize*2 +
	      KEapTypeSize + 2> nameBuf(KETelSmartCardEapSession); // 2 for delimeters
	TPtr name(nameBuf.Des());

	// the length of the AID as a Sept ASCII character
	TChar lengthAIDChar = SeptChar(aAID.Length());

	// the value of the AID
	// converted to a 16-bit string representation.  Multiply by 2,
	// since each AID byte is represented as two sem-octects.
	TBufC<2*RMobilePhone::KAIDSize> appIdbuf;
	TPtr appIdPtr(appIdbuf.Des());
	ConvertBinToText(aAID, appIdPtr);

	// the length of the EapType
	TInt lengthEapType = aEapType.Length();
	TChar charEapType = SeptChar(lengthEapType);

	// the value of the EapType (converted to 16-bit)
	TBufC<KEapTypeSize> eapTypeBuf;
	TPtr eapTypePtr(eapTypeBuf.Des());
	eapTypePtr.Copy(aEapType);

	// appending...
	name.Append(lengthAIDChar);
	name.Append(appIdPtr);
	name.Append(charEapType);
	name.Append(eapTypePtr);

	TIpcArgs args(&name, TIpcArgs::ENothing, subSessionHandle);
	SetSessionHandle(*session);
	ret = CreateSubSession(*session, EEtelOpenFromSubSession, args);

	if (ret != KErrNone)
		{
		Destruct();
		}

	return ret;
	}