|
1 /* |
|
2 * Copyright (c) 2002-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: Implements WLAN meta connection provider |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 8 % |
|
20 */ |
|
21 |
|
22 #include <comms-infras/ss_log.h> |
|
23 #include <comms-infras/agentmcpractivities.h> |
|
24 #include <comms-infras/coremcpractivities.h> |
|
25 #include <comms-infras/ss_tiermanagerutils.h> |
|
26 #include <comms-infras/ss_msgintercept.h> |
|
27 #include "wlanmcpr.h" |
|
28 #include "WlanProvision.h" |
|
29 #include "am_debug.h" |
|
30 |
|
31 |
|
32 using namespace ESock; |
|
33 using namespace NetStateMachine; |
|
34 using namespace MCprActivities; |
|
35 using namespace WlanMCprStates; |
|
36 using namespace Messages; |
|
37 |
|
38 |
|
39 |
|
40 // No Bearer Activity |
|
41 namespace WlanMCPRNoBearerActivity |
|
42 { |
|
43 DECLARE_DEFINE_NODEACTIVITY(ECFActivityNoBearer, WlanMCPRNoBearer, TCFControlProvider::TNoBearer) |
|
44 FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingNoBearer, MeshMachine::TNoTag) |
|
45 LAST_NODEACTIVITY_ENTRY(MeshMachine::KNoTag, CoreNetStates::TSendBearer) |
|
46 NODEACTIVITY_END() |
|
47 } |
|
48 |
|
49 |
|
50 |
|
51 // Activity Map |
|
52 namespace WlanMCprStates |
|
53 { |
|
54 DEFINE_EXPORT_ACTIVITY_MAP(stateMap) |
|
55 ACTIVITY_MAP_ENTRY(WlanMCPRNoBearerActivity, WlanMCPRNoBearer) |
|
56 ACTIVITY_MAP_END_BASE(AgentMCprActivities, agentMCprActivities) |
|
57 } // namespace WlanMCprStates |
|
58 |
|
59 //-========================================================= |
|
60 // |
|
61 //CWlanMetaConnectionProvider implementation |
|
62 // |
|
63 //-========================================================= |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CWlanMetaConnectionProvider::NewL |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 EXPORT_C CWlanMetaConnectionProvider* CWlanMetaConnectionProvider::NewL(ESock::CMetaConnectionProviderFactoryBase& aFactory, const TProviderInfo& aProviderInfo) |
|
70 { |
|
71 CWlanMetaConnectionProvider* self = new (ELeave) CWlanMetaConnectionProvider(aFactory, aProviderInfo, WlanMCprStates::stateMap::Self()); |
|
72 CleanupStack::PushL(self); |
|
73 self->ConstructL(); |
|
74 CleanupStack::Pop(self); |
|
75 return self; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CWlanMetaConnectionProvider::ConstructL |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C void CWlanMetaConnectionProvider::ConstructL() |
|
83 { |
|
84 CAgentMetaConnectionProvider::ConstructL(); |
|
85 SetAccessPointConfigFromDbL(); |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CWlanMetaConnectionProvider::CWlanMetaConnectionProvider |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C CWlanMetaConnectionProvider::CWlanMetaConnectionProvider(CMetaConnectionProviderFactoryBase& aFactory, |
|
93 const ESock::TProviderInfo& aProviderInfo, |
|
94 const MeshMachine::TNodeActivityMap& aActivityMap) |
|
95 : CAgentMetaConnectionProvider(aFactory,aProviderInfo,aActivityMap) |
|
96 { |
|
97 |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CWlanMetaConnectionProvider::~CWlanMetaConnectionProvider |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 EXPORT_C CWlanMetaConnectionProvider::~CWlanMetaConnectionProvider() |
|
105 { |
|
106 |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CWlanMetaConnectionProvider::ReceivedL |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C void CWlanMetaConnectionProvider::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage) |
|
114 { |
|
115 DEBUG1("CWlanMetaConnectionProvider::ReceivedL, aCFMessage=%d", aMessage.MessageId().MessageId()); |
|
116 |
|
117 //ESOCK_DEBUG_MESSAGE_INTERCEPT(aSender, aMessage, aRecipient); |
|
118 |
|
119 MeshMachine::TNodeContext<CWlanMetaConnectionProvider> ctx(*this, aMessage, aSender, aRecipient); |
|
120 CCoreMetaConnectionProvider::Received(ctx); |
|
121 User::LeaveIfError(ctx.iReturn); |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CWlanMetaConnectionProvider::SetAccessPointConfigFromDbL |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void CWlanMetaConnectionProvider::SetAccessPointConfigFromDbL() |
|
129 { |
|
130 DEBUG("CWlanMetaConnectionProvider::SetAccessPointConfigFromDbL"); |
|
131 |
|
132 RMetaExtensionContainer mec; |
|
133 static_cast<void>(mec.Open(AccessPointConfig())); |
|
134 CleanupClosePushL(mec); |
|
135 |
|
136 // Open an IAP specific view on CommsDat |
|
137 CCommsDatIapView* iapView = OpenIapViewLC(); |
|
138 |
|
139 // Presumptions: |
|
140 // - none of the extensions can already exist in the AccessPointConfig array. AppendExtensionL() |
|
141 // is presumed to panic if adding the same extension a second time. |
|
142 // - if we have added several extensions to the AccessPointConfig array before getting a failure |
|
143 // and leaving, it is presumed that the MCPr will be destroyed and AccessPointConfig destructor |
|
144 // will clean up the extensions immediately afterwards. |
|
145 |
|
146 ProvisionNetworkConfigL(iapView, mec); |
|
147 |
|
148 CleanupStack::PopAndDestroy(); // CloseIapView(); |
|
149 |
|
150 AccessPointConfig().Close(); |
|
151 AccessPointConfig().Open(mec); |
|
152 CleanupStack::PopAndDestroy(&mec); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CWlanMetaConnectionProvider::ProvisionNetworkConfigL |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void CWlanMetaConnectionProvider::ProvisionNetworkConfigL(CCommsDatIapView* aIapView, ESock::RMetaExtensionContainer& aMec) |
|
160 { |
|
161 HBufC* buf = NULL; |
|
162 aIapView->GetTextL(KCDTIdLANIfNetworks, buf); |
|
163 CleanupStack::PushL(buf); |
|
164 if (buf->Length() == 0) |
|
165 { |
|
166 User::Leave(KErrCorrupt); |
|
167 } |
|
168 |
|
169 TPtrC16 networks; |
|
170 networks.Set(*buf); |
|
171 TPtrC16 current; |
|
172 TUint32 order = 0; |
|
173 TInt commaPos = 0; |
|
174 while (commaPos != KErrNotFound) |
|
175 { |
|
176 commaPos = networks.LocateF(','); |
|
177 if (commaPos == KErrNotFound) |
|
178 { |
|
179 // take all of string |
|
180 current.Set(networks); |
|
181 } |
|
182 else |
|
183 { |
|
184 current.Set(networks.Ptr(), commaPos); |
|
185 } |
|
186 |
|
187 if (!current.CompareF(_L("ip"))) |
|
188 { |
|
189 ProvisionIp4ConfigL(aIapView, order, aMec); |
|
190 } |
|
191 else if (!current.CompareF(_L("ip6"))) |
|
192 { |
|
193 ProvisionIp6ConfigL(aIapView, order, aMec); |
|
194 } |
|
195 else |
|
196 { |
|
197 User::Leave(KErrCorrupt); |
|
198 } |
|
199 |
|
200 order++; |
|
201 networks.Set(networks.Mid(commaPos+1)); |
|
202 } |
|
203 |
|
204 CleanupStack::PopAndDestroy(buf); |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CWlanMetaConnectionProvider::ProvisionIp4ConfigL |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CWlanMetaConnectionProvider::ProvisionIp4ConfigL(CCommsDatIapView* aIapView, TUint32 aOrder, ESock::RMetaExtensionContainer& aMec) |
|
212 { |
|
213 TLanIp4Provision* ip4Provision = new (ELeave) TLanIp4Provision; |
|
214 CleanupStack::PushL(ip4Provision); |
|
215 |
|
216 ip4Provision->SetOrder(aOrder); |
|
217 |
|
218 // Read IP address configuration parameters |
|
219 TBool serverRequired; |
|
220 aIapView->GetBoolL(KCDTIdLANIpAddrFromServer, serverRequired); |
|
221 |
|
222 TUint32 addr; |
|
223 TInt err; |
|
224 |
|
225 ip4Provision->SetLocalAddr(KInetAddrNone); |
|
226 ip4Provision->SetNetMask(KInetAddrNone); |
|
227 ip4Provision->SetDefGateway(KInetAddrNone); |
|
228 |
|
229 if (!serverRequired) |
|
230 { |
|
231 GetIp4AddrL(aIapView, KCDTIdLANIpAddr, addr); |
|
232 ip4Provision->SetLocalAddr(addr); |
|
233 GetIp4AddrL(aIapView, KCDTIdLANIpNetMask, addr); |
|
234 ip4Provision->SetNetMask(addr); |
|
235 |
|
236 err = GetIp4Addr(aIapView, KCDTIdLANIpGateway, addr); |
|
237 if (err == KErrNone) |
|
238 { |
|
239 ip4Provision->SetDefGateway(addr); |
|
240 } |
|
241 else if (err == KErrNotFound) |
|
242 { |
|
243 ip4Provision->SetDefGateway(ip4Provision->LocalAddr()); |
|
244 } |
|
245 else |
|
246 { |
|
247 User::Leave(err); |
|
248 } |
|
249 |
|
250 // Because CommDB doesn't define a Broadcast Address field, we must |
|
251 // calculate the broadcast address. This is based on the localAddr |
|
252 // and the netMask. |
|
253 |
|
254 TInetAddr localAddr(ip4Provision->LocalAddr(), 0); |
|
255 TInetAddr netMask(ip4Provision->NetMask(), 0); |
|
256 TInetAddr broadcast; |
|
257 broadcast.SubNetBroadcast(ip4Provision->LocalAddr(), ip4Provision->NetMask()); |
|
258 ip4Provision->SetBroadcastAddr(broadcast.Address()); |
|
259 } |
|
260 |
|
261 ip4Provision->SetPrimaryDns(KInetAddrNone); |
|
262 ip4Provision->SetSecondaryDns(KInetAddrNone); |
|
263 |
|
264 aIapView->GetBoolL(KCDTIdLANIpDNSAddrFromServer, serverRequired); |
|
265 if (!serverRequired) |
|
266 { |
|
267 err = GetIp4Addr(aIapView, KCDTIdLANIpNameServer1, addr); |
|
268 if (err == KErrNone) |
|
269 { |
|
270 ip4Provision->SetPrimaryDns(addr); |
|
271 err = GetIp4Addr(aIapView, KCDTIdLANIpNameServer2, addr); |
|
272 if (err == KErrNone) |
|
273 { |
|
274 ip4Provision->SetSecondaryDns(addr); |
|
275 } |
|
276 } |
|
277 |
|
278 if (err != KErrNone && err != KErrNotFound) |
|
279 { |
|
280 User::Leave(err); |
|
281 } |
|
282 } |
|
283 |
|
284 // Append the provisioning object to the CAccessPointConfig array |
|
285 aMec.AppendExtensionL(ip4Provision); |
|
286 CleanupStack::Pop(ip4Provision); |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CWlanMetaConnectionProvider::ProvisionIp6ConfigL |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 void CWlanMetaConnectionProvider::ProvisionIp6ConfigL(CCommsDatIapView* aIapView, TUint32 aOrder, ESock::RMetaExtensionContainer& aMec) |
|
294 { |
|
295 TLanIp6Provision* ip6Provision = new (ELeave) TLanIp6Provision; |
|
296 CleanupStack::PushL(ip6Provision); |
|
297 |
|
298 ip6Provision->SetOrder(aOrder); |
|
299 |
|
300 // Determine whether static DNS configuration is required. |
|
301 TBool dynamicDns = ETrue; |
|
302 |
|
303 // By default, Ensure that static DNS addresses are set as unspecified, |
|
304 // so they are not used in Control(KSoIfConfig). |
|
305 ip6Provision->SetPrimaryDns(KInet6AddrNone); |
|
306 ip6Provision->SetSecondaryDns(KInet6AddrNone); |
|
307 |
|
308 // Ignore any errors from reading this field - default to dynamicDns = ETrue |
|
309 (void) aIapView->GetBool(KCDTIdLANIp6DNSAddrFromServer, dynamicDns); |
|
310 |
|
311 if (!dynamicDns) |
|
312 { |
|
313 // Read static DNS addresses |
|
314 TInt err; |
|
315 TIp6Addr addr6; |
|
316 err = GetIp6Addr(aIapView, KCDTIdLANIpNameServer1, addr6); |
|
317 if (err == KErrNone) |
|
318 { |
|
319 ip6Provision->SetPrimaryDns(addr6); |
|
320 err = GetIp6Addr(aIapView, KCDTIdLANIpNameServer2, addr6); |
|
321 if (err == KErrNone) |
|
322 { |
|
323 ip6Provision->SetSecondaryDns(addr6); |
|
324 } |
|
325 } |
|
326 |
|
327 if (err != KErrNone && err != KErrNotFound) |
|
328 { |
|
329 User::Leave(err); |
|
330 } |
|
331 } |
|
332 |
|
333 // Append the provisioning object to the CAccessPointConfig array |
|
334 aMec.AppendExtensionL(ip6Provision); |
|
335 CleanupStack::Pop(ip6Provision); |
|
336 } |
|
337 |
|
338 |