wlanutilities/wpswizard/src/cwpsactiverunner.cpp
changeset 38 2dc6da6fb431
parent 29 dbe86d96ce5b
child 41 a87deff717bc
child 45 d9ec2b8c6bad
equal deleted inserted replaced
29:dbe86d96ce5b 38:2dc6da6fb431
     1 /*
       
     2  * Copyright (c) 2010 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: Implementation of middleware wrapper class
       
    15  *   
       
    16  *
       
    17  */
       
    18 
       
    19 
       
    20 // User includes
       
    21 #include "cwpsactiverunner.h"
       
    22 #include "wlanmgmtcommon.h"
       
    23 
       
    24 //Need to check this.
       
    25 const TInt KArrayGranularity = 4;
       
    26 
       
    27 /*!
       
    28  \class CWpsActiveRunner
       
    29  \brief CWpsActiveRunner is a wrapper class wlan Mgmt engine interface
       
    30  */
       
    31 
       
    32 
       
    33 /*!
       
    34  * Creates the instance of active runner which encapsulates the wlan mgmt
       
    35  * interface middleware calls
       
    36  * 
       
    37  * 
       
    38  * \param MWpsActiveRunnerCallback call back interface to notify the completion of the middleware calls
       
    39  */
       
    40 CWpsActiveRunner* CWpsActiveRunner::NewL(MWpsActiveRunnerCallback& aObserver)
       
    41 {
       
    42     CWpsActiveRunner* self = new (ELeave) CWpsActiveRunner( aObserver );
       
    43     CleanupStack::PushL(self);
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47 }
       
    48 /*!
       
    49  * Creates the instance of active runner which encapsulates the wlan mgmt
       
    50  * interface middleware calls
       
    51  * 
       
    52  * 
       
    53  * \param MWpsActiveRunnerCallback call back interface to notify the completion of the middleware calls
       
    54  */
       
    55 CWpsActiveRunner::CWpsActiveRunner(MWpsActiveRunnerCallback& aObserver) :
       
    56     CActive(EPriorityStandard), iObserver(aObserver)
       
    57 {
       
    58 #ifdef __arm
       
    59     iIapParametersArray = NULL;
       
    60     iWLANMgmtClient = NULL;
       
    61 #endif
       
    62 }
       
    63 
       
    64 /*!
       
    65  * Initializes the member variables
       
    66  * 
       
    67  * 
       
    68  * \return integer error code indicating the result of the operation
       
    69  */
       
    70 void CWpsActiveRunner::InitL()
       
    71 {
       
    72     CActiveScheduler::Add(this);
       
    73 #ifdef __arm
       
    74     InitializeL();
       
    75 #else
       
    76     iTimer.CreateLocal();
       
    77 #endif
       
    78 
       
    79 }
       
    80 
       
    81 void CWpsActiveRunner::ConstructL()
       
    82 {
       
    83     InitL();
       
    84 }
       
    85 
       
    86 /*!
       
    87  * Initializes the member variables for making the middleware calls
       
    88  * 
       
    89  */
       
    90 
       
    91 void CWpsActiveRunner::InitializeL()
       
    92 {
       
    93 #ifdef __arm    
       
    94     if (!iWLANMgmtClient)
       
    95         iWLANMgmtClient = CWlanMgmtClient::NewL();
       
    96     if (!iIapParametersArray)
       
    97         iIapParametersArray = new (ELeave) CArrayFixSeg<
       
    98     TWlanProtectedSetupCredentialAttribute> (KArrayGranularity);
       
    99 #endif    
       
   100 }
       
   101 
       
   102 /*!
       
   103  * Destructor
       
   104  * 
       
   105  */
       
   106 
       
   107 CWpsActiveRunner::~CWpsActiveRunner()
       
   108 {
       
   109     Cancel();
       
   110 #ifdef __arm
       
   111     delete iWLANMgmtClient;
       
   112     delete iIapParametersArray;
       
   113 #else
       
   114     iTimer.Cancel();
       
   115     iTimer.Close();
       
   116 #endif
       
   117 }
       
   118 
       
   119 /*!
       
   120  * Initiates the call to the middleware
       
   121  */
       
   122 void CWpsActiveRunner::StartSetup(RBuf8& aSsid, int aPin)
       
   123 {
       
   124 #ifdef __arm
       
   125     TWlanSsid ssid;
       
   126     TWlanWpsPin pin;
       
   127 
       
   128     ssid.Copy(aSsid);
       
   129     TBuf8<32> pinCode;
       
   130     pinCode.AppendNum(aPin);
       
   131     pin.Copy(pinCode);
       
   132     iWLANMgmtClient->RunProtectedSetup(iStatus,ssid,pin,*iIapParametersArray);
       
   133 #else
       
   134     iTimer.After(iStatus, 4 * 1000000);
       
   135 #endif
       
   136     SetActive();
       
   137 
       
   138 }
       
   139 
       
   140 /*!
       
   141  * RunL implementation
       
   142  */
       
   143 void CWpsActiveRunner::RunL()
       
   144 {
       
   145     TInt completionCode = iStatus.Int();
       
   146     QList<TWlanProtectedSetupCredentialAttribute> credentials;
       
   147 
       
   148     if (completionCode < KErrNone) {
       
   149         //Raise Error
       
   150         iObserver.WpsActiveRunnerStopped(credentials, completionCode);
       
   151     }
       
   152     else {
       
   153 #ifdef __arm
       
   154         TInt len = iIapParametersArray->Length();
       
   155         TInt count;
       
   156         for(count=0;count<iIapParametersArray->Count();count++)
       
   157         {
       
   158             TWlanProtectedSetupCredentialAttribute attr =(*iIapParametersArray)[count];
       
   159             credentials.append(attr);
       
   160         }
       
   161         iObserver.WpsActiveRunnerStopped(credentials,completionCode);
       
   162 #else
       
   163 
       
   164         RunProtectedSetup_Stub();
       
   165 #endif
       
   166     }
       
   167 
       
   168 }
       
   169 
       
   170 /*!
       
   171  * Cancels the ongoing call
       
   172  */
       
   173 void CWpsActiveRunner::DoCancel()
       
   174 {
       
   175 #ifdef __arm    
       
   176     if(iWLANMgmtClient)
       
   177     iWLANMgmtClient->CancelProtectedSetup();
       
   178 #else
       
   179     iTimer.Cancel();
       
   180 #endif
       
   181 }
       
   182 
       
   183 /*!
       
   184  * Handles the error usecase
       
   185  */
       
   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