|
1 /* |
|
2 * Copyright (c) 2000-2006 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 declaration. |
|
15 |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 /** |
|
24 |
|
25 * @file vpnconnagt.h |
|
26 |
|
27 * |
|
28 |
|
29 * VPN Connection Agent declaration. |
|
30 |
|
31 * |
|
32 |
|
33 */ |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 #if !defined __VPN_CONN_AGT_H__ |
|
40 |
|
41 #define __VPN_CONN_AGT_H__ |
|
42 |
|
43 |
|
44 |
|
45 // INCLUDES |
|
46 |
|
47 #include <comms-infras/cagentbase.h> |
|
48 |
|
49 |
|
50 |
|
51 #include "eventmediatorapi.h" |
|
52 |
|
53 |
|
54 |
|
55 #include "vpnconnagtprog.h" |
|
56 |
|
57 #include "vpnconnagtdefs.h" |
|
58 |
|
59 #include "eventdefssit.h" |
|
60 |
|
61 #include "log_r6.h" |
|
62 |
|
63 |
|
64 |
|
65 // CONSTANTS |
|
66 |
|
67 const TInt KMajorVerNumber=1; |
|
68 |
|
69 const TInt KMinorVerNumber=0; |
|
70 |
|
71 const TInt KBuildVerNumber=0; |
|
72 |
|
73 |
|
74 |
|
75 _LIT(KVPNConnAgtName,"vpnconnagt"); |
|
76 |
|
77 |
|
78 |
|
79 class CAsyncDisconnecter; |
|
80 |
|
81 |
|
82 |
|
83 /** |
|
84 |
|
85 * A Factory for creating a VPNConnAgent. |
|
86 |
|
87 */ |
|
88 |
|
89 class CVPNConnAgtFactory : public CNifAgentFactory |
|
90 |
|
91 { |
|
92 |
|
93 /** |
|
94 |
|
95 @internalComponent |
|
96 |
|
97 */ |
|
98 |
|
99 protected: // Methods |
|
100 |
|
101 |
|
102 |
|
103 /** |
|
104 |
|
105 * "Installs" this factory to the system. From this Agent point of view |
|
106 |
|
107 * it doesn't do anything... |
|
108 |
|
109 */ |
|
110 |
|
111 void InstallL(); |
|
112 |
|
113 |
|
114 |
|
115 /** |
|
116 |
|
117 * Creates a new VPN Agent instance. |
|
118 |
|
119 * @param aName Not used. |
|
120 |
|
121 * @return Returns the pointer to the agent created if succeed. Otherwise it |
|
122 |
|
123 * leaves. |
|
124 |
|
125 */ |
|
126 |
|
127 CNifAgentBase *NewAgentL(const TDesC& aName); |
|
128 |
|
129 |
|
130 |
|
131 /** |
|
132 |
|
133 * Returns the information defined in TNifAgentInfo. |
|
134 |
|
135 * @param aInfo The reference to the TNifAgentInfo object to be used to pass |
|
136 |
|
137 * the needed information. |
|
138 |
|
139 * @param aIndex Not used. |
|
140 |
|
141 */ |
|
142 |
|
143 TInt Info(TNifAgentInfo& aInfo, TInt aIndex) const; |
|
144 |
|
145 }; |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 /** |
|
152 |
|
153 * Class declaration for VPN connection agent. Each agent reference |
|
154 |
|
155 * has it's own instance of agent and nif. Nif sends it's name via |
|
156 |
|
157 * agent reference to agent. This triggers agent to initialize the VPN connection |
|
158 |
|
159 * through the VPN Manager Server. After VPN tunnel has been created |
|
160 |
|
161 * agent sends the IP address and the DNS addresses to the nif which |
|
162 |
|
163 * in turn informs the Nifman and IP stack that the connection has |
|
164 |
|
165 * been created. |
|
166 |
|
167 */ |
|
168 |
|
169 class CVPNConnAgt : public CAgentBase, public MEventObserver |
|
170 |
|
171 { |
|
172 |
|
173 /** |
|
174 |
|
175 @internalComponent |
|
176 |
|
177 */ |
|
178 |
|
179 friend class CAsyncDisconnecter; |
|
180 |
|
181 public: // Methods |
|
182 |
|
183 |
|
184 |
|
185 /** |
|
186 |
|
187 * Static constructor. |
|
188 |
|
189 * @return The return value is the pointer to the CVPNConnAgt |
|
190 |
|
191 * if it succeed. Otherwise the fuction leaves. |
|
192 |
|
193 */ |
|
194 |
|
195 static CVPNConnAgt* NewL(); |
|
196 |
|
197 |
|
198 |
|
199 /** |
|
200 |
|
201 * Default C++ destructor. |
|
202 |
|
203 * Cancels all the Callbacks. |
|
204 |
|
205 */ |
|
206 |
|
207 virtual ~CVPNConnAgt(); |
|
208 |
|
209 |
|
210 |
|
211 // from CNifAgentBase |
|
212 |
|
213 /** |
|
214 |
|
215 * Returns the information defined in TNifAgentInfo. |
|
216 |
|
217 * @param aInfo A reference to TNifAgentInfo object which is |
|
218 |
|
219 * used to pass the information to caller of this function. |
|
220 |
|
221 */ |
|
222 |
|
223 void Info(TNifAgentInfo& aInfo) const; |
|
224 |
|
225 |
|
226 |
|
227 /** |
|
228 |
|
229 * Starts the connection creation process. |
|
230 |
|
231 * @param aType Not used. |
|
232 |
|
233 */ |
|
234 |
|
235 void Connect(TAgentConnectType aType); |
|
236 |
|
237 |
|
238 |
|
239 /** |
|
240 |
|
241 * Starts the connection by calling Connect(TAgentConnectType aType). |
|
242 |
|
243 * @param aType Type of the connection e.g. EAgentReconnect. |
|
244 |
|
245 * @param aOverrideSettings Not used. |
|
246 |
|
247 */ |
|
248 |
|
249 void Connect(TAgentConnectType aType, CStoreableOverrideSettings* aOverrideSettings); |
|
250 |
|
251 |
|
252 |
|
253 /** |
|
254 |
|
255 * Starts the cancellation of the connect. |
|
256 |
|
257 */ |
|
258 |
|
259 void CancelConnect(); |
|
260 |
|
261 |
|
262 |
|
263 /** |
|
264 |
|
265 * Disconnects an ongoing connection. |
|
266 |
|
267 * @param aReason Not used. |
|
268 |
|
269 */ |
|
270 |
|
271 void Disconnect(TInt aReason); |
|
272 |
|
273 |
|
274 |
|
275 /** |
|
276 |
|
277 * Called after Connect() in connection creation phase. Connection configuration |
|
278 |
|
279 * parameters are read and request for the VPNManServer to open the connection |
|
280 |
|
281 * is done. During the execution of this function VPN Nif is created. |
|
282 |
|
283 * @param aError Not used. |
|
284 |
|
285 */ |
|
286 |
|
287 void ServiceStarted(TInt& aError); |
|
288 |
|
289 |
|
290 |
|
291 /** |
|
292 |
|
293 * The addresses got from the VPN Manager Server are send to VPN Nif. |
|
294 |
|
295 * Nifman is informed with the progress call (with parameter EVPNConnAgtConnected). |
|
296 |
|
297 * MNifAgentNotify interface's ConnectComplete() is called (this generates the Start() |
|
298 |
|
299 * call to VPN Nif. |
|
300 |
|
301 * @param aError Not used. |
|
302 |
|
303 */ |
|
304 |
|
305 void ConnectionComplete(TInt aError); |
|
306 |
|
307 |
|
308 |
|
309 /** |
|
310 |
|
311 * Causes the deactivationing/unloading of the VPN Policies. |
|
312 |
|
313 */ |
|
314 |
|
315 void DisconnectionComplete(); |
|
316 |
|
317 |
|
318 |
|
319 /** |
|
320 |
|
321 * Not Supported. |
|
322 |
|
323 * @param aBuffer Not used. |
|
324 |
|
325 * @return Always returns KErrNotSupported. |
|
326 |
|
327 */ |
|
328 |
|
329 TInt GetExcessData(TDes8& aBuffer); |
|
330 |
|
331 |
|
332 |
|
333 /** |
|
334 |
|
335 * Used to deliver the name of the VPN Nif to the VPN Agent. |
|
336 |
|
337 * @param aEvent If the value of this is ENifToVPNAgentEventTypeIfName the name of the |
|
338 |
|
339 * VPN Nif is copied from the aInfo parameter. |
|
340 |
|
341 * @param aInfo TName type pointer containing the name of the VPN NIf (if aEvent value is |
|
342 |
|
343 * ENifToVPNAgentEventTypeIfName). |
|
344 |
|
345 * @return Returns KErrNone if the fuction is used to deliver the name of the VPN Nif, |
|
346 |
|
347 * otherwise it returns KErrNotSupported. |
|
348 |
|
349 */ |
|
350 |
|
351 TInt Notification(TNifToAgentEventType aEvent, TAny* aInfo); |
|
352 |
|
353 |
|
354 |
|
355 /** |
|
356 |
|
357 * Passes the last error code to the caller. |
|
358 |
|
359 * @param aError Reference to the TInt type error code. |
|
360 |
|
361 */ |
|
362 |
|
363 void GetLastError(TInt& aError); |
|
364 |
|
365 |
|
366 |
|
367 /** |
|
368 |
|
369 * |
|
370 |
|
371 */ |
|
372 |
|
373 TBool IsReconnect() const {return (ETrue);}; |
|
374 |
|
375 |
|
376 |
|
377 /** |
|
378 |
|
379 * Not supported. |
|
380 |
|
381 */ |
|
382 |
|
383 TInt IncomingConnectionReceived(); |
|
384 |
|
385 |
|
386 |
|
387 /** |
|
388 |
|
389 * Is called when an event comes from real interface via event mediator. |
|
390 |
|
391 * @param aStatus Error code if the call fails. KErrNone if everything succees. |
|
392 |
|
393 * @param aType Type pf the event e.g. ESingleInterfaceEvent. |
|
394 |
|
395 * @param aData Pointer to the TInterfaceNotificationBuf type packaged buffer. Contains |
|
396 |
|
397 * the status of the real interface. |
|
398 |
|
399 */ |
|
400 |
|
401 void EventOccured(TInt aStatus, TEventType aType, TDesC8* aData); |
|
402 |
|
403 |
|
404 |
|
405 protected: // Methods |
|
406 |
|
407 |
|
408 |
|
409 /** |
|
410 |
|
411 * Overwrites the default implementation to catch the ip version reading from the |
|
412 |
|
413 * database. This value is retrieved from the VPN Manager Server. |
|
414 |
|
415 * @param aField Colum name in the CommDb. Ip version colum name is SERVICE_IF_NETWORKS. |
|
416 |
|
417 * @param aValue Value to be returned. In SERVICE_IF_NETWORKS case it's ip or ip6. |
|
418 |
|
419 * @param aMessage Message to validate capabilities |
|
420 |
|
421 * @return Returns KErrNone if the function succeed. Otherwise it returns system wide |
|
422 |
|
423 * error code. |
|
424 |
|
425 */ |
|
426 |
|
427 TInt DoReadDes(const TDesC& aField, TDes16& aValue, const RMessagePtr2* aMessage ); |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 /** |
|
434 |
|
435 * Returns the pointer to the parameter object defined in vpnconnagtdefs.h. |
|
436 |
|
437 * @return The pointer to the connection parameter object. |
|
438 |
|
439 */ |
|
440 |
|
441 TVPNParameters* VPNParameters() { return &iVPNParameters; }; |
|
442 |
|
443 |
|
444 |
|
445 /** |
|
446 |
|
447 * Returns the pointer to the name of the VPN Nif sent by the nif itself. |
|
448 |
|
449 * @return The pointer to the TName type object containing the name of the |
|
450 |
|
451 * VPN Nif. |
|
452 |
|
453 */ |
|
454 |
|
455 TName* VPNNifName(void){ return iVPNParameters.GetVPNNifName();}; |
|
456 |
|
457 |
|
458 |
|
459 /** |
|
460 |
|
461 * Returns the pointer to the interface from the Agent to Nifman. This interface |
|
462 |
|
463 * is used to e.g. send progress notifications from Agent to Nifman. |
|
464 |
|
465 * @return The pointer to the interface from the Agent to Nifman. |
|
466 |
|
467 */ |
|
468 |
|
469 MNifAgentNotify* Notify() { return iNotify; }; |
|
470 |
|
471 |
|
472 |
|
473 /** |
|
474 |
|
475 * After deactivationing/unloading of the VPN Policies Nifman is informed with the |
|
476 |
|
477 * progress call (with EVPNConnAgtDisconnected). |
|
478 |
|
479 * MNifAgentNotify interface's DisconnectComplete() is called (this generates the deletion |
|
480 |
|
481 * of the VPN Nif and at the end deletion of the agent. |
|
482 |
|
483 * |
|
484 |
|
485 */ |
|
486 |
|
487 void VPNDisconnCompleted(TInt aError); |
|
488 |
|
489 |
|
490 |
|
491 private: // Methods |
|
492 |
|
493 |
|
494 |
|
495 /** |
|
496 |
|
497 * Second phase constructor. |
|
498 |
|
499 */ |
|
500 |
|
501 void ConstructL(); |
|
502 |
|
503 |
|
504 |
|
505 /** |
|
506 |
|
507 * Default constructor. |
|
508 |
|
509 */ |
|
510 |
|
511 CVPNConnAgt(); |
|
512 |
|
513 |
|
514 |
|
515 /** |
|
516 |
|
517 * CallBack to start the service (means the connection creation). |
|
518 |
|
519 * @param aThisPtr Pointer to the CVPNConnAgt type object. |
|
520 |
|
521 * @return Always returns KErrNone. |
|
522 |
|
523 */ |
|
524 |
|
525 static TInt ServiceStartedCb(TAny* aThisPtr); |
|
526 |
|
527 |
|
528 |
|
529 /** |
|
530 |
|
531 * CallBack to complete the connection. |
|
532 |
|
533 * @param aThisPtr Pointer to the CVPNConnAgt type object. |
|
534 |
|
535 * @return Always returns KErrNone. |
|
536 |
|
537 */ |
|
538 |
|
539 static TInt ConnectCompleteCb(TAny* aThisPtr); |
|
540 |
|
541 |
|
542 |
|
543 /** |
|
544 |
|
545 * CallBack to disconnect. |
|
546 |
|
547 * @param aThisPtr Pointer to the CVPNConnAgt type object. |
|
548 |
|
549 * @return Always returns KErrNone. |
|
550 |
|
551 */ |
|
552 |
|
553 static TInt DisconnectCompleteCb(TAny* aThisPtr); |
|
554 |
|
555 |
|
556 |
|
557 /** |
|
558 |
|
559 * Reads needed configuration settings from the CommDb database. |
|
560 |
|
561 */ |
|
562 |
|
563 void ReadConfigurationL(); |
|
564 |
|
565 |
|
566 |
|
567 /** |
|
568 |
|
569 * Starts the listening of real interface events. |
|
570 |
|
571 */ |
|
572 |
|
573 void ListenRealIAP(); |
|
574 |
|
575 |
|
576 |
|
577 /** |
|
578 |
|
579 * Starts the listening of virtual nif address change event. |
|
580 |
|
581 */ |
|
582 |
|
583 void ListenAddressChange(); |
|
584 |
|
585 |
|
586 |
|
587 /** |
|
588 |
|
589 * Cancels the listening of the real interface events and the |
|
590 |
|
591 * listening of virtual nif address change event. |
|
592 |
|
593 */ |
|
594 |
|
595 void CancelListeners(); |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 private: |
|
602 |
|
603 |
|
604 |
|
605 /** |
|
606 |
|
607 * Defines the internal states. |
|
608 |
|
609 */ |
|
610 |
|
611 enum TRequestState |
|
612 |
|
613 { |
|
614 |
|
615 EGettingProtocolVersion, |
|
616 |
|
617 EConnecting, |
|
618 |
|
619 EConnected, |
|
620 |
|
621 EClosingConnection, |
|
622 |
|
623 EConnectionClosed, |
|
624 |
|
625 EStartingRealIf, |
|
626 |
|
627 EListeningEvents, |
|
628 |
|
629 EIdle |
|
630 |
|
631 }; |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 /** CallBack object to implement ServiceStarted asynchronously. */ |
|
638 |
|
639 CAsyncCallBack iServiceStartedCallback; |
|
640 |
|
641 |
|
642 |
|
643 /** CallBack object to implement ConnectCompleted asynchronously. */ |
|
644 |
|
645 CAsyncCallBack iConnectCompleteCallback; |
|
646 |
|
647 |
|
648 |
|
649 /** CallBack object to implement Disconnect asynchronously. */ |
|
650 |
|
651 CAsyncCallBack iDisconnectCallback; |
|
652 |
|
653 |
|
654 |
|
655 /** Defines wether Agent is connected (Connection completed successfully). */ |
|
656 |
|
657 TBool iConnected; |
|
658 |
|
659 |
|
660 |
|
661 /** Connection configuration parameter member object. See vpnconnagtdefs.h. */ |
|
662 |
|
663 TVPNParameters iVPNParameters; |
|
664 |
|
665 |
|
666 |
|
667 /** An integer to keep last error code in memory. */ |
|
668 |
|
669 TInt iLastErrorCode; |
|
670 |
|
671 |
|
672 |
|
673 /** An API to EventMediator */ |
|
674 |
|
675 REventMediator iEventMediator; |
|
676 |
|
677 |
|
678 |
|
679 /** Tells if vpnconnagt must close tunnelnif */ |
|
680 |
|
681 TBool iEventActivatedClose; |
|
682 |
|
683 |
|
684 |
|
685 /** This defines the shutdown type to the kmd. Value 0 is normal and 1 is to |
|
686 |
|
687 force it to shutdown without trying to send any packets anymore */ |
|
688 |
|
689 TDeactivateType iDisconnectType; |
|
690 |
|
691 |
|
692 |
|
693 /* State of the agent object */ |
|
694 |
|
695 TRequestState iState; |
|
696 |
|
697 |
|
698 |
|
699 /** Boolean to define wether disconnecting operation is ongoing */ |
|
700 |
|
701 TBool iDisconnecting; |
|
702 |
|
703 |
|
704 |
|
705 /** PckgBufs used when creating connection through eventmediator api */ |
|
706 |
|
707 TPckgBuf<TGetProtocolVersionEventSpec> iProtocolVersionDes; |
|
708 |
|
709 TPckgBuf<TStartVpnConnEventSpec> iStartVpnConnDes; |
|
710 |
|
711 TPckgBuf<TCloseVpnConnEventSpec> iCloseVpnConnDes; |
|
712 |
|
713 TPckgBuf<TObserveRealIapConnEventSpec> iObserveRealIapConnDes; |
|
714 |
|
715 |
|
716 |
|
717 /** Poiter to an object which confirms disconnect operation to Nifman */ |
|
718 |
|
719 CAsyncDisconnecter* iAD; |
|
720 |
|
721 }; |
|
722 |
|
723 |
|
724 |
|
725 class CAsyncDisconnecter : public CAsyncOneShot |
|
726 |
|
727 { |
|
728 |
|
729 /** |
|
730 |
|
731 @internalComponent |
|
732 |
|
733 */ |
|
734 |
|
735 public: |
|
736 |
|
737 static CAsyncDisconnecter* NewL(CVPNConnAgt* aAgent); |
|
738 |
|
739 void ConfirmDisconnect(); |
|
740 |
|
741 |
|
742 |
|
743 private: |
|
744 |
|
745 CAsyncDisconnecter(CVPNConnAgt* aAgent); |
|
746 |
|
747 void RunL(); // From CAsyncOneShot |
|
748 |
|
749 |
|
750 |
|
751 private: |
|
752 |
|
753 CVPNConnAgt* iAgent; |
|
754 |
|
755 }; |
|
756 |
|
757 |
|
758 |
|
759 #endif // VPN_CONN_AGT_H |
|
760 |