bluetooth/btstack/linkmgr/AclDataQController.cpp
changeset 32 f72906e669b4
parent 0 29b1cd4cb562
equal deleted inserted replaced
31:b9d1744dc449 32:f72906e669b4
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1999-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 // The HCI in such cases would then signal the stack with not all credits etc.
    18 // The HCI in such cases would then signal the stack with not all credits etc.
    19 // 
    19 // 
    20 //
    20 //
    21 
    21 
    22 #include <bluetooth/logger.h>
    22 #include <bluetooth/logger.h>
       
    23 #include <bluetooth/hci/hciconsts.h>
    23 #include "AclDataQController.h"
    24 #include "AclDataQController.h"
    24 #include "linkmgr.h"
    25 #include "linkmgr.h"
    25 #include "AclDataQ.h"
    26 #include "AclDataQ.h"
    26 #include "hcifacade.h"
    27 #include "hcifacade.h"
       
    28 #include "hostmbufpool.h"
       
    29 #include "linkflowcontrol.h"
       
    30 #include "linkconsts.h"
    27 
    31 
    28 #ifdef __FLOG_ACTIVE
    32 #ifdef __FLOG_ACTIVE
    29 _LIT8(KLogComponent, LOG_COMPONENT_LINKMGR);
    33 _LIT8(KLogComponent, LOG_COMPONENT_LINKMGR);
    30 #endif
    34 #endif
    31 
    35 
    48 
    52 
    49 	CACLDataQController* self = new(ELeave) CACLDataQController(aProtocol.HCIFacade(), aMuxer);
    53 	CACLDataQController* self = new(ELeave) CACLDataQController(aProtocol.HCIFacade(), aMuxer);
    50 	CleanupStack::PushL(self);
    54 	CleanupStack::PushL(self);
    51 	self->ConstructL(aProtocol, aBufSize, aFrameOverhead, aNumBufs);
    55 	self->ConstructL(aProtocol, aBufSize, aFrameOverhead, aNumBufs);
    52 	CleanupStack::Pop(self);
    56 	CleanupStack::Pop(self);
    53 
       
    54 	LOG1(_L("CACLDataQController::NewL self = 0x%08x"), self);
       
    55 	return self;
    57 	return self;
    56 	}
    58 	}
    57 
    59 
    58 CACLDataQController::CACLDataQController(CHCIFacade& aHCIFacade,
    60 CACLDataQController::CACLDataQController(CHCIFacade& aHCIFacade,
    59 										 CLinkMuxer& aMuxer)
    61 										 CLinkMuxer& aMuxer)
    65 	}
    67 	}
    66 
    68 
    67 CACLDataQController::~CACLDataQController()
    69 CACLDataQController::~CACLDataQController()
    68 	{
    70 	{
    69 	LOG_FUNC
    71 	LOG_FUNC
    70 
    72 	
       
    73 #ifdef HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
    74 	delete iMBufPool;
       
    75 #endif
       
    76 	
    71 	delete iDataQ;
    77 	delete iDataQ;
    72 	iAclConns.Reset();
    78 	iAclConns.Reset();
    73 	iAclConns.Close();
    79 	iAclConns.Close();
    74 	}
    80 	}
    75 
    81 
    79 									 TUint aNumBufs)
    85 									 TUint aNumBufs)
    80 	{
    86 	{
    81 	LOG_FUNC
    87 	LOG_FUNC
    82 
    88 
    83 	iDataQ = CAclDataQ::NewL(aProtocol, aNumBufs, aBufSize, aFrameOverhead);
    89 	iDataQ = CAclDataQ::NewL(aProtocol, aNumBufs, aBufSize, aFrameOverhead);
       
    90 	
    84 
    91 
    85 #ifdef PROXY_COMMUNICATES
    92 #ifdef PROXY_COMMUNICATES
    86 	LOG(_L("\tPROXY_COMMUNICATES defined- reserving slots for broadcast channel"));
    93 	LOG(_L("\tPROXY_COMMUNICATES defined- reserving slots for broadcast channel"));
    87 
    94 
    88 	// Reserve BC one now
    95 	// Reserve BC one now
    89 	User::LeaveIfError(ACLLogicalLinkUp(KHCIBroadcastHandle, EFalse));
    96 	User::LeaveIfError(ACLLogicalLinkUp(KHCIBroadcastHandle, EFalse));
       
    97 #endif
       
    98 	
       
    99 #ifdef HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
   100 	LOG(_L8("\tHOSTCONTROLLER_TO_HOST_FLOW_CONTROL defined- creating buffer pool"));
       
   101 	iMBufPool = CHostMBufPool::NewL(aProtocol.HCIFacade().CommandQController());
    90 #endif
   102 #endif
    91 	}
   103 	}
    92 
   104 
    93 void CACLDataQController::InitialDataCredits(TUint16 aCredits)
   105 void CACLDataQController::InitialDataCredits(TUint16 aCredits)
    94 /**
   106 /**
   425 	{
   437 	{
   426 	LOG_FUNC
   438 	LOG_FUNC
   427 	LOG1(_L("CACLDataQController::ACLLogicalLinkDown aConnH = %d"), 
   439 	LOG1(_L("CACLDataQController::ACLLogicalLinkDown aConnH = %d"), 
   428 		aConnH);
   440 		aConnH);
   429 
   441 
       
   442 #ifdef HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
   443 	if(iMBufPool)
       
   444 		{
       
   445 		iMBufPool->InvalidateByConnH(aConnH);
       
   446 		// the packet completions should probably move to the iAclConns model
       
   447 		// to clean up this code.
       
   448 		}
       
   449 #endif // HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
   450 
   430 	TInt connection = FindConnection(aConnH);
   451 	TInt connection = FindConnection(aConnH);
   431 		
   452 		
   432 	if ( connection == KErrNotFound )
   453 	if ( connection == KErrNotFound )
   433 		{
   454 		{
   434 		LOG(_L("CACLDataQController::ACLLogicalLinkDown (Connection not found)."));
   455 		LOG(_L("CACLDataQController::ACLLogicalLinkDown (Connection not found)."));
   618 		}
   639 		}
   619 
   640 
   620 	return rerr;
   641 	return rerr;
   621 	}
   642 	}
   622 
   643 
       
   644 RMBufChain CACLDataQController::PopulateInboundBufferL(THCIConnHandle aConnH, TUint8 aFlag, const TDesC8& aData)
       
   645 	{
       
   646 	LOG_FUNC
       
   647 	// make a new chain consisting of Flag(1st octet) followed by Data.
       
   648 	RMBufChain aclData;
       
   649 	static const TInt KFlagHeaderOffset = 0;
       
   650 	
       
   651 #ifdef HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
   652 	// Check what flow control mode is in operation
       
   653 	TFlowControlMode flowControl = iLinkMuxer.FlowControlMode();
       
   654 	TBool ctrlerToHost = (flowControl == ETwoWayFlowControlEnabled) || (flowControl == EFlowControlFromHostControllerOnly);
       
   655 	if(ctrlerToHost)
       
   656 		{
       
   657 		__ASSERT_DEBUG(iMBufPool, Panic(ELinkMgrFlowControlChangeOfMind));
       
   658 		aclData = iMBufPool->TakeBufferL(aConnH);
       
   659 		aclData.CopyIn(aData, KLinkMgrIncomingBufferHeaderSize);
       
   660 		// return the reserved MBufs we didn't need to the global pool
       
   661 		aclData.TrimEnd(aData.Length() + KLinkMgrIncomingBufferHeaderSize);
       
   662 		}
       
   663 	else
       
   664 #endif // HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
   665 		{
       
   666 		aclData.CreateL(aData, KLinkMgrIncomingBufferHeaderSize);
       
   667 		}
       
   668 	
       
   669 	aclData.First()->Ptr()[KFlagHeaderOffset] = aFlag;
       
   670 	
       
   671 	return aclData;
       
   672 	}
       
   673 
       
   674 void CACLDataQController::NoExplicitInboundPoolNeeded()
       
   675 	{
       
   676 	LOG_FUNC
       
   677 #ifdef HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
   678 	delete iMBufPool;
       
   679 	iMBufPool = NULL;
       
   680 #endif // HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
   681 	}
       
   682 
   623 //
   683 //
   624 // End of file
   684 // End of file