bluetooth/btstack/avctp/avctppacket.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 // Provides the AVCTP Packet classes
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef AVCTPPACKET_H
       
    24 #define AVCTPPACKET_H
       
    25 
       
    26 #include <es_mbuf.h>
       
    27 
       
    28 #include "avctpconstants.h"
       
    29 #include "avctppacketstatics.h"
       
    30 
       
    31 // Forward definitions
       
    32 class TAvctpHeaderInfo;
       
    33 class TAvctpNormalHeaderInfo;
       
    34 class TAvctpStartHeaderInfo;
       
    35 
       
    36 class RMBufChain;
       
    37 
       
    38 NONSHARABLE_CLASS(CAvctpPacket) : public CBase
       
    39 /**
       
    40 Static methods to help parse an AVCTP packet.
       
    41 
       
    42   @internalComponent
       
    43 */
       
    44 	{
       
    45 public:
       
    46 	static TInt ParseHeader(const RMBufChain& aData, TAvctpStartHeaderInfo& aHeaderInfo);
       
    47 	static TPtrC8 GetHeader(const RMBufChain& aChain);
       
    48 	
       
    49 	static TInt ParseNormalHeader(const TDesC8& aData, TAvctpNormalHeaderInfo& aHeaderInfo);
       
    50 	static TInt ParseStartHeader(const TDesC8& aData, TAvctpStartHeaderInfo& aHeaderInfo);
       
    51 
       
    52 	static TInt CheckNormalHeaderInfo(const TAvctpNormalHeaderInfo& aHeaderInfo);
       
    53 	static TInt CheckStartHeaderInfo(const TAvctpStartHeaderInfo& aHeaderInfo);
       
    54 
       
    55 	};
       
    56 	
       
    57 
       
    58 /**
       
    59 Contains the common information given in all AVCTP packet headers
       
    60 @internalComponent.
       
    61 
       
    62 This class by itself represents the headers of Continue and End 
       
    63 packets.
       
    64 */
       
    65 NONSHARABLE_CLASS(TAvctpHeaderInfo)
       
    66 	{
       
    67 public:
       
    68 	inline TAvctpHeaderInfo();
       
    69 	inline TAvctpHeaderInfo(SymbianAvctp::TTransactionLabel aTransactionLabel,
       
    70 							SymbianAvctp::TPacketType aPktType,
       
    71 							SymbianAvctp::TMessageType aMsgType);
       
    72 	inline SymbianAvctp::TPduHeaderLength HeaderLength() const;
       
    73 
       
    74 public:
       
    75 	SymbianAvctp::TTransactionLabel iTransactionLabel;
       
    76 	SymbianAvctp::TPacketType iPktType;
       
    77 	SymbianAvctp::TMessageType iMsgType;
       
    78 	};
       
    79 
       
    80 /**
       
    81 Contains the information given in a AVCTP normal packet header
       
    82 @internalComponent
       
    83 */
       
    84 NONSHARABLE_CLASS(TAvctpNormalHeaderInfo) : public TAvctpHeaderInfo
       
    85 	{
       
    86 public:
       
    87 	inline TAvctpNormalHeaderInfo();
       
    88 	inline TAvctpNormalHeaderInfo(SymbianAvctp::TTransactionLabel aTransactionLabel,
       
    89 								  SymbianAvctp::TPacketType aPktType,
       
    90 								  SymbianAvctp::TMessageType aMsgType,
       
    91 								  TBool aHasValidPid,
       
    92 								  SymbianAvctp::TPid aPid);
       
    93 public:
       
    94 	TBool iHasValidPid;
       
    95 	SymbianAvctp::TPid iPid;
       
    96 	};
       
    97 	
       
    98 /**
       
    99 Contains the information given in a AVCTP start packet header
       
   100 @internalComponent
       
   101 */
       
   102 NONSHARABLE_CLASS(TAvctpStartHeaderInfo) : public TAvctpNormalHeaderInfo
       
   103 	{
       
   104 public:
       
   105 	inline TAvctpStartHeaderInfo();
       
   106 	inline TAvctpStartHeaderInfo(SymbianAvctp::TTransactionLabel aTransactionLabel,
       
   107 								 SymbianAvctp::TPacketType aPktType,
       
   108 								 SymbianAvctp::TMessageType aMsgType,
       
   109 								 TBool aHasValidPid,
       
   110 								 SymbianAvctp::TPid aPid,
       
   111 								 TUint aFragmentsInSdu);
       
   112 public:
       
   113 	TUint iFragmentsInSdu;
       
   114 	};
       
   115 
       
   116 // Forward Declaration
       
   117 class HAvctpIncomingSdu;
       
   118 class TAvctpOutboundQ;
       
   119 		
       
   120 /**
       
   121 The sap uses this class to take owner ship of data coming down from esock
       
   122 & que it.
       
   123 */
       
   124 NONSHARABLE_CLASS(HAvctpOutgoingSdu) 
       
   125 	{
       
   126 friend class TAvctpOutboundQ;   // So it has access to iQueLink to do it's Q ordering & Dequeing
       
   127 friend class CAvctpProtocol;   	// So it can Q the Sdus
       
   128 
       
   129 public:
       
   130 	static HAvctpOutgoingSdu* NewL(const TAvctpNormalHeaderInfo& aHeaderInfo,
       
   131 							 	   const TBTDevAddr& aAddr,
       
   132 					 		 	   RMBufChain& aData);
       
   133 					 		 	   
       
   134 	static HAvctpOutgoingSdu* NewIpidResponseL(const HAvctpIncomingSdu& aIncomingSdu, TInt aChannel);
       
   135 					 		 	   					 		 	   
       
   136 	~HAvctpOutgoingSdu();
       
   137 
       
   138 	inline const TBTDevAddr& BTAddr() const;
       
   139 	inline TAvctpNormalHeaderInfo& HeaderInfo(); //non-const so fragmenter can update header
       
   140 	inline RMBufChain& Data();
       
   141 	inline void AddToQueue(TAvctpOutboundQ* aOutboundQ);
       
   142 	inline TInt Channel() const;
       
   143 	
       
   144 private:
       
   145 	inline HAvctpOutgoingSdu(const TAvctpNormalHeaderInfo& aHeaderInfo,
       
   146 							 const TBTDevAddr& aAddr);	
       
   147 	void ConstructL(RMBufChain& aData);
       
   148 
       
   149 private:
       
   150 	TDblQueLink iQueLink;
       
   151 	TAvctpNormalHeaderInfo iHeaderInfo;
       
   152 	TBTDevAddr iAddr;
       
   153 	RMBufChain	iSduData;
       
   154 	
       
   155 	TAvctpOutboundQ* 	iOutboundQ; // unowned
       
   156 	// iChannel is only used to carry the channel for the IPID responses. 
       
   157 	// in all the other cases (i.e. for normal writing) the right fragmenter is picked up based on the current channel.
       
   158 	// But IPID responses are generated by the protocol, asynchronously, so we save the channel value here.
       
   159 	TUint				iChannel;
       
   160 	};
       
   161 	
       
   162 /**
       
   163 The sap uses this class to take owner ship of data coming up from below
       
   164 & que it.
       
   165 */	
       
   166 NONSHARABLE_CLASS(HAvctpIncomingSdu) 
       
   167 	{
       
   168 friend class CAvctpSap; 		// So it can Q the Sdus
       
   169 	
       
   170 public:
       
   171 	inline HAvctpIncomingSdu(const TBTDevAddr& aAddr, 
       
   172 							 RMBufChain& aSduData);	
       
   173 
       
   174 	inline ~HAvctpIncomingSdu();
       
   175 	inline const TBTDevAddr& BTAddr() const;
       
   176 	inline const RMBufChain& Data() const;
       
   177 private:
       
   178 	TBTDevAddr	iAddr;
       
   179 	RMBufChain	iSduData; // takes ownership of inbound chain
       
   180 	TDblQueLink iQueLink;
       
   181 	};	
       
   182 	
       
   183 #include "avctppacket.inl"
       
   184 	
       
   185 #endif // AVCTPPACKET_H