telephonyserverplugins/simtsy/src/CSimMbmsPacketContext.cpp
changeset 0 3553901f7fa8
child 10 4284d6390a82
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This file contains the implementation of the Similator TSY MBMS Packet Context functionality.  
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include "Simlog.h"
       
    23 #include "CSimPhone.h"
       
    24 #include "CSimMbmsPacketContext.h"
       
    25 #include "CSimPacketQoS.h"
       
    26 #include "utils.h"
       
    27 #include <e32math.h>
       
    28 #include "CSimPacketService.h"
       
    29 #include "CSimContextHelper.h"
       
    30 
       
    31 CSimMbmsPacketContext* CSimMbmsPacketContext::NewL(CSimPhone* aPhone, CSimPacketService* aPacketService, const TDesC& aContextName)
       
    32 /**
       
    33 * Standard two phase constructor
       
    34 *
       
    35 * @param aPacketService Pointer to the Packet Service object (CSimPacketService)
       
    36 * @param aContextName name  for this packet context
       
    37 * @return CSimMbmsPacketContext pointer to the packet context object created.
       
    38 * @leave Leaves if no memory or object is not created for any reason.
       
    39 */
       
    40 	{
       
    41 	CSimMbmsPacketContext* packetContext = new(ELeave) CSimMbmsPacketContext(aPhone, aPacketService, aContextName);
       
    42 	CleanupStack::PushL(packetContext);
       
    43 	packetContext->ConstructL();
       
    44 	CleanupStack::Pop();
       
    45 	return packetContext;
       
    46 	}
       
    47 
       
    48 CSimMbmsPacketContext::CSimMbmsPacketContext(CSimPhone* aPhone, CSimPacketService* aPacketService, const TName& aContextName)
       
    49 	:CSimPacketContext(aPhone,aPacketService,aContextName),iContextName(aContextName), iContextType(TPacketDataConfigBase::KConfigMBMS),
       
    50 	iPhone(aPhone),iPacketService(aPacketService)
       
    51 /**
       
    52 * Trivial Constructor.  Initialises all the data members
       
    53 *
       
    54 * @param aPacketService Pointer to the Packet Service object (CSimPacketService)
       
    55 * @param aContextName name  for this packet context
       
    56 */
       
    57 	{
       
    58 	LOGPACKET1("CSimMbmsPacketContext: Entered constructor");
       
    59 	iNotifyConfigMBMS.iNotifyPending = EFalse;
       
    60 	iNotifyStatusChange.iNotifyPending = EFalse;
       
    61 	}
       
    62 
       
    63 void CSimMbmsPacketContext::ConstructL()
       
    64 /**
       
    65 * Second phase of the 2-phase constructor.
       
    66 * Constructs all the member data and retrieves all the data from the config file specific to this class.
       
    67 *
       
    68 * @leave Leaves no memory or any data member does not construct for any reason.
       
    69 */
       
    70 	{
       
    71 	LOGPACKET1("CSimMbmsPacketContext: Entered constructL function");
       
    72 	CSimPacketContext::ConstructL();
       
    73 	
       
    74 	iMbmsSetConfigTimer = CSimTimer::NewL(iPhone);
       
    75 	iMbmsContextTimer = CSimTimer::NewL(iPhone);
       
    76 	iMbmsUpdateSessionTimer = CSimTimer::NewL(iPhone);
       
    77 	iMbmsContextInitTimer = CSimTimer::NewL(iPhone);
       
    78 	iMbmsGetSessionTimer = CSimTimer::NewL(iPhone);
       
    79 	
       
    80 	iMbmsContextConfigParams = new (ELeave) CArrayFixFlat<TMbmsConfigParams>(KNumberofConfigs);
       
    81 	iSessionIdList = new (ELeave) CArrayFixFlat<TUint>(1);
       
    82 	iMbmsSessionList = new CArrayPtrFlat<CPcktListReadAllAttempt>(1);
       
    83 		
       
    84 	const CTestConfigItem* item=NULL;
       
    85 	TInt ret=KErrNone;
       
    86 
       
    87 	/* Reading the MBMS Context configuration parameters */
       
    88 	TUint count=CfgFile()->ItemCount(KMBMSBroadcastMonitorList); //< Retrieves the Count of MBMS related information
       
    89 
       
    90 	for(TInt i=0;i<count;i++)
       
    91 		{
       
    92 		item = CfgFile()->Item(KMBMSBroadcastMonitorList,i); //< Retrieves the MBMS related information
       
    93 
       
    94 		TInt mnc =0; 
       
    95 		TInt mcc =0;
       
    96 		TInt serviceId =0;
       
    97 		TInt accessBearer=0;
       
    98 		TInt serviceMode =0;
       
    99 		TInt activateCode =0;
       
   100 		TInt servicePriority=0;
       
   101 		if(!item)
       
   102 			break;
       
   103 
       
   104 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,mcc);
       
   105 		if(ret!=KErrNone)
       
   106 			{
       
   107 			break;
       
   108 			}
       
   109 
       
   110 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,2,mnc);
       
   111 		if(ret!=KErrNone)
       
   112 			{
       
   113 			break;
       
   114 			}
       
   115 
       
   116 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,3,serviceId);
       
   117 		if(ret!=KErrNone)
       
   118 			{
       
   119 			break;
       
   120 			}
       
   121 
       
   122 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,4,accessBearer);
       
   123 		if(ret!=KErrNone)
       
   124 			{
       
   125 			break;
       
   126 			}
       
   127 
       
   128 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,5,serviceMode);
       
   129 		if(ret!=KErrNone)
       
   130 			{
       
   131 			break;
       
   132 			}
       
   133 
       
   134 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,7,activateCode);
       
   135 		if(ret!=KErrNone)
       
   136 			{
       
   137 			break;
       
   138 			}
       
   139 
       
   140 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,8,servicePriority);
       
   141 		if(ret!=KErrNone)
       
   142 			{
       
   143 			break;
       
   144 			}
       
   145 
       
   146 		TMbmsConfigParams mbmsConfigParams;
       
   147 
       
   148 		mbmsConfigParams.iMCC = mcc;
       
   149 		mbmsConfigParams.iMNC = mnc;
       
   150 		mbmsConfigParams.iServiceId = serviceId;
       
   151 		mbmsConfigParams.iAccessBearer = reinterpret_cast<TMbmsScope&> (accessBearer);
       
   152 		mbmsConfigParams.iServiceMode = reinterpret_cast<TMbmsServiceMode&> (serviceMode);
       
   153 		mbmsConfigParams.iServicePriority = reinterpret_cast<TMbmsServicePriority&> (servicePriority);
       
   154 		mbmsConfigParams.iActivateCode = activateCode;
       
   155 
       
   156 		iMbmsContextConfigParams->AppendL(mbmsConfigParams);
       
   157 		}
       
   158 	
       
   159 	//iSessionIdList->AppendL(iNumOfSessionId);
       
   160 	iSessionIdList->InsertL(0,iNumOfSessionId);
       
   161 	
       
   162 	/* Reading the list of session ids mentioned in the configuration file*/
       
   163 	/*item = CfgFile()->Item(KMBMSSessionIdList,0); //< Retrieves the MBMS related information
       
   164 	
       
   165 	if(item != NULL)
       
   166 		{
       
   167 		TInt sessionId =0;
       
   168 		TInt numOfSessions =0;
       
   169 		
       
   170 		ret = CTestConfig::GetElement(item->Value(),KStdDelimiter,0,numOfSessions);
       
   171 		iSessionIdList->AppendL(numOfSessions);
       
   172 		
       
   173 		for(TInt j=1;j<=numOfSessions;j++)
       
   174 			{
       
   175 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,j,sessionId);
       
   176 			if(ret!=KErrNone)
       
   177 				{
       
   178 				break;
       
   179 				}
       
   180 			else
       
   181 				{
       
   182 				iSessionIdList->AppendL(sessionId);
       
   183 				}
       
   184 			}
       
   185 		}*/
       
   186 	}
       
   187 
       
   188 void CSimMbmsPacketContext::Init()
       
   189 /*
       
   190  * Initialisation function; Not used in the CSimMbmsPacketContext class.
       
   191  * but should be implemented as it is a pure virtual function of MTelObjectTSY. 
       
   192  */
       
   193 	{}
       
   194 	
       
   195 CSimMbmsPacketContext::~CSimMbmsPacketContext()
       
   196 /**
       
   197 * Trivial Destructor
       
   198 * Closes all CObject type objects and destroys all other objects created in the ConstructL()
       
   199 *
       
   200 */
       
   201 	{
       
   202 	LOGPACKET1("CSimMbmsPacketContext: Entered destructor");
       
   203 
       
   204 	if (iMbmsSetConfigTimer != NULL)
       
   205 		{
       
   206 		delete iMbmsSetConfigTimer;
       
   207 		}
       
   208 
       
   209 	if(iMbmsContextTimer != NULL)
       
   210 		{
       
   211 		delete iMbmsContextTimer;
       
   212 		}
       
   213 
       
   214 	if(iMbmsUpdateSessionTimer != NULL)
       
   215 		{	
       
   216 		delete iMbmsUpdateSessionTimer;
       
   217 		}
       
   218 
       
   219 	if(iMbmsContextInitTimer)
       
   220 		{
       
   221 		delete iMbmsContextInitTimer;
       
   222 		}
       
   223 
       
   224 	if(iMbmsGetSessionTimer)
       
   225 		{
       
   226 		delete iMbmsGetSessionTimer;
       
   227 		}
       
   228 	
       
   229 	if(iMbmsContextConfigParams !=NULL)
       
   230 		{
       
   231 		iMbmsContextConfigParams->Delete(0,iMbmsContextConfigParams->Count());
       
   232 		delete iMbmsContextConfigParams;
       
   233 		}
       
   234 
       
   235 	if(iSessionIdList != NULL)
       
   236 		{
       
   237 		iSessionIdList->Delete(0,iSessionIdList->Count());
       
   238 		delete iSessionIdList;
       
   239 		}
       
   240 
       
   241 	if(iMbmsSessionList)
       
   242 		{
       
   243 		iMbmsSessionList->ResetAndDestroy();
       
   244 		}
       
   245 	delete iMbmsSessionList;
       
   246 
       
   247 	iPacketService->DecrementMbmsContextCount();
       
   248 	}
       
   249 
       
   250 CTelObject* CSimMbmsPacketContext::OpenNewObjectByNameL(const TDesC& /*aName*/)
       
   251 /**
       
   252  * No Qos settings for the MBMS broadcast context 
       
   253  * This is not supported and if called, will leave.
       
   254  *
       
   255  * @param aName name of the QoS object to be opened
       
   256  * @leave Leaves with KErrNotSupported if the name is not as expected.
       
   257  * @ return NULL.
       
   258  */
       
   259 	{	
       
   260 	LOGPACKET1("Unexpected call to CSimMbmsPacketContext: OpenNewObjectByName");
       
   261 	User::Leave(KErrNotSupported);
       
   262 	return NULL;
       
   263 	}
       
   264 
       
   265 CTelObject* CSimMbmsPacketContext::OpenNewObjectL(TDes& /*aNewName*/)
       
   266 /**
       
   267  * No Qos settings for the MBMS broadcast context 
       
   268  * This is not supported and if called, will leave.
       
   269  *
       
   270  * @param aNewName new name of the object created
       
   271  * @return NULL
       
   272  * @leave Leaves if out of memory.
       
   273  */
       
   274 	{
       
   275 	LOGPACKET1("Unexpected call to CSimMbmsPacketContext: OpenNewObjectL");
       
   276 	User::Leave(KErrNotSupported);
       
   277 	return NULL;
       
   278 	}
       
   279 
       
   280 CTelObject::TReqMode CSimMbmsPacketContext::ReqModeL(const TInt aIpc)
       
   281 /**
       
   282 * ReqModeL is called from the server's CTelObject::ReqAnalyserL
       
   283 * in order to check the type of request it has.
       
   284 * 
       
   285 * @param aIpc the ipc number that identifies the client request
       
   286 * @return CTelObject::TReqMode The request mode to be used for this request
       
   287 * @leave Leaves if not supported by this tsy 
       
   288 */
       
   289 	{
       
   290 	LOGPACKET1("CSimMbmsPacketContext: ReqModeL");
       
   291 	CTelObject::TReqMode ret=0;
       
   292 	switch (aIpc)
       
   293 		{
       
   294 		case EPacketContextGetConfig:
       
   295 		case EPacketContextSetConfig:
       
   296 		case EPacketContextActivate:
       
   297 		case EPacketContextDeactivate:
       
   298 		case EPacketContextDelete:
       
   299 		case EPacketContextGetStatus:
       
   300 		case EPacketContextUpdateMbmsSessionList:
       
   301 		case EPacketContextInitialiseContext:
       
   302 		case EPacketGetMbmsSessionListPhase1:
       
   303 		case EPacketGetMbmsSessionListPhase2:
       
   304 		case EPacketContextGetLastErrorCause:
       
   305 			break;
       
   306 						
       
   307 		case EPacketContextNotifyConfigChanged:
       
   308 		case EPacketContextNotifyStatusChange:
       
   309 		case EPacketContextNotifyDataTransferred:
       
   310 			ret=KReqModeMultipleCompletionEnabled | KReqModeRePostImmediately;
       
   311 			break;
       
   312 		default:
       
   313 			LOGPACKET1("CSimMbmsPacketContext: ReqModeL error, unknown IPC");
       
   314 			LOGPACKET1("CSimMbmsPacketContext: ReqModeL sending the request to CSimPacketContext");
       
   315 			ret = CSimPacketContext::ReqModeL(aIpc);
       
   316 			break;
       
   317 		}
       
   318 	return ret;
       
   319 	}
       
   320 
       
   321 TInt CSimMbmsPacketContext::RegisterNotification(const TInt aIpc)
       
   322 /**
       
   323 * RegisterNotification is called when the server recognises that this notification
       
   324 * is being posted for the first time on this sub-session object.
       
   325 * 
       
   326 * It enables the TSY to "turn on" any regular notification messages that it may receive 
       
   327 * from the phone
       
   328 *
       
   329 * @param aIpc the ipc number that identifies the client request
       
   330 * @return err KErrNone if fine
       
   331 */
       
   332 	{
       
   333 	LOGPACKET1("CSimMbmsPacketContext: RegisterNotification called");
       
   334 	switch (aIpc)
       
   335 		{
       
   336 		case EPacketContextNotifyConfigChanged:
       
   337 		case EPacketContextNotifyStatusChange:
       
   338 		case EPacketContextNotifyDataTransferred:
       
   339 			LOGPACKET1("CSimMbmsPacketContext: RegisterNotification");
       
   340 			return KErrNone;
       
   341 		default:
       
   342 			// Unknown or invalid IPC
       
   343 			LOGPACKET1("CSimMbmsPacketContext: Register error, unknown IPC");
       
   344 			LOGPACKET1("CSimMbmsPacketContext: Register sending the request to CSimPacketContext");
       
   345 			return CSimPacketContext::RegisterNotification(aIpc);
       
   346 		}
       
   347 	}
       
   348 
       
   349 TInt CSimMbmsPacketContext::DeregisterNotification(const TInt aIpc)
       
   350 /**
       
   351 * DeregisterNotification is called when the server recognises that this notification
       
   352 * will not be posted again because the last client to have a handle on this sub-session
       
   353 * object has just closed the handle.
       
   354 *
       
   355 * It enables the TSY to "turn off" any regular notification messages that it may 
       
   356 * receive from the phone
       
   357 *
       
   358 * @param aIpc the ipc number that identifies the client request
       
   359 * @return err KErrNone if fine
       
   360 */
       
   361 	{	
       
   362 	LOGPACKET1("CSimMbmsPacketContext: DeregisterNotification called");
       
   363 	switch (aIpc)
       
   364 		{
       
   365 		case EPacketContextNotifyConfigChanged:
       
   366 		case EPacketContextNotifyStatusChange:
       
   367 		case EPacketContextNotifyDataTransferred:
       
   368 			LOGPACKET1("CSimMbmsPacketContext: DeregisterNotification");
       
   369 			return KErrNone;
       
   370 		default:
       
   371 			// Unknown or invalid IPC
       
   372 			LOGPACKET1("CSimMbmsPacketContext: Deregister error, unknown IPC");
       
   373 			LOGPACKET1("CSimMbmsPacketContext: Deregister sending the request to CSimPacketContext");
       
   374 			return CSimPacketContext::DeregisterNotification(aIpc);
       
   375 		}
       
   376 	}
       
   377 
       
   378 TInt CSimMbmsPacketContext::NumberOfSlotsL(const TInt aIpc)
       
   379 /**
       
   380 * NumberOfSlotsL is called by the server when it is registering a new notification
       
   381 * It enables the TSY to tell the server how many buffer slots to allocate for
       
   382 * "repost immediately" notifications that may trigger before clients collect them
       
   383 *
       
   384 * @param aIpc the ipc number that identifies the client request
       
   385 * @return err KErrNone if fine
       
   386 */
       
   387 	{
       
   388 	LOGPACKET1("CSimMbmsPacketContext: NumberOfSlotsL called");
       
   389 	TInt numberOfSlots=1;
       
   390 	switch (aIpc)
       
   391 		{
       
   392 		case EPacketContextNotifyConfigChanged:
       
   393 		case EPacketContextNotifyStatusChange:
       
   394 		case EPacketContextNotifyDataTransferred:
       
   395 			LOGPACKET1("CSimMbmsPacketContext: Registered with 5 slots");
       
   396 			numberOfSlots=5;
       
   397 			break;
       
   398 		default:
       
   399 			// Unknown or invalid IPC
       
   400 			LOGPACKET1("CSimMbmsPacketContext: Number of Slots error, unknown IPC");
       
   401 			LOGPACKET1("CSimMbmsPacketContext: Number of Slots: sending the request to CSimPacketContext");
       
   402 			return CSimPacketContext::NumberOfSlotsL(aIpc);
       
   403 		}  
       
   404 	return numberOfSlots;
       
   405 	}
       
   406 
       
   407 TInt CSimMbmsPacketContext::ExtFunc(const TTsyReqHandle aTsyReqHandle,const TInt aIpc,
       
   408 							  const TDataPackage& aPackage)
       
   409 /**
       
   410 * ExtFunc is called by the server when it has a "extended", i.e. non-core ETel request
       
   411 * for the TSY to process.
       
   412 * A request handle, request type and request data are passed to the TSY
       
   413 * 
       
   414 * @param aTsyReqHandle  The request handle for completing the request 
       
   415 * @param aIpc Ipc representing the request
       
   416 * @param aPackage any data associated with the request
       
   417 * @return err KErrNone if request completes ok
       
   418 */
       
   419 	{
       
   420 	//< if this context has been deleted then the client can not do anything with it
       
   421 	//< if the client wants to use this class, the client must open a new object by 
       
   422 	//< name with the name for this context and this will reactivate the context.
       
   423 	if(iDeleted && (aIpc != EPacketContextGetStatus))  
       
   424 		{
       
   425 		ReqCompleted(aTsyReqHandle,KErrNotReady);
       
   426 		return KErrNone;
       
   427 		}
       
   428 	LOGPACKET1("CSimMbmsPacketContext: ExtFunc Called");
       
   429 	TAny* dataPtr=aPackage.Ptr1();
       
   430 	TAny* dataPtr2=aPackage.Ptr2();
       
   431 
       
   432 	switch (aIpc)
       
   433 		{
       
   434 		case EPacketContextGetConfig:
       
   435 			return GetConfig(aTsyReqHandle, aPackage.Des1n());
       
   436 		case EPacketContextGetConfigCancel:
       
   437 			return GetConfigCancel(aTsyReqHandle);
       
   438 		case EPacketContextSetConfig:
       
   439 			return SetConfig(aTsyReqHandle, aPackage.Des1n());
       
   440 		case EPacketContextSetConfigCancel:
       
   441 			return SetConfigCancel(aTsyReqHandle);
       
   442 		case EPacketContextActivate:
       
   443 			{	//< Ensures that theres only one context active as only one active context is 
       
   444 			//<permitted at any one time
       
   445 			if(iIsActive)
       
   446 				{
       
   447 				LOGPACKET1("Trying to activate an already activated context");
       
   448 				ReqCompleted(aTsyReqHandle,KErrEtelCallAlreadyActive);
       
   449 				return KErrNone;
       
   450 				}
       
   451 			else
       
   452 				return Activate(aTsyReqHandle);
       
   453 			}
       
   454 		case EPacketContextActivateCancel:
       
   455 			return ActivateCancel(aTsyReqHandle);
       
   456 		case EPacketContextDeactivate:
       
   457 			return Deactivate(aTsyReqHandle);
       
   458 		case EPacketContextDeactivateCancel:
       
   459 			return DeactivateCancel(aTsyReqHandle);
       
   460 		case EPacketContextDelete:
       
   461 			return Delete(aTsyReqHandle);
       
   462 		case EPacketContextDeleteCancel:
       
   463 			return DeleteCancel(aTsyReqHandle);
       
   464 		case EPacketContextGetLastErrorCause:
       
   465 			return GetLastErrorCause(aTsyReqHandle,
       
   466 			REINTERPRET_CAST(TInt*, dataPtr));
       
   467 		case EPacketContextNotifyConfigChanged:
       
   468 			return NotifyConfigChanged(aTsyReqHandle, aPackage.Des1n());
       
   469 		case EPacketContextNotifyConfigChangedCancel:
       
   470 			return NotifyConfigChangedCancel(aTsyReqHandle);
       
   471 		case EPacketContextNotifyStatusChange:
       
   472 			return NotifyStatusChange(aTsyReqHandle,
       
   473 					REINTERPRET_CAST(RPacketContext::TContextStatus*, dataPtr));
       
   474 		case EPacketContextNotifyStatusChangeCancel:
       
   475 			return NotifyStatusChangeCancel(aTsyReqHandle);
       
   476 		case EPacketContextGetStatus:
       
   477 			return GetStatus(aTsyReqHandle,
       
   478 					REINTERPRET_CAST(RPacketContext::TContextStatus*, dataPtr));
       
   479 		case EPacketContextUpdateMbmsSessionList:
       
   480 			return UpdateMbmsSessionListL(aTsyReqHandle,
       
   481 					REINTERPRET_CAST(TMbmsAction*, dataPtr),
       
   482 					REINTERPRET_CAST(TUint*, dataPtr2));	
       
   483 		case EPacketContextInitialiseContext:
       
   484 			return InitialiseContext(aTsyReqHandle, aPackage.Des1n());
       
   485 		case EPacketContextInitialiseContextCancel:
       
   486 			return InitialiseContextCancel(aTsyReqHandle);
       
   487 		case EPacketGetMbmsSessionListPhase1:
       
   488 			return GetMbmsSessionsPhase1(aTsyReqHandle, 
       
   489 			REINTERPRET_CAST(TClientId*, dataPtr), 
       
   490 			REINTERPRET_CAST(TInt*, dataPtr2));
       
   491 		case EPacketGetMbmsSessionListPhase2:
       
   492 			return GetMbmsSessionsPhase2(aTsyReqHandle, 
       
   493 			REINTERPRET_CAST(TClientId*, dataPtr), aPackage.Des2n());		
       
   494 		default:
       
   495 			LOGPACKET1("CSimMbmsPacketContext: ExtFunc Unknown IPC");
       
   496 			LOGPACKET1("CSimMbmsPacketContext: sending the request to CSimPacketContext::ExtFunc Unknown IPC");
       
   497 			return CSimPacketContext::ExtFunc(aTsyReqHandle,aIpc,aPackage);
       
   498 		}
       
   499 	}
       
   500 		
       
   501 TInt CSimMbmsPacketContext::CancelService(const TInt aIpc,const TTsyReqHandle aTsyReqHandle)
       
   502 /**
       
   503 * CancelService is called by the server when it is "cleaning-up" any still outstanding
       
   504 * asynchronous requests before closing a client's sub-session.
       
   505 * This will happen if a client closes its R-class handle without cancelling outstanding asynchronous requests.
       
   506 * 
       
   507 * @param aTsyReqHandle  The request handle for completing the request 
       
   508 * @param aIpc Ipc representing the request
       
   509 * @return err KErrNone if request completes ok
       
   510 */
       
   511 	{
       
   512 	LOGPACKET1("CSimMbmsPacketContext: - CancelService called");
       
   513 
       
   514 	switch (aIpc)
       
   515 		{
       
   516 		case EPacketContextSetConfig:
       
   517 			return SetConfigCancel(aTsyReqHandle);
       
   518 		case EPacketContextGetConfig:
       
   519 			return GetConfigCancel(aTsyReqHandle);
       
   520 		case EPacketContextActivate:
       
   521 			return ActivateCancel(aTsyReqHandle);
       
   522 		case EPacketContextDeactivate:
       
   523 			return DeactivateCancel(aTsyReqHandle);
       
   524 		case EPacketContextDeleteCancel:
       
   525 			return DeleteCancel(aTsyReqHandle);
       
   526 		case EPacketContextNotifyConfigChanged:
       
   527 			return NotifyConfigChangedCancel(aTsyReqHandle);
       
   528 		case EPacketContextNotifyStatusChange:
       
   529 			return NotifyStatusChangeCancel(aTsyReqHandle);
       
   530 		case EPacketContextInitialiseContext:
       
   531 			return InitialiseContextCancel(aTsyReqHandle);
       
   532 		case EPacketGetMbmsSessionListPhase1:
       
   533 		case EPacketGetMbmsSessionListPhase2:
       
   534 			return GetMbmsSessionsCancel(aTsyReqHandle);
       
   535 		default:
       
   536 			LOGPACKET1("CSimMbmsPacketContext: - CancelService unknown IPC called");
       
   537 			LOGPACKET1("CSimMbmsPacketContext: sending the request to CSimPacketContext::ExtFunc Unknown IPC");
       
   538 			return CSimPacketContext::CancelService(aIpc,aTsyReqHandle);
       
   539 		}
       
   540 	}
       
   541 
       
   542 void CSimMbmsPacketContext::TimerCallBack(TInt aId)
       
   543 /**
       
   544 * Timer callback function.  When the timer goes off, it will call back into this
       
   545 * function for further processing.
       
   546 * param - aId indicates which Timer Event has occured.
       
   547 */
       
   548 	{
       
   549 	LOGPACKET1("CSimMbmsPacketContext: - TimerCallBack(TInt aId) called");
       
   550 	switch(aId)
       
   551 		{
       
   552 		case ETimerIdMbmsPcktContextSetConfig:
       
   553 			LOGPACKET1("CSimMbmsPacketContext: - TimerCallBack SetConfig called");
       
   554 			if(iSetConfigValues.iErrorValue == KErrNone)
       
   555 				{
       
   556 				iMbmsContextConfigParamsIndex = iSetConfigValues.iIndex ;
       
   557 				}
       
   558 			ReqCompleted(iSetConfigRequestHandle,iSetConfigValues.iErrorValue);
       
   559 			break;
       
   560 		case ETimerIdMbmsUpdateSessionId:
       
   561 			LOGPACKET1("CSimMbmsPacketContext: - TimerCallBack UpdateSessionID called");
       
   562 			if(iUpdateSessionHandle != NULL)
       
   563 				{
       
   564 				ReqCompleted(iUpdateSessionHandle,KErrNone);
       
   565 				}
       
   566 			break;
       
   567 		case ETimerIdPcktContextInitContext:
       
   568 			DoInitialiseContext();
       
   569 			break;
       
   570 		case ETimerIdPcktContextCreateTft:
       
   571 			CSimPacketContext::TimerCallBack(aId);
       
   572 			break;
       
   573 		default:
       
   574 			{
       
   575 			LOGPACKET1(">>CSimMbmsPacketContext::TimerCallBack Default Case for Context Events");
       
   576 			switch(iCurrentEvent)
       
   577 				{
       
   578 				case EMbmsContextEventNone:
       
   579 					LOGPACKET1("TimerCallBack - iCurrentEvent = [EMbmsContextEventNone]");
       
   580 					break;
       
   581 				case EMbmsContextEventActivate:
       
   582 					LOGPACKET1("TimerCallBack - iCurrentEvent = [EMbmsContextEventActivate]");
       
   583 					if(iState==RPacketContext::EStatusActivating)
       
   584 						{
       
   585 						TInt activateValue = iMbmsContextConfigParams->At(iMbmsContextConfigParamsIndex).iActivateCode;
       
   586 						TInt ret;
       
   587 						if(activateValue != KErrNone) 
       
   588 							{ // Reject the Activation request.
       
   589 							ret=ChangeState(RPacketContext::EStatusInactive);
       
   590 							ReqCompleted(iActivateRequestHandle,KErrGprsActivationRejected);
       
   591 							iCurrentEvent=EMbmsContextEventNone;
       
   592 							}
       
   593 						else
       
   594 							{
       
   595 							ret=ChangeState(RPacketContext::EStatusActive);
       
   596 							ReqCompleted(iActivateRequestHandle,ret);
       
   597 							iCurrentEvent=EMbmsContextEventNone;
       
   598 							iIsActive = ETrue;
       
   599 							}
       
   600 						
       
   601 						// Check for and complete any pending notifications
       
   602 						if(iNotifyConfigMBMS.iNotifyPending)
       
   603 							{
       
   604 							TMbmsConfigParams thisConfig = iMbmsContextConfigParams->At(iMbmsContextConfigParamsIndex);
       
   605 							iNotifyConfigMBMS.iNotifyPending=EFalse;
       
   606 							RPacketMbmsContext::TContextConfigMbmsV1 *tempConfig = (RPacketMbmsContext::TContextConfigMbmsV1*)iNotifyConfigMBMS.iNotifyData;
       
   607 							tempConfig->iTmgi.SetServiceId(thisConfig.iServiceId);
       
   608 							tempConfig->iTmgi.SetMCC(thisConfig.iMCC);
       
   609 							tempConfig->iTmgi.SetMNC(thisConfig.iMNC);
       
   610 							tempConfig->iMbmsAccessBearer= thisConfig.iAccessBearer;
       
   611 							tempConfig->iMbmsServicePriority = thisConfig.iServicePriority;
       
   612 							tempConfig->iMbmsServiceMode = thisConfig.iServiceMode;
       
   613 							ReqCompleted(iNotifyConfigMBMS.iNotifyHandle,KErrNone);
       
   614 							}
       
   615 						}
       
   616 					else
       
   617 						{
       
   618 						LOGPACKET1("Unexpected iState for iCurrentEvent[EMbmsContextEventActivate]");
       
   619 						}
       
   620 					break;
       
   621 				case EMbmsContextEventDeactivate:
       
   622 					LOGPACKET1("TimerCallBack - iCurrentEvent = [EMbmsContextEventDeactivate]");
       
   623 					if(((iState == RPacketContext::EStatusInactive) || (iState == RPacketContext::EStatusDeactivating)) && 
       
   624 									(iCurrentEvent==EMbmsContextEventDeactivate))
       
   625 						{
       
   626 						TInt ret=ChangeState(RPacketContext::EStatusInactive);
       
   627 						ReqCompleted(iDeactivateRequestHandle,ret);
       
   628 						iCurrentEvent=EMbmsContextEventNone;
       
   629 						iIsActive = EFalse;
       
   630 						}
       
   631 					else
       
   632 						{
       
   633 						LOGPACKET1("Unexpected iState for iCurrentEvent[EMbmsContextEventActivate]");
       
   634 						}
       
   635 					break;
       
   636 				case EMbmsContextEventDelete:
       
   637 					LOGPACKET1("TimerCallBack - iCurrentEvent = [EMbmsContextEventDelete]");
       
   638 					if(iState == RPacketContext::EStatusInactive && !iIsActive )
       
   639 						{
       
   640 						TInt ret = ChangeState(RPacketContext::EStatusDeleted);
       
   641 						ReqCompleted(iDeleteRequestHandle,ret);
       
   642 						iCurrentEvent=EMbmsContextEventNone;
       
   643 						}
       
   644 					else
       
   645 						{
       
   646 						ReqCompleted(iDeleteRequestHandle,KErrCorrupt); // KErrCorrupt is sent to indicate that the 
       
   647 						//delete request is received when the context is Not inactive.
       
   648 						}
       
   649 					break;
       
   650 				default:
       
   651 					{
       
   652 					LOGPACKET1("CSimMbmsPacketContext::TimerCallBack");
       
   653 					LOGPACKET1("<<Unexpected iCurrentEvent @ TimerCallBack");
       
   654 					break;
       
   655 					}
       
   656 				}
       
   657 			}
       
   658 		}
       
   659 	}
       
   660 
       
   661 TName CSimMbmsPacketContext::ContextName() const 
       
   662 /**
       
   663 * Returns the context name to the requested client
       
   664 *
       
   665 * @return TName	Name of the MBMS context
       
   666 */
       
   667 	{
       
   668 	LOGPACKET1("CSimMbmsPacketContext::ContextName called");
       
   669 	return iContextName; 
       
   670 	}
       
   671 
       
   672 const CTestConfigSection* CSimMbmsPacketContext::CfgFile()
       
   673 /**
       
   674 * Return a pointer to the Configuration File Section
       
   675 *
       
   676 * @return CTestConfigSection	pointer to the configuration file section
       
   677 */
       
   678 	{
       
   679 	LOGPACKET1("CSimMbmsPacketContext::CfgFile called");
       
   680 	return iPacketService->CfgFile();
       
   681 	}
       
   682 
       
   683 TInt CSimMbmsPacketContext::SetConfig(const TTsyReqHandle aTsyReqHandle,const TDesC8* aConfig)
       
   684 /**
       
   685 * Sets the MBMS configuration parameters and notifies if
       
   686 * there is a pending notification for the config change.
       
   687 *
       
   688 * @param aTsyReqHandle Tsy Request handle for the client request
       
   689 * @param aConfig pointer containing the parameters to set to.
       
   690 * @return KErrNone
       
   691 */
       
   692 	{
       
   693 	LOGPACKET1("CSimMbmsPacketContext::SetConfig called");
       
   694 
       
   695 	TPckg<TPacketDataConfigBase>* configBase = (TPckg<TPacketDataConfigBase>*)aConfig;
       
   696 	TPacketDataConfigBase& configBaseV1 = (*configBase)();
       
   697 	iSetConfigRequestHandle = aTsyReqHandle;
       
   698 	TInt err = KErrCorrupt;
       
   699 
       
   700 	if(configBaseV1.ExtensionId()==TPacketDataConfigBase::KConfigMBMS)
       
   701 		{
       
   702 		TPckg<RPacketMbmsContext::TContextConfigMbmsV1>* configMBMSPckg = (TPckg<RPacketMbmsContext::TContextConfigMbmsV1>*)aConfig;
       
   703 		RPacketMbmsContext::TContextConfigMbmsV1& configMBMS = (*configMBMSPckg)();
       
   704 
       
   705 		TMbmsConfigParams mbmsConfigParams;
       
   706 
       
   707 		mbmsConfigParams.iMCC = configMBMS.iTmgi.GetMCC();
       
   708 		mbmsConfigParams.iMNC = configMBMS.iTmgi.GetMNC();
       
   709 		mbmsConfigParams.iServiceId = configMBMS.iTmgi.GetServiceId() ;
       
   710 		mbmsConfigParams.iAccessBearer = configMBMS.iMbmsAccessBearer;
       
   711 		mbmsConfigParams.iServiceMode = configMBMS.iMbmsServiceMode;
       
   712 		mbmsConfigParams.iServicePriority = configMBMS.iMbmsServicePriority;
       
   713 
       
   714 		TUint index;
       
   715 		for(index=0; index < iMbmsContextConfigParams->Count(); index++)
       
   716 			{
       
   717 			TMbmsConfigParams thisConfig = iMbmsContextConfigParams->At(index);
       
   718 
       
   719 			if ((mbmsConfigParams.iAccessBearer != thisConfig.iAccessBearer) ||
       
   720 					(mbmsConfigParams.iServiceMode != thisConfig.iServiceMode) ||
       
   721 					(mbmsConfigParams.iServicePriority != thisConfig.iServicePriority) ||
       
   722 					(mbmsConfigParams.iMCC != thisConfig.iMCC) ||
       
   723 					(mbmsConfigParams.iMNC != thisConfig.iMNC) ||
       
   724 					(mbmsConfigParams.iServiceId != thisConfig.iServiceId))
       
   725 				{
       
   726 				err = KErrCorrupt;
       
   727 				}
       
   728 			else
       
   729 				{
       
   730 				err = KErrNone;
       
   731 				//Check for and complete any pending notifications
       
   732 				if(iNotifyConfigMBMS.iNotifyPending)
       
   733 					{
       
   734 					iNotifyConfigMBMS.iNotifyPending=EFalse;
       
   735 					RPacketMbmsContext::TContextConfigMbmsV1 *tempConfig = (RPacketMbmsContext::TContextConfigMbmsV1*)iNotifyConfigMBMS.iNotifyData;
       
   736 					tempConfig->iTmgi.SetServiceId(thisConfig.iServiceId);
       
   737 					tempConfig->iTmgi.SetMCC(thisConfig.iMCC);
       
   738 					tempConfig->iTmgi.SetMNC(thisConfig.iMNC);
       
   739 					tempConfig->iMbmsAccessBearer= thisConfig.iAccessBearer;
       
   740 					tempConfig->iMbmsServicePriority = thisConfig.iServicePriority;
       
   741 					tempConfig->iMbmsServiceMode = thisConfig.iServiceMode;
       
   742 					ReqCompleted(iNotifyConfigMBMS.iNotifyHandle,KErrNone);
       
   743 					}
       
   744 				break;
       
   745 				}
       
   746 			}
       
   747 		iSetConfigValues.iErrorValue = err;
       
   748 		iSetConfigValues.iIndex = index;
       
   749 		}
       
   750 	else
       
   751 		{ // not expected to reach here in case of MBMS context
       
   752 		TUint index=0;
       
   753 		iSetConfigValues.iErrorValue = err;
       
   754 		iSetConfigValues.iIndex = index;
       
   755 		}
       
   756 	iMbmsSetConfigTimer->Start(RandTime(),this,ETimerIdMbmsPcktContextSetConfig);
       
   757 
       
   758 	return KErrNone;
       
   759 	}
       
   760 
       
   761 TInt CSimMbmsPacketContext::SetConfigCancel(const TTsyReqHandle aTsyReqHandle)
       
   762 /**
       
   763 * Cancels the Setconfig request.
       
   764 * This method will do nothing in this version of SimTSY.
       
   765 * @param aTsyReqHandle Tsy Request handle for the client request
       
   766 * @return err KErrNone 
       
   767 */
       
   768 	{
       
   769 	iMbmsSetConfigTimer->Cancel();
       
   770 	ReqCompleted(aTsyReqHandle, KErrCancel);
       
   771 	return KErrNone;
       
   772 	}
       
   773 
       
   774 TInt CSimMbmsPacketContext::GetConfig(const TTsyReqHandle aTsyReqHandle,TDes8* aConfig)
       
   775 /**
       
   776 * Retrieves and returns the MBMS context configuration
       
   777 *
       
   778 * @param aTsyReqHandle Tsy Request handle for the client request
       
   779 * @param aConfig pointer to the configuration params to retrieve
       
   780 * @return KErrNone
       
   781 */
       
   782 	{
       
   783 	LOGPACKET1("CSimMbmsPacketContext::GetConfig called");
       
   784 	TPckg<TPacketDataConfigBase>* configBase = (TPckg<TPacketDataConfigBase>*)aConfig;
       
   785 	TPacketDataConfigBase& configBaseV1 = (*configBase)();
       
   786 	
       
   787 	if(configBaseV1.ExtensionId()==TPacketDataConfigBase::KConfigMBMS)
       
   788 		{
       
   789 
       
   790 		TPckg<RPacketMbmsContext::TContextConfigMbmsV1>* configMBMSPckg = (TPckg<RPacketMbmsContext::TContextConfigMbmsV1>*)aConfig;
       
   791 		RPacketMbmsContext::TContextConfigMbmsV1& configMBMS = (*configMBMSPckg)();
       
   792 		
       
   793 		configMBMS.iTmgi.SetServiceId(iMbmsContextConfigParams->At(iMbmsContextConfigParamsIndex).iServiceId);
       
   794 		configMBMS.iTmgi.SetMCC(iMbmsContextConfigParams->At(iMbmsContextConfigParamsIndex).iMCC);
       
   795 		configMBMS.iTmgi.SetMNC(iMbmsContextConfigParams->At(iMbmsContextConfigParamsIndex).iMNC);
       
   796 		configMBMS.iMbmsAccessBearer = reinterpret_cast<TMbmsScope&>(iMbmsContextConfigParams->At(iMbmsContextConfigParamsIndex).iAccessBearer);
       
   797 		configMBMS.iMbmsServicePriority = reinterpret_cast<TMbmsServicePriority&>(iMbmsContextConfigParams->At(iMbmsContextConfigParamsIndex).iServicePriority);
       
   798 		configMBMS.iMbmsServiceMode = reinterpret_cast<TMbmsServiceMode&>(iMbmsContextConfigParams->At(iMbmsContextConfigParamsIndex).iServiceMode);
       
   799 
       
   800 		ReqCompleted(aTsyReqHandle,KErrNone);
       
   801 		}
       
   802 	else
       
   803 		{
       
   804 		ReqCompleted(aTsyReqHandle,KErrNotSupported);
       
   805 		}
       
   806 
       
   807 	return KErrNone;
       
   808 	}
       
   809 
       
   810 TInt CSimMbmsPacketContext::GetConfigCancel(const TTsyReqHandle /*aTsyReqHandle*/)
       
   811 /**
       
   812 * Cancels the Getconfig request.  
       
   813 * This method will do nothing in this version of SimTSY.
       
   814 *
       
   815 * @param aTsyReqHandle Tsy Request handle for the client request
       
   816 * @return err KErrNone 
       
   817 */
       
   818 	{
       
   819 	LOGPACKET1("CSimMbmsPacketContext::GetConfigCancel called");
       
   820 	return KErrNone;
       
   821 	}
       
   822 
       
   823 TInt CSimMbmsPacketContext::GetStatus(const TTsyReqHandle aTsyReqHandle,RPacketContext::TContextStatus* aContextStatus)
       
   824 /**
       
   825 * Retrieves and returns the current status of the MBMS context 
       
   826 * 
       
   827 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
   828 * @param aContextStatus pointer to the status of the mbms packet context.
       
   829 * @return KerrNone
       
   830 */
       
   831 	{
       
   832 	LOGPACKET1("CSimMbmsPacketContext::GetStatus called");
       
   833 	*aContextStatus = iState;
       
   834 	ReqCompleted(aTsyReqHandle,KErrNone);
       
   835 	return KErrNone;
       
   836 	}
       
   837 
       
   838 TInt CSimMbmsPacketContext::Activate(const TTsyReqHandle aTsyReqHandle)
       
   839 /**
       
   840 * Client calls this method to try to Activate a mbms context.
       
   841 * In this method, we'll store the TsyReqHandle for later completion then call ActionEvent
       
   842 * state machine to handle the event which will kick off a timer.
       
   843 * The Actual Activation will take place in the TimerCallBack method.
       
   844 *
       
   845 * @param aTsyReqHandle Tsy Request handle for the client request
       
   846 * @return KErrNone
       
   847 */
       
   848 	{
       
   849 	iActivateRequestHandle = aTsyReqHandle;
       
   850 	TInt ret;
       
   851 	ret = ActionEvent(EMbmsContextEventActivate);
       
   852 	return ret;
       
   853 	}
       
   854 
       
   855 TInt CSimMbmsPacketContext::ActivateCancel(const TTsyReqHandle aTsyReqHandle)
       
   856 /**
       
   857 * Client calls this method to try and cancel an Activate request.
       
   858 * This will only complete successfully if and only if the Activate request 
       
   859 * has not completed.i.e. if we haven't already activated the context.
       
   860 * Otherwise, the request will be completed with KErrNone
       
   861 *
       
   862 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
   863 * @return KErrNone
       
   864 */
       
   865 	{
       
   866 	LOGPACKET1("CSimMbmsPacketContext::ActivateCancel called");
       
   867 	iMbmsContextTimer->Cancel();
       
   868 	if(((iState == RPacketContext::EStatusInactive) || (iState == RPacketContext::EStatusActivating)) && 
       
   869 					(iCurrentEvent==EMbmsContextEventActivate))
       
   870 		{
       
   871 		iCurrentEvent= EMbmsContextEventNone;
       
   872 		TInt ret = ChangeState(RPacketContext::EStatusInactive);
       
   873 		if(ret!= KErrNone)
       
   874 			{
       
   875 			ReqCompleted(aTsyReqHandle,ret);
       
   876 			}
       
   877 		else
       
   878 			{
       
   879 			ReqCompleted(aTsyReqHandle,KErrCancel);
       
   880 			}
       
   881 		}
       
   882 	else if (iState == RPacketContext::EStatusDeleted)
       
   883 		{
       
   884 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
   885 		}
       
   886 	else
       
   887 		{
       
   888 		ReqCompleted(aTsyReqHandle,KErrNone);
       
   889 		}
       
   890 
       
   891 	return KErrNone;
       
   892 	}
       
   893 
       
   894 TInt CSimMbmsPacketContext::Deactivate(const TTsyReqHandle aTsyReqHandle)
       
   895 /**
       
   896 * Client calls this method to try to Deactivate an active context.
       
   897 * In this method, we'll store the TsyReqHandle for later completion then call ActionEvent
       
   898 * state machine to handle the event which will kick off a timer.
       
   899 * The Actual Deactivation will take place in the TimerCallBack method.
       
   900 *
       
   901 * @param aTsyReqHandle Tsy Request handle for the client request
       
   902 * @return KErrNone
       
   903 */
       
   904 	{
       
   905 	LOGPACKET1("CSimMbmsPacketContext::Deactivate called");
       
   906 	iDeactivateRequestHandle = aTsyReqHandle;
       
   907 	TInt ret = ActionEvent(EMbmsContextEventDeactivate);
       
   908 	return ret;
       
   909 	}
       
   910 
       
   911 TInt CSimMbmsPacketContext::DeactivateCancel(const TTsyReqHandle aTsyReqHandle)
       
   912 /**
       
   913 * Client calls this method to try and cancel a Deactivate request.
       
   914 * This will only complete successfully if and only if the Deactivate request has not completed.
       
   915 * i.e. if we haven't already deactivated the context.
       
   916 * Otherwise, the request will be completed with KErrNone.
       
   917 * 
       
   918 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
   919 * @return KErrNone
       
   920 */
       
   921 	{
       
   922 	LOGPACKET1("CSimMbmsPacketContext::DeactivateCancel called");
       
   923 	iMbmsContextTimer->Cancel();
       
   924 	if(((iState == RPacketContext::EStatusInactive) || (iState == RPacketContext::EStatusDeactivating)) && 
       
   925 					(iCurrentEvent==EMbmsContextEventDeactivate))
       
   926 		{
       
   927 		iCurrentEvent= EMbmsContextEventNone;
       
   928 		TInt ret = ChangeState(RPacketContext::EStatusActive);
       
   929 		if(ret!= KErrNone)
       
   930 			{
       
   931 			ReqCompleted(aTsyReqHandle,ret);
       
   932 			}
       
   933 		else
       
   934 			{
       
   935 			ReqCompleted(aTsyReqHandle,KErrCancel);
       
   936 			}
       
   937 		}
       
   938 	else
       
   939 		{
       
   940 		ReqCompleted(aTsyReqHandle,KErrNone);
       
   941 		}
       
   942 	
       
   943 	return KErrNone;
       
   944 	}
       
   945 
       
   946 TInt CSimMbmsPacketContext::ReActivate(CSimPacketService* aPacketService, const TName& aContextName)
       
   947 /**
       
   948 * This method is called by the packet Service to Re-Initialise a Deleted context.
       
   949 * If the context is deleted then the client cannot retrieve any 
       
   950 * infomation or use the context in any way.
       
   951 * In order for the client to use the context again, the client must 
       
   952 * open an object by name passing the name of this context as a pararemter.
       
   953 *
       
   954 * @param aPacketService pointer to the parent class CSimPacketService.
       
   955 * @param aContextName Must be the same name as the name for this context.
       
   956 * @return KErrNone if no problem in re-initialising this context.
       
   957 */
       
   958 	{
       
   959 	if(iContextName.Compare(aContextName) != KErrNone)
       
   960 		{
       
   961 		return KErrBadName;
       
   962 		}
       
   963 
       
   964 	iPacketService = aPacketService;
       
   965 
       
   966 	if(iDeleted)
       
   967 		{
       
   968 		TInt ret = ChangeState(RPacketContext::EStatusInactive);
       
   969 		if (ret != KErrNone)
       
   970 			{
       
   971 			return ret;
       
   972 			}
       
   973 
       
   974 		iDeleted = EFalse;
       
   975 		iMbmsContextConfigParamsIndex = 0;
       
   976 		iNotifyStatusChange.iNotifyPending = EFalse;
       
   977 		iNotifyConfigMBMS.iNotifyPending = EFalse;
       
   978 		}
       
   979 	return KErrNone;
       
   980 	}
       
   981 
       
   982 TInt CSimMbmsPacketContext::Delete(const TTsyReqHandle aTsyReqHandle)
       
   983 /**
       
   984 * Client calls this method to try to Delete this context.
       
   985 * In this method, we'll store the TsyReqHandle for later completion then call ActionEvent
       
   986 * state machine to handle the event which will kick off a timer.
       
   987 * The Actual Delete will take place in the TimerCallBack method.
       
   988 *
       
   989 * This request will only succeed if the context already exist (had been created) and also not
       
   990 * previously deleted.
       
   991 *
       
   992 * @param aTsyReqHandle Tsy Request handle for the client request
       
   993 * @return KErrNone
       
   994 */
       
   995 	{
       
   996 	LOGPACKET1("CSimMbmsPacketContext::Delete called");
       
   997 	iDeleteRequestHandle = aTsyReqHandle;
       
   998 	TInt ret = ActionEvent(EMbmsContextEventDelete);
       
   999 	return ret;
       
  1000 	}
       
  1001 
       
  1002 TInt CSimMbmsPacketContext::DeleteCancel(const TTsyReqHandle aTsyReqHandle)
       
  1003 /**
       
  1004 * Client calls this method to try and cancel a Delete context request.
       
  1005 * This will only complete successfully if and only if the Delete request has not completed.
       
  1006 * i.e. if we haven't already Deleted the context.
       
  1007 *
       
  1008 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  1009 * @return KErrNone
       
  1010 */
       
  1011 	{
       
  1012 	LOGPACKET1("CSimMbmsPacketContext::DeleteCancel called");
       
  1013 	iMbmsContextTimer->Cancel();
       
  1014 	if((iState == RPacketContext::EStatusInactive) && (iCurrentEvent==EMbmsContextEventDelete))
       
  1015 		{
       
  1016 		iCurrentEvent= EMbmsContextEventNone;
       
  1017 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  1018 		}
       
  1019 	return KErrNone;
       
  1020 	}
       
  1021 
       
  1022 TInt CSimMbmsPacketContext::GetLastErrorCause(const TTsyReqHandle aTsyReqHandle,TInt* /*aError*/)
       
  1023 /**
       
  1024 * This method is supported in only for the MBMS Packet Context
       
  1025 *
       
  1026 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1027 * @param aError pointer to the last error cause
       
  1028 * @return KerrNone
       
  1029 */
       
  1030 	{
       
  1031 	LOGPACKET1("CSimMbmsPacketContext::GetLastErrorCause called");
       
  1032 	
       
  1033 	ReqCompleted(aTsyReqHandle,iLastError);
       
  1034 	return KErrNone;
       
  1035 	}
       
  1036 
       
  1037 
       
  1038 TInt CSimMbmsPacketContext::NotifyConfigChanged(const TTsyReqHandle aTsyReqHandle, TDes8* aConfig)
       
  1039 /**
       
  1040 * Records a client interest in being notified of a change in the Context Configuration.
       
  1041 *
       
  1042 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1043 * @param aConfig pointer to the context config to store the config info when the config changes.
       
  1044 * @return KErrNone
       
  1045 */
       
  1046 	{
       
  1047 	LOGPACKET1("CSimMbmsPacketContext::NotifyConfigChanged called");
       
  1048 	TPckg<TPacketDataConfigBase>* configBase = (TPckg<TPacketDataConfigBase>*)aConfig;
       
  1049 	TPacketDataConfigBase& configBaseV1 = (*configBase)();
       
  1050 	
       
  1051 	if(configBaseV1.ExtensionId() == TPacketDataConfigBase::KConfigMBMS)
       
  1052 		{
       
  1053 	    __ASSERT_ALWAYS(!iNotifyConfigMBMS.iNotifyPending,SimPanic(ENotificationAlreadyPending));
       
  1054 
       
  1055 	    iNotifyConfigMBMS.iNotifyPending = ETrue;
       
  1056 	    iNotifyConfigMBMS.iNotifyHandle = aTsyReqHandle;
       
  1057 	    iNotifyConfigMBMS.iNotifyData = &configBaseV1;
       
  1058 		}
       
  1059 	else
       
  1060 		{
       
  1061 		LOGPACKET1("CSimMbmsPacketContext::NotifyConfigChanged Unexpected config for MBMS context");
       
  1062 		}
       
  1063 
       
  1064 	return KErrNone;
       
  1065 	}
       
  1066 
       
  1067 TInt CSimMbmsPacketContext::NotifyConfigChangedCancel(const TTsyReqHandle aTsyReqHandle)
       
  1068 /**
       
  1069 * Cancel a client's interest in being notified when the context configuration changes
       
  1070 * This is acheived simply by resetting the flag that indicates a notification is pending.
       
  1071 * 
       
  1072 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  1073 * @return KErrNone
       
  1074 */
       
  1075 	{
       
  1076 	LOGPACKET1("CSimMbmsPacketContext::NotifyConfigChangedCancel called");
       
  1077 	if(iNotifyConfigMBMS.iNotifyPending &&
       
  1078 		iNotifyConfigMBMS.iNotifyHandle == aTsyReqHandle)
       
  1079 		{
       
  1080 		iNotifyConfigMBMS.iNotifyPending=EFalse;
       
  1081 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  1082 		}
       
  1083 	else
       
  1084 		{
       
  1085 		ReqCompleted(aTsyReqHandle,KErrNone);
       
  1086 		}
       
  1087 		
       
  1088 	return KErrNone;
       
  1089 	}
       
  1090 
       
  1091 TInt CSimMbmsPacketContext::NotifyStatusChange(const TTsyReqHandle aTsyReqHandle,RPacketContext::TContextStatus* aContextStatus)
       
  1092 /**
       
  1093 * Record a client's interest in being notified of the state of the packet contexts.
       
  1094 * First check that there isn't already a notification pending (the ETel Server should protect
       
  1095 * against this) and then record the information necessary to complete the request later, when
       
  1096 * the status does actually change.
       
  1097 *
       
  1098 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1099 * @param aContextStatus pointer to the packet context status
       
  1100 * @return KErrNone
       
  1101 */
       
  1102 	{
       
  1103 	LOGPACKET1("CSimMbmsPacketContext::NotifyStatusChange called");
       
  1104 	__ASSERT_ALWAYS(!iNotifyStatusChange.iNotifyPending,SimPanic(ENotificationAlreadyPending));
       
  1105 	iNotifyStatusChange.iNotifyPending = ETrue;
       
  1106 	iNotifyStatusChange.iNotifyHandle = aTsyReqHandle;
       
  1107 	iNotifyStatusChange.iNotifyData = aContextStatus;
       
  1108 	return KErrNone;
       
  1109 	}
       
  1110 
       
  1111 TInt CSimMbmsPacketContext::NotifyStatusChangeCancel(const TTsyReqHandle aTsyReqHandle)
       
  1112 /**
       
  1113 * Cancel a client's interest in being notified when the packet context status changes.
       
  1114 * This is acheived simply by resetting the flag that indicates a notification is pending.
       
  1115 * 
       
  1116 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  1117 * @return KErrNone
       
  1118 */
       
  1119 	{
       
  1120 	LOGPACKET1("CSimMbmsPacketContext::NotifyStatusChangeCancel called");
       
  1121 	if(iNotifyStatusChange.iNotifyPending)
       
  1122 		{
       
  1123 		iNotifyStatusChange.iNotifyPending=EFalse;
       
  1124 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  1125 		}
       
  1126 	else
       
  1127 		{
       
  1128 		ReqCompleted(aTsyReqHandle,KErrNone);
       
  1129 		}
       
  1130 	return KErrNone;
       
  1131 	}
       
  1132 
       
  1133 TInt CSimMbmsPacketContext::UpdateMbmsSessionListL(const TTsyReqHandle aTsyReqHandle,TMbmsAction* aAction, TUint* aSessionId)
       
  1134 /**
       
  1135 * client's interest in updating the MBMS session's list.
       
  1136 * This is achieved  by updating the list maintained internally by the context
       
  1137 * 
       
  1138 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1139 * @param aAction TMbmsAction - ADD/ REMOVE / REMOVE_ALL
       
  1140 * @param aSessionId sessoinID to be used for the updation.
       
  1141 * @return KErrNone
       
  1142 */
       
  1143 	{
       
  1144 	LOGPACKET1("CSimMbmsPacketContext::UpdateMbmsSessionListL called");
       
  1145 
       
  1146 	TInt error=KErrNone;
       
  1147 	iUpdateSessionHandle = aTsyReqHandle;
       
  1148 	TKeyArrayFix key(0, ECmpTUint);
       
  1149 	TInt position =-1;
       
  1150 
       
  1151 	switch(*aAction)
       
  1152 		{
       
  1153 		case SIMTSY_PACKET_MBMS_ADD_ENTRIES:
       
  1154 			LOGPACKET1("CSimMbmsPacketContext::UpdateMbmsSessionListL Action: ADD ");
       
  1155 			TRAP(error,iSessionIdList->AppendL(*aSessionId));
       
  1156 			if(error == KErrNone)
       
  1157 				{
       
  1158 				//iSessionIdList->At(0) = ++iNumOfSessionId;
       
  1159 				iSessionIdList->Delete(0);
       
  1160 				iSessionIdList->InsertL(0,++iNumOfSessionId);
       
  1161 				iMbmsUpdateSessionTimer->Start(RandTime(),this,ETimerIdMbmsUpdateSessionId);
       
  1162 				}
       
  1163 			else
       
  1164 				{
       
  1165 				ReqCompleted(iUpdateSessionHandle,error);
       
  1166 				}
       
  1167 			break;
       
  1168 
       
  1169 		case SIMTSY_PACKET_MBMS_REM_ENTRIES:
       
  1170 			LOGPACKET1("CSimMbmsPacketContext::UpdateMbmsSessionListL Action: REMOVE ");
       
  1171 			iSessionIdList->Find(*aSessionId,key,position);
       
  1172 			if(position != -1)
       
  1173 				{
       
  1174 				iSessionIdList->Delete(position);
       
  1175 				//iSessionIdList->At(0) = --iNumOfSessionId;
       
  1176 				iSessionIdList->InsertL(0,--iNumOfSessionId);
       
  1177 				iMbmsUpdateSessionTimer->Start(RandTime(),this,ETimerIdMbmsUpdateSessionId);
       
  1178 				}
       
  1179 			else
       
  1180 				{
       
  1181 				error = KErrNotFound;
       
  1182 				ReqCompleted(iUpdateSessionHandle,error);
       
  1183 				}
       
  1184 			break;
       
  1185 
       
  1186 		case SIMTSY_PACKET_MBMS_REM_ALL_ENTRIES:
       
  1187 			LOGPACKET1("CSimMbmsPacketContext::UpdateMbmsSessionListL Action: REMOVE_ALL ");
       
  1188 			iNumOfSessionId=0;
       
  1189 			//iSessionIdList->At(0) = iNumOfSessionId;
       
  1190 			iSessionIdList->InsertL(0,iNumOfSessionId);
       
  1191 			iSessionIdList->Delete(1,iSessionIdList->Count()); // removing all session ids from the list
       
  1192 			ReqCompleted(aTsyReqHandle, KErrNone);
       
  1193 			break;
       
  1194 
       
  1195 		default:
       
  1196 			LOGPACKET1("CSimMbmsPacketContext::UpdateMbmsSessionListL Action: Default ");
       
  1197 			ReqCompleted(aTsyReqHandle,KErrNotFound);
       
  1198 			break;
       
  1199 		}
       
  1200 	return KErrNone;
       
  1201 	}
       
  1202 
       
  1203 TInt CSimMbmsPacketContext::UpdateMbmsSessionListCancel(const TTsyReqHandle aTsyReqHandle)
       
  1204 /**
       
  1205 * client's interest in cancelling the updation the MBMS session's list.
       
  1206 * 
       
  1207 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  1208 * @return KErrNone
       
  1209 */
       
  1210 	{
       
  1211 	LOGPACKET1("CSimMbmsPacketContext::UpdateMbmsSessionListCancel called");
       
  1212 	iMbmsUpdateSessionTimer->Cancel();
       
  1213 	if( iUpdateSessionHandle == aTsyReqHandle )
       
  1214 		{
       
  1215 		ReqCompleted(iUpdateSessionHandle,KErrCancel);
       
  1216 		iUpdateSessionHandle=NULL;
       
  1217 		}
       
  1218 	else
       
  1219 		{
       
  1220 		ReqCompleted(iUpdateSessionHandle,KErrNone);
       
  1221 		}
       
  1222 	return KErrNone;
       
  1223 	}
       
  1224 
       
  1225 TInt CSimMbmsPacketContext::InitialiseContext(const TTsyReqHandle aTsyReqHandle, TDes8* aDataChannelV2Pckg)
       
  1226 /**
       
  1227 * client's interest in Initialising the context.
       
  1228 * 
       
  1229 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1230 * @param aDataChannelV2Pckg the information to be filled once the initialisation is complete.
       
  1231 * @return KErrNone
       
  1232 */
       
  1233 	{
       
  1234 	TCommSetupItem item = FindCommSettings();
       
  1235 	iInitContextData.iTsyReqHandle = aTsyReqHandle;
       
  1236 	iInitContextData.iChannel = aDataChannelV2Pckg;
       
  1237 	iMbmsContextInitTimer->Start(RandTime(), this, ETimerIdPcktContextInitContext);
       
  1238 
       
  1239 	return KErrNone;
       
  1240 	}
       
  1241 	
       
  1242 TInt CSimMbmsPacketContext::DoInitialiseContext()
       
  1243 /* Function completes the request from the client for the initialisation of the context.
       
  1244  * Called when the timer event occurs after receiving the InitialiseContext request.
       
  1245  * returns KErrNone.
       
  1246  */
       
  1247 	{
       
  1248 	RPacketContext::TDataChannelV2Pckg* channel = (RPacketContext::TDataChannelV2Pckg*)iInitContextData.iChannel;
       
  1249 	RPacketContext::TDataChannelV2& channelV2 = (*channel)();
       
  1250 
       
  1251 	// Check that the data structure is supported by the simulated TSY version
       
  1252 	TInt err = iPhone->CheckSimTsyVersion(channelV2);
       
  1253 	if(err != KErrNone)
       
  1254 		{
       
  1255 		ReqCompleted(iInitContextData.iTsyReqHandle, err);
       
  1256 		return KErrNone;
       
  1257 		}
       
  1258 
       
  1259 	TCommSetupItem item = FindCommSettings();
       
  1260 	channelV2.iPort = item.iPortName;
       
  1261 	channelV2.iCsy = item.iCsyName;
       
  1262 	channelV2.iChannelId = item.iPortName;
       
  1263 	
       
  1264 	ReqCompleted(iInitContextData.iTsyReqHandle, KErrNone);
       
  1265 
       
  1266 	return KErrNone;
       
  1267 	}
       
  1268 
       
  1269 TInt CSimMbmsPacketContext::InitialiseContextCancel(const TTsyReqHandle aTsyReqHandle)
       
  1270 /**
       
  1271 * client's interest in cancelling the Initialisation of the MBMS Context.
       
  1272 * 
       
  1273 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  1274 * @return KErrNone
       
  1275 */
       
  1276 	{
       
  1277 	iMbmsContextInitTimer->Cancel();
       
  1278 	ReqCompleted(aTsyReqHandle, KErrCancel);
       
  1279 	
       
  1280 	return KErrNone;
       
  1281 	}
       
  1282 
       
  1283 TInt CSimMbmsPacketContext::GetMbmsSessionsPhase1(const TTsyReqHandle aTsyReqHandle, TClientId* aClient, TInt* aBufSize)
       
  1284 /**
       
  1285 * client's interest in retrieving the MBMS Session information.
       
  1286 * This is the phase1 retrieval
       
  1287 * 
       
  1288 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1289 * @param aClient ClientId from which the request is sent
       
  1290 * @param aBufSize  Size of the buffer to be allocated to retrieve the data in phase2.
       
  1291 * @return KErrNone
       
  1292 */
       
  1293 	{
       
  1294 	LOGPACKET1("CSimMbmsPacketContext::GetMbmsSessionsPhase1 called");
       
  1295 	iGetMbmsSessionHandle = aTsyReqHandle;
       
  1296 	TInt ret=KErrNone;
       
  1297 	TInt leaveCode=KErrNone;
       
  1298 	TRAP(leaveCode, ret=ProcessGetMbmsSessionsPhase1L(aTsyReqHandle, aClient, aBufSize););
       
  1299 	if (leaveCode != KErrNone)
       
  1300 		{
       
  1301 		ReqCompleted(aTsyReqHandle,leaveCode);
       
  1302 		}
       
  1303 	return ret;
       
  1304 	}	
       
  1305 
       
  1306 TInt CSimMbmsPacketContext::ProcessGetMbmsSessionsPhase1L(const TTsyReqHandle aTsyReqHandle, 
       
  1307 													 TClientId* aClient, 
       
  1308 													 TInt* aBufSize)
       
  1309 /**
       
  1310 * The Actual function which does the phase1 retrieval.
       
  1311 * 
       
  1312 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1313 * @param aClient ClientId from which the request is sent
       
  1314 * @param aBufSize  Size of the buffer to be allocated to retrieve the data in phase2.
       
  1315 * @return KErrNone
       
  1316 */
       
  1317 	{
       
  1318 	// Retrieve MBMS session list,
       
  1319 	// Store the sessions and then return the size of the buffer to the client
       
  1320 	LOGPACKET1("CSimMbmsPacketContext::ProcessGetMbmsSessionsPhase1L called");
       
  1321 	RPacketMbmsContext::CMbmsSession* mbmsSession=RPacketMbmsContext::CMbmsSession::NewL();
       
  1322 	CleanupStack::PushL(mbmsSession);
       
  1323 
       
  1324 	for(TInt i=1;i<=iNumOfSessionId;i++)
       
  1325 		{
       
  1326 		mbmsSession->iSessionIdList.Append(iSessionIdList->At(i));
       
  1327 		}
       
  1328 
       
  1329 	
       
  1330 	// Store the streamed list and the client ID
       
  1331 	CPcktListReadAllAttempt* read = CPcktListReadAllAttempt::NewL(*aClient,aTsyReqHandle);
       
  1332 	CleanupStack::PushL(read);
       
  1333 	
       
  1334 	HBufC8* iBuff=NULL;
       
  1335 	mbmsSession->ExternalizeL(iBuff);	
       
  1336 	CleanupStack::PushL(iBuff);
       
  1337 		
       
  1338 	CBufFlat* buf=CBufFlat::NewL(iBuff->Length());
       
  1339 	CleanupStack::PushL(buf);
       
  1340 	buf->InsertL(0,*iBuff);	
       
  1341 	
       
  1342 	read->iListBuf = buf;
       
  1343 	CleanupStack::Pop(buf);	
       
  1344 	CleanupStack::PopAndDestroy(iBuff);
       
  1345 	
       
  1346 	iMbmsSessionList->AppendL(read);
       
  1347 	CleanupStack::Pop(); // pop the CListReadAllAttempt
       
  1348 	
       
  1349 	// return the CBufBase’s size to client
       
  1350 	*aBufSize=(read->iListBuf)->Size();
       
  1351 	CleanupStack::PopAndDestroy(mbmsSession);
       
  1352 	
       
  1353 	// Complete first phase of list retrieval
       
  1354 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  1355 	return KErrNone;
       
  1356 	}
       
  1357 
       
  1358 TInt CSimMbmsPacketContext::GetMbmsSessionsPhase2(const TTsyReqHandle aTsyReqHandle,TClientId* aClient, TDes8* aBuf)
       
  1359 /**
       
  1360 * client's interest in retrieving the MBMS Session information.
       
  1361 * This is the phase2 retrieval
       
  1362 * 
       
  1363 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1364 * @param aClient ClientId from which the request is sent
       
  1365 * @param aBuf  Buffer allocated to retrieve the data.
       
  1366 * @return KErrNone
       
  1367 */
       
  1368 	{
       
  1369 	LOGPACKET1("CSimMbmsPacketContext::GetMbmsSessionsPhase2 called");
       
  1370 	CPcktListReadAllAttempt* read=NULL;
       
  1371 	// Find the get Mbms monitored services from this client
       
  1372 	for (TInt i=0; i<iMbmsSessionList->Count(); ++i)
       
  1373 		{
       
  1374 		read = iMbmsSessionList->At(i);
       
  1375 		if ((read->iClient.iSessionHandle==aClient->iSessionHandle) &&
       
  1376 		    (read->iClient.iSubSessionHandle==aClient->iSubSessionHandle))
       
  1377 			{
       
  1378 			TPtr8 bufPtr((read->iListBuf)->Ptr(0));
       
  1379 			// Copy the streamed list to the client
       
  1380 			aBuf->Copy(bufPtr);
       
  1381 			delete read;
       
  1382 			iMbmsSessionList->Delete(i);
       
  1383 			ReqCompleted(aTsyReqHandle,KErrNone);
       
  1384 			return KErrNone;
       
  1385 			}
       
  1386 		}
       
  1387 	// Should handle error case of not finding the matching client from read all phase 1
       
  1388 	ReqCompleted(aTsyReqHandle,KErrBadHandle);
       
  1389 	return KErrNone;
       
  1390 	}
       
  1391 	
       
  1392 TInt CSimMbmsPacketContext::GetMbmsSessionsCancel(const TTsyReqHandle aTsyReqHandle)
       
  1393 /**
       
  1394 * client's interest in cancelling the MBMS Get session request.
       
  1395 * 
       
  1396 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1397 * @return KErrNone
       
  1398 */
       
  1399 	{
       
  1400 	LOGPACKET1("CSimMbmsPacketContext::GetMbmsSessionsCancel called");
       
  1401 	// Remove the MBMS sessions from iMbmsSessionList
       
  1402 	
       
  1403 	CPcktListReadAllAttempt* read=NULL;
       
  1404 	for (TInt i=0; i<iMbmsSessionList->Count(); ++i)
       
  1405 		{
       
  1406 		read = iMbmsSessionList->At(i);
       
  1407 		if (read->iReqHandle == aTsyReqHandle)
       
  1408 			{
       
  1409 			delete read;
       
  1410 			iMbmsSessionList->Delete(i);
       
  1411 			break;
       
  1412 			}
       
  1413 		}
       
  1414 	ReqCompleted(aTsyReqHandle,KErrCancel);
       
  1415 	return KErrNone;
       
  1416 	}
       
  1417 
       
  1418 TInt CSimMbmsPacketContext::ChangeState(RPacketContext::TContextStatus aNewState)
       
  1419 /**
       
  1420 * Attempt to change state.
       
  1421 * First validate that the requested state change is ok.  If it is then proceed to change
       
  1422 * the state and complete any pending state change notification.
       
  1423 *
       
  1424 * @param aNewState the new state to change to
       
  1425 * @return Error indication if change of state is successful or not
       
  1426 */
       
  1427 	{
       
  1428 	LOGPACKET2("CSimMbmsPacketContext::ChangeState [newState=%d]", aNewState);
       
  1429 	__ASSERT_ALWAYS(aNewState!=RPacketContext::EStatusUnknown,SimPanic(ECallStatusUnknownIllegal));
       
  1430 
       
  1431 	if(iState==aNewState)
       
  1432 		return KErrNone;
       
  1433 
       
  1434 	TInt ret=KErrGeneral;
       
  1435 	const struct TMbmsContextStateChangeValidity* stateChangePnt=KMbmsContextStateChangeValidity;
       
  1436 	while(stateChangePnt->iOldState!=KMbmsContextStateTableTerminator)
       
  1437 		{
       
  1438 		if(stateChangePnt->iOldState == RPacketContext::EStatusReceiving && stateChangePnt->iNewState == RPacketContext::EStatusActive)
       
  1439 			{
       
  1440 			iLastError = KErrMbmsNotSupported;
       
  1441 			}
       
  1442 		else if(stateChangePnt->iOldState == RPacketContext::EStatusReceiving && stateChangePnt->iNewState == RPacketContext::EStatusSuspended)
       
  1443 			{
       
  1444 			iLastError = KErrMbmsServicePreempted;
       
  1445 			}
       
  1446 		else if(stateChangePnt->iOldState == RPacketContext::EStatusSuspended && stateChangePnt->iNewState == RPacketContext::EStatusActive)
       
  1447 			{
       
  1448 			iLastError = KErrMbmsServiceUnavailable;
       
  1449 			}
       
  1450 		if((stateChangePnt->iOldState==iState) && (stateChangePnt->iNewState==aNewState))
       
  1451 			{
       
  1452 			ret=stateChangePnt->iError;
       
  1453 			break;
       
  1454 			}
       
  1455 		stateChangePnt++;
       
  1456 		}
       
  1457 
       
  1458 	if(ret!=KErrNone)
       
  1459 		return ret;
       
  1460 
       
  1461 	//Request permission from the phone to change the state of the packet connection
       
  1462 	ret = iPacketService->ChangeState(ConvertToPacketServiceStatus(aNewState));
       
  1463 	if(ret!=KErrNone)
       
  1464 		return ret;
       
  1465 
       
  1466 	// Actually change the state.
       
  1467 	iState=aNewState;
       
  1468 
       
  1469 	// Check for a pending line state notification.
       
  1470 	if(iNotifyStatusChange.iNotifyPending)
       
  1471 		{
       
  1472 		iNotifyStatusChange.iNotifyPending = EFalse;
       
  1473 		*(RPacketContext::TContextStatus*)iNotifyStatusChange.iNotifyData = iState;
       
  1474 		ReqCompleted(iNotifyStatusChange.iNotifyHandle,KErrNone);
       
  1475 		}
       
  1476 
       
  1477 	LOGPACKET1("<<CSimMbmsPacketContext::ChangeState Completed");
       
  1478 	return KErrNone;
       
  1479 	}
       
  1480 
       
  1481 TInt CSimMbmsPacketContext::ActionEvent(TMbmsContextEvent aEvent)
       
  1482 /**
       
  1483 * Entry point when an event has occured that may advance the state machine.
       
  1484 * The aEvent parameter describes the event.
       
  1485 *
       
  1486 * This function contains the main state machine for the packet Context.  
       
  1487 *
       
  1488 * @param aEvent The Packet Context event to handle
       
  1489 * @return value represents the error state caused by the attempted state machine jump.
       
  1490 */
       
  1491 	{
       
  1492 	LOGPACKET1("<<CSimMbmsPacketContext::ActionEvent Completed");
       
  1493 	TInt ret=KErrNone;
       
  1494 	__ASSERT_ALWAYS(iState!=RPacketContext::EStatusUnknown,SimPanic(ECallStatusUnknownIllegal));
       
  1495 
       
  1496 	switch(aEvent)
       
  1497 		{
       
  1498 		case EMbmsContextEventActivate:
       
  1499 			LOGPACKET1("CSimMbmsPacketContext::ActionEvent = [EMbmsContextEventActivate]");
       
  1500 			if(iState==RPacketContext::EStatusInactive)
       
  1501 				{
       
  1502 				iCurrentEvent=EMbmsContextEventActivate;
       
  1503 				ret = ChangeState(RPacketContext::EStatusActivating);
       
  1504 				iMbmsContextTimer->Start(RandTime(),this);  
       
  1505 				}
       
  1506 			else
       
  1507 				{
       
  1508 				ReqCompleted(iActivateRequestHandle, KErrGprsActivationRejected);
       
  1509 				}
       
  1510 			break;
       
  1511 
       
  1512 		case EMbmsContextEventDeactivate:
       
  1513 			LOGPACKET1("CSimMbmsPacketContext::ActionEvent = [EMbmsContextEventDeactivate]");
       
  1514 			if(iState==RPacketContext::EStatusActive || iState==RPacketContext::EStatusActivating)
       
  1515 				{
       
  1516 				iCurrentEvent=EMbmsContextEventDeactivate;
       
  1517 				ret = ChangeState(RPacketContext::EStatusDeactivating);
       
  1518 				iMbmsContextTimer->Start(RandTime(),this);
       
  1519 				}
       
  1520 			else
       
  1521 				{
       
  1522 				ReqCompleted(iDeactivateRequestHandle, KErrNone);
       
  1523 				}
       
  1524 			break;
       
  1525 
       
  1526 		case EMbmsContextEventDelete:
       
  1527 			LOGPACKET1("CSimMbmsPacketContext::ActionEvent = [EMbmsContextEventDelete]");
       
  1528 			iDeleted = ETrue;
       
  1529 			if(iState==RPacketContext::EStatusInactive)
       
  1530 				{
       
  1531 				iCurrentEvent=EMbmsContextEventDelete;
       
  1532 				iMbmsContextTimer->Start(RandTime(),this);
       
  1533 				}
       
  1534 			else
       
  1535 				ReqCompleted(iDeleteRequestHandle, KErrInUse);
       
  1536 			break;
       
  1537 		default:
       
  1538 			LOGPACKET1("CSimMbmsPacketContext::ActionEvent = [Default Case]");
       
  1539 			break;
       
  1540 		}
       
  1541 	return ret;
       
  1542 	}
       
  1543 
       
  1544 RPacketService::TStatus CSimMbmsPacketContext::ConvertToPacketServiceStatus(RPacketContext::TContextStatus aNewState)
       
  1545 /**
       
  1546 * Converts Packet Context Status (RPacketContext::TContextStatus) to 
       
  1547 *          Packet Service Status (RPacketService::TStatus)
       
  1548 *
       
  1549 * @param aNewState the Context status to convert to packet service status
       
  1550 * @return RPacketService::TStatus The packet service status conversion
       
  1551 */
       
  1552 	{
       
  1553 	LOGPACKET1("CSimMbmsPacketContext::ConvertToPacketServiceStatus called");
       
  1554 	RPacketService::TStatus serviceStatus;
       
  1555 	switch (aNewState)
       
  1556 		{
       
  1557 		case RPacketContext::EStatusInactive:
       
  1558 		case RPacketContext::EStatusActivating:
       
  1559 		case RPacketContext::EStatusDeleted:
       
  1560 			serviceStatus = RPacketService::EStatusAttached;
       
  1561 			break;
       
  1562 		case RPacketContext::EStatusActive:
       
  1563 		case RPacketContext::EStatusDeactivating:
       
  1564 			serviceStatus = RPacketService::EStatusActive;
       
  1565 			break;
       
  1566 		case RPacketContext::EStatusSuspended:
       
  1567 			serviceStatus = RPacketService::EStatusSuspended;
       
  1568 			break;
       
  1569 		default:
       
  1570 			serviceStatus = RPacketService::EStatusUnattached;
       
  1571 			break;
       
  1572 		}
       
  1573 	return serviceStatus;
       
  1574 	}
       
  1575 
       
  1576 TInt CSimMbmsPacketContext::RandTime()
       
  1577 /* 
       
  1578  * Function that generates time(in seconds) at random for the SimTSY 
       
  1579  * Maximum of four seconds; zero seconds also included just to simulate the 
       
  1580  * synchronous call scenario 
       
  1581  */
       
  1582 	{
       
  1583 	LOGPACKET1("CSimMbmsPacketContext::RandTime called");
       
  1584 	TInt ranT= Math::Random()%4; 
       
  1585 	return(ranT);
       
  1586 	}