wlansecuritysettings/wlaneapsettingsui/EapPluginConfig/src/EAPPluginConfiguration.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 EAP Plugin Configuration
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "EAPPluginConfiguration.h"
       
    22 #include "EAPPlugInConfigurationDlg.h"
       
    23 #include "EAPPluginConfigurationModel.h"
       
    24 #include <bautils.h>
       
    25 #include <EapType.h>
       
    26 #include "EAPPluginList.h"
       
    27 
       
    28 #include <ecom/ecom.h>
       
    29 #include <data_caging_path_literals.hrh>
       
    30 #include <EAPPluginConfigRes.rsg>
       
    31 
       
    32 // CONSTANTS
       
    33 _LIT( KDriveZ, "z:" );                               // ROM folder
       
    34 _LIT( KResourceFileName, "EAPPluginConfigRes.rsc" );   // RSC file name.
       
    35 _LIT( KSpace, " " );
       
    36 _LIT( KPlusSign, "+" );
       
    37 _LIT( KMinusSign, "-" );
       
    38 _LIT( KComma, "," );
       
    39 
       
    40 
       
    41 // Length of the UID
       
    42 static const TInt KLengthOfImplUid = 3;
       
    43 
       
    44 // Length of expanded EAP type (RFC 3748)
       
    45 static const TInt KLengthOfExpEapType = 8; 
       
    46 
       
    47 
       
    48 
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CEAPPluginConfiguration::CEAPPluginConfiguration
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CEAPPluginConfiguration::CEAPPluginConfiguration()
       
    56 : iIapId( 0 )
       
    57     {
       
    58     }
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CEAPPluginConfiguration::NewL
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CEAPPluginConfiguration* CEAPPluginConfiguration::NewL() 
       
    66     {
       
    67     CEAPPluginConfiguration* self = NewLC();
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72     
       
    73 // -----------------------------------------------------------------------------
       
    74 // CEAPPluginConfiguration::NewLC
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CEAPPluginConfiguration* CEAPPluginConfiguration::NewLC()
       
    78     {
       
    79     CEAPPluginConfiguration* self = new( ELeave )CEAPPluginConfiguration();
       
    80     CleanupStack::PushL(self);
       
    81     self->ConstructL();
       
    82     return self;
       
    83     }
       
    84 
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CEAPPluginConfiguration::ConstructL
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CEAPPluginConfiguration::ConstructL()
       
    91     {
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CEAPPluginConfiguration::~CEAPPluginConfiguration
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 CEAPPluginConfiguration::~CEAPPluginConfiguration()
       
   100     {    
       
   101     iEapArray.ResetAndDestroy();
       
   102     CCoeEnv::Static()->DeleteResourceFile( iResOffset );
       
   103     }
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------
       
   107 // CEAPPluginConfiguration::EAPPluginConfigurationL
       
   108 // ---------------------------------------------------------
       
   109 //
       
   110 TInt CEAPPluginConfiguration::EAPPluginConfigurationL( TDes& aWPAEAPPlugin,
       
   111                                                  const TUint32 aIapId, 
       
   112                                                  const TDes& aConnectionName )
       
   113     {
       
   114   	// Adding the resource file to the CoeEnv.
       
   115     if( !iResOffset )
       
   116         {  		
       
   117         TFileName fileName;
       
   118 
       
   119         fileName.Append( KDriveZ );
       
   120         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
   121         fileName.Append( KResourceFileName );
       
   122 	    
       
   123         BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), 
       
   124                                         fileName );
       
   125 	    
       
   126 	    TRAP_IGNORE( iResOffset = 
       
   127                             CCoeEnv::Static()->AddResourceFileL( fileName ); );
       
   128   	    }       
       
   129 
       
   130     TInt buttonId;
       
   131     
       
   132     REAPPluginList plugins;            ///< Plug-in infos.
       
   133     
       
   134     LoadPluginInfoL( aWPAEAPPlugin, plugins );
       
   135     CEAPPluginConfigurationModel* model = new( ELeave ) 
       
   136                                     CEAPPluginConfigurationModel( plugins );
       
   137     CleanupStack::PushL( model );
       
   138 
       
   139     CEAPPluginConfigurationDlg* pluginDlg = new( ELeave ) 
       
   140                         CEAPPluginConfigurationDlg( buttonId, *model, aIapId );
       
   141 
       
   142     pluginDlg->ConstructAndRunLD( plugins, aConnectionName );
       
   143 
       
   144     SavePluginInfoL( aWPAEAPPlugin, plugins );
       
   145     
       
   146     CleanupStack::PopAndDestroy( model );
       
   147     plugins.Close();
       
   148     
       
   149     iIapId = aIapId;
       
   150 
       
   151     return buttonId;
       
   152     }
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------
       
   156 // CEAPPluginConfiguration::EAPPluginConfigurationL
       
   157 // ---------------------------------------------------------
       
   158 //
       
   159 TInt CEAPPluginConfiguration::EAPPluginConfigurationL( 
       
   160                                                 TDes8& aWPAEnabledEAPPlugin,
       
   161                                                 TDes8& aWPADisabledEAPPlugin,
       
   162                                                 const TUint32 aIapId, 
       
   163                                                 const TDes& aConnectionName )
       
   164     {
       
   165   	// Adding the resource file to the CoeEnv.
       
   166     if( !iResOffset )
       
   167         {  		
       
   168         TFileName fileName;
       
   169 
       
   170         fileName.Append( KDriveZ );
       
   171         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
   172         fileName.Append( KResourceFileName );
       
   173 	    
       
   174         BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), 
       
   175                                         fileName );
       
   176 	    
       
   177 	    TRAP_IGNORE( iResOffset = 
       
   178                             CCoeEnv::Static()->AddResourceFileL( fileName ); );
       
   179   	    }       
       
   180 
       
   181 
       
   182     TInt buttonId;
       
   183     
       
   184     REAPPluginList plugins;            ///< Plug-in infos.
       
   185     
       
   186     LoadPluginInfoL( aWPAEnabledEAPPlugin, aWPADisabledEAPPlugin, plugins );
       
   187     CEAPPluginConfigurationModel* model = new( ELeave ) 
       
   188                                     CEAPPluginConfigurationModel( plugins );
       
   189     CleanupStack::PushL( model );
       
   190 
       
   191     CEAPPluginConfigurationDlg* pluginDlg = new( ELeave ) 
       
   192                         CEAPPluginConfigurationDlg( buttonId, *model, aIapId );
       
   193 
       
   194     pluginDlg->ConstructAndRunLD( plugins, aConnectionName );
       
   195 
       
   196     SavePluginInfoL( aWPAEnabledEAPPlugin, aWPADisabledEAPPlugin, plugins );
       
   197     
       
   198     CleanupStack::PopAndDestroy( model );
       
   199     plugins.Close();
       
   200     
       
   201     iIapId = aIapId;
       
   202 
       
   203     return buttonId;
       
   204     }
       
   205     
       
   206 
       
   207 // ---------------------------------------------------------
       
   208 // CEAPPluginConfiguration::LoadPluginInfoL
       
   209 // ---------------------------------------------------------
       
   210 //
       
   211 void CEAPPluginConfiguration::LoadPluginInfoL( TDes& aWPAEAPPlugin, 
       
   212                                                REAPPluginList& aPlugins )
       
   213     {
       
   214     TInt posComma = aWPAEAPPlugin.Locate( ',' );
       
   215     while ( posComma != KErrNotFound )                // Extract the parameters
       
   216         {
       
   217         aWPAEAPPlugin.Replace( posComma, 1, KSpace );
       
   218         posComma = aWPAEAPPlugin.Locate( ',' );
       
   219         }
       
   220 
       
   221     TLex lex( aWPAEAPPlugin );
       
   222 
       
   223     CArrayFixFlat<TPtrC>* params;       // array of parameters
       
   224     params = new( ELeave ) CArrayFixFlat<TPtrC>( sizeof( TPtrC ) );
       
   225     CleanupStack::PushL( params );
       
   226 
       
   227     while ( !lex.Eos() )                // Extract the parameters
       
   228         {
       
   229         params->AppendL( lex.NextToken() );
       
   230         }
       
   231 
       
   232     aPlugins.Reset();   // Reset this first: dependent on iEapArray.
       
   233     iEapArray.ResetAndDestroy();
       
   234     REComSession::ListImplementationsL( KEapTypeInterfaceUid, iEapArray );
       
   235 
       
   236     // EAP plugin interface dialog should show only the EAP types that allowed
       
   237     // outside PEAP.
       
   238     
       
   239     for( TInt count = 0; count < iEapArray.Count(); count++ )
       
   240         {
       
   241         // Filter out the EAP types which are NOT allowed outside PEAP.
       
   242         if( CEapType::IsDisallowedOutsidePEAP( *iEapArray[count] ) )
       
   243             {
       
   244             // Delete the EAP type, which isn't allowed outside PEAP, 
       
   245             // from the array.
       
   246             delete iEapArray[count];
       
   247             iEapArray.Remove( count );
       
   248             
       
   249             // One item removed from the array. So reduce the item count.
       
   250             count--;
       
   251             }
       
   252         }
       
   253 
       
   254     TInt numParams = params->Count();
       
   255     TBool foundDefaultEAPTypes = EFalse;
       
   256     
       
   257     // Rearrange the array so that EAP-SIM and EAP-AKA are on top, in that order.
       
   258     
       
   259     // The rearrange is needed only for the first time creation.
       
   260     if ( numParams == 0 )
       
   261         {
       
   262         TInt topPos = 0; // position in the beginning of arrary.
       
   263         TInt error( KErrNone );
       
   264 
       
   265         // First move EAP-AKA to top, if it is present in the array.
       
   266         error = MoveEAPType( EAPSettings::EEapAka, topPos );
       
   267 
       
   268         if ( error != KErrNotFound )
       
   269             {
       
   270             // Found EAP-AKA in the array. 
       
   271             // Doesn't matter if the move was a success or not.
       
   272             foundDefaultEAPTypes = ETrue;
       
   273             }
       
   274 
       
   275         // Now move EAP-SIM to top. 
       
   276         // EAP-SIM will be always the top most if it is present in the array.
       
   277         // Otherwise EAP-AKA stays in the top, if it is present.
       
   278         // The order doesn't matter if these two are not present.
       
   279         MoveEAPType( EAPSettings::EEapSim, topPos );
       
   280 
       
   281         if( error != KErrNotFound)
       
   282             {
       
   283             // Found EAP-SIM in the array. 
       
   284             // Doesn't matter if the move was a success.
       
   285             foundDefaultEAPTypes = ETrue;
       
   286             }   
       
   287         }
       
   288 
       
   289     TInt i;
       
   290     TInt j;
       
   291     TInt numInfoStore = iEapArray.Count();
       
   292     TInt eapUid;
       
   293     
       
   294     // just to make sure we are not given a non-empty but fully disabled list
       
   295     TBool gotEnabled = EFalse;
       
   296 
       
   297     CArrayFix<TInt>* usedImplInfo = new( ELeave ) CArrayFixFlat<TInt>( 4 );
       
   298     CleanupStack::PushL( usedImplInfo );
       
   299     usedImplInfo->AppendL( 0, numInfoStore );
       
   300 
       
   301     for ( j = 0; j < numParams; j++ )
       
   302         {
       
   303         TLex lexUid( params->At( j ) );
       
   304         if ( lexUid.Val( eapUid ) == KErrNone )
       
   305             {
       
   306             for ( i = 0; i < numInfoStore; i++ )
       
   307                 {
       
   308                 TLex8 lexDataType( iEapArray[i]->DataType() );
       
   309                 TInt implUID;
       
   310 
       
   311                 if ( lexDataType.Val( implUID ) == KErrNone )
       
   312                     {
       
   313                     if ( implUID == Abs( eapUid ) )
       
   314                         {
       
   315                         usedImplInfo->InsertL( i, 1 );
       
   316                         if ( i+1 < usedImplInfo->Count() )
       
   317                             {
       
   318                             usedImplInfo->Delete( i+1 );
       
   319                             }
       
   320 
       
   321                         TEAPPluginInfo plugin;
       
   322                         plugin.iInfo = iEapArray[i];
       
   323 
       
   324                         plugin.iEnabled = ( eapUid > 0 || 
       
   325                                 ( eapUid == 0 && 
       
   326                                   params->At( j ).Left( 1 ) == KPlusSign ) );
       
   327                         User::LeaveIfError( aPlugins.Append( plugin ) );
       
   328                         gotEnabled = gotEnabled || plugin.iEnabled;
       
   329                         i = numInfoStore;  // to exit from cycle
       
   330                         }
       
   331                     }
       
   332                 }   
       
   333             }
       
   334         }
       
   335 
       
   336     for ( i = 0; i < numInfoStore; i++ )
       
   337         {
       
   338         if ( !usedImplInfo->At( i ) )
       
   339             {
       
   340             TEAPPluginInfo plugin;
       
   341             plugin.iInfo = iEapArray[i];
       
   342             
       
   343             // Default is enabled. 
       
   344             // There should not be a case of all EAP types disabled.
       
   345             TBool defaultEnableValue( ETrue ); 
       
   346             
       
   347             if ( numParams > 0 && gotEnabled)
       
   348                 {
       
   349                 // If there some EAP types which are already enabled/disabled,
       
   350                 // we make the new EAP types disabled.
       
   351                 defaultEnableValue = EFalse;
       
   352                 }
       
   353             else
       
   354                 {
       
   355                 // Nothing in the string or all disabled.
       
   356                 // Should be the first time execution (creating new IAP).
       
   357                 // Only EAP-SIM and EAP-AKA are enabled in this case.
       
   358                 TLex8 lexDataType( iEapArray[i]->DataType() );
       
   359                 TInt implDataType;
       
   360                 
       
   361                 if ( lexDataType.Val( implDataType ) == KErrNone )
       
   362                     {
       
   363                     if( foundDefaultEAPTypes )
       
   364                         {
       
   365                         defaultEnableValue = 
       
   366                                     ( implDataType == EAPSettings::EEapSim ||
       
   367                                       implDataType == EAPSettings::EEapAka );
       
   368                         }
       
   369                     else
       
   370                         {
       
   371                         // No default EAPs (No EAP-SIM and EAP-AKA). 
       
   372                         // So all EAP types are enabled by default.
       
   373                         defaultEnableValue = ETrue;
       
   374                         }
       
   375                     }
       
   376                 }
       
   377 
       
   378             plugin.iEnabled = defaultEnableValue;
       
   379             User::LeaveIfError( aPlugins.Append( plugin ) );
       
   380             }
       
   381         }
       
   382 
       
   383     CleanupStack::PopAndDestroy( 2, params );  // usedImplInfo, params
       
   384     }
       
   385 
       
   386 
       
   387 // ---------------------------------------------------------
       
   388 // CEAPPluginConfiguration::LoadPluginInfoL
       
   389 // ---------------------------------------------------------
       
   390 //
       
   391 void CEAPPluginConfiguration::LoadPluginInfoL( TDes8& aWPAEnabledEAPPlugin, 
       
   392                                                TDes8& aWPADisabledEAPPlugin, 
       
   393                                                REAPPluginList& aPlugins )
       
   394     {
       
   395     // size of aWPAEnabledEAPPlugin and aWPADisabledEAPPlugin must be 
       
   396     // divisible by KLengthOfExpEapType
       
   397     __ASSERT_DEBUG( ( aWPAEnabledEAPPlugin.Size() % KLengthOfExpEapType == 0 ), 
       
   398                     User::Panic( _L( "aWPAEnabledEAPPlugin is corrupted!" ), KErrCorrupt ) );
       
   399                      
       
   400     __ASSERT_DEBUG( ( aWPADisabledEAPPlugin.Size() % KLengthOfExpEapType == 0 ), 
       
   401                     User::Panic( _L( "aWPADisabledEAPPlugin is corrupted!" ), KErrCorrupt ) );
       
   402     
       
   403 
       
   404     aPlugins.Reset();   // Reset this first: dependent on iEapArray.
       
   405     iEapArray.ResetAndDestroy();
       
   406     REComSession::ListImplementationsL( KEapTypeInterfaceUid, iEapArray );
       
   407 
       
   408     // EAP plugin interface dialog should show only the EAP types that allowed
       
   409     // outside PEAP.
       
   410     
       
   411     for( TInt count = 0; count < iEapArray.Count(); count++ )
       
   412         {
       
   413         // Filter out the EAP types which are NOT allowed outside PEAP.
       
   414         if( CEapType::IsDisallowedOutsidePEAP( *iEapArray[count] ) )
       
   415             {
       
   416             // Delete the EAP type, which isn't allowed outside PEAP, 
       
   417             // from the array.
       
   418             delete iEapArray[count];
       
   419             iEapArray.Remove( count );
       
   420             
       
   421             // One item removed from the array. So reduce the item count.
       
   422             count--;
       
   423             }
       
   424         }
       
   425 
       
   426     TInt numEnabled = aWPAEnabledEAPPlugin.Size() / KLengthOfExpEapType;
       
   427     TInt numDisabled = aWPADisabledEAPPlugin.Size() / KLengthOfExpEapType;
       
   428     TBool foundDefaultEAPTypes = EFalse;
       
   429     
       
   430     // Rearrange the array so that EAP-SIM and EAP-AKA are on top, in that order.
       
   431     
       
   432     // The rearrange is needed only for the first time creation.
       
   433     if ( !( numEnabled || numDisabled ) )
       
   434         {
       
   435         TInt topPos = 0; // position in the beginning of array.
       
   436         TInt error( KErrNone );
       
   437 
       
   438         // First move EAP-AKA to top, if it is present in the array.
       
   439         _LIT8( KExpEapTypeFormat, "\xFE\0\0\0%c%c%c%c" );
       
   440         TBuf8<KLengthOfExpEapType> tmpEap;
       
   441         
       
   442         // BigEndian::Put32( const_cast<TUint8*>( tmpEap.Ptr() ) + 4, 
       
   443         //                  EAPSettings::EEapAka );
       
   444         tmpEap.Format( KExpEapTypeFormat, ( EAPSettings::EEapAka >> 24 ) & 0xff, 
       
   445                                           ( EAPSettings::EEapAka >> 16 ) & 0xff,
       
   446                                           ( EAPSettings::EEapAka >> 8 ) & 0xff,
       
   447                                           EAPSettings::EEapAka & 0xff );
       
   448                                           
       
   449         error = MoveEAPType( tmpEap, topPos );
       
   450 
       
   451         if ( error != KErrNotFound )
       
   452             {
       
   453             // Found EAP-AKA in the array. 
       
   454             // Doesn't matter if the move was a success or not.
       
   455             foundDefaultEAPTypes = ETrue;
       
   456             }
       
   457 
       
   458         // Now move EAP-SIM to top. 
       
   459         // EAP-SIM will be always the top most if it is present in the array.
       
   460         // Otherwise EAP-AKA stays in the top, if it is present.
       
   461         // The order doesn't matter if these two are not present.
       
   462         // BigEndian::Put32( const_cast<TUint8*>( tmpEap.Ptr() ) + 4, 
       
   463         //                  EAPSettings::EEapSim );
       
   464         tmpEap.Format( KExpEapTypeFormat, ( EAPSettings::EEapSim >> 24 ) & 0xff, 
       
   465                                           ( EAPSettings::EEapSim >> 16 ) & 0xff,
       
   466                                           ( EAPSettings::EEapSim >> 8 ) & 0xff,
       
   467                                           EAPSettings::EEapSim & 0xff );
       
   468                                           
       
   469         error = MoveEAPType( tmpEap, topPos );
       
   470 
       
   471         if( error != KErrNotFound)
       
   472             {
       
   473             // Found EAP-SIM in the array. 
       
   474             // Doesn't matter if the move was a success.
       
   475             foundDefaultEAPTypes = ETrue;
       
   476             }   
       
   477         }
       
   478 
       
   479     TInt i;
       
   480     TInt j;
       
   481     TInt numInfoStore = iEapArray.Count();
       
   482 
       
   483     CArrayFix<TInt>* usedImplInfo = new( ELeave ) CArrayFixFlat<TInt>( 4 );
       
   484     CleanupStack::PushL( usedImplInfo );
       
   485   
       
   486     usedImplInfo->AppendL( 0, numInfoStore );
       
   487 
       
   488     // deal with the enabled first
       
   489     for ( j = 0; j < numEnabled; j++ )
       
   490         {
       
   491     	TPtrC8 param( aWPAEnabledEAPPlugin.Ptr() + KLengthOfExpEapType * j, 
       
   492     	              KLengthOfExpEapType );
       
   493     	
       
   494         for ( i = 0; i < numInfoStore; i++ )
       
   495             {
       
   496             if ( !param.Compare( iEapArray[i]->DataType() ) )
       
   497                 {
       
   498                 usedImplInfo->InsertL( i, 1 );
       
   499                 if ( i+1 < usedImplInfo->Count() )
       
   500                     {
       
   501                     usedImplInfo->Delete( i+1 );
       
   502                     }
       
   503 
       
   504                 TEAPPluginInfo plugin;
       
   505                 plugin.iInfo = iEapArray[i];
       
   506                 plugin.iEnabled = ETrue;
       
   507                 
       
   508                 User::LeaveIfError( aPlugins.Append( plugin ) );
       
   509                 i = numInfoStore;  // to exit from cycle
       
   510                 }
       
   511             }   
       
   512         }
       
   513 
       
   514 
       
   515     // now come the disabled
       
   516     for ( j = 0; j < numDisabled; j++ )
       
   517         {
       
   518     	TPtrC8 param( aWPADisabledEAPPlugin.Ptr() + KLengthOfExpEapType * j, 
       
   519     	              KLengthOfExpEapType );
       
   520     	
       
   521         for ( i = 0; i < numInfoStore; i++ )
       
   522             {
       
   523             if ( !param.Compare( iEapArray[i]->DataType() ) )
       
   524                 {
       
   525                 usedImplInfo->InsertL( i, 1 );
       
   526                 if ( i+1 < usedImplInfo->Count() )
       
   527                     {
       
   528                     usedImplInfo->Delete( i+1 );
       
   529                     }
       
   530 
       
   531                 TEAPPluginInfo plugin;
       
   532                 plugin.iInfo = iEapArray[i];
       
   533                 plugin.iEnabled = EFalse;
       
   534                 
       
   535                 User::LeaveIfError( aPlugins.Append( plugin ) );
       
   536                 i = numInfoStore;  // to exit from cycle
       
   537                 }
       
   538             }   
       
   539         }
       
   540         
       
   541 
       
   542     for ( i = 0; i < numInfoStore; i++ )
       
   543         {
       
   544         if ( !usedImplInfo->At( i ) )
       
   545             {
       
   546             TEAPPluginInfo plugin;
       
   547             plugin.iInfo = iEapArray[i];
       
   548             
       
   549             // Default is enabled. 
       
   550             // There should not be a case of all EAP types disabled.
       
   551             TBool defaultEnableValue( ETrue ); 
       
   552             
       
   553             if ( numEnabled > 0 )
       
   554                 {
       
   555                 // If there some EAP types which are already enabled/disabled,
       
   556                 // we make the new EAP types disabled.
       
   557                 defaultEnableValue = EFalse;
       
   558                 }
       
   559             else
       
   560                 {
       
   561                 // No EAP types enabled. 
       
   562                 // Should be the first time execution (creating new IAP).
       
   563                 // Only EAP-SIM and EAP-AKA are enabled in this case.
       
   564                 
       
   565                 // [FE] [00 00 00] [TEapType_bigendian]
       
   566                 const TDesC8& cue = iEapArray[i]->DataType();
       
   567                 
       
   568                 TPtrC8 eapType( cue.Ptr() + 4, 4 );
       
   569                 TUint32 implDataType = ( eapType[0] << 24 ) |
       
   570                                        ( eapType[1] << 16 ) |
       
   571                                        ( eapType[2] << 8 ) |
       
   572                                        eapType[3];
       
   573 
       
   574                 if( foundDefaultEAPTypes )
       
   575                     {
       
   576                     _LIT8( KExpEapFirstQuad, "\xFE\0\0\0" );
       
   577                     TPtrC8 firstQuad( cue.Ptr(), 4 );
       
   578                     
       
   579                     defaultEnableValue = 
       
   580                             ( !firstQuad.Compare ( KExpEapFirstQuad ) &&
       
   581                                 ( implDataType == EAPSettings::EEapSim ||
       
   582                                   implDataType == EAPSettings::EEapAka ) );
       
   583                     }
       
   584                 else
       
   585                     {
       
   586                     // No default EAPs (No EAP-SIM and EAP-AKA). 
       
   587                     // So all EAP types are enabled by default.
       
   588                     defaultEnableValue = ETrue;
       
   589                     }
       
   590                 }
       
   591 
       
   592             plugin.iEnabled = defaultEnableValue;
       
   593             User::LeaveIfError( aPlugins.Append( plugin ) );
       
   594             }
       
   595         }
       
   596     CleanupStack::PopAndDestroy( usedImplInfo );
       
   597     
       
   598     }
       
   599     
       
   600 
       
   601 // ---------------------------------------------------------
       
   602 // CEAPPluginConfiguration::SavePluginInfoL
       
   603 // ---------------------------------------------------------
       
   604 //
       
   605 void CEAPPluginConfiguration::SavePluginInfoL( TDes& aWPAEAPPlugin, 
       
   606                                                REAPPluginList& aPlugins )
       
   607     {
       
   608     aWPAEAPPlugin.Zero();
       
   609     for ( TInt index = 0; index < aPlugins.Count(); index++ )
       
   610         {
       
   611         TBuf8<KLengthOfImplUid> cue = aPlugins[index].iInfo->DataType(); 
       
   612 
       
   613         TLex8 lexDataType( cue );
       
   614         TInt implUID;
       
   615         if ( lexDataType.Val( implUID ) == KErrNone )
       
   616             {
       
   617             if ( aPlugins[index].iEnabled )
       
   618                 {
       
   619                 aWPAEAPPlugin.Append( KPlusSign );
       
   620                 }
       
   621             else
       
   622                 {
       
   623                 aWPAEAPPlugin.Append( KMinusSign );
       
   624                 }
       
   625 
       
   626             aWPAEAPPlugin.AppendNumFixedWidth( implUID, EDecimal, 
       
   627                                                KLengthOfImplUid );
       
   628 
       
   629             if ( index != aPlugins.Count()-1 )
       
   630                 {
       
   631                 aWPAEAPPlugin.Append( KComma );
       
   632                 }
       
   633             }
       
   634         }
       
   635     }
       
   636 
       
   637 
       
   638 // ---------------------------------------------------------
       
   639 // CEAPPluginConfiguration::SavePluginInfoL
       
   640 // ---------------------------------------------------------
       
   641 //
       
   642 void CEAPPluginConfiguration::SavePluginInfoL( TDes8& aWPAEnabledEAPPlugin, 
       
   643                                                TDes8& aWPADisabledEAPPlugin, 
       
   644                                                REAPPluginList& aPlugins )
       
   645     {
       
   646     aWPAEnabledEAPPlugin.Zero();
       
   647     aWPADisabledEAPPlugin.Zero();
       
   648     
       
   649     for ( TInt index = 0; index < aPlugins.Count(); index++ )
       
   650         {
       
   651         if ( aPlugins[index].iEnabled )
       
   652             {
       
   653             aWPAEnabledEAPPlugin.Append( aPlugins[index].iInfo->DataType() );
       
   654             }
       
   655         else
       
   656             {
       
   657             aWPADisabledEAPPlugin.Append( aPlugins[index].iInfo->DataType() );
       
   658             }
       
   659         } 
       
   660     
       
   661     }
       
   662     
       
   663 
       
   664 // ---------------------------------------------------------
       
   665 // CEAPPluginConfiguration::ShowEAPTypeInfo
       
   666 // ---------------------------------------------------------
       
   667 //
       
   668 void CEAPPluginConfiguration::ShowEAPTypeInfo()
       
   669     {    
       
   670     
       
   671     }
       
   672 
       
   673 
       
   674 // ---------------------------------------------------------
       
   675 // CEAPPluginConfiguration::DeleteSettingsL
       
   676 // ---------------------------------------------------------
       
   677 //
       
   678 void CEAPPluginConfiguration::DeleteSettingsL( const TUint32 aIapID )
       
   679     {    
       
   680     iEapArray.ResetAndDestroy();
       
   681     REComSession::ListImplementationsL( KEapTypeInterfaceUid, iEapArray );
       
   682         
       
   683     for ( TInt i = 0; i < iEapArray.Count(); i++ )
       
   684         {
       
   685         if ( !CEapType::IsDisallowedOutsidePEAP( *iEapArray[i] ) )
       
   686             {
       
   687             CEapType* eapType = CEapType::NewL( iEapArray[i]->DataType(), 
       
   688                                                 ELan, 
       
   689                                                 aIapID );
       
   690             CleanupStack::PushL( eapType );
       
   691             
       
   692             eapType->DeleteConfigurationL();
       
   693             CleanupStack::PopAndDestroy( eapType );
       
   694             }
       
   695         }    
       
   696     }
       
   697 
       
   698 
       
   699 // ---------------------------------------------------------
       
   700 // CEAPPluginConfiguration::ChangeIapIDL
       
   701 // ---------------------------------------------------------
       
   702 //
       
   703 void CEAPPluginConfiguration::ChangeIapIDL( const TUint32 aOldIapID,
       
   704                                             const TUint32 aNewIapID )
       
   705     {
       
   706     iEapArray.ResetAndDestroy();
       
   707     REComSession::ListImplementationsL( KEapTypeInterfaceUid, iEapArray );
       
   708         
       
   709     for ( TInt i = 0; i < iEapArray.Count(); i++ )
       
   710         {
       
   711         if ( !CEapType::IsDisallowedOutsidePEAP( *iEapArray[i] ) )
       
   712             {
       
   713             CEapType* eapType = CEapType::NewL( iEapArray[i]->DataType(), 
       
   714                                                 ELan, 
       
   715                                                 aOldIapID );
       
   716             CleanupStack::PushL( eapType );
       
   717             
       
   718             eapType->SetIndexL( ELan, aNewIapID );
       
   719             CleanupStack::PopAndDestroy( eapType );
       
   720         }
       
   721     }    
       
   722 }
       
   723 
       
   724 // ---------------------------------------------------------
       
   725 // CEAPPluginConfiguration::CopySettingsL
       
   726 // ---------------------------------------------------------
       
   727 //
       
   728 void CEAPPluginConfiguration::CopySettingsL( const TUint32 aSourceIapID,
       
   729 	                                         const TUint32 aDestinationIapID )
       
   730     {
       
   731 	iEapArray.ResetAndDestroy();
       
   732 	REComSession::ListImplementationsL( KEapTypeInterfaceUid, iEapArray );
       
   733 		
       
   734 	for ( TInt i = 0; i < iEapArray.Count(); i++ )
       
   735 	    {
       
   736 		if ( !CEapType::IsDisallowedOutsidePEAP( *iEapArray[i] ) )
       
   737 		    {
       
   738 			CEapType* eapType = CEapType::NewL( iEapArray[i]->DataType(), 
       
   739 			                                    ELan, 
       
   740 			                                    aSourceIapID );
       
   741 			CleanupStack::PushL( eapType );
       
   742 			
       
   743 			eapType->CopySettingsL( ELan, aDestinationIapID );
       
   744 			CleanupStack::PopAndDestroy( eapType );
       
   745     		}
       
   746 	    }	
       
   747     }
       
   748         
       
   749 
       
   750 // ---------------------------------------------------------
       
   751 // CEAPPluginConfiguration::MoveEAPType
       
   752 // ---------------------------------------------------------
       
   753 //
       
   754 TInt CEAPPluginConfiguration::MoveEAPType( EAPSettings::TEapType aEapType, 
       
   755                                            TInt aPos )
       
   756     {
       
   757     TInt error( KErrNotFound );
       
   758 
       
   759     // Parse the array to find out the desired EAP type.
       
   760     for( TInt count = 0; count < iEapArray.Count(); count++ )
       
   761         {
       
   762         TLex8 lexDataType( iEapArray[count]->DataType() );
       
   763         TInt implDataType;
       
   764         
       
   765         if ( lexDataType.Val( implDataType ) == KErrNone )
       
   766             {
       
   767             if ( implDataType == aEapType )
       
   768                 {
       
   769                 // Move this to the required destination.
       
   770                 error = iEapArray.Insert( iEapArray[count], aPos );
       
   771 
       
   772                 if( KErrNone == error )
       
   773                     {
       
   774                     // Delete the old entry. It should be one count up now.
       
   775                     iEapArray.Remove( count+1 );          			
       
   776                     }
       
   777                 else
       
   778                     {
       
   779                     // Some problem. Couldn't move.
       
   780                     error = KErrUnknown;
       
   781                     }
       
   782 
       
   783                 // No need to parse further in the array. 
       
   784                 // We found the needed EAP type.
       
   785                 break; 
       
   786                 }
       
   787             }
       
   788         else
       
   789             {
       
   790             error = KErrGeneral;
       
   791             }
       
   792         }
       
   793 
       
   794     return error;
       
   795     }
       
   796 
       
   797 
       
   798 // ---------------------------------------------------------
       
   799 // CEAPPluginConfiguration::MoveEAPType
       
   800 // ---------------------------------------------------------
       
   801 //
       
   802 TInt CEAPPluginConfiguration::MoveEAPType( const TDesC8& aEapType, TInt aPos )
       
   803     {
       
   804     TInt error( KErrNotFound );
       
   805 
       
   806     // Parse the array to find out the desired EAP type.
       
   807     for( TInt count = 0; count < iEapArray.Count(); count++ )
       
   808         {
       
   809         if ( !iEapArray[count]->DataType().Compare( aEapType ) )
       
   810             {
       
   811             // Move this to the required destination.
       
   812             error = iEapArray.Insert( iEapArray[count], aPos );
       
   813 
       
   814             if( KErrNone == error )
       
   815                 {
       
   816                 // Delete the old entry. It should be one count up now.
       
   817                 iEapArray.Remove( count+1 );          			
       
   818                 }
       
   819             else
       
   820                 {
       
   821                 // Some problem. Couldn't move.
       
   822                 error = KErrUnknown;
       
   823                 }
       
   824 
       
   825             // No need to parse further in the array. 
       
   826             // We found the needed EAP type.
       
   827             break; 
       
   828             }
       
   829         }
       
   830 
       
   831     return error;
       
   832     }
       
   833 
       
   834 // End of file.