telephonyprotocols/pdplayer/src/PDPSCPRStates.cpp
changeset 0 3553901f7fa8
child 14 7ef16719d8cb
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 // PDP SubConnection Provider states/transitions
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <comms-infras/es_config.h>
       
    24 #include <comms-infras/corescpractivities.h>
       
    25 #include <comms-infras/ss_mcprnodemessages.h>
       
    26 #include "PDPSCPRStates.h"
       
    27 #include "PDPDeftSCPR.h"
       
    28 #include "PDPParamMapper.h"
       
    29 #include <comms-infras/ss_log.h>
       
    30 #include <networking/ipaddrinfoparams.h>
       
    31 #include <networking/mbmsparams.h>
       
    32 #include <ip_subconparams.h>
       
    33 #include <genericscprparams.h>
       
    34 #include "pdpfsmnmspace.h"
       
    35 #include "pdpdef.h"
       
    36 #include <comms-infras/ss_nodemessages_flow.h>
       
    37 #include <comms-infras/ss_nodemessages.h>
       
    38 #include <comms-infras/ss_api_ext.h>
       
    39 #include <elements/nm_messages_errorrecovery.h>
       
    40 #include <comms-infras/sockmes.h> // for ioctl ipc
       
    41 #include <nifvar_internal.h>
       
    42 #include <elements/mm_activities.h>
       
    43 
       
    44 using namespace Messages;
       
    45 using namespace MeshMachine;
       
    46 using namespace ESock;
       
    47 using namespace NetStateMachine;
       
    48 using namespace PDPSCprActivities;
       
    49 using namespace SpudMan;
       
    50 using namespace ConnectionServ;
       
    51 
       
    52 #ifdef _DEBUG
       
    53 _LIT (KPdpSCprPanic,"PpdScprPanic");
       
    54 #endif
       
    55 
       
    56 //-=========================================================
       
    57 //
       
    58 // States
       
    59 //
       
    60 //-=========================================================
       
    61 namespace PDPSCprStates
       
    62 {
       
    63 //-=========================================================
       
    64 //Util
       
    65 //-=========================================================
       
    66 DEFINE_SMELEMENT(TAwaitingPDPFSMMessage, NetStateMachine::MState, PDPSCprStates::TContext)
       
    67 TBool TAwaitingPDPFSMMessage::Accept()
       
    68     {
       
    69     return iContext.iMessage.IsMessage<TPDPFSMMessages::TPDPFSMMessage>();
       
    70     }
       
    71 
       
    72 DEFINE_SMELEMENT(TNoTagOrError, NetStateMachine::MStateFork, PDPSCprStates::TContext)
       
    73 TInt TNoTagOrError::TransitionTag()
       
    74     {
       
    75     ASSERT(iContext.iNodeActivity);
       
    76     TPDPFSMMessages::TPDPFSMMessage& msg = message_cast<TPDPFSMMessages::TPDPFSMMessage>(iContext.iMessage);
       
    77     if (msg.iValue2 != KErrNone)
       
    78         {
       
    79         iContext.iNodeActivity->SetError(msg.iValue2);
       
    80         return KErrorTag;
       
    81         }
       
    82     return KNoTag;
       
    83     }
       
    84 
       
    85 DEFINE_SMELEMENT(TNoTagOrAlreadyStarted, NetStateMachine::MStateFork, PDPSCprStates::TContext)
       
    86 TInt TNoTagOrAlreadyStarted::TransitionTag()
       
    87     {
       
    88     ASSERT(iContext.iMessage.IsMessage<TCFDataClient::TStart>());
       
    89     ASSERT(iContext.iNodeActivity);
       
    90     if (iContext.Node().iPDPFsmContextId != CPDPSubConnectionProvider::EInvalidContextId)
       
    91         {
       
    92         return CoreNetStates::KAlreadyStarted;
       
    93         }
       
    94     return KNoTag;
       
    95     }
       
    96 
       
    97 
       
    98 TBool TAwaitingPDPFSMMessage::Accept(TInt aExtensionId)
       
    99     {
       
   100     TPDPFSMMessages::TPDPFSMMessage* pdpmsg = message_cast<TPDPFSMMessages::TPDPFSMMessage>(&iContext.iMessage);
       
   101     if ( pdpmsg )
       
   102         {
       
   103         if (pdpmsg->iValue1 == aExtensionId)
       
   104             {
       
   105             return ETrue;
       
   106             }
       
   107         }
       
   108     return EFalse;
       
   109     }
       
   110 
       
   111 DEFINE_SMELEMENT(TSendDataClientIdleIfNoSubconnsAndNoClients, NetStateMachine::MStateTransition, PDPSCprStates::TDefContext)
       
   112 void TSendDataClientIdleIfNoSubconnsAndNoClients::DoL()
       
   113     {
       
   114 	iContext.Node().SendDataClientIdleIfNoSubconnsAndNoClientsL();
       
   115 	}
       
   116 
       
   117 DEFINE_SMELEMENT(TNoTagOrSendErrorRecoveryRequestOrError, NetStateMachine::MStateFork, PDPSCprStates::TContext)
       
   118 TInt TNoTagOrSendErrorRecoveryRequestOrError::TransitionTag()
       
   119 	{
       
   120 	ASSERT(iContext.iNodeActivity);
       
   121 	TPDPFSMMessages::TPDPFSMMessage& msg = message_cast<TPDPFSMMessages::TPDPFSMMessage>(iContext.iMessage);
       
   122 	if (msg.iValue2 == KErrUmtsMaxNumOfContextExceededByNetwork ||
       
   123 	    msg.iValue2 == KErrUmtsMaxNumOfContextExceededByPhone)
       
   124 		{
       
   125 		return KSendErrorRecoveryRequest;
       
   126 		}
       
   127 	else if (msg.iValue2 != KErrNone)
       
   128 		{
       
   129 		iContext.iNodeActivity->SetError(msg.iValue2);
       
   130 		return KErrorTag;
       
   131 		}
       
   132 	return KNoTag;
       
   133 	}
       
   134 
       
   135 DEFINE_SMELEMENT(TNoTagBackwardOrErrorTag, NetStateMachine::MStateFork, PDPSCprStates::TContext)
       
   136 TInt TNoTagBackwardOrErrorTag::TransitionTag()
       
   137 	{
       
   138 	__ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KPdpSCprPanic, CorePanics::KPanicNoActivity));
       
   139 	iContext.Node().SetContentionRequested(EFalse);
       
   140 	if (iContext.iMessage.IsMessage<TEErrorRecovery::TErrorRecoveryResponse>() &&
       
   141 		message_cast<TEErrorRecovery::TErrorRecoveryResponse>(iContext.iMessage).iErrResponse.iAction == TErrResponse::ERetry)
       
   142 		{
       
   143 		return KNoTag | NetStateMachine::EBackward;	
       
   144 		}
       
   145 
       
   146 		
       
   147 	TEErrorRecovery::TErrorRecoveryResponse* recoveryMsg = message_cast<TEErrorRecovery::TErrorRecoveryResponse>(&iContext.iMessage);
       
   148 	if (recoveryMsg)
       
   149 		{
       
   150 		iContext.iNodeActivity->SetError(recoveryMsg->iErrResponse.iError);
       
   151 		}
       
   152 		
       
   153 		
       
   154 	TEBase::TError* errMsg = message_cast<TEBase::TError>(&iContext.iMessage);
       
   155 	if (errMsg)
       
   156 		{
       
   157 		iContext.iNodeActivity->SetError(errMsg->iValue);
       
   158 		}
       
   159 	return KErrorTag;
       
   160 	}
       
   161 
       
   162 DEFINE_SMELEMENT(TNoTagOrContentionTag, NetStateMachine::MStateFork, PDPSCprStates::TContext)
       
   163 TInt TNoTagOrContentionTag::TransitionTag()
       
   164 	{
       
   165 	if (iContext.Node().ContentionRequested())
       
   166 		{
       
   167 		return KContentionTag;
       
   168 		}
       
   169 	return KNoTag;
       
   170 	}
       
   171 
       
   172 
       
   173 
       
   174 //-=========================================================
       
   175 //Provisioning
       
   176 //-=========================================================
       
   177 DEFINE_SMELEMENT(TSelfInit, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   178 void TSelfInit::DoL()
       
   179     {
       
   180     if (iContext.Node().iPdpFsmInterface == NULL)
       
   181         {
       
   182         //Non-default SCPR running this code
       
   183         ASSERT(iContext.Node().ControlProvider());
       
   184         ESock::TDefaultSCPRFactoryQuery query(iContext.Node().ControlProvider()->RecipientId(), TSubConnOpen::EAttachToDefault );
       
   185         ESock::CSubConnectionProviderBase* defProvider = static_cast<ESock::CSubConnectionProviderBase*>(static_cast<ESock::CSubConnectionProviderFactoryBase&>(iContext.Node().Factory()).Find(query));
       
   186         ASSERT(defProvider);
       
   187         iContext.Node().iDefaultSCPR = static_cast<CPDPDefaultSubConnectionProvider*>(defProvider);
       
   188         ASSERT(iContext.Node().iDefaultSCPR != &iContext.Node()); //This transition is not expected to be executed for defaults.
       
   189         ASSERT(iContext.Node().iDefaultSCPR->iPdpFsmInterface != NULL);
       
   190         ASSERT(iContext.Node().iPdpFsmInterface == NULL);
       
   191         iContext.Node().iPdpFsmInterface = iContext.Node().iDefaultSCPR->iPdpFsmInterface;
       
   192         iContext.Node().iPdpFsmInterface->Open();
       
   193         }
       
   194     else
       
   195         {
       
   196         //default SCPR running this code
       
   197         const CTSYProvision* tsyProvision = static_cast<const CTSYProvision*>(
       
   198 	        iContext.Node().AccessPointConfig().FindExtension(CTSYProvision::TypeId()));
       
   199         if (tsyProvision == NULL)
       
   200         	{
       
   201         	User::Leave(KErrCorrupt);
       
   202         	}
       
   203         CGPRSProvision* gprsProvision = const_cast<CGPRSProvision*>(static_cast<const CGPRSProvision*>(
       
   204         	    iContext.Node().AccessPointConfig().FindExtension(STypeId::CreateSTypeId(CGPRSProvision::EUid,CGPRSProvision::ETypeId))));
       
   205         if (gprsProvision == NULL)
       
   206                 	{
       
   207                 	User::Leave(KErrCorrupt);
       
   208                 	}
       
   209         switch(gprsProvision->UmtsGprsRelease())
       
   210         	{
       
   211         	case TPacketDataConfigBase::KConfigGPRS:
       
   212                 iContext.Node().iPdpFsmInterface->NewL(tsyProvision->iTsyName, TPacketDataConfigBase::KConfigGPRS);
       
   213         		break;
       
   214         	case TPacketDataConfigBase::KConfigRel99Rel4:
       
   215                 iContext.Node().iPdpFsmInterface->NewL(tsyProvision->iTsyName, TPacketDataConfigBase::KConfigRel99Rel4);
       
   216         		break;
       
   217         	case TPacketDataConfigBase::KConfigRel5:
       
   218                 iContext.Node().iPdpFsmInterface->NewL(tsyProvision->iTsyName, TPacketDataConfigBase::KConfigRel5);
       
   219         		break;
       
   220         	default:
       
   221         		User::Leave(KErrNotSupported);
       
   222         	}
       
   223 
       
   224         iContext.Node().iDefaultSCPR = static_cast<CPDPDefaultSubConnectionProvider*>(&iContext.Node());
       
   225         }
       
   226 
       
   227     //Replace the BCA provision - we'll be overriding the portname (the rest stays the same).
       
   228   
       
   229     // BA: This doesn't make sense, the port name is copied too so just replaces one CBCAProvision
       
   230     // with another identical one!!
       
   231 //    const CBCAProvision* bcaExtension = static_cast<const CBCAProvision*>(
       
   232 //        iContext.Node().AccessPointConfig().FindExtensionL(CBCAProvision::TypeId()));
       
   233 
       
   234 /*    
       
   235 	CBCAProvision* bcaExtension2 = new (ELeave) CBCAProvision;
       
   236 	CleanupStack::PushL(bcaExtension2);
       
   237 
       
   238 	//Could optimise it one day.
       
   239 	bcaExtension2->SetBCAStack(bcaExtension->GetBCAStack());
       
   240 	bcaExtension2->SetBCAName(bcaExtension->GetBCAName());
       
   241 	bcaExtension2->SetIAPid(bcaExtension->GetIAPid());
       
   242 	bcaExtension2->SetPortName(bcaExtension->GetPortName());
       
   243 	bcaExtension2->SetCommRole(bcaExtension->GetCommRole());
       
   244 	bcaExtension2->SetHandShaking(bcaExtension->GetHandShaking());
       
   245 
       
   246 	iContext.Node().iAccessPointConfig->RemoveAndDestroyExtension_INTERNALTECH(CBCAProvision::TypeId());
       
   247     iContext.Node().iAccessPointConfig->AppendExtensionL(bcaExtension2);
       
   248     CleanupStack::Pop(bcaExtension2); //Ownership with the list
       
   249 */ 
       
   250     }
       
   251 
       
   252 
       
   253 //-=========================================================
       
   254 //Creating context
       
   255 //-=========================================================
       
   256 MeshMachine::CNodeActivityBase* CStartActivity::NewL( const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode )
       
   257     {
       
   258     return new (ELeave) CStartActivity(aActivitySig, aNode);
       
   259     };
       
   260 
       
   261 CStartActivity::~CStartActivity()
       
   262     {
       
   263     RNodeInterface* startedDataClient = iNode.GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData, TCFClientType::EStarted));
       
   264     ASSERT(iNode.GetClientIter<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData))[1] == NULL);
       
   265     CPDPSubConnectionProvider& pdpscpr = static_cast<CPDPSubConnectionProvider&>(iNode);
       
   266     if (pdpscpr.iPDPFsmContextId == CPDPSubConnectionProvider::EInvalidContextId ||
       
   267         startedDataClient == NULL)
       
   268         {
       
   269         pdpscpr.LinkDown(Error());
       
   270         }
       
   271     }
       
   272 
       
   273 CStartActivity::CStartActivity( const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
       
   274 :MeshMachine::CNodeRetryActivity(aActivitySig, aNode)
       
   275     {
       
   276     }
       
   277 
       
   278 DEFINE_SMELEMENT(TCreateSecondaryOrMbmsPDPCtx, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   279 void TCreateSecondaryOrMbmsPDPCtx::DoL()
       
   280     {
       
   281     ASSERT(iContext.Node().iPdpFsmInterface);
       
   282 
       
   283   	RParameterFamily mbmsInfoFamily = iContext.Node().iParameterBundle.FindFamily(KSubConChannelParamsType);
       
   284   	STypeId typeId = STypeId::CreateSTypeId(KSubConChannelParamsImplUid, KSubConChannelParamsType);
       
   285     CSubConChannelParamSet *mbmsSubConParamSet = mbmsInfoFamily.IsNull() ? NULL :
       
   286     		(CSubConChannelParamSet *)(mbmsInfoFamily.FindParameterSet(typeId, RParameterFamily::ERequested));
       
   287 
       
   288     if (mbmsSubConParamSet)
       
   289 		{
       
   290 		RPacketMbmsContext::TContextConfigMbmsV1 mbmsConfig;
       
   291 		ConnectionServ::TMBMSChannelInfoV1* channelPtr = reinterpret_cast<ConnectionServ::TMBMSChannelInfoV1*>(mbmsSubConParamSet->GetChannelInfo());
       
   292    		mbmsConfig.iTmgi		 		= channelPtr->GetTmgi();
       
   293    	 	mbmsConfig.iMbmsServicePriority = channelPtr->GetServicePriority();
       
   294    		mbmsConfig.iMbmsAccessBearer    = channelPtr->GetScope();
       
   295 
       
   296    		TSessionOperatioInfo sessionInfo;
       
   297 		CSubConMBMSExtensionParamSet *mbmsSessionSet=static_cast<CSubConMBMSExtensionParamSet *>(mbmsInfoFamily.FindParameterSet(
       
   298 			STypeId::CreateSTypeId(KSubConMBMSExtParamsImplUid,KSubConMBMSSessionExtParamsType),RParameterFamily::ERequested));
       
   299 		if (mbmsSessionSet)
       
   300 			{
       
   301 			sessionInfo.iSessionIds.Reset();
       
   302 			for(TInt i=0;i<mbmsSessionSet->GetSessionCount();i++)
       
   303 				{
       
   304 				sessionInfo.iSessionIds.Append(mbmsSessionSet->GetSessionId(i));
       
   305 				}
       
   306 			sessionInfo.iOperation = mbmsSessionSet->GetOperationType();
       
   307 			mbmsConfig.iMbmsServiceMode  = mbmsSessionSet->GetServiceMode();
       
   308 			}
       
   309 		else
       
   310 			{
       
   311 			User::Leave(KErrCorrupt);
       
   312 			}
       
   313 
       
   314 		iContext.Node().iPDPFsmContextId = iContext.Node().iPdpFsmInterface->NewFsmContextL(iContext.Node(),SpudMan::EMbms);
       
   315 
       
   316 		iContext.Node().iContextType=SpudMan::EMbms;
       
   317 
       
   318        	iContext.Node().iPdpFsmInterface->Set(iContext.Node().iPDPFsmContextId,mbmsConfig);
       
   319 
       
   320 		TTFTInfo tft;
       
   321     	User::LeaveIfError(iContext.Node().iPdpFsmInterface->Set(iContext.Node().iPDPFsmContextId, tft));
       
   322     	User::LeaveIfError(iContext.Node().iPdpFsmInterface->Set(iContext.Node().iPDPFsmContextId, sessionInfo));
       
   323     	User::LeaveIfError(iContext.Node().iPdpFsmInterface->Input(iContext.Node().iPDPFsmContextId, SpudMan::ECreateMbmsPDPContext));
       
   324     	iContext.Node().iActivityAwaitingResponse = iContext.iNodeActivity->ActivityId();
       
   325     	sessionInfo.iSessionIds.Close();
       
   326     	}
       
   327 	else
       
   328 		{
       
   329 		// Reset the default QoS and TFT here. KContextQoSSet should arrive soon
       
   330 		// with the proper values.
       
   331 #ifdef SYMBIAN_NETWORKING_UMTSR5
       
   332 		RPacketQoS::TQoSR5Requested qos;
       
   333 #else
       
   334 		RPacketQoS::TQoSR99_R4Requested qos;
       
   335 #endif
       
   336 		// SYMBIAN_NETWORKING_UMTSR5
       
   337 
       
   338 		iContext.Node().iPDPFsmContextId = iContext.Node().iPdpFsmInterface->NewFsmContextL(iContext.Node(),SpudMan::ESecondary);
       
   339 
       
   340 		iContext.Node().iContextType = SpudMan::ESecondary;
       
   341 
       
   342 		User::LeaveIfError(iContext.Node().iPdpFsmInterface->Set(iContext.Node().iPDPFsmContextId,  qos));
       
   343 
       
   344 		TTFTInfo tft;
       
   345 		User::LeaveIfError(iContext.Node().iPdpFsmInterface->Set(iContext.Node().iPDPFsmContextId, tft));
       
   346 		User::LeaveIfError(iContext.Node().iPdpFsmInterface->Input(iContext.Node().iPDPFsmContextId, SpudMan::ECreateSecondaryPDPContext));
       
   347 		iContext.Node().iActivityAwaitingResponse = iContext.iNodeActivity->ActivityId();
       
   348 		}
       
   349     }
       
   350 
       
   351 DEFINE_SMELEMENT(TAwaitingPDPCtxCreated, NetStateMachine::MState, PDPSCprStates::TContext)
       
   352 TBool TAwaitingPDPCtxCreated::Accept()
       
   353     {
       
   354     if (iContext.Node().iContextType != SpudMan::EMbms)
       
   355     	{
       
   356     	return TAwaitingPDPFSMMessage::Accept(KSecondaryContextCreated);
       
   357     	}
       
   358     else
       
   359     	{
       
   360        	return TAwaitingPDPFSMMessage::Accept(KMbmsContextCreated); //
       
   361 		}
       
   362     }
       
   363 
       
   364 DEFINE_SMELEMENT(TAwaitingPrimaryPDPCtxCreated, NetStateMachine::MState, PDPSCprStates::TContext)
       
   365 TBool TAwaitingPrimaryPDPCtxCreated::Accept()
       
   366     {
       
   367     return TAwaitingPDPFSMMessage::Accept(KPrimaryContextCreated);
       
   368     }
       
   369 
       
   370 DEFINE_SMELEMENT(TCreatePrimaryPDPCtx, NetStateMachine::MStateTransition, PDPSCprStates::TDefContext)
       
   371 void TCreatePrimaryPDPCtx::SetupSipServerAddrRetrievalL(RPacketContext::TProtocolConfigOptionV2& aPco)
       
   372 	{
       
   373 	TPtr8 pcoPtr(const_cast<TUint8*>(aPco.iMiscBuffer.Ptr()),aPco.iMiscBuffer.Length(),aPco.iMiscBuffer.MaxLength());
       
   374 
       
   375 	// attach TTlv to the buffer
       
   376 	TTlvStruct<RPacketContext::TPcoId,RPacketContext::TPcoItemDataLength> tlv(pcoPtr,0);
       
   377 	tlv.AppendItemL(RPacketContext::TPcoId(RPacketContext::EEtelPcktPCSCFAddressRequest),
       
   378 		TPtr8(static_cast<TUint8*>(NULL), 0, 0));
       
   379 	aPco.iMiscBuffer.SetLength(pcoPtr.Length());
       
   380 	}
       
   381 
       
   382 void TCreatePrimaryPDPCtx::SetImsSignallingFlagL(RPacketContext::TProtocolConfigOptionV2& aPco, TBool aImcn)
       
   383 	{
       
   384 	if (aImcn)
       
   385 		{
       
   386 		TPtr8 pcoPtr(const_cast<TUint8*>(aPco.iMiscBuffer.Ptr()),aPco.iMiscBuffer.Length(),aPco.iMiscBuffer.MaxLength());
       
   387 		TTlvStruct<RPacketContext::TPcoId,RPacketContext::TPcoItemDataLength> tlv(pcoPtr,0);
       
   388 		tlv.AppendItemL(RPacketContext::TPcoId(RPacketContext::EEtelPcktIMCNMSSubsystemSignallingFlag ),
       
   389 						TPtr8(static_cast<TUint8*>(NULL), 0, 0));
       
   390 		aPco.iMiscBuffer.SetLength(pcoPtr.Length());
       
   391 		}
       
   392 	}
       
   393 
       
   394 TBool TCreatePrimaryPDPCtx::IsModeGsmL() const
       
   395 	{
       
   396     const CTSYProvision* tsyProvision = static_cast<const CTSYProvision*>(
       
   397     	iContext.Node().AccessPointConfig().FindExtension(CTSYProvision::TypeId()));
       
   398 	if (tsyProvision == NULL)
       
   399 		{
       
   400 		User::Leave(KErrCorrupt);
       
   401 		}
       
   402 
       
   403 	RTelServer telServer;
       
   404 	User::LeaveIfError(telServer.Connect());
       
   405 	CleanupClosePushL(telServer);
       
   406 
       
   407 	User::LeaveIfError(telServer.LoadPhoneModule(tsyProvision->iTsyName));
       
   408 
       
   409 	TInt phones = 0;
       
   410 	User::LeaveIfError(telServer.EnumeratePhones(phones));
       
   411 
       
   412 	RTelServer::TPhoneInfo phoneInfo;
       
   413 	TBuf<KCommsDbSvrMaxFieldLength> currentTsyName;
       
   414 	TBool found = EFalse;
       
   415 	_LIT(KTsyNameExtension, ".tsy");
       
   416 	for (TInt i = 0; i < phones; ++i)
       
   417 		{
       
   418 		User::LeaveIfError(telServer.GetTsyName(i, currentTsyName));
       
   419 		// remove .TSY extension if necessary
       
   420 		if (currentTsyName.Right(4).CompareF(KTsyNameExtension()) == 0)
       
   421 			{
       
   422 			currentTsyName = currentTsyName.Left(currentTsyName.Length() - 4);
       
   423 			}
       
   424 		// compare current TSY name with the one we're looking for
       
   425 		if (currentTsyName.CompareF(tsyProvision->iTsyName) == 0)
       
   426 			{
       
   427 			// get phone info from the TSY
       
   428 			User::LeaveIfError(telServer.GetPhoneInfo(i, phoneInfo));
       
   429 			found = ETrue;
       
   430 			break;
       
   431 			}
       
   432 		}
       
   433 	if (!found)
       
   434 		{
       
   435 		User::Leave(KErrNotFound);
       
   436 		}
       
   437 
       
   438 	RMobilePhone phone;
       
   439 	User::LeaveIfError(phone.Open(telServer, phoneInfo.iName));
       
   440 	CleanupClosePushL(phone);
       
   441 
       
   442 	RMobilePhone::TMobilePhoneNetworkMode networkMode = RMobilePhone::ENetworkModeUnknown;
       
   443 	User::LeaveIfError(phone.GetCurrentMode(networkMode));
       
   444 	CleanupStack::PopAndDestroy(2); // phone, telServer
       
   445 	return (networkMode == RMobilePhone::ENetworkModeGsm);
       
   446 	}
       
   447 
       
   448 void TCreatePrimaryPDPCtx::DoL()
       
   449     {
       
   450     ASSERT(iContext.Node().iPdpFsmInterface);
       
   451 
       
   452     iContext.Node().PostToClients<TDefaultClientMatchPolicy>(
       
   453             iContext.NodeId(),
       
   454             TCFMessage::TStateChange(
       
   455                     Elements::TStateChange(KPsdStartingConfiguration, KErrNone)).CRef(),
       
   456             TClientType(TCFClientType::ECtrlProvider));
       
   457 
       
   458 	CGPRSProvision* gprsProvision = const_cast<CGPRSProvision*>(static_cast<const CGPRSProvision*>(
       
   459 	    iContext.Node().AccessPointConfig().FindExtension(STypeId::CreateSTypeId(CGPRSProvision::EUid,CGPRSProvision::ETypeId))));
       
   460 
       
   461 	//retrieve QoS (should be provisioned, but can also be overriden with SetParams).
       
   462 	RPacketQoS::TQoSR5Requested qosOverridenParams;
       
   463 	const RPacketQoS::TQoSR5Requested* qosParams = NULL;
       
   464 	if (! iContext.Node().iParameterBundle.IsNull() && ! iContext.Node().iParameterBundle.FindFamily(KSubConQoSFamily).IsNull())
       
   465     	{
       
   466     	MPDPParamMapper::MapQosParamBundleToEtelL(iContext.Node().iParameterBundle, qosOverridenParams);
       
   467     	qosParams = &qosOverridenParams;
       
   468     	}
       
   469 	else
       
   470     	{
       
   471     	const CDefaultPacketQoSProvision* defaultQoSProvision = static_cast<const CDefaultPacketQoSProvision*>(
       
   472     	    iContext.Node().AccessPointConfig().FindExtension(STypeId::CreateSTypeId(CDefaultPacketQoSProvision::EUid,CDefaultPacketQoSProvision::ETypeId)));
       
   473     	qosParams = defaultQoSProvision ? &defaultQoSProvision->iParams : NULL;
       
   474 
       
   475         //Here we're taking the qos defaults from the provision info, hence skipping the iParameterBundle.
       
   476         //The lack of iParameterBundle however and the respective ERequested params is badly tolerated by the rest
       
   477         //of the code (e.g.: when subsequently raising granted params it is assumed something has been requested).
       
   478         //Let's create a phoney requested params.
       
   479         //iContext.Node().CreateParameterBundleL();
       
   480 		//RParameterFamily family = iContext.Node().iParameterBundle.CreateFamilyL(KSubConQoSFamily); //PJLEFT
       
   481 
       
   482 		RCFParameterFamilyBundle newBundle;
       
   483 		newBundle.CreateL();
       
   484 		iContext.Node().iParameterBundle.Open(newBundle);
       
   485 		RParameterFamily family = newBundle.CreateFamilyL(KSubConQoSFamily);
       
   486 		CSubConQosGenericParamSet::NewL(family, RParameterFamily::ERequested);
       
   487     	}
       
   488 	TTFTInfo tft; //We'll use empty/thus default TFT
       
   489 	if (gprsProvision == NULL || qosParams == NULL)
       
   490     	{
       
   491     	User::Leave(KErrCorrupt);
       
   492     	}
       
   493 
       
   494 	const CImsExtProvision* imsprov = static_cast<const CImsExtProvision*>(
       
   495 		iContext.Node().AccessPointConfig().FindExtension(STypeId::CreateSTypeId(CImsExtProvision::EUid, CImsExtProvision::ETypeId)));
       
   496 
       
   497 
       
   498 	switch (gprsProvision->UmtsGprsRelease())
       
   499 			{
       
   500 	    	case TPacketDataConfigBase::KConfigGPRS:
       
   501 				{
       
   502 				SetImsSignallingFlagL(gprsProvision->GetScratchContextAs<RPacketContext::TContextConfigGPRS>().iProtocolConfigOption, imsprov->iImsSignalIndicator);
       
   503 				}
       
   504 				break;
       
   505 	    	case TPacketDataConfigBase::KConfigRel5:
       
   506 		    case TPacketDataConfigBase::KConfigRel99Rel4:
       
   507 				{
       
   508 				SetImsSignallingFlagL(gprsProvision->GetScratchContextAs<RPacketContext::TContextConfigR99_R4>().iProtocolConfigOption, imsprov->iImsSignalIndicator);
       
   509 				}
       
   510 				break;
       
   511 			}
       
   512 
       
   513 	TRAP_IGNORE(iContext.Node().iIsModeGsm = IsModeGsmL());
       
   514 
       
   515 	// Only request SIP server address retrieval when network not in GSM/GPRS mode
       
   516 	// e.g. UMTS/WCDMA
       
   517 	if (!iContext.Node().iIsModeGsm)
       
   518 		{
       
   519 		switch (gprsProvision->UmtsGprsRelease())
       
   520 			{
       
   521 	    	case TPacketDataConfigBase::KConfigGPRS:
       
   522 				{
       
   523 				SetupSipServerAddrRetrievalL(gprsProvision->GetScratchContextAs<RPacketContext::TContextConfigGPRS>().iProtocolConfigOption);
       
   524 				}
       
   525 				break;
       
   526 	    	case TPacketDataConfigBase::KConfigRel5:
       
   527 		    case TPacketDataConfigBase::KConfigRel99Rel4:
       
   528 				{
       
   529 				SetupSipServerAddrRetrievalL(gprsProvision->GetScratchContextAs<RPacketContext::TContextConfigR99_R4>().iProtocolConfigOption);
       
   530 				}
       
   531 				break;
       
   532 			}
       
   533 		}
       
   534 	
       
   535 	iContext.Node().iPDPFsmContextId = iContext.Node().iPdpFsmInterface->NewFsmContextL(iContext.Node(),SpudMan::EPrimary);
       
   536 
       
   537     iContext.Node().PostToClients<TDefaultClientMatchPolicy>(
       
   538             iContext.NodeId(),
       
   539             TCFMessage::TStateChange(
       
   540                     Elements::TStateChange(KPsdFinishedConfiguration, KErrNone)).CRef(),
       
   541             TClientType(TCFClientType::ECtrlProvider));
       
   542 
       
   543     iContext.Node().PostToClients<TDefaultClientMatchPolicy>(
       
   544             iContext.NodeId(),
       
   545             TCFMessage::TStateChange(
       
   546                     Elements::TStateChange(KPsdStartingActivation, KErrNone)).CRef(),
       
   547             TClientType(TCFClientType::ECtrlProvider));
       
   548 
       
   549 	ASSERT(iContext.Node().iPDPFsmContextId == KPrimaryContextId);
       
   550 	iContext.Node().iContextType=SpudMan::EPrimary;
       
   551 	iContext.Node().iPdpFsmInterface->Set(KPrimaryContextId, gprsProvision->GetScratchContextAs<TPacketDataConfigBase>());
       
   552 	//Set default QoS
       
   553 	iContext.Node().iPdpFsmInterface->Set(KPrimaryContextId, *qosParams);
       
   554     //Set default TFTs
       
   555     iContext.Node().iPdpFsmInterface->Set(KPrimaryContextId,  tft); // ignore any error
       
   556     //Start the primary.
       
   557     User::LeaveIfError(iContext.Node().iPdpFsmInterface->Input(KPrimaryContextId, SpudMan::ECreatePrimaryPDPContext));
       
   558     iContext.iNodeActivity->ClearPostedTo();
       
   559     iContext.Node().iActivityAwaitingResponse = iContext.iNodeActivity->ActivityId();
       
   560     }
       
   561 
       
   562 DEFINE_SMELEMENT(TOverrideProvision, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   563 void TOverrideProvision::DoL()
       
   564     {
       
   565 	const CBCAProvision& bcaExtension = static_cast<const CBCAProvision&>(iContext.Node().AccessPointConfig().FindExtensionL(CBCAProvision::TypeId()));
       
   566    		
       
   567     // This cannot return NULL - checked in an earlier transition
       
   568 	const CTSYProvision& tsyProvision = static_cast<const CTSYProvision&>(
       
   569         iContext.Node().AccessPointConfig().FindExtensionL(CTSYProvision::TypeId()));
       
   570 	
       
   571 	RPacketContext::TDataChannelV2& dataChannel = iContext.Node().iTempDataChannelV2;
       
   572 	iContext.Node().iPdpFsmInterface->Get(iContext.Node().iPDPFsmContextId, dataChannel);
       
   573 
       
   574 	// The telephony etel documentation is confusing/misleading.
       
   575 	// In source it states that both iChannel and iPort have been deprecated, and that iPort is undeprecated
       
   576 	// and that iPort should be used.
       
   577 	// Other etel documentation states that iPort is deprecated and that iChannel should be used.
       
   578 	// Current CBS TA advise suggests iChannelId should be used rather than iPort
       
   579 	// Legacy SPUDs and this PDP SCpr use iPort and will do this when common TSY is not used maintaining compatibility with existing licensee TSYs
       
   580 	
       
   581 	_LIT(KCommonTsy, "phonetsy");
       
   582 	if (!tsyProvision.iTsyName.Left(KCommonTsy().Length()).CompareF(KCommonTsy))
       
   583 		{
       
   584 		// CTSY has been changed to return the context name + channel Id in iChannelId,
       
   585 		const_cast<CBCAProvision&>(bcaExtension).SetPortName(dataChannel.iChannelId);
       
   586 		}
       
   587 	else
       
   588 		{
       
   589 		// Co-incidentally SIMTSY will return the same value in both iChannelId and iPort meaning that
       
   590 		// a change here would not show a regression in our tests - YOU HAVE BEEN CAUTIONED!
       
   591 		const_cast<CBCAProvision&>(bcaExtension).SetPortName(dataChannel.iPort);
       
   592     	}
       
   593 	
       
   594 	if (iContext.Node().iContextType != SpudMan::EMbms)
       
   595     	{
       
   596 		CGPRSProvision& gprsProvision = const_cast<CGPRSProvision&>(static_cast<const CGPRSProvision&>(
       
   597 	    	iContext.Node().AccessPointConfig().FindExtensionL(STypeId::CreateSTypeId(CGPRSProvision::EUid,CGPRSProvision::ETypeId))));
       
   598 		iContext.Node().iPdpFsmInterface->Get(iContext.Node().iPDPFsmContextId, gprsProvision.GetScratchContextAs<TPacketDataConfigBase>());
       
   599     	}
       
   600 	iContext.Node().PostToClients<TDefaultClientMatchPolicy>(
       
   601 	        iContext.NodeId(),
       
   602 	        TCFMessage::TStateChange(
       
   603 	                Elements::TStateChange(KPsdFinishedActivation, KErrNone)).CRef(),
       
   604 	                TClientType(TCFClientType::ECtrlProvider));
       
   605     }
       
   606 
       
   607 DEFINE_SMELEMENT(TSendErrorRecoveryRequest, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   608 void TSendErrorRecoveryRequest::DoL()
       
   609 	{
       
   610 	TPDPFSMMessages::TPDPFSMMessage* msg = message_cast<TPDPFSMMessages::TPDPFSMMessage>(&iContext.iMessage);
       
   611 
       
   612 	__ASSERT_DEBUG(msg, User::Panic(KPdpSCprPanic,  CorePanics::KPanicIncorrectMessage));
       
   613 	__ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KPdpSCprPanic, CorePanics::KPanicNoActivity));
       
   614 
       
   615 	const RNodeInterface* controlProvider = iContext.Node().ControlProvider();
       
   616 	__ASSERT_DEBUG(controlProvider, User::Panic(KPdpSCprPanic, CorePanics::KPanicNoControlProvider));
       
   617 
       
   618 	
       
   619 	TErrContext ctx(controlProvider->RecipientId(), msg->MessageId(), iContext.iNodeActivity->ActivitySigId(), Elements::TStateChange(0, msg->iValue2));
       
   620 
       
   621 	TEErrorRecovery::TErrorRecoveryRequest rawReq(ctx);
       
   622 	
       
   623 	
       
   624 	iContext.iNodeActivity->PostRequestTo(
       
   625 		*controlProvider,
       
   626 		TCFSafeMessage::TRequestCarrierEast<TEErrorRecovery::TErrorRecoveryRequest>(rawReq).CRef()
       
   627 		);
       
   628 	iContext.iNodeActivity->ClearPostedTo();
       
   629 
       
   630 	iContext.Node().SetContentionRequested(ETrue);
       
   631 	}
       
   632 
       
   633 
       
   634 
       
   635 //-=========================================================
       
   636 //Activiating context
       
   637 //-=========================================================
       
   638 
       
   639 DEFINE_SMELEMENT(TActivatePDPContext, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   640 void TActivatePDPContext::DoL()
       
   641     {
       
   642     ASSERT(iContext.Node().iPdpFsmInterface);
       
   643     User::LeaveIfError(iContext.Node().iPdpFsmInterface->Input(iContext.Node().iPDPFsmContextId, SpudMan::EContextActivate));
       
   644 
       
   645     //Expect Response
       
   646     iContext.iNodeActivity->ClearPostedTo();
       
   647     iContext.Node().iActivityAwaitingResponse = iContext.iNodeActivity->ActivityId();
       
   648     }
       
   649 
       
   650 
       
   651 DEFINE_SMELEMENT(TAwaitingPDPContextActive, NetStateMachine::MState, PDPSCprStates::TContext)
       
   652 TBool TAwaitingPDPContextActive::Accept()
       
   653     {
       
   654     return TAwaitingPDPFSMMessage::Accept(KContextActivateEvent);
       
   655     }
       
   656 
       
   657 DEFINE_SMELEMENT(TModifyActivePDPContext, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   658 void TModifyActivePDPContext::DoL()
       
   659     {
       
   660     ASSERT(iContext.Node().iPdpFsmInterface);
       
   661 
       
   662     TBool QoSChanged=MPDPParamMapper::QoSRequested(iContext.Node().iParameterBundle);
       
   663 
       
   664     const RParameterFamily &IPAddressInfoFamily = iContext.Node().iParameterBundle.FindFamily(KSubConIPAddressInfoFamily);
       
   665     const CSubConIPAddressInfoParamSet* IPAddressInfoSet = IPAddressInfoFamily.IsNull() ? NULL : static_cast<const CSubConIPAddressInfoParamSet*>(
       
   666                IPAddressInfoFamily.FindParameterSet(STypeId::CreateSTypeId(CSubConIPAddressInfoParamSet::EUid,CSubConIPAddressInfoParamSet::ETypeId),RParameterFamily::ERequested));
       
   667 
       
   668    	TBool TFTChanged = IPAddressInfoSet?ETrue:EFalse;
       
   669 
       
   670    	if(QoSChanged || TFTChanged)
       
   671    	    {
       
   672         User::LeaveIfError(iContext.Node().iPdpFsmInterface->Input(iContext.Node().iPDPFsmContextId, SpudMan::EContextModifyActive));
       
   673    	    }
       
   674    	else
       
   675    	    {
       
   676         RClientInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.NodeId(),
       
   677             TPDPFSMMessages::TPDPFSMMessage(KContextModifyActiveEvent, KErrNone).CRef());
       
   678    	    }
       
   679 
       
   680     //Expect Response
       
   681     iContext.iNodeActivity->ClearPostedTo();
       
   682     iContext.Node().iActivityAwaitingResponse = iContext.iNodeActivity->ActivityId();
       
   683     }
       
   684 
       
   685 DEFINE_SMELEMENT(TAwaitingActivePDPContextModified, NetStateMachine::MState, PDPSCprStates::TContext)
       
   686 TBool TAwaitingActivePDPContextModified::Accept()
       
   687     {
       
   688     return TAwaitingPDPFSMMessage::Accept(KContextModifyActiveEvent);
       
   689     }
       
   690 
       
   691 DEFINE_SMELEMENT(TAwaitingNegotiatedQoSRetrieved, NetStateMachine::MState, PDPSCprStates::TContext)
       
   692 TBool TAwaitingNegotiatedQoSRetrieved::Accept()
       
   693     {
       
   694 
       
   695     return TAwaitingPDPFSMMessage::Accept(KGetNegQoSEvent);
       
   696     }
       
   697 
       
   698 DEFINE_SMELEMENT(TGetNegotiatedQoS, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   699 void TGetNegotiatedQoS::DoL()
       
   700     {
       
   701     if (iContext.Node().iContextType == SpudMan::EMbms)
       
   702     	{
       
   703     	//just move to next step
       
   704     	RClientInterface::OpenPostMessageClose(
       
   705     			TNodeCtxId(iContext.ActivityId(), iContext.NodeId()),
       
   706     			iContext.NodeId(),
       
   707     			TPDPFSMMessages::TPDPFSMMessage(KGetNegQoSEvent, KErrNone).CRef()
       
   708     			);
       
   709     	}
       
   710     else
       
   711     	{
       
   712     	ASSERT(iContext.Node().iPdpFsmInterface);
       
   713     	User::LeaveIfError(iContext.Node().iPdpFsmInterface->Input(iContext.Node().iPDPFsmContextId, SpudMan::EGetNegQoS));
       
   714     	}
       
   715     //Expect Response
       
   716     iContext.iNodeActivity->ClearPostedTo();
       
   717     iContext.Node().iActivityAwaitingResponse = iContext.iNodeActivity->ActivityId();
       
   718     }
       
   719 
       
   720 
       
   721 DEFINE_SMELEMENT(TSendDataClientStarted, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   722 void TSendDataClientStarted::DoL()
       
   723     {
       
   724     PRStates::TSendDataClientStarted coreDCStarted(iContext);
       
   725     coreDCStarted.DoL();
       
   726     iContext.Node().LinkUp();
       
   727     }
       
   728 
       
   729 DEFINE_SMELEMENT(TSendDataClientStopped, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   730 void TSendDataClientStopped::DoL()
       
   731     {
       
   732     PRStates::TSendDataClientStopped coreDCStopped(iContext);
       
   733     coreDCStopped.DoL();
       
   734     iContext.Node().LinkDown(coreDCStopped.iStopCode);
       
   735     }
       
   736 
       
   737 
       
   738 
       
   739 //-=========================================================
       
   740 //Setting Params
       
   741 //-=========================================================
       
   742 DEFINE_SMELEMENT(TSetQoS, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   743 void TSetQoS::DoL()
       
   744     {
       
   745     ASSERT(iContext.Node().iPdpFsmInterface);
       
   746     ASSERT(!iContext.Node().GetParameterBundle().IsNull());
       
   747 
       
   748     if (MPDPParamMapper::QoSRequested(iContext.Node().GetParameterBundle()))
       
   749         {
       
   750         RPacketQoS::TQoSR5Requested requestedParams;
       
   751         iContext.Node().iParamsRelease = MPDPParamMapper::MapQosParamBundleToEtelL(iContext.Node().GetParameterBundle(), requestedParams);
       
   752         iContext.Node().iPdpFsmInterface->Set(iContext.Node().iPDPFsmContextId, requestedParams);
       
   753         User::LeaveIfError(iContext.Node().iPdpFsmInterface->Input(iContext.Node().iPDPFsmContextId, SpudMan::EContextQoSSet));
       
   754         }
       
   755     else
       
   756         {
       
   757         //No QoS Requested. Complete this message locally to push yourself forward
       
   758         RClientInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.NodeId(),
       
   759         	TPDPFSMMessages::TPDPFSMMessage(KContextQoSSetEvent, KErrNone).CRef());
       
   760         }
       
   761 
       
   762     //Expect Response
       
   763     iContext.iNodeActivity->ClearPostedTo();
       
   764     iContext.Node().iActivityAwaitingResponse = iContext.iNodeActivity->ActivityId();
       
   765     }
       
   766 
       
   767 DEFINE_SMELEMENT(TAwaitingQoSSet, NetStateMachine::MState, PDPSCprStates::TContext)
       
   768 TBool TAwaitingQoSSet::Accept()
       
   769     {
       
   770     return TAwaitingPDPFSMMessage::Accept(KContextQoSSetEvent);
       
   771     }
       
   772 
       
   773 DEFINE_SMELEMENT(TSetTFT, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   774 void TSetTFT::DoL()
       
   775     {
       
   776     ASSERT(iContext.Node().iPdpFsmInterface);
       
   777     ASSERT(!iContext.Node().GetParameterBundle().IsNull());
       
   778 
       
   779 	RParameterFamily ipAddressInfoFamily =
       
   780 		iContext.Node().GetParameterBundle().FindFamily(KSubConIPAddressInfoFamily);
       
   781 	CSubConIPAddressInfoParamSet* ipAddressInfoSet = NULL;
       
   782 	if( ! ipAddressInfoFamily.IsNull())
       
   783 		{
       
   784 		ipAddressInfoSet = static_cast<CSubConIPAddressInfoParamSet*>(
       
   785 			ipAddressInfoFamily.FindParameterSet(
       
   786 				STypeId::CreateSTypeId(CSubConIPAddressInfoParamSet::EUid,CSubConIPAddressInfoParamSet::ETypeId),
       
   787 					RParameterFamily::ERequested));
       
   788 		}
       
   789 
       
   790     if (ipAddressInfoSet)
       
   791         {
       
   792         iContext.Node().iPdpFsmInterface->Set(iContext.Node().iPDPFsmContextId, iContext.Node().GetTftInfoL(ipAddressInfoSet));
       
   793         iContext.Node().iPdpFsmInterface->Set(iContext.Node().iPDPFsmContextId, iContext.Node().GetOperationCodeL(ipAddressInfoSet));
       
   794         User::LeaveIfError(iContext.Node().iPdpFsmInterface->Input(iContext.Node().iPDPFsmContextId, SpudMan::EContextTFTModify));
       
   795         }
       
   796     else
       
   797         {
       
   798         //No QoS Requested. Complete this message locally to push yourself forward
       
   799         RClientInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.NodeId(),
       
   800         	TPDPFSMMessages::TPDPFSMMessage(KContextTFTModifiedEvent, KErrNone).CRef());
       
   801         }
       
   802 
       
   803     //Expect Response
       
   804     iContext.iNodeActivity->ClearPostedTo();
       
   805     iContext.Node().iActivityAwaitingResponse = iContext.iNodeActivity->ActivityId();
       
   806     }
       
   807 
       
   808 DEFINE_SMELEMENT(TAwaitingTFTSet, NetStateMachine::MState, PDPSCprStates::TDefContext)
       
   809 TBool TAwaitingTFTSet::Accept()
       
   810     {
       
   811     return TAwaitingPDPFSMMessage::Accept(KContextTFTModifiedEvent);
       
   812     }
       
   813 
       
   814 
       
   815 
       
   816 //-=========================================================
       
   817 //Setting MBMS Params (session ids)
       
   818 //-=========================================================
       
   819 DEFINE_SMELEMENT(TSetMbmsParameters, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   820 void TSetMbmsParameters::DoL()
       
   821     {
       
   822     ASSERT(iContext.Node().iPdpFsmInterface);
       
   823     if (iContext.Node().iContextType == SpudMan::EMbms)
       
   824 		{
       
   825 		/* extract session ids from MBMS Extension Set*/
       
   826 		RParameterFamily mbmsInfoFamily = iContext.Node().iParameterBundle.FindFamily(KSubConChannelParamsType);
       
   827    		CSubConMBMSExtensionParamSet *mbmsExtensionSet = mbmsInfoFamily.IsNull() ? 	NULL :
       
   828    		   static_cast<CSubConMBMSExtensionParamSet *>(mbmsInfoFamily.FindParameterSet(
       
   829    		   		STypeId::CreateSTypeId(KSubConMBMSExtParamsImplUid,KSubConMBMSSessionExtParamsType), RParameterFamily::ERequested));
       
   830 		if (mbmsExtensionSet)
       
   831 			{
       
   832 			TSessionOperatioInfo sessionInfo;
       
   833 			sessionInfo.iSessionIds.Reset();
       
   834 			for(int i=0 ;i < mbmsExtensionSet->GetSessionCount(); i++)
       
   835 				{
       
   836 				sessionInfo.iSessionIds.Append(mbmsExtensionSet->GetSessionId(i));
       
   837 				}
       
   838 			sessionInfo.iOperation=mbmsExtensionSet->GetOperationType();
       
   839 			User::LeaveIfError(iContext.Node().iPdpFsmInterface->Set(iContext.Node().iPDPFsmContextId, sessionInfo));
       
   840 			User::LeaveIfError(iContext.Node().iPdpFsmInterface->Input(iContext.Node().iPDPFsmContextId, SpudMan::EMbmsSessionUpdate));
       
   841 			sessionInfo.iSessionIds.Close();
       
   842 			}
       
   843 		}
       
   844 	}
       
   845 
       
   846 //-=========================================================
       
   847 //Events
       
   848 //-=========================================================
       
   849 DEFINE_SMELEMENT(TBlockedOrUnblocked, NetStateMachine::MStateFork, PDPSCprStates::TContext)
       
   850 TInt TBlockedOrUnblocked::TransitionTag()
       
   851 	{
       
   852 	TPDPFSMMessages::TPDPFSMMessage& pdpmsg = message_cast<TPDPFSMMessages::TPDPFSMMessage>(iContext.iMessage);
       
   853 	if (pdpmsg.iValue1 == KContextBlockedEvent)
       
   854 		return KBlocked;
       
   855 	else
       
   856 		return KUnblocked;
       
   857 	}
       
   858 
       
   859 
       
   860 
       
   861 DEFINE_SMELEMENT(TAwaitingParamsChanged, NetStateMachine::MState, PDPSCprStates::TContext)
       
   862 TBool TAwaitingParamsChanged::Accept()
       
   863     {
       
   864     return TAwaitingPDPFSMMessage::Accept(KContextParametersChangeEvent);
       
   865     }
       
   866 
       
   867 DEFINE_SMELEMENT(TAwaitingContextBlockedOrUnblocked, NetStateMachine::MState, PDPSCprStates::TContext)
       
   868 TBool TAwaitingContextBlockedOrUnblocked::Accept()
       
   869     {
       
   870     return TAwaitingPDPFSMMessage::Accept(KContextBlockedEvent) || TAwaitingPDPFSMMessage::Accept(KContextUnblockedEvent);
       
   871     }
       
   872 
       
   873 DEFINE_SMELEMENT(TForwardContextBlockedOrUnblockedToDC, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   874 void TForwardContextBlockedOrUnblockedToDC::DoL()
       
   875     {
       
   876     TPDPFSMMessages::TPDPFSMMessage& pdpmsg = message_cast<TPDPFSMMessages::TPDPFSMMessage>(iContext.iMessage);
       
   877 
       
   878 	RNodeInterface* theOnlyDataClient = iContext.iNode.GetFirstClient<TDefaultClientMatchPolicy>(TCFClientType::EData);
       
   879 	ASSERT(iContext.iNode.GetClientIter<TDefaultClientMatchPolicy>(TCFClientType::EData)[1] == NULL);
       
   880     ASSERT(theOnlyDataClient);
       
   881 
       
   882     switch (pdpmsg.iValue1)
       
   883         {
       
   884         case KContextBlockedEvent:
       
   885         theOnlyDataClient->PostMessage(iContext.NodeId(), ESock::TCFFlow::TBlock().CRef());
       
   886         break;
       
   887 
       
   888         case KContextUnblockedEvent:
       
   889         theOnlyDataClient->PostMessage(iContext.NodeId(), ESock::TCFFlow::TUnBlock().CRef());
       
   890         break;
       
   891 
       
   892         default:
       
   893         ASSERT(EFalse);
       
   894         }
       
   895     }
       
   896 
       
   897 DEFINE_SMELEMENT(TSendDataTransferTemporarilyBlocked, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   898 void TSendDataTransferTemporarilyBlocked::DoL()
       
   899     {
       
   900     if (iContext.Node().iPDPFsmContextId == KPrimaryContextId)
       
   901         {
       
   902         iContext.Node().PostToClients<TDefaultClientMatchPolicy>(
       
   903                 iContext.NodeId(),
       
   904                 TCFMessage::TStateChange(
       
   905                     Elements::TStateChange(KDataTransferTemporarilyBlocked, KErrNone)).CRef(),
       
   906                     TClientType(TCFClientType::ECtrlProvider));
       
   907         }
       
   908 	}
       
   909 
       
   910 DEFINE_SMELEMENT(TSendDataTransferUnblocked, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   911 void TSendDataTransferUnblocked::DoL()
       
   912     {
       
   913     if (iContext.Node().iPDPFsmContextId == KPrimaryContextId)
       
   914         {
       
   915         iContext.Node().PostToClients<TDefaultClientMatchPolicy>(
       
   916                 iContext.NodeId(),
       
   917                 TCFMessage::TStateChange(
       
   918                     Elements::TStateChange(KDataTransferUnblocked, KErrNone)).CRef(),
       
   919                     TClientType(TCFClientType::ECtrlProvider));
       
   920         }
       
   921     }
       
   922 	
       
   923 DEFINE_SMELEMENT(TFillInGrantedParams, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
   924 void TFillInGrantedParams::DoL()
       
   925     {
       
   926     ASSERT(!iContext.Node().GetParameterBundle().IsNull());
       
   927     RCFParameterFamilyBundleC& bundle = iContext.Node().GetParameterBundle();
       
   928     TBool notifySetFlag=EFalse;
       
   929 
       
   930 	CSubConGenEventParamsGranted* event;
       
   931 	RParameterFamily parFamily;
       
   932 
       
   933     //-=============================================
       
   934     //Qos Params
       
   935     //-=============================================
       
   936     //Fish out the qos family
       
   937     if (MPDPParamMapper::QoSRequested(bundle))
       
   938         {
       
   939         //Quite awkward CSubConnectionParameterBundle API doesn't allow browsing
       
   940         //the extensions. CSubConGenEventParamsGranted does. Hence the
       
   941         //MPDPParamMapper fills in events (and not bundles), as bundles
       
   942         //can be populated from the events and not vice versa.
       
   943         //It's unfortunate, as we're not even raising an event here.
       
   944         //CSubConGenEventParamsGranted & CSubConnectionParameterBundle
       
   945         //would benefit greatly from having a common ancestor.
       
   946 		parFamily = bundle.FindFamily(KSubConQoSFamily);
       
   947 		if( parFamily.IsNull() )
       
   948 			{
       
   949 			// really should have been found!
       
   950 			User::Leave(KErrUnknown);
       
   951 			}
       
   952 		event = CSubConGenEventParamsGranted::NewL();
       
   953         CleanupStack::PushL(event);
       
   954         event->SetFamily (KSubConQoSFamily);
       
   955         FillInEventL(*event); //fill in the params.
       
   956         notifySetFlag = ETrue;
       
   957         }
       
   958 	else if (!(parFamily = iContext.Node().iParameterBundle.FindFamily(KSubConAuthorisationFamily)).IsNull()) // check out sblp session ids granted
       
   959         {  // check out sblp familytype (KSubConAuthorisationFamily==5)         	    	   			
       
   960     			event = CSubConGenEventParamsGranted::NewL();
       
   961     			CleanupStack::PushL(event);
       
   962     			event->SetFamily (KSubConAuthorisationFamily);
       
   963     			FillInEventL(*event); //fill in the params.
       
   964     			notifySetFlag = ETrue;
       
   965         }
       
   966 	else //check out mbms session ids granted
       
   967         {
       
   968         parFamily = iContext.Node().iParameterBundle.FindFamily(KSubConChannelParamsType);
       
   969         STypeId typeId = STypeId::CreateSTypeId(KSubConChannelParamsImplUid, KSubConChannelParamsType);
       
   970 		if (!parFamily.IsNull() && parFamily.FindParameterSet(typeId, RParameterFamily::ERequested))
       
   971 			{
       
   972 			event = CSubConGenEventParamsGranted::NewL();
       
   973 	        CleanupStack::PushL(event);
       
   974 			event->SetFamily (KSubConChannelParamsType);
       
   975 			FillInMbmsSessionIdsL(*event); //Fill Session Ids
       
   976 			notifySetFlag = ETrue;
       
   977 			}
       
   978 		}
       
   979 
       
   980 	if (notifySetFlag)
       
   981 		{
       
   982         parFamily.ClearAllParameters(RParameterFamily::ERequested);
       
   983         parFamily.ClearAllParameters(RParameterFamily::EAcceptable);
       
   984         parFamily.ClearAllParameters(RParameterFamily::EGranted);
       
   985 
       
   986    		//Populate EGranted params from the event.
       
   987    		FillInGrantedL(parFamily, *event);
       
   988 
       
   989    		iContext.Node().NotifyClientsL(*event);
       
   990    		CleanupStack::Pop(event);
       
   991 		}
       
   992 
       
   993 
       
   994     //-=============================================
       
   995     //TFT Params
       
   996     //-=============================================
       
   997 	// Should use KSubConIPAddressInfoFamily in FindFamily as argument instead of EUid
       
   998 	// DEF123513 FindFamily uses EUid as argument raised to fix regressions.
       
   999 	RParameterFamily ipAddressInfoFamily=bundle.FindFamily(CSubConIPAddressInfoParamSet::EUid);
       
  1000     if ( ! ipAddressInfoFamily.IsNull())
       
  1001         {
       
  1002         CSubConIPAddressInfoParamSet* requestedIPAddressInfo = CSubConIPAddressInfoParamSet::NewL(ipAddressInfoFamily, RParameterFamily::ERequested);
       
  1003 		TInt count = requestedIPAddressInfo->GetParamNum();
       
  1004 		if (count > 0)
       
  1005 			{
       
  1006 		CSubConIPAddressInfoParamSet::TSubConIPAddressInfo paramInfo(requestedIPAddressInfo->GetParamInfoL(0));
       
  1007 		TUint id = iContext.Node().FindPacketFilterIdL(paramInfo);
       
  1008 
       
  1009 		switch(paramInfo.iState)
       
  1010 			{
       
  1011 			case CSubConIPAddressInfoParamSet::TSubConIPAddressInfo::EAdd :
       
  1012 					iContext.Node().NewPacketFilterAddedL(paramInfo, id);
       
  1013 					break;
       
  1014 			case CSubConIPAddressInfoParamSet::TSubConIPAddressInfo::ERemove :
       
  1015 					iContext.Node().PacketFilterRemovedL(id);
       
  1016 					break;
       
  1017 			case CSubConIPAddressInfoParamSet::TSubConIPAddressInfo::ENone :
       
  1018 					break;
       
  1019 			default: ;
       
  1020 				/** TODO: What to do with an error */
       
  1021 				}
       
  1022 			}
       
  1023 
       
  1024 		ipAddressInfoFamily.ClearAllParameters(RParameterFamily::ERequested);
       
  1025 
       
  1026         }
       
  1027     //something must have had been granted.
       
  1028     /* [401TODO]: We have a case where applyrequest after rejoin on transfloshim will cause this bit to execute
       
  1029     Since we don't have neither qos nor addrInfo parameters set it will kick this assert*/
       
  1030     }
       
  1031 
       
  1032 void TParamsEvent::FillInEventL(CSubConGenEventParamsGranted& aEvent)
       
  1033     {
       
  1034     RPacketQoS::TQoSR5Negotiated negotiatedQoS;
       
  1035     iContext.Node().iPdpFsmInterface->Get(iContext.Node().iPDPFsmContextId,  negotiatedQoS);
       
  1036     MPDPParamMapper::MapQosEtelToGrantedParamsL(&negotiatedQoS, aEvent, iContext.Node().iParamsRelease);
       
  1037     }
       
  1038 
       
  1039 
       
  1040 void TParamsEvent::FillInMbmsSessionIdsL(CSubConGenEventParamsGranted& aEvent)
       
  1041 	{
       
  1042 
       
  1043 	CSubConChannelParamSet* genericMbms = CSubConChannelParamSet::NewL ();
       
  1044 	aEvent.SetGenericSet(genericMbms);
       
  1045 
       
  1046 	//Fill  List of Session Ids received in Extension Set
       
  1047 	TSessionOperatioInfo sessionInfo;
       
  1048 	User::LeaveIfError(iContext.Node().iPdpFsmInterface->Get(iContext.Node().iPDPFsmContextId, sessionInfo));
       
  1049 	CSubConMBMSExtensionParamSet *mbmsSessionExtn= CSubConMBMSExtensionParamSet::NewL();
       
  1050 	CleanupStack::PushL(mbmsSessionExtn);
       
  1051 	for (TInt i=0;i<sessionInfo.iSessionIds.Count();i++)
       
  1052 		{
       
  1053 		mbmsSessionExtn->SetSessionId(sessionInfo.iSessionIds[i]);
       
  1054 		}
       
  1055 	aEvent.AddExtensionSetL(mbmsSessionExtn);
       
  1056    	sessionInfo.iSessionIds.Close();
       
  1057 	CleanupStack::Pop(mbmsSessionExtn);
       
  1058 	}
       
  1059 
       
  1060 void TParamsEvent::FillInGrantedL(RParameterFamily& aFamily, const CSubConGenEventParamsGranted& aEvent)
       
  1061     {
       
  1062     //Unfortunatelly no easy way to copy a content of an event into
       
  1063     //a bundle family. Using ECOM Load/Store to do that.
       
  1064     //Unfortunatelly CSubConGenEventParamsGranted::GetNumExtensionSets is a non-const
       
  1065     //method.
       
  1066     CSubConGenEventParamsGranted& noncEvent = const_cast<CSubConGenEventParamsGranted&>(aEvent);
       
  1067 
       
  1068     //clear granted params in the bundle
       
  1069     aFamily.ClearAllParameters(RParameterFamily::EGranted);
       
  1070     ASSERT(aEvent.GetGenericSet());
       
  1071     const CSubConParameterSet* genSetSource = aEvent.GetGenericSet();
       
  1072 
       
  1073     TInt i = 0;
       
  1074 
       
  1075     //dry run - find out the max length for the buffer.
       
  1076     TInt bufLen = genSetSource->Length();
       
  1077     for (i = 0; i < noncEvent.GetNumExtensionSets(); i++)
       
  1078         {
       
  1079         TInt extLen = aEvent.GetExtensionSet(i)->Length();
       
  1080         bufLen = extLen > bufLen ? extLen : bufLen;
       
  1081         }
       
  1082 
       
  1083 
       
  1084 	RBuf8 buffer;
       
  1085 	buffer.CreateL(bufLen);
       
  1086 	buffer.CleanupClosePushL();
       
  1087 
       
  1088 	genSetSource->Store(buffer);
       
  1089     TPtrC8 whyDoWeNeedPointerToRbufHere(buffer);
       
  1090 	CSubConGenericParameterSet* genSetTarget = static_cast<CSubConGenericParameterSet*>(
       
  1091 	                    CSubConGenericParameterSet::LoadL(whyDoWeNeedPointerToRbufHere));
       
  1092 	CleanupStack::PushL(genSetTarget);
       
  1093     aFamily.AddParameterSetL(genSetTarget, RParameterFamily::EGranted);
       
  1094     CleanupStack::Pop(genSetTarget);
       
  1095 
       
  1096     //loop thru the extensions
       
  1097     for (i = 0; i < noncEvent.GetNumExtensionSets(); i++)
       
  1098         {
       
  1099         const CSubConExtensionParameterSet* extSetSource = aEvent.GetExtensionSet(i);
       
  1100         buffer.Zero();
       
  1101         extSetSource->Store(buffer);
       
  1102         whyDoWeNeedPointerToRbufHere.Set(buffer);
       
  1103         CSubConExtensionParameterSet* extSetTarget = static_cast<CSubConExtensionParameterSet*>(CSubConParameterSet::LoadL(whyDoWeNeedPointerToRbufHere));
       
  1104         CleanupStack::PushL(extSetTarget);
       
  1105         aFamily.AddParameterSetL(extSetTarget, RParameterFamily::EGranted);
       
  1106         CleanupStack::Pop(extSetTarget);
       
  1107         }
       
  1108     CleanupStack::PopAndDestroy(&buffer);
       
  1109     }
       
  1110 
       
  1111 
       
  1112 DEFINE_SMELEMENT(TRaiseParamsRejectedL, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
  1113 void TRaiseParamsRejectedL::DoL()
       
  1114     {
       
  1115     ASSERT(iContext.iNodeActivity && iContext.iNodeActivity->Error() != KErrNone);
       
  1116     CSubConGenEventParamsRejected* event= CSubConGenEventParamsRejected::NewL();
       
  1117     CleanupStack::PushL(event);
       
  1118 
       
  1119 	if (iContext.Node().iContextType == SpudMan::EMbms)
       
  1120 		{
       
  1121 		TPDPFSMMessages::TPDPFSMMessage& message = message_cast<TPDPFSMMessages::TPDPFSMMessage>(iContext.iMessage);
       
  1122 		TInt prevOperationValue = message.iValue2;
       
  1123 		if ((prevOperationValue == KErrNotFound) || (prevOperationValue == KErrNotSupported ) ||
       
  1124 			 (prevOperationValue == KErrMbmsImpreciseServiceEntries ) ||(prevOperationValue == KErrMbmsServicePreempted) )
       
  1125 			{
       
  1126     		event->SetFamilyId (KSubConChannelParamsType);
       
  1127 			}
       
  1128 		}
       
  1129 	else
       
  1130 		{
       
  1131 		event->SetFamilyId (KSubConQoSFamily);
       
  1132 		}
       
  1133     event->SetError(iContext.iNodeActivity->Error());
       
  1134     iContext.Node().NotifyClientsL(*event);
       
  1135     CleanupStack::Pop(event);
       
  1136 
       
  1137 	TInt err = iContext.iNodeActivity->Error();
       
  1138 	iContext.iNodeActivity->SetError(KErrNone);
       
  1139 	User::Leave(err);
       
  1140 	}
       
  1141 
       
  1142 DEFINE_SMELEMENT(TRaiseParamsChanged, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
  1143 void TRaiseParamsChanged::DoL()
       
  1144     {
       
  1145     TPDPFSMMessages::TPDPFSMMessage& message = message_cast<TPDPFSMMessages::TPDPFSMMessage>(iContext.iMessage);
       
  1146 	TInt err=KErrNone;
       
  1147     ASSERT(message.iValue2 == KErrNone);
       
  1148     CSubConGenEventParamsChanged* event = NULL;
       
  1149     TRAP_IGNORE(event = CSubConGenEventParamsChanged::NewL());
       
  1150     if (event)
       
  1151        	{
       
  1152        	RParameterFamily parFamily = iContext.Node().iParameterBundle.FindFamily(KSubConChannelParamsType);
       
  1153     	if (!parFamily.IsNull()) //check the changed mbms session ids
       
  1154 			{
       
  1155 			STypeId typeId = STypeId::CreateSTypeId(KSubConChannelParamsImplUid, KSubConChannelParamsType);
       
  1156 			CSubConChannelParamSet* mbmsSubConParamSet = parFamily.IsNull() ? NULL :
       
  1157     			static_cast<CSubConChannelParamSet *>(parFamily.FindParameterSet(typeId, RParameterFamily::ERequested));
       
  1158 			if (mbmsSubConParamSet)
       
  1159 				{
       
  1160 				event->SetFamily (KSubConChannelParamsType);
       
  1161         		event->SetError(message.iValue2);
       
  1162 				TRAP(err,FillInMbmsSessionIdsL(*event)); //Fill Session Ids
       
  1163 				}
       
  1164 			}
       
  1165 		else
       
  1166 			{
       
  1167 			parFamily = iContext.Node().iParameterBundle.FindFamily(KSubConQoSFamily);
       
  1168 			event->SetFamily (KSubConQoSFamily);
       
  1169         	event->SetError(message.iValue2);
       
  1170         	TRAP(err, FillInEventL(*event));
       
  1171 			}
       
  1172 		if (err == KErrNone)
       
  1173           	{
       
  1174 			FillInGrantedL(parFamily, *event);
       
  1175             iContext.Node().NotifyClientsL(*event);
       
  1176 			}
       
  1177        	}
       
  1178    	else
       
  1179         {
       
  1180         delete event;
       
  1181         }
       
  1182     }
       
  1183 
       
  1184 
       
  1185 DEFINE_SMELEMENT(TAwaitingNetworkStatusEvent, NetStateMachine::MState, PDPSCprStates::TContext)
       
  1186 TBool TAwaitingNetworkStatusEvent::Accept()
       
  1187     {
       
  1188     return TAwaitingPDPFSMMessage::Accept(KNetworkStatusEvent);
       
  1189     }
       
  1190 
       
  1191 DEFINE_SMELEMENT(TNetworkStatusEventTypeTag, NetStateMachine::MStateFork, PDPSCprStates::TContext)
       
  1192 TInt TNetworkStatusEventTypeTag::TransitionTag()
       
  1193     {
       
  1194 	RPacketService::TStatus status;
       
  1195 	iContext.Node().iPdpFsmInterface->Get(status);
       
  1196     switch (status)
       
  1197         {
       
  1198         case RPacketService::EStatusUnattached:
       
  1199             // If status change is to unattached, but stop has been requested,
       
  1200             // or we haven't been started, do nothing
       
  1201             if (iContext.Node().CountActivities(ECFActivityStopDataClient) > 0
       
  1202                || iContext.Node().CountClients<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData, TCFClientType::EStarted)) == 0)
       
  1203                 {
       
  1204                 return KNoTag;
       
  1205                 }
       
  1206 			return status;	
       
  1207         case RPacketService::EStatusAttached:
       
  1208         case RPacketService::EStatusActive:
       
  1209         case RPacketService::EStatusSuspended:
       
  1210         	return status;
       
  1211         }
       
  1212     return KNoTag;
       
  1213     }
       
  1214 
       
  1215 DEFINE_SMELEMENT(TSendGoneDown, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
  1216 void TSendGoneDown::DoL()
       
  1217     {
       
  1218     ASSERT(iContext.iNodeActivity);
       
  1219 
       
  1220     const TProviderInfo& providerInfo = static_cast<const TProviderInfoExt&>(iContext.Node().AccessPointConfig().FindExtensionL(
       
  1221             STypeId::CreateSTypeId(TProviderInfoExt::EUid, TProviderInfoExt::ETypeId))).iProviderInfo; 
       
  1222 	iContext.Node().PostToClients<TDefaultClientMatchPolicy>(
       
  1223 	iContext.NodeId(),
       
  1224 	TCFControlClient::TGoneDown(KErrDisconnected,providerInfo.APId()).CRef(),
       
  1225 		TClientType(TCFClientType::ECtrl));
       
  1226 
       
  1227 	iContext.Node().ControlProvider()->PostMessage(
       
  1228  	        iContext.NodeId(),
       
  1229  	        TCFControlProvider::TDataClientGoneDown(KErrDisconnected,providerInfo.APId()).CRef());
       
  1230 
       
  1231     }
       
  1232 
       
  1233 
       
  1234 //-=========================================================
       
  1235 //Destroying context
       
  1236 //-=========================================================
       
  1237 DEFINE_SMELEMENT(TDestroyPDPContext, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
  1238 void TDestroyPDPContext::DoL()
       
  1239     {
       
  1240     ASSERT(iContext.Node().iPdpFsmInterface);
       
  1241     if (iContext.Node().iPDPFsmContextId == KPrimaryContextId)
       
  1242         {
       
  1243         iContext.Node().PostToClients<TDefaultClientMatchPolicy>(
       
  1244                 iContext.NodeId(),
       
  1245                 TCFMessage::TStateChange(
       
  1246                         Elements::TStateChange(KPsdStartingDeactivation, KErrNone)).CRef(),
       
  1247                         TClientType(TCFClientType::ECtrlProvider));
       
  1248         }
       
  1249 
       
  1250     iContext.Node().iPdpFsmInterface->Input(iContext.Node().iPDPFsmContextId, SpudMan::EContextDelete);
       
  1251 
       
  1252     //Expect Response
       
  1253     iContext.iNodeActivity->ClearPostedTo();
       
  1254     iContext.Node().iActivityAwaitingResponse = iContext.iNodeActivity->ActivityId();
       
  1255     }
       
  1256 
       
  1257 DEFINE_SMELEMENT(TAwaitingPDPContextDestroyed, NetStateMachine::MState, PDPSCprStates::TContext)
       
  1258 TBool TAwaitingPDPContextDestroyed::Accept()
       
  1259     {
       
  1260     if (TAwaitingPDPFSMMessage::Accept(KContextDeleteEvent))
       
  1261         {
       
  1262         if (iContext.Node().iPDPFsmContextId != CPDPSubConnectionProvider::EInvalidContextId)
       
  1263             {
       
  1264 			if (!iContext.Node().ContentionRequested())
       
  1265 				{
       
  1266 				CSubConGenEventSubConDown* event = CSubConGenEventSubConDown::NewL();
       
  1267 				CleanupStack::PushL(event);
       
  1268 				iContext.Node().NotifyClientsL(*event);
       
  1269 				CleanupStack::Pop(event);
       
  1270 				}
       
  1271 
       
  1272 			if (iContext.Node().iPDPFsmContextId == KPrimaryContextId)
       
  1273                 {
       
  1274                 iContext.Node().PostToClients<TDefaultClientMatchPolicy>(
       
  1275                         iContext.NodeId(),
       
  1276                         TCFMessage::TStateChange(
       
  1277                                 Elements::TStateChange(KPsdFinishedDeactivation, KErrNone)).CRef(),
       
  1278                                 TClientType(TCFClientType::ECtrlProvider));
       
  1279                 }
       
  1280 
       
  1281             iContext.Node().iPdpFsmInterface->DeleteFsmContext(iContext.Node().iPDPFsmContextId);
       
  1282             iContext.Node().iPDPFsmContextId = CPDPSubConnectionProvider::EInvalidContextId;            
       
  1283             }
       
  1284         return ETrue;
       
  1285         }
       
  1286     return EFalse;
       
  1287     }
       
  1288 
       
  1289 DEFINE_SMELEMENT(TAwaitingPDPContextGoneDown, NetStateMachine::MState, PDPSCprStates::TContext)
       
  1290 TBool TAwaitingPDPContextGoneDown::Accept()
       
  1291     {
       
  1292     if (TAwaitingPDPContextDestroyed::Accept())
       
  1293         {
       
  1294 		if (!iContext.Node().ContentionRequested())
       
  1295 			{
       
  1296 			//Following SPUD, we're ignoring the error raised by the FSM and override it with KErrDisconnected
       
  1297 			iContext.Node().LinkDown(KErrDisconnected);
       
  1298 			}
       
  1299         return ETrue;
       
  1300         }
       
  1301     return EFalse;
       
  1302     }
       
  1303 
       
  1304 
       
  1305 DEFINE_SMELEMENT(TNoTagOrProviderStopped, NetStateMachine::MStateFork, PDPSCprStates::TContext)
       
  1306 TInt TNoTagOrProviderStopped::TransitionTag()
       
  1307     {
       
  1308     if (iContext.Node().iPDPFsmContextId != CPDPSubConnectionProvider::EInvalidContextId &&
       
  1309         iContext.Node().iPdpFsmInterface->FsmContextExists(iContext.Node().iPDPFsmContextId))
       
  1310         {
       
  1311         //context is alive
       
  1312         return KNoTag;
       
  1313         }
       
  1314     return CoreNetStates::KProviderStopped;
       
  1315     }
       
  1316 
       
  1317 
       
  1318 
       
  1319 //===========================================================
       
  1320 //   Sip Address retrieval
       
  1321 //===========================================================
       
  1322 DEFINE_SMELEMENT(TAwaitingIoctlMessage, NetStateMachine::MState, PDPSCprStates::TContext)
       
  1323 TBool TAwaitingIoctlMessage::Accept()
       
  1324 	{
       
  1325 	if (iContext.iMessage.IsTypeOf(Meta::STypeId::CreateSTypeId(TCFSigLegacyRMessage2Ext::EUid, TCFSigLegacyRMessage2Ext::ETypeId)))
       
  1326 		{
       
  1327 		TCFSigLegacyRMessage2Ext& msg = static_cast<TCFSigLegacyRMessage2Ext&>(iContext.iMessage);
       
  1328 		if (msg.iMessage.Function() == ECNIoctl)
       
  1329 			{
       
  1330 			return ETrue;
       
  1331 			}
       
  1332 		}
       
  1333 	return EFalse;
       
  1334 	}
       
  1335 
       
  1336 DEFINE_SMELEMENT(TRetrieveSipAddr, NetStateMachine::MStateTransition, PDPSCprStates::TDefContext)
       
  1337 void TRetrieveSipAddr::DoL()
       
  1338 	{
       
  1339 	MeshMachine::CNodeParallelMessageStoreActivityBase* act = static_cast<MeshMachine::CNodeParallelMessageStoreActivityBase*>(iContext.Activity());
       
  1340 
       
  1341 	ASSERT(act->Message().IsTypeOf(Meta::STypeId::CreateSTypeId(TCFSigLegacyRMessage2Ext::EUid, TCFSigLegacyRMessage2Ext::ETypeId)));
       
  1342 	RLegacyResponseMsg ioctl(iContext, static_cast<TCFSigLegacyRMessage2Ext&>(act->Message()).iMessage, static_cast<TCFSigLegacyRMessage2Ext&>(act->Message()).iMessage.Int0());
       
  1343 	
       
  1344 	TInt err = KErrNotFound;
       
  1345 
       
  1346 	if (iContext.Node().iIsModeGsm)
       
  1347 		{
       
  1348 		err = KErrNotSupported;
       
  1349 		}
       
  1350 	else
       
  1351 		{
       
  1352 		CGPRSProvision* gprsProvision = const_cast<CGPRSProvision*>(
       
  1353 			static_cast<const CGPRSProvision*>(iContext.Node().AccessPointConfig().FindExtension(
       
  1354 												   STypeId::CreateSTypeId(CGPRSProvision::EUid,CGPRSProvision::ETypeId))));
       
  1355 
       
  1356 		RPacketContext::TProtocolConfigOptionV2* protConfigOpt = NULL;
       
  1357 		
       
  1358 		if(gprsProvision != NULL)
       
  1359 		   {
       
  1360 		   switch (gprsProvision->UmtsGprsRelease())
       
  1361 		   	  {
       
  1362 	    	  case TPacketDataConfigBase::KConfigGPRS:
       
  1363 			     {
       
  1364 				 protConfigOpt = &(gprsProvision->GetScratchContextAs<RPacketContext::TContextConfigGPRS>().iProtocolConfigOption);
       
  1365 				 }
       
  1366 			  break;
       
  1367 			  
       
  1368 	    	  case TPacketDataConfigBase::KConfigRel5:
       
  1369 			  case TPacketDataConfigBase::KConfigRel99Rel4:
       
  1370 			     {
       
  1371 				 protConfigOpt = &(gprsProvision->GetScratchContextAs<RPacketContext::TContextConfigR99_R4>().iProtocolConfigOption);
       
  1372 				 }
       
  1373 			  break;
       
  1374 			  }
       
  1375 		   }
       
  1376 		
       
  1377 		if(protConfigOpt != NULL)
       
  1378 			{
       
  1379 			if (protConfigOpt->iMiscBuffer.Length() > 0)
       
  1380 				{
       
  1381 				TSipServerAddrBuf sipbuf;
       
  1382 				ioctl.ReadL(2, sipbuf);
       
  1383 
       
  1384 				TPtr8 pcoPtr(const_cast<TUint8*>(protConfigOpt->iMiscBuffer.Ptr()),
       
  1385 						protConfigOpt->iMiscBuffer.Length(),
       
  1386 						protConfigOpt->iMiscBuffer.MaxLength());
       
  1387 				TTlvStruct<RPacketContext::TPcoId,RPacketContext::TPcoItemDataLength> tlv(pcoPtr,0);
       
  1388 				tlv.ResetCursorPos();
       
  1389 
       
  1390 				TIp6Addr addr;
       
  1391 				TPtr8 addrPtr(NULL, 0);
       
  1392 				TPckg<TIp6Addr> addrPckg(addr);
       
  1393 
       
  1394 				for (TInt i = 0; tlv.NextItemL(RPacketContext::EEtelPcktPCSCFAddress,addrPtr) == KErrNone; i++)
       
  1395 					{
       
  1396 					if (i == sipbuf().index)
       
  1397 						{
       
  1398 						addrPckg.Copy(addrPtr);
       
  1399 						sipbuf().address.SetAddress(addr);
       
  1400 						if (!sipbuf().address.IsUnspecified())
       
  1401 							err = KErrNone;
       
  1402 						break;
       
  1403 						}
       
  1404 					}
       
  1405 
       
  1406 				ioctl.WriteL(2, sipbuf);
       
  1407 				}
       
  1408 			else
       
  1409 				{
       
  1410 				err = KErrNotFound;
       
  1411 				}
       
  1412 			}
       
  1413 		}
       
  1414 
       
  1415 	ioctl.Complete(err);
       
  1416 	}
       
  1417 
       
  1418 
       
  1419 //===========================================================
       
  1420 // Rejoin
       
  1421 //===========================================================
       
  1422 
       
  1423 MeshMachine::CNodeActivityBase* CPrimaryPDPGoneDownActivity::NewL(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
       
  1424     {
       
  1425     return new (ELeave) CPrimaryPDPGoneDownActivity(aActivitySig, aNode);
       
  1426     }
       
  1427 
       
  1428 CPrimaryPDPGoneDownActivity::~CPrimaryPDPGoneDownActivity()
       
  1429     {
       
  1430     }
       
  1431 
       
  1432 CPDPSubConnectionProvider* CPrimaryPDPGoneDownActivity::NewDefault()
       
  1433     {
       
  1434     if (iNewDefault == NULL)
       
  1435         {
       
  1436     	THighestQoSQuery query(static_cast<CPDPSubConnectionProvider&>(iNode).ControlProvider()->RecipientId());
       
  1437     	static_cast<CSubConnectionProviderFactoryBase&>(static_cast<CPDPSubConnectionProvider&>(iNode).Factory()).Find(query);
       
  1438     	iNewDefault = query.HighestQoSProvider();
       
  1439         }
       
  1440     return iNewDefault;
       
  1441     }
       
  1442 
       
  1443 CPrimaryPDPGoneDownActivity::CPrimaryPDPGoneDownActivity(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode )
       
  1444 :MeshMachine::CNodeActivityBase(aActivitySig, aNode)
       
  1445     {
       
  1446 	iOriginalDataClient.SetNull();
       
  1447     }
       
  1448 
       
  1449 
       
  1450 DEFINE_SMELEMENT( CPrimaryPDPGoneDownActivity::TApplyNewDefault, NetStateMachine::MStateTransition, CPrimaryPDPGoneDownActivity::TContext)
       
  1451 void CPrimaryPDPGoneDownActivity::TApplyNewDefault::DoL()
       
  1452 	{
       
  1453     ASSERT(iContext.iNodeActivity);
       
  1454 	CPrimaryPDPGoneDownActivity* primaryGoneDownActivity = static_cast<CPrimaryPDPGoneDownActivity*>(iContext.iNodeActivity);
       
  1455 
       
  1456     RClientInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), primaryGoneDownActivity->NewDefault()->Id(),
       
  1457     	TCFScpr::TApplyRequest().CRef());
       
  1458 	}
       
  1459 
       
  1460 DEFINE_SMELEMENT( CPrimaryPDPGoneDownActivity::TStoreOriginalDataClient, NetStateMachine::MStateTransition, CPrimaryPDPGoneDownActivity::TContext)
       
  1461 void CPrimaryPDPGoneDownActivity::TStoreOriginalDataClient::DoL()
       
  1462 	{
       
  1463 	ASSERT(iContext.iNodeActivity);
       
  1464 	CPrimaryPDPGoneDownActivity* act = static_cast<CPrimaryPDPGoneDownActivity*>(iContext.iNodeActivity);
       
  1465 	act->iOriginalDataClient
       
  1466 		= iContext.Node().GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData))->RecipientId();
       
  1467 	}
       
  1468 
       
  1469 DEFINE_SMELEMENT( CPrimaryPDPGoneDownActivity::TStopOriginalDataClient, NetStateMachine::MStateTransition, CPrimaryPDPGoneDownActivity::TContext)
       
  1470 void CPrimaryPDPGoneDownActivity::TStopOriginalDataClient::DoL()
       
  1471 	{
       
  1472 	ASSERT(iContext.iNodeActivity);
       
  1473 	CPrimaryPDPGoneDownActivity* act = static_cast<CPrimaryPDPGoneDownActivity*>(iContext.iNodeActivity);
       
  1474 	ASSERT(!act->iOriginalDataClient.IsNull());
       
  1475 
       
  1476 	iContext.iNodeActivity->PostRequestTo(act->iOriginalDataClient,
       
  1477 		TCFDataClient::TStop(KErrCancel).CRef());
       
  1478 	}
       
  1479 
       
  1480 
       
  1481 DEFINE_SMELEMENT( CPrimaryPDPGoneDownActivity::TSwitchToNewDefault, NetStateMachine::MStateTransition, CPrimaryPDPGoneDownActivity::TContext)
       
  1482 void CPrimaryPDPGoneDownActivity::TSwitchToNewDefault::DoL()
       
  1483 	{
       
  1484   	ASSERT(&iContext.Node() == iContext.Node().iDefaultSCPR); //only to be excecuted by the current default
       
  1485 	ASSERT(iContext.iNodeActivity);
       
  1486 	CPrimaryPDPGoneDownActivity* primaryGoneDownActivity = static_cast<CPrimaryPDPGoneDownActivity*>(iContext.iNodeActivity);
       
  1487 	CPDPSubConnectionProvider* newDefault = primaryGoneDownActivity->NewDefault();
       
  1488 	ASSERT( newDefault && newDefault != &iContext.Node());
       
  1489     newDefault->RemoveClient(iContext.NodeId());
       
  1490 
       
  1491 	//switch the context owner - the current owner will go down.
       
  1492 	iContext.Node().iPDPFsmContextId = newDefault->iPDPFsmContextId;
       
  1493 	newDefault->iPDPFsmContextId = CPDPSubConnectionProvider::EInvalidContextId;
       
  1494 	iContext.Node().iPdpFsmInterface->Set(iContext.Node().iPDPFsmContextId, iContext.Node());
       
  1495 	}
       
  1496 
       
  1497 DEFINE_SMELEMENT( CPrimaryPDPGoneDownActivity::TRejoinDataClient, NetStateMachine::MStateTransition, CPrimaryPDPGoneDownActivity::TContext)
       
  1498 void CPrimaryPDPGoneDownActivity::TRejoinDataClient::DoL()
       
  1499 	{
       
  1500   	ASSERT(&iContext.Node() == iContext.Node().iDefaultSCPR); //only to be excecuted by the current default
       
  1501 	ASSERT(iContext.iNodeActivity);
       
  1502 	CPrimaryPDPGoneDownActivity* primaryGoneDownActivity = static_cast<CPrimaryPDPGoneDownActivity*>(iContext.iNodeActivity);
       
  1503 	CPDPSubConnectionProvider* newDefault = primaryGoneDownActivity->NewDefault();
       
  1504 	ASSERT( newDefault && newDefault != &iContext.Node());
       
  1505 	if(!newDefault)
       
  1506 	{
       
  1507 		User::Leave(KErrNotFound);
       
  1508 	}
       
  1509 	newDefault->AddClientL(iContext.NodeId(), TClientType(TCFClientType::ECtrl));
       
  1510 
       
  1511 	//migrate the flow - will need TApply
       
  1512     TCFRejoiningProvider::TRejoinDataClientRequest msg(newDefault->GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData))->RecipientId(), iContext.NodeId());
       
  1513     RClientInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), newDefault->Id(), msg);
       
  1514 	}
       
  1515 
       
  1516 
       
  1517 DEFINE_SMELEMENT( CPrimaryPDPGoneDownActivity::TNoTagOrProviderStopped, NetStateMachine::MStateFork, CPrimaryPDPGoneDownActivity::TContext)
       
  1518 TInt CPrimaryPDPGoneDownActivity::TNoTagOrProviderStopped::TransitionTag()
       
  1519 	{
       
  1520 	ASSERT(iContext.iNodeActivity);
       
  1521 	CPrimaryPDPGoneDownActivity* primaryGoneDownActivity = static_cast<CPrimaryPDPGoneDownActivity*>(iContext.iNodeActivity);
       
  1522 	if (primaryGoneDownActivity->NewDefault())
       
  1523     	{
       
  1524     	return KNoTag;
       
  1525     	}
       
  1526     return CoreNetStates::KProviderStopped;
       
  1527 	}
       
  1528 
       
  1529 DEFINE_SMELEMENT(TFillInImsExtParams, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
  1530 void TFillInImsExtParams::DoL()
       
  1531 	{
       
  1532 	CGPRSProvision* gprsProvision = const_cast<CGPRSProvision*>(
       
  1533 			static_cast<const CGPRSProvision*>(iContext.Node().AccessPointConfig().FindExtension(
       
  1534 					STypeId::CreateSTypeId(CGPRSProvision::EUid,CGPRSProvision::ETypeId))));
       
  1535 	ASSERT(gprsProvision);
       
  1536 
       
  1537 	iContext.Node().iPdpFsmInterface->Get(KPrimaryContextId, gprsProvision->GetScratchContextAs<TPacketDataConfigBase>());
       
  1538 	// the bundle is assumed to be valid, since its created in createPdpContext
       
  1539 	//RParameterFamily imcnFamily = iContext.Node().GetOrCreateParameterBundleL().CreateFamilyL(KSubConnContextDescrParamsFamily); //PJLEFT
       
  1540 
       
  1541 	RCFParameterFamilyBundle newBundle;
       
  1542 	newBundle.CreateL();
       
  1543 	newBundle.Open(iContext.Node().iParameterBundle);
       
  1544 	RParameterFamily imcnFamily = newBundle.CreateFamilyL(KSubConnContextDescrParamsFamily);
       
  1545 
       
  1546 	CSubConImsExtParamSet *imcnFlag = CSubConImsExtParamSet::NewL(imcnFamily,RParameterFamily::EGranted);
       
  1547 	newBundle.Close();
       
  1548 
       
  1549 	RPacketContext::TProtocolConfigOptionV2* pco = NULL;
       
  1550 	switch (gprsProvision->UmtsGprsRelease())
       
  1551 		{
       
  1552     		case TPacketDataConfigBase::KConfigGPRS:
       
  1553 			{
       
  1554 			pco = &(gprsProvision->GetScratchContextAs<RPacketContext::TContextConfigGPRS>().iProtocolConfigOption);
       
  1555 			}
       
  1556 			break;
       
  1557 	    	case TPacketDataConfigBase::KConfigRel5:
       
  1558 	    	case TPacketDataConfigBase::KConfigRel99Rel4:
       
  1559 			{
       
  1560 			pco = &(gprsProvision->GetScratchContextAs<RPacketContext::TContextConfigR99_R4>().iProtocolConfigOption);
       
  1561 			}
       
  1562 			break;
       
  1563 		}
       
  1564 
       
  1565 	if(pco)
       
  1566 		{
       
  1567 		TPtr8 pcoPtr(const_cast<TUint8*>(pco->iMiscBuffer.Ptr()),pco->iMiscBuffer.Length(),pco->iMiscBuffer.MaxLength());
       
  1568 		TTlvStruct<RPacketContext::TPcoId,RPacketContext::TPcoItemDataLength> tlv(pcoPtr,0);
       
  1569 		tlv.ResetCursorPos();
       
  1570 
       
  1571 		TPtr8 imsFlagPtr(NULL, 0);
       
  1572 		TInt err = tlv.NextItemL(RPacketContext::EEtelPcktIMCNNetworkSubsystemSignallingFlag, imsFlagPtr);
       
  1573 		imcnFlag->SetImsSignallingIndicator(err == KErrNone);
       
  1574 		}
       
  1575 
       
  1576 	}
       
  1577 
       
  1578 //===========================================================
       
  1579 // Cancel Start or Stop
       
  1580 //===========================================================
       
  1581 
       
  1582 DEFINE_SMELEMENT(TAwaitingDataClientStopOrCancel, NetStateMachine::MState, TContext)
       
  1583 TBool TAwaitingDataClientStopOrCancel::Accept()
       
  1584     {
       
  1585     CNodeActivityBase* startActivity = iContext.Node().FindActivityById(ECFActivityStartDataClient);
       
  1586     if (startActivity)
       
  1587         {
       
  1588         //cancel start
       
  1589         startActivity->Cancel(iContext);
       
  1590         return EFalse;
       
  1591         }
       
  1592 
       
  1593     CoreNetStates::TAwaitingDataClientStop state(iContext);
       
  1594     return state.Accept();
       
  1595     }
       
  1596 
       
  1597 DEFINE_SMELEMENT(TCancelDataClientStartInPDP, NetStateMachine::MStateTransition, PDPSCprStates::TContext)
       
  1598 void TCancelDataClientStartInPDP::DoL()
       
  1599     {
       
  1600     CNodeActivityBase* startActivity = iContext.Node().FindActivityById(ECFActivityStartDataClient);
       
  1601     if (startActivity)
       
  1602         {
       
  1603         //cancel start with KErrDisconnected
       
  1604         startActivity->SetError(KErrDisconnected);
       
  1605         startActivity->Cancel(iContext);
       
  1606         }
       
  1607     else
       
  1608         {
       
  1609         RClientInterface::OpenPostMessageClose(TNodeCtxId(ECFActivityStart, iContext.NodeId()), iContext.NodeId(), TEBase::TCancel().CRef());
       
  1610         }
       
  1611     }
       
  1612 
       
  1613 } //namespace end