|
1 // Copyright (c) 1997-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 // Implementation CLanIp4Bearer class, a derived from CLanxBearer. |
|
15 // History |
|
16 // 15/11/01 Started by Julian Skidmore. |
|
17 // 11/03 Refactored as part of DHCP relocation work |
|
18 // |
|
19 // |
|
20 |
|
21 /** |
|
22 @file |
|
23 */ |
|
24 |
|
25 #include <in_sock.h> // Header is retained, but in_sock.h is modified for ipv6 |
|
26 #include <in_pkt.h> |
|
27 #include <in6_if.h> |
|
28 #include <nifvar.h> |
|
29 #include <comms-infras/connectionsettings.h> |
|
30 #include "CLanIp4Bearer.h" |
|
31 #include "arp_hdr.h" |
|
32 #include <commdb.h> |
|
33 #include <cdblen.h> |
|
34 #include "EthProto.h" |
|
35 #include "eth_log.h" |
|
36 #include "ProtocolHeaders.h" |
|
37 #include <comms-infras/es_protbinder.h> |
|
38 #include "EthProvision.h" |
|
39 |
|
40 using namespace ESock; |
|
41 |
|
42 /** |
|
43 Required ConstructL() method. Performs the following: |
|
44 " Sets a unique name for this binder instance in the iIfName field - "eth6[0x%x]" where "%x" |
|
45 is the hexadecimal address of the "this" object. |
|
46 " Reads the IP Interface Settings using ReadIPInterfaceSettingsL(). |
|
47 " Reads CommDb settings (e.g. IPv6 static DNS configuration) from the LAN Service Table via |
|
48 ReadCommDbLanSettingsL(). |
|
49 */ |
|
50 void CLanIp4Bearer::ConstructL() |
|
51 { |
|
52 iIfName.Format(_L("eth[0x%08x]"), this); |
|
53 // ReadCommDbLanSettingsL() moved from here to point when provisioning information received |
|
54 } |
|
55 |
|
56 TInt CLanIp4Bearer::Control(TUint aLevel, TUint aName, TDes8& aOption) |
|
57 { |
|
58 if ((aLevel==KCOLInterface) || (aLevel==KSOLInterface)) |
|
59 { |
|
60 switch (aName) |
|
61 { |
|
62 case KSoIfHardwareAddr: |
|
63 { |
|
64 if (static_cast<TUint>(aOption.Length())<sizeof(TSoIfHardwareAddr)) |
|
65 { |
|
66 return KErrArgument; |
|
67 } |
|
68 TSoIfHardwareAddr& opt=*(TSoIfHardwareAddr*)aOption.Ptr(); |
|
69 opt.iHardwareAddr.SetFamily(1); // Set up the address family type |
|
70 opt.iHardwareAddr.SetPort(1); // Hardware Type, has to be returned in the port field... |
|
71 opt.iHardwareAddr.SetLength(8); // The length so far, 4 for family + 4 for port... |
|
72 opt.iHardwareAddr.Append(Link()->MacAddress()); |
|
73 return KErrNone; |
|
74 } |
|
75 default: |
|
76 return KErrNotSupported; |
|
77 } |
|
78 } |
|
79 return KErrNotSupported; // keep compiler happy - all returns covered by switch above |
|
80 } |
|
81 |
|
82 |
|
83 _LIT8(KEtherMACMultiCastPrefix,"\x01\x00\x5e"); |
|
84 |
|
85 /** |
|
86 Call down from the Protocol |
|
87 Real Protocol data is in the second MBuf of the RMBufChain |
|
88 The info block contains important addressing information; |
|
89 If the destination address family is KAfInet, |
|
90 then we must generate the hardware destination address |
|
91 since it could not be resolved by ARP. It is probably |
|
92 a broadcast or multicast address. |
|
93 Otherwise, |
|
94 the destination address contains a resolved hardware |
|
95 address and we only need to shift the address bytes |
|
96 for the lower layer. |
|
97 Caller Flow controls off if the return to this method is <= 0 |
|
98 @param aPdu A reference to the packet to be sent (really an RMBufPkt) |
|
99 @param aSource A pointer to the source protocol. |
|
100 @return The no. of bytes send. |
|
101 */ |
|
102 MLowerDataSender::TSendResult CLanIp4Bearer::Send(RMBufChain& aPdu) |
|
103 { |
|
104 // Check that we are allowed to send data |
|
105 if (!Link()->BearerIsActive(this)) |
|
106 { |
|
107 aPdu.Free(); |
|
108 return ESendBlocked; |
|
109 } |
|
110 |
|
111 RMBufPktInfo* info = RMBufPacket::PeekInfoInChain(aPdu); |
|
112 |
|
113 if (info->iDstAddr.Family() == KAfInet) |
|
114 { |
|
115 // Create hardware addresses for multicast and broadcast destinations |
|
116 |
|
117 if (TInetAddr::Cast(info->iDstAddr).IsMulticast()) |
|
118 { |
|
119 TInetAddr multicastDest(TInetAddr::Cast(info->iDstAddr).Address() & KArpMacMulticastMask, 0); |
|
120 info->iDstAddr.Copy(KEtherMACMultiCastPrefix); |
|
121 TUint32 addr = multicastDest.Address(); |
|
122 info->iDstAddr.Append((addr&0xff0000)>>16); |
|
123 info->iDstAddr.Append((addr&0xff00)>>8); |
|
124 info->iDstAddr.Append((addr&0xff)); |
|
125 } |
|
126 else |
|
127 // Catch all types of broadcast addresses (including subnet) |
|
128 { |
|
129 for(TUint ix = 0; ix < KMACByteLength; ix++) |
|
130 { |
|
131 info->iDstAddr[ix] = 0xff; |
|
132 } |
|
133 } |
|
134 } |
|
135 else |
|
136 // Shift the already resolved hardware address to the beginning |
|
137 { |
|
138 for(TUint ix = 0; ix < KMACByteLength; ix++) |
|
139 { |
|
140 info->iDstAddr[ix] = info->iDstAddr[ix + KDestAddrOffset]; |
|
141 } |
|
142 } |
|
143 |
|
144 TInt ret = Link()->FrameSend(aPdu, NULL, (TUint)info->iProtocol == KProtocolArp ? KArpFrameType : KIPFrameType); |
|
145 __FLOG_STATIC(KEther802LogTag1, KEthLogTag2, _L("CLanIp4Bearer::Send() sent packet")); |
|
146 return static_cast<MLowerDataSender::TSendResult>(ret); |
|
147 } |
|
148 |
|
149 /** |
|
150 StartSending notifies the protocol that this object is ready to transmit and process data. |
|
151 @param aProtocol A pointer to the object which signalled it is ready to StartSending. |
|
152 */ |
|
153 void CLanIp4Bearer::StartSending(CProtocolBase* aProtocol) |
|
154 { |
|
155 __FLOG_STATIC(KEther802LogTag1, KEthLogTag2, _L("CLanIp4Bearer::StartSending()")); |
|
156 CLanxBearer::StartSending(aProtocol); |
|
157 } |
|
158 |
|
159 /** |
|
160 WantsProtocol, takes an ethernet aProtocolCode code and the initial part of the packet's |
|
161 payload as input and returns ETrue if the bearer wants the packet of this type of protocol |
|
162 and payload, or EFalse otherwise. CLanIp4Bearer wants the protocol if it is an Arp message or |
|
163 an Ip4 protocol (an Ip protocol, whose Version field == 4). WantsProtocol also sets |
|
164 iArpMsgNext to ETrue if the protocol was Arp or EFalse otherwise. |
|
165 @param aProtocolCode The Ethernet protocol Type. |
|
166 @param aPayload A pointer to the beginning of the packet payload. |
|
167 @return sets iArpMsgNext to ETrue if the protocol was Arp or EFalse otherwise. |
|
168 */ |
|
169 TBool CLanIp4Bearer::WantsProtocol(TUint16 aProtocolCode,const TUint8* aPayload) |
|
170 { |
|
171 return ((aProtocolCode==KIPProtocol && (aPayload[0]>>4)==KIP4Protocol) || (aProtocolCode==KArpFrameType)) ? ETrue:EFalse; |
|
172 } |
|
173 |
|
174 /** |
|
175 Process processes a packet received from the LinkLayer. |
|
176 @param aPdu The Packet to be sent (actually an RMBufPkt). |
|
177 @param aLLC Unclear. |
|
178 */ |
|
179 void CLanIp4Bearer::Process(RMBufChain& aPdu, TAny* aLLC) |
|
180 { |
|
181 __FLOG_STATIC(KEther802LogTag1, KEthLogTag2, _L("CLanIp4Bearer::Process(RMBufChain& aPdu,TAny* aLLC)")); |
|
182 |
|
183 if (iUpperReceiver) |
|
184 { |
|
185 // Set the protocol type in the info header if ARP packet |
|
186 RMBufPktInfo* info = RMBufPacket::PeekInfoInChain(aPdu); |
|
187 if (reinterpret_cast<TUint32>(aLLC) == KArpFrameType) |
|
188 { |
|
189 __FLOG_STATIC(KEther802LogTag1, KEthLogTag2, _L("CLanIp4Bearer::Process() - Received ARP packet")); |
|
190 info->iProtocol = KProtocolArp; |
|
191 } |
|
192 |
|
193 __FLOG_STATIC(KEther802LogTag1, KEthLogTag2, _L("CLanIp4Bearer::Process() - calling iProtocol->Process(aPdu,..)")); |
|
194 iUpperReceiver->Process(aPdu); |
|
195 } |
|
196 else |
|
197 { |
|
198 aPdu.Free(); |
|
199 } |
|
200 } |
|
201 |
|
202 /** |
|
203 ReadCommDbLanSettingsL() reads CommDb settings from the LAN Service Table. In particular, it |
|
204 reads the fields related to IPv4 Static DNS configuration. The LAN_IP4_DNS_ADDR_FROM_SERVER |
|
205 field is a boolean that indicates whether IPv4 Static DNS configuration is required or not. |
|
206 If FALSE, then static configuration is required. In this case, the IPv4 primary and secondary |
|
207 DNS server addresses are read from the CommDb fields LAN_IP4_NAME_SERVER1 and LAN_IP4_NAME_SERVER2 |
|
208 and stored in the iPrimaryDns and iSecondaryDns data members. They are later presented to |
|
209 the TCP/IP stack when the Control() method is called with the KSoIfConfig option. |
|
210 */ |
|
211 void CLanIp4Bearer::ReadCommDbLanSettingsL() |
|
212 { |
|
213 ASSERT(iProvision); |
|
214 |
|
215 iLocalAddr = iProvision->LocalAddr(); |
|
216 iNetMask = iProvision->NetMask(); |
|
217 iDefGateway = iProvision->DefGateway(); |
|
218 iPrimaryDns = iProvision->PrimaryDns(); |
|
219 iSecondaryDns = iProvision->SecondaryDns(); |
|
220 } |
|
221 |
|
222 |
|
223 TInt CLanIp4Bearer::GetConfig(TBinderConfig& aConfig) |
|
224 { |
|
225 TBinderConfig4* config = TBinderConfig::Cast<TBinderConfig4>(aConfig); |
|
226 |
|
227 if(config == NULL) |
|
228 { |
|
229 return KErrNotSupported; |
|
230 } |
|
231 |
|
232 config->iFamily = KAfInet; /* KAfInet / KAfInet6 - selects TBinderConfig4/6 */ |
|
233 |
|
234 config->iInfo.iFeatures = KIfCanBroadcast | KIfCanMulticast | KIfNeedsND; /* Feature flags */ |
|
235 config->iInfo.iMtu = Link()->Mtu(); /* Maximum transmission unit. */ |
|
236 config->iInfo.iRMtu = Link()->Mtu(); /* Maximum transmission unit for receiving. */ |
|
237 config->iInfo.iSpeedMetric = Link()->SpeedMetric(); /* approximation of the interface speed in Kbps. */ |
|
238 |
|
239 config->iAddress.SetAddress(iLocalAddr); /* Interface IP address. */ |
|
240 config->iNetMask.SetAddress(iNetMask); /* IP netmask. */ |
|
241 config->iBrdAddr.SetAddress(iBroadcastAddr); /* IP broadcast address. */ |
|
242 config->iDefGate.SetAddress(iDefGateway); /* IP default gateway or peer address (if known). */ |
|
243 config->iNameSer1.SetAddress(iPrimaryDns); /* IP primary name server (if any). */ |
|
244 config->iNameSer2.SetAddress(iSecondaryDns); /* IP secondary name server (if any). */ |
|
245 |
|
246 return KErrNone; |
|
247 } |
|
248 |
|
249 const TDesC8& CLanIp4Bearer::ProtocolName() const |
|
250 /** |
|
251 Return the protocol name of this bearer |
|
252 |
|
253 Called from CLANLinkCommon |
|
254 */ |
|
255 { |
|
256 _LIT8(KProtocolName, "ip"); |
|
257 return KProtocolName(); |
|
258 } |
|
259 |
|
260 void CLanIp4Bearer::SetProvisionL(const Meta::SMetaData* aProvision) |
|
261 { |
|
262 if (iProvision == NULL) |
|
263 { |
|
264 iProvision = static_cast<const TLanIp4Provision*>(aProvision); |
|
265 ReadCommDbLanSettingsL(); |
|
266 } |
|
267 } |
|
268 |