|
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 #ifndef C_WIFIPROTACTIVERUNNER_H |
|
20 #define C_WIFIPROTACTIVERUNNER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <cmmanagerext.h> |
|
25 #include <AknQueryDialog.h> |
|
26 #include <AknProgressDialog.h> |
|
27 |
|
28 #include "wifiprotdlgsplugin.h" |
|
29 #include "wifiparams.h" |
|
30 #include "wifiprotactiverunnercallback.h" |
|
31 |
|
32 |
|
33 //FORWARD DECLARATIONS |
|
34 class CWlanMgmtClient; |
|
35 class CMDBSession; |
|
36 class CWiFiProtConfirmationNoteDlg; |
|
37 class CWiFiProtInitiateEasySetupDlg; |
|
38 class CWlanScanInfo; |
|
39 class CWiFiProtEnterPinDlg; |
|
40 class CWEPSecuritySettings; |
|
41 class RCmConnectionMethodExt; |
|
42 |
|
43 //CONSTS |
|
44 const TInt KMaxPINLength = 8; //is it really 8? |
|
45 // ID of OfflineWlanNote dialog |
|
46 const TUid KUidCOfflineWlanNoteDlg = { 0x101FD671 }; |
|
47 |
|
48 /** |
|
49 * CWiFiProtActiveRunner |
|
50 * State machine like object that manages Wi-Fi Protected setup ui process |
|
51 * @since S60 v3.2 |
|
52 */ |
|
53 class CWiFiProtActiveRunner : public CActive, public MProgressDialogCallback, |
|
54 MActiveRunnerCallback |
|
55 { |
|
56 private: |
|
57 // States to control Wi-Fi Protected Setup sequence |
|
58 enum TWiFiProtStates |
|
59 { |
|
60 // Display 'Configure Automatically?' Dialog |
|
61 EWiFiProtAskConfigureAutomatically = 1, |
|
62 // Display 'Initiate Easy Setup?' Dialog |
|
63 EWiFiProtInitiateEasySetup, |
|
64 // If phone is in offline mode, continue with |
|
65 // "Create WLAN connection in offline mode?" confirmation |
|
66 EWifiProtOfflineQuery, |
|
67 // Display 'Enter PIN code' Dialog |
|
68 EWiFiProtUsePinCode, |
|
69 // Starting wait dialog |
|
70 EWiFiProtStartingWaitDlg, |
|
71 // Configuring (Creating temp iap and making a call to wlan |
|
72 // mgmt server ) |
|
73 EWiFiProtConfiguring, |
|
74 // Wlan Mgmt server returned |
|
75 EWiFiProtWlanMgmtEngineReturned, |
|
76 // Creating iap from parameters from wlan mgmt server |
|
77 EWiFiProtCreateAllIaps, |
|
78 // Configuration finished |
|
79 EWiFiProtConfFinished, |
|
80 // Destroying wait note |
|
81 EWiFiProtDestroyWaitNote, |
|
82 // Waiting for PIN query to exit |
|
83 EWiFiProtWaitForPINQuery, |
|
84 // Wlan Scan |
|
85 EWiFiProtWlanScan, |
|
86 // Displaying Select Connection Dialog |
|
87 EWiFiProtSelectConnection, |
|
88 // Displaying final note about configured settings |
|
89 EWiFiProtSettingsConfNote, |
|
90 // Finished, exiting |
|
91 EWiFiProtFinished, |
|
92 // Cancelled, exiting |
|
93 EWiFiProtCancelled |
|
94 }; |
|
95 |
|
96 // Asynchronous service to cancel |
|
97 enum TWiFiProtOutstandingRequest |
|
98 { |
|
99 EWiFiProtReqNone = 0, |
|
100 EWiFiProtReqConfirmDialog, |
|
101 EWiFiProtReqInitDialog, |
|
102 EWiFiProtReqWPS, |
|
103 EWiFiProtReqWlanScan |
|
104 }; |
|
105 |
|
106 public: |
|
107 /** |
|
108 * Two phased constructor |
|
109 * @param aPriority Active object priority |
|
110 */ |
|
111 static CWiFiProtActiveRunner* NewL( CWiFiProtDlgsPlugin* aParent, |
|
112 TInt aPriority = CActive::EPriorityStandard ); |
|
113 |
|
114 /** |
|
115 * Destructor |
|
116 */ |
|
117 ~CWiFiProtActiveRunner(); |
|
118 |
|
119 |
|
120 /** |
|
121 * Starts Wi-Fi Protected Setup |
|
122 * @param aSSid contains SSid of the network we want to configure |
|
123 * @param aCmManagerToUse - RCmManagerExt to use. Must pass this |
|
124 * to avoid CmManager database |
|
125 * locking problems |
|
126 */ |
|
127 void StartProtectedSetupAsyncL ( const TWlanSsid& aSSid, |
|
128 RArray<TUint32>& aUids, |
|
129 RCmManagerExt& aCmManagerToUse ); |
|
130 |
|
131 /** |
|
132 * Starts Wi-Fi Protected Setup in Connection creation mode |
|
133 * @param aSSid contains SSid of the network we want to configure |
|
134 * @param aNetworkSettings the configured network's settings to be |
|
135 * returned |
|
136 * @param aCmManagerToUse - RCmManagerExt to use. Must pass this |
|
137 * to avoid CmManager database |
|
138 * locking problems |
|
139 * @return possible return values are ok, cancel process and not use |
|
140 * protected setup (No Automatic Setup). |
|
141 */ |
|
142 void StartProtectedSetupConnL ( |
|
143 const TWlanSsid& aSSid, |
|
144 TWlanProtectedSetupCredentialAttribute& |
|
145 aNetworkSettings, |
|
146 RCmManagerExt& aCmManagerToUse ); |
|
147 |
|
148 /** |
|
149 * Starts Wi-Fi Protected Setup using CActiveSchedulerWait block |
|
150 * @param aSSid contains SSid of the network we want to configure |
|
151 * @param aCmManagerToUse - RCmManagerExt to use. Must pass this |
|
152 * to avoid CmManager database |
|
153 * locking problems |
|
154 * @return possible return values are ok, cancel process and not use |
|
155 * protected setup (No Automatic Setup). |
|
156 */ |
|
157 WiFiProt::TWiFiReturn StartProtectedSetupL ( const TWlanSsid& aSSid, |
|
158 RArray<TUint32>& aUids, |
|
159 RCmManagerExt& aCmManagerToUse ); |
|
160 |
|
161 /** |
|
162 * When the process is cancelled by the client rather than |
|
163 * cancelled by the user, some things are taken care of |
|
164 * a bit differently. |
|
165 */ |
|
166 void CancelByClient(); |
|
167 |
|
168 private: |
|
169 |
|
170 |
|
171 /** |
|
172 * Shows the first dialog in the sequence |
|
173 */ |
|
174 void ShowInitialDialogL (); |
|
175 /** |
|
176 * Shows connect in offline -notification. |
|
177 */ |
|
178 void ShowOfflineQuery (); |
|
179 /** |
|
180 * Shows the Initiate Easy Setup dialog |
|
181 */ |
|
182 void ShowInitiateEasySetupDialogL (); |
|
183 |
|
184 /** |
|
185 * Shows the 'Enter PIN on Wireless Station' dialog |
|
186 */ |
|
187 void ShowEnterPinOnStationDialogL(); |
|
188 |
|
189 /** |
|
190 * Shows waiting dialog |
|
191 */ |
|
192 void ShowWaitingDialogL(); |
|
193 |
|
194 /** |
|
195 * Shows waiting dialog and proceeds with the process |
|
196 */ |
|
197 void ShowWaitingDialogAndProceedL(); |
|
198 |
|
199 /** |
|
200 * Shows 'settings configured' dialog |
|
201 * @param aWiFiProtState state to decide which note to display |
|
202 */ |
|
203 void ShowFinalNoteL(); |
|
204 |
|
205 /** |
|
206 * wait note callback |
|
207 */ |
|
208 void DialogDismissedL( TInt aButtonId ); |
|
209 |
|
210 /** |
|
211 * Creates Temporary iap (cm) which contains parameters to be passed |
|
212 * to wlan engine |
|
213 * @param aTempServId Temporary iap service id |
|
214 * @return TUint32 iap id (cm uid) |
|
215 */ |
|
216 TUint32 CreateTempIapL( TUint32& aTempServId ); |
|
217 |
|
218 /** |
|
219 * Calls the active object that calls wlan engine's RunProtectedSetup |
|
220 * @param TUint32 aIap iap id (cm uid) |
|
221 */ |
|
222 void RunProtectedSetup( const TInt32 aIap ); |
|
223 |
|
224 /** |
|
225 * Constructor |
|
226 * @param aParent Parent object |
|
227 * @param aPriority Active object priority |
|
228 */ |
|
229 CWiFiProtActiveRunner( CWiFiProtDlgsPlugin* aParent, TInt aPriority ); |
|
230 |
|
231 /** |
|
232 * Second phase constructor |
|
233 */ |
|
234 void ConstructL(); |
|
235 |
|
236 /** From CActive */ |
|
237 /** |
|
238 @see CActive::DoCancel |
|
239 */ |
|
240 virtual void DoCancel(); |
|
241 |
|
242 /** |
|
243 @see CActive::RunL |
|
244 */ |
|
245 virtual void RunL(); |
|
246 |
|
247 |
|
248 /** |
|
249 * Sets iNextWiFiProtState and completes the pending request |
|
250 * used to step forward in the 'state machine' |
|
251 * @param aNextState - the state to step to |
|
252 */ |
|
253 void SetNextStateAndComplete( TWiFiProtStates aNextState, |
|
254 TInt aError = KErrNone ); |
|
255 |
|
256 /** |
|
257 * Called from RunL in EWiFiProtConfiguring state |
|
258 * Starts configuring the connection methods |
|
259 */ |
|
260 void ConfigureL(); |
|
261 |
|
262 /** |
|
263 * Proceeds after DestroyWaitDialog or after PinQueryExitL and |
|
264 * checks error state and continues with Wlan availability |
|
265 * scan if needed |
|
266 */ |
|
267 void EvaluateResult(); |
|
268 |
|
269 /** |
|
270 * Called from RunL in EWiFiProtConfFinished state |
|
271 * Destroys the wait dialog as configuring is complete |
|
272 */ |
|
273 void DestroyWaitDialog(); |
|
274 |
|
275 /* |
|
276 * Computes checksum number which is the last number of |
|
277 * the 8 digit PIN code passed to wlan mgmt engine |
|
278 * algorythm copied from Wi-Fi spec |
|
279 * @param aPin Pin code |
|
280 * @return last digit, to be appended to PIN |
|
281 */ |
|
282 TInt ComputeChecksum(TInt aPin); |
|
283 |
|
284 /* |
|
285 * Creates a single iap (from the first network's parameters), |
|
286 * and then repeats the process for each iap |
|
287 * The iap parameters at 0 index (in iIapParametersArray) will be |
|
288 * used to create an iap. passed to CreateIapL. |
|
289 */ |
|
290 void CreateAllIapsL(); |
|
291 |
|
292 /** |
|
293 * Creates Connection Method using RCmManagerExt |
|
294 * The iap parameters at the given index (in iIapParametersArray) |
|
295 * will be used to create an iap. Then the parameters entry will |
|
296 * be deleted from iIapParametersArray |
|
297 * and the new iap's id will be added to iCmArray. |
|
298 * @param TInt aIndex index of the connection method (iap) to create |
|
299 * in iIapParametersArray |
|
300 * @return IapId of the cm |
|
301 */ |
|
302 TUint32 CreateIapL( const TInt aIndex ); |
|
303 |
|
304 /** |
|
305 * Sets iap settings to a given connection method object and saves it |
|
306 * @param TInt aIndex index of the connection method (iap) |
|
307 * in iIapParametersArray |
|
308 * @param aCmToSet target connection method object |
|
309 * @return IapId of the cm |
|
310 */ |
|
311 TUint32 SetIapDataL( const TInt aIndex, RCmConnectionMethodExt& aCmToSet ); |
|
312 |
|
313 // calls DeleteTempIapL, and also steps the state machine |
|
314 void CleanupTempIapL(); |
|
315 |
|
316 /** |
|
317 * Deletes temporary iap |
|
318 */ |
|
319 void DeleteTempIapL(); |
|
320 |
|
321 /** |
|
322 * Returns wep format, ETrue if it is in hex |
|
323 * @param aLength Wep key length |
|
324 */ |
|
325 TBool IsWepFormatHexL( TInt aLength ); |
|
326 |
|
327 /** |
|
328 * Saves wep security settings from the |
|
329 * given credential parameters |
|
330 * @param aCredentialAttribute credential parameters including wep |
|
331 * security settings data |
|
332 * @param aWlanServiceId Wlan service id |
|
333 * @param aDb Database session needed for saving |
|
334 * wep security settings |
|
335 */ |
|
336 void SaveWepSecuritySettingsL( |
|
337 TWlanProtectedSetupCredentialAttribute |
|
338 aCredentialAttribute, |
|
339 TUint32 aWlanServiceId, |
|
340 CommsDat::CMDBSession& aDb ); |
|
341 |
|
342 /** |
|
343 * Handles the given error code by dispaying an error note |
|
344 * @param aErrorCode error code to handle |
|
345 */ |
|
346 TBool HandleErrorL( TInt aErrorCode ); |
|
347 |
|
348 /** |
|
349 * Steps into the next state of Wi-Fi Protected Setup sequence |
|
350 * called from RunL() |
|
351 */ |
|
352 void HandleNoErrorL (); |
|
353 |
|
354 |
|
355 /** |
|
356 * From MActiveRunnerCallback |
|
357 * called when CWifiProtEnterPinDlg is finished |
|
358 * @param TInt aResponse can be KErrNone or KErrCancel |
|
359 */ |
|
360 void PinQueryExitL( TInt aResponse ); |
|
361 |
|
362 /** |
|
363 * Called by UsePinCodeLinkSelectedL when pin code mechanism |
|
364 * is selected. Sets iUsePin flag and completes Active Runner |
|
365 * (this) object |
|
366 */ |
|
367 void DoUsePinCodeLinkSelectedL(); |
|
368 |
|
369 /** |
|
370 * Starts wlan scan |
|
371 */ |
|
372 void StartWlanScan(); |
|
373 |
|
374 /** |
|
375 * Compares the fresh wlan networks list with the |
|
376 * items returned by WPS. Puts the available network indexes |
|
377 * into iAvailableNetworks |
|
378 */ |
|
379 void CheckNetworkAvailabilityL(); |
|
380 |
|
381 /* |
|
382 * Displays the Select Connection Dialog |
|
383 * When there are more connections available to use |
|
384 * (used in Create Connection Mode) |
|
385 */ |
|
386 void SelectConnectionL(); |
|
387 |
|
388 /* |
|
389 * Displays a note to show the user that |
|
390 * no wlan networks were found during wlan scan |
|
391 */ |
|
392 void ShowNoWlanNetworksNoteL(); |
|
393 |
|
394 /* |
|
395 * Calls cancel on the possibly currently ongoing request |
|
396 */ |
|
397 void CancelOngoingRequest(); |
|
398 |
|
399 /** |
|
400 * Sets wep key |
|
401 * @param aWepSecSettings Wep security settings object |
|
402 * @param aWepKey Wep key to set |
|
403 * @param aKeyNumber number of wep key to set |
|
404 */ |
|
405 void SetWepKeyL( CWEPSecuritySettings& aWepSecSettings, |
|
406 TWlanWepKey& aWepKey, TInt aKeyNumber ); |
|
407 |
|
408 public: |
|
409 /** |
|
410 * Callback to handle pin code pin code mechanism link selection |
|
411 */ |
|
412 static TInt UsePinCodeLinkSelectedL( TAny* aObject ); |
|
413 |
|
414 private: |
|
415 // reference to parent object |
|
416 CWiFiProtDlgsPlugin* iParent; |
|
417 // wait dialog |
|
418 CAknWaitDialog* iWaitDlg; ///Owned |
|
419 // RCmManagerExt object for Cm Manager operations |
|
420 RCmManagerExt* iCmManagerExt; //NOT OWNED!!! |
|
421 // ETrue if connection is needed after the Wi-Fi Protected |
|
422 // setup. |
|
423 TBool iIsConnectionNeeded; |
|
424 // Array to store returned uids of created iaps (connection methods) |
|
425 RArray<TUint32>* iUids;//NOT OWNED!!! |
|
426 // flag to indicate that wait dialog was cancelled |
|
427 TBool iWaitDlgCancelled; |
|
428 // ssid of the network to setup |
|
429 TWlanSsid iSsid; |
|
430 // iap id of the temporary iap |
|
431 TUint32 iTempIapId ; |
|
432 // service id of the temporary iap |
|
433 TUint32 iTempServId ; |
|
434 // PIN code (holds a value only if PIN method is used) |
|
435 // for Wi-Fi Protected Setup authentication |
|
436 TBuf<KMaxPINLength> iPIN; |
|
437 // Wlan mgmt engine |
|
438 CWlanMgmtClient* iWlanMgmtEngine; |
|
439 // Next state, checked in RunL to control the setup process |
|
440 TWiFiProtStates iNextWiFiProtState; |
|
441 // return value |
|
442 WiFiProt::TWiFiReturn iReturn; |
|
443 // A flag to indicate that PIN method is used |
|
444 TBool iUsePin; |
|
445 // Holds the error code from wlan mgmt engine after |
|
446 // our wlan mgmt server request is complete |
|
447 TInt iError; |
|
448 // Active Scheduler wait object to hold the process until we are |
|
449 // complete |
|
450 CActiveSchedulerWait iWait; |
|
451 // Array to hold the connection methods which are created from |
|
452 // the data returned from wlan mgmt engine |
|
453 RPointerArray<RCmConnectionMethodExt> iCmArray;//used to store cms |
|
454 // before submitting them |
|
455 // The connection metod parameters returned from wlan mgmt engine |
|
456 CArrayFixSeg<TWlanProtectedSetupCredentialAttribute>* |
|
457 iIapParametersArray; //parameters from wlan mgmt engine |
|
458 // ETrue if Pin Query Dialog is active |
|
459 TBool iPinQueryActive; |
|
460 // ETrue if a wait note is needed to be shown |
|
461 TBool iWaitNoteNeeded; |
|
462 // initiate setup dialog is stored to handle link selection callback, |
|
463 // not owned |
|
464 CWiFiProtInitiateEasySetupDlg* iInitDialog; |
|
465 // Wlan Scan Info |
|
466 CWlanScanInfo* iScanInfo; |
|
467 // List of available networks, contains indexes for iIapParametersArray |
|
468 RArray<TInt> iAvailableNetworks; |
|
469 // index of selected network in iAvailableNetworks |
|
470 TInt iSelectedNetworkIndex; |
|
471 // ongoing request to cancel if cancelled |
|
472 TWiFiProtOutstandingRequest iORequest; |
|
473 // Cancel called by user, cancel at next RunL cycle |
|
474 TBool iUserCancelled; |
|
475 // ETrue if the process is cancelled by the client. |
|
476 TBool iClientCancelled; |
|
477 // Flag to indicate that the 'use pin code' link was used |
|
478 // and we have to destroy the dialog later, because avkon crashes if |
|
479 // we do it in the callback (DoUsePinCodeLinkSelectedL) |
|
480 TBool iDestroyInitDialogLater; |
|
481 // not owned, just keeping pointer to handle cancel softkey removal |
|
482 CWiFiProtEnterPinDlg* iPinDlg; |
|
483 //pointer to network settings to be returned if WPS is used for |
|
484 // connection creation |
|
485 TWlanProtectedSetupCredentialAttribute* iNetworkSettings; |
|
486 // ETrue if the WPS process is used in synchronous mode |
|
487 TBool iSyncMode; |
|
488 // ETrue if phone is in offline mode. |
|
489 TBool iInOfflineMode; |
|
490 // Stores data for offline note. Used |
|
491 // only for writing result. Not read. |
|
492 TPckgBuf<TBool> iOfflineReply; |
|
493 // Interface to Notifier |
|
494 RNotifier iNotifier; |
|
495 // Pointer to the 1st confirmation dialog. Owned. |
|
496 CWiFiProtConfirmationNoteDlg* iConfirmationDialog; |
|
497 |
|
498 |
|
499 |
|
500 }; |
|
501 |
|
502 #endif //C_WIFIPROTACTIVERUNNER_H |
|
503 |
|
504 // End of File |