|
1 /* |
|
2 * Copyright (c) 2001-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 the License "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 a state - machine like active object that controls Wi-Fi Protected Setup Process. |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: tr1cfwln#29 % |
|
20 */ |
|
21 |
|
22 //SYSTEM INCLUDES |
|
23 #include <wlanmgmtclient.h> |
|
24 #include <wifiprotplugin.rsg> |
|
25 #include <StringLoader.h> |
|
26 #include <AknWaitDialog.h> |
|
27 #include <cmpluginwlandef.h> |
|
28 #include <commdb.h> |
|
29 #include <WPASecuritySettingsUI.h> |
|
30 #include <WEPSecuritySettingsUI.h> |
|
31 #include <e32math.h> |
|
32 #include <cmconnectionmethoddef.h> |
|
33 #include <wlanerrorcodes.h> |
|
34 #include <utf.h> |
|
35 #include <AknIconArray.h> |
|
36 #include <AknGlobalNote.h> |
|
37 #include <AknSgcc.h> |
|
38 #include <uikon/eiksrvui.h> |
|
39 #include <AknsUtils.h> |
|
40 #include <data_caging_path_literals.hrh> |
|
41 #include <wifiprot.mbg> |
|
42 |
|
43 #include <CoreApplicationUIsSDKCRKeys.h> |
|
44 #include <e32std.h> |
|
45 #include <ConnectionUiUtilities.h> |
|
46 |
|
47 //USER INCLUDES |
|
48 #include "wifiprotlogger.h" |
|
49 #include "wifiprotactiverunner.h" |
|
50 #include "wifiprotconfirmationnotedlg.h" |
|
51 #include "wifiprotselectnetworkdlg.h" |
|
52 #include "wifiprotenterpindlg.h" |
|
53 #include "wifiprotinitiateeasysetupdlg.h" |
|
54 |
|
55 #include "featmgr.h" |
|
56 |
|
57 // valid Wep key lengths, to check wep key format |
|
58 // (wep key format depends on key length) |
|
59 const TInt KConnUiUtilsWepLengthASCII5 = 5; |
|
60 const TInt KConnUiUtilsWepLengthASCII13 = 13; |
|
61 const TInt KConnUiUtilsWepLengthASCII29 = 29; |
|
62 const TInt KConnUiUtilsWepLengthHEX10 = 10; |
|
63 const TInt KConnUiUtilsWepLengthHEX26 = 26; |
|
64 const TInt KConnUiUtilsWepLengthHEX58 = 58; |
|
65 #ifdef __WINS__ |
|
66 const TInt KNumberOfEmulatedAvailableNetworks = 2; |
|
67 const TInt KIndexOfFirstEmulatedAvailableNetwork = 0; |
|
68 const TInt KIndexOfSecondEmulatedAvailableNetwork = 1; |
|
69 #endif |
|
70 |
|
71 /** |
|
72 * Management frame information element IDs. |
|
73 * needed to determine coverage |
|
74 */ |
|
75 enum T802Dot11InformationElementID |
|
76 { |
|
77 E802Dot11SsidIE = 0, |
|
78 E802Dot11SupportedRatesIE = 1, |
|
79 E802Doi11FhParameterSetIE = 2, |
|
80 E802Dot11DsParameterSetIE = 3, |
|
81 E802Dot11CfParameterSetIE = 4, |
|
82 E802Dot11TimIE = 5, |
|
83 E802Dot11IbssParameterSetIE = 6, |
|
84 E802Dot11CountryIE = 7, |
|
85 E802Dot11HoppingPatternParamIE = 8, |
|
86 E802Dot11HoppingPatternTableIE = 9, |
|
87 E802Dot11RequestIE = 10, |
|
88 |
|
89 E802Dot11ChallengeTextIE = 16, |
|
90 // Reserved for challenge text extension 17 - 31 |
|
91 E802Dot11ErpInformationIE = 42, |
|
92 E802Dot11ExtendedRatesIE = 50, |
|
93 E802Dot11AironetIE = 133, |
|
94 E802Dot11ApIpAddressIE = 149, |
|
95 E802Dot11RsnIE = 221 |
|
96 }; |
|
97 |
|
98 const TInt KArrayGranularity = 10; |
|
99 const TInt KIconsGranularity = 4; |
|
100 |
|
101 _LIT( KWiFiFileIcons, "z:wifiprot.mbm" ); |
|
102 |
|
103 _LIT8( KEapWsc, "\xFE\x00\x37\x2A\x00\x00\x00\x01"); |
|
104 |
|
105 _LIT( KWiFiPanic, "Wi-Fi Protected Setup"); |
|
106 |
|
107 using namespace CMManager; |
|
108 |
|
109 // ================= MEMBER FUNCTIONS ======================= |
|
110 // |
|
111 // -------------------------------------------------------------------------- |
|
112 // CWiFiProtActiveRunner::NewL |
|
113 // -------------------------------------------------------------------------- |
|
114 // |
|
115 CWiFiProtActiveRunner* CWiFiProtActiveRunner::NewL( |
|
116 CWiFiProtDlgsPlugin* aParent, TInt aPriority ) |
|
117 { |
|
118 CLOG_ENTERFN( "CWiFiProtActiveRunner::NewL" ); |
|
119 |
|
120 CWiFiProtActiveRunner* self = |
|
121 new(ELeave) CWiFiProtActiveRunner( aParent, aPriority ); |
|
122 CleanupStack::PushL( self ); |
|
123 self->ConstructL(); |
|
124 CleanupStack::Pop(); // self |
|
125 |
|
126 CLOG_LEAVEFN( "CWiFiProtActiveRunner::NewL" ); |
|
127 |
|
128 return self; |
|
129 } |
|
130 |
|
131 // -------------------------------------------------------------------------- |
|
132 // CWiFiProtActiveRunner::~CWiFiProtActiveRunner |
|
133 // -------------------------------------------------------------------------- |
|
134 // |
|
135 CWiFiProtActiveRunner::~CWiFiProtActiveRunner() |
|
136 { |
|
137 CLOG_ENTERFN( "CWiFiProtActiveRunner::~CWiFiProtActiveRunner" ); |
|
138 |
|
139 // Close notifier |
|
140 iNotifier.Close(); |
|
141 |
|
142 Cancel(); |
|
143 |
|
144 // If the cancel has been initiated by the client, temp IAP cannot be deleted until |
|
145 // after the RNotifier Cancel() call has returned (deadlock between MPM and CMM). |
|
146 // Therefore, temp IAP cleanup must be done later. |
|
147 if ( !iClientCancelled ) |
|
148 { |
|
149 TRAP_IGNORE( DeleteTempIapL() ); //we can't do much if delete fails |
|
150 } |
|
151 |
|
152 delete iWlanMgmtEngine; |
|
153 |
|
154 // if cancelled from client, wait note may still be visible |
|
155 if ( iWaitDlg ) |
|
156 { |
|
157 CLOG_WRITE( "iWaitDlg->SetCallback( NULL );" ); |
|
158 iWaitDlg->SetCallback( NULL ); |
|
159 CLOG_WRITE( "iWaitDlg->ProcessFinishedL( );" ); |
|
160 TRAP_IGNORE( iWaitDlg->ProcessFinishedL() ); |
|
161 delete iWaitDlg; |
|
162 } |
|
163 |
|
164 if ( iPinDlg ) |
|
165 { |
|
166 delete iPinDlg; |
|
167 } |
|
168 |
|
169 TBool cleanupCms = EFalse; |
|
170 if ( iReturn == EWiFiCancel ) |
|
171 { |
|
172 cleanupCms = ETrue; |
|
173 } |
|
174 |
|
175 for ( TInt i = 0; i < iCmArray.Count();i++ ) |
|
176 { |
|
177 // if we are setting up a connection, we save the settings into |
|
178 // easy wlan iap (connection method), which we shouldn't ever delete! |
|
179 if ( ( !iIsConnectionNeeded ) && cleanupCms ) |
|
180 { |
|
181 //we can't do much if delete fails |
|
182 TRAP_IGNORE( iCmArray[i]->DeleteL() ); |
|
183 } |
|
184 iCmArray[i]->Close(); |
|
185 delete iCmArray[i]; |
|
186 iCmArray[i] = NULL; |
|
187 } |
|
188 |
|
189 iCmArray.ResetAndDestroy(); |
|
190 iAvailableNetworks.Close(); |
|
191 delete iIapParametersArray; |
|
192 delete iScanInfo; |
|
193 CLOG_LEAVEFN( "CWiFiProtActiveRunner::~CWiFiProtActiveRunner" ); |
|
194 |
|
195 } |
|
196 |
|
197 // -------------------------------------------------------------------------- |
|
198 // CWiFiProtActiveRunner::StartProtectedSetupL |
|
199 // -------------------------------------------------------------------------- |
|
200 // |
|
201 void CWiFiProtActiveRunner::StartProtectedSetupAsyncL ( |
|
202 const TWlanSsid& aSSid, |
|
203 RArray<TUint32>& aUids, |
|
204 RCmManagerExt& aCmManagerToUse ) |
|
205 { |
|
206 CLOG_ENTERFN( "CWiFiProtActiveRunner::StartProtectedSetupAsyncL" ); |
|
207 |
|
208 iIsConnectionNeeded = EFalse; |
|
209 iUids = &aUids; |
|
210 iCmManagerExt = &aCmManagerToUse; |
|
211 iSsid.Copy( aSSid ); |
|
212 ShowInitialDialogL(); |
|
213 |
|
214 CLOG_LEAVEFN( "CWiFiProtActiveRunner::StartProtectedSetupAsyncL" ); |
|
215 |
|
216 } |
|
217 |
|
218 // -------------------------------------------------------------------------- |
|
219 // CWiFiProtActiveRunner::StartProtectedSetupConnL |
|
220 // -------------------------------------------------------------------------- |
|
221 // |
|
222 void CWiFiProtActiveRunner::StartProtectedSetupConnL ( |
|
223 const TWlanSsid& aSSid, |
|
224 TWlanProtectedSetupCredentialAttribute& |
|
225 aNetworkSettings, |
|
226 RCmManagerExt& aCmManagerToUse ) |
|
227 { |
|
228 CLOG_ENTERFN( "CWiFiProtActiveRunner::StartProtectedSetupConnL" ); |
|
229 |
|
230 iIsConnectionNeeded = ETrue; |
|
231 iNetworkSettings = &aNetworkSettings; |
|
232 iCmManagerExt = &aCmManagerToUse; |
|
233 iSsid.Copy( aSSid ); |
|
234 ShowInitialDialogL(); |
|
235 |
|
236 CLOG_LEAVEFN( "CWiFiProtActiveRunner::StartProtectedSetupConnL" ); |
|
237 |
|
238 } |
|
239 |
|
240 // -------------------------------------------------------------------------- |
|
241 // CWiFiProtActiveRunner::StartProtectedSetupL |
|
242 // -------------------------------------------------------------------------- |
|
243 // |
|
244 WiFiProt::TWiFiReturn CWiFiProtActiveRunner::StartProtectedSetupL ( |
|
245 const TWlanSsid& aSSid, |
|
246 RArray<TUint32>& aUids, |
|
247 RCmManagerExt& aCmManagerToUse ) |
|
248 { |
|
249 CLOG_ENTERFN( "CWiFiProtActiveRunner::StartProtectedSetupL" ); |
|
250 |
|
251 iSyncMode = ETrue; |
|
252 iIsConnectionNeeded = EFalse; |
|
253 iUids = &aUids; |
|
254 iCmManagerExt = &aCmManagerToUse; |
|
255 iSsid.Copy( aSSid ); |
|
256 ShowInitialDialogL(); |
|
257 |
|
258 CLOG_LEAVEFN( "CWiFiProtActiveRunner::StartProtectedSetupL" ); |
|
259 |
|
260 return iReturn; |
|
261 } |
|
262 |
|
263 // -------------------------------------------------------------------------- |
|
264 // CWiFiProtActiveRunner::CancelByClient() |
|
265 // -------------------------------------------------------------------------- |
|
266 // |
|
267 void CWiFiProtActiveRunner::CancelByClient() |
|
268 { |
|
269 iClientCancelled = ETrue; |
|
270 Cancel(); |
|
271 if ( iWaitDlg ) |
|
272 { |
|
273 CLOG_WRITE( "Removing wait note( );" ); |
|
274 iWaitDlg->SetCallback( NULL ); |
|
275 |
|
276 TRAPD(err, iWaitDlg->ProcessFinishedL()); |
|
277 if (err) |
|
278 { |
|
279 CLOG_WRITE( "LEAVE: iWaitDlg->ProcessFinishedL" ); |
|
280 |
|
281 } |
|
282 delete iWaitDlg; |
|
283 iWaitDlg = NULL; |
|
284 } |
|
285 } |
|
286 |
|
287 // -------------------------------------------------------------------------- |
|
288 // CWiFiProtActiveRunner::ShowInitialDialogL() |
|
289 // -------------------------------------------------------------------------- |
|
290 // |
|
291 void CWiFiProtActiveRunner::ShowInitialDialogL() |
|
292 { |
|
293 CLOG_ENTERFN( "CWiFiProtActiveRunner::ShowInitialDialogL" ); |
|
294 |
|
295 if ( IsActive() == EFalse ) |
|
296 { |
|
297 |
|
298 // Check if offline mode is on: |
|
299 iInOfflineMode = EFalse; |
|
300 if ( FeatureManager::FeatureSupported( KFeatureIdOfflineMode ) ) |
|
301 { |
|
302 TInt connAllowed; |
|
303 CRepository* repository = CRepository::NewLC( |
|
304 KCRUidCoreApplicationUIs ); |
|
305 repository->Get( KCoreAppUIsNetworkConnectionAllowed, connAllowed ); |
|
306 CleanupStack::PopAndDestroy(repository); // repository |
|
307 if ( connAllowed == 0 ) |
|
308 { |
|
309 iInOfflineMode = ETrue; |
|
310 } |
|
311 } |
|
312 |
|
313 if ( iInOfflineMode && iSyncMode ) |
|
314 { |
|
315 // If in offline mode, query about offline mode first. |
|
316 iNextWiFiProtState = EWifiProtOfflineQuery; |
|
317 } |
|
318 else |
|
319 { |
|
320 // Else initiate easy setup. |
|
321 iNextWiFiProtState = EWiFiProtInitiateEasySetup; |
|
322 } |
|
323 |
|
324 iConfirmationDialog = |
|
325 new ( ELeave ) CWiFiProtConfirmationNoteDlg( iStatus ); |
|
326 iConfirmationDialog->ExecuteLD( R_WIFIPROT_CONFIGURE_AUTO_DIALOG ); |
|
327 iORequest = EWiFiProtReqConfirmDialog; |
|
328 SetActive( ); |
|
329 if ( iSyncMode ) |
|
330 { |
|
331 CLOG_WRITE( "CActiveSchedulerWait Started" ); |
|
332 iWait.Start(); |
|
333 CLOG_WRITE( "CActiveSchedulerWait Returned" ); |
|
334 } |
|
335 |
|
336 }// do nothing if already active |
|
337 |
|
338 CLOG_LEAVEFN( "CWiFiProtActiveRunner::ShowInitialDialogL" ); |
|
339 |
|
340 } |
|
341 |
|
342 // -------------------------------------------------------------------------- |
|
343 // CWiFiProtActiveRunner::ShowInitiateEasySetupDialogL() |
|
344 // -------------------------------------------------------------------------- |
|
345 // |
|
346 void CWiFiProtActiveRunner::ShowInitiateEasySetupDialogL() |
|
347 { |
|
348 CLOG_ENTERFN( "CWiFiProtActiveRunner::ShowInitiateEasySetupDialogL" ); |
|
349 |
|
350 iDestroyInitDialogLater = EFalse; |
|
351 iNextWiFiProtState = EWiFiProtUsePinCode; |
|
352 //store it, but not own it |
|
353 iInitDialog = new ( ELeave ) CWiFiProtInitiateEasySetupDlg( iStatus ); |
|
354 iInitDialog->PrepareLC( R_WIFIPROT_INITIATE_EASY_SETUP_DIALOG ); |
|
355 _LIT( KLinkStartTag, "\n<AknMessageQuery Link>" ); |
|
356 _LIT( KLinkEndTag, "</AknMessageQuery Link>" ); |
|
357 |
|
358 HBufC *messageBase = |
|
359 StringLoader::LoadLC( R_QTN_NETW_CONSET_WPS_MSG_PBC ); |
|
360 HBufC* linkString1 = StringLoader::LoadLC( |
|
361 R_QTN_NETW_CONSET_WPS_MSG_LINK_USE_PIN ); |
|
362 |
|
363 TInt lenMsg = messageBase->Des().Length()+ |
|
364 linkString1->Des().Length()+ |
|
365 KLinkStartTag().Length()+ |
|
366 KLinkEndTag().Length(); |
|
367 |
|
368 HBufC* message = HBufC::NewLC( lenMsg ); |
|
369 TPtr messagePtr = message->Des(); |
|
370 |
|
371 messagePtr.Append( messageBase->Des() ); |
|
372 |
|
373 messagePtr.Append( KLinkStartTag ); |
|
374 messagePtr.Append( linkString1->Des() ); |
|
375 messagePtr.Append( KLinkEndTag ); |
|
376 |
|
377 iInitDialog->SetMessageTextL( messagePtr ); |
|
378 CleanupStack::PopAndDestroy( message ); |
|
379 |
|
380 CleanupStack::PopAndDestroy( linkString1 ); |
|
381 CleanupStack::PopAndDestroy( messageBase ); |
|
382 TCallBack callBackLink( CWiFiProtActiveRunner::UsePinCodeLinkSelectedL, |
|
383 this ); |
|
384 |
|
385 iInitDialog->SetLink( callBackLink ); |
|
386 iInitDialog->RunLD(); |
|
387 iORequest = EWiFiProtReqInitDialog; |
|
388 SetActive( ); |
|
389 |
|
390 CLOG_LEAVEFN( "CWiFiProtActiveRunner::ShowInitiateEasySetupDialogL" ); |
|
391 |
|
392 } |
|
393 |
|
394 // -------------------------------------------------------------------------- |
|
395 // CWiFiProtActiveRunner::ShowEnterPinOnStationDialogL() |
|
396 // -------------------------------------------------------------------------- |
|
397 // |
|
398 void CWiFiProtActiveRunner::ShowEnterPinOnStationDialogL() |
|
399 { |
|
400 CLOG_ENTERFN( "CWiFiProtActiveRunner::ShowEnterPinOnStationDialogL" ); |
|
401 |
|
402 iNextWiFiProtState = EWiFiProtStartingWaitDlg; |
|
403 TInt pin = 0; |
|
404 TTime t; |
|
405 t.HomeTime(); |
|
406 TInt64 seed = t.Int64(); |
|
407 do { |
|
408 pin = Math::Rand( seed ); |
|
409 } |
|
410 while ( pin <(10^(KMaxPINLength-2)) |
|
411 || ( ((pin / 1000000) % 10) ) == 0 ); |
|
412 //last digit is checksum, so we need 7 digits |
|
413 //and the first shouldn't be 0 |
|
414 pin = pin % 10000000; |
|
415 TInt checkSum = ComputeChecksum(pin); |
|
416 pin *= 10; |
|
417 pin += checkSum; |
|
418 _LIT(KPinFormat,"%d"); |
|
419 iPIN.Format(KPinFormat, pin); |
|
420 |
|
421 CLOG_WRITE( "Enter pin code note" ); |
|
422 |
|
423 HBufC* prompt = |
|
424 StringLoader::LoadLC( R_QTN_NETW_CONSET_WPS_INFO_ENTER_PIN_CODE, pin ); |
|
425 CWiFiProtEnterPinDlg* pinDlg = new ( ELeave ) CWiFiProtEnterPinDlg( *this ); |
|
426 |
|
427 CleanupStack::PushL(pinDlg); |
|
428 pinDlg->SetPromptL( *prompt ); |
|
429 CleanupStack::Pop(pinDlg); |
|
430 |
|
431 CleanupStack::PopAndDestroy( prompt ); |
|
432 iPinDlg = pinDlg; |
|
433 iPinDlg->ExecuteLD( R_WIFIPROT_ENTER_PIN_CODE_DIALOG ); |
|
434 iPinQueryActive = ETrue; |
|
435 SetActive( ); |
|
436 SetNextStateAndComplete( EWiFiProtConfiguring ); |
|
437 CLOG_LEAVEFN( "CWiFiProtActiveRunner::ShowEnterPinOnStationDialogL" ); |
|
438 |
|
439 } |
|
440 |
|
441 // -------------------------------------------------------------------------- |
|
442 // CWiFiProtActiveRunner::ShowWaitingDialogL() |
|
443 // -------------------------------------------------------------------------- |
|
444 // |
|
445 void CWiFiProtActiveRunner::ShowWaitingDialogL() |
|
446 { |
|
447 CLOG_ENTERFN( "CWiFiProtActiveRunner::ShowWaitingDialogL" ); |
|
448 HBufC* text = StringLoader::LoadLC( |
|
449 R_QTN_NETW_CONSET_WAIT_WPS_CONFIGURING ); |
|
450 iWaitDlg = new ( ELeave ) CAknWaitDialog( |
|
451 ( REINTERPRET_CAST( CEikDialog**, &iWaitDlg )), |
|
452 ETrue ); |
|
453 iWaitDlg->SetTextL( *text ); |
|
454 CleanupStack::PopAndDestroy( text ); |
|
455 iWaitDlg->SetCallback( this ); |
|
456 iWaitDlg->SetTone( CAknNoteDialog::EConfirmationTone ); |
|
457 iWaitDlg->ExecuteLD( R_WIFIPROT_WAIT_NOTE ); |
|
458 CLOG_LEAVEFN( "CWiFiProtActiveRunner::ShowWaitingDialogL" ); |
|
459 } |
|
460 |
|
461 |
|
462 // -------------------------------------------------------------------------- |
|
463 // CWiFiProtActiveRunner::ShowWaitingDialogAndProceedL() |
|
464 // -------------------------------------------------------------------------- |
|
465 // |
|
466 void CWiFiProtActiveRunner::ShowWaitingDialogAndProceedL() |
|
467 { |
|
468 CLOG_ENTERFN( "CWiFiProtActiveRunner::ShowWaitingDialogAndProceedL" ); |
|
469 |
|
470 iStatus = KRequestPending; //should be set by service provider |
|
471 ShowWaitingDialogL(); |
|
472 SetActive( ); |
|
473 SetNextStateAndComplete( EWiFiProtConfiguring ); |
|
474 |
|
475 CLOG_LEAVEFN( "CWiFiProtActiveRunner::ShowWaitingDialogAndProceedL" ); |
|
476 |
|
477 } |
|
478 |
|
479 // -------------------------------------------------------------------------- |
|
480 // CWiFiProtActiveRunner::ShowFinalNoteL() |
|
481 // -------------------------------------------------------------------------- |
|
482 // |
|
483 void CWiFiProtActiveRunner::ShowFinalNoteL() |
|
484 { |
|
485 CLOG_ENTERFN( "CWiFiProtActiveRunner::ShowFinalNoteL" ); |
|
486 |
|
487 const TInt KSettingsConfNone = 0; |
|
488 const TInt KSettingsConfOne = 1; |
|
489 const TInt KSettingsConfMulti = 2; |
|
490 const TInt KResourceIdInvalid = 0; |
|
491 |
|
492 HBufC* text = NULL; |
|
493 TInt resId = KResourceIdInvalid; |
|
494 CAknNoteDialog::TTone tone = CAknNoteDialog::ENoTone; |
|
495 TInt numberOfNetworksConfigured = 0; |
|
496 if ( iIsConnectionNeeded ) |
|
497 { |
|
498 // we have one network configured if we are here |
|
499 numberOfNetworksConfigured = 1; |
|
500 } |
|
501 else |
|
502 { |
|
503 numberOfNetworksConfigured = iCmArray.Count(); |
|
504 } |
|
505 |
|
506 |
|
507 //more than one = multiple |
|
508 if ( numberOfNetworksConfigured > KSettingsConfOne) |
|
509 { |
|
510 numberOfNetworksConfigured = KSettingsConfMulti; |
|
511 } |
|
512 switch ( numberOfNetworksConfigured ) |
|
513 { |
|
514 case KSettingsConfOne : |
|
515 { |
|
516 CLOG_WRITE( "Show one network configured note " ); |
|
517 HBufC* name; |
|
518 if ( iIsConnectionNeeded ) |
|
519 { |
|
520 // We have to convert the 8-bit SSID to 16-bit |
|
521 HBufC* ssid16 = HBufC::NewLC( (*iIapParametersArray) |
|
522 [iAvailableNetworks[ |
|
523 iSelectedNetworkIndex]].iSsid.Length()+1 ); |
|
524 TPtr ssid16Ptr( ssid16->Des() ); |
|
525 CnvUtfConverter::ConvertToUnicodeFromUtf8( ssid16Ptr, |
|
526 (*iIapParametersArray)[iAvailableNetworks[ |
|
527 iSelectedNetworkIndex]].iSsid ); |
|
528 ssid16Ptr.ZeroTerminate(); |
|
529 name = ssid16Ptr.AllocL(); |
|
530 CleanupStack::PopAndDestroy( ssid16 ); |
|
531 } |
|
532 else |
|
533 { |
|
534 RCmConnectionMethodExt cm = |
|
535 iCmManagerExt->ConnectionMethodL( |
|
536 iCmArray[0]->GetIntAttributeL( ECmId ) ); |
|
537 CleanupClosePushL( cm ); |
|
538 name = cm.GetStringAttributeL( EWlanSSID ); |
|
539 CleanupStack::PopAndDestroy( &cm ); |
|
540 } |
|
541 CleanupStack::PushL( name ); |
|
542 text = StringLoader::LoadL( |
|
543 R_QTN_NETW_CONSET_CONF_WPS_ONE_NETWORK_CONFIGURED , *name); |
|
544 CleanupStack::PopAndDestroy( name ); |
|
545 CleanupStack::PushL( text ); |
|
546 resId = R_WIFIPROT_OK_NOTE; |
|
547 tone = CAknNoteDialog::EConfirmationTone; |
|
548 break; |
|
549 } |
|
550 case KSettingsConfMulti: |
|
551 { |
|
552 CLOG_WRITE( "Show multiple networks configured note " ); |
|
553 text = StringLoader::LoadLC( |
|
554 R_QTN_NETW_CONSET_CONF_WPS_MULTIPLE_NETWORKS_CONFIG ); |
|
555 resId = R_WIFIPROT_OK_NOTE; |
|
556 tone = CAknNoteDialog::EConfirmationTone; |
|
557 break; |
|
558 } |
|
559 case KSettingsConfNone : |
|
560 { |
|
561 CLOG_WRITE( "Show no networks configured note " ); |
|
562 text = StringLoader::LoadLC( |
|
563 R_QTN_NETW_CONSET_CONF_WPS_NO_NETWORKS_CONFIGURED ); |
|
564 resId = R_WIFIPROT_INFO_NOTE; |
|
565 break; |
|
566 } |
|
567 default: |
|
568 { |
|
569 //should not ever get here |
|
570 CLOG_WRITE( "Unhandled Final Note!!!" ); |
|
571 User::Leave( KErrGeneral ); |
|
572 break; |
|
573 } |
|
574 } |
|
575 |
|
576 CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog( |
|
577 tone, |
|
578 CAknNoteDialog::ELongTimeout ); |
|
579 dlg->SetTextL( *text ); |
|
580 CleanupStack::PopAndDestroy( text ); |
|
581 iStatus = KRequestPending; //should be set by service provider |
|
582 SetActive( ); |
|
583 dlg->ExecuteLD( resId ); |
|
584 SetNextStateAndComplete( EWiFiProtFinished ); |
|
585 |
|
586 CLOG_LEAVEFN( "CWiFiProtActiveRunner::ShowFinalNoteL" ); |
|
587 |
|
588 } |
|
589 |
|
590 // -------------------------------------------------------------------------- |
|
591 // CWiFiProtActiveRunner::DialogDismissedL |
|
592 // -------------------------------------------------------------------------- |
|
593 // |
|
594 void CWiFiProtActiveRunner::DialogDismissedL( TInt aButtonId ) |
|
595 { |
|
596 CLOG_ENTERFN( "CWiFiProtActiveRunner::DialogDismissedL" ); |
|
597 |
|
598 //wait dialog cancelled |
|
599 if ( aButtonId == EAknSoftkeyCancel ) |
|
600 { |
|
601 CLOG_WRITE( "Cancel pressed!" ); |
|
602 if (iWaitDlg) |
|
603 { |
|
604 iWaitDlgCancelled = ETrue; |
|
605 } |
|
606 iUserCancelled = ETrue; |
|
607 CancelOngoingRequest(); |
|
608 } |
|
609 // iWaitDlg is destroyed, so we can null it |
|
610 iWaitDlg = NULL; |
|
611 |
|
612 CLOG_LEAVEFN( "CWiFiProtActiveRunner::DialogDismissedL" ); |
|
613 |
|
614 } |
|
615 |
|
616 // -------------------------------------------------------------------------- |
|
617 // CWiFiProtActiveRunner::CreateTempIapL |
|
618 // -------------------------------------------------------------------------- |
|
619 // |
|
620 TUint32 CWiFiProtActiveRunner::CreateTempIapL( TUint32& aTempServId ) |
|
621 { |
|
622 CLOG_ENTERFN( "CWiFiProtActiveRunner::CreateTempIapL" ); |
|
623 |
|
624 RCmConnectionMethodExt cm; |
|
625 cm = iCmManagerExt->CreateConnectionMethodL( KUidWlanBearerType ); |
|
626 CleanupClosePushL(cm); |
|
627 |
|
628 // We have to convert the 8-bit SSID to 16-bit for CommsDat. |
|
629 HBufC* ssid16 = HBufC::NewLC( iSsid.Length() ); |
|
630 TPtr ssid16Ptr( ssid16->Des() ); |
|
631 CnvUtfConverter::ConvertToUnicodeFromUtf8( ssid16Ptr , iSsid ); |
|
632 cm.SetStringAttributeL( EWlanSSID, *ssid16 ); |
|
633 cm.SetStringAttributeL( ECmName, *ssid16 ); |
|
634 CLOG_WRITEF( _L("SSid: ") ); |
|
635 CLOG_WRITEF( *ssid16 ); |
|
636 CleanupStack::PopAndDestroy( ssid16 ); |
|
637 |
|
638 |
|
639 cm.SetIntAttributeL( EWlanSecurityMode, EWlanSecModeWpa2 ); |
|
640 cm.UpdateL(); |
|
641 |
|
642 aTempServId = cm.GetIntAttributeL( ECmIapServiceId ); |
|
643 TInt32 iapID = cm.GetIntAttributeL( ECmId ); |
|
644 |
|
645 CommsDat::CMDBSession* db = |
|
646 CommsDat::CMDBSession::NewL( CommsDat::CMDBSession::LatestVersion() ); |
|
647 CleanupStack::PushL( db ); |
|
648 CWPASecuritySettings* wpaSecSettings = |
|
649 CWPASecuritySettings::NewL( ESecurityModeWpa ); |
|
650 CleanupStack::PushL( wpaSecSettings ); |
|
651 User::LeaveIfError( wpaSecSettings->SetWPAEnabledEAPPlugin( KEapWsc ) ); |
|
652 CLOG_WRITEF( _L("Enabled EAP plugin set: EAP WSC")); |
|
653 if (iPIN != KNullDesC) |
|
654 { |
|
655 User::LeaveIfError( wpaSecSettings->SetWPAPreSharedKey( iPIN ) ); |
|
656 CLOG_WRITEF( _L("Pin set as WPA key: ")); |
|
657 CLOG_WRITEF( iPIN ); |
|
658 } |
|
659 |
|
660 CLOG_WRITEF( _L("WPA settings save - ECmIapServiceId in aTempServId %d"), aTempServId ); |
|
661 wpaSecSettings->SaveL( aTempServId , *db, ESavingBrandNewAP, 0 ); |
|
662 CLOG_WRITEF( _L("WPA settings saved!")); |
|
663 CleanupStack::PopAndDestroy( wpaSecSettings ); |
|
664 db->Close(); |
|
665 CleanupStack::PopAndDestroy( db ); |
|
666 CleanupStack::PopAndDestroy( &cm ); |
|
667 |
|
668 CLOG_LEAVEFN( "CWiFiProtActiveRunner::CreateTempIapL" ); |
|
669 |
|
670 return iapID; |
|
671 } |
|
672 |
|
673 // -------------------------------------------------------------------------- |
|
674 // CWiFiProtActiveRunner::RunProtectedSetup |
|
675 // -------------------------------------------------------------------------- |
|
676 // |
|
677 void CWiFiProtActiveRunner::RunProtectedSetup ( const TInt32 aIapId ) |
|
678 { |
|
679 |
|
680 CLOG_ENTERFN( "CWiFiProtActiveRunner::RunProtectedSetup" ); |
|
681 |
|
682 iNextWiFiProtState = EWiFiProtWlanMgmtEngineReturned; |
|
683 if ( iWlanMgmtEngine ) |
|
684 { |
|
685 CLOG_WRITEF(_L( |
|
686 "We have a wlanmgmt engine, calling RunProtectedSetup with uid %d") |
|
687 , aIapId ); |
|
688 iWlanMgmtEngine->RunProtectedSetup( iStatus, aIapId, |
|
689 *iIapParametersArray ); |
|
690 iORequest = EWiFiProtReqWPS; |
|
691 SetActive( ); |
|
692 } |
|
693 else |
|
694 { |
|
695 // we complete ourselves after creating these cms synchronously |
|
696 //just for wins testing |
|
697 //add 1 conneciton method; |
|
698 #ifdef __WINS__ |
|
699 CLOG_WRITE( "No wlanmgmt engine, simulating... " ); |
|
700 TWlanProtectedSetupCredentialAttribute tmpCred; |
|
701 tmpCred.iOperatingMode = EWlanOperatingModeInfrastructure; |
|
702 tmpCred.iAuthenticationMode = EWlanAuthenticationModeOpen; |
|
703 tmpCred.iSecurityMode = EWlanIapSecurityModeAllowUnsecure; |
|
704 tmpCred.iSsid = _L8("Available Network"); |
|
705 |
|
706 TRAP_IGNORE( iIapParametersArray->AppendL(tmpCred) ); |
|
707 |
|
708 tmpCred.iOperatingMode = EWlanOperatingModeInfrastructure; |
|
709 tmpCred.iAuthenticationMode = EWlanAuthenticationModeOpen; |
|
710 tmpCred.iSecurityMode = EWlanIapSecurityModeAllowUnsecure; |
|
711 tmpCred.iSsid = _L8("Available Network 2"); |
|
712 |
|
713 TRAP_IGNORE( iIapParametersArray->AppendL(tmpCred) ); |
|
714 |
|
715 tmpCred.iOperatingMode = EWlanOperatingModeInfrastructure; |
|
716 tmpCred.iAuthenticationMode = EWlanAuthenticationModeOpen; |
|
717 tmpCred.iSecurityMode = EWlanIapSecurityModeAllowUnsecure; |
|
718 tmpCred.iSsid = _L8("Unavailable Network"); |
|
719 |
|
720 TRAP_IGNORE( iIapParametersArray->AppendL(tmpCred) ); |
|
721 |
|
722 iStatus = KRequestPending; |
|
723 SetActive( ); |
|
724 SetNextStateAndComplete(EWiFiProtWlanMgmtEngineReturned ); |
|
725 #else |
|
726 //no engine in hardware, should not ever get here! |
|
727 User::Panic( KWiFiPanic , KErrNotFound ); |
|
728 #endif |
|
729 } |
|
730 |
|
731 CLOG_LEAVEFN( "CWiFiProtActiveRunner::RunProtectedSetup" ); |
|
732 |
|
733 } |
|
734 |
|
735 // -------------------------------------------------------------------------- |
|
736 // CWiFiProtActiveRunner::CWiFiProtActiveRunner |
|
737 // -------------------------------------------------------------------------- |
|
738 // |
|
739 CWiFiProtActiveRunner::CWiFiProtActiveRunner( |
|
740 CWiFiProtDlgsPlugin* aParent, TInt aPriority ) |
|
741 : CActive( aPriority ), |
|
742 iParent( aParent ), |
|
743 iIsConnectionNeeded( EFalse ), |
|
744 iWaitDlgCancelled( EFalse ), |
|
745 iSsid( KNullDesC8 ), |
|
746 iPIN( KNullDesC ), |
|
747 iNextWiFiProtState( EWiFiProtAskConfigureAutomatically ), |
|
748 iReturn( EWiFiCancel ), |
|
749 iUsePin( EFalse ), |
|
750 iError( KErrNone ), |
|
751 iPinQueryActive( EFalse ), |
|
752 iWaitNoteNeeded( EFalse ), |
|
753 iInitDialog( NULL ), |
|
754 iClientCancelled( EFalse ) |
|
755 { |
|
756 CLOG_ENTERFN( "CWiFiProtActiveRunner::CWiFiProtActiveRunner" ); |
|
757 |
|
758 CLOG_LEAVEFN( "CWiFiProtActiveRunner::CWiFiProtActiveRunner" ); |
|
759 |
|
760 } |
|
761 |
|
762 // -------------------------------------------------------------------------- |
|
763 // CWiFiProtActiveRunner::ConstructL |
|
764 // -------------------------------------------------------------------------- |
|
765 // |
|
766 void CWiFiProtActiveRunner::ConstructL() |
|
767 { |
|
768 CLOG_ENTERFN( "CWiFiProtActiveRunner::ConstructL" ); |
|
769 |
|
770 CActiveScheduler::Add( this ); |
|
771 #ifndef __WINS__ |
|
772 iWlanMgmtEngine = CWlanMgmtClient::NewL(); |
|
773 iScanInfo = CWlanScanInfo::NewL(); |
|
774 #endif // !__WINS__ |
|
775 iIapParametersArray = new (ELeave) |
|
776 CArrayFixSeg<TWlanProtectedSetupCredentialAttribute> |
|
777 ( KArrayGranularity ); |
|
778 |
|
779 User::LeaveIfError(iNotifier.Connect()); // Connects to the extended notifier server |
|
780 |
|
781 CLOG_LEAVEFN( "CWiFiProtActiveRunner::ConstructL" ); |
|
782 |
|
783 } |
|
784 |
|
785 // -------------------------------------------------------------------------- |
|
786 // CWiFiProtActiveRunner::DoCancel |
|
787 // -------------------------------------------------------------------------- |
|
788 // |
|
789 void CWiFiProtActiveRunner::DoCancel() |
|
790 { |
|
791 CLOG_ENTERFN( "CWiFiProtActiveRunner::DoCancel" ); |
|
792 |
|
793 CancelOngoingRequest(); |
|
794 |
|
795 CLOG_LEAVEFN( "CWiFiProtActiveRunner::DoCancel" ); |
|
796 |
|
797 } |
|
798 |
|
799 // -------------------------------------------------------------------------- |
|
800 // CWiFiProtActiveRunner::RunL |
|
801 // -------------------------------------------------------------------------- |
|
802 // |
|
803 void CWiFiProtActiveRunner::RunL() |
|
804 { |
|
805 CLOG_ENTERFN( "CWiFiProtActiveRunner::RunL" ); |
|
806 |
|
807 // reset the async request id |
|
808 iORequest = EWiFiProtReqNone; |
|
809 |
|
810 if ( iClientCancelled ) |
|
811 { |
|
812 // no further actions needed here, message completion taken care of |
|
813 // in the notifier |
|
814 return; |
|
815 } |
|
816 |
|
817 CLOG_WRITEF( _L(" iNextWiFiProtState: %d"), iNextWiFiProtState ); |
|
818 if ( iNextWiFiProtState == EWiFiProtWlanMgmtEngineReturned ) |
|
819 { |
|
820 iORequest = EWiFiProtReqNone; |
|
821 //if we have a dialog and configuration is finished, |
|
822 // store error code for destroying dialog |
|
823 iError = iStatus.Int(); |
|
824 CleanupTempIapL(); |
|
825 } |
|
826 else if ( iNextWiFiProtState == EWiFiProtDestroyWaitNote ) |
|
827 { |
|
828 DestroyWaitDialog(); |
|
829 } |
|
830 else |
|
831 { |
|
832 if ( iUserCancelled ) |
|
833 { |
|
834 iStatus = KErrCancel; |
|
835 } |
|
836 |
|
837 if ( iStatus.Int() == KErrNone ) //no error |
|
838 { |
|
839 HandleNoErrorL(); |
|
840 } |
|
841 // error or cancel |
|
842 // try to handle error, if can't, just cancel |
|
843 else if ( !HandleErrorL( iStatus.Int() ) ) |
|
844 { |
|
845 if ( (iStatus.Int() != KErrAbort) && |
|
846 (iNextWiFiProtState == EWifiProtOfflineQuery || iNextWiFiProtState == EWiFiProtInitiateEasySetup) ) |
|
847 { |
|
848 // Use WPS to configure or connect in offline mode? -> No -> Continue the traditional way without WPS |
|
849 iReturn = EWifiNoAuto; |
|
850 } |
|
851 else |
|
852 { |
|
853 iReturn = EWiFiCancel; |
|
854 } |
|
855 |
|
856 if ( iSyncMode ) |
|
857 { |
|
858 if ( iWait.IsStarted() ) |
|
859 { |
|
860 iWait.AsyncStop(); |
|
861 } |
|
862 } |
|
863 else |
|
864 { |
|
865 iParent->CompleteProcessL( iReturn ); |
|
866 } |
|
867 } |
|
868 } |
|
869 |
|
870 CLOG_LEAVEFN( "CWiFiProtActiveRunner::RunL" ); |
|
871 |
|
872 } |
|
873 |
|
874 // -------------------------------------------------------------------------- |
|
875 // CWiFiProtActiveRunner::SetNextStateAndComplete |
|
876 // -------------------------------------------------------------------------- |
|
877 // |
|
878 void CWiFiProtActiveRunner::SetNextStateAndComplete( |
|
879 TWiFiProtStates aNextState, |
|
880 TInt aError ) |
|
881 { |
|
882 CLOG_ENTERFN( "CWiFiProtActiveRunner::SetNextStateAndComplete" ); |
|
883 |
|
884 iNextWiFiProtState = aNextState; |
|
885 CLOG_WRITEF( _L(" aNextState: %d"), aNextState ); |
|
886 TRequestStatus* pS = &iStatus; |
|
887 User::RequestComplete( pS, aError ); |
|
888 |
|
889 CLOG_LEAVEFN( "CWiFiProtActiveRunner::SetNextStateAndComplete" ); |
|
890 |
|
891 } |
|
892 |
|
893 // -------------------------------------------------------------------------- |
|
894 // CWiFiProtActiveRunner::ConfigureL() |
|
895 // -------------------------------------------------------------------------- |
|
896 // |
|
897 void CWiFiProtActiveRunner::ConfigureL() |
|
898 { |
|
899 CLOG_ENTERFN( "CWiFiProtActiveRunner::ConfigureL" ); |
|
900 iWaitNoteNeeded = ETrue; |
|
901 iTempIapId = CreateTempIapL( iTempServId ); |
|
902 CLOG_WRITEF( _L("Temp Iap created! Id: %d"), iTempIapId ); |
|
903 RunProtectedSetup( iTempServId ); |
|
904 // do not complete self, waiting for engine or user cancel to complete us |
|
905 |
|
906 CLOG_LEAVEFN( "CWiFiProtActiveRunner::ConfigureL" ); |
|
907 |
|
908 } |
|
909 |
|
910 // -------------------------------------------------------------------------- |
|
911 // CWiFiProtActiveRunner::EvaluateResult |
|
912 // -------------------------------------------------------------------------- |
|
913 // |
|
914 void CWiFiProtActiveRunner::EvaluateResult() |
|
915 { |
|
916 CLOG_ENTERFN( "CWiFiProtActiveRunner::EvaluateResult" ); |
|
917 if (iError == KErrNone) |
|
918 { |
|
919 if ( iIsConnectionNeeded ) |
|
920 { |
|
921 TRAPD(err, CheckNetworkAvailabilityL()); |
|
922 if (err) |
|
923 { |
|
924 CLOG_WRITE( |
|
925 "LEAVE: CheckNetworkAvailabilityL" ); |
|
926 } |
|
927 } |
|
928 else |
|
929 { |
|
930 CLOG_WRITE( |
|
931 "SetNextStateAndComplete( EWiFiProtSettingsConfNote );" ); |
|
932 SetNextStateAndComplete( EWiFiProtSettingsConfNote ); |
|
933 } |
|
934 } |
|
935 else |
|
936 { //now we complete with the error code as dialog is finished |
|
937 CLOG_WRITE( "SetNextStateAndComplete( EWiFiProtFinished, iError );" ); |
|
938 SetNextStateAndComplete( EWiFiProtFinished , iError ); |
|
939 } |
|
940 CLOG_LEAVEFN( "CWiFiProtActiveRunner::EvaluateResult" ); |
|
941 } |
|
942 |
|
943 // -------------------------------------------------------------------------- |
|
944 // CWiFiProtActiveRunner::DestroyWaitDialog |
|
945 // -------------------------------------------------------------------------- |
|
946 // |
|
947 void CWiFiProtActiveRunner::DestroyWaitDialog() |
|
948 { |
|
949 CLOG_ENTERFN( "CWiFiProtActiveRunner::DestroyWaitDialog" ); |
|
950 |
|
951 CLOG_WRITE( "SetActive();" ); |
|
952 SetActive(); |
|
953 iStatus = KRequestPending; //should be set by service provider |
|
954 iWaitNoteNeeded = EFalse; |
|
955 if( !iWaitDlgCancelled ) |
|
956 { |
|
957 // iWaitDlg possibly wasn't even shown... |
|
958 if ( iWaitDlg ) |
|
959 { |
|
960 CLOG_WRITE( "iWaitDlg->SetCallback( NULL );" ); |
|
961 iWaitDlg->SetCallback( NULL ); |
|
962 CLOG_WRITE( "iWaitDlg->ProcessFinishedL( );" ); |
|
963 |
|
964 TRAPD(err, iWaitDlg->ProcessFinishedL()); |
|
965 if (err) |
|
966 { |
|
967 CLOG_WRITE( "LEAVE: iWaitDlg->ProcessFinishedL( );" ); |
|
968 } |
|
969 |
|
970 CLOG_WRITE( "delete iWaitDlg;" ); |
|
971 delete iWaitDlg; |
|
972 iWaitDlg = NULL; |
|
973 } |
|
974 if ( iPinQueryActive ) //waiting for PIN Query |
|
975 { |
|
976 CLOG_WRITE( |
|
977 "SetNextStateAndComplete( EWiFiProtWaitForPINQuery );" ); |
|
978 // if pin query is still active, remove the cancel... |
|
979 if ( iPinQueryActive && iPinDlg) |
|
980 { |
|
981 iPinDlg->RemoveCancel(); |
|
982 } |
|
983 iNextWiFiProtState = EWiFiProtWaitForPINQuery; |
|
984 } |
|
985 else |
|
986 { |
|
987 EvaluateResult(); |
|
988 } |
|
989 } |
|
990 else |
|
991 { |
|
992 CLOG_WRITE( |
|
993 "SetNextStateAndComplete( EWiFiProtFinished, KErrCancel );" ); |
|
994 SetNextStateAndComplete( EWiFiProtFinished , KErrCancel ); |
|
995 } |
|
996 |
|
997 CLOG_LEAVEFN( "CWiFiProtActiveRunner::DestroyWaitDialog" ); |
|
998 |
|
999 } |
|
1000 |
|
1001 // -------------------------------------------------------------------------- |
|
1002 // CWiFiProtActiveRunner::ComputeChecksum |
|
1003 // -------------------------------------------------------------------------- |
|
1004 // |
|
1005 TInt CWiFiProtActiveRunner::ComputeChecksum(TInt aPin) |
|
1006 { |
|
1007 CLOG_ENTERFN( "CWiFiProtActiveRunner::ComputeChecksum" ); |
|
1008 |
|
1009 TInt accum = 0; |
|
1010 aPin *= 10; |
|
1011 accum += 3 * ((aPin / 10000000) % 10); |
|
1012 accum += 1 * ((aPin / 1000000) % 10); |
|
1013 accum += 3 * ((aPin / 100000) % 10); |
|
1014 accum += 1 * ((aPin / 10000) % 10); |
|
1015 accum += 3 * ((aPin / 1000) % 10); |
|
1016 accum += 1 * ((aPin / 100) % 10); |
|
1017 accum += 3 * ((aPin / 10) % 10); |
|
1018 TInt digit = (accum % 10); |
|
1019 |
|
1020 CLOG_LEAVEFN( "CWiFiProtActiveRunner::ComputeChecksum" ); |
|
1021 |
|
1022 return (10 - digit) % 10; |
|
1023 } |
|
1024 |
|
1025 // -------------------------------------------------------------------------- |
|
1026 // CWiFiProtActiveRunner::CreateAllIapsL |
|
1027 // -------------------------------------------------------------------------- |
|
1028 // |
|
1029 void CWiFiProtActiveRunner::CreateAllIapsL() |
|
1030 { |
|
1031 CreateIapL(0); |
|
1032 iStatus = KRequestPending; //should be set by service provider |
|
1033 SetActive(); |
|
1034 if ( iIapParametersArray->Count() ) |
|
1035 { |
|
1036 //another cm, another round |
|
1037 SetNextStateAndComplete( EWiFiProtCreateAllIaps ); |
|
1038 } |
|
1039 else |
|
1040 { |
|
1041 //cm creation finished |
|
1042 SetNextStateAndComplete( EWiFiProtDestroyWaitNote ); |
|
1043 } |
|
1044 } |
|
1045 |
|
1046 // -------------------------------------------------------------------------- |
|
1047 // CWiFiProtActiveRunner::CreateIapL |
|
1048 // -------------------------------------------------------------------------- |
|
1049 // |
|
1050 TUint32 CWiFiProtActiveRunner::CreateIapL( const TInt aIndex ) |
|
1051 { |
|
1052 CLOG_ENTERFN( "CWiFiProtActiveRunner::CreateIapL" ); |
|
1053 |
|
1054 TInt32 iapID = 0; |
|
1055 if ( iIapParametersArray->Count() ) |
|
1056 { |
|
1057 RCmConnectionMethodExt cm; |
|
1058 cm = iCmManagerExt->CreateConnectionMethodL( KUidWlanBearerType ); |
|
1059 CleanupClosePushL(cm); |
|
1060 iapID = SetIapDataL( aIndex, cm ); |
|
1061 CleanupStack::Pop( &cm ); |
|
1062 |
|
1063 RCmConnectionMethodExt* cmToAppend = |
|
1064 new (ELeave) RCmConnectionMethodExt(cm); |
|
1065 CleanupStack::PushL(cmToAppend); |
|
1066 iCmArray.Append( cmToAppend ); //ownership transferred |
|
1067 CleanupStack::Pop( cmToAppend ); |
|
1068 CLOG_WRITEF( _L("Cm appended to array: ") ); |
|
1069 |
|
1070 |
|
1071 (*iIapParametersArray).Delete(aIndex); |
|
1072 } |
|
1073 |
|
1074 |
|
1075 CLOG_LEAVEFN( "CWiFiProtActiveRunner::CreateIapL" ); |
|
1076 |
|
1077 return iapID; |
|
1078 } |
|
1079 |
|
1080 |
|
1081 // -------------------------------------------------------------------------- |
|
1082 // CWiFiProtActiveRunner::SetIapDataL |
|
1083 // -------------------------------------------------------------------------- |
|
1084 // |
|
1085 TUint32 CWiFiProtActiveRunner::SetIapDataL( const TInt aIndex, |
|
1086 RCmConnectionMethodExt& aCmToSet ) |
|
1087 { |
|
1088 // We have to convert the 8-bit SSID to 16-bit for CommsDat. |
|
1089 HBufC* ssid16 = |
|
1090 HBufC::NewLC( ( *iIapParametersArray)[aIndex].iSsid.Length() ); |
|
1091 TPtr ssid16Ptr( ssid16->Des() ); |
|
1092 CnvUtfConverter::ConvertToUnicodeFromUtf8( |
|
1093 ssid16Ptr , (*iIapParametersArray)[aIndex].iSsid ); |
|
1094 |
|
1095 aCmToSet.SetStringAttributeL( ECmName, *ssid16 ); |
|
1096 aCmToSet.SetStringAttributeL( EWlanSSID, *ssid16 ); |
|
1097 CLOG_WRITEF( _L("Parameters from wlan mgmt engine: ") ); |
|
1098 CLOG_WRITEF( _L("SSid: ") ); |
|
1099 CLOG_WRITEF( *ssid16 ); |
|
1100 CleanupStack::PopAndDestroy( ssid16 ); |
|
1101 |
|
1102 TInt connMode = EAdhoc; |
|
1103 switch ( (*iIapParametersArray)[aIndex].iOperatingMode ) |
|
1104 { |
|
1105 case EWlanOperatingModeAdhoc: |
|
1106 { |
|
1107 CLOG_WRITEF( _L("Operating Mode: Adhoc") ); |
|
1108 break; |
|
1109 } |
|
1110 case EWlanOperatingModeInfrastructure: |
|
1111 { |
|
1112 CLOG_WRITEF( _L("Operating Mode: Infra") ); |
|
1113 connMode = EInfra; |
|
1114 break; |
|
1115 } |
|
1116 default: |
|
1117 { |
|
1118 CLOG_WRITEF( _L("Operating Mode: Not Supported") ); |
|
1119 User::Leave( KErrNotSupported ); |
|
1120 break; |
|
1121 } |
|
1122 } |
|
1123 aCmToSet.SetIntAttributeL( EWlanConnectionMode, connMode ); |
|
1124 |
|
1125 CMManager::TWlanSecMode secMode = EWlanSecModeOpen; |
|
1126 switch( (*iIapParametersArray)[aIndex].iSecurityMode ) |
|
1127 { |
|
1128 case EWlanIapSecurityModeAllowUnsecure: |
|
1129 { |
|
1130 CLOG_WRITEF( _L("Security Mode: Open") ); |
|
1131 secMode = EWlanSecModeOpen; |
|
1132 break; |
|
1133 } |
|
1134 |
|
1135 case EWlanIapSecurityModeWep: |
|
1136 { |
|
1137 CLOG_WRITEF( _L("Security Mode: Wep") ); |
|
1138 secMode = EWlanSecModeWep; |
|
1139 break; |
|
1140 } |
|
1141 |
|
1142 case EWlanIapSecurityMode802d1x: |
|
1143 { |
|
1144 CLOG_WRITEF( _L("Security Mode: 802_1x") ); |
|
1145 secMode = EWlanSecMode802_1x; |
|
1146 break; |
|
1147 } |
|
1148 |
|
1149 // EWlanIapSecurityModeWpa and |
|
1150 // EWlanIapSecurityModeWpa2Only are handled as wpa |
|
1151 case EWlanIapSecurityModeWpa: |
|
1152 case EWlanIapSecurityModeWpa2Only: |
|
1153 { |
|
1154 CLOG_WRITEF( _L("Security Mode: wpa") ); |
|
1155 secMode = EWlanSecModeWpa; |
|
1156 break; |
|
1157 } |
|
1158 |
|
1159 default: |
|
1160 { |
|
1161 User::Leave( KErrNotSupported ); |
|
1162 } |
|
1163 } |
|
1164 |
|
1165 aCmToSet.SetIntAttributeL( EWlanSecurityMode, secMode ); |
|
1166 |
|
1167 aCmToSet.UpdateL(); |
|
1168 TInt32 wlanServId = aCmToSet.GetIntAttributeL( ECmIapServiceId ); |
|
1169 TInt32 iapID = aCmToSet.GetIntAttributeL( ECmId ); |
|
1170 |
|
1171 CommsDat::CMDBSession* db = |
|
1172 CommsDat::CMDBSession::NewL( |
|
1173 CommsDat::CMDBSession::LatestVersion() ); |
|
1174 CleanupStack::PushL( db ); |
|
1175 |
|
1176 switch( (*iIapParametersArray)[aIndex].iSecurityMode ) |
|
1177 { |
|
1178 case EWlanIapSecurityModeWep: |
|
1179 { |
|
1180 SaveWepSecuritySettingsL( |
|
1181 ( *iIapParametersArray )[aIndex], wlanServId, *db ); |
|
1182 break; |
|
1183 } |
|
1184 // EWlanIapSecurityModeWpa and |
|
1185 // EWlanIapSecurityModeWpa2Only are handled as wpa |
|
1186 case EWlanIapSecurityModeWpa: |
|
1187 case EWlanIapSecurityModeWpa2Only: |
|
1188 { |
|
1189 CWPASecuritySettings* wpaSecSettings = |
|
1190 CWPASecuritySettings::NewL( ESecurityModeWpa ); |
|
1191 CleanupStack::PushL( wpaSecSettings ); |
|
1192 if ((*iIapParametersArray) |
|
1193 [aIndex].iWpaPreSharedKey != KNullDesC8) |
|
1194 { |
|
1195 TBuf<KWlanWpaPskMaxLength> wpaBuf16; |
|
1196 wpaBuf16.Copy((*iIapParametersArray) |
|
1197 [aIndex].iWpaPreSharedKey); |
|
1198 User::LeaveIfError( |
|
1199 wpaSecSettings->SetWPAPreSharedKey( wpaBuf16 ) ); |
|
1200 CLOG_WRITEF( _L("wpa psk set: ") ); |
|
1201 CLOG_WRITEF( wpaBuf16 ); |
|
1202 |
|
1203 } |
|
1204 |
|
1205 TTypeOfSaving typeOfSaving = ESavingBrandNewAP; |
|
1206 |
|
1207 if ( iapID == iCmManagerExt->EasyWlanIdL() ) |
|
1208 { |
|
1209 typeOfSaving = ESavingEditedAP; |
|
1210 } |
|
1211 |
|
1212 wpaSecSettings->SaveL( wlanServId, *db, |
|
1213 typeOfSaving, 0 ) ; |
|
1214 |
|
1215 CleanupStack::PopAndDestroy( wpaSecSettings ); |
|
1216 break; |
|
1217 } |
|
1218 // EWlanIapSecurityMode802d1x and |
|
1219 // EWlanConnectionSecurityOpen - no key needs to be saved |
|
1220 case EWlanIapSecurityMode802d1x: |
|
1221 case EWlanConnectionSecurityOpen: |
|
1222 default: |
|
1223 { |
|
1224 break; |
|
1225 } |
|
1226 } |
|
1227 |
|
1228 db->Close(); |
|
1229 CleanupStack::PopAndDestroy( db ); |
|
1230 return iapID; |
|
1231 } |
|
1232 |
|
1233 // -------------------------------------------------------------------------- |
|
1234 // CWiFiProtActiveRunner::CleanupTempIapL() |
|
1235 // -------------------------------------------------------------------------- |
|
1236 // |
|
1237 void CWiFiProtActiveRunner::CleanupTempIapL() |
|
1238 { |
|
1239 CLOG_ENTERFN( "CWiFiProtActiveRunner::CleanupTempIapL" ); |
|
1240 |
|
1241 //we don't need the temp iap anymore, delete it |
|
1242 //shouldn't be any errors, because nobody else knows about our temp iap |
|
1243 DeleteTempIapL(); |
|
1244 SetActive(); |
|
1245 iStatus = KRequestPending; //should be set by service provider |
|
1246 if ( iError == KErrNone ) |
|
1247 { |
|
1248 if ( iIsConnectionNeeded ) |
|
1249 { |
|
1250 StartWlanScan(); //scan wlan before we close the wait dialog |
|
1251 } |
|
1252 else |
|
1253 { |
|
1254 //start creating iaps |
|
1255 SetNextStateAndComplete( EWiFiProtCreateAllIaps ); |
|
1256 } |
|
1257 } |
|
1258 else |
|
1259 { |
|
1260 //don't create iaps or scan wlan, we had an error! |
|
1261 SetNextStateAndComplete( EWiFiProtDestroyWaitNote ); |
|
1262 } |
|
1263 |
|
1264 CLOG_LEAVEFN( "CWiFiProtActiveRunner::CleanupTempIapL" ); |
|
1265 |
|
1266 } |
|
1267 |
|
1268 // -------------------------------------------------------------------------- |
|
1269 // CWiFiProtActiveRunner::DeleteTempIapL() |
|
1270 // -------------------------------------------------------------------------- |
|
1271 // |
|
1272 void CWiFiProtActiveRunner::DeleteTempIapL() |
|
1273 { |
|
1274 CLOG_ENTERFN( "CWiFiProtActiveRunner::DeleteTempIapL" ); |
|
1275 |
|
1276 if ( iTempIapId ) |
|
1277 { |
|
1278 const TInt KInvalidUid = 0; |
|
1279 |
|
1280 CLOG_WRITE( "Calling iCmManagerExt->ConnectionMethodL" ); |
|
1281 |
|
1282 RCmConnectionMethodExt cm = |
|
1283 iCmManagerExt->ConnectionMethodL(iTempIapId); |
|
1284 |
|
1285 CLOG_WRITE( "Calling cm.DeleteL" ); |
|
1286 |
|
1287 TRAPD(err, cm.DeleteL()); |
|
1288 CLOG_WRITEF( _L("Temp Iap deleted! Error code: %d"), err ); |
|
1289 cm.Close(); |
|
1290 iTempIapId = KInvalidUid; |
|
1291 } |
|
1292 |
|
1293 CLOG_LEAVEFN( "CWiFiProtActiveRunner::DeleteTempIapL" ); |
|
1294 |
|
1295 } |
|
1296 |
|
1297 // -------------------------------------------------------------------------- |
|
1298 // CWiFiProtActiveRunner::IsWepFormatHexL |
|
1299 // -------------------------------------------------------------------------- |
|
1300 // |
|
1301 TBool CWiFiProtActiveRunner::IsWepFormatHexL( TInt aLength ) |
|
1302 { |
|
1303 CLOG_ENTERFN( "CWiFiProtActiveRunner::IsWepFormatHexL" ); |
|
1304 |
|
1305 if ( ( aLength == KConnUiUtilsWepLengthASCII5 ) || |
|
1306 ( aLength == KConnUiUtilsWepLengthASCII13 ) || |
|
1307 ( aLength == KConnUiUtilsWepLengthASCII29 ) ) |
|
1308 { |
|
1309 return EFalse; |
|
1310 } |
|
1311 else if ( ( aLength == KConnUiUtilsWepLengthHEX10 ) || |
|
1312 ( aLength == KConnUiUtilsWepLengthHEX26 ) || |
|
1313 ( aLength == KConnUiUtilsWepLengthHEX58 ) ) |
|
1314 { |
|
1315 return ETrue; |
|
1316 } |
|
1317 else |
|
1318 { |
|
1319 User::Leave( KErrNotSupported ); |
|
1320 } |
|
1321 |
|
1322 CLOG_LEAVEFN( "CWiFiProtActiveRunner::IsWepFormatHexL" ); |
|
1323 |
|
1324 return EFalse; |
|
1325 } |
|
1326 |
|
1327 // -------------------------------------------------------------------------- |
|
1328 // CWiFiProtActiveRunner::SaveWepSecuritySettingsL |
|
1329 // -------------------------------------------------------------------------- |
|
1330 // |
|
1331 void CWiFiProtActiveRunner::SaveWepSecuritySettingsL( |
|
1332 TWlanProtectedSetupCredentialAttribute |
|
1333 aCredentialAttribute, |
|
1334 TUint32 aWlanServiceId, |
|
1335 CommsDat::CMDBSession& aDb ) |
|
1336 { |
|
1337 CLOG_ENTERFN( "CWiFiProtActiveRunner::SaveWepSecuritySettingsL" ); |
|
1338 |
|
1339 CWEPSecuritySettings* wepSecSettings = CWEPSecuritySettings::NewL( ); |
|
1340 CleanupStack::PushL( wepSecSettings ); |
|
1341 TInt keyIndex = 0; |
|
1342 // wep key 1 |
|
1343 SetWepKeyL( *wepSecSettings, aCredentialAttribute.iWepKey1, keyIndex ); |
|
1344 keyIndex++; |
|
1345 // wep key 2 |
|
1346 SetWepKeyL( *wepSecSettings, aCredentialAttribute.iWepKey2, keyIndex ); |
|
1347 keyIndex++; |
|
1348 // wep key 3 |
|
1349 SetWepKeyL( *wepSecSettings, aCredentialAttribute.iWepKey3, keyIndex ); |
|
1350 keyIndex++; |
|
1351 // wep key 4 |
|
1352 SetWepKeyL( *wepSecSettings, aCredentialAttribute.iWepKey4, keyIndex ); |
|
1353 |
|
1354 //should be the same enum |
|
1355 wepSecSettings->SetKeyInUse( (CWEPSecuritySettings::TWEPKeyInUse) |
|
1356 aCredentialAttribute.iWepDefaultKey ); |
|
1357 CLOG_WRITEF( _L("Wep key in use %d:"), |
|
1358 aCredentialAttribute.iWepDefaultKey ); |
|
1359 |
|
1360 CWEPSecuritySettings::TWEPAuthentication auth = |
|
1361 CWEPSecuritySettings::EAuthOpen; |
|
1362 |
|
1363 switch( aCredentialAttribute.iAuthenticationMode ) |
|
1364 { |
|
1365 case EWlanAuthenticationModeOpen: |
|
1366 { |
|
1367 CLOG_WRITEF( _L("Authentication mode: open") ); |
|
1368 break; |
|
1369 } |
|
1370 case EWlanAuthenticationModeShared: |
|
1371 { |
|
1372 CLOG_WRITEF( _L("Authentication mode: shared") ); |
|
1373 auth = CWEPSecuritySettings::EAuthShared; |
|
1374 break; |
|
1375 } |
|
1376 default: |
|
1377 { |
|
1378 break; |
|
1379 } |
|
1380 } |
|
1381 |
|
1382 //should be the same enum |
|
1383 wepSecSettings->SetAuthentication( |
|
1384 (CWEPSecuritySettings::TWEPAuthentication) auth ); |
|
1385 wepSecSettings->SaveL( aWlanServiceId, aDb ) ; |
|
1386 CleanupStack::PopAndDestroy( wepSecSettings ); |
|
1387 |
|
1388 CLOG_LEAVEFN( "CWiFiProtActiveRunner::SaveWepSecuritySettingsL" ); |
|
1389 |
|
1390 } |
|
1391 |
|
1392 // -------------------------------------------------------------------------- |
|
1393 // CWiFiProtActiveRunner::HandleErrorL() |
|
1394 // -------------------------------------------------------------------------- |
|
1395 // |
|
1396 TBool CWiFiProtActiveRunner::HandleErrorL( TInt aErrorCode ) |
|
1397 { |
|
1398 CLOG_ENTERFN( "CWiFiProtActiveRunner::HandleErrorL" ); |
|
1399 |
|
1400 CLOG_WRITEF( _L("Error code: %d"), aErrorCode ); |
|
1401 if (iWaitDlg) //close dialog first |
|
1402 { |
|
1403 TInt error = iStatus.Int(); |
|
1404 iStatus = KRequestPending; //should be set by service provider |
|
1405 SetActive( ); |
|
1406 SetNextStateAndComplete( EWiFiProtDestroyWaitNote , error ); |
|
1407 |
|
1408 CLOG_LEAVEFN( "CWiFiProtActiveRunner::HandleErrorL" ); |
|
1409 |
|
1410 return ETrue; |
|
1411 } |
|
1412 else |
|
1413 { |
|
1414 TWiFiProtStates nextState = EWiFiProtFinished; |
|
1415 TInt textResId = 0; |
|
1416 TInt status = KErrCancel; |
|
1417 TBool ret = ETrue; |
|
1418 switch (aErrorCode) |
|
1419 { |
|
1420 // Error codes are in the original order |
|
1421 case KErrWlanProtectedSetupOOBInterfaceReadError: |
|
1422 case KErrWlanProtectedSetupDecryptionCRCFailure: |
|
1423 // the same handling here for this error code too |
|
1424 { |
|
1425 textResId = R_QTN_ERR_WLAN_SC_CONFIG_FAILED_TRY_AGAIN; |
|
1426 break; |
|
1427 } |
|
1428 case KErrWlanProtectedSetup5_0ChannelNotSupported: |
|
1429 case KErrWlanProtectedSetup2_4ChannelNotSupported: |
|
1430 // the same handling here for this error code too |
|
1431 { |
|
1432 textResId = R_QTN_ERR_WLAN_SC_CONFIG_FAILED; |
|
1433 break; |
|
1434 } |
|
1435 case KErrWlanSignalTooWeak: |
|
1436 { |
|
1437 textResId = R_QTN_ERR_WLAN_SIGNAL_TOO_WEAK; |
|
1438 break; |
|
1439 } |
|
1440 case KErrWlanProtectedSetupNetworkAuthFailure: |
|
1441 { |
|
1442 status = KErrNone; |
|
1443 textResId = R_QTN_ERR_WLAN_SC_CONFIG_FAILED_TRY_AGAIN; |
|
1444 if ( iUsePin ) |
|
1445 { |
|
1446 // ...pin code dialog if pin code was used |
|
1447 nextState = EWiFiProtUsePinCode; |
|
1448 } |
|
1449 else |
|
1450 { |
|
1451 // ... or initiate WPS dialog if push button was used |
|
1452 nextState = EWiFiProtInitiateEasySetup; |
|
1453 } |
|
1454 break; |
|
1455 } |
|
1456 case KErrWlanProtectedSetupNetworkAssociationFailure: |
|
1457 { |
|
1458 textResId = R_QTN_ERR_WLAN_NETWORK_NOT_FOUND; |
|
1459 break; |
|
1460 } |
|
1461 case KErrWlanProtectedSetupNoDHCPResponse: |
|
1462 case KErrWlanProtectedSetupFailedDHCPConfig: |
|
1463 // the same handling here for this error code too |
|
1464 case KErrWlanProtectedSetupIPAddressConflict: |
|
1465 // the same handling here for this error code too |
|
1466 case KErrWlanProtectedSetupCouldNotConnectToRegistrar: |
|
1467 // the same handling here for this error code too |
|
1468 { |
|
1469 textResId = R_QTN_ERR_WLAN_SC_CONFIG_FAILED; |
|
1470 break; |
|
1471 } |
|
1472 case KErrWlanProtectedSetupMultiplePBCSessionsDetected: |
|
1473 { |
|
1474 nextState = EWiFiProtInitiateEasySetup; |
|
1475 status = KErrNone; |
|
1476 textResId = |
|
1477 R_QTN_ERR_WLAN_SC_CONFIG_FAILED_MULTIPLE_PB_SESSIONS; |
|
1478 break; |
|
1479 } |
|
1480 case KErrWlanProtectedSetupRogueActivitySuspected: |
|
1481 { |
|
1482 nextState = EWiFiProtUsePinCode; |
|
1483 iUsePin = ETrue; |
|
1484 status = KErrNone; |
|
1485 textResId = |
|
1486 R_QTN_ERR_WLAN_SC_CONFIG_FAILED_ROGUE_ACTIVITY; |
|
1487 break; |
|
1488 } |
|
1489 case KErrWlanProtectedSetupDeviceBusy: |
|
1490 case KErrWlanProtectedSetupSetupLocked: |
|
1491 // the same handling here for this error code too |
|
1492 case KErrWlanProtectedSetupMessageTimeout: |
|
1493 // the same handling here for this error code too |
|
1494 { |
|
1495 textResId = R_QTN_ERR_WLAN_SC_CONFIG_FAILED_TRY_AGAIN; |
|
1496 break; |
|
1497 } |
|
1498 case KErrWlanProtectedSetupRegistrationSessionTimeout: |
|
1499 { |
|
1500 textResId = R_QTN_ERR_WLAN_SC_CONFIG_FAILED_TRY_AGAIN; |
|
1501 status = KErrNone; |
|
1502 // Registration session timeout, return to ... |
|
1503 if ( iUsePin ) |
|
1504 { |
|
1505 // ...pin code dialog if pin code was used |
|
1506 nextState = EWiFiProtUsePinCode; |
|
1507 } |
|
1508 else |
|
1509 { |
|
1510 // ... or initiate WPS dialog if push button was used |
|
1511 nextState = EWiFiProtInitiateEasySetup; |
|
1512 } |
|
1513 break; |
|
1514 } |
|
1515 case KErrWlanProtectedSetupDevicePasswordAuthFailure: |
|
1516 { |
|
1517 status = KErrNone; |
|
1518 textResId = R_QTN_ERR_WLAN_SC_CONFIG_FAILED_TRY_AGAIN; |
|
1519 if ( iUsePin ) |
|
1520 { |
|
1521 // ...pin code dialog if pin code was used |
|
1522 nextState = EWiFiProtUsePinCode; |
|
1523 } |
|
1524 else |
|
1525 { |
|
1526 // ... or initiate WPS dialog if push button was used |
|
1527 nextState = EWiFiProtInitiateEasySetup; |
|
1528 } |
|
1529 break; |
|
1530 } |
|
1531 case KErrWlanProtectedSetupPINMethodNotSupported: |
|
1532 { |
|
1533 textResId = |
|
1534 R_QTN_ERR_WLAN_SC_CONFIG_FAILED_PIN_NOT_SUPPORTED; |
|
1535 break; |
|
1536 } |
|
1537 case KErrWlanProtectedSetupPBMethodNotSupported: |
|
1538 { |
|
1539 textResId = |
|
1540 R_QTN_ERR_WLAN_SC_CONFIG_FAILED_PB_NOT_SUPPORTED; |
|
1541 break; |
|
1542 } |
|
1543 case KErrWlanConnAlreadyActive: |
|
1544 { |
|
1545 textResId = R_QTN_WLAN_INFO_CONNECTION_ALREADY_ACTIVE; |
|
1546 break; |
|
1547 } |
|
1548 default: |
|
1549 { |
|
1550 ret = EFalse; |
|
1551 } |
|
1552 } |
|
1553 if (ret) |
|
1554 { |
|
1555 HBufC* text = StringLoader::LoadLC( textResId ); |
|
1556 CLOG_WRITEF( *text ); |
|
1557 CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog( |
|
1558 CAknNoteDialog::EErrorTone, |
|
1559 CAknNoteDialog::ELongTimeout ); |
|
1560 dlg->SetTextL( *text ); |
|
1561 CleanupStack::PopAndDestroy( text ); |
|
1562 iStatus = KRequestPending; //should be set by service provider |
|
1563 SetActive( ); |
|
1564 dlg->ExecuteLD( R_WIFIPROT_ERROR_NOTE ); |
|
1565 SetNextStateAndComplete( nextState , status ); |
|
1566 } |
|
1567 |
|
1568 CLOG_LEAVEFN( "CWiFiProtActiveRunner::HandleErrorL" ); |
|
1569 |
|
1570 return ret; |
|
1571 } |
|
1572 } |
|
1573 |
|
1574 // -------------------------------------------------------------------------- |
|
1575 // CWiFiProtActiveRunner::ShowOfflineQuery |
|
1576 // -------------------------------------------------------------------------- |
|
1577 // |
|
1578 void CWiFiProtActiveRunner::ShowOfflineQuery() |
|
1579 { |
|
1580 iNextWiFiProtState = EWiFiProtInitiateEasySetup; |
|
1581 |
|
1582 iNotifier.StartNotifierAndGetResponse(iStatus,KUidCOfflineWlanNoteDlg, |
|
1583 KNullDesC8(), |
|
1584 iOfflineReply ); |
|
1585 SetActive(); |
|
1586 } |
|
1587 |
|
1588 // -------------------------------------------------------------------------- |
|
1589 // CWiFiProtActiveRunner::HandleNoErrorL |
|
1590 // -------------------------------------------------------------------------- |
|
1591 // |
|
1592 void CWiFiProtActiveRunner::HandleNoErrorL() |
|
1593 { |
|
1594 CLOG_ENTERFN( "CWiFiProtActiveRunner::HandleNoErrorL" ); |
|
1595 |
|
1596 switch (iNextWiFiProtState) |
|
1597 { |
|
1598 case EWifiProtOfflineQuery : |
|
1599 { |
|
1600 ShowOfflineQuery(); |
|
1601 break; |
|
1602 } |
|
1603 case EWiFiProtInitiateEasySetup : |
|
1604 { |
|
1605 ShowInitiateEasySetupDialogL(); |
|
1606 break; |
|
1607 } |
|
1608 case EWiFiProtUsePinCode : |
|
1609 { |
|
1610 if ( iUsePin ) |
|
1611 { |
|
1612 // dismiss the link dialog now |
|
1613 if ( iDestroyInitDialogLater ) |
|
1614 { |
|
1615 iInitDialog->TryExitL( EAknSoftkeyView ); |
|
1616 iDestroyInitDialogLater = EFalse; |
|
1617 } |
|
1618 ShowEnterPinOnStationDialogL(); |
|
1619 } |
|
1620 else |
|
1621 { |
|
1622 iStatus = KRequestPending; |
|
1623 SetActive( ); |
|
1624 SetNextStateAndComplete( EWiFiProtStartingWaitDlg ); |
|
1625 } |
|
1626 break; |
|
1627 } |
|
1628 case EWiFiProtStartingWaitDlg : |
|
1629 { |
|
1630 ShowWaitingDialogAndProceedL( ); |
|
1631 break; |
|
1632 } |
|
1633 case EWiFiProtConfiguring : |
|
1634 { |
|
1635 ConfigureL(); |
|
1636 break; |
|
1637 } |
|
1638 case EWiFiProtCreateAllIaps : |
|
1639 { |
|
1640 CreateAllIapsL(); |
|
1641 break; |
|
1642 } |
|
1643 |
|
1644 // when we are here, wlan scan is finished |
|
1645 case EWiFiProtWlanScan : |
|
1646 { |
|
1647 iORequest = EWiFiProtReqNone; |
|
1648 iStatus = KRequestPending; |
|
1649 SetActive( ); |
|
1650 SetNextStateAndComplete( EWiFiProtDestroyWaitNote ); |
|
1651 break; |
|
1652 } |
|
1653 case EWiFiProtSelectConnection : |
|
1654 { |
|
1655 SelectConnectionL(); |
|
1656 break; |
|
1657 } |
|
1658 |
|
1659 case EWiFiProtSettingsConfNote : |
|
1660 { |
|
1661 ShowFinalNoteL( ); |
|
1662 break; |
|
1663 } |
|
1664 case EWiFiProtFinished : |
|
1665 { |
|
1666 iReturn = EWiFiOK; |
|
1667 |
|
1668 if ( iIsConnectionNeeded ) |
|
1669 { |
|
1670 *iNetworkSettings = (*iIapParametersArray)[ |
|
1671 iAvailableNetworks[iSelectedNetworkIndex] ]; |
|
1672 } |
|
1673 else |
|
1674 { |
|
1675 // Copy the results into the output array |
|
1676 for (TInt i = 0; i< iCmArray.Count();i++ ) |
|
1677 { |
|
1678 CLOG_WRITEF( _L( |
|
1679 "Copy the results into the output array, i == %d"), i ); |
|
1680 if ( iUids == NULL) |
|
1681 { |
|
1682 User::Panic( KWiFiPanic, KErrNotSupported ); |
|
1683 } |
|
1684 iUids->Append( iCmArray[i]->GetIntAttributeL( ECmId ) ); |
|
1685 } |
|
1686 } |
|
1687 |
|
1688 if ( iSyncMode ) |
|
1689 { |
|
1690 if (iWait.IsStarted() ) |
|
1691 { |
|
1692 iWait.AsyncStop(); |
|
1693 } |
|
1694 } |
|
1695 else |
|
1696 { |
|
1697 iParent->CompleteProcessL( iReturn ); |
|
1698 } |
|
1699 break; |
|
1700 } |
|
1701 default: |
|
1702 { |
|
1703 //should not ever get here |
|
1704 CLOG_WRITE( "Unhandled WiFiProtState!!!" ); |
|
1705 User::Leave( KErrGeneral ); |
|
1706 break; |
|
1707 } |
|
1708 } |
|
1709 |
|
1710 CLOG_LEAVEFN( "CWiFiProtActiveRunner::HandleNoErrorL" ); |
|
1711 } |
|
1712 |
|
1713 // -------------------------------------------------------------------------- |
|
1714 // CWiFiProtActiveRunner::PinQueryExitL |
|
1715 // -------------------------------------------------------------------------- |
|
1716 // |
|
1717 void CWiFiProtActiveRunner::PinQueryExitL( TInt aResponse ) |
|
1718 { |
|
1719 iPinQueryActive = EFalse; |
|
1720 iPinDlg = NULL; |
|
1721 if ( aResponse == KErrNone ) |
|
1722 { |
|
1723 |
|
1724 if ( iWaitNoteNeeded ) |
|
1725 { |
|
1726 ShowWaitingDialogL(); |
|
1727 } |
|
1728 else |
|
1729 { |
|
1730 EvaluateResult(); //we were just waiting for PIN query to exit |
|
1731 } |
|
1732 } |
|
1733 else |
|
1734 { |
|
1735 iUserCancelled = ETrue; |
|
1736 CancelOngoingRequest(); |
|
1737 } |
|
1738 } |
|
1739 |
|
1740 // -------------------------------------------------------------------------- |
|
1741 // void CWiFiProtActiveRunner::DoUsePinCodeLinkSelectedL() |
|
1742 // -------------------------------------------------------------------------- |
|
1743 // |
|
1744 void CWiFiProtActiveRunner::DoUsePinCodeLinkSelectedL() |
|
1745 { |
|
1746 CLOG_ENTERFN( "CWiFiProtActiveRunner::DoUsePinCodeLinkSelectedL" ); |
|
1747 if ( !iDestroyInitDialogLater ) |
|
1748 { |
|
1749 iUsePin = ETrue; |
|
1750 TRequestStatus* pS = &iStatus; |
|
1751 User::RequestComplete( pS, KErrNone ); |
|
1752 iDestroyInitDialogLater = ETrue; |
|
1753 } |
|
1754 CLOG_LEAVEFN( "CWiFiProtActiveRunner::DoUsePinCodeLinkSelectedL" ); |
|
1755 } |
|
1756 |
|
1757 // -------------------------------------------------------------------------- |
|
1758 // void CWiFiProtActiveRunner::StartWlanScan() |
|
1759 // -------------------------------------------------------------------------- |
|
1760 // |
|
1761 void CWiFiProtActiveRunner::StartWlanScan() |
|
1762 { |
|
1763 CLOG_ENTERFN( "CWiFiProtActiveRunner::StartWlanScan" ); |
|
1764 // this flag is needed to store the cancel because we cannot |
|
1765 // cancel wlan scan itself |
|
1766 #ifdef __WINS__ |
|
1767 SetNextStateAndComplete( EWiFiProtWlanScan ); |
|
1768 #else |
|
1769 iORequest = EWiFiProtReqWlanScan; |
|
1770 iNextWiFiProtState = EWiFiProtWlanScan; |
|
1771 iWlanMgmtEngine->GetScanResults( iStatus, *iScanInfo ); |
|
1772 #endif |
|
1773 CLOG_LEAVEFN( "CWiFiProtActiveRunner::StartWlanScan" ); |
|
1774 } |
|
1775 |
|
1776 // -------------------------------------------------------------------------- |
|
1777 // void CWiFiProtActiveRunner::CheckNetworkAvailabilityL() |
|
1778 // -------------------------------------------------------------------------- |
|
1779 // |
|
1780 void CWiFiProtActiveRunner::CheckNetworkAvailabilityL() |
|
1781 { |
|
1782 CLOG_ENTERFN( "CWiFiProtActiveRunner::CheckNetworkAvailabilityL" ); |
|
1783 |
|
1784 iAvailableNetworks.Reset(); |
|
1785 TBool found = EFalse; |
|
1786 for (TInt i = 0; i < iIapParametersArray->Count(); i++ ) |
|
1787 { |
|
1788 found = EFalse; |
|
1789 #ifdef __WINS__ |
|
1790 for (TInt j = 0; j<KNumberOfEmulatedAvailableNetworks; j++) |
|
1791 #else |
|
1792 for ( iScanInfo->First(); (!iScanInfo->IsDone()) |
|
1793 && (!found); iScanInfo->Next() ) |
|
1794 #endif |
|
1795 { |
|
1796 TUint8 ieLen( 0 ); |
|
1797 const TUint8* ieData; |
|
1798 TBuf8<KWlanMaxSsidLength> ssid8; |
|
1799 #ifdef __WINS__ |
|
1800 TBuf8<KWlanMaxSsidLength> ssidData; |
|
1801 ieData = ssidData.PtrZ(); |
|
1802 switch (j) |
|
1803 { |
|
1804 case KIndexOfFirstEmulatedAvailableNetwork: |
|
1805 { |
|
1806 ssidData = _L8("Available Network"); |
|
1807 break; |
|
1808 } |
|
1809 case KIndexOfSecondEmulatedAvailableNetwork: |
|
1810 { |
|
1811 ssidData = _L8("Available Network 2"); |
|
1812 break; |
|
1813 } |
|
1814 default: |
|
1815 { |
|
1816 User::Panic( KWiFiPanic , KErrNotFound ); |
|
1817 break; |
|
1818 } |
|
1819 } |
|
1820 ieLen = ssidData.Length(); |
|
1821 TInt ret = KErrNone; |
|
1822 #else |
|
1823 TInt ret = iScanInfo->InformationElement( E802Dot11SsidIE, ieLen, |
|
1824 &ieData ); |
|
1825 #endif |
|
1826 User::LeaveIfError( ret ); |
|
1827 if ( ieLen ) |
|
1828 { |
|
1829 CLOG_WRITE( "Starting copying ssid" ); |
|
1830 // get the ssid |
|
1831 ssid8.Copy( ieData, ieLen ); |
|
1832 CLOG_WRITE( "SSID copied" ); |
|
1833 if ( !(*iIapParametersArray)[i].iSsid.Compare( ssid8 ) ) |
|
1834 { |
|
1835 iAvailableNetworks.Append(i); |
|
1836 found = ETrue; |
|
1837 } |
|
1838 } |
|
1839 } |
|
1840 } |
|
1841 |
|
1842 if (iAvailableNetworks.Count() == 1) |
|
1843 { |
|
1844 // only one network available, go to confirmation note |
|
1845 iSelectedNetworkIndex = 0; |
|
1846 SetNextStateAndComplete( EWiFiProtSettingsConfNote ); |
|
1847 } |
|
1848 else if (iAvailableNetworks.Count() > 1) |
|
1849 { |
|
1850 // more are available, select connection dialog |
|
1851 SetNextStateAndComplete( EWiFiProtSelectConnection ); |
|
1852 } |
|
1853 else |
|
1854 { |
|
1855 // no wlan networks found note |
|
1856 ShowNoWlanNetworksNoteL(); |
|
1857 } |
|
1858 |
|
1859 CLOG_LEAVEFN( "CWiFiProtActiveRunner::CheckNetworkAvailabilityL" ); |
|
1860 } |
|
1861 |
|
1862 // -------------------------------------------------------------------------- |
|
1863 // CWiFiProtActiveRunner::SelectConnection |
|
1864 // -------------------------------------------------------------------------- |
|
1865 // |
|
1866 void CWiFiProtActiveRunner::SelectConnectionL( ) |
|
1867 { |
|
1868 CDesCArrayFlat* items = |
|
1869 new ( ELeave ) CDesCArrayFlat( KArrayGranularity ); |
|
1870 CleanupStack::PushL( items ); |
|
1871 |
|
1872 _LIT( KListBoxItemFormat, "%d\t%s\t" ); |
|
1873 const TInt KListBoxItemFormatLength = 4; |
|
1874 TBuf<KWlanMaxSsidLength+KListBoxItemFormatLength+1> buf; |
|
1875 for (TInt i = 0; i < iAvailableNetworks.Count(); i++ ) |
|
1876 { |
|
1877 // We have to convert the 8-bit SSID to 16-bit |
|
1878 HBufC* ssid16 = HBufC::NewLC( (*iIapParametersArray) |
|
1879 [iAvailableNetworks[i]].iSsid.Length()+1 ); |
|
1880 TPtr ssid16Ptr( ssid16->Des() ); |
|
1881 CnvUtfConverter::ConvertToUnicodeFromUtf8( ssid16Ptr, |
|
1882 (*iIapParametersArray)[iAvailableNetworks[i]].iSsid ); |
|
1883 ssid16Ptr.ZeroTerminate(); |
|
1884 buf.Format( KListBoxItemFormat, |
|
1885 0/*we use only one icon*/, ssid16->Ptr() ); |
|
1886 CleanupStack::PopAndDestroy( ssid16 ); |
|
1887 items->AppendL(buf); |
|
1888 } |
|
1889 CAknIconArray* icons = new( ELeave ) CAknIconArray( KIconsGranularity ); |
|
1890 CleanupStack::PushL( icons ); |
|
1891 //creating icon |
|
1892 TAknsItemID id; |
|
1893 MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance(); |
|
1894 |
|
1895 TParse mbmFile; |
|
1896 User::LeaveIfError( mbmFile.Set( KWiFiFileIcons, |
|
1897 &KDC_BITMAP_DIR, |
|
1898 NULL ) ); |
|
1899 |
|
1900 CGulIcon* icon = AknsUtils::CreateGulIconL( |
|
1901 skinInstance, |
|
1902 id, |
|
1903 mbmFile.FullName(), |
|
1904 EMbmWifiprotQgn_prop_wlan_bearer, |
|
1905 EMbmWifiprotQgn_prop_wlan_bearer_mask ); |
|
1906 /// |
|
1907 |
|
1908 CleanupStack::PushL(icon); |
|
1909 icons->AppendL( icon ); |
|
1910 CleanupStack::Pop(); //icon array takes ownership |
|
1911 // we are finished, don't create any iaps in connection mode! |
|
1912 iNextWiFiProtState = EWiFiProtFinished; |
|
1913 CWiFiProtSelectNetworkDlg* dlg = |
|
1914 new ( ELeave ) CWiFiProtSelectNetworkDlg(iStatus , |
|
1915 iSelectedNetworkIndex, |
|
1916 items, icons ); |
|
1917 CleanupStack::Pop( icons ); // list takes ownership |
|
1918 CleanupStack::Pop( items );// list takes ownership |
|
1919 dlg->PrepareAndRunLD( ); |
|
1920 SetActive(); |
|
1921 } |
|
1922 |
|
1923 // -------------------------------------------------------------------------- |
|
1924 // void CWiFiProtActiveRunner::ShowNoWlanNetworksNoteL() |
|
1925 // -------------------------------------------------------------------------- |
|
1926 // |
|
1927 void CWiFiProtActiveRunner::ShowNoWlanNetworksNoteL() |
|
1928 { |
|
1929 CLOG_ENTERFN( "CWiFiProtActiveRunner::ShowNoWlanNetworksNoteL" ); |
|
1930 HBufC* stringLabel = StringLoader::LoadLC( |
|
1931 R_QTN_WLAN_INFO_NO_NETWORKS_FOUND ); |
|
1932 |
|
1933 RAknUiServer* globalNote = CAknSgcClient::AknSrv(); |
|
1934 if ( globalNote->Handle() ) |
|
1935 { |
|
1936 globalNote->ShowGlobalNoteL( *stringLabel, |
|
1937 EAknGlobalInformationNote ); |
|
1938 } |
|
1939 CleanupStack::PopAndDestroy( stringLabel ); |
|
1940 SetNextStateAndComplete( EWiFiProtFinished ); |
|
1941 |
|
1942 CLOG_LEAVEFN( "CWiFiProtActiveRunner::ShowNoWlanNetworksNoteL" ); |
|
1943 |
|
1944 } |
|
1945 |
|
1946 // -------------------------------------------------------------------------- |
|
1947 // CWiFiProtActiveRunner::CancelOngoingRequest |
|
1948 // -------------------------------------------------------------------------- |
|
1949 // |
|
1950 void CWiFiProtActiveRunner::CancelOngoingRequest() |
|
1951 { |
|
1952 |
|
1953 CLOG_ENTERFN( "CWiFiProtActiveRunner::CancelOngoingRequest" ); |
|
1954 |
|
1955 switch ( iORequest ) |
|
1956 { |
|
1957 case EWiFiProtReqConfirmDialog: |
|
1958 { |
|
1959 // Remove the showing dialog and cancel the request |
|
1960 delete iConfirmationDialog; |
|
1961 iConfirmationDialog = NULL; |
|
1962 TRequestStatus* pS = &iStatus; |
|
1963 User::RequestComplete( pS, KErrCancel ); |
|
1964 break; |
|
1965 } |
|
1966 case EWiFiProtReqInitDialog: |
|
1967 { |
|
1968 // Remove the showing dialog and cancel the request |
|
1969 delete iInitDialog; |
|
1970 iInitDialog = NULL; |
|
1971 TRequestStatus* pS = &iStatus; |
|
1972 User::RequestComplete( pS, KErrCancel ); |
|
1973 break; |
|
1974 } |
|
1975 case EWiFiProtReqWPS : |
|
1976 { |
|
1977 if ( iPinQueryActive ) |
|
1978 { |
|
1979 delete iPinDlg; |
|
1980 iPinDlg = NULL; |
|
1981 } |
|
1982 if ( iWlanMgmtEngine ) |
|
1983 { |
|
1984 CLOG_WRITE( "Calling WPS cancel!" ); |
|
1985 iWlanMgmtEngine->CancelProtectedSetup(); |
|
1986 CLOG_WRITE( "WPS cancel called!" ); |
|
1987 } |
|
1988 break; |
|
1989 } |
|
1990 case EWiFiProtReqWlanScan : |
|
1991 { |
|
1992 iWlanMgmtEngine->CancelGetScanResults(); |
|
1993 break; |
|
1994 } |
|
1995 case EWiFiProtReqNone : |
|
1996 { |
|
1997 // it is possible, especially in emulator, that the pin dialog |
|
1998 // is still visible at this point |
|
1999 if ( iPinQueryActive ) |
|
2000 { |
|
2001 delete iPinDlg; |
|
2002 iPinDlg = NULL; |
|
2003 TRequestStatus* pS = &iStatus; |
|
2004 User::RequestComplete( pS, KErrCancel ); |
|
2005 } |
|
2006 // set CancelCalled flag to make RunL start shutdown next time |
|
2007 iUserCancelled = ETrue; |
|
2008 break; |
|
2009 } |
|
2010 |
|
2011 default: |
|
2012 { |
|
2013 // should not ever get here |
|
2014 } |
|
2015 } |
|
2016 |
|
2017 CLOG_LEAVEFN( "CWiFiProtActiveRunner::CancelOngoingRequest" ); |
|
2018 |
|
2019 } |
|
2020 |
|
2021 // -------------------------------------------------------------------------- |
|
2022 // CWiFiProtActiveRunner::SetWepKeyL |
|
2023 // -------------------------------------------------------------------------- |
|
2024 // |
|
2025 void CWiFiProtActiveRunner::SetWepKeyL( CWEPSecuritySettings& |
|
2026 aWepSecSettings, |
|
2027 TWlanWepKey& aWepKey, |
|
2028 TInt aKeyNumber ) |
|
2029 { |
|
2030 if ( aWepKey != KNullDesC8) |
|
2031 { |
|
2032 TBool wepKeyInAsciiFormat = IsWepFormatHexL( aWepKey.Length() ); |
|
2033 TBuf<KWlanWepKeyMaxLength> wepBuf16; |
|
2034 wepBuf16.Copy( aWepKey ); |
|
2035 User::LeaveIfError(aWepSecSettings.SetKeyDataL( aKeyNumber, wepBuf16, |
|
2036 wepKeyInAsciiFormat ) ); |
|
2037 CLOG_WRITEF( _L("Wep key: %d"), aKeyNumber ); |
|
2038 CLOG_WRITEF( wepBuf16 ); |
|
2039 } |
|
2040 } |
|
2041 |
|
2042 // -------------------------------------------------------------------------- |
|
2043 // TInt CWiFiProtActiveRunner::UsePinCodeLinkSelectedL() |
|
2044 // -------------------------------------------------------------------------- |
|
2045 // |
|
2046 TInt CWiFiProtActiveRunner::UsePinCodeLinkSelectedL( TAny* aObject ) |
|
2047 { |
|
2048 CLOG_ENTERFN( "CWiFiProtActiveRunner::UsePinCodeLinkSelectedL" ); |
|
2049 CWiFiProtActiveRunner* myself = |
|
2050 static_cast<CWiFiProtActiveRunner*>( aObject ); |
|
2051 myself->DoUsePinCodeLinkSelectedL(); |
|
2052 CLOG_LEAVEFN( "CWiFiProtActiveRunner::UsePinCodeLinkSelectedL" ); |
|
2053 |
|
2054 return 1; |
|
2055 } |
|
2056 // End of File |