linklayerprotocols/ethernetnif/EthInt/ethmcpr.cpp
changeset 0 af10295192d8
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 // Ethernet MCPR
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <comms-infras/ss_log.h>
       
    24 #include <comms-infras/agentmcpractivities.h>
       
    25 #include <comms-infras/coremcpractivities.h>
       
    26 #include <comms-infras/ss_tiermanagerutils.h>
       
    27 #include <comms-infras/ss_msgintercept.h>
       
    28 
       
    29 #include "ethmcpr.h"
       
    30 #include "EthProvision.h"
       
    31 
       
    32 #define KEthMCprTag KESockMetaConnectionTag
       
    33 
       
    34 using namespace Messages;
       
    35 using namespace MeshMachine;
       
    36 using namespace ESock;
       
    37 using namespace NetStateMachine;
       
    38 using namespace MCprActivities;
       
    39 using namespace EthMCprStates;
       
    40 
       
    41 
       
    42 
       
    43 // No Bearer Activity
       
    44 namespace EthMCPRNoBearerActivity
       
    45 {
       
    46 DECLARE_DEFINE_NODEACTIVITY(ECFActivityNoBearer, EthMCPRNoBearer, TCFControlProvider::TNoBearer)
       
    47 	FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingNoBearer, MeshMachine::TNoTag)
       
    48 	LAST_NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TSendBearer)
       
    49 NODEACTIVITY_END()
       
    50 }
       
    51 
       
    52 
       
    53 
       
    54 // Activity Map
       
    55 namespace EthMCprStates
       
    56 {
       
    57 DEFINE_EXPORT_ACTIVITY_MAP(stateMap)
       
    58 	ACTIVITY_MAP_ENTRY(EthMCPRNoBearerActivity, EthMCPRNoBearer)
       
    59 ACTIVITY_MAP_END_BASE(AgentMCprActivities, agentMCprActivities)
       
    60 } // namespace EthMCprStates
       
    61 
       
    62 //-=========================================================
       
    63 //
       
    64 //CEthMetaConnectionProvider implementation
       
    65 //
       
    66 //-=========================================================
       
    67 
       
    68 EXPORT_C CEthMetaConnectionProvider* CEthMetaConnectionProvider::NewL(ESock::CMetaConnectionProviderFactoryBase& aFactory, const TProviderInfo& aProviderInfo)
       
    69     {
       
    70     // coverity[alloc_fn] coverity[alias] coverity[assign]
       
    71     CEthMetaConnectionProvider* self = new (ELeave) CEthMetaConnectionProvider(aFactory, aProviderInfo, EthMCprStates::stateMap::Self());
       
    72     // coverity[push]
       
    73     CleanupStack::PushL(self);
       
    74     // coverity[alias] coverity[double_push]
       
    75     self->ConstructL();
       
    76     CleanupStack::Pop(self);
       
    77     return self;
       
    78     }
       
    79 
       
    80 EXPORT_C void CEthMetaConnectionProvider::ConstructL()
       
    81 	{
       
    82 	CAgentMetaConnectionProvider::ConstructL();
       
    83 	SetAccessPointConfigFromDbL();
       
    84 	}
       
    85 
       
    86 EXPORT_C CEthMetaConnectionProvider::CEthMetaConnectionProvider(CMetaConnectionProviderFactoryBase& aFactory,
       
    87     							     const ESock::TProviderInfo& aProviderInfo,
       
    88 								     const MeshMachine::TNodeActivityMap& aActivityMap)
       
    89 :	CAgentMetaConnectionProvider(aFactory,aProviderInfo,aActivityMap)
       
    90 	{
       
    91 	LOG_NODE_CREATE(KEthMCprTag, CEthMetaConnectionProvider);
       
    92 	}
       
    93 
       
    94 EXPORT_C  CEthMetaConnectionProvider::~CEthMetaConnectionProvider()
       
    95 	{
       
    96 	LOG_NODE_DESTROY(KEthMCprTag, CEthMetaConnectionProvider);
       
    97 	}
       
    98 
       
    99 EXPORT_C void CEthMetaConnectionProvider::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage)
       
   100     {
       
   101 	__CFLOG_VAR((KEthMCprTag, KEthMCprSubTag, _L8("CEthMetaConnectionProvider [this=%08x]::ReceivedL() aCFMessage=%d"),
       
   102 	   this, aCFMessage.MessageId().MessageId()));
       
   103 
       
   104 	ESOCK_DEBUG_MESSAGE_INTERCEPT(aSender, aMessage, aRecipient);
       
   105 
       
   106 	TNodeContext<CEthMetaConnectionProvider> ctx(*this, aMessage, aSender, aRecipient);
       
   107     CCoreMetaConnectionProvider::Received(ctx);
       
   108     User::LeaveIfError(ctx.iReturn);
       
   109 	}
       
   110 
       
   111 void CEthMetaConnectionProvider::SetAccessPointConfigFromDbL()
       
   112     {
       
   113 	__CFLOG_VAR((KEthMCprFactoryTag, KEthMCprFactorySubTag, _L8("CEthMetaConnectionProvider %08x:\tSetAccessPointConfigFromDbL()"), this));
       
   114 
       
   115     RMetaExtensionContainer mec;
       
   116     mec.Open(AccessPointConfig());
       
   117     CleanupClosePushL(mec);
       
   118     
       
   119 	
       
   120 	// Open an IAP specific view on CommsDat
       
   121 	CCommsDatIapView* iapView = OpenIapViewLC();
       
   122 
       
   123 	// Presumptions:
       
   124 	// - none of the extensions can already exist in the AccessPointConfig array.  AppendExtensionL()
       
   125 	//   is presumed to panic if adding the same extension a second time.
       
   126 	// - if we have added several extensions to the AccessPointConfig array before getting a failure
       
   127 	//   and leaving, it is presumed that the MCPr will be destroyed and AccessPointConfig destructor
       
   128 	//   will clean up the extensions immediately afterwards.
       
   129 
       
   130     ProvisionLinkConfigL(iapView, mec);
       
   131     ProvisionNetworkConfigL(iapView, mec);
       
   132     
       
   133 	CleanupStack::PopAndDestroy(); // CloseIapView();
       
   134 
       
   135 	AccessPointConfig().Close();
       
   136 	AccessPointConfig().Open(mec);
       
   137     CleanupStack::PopAndDestroy(&mec);
       
   138 	}
       
   139 
       
   140 
       
   141 
       
   142 void CEthMetaConnectionProvider::ProvisionLinkConfigL(CCommsDatIapView* aIapView, ESock::RMetaExtensionContainer& aMec)
       
   143     {
       
   144 	TLanLinkProvision* linkProvision = new (ELeave) TLanLinkProvision;
       
   145 	CleanupStack::PushL(linkProvision);
       
   146 
       
   147 	// Initialise the link config
       
   148 
       
   149 	// NOTE:
       
   150 	// All the LANBearer strings are read as 16-bit values and copied into the
       
   151 	// 8-bit buffers in the provisioning structure to save memory
       
   152 	HBufC* buf = NULL;
       
   153 	TInt err(KErrNone);
       
   154 
       
   155 	// Config Daemon Name
       
   156 	err = aIapView->GetText(KCDTIdLANConfigDaemonName, buf);
       
   157 	if (err == KErrNone  && buf != NULL) 
       
   158 	    {
       
   159     	linkProvision->SetConfigDaemonName(*buf);
       
   160     	delete buf;
       
   161     	buf= NULL;
       
   162 	    }
       
   163 	else if (err == KErrNotFound)
       
   164 	    {
       
   165 	    linkProvision->SetConfigDaemonName (KNullDesC);
       
   166 	    }
       
   167 	else
       
   168 	    {
       
   169 	    User::Leave(err);
       
   170 	    }
       
   171 
       
   172 	// LDD Filename
       
   173 	err = aIapView->GetText(KCDTIdLANBearerLddFilename, buf);
       
   174 	if (err == KErrNone && buf != NULL) 
       
   175 	    {
       
   176     	linkProvision->SetLddFilename(*buf);
       
   177     	delete buf;
       
   178     	buf= NULL;
       
   179 	    }
       
   180 	else if (err == KErrNotFound)
       
   181 	    {
       
   182 	    linkProvision->SetLddFilename (KNullDesC);
       
   183 	    }
       
   184 	else
       
   185 	    {
       
   186 	    User::Leave(err);
       
   187 	    }
       
   188 
       
   189 	// LDD Name
       
   190 	err = aIapView->GetText(KCDTIdLANBearerLddName, buf);
       
   191 	if (err == KErrNone && buf != NULL) 
       
   192 	    {
       
   193     	linkProvision->SetLddName(*buf);
       
   194     	delete buf;
       
   195     	buf= NULL;
       
   196 	    }
       
   197 	else if (err == KErrNotFound)
       
   198 	    {
       
   199 	    linkProvision->SetLddName (KNullDesC);
       
   200 	    }
       
   201 	else
       
   202 	    {
       
   203 	    User::Leave(err);
       
   204 	    }
       
   205 
       
   206 	// PDD Filename
       
   207 	err = aIapView->GetText(KCDTIdLANBearerPddFilename, buf);
       
   208 	if (err == KErrNone && buf != NULL) 
       
   209 	    {
       
   210     	linkProvision->SetPddFilename(*buf);
       
   211     	delete buf;
       
   212     	buf= NULL;
       
   213 	    }
       
   214 	else if (err == KErrNotFound)
       
   215 	    {
       
   216 	    linkProvision->SetPddFilename (KNullDesC);
       
   217 	    }
       
   218 	else
       
   219 	    {
       
   220 	    User::Leave(err);
       
   221 	    }
       
   222 
       
   223 	// PDD Name
       
   224 	err = aIapView->GetText(KCDTIdLANBearerPddName, buf);
       
   225 	if (err == KErrNone && buf != NULL) 
       
   226 	    {
       
   227     	linkProvision->SetPddName(*buf);
       
   228     	delete buf;
       
   229     	buf= NULL;
       
   230 	    }
       
   231 	else if (err == KErrNotFound)
       
   232 	    {
       
   233 	    linkProvision->SetPddName (KNullDesC);
       
   234 	    }
       
   235 	else
       
   236 	    {
       
   237 	    User::Leave(err);
       
   238 	    }
       
   239 
       
   240 	// Packet Driver Name - required info, always error
       
   241 	aIapView->GetTextL(KCDTIdLANBearerPacketDriverName, buf);
       
   242 	linkProvision->SetPacketDriverName(*buf);
       
   243  	delete buf;
       
   244 
       
   245 	// Append the provisioning object to the CAccessPointConfig array
       
   246  	aMec.AppendExtensionL(linkProvision);
       
   247 	CleanupStack::Pop(linkProvision);
       
   248     }
       
   249 
       
   250 
       
   251 void CEthMetaConnectionProvider::ProvisionNetworkConfigL(CCommsDatIapView* aIapView, ESock::RMetaExtensionContainer& aMec)
       
   252     {
       
   253 	HBufC* buf = NULL;
       
   254     aIapView->GetTextL(KCDTIdLANIfNetworks, buf);
       
   255     CleanupStack::PushL(buf);
       
   256     if (buf->Length() == 0)
       
   257         {
       
   258         User::Leave(KErrCorrupt);
       
   259         }
       
   260 
       
   261     TPtrC16 networks;
       
   262     networks.Set(*buf);
       
   263     TPtrC16 current;
       
   264     TUint32 order = 0;
       
   265     TInt commaPos = 0;
       
   266     while (commaPos != KErrNotFound)
       
   267         {
       
   268         commaPos = networks.LocateF(',');
       
   269         if (commaPos == KErrNotFound)
       
   270             {
       
   271             // take all of string
       
   272             current.Set(networks);
       
   273             }
       
   274         else
       
   275             {
       
   276             current.Set(networks.Ptr(), commaPos);
       
   277             }
       
   278 
       
   279         if (!current.CompareF(_L("ip")))
       
   280             {
       
   281             ProvisionIp4ConfigL(aIapView, order, aMec);
       
   282             }
       
   283         else if (!current.CompareF(_L("ip6")))
       
   284             {
       
   285             ProvisionIp6ConfigL(aIapView, order, aMec);
       
   286             }
       
   287         else
       
   288             {
       
   289             User::Leave(KErrCorrupt);
       
   290             }
       
   291 
       
   292         order++;
       
   293         networks.Set(networks.Mid(commaPos+1));
       
   294         }
       
   295 
       
   296     CleanupStack::PopAndDestroy(buf);
       
   297     }
       
   298 
       
   299 
       
   300 void CEthMetaConnectionProvider::ProvisionIp4ConfigL(CCommsDatIapView* aIapView, TUint32 aOrder, ESock::RMetaExtensionContainer& aMec)
       
   301     {
       
   302 	TLanIp4Provision* ip4Provision = new (ELeave) TLanIp4Provision;
       
   303 	CleanupStack::PushL(ip4Provision);
       
   304 
       
   305 	ip4Provision->SetOrder(aOrder);
       
   306 
       
   307 	// Read IP address configuration parameters
       
   308 	TBool serverRequired;
       
   309 	aIapView->GetBoolL(KCDTIdLANIpAddrFromServer, serverRequired);
       
   310 
       
   311 	TUint32 addr;
       
   312 	TInt err;
       
   313 
       
   314 	ip4Provision->SetLocalAddr(KInetAddrNone);
       
   315 	ip4Provision->SetNetMask(KInetAddrNone);
       
   316 	ip4Provision->SetDefGateway(KInetAddrNone);
       
   317 
       
   318 	if (!serverRequired)
       
   319 		{
       
   320 		GetIp4AddrL(aIapView, KCDTIdLANIpAddr, addr);
       
   321   		ip4Provision->SetLocalAddr(addr);
       
   322 		err = GetIp4Addr(aIapView, KCDTIdLANIpNetMask, addr);
       
   323 		if (err == KErrNone)
       
   324 			{
       
   325 			ip4Provision->SetNetMask(addr);
       
   326 			}
       
   327 
       
   328 		err = GetIp4Addr(aIapView, KCDTIdLANIpGateway, addr);
       
   329 		if (err == KErrNone)
       
   330 		    {
       
   331 		    ip4Provision->SetDefGateway(addr);
       
   332 		    }
       
   333 		else if (err == KErrNotFound || err == KErrArgument)
       
   334 		    {
       
   335 		    ip4Provision->SetDefGateway(ip4Provision->LocalAddr());
       
   336 		    }
       
   337 		else
       
   338 		    {
       
   339 		    User::Leave(err);
       
   340 		    }
       
   341 
       
   342 		// Because CommDB doesn't define a Broadcast Address field, we must
       
   343 		// calculate the broadcast address. This is based on the localAddr
       
   344 		// and the netMask.
       
   345 
       
   346 		TInetAddr localAddr(ip4Provision->LocalAddr(), 0);
       
   347 		TInetAddr netMask(ip4Provision->NetMask(), 0);
       
   348 		TInetAddr broadcast;
       
   349 		broadcast.SubNetBroadcast(ip4Provision->LocalAddr(), ip4Provision->NetMask());
       
   350 		ip4Provision->SetBroadcastAddr(broadcast.Address());
       
   351    		}
       
   352 
       
   353 	ip4Provision->SetPrimaryDns(KInetAddrNone);
       
   354 	ip4Provision->SetSecondaryDns(KInetAddrNone);
       
   355 
       
   356 	aIapView->GetBoolL(KCDTIdLANIpDNSAddrFromServer, serverRequired);
       
   357   	if (!serverRequired)
       
   358   		{
       
   359   		err = GetIp4Addr(aIapView, KCDTIdLANIpNameServer1, addr);
       
   360   		if (err == KErrNone)
       
   361   		    {
       
   362   		    ip4Provision->SetPrimaryDns(addr);
       
   363 		    err = GetIp4Addr(aIapView, KCDTIdLANIpNameServer2, addr);
       
   364 		    if (err == KErrNone)
       
   365 		        {
       
   366 		        ip4Provision->SetSecondaryDns(addr);
       
   367 		        }
       
   368   		    }
       
   369 
       
   370   		if (err != KErrNone && err != KErrNotFound && err != KErrArgument)
       
   371   		    {
       
   372   		    User::Leave(err);
       
   373   		    }
       
   374      	}
       
   375 
       
   376 	// Append the provisioning object to the CAccessPointConfig array
       
   377   	aMec.AppendExtensionL(ip4Provision);
       
   378 	CleanupStack::Pop(ip4Provision);
       
   379     }
       
   380 
       
   381 
       
   382 void CEthMetaConnectionProvider::ProvisionIp6ConfigL(CCommsDatIapView* aIapView, TUint32 aOrder, ESock::RMetaExtensionContainer& aMec)
       
   383     {
       
   384 	TLanIp6Provision* ip6Provision = new (ELeave) TLanIp6Provision;
       
   385 	CleanupStack::PushL(ip6Provision);
       
   386 
       
   387 	ip6Provision->SetOrder(aOrder);
       
   388 
       
   389 	// Determine whether static DNS configuration is required.
       
   390 	TBool dynamicDns = ETrue;
       
   391 
       
   392 	// By default, Ensure that static DNS addresses are set as unspecified,
       
   393 	// so they are not used in Control(KSoIfConfig).
       
   394 	ip6Provision->SetPrimaryDns(KInet6AddrNone);
       
   395 	ip6Provision->SetSecondaryDns(KInet6AddrNone);
       
   396 
       
   397 	// Ignore any errors from reading this field - default to dynamicDns = ETrue
       
   398 	(void) aIapView->GetBool(KCDTIdLANIp6DNSAddrFromServer, dynamicDns);
       
   399 
       
   400 	if (!dynamicDns)
       
   401 		{
       
   402 		// Read static DNS addresses
       
   403 		TInt err;
       
   404 		TIp6Addr addr6;
       
   405   		err = GetIp6Addr(aIapView, KCDTIdLANIp6NameServer1, addr6);
       
   406   		if (err == KErrNone)
       
   407   		    {
       
   408   		    ip6Provision->SetPrimaryDns(addr6);
       
   409 		    err = GetIp6Addr(aIapView, KCDTIdLANIp6NameServer2, addr6);
       
   410 		    if (err == KErrNone)
       
   411 		        {
       
   412 		        ip6Provision->SetSecondaryDns(addr6);
       
   413 		        }
       
   414   		    }
       
   415 
       
   416   		if (err != KErrNone && err != KErrNotFound && err != KErrArgument)
       
   417   		    {
       
   418   		    User::Leave(err);
       
   419   		    }
       
   420 		}
       
   421 
       
   422 	// Append the provisioning object to the CAccessPointConfig array
       
   423 	aMec.AppendExtensionL(ip6Provision);
       
   424 	CleanupStack::Pop(ip6Provision);
       
   425     }
       
   426 
       
   427