networkcontrol/iptransportlayer/src/ipdeftscpr.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 <comms-infras/corescpractivities.h>
       
    24 #include <comms-infras/ss_corepractivities.h>
       
    25 #include "ipdeftscpr.h"
       
    26 #include "IPMessages.h"
       
    27 #include <comms-infras/ss_log.h>
       
    28 #include "IPCpr.h"
       
    29 
       
    30 #include <comms-infras/ss_msgintercept.h>
       
    31 
       
    32 #ifdef SYMBIAN_TRACE_ENABLE
       
    33 	#define KIPSCprTag KESockSubConnectionTag
       
    34 	//_LIT8(KIPSCprSubTag, "ipqosdeftscpr");
       
    35 #endif // SYMBIAN_TRACE_ENABLE
       
    36 
       
    37 
       
    38 using namespace Messages;
       
    39 using namespace MeshMachine;
       
    40 using namespace ESock;
       
    41 using namespace IPDeftBaseSCprActivities;
       
    42 using namespace PRActivities;
       
    43 using namespace CoreNetStates;
       
    44 
       
    45 //We reserve space for two preallocated activities that may start concurrently on the default SCPR
       
    46 //node: destroy and data client stop.
       
    47 static const TUint KDefaultMaxPreallocatedActivityCount = 2;
       
    48 static const TUint KMaxPreallocatedActivitySize = sizeof(MeshMachine::CNodeRetryParallelActivity) + sizeof(MeshMachine::APreallocatedOriginators<4>);
       
    49 static const TUint KIPDefaultSCPRPreallocatedActivityBufferSize = KDefaultMaxPreallocatedActivityCount * KMaxPreallocatedActivitySize;
       
    50 
       
    51 //-=========================================================
       
    52 //
       
    53 // States
       
    54 //
       
    55 //-=========================================================
       
    56 namespace IPDeftSCprStates
       
    57 {
       
    58 DEFINE_SMELEMENT(TPolicyChecking, NetStateMachine::MStateTransition, IPBaseSCprStates::TContext)
       
    59 void TPolicyChecking::DoL()
       
    60 	{
       
    61 	IPBaseSCprStates::TStoreAddressUpdate storeAddressUpdate(iContext);
       
    62 	storeAddressUpdate.DoL();
       
    63 
       
    64 	TCFIPMessage::TDataClientRouted& addressUpdateMsg = message_cast<TCFIPMessage::TDataClientRouted>(iContext.iMessage);
       
    65 
       
    66 	// check for src and dst address presence
       
    67 	if( addressUpdateMsg.iAddrUpdate.iSrcSockAddr.Family() != KAFUnspec &&
       
    68 		addressUpdateMsg.iAddrUpdate.iDestSockAddr.Family() != KAFUnspec )
       
    69 		{
       
    70 		RNodeInterface* ctrlProvider = iContext.Node().ControlProvider();
       
    71 		User::LeaveIfError(ctrlProvider? KErrNone : KErrCorrupt);
       
    72 
       
    73 	    RIPDataClientNodeInterface* client = static_cast<RIPDataClientNodeInterface*>(iContext.iPeer);
       
    74 
       
    75 		ctrlProvider->PostMessage(
       
    76 			TNodeCtxId(iContext.ActivityId(), iContext.NodeId()),
       
    77 			TCFIPMessage::TPolicyParams(
       
    78 				addressUpdateMsg.iAddrUpdate,
       
    79 				iContext.NodeId(),
       
    80 				address_cast<TNodeId>(iContext.iSender),
       
    81 				client->iAppSid
       
    82 				).CRef()
       
    83 			);
       
    84 		}
       
    85 	}
       
    86 }//namespace 
       
    87 //-=========================================================
       
    88 //
       
    89 // Activities
       
    90 //
       
    91 //-=========================================================
       
    92 namespace IPDeftSCprAddressUpdate
       
    93 {
       
    94 DECLARE_DEFINE_NODEACTIVITY(ECFActivityAddressUpdate, IPDeftSCprAddressUpdate, TCFIPMessage::TDataClientRouted)
       
    95 	NODEACTIVITY_ENTRY(KNoTag, IPDeftSCprStates::TPolicyChecking, IPBaseSCprStates::TAwaitingAddressUpdate, MeshMachine::TNoTag)
       
    96 NODEACTIVITY_END()
       
    97 }
       
    98 
       
    99 
       
   100 DEFINE_SMELEMENT(CCommsIPBinderActivity::TFetchClientUids, NetStateMachine::MStateTransition, TContext)
       
   101 void CCommsIPBinderActivity::TFetchClientUids::DoL()
       
   102 	{
       
   103 	MPlatsecApiExt* platsec(NULL);
       
   104    	TRAP_IGNORE(platsec = reinterpret_cast<MPlatsecApiExt*>(address_cast<TNodeId>(iContext.iSender).Node().FetchNodeInterfaceL(MPlatsecApiExt::KInterfaceId)));
       
   105    	if (platsec)
       
   106    		{
       
   107 		TSecureId secureId = 0;
       
   108    		if(platsec->SecureId(secureId) != KErrNone)
       
   109    			{
       
   110    			return;
       
   111    			}
       
   112 
       
   113 		CCommsIPBinderActivity* intf = reinterpret_cast<CCommsIPBinderActivity*>(iContext.iNodeActivity->FetchExtInterface(CCommsIPBinderActivity::KInterfaceId));
       
   114 		if(intf)
       
   115 			{
       
   116 			intf->SetUid(TUid::Uid(secureId.iId));
       
   117 			}
       
   118    		}
       
   119 	}
       
   120 
       
   121 DEFINE_SMELEMENT(CCommsIPBinderActivity::TUpdateClientUids, NetStateMachine::MStateTransition, TContext)
       
   122 void CCommsIPBinderActivity::TUpdateClientUids::DoL()
       
   123 	{
       
   124 	/* Data client joined is recieved from the factory, which isn't the peer. Therefore we must look up
       
   125 	 * the client using it's comms id which we can get from the dcjoined message
       
   126 	 */
       
   127     RIPDataClientNodeInterface* client = static_cast<RIPDataClientNodeInterface*>(iContext.iPeer);
       
   128     if (!client)
       
   129         {
       
   130         return;
       
   131         }
       
   132 
       
   133 	CCommsIPBinderActivity* intf = reinterpret_cast<CCommsIPBinderActivity*>(iContext.iNodeActivity->FetchExtInterface(CCommsIPBinderActivity::KInterfaceId));
       
   134 	if(intf)
       
   135 		{
       
   136 	    client->iAppSid = intf->GetUid();
       
   137 		}
       
   138 	}
       
   139 
       
   140 namespace IPDeftSCprBinderRequestActivity
       
   141 {
       
   142 DECLARE_DEFINE_CUSTOM_NODEACTIVITY(ECFActivityBinderRequest, IPDeftSCprBinderRequest, TCFServiceProvider::TCommsBinderRequest, CCommsIPBinderActivity::NewL)
       
   143 	FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingBinderRequest, MeshMachine::TNoTag )
       
   144 
       
   145 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, CCommsIPBinderActivity::TFetchClientUids, IPDeftBaseSCprBinderRequestActivity::TNoTagOrUseExistingOrPermissionDenied)
       
   146 	NODEACTIVITY_ENTRY(KNoTag, PRStates::TCreateDataClient, CoreNetStates::TAwaitingDataClientJoin, MeshMachine::TNoTag)
       
   147 	// Below this point we need to modify the error handling approach. If we're getting a TError on TBinderResponse,
       
   148 	// this means the client requesting the binder couldn't bind to it. As far as the client is concerned, this
       
   149 	// activity is finished (it has flagged an error). The standard error handling will result in erroring
       
   150 	// the originator. In this case we shouoldn't error the originator, instead, wrap up quietly.
       
   151 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, CCommsIPBinderActivity::TProcessDataClientCreationAndUpdateClientUids, MeshMachine::TTag<CoreStates::KUseExisting>)
       
   152 
       
   153 	NODEACTIVITY_ENTRY(CoreStates::KUseExisting, CCommsBinderActivity::TSendBinderResponse, CCommsBinderActivity::TAwaitingBindToComplete, MeshMachine::TNoTagOrErrorTag)
       
   154 	LAST_NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TDoNothing)
       
   155 	LAST_NODEACTIVITY_ENTRY(KErrorTag, MeshMachine::TClearError)
       
   156 	LAST_NODEACTIVITY_ENTRY(IPDeftBaseSCprBinderRequestActivity::KPermissionDenied, MeshMachine::TRaiseAndClearActivityError)
       
   157 NODEACTIVITY_END()
       
   158 }
       
   159 
       
   160 namespace IPDeftSCprActivities
       
   161 {
       
   162 DECLARE_DEFINE_ACTIVITY_MAP(activityMap)
       
   163 	ACTIVITY_MAP_ENTRY(IPDeftSCprAddressUpdate, IPDeftSCprAddressUpdate)
       
   164 	ACTIVITY_MAP_ENTRY(IPDeftSCprBinderRequestActivity, IPDeftSCprBinderRequest)
       
   165 ACTIVITY_MAP_END_BASE(IPDeftBaseSCprActivities, ipdeftbasescprActivityMap)
       
   166 }
       
   167 
       
   168 //-=========================================================
       
   169 //
       
   170 // CIpDefaultSubConnectionProvider methods
       
   171 //
       
   172 //-=========================================================
       
   173 CIpDefaultSubConnectionProvider::~CIpDefaultSubConnectionProvider()
       
   174     {
       
   175     LOG_NODE_DESTROY(KIPSCprTag, CIpDefaultSubConnectionProvider);
       
   176     }
       
   177 
       
   178 CIpDefaultSubConnectionProvider::CIpDefaultSubConnectionProvider(ESock::CSubConnectionProviderFactoryBase& aFactory)
       
   179 	: CIpDefaultBaseSubConnectionProvider(aFactory, IPDeftSCprActivities::activityMap::Self())
       
   180     {
       
   181     LOG_NODE_CREATE(KIPSCprTag, CIpDefaultSubConnectionProvider);
       
   182     }
       
   183 
       
   184 CIpDefaultSubConnectionProvider* CIpDefaultSubConnectionProvider::NewL(ESock::CSubConnectionProviderFactoryBase& aFactory)
       
   185     {
       
   186     CIpDefaultSubConnectionProvider* provider = new (ELeave) CIpDefaultSubConnectionProvider(aFactory);
       
   187     CleanupStack::PushL(provider);
       
   188     provider->ConstructL(KIPDefaultSCPRPreallocatedActivityBufferSize);
       
   189 
       
   190     CleanupStack::Pop(provider);
       
   191     return provider;
       
   192     }
       
   193 
       
   194 void CIpDefaultSubConnectionProvider::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage)
       
   195 	{
       
   196 	ESOCK_DEBUG_MESSAGE_INTERCEPT(aSender, aMessage, aRecipient);
       
   197    	TNodeContext<CIpDefaultSubConnectionProvider> ctx(*this, aMessage, aSender, aRecipient);
       
   198 	CCoreSubConnectionProvider::ReceivedL(aSender, aRecipient, aMessage);
       
   199 	User::LeaveIfError(ctx.iReturn);
       
   200 	}
       
   201 
       
   202 MeshMachine::CNodeActivityBase* CCommsIPBinderActivity::NewL(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
       
   203     {
       
   204 	TUint c = GetNextActivityCountL(aActivitySig,aNode);
       
   205     return new(ELeave)CCommsIPBinderActivity(aActivitySig, aNode, c);
       
   206     }
       
   207 
       
   208 CCommsIPBinderActivity::CCommsIPBinderActivity(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode, TUint aNextActivityCount)
       
   209 :	CCommsBinderActivity(aActivitySig, aNode, aNextActivityCount)
       
   210 	{
       
   211 	iAppSid = TUid::Null();
       
   212 	}