|
1 /* |
|
2 * Copyright (c) 2008-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: Provider WLAN search and SNAP handling functionality |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Search WLAN |
|
20 #include <cmmanagerdef.h> |
|
21 #include <cmpluginwlandef.h> // bearer type |
|
22 #include <cmdestinationext.h> |
|
23 #include <cmconnectionmethoddef.h> |
|
24 #include <ConnectionUiUtilities.h> |
|
25 #include <cmconnectionmethodext.h> |
|
26 #include <WEPSecuritySettingsUI.h> |
|
27 #include <WPASecuritySettingsUI.h> |
|
28 #include <cmmanager.h> |
|
29 #include <cmpluginpacketdatadef.h> |
|
30 |
|
31 #include "cchuilogger.h" |
|
32 #include "cchuicchhandler.h" |
|
33 #include "cchuispshandler.h" |
|
34 #include "cchuiconnectionhandler.h" |
|
35 |
|
36 const TInt KSsidLength = 256; |
|
37 const TInt KCmHighestPriority = 0; |
|
38 const TInt KDestinationArrayGranularity = 10; |
|
39 |
|
40 |
|
41 // ======== MEMBER FUNCTIONS ======== |
|
42 |
|
43 CCchUiConnectionHandler::CCchUiConnectionHandler( |
|
44 CCchUiCchHandler& aCchHandler, |
|
45 CCchUiSpsHandler& aSpsHandler ): |
|
46 iCCHHandler( aCchHandler ), |
|
47 iSpsHandler( aSpsHandler ), |
|
48 iSearchWlanOngoing( EFalse ) |
|
49 { |
|
50 } |
|
51 |
|
52 void CCchUiConnectionHandler::ConstructL() |
|
53 { |
|
54 iConnUiUtils = CConnectionUiUtilities::NewL(); |
|
55 iCmManagerExt.OpenL(); |
|
56 User::LeaveIfError( iConnMon.ConnectL() ); |
|
57 } |
|
58 |
|
59 CCchUiConnectionHandler* CCchUiConnectionHandler::NewL( |
|
60 CCchUiCchHandler& aCchHandler, |
|
61 CCchUiSpsHandler& aSpsHandler ) |
|
62 { |
|
63 CCchUiConnectionHandler* self = NewLC( |
|
64 aCchHandler, aSpsHandler ); |
|
65 CleanupStack::Pop(self); |
|
66 return self; |
|
67 } |
|
68 |
|
69 CCchUiConnectionHandler* CCchUiConnectionHandler::NewLC( |
|
70 CCchUiCchHandler& aCchHandler, |
|
71 CCchUiSpsHandler& aSpsHandler ) |
|
72 { |
|
73 CCchUiConnectionHandler* self = |
|
74 new (ELeave) CCchUiConnectionHandler( |
|
75 aCchHandler, aSpsHandler ); |
|
76 CleanupStack::PushL(self); |
|
77 self->ConstructL(); |
|
78 return self; |
|
79 } |
|
80 |
|
81 CCchUiConnectionHandler::~CCchUiConnectionHandler() |
|
82 { |
|
83 delete iConnUiUtils; |
|
84 iCmManagerExt.Close(); |
|
85 iConnMon.Close(); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Searches access poinsts and adds selected access point to snap |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CCchUiConnectionHandler::SearchAccessPointsL( |
|
93 TUint aServiceId, |
|
94 TUint32 aSnapId, |
|
95 const TDesC& aServiceName ) |
|
96 { |
|
97 CCHUIDEBUG( "CCchUiConnectionHandler::SearchAccessPointsL - IN" ); |
|
98 |
|
99 // SSID of the WLAN network selected by user |
|
100 TWlanSsid ssid; |
|
101 |
|
102 // Connection mode of the WLAN network |
|
103 TWlanConnectionMode connectionMode; |
|
104 |
|
105 // Security mode of the WLAN network |
|
106 TWlanConnectionSecurityMode securityMode; |
|
107 |
|
108 // Flag for determining if hidden wlan |
|
109 TBool hiddenWlan( EFalse ); |
|
110 |
|
111 CCHUIDEBUG( |
|
112 "CCchUiConnectionHandler::SearchAccessPointsL - begin search wlan" ); |
|
113 |
|
114 // Set flag which indicates that search wlan query is open |
|
115 iSearchWlanOngoing = ETrue; |
|
116 |
|
117 TBool ret = iConnUiUtils->SearchWLANNetwork( |
|
118 ssid, connectionMode, securityMode ); |
|
119 |
|
120 iSearchWlanOngoing = EFalse; |
|
121 |
|
122 if ( !ret ) |
|
123 { |
|
124 //ret is ETrue if user pressed OK softkey. Otherwise leave |
|
125 //with cancel |
|
126 User::Leave( KErrCancel ); |
|
127 } |
|
128 |
|
129 CCHUIDEBUG( |
|
130 "CCchUiConnectionHandler::SearchAccessPointsL - search wlan finished" ); |
|
131 |
|
132 // Check if hidden wlan |
|
133 TUint32 easyWlanId( 0 ); |
|
134 easyWlanId = iCmManagerExt.EasyWlanIdL(); |
|
135 |
|
136 if ( easyWlanId ) |
|
137 { |
|
138 RCmConnectionMethodExt cmConnMethodExt = |
|
139 iCmManagerExt.ConnectionMethodL( easyWlanId ); |
|
140 CleanupClosePushL( cmConnMethodExt ); |
|
141 |
|
142 if ( cmConnMethodExt.GetBoolAttributeL( CMManager::EWlanScanSSID ) ) |
|
143 { |
|
144 CCHUIDEBUG( |
|
145 "CCchUiConnectionHandler::SearchAccessPointsL - hidden wlan" ); |
|
146 |
|
147 hiddenWlan = ETrue; |
|
148 } |
|
149 |
|
150 CleanupStack::PopAndDestroy( &cmConnMethodExt ); |
|
151 } |
|
152 |
|
153 HBufC* ssid16 = HBufC::NewL( KSsidLength ); |
|
154 CleanupStack::PushL( ssid16 ); |
|
155 |
|
156 TPtr ssid16Ptr( ssid16->Des() ); |
|
157 ssid16Ptr.Copy( ssid ); |
|
158 |
|
159 // Check if the snap returned by Cch really exists. |
|
160 if ( aSnapId ) |
|
161 { |
|
162 RArray<TUint32> destIds = RArray<TUint32>( 1 ); |
|
163 CleanupClosePushL( destIds ); |
|
164 iCmManagerExt.AllDestinationsL( destIds ); |
|
165 |
|
166 TBool found( EFalse ); |
|
167 for ( TInt index = 0 ; index < destIds.Count() ; index++ ) |
|
168 { |
|
169 if ( destIds[index] == aSnapId ) |
|
170 { |
|
171 found = ETrue; |
|
172 } |
|
173 } |
|
174 CleanupStack::PopAndDestroy( &destIds ); |
|
175 |
|
176 // Reset snap id if the snap doesn't exist. |
|
177 if ( !found ) |
|
178 { |
|
179 aSnapId = 0; |
|
180 } |
|
181 } |
|
182 |
|
183 if ( !aSnapId ) |
|
184 { |
|
185 RCmDestinationExt newDestination = |
|
186 CreateServiceSnapL( aServiceName ); |
|
187 CleanupClosePushL( newDestination ); |
|
188 |
|
189 TBool alreadyExists = EFalse; |
|
190 |
|
191 TInt iapId = AddNewConnectionMethodL( |
|
192 newDestination, |
|
193 *ssid16, |
|
194 securityMode, |
|
195 alreadyExists, |
|
196 hiddenWlan ); |
|
197 |
|
198 if ( KErrCancel == iapId ) |
|
199 { |
|
200 //Leave with cancel if user pressed Cancel softkey |
|
201 CleanupStack::PopAndDestroy( &newDestination ); |
|
202 CleanupStack::PopAndDestroy( ssid16 ); |
|
203 User::Leave( KErrCancel ); |
|
204 } |
|
205 |
|
206 if ( !alreadyExists ) |
|
207 { |
|
208 iSpsHandler.SetTemporaryIapIdL( aServiceId, iapId ); |
|
209 } |
|
210 |
|
211 // Now the snap is created, set it to use with cch |
|
212 SetSnapToUseL( aServiceId, newDestination.Id() ); |
|
213 |
|
214 // Self created, write id to service table in order to remove |
|
215 // in service uninstall |
|
216 TRAP_IGNORE( iSpsHandler.SetSnapIdL( |
|
217 aServiceId, newDestination.Id() ) ); |
|
218 |
|
219 CleanupStack::PopAndDestroy( &newDestination ); |
|
220 CleanupStack::PopAndDestroy( ssid16 ); |
|
221 } |
|
222 else |
|
223 { |
|
224 RCmDestinationExt destination = |
|
225 iCmManagerExt.DestinationL( aSnapId ); |
|
226 CleanupClosePushL( destination ); |
|
227 |
|
228 TBool alreadyExists = EFalse; |
|
229 TInt iapId = AddNewConnectionMethodL( |
|
230 destination, |
|
231 *ssid16, |
|
232 securityMode, |
|
233 alreadyExists, |
|
234 hiddenWlan ); |
|
235 |
|
236 CleanupStack::PopAndDestroy( &destination ); |
|
237 CleanupStack::PopAndDestroy( ssid16 ); |
|
238 |
|
239 if ( KErrCancel == iapId ) |
|
240 { |
|
241 //Leave with cancel if user pressed Cancel softkey |
|
242 User::Leave( KErrCancel ); |
|
243 } |
|
244 |
|
245 if ( !alreadyExists ) |
|
246 { |
|
247 iSpsHandler.SetTemporaryIapIdL( |
|
248 aServiceId, iapId ); |
|
249 } |
|
250 else |
|
251 { |
|
252 // Get current connection iap id |
|
253 TInt currentIapId( KErrNone ); |
|
254 TInt error( KErrNone ); |
|
255 iCCHHandler.GetCurrentConnectionIapIdL( |
|
256 aServiceId, ECCHUnknown, currentIapId, error ); |
|
257 |
|
258 CCHUIDEBUG2( "CCchUiConnectionHandler::SearchAccessPointsL - error: %d", error ); |
|
259 CCHUIDEBUG2( "CCchUiConnectionHandler::SearchAccessPointsL - current iap id: %d", currentIapId ); |
|
260 CCHUIDEBUG2( "CCchUiConnectionHandler::SearchAccessPointsL - selected iap id: %d", iapId ); |
|
261 |
|
262 // if selected iap is same as current iap no need to continue |
|
263 // because if we continue there will be unnecessary disable enable loop |
|
264 if ( currentIapId == iapId ) |
|
265 { |
|
266 User::Leave( KErrCancel ); |
|
267 } |
|
268 } |
|
269 |
|
270 SetSnapToUseL( aServiceId, aSnapId ); |
|
271 } |
|
272 |
|
273 // Reset Easy Wlan EWlanScanSSID parameter to EFalse |
|
274 if ( easyWlanId && hiddenWlan ) |
|
275 { |
|
276 RCmConnectionMethodExt cmConnMethodExt = |
|
277 iCmManagerExt.ConnectionMethodL( easyWlanId ); |
|
278 CleanupClosePushL( cmConnMethodExt ); |
|
279 cmConnMethodExt.SetBoolAttributeL( CMManager::EWlanScanSSID, EFalse ); |
|
280 cmConnMethodExt.UpdateL(); |
|
281 CleanupStack::PopAndDestroy( &cmConnMethodExt ); |
|
282 } |
|
283 |
|
284 CCHUIDEBUG( "CCchUiConnectionHandler::SearchAccessPointsL - OUT" ); |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // Check if connnection method already exists. If exists, connection method |
|
289 // id is returned, othewise KErrNotFound. |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 TInt CCchUiConnectionHandler::ConnectionMethodAlreadyExistsL( |
|
293 RCmDestinationExt& aDestination, |
|
294 const TDesC& aSsid, |
|
295 CMManager::TWlanSecMode aSecurityMode, |
|
296 TBool& aAlreadyExists, |
|
297 TBool aHidden ) |
|
298 { |
|
299 CCHUIDEBUG( "CCchUiConnectionHandler::ConnectionMethodAlreadyExistsL" ); |
|
300 |
|
301 TInt connectionMethodId = KErrNotFound; |
|
302 for ( TInt i=0 ; |
|
303 i < aDestination.ConnectionMethodCount() && !aAlreadyExists ; |
|
304 i++ ) |
|
305 { |
|
306 HBufC* refSsid( NULL ); |
|
307 |
|
308 RCmConnectionMethodExt cm = aDestination.ConnectionMethodL(i); |
|
309 CleanupClosePushL( cm ); |
|
310 |
|
311 // If snap contains non wlan iaps, this will leave so trap |
|
312 TRAPD( err, refSsid = cm.GetStringAttributeL( CMManager::EWlanSSID )); |
|
313 if ( refSsid && !err ) |
|
314 { |
|
315 CleanupStack::PushL( refSsid ); |
|
316 |
|
317 if ( refSsid->Compare( aSsid ) == 0 ) |
|
318 { |
|
319 CCHUIDEBUG( "Matching wlan SSID Found" ); |
|
320 |
|
321 // check security and hidden |
|
322 TBool refHidden = cm.GetBoolAttributeL( |
|
323 CMManager::EWlanScanSSID ); |
|
324 TUint refSecurity = cm.GetIntAttributeL( |
|
325 CMManager::EWlanSecurityMode ); |
|
326 |
|
327 // ref AP security mode is stored as EWlanSecModeWpa in case of EWlanSecModeWpa2 |
|
328 TBool exception( EFalse ); |
|
329 |
|
330 if ( aSecurityMode == CMManager::EWlanSecModeWpa2 && |
|
331 refSecurity == CMManager::EWlanSecModeWpa ) |
|
332 { |
|
333 exception = ETrue; |
|
334 } |
|
335 |
|
336 if ( refHidden == aHidden && |
|
337 ( refSecurity == aSecurityMode || exception ) ) |
|
338 { |
|
339 connectionMethodId = |
|
340 cm.GetIntAttributeL( CMManager::ECmIapId ); |
|
341 aAlreadyExists = ETrue; |
|
342 } |
|
343 } |
|
344 CleanupStack::PopAndDestroy( refSsid ); |
|
345 } |
|
346 else if ( KErrNoMemory == err ) |
|
347 { |
|
348 User::Leave( err ); |
|
349 } |
|
350 else |
|
351 { |
|
352 // for note from code analysis tool |
|
353 } |
|
354 CleanupStack::PopAndDestroy( &cm ); |
|
355 } |
|
356 |
|
357 CCHUIDEBUG2( "ConnectionMethodAlreadyExistsL connection method id=%d", |
|
358 connectionMethodId ); |
|
359 |
|
360 return connectionMethodId; |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // Add new connection method. |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 TInt CCchUiConnectionHandler::AddNewConnectionMethodL( |
|
368 RCmDestinationExt& aDestination, |
|
369 const TDesC& aSsid, |
|
370 TWlanConnectionSecurityMode aSecurityMode, |
|
371 TBool& aAlreadyExists, |
|
372 TBool aSetHidden ) |
|
373 { |
|
374 CCHUIDEBUG( "CCchUiConnectionHandler::AddNewConnectionMethodL" ); |
|
375 |
|
376 CMManager::TWlanSecMode securityModeToSet = CMManager::EWlanSecModeOpen; |
|
377 switch ( aSecurityMode ) |
|
378 { |
|
379 case EWlanConnectionSecurityOpen: |
|
380 { |
|
381 securityModeToSet = CMManager::EWlanSecModeOpen; |
|
382 } |
|
383 break; |
|
384 |
|
385 case EWlanConnectionSecurityWep: |
|
386 { |
|
387 securityModeToSet = CMManager::EWlanSecModeWep; |
|
388 } |
|
389 break; |
|
390 |
|
391 case EWlanConnectionSecurity802d1x: |
|
392 { |
|
393 securityModeToSet = CMManager::EWlanSecMode802_1x; |
|
394 } |
|
395 break; |
|
396 |
|
397 case EWlanConnectionSecurityWpa: |
|
398 { |
|
399 securityModeToSet = CMManager::EWlanSecModeWpa; |
|
400 } |
|
401 break; |
|
402 |
|
403 case EWlanConnectionSecurityWpaPsk: |
|
404 { |
|
405 securityModeToSet = CMManager::EWlanSecModeWpa2; |
|
406 } |
|
407 break; |
|
408 |
|
409 default: |
|
410 break; |
|
411 } |
|
412 |
|
413 // Check is iap with same ssid already exists |
|
414 RArray<TUint32> destArray; |
|
415 CleanupClosePushL( destArray ); |
|
416 |
|
417 iCmManagerExt.AllDestinationsL( destArray ); |
|
418 |
|
419 for ( TInt i( 0 ); i < destArray.Count(); i++ ) |
|
420 { |
|
421 RCmDestinationExt destination = |
|
422 iCmManagerExt.DestinationL( destArray[ i ] ); |
|
423 CleanupClosePushL( destination ); |
|
424 |
|
425 TInt connectionId = ConnectionMethodAlreadyExistsL( |
|
426 destination, aSsid, securityModeToSet, aAlreadyExists, aSetHidden ); |
|
427 |
|
428 if ( aAlreadyExists && KErrNotFound != connectionId ) |
|
429 { |
|
430 RCmConnectionMethodExt connectionMethod = |
|
431 destination.ConnectionMethodByIDL( connectionId ); |
|
432 CleanupClosePushL( connectionMethod ); |
|
433 if ( destination.Id() != aDestination.Id() ) |
|
434 { |
|
435 CCHUIDEBUG( "Copy existing connection method to destination" ); |
|
436 |
|
437 aDestination.AddConnectionMethodL( |
|
438 connectionMethod.CreateCopyL() ); |
|
439 } |
|
440 TRAP_IGNORE( aDestination.ModifyPriorityL( |
|
441 connectionMethod, KCmHighestPriority ) ); |
|
442 aDestination.UpdateL(); |
|
443 |
|
444 CleanupStack::PopAndDestroy( &connectionMethod ); |
|
445 CleanupStack::PopAndDestroy( &destination ); |
|
446 CleanupStack::PopAndDestroy( &destArray ); |
|
447 return connectionId; |
|
448 } |
|
449 CleanupStack::PopAndDestroy( &destination ); |
|
450 } |
|
451 CleanupStack::PopAndDestroy( &destArray ); |
|
452 |
|
453 TInt ret = KErrNone; |
|
454 |
|
455 RCmConnectionMethodExt newConnMethod = |
|
456 aDestination.CreateConnectionMethodL( KUidWlanBearerType ); |
|
457 CleanupClosePushL( newConnMethod ); |
|
458 |
|
459 // Set attributes |
|
460 newConnMethod.SetStringAttributeL( CMManager::ECmName, aSsid ); |
|
461 newConnMethod.SetStringAttributeL( CMManager::EWlanSSID, aSsid ); |
|
462 |
|
463 if ( aSetHidden ) |
|
464 { |
|
465 newConnMethod.SetBoolAttributeL( |
|
466 CMManager::EWlanScanSSID, ETrue ); |
|
467 } |
|
468 |
|
469 newConnMethod.SetIntAttributeL( |
|
470 CMManager::EWlanSecurityMode, securityModeToSet ); |
|
471 |
|
472 TRAP_IGNORE( aDestination.ModifyPriorityL( |
|
473 newConnMethod, KCmHighestPriority )); |
|
474 |
|
475 aDestination.UpdateL(); |
|
476 ret = newConnMethod.GetIntAttributeL( CMManager::ECmIapId ); |
|
477 |
|
478 CConnectionUiUtilities* connUiUtils = CConnectionUiUtilities::NewL(); |
|
479 CleanupStack::PushL( connUiUtils ); |
|
480 |
|
481 TInt createdUid( 0 ); |
|
482 createdUid = newConnMethod.GetIntAttributeL( CMManager::EWlanServiceId ); |
|
483 |
|
484 HBufC* key = HBufC::NewL( KWlanWpaPskMaxLength ); |
|
485 CleanupStack::PushL( key ); |
|
486 TPtr keyPtr( key->Des() ); |
|
487 |
|
488 TBool hex = EFalse; |
|
489 |
|
490 if ( securityModeToSet == CMManager::EWlanSecModeWep ) |
|
491 { |
|
492 if ( connUiUtils->EasyWepDlg( &keyPtr, hex ) ) |
|
493 { |
|
494 SaveSecuritySettingsL( aSecurityMode, key, hex, createdUid ); |
|
495 } |
|
496 else |
|
497 { |
|
498 aDestination.DeleteConnectionMethodL( newConnMethod ); |
|
499 aDestination.UpdateL(); |
|
500 |
|
501 ret = KErrCancel; |
|
502 } |
|
503 } |
|
504 else if ( securityModeToSet == CMManager::EWlanSecModeWpa || |
|
505 securityModeToSet == CMManager::EWlanSecModeWpa2 ) |
|
506 { |
|
507 if ( connUiUtils->EasyWpaDlg( &keyPtr ) ) |
|
508 { |
|
509 SaveSecuritySettingsL( aSecurityMode, key, hex, createdUid ); |
|
510 } |
|
511 else |
|
512 { |
|
513 aDestination.DeleteConnectionMethodL( newConnMethod ); |
|
514 aDestination.UpdateL(); |
|
515 |
|
516 ret = KErrCancel; |
|
517 } |
|
518 } |
|
519 else |
|
520 { |
|
521 CCHUIDEBUG( "AddNewConnectionMethodL - WlanConnectionSecurityOpen" ); |
|
522 } |
|
523 CleanupStack::PopAndDestroy( key ); |
|
524 CleanupStack::PopAndDestroy( connUiUtils ); |
|
525 CleanupStack::PopAndDestroy( &newConnMethod ); |
|
526 |
|
527 CCHUIDEBUG2( "AddNewConnectionMethodL - return: %d", ret ); |
|
528 return ret; |
|
529 } |
|
530 |
|
531 // --------------------------------------------------------------------------- |
|
532 // Save security settings. |
|
533 // --------------------------------------------------------------------------- |
|
534 // |
|
535 void CCchUiConnectionHandler::SaveSecuritySettingsL( |
|
536 const TWlanConnectionSecurityMode aSecMode, |
|
537 const HBufC* aKey, |
|
538 const TBool aHex, |
|
539 const TUint32 aIapId ) |
|
540 { |
|
541 CCHUIDEBUG( "CCchUiConnectionHandler::SaveSecuritySettingsL - IN" ); |
|
542 |
|
543 CMDBSession* db = CMDBSession::NewL( CMDBSession::LatestVersion() ); |
|
544 CleanupStack::PushL( db ); |
|
545 switch ( aSecMode ) |
|
546 { |
|
547 case EWlanConnectionSecurityWep: |
|
548 { |
|
549 CWEPSecuritySettings* wepSecSettings = |
|
550 CWEPSecuritySettings::NewL(); |
|
551 CleanupStack::PushL( wepSecSettings ); |
|
552 wepSecSettings->LoadL( aIapId, *db ); |
|
553 User::LeaveIfError( |
|
554 wepSecSettings->SetKeyDataL( 0, *aKey, aHex ) ); |
|
555 wepSecSettings->SaveL( aIapId, *db ); |
|
556 CleanupStack::PopAndDestroy( wepSecSettings ); |
|
557 break; |
|
558 } |
|
559 case EWlanConnectionSecurityWpaPsk: |
|
560 { |
|
561 CWPASecuritySettings* wpaSecSettings = |
|
562 CWPASecuritySettings::NewL( ESecurityModeWpa ); |
|
563 CleanupStack::PushL( wpaSecSettings ); |
|
564 wpaSecSettings->LoadL( aIapId, *db ); |
|
565 User::LeaveIfError( wpaSecSettings->SetWPAPreSharedKey( *aKey ) ); |
|
566 wpaSecSettings->SaveL( aIapId, *db, ESavingBrandNewAP, 0 ) ; |
|
567 CleanupStack::PopAndDestroy( wpaSecSettings ); |
|
568 break; |
|
569 } |
|
570 case EWlanConnectionSecurityWpa: |
|
571 case EWlanConnectionSecurity802d1x: |
|
572 { |
|
573 CWPASecuritySettings* wpaSecSettings = |
|
574 CWPASecuritySettings::NewL( |
|
575 aSecMode == EWlanConnectionSecurityWpa ? |
|
576 ESecurityModeWpa : ESecurityMode8021x ); |
|
577 CleanupStack::PushL( wpaSecSettings ); |
|
578 wpaSecSettings->LoadL( aIapId, *db ); |
|
579 wpaSecSettings->SaveL( aIapId, *db, ESavingBrandNewAP, 0 ); |
|
580 CleanupStack::PopAndDestroy( wpaSecSettings ); |
|
581 break; |
|
582 } |
|
583 default: |
|
584 // Fore example EWlanConnectionSecurityOpen -> no need to save |
|
585 // any security settings. |
|
586 break; |
|
587 } |
|
588 CleanupStack::PopAndDestroy( db ); // db |
|
589 |
|
590 CCHUIDEBUG( "CCchUiConnectionHandler::SaveSecuritySettingsL - OUT" ); |
|
591 } |
|
592 |
|
593 // --------------------------------------------------------------------------- |
|
594 // Sets SNAP into use via CCH. |
|
595 // --------------------------------------------------------------------------- |
|
596 // |
|
597 void CCchUiConnectionHandler::SetSnapToUseL( |
|
598 TUint aServiceId, TUint32 aSNAPId ) |
|
599 { |
|
600 CCHUIDEBUG( "CCchUiConnectionHandler::SetSnapToUseL - IN" ); |
|
601 |
|
602 CCHUIDEBUG2( "SetSnapToUseL - aServiceId: %d", aServiceId ); |
|
603 CCHUIDEBUG2( "SetSnapToUseL - aSNAPId: %d", aSNAPId ); |
|
604 |
|
605 TInt err( KErrNone ); |
|
606 iCCHHandler.SetConnectionSnapIdL( aServiceId, aSNAPId, err ); |
|
607 |
|
608 if ( err ) |
|
609 { |
|
610 User::Leave( err ); |
|
611 } |
|
612 |
|
613 CCHUIDEBUG( "CCchUiConnectionHandler::SetSnapToUseL - OUT" ); |
|
614 } |
|
615 |
|
616 // --------------------------------------------------------------------------- |
|
617 // CCchUiConnectionHandler::ConnectionMethodAlreadyExistsL |
|
618 // --------------------------------------------------------------------------- |
|
619 // |
|
620 TBool CCchUiConnectionHandler::ConnectionMethodAlreadyExistsL( |
|
621 TUint32 aIapId, RCmDestinationExt& aTargetSnap ) const |
|
622 { |
|
623 CCHUIDEBUG( "CCchUiConnectionHandler::ConnectionMethodAlreadyExistsL - IN" ); |
|
624 |
|
625 TBool returnVal = EFalse; |
|
626 TInt conMethodCount = aTargetSnap.ConnectionMethodCount(); |
|
627 |
|
628 for ( TInt i( 0 ) ; i < conMethodCount && !returnVal; i ++ ) |
|
629 { |
|
630 RCmConnectionMethodExt cm = aTargetSnap.ConnectionMethodL( i ); |
|
631 CleanupClosePushL( cm ); |
|
632 |
|
633 TUint32 bearerType = cm.GetIntAttributeL( CMManager::ECmBearerType ); |
|
634 if ( bearerType == iCmManagerExt.GetConnectionMethodInfoIntL( |
|
635 aIapId, CMManager::ECmBearerType ) ) |
|
636 { |
|
637 HBufC* buffer = NULL; |
|
638 HBufC* bufferToCompare = NULL; |
|
639 |
|
640 switch( bearerType ) |
|
641 { |
|
642 case KUidWlanBearerType: |
|
643 CCHUIDEBUG( "ConnectionMethodAlreadyExistsL - KUidWlanBearerType" ); |
|
644 buffer = iCmManagerExt.GetConnectionMethodInfoStringL( |
|
645 aIapId, CMManager::EWlanSSID ); |
|
646 CleanupStack::PushL( buffer ); |
|
647 bufferToCompare = |
|
648 cm.GetStringAttributeL( CMManager::EWlanSSID ); |
|
649 if ( buffer->Compare( *bufferToCompare ) == 0 ) |
|
650 { |
|
651 returnVal = ETrue; |
|
652 } |
|
653 CleanupStack::PopAndDestroy( buffer ); |
|
654 delete bufferToCompare; |
|
655 bufferToCompare = NULL; |
|
656 break; |
|
657 case KUidPacketDataBearerType: |
|
658 CCHUIDEBUG( "ConnectionMethodAlreadyExistsL - KUidPacketDataBearerType" ); |
|
659 buffer = iCmManagerExt.GetConnectionMethodInfoStringL( |
|
660 aIapId, CMManager::EPacketDataAPName ); |
|
661 CleanupStack::PushL( buffer ); |
|
662 bufferToCompare = |
|
663 cm.GetStringAttributeL( CMManager::EPacketDataAPName ); |
|
664 if ( buffer->Compare( *bufferToCompare ) == 0 ) |
|
665 { |
|
666 returnVal = ETrue; |
|
667 } |
|
668 CleanupStack::PopAndDestroy( buffer ); |
|
669 delete bufferToCompare; |
|
670 bufferToCompare = NULL; |
|
671 break; |
|
672 default: |
|
673 break; |
|
674 } |
|
675 } |
|
676 CleanupStack::PopAndDestroy( &cm ); |
|
677 } |
|
678 CCHUIDEBUG2( "CCchUiConnectionHandler::ConnectionMethodAlreadyExistsL - return = %d", returnVal ); |
|
679 |
|
680 return returnVal; |
|
681 } |
|
682 |
|
683 // --------------------------------------------------------------------------- |
|
684 // Copies specific iap from specific snap to target snap |
|
685 // --------------------------------------------------------------------------- |
|
686 // |
|
687 void CCchUiConnectionHandler::CopyIapToServiceSnapL( |
|
688 TUint aServiceId, |
|
689 const TDesC& aServiceName, |
|
690 TUint32 aSourceIap, |
|
691 TUint32 aTargetSnap ) |
|
692 { |
|
693 CCHUIDEBUG( "CCchUiConnectionHandler::CopyIapToServiceSnapL - IN" ); |
|
694 |
|
695 CCHUIDEBUG3( "CopyIapToServiceSnapL - aSourceIap: %d, aTargetSnap: %d", |
|
696 aSourceIap, aTargetSnap ); |
|
697 |
|
698 RCmDestinationExt targetSnap; |
|
699 TRAPD( err, ( targetSnap = iCmManagerExt.DestinationL( aTargetSnap ) ) ); |
|
700 CCHUIDEBUG2( " -> get target snap err: %d", err ); |
|
701 if ( err ) |
|
702 { |
|
703 CCHUIDEBUG( "CopyIapToServiceSnapL - Create snap for service"); |
|
704 |
|
705 targetSnap = CreateServiceSnapL( aServiceName ); |
|
706 CleanupClosePushL( targetSnap ); |
|
707 // Now the snap is created, set it to use with cch |
|
708 SetSnapToUseL( aServiceId, targetSnap.Id() ); |
|
709 } |
|
710 else |
|
711 { |
|
712 CleanupClosePushL( targetSnap ); |
|
713 } |
|
714 |
|
715 if( !ConnectionMethodAlreadyExistsL( aSourceIap, targetSnap ) ) |
|
716 { |
|
717 CCHUIDEBUG( |
|
718 "CopyIapToServiceSnapL - connection not exists -> add connection" ); |
|
719 |
|
720 RCmConnectionMethodExt sourceConn = |
|
721 iCmManagerExt.ConnectionMethodL( aSourceIap ); |
|
722 CleanupClosePushL( sourceConn ); |
|
723 |
|
724 RCmConnectionMethodExt newConnection = sourceConn.CreateCopyL(); |
|
725 CleanupClosePushL( newConnection ); |
|
726 targetSnap.AddConnectionMethodL( newConnection ); |
|
727 CleanupStack::PopAndDestroy( &newConnection ); |
|
728 CleanupStack::PopAndDestroy( &sourceConn ); |
|
729 |
|
730 targetSnap.UpdateL(); |
|
731 } |
|
732 |
|
733 CleanupStack::PopAndDestroy( &targetSnap ); |
|
734 |
|
735 CCHUIDEBUG( "CCchUiConnectionHandler::CopyIapToServiceSnapL - OUT" ); |
|
736 } |
|
737 |
|
738 // --------------------------------------------------------------------------- |
|
739 // Removes connection method from SNAP. |
|
740 // --------------------------------------------------------------------------- |
|
741 // |
|
742 void CCchUiConnectionHandler::RemoveConnectionL( |
|
743 const TDesC& aServiceName, TInt aIapId ) |
|
744 { |
|
745 CCHUIDEBUG( "CCchUiConnectionHandler::RemoveConnectionL - IN" ); |
|
746 CCHUIDEBUG2( "RemoveConnectionL - aServiceName=%S", &aServiceName ); |
|
747 CCHUIDEBUG2( "RemoveConnectionL - aIapId=%d", aIapId ); |
|
748 |
|
749 RArray<TUint32> destIds = RArray<TUint32>( 1 ); |
|
750 CleanupClosePushL( destIds ); |
|
751 iCmManagerExt.AllDestinationsL( destIds ); |
|
752 |
|
753 for ( TInt i( 0 ) ; i < destIds.Count() ; i++ ) |
|
754 { |
|
755 RCmDestinationExt dest = iCmManagerExt.DestinationL( destIds[ i ] ); |
|
756 CleanupClosePushL( dest ); |
|
757 |
|
758 HBufC* destName = dest.NameLC(); |
|
759 if ( destName->Des().Compare( aServiceName ) == 0 ) |
|
760 { |
|
761 CCHUIDEBUG( "RemoveConnectionL - get connection method"); |
|
762 |
|
763 RCmConnectionMethodExt connMethod = |
|
764 iCmManagerExt.ConnectionMethodL( aIapId ); |
|
765 |
|
766 CCHUIDEBUG( "RemoveConnectionL - remove connection method"); |
|
767 |
|
768 dest.RemoveConnectionMethodL( connMethod ); |
|
769 dest.UpdateL(); |
|
770 |
|
771 CCHUIDEBUG( "RemoveConnectionL - connection method removed"); |
|
772 } |
|
773 |
|
774 CleanupStack::PopAndDestroy( destName ); |
|
775 CleanupStack::PopAndDestroy( &dest ); |
|
776 } |
|
777 |
|
778 CleanupStack::PopAndDestroy( &destIds ); |
|
779 |
|
780 CCHUIDEBUG( "CCchUiConnectionHandler::RemoveConnectionL - OUT" ); |
|
781 } |
|
782 |
|
783 // --------------------------------------------------------------------------- |
|
784 // Returns ETrue if wlan search (query) is ongoing. |
|
785 // --------------------------------------------------------------------------- |
|
786 // |
|
787 TBool CCchUiConnectionHandler::SearchWlanOngoing() |
|
788 { |
|
789 CCHUIDEBUG2( "CCchUiConnectionHandler::SearchWlanOngoing ongoing=%d", |
|
790 iSearchWlanOngoing ); |
|
791 |
|
792 return iSearchWlanOngoing; |
|
793 } |
|
794 |
|
795 |
|
796 // --------------------------------------------------------------------------- |
|
797 // Creates service snap |
|
798 // --------------------------------------------------------------------------- |
|
799 // |
|
800 RCmDestinationExt CCchUiConnectionHandler::CreateServiceSnapL( |
|
801 const TDesC& aServiceName ) |
|
802 { |
|
803 CCHUIDEBUG( "CCchUiConnectionHandler::CreateServiceSnapL" ); |
|
804 |
|
805 // Create snap again, user might have deleted it |
|
806 RCmDestinationExt newDestination; |
|
807 |
|
808 // Check if snap with service name already exists. |
|
809 TBool snapAlreadyExists = EFalse; |
|
810 RArray<TUint32> destIdArray = |
|
811 RArray<TUint32>( KDestinationArrayGranularity ); |
|
812 CleanupClosePushL( destIdArray ); |
|
813 |
|
814 CCHUIDEBUG( "CreateServiceSnapL - check if snap exists"); |
|
815 |
|
816 iCmManagerExt.AllDestinationsL( destIdArray ); |
|
817 |
|
818 CCHUIDEBUG2( "CreateServiceSnapL - destination count: %d", |
|
819 destIdArray.Count() ); |
|
820 |
|
821 for ( TInt i = 0; |
|
822 i < destIdArray.Count() && !snapAlreadyExists; |
|
823 i++ ) |
|
824 { |
|
825 RCmDestinationExt dest = |
|
826 iCmManagerExt.DestinationL( destIdArray[i] ); |
|
827 CleanupClosePushL( dest ); |
|
828 HBufC* destName = dest.NameLC(); |
|
829 if ( *destName == aServiceName ) |
|
830 { |
|
831 CCHUIDEBUG( "CreateServiceSnapL - snap already exists" ); |
|
832 snapAlreadyExists = ETrue; |
|
833 newDestination = iCmManagerExt.DestinationL( destIdArray[i] ); |
|
834 } |
|
835 CleanupStack::PopAndDestroy( destName ); |
|
836 CleanupStack::PopAndDestroy( &dest ); |
|
837 } |
|
838 CleanupStack::PopAndDestroy( &destIdArray ); |
|
839 |
|
840 if ( !snapAlreadyExists ) |
|
841 { |
|
842 newDestination = |
|
843 iCmManagerExt.CreateDestinationL( aServiceName ); |
|
844 CleanupClosePushL( newDestination ); |
|
845 newDestination.SetMetadataL( |
|
846 CMManager::ESnapMetadataHiddenAgent, ETrue ); |
|
847 newDestination.UpdateL(); |
|
848 CleanupStack::Pop( &newDestination ); |
|
849 } |
|
850 |
|
851 return newDestination; |
|
852 } |
|
853 |