networkcontrol/ipnetworklayer/src/IPProtoMCpr.cpp
changeset 0 af10295192d8
child 53 7e41d162e158
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 // IPProto MCPR
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 
       
    24 #include <comms-infras/ss_log.h>
       
    25 //#include <ss_nodestates.h>
       
    26 #include <comms-infras/corecprstates.h>
       
    27 #include <comms-infras/coremcprstates.h>
       
    28 #include <comms-infras/coremcpractivities.h>
       
    29 #include <commsdattypesv1_1.h> // CommsDat
       
    30 #include <comms-infras/ss_tiermanager.h> //TierManagerUtils
       
    31 #include <comms-infras/ss_tiermanagerutils.h>
       
    32 #include <comms-infras/netcfgextprov.h>
       
    33 #include "IPProtoMCpr.h"
       
    34 #include "idletimer.h"
       
    35 
       
    36 
       
    37 #if defined __CFLOG_ACTIVE || defined SYMBIAN_TRACE_ENABLE
       
    38 #define KIPProtoMCprTag KESockMetaConnectionTag
       
    39 _LIT8(KIPProtoMCprSubTag, "ipprotomcpr");
       
    40 #endif
       
    41 
       
    42 #include <comms-infras/ss_msgintercept.h>
       
    43 
       
    44 using namespace Messages;
       
    45 using namespace MeshMachine;
       
    46 using namespace ESock;
       
    47 using namespace NetStateMachine;
       
    48 using namespace CommsDat;
       
    49 using namespace MCprActivities;
       
    50 
       
    51 //
       
    52 //CIPProtoMetaConnectionProvider
       
    53 CIPProtoMetaConnectionProvider* CIPProtoMetaConnectionProvider::NewL(CMetaConnectionProviderFactoryBase& aFactory,
       
    54                                                                      const TProviderInfo& aProviderInfo)
       
    55 	{
       
    56 	CIPProtoMetaConnectionProvider* self = new (ELeave) CIPProtoMetaConnectionProvider(aFactory,aProviderInfo,IPProtoMCprActivities::ipProtoActivitiesMCpr::Self());
       
    57 	CleanupStack::PushL(self);
       
    58 	self->ConstructL();
       
    59 	CleanupStack::Pop(self);
       
    60 	return self;
       
    61 	}
       
    62 
       
    63 CIPProtoMetaConnectionProvider::CIPProtoMetaConnectionProvider(CMetaConnectionProviderFactoryBase& aFactory,
       
    64                                                                const TProviderInfo& aProviderInfo,
       
    65                                                                const MeshMachine::TNodeActivityMap& aActivityMap)
       
    66 	:	CCoreMetaConnectionProvider(aFactory,aProviderInfo,aActivityMap), iIapLocked(EFalse)
       
    67 	{
       
    68 	LOG_NODE_CREATE(KIPProtoMCprTag, CIPProtoMetaConnectionProvider);
       
    69 	}
       
    70 
       
    71 CIPProtoMetaConnectionProvider::~CIPProtoMetaConnectionProvider()
       
    72 	{
       
    73 	LOG_NODE_DESTROY(KIPProtoMCprTag, CIPProtoMetaConnectionProvider);
       
    74 	}
       
    75 
       
    76 
       
    77 void CIPProtoMetaConnectionProvider::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage)
       
    78     {
       
    79 	__CFLOG_VAR((KIPProtoMCprTag, KIPProtoMCprSubTag, _L8("CIPProtoMetaConnectionProvider %08x:\tReceived() aCFMessage=%d"),
       
    80 	   this, aMessage.MessageId().MessageId()));
       
    81 
       
    82 	ESOCK_DEBUG_MESSAGE_INTERCEPT(aSender, aMessage, aRecipient);
       
    83 
       
    84 	TNodeContext<CIPProtoMetaConnectionProvider> ctx(*this, aMessage, aSender, aRecipient);
       
    85     CCoreMetaConnectionProvider::Received(ctx);
       
    86 
       
    87     User::LeaveIfError(ctx.iReturn);
       
    88 	}
       
    89 
       
    90 void CIPProtoMetaConnectionProvider::ConstructL()
       
    91     {
       
    92     CMetaConnectionProviderBase::ConstructL(); //This initialises the AccessPointInfo
       
    93 
       
    94   	//For construction of IpProto providers (construction only) we use the instance field of TProviderInfo
       
    95    	//to carry the IAP id. The IAP id is necessary for the initialisation if IpProto specific data.
       
    96     TInt iap = (TInt)ProviderInfo().Instance();
       
    97 	SetProviderInfo(TProviderInfo(ProviderInfo().TierId(),iap));
       
    98     SetConfigL();
       
    99     }
       
   100 
       
   101 void CIPProtoMetaConnectionProvider::SetConfigL()
       
   102 /**
       
   103 Setup the provisioning information for the IPProto layer.
       
   104 */
       
   105     {
       
   106     RMetaExtensionContainer mec;
       
   107     mec.Open(AccessPointConfig());
       
   108     CleanupClosePushL(mec);
       
   109 
       
   110     //At this moment our ProviderInfo().APId() points to the IAP this provider represents
       
   111     TUint configurationIap = ProviderInfo().APId();
       
   112     CCommsDatIapView* iapView = CCommsDatIapView::NewLC(configurationIap);
       
   113 
       
   114     // Read Idle timer values
       
   115     TIdleTimerValues* timerValues = new (ELeave) TIdleTimerValues;
       
   116     CleanupStack::PushL(timerValues);
       
   117     iapView->GetTimeoutValuesL(timerValues->iShortTimer, timerValues->iMediumTimer, timerValues->iLongTimer);
       
   118     mec.AppendExtensionL(timerValues); //iAccessPointConfig owns timerValues from now on
       
   119     CleanupStack::Pop(timerValues);
       
   120 
       
   121     // Read NetworkId
       
   122     TUint32 net = 0;
       
   123     iapView->GetIntL(KCDTIdIAPNetwork, net);
       
   124 
       
   125 	// Read Protocol list (from IfNetworks field).  This contains a comma seperated list of
       
   126 	// protocol names and determines the binders instantiated in the lower CFProtocol (typically
       
   127 	// "ip" or "ip,ip6").
       
   128 
       
   129 	HBufC* protocolList = NULL;
       
   130 
       
   131 	if (iapView->GetServiceTableType() == KCDTIdVPNServiceRecord)
       
   132 		{
       
   133 		// *** HACK ***
       
   134 		// Normally, the IfNetworks field is read via the Agent ReadDes() methods.  This
       
   135 		// allow, for example, the VPNConnAgt to fake up the IfNetworks field to "ip" when,
       
   136 		// in fact, it does not exist in the CommsDat.  We should somehow be arranging for the
       
   137 		// provisioning of this field to be from the underlying Agent, but the Agent is
       
   138 		// only accessible from the Agent Adapter in the AgentSCPr layer.  Perhaps the
       
   139 		// IPProtoSCPr can do the provisioning of the IfNetworks field, but it would need
       
   140 		// to get the contents of the field from the AgentSCPr below it.
       
   141 		_LIT(KVPNIfNetworks, "ip");
       
   142 		protocolList = HBufC::NewMaxL(4);
       
   143 		*protocolList = KVPNIfNetworks();
       
   144 		}
       
   145 	else
       
   146 		{
       
   147 		iapView->GetTableCommonTextFieldL(CCommsDatIapView::EIfNetworks, protocolList);
       
   148 		}
       
   149 
       
   150 
       
   151 	HBufC* configdaemonmanager = NULL;
       
   152 	TRAPD(err, iapView->GetTableCommonTextFieldL(ESock::CCommsDatIapView::EConfigDaemonManagerName,
       
   153 												  configdaemonmanager));
       
   154 	if ((err == KErrNone) && (*configdaemonmanager != KNullDesC))
       
   155 		{
       
   156 		CleanupStack::PushL(configdaemonmanager);
       
   157 		CNetCfgExtProvision* netcfg = CNetCfgExtProvision::NewL();
       
   158 		CleanupStack::PushL(netcfg);
       
   159 		netcfg->InitialiseConfigL(iapView);
       
   160 		mec.AppendExtensionL(netcfg);
       
   161 		CleanupStack::Pop(netcfg);
       
   162 		CleanupStack::PopAndDestroy(configdaemonmanager);
       
   163 		}
       
   164 
       
   165 	CleanupStack::PopAndDestroy(iapView);
       
   166 	CleanupStack::PushL(protocolList);
       
   167 
       
   168     TItfInfoConfigExt* itfInfoConfig = new (ELeave) TItfInfoConfigExt(TConnectionInfo(configurationIap,net));
       
   169     CleanupStack::PushL(itfInfoConfig);
       
   170 
       
   171 	if (itfInfoConfig->iProtocolList.MaxSize() >= protocolList->Size())
       
   172 		{
       
   173 		itfInfoConfig->iProtocolList.Copy(*protocolList);
       
   174 		}
       
   175 	else
       
   176 		{
       
   177 		User::Leave(KErrOverflow);
       
   178 		}
       
   179 
       
   180     mec.AppendExtensionL(itfInfoConfig);
       
   181     CleanupStack::Pop(itfInfoConfig);
       
   182     CleanupStack::PopAndDestroy(protocolList);
       
   183 
       
   184     XInterfaceNames* itfNames = XInterfaceNames::NewL();
       
   185     CleanupStack::PushL(itfNames);
       
   186     mec.AppendExtensionL(itfNames);
       
   187     CleanupStack::Pop(itfNames);
       
   188 
       
   189     iAccessPointConfig.Close();
       
   190 	iAccessPointConfig.Open(mec);
       
   191 	CleanupStack::PopAndDestroy(&mec);
       
   192     }
       
   193 
       
   194 namespace IPProtoMCprSelectConnPrefListActivity
       
   195 {
       
   196 DECLARE_DEFINE_CUSTOM_NODEACTIVITY(ECFActivitySelect, IPProtoMCprSelectConnPrefList, TCFSelector::TSelect, CSelectNextLayerActivity::NewL)
       
   197 	//Reply from TAwaitingSelectNextLayer if no choices, otherwise accept
       
   198 	FIRST_NODEACTIVITY_ENTRY(MCprStates::TAwaitingSelectNextLayerSuper, MeshMachine::TNoTag)
       
   199 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, CSelectNextLayerActivity::TProcessSimpleSelectionPolicySuper, MCprStates::TSelectedProvider)
       
   200 	//Start the selection main loop
       
   201 	NODEACTIVITY_ENTRY(MCprStates::KSelectedProvider, CSelectNextLayerActivity::TFindOrCreateTierManagerSuper, MCprStates::TAwaitingTierManagerCreated, MeshMachine::TNoTag)
       
   202 	NODEACTIVITY_ENTRY(KNoTag, CSelectNextLayerActivity::TJoinTierManager, CoreStates::TAwaitingJoinComplete, MeshMachine::TNoTag)
       
   203 	//Select next provider and enter the selection internal loop if provider received. Break if SelectComplete(NULL).
       
   204 	NODEACTIVITY_ENTRY(KNoTag, CSelectNextLayerActivity::TSelectNextLayerSuper, MCprStates::TAwaitingSelectComplete, CSelectNextLayerActivity::TNoTagOrSelectedProviderIsNull)
       
   205     NODEACTIVITY_ENTRY(KNoTag, CSelectNextLayerActivity::TAddProviderInfo, MCprStates::TAwaitingSelectComplete, CSelectNextLayerActivity::TNoTagBackwardsOrJoinServiceProvider)
       
   206     //Break the selection internal loop if SelectComplete(NULL), otherwise stay in this tripple
       
   207     NODEACTIVITY_ENTRY(MCprStates::KJoinServiceProvider, CSelectNextLayerActivity::TJoinServiceProvider, CoreStates::TAwaitingJoinComplete, MeshMachine::TNoTag)
       
   208     THROUGH_NODEACTIVITY_ENTRY(KNoTag, CSelectNextLayerActivity::TSendSelectComplete, CSelectNextLayerActivity::TSelectedProviderIsNullOrJoinServiceProviderBackward)
       
   209 	//Break the selection main loop if no more choices, otherwise go back again
       
   210 	THROUGH_NODEACTIVITY_ENTRY(MCprStates::KSelectedProviderIsNull, CSelectNextLayerActivity::TLeaveTierManager, CSelectNextLayerActivity::TNoTagOrSelectedProviderBackwardSuper)
       
   211 	//Finish the activity
       
   212 	LAST_NODEACTIVITY_ENTRY(KNoTag, MCprStates::TSendFinalSelectComplete)
       
   213 NODEACTIVITY_END()
       
   214 }
       
   215 
       
   216 namespace IPProtoMCprActivities
       
   217 {
       
   218 DEFINE_ACTIVITY_MAP(ipProtoActivitiesMCpr)
       
   219 	ACTIVITY_MAP_ENTRY(IPProtoMCprSelectConnPrefListActivity, IPProtoMCprSelectConnPrefList)
       
   220 ACTIVITY_MAP_END_BASE(MCprActivities, coreMCprActivities)
       
   221 }