wlansecuritysettings/wifiprotectedsetup/pluginsrc/wifiprotdlgsplugin.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     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: Implementation of CWiFiProtDlgsPlugin.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32property.h>         // For RProperty 
       
    21 #include <wifiprotuiddefs.h>
       
    22 #include <bautils.h>
       
    23 #include <eikenv.h>
       
    24 #include <data_caging_path_literals.hrh>
       
    25 
       
    26 #include "wifiprotdlgsplugin.h"
       
    27 #include "wifiprotplugin.h"
       
    28 #include "wifiprotlogger.h"
       
    29 #include "wifiprotactiverunner.h"
       
    30 
       
    31 
       
    32 
       
    33 using namespace WiFiProt;
       
    34 
       
    35 // CONSTS
       
    36 _LIT( KDriveZ, "z:" );
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ============================
       
    39     
       
    40 // --------------------------------------------------------------------------
       
    41 // CWiFiProtDlgsPlugin* CWiFiProtDlgsPlugin::NewL()
       
    42 // --------------------------------------------------------------------------
       
    43 //
       
    44 CWiFiProtDlgsPlugin* CWiFiProtDlgsPlugin::NewL( 
       
    45                              const TBool aResourceFileResponsible,
       
    46                                       RCmManagerExt* aCmManagerExt )
       
    47 
       
    48     {
       
    49     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::NewL" );
       
    50     
       
    51     CWiFiProtDlgsPlugin* self = new ( ELeave ) CWiFiProtDlgsPlugin();
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL( KResourceFileName,
       
    54                       aResourceFileResponsible, aCmManagerExt );
       
    55     CleanupStack::Pop( self );
       
    56     
       
    57     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::NewL" );
       
    58     
       
    59     return self;
       
    60     }
       
    61     
       
    62 // --------------------------------------------------------------------------
       
    63 // CWiFiProtDlgsPlugin* CWiFiProtDlgsPlugin::NewL()
       
    64 // --------------------------------------------------------------------------
       
    65 //
       
    66 CWiFiProtDlgsPlugin* CWiFiProtDlgsPlugin::NewL( 
       
    67                                        const TBool aResourceFileResponsible )
       
    68     {
       
    69     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::NewL (without passed CmManager)" );
       
    70     
       
    71     CWiFiProtDlgsPlugin* ret =  NewL( aResourceFileResponsible, NULL );
       
    72     
       
    73     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::NewL (without passed CmManager)" );
       
    74     
       
    75     return ret;
       
    76     }
       
    77 
       
    78 // --------------------------------------------------------------------------
       
    79 // CWiFiProtDlgsPlugin::~CWiFiProtDlgsPlugin
       
    80 // --------------------------------------------------------------------------
       
    81 //
       
    82 CWiFiProtDlgsPlugin::~CWiFiProtDlgsPlugin( )
       
    83 
       
    84     {    
       
    85     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::~CWiFiProtDlgsPlugin" );
       
    86     
       
    87     delete iRunner;
       
    88 
       
    89     //we didn't get a cmManager from the client, so use our own
       
    90     if (iPassedCmManagerExt == NULL)
       
    91         {
       
    92         iCmManagerExt.Close();
       
    93         }    
       
    94 
       
    95     iUids.Close();
       
    96 
       
    97     if ( iResource )
       
    98         {
       
    99         CCoeEnv::Static()->DeleteResourceFile( iResource );        
       
   100         }
       
   101 
       
   102     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::~CWiFiProtDlgsPlugin" );
       
   103     
       
   104     }  
       
   105 
       
   106 // --------------------------------------------------------------------------
       
   107 // CWiFiProtDlgsPlugin::TNotifierInfo 
       
   108 //                                  CWiFiProtDlgsPlugin::Info() const
       
   109 // --------------------------------------------------------------------------
       
   110 //
       
   111 CWiFiProtDlgsPlugin::TNotifierInfo CWiFiProtDlgsPlugin::Info() const
       
   112     {
       
   113     return iInfo;
       
   114     }
       
   115 
       
   116 // --------------------------------------------------------------------------
       
   117 // TPtrC8 CWiFiProtDlgsPlugin::StartL()
       
   118 // --------------------------------------------------------------------------
       
   119 //
       
   120 TPtrC8 CWiFiProtDlgsPlugin::StartL( const TDesC8& /*aBuffer*/ )
       
   121     {
       
   122     CLOG_WRITE( "CWiFiProtDlgsPlugin::StartL" );
       
   123     return KNullDesC8().Ptr();
       
   124     }
       
   125 
       
   126 // --------------------------------------------------------------------------
       
   127 // void CWiFiProtDlgsPlugin::Cancel()
       
   128 // --------------------------------------------------------------------------
       
   129 //
       
   130 void CWiFiProtDlgsPlugin::Cancel()
       
   131     {
       
   132     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::Cancel" );
       
   133     
       
   134     if ( !iCancelled )
       
   135         {
       
   136         if ( iRunner && !iCancelledFromInside )
       
   137             {
       
   138             iClientCancelled = ETrue;
       
   139             iRunner->CancelByClient();
       
   140             }
       
   141         iCancelled = ETrue;
       
   142         if ( !iMessage.IsNull() )
       
   143             {
       
   144             if ( iConnMode )
       
   145                 {
       
   146                 TRAP_IGNORE( iMessage.WriteL( iReplySlot,
       
   147                          TPckg<WiFiProt::TWiFiConnOutputParams>( 
       
   148                                 TWlanProtectedSetupCredentialAttribute() )
       
   149                          ));
       
   150                 }
       
   151             else
       
   152                 {
       
   153                 TRAP_IGNORE( iMessage.WriteL( iReplySlot,
       
   154                          TPckg<WiFiProt::TWiFiOutputParams>( KNullDesC8() )
       
   155                          ));
       
   156                 }
       
   157             iMessage.Complete( KErrCancel );
       
   158             }
       
   159         }
       
   160         
       
   161     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::Cancel" );
       
   162     
       
   163     }
       
   164     
       
   165 // --------------------------------------------------------------------------
       
   166 // void CWiFiProtDlgsPlugin::Release()
       
   167 // --------------------------------------------------------------------------
       
   168 //
       
   169 void CWiFiProtDlgsPlugin::Release()
       
   170     {
       
   171     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::Release" );
       
   172 
       
   173     delete this;
       
   174 
       
   175     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::Release" );
       
   176     }
       
   177 
       
   178 // --------------------------------------------------------------------------
       
   179 // TPtrC8 CWiFiProtDlgsPlugin::UpdateL()
       
   180 // --------------------------------------------------------------------------
       
   181 //
       
   182 TPtrC8 CWiFiProtDlgsPlugin::UpdateL(const TDesC8& /*aBuffer*/)
       
   183     {
       
   184     return KNullDesC8().Ptr();
       
   185     }
       
   186 
       
   187 // --------------------------------------------------------------------------
       
   188 // void CWiFiProtDlgsPlugin::CompleteL()
       
   189 // --------------------------------------------------------------------------
       
   190 //
       
   191 void CWiFiProtDlgsPlugin::CompleteL( TInt aStatus )
       
   192     {    
       
   193     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::CompleteL" );
       
   194     
       
   195     CLOG_WRITEF( _L( "aStatus:" ), aStatus );
       
   196     iCancelled = ETrue;
       
   197     if ( !iMessage.IsNull() )
       
   198         {
       
   199         if ( iConnMode )
       
   200             {
       
   201             // return a different kind of message
       
   202             // for connection creation 
       
   203             WiFiProt::TWiFiConnOutputParams connOutputParams =
       
   204             WiFiProt::TWiFiConnOutputParams( iNetworkSettings );
       
   205             connOutputParams.iReturn = iReturn;            
       
   206             iMessage.WriteL( iReplySlot,
       
   207                             TPckg<WiFiProt::TWiFiConnOutputParams>( connOutputParams ) );            
       
   208             }
       
   209         else
       
   210             {
       
   211             // ... or iap(s) creation
       
   212             const TInt elementSize = sizeof(TUint32);
       
   213             TBuf8<(KMaxNumberOfUids * elementSize)> buf;
       
   214             TInt uidsCount = iUids.Count();
       
   215             if ( uidsCount > KMaxNumberOfUids )
       
   216                 {
       
   217                 uidsCount = KMaxNumberOfUids;
       
   218                 }
       
   219             // copy data from the array to iIapIds in TWiFiOutputParams
       
   220             buf.Append((const TUint8 *)(&iUids[0]), uidsCount *elementSize);
       
   221             //append return value
       
   222             WiFiProt::TWiFiOutputParams outputParams =
       
   223                 WiFiProt::TWiFiOutputParams(buf);
       
   224             outputParams.iReturn = iReturn;
       
   225             iMessage.WriteL( iReplySlot,
       
   226                             TPckg<WiFiProt::TWiFiOutputParams>( outputParams ) );
       
   227             }
       
   228         iMessage.Complete( aStatus );
       
   229         }
       
   230         
       
   231     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::CompleteL" );
       
   232     
       
   233     }
       
   234     
       
   235 // --------------------------------------------------------------------------
       
   236 // CWiFiProtDlgsPlugin::SetCancelledFlag
       
   237 // --------------------------------------------------------------------------
       
   238 //
       
   239 void CWiFiProtDlgsPlugin::SetCancelledFlag( TBool aCancelled )
       
   240     { 
       
   241     iCancelled = aCancelled; 
       
   242     }
       
   243 
       
   244 // --------------------------------------------------------------------------
       
   245 // CWiFiProtDlgsPlugin::TNotifierInfo CWiFiProtDlgsPlugin::RegisterL()
       
   246 // --------------------------------------------------------------------------
       
   247 //
       
   248 CWiFiProtDlgsPlugin::TNotifierInfo CWiFiProtDlgsPlugin::RegisterL()
       
   249     {
       
   250     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::RegisterL" );
       
   251 
       
   252     iInfo.iUid = KUidWiFiProtSetup;
       
   253     iInfo.iPriority = ENotifierPriorityHigh;
       
   254     iInfo.iChannel = KUidWiFiProtSetup;
       
   255     
       
   256     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::RegisterL" );
       
   257     
       
   258     return iInfo;
       
   259     }
       
   260 
       
   261 // --------------------------------------------------------------------------
       
   262 // void CWiFiProtDlgsPlugin::StartL
       
   263 // --------------------------------------------------------------------------
       
   264 //
       
   265 void CWiFiProtDlgsPlugin::StartL( const TDesC8& aBuffer, 
       
   266                                   TInt aReplySlot,
       
   267                                   const RMessagePtr2& aMessage )
       
   268     {
       
   269     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::StartL" );
       
   270     
       
   271     TPckgBuf<TWiFiInputParams> pckgParams(
       
   272                     TPckgBuf<TWiFiInputParams>(TWiFiInputParams(KNullDesC8(),
       
   273                     EFalse))); 
       
   274     pckgParams.Copy( *((TPckgBuf<TWiFiInputParams>*) (&aBuffer)));
       
   275     TWiFiInputParams params((pckgParams)());
       
   276     iConnMode = params.iConnectionNeeded;
       
   277     TWlanSsid ssid;
       
   278     ssid.Copy( params.iSSid );
       
   279     
       
   280     iCancelled = EFalse;
       
   281 
       
   282     iReplySlot = aReplySlot;
       
   283     iMessage = aMessage;
       
   284 
       
   285     if ( iConnMode )
       
   286         {
       
   287         // no need for uid array to return, but we need a single network 
       
   288         // settings struct
       
   289         iRunner->StartProtectedSetupConnL( ssid, iNetworkSettings,
       
   290                                                        CmManagerToUse());
       
   291         }
       
   292     else
       
   293         {
       
   294         iRunner->StartProtectedSetupAsyncL( ssid, iUids, CmManagerToUse() );
       
   295         }
       
   296         
       
   297     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::StartL" );
       
   298     }
       
   299 
       
   300 // --------------------------------------------------------------------------
       
   301 // WiFiProt::TWiFiReturn CWiFiProtDlgsPlugin::CompleteProcessL
       
   302 // --------------------------------------------------------------------------
       
   303 //
       
   304 void CWiFiProtDlgsPlugin::CompleteProcessL( WiFiProt::TWiFiReturn aReturnValue )
       
   305     {
       
   306     CLOG_ENTERFN( "WiFiProtDlgsPlugin::CompleteProcessL" );
       
   307     iReturn = aReturnValue;
       
   308     switch ( aReturnValue )
       
   309         {
       
   310         case EWiFiOK:
       
   311             {
       
   312             CLOG_WRITE("StartProtectedSetupL returned EWiFiOK");
       
   313             CompleteL( KErrNone );
       
   314             break;
       
   315             }
       
   316         case EWifiNoAuto:
       
   317             {
       
   318             CLOG_WRITE("StartProtectedSetupL returned EWifiNoAuto");
       
   319             CompleteL( KErrNone );
       
   320             break;
       
   321             }
       
   322         case EWiFiCancel:
       
   323             {
       
   324             CLOG_WRITE("StartProtectedSetupL returned EWiFiCancel");
       
   325             iCancelledFromInside = ETrue;
       
   326             Cancel();
       
   327             break;
       
   328             }
       
   329         default:
       
   330             {
       
   331             //should never happen
       
   332             CLOG_WRITE("Unhandled exit value, leaving...");
       
   333             User::Leave( KErrGeneral );
       
   334             break;
       
   335             }
       
   336         }
       
   337     CLOG_WRITEF( _L( "Uids returned:" ), iUids.Count() );
       
   338     for ( TInt i = 0;i<iUids.Count();i++ )
       
   339         {
       
   340         CLOG_WRITEF( _L( "Uid:" ), iUids[i] );
       
   341         }
       
   342         
       
   343     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::CompleteProcessL" );
       
   344     }
       
   345 
       
   346     
       
   347 // --------------------------------------------------------------------------
       
   348 // WiFiProt::TWiFiReturn CWiFiProtDlgsPlugin::StartFromUiL
       
   349 // --------------------------------------------------------------------------
       
   350 //
       
   351 
       
   352 WiFiProt::TWiFiReturn CWiFiProtDlgsPlugin::StartFromUiL(
       
   353                                         const TWlanSsid& aSSid,
       
   354                                        TBool aConnectionNeeded,
       
   355                                 RArray<TUint32>& aUidsReturned)
       
   356     {
       
   357     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::StartFromUiL" );
       
   358     
       
   359     CLOG_WRITE("Input params:");
       
   360     CLOG_WRITE("SSid:");
       
   361     
       
   362     TBuf<KWlanMaxSsidLength> buf;
       
   363     buf.Copy(aSSid); 
       
   364     CLOG_WRITEF( buf );
       
   365     CLOG_WRITE("Connection needed:");
       
   366     if ( aConnectionNeeded )
       
   367         {
       
   368         CLOG_WRITE("ETrue");
       
   369         }
       
   370      else
       
   371         {
       
   372         CLOG_WRITE("EFalse");
       
   373         }
       
   374     //use passed CmManager if present
       
   375     WiFiProt::TWiFiReturn ret = iRunner->StartProtectedSetupL( 
       
   376                   aSSid, aUidsReturned, CmManagerToUse());
       
   377     
       
   378     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::StartFromUiL" );
       
   379     return ret;
       
   380     }
       
   381 
       
   382 // --------------------------------------------------------------------------
       
   383 // void CWiFiProtDlgsPlugin::CmManagerToUse()
       
   384 // --------------------------------------------------------------------------
       
   385 //
       
   386 RCmManagerExt& CWiFiProtDlgsPlugin::CmManagerToUse()
       
   387     {
       
   388     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::CmManagerToUse" );
       
   389     
       
   390     if (iPassedCmManagerExt == NULL )
       
   391         {
       
   392         CLOG_WRITE("Own CmManagerExt used");
       
   393         
       
   394         CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::CmManagerToUse" );
       
   395         
       
   396         return iCmManagerExt;
       
   397         }
       
   398      else
       
   399         {
       
   400         CLOG_WRITE("Passed CmManagerExt used");
       
   401         
       
   402         CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::CmManagerToUse" );
       
   403         
       
   404         return *iPassedCmManagerExt;
       
   405         }
       
   406     }
       
   407 
       
   408 // --------------------------------------------------------------------------
       
   409 // CWiFiProtDlgsPlugin::CWiFiProtDlgsPlugin()
       
   410 // --------------------------------------------------------------------------
       
   411 //
       
   412 CWiFiProtDlgsPlugin::CWiFiProtDlgsPlugin()
       
   413 : iCancelled( EFalse ),
       
   414   iResource( 0 ),
       
   415   iCancelledFromInside( EFalse )
       
   416 
       
   417     {
       
   418     CLOG_WRITE("CWiFiProtDlgsPlugin::CWiFiProtDlgsPlugin");
       
   419     }
       
   420     
       
   421 // --------------------------------------------------------------------------
       
   422 // void CWiFiProtDlgsPlugin::ConstructL( )
       
   423 // --------------------------------------------------------------------------
       
   424 //
       
   425 void CWiFiProtDlgsPlugin::ConstructL(const TDesC& aResourceFileName,
       
   426                                      const TBool aResourceFileResponsible,
       
   427                                      RCmManagerExt* aCmManagerExt )
       
   428     {
       
   429     CLOG_ENTERFN( "CWiFiProtDlgsPlugin::ConstructL" );
       
   430     
       
   431     if ( aResourceFileResponsible )
       
   432         {
       
   433         // Since this is a .DLL, resource files that are to be used by the
       
   434         // notifier aren't added automatically so we do that here.
       
   435         TFileName fileName;
       
   436 
       
   437         fileName.Append( KDriveZ );
       
   438         fileName.Append( KDC_RESOURCE_FILES_DIR );   
       
   439         fileName.Append( aResourceFileName );
       
   440 
       
   441         BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(),
       
   442                                         fileName );
       
   443         iResource = CCoeEnv::Static()->AddResourceFileL( fileName );
       
   444         }
       
   445     
       
   446     iPassedCmManagerExt = aCmManagerExt;
       
   447     //we didn't get a cmManager from the client, so use our own
       
   448     if (iPassedCmManagerExt == NULL)
       
   449         {
       
   450         iCmManagerExt.OpenL();
       
   451         }
       
   452     iRunner = CWiFiProtActiveRunner::NewL( this );
       
   453     
       
   454     CLOG_LEAVEFN( "CWiFiProtDlgsPlugin::ConstructL" );
       
   455     
       
   456     }
       
   457 
       
   458 // End of File