terminalsecurity/SCP/SCPClient/src/SCPClient.cpp
changeset 0 b497e44ab2fc
child 1 a9c0ce913924
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2000 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Implementation of terminalsecurity components
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32svr.h>
       
    22 #include <e32math.h>
       
    23 #include <e32uid.h>
       
    24 #include <AknGlobalNote.h>
       
    25 #include <aknnotewrappers.h> 
       
    26 #include <AknQueryDialog.h>
       
    27 #include <AknGlobalConfirmationQuery.h>
       
    28 
       
    29 #include "SCPClient.h"
       
    30 #include "SCPQueryDialog.h"
       
    31 #include "SCPParamObject.h"
       
    32 
       
    33 #include <SCPNotifier.rsg>
       
    34 #include "SCP_IDs.h"
       
    35 
       
    36 #include <centralrepository.h>
       
    37 #include "SCPLockCode.h"
       
    38 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
       
    39 #include <TerminalControl3rdPartyAPI.h>
       
    40 #include <SCPServerInterface.h>
       
    41 #include <SecUi.rsg>
       
    42 #include <SecUi.hrh>
       
    43 #include <StringLoader.h>
       
    44 #include <bautils.h>
       
    45 //#endif // DEVICE_LOCK_ENHANCEMENTS
       
    46 
       
    47 #include <featmgr.h>
       
    48 #include "SCPDebug.h"
       
    49 #include <e32property.h>
       
    50 /*#ifdef _DEBUG
       
    51 #define __SCP_DEBUG
       
    52 #endif // _DEBUG
       
    53 
       
    54 // Define this so the precompiler in CW 3.1 won't complain about token pasting,
       
    55 // the warnings are not valid
       
    56 #pragma warn_illtokenpasting off
       
    57 
       
    58 #ifdef __SCP_DEBUG
       
    59 #define Dprint(a) RDebug::Print##a
       
    60 #else
       
    61 #define Dprint(a)
       
    62 #endif // _DEBUG*/
       
    63 
       
    64 static const TUint KDefaultMessageSlots = 3;
       
    65 static const TInt KSCPConnectRetries( 2 );
       
    66 
       
    67 
       
    68 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
       
    69 _LIT( KDriveZ, "Z:" );
       
    70 _LIT( KSCPResourceFilename, "\\Resource\\SCPNotifier.RSC" );
       
    71 _LIT( KSCPSecUIResourceFilename, "\\Resource\\SecUi.RSC" );
       
    72 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
       
    73 
       
    74 // Uid for the application; this should match the mmp file
       
    75 const TUid KServerUid3 = {0x10207836};
       
    76 
       
    77 #ifdef __WINS__
       
    78 static const TUint KServerMinHeapSize =  0x1000;  //  4K
       
    79 static const TUint KServerMaxHeapSize = 0x10000;  // 64K
       
    80 #endif
       
    81 
       
    82 static TInt StartServer();
       
    83 static TInt CreateServerProcess();
       
    84 
       
    85 
       
    86 // LOCAL FUNCTION PROTOTYPES
       
    87 
       
    88 // ==================== LOCAL FUNCTIONS ====================
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // StartServer() Server starter check
       
    93 // Determines if the server is running, if not, calls the starter function
       
    94 // Returns: TInt: Operation status, a standard error code
       
    95 //
       
    96 // Status : Approved
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 static TInt StartServer()
       
   100     {
       
   101     Dprint( (_L("--> SCPClient::StartServer()") ));        
       
   102         
       
   103     TInt result;
       
   104     
       
   105     TFindServer findSCPServer( KSCPServerName );
       
   106     TFullName name;
       
   107 
       
   108     result = findSCPServer.Next( name );
       
   109     if ( result != KErrNone )
       
   110         {
       
   111         // The server is not running, try to create the server process
       
   112         result = CreateServerProcess();
       
   113         } 
       
   114 
       
   115     Dprint( (_L("<-- SCPClient::StartServer(): Exit code: %d"), result ));
       
   116     return result;
       
   117     }
       
   118 
       
   119 
       
   120 // ---------------------------------------------------------
       
   121 // CreateServerProcess() Server starter function
       
   122 // Starts the SCP server
       
   123 // Returns: TInt: Operation status, a standard error code
       
   124 //
       
   125 // Status : Approved
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 static TInt CreateServerProcess()
       
   129     {
       
   130     Dprint( (_L("--> SCPClient::CreateServerProcess()") ));
       
   131     TInt result;
       
   132 
       
   133     const TUidType serverUid( KNullUid, KNullUid, KServerUid3 );
       
   134 
       
   135     RProcess server;
       
   136 
       
   137     _LIT( KEmpty, "");   
       
   138     result = server.Create( KSCPServerFileName, KEmpty );
       
   139 
       
   140     if ( result != KErrNone )
       
   141         {
       
   142         Dprint( (_L("<-- SCPClient::CreateServerProcess(), process creation error!") ));
       
   143         return result;
       
   144         }
       
   145 
       
   146     TRequestStatus stat;
       
   147    
       
   148     server.Rendezvous(stat);
       
   149   
       
   150     if ( stat != KRequestPending )
       
   151         {
       
   152         server.Kill(0);    // abort startup
       
   153         }    
       
   154     else
       
   155         {
       
   156         server.Resume(); // logon OK - start the server
       
   157         }
       
   158     
       
   159     User::WaitForRequest(stat); // wait for start or death
       
   160   
       
   161     // we can't use the 'exit reason' if the server panicked as this
       
   162     // is the panic 'reason' and may be '0' which cannot be distinguished
       
   163     // from KErrNone
       
   164     result = ( server.ExitType() == EExitPanic ) ? KErrGeneral : stat.Int();
       
   165   
       
   166     server.Close();
       
   167 
       
   168     Dprint( (_L("<-- SCPClient::CreateServerProcess(): %d"), result ));
       
   169     return result;
       
   170     }
       
   171 
       
   172 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
       
   173 
       
   174 // ---------------------------------------------------------
       
   175 // RunDialog() Dialog execution wrapper
       
   176 // Initialize and run the query dialog
       
   177 // Returns: TInt: The return code from the dialog.
       
   178 //          Can leave with a generic error code.
       
   179 //
       
   180 // Status : Approved
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 TInt RunDialogL( TDes& aReplyBuf,
       
   184                 RSCPClient::TSCPButtonConfig aButtonsShown,
       
   185                 TInt aMinLen,
       
   186                 TInt aMaxLen,
       
   187                 TUint aResId = 0,
       
   188                 TDesC* aPrompt = NULL,
       
   189                 TBool aECSSupport = EFalse         
       
   190               )
       
   191     {
       
   192     Dprint(_L("[RSCPClient]-> RunDialogL() >>> "));
       
   193     FeatureManager::InitializeLibL();
       
   194     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
       
   195 	{
       
   196 			FeatureManager::UnInitializeLib();
       
   197 		return KErrNotSupported;
       
   198 	}
       
   199 		FeatureManager::UnInitializeLib();
       
   200     if ( ( aPrompt == NULL ) && ( aResId == 0 ) )
       
   201         {
       
   202         return KErrArgument;
       
   203         }
       
   204     Dprint((_L("--> SCPClient::RunDialogL() start the dialog")));    
       
   205     CSCPQueryDialog* dialog = new (ELeave) CSCPQueryDialog( 
       
   206         aReplyBuf,
       
   207         aButtonsShown,
       
   208         aMinLen,
       
   209         aMaxLen,
       
   210         aECSSupport
       
   211         ); 
       
   212         
       
   213     CleanupStack::PushL( dialog );            
       
   214     
       
   215     if ( aResId != 0 )
       
   216         {
       
   217         // Load and set the prompt from a resource ID
       
   218         HBufC* prompt;
       
   219         
       
   220         prompt = StringLoader::LoadLC( aResId );   
       
   221         dialog->SetPromptL( *prompt ); 
       
   222         
       
   223         CleanupStack::PopAndDestroy( prompt );       
       
   224         }
       
   225     else
       
   226         {
       
   227         // Set the given prompt
       
   228         dialog->SetPromptL( *aPrompt );
       
   229         }        
       
   230     Dprint((_L("-- SCPClient::RunDialogL() dialog->ExecuteLD")));
       
   231     TInt ret = dialog->ExecuteLD( R_SCP_CODE_QUERY );
       
   232     
       
   233     CleanupStack::Pop( dialog );
       
   234     Dprint( (_L("-- SCPClient::RunDialogL(): ret val %d"), ret));
       
   235     return ret;
       
   236     }
       
   237     
       
   238 
       
   239 // ---------------------------------------------------------
       
   240 // LoadResources() Resource loader
       
   241 // Load the resources for the library
       
   242 // Returns: TInt: A generic error code.
       
   243 //
       
   244 // Status : Approved
       
   245 // ---------------------------------------------------------
       
   246 //
       
   247 TInt LoadResources( TInt& aRes1, TInt& aRes2 )
       
   248     {
       
   249     
       
   250    TRAPD ( err, FeatureManager::InitializeLibL() );   
       
   251    if ( err == KErrNone )
       
   252    {
       
   253     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
       
   254 	{
       
   255 			FeatureManager::UnInitializeLib();
       
   256 		return KErrNotSupported;
       
   257 	}
       
   258 		FeatureManager::UnInitializeLib();
       
   259     // Load the resource files for this DLL
       
   260     TInt err = KErrNone;
       
   261     TInt err2 = KErrNone;
       
   262        
       
   263     // Localize the file name, and load the SCP resources
       
   264     TFileName resFile;
       
   265     resFile.Copy( KDriveZ );
       
   266     resFile.Append( KSCPResourceFilename );
       
   267     BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resFile );    
       
   268     TRAP( err, aRes1 = CCoeEnv::Static()->AddResourceFileL( resFile ) );
       
   269     
       
   270     if ( err == KErrNone )
       
   271         {
       
   272         // Localize the file name, and load the SecUi resources
       
   273         resFile.Copy( KDriveZ );
       
   274         resFile.Append( KSCPSecUIResourceFilename );
       
   275         BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resFile );
       
   276         TRAP( err2, aRes2 = CCoeEnv::Static()->AddResourceFileL( resFile ) );
       
   277         }   
       
   278              
       
   279     if ( ( err != KErrNone ) || ( err2 != KErrNone ) )
       
   280         {        
       
   281         if ( err == KErrNone )             
       
   282             {
       
   283             // First resource was loaded OK, remove it
       
   284             CCoeEnv::Static()->DeleteResourceFile( aRes1 );
       
   285             err = err2;
       
   286             }
       
   287         } 
       
   288     }        
       
   289     return err;           
       
   290     }     
       
   291 
       
   292 //#endif //  __SAP_DEVICE_LOCK_ENHANCEMENTS
       
   293 
       
   294 // ================= MEMBER FUNCTIONS =======================
       
   295 
       
   296 // C++ default constructor can NOT contain any code, that
       
   297 // might leave.
       
   298 //
       
   299 EXPORT_C RSCPClient::RSCPClient()
       
   300 :   RSessionBase()
       
   301     {
       
   302     // No implementation required
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------
       
   306 // TInt RSCPClient::Connect()
       
   307 // Creates a new session, and starts the server, if required.
       
   308 // 
       
   309 // Status : Approved
       
   310 // ---------------------------------------------------------
       
   311 //
       
   312 EXPORT_C TInt RSCPClient::Connect()
       
   313     {
       
   314     Dprint( (_L("--> RSCPClient::Connect()") ));
       
   315     
       
   316     // Use a mutex-object so that two processes cannot start the server at the same time
       
   317     RMutex startMutex;
       
   318     
       
   319     TRAPD( errf, FeatureManager::InitializeLibL() );
       
   320 	if( errf != KErrNone )
       
   321 		{
       
   322 		return errf;
       
   323 		}
       
   324 		if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
       
   325 		{
       
   326 			isFlagEnabled = ETrue;
       
   327 		}
       
   328 		else
       
   329 		{
       
   330 			isFlagEnabled = EFalse;
       
   331 		}
       
   332 		FeatureManager::UnInitializeLib();
       
   333     TInt mRet = startMutex.OpenGlobal( KSCPServerName );
       
   334     if ( mRet == KErrNotFound )
       
   335         {
       
   336         mRet = startMutex.CreateGlobal( KSCPServerName );
       
   337         }
       
   338         
       
   339     if ( mRet != KErrNone )
       
   340         {        
       
   341         return mRet;
       
   342         }
       
   343     
       
   344     // Acquire the mutex
       
   345     startMutex.Wait();
       
   346     
       
   347     TInt retry = KSCPConnectRetries;
       
   348     TInt r;
       
   349     for (;;)
       
   350         {        
       
   351         r = CreateSession( KSCPServerName, Version(), KDefaultMessageSlots );
       
   352         
       
   353         if ( ( r != KErrNotFound ) && ( r != KErrServerTerminated  ) )
       
   354             {
       
   355             break;
       
   356             }
       
   357         
       
   358         if ( --retry == 0 )
       
   359             {
       
   360             break;
       
   361             }
       
   362       
       
   363         r = StartServer();
       
   364         
       
   365         if ( ( r != KErrNone ) && ( r != KErrAlreadyExists ) )
       
   366             {
       
   367             break;   
       
   368             }
       
   369         }
       
   370     
       
   371     Dprint( (_L("<-- RSCPClient::Connect(), exiting: %d"), r ));
       
   372     
       
   373     // Release the mutex
       
   374     startMutex.Signal();
       
   375     startMutex.Close();
       
   376 
       
   377     return r;
       
   378     }
       
   379 
       
   380 
       
   381 // ---------------------------------------------------------
       
   382 // TVersion RSCPClient::Version()
       
   383 // Constructs a TVersion object containing the defined version
       
   384 // numbers, and returns it
       
   385 // 
       
   386 // Status : Approved
       
   387 // ---------------------------------------------------------
       
   388 //
       
   389 EXPORT_C TVersion RSCPClient::Version() const
       
   390     {
       
   391     Dprint( (_L("<--> RSCPClient::Version()") ));
       
   392     return( TVersion( KSCPServMajorVersionNumber,
       
   393                       KSCPServMinorVersionNumber,
       
   394                       KSCPServBuildVersionNumber ) );
       
   395     }
       
   396 
       
   397 
       
   398 // ---------------------------------------------------------
       
   399 // TInt RSCPClient::GetCode( TSCPSecCode& aCode )
       
   400 // Requests the stored ISA code.
       
   401 // 
       
   402 // Status : Approved
       
   403 // ---------------------------------------------------------
       
   404 //
       
   405 EXPORT_C TInt RSCPClient::GetCode( TSCPSecCode& aCode )
       
   406     {
       
   407     Dprint( (_L("--> RSCPClient::GetCode()") ));
       
   408         
       
   409     TInt ret = SendReceive(ESCPServGetCode, TIpcArgs( &aCode ) );
       
   410   
       
   411     Dprint( (_L("<-- RSCPClient::GetCode(): %d"), ret ));
       
   412     return ret;
       
   413     }
       
   414         
       
   415    
       
   416 // ---------------------------------------------------------
       
   417 // TInt RSCPClient::StoreCode( TSCPSecCode& aCode )
       
   418 // Propagates the store code -request to the server along
       
   419 // with the buffer parameter.
       
   420 // 
       
   421 // Status : Approved
       
   422 // ---------------------------------------------------------
       
   423 //
       
   424 EXPORT_C TInt RSCPClient::StoreCode( TSCPSecCode& aCode )
       
   425     {
       
   426     Dprint( (_L("--> RSCPClient::StoreCode()") ));
       
   427         
       
   428     TInt ret = SendReceive(ESCPServSetCode, TIpcArgs( &aCode ) );
       
   429   
       
   430     Dprint( (_L("<-- RSCPClient::StoreCode(): %d"), ret ));
       
   431     return ret;
       
   432     }   
       
   433 
       
   434 
       
   435 
       
   436 // ---------------------------------------------------------
       
   437 // TInt RSCPClient::ChangeCode( TDes& aNewCode )
       
   438 // Propagates the change code -request to the server, along with
       
   439 // the code parameter.
       
   440 // 
       
   441 // Status : Approved
       
   442 // ---------------------------------------------------------
       
   443 //
       
   444 EXPORT_C TInt RSCPClient::ChangeCode( TDes& aNewCode )
       
   445     {
       
   446     Dprint( (_L("--> RSCPClient::ChangeCode()") ));
       
   447         
       
   448     TInt ret = SendReceive(ESCPServChangeCode, TIpcArgs( &aNewCode ) );
       
   449   
       
   450     Dprint( (_L("<-- RSCPClient::ChangeCode(): %d"), ret ));  
       
   451     return ret;
       
   452     }   
       
   453 
       
   454 // ---------------------------------------------------------
       
   455 // TInt RSCPClient::SetPhoneLock()
       
   456 // Propagates the lock/unlock phone -request to the server
       
   457 // 
       
   458 // Status : Approved
       
   459 // ---------------------------------------------------------
       
   460 //
       
   461 EXPORT_C TInt RSCPClient::SetPhoneLock( TBool aLocked )
       
   462     {
       
   463     Dprint( (_L("--> RSCPClient::SetPhoneLock( %d)"), aLocked ));
       
   464             
       
   465     TInt ret = SendReceive(ESCPServSetPhoneLock, TIpcArgs( aLocked ) );
       
   466   
       
   467     Dprint( (_L("<-- RSCPClient::SetPhoneLock(): %d"), ret ));
       
   468     return ret;
       
   469     }   
       
   470 
       
   471 // ---------------------------------------------------------
       
   472 // TBool RSCPClient::QueryAdminCmd( TSCPAdminCommand aCommand )
       
   473 // Packs the command parameter into a buffer, and propagates
       
   474 // the call to the server, the response is received in the
       
   475 // same buffer.
       
   476 // 
       
   477 // Status : Approved
       
   478 // ---------------------------------------------------------
       
   479 //
       
   480 EXPORT_C TBool RSCPClient::QueryAdminCmd( TSCPAdminCommand aCommand )
       
   481     {
       
   482     Dprint( (_L("--> RSCPClient::QueryAdminCmd()") ));
       
   483         
       
   484     TInt status = 0;
       
   485   
       
   486     TPckg<TInt> retPackage(status);
       
   487     
       
   488     TInt ret = SendReceive( ESCPServQueryAdminCmd, TIpcArgs( aCommand, &retPackage ) );
       
   489    
       
   490     Dprint( (_L("<-- RSCPClient::QueryAdminCmd(): %d"), retPackage() ));
       
   491     return static_cast<TBool>( status );
       
   492     }   
       
   493         
       
   494 // ---------------------------------------------------------
       
   495 // TInt RSCPClient::GetLockState( TBool& aState )
       
   496 // Package the parameter, and send it to the server.
       
   497 // 
       
   498 // Status : Approved
       
   499 // ---------------------------------------------------------
       
   500 //
       
   501 EXPORT_C TInt RSCPClient::GetLockState( TBool& aState )
       
   502     {
       
   503     Dprint( (_L("--> RSCPClient::GetLockState()") )); 
       
   504       
       
   505     TPckg<TBool> retPackage(aState);
       
   506     
       
   507     TInt ret = SendReceive( ESCPServGetLockState, TIpcArgs( &retPackage ) );
       
   508      
       
   509     Dprint( (_L("<-- RSCPClient::GetLockState(): %d"), retPackage() ));
       
   510     return ret;            
       
   511     }
       
   512   
       
   513   
       
   514 // ---------------------------------------------------------
       
   515 // TInt RSCPClient::GetParamValue( TInt aParamID, TDes& aValue )
       
   516 // The server contains all the logic for the parameters, just 
       
   517 // propagate the call.
       
   518 // 
       
   519 // Status : Approved
       
   520 // ---------------------------------------------------------
       
   521 //
       
   522 EXPORT_C TInt RSCPClient::GetParamValue( TInt aParamID, TDes& aValue )
       
   523     {
       
   524     Dprint( (_L("--> RSCPClient::GetParamValue()") ));  
       
   525     
       
   526     TInt ret = SendReceive( ESCPServGetParam, TIpcArgs( aParamID, &aValue ) );
       
   527      
       
   528     Dprint( (_L("<-- RSCPClient::GetParamValue(): %d"), ret));
       
   529     return ret;            
       
   530     }
       
   531     
       
   532 // ---------------------------------------------------------
       
   533 // TInt RSCPClient::SetParamValue( TInt aParamID, TDes& aValue )
       
   534 // The server contains all the logic for the parameters, just 
       
   535 // propagate the call.
       
   536 // 
       
   537 // Status : Approved
       
   538 // ---------------------------------------------------------
       
   539 //
       
   540 EXPORT_C TInt RSCPClient::SetParamValue( TInt aParamID, TDes& aValue )
       
   541     {
       
   542     Dprint( (_L("--> RSCPClient::SetParamValue()") ));  
       
   543     
       
   544     TInt ret = SendReceive( ESCPServSetParam, TIpcArgs( aParamID, &aValue ) );
       
   545      
       
   546     Dprint( (_L("<-- RSCPClient::SetParamValue(): %d"), ret ));
       
   547     return ret;            
       
   548     }    
       
   549     
       
   550 
       
   551 // *********** Device lock new features ************* -->>
       
   552 
       
   553 // ---------------------------------------------------------
       
   554 // RSCPClient::SecCodeQuery()
       
   555 // Request the security code from the user and authenticate
       
   556 // through the server.
       
   557 // 
       
   558 // Status : Approved
       
   559 // ---------------------------------------------------------
       
   560 //
       
   561 EXPORT_C TInt RSCPClient::SecCodeQuery( RMobilePhone::TMobilePassword& aPassword, 
       
   562                                         TSCPButtonConfig aButtonsShown, 
       
   563                                         TBool aECSSupport,
       
   564                                         TInt aFlags )
       
   565     {
       
   566     TInt lErr = KErrNone;
       
   567     TInt lStatus = KErrNone;
       
   568     TInt lResFileSCP = NULL;
       
   569     TInt lResFileSecUi = NULL;
       
   570     Dprint( (_L("--> RSCPClient::SecCodeQuery(%d, %d"), aButtonsShown, aECSSupport ));  
       
   571     TRAP(lErr, lStatus = SetSecurityCodeL(aPassword, aButtonsShown, aECSSupport, aFlags, lResFileSCP, lResFileSecUi));    
       
   572    
       
   573     
       
   574     if(lResFileSCP) {
       
   575         CCoeEnv :: Static()->DeleteResourceFile(lResFileSCP);
       
   576 	}
       
   577     
       
   578     if(lResFileSecUi) {
       
   579     
       
   580     
       
   581         CCoeEnv :: Static()->DeleteResourceFile(lResFileSecUi);
       
   582     }
       
   583     
       
   584     Dprint((_L("<-- RSCPClient::SecCodeQuery(): lStatus= %d, lErr= %d"), lStatus, lErr));
       
   585     return (lErr != KErrNone) ? lErr : lStatus;
       
   586 }
       
   587 
       
   588 // ---------------------------------------------------------
       
   589 // RSCPClient::ChangeCodeRequest()
       
   590 // Show the current code query dialog and continue in GetNew
       
   591 // CodeAndChange.
       
   592 // 
       
   593 // Status : Approved
       
   594 // ---------------------------------------------------------
       
   595 //
       
   596 EXPORT_C TInt RSCPClient::ChangeCodeRequest()
       
   597     {
       
   598     Dprint((_L("[RSCPClient] ChangeCodeRequest() >>>")));
       
   599     
       
   600     if(EFalse == isFlagEnabled) {
       
   601         Dprint((_L("[RSCPClient]-> ChangeCodeRequest(): ERROR: Function not supported in this variant")));
       
   602         User :: Invariant();
       
   603         return KErrNotSupported;
       
   604 	}
       
   605 
       
   606     TInt lRet(KErrNone);
       
   607     TInt lErr(KErrNone);
       
   608 
       
   609     TInt resourceFileSCP(NULL);
       
   610     TInt resourceFileSecUi(NULL);
       
   611 
       
   612     // Check if the code change is allowed
       
   613     {
       
   614         HBufC8* addParamsHBuf = NULL;
       
   615         TRAP(lErr, addParamsHBuf = HBufC8 :: NewL(KSCPMaxTARMNotifParamLen));
       
   616         
       
   617         if(lErr != KErrNone) {
       
   618             return lErr;
       
   619         }
       
   620 
       
   621         TPtr8 addParams = addParamsHBuf->Des();
       
   622         addParams.Zero();
       
   623 
       
   624         TInt status(KErrNone);
       
   625         TPckg<TInt> retPackage(status);
       
   626         
       
   627         TInt ret = SendReceive(ESCPServCodeChangeQuery, TIpcArgs(&retPackage, &addParams));
       
   628 
       
   629         if((ret == KErrNone) && (addParams.Length() > 0)) {
       
   630             // The server has sent additional parameters, ignore errors in processing
       
   631             TRAP_IGNORE(ProcessServerCommandsL(addParams));
       
   632         }
       
   633 
       
   634         delete addParamsHBuf;
       
   635 
       
   636         if((ret != KErrNone) || (status != KErrNone)) {
       
   637             // Password cannot be changed now
       
   638             return KErrAbort;
       
   639         }
       
   640     }
       
   641 
       
   642     // Load the required resource files into this process
       
   643     lRet = LoadResources(resourceFileSCP, resourceFileSecUi);
       
   644     
       
   645     if(lRet != KErrNone) {
       
   646         return lRet;
       
   647     }
       
   648 
       
   649     HBufC* codeHBuf = NULL;
       
   650     
       
   651     TRAP(lErr, codeHBuf = HBufC :: NewL(KSCPPasscodeMaxLength + 1));
       
   652     
       
   653     if(lErr != KErrNone) {
       
   654         // Remove the resource files
       
   655         CCoeEnv :: Static()->DeleteResourceFile(resourceFileSCP);
       
   656         CCoeEnv :: Static()->DeleteResourceFile(resourceFileSecUi);
       
   657         return lErr;
       
   658     }
       
   659 
       
   660     TPtr codeBuffer = codeHBuf->Des();
       
   661     codeBuffer.Zero();
       
   662 
       
   663     TInt def_code = -1;
       
   664     CRepository* lRepository = NULL;
       
   665     
       
   666     TRAP(lErr, lRepository = CRepository :: NewL(KCRUidSCPLockCode));
       
   667     
       
   668     if(KErrNone == lErr) {
       
   669         lErr = lRepository->Get(KSCPLockCodeDefaultLockCode, def_code);
       
   670        
       
   671         if(def_code == 0) {
       
   672             TRAP(lErr, lRet = RunDialogL(codeBuffer, SCP_OK_CANCEL, KSCPPasscodeMinLength,
       
   673                                      KSCPPasscodeMaxLength, R_SECUI_TEXT_ENTER_SEC_CODE));
       
   674     
       
   675             if((lRet) && (lErr == KErrNone) && (lRet != ESecUiEmergencyCall)) {
       
   676                 lErr = GetNewCodeAndChange(codeBuffer, KSCPNormalChange);
       
   677             }
       
   678     
       
   679             if(lErr != KErrNone) {
       
   680                 Dprint((_L("RSCPClient::ChangeCodeRequest(): Code change FAILED: %d"), lErr));
       
   681             }
       
   682     
       
   683             if(((!lRet) && (lErr == KErrNone)) || (lRet == ESecUiEmergencyCall)) {
       
   684                 // Cancelled by user
       
   685                 lErr = KErrAbort;
       
   686             }
       
   687         }
       
   688         else if(def_code != -1) {
       
   689             _LIT(KText, "12345");
       
   690             TBufC<10> NBuf (KText);
       
   691             TPtr codeBuf = NBuf.Des();
       
   692             
       
   693             lErr = GetNewCodeAndChange(codeBuf, KSCPNormalChange);
       
   694             
       
   695             if(lErr == KErrNone) {
       
   696                 lRepository->Set(KSCPLockCodeDefaultLockCode, 0);
       
   697             }
       
   698             else {
       
   699                 Dprint((_L("RSCPClient::ChangeCodeRequest(): Code change FAILED automatic: %d"), lErr));
       
   700             }
       
   701         }
       
   702         
       
   703         delete lRepository;
       
   704     }
       
   705     
       
   706     Dprint((_L("<-- RSCPClient::ChangeCodeRequest(): %d"), lErr ));
       
   707     
       
   708     // Remove the resource files
       
   709     CCoeEnv :: Static()->DeleteResourceFile(resourceFileSCP);
       
   710     CCoeEnv :: Static()->DeleteResourceFile(resourceFileSecUi);    
       
   711     delete codeHBuf;
       
   712     return lErr;
       
   713 }
       
   714 
       
   715 // ---------------------------------------------------------
       
   716 // RSCPClient::CheckConfiguration()
       
   717 // Ask the server if the configuration is OK
       
   718 // 
       
   719 // Status : Approved
       
   720 // ---------------------------------------------------------
       
   721 //
       
   722 
       
   723 EXPORT_C TInt RSCPClient::CheckConfiguration( TInt aMode )
       
   724     {
       
   725     Dprint( (_L("--> RSCPClient::CheckConfiguration()") ));
       
   726     
       
   727     TInt status = 0;
       
   728   
       
   729     TPckg<TInt> retPackage(status);    
       
   730     
       
   731     TInt ret = SendReceive(ESCPServCheckConfig, TIpcArgs( aMode, &retPackage ) );
       
   732     
       
   733     if ( ret == KErrNone )
       
   734         {
       
   735         ret = status;
       
   736         
       
   737         if ( status == KErrNone )
       
   738             {
       
   739             Dprint( (_L("RSCPClient::CheckConfiguration(): Configuration OK") ));
       
   740             }
       
   741         else if ( status == KErrAccessDenied )
       
   742             {
       
   743             if ( aMode == KSCPInitial )
       
   744                 {
       
   745                 Dprint( (_L("RSCPClient::CheckConfiguration(): Initial check failed") ));
       
   746                 }
       
   747             else
       
   748                 {
       
   749                 Dprint( (_L("RSCPClient::CheckConfiguration(): WARNING:\
       
   750                    Configuration Out of sync") ));
       
   751                 }            
       
   752             }
       
   753         }                
       
   754   
       
   755     Dprint( (_L("<-- RSCPClient::CheckConfiguration(): %d"), status ));
       
   756     
       
   757     return ret;
       
   758     }
       
   759 EXPORT_C TInt RSCPClient :: PerformCleanupL(RArray<TUid>& aAppIDs) {
       
   760     TInt lCount = aAppIDs.Count();
       
   761     
       
   762     if(lCount < 1) {
       
   763         return KErrNone; 
       
   764     }
       
   765         
       
   766     HBufC8* lBuff = HBufC8 :: NewLC(lCount * sizeof(TInt32));
       
   767     TPtr8 lBufPtr = lBuff->Des();
       
   768     RDesWriteStream lWriteStream(lBufPtr);
       
   769     CleanupClosePushL(lWriteStream);
       
   770     
       
   771     for(TInt i=0; i < lCount; i++) {
       
   772         Dprint((_L("[RSCPClient]-> Marking %d for cleanup"), aAppIDs[i].iUid ));
       
   773         lWriteStream.WriteInt32L(aAppIDs[i].iUid);
       
   774     }
       
   775     lWriteStream.CommitL();
       
   776     TInt lStatus = SendReceive(ESCPApplicationUninstalled, TIpcArgs(ESCPApplicationUninstalled, &lBuff->Des()));
       
   777     CleanupStack :: PopAndDestroy(2); // lBuff, lWriteStream
       
   778     return lStatus;
       
   779 }
       
   780 // ---------------------------------------------------------
       
   781 // The server contains all the logic for the parameters, just
       
   782 // propagate the call.
       
   783 //
       
   784 // ---------------------------------------------------------
       
   785 //
       
   786 EXPORT_C TInt RSCPClient :: SetParamValue(TInt aParamID, TDes& aValue, TUint32 aCallerSID) {
       
   787     Dprint((_L("RSCPClient::SetParamValue() >>>")));
       
   788     TPckgBuf<TUint32> lCallerID(aCallerSID);
       
   789     TInt ret = SendReceive(ESCPServSetParam, TIpcArgs(aParamID, &aValue, &lCallerID));
       
   790     Dprint((_L("RSCPClient::SetParamValue(): %d <<<"), ret));
       
   791     return ret;
       
   792 }
       
   793 
       
   794 /* ---------------------------------------------------------
       
   795  * Alternative function that can be used to set the Auto Lock period
       
   796  * Caller should have AllFiles access level
       
   797  * Primarily called from the general settings components
       
   798 // ---------------------------------------------------------
       
   799 */
       
   800 EXPORT_C TInt RSCPClient :: SetAutoLockPeriod( TInt aValue ) {
       
   801     Dprint((_L("[RSCPClient]-> SetAutoLockPeriod() >>>")));
       
   802     TPckgBuf<TInt> lAutoLockPeriod(aValue);
       
   803     TInt ret = SendReceive(ESCPServUISetAutoLock, TIpcArgs(&lAutoLockPeriod));
       
   804     Dprint((_L("[RSCPClient]-> SetAutoLockPeriod(): %d <<<"), ret));
       
   805     return ret;
       
   806 }
       
   807 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
       
   808 
       
   809 // ---------------------------------------------------------
       
   810 // RSCPClient::GetNewCodeAndChange()
       
   811 // Show the new code request and verification dialogs and
       
   812 // send the change request to the server.
       
   813 // 
       
   814 // Status : Approved
       
   815 // ---------------------------------------------------------
       
   816 //  
       
   817 TInt RSCPClient::GetNewCodeAndChange( TDes& aOldCode, 
       
   818                                       TInt aMode,
       
   819                                       TSCPSecCode* aNewDOSCode /*=NULL*/, 
       
   820                                       HBufC** aNewCodePptr/* = NULL*/)
       
   821     {
       
   822     
       
   823     
       
   824     if(!isFlagEnabled)
       
   825 	{
       
   826 		return KErrNotSupported;
       
   827 	}
       
   828     TInt err = KErrNone;
       
   829     TInt ret = KErrNone;            
       
   830     
       
   831             
       
   832     TInt maxLen = KSCPPasscodeMaxLength;
       
   833     TInt minLen = 1;
       
   834         
       
   835     // Fetch the minimum and maximum lengths for the code, if available.
       
   836     // This feature is commented out for correction to BU error ID: BNIN-6LC3AP.
       
   837     // Left in the code for possible inclusion in the future.
       
   838     //FetchLimits( minLen, maxLen );        
       
   839         
       
   840     // Request the new code and verify it. Repeat this until the codes match.
       
   841     
       
   842     // Create the buffers on the heap
       
   843     HBufC* newCodeHBuf = NULL;
       
   844     HBufC* verifyCodeHBuf = NULL;
       
   845     
       
   846     TRAP( err, newCodeHBuf = HBufC::NewL( KSCPPasscodeMaxLength + 1 ) );
       
   847     if ( err == KErrNone )
       
   848         {
       
   849         TRAP( err, verifyCodeHBuf = HBufC::NewL( KSCPPasscodeMaxLength + 1 ) );
       
   850         }
       
   851     
       
   852     if ( err != KErrNone )
       
   853         {
       
   854         if ( newCodeHBuf != NULL )
       
   855             {
       
   856             delete newCodeHBuf;
       
   857             }
       
   858         return err; 
       
   859         }    
       
   860         
       
   861     TPtr newCodeBuffer = newCodeHBuf->Des();
       
   862     TPtr verifyCodeBuffer = verifyCodeHBuf->Des();  
       
   863     
       
   864     // Configure the buttons according to the mode
       
   865     TSCPButtonConfig bConfig;
       
   866     TBool ecSupport;
       
   867     if ( aMode == KSCPForcedChange )
       
   868         {
       
   869         bConfig = SCP_OK_ETEL;
       
   870         ecSupport = ETrue;
       
   871         }
       
   872     else
       
   873         {
       
   874         bConfig = SCP_OK_CANCEL;
       
   875         ecSupport = EFalse;
       
   876         }
       
   877     
       
   878     TBool isMismatch = EFalse;
       
   879     do // Repeat loop BEGIN
       
   880         {
       
   881         isMismatch = EFalse;
       
   882                 
       
   883         if ( err == KErrSCPInvalidCode )
       
   884             {
       
   885             err = KErrNone; // "reset"
       
   886             }
       
   887                           
       
   888         newCodeBuffer.Zero(); 
       
   889         
       
   890         TRAP( err, ret = RunDialogL( newCodeBuffer, 
       
   891                                  bConfig, 
       
   892                                  minLen,
       
   893                                  maxLen,
       
   894                                  R_SECUI_TEXT_ENTER_NEW_SEC_CODE,
       
   895                                  NULL,
       
   896                                  ecSupport ) );
       
   897     
       
   898         if ( ( ret ) && ( ret != ESecUiEmergencyCall ) && ( err == KErrNone ) )
       
   899             {        
       
   900             verifyCodeBuffer.Zero();
       
   901             
       
   902             TRAP( err, ret = RunDialogL( verifyCodeBuffer, 
       
   903                                  bConfig, 
       
   904                                  minLen,
       
   905                                  maxLen,
       
   906                                  R_SECUI_TEXT_VERIFY_NEW_SEC_CODE,
       
   907                                  NULL,
       
   908                                  ecSupport ) );                             
       
   909             }
       
   910 
       
   911         if ( ( !ret ) || ( err != KErrNone ) || ( ret == ESecUiEmergencyCall ) )
       
   912             {
       
   913             break;
       
   914             }            
       
   915             
       
   916         if  ( verifyCodeBuffer.Compare( newCodeBuffer ) != 0 )
       
   917             {                        
       
   918             // Ignore the errors from showing the note, it's better to continue if it fails
       
   919             
       
   920             TRAP_IGNORE(
       
   921                 // Show an error note, the entered codes don't match             
       
   922                 CAknNoteDialog* noteDlg = 
       
   923                     new (ELeave) CAknNoteDialog(reinterpret_cast<CEikDialog**>( &noteDlg ) );
       
   924                 noteDlg->SetTimeout( CAknNoteDialog::ELongTimeout );
       
   925                 noteDlg->SetTone( CAknNoteDialog::EErrorTone );
       
   926                 noteDlg->ExecuteLD( R_CODES_DONT_MATCH );
       
   927             );
       
   928             
       
   929             isMismatch = ETrue; // Repeat code query
       
   930             }        
       
   931         
       
   932         if ( !isMismatch )
       
   933             {
       
   934             HBufC8* addParamsHBuf = NULL;
       
   935     
       
   936             TRAP( err, addParamsHBuf = HBufC8::NewL( KSCPMaxTARMNotifParamLen ) );
       
   937             if ( err != KErrNone )
       
   938                 {
       
   939                 delete verifyCodeHBuf;
       
   940                 delete newCodeHBuf;             
       
   941                 return err;
       
   942                 }      
       
   943         
       
   944             TPtr8 addParams = addParamsHBuf->Des();
       
   945             addParams.Zero();                                    
       
   946             
       
   947             if ( !isMismatch )
       
   948                 {
       
   949                 // Try to change the code
       
   950                 TSCPSecCode newDOSCode;
       
   951                 newDOSCode.Zero();
       
   952                 
       
   953                 err = SendReceive(  ESCPServChangeEnhCode, 
       
   954                             TIpcArgs( &aOldCode, &verifyCodeBuffer, &addParams, &newDOSCode ) 
       
   955                          );
       
   956                 
       
   957                 if ( addParams.Length() > 0 )
       
   958                     {
       
   959                     // The server has sent additional parameters
       
   960                     TRAPD( err, ProcessServerCommandsL( addParams ) );
       
   961                     if ( err != KErrNone )
       
   962                         {
       
   963                         Dprint( (_L("RSCPClient::GetNewCodeAndChange():\
       
   964                             Process cmds FAILED: %d"), err ));
       
   965                         }                    
       
   966                     }
       
   967                     
       
   968                 if ( aNewDOSCode != NULL )
       
   969                     {
       
   970                     (*aNewDOSCode).Copy( newDOSCode );
       
   971                     }
       
   972                 }
       
   973             
       
   974             delete addParamsHBuf;
       
   975             }
       
   976                             
       
   977         } while ( ( isMismatch ) || ( err == KErrSCPInvalidCode ) ); // Loop END
       
   978         
       
   979     if ( ( ( !ret ) && ( err == KErrNone ) ) || ( ret == ESecUiEmergencyCall ) )
       
   980         {
       
   981         // Cancelled by user
       
   982         err = KErrAbort;
       
   983         }
       
   984 
       
   985     if((KErrNone == err) && (aNewCodePptr != 0)) {
       
   986         Dprint(_L("[RSCPClient]-> INFO: Updating new lock code to aNewCodePptr"));
       
   987         TRAP(err, *aNewCodePptr = HBufC :: NewL(verifyCodeHBuf->Des().Length()));
       
   988 
       
   989         if(*aNewCodePptr != NULL) {
       
   990             (*aNewCodePptr)->Des().Copy(verifyCodeHBuf->Des());
       
   991             Dprint(_L("[RSCPClient]-> INFO: Updated new lock code to aNewCodePptr"));
       
   992         }
       
   993     }
       
   994     
       
   995     delete verifyCodeHBuf;
       
   996     delete newCodeHBuf;
       
   997         
       
   998     return err;        
       
   999     }
       
  1000        
       
  1001             
       
  1002         
       
  1003 // ---------------------------------------------------------
       
  1004 // RSCPClient::ProcessServerCommandsL()
       
  1005 // Handle the commands in the server's param-buffer
       
  1006 // 
       
  1007 // Status : Approved
       
  1008 // ---------------------------------------------------------
       
  1009 //
       
  1010 void RSCPClient::ProcessServerCommandsL( TDes8& aInParams, 
       
  1011                                          CSCPParamObject** aOutParams,
       
  1012                                          TBool isNotifierEvent )
       
  1013     {    
       
  1014 
       
  1015     if(!isFlagEnabled)
       
  1016 	{
       
  1017 		User::Leave(KErrNotSupported);
       
  1018 	}
       
  1019     Dprint( (_L("--> RSCPClient::ProcessServerCommandsL()") ));
       
  1020     (void)aOutParams;
       
  1021     
       
  1022     CSCPParamObject* theParams = CSCPParamObject::NewL();
       
  1023     CleanupStack::PushL( theParams );
       
  1024     
       
  1025     theParams->Parse( aInParams );
       
  1026     TInt actionID;
       
  1027     TInt ret = theParams->Get( KSCPParamAction, actionID );
       
  1028     
       
  1029     Dprint( (_L("RSCPClient::ProcessServerCommandsL():Params parsed") ));
       
  1030     
       
  1031     if ( ret != KErrNone )
       
  1032         {
       
  1033         Dprint( (_L("RSCPClient::ProcessServerCommands(): Can't get action ID: %d"), ret )); 
       
  1034         }
       
  1035     else
       
  1036         {
       
  1037         switch ( actionID )
       
  1038             {
       
  1039             case ( KSCPActionShowUI ):
       
  1040                 {
       
  1041                 TRAP( ret, ShowUIL( *theParams ) );
       
  1042                 break;
       
  1043                 }
       
  1044                 
       
  1045             case ( KSCPActionForceChange ):
       
  1046                 {
       
  1047                 if ( isNotifierEvent )
       
  1048                     {
       
  1049                     break; // Calling this through the notifier would jam the system
       
  1050                     // since the server is busy.
       
  1051                     }                                    
       
  1052                 
       
  1053                 HBufC* codeHBuf = NULL;
       
  1054                 codeHBuf = HBufC::NewL( KSCPPasscodeMaxLength + 1 );    
       
  1055                 CleanupStack::PushL( codeHBuf );
       
  1056                    
       
  1057                 TPtr codeBuf = codeHBuf->Des();
       
  1058                 codeBuf.Zero(); 
       
  1059                 
       
  1060                 ret = theParams->Get( KSCPParamPassword, codeBuf );
       
  1061                 if ( ret == KErrNone )
       
  1062                     {
       
  1063                     TSCPSecCode newDOSCode;
       
  1064                     ret = GetNewCodeAndChange( codeBuf, KSCPForcedChange, &newDOSCode );
       
  1065                     
       
  1066                     // If aOutParams is defined, return the new code
       
  1067                     if ( aOutParams != NULL )
       
  1068                         {
       
  1069                         (*aOutParams) = CSCPParamObject::NewL();
       
  1070                         (*aOutParams)->Set( KSCPParamPassword, newDOSCode );
       
  1071                         }
       
  1072                     }
       
  1073                     
       
  1074                 CleanupStack::PopAndDestroy( codeHBuf );
       
  1075                                     
       
  1076                 break;
       
  1077                 }                            
       
  1078             }                
       
  1079         }
       
  1080                        
       
  1081     CleanupStack::PopAndDestroy( theParams );
       
  1082     
       
  1083     Dprint( (_L("<-- RSCPClient::ProcessServerCommandsL()") ));
       
  1084     User::LeaveIfError( ret );
       
  1085     }
       
  1086     
       
  1087 // ---------------------------------------------------------
       
  1088 // RSCPClient::ShowUI()
       
  1089 // Show the requested UI through AVKON
       
  1090 // 
       
  1091 // Status : Approved
       
  1092 // ---------------------------------------------------------
       
  1093 //
       
  1094 void RSCPClient::ShowUIL( CSCPParamObject& aContext )
       
  1095     {
       
  1096     
       
  1097     if(!isFlagEnabled)
       
  1098 	{
       
  1099 		User::Leave(KErrNotSupported);
       
  1100 	}
       
  1101     Dprint( (_L("--> RSCPClient::ShowUIL()") ));
       
  1102     TInt mode;
       
  1103     User::LeaveIfError( aContext.Get( KSCPParamUIMode, mode ) );
       
  1104     
       
  1105     switch ( mode )
       
  1106         {
       
  1107         case ( KSCPUINote ):
       
  1108             {
       
  1109             // Get prompt
       
  1110             TBuf<KSCPMaxPromptTextLen> promptText;
       
  1111             aContext.Get( KSCPParamPromptText, promptText );
       
  1112                         
       
  1113             // Try to get note icon, default is to use "error"
       
  1114             TInt noteType = KSCPUINoteError;
       
  1115             Dprint( (_L("RSCPClient::ShowUIL(): Creating note object") ));
       
  1116             
       
  1117             CAknResourceNoteDialog* note = NULL;
       
  1118             
       
  1119             if ( aContext.Get( KSCPParamNoteIcon, noteType ) != KErrNone )
       
  1120                 {
       
  1121                 noteType = KSCPUINoteError;
       
  1122                 }
       
  1123                 
       
  1124             switch ( noteType )
       
  1125                 {
       
  1126                 case ( KSCPUINoteWarning ):
       
  1127                     {
       
  1128                     note = new (ELeave) CAknWarningNote( ETrue );    
       
  1129                     break;
       
  1130                     }
       
  1131                     
       
  1132                 case ( KSCPUINoteError ):
       
  1133                 default: // default to error
       
  1134                     {
       
  1135                     note = new (ELeave) CAknErrorNote( ETrue ); 
       
  1136                     break;
       
  1137                     }                         
       
  1138                 }                                          
       
  1139 
       
  1140             if ( note != NULL )
       
  1141                 {
       
  1142                 Dprint( (_L("RSCPClient::ShowUIL(): Showing note") ));
       
  1143                 note->ExecuteLD( promptText );
       
  1144                 }            
       
  1145             }
       
  1146         }
       
  1147 
       
  1148     Dprint( (_L("<-- RSCPClient::ShowUIL()") ));
       
  1149     } 
       
  1150        
       
  1151 
       
  1152 // ---------------------------------------------------------
       
  1153 // RSCPClient::FetchLimits()
       
  1154 // Retrieve the limit-parameter values if available
       
  1155 // 
       
  1156 // Status : Approved
       
  1157 // ---------------------------------------------------------
       
  1158 //
       
  1159 void RSCPClient::FetchLimits( TInt& aMin, TInt& aMax )
       
  1160     {        
       
  1161     if(!isFlagEnabled)
       
  1162 	{
       
  1163 		return;
       
  1164 	}      
       
  1165     TInt maxLenID = RTerminalControl3rdPartySession::EPasscodeMaxLength;
       
  1166     TInt minLenID = RTerminalControl3rdPartySession::EPasscodeMinLength;
       
  1167     TBuf<KSCPMaxIntLength> intBuf;
       
  1168    
       
  1169     intBuf.Zero();    
       
  1170     if ( GetParamValue( minLenID, intBuf ) != KErrNone )
       
  1171         {
       
  1172         aMin = KSCPPasscodeMinLength;
       
  1173         }
       
  1174     else
       
  1175         {
       
  1176         TLex lex( intBuf );
       
  1177         if ( ( lex.Val( aMin ) != KErrNone ) || ( aMin <= 0 ) )
       
  1178             {
       
  1179             aMin = KSCPPasscodeMinLength;
       
  1180             }
       
  1181         }                
       
  1182     
       
  1183     intBuf.Zero();
       
  1184     if ( GetParamValue( maxLenID, intBuf ) != KErrNone )
       
  1185         {
       
  1186         aMax = KSCPPasscodeMaxLength;
       
  1187         }
       
  1188     else
       
  1189         {
       
  1190         TLex lex( intBuf );
       
  1191         if ( ( lex.Val( aMax ) != KErrNone ) || ( aMax <= 0 ) )
       
  1192             {
       
  1193             aMax = KSCPPasscodeMaxLength;
       
  1194             }
       
  1195         }
       
  1196     }              
       
  1197 TInt RSCPClient :: SetSecurityCodeL(RMobilePhone :: TMobilePassword& aPassword, 
       
  1198             TSCPButtonConfig aButtonsShown, TBool aECSSupport, TInt aFlags, TInt& aResFileSCP, TInt& aResFileSecUi) {
       
  1199     Dprint((_L("[RSCPClient]-> SetSecurityCodeL() >>>")));
       
  1200     Dprint((_L("[RSCPClient]-> input params - aButtonsShown=%d, aECSSupport=%d"), aButtonsShown, aECSSupport));
       
  1201     
       
  1202     if(EFalse == isFlagEnabled) {
       
  1203         (void)aPassword;
       
  1204         Dprint((_L("[RSCPClient]-> ERROR: Function not supported in this variant")));
       
  1205         User :: Invariant();
       
  1206         return KErrNotSupported;
       
  1207     }
       
  1208     TInt lRet = LoadResources(aResFileSCP, aResFileSecUi);
       
  1209     if(lRet != KErrNone) {
       
  1210         return lRet;
       
  1211     }
       
  1212     TInt lDefCode = 0;
       
  1213     CRepository* lRepository = CRepository :: NewLC(KCRUidSCPLockCode);
       
  1214     lRet = lRepository->Get(KSCPLockCodeDefaultLockCode, lDefCode);
       
  1215     if(lRet != KErrNone) {
       
  1216         Dprint(_L("[RSCPClient]-> ERROR: Unable to perform get on CenRep, lErr=%d"), lRet);
       
  1217         CleanupStack :: PopAndDestroy(lRepository);
       
  1218         return lRet;
       
  1219     }
       
  1220     HBufC* codeHBuf = HBufC :: NewLC(KSCPPasscodeMaxLength + 1);
       
  1221     HBufC8* addParamsHBuf = HBufC8 :: NewLC(KSCPMaxTARMNotifParamLen);
       
  1222     TPtr codeBuffer = codeHBuf->Des();
       
  1223     TPtr8 addParams = addParamsHBuf->Des();
       
  1224     if(lDefCode == 0) {
       
  1225         Dprint(_L("[RSCPClient]-> INFO: Default lock code has been set already by the user..."));
       
  1226         lRet = RunDialogL(codeBuffer, aButtonsShown, KSCPPasscodeMinLength, KSCPPasscodeMaxLength,
       
  1227                 R_SECUI_TEXT_ENTER_SEC_CODE, NULL, aECSSupport);
       
  1228         if((lRet) && (lRet != ESecUiEmergencyCall) && (lRet != EAknSoftkeyEmergencyCall)) {
       
  1229             Dprint(_L("[RSCPClient]-> INFO: User has updated the lock code..."));
       
  1230             lRet = SendReceive( ESCPServAuthenticateS60, TIpcArgs( &codeBuffer, &aPassword, &addParams, aFlags));
       
  1231             Dprint((_L("[RSCPClient]-> INFO: addParams.Length()=%d")), addParams.Length());
       
  1232             Dprint((_L("[RSCPClient]-> INFO: lRet=%d")), lRet);
       
  1233         }
       
  1234         else {
       
  1235             switch(lRet) {
       
  1236             case 0:
       
  1237             case EAknSoftkeyEmergencyCall:
       
  1238                 //lRet = KErrCancel;
       
  1239                 break;
       
  1240             case ESecUiEmergencyCall:
       
  1241                 lRet = ESecUiEmergencyCall;
       
  1242                 break;
       
  1243             default:
       
  1244                 break;
       
  1245             }
       
  1246         }
       
  1247     }
       
  1248     else {
       
  1249         TRequestStatus statusSave;
       
  1250         Dprint(_L("[RSCPClient]-> INFO: Default lock code not set by the user, requesting for the same"));
       
  1251 
       
  1252         HBufC* msgConfirmSave = NULL;
       
  1253         CAknGlobalConfirmationQuery* query = CAknGlobalConfirmationQuery :: NewLC();
       
  1254         
       
  1255         if(aButtonsShown == SCP_OK || aButtonsShown == SCP_OK_ETEL) {
       
  1256             //msgConfirmSave = CEikonEnv :: Static()->AllocReadResourceLC(R_SET_SEC_CODE_STARTUP_QUERY);
       
  1257             msgConfirmSave = CEikonEnv :: Static()->AllocReadResourceLC(R_SET_SEC_CODE);
       
  1258             query->ShowConfirmationQueryL(statusSave, *msgConfirmSave, R_AVKON_SOFTKEYS_OK_EMPTY__OK, R_QGN_NOTE_INFO_ANIM);
       
  1259         }
       
  1260         else {
       
  1261             msgConfirmSave = CEikonEnv :: Static()->AllocReadResourceLC(R_SET_SEC_CODE);
       
  1262         query->ShowConfirmationQueryL(statusSave, *msgConfirmSave, R_AVKON_SOFTKEYS_YES_NO__YES, R_QGN_NOTE_QUERY_ANIM);
       
  1263         }
       
  1264         
       
  1265         User :: WaitForRequest(statusSave);
       
  1266         CleanupStack :: PopAndDestroy(2); // msgConfirmSave query
       
  1267 
       
  1268         if((statusSave == EAknSoftkeyYes) || (statusSave == EAknSoftkeyOk)) {
       
  1269             Dprint(_L("[RSCPClient]-> INFO: calling GetNewCodeAndChange() ..."));
       
  1270             
       
  1271             TBufC<10> NBuf(KSCPDefaultEnchSecCode);
       
  1272             TPtr codeBuf = NBuf.Des();
       
  1273             
       
  1274             TSCPSecCode lNewSecCode;
       
  1275             TInt lButtonCfg = (aButtonsShown == SCP_OK || aButtonsShown == SCP_OK_ETEL) ? KSCPForcedChange : KSCPNormalChange;
       
  1276             HBufC* lNewLkCodeBuf = NULL;
       
  1277             lRet = GetNewCodeAndChange(codeBuf, lButtonCfg, &lNewSecCode, &lNewLkCodeBuf);
       
  1278             
       
  1279             Dprint(_L("[RSCPClient]-> INFO: GetNewCodeAndChange() complete, err=%d"), lRet);
       
  1280             
       
  1281             if(KErrNone == lRet) {
       
  1282                 /* This is being called as a workaround for a freezing issue with SecUI. This is in place 
       
  1283                  * as a temporary measure until the source is identified.
       
  1284                 */
       
  1285                 TInt lTmpRet = SendReceive(ESCPServAuthenticateS60, TIpcArgs(&lNewLkCodeBuf->Des(), &aPassword, &addParams, aFlags));
       
  1286                 
       
  1287                 Dprint(_L("[RSCPClient]-> INFO: lTmpRet from SendReceive()=%d"), lTmpRet);
       
  1288                 if(KErrNone == lRet) {
       
  1289                     Dprint(_L("[RSCPClient]-> INFO: updating CenRep ..."));
       
  1290                     lRepository->Set(KSCPLockCodeDefaultLockCode, 0);
       
  1291                     Dprint(_L("[RSCPClient]-> INFO: User updated lock code for the first time...err= %d"), lRet);
       
  1292                 }
       
  1293             }
       
  1294             
       
  1295             if(lNewLkCodeBuf) {
       
  1296                 delete lNewLkCodeBuf;
       
  1297             }
       
  1298         }
       
  1299         else {
       
  1300             Dprint(_L("[RSCPClient]-> INFO: Returning KErrCancel"));
       
  1301             lRet = KErrCancel;
       
  1302         }
       
  1303         
       
  1304         if(KErrAbort == lRet) {
       
  1305             Dprint(_L("[RSCPClient]-> INFO: Returning KErrCancel"));
       
  1306             lRet = KErrCancel;
       
  1307         }
       
  1308 
       
  1309     }
       
  1310     
       
  1311     if(addParams.Length() > 0) {
       
  1312         CSCPParamObject* tmp = CSCPParamObject :: NewLC();            
       
  1313         TInt lTempRet = tmp->Parse(addParams);
       
  1314         
       
  1315         if(lTempRet == KErrNone) {
       
  1316             lTempRet = tmp->Set(KSCPParamPassword, codeBuffer);
       
  1317         }
       
  1318         
       
  1319         if(lTempRet == KErrNone) {
       
  1320             addParams.Zero();
       
  1321             HBufC8* tmpBuf;
       
  1322             lTempRet = tmp->GetBuffer(tmpBuf);
       
  1323             
       
  1324             if(lTempRet == KErrNone) {
       
  1325                 addParams.Copy(tmpBuf->Des());
       
  1326                 delete tmpBuf;
       
  1327             }
       
  1328         }
       
  1329         
       
  1330         if(lTempRet == KErrNone) {
       
  1331             CSCPParamObject* outParams = NULL;
       
  1332             ProcessServerCommandsL(addParams, &outParams);
       
  1333             
       
  1334             if(outParams != NULL) {
       
  1335                 TSCPSecCode newSecCode;
       
  1336                 if(outParams->Get(KSCPParamPassword, newSecCode) == KErrNone) {
       
  1337                     Dprint((_L("[RSCPClient]-> INFO: Updating encoded password received from the server into aPassword...")));
       
  1338                     aPassword.Copy(newSecCode);
       
  1339                 }
       
  1340                 delete outParams;
       
  1341             }
       
  1342         }
       
  1343         CleanupStack :: PopAndDestroy(tmp);
       
  1344     }
       
  1345     CleanupStack :: PopAndDestroy(3); // repository, addParamsHBuf, codeHBuf
       
  1346     Dprint(_L("[RSCPClient]-> SetSecurityCodeL() <<< lRet=%d"), lRet);
       
  1347     return lRet;
       
  1348 }
       
  1349 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
       
  1350 // <<-- *********** Device lock new features *************
       
  1351 
       
  1352 
       
  1353 // ================= OTHER EXPORTED FUNCTIONS ==============
       
  1354 
       
  1355 
       
  1356 //  End of File  
       
  1357 
       
  1358