wlansecuritysettings/wepsecuritysettingsui/src/WEPSecuritySettingsImpl.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Implementation of class CWEPSecuritySettingsImpl.     
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "WEPSecuritySettingsImpl.h"
       
    22 #include "WEPSecuritySettingsUiPanic.h"
       
    23 
       
    24 #include <WEPSecuritySettingsUI.h>
       
    25 #include <commdb.h>
       
    26 #include <FeatMgr.h>
       
    27 #include <WlanCdbCols.h>
       
    28 
       
    29 #include <commsdattypesv1_1.h>
       
    30 #include <cmmanagertablefields.h>
       
    31 #include <wlancontainer.h>
       
    32 
       
    33 // CONSTANT DECLARATIONS
       
    34 
       
    35 // Index of first key
       
    36 LOCAL_D const TInt KFirstKey = 0;
       
    37 
       
    38 // Index of second key
       
    39 LOCAL_D const TInt KSecondKey = 1;
       
    40 
       
    41 // Index of third key
       
    42 LOCAL_D const TInt KThirdKey = 2;
       
    43 
       
    44 // Index of fourth key
       
    45 LOCAL_D const TInt KFourthKey = 3;
       
    46 
       
    47 // Ratio of ascii and hex key sizes
       
    48 LOCAL_D const TInt KAsciiHexRatio = 2;
       
    49 
       
    50 
       
    51 // ================= MEMBER FUNCTIONS =======================
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CWEPSecuritySettingsImpl::NewL
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 CWEPSecuritySettingsImpl* CWEPSecuritySettingsImpl::NewL()
       
    58     {
       
    59     CWEPSecuritySettingsImpl* settings = 
       
    60                                     new ( ELeave ) CWEPSecuritySettingsImpl();
       
    61     CleanupStack::PushL( settings );
       
    62     settings->ConstructL();
       
    63     CleanupStack::Pop( settings ); 
       
    64     return settings;    
       
    65     }
       
    66 
       
    67 
       
    68 // ---------------------------------------------------------
       
    69 // CWEPSecuritySettingsImpl::CWEPSecuritySettingsImpl
       
    70 // ---------------------------------------------------------
       
    71 //
       
    72 CWEPSecuritySettingsImpl::CWEPSecuritySettingsImpl()
       
    73 : iIsWEP256Enabled( ETrue )
       
    74     {
       
    75     iKeyInUse = CWEPSecuritySettings::EKeyNumber1;
       
    76     iAuthentication = CWEPSecuritySettings::EAuthOpen;
       
    77     for ( TUint i = 0; i < KMaxNumberofKeys; i++)
       
    78         {
       
    79         iKeyLength[i] = CWEPSecuritySettings::E40Bits;
       
    80         iKeyFormat[i] = CWEPSecuritySettings::EAscii;
       
    81         iKeyData[i].Zero();
       
    82         }
       
    83     }
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CWEPSecuritySettingsImpl::ConstructL
       
    88 // ---------------------------------------------------------
       
    89 //
       
    90 void CWEPSecuritySettingsImpl::ConstructL()
       
    91     {
       
    92     // WEP256 is deprecated.
       
    93     iIsWEP256Enabled = EFalse;
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------
       
    98 // CWEPSecuritySettingsImpl::~CWEPSecuritySettingsImpl
       
    99 // ---------------------------------------------------------
       
   100 //
       
   101 CWEPSecuritySettingsImpl::~CWEPSecuritySettingsImpl()
       
   102     {
       
   103     }
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------
       
   107 // CWEPSecuritySettingsImpl::LoadL
       
   108 // ---------------------------------------------------------
       
   109 //
       
   110 void CWEPSecuritySettingsImpl::LoadL( TUint32 aIapId, 
       
   111                                       CCommsDatabase& aCommsDb )
       
   112     {
       
   113     if ( aIapId == KUidNone )
       
   114         {
       
   115         return;
       
   116         }
       
   117 
       
   118     CCommsDbTableView* wLanServiceTable;
       
   119         
       
   120     wLanServiceTable = aCommsDb.OpenViewMatchingUintLC(
       
   121                     TPtrC( WLAN_SERVICE ), TPtrC( WLAN_SERVICE_ID ), aIapId );
       
   122 
       
   123     TInt errorCode = wLanServiceTable->GotoFirstRecord();
       
   124     if ( errorCode == KErrNone )
       
   125         {
       
   126         // Get index of key in use
       
   127         TRAPD( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_WEP_INDEX ),
       
   128                                     ( TUint32& ) iKeyInUse ) );
       
   129 
       
   130         // Get index of key in use
       
   131         TRAP( err, wLanServiceTable->ReadUintL( 
       
   132                                         TPtrC( NU_WLAN_AUTHENTICATION_MODE ),
       
   133                                         ( TUint32& ) iAuthentication ) );
       
   134 
       
   135         // Get first WEP key
       
   136         wLanServiceTable->ReadTextL( TPtrC( NU_WLAN_WEP_KEY1 ), 
       
   137                                      iKeyData[KFirstKey] );
       
   138         SetLenKeyDataFromText( KFirstKey );
       
   139 
       
   140         // Get second WEP key
       
   141         wLanServiceTable->ReadTextL( TPtrC( NU_WLAN_WEP_KEY2 ), 
       
   142                                      iKeyData[KSecondKey] );
       
   143         SetLenKeyDataFromText( KSecondKey );
       
   144 
       
   145         // Get third WEP key
       
   146         wLanServiceTable->ReadTextL( TPtrC( NU_WLAN_WEP_KEY3 ), 
       
   147                                      iKeyData[KThirdKey] );
       
   148         SetLenKeyDataFromText( KThirdKey );
       
   149 
       
   150         // Get fourth WEP key
       
   151         wLanServiceTable->ReadTextL( TPtrC( NU_WLAN_WEP_KEY4 ), 
       
   152                                      iKeyData[KFourthKey] );
       
   153         SetLenKeyDataFromText( KFourthKey );
       
   154 
       
   155 
       
   156         // Get the format of the keys
       
   157         TRAP( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_WEP_KEY1_FORMAT ),
       
   158                                     ( TUint32& ) iKeyFormat[KFirstKey] ) );
       
   159 
       
   160         TRAP( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_WEP_KEY2_FORMAT ),
       
   161                                     ( TUint32& ) iKeyFormat[KSecondKey] ) );
       
   162 
       
   163         TRAP( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_WEP_KEY3_FORMAT ),
       
   164                                     ( TUint32& ) iKeyFormat[KThirdKey] ) );
       
   165 
       
   166         TRAP( err, wLanServiceTable->ReadUintL( TPtrC( WLAN_WEP_KEY4_FORMAT ),
       
   167                                     ( TUint32& ) iKeyFormat[KFourthKey] ) );
       
   168         }
       
   169     else
       
   170         {
       
   171         // silently ignore KErrNotFound. It is caused by incorrect DB,
       
   172         // we are 'repairing it' this way.
       
   173         if ( errorCode != KErrNotFound )
       
   174             {
       
   175             User::Leave( errorCode );
       
   176             }
       
   177         }
       
   178 
       
   179     CleanupStack::PopAndDestroy( wLanServiceTable );  // wLanServiceTable
       
   180     }
       
   181 
       
   182 
       
   183 // ---------------------------------------------------------
       
   184 // CWEPSecuritySettingsImpl::SaveL
       
   185 // ---------------------------------------------------------
       
   186 //
       
   187 void CWEPSecuritySettingsImpl::SaveL( TUint32 aIapId, 
       
   188                                       CCommsDatabase& aCommsDb ) const
       
   189     {
       
   190     CCommsDbTableView* wLanServiceTable;
       
   191 
       
   192     // Caller MUST initiate a transaction, WE WILL NOT.
       
   193 
       
   194     wLanServiceTable = aCommsDb.OpenViewMatchingUintLC( 
       
   195                     TPtrC( WLAN_SERVICE ), TPtrC( WLAN_SERVICE_ID ), aIapId );
       
   196     TInt errorCode = wLanServiceTable->GotoFirstRecord();
       
   197 
       
   198     if ( errorCode == KErrNone )
       
   199         {
       
   200         wLanServiceTable->UpdateRecord();
       
   201         }
       
   202     else
       
   203         {
       
   204         TUint32 dummyUid( KUidNone );
       
   205         User::LeaveIfError( wLanServiceTable->InsertRecord( dummyUid ) );
       
   206 
       
   207         // Save link to LAN service
       
   208         wLanServiceTable->WriteUintL( TPtrC( WLAN_SERVICE_ID ), aIapId );
       
   209         }
       
   210 
       
   211     // Save index of key in use
       
   212     wLanServiceTable->WriteUintL( TPtrC( WLAN_WEP_INDEX ), 
       
   213                                  ( TUint32& ) iKeyInUse );
       
   214 
       
   215     // Save index of key in use
       
   216     wLanServiceTable->WriteUintL( TPtrC( NU_WLAN_AUTHENTICATION_MODE ), 
       
   217                                  ( TUint32& ) iAuthentication );
       
   218 
       
   219     // Save first WEP key
       
   220     wLanServiceTable->WriteTextL( TPtrC( NU_WLAN_WEP_KEY1 ), 
       
   221                                   iKeyData[KFirstKey] );
       
   222 
       
   223     // Save second WEP key
       
   224     wLanServiceTable->WriteTextL( TPtrC( NU_WLAN_WEP_KEY2 ), 
       
   225                                   iKeyData[KSecondKey] );
       
   226 
       
   227     // Save third WEP key
       
   228     wLanServiceTable->WriteTextL( TPtrC( NU_WLAN_WEP_KEY3 ), 
       
   229                                   iKeyData[KThirdKey] );
       
   230 
       
   231     // Save fourth WEP key
       
   232     wLanServiceTable->WriteTextL( TPtrC( NU_WLAN_WEP_KEY4 ), 
       
   233                                   iKeyData[KFourthKey] );
       
   234 
       
   235     // Save the format of the keys
       
   236     wLanServiceTable->WriteUintL( TPtrC( WLAN_WEP_KEY1_FORMAT ), 
       
   237                                  ( TUint32& ) iKeyFormat[KFirstKey] );
       
   238 
       
   239     wLanServiceTable->WriteUintL( TPtrC( WLAN_WEP_KEY2_FORMAT ), 
       
   240                                  ( TUint32& ) iKeyFormat[KSecondKey] );
       
   241 
       
   242     wLanServiceTable->WriteUintL( TPtrC( WLAN_WEP_KEY3_FORMAT ), 
       
   243                                  ( TUint32& ) iKeyFormat[KThirdKey] );
       
   244 
       
   245     wLanServiceTable->WriteUintL( TPtrC( WLAN_WEP_KEY4_FORMAT ), 
       
   246                                  ( TUint32& ) iKeyFormat[KFourthKey] );
       
   247 
       
   248     wLanServiceTable->PutRecordChanges();
       
   249 
       
   250     CleanupStack::PopAndDestroy( wLanServiceTable );  // wLanServiceTable
       
   251     }
       
   252     
       
   253 
       
   254 // ---------------------------------------------------------
       
   255 // CWEPSecuritySettingsImpl::SetLenKeyDataFromText
       
   256 // ---------------------------------------------------------
       
   257 //
       
   258 void CWEPSecuritySettingsImpl::SetLenKeyDataFromText( const TInt aIndex )
       
   259     {
       
   260     const TUint keyDataLength = iKeyData[aIndex].Length();
       
   261 
       
   262     if ( keyDataLength == KKeyDataLength104Bits )
       
   263         {
       
   264         iKeyLength[aIndex] = CWEPSecuritySettings::E104Bits;
       
   265         }
       
   266     else if ( keyDataLength == KKeyDataLength232Bits && iIsWEP256Enabled )
       
   267         {
       
   268         iKeyLength[aIndex] = CWEPSecuritySettings::E232Bits;
       
   269         }
       
   270     else            // if ( aKeyDataLength == KKeyDataLength40Bits ) or any
       
   271         {           //  other case, by default
       
   272         iKeyLength[aIndex] = CWEPSecuritySettings::E40Bits;
       
   273         }
       
   274     }
       
   275 
       
   276 
       
   277 // ---------------------------------------------------------
       
   278 // CWEPSecuritySettingsImpl::IsValid
       
   279 // ---------------------------------------------------------
       
   280 //
       
   281 TBool CWEPSecuritySettingsImpl::IsValid()
       
   282     {
       
   283     return ( KeyData( KeyInUse() )->Length() == 
       
   284                         ExpectedLengthOfKeyData( KeyLength( KeyInUse() ) ) );
       
   285     }
       
   286 
       
   287 
       
   288 //----------------------------------------------------------
       
   289 // CWEPSecuritySettingsImpl::ExpectedLengthOfKeyData
       
   290 //----------------------------------------------------------
       
   291 //
       
   292 TInt CWEPSecuritySettingsImpl::ExpectedLengthOfKeyData( 
       
   293                                CWEPSecuritySettings::TWEPKeyLength aKeyLength )
       
   294     {
       
   295     TInt retVal;
       
   296 
       
   297     switch ( aKeyLength )
       
   298         {
       
   299         case CWEPSecuritySettings::E40Bits:
       
   300             {
       
   301             retVal = KKeyDataLength40Bits;
       
   302             break;
       
   303             }
       
   304 
       
   305         case CWEPSecuritySettings::E104Bits:
       
   306             {
       
   307             retVal = KKeyDataLength104Bits;
       
   308             break;
       
   309             }
       
   310 
       
   311         case CWEPSecuritySettings::E232Bits:
       
   312             {
       
   313             retVal = WEP256Enabled() ? KKeyDataLength232Bits : 0;
       
   314             break;
       
   315             }
       
   316 
       
   317         default:
       
   318             {
       
   319             retVal = 0;
       
   320             break;
       
   321             }
       
   322         }
       
   323 
       
   324     return retVal;
       
   325     }
       
   326  
       
   327 
       
   328 
       
   329 // ---------------------------------------------------------
       
   330 // CWEPSecuritySettingsImpl::SetKeyDataL
       
   331 // ---------------------------------------------------------
       
   332 //
       
   333 TInt CWEPSecuritySettingsImpl::SetKeyDataL( const TInt aElement, 
       
   334                                             const TDesC& aKeyData,
       
   335                                             const TBool aHex )
       
   336     {
       
   337     CWEPSecuritySettings::TWEPKeyFormat keyFormat = aHex ? 
       
   338                                     CWEPSecuritySettings::EHexadecimal : 
       
   339                                     CWEPSecuritySettings::EAscii;
       
   340     SetKeyFormat( aElement, keyFormat );
       
   341 
       
   342     TInt dataLength = aKeyData.Length();
       
   343     if ( dataLength == KKeyDataLength40Bits ||
       
   344          dataLength == KKeyDataLength40Bits / KAsciiHexRatio )
       
   345         {
       
   346         SetKeyLength( aElement, CWEPSecuritySettings::E40Bits );
       
   347         }
       
   348     else if ( dataLength == KKeyDataLength104Bits ||
       
   349          dataLength == KKeyDataLength104Bits / KAsciiHexRatio )
       
   350         {
       
   351         SetKeyLength( aElement, CWEPSecuritySettings::E104Bits );
       
   352         }
       
   353     else if ( dataLength == KKeyDataLength232Bits ||
       
   354          dataLength == KKeyDataLength232Bits / KAsciiHexRatio )
       
   355         {
       
   356         SetKeyLength( aElement, CWEPSecuritySettings::E232Bits );
       
   357         }
       
   358     else
       
   359         {
       
   360         return KErrInvalidLength;
       
   361         }
       
   362 
       
   363     TInt expectedLength = ExpectedLengthOfKeyData( KeyLength( aElement ) );
       
   364 
       
   365     if ( keyFormat == CWEPSecuritySettings::EAscii )
       
   366         {
       
   367         expectedLength /= KAsciiHexRatio; //Ascii key is half the length of Hex
       
   368         }
       
   369 
       
   370     HBufC8* buf8 = HBufC8::NewL( dataLength );
       
   371     CleanupStack::PushL( buf8 );
       
   372     buf8->Des().Copy( aKeyData ); 
       
   373 
       
   374     TInt errData = VerifyKeyData( *buf8, expectedLength, 
       
   375                                   KeyFormat( aElement ) );
       
   376     if ( errData == KErrNone )
       
   377         {
       
   378         if ( aHex )
       
   379             {
       
   380             SetKeyData( aElement, buf8->Des() );
       
   381             }
       
   382         else
       
   383             {
       
   384             HBufC8* buf8Conv = HBufC8::NewL( dataLength * KAsciiHexRatio );
       
   385                                 // Ascii key is half the length of Hex
       
   386             ConvertAsciiToHex( buf8->Des(), buf8Conv );
       
   387             SetKeyData( aElement, buf8Conv->Des() );
       
   388             delete buf8Conv;
       
   389             }
       
   390         }
       
   391 
       
   392     CleanupStack::PopAndDestroy( buf8 ); // buf8
       
   393 
       
   394     return errData;
       
   395     }
       
   396 
       
   397 
       
   398 //----------------------------------------------------------
       
   399 // CWEPSecuritySettingsImpl::VerifyKeyData
       
   400 //----------------------------------------------------------
       
   401 //
       
   402 TInt CWEPSecuritySettingsImpl::VerifyKeyData( const TDesC8& aTextToTest,
       
   403                                              TInt aLengthOfKeyData,
       
   404                             CWEPSecuritySettings::TWEPKeyFormat aWEPKeyFormat )
       
   405     {
       
   406     TInt err = KErrNone;
       
   407     TInt lengthOfText = aTextToTest.Length();
       
   408 
       
   409     if ( aTextToTest.Length() != aLengthOfKeyData )
       
   410         {
       
   411         err = KErrInvalidLength;
       
   412         }
       
   413     else if ( aWEPKeyFormat == CWEPSecuritySettings::EHexadecimal )
       
   414         {
       
   415         for ( TInt i = 0; i < lengthOfText; i++ )
       
   416             {
       
   417             TChar c ( aTextToTest[i] );
       
   418 
       
   419             if ( !c.IsHexDigit() ) 
       
   420                 {
       
   421                 err = KErrInvalidChar;
       
   422                 break;
       
   423                 }
       
   424             }
       
   425         }
       
   426 
       
   427     return err;
       
   428     }
       
   429 
       
   430 
       
   431 //----------------------------------------------------------
       
   432 // CWEPSecuritySettingsImpl::ConvertAsciiToHex
       
   433 //----------------------------------------------------------
       
   434 //
       
   435 void CWEPSecuritySettingsImpl::ConvertAsciiToHex( const TDesC8& aSource, 
       
   436                                                   HBufC8*& aDest )
       
   437 	{
       
   438 	_LIT( hex, "0123456789ABCDEF" );
       
   439 	TInt size = aSource.Size();
       
   440 	TPtr8 ptr = aDest->Des();
       
   441 	for ( TInt ii = 0; ii < size; ii++ )
       
   442 		{
       
   443 		TText8 ch = aSource[ii];
       
   444 		ptr.Append( hex()[(ch/16)&0x0f] );
       
   445 		ptr.Append( hex()[ch&0x0f] );
       
   446 		}
       
   447 	}
       
   448 
       
   449 
       
   450 // ---------------------------------------------------------
       
   451 // CWEPSecuritySettingsImpl::LoadL
       
   452 // ---------------------------------------------------------
       
   453 //
       
   454 void CWEPSecuritySettingsImpl::LoadL( TUint32 aIapId, 
       
   455                                       CMDBSession& aSession )
       
   456     {
       
   457     
       
   458     if ( aIapId == KUidNone )
       
   459         {
       
   460         return;
       
   461         }
       
   462     
       
   463     // Load WLAN service table
       
   464     // first get WLAN table id
       
   465     CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*>
       
   466         ( CCDRecordBase::RecordFactoryL( 0 ) );
       
   467     CleanupStack::PushL( generic );    
       
   468     generic->InitializeL( TPtrC( WLAN_SERVICE ), NULL );
       
   469     generic->LoadL( aSession );
       
   470     TMDBElementId wlanTableId = generic->TableId();
       
   471     
       
   472     CMDBField<TUint32>* sidField = static_cast<CMDBField<TUint32>*>
       
   473                                     (generic->GetFieldByIdL( KCDTIdWlanServiceId));
       
   474     
       
   475     // prime with service id                
       
   476     *sidField = aIapId;
       
   477 
       
   478     if( generic->FindL( aSession) )
       
   479         {
       
   480         // get the values
       
   481         CMDBField<TUint>* keyInUseField = static_cast<CMDBField<TUint>*>
       
   482                             ( generic->GetFieldByIdL( KCDTIdWlanWepIndex ) );
       
   483         ( TUint32& )iKeyInUse = *keyInUseField;
       
   484         CMDBField<TUint>* authenticationField = static_cast<CMDBField<TUint>*>
       
   485                             ( generic->GetFieldByIdL( KCDTIdWlanAuthMode ) );
       
   486         ( TUint32& )iAuthentication = *authenticationField;
       
   487         
       
   488         CMDBField<TDesC8>* wepKey1Field = static_cast<CMDBField<TDesC8>*>
       
   489                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey1 ) );
       
   490         iKeyData[ KFirstKey ] = *wepKey1Field;
       
   491         SetLenKeyDataFromText( KFirstKey );
       
   492         
       
   493         CMDBField<TDesC8>* wepKey2Field = static_cast<CMDBField<TDesC8>*>
       
   494                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey2 ) );
       
   495         iKeyData[ KSecondKey ] = *wepKey2Field;
       
   496         SetLenKeyDataFromText( KSecondKey );
       
   497         
       
   498         CMDBField<TDesC8>* wepKey3Field = static_cast<CMDBField<TDesC8>*>
       
   499                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey3 ) );
       
   500         iKeyData[ KThirdKey ] = *wepKey3Field;
       
   501         SetLenKeyDataFromText( KThirdKey );
       
   502         
       
   503         CMDBField<TDesC8>* wepKey4Field = static_cast<CMDBField<TDesC8>*>
       
   504                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey4 ) );
       
   505         iKeyData[ KFourthKey ] = *wepKey4Field;
       
   506         SetLenKeyDataFromText( KFourthKey );
       
   507         
       
   508         CMDBField<TUint>* formatKey1Field = static_cast<CMDBField<TUint>*>
       
   509                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey1 ) );
       
   510         ( TUint32& )iKeyFormat[ KFirstKey ] = *formatKey1Field;
       
   511         CMDBField<TUint>* formatKey2Field = static_cast<CMDBField<TUint>*>
       
   512                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey2 ) );
       
   513         ( TUint32& )iKeyFormat[ KSecondKey ] = *formatKey2Field;
       
   514         CMDBField<TUint>* formatKey3Field = static_cast<CMDBField<TUint>*>
       
   515                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey3 ) );
       
   516         ( TUint32& )iKeyFormat[ KThirdKey ] = *formatKey3Field;
       
   517         CMDBField<TUint>* formatKey4Field = static_cast<CMDBField<TUint>*>
       
   518                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey4 ) );
       
   519         ( TUint32& )iKeyFormat[ KFourthKey ] = *formatKey4Field;
       
   520         }
       
   521 
       
   522     CleanupStack::PopAndDestroy( generic );
       
   523     
       
   524     }
       
   525     
       
   526 
       
   527 // ---------------------------------------------------------
       
   528 // CWEPSecuritySettingsImpl::SaveL
       
   529 // ---------------------------------------------------------
       
   530 //
       
   531 void CWEPSecuritySettingsImpl::SaveL( TUint32 aIapId, 
       
   532                                       CMDBSession& aSession ) const
       
   533     {
       
   534     // Load WLAN service table
       
   535     // first get WLAN table id
       
   536     CMDBGenericRecord* generic = static_cast<CMDBGenericRecord*>
       
   537         ( CCDRecordBase::RecordFactoryL( 0 ) );
       
   538     CleanupStack::PushL( generic );    
       
   539     generic->InitializeL( TPtrC( WLAN_SERVICE ), NULL );
       
   540     generic->LoadL( aSession );
       
   541     TMDBElementId wlanTableId = generic->TableId();
       
   542     
       
   543     CMDBField<TUint32>* sidField = static_cast<CMDBField<TUint32>*>
       
   544                              ( generic->GetFieldByIdL( KCDTIdWlanServiceId ) );
       
   545     
       
   546     // prime with service id                
       
   547     *sidField = aIapId;
       
   548     
       
   549     TBool found = generic->FindL( aSession);
       
   550    
       
   551     // If loading failed, WLAN service record will be 
       
   552     // created and StoreL()-d, otherwise, ModifyL()
       
   553     
       
   554     CMDBField<TUint>* keyInUseField = static_cast<CMDBField<TUint>*>
       
   555                             ( generic->GetFieldByIdL( KCDTIdWlanWepIndex ) );
       
   556     keyInUseField->SetL( iKeyInUse );
       
   557 
       
   558     CMDBField<TUint>* authenticationField = static_cast<CMDBField<TUint>*>
       
   559                             ( generic->GetFieldByIdL( KCDTIdWlanAuthMode ) );
       
   560     authenticationField->SetL( iAuthentication );
       
   561     
       
   562     CMDBField<TDesC8>* wepKey1Field = static_cast<CMDBField<TDesC8>*>
       
   563                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey1 ) );
       
   564     wepKey1Field->SetL( iKeyData[ KFirstKey ] );
       
   565     CMDBField<TDesC8>* wepKey2Field = static_cast<CMDBField<TDesC8>*>
       
   566                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey2 ) );
       
   567     wepKey2Field->SetL( iKeyData[ KSecondKey ] );
       
   568     CMDBField<TDesC8>* wepKey3Field = static_cast<CMDBField<TDesC8>*>
       
   569                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey3 ) );
       
   570     wepKey3Field->SetL( iKeyData[ KThirdKey ] );
       
   571     CMDBField<TDesC8>* wepKey4Field = static_cast<CMDBField<TDesC8>*>
       
   572                         ( generic->GetFieldByIdL( KCDTIdWlanWepKey4 ) );
       
   573     wepKey4Field->SetL( iKeyData[ KFourthKey ] );
       
   574     
       
   575     CMDBField<TUint>* formatKey1Field = static_cast<CMDBField<TUint>*>
       
   576                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey1 ) );
       
   577     formatKey1Field->SetL( iKeyFormat[ KFirstKey ] );
       
   578     CMDBField<TUint>* formatKey2Field = static_cast<CMDBField<TUint>*>
       
   579                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey2 ) );
       
   580     formatKey2Field->SetL( iKeyFormat[ KSecondKey ] );
       
   581     CMDBField<TUint>* formatKey3Field = static_cast<CMDBField<TUint>*>
       
   582                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey3 ) );
       
   583     formatKey3Field->SetL( iKeyFormat[ KThirdKey ] );
       
   584     CMDBField<TUint>* formatKey4Field = static_cast<CMDBField<TUint>*>
       
   585                             ( generic->GetFieldByIdL( KCDTIdWlanFormatKey4 ) );
       
   586     formatKey4Field->SetL( iKeyFormat[ KFourthKey ] );
       
   587     
       
   588     // If table existed modify it
       
   589     if( found )
       
   590         {
       
   591         generic->ModifyL( aSession );
       
   592         }
       
   593     // Otherwise store a new record
       
   594     else
       
   595         {
       
   596         generic->SetRecordId( KCDNewRecordRequest );
       
   597         generic->StoreL( aSession );
       
   598         }
       
   599     CleanupStack::PopAndDestroy( generic );
       
   600     }
       
   601 
       
   602 
       
   603 // End of File