|
1 /* |
|
2 * Copyright (c) 2008-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: active object, that monitors activating |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ikedebug.h" |
|
20 #include "ikepolparser.h" |
|
21 #include "internaladdress.h" |
|
22 #include "vpnconnection.h" |
|
23 |
|
24 // CLASS HEADER |
|
25 #include "activationstarter.h" |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // Two-phased constructor. |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CActivationStarter* CActivationStarter::NewL( CVpnConnection& aConnection, |
|
34 MActivationStarterCallback& aCallback, |
|
35 MIkeDebug& aDebug ) |
|
36 { |
|
37 CActivationStarter* self = new ( ELeave ) CActivationStarter( aConnection, |
|
38 aCallback, |
|
39 aDebug ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // Destructor. |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CActivationStarter::~CActivationStarter() |
|
48 { |
|
49 Cancel(); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Constructor. |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CActivationStarter::CActivationStarter( CVpnConnection& aConnection, |
|
57 MActivationStarterCallback& aCallback, |
|
58 MIkeDebug& aDebug ) |
|
59 : CActive( EPriorityStandard ), |
|
60 iConnection( aConnection ), |
|
61 iCallback( aCallback ), |
|
62 iDebug( aDebug ) |
|
63 { |
|
64 CActiveScheduler::Add( this ); |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // Starts asynchronous activating. |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CActivationStarter::Activate( CIkeData& aIkeData, |
|
72 const TDesC& aVpnIfName ) |
|
73 { |
|
74 TUint32 vpnInterfaceIndex( 0 ); |
|
75 TInt err = GetVpnInterfaceIndex( aVpnIfName, |
|
76 vpnInterfaceIndex ); |
|
77 |
|
78 if ( err != KErrNone ) |
|
79 { |
|
80 TRequestStatus* status = &iStatus; |
|
81 *status = KRequestPending; |
|
82 SetActive(); |
|
83 |
|
84 User::RequestComplete( status, err ); |
|
85 return; |
|
86 } |
|
87 |
|
88 TInetAddr remoteAddr = aIkeData.iAddr; |
|
89 iIpVersion = IkeSocket::EIPv4; |
|
90 if ( remoteAddr.Family() == KAfInet6 && |
|
91 !remoteAddr.IsV4Mapped() ) |
|
92 { |
|
93 iIpVersion = IkeSocket::EIPv6; |
|
94 } |
|
95 iDnsServerAddr = aIkeData.iDnsServer; |
|
96 |
|
97 iConnection.NegotiateWithHost( aIkeData, |
|
98 vpnInterfaceIndex, |
|
99 iIpVersion, |
|
100 iInternalAddress, |
|
101 iStatus ); |
|
102 SetActive(); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // Gets VPN interface index. |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 TInt CActivationStarter::GetVpnInterfaceIndex( const TDesC& aVpnIfName, |
|
110 TUint32& aVpnInterfaceIndex ) |
|
111 { |
|
112 TInt err( KErrNone ); |
|
113 RSocketServ ss; |
|
114 err = ss.Connect(); |
|
115 |
|
116 if ( err == KErrNone ) |
|
117 { |
|
118 RSocket socket; |
|
119 err = socket.Open( ss, |
|
120 KAfInet, |
|
121 KSockDatagram, |
|
122 KProtocolInetIp ); |
|
123 |
|
124 if ( err == KErrNone ) |
|
125 { |
|
126 TPckgBuf<TSoInetIfQuery> opt; |
|
127 opt().iName = aVpnIfName; |
|
128 |
|
129 err = socket.GetOpt( KSoInetIfQueryByName, |
|
130 KSolInetIfQuery, |
|
131 opt ); |
|
132 if ( err == KErrNone ) |
|
133 { |
|
134 aVpnInterfaceIndex = opt().iZone[0]; // VPN Interface index |
|
135 } |
|
136 } |
|
137 socket.Close(); |
|
138 } |
|
139 |
|
140 ss.Close(); |
|
141 return err; |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // From class CActive |
|
146 // Handles completion of asynchronous activating. |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CActivationStarter::RunL() |
|
150 { |
|
151 TInt err( iStatus.Int() ); |
|
152 |
|
153 if ( err == KErrNone ) |
|
154 { |
|
155 if ( iInternalAddress.iVPNIfAddr.IsUnspecified() ) |
|
156 { |
|
157 TInetAddr localAddr; |
|
158 err = iConnection.GetLocalAddress( iIpVersion, localAddr ); |
|
159 |
|
160 if ( err == KErrNone ) |
|
161 { |
|
162 iInternalAddress.iVPNIfAddr = localAddr; |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 if ( err == KErrNone && |
|
168 iInternalAddress.iVPNIfDNS1.IsUnspecified() ) |
|
169 { |
|
170 if ( iDnsServerAddr.Address() != KAFUnspec ) |
|
171 { |
|
172 #ifdef _DEBUG |
|
173 TBuf<39> addrBuf; |
|
174 iDnsServerAddr.OutputWithScope( addrBuf ); |
|
175 DEBUG_LOG1(_L("DNS Server Address in IKE data %S"), &addrBuf); |
|
176 #endif //_DEBUG |
|
177 iInternalAddress.iVPNIfDNS1 = iDnsServerAddr; |
|
178 } |
|
179 else |
|
180 { |
|
181 DEBUG_LOG(_L("DNS server not defined in policy")); |
|
182 } |
|
183 } |
|
184 |
|
185 iCallback.ActivationCompleted( err, iInternalAddress ); |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // From class CActive |
|
190 // Handles cancellation of asynchronous activating. |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 void CActivationStarter::DoCancel() |
|
194 { |
|
195 iConnection.CancelNegotiateWithHost(); |
|
196 } |
|
197 |