|
1 /* |
|
2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: VPN Connection Agent |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <cmmanager.h> |
|
21 #include <cmconnectionmethod.h> |
|
22 #include <cmpluginvpndef.h> |
|
23 #include <commdbconnpref.h> |
|
24 #include <in_iface.h> |
|
25 #include <tunnelnifvar.h> |
|
26 #include <d32dbmsconstants.h> |
|
27 |
|
28 #include "vpnconnagt.h" |
|
29 |
|
30 |
|
31 /***************CVPNConnAgtFactory********************/ |
|
32 |
|
33 extern "C" EXPORT_C CNifAgentFactory* NewAgentFactoryL() |
|
34 { |
|
35 return new(ELeave) CVPNConnAgtFactory; |
|
36 } |
|
37 |
|
38 void CVPNConnAgtFactory::InstallL() |
|
39 { |
|
40 } |
|
41 |
|
42 CNifAgentBase* CVPNConnAgtFactory::NewAgentL( |
|
43 const TDesC& /*aName*/) |
|
44 { |
|
45 return CVPNConnAgt::NewL(); |
|
46 } |
|
47 |
|
48 TInt CVPNConnAgtFactory::Info( |
|
49 TNifAgentInfo& aInfo, |
|
50 TInt /*aIndex*/) const |
|
51 { |
|
52 aInfo.iName = KVPNConnAgtName; |
|
53 aInfo.iVersion = TVersion(KMajorVerNumber,KMinorVerNumber,KBuildVerNumber); |
|
54 return KErrNone; |
|
55 } |
|
56 |
|
57 /***************CVPNConnAgt********************/ |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CVPNConnAgt |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CVPNConnAgt::CVPNConnAgt() : |
|
64 iServiceStartedCallback(CActive::EPriorityStandard), |
|
65 iConnectCompleteCallback(CActive::EPriorityStandard), |
|
66 iDisconnectCallback(CActive::EPriorityStandard) |
|
67 { |
|
68 TCallBack serviceStartedCallback(ServiceStartedCb, this); |
|
69 iServiceStartedCallback.Set(serviceStartedCallback); |
|
70 |
|
71 TCallBack connectionCompleteCallback(ConnectCompleteCb, this); |
|
72 iConnectCompleteCallback.Set(connectionCompleteCallback); |
|
73 |
|
74 TCallBack disconnectionCompleteCallback(DisconnectCompleteCb, this); |
|
75 iDisconnectCallback.Set(disconnectionCompleteCallback); |
|
76 |
|
77 iEventActivatedClose = EFalse; |
|
78 iDisconnectType = (TDeactivateType)NORMAL_DISCONNECT_MODE; // means the normal way to shutdown |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // Destructor |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 CVPNConnAgt::~CVPNConnAgt() |
|
86 { |
|
87 LOG(TName name; |
|
88 name.AppendFormat(_L("[0x%08x]"), this); |
|
89 Log::Printf(_L("%s Destructing VPN Connection Agent\n"),name.PtrZ())); |
|
90 |
|
91 iEventMediator.Close(); |
|
92 |
|
93 iServiceStartedCallback.Cancel(); |
|
94 iConnectCompleteCallback.Cancel(); |
|
95 iDisconnectCallback.Cancel(); |
|
96 |
|
97 delete iAD; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // NewL() |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 CVPNConnAgt* CVPNConnAgt::NewL() |
|
105 { |
|
106 CVPNConnAgt* self = new (ELeave) CVPNConnAgt(); |
|
107 CleanupStack::PushL(self); |
|
108 self->ConstructL(); |
|
109 CleanupStack::Pop(self); |
|
110 return self; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // ConstructL() |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 inline void CVPNConnAgt::ConstructL() |
|
118 { |
|
119 LOG_1("[0x%08x] Constructing VPN Connection Agent\n", this); |
|
120 // construct the database and dialog processor |
|
121 CAgentBase::ConstructL(); |
|
122 iConnected = EFalse; |
|
123 iDisconnecting = EFalse; |
|
124 LOG_("CVPNConnAgt::ReadConfigurationL EventMediator"); |
|
125 User::LeaveIfError(iEventMediator.Connect()); |
|
126 |
|
127 iAD = CAsyncDisconnecter::NewL(this); |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // Info() |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 void CVPNConnAgt::Info( |
|
135 TNifAgentInfo& aInfo) const |
|
136 { |
|
137 aInfo.iName = KVPNConnAgtName; |
|
138 aInfo.iName.AppendFormat(_L("-AgentFactory[0x%08x]"), this); |
|
139 aInfo.iVersion = TVersion( |
|
140 TCommDbConnPref::KMajorVersionNumber, |
|
141 TCommDbConnPref::KMinorVersionNumber, |
|
142 TCommDbConnPref::KBuildVersionNumber |
|
143 ); |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // Connect() |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void CVPNConnAgt::Connect( |
|
151 TAgentConnectType /*aType*/) |
|
152 { |
|
153 iServiceStartedCallback.CallBack(); |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // Connect() |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 void CVPNConnAgt::Connect( |
|
161 TAgentConnectType aType, |
|
162 CStoreableOverrideSettings* /*aOverrideSettings*/) |
|
163 { |
|
164 Connect(aType); |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CancelConnect() |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CVPNConnAgt::CancelConnect() |
|
172 { |
|
173 LOG_("CVPNConnAgt::CancelConnect"); |
|
174 iServiceStartedCallback.Cancel(); |
|
175 iConnectCompleteCallback.Cancel(); |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // Disconnect() |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 void CVPNConnAgt::Disconnect( |
|
183 TInt aReason) |
|
184 { |
|
185 LOG_1("Disconnect called from Nifman with reason:%d\n", aReason); |
|
186 if ( iDisconnecting ) |
|
187 { |
|
188 LOG_("Already disconnecting, return\n"); |
|
189 return; |
|
190 } |
|
191 |
|
192 if ( aReason == KErrConnectionTerminated ) |
|
193 iDisconnectType = (TDeactivateType)SILENT_DISCONNECT_MODE; |
|
194 |
|
195 iLastErrorCode = aReason; |
|
196 iDisconnectCallback.CallBack(); |
|
197 } |
|
198 |
|
199 |
|
200 /****************************************************************************/ |
|
201 /* GetExcessData() */ |
|
202 /****************************************************************************/ |
|
203 TInt CVPNConnAgt::GetExcessData( |
|
204 TDes8& /*aBuffer*/) |
|
205 { |
|
206 return KErrNotSupported; |
|
207 } |
|
208 |
|
209 /****************************************************************************/ |
|
210 /* Notification() */ |
|
211 /* Nif calls this via agentref to pass the name of the nif. */ |
|
212 /****************************************************************************/ |
|
213 TInt CVPNConnAgt::Notification( |
|
214 TNifToAgentEventType aEvent, |
|
215 TAny* aInfo) |
|
216 { |
|
217 if ( (TTunnelNifToAgentEventType)aEvent == ENifToAgentEventTypeSetIfName ) |
|
218 { |
|
219 iVPNParameters.SetVPNNifName(*(TName*)aInfo); |
|
220 return KErrNone; |
|
221 } |
|
222 |
|
223 if ( aEvent == ENifToAgentEventTypeLinkLayerDown ) |
|
224 {// Tunnelnif down |
|
225 return KErrNone; |
|
226 } |
|
227 |
|
228 return KErrNotSupported; |
|
229 } |
|
230 |
|
231 /****************************************************************************/ |
|
232 /* GetLastError() */ |
|
233 /****************************************************************************/ |
|
234 void CVPNConnAgt::GetLastError(TInt& aError) |
|
235 { |
|
236 aError = iLastErrorCode; |
|
237 } |
|
238 |
|
239 TInt CVPNConnAgt::IncomingConnectionReceived() |
|
240 { |
|
241 return KErrNotSupported; |
|
242 } |
|
243 |
|
244 /****************************************************************************/ |
|
245 /* ServiceStartedCb() */ |
|
246 /****************************************************************************/ |
|
247 TInt CVPNConnAgt::ServiceStartedCb(TAny* aThisPtr) |
|
248 { |
|
249 CVPNConnAgt* self = (CVPNConnAgt*)aThisPtr; |
|
250 |
|
251 TInt err = KErrNone; |
|
252 self->ServiceStarted(err); |
|
253 return err; |
|
254 } |
|
255 |
|
256 /****************************************************************************/ |
|
257 /* ConnectCompleteCb() */ |
|
258 /****************************************************************************/ |
|
259 TInt CVPNConnAgt::ConnectCompleteCb( |
|
260 TAny* aThisPtr) |
|
261 { |
|
262 CVPNConnAgt* self = (CVPNConnAgt*) aThisPtr; |
|
263 self->ConnectionComplete(KErrNone); |
|
264 return KErrNone; |
|
265 } |
|
266 |
|
267 /****************************************************************************/ |
|
268 /* DisconnectCompleteCb() */ |
|
269 /****************************************************************************/ |
|
270 TInt CVPNConnAgt::DisconnectCompleteCb( |
|
271 TAny* aThisPtr) |
|
272 { |
|
273 CVPNConnAgt* self = (CVPNConnAgt*) aThisPtr; |
|
274 self->DisconnectionComplete(); |
|
275 return KErrNone; |
|
276 } |
|
277 |
|
278 /****************************************************************************/ |
|
279 /* ServiceStarted() */ |
|
280 /****************************************************************************/ |
|
281 void CVPNConnAgt::ServiceStarted(TInt& aError) |
|
282 { |
|
283 iLastErrorCode = KErrNone; |
|
284 |
|
285 iNotify->AgentProgress(EVPNConnAgtConnecting, iLastErrorCode); |
|
286 |
|
287 // read IAP configuration |
|
288 TRAP(iLastErrorCode, ReadConfigurationL()); |
|
289 if ( iLastErrorCode ) |
|
290 { |
|
291 LOG(TName name; |
|
292 name.AppendFormat(_L("[0x%08x]"), this); |
|
293 Log::Printf(_L("%s Error %d in reading configuration\n"),name.PtrZ(), iLastErrorCode)); |
|
294 |
|
295 iNotify->ConnectComplete(iLastErrorCode); |
|
296 aError = iLastErrorCode; |
|
297 return; |
|
298 } |
|
299 |
|
300 LOG_1("[0x%08x] Get protocol version\n", this); |
|
301 iProtocolVersionDes().iId = iEventMediator.NewEventSpecId(); |
|
302 iProtocolVersionDes().iPolicyId = *(iVPNParameters.GetVPNPolicy()); |
|
303 iEventMediator.ListenToEvent( |
|
304 EGetProtocolVersionEvent, iProtocolVersionDes, *this); |
|
305 iState = EGettingProtocolVersion; |
|
306 } |
|
307 |
|
308 /****************************************************************************/ |
|
309 /* ConnectionComplete() */ |
|
310 /****************************************************************************/ |
|
311 void CVPNConnAgt::ConnectionComplete( |
|
312 TInt aError) |
|
313 { |
|
314 if ( aError ) |
|
315 { |
|
316 switch ( iState ) |
|
317 { |
|
318 case EGettingProtocolVersion: |
|
319 iEventMediator.CancelListening(EGetProtocolVersionEvent, iProtocolVersionDes); |
|
320 iNotify->AgentProgress(EVPNConnAgtDisconnected, aError); |
|
321 iNotify->ConnectComplete(aError); |
|
322 iState = EConnectionClosed; |
|
323 return; |
|
324 case EConnecting: |
|
325 iEventMediator.CancelListening(EStartVpnConnEvent, iStartVpnConnDes); |
|
326 iNotify->AgentProgress(EVPNConnAgtDisconnected, aError); |
|
327 iNotify->ConnectComplete(aError); |
|
328 iState = EConnectionClosed; |
|
329 return; |
|
330 default: |
|
331 break; |
|
332 } |
|
333 return; |
|
334 } |
|
335 |
|
336 TInetIfConfig addr; |
|
337 addr.iAddress = iVPNParameters.GetVPNNifAddress(); |
|
338 addr.iNameSer1 = iVPNParameters.GetVPNNifDNS1(); |
|
339 addr.iNameSer2 = iVPNParameters.GetVPNNifDNS2(); |
|
340 |
|
341 LOG(TName name; |
|
342 name.AppendFormat(_L("[0x%08x]"), this); |
|
343 TBuf<39> addrBuf; |
|
344 iVPNParameters.GetVPNNifAddress().OutputWithScope(addrBuf); |
|
345 Log::Printf(_L("%s Vpn interface address = %s\n"),name.PtrZ(), addrBuf.PtrZ())); |
|
346 |
|
347 LOG(iVPNParameters.GetVPNNifDNS1().OutputWithScope(addrBuf); |
|
348 Log::Printf(_L("%s Vpn DNS1 = %s\n"),name.PtrZ(), addrBuf.PtrZ())); |
|
349 |
|
350 LOG(iVPNParameters.GetVPNNifDNS2().OutputWithScope(addrBuf); |
|
351 Log::Printf(_L("%s Vpn DNS2 = %s\n"),name.PtrZ(), addrBuf.PtrZ())); |
|
352 |
|
353 // Send VPN interface address to the tunnelnif |
|
354 iNotify->Notification((TAgentToNifEventType)EAgentToNifEventTypeSetAddress, (void*)(&addr)); |
|
355 |
|
356 // Inform the Nifman |
|
357 iNotify->AgentProgress(EVPNConnAgtConnected, KErrNone); |
|
358 iNotify->ConnectComplete(aError); |
|
359 |
|
360 iConnected = ETrue; |
|
361 |
|
362 // initialize real if observer |
|
363 iObserveRealIapConnDes().iRealIapConnInfo.iIapId = iVPNParameters.GetRealIapId(); |
|
364 iObserveRealIapConnDes().iRealIapConnInfo.iNetId = iVPNParameters.GetRealNetworkId(); |
|
365 iObserveRealIapConnDes().iVpnIapId = iVPNParameters.GetVPNIapId(); |
|
366 |
|
367 ListenRealIAP(); |
|
368 ListenAddressChange(); |
|
369 |
|
370 iState = EListeningEvents; |
|
371 LOG_1("[0x%08x] VPN CONNECTION READY!\n", this); |
|
372 } |
|
373 |
|
374 /****************************************************************************/ |
|
375 /* DisconnectionComplete() */ |
|
376 /****************************************************************************/ |
|
377 void CVPNConnAgt::DisconnectionComplete() |
|
378 { |
|
379 if ( iDisconnecting ) |
|
380 { |
|
381 LOG(TName name; |
|
382 name.AppendFormat(_L("[0x%08x]"), this); |
|
383 Log::Printf(_L("%s Already disconnecting, return\n"),name.PtrZ())); |
|
384 return; |
|
385 } |
|
386 else |
|
387 iDisconnecting = ETrue; |
|
388 |
|
389 iNotify->AgentProgress(EVPNConnAgtDisconnecting, KErrNone); |
|
390 |
|
391 if ( iConnected && (iState == EListeningEvents || iState == EStartingRealIf) ) |
|
392 { |
|
393 // Start the deactivate/unload of the VPN policies. |
|
394 CancelListeners(); |
|
395 |
|
396 if ( iState == EStartingRealIf ) |
|
397 iDisconnectType = (TDeactivateType)SILENT_DISCONNECT_MODE; |
|
398 |
|
399 iCloseVpnConnDes().iId = iEventMediator.NewEventSpecId(); |
|
400 iCloseVpnConnDes().iIkePolicyHandle = iVPNParameters.GetIkePolicyHandle(); |
|
401 iCloseVpnConnDes().iIpsecPolicyHandle = iVPNParameters.GetIpsecPolicyHandle(); |
|
402 iCloseVpnConnDes().iDeactivateType = iDisconnectType; |
|
403 iCloseVpnConnDes().iVpnIapId = iVPNParameters.GetVPNIapId(); |
|
404 iCloseVpnConnDes().iRealIapId = iVPNParameters.GetRealIapId(); |
|
405 iEventMediator.ListenToEvent(ECloseVpnConnEvent, iCloseVpnConnDes, *this); |
|
406 iState = EClosingConnection; |
|
407 |
|
408 LOG(TName name; |
|
409 name.AppendFormat(_L("[0x%08x]"), this); |
|
410 Log::Printf(_L("%s Disconnecting type is %d\n"),name.PtrZ(), (TInt)iDisconnectType)); |
|
411 |
|
412 return; |
|
413 } |
|
414 |
|
415 iAD->ConfirmDisconnect(); |
|
416 iDisconnecting = EFalse; |
|
417 } |
|
418 |
|
419 |
|
420 /****************************************************************************/ |
|
421 /* EventOccured() */ |
|
422 /****************************************************************************/ |
|
423 void CVPNConnAgt::EventOccured(TInt aStatus, TEventType aType, TDesC8* aData) |
|
424 { |
|
425 LOG(TName name; |
|
426 name.AppendFormat(_L("[0x%08x]"), this); |
|
427 Log::Printf(_L("%s Event occured with status %d\n"),name.PtrZ(), aStatus)); |
|
428 |
|
429 if ( aStatus == KErrServerTerminated ) |
|
430 { |
|
431 iNotify->Notification(EAgentToNifEventTypeDisableConnection, NULL); |
|
432 iConnected = EFalse; // Disable listening of ECloseVpnConnEvent event |
|
433 return; |
|
434 } |
|
435 |
|
436 if ( aStatus != KErrNone || !aData ) |
|
437 { |
|
438 if ( !iConnected ) |
|
439 ConnectionComplete(aStatus); |
|
440 else |
|
441 DisconnectionComplete(); |
|
442 |
|
443 return; |
|
444 } |
|
445 |
|
446 TGetProtocolVersionEventData* protocolVersion=NULL; |
|
447 TStartVpnConnEventData* connection = NULL; |
|
448 TCloseVpnConnEventData* closeData = NULL; |
|
449 switch (aType) |
|
450 { |
|
451 case EGetProtocolVersionEvent: |
|
452 protocolVersion = (TGetProtocolVersionEventData*)(aData->Ptr()); |
|
453 if ( protocolVersion->iTaskStatus ) |
|
454 { |
|
455 TProtocolVersion pv(EVersionIp); |
|
456 iVPNParameters.SetProtocolVersion(pv); |
|
457 } |
|
458 else |
|
459 iVPNParameters.SetProtocolVersion(protocolVersion->iProtocolVersion); |
|
460 |
|
461 |
|
462 LOG(Log::Printf(_L("%s Protocol resolved = %d\n"),name.PtrZ(), protocolVersion->iProtocolVersion)); |
|
463 |
|
464 // Inform Nifman to go forward |
|
465 iNotify->ServiceStarted(); |
|
466 |
|
467 // Initialise the connection parameters |
|
468 iStartVpnConnDes().iId = iEventMediator.NewEventSpecId(); |
|
469 iStartVpnConnDes().iIfInfo.iVpnIapId = iVPNParameters.GetVPNIapId(); |
|
470 iStartVpnConnDes().iIfInfo.iVpnNetId = iVPNParameters.GetVPNNetworkId(); |
|
471 iStartVpnConnDes().iIfInfo.iRealIapId = iVPNParameters.GetRealIapId(); |
|
472 iStartVpnConnDes().iIfInfo.iRealNetId = iVPNParameters.GetRealNetworkId(); |
|
473 iStartVpnConnDes().iIfInfo.iVPNIfName = *(VPNNifName()); |
|
474 iStartVpnConnDes().iPolicyId = *(iVPNParameters.GetVPNPolicy()); |
|
475 |
|
476 LOG(Log::Printf(_L("%s Start connection\n"),name.PtrZ())); |
|
477 |
|
478 // Start connection |
|
479 iEventMediator.ListenToEvent(EStartVpnConnEvent, iStartVpnConnDes, *this); |
|
480 iState = EConnecting; |
|
481 break; |
|
482 case EStartVpnConnEvent: |
|
483 // Read the connection data (addresses and policy |
|
484 // handles) |
|
485 connection = (TStartVpnConnEventData*)(aData->Ptr()); |
|
486 ASSERT(connection); |
|
487 if ( connection->iTaskStatus ) |
|
488 { |
|
489 ConnectionComplete(connection->iTaskStatus); |
|
490 break; |
|
491 } |
|
492 |
|
493 LOG(Log::Printf(_L("%s Connection started, Ikehandle: %d, Ipsechandle: %d\n"), |
|
494 name.PtrZ(), connection->iIkePolicyHandle, connection->iIpsecPolicyHandle)); |
|
495 iVPNParameters.SetRealNetworkId(connection->iNetId); |
|
496 iVPNParameters.SetRealIapId(connection->iIapId); |
|
497 iVPNParameters.SetIkePolicyHandle(connection->iIkePolicyHandle); |
|
498 iVPNParameters.SetIpSecPolicyHandle(connection->iIpsecPolicyHandle); |
|
499 iVPNParameters.SetAddresses(connection->iVpnAddressInfo); |
|
500 iState = EConnected; |
|
501 ConnectionComplete(KErrNone); |
|
502 break; |
|
503 case ECloseVpnConnEvent: |
|
504 LOG(Log::Printf(_L("%s ECloseVpnConnEvent\n"),name.PtrZ())); |
|
505 closeData = (TCloseVpnConnEventData*)(aData->Ptr()); |
|
506 if ( closeData->iTaskStatus ) |
|
507 { |
|
508 LOG(Log::Printf(_L("%s ECloseVpnConnEvent: TaskStatus %d\n"),name.PtrZ(), closeData->iTaskStatus)); |
|
509 iLastErrorCode = closeData->iTaskStatus; |
|
510 } |
|
511 |
|
512 if ( iEventActivatedClose ) |
|
513 { |
|
514 iEventActivatedClose = EFalse; |
|
515 iNotify->Notification(EAgentToNifEventTypeDisableConnection, NULL); |
|
516 } |
|
517 |
|
518 iAD->ConfirmDisconnect(); |
|
519 iDisconnecting = EFalse; |
|
520 |
|
521 iConnected = EFalse; |
|
522 |
|
523 iState = EIdle; |
|
524 break; |
|
525 case EAllInterfaceEvents: |
|
526 case EObserveRealIapConnEvent: |
|
527 { |
|
528 if ( iDisconnecting ) // Shouldn't be possible |
|
529 break; |
|
530 |
|
531 LOG(Log::Printf(_L("%s Real interface down, shutdown silently\n"),name.PtrZ())); |
|
532 |
|
533 iEventActivatedClose = ETrue; |
|
534 iDisconnectType = (TDeactivateType)SILENT_DISCONNECT_MODE; // means that KMD doesn't send any packets to the gateway |
|
535 DisconnectionComplete(); |
|
536 break; |
|
537 } |
|
538 case EKmdAddressChangeEvent: |
|
539 { |
|
540 LOG_1("[0x%08x] Address changed event\n",this); |
|
541 |
|
542 TVPNAddress* ptr = (TVPNAddress*)(aData->Ptr()); |
|
543 |
|
544 if ( iVPNParameters.GetVPNNifAddress().CmpAddr(ptr->iVPNIfAddr) |
|
545 && iVPNParameters.GetVPNNifDNS1().CmpAddr(ptr->iVPNIfDNS1) |
|
546 && iVPNParameters.GetVPNNifDNS2().CmpAddr(ptr->iVPNIfDNS2) ) |
|
547 { |
|
548 LOG_("Address change informed but no change found"); |
|
549 |
|
550 TConnectionInfo vpnIfaceInfo; |
|
551 vpnIfaceInfo.iIapId = iVPNParameters.GetVPNIapId(); |
|
552 TConnectionInfoBuf vpnIfaceInfoBuf(vpnIfaceInfo); |
|
553 iEventMediator.ListenToEvent( |
|
554 EKmdAddressChangeEvent, vpnIfaceInfoBuf, *this); |
|
555 } |
|
556 else |
|
557 { |
|
558 iVPNParameters.SetAddresses(*ptr); |
|
559 TInetIfConfig addr; |
|
560 addr.iAddress = iVPNParameters.GetVPNNifAddress(); |
|
561 addr.iNameSer1 = iVPNParameters.GetVPNNifDNS1(); |
|
562 addr.iNameSer2 = iVPNParameters.GetVPNNifDNS2(); |
|
563 |
|
564 iNotify->Notification( |
|
565 (TAgentToNifEventType)EAgentToNifEventTypeUpdateAddress, |
|
566 (void*)(&addr)); |
|
567 |
|
568 LOG(Log::Printf(_L("%s Address changed, continue listening\n"),name.PtrZ())); |
|
569 |
|
570 TConnectionInfo vpnIfaceInfo; |
|
571 vpnIfaceInfo.iIapId = iVPNParameters.GetVPNIapId(); |
|
572 TConnectionInfoBuf vpnIfaceInfoBuf(vpnIfaceInfo); |
|
573 iEventMediator.ListenToEvent(EKmdAddressChangeEvent, vpnIfaceInfoBuf, *this); |
|
574 |
|
575 LOG(TBuf<39> addrBuf; |
|
576 iVPNParameters.GetVPNNifAddress().OutputWithScope(addrBuf); |
|
577 Log::Printf(_L("%s New Vpn interface address = %s\n"),name.PtrZ(), addrBuf.PtrZ())); |
|
578 |
|
579 LOG(iVPNParameters.GetVPNNifDNS1().OutputWithScope(addrBuf); |
|
580 Log::Printf(_L("%s Vpn DNS1 = %s\n"),name.PtrZ(), addrBuf.PtrZ())); |
|
581 |
|
582 LOG(iVPNParameters.GetVPNNifDNS2().OutputWithScope(addrBuf); |
|
583 Log::Printf(_L("%s Vpn DNS2 = %s\n"),name.PtrZ(), addrBuf.PtrZ())); |
|
584 } |
|
585 break; |
|
586 } |
|
587 default: |
|
588 break; |
|
589 } |
|
590 } |
|
591 |
|
592 |
|
593 /****************************************************************************/ |
|
594 /* ListenRealIAP() */ |
|
595 /****************************************************************************/ |
|
596 void CVPNConnAgt::ListenRealIAP() |
|
597 { |
|
598 // Listen the real interface if it shutsdown or... |
|
599 iObserveRealIapConnDes().iId = iEventMediator.NewEventSpecId(); |
|
600 iEventMediator.ListenToEvent( |
|
601 EObserveRealIapConnEvent, iObserveRealIapConnDes, *this); |
|
602 } |
|
603 |
|
604 /****************************************************************************/ |
|
605 /* ListenAddressChange() */ |
|
606 /****************************************************************************/ |
|
607 void CVPNConnAgt::ListenAddressChange() |
|
608 { |
|
609 // Listen to the VPN interface for address changes |
|
610 TConnectionInfo vpnIfaceInfo; |
|
611 vpnIfaceInfo.iIapId = iVPNParameters.GetVPNIapId(); |
|
612 TConnectionInfoBuf vpnIfaceInfoBuf(vpnIfaceInfo); |
|
613 iEventMediator.ListenToEvent( |
|
614 EKmdAddressChangeEvent, vpnIfaceInfoBuf, *this); |
|
615 } |
|
616 |
|
617 /****************************************************************************/ |
|
618 /* CancelListeners() */ |
|
619 /****************************************************************************/ |
|
620 void CVPNConnAgt::CancelListeners() |
|
621 { |
|
622 // Cancel real interface observer |
|
623 iEventMediator.CancelListening( |
|
624 EObserveRealIapConnEvent, iObserveRealIapConnDes); |
|
625 |
|
626 // Cancel address change event listening |
|
627 TConnectionInfo vpnIfaceInfo; |
|
628 vpnIfaceInfo.iIapId = iVPNParameters.GetVPNIapId(); |
|
629 TConnectionInfoBuf vpnIfaceInfoBuf(vpnIfaceInfo); |
|
630 iEventMediator.CancelListening(EKmdAddressChangeEvent, vpnIfaceInfoBuf); |
|
631 } |
|
632 |
|
633 // --------------------------------------------------------------------------- |
|
634 // Overwrite version of ReadDes to catch the ip version asking |
|
635 // --------------------------------------------------------------------------- |
|
636 // |
|
637 TInt CVPNConnAgt::DoReadDes( |
|
638 const TDesC& aField, TDes16& aValue, const RMessagePtr2* /*aMessage*/ ) |
|
639 { |
|
640 TInt err(KErrNone); |
|
641 LOG_1("CVPNConnAgt::DoReadDes aField=%S", &aField); |
|
642 |
|
643 // If SERVICE_IF_NETWORKS is asked, get the ip version from the VPN |
|
644 // Manager Server. Otherwise use default ReadDes() function. |
|
645 // TBuf<KCommsDbSvrMaxColumnNameLength> columnName=TPtrC( |
|
646 // SERVICE_IF_NETWORKS); |
|
647 // temporary solution |
|
648 TBuf<KDbStoreMaxColumnLength> columnName=TPtrC(SERVICE_IF_NETWORKS); |
|
649 if ( aField.CompareF(columnName) == 0 ) |
|
650 { |
|
651 TProtocolVersion protocol = iVPNParameters.GetProtocolVersion(); |
|
652 if ( protocol == EVersionUnknown ) |
|
653 return KErrNotFound; |
|
654 |
|
655 if ( protocol == EVersionIp ) |
|
656 { |
|
657 _LIT(KIP4, "ip"); |
|
658 aValue = KIP4; |
|
659 } |
|
660 else |
|
661 { |
|
662 _LIT(KIP6, "ip6"); |
|
663 aValue = KIP6; |
|
664 } |
|
665 LOG_1("CVPNConnAgt::DoReadDes aValue=%S", &aValue); |
|
666 return KErrNone; |
|
667 } |
|
668 else |
|
669 { |
|
670 err = iDatabase->ReadDes(aField, columnName); |
|
671 if ( err ) |
|
672 return err; |
|
673 |
|
674 aValue.Copy(columnName); |
|
675 } |
|
676 |
|
677 LOG_1("CVPNConnAgt::DoReadDes aValue=%S", &aValue); |
|
678 return err; |
|
679 } |
|
680 |
|
681 // --------------------------------------------------------------------------- |
|
682 // Read IAP configurations |
|
683 // --------------------------------------------------------------------------- |
|
684 // |
|
685 void CVPNConnAgt::ReadConfigurationL() |
|
686 { |
|
687 // vpn iap id |
|
688 LOG_1("CVPNConnAgt::ReadConfigurationL iIAPId:%d", iSettings.iIAPId); |
|
689 iVPNParameters.SetVPNIapId(iSettings.iIAPId); |
|
690 |
|
691 // read vpn connection method |
|
692 using namespace CMManager; |
|
693 RCmManager cmManager; |
|
694 cmManager.OpenL(); |
|
695 CleanupClosePushL( cmManager ); |
|
696 RCmConnectionMethod vpnConnection = |
|
697 cmManager.ConnectionMethodL( iSettings.iIAPId ); |
|
698 CleanupClosePushL(vpnConnection); |
|
699 ASSERT( vpnConnection.GetBoolAttributeL(ECmVirtual) ); |
|
700 |
|
701 // Read VPN Network Id |
|
702 const TUint32 vpnNetworkId(vpnConnection.GetIntAttributeL(ECmNetworkId)); |
|
703 iVPNParameters.SetVPNNetworkId(vpnNetworkId); |
|
704 |
|
705 LOG_1("CVPNConnAgt::ReadConfigurationL VpnIapId:%d", |
|
706 iVPNParameters.GetVPNIapId()); |
|
707 LOG_1("CVPNConnAgt::ReadConfigurationL VpnNetworkId:%d", |
|
708 iVPNParameters.GetVPNNetworkId()); |
|
709 |
|
710 // vpn policy id |
|
711 HBufC* policy = vpnConnection.GetStringAttributeL(EVpnServicePolicy); |
|
712 if (policy) |
|
713 { |
|
714 TVpnPolicyId policyId; |
|
715 ASSERT( policy->Length() <= policyId.MaxLength() ); |
|
716 |
|
717 policyId.Copy(*policy); |
|
718 delete policy; |
|
719 iVPNParameters.SetVPNPolicy(policyId); |
|
720 } |
|
721 |
|
722 // real IAP or SNAP. ECmNextLayerIapId == EVpnIapId |
|
723 const TUint32 realIap(vpnConnection.GetIntAttributeL(EVpnIapId)); |
|
724 const TUint32 snap( !realIap ? |
|
725 vpnConnection.GetIntAttributeL(ECmNextLayerSNAPId):0); |
|
726 |
|
727 CleanupStack::PopAndDestroy(); // vpnConnection |
|
728 |
|
729 if ( realIap ) |
|
730 { |
|
731 // Now load real connection |
|
732 RCmConnectionMethod realConnection = |
|
733 cmManager.ConnectionMethodL( realIap ); |
|
734 CleanupClosePushL(realConnection); |
|
735 ASSERT( !realConnection.GetBoolAttributeL(ECmVirtual) ); |
|
736 |
|
737 // real iap id |
|
738 const TUint32 realIapId( realConnection.GetIntAttributeL(ECmIapId) ); |
|
739 iVPNParameters.SetRealIapId( realIapId ); |
|
740 |
|
741 // real network id |
|
742 iVPNParameters.SetRealNetworkId( |
|
743 realConnection.GetIntAttributeL(ECmNetworkId) ); |
|
744 CleanupStack::PopAndDestroy(); // realConnection |
|
745 } |
|
746 else |
|
747 { |
|
748 LOG_1("CVPNConnAgt::ReadConfigurationL snap:%d", snap); |
|
749 ASSERT( snap ); // must be snap then |
|
750 iStartVpnConnDes().iIfInfo.iSnapId = snap; |
|
751 } |
|
752 CleanupStack::PopAndDestroy(); // cmManager |
|
753 |
|
754 LOG_1("CVPNConnAgt::ReadConfigurationL RealIap:%d", |
|
755 realIap); |
|
756 LOG_1("CVPNConnAgt::ReadConfigurationL RealIapId:%d", |
|
757 iVPNParameters.GetRealIapId()); |
|
758 LOG_1("CVPNConnAgt::ReadConfigurationL RealNetworkId:%d", |
|
759 iVPNParameters.GetRealNetworkId()); |
|
760 } |
|
761 |
|
762 |
|
763 //////////////////////CAsyncDisconnecter//////////////////// |
|
764 |
|
765 // --------------------------------------------------------------------------- |
|
766 // CAsyncDisconnecter |
|
767 // --------------------------------------------------------------------------- |
|
768 // |
|
769 CAsyncDisconnecter::CAsyncDisconnecter( |
|
770 CVPNConnAgt* aAgent): |
|
771 CAsyncOneShot(EPriorityNormal) |
|
772 { |
|
773 iAgent = aAgent; |
|
774 } |
|
775 |
|
776 // --------------------------------------------------------------------------- |
|
777 // NewL |
|
778 // --------------------------------------------------------------------------- |
|
779 // |
|
780 CAsyncDisconnecter* CAsyncDisconnecter::NewL( |
|
781 CVPNConnAgt* aAgent) |
|
782 { |
|
783 return new (ELeave) CAsyncDisconnecter(aAgent); |
|
784 } |
|
785 |
|
786 // --------------------------------------------------------------------------- |
|
787 // ConfirmDisconnect |
|
788 // --------------------------------------------------------------------------- |
|
789 // |
|
790 void CAsyncDisconnecter::ConfirmDisconnect() |
|
791 { |
|
792 Call(); |
|
793 } |
|
794 |
|
795 // --------------------------------------------------------------------------- |
|
796 // RunL |
|
797 // --------------------------------------------------------------------------- |
|
798 // |
|
799 void CAsyncDisconnecter::RunL() |
|
800 { |
|
801 LOG_1("CAsyncDisconnecter::RunL, iStatus:%d", iStatus.Int() ); |
|
802 iAgent->Notify()->AgentProgress(EVPNConnAgtDisconnected, KErrNone); |
|
803 iAgent->Notify()->DisconnectComplete(); |
|
804 } |
|
805 |