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