terminalsecurity/SCP/SCPServer/src/SCPServer.cpp
branchRCL_3
changeset 24 13d7c31c74e0
parent 18 2de6635c154b
child 25 b183ec05bd8c
equal deleted inserted replaced
23:4af31167ea77 24:13d7c31c74e0
   127        
   127        
   128     iConfiguration.Initialize();
   128     iConfiguration.Initialize();
   129     
   129     
   130     // Assign default config flag
   130     // Assign default config flag
   131     iConfiguration.iConfigFlag = KSCPConfigUnknown;
   131     iConfiguration.iConfigFlag = KSCPConfigUnknown;
   132     iConfiguration.iConfigChecked = EFalse;
   132     
   133     
   133     
   134     // Assign the default codes
   134     // Assign the default codes
   135     iConfiguration.iSecCode.Zero();
   135     iConfiguration.iSecCode.Zero();
   136     iConfiguration.iSecCode.Append( KSCPDefaultSecCode );
   136     iConfiguration.iSecCode.Append( KSCPDefaultSecCode );
   137 
   137 
   167     CleanupStack::PopAndDestroy( codeHBuf );
   167     CleanupStack::PopAndDestroy( codeHBuf );
   168 }
   168 }
   169 //#endif
   169 //#endif
   170    
   170    
   171     // Assign the default max timeout
   171     // Assign the default max timeout
   172     iConfiguration.iMaxTimeout = KSCPDefaultMaxTO;
   172     iConfiguration.iMaxTimeout = 0;
   173    	iConfiguration.iBlockedInOOS = 0;
   173    	iConfiguration.iBlockedInOOS = 0;
   174    
   174    
   175     // Read the configuration, overwriting the default values
   175     // Read the configuration, overwriting the default values
   176     TInt ret = KErrNone;
   176     TInt ret = KErrNone;
   177     TRAPD( err, ret = iConfiguration.ReadSetupL() );
   177     TRAPD( err, ret = iConfiguration.ReadSetupL() );
   184         {
   184         {
   185         Dprint( (_L("CSCPServer::ConstructL(): Configration read OK") ));
   185         Dprint( (_L("CSCPServer::ConstructL(): Configration read OK") ));
   186         }
   186         }
   187     
   187     
   188     
   188     
   189     //If Configuration is not validated already, validate it
   189    
   190     
   190 
   191     if (!iConfiguration.iConfigChecked)
       
   192         {
       
   193         TInt valerr = KErrNone;
       
   194         TRAP( valerr, ValidateConfigurationL( KSCPComplete ));
       
   195         if (valerr != KErrNone)
       
   196             {
       
   197             Dprint( (_L("CSCPServer::ConstructL(): Configuration Validation failed: %d"), valerr ));
       
   198             }
       
   199         else
       
   200             {
       
   201             Dprint( (_L("CSCPServer::ConstructL(): Configuration Validation Passed")));
       
   202             }
       
   203         }
       
   204     
       
   205         
       
   206         
       
   207     Dprint( (_L("CSCPServer::ConstructL(): Connecting to CenRep") ));
   191     Dprint( (_L("CSCPServer::ConstructL(): Connecting to CenRep") ));
   208     iALPeriodRep = CRepository::NewL( KCRUidSecuritySettings );        
   192     iALPeriodRep = CRepository::NewL( KCRUidSecuritySettings );        
   209     
   193     
   210     // Check for factory settings
   194     // Check for factory settings
   211     CheckIfRfsPerformedL();
   195     CheckIfRfsPerformedL();
   666 // Status : Approved
   650 // Status : Approved
   667 // ---------------------------------------------------------
   651 // ---------------------------------------------------------
   668 //	
   652 //	
   669 void CSCPServer::ValidateConfigurationL( TInt aMode )
   653 void CSCPServer::ValidateConfigurationL( TInt aMode )
   670     {
   654     {
   671     Dprint( (_L("--> CSCPServer::ValidateConfigurationL()") ));
   655     if (aMode == KSCPInitial) {
   672     RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()"));
   656         // Return here, must be checked by complete mode
   673     TInt startupReason(ENormalStartup);
   657         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@@aMode == KSCPInitial "));
   674     RProperty::Get(KPSUidStartup, KPSStartupReason, startupReason);
   658         User::Leave(KErrAccessDenied);
   675     Dprint( (_L("CSCPServer::ValidateConfigurationL(): startupReason = %d"), startupReason));
   659     }
   676      if((startupReason == ENormalRFSReset)||(startupReason ==  EDeepRFSReset)||(startupReason == EFirmwareUpdate)||(iConfiguration.iConfigFlag == KSCPConfigUnknown))
   660     
   677          {
   661     RMobilePhone::TMobilePassword storedCode;
   678     
       
   679 	RMobilePhone::TMobilePassword storedCode;
       
   680     storedCode.Zero();
   662     storedCode.Zero();
   681     User::LeaveIfError(GetCode(storedCode));
   663     User::LeaveIfError(GetCode(storedCode));
   682     
   664     TBool isDefaultLockcode = ETrue;
   683     
   665     TInt err = KErrNone;
   684 	Dprint( (_L("CSCPServer::ValidateConfigurationL(): Checking code: %s"), storedCode.PtrZ() ));
   666     
   685 	// Check that the ISA code is stored correctly
   667     RMobilePhone::TMobilePassword defaultLockcode;
   686 	TRAPD( err, CheckISACodeL( storedCode ) );
   668     defaultLockcode.Zero();
   687 	 //Bool for the correction of Defaultlockcode cenrep
   669     defaultLockcode.Copy(KSCPDefaultSecCode);
   688     TBool lCorrectDefaultlockcode = EFalse;
   670     if (storedCode.Compare(KSCPDefaultSecCode) == 0) {
   689     
   671         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@config has KSCPDefaultSecCode "));
   690      Dprint( (_L("CSCPServer::ValidateConfigurationL(): iConfigFlag = %d, iConfigChecked = %d"), iConfiguration.iConfigFlag, iConfiguration.iConfigChecked));
   672         TRAP( err, CheckISACodeL( defaultLockcode ) );
   691      
   673         if (err == KErrNone) {
   692     if ((iConfiguration.iConfigFlag == KSCPConfigOK)
   674             RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@ISA also has KSCPDefaultSecCode "));
   693             && (iConfiguration.iConfigChecked) && (err == KErrNone))
   675             iConfiguration.iConfigFlag = KSCPConfigOK;
   694         {
   676             isDefaultLockcode = ETrue;
   695         // The configuration has already been checked, exit
   677         }
   696         Dprint( (_L("CSCPServer::ValidateConfigurationL(): Configuration is non-default.") ));
   678         else {
   697         User::Leave( KErrNone );
   679             RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@ISA doesn't has KSCPDefaultSecCode "));
   698         }
   680             iConfiguration.iConfigFlag = KSCPConfigInvalid;
   699     else if ( aMode == KSCPInitial )
   681             iConfiguration.iFailedAttempts++;
   700         {
   682             isDefaultLockcode = EFalse;
   701         // Return here, must be checked by complete mode
   683         }
   702         User::Leave( KErrAccessDenied );
   684     }
   703         }
   685     else {
   704     
   686         RDebug::Print(_L("CSCPServer::CheckISACodeL(): config lock code %s"), storedCode.PtrZ());
   705    
   687         TRAP( err, CheckISACodeL( storedCode ) );
   706     TInt hashedISAcode;
   688         if (err == KErrNone) {
   707     TSCPSecCode hashedCode;
   689             RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@ISA and config are in SYNC !! "));
   708 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS    
   690             iConfiguration.iConfigFlag = KSCPConfigOK;
   709 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
   691             isDefaultLockcode = EFalse;
   710 {
   692         }
   711 	/*TInt*/ hashedISAcode = HashISACode( iConfiguration.iEnhSecCode );
   693         else {
   712    // TSCPSecCode hashedCode;
   694             iConfiguration.iSecCode.Zero();
   713     hashedCode.Zero();
   695             iConfiguration.iSecCode.Append(KSCPDefaultSecCode);
   714     hashedCode.AppendNum( hashedISAcode );
   696             RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@May be ISA has KSCPDefaultSecCode "));
       
   697             TRAP(err,ChangeISACodeL(storedCode));
       
   698             if (err == KErrNone) {
       
   699                 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()chnaged ISA code with config value "));
       
   700                 iConfiguration.iConfigFlag = KSCPConfigOK;
       
   701                 isDefaultLockcode = EFalse;
       
   702             }
       
   703             else
       
   704             {
       
   705                 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()it shouldn't reach this :( "));
       
   706             }
       
   707         }
       
   708     }
       
   709 
       
   710     CRepository* repository = CRepository::NewL(KCRUidSCPLockCode);
       
   711     CleanupStack::PushL(repository);
       
   712     if (isDefaultLockcode ) {
       
   713         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()setting def. lockcode to 12345 "));
       
   714         repository->Set(KSCPLockCodeDefaultLockCode, 12345);
       
   715     }
       
   716     else {
       
   717         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()setting def. lockcode to 0 "));
       
   718         repository->Set(KSCPLockCodeDefaultLockCode, 0);
       
   719     }
       
   720     CleanupStack::PopAndDestroy(repository);
       
   721     
       
   722     TRAP( err, iConfiguration.WriteSetupL() );
       
   723     if (err != KErrNone) {
       
   724         Dprint( (_L("CSCPServer::ValidateConfigurationL(): WARNING: failed to write configuration\
       
   725                 : %d"), err ));
       
   726     }
       
   727 
       
   728     if (iConfiguration.iConfigFlag == KSCPConfigOK) {
       
   729         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@iConfigFlag == KSCPConfigOK "));
       
   730         err = KErrNone;
       
   731     }
       
   732     else {
       
   733         RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@iConfigFlag == KErrAccessDenied "));
       
   734         err = KErrAccessDenied;
       
   735     }
       
   736 
       
   737     User::LeaveIfError(err);
   715 }
   738 }
   716 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS    
   739 
   717             
       
   718     
       
   719     
       
   720    
       
   721     if (err != KErrNone)
       
   722         {
       
   723         lCorrectDefaultlockcode = ETrue;
       
   724         }
       
   725     if ( err == KErrNone ) 
       
   726         {
       
   727         iConfiguration.iConfigFlag = KSCPConfigOK;
       
   728         }
       
   729     else if ( err == KErrAccessDenied )
       
   730         {        
       
   731         iConfiguration.iConfigFlag = KSCPConfigInvalid;
       
   732         }
       
   733     else if ( err == KErrLocked )
       
   734         {
       
   735         Dprint( (_L("CSCPServer::ValidateConfigurationL(): ISA code locked.") ));
       
   736         }
       
   737     else
       
   738         {
       
   739         Dprint( (_L("CSCPServer::ValidateConfigurationL(): ERROR in validation.") ));
       
   740         }
       
   741 
       
   742 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS         
       
   743 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
       
   744 {
       
   745     if ( err == KErrNone )
       
   746         {
       
   747         // Check that the codes are in-sync with each other. Especially the default ISA code must
       
   748         // be changed according to the default enhanced code.        
       
   749         if ( storedCode.Compare( hashedCode ) != 0 )
       
   750             {
       
   751             Dprint( (_L("CSCPServer::ValidateConfigurationL(): Correct ISA code stored.\
       
   752                Changing ISA code to match enhanced code => %d"), hashedISAcode ));
       
   753                
       
   754             storedCode.Copy( hashedCode );
       
   755             // Change the ISA code to match the hashed code
       
   756             ChangeISACodeL( storedCode );
       
   757             }
       
   758         }
       
   759     else if ( ( err == KErrAccessDenied ) && ( storedCode.Compare( hashedCode ) != 0 ) )
       
   760         {
       
   761         // Try again with the hashed code
       
   762         TRAP( err, CheckISACodeL( hashedCode ) );
       
   763         
       
   764         if ( err == KErrNone )
       
   765             {            
       
   766             Dprint( (_L("CSCPServer::ValidateConfigurationL(): Hashed code is correct.\
       
   767                Storing hashed code(%d)"), hashedISAcode ));
       
   768                
       
   769             if ( StoreCode( hashedCode ) == KErrNone )
       
   770                 {
       
   771                 iConfiguration.iConfigFlag = KSCPConfigOK;
       
   772                 lCorrectDefaultlockcode = ETrue;
       
   773                 }
       
   774             }        
       
   775         }
       
   776     
       
   777     //If Correction of Defaultlockcode cenrep is required for the mismatch between Config and ISA
       
   778         if (lCorrectDefaultlockcode)
       
   779             {
       
   780             TInt lDefCode = -1;
       
   781             CRepository* lRepository = CRepository::NewL(KCRUidSCPLockCode);
       
   782             CleanupStack::PushL(lRepository);
       
   783             TInt lRet = lRepository->Get(KSCPLockCodeDefaultLockCode,
       
   784                     lDefCode);
       
   785             if (lRet == KErrNone && lDefCode != -1)
       
   786                 {
       
   787                 if (lDefCode == 12345)
       
   788                     {
       
   789                     //Although lock code is already set, due to some unexpected condition
       
   790                     //like C drive wipe, cenrep status is wrongly shown. Correcting it here.
       
   791                     lRepository->Set(KSCPLockCodeDefaultLockCode, 0);
       
   792                     Dprint( (_L("RSCPClient::ValidateConfigurationL(): Corrected the Default lock code cenrep status to 0") ));
       
   793                     }
       
   794                 else if (lDefCode == 0)
       
   795                     {
       
   796                     //If only ISA side is formatted, then the lock code on ISA side is default; 
       
   797                     //Cenrep status remains wrongly as the lock code is already set. Correcting it here.
       
   798                     lRepository->Set(KSCPLockCodeDefaultLockCode, 12345);
       
   799                     Dprint( (_L("RSCPClient::ValidateConfigurationL(): Corrected the Default lock code cenrep status to 12345") ));
       
   800                     }
       
   801                 }
       
   802             CleanupStack::PopAndDestroy(lRepository);
       
   803             }
       
   804         }
       
   805 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
       
   806     //Set the flag to True, after config is validated 
       
   807     iConfiguration.iConfigChecked = ETrue;
       
   808     
       
   809     TRAPD( err2, iConfiguration.WriteSetupL() );
       
   810     if ( err2 != KErrNone )
       
   811         {
       
   812         Dprint( (_L("CSCPServer::ValidateConfigurationL(): WARNING: failed to write configuration\
       
   813             : %d"), err2 ));        
       
   814         } 
       
   815     
       
   816     User::LeaveIfError( err );
       
   817          }
       
   818     Dprint( (_L("<-- CSCPServer::ValidateConfigurationL()") ));
       
   819     }
       
   820 
   740 
   821         
   741         
   822     
   742     
   823     
   743     
   824 // ---------------------------------------------------------
   744 // ---------------------------------------------------------
   835 #ifdef __WINS__    
   755 #ifdef __WINS__    
   836     
   756     
   837     (void)aCode;    
   757     (void)aCode;    
   838 
   758 
   839 #endif // __WINS__
   759 #endif // __WINS__
   840    
   760 
       
   761 
       
   762 Dprint( (_L("CSCPServer::CheckISACodeL(): current lock code %s"), aCode.PtrZ() ));
       
   763 RDebug::Print(_L("CSCPServer::CheckISACodeL(): current lock code %s"), aCode.PtrZ());
   841     RMobilePhone::TMobilePhoneSecurityCode secCodeType;
   764     RMobilePhone::TMobilePhoneSecurityCode secCodeType;
   842     secCodeType = RMobilePhone::ESecurityCodePhonePassword;
   765     secCodeType = RMobilePhone::ESecurityCodePhonePassword;
   843     
   766     
   844     RMobilePhone::TMobilePassword required_fourth;
   767     RMobilePhone::TMobilePassword required_fourth;
   845                 
   768                 
   871             Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code NOT OK") ));
   794             Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code NOT OK") ));
   872             if (iConfiguration.iBlockedInOOS == 1)
   795             if (iConfiguration.iBlockedInOOS == 1)
   873 	         {
   796 	         {
   874 	            	iConfiguration.iBlockedInOOS = 0;
   797 	            	iConfiguration.iBlockedInOOS = 0;
   875    	            	Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 0, KErrAccessDenied") ));
   798    	            	Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 0, KErrAccessDenied") ));
       
   799    	            	RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@iBlockedInOOS = 0, KErrAccessDenie"));
   876 	         }            
   800 	         }            
   877             ret = KErrAccessDenied;             
   801             ret = KErrAccessDenied;             
   878             }
   802             }
   879         else if ( ( ret == KErrGsmSSPasswordAttemptsViolation ) || ( ret == KErrLocked ) )
   803         else if ( ( ret == KErrGsmSSPasswordAttemptsViolation ) || ( ret == KErrLocked ) )
   880             {
   804             {
   881             Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code BLOCKED") ));            
   805             Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code BLOCKED") ));            
   882             if (ret==KErrGsmSSPasswordAttemptsViolation)
   806             if (ret==KErrGsmSSPasswordAttemptsViolation)
   883             {
   807             {
   884             	Dprint( (_L("CSCPServer::CheckISACodeL(): KErrGsmSSPasswordAttemptsViolation") ));            	
   808             	Dprint( (_L("CSCPServer::CheckISACodeL(): KErrGsmSSPasswordAttemptsViolation") ));  
       
   809             	RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@KErrGsmSSPasswordAttemptsViolation"));
   885             }
   810             }
   886             else
   811             else
   887             {
   812             {
   888             	Dprint( (_L("CSCPServer::CheckISACodeL(): KErrLocked") ));
   813             	Dprint( (_L("CSCPServer::CheckISACodeL(): KErrLocked") ));
       
   814             	RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@KErrLocked"));
   889             }	            
   815             }	            
   890             ret = KErrLocked;
   816             ret = KErrLocked;
   891             if (iConfiguration.iBlockedInOOS == 0)
   817             if (iConfiguration.iBlockedInOOS == 0)
   892         	 {
   818         	 {
   893             	iConfiguration.iBlockedInOOS = 1;
   819             	iConfiguration.iBlockedInOOS = 1;
   894             	Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 1, KSCPErrCodeBlockStarted") ));
   820             	Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 1, KSCPErrCodeBlockStarted") ));
       
   821             	RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@@@@"));
   895             	ret = KSCPErrCodeBlockStarted;	
   822             	ret = KSCPErrCodeBlockStarted;	
   896         	 }
   823         	 }
   897             }            
   824             }            
   898         else
   825         else
   899             {
   826             {
   900             Dprint( (_L("CSCPServer::CheckISACodeL(): ERROR reply checking ISA code: %d"),
   827             Dprint( (_L("CSCPServer::CheckISACodeL(): ERROR reply checking ISA code: %d"),
   901                 status.Int() ));
   828                 status.Int() ));
       
   829                 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()"));
   902             }            
   830             }            
   903         }
   831         }
   904         TRAPD( err, iConfiguration.WriteSetupL() );
   832         TRAPD( err, iConfiguration.WriteSetupL() );
   905         if ( err != KErrNone )
   833         if ( err != KErrNone )
   906             {
   834             {
  1014     		 * already set
   942     		 * already set
  1015     		 * */
   943     		 * */
  1016     		TRAP(err, repository = CRepository :: NewL(KCRUidSCPLockCode));
   944     		TRAP(err, repository = CRepository :: NewL(KCRUidSCPLockCode));
  1017     		
   945     		
  1018     		if(err == KErrNone) {
   946     		if(err == KErrNone) {
       
   947     			RDebug::Print(_L("<-- CSCPServer::StoreEnhCode()  setting KSCPLockCodeDefaultLockCode to 0"));
  1019                 err = repository->Set(KSCPLockCodeDefaultLockCode, 0);
   948                 err = repository->Set(KSCPLockCodeDefaultLockCode, 0);
  1020                 delete repository;
   949                 delete repository;
  1021     		}
   950     		}
  1022         	}    
   951         	}    
  1023         }
   952         }
  1349 #endif // __SCP_DEBUG    
  1278 #endif // __SCP_DEBUG    
  1350     
  1279     
  1351     TInt lRetStatus(KErrNone);
  1280     TInt lRetStatus(KErrNone);
  1352     Dprint(_L("[CSCPServer]-> Initiating branching on parameter..."));
  1281     Dprint(_L("[CSCPServer]-> Initiating branching on parameter..."));
  1353     
  1282     
  1354     switch ( aID )
  1283     switch(aID) {
  1355         {
  1284         case ESCPAutolockPeriod:
  1356         case ( ESCPAutolockPeriod ):
  1285         case ESCPMaxAutolockPeriod: {
  1357         // Flow through            
       
  1358         case ( ESCPMaxAutolockPeriod ):
       
  1359             {
       
  1360             // Convert the value, and set it
  1286             // Convert the value, and set it
  1361             TInt value;
  1287             TInt value;
  1362             TLex lex(aValue);
  1288             TLex lex(aValue);
  1363             lRetStatus = lex.Val(value);
  1289             lRetStatus = lex.Val(value);
  1364              
       
  1365 
  1290 
  1366             if((lRetStatus != KErrNone ) || ( value < 0) || ( value > KSCPAutolockPeriodMaximum )) {
  1291             if((lRetStatus != KErrNone ) || ( value < 0) || ( value > KSCPAutolockPeriodMaximum )) {
  1367                 lRetStatus = KErrArgument;
  1292                 lRetStatus = KErrArgument;
  1368                 break;
  1293                 break;
  1369                 }
  1294             }
  1370                   
  1295                   
  1371             //Check if the device memory is encrypted or not.
  1296             //Check if the device memory is encrypted or not.
  1372             TBool encryptionEnabled = IsDeviceMemoryEncrypted();
  1297             TBool encryptionEnabled = IsDeviceMemoryEncrypted();
       
  1298             CSCPParamDBController* lParamDB = CSCPParamDBController :: NewLC();
  1373             
  1299             
  1374             // Value OK
  1300             // Value OK
  1375             if(aID == ESCPMaxAutolockPeriod) 
  1301             if(aID == ESCPMaxAutolockPeriod) {
  1376 						{
  1302                 if( encryptionEnabled ) {
  1377 						   if (  encryptionEnabled )
  1303                     Dprint(_L("[CSCPServer]-> Memory is encrypted"));
  1378                   {
  1304                     
  1379                   Dprint(_L("Memory is encrypted"));
  1305                     if(( 0 == value) || value > KMaxAutolockPeriod) {
  1380                   if (( 0 == value) || value > KMaxAutolockPeriod)
  1306                         Dprint((_L("[CSCPServer]-> Denying setting of max auto lock as value is %d"), value));
  1381                       {
  1307                         User :: Leave( KErrPermissionDenied );
  1382                       Dprint((_L("Denying setting of max auto lock as value is %d"), value));
  1308                     }
  1383                       User::Leave( KErrPermissionDenied );
  1309                 }
  1384                       }
  1310                 else {
  1385                       
       
  1386                   }
       
  1387                 else
       
  1388                     {
       
  1389                     Dprint(_L("Memory is decrypted, hence no restrictions to max autolock"));
  1311                     Dprint(_L("Memory is decrypted, hence no restrictions to max autolock"));
  1390                     }
  1312                 }
  1391                     
  1313                     
  1392                 Dprint(_L("[CSCPServer]-> Branched to ESCPMaxAutolockPeriod..."));
  1314                 Dprint(_L("[CSCPServer]-> Branched to ESCPMaxAutolockPeriod..."));                
  1393                 CSCPParamDBController* lParamDB = CSCPParamDBController :: NewLC();
       
  1394                 lRetStatus = SetBestPolicyL(RTerminalControl3rdPartySession :: EMaxTimeout, aValue, aCallerIdentity, lParamDB);
  1315                 lRetStatus = SetBestPolicyL(RTerminalControl3rdPartySession :: EMaxTimeout, aValue, aCallerIdentity, lParamDB);
  1395 
  1316 
  1396                 if(lRetStatus == KErrNone) 
  1317                 if(lRetStatus == KErrNone) {
  1397 								{
       
  1398                     // Do we have to change the Autolock period as well?
  1318                     // Do we have to change the Autolock period as well?
  1399                     TInt currentALperiod;
  1319                     TInt currentALperiod;
  1400                     lRetStatus = GetAutolockPeriodL(currentALperiod);
  1320                     lRetStatus = GetAutolockPeriodL(currentALperiod);
  1401 
  1321 
  1402                     if(lRetStatus == KErrNone) 
  1322                     if(lRetStatus == KErrNone) {
  1403 										{
  1323                         if( (iConfiguration.iMaxTimeout > 0) && 
  1404                         if((iConfiguration.iMaxTimeout > 0) && ((iConfiguration.iMaxTimeout < currentALperiod) || (currentALperiod == 0))) 
  1324                             ((iConfiguration.iMaxTimeout < currentALperiod) ||
  1405 												{
  1325                             (currentALperiod == 0))) {
       
  1326                         
  1406                            Dprint((_L("[CSCPServer]-> Changing AL period to Max. AL period (Current ALP: %d, Max. ALP: %d)"), currentALperiod, value));
  1327                            Dprint((_L("[CSCPServer]-> Changing AL period to Max. AL period (Current ALP: %d, Max. ALP: %d)"), currentALperiod, value));
  1407                            lRetStatus = SetAutolockPeriodL(value);
  1328                            //lRetStatus = SetAutolockPeriodL(value);                           
       
  1329                            /*
       
  1330                             * Call to SetBestPolicyL will not check for Stronger/Weaker. The value of ETimeout just gets stored in 
       
  1331                             * both the internal DB and the CenRep
       
  1332                            */
       
  1333                            lRetStatus = SetBestPolicyL(RTerminalControl3rdPartySession :: ETimeout, aValue, aCallerIdentity, lParamDB);
  1408                         }
  1334                         }
  1409                     }
  1335                     }
  1410                     else 
  1336                     else {
  1411 										{
       
  1412                         Dprint((_L("[CSCPServer]-> ERROR: Couldn't get the Autolock period: %d"), lRetStatus));
  1337                         Dprint((_L("[CSCPServer]-> ERROR: Couldn't get the Autolock period: %d"), lRetStatus));
  1413                     }
  1338                     }
  1414                 }
  1339                 }
  1415 
  1340             }
  1416                 CleanupStack :: PopAndDestroy(); //lParamDB
  1341             // Autolock Period
  1417             }
  1342             else {
  1418             
  1343                 //Code is commented as it is already taken care by the below condition #1343 irrespective of the drive encryption state.
  1419             else 
  1344                 /*  if ( 0 == value ) {
  1420             { // Autolock Period
  1345                     if(encryptionEnabled) {
  1421             	
       
  1422             			//Code is commented as it is already taken care by the below condition #1343 irrespective of the drive encryption state.
       
  1423             	     /*  if ( 0 == value )
       
  1424                     {
       
  1425                     if ( encryptionEnabled )
       
  1426                         {
       
  1427                         Dprint(_L("Permission denied!"));
  1346                         Dprint(_L("Permission denied!"));
  1428                         User::Leave( KErrPermissionDenied );
  1347                         User :: Leave(KErrPermissionDenied);
  1429                         }
  1348                     }
  1430                     }*/
  1349                 }*/
  1431                     
  1350 
  1432                 Dprint(_L("[CSCPServer]-> Branched to ESCPAutolockPeriod..."));
  1351                 Dprint(_L("[CSCPServer]-> Branched to ESCPAutolockPeriod..."));
  1433                 //  Check if this value is not allowed by the Max. Autolock period
  1352                 //  Check if this value is not allowed by the Max. Autolock period
  1434                 if ((iConfiguration.iMaxTimeout > 0) && ((iConfiguration.iMaxTimeout < value) || (value == 0))) {
  1353                 if ((iConfiguration.iMaxTimeout > 0) && ((iConfiguration.iMaxTimeout < value) || (value == 0))) {
  1435                     Dprint((_L("[CSCPServer]-> ERROR: The value %d for AL period not allowed (Max. AL period: %d)"), value, iConfiguration.iMaxTimeout));
  1354                     Dprint((_L("[CSCPServer]-> ERROR: The value %d for AL period not allowed (Max. AL period: %d)"), value, iConfiguration.iMaxTimeout));
  1436 
  1355 
  1437                     lRetStatus = KErrArgument;
  1356                     lRetStatus = KErrArgument;
  1438                 }
  1357                 }
  1439                 else {
  1358                 else {
  1440                     lRetStatus = SetAutolockPeriodL(value);
  1359                     //lRetStatus = SetAutolockPeriodL(value);
       
  1360                     /*
       
  1361                      * Call to SetBestPolicyL will not check for Stronger/Weaker. The value of ETimeout just gets stored in 
       
  1362                      * both the internal DB and the CenRep
       
  1363                     */
       
  1364                     lRetStatus = SetBestPolicyL(RTerminalControl3rdPartySession :: ETimeout, aValue, aCallerIdentity, lParamDB);
  1441 
  1365 
  1442                     if(lRetStatus != KErrNone) {
  1366                     if(lRetStatus != KErrNone) {
  1443                         Dprint((_L("[CSCPServer]-> ERROR: Couldn't set the Autolock period: %d"), lRetStatus));
  1367                         Dprint((_L("[CSCPServer]-> ERROR: Couldn't set the Autolock period: %d"), lRetStatus));
  1444                     }
  1368                     }
  1445                 }
  1369                 }
  1446             }
  1370             }
       
  1371             
       
  1372             CleanupStack :: PopAndDestroy(); //lParamDB
  1447         }
  1373         }
  1448         break;
  1374         break;
  1449         case ESCPCodeChangePolicy:
  1375         case ESCPCodeChangePolicy:
  1450             Dprint(_L("[CSCPServer]-> Branched to ESCPCodeChangePolicy..."));
  1376             Dprint(_L("[CSCPServer]-> Branched to ESCPCodeChangePolicy..."));
  1451             lRetStatus = ChangeCodePolicy( aValue );
  1377             lRetStatus = ChangeCodePolicy( aValue );
  2081 // Status : Approved
  2007 // Status : Approved
  2082 // ---------------------------------------------------------
  2008 // ---------------------------------------------------------
  2083 //  
  2009 //  
  2084 TInt CSCPServer::IsCorrectEnhCode( TDes& aCode, TInt aFlags )
  2010 TInt CSCPServer::IsCorrectEnhCode( TDes& aCode, TInt aFlags )
  2085     {
  2011     {
  2086     
  2012     Dprint( (_L("CSCPServer::IsCorrectEnhCode(): ") ));
  2087     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2013     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  2088     {
  2014     {
  2089     	return KErrNotSupported;
  2015     	return KErrNotSupported;
  2090     }
  2016     }
  2091     TInt ret = KErrAccessDenied;
  2017     TInt ret = KErrAccessDenied;
  2092     
  2018    
  2093     // Hash the code
  2019     // Hash the code
  2094     TBuf<KSCPMaxHashLength> hashBuf;
  2020     TBuf<KSCPMaxHashLength> hashBuf;
  2095     hashBuf.Zero();
  2021     hashBuf.Zero();
  2096     iPluginEventHandler->HashInput( aCode, hashBuf );
  2022     iPluginEventHandler->HashInput( aCode, hashBuf );
  2097         
  2023         
  2102     pswCandidate.AppendNum( ISACode );
  2028     pswCandidate.AppendNum( ISACode );
  2103         
  2029         
  2104     TBool enhancedCodeMatches = EFalse;
  2030     TBool enhancedCodeMatches = EFalse;
  2105     if ( hashBuf.Compare( iConfiguration.iEnhSecCode ) == 0 )
  2031     if ( hashBuf.Compare( iConfiguration.iEnhSecCode ) == 0 )
  2106         {
  2032         {
       
  2033         	Dprint( (_L("CSCPServer::IsCorrectEnhCode(): enh code matches.") ));
  2107         enhancedCodeMatches = ETrue;
  2034         enhancedCodeMatches = ETrue;
  2108         }
  2035         }
  2109         
  2036         
  2110     // Check if the code is blocked (don't check if we're out-of-sync)
  2037     // Check if the code is blocked (don't check if we're out-of-sync)
  2111     if ( ( iConfiguration.iConfigFlag == KSCPConfigOK ) && ( IsCodeBlocked() ) )
  2038     if ( ( iConfiguration.iConfigFlag == KSCPConfigOK ) && ( IsCodeBlocked() ) )
  2112         {
  2039         {
       
  2040         	Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 1") ));
  2113         if ( aFlags & KSCPEtelRequest )
  2041         if ( aFlags & KSCPEtelRequest )
  2114             {
  2042             {
       
  2043             	Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 2") ));
  2115             // Check if the code is correct
  2044             // Check if the code is correct
  2116             if ( enhancedCodeMatches )
  2045             if ( enhancedCodeMatches )
  2117                 {
  2046                 {
  2118                 // Mess-up the code                 
  2047                 // Mess-up the code                 
  2119                 RMobilePhone::TMobilePassword codeToSend;
  2048                 RMobilePhone::TMobilePassword codeToSend;
  2123                 SendInvalidDOSCode( codeToSend );
  2052                 SendInvalidDOSCode( codeToSend );
  2124                 }
  2053                 }
  2125             else 
  2054             else 
  2126                 {
  2055                 {
  2127                 // OK, the code is already invalid
  2056                 // OK, the code is already invalid
       
  2057                 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 3") ));
  2128                 SendInvalidDOSCode( pswCandidate );
  2058                 SendInvalidDOSCode( pswCandidate );
  2129                 }
  2059                 }
  2130             }
  2060             }
  2131         return KErrLocked;
  2061         return KErrLocked;
  2132         }       
  2062         }       
  2135     
  2065     
  2136     if ( iConfiguration.iConfigFlag == KSCPConfigOK )
  2066     if ( iConfiguration.iConfigFlag == KSCPConfigOK )
  2137         {
  2067         {
  2138         // Normal situation: we have the correct code stored.
  2068         // Normal situation: we have the correct code stored.
  2139         // Compare the hashes (hashing error will result in EFalse )
  2069         // Compare the hashes (hashing error will result in EFalse )
       
  2070         Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 4") ));
  2140         if ( enhancedCodeMatches )
  2071         if ( enhancedCodeMatches )
  2141             {
  2072             {
  2142             ret = KErrNone;
  2073             ret = KErrNone;
  2143             
  2074             
  2144             if ( aFlags & KSCPEtelRequest )
  2075             if ( aFlags & KSCPEtelRequest )
  2145                 {
  2076                 {
  2146                 // Send the correct code to DOS side
  2077                 // Send the correct code to DOS side
       
  2078                 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 5") ));
  2147                 TRAP( ret, CheckISACodeL( pswCandidate ) );
  2079                 TRAP( ret, CheckISACodeL( pswCandidate ) );
  2148                 }  
  2080                 }  
  2149                 
  2081                 
  2150             if ( ret == KErrNone )
  2082             if ( ret == KErrNone )
  2151                 {
  2083                 {
  2152                 if ( iConfiguration.iFailedAttempts > 0 )
  2084                 if ( iConfiguration.iFailedAttempts > 0 )
  2153                     {
  2085                     {
  2154                     iConfiguration.iFailedAttempts = 0;  
  2086                     iConfiguration.iFailedAttempts = 0;  
  2155                     Dprint( (_L("CSCPServer::IsCorrectEnhCode():KErrAccessDenied: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts ));
  2087                     Dprint( (_L("CSCPServer::IsCorrectEnhCode():: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts ));
  2156                     writeSetup = ETrue;
  2088                     writeSetup = ETrue;
  2157                     }                
  2089                     }                
  2158                 }
  2090                 }
  2159             else
  2091             else
  2160                 {
  2092                 {
  2165         else
  2097         else
  2166             {
  2098             {
  2167             ret = KErrAccessDenied;
  2099             ret = KErrAccessDenied;
  2168             
  2100             
  2169             iConfiguration.iFailedAttempts++;
  2101             iConfiguration.iFailedAttempts++;
  2170             Dprint( (_L("CSCPServer::IsCorrectEnhCode():KErrAccessDenied: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts ));
  2102             Dprint( (_L("CSCPServer::IsCorrectEnhCode():@@@: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts ));
  2171             writeSetup = ETrue;
  2103             writeSetup = ETrue;
  2172             
  2104             
  2173             if ( iConfiguration.iFailedAttempts == KSCPCodeBlockLimit )
  2105             if ( iConfiguration.iFailedAttempts == KSCPCodeBlockLimit )
  2174                 {
  2106                 {
       
  2107                 	Dprint( (_L("CSCPServer::IsCorrectEnhCode(): KSCPCodeBlockLimit  ") ));
  2175                 // Block the code
  2108                 // Block the code
  2176                 TTime curTime;
  2109                 TTime curTime;
  2177                 curTime.UniversalTime();
  2110                 curTime.UniversalTime();
  2178                 
  2111                 
  2179                 iConfiguration.iBlockedAtTime.Zero();
  2112                 iConfiguration.iBlockedAtTime.Zero();
  2190             }
  2123             }
  2191         }
  2124         }
  2192     else 
  2125     else 
  2193         {
  2126         {
  2194         // iConfiguration.iConfigFlag == KSCPConfigInvalid or KSCPConfigUnknown
  2127         // iConfiguration.iConfigFlag == KSCPConfigInvalid or KSCPConfigUnknown
  2195         
  2128 
  2196         // We might be out-of-sync, no idea about the real code.
  2129         // We might be out-of-sync, no idea about the real code.
  2197         // Check if the DOS code hashed from the given code is correct.
  2130         // Check if the DOS code hashed from the given code is correct.
  2198         Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Attempting to correct OoS situation.") ));
  2131         Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Attempting to correct OoS situation.") ));
  2199                 
  2132         if (IsCodeBlocked()) {
       
  2133             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): OOS ->KErrLocked  ") ));
       
  2134             return KErrLocked;
       
  2135         }
  2200         TRAP( ret, CheckISACodeL( pswCandidate ) );
  2136         TRAP( ret, CheckISACodeL( pswCandidate ) );
  2201 
  2137 
  2202         if ( ret == KErrNone )
  2138         if (ret == KErrNone) {
  2203             {
       
  2204             // OK, we must assume that this is the correct code, since
  2139             // OK, we must assume that this is the correct code, since
  2205             // the hashed DOS code is correct. Save the codes, and return OK.
  2140             // the hashed DOS code is correct. Save the codes, and return OK.
  2206 
  2141 
  2207             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Given code has the correct hash (%d)\
  2142             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Given code has the correct hash (%d)\
  2208                 , saving codes."), ISACode ));
  2143                 , saving codes."), ISACode ));
  2209                 
  2144 
  2210             iConfiguration.iEnhSecCode.Zero();
  2145             iConfiguration.iEnhSecCode.Zero();
  2211             iConfiguration.iEnhSecCode.Copy( hashBuf );
  2146             iConfiguration.iEnhSecCode.Copy(hashBuf);
  2212 
  2147 
  2213             iConfiguration.iSecCode.Zero();
  2148             iConfiguration.iSecCode.Zero();
  2214             iConfiguration.iSecCode.AppendNum( ISACode );
  2149             iConfiguration.iSecCode.AppendNum(ISACode);
  2215             
  2150 
  2216             // Unset the invalid configuration flag
  2151             // Unset the invalid configuration flag
  2217             iConfiguration.iConfigFlag = KSCPConfigOK;
  2152             iConfiguration.iConfigFlag = KSCPConfigOK;
  2218             writeSetup = ETrue;
  2153             writeSetup = ETrue;
  2219             }
  2154         }
  2220         else
  2155         else {
  2221             {
  2156             ret = KErrAccessDenied;
  2222 				
  2157 
  2223             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Given code does not have the \
  2158             iConfiguration.iFailedAttempts++;
  2224                 correct hash: ret; %d user enter password: %d"), ret ));
  2159             Dprint( (_L("CSCPServer::IsCorrectEnhCode():@@@: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts ));
  2225 			TRAP( ret, CheckISACodeL( aCode ) );
       
  2226 			if (ret == KErrNone)
       
  2227 			{
       
  2228 				//store this code in our interal storage as it is used as oldpassword while changing at ISA side in next command
       
  2229 				//ChangeISACodeL. 
       
  2230 				iConfiguration.iSecCode.Zero();
       
  2231 				iConfiguration.iSecCode.Append( aCode );
       
  2232 				TRAP(ret,ChangeISACodeL(pswCandidate));
       
  2233 			}
       
  2234 			if (ret == KErrNone)
       
  2235 			{
       
  2236 			iConfiguration.iEnhSecCode.Zero();
       
  2237             iConfiguration.iEnhSecCode.Copy( hashBuf );
       
  2238 
       
  2239             iConfiguration.iSecCode.Zero();
       
  2240             iConfiguration.iSecCode.AppendNum( ISACode );
       
  2241             
       
  2242             // Unset the invalid configuration flag
       
  2243             iConfiguration.iConfigFlag = KSCPConfigOK;
       
  2244             writeSetup = ETrue;
  2160             writeSetup = ETrue;
  2245 			}
  2161 
  2246             }
  2162             if (iConfiguration.iFailedAttempts == KSCPCodeBlockLimit) {
  2247         }
  2163                 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): KSCPCodeBlockLimit  ") ));
       
  2164                 // Block the code
       
  2165                 TTime curTime;
       
  2166                 curTime.UniversalTime();
       
  2167 
       
  2168                 iConfiguration.iBlockedAtTime.Zero();
       
  2169                 iConfiguration.iBlockedAtTime.AppendNum(curTime.Int64());
       
  2170 
       
  2171                 // The code will be blocked for now on
       
  2172                 ret = KSCPErrCodeBlockStarted;
       
  2173             }
       
  2174         }
       
  2175 
       
  2176     }
  2248     
  2177     
  2249     // Write setup if needed
  2178     // Write setup if needed
  2250     if ( writeSetup )
  2179     if ( writeSetup )
  2251         {
  2180         {
       
  2181         	Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 7  ") ));
  2252         TRAPD( err, iConfiguration.WriteSetupL() );
  2182         TRAPD( err, iConfiguration.WriteSetupL() );
  2253         if ( err != KErrNone )
  2183         if ( err != KErrNone )
  2254             {
  2184             {
  2255             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): WARNING:\
  2185             Dprint( (_L("CSCPServer::IsCorrectEnhCode(): WARNING:\
  2256                 failed to write configuration: %d"), err ));                                        
  2186                 failed to write configuration: %d"), err ));                                        
  2665     Dprint( (_L("[CSCPServer]-> ParamValue=%d "), aValue));
  2595     Dprint( (_L("[CSCPServer]-> ParamValue=%d "), aValue));
  2666 
  2596 
  2667     TBool lFirstTime(EFalse);
  2597     TBool lFirstTime(EFalse);
  2668     TInt32 lNumValue (-1);
  2598     TInt32 lNumValue (-1);
  2669     TInt32 lNumValDB (-1);
  2599     TInt32 lNumValDB (-1);
  2670     TInt32 lRetStatus = KErrNone;
  2600     TInt lRetStatus = KErrNone;
  2671 
  2601 
  2672     switch(aID) {
  2602     switch(aID) {
       
  2603         case RTerminalControl3rdPartySession :: ETimeout:
  2673         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2604         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2674         case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2605         case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2675         case RTerminalControl3rdPartySession :: EPasscodeMaxLength:
  2606         case RTerminalControl3rdPartySession :: EPasscodeMaxLength:
  2676         case RTerminalControl3rdPartySession :: EPasscodeRequireUpperAndLower:
  2607         case RTerminalControl3rdPartySession :: EPasscodeRequireUpperAndLower:
  2677         case RTerminalControl3rdPartySession :: EPasscodeRequireCharsAndNumbers:
  2608         case RTerminalControl3rdPartySession :: EPasscodeRequireCharsAndNumbers:
  2709         lRetStatus = aParamDB->DropValuesL(aID);
  2640         lRetStatus = aParamDB->DropValuesL(aID);
  2710     }
  2641     }
  2711     else {
  2642     else {
  2712         // Fetch the previous value of the parameter from the private database
  2643         // Fetch the previous value of the parameter from the private database
  2713         switch(aID) {
  2644         switch(aID) {
       
  2645             case RTerminalControl3rdPartySession :: ETimeout:
       
  2646                 // No need to fetch previous value for ETimeout since Stronger/Weaker check is not required for it.
       
  2647                 break;
  2714             case RTerminalControl3rdPartySession :: EMaxTimeout:
  2648             case RTerminalControl3rdPartySession :: EMaxTimeout:
  2715             case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2649             case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2716             case RTerminalControl3rdPartySession :: EPasscodeMaxLength:
  2650             case RTerminalControl3rdPartySession :: EPasscodeMaxLength:
  2717             case RTerminalControl3rdPartySession :: EPasscodeRequireUpperAndLower:
  2651             case RTerminalControl3rdPartySession :: EPasscodeRequireUpperAndLower:
  2718             case RTerminalControl3rdPartySession :: EPasscodeRequireCharsAndNumbers:
  2652             case RTerminalControl3rdPartySession :: EPasscodeRequireCharsAndNumbers:
  2777 
  2711 
  2778         lRetStatus = KErrNone;
  2712         lRetStatus = KErrNone;
  2779 
  2713 
  2780         // Decision code that verifies if policy is strongest
  2714         // Decision code that verifies if policy is strongest
  2781         switch(aID) {
  2715         switch(aID) {
       
  2716         case RTerminalControl3rdPartySession :: ETimeout:
       
  2717             /* 
       
  2718              * No need to check stronger/weaker for ETimeout. The value just has to be maintained in both
       
  2719              * DB and the CenRep
       
  2720             */
       
  2721             break;
  2782         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2722         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2783         case RTerminalControl3rdPartySession :: EPasscodeMaxRepeatedCharacters:
  2723         case RTerminalControl3rdPartySession :: EPasscodeMaxRepeatedCharacters:
  2784         case RTerminalControl3rdPartySession :: EPasscodeExpiration:
  2724         case RTerminalControl3rdPartySession :: EPasscodeExpiration:
  2785         case RTerminalControl3rdPartySession :: EPasscodeMinChangeTolerance:
  2725         case RTerminalControl3rdPartySession :: EPasscodeMinChangeTolerance:
  2786         case RTerminalControl3rdPartySession :: EPasscodeMinChangeInterval:
  2726         case RTerminalControl3rdPartySession :: EPasscodeMinChangeInterval:
  2830      * from iPluginEventHandler->GetParameters() fails.
  2770      * from iPluginEventHandler->GetParameters() fails.
  2831      * (WriteToFileL() is called in some destructor when the SCPServer terminates) 
  2771      * (WriteToFileL() is called in some destructor when the SCPServer terminates) 
  2832     */
  2772     */
  2833     if (lRetStatus == KErrNone) {
  2773     if (lRetStatus == KErrNone) {
  2834         switch (aID) {
  2774         switch (aID) {
       
  2775         case RTerminalControl3rdPartySession :: ETimeout:
       
  2776             lRetStatus = SetAutolockPeriodL(TInt(lNumValue));
       
  2777             Dprint(_L("[CSCPServer]-> After setting ETimeout lRetStatus = %d "), lRetStatus);
       
  2778             break;
       
  2779 			
  2835         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2780         case RTerminalControl3rdPartySession :: EMaxTimeout:
  2836             iConfiguration.iMaxTimeout = lNumValue;
  2781             iConfiguration.iMaxTimeout = lNumValue;
  2837             lRetStatus = iConfiguration.WriteSetupL();
  2782             lRetStatus = iConfiguration.WriteSetupL();
  2838             Dprint(_L("[CSCPServer]-> After setting EMaxTimeout lRetStatus = %d "), lRetStatus);
  2783             Dprint(_L("[CSCPServer]-> After setting EMaxTimeout lRetStatus = %d "), lRetStatus);
  2839             break;
  2784             break;
       
  2785 			
  2840         default:
  2786         default:
  2841             TUint16* ptr = const_cast<TUint16*>(aValue.Ptr());
  2787             TUint16* ptr = const_cast<TUint16*>(aValue.Ptr());
  2842             TPtr valBuf(ptr, aValue.Length(), aValue.Length());
  2788             TPtr valBuf(ptr, aValue.Length(), aValue.Length());
  2843             lRetStatus = iPluginEventHandler->GetParameters().Set(aID, valBuf);
  2789             lRetStatus = iPluginEventHandler->GetParameters().Set(aID, valBuf);
  2844             Dprint(_L("[CSCPServer]-> After setting (%d ) lRetStatus = %d "), aID, lRetStatus);
  2790             Dprint(_L("[CSCPServer]-> After setting (%d ) lRetStatus = %d "), aID, lRetStatus);
  2929                 lParamIds[lMinTolIndex] = RTerminalControl3rdPartySession :: EPasscodeHistoryBuffer;
  2875                 lParamIds[lMinTolIndex] = RTerminalControl3rdPartySession :: EPasscodeHistoryBuffer;
  2930                 Dprint(_L("[CSCPServer]-> Switching the cleanup order of EPasscodeHistoryBuffer and EPasscodeMinChangeTolerance"));
  2876                 Dprint(_L("[CSCPServer]-> Switching the cleanup order of EPasscodeHistoryBuffer and EPasscodeMinChangeTolerance"));
  2931                 Dprint(_L("[CSCPServer]-> Old Index of EPasscodeHistoryBuffer=%d"), lHistBuffIndex);
  2877                 Dprint(_L("[CSCPServer]-> Old Index of EPasscodeHistoryBuffer=%d"), lHistBuffIndex);
  2932                 Dprint(_L("[CSCPServer]-> Old Index of EPasscodeMinChangeTolerance=%d"), lMinTolIndex);
  2878                 Dprint(_L("[CSCPServer]-> Old Index of EPasscodeMinChangeTolerance=%d"), lMinTolIndex);
  2933             }
  2879             }
       
  2880 			
       
  2881             /*
       
  2882              * If both ETimeout and EMaxTimeout are marked for cleanup then interchange the cleanup order of 
       
  2883              * ETimeout and EMaxTimeout since AutoLock (ETimeout) cannot be disabled
       
  2884              * if MaxAutolock (EMaxTimeout) is still enabled
       
  2885              */
       
  2886             if( lParamIds[0] == RTerminalControl3rdPartySession :: ETimeout &&
       
  2887                 lParamIds[1] == RTerminalControl3rdPartySession :: EMaxTimeout) {
       
  2888             
       
  2889                 lParamIds[0] = RTerminalControl3rdPartySession :: EMaxTimeout;
       
  2890                 lParamIds[1] = RTerminalControl3rdPartySession :: ETimeout;
       
  2891             }
  2934        	}
  2892        	}
  2935 
  2893 
  2936         for(TInt j=0; j < lCount; j++) {
  2894         for(TInt j=0; j < lCount; j++) {
  2937             TInt lCurrParamID = lParamIds[j];            
  2895             TInt lCurrParamID = lParamIds[j];            
  2938             lDefValueBuf->Des().Zero();
  2896             lDefValueBuf->Des().Zero();
  2939             lDefValueBuf->Des().Format(_L("%d "), 0);
  2897             lDefValueBuf->Des().Format(_L("%d "), 0);
       
  2898 			
  2940             // Initialize the default values here...
  2899             // Initialize the default values here...
  2941             switch(lCurrParamID) {
  2900             switch(lCurrParamID) {
       
  2901                 case RTerminalControl3rdPartySession :: ETimeout:
       
  2902                     // lDefValueBuf already has the default value, 0 initialized...
       
  2903                     lCurrParamID = ESCPAutolockPeriod;
       
  2904                     break;
  2942                 case RTerminalControl3rdPartySession :: EMaxTimeout:
  2905                 case RTerminalControl3rdPartySession :: EMaxTimeout:
  2943                     // lDefValueBuf already has the default value, 0 initialized...
  2906                     // lDefValueBuf already has the default value, 0 initialized...
  2944                     lCurrParamID = ESCPMaxAutolockPeriod;
  2907                     lCurrParamID = ESCPMaxAutolockPeriod;
  2945                     break;
  2908                     break;
  2946                 case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2909                 case RTerminalControl3rdPartySession :: EPasscodeMinLength:
  2965                         iOverrideForCleanup = ETrue;
  2928                         iOverrideForCleanup = ETrue;
  2966                     TInt lDesCount = lDesArr.Count();
  2929                     TInt lDesCount = lDesArr.Count();
  2967                         
  2930                         
  2968                         for(TInt k=0; k < lDesCount; k++) {
  2931                         for(TInt k=0; k < lDesCount; k++) {
  2969                             TRAP(lStatus, lStatus = SetParameterValueL(lCurrParamID, lDesArr[k]->Des(), lAppID));
  2932                             TRAP(lStatus, lStatus = SetParameterValueL(lCurrParamID, lDesArr[k]->Des(), lAppID));
       
  2933 							
  2970                             if(KErrNone != lStatus) {
  2934                             if(KErrNone != lStatus) {
  2971                                 Dprint(_L("[CSCPServer]-> ERROR: Unable to cleanup parameter %d error %d"), lParamIds[j], lStatus);
  2935                                 Dprint(_L("[CSCPServer]-> ERROR: Unable to cleanup parameter %d error %d"), lParamIds[j], lStatus);
  2972                                 lSubOpsFailed = ETrue;
  2936                                 lSubOpsFailed = ETrue;
  2973                             }
  2937                             }
  2974                         }
  2938                         }
  2978                     
  2942                     
  2979                     lDesArr.ResetAndDestroy();
  2943                     lDesArr.ResetAndDestroy();
  2980                     CleanupStack :: PopAndDestroy(1); // lDesArray
  2944                     CleanupStack :: PopAndDestroy(1); // lDesArray
  2981                 }
  2945                 }
  2982                 break;
  2946                 break;
       
  2947 				
       
  2948                 case ESCPAutolockPeriod: {
       
  2949                     TInt32 lParamValueDB(0);
       
  2950                     TInt lParamValueCenRep(0);
       
  2951                     TInt32 lCurrParamOwner(0);
       
  2952 					
       
  2953                     lStatus = lParamDB->GetValueL(RTerminalControl3rdPartySession :: ETimeout, lParamValueDB, lCurrParamOwner);
       
  2954 					
       
  2955                     if(lStatus != KErrNone) {
       
  2956                         Dprint(_L("[CSCPServer]-> ERROR: Unable to get current value of ETimeout from DB..."));
       
  2957                         lSubOpsFailed = ETrue;
       
  2958                         break;
       
  2959                     }
       
  2960 					
       
  2961                     lStatus = GetAutolockPeriodL(lParamValueCenRep);
       
  2962 					
       
  2963                     if(lStatus != KErrNone) {
       
  2964                         Dprint(_L("[CSCPServer]-> ERROR: Unable to get current value of ETimeout from CenRep..."));
       
  2965                         lSubOpsFailed = ETrue;
       
  2966                         break;
       
  2967                     }
       
  2968                     
       
  2969                     /*
       
  2970                      *  It is possible that AutoLock set from UI is different. In that case internal DB and CenRep 
       
  2971                      *  are not in sync. Compare the two values and if they are same assume that the values are in sync.
       
  2972                      *  Limitation is that if the user sets the AutoLock with the same value as set by the current app then
       
  2973                      *  AutoLock will get disabled.
       
  2974                      *  
       
  2975                     */
       
  2976                     if(lParamValueCenRep != lParamValueDB) {
       
  2977                         break;
       
  2978                     }
       
  2979                 }
       
  2980 				
  2983                 default: {
  2981                 default: {
  2984                     iOverrideForCleanup = ETrue;
  2982                     iOverrideForCleanup = ETrue;
  2985                     TRAP(lStatus, lStatus = SetParameterValueL(lCurrParamID, lDefValueBuf->Des(), lAppID));
  2983                     TRAP(lStatus, lStatus = SetParameterValueL(lCurrParamID, lDefValueBuf->Des(), lAppID));
  2986                     iOverrideForCleanup = EFalse;
  2984                     iOverrideForCleanup = EFalse;
  2987     
  2985     
  2994                         
  2992                         
  2995                         // No need to destroy lTmpBuffer, it will be cleaned up by the caller (on cleanup of aParamValArray)
  2993                         // No need to destroy lTmpBuffer, it will be cleaned up by the caller (on cleanup of aParamValArray)
  2996                         aParamValArray.AppendL(lTmpBuffer);
  2994                         aParamValArray.AppendL(lTmpBuffer);
  2997                     }
  2995                     }
  2998                 }
  2996                 }
  2999             }
  2997                 break;
       
  2998             };
  3000             
  2999             
  3001             if(KErrNone != lStatus) {
  3000             if(KErrNone != lStatus) {
  3002                 Dprint(_L("[CSCPServer]-> ERROR: Unable to cleanup parameter %d error %d"), lParamIds[j], lStatus);
  3001                 Dprint(_L("[CSCPServer]-> ERROR: Unable to cleanup parameter %d error %d"), lParamIds[j], lStatus);
  3003                 lSubOpsFailed = ETrue;
  3002                 lSubOpsFailed = ETrue;
  3004             }
  3003             }