bluetooth/btstack/avctp/common/Avctp.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2005-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalTechnology
       
    19 */
       
    20 
       
    21 #ifndef AVCTP_H
       
    22 #define AVCTP_H
       
    23 
       
    24 #include <es_prot.h>
       
    25 #include <bluetoothav.h>
       
    26 #include <e32hashtab.h>
       
    27 #include "btsockettimer.h"
       
    28 #include "avctpcommon.h"
       
    29 #include <es_prot_internal.h>
       
    30 
       
    31 namespace SymbianAvctp
       
    32 {
       
    33 
       
    34 const static TUint KServiceInfo =
       
    35 	KSIConnectionLess | KSIReliable | KSIInOrder | 
       
    36 	KSIDatagram | KSIGracefulClose;
       
    37 
       
    38 const static TInt KServiceTypeInfo = 
       
    39 	ESocketSupport | ECantProcessMBufChains | EUseCanSend;
       
    40 
       
    41 const static TInt KMaxNumSocketsInProtocol = 10;
       
    42 } // end of namespace SymbianAvctp
       
    43 
       
    44 
       
    45 // ok to not have in namespace
       
    46 const static TL2CAPPort KAvctpSecondChannelPSM = 0x1b;
       
    47 const TInt KAvctpSecondaryChannelOutboundMTU = 0xffff;
       
    48 const TInt KAvctpSecondaryChannelInboundMTU = 0xffff;
       
    49 
       
    50 // forward declarations
       
    51 class CAvctpSap;
       
    52 class CAvctpTransport;
       
    53 class CAvctpMuxerStateFactory;
       
    54 class CAvctpConnection;
       
    55 class CAvctpPacketMgr;
       
    56 class HAvctpIncomingSdu;
       
    57 class HAvctpOutgoingSdu;
       
    58 class CAvctpSubConDeviceErrorEvent;
       
    59 class CAvctpSubConEventConnectCfm;
       
    60 class CAvctpSubConEventConnectInd;
       
    61 class CAvctpSubConEventDiscCfm;
       
    62 class CAvctpSubConEventDiscInd;
       
    63 class MAvctpSDUSender;
       
    64 
       
    65 NONSHARABLE_CLASS(TClientItem)
       
    66 	{
       
    67 public:
       
    68 	TClientItem(TUint16 aClientId);
       
    69 	void AttachPrimaryChannel(MSocketNotify& aNotify);
       
    70 	void AttachSecondaryChannel(MSocketNotify& aNotify);
       
    71 	void DetachSecondaryChannel();
       
    72 	TUint16 ClientId() const;
       
    73 	MSocketNotify* PrimaryChannel() const;
       
    74 	MSocketNotify* SecondaryChannel() const;
       
    75 	TBool IsSecondaryChannelAttached() const;
       
    76 private:
       
    77 	TUint16					iClientId;
       
    78 	MSocketNotify*			iPrimaryChannel;
       
    79 	MSocketNotify*			iSecondaryChannel;
       
    80 	TBool					iIsSecondaryChannelAttached;
       
    81 	TInt					iRefCount;
       
    82 	};
       
    83 
       
    84 /**
       
    85 The AVCTP Protocol object.  Used by BT_v2.prt to create a CProtocolBase object
       
    86 for ESOCK, so ESOCK can create AVCTP sockets.
       
    87 
       
    88 This is the object created by ESock to give access to AVCTP services
       
    89 
       
    90   @internalAll
       
    91   @see CProtocolBase
       
    92 */
       
    93 
       
    94 NONSHARABLE_CLASS(CAvctpProtocol) : public CBluetoothProtocolBase
       
    95     {
       
    96 public:
       
    97 	// Factory functions
       
    98     static CAvctpProtocol* NewL(CBTSecMan& aSecMan, RBTControlPlane& aControlPlane, CBTCodServiceMan& aCodMan);
       
    99     static CAvctpProtocol* NewLC(CBTSecMan& aSecMan, RBTControlPlane& aControlPlane, CBTCodServiceMan& aCodMan);
       
   100 	
       
   101 	// Functions from CProtocolBase
       
   102 	virtual void InitL(TDesC& aTag);				// need to get a state factory
       
   103 	virtual void StartL();							// check we're bound
       
   104 	virtual void BindToL(CProtocolBase* aProtocol);	// bind to lower protocol (L2CAP)
       
   105 	virtual void CloseNow();
       
   106 	virtual void Open();
       
   107 	virtual void Close();
       
   108 	virtual void Identify(TServerProtocolDesc* aProtocolDesc) const;
       
   109 	virtual CServProviderBase* NewSAPL(TUint aSockType);
       
   110 	
       
   111 	// Functions  from CBluetoothProtocolBase
       
   112 	virtual TInt BearerConnectComplete(const TBTDevAddr& aAddr, CServProviderBase* aSSP);
       
   113 	virtual TInt ControlPlaneMessage(TBTControlPlaneMessage aMessage, TAny* aParam);
       
   114 
       
   115 	// Other general protocol functions	
       
   116 	TInt StartProtocolListening();
       
   117 	void DoStartAvctpListeningL();
       
   118 	static void ProtocolIdentity(TServerProtocolDesc* aDesc); // Static query function used by Identify
       
   119 	TInt SetPreauthorisation(const TBTDevAddr& aPreauthoriseAddress, TBool aSetPreauthorisation);
       
   120 
       
   121 	// AVCTP specific functions
       
   122 	CAvctpMuxerStateFactory& MuxerStateFactory() const;
       
   123 
       
   124 	// Interface to the muxer
       
   125 	TInt ProvideTransport(const TBTDevAddr& aRemoteAddr, TUint16 aClientId, MSocketNotify& aControlSocket);
       
   126 	TInt ActiveExtendTransport(const TBTDevAddr& aRemoteAddr, TUint16 aClientId, MSocketNotify& aSecondChannelControlSocket);
       
   127 	void AwaitForExtendedTransport(TUint16 aClientId, MSocketNotify& aSecondChannelControlSocket);
       
   128 	void PrimaryChannelRefuseAttach(const TBTDevAddr& aRemoteAddr, TUint16 aClientId);
       
   129 	void SecondaryChannelRefuseAttach(const TBTDevAddr& aRemoteAddr, TUint16 aClientId);	
       
   130 	TInt AttachInboundConnectionToTransport(const TBTDevAddr& aRemoteAddr, CServProviderBase* aL2CAPConSAP);
       
   131 	TInt GetChannelMtu(TInt aChannel, const TBTDevAddr& aAddr, TInt& aMtu);
       
   132 	TInt ReleaseTransport(const TBTDevAddr& aRemoteAddr, TUint16 aClientId);
       
   133 	TInt ReleaseExtendedTransport(const TBTDevAddr& aRemoteAddr, TUint16 aClientId);
       
   134 	void PrimaryChannelIncomingRemoteDisconnection(const TBTDevAddr& aRemoteAddr);
       
   135 	MAvctpSDUSender* GetSDUSender(const TBTDevAddr& aRemoteAddr, TInt aChannel);
       
   136 	CAvctpTransport* FindTransport(const TBTDevAddr& aDevAddr);
       
   137 	void AwaitTransport(TUint16 aClientId, MSocketNotify& aControlSocket);
       
   138 	TInt PrimaryChannelAgreeAttachment(TUint16 aClientId, const TBTDevAddr& aRemoteAddr);
       
   139 	TInt SecondaryChannelAgreeAttachment(TUint16 aClientId, const TBTDevAddr& aRemoteAddr);
       
   140 	// Interface to all Saps provided for the muxers
       
   141 	TBool SapsHaveDataFor(const TBTDevAddr& aRemoteAddr);
       
   142 	void  SignalCanSendToSaps(CAvctpPacketMgr& aPacketMgr);
       
   143 	void  SignalNewDataToSaps(HAvctpIncomingSdu* aSdu, TInt aChannel);
       
   144 	void  SignalMuxerDownToSaps(const TBTDevAddr& aRemoteAddr);
       
   145 	
       
   146 	// Que Management
       
   147 	TInt AddSap(CAvctpSap& aSap);
       
   148 	void RemoveSap(CAvctpSap& aSap);
       
   149 	CAvctpSap* FindSap(TUint16 aClientId);
       
   150 	TInt AddTransport(CAvctpTransport& aMuxer);
       
   151 	void RemoveTransport(CAvctpTransport& aMuxer);
       
   152 	CAvctpTransport* FindOrCreateTransport(const TBTDevAddr& aDevAddr, TInt aChannel, CServProviderBase* aL2CAPConSAP = NULL);
       
   153 	void SetSecondChannelCtrlNotify(TUint16 aClientId, MSocketNotify& aSecondChannelControlSocket);
       
   154 	void NotifyLinkUp(const TBTDevAddr& aAddr, TBool aIsSecondChannel);
       
   155 private:
       
   156 	CAvctpProtocol(CBTSecMan& aSecMan, RBTControlPlane& aControlPlane, CBTCodServiceMan& aCodMan);
       
   157 	void ConstructL();
       
   158 	~CAvctpProtocol();
       
   159 
       
   160 	// Close Functions
       
   161 	void CheckForIdle();
       
   162 	TBool IsIdle();
       
   163 	void QueIdleTimer();
       
   164 	void DequeIdleTimer();
       
   165 	const TClientItem* AddClientItem(TUint16 aClientId, MSocketNotify& aNotify);
       
   166 	const TClientItem* ClientItem(TUint16 aClientId) const;
       
   167 	static TInt TryToClose(TAny* aProtocol);
       
   168 	
       
   169 	// Ipid Response Callback functions
       
   170 	static TInt IpidAsyncCallBack(TAny* aProtocol);
       
   171 	inline void StartSendIpidAsyncCallBack();
       
   172 	inline void CancelIpidAsyncCallBack();
       
   173 	
       
   174 #ifdef __FLOG_ACTIVE
       
   175 	void LogSaps();
       
   176 	void LogMuxers();
       
   177 #endif
       
   178 	
       
   179 private:
       
   180 	/** The state factory for the lightweight AVCTP SAP states */
       
   181 	CAvctpMuxerStateFactory*		iMuxerStateFactory;
       
   182 
       
   183 	// Queues
       
   184 	/** All AVCTP Service Access Providers are owned by esock. 
       
   185 	    This queue is for Saps that have been assigned a PID 
       
   186 	    to allow us to enforce the 1 SAP / PID rule */
       
   187 	TDblQue<CAvctpSap> iSaps;
       
   188 	/** All AVCTP transports are owned by the protocol.
       
   189 	    This queue is for Muxers that have been assigned a remote address
       
   190 	    to allow us to enforce the 1 Muxer / remote address rule */
       
   191 	TDblQue<CAvctpTransport> iTransports;
       
   192 	/** This is a Que of IPID responses to remote devices 
       
   193 		These are owned by the protocol */
       
   194 	TDblQue<HAvctpOutgoingSdu> iIpidResponses;
       
   195 
       
   196 	// Stuff for close callbacks, etc.
       
   197 	/** Whether we are about to die */
       
   198 	TBool					iClosePending;
       
   199 
       
   200 	/** An entry in the BT protocol family delta timer queue
       
   201 		The idle timer is something that runs to prevent the protocol going down and 
       
   202 		then being brought up again immediately because this is costly. Instead we 
       
   203 		stay alive for a small amount of time to try and smooth out the Opening and
       
   204 		closing */
       
   205 	TDeltaTimerEntry		iIdleTimerEntry;
       
   206 	TBool			iIdleTimerQueued;
       
   207 	
       
   208 	CAsyncCallBack*	iIpidResponseAsyncCallBack;
       
   209 	CIncomingConnectionListener*	iSecondChannelListener;
       
   210 	RHashMap<TInt, TClientItem>		iClientItems;
       
   211 	};
       
   212 
       
   213 #include "avctp.inl"
       
   214 
       
   215 #endif // AVCTP_H
       
   216