bluetooth/btstack/linkmgr/ACLSAP.cpp
changeset 32 f72906e669b4
parent 16 0089b2f7ebd8
equal deleted inserted replaced
31:b9d1744dc449 32:f72906e669b4
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2003-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".
    17 //
    17 //
    18 
    18 
    19 #include <bluetooth/logger.h>
    19 #include <bluetooth/logger.h>
    20 #include <bt_sock.h>
    20 #include <bt_sock.h>
    21 #include <bluetooth/hci/aclpacketconsts.h>
    21 #include <bluetooth/hci/aclpacketconsts.h>
       
    22 #include <bluetooth/hci/hciconsts.h>
    22 
    23 
    23 #include "ACLSAP.h"
    24 #include "ACLSAP.h"
    24 #include "physicallinks.h"
    25 #include "physicallinks.h"
    25 #include "physicallinksmanager.h"
    26 #include "physicallinksmanager.h"
    26 #include "Basebandmodel.h"
    27 #include "Basebandmodel.h"
  1087 		{
  1088 		{
  1088 		// New physical link connection request
  1089 		// New physical link connection request
  1089 		CPhysicalLink* physicalLink = &iLinksMan.NewPhysicalLinkL(iRemoteDev);
  1090 		CPhysicalLink* physicalLink = &iLinksMan.NewPhysicalLinkL(iRemoteDev);
  1090 		// physicalLink is owned by the physical links manager.
  1091 		// physicalLink is owned by the physical links manager.
  1091 		User::LeaveIfError(BindLink(EACLLink, *physicalLink));
  1092 		User::LeaveIfError(BindLink(EACLLink, *physicalLink));
  1092 		TInt err = iPhysicalLink->Connect();
  1093 		iPhysicalLink->Connect();
  1093 		if(err != KErrNone)
       
  1094 			{
       
  1095 			// If we failed to connect then we should roll back the attachment
       
  1096 			ClearPhysicalLink();
       
  1097 			User::Leave(err);
       
  1098 			}
       
  1099 		}
  1094 		}
  1100 	}
  1095 	}
  1101 
  1096 
  1102 TInt CACLLink::SetLocalName(TSockAddr& aAddr)
  1097 TInt CACLLink::SetLocalName(TSockAddr& aAddr)
  1103 	{
  1098 	{
  1331 	{
  1326 	{
  1332 	LOG_FUNC
  1327 	LOG_FUNC
  1333 	iState->Shutdown(*this, aOption);
  1328 	iState->Shutdown(*this, aOption);
  1334 	}
  1329 	}
  1335 
  1330 
  1336 
       
  1337 void CACLLink::NotifyDataToSocket(TUint8 aFlag, const TDesC8& aData)
  1331 void CACLLink::NotifyDataToSocket(TUint8 aFlag, const TDesC8& aData)
  1338 	{
  1332 	{
  1339 	LOG_FUNC
  1333 	LOG_FUNC
  1340 	const TUint8 KFlagHeaderSize =1;
       
  1341 /*
  1334 /*
  1342 	The design of the protocol specification for L2CAP
  1335 	The design of the protocol specification for L2CAP
  1343 	means that both we and L2CAP need to know the flag parameter
  1336 	means that both we and L2CAP need to know the flag parameter
  1344 	for now we just signal one datagram (*could* signal two - one for flag: but that's just as grubby)
  1337 	for now we just signal one datagram (*could* signal two - one for flag: but that's just as grubby)
  1345 */
  1338 */
  1346 
  1339 
  1347 
       
  1348 	// make a new chain consisting of Flag(1st octet) followed by Data.
       
  1349 	RMBufChain aclData;
  1340 	RMBufChain aclData;
  1350 	#ifdef HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
  1341 
  1351 	THCIConnHandle connH=iHandle;
  1342 	CACLDataQController& aclQctrl = iProtocol.ACLController();
  1352 	aclData = const_cast<CHCIFacade&>(iLinksMan.HCIFacade()).TakeInboundACLDataBufferFromPool(connH);
  1343 	THCIConnHandle connH = iHandle;
  1353 	aclData.CopyIn(aData,KFlagHeaderSize);
  1344 	TRAPD(err, aclData = aclQctrl.PopulateInboundBufferL(connH, aFlag, aData));
  1354 	aclData.TrimEnd(aData.Length()+KFlagHeaderSize); //return the reserved MBufs we didn't need
       
  1355 													 //to the global pool
       
  1356 	#else
       
  1357 	TRAPD(err, aclData.CreateL(aData, KFlagHeaderSize));
       
  1358 
       
  1359 	if (err)
  1345 	if (err)
  1360 		{
  1346 		{
  1361 		//Since HC->H flow control is off, and we have run out of MBufs
  1347 		// We have run out of MBufs, there is nothing we can do here but 
  1362 		//there is nothing we can do here but drop or disconnect the link
  1348 		// 1) drop the received packet, or
  1363 		//due to limited resources. We drop.
  1349 		// 2) disconnect the link
       
  1350 		// We drop the packet to be multi-profile "friendly"
       
  1351 		LOG1(_L8("*** ERROR: Dropping ACL Data!!! (error = %d) ***"), err);
  1364 		return;
  1352 		return;
  1365 		}
  1353 		}
  1366 	#endif
  1354 	
  1367 
       
  1368 	aclData.First()->Ptr()[0] = aFlag;	// aData is already in the chain
       
  1369 
       
  1370 
       
  1371 	// slap onto the RMBufPacketQ
  1355 	// slap onto the RMBufPacketQ
  1372 	iInboundBuffer.Append(aclData); // transfers
  1356 	iInboundBuffer.Append(aclData); // transfers
  1373 	
  1357 	
  1374 
  1358 	iSocket->NewData(1);	// datagrams: could async notify - or get l2cap to drain async
  1375 	#ifndef HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
  1376 	if (!err)
       
  1377 		{
       
  1378 	#endif
       
  1379 		iSocket->NewData(1);	// datagrams: could async notify - or get l2cap to drain async
       
  1380 	#ifndef HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
  1381 		}
       
  1382 	#endif
       
  1383 	}
  1359 	}
  1384 
  1360 
  1385 
  1361 
  1386 void CACLLink::GetData(TDes8& aDesc,TUint aOptions,TSockAddr* aAddr)
  1362 void CACLLink::GetData(TDes8& aDesc,TUint aOptions,TSockAddr* aAddr)
  1387 	{
  1363 	{