telephonyserverplugins/simtsy/src/CSimPhone.cpp
changeset 20 244d7c5f118e
parent 19 1f776524b15c
child 24 6638e7f4bd8f
child 42 3adadc800673
equal deleted inserted replaced
19:1f776524b15c 20:244d7c5f118e
   196  		pTable = NULL;
   196  		pTable = NULL;
   197  		LOGPHONE2("Failed to populate %s table in simtsy", &aLookup);			
   197  		LOGPHONE2("Failed to populate %s table in simtsy", &aLookup);			
   198  		}
   198  		}
   199  	}
   199  	}
   200 
   200 
       
   201  
       
   202  
       
   203  void CSimPhone::SetTestNumberAndReadConfigurationFileL()
       
   204      {
       
   205      TInt testNumber;
       
   206      User::LeaveIfError(GetTestNumber(testNumber));
       
   207      iSectionName.Format(KSectionNameFormat,testNumber);
       
   208      
       
   209      delete iConfigFile;
       
   210      iConfigFile = NULL;
       
   211          
       
   212      TRAPD(err, iConfigFile = CTestConfig::NewLC(iFs, KConfigFileDir, KConfigFilename); CleanupStack::Pop(iConfigFile));
       
   213      if( err == KErrNone && iConfigFile->Section(iSectionName) != NULL )
       
   214          {
       
   215          iConfigSection = iConfigFile->Section(iSectionName);
       
   216          }
       
   217     else
       
   218         {
       
   219         LOGPHONE2("Section for requested test number (%d) not found in the Config File",testNumber);
       
   220         delete iConfigFile;
       
   221         iConfigFile = NULL;
       
   222 
       
   223         User::Leave(KErrNotFound);
       
   224         }
       
   225      
       
   226      User::LeaveIfError(SetTestNumberInUse(testNumber));
       
   227      }
       
   228  
   201 void CSimPhone::ConstructL()
   229 void CSimPhone::ConstructL()
   202 /**
   230 /**
   203 * 2 Phase Construction (Second phase)
   231 * 2 Phase Construction (Second phase)
   204 * Loads the WINS Physical and Logical Serial Device Drivers.  C32 loads the non-WINS
   232 * Loads the WINS Physical and Logical Serial Device Drivers.  C32 loads the non-WINS
   205 * serial drivers, so we don't have to worry about these.
   233 * serial drivers, so we don't have to worry about these.
   212 	TInt r=User::LoadPhysicalDevice(PDD_NAME);
   240 	TInt r=User::LoadPhysicalDevice(PDD_NAME);
   213 	r=User::LoadLogicalDevice(LDD_NAME);
   241 	r=User::LoadLogicalDevice(LDD_NAME);
   214 #endif
   242 #endif
   215 
   243 
   216 	LOGPHONE1("Starting to Load and Parse the Config File");
   244 	LOGPHONE1("Starting to Load and Parse the Config File");
   217 	(void)User::LeaveIfError(iFs.Connect());
   245 	
   218 	iConfigFile=CTestConfig::NewLC(iFs,KConfigFileDir,KConfigFilename);
   246 	User::LeaveIfError(iFs.Connect());
   219 
   247 	
   220 	TInt testNumber;
   248 	SetTestNumberAndReadConfigurationFileL();
   221 	(void)User::LeaveIfError(GetTestNumber(testNumber));
   249 	
   222 	iSectionName.Format(KSectionNameFormat,testNumber);
       
   223 	if(iConfigFile->Section(iSectionName)==NULL)
       
   224 		{
       
   225         LOGPHONE2("Section for requested test number (%d) not found in the Config File",testNumber);
       
   226 		CleanupStack::Pop();
       
   227 		User::Leave(KErrNotFound);
       
   228 		}
       
   229 	else
       
   230 		{
       
   231 		(void)User::LeaveIfError(SetTestNumberInUse(testNumber));
       
   232 		}
       
   233 	CleanupStack::Pop();	// iConfigFile pointer is safely stored as a member variable
       
   234 
       
   235 	CSimTsyMode::InitL(this);
   250 	CSimTsyMode::InitL(this);
   236 
   251 
   237 	iReduceTimers = CSimReduceTimers::NewL();
   252 	iReduceTimers = CSimReduceTimers::NewL();
   238 
   253 
   239 	InitPhoneStatus();
   254 	InitPhoneStatus();
   291 			}			
   306 			}			
   292 		}
   307 		}
   293 
   308 
   294 	TPtrC8 IMSI;
   309 	TPtrC8 IMSI;
   295 	iSubscriberId.iError = KErrNone;
   310 	iSubscriberId.iError = KErrNone;
   296 	const CTestConfigItem* item=CfgFile()->Item(KSubscriberId);
   311 	const CTestConfigItem* itemSubscriberId=CfgFile()->Item(KSubscriberId);
   297     if (item)
   312     if( itemSubscriberId != NULL )
   298         {
   313         {
   299         TInt ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,IMSI);
   314         TInt ret=CTestConfig::GetElement(itemSubscriberId->Value(),KStdDelimiter,0,IMSI);
   300         if(ret!=KErrNone)
   315         if( ret != KErrNone )
       
   316 			{
   301             LOGPARSERR("IMSI",ret,0,&KSubscriberId);
   317             LOGPARSERR("IMSI",ret,0,&KSubscriberId);
       
   318 			}
   302         // coverity[check_return]
   319         // coverity[check_return]
   303         CTestConfig::GetElement(item->Value(),KStdDelimiter,1,iSubscriberId.iError);
   320         CTestConfig::GetElement(itemSubscriberId->Value(),KStdDelimiter,1,iSubscriberId.iError);
   304         iSubscriberId.iIMSI.Copy(IMSI);
   321         iSubscriberId.iIMSI.Copy(IMSI);
   305         }
   322         }
   306 	else
   323 	else
       
   324 		{
   307 		iSubscriberId.iIMSI.Copy(KSubscriberIdDefault);
   325 		iSubscriberId.iIMSI.Copy(KSubscriberIdDefault);
       
   326 		}
   308 
   327 
   309 	iNtwkMode=(RMobilePhone::TMobilePhoneNetworkMode)CfgFile()->ItemValue(KNetworkMode,KNetworkModeDefault);
   328 	iNtwkMode=(RMobilePhone::TMobilePhoneNetworkMode)CfgFile()->ItemValue(KNetworkMode,KNetworkModeDefault);
   310 	//get phone id from config file
   329 	//get phone id from config file
   311 	GetPhoneIdAndCaps();
   330 	GetPhoneIdAndCaps();
   312 
   331 
   330 	iPhoneScEapMan = CSimSmartCardEapManager::NewL(this);
   349 	iPhoneScEapMan = CSimSmartCardEapManager::NewL(this);
   331 
   350 
   332 	iNetworkModeTimer = CSimTimer::NewL(this);
   351 	iNetworkModeTimer = CSimTimer::NewL(this);
   333 	//< Read in all network mode data
   352 	//< Read in all network mode data
   334 	TInt count = CfgFile()->ItemCount(KNetworkMode);
   353 	TInt count = CfgFile()->ItemCount(KNetworkMode);
   335 	item = NULL;
   354 	const CTestConfigItem* item = NULL;
   336 	for (TInt i = 0; i < count; ++i)
   355 	for (TInt i = 0; i < count; ++i)
   337 		{
   356 		{
   338 		item = CfgFile()->Item(KNetworkMode,i);
   357 		item = CfgFile()->Item(KNetworkMode,i);
   339 		if (!item)
   358 		if (!item)
   340 			break;
   359 			break;
   386 		iNtwkMode = initialNetworkMode.iNetworkMode;		// set to new value if NetworkMode present in config.txt file
   405 		iNtwkMode = initialNetworkMode.iNetworkMode;		// set to new value if NetworkMode present in config.txt file
   387 		iTimerCallBackNetworkMode.SetHandle(this);
   406 		iTimerCallBackNetworkMode.SetHandle(this);
   388 		iNetworkModeTimer->Start(initialNetworkMode.iDuration, &iTimerCallBackNetworkMode);
   407 		iNetworkModeTimer->Start(initialNetworkMode.iDuration, &iTimerCallBackNetworkMode);
   389 		}
   408 		}
   390 	// end of network mode simulation setup
   409 	// end of network mode simulation setup
   391 
   410 	iTestNumberObserver = CSimTestNumberObserver::NewL(*this);
       
   411 	
   392 	LOGPHONE1("Completed Loading and Parsing the Config File");
   412 	LOGPHONE1("Completed Loading and Parsing the Config File");
   393 	}
   413 	}
   394 
   414 
   395 CSimReduceTimers* CSimPhone::GetReduceTimersSubject()
   415 CSimReduceTimers* CSimPhone::GetReduceTimersSubject()
   396 	{
   416 	{
   409 		LOGPHONE2("Got system property KUidPSSimTsyCategory/KPSSimTsyTestNumber. testNumber=%d", aTestNumber);
   429 		LOGPHONE2("Got system property KUidPSSimTsyCategory/KPSSimTsyTestNumber. testNumber=%d", aTestNumber);
   410 		}
   430 		}
   411 	else
   431 	else
   412 		{
   432 		{
   413 		aTestNumber = KDefaultTestNumber;
   433 		aTestNumber = KDefaultTestNumber;
       
   434 		LOGPHONE2("Using the default test number. testNumber=%d", aTestNumber);
   414 		}
   435 		}
   415 
   436 
   416 	return KErrNone;
   437 	return KErrNone;
   417 	}
   438 	}
   418 
   439 
   477 	if (iSIMServiceTable != NULL)		
   498 	if (iSIMServiceTable != NULL)		
   478 		delete(iSIMServiceTable);
   499 		delete(iSIMServiceTable);
   479 	if (iUSIMServiceTableV8 != NULL)		
   500 	if (iUSIMServiceTableV8 != NULL)		
   480 		delete(iUSIMServiceTableV8);
   501 		delete(iUSIMServiceTableV8);
   481 	
   502 	
   482 	
   503 	if( iPhBkStores != NULL )
   483 	if(iPhBkStores)
       
   484 		{
   504 		{
   485 		TInt storeCount=iPhBkStores->Count();
   505 		TInt storeCount=iPhBkStores->Count();
   486 		for(TInt i=0;i<storeCount;i++)
   506 		for(TInt i=0;i<storeCount;i++)
   487 			{
   507 			{
   488 			iPhBkStores->At(i)->Close();
   508 			iPhBkStores->At(i)->Close();
   489 			}
   509 			}
   490 		delete iPhBkStores;
   510 		delete iPhBkStores;
   491 		}
   511 		}
   492 
   512 	if( iPhBkUSimStores != NULL )
   493 	if(iPhBkUSimStores)
   513 	    {
   494 	{
       
   495 		TInt storeCount=iPhBkUSimStores->Count();
   514 		TInt storeCount=iPhBkUSimStores->Count();
   496 		for(TInt i=0;i<storeCount;i++)
   515 		for(TInt i=0;i<storeCount;i++)
   497 			{
   516 			{
   498 			iPhBkUSimStores->At(i)->Close();
   517 			iPhBkUSimStores->At(i)->Close();
   499 			}
   518 			}
   503 	if(iONStore)
   522 	if(iONStore)
   504 		{
   523 		{
   505 		iONStore->Close();
   524 		iONStore->Close();
   506 		iONStore = NULL;
   525 		iONStore = NULL;
   507 		}
   526 		}
   508 	
   527 	if( iNetworkModeArray != NULL )
   509 
       
   510 	if (iNetworkModeArray != NULL)
       
   511 		{
   528 		{
   512 		iNetworkModeArray->Delete(0,iNetworkModeArray->Count());
   529 		iNetworkModeArray->Delete(0,iNetworkModeArray->Count());
   513 		delete iNetworkModeArray;
   530 		delete iNetworkModeArray;
   514 		}
   531 		}
   515 
   532 	if( iPacketService!= NULL )
   516 
   533 	    {
   517 	if(iPacketService)
       
   518 		iPacketService->Close();
   534 		iPacketService->Close();
   519 
   535 	    }
   520 	if(iSat)
   536 	if( iSat != NULL )
       
   537 	    {
   521 		iSat->Close();
   538 		iSat->Close();
   522 	if(iConfigFile)
   539 	    }
   523 		delete iConfigFile;
   540 	if( iConfigFile == NULL)
   524 	if(iCallBarring)
   541 	    {
   525 		delete iCallBarring;
   542 	    // In this case if iConfigSection exists then it is not owned
   526 	if (iCallForwarding)
   543 	    // by iConfigFile - this is cos there was no config file for
   527 		delete iCallForwarding;
   544 	    // this SIM TSY.
   528 	if (iCallWaiting)
   545 	    delete iConfigSection;
   529 		delete iCallWaiting;
   546 	    }
       
   547 	delete iConfigFile;
       
   548     delete iCallBarring;
       
   549     delete iCallForwarding;
       
   550     delete iCallWaiting;
   530 
   551 
   531 	if (iSetCallProcessingSuspendStateTimer)
   552 	if (iSetCallProcessingSuspendStateTimer)
   532 		{
   553 		{
   533 		iSetCallProcessingSuspendStateTimer->Cancel();
   554 		iSetCallProcessingSuspendStateTimer->Cancel();
   534 		delete iSetCallProcessingSuspendStateTimer;		
   555 		delete iSetCallProcessingSuspendStateTimer;		
   535 		}
   556 		}
   536 	delete iSimPhoneInitialise;
   557 	delete iSimPhoneInitialise;
   537 	
   558 	
   538 	delete iReduceTimers;
   559 	delete iReduceTimers;
   539 
   560 	delete iTestNumberObserver;
       
   561 	
   540 	CSimTsyMode::FreeMode();
   562 	CSimTsyMode::FreeMode();
   541 	LOGPHONE1("CSimPhone Destroyed");
   563 	LOGPHONE1("CSimPhone Destroyed");
   542 	}
   564 	}
   543 
   565 
   544 void CSimPhone::InitPhoneStatus()
   566 void CSimPhone::InitPhoneStatus()
  2172 	RMobilePhone::TMobilePhoneSubscriberId& subscribe=(*subscribePckg)();
  2194 	RMobilePhone::TMobilePhoneSubscriberId& subscribe=(*subscribePckg)();
  2173 	TInt ret = KErrNone;
  2195 	TInt ret = KErrNone;
  2174 	if (iSubscriberId.iError == KErrNone)
  2196 	if (iSubscriberId.iError == KErrNone)
  2175 		{
  2197 		{
  2176 		if(iSubscriberId.iIMSI.Length()>RMobilePhone::KIMSISize)
  2198 		if(iSubscriberId.iIMSI.Length()>RMobilePhone::KIMSISize)
       
  2199 		    {
  2177 			subscribe.Copy(iSubscriberId.iIMSI.Left(RMobilePhone::KIMSISize));
  2200 			subscribe.Copy(iSubscriberId.iIMSI.Left(RMobilePhone::KIMSISize));
       
  2201 		    }
  2178 		else
  2202 		else
       
  2203 		    {
  2179 			subscribe.Copy(iSubscriberId.iIMSI);
  2204 			subscribe.Copy(iSubscriberId.iIMSI);
       
  2205 		    }
  2180 		}
  2206 		}
  2181 	else
  2207 	else
       
  2208 	    {
  2182 		ret = iSubscriberId.iError;
  2209 		ret = iSubscriberId.iError;
       
  2210 	    }
  2183 	ReqCompleted(aReqHandle,ret);
  2211 	ReqCompleted(aReqHandle,ret);
  2184 	return KErrNone;
  2212 	return KErrNone;
  2185 	}
  2213 	}
  2186 
  2214 
  2187 const CTestConfigSection* CSimPhone::CfgFile()
  2215 const CTestConfigSection* CSimPhone::CfgFile()
  2189 *	Return a pointer to the Configuration File Section
  2217 *	Return a pointer to the Configuration File Section
  2190 *
  2218 *
  2191 * @return CTestConfigSection	pointer to the configuration file section
  2219 * @return CTestConfigSection	pointer to the configuration file section
  2192 */
  2220 */
  2193 	{
  2221 	{
  2194 	return iConfigFile->Section(iSectionName);
  2222 	return iConfigSection;
  2195 	}
  2223 	}
  2196 
  2224 
  2197 const CTestConfigSection* CSimPhone::DefaultCfgFile()
  2225 const CTestConfigSection* CSimPhone::DefaultCfgFile()
  2198 /**
  2226 /**
  2199 *	Return a pointer to the Default Configuration File Section
  2227 *	Return a pointer to the Default Configuration File Section
  2200 *
  2228 *
  2201 * @return CTestConfigSection	pointer to the default configuration file section
  2229 * @return CTestConfigSection	pointer to the default configuration file section
  2202 */
  2230 */
  2203 	{
  2231 	{
       
  2232 	if( iConfigFile == NULL )
       
  2233 	    {
       
  2234 	    return NULL;
       
  2235 	    }
  2204 	return iConfigFile->Section(KScriptDefaults);
  2236 	return iConfigFile->Section(KScriptDefaults);
  2205 	}
  2237 	}
  2206 
  2238 
  2207 TInt CSimPhone::ValidateChangeState(CSimLine* aOriginatingLine, RMobileCall::TMobileCallStatus aState)
  2239 TInt CSimPhone::ValidateChangeState(CSimLine* aOriginatingLine, RMobileCall::TMobileCallStatus aState)
  2208 /**
  2240 /**
  2946 	ReqCompleted(aReqHandle,KErrNone);
  2978 	ReqCompleted(aReqHandle,KErrNone);
  2947 	return KErrNone;
  2979 	return KErrNone;
  2948 	}
  2980 	}
  2949 
  2981 
  2950 /**
  2982 /**
       
  2983  * Callback function invoked by the observer object when test number property is changed.
       
  2984  * This function is supposed to reset SIMTSY. Currently only SMS messaging part of SIMTSY
       
  2985  * is re-started with the new test number.
       
  2986  */
       
  2987 void CSimPhone::HandleTestNumberChangedL()
       
  2988     {
       
  2989     SetTestNumberAndReadConfigurationFileL();
       
  2990     iSmsMessaging->ReloadConfigurationSettingsL();
       
  2991     }
       
  2992 
       
  2993 TInt CSimPhone::CheckConfigFile()
       
  2994     {
       
  2995     TInt testNumber;
       
  2996     User::LeaveIfError(GetTestNumber(testNumber));
       
  2997     iSectionName.Format(KSectionNameFormat,testNumber);
       
  2998     
       
  2999     CTestConfig* configFile = NULL; 
       
  3000 
       
  3001     TRAPD(err, configFile = CTestConfig::NewLC(iFs, KConfigFileDir, KConfigFilename); CleanupStack::Pop(configFile));
       
  3002     if( err != KErrNone || configFile->Section(iSectionName) != NULL )
       
  3003         {
       
  3004         err = KErrNone;
       
  3005         }
       
  3006     else
       
  3007         {
       
  3008         err = KErrNotFound;
       
  3009         }
       
  3010     delete configFile;
       
  3011     return err;
       
  3012     }
       
  3013 /**
  2951 	Constructor for suspend call processing timer
  3014 	Constructor for suspend call processing timer
  2952 */
  3015 */
  2953 CSimPhone::CSetCallProcessingSuspendStateTimerCallBack::CSetCallProcessingSuspendStateTimerCallBack()
  3016 CSimPhone::CSetCallProcessingSuspendStateTimerCallBack::CSetCallProcessingSuspendStateTimerCallBack()
  2954 	{}
  3017 	{}
  2955 
  3018 
  3046 		*(RMobilePhone::TMobilePhoneNetworkMode*)iNotifyNetworkModeChange.iNotifyData = (RMobilePhone::TMobilePhoneNetworkMode)iNtwkMode;
  3109 		*(RMobilePhone::TMobilePhoneNetworkMode*)iNotifyNetworkModeChange.iNotifyData = (RMobilePhone::TMobilePhoneNetworkMode)iNtwkMode;
  3047 		ReqCompleted(iNotifyNetworkModeChange.iNotifyHandle,KErrNone);
  3110 		ReqCompleted(iNotifyNetworkModeChange.iNotifyHandle,KErrNone);
  3048 		}
  3111 		}
  3049 	
  3112 	
  3050 	iNetworkModeTimer->Start(iNetworkModeArray->At(iNetworkModeIndex).iDuration, &iTimerCallBackNetworkMode);
  3113 	iNetworkModeTimer->Start(iNetworkModeArray->At(iNetworkModeIndex).iDuration, &iTimerCallBackNetworkMode);
  3051 	}
       
  3052 
       
  3053 
       
  3054 void CSimPhone::ResetTestNumber()
       
  3055 	{
       
  3056 	TInt testNumber;
       
  3057 	GetTestNumber(testNumber);
       
  3058 	iSectionName.Format(KSectionNameFormat,testNumber);
       
  3059 	}
  3114 	}
  3060 
  3115 
  3061 TInt CSimPhone::CheckSimTsyVersion(RMobilePhone::TMultimodeType& aDataStruct) // overload this for other types of structures
  3116 TInt CSimPhone::CheckSimTsyVersion(RMobilePhone::TMultimodeType& aDataStruct) // overload this for other types of structures
  3062 /**
  3117 /**
  3063 * Checks the version of a data structure against the (simulated) version of SIMTSY, in order
  3118 * Checks the version of a data structure against the (simulated) version of SIMTSY, in order
  3245 		ret = KErrNotSupported;
  3300 		ret = KErrNotSupported;
  3246 		}
  3301 		}
  3247 		
  3302 		
  3248 	return ret;	
  3303 	return ret;	
  3249 	}
  3304 	}
       
  3305 ////////////////////
       
  3306 // CSimTestNumberObserver
       
  3307 ////////////////////
       
  3308 
       
  3309 CSimPhone::CSimTestNumberObserver::CSimTestNumberObserver(CSimPhone& aSimPhone)
       
  3310 : CActive(CActive::EPriorityStandard),
       
  3311   iSimPhone(aSimPhone)
       
  3312     {
       
  3313     CActiveScheduler::Add(this);
       
  3314     }
       
  3315 
       
  3316 CSimPhone::CSimTestNumberObserver::~CSimTestNumberObserver()
       
  3317     {
       
  3318     Cancel();
       
  3319     iProperty.Close();
       
  3320     }
       
  3321 
       
  3322 CSimPhone::CSimTestNumberObserver* CSimPhone::CSimTestNumberObserver::NewL(CSimPhone& aSimPhone)
       
  3323     {
       
  3324     CSimPhone::CSimTestNumberObserver* self = new(ELeave)CSimPhone::CSimTestNumberObserver(aSimPhone);
       
  3325     CleanupStack::PushL(self);
       
  3326     self->ConstructL();
       
  3327     CleanupStack::Pop(self);
       
  3328     return self;
       
  3329     }
       
  3330 
       
  3331 void CSimPhone::CSimTestNumberObserver::ConstructL()
       
  3332     {
       
  3333     LOGPHONE1("CSimPhone::CSimPhoneObserver::ConstructL");
       
  3334     User::LeaveIfError(iProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber));
       
  3335     Start();
       
  3336     }
       
  3337 
       
  3338 void CSimPhone::CSimTestNumberObserver::Start()
       
  3339     {
       
  3340     LOGPHONE1("CSimPhone::CSimPhoneObserver::Start");
       
  3341     iProperty.Subscribe(iStatus);
       
  3342     SetActive();
       
  3343     }
       
  3344 
       
  3345 void CSimPhone::CSimTestNumberObserver::RunL()
       
  3346     {
       
  3347     LOGPHONE2("CSimPhone::CSimPhoneObserver::RunL [iStatus=%d]", iStatus.Int());
       
  3348     TInt err = iSimPhone.CheckConfigFile();
       
  3349     if( err == KErrNone )
       
  3350         {
       
  3351         iSimPhone.HandleTestNumberChangedL();
       
  3352         }
       
  3353 
       
  3354     Start();
       
  3355     }
       
  3356 
       
  3357 void CSimPhone::CSimTestNumberObserver::DoCancel()
       
  3358     {
       
  3359     LOGPHONE1("CSimPhone::CSimPhoneObserver::DoCancel");
       
  3360     iProperty.Cancel();
       
  3361     }
       
  3362