omadm/omadmextensions/adapters/nsmldinternet/src/NSmlWlanSettings.cpp
changeset 1 4490afcb47b1
equal deleted inserted replaced
0:3ce708148e4d 1:4490afcb47b1
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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:   Wlan Adapter DB handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    22 #include <commsdat_partner.h>
       
    23 #endif
       
    24 #include <WlanCdbCols.h>
       
    25 #include "NSmlWlanSettings.h"
       
    26 #include "NSmlWLanAdapter.h"
       
    27 #include "nsmldebug.h"
       
    28 #include <comms-infras/commdb/protection/protectdb.h>
       
    29 #include <SettingEnforcementInfo.h> // vsettingenforcementinfo
       
    30 #include <featmgr.h>
       
    31 
       
    32 #ifndef __WINS__
       
    33 // This lowers the unnecessary compiler warning (armv5) to remark.
       
    34 // "Warning:  #174-D: expression has no effect..." is caused by 
       
    35 // DBG_ARGS8 macro in no-debug builds.
       
    36 #pragma diag_remark 174
       
    37 #endif
       
    38 
       
    39 const TUint KEAPListBufferSize = 128;
       
    40 const TUint KLengthOfOldStyleEAPListEntry = 5; // "+xxx,"
       
    41 
       
    42 const TInt KBeginTransRetryDelay = 1000000; // Delay for comms db begintransaction retry (microseconds)
       
    43 const  TInt KBeginTransRetryCount = 7;      // Maximum number of retries
       
    44 //-----------------------------------------------------------------------------
       
    45 // CWlanAdapter::CWlanSettings( CCommsDatabase& aDatabase )
       
    46 //-----------------------------------------------------------------------------
       
    47 CWlanSettings::CWlanSettings( CCommsDatabase& aDatabase ) : iDatabase( aDatabase ), iExpandedEAPTypeFieldsUsed( ETrue )
       
    48 	{
       
    49 	_DBG_FILE("CWlanSettings::CWlanSettings(): begin");
       
    50 
       
    51 	iTableView = 0;
       
    52 	iEapType = NULL;
       
    53 	iSecondaryView = NULL;
       
    54 
       
    55 
       
    56 	_DBG_FILE("CWlanSettings::CWlanSettings(): end");
       
    57 	}
       
    58 
       
    59 //-----------------------------------------------------------------------------
       
    60 // CWlanAdapter::~CWlanSettings( )
       
    61 //-----------------------------------------------------------------------------
       
    62 CWlanSettings::~CWlanSettings( )
       
    63 	{
       
    64 
       
    65 	delete iEapType;
       
    66 	delete iSecondaryView;
       
    67 	delete iTableView;
       
    68 	}
       
    69 
       
    70 //-----------------------------------------------------------------------------
       
    71 // CWlanSettings* CWlanSettings::NewL( CCommsDatabase& aDatabase )
       
    72 //-----------------------------------------------------------------------------
       
    73 CWlanSettings* CWlanSettings::NewL( CCommsDatabase& aDatabase )
       
    74 	{
       
    75 	_DBG_FILE("CWlanSettings::NewL(): begin");
       
    76 
       
    77 	CWlanSettings* self = new(ELeave) CWlanSettings( aDatabase );
       
    78 
       
    79 	CleanupStack::PushL( self );
       
    80 	self->ConstructL( );
       
    81 	CleanupStack::Pop( self );
       
    82 
       
    83 	_DBG_FILE("CWlanSettings::NewL(): end");
       
    84 	return self;
       
    85 	}
       
    86 
       
    87 //-----------------------------------------------------------------------------
       
    88 // void CWlanSettings::ConstructL( )
       
    89 //-----------------------------------------------------------------------------
       
    90 void CWlanSettings::ConstructL( )
       
    91 {
       
    92 	_DBG_FILE("CWlanSettings::ConstructL(): begin");
       
    93 	_DBG_FILE("CWlanSettings::ConstructL(): end");
       
    94 }
       
    95 
       
    96 
       
    97 //-----------------------------------------------------------------------------
       
    98 // TInt CWlanSettings::GetWlanSettings( TUint32 aLuid, TWlanSettings& aWlanSettings )
       
    99 //-----------------------------------------------------------------------------
       
   100 TInt CWlanSettings::GetWlanSettings( TUint32 aLuid, TWlanSettings& aWlanSettings )
       
   101 	{
       
   102 	_DBG_FILE("CWlanSettings::GetWlanSettings(): begin");
       
   103 
       
   104 	TRAPD( err, ConnectToDatabaseL() );
       
   105 	if( err == KErrNone )
       
   106 		{
       
   107 		err = GoToRecord( aLuid );
       
   108 
       
   109 		if( err == KErrNone )
       
   110 			{
       
   111 			TRAP( err, GetDataFromRecordL( &aWlanSettings ) );			
       
   112 			}
       
   113 		}
       
   114 
       
   115 	_DBG_FILE("CWlanSettings::GetWlanSettings(): end");
       
   116 	return err;
       
   117 	}
       
   118 	
       
   119 
       
   120 //-----------------------------------------------------------------------------
       
   121 // TInt CWlanSettings::GetEapSettings( TInt aId, TWlanSettings& aWlanSettings )
       
   122 //-----------------------------------------------------------------------------
       
   123 TInt CWlanSettings::GetEAPSettings( const TInt aId, const TInt aEapType, const TInt aTunnelingType, EAPSettings& aEapSettings )
       
   124 	{
       
   125 	_DBG_FILE("CWlanSettings::GetEapSettings(): begin");
       
   126 	DBG_ARGS(_S16("aId=%d, eEapType=%d"), aId, aEapType);
       
   127 
       
   128 	TRAPD( err, GetEAPInterfaceL(aId, aTunnelingType, aEapType) );
       
   129 	DBG_ARGS(_S16("GetEAPInterfaceL leaved with %d"), err);
       
   130 	if( err == KErrNone )
       
   131 		{
       
   132 		TRAP(err, iEapType->GetConfigurationL(aEapSettings));
       
   133     	DBG_ARGS(_S16("iEapType->GetConfigurationL leaved with %d"), err);
       
   134 		}
       
   135 		
       
   136 	_DBG_FILE("CWlanSettings::GetEAPSettings(): end");
       
   137 	return err;
       
   138 	}
       
   139 
       
   140 
       
   141 //-----------------------------------------------------------------------------
       
   142 // TInt CWlanSettings::DeleteWlanSettings( TUint32 aLuid )
       
   143 //-----------------------------------------------------------------------------
       
   144 TInt CWlanSettings::DeleteWlanSettings( TUint32 aLuid )
       
   145 	{
       
   146 	_DBG_FILE("CWlanSettings::DeleteWlanSettings(): begin");
       
   147 	TBool wlanEnforce = EFalse;
       
   148 	TInt tableLockError= KErrNone;
       
   149 	
       
   150     if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   151         {
       
   152         TInt enError = KErrNone;
       
   153         TRAP(enError, wlanEnforce=CheckEnforcementL());
       
   154         DBG_ARGS(_S16("CWlanSettings::DeleteWLANSettings, check enforcement failed. error: <%D>"), enError );
       
   155         if(wlanEnforce)
       
   156             {
       
   157             _DBG_FILE("CWlanSettings::WriteWlanSettings(): wlan enforce is ON ");
       
   158             TRAPD(lockError,tableLockError = PerformLockWLANTablesL(EFalse));
       
   159             if(lockError == KErrNone && tableLockError == KErrNone)
       
   160                 {
       
   161                 _DBG_FILE("CWlanSettings::WriteWlanSettings(): Table unlcoked successfully ");
       
   162                 iWLANRelock = ETrue;	
       
   163                 }
       
   164             }
       
   165         }
       
   166  	
       
   167 	TRAPD( err, ConnectToDatabaseL() );
       
   168 	if( err == KErrNone )
       
   169 		{
       
   170 		err = GoToRecord( aLuid );
       
   171 		if( err == KErrNone )
       
   172 			{
       
   173 			
       
   174 			if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   175 			    {
       
   176 			    if(wlanEnforce)
       
   177 			        {
       
   178 			        ((CCommsDbProtectTableView*)iTableView)->UnprotectRecord();
       
   179 			        }
       
   180 			    }
       
   181 
       
   182 			
       
   183 			TInt err = iTableView->UpdateRecord( );
       
   184 	        if( err == KErrLocked )
       
   185 	             {
       
   186 	             _DBG_FILE("DeleteWlanSettings: UpdateRecord was locked.");
       
   187 	             TInt retry = KBeginTransRetryCount;            
       
   188 	             while ( retry > 0 && err == KErrLocked )
       
   189 	                 {
       
   190 	                 User::After(KBeginTransRetryDelay);
       
   191 	                 _DBG_FILE("DeleteWlanSettings: Slept 1 second. Try again");
       
   192 	                 err = iTableView->UpdateRecord();	                 
       
   193 	                 retry--;
       
   194 	                 }      	                           
       
   195                  if( err != KErrNone )
       
   196                      {
       
   197                      _DBG_FILE("DeleteWlanSettings: UpdateRecord was unsuccessful");
       
   198                      }			
       
   199                  else
       
   200                      {
       
   201                      _DBG_FILE("DeleteWlanSettings: UpdateRecord was successful");
       
   202                      }
       
   203 	             }			
       
   204 			
       
   205 			if( err == KErrNone )
       
   206 				{
       
   207 				TRAP( err, iTableView->WriteUintL( TPtrC(WLAN_SERVICE_ID), 0 ) );
       
   208 				if( err != KErrNone )
       
   209 					{
       
   210 					if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   211 					    {
       
   212 					    TInt tableLockError= KErrNone;
       
   213 					    if(iWLANRelock)
       
   214 					        {
       
   215 					        TInt lockError = KErrNone;
       
   216 					        TRAP(lockError,tableLockError = PerformLockWLANTablesL(ETrue));
       
   217 					        ((CCommsDbProtectTableView*)iTableView)->ProtectRecord();
       
   218 					        DBG_ARGS(_S16("CWlanSettings::DeleteWLANSettings, WLAN table Lock error. error: <%D>, <%D> "), lockError,tableLockError );
       
   219 					        iWLANRelock =EFalse;		             
       
   220 					        }
       
   221 					    if ( tableLockError != KErrNone ) // to remove warnings
       
   222 					        {
       
   223 					        tableLockError = KErrNone;
       
   224 					        }
       
   225 					    }
       
   226 					return err;
       
   227 					}
       
   228 				}
       
   229 			err = iTableView->PutRecordChanges( );
       
   230 			if( err == KErrLocked )
       
   231                 {
       
   232                 _DBG_FILE("DeleteWlanSettings: PutRecordChanges was locked.");
       
   233                 TInt retry = KBeginTransRetryCount;            
       
   234                 while ( retry > 0 && err == KErrLocked )
       
   235                     {
       
   236                     User::After(KBeginTransRetryDelay);
       
   237                     _DBG_FILE("DeleteWlanSettings: Slept 1 second. Try again");
       
   238                     err = iTableView->PutRecordChanges();
       
   239                     retry--;
       
   240                     }                                     
       
   241                 if( err != KErrNone )
       
   242                     {
       
   243                     _DBG_FILE("DeleteWlanSettings: PutRecordChanges was unsuccessful");
       
   244                     }
       
   245                 else
       
   246                     {
       
   247                     _DBG_FILE("DeleteWlanSettings: PutRecordChanges was successful");
       
   248                     }
       
   249                 }
       
   250 			
       
   251 			if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   252 			    {
       
   253 				TInt tableLockError= KErrNone;
       
   254 				if(iWLANRelock)
       
   255 					{
       
   256 					TInt lockError = KErrNone;
       
   257 					TRAP(lockError,tableLockError = PerformLockWLANTablesL(ETrue));
       
   258 					DBG_ARGS(_S16("CWlanSettings::DeleteWLANSettings, WLAN table Lock error. error: <%D>, <%D> "), lockError,tableLockError );
       
   259 					((CCommsDbProtectTableView*)iTableView)->ProtectRecord();
       
   260 					iWLANRelock =EFalse;
       
   261 					}
       
   262 				if ( tableLockError != KErrNone ) // to remove warnings
       
   263 				    {
       
   264 				    tableLockError = KErrNone;
       
   265 				    }
       
   266 			    }   
       
   267 
       
   268 			
       
   269 			if ( err == KErrNone )
       
   270 				{
       
   271 				// Ignore err on purpose
       
   272 				TRAP( err, DeleteSecondarySSIDsL( aLuid ) );				
       
   273     	                    
       
   274 	            TRAP( err, DeleteWlanEapSettingsL( aLuid ) );
       
   275 				}            
       
   276 			}
       
   277 		}
       
   278 
       
   279 
       
   280 	_DBG_FILE("CWlanSettings::DeleteWlanSettings(): end");
       
   281 	if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   282 	    {
       
   283 	    if(iWLANRelock)
       
   284 		    {
       
   285 		    TInt lockError = KErrNone;
       
   286 		    TRAP(lockError,tableLockError = PerformLockWLANTablesL(ETrue));
       
   287 	        DBG_ARGS(_S16("CWlanSettings::DeleteWLANSettings, WLAN table Lock error. error: <%D>, <%D> "), lockError,tableLockError );
       
   288 	        ((CCommsDbProtectTableView*)iTableView)->ProtectRecord();
       
   289 	        iWLANRelock =EFalse;		   
       
   290 		    }
       
   291 	    }
       
   292 	
       
   293 	if (wlanEnforce) 
       
   294 		wlanEnforce = EFalse; // to get rid of warnings
       
   295 	return err;
       
   296 	}
       
   297 
       
   298 
       
   299 
       
   300 
       
   301 TInt CWlanSettings::DeleteOneSecondarySSIDL( TUint32 aWLANId , TUint32 asecId)
       
   302 {
       
   303   
       
   304   	   TInt retval = KErrNone;
       
   305         SetSecondaryViewToRecordL(aWLANId);
       
   306     	retval = iSecondaryView->GotoFirstRecord();
       
   307           
       
   308        while (retval == KErrNone)
       
   309         {
       
   310         TSecondarySSID ssid;
       
   311         TRAP(retval, iSecondaryView->ReadUintL( TPtrC(WLAN_SEC_SSID_ID ),  ssid.Id ));
       
   312         if(ssid.Id == asecId)
       
   313             {
       
   314             //retval = iSecondaryView->UpdateRecord();
       
   315             //if( retval==KErrNone )
       
   316               //  {
       
   317             if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   318                 {
       
   319     			TBool wlanEnforce = EFalse;
       
   320     			TInt enError = KErrNone;
       
   321     			TRAP(enError, wlanEnforce=CheckEnforcementL());
       
   322     			DBG_ARGS(_S16("CWlanSettings::DeleteWLANSettings, check enforcement failed. error: <%D>"), enError );
       
   323     			if(wlanEnforce)
       
   324     				{
       
   325     				((CCommsDbProtectTableView*)iSecondaryView)->UnprotectRecord();
       
   326     				}
       
   327                 }
       
   328 
       
   329             retval = iSecondaryView->DeleteRecord();
       
   330             if( retval == KErrLocked )
       
   331                 {
       
   332                 _DBG_FILE("DeleteOneSecondarySSIDL: DeleteRecord was locked.");
       
   333                 TInt retry = KBeginTransRetryCount;            
       
   334                 while ( retry > 0 && retval == KErrLocked )
       
   335                     {
       
   336                     User::After(KBeginTransRetryDelay);
       
   337                     _DBG_FILE("DeleteOneSecondarySSIDL: Slept 1 second. Try again");
       
   338                     retval = iSecondaryView->DeleteRecord();
       
   339                     retry--;
       
   340                     }                                    
       
   341                 if( retval != KErrNone )
       
   342                     {
       
   343                     _DBG_FILE("DeleteOneSecondarySSIDL: DeleteRecord was unsuccessful");
       
   344                     }
       
   345                 else
       
   346                     {
       
   347                     _DBG_FILE("DeleteOneSecondarySSIDL: DeleteRecord was successful");
       
   348                     }
       
   349                 }
       
   350                 DBG_ARGS(_S16("CWlanSettings::DeleteOneSecondarySSIDL, Secondaryssid delete error: <%D> "), retval );
       
   351 
       
   352                 //    iTableView->PutRecordChanges( );
       
   353                 //}
       
   354 
       
   355         	break;
       
   356        	}
       
   357         
       
   358         retval = iSecondaryView->GotoNextRecord();
       
   359         }
       
   360         
       
   361 	return retval;
       
   362 }
       
   363 
       
   364 TInt CWlanSettings::DeleteSecondarySSIDsL( TUint32 aWLANId )
       
   365     {
       
   366     TInt retVal(KErrNone);
       
   367 	if (iSecondaryView == NULL)
       
   368 	    {
       
   369 	    SetSecondaryViewToRecordL(aWLANId);
       
   370 	    }
       
   371 	else 
       
   372 	    {
       
   373 	    retVal = iSecondaryView->GotoFirstRecord();
       
   374 	    TUint32 secId = 0;
       
   375 	    if (retVal == KErrNone)
       
   376 	        {
       
   377 	        iSecondaryView->ReadUintL( TPtrC(WLAN_SEC_SSID_SERVICE_ID), secId );
       
   378 	        }
       
   379 	    if (secId != aWLANId)
       
   380 	        {
       
   381 	        SetSecondaryViewToRecordL(aWLANId);
       
   382 	        }
       
   383 	    }
       
   384 	    
       
   385     TInt err = iSecondaryView->GotoFirstRecord();
       
   386     while (err == KErrNone)
       
   387         {
       
   388         if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   389             {
       
   390 			TBool wlanEnforce = EFalse;
       
   391 			TInt enError = KErrNone;
       
   392 			TRAP(enError, wlanEnforce=CheckEnforcementL());
       
   393 			DBG_ARGS(_S16("CWlanSettings::DeleteSecondarySSIDsL, check enforcement failed. error: <%D>"), enError );
       
   394 			if(wlanEnforce)
       
   395 				{
       
   396 				((CCommsDbProtectTableView*)iSecondaryView)->UnprotectRecord();
       
   397 				}
       
   398             }
       
   399 		retVal = iSecondaryView->DeleteRecord();
       
   400         if( retVal == KErrLocked )
       
   401              {
       
   402              _DBG_FILE("DeleteSecondarySSIDsL: DeleteRecord was locked.");
       
   403              TInt retry = KBeginTransRetryCount;            
       
   404              while ( retry > 0 && retVal == KErrLocked )
       
   405                  {
       
   406                  User::After(KBeginTransRetryDelay);
       
   407                  _DBG_FILE("DeleteSecondarySSIDsL: Slept 1 second. Try again");
       
   408                  retVal = iSecondaryView->DeleteRecord();
       
   409                  retry--;
       
   410                  }                                   
       
   411              if( retVal != KErrNone )
       
   412                  {
       
   413                  _DBG_FILE("DeleteSecondarySSIDsL: DeleteRecord was unsuccessful");
       
   414                  }
       
   415              else
       
   416                  {
       
   417                  _DBG_FILE("DeleteSecondarySSIDsL: DeleteRecord was successful");     
       
   418                  }
       
   419              }
       
   420 		DBG_ARGS(_S16("CWlanSettings::DeleteSecondarySSIDsL, Secondaryssid delete error: <%D> "), retVal );
       
   421 
       
   422 		err = iSecondaryView->GotoNextRecord();
       
   423         }
       
   424     
       
   425     return retVal;
       
   426     }
       
   427 //-----------------------------------------------------------------------------
       
   428 // TInt CWlanSettings::DeleteEapSettings( TInt aWlanId, TInt aEapType )
       
   429 //-----------------------------------------------------------------------------
       
   430 TInt CWlanSettings::DeleteEAPSettings( TInt aWlanId, TInt aEapType  )
       
   431 	{
       
   432 	_DBG_FILE("CWlanSettings::DeleteEAPSettings(): begin");
       
   433 
       
   434 	TRAPD( err, GetEAPInterfaceL(aWlanId, EAPSettings::EEapNone, aEapType) );
       
   435 	if( err == KErrNone )
       
   436 		{
       
   437 		TRAP( err, iEapType->DeleteConfigurationL());
       
   438 		if( err != KErrNone )
       
   439 		    {
       
   440 		    DBG_ARGS(_S16("CWlanSettings::DeleteEAPSettings, delete failed, error: <%D> "), err );
       
   441 			return err;
       
   442 		    }
       
   443 		}
       
   444 
       
   445 	_DBG_FILE("CWlanSettings::DeleteEAPSettings(): end");
       
   446 	return err;
       
   447 	}
       
   448 
       
   449 //-----------------------------------------------------------------------------
       
   450 // TInt CWlanSettings::DeleteWlanEapSettings( TInt aWlanId )
       
   451 // Deletes all EAPs from a Wlan
       
   452 //-----------------------------------------------------------------------------
       
   453 void CWlanSettings::DeleteWlanEapSettingsL( TInt aWlanId )
       
   454 	{
       
   455 	_DBG_FILE("CWlanSettings::DeleteWlanEapSettings(): begin");    
       
   456     TInt retVal( KErrNone );
       
   457     TInt err( KErrNone );
       
   458 
       
   459     // List EAP implementations and call deletion for those that are not encapsulated
       
   460 	
       
   461 	RImplInfoPtrArray ecomInfoArray;
       
   462 	REComSession::ListImplementationsL( KEapTypeInterfaceUid, ecomInfoArray );	
       
   463 	TUint eapId;
       
   464 	for (TInt i = 0; i < ecomInfoArray.Count(); i++)
       
   465 		{
       
   466 		if ( !CEapType::IsDisallowedOutsidePEAP( *ecomInfoArray[i] ) )
       
   467 			{
       
   468 			// Not encapsulated method. Settings can be deleted.
       
   469 			if ( ecomInfoArray[i]->DataType().Length() == KExpandedEAPIdLength)
       
   470 				{				
       
   471 				// The EAP ID is in expanded type format
       
   472 				eapId = ecomInfoArray[i]->DataType()[7];				
       
   473 				}
       
   474 			else
       
   475 				{
       
   476 				// The EAP ID is in old 8-bit format (as string)
       
   477 				TLex8 lex( ecomInfoArray[i]->DataType() );
       
   478         		lex.Val( eapId );        		        		
       
   479 				}
       
   480 			err = DeleteEAPSettings( aWlanId, eapId );				
       
   481 			if ( err != KErrNone )
       
   482 				{
       
   483 				retVal = err;
       
   484 				}
       
   485 			}
       
   486 		}
       
   487 	ecomInfoArray.ResetAndDestroy();
       
   488 	User::LeaveIfError (retVal);
       
   489 		
       
   490 	_DBG_FILE("CWlanSettings::DeleteWlanEapSettings(): end");	
       
   491 	}
       
   492 
       
   493 
       
   494 
       
   495 //-----------------------------------------------------------------------------
       
   496 // TInt CWlanSettings::WriteWlanSettings( TWlanSettings& aWlanSettings )
       
   497 //-----------------------------------------------------------------------------
       
   498 TInt CWlanSettings::WriteWlanSettings( TWlanSettings& aWlanSettings )
       
   499 	{
       
   500 	_DBG_FILE("CWlanSettings::WriteWlanSettings(): begin");
       
   501 
       
   502 	TInt err = 0;
       
   503 	TInt enError= KErrNone;
       
   504 	iServiceID = aWlanSettings.ServiceID; 
       
   505 	TBool wlanEnforce = EFalse;
       
   506 
       
   507 	if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   508 	    {
       
   509 	    TRAP(enError, wlanEnforce=CheckEnforcementL());
       
   510 	    DBG_ARGS(_S16("CWlanSettings::WriteWlanSettings, check enforcement . error: <%D>"), enError );
       
   511 	    if(wlanEnforce)
       
   512 	        {
       
   513 	        TRAPD(lockError,enError = PerformLockWLANTablesL(EFalse));
       
   514 	        if(lockError == KErrNone && enError == KErrNone)
       
   515 	            {
       
   516 	            iWLANRelock = ETrue;	
       
   517 	            }
       
   518 	        }
       
   519 	    }
       
   520 	
       
   521 	if( RecordExists( aWlanSettings.ServiceID ) <= 0 )
       
   522 		{
       
   523 		err = iTableView->InsertRecord( aWlanSettings.Id );			           
       
   524         if( err == KErrLocked )
       
   525             {
       
   526             _DBG_FILE("WriteWlanSettings InsertRecord: CommsDat was locked.");
       
   527             TInt retry = KBeginTransRetryCount;            
       
   528             while ( retry > 0 && err == KErrLocked )
       
   529                 {
       
   530                 User::After(KBeginTransRetryDelay);
       
   531                 _DBG_FILE("WriteWlanSettings: Slept 1 second. Try again");
       
   532                 err = iTableView->InsertRecord( aWlanSettings.Id ); 
       
   533                 retry--;
       
   534                 }      
       
   535             }        
       
   536 		
       
   537 		if( err != KErrNone )
       
   538 			{
       
   539 			DBG_ARGS(_S16("CWlanSettings::WriteWlanSettings(): - InsertRecord failed. error: <%D>"), err );
       
   540 		
       
   541 			if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   542 			    {
       
   543 			    TInt tableLockError= KErrNone;
       
   544 			    if(iWLANRelock)
       
   545 			        {
       
   546 			        TInt lockError = KErrNone;
       
   547 			        TRAP(lockError,tableLockError = PerformLockWLANTablesL(ETrue));
       
   548 			        DBG_ARGS(_S16("CWlanSettings::WriteWlanSettings, WLAN table Lock error. error: <%D>, <%D> "), lockError,tableLockError );
       
   549 			        iWLANRelock =EFalse;
       
   550 			        }
       
   551 			    if ( tableLockError != KErrNone ) // to remove warnings
       
   552 			        {
       
   553 			        tableLockError = KErrNone;
       
   554 			        }
       
   555 			    }
       
   556 			return err;
       
   557 			}
       
   558 		TRAP( err, InitialiseRecordL() );
       
   559 		if( err != KErrNone )
       
   560 			{
       
   561 			DBG_ARGS(_S16("CWlanSettings::WriteWlanSettings(): - InitialiseRecord failed. error: <%D>"), err );
       
   562 		
       
   563 			if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   564 			    {
       
   565 			    TInt tableLockError= KErrNone;
       
   566 			    if(iWLANRelock)
       
   567 			        {
       
   568 			        TInt lockError = KErrNone;
       
   569 			        TRAP(lockError,tableLockError = PerformLockWLANTablesL(ETrue));
       
   570 			        DBG_ARGS(_S16("CWlanSettings::WriteWlanSettings, WLAN table Lock error. error: <%D>, <%D> "), lockError,tableLockError );
       
   571 			        iWLANRelock =EFalse;
       
   572 			        }
       
   573 			    if ( tableLockError != KErrNone ) // to remove warnings
       
   574 			        {
       
   575 			        tableLockError = KErrNone;
       
   576 			        }
       
   577 			    }
       
   578 			return err;
       
   579 			}
       
   580 		}
       
   581 	else
       
   582 		{
       
   583 		err = GoToRecord( aWlanSettings.ServiceID );
       
   584 		if( err == KErrNone )
       
   585 			{
       
   586 			
       
   587 			if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   588 			    {
       
   589 				if ( wlanEnforce )
       
   590 					{
       
   591 					_DBG_FILE("CWlanSettings::WriteWlanSettings(): unprotect wlan");
       
   592 					((CCommsDbProtectTableView*)iTableView)->UnprotectRecord(); 
       
   593 					}
       
   594 			    }
       
   595 
       
   596 			
       
   597 			err = iTableView->UpdateRecord( );
       
   598             if( err == KErrLocked )
       
   599                 {
       
   600                 _DBG_FILE("WriteWlanSettings: UpdateRecord was locked.");
       
   601                 TInt retry = KBeginTransRetryCount;            
       
   602                 while ( retry > 0 && err == KErrLocked )
       
   603                     {
       
   604                     User::After(KBeginTransRetryDelay);
       
   605                     _DBG_FILE("WriteWlanSettings: Slept 1 second. Try again");
       
   606                     err = iTableView->UpdateRecord();                    
       
   607                     retry--;
       
   608                     }               
       
   609                 if( err != KErrNone )
       
   610                     {
       
   611                     _DBG_FILE("WriteWlanSettings: UpdateRecord was unsuccessful");
       
   612                     }
       
   613                 else
       
   614                     {
       
   615                     _DBG_FILE("WriteWlanSettings: UpdateRecord was successful");
       
   616                     }
       
   617                 }           
       
   618 			
       
   619 			if( err != KErrNone )
       
   620 				{
       
   621 				DBG_ARGS(_S16("CWlanSettings::WriteWlanSettings(): - UpdateRecord failed. error: <%D>"), err );
       
   622 			
       
   623 				if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   624 				    {
       
   625 				    TInt tableLockError= KErrNone;
       
   626 				    if(iWLANRelock)
       
   627 				        {
       
   628 				        TInt lockError = KErrNone;
       
   629 				        TRAP(lockError,tableLockError = PerformLockWLANTablesL(ETrue));
       
   630 				        DBG_ARGS(_S16("CWlanSettings::WriteWlanSettings, WLAN table Lock error. error: <%D>, <%D> "), lockError,tableLockError );
       
   631 				        ((CCommsDbProtectTableView*)iTableView)->ProtectRecord(); 
       
   632 				        iWLANRelock =EFalse;
       
   633 				        }
       
   634 				    if ( tableLockError != KErrNone ) // to remove warnings
       
   635 				        {
       
   636 				        tableLockError = KErrNone;
       
   637 				        }
       
   638 				    }
       
   639 				return err;
       
   640 				}
       
   641 			}
       
   642 		}
       
   643 
       
   644 	TRAP( err, WriteDataToRecordL( &aWlanSettings ) );
       
   645 
       
   646 	if( err == KErrNone )
       
   647 		{
       
   648 		_DBG_FILE("CWlanSettings::WriteWlanSettings(): PutRecordChanges");
       
   649 		err = iTableView->PutRecordChanges();
       
   650 		if( err == KErrLocked )
       
   651             {
       
   652             _DBG_FILE("WriteWlanSettings: PutRecordChanges was locked.");
       
   653             TInt retry = KBeginTransRetryCount;            
       
   654             while ( retry > 0 && err == KErrLocked )
       
   655                 {
       
   656                 User::After(KBeginTransRetryDelay);
       
   657                 _DBG_FILE("WriteWlanSettings: Slept 1 second. Try again");
       
   658                 err = iTableView->PutRecordChanges();
       
   659                 retry--;
       
   660                 }      
       
   661             }                
       
   662         if( err != KErrNone )
       
   663             {
       
   664             _DBG_FILE("WriteWlanSettings: PutRecordChanges was unsuccessful");
       
   665             }				
       
   666         else
       
   667             {
       
   668             _DBG_FILE("WriteWlanSettings: PutRecordChanges was successful");        
       
   669             }
       
   670 		}
       
   671 	if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   672 	    {
       
   673 	    if(iWLANRelock)
       
   674 	        {
       
   675 	        TInt lockError = KErrNone;
       
   676 	        TRAP(lockError,enError = PerformLockWLANTablesL(ETrue));
       
   677 	        DBG_ARGS(_S16("CWlanSettings::WriteWlanSettings, WLAN table Lock error. error: <%D>, <%D> "), lockError,enError );
       
   678 	       iWLANRelock =EFalse;
       
   679 		   }
       
   680 	    }
       
   681 	DBG_ARGS(_S16("CWlanSettings::WriteWlanSettings(): end. err: <%D>"), err );
       
   682 	return err;
       
   683 	}
       
   684 
       
   685 
       
   686 
       
   687 //-----------------------------------------------------------------------------
       
   688 // TInt CWlanSettings::WriteWlanSettings( TWlanSettings& aWlanSettings )
       
   689 //-----------------------------------------------------------------------------
       
   690 TInt CWlanSettings::WriteSecondarySSIDL( TUint32 aWlanID, TSecondarySSID& aSettings, TBool aNew )
       
   691     {
       
   692     
       
   693     _DBG_FILE("CWlanSettings::WriteSecondarySSIDL(): begin");
       
   694 
       
   695     TUint32 id = 0;
       
   696     delete iSecondaryView;
       
   697     iSecondaryView = NULL;
       
   698     
       
   699     TInt retval = KErrNone;
       
   700     TInt reLock = EFalse;
       
   701     TBool apEnforce=EFalse;
       
   702     
       
   703     if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   704         {
       
   705     	TRAPD(eError,apEnforce=CheckEnforcementL())
       
   706     	DBG_ARGS8(_S8("CNSmlInternetAdapter::WriteSecondarySSIDL(): EError %d , APEnforcement is %d"),eError,apEnforce);
       
   707 		if(eError==KErrNone && apEnforce)
       
   708 			{
       
   709 			_DBG_FILE("CWlanSettings::WriteSecondarySSIDL(): set db protect");
       
   710 			TInt enError=KErrNone;
       
   711 			TInt lockError = KErrNone;
       
   712 			TRAP(lockError,enError = PerformLockWLANTablesL(EFalse));
       
   713 			reLock = ETrue;
       
   714 			if ( enError != KErrNone ) // to remove warnings
       
   715 			    {
       
   716 			    enError = KErrNone;
       
   717 			    }
       
   718 			}
       
   719         }
       
   720 
       
   721     
       
   722     if (aNew)
       
   723         {
       
   724         _DBG_FILE("CWlanSettings::WriteSecondarySSIDL(): new table inserted");
       
   725         iSecondaryView = iDatabase.OpenTableLC( TPtrC( WLAN_SECONDARY_SSID ) ); 
       
   726         CleanupStack::Pop(iSecondaryView); // iSecondaryView
       
   727         retval = iSecondaryView->InsertRecord(id);
       
   728         
       
   729         if( retval == KErrLocked )
       
   730              {
       
   731              _DBG_FILE("WriteSecondarySSIDL: InsertRecord was locked.");
       
   732              TInt retry = KBeginTransRetryCount;            
       
   733              while ( retry > 0 && retval == KErrLocked )
       
   734                  {
       
   735                  User::After(KBeginTransRetryDelay);
       
   736                  _DBG_FILE("WriteSecondarySSIDL: Slept 1 second. Try again");
       
   737                  retval = iSecondaryView->InsertRecord(id);
       
   738                  retry--;
       
   739                  }      
       
   740              }                
       
   741          if( retval != KErrNone )
       
   742              {
       
   743              _DBG_FILE("WriteSecondarySSIDL: InsertRecord was unsuccessful");
       
   744              }
       
   745          else 
       
   746              {
       
   747              _DBG_FILE("WriteSecondarySSIDL: InsertRecord was successful");
       
   748              }
       
   749         
       
   750         DBG_ARGS8(_S8("CNSmlInternetAdapter::WriteSecondarySSIDL(): Add record, error %d"), retval);
       
   751         if ( retval == KErrNone )
       
   752         	{
       
   753         	_DBG_FILE("CWlanSettings::WriteSecondarySSIDL(): table insertion went ok");      
       
   754         	iSecondaryView->WriteUintL(TPtrC(WLAN_SEC_SSID_SERVICE_ID), aWlanID );
       
   755         	iSecondaryView->WriteUintL(TPtrC(WLAN_SEC_SSID_ID), id );
       
   756         	}
       
   757         }
       
   758     else
       
   759         {
       
   760         _DBG_FILE("CWlanSettings::WriteSecondarySSIDL(): table exists, find it");
       
   761         iSecondaryView = iDatabase.OpenViewMatchingUintLC(TPtrC(WLAN_SECONDARY_SSID),
       
   762                                                         TPtrC(WLAN_SEC_SSID_ID),
       
   763                                                         aSettings.Id);
       
   764         CleanupStack::Pop(iSecondaryView); // iSecondaryView
       
   765         TInt err = iSecondaryView->GotoFirstRecord();
       
   766         if (err != KErrNone)
       
   767             {
       
   768             _DBG_FILE("CWlanSettings::WriteSecondarySSIDL(): go to first record failed");
       
   769             // most likely KErrNotFound, something wrong with the URI parsing probably
       
   770             return err;
       
   771             }
       
   772         if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   773             {
       
   774     		if ( apEnforce )
       
   775     			{
       
   776     			((CCommsDbProtectTableView*)iSecondaryView)->UnprotectRecord();
       
   777     			}
       
   778             }
       
   779         retval = iSecondaryView->UpdateRecord();
       
   780         if( retval == KErrLocked )
       
   781              {
       
   782              _DBG_FILE("WriteSecondarySSIDL: UpdateRecord was locked.");
       
   783              TInt retry = KBeginTransRetryCount;            
       
   784              while ( retry > 0 && retval == KErrLocked )
       
   785                  {
       
   786                  User::After(KBeginTransRetryDelay);
       
   787                  _DBG_FILE("WriteSecondarySSIDL: Slept 1 second. Try again");
       
   788                  retval = iSecondaryView->UpdateRecord();
       
   789                  retry--;
       
   790                  }      
       
   791              }                
       
   792          if( retval != KErrNone )
       
   793              {
       
   794              _DBG_FILE("WriteSecondarySSIDL: UpdateRecord was unsuccessful");
       
   795              }
       
   796          else
       
   797              {
       
   798              _DBG_FILE("WriteSecondarySSIDL: UpdateRecord was successful");
       
   799              }
       
   800         }
       
   801     if ( retval == KErrNone )
       
   802     	{
       
   803     	DBG_ARGS8(_S8("CWlanSettings::writesecondaryssids - WLAN_SEC_SSID_SCANNED_SSID uri: <%S> ad  WLAN_SEC_SSID_USED_SSID : <%S>"), &aSettings.ScannedId, &aSettings.UsedId );
       
   804     	iSecondaryView->WriteTextL(TPtrC(WLAN_SEC_SSID_SCANNED_SSID), aSettings.ScannedId);
       
   805     	iSecondaryView->WriteTextL(TPtrC(WLAN_SEC_SSID_USED_SSID), aSettings.UsedId);
       
   806     
       
   807     	retval = iSecondaryView->PutRecordChanges();
       
   808         if( retval == KErrLocked )
       
   809              {
       
   810              _DBG_FILE("WriteSecondarySSIDL: PutRecordChanges was locked.");
       
   811              TInt retry = KBeginTransRetryCount;            
       
   812              while ( retry > 0 && retval == KErrLocked )
       
   813                  {
       
   814                  User::After(KBeginTransRetryDelay);
       
   815                  _DBG_FILE("WriteSecondarySSIDL: Slept 1 second. Try again");
       
   816                  retval = iSecondaryView->PutRecordChanges();
       
   817                  retry--;
       
   818                  }      
       
   819              }                
       
   820          if( retval != KErrNone )
       
   821              {
       
   822              _DBG_FILE("WriteSecondarySSIDL: PutRecordChanges was unsuccessful");
       
   823              }
       
   824          else
       
   825              {
       
   826              _DBG_FILE("WriteSecondarySSIDL: PutRecordChanges was successful");
       
   827              }
       
   828     	}
       
   829     
       
   830     if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement))
       
   831         {
       
   832     	if ( reLock )
       
   833     		{
       
   834 			TInt enError=KErrNone;
       
   835 			TInt lockError = KErrNone;
       
   836 			TRAP(lockError,enError = PerformLockWLANTablesL(ETrue));
       
   837 			if ( iSecondaryView != NULL )
       
   838 				{
       
   839 				((CCommsDbProtectTableView*)iSecondaryView)->ProtectRecord();
       
   840 				}
       
   841 			if ( enError != KErrNone ) // to remove warnings
       
   842 			    {
       
   843 			    enError = KErrNone;
       
   844 			    }
       
   845     		}
       
   846         }
       
   847 
       
   848     	
       
   849     // This makes sure that there will be no calling to GotoFirstRecord() 
       
   850     // before secondaryview is reinitialized, (causes a panic if that would happen)
       
   851     delete iSecondaryView;
       
   852     iSecondaryView = NULL;
       
   853     
       
   854     if ( reLock&&apEnforce )
       
   855     	{
       
   856     	reLock = EFalse; // to get rid of warnings
       
   857     	apEnforce = EFalse;
       
   858     	}
       
   859     
       
   860     return retval;
       
   861     
       
   862     }
       
   863 	
       
   864 TInt CWlanSettings::WriteEAPSettings( EAPSettings& aEapSettings) 
       
   865     {
       
   866     TRAPD(err, iEapType->SetConfigurationL(aEapSettings));
       
   867     return err;
       
   868     }
       
   869 
       
   870 
       
   871 //-----------------------------------------------------------------------------
       
   872 // void CWlanSettings::ConnectToDatabaseL( )
       
   873 //-----------------------------------------------------------------------------
       
   874 void CWlanSettings::ConnectToDatabaseL( )
       
   875 	{
       
   876 	_DBG_FILE("CWlanSettings::ConnectToDatabaseL(): begin");
       
   877 
       
   878 	if( !iTableView )
       
   879 		{
       
   880 		iTableView = iDatabase.OpenTableLC( TPtrC( WLAN_SERVICE ) ); 
       
   881 
       
   882 		if( iTableView == NULL )
       
   883 			{
       
   884 			_DBG_FILE("CWlanSettings::ConnectToDatabaseL(): could not open table");
       
   885 			User::Leave( KErrCouldNotConnect );
       
   886 			}
       
   887 
       
   888 		CleanupStack::Pop( iTableView ); //iTableView
       
   889 		}
       
   890 	
       
   891 	_DBG_FILE("CWlanSettings::ConnectToDatabaseL(): end");
       
   892 	}
       
   893 
       
   894 
       
   895 void CWlanSettings::GetEAPInterfaceL(const TInt aId, const TInt aTunnelingType, const TInt aType)
       
   896     {
       
   897     if ( aId < 0 )
       
   898     	{
       
   899     	// Illegal input
       
   900     	User::Leave( KErrArgument );
       
   901     	}
       
   902     	
       
   903  	if ( iEapType )
       
   904 	    {
       
   905 	    delete iEapType;
       
   906 	    iEapType = NULL;
       
   907 	    }
       
   908 
       
   909     TInt err = KErrNone;
       
   910     TUint8 expandedEapId[] = {0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
       
   911 
       
   912     TBuf8<KExpandedEAPIdLength> cue;
       
   913     
       
   914 	// First try loading EAP type using the expanded id and if that fails 
       
   915 	// try the 8-bit id. If that succeeds then set the flag so that subsequent
       
   916 	// EAP method loads are always done using the 8-bit id.
       
   917 	if ( iExpandedEAPTypeFieldsUsed )
       
   918 		{
       
   919 		_DBG_FILE("CWlanSettings::GetEAPInterfaceL(): iExpandedEAPTypeFieldsUsed == True.");
       
   920 		// Set-up 64-bit expanded EAP id
       
   921 		if ( ( aType == KMschapv2TypeId[7] ) || ( aType == KTtlspapTypeId[7] ) )
       
   922 			{
       
   923 			// This is plain MSCHAPv2. Set vendor ID correctly
       
   924 			expandedEapId[1] = KMschapv2TypeId[1];
       
   925 			expandedEapId[2] = KMschapv2TypeId[2];
       
   926 			expandedEapId[3] = KMschapv2TypeId[3];
       
   927 			}
       
   928 		
       
   929 		expandedEapId[KExpandedEAPIdLength - 1] = static_cast<TUint8> ( aType );	
       
   930 						
       
   931 		cue.Copy( expandedEapId, KExpandedEAPIdLength );
       
   932 		
       
   933 		// Try loading EAP ECOM module
       
   934 		TRAP( err, iEapType = CEapType::NewL( cue, ELan, aId ));
       
   935 		if ( err != KErrNone )
       
   936 			{
       
   937 			_DBG_FILE("CWlanSettings::GetEAPInterfaceL(): Expanded EAP type loading failed. Trying old style.");
       
   938 			// It failed. Try old style
       
   939 			cue.Format( _L8("%d"), aType );
       
   940 			iEapType = CEapType::NewL( cue, ELan, aId );
       
   941 			_DBG_FILE("CWlanSettings::GetEAPInterfaceL(): Old style loading successful.");
       
   942 			// Succeeded (because didn't leave). Set the flag so that subsequent trys
       
   943 			// are directly using the old format.
       
   944 			iExpandedEAPTypeFieldsUsed = EFalse;					
       
   945 			}			
       
   946     	}
       
   947     else
       
   948     	{
       
   949     	// Use the old 8-bit format
       
   950     	_DBG_FILE("CWlanSettings::GetEAPInterfaceL(): iExpandedEAPTypeFieldsUsed == False.");
       
   951     	cue.Format( _L8("%d"), aType );
       
   952 		iEapType = CEapType::NewL( cue, ELan, aId );
       
   953 		_DBG_FILE("CWlanSettings::GetEAPInterfaceL(): Old style loading successful.");
       
   954     	}   
       
   955     	
       
   956     // Set tunneling type
       
   957 	if (aTunnelingType != EAPSettings::EEapNone)
       
   958 		{
       
   959 		iEapType->SetTunnelingType(aTunnelingType);
       
   960 		}
       
   961 }
       
   962 
       
   963 
       
   964 
       
   965 //-----------------------------------------------------------------------------
       
   966 // TInt CWlanSettings::GoToRecord( TUint32 aId )
       
   967 // Moves iTableView to point record whose id-number equals to aId
       
   968 //-----------------------------------------------------------------------------
       
   969 TInt CWlanSettings::GoToRecord( TUint32 aId )
       
   970 {
       
   971 	_DBG_FILE("CWlanSettings::GoToRecord(): begin");
       
   972 	DBG_ARGS(_S16("CWlanSettings::GoToRecord(): begin Search record id: <%D>"), aId );
       
   973 	
       
   974 	TInt err = iTableView->GotoFirstRecord( );
       
   975 	if( err != KErrNone )
       
   976 		{
       
   977 		DBG_ARGS(_S16("CWlanSettings::GoToRecord(): end, GotoFirstRecord. err: <%D>"), err );
       
   978     return err;
       
   979 		}
       
   980 
       
   981 	TUint32 id = 0;
       
   982 	TRAP( err, iTableView->ReadUintL( TPtrC(WLAN_SERVICE_ID), id ) );
       
   983 	if( err != KErrNone )
       
   984 		{
       
   985 		DBG_ARGS(_S16("CWlanSettings::GoToRecord(): end, ReadUintL. err: <%D>"), err );
       
   986 	  return err;
       
   987 		}
       
   988 
       
   989 	while( aId != id )
       
   990 		{
       
   991 		err = iTableView->GotoNextRecord( );
       
   992 		if( err != KErrNone )
       
   993 			{
       
   994 			DBG_ARGS(_S16("CWlanSettings::GoToRecord(): end, GotoNextRecord. err: <%D>"), err );
       
   995   	  	    return err;
       
   996 			}
       
   997 
       
   998 		TRAP( err, iTableView->ReadUintL( TPtrC(WLAN_SERVICE_ID), id ) );
       
   999 
       
  1000 		if( err == KErrNone )
       
  1001 			{
       
  1002 			DBG_ARGS(_S16("CWlanSettings::GoToRecord(): Found service id: <%D>"), id );
       
  1003 			}
       
  1004 		else
       
  1005 			{
       
  1006 	  	DBG_ARGS(_S16("CWlanSettings::GoToRecord(): end, ReadUintL next. err: <%D>"), err );
       
  1007 			return err;
       
  1008 			}
       
  1009 		}
       
  1010 
       
  1011     TRAP(err, SetSecondaryViewToRecordL(aId));
       
  1012 
       
  1013 
       
  1014 	DBG_ARGS(_S16("CWlanSettings::GoToRecord(): end. Final record id: <%D>"), id );
       
  1015 
       
  1016 	return err;
       
  1017 	}
       
  1018 
       
  1019 
       
  1020 
       
  1021 void CWlanSettings::SetSecondaryViewToRecordL( TUint32 aId )
       
  1022     {
       
  1023     // optional secondarySSID
       
  1024     if (iSecondaryView)
       
  1025         {
       
  1026         delete iSecondaryView;
       
  1027         iSecondaryView = NULL;
       
  1028         }
       
  1029         
       
  1030     // first open a view to secondary ssid table, with all the rows with service id
       
  1031     // matching the wlan service id (count can be zero)        
       
  1032     iSecondaryView = iDatabase.OpenViewMatchingUintLC( TPtrC(WLAN_SECONDARY_SSID),
       
  1033                                                         TPtrC(WLAN_SEC_SSID_SERVICE_ID),
       
  1034                                                         aId);
       
  1035 	if( iSecondaryView == NULL )
       
  1036 		{
       
  1037 		// this should not happen in a normal situation
       
  1038 		User::Leave( KErrCouldNotConnect );
       
  1039 		}
       
  1040 	CleanupStack::Pop( iSecondaryView );
       
  1041     }
       
  1042 
       
  1043 
       
  1044 //-----------------------------------------------------------------------------
       
  1045 // void CWlanSettings::GetDataFromRecordL( TWlanSettings* aWlanSettings )
       
  1046 // Read settings from database to aWlanSettings structure
       
  1047 //-----------------------------------------------------------------------------
       
  1048 void CWlanSettings::GetDataFromRecordL( TWlanSettings* aWlanSettings )
       
  1049 	{
       
  1050 	_DBG_FILE("CWlanSettings::GetDataFromRecordL(): begin");
       
  1051 	
       
  1052     TInt leavecode = 0;
       
  1053 
       
  1054     aWlanSettings->ServiceID = 0;
       
  1055     aWlanSettings->ConnectionMode = 0;
       
  1056     aWlanSettings->SSID = _L("");
       
  1057     aWlanSettings->UsedSSID = _L("");
       
  1058     aWlanSettings->ScanSSID = 0;
       
  1059     aWlanSettings->WepKey1 = _L8("");
       
  1060     aWlanSettings->WepKey2 = _L8("");
       
  1061     aWlanSettings->WepKey3 = _L8("");
       
  1062     aWlanSettings->WepKey4 = _L8("");
       
  1063     aWlanSettings->WepIndex = 0;
       
  1064     aWlanSettings->SecurityMode = EAllowUnsecure;
       
  1065     aWlanSettings->WPAPreSharedKey = _L8("");
       
  1066     aWlanSettings->UseWPAPSK = 0;
       
  1067     aWlanSettings->EapList = _L("");
       
  1068     aWlanSettings->AuthMode = 0;                
       
  1069             
       
  1070     TRAP( leavecode, iTableView->ReadUintL( TPtrC( WLAN_SERVICE_ID ), aWlanSettings->ServiceID ) );
       
  1071     if ( leavecode != KErrNone ) 
       
  1072         {
       
  1073         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): WLAN_SERVICE_ID read error: <%D>"), leavecode );
       
  1074         }       
       
  1075        
       
  1076     TRAP( leavecode, iTableView->ReadUintL( TPtrC( WLAN_CONNECTION_MODE ), aWlanSettings->ConnectionMode ) );
       
  1077     if ( leavecode != KErrNone ) 
       
  1078         {
       
  1079         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): WLAN_CONNECTION_MODE read error: <%D>"), leavecode );
       
  1080         }       
       
  1081 
       
  1082     TRAP( leavecode, iTableView->ReadUintL( TPtrC( NU_WLAN_AUTHENTICATION_MODE ), aWlanSettings->AuthMode ) );
       
  1083     if ( leavecode != KErrNone ) 
       
  1084         {
       
  1085         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): NU_WLAN_AUTHENTICATION_MODE read error: <%D>"), leavecode );
       
  1086         }       
       
  1087  
       
  1088     TRAP( leavecode, iTableView->ReadUintL( TPtrC( WLAN_WEP_INDEX ), aWlanSettings->WepIndex ) );
       
  1089     if ( leavecode != KErrNone ) 
       
  1090         {
       
  1091         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): WLAN_WEP_INDEX read error: <%D>"), leavecode );
       
  1092         }       
       
  1093 
       
  1094     TRAP( leavecode, iTableView->ReadUintL( TPtrC( WLAN_SECURITY_MODE ), aWlanSettings->SecurityMode ) );
       
  1095     if ( leavecode != KErrNone ) 
       
  1096         {
       
  1097         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): WLAN_SECURITY_MODE read error: <%D>"), leavecode );
       
  1098         }       
       
  1099 
       
  1100     TRAP( leavecode, iTableView->ReadUintL( TPtrC( WLAN_ENABLE_WPA_PSK ), aWlanSettings->UseWPAPSK ) );
       
  1101     if ( leavecode != KErrNone ) 
       
  1102         {
       
  1103         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): WLAN_ENABLE_WPA_PSK read error: <%D>"), leavecode );
       
  1104         }       
       
  1105 
       
  1106     TBuf8<KCommsDbSvrMaxFieldLength> columnValue8;
       
  1107     TRAP(leavecode, iTableView->ReadTextL( TPtrC(NU_WLAN_WEP_KEY1 ),  columnValue8 ));
       
  1108     if ( ( leavecode == KErrNone ) && ( columnValue8.Length() > 0 ) )
       
  1109         {
       
  1110     	aWlanSettings->WepKey1 = columnValue8;
       
  1111         }
       
  1112     else
       
  1113         {
       
  1114         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): NU_WLAN_WEP_KEY1 read error: <%D>"), leavecode );
       
  1115         }
       
  1116 
       
  1117     TRAP(leavecode, iTableView->ReadTextL( TPtrC(NU_WLAN_WEP_KEY2 ),  columnValue8 ));
       
  1118     if ( ( leavecode == KErrNone ) && ( columnValue8.Length() > 0 ) )
       
  1119         {
       
  1120     	aWlanSettings->WepKey2 = columnValue8;
       
  1121         }
       
  1122     else
       
  1123         {
       
  1124         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): NU_WLAN_WEP_KEY2 read error: <%D>"), leavecode );
       
  1125         }
       
  1126 
       
  1127     TRAP(leavecode, iTableView->ReadTextL( TPtrC(NU_WLAN_WEP_KEY3 ),  columnValue8 ));
       
  1128     if ( ( leavecode == KErrNone ) && ( columnValue8.Length() > 0 ) )
       
  1129         {
       
  1130     	aWlanSettings->WepKey3 = columnValue8;
       
  1131         }
       
  1132     else
       
  1133         {
       
  1134         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): NU_WLAN_WEP_KEY3 read error: <%D>"), leavecode );
       
  1135         }
       
  1136 
       
  1137     TRAP(leavecode, iTableView->ReadTextL( TPtrC(NU_WLAN_WEP_KEY4 ),  columnValue8 ));
       
  1138     if ( ( leavecode == KErrNone ) && ( columnValue8.Length() > 0 ) )
       
  1139         {
       
  1140     	aWlanSettings->WepKey4 = columnValue8;
       
  1141         }
       
  1142     else
       
  1143         {
       
  1144         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): NU_WLAN_WEP_KEY4 read error: <%D>"), leavecode );
       
  1145         }
       
  1146 
       
  1147 	TBuf8<KMaxPSKLength> precolumnValue8;
       
  1148     TBuf<KCommsDbSvrMaxFieldLength> columnValue;
       
  1149     
       
  1150     _DBG_FILE("CWlanSettings::GetDataFromRecordL(): Before getting WLAN_WPA_PRE_SHARED_KEY ");
       
  1151     TRAP(leavecode, iTableView->ReadTextL( TPtrC(WLAN_WPA_PRE_SHARED_KEY ),  precolumnValue8 ));
       
  1152     DBG_ARGS(_S16("CWlanSettings::ReadTextL( TPtrC(WLAN_WPA_PRE_SHARED_KEY ),length of key: <%D>"), precolumnValue8.Length() );
       
  1153     if ( ( leavecode == KErrNone ) && ( precolumnValue8.Length() > 0 ) )
       
  1154         {
       
  1155     	aWlanSettings->WPAPreSharedKey = precolumnValue8;
       
  1156         }
       
  1157     else
       
  1158         {
       
  1159         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): WLAN_WPA_PRE_SHARED_KEY read error: <%D>"), leavecode );
       
  1160         }
       
  1161 
       
  1162     TRAP(leavecode, iTableView->ReadTextL( TPtrC(NU_WLAN_SSID ),  columnValue ));
       
  1163     if ( ( leavecode == KErrNone ) && ( columnValue.Length() > 0 ) )
       
  1164         {
       
  1165     	aWlanSettings->SSID = columnValue;
       
  1166         }
       
  1167     else
       
  1168         {
       
  1169         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): NU_WLAN_SSID read error: <%D>"), leavecode );
       
  1170         }
       
  1171 
       
  1172     TRAP(leavecode, iTableView->ReadTextL( TPtrC(WLAN_USED_SSID ),  columnValue ));
       
  1173     if ( ( leavecode == KErrNone ) && ( columnValue.Length() > 0 ) )
       
  1174         {
       
  1175     	aWlanSettings->UsedSSID = columnValue;
       
  1176         _DBG_FILE("CWlanSettings::GetDataFromRecordL(): WLAN_USED_SSID reading ok");
       
  1177         }
       
  1178     else
       
  1179         {
       
  1180         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): WLAN_USED_SSID read error: <%D>"), leavecode );
       
  1181         }
       
  1182 	
       
  1183     iTableView->ReadTextL( TPtrC(WLAN_USED_SSID), aWlanSettings->UsedSSID );
       
  1184     _DBG_FILE("CWlanSettings::GetDataFromRecordL(): WLAN_USED_SSID");
       
  1185 
       
  1186     TRAP(leavecode, iTableView->ReadUintL( TPtrC(WLAN_SCAN_SSID ), aWlanSettings->ScanSSID ));
       
  1187     if ( leavecode != KErrNone )
       
  1188         {
       
  1189         DBG_ARGS(_S16("CWlanSettings::GetDataFromRecordL(): WLAN_SCAN_SSID read error: <%D>"), leavecode );
       
  1190         }
       
  1191 
       
  1192 	TInt retval = iSecondaryView->GotoFirstRecord();
       
  1193 	if (retval == KErrNone)
       
  1194 	    {
       
  1195 	    aWlanSettings->SecondarySSIDsExisting = ETrue;
       
  1196 	    }
       
  1197 	else
       
  1198 	    {
       
  1199 	    aWlanSettings->SecondarySSIDsExisting = EFalse;
       
  1200 	    }
       
  1201 
       
  1202 	// Try to read the old EAPList field
       
  1203 	HBufC* eapList = iTableView->ReadLongTextLC( TPtrC( WLAN_EAPS ) );
       
  1204 	if ( eapList->Length() > 0 )
       
  1205 		{
       
  1206 		// The old field was valid and there was content
       
  1207 		aWlanSettings->EapList = *eapList;		
       
  1208 		}
       
  1209 	else
       
  1210 		{
       
  1211 		// Old list was invalid or empty. Try the new fields:
       
  1212 	    // enabled EAP types
       
  1213 	    TBuf8<KEAPListBufferSize> enabledTypes;
       
  1214 	    TBuf8<KEAPListBufferSize> disabledTypes;
       
  1215 	    iTableView->ReadTextL( TPtrC( WLAN_ENABLED_EAPS ), enabledTypes);
       
  1216 	    iTableView->ReadTextL( TPtrC( WLAN_DISABLED_EAPS ), disabledTypes);         	                               
       
  1217 		
       
  1218 	    // Calculate the number of EAP types altogether
       
  1219 	    TUint numEapTypes = enabledTypes.Length() / KExpandedEAPIdLength;
       
  1220 	    numEapTypes += disabledTypes.Length() / KExpandedEAPIdLength;
       
  1221 	    
       
  1222 	    if (numEapTypes > 0)
       
  1223 		    {
       
  1224 		    // One EAP type reserves maximum of 5 bytes: "+xxx,"
       
  1225 		    HBufC* outputBuf = HBufC::NewLC( numEapTypes * KLengthOfOldStyleEAPListEntry );
       
  1226 		    		    
       
  1227 		    TPtr output = outputBuf->Des();	    
       
  1228 			_LIT( KFormat, "%03d" );		                  	                               
       
  1229 			for ( TInt i = (KExpandedEAPIdLength - 1) ; i < enabledTypes.Length() ; i += KExpandedEAPIdLength)
       
  1230 				{
       
  1231 				
       
  1232 				output.Append(TChar( '+' ));
       
  1233 				output.AppendFormat( KFormat, enabledTypes[i] );
       
  1234 				output.Append(TChar( ',' ));
       
  1235 				}
       
  1236 				
       
  1237 			for ( TInt i = (KExpandedEAPIdLength - 1) ; i < disabledTypes.Length() ; i += KExpandedEAPIdLength)
       
  1238 				{				
       
  1239 				output.Append(TChar( '-' ));
       
  1240 				output.AppendFormat( KFormat, disabledTypes[i] );
       
  1241 				output.Append(TChar( ',' ));
       
  1242 				}
       
  1243 			// Strip the final ','
       
  1244 			output.Delete( output.Length() - 1, 1 );
       
  1245 			
       
  1246 			aWlanSettings->EapList = *outputBuf;
       
  1247 			CleanupStack::PopAndDestroy( outputBuf );
       
  1248 		    }
       
  1249 		}
       
  1250     
       
  1251 	CleanupStack::PopAndDestroy( eapList );
       
  1252 
       
  1253     _DBG_FILE("CWlanSettings::GetDataFromRecordL(): WLAN_EAPS");
       
  1254     
       
  1255 
       
  1256 	_DBG_FILE("CWlanSettings::GetDataFromRecordL(): end");
       
  1257 	}
       
  1258 	
       
  1259 	
       
  1260 	
       
  1261 //-----------------------------------------------------------------------------
       
  1262 // void CWlanSettings::GetSecondarySSIDListL(TUint32 aId, RArray<TSecondarySSID>& aSecondarySSIDs)
       
  1263 // Fills the array with secondarySSIDs, which are associated with given WLANID
       
  1264 //-----------------------------------------------------------------------------
       
  1265 void CWlanSettings::GetSecondarySSIDListL(TUint32 aWlanId, RArray<TSecondarySSID>& aSecondarySSIDs)
       
  1266     {
       
  1267     if (iSecondaryView == NULL)
       
  1268         {
       
  1269         // views haven't been initialized, in case of incorrect usage
       
  1270         User::Leave(KErrNotReady);
       
  1271         }
       
  1272         
       
  1273     // set the view pointer into the first record
       
  1274     TInt retval = iSecondaryView->GotoFirstRecord();
       
  1275     if (retval != KErrNone)
       
  1276         {
       
  1277         return;
       
  1278         }
       
  1279     
       
  1280     // check that given id matches the current rowset. If not, then reinitialize
       
  1281     TUint32 id;
       
  1282     TInt err(KErrNone);
       
  1283     TRAP(err, iSecondaryView->ReadUintL( TPtrC(WLAN_SEC_SSID_SERVICE_ID ),  id ));
       
  1284     if (id != aWlanId)
       
  1285         {
       
  1286         SetSecondaryViewToRecordL(aWlanId);
       
  1287     	retval = iSecondaryView->GotoFirstRecord();
       
  1288         }
       
  1289         
       
  1290     TBuf<KMaxTextLength> columnValue;
       
  1291 
       
  1292     while (retval == KErrNone)
       
  1293         {
       
  1294         TSecondarySSID ssid;
       
  1295         TRAP(retval, iSecondaryView->ReadUintL( TPtrC(WLAN_SEC_SSID_ID ),  ssid.Id ));
       
  1296         TRAP(retval, iSecondaryView->ReadTextL( TPtrC(WLAN_SEC_SSID_SCANNED_SSID ),  ssid.ScannedId ));
       
  1297         TRAP(retval, iSecondaryView->ReadTextL( TPtrC(WLAN_SEC_SSID_USED_SSID ),  ssid.UsedId ));
       
  1298         aSecondarySSIDs.Append(ssid);
       
  1299         retval = iSecondaryView->GotoNextRecord();
       
  1300         }
       
  1301     }
       
  1302 
       
  1303 
       
  1304 
       
  1305 
       
  1306 //-----------------------------------------------------------------------------
       
  1307 // void CWlanSettings::WriteDataToRecordL( TWlanSettings* aWlanSettings )
       
  1308 // Writes settings to database from aWlanSettings structure
       
  1309 //-----------------------------------------------------------------------------
       
  1310 void CWlanSettings::WriteDataToRecordL( TWlanSettings* aWlanSettings )
       
  1311 	{
       
  1312 	_DBG_FILE("CWlanSettings::WriteDataToRecordL(): begin");
       
  1313 
       
  1314 	iTableView->WriteUintL( TPtrC(WLAN_SERVICE_ID), aWlanSettings->ServiceID );
       
  1315 	iTableView->WriteUintL( TPtrC(WLAN_CONNECTION_MODE), aWlanSettings->ConnectionMode );
       
  1316 	iTableView->WriteUintL( TPtrC(WLAN_WEP_INDEX), aWlanSettings->WepIndex );
       
  1317 	iTableView->WriteUintL( TPtrC(WLAN_SECURITY_MODE), aWlanSettings->SecurityMode );
       
  1318 	iTableView->WriteUintL( TPtrC(WLAN_ENABLE_WPA_PSK), aWlanSettings->UseWPAPSK );
       
  1319 	iTableView->WriteUintL( TPtrC(NU_WLAN_AUTHENTICATION_MODE), aWlanSettings->AuthMode );
       
  1320 	iTableView->WriteTextL( TPtrC(NU_WLAN_SSID), aWlanSettings->SSID );
       
  1321 	iTableView->WriteTextL( TPtrC(WLAN_USED_SSID), aWlanSettings->UsedSSID );
       
  1322 	iTableView->WriteUintL( TPtrC(WLAN_SCAN_SSID), aWlanSettings->ScanSSID );
       
  1323 	
       
  1324 	iTableView->WriteTextL( TPtrC(NU_WLAN_WEP_KEY1), aWlanSettings->WepKey1 );
       
  1325 	iTableView->WriteTextL( TPtrC(NU_WLAN_WEP_KEY2), aWlanSettings->WepKey2 );
       
  1326 	iTableView->WriteTextL( TPtrC(NU_WLAN_WEP_KEY3), aWlanSettings->WepKey3 );
       
  1327 	iTableView->WriteTextL( TPtrC(NU_WLAN_WEP_KEY4), aWlanSettings->WepKey4 );
       
  1328 	iTableView->WriteUintL( TPtrC(WLAN_WEP_KEY1_FORMAT ), 1 ); // 0 = Eascii, 1 = EHexadecimal
       
  1329 	iTableView->WriteUintL( TPtrC(WLAN_WEP_KEY2_FORMAT ), 1 );
       
  1330 	iTableView->WriteUintL( TPtrC(WLAN_WEP_KEY3_FORMAT ), 1 );
       
  1331 	iTableView->WriteUintL( TPtrC(WLAN_WEP_KEY4_FORMAT ), 1 ); 
       
  1332 	
       
  1333 	iTableView->WriteTextL( TPtrC(WLAN_WPA_PRE_SHARED_KEY), aWlanSettings->WPAPreSharedKey );
       
  1334 	iTableView->WriteUintL( TPtrC(WLAN_WPA_KEY_LENGTH), aWlanSettings->WPAPreSharedKey.Length() );
       
  1335 
       
  1336 	// Expanded EAP types in use. Write the eap list to the new columns.
       
  1337 
       
  1338     // generate appropriate entries in the new enabled and disabled list,
       
  1339     // overwriting those values 
       
  1340     
       
  1341     // count the + and - signs to determine the size of enabled and 
       
  1342     // disabled descriptors
       
  1343     TLex lex( aWlanSettings->EapList );
       
  1344     
       
  1345     TInt numPlus = 0;
       
  1346     TInt numMinus = 0;
       
  1347     TChar ch;
       
  1348     while ( !lex.Eos() )
       
  1349         {
       
  1350         ch = lex.Get();
       
  1351         if ( ch == '+' ) ++numPlus;
       
  1352         else if ( ch == '-' ) ++numMinus;
       
  1353         }
       
  1354         
       
  1355     // each entry consumes 8 bytes in binary format
       
  1356     HBufC8* enabledEAPPlugin = HBufC8::NewL( 8 * numPlus );
       
  1357     CleanupStack::PushL( enabledEAPPlugin );
       
  1358     
       
  1359     HBufC8* disabledEAPPlugin = HBufC8::NewL( 8 * numMinus );
       
  1360     CleanupStack::PushL( disabledEAPPlugin );
       
  1361         
       
  1362     lex.Assign( aWlanSettings->EapList );
       
  1363     
       
  1364     while ( !lex.Eos() )
       
  1365         {
       
  1366         // beginning of implementation UID
       
  1367         TInt16 implUid = 0;
       
  1368         
       
  1369         if ( lex.Val( implUid ) != KErrNone || !implUid )
       
  1370             {
       
  1371             // if the old string is corrupted, null out both lists
       
  1372             enabledEAPPlugin->Des().Zero();
       
  1373             disabledEAPPlugin->Des().Zero();
       
  1374             break;
       
  1375             }
       
  1376 
       
  1377         // append it to the appropriate list ('+' enabled, '-' disabled)
       
  1378         _LIT8( KPadding, "\xFE\0\0\0\0\0\0" );
       
  1379         _LIT8( KMsChapV2Padding, "\xFE\xFF\xFF\xFF\0\0\0");
       
  1380         const TInt KPlainMsChapV2ImplUid = 99;
       
  1381         const TInt KTtlspapImplUid = 98;
       
  1382         
       
  1383         // Check whether eap is inluded or not +/-
       
  1384         if ( implUid > 0 )
       
  1385             {
       
  1386             // check whether plain mschap or ttlspap in question
       
  1387             if ( Abs( implUid ) == KPlainMsChapV2ImplUid || Abs( implUid ) == KTtlspapImplUid )
       
  1388             	{
       
  1389             	enabledEAPPlugin->Des().Append( KMsChapV2Padding );
       
  1390             	}
       
  1391             else
       
  1392             	{
       
  1393             	enabledEAPPlugin->Des().Append( KPadding );
       
  1394             	}
       
  1395             enabledEAPPlugin->Des().Append( Abs( implUid ) );
       
  1396             }
       
  1397         else if (implUid < 0 )
       
  1398             {
       
  1399             // check whether plain mschap or ttlspap in question
       
  1400             if ( Abs( implUid ) == KPlainMsChapV2ImplUid || Abs( implUid ) == KTtlspapImplUid )
       
  1401             	{
       
  1402             	disabledEAPPlugin->Des().Append( KMsChapV2Padding );
       
  1403             	}
       
  1404             else
       
  1405             	{
       
  1406             	disabledEAPPlugin->Des().Append( KPadding );
       
  1407             	}
       
  1408             disabledEAPPlugin->Des().Append( Abs( implUid ) );
       
  1409             }
       
  1410         
       
  1411         // swallow the delimiter (',')
       
  1412         lex.Get();
       
  1413         }
       
  1414                 	
       
  1415 	
       
  1416 	
       
  1417 	iTableView->WriteTextL( TPtrC( WLAN_ENABLED_EAPS ), 
       
  1418                                   enabledEAPPlugin? 
       
  1419                                         (const TDesC8&)*enabledEAPPlugin: 
       
  1420                                         (const TDesC8&)KNullDesC8 );
       
  1421 
       
  1422     iTableView->WriteTextL( TPtrC( WLAN_DISABLED_EAPS ), 
       
  1423                                   disabledEAPPlugin? 
       
  1424                                         (const TDesC8&)*disabledEAPPlugin: 
       
  1425                                         (const TDesC8&)KNullDesC8 );
       
  1426     CleanupStack::PopAndDestroy( disabledEAPPlugin );
       
  1427     CleanupStack::PopAndDestroy( enabledEAPPlugin );
       
  1428     
       
  1429 	_DBG_FILE("CWlanSettings::WriteDataToRecordL(): end");
       
  1430 	}
       
  1431 
       
  1432 //-----------------------------------------------------------------------------
       
  1433 // TInt CWlanSettings::RecordExists( TUint32 aLuid )
       
  1434 // Returns ETrue if record exists in database
       
  1435 //-----------------------------------------------------------------------------
       
  1436 TInt CWlanSettings::RecordExists( TUint32 aLuid )
       
  1437 	{
       
  1438 	_DBG_FILE("CWlanSettings::RecordExists(): begin");
       
  1439 	
       
  1440 	TInt err = KErrNone;
       
  1441 	TRAP( err, ConnectToDatabaseL() );
       
  1442 	
       
  1443 	// If the connection went ok, then we can go to the record
       
  1444 	if( err == KErrNone )
       
  1445 	    {	    
       
  1446 	    err = GoToRecord( aLuid );
       
  1447 	    }
       
  1448 	
       
  1449 	if( err == KErrNone )
       
  1450 		{
       
  1451   	    DBG_ARGS(_S16("CWlanSettings::RecordExists(): end. GoToRecord OK err: <%D>"), err );
       
  1452 		return ETrue;
       
  1453 		}
       
  1454 	else
       
  1455 		{
       
  1456   	    DBG_ARGS(_S16("CWlanSettings::RecordExists(): end. GoToRecord error err: <%D>"), err );
       
  1457 		return err;
       
  1458 		}
       
  1459 	}
       
  1460 
       
  1461 //-----------------------------------------------------------------------------
       
  1462 // void CWlanSettings::InitialiseRecordL( )
       
  1463 // Inserts mandatory values for commsdb
       
  1464 //-----------------------------------------------------------------------------
       
  1465 void CWlanSettings::InitialiseRecordL( )
       
  1466 	{
       
  1467 	_DBG_FILE("CWlanSettings::InitialiseRecordL(): begin");
       
  1468 	
       
  1469 	iTableView->WriteUintL( TPtrC(WLAN_WPA_KEY_LENGTH), 0 );
       
  1470 	iTableView->WriteUintL( TPtrC(NU_WLAN_AUTHENTICATION_MODE), 0 );
       
  1471 
       
  1472   _DBG_FILE("CWlanSettings::InitialiseRecordL(): end");
       
  1473 	}
       
  1474 
       
  1475 		
       
  1476 TInt CWlanSettings::InstalledEAPsL(CBufBase& aEAPList)
       
  1477     {
       
  1478     _DBG_FILE("CWlanSettings::InstalledEAPsL(): begin");
       
  1479 
       
  1480     RImplInfoPtrArray ecomInfoArray;
       
  1481     REComSession::ListImplementationsL(KEapTypeInterfaceUid, ecomInfoArray);
       
  1482         
       
  1483     TUint eapId( 0 ); 
       
  1484                 
       
  1485     // First sort the EAPIds
       
  1486     for (TInt i = 0; i < ecomInfoArray.Count(); i++)
       
  1487         {        
       
  1488 		if ( ecomInfoArray[i]->DataType().Length() == KExpandedEAPIdLength)
       
  1489 			{
       
  1490 			// The EAP ID is in expanded type format
       
  1491 			// Only handle the vendor type of 0
       
  1492 			if ( (ecomInfoArray[i]->DataType()[1] != 0
       
  1493 				 || ecomInfoArray[i]->DataType()[2] != 0
       
  1494 				 || ecomInfoArray[i]->DataType()[3] != 0  )
       
  1495 				 && ( ( ecomInfoArray[i]->DataType()[7] != KMschapv2TypeId[7] ) &&
       
  1496 					  ( ecomInfoArray[i]->DataType()[7] != KTtlspapTypeId[7] ) ) )
       
  1497 				 {
       
  1498 				 	// This is some other vendor type than IETF
       
  1499 				 	continue;	
       
  1500 				 }
       
  1501 			eapId = ecomInfoArray[i]->DataType()[7];
       
  1502 			_DBG_FILE("CWlanSettings::InstalledEAPsL(): Expanded EAP id found.");			
       
  1503 			}
       
  1504 		else
       
  1505 			{
       
  1506 			// The EAP ID is in old 8-bit format (as string)
       
  1507 			TLex8 lex( ecomInfoArray[i]->DataType() );
       
  1508         	if ( lex.Val( eapId ) != KErrNone )
       
  1509         		{
       
  1510         		// Unsupported format. Ignore this.
       
  1511         		_DBG_FILE("CWlanSettings::InstalledEAPsL(): Unsupported EAP id found.");
       
  1512         		continue;
       
  1513 				}			       			
       
  1514 				_DBG_FILE("CWlanSettings::InstalledEAPsL(): Old style EAP id found.");
       
  1515 			}
       
  1516 			        
       
  1517         if ( !CEapType::IsDisallowedOutsidePEAP( *ecomInfoArray[i] ) )
       
  1518         	{
       
  1519 		        aEAPList.InsertL(aEAPList.Size(), KNSmlWLanEapId);  // EAPId
       
  1520         		TBuf8<3> cue;    // Max EAPId == 255
       
  1521         		cue.AppendNumFixedWidth( eapId, EDecimal, 3 );
       
  1522         		aEAPList.InsertL(aEAPList.Size(), cue);
       
  1523 				aEAPList.InsertL(aEAPList.Size(), KSlash);				
       
  1524         	}
       
  1525 
       
  1526 		// Check if the method is allowed inside PEAP
       
  1527 		if ( !CEapType::IsDisallowedInsidePEAP( *ecomInfoArray[i] ) )
       
  1528 			{			
       
  1529 	        aEAPList.InsertL(aEAPList.Size(), KNSmlWLanEapId);  // EAPId
       
  1530 	        TBuf8<3> cue;    // Max EAPId == 255
       
  1531 	        cue.AppendNumFixedWidth( eapId, EDecimal, 3 );
       
  1532 	        aEAPList.InsertL(aEAPList.Size(), cue);		
       
  1533 	        aEAPList.InsertL(aEAPList.Size(), KDash);
       
  1534 	        cue.Zero();
       
  1535 	        cue.AppendNumFixedWidth( KEapPeapTypeId[7], EDecimal, 3 );
       
  1536 	        aEAPList.InsertL(aEAPList.Size(), cue);			       
       
  1537 	        aEAPList.InsertL(aEAPList.Size(), KSlash);
       
  1538 	        
       
  1539 #ifdef FF_WLAN_EXTENSIONS
       
  1540 			// same additions for EAP-FAST
       
  1541 	       	aEAPList.InsertL(aEAPList.Size(), KNSmlWLanEapId);  // EAPId
       
  1542 	       	cue.Zero();    // Max EAPId == 255
       
  1543 	        cue.AppendNumFixedWidth( eapId, EDecimal, 3 );
       
  1544 	       	aEAPList.InsertL(aEAPList.Size(), cue);		
       
  1545 	        aEAPList.InsertL(aEAPList.Size(), KDash);
       
  1546 	        cue.Zero();
       
  1547 	        cue.AppendNumFixedWidth( KEapFastTypeId[7], EDecimal, 3 );
       
  1548 	        aEAPList.InsertL(aEAPList.Size(), cue);			       
       
  1549 	        aEAPList.InsertL(aEAPList.Size(), KSlash);	
       
  1550 #endif		        
       
  1551 			}
       
  1552 		// Check if the method is allowed inside TTLS
       
  1553 		if ( !CEapType::IsDisallowedInsideTTLS( *ecomInfoArray[i] ) )
       
  1554 			{
       
  1555 	        aEAPList.InsertL(aEAPList.Size(), KNSmlWLanEapId);  // EAPId
       
  1556 	        TBuf8<3> cue;    // Max EAPId == 255
       
  1557 	        cue.AppendNumFixedWidth( eapId, EDecimal, 3 );
       
  1558 	        aEAPList.InsertL(aEAPList.Size(), cue);		
       
  1559 	        aEAPList.InsertL(aEAPList.Size(), KDash);
       
  1560 	        cue.Zero();
       
  1561 	        cue.AppendNumFixedWidth( KEapTtlsTypeId[7], EDecimal, 3 );
       
  1562 	        aEAPList.InsertL(aEAPList.Size(), cue);			       	
       
  1563 	        aEAPList.InsertL(aEAPList.Size(), KSlash);		                		        		
       
  1564 			}
       
  1565         }
       
  1566     // ECOM array is no longer needed.
       
  1567     ecomInfoArray.ResetAndDestroy();
       
  1568 
       
  1569     // Cut the last slash
       
  1570 	aEAPList.ResizeL( aEAPList.Size() -1);
       
  1571      
       
  1572     _DBG_FILE("CWlanSettings::InstalledEAPsL(): end");
       
  1573     return KErrNone;
       
  1574     }
       
  1575 
       
  1576 		
       
  1577 
       
  1578 //-----------------------------------------------------------------------------
       
  1579 // TBool CWlanSettings::CheckEnforcementL( )
       
  1580 // Checks if wlan enforcement is On or Off
       
  1581 //-----------------------------------------------------------------------------
       
  1582     TBool CWlanSettings::CheckEnforcementL()
       
  1583     {
       
  1584     	CSettingEnforcementInfo* info = CSettingEnforcementInfo::NewL();
       
  1585 		CleanupStack::PushL(info);
       
  1586 		TBool enforceWLANActive ( EFalse );
       
  1587 		User::LeaveIfError(info->EnforcementActive(EWLANEnforcement, enforceWLANActive));
       
  1588 		CleanupStack::PopAndDestroy(info);
       
  1589 		return ( enforceWLANActive) ;
       
  1590     }
       
  1591 
       
  1592 //-----------------------------------------------------------------------------
       
  1593 // TBool CWlanSettings::CheckAPEnforcementL( )
       
  1594 // Checks if AP enforcement is On or Off
       
  1595 //-----------------------------------------------------------------------------
       
  1596     
       
  1597 TBool CWlanSettings::CheckAPEnforcementL()
       
  1598     {
       
  1599     	CSettingEnforcementInfo* info = CSettingEnforcementInfo::NewL();
       
  1600 		CleanupStack::PushL(info);
       
  1601 		TBool enforceAPActive ( EFalse );
       
  1602 		User::LeaveIfError(info->EnforcementActive(EAPEnforcement, enforceAPActive));
       
  1603 		CleanupStack::PopAndDestroy(info);
       
  1604 		return ( enforceAPActive) ;
       
  1605     }
       
  1606 //-----------------------------------------------------------------------------
       
  1607 // TInt CWlanSettings::PerformLockWLANTablesL( )
       
  1608 // Locks or unlocks the wlan tables depending on the 
       
  1609 // aProtect value
       
  1610 //-----------------------------------------------------------------------------
       
  1611   TInt CWlanSettings::PerformLockWLANTablesL(TBool aProtect)
       
  1612     {
       
  1613        
       
  1614    	_DBG_FILE("CWlanSettings::PerformLockWLANTablesL(): BEGIN ");
       
  1615     CCommsDatabaseProtect* dbprotect = CCommsDatabaseProtect::NewL();
       
  1616     CleanupStack::PushL(dbprotect);
       
  1617     RArray<TPtrC> wlanTableList;
       
  1618     CleanupClosePushL( wlanTableList );
       
  1619     TBuf<KCommsDbSvrMaxFieldLength> serviceType;
       
  1620    	TBool apEnforce = EFalse;
       
  1621    	TInt err = KErrNone;
       
  1622 	
       
  1623    	TRAP_IGNORE( apEnforce=CheckAPEnforcementL() );
       
  1624    	if(apEnforce)
       
  1625     	{
       
  1626     	_DBG_FILE("CWlanSettings::PerformLockWLANTablesL(): AP enforcement is TRUE");
       
  1627    		wlanTableList.AppendL( TPtrC( WAP_ACCESS_POINT ) );
       
  1628 		wlanTableList.AppendL( TPtrC( WAP_IP_BEARER ) );
       
  1629 		wlanTableList.AppendL( TPtrC( IAP ) );
       
  1630 		//condition when only ap is enforced and not wlan then its not 
       
  1631 		//necessary to add wlanservice table
       
  1632 		RDbRowSet::TAccess checkAccessType;
       
  1633 		checkAccessType =  dbprotect->GetTableAccessL(TPtrC(WLAN_DEVICE_SETTINGS));
       
  1634     	switch(checkAccessType)
       
  1635 			{
       
  1636 			case RDbRowSet::EReadOnly :
       
  1637 				{
       
  1638 				wlanTableList.AppendL( TPtrC(WLAN_SERVICE) );
       
  1639 				wlanTableList.AppendL(TPtrC(WLAN_SECONDARY_SSID) );
       
  1640 				}
       
  1641 			default :	
       
  1642 				{
       
  1643 				break;
       
  1644 				}
       
  1645 			}
       
  1646 		
       
  1647     	}
       
  1648     else
       
  1649     	{
       
  1650     	_DBG_FILE("CWlanSettings::PerformLockWLANTablesL() Only wlan enforcement is ON");
       
  1651     	wlanTableList.AppendL( TPtrC(WLAN_SERVICE) );	
       
  1652     	wlanTableList.AppendL(TPtrC(WLAN_SECONDARY_SSID) );
       
  1653     	}
       
  1654     	
       
  1655    	iDatabase.CommitTransaction();
       
  1656 	                                                               	   
       
  1657    	for ( TInt i( 0 ); i < wlanTableList.Count(); i++ )	
       
  1658    	    {
       
  1659    	    if(!aProtect)
       
  1660    	        {
       
  1661 		   	err = dbprotect->UnProtectTable( wlanTableList[ i ] );
       
  1662 		   	DBG_ARGS(_S16("CWlanSettings::PerformLockWLANTablesL(): Unprotect error  %D"), err);	
       
  1663 		   	//Check if current AP is locked , if yes , unprotect 
       
  1664 			// lock = EFalse;
       
  1665 			}
       
  1666    	    else 
       
  1667 			{
       
  1668 			err = dbprotect->ProtectTable( wlanTableList[ i ] );
       
  1669 			//Check if current ServiceID is not locked , if yes , protect
       
  1670 			// lock = ETrue;
       
  1671 			}
       
  1672    	    } //for loop
       
  1673 	
       
  1674    	CleanupStack::PopAndDestroy(&wlanTableList);
       
  1675    	CleanupStack::PopAndDestroy( dbprotect );		
       
  1676    	CCommsDatabase* commsDataBase = CCommsDatabase::NewL();
       
  1677    	CleanupStack::PushL( commsDataBase );
       
  1678 			
       
  1679 	// Open the IAP from IAP Table and protect 
       
  1680 					
       
  1681 	TUint32 apIAPID = 0;   					
       
  1682 	CCommsDbTableView* iapViews = commsDataBase->OpenViewMatchingUintLC(TPtrC(IAP),
       
  1683 	                                                                    TPtrC(IAP_SERVICE),
       
  1684                                                                         iServiceID);
       
  1685     err = iapViews->GotoFirstRecord();
       
  1686 	// Service ID can be same for GPRS or WLAN, hence check service type and get the iAPID
       
  1687     while (err == KErrNone )
       
  1688         {
       
  1689         iapViews->ReadTextL(TPtrC(IAP_SERVICE_TYPE), serviceType);
       
  1690 		if(serviceType == TPtrC(LAN_SERVICE))    
       
  1691 		    {		           	
       
  1692 		    iapViews->ReadUintL(TPtrC(COMMDB_ID), apIAPID);
       
  1693 		    DBG_ARGS(_S16("CWlanSettings::PerformLockWLANTablesL():  IAPId   %D"), apIAPID);	
       
  1694 		    break;
       
  1695 		    }      
       
  1696 		err = iapViews->GotoNextRecord();
       
  1697         }
       
  1698                                                           
       
  1699         //iapViews->ReadUintL(TPtrC(COMMDB_ID), apIAPID);
       
  1700         DBG_ARGS(_S16("CWlanSettings::PerformLockWLANTablesL(): end. IAP ID being locked %d "), apIAPID );
       
  1701         if(err == KErrNone)		
       
  1702             {	
       
  1703             CCommsDbTableView* iapUpdate = commsDataBase->OpenViewMatchingUintLC(TPtrC(IAP),TPtrC(COMMDB_ID),apIAPID);
       
  1704             TInt iapExists = iapUpdate->GotoFirstRecord();
       
  1705 	
       
  1706             if(!aProtect)                                                                       	
       
  1707                 {	
       
  1708                 ((CCommsDbProtectTableView*)iapViews)->UnprotectRecord(); 	
       
  1709                 if (iapExists)		
       
  1710                     {	
       
  1711                     ((CCommsDbProtectTableView*)iapUpdate)->UnprotectRecord();
       
  1712                     }
       
  1713                 }	
       
  1714             else
       
  1715         		{
       
  1716         		((CCommsDbProtectTableView*)iapViews)->ProtectRecord();
       
  1717         		if (iapExists)
       
  1718         			{
       
  1719         			((CCommsDbProtectTableView*)iapUpdate)->ProtectRecord();
       
  1720         			}
       
  1721         		}
       
  1722         	CleanupStack::PopAndDestroy(); // iapUpdate
       
  1723             }
       
  1724     
       
  1725         CleanupStack::PopAndDestroy( iapViews );
       
  1726         CleanupStack::PopAndDestroy( commsDataBase );
       
  1727             
       
  1728         iDatabase.BeginTransaction();
       
  1729 		return err;
       
  1730     }
       
  1731   
       
  1732