dbcreator/commsdatcreator/Src/cdcprocessorwlan.cpp
changeset 56 dd6aaa97e7b1
parent 52 bbe4544dfd31
child 59 2709c04a4af5
equal deleted inserted replaced
52:bbe4544dfd31 56:dd6aaa97e7b1
     1 /*
       
     2 * Copyright (c) 2005 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 "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 the class CProcessorWlan
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "cdcprocessorwlan.h"
       
    24 #include "cdclogger.h"
       
    25 #include "cdcerrors.h"
       
    26 
       
    27 #include <cmpluginwlandef.h>
       
    28 #include <cmpluginbaseeng.h>
       
    29 #include <cmconnectionmethoddef.h>
       
    30 #include <cmmanagerext.h>
       
    31 #include <datamobilitycommsdattypes.h>
       
    32 #include <commsdattypesv1_1.h>
       
    33 #include <WlanCdbCols.h>
       
    34 #include <commsdattypesv1_1.h>
       
    35 #include <wlancontainer.h>
       
    36 
       
    37 using namespace CMManager;
       
    38 
       
    39 // CONSTANTS
       
    40 
       
    41 // network modes.
       
    42 _LIT16( KStrAd_hoc,         "Ad-hoc" );
       
    43 _LIT16( KStrInfrastructure, "Infrastructure" ); // Default value.
       
    44 
       
    45 // security modes.
       
    46 _LIT16( KStrWEP,            "WEP" );
       
    47 _LIT16( KStr802_1x,         "802.1x" );
       
    48 _LIT16( KStrWPA,            "WPA" );          // WPA/WPA2 mixed mode
       
    49 _LIT16( KStrWPA2,           "WPA2" );         // WPA2-only mode
       
    50 _LIT16( KStrOpen,           "Open" );         // Default value.
       
    51 
       
    52 // default WLAN channel Id value
       
    53 const TInt KDefaultChannelId = 0;
       
    54 const TInt KMaximumChannelId = 11;
       
    55 
       
    56 // default port number
       
    57 const TUint32 KDefaultPortNum = 0;
       
    58 
       
    59 // ratio between sizes of ascii and unicode characters
       
    60 const TUint KAsciiUnicodeRatio = 2;
       
    61 
       
    62 // ================= MEMBER FUNCTIONS =======================
       
    63 
       
    64 CEapTypeElement::~CEapTypeElement()
       
    65     {
       
    66     delete iEapSettings;
       
    67     delete iName;
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CProcessorWlan::NewL
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 CProcessorWlan* CProcessorWlan::NewL( CReaderBase* aFileReader,
       
    76                                       RCmManagerExt& aCmManager,
       
    77                                       RPointerArray< RCmConnectionMethodExt >& aPluginArray,
       
    78                                       RPointerArray< HBufC >& aPluginNames,
       
    79                                       RPointerArray< HBufC >& aSecurityInfo,
       
    80 									  RPointerArray< CEapTypeElement >& aEapSettings )
       
    81     {
       
    82     CProcessorWlan* self = new ( ELeave ) CProcessorWlan( aFileReader,
       
    83                                                           aCmManager,
       
    84                                                           aPluginArray,
       
    85                                                           aPluginNames,
       
    86                                                           aSecurityInfo,
       
    87 														  aEapSettings );
       
    88     CleanupStack::PushL( self );
       
    89 
       
    90     // From base class
       
    91     self->ConstructL();
       
    92     CleanupStack::Pop( self );
       
    93     return self;
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------
       
    98 // CProcessorWlan::ConstructL
       
    99 // ---------------------------------------------------------
       
   100 //
       
   101 void CProcessorWlan::ConstructL()
       
   102     {
       
   103     iEmptyTag = KStrEmpty.operator const TDesC16&().Alloc();
       
   104 
       
   105     Reset(); // iWepData, iWpaData
       
   106     }
       
   107 
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CProcessorWlan::CProcessorWlan
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 CProcessorWlan::CProcessorWlan( CReaderBase* aFileReader,
       
   114                                 RCmManagerExt& aCmManager,
       
   115                                 RPointerArray< RCmConnectionMethodExt >& aPluginArray,
       
   116                                 RPointerArray< HBufC >& aPluginNames,
       
   117                                 RPointerArray< HBufC >& aSecurityInfo,
       
   118 								RPointerArray< CEapTypeElement >& aEapSettings ) :
       
   119              CProcessorBase( aFileReader,
       
   120                              aCmManager,
       
   121                              aPluginArray,
       
   122                              aPluginNames ),
       
   123              iSecurityMode( ESecurityModeOpen ),
       
   124              iEapSettings( aEapSettings ),
       
   125              iIsEasyWlan( ETrue )                     
       
   126     {
       
   127     iBearerType = KUidWlanBearerType;
       
   128     iSecurityInfo = &aSecurityInfo;
       
   129     iDataStart = 0;
       
   130     }
       
   131 
       
   132 
       
   133 // ---------------------------------------------------------
       
   134 // CProcessorWlan::~CProcessorWlan
       
   135 // ---------------------------------------------------------
       
   136 //
       
   137 CProcessorWlan::~CProcessorWlan()
       
   138     {
       
   139     delete iEmptyTag;
       
   140     REComSession::FinalClose();
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------
       
   144 // CProcessorWlan::ProcessSpecialFieldsL
       
   145 // ---------------------------------------------------------
       
   146 //
       
   147 void CProcessorWlan::ProcessSpecialFieldsL( TInt aField, HBufC* aPtrTag, TInt /*aDx*/ )
       
   148     {
       
   149         switch( aField )
       
   150             {
       
   151             // TDesC16
       
   152             case EWlanSSID:
       
   153                 {
       
   154                 if ( aPtrTag->CompareF( KStrEmpty ) != 0 )
       
   155                     {
       
   156                     iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   157                     iIsEasyWlan = EFalse;
       
   158                     }
       
   159                 else
       
   160                     {
       
   161                     // Access point is Easy WLAN 
       
   162                     iIsEasyWlan = ETrue;
       
   163                     }
       
   164                 break;
       
   165                 }
       
   166             case EWlanIpAddr:
       
   167                 {
       
   168                 if ( aPtrTag->CompareF( KStrEmpty ) != 0 )
       
   169                     {
       
   170                     iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   171                     }
       
   172                 break;
       
   173                 }
       
   174             // TDesC16
       
   175             case EWlanIpGateway:             //fall through
       
   176             case EWlanIpNetMask:             //fall through
       
   177                 {
       
   178                 iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   179                 break;
       
   180                 }
       
   181             case EWlanIpNameServer1:         //fall through
       
   182             case EWlanIpNameServer2:         //fall through
       
   183             case EWlanIp6NameServer1:        //fall through
       
   184             case EWlanIp6NameServer2:        //fall through
       
   185                 {
       
   186                 iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   187                 SetAddressFromServerL( EWlanIpNameServer1,
       
   188                                       EWlanIpNameServer2,
       
   189                                       EWlanIpDNSAddrFromServer,
       
   190                                       EWlanIp6NameServer1,
       
   191                                       EWlanIp6NameServer2,
       
   192                                       EWlanIp6DNSAddrFromServer );    
       
   193                 break;
       
   194                 }
       
   195             // TUint32
       
   196             case EWlanSecurityMode:
       
   197                 {
       
   198 
       
   199                 if ( aPtrTag->CompareF( KStrWEP ) == 0 )
       
   200                     {
       
   201                     // WEP
       
   202                     iPlugin.SetIntAttributeL( aField, EWlanSecModeWep );
       
   203                     iSecurityMode = ESecurityModeWEP;
       
   204                     }
       
   205                 else if ( aPtrTag->CompareF( KStr802_1x ) == 0 )
       
   206                     {
       
   207                     // 802.1x
       
   208                     iPlugin.SetIntAttributeL( aField, EWlanSecMode802_1x );
       
   209                     iSecurityMode = ESecurityMode802;
       
   210                     }
       
   211                 else if ( aPtrTag->CompareF( KStrWPA ) == 0 )
       
   212                     {
       
   213                     // WPA/WPA2 mixed mode
       
   214                     iPlugin.SetIntAttributeL( aField, EWlanSecModeWpa );
       
   215                     iSecurityMode = ESecurityModeWPA;
       
   216                     }
       
   217                 else if ( aPtrTag->CompareF( KStrWPA2 ) == 0 )
       
   218                     {
       
   219                     // WPA2
       
   220                     iPlugin.SetIntAttributeL( aField, EWlanSecModeWpa2 );
       
   221                     iSecurityMode = ESecurityModeWPA2;
       
   222                     }
       
   223                 else if ( aPtrTag->CompareF( KStrOpen ) == 0 )
       
   224                     {
       
   225                     // Open network (default)
       
   226                     iPlugin.SetIntAttributeL( aField, EWlanSecModeOpen );
       
   227                     iSecurityMode = ESecurityModeOpen;
       
   228                     }
       
   229                 else 
       
   230                     {
       
   231                     iPlugin.SetIntAttributeL( aField, EWlanSecModeOpen );
       
   232                     iSecurityMode = ESecurityModeOpen;
       
   233                     CLOG_WRITE( "! Error : Invalid Security Mode. Default:Open" )
       
   234                     }
       
   235                 break;
       
   236                 }
       
   237                 
       
   238             // TUint32
       
   239             case EWlanConnectionMode:
       
   240                 {
       
   241 
       
   242                 if ( !aPtrTag->CompareF( KStrAd_hoc ) )
       
   243                     {
       
   244                     // Ad-hoc
       
   245                     iPlugin.SetIntAttributeL( aField, EAdhoc );
       
   246                     }
       
   247                 else if ( !aPtrTag->CompareF( KStrInfrastructure ) )
       
   248                     {
       
   249                     // Infrastructure
       
   250                     iPlugin.SetIntAttributeL( aField, EInfra );
       
   251                     }
       
   252                 else
       
   253                     {
       
   254                     iPlugin.SetIntAttributeL( aField, EInfra );
       
   255                     CLOG_WRITE( "! Error : Invalid Network Mode. Default:Infrastructure" )
       
   256                     }
       
   257                 break;
       
   258                 }
       
   259                 
       
   260             // TUint32
       
   261             case ECmProxyPortNumber:
       
   262                 {
       
   263                 // First set proxy usage to enabled
       
   264                 if( !iProxyEnabled )
       
   265                     {
       
   266                     iPlugin.SetBoolAttributeL( ECmProxyUsageEnabled, ETrue );
       
   267                     iProxyEnabled = ETrue;
       
   268                     }
       
   269                 TLex16 lex( *aPtrTag );
       
   270                 TUint32 tmp( 0 );
       
   271                 if ( lex.Val( tmp, EDecimal ) == KErrNone )
       
   272                     {
       
   273                     iPlugin.SetIntAttributeL( aField, tmp );
       
   274                     }
       
   275                 else
       
   276                     {
       
   277                     //no valid data is given
       
   278                     iPlugin.SetIntAttributeL( aField, KDefaultPortNum );
       
   279                     CLOG_WRITE( "! Error : Invalid port number. Default:0" );
       
   280                     }
       
   281                 break;
       
   282                 }
       
   283             // Long text.
       
   284             case ECmStartPage:
       
   285                 {
       
   286 
       
   287                 if ( aPtrTag->CompareF( KStrEmpty ) != 0 )
       
   288                     {
       
   289                     iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   290                     }
       
   291                 break;
       
   292                 }
       
   293                 
       
   294 	        case ECmProxyProtocolName:
       
   295 	        	{
       
   296 	        	// Do not enable proxy in this case yet
       
   297 	        	iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   298 	        	break;
       
   299 	        	}
       
   300 	                
       
   301             // Long text.
       
   302             case ECmProxyServerName:            
       
   303                 {
       
   304                 // First set proxy usage to enabled
       
   305                 if( !iProxyEnabled )
       
   306                     {
       
   307                     iPlugin.SetBoolAttributeL( ECmProxyUsageEnabled, ETrue );
       
   308                     iProxyEnabled = ETrue;
       
   309                     }
       
   310                 iPlugin.SetStringAttributeL( aField, *aPtrTag );
       
   311                 break;
       
   312                 }
       
   313             // Bool
       
   314             case EWlanScanSSID:
       
   315                 {
       
   316                 if ( !aPtrTag->CompareF( KStrYes ) )
       
   317                     {
       
   318                     iPlugin.SetBoolAttributeL( aField, ETrue );
       
   319                     }
       
   320                 else if ( !aPtrTag->CompareF( KStrNo ) )
       
   321                     {
       
   322                     iPlugin.SetBoolAttributeL( aField, EFalse );
       
   323                     }
       
   324                 else 
       
   325                     {
       
   326                     iPlugin.SetBoolAttributeL( aField, EFalse );
       
   327                     CLOG_WRITE( "! Error : Invalid Scan SSID. Default:No" )
       
   328                     }
       
   329                 break;
       
   330                 }
       
   331 
       
   332             // TUint32
       
   333             case EWlanChannelID:
       
   334                 {
       
   335                 TLex16 lex( *aPtrTag );
       
   336                 TUint32 tmp( 0 );
       
   337                 lex.Val( tmp, EDecimal );
       
   338 
       
   339                 if( tmp <= KMaximumChannelId )
       
   340                     {
       
   341                     iPlugin.SetIntAttributeL( aField, tmp );
       
   342                     }
       
   343                 else
       
   344                     {
       
   345                     // Default value
       
   346                     iPlugin.SetIntAttributeL( aField, KDefaultChannelId );
       
   347                     CLOG_WRITE( "! Error : Invalid Chanel Id. Default:0" )
       
   348                     }
       
   349                 break;
       
   350                 }
       
   351             //WEP
       
   352             case EWEPKeyInUse:
       
   353             case EWEPAuthType:
       
   354             case EWEPKey1Length:
       
   355             case EWEPKey1Format:
       
   356             case EWEPKey1Data:
       
   357             case EWEPKey2Length:
       
   358             case EWEPKey2Format:
       
   359             case EWEPKey2Data:
       
   360             case EWEPKey3Length:
       
   361             case EWEPKey3Format:
       
   362             case EWEPKey3Data:
       
   363             case EWEPKey4Length:
       
   364             case EWEPKey4Format:
       
   365             case EWEPKey4Data:
       
   366                 {
       
   367                 if( iSecurityMode == ESecurityModeWEP )
       
   368                     {
       
   369                     AddSecurityDataL( aField, aPtrTag, ETrue );
       
   370                     }
       
   371                 }
       
   372                 break;
       
   373             //WPA
       
   374             case EWPAPresharedKey:
       
   375             case EWPAKeyLength:
       
   376             case EWPAEapMethod:
       
   377             case EWPAUseOfPresharedKey:
       
   378                 {
       
   379                 if( iSecurityMode != ESecurityModeWEP && iSecurityMode != ESecurityModeOpen )
       
   380                     {
       
   381                     AddSecurityDataL( aField, aPtrTag, EFalse );
       
   382                     }
       
   383                 }
       
   384                 break;
       
   385                 
       
   386             default:
       
   387             	// Check if this is EAP setting
       
   388             	if ( EAPSetting( aField ) )
       
   389             		{
       
   390             		AddEAPSettingL( aField, aPtrTag );
       
   391             		}
       
   392             	else
       
   393             		{            		
       
   394             		CLOG_WRITE_FORMAT( "! Warning: Unhandled setting for WLAN: %d", aField );
       
   395             		}
       
   396                 break;
       
   397             }//switch
       
   398     }
       
   399      
       
   400      
       
   401 // ---------------------------------------------------------
       
   402 // CProcessorWlan::ProcessAPL
       
   403 // ---------------------------------------------------------
       
   404 //
       
   405 void CProcessorWlan::ProcessAPL()
       
   406     {
       
   407     
       
   408     RCmConnectionMethodExt& iPlugin = GetLastPluginL();
       
   409     
       
   410     if( iIsProtected )
       
   411         {
       
   412         iPlugin.SetBoolAttributeL( ECmProtected, ETrue );
       
   413         }
       
   414     
       
   415     // Ensure that Easy WLAN is always an open network
       
   416     if( iIsEasyWlan )
       
   417         {
       
   418         iSecurityMode = ESecurityModeOpen;
       
   419         }
       
   420         
       
   421     FillSecurityInfoL();        
       
   422     
       
   423     // Writes into the log file.
       
   424     DoLogL();
       
   425     
       
   426     Reset(); // iWepData, iWpaData
       
   427     }
       
   428     
       
   429 // ---------------------------------------------------------
       
   430 // CProcessorWlan::ProcessAPL
       
   431 // ---------------------------------------------------------
       
   432 //
       
   433 void CProcessorWlan::FillSecurityInfoL()
       
   434     {
       
   435     //Set Security mode settings
       
   436     switch ( iSecurityMode )
       
   437         {
       
   438         case ESecurityModeWEP:
       
   439             if ( WEPFieldValidate() )
       
   440                 {
       
   441                 FillSecurityInfoL( ETrue ); //WEP
       
   442                 }
       
   443             else
       
   444                 {
       
   445                 CLOG_WRITE( "! Error : WEP settings are not valid." )
       
   446                 }
       
   447             break;  
       
   448         case ESecurityMode802:
       
   449         case ESecurityModeWPA:
       
   450         case ESecurityModeWPA2:
       
   451             {
       
   452             FillSecurityInfoL( EFalse ); //WPA
       
   453             break;
       
   454             }
       
   455         default:
       
   456             {
       
   457             }
       
   458             break;
       
   459         }
       
   460     }    
       
   461 
       
   462 // ---------------------------------------------------------
       
   463 // CProcessorWlan::ProcessAPL
       
   464 // ---------------------------------------------------------
       
   465 //
       
   466 void CProcessorWlan::FillSecurityInfoL( TBool aIsWep )
       
   467     {
       
   468     // iName has been deleted by Base. Name is retrieved from name array.
       
   469     TInt lastPos = iPluginArray->Count() - 1;
       
   470     HBufC* name = (*iPluginName)[ lastPos ];
       
   471     
       
   472     // Name appended to the array
       
   473     iSecurityInfo->Append( name->AllocL() );
       
   474     CLOG_WRITE_FORMAT( "FillSecurityInfoL %S", name );
       
   475     CLOG_WRITE_FORMAT( "FillSecurityInfoL start %d", iSecurityInfo->Count() );
       
   476     
       
   477     if( aIsWep )
       
   478         {
       
   479         // Security type appended to the array
       
   480         iSecurityInfo->Append( KStrWEP.operator const TDesC16&().Alloc() );
       
   481         for( TInt i( 0 ); i < KWEPKeyNumOfFields; i++ )
       
   482             {
       
   483             
       
   484             if( iWepData[i] != NULL )
       
   485                 {
       
   486                 CLOG_WRITE_FORMAT( "wep info %S", iWepData[i] );
       
   487                 }
       
   488             else
       
   489                 {
       
   490                 CLOG_WRITE( "wep info NULL" );
       
   491                 }
       
   492             iSecurityInfo->Append( iWepData[i] );
       
   493             }
       
   494         }
       
   495     else
       
   496         {
       
   497         // Security type appended to the array
       
   498         switch ( iSecurityMode )
       
   499             {
       
   500             case ESecurityMode802:
       
   501                 iSecurityInfo->Append( KStr802_1x.operator const TDesC16&().Alloc() );
       
   502             break;            
       
   503             case ESecurityModeWPA2:
       
   504                 iSecurityInfo->Append( KStrWPA2.operator const TDesC16&().Alloc() );
       
   505             break;            
       
   506             default:
       
   507                 iSecurityInfo->Append( KStrWPA.operator const TDesC16&().Alloc() );
       
   508             break;            
       
   509             }
       
   510 
       
   511         for( TInt i( 0 ); i < KWPAKeyNumOfFields; i++ )
       
   512             {
       
   513             
       
   514             if( iWpaData[i] != NULL )
       
   515                 {
       
   516                 CLOG_WRITE_FORMAT( "wpa info %S", iWpaData[i] );
       
   517                 }
       
   518             else
       
   519                 {
       
   520                 CLOG_WRITE( "wep info NULL" );
       
   521                 }
       
   522             iSecurityInfo->Append( iWpaData[ i ] );
       
   523             }
       
   524         }
       
   525 
       
   526     CLOG_WRITE_FORMAT( "FillSecurityInfoL end %d", iSecurityInfo->Count() );
       
   527     }    
       
   528 
       
   529 // ---------------------------------------------------------
       
   530 // CProcessorWlan::SaveSecurityInfoL
       
   531 // ---------------------------------------------------------
       
   532 //
       
   533 void CProcessorWlan::SaveSecurityInfoL()
       
   534     {
       
   535     TInt i(0);
       
   536 
       
   537     while( i < iSecurityInfo->Count() )
       
   538         {
       
   539         if( (*iSecurityInfo)[i] != NULL )
       
   540             {
       
   541             CLOG_WRITE_FORMAT( "Sec Info: %S", (*iSecurityInfo)[i] );
       
   542             }
       
   543         else
       
   544             {
       
   545             CLOG_WRITE( "Sec Info: NULL" );
       
   546             }
       
   547         
       
   548         i++;
       
   549         }
       
   550 
       
   551 
       
   552     i = 0;
       
   553 
       
   554     while( i < iSecurityInfo->Count() )
       
   555         {
       
   556         CLOG_WRITE_FORMAT( "SaveSecurityInfoL %S", (*iSecurityInfo)[i] );
       
   557 
       
   558         TInt id = GetPluginIdL( (*iSecurityInfo)[i] );
       
   559         if( id != KErrNotFound )
       
   560             {
       
   561             i++;
       
   562             SaveSecurityInfoL( i, id );
       
   563             }
       
   564         else
       
   565             {
       
   566             CLOG_WRITE_FORMAT( "WLan IAp cannot find %S", (*iSecurityInfo)[i] );
       
   567             CLOG_WRITE( "Security save likely collapsed" );
       
   568             // Tries to look for an existing IAP.
       
   569             i++;
       
   570             }    
       
   571         }
       
   572 
       
   573 	// EAP settings
       
   574 	CLOG_WRITE( "Starting EAP settings saving" );
       
   575 	CMDBSession* session = CMDBSession::NewL( CMDBSession::LatestVersion() );
       
   576     CleanupStack::PushL( session );
       
   577     
       
   578     // Load IAP record in order to get the service id
       
   579 	for ( i = 0; i < iEapSettings.Count() ; i++ )
       
   580         {
       
   581         CEapTypeElement* eap = iEapSettings[i];
       
   582         // 
       
   583         TInt id = GetPluginIdL( eap->iName );
       
   584         
       
   585 	    CCDIAPRecord* iapRecord = static_cast< CCDIAPRecord * >
       
   586 	                        ( CCDRecordBase::RecordFactoryL( KCDTIdIAPRecord ) );
       
   587 	                        
       
   588 	    CleanupStack::PushL( iapRecord );
       
   589 	    
       
   590 	    iapRecord->SetRecordId( id );
       
   591 	    
       
   592 	    iapRecord->LoadL( *session );
       
   593 	   
       
   594 	    TInt serviceId = iapRecord->iService;
       
   595 	    
       
   596 	    CleanupStack::PopAndDestroy( iapRecord );	        
       
   597 	            
       
   598         CEapType* eapType ( NULL );
       
   599         TRAPD( leave, 
       
   600                eapType = CEapType::NewL( ELan, 
       
   601                                          serviceId, 
       
   602                                          eap->iEapSettings->iEAPExpandedType ) );
       
   603         if ( leave == KErrNone )
       
   604             {
       
   605             CleanupStack::PushL( eapType );
       
   606             
       
   607             // Inner EAP
       
   608             if ( eap->iEncapsulatingEapId != *EapExpandedTypeNone.GetType() )
       
   609                 {
       
   610                 eapType->SetTunnelingType( eap->iEncapsulatingEapId );
       
   611                 }
       
   612                     
       
   613             // write EAP setting
       
   614             eapType->SetConfigurationL(*eap->iEapSettings);
       
   615             CleanupStack::PopAndDestroy( eapType );
       
   616             }
       
   617         }
       
   618     
       
   619     session->Close();
       
   620     CleanupStack::PopAndDestroy( session );
       
   621     CLOG_WRITE( "Finished EAP settings saving" );
       
   622 
       
   623     CLOG_WRITE_FORMAT( "SaveSecurityInfoL end %d", iSecurityInfo->Count() );
       
   624 }
       
   625 
       
   626 // ---------------------------------------------------------
       
   627 // CProcessorWlan::SaveSecurityInfoL
       
   628 // ---------------------------------------------------------
       
   629 //
       
   630 void CProcessorWlan::SaveSecurityInfoL( TInt& aCounter, TInt aId )
       
   631     {
       
   632     if( (*iSecurityInfo)[ aCounter ]->Compare( KStrWEP ) == 0 )
       
   633         {
       
   634         aCounter++;
       
   635         TInt end( aCounter + KWEPKeyNumOfFields );
       
   636         
       
   637         for( TInt index(0); aCounter < end; aCounter++, index++ )
       
   638             {
       
   639             if( (*iSecurityInfo)[ aCounter ] != NULL )
       
   640                 {
       
   641                 CLOG_WRITE_FORMAT( "wep info %S", (*iSecurityInfo)[ aCounter ] );
       
   642                 }
       
   643             else
       
   644                 {
       
   645                 CLOG_WRITE( "wep info NULL" );
       
   646                 }
       
   647             iWepData[ index] = (*iSecurityInfo)[ aCounter ] ;
       
   648             }
       
   649         SaveWEPL( aId );
       
   650         }
       
   651     else
       
   652         {
       
   653         
       
   654         // Set security mode.        
       
   655         if ( (*iSecurityInfo)[ aCounter ]->CompareF( KStr802_1x ) == 0 )
       
   656             {
       
   657             // 802.1x
       
   658             iSecurityMode = ESecurityMode802;
       
   659             }
       
   660         else if ( (*iSecurityInfo)[ aCounter ]->CompareF( KStrWPA2 ) == 0 )
       
   661             {
       
   662             // WPA2 mode
       
   663             iSecurityMode = ESecurityModeWPA2;
       
   664             }
       
   665         else 
       
   666             {
       
   667             // WPA
       
   668             iSecurityMode = ESecurityModeWPA;
       
   669             }
       
   670 
       
   671         aCounter++;
       
   672         TInt end( aCounter + KWPAKeyNumOfFields );
       
   673         
       
   674         for( TInt index(0); aCounter < end; aCounter++, index++ )
       
   675             {
       
   676             if( (*iSecurityInfo)[ aCounter ] != NULL )
       
   677                 {
       
   678                 CLOG_WRITE_FORMAT( "wpa info %S", (*iSecurityInfo)[ aCounter ] );
       
   679                 }
       
   680             else
       
   681                 {
       
   682                 CLOG_WRITE( "wpa info NULL" );
       
   683                 }
       
   684             iWpaData[ index ] = (*iSecurityInfo)[ aCounter ] ;
       
   685             }
       
   686         SaveWPAL( aId );
       
   687         }
       
   688     }
       
   689 
       
   690 
       
   691      
       
   692 // ---------------------------------------------------------
       
   693 // WEP Security settings
       
   694 // ---------------------------------------------------------     
       
   695 
       
   696 // ---------------------------------------------------------
       
   697 // CProcessorWlan::SaveWEPL
       
   698 // ---------------------------------------------------------
       
   699 //
       
   700 void CProcessorWlan::SaveWEPL( TUint32 aIapId ) 
       
   701     {
       
   702     CMDBSession* session = CMDBSession::NewL( CMDBSession::LatestVersion() );
       
   703     CleanupStack::PushL( session );
       
   704     // Load IAP record
       
   705     CCDIAPRecord* iapRecord = static_cast< CCDIAPRecord * >
       
   706                         ( CCDRecordBase::RecordFactoryL( KCDTIdIAPRecord ) );
       
   707     CleanupStack::PushL( iapRecord );
       
   708     iapRecord->SetRecordId( aIapId );
       
   709     iapRecord->LoadL( *session );
       
   710    
       
   711     // Load WLAN service table
       
   712     // first get WLAN table id
       
   713     CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*>
       
   714         ( CCDRecordBase::RecordFactoryL( 0 ) );
       
   715     CleanupStack::PushL( generic );    
       
   716     generic->InitializeL( TPtrC( WLAN_SERVICE ), NULL );
       
   717     generic->LoadL( *session );
       
   718     TMDBElementId wlanTableId = generic->TableId();
       
   719     
       
   720     CMDBField<TUint32>* sidField = static_cast<CMDBField<TUint32>*>
       
   721                              ( generic->GetFieldByIdL( KCDTIdWlanServiceId ) );
       
   722     
       
   723     TInt service = iapRecord->iService;
       
   724     // prime with service id                
       
   725     *sidField = (TUint32)service;
       
   726        
       
   727     User::LeaveIfError( generic->FindL( *session ) );
       
   728 
       
   729     // Save index of key in use
       
   730     TUint32 keyInUse( WEPKeyInUse() );
       
   731     CMDBField<TUint>* keyInUseField = static_cast<CMDBField<TUint>*>
       
   732                             ( generic->GetFieldByIdL( KCDTIdWlanWepIndex ) );
       
   733     keyInUseField->SetL( keyInUse );
       
   734     
       
   735     // Save authentication mode
       
   736     TUint32 auth( WEPAuthentication() );
       
   737     CMDBField<TUint>* authenticationField = static_cast<CMDBField<TUint>*>
       
   738                             ( generic->GetFieldByIdL( KCDTIdWlanAuthMode ) );
       
   739     authenticationField->SetL( auth );
       
   740     
       
   741     // Save WEP keys and key formats  
       
   742     if ( WEPFieldData( EWEPKey1Data )->Length() )
       
   743         {
       
   744         CMDBField<TDesC8>* wepKey1Field = static_cast<CMDBField<TDesC8>*>
       
   745                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey1 ) );
       
   746         WriteKeyL( wepKey1Field,
       
   747                    WEPFieldData( EWEPKey1Data ),
       
   748                    WEPKeyFormat( EWEPKey1Format ) );
       
   749         CMDBField<TUint>* formatKey1Field = static_cast<CMDBField<TUint>*>
       
   750                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey1 ) );
       
   751         formatKey1Field->SetL( WEPKeyFormat( EWEPKey1Format ) );
       
   752         }
       
   753     if ( WEPFieldData( EWEPKey2Data )->Length() )
       
   754         {
       
   755         CMDBField<TDesC8>* wepKey2Field = static_cast<CMDBField<TDesC8>*>
       
   756                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey2 ) );
       
   757         WriteKeyL( wepKey2Field,
       
   758                    WEPFieldData( EWEPKey2Data ),
       
   759                    WEPKeyFormat( EWEPKey2Format ) );
       
   760         CMDBField<TUint>* formatKey2Field = static_cast<CMDBField<TUint>*>
       
   761                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey2 ) );
       
   762         formatKey2Field->SetL( WEPKeyFormat( EWEPKey2Format ) );
       
   763         }
       
   764     if ( WEPFieldData( EWEPKey3Data )->Length() )
       
   765         {
       
   766         CMDBField<TDesC8>* wepKey3Field = static_cast<CMDBField<TDesC8>*>
       
   767                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey3 ) );
       
   768         WriteKeyL( wepKey3Field,
       
   769                    WEPFieldData( EWEPKey3Data ),
       
   770                    WEPKeyFormat( EWEPKey3Format ) );
       
   771         CMDBField<TUint>* formatKey3Field = static_cast<CMDBField<TUint>*>
       
   772                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey3 ) );
       
   773         formatKey3Field->SetL( WEPKeyFormat( EWEPKey3Format ) );
       
   774         }
       
   775     if ( WEPFieldData( EWEPKey4Data )->Length() )
       
   776         {
       
   777         CMDBField<TDesC8>* wepKey4Field = static_cast<CMDBField<TDesC8>*>
       
   778                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey4 ) );
       
   779         WriteKeyL( wepKey4Field,
       
   780                    WEPFieldData( EWEPKey4Data ),
       
   781                    WEPKeyFormat( EWEPKey4Format ) );
       
   782         CMDBField<TUint>* formatKey4Field = static_cast<CMDBField<TUint>*>
       
   783                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey4 ) );
       
   784         formatKey4Field->SetL( WEPKeyFormat( EWEPKey4Format ) );
       
   785         }
       
   786     
       
   787     generic->ModifyL( *session );
       
   788 
       
   789     CleanupStack::PopAndDestroy( generic ); // generic
       
   790     CleanupStack::PopAndDestroy( iapRecord ); // iapRecord
       
   791     CleanupStack::PopAndDestroy( session ); // session
       
   792     }
       
   793     
       
   794 
       
   795 // ---------------------------------------------------------
       
   796 // CProcessorWlan::WriteKeyL
       
   797 // ---------------------------------------------------------
       
   798 //
       
   799 void CProcessorWlan::WriteKeyL( CMDBField<TDesC8>* aKeyField,                                
       
   800                                 HBufC16* aKey,
       
   801                                 const TInt aKeyFormat ) 
       
   802     {
       
   803     TBuf8<KMaxLengthOfKeyData> key;
       
   804     
       
   805     //convert to 8 bit
       
   806     key.Copy( aKey->Des() );
       
   807     
       
   808     if ( aKeyFormat == EAscii )
       
   809         {
       
   810         // Must be converted to hexa and stored as a hexa
       
   811         // Ascii key is half the length of Hex
       
   812         HBufC8* buf8Conv = HBufC8::NewLC( key.Length() * KAsciiUnicodeRatio );
       
   813         ConvertAsciiToHex( key, buf8Conv );
       
   814         aKeyField->SetL( buf8Conv->Des() );
       
   815         CleanupStack::PopAndDestroy( buf8Conv );
       
   816         }
       
   817     else if ( VerifyHex( key ) )
       
   818         {
       
   819         //already in hexa format
       
   820         aKeyField->SetL( key );    
       
   821         }
       
   822     else
       
   823         {
       
   824         CLOG_WRITE( "! Error : Invalid hexadecimal format" )
       
   825         }
       
   826     }
       
   827     
       
   828 // ---------------------------------------------------------
       
   829 // CProcessorWlan::WEPFieldData
       
   830 // ---------------------------------------------------------
       
   831 //
       
   832 HBufC16* CProcessorWlan::WEPFieldData( TDbCreatorWEPFields aFieldId ) 
       
   833     {
       
   834     TInt index = WEPIndex( aFieldId );
       
   835     if( iWepData[ index ] == NULL )
       
   836         {
       
   837         return iEmptyTag;
       
   838         }
       
   839     else
       
   840         {
       
   841         return iWepData[ index ];
       
   842         }
       
   843     }
       
   844     
       
   845 // ---------------------------------------------------------
       
   846 // CProcessorWlan::WEPAuthentication
       
   847 // ---------------------------------------------------------
       
   848 //   
       
   849 TInt CProcessorWlan::WEPAuthentication()
       
   850     {
       
   851     HBufC16* authTypeStr = WEPFieldData( EWEPAuthType );
       
   852     TInt authType ( EAuthOpen ) ;
       
   853     
       
   854     _LIT16( KStrOpen,   "Open" );  
       
   855     _LIT16( KStrShared, "Shared" );
       
   856     
       
   857     if ( authTypeStr->CompareF( KStrOpen ) == 0 )
       
   858         {
       
   859         //CLOG_WRITE( "Authentication type : Open" )
       
   860         }
       
   861     else if ( authTypeStr->CompareF( KStrShared ) == 0 )
       
   862         {
       
   863         //CLOG_WRITE( "Authentication type : Shared" )
       
   864         authType = EAuthShared;
       
   865         }
       
   866     else 
       
   867         {
       
   868         //aField is either empty or invalid
       
   869         authType = KErrNotFound;
       
   870         }
       
   871         
       
   872     return authType;
       
   873     }
       
   874 
       
   875 // ---------------------------------------------------------
       
   876 // CProcessorWlan::WEPKeyInUse
       
   877 // ---------------------------------------------------------
       
   878 //
       
   879 TInt CProcessorWlan::WEPKeyInUse()
       
   880     {  
       
   881     HBufC16* keyStr = WEPFieldData( EWEPKeyInUse );
       
   882     TInt key ( EKeyNumber1 ) ;
       
   883     
       
   884     _LIT16( KStrKey1,   "key1" );  
       
   885     _LIT16( KStrKey2,   "key2" );
       
   886     _LIT16( KStrKey3,   "key3" );
       
   887     _LIT16( KStrKey4,   "key4" );
       
   888     
       
   889     if ( keyStr->CompareF( KStrKey1 ) == 0 )
       
   890         {
       
   891         //CLOG_WRITE( "WEP key in use : key 1" )
       
   892         }
       
   893     else if ( keyStr->CompareF( KStrKey2 ) == 0 )
       
   894         {
       
   895         //CLOG_WRITE( "WEP key in use : key 2" )
       
   896         key = EKeyNumber2;
       
   897         }
       
   898     else if ( keyStr->CompareF( KStrKey3 ) == 0 )
       
   899         {
       
   900         //CLOG_WRITE( "WEP key in use : key 3" )
       
   901         key = EKeyNumber3;
       
   902         }
       
   903     else if ( keyStr->CompareF( KStrKey4 ) == 0 )
       
   904         {
       
   905         //CLOG_WRITE( "WEP key in use : key 4" )
       
   906         key = EKeyNumber4;
       
   907         }
       
   908     else 
       
   909         {
       
   910         //aField is either empty or invalid
       
   911         key = KErrNotFound;
       
   912         }
       
   913         
       
   914     return key;
       
   915     }
       
   916 
       
   917 
       
   918     
       
   919 // ---------------------------------------------------------
       
   920 // CProcessorWlan::WEPKeyFormat
       
   921 // ---------------------------------------------------------
       
   922 // 
       
   923 TInt CProcessorWlan::WEPKeyFormat(  TDbCreatorWEPFields aFieldId  )
       
   924     {
       
   925     __ASSERT_ALWAYS( ( aFieldId == EWEPKey1Format || 
       
   926                        aFieldId == EWEPKey2Format ||
       
   927                        aFieldId == EWEPKey3Format ||
       
   928                        aFieldId == EWEPKey4Format ),
       
   929                      User::Panic ( KPanicOutOfRange, KErrOutOfRange ) );
       
   930                     
       
   931     HBufC16* keyFormatStr = WEPFieldData( aFieldId );
       
   932     TWEPKeyFormat keyFormat ( EAscii ) ;
       
   933     
       
   934     _LIT16( KStrAscii,       "Ascii" );  
       
   935     _LIT16( KStrHexadecimal, "Hexadecimal" );
       
   936     
       
   937     if ( keyFormatStr->CompareF( KStrAscii ) == 0 )
       
   938         {
       
   939         //CLOG_WRITE( "Key format : Ascii" )
       
   940         }
       
   941     else if ( keyFormatStr->CompareF( KStrHexadecimal ) == 0 )
       
   942         {
       
   943         //CLOG_WRITE( "Key format : Hexadecimal" )
       
   944         keyFormat = EHexadecimal;
       
   945         }
       
   946     else 
       
   947         {
       
   948         CLOG_WRITE( "! Error : Invalid key format. Default:Ascii" )
       
   949         }
       
   950         
       
   951     return keyFormat;
       
   952     }
       
   953     
       
   954 // ---------------------------------------------------------
       
   955 // CProcessorWlan::WEPKeyLength
       
   956 // ---------------------------------------------------------
       
   957 // 
       
   958 TWEPKeyLength CProcessorWlan::WEPKeyLength(  TDbCreatorWEPFields aFieldId  )
       
   959     {
       
   960     __ASSERT_ALWAYS( ( aFieldId == EWEPKey1Length || 
       
   961                        aFieldId == EWEPKey2Length ||
       
   962                        aFieldId == EWEPKey3Length ||
       
   963                        aFieldId == EWEPKey4Length ),
       
   964                      User::Panic ( KPanicOutOfRange, KErrOutOfRange ) );
       
   965                     
       
   966     HBufC16* keyLengthStr = WEPFieldData( aFieldId );
       
   967     TWEPKeyLength keyLen ( E40Bits ) ;
       
   968     
       
   969     _LIT16( KStr64,       "64" );  
       
   970     _LIT16( KStr128,      "128" );
       
   971     _LIT16( KStr256,      "256" );
       
   972     
       
   973     if ( keyLengthStr->CompareF( KStr64 ) == 0 )
       
   974         {
       
   975         //CLOG_WRITE( "Key length : 64" )
       
   976         }
       
   977     else if ( keyLengthStr->CompareF( KStr128 ) == 0 )
       
   978         {
       
   979         //CLOG_WRITE( "Key length : 128" )
       
   980         keyLen = E104Bits;
       
   981         }
       
   982     else if ( keyLengthStr->CompareF( KStr256 ) == 0 )
       
   983         {
       
   984         //CLOG_WRITE( "Key length : 256" )
       
   985         keyLen = E232Bits;
       
   986         }
       
   987     else 
       
   988         {
       
   989         CLOG_WRITE( "! Error : Invalid key length. Default:64" )
       
   990         }
       
   991         
       
   992     return keyLen;
       
   993     }
       
   994     
       
   995 // ---------------------------------------------------------
       
   996 // CProcessorWlan::WEPKeyValidLen
       
   997 // ---------------------------------------------------------
       
   998 //     
       
   999 TInt CProcessorWlan::WEPKeyValidLen(TInt aFormat , TWEPKeyLength aLen )
       
  1000     {
       
  1001     __ASSERT_ALWAYS( aFormat == EAscii || aFormat == EHexadecimal, 
       
  1002                      User::Panic ( KPanicOutOfRange, KErrOutOfRange ) );
       
  1003                      
       
  1004     __ASSERT_ALWAYS( aLen == E40Bits || aLen == E104Bits || aLen == E232Bits,
       
  1005                      User::Panic ( KPanicOutOfRange, KErrOutOfRange ) );
       
  1006                      
       
  1007     TInt len( 0 );
       
  1008     
       
  1009     switch ( aFormat )
       
  1010         {
       
  1011         case EAscii:
       
  1012             switch ( aLen )
       
  1013                 {
       
  1014                 case E40Bits :  len = KKeyDataLength40Bits /
       
  1015                                                         KAsciiUnicodeRatio;
       
  1016                     break;
       
  1017                 case E104Bits : len = KKeyDataLength104Bits /
       
  1018                                                         KAsciiUnicodeRatio;
       
  1019                     break;
       
  1020                 case E232Bits : len = KKeyDataLength232Bits /
       
  1021                                                         KAsciiUnicodeRatio;  
       
  1022                 }
       
  1023             break;
       
  1024         case EHexadecimal:
       
  1025             switch ( aLen )
       
  1026                 {
       
  1027                 case E40Bits :  len = KKeyDataLength40Bits;
       
  1028                     break;
       
  1029                 case E104Bits : len = KKeyDataLength104Bits;
       
  1030                     break;
       
  1031                 case E232Bits : len = KKeyDataLength232Bits;
       
  1032                 }
       
  1033         }
       
  1034         
       
  1035     return len;
       
  1036     }
       
  1037 
       
  1038 // ---------------------------------------------------------
       
  1039 // CProcessorWlan::WEPIndex
       
  1040 // ---------------------------------------------------------
       
  1041 //       
       
  1042 TInt CProcessorWlan::WEPIndex( TDbCreatorWEPFields aFieldId )
       
  1043     {
       
  1044     __ASSERT_ALWAYS( aFieldId >= EWEPKeyInUse && aFieldId <= EWEPKey4Data, 
       
  1045                      User::Panic ( KPanicOutOfRange, KErrOutOfRange ) );
       
  1046                      
       
  1047     return aFieldId - 0x1000 + iDataStart;                     
       
  1048                      
       
  1049     ////return iWEPIndex[ aFieldId - 0x1000 ];
       
  1050     }
       
  1051 
       
  1052 // ---------------------------------------------------------
       
  1053 // CProcessorWlan::WEPFieldValidate
       
  1054 // ---------------------------------------------------------
       
  1055 //   
       
  1056 TBool CProcessorWlan::WEPFieldValidate()
       
  1057     {
       
  1058     TBool valid (ETrue);
       
  1059     
       
  1060     if ( ( WEPAuthentication() == KErrNotFound ) ||
       
  1061          ( WEPKeyInUse() == KErrNotFound ) )
       
  1062         {
       
  1063         valid = EFalse;
       
  1064         }
       
  1065     else
       
  1066         {
       
  1067         //gets the actual keylength
       
  1068         TInt keyLen[ KMaxNumberofKeys ] = { 0,0,0,0 };
       
  1069        
       
  1070         keyLen[EKeyNumber1] = WEPFieldData( EWEPKey1Data )->Length();
       
  1071         keyLen[EKeyNumber2] = WEPFieldData( EWEPKey2Data )->Length();
       
  1072         keyLen[EKeyNumber3] = WEPFieldData( EWEPKey3Data )->Length();
       
  1073         keyLen[EKeyNumber4] = WEPFieldData( EWEPKey4Data )->Length();
       
  1074 
       
  1075 
       
  1076         //check validity of key1 length
       
  1077         TInt validLen = WEPKeyValidLen( WEPKeyFormat( EWEPKey1Format ), 
       
  1078                                         WEPKeyLength( EWEPKey1Length ) );
       
  1079         if ( keyLen[EKeyNumber1] && keyLen[EKeyNumber1] != validLen) 
       
  1080             {
       
  1081             valid = EFalse;
       
  1082             CLOG_WRITE_FORMAT( "! Error : Key1 length is invalid %d", 
       
  1083                                         keyLen[EKeyNumber1] );
       
  1084             CLOG_WRITE_FORMAT( "ValidLen1: %d \n", validLen );
       
  1085             }
       
  1086         else if ( keyLen[EKeyNumber2] )
       
  1087             {    
       
  1088             //check validity of key2 length
       
  1089             validLen = WEPKeyValidLen( WEPKeyFormat( EWEPKey2Format ), 
       
  1090                                        WEPKeyLength( EWEPKey2Length ) );
       
  1091             if ( keyLen[EKeyNumber2] != validLen )
       
  1092                 {
       
  1093                 valid = EFalse;
       
  1094                 CLOG_WRITE_FORMAT( "! Error : Key2 length is invalid %d", 
       
  1095                                             keyLen[EKeyNumber2] )
       
  1096                 CLOG_WRITE_FORMAT( "ValidLen2: %d \n", validLen );
       
  1097                 }
       
  1098             else if ( keyLen[EKeyNumber3] )
       
  1099                 {
       
  1100                 //check validity of key3 length
       
  1101                 validLen = WEPKeyValidLen( WEPKeyFormat( EWEPKey3Format ), 
       
  1102                                            WEPKeyLength( EWEPKey3Length ) );
       
  1103                 if ( keyLen[EKeyNumber3] != validLen )
       
  1104                     {
       
  1105                     valid = EFalse;
       
  1106                     CLOG_WRITE_FORMAT( "! Error : Key3 length is invalid %d", 
       
  1107                                                 keyLen[EKeyNumber3] );
       
  1108                     CLOG_WRITE_FORMAT( "ValidLen3: %d \n", validLen );
       
  1109                     }
       
  1110                 else if ( keyLen[EKeyNumber4] )
       
  1111                     {
       
  1112                     //check validity of key4 length
       
  1113                     validLen = WEPKeyValidLen( WEPKeyFormat( EWEPKey4Format ), 
       
  1114                                            WEPKeyLength( EWEPKey4Length ) );
       
  1115                     if ( keyLen[EKeyNumber4] != validLen )
       
  1116                         {
       
  1117                         valid = EFalse;
       
  1118                         CLOG_WRITE_FORMAT( "! Error : Key4 length is invalid %d", 
       
  1119                                                     keyLen[EKeyNumber4] );
       
  1120                         CLOG_WRITE_FORMAT( "ValidLen4: %d \n", validLen );
       
  1121                         }//if
       
  1122                     }//else                
       
  1123                 }//else
       
  1124             }//else
       
  1125         }//else
       
  1126         
       
  1127     return valid;
       
  1128     }
       
  1129 
       
  1130 //----------------------------------------------------------
       
  1131 // CProcessorWlan::ConvertAsciiToHex
       
  1132 //----------------------------------------------------------
       
  1133 //
       
  1134 void CProcessorWlan::ConvertAsciiToHex( const TDesC8& aSource, 
       
  1135                                               HBufC8*& aDest )
       
  1136 	{
       
  1137 	_LIT( hex, "0123456789ABCDEF" );
       
  1138 	TInt size = aSource.Size();
       
  1139 	TPtr8 ptr = aDest->Des();
       
  1140 	for ( TInt ii = 0; ii < size; ii++ )
       
  1141 		{
       
  1142 		TText8 ch = aSource[ii];
       
  1143 		ptr.Append( hex()[(ch/16)&0x0f] );
       
  1144 		ptr.Append( hex()[ch&0x0f] );
       
  1145 		}
       
  1146 	}
       
  1147 		
       
  1148 //----------------------------------------------------------
       
  1149 // CWEPSecuritySettingsDlg::VerifyHex
       
  1150 //----------------------------------------------------------
       
  1151 //
       
  1152 TBool CProcessorWlan::VerifyHex( const TDesC8& aHex )
       
  1153     {
       
  1154     TBool err( ETrue );
       
  1155     
       
  1156     for ( TInt i = 0; i < aHex.Length(); i++ )
       
  1157         {
       
  1158         TChar c( aHex[i] );
       
  1159 
       
  1160         if ( !c.IsHexDigit() ) 
       
  1161             {
       
  1162             err = EFalse;
       
  1163             break;
       
  1164             }
       
  1165         }
       
  1166 
       
  1167     return err;
       
  1168     }
       
  1169    
       
  1170     
       
  1171 // ---------------------------------------------------------
       
  1172 // WPA Security settings
       
  1173 // ---------------------------------------------------------
       
  1174 
       
  1175 
       
  1176 // ---------------------------------------------------------
       
  1177 // CProcessorWlan::SaveWPAL
       
  1178 // ---------------------------------------------------------
       
  1179 //
       
  1180 void CProcessorWlan::SaveWPAL( TUint32 aIapId )
       
  1181     {
       
  1182     CLOG_WRITE( "CProcessorWlan::SaveWPAL enter" );
       
  1183     
       
  1184     CMDBSession* session = CMDBSession::NewL( CMDBSession::LatestVersion() );
       
  1185     CleanupStack::PushL( session );
       
  1186     
       
  1187     // Load IAP record
       
  1188     CCDIAPRecord* iapRecord = static_cast<CCDIAPRecord *>
       
  1189                         ( CCDRecordBase::RecordFactoryL( KCDTIdIAPRecord ) );
       
  1190     CleanupStack::PushL( iapRecord );
       
  1191     iapRecord->SetRecordId( aIapId );
       
  1192     iapRecord->LoadL( *session );
       
  1193     
       
  1194     // Load WLAN service table
       
  1195     // first get WLAN table id
       
  1196     CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*>
       
  1197         ( CCDRecordBase::RecordFactoryL( 0 ) );
       
  1198     CleanupStack::PushL( generic );
       
  1199         
       
  1200     generic->InitializeL( TPtrC( WLAN_SERVICE ), NULL );
       
  1201     generic->LoadL( *session );
       
  1202     TMDBElementId wlanTableId = generic->TableId();
       
  1203     CMDBField<TUint32>* sidField = static_cast<CMDBField<TUint32>*>
       
  1204                              ( generic->GetFieldByIdL( KCDTIdWlanServiceId ) );
       
  1205     
       
  1206     TInt service = iapRecord->iService;
       
  1207     // prime with service id                
       
  1208     *sidField = (TUint32)service;
       
  1209     
       
  1210     User::LeaveIfError( generic->FindL( *session ) );
       
  1211        
       
  1212     // Set WPA mode
       
  1213     CMDBField<TUint>* enableWpaPskField = static_cast<CMDBField<TUint>*>
       
  1214                             ( generic->GetFieldByIdL( KCDTIdWlanEnableWpaPsk ) );
       
  1215                             
       
  1216     enableWpaPskField->SetL( WPAPresharedKeyInUse() );
       
  1217 	
       
  1218 	CLOG_WRITE( "Wrote enableWpaPskField" );
       
  1219     
       
  1220     // Set security mode
       
  1221     CMDBField<TUint>* secModeField = static_cast<CMDBField<TUint>*>
       
  1222                         ( generic->GetFieldByIdL( KCDTIdWlanSecMode ) );
       
  1223     secModeField->SetL( iSecurityMode );
       
  1224     
       
  1225     CLOG_WRITE( "Wrote securityMode" );
       
  1226 
       
  1227     // Save EAP list
       
  1228     SetExpandedEapListL( service );
       
  1229     CLOG_WRITE( "Wrote Expanded EAPList" );
       
  1230     
       
  1231     // Save PreShared Key
       
  1232     TBuf8<KMaxLengthOfKeyData> keyWPA;
       
  1233     //convert to 8 bit
       
  1234     keyWPA.Copy( WPAFieldData( EWPAPresharedKey )->Des() );
       
  1235     CMDBField<TDesC8>* wpaPskField = static_cast<CMDBField<TDesC8>*>
       
  1236                         ( generic->GetFieldByIdL( KCDTIdWlanWpaPreSharedKey ) );
       
  1237     wpaPskField->SetL( keyWPA );
       
  1238     
       
  1239     CLOG_WRITE( "Wrote pre-shared key" );
       
  1240     if ( keyWPA.Length() < 8 )
       
  1241         {
       
  1242         CLOG_WRITE( "Error: WPA pre-shared key is less then 8 chars." );	        
       
  1243         }
       
  1244 
       
  1245     // Check and save PreShared Key Length
       
  1246     TInt len( WPAKeyLength() );
       
  1247     if ( len != keyWPA.Length() )
       
  1248         {
       
  1249         CLOG_WRITE( "! Error : WPA key lengths do not match" );
       
  1250         }
       
  1251     
       
  1252     CMDBField<TUint>* keyLengthField = static_cast<CMDBField<TUint>*>
       
  1253                         ( generic->GetFieldByIdL( KCDTIdWlanWpaKeyLength ) );
       
  1254     keyLengthField->SetL( len );
       
  1255     
       
  1256     generic->ModifyL( *session );
       
  1257     
       
  1258     CleanupStack::PopAndDestroy( generic ); 
       
  1259     CleanupStack::PopAndDestroy( iapRecord );
       
  1260     CleanupStack::PopAndDestroy( session );
       
  1261     CLOG_WRITE( "CProcessorWlan::SaveWPAL exit" );
       
  1262     }
       
  1263 
       
  1264 // ---------------------------------------------------------
       
  1265 // CProcessorWlan::SetExpandedEapListL
       
  1266 // ---------------------------------------------------------
       
  1267 //
       
  1268 void CProcessorWlan::SetExpandedEapListL( const TUint aServiceId )
       
  1269     {
       
  1270     CLOG_WRITE( "CProcessorWlan::SetExpandedEapListL" )
       
  1271     // Gets the text format eap list
       
  1272     HBufC16* eapList = WPAFieldData( EWPAEapMethod );
       
  1273     
       
  1274     if ( eapList != NULL && 0 < eapList->Length() )
       
  1275         {
       
  1276         // load general EAP settings If
       
  1277         CEapGeneralSettings* eapGs;
       
  1278         eapGs = CEapGeneralSettings::NewL( ELan, aServiceId );
       
  1279         CleanupStack::PushL( eapGs );
       
  1280         
       
  1281         // get lists of enabled/disabled EAPs for the IAP
       
  1282         RArray< TEapExpandedType > enabledEapMethods;
       
  1283         RArray< TEapExpandedType > disabledEapMethods;
       
  1284         
       
  1285         enabledEapMethods.Append( GetExpandedEapTypeIdL( *eapList ) );
       
  1286         
       
  1287         // disabledEapMethods can be empty, SetEapMethods takes care of it,
       
  1288         // only enabledEapMethods is a must with correct contents
       
  1289         User::LeaveIfError( eapGs->SetEapMethods( enabledEapMethods, 
       
  1290                                                      disabledEapMethods ) );
       
  1291    
       
  1292         CleanupStack::PopAndDestroy( eapGs );
       
  1293         }
       
  1294     }
       
  1295 
       
  1296 // ---------------------------------------------------------
       
  1297 // CProcessorWlan::GetExpandedEapTypeId
       
  1298 // ---------------------------------------------------------
       
  1299 //
       
  1300 TEapExpandedType CProcessorWlan::GetExpandedEapTypeIdL( TDesC& aField )
       
  1301     {
       
  1302     TUint8 resultByte;
       
  1303     TLex16 lex( aField.Ptr() );
       
  1304     User::LeaveIfError( lex.Val( resultByte, EDecimal ) );
       
  1305     
       
  1306     CLOG_WRITE_FORMAT( "CProcessorWlan::GetExpandedEapTypeIdL: EAP %d",
       
  1307                     (int)resultByte )
       
  1308     
       
  1309     switch ( resultByte )
       
  1310         {
       
  1311         case 0x06:
       
  1312             {
       
  1313             return *EapExpandedTypeGtc.GetType();
       
  1314             }
       
  1315         case 0x0d:
       
  1316             {
       
  1317             return *EapExpandedTypeTls.GetType();
       
  1318             }
       
  1319         case 0x11:
       
  1320             {
       
  1321             return *EapExpandedTypeLeap.GetType();
       
  1322             }
       
  1323         case 0x12:
       
  1324             {
       
  1325             return *EapExpandedTypeSim.GetType();
       
  1326             }
       
  1327         case 0x15:
       
  1328             {
       
  1329             return *EapExpandedTypeTtls.GetType();
       
  1330             }
       
  1331         case 0x17:
       
  1332             {
       
  1333             return *EapExpandedTypeAka.GetType();
       
  1334             }
       
  1335         case 0x19:
       
  1336             {
       
  1337             return *EapExpandedTypePeap.GetType();
       
  1338             }
       
  1339         case 0x1a:
       
  1340             {
       
  1341             return *EapExpandedTypeMsChapv2.GetType();
       
  1342             }
       
  1343         case 0x2b:
       
  1344             {
       
  1345             return *EapExpandedTypeFast.GetType();
       
  1346             }
       
  1347         case 0x01:
       
  1348             {
       
  1349             return *EapExpandedTypeProtectedSetup.GetType();
       
  1350             }
       
  1351         case 0x62:
       
  1352             {
       
  1353             return *EapExpandedTypeTtlsPap.GetType();
       
  1354             }
       
  1355         case 0x63:
       
  1356             {
       
  1357             return *EapExpandedPlainMsChapv2.GetType();
       
  1358             }
       
  1359         default:
       
  1360             {
       
  1361             return *EapExpandedTypeNone.GetType();
       
  1362             }
       
  1363         }
       
  1364     }
       
  1365 
       
  1366 // ---------------------------------------------------------
       
  1367 // CProcessorWlan::WPAIndex
       
  1368 // ---------------------------------------------------------
       
  1369 //       
       
  1370 TInt CProcessorWlan::WPAIndex( TDbCreatorWPAFields aFieldId )
       
  1371     {
       
  1372     __ASSERT_ALWAYS( aFieldId >= EWPAPresharedKey && aFieldId <= EWPAUseOfPresharedKey, 
       
  1373                      User::Panic ( KPanicOutOfRange, KErrOutOfRange ) );
       
  1374                      
       
  1375     return aFieldId - 0x2000 + iDataStart;                     
       
  1376     }
       
  1377     
       
  1378 // ---------------------------------------------------------
       
  1379 // CProcessorWlan::WPAFieldData
       
  1380 // ---------------------------------------------------------
       
  1381 //
       
  1382 HBufC16* CProcessorWlan::WPAFieldData( TDbCreatorWPAFields aFieldId ) 
       
  1383     {
       
  1384     TInt index = WPAIndex( aFieldId );
       
  1385     if( iWpaData[ index ] == NULL )
       
  1386         {
       
  1387         return iEmptyTag;
       
  1388         }
       
  1389     else
       
  1390         {
       
  1391         return iWpaData[ index ];
       
  1392         }
       
  1393     }
       
  1394     
       
  1395 // ---------------------------------------------------------
       
  1396 // CProcessorWlan::WPAPresharedKeyInUse
       
  1397 // ---------------------------------------------------------
       
  1398 //
       
  1399 TBool CProcessorWlan::WPAPresharedKeyInUse()
       
  1400     {
       
  1401     HBufC16* useStr = WPAFieldData( EWPAUseOfPresharedKey );   
       
  1402 
       
  1403     TBool usePSK ( EFalse ) ;
       
  1404     
       
  1405     if ( useStr->CompareF( KStrYes ) == 0 )
       
  1406         {
       
  1407         CLOG_WRITE( "Preshared key in use" )
       
  1408         usePSK = ETrue;
       
  1409         }
       
  1410     else if ( useStr->CompareF( KStrNo ) == 0 )
       
  1411         {
       
  1412         CLOG_WRITE( "Preshared key not in use" );
       
  1413         }
       
  1414     else 
       
  1415         {
       
  1416         //aField is either empty or invalid
       
  1417         CLOG_WRITE( "! Error : Invalid Use WPA preshared key. Default:No" );
       
  1418         }
       
  1419         
       
  1420     return usePSK;
       
  1421     }
       
  1422     
       
  1423 // ---------------------------------------------------------
       
  1424 // CProcessorWlan::WPAKeyLength
       
  1425 // ---------------------------------------------------------
       
  1426 //
       
  1427 TInt CProcessorWlan::WPAKeyLength() 
       
  1428     {
       
  1429     HBufC16* tag = WPAFieldData( EWPAKeyLength );   
       
  1430     
       
  1431     TInt num( 0 );
       
  1432     TLex parser( tag->Des() );
       
  1433 
       
  1434     if ( parser.Val( num ) != KErrNone )
       
  1435         {
       
  1436         CLOG_WRITE( "! Error : Invalid input : WPA key length" );
       
  1437         }
       
  1438         
       
  1439     return num;
       
  1440     }
       
  1441 
       
  1442 // ---------------------------------------------------------
       
  1443 // CProcessorWlan::AddSecurityDataL
       
  1444 // ---------------------------------------------------------
       
  1445 //   
       
  1446 void CProcessorWlan::AddSecurityDataL( TInt aField, HBufC* aPtrTag, TBool aIsWep )
       
  1447     {
       
  1448     if( aIsWep )
       
  1449         {
       
  1450         iWepData[ WEPIndex( (TDbCreatorWEPFields)aField ) ] = aPtrTag->AllocL();
       
  1451         ////iWepData.Insert( aPtrTag->AllocL(), WEPIndex( (TDbCreatorWEPFields)aField ) );
       
  1452         }
       
  1453     else    
       
  1454         {
       
  1455         iWpaData[ WPAIndex( (TDbCreatorWPAFields)aField ) ] = aPtrTag->AllocL();
       
  1456         ////iWpaData.Insert( aPtrTag->AllocL(), WPAIndex( (TDbCreatorWPAFields)aField ) );
       
  1457         }
       
  1458     }        
       
  1459         
       
  1460 // ---------------------------------------------------------
       
  1461 // CProcessorWlan::DoLogL
       
  1462 // ---------------------------------------------------------
       
  1463 //
       
  1464 void CProcessorWlan::DoLogL()
       
  1465     {
       
  1466     // Writes some data of the actual WLAN access point into the log file.
       
  1467     HBufC16* tmp;
       
  1468     RCmConnectionMethodExt& plugin = GetLastPluginL();
       
  1469 
       
  1470     // Writes some data of the Internet acces point into the log file.
       
  1471     if ( iIsEasyWlan )
       
  1472         {
       
  1473         CLOG_WRITE( "Easy WLAN Access Point created:" )
       
  1474         }
       
  1475     else
       
  1476         {
       
  1477         CLOG_WRITE( "WLAN Access Point created:" )
       
  1478         }
       
  1479         
       
  1480     CLOG_WRITE_FORMAT( "\t Connection name in array: %S ", 
       
  1481                         (*iPluginName)[ PluginCount() - 1] );  
       
  1482         
       
  1483     tmp = plugin.GetStringAttributeL( ECmName );
       
  1484     if( tmp )
       
  1485         {
       
  1486         CleanupStack::PushL( tmp );
       
  1487         CLOG_WRITE_FORMAT( "\t Connection name: %S ", tmp )
       
  1488         CleanupStack::PopAndDestroy( tmp );
       
  1489         }
       
  1490 
       
  1491     // For the WLAN network name
       
  1492     tmp = plugin.GetStringAttributeL( EWlanSSID );
       
  1493     if( tmp )
       
  1494         {
       
  1495         CleanupStack::PushL( tmp );
       
  1496         CLOG_WRITE_FORMAT( "\t Network name: %S", tmp )
       
  1497         CleanupStack::PopAndDestroy( tmp );
       
  1498         }
       
  1499     CLOG_WRITE( "\t \r\n" )
       
  1500     }
       
  1501 
       
  1502 
       
  1503 // ---------------------------------------------------------
       
  1504 // CProcessorWlan::Reset
       
  1505 // ---------------------------------------------------------
       
  1506 //
       
  1507 void CProcessorWlan::Reset()
       
  1508     {
       
  1509     for( TInt i = 0; i < KWEPKeyNumOfFields; i++ )
       
  1510         {
       
  1511         iWepData[i] = NULL;
       
  1512         }
       
  1513     for( TInt i = 0; i < KWPAKeyNumOfFields; i++ )
       
  1514         {
       
  1515         iWpaData[i] = NULL;
       
  1516         }
       
  1517     }
       
  1518     
       
  1519 // ---------------------------------------------------------
       
  1520 // CProcessorWlan::EAPSetting
       
  1521 // ---------------------------------------------------------
       
  1522 //
       
  1523 TBool CProcessorWlan::EAPSetting( const TInt aField )
       
  1524 	{
       
  1525 	// Checks if the supplied field is EAP settings and returns ETrue if it is
       
  1526 	if ( aField > EEapParameterFirst
       
  1527 		 && aField < EEapParameterLast )
       
  1528 		{
       
  1529 		return ETrue;
       
  1530 		}
       
  1531 	else
       
  1532 		{
       
  1533 		return EFalse;
       
  1534 		}
       
  1535 	}
       
  1536 
       
  1537 // ---------------------------------------------------------
       
  1538 // CProcessorWlan::GetEapTypeIdFromSettingId
       
  1539 // ---------------------------------------------------------
       
  1540 //
       
  1541 TEapExpandedType CProcessorWlan::GetEapTypeIdFromSettingId( const TInt aField )
       
  1542 	{
       
  1543 	switch ( aField )
       
  1544 		{
       
  1545 		case EEapGtcUsername:
       
  1546 		case EEapGtcSessionValidityTime:
       
  1547 		case EEapGtcEncapsulation:
       
  1548 			{
       
  1549 			return *EapExpandedTypeGtc.GetType();
       
  1550 			}
       
  1551 		case EEapTlsUsername:
       
  1552 		case EEapTlsRealm:
       
  1553 		case EEapTlsVerifyServerRealm:
       
  1554 		case EEapTlsRequireClientAuth:
       
  1555 		case EEapTlsSessionValidityTime:
       
  1556 		case EEapTlsCipherSuites:
       
  1557 		case EEapTlsUserCertSubjectKeyId:
       
  1558 		case EEapTlsUserCertIssuerName:
       
  1559 		case EEapTlsUserCertSerialNumber:
       
  1560 		case EEapTlsCaCertSubjectKeyId:
       
  1561 		case EEapTlsCaCertIssuerName:
       
  1562 		case EEapTlsCaCertSerialNumber:
       
  1563 		case EEapTlsEncapsulation:
       
  1564 			{
       
  1565 			return *EapExpandedTypeTls.GetType();
       
  1566 			}
       
  1567 		case EEapLeapUsername:
       
  1568 		case EEapLeapPassword:
       
  1569 		case EEapLeapSessionValidityTime:
       
  1570 			{
       
  1571 			return *EapExpandedTypeLeap.GetType();
       
  1572 			}
       
  1573 		case EEapSimUsername:
       
  1574 		case EEapSimRealm:
       
  1575 		case EEapSimUsePseudonyms:
       
  1576 		case EEapSimSessionValidityTime:
       
  1577 		case EEapSimEncapsulation:
       
  1578 			{
       
  1579 			return *EapExpandedTypeSim.GetType();
       
  1580 			}
       
  1581 		case EEapTtlsUsername:
       
  1582 		case EEapTtlsRealm:
       
  1583 		case EEapTtlsVerifyServerRealm:
       
  1584 		case EEapTtlsRequireClientAuth:
       
  1585 		case EEapTtlsSessionValidityTime:
       
  1586 		case EEapTtlsCipherSuites:
       
  1587 		case EEapTtlsEncapsulatedTypes:
       
  1588 		case EEapTtlsUserCertSubjectKeyId:
       
  1589 		case EEapTtlsUserCertIssuerName:
       
  1590 		case EEapTtlsUserCertSerialNumber:
       
  1591 		case EEapTtlsCaCertSubjectKeyId:
       
  1592 		case EEapTtlsCaCertIssuerName:
       
  1593 		case EEapTtlsCaCertSerialNumber:
       
  1594 			{
       
  1595 			return *EapExpandedTypeTtls.GetType();
       
  1596 			}
       
  1597 		case EEapAkaUsername:
       
  1598 		case EEapAkaRealm:
       
  1599 		case EEapAkaUsePseudonyms:
       
  1600 		case EEapAkaSessionValidityTime:
       
  1601 		case EEapAkaEncapsulation:
       
  1602 			{
       
  1603 			return *EapExpandedTypeAka.GetType();
       
  1604 			}
       
  1605 		case EEapPeapUsername:
       
  1606 		case EEapPeapRealm:
       
  1607 		case EEapPeapVerifyServerRealm:
       
  1608 		case EEapPeapRequireClientAuth:
       
  1609 		case EEapPeapSessionValidityTime:
       
  1610 		case EEapPeapCipherSuites:
       
  1611 		case EEapPeapV0Allowed:
       
  1612 		case EEapPeapV1Allowed:
       
  1613 		case EEapPeapV2Allowed:
       
  1614 		case EEapPeapEncapsulatedTypes:
       
  1615 		case EEapPeapUserCertSubjectKeyId:
       
  1616 		case EEapPeapUserCertIssuerName:
       
  1617 		case EEapPeapUserCertSerialNumber:
       
  1618 		case EEapPeapCaCertSubjectKeyId:
       
  1619 		case EEapPeapCaCertIssuerName:
       
  1620 		case EEapPeapCaCertSerialNumber:		
       
  1621 			{
       
  1622 			return *EapExpandedTypePeap.GetType();
       
  1623 			}
       
  1624 		case EEapMschapv2Username:
       
  1625 		case EEapMschapv2Password:
       
  1626 		case EEapMschapv2SessionValidityTime:
       
  1627 		case EEapMschapv2Encapsulation:
       
  1628 			{
       
  1629 			return *EapExpandedTypeMsChapv2.GetType();
       
  1630 			}
       
  1631 		case EEapFastUsername:
       
  1632 		case EEapFastRealm:
       
  1633 		case EEapFastVerifyServerRealm:
       
  1634 		case EEapFastRequireClientAuth:
       
  1635 		case EEapFastSessionValidityTime:
       
  1636 		case EEapFastCipherSuites:
       
  1637 		case EEapFastEncapsulatedTypes:
       
  1638 		case EEapFastAuthProvModeAllowed:
       
  1639 		case EEapFastUnauthProvModeAllowed:
       
  1640 		case EEapFastWarnADHPNoPAC:
       
  1641 		case EEapFastWarnADHPNoMatchingPAC:
       
  1642 		case EEapFastWarnNotDefaultServer:
       
  1643 		case EEapFastUserCertSubjectKeyId:
       
  1644 		case EEapFastUserCertIssuerName:
       
  1645 		case EEapFastUserCertSerialNumber:
       
  1646 		case EEapFastCaCertSubjectKeyId:
       
  1647 		case EEapFastCaCertIssuerName:
       
  1648 		case EEapFastCaCertSerialNumber:
       
  1649 			{
       
  1650 			return *EapExpandedTypeFast.GetType();
       
  1651 			}
       
  1652 		
       
  1653 		case EMschapv2Username:
       
  1654 		case EMschapv2Password:
       
  1655 		case EMschapv2SessionValidityTime:
       
  1656 		case EMschapv2Encapsulation:
       
  1657 			{
       
  1658 			return *EapExpandedPlainMsChapv2.GetType();
       
  1659 			}
       
  1660 		default:
       
  1661 			{
       
  1662 			return *EapExpandedTypeNone.GetType();
       
  1663 			}
       
  1664 		
       
  1665 		}
       
  1666 	}
       
  1667 	
       
  1668 // ---------------------------------------------------------
       
  1669 // CProcessorWlan::AddEAPSetting
       
  1670 // ---------------------------------------------------------
       
  1671 //
       
  1672 void CProcessorWlan::AddEAPSettingL( const TInt aField, HBufC16* aValue  )
       
  1673     {
       
  1674     TEapExpandedType eapId = GetEapTypeIdFromSettingId( aField );
       
  1675     if ( eapId == *EapExpandedTypeNone.GetType() )
       
  1676     	{
       
  1677     	CLOG_WRITE( "! Error : Unknown EAP method" );
       
  1678     	User::Leave( KErrArgument ); 
       
  1679     	}
       
  1680     
       
  1681 	TInt eapIndex(0);
       
  1682 	// Search if the EAP instance already exists in the array for this
       
  1683 	for ( eapIndex = 0 ; eapIndex < iEapSettings.Count() ; eapIndex++ )
       
  1684 		{       				
       
  1685 		if ( ( iEapSettings[eapIndex]->iEapSettings->iEAPExpandedType == eapId )
       
  1686 			 && ( iEapSettings[eapIndex]->iName != NULL ) 
       
  1687 			 && ( iEapSettings[eapIndex]->iName->Compare( *iName ) == 0 ))        					 	
       
  1688 		 	{       				
       
  1689 		 	// Found it
       
  1690 		 	break;
       
  1691 		 	}
       
  1692 		}
       
  1693 		
       
  1694 	if ( eapIndex == iEapSettings.Count() )
       
  1695 		{
       
  1696 		// Not found. Create new
       
  1697 		CEapTypeElement* newEap = new (ELeave) CEapTypeElement;
       
  1698 		CleanupStack::PushL( newEap );
       
  1699 		
       
  1700 		newEap->iEapSettings = new (ELeave) EAPSettings;
       
  1701 		
       
  1702 		newEap->iEapSettings->iEAPExpandedType = eapId;
       
  1703 		
       
  1704 		newEap->iName = iName->AllocL();                           
       
  1705 		               	    	
       
  1706 		iEapSettings.AppendL(newEap);
       
  1707 		
       
  1708 		CleanupStack::Pop( newEap );
       
  1709 		
       
  1710 		// Set the index to the newly created EAP settings instance
       
  1711 		eapIndex = iEapSettings.Count() - 1;
       
  1712 		
       
  1713 		}
       
  1714 	switch ( aField )
       
  1715 		{
       
  1716 		case EEapGtcUsername:
       
  1717 		case EEapTlsUsername:
       
  1718 		case EEapLeapUsername:
       
  1719 		case EEapSimUsername:
       
  1720 		case EEapTtlsUsername:
       
  1721 		case EEapAkaUsername:
       
  1722 		case EEapPeapUsername:
       
  1723 		case EEapMschapv2Username:
       
  1724 		case EEapFastUsername:
       
  1725 		case EMschapv2Username:
       
  1726 			{
       
  1727 			iEapSettings[eapIndex]->iEapSettings->iUsernamePresent = ETrue;
       
  1728 			iEapSettings[eapIndex]->iEapSettings->iUsername.Copy( *aValue );
       
  1729 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticUsernamePresent = ETrue;
       
  1730 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticUsername = EFalse;
       
  1731 			break;
       
  1732 			}
       
  1733 			
       
  1734 		case EEapLeapPassword:
       
  1735 		case EEapMschapv2Password:
       
  1736 		case EMschapv2Password:
       
  1737 			{
       
  1738 			iEapSettings[eapIndex]->iEapSettings->iPasswordPresent = ETrue;
       
  1739 			iEapSettings[eapIndex]->iEapSettings->iPassword.Copy( *aValue );
       
  1740 			iEapSettings[eapIndex]->iEapSettings->iShowPassWordPromptPresent = ETrue;
       
  1741 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticUsername = EFalse;
       
  1742 			break;
       
  1743 			}
       
  1744 
       
  1745 		case EEapTlsRealm:
       
  1746 		case EEapSimRealm:
       
  1747 		case EEapTtlsRealm:
       
  1748 		case EEapAkaRealm:
       
  1749 		case EEapPeapRealm:
       
  1750 		case EEapFastRealm:
       
  1751 			{
       
  1752 			iEapSettings[eapIndex]->iEapSettings->iRealmPresent = ETrue;
       
  1753 			iEapSettings[eapIndex]->iEapSettings->iRealm.Copy( *aValue );
       
  1754 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticRealmPresent = ETrue;
       
  1755 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticRealm = EFalse;
       
  1756 			break;
       
  1757 			}
       
  1758 				
       
  1759 		case EEapGtcSessionValidityTime:
       
  1760 		case EEapTtlsSessionValidityTime:
       
  1761 		case EEapTlsSessionValidityTime:
       
  1762 		case EEapSimSessionValidityTime:
       
  1763 		case EEapLeapSessionValidityTime:
       
  1764 		case EMschapv2SessionValidityTime:
       
  1765 		case EEapAkaSessionValidityTime:
       
  1766 		case EEapPeapSessionValidityTime:
       
  1767 		case EEapMschapv2SessionValidityTime:
       
  1768 		case EEapFastSessionValidityTime:
       
  1769 			{
       
  1770 		    // Convert the input parameter to integer
       
  1771 	    	TLex lex( *aValue );
       
  1772 			TUint value( 0 );
       
  1773 			if( lex.Val( value, EDecimal) != KErrNone )
       
  1774 				{				
       
  1775 				CLOG_WRITE_FORMAT( "! Error : Invalid session validity time value. EapId: %d", eapId.GetVendorType() );
       
  1776 				User::Leave( KErrArgument );
       
  1777 				}			
       
  1778 
       
  1779 			iEapSettings[eapIndex]->iEapSettings->iSessionValidityTimePresent = ETrue;
       
  1780 			iEapSettings[eapIndex]->iEapSettings->iSessionValidityTime = value;
       
  1781 			break;
       
  1782 			}
       
  1783 				
       
  1784 		case EEapGtcEncapsulation:
       
  1785 		case EEapTlsEncapsulation:
       
  1786 		case EEapSimEncapsulation:
       
  1787 		case EEapAkaEncapsulation:
       
  1788 		case EEapMschapv2Encapsulation:
       
  1789 		case EMschapv2Encapsulation:
       
  1790 			{
       
  1791 			TLex lex( *aValue );				
       
  1792 			TUint eapTypeId( 0 );						
       
  1793 			if( lex.Val( eapTypeId, EDecimal) != KErrNone )
       
  1794 				{
       
  1795 				CLOG_WRITE_FORMAT( "! Error : Invalid encapsulation value. EapId: %d", eapId.GetVendorType() );
       
  1796 				User::Leave( KErrArgument );
       
  1797 				}			
       
  1798 			iEapSettings[eapIndex]->iEncapsulatingEapId.SetValue( eapId.GetVendorId(), eapTypeId ); 
       
  1799 			break;
       
  1800 			}
       
  1801 		
       
  1802 		case EEapTlsVerifyServerRealm:
       
  1803 		case EEapTtlsVerifyServerRealm:
       
  1804 		case EEapPeapVerifyServerRealm:
       
  1805 		case EEapFastVerifyServerRealm:
       
  1806 			{
       
  1807             if ( !aValue->CompareF( KStrYes ) )
       
  1808                 {
       
  1809 				iEapSettings[eapIndex]->iEapSettings->iVerifyServerRealmPresent = ETrue;
       
  1810 				iEapSettings[eapIndex]->iEapSettings->iVerifyServerRealm = ETrue;
       
  1811                 }
       
  1812             else if ( !aValue->CompareF( KStrNo ) )
       
  1813                 {
       
  1814                 iEapSettings[eapIndex]->iEapSettings->iVerifyServerRealmPresent = ETrue;
       
  1815 				iEapSettings[eapIndex]->iEapSettings->iVerifyServerRealm = EFalse;
       
  1816                 }
       
  1817             else 
       
  1818                 {                
       
  1819                 CLOG_WRITE_FORMAT( "! Error : Invalid VerifyServerRealm. EapId: %d", eapId.GetVendorType() );                
       
  1820                 User::Leave( KErrArgument );
       
  1821                 }
       
  1822 
       
  1823 			break;
       
  1824 			}
       
  1825 						
       
  1826 		case EEapTlsRequireClientAuth:
       
  1827 		case EEapTtlsRequireClientAuth:		
       
  1828 		case EEapPeapRequireClientAuth:
       
  1829 		case EEapFastRequireClientAuth:
       
  1830 			{
       
  1831             if ( !aValue->CompareF( KStrYes ) )
       
  1832                 {
       
  1833 				iEapSettings[eapIndex]->iEapSettings->iRequireClientAuthenticationPresent = ETrue;
       
  1834 				iEapSettings[eapIndex]->iEapSettings->iRequireClientAuthentication = ETrue;
       
  1835                 }
       
  1836             else if ( !aValue->CompareF( KStrNo ) )
       
  1837                 {
       
  1838                 iEapSettings[eapIndex]->iEapSettings->iRequireClientAuthenticationPresent = ETrue;
       
  1839 				iEapSettings[eapIndex]->iEapSettings->iRequireClientAuthentication = EFalse;
       
  1840                 }
       
  1841             else 
       
  1842                 {                
       
  1843                 CLOG_WRITE_FORMAT( "! Error : Invalid RequireClientAuth. EapId: %d", eapId.GetVendorType() );                
       
  1844                 User::Leave( KErrArgument );
       
  1845                 }
       
  1846 			
       
  1847 			break;
       
  1848 			}
       
  1849 		
       
  1850 		case EEapTlsCipherSuites:
       
  1851 		case EEapTtlsCipherSuites:
       
  1852 		case EEapPeapCipherSuites:
       
  1853 		case EEapFastCipherSuites:
       
  1854 			{
       
  1855 			TRAPD( err, FillCipherSuitesL( aValue, eapIndex ) );
       
  1856 			if( err != KErrNone )
       
  1857 				{
       
  1858 				CLOG_WRITE_FORMAT( "! Error : Invalid CipherSuites. EapId: %d", eapId.GetVendorType() );
       
  1859 				User::Leave( KErrArgument );
       
  1860 				}
       
  1861 			break;
       
  1862 			}
       
  1863 		
       
  1864 		case EEapTlsUserCertSubjectKeyId:
       
  1865 		case EEapTtlsUserCertSubjectKeyId:
       
  1866 		case EEapPeapUserCertSubjectKeyId:
       
  1867 		case EEapFastUserCertSubjectKeyId:
       
  1868 			{
       
  1869 			TInt certIndex = FindCertificateEntryL( EapCertificateEntry::EUser, eapIndex ); 
       
  1870 
       
  1871 			TKeyIdentifier key;
       
  1872 			
       
  1873 			TRAPD( err, ConvertSubjectKeyIdToBinaryL( aValue, key) );
       
  1874 			if( err != KErrNone )
       
  1875 				{
       
  1876 				CLOG_WRITE_FORMAT( "! Error : Invalid UserCertSubjectKeyId. EapId: %d", eapId.GetVendorType() );
       
  1877 				User::Leave( KErrArgument );
       
  1878 				}
       
  1879    			
       
  1880    			iEapSettings[eapIndex]->iEapSettings->iCertificatesPresent = ETrue;
       
  1881    			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetIsEnabled( ETrue );
       
  1882    			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetSubjectKeyId( key );
       
  1883    			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetSubjectKeyIdPresent();
       
  1884 			break;
       
  1885 			}
       
  1886 		
       
  1887 		case EEapTlsUserCertIssuerName:
       
  1888 		case EEapTtlsUserCertIssuerName:
       
  1889 		case EEapPeapUserCertIssuerName:
       
  1890 		case EEapFastUserCertIssuerName:
       
  1891 			{
       
  1892 			TUint certIndex = FindCertificateEntryL( EapCertificateEntry::EUser, eapIndex ); 
       
  1893 			
       
  1894 			iEapSettings[eapIndex]->iEapSettings->iCertificatesPresent = ETrue;
       
  1895 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetIsEnabled( ETrue );
       
  1896 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetSubjectKeyIdPresent();
       
  1897 	 		iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetIssuerName( *aValue );			
       
  1898 			break;
       
  1899 			}
       
  1900 		
       
  1901 		case EEapTlsUserCertSerialNumber:
       
  1902 		case EEapTtlsUserCertSerialNumber:
       
  1903 		case EEapPeapUserCertSerialNumber:
       
  1904 		case EEapFastUserCertSerialNumber:
       
  1905 			{
       
  1906 			TUint certIndex = FindCertificateEntryL( EapCertificateEntry::EUser, eapIndex );
       
  1907 			
       
  1908 			iEapSettings[eapIndex]->iEapSettings->iCertificatesPresent = ETrue;
       
  1909 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetIsEnabled( ETrue );
       
  1910 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetSerialNumberPresent();
       
  1911 	 		iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetSerialNumber( *aValue );			
       
  1912 			break;
       
  1913 			}
       
  1914 		
       
  1915 		case EEapTlsCaCertSubjectKeyId:
       
  1916 		case EEapTtlsCaCertSubjectKeyId:
       
  1917 		case EEapPeapCaCertSubjectKeyId:
       
  1918 		case EEapFastCaCertSubjectKeyId:
       
  1919 			{
       
  1920 			TInt certIndex = FindCertificateEntryL( EapCertificateEntry::ECA, eapIndex ); 
       
  1921 
       
  1922 			TKeyIdentifier key;
       
  1923 			
       
  1924 			TRAPD( err, ConvertSubjectKeyIdToBinaryL( aValue, key) );
       
  1925 			if( err != KErrNone )
       
  1926 				{
       
  1927 				CLOG_WRITE_FORMAT( "! Error : Invalid UserCertSubjectKeyId. EapId: %d", eapId.GetVendorType() );
       
  1928 				User::Leave( KErrArgument );
       
  1929 				}
       
  1930 
       
  1931 			iEapSettings[eapIndex]->iEapSettings->iCertificatesPresent = ETrue;
       
  1932 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetIsEnabled( ETrue );
       
  1933 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetSubjectKeyId( key );
       
  1934 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetSubjectKeyIdPresent();
       
  1935 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticCACertificatePresent = ETrue;
       
  1936 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticCACertificate = EFalse;
       
  1937 			break;
       
  1938 			}
       
  1939 		
       
  1940 		case EEapTlsCaCertIssuerName:
       
  1941 		case EEapTtlsCaCertIssuerName:		
       
  1942 		case EEapPeapCaCertIssuerName:
       
  1943 		case EEapFastCaCertIssuerName:
       
  1944 			{
       
  1945 			TUint certIndex = FindCertificateEntryL( EapCertificateEntry::ECA, eapIndex ); 
       
  1946 			iEapSettings[eapIndex]->iEapSettings->iCertificatesPresent = ETrue;
       
  1947 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetIsEnabled( ETrue );
       
  1948 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetIssuerNamePresent();
       
  1949 	 		iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetIssuerName( *aValue );
       
  1950 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticCACertificatePresent = ETrue;
       
  1951 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticCACertificate = EFalse;
       
  1952 			
       
  1953 			break;
       
  1954 			}
       
  1955 		
       
  1956 		case EEapTlsCaCertSerialNumber:
       
  1957 		case EEapTtlsCaCertSerialNumber:		
       
  1958 		case EEapPeapCaCertSerialNumber:
       
  1959 		case EEapFastCaCertSerialNumber:
       
  1960 			{
       
  1961 			TUint certIndex = FindCertificateEntryL( EapCertificateEntry::ECA, eapIndex ); 
       
  1962 			iEapSettings[eapIndex]->iEapSettings->iCertificatesPresent = ETrue;
       
  1963 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetIsEnabled( ETrue );
       
  1964 			iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetSerialNumberPresent();
       
  1965 	 		iEapSettings[eapIndex]->iEapSettings->iCertificates[certIndex]->SetSerialNumber( *aValue );
       
  1966 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticCACertificatePresent = ETrue;
       
  1967 			iEapSettings[eapIndex]->iEapSettings->iUseAutomaticCACertificate = EFalse;
       
  1968 			break;
       
  1969 			}
       
  1970 		
       
  1971 		case EEapSimUsePseudonyms:
       
  1972 		case EEapAkaUsePseudonyms:
       
  1973 			{
       
  1974             if ( !aValue->CompareF( KStrYes ) )
       
  1975 	            {
       
  1976 				iEapSettings[eapIndex]->iEapSettings->iUsePseudonymsPresent = ETrue;
       
  1977 				iEapSettings[eapIndex]->iEapSettings->iUsePseudonyms = ETrue;
       
  1978 	            }
       
  1979 	        else if ( !aValue->CompareF( KStrNo ) )
       
  1980 	            {
       
  1981 	            iEapSettings[eapIndex]->iEapSettings->iUsePseudonymsPresent = ETrue;
       
  1982 				iEapSettings[eapIndex]->iEapSettings->iUsePseudonyms = EFalse;
       
  1983 	            }
       
  1984 	        else 
       
  1985 	            {
       
  1986 	            CLOG_WRITE_FORMAT( "! Error : Invalid UsePseudonyms. EapId: %d", eapId.GetVendorType() );                
       
  1987                 User::Leave( KErrArgument );
       
  1988 	            }
       
  1989 			break;
       
  1990 			}
       
  1991 				
       
  1992 		case EEapTtlsEncapsulatedTypes:
       
  1993 		case EEapPeapEncapsulatedTypes:
       
  1994 		case EEapFastEncapsulatedTypes:
       
  1995 			{
       
  1996 			iEapSettings[eapIndex]->iEapSettings->iEnabledEncapsulatedEAPExpandedTypes.Append( GetExpandedEapTypeIdL( *aValue ) );
       
  1997             iEapSettings[eapIndex]->iEapSettings->iEnabledEncapsulatedEAPExpandedTypesPresent = ETrue;
       
  1998 			break;
       
  1999 			}
       
  2000 		
       
  2001 		case EEapPeapV0Allowed:
       
  2002 			{
       
  2003             if ( !aValue->CompareF( KStrYes ) )
       
  2004 	            {
       
  2005 				iEapSettings[eapIndex]->iEapSettings->iPEAPVersionsPresent = ETrue;
       
  2006 				iEapSettings[eapIndex]->iEapSettings->iPEAPv0Allowed = ETrue;
       
  2007 	            }
       
  2008 	        else if ( !aValue->CompareF( KStrNo ) )
       
  2009 	            {
       
  2010 	            iEapSettings[eapIndex]->iEapSettings->iPEAPVersionsPresent = ETrue;
       
  2011 				iEapSettings[eapIndex]->iEapSettings->iPEAPv0Allowed = EFalse;
       
  2012 	            }
       
  2013 	        else 
       
  2014 	            {
       
  2015    	            CLOG_WRITE_FORMAT( "! Error : Invalid EapPeapV0Allowed. EapId: %d", eapId.GetVendorType() );                
       
  2016                 User::Leave( KErrArgument );
       
  2017 	            }
       
  2018 			
       
  2019 			break;
       
  2020 			}
       
  2021 		
       
  2022 		case EEapPeapV1Allowed:
       
  2023 			{
       
  2024             if ( !aValue->CompareF( KStrYes ) )
       
  2025 	            {
       
  2026 				iEapSettings[eapIndex]->iEapSettings->iPEAPVersionsPresent = ETrue;
       
  2027 				iEapSettings[eapIndex]->iEapSettings->iPEAPv1Allowed = ETrue;
       
  2028 	            }
       
  2029 	        else if ( !aValue->CompareF( KStrNo ) )
       
  2030 	            {
       
  2031 	            iEapSettings[eapIndex]->iEapSettings->iPEAPVersionsPresent = ETrue;
       
  2032 				iEapSettings[eapIndex]->iEapSettings->iPEAPv1Allowed = EFalse;
       
  2033 	            }
       
  2034 	        else 
       
  2035 	            {
       
  2036    	            CLOG_WRITE_FORMAT( "! Error : Invalid EapPeapV1Allowed. EapId: %d", eapId.GetVendorType() );                
       
  2037                 User::Leave( KErrArgument );
       
  2038 	            }
       
  2039 			
       
  2040 			break;
       
  2041 			}
       
  2042 		
       
  2043 		case EEapPeapV2Allowed:
       
  2044 			{
       
  2045             if ( !aValue->CompareF( KStrYes ) )
       
  2046 	            {
       
  2047 				iEapSettings[eapIndex]->iEapSettings->iPEAPVersionsPresent = ETrue;
       
  2048 				iEapSettings[eapIndex]->iEapSettings->iPEAPv2Allowed = ETrue;
       
  2049 	            }
       
  2050 	        else if ( !aValue->CompareF( KStrNo ) )
       
  2051 	            {
       
  2052 	            iEapSettings[eapIndex]->iEapSettings->iPEAPVersionsPresent = ETrue;
       
  2053 				iEapSettings[eapIndex]->iEapSettings->iPEAPv2Allowed = EFalse;
       
  2054 	            }
       
  2055 	        else 
       
  2056 	            {
       
  2057    	            CLOG_WRITE_FORMAT( "! Error : Invalid EapPeapV2Allowed. EapId: %d", eapId.GetVendorType() );
       
  2058                 User::Leave( KErrArgument );
       
  2059 	            }
       
  2060 			
       
  2061 			break;
       
  2062 			}
       
  2063 				
       
  2064 		case EEapFastAuthProvModeAllowed:
       
  2065 			{
       
  2066             if ( !aValue->CompareF( KStrYes ) )
       
  2067 	            {
       
  2068 				iEapSettings[eapIndex]->iEapSettings->iAuthProvModeAllowedPresent = ETrue;
       
  2069 				iEapSettings[eapIndex]->iEapSettings->iAuthProvModeAllowed = ETrue;
       
  2070 	            }
       
  2071 	        else if ( !aValue->CompareF( KStrNo ) )
       
  2072 	            {
       
  2073 	            iEapSettings[eapIndex]->iEapSettings->iAuthProvModeAllowedPresent = ETrue;
       
  2074 				iEapSettings[eapIndex]->iEapSettings->iAuthProvModeAllowed = EFalse;
       
  2075 	            }
       
  2076 	        else 
       
  2077 	            {
       
  2078   	            CLOG_WRITE_FORMAT( "! Error : Invalid EEapFastAuthProvModeAllowed. EapId: %d", eapId.GetVendorType() );                
       
  2079                 User::Leave( KErrArgument );
       
  2080 	            }
       
  2081 			
       
  2082 			break;
       
  2083 			}
       
  2084 		
       
  2085 		case EEapFastUnauthProvModeAllowed:
       
  2086 			{
       
  2087             if ( !aValue->CompareF( KStrYes ) )
       
  2088 	            {
       
  2089 				iEapSettings[eapIndex]->iEapSettings->iUnauthProvModeAllowedPresent = ETrue;
       
  2090 				iEapSettings[eapIndex]->iEapSettings->iUnauthProvModeAllowed = ETrue;
       
  2091 	            }
       
  2092 	        else if ( !aValue->CompareF( KStrNo ) )
       
  2093 	            {
       
  2094 	            iEapSettings[eapIndex]->iEapSettings->iUnauthProvModeAllowedPresent = ETrue;
       
  2095 				iEapSettings[eapIndex]->iEapSettings->iUnauthProvModeAllowed = EFalse;
       
  2096 	            }
       
  2097 	        else 
       
  2098 	            {
       
  2099 
       
  2100   	            CLOG_WRITE_FORMAT( "! Error : Invalid EapFastUnauthProvModeAllowed. EapId: %d", eapId.GetVendorType() );                
       
  2101                 User::Leave( KErrArgument );
       
  2102 	            }
       
  2103 			
       
  2104 			break;
       
  2105 			}
       
  2106 		
       
  2107 		case EEapFastWarnADHPNoPAC:
       
  2108 			{
       
  2109             if ( !aValue->CompareF( KStrYes ) )
       
  2110 	            {
       
  2111 				iEapSettings[eapIndex]->iEapSettings->iWarnADHPNoPACPresent = ETrue;
       
  2112 				iEapSettings[eapIndex]->iEapSettings->iWarnADHPNoPAC = ETrue;
       
  2113 	            }
       
  2114 	        else if ( !aValue->CompareF( KStrNo ) )
       
  2115 	            {
       
  2116 	            iEapSettings[eapIndex]->iEapSettings->iWarnADHPNoPACPresent = ETrue;
       
  2117 				iEapSettings[eapIndex]->iEapSettings->iWarnADHPNoPAC = EFalse;
       
  2118 	            }
       
  2119 	        else 
       
  2120 	            {
       
  2121   	            CLOG_WRITE_FORMAT( "! Error : Invalid EapFastWarnADHPNoPAC. EapId: %d", eapId.GetVendorType() );                
       
  2122                 User::Leave( KErrArgument );
       
  2123 	            }
       
  2124 			
       
  2125 			break;
       
  2126 			}
       
  2127 		
       
  2128 		case EEapFastWarnADHPNoMatchingPAC:
       
  2129 			{
       
  2130             if ( !aValue->CompareF( KStrYes ) )
       
  2131 	            {
       
  2132 				iEapSettings[eapIndex]->iEapSettings->iWarnADHPNoMatchingPACPresent = ETrue;
       
  2133 				iEapSettings[eapIndex]->iEapSettings->iWarnADHPNoMatchingPAC = ETrue;
       
  2134 	            }
       
  2135 	        else if ( !aValue->CompareF( KStrNo ) )
       
  2136 	            {
       
  2137 	            iEapSettings[eapIndex]->iEapSettings->iWarnADHPNoMatchingPACPresent = ETrue;
       
  2138 				iEapSettings[eapIndex]->iEapSettings->iWarnADHPNoMatchingPAC = EFalse;
       
  2139 	            }
       
  2140 	        else 
       
  2141 	            {
       
  2142   	            CLOG_WRITE_FORMAT( "! Error : Invalid EapFastWarnADHPNoMatchingPAC. EapId: %d", eapId.GetVendorType() );                
       
  2143                 User::Leave( KErrArgument );
       
  2144 	            }
       
  2145 			
       
  2146 			break;
       
  2147 			}
       
  2148 		
       
  2149 		case EEapFastWarnNotDefaultServer:
       
  2150 			{
       
  2151             if ( !aValue->CompareF( KStrYes ) )
       
  2152 	            {
       
  2153 				iEapSettings[eapIndex]->iEapSettings->iWarnNotDefaultServerPresent = ETrue;
       
  2154 				iEapSettings[eapIndex]->iEapSettings->iWarnNotDefaultServer = ETrue;
       
  2155 	            }
       
  2156 	        else if ( !aValue->CompareF( KStrNo ) )
       
  2157 	            {
       
  2158 	            iEapSettings[eapIndex]->iEapSettings->iWarnNotDefaultServerPresent = ETrue;
       
  2159 				iEapSettings[eapIndex]->iEapSettings->iWarnNotDefaultServer = EFalse;
       
  2160 	            }
       
  2161 	        else 
       
  2162 	            {
       
  2163   	            CLOG_WRITE_FORMAT( "! Error : Invalid EapFastWarnNotDefaultServer. EapId: %d", eapId.GetVendorType() );                
       
  2164                 User::Leave( KErrArgument );
       
  2165 	            }
       
  2166 			
       
  2167 			break;
       
  2168 			}
       
  2169 			
       
  2170 		default:		
       
  2171 			{
       
  2172 			
       
  2173 			}
       
  2174 		}
       
  2175     }
       
  2176 // ---------------------------------------------------------
       
  2177 // CProcessorWlan::FillCipherSuitesL
       
  2178 // ---------------------------------------------------------
       
  2179 //
       
  2180 void CProcessorWlan::FillCipherSuitesL( const HBufC16* const aPtrTag, const TInt aEapIndex )
       
  2181     {
       
  2182     if ( iEapSettings[aEapIndex] == NULL )
       
  2183         {
       
  2184 		User::Leave( KErrArgument );
       
  2185         }
       
  2186 
       
  2187     iEapSettings[aEapIndex]->iEapSettings->iCipherSuites.Reset();
       
  2188     iEapSettings[aEapIndex]->iEapSettings->iCipherSuitesPresent = EFalse; // init to EFalse
       
  2189     
       
  2190     TChar plus( '+' );
       
  2191     
       
  2192     TBuf8<256> tmpBuf;
       
  2193    	tmpBuf.Copy( *aPtrTag);
       
  2194    			
       
  2195     TInt length = tmpBuf.Length();
       
  2196     
       
  2197     for ( TInt i = 0 ; i + 3 < length ; i += 5)
       
  2198         {
       
  2199         if ( tmpBuf[i] == plus )
       
  2200             {
       
  2201             TLex8 lex( tmpBuf.Mid( i + 1, 3) );
       
  2202             TUint suite;
       
  2203             User::LeaveIfError( lex.Val( suite ) );
       
  2204             iEapSettings[aEapIndex]->iEapSettings->iCipherSuites.Append(suite);
       
  2205             iEapSettings[aEapIndex]->iEapSettings->iCipherSuitesPresent = ETrue;
       
  2206             }
       
  2207         }
       
  2208 	}
       
  2209     
       
  2210 // ---------------------------------------------------------
       
  2211 // CProcessorWlan::FindCertificateEntry
       
  2212 // ---------------------------------------------------------
       
  2213 //
       
  2214 TUint CProcessorWlan::FindCertificateEntryL( const EapCertificateEntry::TCertType aCertType, const TInt aEapIndex )
       
  2215     {
       
  2216     TUint certIndex( 0 );
       
  2217 	for( certIndex = 0; certIndex < iEapSettings[aEapIndex]->iEapSettings->iCertificates.Count() ; certIndex++ )
       
  2218 		{
       
  2219 		if( iEapSettings[aEapIndex]->iEapSettings->iCertificates[certIndex]->GetCertType() == aCertType )
       
  2220 			{
       
  2221 			// Found
       
  2222 			break;
       
  2223 			}
       
  2224 		}
       
  2225 	if( certIndex == iEapSettings[aEapIndex]->iEapSettings->iCertificates.Count() )
       
  2226 		{
       
  2227 		// Not found. Create
       
  2228 		EapCertificateEntry* entry;
       
  2229 		entry = new (ELeave) EapCertificateEntry;
       
  2230 		entry->SetCertType( aCertType );
       
  2231 
       
  2232 		iEapSettings[aEapIndex]->iEapSettings->iCertificates.AppendL( entry );
       
  2233 
       
  2234 		certIndex = iEapSettings[aEapIndex]->iEapSettings->iCertificates.Count() - 1;
       
  2235 		}
       
  2236 	return certIndex;	
       
  2237 	}
       
  2238 
       
  2239 // ---------------------------------------------------------
       
  2240 // CProcessorWlan::ConvertSubjectKeyIdToBinary
       
  2241 // ---------------------------------------------------------
       
  2242 //
       
  2243 void CProcessorWlan::ConvertSubjectKeyIdToBinaryL( const HBufC16* const aSubjectKeyIdString, TKeyIdentifier& aBinaryKey)
       
  2244 	{
       
  2245 	TInt err( KErrNone );
       
  2246 	
       
  2247 		// Define literals to search the subject key for possible 0X/0x beginning
       
  2248 	_LIT(KHexIdLC, "0x");
       
  2249 	_LIT(KHexIdUC, "0X");
       
  2250 	TBuf<2> hexIdBuf;
       
  2251 	
       
  2252 	// The lenght of the key given as input
       
  2253 	TInt keyLen = aSubjectKeyIdString->Length();
       
  2254 	
       
  2255 	// setting the given key to the key buffer
       
  2256 	TBuf8<256> origKey;
       
  2257 	
       
  2258 	origKey.Copy( *aSubjectKeyIdString );
       
  2259 	origKey.SetLength(keyLen);
       
  2260 		
       
  2261 	TLex8 tmpByte;
       
  2262 	TUint16 byte;
       
  2263 	
       
  2264 	// Remove possible spaces from the beginning
       
  2265 	origKey.TrimLeft();
       
  2266 	
       
  2267 	// the key should be atleast two chars long
       
  2268 	if (origKey.Length() >= 2)
       
  2269 		{
       
  2270 		// Copy the two left most characters in to the buffer
       
  2271 		hexIdBuf.Copy(origKey.Left(2));
       
  2272 		
       
  2273 		// If the first characters are 0x or 0X, then thet should be ignored
       
  2274 		if (hexIdBuf.Compare(KHexIdLC) == 0
       
  2275 				|| hexIdBuf.Compare(KHexIdUC) == 0)
       
  2276 			{
       
  2277 			// delete two characters
       
  2278 			origKey.Delete(0, 2);
       
  2279 			}
       
  2280 		}
       
  2281 
       
  2282 
       
  2283 	// looping the subject key through, removing whitespaces
       
  2284 	for (TInt i = 0; i < KKeyIdentifierLength; i++)
       
  2285 		{
       
  2286 		// removing white spaces from the left side of the key
       
  2287 		origKey.TrimLeft();
       
  2288 		// check that there are characters left
       
  2289 		if (origKey.Length() >= 2)
       
  2290 			{
       
  2291 			// pick the two left most bytes from the key
       
  2292 			tmpByte = origKey.Left(2);
       
  2293 			// convert byte into binary format
       
  2294 			err = tmpByte.Val(byte, EHex);
       
  2295 			
       
  2296 			// check whether conversion to decimal went ok
       
  2297 			if (err != KErrNone)
       
  2298 				{
       
  2299 				// if there are problems, then leave the loop
       
  2300 				break;
       
  2301 				}
       
  2302 			
       
  2303 			// store the appended byte into the key variable
       
  2304 			aBinaryKey.Append(byte);
       
  2305 			// delete two characters from the left side of the character array in the buffer
       
  2306 			origKey.Delete(0, 2);
       
  2307 			}
       
  2308 		else {
       
  2309 			// leave the loop, no characters are left			
       
  2310 			break;
       
  2311 			}
       
  2312 		}
       
  2313 	User::LeaveIfError( err );		
       
  2314 	}
       
  2315 	
       
  2316 
       
  2317 // End of File.