telephonyserverplugins/simtsy/src/CSimPacketService.cpp
changeset 0 3553901f7fa8
child 19 630d2f34d719
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2001-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 // implementattion for CSimPacketService Class
       
    15 // This file contains the implementation of the Similator TSY Packet Service functionality.  
       
    16 // CSimPacketService class provides a simulated packet-switched connection to a packet 
       
    17 // (GPRS and CDMA) network.
       
    18 // 
       
    19 //
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include "CSimPacketService.h"
       
    26 #include "Simlog.h"
       
    27 #include <pcktcs.h>
       
    28 #include "CSimPhone.h"
       
    29 #include "utils.h"
       
    30 #include "CSimPacketContext.h"
       
    31 #include "CSimPubSubChange.h"
       
    32 
       
    33 
       
    34 #include "CSimIncomingContextManager.h"
       
    35 
       
    36 
       
    37 _LIT(KApn, "ACME INTERNET PROVIDERS LTD");
       
    38 _LIT(KProtocolAddress, "i-MODE GATEWAY");
       
    39 _LIT(KUsername, "USER1");
       
    40 _LIT(KPassword, "PASSWORD1");
       
    41 _LIT(KChallenge, "CHALLENGE1");
       
    42 _LIT(KResponse, "RESPONSE1");
       
    43 _LIT(KPrimaryDNS, "PRIMARYSERVER1");
       
    44 _LIT(KSecondaryDNS, "SECONDARYSERVER1");
       
    45 
       
    46 
       
    47 // enum for caps
       
    48 const TUint KPacketServiceCaps=(RPacketService::KCapsSuspendSupported |
       
    49 								RPacketService::KCapsMSClassSupported |
       
    50 								RPacketService::KCapsCDMA2000HighSpeedDataSupported |
       
    51 								RPacketService::KCapsNetworkAvailabilitySupported |
       
    52 								RPacketService::KCapsProtocolPPPSupported |
       
    53 								RPacketService::KCapsHSDPASupported |
       
    54 								RPacketService::KCapsEGPRSSupported |
       
    55 								RPacketService::KCapsHSUPASupported );
       
    56 								 
       
    57 CSimPacketService* CSimPacketService::NewL(CSimPhone* aPhone)
       
    58 /**
       
    59 * Standard two phase constructor
       
    60 *
       
    61 * @param aPhone Pointer to the phone object (CSimPhone)
       
    62 * @return CSimPacketService pointer to the packet service object created.
       
    63 * @leave Leaves if no memory or object is not created for any reason.
       
    64 */
       
    65 	{
       
    66 	CSimPacketService* simPacket=new(ELeave) CSimPacketService(aPhone);
       
    67 	CleanupStack::PushL(simPacket);
       
    68 	simPacket->ConstructL();
       
    69 	CleanupStack::Pop();
       
    70 	return simPacket;
       
    71 	}
       
    72 
       
    73 void CSimPacketService::Init()
       
    74 	{}
       
    75 
       
    76 CSimPacketService::CSimPacketService(CSimPhone* aPhone)
       
    77 	: iPhone(aPhone), iContextCount(0), iPrimaryContextNameInc(0),
       
    78 	  iSecondaryContextNameInc(0), iAttachMode(RPacketService::EAttachWhenNeeded),
       
    79 	  iCurrentEvent(EPacketEventNone), iPacketReleaseModeIndex(0), 
       
    80 	  iPcktTimerBool(EFalse), iCurrentPrimaryContextIndex(0)
       
    81 /**
       
    82 * Trivial Constructor.  Initialises all the data members
       
    83 *
       
    84 * @param aPhone pointer to the phone object that owns this class.
       
    85 */
       
    86 	{
       
    87 	iState=RPacketService::EStatusUnattached;
       
    88 	iMSClass = RPacketService::EMSClassSuspensionRequired;
       
    89 	iNotifyStatusChange.iNotifyPending = EFalse;		
       
    90 	iNotifyContextAdded.iNotifyPending = EFalse;
       
    91 	iNotifyChangeOfNtwk.iNotifyPending = EFalse;
       
    92 	iNotifyMSClassChange.iNotifyPending = EFalse;
       
    93 	iNotifyChangeOfReleaseMode.iNotifyPending=EFalse;
       
    94 	iNotifyChangeOfAttachMode.iNotifyPending=EFalse;
       
    95 	iNotifyDynamicCapsChange.iNotifyPending = EFalse;
       
    96 	iNotifyMbmsNetworkStatusChange.iNotifyPending = EFalse;
       
    97 	iNotifyMbmsServAvailChange.iNotifyPending = EFalse;
       
    98 	iSecondaryContext = EFalse;
       
    99 	}
       
   100 
       
   101 
       
   102 void CSimPacketService::ConstructL()
       
   103 /**
       
   104 * Second phase of the 2-phase constructor.
       
   105 * Constructs all the member data and retrieves all the data from the config file specific to this class.
       
   106 *
       
   107 * @leave Leaves no memory or any data member does not construct for any reason.
       
   108 * @panic Panics with SIMTSY EInvalidParameterFormatInConfigFile if an additional param data item is in an invalid format
       
   109 */
       
   110 	{
       
   111 	LOGPACKET1("CSimPacketService: Entered ConstructL()");
       
   112 	
       
   113 	iTimer = CSimTimer::NewL(iPhone);
       
   114 	iPcktRegTimer = CSimTimer::NewL(iPhone);
       
   115 	iNtwkRegTimer = CSimTimer::NewL(iPhone);
       
   116 	iReleaseModeTimer = CSimTimer::NewL(iPhone);
       
   117 	iDynamicCapsTimer = CSimTimer::NewL(iPhone);
       
   118 	iMbmsPcktTimer = CSimTimer::NewL(iPhone);
       
   119 	iMutex.CreateGlobal(KNullDesC, EOwnerProcess);
       
   120 	
       
   121 	iNtwkRegStatusInfo = new(ELeave) CArrayFixFlat<TNtwkRegStatus>(KGranularity);
       
   122 	iPcktRegStatusInfo=new(ELeave) CArrayFixFlat<TPacketRegStatus>(KGranularity);
       
   123 	iPacketReleaseModeArray=new (ELeave) CArrayFixFlat<TPacketReleaseMode>(KGranularity);
       
   124 	iDynamicCapsArray = new (ELeave) CArrayFixFlat<TPacketDynamicCaps>(KGranularity);
       
   125 	iSecondaryContextCountArray = new(ELeave)CArrayFixFlat<TInt>(KGranularity);
       
   126 	iMbmsBroadcastParamsArray = new(ELeave)CArrayFixFlat<TMbmsBroadCastParams>(KGranularity);
       
   127 	iMbmsMonitorListParamsArray = new(ELeave)CArrayFixFlat<TMbmsMonitorListParams>(KGranularity);
       
   128 	iMbmsServicesList = new CArrayPtrFlat<CPcktListReadAllAttempt>(1);
       
   129 	
       
   130 	iNtwkRegStatusChangeProperty = CSimPubSub::TPubSubProperty(KUidPSSimTsyCategory, KPSSimtsyPacketServiceNtwkRegStatusChange, KPSSimtsyPacketServiceNtwkRegStatusChangeKeyType);
       
   131 	iNtwkRegStatusChange =  CSimPubSub::NewL(this,iNtwkRegStatusChangeProperty);
       
   132 	iNtwkRegStatusChange->Start(); 
       
   133 	
       
   134 	iMbmsActivation = CSimPubSubChange::NewL(this,CSimPubSub::TPubSubProperty(KUidPSSimTsyCategory, KPSSimTsyMbmsService, KPSSimTsyMbmsServiceType));
       
   135 
       
   136 	const CTestConfigItem* item=NULL;
       
   137 	TInt ret=KErrNone;
       
   138 	
       
   139 	item=CfgFile()->Item(KAttachPauseDuration); //< Retrieves the attach pause duration number from the config file
       
   140 	if(item)
       
   141 		{
       
   142 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,iAttachPause);
       
   143 		if(ret!=KErrNone)
       
   144 			iAttachPause = KDefaultPauseDuration;
       
   145 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,iAttachFail);
       
   146 		if(ret==KErrNotFound)
       
   147 			iAttachFail = KErrNone;
       
   148 		}
       
   149 
       
   150 	item=CfgFile()->Item(KDetachPauseDuration);	//< Retrieves the detach pause duration number from the config file
       
   151 	if(item)
       
   152 		{
       
   153 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,iDetachPause);
       
   154 		if(ret!=KErrNone)
       
   155 			iDetachPause = KDefaultPauseDuration;
       
   156 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,iDetachFail);
       
   157 		if(ret==KErrNotFound)
       
   158 			iDetachFail = KErrNone;
       
   159 		}
       
   160 
       
   161 	TInt count=CfgFile()->ItemCount(KPacketRegStatus); //< Retrieves the packet registration info
       
   162 	item=NULL;
       
   163 	TInt i;
       
   164 	for(i=0;i<count;i++)
       
   165 		{
       
   166 		item=CfgFile()->Item(KPacketRegStatus,i);
       
   167 		if(!item)
       
   168 			break;
       
   169 
       
   170 		TInt time,regState;
       
   171 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,time);
       
   172 		if(ret!=KErrNone)
       
   173 			break;
       
   174 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,regState);
       
   175 		if(ret!=KErrNone)
       
   176 			break;
       
   177 
       
   178 		TPacketRegStatus status;
       
   179 		status.iDuration=time;
       
   180 		status.iStatus=(RPacketService::TStatus)regState;
       
   181 		TRAP_IGNORE(iPcktRegStatusInfo->AppendL(status));
       
   182 		}
       
   183 
       
   184 	iNtwkRegStatusNotificationType = ETimer;
       
   185 	item=CfgFile()->Item(KNetworkRegStatusType);
       
   186 	if(item)
       
   187 		{
       
   188 		TPtrC8 networkRegStatusType;
       
   189 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,networkRegStatusType);
       
   190 		if(ret==KErrNone && networkRegStatusType.Compare(KNotificationTypePublishSubscribe)==0)
       
   191 			{
       
   192 			iNtwkRegStatusNotificationType = EPublishAndSubscribe;
       
   193 			}
       
   194 		}
       
   195 
       
   196 	count=CfgFile()->ItemCount(KNetworkRegStatus); //< Retrieves the packet registration info
       
   197 	item=NULL;
       
   198 	for(i=0;i<count;i++)
       
   199 		{
       
   200 		item=CfgFile()->Item(KNetworkRegStatus,i);
       
   201 		if(!item)
       
   202 			break;
       
   203 
       
   204 		TInt time,regState;
       
   205 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,time);
       
   206 		if(ret!=KErrNone)
       
   207 			break;
       
   208 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,regState);
       
   209 		if(ret!=KErrNone)
       
   210 			break;
       
   211 
       
   212 		TNtwkRegStatus status;
       
   213 		status.iDuration=time;
       
   214 		status.iRegStatus=(RPacketService::TRegistrationStatus)regState;
       
   215 		TRAP_IGNORE(iNtwkRegStatusInfo->AppendL(status));
       
   216 		}
       
   217 
       
   218 	if(iPcktRegStatusInfo->Count()!=0)
       
   219 		{
       
   220 		iPcktRegStatIndex=0;
       
   221 		iState=(RPacketService::TStatus)iPcktRegStatusInfo->At(0).iStatus;
       
   222 		iPcktRegTimer->Start(iPcktRegStatusInfo->At(0).iDuration,this,ETimerIdPcktServPacket);
       
   223 		}
       
   224 
       
   225 	if(iNtwkRegStatusInfo->Count()!=0)
       
   226 		{
       
   227 		iCurrentRegStatus=(RPacketService::TRegistrationStatus)iNtwkRegStatusInfo->At(0).iRegStatus;
       
   228 		if (iNtwkRegStatusNotificationType == ETimer)
       
   229 			{
       
   230 			iNtwkRegStatIndex=0;
       
   231 			iNtwkRegTimer->Start(iNtwkRegStatusInfo->At(0).iDuration,this,ETimerIdPcktServNtwkStatusChange);
       
   232 			}
       
   233 		}
       
   234 
       
   235 	//< Read in all dynamic capabilities data
       
   236 	count = CfgFile()->ItemCount(KDynamicCaps);
       
   237 	item = NULL;
       
   238 	for (i = 0; i < count; ++i)
       
   239 		{
       
   240 		item = CfgFile()->Item(KDynamicCaps,i);
       
   241 		if (!item)
       
   242 			break;
       
   243 		
       
   244 		TInt duration(0); 
       
   245 		TInt dynamicCaps(0);
       
   246 		ret = CTestConfig::GetElement(item->Value(),KStdDelimiter,0,duration);
       
   247 		if (ret != KErrNone)
       
   248 			break;
       
   249 		ret = CTestConfig::GetElement(item->Value(),KStdDelimiter,1,dynamicCaps);
       
   250 		if (ret != KErrNone)
       
   251 			break;
       
   252 		
       
   253 		TPacketDynamicCaps dynamicCapsData;
       
   254 		dynamicCapsData.iDuration = duration;
       
   255 		dynamicCapsData.iDynamicCaps = dynamicCaps;
       
   256 		
       
   257 		TRAP_IGNORE(iDynamicCapsArray->AppendL(dynamicCapsData));
       
   258 		}
       
   259 	
       
   260 	if (iDynamicCapsArray->Count() != 0)
       
   261 		{
       
   262 		iDynamicCapsIndex = 0;
       
   263 		TPacketDynamicCaps initialCaps = iDynamicCapsArray->At(0);
       
   264 		iCurrentDynamicCaps = initialCaps.iDynamicCaps;
       
   265 		iDynamicCapsTimer->Start(initialCaps.iDuration, this, ETimerIdPcktServDynamicCaps);
       
   266 		}
       
   267 	// end of dynamic caps simulation setup
       
   268 	
       
   269 	//< Read in all the data for getting the default GPRS configuration parameters
       
   270 	
       
   271 	item = CfgFile()->Item(KDefaultContextparamGPRS);
       
   272 	if(item) 
       
   273 		{
       
   274 		TInt protocolType,pdpCompression, anonymousAccess, useEdge;
       
   275 		TPtrC8 gsnAddress, protocolAddress;
       
   276 		TInt protocol;	
       
   277 		TPtrC8 username,password, challenge, response, primaryDNS, secondaryDNS, iMiscBuffer;
       
   278 		TInt id, numAdditionalParams;
       
   279 
       
   280 		iGPRSDefaultConfig.iProtocolConfigOption.iMiscBuffer.Zero();
       
   281 		
       
   282 		TPtr8 pcoPtr(const_cast<TUint8*>(iGPRSDefaultConfig.iProtocolConfigOption.iMiscBuffer.Ptr()), 
       
   283 			RPacketContext::KMiscProtocolBufferLength);
       
   284 
       
   285 		// Attach TTlv to the buffer
       
   286 		TTlvStruct<RPacketContext::TPcoId,RPacketContext::TPcoItemDataLength> tlvStruct(pcoPtr,0);
       
   287 
       
   288 		RPacketContext::TPcoId pcoId;
       
   289 		
       
   290 		TUint itemOffSet = 0; // Used for nested Addional Param items		
       
   291 		
       
   292 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,protocolType);
       
   293 		if(ret==KErrNone)
       
   294 			iGPRSDefaultConfig.iProtocolType = protocolType;
       
   295 
       
   296 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,gsnAddress);
       
   297 		if(ret==KErrNone)
       
   298 			iGPRSDefaultConfig.iGsnAddress.Set(gsnAddress);
       
   299 
       
   300 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,2,protocolAddress);
       
   301 		if(ret==KErrNone)
       
   302 			iGPRSDefaultConfig.iProtocolAddress.Set(protocolAddress);
       
   303 
       
   304 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,3,pdpCompression);
       
   305 		if(ret==KErrNone)
       
   306 			iGPRSDefaultConfig.iPdpCompression = pdpCompression;
       
   307 
       
   308 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,4,anonymousAccess);
       
   309 		if(ret==KErrNone)
       
   310 			iGPRSDefaultConfig.iAnonymousAccess = anonymousAccess;
       
   311 
       
   312 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,5,useEdge);
       
   313 		if(ret==KErrNone)
       
   314 			iGPRSDefaultConfig.iUseEdge = useEdge;
       
   315 
       
   316 		// Protocol configuration and DNS server parameters added
       
   317 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,6,protocol);
       
   318 		if(ret==KErrNone)
       
   319 			iGPRSDefaultConfig.iProtocolConfigOption.iAuthProtocol = protocol;
       
   320 
       
   321 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,7,username);
       
   322 		if(ret==KErrNone)
       
   323 			iGPRSDefaultConfig.iProtocolConfigOption.iUsername.Set(username);
       
   324 
       
   325 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,8,password);
       
   326 		if(ret==KErrNone)
       
   327 			iGPRSDefaultConfig.iProtocolConfigOption.iPassword.Set(password);
       
   328 
       
   329 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,9,challenge);
       
   330 		if(ret==KErrNone)
       
   331 			iGPRSDefaultConfig.iProtocolConfigOption.iChallenge.Set(challenge);
       
   332 
       
   333 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,10,response);
       
   334 		if(ret==KErrNone)
       
   335 			iGPRSDefaultConfig.iProtocolConfigOption.iResponse.Set(response);
       
   336 
       
   337 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,11,primaryDNS);
       
   338 		if(ret==KErrNone)
       
   339 			iGPRSDefaultConfig.iProtocolConfigOption.iPrimaryDNS.Set(primaryDNS);
       
   340 
       
   341 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,12,secondaryDNS);
       
   342 		if(ret==KErrNone)
       
   343 			iGPRSDefaultConfig.iProtocolConfigOption.iSecondaryDNS.Set(secondaryDNS);
       
   344 
       
   345 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,13,id);
       
   346 		if(ret==KErrNone)
       
   347 			iGPRSDefaultConfig.iProtocolConfigOption.iId = id;
       
   348 		
       
   349 		//Get the Additional Params List
       
   350 		//Get the number of items in the Additional Params List
       
   351 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,14,numAdditionalParams);
       
   352 		if(ret==KErrNone)
       
   353 			{
       
   354 			TInt nestedItemNumber;
       
   355 			TUint16 digit, format;
       
   356 			const CTestConfigItem* item2;
       
   357 			
       
   358 			for(nestedItemNumber=itemOffSet; nestedItemNumber<itemOffSet+numAdditionalParams; nestedItemNumber++)
       
   359 				{
       
   360 				item2 = CfgFile()->Item(KDefaultGPRSAdditionalParamItem, nestedItemNumber);
       
   361 		
       
   362 				if(item2)
       
   363 					{
       
   364 					TPtrC8 additionalParamId, additionalParamContent, additionalParamDataFormat;
       
   365 				
       
   366 					// Get ID
       
   367 					ret=CTestConfig::GetElement(item2->Value(),KStdDelimiter,0,additionalParamId);
       
   368 					if(ret==KErrNone)
       
   369 						{
       
   370 						if(AsciiToNum(additionalParamId, digit)==KErrNone)
       
   371 							{
       
   372 							pcoId.SetId(digit);
       
   373 							}
       
   374 						}
       
   375 					
       
   376 					// Read AdditionalParamDataFormat field to find out how
       
   377 					// to interpret data in the AdditionalParamData field
       
   378 					ret=CTestConfig::GetElement(item2->Value(),KStdDelimiter,2,additionalParamDataFormat);
       
   379 					if (ret != KErrNone)
       
   380 						{
       
   381 						// AdditionalParamDataFormat not been specified,
       
   382 						// default to plain ASCII
       
   383 						LOGPARSERR("AdditionalParamItem::additionalParamDataFormat",ret,2,&KDefaultGPRSAdditionalParamItem);
       
   384 						format = EConfigDataFormatAscii;
       
   385 						}
       
   386 					else
       
   387 						{
       
   388 						if (AsciiToNum(additionalParamDataFormat, format) != KErrNone)
       
   389 							{
       
   390 							LOGPARSERR("AdditionalParamItem::additionalParamDataFormat",KErrArgument,2,&KDefaultGPRSAdditionalParamItem);
       
   391 							format = EConfigDataFormatAscii;
       
   392 							}
       
   393 
       
   394 						// Check that the AdditionalParamDataFormat value
       
   395 						// specified in the config file is a valid one,
       
   396 						// default to ASCII if not.
       
   397 						if (format >= EMaxConfigDataFormat)
       
   398 							{
       
   399 							LOGPARSERR("AdditionalParamItem::additionalParamDataFormat",KErrArgument,2,&KDefaultGPRSAdditionalParamItem);
       
   400 							format = EConfigDataFormatAscii;
       
   401 							}
       
   402 						}
       
   403 										
       
   404 					// Get AdditionalParamData
       
   405 					ret=CTestConfig::GetElement(item2->Value(),KStdDelimiter,1,additionalParamContent);
       
   406 					if(ret==KErrNone)
       
   407 						{
       
   408 						// Add AdditionalParamData to PCO buffer depending on format
       
   409 						switch (format)
       
   410 							{
       
   411 						case EConfigDataFormatMixedBinaryAndAscii:
       
   412 							{
       
   413 							// Parse the string here
       
   414 							// Will store the parsed data when algorithm has completed
       
   415 							TBuf8<RPacketContext::KMiscProtocolBufferLength> additionalParamDataBuffer;
       
   416 							additionalParamDataBuffer.Copy (additionalParamContent);
       
   417 
       
   418 							if (ParseMixedBinaryAsciiDataL(additionalParamDataBuffer) != KErrNone)
       
   419 								{
       
   420 								LOGPARSERR("AdditionalParamItem::additionalParamContent",KErrArgument,1,&KDefaultGPRSAdditionalParamItem);
       
   421 								SimPanic(EInvalidParameterFormatInConfigFile);
       
   422 								}
       
   423 
       
   424 							TPtr8 paramPtr(const_cast<TUint8*>(additionalParamDataBuffer.Ptr()), 
       
   425 								additionalParamDataBuffer.Length(), additionalParamDataBuffer.Length());
       
   426 							tlvStruct.AppendItemL(pcoId, paramPtr);
       
   427 
       
   428 							} // case EAdditionalParamDataFormatMixedBinaryAndAscii
       
   429 							break;
       
   430 						case EConfigDataFormatAscii:
       
   431 						default:
       
   432 							TPtr8 paramPtr(const_cast<TUint8*>(additionalParamContent.Ptr()), 
       
   433 								additionalParamContent.Length(), additionalParamContent.Length());
       
   434 							tlvStruct.AppendItemL(pcoId, paramPtr);
       
   435 
       
   436 							break;
       
   437 							} // switch (format)
       
   438 						
       
   439 						iGPRSDefaultConfig.iProtocolConfigOption.iMiscBuffer.SetLength(pcoPtr.Length());						
       
   440 						} // if (ret == KErrNone)
       
   441 					}
       
   442 				}
       
   443 
       
   444 				itemOffSet= itemOffSet + numAdditionalParams;;
       
   445 			}
       
   446 		else
       
   447 			{
       
   448 			LOGPARSERR("ProtocolConfigOption::numAdditionalParams",ret,14,&KDefaultContextparamGPRS);	
       
   449 			} 
       
   450 		} 
       
   451 
       
   452 	//< Read in all the data for getting the default UMTS configuration parameters
       
   453 	item = CfgFile()->Item(KDefaultContextparamRel99);
       
   454 	if(item)
       
   455 		{
       
   456 		TInt protocolType,useEdge;
       
   457 		TPtrC8 gsnAddress, protocolAddress;
       
   458 		TInt protocol;
       
   459 		TPtrC8 username,password, challenge, response, primaryDNS, secondaryDNS, iMiscBuffer;
       
   460 		TInt id, numAdditionalParams;
       
   461 
       
   462 		iR99_R4DefaultConfig.iProtocolConfigOption.iMiscBuffer.Zero();
       
   463 		
       
   464 		TPtr8 pcoPtr(const_cast<TUint8*>(iR99_R4DefaultConfig.iProtocolConfigOption.iMiscBuffer.Ptr()), 
       
   465 			RPacketContext::KMiscProtocolBufferLength);
       
   466 
       
   467 		// Attach TTlv to the buffer
       
   468 		TTlvStruct<RPacketContext::TPcoId,RPacketContext::TPcoItemDataLength> tlvStruct(pcoPtr,0);
       
   469 
       
   470 		RPacketContext::TPcoId pcoId;
       
   471 		
       
   472 		TUint itemOffSet = 0; // Used for nested Addional Param items
       
   473 
       
   474 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,protocolType);
       
   475 		if(ret==KErrNone)
       
   476 			iR99_R4DefaultConfig.iProtocolType = protocolType;
       
   477 
       
   478 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,gsnAddress);
       
   479 		if(ret==KErrNone)
       
   480 			iR99_R4DefaultConfig.iGsnAddress.Set(gsnAddress);
       
   481 
       
   482 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,2,protocolAddress);
       
   483 		if(ret==KErrNone)
       
   484 			iR99_R4DefaultConfig.iProtocolAddress.Set(protocolAddress);
       
   485 
       
   486 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,3,useEdge);
       
   487 		if(ret==KErrNone)
       
   488 			iR99_R4DefaultConfig.iUseEdge = useEdge;
       
   489 
       
   490 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,4,protocol);
       
   491 		if(ret==KErrNone)
       
   492 			iR99_R4DefaultConfig.iProtocolConfigOption.iAuthProtocol = protocol;
       
   493 
       
   494 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,5,username);
       
   495 		if(ret==KErrNone)
       
   496 			iR99_R4DefaultConfig.iProtocolConfigOption.iUsername.Set(username);
       
   497 
       
   498 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,6,password);
       
   499 		if(ret==KErrNone)
       
   500 			iR99_R4DefaultConfig.iProtocolConfigOption.iPassword.Set(password);
       
   501 
       
   502 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,7,challenge);
       
   503 		if(ret==KErrNone)
       
   504 			iR99_R4DefaultConfig.iProtocolConfigOption.iChallenge.Set(challenge);
       
   505 
       
   506 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,8,response);
       
   507 		if(ret==KErrNone)
       
   508 			iR99_R4DefaultConfig.iProtocolConfigOption.iResponse.Set(response);
       
   509 
       
   510 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,9,primaryDNS);
       
   511 		if(ret==KErrNone)
       
   512 			iR99_R4DefaultConfig.iProtocolConfigOption.iPrimaryDNS.Set(primaryDNS);
       
   513 
       
   514 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,10,secondaryDNS);
       
   515 		if(ret==KErrNone)
       
   516 			iR99_R4DefaultConfig.iProtocolConfigOption.iSecondaryDNS.Set(secondaryDNS);
       
   517 
       
   518 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,11,id);
       
   519 		if(ret==KErrNone)
       
   520 			iR99_R4DefaultConfig.iProtocolConfigOption.iId = id;
       
   521 		
       
   522 		//Get the Additional Params List
       
   523 		//Get the number of items in the Additional Params List
       
   524 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,12,numAdditionalParams);
       
   525 		if(ret==KErrNone)
       
   526 			{
       
   527 			TInt nestedItemNumber;
       
   528 			TUint16 digit, format;
       
   529 			const CTestConfigItem* item2;
       
   530 			
       
   531 			for(nestedItemNumber=itemOffSet; nestedItemNumber<itemOffSet+numAdditionalParams; nestedItemNumber++)
       
   532 				{
       
   533 				item2 = CfgFile()->Item(KDefaultAdditionalParamItemRel99, nestedItemNumber);
       
   534 		
       
   535 				if(item2)
       
   536 					{
       
   537 					TPtrC8 additionalParamId, additionalParamContent, additionalParamDataFormat;
       
   538 				
       
   539 					ret=CTestConfig::GetElement(item2->Value(),KStdDelimiter,0,additionalParamId);
       
   540 					if(ret==KErrNone)
       
   541 						{
       
   542 						if(AsciiToNum(additionalParamId, digit)==KErrNone)
       
   543 							{
       
   544 							pcoId.SetId(digit);
       
   545 							}
       
   546 						}
       
   547 
       
   548 					// Read AdditionalParamDataFormat field to find out how
       
   549 					// to interpret data in the AdditionalParamData field
       
   550 					ret=CTestConfig::GetElement(item2->Value(),KStdDelimiter,2,additionalParamDataFormat);
       
   551 					if (ret != KErrNone)
       
   552 						{
       
   553 						// AdditionalParamDataFormat not been specified,
       
   554 						// default to plain ASCII
       
   555 						LOGPARSERR("No AdditionalParamItem::additionalParamDataFormat",ret,2,&KDefaultAdditionalParamItemRel99);
       
   556 						format = EConfigDataFormatAscii;
       
   557 						}
       
   558 					else
       
   559 						{
       
   560 						if (AsciiToNum(additionalParamDataFormat, format) != KErrNone)
       
   561 							{
       
   562 							LOGPARSERR("AdditionalParamItem::additionalParamDataFormat",KErrArgument,2,&KDefaultAdditionalParamItemRel99);
       
   563 							format = EConfigDataFormatAscii;
       
   564 							}
       
   565 
       
   566 						// Check that the AdditionalParamDataFormat value
       
   567 						// specified in the config file is a valid one,
       
   568 						// default to ASCII if not.
       
   569 						if (format >= EMaxConfigDataFormat)
       
   570 							{
       
   571 							LOGPARSERR("AdditionalParamItem::additionalParamDataFormat",KErrArgument,2,&KDefaultAdditionalParamItemRel99);
       
   572 							format = EConfigDataFormatAscii;
       
   573 							}
       
   574 						}
       
   575 						
       
   576 					ret=CTestConfig::GetElement(item2->Value(),KStdDelimiter,1,additionalParamContent);
       
   577 					if(ret==KErrNone)
       
   578 						{
       
   579 						// Add AdditionalParamData to PCO buffer depending on format
       
   580 						switch (format)
       
   581 							{
       
   582 						case EConfigDataFormatMixedBinaryAndAscii:
       
   583 							{
       
   584 							// Parse the string here
       
   585 							// Will store the parsed data when algorithm has completed
       
   586 							TBuf8<RPacketContext::KMiscProtocolBufferLength> additionalParamDataBuffer;
       
   587 							additionalParamDataBuffer.Copy (additionalParamContent);
       
   588 
       
   589 							if (ParseMixedBinaryAsciiDataL(additionalParamDataBuffer) != KErrNone)
       
   590 								{
       
   591 								LOGPARSERR("AdditionalParamItem::additionalParamContent",KErrArgument,1,&KDefaultAdditionalParamItemRel99);
       
   592 								SimPanic(EInvalidParameterFormatInConfigFile);
       
   593 								}
       
   594 
       
   595 							TPtr8 paramPtr(const_cast<TUint8*>(additionalParamDataBuffer.Ptr()), 
       
   596 								additionalParamDataBuffer.Length(), additionalParamDataBuffer.Length());
       
   597 							tlvStruct.AppendItemL(pcoId, paramPtr);
       
   598 
       
   599 							} // case EAdditionalParamDataFormatMixedBinaryAndAscii
       
   600 							break;
       
   601 						case EConfigDataFormatAscii:
       
   602 						default:
       
   603 							TPtr8 paramPtr(const_cast<TUint8*>(additionalParamContent.Ptr()), 
       
   604 								additionalParamContent.Length(), additionalParamContent.Length());
       
   605 							tlvStruct.AppendItemL(pcoId, paramPtr);
       
   606 
       
   607 							break;
       
   608 							} // switch (format)
       
   609 						iR99_R4DefaultConfig.iProtocolConfigOption.iMiscBuffer.SetLength(pcoPtr.Length());
       
   610 						}
       
   611 					}
       
   612 				}
       
   613 
       
   614 				itemOffSet= itemOffSet + numAdditionalParams;;
       
   615 			}
       
   616 		else
       
   617 			{
       
   618 			LOGPARSERR("ProtocolConfigOption::numAdditionalParams",ret,12,&KDefaultContextparamRel99);	
       
   619 			} 		
       
   620 
       
   621 		}
       
   622 
       
   623 		//< Read in all the data for getting the default R5 configuration parameters
       
   624 		item = CfgFile()->Item(KDefaultContextParamRel5);
       
   625 		if(item)
       
   626 			{
       
   627 			TInt protocolType, useEdge, protocol, id;
       
   628 			TInt pdpDataCompression, pdpHeaderCompression, numAdditionalParams;
       
   629 			TPtrC8 gsnAddress, protocolAddress, username, password, challenge;
       
   630 			TPtrC8 response, primaryDNS, secondaryDNS, iMiscBuffer;
       
   631 
       
   632 			iR5DefaultConfig.iProtocolConfigOption.iMiscBuffer.Zero();
       
   633 
       
   634 			TPtr8 pcoPtr(const_cast<TUint8*>(iR5DefaultConfig.iProtocolConfigOption.iMiscBuffer.Ptr()), 
       
   635 				RPacketContext::KMiscProtocolBufferLength);
       
   636 
       
   637 			// Attach the TTlv to the buffer
       
   638 			TTlvStruct<RPacketContext::TPcoId,RPacketContext::TPcoItemDataLength> tlvStruct(pcoPtr,0);
       
   639 
       
   640 			RPacketContext::TPcoId pcoId;
       
   641 			
       
   642 			TUint itemOffSet = 0; //Used for nested Addional Param items
       
   643 
       
   644 			//Get the Protocol Type from the config file
       
   645 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,protocolType);
       
   646 			if(ret==KErrNone)
       
   647 				{
       
   648 				iR5DefaultConfig.iProtocolType = protocolType;	
       
   649 				}
       
   650 			
       
   651 			//Get the GGSN Address from the config file
       
   652 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,gsnAddress);
       
   653 			if(ret==KErrNone)
       
   654 				{
       
   655 				iR5DefaultConfig.iGsnAddress.Set(gsnAddress);
       
   656 				}
       
   657 
       
   658 			//Get the ProtocolAddress from the config file
       
   659 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,2,protocolAddress);
       
   660 			if(ret==KErrNone)
       
   661 				{
       
   662 				iR5DefaultConfig.iProtocolAddress.Set(protocolAddress);
       
   663 				}	
       
   664 				
       
   665 			//Get the UseEdge config param from the config file
       
   666 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,3,useEdge);
       
   667 			if(ret==KErrNone)
       
   668 				{
       
   669 				iR5DefaultConfig.iUseEdge = useEdge;	
       
   670 				}
       
   671 			
       
   672 			
       
   673 			//Get the Autorisation Protocol config param from the config file
       
   674 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,4,protocol);
       
   675 			if(ret==KErrNone)
       
   676 				{
       
   677 				iR5DefaultConfig.iProtocolConfigOption.iAuthProtocol = protocol;	
       
   678 				}
       
   679 
       
   680 
       
   681 			//Get the Username config param from the config file
       
   682 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,5,username);
       
   683 			if(ret==KErrNone)
       
   684 				{
       
   685 				iR5DefaultConfig.iProtocolConfigOption.iUsername.Set(username);	
       
   686 				}
       
   687 
       
   688 			//Get the psword config param from the config file
       
   689 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,6,password);
       
   690 			if(ret==KErrNone)
       
   691 				{
       
   692 				iR5DefaultConfig.iProtocolConfigOption.iPassword.Set(password);	
       
   693 				}
       
   694 			
       
   695 			//Get the Challenge config param from the config file
       
   696 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,7,challenge);
       
   697 			if(ret==KErrNone)
       
   698 				{
       
   699 				iR5DefaultConfig.iProtocolConfigOption.iChallenge.Set(challenge);	
       
   700 				}
       
   701 
       
   702 			//Get the Response config param from the config file
       
   703 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,8,response);
       
   704 			if(ret==KErrNone)
       
   705 				{
       
   706 				iR5DefaultConfig.iProtocolConfigOption.iResponse.Set(response);	
       
   707 				}
       
   708 
       
   709 			//Get the Primary DNS config param from the config file
       
   710 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,9,primaryDNS);
       
   711 			if(ret==KErrNone)
       
   712 				{
       
   713 				iR5DefaultConfig.iProtocolConfigOption.iPrimaryDNS.Set(primaryDNS);	
       
   714 				}
       
   715 
       
   716 			//Get the Secondary DNS config param from the config file
       
   717 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,10,secondaryDNS);
       
   718 			if(ret==KErrNone)
       
   719 				{
       
   720 				iR5DefaultConfig.iProtocolConfigOption.iSecondaryDNS.Set(secondaryDNS);	
       
   721 				}
       
   722 				
       
   723 			//Get the ID config param from the config file.
       
   724 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,11,id);
       
   725 			if(ret==KErrNone)
       
   726 				{
       
   727 				iR5DefaultConfig.iProtocolConfigOption.iId = id;	
       
   728 				}
       
   729 
       
   730 			//Get the PDP Header Compression params
       
   731 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,12,pdpHeaderCompression);
       
   732 			if(ret==KErrNone)
       
   733 				{
       
   734 				iR5DefaultConfig.iPdpHeaderCompression = pdpHeaderCompression;
       
   735 				}
       
   736 			
       
   737 			//Get the PDP Data compression params
       
   738 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,13,pdpDataCompression);
       
   739 			if(ret==KErrNone)
       
   740 				{
       
   741 				iR5DefaultConfig.iPdpDataCompression = pdpDataCompression;
       
   742 				}
       
   743 				
       
   744 
       
   745 			//Get the Additional Params List
       
   746 			//Get the number of items in the Additional Params List
       
   747 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,14,numAdditionalParams);
       
   748 			if(ret==KErrNone)
       
   749 				{
       
   750 				TInt nestedItemNumber;
       
   751 				TUint16 digit, format;
       
   752 				const CTestConfigItem* item2;
       
   753 				
       
   754 				for(nestedItemNumber=itemOffSet; nestedItemNumber<itemOffSet+numAdditionalParams; nestedItemNumber++)
       
   755 					{
       
   756 					item2 = CfgFile()->Item(KDefaultAdditionalParamItem, nestedItemNumber);
       
   757 			
       
   758 					if(item2)
       
   759 						{
       
   760 						TPtrC8 additionalParamId, additionalParamContent, additionalParamDataFormat;
       
   761 					
       
   762 						ret=CTestConfig::GetElement(item2->Value(),KStdDelimiter,0,additionalParamId);
       
   763 						if(ret==KErrNone)
       
   764 							{
       
   765 							if(AsciiToNum(additionalParamId, digit)==KErrNone)
       
   766 								{
       
   767 								pcoId.SetId(digit);
       
   768 								}
       
   769 							}
       
   770 
       
   771 					// Read AdditionalParamDataFormat field to find out how
       
   772 					// to interpret data in the AdditionalParamData field
       
   773 					ret=CTestConfig::GetElement(item2->Value(),KStdDelimiter,2,additionalParamDataFormat);
       
   774 					if (ret != KErrNone)
       
   775 						{
       
   776 						// AdditionalParamDataFormat not been specified,
       
   777 						// default to plain ASCII
       
   778 						LOGPARSERR("No AdditionalParamItem::additionalParamDataFormat",ret,2,&KDefaultAdditionalParamItem);
       
   779 						format = EConfigDataFormatAscii;
       
   780 						}
       
   781 					else
       
   782 						{
       
   783 						if (AsciiToNum(additionalParamDataFormat, format) != KErrNone)
       
   784 							{
       
   785 							LOGPARSERR("AdditionalParamItem::additionalParamDataFormat",KErrArgument,2,&KDefaultAdditionalParamItem);
       
   786 							format = EConfigDataFormatAscii;
       
   787 							}
       
   788 
       
   789 						// Check that the AdditionalParamDataFormat value
       
   790 						// specified in the config file is a valid one,
       
   791 						// default to ASCII if not.
       
   792 						if (format >= EMaxConfigDataFormat)
       
   793 							{
       
   794 							LOGPARSERR("AdditionalParamItem::additionalParamDataFormat",KErrArgument,2,&KDefaultAdditionalParamItem);
       
   795 							format = EConfigDataFormatAscii;
       
   796 							}
       
   797 						}
       
   798 
       
   799 						ret=CTestConfig::GetElement(item2->Value(),KStdDelimiter,1,additionalParamContent);
       
   800 						if(ret==KErrNone)
       
   801 							{
       
   802 							// Add AdditionalParamData to PCO buffer depending on format
       
   803 							switch (format)
       
   804 								{
       
   805 							case EConfigDataFormatMixedBinaryAndAscii:
       
   806 								{
       
   807 								// Parse the string here
       
   808 								// Will store the parsed data when algorithm has completed
       
   809 								TBuf8<RPacketContext::KMiscProtocolBufferLength> additionalParamDataBuffer;
       
   810 								additionalParamDataBuffer.Copy (additionalParamContent);
       
   811 
       
   812 								if (ParseMixedBinaryAsciiDataL(additionalParamDataBuffer) != KErrNone)
       
   813 									{
       
   814 									LOGPARSERR("AdditionalParamItem::additionalParamContent",KErrArgument,1,&KDefaultAdditionalParamItem);
       
   815 									SimPanic(EInvalidParameterFormatInConfigFile);
       
   816 									}
       
   817 
       
   818 								TPtr8 paramPtr(const_cast<TUint8*>(additionalParamDataBuffer.Ptr()), 
       
   819 									additionalParamDataBuffer.Length(), additionalParamDataBuffer.Length());
       
   820 								tlvStruct.AppendItemL(pcoId, paramPtr);
       
   821 
       
   822 								} // case EAdditionalParamDataFormatMixedBinaryAndAscii
       
   823 								break;
       
   824 							case EConfigDataFormatAscii:
       
   825 							default:
       
   826 								TPtr8 paramPtr(const_cast<TUint8*>(additionalParamContent.Ptr()), 
       
   827 									additionalParamContent.Length(), additionalParamContent.Length());
       
   828 								tlvStruct.AppendItemL(pcoId, paramPtr);
       
   829 
       
   830 								break;
       
   831 								} // switch (format)
       
   832 							iR5DefaultConfig.iProtocolConfigOption.iMiscBuffer.SetLength(pcoPtr.Length());
       
   833 							}
       
   834 						}
       
   835 					}
       
   836 
       
   837 					itemOffSet= itemOffSet + numAdditionalParams;;
       
   838 				}
       
   839 			}
       
   840 
       
   841 		count=CfgFile()->ItemCount(KPacketReleaseMode); //< Retrieves the packet registration info
       
   842 		item=NULL;
       
   843 		for(i=0;i<count;i++)
       
   844 			{
       
   845 			item=CfgFile()->Item(KPacketReleaseMode,i);
       
   846 			if(!item)
       
   847 				break;
       
   848 			TInt release,duration;
       
   849 			
       
   850 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,release);
       
   851 			if(ret!=KErrNone)
       
   852 				break;
       
   853 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,duration);
       
   854 			if(ret!=KErrNone)
       
   855 				break;
       
   856 
       
   857 			TPacketReleaseMode releaseMode;
       
   858 			releaseMode.iDuration=duration;
       
   859 			releaseMode.iReleaseMode=release;
       
   860 			TRAP_IGNORE(iPacketReleaseModeArray->AppendL(releaseMode));
       
   861 			}
       
   862 
       
   863 		item=NULL;
       
   864 		count=CfgFile()->ItemCount(KMBMSBroadCastPacketServiceParams); //< Retrieves the Count of MBMS related information
       
   865 
       
   866 		for(i=0;i<count;i++)
       
   867 			{
       
   868 			item = CfgFile()->Item(KMBMSBroadCastPacketServiceParams,i); //< Retrieves the MBMS related information
       
   869 
       
   870 			TInt duration =0;
       
   871 			TInt status =0;
       
   872 			if(!item)
       
   873 				{
       
   874 				break;
       
   875 				}
       
   876 
       
   877 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,duration);
       
   878 			if(ret!=KErrNone)
       
   879 				{
       
   880 				break;
       
   881 				}
       
   882 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,status);
       
   883 			if(ret!=KErrNone)
       
   884 				{
       
   885 				status = EMbmsSupportUnknown;
       
   886 				}
       
   887 
       
   888 			TMbmsBroadCastParams mbmsParams;
       
   889 			mbmsParams.iDuration = duration;
       
   890 			mbmsParams.iMbmsNetworkStatus = reinterpret_cast<TMbmsNetworkServiceStatus&> (status);
       
   891 			TRAP_IGNORE(iMbmsBroadcastParamsArray->AppendL(mbmsParams));
       
   892 			}
       
   893 
       
   894 		item=NULL;
       
   895 		count=CfgFile()->ItemCount(KMBMSBroadcastMonitorList); //< Retrieves the Count of MBMS related information
       
   896 
       
   897 		for(i=0;i<count;i++)
       
   898 			{
       
   899 			item = CfgFile()->Item(KMBMSBroadcastMonitorList,i); //< Retrieves the MBMS related information
       
   900 
       
   901 			TInt duration =0;
       
   902 			TInt mnc=0;
       
   903 			TInt mcc=0;
       
   904 			TInt serviceId=0;
       
   905 			TInt accessBearer=0;
       
   906 			TInt serviceMode=0;
       
   907 			TInt serviceAvailability=0;
       
   908 			TInt entryValid=0;
       
   909 			
       
   910 			if(!item)
       
   911 				{
       
   912 				break;
       
   913 				}
       
   914 
       
   915 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,duration);
       
   916 			if(ret!=KErrNone)
       
   917 				{
       
   918 				break;
       
   919 				}
       
   920 
       
   921 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,mcc);
       
   922 			if(ret!=KErrNone)
       
   923 				{
       
   924 				break;
       
   925 				}
       
   926 
       
   927 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,2,mnc);
       
   928 			if(ret!=KErrNone)
       
   929 				{
       
   930 				break;
       
   931 				}
       
   932 
       
   933 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,3,serviceId);
       
   934 			if(ret!=KErrNone)
       
   935 				{
       
   936 				break;
       
   937 				}
       
   938 
       
   939 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,4,accessBearer);
       
   940 			if(ret!=KErrNone)
       
   941 				{
       
   942 				break;
       
   943 				}
       
   944 
       
   945 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,5,serviceMode);
       
   946 			if(ret!=KErrNone)
       
   947 				{
       
   948 				break;
       
   949 				}
       
   950 
       
   951 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,6,serviceAvailability);
       
   952 			if(ret!=KErrNone)
       
   953 				{
       
   954 				break;
       
   955 				}
       
   956 
       
   957 			ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,7,entryValid);
       
   958 			if(ret!=KErrNone)
       
   959 				{
       
   960 				entryValid = 0; //default Entry is Invalid
       
   961 				}
       
   962 			TMbmsMonitorListParams mbmsMonitorParams;
       
   963 
       
   964 			mbmsMonitorParams.iDuration = duration;
       
   965 			mbmsMonitorParams.iMCC = mcc;
       
   966 			mbmsMonitorParams.iMNC = mnc;
       
   967 			mbmsMonitorParams.iServiceId = serviceId;
       
   968 			mbmsMonitorParams.iAccessBearer = reinterpret_cast<TMbmsScope&> (accessBearer);
       
   969 			mbmsMonitorParams.iServiceMode = reinterpret_cast<TMbmsServiceMode&> (serviceMode);
       
   970 			mbmsMonitorParams.iAvailStatus = reinterpret_cast<TMbmsAvailabilityStatus&> (serviceAvailability);
       
   971 			mbmsMonitorParams.iIsEntryValid = reinterpret_cast<TBool&> (entryValid);
       
   972 
       
   973 			TRAP_IGNORE(iMbmsMonitorListParamsArray->AppendL(mbmsMonitorParams));
       
   974 
       
   975 			}
       
   976 
       
   977 			if(iMbmsBroadcastParamsArray->Count()!=0)
       
   978 				{
       
   979 				iMbmsPcktTimer->Start(iMbmsBroadcastParamsArray->At(0).iDuration,this,ETimerIdMbmsPcktService);
       
   980 				}
       
   981 			else if (iMbmsMonitorListParamsArray->Count()!=0)
       
   982 				{
       
   983 				iMbmsPcktTimer->Start(iMbmsMonitorListParamsArray->At(0).iDuration,this,ETimerIdMbmsPcktService);
       
   984 				}
       
   985 
       
   986 			if(iPacketReleaseModeArray->Count()!=0)
       
   987 				{
       
   988 				iPacketReleaseModeIndex = 0;
       
   989 				iCurrentPacketReleaseMode = iPacketReleaseModeArray->At(0).iReleaseMode;
       
   990 				iReleaseModeTimer->Start(iPacketReleaseModeArray->At(0).iDuration,this,ETimerIdPcktServReleaseMode);
       
   991 				}
       
   992 			iIncomingContextManager = CSimIncomingContextManager::NewL(iPhone, this);
       
   993 			iIncomingContextManager->LoadIncomingContextsL( KDelayIncomingContext() );
       
   994 			iIncomingContextManager->SetUseTimerOn();
       
   995 			}
       
   996 	
       
   997 
       
   998 CSimPacketService::~CSimPacketService()
       
   999 /**
       
  1000 * Trivial Destructor
       
  1001 * Closes all CObject type objects and destroys all other objects created in the ConstructL()
       
  1002 *
       
  1003 */
       
  1004 	{
       
  1005 	LOGPACKET1("CSimPacketService: Entered destructor");
       
  1006 		
       
  1007 	delete iIncomingContextManager;
       
  1008 	
       
  1009 	iMutex.Close();
       
  1010 	// delete nifs' contexts
       
  1011 	int count = iNifWrappers.Count();
       
  1012 
       
  1013 	for(TInt i = 0; i<count; i++)
       
  1014 		{
       
  1015 		iNifWrappers[i].Close();
       
  1016 		}
       
  1017 
       
  1018 	iNifWrappers.Close();
       
  1019 	
       
  1020 	if (iPcktRegStatusInfo != NULL)
       
  1021 		{
       
  1022 		iPcktRegStatusInfo->Delete(0,iPcktRegStatusInfo->Count());
       
  1023 		delete iPcktRegStatusInfo;
       
  1024 		}
       
  1025 
       
  1026 	if(iNtwkRegStatusInfo != NULL)
       
  1027 		{
       
  1028 		iNtwkRegStatusInfo->Delete(0,iNtwkRegStatusInfo->Count());
       
  1029 		delete iNtwkRegStatusInfo;
       
  1030 		}
       
  1031 
       
  1032 	delete iTimer;
       
  1033 	
       
  1034 	delete iPcktRegTimer;
       
  1035 
       
  1036 	delete iNtwkRegTimer;
       
  1037 
       
  1038 	delete iReleaseModeTimer;
       
  1039 	
       
  1040 	delete iDynamicCapsTimer;
       
  1041 	
       
  1042 	delete iMbmsPcktTimer;
       
  1043 
       
  1044 	if (iPacketReleaseModeArray != NULL)
       
  1045 		{	
       
  1046 		iPacketReleaseModeArray->Delete(0,iPacketReleaseModeArray->Count());
       
  1047 		delete iPacketReleaseModeArray;
       
  1048 		}
       
  1049 	if (iDynamicCapsArray != NULL)
       
  1050 		{
       
  1051 		iDynamicCapsArray->Delete(0,iDynamicCapsArray->Count());
       
  1052 		delete iDynamicCapsArray;
       
  1053 		}
       
  1054 	
       
  1055 	if (iSecondaryContextCountArray != NULL)
       
  1056 		{
       
  1057 		iSecondaryContextCountArray->Delete(0,iSecondaryContextCountArray->Count());
       
  1058 		delete iSecondaryContextCountArray;
       
  1059 		}
       
  1060 	
       
  1061 	if(iMbmsBroadcastParamsArray != NULL)
       
  1062 		{
       
  1063 		iMbmsBroadcastParamsArray->Delete(0,iMbmsBroadcastParamsArray->Count());
       
  1064 		delete iMbmsBroadcastParamsArray;
       
  1065 		}
       
  1066 	
       
  1067 	if(iMbmsMonitorListParamsArray != NULL)
       
  1068 		{
       
  1069 		iMbmsMonitorListParamsArray->Delete(0,iMbmsMonitorListParamsArray->Count());
       
  1070 		delete iMbmsMonitorListParamsArray;
       
  1071 		}
       
  1072 	
       
  1073 	if(iMbmsServicesList)
       
  1074 		{
       
  1075 		iMbmsServicesList->ResetAndDestroy();
       
  1076 		}
       
  1077 	delete iMbmsServicesList;
       
  1078 	
       
  1079 	// delete nifs' contexts
       
  1080 	count = iMbmsNifWrappers.Count();
       
  1081 
       
  1082 	for(TInt i = 0; i<count; i++)
       
  1083 		{
       
  1084 		iMbmsNifWrappers[i].Close();
       
  1085 		}
       
  1086 
       
  1087 	iMbmsNifWrappers.Close();
       
  1088 	
       
  1089 	delete iNtwkRegStatusChange;
       
  1090 	
       
  1091 	delete iMbmsActivation;
       
  1092 	}
       
  1093 
       
  1094 CSimPhone* CSimPacketService::PhonePtr() const
       
  1095 /**
       
  1096 * Returns a pointer to the phone (parent) object
       
  1097 *
       
  1098 * @return CSimPhone Pointer to the phone object
       
  1099 */
       
  1100 	{
       
  1101 		return iPhone; 
       
  1102 	}
       
  1103 
       
  1104 CTelObject* CSimPacketService::OpenNewObjectByNameL(const TDesC& aName)
       
  1105 /**
       
  1106 * Returns a pointer to an existing Context object identified by name.
       
  1107 * If the object is deleted then reopen it then return a handle to it.
       
  1108 *
       
  1109 * @param aName name of the Context object to be opened
       
  1110 * @return CTelObject pointer to the CSimPacketContext object or null if not possible or not found
       
  1111 * @leave Leaves if object cannot be opened or created.
       
  1112 */
       
  1113 	{
       
  1114 	CSimPacketContext*  packetContext = NULL;
       
  1115 
       
  1116 	// go through every nif, and from there through every context in nif
       
  1117 	TInt counter = iNifWrappers.Count();
       
  1118 	
       
  1119 	for(TInt i=0; i<counter; i++)
       
  1120 		{
       
  1121 		// now go through all contexts of the nif at index i
       
  1122 		TInt totalContexts = iNifWrappers[i].NumberOfContexts();
       
  1123 		for (TInt x=0; x<totalContexts; x++)
       
  1124 			{
       
  1125 			packetContext = iNifWrappers[i].GetContext(x);
       
  1126 						
       
  1127 			// if context name matches parameter, reactivate
       
  1128 			if(aName.Compare(packetContext->ContextName())==KErrNone)
       
  1129 				{
       
  1130 				iCurrentPrimaryContextIndex = i;
       
  1131 				TInt err = packetContext->ReActivate(this,aName);
       
  1132 				if(err != KErrNone)
       
  1133 					{
       
  1134 					User::Leave(err);
       
  1135 					return NULL;
       
  1136 					}	
       
  1137 				return packetContext;
       
  1138 				}
       
  1139 			}
       
  1140 		}
       
  1141 	
       
  1142 	// if the control has reached here, then the context requested is not in the PDP context
       
  1143 	// hence lets search in the list of MBMS contexts.
       
  1144 	CSimMbmsPacketContext* pcktMbmsContext = NULL;
       
  1145 	
       
  1146 	counter = iMbmsNifWrappers.Count();
       
  1147 	
       
  1148 	for(TInt i=0;i<counter;i++)
       
  1149 		{
       
  1150 		TInt totalContexts = iMbmsNifWrappers[i].NumberOfContexts();
       
  1151 		for (TInt x=0; x<totalContexts; x++)
       
  1152 			{
       
  1153 			pcktMbmsContext = iMbmsNifWrappers[i].GetContext(x);
       
  1154 						
       
  1155 			// if context name matches parameter, reactivate
       
  1156 			if(aName.Compare(pcktMbmsContext->ContextName())==KErrNone)
       
  1157 				{
       
  1158 				TInt err = pcktMbmsContext->ReActivate(this,aName);
       
  1159 				if(err != KErrNone)
       
  1160 					{
       
  1161 					User::Leave(err);
       
  1162 					return NULL;
       
  1163 					}	
       
  1164 				return pcktMbmsContext;
       
  1165 				}
       
  1166 			}
       
  1167 		}
       
  1168 	
       
  1169 	User::Leave(KErrNotFound);
       
  1170 	return NULL;
       
  1171 	}
       
  1172 
       
  1173 CTelObject* CSimPacketService::OpenNewObjectL(TDes& aNewName)
       
  1174 /**
       
  1175 * Creates a new CSimPacketContext object and returns a pointer to it.
       
  1176 *
       
  1177 * @param aName new name of the object created
       
  1178 * @return CTelObject pointer to the CSimPacketContext object created
       
  1179 * @leave Leaves if out of memory.
       
  1180 */
       
  1181 	{
       
  1182 	// Check whether the context creation is for MBMS of PDP context
       
  1183 
       
  1184 	if(aNewName.Compare(_L("MBMS_CONTEXT"))== KErrNone)  
       
  1185 		{
       
  1186 		// Processing for MBMS context creation starts
       
  1187 		CSimMbmsPacketContext* pcktMbmsContext = NULL;
       
  1188 
       
  1189 		TInt ctr = iMbmsNifWrappers.Count();
       
  1190 		TInt mbmsCnxtCount = 0;
       
  1191 		for(TInt i=0;i<ctr; i++)
       
  1192 			{
       
  1193 			TInt mbmsContextsCount = iMbmsNifWrappers[i].NumberOfContexts();
       
  1194 			for(TInt j=0;j<mbmsContextsCount;j++)
       
  1195 				{
       
  1196 				pcktMbmsContext = iMbmsNifWrappers[i].GetContext(j);
       
  1197 				RPacketContext::TContextStatus tStat = pcktMbmsContext->ContextStatus();
       
  1198 				if(tStat != RPacketContext::EStatusDeleted)
       
  1199 					{
       
  1200 					mbmsCnxtCount++;
       
  1201 					}
       
  1202 				}
       
  1203 			}
       
  1204 		if ( mbmsCnxtCount > KMaxMbmsContextSupportedByPhone )
       
  1205 			{
       
  1206 			if(iNotifyContextAdded.iNotifyPending)
       
  1207 				{
       
  1208 				iNotifyContextAdded.iNotifyPending = EFalse;
       
  1209 				ReqCompleted(iNotifyContextAdded.iNotifyHandle,KErrUmtsMaxNumOfContextExceededByPhone);
       
  1210 				}
       
  1211 			User::Leave(KErrNoMemory);
       
  1212 			return NULL;
       
  1213 			}
       
  1214 		else if (mbmsCnxtCount > KMaxMbmsContextSupportedByNetwork)
       
  1215 			{
       
  1216 			if(iNotifyContextAdded.iNotifyPending)
       
  1217 				{
       
  1218 				iNotifyContextAdded.iNotifyPending = EFalse;
       
  1219 				ReqCompleted(iNotifyContextAdded.iNotifyHandle,KMaxMbmsContextSupportedByNetwork);
       
  1220 				}
       
  1221 			User::Leave(KErrNoMemory);
       
  1222 			return NULL;
       
  1223 			}
       
  1224 		
       
  1225 		aNewName.AppendNum(++iMbmsContextNameInc);  
       
  1226 		pcktMbmsContext = CSimMbmsPacketContext::NewL(iPhone, this, aNewName);
       
  1227 		CleanupStack::PushL(pcktMbmsContext);
       
  1228 		
       
  1229 		if(pcktMbmsContext->Open()==KErrNone)
       
  1230 			{
       
  1231 			TMbmsNifWrapper tMbmsNif;
       
  1232 			tMbmsNif.AddContext(pcktMbmsContext);
       
  1233 			iMbmsNifWrappers.Append(tMbmsNif);
       
  1234 			}
       
  1235 		iMbmsContextCount++;		
       
  1236 
       
  1237 		// Check for a pending line state notification.
       
  1238 		if(iNotifyContextAdded.iNotifyPending)
       
  1239 			{
       
  1240 			iNotifyContextAdded.iNotifyPending=EFalse;
       
  1241 			*(reinterpret_cast<TName*>(iNotifyContextAdded.iNotifyData))=pcktMbmsContext->ContextName();
       
  1242 			ReqCompleted(iNotifyContextAdded.iNotifyHandle,KErrNone);
       
  1243 			}
       
  1244 
       
  1245 		CleanupStack::Pop(pcktMbmsContext);
       
  1246 		return pcktMbmsContext;
       
  1247 
       
  1248 
       
  1249 		} // End of MBMS Context processing.
       
  1250 
       
  1251 	else 
       
  1252 		{
       
  1253 		// Processing for PDP context creation starts
       
  1254 		
       
  1255 		// if there are more contexts than the maximum allowed, return error code
       
  1256 		CSimPacketContext*  packetContext = NULL;
       
  1257 
       
  1258 		// go through every nif, and from there through every context in nif
       
  1259 		TInt counter = iNifWrappers.Count();
       
  1260 		TInt contextCount=0;
       
  1261 
       
  1262 		for(TInt i=0; i<counter; i++)
       
  1263 			{
       
  1264 			// now go through all contexts of the nif at index i
       
  1265 			TInt totalContexts = iNifWrappers[i].NumberOfContexts();
       
  1266 			for (TInt x=0; x<totalContexts; x++)
       
  1267 				{
       
  1268 				packetContext = iNifWrappers[i].GetContext(x);	
       
  1269 				RPacketContext::TContextStatus tstat = packetContext->ContextStatus();
       
  1270 				if(tstat != RPacketContext::EStatusDeleted)
       
  1271 					contextCount++;
       
  1272 				}
       
  1273 			}
       
  1274 
       
  1275 		if(contextCount >= KMaxContextPoolSize)
       
  1276 			{
       
  1277 			if(iNotifyContextAdded.iNotifyPending)
       
  1278 				{
       
  1279 				iNotifyContextAdded.iNotifyPending = EFalse;
       
  1280 				ReqCompleted(iNotifyContextAdded.iNotifyHandle,KErrNoMemory);
       
  1281 				}
       
  1282 			User::Leave(KErrNoMemory);
       
  1283 			return NULL;
       
  1284 			}
       
  1285 
       
  1286 		CSimPacketContext* newContext;
       
  1287 		
       
  1288 		// if this is not a secondary context, give the new context the primary
       
  1289 		// context name increment
       
  1290 		if (!iSecondaryContext)
       
  1291 			{
       
  1292 			aNewName.Append(KSimPacketPrimaryContextName); 
       
  1293 			aNewName.AppendNum(++iPrimaryContextNameInc);
       
  1294 
       
  1295 			newContext = CSimPacketContext::NewL(iPhone, this, aNewName);
       
  1296 			CleanupStack::PushL(newContext);
       
  1297 			if (newContext->Open() == KErrNone)
       
  1298 				{
       
  1299 				TNifWrapper nif;
       
  1300 				nif.AddContext(newContext);
       
  1301 				iNifWrappers.Append(nif);
       
  1302 				iCurrentPrimaryContextIndex = iNifWrappers.Count() - 1;
       
  1303 				}
       
  1304 
       
  1305 			// for every primary context, add an element in the array so that a count
       
  1306 			// can be kept for each primary's secondary contexts
       
  1307 			iSecondaryContextCountArray->AppendL(iCurrentPrimaryContextIndex);
       
  1308 			iCurrentPrimaryContextIndex++;
       
  1309 			}
       
  1310 		else
       
  1311 			{ 
       
  1312 			// if this is a secondary context, name it accordingly
       
  1313 			// and increment the count of the secondary's primary context
       
  1314 			aNewName.Append(KSimPacketSecondaryContextName);
       
  1315 			iSecondaryContextCountArray->At(iCurrentPrimaryContextIndex)++;
       
  1316 			aNewName.AppendNum(iSecondaryContextCountArray->At(iCurrentPrimaryContextIndex));
       
  1317 
       
  1318 			newContext = CSimPacketContext::NewL(iPhone, this, aNewName);
       
  1319 			CleanupStack::PushL(newContext);
       
  1320 
       
  1321 			if(newContext->Open()==KErrNone)
       
  1322 				{
       
  1323 				iNifWrappers[iCurrentPrimaryContextIndex].AddContext(newContext);
       
  1324 				iSecondaryContextNameInc++;	// keep a global count of number of secondary contexts
       
  1325 				}
       
  1326 			}
       
  1327 		iContextCount++;
       
  1328 
       
  1329 		// Check for a pending line state notification.
       
  1330 		if(iNotifyContextAdded.iNotifyPending)
       
  1331 			{
       
  1332 			iNotifyContextAdded.iNotifyPending=EFalse;
       
  1333 			*(TName*)iNotifyContextAdded.iNotifyData=newContext->ContextName();
       
  1334 			ReqCompleted(iNotifyContextAdded.iNotifyHandle,KErrNone);
       
  1335 			}
       
  1336 
       
  1337 		// ie assume false until PrepareOpenSecondary() is called again
       
  1338 		iSecondaryContext = EFalse;
       
  1339 		CleanupStack::Pop(newContext);
       
  1340 		return newContext;
       
  1341 		}
       
  1342 	}
       
  1343 
       
  1344 CTelObject::TReqMode CSimPacketService::ReqModeL(const TInt aIpc)
       
  1345 /**
       
  1346 * ReqModeL is called from the server's CTelObject::ReqAnalyserL
       
  1347 * in order to check the type of request it has.
       
  1348 * 
       
  1349 * 
       
  1350 * @param aIpc the ipc number that identifies the client request
       
  1351 * @return CTelObject::TReqMode The request mode to be used for this request
       
  1352 * @leave Leaves if not supported by this tsy
       
  1353 */	
       
  1354 	{
       
  1355 	CTelObject::TReqMode ret=0;
       
  1356 	switch (aIpc)
       
  1357 		{
       
  1358 		case EPacketAttach:
       
  1359 		case EPacketDetach:
       
  1360 		case EPacketRejectActivationRequest:
       
  1361 		case EPacketSetMSClass:
       
  1362 		case EPacketSetAttachMode:
       
  1363 		case EPacketSetDefaultContextParams:
       
  1364 		case EPacketGetStatus:
       
  1365 		case EPacketGetContextInfo:
       
  1366 		case EPacketGetNtwkRegStatus:
       
  1367 		case EPacketGetMSClass:
       
  1368 		case EPacketGetStaticCaps:
       
  1369 		case EPacketGetDynamicCaps:
       
  1370 		case EPacketGetAttachMode:
       
  1371 		case EPacketGetDefaultContextParams:
       
  1372 		case EPacketEnumerateContexts:
       
  1373 		case EPacketGetCurrentReleaseMode:
       
  1374 		case EPacketEnumerateNifs:
       
  1375 		case EPacketGetNifInfo:
       
  1376 		case EPacketEnumerateContextsInNif:
       
  1377 		case EPacketGetContextNameInNif:
       
  1378 		case EPacketPrepareOpenSecondary:
       
  1379 		case EPacketGetMbmsNetworkServiceStatus:
       
  1380 		case EPacketUpdateMbmsMonitorServiceList:
       
  1381 		case EPacketGetMbmsMonitoredServicesPhase1:
       
  1382 		case EPacketGetMbmsMonitoredServicesPhase2:
       
  1383 		case EPacketEnumerateMbmsMonitorServiceList:
       
  1384 		case EPacketEnumerateMbmsActiveServiceList:
       
  1385 			break;
       
  1386 
       
  1387 		case EPacketNotifyContextAdded:
       
  1388 		case EPacketNotifyStatusChange:
       
  1389 		case EPacketNotifyContextActivationRequested:
       
  1390 		case EPacketNotifyChangeOfNtwkRegStatus:
       
  1391 		case EPacketNotifyMSClassChange:
       
  1392 		case EPacketNotifyDynamicCapsChange:
       
  1393 		case EPacketNotifyReleaseModeChange:
       
  1394 		case EPacketNotifyAttachModeChange:
       
  1395 		case EPacketNotifyMbmsNetworkServiceStatusChange:
       
  1396 		case EPacketNotifyMbmsServiceAvailabilityChange:
       
  1397 			ret=KReqModeMultipleCompletionEnabled | KReqModeRePostImmediately;
       
  1398 			break;
       
  1399 
       
  1400 		default:
       
  1401 			User::Leave(KErrNotSupported);
       
  1402 			break;
       
  1403 		}
       
  1404 	return ret;
       
  1405 	}
       
  1406 
       
  1407 RHandleBase* CSimPacketService::GlobalKernelObjectHandle()
       
  1408 /**
       
  1409 * Implements CSubSessionExtBase virtual method, which provides
       
  1410 * handle of the mutex object to etel server that passes it up to clients.
       
  1411 * @return pointer to synchronisation mutex object
       
  1412 */
       
  1413 	{
       
  1414 		return &iMutex;
       
  1415 	}
       
  1416 
       
  1417 TInt CSimPacketService::RegisterNotification(const TInt aIpc)
       
  1418 /**
       
  1419 * RegisterNotification is called when the server recognises that this notification
       
  1420 * is being posted for the first time on this sub-session object.
       
  1421 * 
       
  1422 * It enables the TSY to "turn on" any regular notification messages that it may receive 
       
  1423 * from the phone
       
  1424 *
       
  1425 * @param aIpc the ipc number that identifies the client request
       
  1426 * @return err KErrNone if fine
       
  1427 */
       
  1428 	{
       
  1429 	switch (aIpc)
       
  1430 		{
       
  1431 		case EPacketNotifyContextAdded:
       
  1432 		case EPacketNotifyStatusChange:
       
  1433 		case EPacketNotifyContextActivationRequested:
       
  1434 		case EPacketNotifyChangeOfNtwkRegStatus:
       
  1435 		case EPacketNotifyMSClassChange:
       
  1436 		case EPacketNotifyDynamicCapsChange:
       
  1437 		case EPacketNotifyReleaseModeChange:
       
  1438 		case EPacketNotifyAttachModeChange:
       
  1439 		case EPacketNotifyMbmsNetworkServiceStatusChange:
       
  1440 		case EPacketNotifyMbmsServiceAvailabilityChange:
       
  1441 			LOGPACKET1("CSimPacketService: RegisterNotification");
       
  1442 			return KErrNone;
       
  1443 		default:
       
  1444 			// Unknown or invalid IPC
       
  1445 			LOGPACKET1("CSimPacketService: Register error, unknown IPC");
       
  1446 			return KErrNotSupported;
       
  1447 		}
       
  1448 	}
       
  1449 
       
  1450 TInt CSimPacketService::DeregisterNotification(const TInt aIpc)
       
  1451 /**
       
  1452 * DeregisterNotification is called when the server recognises that this notification
       
  1453 * will not be posted again because the last client to have a handle on this sub-session
       
  1454 * object has just closed the handle.
       
  1455 *
       
  1456 * It enables the TSY to "turn off" any regular notification messages that it may 
       
  1457 * receive from the phone
       
  1458 *
       
  1459 * @param aIpc the ipc number that identifies the client request
       
  1460 * @return err KErrNone if fine
       
  1461 */
       
  1462 	{
       
  1463 	switch (aIpc)
       
  1464 		{
       
  1465 		case EPacketNotifyContextAdded:
       
  1466 		case EPacketNotifyStatusChange:
       
  1467 		case EPacketNotifyContextActivationRequested:
       
  1468 		case EPacketNotifyChangeOfNtwkRegStatus:
       
  1469 		case EPacketNotifyMSClassChange:
       
  1470 		case EPacketNotifyDynamicCapsChange:
       
  1471 		case EPacketNotifyReleaseModeChange:
       
  1472 		case EPacketNotifyAttachModeChange:
       
  1473 		case EPacketNotifyMbmsNetworkServiceStatusChange:
       
  1474 		case EPacketNotifyMbmsServiceAvailabilityChange:
       
  1475 			LOGPACKET1("CSimPacketService: DeregisterNotification");
       
  1476 			return KErrNone;
       
  1477 		default:
       
  1478 			// Unknown or invalid IPC
       
  1479 			LOGPACKET1("CSimPacketService: Deregister error, unknown IPC");
       
  1480 			return KErrNotSupported;
       
  1481 		}
       
  1482 	}
       
  1483 
       
  1484 TInt CSimPacketService::NumberOfSlotsL(const TInt aIpc)
       
  1485 /**
       
  1486 * NumberOfSlotsL is called by the server when it is registering a new notification
       
  1487 * It enables the TSY to tell the server how many buffer slots to allocate for
       
  1488 * "repost immediately" notifications that may trigger before clients collect them
       
  1489 *
       
  1490 * @param aIpc the ipc number that identifies the client request
       
  1491 * @return err KErrNone if fine
       
  1492 */
       
  1493 	{
       
  1494 	TInt numberOfSlots=1;
       
  1495 	switch (aIpc)
       
  1496 		{
       
  1497 		case EPacketNotifyStatusChange:
       
  1498 		case EPacketNotifyDynamicCapsChange:
       
  1499 		case EPacketNotifyMbmsNetworkServiceStatusChange:
       
  1500 			LOGPACKET1("CSimPacketService: Registered with 10 slots");
       
  1501 			numberOfSlots=10;
       
  1502 			break;
       
  1503 		case EPacketNotifyContextAdded:
       
  1504 		case EPacketNotifyContextActivationRequested:
       
  1505 		case EPacketNotifyChangeOfNtwkRegStatus:
       
  1506 		case EPacketNotifyMSClassChange:
       
  1507 		case EPacketNotifyReleaseModeChange:
       
  1508 		case EPacketNotifyAttachModeChange:
       
  1509 		case EPacketNotifyMbmsServiceAvailabilityChange:
       
  1510 			LOGPACKET1("CSimPacketService: Registered with 2 slots");
       
  1511 			numberOfSlots=2;
       
  1512 			break;
       
  1513 		default:
       
  1514 			// Unknown or invalid IPC
       
  1515 			LOGPACKET1("CSimPacketService: Number of Slots error, unknown IPC");
       
  1516 			User::Leave(KErrNotSupported);
       
  1517 			break;
       
  1518 		}  
       
  1519 	return numberOfSlots;
       
  1520 	}
       
  1521 
       
  1522 
       
  1523 TInt CSimPacketService::ExtFunc(const TTsyReqHandle aTsyReqHandle,const TInt aIpc,
       
  1524 							  const TDataPackage& aPackage)
       
  1525 /**
       
  1526 * ExtFunc is called by the server when it has a "extended", i.e. non-core ETel request
       
  1527 * for the TSY to process.
       
  1528 * A request handle, request type and request data are passed to the TSY
       
  1529 * 
       
  1530 * @param aTsyReqHandle  The request handle for completing the request 
       
  1531 * @param aIpc Ipc representing the request
       
  1532 * @param aPackage any data associated with the request
       
  1533 * @return err KErrNone if request completes ok
       
  1534 */
       
  1535 	{
       
  1536 	TAny* dataPtr=aPackage.Ptr1();
       
  1537 	TAny* dataPtr2=aPackage.Ptr2();
       
  1538 
       
  1539 	switch (aIpc)
       
  1540 		{
       
  1541 		case EPacketNotifyContextAdded:
       
  1542 			return NotifyContextAdded(aTsyReqHandle, aPackage.Des1u());
       
  1543 		case EPacketGetStatus:
       
  1544 			return GetStatus(aTsyReqHandle,
       
  1545 					REINTERPRET_CAST(RPacketService::TStatus*, dataPtr));
       
  1546 		case EPacketNotifyStatusChange:
       
  1547 			return NotifyStatusChange(aTsyReqHandle,
       
  1548 					REINTERPRET_CAST(RPacketService::TStatus*, dataPtr));
       
  1549 		case EPacketNotifyContextActivationRequested:
       
  1550 			return NotifyContextActivationRequested(aTsyReqHandle, 
       
  1551 					aPackage.Des1n());
       
  1552 		case EPacketEnumerateContexts:
       
  1553 			return EnumerateContexts(aTsyReqHandle,
       
  1554 					REINTERPRET_CAST(TInt*, dataPtr),
       
  1555 					REINTERPRET_CAST(TInt*, dataPtr2));
       
  1556 		case EPacketGetContextInfo:
       
  1557 			return GetContextInfo(aTsyReqHandle,
       
  1558 					REINTERPRET_CAST(TInt*, dataPtr),
       
  1559 					REINTERPRET_CAST(RPacketService::TContextInfo*, dataPtr2));
       
  1560 		case EPacketGetNtwkRegStatus:
       
  1561 			return GetNtwkRegStatus(aTsyReqHandle,
       
  1562 					REINTERPRET_CAST(RPacketService::TRegistrationStatus*, dataPtr));
       
  1563 		case EPacketNotifyChangeOfNtwkRegStatus:
       
  1564 			return NotifyChangeOfNtwkRegStatus(aTsyReqHandle,
       
  1565 					REINTERPRET_CAST(RPacketService::TRegistrationStatus*, dataPtr));
       
  1566 		case EPacketGetMSClass:
       
  1567 			return GetMSClass(aTsyReqHandle,
       
  1568 					REINTERPRET_CAST(RPacketService::TMSClass*, dataPtr),
       
  1569 					REINTERPRET_CAST(RPacketService::TMSClass*, dataPtr2));
       
  1570 		case EPacketSetMSClass:
       
  1571 			return SetMSClass(aTsyReqHandle,
       
  1572 					REINTERPRET_CAST(RPacketService::TMSClass*, dataPtr));
       
  1573 		case EPacketNotifyMSClassChange:
       
  1574 			return NotifyMSClassChange(aTsyReqHandle,
       
  1575 					REINTERPRET_CAST(RPacketService::TMSClass*, dataPtr));
       
  1576 		case EPacketGetStaticCaps:
       
  1577 			return GetStaticCaps(aTsyReqHandle, 
       
  1578 					REINTERPRET_CAST(TUint*, dataPtr),
       
  1579 					REINTERPRET_CAST(RPacketContext::TProtocolType*, dataPtr2));
       
  1580 		case EPacketGetDynamicCaps:
       
  1581 			return GetDynamicCaps(aTsyReqHandle,
       
  1582 					REINTERPRET_CAST(RPacketService::TDynamicCapsFlags*, dataPtr));
       
  1583 		case EPacketNotifyDynamicCapsChange:
       
  1584 			return NotifyDynamicCapsChange(aTsyReqHandle,
       
  1585 					REINTERPRET_CAST(RPacketService::TDynamicCapsFlags*, dataPtr));
       
  1586 		case EPacketSetAttachMode:
       
  1587 			return SetAttachMode(aTsyReqHandle,
       
  1588 					REINTERPRET_CAST(RPacketService::TAttachMode*, dataPtr));
       
  1589 		case EPacketGetAttachMode:
       
  1590 			return GetAttachMode(aTsyReqHandle,
       
  1591 					REINTERPRET_CAST(RPacketService::TAttachMode*, dataPtr));
       
  1592 		case EPacketNotifyAttachModeChange:
       
  1593 			return NotifyAttachModeChange(aTsyReqHandle,
       
  1594 					REINTERPRET_CAST(RPacketService::TAttachMode*, dataPtr));
       
  1595 		case EPacketAttach:
       
  1596 			return Attach(aTsyReqHandle);
       
  1597 		case EPacketDetach:
       
  1598 			return Detach(aTsyReqHandle);
       
  1599 		case EPacketRejectActivationRequest:
       
  1600 			return RejectActivationRequest(aTsyReqHandle);
       
  1601 		case EPacketSetDefaultContextParams:
       
  1602 			return SetDefaultContextParams(aTsyReqHandle, aPackage.Des1n());
       
  1603 		case EPacketGetDefaultContextParams:
       
  1604 			return GetDefaultContextParams(aTsyReqHandle, aPackage.Des1n());
       
  1605 		case EPacketGetCurrentReleaseMode:
       
  1606 			return GetCurrentReleaseMode(aTsyReqHandle, REINTERPRET_CAST(RPacketService::TPacketReleaseMode*, dataPtr));
       
  1607 		case EPacketNotifyReleaseModeChange:
       
  1608 			return NotifyReleaseModeChange(aTsyReqHandle,
       
  1609 					REINTERPRET_CAST(RPacketService::TPacketReleaseMode*, dataPtr));
       
  1610 		case EPacketEnumerateNifs:
       
  1611 			return EnumerateNifs(aTsyReqHandle, *(REINTERPRET_CAST(TInt*, dataPtr)));
       
  1612 		case EPacketGetNifInfo:
       
  1613 			return GetNifInfo(aTsyReqHandle, *REINTERPRET_CAST(TInt*, dataPtr), aPackage.Des2n());
       
  1614 		case EPacketEnumerateContextsInNif:
       
  1615 			return EnumerateContextsInNif(aTsyReqHandle, aPackage.Des2u(), *REINTERPRET_CAST(TInt*, dataPtr));			
       
  1616 		case EPacketGetContextNameInNif:
       
  1617 			return GetContextNameInNif(aTsyReqHandle, aPackage.Des2u(), *REINTERPRET_CAST(TInt*, dataPtr), aPackage.Des2u());
       
  1618 		case EPacketPrepareOpenSecondary:
       
  1619 			//return PrepareOpenSecondary(aTsyReqHandle, *REINTERPRET_CAST(TDesC*, dataPtr));
       
  1620 			return PrepareOpenSecondary(aTsyReqHandle, aPackage.Des1u());
       
  1621 		case EPacketGetNifInfoCancel:
       
  1622 			return GetNifInfoCancel(aTsyReqHandle);
       
  1623 		case EPacketGetMbmsNetworkServiceStatus:
       
  1624 			return GetMbmsNetworkServiceStatus(aTsyReqHandle, reinterpret_cast<TBool> (dataPtr),
       
  1625 					reinterpret_cast<TMbmsNetworkServiceStatus*> (dataPtr2));
       
  1626 		case EPacketNotifyMbmsNetworkServiceStatusChange:
       
  1627 			return NotifyMbmsNetworkServiceStatusChange(aTsyReqHandle,
       
  1628 					reinterpret_cast<TMbmsNetworkServiceStatus*>(dataPtr));
       
  1629 		case EPacketNotifyMbmsServiceAvailabilityChange:
       
  1630 			return NotifyMbmsServiceAvailabilityChange(aTsyReqHandle);
       
  1631 		case EPacketUpdateMbmsMonitorServiceList:
       
  1632 			TInt retValue;
       
  1633 			TInt err;
       
  1634 			if(dataPtr2)
       
  1635 				{
       
  1636 				TRAP(err, retValue = UpdateMbmsMonitorServiceListL(aTsyReqHandle,
       
  1637 					reinterpret_cast<TMbmsAction*>(dataPtr),aPackage.Des2n()));
       
  1638 				}
       
  1639 			else
       
  1640 				{
       
  1641 				TRAP(err, retValue = UpdateMbmsMonitorServiceListL(aTsyReqHandle,
       
  1642 					reinterpret_cast<TMbmsAction*>(dataPtr)));
       
  1643 				}
       
  1644 			if(err != KErrNone)
       
  1645 				{
       
  1646 				retValue = err;
       
  1647 				}
       
  1648 			return retValue;
       
  1649 		case EPacketGetMbmsMonitoredServicesPhase1:
       
  1650 			return GetMbmsMonitoredServicesListPhase1(aTsyReqHandle, 
       
  1651 					reinterpret_cast<TClientId*>(dataPtr), 
       
  1652 					reinterpret_cast<TInt*>(dataPtr2));
       
  1653 		case EPacketGetMbmsMonitoredServicesPhase2:
       
  1654 			return GetMbmsMonitoredServicesListPhase2(aTsyReqHandle, 
       
  1655 					reinterpret_cast<TClientId*>(dataPtr), aPackage.Des2n());	
       
  1656 		case EPacketEnumerateMbmsMonitorServiceList:
       
  1657 			return EnumerateMbmsMonitorServiceList(aTsyReqHandle,
       
  1658 					reinterpret_cast<TInt*>(dataPtr),
       
  1659 					reinterpret_cast<TInt*>(dataPtr2));
       
  1660 		case EPacketEnumerateMbmsActiveServiceList:
       
  1661 			return EnumerateMbmsActiveServiceList(aTsyReqHandle,
       
  1662 					reinterpret_cast<TInt*>(dataPtr),
       
  1663 					reinterpret_cast<TInt*>(dataPtr2));
       
  1664 		default:
       
  1665 			return KErrNotSupported;
       
  1666 		}
       
  1667 	}
       
  1668 
       
  1669 TInt CSimPacketService::CancelService(const TInt aIpc,const TTsyReqHandle aTsyReqHandle)
       
  1670 /**
       
  1671 * CancelService is called by the server when it is "cleaning-up" any still outstanding
       
  1672 * asynchronous requests before closing a client's sub-session.
       
  1673 * This will happen if a client closes its R-class handle without cancelling outstanding asynchronous requests.
       
  1674 * 
       
  1675 *  This function will be called when a client explicitly cancels
       
  1676 *
       
  1677 * @param aTsyReqHandle  The request handle for completing the request 
       
  1678 * @param aIpc Ipc representing the request
       
  1679 * @return err KErrNone if request completes ok
       
  1680 */
       
  1681 	{
       
  1682 	LOGPACKET1("CSimPacketService: - CancelService called");
       
  1683 	switch (aIpc)
       
  1684 		{
       
  1685 		case EPacketNotifyContextAdded:
       
  1686 			return NotifyContextAddedCancel(aTsyReqHandle);
       
  1687 		case EPacketAttach:
       
  1688 			return AttachCancel(aTsyReqHandle);
       
  1689 		case EPacketDetach:
       
  1690 			return DetachCancel(aTsyReqHandle);
       
  1691 		case EPacketNotifyStatusChange:
       
  1692 			return NotifyStatusChangeCancel(aTsyReqHandle);
       
  1693 		case EPacketNotifyContextActivationRequested:
       
  1694 			return NotifyContextActivationRequestedCancel(aTsyReqHandle);
       
  1695 		case EPacketRejectActivationRequest:
       
  1696 			return RejectActivationRequestCancel(aTsyReqHandle);
       
  1697 		case EPacketGetContextInfo:
       
  1698 			return GetContextInfoCancel(aTsyReqHandle);
       
  1699 		case EPacketNotifyChangeOfNtwkRegStatus:
       
  1700 			return NotifyChangeOfNtwkRegStatusCancel(aTsyReqHandle);
       
  1701 		case EPacketGetMSClass:
       
  1702 			return GetMSClassCancel(aTsyReqHandle);
       
  1703 		case EPacketSetMSClass:
       
  1704 			return SetMSClassCancel(aTsyReqHandle);
       
  1705 		case EPacketNotifyMSClassChange:
       
  1706 			return NotifyMSClassChangeCancel(aTsyReqHandle);
       
  1707 		case EPacketNotifyDynamicCapsChange:
       
  1708 			return NotifyDynamicCapsChangeCancel(aTsyReqHandle);
       
  1709 		case EPacketEnumerateContextsCancel:
       
  1710 			return EnumerateContextsCancel(aTsyReqHandle);
       
  1711 		case EPacketGetCurrentReleaseMode:
       
  1712 			return GetCurrentReleaseModeCancel(aTsyReqHandle);
       
  1713 		case EPacketNotifyReleaseModeChange:
       
  1714 			return NotifyReleaseModeChangeCancel(aTsyReqHandle);
       
  1715 		case EPacketEnumerateNifs:
       
  1716 			return EnumerateNifsCancel(aTsyReqHandle);
       
  1717 		case EPacketGetNifInfo:
       
  1718 			return GetNifInfoCancel(aTsyReqHandle);
       
  1719 		case EPacketEnumerateContextsInNif:	
       
  1720 			return EnumerateContextsInNifCancel(aTsyReqHandle);
       
  1721 		case EPacketGetContextNameInNif:
       
  1722 			return GetContextNameInNifCancel(aTsyReqHandle);
       
  1723 		case EPacketNotifyAttachModeChange:
       
  1724 			return NotifyAttachModeChangeCancel(aTsyReqHandle);
       
  1725 		case EPacketGetMbmsNetworkServiceStatus:
       
  1726 			return GetMbmsNetworkServiceStatusCancel(aTsyReqHandle);
       
  1727 		case EPacketNotifyMbmsNetworkServiceStatusChange:
       
  1728 			return NotifyMbmsNetworkServiceStatusChangeCancel(aTsyReqHandle);
       
  1729 		case EPacketNotifyMbmsServiceAvailabilityChange:
       
  1730 			return NotifyMbmsServiceAvailabilityChangeCancel(aTsyReqHandle);
       
  1731 		case EPacketUpdateMbmsMonitorServiceList:
       
  1732 			return UpdateMbmsMonitorServiceListCancel(aTsyReqHandle);
       
  1733 		case EPacketGetMbmsMonitoredServicesPhase1:
       
  1734 		case EPacketGetMbmsMonitoredServicesPhase2:
       
  1735 			return GetMbmsMonitoredServicesListCancel(aTsyReqHandle);
       
  1736 		case EPacketEnumerateMbmsMonitorServiceList:
       
  1737 			return EnumerateMbmsMonitorServiceListCancel(aTsyReqHandle);
       
  1738 		case EPacketEnumerateMbmsActiveServiceList:
       
  1739 			return EnumerateMbmsActiveServiceListCancel(aTsyReqHandle);
       
  1740 
       
  1741 		default:
       
  1742 			return KErrGeneral; 
       
  1743 		} 
       
  1744 	}
       
  1745 
       
  1746 TInt CSimPacketService::NotifyContextAdded(const TTsyReqHandle aTsyReqHandle, TDes* aContextId)
       
  1747 /**
       
  1748 * Record a client's interest in being notified when a new context is added to the network.
       
  1749 * First check that there isn't already a notification pending (the ETel Server should protect
       
  1750 * against this) and then record the information necessary to complete the request later, when
       
  1751 * the status does actually change.
       
  1752 *
       
  1753 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1754 * @param aContextId pointer to the packet context data
       
  1755 * @return KErrNone
       
  1756 */
       
  1757 	{
       
  1758 	__ASSERT_ALWAYS(!iNotifyContextAdded.iNotifyPending,SimPanic(ENotificationAlreadyPending));
       
  1759 
       
  1760 	iNotifyContextAdded.iNotifyPending = ETrue;
       
  1761 	iNotifyContextAdded.iNotifyHandle = aTsyReqHandle;
       
  1762 	iNotifyContextAdded.iNotifyData = aContextId;
       
  1763 	return KErrNone;
       
  1764 	}
       
  1765 
       
  1766 TInt CSimPacketService::NotifyContextAddedCancel(const TTsyReqHandle aTsyReqHandle)
       
  1767 /**
       
  1768 * Cancel a client's interest in being notified when a new context is added.
       
  1769 * This is acheived simply by resetting the flag that indicates a notification is pending.
       
  1770 * 
       
  1771 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  1772 * @return KErrNone
       
  1773 */
       
  1774 	{
       
  1775 	LOGPACKET1("CSimPacketService::NotifyContextAddedCancel called");
       
  1776 	if(iNotifyContextAdded.iNotifyPending)
       
  1777 		{
       
  1778 		iNotifyContextAdded.iNotifyPending=EFalse;
       
  1779 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  1780 		}
       
  1781 	return KErrNone;
       
  1782 	}
       
  1783 
       
  1784 TInt CSimPacketService::Attach(const TTsyReqHandle aTsyReqHandle)
       
  1785 /**
       
  1786 * Client calls this method to attach to the service network.
       
  1787 * In this TSY, the request is registered then the state machine (ActionEvent) is called
       
  1788 * to handle the request making sure that the class state is updated and the phone is informed.
       
  1789 *
       
  1790 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1791 * @return TInt KErrnone if request completes ok
       
  1792 */
       
  1793 	{
       
  1794 	LOGPACKET1("CSimPacketService::Attach called");
       
  1795 	iAttachRequestHandle=aTsyReqHandle;
       
  1796 	return ActionEvent(EPacketEventAttach);
       
  1797 	}
       
  1798 
       
  1799 TInt CSimPacketService::AttachCancel(const TTsyReqHandle aTsyReqHandle)
       
  1800 /**
       
  1801 * Cancels a clients interest in attaching to a network.
       
  1802 * this can only be achieved if we're not already attached otherwise the request is ignored.
       
  1803 *
       
  1804 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1805 * @return TInt KErrnone if request completes ok
       
  1806 */
       
  1807 	{
       
  1808 	LOGPACKET1("CSimPacketService::AttachCancel called");
       
  1809 	if((iState == RPacketService::EStatusUnattached) && (iCurrentEvent==EPacketEventAttach))
       
  1810 		{
       
  1811 		iTimer->Cancel();
       
  1812 		iCurrentEvent= EPacketEventNone;
       
  1813 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  1814 		}
       
  1815 	return KErrNone;
       
  1816 	}
       
  1817 
       
  1818 /***
       
  1819 * This function will detach the packet service and all its contexts from the network
       
  1820 ***/
       
  1821 TInt CSimPacketService::DoDetach()
       
  1822 	{
       
  1823 	TInt ret=KErrNone;
       
  1824 
       
  1825 	switch(iState)
       
  1826 		{
       
  1827 		case RPacketService::EStatusUnattached:
       
  1828 			break;
       
  1829 
       
  1830 		case RPacketService::EStatusAttached:
       
  1831 			ret=ChangeState(RPacketService::EStatusUnattached);
       
  1832 			ReqCompleted(iDetachRequestHandle,ret);
       
  1833 			break;
       
  1834 
       
  1835 		case RPacketService::EStatusActive:
       
  1836 		case RPacketService::EStatusSuspended:
       
  1837 			{
       
  1838 			TInt totalWrappers = iNifWrappers.Count();
       
  1839 				
       
  1840 			// deactivate all contexts in every nif
       
  1841 			for(TInt j=0; j < totalWrappers; j++)
       
  1842 				{
       
  1843 				TInt totalContexts = iNifWrappers[j].NumberOfContexts();
       
  1844 				for(TInt x =0; x<totalContexts; x++)
       
  1845 					{
       
  1846 					ret = iNifWrappers[j].GetContext(x)->AttemptDeactivateImmediately();
       
  1847 					if(ret!=KErrNone)
       
  1848 						{
       
  1849 						break;
       
  1850 						}
       
  1851 					}
       
  1852 				}
       
  1853 	
       
  1854 			if(ret==KErrNone)
       
  1855 				{
       
  1856 					ret=ChangeState(RPacketService::EStatusUnattached);
       
  1857 				}
       
  1858 				ReqCompleted(iDetachRequestHandle,ret);
       
  1859 			}
       
  1860 			break;
       
  1861 		default:
       
  1862 			break;
       
  1863 		}
       
  1864 	return ret;
       
  1865 	}
       
  1866 TInt CSimPacketService::Detach(const TTsyReqHandle aTsyReqHandle)
       
  1867 /**
       
  1868 * Client calls this method to detach from the service network.
       
  1869 * In this TSY, the request is registered then the state machine (ActionEvent) is called
       
  1870 * to handle the request making sure that the class state is updated and the phone is informed.
       
  1871 *
       
  1872 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1873 * @return TInt KErrnone if request completes ok
       
  1874 */
       
  1875 	{
       
  1876 	LOGPACKET1("CSimPacketService::Detach called");
       
  1877 	iDetachRequestHandle=aTsyReqHandle;
       
  1878 	return ActionEvent(EPacketEventDetach);
       
  1879 	}
       
  1880 
       
  1881 TInt CSimPacketService::DetachCancel(const TTsyReqHandle aTsyReqHandle)
       
  1882 /**
       
  1883 * Cancels a clients interest in detaching from the network.
       
  1884 * this can only be achieved if we're not already attached and in the process of detaching
       
  1885 * but not detached yet otherwise the request is ignored.
       
  1886 *
       
  1887 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1888 * @return TInt KErrnone if request completes ok
       
  1889 */
       
  1890 	{
       
  1891 	LOGPACKET1("CSimPacketService::DetachCancel called");
       
  1892 	if((iState == RPacketService::EStatusAttached) && (iCurrentEvent==EPacketEventDetach))
       
  1893 			{
       
  1894 			iTimer->Cancel();
       
  1895 			iCurrentEvent= EPacketEventNone;
       
  1896 			ReqCompleted(aTsyReqHandle,KErrCancel);
       
  1897 			}
       
  1898 	return KErrNone;
       
  1899 	}
       
  1900 
       
  1901 TInt CSimPacketService::GetStatus(const TTsyReqHandle aTsyReqHandle, RPacketService::TStatus* aStatus)
       
  1902 /**
       
  1903 * Retrieves and returns the status of the Packet service
       
  1904 *
       
  1905 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1906 * @param aStatus pointer to the status
       
  1907 * @return TInt err KErrNone if ok
       
  1908 */
       
  1909 	{
       
  1910 	LOGPACKET1("CSimPacketService::GetStatus called");
       
  1911 	*aStatus = iState;
       
  1912 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  1913 	return KErrNone;
       
  1914 	}
       
  1915 
       
  1916 TInt CSimPacketService::NotifyStatusChange(const TTsyReqHandle aTsyReqHandle, RPacketService::TStatus* aStatus)
       
  1917 /**
       
  1918 * Record a client's interest in being notified of the state of the packet network and contexts.
       
  1919 * First check that there isn't already a notification pending (the ETel Server should protect
       
  1920 * against this) and then record the information necessary to complete the request later, when
       
  1921 * the status does actually change.
       
  1922 *
       
  1923 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1924 * @param aStatus pointer to the packet service status
       
  1925 * @return KErrNone
       
  1926 */
       
  1927 	{
       
  1928  	__ASSERT_ALWAYS(!iNotifyStatusChange.iNotifyPending,SimPanic(ENotificationAlreadyPending));
       
  1929 
       
  1930 	iNotifyStatusChange.iNotifyPending = ETrue;
       
  1931 	iNotifyStatusChange.iNotifyHandle = aTsyReqHandle;
       
  1932 	iNotifyStatusChange.iNotifyData = aStatus;
       
  1933 	return KErrNone;
       
  1934 	}
       
  1935 
       
  1936 TInt CSimPacketService::NotifyStatusChangeCancel(const TTsyReqHandle aTsyReqHandle)
       
  1937 /**
       
  1938 * Cancel a client's interest in being notified when the call status changes.
       
  1939 * This is acheived simply by resetting the flag that indicates a notification is pending.
       
  1940 * 
       
  1941 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  1942 * @return KErrNone
       
  1943 */
       
  1944 	{
       
  1945 	LOGPACKET1("CSimPacketService::NotifyStatusChangeCancel called");
       
  1946 	if(iNotifyStatusChange.iNotifyPending)
       
  1947 		{
       
  1948 		iNotifyStatusChange.iNotifyPending=EFalse;
       
  1949 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  1950 		}
       
  1951 	return KErrNone;
       
  1952 	}
       
  1953 
       
  1954 
       
  1955 
       
  1956 TInt CSimPacketService::NotifyContextActivationRequested(const TTsyReqHandle aTsyReqHandle, TDes8* aContextParameters)
       
  1957 /**
       
  1958 * Record a client's interest in being notified when a context is activated.
       
  1959 * First check that there isn't already a notification pending (the ETel Server should protect
       
  1960 * against this) and then record the information necessary to complete the request later, when
       
  1961 * the status does actually change.
       
  1962 *
       
  1963 * Hurricane does not support this method
       
  1964 *
       
  1965 * @param aTsyReqHandle Tsy Request handle for the client request
       
  1966 * @param aStatus pointer to the packet service status
       
  1967 * @return KErrNone
       
  1968 */
       
  1969 	{
       
  1970 	LOGPACKET1("CSimPacketService::NotifyContextActivationRequested called");
       
  1971 	
       
  1972 	iConfigData.iTsyReqHandle = aTsyReqHandle;
       
  1973 	iConfigData.iData = aContextParameters;
       
  1974 
       
  1975 	if ( iIncomingContextManager->IsUseTimerOn() )
       
  1976 		{ // Timer use is on, so we can use it.	
       
  1977 		// 1st time by the reguest for notifictaion, 
       
  1978 		// 2nd time when do ReqCompleted(aTsyReqHandle,KErrCancel);
       
  1979 		    
       
  1980 		iIncomingContextManager->StartFirstIncomingEvent();
       
  1981 			// When timer is done we have completed the request to activate a PDP.
       
  1982 		iIncomingContextManager->SetUseTimerOff();
       
  1983 		}
       
  1984 		
       
  1985 	return KErrNone;
       
  1986 	}
       
  1987 
       
  1988 TInt CSimPacketService::NotifyContextActivationRequestedCancel(const TTsyReqHandle aTsyReqHandle)
       
  1989 /**
       
  1990 * Cancel a client's interest in being notified when a context is activated.
       
  1991 * This is acheived simply by resetting the flag that indicates a notification is pending.
       
  1992 * 
       
  1993 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  1994 * @return KErrNone
       
  1995 */
       
  1996 	{
       
  1997 	LOGPACKET1("CSimPacketService::NotifyContextActivationRequestedCancel called");
       
  1998 
       
  1999 	iIncomingContextManager->Cancel();	
       
  2000 	iIncomingContextManager->SetUseTimerOff();	
       
  2001 	
       
  2002 	ReqCompleted(aTsyReqHandle, KErrNone);
       
  2003 	return KErrNone;
       
  2004 	}
       
  2005 
       
  2006 TInt CSimPacketService::RejectActivationRequest(const TTsyReqHandle aTsyReqHandle)
       
  2007 /**
       
  2008 * This method is called when a client wishes to reject an Activation request from the network
       
  2009 * This is currently not supported in this version of the simulator tsy.
       
  2010 *
       
  2011 * Hurricane does not support this method
       
  2012 *
       
  2013 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2014 * @return KErrNone
       
  2015 */
       
  2016 	{
       
  2017 	ReqCompleted(aTsyReqHandle, KErrNotSupported);
       
  2018 	return KErrNone;
       
  2019 	}
       
  2020 
       
  2021 TInt CSimPacketService::RejectActivationRequestCancel(const TTsyReqHandle aTsyReqHandle)
       
  2022 /**
       
  2023 * This method cancels a clients' request  in rejecting an activation request.
       
  2024 * The TSY is not supporting this method
       
  2025 *
       
  2026 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  2027 * @return KErrNone
       
  2028 */
       
  2029 	{
       
  2030 	ReqCompleted(aTsyReqHandle, KErrCancel);
       
  2031 	return KErrNone;
       
  2032 	}
       
  2033 
       
  2034 TInt CSimPacketService::EnumerateContexts(const TTsyReqHandle aTsyReqHandle, TInt* aCount, TInt* aMaxAllowed)
       
  2035 /**
       
  2036 * Returns the number of contexts opened on the packet service
       
  2037 *
       
  2038 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2039 * @param aCount pointer to the number of contexts opened.
       
  2040 * @param aMaxAllowed pointer to the maximum number of contexts that can be opened on the packet service
       
  2041 * @return KErrNone
       
  2042 */
       
  2043 	{
       
  2044 	LOGPACKET1("CSimPacketService::EnumerateContexts called");
       
  2045 	// this should enumerate all primary and secondary contexts
       
  2046 	*aCount = iPrimaryContextNameInc + iSecondaryContextNameInc;
       
  2047 	*aMaxAllowed = KMaxContextPoolSize;
       
  2048 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  2049 	return KErrNone;
       
  2050 	}
       
  2051 	
       
  2052 TInt CSimPacketService::EnumerateContextsCancel(const TTsyReqHandle /*aTsyReqHandle*/)
       
  2053 /**
       
  2054 * This method cancels a clients' request in Enmerationg the contexts
       
  2055 * This does nothing as Enumerate context is processed synchronously
       
  2056 * 
       
  2057 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  2058 * @return KErrNone
       
  2059 */
       
  2060 	{
       
  2061 	LOGPACKET1("CSimPacketService::Enumerate Context Cancel called");
       
  2062 	return KErrNone;
       
  2063 	}
       
  2064 
       
  2065 TInt CSimPacketService::GetContextInfo(const TTsyReqHandle aTsyReqHandle, TInt* aIndex,RPacketService::TContextInfo* aInfo)
       
  2066 /**
       
  2067 * Retrieves a specific context info specified by the index variable
       
  2068 *
       
  2069 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2070 * @param aIndex pointer to the index of the context the info is requested from
       
  2071 * @param aInfo pointer to the context info. 
       
  2072 * @return KErrNone if context is found in the list of contexts 
       
  2073 */
       
  2074 	{
       
  2075 	LOGPACKET1("CSimPacketService::GetContextInfo called");
       
  2076 	CSimPacketContext*  packetContext;
       
  2077 
       
  2078 	if((*aIndex >= iContextCount) || (*aIndex < 0))
       
  2079 		ReqCompleted(aTsyReqHandle,KErrArgument);
       
  2080 	else {
       
  2081 		// this method is used in conjunction with EnumerateContexts() which for Jetstream
       
  2082 		// now returns the number of all contexts - not just the number of primary contexts as
       
  2083 		// was done in Hurricane. To that end, the index passed as a parameter needs to be translated
       
  2084 		// to take into account the nifwrappers array's contexts.
       
  2085 		TInt realIndex=*aIndex;
       
  2086 		TInt i;
       
  2087 		TInt wrappersCount = iNifWrappers.Count();
       
  2088 		for(i = 0; i<wrappersCount; i++)
       
  2089 			{
       
  2090 			if(iNifWrappers[i].NumberOfContexts() <= realIndex)
       
  2091 				{
       
  2092 				realIndex-=iNifWrappers[i].NumberOfContexts();
       
  2093 				continue;
       
  2094 				}
       
  2095 			else
       
  2096 				{
       
  2097 				break;
       
  2098 				}
       
  2099 			}
       
  2100 		packetContext = iNifWrappers[i].GetContext(realIndex);
       
  2101 		aInfo->iName.Copy(packetContext->ContextName());
       
  2102 		aInfo->iStatus = packetContext->ContextStatus();
       
  2103 		ReqCompleted(aTsyReqHandle,KErrNone);
       
  2104 		}
       
  2105 	return KErrNone;
       
  2106 	}
       
  2107 
       
  2108 TInt CSimPacketService::GetContextInfoCancel(const TTsyReqHandle /*aTsyReqHandle*/) 
       
  2109 /**
       
  2110 * Cancels a clients request for a context info
       
  2111 *
       
  2112 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  2113 * @return KErrNone
       
  2114 */
       
  2115 	{
       
  2116 	return KErrNone;
       
  2117 	}
       
  2118 
       
  2119 TInt CSimPacketService::GetNtwkRegStatus(const TTsyReqHandle aTsyReqHandle, RPacketService::TRegistrationStatus* aRegistrationStatus)
       
  2120 /**
       
  2121 * Returns the Network registration status to the client.
       
  2122 *
       
  2123 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2124 * @param aRegistrationStatus pointer to the registration status info requested
       
  2125 * @return KErrNone 
       
  2126 */
       
  2127 	{
       
  2128 	LOGPACKET1("CSimPacketService::GetNtwkRegStatus called");
       
  2129 	*aRegistrationStatus = (RPacketService::TRegistrationStatus)iCurrentRegStatus;
       
  2130 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  2131 	return KErrNone;
       
  2132 	}
       
  2133 
       
  2134 TInt CSimPacketService::NotifyChangeOfNtwkRegStatus(const TTsyReqHandle aTsyReqHandle, RPacketService::TRegistrationStatus* aRegistrationStatus)
       
  2135 /**
       
  2136 * Record a client's interest in being notified of a change in the Nk registration status.
       
  2137 * First check that there isn't already a notification pending (the ETel Server should protect
       
  2138 * against this) and then record the information necessary to complete the request later, when
       
  2139 * the status does actually change.
       
  2140 *
       
  2141 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2142 * @param aRegistrationStatus pointer to the Network registration status
       
  2143 * @return KErrNone
       
  2144 */
       
  2145 	{
       
  2146 	if(iNtwkRegStatusInfo->Count()==0)
       
  2147 		{
       
  2148 		ReqCompleted(aTsyReqHandle,KErrNotSupported);
       
  2149 		return KErrNone;
       
  2150 		}
       
  2151 
       
  2152 	__ASSERT_ALWAYS(!iNotifyChangeOfNtwk.iNotifyPending,SimPanic(ENotificationReqAlreadyOutstanding));
       
  2153 	iNotifyChangeOfNtwk.iNotifyPending=ETrue;
       
  2154 	iNotifyChangeOfNtwk.iNotifyHandle=aTsyReqHandle;
       
  2155 	iNotifyChangeOfNtwk.iNotifyData=aRegistrationStatus;
       
  2156 	return KErrNone;
       
  2157 	}
       
  2158 
       
  2159 TInt CSimPacketService::NotifyChangeOfNtwkRegStatusCancel(const TTsyReqHandle aTsyReqHandle)
       
  2160 /**
       
  2161 * Cancel a client's interest in being notified of a change in the Nk registration status.
       
  2162 * This is acheived simply by resetting the flag that indicates a notification is pending.
       
  2163 * 
       
  2164 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  2165 * @return KErrNone
       
  2166 */
       
  2167 	{
       
  2168 	LOGPACKET1("CSimPacketService::NotifyChangeOfNtwkRegStatusCancel called");
       
  2169 	if(iNotifyChangeOfNtwk.iNotifyPending)
       
  2170 		{
       
  2171 		iNotifyChangeOfNtwk.iNotifyPending=EFalse;
       
  2172 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  2173 		}
       
  2174 	return KErrNone;
       
  2175 	}
       
  2176 
       
  2177 TInt CSimPacketService::GetMSClass(const TTsyReqHandle aTsyReqHandle, RPacketService::TMSClass* aCurrentClass, RPacketService::TMSClass* aMaxClass)
       
  2178 /**
       
  2179 * Returns the Current MSClass supported by the TSY.
       
  2180 *
       
  2181 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2182 * @param aCurrentClass pointer to the current MSClass
       
  2183 * @param aMaxClass the maximum MSClass this TSY can support
       
  2184 * @return KErrNone 
       
  2185 */
       
  2186 	{
       
  2187 	//This version of the Simulator TSY will only support CLASS B i.e EMSClassSuspensionRequired
       
  2188 	*aCurrentClass = iMSClass;
       
  2189 	*aMaxClass = RPacketService::EMSClassSuspensionRequired;
       
  2190 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  2191 	return KErrNone;
       
  2192 	}
       
  2193 
       
  2194 TInt CSimPacketService::GetMSClassCancel(const TTsyReqHandle /*aTsyReqHandle*/)
       
  2195 /**
       
  2196 * Cancels a clients request in retrieving the current MSClass supported by the TSY.
       
  2197 *
       
  2198 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  2199 * @return KErrNone
       
  2200 */
       
  2201 	{
       
  2202 	return KErrNone;
       
  2203 	}
       
  2204 
       
  2205 TInt CSimPacketService::SetMSClass(const TTsyReqHandle aTsyReqHandle, RPacketService::TMSClass* aClass)
       
  2206 /**
       
  2207 * Sets the MSClass for the TSY. This TSY current support Class B only and cannot be reset.
       
  2208 *
       
  2209 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2210 * @param aClass pointer to the MSClass to set the TSY to support
       
  2211 * @return KErrNone
       
  2212 */
       
  2213 	{
       
  2214 	if(*aClass != RPacketService::EMSClassSuspensionRequired)
       
  2215 		ReqCompleted(aTsyReqHandle,KErrNotSupported);
       
  2216 	else {
       
  2217 		iMSClass = *aClass;
       
  2218 		ReqCompleted(aTsyReqHandle,KErrNone);
       
  2219 		}
       
  2220 	return KErrNone;
       
  2221 	}
       
  2222 
       
  2223 TInt CSimPacketService::SetMSClassCancel(const TTsyReqHandle /*aTsyReqHandle*/)
       
  2224 /**
       
  2225 * Cancels a clients interest in setting the MSClass support for the TSY.
       
  2226 *
       
  2227 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  2228 * @return KErrNone
       
  2229 */
       
  2230 	{
       
  2231 	return KErrNone;
       
  2232 	}
       
  2233 
       
  2234 TInt CSimPacketService::NotifyMSClassChange(const TTsyReqHandle aTsyReqHandle, RPacketService::TMSClass* /*aNewClass*/)
       
  2235 /**
       
  2236 * Record a client's interest in being notified of a change of MSClass supported.
       
  2237 * First check that there isn't already a notification pending (the ETel Server should protect
       
  2238 * against this) and then record the information necessary to complete the request later, when
       
  2239 * the status does actually change.
       
  2240 * 
       
  2241 * Currently the TSY will only support Class B and thus this method is not supported.
       
  2242 *
       
  2243 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2244 * @param aNewClass pointer to the MSClass to set to
       
  2245 * @return KErrNone
       
  2246 */
       
  2247 	{
       
  2248 	ReqCompleted(aTsyReqHandle,KErrNotSupported);
       
  2249 	return KErrNone;
       
  2250 	}
       
  2251 
       
  2252 TInt CSimPacketService::NotifyMSClassChangeCancel(const TTsyReqHandle /*aTsyReqHandle*/)
       
  2253 /**
       
  2254 * Cancel a client's interest in being notified of a change of MSClass supported.
       
  2255 * This is acheived simply by resetting the flag that indicates a notification is pending.
       
  2256 * 
       
  2257 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  2258 * @return KErrNone
       
  2259 */
       
  2260 	{
       
  2261 	return KErrNone;
       
  2262 	}
       
  2263 
       
  2264 TInt CSimPacketService::GetStaticCaps(const TTsyReqHandle aTsyReqHandle, TUint* aCaps,RPacketContext::TProtocolType* aPdpType)
       
  2265 /**
       
  2266 * Returns the Static capabilities supported by the TSY
       
  2267 *
       
  2268 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2269 * @param aCaps pointer to the TSY's capability
       
  2270 * @param aPdpType protocol type used by the TSY
       
  2271 * @return KErrNone
       
  2272 */
       
  2273 	{
       
  2274 	LOGPACKET1("CSimPacketService::GetStaticCaps called");
       
  2275 	*aCaps = KPacketServiceCaps;
       
  2276 	*aPdpType = RPacketContext::EPdpTypePPP;
       
  2277 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  2278 	return KErrNone;
       
  2279 	}
       
  2280 
       
  2281 /**
       
  2282 * Returns the Dynamic capabilities supported by the TSY
       
  2283 *
       
  2284 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2285 * @param aCaps Pointer to be populated with the dynamic capabilities of the TSY
       
  2286 * @return KErrNone
       
  2287 */
       
  2288 TInt CSimPacketService::GetDynamicCaps(const TTsyReqHandle aTsyReqHandle, RPacketService::TDynamicCapsFlags* aCaps)
       
  2289 	{
       
  2290 	LOGPACKET1("CSimPacketService::GetDynamicCaps called");
       
  2291 	
       
  2292 	if (iDynamicCapsArray->Count() == 0)
       
  2293 		{
       
  2294 		ReqCompleted(aTsyReqHandle, KErrNotSupported);
       
  2295 		return KErrNone;
       
  2296 		}
       
  2297 	*aCaps = iCurrentDynamicCaps;
       
  2298 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  2299 	return KErrNone;
       
  2300 	}
       
  2301 
       
  2302 /**
       
  2303 * Registers a client interest of change in the Dynamic capabilities change.
       
  2304 *
       
  2305 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2306 * @param aCaps Pointer to be populated with the dynamic capabilities of the TSY
       
  2307 * @return KErrNone
       
  2308 */
       
  2309 TInt CSimPacketService::NotifyDynamicCapsChange(const TTsyReqHandle aTsyReqHandle, RPacketService::TDynamicCapsFlags* aCaps)
       
  2310 	{
       
  2311 	LOGPACKET1("CSimPacketService::NotifyDynamicCapsChange called");
       
  2312 	__ASSERT_ALWAYS(!iNotifyDynamicCapsChange.iNotifyPending,SimPanic(ENotificationAlreadyPending));
       
  2313  
       
  2314 	if (iDynamicCapsArray->Count() == 0)
       
  2315 		{
       
  2316 		ReqCompleted(aTsyReqHandle,KErrNotSupported);
       
  2317 		return KErrNone;
       
  2318 		}
       
  2319 	
       
  2320 	iNotifyDynamicCapsChange.iNotifyPending = ETrue;
       
  2321 	iNotifyDynamicCapsChange.iNotifyHandle = aTsyReqHandle;
       
  2322 	iNotifyDynamicCapsChange.iNotifyData = aCaps;
       
  2323 	return KErrNone;
       
  2324 	}
       
  2325 
       
  2326 /**
       
  2327 * Cancels a clients interest in the change of dynamic caps.
       
  2328 *
       
  2329 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  2330 * @return KErrNone
       
  2331 */
       
  2332 TInt CSimPacketService::NotifyDynamicCapsChangeCancel(const TTsyReqHandle aTsyReqHandle)
       
  2333 	{
       
  2334 	LOGPACKET1("CSimPacketService::NotifyDynamicCapsChangeCancel called");
       
  2335 	if( (iNotifyDynamicCapsChange.iNotifyPending) && (aTsyReqHandle == iNotifyDynamicCapsChange.iNotifyHandle))
       
  2336 		{
       
  2337 		iNotifyDynamicCapsChange.iNotifyPending=EFalse;
       
  2338 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  2339 		}
       
  2340 	return KErrNone;
       
  2341 	}
       
  2342 
       
  2343 /**
       
  2344 * Timer callback function to simulate a change in the dynamic capabilities of the TSY
       
  2345 */
       
  2346 void CSimPacketService::TimerCallBackDynamicCaps()
       
  2347 	{
       
  2348 	if (++iDynamicCapsIndex >= iDynamicCapsArray->Count())
       
  2349 		{
       
  2350 		return;
       
  2351 		}
       
  2352 	iCurrentDynamicCaps = iDynamicCapsArray->At(iDynamicCapsIndex).iDynamicCaps;
       
  2353 	if (iNotifyDynamicCapsChange.iNotifyPending)
       
  2354 		{
       
  2355 		iNotifyDynamicCapsChange.iNotifyPending = EFalse;
       
  2356 		*(TInt*)iNotifyDynamicCapsChange.iNotifyData = iCurrentDynamicCaps;
       
  2357 		ReqCompleted(iNotifyDynamicCapsChange.iNotifyHandle,KErrNone);
       
  2358 		}
       
  2359 	
       
  2360 	iDynamicCapsTimer->Start(iDynamicCapsArray->At(iDynamicCapsIndex).iDuration, this, ETimerIdPcktServDynamicCaps);
       
  2361 	}
       
  2362 
       
  2363 TInt CSimPacketService::SetAttachMode(const TTsyReqHandle aTsyReqHandle, RPacketService::TAttachMode* aMode)
       
  2364 /**
       
  2365 * Sets the attach mode to be used by the tsy.
       
  2366 * Currently The TSY supports EAttachWhenNeeded only.
       
  2367 *
       
  2368 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2369 * @param aMode pointer to the mode to change to
       
  2370 * @return KErrNone 
       
  2371 */
       
  2372 	{
       
  2373 	LOGPACKET1("CSimPacketService::SetAttachMode called");
       
  2374 	if(*aMode != RPacketService::EAttachWhenNeeded)
       
  2375 		{
       
  2376 		ReqCompleted(aTsyReqHandle, KErrNotSupported);
       
  2377 		}
       
  2378 	else 
       
  2379 		{
       
  2380 		iAttachMode = *aMode;
       
  2381 		// Check for a pending attach mode notification.
       
  2382 		if(iNotifyChangeOfAttachMode.iNotifyPending)
       
  2383 			{
       
  2384 			iNotifyChangeOfAttachMode.iNotifyPending=EFalse;
       
  2385 			*(RPacketService::TAttachMode*)iNotifyChangeOfAttachMode.iNotifyData = iAttachMode;
       
  2386 			ReqCompleted(iNotifyChangeOfAttachMode.iNotifyHandle,KErrNone);
       
  2387 			}	
       
  2388 		ReqCompleted(aTsyReqHandle,KErrNone);
       
  2389 		}
       
  2390 	return KErrNone;
       
  2391 	}
       
  2392 
       
  2393 TInt CSimPacketService::GetAttachMode(const TTsyReqHandle aTsyReqHandle, RPacketService::TAttachMode* aMode)
       
  2394 /**
       
  2395 * Retrieves and returns the current attach mode for the TSY.
       
  2396 *
       
  2397 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2398 * @param aMode pointer to the mode to change
       
  2399 * @return KErrNone 
       
  2400 */
       
  2401 	{
       
  2402 	LOGPACKET1("CSimPacketService::GetAttachMode called");
       
  2403 	*aMode = iAttachMode;
       
  2404 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  2405 	return KErrNone;
       
  2406 	}
       
  2407 	
       
  2408 TInt CSimPacketService::NotifyAttachModeChange(const TTsyReqHandle aTsyReqHandle, RPacketService::TAttachMode* aMode)
       
  2409 /**
       
  2410 * Set notification request for change of current attach mode
       
  2411 *
       
  2412 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2413 * @param aMode pointer to the mode to change
       
  2414 * @return KErrNone 
       
  2415 */
       
  2416 	{
       
  2417 	LOGPACKET1("CSimPacketService::NotifyAttachModeChange called");
       
  2418 	
       
  2419 	__ASSERT_ALWAYS(!iNotifyChangeOfAttachMode.iNotifyPending,SimPanic(ENotificationAlreadyPending));
       
  2420 	
       
  2421 	iNotifyChangeOfAttachMode.iNotifyPending=ETrue;
       
  2422 	iNotifyChangeOfAttachMode.iNotifyHandle=aTsyReqHandle;
       
  2423 	iNotifyChangeOfAttachMode.iNotifyData=aMode;
       
  2424 		
       
  2425 	return KErrNone;
       
  2426 	}
       
  2427 
       
  2428 TInt CSimPacketService::SetDefaultContextParams(const TTsyReqHandle aTsyReqHandle, const TDesC8* aPckg)
       
  2429 /**
       
  2430 * Sets the Default Context Parameters to be used when attaching and activating a context.
       
  2431 *
       
  2432 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2433 * @param aPckg pointer containing the parameters to set to.
       
  2434 * @return KErrNone
       
  2435 */
       
  2436 	{
       
  2437 	LOGPACKET1("CSimPacketService::SetDefaultContextParams called");
       
  2438 	
       
  2439 	TPckg<TPacketDataConfigBase>* configBase = (TPckg<TPacketDataConfigBase>*)aPckg;
       
  2440 	TPacketDataConfigBase& configBaseV1 = (*configBase)();
       
  2441 
       
  2442 		
       
  2443 	// GPRS
       
  2444 	if(configBaseV1.ExtensionId()==TPacketDataConfigBase::KConfigGPRS)
       
  2445 		{
       
  2446 		iPhone->UpdateNetworkMode(RMobilePhone::ENetworkModeGsm);
       
  2447 		TPckg<RPacketContext::TContextConfigGPRS>* defaultContextGPRSPckg = (TPckg<RPacketContext::TContextConfigGPRS>*)aPckg;
       
  2448 		RPacketContext::TContextConfigGPRS& defaultContextGPRSV1 = (*defaultContextGPRSPckg)();
       
  2449 
       
  2450 		TBuf8<RPacketContext::KGSNNameLength> accessPointName;
       
  2451 		accessPointName.Copy(defaultContextGPRSV1.iAccessPointName);
       
  2452 
       
  2453 		TBuf8<RPacketContext::KMaxPDPAddressLength> dpAddress;
       
  2454 		dpAddress.Copy(defaultContextGPRSV1.iPdpAddress);
       
  2455 
       
  2456 		TBuf8<RPacketContext::KMaxAuthDataLength> password;
       
  2457 		password.Copy(defaultContextGPRSV1.iProtocolConfigOption.iAuthInfo.iPassword);
       
  2458 
       
  2459 		TBuf8<RPacketContext::KMaxAuthDataLength> username;
       
  2460 		username.Copy(defaultContextGPRSV1.iProtocolConfigOption.iAuthInfo.iUsername);
       
  2461 
       
  2462 		TBuf8<RPacketContext::KMaxAuthDataLength> challenge;
       
  2463 		challenge.Copy(defaultContextGPRSV1.iProtocolConfigOption.iChallenge);
       
  2464 		
       
  2465 		TBuf8<RPacketContext::KMaxAuthDataLength> response;
       
  2466 		response.Copy(defaultContextGPRSV1.iProtocolConfigOption.iResponse);
       
  2467 
       
  2468 		TBuf8<RPacketContext::KMaxPDPAddressLength> primaryDNS;
       
  2469 		primaryDNS.Copy(defaultContextGPRSV1.iProtocolConfigOption.iDnsAddresses.iPrimaryDns);
       
  2470 
       
  2471 		TBuf8<RPacketContext::KMaxAuthDataLength> secondaryDNS;
       
  2472 		secondaryDNS.Copy(defaultContextGPRSV1.iProtocolConfigOption.iDnsAddresses.iSecondaryDns);
       
  2473 
       
  2474 		TBuf8<RPacketContext::KMiscProtocolBufferLength> miscBuffer;
       
  2475 		miscBuffer.Copy(defaultContextGPRSV1.iProtocolConfigOption.iMiscBuffer);
       
  2476 
       
  2477 		if ((defaultContextGPRSV1.iPdpType != iGPRSDefaultConfig.iProtocolType)||
       
  2478 			(iGPRSDefaultConfig.iGsnAddress.Compare(accessPointName) != KErrNone) ||
       
  2479 			(iGPRSDefaultConfig.iProtocolAddress.Compare(dpAddress) != KErrNone) ||
       
  2480 			(defaultContextGPRSV1.iPdpCompression != iGPRSDefaultConfig.iPdpCompression) ||
       
  2481 			(defaultContextGPRSV1.iAnonymousAccessReqd != iGPRSDefaultConfig.iAnonymousAccess) ||
       
  2482 			(defaultContextGPRSV1.iUseEdge != iGPRSDefaultConfig.iUseEdge) ||
       
  2483 			(defaultContextGPRSV1.iProtocolConfigOption.iAuthInfo.iProtocol != iGPRSDefaultConfig.iProtocolConfigOption.iAuthProtocol) ||
       
  2484 			((iGPRSDefaultConfig.iProtocolConfigOption.iPassword).Compare(password) != KErrNone) ||
       
  2485 			((iGPRSDefaultConfig.iProtocolConfigOption.iUsername).Compare(username) != KErrNone) ||
       
  2486 			((iGPRSDefaultConfig.iProtocolConfigOption.iChallenge).Compare(challenge) != KErrNone) ||
       
  2487 			((iGPRSDefaultConfig.iProtocolConfigOption.iResponse).Compare(response) != KErrNone) ||
       
  2488 			((iGPRSDefaultConfig.iProtocolConfigOption.iPrimaryDNS).Compare(primaryDNS) != KErrNone) ||
       
  2489 			((iGPRSDefaultConfig.iProtocolConfigOption.iSecondaryDNS).Compare(secondaryDNS) != KErrNone) ||
       
  2490 			(iGPRSDefaultConfig.iProtocolConfigOption.iId != defaultContextGPRSV1.iProtocolConfigOption.iId))
       
  2491 				ReqCompleted(aTsyReqHandle,KErrArgument);
       
  2492 		else
       
  2493 				ReqCompleted(aTsyReqHandle,KErrNone);
       
  2494 		}
       
  2495 	// UMTS
       
  2496 	else if (configBaseV1.ExtensionId()==TPacketDataConfigBase::KConfigRel99Rel4)
       
  2497 		{
       
  2498 		iPhone->UpdateNetworkMode(RMobilePhone::ENetworkModeGsm);
       
  2499 		TPckg<RPacketContext::TContextConfigR99_R4>* defaultContextR99_R4Pckg = (TPckg<RPacketContext::TContextConfigR99_R4>*)aPckg;
       
  2500 		RPacketContext::TContextConfigR99_R4& defaultContextR99_R4V1 = (*defaultContextR99_R4Pckg)();
       
  2501 
       
  2502 		TBuf8<RPacketContext::KGSNNameLength> accessPointName;
       
  2503 		accessPointName.Copy(defaultContextR99_R4V1.iAccessPointName);
       
  2504 
       
  2505 		TBuf8<RPacketContext::KMaxPDPAddressLength> dpAddress;
       
  2506 		dpAddress.Copy(defaultContextR99_R4V1.iPdpAddress);
       
  2507 
       
  2508 		TBuf8<RPacketContext::KMaxAuthDataLength> password;
       
  2509 		password.Copy(defaultContextR99_R4V1.iProtocolConfigOption.iAuthInfo.iPassword);
       
  2510 
       
  2511 		TBuf8<RPacketContext::KMaxAuthDataLength> username;
       
  2512 		username.Copy(defaultContextR99_R4V1.iProtocolConfigOption.iAuthInfo.iUsername);
       
  2513 
       
  2514 		TBuf8<RPacketContext::KMaxAuthDataLength> challenge;
       
  2515 		challenge.Copy(defaultContextR99_R4V1.iProtocolConfigOption.iChallenge);
       
  2516 		
       
  2517 		TBuf8<RPacketContext::KMaxAuthDataLength> response;
       
  2518 		response.Copy(defaultContextR99_R4V1.iProtocolConfigOption.iResponse);
       
  2519 
       
  2520 		TBuf8<RPacketContext::KMaxPDPAddressLength> primaryDNS;
       
  2521 		primaryDNS.Copy(defaultContextR99_R4V1.iProtocolConfigOption.iDnsAddresses.iPrimaryDns);
       
  2522 
       
  2523 		TBuf8<RPacketContext::KMaxAuthDataLength> secondaryDNS;
       
  2524 		secondaryDNS.Copy(defaultContextR99_R4V1.iProtocolConfigOption.iDnsAddresses.iSecondaryDns);
       
  2525 
       
  2526 		TBuf8<RPacketContext::KMiscProtocolBufferLength> miscBuffer;
       
  2527 		miscBuffer.Copy(defaultContextR99_R4V1.iProtocolConfigOption.iMiscBuffer);
       
  2528 		
       
  2529 		if ((defaultContextR99_R4V1.iPdpType != iR99_R4DefaultConfig.iProtocolType)||
       
  2530 				(iR99_R4DefaultConfig.iGsnAddress.Compare(accessPointName) != KErrNone) ||
       
  2531 				(iR99_R4DefaultConfig.iProtocolAddress.Compare(dpAddress) != KErrNone) ||
       
  2532 				(defaultContextR99_R4V1.iUseEdge != iR99_R4DefaultConfig.iUseEdge) ||
       
  2533 			   (defaultContextR99_R4V1.iProtocolConfigOption.iAuthInfo.iProtocol != iR99_R4DefaultConfig.iProtocolConfigOption.iAuthProtocol) ||
       
  2534 			   ((iR99_R4DefaultConfig.iProtocolConfigOption.iPassword).Compare(password) != KErrNone) ||
       
  2535 			   ((iR99_R4DefaultConfig.iProtocolConfigOption.iUsername).Compare(username) != KErrNone) ||
       
  2536 			   ((iR99_R4DefaultConfig.iProtocolConfigOption.iChallenge).Compare(challenge) != KErrNone) ||
       
  2537 			   ((iR99_R4DefaultConfig.iProtocolConfigOption.iResponse).Compare(response) != KErrNone) ||
       
  2538 			   ((iR99_R4DefaultConfig.iProtocolConfigOption.iPrimaryDNS).Compare(primaryDNS) != KErrNone) ||
       
  2539 			   ((iR99_R4DefaultConfig.iProtocolConfigOption.iSecondaryDNS.Compare(secondaryDNS) != KErrNone) ||
       
  2540 			   (iR99_R4DefaultConfig.iProtocolConfigOption.iId != defaultContextR99_R4V1.iProtocolConfigOption.iId)))
       
  2541 
       
  2542 			ReqCompleted(aTsyReqHandle,KErrArgument);
       
  2543 		else
       
  2544 			ReqCompleted(aTsyReqHandle,KErrNone);
       
  2545 		}
       
  2546 	//R5
       
  2547 	else if(configBaseV1.ExtensionId()==TPacketDataConfigBase::KConfigRel5)
       
  2548 		{
       
  2549 		iPhone->UpdateNetworkMode(RMobilePhone::ENetworkModeGsm);
       
  2550 		TPckg<RPacketContext::TContextConfig_R5>* defaultContext_R5Pckg = (TPckg<RPacketContext::TContextConfig_R5>*)aPckg;
       
  2551 		RPacketContext::TContextConfig_R5& defaultContextR5 = (*defaultContext_R5Pckg)();
       
  2552 
       
  2553 		TBuf8<RPacketContext::KGSNNameLength> accessPointName;
       
  2554 		accessPointName.Copy(defaultContextR5.iAccessPointName);
       
  2555 
       
  2556 		TBuf8<RPacketContext::KMaxPDPAddressLength> dpAddress;
       
  2557 		dpAddress.Copy(defaultContextR5.iPdpAddress);
       
  2558 
       
  2559 		TBuf8<RPacketContext::KMaxAuthDataLength> password;
       
  2560 		password.Copy(defaultContextR5.iProtocolConfigOption.iAuthInfo.iPassword);
       
  2561 
       
  2562 		TBuf8<RPacketContext::KMaxAuthDataLength> username;
       
  2563 		username.Copy(defaultContextR5.iProtocolConfigOption.iAuthInfo.iUsername);
       
  2564 
       
  2565 		TBuf8<RPacketContext::KMaxAuthDataLength> challenge;
       
  2566 		challenge.Copy(defaultContextR5.iProtocolConfigOption.iChallenge);
       
  2567 		
       
  2568 		TBuf8<RPacketContext::KMaxAuthDataLength> response;
       
  2569 		response.Copy(defaultContextR5.iProtocolConfigOption.iResponse);
       
  2570 
       
  2571 		TBuf8<RPacketContext::KMaxPDPAddressLength> primaryDNS;
       
  2572 		primaryDNS.Copy(defaultContextR5.iProtocolConfigOption.iDnsAddresses.iPrimaryDns);
       
  2573 
       
  2574 		TBuf8<RPacketContext::KMaxAuthDataLength> secondaryDNS;
       
  2575 		secondaryDNS.Copy(defaultContextR5.iProtocolConfigOption.iDnsAddresses.iSecondaryDns);
       
  2576 
       
  2577 		TBuf8<RPacketContext::KMiscProtocolBufferLength> miscBuffer;
       
  2578 		miscBuffer.Copy(defaultContextR5.iProtocolConfigOption.iMiscBuffer);
       
  2579 
       
  2580 		if ((defaultContextR5.iPdpType != iR5DefaultConfig.iProtocolType)||
       
  2581 			(iR5DefaultConfig.iGsnAddress.Compare(accessPointName) != KErrNone) ||
       
  2582 			(iR5DefaultConfig.iProtocolAddress.Compare(dpAddress) != KErrNone) ||
       
  2583 			(defaultContextR5.iUseEdge != iR5DefaultConfig.iUseEdge) ||
       
  2584 			(defaultContextR5.iProtocolConfigOption.iAuthInfo.iProtocol != iR5DefaultConfig.iProtocolConfigOption.iAuthProtocol) ||
       
  2585 			((iR5DefaultConfig.iProtocolConfigOption.iPassword).Compare(password) != KErrNone) ||
       
  2586 			((iR5DefaultConfig.iProtocolConfigOption.iUsername).Compare(username) != KErrNone) ||
       
  2587 			((iR5DefaultConfig.iProtocolConfigOption.iChallenge).Compare(challenge) != KErrNone) ||
       
  2588 			((iR5DefaultConfig.iProtocolConfigOption.iResponse).Compare(response) != KErrNone) ||
       
  2589 			((iR5DefaultConfig.iProtocolConfigOption.iPrimaryDNS).Compare(primaryDNS) != KErrNone) ||
       
  2590 			((iR5DefaultConfig.iProtocolConfigOption.iSecondaryDNS).Compare(secondaryDNS) != KErrNone) ||
       
  2591 			(iR5DefaultConfig.iProtocolConfigOption.iId != defaultContextR5.iProtocolConfigOption.iId) ||
       
  2592 			(iR5DefaultConfig.iPdpHeaderCompression != defaultContextR5.iPdpHeaderCompression) ||
       
  2593 			(iR5DefaultConfig.iPdpDataCompression != defaultContextR5.iPdpDataCompression))
       
  2594 			{
       
  2595 			ReqCompleted(aTsyReqHandle,KErrArgument);
       
  2596 			}
       
  2597 		else
       
  2598 			{
       
  2599 			ReqCompleted(aTsyReqHandle,KErrNone);
       
  2600 			}
       
  2601 		}
       
  2602 	else 
       
  2603 		{
       
  2604 		iPhone->UpdateNetworkMode(RMobilePhone::ENetworkModeUnknown);
       
  2605 		}
       
  2606 	return KErrNone;
       
  2607 	}
       
  2608 
       
  2609 
       
  2610 TInt CSimPacketService::GetGPRSDefaultContextParams(const TTsyReqHandle aTsyReqHandle, TDes8* aPckg)
       
  2611 /**
       
  2612 * Returns the Default Context Parameters set by the client.
       
  2613 *
       
  2614 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2615 * @param aPckg pointer containing the parameters to return to client.
       
  2616 * @return KErrNone
       
  2617 */
       
  2618 	{
       
  2619 	LOGPACKET1("CSimPacketService::GetDefaultContextParams called");
       
  2620 
       
  2621 	TPckg<RPacketContext::TContextConfigGPRS>* contextConfigGPRSPckg = (TPckg<RPacketContext::TContextConfigGPRS>*)aPckg;
       
  2622 	RPacketContext::TContextConfigGPRS& contextConfigV1 = (*contextConfigGPRSPckg)();
       
  2623 
       
  2624 	contextConfigV1.iAccessPointName.Copy(KApn);
       
  2625 	contextConfigV1.iAnonymousAccessReqd = RPacketContext::ERequired;
       
  2626 	contextConfigV1.iPdpAddress.Copy(KProtocolAddress);
       
  2627 	contextConfigV1.iPdpCompression = 1;
       
  2628 	contextConfigV1.iPdpType =  RPacketContext::EPdpTypeIPv6;  
       
  2629 
       
  2630 	contextConfigV1.iUseEdge = ETrue;
       
  2631 	contextConfigV1.iProtocolConfigOption.iAuthInfo.iUsername.Copy(KUsername);
       
  2632 	contextConfigV1.iProtocolConfigOption.iAuthInfo.iPassword.Copy(KPassword);
       
  2633 	contextConfigV1.iProtocolConfigOption.iChallenge.Copy(KChallenge);
       
  2634 	contextConfigV1.iProtocolConfigOption.iResponse.Copy(KResponse);
       
  2635 	contextConfigV1.iProtocolConfigOption.iDnsAddresses.iPrimaryDns.Copy(KPrimaryDNS);
       
  2636 	contextConfigV1.iProtocolConfigOption.iDnsAddresses.iSecondaryDns.Copy(KSecondaryDNS);
       
  2637 	contextConfigV1.iProtocolConfigOption.iId = 1;
       
  2638 	contextConfigV1.iProtocolConfigOption.iMiscBuffer.Copy(_L(""));
       
  2639 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  2640 	return KErrNone;
       
  2641 	}
       
  2642 	
       
  2643 TInt CSimPacketService::GetDefaultContextParams(const TTsyReqHandle aTsyReqHandle, TDes8* aPckg)
       
  2644 /**
       
  2645 * Returns the Default Context Parameters set by the client.
       
  2646 *
       
  2647 * @param aTsyReqHandle Tsy Request handle for the client request
       
  2648 * @param aPckg pointer containing the parameters to return to client.
       
  2649 * @return KErrNone
       
  2650 */
       
  2651 	{
       
  2652 	LOGPACKET1("CSimPacketService::GetDefaultContextParams called");
       
  2653 	TPckg<TPacketDataConfigBase>* configBase = (TPckg<TPacketDataConfigBase>*)aPckg;
       
  2654 	TPacketDataConfigBase& configBaseV1 = (*configBase)();
       
  2655 
       
  2656 	// GPRS
       
  2657 	if(configBaseV1.ExtensionId()==TPacketDataConfigBase::KConfigGPRS)
       
  2658 		{
       
  2659 		TPckg<RPacketContext::TContextConfigGPRS>* contextConfigGPRSPckg = (TPckg<RPacketContext::TContextConfigGPRS>*)aPckg;
       
  2660 		RPacketContext::TContextConfigGPRS& contextConfigV1 = (*contextConfigGPRSPckg)();
       
  2661 
       
  2662 		contextConfigV1.iAccessPointName.Copy(iGPRSDefaultConfig.iGsnAddress);// = STATIC_CAST(RPacketContext::TGSNAddress,accessPointName);
       
  2663 		contextConfigV1.iAnonymousAccessReqd = STATIC_CAST(RPacketContext::TAnonymousAccess,iGPRSDefaultConfig.iAnonymousAccess);
       
  2664 		contextConfigV1.iPdpAddress.Copy(iGPRSDefaultConfig.iProtocolAddress);// = STATIC_CAST(RPacketContext::TProtocolAddress, dpAddress);
       
  2665 		contextConfigV1.iPdpCompression = STATIC_CAST(TUint, iGPRSDefaultConfig.iPdpCompression);
       
  2666 		contextConfigV1.iPdpType = STATIC_CAST(RPacketContext::TProtocolType, iGPRSDefaultConfig.iProtocolType);
       
  2667 		contextConfigV1.iUseEdge = iGPRSDefaultConfig.iUseEdge;
       
  2668 		contextConfigV1.iProtocolConfigOption.iAuthInfo.iProtocol = STATIC_CAST(RPacketContext::TAuthProtocol, iGPRSDefaultConfig.iProtocolConfigOption.iAuthProtocol);
       
  2669 		contextConfigV1.iProtocolConfigOption.iAuthInfo.iUsername.Copy(iGPRSDefaultConfig.iProtocolConfigOption.iUsername);
       
  2670 		contextConfigV1.iProtocolConfigOption.iAuthInfo.iPassword.Copy(iGPRSDefaultConfig.iProtocolConfigOption.iPassword);
       
  2671 		contextConfigV1.iProtocolConfigOption.iChallenge.Copy(iGPRSDefaultConfig.iProtocolConfigOption.iChallenge);
       
  2672 		contextConfigV1.iProtocolConfigOption.iResponse.Copy(iGPRSDefaultConfig.iProtocolConfigOption.iResponse);
       
  2673 		contextConfigV1.iProtocolConfigOption.iDnsAddresses.iPrimaryDns.Copy(iGPRSDefaultConfig.iProtocolConfigOption.iPrimaryDNS);
       
  2674 		contextConfigV1.iProtocolConfigOption.iDnsAddresses.iSecondaryDns.Copy(iGPRSDefaultConfig.iProtocolConfigOption.iSecondaryDNS);
       
  2675 		contextConfigV1.iProtocolConfigOption.iId = STATIC_CAST(TUint8, iGPRSDefaultConfig.iProtocolConfigOption.iId);
       
  2676 		contextConfigV1.iProtocolConfigOption.iMiscBuffer.Copy(iGPRSDefaultConfig.iProtocolConfigOption.iMiscBuffer);
       
  2677 		ReqCompleted(aTsyReqHandle,KErrNone);
       
  2678 		}
       
  2679 	// UMTS
       
  2680 	else if(configBaseV1.ExtensionId()==TPacketDataConfigBase::KConfigRel99Rel4)
       
  2681 		{
       
  2682 		TPckg<RPacketContext::TContextConfigR99_R4>* contextConfigR99_R4Pckg = (TPckg<RPacketContext::TContextConfigR99_R4>*)aPckg;
       
  2683 		RPacketContext::TContextConfigR99_R4& contextConfigV1 = (*contextConfigR99_R4Pckg)();
       
  2684 
       
  2685 		contextConfigV1.iAccessPointName.Copy(iR99_R4DefaultConfig.iGsnAddress);// = STATIC_CAST(RPacketContext::TGSNAddress,accessPointName);
       
  2686 		contextConfigV1.iPdpAddress.Copy(iR99_R4DefaultConfig.iProtocolAddress);// = STATIC_CAST(RPacketContext::TProtocolAddress, dpAddress);
       
  2687 		contextConfigV1.iPdpType = STATIC_CAST(RPacketContext::TProtocolType, iR99_R4DefaultConfig.iProtocolType);
       
  2688 		contextConfigV1.iUseEdge = iR99_R4DefaultConfig.iUseEdge;
       
  2689 		contextConfigV1.iProtocolConfigOption.iAuthInfo.iProtocol = STATIC_CAST(RPacketContext::TAuthProtocol, iR99_R4DefaultConfig.iProtocolConfigOption.iAuthProtocol);
       
  2690 		contextConfigV1.iProtocolConfigOption.iAuthInfo.iUsername.Copy(iR99_R4DefaultConfig.iProtocolConfigOption.iUsername);
       
  2691 		contextConfigV1.iProtocolConfigOption.iAuthInfo.iPassword.Copy(iR99_R4DefaultConfig.iProtocolConfigOption.iPassword);
       
  2692 		contextConfigV1.iProtocolConfigOption.iChallenge.Copy(iR99_R4DefaultConfig.iProtocolConfigOption.iChallenge);
       
  2693 		contextConfigV1.iProtocolConfigOption.iResponse.Copy(iR99_R4DefaultConfig.iProtocolConfigOption.iResponse);
       
  2694 		contextConfigV1.iProtocolConfigOption.iDnsAddresses.iPrimaryDns.Copy(iR99_R4DefaultConfig.iProtocolConfigOption.iPrimaryDNS);
       
  2695 		contextConfigV1.iProtocolConfigOption.iDnsAddresses.iSecondaryDns.Copy(iR99_R4DefaultConfig.iProtocolConfigOption.iSecondaryDNS);
       
  2696 		contextConfigV1.iProtocolConfigOption.iId = STATIC_CAST(TUint8, iR99_R4DefaultConfig.iProtocolConfigOption.iId);
       
  2697 		contextConfigV1.iProtocolConfigOption.iMiscBuffer.Copy(iR99_R4DefaultConfig.iProtocolConfigOption.iMiscBuffer);
       
  2698 		ReqCompleted(aTsyReqHandle,KErrNone);
       
  2699 		}
       
  2700 
       
  2701 	//R5
       
  2702 	else if(configBaseV1.ExtensionId()==TPacketDataConfigBase::KConfigRel5)
       
  2703 		{
       
  2704 		TPckg<RPacketContext::TContextConfig_R5>* contextConfigR5Pckg = (TPckg<RPacketContext::TContextConfig_R5>*)aPckg;
       
  2705 		RPacketContext::TContextConfig_R5& contextConfigV1 = (*contextConfigR5Pckg)();
       
  2706 
       
  2707 		contextConfigV1.iAccessPointName.Copy(iR5DefaultConfig.iGsnAddress);
       
  2708 		contextConfigV1.iPdpAddress.Copy(iR5DefaultConfig.iProtocolAddress);
       
  2709 		contextConfigV1.iPdpType = static_cast<RPacketContext::TProtocolType>(iR5DefaultConfig.iProtocolType);
       
  2710 		contextConfigV1.iUseEdge = iR5DefaultConfig.iUseEdge;
       
  2711 		contextConfigV1.iPdpHeaderCompression = 
       
  2712 			static_cast<RPacketContext::THeaderCompression>(iR5DefaultConfig.iPdpHeaderCompression);
       
  2713 		contextConfigV1.iPdpDataCompression = 
       
  2714 			static_cast<RPacketContext::TDataCompression>(iR5DefaultConfig.iPdpDataCompression);
       
  2715 		contextConfigV1.iProtocolConfigOption.iAuthInfo.iProtocol = 
       
  2716 			static_cast<RPacketContext::TAuthProtocol>(iR5DefaultConfig.iProtocolConfigOption.iAuthProtocol);
       
  2717 		contextConfigV1.iProtocolConfigOption.iAuthInfo.iUsername.Copy(
       
  2718 			iR5DefaultConfig.iProtocolConfigOption.iUsername);
       
  2719 		contextConfigV1.iProtocolConfigOption.iAuthInfo.iPassword.Copy(
       
  2720 			iR5DefaultConfig.iProtocolConfigOption.iPassword);
       
  2721 		contextConfigV1.iProtocolConfigOption.iChallenge.Copy(
       
  2722 			iR5DefaultConfig.iProtocolConfigOption.iChallenge);
       
  2723 		contextConfigV1.iProtocolConfigOption.iResponse.Copy(
       
  2724 			iR5DefaultConfig.iProtocolConfigOption.iResponse);
       
  2725 		contextConfigV1.iProtocolConfigOption.iDnsAddresses.iPrimaryDns.Copy(
       
  2726 			iR5DefaultConfig.iProtocolConfigOption.iPrimaryDNS);
       
  2727 		contextConfigV1.iProtocolConfigOption.iDnsAddresses.iSecondaryDns.Copy(
       
  2728 			iR5DefaultConfig.iProtocolConfigOption.iSecondaryDNS);
       
  2729 		contextConfigV1.iProtocolConfigOption.iId = 
       
  2730 			static_cast<TUint8>(iR5DefaultConfig.iProtocolConfigOption.iId);
       
  2731 		contextConfigV1.iProtocolConfigOption.iMiscBuffer.Copy(
       
  2732 			iR5DefaultConfig.iProtocolConfigOption.iMiscBuffer);
       
  2733 
       
  2734 		ReqCompleted(aTsyReqHandle,KErrNone);
       
  2735 		}
       
  2736 
       
  2737 	return KErrNone;
       
  2738 	}
       
  2739 
       
  2740 
       
  2741 void CSimPacketService::TimerCallBack(TInt aId)
       
  2742 /**
       
  2743 * Timer callback function.  When the timer goes off, it will call back into this
       
  2744 * function for further processing.
       
  2745 *
       
  2746 * @param aId an id identifying which timer callback is being called
       
  2747 */
       
  2748 	{
       
  2749 	LOGPACKET1(">>CSimPacketService::TimerCallBack");
       
  2750 
       
  2751 	if(aId == ETimerIdPcktServPacket)
       
  2752 		{
       
  2753 		TimerCallBackPcktRegStatus();
       
  2754 		}
       
  2755 	else if (aId== ETimerIdPcktServReleaseMode)
       
  2756 		{
       
  2757 		TimerCallBackReleaseMode();
       
  2758 		}
       
  2759 	else if (aId == ETimerIdPcktServNtwkStatusChange)
       
  2760 		{
       
  2761 		TimerCallBackNtwkRegStatus();
       
  2762 		}
       
  2763 	else if (aId == ETimerIdPcktServStatusSuspend || 
       
  2764 			 aId == ETimerIdPcktServStatusDetach  ||
       
  2765 			 aId == ETimerIdPcktServStatusUnattach)
       
  2766 		{
       
  2767 		TimerCallBackDeactivate();	
       
  2768 		}
       
  2769 	else if (aId == ETimerIdPcktServDynamicCaps)
       
  2770 		{
       
  2771 		TimerCallBackDynamicCaps();
       
  2772 		}		
       
  2773 	else if(aId == ETimerIdContextActivationRequestedChange)
       
  2774 		{
       
  2775 
       
  2776 
       
  2777 		iIncomingContextManager->NextIncomingEvent(iConfigData.iData);
       
  2778 			// Set up for the next incoming PDP if any.
       
  2779 			// Note at moment can only handle 1 GPRS incoming.
       
  2780 			// There is no support for 2ndary contexts, so can not have 2 incoming (of the same type).
       
  2781 			// And at the moment there is no support for any other type thanm GPRS.
       
  2782 
       
  2783 		iIncomingContextManager->Cancel();	
       
  2784 			// No more timers.
       
  2785 								
       
  2786 		iIncomingContextManager->SetUseTimerOff();								
       
  2787 		ReqCompleted(iConfigData.iTsyReqHandle,KErrNone);
       
  2788 		iIncomingContextManager->SetUseTimerOn();								
       
  2789 						
       
  2790 		}
       
  2791 	else if(aId == ETimerIdMbmsPcktService)
       
  2792 		{
       
  2793 		if(iNotifyMbmsNetworkStatusChange.iNotifyPending)
       
  2794 			{
       
  2795 			iNotifyMbmsNetworkStatusChange.iNotifyPending = EFalse;
       
  2796 			*(static_cast<TMbmsNetworkServiceStatus*>(iNotifyMbmsNetworkStatusChange.iNotifyData))=
       
  2797 			iMbmsBroadcastParamsArray->At(iCurrentMbmsParamsIndex).iMbmsNetworkStatus;
       
  2798 			ReqCompleted(iNotifyMbmsNetworkStatusChange.iNotifyHandle,KErrNone);
       
  2799 			}
       
  2800 
       
  2801 		if(iNotifyMbmsServAvailChange.iNotifyPending)
       
  2802 			{
       
  2803 			iNotifyMbmsServAvailChange.iNotifyPending = EFalse;
       
  2804 			ReqCompleted(iNotifyMbmsServAvailChange.iNotifyHandle,KErrNone);
       
  2805 			}
       
  2806 
       
  2807 		if(iMbmsBroadcastParamsArray->Count() > iCurrentMbmsParamsIndex)
       
  2808 			{
       
  2809 			iMbmsPcktTimer->Start(iMbmsBroadcastParamsArray->At(iCurrentMbmsParamsIndex).iDuration,this,ETimerIdMbmsPcktService);
       
  2810 			}
       
  2811 		else if (iMbmsMonitorListParamsArray->Count() > iCurrentMbmsMonitorListIndex)
       
  2812 			{
       
  2813 			iMbmsPcktTimer->Start(iMbmsMonitorListParamsArray->At(iCurrentMbmsMonitorListIndex).iDuration,this,ETimerIdMbmsPcktService);
       
  2814 			}
       
  2815 
       
  2816 		}
       
  2817 	else
       
  2818 		{
       
  2819 		TInt ret = ActionEvent(EPacketEventTimeOut);
       
  2820 		__ASSERT_ALWAYS(ret==KErrNone,SimPanic(ETimeOutEventActionFailed));	// Note: this is very crude error handling and should be replaced by something rather more elegant.
       
  2821 		}
       
  2822 	LOGPACKET1("<<CSimPacketService::TimerCallBack");
       
  2823 	}
       
  2824 
       
  2825 void CSimPacketService::TimerCallBackDeactivate()
       
  2826 {
       
  2827 	// deactivate all contexts in every nif
       
  2828 	TInt totalWrappers = iNifWrappers.Count();
       
  2829 	for(TInt j=0; j < totalWrappers; j++)
       
  2830 		{
       
  2831 		TInt totalContexts = iNifWrappers[j].NumberOfContexts();
       
  2832 		for(TInt x =0; x<totalContexts; x++)
       
  2833 			{
       
  2834 			iNifWrappers[j].GetContext(x)->AttemptDeactivateImmediately();
       
  2835 			}
       
  2836 		}
       
  2837 }
       
  2838 
       
  2839 void CSimPacketService::TimerCallBackReleaseMode()
       
  2840 /**
       
  2841 * called when release mode timer callback occurs
       
  2842 */
       
  2843 	{
       
  2844 	if(iPacketReleaseModeArray->Count()<=iPacketReleaseModeIndex)
       
  2845 		return;
       
  2846 
       
  2847 	iCurrentPacketReleaseMode=iPacketReleaseModeArray->At(iPacketReleaseModeIndex).iReleaseMode;
       
  2848 
       
  2849 	// if event is pending complete request
       
  2850 	if(iNotifyChangeOfReleaseMode.iNotifyPending)
       
  2851 	{
       
  2852 	iNotifyChangeOfReleaseMode.iNotifyPending=EFalse;
       
  2853 	*(RPacketService::TPacketReleaseMode*)iNotifyChangeOfReleaseMode.iNotifyData=(RPacketService::TPacketReleaseMode)iCurrentPacketReleaseMode;
       
  2854 	ReqCompleted(iNotifyChangeOfReleaseMode.iNotifyHandle,KErrNone);
       
  2855 	}
       
  2856 
       
  2857 	iPacketReleaseModeIndex++;
       
  2858 	if (iPacketReleaseModeArray->Count() > (iPacketReleaseModeIndex))
       
  2859 		{	
       
  2860 		// start timer again
       
  2861 		iReleaseModeTimer->Start(iPacketReleaseModeArray->At(iPacketReleaseModeIndex).iDuration,this,ETimerIdPcktServReleaseMode);
       
  2862 		}
       
  2863 	}
       
  2864 
       
  2865 void CSimPacketService::TimerCallBackPcktRegStatus()
       
  2866 /**
       
  2867 * Timer Call back for the Network Registration status.
       
  2868 *
       
  2869 */
       
  2870 	{
       
  2871 	iState=(RPacketService::TStatus)iPcktRegStatusInfo->At(iPcktRegStatIndex).iStatus;
       
  2872 
       
  2873 	if(iNotifyStatusChange.iNotifyPending)
       
  2874 		{
       
  2875 		iNotifyStatusChange.iNotifyPending=EFalse;
       
  2876 		*(RPacketService::TStatus*)iNotifyStatusChange.iNotifyData=(RPacketService::TStatus)iState;
       
  2877 		ReqCompleted(iNotifyStatusChange.iNotifyHandle,KErrNone);
       
  2878 		}
       
  2879 	
       
  2880 	// please note that this bool is in case the test code is setting 
       
  2881 	// iState to another value, in which case the request will not complete
       
  2882 	// unless this bool is set and therefore the request will complete
       
  2883 	// in ActionEvent() 
       
  2884 	if (iCurrentEvent != EPacketEventNone)
       
  2885 		iPcktTimerBool = ETrue;
       
  2886 
       
  2887 	iPcktRegStatIndex++;
       
  2888 	if (iPcktRegStatusInfo->Count() > iPcktRegStatIndex)
       
  2889 		{
       
  2890 		iPcktRegTimer->Start(iPcktRegStatusInfo->At(iPcktRegStatIndex).iDuration,this,ETimerIdPcktServPacket);
       
  2891 		}
       
  2892 	}
       
  2893 
       
  2894 void CSimPacketService::SimPSEvent(const CSimPubSub::TPubSubProperty aProperty, TInt aStatus)
       
  2895 	{
       
  2896 
       
  2897 	
       
  2898 	if (aProperty == iNtwkRegStatusChangeProperty)
       
  2899 		{ // The call is for the network.
       
  2900 		TInt index = aStatus;
       
  2901 		TInt length = iNtwkRegStatusInfo->Count();
       
  2902 		if (index < length)
       
  2903 			{
       
  2904 			TNtwkRegStatus& ntwkRegStatus = iNtwkRegStatusInfo->At(index);
       
  2905 			CompleteNtwkRegStatus(ntwkRegStatus.iRegStatus);
       
  2906 			}
       
  2907 		}
       
  2908 	else if ( iIncomingContextManager->IsForcedIncoming( aProperty ) )
       
  2909 		{ //  Lets force the completion of the PDP, rather than waiting around 
       
  2910 		  // for a large time to finish.
       
  2911 		TInt index = aStatus;
       
  2912 		iIncomingContextManager->ForcedIncoming( index, iConfigData.iData );
       
  2913 		iIncomingContextManager->SetUseTimerOff();								
       
  2914 		ReqCompleted(iConfigData.iTsyReqHandle,KErrNone);
       
  2915 			// Force the change through as if the timer had timed out.
       
  2916 		iIncomingContextManager->SetUseTimerOn();								
       
  2917 			// May get more timeouts for other primary PDP's.
       
  2918 		}
       
  2919 	else
       
  2920 		{  // Error. Some sort of stange request. Hopefully impossible.
       
  2921 		LOGPACKET1("CSimPacketService::SimPSEvent property mismatch.");
       
  2922 		SimPanic(EFailedToSetProperty);
       
  2923 		}
       
  2924 	
       
  2925 	}
       
  2926 
       
  2927 void CSimPacketService::PubSubCallback(TInt aIndex)
       
  2928 	{
       
  2929 
       
  2930 	if(aIndex ==0 )
       
  2931 		{
       
  2932 		ReqCompleted(iGetMbmsNetworkReqHandle,KErrNone);	
       
  2933 		}
       
  2934 
       
  2935 	else if (aIndex ==1)
       
  2936 		{
       
  2937 		if(iNotifyMbmsServAvailChange.iNotifyPending)
       
  2938 			{
       
  2939 			iNotifyMbmsServAvailChange.iNotifyPending = EFalse;
       
  2940 			ReqCompleted(iNotifyMbmsServAvailChange.iNotifyHandle,KErrNone);
       
  2941 			}
       
  2942 		}
       
  2943 
       
  2944 	else if(aIndex ==2)
       
  2945 		{
       
  2946 		if(iUpdateMbmsServiceReqHandle)
       
  2947 			{
       
  2948 			ReqCompleted(iUpdateMbmsServiceReqHandle,iUpdateMbmsServiceError);
       
  2949 			}
       
  2950 		}
       
  2951 
       
  2952 	else if(aIndex ==3)
       
  2953 		{
       
  2954 		ReqCompleted(iEnumerateActiveListReqHandle,KErrNone);
       
  2955 		}
       
  2956 
       
  2957 	else if(aIndex ==4)
       
  2958 		{
       
  2959 		ReqCompleted(iEnumerateMonitorListReqHandle,KErrNone);
       
  2960 		}
       
  2961 
       
  2962 	else {}
       
  2963 }
       
  2964 
       
  2965 void CSimPacketService::TimerCallBackNtwkRegStatus()
       
  2966 	{
       
  2967 	if(iNtwkRegStatusInfo->Count()<=iNtwkRegStatIndex)
       
  2968 		return;
       
  2969 
       
  2970 	TNtwkRegStatus& ntwkRegStatus = iNtwkRegStatusInfo->At(iNtwkRegStatIndex);
       
  2971 	CompleteNtwkRegStatus(ntwkRegStatus.iRegStatus);
       
  2972 
       
  2973 	iNtwkRegStatIndex++;
       
  2974 	if(iNtwkRegStatusInfo->Count()>iNtwkRegStatIndex)
       
  2975 		iNtwkRegTimer->Start(iNtwkRegStatusInfo->At(iNtwkRegStatIndex).iDuration,this,ETimerIdPcktServNtwkStatusChange);
       
  2976 	}
       
  2977 	
       
  2978 void CSimPacketService::CompleteNtwkRegStatus(RPacketService::TRegistrationStatus aRegistrationStatus)
       
  2979 	{
       
  2980 	iCurrentRegStatus = aRegistrationStatus;
       
  2981 
       
  2982 	if(iNotifyChangeOfNtwk.iNotifyPending)
       
  2983 		{
       
  2984 		iNotifyChangeOfNtwk.iNotifyPending=EFalse;
       
  2985 		*(RPacketService::TRegistrationStatus*)iNotifyChangeOfNtwk.iNotifyData=(RPacketService::TRegistrationStatus)iCurrentRegStatus;
       
  2986 		ReqCompleted(iNotifyChangeOfNtwk.iNotifyHandle,KErrNone);
       
  2987 		}
       
  2988 
       
  2989 	if (//iCurrentRegStatus == RPacketService::ENotRegisteredSearching || 
       
  2990 		iCurrentRegStatus == RPacketService::ERegistrationDenied ||
       
  2991 		iCurrentRegStatus == RPacketService::ENotRegisteredButAvailable ||
       
  2992 		iCurrentRegStatus == RPacketService::ENotRegisteredAndNotAvailable)
       
  2993 	{
       
  2994 		// deactivate all contexts in every nif
       
  2995 		TInt totalWrappers = iNifWrappers.Count();
       
  2996 		for(TInt j=0; j < totalWrappers; j++)
       
  2997 			{
       
  2998 			TInt totalContexts = iNifWrappers[j].NumberOfContexts();
       
  2999 			for(TInt x =0; x<totalContexts; x++)
       
  3000 				{
       
  3001 				iNifWrappers[j].GetContext(x)->AttemptDeactivateImmediately();
       
  3002 				}
       
  3003 			}
       
  3004 	}
       
  3005 }
       
  3006 
       
  3007 TInt CSimPacketService::ChangeState(RPacketService::TStatus aNewState)
       
  3008 /**
       
  3009 * Attempt to change state.
       
  3010 * First validate that the requested state change is ok.  If it is then proceed to change
       
  3011 * the state and complete any pending state change notification.
       
  3012 *
       
  3013 * @param aState the new state to change to
       
  3014 * @return Error indication if change of state is successful or not
       
  3015 */
       
  3016 	{
       
  3017 	LOGPACKET2(">>CSimPacketService::ChangeState [newState=%d]", aNewState);
       
  3018 	if(iState == aNewState)
       
  3019 		return KErrNone;
       
  3020 
       
  3021 	TInt ret=KErrGeneral;
       
  3022 	const TPacketStateChangeValidity* stateChangePnt=KPacketStateChangeValidity;
       
  3023 	while(stateChangePnt->iOldState!=KPacketStateTableTerminator)
       
  3024 		{
       
  3025 		if((stateChangePnt->iOldState==iState) && (stateChangePnt->iNewState==aNewState))
       
  3026 			{
       
  3027 			ret=stateChangePnt->iError;
       
  3028 			break;
       
  3029 			}
       
  3030 		stateChangePnt++;
       
  3031 		}
       
  3032 
       
  3033 	if(ret!=KErrNone)
       
  3034 		return ret;
       
  3035 
       
  3036 //Request permission from the phone to change the state of the packet connection
       
  3037 	ret = iPhone->ValidateChangeState(aNewState);
       
  3038 	if(ret!=KErrNone)
       
  3039 		return ret;
       
  3040 
       
  3041 // Actually change the state.
       
  3042 	iState=aNewState;
       
  3043 
       
  3044 // if suspended or unattached take appropriate action
       
  3045 	if (iState==RPacketService::EStatusSuspended || iState == RPacketService::EStatusUnattached)
       
  3046 		{
       
  3047 			// deactivate all contexts in every nif
       
  3048 			TInt totalWrappers = iNifWrappers.Count();
       
  3049 			for(TInt j=0; j < totalWrappers; j++)
       
  3050 				{
       
  3051 				TInt totalContexts = iNifWrappers[j].NumberOfContexts();
       
  3052 				for(TInt x =0; x<totalContexts; x++)
       
  3053 					{
       
  3054 					ret = iNifWrappers[j].GetContext(x)->AttemptDeactivateImmediately();
       
  3055 					if(ret!=KErrNone)
       
  3056 						{
       
  3057 						break;
       
  3058 						}
       
  3059 					}
       
  3060 				}
       
  3061 		}
       
  3062 
       
  3063 // Check for a pending line state notification.
       
  3064 	if(iNotifyStatusChange.iNotifyPending)
       
  3065 		{
       
  3066 		iNotifyStatusChange.iNotifyPending=EFalse;
       
  3067 		*(RPacketService::TStatus*)iNotifyStatusChange.iNotifyData=iState;
       
  3068 		ReqCompleted(iNotifyStatusChange.iNotifyHandle,KErrNone);
       
  3069 		}
       
  3070 
       
  3071 	LOGPACKET1("<<CSimPacketService::ChangeState");
       
  3072 	return KErrNone;
       
  3073 	}
       
  3074 
       
  3075 TInt CSimPacketService::ActionEvent(TPacketEvent aEvent)
       
  3076 /**
       
  3077 * Entry point when an event has occured that may advance the state machine.
       
  3078 * The aEvent parameter describes the event.
       
  3079 *
       
  3080 * This function contains the main state machine for the packet service.  
       
  3081 *
       
  3082 * @param aEvent The Packet Service event to handle
       
  3083 * @return value represents the error state caused by the attempted state machine jump.
       
  3084 */
       
  3085 	{
       
  3086 	TInt ret=KErrNone;
       
  3087 
       
  3088 	switch(aEvent)
       
  3089 		{
       
  3090 	case EPacketEventAttach:
       
  3091 		LOGPACKET1(">>CSimPacketService::ActionEvent = [EPacketEventAttach]");
       
  3092 		if(iState==RPacketService::EStatusUnattached)
       
  3093 			{
       
  3094 			iCurrentEvent=EPacketEventAttach;
       
  3095 			iTimer->Start(iAttachPause,this);
       
  3096 			}
       
  3097 		else
       
  3098 			ReqCompleted(iAttachRequestHandle, KErrNone);
       
  3099 		break;
       
  3100 
       
  3101 	case EPacketEventDetach:
       
  3102 		LOGPACKET1(">>CSimPacketService::ActionEvent = [EPacketEventDetach]");
       
  3103 		if(iState !=RPacketService::EStatusUnattached)
       
  3104 			{
       
  3105 			iCurrentEvent=EPacketEventDetach;
       
  3106 			iTimer->Start(iDetachPause,this);
       
  3107 			}
       
  3108 		else
       
  3109 			{
       
  3110 			ReqCompleted(iDetachRequestHandle, KErrNone);
       
  3111 			}
       
  3112 		break;
       
  3113 
       
  3114 	case EPacketEventTimeOut:
       
  3115 		switch(iCurrentEvent)
       
  3116 			{
       
  3117 		case EPacketEventNone:
       
  3118 			break;
       
  3119 		case EPacketEventAttach:
       
  3120 			if(iAttachFail != KErrNone)
       
  3121 				{
       
  3122 				ReqCompleted(iAttachRequestHandle,iAttachFail);
       
  3123 				iCurrentEvent=EPacketEventNone;
       
  3124 				iAttachFail = KErrNone;
       
  3125 				break;
       
  3126 				}
       
  3127 			if(iState==RPacketService::EStatusUnattached)
       
  3128 				{
       
  3129 				ret=ChangeState(RPacketService::EStatusAttached);
       
  3130 				ReqCompleted(iAttachRequestHandle,ret);
       
  3131 				}
       
  3132 			else if (iPcktTimerBool)
       
  3133 				{	
       
  3134 				ReqCompleted(iAttachRequestHandle,KErrNone);
       
  3135 				iPcktTimerBool= EFalse;
       
  3136 				}
       
  3137 			iCurrentEvent=EPacketEventNone;
       
  3138 			break;
       
  3139 		case EPacketEventDetach:
       
  3140 			if(iDetachFail != KErrNone)
       
  3141 				{
       
  3142 				ReqCompleted(iDetachRequestHandle,iDetachFail);
       
  3143 				iCurrentEvent=EPacketEventNone;
       
  3144 				iDetachFail = KErrNone;
       
  3145 				break;
       
  3146 				}
       
  3147 			ret = DoDetach();
       
  3148 			if (iPcktTimerBool)
       
  3149 				{	
       
  3150 				ReqCompleted(iDetachRequestHandle,KErrNone);
       
  3151 				iPcktTimerBool= EFalse;
       
  3152 				}
       
  3153 			iCurrentEvent=EPacketEventNone;
       
  3154 			break;
       
  3155 		default:
       
  3156 			break;
       
  3157 			}
       
  3158 		break;
       
  3159 
       
  3160 	default:
       
  3161 		break;
       
  3162 		}
       
  3163 	return ret;
       
  3164 	}
       
  3165 
       
  3166 const CTestConfigSection* CSimPacketService::CfgFile()
       
  3167 /**
       
  3168 *	Return a pointer to the Configuration File Section
       
  3169 *
       
  3170 * @return CTestConfigSection	pointer to the configuration file section
       
  3171 */
       
  3172 	{
       
  3173 	return iPhone->CfgFile();
       
  3174 	}
       
  3175 
       
  3176 /**
       
  3177 * check that there is a primary context and that opening a secondary
       
  3178 * is a valid action
       
  3179 **/
       
  3180 TInt CSimPacketService::PrepareOpenSecondary(const TTsyReqHandle aTsyReqHandle, const TDesC* aOriginalContextName)
       
  3181 	{
       
  3182 	TInt i = 0;
       
  3183 	TInt err = KErrNone;
       
  3184 
       
  3185 	for(i = 0; i<iNifWrappers.Count(); i++)
       
  3186 		{
       
  3187 		TNifWrapper& nifWrapper = iNifWrappers[i];
       
  3188 		for (TInt j = 0; j < nifWrapper.NumberOfContexts(); j++)
       
  3189 			{
       
  3190 			if (nifWrapper.GetContext(j)->ContextName().Compare(*aOriginalContextName) == KErrNone)
       
  3191 				{
       
  3192 				iSecondaryContext = ETrue;
       
  3193 				iCurrentPrimaryContextIndex = i;
       
  3194 				break;
       
  3195 				}
       
  3196 			}
       
  3197 		}
       
  3198 	
       
  3199 	if (iSecondaryContext == EFalse)
       
  3200 		err = KErrNotSupported;
       
  3201 	
       
  3202 	ReqCompleted(aTsyReqHandle, err);
       
  3203 	return err;
       
  3204 	}
       
  3205 
       
  3206 TInt CSimPacketService::GetCurrentReleaseMode(const TTsyReqHandle aTsyReqHandle,RPacketService::TPacketReleaseMode* aReleaseMode)
       
  3207 // return current release mode
       
  3208 	{
       
  3209 	LOGPACKET1("CSimPacketService::GetCurrentReleaseMode called");
       
  3210 	*aReleaseMode = (RPacketService::TPacketReleaseMode)iCurrentPacketReleaseMode;
       
  3211 	ReqCompleted(aTsyReqHandle, KErrNone);
       
  3212 	return KErrNone;
       
  3213 	}
       
  3214 	
       
  3215 TInt CSimPacketService::NotifyReleaseModeChange(const TTsyReqHandle aTsyReqHandle, RPacketService::TPacketReleaseMode* aReleaseMode)
       
  3216 	{
       
  3217 	// if release mode has changed
       
  3218 	if(iPacketReleaseModeArray->Count()==0)
       
  3219 		{
       
  3220 		ReqCompleted(aTsyReqHandle,KErrNotSupported);
       
  3221 		return KErrNotSupported;
       
  3222 		}
       
  3223 
       
  3224 	__ASSERT_ALWAYS(!iNotifyChangeOfReleaseMode.iNotifyPending,SimPanic(ENotificationReqAlreadyOutstanding));
       
  3225 
       
  3226 	iNotifyChangeOfReleaseMode.iNotifyPending=ETrue;
       
  3227 	iNotifyChangeOfReleaseMode.iNotifyHandle=aTsyReqHandle;
       
  3228 	iNotifyChangeOfReleaseMode.iNotifyData=&aReleaseMode;
       
  3229 	return KErrNone;
       
  3230 	}
       
  3231 
       
  3232 TInt CSimPacketService::EnumerateNifs(const TTsyReqHandle aTsyReqHandle, TInt& aCount) 
       
  3233 	{
       
  3234 // return number of nifs
       
  3235 	aCount = iNifWrappers.Count();
       
  3236 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  3237 	return KErrNone;
       
  3238 	}
       
  3239 
       
  3240 TInt CSimPacketService::GetNifInfo(const TTsyReqHandle aTsyReqHandle, TInt aIndex, TDes8* aNifInfoV2) 
       
  3241 	{
       
  3242 // get info for nif
       
  3243 	TInt range = iNifWrappers.Count()-1;
       
  3244 	if (aIndex < 0 || aIndex > range)
       
  3245 		{
       
  3246 		ReqCompleted(aTsyReqHandle,KErrArgument);
       
  3247 		return KErrArgument;
       
  3248 		}
       
  3249 
       
  3250 	RPacketService::TNifInfoV2Pckg* nifInfoV2Pckg = (RPacketService::TNifInfoV2Pckg*)aNifInfoV2;
       
  3251 	RPacketService::TNifInfoV2& nifInfoV2 = (*nifInfoV2Pckg)();
       
  3252 
       
  3253 	// Check that the data structure is supported by the simulated TSY version
       
  3254 	TInt err = iPhone->CheckSimTsyVersion(nifInfoV2);
       
  3255 	if(err != KErrNone)
       
  3256 		{
       
  3257 		iPhone->ReqCompleted(aTsyReqHandle, err);
       
  3258 		return KErrNone;
       
  3259 		}
       
  3260 
       
  3261 	nifInfoV2.iContextName.Copy(iNifWrappers[aIndex].GetContext(0)->ContextName());
       
  3262 	nifInfoV2.iContextType = STATIC_CAST(RPacketService::TContextType, iNifWrappers[aIndex].GetContext(0)->ContextType());
       
  3263 
       
  3264 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  3265 	return KErrNone;
       
  3266 	}
       
  3267 
       
  3268 /***
       
  3269 * This function takes the name passed in the parameter aExistingContextName and 
       
  3270 * returns the number of contexts sharing its Nif. 
       
  3271 ***/
       
  3272 TInt CSimPacketService::EnumerateContextsInNif(const TTsyReqHandle aTsyReqHandle, const TDesC* aExistingContextName, TInt& aCount) 
       
  3273 	{
       
  3274 	// find contexts sharing name aExistingContextName, ie primary and secondary as well
       
  3275 	TInt number = KErrNotFound;
       
  3276 	TInt wrappersCount = iNifWrappers.Count();
       
  3277 
       
  3278 	for(TInt i = 0; i<wrappersCount; i++)
       
  3279 		{
       
  3280 		TInt contextsTotal = iNifWrappers[i].NumberOfContexts();
       
  3281 		for(TInt j = 0; j<contextsTotal; j++)
       
  3282 			{
       
  3283 			if(iNifWrappers[i].GetContext(j)->ContextName().Compare(*aExistingContextName) == KErrNone)
       
  3284 				{
       
  3285 				number = iNifWrappers[i].NumberOfContexts();
       
  3286 				break;
       
  3287 				}
       
  3288 			}
       
  3289 		}
       
  3290 
       
  3291 	// ie couldn't find context of aExistingContextName
       
  3292 	if (number == KErrNotFound)
       
  3293 		{
       
  3294 		ReqCompleted(aTsyReqHandle, KErrArgument);
       
  3295 		return KErrArgument;
       
  3296 		}
       
  3297 
       
  3298 	// count primary context as well!
       
  3299 	aCount = number;
       
  3300 	ReqCompleted(aTsyReqHandle, KErrNone);
       
  3301 	return KErrNone;
       
  3302 	}
       
  3303 
       
  3304 TInt CSimPacketService::GetContextNameInNif(const TTsyReqHandle aTsyReqHandle, const TDesC* aExistingContextName, TInt aIndex, TDes* aContextName) 
       
  3305 	{
       
  3306 // get for context name specified, find nif's context name at index given
       
  3307 	// first, check aExistingContextName exists in contexts
       
  3308 	TInt number = KErrNotFound;
       
  3309 	TInt wrappersCount =  iNifWrappers.Count();
       
  3310 
       
  3311 	for(TInt i = 0; i<wrappersCount; i++)
       
  3312 		{
       
  3313 		TInt contextsTotal = iNifWrappers[i].NumberOfContexts();
       
  3314 		for(TInt j = 0; j<contextsTotal; j++)
       
  3315 			{
       
  3316 			if (iNifWrappers[i].GetContext(j)->ContextName().Compare(*aExistingContextName) == KErrNone)
       
  3317 				{
       
  3318 				number = i;
       
  3319 				break;
       
  3320 				}
       
  3321 			}
       
  3322 		}
       
  3323 
       
  3324 	// total no. of contexts with name is number of secondary contexts plus primary, so
       
  3325 	// number + 1
       
  3326 	// so range should be within number+1-1 ie number.
       
  3327 	if (number == KErrNotFound || aIndex < 0 || aIndex > number)
       
  3328 		{
       
  3329 		ReqCompleted(aTsyReqHandle, KErrArgument);
       
  3330 		return KErrArgument;
       
  3331 		}
       
  3332 	
       
  3333 	*aContextName = iNifWrappers[number].GetContext(aIndex)->ContextName();
       
  3334 	ReqCompleted(aTsyReqHandle, KErrNone);
       
  3335 	return KErrNone;
       
  3336 	}
       
  3337 
       
  3338 /**
       
  3339 * Cancel method, returns KErrNone
       
  3340 */
       
  3341 TInt CSimPacketService::GetCurrentReleaseModeCancel(const TTsyReqHandle /*aTsyReqHandle*/)
       
  3342 	{
       
  3343 	return KErrNone;
       
  3344 	}
       
  3345 
       
  3346 /**
       
  3347 * Cancel method, returns KErrNone
       
  3348 */
       
  3349 TInt CSimPacketService::NotifyReleaseModeChangeCancel(const TTsyReqHandle aTsyReqHandle)
       
  3350 	{
       
  3351 	LOGPACKET1("CSimPacketService::NotifyChangeOfNtwkRegStatusCancel called");
       
  3352 	if(iNotifyChangeOfReleaseMode.iNotifyPending)
       
  3353 		{
       
  3354 		iNotifyChangeOfReleaseMode.iNotifyPending=EFalse;
       
  3355 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  3356 		}
       
  3357 	return KErrNone;
       
  3358 	}
       
  3359 
       
  3360 /**
       
  3361 * Cancel method, returns KErrNone
       
  3362 */
       
  3363 TInt CSimPacketService::EnumerateNifsCancel(const TTsyReqHandle /*aTsyReqHandle*/)
       
  3364 	{
       
  3365 	return KErrNone;
       
  3366 	}
       
  3367 
       
  3368 /**
       
  3369 * Cancel method, returns KErrNone
       
  3370 */
       
  3371 TInt CSimPacketService::GetNifInfoCancel(const TTsyReqHandle /*aTsyReqHandle*/)
       
  3372 	{
       
  3373 	return KErrNone;
       
  3374 	}
       
  3375 
       
  3376 /**
       
  3377 * Cancel method, returns KErrNone
       
  3378 */
       
  3379 TInt CSimPacketService::EnumerateContextsInNifCancel(const TTsyReqHandle /*aTsyReqHandle*/)
       
  3380 	{
       
  3381 	return KErrNone;
       
  3382 	}
       
  3383 
       
  3384 /**
       
  3385 * Cancel method, returns KErrNone
       
  3386 */	
       
  3387 TInt CSimPacketService::GetContextNameInNifCancel(const TTsyReqHandle /*aTsyReqHandle*/)
       
  3388 	{
       
  3389 	return KErrNone;
       
  3390 	}
       
  3391 	
       
  3392 /**
       
  3393 * Cancel method, returns KErrNone
       
  3394 */
       
  3395 TInt CSimPacketService::NotifyAttachModeChangeCancel(const TTsyReqHandle aTsyReqHandle)
       
  3396 	{
       
  3397 	LOGPACKET1("CSimPacketService::NotifyAttachModeChangeCancel called");
       
  3398 	if(iNotifyChangeOfAttachMode.iNotifyPending)
       
  3399 		{
       
  3400 		iNotifyChangeOfAttachMode.iNotifyPending=EFalse;
       
  3401 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  3402 		}
       
  3403 	return KErrNone;
       
  3404 	}
       
  3405 
       
  3406 TInt CSimPacketService::GetMbmsNetworkServiceStatus(const TTsyReqHandle aTsyReqHandle, TBool aAttemptAttach,TMbmsNetworkServiceStatus* aStatus)
       
  3407 /**
       
  3408 * Retrieves and returns the status of the MBMS Packet service
       
  3409 *
       
  3410 * @param aTsyReqHandle Tsy Request handle for the client request
       
  3411 * @param aStatus pointer to the status
       
  3412 * @return TInt err KErrNone if ok
       
  3413 */
       
  3414 	{
       
  3415 	LOGPACKET1("CSimPacketService::GetMbmsNetworkServiceStatus called");
       
  3416 	*aStatus = (iMbmsBroadcastParamsArray->At(iCurrentMbmsParamsIndex).iMbmsNetworkStatus);
       
  3417 	if(aAttemptAttach)
       
  3418 		{
       
  3419 		if(*aStatus == EMbmsSupportUnknown)
       
  3420 			{
       
  3421 			*aStatus = EMbmsSupported;
       
  3422 			}
       
  3423 		}
       
  3424 	iGetMbmsNetworkReqHandle = aTsyReqHandle;
       
  3425 	iCurrentMbmsParamsIndex++;
       
  3426 	TInt totCount = iMbmsBroadcastParamsArray->Count();
       
  3427 	if(iCurrentMbmsParamsIndex == totCount)
       
  3428 		{
       
  3429 		iCurrentMbmsParamsIndex--;
       
  3430 		}
       
  3431 	return KErrNone;
       
  3432 	}
       
  3433 
       
  3434 TInt CSimPacketService::GetMbmsNetworkServiceStatusCancel(const TTsyReqHandle aTsyReqHandle)
       
  3435 /* 
       
  3436  * Cancels the GetMBMSNetworkServiceStatus request.
       
  3437  * In fact this is not needed- just to avoid Panic if called, this implementation is done.
       
  3438  */
       
  3439 	{
       
  3440 	if(iGetMbmsNetworkReqHandle == aTsyReqHandle)
       
  3441 		{
       
  3442 		ReqCompleted(iGetMbmsNetworkReqHandle,KErrCancel);
       
  3443 		}
       
  3444 	else
       
  3445 		{
       
  3446 		ReqCompleted(iGetMbmsNetworkReqHandle,KErrCorrupt);
       
  3447 		}
       
  3448 	return KErrNone;
       
  3449 	}
       
  3450 
       
  3451 TInt CSimPacketService::NotifyMbmsNetworkServiceStatusChange(const TTsyReqHandle aTsyReqHandle, TMbmsNetworkServiceStatus* aStatus)
       
  3452 /**
       
  3453 * Record a client's interest in being notified of the state of the MBMS packet network and contexts.
       
  3454 * First check that there isn't already a notification pending (the ETel Server should protect
       
  3455 * against this) and then record the information necessary to complete the request later, when
       
  3456 * the status does actually change.
       
  3457 *
       
  3458 * @param aTsyReqHandle Tsy Request handle for the client request
       
  3459 * @param aStatus pointer to the mbms packet service status
       
  3460 * @return KErrNone
       
  3461 */
       
  3462 	{
       
  3463 	LOGPACKET1("CSimPacketService::NotifyMbmsNetworkServiceStatusChange called");
       
  3464  	__ASSERT_ALWAYS(!iNotifyMbmsNetworkStatusChange.iNotifyPending,SimPanic(ENotificationAlreadyPending));
       
  3465 
       
  3466  	iNotifyMbmsNetworkStatusChange.iNotifyPending = ETrue;
       
  3467 	iNotifyMbmsNetworkStatusChange.iNotifyHandle = aTsyReqHandle;
       
  3468  	iNotifyMbmsNetworkStatusChange.iNotifyData = aStatus;
       
  3469 	return KErrNone;
       
  3470 	}
       
  3471 
       
  3472 TInt CSimPacketService::NotifyMbmsNetworkServiceStatusChangeCancel(const TTsyReqHandle aTsyReqHandle)
       
  3473 /**
       
  3474 * Cancel a client's interest in being notified when the mbms network status changes.
       
  3475 * This is acheived simply by resetting the flag that indicates a notification is pending.
       
  3476 * 
       
  3477 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3478 * @return KErrNone
       
  3479 */
       
  3480 	{
       
  3481 	LOGPACKET1("CSimPacketService::NotifyMbmsNetworkServiceStatusChangeCancel called");
       
  3482 	if(iNotifyMbmsNetworkStatusChange.iNotifyPending)
       
  3483 		{
       
  3484 		iNotifyMbmsNetworkStatusChange.iNotifyPending=EFalse;
       
  3485 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  3486 		}
       
  3487 	return KErrNone;
       
  3488 	}
       
  3489 
       
  3490 TInt CSimPacketService::NotifyMbmsServiceAvailabilityChange(const TTsyReqHandle aTsyReqHandle)
       
  3491 /**
       
  3492 * Record a client's interest in being notified of the service availability of the MBMS packet network.
       
  3493 * First check that there isn't already a notification pending (the ETel Server should protect
       
  3494 * against this) and then record the information necessary to complete the request later, when
       
  3495 * the status does actually change.
       
  3496 *
       
  3497 * @param aTsyReqHandle Tsy Request handle for the client request
       
  3498 * @return KErrNone
       
  3499 */
       
  3500 	{
       
  3501 	LOGPACKET1("CSimPacketService::NotifyMbmsServiceAvailabilityChange called");
       
  3502  	__ASSERT_ALWAYS(!iNotifyMbmsNetworkStatusChange.iNotifyPending,SimPanic(ENotificationAlreadyPending));
       
  3503 
       
  3504  	iNotifyMbmsServAvailChange.iNotifyPending = ETrue;
       
  3505  	iNotifyMbmsServAvailChange.iNotifyHandle = aTsyReqHandle;
       
  3506  	(void)iNotifyMbmsServAvailChange.iNotifyData;
       
  3507 	return KErrNone;
       
  3508 	}
       
  3509 
       
  3510 TInt CSimPacketService::NotifyMbmsServiceAvailabilityChangeCancel(const TTsyReqHandle aTsyReqHandle)
       
  3511 /**
       
  3512 * Cancel a client's interest in being notified when the mbms service availability changes.
       
  3513 * This is acheived simply by resetting the flag that indicates a notification is pending.
       
  3514 * 
       
  3515 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3516 * @return KErrNone
       
  3517 */
       
  3518 	{
       
  3519 	LOGPACKET1("CSimPacketService::NotifyMbmsServiceAvailabilityChangeCancel called");
       
  3520 	if(iNotifyMbmsServAvailChange.iNotifyPending)
       
  3521 		{
       
  3522 		iNotifyMbmsServAvailChange.iNotifyPending=EFalse;
       
  3523 		ReqCompleted(aTsyReqHandle,KErrCancel);
       
  3524 		}
       
  3525 	return KErrNone;
       
  3526 	}
       
  3527 
       
  3528 TInt CSimPacketService::UpdateMbmsMonitorServiceListL(const TTsyReqHandle aTsyReqHandle,TMbmsAction* aAction, TDes8* aBuffer)
       
  3529 /**
       
  3530 * client's interest in updating the MBMS Service Monitoring list.
       
  3531 * The update action is also passed as the MBMS Action parameter.
       
  3532 * This will update the MBMS Service Monitoring List in TSY.
       
  3533 * 
       
  3534 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3535 * @param aAction TMbmsAction to be performed
       
  3536 * @param aBuffer list of TMbmsServiceAvailabilityV1 class passed.
       
  3537 * @return KErrNone
       
  3538 */
       
  3539 	{
       
  3540 	LOGPACKET1("CSimPacketService::UpdateMbmsMonitorServiceListL called");
       
  3541 	CPcktMbmsMonitoredServiceList* monServList = CPcktMbmsMonitoredServiceList::NewL();
       
  3542 	CleanupStack::PushL(monServList); 
       
  3543 
       
  3544 	TInt error=KErrNone;
       
  3545 	TInt i=0;
       
  3546 	TInt j=0;
       
  3547 	TInt ii=0;
       
  3548 	TInt countAdd=0;
       
  3549 	TInt countRem=0;
       
  3550 	RPacketService::TMbmsServiceAvailabilityV1 entry;
       
  3551 	
       
  3552 	switch(*aAction)
       
  3553 		{
       
  3554 		case SIMTSY_PACKET_MBMS_ADD_ENTRIES:
       
  3555 			LOGPACKET1("CSimPacketService::UpdateMbmsMonitorServiceListL Action: ADD ");
       
  3556 			monServList->RestoreL(*aBuffer);
       
  3557 			countAdd = monServList->Enumerate();
       
  3558 			if(countAdd != SIMTSY_PACKET_MBMS_ADD_ENTRIES_COUNT)
       
  3559 				{
       
  3560 				ReqCompleted(aTsyReqHandle,KErrCorrupt);
       
  3561 				CleanupStack::PopAndDestroy(); // monServList
       
  3562 				return KErrNone;
       
  3563 				}
       
  3564 			for(;i<SIMTSY_PACKET_MBMS_ADD_ENTRIES_COUNT;i++)
       
  3565 				{
       
  3566 				TRAPD(ret,entry=monServList->GetEntryL(i));
       
  3567 				if (ret != KErrNone)
       
  3568 					{
       
  3569 					break;
       
  3570 					}
       
  3571 				TBool entryFound=EFalse;
       
  3572 				
       
  3573 				for(ii=0;ii<iMbmsMonitorListParamsArray->Count();ii++)
       
  3574 					{
       
  3575 					 if((entry.iMbmsServiceMode == iMbmsMonitorListParamsArray->At(ii).iServiceMode) &&
       
  3576 						(entry.iMbmsAccessBearer == iMbmsMonitorListParamsArray->At(ii).iAccessBearer) &&
       
  3577 						(entry.iTmgi.GetMCC() == iMbmsMonitorListParamsArray->At(ii).iMCC) &&
       
  3578 						(entry.iTmgi.GetMNC() == iMbmsMonitorListParamsArray->At(ii).iMNC) &&
       
  3579 						(entry.iTmgi.GetServiceId() == iMbmsMonitorListParamsArray->At(ii).iServiceId))		
       
  3580 							{
       
  3581 							entryFound =  ETrue;
       
  3582 							break;
       
  3583 							}
       
  3584 					}
       
  3585 					
       
  3586 				if(!entryFound)
       
  3587 					{
       
  3588 					error = KErrMbmsImpreciseServiceEntries;
       
  3589 					}
       
  3590 					
       
  3591 				else
       
  3592 					{
       
  3593 					entry.iMbmsAvailabilityStatus = iMbmsMonitorListParamsArray->At(ii).iAvailStatus ;
       
  3594 					}
       
  3595 				 	
       
  3596 				}
       
  3597 			iMbmsMonitorListCount += i;
       
  3598 			if(iMbmsMonitorListCount > KMaxMbmsMonitorContexts)
       
  3599 				{
       
  3600 				error =KErrNoMemory;
       
  3601 				iMbmsMonitorListCount -= i;
       
  3602 				}
       
  3603 			
       
  3604 			ReqCompleted(aTsyReqHandle, error);
       
  3605 			CleanupStack::PopAndDestroy(); // monServList
       
  3606 			break;
       
  3607 
       
  3608 		case SIMTSY_PACKET_MBMS_REM_ENTRIES:
       
  3609 			LOGPACKET1("CSimPacketService::UpdateMbmsMonitorServiceListL Action: REMOVE ");
       
  3610 			monServList->RestoreL(*aBuffer);
       
  3611 			countRem = monServList->Enumerate();
       
  3612 			if(countRem != SIMTSY_PACKET_MBMS_REM_ENTRIES_COUNT)
       
  3613 				{
       
  3614 				ReqCompleted(aTsyReqHandle,KErrCorrupt);
       
  3615 				CleanupStack::PopAndDestroy(); // monServList
       
  3616 				return KErrNone;
       
  3617 				}
       
  3618 	
       
  3619 			for(;i<SIMTSY_PACKET_MBMS_REM_ENTRIES_COUNT;i++)
       
  3620 				{
       
  3621 				TRAPD(ret,entry=monServList->GetEntryL(i));
       
  3622 				
       
  3623 				if (ret != KErrNone)
       
  3624 					{
       
  3625 					break;
       
  3626 					}
       
  3627 					
       
  3628 				TBool entryFound=EFalse;
       
  3629 				
       
  3630 				for(ii=0;ii<iMbmsMonitorListParamsArray->Count();ii++)
       
  3631 					{
       
  3632 					 if((entry.iMbmsServiceMode == iMbmsMonitorListParamsArray->At(ii).iServiceMode) &&
       
  3633 						(entry.iMbmsAccessBearer == iMbmsMonitorListParamsArray->At(ii).iAccessBearer) &&
       
  3634 						(entry.iTmgi.GetMCC() == iMbmsMonitorListParamsArray->At(ii).iMCC) &&
       
  3635 						(entry.iTmgi.GetMNC() == iMbmsMonitorListParamsArray->At(ii).iMNC) &&
       
  3636 						(entry.iTmgi.GetServiceId() == iMbmsMonitorListParamsArray->At(ii).iServiceId))		
       
  3637 					 		{
       
  3638 					 		entryFound =  ETrue;
       
  3639 					 		break;
       
  3640 					 		}
       
  3641 					}
       
  3642 					
       
  3643 				if(!entryFound)
       
  3644 					{
       
  3645 					j++;
       
  3646 					error = KErrMbmsImpreciseServiceEntries;
       
  3647 					}
       
  3648 					
       
  3649 				else
       
  3650 					{
       
  3651 					entry.iMbmsAvailabilityStatus = iMbmsMonitorListParamsArray->At(ii).iAvailStatus ;
       
  3652 					iMbmsMonitorListParamsArray->Delete(ii);
       
  3653 					}
       
  3654 				 	
       
  3655 				}
       
  3656 				if(j == SIMTSY_PACKET_MBMS_REM_ENTRIES_COUNT)
       
  3657 					{
       
  3658 					error = KErrNotFound;					
       
  3659 					}
       
  3660 					
       
  3661 			if(iMbmsMonitorListCount >=j)
       
  3662 				{
       
  3663 				iMbmsMonitorListCount -= j;
       
  3664 				}
       
  3665 				
       
  3666 			iUpdateMbmsServiceError = error;
       
  3667 			iUpdateMbmsServiceReqHandle = aTsyReqHandle;
       
  3668 			
       
  3669 			CleanupStack::PopAndDestroy(); // monServList
       
  3670 			break;
       
  3671 			
       
  3672 		case SIMTSY_PACKET_MBMS_REM_ALL_ENTRIES:
       
  3673 			iMbmsMonitorListCount = 0;
       
  3674 			iMbmsMonitorListParamsArray->Delete(0,iMbmsMonitorListParamsArray->Count());
       
  3675 			LOGPACKET1("CSimPacketService::UpdateMbmsMonitorServiceListL Action: REMOVE_ALL ");
       
  3676 			iUpdateMbmsServiceError = KErrNone;
       
  3677 			iUpdateMbmsServiceReqHandle = aTsyReqHandle;
       
  3678 			CleanupStack::PopAndDestroy(); // monServList
       
  3679 			break;
       
  3680 			
       
  3681 		default:
       
  3682 			LOGPACKET1("CSimPacketService::UpdateMbmsMonitorServiceListL Action: Default ");
       
  3683 			ReqCompleted(aTsyReqHandle,KErrNotFound);
       
  3684 			CleanupStack::PopAndDestroy(); // monServList
       
  3685 			break;
       
  3686 		}
       
  3687 	return KErrNone;
       
  3688 	}
       
  3689 
       
  3690 TInt CSimPacketService::UpdateMbmsMonitorServiceListCancel(const TTsyReqHandle aTsyReqHandle)
       
  3691 /**
       
  3692 * client's interest in cancelling the updation MBMS Service Monitoring list.
       
  3693 * 
       
  3694 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3695 * @return KErrNone
       
  3696 */
       
  3697 	{
       
  3698 	LOGPACKET1("CSimPacketService::UpdateMbmsMonitorServiceListCancel Called ");
       
  3699 	ReqCompleted(aTsyReqHandle,KErrCancel);
       
  3700 	return KErrNone;
       
  3701 	}
       
  3702 
       
  3703 // CHANGES FOR 2 Phase retrieval of MBMS Monitored Services list starts here.
       
  3704 
       
  3705 TInt CSimPacketService::GetMbmsMonitoredServicesListPhase1(const TTsyReqHandle aTsyReqHandle, TClientId* aClient, TInt* aBufSize)
       
  3706 /**
       
  3707 * client's interest in retrieving the MBMS Service Monitoring list.
       
  3708 * This function is the call for the first phase of 2 phase retrieval.
       
  3709 * 
       
  3710 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3711 * @param aAction TClientId to be used
       
  3712 * @param aBufSize Size to be allocated for retrieving the actual list in second phase.
       
  3713 * @return KErrNone
       
  3714 */
       
  3715 	{
       
  3716 	LOGPACKET1("CSimPacketService::GetMbmsMonitoredServicesListPhase1 called");
       
  3717 	TInt ret=KErrNone;
       
  3718 	TInt leaveCode=KErrNone;
       
  3719 	TRAP(leaveCode, ret=ProcessGetMbmsMonitoredServicesListPhase1L(aTsyReqHandle, aClient, aBufSize););
       
  3720 	if (leaveCode != KErrNone)
       
  3721 		{
       
  3722 		ReqCompleted(aTsyReqHandle,leaveCode);
       
  3723 		}
       
  3724 	return ret;
       
  3725 	}	
       
  3726 	
       
  3727 TInt CSimPacketService::ProcessGetMbmsMonitoredServicesListPhase1L(const TTsyReqHandle aTsyReqHandle, 
       
  3728 													 TClientId* aClient, 
       
  3729 													 TInt* aBufSize)
       
  3730 /**
       
  3731 * Local function to perform the first phse of the 2 phase retrieval.
       
  3732 * 
       
  3733 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3734 * @param aAction TClientId to be used
       
  3735 * @param aBufSize Size to be allocated for retrieving the actual list in second phase.
       
  3736 * @return KErrNone
       
  3737 */
       
  3738 	{
       
  3739 	
       
  3740 	LOGPACKET1("CSimPacketService::ProcessGetMbmsMonitoredServicesListPhase1L called");
       
  3741 	CPcktMbmsMonitoredServiceList* list=CPcktMbmsMonitoredServiceList::NewL();
       
  3742 	CleanupStack::PushL(list);
       
  3743 
       
  3744 	RPacketService::TMbmsServiceAvailabilityV1 entry;
       
  3745 	
       
  3746 	for (TInt i=0; i <iMbmsMonitorListParamsArray->Count(); i++)
       
  3747 		{
       
  3748 			entry.iMbmsServiceMode = iMbmsMonitorListParamsArray->At(i).iServiceMode;
       
  3749 			entry.iMbmsAccessBearer = iMbmsMonitorListParamsArray->At(i).iAccessBearer;
       
  3750 			entry.iMbmsAvailabilityStatus = iMbmsMonitorListParamsArray->At(i).iAvailStatus;
       
  3751 			entry.iTmgi.SetMCC(iMbmsMonitorListParamsArray->At(i).iMCC);
       
  3752 			entry.iTmgi.SetMNC(iMbmsMonitorListParamsArray->At(i).iMNC);
       
  3753 			entry.iTmgi.SetServiceId(iMbmsMonitorListParamsArray->At(i).iServiceId);
       
  3754 			// Add the entry into the list, at the next empty location
       
  3755 			LOGPACKET2("Adding the Entry no. %d to the List",i+1);
       
  3756 			list->AddEntryL(entry);
       
  3757 		}
       
  3758 	
       
  3759 	// Store the  streamed list and the client ID
       
  3760 	CPcktListReadAllAttempt* read=CPcktListReadAllAttempt::NewL(*aClient,aTsyReqHandle);
       
  3761 	CleanupStack::PushL(read);
       
  3762 	
       
  3763 	read->iListBuf = list->StoreLC();
       
  3764 	CleanupStack::Pop(); // pop the CBufBase allocated by StoreLC
       
  3765 	
       
  3766 	iMbmsServicesList->AppendL(read);
       
  3767 	CleanupStack::Pop(); // pop the CPcktListReadAllAttempt
       
  3768 	
       
  3769 	// return the CBufBase size to client
       
  3770 	*aBufSize=(read->iListBuf)->Size();
       
  3771 	
       
  3772 	// Complete first phase of list retrieval
       
  3773 	ReqCompleted(aTsyReqHandle,KErrNone);
       
  3774 	CleanupStack::PopAndDestroy(); // pop&destroy list
       
  3775 	
       
  3776 	return KErrNone;
       
  3777 	}
       
  3778 
       
  3779 TInt CSimPacketService::GetMbmsMonitoredServicesListPhase2(const TTsyReqHandle aTsyReqHandle,TClientId* aClient, TDes8* aBuf)
       
  3780 /**
       
  3781 * client's interest in retrieving the MBMS Service Monitoring list.
       
  3782 * This function is the call for the second phase of 2 phase retrieval.
       
  3783 * 
       
  3784 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3785 * @param aAction TClientId to be used
       
  3786 * @param aBuf buffer for the actual list to be populated.
       
  3787 * @return KErrNone
       
  3788 */
       
  3789 	{
       
  3790 	LOGPACKET1("CSimPacketService::GetMbmsMonitoredServicesListPhase2 called");
       
  3791 	CPcktListReadAllAttempt* read=NULL;
       
  3792 	// Find the get MBMS Monitor Service List from this client
       
  3793 	for (TInt i=0; i<iMbmsServicesList->Count(); ++i)
       
  3794 		{
       
  3795 		read = iMbmsServicesList->At(i);
       
  3796 		if ((read->iClient.iSessionHandle==aClient->iSessionHandle) &&
       
  3797 		    (read->iClient.iSubSessionHandle==aClient->iSubSessionHandle))
       
  3798 			{
       
  3799 			TPtr8 bufPtr((read->iListBuf)->Ptr(0));
       
  3800 			// Copy the streamed list to the client
       
  3801 			aBuf->Copy(bufPtr);
       
  3802 			delete read;
       
  3803 			
       
  3804 			iMbmsServicesList->Delete(i);
       
  3805 			ReqCompleted(aTsyReqHandle,KErrNone);
       
  3806 			return KErrNone;
       
  3807 			}
       
  3808 		}
       
  3809 	// Should handle error case of not finding the matching client from read all phase 1
       
  3810 	return KErrNotFound;
       
  3811 	}
       
  3812 	
       
  3813 TInt CSimPacketService::GetMbmsMonitoredServicesListCancel(const TTsyReqHandle aTsyReqHandle)
       
  3814 /**
       
  3815 * client's interest in canceling the retrieval of the MBMS Service Monitoring list.
       
  3816 * 
       
  3817 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3818 * @return KErrNone
       
  3819 */
       
  3820 	{
       
  3821 	LOGPACKET1("CSimPacketService::GetMbmsMonitoredServicesListCancel called");
       
  3822 	// Remove the read all attempt from iGetMbmsMonitoredServices
       
  3823 
       
  3824 	CPcktListReadAllAttempt* read=NULL;
       
  3825 	for (TInt i=0; i<iMbmsServicesList->Count(); ++i)
       
  3826 		{
       
  3827 		read = iMbmsServicesList->At(i);
       
  3828 		if (read->iReqHandle == aTsyReqHandle)
       
  3829 			{
       
  3830 			delete read;
       
  3831 			iMbmsServicesList->Delete(i);
       
  3832 			break;
       
  3833 			}
       
  3834 		}
       
  3835 	ReqCompleted(aTsyReqHandle,KErrCancel);
       
  3836 	return KErrNone;
       
  3837 	}
       
  3838 
       
  3839 TInt CSimPacketService::EnumerateMbmsMonitorServiceList(const TTsyReqHandle aTsyReqHandle, TInt* aCount, TInt* aMaxAllowed)
       
  3840 /**
       
  3841 * client's interest in retrieving the information regarding the MBMS Monitoring Service list.
       
  3842 * 
       
  3843 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3844 * @param aCount count of the MBMS monitoring services in the list
       
  3845 * @param aMaxAllowed maximum MBMS monitoring services allowed
       
  3846 * @return KErrNone
       
  3847 */
       
  3848 	{
       
  3849 	LOGPACKET1("CSimPacketService::EnumerateMbmsMonitorServiceList called");
       
  3850 	*aCount = iMbmsMonitorListCount;
       
  3851 	*aMaxAllowed = KMaxMbmsMonitorContexts;
       
  3852 	iEnumerateMonitorListReqHandle = aTsyReqHandle;
       
  3853 	return KErrNone;
       
  3854 	}
       
  3855 
       
  3856 TInt CSimPacketService::EnumerateMbmsMonitorServiceListCancel(const TTsyReqHandle aTsyReqHandle)
       
  3857 /**
       
  3858 * client's interest in canceling the enumeration the MBMS Service Monitoring list.
       
  3859 * This function is just a dummy function.
       
  3860 * 
       
  3861 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3862 * @return KErrNone
       
  3863 */
       
  3864 	{
       
  3865 	if(iEnumerateMonitorListReqHandle == aTsyReqHandle)
       
  3866 		{
       
  3867 		ReqCompleted(iEnumerateMonitorListReqHandle,KErrCancel);
       
  3868 		}
       
  3869 	else
       
  3870 		{
       
  3871 		ReqCompleted(iEnumerateMonitorListReqHandle,KErrCorrupt);
       
  3872 		}
       
  3873 	return KErrNone;
       
  3874 	}
       
  3875 	
       
  3876 TInt CSimPacketService::EnumerateMbmsActiveServiceList(const TTsyReqHandle aTsyReqHandle, TInt* aCount, TInt* aMaxAllowed)
       
  3877 /**
       
  3878 * client's interest in retrieving the information regarding the MBMS Active Service list.
       
  3879 * 
       
  3880 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3881 * @param aCount count of the MBMS active services in the list
       
  3882 * @param aMaxAllowed maximum MBMS active services allowed
       
  3883 * @return KErrNone
       
  3884 */
       
  3885 	{
       
  3886 	LOGPACKET1("CSimPacketService::EnumerateMbmsActiveServiceList called");
       
  3887 	*aCount = iMbmsNifWrappers.Count(); // The NifWrapper contains the list of mbmsContexts that are activated.
       
  3888 	*aMaxAllowed = KMaxMbmsActiveContexts;
       
  3889 	iEnumerateActiveListReqHandle = aTsyReqHandle;
       
  3890 	return KErrNone;
       
  3891 	}
       
  3892 
       
  3893 TInt CSimPacketService::EnumerateMbmsActiveServiceListCancel(const TTsyReqHandle aTsyReqHandle)
       
  3894 /**
       
  3895 * client's interest in canceling the enumeration the MBMS Service active list.
       
  3896 * This function is just a dummy function.
       
  3897 * 
       
  3898 * @param aTsyReqHandle Tsy Request handle for the client cancel request
       
  3899 * @return KErrNone
       
  3900 */
       
  3901 	{
       
  3902 	if(iEnumerateActiveListReqHandle == aTsyReqHandle)
       
  3903 		{
       
  3904 		ReqCompleted(iEnumerateActiveListReqHandle,KErrCancel);
       
  3905 		}
       
  3906 	else
       
  3907 		{
       
  3908 		ReqCompleted(iEnumerateActiveListReqHandle,KErrCorrupt);
       
  3909 		}
       
  3910 	return KErrNone;
       
  3911 	}	
       
  3912 		
       
  3913 /**
       
  3914 * A CSimPacketContext object has been destroyed - this method will be called in its 
       
  3915 * destructor
       
  3916 */
       
  3917 void CSimPacketService::DecrementContextCount()
       
  3918 	{
       
  3919 	iContextCount--;
       
  3920 	}
       
  3921 
       
  3922 /**
       
  3923 * A CSimPacketContext object has been destroyed - this method will be called in its 
       
  3924 * destructor
       
  3925 */
       
  3926 void CSimPacketService::DecrementMbmsContextCount()
       
  3927 	{
       
  3928 	iMbmsContextCount--;
       
  3929 	}
       
  3930 
       
  3931