networkcontrol/iptransportlayer/src/ipscpr.cpp
changeset 0 af10295192d8
child 19 3652a10b304a
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     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 // IP SubConnection Provider implementation
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include "ipscpr.h"
       
    24 #include "ipdeftbasescpr.h"
       
    25 #include "ipscprlog.h"
       
    26 #include "ipscprstates.h"
       
    27 #include <comms-infras/ss_log.h>
       
    28 #include "IPMessages.h"
       
    29 
       
    30 #include <comms-infras/ss_msgintercept.h>
       
    31 #include <elements/nm_signatures.h>
       
    32 #include <comms-infras/ss_nodemessages_factory.h>
       
    33 
       
    34 #if defined __FLOG_ACTIVE || defined SYMBIAN_TRACE_ENABLE
       
    35 	#define KIPSCprTag KESockSubConnectionTag
       
    36 	//_LIT8(KIPSCprSubTag, "ipscpr");
       
    37 #endif
       
    38 
       
    39 using namespace MeshMachine;
       
    40 using namespace Messages;
       
    41 using namespace ESock;
       
    42 using namespace NetStateMachine;
       
    43 
       
    44 //We reserve space for two preallocated activities that may start concurrently on the SCPR
       
    45 //node: destroy and data client stop.
       
    46 static const TUint KDefaultMaxPreallocatedActivityCount = 2;
       
    47 static const TUint KMaxPreallocatedActivitySize = sizeof(MeshMachine::CNodeRetryParallelActivity) + sizeof(MeshMachine::APreallocatedOriginators<4>);
       
    48 static const TUint KIPSCPRPreallocatedActivityBufferSize = KDefaultMaxPreallocatedActivityCount * KMaxPreallocatedActivitySize;
       
    49 
       
    50 namespace IPSCprAddressUpdate
       
    51 {
       
    52 DECLARE_DEFINE_NODEACTIVITY(IPDeftSCprBaseActivities::ECFActivityAddressUpdate, IPSCprAddressUpdate, TCFIPMessage::TDataClientRouted)
       
    53 	NODEACTIVITY_ENTRY(KNoTag, IPBaseSCprStates::TStoreAddressUpdate, IPBaseSCprStates::TAwaitingAddressUpdate, IpSCprStates::TNoTagOrDoNothingTag)
       
    54 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, IpSCprStates::TCreateAddressInfoBundle, MeshMachine::TNoTag)
       
    55 	NODEACTIVITY_ENTRY(KNoTag, IpSCprStates::TSendSelfStart, CoreNetStates::TAwaitingStarted, IpSCprStates::TDoNothingTag)
       
    56 	LAST_NODEACTIVITY_ENTRY(IpSCprStates::KDoNothingTag, MeshMachine::TDoNothing)
       
    57 NODEACTIVITY_END()
       
    58 }
       
    59 
       
    60 #ifndef SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
    61 namespace IPSCprParamsRequest
       
    62 {
       
    63 DECLARE_DEFINE_NODEACTIVITY(ECFActivityParamRequest, IPSCprSetParams, TCFScpr::TParamsRequest)
       
    64 	FIRST_NODEACTIVITY_ENTRY(SCprStates::TAwaitingParamRequest, CoreNetStates::TNoTagOrBearerPresent)
       
    65 	NODEACTIVITY_ENTRY(CoreNetStates::KBearerPresent, SCprStates::TPassToServiceProvider, CoreNetStates::TAwaitingParamResponse, CoreNetStates::TBearerPresent)
       
    66 	LAST_NODEACTIVITY_ENTRY(CoreNetStates::KBearerPresent, SCprStates::TStoreParamsAndPostToOriginators)
       
    67 	LAST_NODEACTIVITY_ENTRY(KNoTag, SCprStates::TStoreAndRespondWithCurrentParams)
       
    68 NODEACTIVITY_END()
       
    69 }
       
    70 #endif // SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
    71 
       
    72 namespace IPSCprApplyRequest
       
    73 {
       
    74 DECLARE_DEFINE_NODEACTIVITY(ECFActivityApplyChanges, IpSCprApplyReq, TCFScpr::TApplyRequest)
       
    75 #ifdef SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
    76 	FIRST_NODEACTIVITY_ENTRY(PRStates::TAwaitingApplyRequest, IpSCprStates::TNoTagOrSendApplyResponseOrErrorTag)
       
    77 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, IpSCprStates::TCreateAddressInfoBundleFromJoiningClient, MeshMachine::TNoTag)
       
    78 	NODEACTIVITY_ENTRY(KNoTag, IpSCprStates::TSendSelfStart, CoreNetStates::TAwaitingStarted, MeshMachine::TNoTag)
       
    79 	LAST_NODEACTIVITY_ENTRY(KNoTag, PRStates::TSendApplyResponse)
       
    80 	LAST_NODEACTIVITY_ENTRY(SCprActivities::Apply::ESendApplyResponse, PRStates::TSendApplyResponse)
       
    81 #else
       
    82 	FIRST_NODEACTIVITY_ENTRY(SCprStates::TAwaitingApplyRequest, IpSCprStates::TNoTagOrSendApplyResponseOrErrorTag)
       
    83 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, IpSCprStates::TCreateAddressInfoBundleFromJoiningClient, MeshMachine::TNoTag)
       
    84 	NODEACTIVITY_ENTRY(KNoTag, IpSCprStates::TSendSelfStart, CoreNetStates::TAwaitingStarted, MeshMachine::TNoTag)
       
    85 	LAST_NODEACTIVITY_ENTRY(KNoTag, SCprStates::TSendApplyResponse)
       
    86 	LAST_NODEACTIVITY_ENTRY(SCprActivities::Apply::ESendApplyResponse, SCprStates::TSendApplyResponse)
       
    87 #endif // SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
    88 	LAST_NODEACTIVITY_ENTRY(KErrorTag, MeshMachine::TRaiseActivityError)
       
    89 NODEACTIVITY_END()
       
    90 }
       
    91 
       
    92 namespace IPSCprStartActivity
       
    93 {
       
    94 //TODO perhaps get this from a header file since its used in a number of places - see ss_subconn.cpp
       
    95 typedef MeshMachine::TAcceptErrorState<CoreNetStates::TAwaitingApplyResponse> TAwaitingApplyResponseOrError;
       
    96 
       
    97 DECLARE_DEFINE_CUSTOM_NODEACTIVITY(ECFActivityStart, IPSCprStart, TCFServiceProvider::TStart, PRActivities::CStartActivity::NewL)
       
    98     FIRST_NODEACTIVITY_ENTRY(MeshMachine::TAwaitingMessageState<TCFServiceProvider::TStart>, IpSCprStates::TNoTagOrBearerPresentBlockedByStopOrBindTo)
       
    99 	NODEACTIVITY_ENTRY(CoreNetStates::KBearerPresent, CoreNetStates::TBindSelfToPresentBearer, CoreNetStates::TAwaitingBindToComplete, MeshMachine::TTag<CoreNetStates::KBearerPresent>)
       
   100 
       
   101 	NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TSendNoBearer, MeshMachine::TAwaitingMessageState<TCFControlProvider::TBearer>, MeshMachine::TTag<CoreNetStates::KBearerPresent>)
       
   102 
       
   103 	//[401TODO] RZ: this tuple is the only thing that distinguishes this activity from the core although, the core should look
       
   104 	//like this one - i.e.: sending params down on start is every scpr's bussiness.
       
   105 #ifdef SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
   106 	NODEACTIVITY_ENTRY(CoreNetStates::KBearerPresent, PRStates::TSendParamsToServiceProvider, CoreNetStates::TAwaitingParamResponse, IpSCprStates::TNoTagOrAlreadyStarted)
       
   107 #else
       
   108 	NODEACTIVITY_ENTRY(CoreNetStates::KBearerPresent, IpSCprStates::TSendParamsToServiceProvider, CoreNetStates::TAwaitingParamResponse, IpSCprStates::TNoTagOrAlreadyStarted)
       
   109 #endif // SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
   110 
       
   111 	NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TStartServiceProviderRetry, CoreNetStates::TAwaitingStarted, MeshMachine::TNoTag)
       
   112     NODEACTIVITY_ENTRY(CoreNetStates::KAlreadyStarted,CoreNetStates::TSendApplyRequest, TAwaitingApplyResponseOrError, MeshMachine::TNoTagOrErrorTag)
       
   113 	LAST_NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TSendStarted)
       
   114 	LAST_NODEACTIVITY_ENTRY(KErrorTag, MeshMachine::TRaiseActivityError)
       
   115 NODEACTIVITY_END()
       
   116 }
       
   117 
       
   118 
       
   119 namespace IPSCprActivities
       
   120 {
       
   121 DECLARE_DEFINE_ACTIVITY_MAP(activityMap)
       
   122     ACTIVITY_MAP_ENTRY(IPSCprAddressUpdate, IPSCprAddressUpdate)
       
   123     ACTIVITY_MAP_ENTRY(IPSCprApplyRequest, IpSCprApplyReq)
       
   124     ACTIVITY_MAP_ENTRY(IPSCprStartActivity, IPSCprStart)
       
   125 #ifndef SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
   126 	ACTIVITY_MAP_ENTRY(IPSCprParamsRequest, IPSCprSetParams)
       
   127 #endif // SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
   128 ACTIVITY_MAP_END_BASE(IPDeftBaseSCprActivities, ipdeftbasescprActivityMap)
       
   129 }
       
   130 //-=========================================================
       
   131 //
       
   132 // CIpSubConnectionProvider methods
       
   133 //
       
   134 //-=========================================================
       
   135 CIpSubConnectionProvider* CIpSubConnectionProvider::NewL(CIpSubConnectionProviderFactory& aFactory)
       
   136 /**
       
   137 Construct a new IP SubConnection Provider Object
       
   138 
       
   139 @params aFactory factory that create this object
       
   140 @param aConnProvider Connection Provider associated with this object
       
   141 */
       
   142 	{
       
   143 	__IPCPRLOG(IpCprLog::Printf(_L("CIpSubConnectionProvider::NewL")));
       
   144 	CIpSubConnectionProvider* self = new (ELeave) CIpSubConnectionProvider(aFactory);
       
   145     CleanupStack::PushL(self);
       
   146     self->ConstructL();
       
   147     CleanupStack::Pop();
       
   148 	return self;
       
   149 	}
       
   150 
       
   151 
       
   152 CIpSubConnectionProvider::~CIpSubConnectionProvider()
       
   153     {
       
   154 	__IPCPRLOG(IpCprLog::Printf(_L("CIpSubConnectionProvider::~CIpSubConnectionProvider [%08x]"), this));
       
   155     LOG_NODE_DESTROY(KIPSCprTag, CIpSubConnectionProvider);
       
   156     }
       
   157 
       
   158 
       
   159 CIpSubConnectionProvider::CIpSubConnectionProvider(ESock::CSubConnectionProviderFactoryBase& aFactory)
       
   160 :CIpSubConnectionProviderBase(aFactory, IPSCprActivities::activityMap::Self())
       
   161     {
       
   162 	__IPCPRLOG(IpCprLog::Printf(_L("CIpSubConnectionProvider::CIpSubConnectionProvider [%08x]"), this));
       
   163     LOG_NODE_CREATE(KIPSCprTag, CIpSubConnectionProvider);
       
   164     }
       
   165 
       
   166 void CIpSubConnectionProvider::ConstructL()
       
   167 /**
       
   168 IP SubConnection Provider Second Phase Constructor
       
   169 */
       
   170 	{
       
   171     CIpSubConnectionProviderBase::ConstructL(KIPSCPRPreallocatedActivityBufferSize);
       
   172 	}
       
   173 
       
   174 RNodeInterface* CIpSubConnectionProvider::NewClientInterfaceL(const TClientType& aClientType, TAny* /*aClientInfo*/)
       
   175     {
       
   176 	__IPCPRLOG(IpCprLog::Printf(_L("CIpSubConnectionProvider::NewClientInterfaceL [%08x]"), this));
       
   177 
       
   178     if (aClientType.Type() & TCFClientType::EData)
       
   179         {
       
   180         return new (ELeave) RIPDataClientNodeInterface();
       
   181         }
       
   182 
       
   183     return CCoreSubConnectionProvider::NewClientInterfaceL(aClientType);
       
   184     }
       
   185 
       
   186 
       
   187 void CIpSubConnectionProvider::Received(TNodeContextBase& aContext)
       
   188     {
       
   189 	__IPCPRLOG(IpCprLog::Printf(_L("CIpSubConnectionProvider::Received [%08x]"), this));
       
   190 
       
   191     Messages::TNodeSignal::TMessageId noPeerIds[] = {
       
   192         TCFFactory::TPeerFoundOrCreated::Id(),
       
   193         TCFPeer::TJoinRequest::Id(),
       
   194         Messages::TNodeSignal::TMessageId()
       
   195         };
       
   196 
       
   197     MeshMachine::AMMNodeBase::Received(noPeerIds, aContext);
       
   198 	MeshMachine::AMMNodeBase::PostReceived(aContext);
       
   199 	}
       
   200 
       
   201 void CIpSubConnectionProvider::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage)
       
   202     {
       
   203 	__IPCPRLOG(IpCprLog::Printf(_L("CIpSubConnectionProvider::ReceivedL [%08x]"), this));
       
   204 	ESOCK_DEBUG_MESSAGE_INTERCEPT(aSender, aMessage, aRecipient);
       
   205 	IpSCprStates::TContext ctx(*this, aMessage, aSender, aRecipient);
       
   206     CIpSubConnectionProvider::Received(ctx);
       
   207     User::LeaveIfError(ctx.iReturn);
       
   208 	}
       
   209 
       
   210 TInt CIpSubConnectionProvider::AddressCompletionValidation(RIPDataClientNodeInterface& aDataClient)
       
   211 /**
       
   212 Helper function to check for presence of source  and destionation address in DataClient Node Interface
       
   213 
       
   214 @param aDataClient Data Client
       
   215 */
       
   216 	{
       
   217 	__IPCPRLOG(IpCprLog::Printf(_L("CIpSubConnectionProvider::AddressCompletionValidation [%08x]"), this));
       
   218 
       
   219 	TUint addrFamily = aDataClient.iCliSrcAddr.Family();
       
   220 
       
   221 	if( addrFamily != KAfInet6 && addrFamily != KAfInet)
       
   222 		{
       
   223 		__IPCPRLOG(IpCprLog::Printf(_L("Source Address not defined")));
       
   224 		return KErrNotReady;
       
   225 		}
       
   226 
       
   227 	addrFamily = aDataClient.iCliSrcAddr.Family();
       
   228 	if( addrFamily != KAfInet6 && addrFamily != KAfInet)
       
   229 		{
       
   230 		__IPCPRLOG(IpCprLog::Printf(_L("Destination Address not defined")));
       
   231 		return KErrNotReady;
       
   232 		}
       
   233 
       
   234 	return KErrNone;
       
   235 	}
       
   236 
       
   237 CSubConIPAddressInfoParamSet* CIpSubConnectionProvider::InitBundleL()
       
   238 /**
       
   239 Helper function to initialize param bundle
       
   240 */
       
   241 	{
       
   242 	CSubConIPAddressInfoParamSet* retValue(NULL);
       
   243 
       
   244 	// create family
       
   245 	RCFParameterFamilyBundleC& bundle = GetOrCreateParameterBundleL();
       
   246 	RParameterFamily family=bundle.FindFamily(KSubConIPAddressInfoFamily);
       
   247 	if ( family.IsNull() ) 
       
   248 		{
       
   249 		__IPCPRLOG(IpCprLog::Printf(_L("SubConIPAddressInfoFamily is created")));
       
   250 		//family = bundle.CreateFamilyL(KSubConIPAddressInfoFamily); //PJLEFT
       
   251 		RCFParameterFamilyBundle newBundle;
       
   252 		newBundle.CreateL();
       
   253 		newBundle.Open(iParameterBundle);
       
   254 		family = newBundle.CreateFamilyL(KSubConIPAddressInfoFamily);
       
   255 		retValue = CSubConIPAddressInfoParamSet::NewL(family, RParameterFamily::ERequested);
       
   256 		newBundle.Close();
       
   257 		}
       
   258 	else
       
   259 		{
       
   260 		// get param set
       
   261 		STypeId typeId = STypeId::CreateSTypeId( CSubConIPAddressInfoParamSet::EUid,
       
   262 						CSubConIPAddressInfoParamSet::ETypeId );
       
   263 		retValue = static_cast<CSubConIPAddressInfoParamSet*>
       
   264 			(family.FindParameterSet(typeId,RParameterFamily::ERequested));
       
   265 		}
       
   266 
       
   267 	return retValue;
       
   268 	}