|
1 // Copyright (c) 2002-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 // tunnelnif.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <es_mbuf.h> |
|
19 //#include <flogger.h> |
|
20 |
|
21 #include <agenterrors.h> |
|
22 |
|
23 #include "tunnelnifvar.h" |
|
24 #include "tunnelBinders.h" |
|
25 #include <comms-infras/es_protbinder.h> |
|
26 #include "TunnelAgentHandler.h" |
|
27 #include <comms-infras/commsdebugutility.h> |
|
28 /* |
|
29 * This sections defines a whole load of constants etc... not very exciting |
|
30 */ |
|
31 #if defined (_DEBUG) |
|
32 #define LOG(a) a |
|
33 _LIT(KTunnelIfLogFolder, "tunnel"); |
|
34 _LIT(KTunnelIfLogFile, "tunnel"); |
|
35 #else |
|
36 #define LOG(a) |
|
37 #endif |
|
38 |
|
39 const TUint KConnNifConfig = (1 | KConnReadUserDataBit); |
|
40 |
|
41 CTunnelNcp::CTunnelNcp(CTunnelFlow& aFlow) |
|
42 : iFlow(&aFlow) |
|
43 { |
|
44 } |
|
45 |
|
46 // |
|
47 // from ESock::MLowerControl |
|
48 // |
|
49 |
|
50 TInt CTunnelNcp::GetName(TDes& aName) |
|
51 /** |
|
52 Return binder name. |
|
53 |
|
54 Called from upper layer. |
|
55 |
|
56 @param aName return descriptor filled in with binder name |
|
57 */ |
|
58 { |
|
59 aName.Copy(Info()->iIfName); |
|
60 return KErrNone; |
|
61 } |
|
62 |
|
63 TInt CTunnelNcp::BlockFlow(MLowerControl::TBlockOption /*aOption*/) |
|
64 { |
|
65 return KErrNotSupported; |
|
66 } |
|
67 |
|
68 // |
|
69 // Utility functions called from CTunnelFlow |
|
70 // |
|
71 |
|
72 MLowerDataSender* CTunnelNcp::Bind(MUpperDataReceiver* aUpperReceiver, MUpperControl* aUpperControl) |
|
73 /** |
|
74 * Binds TCP/IP protocol to Flow |
|
75 * |
|
76 * @param aUpperReceiver A pointer to Upper layer Receive class |
|
77 * @param aUpperControl A pointer to Upper layer control class |
|
78 */ |
|
79 { |
|
80 CTunnelNcpLog::Printf(_L("CTunnelNcp:\tBind()")); |
|
81 |
|
82 iUpperReceiver = aUpperReceiver; |
|
83 iUpperControl = aUpperControl; |
|
84 return this; |
|
85 } |
|
86 |
|
87 void CTunnelNcp::Unbind(MUpperDataReceiver* aUpperReceiver, MUpperControl* aUpperControl) |
|
88 { |
|
89 CTunnelNcpLog::Printf(_L("CTunnelNcp:\tUnbind()")); |
|
90 |
|
91 (void)aUpperReceiver; |
|
92 (void)aUpperControl; |
|
93 ASSERT(aUpperReceiver == iUpperReceiver); |
|
94 ASSERT(aUpperControl == iUpperControl); |
|
95 iUpperReceiver = NULL; |
|
96 iUpperControl = NULL; |
|
97 } |
|
98 |
|
99 void CTunnelNcp::StartSending() |
|
100 /** |
|
101 * Indicates to the protocol layer that the NIF is ready to send packets. |
|
102 * |
|
103 * @param aProtocol A pointer to a protocol |
|
104 */ |
|
105 { |
|
106 CTunnelNcpLog::Printf(_L("CTunnelNcp:\tStartSending()")); |
|
107 |
|
108 // Default implementation. |
|
109 // Uses iProtocol instead aProtocol. |
|
110 iUpperControl->StartSending(); |
|
111 } |
|
112 |
|
113 TBool CTunnelNcp::MatchesUpperControl(const ESock::MUpperControl* aUpperControl) |
|
114 { |
|
115 return iUpperControl == aUpperControl; |
|
116 } |
|
117 |
|
118 MLowerDataSender::TSendResult CTunnelNcp::Send(RMBufChain& aPdu) |
|
119 { |
|
120 CTunnelNcpLog::Printf(_L("Illegal CTunnelNcp::Send Called, Dropping packet")); |
|
121 aPdu.Free(); |
|
122 return MLowerDataSender::ESendAccepted; |
|
123 } |
|
124 |
|
125 // =================================================================================== |
|
126 // |
|
127 // NCP4 specific functions |
|
128 // |
|
129 |
|
130 CTunnelNcp4::CTunnelNcp4(CTunnelFlow& aFlow) |
|
131 : CTunnelNcp(aFlow) |
|
132 { |
|
133 } |
|
134 |
|
135 CTunnelNcp4* CTunnelNcp4::ConstructL(CTunnelFlow& aFlow) |
|
136 { |
|
137 CTunnelNcpLog::Printf(_L("CTunnelNcp4::ConstructL()")); |
|
138 |
|
139 CTunnelNcp4* self = new(ELeave) CTunnelNcp4(aFlow); |
|
140 CleanupStack::PushL(self); |
|
141 |
|
142 CTunnelNcpLog::Printf(_L("CTunnelNcp4::ConstructL() - Created Nif %S"), &self->Info()->iIfName); |
|
143 CleanupStack::Pop(self); |
|
144 return self; |
|
145 } |
|
146 |
|
147 TInt CTunnelNcp4::GetConfig(TBinderConfig& aConfig) |
|
148 { |
|
149 TBinderConfig4* config = TBinderConfig::Cast<TBinderConfig4>(aConfig); |
|
150 |
|
151 if(config == NULL) |
|
152 { |
|
153 return KErrNotSupported; |
|
154 } |
|
155 |
|
156 config->iFamily = KAfInet; /* KAfInet - selects TBinderConfig4 */ |
|
157 |
|
158 config->iInfo.iFeatures = KIfCanBroadcast | KIfCanMulticast; /* Feature flags */ |
|
159 config->iInfo.iMtu = KTunnelMtu; /* Maximum transmission unit. */ |
|
160 config->iInfo.iRMtu = KTunnelMtu; /* Maximum transmission unit for receiving. */ |
|
161 config->iInfo.iSpeedMetric = 0; /* approximation of the interface speed in Kbps. */ |
|
162 |
|
163 config->iNetMask.SetAddress(0); /* IP netmask. */ |
|
164 config->iBrdAddr.SetAddress(0); /* IP broadcast address. */ |
|
165 |
|
166 // do this only if we have a valid address |
|
167 if(iLocalAddress == 0) |
|
168 { |
|
169 TInetAddr unspec(KAFUnspec); |
|
170 config->iAddress = unspec; |
|
171 config->iDefGate = unspec; |
|
172 } |
|
173 else |
|
174 { |
|
175 config->iAddress.SetAddress(iLocalAddress); /* Interface IP address. */ |
|
176 config->iDefGate.SetAddress(iLocalAddress); /* IP default gateway or peer address (if known). */ |
|
177 config->iNameSer1 = iNameSer1; /* IP primary name server (if any). */ |
|
178 config->iNameSer2 = iNameSer2; /* IP secondary name server (if any). */ |
|
179 } |
|
180 |
|
181 return KErrNone; |
|
182 } |
|
183 |
|
184 TInt CTunnelNcp4::Control(TUint aLevel, TUint aName, TDes8& aOption) |
|
185 { |
|
186 CTunnelNcpLog::Printf(_L("CTunnelNcp4::Control(aLevel %x, aName %x, ...)"), aLevel, aName); |
|
187 |
|
188 if (aLevel == KCOLInterface) |
|
189 { |
|
190 if (aName == KConnNifConfig) |
|
191 { |
|
192 TInetIfConfig& opt = *(TInetIfConfig*)aOption.Ptr(); |
|
193 iLocalAddress = opt.iAddress.Address(); |
|
194 iNameSer1 = opt.iNameSer1; |
|
195 iNameSer2 = opt.iNameSer2; |
|
196 return KErrNone; |
|
197 } |
|
198 } |
|
199 return KErrNotSupported; |
|
200 } |
|
201 |
|
202 TInt CTunnelNcp4::Notification(TTunnelAgentMessage::TTunnelSetAddress& aMessage) |
|
203 { |
|
204 iLocalAddress = aMessage.iAddress.Address() ; |
|
205 iNameSer1 = aMessage.iNameSer1; |
|
206 iNameSer2 = aMessage.iNameSer2; |
|
207 if ( aMessage.iIsUpdate ) |
|
208 { |
|
209 ASSERT(iUpperControl); |
|
210 iUpperControl->Error(KErrLinkConfigChanged); |
|
211 // iLink->Notify()->BinderLayerDown((CNifIfBase*)this, KErrLinkConfigChanged, MNifIfNotify::EReconnect); |
|
212 } |
|
213 return KErrNone; |
|
214 } |
|
215 |
|
216 // =================================================================================== |
|
217 // |
|
218 // NCP6 specific functions |
|
219 // |
|
220 |
|
221 CTunnelNcp6::CTunnelNcp6(CTunnelFlow& aFlow) |
|
222 : CTunnelNcp(aFlow) |
|
223 { |
|
224 } |
|
225 |
|
226 CTunnelNcp6* CTunnelNcp6::ConstructL(CTunnelFlow& aLink) |
|
227 { |
|
228 CTunnelNcpLog::Printf(_L("CTunnelNcp6::ConstructL()")); |
|
229 |
|
230 CTunnelNcp6* self = new(ELeave) CTunnelNcp6(aLink); |
|
231 CleanupStack::PushL(self); |
|
232 |
|
233 CTunnelNcpLog::Printf(_L("CTunnelNcp::ConstructL() - Created Nif %S"), &self->Info()->iIfName); |
|
234 CleanupStack::Pop(self); |
|
235 return self; |
|
236 } |
|
237 |
|
238 TInt CTunnelNcp6::GetConfig(TBinderConfig& aConfig) |
|
239 /** |
|
240 Return the configuration information for the binder (e.g. IP address) |
|
241 |
|
242 Called from upper layer. |
|
243 |
|
244 @param aConfig base class of structure to fill in with configuration information. |
|
245 */ |
|
246 { |
|
247 if(TBinderConfig::Cast<TBinderConfig6>(aConfig) == NULL) |
|
248 { |
|
249 return KErrNotSupported; |
|
250 } |
|
251 |
|
252 TBinderConfig6& config = static_cast<TBinderConfig6&>(aConfig); |
|
253 |
|
254 config.iFamily = KAfInet6; /* KAfInet - selects TBinderConfig4 */ |
|
255 |
|
256 config.iInfo.iFeatures = KIfCanBroadcast | KIfCanMulticast; /* Feature flags */ |
|
257 config.iInfo.iMtu = KTunnelMtu; /* Maximum transmission unit. */ |
|
258 config.iInfo.iRMtu = KTunnelMtu; /* Maximum transmission unit for receiving. */ |
|
259 config.iInfo.iSpeedMetric = 0; /* approximation of the interface speed in Kbps. */ |
|
260 |
|
261 config.iLocalId = iLocalAddress; |
|
262 //opt.iRemoteId.SetAddress(iLocalAddress); |
|
263 // Setup static DNS address if required |
|
264 if (!iNameSer1.IsUnspecified()) |
|
265 { |
|
266 config.iNameSer1 = iNameSer1; |
|
267 if (!iNameSer1.IsUnspecified()) |
|
268 config.iNameSer2 = iNameSer2; |
|
269 } |
|
270 |
|
271 return KErrNone; |
|
272 } |
|
273 |
|
274 TInt CTunnelNcp6::Control(TUint aLevel, TUint aName, TDes8& aOption) |
|
275 { |
|
276 CTunnelNcpLog::Printf(_L("CTunnelNcp6::Control(aLevel %x, aName %x, ...)"), aLevel, aName); |
|
277 |
|
278 if (aLevel == KCOLInterface) |
|
279 { |
|
280 if (aName == KConnNifConfig) |
|
281 { |
|
282 TSoInet6IfConfig& opt = *(TSoInet6IfConfig*)aOption.Ptr(); |
|
283 iLocalAddress = opt.iLocalId; |
|
284 iNameSer1 = opt.iNameSer1; |
|
285 iNameSer2 = opt.iNameSer2; |
|
286 return KErrNone; |
|
287 } |
|
288 } |
|
289 |
|
290 return KErrNotSupported; |
|
291 } |
|
292 |
|
293 TInt CTunnelNcp6::Notification(TTunnelAgentMessage::TTunnelSetAddress& aMessage) |
|
294 { |
|
295 iLocalAddress = aMessage.iAddress; |
|
296 iNameSer1 = aMessage.iNameSer1; |
|
297 iNameSer2 = aMessage.iNameSer2; |
|
298 if ( aMessage.iIsUpdate ) |
|
299 { |
|
300 ASSERT(iUpperControl); |
|
301 iUpperControl->Error(KErrLinkConfigChanged); |
|
302 // iLink->Notify()->BinderLayerDown((CNifIfBase*)this, KErrLinkConfigChanged, MNifIfNotify::EReconnect); |
|
303 } |
|
304 return KErrNone; |
|
305 } |
|
306 |
|
307 |
|
308 void CTunnelNcpLog::Write(const TDesC& aDes) |
|
309 // |
|
310 // Write aText to the log |
|
311 // |
|
312 { |
|
313 LOG(RFileLogger::Write(KTunnelIfLogFolder(), KTunnelIfLogFile(), EFileLoggingModeAppend, aDes);) |
|
314 (void)aDes; |
|
315 } |
|
316 |
|
317 void CTunnelNcpLog::Printf(TRefByValue<const TDesC> aFmt,...) |
|
318 // |
|
319 // Write a mulitple argument list to the log, trapping and ignoring any leave |
|
320 // |
|
321 { |
|
322 LOG( |
|
323 VA_LIST list; |
|
324 VA_START(list,aFmt); |
|
325 RFileLogger::WriteFormat(KTunnelIfLogFolder(), KTunnelIfLogFile(), EFileLoggingModeAppend, aFmt, list); |
|
326 ) |
|
327 (void)aFmt; |
|
328 } |
|
329 |
|
330 |
|
331 |
|
332 |