bluetooth/btstack/l2cap/l2capSigPacketConfigure.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2004-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 #ifndef L2CAPSIGPACKETCONFIGURE_H
       
    17 #define L2CAPSIGPACKETCONFIGURE_H
       
    18 
       
    19 #include "l2capCommand.h"
       
    20 
       
    21 class CL2CapChannelConfig;
       
    22 class TL2CapConfigParamOptions;
       
    23 
       
    24 NONSHARABLE_CLASS(HConfigureRequest) : public HL2CapCommand
       
    25 	{
       
    26 public:	
       
    27 	static HConfigureRequest* New(TL2CAPPort aRemotePort, CL2CapChannelConfig& aConfig,
       
    28                  				  TUint8 aRTXTimerDuration = KDefaultRTXTimerDuration,
       
    29 	             				  TUint16 aERTXTimerDuration = KDefaultERTXTimerDuration);
       
    30 	static TInt NewCommandIfValid(RMBufChain& aBuffer, HL2CapCommand*& aCommand);
       
    31 	
       
    32 	TBool ProcessCommand(CL2CapSignalHandler& aSignalHandler);
       
    33 
       
    34 	inline TL2CAPPort DestinationCID() const;
       
    35 	inline TConfigFlags Flags() const;
       
    36 	inline void SetDestinationCID(TL2CAPPort aPort);
       
    37 	inline void SetFlags(TConfigFlags aFlags);
       
    38 
       
    39 	TInt ParseOptions(TL2CapConfigParamOptions& aConfigOptions, RMBufChain& aUnknownOptions) const;
       
    40 	TInt AddOptionsToCommand(CL2CapChannelConfig& aConfig);
       
    41 
       
    42 private:
       
    43 	HConfigureRequest(RMBufChain& aCommand,
       
    44                  	  TUint8 aRTXTimerDuration = KDefaultRTXTimerDuration,
       
    45 	                  TUint16 aERTXTimerDuration = KDefaultERTXTimerDuration);
       
    46 
       
    47 private:
       
    48 	const static TUint8 KConfigRequestEmptyLength	= 8;
       
    49 	
       
    50 	const static TUint8 KDestinationCIDOffset		= 4;
       
    51 	const static TUint8 KFlagsOffset				= 6;
       
    52 	const static TUint8 KOptionsOffset				= 8;
       
    53 	
       
    54 	const static TUint8 KNoConfigurationFlags		= 0;
       
    55 	};
       
    56 
       
    57 inline TL2CAPPort HConfigureRequest::DestinationCID() const
       
    58 	{
       
    59 	return GetLittleEndian16(KDestinationCIDOffset, iCommand);
       
    60 	}
       
    61 
       
    62 inline TConfigFlags HConfigureRequest::Flags() const
       
    63 	{
       
    64 	return GetLittleEndian16(KFlagsOffset, iCommand);
       
    65 	}
       
    66 
       
    67 inline void HConfigureRequest::SetDestinationCID(TL2CAPPort aPort)
       
    68 	{
       
    69 	PutLittleEndian16(aPort, KDestinationCIDOffset, iCommand);
       
    70 	}
       
    71 
       
    72 inline void HConfigureRequest::SetFlags(TConfigFlags aFlags)
       
    73 	{
       
    74 	PutLittleEndian16(aFlags, KFlagsOffset, iCommand);
       
    75 	}
       
    76 
       
    77 
       
    78 NONSHARABLE_CLASS(HConfigureResponse) :public HL2CapCommand
       
    79 	{
       
    80 public:
       
    81 	static HConfigureResponse* New(TUint8 aId, TL2CAPPort aRemotePort, TConfigFlags aFlags, TConfigResponseResult aResult);
       
    82 	static TInt NewCommandIfValid(RMBufChain& aBuffer, HL2CapCommand*& aCommand);
       
    83 	
       
    84 	TBool ProcessCommand(CL2CapSignalHandler& aSignalHandler);
       
    85 
       
    86 	inline TL2CAPPort SourceCID() const;
       
    87 	inline TConfigFlags Flags() const;
       
    88 	inline TConfigResponseResult Results() const;
       
    89 	inline void SetSourceCID(TL2CAPPort aPort);
       
    90 	inline void SetFlags(TConfigFlags aFlags);
       
    91 	inline void SetResults(TConfigResponseResult aResult);
       
    92 
       
    93 	TInt ParseOptions(TL2CapConfigParamOptions& aConfigOptions, RMBufChain& aUnknownOptions) const;
       
    94 	TInt AddOptionsToCommand(CL2CapChannelConfig& aConfig, TConfigResponseResult aResult);
       
    95 	void AddUnknownOptionsToCommand(RMBufChain& aUnknownOptions);
       
    96 
       
    97 public:
       
    98 	// Used on creation to specify that no flags
       
    99 	// (i.e., the continuation flag) are set.
       
   100 	const static TUint8 KNoConfigurationFlags		= 0;
       
   101 
       
   102 private:
       
   103 	HConfigureResponse(RMBufChain& aCommand);
       
   104 		
       
   105 private:
       
   106 	const static TUint8 KConfigResponseEmptyLength	= 10;
       
   107 	
       
   108 	const static TUint8 KSourceCIDOffset			= 4;
       
   109 	const static TUint8 KFlagsOffset				= 6;
       
   110 	const static TUint8 KResultOffset				= 8;
       
   111 	const static TUint8 KOptionsOffset				= 10;
       
   112 	};
       
   113 
       
   114 inline TL2CAPPort HConfigureResponse::SourceCID() const
       
   115 	{
       
   116 	return GetLittleEndian16(KSourceCIDOffset, iCommand);
       
   117 	}
       
   118 
       
   119 inline TConfigFlags HConfigureResponse::Flags() const
       
   120 	{
       
   121 	return GetLittleEndian16(KFlagsOffset, iCommand);
       
   122 	}
       
   123 
       
   124 inline TConfigResponseResult HConfigureResponse::Results() const
       
   125 	{
       
   126 	return static_cast<TConfigResponseResult>(GetLittleEndian16(KResultOffset, iCommand));
       
   127 	}
       
   128 
       
   129 inline void HConfigureResponse::SetSourceCID(TL2CAPPort aPort)
       
   130 	{
       
   131 	PutLittleEndian16(aPort, KSourceCIDOffset, iCommand);
       
   132 	}
       
   133 
       
   134 inline void HConfigureResponse::SetFlags(TConfigFlags aFlags)
       
   135 	{
       
   136 	PutLittleEndian16(aFlags, KFlagsOffset, iCommand);
       
   137 	}
       
   138 
       
   139 inline void HConfigureResponse::SetResults(TConfigResponseResult aResult)
       
   140 	{
       
   141 	PutLittleEndian16(static_cast<TUint16>(aResult), KResultOffset, iCommand);
       
   142 	}
       
   143 
       
   144 NONSHARABLE_CLASS(TL2CapConfigParamOptions)
       
   145 	{
       
   146 public:
       
   147 	TL2CapConfigParamOptions();
       
   148 
       
   149 	inline void SetMtu(const TMTUOption& aMtu);
       
   150 	inline TBool IsMtuSet() const;
       
   151 	inline const TMTUOption& Mtu() const;
       
   152 
       
   153 	inline void SetFlushTimeout(const TFlushTimeoutDurationOption& aFlushTimeout);
       
   154 	inline TBool IsFlushTimeoutSet() const;
       
   155 	inline const TFlushTimeoutDurationOption& FlushTimeout() const;
       
   156 	
       
   157 	inline void SetFec(const TRetransmissionAndFlowControlOption& aFec);
       
   158 	inline TBool IsFecSet() const;
       
   159 	inline const TRetransmissionAndFlowControlOption& Fec() const;
       
   160 
       
   161 	inline void SetQos(const TQualityOfServiceOption& aQos);
       
   162 	inline TBool IsQosSet() const;
       
   163 	inline const TQualityOfServiceOption& Qos() const;
       
   164 
       
   165 	TBool operator==(const TL2CapConfigParamOptions& aThat);
       
   166 
       
   167 	TInt ParseOptions(TUint8 aOptionOffset, const RMBufChain& aCommand, RMBufChain& aUnknownOptions);
       
   168 	
       
   169 	static TInt AddConfigRequestOptions(CL2CapChannelConfig& aConfig, TUint8 aOptionOffset, RMBufChain& aOptions);
       
   170 	static TInt AddConfigResponseOptions(CL2CapChannelConfig& aConfig, TUint8 aOptionOffset, RMBufChain& aOptions, TConfigResponseResult aResult);
       
   171 	static TInt AddMtuOptionL(TInt16 aMtu, TUint8 aOptionOffset, RMBufChain& aOptions);
       
   172 	static TInt AddFlushOptionL(TInt16 aFlushTimeout, TUint8 aOptionOffset, RMBufChain& aOptions);
       
   173 	static TInt AddQosOptionL(const TQualityOfServiceOption& aQosOption, TUint8 aOptionOffset, RMBufChain& aOptions);
       
   174 	static TInt AddFecOptionL(const TRetransmissionAndFlowControlOption& aFecOption, TUint8 aOptionOffset, RMBufChain& aOptions);
       
   175 	static TBool VerifyOptionsStructure(TUint8 aOptionOffset, const RMBufChain& aCommand);
       
   176 private:
       
   177 	// Options Constants
       
   178 	const static TUint8 KTypeOffset   			= 0;
       
   179 	const static TUint8 KLengthOffset 			= 1;
       
   180 	const static TUint8 KDataOffset   			= 2;
       
   181 	const static TUint8 KOptionHeaderLength		= 2;
       
   182 
       
   183 	const static TUint8 KMTUOptionDataLen 		= 2;
       
   184 	const static TUint8 KFlushOptionDataLen		= 2;
       
   185 	const static TUint8 KQOSOptionDataLen 		= 22;
       
   186 	const static TUint8 KFECOptionDataLen		= 9;
       
   187 	const static TUint8 KFcsOptionDataLen		= 1;
       
   188 	
       
   189 	//QOS Options Offsets
       
   190 	const static TUint8 KQOSServiceTypeOffset 	= 1;
       
   191 	const static TUint8 KTokenRateOffset 		= 2;
       
   192 	const static TUint8 KTokenBucketSizeOffset 	= 6;
       
   193 	const static TUint8 KPeakBandwidthOffset 	= 10;
       
   194 	const static TUint8 KLatencyOffset 			= 14;
       
   195 	const static TUint8 KDelayVariationOffset 	= 18;
       
   196 
       
   197 	// FEC Options Offsets
       
   198 	const static TUint8 KLinkModeOffset					= 0;
       
   199 	const static TUint8 KTxWindowSizeOffset 			= 1;
       
   200 	const static TUint8 KMaxTransmitOffset 				= 2;
       
   201 	const static TUint8 KRetransmissionTimeoutOffset 	= 3;
       
   202 	const static TUint8 KMonitorTimeoutOffset 			= 5;
       
   203 	const static TUint8 KMaximumPDUSizeOffset 			= 7;
       
   204 
       
   205 private:
       
   206 	TBool								iMtuSet;
       
   207 	TMTUOption							iMtu;
       
   208 
       
   209 	TBool								iFlushTimeoutSet;
       
   210 	TFlushTimeoutDurationOption			iFlushTimeout;
       
   211 
       
   212 	TBool								iFecSet;
       
   213 	TRetransmissionAndFlowControlOption iFec;
       
   214 
       
   215 	TBool								iQosSet;
       
   216 	TQualityOfServiceOption				iQos;
       
   217 	};
       
   218 
       
   219 
       
   220 inline void TL2CapConfigParamOptions::SetMtu(const TMTUOption& aMtu)
       
   221 	{
       
   222 	iMtu = aMtu;
       
   223 	iMtuSet = ETrue;
       
   224 	}
       
   225 
       
   226 inline TBool TL2CapConfigParamOptions::IsMtuSet() const
       
   227 	{ return iMtuSet; }
       
   228 
       
   229 inline const TMTUOption& TL2CapConfigParamOptions::Mtu() const
       
   230 	{ return iMtu; }
       
   231 
       
   232 inline void TL2CapConfigParamOptions::SetFlushTimeout(const TFlushTimeoutDurationOption& aFlushTimeout)
       
   233 	{
       
   234 	iFlushTimeout = aFlushTimeout;
       
   235 	iFlushTimeoutSet = ETrue;
       
   236 	}
       
   237 
       
   238 inline TBool TL2CapConfigParamOptions::IsFlushTimeoutSet() const
       
   239 	{ return iFlushTimeoutSet; }
       
   240 
       
   241 inline const TFlushTimeoutDurationOption& TL2CapConfigParamOptions::FlushTimeout() const
       
   242 	{ return iFlushTimeout; }
       
   243 
       
   244 inline void TL2CapConfigParamOptions::SetFec(const TRetransmissionAndFlowControlOption& aFec)
       
   245 	{
       
   246 	iFec = aFec;
       
   247 	iFecSet = ETrue;
       
   248 	}
       
   249 
       
   250 inline TBool TL2CapConfigParamOptions::IsFecSet() const
       
   251 	{ return iFecSet; }
       
   252 
       
   253 inline const TRetransmissionAndFlowControlOption& TL2CapConfigParamOptions::Fec() const
       
   254 	{ return iFec; }
       
   255 
       
   256 inline void TL2CapConfigParamOptions::SetQos(const TQualityOfServiceOption& aQos)
       
   257 	{
       
   258 	iQos = aQos;
       
   259 	iQosSet = ETrue;
       
   260 	}
       
   261 
       
   262 inline TBool TL2CapConfigParamOptions::IsQosSet() const
       
   263 	{ return iQosSet; }
       
   264 
       
   265 inline const TQualityOfServiceOption& TL2CapConfigParamOptions::Qos() const
       
   266 	{ return iQos; }
       
   267 
       
   268 #endif