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