652 // Status : Approved |
636 // Status : Approved |
653 // --------------------------------------------------------- |
637 // --------------------------------------------------------- |
654 // |
638 // |
655 void CSCPServer::ValidateConfigurationL( TInt aMode ) |
639 void CSCPServer::ValidateConfigurationL( TInt aMode ) |
656 { |
640 { |
657 Dprint( (_L("--> CSCPServer::ValidateConfigurationL()") )); |
641 if (aMode == KSCPInitial) { |
658 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()")); |
642 // Return here, must be checked by complete mode |
659 TInt startupReason(ENormalStartup); |
643 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@@aMode == KSCPInitial ")); |
660 RProperty::Get(KPSUidStartup, KPSStartupReason, startupReason); |
644 User::Leave(KErrAccessDenied); |
661 Dprint( (_L("CSCPServer::ValidateConfigurationL(): startupReason = %d"), startupReason)); |
645 } |
662 if((startupReason == ENormalRFSReset)||(startupReason == EDeepRFSReset)||(startupReason == EFirmwareUpdate)||(iConfiguration.iConfigFlag == KSCPConfigUnknown)) |
646 |
663 { |
647 RMobilePhone::TMobilePassword storedCode; |
664 |
|
665 RMobilePhone::TMobilePassword storedCode; |
|
666 storedCode.Zero(); |
648 storedCode.Zero(); |
667 User::LeaveIfError(GetCode(storedCode)); |
649 User::LeaveIfError(GetCode(storedCode)); |
668 |
650 TBool isDefaultLockcode = ETrue; |
669 |
651 TInt err = KErrNone; |
670 Dprint( (_L("CSCPServer::ValidateConfigurationL(): Checking code: %s"), storedCode.PtrZ() )); |
652 |
671 // Check that the ISA code is stored correctly |
653 RMobilePhone::TMobilePassword defaultLockcode; |
672 TRAPD( err, CheckISACodeL( storedCode ) ); |
654 defaultLockcode.Zero(); |
673 //Bool for the correction of Defaultlockcode cenrep |
655 defaultLockcode.Copy(KSCPDefaultSecCode); |
674 TBool lCorrectDefaultlockcode = EFalse; |
656 if (storedCode.Compare(KSCPDefaultSecCode) == 0) { |
675 |
657 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@config has KSCPDefaultSecCode ")); |
676 Dprint( (_L("CSCPServer::ValidateConfigurationL(): iConfigFlag = %d, iConfigChecked = %d"), iConfiguration.iConfigFlag, iConfiguration.iConfigChecked)); |
658 TRAP( err, CheckISACodeL( defaultLockcode ) ); |
677 |
659 if (err == KErrNone) { |
678 if ((iConfiguration.iConfigFlag == KSCPConfigOK) |
660 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@ISA also has KSCPDefaultSecCode ")); |
679 && (iConfiguration.iConfigChecked) && (err == KErrNone)) |
661 iConfiguration.iConfigFlag = KSCPConfigOK; |
680 { |
662 isDefaultLockcode = ETrue; |
681 // The configuration has already been checked, exit |
663 } |
682 Dprint( (_L("CSCPServer::ValidateConfigurationL(): Configuration is non-default.") )); |
664 else { |
683 User::Leave( KErrNone ); |
665 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@ISA doesn't has KSCPDefaultSecCode ")); |
684 } |
666 iConfiguration.iConfigFlag = KSCPConfigInvalid; |
685 else if ( aMode == KSCPInitial ) |
667 iConfiguration.iFailedAttempts++; |
686 { |
668 isDefaultLockcode = EFalse; |
687 // Return here, must be checked by complete mode |
669 } |
688 User::Leave( KErrAccessDenied ); |
670 } |
689 } |
671 else { |
690 |
672 RDebug::Print(_L("CSCPServer::CheckISACodeL(): config lock code %s"), storedCode.PtrZ()); |
691 |
673 TRAP( err, CheckISACodeL( storedCode ) ); |
692 TInt hashedISAcode; |
674 if (err == KErrNone) { |
693 TSCPSecCode hashedCode; |
675 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@ISA and config are in SYNC !! ")); |
694 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS |
676 iConfiguration.iConfigFlag = KSCPConfigOK; |
695 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements)) |
677 isDefaultLockcode = EFalse; |
696 { |
678 } |
697 /*TInt*/ hashedISAcode = HashISACode( iConfiguration.iEnhSecCode ); |
679 else { |
698 // TSCPSecCode hashedCode; |
680 iConfiguration.iSecCode.Zero(); |
699 hashedCode.Zero(); |
681 iConfiguration.iSecCode.Append(KSCPDefaultSecCode); |
700 hashedCode.AppendNum( hashedISAcode ); |
682 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@May be ISA has KSCPDefaultSecCode ")); |
|
683 TRAP(err,ChangeISACodeL(storedCode)); |
|
684 if (err == KErrNone) { |
|
685 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()chnaged ISA code with config value ")); |
|
686 iConfiguration.iConfigFlag = KSCPConfigOK; |
|
687 isDefaultLockcode = EFalse; |
|
688 } |
|
689 else |
|
690 { |
|
691 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()it shouldn't reach this :( ")); |
|
692 } |
|
693 } |
|
694 } |
|
695 |
|
696 CRepository* repository = CRepository::NewL(KCRUidSCPLockCode); |
|
697 CleanupStack::PushL(repository); |
|
698 if (isDefaultLockcode ) { |
|
699 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()setting def. lockcode to 12345 ")); |
|
700 repository->Set(KSCPLockCodeDefaultLockCode, 12345); |
|
701 } |
|
702 else { |
|
703 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()setting def. lockcode to 0 ")); |
|
704 repository->Set(KSCPLockCodeDefaultLockCode, 0); |
|
705 } |
|
706 CleanupStack::PopAndDestroy(repository); |
|
707 |
|
708 TRAP( err, iConfiguration.WriteSetupL() ); |
|
709 if (err != KErrNone) { |
|
710 Dprint( (_L("CSCPServer::ValidateConfigurationL(): WARNING: failed to write configuration\ |
|
711 : %d"), err )); |
|
712 } |
|
713 |
|
714 if (iConfiguration.iConfigFlag == KSCPConfigOK) { |
|
715 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@iConfigFlag == KSCPConfigOK ")); |
|
716 err = KErrNone; |
|
717 } |
|
718 else { |
|
719 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()@iConfigFlag == KErrAccessDenied ")); |
|
720 err = KErrAccessDenied; |
|
721 } |
|
722 |
|
723 User::LeaveIfError(err); |
701 } |
724 } |
702 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 if (err != KErrNone) |
|
708 { |
|
709 lCorrectDefaultlockcode = ETrue; |
|
710 } |
|
711 if ( err == KErrNone ) |
|
712 { |
|
713 iConfiguration.iConfigFlag = KSCPConfigOK; |
|
714 } |
|
715 else if ( err == KErrAccessDenied ) |
|
716 { |
|
717 iConfiguration.iConfigFlag = KSCPConfigInvalid; |
|
718 } |
|
719 else if ( err == KErrLocked ) |
|
720 { |
|
721 Dprint( (_L("CSCPServer::ValidateConfigurationL(): ISA code locked.") )); |
|
722 } |
|
723 else |
|
724 { |
|
725 Dprint( (_L("CSCPServer::ValidateConfigurationL(): ERROR in validation.") )); |
|
726 } |
|
727 |
|
728 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS |
|
729 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements)) |
|
730 { |
|
731 if ( err == KErrNone ) |
|
732 { |
|
733 // Check that the codes are in-sync with each other. Especially the default ISA code must |
|
734 // be changed according to the default enhanced code. |
|
735 if ( storedCode.Compare( hashedCode ) != 0 ) |
|
736 { |
|
737 Dprint( (_L("CSCPServer::ValidateConfigurationL(): Correct ISA code stored.\ |
|
738 Changing ISA code to match enhanced code => %d"), hashedISAcode )); |
|
739 |
|
740 storedCode.Copy( hashedCode ); |
|
741 // Change the ISA code to match the hashed code |
|
742 ChangeISACodeL( storedCode ); |
|
743 } |
|
744 } |
|
745 else if ( ( err == KErrAccessDenied ) && ( storedCode.Compare( hashedCode ) != 0 ) ) |
|
746 { |
|
747 // Try again with the hashed code |
|
748 TRAP( err, CheckISACodeL( hashedCode ) ); |
|
749 |
|
750 if ( err == KErrNone ) |
|
751 { |
|
752 Dprint( (_L("CSCPServer::ValidateConfigurationL(): Hashed code is correct.\ |
|
753 Storing hashed code(%d)"), hashedISAcode )); |
|
754 |
|
755 if ( StoreCode( hashedCode ) == KErrNone ) |
|
756 { |
|
757 iConfiguration.iConfigFlag = KSCPConfigOK; |
|
758 lCorrectDefaultlockcode = ETrue; |
|
759 } |
|
760 } |
|
761 } |
|
762 |
|
763 //If Correction of Defaultlockcode cenrep is required for the mismatch between Config and ISA |
|
764 if (lCorrectDefaultlockcode) |
|
765 { |
|
766 TInt lDefCode = -1; |
|
767 CRepository* lRepository = CRepository::NewL(KCRUidSCPLockCode); |
|
768 CleanupStack::PushL(lRepository); |
|
769 TInt lRet = lRepository->Get(KSCPLockCodeDefaultLockCode, |
|
770 lDefCode); |
|
771 if (lRet == KErrNone && lDefCode != -1) |
|
772 { |
|
773 if (lDefCode == 12345) |
|
774 { |
|
775 //Although lock code is already set, due to some unexpected condition |
|
776 //like C drive wipe, cenrep status is wrongly shown. Correcting it here. |
|
777 lRepository->Set(KSCPLockCodeDefaultLockCode, 0); |
|
778 Dprint( (_L("RSCPClient::ValidateConfigurationL(): Corrected the Default lock code cenrep status to 0") )); |
|
779 } |
|
780 else if (lDefCode == 0) |
|
781 { |
|
782 //If only ISA side is formatted, then the lock code on ISA side is default; |
|
783 //Cenrep status remains wrongly as the lock code is already set. Correcting it here. |
|
784 lRepository->Set(KSCPLockCodeDefaultLockCode, 12345); |
|
785 Dprint( (_L("RSCPClient::ValidateConfigurationL(): Corrected the Default lock code cenrep status to 12345") )); |
|
786 } |
|
787 } |
|
788 CleanupStack::PopAndDestroy(lRepository); |
|
789 } |
|
790 } |
|
791 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS |
|
792 //Set the flag to True, after config is validated |
|
793 iConfiguration.iConfigChecked = ETrue; |
|
794 |
|
795 TRAPD( err2, iConfiguration.WriteSetupL() ); |
|
796 if ( err2 != KErrNone ) |
|
797 { |
|
798 Dprint( (_L("CSCPServer::ValidateConfigurationL(): WARNING: failed to write configuration\ |
|
799 : %d"), err2 )); |
|
800 } |
|
801 |
|
802 User::LeaveIfError( err ); |
|
803 } |
|
804 Dprint( (_L("<-- CSCPServer::ValidateConfigurationL()") )); |
|
805 } |
|
806 |
725 |
807 |
726 |
808 |
727 |
809 |
728 |
810 // --------------------------------------------------------- |
729 // --------------------------------------------------------- |
857 Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code NOT OK") )); |
779 Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code NOT OK") )); |
858 if (iConfiguration.iBlockedInOOS == 1) |
780 if (iConfiguration.iBlockedInOOS == 1) |
859 { |
781 { |
860 iConfiguration.iBlockedInOOS = 0; |
782 iConfiguration.iBlockedInOOS = 0; |
861 Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 0, KErrAccessDenied") )); |
783 Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 0, KErrAccessDenied") )); |
|
784 RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@iBlockedInOOS = 0, KErrAccessDenie")); |
862 } |
785 } |
863 ret = KErrAccessDenied; |
786 ret = KErrAccessDenied; |
864 } |
787 } |
865 else if ( ( ret == KErrGsmSSPasswordAttemptsViolation ) || ( ret == KErrLocked ) ) |
788 else if ( ( ret == KErrGsmSSPasswordAttemptsViolation ) || ( ret == KErrLocked ) ) |
866 { |
789 { |
867 Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code BLOCKED") )); |
790 Dprint( (_L("CSCPServer::CheckISACodeL(): ISA code BLOCKED") )); |
868 if (ret==KErrGsmSSPasswordAttemptsViolation) |
791 if (ret==KErrGsmSSPasswordAttemptsViolation) |
869 { |
792 { |
870 Dprint( (_L("CSCPServer::CheckISACodeL(): KErrGsmSSPasswordAttemptsViolation") )); |
793 Dprint( (_L("CSCPServer::CheckISACodeL(): KErrGsmSSPasswordAttemptsViolation") )); |
|
794 RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@KErrGsmSSPasswordAttemptsViolation")); |
871 } |
795 } |
872 else |
796 else |
873 { |
797 { |
874 Dprint( (_L("CSCPServer::CheckISACodeL(): KErrLocked") )); |
798 Dprint( (_L("CSCPServer::CheckISACodeL(): KErrLocked") )); |
|
799 RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@KErrLocked")); |
875 } |
800 } |
876 ret = KErrLocked; |
801 ret = KErrLocked; |
877 if (iConfiguration.iBlockedInOOS == 0) |
802 if (iConfiguration.iBlockedInOOS == 0) |
878 { |
803 { |
879 iConfiguration.iBlockedInOOS = 1; |
804 iConfiguration.iBlockedInOOS = 1; |
880 Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 1, KSCPErrCodeBlockStarted") )); |
805 Dprint( (_L("CSCPServer::CheckISACodeL():iBlockedInOOS = 1, KSCPErrCodeBlockStarted") )); |
|
806 RDebug::Print(_L("--> CSCPServer::CheckISACodeL()@@@@@")); |
881 ret = KSCPErrCodeBlockStarted; |
807 ret = KSCPErrCodeBlockStarted; |
882 } |
808 } |
883 } |
809 } |
884 else |
810 else |
885 { |
811 { |
886 Dprint( (_L("CSCPServer::CheckISACodeL(): ERROR reply checking ISA code: %d"), |
812 Dprint( (_L("CSCPServer::CheckISACodeL(): ERROR reply checking ISA code: %d"), |
887 status.Int() )); |
813 status.Int() )); |
|
814 RDebug::Print(_L("--> CSCPServer::ValidateConfigurationL()")); |
888 } |
815 } |
889 } |
816 } |
890 TRAPD( err, iConfiguration.WriteSetupL() ); |
817 TRAPD( err, iConfiguration.WriteSetupL() ); |
891 if ( err != KErrNone ) |
818 if ( err != KErrNone ) |
892 { |
819 { |
2201 iConfiguration.iSecCode.AppendNum( ISACode ); |
2131 iConfiguration.iSecCode.AppendNum( ISACode ); |
2202 |
2132 |
2203 // Unset the invalid configuration flag |
2133 // Unset the invalid configuration flag |
2204 iConfiguration.iConfigFlag = KSCPConfigOK; |
2134 iConfiguration.iConfigFlag = KSCPConfigOK; |
2205 writeSetup = ETrue; |
2135 writeSetup = ETrue; |
2206 } |
2136 } |
2207 else |
2137 else { |
2208 { |
2138 ret = KErrAccessDenied; |
2209 |
2139 |
2210 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): Given code does not have the \ |
2140 iConfiguration.iFailedAttempts++; |
2211 correct hash: ret; %d user enter password: %d"), ret )); |
2141 Dprint( (_L("CSCPServer::IsCorrectEnhCode():@@@: iFailedAttempts (%d)."), iConfiguration.iFailedAttempts )); |
2212 TRAP( ret, CheckISACodeL( aCode ) ); |
|
2213 if (ret == KErrNone) |
|
2214 { |
|
2215 //store this code in our interal storage as it is used as oldpassword while changing at ISA side in next command |
|
2216 //ChangeISACodeL. |
|
2217 iConfiguration.iSecCode.Zero(); |
|
2218 iConfiguration.iSecCode.Append( aCode ); |
|
2219 TRAP(ret,ChangeISACodeL(pswCandidate)); |
|
2220 } |
|
2221 if (ret == KErrNone) |
|
2222 { |
|
2223 iConfiguration.iEnhSecCode.Zero(); |
|
2224 iConfiguration.iEnhSecCode.Copy( hashBuf ); |
|
2225 |
|
2226 iConfiguration.iSecCode.Zero(); |
|
2227 iConfiguration.iSecCode.AppendNum( ISACode ); |
|
2228 |
|
2229 // Unset the invalid configuration flag |
|
2230 iConfiguration.iConfigFlag = KSCPConfigOK; |
|
2231 writeSetup = ETrue; |
2142 writeSetup = ETrue; |
2232 } |
2143 |
2233 } |
2144 if (iConfiguration.iFailedAttempts == KSCPCodeBlockLimit) { |
2234 } |
2145 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): KSCPCodeBlockLimit ") )); |
|
2146 // Block the code |
|
2147 TTime curTime; |
|
2148 curTime.UniversalTime(); |
|
2149 |
|
2150 iConfiguration.iBlockedAtTime.Zero(); |
|
2151 iConfiguration.iBlockedAtTime.AppendNum(curTime.Int64()); |
|
2152 |
|
2153 // The code will be blocked for now on |
|
2154 ret = KSCPErrCodeBlockStarted; |
|
2155 } |
|
2156 } |
|
2157 |
|
2158 } |
2235 |
2159 |
2236 // Write setup if needed |
2160 // Write setup if needed |
2237 if ( writeSetup ) |
2161 if ( writeSetup ) |
2238 { |
2162 { |
|
2163 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): 7 ") )); |
2239 TRAPD( err, iConfiguration.WriteSetupL() ); |
2164 TRAPD( err, iConfiguration.WriteSetupL() ); |
2240 if ( err != KErrNone ) |
2165 if ( err != KErrNone ) |
2241 { |
2166 { |
2242 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): WARNING:\ |
2167 Dprint( (_L("CSCPServer::IsCorrectEnhCode(): WARNING:\ |
2243 failed to write configuration: %d"), err )); |
2168 failed to write configuration: %d"), err )); |
2244 } |
2169 } |
2245 } |
2170 } |
2246 Dprint( (_L("CSCPServer::IsCorrectEnhCode %d"), ret )); |
2171 |
2247 return ret; |
2172 return ret; |
2248 } |
2173 } |
2249 |
2174 |
2250 |
2175 |
2251 |
2176 |