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