bluetoothengine/btmac/src/BTMonoCmdHandler/btmccallstatus.cpp
changeset 0 f63038272f30
child 10 0707dd69d236
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include "atcodec.h"
       
    19 #include "btmcprotocol.h"
       
    20 #include "btmcprotocolstatus.h"
       
    21 #include "btmccallstatus.h"
       
    22 #include "btmcmobileline.h"
       
    23 #include "btmcvoipline.h"
       
    24 #include "debug.h"
       
    25 
       
    26 const TInt KRingTimerService = 10;
       
    27 
       
    28 CBtmcCallStatus* CBtmcCallStatus::NewL(
       
    29     CBtmcProtocol& aProtocol, 
       
    30     RMobilePhone& aPhone,
       
    31     TBtmcProfileId aProfile)
       
    32     {
       
    33     CBtmcCallStatus* self=new (ELeave) CBtmcCallStatus(aProtocol);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL(aPhone, aProfile);
       
    36     CleanupStack::Pop(self);
       
    37     return self;
       
    38     }
       
    39 
       
    40 // ==========================================================
       
    41 // CBtmcCallStatus::~CBtmcCallStatus
       
    42 // 
       
    43 // ==========================================================
       
    44 //
       
    45 CBtmcCallStatus::~CBtmcCallStatus()
       
    46     {
       
    47     TRACE_FUNC_ENTRY
       
    48     delete iTimerActive;
       
    49     iTimer.Close();
       
    50     
       
    51     iLines.ResetAndDestroy();
       
    52     iLines.Close();
       
    53     TRACE_FUNC_EXIT
       
    54     }
       
    55 
       
    56 // ==========================================================
       
    57 // CBtmcCallStatus::CallStatus
       
    58 // 
       
    59 // ==========================================================
       
    60 //
       
    61 TInt CBtmcCallStatus::CallStatusL() const
       
    62     {
       
    63     TRACE_FUNC
       
    64     TInt mask = 0;
       
    65     TInt count = iLines.Count();
       
    66     for (TInt i = 0; i < count; i++)
       
    67         {
       
    68         mask |= iLines[i]->CallStatusL();
       
    69         }
       
    70     TRACE_INFO((_L(" overall CALL STATUS 0x%08x"), mask))    
       
    71     return mask;    
       
    72     }
       
    73 
       
    74 // ==========================================================
       
    75 // CBtmcCallStatus::ReportCallStatusL
       
    76 // 
       
    77 // ==========================================================
       
    78 //
       
    79 void CBtmcCallStatus::ReportCallStatusL()
       
    80     {
       
    81     TInt callBits = CallStatusL();
       
    82     ReportCallEventL(iProtocol.ProtocolStatus().iCallBits, callBits);
       
    83     iProtocol.ProtocolStatus().iCallBits = callBits;    
       
    84     }
       
    85 
       
    86 // ==========================================================
       
    87 // CBtmcCallStatus::RequestCompleted
       
    88 // 
       
    89 // ==========================================================
       
    90 //
       
    91 void CBtmcCallStatus::RequestCompletedL(CBtmcActive& aActive, TInt aErr)
       
    92     {
       
    93     TRACE_FUNC_ENTRY
       
    94     switch (aActive.ServiceId())
       
    95         {
       
    96         case KRingTimerService:
       
    97             {
       
    98             if (aErr == KErrNone)
       
    99                 {
       
   100                 ReportRingAndClipL();
       
   101                 iTimer.After(aActive.iStatus, KRingInterval);
       
   102                 aActive.GoActive();
       
   103                 }
       
   104             break;
       
   105             }
       
   106         default:
       
   107             break;
       
   108         }
       
   109     TRACE_FUNC_EXIT
       
   110     }
       
   111 
       
   112 // ==========================================================
       
   113 // CBtmcCallStatus::CancelRequest
       
   114 // Constructor
       
   115 // ==========================================================
       
   116 //
       
   117 void CBtmcCallStatus::CancelRequest(TInt aServiceId)
       
   118     {
       
   119     TRACE_FUNC_ENTRY
       
   120     if (aServiceId == KRingTimerService)
       
   121         {
       
   122         iTimer.Cancel();
       
   123         }
       
   124     TRACE_FUNC_EXIT
       
   125     }
       
   126 
       
   127 // ==========================================================
       
   128 // CBtmcCallStatus::CBtmcCallStatus
       
   129 // Constructor
       
   130 // ==========================================================
       
   131 //
       
   132 CBtmcCallStatus::CBtmcCallStatus(CBtmcProtocol& aProtocol) : iProtocol(aProtocol)
       
   133     {
       
   134     }
       
   135 
       
   136 // ==========================================================
       
   137 // CBtmcCallStatus::ConstructL
       
   138 // 
       
   139 // ==========================================================
       
   140 //
       
   141 void CBtmcCallStatus::ConstructL(
       
   142     RMobilePhone& aPhone,
       
   143     TBtmcProfileId aProfile)
       
   144     {
       
   145     TRACE_FUNC_ENTRY
       
   146     CBtmcMobileLine* voiceline = CBtmcMobileLine::NewLC(*this, aPhone, KMmTsyVoice1LineName);
       
   147     iLines.AppendL(voiceline);
       
   148     CleanupStack::Pop(voiceline);
       
   149     CBtmcVoIPLine *voipline = NULL;
       
   150     TRAPD(err, voipline = CBtmcVoIPLine::NewL(*this, aPhone));
       
   151     if(!err)
       
   152         {
       
   153         CleanupStack::PushL(voipline);
       
   154         iLines.AppendL(voipline);
       
   155         CleanupStack::Pop(voipline);        
       
   156         }
       
   157     
       
   158     TRAP(err, voiceline = CBtmcMobileLine::NewL(*this, aPhone, KMmTsyVoice2LineName));
       
   159     if (!err)
       
   160         {
       
   161         CleanupStack::PushL(voiceline);
       
   162         iLines.AppendL(voiceline);
       
   163         CleanupStack::Pop(voiceline);
       
   164         }
       
   165     
       
   166     if (aProfile == EBtmcHFP0105 )
       
   167         {
       
   168         CBtmcMobileLine* dataline = CBtmcMobileLine::NewLC(*this, aPhone, KMmTsyDataLineName);
       
   169         iLines.AppendL(dataline);
       
   170         CleanupStack::Pop(dataline);
       
   171         }
       
   172     TRACE_FUNC_EXIT
       
   173     }
       
   174 
       
   175 // ==========================================================
       
   176 // CBtmcCallStatus::HandleClccL
       
   177 // 
       
   178 // ==========================================================
       
   179 //
       
   180 void CBtmcCallStatus::HandleClccL()
       
   181     {
       
   182     TRACE_FUNC_ENTRY
       
   183     RATResultPtrArray resarr;
       
   184     ATObjArrayCleanupResetAndDestroyPushL(resarr);
       
   185         
       
   186     if(CallStatusL() & KCallAllStatusMask)
       
   187         {
       
   188         TInt count = iLines.Count();        
       
   189         for(TInt i=0; i<count; i++)
       
   190             {            
       
   191             if( !iLines[i]->IsVoip() )
       
   192                 {                
       
   193                 const RPointerArray<CBtmcCallActive>& calls = iLines[i]->ActiveCalls();
       
   194                 TInt count2 = calls.Count();            
       
   195                 RMobileConferenceCall myConf;
       
   196                 User::LeaveIfError(myConf.Open(iLines[i]->Phone()));
       
   197                 CleanupClosePushL(myConf);
       
   198                 TInt confcount;
       
   199                 User::LeaveIfError(myConf.EnumerateCalls(confcount));                
       
   200                 RMobileCall::TMobileCallInfoV1 info;
       
   201                 RMobileCall::TMobileCallRemotePartyInfoV1 remote;                
       
   202                 for(TInt j=0; j<count2; j++)
       
   203                     {                                        
       
   204                     calls[j]->GetCallInfo(info);                                        
       
   205                     if (info.iStatus != RMobileCall::EStatusIdle)
       
   206                         {
       
   207                         remote = info.iRemoteParty;
       
   208                         CATResult* cmd = MakeClccL(info, remote, confcount);
       
   209                         resarr.AppendL(cmd);
       
   210                         }
       
   211                     }
       
   212                 CleanupStack::PopAndDestroy(&myConf);
       
   213                 }
       
   214             else // VoIP case
       
   215                 {                       
       
   216 				const MCall& callInfo = iLines[i]->CallInformationL();
       
   217 				if(&callInfo != NULL)
       
   218 				    {				    
       
   219 				    CATResult* cmd = MakeVoIPClccL(callInfo);
       
   220 				    resarr.AppendL(cmd);
       
   221 				    }				                    				
       
   222                 }
       
   223             }
       
   224         }
       
   225     CATResult* ok = CATResult::NewL(EATOK);
       
   226     CleanupStack::PushL(ok);
       
   227     resarr.AppendL(ok);
       
   228     CleanupStack::Pop(ok);
       
   229     iProtocol.SendResponseL(resarr);
       
   230     CleanupStack::PopAndDestroy(&resarr);
       
   231     iProtocol.CmdHandlingCompletedL();
       
   232     TRACE_FUNC_EXIT
       
   233     }
       
   234 
       
   235 // ==========================================================
       
   236 // CBtmcCallStatus::GetRingingNumL
       
   237 // 
       
   238 // ==========================================================
       
   239 //
       
   240 void CBtmcCallStatus::GetRingingNumL(TDes8& aNum)
       
   241 	{
       
   242     TRACE_FUNC_ENTRY
       
   243 	if(CallStatusL() & KCallRingingBit)
       
   244 		{
       
   245 		TInt count = iLines.Count();
       
   246 		for(TInt i=0; i<count; i++)
       
   247 			{
       
   248 			if(!iLines[i]->IsVoip())
       
   249 			    {
       
   250                 const RPointerArray<CBtmcCallActive>& calls = iLines[i]->ActiveCalls();
       
   251                 TInt count2 = calls.Count();
       
   252                 RMobileConferenceCall myConf;
       
   253                 User::LeaveIfError(myConf.Open(iLines[i]->Phone()));
       
   254                 CleanupClosePushL(myConf);
       
   255                 RMobileCall::TMobileCallInfoV1 info;
       
   256                 RMobileCall::TMobileCallRemotePartyInfoV1 remote;
       
   257 			
       
   258                 for(TInt j=0; j<count2; j++)
       
   259                     {
       
   260                     calls[j]->GetCallInfo(info);
       
   261                     if (info.iStatus == RMobileCall::EStatusRinging
       
   262                        && (info.iValid & RMobileCall::KCallRemoteParty)
       
   263                        && info.iRemoteParty.iRemoteIdStatus == RMobileCall::ERemoteIdentityAvailable)
       
   264                         {
       
   265                         aNum.Copy(info.iRemoteParty.iRemoteNumber.iTelNumber);
       
   266                         break;
       
   267                         }
       
   268                     }
       
   269                 CleanupStack::PopAndDestroy(&myConf);
       
   270 			    }
       
   271 	        }
       
   272 		}
       
   273 	TRACE_FUNC_EXIT
       
   274 	}
       
   275 
       
   276 // ==========================================================
       
   277 // CBtmcCallStatus::GetOutgoingNumL
       
   278 // 
       
   279 // ==========================================================
       
   280 //
       
   281 void CBtmcCallStatus::GetOutgoingNumL(TDes8& aNum)
       
   282 	{
       
   283     TRACE_FUNC_ENTRY
       
   284 	TInt count = iLines.Count();
       
   285 	for(TInt i=0; i<count; i++)
       
   286 		{
       
   287 		const RPointerArray<CBtmcCallActive>& calls = iLines[i]->ActiveCalls();
       
   288 		TInt count2 = calls.Count();
       
   289 		RMobileCall::TMobileCallInfoV1 info;
       
   290 		RMobileCall::TMobileCallRemotePartyInfoV1 remote;
       
   291 		
       
   292 		for(TInt j=0; j<count2; j++)
       
   293 			{
       
   294 			calls[j]->GetCallInfo(info);
       
   295 			if (info.iStatus == RMobileCall::EStatusDialling
       
   296 				&& (info.iValid & RMobileCall::KCallDialledParty))
       
   297 			    {
       
   298 				TPtrC tempPtrC(KNullDesC);
       
   299 				tempPtrC.Set(info.iDialledParty.iTelNumber);
       
   300 				aNum.Copy(tempPtrC);
       
   301 				break;
       
   302 			    }
       
   303 			}
       
   304 		}
       
   305 	TRACE_FUNC_EXIT
       
   306 	}
       
   307 
       
   308 TBTMonoATPhoneNumberType CBtmcCallStatus::NumberType( const TDesC8& aNum )
       
   309     {
       
   310     if (aNum.Length() == 0)
       
   311         {
       
   312         return EBTMonoATPhoneNumberUnavailable;
       
   313         }
       
   314     if(aNum.Locate('+') == 0)
       
   315         {
       
   316         return EBTMonoATPhoneNumberInternational;
       
   317         }
       
   318     return EBTMonoATPhoneNumberNational;
       
   319     }
       
   320 
       
   321 // ==========================================================
       
   322 // CBtmcCallStatus::MakeClccL
       
   323 // 
       
   324 // ==========================================================
       
   325 //
       
   326 CATResult* CBtmcCallStatus::MakeClccL(RMobileCall::TMobileCallInfoV1& info, 
       
   327     RMobileCall::TMobileCallRemotePartyInfoV1& remote, TInt aConferenceCallCount)
       
   328     {
       
   329     TRACE_FUNC_ENTRY
       
   330     RArray<TATParam> params;
       
   331     CleanupClosePushL(params);
       
   332     if(info.iValid & RMobileCall::KCallId)
       
   333         {
       
   334         LEAVE_IF_ERROR(params.Append(TATParam(info.iCallId))) // Index number
       
   335         }
       
   336     else
       
   337         {
       
   338         LEAVE_IF_ERROR(params.Append(TATParam()))
       
   339         }
       
   340         
       
   341     if(remote.iDirection == RMobileCall::EMobileOriginated) // outgoing
       
   342         {
       
   343         LEAVE_IF_ERROR(params.Append(TATParam(0)))
       
   344         }
       
   345     else // unknown or incoming
       
   346         {
       
   347         LEAVE_IF_ERROR(params.Append(TATParam(1)))            
       
   348         }
       
   349         
       
   350     switch(info.iStatus) // status
       
   351         {
       
   352         case RMobileCall::EStatusDialling:
       
   353             {
       
   354             LEAVE_IF_ERROR(params.Append(TATParam(2)))
       
   355             break;
       
   356             }
       
   357         case RMobileCall::EStatusRinging:
       
   358             {
       
   359             TInt status = CallStatusL();
       
   360             if(status & KActiveCallMask)
       
   361             	{
       
   362             	LEAVE_IF_ERROR(params.Append(TATParam(5)))
       
   363             	}
       
   364             else
       
   365 	            {
       
   366             	LEAVE_IF_ERROR(params.Append(TATParam(4)))
       
   367 	            }
       
   368             break;
       
   369             }
       
   370         case RMobileCall::EStatusAnswering:
       
   371             {
       
   372             LEAVE_IF_ERROR(params.Append(TATParam(5)))
       
   373             break;
       
   374             }
       
   375         case RMobileCall::EStatusConnecting:
       
   376             {
       
   377             LEAVE_IF_ERROR(params.Append(TATParam(3)))
       
   378             break;
       
   379             }
       
   380         case RMobileCall::EStatusConnected:
       
   381             {
       
   382             LEAVE_IF_ERROR(params.Append(TATParam(0)))
       
   383             break;
       
   384             }
       
   385         case RMobileCall::EStatusHold:
       
   386             {
       
   387             LEAVE_IF_ERROR(params.Append(TATParam(1)))
       
   388             break;
       
   389             }
       
   390         default:
       
   391             LEAVE_IF_ERROR(params.Append(TATParam(0)))
       
   392         }
       
   393         
       
   394     switch(info.iService) // mode
       
   395         {
       
   396         case RMobilePhone::EVoiceService:
       
   397             {
       
   398             LEAVE_IF_ERROR(params.Append(TATParam(0)))
       
   399             break;
       
   400             }
       
   401         case RMobilePhone::ECircuitDataService:
       
   402         case RMobilePhone::EPacketDataService:
       
   403             {
       
   404             LEAVE_IF_ERROR(params.Append(TATParam(1)))
       
   405             break;
       
   406             }
       
   407         case RMobilePhone::EFaxService:
       
   408             {
       
   409             LEAVE_IF_ERROR(params.Append(TATParam(2)))
       
   410             break;
       
   411             }
       
   412         default:
       
   413             LEAVE_IF_ERROR(params.Append(TATParam(0)))    
       
   414         }
       
   415         
       
   416     // multiparty
       
   417     TATParam param;
       
   418     if(aConferenceCallCount)
       
   419         LEAVE_IF_ERROR(params.Append(TATParam(1)))
       
   420     else
       
   421         LEAVE_IF_ERROR(params.Append(TATParam(0)))
       
   422 
       
   423     // number (optional)
       
   424 	TPtrC tempPtrC(KNullDesC);
       
   425     if ((info.iValid & RMobileCall::KCallRemoteParty) && 
       
   426          info.iRemoteParty.iRemoteIdStatus == RMobileCall::ERemoteIdentityAvailable)
       
   427         {
       
   428         tempPtrC.Set(info.iRemoteParty.iRemoteNumber.iTelNumber);
       
   429         }
       
   430 	else if (info.iValid & RMobileCall::KCallDialledParty)
       
   431 		{
       
   432 		//append number for outgoing call
       
   433 		tempPtrC.Set(info.iDialledParty.iTelNumber);
       
   434 		}
       
   435 	
       
   436 	if(tempPtrC != KNullDesC)
       
   437 		{
       
   438 		TBuf8<100> tempBuf8;
       
   439 		tempBuf8.Copy(tempPtrC); // conversion to 8 bit
       
   440     	LEAVE_IF_ERROR(params.Append(TATParam(tempBuf8, EATDQStringParam)))		
       
   441 
       
   442 	    // type (optional)
       
   443 	    TBTMonoATPhoneNumberType numType = NumberType( tempBuf8 );
       
   444 	    params.AppendL(TATParam(numType));
       
   445 		}
       
   446 
       
   447     CATResult* clcc = CATResult::NewL(EATCLCC, EATActionResult, &params);
       
   448     CleanupStack::PopAndDestroy(&params);
       
   449     TRACE_FUNC_EXIT
       
   450     return clcc;
       
   451     }
       
   452 
       
   453 // ==========================================================
       
   454 // CBtmcCallStatus::MakeVoIPClccL
       
   455 // 
       
   456 // ==========================================================
       
   457 //
       
   458 CATResult* CBtmcCallStatus::MakeVoIPClccL(const MCall &callinfo)
       
   459     {
       
   460     TRACE_FUNC_ENTRY
       
   461     RArray<TATParam> params;
       
   462     CleanupClosePushL(params);
       
   463     LEAVE_IF_ERROR(params.Append(TATParam(1))) // Index number
       
   464     
       
   465     if(callinfo.CallDirection() == CCPCall::EMobileOriginated) // outgoing
       
   466         {        
       
   467         LEAVE_IF_ERROR(params.Append(TATParam(0)))
       
   468         }
       
   469     else // unknown or incoming
       
   470         {        
       
   471         LEAVE_IF_ERROR(params.Append(TATParam(1)))            
       
   472         }       
       
   473     
       
   474     switch(callinfo.CallState()) // status
       
   475         {
       
   476         case CCPCall::EStateDialling:
       
   477             {            
       
   478             LEAVE_IF_ERROR(params.Append(TATParam(2)))
       
   479             break;
       
   480             }
       
   481         case CCPCall::EStateRinging:
       
   482             {            
       
   483             TInt status = CallStatusL();
       
   484             if(status & KActiveCallMask)
       
   485                 {
       
   486                 LEAVE_IF_ERROR(params.Append(TATParam(5)))
       
   487                 }
       
   488             else
       
   489                 {
       
   490                 LEAVE_IF_ERROR(params.Append(TATParam(4)))
       
   491                 }
       
   492             break;
       
   493             }
       
   494         case CCPCall::EStateAnswering:
       
   495             {            
       
   496             LEAVE_IF_ERROR(params.Append(TATParam(5)))
       
   497             break;
       
   498             }
       
   499         case CCPCall::EStateConnecting:
       
   500             {            
       
   501             LEAVE_IF_ERROR(params.Append(TATParam(3)))
       
   502             break;
       
   503             }
       
   504         case CCPCall::EStateConnected:
       
   505             {            
       
   506             LEAVE_IF_ERROR(params.Append(TATParam(0)))
       
   507             break;
       
   508             }
       
   509         case CCPCall::EStateHold:
       
   510             {         
       
   511             LEAVE_IF_ERROR(params.Append(TATParam(1)))
       
   512             break;
       
   513             }
       
   514         default:            
       
   515             LEAVE_IF_ERROR(params.Append(TATParam(0)))
       
   516         }
       
   517         
       
   518     LEAVE_IF_ERROR(params.Append(TATParam(1)))
       
   519         
       
   520     // multiparty
       
   521     LEAVE_IF_ERROR(params.Append(TATParam(0)))
       
   522 
       
   523     CATResult* clcc = CATResult::NewL(EATCLCC, EATActionResult, &params);
       
   524     CleanupStack::PopAndDestroy(&params);
       
   525     TRACE_FUNC_EXIT
       
   526     return clcc;
       
   527     }
       
   528 
       
   529 // Sending Call Waiting notification
       
   530 // if incoming call starts ringing and there is active call already. 
       
   531 // <+CCWA: "nnn", 129, 1> when calling number is national
       
   532 // <+CCWA: "nnn", 145, 1> when calling number is international (first char is '+')
       
   533 // <+CCWA: "", 128, 1>    when calling number is not available
       
   534 
       
   535 // RING is started in the following cases:
       
   536 //
       
   537 // 1. call is ringing (RMobileCall::EStatusRinging) and no active calls exist.
       
   538 // 2. call is terminating (RMobileCall::EStatusIdle) and ringing call exists.
       
   539 
       
   540 
       
   541 // Call status notification 
       
   542 // +CIEV: 2,0 is generated if last active(Connected or Hold)call disconnects
       
   543 // +CIEV: 2,1 is generated if first call becomes active
       
   544 //
       
   545 
       
   546 // Call setup status notification 
       
   547 // +CIEV: 3,0 if call set up state ends
       
   548 // +CIEV: 3,1 if an incoming call set up is ongoing
       
   549 // +CIEV: 3,2 if an outgoing call set up is ongoing
       
   550 // +CIEV: 3,3 if remote party being alerted in an outgoing call
       
   551 
       
   552 void CBtmcCallStatus::HandleMobileCallEventL(
       
   553     const TName& aName,
       
   554     const TDesC& aRemotePartyName,
       
   555     RMobileCall::TMobileCallStatus aStatus, TBool aOutgoingCall)
       
   556     {
       
   557     TRACE_FUNC_ENTRY
       
   558     TRACE_INFO((_L("INDICATOR STATUS: CIEV 0x%08x, CLI %d, CCWA %d, previous CALL BITS 0x%08x, OutgoingCall %d"), 
       
   559         iProtocol.ProtocolStatus().iIndicatorNotif, iProtocol.ProtocolStatus().iCallerIdNotif, iProtocol.ProtocolStatus().iCallWaitingNotif,
       
   560         iProtocol.ProtocolStatus().iCallBits, iProtocol.ProtocolStatus().iOutgoingCallNotif))
       
   561         
       
   562     TRACE_INFO((_L("NAME '%S', REMOTE PARTY '%S', STATUS %d"), 
       
   563         &aName, &aRemotePartyName, aStatus)); (void) aName; (void) aStatus;
       
   564         
       
   565     (void) aRemotePartyName;
       
   566 
       
   567     TInt callBits = CallStatusL();
       
   568     //Before SLC, no event will be reported
       
   569     if (iProtocol.ProtocolStatus().iSlc)
       
   570         {
       
   571         ReportCallEventL(iProtocol.ProtocolStatus().iCallBits, callBits, aOutgoingCall);
       
   572         }
       
   573     iProtocol.ProtocolStatus().iCallBits = callBits;
       
   574     TRACE_FUNC_EXIT
       
   575     }
       
   576 
       
   577 void CBtmcCallStatus::ReportRingAndClipL(TBool aColp)
       
   578     {
       
   579     TRACE_FUNC_ENTRY
       
   580    	CATResult* event = CATResult::NewLC(EATRING, EATUnsolicitedResult);
       
   581     RArray<TATParam> params;
       
   582     CleanupClosePushL(params);   	
       
   583 
       
   584     if(!aColp)
       
   585     	{
       
   586     	iProtocol.SendUnsoltResultL(*event);
       
   587     	}
       
   588  
       
   589     if (iProtocol.ProtocolStatus().iCallerIdNotif == EBTMonoATCallerIdNotifEnabled && !aColp)
       
   590         {
       
   591         TRACE_INFO((_L("CLIP")))
       
   592         GetRingingNumL( iRemoteTelNum );
       
   593         TBTMonoATPhoneNumberType numType = NumberType( iRemoteTelNum );
       
   594         params.AppendL(TATParam(iRemoteTelNum, EATDQStringParam));
       
   595         params.AppendL(TATParam(numType));
       
   596        	LEAVE_IF_ERROR(event->Set(EATCLIP, EATUnsolicitedResult, &params))
       
   597 		iProtocol.SendUnsoltResultL(*event);
       
   598 		}
       
   599 	else if( iProtocol.ProtocolStatus().iOutgoingCallNotif && aColp ) // COLP
       
   600 		{
       
   601         TRACE_INFO((_L("COLP")))
       
   602 		GetOutgoingNumL(iRemoteTelNum);
       
   603         TBTMonoATPhoneNumberType numType = NumberType( iRemoteTelNum );
       
   604         params.AppendL(TATParam(iRemoteTelNum, EATDQStringParam));
       
   605         params.AppendL(TATParam(numType));
       
   606        	LEAVE_IF_ERROR(event->Set(EATCOLP, EATUnsolicitedResult, &params))
       
   607 		iProtocol.SendUnsoltResultL(*event);
       
   608 		}
       
   609 
       
   610     CleanupStack::PopAndDestroy(&params);
       
   611     CleanupStack::PopAndDestroy(event);    
       
   612     TRACE_FUNC_EXIT
       
   613     }
       
   614 
       
   615 // ==========================================================
       
   616 // CBtmcCallStatus::ReportCallEventL
       
   617 // 
       
   618 // ==========================================================
       
   619 //
       
   620 void CBtmcCallStatus::ReportCallEventL(TInt aPrevStatus, TInt aNewStatus, TBool /*aOutgoing*/)
       
   621     {
       
   622     TRACE_FUNC_ENTRY
       
   623     // CCWA
       
   624     if (iProtocol.ProtocolStatus().iCallWaitingNotif == EBTMonoATCallWaitingNotifEnabled && 
       
   625         (!(aPrevStatus & KCallRingingBit) && (aNewStatus & KCallRingingBit)) &&
       
   626         ((aNewStatus & KCallConnectedBit) || 
       
   627          (aNewStatus & KCallHoldBit)))
       
   628         {
       
   629         StopTimer(KRingTimerService);
       
   630         GetRingingNumL( iRemoteTelNum );
       
   631         TBTMonoATPhoneNumberType numType = NumberType( iRemoteTelNum );
       
   632         RArray<TATParam> params;
       
   633         CleanupClosePushL(params);
       
   634         params.AppendL(TATParam(iRemoteTelNum, EATDQStringParam));
       
   635         params.AppendL(TATParam(numType));
       
   636         params.AppendL(TATParam(1));
       
   637         CATResult* ccwa = CATResult::NewLC(EATCCWA, EATUnsolicitedResult, &params);
       
   638         iProtocol.SendUnsoltResultL(*ccwa);
       
   639         CleanupStack::PopAndDestroy(ccwa);
       
   640         CleanupStack::PopAndDestroy(&params);
       
   641         }
       
   642         
       
   643     // Call and setup status
       
   644     if (iProtocol.ProtocolStatus().iIndicatorNotif)
       
   645         {    
       
   646         TInt presta = 0;
       
   647         presta |= (aPrevStatus & KCallConnectedBit) | (aPrevStatus & KCallHoldBit);
       
   648         
       
   649         TInt newsta = 0;
       
   650         newsta |= (aNewStatus & KCallConnectedBit) | (aNewStatus & KCallHoldBit);
       
   651         
       
   652         TRACE_INFO((_L("call (Active and Held): presta 0x%08x, newsta 0x%08x"), presta, newsta))
       
   653         
       
   654         // Call status
       
   655         // If an active call is terminated by AT+CHLD=1, we should not send NoCall indication.
       
   656         if (presta && !newsta && 
       
   657                 !(iProtocol.ActiveChldHandling() && ( aNewStatus & KCallRingingBit ) ) )
       
   658             {
       
   659             ReportCallIndicatorL(EBTMonoATCallIndicator, EBTMonoATNoCall); 
       
   660             }
       
   661         else if (!presta && newsta)
       
   662             {
       
   663 	        ReportCallIndicatorL(EBTMonoATCallIndicator, EBTMonoATCallActive);
       
   664             }
       
   665 
       
   666         // Call setup status    
       
   667         presta = 0;
       
   668         presta |= (aPrevStatus & KCallDiallingBit) | 
       
   669                   (aPrevStatus & KCallRingingBit) | 
       
   670                   (aPrevStatus & KCallAnsweringBit) | 
       
   671                   (aPrevStatus & KCallConnectingBit);
       
   672                  
       
   673         newsta = 0;
       
   674         newsta |= (aNewStatus & KCallDiallingBit) | 
       
   675                   (aNewStatus & KCallRingingBit) | 
       
   676                   (aNewStatus & KCallAnsweringBit) | 
       
   677                   (aNewStatus & KCallConnectingBit);
       
   678         TRACE_INFO((_L("call setup: presta 0x%08x, newsta 0x%08x"), presta, newsta))
       
   679 
       
   680         if (presta != newsta && !(aNewStatus & KCallAnsweringBit))
       
   681             {
       
   682             TInt callSetupInd = EBTMonoATNoCallSetup;
       
   683 
       
   684             if (newsta & KCallRingingBit)
       
   685                 {
       
   686                 callSetupInd = EBTMonoATCallRinging;
       
   687                 }
       
   688             else if (newsta & KCallDiallingBit)
       
   689                 {
       
   690                 callSetupInd = EBTMonoATCallDialling;
       
   691                 }
       
   692             else if (newsta & KCallConnectingBit)
       
   693                 {
       
   694                 callSetupInd = EBTMonoATCallConnecting;
       
   695                 }
       
   696             ReportCallIndicatorL(EBTMonoATCallSetupIndicator, callSetupInd);
       
   697             ReportCallIndicatorL(EBTMonoATCall_SetupIndicator, callSetupInd);
       
   698 		    // COLP
       
   699             if( (newsta & KCallDiallingBit) &&  iProtocol.ProtocolStatus().iOutgoingCallNotif)
       
   700             	ReportRingAndClipL(ETrue);
       
   701             }
       
   702         
       
   703         // Call Held status
       
   704         if ((aPrevStatus & KCallHoldBit) && !(aNewStatus & KCallHoldBit))
       
   705             {
       
   706             ReportCallIndicatorL(EBTMonoATCallHeldIndicator, EBTMonoATNoCallHeld);
       
   707             }
       
   708         else if (!(aPrevStatus & KCallHoldBit) && (aNewStatus & KCallHoldBit))
       
   709             {
       
   710             if ((aNewStatus & KCallConnectedBit))
       
   711                 {
       
   712                 ReportCallIndicatorL(EBTMonoATCallHeldIndicator, EBTMonoATCallHeldAndActive);
       
   713                 }
       
   714             else if (!(aNewStatus & KCallConnectedBit) && !(aNewStatus & KCallRingingBit))
       
   715                 {
       
   716                 ReportCallIndicatorL(EBTMonoATCallHeldIndicator, EBTMonoATCallHeldOnly);
       
   717                 }
       
   718             }
       
   719         else if ((aPrevStatus & KCallHoldBit) && (aNewStatus & KCallHoldBit))
       
   720             {
       
   721             if ((aPrevStatus & KCallConnectedBit) && !(aNewStatus & KCallConnectedBit))
       
   722                 {
       
   723                 ReportCallIndicatorL(EBTMonoATCallHeldIndicator, EBTMonoATCallHeldOnly);
       
   724                 }
       
   725             else if (!(aPrevStatus & KCallConnectedBit) && (aNewStatus & KCallConnectedBit))
       
   726                 {
       
   727                 ReportCallIndicatorL(EBTMonoATCallHeldIndicator, EBTMonoATCallHeldAndActive);
       
   728                 }
       
   729             }
       
   730         }
       
   731 
       
   732     // Ring 
       
   733     // We can not send RING when the active call is ended and 
       
   734     // waiting call answered by AT+CHLD=1.
       
   735     if (!(aNewStatus & KCallConnectedBit) && 
       
   736         !(aNewStatus & KCallHoldBit) && 
       
   737         (aNewStatus & KCallRingingBit) &&
       
   738         !iProtocol.ActiveChldHandling() )
       
   739         {
       
   740         ReportRingAndClipL();
       
   741         StartTimerL(KRingTimerService, KRingInterval);
       
   742         }
       
   743     else
       
   744         {
       
   745         StopTimer(KRingTimerService);
       
   746         }
       
   747     TRACE_FUNC_EXIT
       
   748     }
       
   749 
       
   750 // ==========================================================
       
   751 // CBtmcCallStatus::StartTimerL
       
   752 // 
       
   753 // ==========================================================
       
   754 //
       
   755 void CBtmcCallStatus::StartTimerL(TInt aService, TInt aTimeout)
       
   756     {
       
   757     if (!iTimerActive)
       
   758         {
       
   759         TRACE_FUNC_ENTRY
       
   760         iTimerActive = CBtmcActive::NewL(*this, CActive::EPriorityStandard, aService);
       
   761         iTimer.CreateLocal();
       
   762         iTimer.After(iTimerActive->iStatus, aTimeout);
       
   763         iTimerActive->GoActive();
       
   764         TRACE_FUNC_EXIT
       
   765         }
       
   766     else
       
   767         {
       
   768         TRACE_WARNING(_L("WARNING, timer is active already"))
       
   769         }
       
   770     }
       
   771 // ==========================================================
       
   772 // CBtmcCallStatus::StopTimer
       
   773 // 
       
   774 // ==========================================================
       
   775 //
       
   776 void CBtmcCallStatus::StopTimer(TInt aService)
       
   777     {
       
   778     if (iTimerActive && iTimerActive->ServiceId() == aService)
       
   779         {
       
   780         TRACE_FUNC_ENTRY
       
   781         delete iTimerActive;
       
   782         iTimerActive = NULL;
       
   783         iTimer.Close();
       
   784         TRACE_FUNC_EXIT
       
   785         }
       
   786     }
       
   787 // ==========================================================
       
   788 // CBtmcCallStatus::ReportCallIndicatorL
       
   789 // 
       
   790 // ==========================================================
       
   791 //
       
   792 void CBtmcCallStatus::ReportCallIndicatorL(TBTMonoATPhoneIndicatorId aIndicator, TInt aValue)
       
   793     {
       
   794     TRACE_FUNC_ENTRY
       
   795     TRACE_INFO((_L("indicator %d, value %d"), aIndicator, aValue))
       
   796     RArray<TATParam> params;
       
   797     CleanupClosePushL(params);
       
   798     params.AppendL(TATParam(aIndicator));
       
   799     params.AppendL(TATParam(aValue));
       
   800     CATResult* ciev = CATResult::NewLC(EATCIEV, EATUnsolicitedResult, &params);
       
   801     iProtocol.SendUnsoltResultL(*ciev);
       
   802     CleanupStack::PopAndDestroy(ciev);
       
   803     CleanupStack::PopAndDestroy(&params);
       
   804     TRACE_FUNC_EXIT
       
   805     }
       
   806     
       
   807 // End of File