|
1 /** |
|
2 * Copyright (c) 2010 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: |
|
15 * Provision implemtation for Ipv4 and Ipv6 binders for tundriver. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 /** |
|
21 @file tundriverprovision.cpp |
|
22 @internalTechnology |
|
23 */ |
|
24 |
|
25 #include <comms-infras/ss_log.h> |
|
26 #include <in_sock.h> |
|
27 #include <comms-infras/metadata.h> |
|
28 #include <comms-infras/coremcpractivities.h> |
|
29 #include <comms-infras/ss_tiermanagerutils.h> |
|
30 #include "tundrivermcpr.h" |
|
31 #include "tundriverprovision.h" |
|
32 |
|
33 using namespace ESock; |
|
34 |
|
35 void CTunDriverProtoProvision::InitialiseConfigL(CCommsDatIapView* aIapView) |
|
36 /** |
|
37 * CTunDriverProtoProvision::InitialiseConfigL is called from TunDriver MCPR to initialze |
|
38 * tundriver with values from comms database. |
|
39 * @param aIapView |
|
40 * @returns |
|
41 */ |
|
42 { |
|
43 ProvisionNetworkConfigL(aIapView); |
|
44 } |
|
45 |
|
46 void CTunDriverProtoProvision::ProvisionNetworkConfigL(CCommsDatIapView* aIapView) |
|
47 /** |
|
48 * CTunDriverProtoProvision::ProvisionNetworkConfigL is called from TunDriver MCPR to identify |
|
49 * tundriver is associated with protocol IPv4 or IPv6 |
|
50 * @param aIapView |
|
51 * @returns |
|
52 */ |
|
53 { |
|
54 HBufC* buf = NULL; |
|
55 aIapView->GetTextL(KCDTIdLANIfNetworks, buf); |
|
56 CleanupStack::PushL(buf); |
|
57 if (buf->Length() == 0) |
|
58 { |
|
59 User::Leave(KErrCorrupt); |
|
60 } |
|
61 |
|
62 TPtrC16 networks; |
|
63 networks.Set(*buf); |
|
64 TPtrC16 current; |
|
65 TUint32 order = 0; |
|
66 TInt commaPos = 0; |
|
67 while (commaPos != KErrNotFound) |
|
68 { |
|
69 commaPos = networks.LocateF(','); |
|
70 if (commaPos == KErrNotFound) |
|
71 { |
|
72 // take all of string |
|
73 current.Set(networks); |
|
74 } |
|
75 else |
|
76 { |
|
77 current.Set(networks.Ptr(), commaPos); |
|
78 } |
|
79 |
|
80 if (current.CompareF(_L("ip")) == KErrNone) |
|
81 { |
|
82 ProvisionIp4ConfigL(aIapView, order); |
|
83 } |
|
84 #ifdef IPV6SUPPORT |
|
85 else if (current.CompareF(_L("ip6")) == KErrNone) |
|
86 { |
|
87 ProvisionIp6ConfigL(aIapView, order); |
|
88 } |
|
89 #endif |
|
90 else |
|
91 { |
|
92 User::Leave(KErrCorrupt); |
|
93 } |
|
94 |
|
95 order++; |
|
96 networks.Set(networks.Mid(commaPos+1)); |
|
97 } |
|
98 |
|
99 CleanupStack::PopAndDestroy(buf); |
|
100 } |
|
101 |
|
102 |
|
103 void CTunDriverProtoProvision::ProvisionIp4ConfigL(CCommsDatIapView* aIapView, TUint32 aOrder) |
|
104 /** |
|
105 * CTunDriverProtoProvision::ProvisionIp4ConfigL will initialize with IPv4 Header values |
|
106 * for tundriver IPv4 configuration. like IPaddress, NetMask, Gateway and DNS Address. |
|
107 * @param aIapView |
|
108 * @returns |
|
109 */ |
|
110 { |
|
111 iIp4Provision.SetOrder(aOrder); |
|
112 |
|
113 // Read IP address configuration parameters |
|
114 TBool serverRequired; |
|
115 aIapView->GetBoolL(KCDTIdLANIpAddrFromServer, serverRequired); |
|
116 |
|
117 TUint32 addr; |
|
118 TInt err; |
|
119 |
|
120 iIp4Provision.SetLocalAddr(KInetAddrNone); |
|
121 iIp4Provision.SetNetMask(KInetAddrNone); |
|
122 iIp4Provision.SetDefGateway(KInetAddrNone); |
|
123 iIp4Provision.SetPrimaryDns(KInetAddrNone); |
|
124 iIp4Provision.SetSecondaryDns(KInetAddrNone); |
|
125 if (!serverRequired) |
|
126 { |
|
127 CAgentMetaConnectionProvider::GetIp4AddrL(aIapView, KCDTIdLANIpAddr, addr); |
|
128 TInetAddr v4MappedAddr; |
|
129 v4MappedAddr.SetV4MappedAddress(addr); |
|
130 iIp4Provision.SetLocalAddr(v4MappedAddr); |
|
131 err = CAgentMetaConnectionProvider::GetIp4Addr(aIapView, KCDTIdLANIpNetMask, addr); |
|
132 if (err == KErrNone) |
|
133 { |
|
134 v4MappedAddr.SetV4MappedAddress(addr); |
|
135 iIp4Provision.SetNetMask(v4MappedAddr); |
|
136 } |
|
137 |
|
138 err = CAgentMetaConnectionProvider::GetIp4Addr(aIapView, KCDTIdLANIpGateway, addr); |
|
139 if (err == KErrNone) |
|
140 { |
|
141 v4MappedAddr.SetV4MappedAddress(addr); |
|
142 iIp4Provision.SetDefGateway(v4MappedAddr); |
|
143 } |
|
144 else if (err == KErrNotFound || err == KErrArgument) |
|
145 { |
|
146 iIp4Provision.SetDefGateway(iIp4Provision.LocalAddr()); |
|
147 } |
|
148 else |
|
149 { |
|
150 User::Leave(err); |
|
151 } |
|
152 |
|
153 // Because CommDB doesn't define a Broadcast Address field, we must |
|
154 // calculate the broadcast address. This is based on the localAddr |
|
155 // and the netMask. |
|
156 |
|
157 TInetAddr localAddr; |
|
158 localAddr.SetV4MappedAddress(iIp4Provision.LocalAddr().Address()); |
|
159 localAddr.SetPort(0); |
|
160 TInetAddr netMask; |
|
161 netMask.SetV4MappedAddress(iIp4Provision.NetMask().Address()); |
|
162 netMask.SetPort(0); |
|
163 TInetAddr broadcast; |
|
164 broadcast.SubNetBroadcast(localAddr, netMask); |
|
165 iIp4Provision.SetBroadcastAddr(broadcast.Address()); |
|
166 } |
|
167 |
|
168 aIapView->GetBoolL(KCDTIdLANIpDNSAddrFromServer, serverRequired); |
|
169 if (!serverRequired) |
|
170 { |
|
171 err = CAgentMetaConnectionProvider::GetIp4Addr(aIapView, KCDTIdLANIpNameServer1, addr); |
|
172 if (err == KErrNone) |
|
173 { |
|
174 TInetAddr primaryDns; |
|
175 primaryDns.SetV4MappedAddress(addr); |
|
176 iIp4Provision.SetPrimaryDns(primaryDns); |
|
177 err = CAgentMetaConnectionProvider::GetIp4Addr(aIapView, KCDTIdLANIpNameServer2, addr); |
|
178 if (err == KErrNone) |
|
179 { |
|
180 TInetAddr secondaryDns; |
|
181 secondaryDns.SetV4MappedAddress(addr); |
|
182 iIp4Provision.SetSecondaryDns(secondaryDns); |
|
183 } |
|
184 } |
|
185 |
|
186 if (err != KErrNone && err != KErrNotFound && err != KErrArgument) |
|
187 { |
|
188 User::Leave(err); |
|
189 } |
|
190 } |
|
191 } |
|
192 |
|
193 #ifdef IPV6SUPPORT |
|
194 void CTunDriverProtoProvision::ProvisionIp6ConfigL(CCommsDatIapView* aIapView, TUint32 aOrder) |
|
195 /** |
|
196 * CTunDriverProtoProvision::ProvisionIp6ConfigL will initialize with IPv4 Header values |
|
197 * for tundriver IPv6 configuration. like IPaddress, NetMask, Gateway and DNS Address. |
|
198 * @param aIapView |
|
199 * @returns |
|
200 */ |
|
201 { |
|
202 iIp6Provision.SetOrder(aOrder); |
|
203 |
|
204 // Read IP address configuration parameters |
|
205 TBool serverRequired; |
|
206 aIapView->GetBoolL(KCDTIdLANIpAddrFromServer, serverRequired); |
|
207 |
|
208 TIp6Addr addr; |
|
209 TInetAddr inetAddress; |
|
210 TInt err; |
|
211 |
|
212 iIp6Provision.SetLocalAddr(KInetAddrNone); |
|
213 iIp6Provision.SetNetMask(KInetAddrNone); |
|
214 iIp6Provision.SetDefGateway(KInetAddrNone); |
|
215 iIp6Provision.SetPrimaryDns(KInetAddrNone); |
|
216 iIp6Provision.SetSecondaryDns(KInetAddrNone); |
|
217 if (!serverRequired) |
|
218 { |
|
219 CAgentMetaConnectionProvider::GetIp6AddrL(aIapView, KCDTIdLANIpAddr, addr); |
|
220 inetAddress.SetAddress(addr); |
|
221 iIp6Provision.SetLocalAddr(inetAddress); |
|
222 err = CAgentMetaConnectionProvider::GetIp6Addr(aIapView, KCDTIdLANIpNetMask, addr); |
|
223 if (err == KErrNone) |
|
224 { |
|
225 inetAddress.SetAddress(addr); |
|
226 iIp6Provision.SetNetMask(inetAddress); |
|
227 } |
|
228 err = CAgentMetaConnectionProvider::GetIp6Addr(aIapView, KCDTIdLANIpGateway, addr); |
|
229 if (err == KErrNone) |
|
230 { |
|
231 inetAddress.SetAddress(addr); |
|
232 iIp6Provision.SetDefGateway(inetAddress); |
|
233 } |
|
234 else if (err == KErrNotFound || err == KErrArgument) |
|
235 { |
|
236 iIp6Provision.SetDefGateway(iIp6Provision.LocalAddr()); |
|
237 } |
|
238 else |
|
239 { |
|
240 User::Leave(err); |
|
241 } |
|
242 err = CAgentMetaConnectionProvider::GetIp6Addr(aIapView, KCDTIdLANIpNameServer1, addr); |
|
243 if(err == KErrNone) |
|
244 { |
|
245 inetAddress.SetAddress(addr); |
|
246 iIp6Provision.SetPrimaryDns(inetAddress); |
|
247 } |
|
248 else |
|
249 { |
|
250 User::LeaveIfError(err); |
|
251 } |
|
252 err = CAgentMetaConnectionProvider::GetIp6Addr(aIapView, KCDTIdLANIpNameServer2, addr); |
|
253 if(err == KErrNone) |
|
254 { |
|
255 inetAddress.SetAddress(addr); |
|
256 iIp6Provision.SetSecondaryDns(inetAddress); |
|
257 } |
|
258 else |
|
259 { |
|
260 User::LeaveIfError(err); |
|
261 } |
|
262 // Because CommDB doesn't define a Broadcast Address field, we must |
|
263 // calculate the broadcast address. This is based on the localAddr |
|
264 // and the netMask. |
|
265 |
|
266 TInetAddr localAddr; |
|
267 localAddr = iIp6Provision.LocalAddr(); |
|
268 localAddr.SetPort(0); |
|
269 TInetAddr netMask; |
|
270 netMask = iIp6Provision.NetMask(); |
|
271 netMask.SetPort(0); |
|
272 TInetAddr broadcast; |
|
273 broadcast.SubNetBroadcast(localAddr, netMask); |
|
274 iIp6Provision.SetBroadcastAddr(broadcast); |
|
275 } |
|
276 |
|
277 iIp6Provision.SetPrimaryDns(KInetAddrNone); |
|
278 iIp6Provision.SetSecondaryDns(KInetAddrNone); |
|
279 |
|
280 aIapView->GetBoolL(KCDTIdLANIpDNSAddrFromServer, serverRequired); |
|
281 if (!serverRequired) |
|
282 { |
|
283 err = CAgentMetaConnectionProvider::GetIp6Addr(aIapView, KCDTIdLANIpNameServer1, addr); |
|
284 if (err == KErrNone) |
|
285 { |
|
286 inetAddress.SetAddress(addr); |
|
287 iIp6Provision.SetPrimaryDns(inetAddress); |
|
288 err = CAgentMetaConnectionProvider::GetIp6Addr(aIapView, KCDTIdLANIpNameServer2, addr); |
|
289 if (err == KErrNone) |
|
290 { |
|
291 inetAddress.SetAddress(addr); |
|
292 iIp6Provision.SetSecondaryDns(inetAddress); |
|
293 } |
|
294 } |
|
295 |
|
296 if (err != KErrNone && err != KErrNotFound && err != KErrArgument) |
|
297 { |
|
298 User::Leave(err); |
|
299 } |
|
300 } |
|
301 } |
|
302 #endif |
|
303 |
|
304 // |
|
305 // Attribute table for provisioning structures passed to CFProtocol |
|
306 // |
|
307 |
|
308 START_ATTRIBUTE_TABLE(CTunDriverProtoProvision, CTunDriverProtoProvision::EUid, CTunDriverProtoProvision::ETypeId) |
|
309 // no attributes defined as no serialisation takes place. |
|
310 END_ATTRIBUTE_TABLE() |