bluetoothengine/btsac/src/btsacStateConnected.cpp
changeset 0 f63038272f30
child 1 6a1fe72036e3
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2002-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:  In this state, BTSAC is listening for remote connection
       
    15 *								 from a stereo audio accessory
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "btsacStateConnected.h"
       
    24 #include "btsacStateConfigured.h"
       
    25 #include "btsacStateConfiguring.h"
       
    26 #include "btsacStateListening.h"
       
    27 #include "btsacStateAborting.h"
       
    28 #include "btsacactive.h"
       
    29 #include "btsacGavdp.h"
       
    30 #include "btsacSEPManager.h"
       
    31 #include "btsacStreamerController.h"
       
    32 #include "debug.h"
       
    33 
       
    34 // A2DP codec-specific element definitions
       
    35 // in bluetoothAV.h
       
    36 using namespace SymbianBluetoothAV;   
       
    37 
       
    38 // Subband codec-specific values
       
    39 // in bluetoothAV.h
       
    40 using namespace SymbianSBC;   
       
    41 
       
    42 const TInt KSEPDiscoverResponseDelay = 5000000; 	// 5 sec
       
    43 const TInt KGetCapabilitiesResponseDelay = 4000000; // 4 sec
       
    44 const TInt KSEPConfigureResponseDelay = 4000000; 	// 4 sec
       
    45 const TInt KCreateBearersResponseDelay = 5000000; 	// 5 sec
       
    46 const TInt KWaitConfStartIndicationDelay = 3000000; // 3 sec
       
    47 const TInt KOneSecondDelay = 1000000; 				// 1 sec
       
    48 
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =======================
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CBtsacConnected::NewL
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CBtsacConnected* CBtsacConnected::NewL(CBTSAController& aParent, TBTConnType aConnType)
       
    57     {
       
    58     CBtsacConnected* self = new( ELeave ) CBtsacConnected(aParent, aConnType);
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop(self);
       
    62     return self;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CBtsacConnected::CBtsacConnected
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CBtsacConnected::CBtsacConnected(CBTSAController& aParent, TBTConnType aConnType)
       
    70 :	CBtsacState(aParent, EStateConnected), iSuitableSEPFoundAlready(EFalse), iConnType(aConnType),
       
    71 	iSEPFound(ESEPNotInitialized), iRemoteSEPIndex(0), iBearersQuery(EFalse), iCancelConnectReq(EFalse),
       
    72 	iAudioOpenedBy(EAudioOpenedByNone)
       
    73     {
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CBtsacConnected::ConstructL
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CBtsacConnected::ConstructL()
       
    81 	{
       
    82 	iTimerActive = CBtsacActive::NewL(*this, CActive::EPriorityStandard, KRequestIdTimer);
       
    83 	iTimer.CreateLocal();
       
    84 	}
       
    85     
       
    86 // -----------------------------------------------------------------------------
       
    87 // CBtsacConnected::~CBtsacConnected
       
    88 // -----------------------------------------------------------------------------
       
    89 //    
       
    90 CBtsacConnected::~CBtsacConnected()
       
    91     {
       
    92     TRACE_FUNC_ENTRY
       
    93     delete iTimerActive;
       
    94     iTimerActive = NULL;
       
    95     iTimer.Close();
       
    96     TRACE_FUNC_EXIT
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CBtsacConnected::EnterL
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CBtsacConnected::EnterL()
       
   104     {
       
   105 	TRACE_STATE(_L("[BTSAC State] Connected"))	
       
   106 	_LIT(KName, "CBtsacStateConnected");
       
   107 	const TDesC& Name = KName;
       
   108 	Parent().iGavdp->RegisterObserver(this, Name);
       
   109 
       
   110 	switch(iConnType)
       
   111 		{
       
   112 		case EOutgoingConnWithAudio:
       
   113 		case EOutgoingConn:
       
   114 			{
       
   115 			if(iConnType == EOutgoingConnWithAudio)
       
   116 				{
       
   117 				iAudioOpenedBy = EAudioOpenedByAFW;
       
   118 				}
       
   119 			StartTimer(KSEPDiscoverResponseDelay, KRequestIdTimer);
       
   120 			Parent().iGavdp->DiscoverSEPs(); // start with SEP discovery			
       
   121 			break;
       
   122 			}
       
   123 		case EOutgoingConnWithAudioNoDiscovery:
       
   124 		case EOutgoingConnNoDiscovery:
       
   125 			{
       
   126 			if(iConnType == EOutgoingConnWithAudioNoDiscovery)
       
   127 				{
       
   128 				iAudioOpenedBy = EAudioOpenedByAFW;
       
   129 				}
       
   130 			ConfigureL();
       
   131 			break;
       
   132 			}
       
   133 		case EIncomingConn:
       
   134 			{
       
   135 			Parent().NewAccessory(Parent().GetRemoteAddr());
       
   136 			break;
       
   137 			}
       
   138 		case EConnExists:
       
   139 			break;
       
   140 		}
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CBtsacConnected::StartTimer
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CBtsacConnected::StartTimer(TTimeIntervalMicroSeconds32 aTimeout, TInt aRequestId)
       
   148 	{
       
   149 	TRACE_FUNC
       
   150 	if (iTimerActive)
       
   151     	{
       
   152 	    if(!iTimerActive->IsActive())
       
   153 		    {	    	
       
   154 	        iTimerActive->SetRequestId(aRequestId);
       
   155 	        iTimer.After(iTimerActive->iStatus, aTimeout);
       
   156 	        iTimerActive->GoActive();
       
   157 		    }
       
   158         }
       
   159     else
       
   160     	{
       
   161     	TRACE_INFO((_L("CBtsacConnected::StartTimer, Timer Active doesn't exist.")))
       
   162     	}
       
   163 	}
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CBtsacConnected::StopTimer
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CBtsacConnected::StopTimer()
       
   170 	{
       
   171 	TRACE_FUNC
       
   172 	if (iTimerActive)
       
   173     	{
       
   174 		iTimerActive->Cancel();
       
   175         }
       
   176 	}
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CBtsacConnected::CancelActionL
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CBtsacConnected::CancelActionL(TInt aError, TBTSACGavdpResetReason aGavdpReset)
       
   183     {
       
   184     TRACE_FUNC
       
   185     StopTimer();
       
   186 	Parent().CompletePendingRequests((KConnectReq | KOpenAudioReq), aError);
       
   187 	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), aGavdpReset, aError));
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CBtsacConnected::OpenAudioLinkL
       
   192 // -----------------------------------------------------------------------------
       
   193 //    
       
   194 void CBtsacConnected::OpenAudioLinkL(const TBTDevAddr& aAddr)
       
   195 	{  
       
   196 	TRACE_FUNC	
       
   197 	
       
   198 	if (Parent().GetRemoteAddr() != aAddr)
       
   199 		{
       
   200 		TRACE_INFO((_L("CBtsacConnected::OpenAudio, Error!")))
       
   201 		CancelActionL(KErrNotFound, EGavdpResetReasonGeneral);
       
   202 		return;
       
   203 		}
       
   204 	iAudioOpenedBy = EAudioOpenedByAFW;
       
   205 	Parent().SetRemoteAddr(aAddr);
       
   206 	
       
   207 	if(iConnType == EIncomingConn)
       
   208 		{
       
   209 		// Accessory has created connection to us. Don't open audio immediately, 
       
   210 		// let's wait for a while if accessory starts configuration. This way
       
   211 		// we can avoid configure collision.
       
   212 		StartTimer(KOneSecondDelay, KRequestIdWaitRemoteConfStart);
       
   213 		}
       
   214 	else
       
   215 		{
       
   216 		StartConfigurationL();
       
   217 		}
       
   218 	}
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CBtsacConnected::CancelOpenAudioLinkL()
       
   222 // -----------------------------------------------------------------------------
       
   223 //    
       
   224 void CBtsacConnected::CancelOpenAudioLinkL()
       
   225     {
       
   226     TRACE_FUNC
       
   227 	CancelActionL(KErrCancel, EGavdpResetReasonGeneral);
       
   228     }
       
   229 	
       
   230 // -----------------------------------------------------------------------------
       
   231 // CBtsacConnected::DisconnectL
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void CBtsacConnected::DisconnectL()
       
   235 	{
       
   236 	TRACE_FUNC
       
   237 	Parent().CompletePendingRequests(KDisconnectReq, KErrNone);
       
   238 	CancelActionL(KErrCancel, EGavdpResetReasonDisconnect);
       
   239 	}
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CBtsacConnected::CancelConnectL
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CBtsacConnected::CancelConnectL()
       
   246     {
       
   247     TRACE_FUNC
       
   248     if(!iBearersQuery)
       
   249     	{
       
   250 		CancelActionL(KErrCancel, EGavdpResetReasonGeneral);
       
   251     	}
       
   252     else
       
   253     	{
       
   254     	// We have to wait bearers to be completed
       
   255     	TRACE_INFO((_L("CBtsacConnected::CancelConnectL() Wait for BearerReady.")))
       
   256     	iCancelConnectReq = ETrue;
       
   257     	}
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CBtsacConnected::StartConfigurationL()
       
   262 // -----------------------------------------------------------------------------
       
   263 //    
       
   264 void CBtsacConnected::StartConfigurationL()
       
   265 	{
       
   266 	TRACE_FUNC
       
   267 	if (!Parent().iRemoteSEPs->NoOfSEPs())	// if accessory info not stored already
       
   268 		{
       
   269 		iRemoteSEPIndex = 0;
       
   270 		Parent().InitializeSEPManager();
       
   271 		StartTimer(KSEPDiscoverResponseDelay, KRequestIdTimer);
       
   272 		Parent().iGavdp->DiscoverSEPs();		// start with SEP discovery
       
   273 		}
       
   274 	else	// otherwise we have explored this accessory before - go straight to configure 
       
   275 		{
       
   276 		ConfigureL();
       
   277 		}
       
   278 	}
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CBtsacConnected::ConfigureL
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 void CBtsacConnected::ConfigureL()
       
   285     {
       
   286     TRACE_FUNC
       
   287    
       
   288  	RPointerArray<TAvdtpServiceCapability> SEPCapabilities;
       
   289     if ((Parent().iRemoteSEPs->GetCaps(Parent().GetSEPIndex(), SEPCapabilities)) )
       
   290 		{
       
   291 		TRACE_INFO((_L("CBtsacConnected::Configure() Couldn't retrieve Capabilities !")))
       
   292 		CancelActionL(KErrCancel, EGavdpResetReasonGeneral);
       
   293 	   	SEPCapabilities.Close();
       
   294 		return; 
       
   295 		}   
       
   296     
       
   297 	TRACE_INFO((_L("CBtsacConnected::Configure() Retrieve %d capabilities"), SEPCapabilities.Count()))
       
   298    	// loop through all capablities to find sbc codec capablities
       
   299    	TSBCCodecCapabilities SBCCaps; 
       
   300    	TAvdtpMediaTransportCapabilities MedTransCaps; 
       
   301    	for (TInt index=0; index < SEPCapabilities.Count(); index++)		
       
   302    		{
       
   303 		TAvdtpServiceCapability* cap = SEPCapabilities[index];
       
   304 		TAvdtpServiceCategory cat = cap->Category();
       
   305 		if ( cat == EServiceCategoryMediaCodec )
       
   306 			{
       
   307 		    SBCCaps = static_cast<TSBCCodecCapabilities&>(*cap);	
       
   308 		    TRACE_INFO((_L("CBtsacConnected::Configure() SBC Caps retrieved.")))
       
   309 			}
       
   310 		else if ( cat == EServiceCategoryMediaTransport )
       
   311 			{
       
   312 			MedTransCaps = static_cast<TAvdtpMediaTransportCapabilities&>(*cap);
       
   313 			TRACE_INFO((_L("CBtsacConnected::Configure() Media Transport Caps retrieved.")))
       
   314 			}
       
   315    		}
       
   316    	SEPCapabilities.Close();
       
   317 
       
   318    // Check if headset's capabilities suits us				
       
   319 	TRACE_INFO((_L("CBtsacConnected::Configure() Accessory Sampling Frequencies: %d"), SBCCaps.SamplingFrequencies()))
       
   320 	TRACE_INFO((_L("CBtsacConnected::Configure() Accessory Channel modes: %d"), SBCCaps.ChannelModes()))
       
   321 	TRACE_INFO((_L("CBtsacConnected::Configure() Accessory Blocks: %d"), SBCCaps.BlockLengths()))
       
   322 	TRACE_INFO((_L("CBtsacConnected::Configure() Accessory SubBands: %d"), SBCCaps.Subbands()))
       
   323 	TRACE_INFO((_L("CBtsacConnected::Configure() Accessory Alloc method: %d"), SBCCaps.AllocationMethods()))
       
   324 	TRACE_INFO((_L("CBtsacConnected::Configure() Accessory Max bitpool: %d"), SBCCaps.MaxBitpoolValue()))
       
   325 	TRACE_INFO((_L("CBtsacConnected::Configure() Accessory Min bitpool: %d"), SBCCaps.MinBitpoolValue()))
       
   326 	
       
   327 	if (Parent().iStreamer->ConfigureSEP(SBCCaps) )
       
   328 		{
       
   329    		TRACE_INFO((_L("CBtsacConnected::Configure() Streamer couldn't configure SEP !")))
       
   330         CancelActionL(KErrCancel, EGavdpResetReasonGeneral); 
       
   331         return;   // capabilites doesn't suit us
       
   332 		}
       
   333 		
       
   334 	TAvdtpSEPInfo SEPInfo;
       
   335 	if (Parent().iRemoteSEPs->GetInfo(Parent().GetSEPIndex(), SEPInfo))
       
   336 		{
       
   337 		TRACE_INFO((_L("CBtsacConnected::Configure() Couldn't retrieve SEP Info !")))
       
   338 		CancelActionL(KErrCancel, EGavdpResetReasonGeneral); 
       
   339         return;   // capabilites doesn't suit us
       
   340 		}
       
   341 	TSEID remoteSEPid = SEPInfo.SEID(); 	
       
   342 	// local sep index is hard coded cause current implementation is only sbc encoded
       
   343 	TSEID localSEPid = TSEID(1, ETrue);
       
   344  	
       
   345  	StartTimer(KSEPConfigureResponseDelay, KRequestIdTimer);
       
   346 	if ( Parent().iGavdp->ConfigureSEP(localSEPid, remoteSEPid , SBCCaps, MedTransCaps ) )
       
   347 		{
       
   348 		TRACE_INFO((_L("CBtsacConnected::Configure() ConfigureSEP returned Error !!!")))
       
   349 		CancelActionL(KErrCancel, EGavdpResetReasonGeneral);
       
   350 		}
       
   351     }
       
   352     
       
   353 // -----------------------------------------------------------------------------
       
   354 // CBtsacConnected::GetCapabilitiesOfAllSEPs
       
   355 // -----------------------------------------------------------------------------
       
   356 //
       
   357 void CBtsacConnected::GetCapabilitiesOfAllSEPs()
       
   358 	{
       
   359 	TRACE_INFO((_L("CBtsacConnected::GetCapabilitiesOfAllSEPs() CurrentSEP:%d"), iRemoteSEPIndex))
       
   360 	TRACE_INFO((_L("CBtsacConnected::GetCapabilitiesOfAllSEPs() Total Remote SEPs registered:%d"), Parent().iRemoteSEPs->NoOfSEPs()))
       
   361 
       
   362 	if ( iRemoteSEPIndex < Parent().iRemoteSEPs->NoOfSEPs() )
       
   363 		{
       
   364 		TAvdtpSEPInfo SEPInfo;
       
   365 		if (!Parent().iRemoteSEPs->GetInfo(iRemoteSEPIndex, SEPInfo))
       
   366 			{
       
   367 			TSEID id = SEPInfo.SEID(); 
       
   368 			Parent().iGavdp->GetCapabilities(id);	
       
   369 			}
       
   370 		}
       
   371 	else // we have covered all SEPs
       
   372 		{
       
   373 		StopTimer();
       
   374 		// store all info in our db
       
   375 		//Parent().StoreAccInfo();  // stores iRemoteSEPs (SEPManager) into database
       
   376 		iSuitableSEPFoundAlready = EFalse;
       
   377 		
       
   378 		if ( iSEPFound == ESEPConfigure ) 
       
   379 			{
       
   380 			TRAP_IGNORE(ConfigureL());
       
   381 			}
       
   382 		else if ( iSEPFound == ESEPInUse )
       
   383 			{
       
   384 			// We have open audio or connect request pending but do not complete it yet. We expect that
       
   385 			// accessory will start configure us. We should receive GAVDP_ConfigurationStartIndication
       
   386 			// from the remote and remote will configure us. Eventually acc FW's open audio request
       
   387 			// will be completed in CBTsacConfigured state and connect request will be completed in
       
   388 			// CBTsacConfiguring state.
       
   389 
       
   390 			// For safety's sake start timer to protect the situation where we do not receive
       
   391 			// GAVDP_ConfigurationStartIndication.
       
   392 			StartTimer(KWaitConfStartIndicationDelay, KRequestIdTimer);
       
   393 			}
       
   394 		else // no audio sbc sink sep found
       
   395 			{
       
   396 			TRAP_IGNORE(CancelActionL(KErrCancel, EGavdpResetReasonGeneral));
       
   397 			}
       
   398 		}
       
   399 	}
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // CBtsacConnected::GAVDP_SEPDiscovered
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 void CBtsacConnected::GAVDP_SEPDiscovered(const TAvdtpSEPInfo& aSEPInfo)
       
   406 	{
       
   407 	TRACE_INFO((_L("CBtsacConnected:::GAVDP_SEPDiscovered() SEID: %d  InUse: %d  MediaType: %d  IsSink: %d"),
       
   408 				aSEPInfo.SEID().SEID(), aSEPInfo.InUse(), aSEPInfo.MediaType(), aSEPInfo.IsSink()))
       
   409 	
       
   410 	// BTSAC cares only about audio SEPs which are sink
       
   411      if (aSEPInfo.MediaType() == EAvdtpMediaTypeAudio && aSEPInfo.IsSink() )
       
   412      	{
       
   413   		TRAPD(err, Parent().iRemoteSEPs->NewSEPL(aSEPInfo))
       
   414 		if (!err)
       
   415 			{
       
   416 			Parent().iRemoteSEPs->SetState(aSEPInfo.SEID(), CBTSACStreamEndPoint::EDiscoveredRemote, &aSEPInfo);
       
   417 			}
       
   418 		else // internal problem
       
   419 			{
       
   420   			TRAP_IGNORE(CancelActionL(KErrCancel, EGavdpResetReasonGeneral));
       
   421 			}
       
   422      	}
       
   423 	}
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // CBtsacConnected::GAVDP_SEPDiscoveryComplete
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 void CBtsacConnected::GAVDP_SEPDiscoveryComplete()
       
   430 	{
       
   431 	TRACE_FUNC
       
   432 	StopTimer();
       
   433 	if ( Parent().iRemoteSEPs->NoOfSEPs() )
       
   434 		{
       
   435 		StartTimer(KGetCapabilitiesResponseDelay, KRequestIdTimer);
       
   436 		GetCapabilitiesOfAllSEPs();
       
   437 		}
       
   438 	else // remote A2DP has no 'audio' 'sink' SEPs ! naughty remote
       
   439 		{
       
   440 		TRACE_INFO((_L("CBtsacConnected::GAVDP_SEPDiscoveryComplete() Remote A2dP has no 'audio' 'sink' SEPs !")))
       
   441 		TRAP_IGNORE(CancelActionL(KErrCancel, EGavdpResetReasonGeneral));
       
   442 		}
       
   443 	}
       
   444 	
       
   445 // -----------------------------------------------------------------------------
       
   446 // CBtsacConnected::GAVDP_SEPCapability
       
   447 // -----------------------------------------------------------------------------
       
   448 //	
       
   449 void CBtsacConnected::GAVDP_SEPCapability(TAvdtpServiceCapability* aCapability)
       
   450 	{
       
   451 	TRACE_INFO((_L("CBtsacConnected::GAVDP_SEPCapability(%d)"), aCapability->Category()))
       
   452 
       
   453 	Parent().iRemoteSEPs->StoreCaps(iRemoteSEPIndex, aCapability);
       
   454 	
       
   455 	if( iSuitableSEPFoundAlready )
       
   456 		{
       
   457 		return; 
       
   458 		}
       
   459 
       
   460 	if ( aCapability->Category() == EServiceCategoryMediaCodec )
       
   461 		{
       
   462 		TAvdtpMediaCodecCapabilities& codecCaps = static_cast<TAvdtpMediaCodecCapabilities&>(*aCapability);
       
   463 		TAvdtpSEPInfo SEPInfo;
       
   464 		TBool InUse = EFalse;
       
   465 
       
   466 		if ( !Parent().iRemoteSEPs->GetInfo(iRemoteSEPIndex, SEPInfo))
       
   467 			{
       
   468 			InUse = SEPInfo.InUse();
       
   469 			}
       
   470 		else
       
   471 			{
       
   472 			TRACE_INFO((_L("CBtsacConnected::GAVDP_SEPCapability() Couldn't retrieve SEP Info !")))
       
   473 			return;
       
   474 			}
       
   475 
       
   476 		if ( (codecCaps.MediaCodecType() == EAudioCodecSBC) && !InUse) // found SEP that we are interested in
       
   477 			{
       
   478 			TRACE_INFO((_L("CBtsacConnected::GAVDP_SEPCapability() Found SBC Audio Sink SEP !!!")))
       
   479 			iSuitableSEPFoundAlready = ETrue;
       
   480 			iSEPFound = ESEPConfigure;
       
   481 			Parent().SetSEPIndex(iRemoteSEPIndex);
       
   482 			}
       
   483 		else
       
   484 			{
       
   485 			TRACE_INFO((_L("CBtsacConnected::GAVDP_SEPCapability() Remote SEP In Use or Codec Type not suitable !!!")))
       
   486 			iSEPFound = InUse ? ESEPInUse : ESEPCodecTypeNotAllowed;
       
   487 			}
       
   488 		}
       
   489 	}
       
   490 
       
   491 // -----------------------------------------------------------------------------
       
   492 // CBtsacConnected::GAVDP_SEPCapabilityComplete
       
   493 // -----------------------------------------------------------------------------
       
   494 //
       
   495 void CBtsacConnected::GAVDP_SEPCapabilityComplete()
       
   496 	{
       
   497 	TRACE_FUNC
       
   498 	iRemoteSEPIndex++;	
       
   499 	GetCapabilitiesOfAllSEPs();
       
   500 	}
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CBtsacConnected::GAVDP_ConfigurationConfirm
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 void CBtsacConnected::GAVDP_ConfigurationConfirm()
       
   507 	{
       
   508 	TRACE_FUNC
       
   509 	StopTimer();
       
   510 	TAvdtpSEPInfo SEPInfo;
       
   511 	if (Parent().iRemoteSEPs->GetInfo(Parent().GetSEPIndex(), SEPInfo))
       
   512 		{
       
   513 		TRACE_INFO((_L("CBtsacConnected::GAVDP_ConfigurationConfirm Couldn't retrieve SEP Info !")))
       
   514 		TRAP_IGNORE(CancelActionL(KErrCancel, EGavdpResetReasonGeneral));
       
   515        	return;   // cannot get remote SEP capabilites 
       
   516 		}
       
   517 	TSEID remoteSEPid = SEPInfo.SEID();
       
   518 	TRACE_INFO((_L("CBtsacConnected::GAVDP_ConfigurationConfirm() Asking for bearer for remote SEID(%d)"), remoteSEPid.SEID()))	
       
   519 	iBearersQuery = ETrue;
       
   520 	StartTimer(KCreateBearersResponseDelay, KRequestIdTimer);
       
   521 	Parent().iGavdp->CreateBearers(remoteSEPid);
       
   522 	}
       
   523 
       
   524 // -----------------------------------------------------------------------------
       
   525 // CBtsacConnected::GAVDP_BearerReady
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 void CBtsacConnected::GAVDP_BearerReady(RSocket aNewSocket, const TAvdtpSockAddr& aAddr)
       
   529 	{
       
   530 	TRACE_FUNC
       
   531 	TRACE_INFO((_L("CBtsacConnected::GAVDP_BearerReady() SEID: %d"), aAddr.SEID().SEID()))
       
   532 	(void)aAddr.SEID(); 	
       
   533 	StopTimer();
       
   534 	if(!iCancelConnectReq)
       
   535 		{		
       
   536 		if(iConnType != EIncomingConn)
       
   537 			{
       
   538 			// New accessory has been already informed if connection type is incoming,
       
   539 			// otherwise tell about new accessory
       
   540 		    Parent().NewAccessory(Parent().GetRemoteAddr());
       
   541 			}
       
   542 		
       
   543 		if(iConnType == EOutgoingConn || iConnType == EOutgoingConnNoDiscovery)
       
   544 			{
       
   545 			// If connection is without audio, just complete pending connect request if any.
       
   546 			// Otherwise pending request(s) is/are completed in configured state.
       
   547 			Parent().CompletePendingRequests(KConnectReq, KErrNone);
       
   548 			}			
       
   549 		TRAP_IGNORE(Parent().ChangeStateL(CBtsacConfigured::NewL(Parent(), aNewSocket, iAudioOpenedBy, EStreamConfiguredBySrc)));
       
   550 		}
       
   551 	else
       
   552 		{
       
   553 		TRACE_ASSERT(Parent().iStreamingSockets.Count() == 0, EBTPanicSocketExists)
       
   554 		TRACE_INFO((_L("[SOCKET] created.")))
       
   555 		Parent().iStreamingSockets.Append(aNewSocket);
       
   556 		Parent().CompletePendingRequests(KCompleteAllReqs, KErrCancel);
       
   557 		TRAP_IGNORE(Parent().ChangeStateL(CBtsacListening::NewL(Parent(), EGavdpResetReasonGeneral, KErrNone)));
       
   558 		}
       
   559 	}
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // CBtsacConnected::GAVDP_AbortIndication
       
   563 // -----------------------------------------------------------------------------
       
   564 //	
       
   565 void CBtsacConnected::GAVDP_AbortIndication(TSEID aSEID)
       
   566 	{
       
   567 	TRACE_INFO((_L("CBtsacConnected::GAVDP_AbortIndication() SEID:%d"), aSEID.SEID()))
       
   568 	(void)aSEID;
       
   569 	TRAP_IGNORE(CancelActionL(KErrDisconnected, EGavdpResetReasonNone));
       
   570 	}
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // CBtsacConnected::GAVDP_ConfigurationStartIndication
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 void CBtsacConnected::GAVDP_ConfigurationStartIndication(TSEID aLocalSEID, TSEID aRemoteSEID)
       
   577 	{
       
   578     TRACE_INFO((_L("CBtsacConnected::GAVDP_ConfigurationStartIndication() LocalSEID: %d, RemoteSEID: %d"), aLocalSEID.SEID(), aRemoteSEID.SEID()))
       
   579     StopTimer();
       
   580 	Parent().InitializeSEPManager();
       
   581 	TRAP_IGNORE(Parent().ChangeStateL(CBtsacConfiguring::NewL(Parent(), aLocalSEID, aRemoteSEID)));
       
   582 	}
       
   583 
       
   584 // -----------------------------------------------------------------------------
       
   585 // CBtsacConnected::RequestCompletedL
       
   586 // -----------------------------------------------------------------------------
       
   587 //
       
   588 void CBtsacConnected::RequestCompletedL(CBtsacActive& aActive)
       
   589     {
       
   590 	TRACE_FUNC
       
   591 	switch(aActive.RequestId())
       
   592 		{
       
   593 		case KRequestIdTimer:
       
   594 			{
       
   595 			if(!iBearersQuery)
       
   596 				{				
       
   597 			// Go to listening state, gavdp will be shutdown in listening state
       
   598 			CancelActionL(KErrCancel, EGavdpResetReasonNone);
       
   599 				}
       
   600 			else
       
   601 				{
       
   602 				// If bearers query timer has expired, lets handle it separately.		
       
   603 				Parent().iGavdp->Cancel();
       
   604 				TInt err = Parent().AbortStream();
       
   605 				if(!err)
       
   606 					{
       
   607 					Parent().ChangeStateL(CBtsacAborting::NewL(Parent()));
       
   608 					}
       
   609 				else
       
   610 					{
       
   611 					CancelActionL(KErrCancel, EGavdpResetReasonGeneral);
       
   612 					}
       
   613 				}
       
   614 			break;
       
   615 			}
       
   616 		case KRequestIdWaitRemoteConfStart:
       
   617 			{
       
   618 			// Remote didn't configure us and we have open audio request from acc fw.
       
   619 			// Let's configure the link and open audio by our selves.
       
   620 			StartConfigurationL();
       
   621 			break;
       
   622 			}
       
   623 		default:
       
   624 			{
       
   625 			TRACE_INFO((_L("CBtsacConnected::RequestCompletedL() Unknown request")))
       
   626 			break;
       
   627 			}				
       
   628 		}
       
   629     }
       
   630 
       
   631 // -----------------------------------------------------------------------------
       
   632 // CBtsacConnected::CancelRequest
       
   633 // -----------------------------------------------------------------------------
       
   634 //
       
   635 void CBtsacConnected::CancelRequest(CBtsacActive& aActive)
       
   636 	{
       
   637 	TRACE_FUNC
       
   638 	(void)aActive;
       
   639 	iTimer.Cancel();
       
   640 	}    
       
   641 
       
   642 // -----------------------------------------------------------------------------
       
   643 // CBtsacConnected::HandleGavdpErrorL
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 void CBtsacConnected::HandleGavdpErrorL(TInt aError)
       
   647 	{
       
   648 	TRACE_FUNC
       
   649 	StopTimer();
       
   650 	switch (aError)
       
   651 		{
       
   652 		case KErrAvdtpRequestTimeout: // -18005
       
   653 			{
       
   654 			TRACE_INFO((_L("CBtsacConnected::HandleGavdpErrorL() Request TIMEOUT")))
       
   655 			// Go to listening state, gavdp will be shutdown in listening state
       
   656 			CancelActionL(KErrDisconnected, EGavdpResetReasonNone);
       
   657 			break;
       
   658 			}
       
   659 			
       
   660 		case KErrHCILinkDisconnection: // -6305
       
   661 		case KErrDisconnected: // -36
       
   662 			{
       
   663 			TRACE_INFO((_L("CBtsacConnected::HandleGavdpErrorL() Signalling disconnected.")))
       
   664 			// for both outgoing or incoming connection, if we have an error, 
       
   665 			// this means there is disconnection
       
   666 			CancelActionL(aError, EGavdpResetReasonGeneral);
       
   667 			break;
       
   668 			}	
       
   669 
       
   670 		case (KErrAvdtpSignallingErrorBase - EAvdtpSEPInUse): // -18064 
       
   671 			{
       
   672 			// Remote SEP is in use.
       
   673 			// Wait for a while, accessory might configure us. If we don't receive 
       
   674 			// start ind during KOneSecondDelay, go to listening state.
       
   675     		StartTimer(KOneSecondDelay, KRequestIdTimer);
       
   676 			break;
       
   677 			}
       
   678 		
       
   679 		default:
       
   680 		// KErrNotReady -18
       
   681 		// KErrInUse -14
       
   682 		// KErrCorrupt -20
       
   683 		// (KErrAvdtpSignallingErrorBase - EAvdtpBadState) -18094
       
   684 			{
       
   685 			CancelActionL(KErrDisconnected, EGavdpResetReasonGeneral);
       
   686 			}
       
   687 		}
       
   688 	}
       
   689 
       
   690 //  End of File