telephonyserverplugins/multimodetsy/hayes/ATINIT.CPP
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 1997-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 // AT Initialisation
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <commsdattypesv1_1.h>
       
    19 #include <cdblen.h>
       
    20 #include "ATINIT.H"
       
    21 #include "NOTIFY.H"
       
    22 #include "mSLOGGER.H"
       
    23 #include "PHONE.H"
       
    24 #include "CALL.H"
       
    25 #include "ATNOCARR.H"
       
    26 #include "mPHBOOK.H"
       
    27 #include "ATIO.H"
       
    28 #include "Matstd.h"
       
    29 #include "ATHANGUP.H"
       
    30 #include <etelqos.h>
       
    31 
       
    32 _LIT8(KTestPhoneBookStorage,"AT+CPBS=?");
       
    33 _LIT8(KSetExtendedCallIndicationCommand,   "AT+CRC=1\r");
       
    34 _LIT8(KClearUnsolicitedNetworkRegistration, "AT+CREG=0\r");
       
    35 _LIT8(KSetUnsolicitedNetworkRegistration2,  "AT+CREG=2\r");
       
    36 _LIT8(KSetUnsolicitedNetworkRegistration1,  "AT+CREG=1\r");
       
    37 _LIT8(KReadUnsolicitedNetworkRegistration,  "AT+CREG?\r");
       
    38 _LIT8(KGetCurrentOperatorCommand, "AT+COPS?\r");
       
    39 _LIT8(KGetBatteryInfoCommand, "AT+CBC\r");
       
    40 _LIT8(KGetSignalInfoCommand, "AT+CSQ\r");
       
    41 _LIT8(KOperatorResponse,"+COPS:");
       
    42 _LIT8(KGetServiceCentreAddressCommand,"AT+CSCA?\r");
       
    43 
       
    44 _LIT8(KSetUnsolicitedGPRSNetworkRegistration1,  "AT+CGREG=1\r");
       
    45 _LIT8(KSetECAMConfigCommand, "AT*ECAM=1\r");
       
    46 
       
    47 _LIT(KSpaceSeparator," ");
       
    48 
       
    49 _LIT8(KClassA,"A");
       
    50 _LIT8(KClassB,"B");
       
    51 _LIT8(KClassC,"C");
       
    52 _LIT8(KClassCG,"CG");
       
    53 _LIT8(KClassCC,"CC");
       
    54 _LIT16(KEricsson,"*ERICSSON*");
       
    55 
       
    56 const TInt KMaxNoRetries=3;
       
    57 
       
    58 const TUint KZeroChar='0';
       
    59 const TUint KOneChar='1';
       
    60 
       
    61 
       
    62 #ifdef __LOGDEB__
       
    63 _LIT8(KLogEntry,"CATInit::%S\t%S");
       
    64 #define LOCAL_LOGTEXT(function,text) {_LIT8(F,function);_LIT8(T,text);LOGTEXT3(KLogEntry,&F,&T);}
       
    65 #else
       
    66 #define LOCAL_LOGTEXT(function,text)
       
    67 #endif
       
    68 
       
    69 
       
    70 
       
    71 CATInit* CATInit::NewL(CATIO* aIo,CTelObject* aTelObject,CPhoneGlobals* aPhoneGlobals)
       
    72 	{
       
    73 	CATInit* self = new(ELeave) CATInit(aIo,aTelObject,aPhoneGlobals);
       
    74 	CleanupStack::PushL(self);
       
    75 	self->ConstructL();
       
    76 	CleanupStack::Pop();
       
    77 	return self;
       
    78 	}
       
    79 
       
    80 CATInit::CATInit(CATIO* aIo,CTelObject* aTelObject,CPhoneGlobals* aPhoneGlobals)
       
    81 	: CATBase(aIo,aTelObject,aPhoneGlobals)
       
    82 	{}
       
    83 
       
    84 void CATInit::ConstructL()
       
    85 	{
       
    86 	iEnumerate = CATSmsMemoryStorage::NewL(iIo, iTelObject, this, iPhoneGlobals);
       
    87 	}
       
    88 
       
    89 CATInit::~CATInit()
       
    90 	{
       
    91 	iIo->RemoveExpectStrings(this);
       
    92 	delete iEnumerate;
       
    93 	}
       
    94 
       
    95 void CATInit::StartInit(CATCommands* aPendingCommand,TTsyReqHandle aTsyReqHandle, TAny* aParams)
       
    96 	{
       
    97 	SetToNotInitialised();	
       
    98 	iPendingCommand = aPendingCommand;
       
    99 	iReqHandle = aTsyReqHandle;
       
   100 	iParams = aParams;
       
   101 	iCallInfo = aPendingCommand->CallInfo();	// iCallInfo is NULL if 
       
   102 												// aPendingCommand has no iCallInfo
       
   103 	iIo->Cancel();
       
   104 	iAttemptCnt=1;
       
   105 	InitAttempt();
       
   106 	}
       
   107 
       
   108 TBool CATInit::CheckActiveReqHandle(const TTsyReqHandle aTsyReqHandle)
       
   109 //
       
   110 // Check the Request against the current request handle
       
   111 //
       
   112 	{
       
   113 	if((iPhoneGlobals->iPhoneStatus.iInitStatus==EPhoneInitialising)&&
       
   114 	   (aTsyReqHandle==iReqHandle))
       
   115 		return ETrue;
       
   116 	else
       
   117 		return EFalse;
       
   118 	}
       
   119 
       
   120 void CATInit::StopInit(TTsyReqHandle aTsyReqHandle)
       
   121 	{
       
   122 	__ASSERT_ALWAYS(aTsyReqHandle == iReqHandle,Panic(EIllegalTsyReqHandle));
       
   123 	LOGTEXT(_L8("Cancelling Initialisation"));
       
   124 	iPhoneGlobals->iPhoneStatus.iInitStatus = EPhoneInitialiseCancelling;
       
   125 	iIo->SetTimeOut(this,KOneSecondPause);
       
   126 	}
       
   127 
       
   128 void CATInit::SpecialStart(TTsyReqHandle aTsyReqHandle)
       
   129 //
       
   130 //	If aTsyReqHandle is NULL, this is an Automatic Init with no ReqComplete to call
       
   131 //	Otherwise it is from CPhoneHayes::ControlledInitialise() which should be completed
       
   132 //
       
   133 	{
       
   134 	iReqHandle = aTsyReqHandle;
       
   135 	iPendingCommand = NULL;
       
   136 	iAttemptCnt=1;
       
   137 	InitAttempt();
       
   138 	}
       
   139 
       
   140 void CATInit::InitAttempt()
       
   141 	{
       
   142 	if (iPhoneGlobals->iPhoneStatus.iInitStatus == EPhoneInitialiseCancelling)
       
   143 		return;	// "initialise" may have been cancelled while we were waiting for the call back.
       
   144 
       
   145 	LOGTEXT2(_L8("Starting Initialisation Sequence, Attempt %d"),iAttemptCnt);
       
   146 	iPhoneGlobals->iPhoneStatus.iInitStatus = EPhoneInitialising;
       
   147 	iPhoneGlobals->iSmsPduModeSupported=EFalse;
       
   148 	TCommConfig aConfigPckg;
       
   149 	iIo->Cancel();
       
   150 	TInt ret = iPhoneGlobals->iConfiguration->PortConfig(aConfigPckg,EConfigTypePreInit);
       
   151 	if (ret==KErrNone)
       
   152 		ret = iIo->ConfigurePort(aConfigPckg);
       
   153 	if (ret)
       
   154 		{
       
   155 		Complete(ret);
       
   156 		return;
       
   157 		}
       
   158 	iIo->SetTimeOut(this,100);
       
   159 	iState=EShortTimeOutFix;
       
   160 	}
       
   161 	
       
   162 void CATInit::RetryOrFail(TBool aCommsErrorOccurred)
       
   163 	{
       
   164 	if (!aCommsErrorOccurred)
       
   165 		iIo->RemoveExpectStrings(this);	
       
   166 	iConnectExpectString = NULL;
       
   167 	iNoCarrierExpectString = NULL;
       
   168 	iOKExpectString = NULL;
       
   169 	iErrorExpectString = NULL;
       
   170 	if(++iAttemptCnt > (TUint)KMaxNoRetries)
       
   171 		{
       
   172 		LOGTEXT(_L8("Cannot Initialise"));
       
   173 		iIo->RemoveExpectStrings(this);
       
   174 		if (iPhoneGlobals->iPhoneStatus.iModemDetected != RPhone::EDetectedPresent)
       
   175 			Complete(KErrEtelModemNotDetected);
       
   176 		else
       
   177 			Complete(KErrEtelInitialisationFailure);
       
   178 		}
       
   179 	else
       
   180 		{
       
   181 		iIo->Cancel();
       
   182 		InitAttempt();
       
   183 		}	
       
   184 	}
       
   185 
       
   186 void CATInit::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
       
   187 //
       
   188 //	CATIO removes expect strings in the event of an error from the port, so set ptrs to NULL.
       
   189 //	If error is KErrCommsFrame and this is the first attempt at initialising, give the modem
       
   190 //	benefit of the doubt and try again.
       
   191 //
       
   192 	{
       
   193 	if (aStatus==KErrCommsFrame && iAttemptCnt==1)
       
   194 		RetryOrFail(ETrue);
       
   195 	else
       
   196 		{
       
   197 		iNoCarrierExpectString = NULL;
       
   198 		iConnectExpectString = NULL;
       
   199 		iOKExpectString = NULL;
       
   200 		iErrorExpectString = NULL;
       
   201 		Complete(aStatus);
       
   202 		}
       
   203 	}
       
   204 
       
   205 void CATInit::ValidateATHExpectStringL()
       
   206 	{
       
   207 	if(iIo->FoundChatString()==iErrorExpectString)
       
   208 		{
       
   209 		LOGTEXT(_L8("Modem returned ERROR in response to command"));
       
   210 		User::Leave(KErrGeneral);
       
   211 		}
       
   212 	if(iIo->FoundChatString()==iNoCarrierExpectString)
       
   213 		{
       
   214 		LOGTEXT(_L8("Modem returned NO CARRIER in response to command"));
       
   215 		return;
       
   216 		}
       
   217 	if(iIo->FoundChatString()==iOKExpectString)
       
   218 		return;
       
   219 	LOGTEXT(_L8("Modem returned unexpected response to command"));
       
   220 	User::Leave(KErrUnknown);
       
   221 	}
       
   222 
       
   223 void CATInit::EventSignal(TEventSource aSource)
       
   224 	{
       
   225 	if(aSource==ETimeOutCompletion && iState==EWaitForDSR)
       
   226 		{
       
   227 		LOGTEXT(_L8("CATInit::EventSignal  Ignoring timeout during EWaitForDSR"));
       
   228 		iIo->WriteAndTimerCancel(this);
       
   229  		iIo->RemoveExpectStrings(this);
       
   230 		}
       
   231 	else if ((aSource==ETimeOutCompletion)
       
   232 	  &&(iPhoneGlobals->iPhoneStatus.iInitStatus != EPhoneInitialiseCancelling)
       
   233 	  &&(iState!=EATWaitForATCheckOK)&&(iState!=EShortTimeOutFix))
       
   234 		{
       
   235 		LOGTEXT(_L8("CATInit::EventSignal  Error during Initialisation Sequence"));
       
   236 		RetryOrFail();
       
   237 		return;
       
   238 		}
       
   239 	
       
   240 	if (iPhoneGlobals->iPhoneStatus.iInitStatus == EPhoneInitialiseCancelling)
       
   241 		{
       
   242 		if (aSource==EWriteCompletion)
       
   243 			{
       
   244 			iIo->SetTimeOut(this,KOneSecondPause);
       
   245 			}
       
   246 		if (aSource==EReadCompletion || aSource==ETimeOutCompletion)
       
   247 			{
       
   248 			LOGTEXT2(_L8("Entered InitCancelling with aSource=%d"),aSource);
       
   249 			iIo->WriteAndTimerCancel(this);
       
   250 			iIo->RemoveExpectStrings(this);
       
   251 			iOKExpectString=NULL;
       
   252 			iErrorExpectString=NULL;
       
   253 			iPhoneGlobals->iPhoneStatus.iInitStatus = EPhoneNotInitialised;
       
   254 			if (iPendingCommand)
       
   255 				{
       
   256 				if (iCallInfo)
       
   257 					REINTERPRET_CAST(CCallHayes*,iPendingCommand->Owner())->SetToIdle();
       
   258 				iPendingCommand->Owner()->ReqCompleted(iReqHandle,KErrCancel);
       
   259 				iPendingCommand=NULL;
       
   260 				}
       
   261 			else
       
   262 				{
       
   263 				iTelObject->ReqCompleted(iReqHandle,KErrCancel);
       
   264 				return;
       
   265 				}
       
   266 			if ((iCallInfo != NULL) && (iCallInfo->iClientPanicOccurred!=ENoPanicOccurred))
       
   267 				{
       
   268 				__ASSERT_DEBUG(iPendingCommand!=NULL,Panic(ERelinquishOwnershipWithNoCall));
       
   269 				iComplete = CCompleteRelinquish::New(iPendingCommand->Owner());
       
   270 				iComplete->SetWhichCompletion(iCallInfo->iClientPanicOccurred);
       
   271 				iComplete->Call();	// calls the AysncOneShot Relinquish completion function
       
   272 				iCallInfo->iClientPanicOccurred = ENoPanicOccurred;
       
   273 				}	
       
   274 			}
       
   275 		return;
       
   276 		}
       
   277 
       
   278 	switch(iState)
       
   279 		{
       
   280 	case EShortTimeOutFix:
       
   281 		//
       
   282 		//	Calling iIo->Start() synchronously inside the InitAttempt() function caused a 
       
   283 		//  hang when using IrDA on the ARM, and Netdial, as Netdial is in the ESock thread
       
   284 		//  and is blocking waiting for its RTelSubSession::Open() to complete, but iIo->Start()
       
   285 		//	calls C32 which calls ESock. So introduced this short time out.
       
   286 		//
       
   287 		//	Also retrieving the strings here at the start of the initialisation - the first
       
   288 		//	time we get back KErrAccessDenied for some reason.
       
   289 		//
       
   290 		{
       
   291 		iIo->Cancel();
       
   292 		iIo->Start(this);		// ramps up DTR
       
   293 		iIo->SetTimeOut(this,5 * KOneSecondPause);	// should be enough time for a battery-powered
       
   294 													// modem to initialise itself
       
   295 		__ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral));
       
   296 		iState=EWaitForDSR;
       
   297 		}
       
   298 		break;
       
   299 		
       
   300 	case EWaitForDSR:
       
   301  		// Do not assert aSource==EWriteCompletion as we could have got here with a ETimeOutCompletion
       
   302 		{
       
   303 		if (!(iIo->ReadPending()))		// Otherwise CATIO will queue a read on the way back down the stack anyway
       
   304 			iIo->Read();
       
   305 		Write(KAT2Command(),5);		// needs to be long because IR takes a while 
       
   306 		iState=EWaitForATHangUpWriteComplete;
       
   307 		}
       
   308 		break; //ATHcommand is now an AT. Introduced 23/03/99: Fix ER5-defect EDNJWAD-465K6M
       
   309 
       
   310 	case EWaitForATHangUpWriteComplete:
       
   311 		StandardWriteCompletionHandler(aSource,5);
       
   312 		if (!iNoCarrierExpectString)
       
   313 			iNoCarrierExpectString = iIo->AddExpectString(this,KNoCarrierString);
       
   314 		iState=EWaitForATHangUpOK;
       
   315 		break;
       
   316 
       
   317 	case EWaitForATHangUpOK:
       
   318 		{
       
   319 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   320 
       
   321 		// Fix defect CLE-4RGN8Z, NM, 9/01/01.
       
   322 		// Fix defect SIH-4UCMW9, that actually fixes the problem caused by
       
   323 		// previous CLE-4RGN8Z fix !  KAS 2/03/01 
       
   324 		if (iPhoneGlobals->iPhoneStatus.iModemDetected != RPhone::EDetectedPresent) 
       
   325 			{
       
   326 			iPhoneGlobals->iNotificationStore->CheckNotification(iTelObject,EPhoneDetected);
       
   327 			iPhoneGlobals->iPhoneStatus.iModemDetected = RPhone::EDetectedPresent;
       
   328 			}
       
   329 
       
   330 		TRAPD(ret,ValidateATHExpectStringL());
       
   331 		if (ret)
       
   332 			{
       
   333 			RetryOrFail();
       
   334 			break;
       
   335 			}
       
   336 		iIo->WriteAndTimerCancel(this);
       
   337 		RemoveStdExpectStrings();
       
   338 		iIo->RemoveExpectString(iConnectExpectString);
       
   339 		iConnectExpectString = NULL;
       
   340 		iIo->RemoveExpectString(iNoCarrierExpectString);
       
   341 		iNoCarrierExpectString=NULL;
       
   342 		TCommConfig aConfigPckg;
       
   343 		iIo->Cancel();
       
   344 		ret = iPhoneGlobals->iConfiguration->PortConfig(aConfigPckg,EConfigTypeInit);
       
   345 		if (ret==KErrNone)
       
   346 			ret = iIo->ConfigurePort(aConfigPckg);
       
   347 		if (ret)
       
   348 			{
       
   349 			Complete(ret);
       
   350 			return;
       
   351 			}
       
   352 
       
   353 		//
       
   354 		// iCallInfo is NULL if this hasn't been originated by a CCallHayes command,
       
   355 		// eg using CPhoneHayes::Init()
       
   356 		//
       
   357 		// Don't bother notifying about hook change here as it's likely only to be from 
       
   358 		// unknown to on.
       
   359 		//
       
   360 		iPhoneGlobals->iNotificationStore->CheckNotification(iTelObject,EBecomeIdle);
       
   361 		REINTERPRET_CAST(CPhoneHayes*,iTelObject)->SetHookStatus(RCall::EHookStatusOn);
       
   362 		iPhoneGlobals->iPhoneStatus.iMode = RPhone::EModeIdle;
       
   363 		TBuf8<KMaxLengthOfUserDefinedInitString> initCommand;
       
   364 			initCommand=KAT2Command;			
       
   365 		Write(initCommand,5);
       
   366 		iState=EWaitForModemInitWrite;
       
   367 		}
       
   368 		break;
       
   369 
       
   370 	case EWaitForModemInitWrite:
       
   371 		StandardWriteCompletionHandler(aSource,5);
       
   372 		iState=EWaitForModemInitOK;
       
   373 		break;
       
   374 
       
   375 	case EWaitForModemInitOK:
       
   376 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   377 			{
       
   378 			TInt ret(ValidateExpectString());
       
   379 			if (ret)
       
   380 				{
       
   381 				RetryOrFail();
       
   382 				break;
       
   383 				}
       
   384 			RemoveStdExpectStrings();
       
   385 			iIo->WriteAndTimerCancel(this);	
       
   386 			TPtrC8 atCheck(KAT2Command);		// modem may take time to complete user-defined
       
   387 											// Init string, so send an AT once and if this
       
   388 											// fails try again twice
       
   389 			Write(atCheck,5);
       
   390 			iState=EWaitForATCheckWrite;
       
   391 			}
       
   392 		break;
       
   393 
       
   394 	case EWaitForATCheckWrite:
       
   395 		StandardWriteCompletionHandler(aSource,5);
       
   396 		iState=EATWaitForATCheckOK;
       
   397 		break;
       
   398 
       
   399 	case EATWaitForATCheckOK:
       
   400 		{
       
   401 		if (aSource==ETimeOutCompletion)
       
   402 			{
       
   403 			RemoveStdExpectStrings();
       
   404 			if (iRetryCounter++ == (TUint)KMaxNoChecks)
       
   405 				{
       
   406 				iRetryCounter=0;
       
   407 				Complete(KErrTimedOut);
       
   408 				}
       
   409 			else
       
   410 				{
       
   411 				TPtrC8 atCheck(KAT2Command);
       
   412 				Write(atCheck,5);
       
   413 				iState=EWaitForATCheckWrite;
       
   414 				}
       
   415 			return;
       
   416 			}
       
   417 		TInt ret(ValidateExpectString());
       
   418 		if (ret)
       
   419 			{
       
   420 			RetryOrFail();
       
   421 			break;
       
   422 			}
       
   423 		RemoveStdExpectStrings();
       
   424 		WriteExpectingResults(KGetPhoneCapsCommand(),5);
       
   425 		iState=EWaitForATGetPhoneCapsWrite;
       
   426 		}
       
   427 		break;
       
   428 
       
   429 	case EWaitForATGetPhoneCapsWrite:
       
   430 		StandardWriteCompletionHandler(aSource,5);
       
   431 		iState=EWaitForATGetPhoneCapsOK;
       
   432 		break;
       
   433 
       
   434 	case EWaitForATGetPhoneCapsOK:
       
   435 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   436 			{
       
   437 			TInt ret(ValidateExpectString());
       
   438 			if(ret==KErrGeneral)
       
   439 				ParseAnErroredPhoneCaps();
       
   440 			else if(ret!=KErrNone)
       
   441 				{	
       
   442 				RetryOrFail();
       
   443 				break;
       
   444 				}
       
   445 			else
       
   446 				{
       
   447 				iIo->WriteAndTimerCancel(this);
       
   448 				TRAP(ret,ParsePhoneCapsL());
       
   449 				if (ret)
       
   450 					{	
       
   451 					iIo->RemoveExpectStrings(this);
       
   452 					Complete(KErrEtelInitialisationFailure);
       
   453 					break;
       
   454 					}
       
   455 				}
       
   456 			RemoveStdExpectStrings();
       
   457 			TBuf8<KCommsDbSvrMaxFieldLength> echoSetting;
       
   458 			TBuf8<KCommsDbSvrMaxFieldLength> quietSetting;
       
   459 			TBuf8<KCommsDbSvrMaxFieldLength> verboseSetting;
       
   460 			ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameEchoOff),echoSetting);
       
   461 			if (ret==KErrNone)
       
   462 				{
       
   463 				ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameQuietOff),quietSetting);
       
   464 				}
       
   465 			if (ret==KErrNone)
       
   466 				{
       
   467 				ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameVerboseText),verboseSetting);
       
   468 				}
       
   469 			if (ret)
       
   470 				{
       
   471 				iIo->RemoveExpectStrings(this);
       
   472 				Complete(ret);
       
   473 				break;
       
   474 				}
       
   475 			iTxBuffer.Format(_L8("AT%S%S%S\r"),&echoSetting, &quietSetting, &verboseSetting);
       
   476 			iIo->Write(this,iTxBuffer);
       
   477 			iIo->SetTimeOut(this,5*KOneSecondPause);
       
   478 			iState=EWaitForATStandardInitWrite;
       
   479 			}
       
   480 		break;
       
   481 
       
   482 	case EWaitForATStandardInitWrite:
       
   483 		StandardWriteCompletionHandler(aSource,5);
       
   484 		iState=EWaitForATStandardInitOK;
       
   485 		break;
       
   486 
       
   487 	case EWaitForATStandardInitOK:
       
   488 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   489 			{
       
   490 			TInt ret(ValidateExpectString());
       
   491 			if (ret)
       
   492 				{
       
   493 				RetryOrFail();
       
   494 				break;
       
   495 				}
       
   496 			iIo->WriteAndTimerCancel(this);
       
   497 			RemoveStdExpectStrings();
       
   498 			TPtrC8 interrogateWaitTime(KSmsSetTABufferMode);
       
   499 			WriteExpectingResults(interrogateWaitTime,5);
       
   500 			iState=EWaitForATUnsolicitedFixWrite;
       
   501 			}
       
   502 		break;
       
   503 
       
   504 	case EWaitForATUnsolicitedFixWrite:
       
   505 		StandardWriteCompletionHandler(aSource,5);
       
   506 		iState=EWaitForATUnsolicitedFixOK;
       
   507 		break;
       
   508 
       
   509 	case EWaitForATUnsolicitedFixOK:
       
   510 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   511 			{
       
   512 			// Ensures that unsolicited messages are buffered by the TA during initialisation
       
   513 			// We dont care what this returns becasue if AT+CNMI= fails, it is unlikely
       
   514 			// that SMS's can received at all.
       
   515 			iIo->WriteAndTimerCancel(this);
       
   516 			RemoveStdExpectStrings();
       
   517 			TPtrC8 interrogateWaitTime(KGetCarrierWaitTimeCommand);
       
   518 			WriteExpectingResults(interrogateWaitTime,5);
       
   519 			iState=EWaitForATCarrierWaitTimeWrite;
       
   520 			}
       
   521 		break;
       
   522 
       
   523 	case EWaitForATCarrierWaitTimeWrite:
       
   524 		StandardWriteCompletionHandler(aSource,5);
       
   525 		iState=EWaitForATCarrierWaitTimeOK;
       
   526 		break;
       
   527 
       
   528 	case EWaitForATCarrierWaitTimeOK:
       
   529 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   530 		//
       
   531 		//	if modem does not support ATS7 (carrier wait time) set it to default value
       
   532 		//
       
   533 			{
       
   534 			TInt ret(ValidateExpectString());
       
   535 			if (ret==KErrNone)
       
   536 				TRAP(ret,ParseWaitTimeL());
       
   537 			if (ret)
       
   538 				iPhoneGlobals->iPhoneStatus.iWaitForCarrierTime = KDefaultSecondsToWaitForCarrier;
       
   539 			iIo->WriteAndTimerCancel(this);	
       
   540 			RemoveStdExpectStrings();
       
   541 			Write(KAutoAnswerCommand(),5,KDefaultAutoAnswer);
       
   542 			iState=EWaitForATAutoAnswerTimeWrite;
       
   543 			}
       
   544 		break;
       
   545 
       
   546 	case EWaitForATAutoAnswerTimeWrite:
       
   547 		StandardWriteCompletionHandler(aSource,5);
       
   548 		iState=EWaitForATAutoAnswerTimeOK;
       
   549 		break;
       
   550 
       
   551 	case EWaitForATAutoAnswerTimeOK:
       
   552 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   553 			{
       
   554 			iIo->WriteAndTimerCancel(this);	
       
   555 			RemoveStdExpectStrings();
       
   556 			//
       
   557 			//
       
   558 			//All the MM initialization stuff starts now//
       
   559 			//
       
   560 			// 
       
   561 			iPhoneGlobals->iPhoneTestState = CPhoneGlobals::EPhoneTestUndefined; //New-ETSI-Phone or Old-ETSI-Phone? 
       
   562 
       
   563 			iTxBuffer.Copy(KGetManufacturerIDCommand);
       
   564 			iIo->Write(this, iTxBuffer);
       
   565 			iIo->SetTimeOut(this, 5000);
       
   566 			iState = EATWaitForSendingCGMIRequest;
       
   567 			}
       
   568 		break;	
       
   569 
       
   570 	case EATWaitForSendingCGMIRequest:
       
   571 		iIo->WriteAndTimerCancel(this);
       
   572 		StandardWriteCompletionHandler(aSource,5);
       
   573 		iState = EATWaitForSendingCGMIRequestComplete;
       
   574 		break;
       
   575 
       
   576 	case EATWaitForSendingCGMIRequestComplete:
       
   577 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   578 			{
       
   579 			iIo->WriteAndTimerCancel(this);
       
   580 			TInt ret(ValidateExpectString());
       
   581 			RemoveStdExpectStrings();
       
   582 			if (ret == KErrNone)
       
   583 				{
       
   584 				iCGMIFlag = ETrue;
       
   585 				__ASSERT_ALWAYS(GetIdentityResponse() == KErrNone,Panic(EGeneral));
       
   586 				iCGMIFlag = EFalse;
       
   587 				iPhoneGlobals->iPhoneIdCaps |= RMobilePhone::KCapsGetManufacturer;
       
   588 				}
       
   589 			else
       
   590 				{
       
   591 				LOGTEXT(_L8("MMTsy:\tCATInit:\tCGMI query returned ERROR. Setting NULL TBuf8"));
       
   592 				iPhoneGlobals->iPhoneId.iManufacturer.Zero();
       
   593 				}
       
   594 			iTxBuffer.Copy(KGetModelIDCommand);
       
   595 			iIo->Write(this, iTxBuffer);
       
   596 			iIo->SetTimeOut(this, 5000);
       
   597 			iState = EATWaitForSendingCGMMRequest;
       
   598 			}
       
   599 		break;
       
   600 		
       
   601 	case EATWaitForSendingCGMMRequest:
       
   602 		iIo->WriteAndTimerCancel(this);
       
   603 		StandardWriteCompletionHandler(aSource,5);
       
   604 		iState = EATWaitForSendingCGMMRequestComplete;
       
   605 		break;
       
   606 	
       
   607 	case EATWaitForSendingCGMMRequestComplete:
       
   608 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   609 			{
       
   610 			iIo->WriteAndTimerCancel(this);
       
   611 			TInt ret(ValidateExpectString());
       
   612 			RemoveStdExpectStrings();
       
   613 			if (ret == KErrNone)
       
   614 				{
       
   615 				iCGMMFlag = ETrue;
       
   616 				LOGTEXT(_L8("MMTsy:\tEntering CGMMResponse TRAPD' function"));
       
   617 				__ASSERT_ALWAYS(GetIdentityResponse() == KErrNone,Panic(EGeneral));
       
   618 				iCGMMFlag = EFalse;
       
   619 				iPhoneGlobals->iPhoneIdCaps |= RMobilePhone::KCapsGetModel;
       
   620 				}
       
   621 			else
       
   622 				{
       
   623 				LOGTEXT(_L8("MMTsy:\tCATInit:\tCGMM query returned ERROR. Setting NULL TBuf8"));
       
   624 				iPhoneGlobals->iPhoneId.iModel.Zero();
       
   625 				}
       
   626 			iTxBuffer.Copy(KGetRevisionIDCommand);
       
   627 			iIo->SetTimeOut(this, 5000);
       
   628 			iIo->Write(this, iTxBuffer);
       
   629 			iState = EATWaitForSendingCGMRRequest;
       
   630 			}
       
   631 		break;
       
   632 
       
   633 	case EATWaitForSendingCGMRRequest:
       
   634 		__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
       
   635 			{
       
   636 			iIo->WriteAndTimerCancel(this);
       
   637 			StandardWriteCompletionHandler(aSource, 5);
       
   638 			iState = EATWaitForSendingCGMRRequestComplete;
       
   639 			}
       
   640 		break;
       
   641 
       
   642 	case EATWaitForSendingCGMRRequestComplete:
       
   643 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   644 			{
       
   645 			iIo->WriteAndTimerCancel(this);
       
   646 			TInt ret(ValidateExpectString());
       
   647 			RemoveStdExpectStrings();
       
   648 			if (ret == KErrNone)
       
   649 				{
       
   650 				iCGMRFlag = ETrue;
       
   651 				__ASSERT_ALWAYS(GetIdentityResponse() == KErrNone,Panic(EGeneral));
       
   652 				iCGMRFlag = EFalse;
       
   653 				iPhoneGlobals->iPhoneIdCaps |= RMobilePhone::KCapsGetRevision;
       
   654 				}
       
   655 			else
       
   656 				{
       
   657 				LOGTEXT(_L8("MMTsy:\tCATInit:\tCGMR query returned ERROR. Setting NULL TBuf8"));
       
   658 				iPhoneGlobals->iPhoneId.iRevision.Zero();
       
   659 				}
       
   660 			iTxBuffer.Copy(KGetSerialNumberIDCommand);
       
   661 			iIo->Write(this, iTxBuffer);
       
   662 			iIo->SetTimeOut(this, 5000);
       
   663 			iState = EATWaitForSendingCGSNRequest;
       
   664 			}
       
   665 		break;
       
   666 
       
   667 
       
   668 	case EATWaitForSendingCGSNRequest:
       
   669 		__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
       
   670 			{
       
   671 			iIo->WriteAndTimerCancel(this);
       
   672 			StandardWriteCompletionHandler(aSource, 5);
       
   673 			iState = EATWaitForSendingCGSNRequestComplete;
       
   674 			}
       
   675 		break;
       
   676 
       
   677 	case EATWaitForSendingCGSNRequestComplete:
       
   678 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   679 			{
       
   680 			iIo->WriteAndTimerCancel(this);
       
   681 			TInt ret(ValidateExpectString());
       
   682 			RemoveStdExpectStrings();
       
   683 			if (ret == KErrNone)
       
   684 				{
       
   685 				iCGSNFlag = ETrue;
       
   686 				__ASSERT_ALWAYS(GetIdentityResponse() == KErrNone,Panic(EGeneral));
       
   687 				iCGSNFlag = EFalse;
       
   688 				iPhoneGlobals->iPhoneIdCaps |= RMobilePhone::KCapsGetSerialNumber;
       
   689 				}
       
   690 			else
       
   691 				{
       
   692 				LOGTEXT(_L8("MMTsy:\tCATInit:\tCGSN query returned ERROR. Setting NULL TBuf8"));
       
   693 				iPhoneGlobals->iPhoneId.iSerialNumber.Zero();
       
   694 				}
       
   695 
       
   696 			LOGTEXT(_L8("MMTsy:\tGrabbing the subscriber id capabilities"));
       
   697 			WriteExpectingResults(KGetSubscrieberIDCommand(), 5); 
       
   698 			iState=EATGetSubscriberIdWriteComplete;
       
   699 			}
       
   700 		break;
       
   701 
       
   702 	case EATGetSubscriberIdWriteComplete:
       
   703 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
   704 			{
       
   705 			iIo->WriteAndTimerCancel(this);
       
   706 			StandardWriteCompletionHandler(aSource, 5);
       
   707 			iState=EATGetSubscriberIdReadComplete;
       
   708 			}
       
   709 			break;
       
   710                 
       
   711 	case EATGetSubscriberIdReadComplete:
       
   712 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   713 			{
       
   714 			iIo->WriteAndTimerCancel(this);
       
   715 			TInt ret(ValidateExpectString());
       
   716 			RemoveStdExpectStrings();
       
   717 			if (ret != KErrNone)
       
   718 				{
       
   719 				LOGTEXT(_L8("MMTsy:\tCATInit:\t+CIMI not supported"));
       
   720 				}
       
   721 			else
       
   722 				{
       
   723 				LOGTEXT(_L8("MMTsy:\tCATInit:\t+CIMI supported"));
       
   724 				iPhoneGlobals->iPhoneIdCaps |= RMobilePhone::KCapsGetSubscriberId;
       
   725 				}
       
   726 
       
   727 			LOGTEXT(_L8("MMTsy:\tGrabbing the SMS <mode> capabilities"));
       
   728 			WriteExpectingResults(KSmsGetModeCommand(), 5); 
       
   729 			iState=EATWaitForSendingCMGFRequestWrite;
       
   730 
       
   731 			}
       
   732 			break;		
       
   733 
       
   734 	case EATWaitForSendingCMGFRequestWrite:
       
   735 		StandardWriteCompletionHandler(aSource,5);
       
   736 		iState=EATWaitForSendingCMGFRequestComplete;
       
   737 		break;
       
   738 
       
   739 	case EATWaitForSendingCMGFRequestComplete:
       
   740 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   741 			{
       
   742 			iIo->WriteAndTimerCancel(this);	
       
   743 			TInt ret(ValidateExpectString());
       
   744 			RemoveStdExpectStrings();
       
   745 			iPhoneGlobals->iSmsPduModeSupported=EFalse;
       
   746 			if(ret==KErrNone)
       
   747 				{
       
   748 				TRAP(ret,CheckCMGFResponseL());
       
   749 				}
       
   750 			if((ret==KErrNone)&&(iPhoneGlobals->iSmsPduModeSupported))
       
   751 				{
       
   752 				LOGTEXT(_L8("MMTsy:\tPdu mode is supported by ME. Enabling this as the default mode."));
       
   753 				WriteExpectingResults(KSetSmsModeSupportCommand, 5);
       
   754 				iState = EATWaitForSendingCMGFConfigureWrite;
       
   755 				}
       
   756 			else
       
   757 				{
       
   758 				LOGTEXT(_L8("MMTsy:\tPdu mode not supported by ME. Sending a dummy \"AT\" instead."));
       
   759 				WriteExpectingResults(KATCommand, 5);
       
   760 				iState = EATWaitForSendingCMGFConfigureWrite;
       
   761 				}
       
   762 			} //case
       
   763 		break;
       
   764 	
       
   765 	case EATWaitForSendingCMGFConfigureWrite:
       
   766 		StandardWriteCompletionHandler(aSource,5);
       
   767 		iState=EATWaitForCMGFResponseOKComplete;
       
   768 		break;
       
   769 
       
   770 	case EATWaitForCMGFResponseOKComplete:
       
   771 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   772 			{
       
   773 			iIo->WriteAndTimerCancel(this);
       
   774 			TInt ret(ValidateExpectString());
       
   775 			if (ret)
       
   776 				{
       
   777 				RetryOrFail();
       
   778 				break;
       
   779 				}
       
   780 			RemoveStdExpectStrings();
       
   781 		
       
   782 		// CMGF is taken care of... mode capabilites assessed, and Pdu mode (for now) has been assigned to ME. (Mobile Equipment)
       
   783 			iTxBuffer.Copy(KGetPrefMemCommand);	// Preferred Memory Storage cmd. ETSI std GSM 07.05, May 1996
       
   784 			iIo->Write(this, iTxBuffer);
       
   785 			iIo->SetTimeOut(this, 5000);
       
   786 			iState = EATWaitForSendingEnumRequest;
       
   787 			} //case
       
   788 		break;
       
   789 
       
   790 	case EATWaitForSendingEnumRequest:
       
   791 		__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
       
   792 		{
       
   793 		iIo->WriteAndTimerCancel(this);
       
   794 		StandardWriteCompletionHandler(aSource, 5);
       
   795 		iState = EATWaitForSendingEnumRequestComplete;
       
   796 		}
       
   797 		break;
       
   798 
       
   799 	case EATWaitForSendingEnumRequestComplete:
       
   800 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   801 		{
       
   802 		iIo->WriteAndTimerCancel(this);
       
   803 		TInt ret(ValidateExpectString());
       
   804 		if (ret!=KErrNone)
       
   805 			{
       
   806 			LOGTEXT(_L8("MMTsy:\tCATInit:\tAT+CPMS=? command not supported by this phone"));
       
   807 			LOGTEXT(_L8("MMTsy:\tCATInit:\tThis situation should NOT occur for a MM(GSM) phone as this command is mandatory!"));
       
   808 			}
       
   809 		else
       
   810 			{
       
   811 			TRAPD(ret, iEnumerate->EnumerateCPMSResponseL());
       
   812 			if (ret != KErrNone)
       
   813 				{
       
   814 				LOGTEXT(_L8("MMTsy:\tCATInit:\tError Enumerating Message Stores"));
       
   815 				RetryOrFail();
       
   816 				break;
       
   817 				}
       
   818 			}
       
   819 		RemoveStdExpectStrings();
       
   820 
       
   821 		iTxBuffer.Copy(KGetPrefMemTestCommand);
       
   822 		iIo->Write(this, iTxBuffer);
       
   823 		iIo->SetTimeOut(this, 5000);
       
   824 		iState = EATWaitForGetPrefMemWriteComplete;				
       
   825 		}
       
   826 		break;
       
   827 
       
   828 	case EATWaitForGetPrefMemWriteComplete:
       
   829 		StandardWriteCompletionHandler(aSource, 5);
       
   830 		iState=EATWaitForGetPrefMemReadComplete;
       
   831 		break;
       
   832 
       
   833 	case EATWaitForGetPrefMemReadComplete:
       
   834 		__ASSERT_ALWAYS(aSource==EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   835 		{
       
   836 		iIo->WriteAndTimerCancel(this);
       
   837 		TInt ret(ValidateExpectString());
       
   838 		if (ret!=KErrNone)
       
   839 			{
       
   840 			LOGTEXT(_L8("MMTsy:\tCATInit:\tAT+CPMS? command not supported by this phone"));
       
   841 			LOGTEXT(_L8("MMTsy:\tCATInit:\tThis situation should NOT occur for a MM/(GSM) phone as this command is mandatory!"));
       
   842 			}
       
   843 		else
       
   844 			{
       
   845 			TRAPD(ret, iEnumerate->GetPrefMemL());
       
   846 			if (ret != KErrNone)
       
   847 				{
       
   848 				LOGTEXT(_L8("MMTsy:\tCATInit:\tError Determining Pref'd Memory"));
       
   849 				RetryOrFail();
       
   850 				break;
       
   851 				}
       
   852 			}
       
   853 		RemoveStdExpectStrings();
       
   854 
       
   855 		Write(KTestPhoneBookStorage(), 5);
       
   856 		iState=EATWaitForTestPhoneBookStorageWriteComplete;
       
   857 		}
       
   858 		break;
       
   859 
       
   860 	case EATWaitForTestPhoneBookStorageWriteComplete:
       
   861 		StandardWriteCompletionHandler(aSource,5);
       
   862 		iState=EATWaitForTestPhoneBookStorageRequestComplete;
       
   863 		break;
       
   864 
       
   865 	case EATWaitForTestPhoneBookStorageRequestComplete:
       
   866 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   867 			{
       
   868 			iIo->WriteAndTimerCancel(this);
       
   869 			TInt ret(ValidateExpectString());
       
   870 			if (ret!=KErrNone)
       
   871 				LOGTEXT(_L8("CATInit:\tAT+CPBS command not supported by this phone. Skipping to Network Registration"));
       
   872 			else
       
   873 				{
       
   874 				TRAP(ret,ParsePhoneBookStorageL());
       
   875 				if (ret!=KErrNone)
       
   876 					{
       
   877 					RetryOrFail();
       
   878 					break;
       
   879 					}
       
   880 				}
       
   881 			RemoveStdExpectStrings();
       
   882 
       
   883 			// Start waiting for asynchronous notification
       
   884 			// Some notifications may be ignored until the phone is fully initialized.
       
   885 			STATIC_CAST(CPhoneHayes*,iTelObject)->StartWaitForRing(); 
       
   886 
       
   887 			iTxBuffer.Copy(KClearUnsolicitedNetworkRegistration);
       
   888 			iIo->Write(this, iTxBuffer);
       
   889 			iIo->SetTimeOut(this, 5000);
       
   890 			iState = EATWaitForClearUnsolicitedNetworkRegistrationWrite;
       
   891 			}
       
   892 		break;
       
   893 
       
   894 
       
   895 	case EATWaitForClearUnsolicitedNetworkRegistrationWrite:
       
   896 		__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
       
   897 			{
       
   898 			iIo->WriteAndTimerCancel(this);
       
   899 			StandardWriteCompletionHandler(aSource, 5);
       
   900 			iState = EATWaitForClearUnsolicitedNetworkRegistrationOK;
       
   901 			}
       
   902 		break;
       
   903 
       
   904 	case EATWaitForClearUnsolicitedNetworkRegistrationOK:
       
   905 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   906 			{
       
   907 			iIo->WriteAndTimerCancel(this);
       
   908 			TInt ret(ValidateExpectString());
       
   909 			RemoveStdExpectStrings();
       
   910 			if (ret != KErrNone)
       
   911 				{
       
   912 				LOGTEXT(_L8("MMTsy:\tCATWaitForCall:\t+CREG=0 failed"));
       
   913 				}
       
   914 			else
       
   915 				{
       
   916 				// Getting the network capabilities that AT+CREG supplies 
       
   917 				// The phone supports retrieval of current registration status.
       
   918 				iPhoneGlobals->iNetworkCaps |= RMobilePhone::KCapsGetRegistrationStatus; //0x00000001
       
   919 				iPhoneGlobals->iNetworkCaps |= RMobilePhone::KCapsGetCurrentMode; //0x00000004
       
   920 				}
       
   921 
       
   922 			iTxBuffer.Copy(KSetUnsolicitedNetworkRegistration2);
       
   923 			iIo->Write(this, iTxBuffer);
       
   924 			iIo->SetTimeOut(this, 5000);
       
   925 			iState = EATWaitForSetUnsolicitedNetworkRegistrationWrite;
       
   926 			}
       
   927 		break;
       
   928 
       
   929 	case EATWaitForSetUnsolicitedNetworkRegistrationWrite:
       
   930 		__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
       
   931 			{
       
   932 			iIo->WriteAndTimerCancel(this);
       
   933 			StandardWriteCompletionHandler(aSource, 5);
       
   934 			iState = EATWaitForSetUnsolicitedNetworkRegistrationOK;
       
   935 			}
       
   936 		break;
       
   937 
       
   938 	case EATWaitForSetUnsolicitedNetworkRegistrationOK:
       
   939 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   940 			{
       
   941 			iIo->WriteAndTimerCancel(this);
       
   942 			TInt ret(ValidateExpectString());
       
   943 			RemoveStdExpectStrings();
       
   944 			if (ret != KErrNone)
       
   945 				{
       
   946 				if (iTxBuffer==KSetUnsolicitedNetworkRegistration2)
       
   947 					{
       
   948 					// Some phones do not support +CREG=2 (e.g SH888)
       
   949 					// Try the fallback position with +CREG=1
       
   950 
       
   951 					iTxBuffer.Copy(KSetUnsolicitedNetworkRegistration1);
       
   952 					iIo->Write(this, iTxBuffer);
       
   953 					iIo->SetTimeOut(this, 5000);
       
   954 					iState = EATWaitForSetUnsolicitedNetworkRegistrationWrite;
       
   955 					break;
       
   956 					}
       
   957 				LOGTEXT(_L8("MMTsy:\tCATInit:\tC+CREG failed"));
       
   958 				}
       
   959 
       
   960 			if(ret == KErrNone) // If +CREG=2 or +CREG=1 were succesfully executed the capabilities can be set. 
       
   961 				{
       
   962 				// The phone supports notify registration status.
       
   963 				iPhoneGlobals->iNetworkCaps |= RMobilePhone::KCapsNotifyRegistrationStatus;
       
   964 
       
   965 				// The phone supports notify mode.
       
   966 				iPhoneGlobals->iNetworkCaps |= RMobilePhone::KCapsNotifyMode;
       
   967 				}
       
   968 			
       
   969 			iTxBuffer.Copy(KReadUnsolicitedNetworkRegistration);
       
   970 			iIo->Write(this, iTxBuffer);
       
   971 			iIo->SetTimeOut(this, 5000);
       
   972 			iState = EATWaitForReadUnsolicitedNetworkRegistrationWrite;
       
   973 			}
       
   974 		break;
       
   975 
       
   976 	case EATWaitForReadUnsolicitedNetworkRegistrationWrite:
       
   977 		__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
       
   978 			{
       
   979 			iIo->WriteAndTimerCancel(this);
       
   980 			StandardWriteCompletionHandler(aSource, 5);
       
   981 			iState = EATWaitForReadUnsolicitedNetworkRegistrationOK;
       
   982 			}
       
   983 		break;
       
   984 
       
   985 	case EATWaitForReadUnsolicitedNetworkRegistrationOK:
       
   986 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
   987 			{
       
   988 			iIo->WriteAndTimerCancel(this);
       
   989 			TInt ret(ValidateExpectString());
       
   990 			RemoveStdExpectStrings();
       
   991 			if (ret != KErrNone)
       
   992 				{				
       
   993 				LOGTEXT(_L8("MMTsy:\tCATInit:\tRead Network Registration Not Supported"));				
       
   994 				}
       
   995 			iTxBuffer.Copy(KSetExtendedCallIndicationCommand);
       
   996 			iIo->Write(this, iTxBuffer);
       
   997 			iIo->SetTimeOut(this, 5000);
       
   998 			iState = EATWaitForSetExtendedCallIndicationWrite;
       
   999 			}
       
  1000 		break;
       
  1001 
       
  1002 	case EATWaitForSetExtendedCallIndicationWrite:
       
  1003 		__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1004 			{
       
  1005 			iIo->WriteAndTimerCancel(this);
       
  1006 			StandardWriteCompletionHandler(aSource, 5);
       
  1007 			iState = EATWaitForSetExtendedCallIndicationOK;
       
  1008 			}
       
  1009 		break;
       
  1010 
       
  1011 	case EATWaitForSetExtendedCallIndicationOK:
       
  1012 		__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
  1013 			{
       
  1014 			iIo->WriteAndTimerCancel(this);
       
  1015 			TInt ret(ValidateExpectString());
       
  1016 			RemoveStdExpectStrings();
       
  1017 			if (ret != KErrNone)
       
  1018 				{
       
  1019 				LOGTEXT(_L8("MMTsy:\tCATWaitForCall:\t+CRC=1 failed"));
       
  1020 				}
       
  1021 			iTxBuffer.Copy(KGetCurrentOperatorCommand);
       
  1022 			iIo->Write(this, iTxBuffer);
       
  1023 			iIo->SetTimeOut(this, 5000);
       
  1024 			iState=EATGetCurrentOperatorWriteComplete;
       
  1025 			}
       
  1026 		break;
       
  1027 	
       
  1028 	case EATGetCurrentOperatorWriteComplete:
       
  1029 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1030 			{
       
  1031 			iIo->WriteAndTimerCancel(this);
       
  1032 			StandardWriteCompletionHandler(aSource, 5);
       
  1033 			iState=EATGetCurrentOperatorReadComplete;
       
  1034 			}
       
  1035 			break;
       
  1036 
       
  1037 	case EATGetCurrentOperatorReadComplete:
       
  1038 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
  1039 			{
       
  1040 			iIo->WriteAndTimerCancel(this);
       
  1041 			TInt ret(ValidateExpectString());
       
  1042 			RemoveStdExpectStrings();
       
  1043 			if (ret != KErrNone)
       
  1044 				{
       
  1045 				LOGTEXT(_L8("MMTsy:\tCATInit:\t+COPS? not supported"));
       
  1046 				}
       
  1047 			else
       
  1048 				{
       
  1049 				LOGTEXT(_L8("MMTsy:\tCATInit:\t+COPS? supported"));
       
  1050 
       
  1051 				// Getting the network capabilities that AT+COPS supplies.
       
  1052 				// The phone supports get/notify current network information.
       
  1053 				iPhoneGlobals->iNetworkCaps |= RMobilePhone::KCapsGetCurrentNetwork; //0x00000010
       
  1054 				iPhoneGlobals->iNetworkCaps |= RMobilePhone::KCapsNotifyCurrentNetwork; //0x00000020
       
  1055 
       
  1056 				// The phone supprts retrieval of a list of detected networks.
       
  1057 				iPhoneGlobals->iNetworkCaps |= RMobilePhone::KCapsGetDetectedNetworks; //0x00000080
       
  1058 
       
  1059 				TRAPD(ret,ParseOperatorL());
       
  1060 				if (ret != KErrNone)
       
  1061 					{
       
  1062 					LOGTEXT(_L8("MMTsy:\tCATInit:\tError parsing +COPS?"));
       
  1063 					}								
       
  1064 				}
       
  1065 			iTxBuffer.Copy(KGetBatteryInfoCommand); // Start the sequence of getting the battery capabilities.
       
  1066 			iIo->Write(this, iTxBuffer);
       
  1067 			iIo->SetTimeOut(this, 5000);
       
  1068 			iState=EATGetBatteryInfoWriteComplete;
       
  1069 			}
       
  1070 			break;
       
  1071 
       
  1072 	case EATGetBatteryInfoWriteComplete:
       
  1073 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1074 			{
       
  1075 			iIo->WriteAndTimerCancel(this);
       
  1076 			StandardWriteCompletionHandler(aSource, 5);
       
  1077 			iState=EATGetBatteryInfoReadComplete;
       
  1078 			}
       
  1079 			break;
       
  1080                 
       
  1081 	case EATGetBatteryInfoReadComplete:
       
  1082 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
  1083 			{
       
  1084 			iIo->WriteAndTimerCancel(this);
       
  1085 			TInt ret(ValidateExpectString());
       
  1086 			RemoveStdExpectStrings();
       
  1087 			if (ret != KErrNone)
       
  1088 				{
       
  1089 				LOGTEXT(_L8("MMTsy:\tCATInit:\t+CBC not supported"));
       
  1090 				}
       
  1091 			else
       
  1092 				{
       
  1093 				LOGTEXT(_L8("MMTsy:\tCATInit:\t+CBC supported"));		
       
  1094 				iPhoneGlobals->iBatteryCaps=RMobilePhone::KCapsGetBatteryInfo;
       
  1095 				}
       
  1096 			iTxBuffer.Copy(KGetSignalInfoCommand); // Start the sequence of getting the signal capabilities.
       
  1097 			iIo->Write(this, iTxBuffer);
       
  1098 			iIo->SetTimeOut(this, 5000);
       
  1099 			iState=EATGetSignalInfoWriteComplete;
       
  1100 
       
  1101 			}
       
  1102 			break;
       
  1103 
       
  1104 	case EATGetSignalInfoWriteComplete:
       
  1105 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1106 			{
       
  1107 			iIo->WriteAndTimerCancel(this);
       
  1108 			StandardWriteCompletionHandler(aSource, 5);
       
  1109 			iState=EATGetSignalInfoReadComplete;
       
  1110 			}
       
  1111 			break;
       
  1112                 
       
  1113 	case EATGetSignalInfoReadComplete:
       
  1114 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
  1115 			{
       
  1116 			iIo->WriteAndTimerCancel(this);
       
  1117 			TInt ret(ValidateExpectString());
       
  1118 			RemoveStdExpectStrings();
       
  1119 			if (ret != KErrNone)
       
  1120 				{
       
  1121 				LOGTEXT(_L8("MMTsy:\tCATInit:\t+CSQ not supported"));
       
  1122 				}
       
  1123 			else
       
  1124 				{
       
  1125 				LOGTEXT(_L8("MMTsy:\tCATInit:\t+CSQ supported"));		
       
  1126 				iPhoneGlobals->iSignalCaps=RMobilePhone::KCapsGetSignalStrength;
       
  1127 				}
       
  1128 			iTxBuffer.Copy(KCurrentCGCLASSCommand);
       
  1129 			iIo->Write(this, iTxBuffer);
       
  1130 			iIo->SetTimeOut(this, 5000);
       
  1131 			iState=EATGetCurrentMSCLASSWriteComplete;
       
  1132 			}
       
  1133 			break;
       
  1134 
       
  1135 	case EATGetCurrentMSCLASSWriteComplete:
       
  1136 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1137 			{
       
  1138 			iIo->WriteAndTimerCancel(this);
       
  1139 			StandardWriteCompletionHandler(aSource, 5);
       
  1140 			iState=EATGetCurrentMSCLASSReadComplete;
       
  1141 			}
       
  1142 			break;
       
  1143 
       
  1144 	case EATGetCurrentMSCLASSReadComplete:
       
  1145 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
  1146 			{
       
  1147 			iIo->WriteAndTimerCancel(this);
       
  1148 			TInt ret(ValidateExpectString());
       
  1149 			RemoveStdExpectStrings();
       
  1150 			if (ret != KErrNone)
       
  1151 				{
       
  1152 				LOGTEXT(_L8("CATInit:\t+CGCLASS? not supported"));
       
  1153 				// Reset the global settings affected by this AT command
       
  1154 				iPhoneGlobals->iMSClass = RPacketService::EMSClassUnknown;
       
  1155 
       
  1156 				}
       
  1157 			else
       
  1158 				{
       
  1159 				LOGTEXT(_L8("CATInit:\t+CGCLASS? supported"));
       
  1160 				TRAPD(ret,ParseCurrentMsClassL());
       
  1161 				if (ret != KErrNone)
       
  1162 					{
       
  1163 					LOGTEXT(_L8("CATInit:\tError parsing +CGCLASS?"));
       
  1164 					}								
       
  1165 				}
       
  1166 			iTxBuffer.Copy(KMaxCGCLASSCommand);
       
  1167 			iIo->Write(this, iTxBuffer);
       
  1168 			iIo->SetTimeOut(this, 5000);
       
  1169 			iState=EATGetMaxMSCLASSWriteComplete;
       
  1170 			}
       
  1171 		break;
       
  1172 
       
  1173 
       
  1174 	case EATGetMaxMSCLASSWriteComplete:
       
  1175 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1176 			{
       
  1177 			iIo->WriteAndTimerCancel(this);
       
  1178 			StandardWriteCompletionHandler(aSource, 5);
       
  1179 			iState=EATGetMaxMSCLASSReadComplete;
       
  1180 			}
       
  1181 			break;
       
  1182 
       
  1183 
       
  1184 	case EATGetMaxMSCLASSReadComplete:
       
  1185 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
  1186 			{
       
  1187 			iIo->WriteAndTimerCancel(this);
       
  1188 			TInt ret(ValidateExpectString());
       
  1189 			RemoveStdExpectStrings();
       
  1190 			if (ret != KErrNone)
       
  1191 				{
       
  1192 				LOGTEXT(_L8("CATInit:\t+CGCLASS=? not supported"));
       
  1193 				iPhoneGlobals->iMaxMSClass = RPacketService::EMSClassUnknown;
       
  1194 				}
       
  1195 			else
       
  1196 				{
       
  1197 				LOGTEXT(_L8("CATInit:\t+CGCLASS=? supported"));
       
  1198 				TRAPD(ret,ParseMaxMsClassL());
       
  1199 				if (ret != KErrNone)
       
  1200 					{
       
  1201 					LOGTEXT(_L8("CATInit:\tError parsing +CGCLASS=?"));
       
  1202 					}								
       
  1203 				}
       
  1204 			iTxBuffer.Copy(KCGQREQCommand);
       
  1205 			iIo->Write(this, iTxBuffer);
       
  1206 			iIo->SetTimeOut(this, 5000);
       
  1207 			iState=EATGetCurrentCGQREQTWriteComplete;
       
  1208 			}
       
  1209 		break;
       
  1210 
       
  1211 	case EATGetCurrentCGQREQTWriteComplete:
       
  1212 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1213 			{
       
  1214 			iIo->WriteAndTimerCancel(this);
       
  1215 			StandardWriteCompletionHandler(aSource, 5);
       
  1216 			iState=EATGetCurrentCGQREQTReadComplete;
       
  1217 			}
       
  1218 		break;
       
  1219 
       
  1220 	case EATGetCurrentCGQREQTReadComplete:
       
  1221 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
  1222 			{
       
  1223 			iIo->WriteAndTimerCancel(this);
       
  1224 			TInt ret(ValidateExpectString());
       
  1225 			RemoveStdExpectStrings();
       
  1226 			if (ret != KErrNone)
       
  1227 				{
       
  1228 				LOGTEXT(_L8("CATInit:\t+CGQREQ? not supported"));
       
  1229 				// Reset the global settings affected by this AT command
       
  1230 				iPhoneGlobals->iStaticQoSCaps.iPrecedence = 0;
       
  1231 				iPhoneGlobals->iStaticQoSCaps.iDelay = 0;
       
  1232 				iPhoneGlobals->iStaticQoSCaps.iReliability = 0;
       
  1233 				iPhoneGlobals->iStaticQoSCaps.iPeak = 0;
       
  1234 				iPhoneGlobals->iStaticQoSCaps.iMean = 0;
       
  1235 				iPhoneGlobals->iGprsMaxNumContexts = 0;		
       
  1236 				}
       
  1237 			else
       
  1238 				{
       
  1239 				LOGTEXT(_L8("CATInit:\t+CGQREQ? supported"));
       
  1240 				TRAPD(ret,ParseCGQREQResponseL());
       
  1241 				if (ret != KErrNone)
       
  1242 					{
       
  1243 					LOGTEXT(_L8("CATInit:\tError parsing +CGQREQ?"));
       
  1244 
       
  1245 
       
  1246 					}								
       
  1247 				}
       
  1248 
       
  1249 			iTxBuffer.Copy(KCGATTCommand);
       
  1250 			iIo->Write(this, iTxBuffer);
       
  1251 			iIo->SetTimeOut(this, 5000);
       
  1252 			iState=EATGetCurrentGprsAttachStateWriteComplete;
       
  1253 
       
  1254 			}
       
  1255 		break;
       
  1256 	case EATGetCurrentGprsAttachStateWriteComplete:
       
  1257 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1258 			{
       
  1259 			iIo->WriteAndTimerCancel(this);
       
  1260 			StandardWriteCompletionHandler(aSource, 5);
       
  1261 			iState=EATGetCurrentGprsAttachStateReadComplete;
       
  1262 			}
       
  1263 		break;
       
  1264 
       
  1265 	case EATGetCurrentGprsAttachStateReadComplete:
       
  1266 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
  1267 			{
       
  1268 			iIo->WriteAndTimerCancel(this);
       
  1269 			TInt ret(ValidateExpectString());
       
  1270 			RemoveStdExpectStrings();
       
  1271 			if (ret != KErrNone)
       
  1272 				{
       
  1273 				LOGTEXT(_L8("CATInit:\t+CGATT? not supported"));
       
  1274 				iPhoneGlobals->iGprsStatus = RPacketService::EStatusUnattached;			
       
  1275 				}
       
  1276 			else
       
  1277 				{
       
  1278 				LOGTEXT(_L8("CATInit:\t+CGATT? supported"));
       
  1279 				TRAPD(ret,ParseCGATTResponseL());
       
  1280 				if (ret != KErrNone)
       
  1281 					{
       
  1282 					LOGTEXT(_L8("CATInit:\tError parsing +CGATT?"));
       
  1283 					}								
       
  1284 				}
       
  1285 
       
  1286 			//
       
  1287 			// Now need to get the SMS receive mode capabilities of the phone.
       
  1288 			// We get these by sending the command AT+CNMI=?
       
  1289 			iTxBuffer.Copy(KGetCNMIConfigCommand);
       
  1290 			iIo->Write(this, iTxBuffer);
       
  1291 			iIo->SetTimeOut(this, 5000);
       
  1292 			iState=EATWaitForSendingCNMIRequest;
       
  1293 			}
       
  1294 		break;
       
  1295 
       
  1296 	case EATWaitForSendingCNMIRequest:
       
  1297 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1298 			{
       
  1299 			iIo->WriteAndTimerCancel(this);
       
  1300 			StandardWriteCompletionHandler(aSource, 5);
       
  1301 			iState=EATWaitForSendingCNMIComplete;
       
  1302 			}
       
  1303 		break;
       
  1304 
       
  1305 	case EATWaitForSendingCNMIComplete:	
       
  1306 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1307 		{			// Curly brackets needed to scope ret variable
       
  1308 		//
       
  1309 		// When we get here we have just received a response from the modem in response
       
  1310 		// to the TSY sending AT+CNMI=?.
       
  1311 
       
  1312 		//
       
  1313 		// Check if the modem returned ERROR
       
  1314 		iIo->WriteAndTimerCancel(this);
       
  1315 		TInt ret(ValidateExpectString());
       
  1316 		RemoveStdExpectStrings();
       
  1317 		if (ret != KErrNone)
       
  1318 			{
       
  1319 			LOGTEXT(_L8("CATInit: +CNMI=? not supported, assuming the phone does not support SMS receive"));
       
  1320 			//
       
  1321 			// We do not have to do the below as the CBase stuff should ensure they are initialised
       
  1322 			// as EFalse. But the code is included below just to be safe and to make the code a bit 
       
  1323 			// more obvious ;-)
       
  1324 			iPhoneGlobals->iModemSupportsCMTIMode=EFalse;
       
  1325 			iPhoneGlobals->iModemSupportsCMTMode=EFalse;
       
  1326 			}
       
  1327 		else
       
  1328 			{
       
  1329 			LOGTEXT(_L8("CATInit: +CNMI=? supported"));
       
  1330 			//
       
  1331 			// ParseCNMIResponse will parse the response string and set the
       
  1332 			// appropriate CPhoneGlobals data. If the call leaves, then the
       
  1333 			// CPhoneGlobal data may or may not have valid values, so we 
       
  1334 			// have to manually correct them here.
       
  1335 			TRAPD(ret,ParseCNMIResponseL());
       
  1336 			if (ret != KErrNone)
       
  1337 				{
       
  1338 				LOGTEXT(_L8("CATInit: Error parsing +CNMI=? response, assuming phone does not support SMS receive"));
       
  1339 				iPhoneGlobals->iModemSupportsCMTIMode=EFalse;
       
  1340 				iPhoneGlobals->iModemSupportsCMTMode=EFalse;
       
  1341 				}								
       
  1342 			}
       
  1343 		
       
  1344 		// 
       
  1345 		// Start of work-around for Ericsson phones
       
  1346 
       
  1347 		// The Ericsson phones (T28 & R320 definetly) do not support 
       
  1348 		// CMT PDU Rx (unstored) mode even though they claim to in their
       
  1349 		// "AT+CNMI=?" responses.
       
  1350 		if(iPhoneGlobals->iPhoneId.iManufacturer.MatchF(KEricsson)==0)
       
  1351 			{
       
  1352 			LOCAL_LOGTEXT("EventSignalL","Applying Ericsson +CNMI=? work-around");
       
  1353 			iPhoneGlobals->iModemSupportsCMTMode=EFalse;
       
  1354 			}
       
  1355 		
       
  1356 		// End of work-around for Ericsson phones
       
  1357 		// 
       
  1358 
       
  1359 		// 
       
  1360 		// Start of work-around for Nokia 6210 phone
       
  1361 
       
  1362 		// The Nokia 6210 phones do not seem to support CMTI (receive stored)
       
  1363 		// SMS receive mode.
       
  1364 		_LIT16(KNokia,"*Nokia*");
       
  1365 		_LIT16(KNokia6210,"*Nokia 6210*");
       
  1366 		if(iPhoneGlobals->iPhoneId.iManufacturer.MatchF(KNokia)==0 &&
       
  1367 		   iPhoneGlobals->iPhoneId.iModel.MatchF(KNokia6210)==0)
       
  1368 			{
       
  1369 			LOCAL_LOGTEXT("EventSignalL","Applying Nokia 6210 +CNMI=? work-around");
       
  1370 			iPhoneGlobals->iModemSupportsCMTIMode=EFalse;
       
  1371 			}
       
  1372 		
       
  1373 		// End of work-around for Nokia 6210 phones
       
  1374 		// 
       
  1375 
       
  1376 	
       
  1377 
       
  1378 		
       
  1379 		//
       
  1380 		// Summarise the phone capabilties to the log file
       
  1381 		LOGTEXT3(_L8("CATInit: iModemSupportsCMTIMode:%d iModemSupportsCMTMode:%d"),iPhoneGlobals->iModemSupportsCMTIMode,iPhoneGlobals->iModemSupportsCMTMode);
       
  1382 		}
       
  1383 
       
  1384 		//
       
  1385 		// Start the sending of the +CBST=? command
       
  1386 		iTxBuffer.Copy(KGetCBSTConfigCommand);
       
  1387 		iIo->Write(this, iTxBuffer);
       
  1388 		iIo->SetTimeOut(this, 5000);
       
  1389 		iState=EATWaitForSendingCBSTRequest;
       
  1390 		break;
       
  1391 
       
  1392 	case EATWaitForSendingCBSTRequest:
       
  1393 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1394 			{
       
  1395 			iIo->WriteAndTimerCancel(this);
       
  1396 			StandardWriteCompletionHandler(aSource, 5);
       
  1397 			iState=EATWaitForSendingCBSTComplete;
       
  1398 			}
       
  1399 		break;
       
  1400 	
       
  1401 	case EATWaitForSendingCBSTComplete:
       
  1402 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1403 		{			// Curly brackets needed to scope ret variable
       
  1404 		//
       
  1405 		// When we get here we have just received a response from the modem in response
       
  1406 		// to the TSY sending AT+CBST=?.
       
  1407 
       
  1408 		//
       
  1409 		// Check if the modem returned ERROR
       
  1410 		iIo->WriteAndTimerCancel(this);
       
  1411 		TInt ret(ValidateExpectString());
       
  1412 		RemoveStdExpectStrings();
       
  1413 		if (ret != KErrNone)
       
  1414 			{
       
  1415 			LOGTEXT(_L8("CATInit: +CBST=? not supported"));
       
  1416 			}
       
  1417 		else
       
  1418 			{
       
  1419 			LOGTEXT(_L8("CATInit: +CBST=? supported"));
       
  1420 			//
       
  1421 			// ParseCBSTResponse will parse the response string and set the
       
  1422 			// appropriate CPhoneGlobals data. 
       
  1423 			TRAPD(ret,ParseCBSTResponseL());
       
  1424 			if (ret != KErrNone)
       
  1425 				{
       
  1426 				LOGTEXT(_L8("CATInit: Error parsing +CBST=? response"));
       
  1427 				}
       
  1428 			}
       
  1429 		}
       
  1430 
       
  1431 		//
       
  1432 		// Start the sending of the +CSCA? command
       
  1433 		iTxBuffer.Copy(KGetServiceCentreAddressCommand);
       
  1434 		iIo->Write(this, iTxBuffer);
       
  1435 		iIo->SetTimeOut(this, 5000);
       
  1436 		iState=EATWaitForSendingCSCARequest;
       
  1437 		break;
       
  1438 
       
  1439 	case EATWaitForSendingCSCARequest:
       
  1440 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1441 			{
       
  1442 			iIo->WriteAndTimerCancel(this);
       
  1443 			StandardWriteCompletionHandler(aSource, 5);
       
  1444 			iState=EATWaitForSendingCSCAComplete;
       
  1445 			}
       
  1446 		break;
       
  1447 	
       
  1448 	case EATWaitForSendingCSCAComplete:
       
  1449 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1450 		{			// Curly brackets needed to scope ret variable
       
  1451 		//
       
  1452 		// Check if the modem returned ERROR
       
  1453 		iIo->WriteAndTimerCancel(this);
       
  1454 		TInt ret(ValidateExpectString());
       
  1455 		RemoveStdExpectStrings();
       
  1456 		if (ret != KErrNone)
       
  1457 			{
       
  1458 			LOGTEXT(_L8("CATInit: +CSCA? not supported"));
       
  1459 			iPhoneGlobals->iModemSupportsCSCAMode=EFalse;
       
  1460 			}
       
  1461 		else
       
  1462 			{
       
  1463 			LOGTEXT(_L8("CATInit: +CSCA? supported"));
       
  1464 			iPhoneGlobals->iModemSupportsCSCAMode=ETrue;
       
  1465 			}
       
  1466 		}
       
  1467 	
       
  1468 		//
       
  1469 		// Start the sending of the AT=CGREG=1 command
       
  1470 		// We do this to set the unsolicited GPRS network registration status change mode
       
  1471 		// of the phone.
       
  1472 		iTxBuffer.Copy(KSetUnsolicitedGPRSNetworkRegistration1);
       
  1473 		iIo->Write(this, iTxBuffer);
       
  1474 		iIo->SetTimeOut(this, 5000);
       
  1475 		iState=EATWaitForSetUnsolicitedGPRSNetworkRegistrationWrite;
       
  1476 		break;
       
  1477 
       
  1478 	case EATWaitForSetUnsolicitedGPRSNetworkRegistrationWrite:
       
  1479 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1480 			{
       
  1481 			iIo->WriteAndTimerCancel(this);
       
  1482 			StandardWriteCompletionHandler(aSource, 5);
       
  1483 			iState=EATWaitForSetUnsolicitedGPRSNetworkRegistrationOK;
       
  1484 			}
       
  1485 		break;
       
  1486 
       
  1487 	case EATWaitForSetUnsolicitedGPRSNetworkRegistrationOK:
       
  1488 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1489 		{			// Curly brackets needed to scope ret variable
       
  1490 		//
       
  1491 		// Check if the modem returned ERROR
       
  1492 		iIo->WriteAndTimerCancel(this);
       
  1493 		TInt ret(ValidateExpectString());
       
  1494 		RemoveStdExpectStrings();
       
  1495 		if (ret != KErrNone)
       
  1496 			{
       
  1497 			LOGTEXT(_L8("CATInit: AT+CGREG=1 not supported"));
       
  1498 			iPhoneGlobals->iModemSupportsCGREGNotification=EFalse;
       
  1499 			}
       
  1500 		else
       
  1501 			{
       
  1502 			LOGTEXT(_L8("CATInit: AT+CGREG=1 supported"));
       
  1503 			iPhoneGlobals->iModemSupportsCGREGNotification=ETrue;
       
  1504 			}
       
  1505 		}
       
  1506 
       
  1507 
       
  1508 		// If it's an Ericsson phone then enable their call monitoring because
       
  1509 		// they don't return NO CARRIER correctly for voice calls.
       
  1510 		if(iPhoneGlobals->iPhoneId.iManufacturer.MatchF(KEricsson)==0)
       
  1511 			{
       
  1512 			//
       
  1513 			// Start the sending of the AT*ECAM=1 command
       
  1514 			iTxBuffer.Copy(KSetECAMConfigCommand);
       
  1515 			iIo->Write(this, iTxBuffer);
       
  1516 			iIo->SetTimeOut(this, 5000);
       
  1517 			iState=EATWaitForSendingECAMRequest;
       
  1518 			}
       
  1519 			else
       
  1520 			{
       
  1521 				// It's not an Ericsson phone, so Init is complete
       
  1522 				Complete(KErrNone);
       
  1523 			}
       
  1524 		break;
       
  1525 
       
  1526 	case EATWaitForSendingECAMRequest:
       
  1527 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1528 			{
       
  1529 			iIo->WriteAndTimerCancel(this);
       
  1530 			StandardWriteCompletionHandler(aSource, 5);
       
  1531 			iState=EATWaitForSendingECAMComplete;
       
  1532 			}
       
  1533 		break;
       
  1534 	
       
  1535 	case EATWaitForSendingECAMComplete:
       
  1536 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  1537 		{			
       
  1538 		// Curly brackets needed to scope ret variable
       
  1539 		// Check if the modem returned ERROR
       
  1540 		iIo->WriteAndTimerCancel(this);
       
  1541 		TInt ret(ValidateExpectString());
       
  1542 		RemoveStdExpectStrings();
       
  1543 		if (ret != KErrNone)
       
  1544 			{
       
  1545 			LOGTEXT(_L8("CATInit: Ericsson Call Monitoring NOT supported"));
       
  1546 			}
       
  1547 		else
       
  1548 			{
       
  1549 			LOGTEXT(_L8("CATInit: Ericsson Call Monitoring supported"));
       
  1550 			}
       
  1551 		}		
       
  1552 		//
       
  1553 		// The initialisation of the TSY is complete
       
  1554 		Complete(KErrNone);
       
  1555 		break;
       
  1556 	default:					// Default case required to avoid warnings in ARM builds
       
  1557 		break;
       
  1558 		} // iState
       
  1559 	}			
       
  1560 
       
  1561 void CATInit::ParseWaitTimeL()
       
  1562 	{
       
  1563 	ParseBufferLC();
       
  1564 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  1565 	if (iRxResults.IsEmpty())
       
  1566 		iPhoneGlobals->iPhoneStatus.iWaitForCarrierTime = KDefaultSecondsToWaitForCarrier;
       
  1567 	else
       
  1568 		{
       
  1569 		CATParamListEntry* entry = iRxResults.First();
       
  1570 		TLex8 lex(entry->iResultPtr);
       
  1571 		(void)User::LeaveIfError(lex.Val(iPhoneGlobals->iPhoneStatus.iWaitForCarrierTime));
       
  1572 		entry->Deque();
       
  1573 		delete entry;
       
  1574 		entry=NULL;
       
  1575 		}
       
  1576 	CleanupStack::PopAndDestroy();
       
  1577 	}
       
  1578 
       
  1579 void CATInit::ParsePhoneCapsL()
       
  1580 	{
       
  1581 	ParseBufferLC();
       
  1582 	TUint phoneCaps = 0;
       
  1583 	if (iRxResults.IsEmpty())
       
  1584 		phoneCaps |= RPhone::KCapsUnknown;
       
  1585 	else
       
  1586 		{
       
  1587 		CATParamListEntry* entry;
       
  1588 		TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  1589 		while (entry = iter++,entry!=NULL)
       
  1590 			{
       
  1591 			TPtrC8 aResult(entry->iResultPtr);
       
  1592 			if (aResult==KGetPhoneCapsCommand)
       
  1593 				continue;	// echo is still enabled - ignore the original command!
       
  1594 			else if (aResult==KZeroString)
       
  1595 				phoneCaps |= RPhone::KCapsData;
       
  1596 			else if (aResult==KOneString)
       
  1597 				phoneCaps |= RPhone::KCapsFaxClassOne;
       
  1598 			else if (aResult==KOnePointZeroString)
       
  1599 				phoneCaps |= RPhone::KCapsFaxClassOnePointZero;
       
  1600 			else if (aResult==KTwoString)
       
  1601 				phoneCaps |= RPhone::KCapsFaxClassTwo;
       
  1602 			else if (aResult==KTwoPointZeroString)
       
  1603 				phoneCaps |= RPhone::KCapsFaxClassTwoPointZero;
       
  1604 			else if (aResult==KTwoPointOneString)
       
  1605 				phoneCaps |= RPhone::KCapsFaxClassTwoPointOne;
       
  1606 			entry->Deque();
       
  1607 			delete entry;
       
  1608 			}
       
  1609 		phoneCaps |= RPhone::KCapsEventModemDetection;
       
  1610 		phoneCaps |= RPhone::KCapsVoice;	// always true of a GSM phone!
       
  1611 		}
       
  1612 	LOGTEXT2(_L8("ParsePhoneCapsL\t iDataAndFaxFlags set to 0x%x"), phoneCaps);
       
  1613 	iPhoneGlobals->iPhoneStatus.iDataAndFaxFlags = phoneCaps;
       
  1614 	CleanupStack::PopAndDestroy();
       
  1615 	}
       
  1616 
       
  1617 void CATInit::ParseAnErroredPhoneCaps()
       
  1618 //
       
  1619 // If the modem returns an ERROR to "AT+FCLASS=?" then assume Data and Voice only
       
  1620 //
       
  1621 	{
       
  1622 	TUint phoneCaps = 0;
       
  1623 	phoneCaps |= RPhone::KCapsData;
       
  1624 	phoneCaps |= RPhone::KCapsEventModemDetection;
       
  1625 	phoneCaps |= RPhone::KCapsVoice;
       
  1626 	LOGTEXT2(_L8("ParseAnErroredPhoneCapsL\t iDataAndFaxFlags set to 0x%x"), phoneCaps);
       
  1627 	iPhoneGlobals->iPhoneStatus.iDataAndFaxFlags = phoneCaps;
       
  1628 	}
       
  1629 
       
  1630 void CATInit::ParsePhoneBookStorageL()
       
  1631 	{
       
  1632 	ParseBufferLC();
       
  1633 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  1634 	TUint phoneBook=KPhoneBookNoStorage;
       
  1635 	TInt count=0;
       
  1636 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  1637 	if (!iRxResults.IsEmpty())
       
  1638 		iter++;	// skip the +CPMS:
       
  1639 
       
  1640 	CATParamListEntry* entry;
       
  1641 	while (entry = iter++,entry!=NULL)
       
  1642 		{
       
  1643 		count++;
       
  1644 		TPtrC8 result(entry->iResultPtr);
       
  1645 		if (result==KFDStorage)
       
  1646 			phoneBook|=KPhoneBookFDStorage;
       
  1647 		else if (result==KLDStorage)
       
  1648 			phoneBook|=KPhoneBookLDStorage;
       
  1649 		else if (result==KMEStorage)
       
  1650 			phoneBook|=KPhoneBookMEStorage;
       
  1651 		else if (result==KMTStorage)
       
  1652 			phoneBook|=KPhoneBookMTStorage;
       
  1653 		else if (result==KSMStorage)
       
  1654 			phoneBook|=KPhoneBookSMStorage;
       
  1655 		else if (result==KTAStorage)
       
  1656 			phoneBook|=KPhoneBookTAStorage;
       
  1657 		else if (result==KBMStorage)
       
  1658 			phoneBook|=KPhoneBookBarredStorage;
       
  1659 		else if (result==KDCStorage)
       
  1660 			phoneBook|=KPhoneBookLastDialledStorage;
       
  1661 		else if (result==KENStorage)
       
  1662 			phoneBook|=KPhoneBookEmergencyStorage;
       
  1663 		else if (result==KMCStorage)
       
  1664 			phoneBook|=KPhoneBookMissedCallsStorage;
       
  1665 		else if (result==KONStorage)
       
  1666 			phoneBook|=KPhoneBookOwnNumbersStorage;
       
  1667 		else if (result==KRCStorage)
       
  1668 			phoneBook|=KPhoneBookReceivedCallsStorage;
       
  1669 		else if (result==KSNStorage)
       
  1670 			phoneBook|=KPhoneBookServiceNumberStorage;
       
  1671 		entry->Deque();
       
  1672 		delete entry;
       
  1673 		}
       
  1674 	iPhoneGlobals->iPhoneStatus.iSupportedPhoneBookStorageFlag=phoneBook;
       
  1675 	iPhoneGlobals->iPhoneStatus.iSupportedPhoneBookCount=count;
       
  1676 	CleanupStack::PopAndDestroy();
       
  1677 	}
       
  1678 
       
  1679 static TInt NetworkIdL(const TDesC8& aCode,RMobilePhone::TMobilePhoneNetworkCountryCode& aCountryCode, RMobilePhone::TMobilePhoneNetworkIdentity& aNetworkIdentity)
       
  1680 /**
       
  1681  * This function converts the MCC and MNC as hex print of BCD coding. It is called from
       
  1682  * the CATInit::ParseOperatorL() method. 
       
  1683  */
       
  1684 	{
       
  1685 	if (aCode.Length()!=5)
       
  1686 		{
       
  1687 		return KErrGeneral;
       
  1688 		}
       
  1689 	
       
  1690 	aCountryCode.SetLength(3);
       
  1691 	aCountryCode[0] = aCode[0];
       
  1692 	aCountryCode[1] = aCode[1];
       
  1693 	aCountryCode[2] = aCode[2];
       
  1694 
       
  1695 	aNetworkIdentity.SetLength(2);
       
  1696 	aNetworkIdentity[0] = aCode[3];
       
  1697 	aNetworkIdentity[1] = aCode[4];
       
  1698 	
       
  1699 	return KErrNone;
       
  1700 	}
       
  1701 
       
  1702 void CATInit::ParseOperatorL()
       
  1703 /** This method parses the response to the operator query AT command.
       
  1704  *  The response from the phone has one of the formats below:
       
  1705  *		+COPS: mode, 0, "long format name"
       
  1706  *		+COPS: mode, 1, "short format name"
       
  1707  *		+COPS: mode, 2, "operator ID in hex"
       
  1708  *		+COPS: mode
       
  1709  */
       
  1710 	{
       
  1711 	RMobilePhone::TMobilePhoneNetworkInfoV1& networkInfo = iPhoneGlobals->iPhoneStatus.iCurrentNetwork;
       
  1712 
       
  1713 	// Set all the Network Info. variables to zero/unknown
       
  1714 	networkInfo.iCountryCode.FillZ(); // MCC 
       
  1715 	networkInfo.iNetworkId.FillZ();	  // MNC 
       
  1716 	networkInfo.iCdmaSID.FillZ();	  // Unused CDMA field
       
  1717 	networkInfo.iAnalogSID.FillZ();	  // Unused CDMA field
       
  1718 	networkInfo.iShortName.FillZ();
       
  1719 	networkInfo.iLongName.FillZ();
       
  1720 	networkInfo.iStatus=RMobilePhone::ENetworkStatusUnknown; 
       
  1721 
       
  1722 	ParseBufferLC();
       
  1723 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  1724 	CATParamListEntry* entry;
       
  1725 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  1726 
       
  1727 	entry=iter++;				// +COPS:
       
  1728 	if (entry->iResultPtr.MatchF(KOperatorResponse)!=0)
       
  1729 		User::Leave(KErrGeneral);
       
  1730 
       
  1731 	entry=iter++;				// <mode>
       
  1732 	if (entry==NULL)
       
  1733 		User::Leave(KErrGeneral);
       
  1734 	// not interested in the mode
       
  1735 
       
  1736 	entry=iter++;				// <format>
       
  1737 	if (entry==NULL)
       
  1738 		User::Leave(KErrGeneral);
       
  1739 	TInt format=CATParamListEntry::EntryValL(entry);
       
  1740 
       
  1741 	entry=iter++;				// <oper>
       
  1742 	if (entry==NULL)
       
  1743 		User::Leave(KErrGeneral);
       
  1744 	switch (format)
       
  1745 		{
       
  1746 	case 0:
       
  1747   		if((entry->iResultPtr).Length() > networkInfo.iLongName.MaxLength())
       
  1748   			networkInfo.iLongName.Copy((entry->iResultPtr).Mid(0,networkInfo.iLongName.MaxLength()));			
       
  1749   		else
       
  1750   			networkInfo.iLongName.Copy(entry->iResultPtr);
       
  1751 		break;
       
  1752 	case 1:
       
  1753   		if((entry->iResultPtr).Length() > networkInfo.iShortName.MaxLength())
       
  1754   			networkInfo.iShortName.Copy((entry->iResultPtr).Mid(0,networkInfo.iShortName.MaxLength()));			
       
  1755   		else 
       
  1756   			networkInfo.iShortName.Copy(entry->iResultPtr);	
       
  1757 		break;
       
  1758 	case 2:	
       
  1759 		User::LeaveIfError(NetworkIdL(entry->iResultPtr,networkInfo.iCountryCode, networkInfo.iNetworkId));
       
  1760 		break;		// hs	
       
  1761 	default:
       
  1762 		User::Leave(KErrGeneral);
       
  1763 		break;
       
  1764 		}
       
  1765 
       
  1766 	// We've got an answer, so this must be the current network
       
  1767 	networkInfo.iStatus=RMobilePhone::ENetworkStatusCurrent;
       
  1768 	
       
  1769 	CleanupStack::PopAndDestroy();
       
  1770 	}
       
  1771 
       
  1772 void CATInit::ParseCurrentMsClassL()
       
  1773 	{
       
  1774 	iPhoneGlobals->iMSClass = RPacketService::EMSClassUnknown;
       
  1775 	ParseBufferLC();
       
  1776 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  1777 	CATParamListEntry* entry;
       
  1778 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  1779 	entry=iter++;				// +CGCLASS:
       
  1780 	if(entry==NULL)
       
  1781 		User::Leave(KErrGeneral);
       
  1782 	if (entry->iResultPtr.MatchF(KCGCLASSResponseString)!=0)
       
  1783 		User::Leave(KErrGeneral);
       
  1784 	entry=iter++;				
       
  1785 	if (entry==NULL)
       
  1786 		User::Leave(KErrGeneral);
       
  1787 	// not interested in the mode
       
  1788 	TPtrC8 result(entry->iResultPtr);
       
  1789 	if(result == KClassA)
       
  1790 		iPhoneGlobals->iMSClass = RPacketService::EMSClassDualMode;
       
  1791 	else if(result == KClassB)
       
  1792 		iPhoneGlobals->iMSClass = RPacketService::EMSClassSuspensionRequired;
       
  1793 	else if(result == KClassC)
       
  1794 		iPhoneGlobals->iMSClass = RPacketService::EMSClassAlternateMode;
       
  1795 	else if(result == KClassCG)
       
  1796 		iPhoneGlobals->iMSClass = RPacketService::EMSClassPacketSwitchedOnly;
       
  1797 	else if(result == KClassCC)
       
  1798 		iPhoneGlobals->iMSClass = RPacketService::EMSClassCircuitSwitchedOnly;
       
  1799 	CleanupStack::PopAndDestroy();
       
  1800 	}
       
  1801 
       
  1802 
       
  1803 void CATInit::ParseMaxMsClassL()
       
  1804 	{
       
  1805 	iPhoneGlobals->iMaxMSClass = RPacketService::EMSClassUnknown;
       
  1806 	ParseBufferLC();
       
  1807 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  1808 	CATParamListEntry* entry;
       
  1809 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  1810 	entry=iter++;				// +CGCLASS:
       
  1811 	if(entry==NULL)
       
  1812 		User::Leave(KErrGeneral);
       
  1813 	if (entry->iResultPtr.MatchF(KCGCLASSResponseString)!=0)
       
  1814 		User::Leave(KErrGeneral);
       
  1815 	entry=iter++;				
       
  1816 	if (entry==NULL)
       
  1817 		User::Leave(KErrGeneral);
       
  1818 	// not interested in the mode
       
  1819 	TPtrC8 result(entry->iResultPtr);
       
  1820 	if(result == KClassA)
       
  1821 		iPhoneGlobals->iMaxMSClass = RPacketService::EMSClassDualMode;
       
  1822 	else if(result == KClassB)
       
  1823 		iPhoneGlobals->iMaxMSClass = RPacketService::EMSClassSuspensionRequired;
       
  1824 	else if(result == KClassC)
       
  1825 		iPhoneGlobals->iMaxMSClass = RPacketService::EMSClassAlternateMode;
       
  1826 	else if(result == KClassCG)
       
  1827 		iPhoneGlobals->iMaxMSClass = RPacketService::EMSClassPacketSwitchedOnly;
       
  1828 	else if(result == KClassCC)
       
  1829 		iPhoneGlobals->iMaxMSClass = RPacketService::EMSClassCircuitSwitchedOnly;
       
  1830 	CleanupStack::PopAndDestroy();
       
  1831 
       
  1832 	}
       
  1833 
       
  1834 
       
  1835 void CATInit::ParseCGQREQResponseL()
       
  1836 /**
       
  1837  * This Function parses the response from the get CGQREQ command to the phone.
       
  1838  * An example response is;
       
  1839  *  +CGQREQ: (1-3),(0-3),(0-4),(0-5),(0-9),(0-18,31)
       
  1840  *  1st parameter: list of valid context ID values
       
  1841  *  2nd parameter: list of supported <precedence>
       
  1842  *  3rd parameter: list of supported <delay>
       
  1843  *  4th parameter: list of supported <reliabilitiy>
       
  1844  *  5th parameter: list of supported <peak>
       
  1845  *  6th parameter: list of supported <mean>
       
  1846  */
       
  1847 	{
       
  1848 	iPhoneGlobals->iStaticQoSCaps.iPrecedence = 0;
       
  1849 	iPhoneGlobals->iStaticQoSCaps.iDelay = 0;
       
  1850 	iPhoneGlobals->iStaticQoSCaps.iReliability = 0;
       
  1851 	iPhoneGlobals->iStaticQoSCaps.iPeak = 0;
       
  1852 	iPhoneGlobals->iStaticQoSCaps.iMean = 0;
       
  1853 	iPhoneGlobals->iGprsMaxNumContexts = 0;
       
  1854 	ParseBufferLC();
       
  1855 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  1856 	CATParamListEntry* entry;
       
  1857 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  1858 
       
  1859 	//
       
  1860 	// Check we have +CGQREQ: at the start of the response string
       
  1861 	entry=iter++;			
       
  1862 	if (entry==NULL || entry->iResultPtr.MatchF(KCGQREQResponseString)!=0)
       
  1863 		User::Leave(KErrGeneral);
       
  1864 
       
  1865 	//
       
  1866 	// Parse 1st parmeeter, list of valid context IDs (cid)
       
  1867 	// We just want to extract the maximum cid
       
  1868 	entry=iter++;				
       
  1869 	if (entry==NULL)
       
  1870 		User::Leave(KErrGeneral);
       
  1871 	
       
  1872 	// Check to see if the phone supports more than 9 contexts
       
  1873 	TPtrC8 result(entry->iResultPtr.Right(2));
       
  1874 	TLex8 lex(result);
       
  1875 	TInt value(0);
       
  1876 	if(lex.Val(value)!= KErrNone || value<0 || value>20)
       
  1877 		{
       
  1878 		TPtrC8 result(entry->iResultPtr.Right(1)); 
       
  1879 		TLex8 lex2(result);
       
  1880 		(void)User::LeaveIfError(lex2.Val(value));
       
  1881 		}
       
  1882 	iPhoneGlobals->iGprsMaxNumContexts = value;
       
  1883 
       
  1884 // Get max precedence levels
       
  1885 	entry=iter++;				
       
  1886 	if (entry==NULL)
       
  1887 		User::Leave(KErrGeneral);
       
  1888 	result.Set(entry->iResultPtr.Right(1));
       
  1889 	lex = result;
       
  1890 	value = 0;
       
  1891 	TInt valueToSet = 0;
       
  1892 	(void)User::LeaveIfError(lex.Val(value));
       
  1893 	switch(value)
       
  1894 		{
       
  1895 		case 1:
       
  1896 			valueToSet = RPacketQoS::EPriorityHighPrecedence;
       
  1897 			break;
       
  1898 		case 2:
       
  1899 			valueToSet = RPacketQoS::EPriorityMediumPrecedence;
       
  1900 			break;
       
  1901 		case 3:
       
  1902 			valueToSet = RPacketQoS::EPriorityLowPrecedence;
       
  1903 			break;
       
  1904 		default:
       
  1905 			valueToSet = RPacketQoS::EUnspecifiedPrecedence;
       
  1906 			break;
       
  1907 		}
       
  1908 	iPhoneGlobals->iStaticQoSCaps.iPrecedence = valueToSet;
       
  1909 // Get max delay class
       
  1910 	entry=iter++;				
       
  1911 	if (entry==NULL)
       
  1912 		User::Leave(KErrGeneral);
       
  1913 	result.Set(entry->iResultPtr.Right(1)); 
       
  1914 	lex = result;
       
  1915 	value = 0;
       
  1916 	(void)User::LeaveIfError(lex.Val(value));
       
  1917 	switch(value)
       
  1918 		{
       
  1919 		case 1:
       
  1920 			valueToSet = RPacketQoS::EDelayClass1;
       
  1921 			break;
       
  1922 		case 2:
       
  1923 			valueToSet = RPacketQoS::EDelayClass2;
       
  1924 			break;
       
  1925 		case 3:
       
  1926 			valueToSet = RPacketQoS::EDelayClass3;
       
  1927 			break;
       
  1928 		case 4:
       
  1929 			valueToSet = RPacketQoS::EDelayClass4;
       
  1930 			break;
       
  1931 		default:
       
  1932 			valueToSet = RPacketQoS::EUnspecifiedDelayClass;
       
  1933 			break;
       
  1934 	}
       
  1935 	iPhoneGlobals->iStaticQoSCaps.iDelay = valueToSet ;
       
  1936 // Get max reliability class
       
  1937 	entry=iter++;				
       
  1938 	if (entry==NULL)
       
  1939 		User::Leave(KErrGeneral);
       
  1940 	result.Set(entry->iResultPtr.Right(1)); 
       
  1941 	lex = result;
       
  1942 	value = 0;
       
  1943 	(void)User::LeaveIfError(lex.Val(value));
       
  1944 	switch(value)
       
  1945 		{
       
  1946 		case 1:
       
  1947 			valueToSet = RPacketQoS::EReliabilityClass1;
       
  1948 			break;
       
  1949 		case 2:
       
  1950 			valueToSet = RPacketQoS::EReliabilityClass2;
       
  1951 			break;
       
  1952 		case 3:
       
  1953 			valueToSet = RPacketQoS::EReliabilityClass3;
       
  1954 			break;
       
  1955 		case 4:
       
  1956 			valueToSet = RPacketQoS::EReliabilityClass4;
       
  1957 			break;	
       
  1958 		case 5:
       
  1959 			valueToSet = RPacketQoS::EReliabilityClass5;
       
  1960 			break;
       
  1961 		default:
       
  1962 			valueToSet = RPacketQoS::EUnspecifiedReliabilityClass;
       
  1963 			break;
       
  1964 		}
       
  1965 	iPhoneGlobals->iStaticQoSCaps.iReliability = valueToSet;
       
  1966 // Get max peak throughput class
       
  1967 	entry=iter++;				
       
  1968 	if (entry==NULL)
       
  1969 		User::Leave(KErrGeneral);
       
  1970 	result.Set(entry->iResultPtr.Right(1)); 
       
  1971 	lex = result;
       
  1972 	value = 0;
       
  1973 	(void)User::LeaveIfError(lex.Val(value));
       
  1974 	switch(value)
       
  1975 		{
       
  1976 		case 1:
       
  1977 			valueToSet = RPacketQoS::EPeakThroughput1000;
       
  1978 			break;
       
  1979 		case 2:
       
  1980 			valueToSet = RPacketQoS::EPeakThroughput2000;
       
  1981 			break;
       
  1982 		case 3:
       
  1983 			valueToSet = RPacketQoS::EPeakThroughput4000;
       
  1984 			break;
       
  1985 		case 4:
       
  1986 			valueToSet = RPacketQoS::EPeakThroughput8000;
       
  1987 			break;	
       
  1988 		case 5:
       
  1989 			valueToSet = RPacketQoS::EPeakThroughput16000;
       
  1990 			break;
       
  1991 		case 6:
       
  1992 			valueToSet = RPacketQoS::EPeakThroughput32000;
       
  1993 			break;
       
  1994 		case 7:
       
  1995 			valueToSet = RPacketQoS::EPeakThroughput64000;
       
  1996 			break;
       
  1997 		case 8:
       
  1998 			valueToSet = RPacketQoS::EPeakThroughput128000;
       
  1999 			break;
       
  2000 		case 9:
       
  2001 			valueToSet = RPacketQoS::EPeakThroughput256000;
       
  2002 			break;
       
  2003 		
       
  2004 		default:
       
  2005 			valueToSet = RPacketQoS::EUnspecifiedPeakThroughput;
       
  2006 			break;
       
  2007 		}
       
  2008 	iPhoneGlobals->iStaticQoSCaps.iPeak = valueToSet;
       
  2009 // Get max mean throughput class
       
  2010 	entry=iter++;				
       
  2011 	if (entry==NULL)
       
  2012 		User::Leave(KErrGeneral);
       
  2013 	result.Set(entry->iResultPtr.Right(2)); // Get the mean rate.
       
  2014 	if(result[0] == '-')
       
  2015 		result.Set(entry->iResultPtr.Right(1));
       
  2016 	entry=iter++;			
       
  2017 	if (entry!=NULL) // There could be another number like (0-18,31) where we want the 31.
       
  2018 		{
       
  2019 		TPtrC8 maxMean(entry->iResultPtr);
       
  2020 		TLex8 lexMaxMean(maxMean);
       
  2021 		if(lexMaxMean.Val(value) == KErrNone)
       
  2022 			{
       
  2023 			result.Set(entry->iResultPtr);
       
  2024 			}
       
  2025 		}
       
  2026 	lex = result;
       
  2027 	value = 0;
       
  2028 	(void)User::LeaveIfError(lex.Val(value));
       
  2029 	switch(value)
       
  2030 		{
       
  2031 		case 1:
       
  2032 			valueToSet = RPacketQoS::EMeanThroughput100;
       
  2033 			break;
       
  2034 		case 2:
       
  2035 			valueToSet = RPacketQoS::EMeanThroughput200;
       
  2036 			break;
       
  2037 		case 3:
       
  2038 			valueToSet = RPacketQoS::EMeanThroughput500;
       
  2039 			break;
       
  2040 		case 4:
       
  2041 			valueToSet = RPacketQoS::EMeanThroughput1000;
       
  2042 			break;
       
  2043 		case 5:
       
  2044 			valueToSet = RPacketQoS::EMeanThroughput2000;
       
  2045 			break;	
       
  2046 		case 6:
       
  2047 			valueToSet = RPacketQoS::EMeanThroughput5000;
       
  2048 			break;
       
  2049 		case 7:
       
  2050 			valueToSet = RPacketQoS::EMeanThroughput10000;
       
  2051 			break;
       
  2052 		case 8:
       
  2053 			valueToSet = RPacketQoS::EMeanThroughput20000;
       
  2054 			break;
       
  2055 		case 9:
       
  2056 			valueToSet = RPacketQoS::EMeanThroughput50000;
       
  2057 			break;
       
  2058 		case 10:
       
  2059 			valueToSet = RPacketQoS::EMeanThroughput100000;
       
  2060 			break;
       
  2061 		case 11:
       
  2062 			valueToSet = RPacketQoS::EMeanThroughput200000;
       
  2063 			break;
       
  2064 		case 12:
       
  2065 			valueToSet = RPacketQoS::EMeanThroughput500000;
       
  2066 			break;
       
  2067 		case 13:
       
  2068 			valueToSet = RPacketQoS::EMeanThroughput1000000;
       
  2069 			break;
       
  2070 		case 14:
       
  2071 			valueToSet = RPacketQoS::EMeanThroughput2000000;
       
  2072 			break;
       
  2073 		case 15:
       
  2074 			valueToSet = RPacketQoS::EMeanThroughput5000000;
       
  2075 			break;
       
  2076 		case 16:
       
  2077 			valueToSet = RPacketQoS::EMeanThroughput10000000;
       
  2078 			break;
       
  2079 		case 17:
       
  2080 			valueToSet = RPacketQoS::EMeanThroughput20000000;
       
  2081 			break;
       
  2082 		case 18:
       
  2083 			valueToSet = RPacketQoS::EMeanThroughput50000000;
       
  2084 			break;
       
  2085 		default:			// This intentionally catches case 0 and case 31
       
  2086 			valueToSet = RPacketQoS::EUnspecifiedMeanThroughput;
       
  2087 			break;
       
  2088 		}
       
  2089 	iPhoneGlobals->iStaticQoSCaps.iMean = valueToSet;
       
  2090 	CleanupStack::PopAndDestroy();
       
  2091 	}
       
  2092 
       
  2093 
       
  2094 
       
  2095 
       
  2096 void CATInit::ParseCNMIResponseL()
       
  2097 /**
       
  2098  * This function parses the response for +CNMI=? from the modem and attempts
       
  2099  * to set the iModemSupportsCMTIMode and iModemSupportsCMTMode of CPhoneGlobals.
       
  2100  * An example response is;
       
  2101  *  +CNMI: (0-2),(0-3),(0,2,3),(0-2),(0,1) 
       
  2102  * The ETSI specs names these +CNMI: <mode>,<mt>,<bm>,<ds>,<bfr>        
       
  2103  */
       
  2104 	{
       
  2105 	_LIT8(KHyphenCharacter,"-");
       
  2106 	_LIT8(KOpenBracketCharacter,"(");
       
  2107 	_LIT8(KCloseBracketCharacter,")");
       
  2108 
       
  2109 	ParseBufferLC(ETrue);		   // ETrue so that we are given the bracket list seperators
       
  2110 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  2111 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  2112 	CATParamListEntry* entry=iter++;
       
  2113 
       
  2114 	//
       
  2115 	// Validate we have received the starting '+CNMI:' string
       
  2116 	if((entry==NULL)||(entry->iResultPtr!=KCNMIResponseString))
       
  2117 		{
       
  2118 		LOCAL_LOGTEXT("ParseCNMIResponse","Cannot find +CNMI: string");
       
  2119 		User::Leave(KErrNotFound);
       
  2120 		}
       
  2121 
       
  2122 	//
       
  2123 	// Skip over the <mode> parameter
       
  2124 
       
  2125 	// Find the opening bracket
       
  2126 	while(entry && entry->iResultPtr.Compare(KOpenBracketCharacter))
       
  2127 		entry=iter++;
       
  2128 	if(!entry)
       
  2129 		{
       
  2130 		LOCAL_LOGTEXT("ParseCNMIResponse","Failed parsing <mode> parameter");
       
  2131 		User::Leave(KErrNotFound);
       
  2132 		}
       
  2133 	
       
  2134 	// Find the closing bracket
       
  2135 	while(entry && entry->iResultPtr.Compare(KCloseBracketCharacter))
       
  2136 		entry=iter++;
       
  2137 	if(!entry)
       
  2138 		{
       
  2139 		LOCAL_LOGTEXT("ParseCNMIResponse","Failed parsing <mode> parameter");
       
  2140 		User::Leave(KErrNotFound);
       
  2141 		}
       
  2142 
       
  2143 
       
  2144 	//
       
  2145 	// Parse the <mt> parameter
       
  2146 
       
  2147 	// Find the opening bracket
       
  2148 	while(entry && entry->iResultPtr.Compare(KOpenBracketCharacter))
       
  2149 		entry=iter++;
       
  2150 	if(!entry)
       
  2151 		{
       
  2152 		LOCAL_LOGTEXT("ParseCNMIResponse","Failed parsing <mode> parameter");
       
  2153 		User::Leave(KErrNotFound);
       
  2154 		}
       
  2155 
       
  2156 	// Process the parameter values upto the closing bracket
       
  2157 	entry=iter++;
       
  2158 	while(entry && entry->iResultPtr.Compare(KCloseBracketCharacter))
       
  2159 		{
       
  2160 		//
       
  2161 		// Check if parameter is a range (for example '0-3')
       
  2162 		if(entry->iResultPtr.Find(KHyphenCharacter)>KErrNone)
       
  2163 			{
       
  2164 			//
       
  2165 			// Parameter contains a '-' character so it is a range of values
       
  2166 
       
  2167 			// Get lower & higer values
       
  2168 			TUint8 lowVal;
       
  2169 			TUint8 highVal;
       
  2170 			TLex8 lexRange;
       
  2171 			const TInt rangeCharPos=entry->iResultPtr.Find(KHyphenCharacter);
       
  2172 			lexRange=entry->iResultPtr.Left(rangeCharPos);
       
  2173 			(void)User::LeaveIfError(lexRange.Val(lowVal,EDecimal));
       
  2174 			lexRange=entry->iResultPtr.Mid(rangeCharPos+1);
       
  2175 			(void)User::LeaveIfError(lexRange.Val(highVal,EDecimal));
       
  2176 
       
  2177 			if(lowVal<=1 && highVal>=1) // 1 & 2 are defined in the ESTI spec for the phone to support CMTI mode
       
  2178 				iPhoneGlobals->iModemSupportsCMTIMode=ETrue;
       
  2179 			if(lowVal<=2 && highVal>=2) // 1 & 2 are defined in the ESTI spec for the phone to support CMTI mode
       
  2180 				iPhoneGlobals->iModemSupportsCMTIMode=ETrue;
       
  2181 			if(lowVal<=3 && highVal>=3) // 3 is defined in the ESTI spec for the phone to support CMT mode
       
  2182 				iPhoneGlobals->iModemSupportsCMTMode=ETrue;
       
  2183 			}
       
  2184 		else
       
  2185 			{
       
  2186 			//
       
  2187 			// String does not contain '-' character so it must be just a single value
       
  2188 			const TInt val(CATParamListEntry::EntryValL(entry));
       
  2189 			if(val==1)		// 1 & 2 are defined in the ESTI spec for the phone to support CMTI mode
       
  2190 				iPhoneGlobals->iModemSupportsCMTIMode=ETrue;
       
  2191 			if(val==2)		// 1 & 2 are defined in the ESTI spec for the phone to support CMTI mode
       
  2192 				iPhoneGlobals->iModemSupportsCMTIMode=ETrue;
       
  2193 			if(val==3)		// 3 is defined in the ESTI spec for the phone to support CMT mode
       
  2194 				iPhoneGlobals->iModemSupportsCMTMode=ETrue;
       
  2195 			}
       
  2196 		entry=iter++;
       
  2197 		}
       
  2198 
       
  2199 	if(!entry)
       
  2200 		{
       
  2201 		LOCAL_LOGTEXT("ParseCNMIResponse","Failed parsing <mode> parameter");
       
  2202 		User::Leave(KErrNotFound);
       
  2203 		}
       
  2204 
       
  2205 	//
       
  2206 	// Skip all other parameters as we are not, currently, interested in them
       
  2207 	// We've fisnihed the parse.
       
  2208 	CleanupStack::PopAndDestroy();		// ParseBufferLC object
       
  2209 	}
       
  2210 	
       
  2211 
       
  2212 void CATInit::ParseCGATTResponseL()
       
  2213 	{
       
  2214 	iPhoneGlobals->iGprsStatus = RPacketService::EStatusUnattached;
       
  2215 	ParseBufferLC();
       
  2216 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  2217 	CATParamListEntry* entry;
       
  2218 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  2219 	entry=iter++;				// +CGATT:
       
  2220 	if(entry==NULL)
       
  2221 		User::Leave(KErrGeneral);
       
  2222 	if (entry->iResultPtr.MatchF(KCGATTResponseString)!=0)
       
  2223 		User::Leave(KErrGeneral);
       
  2224 	entry=iter++;				
       
  2225 	if (entry==NULL)
       
  2226 		User::Leave(KErrGeneral);
       
  2227 
       
  2228 	TUint result=CATParamListEntry::EntryValL(entry);
       
  2229 	if(result == KZeroChar)
       
  2230 		iPhoneGlobals->iGprsStatus = RPacketService::EStatusUnattached;
       
  2231 	else if(result == KOneChar)
       
  2232 		iPhoneGlobals->iGprsStatus = RPacketService::EStatusAttached;
       
  2233 	CleanupStack::PopAndDestroy();
       
  2234 
       
  2235 	}
       
  2236 
       
  2237 void CATInit::Complete(TInt aError)
       
  2238 	{
       
  2239 	iIo->Cancel();
       
  2240 	iNoCarrierExpectString=NULL;
       
  2241 
       
  2242 	// The initialization may complete with a status of KErrCancel
       
  2243 	// even when it has not been explicitly cancelled
       
  2244 	// If the KErrCancel status propogates to etel, etel will panic because of the stray
       
  2245 	// cancel status (etel treats KErrCancel specially in that all KErrCancel completions
       
  2246 	// must be explicitly cancelled by the etel client)
       
  2247 	if (aError == KErrCancel)
       
  2248 		{
       
  2249 		// change status to avoid etel panic
       
  2250 		aError = KErrEtelInitialisationFailure;
       
  2251 		}
       
  2252 	iInitError = aError;
       
  2253 
       
  2254 	if (aError)
       
  2255 		{
       
  2256 		LOGTEXT(_L8("CATInit::Complete - EPhoneNotInitialised"));
       
  2257 		iPhoneGlobals->iPhoneStatus.iModemDetected = RPhone::EDetectedNotPresent;
       
  2258 		iPhoneGlobals->iNotificationStore->CheckNotification(iTelObject,EPhoneNotDetected);
       
  2259 		iPhoneGlobals->iNotificationStore->CompleteNotificationsWithError(aError);
       
  2260 
       
  2261 		TPhoneInitStatus currentInitStatus = iPhoneGlobals->iPhoneStatus.iInitStatus;
       
  2262 		SetToNotInitialised();
       
  2263 		if (iPendingCommand)
       
  2264 			{
       
  2265 			if (iCallInfo)
       
  2266 				{
       
  2267 				REINTERPRET_CAST(CCallHayes*,iPendingCommand->Owner())->SetToIdle();
       
  2268 				}
       
  2269 			if (currentInitStatus != EPhoneInitialiseCancelling)
       
  2270 				// if cancelling, ReqCompleted() will have been called already
       
  2271 				{
       
  2272 				iIo->RemoveExpectStrings(this); 
       
  2273 				iPendingCommand->Owner()->ReqCompleted(iReqHandle, aError);		
       
  2274 				iPendingCommand=NULL;
       
  2275 				}
       
  2276 			}
       
  2277 		else
       
  2278 			{
       
  2279 			if (iReqHandle==NULL)
       
  2280 				{	// if this is a CommPort error, CompleteNotificationsWithError will be
       
  2281 					// called in CATError too, with no effect. It is necessary here as the
       
  2282 					// error may be a timeout or an unexpected response.
       
  2283 				iInitJustCompleted = ETrue;
       
  2284 				iTelObject->FlowControlResume();	// Automatic or Notify-started
       
  2285 													// Init finished
       
  2286 				iInitJustCompleted = EFalse;
       
  2287 				}
       
  2288 			else
       
  2289 													// Controlled Init finished
       
  2290 				{
       
  2291 				STATIC_CAST(CPhoneHayes*,iTelObject)->ReqCompleted(iReqHandle,aError);
       
  2292 				}
       
  2293 			}
       
  2294 		}
       
  2295 	else
       
  2296 		{
       
  2297 		LOGTEXT(_L8("CATInit::Complete - EPhoneInitialised"));
       
  2298 		iIo->RemoveExpectStrings(this); 
       
  2299 		iOKExpectString=NULL;
       
  2300 		iErrorExpectString=NULL;
       
  2301 		iPhoneGlobals->iPhoneStatus.iInitStatus = EPhoneInitialised;
       
  2302 		if (iPendingCommand)
       
  2303 			{
       
  2304 			iPendingCommand->Start(iReqHandle,iParams);
       
  2305 			}
       
  2306 		else
       
  2307 			{
       
  2308 			if (iReqHandle==NULL)
       
  2309 				{
       
  2310 				iInitJustCompleted = ETrue;
       
  2311 				iTelObject->FlowControlResume();	// Automatic Init finished
       
  2312 				iInitJustCompleted = EFalse;
       
  2313 				}
       
  2314 			else
       
  2315 													// Controlled Init finished
       
  2316 				STATIC_CAST(CPhoneHayes*,iTelObject)->ReqCompleted(iReqHandle,KErrNone);
       
  2317 			}
       
  2318 		}
       
  2319 	}
       
  2320 
       
  2321 TBool CATInit::JustInitialised(TInt& aError) const
       
  2322 	{
       
  2323 	aError = iInitError;
       
  2324 	return iInitJustCompleted;
       
  2325 	}
       
  2326 
       
  2327 //
       
  2328 
       
  2329 //
       
  2330 // Quick Initialise Class
       
  2331 // Called when TSY recovers Comm Port
       
  2332 // Puts modem in a known state. With no errors, ends in On Line Data state
       
  2333 // Otherwise sets iInitStatus to uninitialised, so full init will be performed with next command.
       
  2334 // If receive a RING or a NO CARRIER, this is conclusive proof that modem is in off-line mode
       
  2335 // so the quick initialisation should stop immediately
       
  2336 //
       
  2337 
       
  2338 CATQuickInit* CATQuickInit::NewL(CATIO* aIo,CTelObject* aTelObject,CPhoneGlobals* aPhoneGlobals)
       
  2339 	{
       
  2340 	return new(ELeave) CATQuickInit(aIo,aTelObject,aPhoneGlobals);
       
  2341 	}
       
  2342 
       
  2343 CATQuickInit::CATQuickInit(CATIO* aIo,CTelObject* aTelObject,CPhoneGlobals* aPhoneGlobals) :
       
  2344 							CATBase(aIo,aTelObject,aPhoneGlobals)
       
  2345 	{}
       
  2346 
       
  2347 CATQuickInit::~CATQuickInit()
       
  2348 	{
       
  2349 	iIo->RemoveExpectStrings(this);
       
  2350 	iIo->WriteAndTimerCancel(this);
       
  2351 	}
       
  2352 
       
  2353 void CATQuickInit::StartQuickInit()
       
  2354 //
       
  2355 //	Ensure port configuration is the same as before the data port was loaned
       
  2356 //
       
  2357 	{
       
  2358 	LOGTEXT(_L8("Starting Quick Initialisation Sequence"));
       
  2359 	
       
  2360 	// Change CPhoneGlobals::iPhoneStatus::iInitStatus so that we prevent
       
  2361 	// +CRINGs being processed while this CATQuickInit machine is running.
       
  2362 	iPhoneGlobals->iPhoneStatus.iInitStatus=EPhoneInitialising;
       
  2363 
       
  2364 	iIo->Cancel();
       
  2365 	TCommConfig aConfigPckg;
       
  2366 	TInt ret = iPhoneGlobals->iConfiguration->PortConfig(aConfigPckg,EConfigTypeQuickInit);
       
  2367 	if (ret==KErrNone)
       
  2368 		ret = iIo->ConfigurePort(aConfigPckg);
       
  2369 	if (ret)
       
  2370 		Complete(ret);
       
  2371 	else
       
  2372 		{
       
  2373 		LOGTEXT2(_L8("Comm signals after PortConfig : %x"),iIo->Signals());
       
  2374 
       
  2375 		// This expect string will always be active
       
  2376 		__ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral));
       
  2377 
       
  2378 		iRingExpectString = iIo->AddExpectString(this,KRingString);
       
  2379 		iNoCarrierExpectString = iIo->AddExpectString(this,KNoCarrierString);
       
  2380 
       
  2381 		TPtrC8 returnATCommand(KReturnATCommand);
       
  2382 		LOGTEXT2(_L8("No. bytes in of input buffer : %d"),iIo->GetSizeOfRxBuffer());
       
  2383 		Write(returnATCommand,1);
       
  2384 		iAttempt=1;
       
  2385 		iState=EWaitForATWrite;
       
  2386 		}
       
  2387 	}
       
  2388 #ifdef _DEBUG
       
  2389 void CATQuickInit::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
       
  2390 #else
       
  2391 void CATQuickInit::CompleteWithIOError(TEventSource /*aSource*/,TInt /*aStatus*/)
       
  2392 #endif
       
  2393 	{
       
  2394 	LOGTEXT2(_L8("CATQuickInit::GenericEventSignal received error status %d"),aStatus);
       
  2395 
       
  2396 	iIo->Cancel();
       
  2397 	if (iState==EWaitForDTRDropped)
       
  2398 		{
       
  2399 		// Make sure DTR is raised again
       
  2400 		iIo->RaiseDTR();
       
  2401 		}
       
  2402 
       
  2403 	iState = ENotInProgress;
       
  2404 
       
  2405 	// Set TSY so it will reinitialise
       
  2406 	STATIC_CAST(CCallHayes*,iTelObject)->SetToIdle();
       
  2407 	SetToNotInitialised();		
       
  2408 	iIo->Read();
       
  2409 	iTelObject->FlowControlResume();
       
  2410 	}
       
  2411 
       
  2412 void CATQuickInit::ValidateATHExpectStringL()
       
  2413 	{
       
  2414 	if(iIo->FoundChatString()==iErrorExpectString)
       
  2415 		{
       
  2416 		LOGTEXT(_L8("Modem returned ERROR in response to command"));
       
  2417 		User::Leave(KErrGeneral);
       
  2418 		}
       
  2419 	if(iIo->FoundChatString()==iNoCarrierExpectString)
       
  2420 		{
       
  2421 		LOGTEXT(_L8("Modem returned NO CARRIER in response to command"));
       
  2422 		User::Leave(KErrEtelNoCarrier);
       
  2423 		}
       
  2424 	if(iIo->FoundChatString()==iOKExpectString)
       
  2425 		return;
       
  2426 	LOGTEXT(_L8("Modem returned unexpected response to command"));
       
  2427 	User::Leave(KErrUnknown);
       
  2428 	}
       
  2429 
       
  2430 void CATQuickInit::CancelAndHangUp(TCallInfoTSY* aCallInfoTSY, CATHangUpData* aHangUpData)
       
  2431 //
       
  2432 //	If doing the quick initialisation sequence, cancel it and call hang up, otherwise just
       
  2433 //	hang up.
       
  2434 //
       
  2435 	{
       
  2436 	if (iState!=ENotInProgress)
       
  2437 		{
       
  2438 		LOGTEXT(_L8("Cancelling Quick Init"));
       
  2439 		iCallInfo = aCallInfoTSY;
       
  2440 		iHangUpData = aHangUpData;
       
  2441 		iState=ECancelling;
       
  2442 		}
       
  2443 	else
       
  2444 		{
       
  2445 		LOGTEXT(_L8("Calling Hang Up"));
       
  2446 		aHangUpData->ExecuteCommand(0,NULL,aCallInfoTSY);
       
  2447 		}
       
  2448 	}
       
  2449 
       
  2450 void CATQuickInit::EventSignal(TEventSource aSource)
       
  2451 	{
       
  2452 	LOGTEXT2(_L8("CATQuickInit::EventSignal iState=%d"),iState);
       
  2453 
       
  2454 	if((aSource==ETimeOutCompletion)
       
  2455 		&&(iState!=EWaitForATSilence)
       
  2456 		&&(iState!=EWaitForATEscapeOK)
       
  2457 		&&(iState!=EWaitForATOK)
       
  2458 		&&(iState!=EWaitForDTRDropped)
       
  2459 		&&(iState!=EWaitForDTRRaised)
       
  2460 		&&(iState!=ECancelling))
       
  2461 		{
       
  2462 		if (iState==EWaitForATWrite)	// the first write hasn't completed
       
  2463 			{
       
  2464 			iIo->Cancel();
       
  2465 			if (iAttempt <= 3)
       
  2466 				{
       
  2467 				TCommConfig aConfigPckg;
       
  2468 				TInt ret = iPhoneGlobals->iConfiguration->PortConfig(aConfigPckg,EConfigTypeDDBugWorkAroundStart);
       
  2469 				if (ret==KErrNone)
       
  2470 					ret = iIo->ConfigurePort(aConfigPckg);
       
  2471 				if (ret)
       
  2472 					{
       
  2473 					Complete(ret);
       
  2474 					return;
       
  2475 					}
       
  2476 				ret = iPhoneGlobals->iConfiguration->PortConfig(aConfigPckg,EConfigTypeDDBugWorkAroundEnd);
       
  2477 				if (ret==KErrNone)
       
  2478 					ret = iIo->ConfigurePort(aConfigPckg);
       
  2479 				if (ret)
       
  2480 					Complete(ret);
       
  2481 				else
       
  2482 					{
       
  2483 					TPtrC8 returnATCommand(KReturnATCommand);
       
  2484 					Write(returnATCommand,1);
       
  2485 					iAttempt++;
       
  2486 					}
       
  2487 				return;
       
  2488 				}
       
  2489 			}
       
  2490 		LOGTEXT(_L8("Error during Quick Initialisation Sequence"));
       
  2491 		RemoveQuickInitExpectStrings();
       
  2492 		Complete(KErrEtelInitialisationFailure);
       
  2493 		return;
       
  2494 		}
       
  2495 
       
  2496 	if (aSource==EReadCompletion)
       
  2497 		{
       
  2498 		CCommChatString* foundString = iIo->FoundChatString();
       
  2499 		if (foundString==iRingExpectString || foundString==iNoCarrierExpectString)
       
  2500 			{
       
  2501 			LOGTEXT(_L8("CATQuickInit::EventSignal Phone mode is off-line"));
       
  2502 			RemoveQuickInitExpectStrings();
       
  2503 			STATIC_CAST(CCallHayes*,iTelObject)->SetToIdle();
       
  2504 			iIo->Cancel();
       
  2505 			iIo->DropDtr();
       
  2506 			iIo->SetTimeOut(this,KOneSecondPause / 2);
       
  2507 			iState = EWaitForDTRDropped;
       
  2508 			return;
       
  2509 			}
       
  2510 		}	
       
  2511 
       
  2512 	switch(iState)
       
  2513 		{
       
  2514 	case ENotInProgress:
       
  2515 		break;
       
  2516 	case EWaitForATSilence:
       
  2517 		{
       
  2518 		__ASSERT_ALWAYS(aSource==ETimeOutCompletion,Panic(EATCommand_IllegalCompletionWaitExpected));
       
  2519 		if (!(iIo->ReadPending()))
       
  2520 			iIo->Read();
       
  2521 		TBuf8<KCommsDbSvrMaxFieldLength> escapeChar;
       
  2522 		TInt ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameEscapeCharacter),escapeChar);
       
  2523 		if (ret)
       
  2524 			{
       
  2525 			Complete(ret);
       
  2526 			}
       
  2527 		iTxBuffer.Format(_L8("%S%S%S"),&escapeChar,&escapeChar,&escapeChar);
       
  2528 		iIo->Write(this,iTxBuffer);
       
  2529 		iIo->SetTimeOut(this,KOneSecondPause);
       
  2530 		iState=EWaitForEscapeWriteCompletion;
       
  2531 		break;
       
  2532 		}
       
  2533 
       
  2534 	case EWaitForEscapeWriteCompletion:
       
  2535 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWaitExpected));
       
  2536 		if (!iOKExpectString)
       
  2537 			iOKExpectString = iIo->AddExpectString(this,KOkString);
       
  2538 		iIo->SetTimeOut(this,5*KOneSecondPause);
       
  2539 		iState=EWaitForATEscapeOK;
       
  2540 		break;
       
  2541 
       
  2542 	case EWaitForATEscapeOK:
       
  2543 		// Can legitimately be TimeOut or ReadCompletion
       
  2544 		__ASSERT_ALWAYS(aSource!=EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteNotExpected));
       
  2545 		{
       
  2546 		if (aSource==EReadCompletion)
       
  2547 			{
       
  2548 			LOGTEXT(_L8("Should now be in On-line Command mode"));
       
  2549 			}
       
  2550 		iIo->RemoveExpectString(iOKExpectString);
       
  2551 		iOKExpectString = NULL;
       
  2552 		iIo->WriteAndTimerCancel(this);
       
  2553 		TPtrC8 ATCommand(KAT2Command);
       
  2554 		Write(ATCommand,1);
       
  2555 		iState=EWaitForATWrite;
       
  2556 		}
       
  2557 		break;
       
  2558 
       
  2559 	case EWaitForATWrite:
       
  2560 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  2561 		if (!iOKExpectString)
       
  2562 			iOKExpectString = iIo->AddExpectString(this,KOkString);
       
  2563 		LOGTEXT2(_L8("Comm signals after first write : %x"),iIo->Signals());
       
  2564 		iIo->SetTimeOut(this,2*KOneSecondPause);
       
  2565 		if (!(iIo->ReadPending()))
       
  2566 			iIo->Read();
       
  2567 		iState=EWaitForATOK;
       
  2568 		break;
       
  2569 
       
  2570 	case EWaitForATOK:
       
  2571 		// Can legitimately be TimeOut or ReadCompletion
       
  2572 		__ASSERT_ALWAYS(aSource!=EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteNotExpected));
       
  2573 		LOGTEXT2(_L8("Comm signals after first read/timeout : %x"),iIo->Signals());
       
  2574 		if (aSource==EReadCompletion)
       
  2575 			{
       
  2576 			TRAPD(ret,ValidateATHExpectStringL());
       
  2577 			if (ret==KErrEtelNoCarrier)
       
  2578 				{
       
  2579 				STATIC_CAST(CCallHayes*,iTelObject)->SetToIdle();
       
  2580 				Complete(KErrNone);
       
  2581 				return;
       
  2582 				}
       
  2583 			}
       
  2584 		iIo->RemoveExpectString(iOKExpectString);
       
  2585 		iOKExpectString = NULL;
       
  2586 		iIo->WriteAndTimerCancel(this);
       
  2587 		if (aSource==ETimeOutCompletion)
       
  2588 			{
       
  2589 			if (iAttempt==1)
       
  2590 				{
       
  2591 				iAttempt++;
       
  2592 				iState = EWaitForATSilence;
       
  2593 				EventSignal(aSource);			// Attempt escape sequence
       
  2594 				}
       
  2595 			else
       
  2596 				{
       
  2597 				LOGTEXT(_L8("Should now be either not connected or modem is not responding for some reason"));
       
  2598 				Complete(KErrEtelInitialisationFailure);
       
  2599 				}
       
  2600 			}
       
  2601 		else
       
  2602 			{
       
  2603 			TBuf8<KCommsDbSvrMaxFieldLength> toOnLineDataCommand;
       
  2604 			TInt ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameOnLine),toOnLineDataCommand);
       
  2605 			if (ret)
       
  2606 				{
       
  2607 				Complete(ret);
       
  2608 				}
       
  2609 			iTxBuffer.Format(KATAndStringFormatString,&toOnLineDataCommand);
       
  2610 			iIo->Write(this,iTxBuffer);
       
  2611 			iIo->SetTimeOut(this,KOneSecondPause);
       
  2612 			iState=EATOWaitForWriteComplete;
       
  2613 			}
       
  2614 		break;
       
  2615 
       
  2616 	case EATOWaitForWriteComplete:
       
  2617 		{
       
  2618 		__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
  2619 		if (!iConnectExpectString)
       
  2620 			{
       
  2621 			TInt ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameConnect),iConnectString);
       
  2622 			if (ret)
       
  2623 				{
       
  2624 				Complete(ret);
       
  2625 				}
       
  2626 			AppendWildCardChar(iConnectString);
       
  2627 			iConnectExpectString=iIo->AddExpectString(this,iConnectString);
       
  2628 			}
       
  2629 		if (!iErrorExpectString)
       
  2630 			iErrorExpectString=iIo->AddExpectString(this,KErrorString);
       
  2631 		iIo->SetTimeOut(this,2*KOneSecondPause);
       
  2632 		iState=EWaitForATOOK;
       
  2633 		}
       
  2634 		break;
       
  2635 
       
  2636 
       
  2637 	case EWaitForATOOK:
       
  2638 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
  2639 			{
       
  2640 			if(iIo->FoundChatString()==iErrorExpectString)
       
  2641 				{
       
  2642 				LOGTEXT(_L8("Should now be in Off-line mode"));
       
  2643 				STATIC_CAST(CCallHayes*,iTelObject)->SetToIdle();
       
  2644 				}
       
  2645 			if(iIo->FoundChatString()==iConnectExpectString)
       
  2646 				{
       
  2647 				LOGTEXT(_L8("Should now be in On-line data mode"));
       
  2648 				iPhoneGlobals->iPhoneStatus.iMode = RPhone::EModeOnlineData;
       
  2649 				}
       
  2650 			Complete(KErrNone);
       
  2651 			}
       
  2652 		break;
       
  2653 
       
  2654 	case EWaitForDTRDropped:	// necessary to lower and raise DTR if the link has been lost,
       
  2655 								// otherwise modem may be in a strange "non-answering" mood.
       
  2656 		__ASSERT_ALWAYS(aSource==ETimeOutCompletion,Panic(EATCommand_IllegalCompletionWaitExpected));
       
  2657 		iIo->Cancel();
       
  2658 		iIo->RaiseDTR();
       
  2659 		iIo->SetTimeOut(this,KOneSecondPause);
       
  2660 		iState = EWaitForDTRRaised;
       
  2661 		break;
       
  2662 
       
  2663 	case EWaitForDTRRaised:
       
  2664 		__ASSERT_ALWAYS(aSource==ETimeOutCompletion,Panic(EATCommand_IllegalCompletionWaitExpected));
       
  2665 		Complete(KErrNone);
       
  2666 		break;
       
  2667 
       
  2668 	case ECancelling:
       
  2669 		if (aSource==EWriteCompletion)
       
  2670 			{
       
  2671 			if (!iOKExpectString)
       
  2672 				iOKExpectString = iIo->AddExpectString(this,KOkString);
       
  2673 			if (!iConnectExpectString)
       
  2674 				{
       
  2675 				TInt ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameConnect),iConnectString);
       
  2676 				if (ret)
       
  2677 					{
       
  2678 					Complete(ret);
       
  2679 					}
       
  2680 				AppendWildCardChar(iConnectString);
       
  2681 				iConnectExpectString=iIo->AddExpectString(this,iConnectString);
       
  2682 				}
       
  2683 			if (!iErrorExpectString)
       
  2684 				iErrorExpectString=iIo->AddExpectString(this,KErrorString);
       
  2685 			iIo->SetTimeOut(this,KOneSecondPause);
       
  2686 			}
       
  2687 		else
       
  2688 			{
       
  2689 			RemoveQuickInitExpectStrings();
       
  2690 			iState=ENotInProgress;
       
  2691 			iTelObject->FlowControlResume();		// Defect fix for MPO-4ZECUN
       
  2692 			iHangUpData->ExecuteCommand(0,NULL,iCallInfo);
       
  2693 			iHangUpData=NULL;
       
  2694 			iCallInfo=NULL;
       
  2695 			break;
       
  2696 			}
       
  2697 		}
       
  2698 	}
       
  2699 
       
  2700 void CATQuickInit::RemoveQuickInitExpectStrings()
       
  2701 	{
       
  2702 	if (iOKExpectString)
       
  2703 		{
       
  2704 		iIo->RemoveExpectString(iOKExpectString);
       
  2705 		iOKExpectString=NULL;
       
  2706 		}
       
  2707 	if (iErrorExpectString)
       
  2708 		{
       
  2709 		iIo->RemoveExpectString(iErrorExpectString);
       
  2710 		iErrorExpectString=NULL;
       
  2711 		}
       
  2712 	if (iConnectExpectString)
       
  2713 		{
       
  2714 		iIo->RemoveExpectString(iConnectExpectString);
       
  2715 		iConnectExpectString=NULL;
       
  2716 		}
       
  2717 	if (iNoCarrierExpectString)
       
  2718 		{
       
  2719 		iIo->RemoveExpectString(iNoCarrierExpectString);
       
  2720 		iNoCarrierExpectString=NULL;
       
  2721 		}
       
  2722 	if (iRingExpectString)
       
  2723 		{
       
  2724 		iIo->RemoveExpectString(iRingExpectString);
       
  2725 		iRingExpectString=NULL;
       
  2726 		}
       
  2727 	}
       
  2728 
       
  2729 void CATQuickInit::Complete(TInt aError)
       
  2730 	{
       
  2731 	LOGTEXT2(_L8("CATQuickInit::Completed with error code %d"),aError);
       
  2732 	LOGTEXT2(_L8("Comm signals : %x"),iIo->Signals());
       
  2733 	iState = ENotInProgress;
       
  2734 	RemoveQuickInitExpectStrings();
       
  2735 	iIo->RemoveExpectStrings(this); // Make sure the error string is removed too
       
  2736 	iIo->Cancel();
       
  2737 	if (aError)
       
  2738 		{
       
  2739 		STATIC_CAST(CCallHayes*,iTelObject)->SetToIdle();
       
  2740 		SetToNotInitialised();		
       
  2741 		}
       
  2742 	else
       
  2743 		{	
       
  2744 		TCommConfig aConfigPckg;
       
  2745 		if (iPhoneGlobals->iPhoneStatus.iMode == RPhone::EModeOnlineData)
       
  2746 			{
       
  2747 			TInt ret = iPhoneGlobals->iConfiguration->PortConfig(aConfigPckg,EConfigTypeConnect);
       
  2748 			if (ret==KErrNone)
       
  2749 				ret = iIo->ConfigurePort(aConfigPckg);
       
  2750 			if (ret)
       
  2751 				{
       
  2752 				Complete(ret);
       
  2753 				return;
       
  2754 				}
       
  2755 			REINTERPRET_CAST(CCallHayes*,iTelObject)->iWaitForNoCarrier->StartWait();
       
  2756 			}
       
  2757 		iPhoneGlobals->iPhoneStatus.iInitStatus = EPhoneInitialised;
       
  2758 		}
       
  2759 	iIo->Read();
       
  2760 	iTelObject->FlowControlResume();
       
  2761 	}
       
  2762 
       
  2763 TInt CATInit::GetIdentityResponse()
       
  2764 /*
       
  2765  * This is the non leaving version of GetIdentityResponseL.
       
  2766  * Having this non-leaving version means that one TRAP harness can replace 
       
  2767  * what were 4.
       
  2768  */
       
  2769  	{
       
  2770 	TRAPD(ret,DoGetIdentityResponseL());
       
  2771 	return ret;
       
  2772 	}
       
  2773 
       
  2774 void CATInit::DoGetIdentityResponseL()
       
  2775 	{
       
  2776 	ParseBufferLC();
       
  2777 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  2778 	CATParamListEntry* entry;
       
  2779 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  2780 
       
  2781 	iMoreInfoFlag = EFalse;
       
  2782 	LOGTEXT(_L8("MMTsy:\tCATBasicGsmPhoneId:\tGrabbing +CGxx results from ME"));
       
  2783 	while (entry = iter++, entry != NULL)
       
  2784 		{
       
  2785 		TPtrC8 result = entry->iResultPtr;
       
  2786 		if (iCGMIFlag)
       
  2787 			{
       
  2788 			if (CheckResponse(result))
       
  2789 				LOGTEXT(_L8("MMTsy:\tCATBasicPhoneId:\tModem responded with +CGMI at the front!"));
       
  2790 			else
       
  2791 				{
       
  2792 				if  (iMoreInfoFlag)
       
  2793 					{
       
  2794 					TBuf<RMobilePhone::KPhoneManufacturerIdSize> aData;
       
  2795 					aData.Zero();
       
  2796 					TInt remainingBufferSize = RMobilePhone::KPhoneManufacturerIdSize - iPhoneGlobals->iPhoneId.iManufacturer.Length() - 1;
       
  2797 					//check not going to over flow buffer (including room for space character)
       
  2798 					if(remainingBufferSize > 0)
       
  2799 						{
       
  2800 						if(result.Length() > remainingBufferSize)
       
  2801 							{
       
  2802 							aData.Copy(result.Mid(0,remainingBufferSize));
       
  2803 							}
       
  2804 						else
       
  2805 							{
       
  2806 							aData.Copy(result);
       
  2807 							}
       
  2808 						iPhoneGlobals->iPhoneId.iManufacturer.Append(KSpaceSeparator);
       
  2809 						iPhoneGlobals->iPhoneId.iManufacturer.Append(aData);
       
  2810 						}
       
  2811 					}
       
  2812 				else
       
  2813 					{
       
  2814 					TBuf<RMobilePhone::KPhoneManufacturerIdSize> aData;
       
  2815 					aData.Zero();
       
  2816 					if(result.Length() > RMobilePhone::KPhoneManufacturerIdSize)
       
  2817 						{
       
  2818 						aData.Copy(result.Mid(0,RMobilePhone::KPhoneManufacturerIdSize));
       
  2819 						}
       
  2820 					else
       
  2821 						{
       
  2822 						aData.Copy(result);
       
  2823 						}
       
  2824 					iPhoneGlobals->iPhoneId.iManufacturer = aData;
       
  2825 					iMoreInfoFlag = ETrue;
       
  2826 					}
       
  2827 				}
       
  2828 			}
       
  2829 		else if (iCGMMFlag)
       
  2830 			{
       
  2831 			if (CheckResponse(result))
       
  2832 				LOGTEXT(_L8("MMTsy:\tCATBasicPhoneId:\tModem responded with +CGMI at the front!"));
       
  2833 			else
       
  2834 				{
       
  2835 				if  (iMoreInfoFlag)
       
  2836 					{
       
  2837 					TBuf<RMobilePhone::KPhoneModelIdSize> aData;
       
  2838 					aData.Zero();
       
  2839 					TInt remainingBufferSize =  RMobilePhone::KPhoneModelIdSize - iPhoneGlobals->iPhoneId.iModel.Length() - 1;
       
  2840 					//check not going to over flow buffer (including room for space character)
       
  2841 					if(remainingBufferSize > 0)
       
  2842 						{
       
  2843 						if(result.Length() > remainingBufferSize)
       
  2844 							{
       
  2845 							aData.Copy(result.Mid(0,remainingBufferSize));
       
  2846 							}
       
  2847 						else
       
  2848 							{
       
  2849 							aData.Copy(result);
       
  2850 							}
       
  2851 						iPhoneGlobals->iPhoneId.iModel.Append(KSpaceSeparator);
       
  2852 						iPhoneGlobals->iPhoneId.iModel.Append(aData);
       
  2853 	   					}
       
  2854 					}
       
  2855 				else
       
  2856 					{
       
  2857 					TBuf<RMobilePhone::KPhoneModelIdSize> aData;
       
  2858 					aData.Zero();
       
  2859 					if(result.Length() > RMobilePhone::KPhoneModelIdSize)
       
  2860 						{
       
  2861 						aData.Copy(result.Mid(0,RMobilePhone::KPhoneModelIdSize));
       
  2862 						}
       
  2863 					else
       
  2864 						{
       
  2865 						aData.Copy(result);
       
  2866 						}
       
  2867 					iPhoneGlobals->iPhoneId.iModel = aData;
       
  2868 					iMoreInfoFlag = ETrue;
       
  2869 					}
       
  2870 				}
       
  2871 			}
       
  2872 		else if (iCGMRFlag)
       
  2873 			{
       
  2874 			if (CheckResponse(result))
       
  2875 				LOGTEXT(_L8("MMTsy:\tCATBasicPhoneId:\tModem responded with +CGMI at the front!"));
       
  2876 			else
       
  2877 				{
       
  2878 				if  (iMoreInfoFlag)
       
  2879 					{
       
  2880 					TBuf<RMobilePhone::KPhoneRevisionIdSize> aData;
       
  2881 					aData.Zero();
       
  2882 					TInt remainingBufferSize =  RMobilePhone::KPhoneRevisionIdSize - iPhoneGlobals->iPhoneId.iRevision.Length() - 1;
       
  2883 					//check not going to over flow buffer (including room for space character)
       
  2884 					if(remainingBufferSize > 0)
       
  2885 						{
       
  2886 						if(result.Length() > remainingBufferSize)
       
  2887 							{
       
  2888 							aData.Copy(result.Mid(0,remainingBufferSize));
       
  2889 							}
       
  2890 						else
       
  2891 							{
       
  2892 							aData.Copy(result);
       
  2893 							}
       
  2894 						iPhoneGlobals->iPhoneId.iRevision.Append(KSpaceSeparator);
       
  2895 						iPhoneGlobals->iPhoneId.iRevision.Append(aData);
       
  2896 						}
       
  2897 					}
       
  2898 				else
       
  2899 					{
       
  2900 					TBuf<RMobilePhone::KPhoneRevisionIdSize> aData;
       
  2901 					aData.Zero();
       
  2902 					if(result.Length() > RMobilePhone::KPhoneRevisionIdSize)
       
  2903 						{
       
  2904 						aData.Copy(result.Mid(0,RMobilePhone::KPhoneRevisionIdSize));
       
  2905 						}
       
  2906 					else
       
  2907 						{
       
  2908 						aData.Copy(result);
       
  2909 						}
       
  2910 					iPhoneGlobals->iPhoneId.iRevision = aData;
       
  2911 					iMoreInfoFlag = ETrue;
       
  2912 					}
       
  2913 				}
       
  2914 			}
       
  2915 		else if (iCGSNFlag)
       
  2916 			{
       
  2917 			if (CheckResponse(result))
       
  2918 				LOGTEXT(_L8("MMTsy:\tCATBasicPhoneId:\tModem responded with +CGMI at the front!"));
       
  2919 			else
       
  2920 				{
       
  2921 				if  (iMoreInfoFlag)
       
  2922 					{
       
  2923 					TBuf<RMobilePhone::KPhoneSerialNumberSize> aData;
       
  2924 					aData.Zero();
       
  2925 					TInt remainingBufferSize = RMobilePhone::KPhoneSerialNumberSize - iPhoneGlobals->iPhoneId.iSerialNumber.Length() - 1;
       
  2926 					//check not going to over flow buffer (including room for space character)
       
  2927 					if(remainingBufferSize > 0)
       
  2928 						{
       
  2929 						if(result.Length() > remainingBufferSize)
       
  2930 							{
       
  2931 							aData.Copy(result.Mid(0,remainingBufferSize));
       
  2932 							}
       
  2933 						else
       
  2934 							{
       
  2935 							aData.Copy(result);
       
  2936 							}
       
  2937 						iPhoneGlobals->iPhoneId.iSerialNumber.Append(KSpaceSeparator);
       
  2938 						iPhoneGlobals->iPhoneId.iSerialNumber.Append(aData);
       
  2939 						}
       
  2940 					}
       
  2941 				else
       
  2942 					{
       
  2943 					TBuf<RMobilePhone::KPhoneSerialNumberSize> aData;
       
  2944 					aData.Zero();
       
  2945 					if(result.Length() > RMobilePhone::KPhoneSerialNumberSize)
       
  2946 						{
       
  2947 						aData.Copy(result.Mid(0,RMobilePhone::KPhoneSerialNumberSize));
       
  2948 						}
       
  2949 					else
       
  2950 						{
       
  2951 						aData.Copy(result);
       
  2952 						}
       
  2953 					iPhoneGlobals->iPhoneId.iSerialNumber = aData;
       
  2954 					iMoreInfoFlag = ETrue;
       
  2955 					}
       
  2956 				}
       
  2957 			}
       
  2958 		entry->Deque();
       
  2959 		delete entry;
       
  2960 		}//while
       
  2961 	iMoreInfoFlag = EFalse;
       
  2962 	entry = NULL;
       
  2963 	CleanupStack::PopAndDestroy();
       
  2964 	}
       
  2965 
       
  2966 TBool CATInit::CheckResponse(TPtrC8 aResult)
       
  2967 	{
       
  2968 	if ((aResult == KCGMIResponseString) || (aResult == KCGMMResponseString)
       
  2969 	 || (aResult == KCGMRResponseString) || (aResult == KCGSNResponseString))
       
  2970 	 return ETrue;
       
  2971 	else
       
  2972 		return EFalse;
       
  2973 	}
       
  2974 
       
  2975 
       
  2976 void CATInit::CheckCMGFResponseL()
       
  2977 //
       
  2978 // Parse the response to the "AT+CMGF=?" command.
       
  2979 // Response should be of the form "+CMGF: xxx" where xxx should be an integer.
       
  2980 //
       
  2981 	{
       
  2982 	ParseBufferLC();						 // Grab the +CMGF:.... response 
       
  2983 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  2984 	CATParamListEntry* entry;
       
  2985 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  2986 
       
  2987 // The "+CMGF:" string should come first
       
  2988 	entry=iter++;
       
  2989 	if((!entry)||(entry->iResultPtr!=KCMGFResponseString))
       
  2990 		User::Leave(KErrNotFound);
       
  2991 	LOGTEXT(_L8("Found +CMGF String!"));
       
  2992 
       
  2993 // Now parse the list of capabilities supported and see if we can find PDU mode
       
  2994 	iPhoneGlobals->iSmsPduModeSupported=EFalse;
       
  2995 	while(entry)
       
  2996 		{
       
  2997 		entry=iter++;
       
  2998 		if(!entry)
       
  2999 			continue;
       
  3000 
       
  3001 		TInt value;
       
  3002 		TLex8 yyLex(entry->iResultPtr);
       
  3003 		(void)User::LeaveIfError(yyLex.Val(value));
       
  3004 
       
  3005 		if (value==0)
       
  3006 			{
       
  3007 			LOGTEXT(_L8("MMTsy:\tCATInit:\tPdu mode is supported."));
       
  3008 			iPhoneGlobals->iSmsPduModeSupported=ETrue;
       
  3009 			break;
       
  3010 			}
       
  3011 		}
       
  3012 
       
  3013 	CleanupStack::PopAndDestroy();
       
  3014 	}
       
  3015 
       
  3016 
       
  3017 
       
  3018 void CATInit::ParseCBSTResponseL()
       
  3019 /**
       
  3020  * This function parses the +CBST: response from the modem and stores the parsed values 
       
  3021  * in the clients iCallCaps structure.
       
  3022  *
       
  3023  * An example response string would be;
       
  3024  *   +CBST: (0-7,12,14-16,34,36,38,39,43,47-51,65,66,68,70,71,75,79-81),(0,2),(0-3)
       
  3025  */	
       
  3026 	{
       
  3027 	const TChar KComma=TChar(',');
       
  3028 	const TChar KOpenBracket=TChar('(');
       
  3029 	const TChar KCloseBracket=TChar(')');
       
  3030 	_LIT8(KRangeChar,"-");
       
  3031 
       
  3032 	LOGTEXT(_L8("CATInit::ParseResponseL "));
       
  3033 
       
  3034 	//
       
  3035 	// Initialise caps 
       
  3036 	iPhoneGlobals->iCallDataCaps.iSpeedCaps=0;
       
  3037 	iPhoneGlobals->iCallDataCaps.iProtocolCaps=0;
       
  3038 	iPhoneGlobals->iCallDataCaps.iServiceCaps=0;
       
  3039 	iPhoneGlobals->iCallDataCaps.iQoSCaps=0;
       
  3040 	iPhoneGlobals->iCallDataCaps.iHscsdSupport=EFalse;
       
  3041 	iPhoneGlobals->iCallDataCaps.iMClass=0;
       
  3042 	iPhoneGlobals->iCallDataCaps.iMaxRxTimeSlots=0;
       
  3043 	iPhoneGlobals->iCallDataCaps.iMaxTxTimeSlots=0;
       
  3044 	iPhoneGlobals->iCallDataCaps.iTotalRxTxTimeSlots=0;
       
  3045 	iPhoneGlobals->iCallDataCaps.iCodingCaps=0;
       
  3046 	iPhoneGlobals->iCallDataCaps.iAsymmetryCaps=0;
       
  3047 	iPhoneGlobals->iCallDataCaps.iUserInitUpgrade=EFalse;
       
  3048 	iPhoneGlobals->iCallDataCaps.iRLPVersionCaps=0;
       
  3049 	iPhoneGlobals->iCallDataCaps.iV42bisCaps=0;
       
  3050 
       
  3051 
       
  3052 	//
       
  3053 	// Count the number of <speed> list items (see ETSI 07.07)
       
  3054 	//
       
  3055 	TLex8 lex(iIo->Buffer());
       
  3056 	TChar c;
       
  3057 	TInt speedItems(0);
       
  3058 
       
  3059 	// Locate opening bracket
       
  3060 	while(lex.Get()!=KOpenBracket && !lex.Eos()) {/* Do nothing*/};
       
  3061 
       
  3062 	if(lex.Eos())
       
  3063 		{
       
  3064 		LOGTEXT(_L8("CATInit::ParseResponseL Failed to locate <speed> opening bracket"));
       
  3065 		User::Leave(KErrGeneral);
       
  3066 		}
       
  3067 
       
  3068 	// Count commas ',' upto the closing bracket
       
  3069 	while((c=lex.Get())!=KCloseBracket && !lex.Eos())
       
  3070 		{
       
  3071 		if(c==KComma)
       
  3072 			speedItems++;
       
  3073 		}
       
  3074 	if(lex.Eos())
       
  3075 		{
       
  3076 		LOGTEXT(_L8("CATInit::ParseResponseL Failed to locate <speed> closing bracket"));
       
  3077 		User::Leave(KErrGeneral);
       
  3078 		}
       
  3079 
       
  3080 	// Increment speedItems by 1 to make it denote the number of <speed> parameters
       
  3081 	++speedItems;
       
  3082 	LOGTEXT2(_L8("CATInit::ParseResponseL speedItems:%d"),speedItems);
       
  3083 
       
  3084 
       
  3085 	//
       
  3086 	// Count the number of <name> list items (see ETSI 07.07)
       
  3087 	//
       
  3088 	TInt nameItems(0);
       
  3089 
       
  3090 	// Locate opening bracket
       
  3091 	while(lex.Get()!=KOpenBracket && !lex.Eos()) {/*Do nothing*/};
       
  3092 	if(lex.Eos())
       
  3093 		{
       
  3094 		LOGTEXT(_L8("CATInit::ParseResponseL Failed to locate <name> opening bracket"));
       
  3095 		User::Leave(KErrGeneral);
       
  3096 		}
       
  3097 
       
  3098 	// Count commas ',' upto the closing bracket
       
  3099 	while((c=lex.Get())!=KCloseBracket && !lex.Eos())
       
  3100 		{
       
  3101 		if(c==KComma)
       
  3102 			nameItems++;
       
  3103 		}
       
  3104 	if(lex.Eos())
       
  3105 		{
       
  3106 		LOGTEXT(_L8("CATInit::ParseResponseL Failed to locate <name> closing bracket"));
       
  3107 		User::Leave(KErrGeneral);
       
  3108 		}
       
  3109 
       
  3110 	// Increment nameItems by 1 to make it denote the number of <speed> parameters
       
  3111 	++nameItems;
       
  3112 	LOGTEXT2(_L8("CATInit::ParseResponseL nameItems:%d"),nameItems);
       
  3113 
       
  3114 	//
       
  3115 	//
       
  3116 	// Count the number of <ce> list items (see ETSI 07.07)
       
  3117 	TInt ceItems(0);
       
  3118 
       
  3119 	// Locate opening bracket
       
  3120 	while(lex.Get()!=KOpenBracket && !lex.Eos()) {/*Do nothing*/};
       
  3121 	if(lex.Eos())
       
  3122 		{
       
  3123 		LOGTEXT(_L8("CATInit::ParseResponseL Failed to locate <ce> opening bracket"));
       
  3124 		User::Leave(KErrGeneral);
       
  3125 		}
       
  3126 
       
  3127 	// Count commas ',' upto the closing bracket
       
  3128 	while((c=lex.Get())!=KCloseBracket && !lex.Eos())
       
  3129 		{
       
  3130 		if(c==KComma)
       
  3131 			ceItems++;
       
  3132 		}
       
  3133 	if(lex.Eos())
       
  3134 		{
       
  3135 		LOGTEXT(_L8("CATInit::ParseResponseL Failed to locate <ce> closing bracket"));
       
  3136 		User::Leave(KErrGeneral);
       
  3137 		}
       
  3138 
       
  3139 	// Increment ceItems by 1 to make it denote the number of <speed> parameters
       
  3140 	++ceItems;
       
  3141 	LOGTEXT2(_L8("CATInit::ParseResponseL ceItems:%d"),ceItems);
       
  3142 
       
  3143 	ParseBufferLC();
       
  3144 	RemoveUnsolicitedStrings();    // Removes any unsolicited strings
       
  3145 	CATParamListEntry* entry;
       
  3146 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
  3147 
       
  3148 	// 
       
  3149 	// Validate that we received the +CBST: response
       
  3150 	entry=iter++;
       
  3151 	if( !entry || (entry->iResultPtr!=KCBSTResponseString) )
       
  3152 		{
       
  3153 		LOGTEXT(_L8("CATInit::ParseResponseL Failed to locate response string +CBST:"));
       
  3154 		User::Leave(KErrGeneral);
       
  3155 		}	
       
  3156 
       
  3157 	// 
       
  3158 	// Process the <speed> list
       
  3159 	TInt i;
       
  3160 	for(i=0;i<speedItems;++i)
       
  3161 		{
       
  3162 		entry=iter++;
       
  3163 		if(entry->iResultPtr.Find(KRangeChar)>KErrNone)
       
  3164 			{
       
  3165 			//
       
  3166 			// Parameter contains a '-' character so it is a range of values
       
  3167 
       
  3168 			// Get lower & higer values
       
  3169 			TUint8 lowVal;
       
  3170 			TUint8 highVal;
       
  3171 			TLex8 lexRange;
       
  3172 			const TInt rangeCharPos=entry->iResultPtr.Find(KRangeChar);
       
  3173 			lexRange=entry->iResultPtr.Left(rangeCharPos);
       
  3174 			(void)User::LeaveIfError(lexRange.Val(lowVal,EDecimal));
       
  3175 			lexRange=entry->iResultPtr.Mid(rangeCharPos+1);
       
  3176 			(void)User::LeaveIfError(lexRange.Val(highVal,EDecimal));
       
  3177 
       
  3178 			LOGTEXT3(_L8("CATInit::ParseResponseL <speed> low:%d high:%d"),lowVal,highVal);
       
  3179 			
       
  3180 			// Set values
       
  3181 			for(TUint8 i=lowVal;i<=highVal;++i)
       
  3182 				SetSpeedCaps(i,iPhoneGlobals->iCallDataCaps);
       
  3183 			}
       
  3184 		else
       
  3185 			{
       
  3186 			//
       
  3187 			// String does not contain '-' character so it must be just a single value
       
  3188 			const TInt val(CATParamListEntry::EntryValL(entry));
       
  3189 			SetSpeedCaps(val,iPhoneGlobals->iCallDataCaps);
       
  3190 			LOGTEXT2(_L8("CATInit::ParseResponseL <speed> val:%d"),val);
       
  3191 			}
       
  3192 		}
       
  3193 
       
  3194 
       
  3195 	//
       
  3196 	// Process the <name> list
       
  3197 	for(i=0;i<nameItems;++i)
       
  3198 		{
       
  3199 		entry=iter++;
       
  3200 		if(entry->iResultPtr.Find(KRangeChar)>KErrNone)
       
  3201 			{
       
  3202 			//
       
  3203 			// Parameter contains a '-' character so it is a range of values
       
  3204 
       
  3205 			// Get lower & higer values
       
  3206 			TUint8 lowVal;
       
  3207 			TUint8 highVal;
       
  3208 			TLex8 lexRange;
       
  3209 			const TInt rangeCharPos=entry->iResultPtr.Find(KRangeChar);
       
  3210 			lexRange=entry->iResultPtr.Left(rangeCharPos);
       
  3211 			(void)User::LeaveIfError(lexRange.Val(lowVal,EDecimal));
       
  3212 			lexRange=entry->iResultPtr.Mid(rangeCharPos+1);
       
  3213 			(void)User::LeaveIfError(lexRange.Val(highVal,EDecimal));
       
  3214 
       
  3215 			LOGTEXT3(_L8("CATInit::ParseResponseL <name> low:%d high:%d"),lowVal,highVal);
       
  3216 			
       
  3217 			// Set values
       
  3218 			for(TUint8 i=lowVal;i<=highVal;++i)
       
  3219 				SetNameCaps(i,iPhoneGlobals->iCallDataCaps);
       
  3220 			}
       
  3221 		else
       
  3222 			{
       
  3223 			//
       
  3224 			// String does not contain '-' character so it must be just a single value
       
  3225 			const TInt val(CATParamListEntry::EntryValL(entry));
       
  3226 			SetNameCaps(val,iPhoneGlobals->iCallDataCaps);
       
  3227 			LOGTEXT2(_L8("CATInit::ParseResponseL <name> val:%d"),val);
       
  3228 			}
       
  3229 		}
       
  3230 
       
  3231 	//
       
  3232 	// Process the <ce> list
       
  3233 	for(i=0;i<ceItems;++i)
       
  3234 		{
       
  3235 		entry=iter++;
       
  3236 		if(entry->iResultPtr.Find(KRangeChar)>KErrNone)
       
  3237 			{
       
  3238 			//
       
  3239 			// Parameter contains a '-' character so it is a range of values
       
  3240 
       
  3241 			// Get lower & higer values
       
  3242 			TUint8 lowVal;
       
  3243 			TUint8 highVal;
       
  3244 			TLex8 lexRange;
       
  3245 			const TInt rangeCharPos=entry->iResultPtr.Find(KRangeChar);
       
  3246 			lexRange=entry->iResultPtr.Left(rangeCharPos);
       
  3247 			(void)User::LeaveIfError(lexRange.Val(lowVal,EDecimal));
       
  3248 			lexRange=entry->iResultPtr.Mid(rangeCharPos+1);
       
  3249 			(void)User::LeaveIfError(lexRange.Val(highVal,EDecimal));
       
  3250 
       
  3251 			LOGTEXT3(_L8("CATInit::ParseResponseL <ce> low:%d high:%d"),lowVal,highVal);
       
  3252 			
       
  3253 			// Set values
       
  3254 			for(TUint8 i=lowVal;i<=highVal;++i)
       
  3255 				SetCECaps(i,iPhoneGlobals->iCallDataCaps);
       
  3256 			}
       
  3257 		else
       
  3258 			{
       
  3259 			//
       
  3260 			// String does not contain '-' character so it must be just a single value
       
  3261 			const TInt val(CATParamListEntry::EntryValL(entry));
       
  3262 			SetCECaps(val,iPhoneGlobals->iCallDataCaps);
       
  3263 			LOGTEXT2(_L8("CATInit::ParseResponseL <ce> val:%d"),val);
       
  3264 			}
       
  3265 		}
       
  3266 
       
  3267 	CleanupStack::PopAndDestroy();		// ParseBufferLC pushed object
       
  3268 	}
       
  3269 
       
  3270 
       
  3271 void CATInit::SetCECaps(TInt aVal,RMobileCall::TMobileCallDataCapsV1& aCaps)
       
  3272 /**
       
  3273  * This function converts the ETSI speed values to the Etel MM speed enums
       
  3274  */
       
  3275 	{
       
  3276 	switch (aVal)
       
  3277 		{
       
  3278 	case 0:
       
  3279 		aCaps.iQoSCaps  |= RMobileCall::KCapsTransparent;
       
  3280 		break;
       
  3281 	case 1:
       
  3282 		aCaps.iQoSCaps  |= RMobileCall::KCapsNonTransparent;
       
  3283 		break;
       
  3284 	case 2:
       
  3285 		aCaps.iQoSCaps  |= RMobileCall::KCapsTransparentPreferred;
       
  3286 		break;
       
  3287 	case 3:
       
  3288 		aCaps.iQoSCaps  |= RMobileCall::KCapsNonTransparentPreferred;
       
  3289 		break;
       
  3290 	default:		// default required to prevent ARM compiler warning
       
  3291 		break;		
       
  3292 		}
       
  3293 	}
       
  3294 
       
  3295 
       
  3296 void CATInit::SetNameCaps(TInt aVal,RMobileCall::TMobileCallDataCapsV1& aCaps)
       
  3297 /**
       
  3298  * This function converts the ETSI speed values to the Etel MM speed enums
       
  3299  */
       
  3300  	{
       
  3301 	switch (aVal)
       
  3302 		{
       
  3303 	case 0:
       
  3304 		aCaps.iServiceCaps |= RMobileCall::KCapsDataCircuitAsynchronous;
       
  3305 		break;
       
  3306 	case 1:
       
  3307 		aCaps.iServiceCaps |= RMobileCall::KCapsDataCircuitSynchronous;
       
  3308 		break;
       
  3309 	case 2:
       
  3310 		aCaps.iServiceCaps |= RMobileCall::KCapsPADAsyncUDI;
       
  3311 		break;
       
  3312 	case 3:
       
  3313 		aCaps.iServiceCaps |= RMobileCall::KCapsPacketAccessSyncUDI;
       
  3314 		break;
       
  3315 	case 4:
       
  3316 		aCaps.iServiceCaps |= RMobileCall::KCapsDataCircuitAsynchronousRDI;
       
  3317 		break;
       
  3318 	case 5:
       
  3319 		aCaps.iServiceCaps |= RMobileCall::KCapsDataCircuitSynchronousRDI;
       
  3320 		break;
       
  3321 	case 6:
       
  3322 		aCaps.iServiceCaps |= RMobileCall::KCapsPADAsyncRDI;
       
  3323 		break;
       
  3324 	case 7:
       
  3325 		aCaps.iServiceCaps |= RMobileCall::KCapsPacketAccessSyncRDI;
       
  3326 		break;
       
  3327 	default:		// default needed to prevent ARM compiler warning
       
  3328 		break;		
       
  3329 		}
       
  3330 	}
       
  3331 
       
  3332 
       
  3333 void CATInit::SetSpeedCaps(TInt aVal,RMobileCall::TMobileCallDataCapsV1& aCaps)
       
  3334 /**
       
  3335  * This function converts the ETSI speed values to the Etel MM speed enums
       
  3336  */
       
  3337  	{
       
  3338 	switch(aVal)
       
  3339 		{
       
  3340 	case 0:
       
  3341 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeedAutobauding; 
       
  3342 		break;
       
  3343 	case 4:
       
  3344 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed2400; 
       
  3345 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV22bis;
       
  3346 		break;
       
  3347 	case 6:
       
  3348 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed4800; 
       
  3349 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV32;
       
  3350 		break;
       
  3351 	case 7:
       
  3352 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed9600; 
       
  3353 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV32;
       
  3354 		break;
       
  3355 	case 12:
       
  3356 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed9600; 
       
  3357 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV34;
       
  3358 		break;
       
  3359 	case 14:
       
  3360 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed14400; 
       
  3361 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV34;
       
  3362 		break;
       
  3363 	case 15:
       
  3364 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed19200; 
       
  3365 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV34;
       
  3366 		aCaps.iHscsdSupport = ETrue;
       
  3367 		break;
       
  3368 	case 16:
       
  3369 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed28800; 
       
  3370 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV34;
       
  3371 		aCaps.iHscsdSupport = ETrue;
       
  3372 		break;
       
  3373 	case 36:
       
  3374 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed2400; 
       
  3375 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV120;
       
  3376 		break;
       
  3377 	case 38:
       
  3378 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed4800; 
       
  3379 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV120;
       
  3380 		break;
       
  3381 	case 39:
       
  3382 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed9600; 
       
  3383 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV120;
       
  3384 		break;
       
  3385 	case 43:
       
  3386 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed14400; 
       
  3387 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV120;
       
  3388 		aCaps.iHscsdSupport = ETrue;
       
  3389 		break;
       
  3390 	case 47:
       
  3391 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed19200; 
       
  3392 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV120;
       
  3393 		aCaps.iHscsdSupport = ETrue;
       
  3394 		break;
       
  3395 	case 48:
       
  3396 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed28800; 
       
  3397 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV120;
       
  3398 		aCaps.iHscsdSupport = ETrue;
       
  3399 		break;
       
  3400 	case 49:
       
  3401 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed38400; 
       
  3402 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV120;
       
  3403 		aCaps.iHscsdSupport = ETrue;
       
  3404 		break;
       
  3405 	case 50:
       
  3406 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed48000; 
       
  3407 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV120;
       
  3408 		aCaps.iHscsdSupport = ETrue;
       
  3409 		break;
       
  3410 	case 51:
       
  3411 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed56000; 
       
  3412 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolV120;
       
  3413 		aCaps.iHscsdSupport = ETrue;
       
  3414 		break;
       
  3415 	case 68:
       
  3416 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed2400; 
       
  3417 		aCaps.iProtocolCaps |= 
       
  3418 			(RMobileCall::KCapsProtocolV110 | RMobileCall::KCapsProtocolX31FlagStuffing);
       
  3419 		break;
       
  3420 	case 70:
       
  3421 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed4800; 
       
  3422 		aCaps.iProtocolCaps |= 
       
  3423 			(RMobileCall::KCapsProtocolV110 | RMobileCall::KCapsProtocolX31FlagStuffing);
       
  3424 		break;
       
  3425 	case 71:
       
  3426 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed9600; 
       
  3427 		aCaps.iProtocolCaps |= 
       
  3428 			(RMobileCall::KCapsProtocolV110 | RMobileCall::KCapsProtocolX31FlagStuffing);
       
  3429 		break;
       
  3430 	case 75:
       
  3431 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed14400; 
       
  3432 		aCaps.iProtocolCaps |= 
       
  3433 			(RMobileCall::KCapsProtocolV110 | RMobileCall::KCapsProtocolX31FlagStuffing);
       
  3434 		aCaps.iHscsdSupport = ETrue;
       
  3435 		break;
       
  3436 	case 79:
       
  3437 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed19200; 
       
  3438 		aCaps.iProtocolCaps |= 
       
  3439 			(RMobileCall::KCapsProtocolV110 | RMobileCall::KCapsProtocolX31FlagStuffing);
       
  3440 		aCaps.iHscsdSupport = ETrue;
       
  3441 		break;
       
  3442 	case 80:
       
  3443 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed28800; 
       
  3444 		aCaps.iProtocolCaps |= 
       
  3445 			(RMobileCall::KCapsProtocolV110 | RMobileCall::KCapsProtocolX31FlagStuffing);
       
  3446 		aCaps.iHscsdSupport = ETrue;
       
  3447 		break;
       
  3448 	case 81:
       
  3449 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed38400; 
       
  3450 		aCaps.iProtocolCaps |= 
       
  3451 			(RMobileCall::KCapsProtocolV110 | RMobileCall::KCapsProtocolX31FlagStuffing);
       
  3452 		aCaps.iHscsdSupport = ETrue;
       
  3453 		break;
       
  3454 	case 82:
       
  3455 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed48000; 
       
  3456 		aCaps.iProtocolCaps |= 
       
  3457 			(RMobileCall::KCapsProtocolV110 | RMobileCall::KCapsProtocolX31FlagStuffing);
       
  3458 		aCaps.iHscsdSupport = ETrue;
       
  3459 		break;
       
  3460 	case 83:
       
  3461 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed56000; 
       
  3462 		aCaps.iProtocolCaps |= 
       
  3463 			(RMobileCall::KCapsProtocolV110 | RMobileCall::KCapsProtocolX31FlagStuffing);
       
  3464 		aCaps.iHscsdSupport = ETrue;
       
  3465 		break;
       
  3466 	case 115:
       
  3467 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed56000; 
       
  3468 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolBitTransparent;
       
  3469 		aCaps.iHscsdSupport = ETrue;
       
  3470 		break;
       
  3471 	case 116:
       
  3472 		aCaps.iSpeedCaps |= RMobileCall::KCapsSpeed64000; 
       
  3473 		aCaps.iProtocolCaps |= RMobileCall::KCapsProtocolBitTransparent;
       
  3474 		aCaps.iHscsdSupport = ETrue;
       
  3475 		break;
       
  3476 	default:		// default required to stop ARM compiler warnings
       
  3477 		break;		
       
  3478 		}
       
  3479 	}
       
  3480