wlanutilities/wpswizard/src/cwpsactiverunner.cpp
changeset 39 7b3e49e4608a
parent 19 10810c91db26
child 61 e1d68407ed06
equal deleted inserted replaced
36:682dd021f9be 39:7b3e49e4608a
     1 /*
     1 /*
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3  * All rights reserved.
     4  * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5  * under the terms of the License "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6  * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8  *
     8  *
     9  * Initial Contributors:
     9  * Initial Contributors:
    10  * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11  *
    11  *
    12  * Contributors:
    12  * Contributors:
    13  *
    13  *
    14  * Description: Implementation of middleware wrapper class
    14  * Description: Implementation of middleware wrapper class
    15  *   
    15  *
    16  *
    16  *
    17  */
    17  */
    18 
    18 // System includes
       
    19 #include <wlanmgmtcommon.h>
       
    20 #include <e32math.h>
    19 
    21 
    20 // User includes
    22 // User includes
    21 #include "cwpsactiverunner.h"
    23 #include "cwpsactiverunner.h"
    22 #include "wlanmgmtcommon.h"
    24 
    23 
    25 // External function prototypes
    24 //Need to check this.
    26 
    25 const TInt KArrayGranularity = 4;
    27 //Constants
       
    28 static const TInt KArrayGranularity = 4;
       
    29 static const TInt KDefaultPinLength = 10;
       
    30 
       
    31 // Trace includes
       
    32 #include "OstTraceDefinitions.h"
       
    33 #ifdef OST_TRACE_COMPILER_IN_USE
       
    34 #include "cwpsactiverunnerTraces.h"
       
    35 #endif
    26 
    36 
    27 /*!
    37 /*!
    28  \class CWpsActiveRunner
    38  \class CWpsActiveRunner
    29  \brief CWpsActiveRunner is a wrapper class wlan Mgmt engine interface
    39  \brief CWpsActiveRunner is a wrapper class wlan Mgmt engine interface.
    30  */
    40  The wrapper class for wlan management engine calls
    31 
    41  */
       
    42 
       
    43 // ======== LOCAL FUNCTIONS ========
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
    32 
    46 
    33 /*!
    47 /*!
    34  * Creates the instance of active runner which encapsulates the wlan mgmt
    48  * Creates the instance of active runner which encapsulates the wlan mgmt
    35  * interface middleware calls
    49  * interface middleware calls
    36  * 
    50  *
    37  * 
    51  *
    38  * \param MWpsActiveRunnerCallback call back interface to notify the completion of the middleware calls
    52  * \param MWpsActiveRunnerCallback[in] call back interface to notify the
       
    53  *      completion of the middleware calls
    39  */
    54  */
    40 CWpsActiveRunner* CWpsActiveRunner::NewL(MWpsActiveRunnerCallback& aObserver)
    55 CWpsActiveRunner* CWpsActiveRunner::NewL(MWpsActiveRunnerCallback& aObserver)
    41 {
    56 {
    42     CWpsActiveRunner* self = new (ELeave) CWpsActiveRunner( aObserver );
    57     OstTraceFunctionEntry0( CWPSACTIVERUNNER_NEWL_ENTRY );
       
    58     CWpsActiveRunner* self = new (ELeave) CWpsActiveRunner(aObserver);
    43     CleanupStack::PushL(self);
    59     CleanupStack::PushL(self);
    44     self->ConstructL();
    60     self->ConstructL();
    45     CleanupStack::Pop(self);
    61     CleanupStack::Pop(self);
       
    62     OstTraceFunctionExit0( CWPSACTIVERUNNER_NEWL_EXIT );
    46     return self;
    63     return self;
    47 }
    64 }
       
    65 
    48 /*!
    66 /*!
    49  * Creates the instance of active runner which encapsulates the wlan mgmt
    67  * Creates the instance of active runner which encapsulates the wlan mgmt
    50  * interface middleware calls
    68  * interface middleware calls
    51  * 
    69  *
    52  * 
    70  *
    53  * \param MWpsActiveRunnerCallback call back interface to notify the completion of the middleware calls
    71  * \param MWpsActiveRunnerCallback[in] call back interface to notify the
       
    72  *      completion of the middleware calls
    54  */
    73  */
    55 CWpsActiveRunner::CWpsActiveRunner(MWpsActiveRunnerCallback& aObserver) :
    74 CWpsActiveRunner::CWpsActiveRunner(MWpsActiveRunnerCallback& aObserver) :
    56     CActive(EPriorityStandard), iObserver(aObserver)
    75     CActive(EPriorityStandard),
    57 {
    76     iObserver(aObserver),
    58 #ifdef __arm
    77     isCancelTriggered(false),
    59     iIapParametersArray = NULL;
    78     iWLANMgmtClient(NULL),
    60     iWLANMgmtClient = NULL;
    79     iIapParametersArray(NULL)
    61 #endif
    80 {
    62 }
    81     OstTraceFunctionEntry1( CWPSACTIVERUNNER_CWPSACTIVERUNNER_ENTRY, this );
    63 
    82     OstTraceFunctionExit1( CWPSACTIVERUNNER_CWPSACTIVERUNNER_EXIT, this );
    64 /*!
    83 }
    65  * Initializes the member variables
    84 
    66  * 
    85 /*!
    67  * 
    86  * ConstructL, Two phased constructor.
    68  * \return integer error code indicating the result of the operation
    87  *
    69  */
    88  */
    70 void CWpsActiveRunner::InitL()
    89 void CWpsActiveRunner::ConstructL()
    71 {
    90 {
       
    91     OstTraceFunctionEntry1( CWPSACTIVERUNNER_CONSTRUCTL_ENTRY, this );
       
    92 
    72     CActiveScheduler::Add(this);
    93     CActiveScheduler::Add(this);
    73 #ifdef __arm
       
    74     InitializeL();
    94     InitializeL();
    75 #else
    95     OstTraceFunctionExit1( CWPSACTIVERUNNER_CONSTRUCTL_EXIT, this );
    76     iTimer.CreateLocal();
       
    77 #endif
       
    78 
       
    79 }
       
    80 
       
    81 void CWpsActiveRunner::ConstructL()
       
    82 {
       
    83     InitL();
       
    84 }
    96 }
    85 
    97 
    86 /*!
    98 /*!
    87  * Initializes the member variables for making the middleware calls
    99  * Initializes the member variables for making the middleware calls
    88  * 
   100  *
    89  */
   101  */
    90 
   102 
    91 void CWpsActiveRunner::InitializeL()
   103 void CWpsActiveRunner::InitializeL()
    92 {
   104 {
    93 #ifdef __arm    
   105     OstTraceFunctionEntry1( CWPSACTIVERUNNER_INITIALIZEL_ENTRY, this );
    94     if (!iWLANMgmtClient)
   106     iWLANMgmtClient = CWlanMgmtClient::NewL();
    95         iWLANMgmtClient = CWlanMgmtClient::NewL();
   107     iIapParametersArray = new (ELeave) CArrayFixSeg<
    96     if (!iIapParametersArray)
   108         TWlanProtectedSetupCredentialAttribute> (KArrayGranularity);
    97         iIapParametersArray = new (ELeave) CArrayFixSeg<
   109     
    98     TWlanProtectedSetupCredentialAttribute> (KArrayGranularity);
   110     OstTraceFunctionExit1( CWPSACTIVERUNNER_INITIALIZEL_EXIT, this );
    99 #endif    
       
   100 }
   111 }
   101 
   112 
   102 /*!
   113 /*!
   103  * Destructor
   114  * Destructor
   104  * 
   115  *
   105  */
   116  */
   106 
       
   107 CWpsActiveRunner::~CWpsActiveRunner()
   117 CWpsActiveRunner::~CWpsActiveRunner()
   108 {
   118 {
       
   119     OstTraceFunctionEntry0( DUP1_CWPSACTIVERUNNER_CWPSACTIVERUNNER_ENTRY );
   109     Cancel();
   120     Cancel();
   110 #ifdef __arm
       
   111     delete iWLANMgmtClient;
   121     delete iWLANMgmtClient;
   112     delete iIapParametersArray;
   122     delete iIapParametersArray;
   113 #else
   123     OstTraceFunctionExit0( DUP1_CWPSACTIVERUNNER_CWPSACTIVERUNNER_EXIT );
   114     iTimer.Cancel();
       
   115     iTimer.Close();
       
   116 #endif
       
   117 }
   124 }
   118 
   125 
   119 /*!
   126 /*!
   120  * Initiates the call to the middleware
   127  * Initiates the call to the middleware
       
   128  *
       
   129  * \param aSsid[in] The network ssid to which we have to connect
       
   130  * \param aPin[in] The pin to be used for WPS negotiating
   121  */
   131  */
   122 void CWpsActiveRunner::StartSetup(RBuf8& aSsid, int aPin)
   132 void CWpsActiveRunner::StartSetup(RBuf8& aSsid, int aPin)
   123 {
   133 {
   124 #ifdef __arm
   134     OstTraceFunctionEntry1( CWPSACTIVERUNNER_STARTSETUP_ENTRY, this );
   125     TWlanSsid ssid;
   135     TWlanSsid ssid;
   126     TWlanWpsPin pin;
   136     TWlanWpsPin pin;
   127 
   137 
       
   138     isCancelTriggered = false;
   128     ssid.Copy(aSsid);
   139     ssid.Copy(aSsid);
   129     TBuf8<32> pinCode;
   140     TBuf8<KDefaultPinLength> pinCode;
   130     pinCode.AppendNum(aPin);
   141 
       
   142     if (aPin == 0) {
       
   143         pinCode.AppendFill('0', 8);
       
   144     }
       
   145     else {
       
   146         pinCode.AppendNum(aPin);
       
   147     }
       
   148 
   131     pin.Copy(pinCode);
   149     pin.Copy(pinCode);
   132     iWLANMgmtClient->RunProtectedSetup(iStatus,ssid,pin,*iIapParametersArray);
   150 
   133 #else
   151     iWLANMgmtClient->RunProtectedSetup(iStatus, ssid, pin, *iIapParametersArray);
   134     iTimer.After(iStatus, 4 * 1000000);
   152 
   135 #endif
       
   136     SetActive();
   153     SetActive();
   137 
   154 
       
   155     OstTraceFunctionExit1( CWPSACTIVERUNNER_STARTSETUP_EXIT, this );
   138 }
   156 }
   139 
   157 
   140 /*!
   158 /*!
   141  * RunL implementation
   159  * RunL implementation
   142  */
   160  */
   143 void CWpsActiveRunner::RunL()
   161 void CWpsActiveRunner::RunL()
   144 {
   162 {
       
   163     OstTraceFunctionEntry1( CWPSACTIVERUNNER_RUNL_ENTRY, this );
       
   164 
   145     TInt completionCode = iStatus.Int();
   165     TInt completionCode = iStatus.Int();
   146     QList<TWlanProtectedSetupCredentialAttribute> credentials;
   166     QList<TWlanProtectedSetupCredentialAttribute> credentials;
   147 
   167 
   148     if (completionCode < KErrNone) {
   168     if(!isCancelTriggered) {
   149         //Raise Error
   169 
   150         iObserver.WpsActiveRunnerStopped(credentials, completionCode);
   170         if (completionCode < KErrNone) {
       
   171             //Raise Error
       
   172         QT_TRYCATCH_LEAVING(iObserver.WpsActiveRunnerStopped(credentials, completionCode));
       
   173         }
       
   174         else {
       
   175             TInt len = iIapParametersArray->Length();
       
   176             TInt count;
       
   177             for(count=0;count<iIapParametersArray->Count();count++)
       
   178                 {
       
   179                 TWlanProtectedSetupCredentialAttribute attr =(*iIapParametersArray)[count];
       
   180                 credentials.append(attr);
       
   181                 }
       
   182             QT_TRYCATCH_LEAVING(iObserver.WpsActiveRunnerStopped(credentials,completionCode));
       
   183 
       
   184         }
   151     }
   185     }
   152     else {
   186 
   153 #ifdef __arm
   187     OstTraceFunctionExit1( CWPSACTIVERUNNER_RUNL_EXIT, this );
   154         TInt len = iIapParametersArray->Length();
   188 }
   155         TInt count;
   189 
   156         for(count=0;count<iIapParametersArray->Count();count++)
   190 /*!
       
   191  * Cancels the ongoing call
       
   192  */
       
   193 void CWpsActiveRunner::DoCancel()
       
   194 {
       
   195     OstTraceFunctionEntry1( CWPSACTIVERUNNER_DOCANCEL_ENTRY, this );
       
   196     isCancelTriggered = true;
       
   197     if(iWLANMgmtClient)
   157         {
   198         {
   158             TWlanProtectedSetupCredentialAttribute attr =(*iIapParametersArray)[count];
   199         iWLANMgmtClient->CancelProtectedSetup();
   159             credentials.append(attr);
   200         }
   160         }
   201     OstTraceFunctionExit1( CWPSACTIVERUNNER_DOCANCEL_EXIT, this );
   161         iObserver.WpsActiveRunnerStopped(credentials,completionCode);
   202 }
   162 #else
   203 
   163 
   204 /*!
   164         RunProtectedSetup_Stub();
   205  * Handles the error usecase
   165 #endif
   206  */
   166     }
   207 TInt CWpsActiveRunner::RunError(TInt aError)
   167 
   208 {
   168 }
   209     OstTraceFunctionEntry1( CWPSACTIVERUNNER_RUNERROR_ENTRY, this );
   169 
   210 
   170 /*!
   211     OstTrace1( TRACE_ERROR, CWPSACTIVERUNNER_RUNERROR, "CWpsActiveRunner::RunError;aError=%d", aError );
   171  * Cancels the ongoing call
   212 
   172  */
   213     QList<TWlanProtectedSetupCredentialAttribute> credentials;
   173 void CWpsActiveRunner::DoCancel()
       
   174 {
       
   175 #ifdef __arm    
       
   176     if(iWLANMgmtClient)
   214     if(iWLANMgmtClient)
   177     iWLANMgmtClient->CancelProtectedSetup();
   215         {
   178 #else
   216         iWLANMgmtClient->CancelProtectedSetup();
   179     iTimer.Cancel();
   217         }
   180 #endif
   218 
   181 }
   219     QT_TRYCATCH_LEAVING(iObserver.WpsActiveRunnerStopped(credentials, aError));
   182 
   220 
   183 /*!
   221     return 0;
   184  * Handles the error usecase
   222 }
   185  */
   223 
   186 TInt CWpsActiveRunner::RunError(TInt aError)
       
   187 {
       
   188     QList<TWlanProtectedSetupCredentialAttribute> credentials;
       
   189 #ifdef __arm    
       
   190     if(iWLANMgmtClient)
       
   191     iWLANMgmtClient->CancelProtectedSetup();
       
   192 #else
       
   193     iTimer.Cancel();
       
   194 #endif
       
   195 
       
   196     iObserver.WpsActiveRunnerStopped(credentials, aError);
       
   197 }
       
   198 
       
   199 #ifndef __arm
       
   200 void CWpsActiveRunner::RunProtectedSetup_Stub()
       
   201 {
       
   202     QList<TWlanProtectedSetupCredentialAttribute> credentials;
       
   203     TWlanProtectedSetupCredentialAttribute attr1 = { EWlanOperatingModeInfrastructure, // iOperatingMode
       
   204         EWlanAuthenticationModeOpen, // iAuthenticationMode
       
   205         EWlanIapSecurityModeWpa, // iSecurityMode,
       
   206         _L8( "STUB01" ), // iSsid
       
   207         _L8( "" ), // iWepKey1
       
   208         _L8( "" ), // iWepKey2
       
   209         _L8( "" ), // iWepKey3
       
   210         _L8( "" ), // iWepKey4
       
   211         EWlanDefaultWepKey1, // iWepDefaultKey
       
   212         _L8( "testtest" )
       
   213     // iWpaPreSharedKey
       
   214         };
       
   215 
       
   216     TWlanProtectedSetupCredentialAttribute attr2 = { EWlanOperatingModeAdhoc,
       
   217         EWlanAuthenticationModeOpen, EWlanIapSecurityModeWep, _L8( "STUB02" ), _L8( "12345" ),
       
   218         _L8( "" ), _L8( "" ), _L8( "" ), EWlanDefaultWepKey1, _L8( "" ) };
       
   219 
       
   220     credentials.append(attr1);
       
   221     credentials.append(attr2);
       
   222 
       
   223     iObserver.WpsActiveRunnerStopped(credentials, KErrNone);
       
   224 }
       
   225 #endif