telephonyserverplugins/multimodetsy/hayes/ATCALL.CPP
changeset 0 3553901f7fa8
child 19 630d2f34d719
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 //
       
    15 
       
    16 #include <commsdattypesv1_1.h>
       
    17 #include <cdblen.h>
       
    18 #include "PHONE.H"
       
    19 #include "ATCALL.H"
       
    20 #include "ATINIT.H"
       
    21 #include "ATESCAPE.H"
       
    22 #include "mSLOGGER.H"
       
    23 #include "CALL.H"
       
    24 #include "NOTIFY.H"
       
    25 #include "ATNOCARR.H"
       
    26 #include "ATIO.H"
       
    27 
       
    28 #include "Matstd.h"
       
    29 
       
    30 _LIT8(KCallInitCommand,"AT%S%S%S%S%d\r");
       
    31 _LIT8(KTrasmitResponse,"Transmit:");
       
    32 _LIT8(KReceiveResponse,"Receive:");
       
    33 
       
    34 // 
       
    35 //	CATCallAlterCommands - generic functionality for Dial, Answer, Connect and Hang Up
       
    36 //
       
    37 
       
    38 CATCallAlterCommands::CATCallAlterCommands(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals)
       
    39 										: CATCommands(aIo,aTelObject,aInit,aPhoneGlobals)
       
    40 	{}
       
    41 
       
    42 void CATCallAlterCommands::ConstructL()
       
    43 	{
       
    44 	CATCommands::ConstructL();
       
    45 	} 
       
    46 
       
    47 CATCallAlterCommands::~CATCallAlterCommands()
       
    48 	{}
       
    49 
       
    50 void CATCallAlterCommands::Start(TTsyReqHandle /*aTsyReqHandle*/, TAny* /*aParams*/)
       
    51 	{}
       
    52 
       
    53 void CATCallAlterCommands::CancelCommand(TTsyReqHandle aTsyReqHandle)
       
    54 	{
       
    55 	if (iPhoneGlobals->iPhoneStatus.iInitStatus==EPhoneInitialising)
       
    56 		{
       
    57 		iInit->StopInit(aTsyReqHandle);
       
    58 		}
       
    59 	else if (iPhoneGlobals->iPhoneStatus.iMode==RPhone::EModeOnlineData)
       
    60 		{
       
    61 		iATSetToOnlineCommandMode->StopEscapeSequence(aTsyReqHandle);
       
    62 		}
       
    63 	else
       
    64 		{
       
    65 		Stop(aTsyReqHandle);
       
    66 		}
       
    67 	}
       
    68 
       
    69 TInt CATCallAlterCommands::ChangeCallStatus(RMobileCall::TMobileCallStatus aCallStatus)
       
    70 //
       
    71 //	All instances of classes derived from CATCallAlterCommands must be owned by CCallHayes
       
    72 //
       
    73 	{
       
    74 	return REINTERPRET_CAST(CCallHayes*,iTelObject)->ChangeCallStatus(aCallStatus);
       
    75 	}
       
    76 
       
    77 void CATCallAlterCommands::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
       
    78 //
       
    79 //	Completes the dial/answer/connect/hangup request with an error
       
    80 //
       
    81 	{
       
    82 	iIo->WriteAndTimerCancel(this);
       
    83 	REINTERPRET_CAST(CCallHayes*,iTelObject)->SetToIdleAndCompleteReq(iReqHandle,aStatus);
       
    84 	}
       
    85 
       
    86 //
       
    87 // CATCallConnectCommands - base class for dial,connect and answer
       
    88 //
       
    89 
       
    90 CATCallConnectCommands::CATCallConnectCommands(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals)
       
    91 			: CATCallAlterCommands(aIo,aTelObject,aInit,aPhoneGlobals)
       
    92 	{
       
    93 	iCallType=ENoneCall;
       
    94 	}
       
    95 
       
    96 CATCallConnectCommands::~CATCallConnectCommands()
       
    97 	{
       
    98 	iIo->RemoveExpectStrings(this);
       
    99 	iIo->WriteAndTimerCancel(this);	
       
   100 	}
       
   101 
       
   102 TBool CATCallConnectCommands::IsPreConnectInProgress()
       
   103 //
       
   104 //	The Call class must know whether the pre-connection initialisation sequence is in
       
   105 //  progress or not.
       
   106 //
       
   107 	{
       
   108 	if (iPreConnectState==ENotInProgress || iPreConnectState==EATInitCompleted)
       
   109 		return EFalse;
       
   110 	return ETrue;
       
   111 	}
       
   112 
       
   113 void CATCallConnectCommands::CompleteWithIOError(TEventSource aSource,TInt aStatus)
       
   114 	{
       
   115 	iPreConnectState = CATCallConnectCommands::ENotInProgress;
       
   116 	CATCallAlterCommands::CompleteWithIOError(aSource,aStatus);
       
   117 	}
       
   118 
       
   119 
       
   120 TInt CATCallConnectCommands::GetSpeakerControlAndVolumeValues(TDes8& aSpeakerCommand,TDes8& aVolumeCommand)
       
   121 	{
       
   122 	TInt ret;
       
   123 	switch (iCallInfo->iSpeakerControl)
       
   124 		{
       
   125 	case RCall::EMonitorSpeakerControlAlwaysOff:
       
   126 		ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameSpeakerAlwaysOff),aSpeakerCommand);
       
   127 		break;
       
   128 	case RCall::EMonitorSpeakerControlAlwaysOn:
       
   129 		ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameSpeakerAlwaysOn),aSpeakerCommand);
       
   130 		break;
       
   131 	case RCall::EMonitorSpeakerControlOnExceptDuringDialling:
       
   132 		ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameSpeakerOnAfterUntilCarrier),aSpeakerCommand);
       
   133 		break;
       
   134 	case RCall::EMonitorSpeakerControlOnUntilCarrier:
       
   135 	case RCall::EMonitorSpeakerControlUnknown:
       
   136 	default:
       
   137 		ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameSpeakerOnUntilCarrier),aSpeakerCommand);
       
   138 		break;
       
   139 		}
       
   140 	switch (iCallInfo->iSpeakerVolume)
       
   141 		{
       
   142 	case RCall::EMonitorSpeakerVolumeOff:
       
   143 	case RCall::EMonitorSpeakerVolumeLow:
       
   144 		ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameSpeakerVolControlLow),aVolumeCommand);
       
   145 		break;
       
   146 	case RCall::EMonitorSpeakerVolumeHigh:
       
   147 		ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameSpeakerVolControlHigh),aVolumeCommand);
       
   148 		break;
       
   149 	case RCall::EMonitorSpeakerVolumeMedium:
       
   150 	case RCall::EMonitorSpeakerVolumeUnknown:
       
   151 	default:
       
   152 		ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameSpeakerVolControlMedium),aVolumeCommand);
       
   153 		break;
       
   154 		}
       
   155 	return ret;
       
   156 	}
       
   157 
       
   158 void CATCallConnectCommands::PreConnectEventSignal(TEventSource aSource)
       
   159 	{
       
   160 	LOGTEXT2(_L8("CATCallConnectCommands::PreConnectEventSignal with aSource %d"),aSource);
       
   161 	LOGTEXT2(_L8("CATCallConnectCommands::PreConnectEventSignal with iPreConnectState %d"),iPreConnectState);
       
   162 
       
   163 	//
       
   164 	// If a timeout has occured then there is not much we can do.
       
   165 	// Complete client request with KErrTimedOut
       
   166 	if(aSource==ETimeOutCompletion)
       
   167 		{
       
   168 		LOGTEXT(_L8("Timeout Error during Dial"));
       
   169 		RemoveStdExpectStrings();
       
   170 		Complete(KErrTimedOut,aSource);
       
   171 		return;
       
   172 		}
       
   173 
       
   174 	//
       
   175 	// Process event
       
   176 	TInt ret(KErrNone);
       
   177 	switch(iPreConnectState)
       
   178 		{
       
   179 	case EATDataClassWaitForWriteComplete:
       
   180 		iIo->Read();
       
   181 		StandardWriteCompletionHandler(aSource,4);
       
   182 		iPreConnectState=EATDataClassReadCompleted;
       
   183 		break;
       
   184 
       
   185 	case EATDataClassReadCompleted:
       
   186 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   187 	
       
   188 		//
       
   189 		// Ignore any OK, ERROR or any other response from the modem.
       
   190 		// This is because some modems, eg. those with out speakers, will ERROR these 
       
   191 		// configuration commands even though the call can go ahead.
       
   192 		iPreConnectState=EATSendCallInit;
       
   193 
       
   194 // Note: No "break;", carry on through to the next state...
       
   195 
       
   196 	case EATSendCallInit:
       
   197 		{
       
   198 		//
       
   199 		// Assemble values for our dial init string
       
   200 		// Exmaple string is ATM0L0X3S8=0
       
   201 		TBuf8<KCommsDbSvrMaxFieldLength> atMonConCommand;
       
   202 		TBuf8<KCommsDbSvrMaxFieldLength> atVolumeCommand;
       
   203 		TBuf8<KCommsDbSvrMaxFieldLength> levelOfResponseCommand;
       
   204 		TBuf8<KCommsDbSvrMaxFieldLength> atPauseCommand;
       
   205 		ret = GetSpeakerControlAndVolumeValues(atMonConCommand,atVolumeCommand);
       
   206 		if (iCallInfo->iWaitForDialTone==RCall::EDialToneWait)			// use X4
       
   207 			{
       
   208 			ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameCallProgress4),levelOfResponseCommand);
       
   209 			}
       
   210 		else	// use X3
       
   211 			{
       
   212 			ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameCallProgress3),levelOfResponseCommand);
       
   213 			}
       
   214 		ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameDialPauseLength),atPauseCommand);
       
   215 		
       
   216 		//
       
   217 		// Send string to modem
       
   218 		if (ret==KErrNone)
       
   219 			{
       
   220 			iTxBuffer.Format(KCallInitCommand,&atMonConCommand,&atVolumeCommand,&levelOfResponseCommand,&atPauseCommand,iCallInfo->iInterval);
       
   221 			iIo->Write(this,iTxBuffer);	
       
   222 			iIo->SetTimeOut(this);
       
   223 			iPreConnectState=EATCallInitWaitForWriteComplete;
       
   224 			}
       
   225 		else
       
   226 			Complete(ret,aSource);		// An error occurred
       
   227 		break;
       
   228 		}
       
   229 
       
   230 
       
   231 	case EATCallInitWaitForWriteComplete:
       
   232 		StandardWriteCompletionHandler(aSource,4);
       
   233 		iPreConnectState=EATCallInitCompleted;
       
   234 		break;
       
   235 
       
   236 		
       
   237 	case EATCallInitCompleted:
       
   238 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   239 		//
       
   240 		// Ignore any OK, ERROR or any other response from the modem.
       
   241 		// This is because some modems, eg. those with out speakers, will ERROR these 
       
   242 		// configuration commands even though the call can go ahead.
       
   243 		RemoveStdExpectStrings();
       
   244 		
       
   245 		//
       
   246 		// If we are dealing with a data call then we still have the MODEM_DATA_INIT_STRING
       
   247 		// from CommDB to send. If we are dealing with voice or fax then we have
       
   248 		// completed the init.
       
   249 		if(iCallType==EDataCall)
       
   250 			{
       
   251 			TBuf8<KCommsDbSvrMaxFieldLength> dataInitCommand;
       
   252 			ret = iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameDataInitString),dataInitCommand);
       
   253 			if(ret==KErrNone)
       
   254 				{
       
   255 				//
       
   256 				// If string from CommDB is null then use simple 'AT' string
       
   257 				if(dataInitCommand.Length()==0)
       
   258 					dataInitCommand=KAT2Command;
       
   259 				//
       
   260 				// Write string to modem
       
   261 				Write(dataInitCommand,4);
       
   262 				iPreConnectState=EATWaitForDataInitWrite;
       
   263 				}
       
   264 			else
       
   265 				Complete(ret,aSource);		// An error occurred
       
   266 			}
       
   267 		else
       
   268 			{
       
   269 			iIo->RemoveExpectStrings(this);
       
   270 			iOKExpectString=NULL;
       
   271 			iErrorExpectString=NULL;
       
   272 			iPreConnectState=EATInitCompleted;
       
   273 			Complete(ret,aSource);
       
   274 			}
       
   275 		break;
       
   276 
       
   277 
       
   278 	case EATWaitForDataInitWrite:
       
   279 		__ASSERT_DEBUG(iCallType==EDataCall,Panic(ENotDataCallType));
       
   280 		StandardWriteCompletionHandler(aSource,4);
       
   281 		iPreConnectState=EATWaitForDataInitOK;
       
   282 		break;
       
   283 
       
   284 
       
   285 	case EATWaitForDataInitOK:
       
   286 		__ASSERT_DEBUG(iCallType==EDataCall,Panic(ENotDataCallType));
       
   287 		__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   288 		//
       
   289 		// Ignore any OK, ERROR or any other response from the modem.
       
   290 		// This is because some modems, eg. those with out speakers, will ERROR these 
       
   291 		// configuration commands even though the call can go ahead.
       
   292 		RemoveStdExpectStrings();
       
   293 		iIo->WriteAndTimerCancel(this);	
       
   294 		Write(KAT2Command,4);
       
   295 		iPreConnectState=EWaitForATCheckWrite;
       
   296 		break;
       
   297 
       
   298 
       
   299 	case EWaitForATCheckWrite:
       
   300 		//
       
   301 		// When a voice call starts this is where it starts its PreConnection from
       
   302 		// this state.
       
   303 		StandardWriteCompletionHandler(aSource,4);
       
   304 		iPreConnectState=EATWaitForATCheckOK;
       
   305 		break;
       
   306 
       
   307 
       
   308 	case EATWaitForATCheckOK:
       
   309 		ret=ValidateExpectString();
       
   310 		RemoveStdExpectStrings();
       
   311 		if(ret==KErrNone)
       
   312 			{
       
   313 			//
       
   314 			// Init is now completed
       
   315 			iIo->WriteAndTimerCancel(this);	
       
   316 			iPhoneGlobals->iPhoneStatus.iMode=RPhone::EModeEstablishingLink;
       
   317 			iPreConnectState=EATInitCompleted;
       
   318 			}
       
   319 		else
       
   320 			Complete(ret,aSource);		// An error occured
       
   321 		break;
       
   322 
       
   323 
       
   324 	case ECancelling:
       
   325 		if (aSource==EWriteCompletion)
       
   326 			{
       
   327 			iIo->SetTimeOut(this);
       
   328 			AddStdExpectStrings();
       
   329 			}
       
   330 		if (aSource==EReadCompletion || aSource==ETimeOutCompletion)
       
   331 			{
       
   332 			RemoveStdExpectStrings();
       
   333 			Complete(KErrCancel,aSource);
       
   334 			}
       
   335 		break;
       
   336 
       
   337 	case ENotInProgress:
       
   338 	case EATInitCompleted:
       
   339 		__ASSERT_DEBUG(EFalse,Panic(EUnexpectedState));
       
   340 		}
       
   341 	}
       
   342 
       
   343 
       
   344 
       
   345 
       
   346 //
       
   347 // CATVoiceCallConnectCommands - voice call specific for dial
       
   348 //
       
   349 CATVoiceCallConnectCommands::CATVoiceCallConnectCommands(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals)
       
   350 			: CATCallConnectCommands(aIo,aTelObject,aInit,aPhoneGlobals)
       
   351 	{
       
   352 	iCallType=EVoiceCall;
       
   353 	}
       
   354 
       
   355 CATVoiceCallConnectCommands::~CATVoiceCallConnectCommands()
       
   356 	{}
       
   357 
       
   358 void CATVoiceCallConnectCommands::Start(TTsyReqHandle aTsyReqHandle,TAny* /*aParams*/)
       
   359 	{
       
   360 	iReqHandle = aTsyReqHandle;
       
   361 	TPtrC8 dataClassCommand(KAT2Command);
       
   362 	Write(dataClassCommand,3);
       
   363 	__ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral));
       
   364 	iPreConnectState=CATCallConnectCommands::EWaitForATCheckWrite;
       
   365 	}
       
   366 
       
   367 void CATVoiceCallConnectCommands::AddCommonExpectStrings()
       
   368 	{
       
   369 	// Voice call setup is indicated by OK, with no indication of
       
   370 	// connection failure except a subsequent "NO CARRIER".
       
   371 	// See GSM 07.07 version 6.3.0 Annex G "Voice call example"
       
   372 	if (!iOKExpectString)
       
   373 		{
       
   374 		iOKExpectString=iIo->AddExpectString(this,KOkString);
       
   375 		}
       
   376 	if (!iNoCarrierExpectString)
       
   377 		{
       
   378 		iNoCarrierExpectString=iIo->AddExpectString(this,KNoCarrierString);
       
   379 		}
       
   380 	}
       
   381 
       
   382 void CATVoiceCallConnectCommands::RemoveCommonExpectStrings()
       
   383 	{
       
   384 	iIo->RemoveExpectString(iOKExpectString);
       
   385 	iOKExpectString=NULL;
       
   386 	iIo->RemoveExpectString(iNoCarrierExpectString);
       
   387 	iNoCarrierExpectString=NULL;
       
   388 	}
       
   389 
       
   390 void CATVoiceCallConnectCommands::Complete(TInt aError,TEventSource aSource)
       
   391 	{
       
   392 	iIo->WriteAndTimerCancel(this);	
       
   393 	iIo->RemoveExpectStrings(this);
       
   394 	iNoCarrierExpectString=NULL;
       
   395 	iConnectExpectString=NULL;
       
   396 	iOKExpectString=NULL;
       
   397 	iPreConnectState = CATCallConnectCommands::ENotInProgress;
       
   398 	if (aError==KErrNone)
       
   399 		{
       
   400 		ChangeLineStatus(RCall::EStatusConnected);
       
   401 		aError = ChangeCallStatus(RMobileCall::EStatusConnected);
       
   402 		}
       
   403 	if (aError==KErrNone)
       
   404 		{
       
   405 		iPhoneGlobals->iPhoneStatus.iMode = RPhone::EModeUnknown;
       
   406 		REINTERPRET_CAST(CCallHayes*,iTelObject)->iWaitForNoCarrier->StartWait();
       
   407 		REINTERPRET_CAST(CCallHayes*,iTelObject)->StartCallTicker();
       
   408 		}
       
   409 	else
       
   410 		{
       
   411 		//	SetToIdle() sets call to unowned 
       
   412 		REINTERPRET_CAST(CCallHayes*,iTelObject)->SetToIdle();
       
   413 		if (aError!=KErrCancel)
       
   414 			iPhoneGlobals->iPhoneStatus.iInitStatus=EPhoneNotInitialised;
       
   415 		}
       
   416 	CATCommands::Complete(aError,aSource);
       
   417 	iTelObject->ReqCompleted(iReqHandle, aError);
       
   418 	if (iCallInfo->iClientPanicOccurred!=ENoPanicOccurred)
       
   419 		{
       
   420 		iComplete = CCompleteRelinquish::New(iTelObject);
       
   421 		iComplete->SetWhichCompletion(iCallInfo->iClientPanicOccurred);
       
   422 		iComplete->Call();	// calls the AysncOneShot Relinquish completion function
       
   423 		iCallInfo->iClientPanicOccurred = ENoPanicOccurred;
       
   424 		}	
       
   425 	if (aSource!=EReadCompletion && !(iIo->ReadPending()))
       
   426 						// if Complete() called whilst aSource ==EWriteCompletion
       
   427 									// iIo->Read won't happen otherwise
       
   428 		iIo->Read();
       
   429 	}
       
   430 
       
   431 
       
   432 
       
   433 
       
   434 //
       
   435 //
       
   436 // CATDataCallConnectCommands - data call specific for dial/answer/connect
       
   437 //
       
   438 
       
   439 CATDataCallConnectCommands::CATDataCallConnectCommands(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals)
       
   440 			: CATCallConnectCommands(aIo,aTelObject,aInit,aPhoneGlobals)
       
   441 	{
       
   442 	iCallType=EDataCall;
       
   443 	}
       
   444 
       
   445 CATDataCallConnectCommands::~CATDataCallConnectCommands()
       
   446 	{}
       
   447 
       
   448 void CATDataCallConnectCommands::Start(TTsyReqHandle aTsyReqHandle,TAny* /*aParams*/)
       
   449 	{
       
   450 	iReqHandle = aTsyReqHandle;
       
   451 	TPtrC8 dataClassCommand(KDataClassCommand);
       
   452 	Write(dataClassCommand,3);
       
   453 	__ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral));
       
   454 	iPreConnectState=CATCallConnectCommands::EATDataClassWaitForWriteComplete;
       
   455 	}
       
   456 
       
   457 TInt CATDataCallConnectCommands::AddCommonExpectStrings()
       
   458 	{
       
   459 	TInt ret(KErrNone);
       
   460 	if (!iConnectExpectString)
       
   461 		{
       
   462 		ret=iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameConnect),iConnectString);
       
   463 		if(ret==KErrNone)
       
   464 			{	
       
   465 			AppendWildCardChar(iConnectString);
       
   466 			iConnectExpectString=iIo->AddExpectString(this,iConnectString);
       
   467 			}
       
   468 		}
       
   469 	if (!iNoCarrierExpectString)
       
   470 		{
       
   471 		iNoCarrierExpectString=iIo->AddExpectString(this,KNoCarrierString);
       
   472 		}
       
   473 	return ret;
       
   474 	}
       
   475 
       
   476 void CATDataCallConnectCommands::RemoveCommonExpectStrings()
       
   477 	{
       
   478 	iIo->RemoveExpectString(iConnectExpectString);
       
   479 	iConnectExpectString=NULL;
       
   480 	iIo->RemoveExpectString(iNoCarrierExpectString);
       
   481 	iNoCarrierExpectString=NULL;
       
   482 	}
       
   483 
       
   484 void CATDataCallConnectCommands::ParseForBearerServiceCapsResponseL()
       
   485 	{
       
   486 	LOGTEXT(_L8("Parse the CBST Bearer Service values"));
       
   487 	iBuffer.Set(iIo->Buffer());
       
   488 	// Look for "CARRIER" in buffer
       
   489 	TBuf8<KCommsDbSvrMaxFieldLength> carrierString;
       
   490 	(void)User::LeaveIfError(iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameCarrier),carrierString));
       
   491 	}
       
   492 
       
   493 TInt CATDataCallConnectCommands::ParseForBearerCapsResponse()
       
   494 	{
       
   495 	LOGTEXT(_L8("Parse the Buffer List for Bearer Service values"));
       
   496 	iBuffer.Set(iIo->Buffer());
       
   497 	iCallInfo->iBearerService.iBearerCaps = 0;
       
   498 	for (TInt i=0;KBearerResponseStrings[i];i++)
       
   499 		{
       
   500 		TPtrC8 ptr(KBearerResponseStrings[i]);
       
   501 		TInt aPos=iBuffer.FindF(ptr);
       
   502 		if (aPos!=KErrNotFound)
       
   503 			{
       
   504 			switch (i)
       
   505 				{
       
   506 				case 0:
       
   507 				case 1:
       
   508 					iCallInfo->iBearerService.iBearerCaps |= RCall::KBearerCapsProtocolLAPM;
       
   509 					break;
       
   510 				case 2:
       
   511 					iCallInfo->iBearerService.iBearerCaps |= RCall::KBearerCapsProtocolALT_CELLULAR;
       
   512 					break;
       
   513 				case 3:
       
   514 					iCallInfo->iBearerService.iBearerCaps |= RCall::KBearerCapsProtocolALT;
       
   515 					break;
       
   516 				case 4:
       
   517 					iCallInfo->iBearerService.iBearerCaps |= RCall::KBearerCapsCompressionV42bis;
       
   518 					break;
       
   519 				case 5:
       
   520 					iCallInfo->iBearerService.iBearerCaps |= RCall::KBearerCapsCompressionMNP5;
       
   521 					break;
       
   522 				default:
       
   523 					iCallInfo->iBearerService.iBearerCaps = RCall::KBearerCapsProtocolUnknown;
       
   524 					iCallInfo->iBearerService.iBearerCaps = RCall::KBearerCapsCompressionUnknown;
       
   525 					return KErrUnknown;
       
   526 				}
       
   527 			}
       
   528 		}
       
   529 	if (!(iCallInfo->iBearerService.iBearerCaps & (RCall::KBearerCapsProtocolLAPM | RCall::KBearerCapsProtocolALT_CELLULAR | RCall::KBearerCapsProtocolALT)))
       
   530 		{
       
   531 		iCallInfo->iBearerService.iBearerCaps |= RCall::KBearerCapsProtocolNone;
       
   532 		}
       
   533 	if (!(iCallInfo->iBearerService.iBearerCaps & (RCall::KBearerCapsCompressionV42bis | RCall::KBearerCapsCompressionMNP5)))
       
   534 		{
       
   535 		iCallInfo->iBearerService.iBearerCaps |= RCall::KBearerCapsCompressionNone;
       
   536 		}
       
   537 
       
   538 	return KErrNone;
       
   539 	}
       
   540 
       
   541 TInt CATDataCallConnectCommands::ParseForBearerSpeedResponse()
       
   542 	{
       
   543 	LOGTEXT(_L8("Parse the Buffer List for Bearer speed values"));
       
   544 
       
   545 	iBuffer.Set(iIo->Buffer());
       
   546 	TLex8 lexString(iBuffer);
       
   547 	// Look for "CARRIER" in buffer
       
   548 	TBuf8<KCommsDbSvrMaxFieldLength> carrierString;
       
   549 	TInt ret=iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameCarrier),carrierString);
       
   550 	if(ret!=KErrNone)
       
   551 		return ret;
       
   552 	TInt aPos=iBuffer.FindF(carrierString);
       
   553 	if (aPos!=KErrNotFound)
       
   554 		{
       
   555 		lexString.Inc(aPos+1);
       
   556 		lexString.SkipCharacters();
       
   557 		lexString.SkipSpace();
       
   558 		lexString.Mark();                     // remember where we are
       
   559         lexString.SkipCharacters();           // move to end of character token
       
   560         if (lexString.TokenLength() != 0)    // if valid potential token
       
   561 			{
       
   562             TPtrC8 token = lexString.MarkedToken();        // extract token
       
   563             if (token.CompareF(KTrasmitResponse) == 0 || token.CompareF(KReceiveResponse) == 0)    // and test
       
   564 				{
       
   565 				ret=SetBearerSpeed(lexString);
       
   566 				if(ret!=KErrNone)
       
   567 					return ret;
       
   568 				}
       
   569 			}
       
   570 		else
       
   571 			{
       
   572 			ret=SetBearerSpeed(lexString);
       
   573 			if(ret!=KErrNone)
       
   574 				return ret;
       
   575 			}
       
   576 		}
       
   577 	else
       
   578 		{
       
   579 		TBuf8<KCommsDbSvrMaxFieldLength> connectString;
       
   580 		ret=iPhoneGlobals->iConfiguration->ConfigModemString(TPtrC(KCDTypeNameConnect),connectString);
       
   581 		if(ret!=KErrNone)
       
   582 			return ret;
       
   583 		TInt aPos=iBuffer.FindF(connectString);
       
   584 		lexString.Inc(aPos+1);
       
   585 		lexString.SkipCharacters();
       
   586 		lexString.SkipSpace();
       
   587 		if (lexString.Peek().IsDigit())
       
   588 			{
       
   589 			ret=SetBearerSpeed(lexString);
       
   590 			if(ret!=KErrNone)
       
   591 				return ret;
       
   592 			}
       
   593 		}
       
   594 	return KErrNone;
       
   595 	}
       
   596 
       
   597 TInt CATDataCallConnectCommands::SetBearerSpeed(TLex8& aLexString)
       
   598 	{
       
   599 	TPtrC8 token;
       
   600 	aLexString.SkipSpaceAndMark();
       
   601 
       
   602 	while (aLexString.Peek().IsDigit())
       
   603 		{
       
   604 		aLexString.Inc();
       
   605 		}
       
   606 	if (TUint(aLexString.Peek())==84)
       
   607 		{
       
   608 		aLexString.Inc();
       
   609 		if (TUint(aLexString.Peek())==88)
       
   610 			{
       
   611 			// We have TX
       
   612 			aLexString.Inc();
       
   613 			}
       
   614 		}
       
   615 	token.Set(aLexString.MarkedToken());
       
   616 	TInt i;
       
   617 	for(i=0;KBearerSpeedResponseStrings[i];i++)
       
   618 		{
       
   619 		TPtrC8 ptr(KBearerSpeedResponseStrings[i]);
       
   620 		if(token.MatchF(ptr)==KErrNone)
       
   621 			break;
       
   622 		}
       
   623 	switch (i)
       
   624 		{
       
   625 	case 0:
       
   626 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData57600;
       
   627 		break;
       
   628 	case 1:
       
   629 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData33600;
       
   630 		break;
       
   631 	case 2:
       
   632 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData31200;
       
   633 		break;
       
   634 	case 3:
       
   635 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData19200;
       
   636 		break;
       
   637 	case 4:
       
   638 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData14400;
       
   639 		break;
       
   640 	case 5:
       
   641 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData12000;
       
   642 		break;
       
   643 	case 6:
       
   644 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData9600;
       
   645 		break;
       
   646 	case 7:
       
   647 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData7200;
       
   648 		break;
       
   649 	case 8:
       
   650 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData4800;
       
   651 		break;
       
   652 	case 9:
       
   653 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData2400;
       
   654 		break;
       
   655 	case 10:
       
   656 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData1200;
       
   657 		break;
       
   658 	case 11:
       
   659 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData75_1200;
       
   660 		break;
       
   661 	case 12:
       
   662 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData1200_75;
       
   663 		break;
       
   664 	case 13:
       
   665 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerData300;
       
   666 		break;
       
   667 	case 14:
       
   668 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerDataUnknown;
       
   669 		break;
       
   670 	default:
       
   671 		iCallInfo->iBearerService.iBearerSpeed = RCall::EBearerDataUnknown;
       
   672 		return KErrUnknown;
       
   673 		}
       
   674 	return KErrNone;
       
   675 	}
       
   676 
       
   677 void CATDataCallConnectCommands::Complete(TInt aError,TEventSource aSource)
       
   678 	{
       
   679 	iIo->WriteAndTimerCancel(this);	
       
   680 	iIo->RemoveExpectStrings(this);
       
   681 	iNoCarrierExpectString=NULL;
       
   682 	iConnectExpectString=NULL;
       
   683 	iOKExpectString=NULL;
       
   684 	iPreConnectState = CATCallConnectCommands::ENotInProgress;
       
   685 	if (aError==KErrNone)
       
   686 		{
       
   687 		ChangeLineStatus(RCall::EStatusConnected);
       
   688 		aError = ChangeCallStatus(RMobileCall::EStatusConnected);
       
   689 		}
       
   690 	if (aError==KErrNone)
       
   691 		{
       
   692 		iPhoneGlobals->iPhoneStatus.iMode = RPhone::EModeOnlineData;
       
   693 		REINTERPRET_CAST(CCallHayes*,iTelObject)->iWaitForNoCarrier->StartWait();
       
   694 		REINTERPRET_CAST(CCallHayes*,iTelObject)->StartCallTicker();
       
   695 		}
       
   696 	else
       
   697 		{
       
   698 		//	SetToIdle() sets call to unowned 
       
   699 		REINTERPRET_CAST(CCallHayes*,iTelObject)->SetToIdle();
       
   700 		if (aError!=KErrCancel)
       
   701 			iPhoneGlobals->iPhoneStatus.iInitStatus=EPhoneNotInitialised;
       
   702 		}
       
   703 	CATCommands::Complete(aError,aSource);
       
   704 	iTelObject->ReqCompleted(iReqHandle, aError);
       
   705 	if (iCallInfo->iClientPanicOccurred!=ENoPanicOccurred)
       
   706 		{
       
   707 		iComplete = CCompleteRelinquish::New(iTelObject);
       
   708 		iComplete->SetWhichCompletion(iCallInfo->iClientPanicOccurred);
       
   709 		iComplete->Call();	// calls the AysncOneShot Relinquish completion function
       
   710 		iCallInfo->iClientPanicOccurred = ENoPanicOccurred;
       
   711 		}	
       
   712 	if (aSource!=EReadCompletion && !(iIo->ReadPending()))
       
   713 						// if Complete() called whilst aSource ==EWriteCompletion
       
   714 									// iIo->Read won't happen otherwise
       
   715 		iIo->Read();
       
   716 	}
       
   717 
       
   718 //
       
   719 // CATFaxCallConnectCommands - fax call specific for dial/answer/connect
       
   720 //
       
   721 
       
   722 CATFaxCallConnectCommands::CATFaxCallConnectCommands(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals)
       
   723 			: CATCallConnectCommands(aIo,aTelObject,aInit,aPhoneGlobals)
       
   724 	{
       
   725 	iCallType=EFaxCall;
       
   726 	}
       
   727 
       
   728 CATFaxCallConnectCommands::~CATFaxCallConnectCommands()
       
   729 	{}
       
   730 
       
   731 void CATFaxCallConnectCommands::Start(TTsyReqHandle aTsyReqHandle, TAny* /*aParams*/)
       
   732 	{
       
   733 	iReqHandle=aTsyReqHandle;
       
   734 	__ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral));
       
   735 	iPreConnectState=CATCallConnectCommands::EATSendCallInit;
       
   736 	EventSignal(EReadCompletion);	// EReadCompletion is a dummy enum here
       
   737 	}
       
   738 
       
   739 void CATFaxCallConnectCommands::Stop(TTsyReqHandle aTsyReqHandle)
       
   740 	{
       
   741 	__ASSERT_ALWAYS(aTsyReqHandle == iReqHandle,Panic(EIllegalTsyReqHandle));
       
   742 	if (iPreConnectState!=CATCallConnectCommands::EATInitCompleted)
       
   743 		{
       
   744 		iPreConnectState=ECancelling;
       
   745 		AddStdExpectStrings();
       
   746 		}
       
   747 	else
       
   748 		{
       
   749 		CCallMobileFax* faxCall = REINTERPRET_CAST(CCallMobileFax*,iTelObject);
       
   750 		faxCall->FaxCancelCommand(aTsyReqHandle);
       
   751 		}
       
   752 	}
       
   753 
       
   754 void CATFaxCallConnectCommands::Complete(TInt aError,TEventSource aSource)
       
   755 //
       
   756 // Doesn't call CATCommands::Complete() 
       
   757 //
       
   758 	{
       
   759 	iIo->WriteAndTimerCancel(this);
       
   760 	iIo->RemoveExpectStrings(this);
       
   761 	if (aError)
       
   762 		{
       
   763 		REINTERPRET_CAST(CCallHayes*,iTelObject)->SetToIdleAndCompleteReq(iReqHandle,aError);
       
   764 		if (aError!=KErrCancel)
       
   765 			iPhoneGlobals->iPhoneStatus.iInitStatus=EPhoneNotInitialised;
       
   766 		if (iCallInfo->iClientPanicOccurred!=ENoPanicOccurred)
       
   767 			{
       
   768 			iComplete = CCompleteRelinquish::New(iTelObject);
       
   769 			iComplete->SetWhichCompletion(iCallInfo->iClientPanicOccurred);
       
   770 			iComplete->Call();	
       
   771 			iCallInfo->iClientPanicOccurred = ENoPanicOccurred;
       
   772 			}	
       
   773 		if (aSource!=EReadCompletion && !(iIo->ReadPending()))
       
   774 			iIo->Read();
       
   775 		}
       
   776 	else
       
   777 		CompleteSuccessfully();
       
   778 	}