networkcontrol/ipnetworklayer/src/nif4.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2005-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 // CNifIfBase and CProtocolBase shim layer functionality
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file nif.cpp
       
    20 */
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <comms-infras/ss_subconnflow.h>
       
    24 #include <comms-infras/ss_protflow.h>
       
    25 
       
    26 #include "in_sock.h"
       
    27 #include "in_iface.h"
       
    28 #include "in6_if.h"
       
    29 
       
    30 #include "nif4.h"
       
    31 #include "notify.h"
       
    32 #include "panic.h"
       
    33 #include "IPProtoDeMux.h"
       
    34 
       
    35 using namespace ESock;
       
    36 
       
    37 //
       
    38 // CIPShimIfBase methods //
       
    39 //
       
    40 
       
    41 CIPShimIfBase4* CIPShimIfBase4::NewL(const TDesC8& aProtocolName)
       
    42 	{
       
    43 	CIPShimIfBase4* p = new (ELeave) CIPShimIfBase4(aProtocolName);
       
    44 	CleanupStack::PushL(p);
       
    45 	p->ConstructL();
       
    46 	CleanupStack::Pop(p);
       
    47 	return p;
       
    48 	}
       
    49 
       
    50 CIPShimIfBase4::CIPShimIfBase4(const TDesC8& aProtocolName)
       
    51   : CIPShimIfBase(aProtocolName)
       
    52 	{
       
    53 	iConfig4.iFamily = KAFUnspec;
       
    54 	}
       
    55 
       
    56 TInt CIPShimIfBase4::ServiceInfoControl(TDes8& aOption, TUint aName)
       
    57 /**
       
    58 Service KSoIfInfo/KSoIfInfo6 calls from upper protocol
       
    59 */
       
    60 	{
       
    61 	TBinderInfo* ourInfo = NULL;
       
    62 	// Validate the size of structure passed in
       
    63 	switch (aName)
       
    64 		{
       
    65 	case KSoIfInfo:
       
    66 		ASSERT(aOption.Length() == sizeof(TSoIfInfo));
       
    67 		if (iConfig4.iFamily != KAfInet)
       
    68 			{
       
    69 			return KErrNotSupported;
       
    70 			}
       
    71 		ourInfo = &iConfig4.iInfo;
       
    72 		break;
       
    73 	case KSoIfInfo6:
       
    74 		return KErrNotSupported;
       
    75 	
       
    76 	default:
       
    77 		Panic(EBadInfoControlOption);
       
    78 		}
       
    79 
       
    80 	TUint8* ptr = const_cast<TUint8*>(aOption.Ptr());
       
    81 	TSoIfInfo& info = reinterpret_cast<TSoIfInfo&>(*ptr);
       
    82 
       
    83 	// Fill in iFeatures, iMtu, iSpeedMetric
       
    84 	info.iFeatures = ourInfo->iFeatures;
       
    85 	info.iSpeedMetric = ourInfo->iSpeedMetric;
       
    86 	info.iMtu = ourInfo->iMtu;
       
    87 	
       
    88 	return KErrNone;
       
    89 	}
       
    90 
       
    91 TInt CIPShimIfBase4::ServiceConfigControl(TDes8& aOption)
       
    92 /**
       
    93 Service KSoIfConfig calls from upper protocol
       
    94 */
       
    95 	{
       
    96 	TUint8* ptr = const_cast<TUint8*>(aOption.Ptr());
       
    97 
       
    98 	TUint family = reinterpret_cast<TSoIfConfigBase&>(*ptr).iFamily;
       
    99 	
       
   100 	switch (family)
       
   101 		{
       
   102 	case KAfInet:					// IP4
       
   103 		{
       
   104 		ASSERT(aOption.Length() == sizeof(TSoInetIfConfig));
       
   105 		TSoInetIfConfig& cf = reinterpret_cast<TSoInetIfConfig&>(*ptr);
       
   106 		
       
   107 		if (iConfig4.iFamily != KAfInet)
       
   108 			{
       
   109 			return KErrNotSupported;
       
   110 			}
       
   111 		else 
       
   112 			{
       
   113 			cf.iConfig.iAddress = iConfig4.iAddress;
       
   114 			cf.iConfig.iNetMask = iConfig4.iNetMask;
       
   115 			cf.iConfig.iBrdAddr = iConfig4.iBrdAddr;
       
   116 			cf.iConfig.iDefGate = iConfig4.iDefGate;
       
   117 			cf.iConfig.iNameSer1 = iConfig4.iNameSer1;
       
   118 			cf.iConfig.iNameSer2 = iConfig4.iNameSer2;
       
   119 			}
       
   120 		}
       
   121 		break;
       
   122 		
       
   123 	default:
       
   124 		Panic(EBadConfigControlFamily);
       
   125 		break;
       
   126 		}
       
   127 		
       
   128 	return KErrNone;
       
   129 	}
       
   130 
       
   131 
       
   132 void CIPShimIfBase4::GetConfigFirstTime()
       
   133 /**
       
   134 Retrieve the IP4/IP6 configuration information from the lower binder, if
       
   135 we haven't already done so.
       
   136 */
       
   137 	{
       
   138 	if (iConfig4.iFamily == KAFUnspec)
       
   139 		{
       
   140 		TBinderConfig& config = iConfig4;
       
   141 		if(iProtoBinders[0]->iLowerControl->GetConfig(config) != KErrNone)
       
   142 			Panic(EBinderConfigNotSupported);
       
   143 
       
   144 		iConfig4.iFamily = config.iFamily;
       
   145 		ASSERT(iConfig4.iFamily == KAfInet);
       
   146 		}		
       
   147 	}