terminalsecurity/SCP/SCPServer/src/SCPSession.cpp
branchRCL_3
changeset 61 b183ec05bd8c
parent 59 13d7c31c74e0
child 62 19bba8228ff0
equal deleted inserted replaced
59:13d7c31c74e0 61:b183ec05bd8c
   108     iSettingHandler = NULL;
   108     iSettingHandler = NULL;
   109     
   109     
   110     iPendingCallStatus = NULL;
   110     iPendingCallStatus = NULL;
   111     
   111     
   112     iServer.SessionClosed();
   112     iServer.SessionClosed();
       
   113     
   113     if(iALParamValue) {
   114     if(iALParamValue) {
   114 		delete iALParamValue;		
   115 		delete iALParamValue;		
   115     }
   116     }
   116         
   117         
   117     Dprint( (_L("<-- CSCPSession::~CSCPSession()")) );   
   118     Dprint( (_L("<-- CSCPSession::~CSCPSession()")) );   
   421         Dprint( (_L("CSCPSession::HandleLockPhoneMessageL():\
   422         Dprint( (_L("CSCPSession::HandleLockPhoneMessageL():\
   422             FAILED to get stored code!") ));
   423             FAILED to get stored code!") ));
   423         User::Leave( KErrGeneral );
   424         User::Leave( KErrGeneral );
   424         }
   425         }
   425      
   426      
       
   427     
   426     // Create a timer object for this call
   428     // Create a timer object for this call
   427     iLockOperationTimer = CSCPTimer::NewL( KSCPLockOperationTimeout, NULL, this );
   429     iLockOperationTimer = CSCPTimer::NewL( KSCPLockOperationTimeout, NULL, this );
   428      
   430      
   429     // Set the state parameter for this session, a lock command is now in progress
   431     // Set the state parameter for this session, a lock command is now in progress
   430     iLockCommandState = ESCPLockCmdStateInProgress;
   432     iLockCommandState = ESCPLockCmdStateInProgress;
   570     aMessage.WriteL( 0, retpackage );
   572     aMessage.WriteL( 0, retpackage );
   571    
   573    
   572     Dprint( (_L("<-- CSCPSession::HandleGetLockStateMessageL()") ));
   574     Dprint( (_L("<-- CSCPSession::HandleGetLockStateMessageL()") ));
   573     }	
   575     }	
   574 		
   576 		
   575 		
   577 void CSCPSession :: HandleGetPoliciesL(const RMessage2 &aMessage) {
   576 		
   578     #ifdef SCP_ENFORCE_SECURITY
       
   579     // Check the access for this parameter
       
   580     if((aMessage.SecureId() != KSCPServerSIDTerminalControl) &&
       
   581        (aMessage.SecureId() != KSCPServerSIDGeneralSettings) &&
       
   582        (aMessage.SecureId() != KDevEncUiUid)) {
       
   583        
       
   584         Dprint((_L("CSCPSession::HandleSetParamMessageL(): ERROR: Permission denied")));
       
   585         User :: Leave( KErrPermissionDenied);
       
   586     }
       
   587     #endif // SCP_ENFORCE_SECURITY
       
   588     
       
   589     // Init a local buffer to store the return value
       
   590     HBufC8* lBuffer = HBufC8 :: NewLC(aMessage.GetDesMaxLength(1));
       
   591 
       
   592     iServer.GetPoliciesL(lBuffer, aMessage.SecureId().iId);
       
   593     Dprint((_L("[CSCPSession]-> iServer.GetPoliciesL complete...")));
       
   594     
       
   595     TPtr8 bufPtr = lBuffer->Des();
       
   596     // OK, send the data to the client side
       
   597     aMessage.WriteL(1, bufPtr);
       
   598     CleanupStack :: PopAndDestroy(1); // lBuffer
       
   599 }
   577 		
   600 		
   578 // ---------------------------------------------------------
   601 // ---------------------------------------------------------
   579 // void CSCPSession::HandleSetParamMessageL( const RMessage2 &aMessage )
   602 // void CSCPSession::HandleSetParamMessageL( const RMessage2 &aMessage )
   580 // Extract the parameters and send them to the server, then pack the response.
   603 // Extract the parameters and send them to the server, then pack the response.
   581 // 
   604 // 
   851 	}
   874 	}
   852     
   875     
   853     TSecureId id = aMessage.SecureId();
   876     TSecureId id = aMessage.SecureId();
   854 	
   877 	
   855     switch(id.iId) {
   878     switch(id.iId) {
       
   879         case KSCPSTIF:
   856         case KSCPServerSIDAutolock:
   880         case KSCPServerSIDAutolock:
   857         case KAknNfySrvUid:
   881         case KAknNfySrvUid:
   858         case KSCPServerSIDGeneralSettings:
   882         case KSCPServerSIDGeneralSettings:
   859         case KSCPServerSIDSysAp:
   883         case KSCPServerSIDSysAp:
   860         case KSCPServerSIDTerminalControl:
   884         case KSCPServerSIDTerminalControl:
   861         case KSCPServerSIDTelephone:
   885         case KSCPServerSIDTelephone:
   862         case KSCPServerSIDLog:
   886         case KSCPServerSIDLog:
   863             break;
   887             break;
   864         default: {
   888         default: {
   865             Dprint( (_L("[CSCPSession]-> ERROR: Permission denied") ));
   889             Dprint( (_L("[CSCPSession]-> ERROR: Permission denied") ));
   866         User::Leave( KErrPermissionDenied );
   890             User::Leave( KErrPermissionDenied );
   867         }
   891         }
   868     };
   892     };
   869 	
   893 	
   870     Dprint( (_L("--> CSCPSession::HandleAuthenticationMessage()") ));
   894     Dprint( (_L("--> CSCPSession::HandleAuthenticationMessage()") ));
   871     
   895     
   910         // Fail the call
   934         // Fail the call
   911         Dprint( (_L("<-- ERROR: CSCPSession::HandleAuthenticationMessage():\
   935         Dprint( (_L("<-- ERROR: CSCPSession::HandleAuthenticationMessage():\
   912             returning %d"), ret ));
   936             returning %d"), ret ));
   913         User::Leave( ret );            
   937         User::Leave( ret );            
   914         }
   938         }
   915         
   939     // read failed polices to msg buffer
   916     // If additional parameters are passed to client side, add them to slot 2
   940     if (addParams != NULL)
   917     if ( addParams != NULL )
   941         {
   918         {
   942         ReadFailedPoliciestoMsgBufferL(addParams,aMessage,2);
   919         HBufC8* paramBuf;
   943         }
   920         TInt pRet = addParams->GetBuffer( paramBuf );
   944         delete addParams;
   921         
       
   922         if ( pRet != KErrNone )
       
   923             {
       
   924             Dprint( (_L("WARNING: CSCPSession::HandleAuthenticationMessage():\
       
   925                 failed to get additional parameter buffer: %d"), pRet ));
       
   926             }
       
   927         else
       
   928             {
       
   929             TPtr8 paramPtr = paramBuf->Des();
       
   930             if ( aMessage.GetDesMaxLength( 2 ) >= paramPtr.Length() )
       
   931                 {
       
   932                 aMessage.Write( 2, paramPtr );    
       
   933                 }
       
   934             else
       
   935                 {
       
   936                 Dprint( (_L("WARNING: CSCPSession::HandleAuthenticationMessage():\
       
   937                     WARNING: not enough space for additional parameters") ));                
       
   938                 }                
       
   939             
       
   940             delete paramBuf;            
       
   941             }
       
   942         
       
   943         delete addParams;               
       
   944         }
       
   945                 
       
   946     // OK, we either have the correct ISA code or don't, return it to the client in slot 1
   945     // OK, we either have the correct ISA code or don't, return it to the client in slot 1
   947     User::LeaveIfError( aMessage.Write( 1, isaCodeToReturn ) );    
   946     User::LeaveIfError( aMessage.Write( 1, isaCodeToReturn ) );    
   948             
   947             
   949     Dprint( (_L("<-- CSCPSession::HandleAuthenticationMessage(): %d"), status ));    
   948     Dprint( (_L("<-- CSCPSession::HandleAuthenticationMessage(): %d"), status ));    
   950     User::LeaveIfError( status );
   949     User::LeaveIfError( status );
   957 // to the server.
   956 // to the server.
   958 //
   957 //
   959 // Status : Approved
   958 // Status : Approved
   960 // ---------------------------------------------------------
   959 // ---------------------------------------------------------
   961 //
   960 //
   962 void CSCPSession::HandleChangeEnhCodeMessageL( const RMessage2 &aMessage )
   961 void CSCPSession :: HandleChangeEnhCodeMessageL(const RMessage2 &aMessage) {
       
   962     
       
   963     Dprint(_L("[CSCPSession]-> HandleChangeEnhCodeMessage() >>>"));
       
   964     
       
   965     if(!FeatureManager :: FeatureSupported(KFeatureIdSapDeviceLockEnhancements)) {	
       
   966 		FeatureManager :: UnInitializeLib();
       
   967 		User :: Leave(KErrNotSupported);
       
   968 	}
       
   969     
       
   970     TInt oldPasswordLen = aMessage.GetDesLength(0);
       
   971     TInt newPasswordLen = aMessage.GetDesLength(1);
       
   972     
       
   973     if ((newPasswordLen == 0) || (oldPasswordLen == 0)) {
       
   974         // We cannot accept an empty code
       
   975         Dprint(_L("[CSCPSession]-> ERROR: Input buffers are empty!!"));
       
   976         User :: Leave(KErrArgument);
       
   977     }
       
   978 
       
   979     TInt lErr = KErrNone;
       
   980     HBufC* oldPassBuf = HBufC :: NewLC(oldPasswordLen);
       
   981     HBufC* newPassBuf = HBufC :: NewLC(newPasswordLen);
       
   982     
       
   983     TPtr oldPassPtr = oldPassBuf->Des();
       
   984     TPtr newPassPtr = newPassBuf->Des();
       
   985     
       
   986     // Read the strings, slot 0 = old password, slot 1 = new password  
       
   987     aMessage.ReadL(0, oldPassPtr);
       
   988     aMessage.ReadL(1, newPassPtr);
       
   989         
       
   990     // A buffer for the updated DOS password
       
   991     TSCPSecCode newDosCode;
       
   992     newDosCode.Zero();
       
   993     
       
   994     CSCPParamObject* addParams = NULL;    
       
   995     lErr = iServer.CheckAndChangeEnhCodeL(oldPassPtr, newPassPtr, addParams, newDosCode);    
       
   996     CleanupStack :: PushL(addParams);
       
   997     
       
   998     if (addParams != NULL) {
       
   999         ReadFailedPoliciestoMsgBufferL(addParams, aMessage, 2);
       
  1000     }
       
  1001     
       
  1002     CleanupStack :: PopAndDestroy(1); //addParams
       
  1003 
       
  1004     if(lErr == KErrNone) {
       
  1005         /* Get the very first character of the new lock code and set the default input mode of the
       
  1006         lock code query on the basis of the first character. */
       
  1007         ch = newPassPtr[0];
       
  1008         def_mode = ch.IsDigit() ? 0 : 1;
       
  1009     
       
  1010         CRepository* repository = CRepository :: NewLC(KCRUidSCPParameters);
       
  1011         User :: LeaveIfError(repository->Set(KSCPLockCodeDefaultInputMode, def_mode));
       
  1012         CleanupStack :: PopAndDestroy(repository);
       
  1013         
       
  1014         /* Set the value in the cenrep that the default lock code has been changed if it is not 
       
  1015          * already set
       
  1016          * */
       
  1017         repository = CRepository :: NewLC(KCRUidSCPLockCode);
       
  1018         User :: LeaveIfError(repository->Set(KSCPLockCodeDefaultLockCode, 0));
       
  1019         CleanupStack :: PopAndDestroy(repository);
       
  1020     }
       
  1021     
       
  1022     CleanupStack :: PopAndDestroy(2); //newPassBuf, oldPassBuf
       
  1023     
       
  1024     Dprint(_L("[CSCPSession]-> HandleChangeEnhCodeMessage() lErr=%d <<<"), lErr);
       
  1025     User :: LeaveIfError(lErr);
       
  1026 }   
       
  1027     
       
  1028 // ---------------------------------------------------------
       
  1029 // void CSCPSession::HandleQueryChangeMessageL()
       
  1030 // Check from the server, if the password is allowed to be changed.
       
  1031 //
       
  1032 // Status : Approved
       
  1033 // ---------------------------------------------------------
       
  1034 //
       
  1035     
       
  1036 void CSCPSession::HandleQueryChangeMessageL( const RMessage2 &aMessage )
   963     {
  1037     {
   964     
  1038     Dprint( (_L("--> CSCPSession::HandleQueryChangeMessage()") ));
   965     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
  1039     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
   966 	{	
  1040 	{	
       
  1041         Dprint( (_L("--> CSCPSession::HandleQueryChangeMessage() .. Feature not Supported !!") ));
   967 		FeatureManager::UnInitializeLib();
  1042 		FeatureManager::UnInitializeLib();
   968 		User::Leave(KErrNotSupported);
  1043 		User::Leave(KErrNotSupported);
   969 	}
  1044 	}
   970     Dprint( (_L("--> CSCPSession::HandleChangeEnhCodeMessage()") ));
       
   971     
       
   972     HBufC* oldPassBuf = NULL;
       
   973     HBufC* newPassBuf = NULL;
       
   974     
       
   975     TInt oldPasswordLen = aMessage.GetDesLength(0);
       
   976     TInt newPasswordLen = aMessage.GetDesLength(1);
       
   977     
       
   978     if ( ( newPasswordLen == 0 ) || ( oldPasswordLen == 0 ) )
       
   979         {
       
   980         // We cannot accept an empty code
       
   981         Dprint( (_L("<-- ERROR: CSCPSession::HandleChangeEnhCodeMessage():\
       
   982             returning KErrArgument, buffer empty") ));
       
   983         User::Leave( KErrArgument );      
       
   984         }
       
   985     else
       
   986         {
       
   987         oldPassBuf = HBufC::NewLC( oldPasswordLen );
       
   988         newPassBuf = HBufC::NewLC( newPasswordLen );
       
   989         }
       
   990     
       
   991     TPtr oldPassPtr = oldPassBuf->Des();
       
   992     TPtr newPassPtr = newPassBuf->Des();
       
   993     
       
   994     // Read the strings, slot 0 = old password, slot 1 = new password  
       
   995     TRAPD( err, aMessage.ReadL( 0, oldPassPtr ) );
       
   996     TRAP( err, aMessage.ReadL( 1, newPassPtr ) );
       
   997         
       
   998     // A buffer for the updated DOS password
       
   999     TSCPSecCode newDosCode;
       
  1000     newDosCode.Zero();    
       
  1001     
  1045     
  1002     CSCPParamObject* addParams = NULL;
  1046     CSCPParamObject* addParams = NULL;
  1003     if ( err != KErrNone )
       
  1004         {
       
  1005         Dprint( (_L("<-- ERROR: CSCPSession::HandleChangeEnhCodeMessage():\
       
  1006             failed to read the strings to server side: %d"), err ));        
       
  1007         }
       
  1008     else
       
  1009         {
       
  1010         err = iServer.CheckAndChangeEnhCodeL( oldPassPtr, newPassPtr, addParams, newDosCode );
       
  1011         }        
       
  1012     
       
  1013     // If additional parameters are passed to client side, add them to slot 2
       
  1014     if ( addParams != NULL )
       
  1015         {
       
  1016         HBufC8* paramBuf;
       
  1017         TInt pRet = addParams->GetBuffer( paramBuf );
       
  1018         
       
  1019         if ( pRet != KErrNone )
       
  1020             {
       
  1021             Dprint( (_L("WARNING: CSCPSession::HandleAuthenticationMessage():\
       
  1022                 failed to get additional parameter buffer: %d"), pRet ));
       
  1023             }
       
  1024         else
       
  1025             {
       
  1026             TPtr8 paramPtr = paramBuf->Des();
       
  1027             if ( aMessage.GetDesMaxLength( 2 ) >= paramPtr.Length() )
       
  1028                 {
       
  1029                 aMessage.Write( 2, paramPtr );    
       
  1030                 }
       
  1031             else
       
  1032                 {
       
  1033                 Dprint( (_L("WARNING: CSCPSession::HandleAuthenticationMessage():\
       
  1034                     WARNING: not enough space for additional parameters") ));                
       
  1035                 }                
       
  1036             
       
  1037             delete paramBuf;            
       
  1038             }
       
  1039         
       
  1040         delete addParams;               
       
  1041         }
       
  1042         
       
  1043     if ( err == KErrNone )
       
  1044         {
       
  1045         // Copy the new DOS code to slot 3
       
  1046         TInt ret = aMessage.Write( 3, newDosCode );
       
  1047         if ( ret != KErrNone )
       
  1048             {
       
  1049             Dprint( (_L("WARNING: CSCPSession::HandleAuthenticationMessage():\
       
  1050                     WARNING: failed to write the new DOS code to client-side") ));
       
  1051             }
       
  1052          else
       
  1053          	{
       
  1054          	/* Get the very first character of the new lock code and set the default input mode of the
       
  1055          	lock code query on the basis of the first character. */
       
  1056          	ch = newPassPtr[0];
       
  1057 			def_mode = ch.IsDigit() ? 0 : 1;
       
  1058 		
       
  1059 			CRepository* repository = CRepository :: NewL(KCRUidSCPParameters);			
       
  1060     		CleanupStack::PushL( repository );
       
  1061     	
       
  1062     		User::LeaveIfError(repository->Set( KSCPLockCodeDefaultInputMode , def_mode) );
       
  1063     		CleanupStack :: PopAndDestroy(repository);
       
  1064     		
       
  1065    			/* Set the value in the cenrep that the default lock code has been changed if it is not 
       
  1066              * already set
       
  1067              * */
       
  1068 			repository = CRepository :: NewL(KCRUidSCPLockCode);
       
  1069             CleanupStack :: PushL(repository);
       
  1070             User :: LeaveIfError(repository->Set(KSCPLockCodeDefaultLockCode, 0));
       
  1071     		CleanupStack::PopAndDestroy( repository );
       
  1072     		repository = NULL;    	   	
       
  1073          	}
       
  1074         }
       
  1075         
       
  1076     oldPassPtr.Zero();
       
  1077     newPassPtr.Zero();
       
  1078     CleanupStack::PopAndDestroy( newPassBuf );
       
  1079     CleanupStack::PopAndDestroy( oldPassBuf );
       
  1080     
       
  1081     Dprint( (_L("<-- CSCPSession::HandleChangeEnhCodeMessage(): %d"), err ));
       
  1082     
       
  1083     if ( err != KErrNone )
       
  1084         {
       
  1085         User::Leave( err );
       
  1086         }
       
  1087     }
       
  1088     
       
  1089     
       
  1090 // ---------------------------------------------------------
       
  1091 // void CSCPSession::HandleQueryChangeMessageL()
       
  1092 // Check from the server, if the password is allowed to be changed.
       
  1093 //
       
  1094 // Status : Approved
       
  1095 // ---------------------------------------------------------
       
  1096 //
       
  1097     
       
  1098 void CSCPSession::HandleQueryChangeMessageL( const RMessage2 &aMessage )
       
  1099     {
       
  1100     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
       
  1101 	{	
       
  1102 		FeatureManager::UnInitializeLib();
       
  1103 		User::Leave(KErrNotSupported);
       
  1104 	}
       
  1105     Dprint( (_L("--> CSCPSession::HandleQueryChangeMessage()") ));
       
  1106     
       
  1107     CSCPParamObject* addParams = NULL;
       
  1108     
  1047     
  1109     TInt ret = iServer.IsPasswordChangeAllowedL( addParams );        
  1048     TInt ret = iServer.IsPasswordChangeAllowedL( addParams );        
  1110     
  1049     if (ret != KErrNone)
  1111     // Return the reply in slot 0
  1050         {
  1112     
  1051         ReadFailedPoliciestoMsgBufferL(addParams,aMessage,0);
  1113     TPckg<TInt> retPackage(ret);
  1052         }
  1114     aMessage.WriteL(0, retPackage );
  1053     if (addParams != NULL)
  1115     
  1054         delete addParams;
  1116     // If additional parameters are passed to client side, add them to slot 1
  1055     
  1117     if ( addParams != NULL )
       
  1118         {
       
  1119         HBufC8* paramBuf;
       
  1120         TInt pRet = addParams->GetBuffer( paramBuf );
       
  1121         
       
  1122         if ( pRet != KErrNone )
       
  1123             {
       
  1124             Dprint( (_L("WARNING: CSCPSession::HandleAuthenticationMessage():\
       
  1125                 failed to get additional parameter buffer: %d"), pRet ));
       
  1126             }
       
  1127         else
       
  1128             {
       
  1129             TPtr8 paramPtr = paramBuf->Des();
       
  1130             if ( aMessage.GetDesMaxLength( 1 ) >= paramPtr.Length() )
       
  1131                 {
       
  1132                 aMessage.Write( 1, paramPtr );    
       
  1133                 }
       
  1134             else
       
  1135                 {
       
  1136                 Dprint( (_L("WARNING: CSCPSession::HandleAuthenticationMessage():\
       
  1137                     WARNING: not enough space for additional parameters") ));                
       
  1138                 }                
       
  1139             
       
  1140             delete paramBuf;            
       
  1141             }
       
  1142         
       
  1143         delete addParams;               
       
  1144         }    
       
  1145    
       
  1146     Dprint( (_L("<-- CSCPSession::HandleQueryChangeMessage()") ));    
  1056     Dprint( (_L("<-- CSCPSession::HandleQueryChangeMessage()") ));    
  1147     }
  1057     }
  1148 
  1058 
  1149     
  1059     
  1150 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
  1060 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
  1444             break; 
  1354             break; 
  1445             }
  1355             }
  1446                     
  1356                     
  1447         case ( ESCPServGetParam ):
  1357         case ( ESCPServGetParam ):
  1448             {
  1358             {
  1449             HandleGetParamMessageL( aMessage );
  1359                 if(aMessage.Int0() == -1) {
       
  1360                     HandleGetPoliciesL(aMessage);
       
  1361                 }
       
  1362                 else {
       
  1363                     HandleGetParamMessageL(aMessage);
       
  1364                 }
       
  1365                 
  1450             break; 
  1366             break; 
  1451             }
  1367             }
  1452             
  1368             
  1453         case ( ESCPServCheckConfig ):
  1369         case ( ESCPServCheckConfig ):
  1454             {
  1370             {
  1493             }
  1409             }
  1494             else
  1410             else
  1495 		    {
  1411 		    {
  1496 		    	User::Leave(KErrNotSupported);
  1412 		    	User::Leave(KErrNotSupported);
  1497 		    }
  1413 		    }
       
  1414             break;
       
  1415             }
       
  1416         case ESCPServValidateLockcode:
       
  1417             {
       
  1418             ValidateLockcodeAgainstPoliciesL(aMessage);
  1498             break;
  1419             break;
  1499             }
  1420             }
  1500             
  1421             
  1501 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS         
  1422 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS         
  1502                            		
  1423                            		
  1539         TUid id(TUid :: Uid((TInt)pluginUID));
  1460         TUid id(TUid :: Uid((TInt)pluginUID));
  1540 
  1461 
  1541         if(TUint32(id.iUid) != aCallerID) {
  1462         if(TUint32(id.iUid) != aCallerID) {
  1542             CTC3rdPartyParamsEcomIF* plugin = CTC3rdPartyParamsEcomIF :: NewL(implementation);
  1463             CTC3rdPartyParamsEcomIF* plugin = CTC3rdPartyParamsEcomIF :: NewL(implementation);
  1543             CleanupStack :: PushL(plugin);
  1464             CleanupStack :: PushL(plugin);
  1544             TRAPD(leaveCode, plugin->DeviceLockParamChangedL(aChange));
  1465             TRAP_IGNORE( plugin->DeviceLockParamChangedL(aChange));
  1545             CleanupStack :: PopAndDestroy(); // plugin 
  1466             CleanupStack :: PopAndDestroy(); // plugin 
  1546         }
  1467         }
  1547 
  1468 
  1548         CleanupStack :: PopAndDestroy(text);
  1469         CleanupStack :: PopAndDestroy(text);
  1549     }
  1470     }
  1553     Dprint(_L("[CSCPSession]-> NotifyAllStakeHoldersL() <<<"));
  1474     Dprint(_L("[CSCPSession]-> NotifyAllStakeHoldersL() <<<"));
  1554     return KErrNone;
  1475     return KErrNone;
  1555 }
  1476 }
  1556 
  1477 
  1557 TInt CSCPSession :: HandleCleanupL(const RMessage2& aMessage) {
  1478 TInt CSCPSession :: HandleCleanupL(const RMessage2& aMessage) {
  1558     Dprint((_L("[CSCPSession]-> HandleCleanupL() >>>")));
       
  1559 	
       
  1560     if( (aMessage.SecureId().iId != KSCPServerSIDTerminalControl) && 
       
  1561         (aMessage.SecureId().iId != KSCPEvntHndlrUid)) {
       
  1562 		
       
  1563         Dprint((_L("[CSCPSession]-> ERROR: caller app id=%ld. Permission denied..."), aMessage.SecureId().iId));
       
  1564         User :: Leave(KErrPermissionDenied);
       
  1565     }
       
  1566 	
       
  1567     // Copy the client data into a local buffer
  1479     // Copy the client data into a local buffer
  1568     TInt32 lCount = aMessage.GetDesLength(1);
  1480     TInt32 lCount = aMessage.GetDesLength(1);
       
  1481     
       
  1482 /*    // If the caller is not SCPEventHandler the deny access
       
  1483     if(aMessage.SecureId() != KSCPEvntHndlrUid) {
       
  1484         return KErrPermissionDenied;
       
  1485     }*/
  1569     
  1486     
  1570     // Atleast one application id has to be present in the received message (atleast 8 bytes)
  1487     // Atleast one application id has to be present in the received message (atleast 8 bytes)
  1571     if(lCount < sizeof(TInt32)) {
  1488     if(lCount < sizeof(TInt32)) {
  1572         return KErrArgument;
  1489         return KErrArgument;
  1573     }
  1490     }
  1574     
  1491     
  1575     TInt lStatus = KErrNone;
       
  1576     RArray<const TParamChange> lChangeArray;
  1492     RArray<const TParamChange> lChangeArray;
  1577     CleanupClosePushL(lChangeArray);
  1493     CleanupClosePushL(lChangeArray);
  1578     
  1494     
  1579     RPointerArray<HBufC8> lParamValArray;
  1495     RPointerArray<HBufC8> lParamValArray;
  1580     CleanupClosePushL(lParamValArray);
  1496     CleanupClosePushL(lParamValArray);
  1581     
  1497     
  1582     HBufC8* lBuffer = HBufC8 :: NewLC(lCount);
  1498     HBufC8* lBuffer = HBufC8 :: NewLC(lCount);
  1583     TPtr8 bufPtr = lBuffer->Des();
  1499     TPtr8 bufPtr = lBuffer->Des();
  1584     aMessage.ReadL(1, bufPtr);    
  1500     aMessage.ReadL(1, bufPtr);
       
  1501     
       
  1502     TInt lStatus = KErrNone;
  1585     
  1503     
  1586     TRAPD(lErr, lStatus = iServer.PerformCleanupL(lBuffer, lChangeArray, lParamValArray));
  1504     TRAPD(lErr, lStatus = iServer.PerformCleanupL(lBuffer, lChangeArray, lParamValArray));
  1587     
  1505     
  1588     if(lErr != KErrNone) {
  1506     if(lErr != KErrNone) {
  1589         Dprint(_L("[CSCPSession]-> ERROR: SCPServer was unable to complete the operation lErr=%d"), lErr);
  1507         Dprint(_L("[CSCPSession]-> ERROR: SCPServer was unable to complete the operation lErr=%d"), lErr);
  1603         }
  1521         }
  1604     }
  1522     }
  1605     
  1523     
  1606     lParamValArray.ResetAndDestroy();
  1524     lParamValArray.ResetAndDestroy();
  1607     CleanupStack :: PopAndDestroy(3); // lParamIDArray lParamValArray lBuffer    
  1525     CleanupStack :: PopAndDestroy(3); // lParamIDArray lParamValArray lBuffer    
  1608     Dprint((_L("[CSCPSession]-> HandleCleanupL() <<<")));
       
  1609     return lStatus;
  1526     return lStatus;
  1610 }
  1527 }
  1611 
  1528 
  1612 TInt CSCPSession :: HandleSetALPeriodL( const RMessage2& aMessage ) {
  1529 TInt CSCPSession :: HandleSetALPeriodL( const RMessage2& aMessage ) {
  1613     Dprint((_L("[CSCPSession]-> HandleSetParamMessageL() >>>")));
  1530     Dprint((_L("[CSCPSession]-> HandleSetParamMessageL() >>>")));
  1614     TBool oldALState = EFalse;
  1531     TBool oldALState = EFalse;
  1615     TBool lNotifyChange = ETrue;
  1532     
  1616     #ifndef __WINS__ // No need to check for lock setting changes in emulator
  1533     #ifndef __WINS__ // No need to check for lock setting changes in emulator
  1617     if ( ( (TSCPParameterID)aMessage.Int0() == ESCPAutolockPeriod ) ||
  1534     if ( ( (TSCPParameterID)aMessage.Int0() == ESCPAutolockPeriod ) ||
  1618          ( (TSCPParameterID)aMessage.Int0() == ESCPMaxAutolockPeriod ) )    
  1535          ( (TSCPParameterID)aMessage.Int0() == ESCPMaxAutolockPeriod ) )    
  1619         {
  1536         {
  1620         oldALState = IsAutolockActive();               
  1537         oldALState = IsAutolockActive();               
  1674 		CleanupStack :: PopAndDestroy(); //lChangeArray
  1591 		CleanupStack :: PopAndDestroy(); //lChangeArray
  1675 		return;
  1592 		return;
  1676 	}
  1593 	}
  1677 	
  1594 	
  1678 	Dprint(_L("[CSCPSession]->INFO: Initiating notification to all the StakeHolders..."));
  1595 	Dprint(_L("[CSCPSession]->INFO: Initiating notification to all the StakeHolders..."));
  1679 	TRAPD(lErr, NotifyAllStakeHoldersL(lChangeArray, aCallerID));
  1596 	TRAP_IGNORE( NotifyAllStakeHoldersL(lChangeArray, aCallerID));
  1680 	Dprint(_L("[CSCPSession]->INFO: Notification to all the StakeHolders complete..."));
  1597 	Dprint(_L("[CSCPSession]->INFO: Notification to all the StakeHolders complete..."));
  1681 	CleanupStack :: PopAndDestroy(); //lChangeArray
  1598 	CleanupStack :: PopAndDestroy(); //lChangeArray
  1682 }
  1599 }
       
  1600 
       
  1601 void CSCPSession :: ReadFailedPoliciestoMsgBufferL(CSCPParamObject*& aParamObject, const RMessage2& aMessage, TInt aSlotNumber) {
       
  1602     Dprint((_L("[CSCPSession]-> ReadFailedPoliciestoMsgBufferL() >>>")));
       
  1603     //get failed polices array from param object
       
  1604     const RArray<TInt>& failedPolicesArray = aParamObject->GetFailedPolices();
       
  1605     
       
  1606     // extra one for failed policies count
       
  1607     HBufC8* failedPoliciesBuf = HBufC8 :: NewLC((EDevicelockTotalPolicies+1) * sizeof(TInt32));
       
  1608     TPtr8 failedpoliciesBufPtr = failedPoliciesBuf->Des();
       
  1609     
       
  1610     RDesWriteStream writeStream(failedpoliciesBufPtr);
       
  1611     CleanupClosePushL(writeStream);
       
  1612     
       
  1613     writeStream.WriteInt32L(failedPolicesArray.Count());
       
  1614     
       
  1615     for(int count =0; count < failedPolicesArray.Count(); count++) {
       
  1616         writeStream.WriteInt32L(failedPolicesArray[count]);
       
  1617     }
       
  1618     
       
  1619     writeStream.CommitL();
       
  1620     aMessage.WriteL(aSlotNumber, failedPoliciesBuf->Des());
       
  1621     CleanupStack :: PopAndDestroy(2); //writeStream, failedPoliciesBuf
       
  1622     Dprint((_L("[CSCPSession]-> ReadFailedPoliciestoMsgBufferL() <<<")));
       
  1623 }
       
  1624 
       
  1625 void CSCPSession :: ValidateLockcodeAgainstPoliciesL(const RMessage2& aMessage) {
       
  1626     Dprint((_L("[CSCPSession]-> ValidateLockcodeAgainstPolicies() <<<")));
       
  1627     TInt lRet = KErrNone;
       
  1628     HBufC* lockcodeBuf = NULL;
       
  1629     CSCPParamObject* addParams = NULL;
       
  1630     TInt lockcodeLen = aMessage.GetDesLength(0);
       
  1631     Dprint( (_L("CSCPSession :: ValidateLockcodeAgainstPoliciesL: lockcodeLen ->%d"), lockcodeLen ));
       
  1632     if (lockcodeLen == 0) {
       
  1633         User :: Leave(KErrArgument);
       
  1634     }
       
  1635     else {
       
  1636         lockcodeBuf = HBufC :: NewLC(lockcodeLen);
       
  1637     }
       
  1638     
       
  1639     TPtr lockcodeptr = lockcodeBuf->Des();
       
  1640     TRAP( lRet, aMessage.ReadL( 0, lockcodeptr ) );
       
  1641     User :: LeaveIfError(lRet);
       
  1642     
       
  1643     lRet = iServer.ValidateLockcodeAgainstPoliciesL(lockcodeptr, addParams);
       
  1644     
       
  1645     if(addParams) {
       
  1646         CleanupStack :: PushL(addParams);
       
  1647     }
       
  1648     
       
  1649     if (lRet != KErrNone) {
       
  1650         ReadFailedPoliciestoMsgBufferL(addParams, aMessage, 1);
       
  1651     }
       
  1652     
       
  1653     if(addParams) {
       
  1654         CleanupStack :: PopAndDestroy(addParams);
       
  1655     }
       
  1656     
       
  1657     CleanupStack :: PopAndDestroy(1); // lockcodeBuf
       
  1658     Dprint((_L("[CSCPSession]-> ValidateLockcodeAgainstPolicies() <<<")));
       
  1659     User :: LeaveIfError(lRet);
       
  1660 }