linklayerprotocols/ethernetnif/INC/EthProto.h
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2003-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 // Historical Note: this file was originally copied from networking/ether802/inc/ethinter.h.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent 
       
    21 */
       
    22 
       
    23 #if !defined(__ETHER802_H__)
       
    24 #define __ETHER802_H__
       
    25 
       
    26 #include <networking/pktdrv.h>
       
    27 #include <comms-infras/nifif.h> //needed for cnififfactory.
       
    28 #include <in_sock.h>
       
    29 
       
    30 #include <comms-infras/commsdebugutility.h>
       
    31 #include <comms-infras/ss_subconnflow.h>
       
    32 #include <comms-infras/ss_flowbinders.h>
       
    33 #include <networking/pktdrv_internal.h>
       
    34 
       
    35 #ifdef __FLOG_ACTIVE
       
    36 #define TCPDUMP_LOGGING // log all ethernet frame in pcap format
       
    37 #endif // __FLOG_ACTIVE
       
    38 
       
    39 class TLanLinkProvision;
       
    40 class TLanIp4Provision;
       
    41 class TLanIp6Provision;
       
    42 
       
    43 const TInt KUidEthintNifmanInterface = 0x10000541;
       
    44 const TInt KAuthenticationComplete = 5;
       
    45 const TInt KEtherMaxFrame = 1492;
       
    46 const TInt KEtherSpeedInKbps = 10000;
       
    47 const TInt KProtocolAddressSize=4; //Address size of IP4
       
    48 const TInt KNetworkAddressSize=6; //Address size for Ether MAC
       
    49 const TInt KArpMacMulticastMask=0x7FFFFF;
       
    50 
       
    51 
       
    52 enum TEtherHeaderType{EStandardEthernet, ELLCEthernet}; // Ethernet header types
       
    53 
       
    54 /*******************************************************************************
       
    55 * A quick intro to the Ethernet packet format:
       
    56 *
       
    57 * A plain frame looks like this:
       
    58 *
       
    59 * struct EtherFrame {
       
    60 *   TUint64 iDestAddr, iSrcAddr;
       
    61 *   TUint16 iType; // Denotes the Protocol Type == Service Access Point == SAP
       
    62 *   TUint8  iData[1500]; // Payload.
       
    63 * };
       
    64 *
       
    65 * iType denotes the type of the payload, 0x0800 denotes IP.
       
    66 *                                        0x0806 denotes ARP.
       
    67 *                                        >=Min, <=1500 denotes LLC.
       
    68 * A frame may also contain an extra 'LLC' field which encapsulates the original
       
    69 * payload in a 5 byte header. The LLC field is somewhat complex, but here we
       
    70 * confine ourselves to the LLC-SNAP variant.
       
    71 *
       
    72 * struct EtherLLCFrame {
       
    73 *   TUint64 iDestAddr, iSrcAddr;
       
    74 *   TUint16 iLen; // Denotes the Len and must be <=1500 so as not to conflict
       
    75 *                 // With iType interpretation.
       
    76 *   TUint8 iDSAP=0xAA; // Which denotes an LLC-SNAP frame.
       
    77 *   TUint8 iSSAP=0xAA; // Which denotes an LLC-SNAP frame.
       
    78 *   TUint8 iCTRL=3;    // Which denotes an LLC-SNAP frame encapsulated by
       
    79 *                      // Ethernet.
       
    80 *   TUint24 OUI=iDstAddr&0xffffff; // 0 is also a valid value.
       
    81 *   TUint16 iType; // The actual iType as described earlier.
       
    82 *   TUint8  iData[1492]; // Payload.
       
    83 * };
       
    84 *
       
    85 *******************************************************************************/
       
    86 
       
    87 _LIT(ETHER802_CONFIG_FILENAME, "ether802.ini");
       
    88 _LIT(KInterfaceSection,"interface_settings");
       
    89 _LIT(KEthernetSection,"ethernet_settings");
       
    90 
       
    91 const TUint32 KDefaultSpeedMetricSetting = 0;
       
    92 const TUint32 KDefaultMtuSetting = 1500;
       
    93 const TUint32 KMACByteLength = 6;
       
    94 const TUint32 KDestAddrOffset = 8;
       
    95 
       
    96 // For the purposes of Wants, we define the protocol code as a pair:
       
    97 // EtherType, IPType... we don't know the link layer above is definitely
       
    98 // using IP packets...
       
    99 const TUint16 KIPFrameType = 0x800;
       
   100 const TUint16 KIP6FrameType = 0x86DD;
       
   101 const TUint16 KArpFrameType= 0x806;
       
   102 const TUint8 KLLC_SNAP_DSAP = 0xAA;
       
   103 const TUint8 KLLC_SNAP_SSAP = 0xAA;
       
   104 const TUint8 KLLC_SNAP_CTRL = 3;
       
   105 
       
   106 /**
       
   107 @internalComponent
       
   108 */
       
   109 struct TEtherFrame
       
   110 {
       
   111 	TUint16 GetType() const { return BigEndian::Get16((TUint8*)&iTypeLen); }
       
   112 	TUint16 iDestAddr[3];
       
   113 	TUint16 iSrcAddr[3];
       
   114 	TUint16 iTypeLen; // Denotes the Protocol Type <=> Service Access Point <=> SAP
       
   115 	TUint8  iData[KDefaultMtuSetting]; // Payload.
       
   116 };
       
   117 
       
   118 const TUint KEtherHeaderSize=14;
       
   119 const TUint KEtherLLCHeaderSize=KEtherHeaderSize+8;
       
   120 
       
   121 /**
       
   122 @internalComponent
       
   123 */
       
   124 struct TEtherLLCFrame
       
   125 {
       
   126 	TUint16 GetType() const { return (TUint16)((iTypeHi<<8)|iTypeLo); }
       
   127 	void SetType(TUint16 aType)
       
   128 		{
       
   129 		iTypeHi=(TUint8)(aType>>8); iTypeLo=(TUint8)(aType&0xff);
       
   130 		}
       
   131 	void SetDestAddr( TDesC8& aDest);
       
   132 	void SetSrcAddr( TDesC8& aSrc);
       
   133 	void SetOUI( TUint32 aOUI);
       
   134 	TUint16 iDestAddr[3];
       
   135 	TUint16 iSrcAddr[3];
       
   136 	TUint16 iTypeLen;
       
   137 	TUint8 iDSAP; // Which denotes an LLC-SNAP frame.
       
   138 	TUint8 iSSAP; // Which denotes an LLC-SNAP frame.
       
   139 	TUint8 iCtrl;    // Which denotes an LLC-SNAP frame encapsulated by
       
   140 	// Ethernet.
       
   141 	TUint8 OUI[3];
       
   142 	TUint8 iTypeHi;
       
   143 	TUint8 iTypeLo; // The actual iType as described earlier.
       
   144 	TUint8 iData[1492]; // Payload.
       
   145 };
       
   146 
       
   147 class CLanxBearer;
       
   148 typedef CArrayPtrFlat<CLanxBearer> CLanxBearerPtrArray;
       
   149 
       
   150 class CEthLog;
       
   151 
       
   152 /**
       
   153 Main LAN Nif Control object creates lower layer objects :-
       
   154 Packet Driver & EtherXXX
       
   155 Calls back to protocol (iProtocol) and nifman (iNotifier in CNifIfBase)
       
   156 Calls down to EtherXX (iMacLayer)
       
   157 @internalComponent
       
   158 */
       
   159 class CLANLinkCommon : public ESock::CSubConnectionFlowBase, public ESock::MFlowBinderControl
       
   160 {
       
   161 	friend class CPktDrvBase;
       
   162 public:
       
   163 	enum TAction
       
   164 		{
       
   165 		EReconnect,
       
   166 		EDisconnect
       
   167 		};
       
   168 	IMPORT_C static CLANLinkCommon* NewL(ESock::CSubConnectionFlowFactoryBase& aFactory, const Messages::TNodeId& aSubConnId, ESock::CProtocolIntfBase* aProtocolIntf);
       
   169 	IMPORT_C CLANLinkCommon(ESock::CSubConnectionFlowFactoryBase& aFactory, const Messages::TNodeId& aSubConnId, ESock::CProtocolIntfBase* aProtocolIntf);
       
   170 	IMPORT_C virtual ~CLANLinkCommon();
       
   171 	IMPORT_C void ConstructL();
       
   172 
       
   173 	// from MFlowBinderControl
       
   174 	IMPORT_C virtual ESock::MLowerControl* GetControlL(const TDesC8& aProtocol);
       
   175 	IMPORT_C virtual ESock::MLowerDataSender* BindL(const TDesC8& aProtocol, ESock::MUpperDataReceiver* aReceiver, ESock::MUpperControl* aControl);
       
   176 	IMPORT_C virtual void Unbind(ESock::MUpperDataReceiver* aReceiver, ESock::MUpperControl* aControl);
       
   177 	virtual ESock::CSubConnectionFlowBase* Flow()
       
   178     	{
       
   179     	return this;
       
   180     	}
       
   181 
       
   182 	// from Messages::ANode
       
   183 	IMPORT_C virtual void ReceivedL(const Messages::TRuntimeCtxId& aSender, const Messages::TNodeId& aRecipient, Messages::TSignatureBase& aMessage);
       
   184 
       
   185 	// Dispatch functions for messages received from SCPR.
       
   186 
       
   187 	void StartFlowL();
       
   188 	void CancelStartFlow();
       
   189 	void StopFlow(TInt aError);
       
   190 	void SubConnectionGoingDown();
       
   191 	void SubConnectionError(TInt aError);
       
   192 	void BindToL(Messages::TNodeId& aCommsBinder);
       
   193 
       
   194 	void Destroy();
       
   195 
       
   196 	// Utility functions for sending messages to SCPR.
       
   197 	void PostProgressMessage(TInt aStage, TInt aError);
       
   198 	void PostDataClientStartedMessage();
       
   199 	void PostFlowDownMessage(TInt aError);
       
   200 	void PostFlowGoingDownMessage(TInt aError, MNifIfNotify::TAction aAction);
       
   201 	void MaybePostDataClientIdle();
       
   202 
       
   203 	// CSubConnectionFlowBase
       
   204 	MFlowBinderControl* DoGetBinderControlL()
       
   205     	{
       
   206     	return this;
       
   207     	}
       
   208 
       
   209 	//
       
   210 	// Upcalls from the packet driver
       
   211 	//
       
   212 	IMPORT_C void Process(RMBufChain& aPdu, TAny* aMAC=0);
       
   213 	IMPORT_C void ResumeSending(); // Flow Control unblocked
       
   214 	IMPORT_C void LinkLayerUp(); // Notify the Protocol that the line is up
       
   215 	IMPORT_C void LinkLayerDown(TInt aError, TAction aAction); // Notify the Protocol that the line is down
       
   216 	IMPORT_C void FoundMACAddrL(); // Added for interfaces that take a while to find their MAC addrs
       
   217 
       
   218 	IMPORT_C TInt ReadInt(const TDesC& aField, TUint32& aValue);
       
   219     IMPORT_C TInt WriteInt(const TDesC& aField, TUint32 aValue);
       
   220     IMPORT_C TInt ReadDes(const TDesC& aField, TDes8& aValue);
       
   221     IMPORT_C TInt ReadDes(const TDesC& aField, TDes16& aValue);
       
   222     IMPORT_C TInt WriteDes(const TDesC& aField, const TDesC8& aValue);
       
   223 	IMPORT_C TInt WriteDes(const TDesC& aField, const TDesC16& aValue);
       
   224 	IMPORT_C TInt ReadBool(const TDesC& aField, TBool& aValue);
       
   225     IMPORT_C TInt WriteBool(const TDesC& aField, TBool aValue);
       
   226 	IMPORT_C void IfProgress(TInt aStage, TInt aError);
       
   227 	IMPORT_C void IfProgress(TSubConnectionUniqueId aSubConnectionUniqueId, TInt aStage, TInt aError);
       
   228 	IMPORT_C void NifEvent(TNetworkAdaptorEventType aEventType, TUint aEvent, const TDesC8& aEventData, TAny* aSource=0);
       
   229 
       
   230 	TUint Mtu() const;
       
   231 
       
   232 	TUint SpeedMetric() const {return KEtherSpeedInKbps; }
       
   233 	TEtherHeaderType EtherType() const { return iEtherType; }
       
   234 	const TBuf8<KMACByteLength>& MacAddress() const;
       
   235 
       
   236 	TInt FrameSend(RMBufChain& aPdu, TAny* aSource=0, TUint16 aType=KIPFrameType);
       
   237 
       
   238 	void SetAllowedBearer(CLanxBearer* aBearer);
       
   239     TBool BearerIsActive(CLanxBearer* aBearer);
       
   240 
       
   241 private:
       
   242 	//
       
   243 	// Configuration methods
       
   244 	TBool ReadMACSettings();
       
   245 	void ReadEthintSettingsL();
       
   246 	TInt EtherFrame(RMBufChain &aChain, TUint16 aType=KIPFrameType);
       
   247 	TBool CheckMac(TDes8& aMacAddr); // checks that the packet driver has returned a valid MAC address,
       
   248 	//New.
       
   249 	TInt GetProtocolType(RMBufChain& aPdu, TUint16& aEtherType, TUint8*& aPayloadPtr, TUint& aEtherHeaderSize) const;
       
   250 	//
       
   251 	// Driver managment
       
   252 	void LoadPacketDriverL();
       
   253 
       
   254 	// Search CLanxBearer array by various keys (used in bind/unbind/provisioning)
       
   255 	CLanxBearer* FindBearerByProtocolName(const TDesC8& aProtocol, TInt& aIndex) const;
       
   256 	CLanxBearer* FindBearerByUpperControl(const ESock::MUpperControl* aUpperControl, TInt& aIndex) const;
       
   257 
       
   258 	// Provisioning
       
   259 	void ProvisionConfig(const ESock::RMetaExtensionContainerC& aConfigData);
       
   260 	void ProvisionConfigL();
       
   261 	void ProvisionBearerConfigL(const TDesC8& aName);
       
   262 	const TLanLinkProvision& LinkProvision();
       
   263 
       
   264 protected:
       
   265 	// Creates packet driver methods
       
   266 	CPktDrvFactory* DoCreateDriverFactoryL(TUid aUid2,const TDesC& aFilename);
       
   267 	CPacketDriverOwner* iPktDrvOwner; // We create this but do not own it
       
   268 
       
   269 	// This class creates the packet driver and binds it to the mac layer
       
   270 	CPktDrvBase*		iPktDrv;
       
   271 
       
   272 	//MAC Address
       
   273 	TBuf8<KMACByteLength> iMacAddr;
       
   274 	//indicates if iMacAddr contains a valid Mac address
       
   275 	TBool iValidMacAddr;
       
   276 
       
   277 	TEtherHeaderType	iEtherType;
       
   278 
       
   279 	// Bearer List:
       
   280 	CLanxBearerPtrArray  *iBearers;
       
   281 	CLanxBearer			 *iOnlyThisBearer;
       
   282 
       
   283 	#ifdef TCPDUMP_LOGGING
       
   284 	private:
       
   285 		CEthLog* iLogger;
       
   286 	#endif // TCPDUMP_LOGGING
       
   287 
       
   288 	// Provisioning related
       
   289 	const TLanLinkProvision* iLanLinkProvision;		// link provisioning information from SCPR
       
   290 	const TLanIp4Provision* iLanIp4Provision;		// ip4 provisioning information from SCPR
       
   291 	const TLanIp6Provision* iLanIp6Provision;		// ip6 provisioning information from SCPR
       
   292 	TBool iStopRequested;
       
   293 
       
   294 	TInt iSavedError;								// saved errors from processing TProvisionConfig message
       
   295 
       
   296 	enum TMeshMashineFlowState
       
   297       	{
       
   298       	EStopped,
       
   299       	EStarting,
       
   300       	EStarted,
       
   301       	EStopping,
       
   302       	};
       
   303 	TMeshMashineFlowState iMMState;
       
   304 };
       
   305 
       
   306 inline const TBuf8<KMACByteLength>& CLANLinkCommon::MacAddress() const
       
   307 {
       
   308 	return iMacAddr;
       
   309 }
       
   310 
       
   311 
       
   312 
       
   313 #endif