bluetooth/btstack/linkmgr/RawConduit.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2003-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 // Implementation of rawconduit
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "RawConduit.h"
       
    19 #include "ProxySAP.h"
       
    20 #include "physicallinksmanager.h"
       
    21 #include "ACLSAP.h"
       
    22 #include "linkutil.h"
       
    23 
       
    24 // a bit like a "signaller" for raw data
       
    25 
       
    26 CACLRawConduit* CACLRawConduit::NewL(CBTProxySAP& aParent)
       
    27 	{
       
    28 	CACLRawConduit* s = new (ELeave) CACLRawConduit(aParent);
       
    29 	CleanupStack::PushL(s);
       
    30 	s->ConstructL();
       
    31 	CleanupStack::Pop(s);
       
    32 	return s;
       
    33 	}
       
    34 
       
    35 void CACLRawConduit::ConstructL()
       
    36 	{
       
    37 	// get our link
       
    38 	iACLLink = CACLLink::NewL(iParent.iLinksMan,
       
    39 							  iParent.iPhysicalLink,
       
    40 							  iParent.iLinksMan.LinkManagerProtocol());
       
    41 	
       
    42 	TPckgBuf<TInt> buf;
       
    43 	TInt err = iACLLink->GetOption(KSolBtACL, ELMInboundACLSize, buf);
       
    44 	__ASSERT_ALWAYS(!err, Panic(EBTACLRawConduitError));
       
    45 
       
    46 	TInt MRU = buf();
       
    47 
       
    48 	iReceiveBuf = HBufC8::NewL(MRU);
       
    49 
       
    50 	iACLLink->SetNotify(this);
       
    51 
       
    52 	TACLSockAddr rawSockAddr;
       
    53 	rawSockAddr.SetPort(EACLPortRaw);
       
    54 	iACLLink->SetLocalName(rawSockAddr);
       
    55 
       
    56 	TBTSockAddr remoteAddr;
       
    57 	remoteAddr.SetBTAddr(iParent.iPhysicalLink->BDAddr());
       
    58 	iACLLink->SetRemName(remoteAddr);
       
    59 
       
    60 	iACLLink->ActiveOpen(); // to attach us - should be there
       
    61 	__ASSERT_DEBUG(iReady, Panic(EBTACLRawConduitError));
       
    62 	
       
    63 	if (!iReady)
       
    64 		{
       
    65 		User::Leave(KErrProxyWriteNotAvailable);
       
    66 		}
       
    67 	}
       
    68 
       
    69 CACLRawConduit::CACLRawConduit(CBTProxySAP& aParent)
       
    70 : iParent(aParent), iReady(EFalse)
       
    71 	{
       
    72 	}
       
    73 
       
    74 CACLRawConduit::~CACLRawConduit()
       
    75 	{
       
    76 	delete iReceiveBuf;
       
    77  	//Don't know the state of the iACLLink. We assume it will have been closed by a call from the
       
    78  	//PHY before our owner deletes us, but if our owner performed an immediate shutdown that might
       
    79  	//not be the case. If we try to delete the iACLLink while it's still open it'll panic. So to be
       
    80  	//sure, do an immediate shutdown on it.
       
    81  	iACLLink->Shutdown(CServProviderBase::EImmediate);
       
    82 	delete iACLLink;
       
    83 	}
       
    84 
       
    85 TInt CACLRawConduit::Write(const TDesC8& aData, TUint aOptions)
       
    86 	{
       
    87 	return iACLLink->Write(aData, aOptions, NULL);
       
    88 	}
       
    89 
       
    90 void CACLRawConduit::NewData(TUint aCount)
       
    91 	{
       
    92 	// get it out of the SAP
       
    93 	// try our best - but it's unreliable tranport
       
    94 	TPtr8 ptr = iReceiveBuf->Des();
       
    95 
       
    96 	while (aCount--)
       
    97 		{
       
    98 		iACLLink->GetData(ptr, 0); // no options
       
    99 		iParent.DataReceived();
       
   100 		}
       
   101 	}
       
   102 
       
   103 void CACLRawConduit::GetData(TDes8& aData)
       
   104 	{
       
   105 	aData = *iReceiveBuf;
       
   106 	}
       
   107 
       
   108 void CACLRawConduit::CanSend()
       
   109 	{
       
   110 	// don't care - unreliable, so haven't stored anything to send
       
   111 	}
       
   112 
       
   113 void CACLRawConduit::ConnectComplete()
       
   114 	{
       
   115 	// as expected!
       
   116 	iReady = ETrue;
       
   117 	}
       
   118 
       
   119 void CACLRawConduit::ConnectComplete(const TDesC8& /*aConnectData*/)
       
   120 	{
       
   121 	// don't care
       
   122 	}
       
   123 
       
   124 void CACLRawConduit::ConnectComplete(CServProviderBase& /*aSSP*/)
       
   125 	{
       
   126 	// don't care
       
   127 	}
       
   128 
       
   129 void CACLRawConduit::ConnectComplete(CServProviderBase& /*aSSP*/,const TDesC8& /*aConnectData*/)
       
   130 	{
       
   131 	// don't care
       
   132 	}
       
   133 
       
   134 void CACLRawConduit::CanClose(TDelete /*aDelete*/)
       
   135 	{
       
   136 	}
       
   137 
       
   138 void CACLRawConduit::CanClose(const TDesC8& /*aDisconnectData*/,TDelete /*aDelete*/)
       
   139 	{
       
   140 	}
       
   141 
       
   142 void CACLRawConduit::Error(TInt /*aError*/,TUint /*aOperationMask*/)
       
   143 	{
       
   144 	// our parent will be told by other means - this is just a data path
       
   145 	}
       
   146 
       
   147 void CACLRawConduit::Disconnect()
       
   148 	{
       
   149 	// our parent will be told by other means - this is just a data path
       
   150 	}
       
   151 
       
   152 void CACLRawConduit::Disconnect(TDesC8& /*aDisconnectData*/)
       
   153 	{
       
   154 	// don't care
       
   155 	}
       
   156 
       
   157 void CACLRawConduit::IoctlComplete(TDesC8* /*aBuf*/)
       
   158 	{
       
   159 	// not used
       
   160 	}
       
   161 
       
   162 void CACLRawConduit::NoBearer(const TDesC8& /*aConnectionInfo*/)
       
   163 	{
       
   164 	// don't care
       
   165 	}
       
   166 
       
   167 void CACLRawConduit::Bearer(const TDesC8& /*aConnectionInfo*/)
       
   168 	{
       
   169 	// don't care
       
   170 	}
       
   171