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