bluetooth/btstack/l2cap/L2CapFecNegotiator.inl
changeset 0 29b1cd4cb562
child 10 8a27654f7b62
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2006-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 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef L2CAPFECNEGOTIATOR_INL
       
    24 #define L2CAPFECNEGOTIATOR_INL
       
    25 
       
    26 // Not needed, but keeps Carbide's semantic analyzer a bit happier.
       
    27 #include "L2CapFecNegotiator.h"
       
    28 
       
    29 //
       
    30 // TFecOptionHandlerDelegator inlines
       
    31 //
       
    32 inline TBool TFecOptionHandlerDelegator::IsOptionValid(const TRetransmissionAndFlowControlOption& aFecOption) const
       
    33 	{
       
    34 	const TModeSpecificFecOptionHandlerBase* handler = ModeToHandler(aFecOption.LinkMode());
       
    35 	// handler == NULL means invalid mode field
       
    36 	return handler && handler->IsOptionValid(aFecOption);
       
    37 	}
       
    38 
       
    39 inline TBool TFecOptionHandlerDelegator::IsPeerResponseAcceptable(const TRetransmissionAndFlowControlOption& aPreferred,
       
    40 																  const TRetransmissionAndFlowControlOption& aPeer) const
       
    41 	{
       
    42 #ifdef __FLOG_ACTIVE
       
    43 	LogCurrentValues(aPreferred, aPeer);
       
    44 #endif
       
    45 	__ASSERT_DEBUG(aPeer.LinkMode() == aPreferred.LinkMode(), Panic(EL2CAPPeerAndPreferredChannelModesNotEqual));
       
    46 
       
    47 	// Logically it's Preferred checking whether Peer is acceptable, so dispatch on preferred.
       
    48 	// (If we're here then both modes are equal though, so it doesn't really matter, but just
       
    49 	// sayin' in case it changes).
       
    50 	return Handler(aPreferred).IsPeerResponseAcceptable(aPreferred, aPeer);
       
    51 	}
       
    52 
       
    53 inline TBool TFecOptionHandlerDelegator::BuildPositiveResponse(TRetransmissionAndFlowControlOption& aPreferred,
       
    54 															   const TRetransmissionAndFlowControlOption& aPeer) const
       
    55 	{
       
    56 #ifdef __FLOG_ACTIVE
       
    57 	LogCurrentValues(aPreferred, aPeer);
       
    58 #endif
       
    59 
       
    60 	// Response will have peer - proposed mode so dispatch on peer.
       
    61 	return Handler(aPeer).BuildPositiveResponse(aPreferred, aPeer);
       
    62 	}
       
    63 
       
    64 inline void TFecOptionHandlerDelegator::BuildNegativeResponse(TRetransmissionAndFlowControlOption& aPreferred,
       
    65 															  const TRetransmissionAndFlowControlOption& aPeer) const
       
    66 	{
       
    67 #ifdef __FLOG_ACTIVE
       
    68 	LogCurrentValues(aPreferred, aPeer);
       
    69 #endif
       
    70 
       
    71 	// Response will have our preferred mode so dispatch on preferred.
       
    72 	Handler(aPreferred).BuildNegativeResponse(aPreferred, aPeer);
       
    73 	}
       
    74 
       
    75 inline void TFecOptionHandlerDelegator::PrepareImplicitPeerResponse(TRetransmissionAndFlowControlOption& aImplicitResponse,
       
    76 																	const TRetransmissionAndFlowControlOption& aPreferred) const
       
    77 	{
       
    78 	// Response will have our preferred mode so dispatch on preferred.
       
    79 	Handler(aPreferred).PrepareImplicitPeerResponse(aImplicitResponse, aPreferred);
       
    80 	}
       
    81 
       
    82 inline void TFecOptionHandlerDelegator::SetMaxTransmit(TRetransmissionAndFlowControlOption& aFecOption, TUint8 aMaxTransmit) const
       
    83 	{
       
    84 	Handler(aFecOption).SetMaxTransmit(aFecOption, aMaxTransmit);
       
    85 	}
       
    86 
       
    87 inline void TFecOptionHandlerDelegator::ZeroUnspecifiedRequestFields(TRetransmissionAndFlowControlOption& aFecOption) const
       
    88 	{
       
    89 	Handler(aFecOption).ZeroUnspecifiedRequestFields(aFecOption);
       
    90 	}
       
    91 
       
    92 inline void TFecOptionHandlerDelegator::ZeroUnspecifiedResponseFields(TRetransmissionAndFlowControlOption& aFecOption) const
       
    93 	{
       
    94 	Handler(aFecOption).ZeroUnspecifiedResponseFields(aFecOption);
       
    95 	}
       
    96 
       
    97 
       
    98 //
       
    99 // TL2CapSingleDirectionFecNegotiatorBase inlines
       
   100 //
       
   101 inline TL2CapSingleDirectionFecNegotiatorBase::TL2CapSingleDirectionFecNegotiatorBase(const TL2CapFecNegotiator& aFecNegotiator)
       
   102  :	iFecNegotiator(aFecNegotiator),
       
   103 	iConfigStatus(EOptionConfigOutstanding)
       
   104 	{}
       
   105 
       
   106 inline TL2CapConfigurationOptionGroupBase::TOptionConfigStatus TL2CapSingleDirectionFecNegotiatorBase::ConfigOptionStatus() const
       
   107 	{
       
   108 	return iConfigStatus;
       
   109 	}
       
   110 
       
   111 inline void TL2CapSingleDirectionFecNegotiatorBase::SetPeer(const TRetransmissionAndFlowControlOption& aFec)
       
   112 	{
       
   113 	iPeer = aFec;
       
   114 	}
       
   115 
       
   116 inline void TL2CapSingleDirectionFecNegotiatorBase::SetPreferred(const TRetransmissionAndFlowControlOption& aFec)
       
   117 	{
       
   118 	iPreferred = aFec;
       
   119 	}
       
   120 
       
   121 inline const TRetransmissionAndFlowControlOption& TL2CapSingleDirectionFecNegotiatorBase::Peer() const
       
   122 	{
       
   123 	return iPeer;
       
   124 	}
       
   125 
       
   126 inline const TRetransmissionAndFlowControlOption& TL2CapSingleDirectionFecNegotiatorBase::Preferred() const
       
   127 	{
       
   128 	return iPreferred;
       
   129 	}
       
   130 
       
   131 
       
   132 inline TL2CapIncomingFecNegotiator::TL2CapIncomingFecNegotiator(const TL2CapFecNegotiator& aFecNegotiator)
       
   133  :	TL2CapSingleDirectionFecNegotiatorBase(aFecNegotiator)
       
   134 	{}
       
   135 
       
   136 inline TL2CapOutgoingFecNegotiator::TL2CapOutgoingFecNegotiator(const TL2CapFecNegotiator& aFecNegotiator)
       
   137  :	TL2CapSingleDirectionFecNegotiatorBase(aFecNegotiator),
       
   138 	iIncludeValueInPositiveConfigResponse(EFalse)
       
   139 	{}
       
   140 
       
   141 inline TBool TL2CapOutgoingFecNegotiator::NeedToIncludeInPositiveConfigResponse()
       
   142 	{
       
   143 	return iIncludeValueInPositiveConfigResponse;
       
   144 	}
       
   145 
       
   146 inline void TL2CapOutgoingFecNegotiator::SetIncludeInPositiveConfigResponse(TBool aVal)
       
   147     {
       
   148     iIncludeValueInPositiveConfigResponse = aVal;
       
   149     }
       
   150 
       
   151 
       
   152 //
       
   153 // TL2CapFecNegotiator inlines
       
   154 //
       
   155 
       
   156 inline TL2CapFecNegotiator::TL2CapFecNegotiator()
       
   157  :	iIncomingNegotiator(*this),
       
   158  	iOutgoingNegotiator(*this),
       
   159  	iNegotiationBehavior(EState1),
       
   160  	iDesiredMode(EL2CAPBasicMode)
       
   161 	{}
       
   162 
       
   163 inline TInt TL2CapFecNegotiator::PeerRequestsOption(const TRetransmissionAndFlowControlOption& aFecOption)
       
   164 	{
       
   165 	if (iModeSpecificHandlers.IsOptionValid(aFecOption))
       
   166 		{
       
   167 		return iOutgoingNegotiator.ProcessPeerValue(aFecOption);
       
   168 		}
       
   169 	else
       
   170 		{
       
   171 		return KErrBadPacketReceived;
       
   172 		}
       
   173 	}
       
   174 
       
   175 inline TInt TL2CapFecNegotiator::PeerRequestsLastAcceptedValue()
       
   176 	{
       
   177 	TInt err = iOutgoingNegotiator.ProcessPeerValue(iOutgoingNegotiator.Peer());
       
   178 	iOutgoingNegotiator.SetIncludeInPositiveConfigResponse(EFalse);
       
   179 	return err;
       
   180 	}
       
   181 
       
   182 inline TInt TL2CapFecNegotiator::PeerRejectsOption(const TRetransmissionAndFlowControlOption& aFecOption)
       
   183 	{
       
   184 	TInt err = KErrNone;
       
   185 
       
   186     // Peer has sent us an Unacceptable Parameters response with a Retransmission And Flow Control
       
   187     // option in it. The only useful information there is the Channel Mode field - this is the one
       
   188     // actually being rejected, all the rest of them are non-negotiable (informational).
       
   189     // Some implementations send their default values for those informational parameters, others
       
   190     // just set them to 0 (that's what we do). Whatever their values are, we don't use them - we
       
   191     // use our own based on the mode suggested by the remote.
       
   192     // This is why we don't (and can't - they may be 0) check all the parameters with IsOptionValid
       
   193     // - channel mode is all we're interested in.
       
   194 
       
   195     if (TRetransmissionAndFlowControlOption::IsModeValid(aFecOption.LinkMode()))
       
   196 		{
       
   197 		iIncomingNegotiator.ProcessPeerValue(aFecOption, ETrue);
       
   198 		}
       
   199 	else
       
   200 		{
       
   201 		err = KErrBadPacketReceived;
       
   202 		}
       
   203 	return err;
       
   204 	}
       
   205 
       
   206 inline TInt TL2CapFecNegotiator::PeerAcceptsOption(const TRetransmissionAndFlowControlOption& aFecOption)
       
   207 	{
       
   208 	TInt err = KErrNone;
       
   209 	if (iModeSpecificHandlers.IsOptionValid(aFecOption))
       
   210 		{
       
   211 		iIncomingNegotiator.ProcessPeerValue(aFecOption, EFalse);
       
   212 		}
       
   213 	else
       
   214 		{
       
   215 		err = KErrBadPacketReceived;
       
   216 		}
       
   217 	return err;
       
   218 	}
       
   219 
       
   220 inline void TL2CapFecNegotiator::PeerAcceptsOption()
       
   221 	{
       
   222 	iIncomingNegotiator.ProcessImplicitPeerValue();
       
   223 	}
       
   224 
       
   225 inline TBool TL2CapFecNegotiator::NeedToIncludeInPositiveConfigResponse()
       
   226 	{
       
   227 	return iOutgoingNegotiator.NeedToIncludeInPositiveConfigResponse();
       
   228 	}
       
   229 
       
   230 inline const TL2CapEntityInfo& TL2CapFecNegotiator::PeerSupportedModes() const
       
   231 	{
       
   232 	return iPeerSupportedModes;
       
   233 	}
       
   234 
       
   235 inline TL2CapFecNegotiator::TNegotiationBehavior TL2CapFecNegotiator::NegotiationBehavior() const
       
   236 	{
       
   237 	return iNegotiationBehavior;
       
   238 	}
       
   239 
       
   240 inline TL2CapChannelMode TL2CapFecNegotiator::DesiredMode() const
       
   241 	{
       
   242 	return iDesiredMode;
       
   243 	}
       
   244 
       
   245 inline TUint8 TL2CapFecNegotiator::MaxTransmit() const
       
   246     {
       
   247     return iMaxTransmit;
       
   248     }
       
   249 
       
   250 inline const TFecOptionHandlerDelegator& TL2CapFecNegotiator::ModeSpecificHandlers() const
       
   251 	{
       
   252 	return iModeSpecificHandlers;
       
   253 	}
       
   254 
       
   255 inline const TRetransmissionAndFlowControlOption& TL2CapFecNegotiator::IncomingPreferred() const
       
   256 	{
       
   257 	return iIncomingNegotiator.Preferred();
       
   258 	}
       
   259 
       
   260 inline const TRetransmissionAndFlowControlOption& TL2CapFecNegotiator::OutgoingPreferred() const
       
   261 	{
       
   262 	return iOutgoingNegotiator.Preferred();
       
   263 	}
       
   264 
       
   265 inline TL2CapConfigurationOptionGroupBase::TOptionConfigStatus TL2CapFecNegotiator::IncomingConfigOptionStatus() const
       
   266 	{
       
   267 	return iIncomingNegotiator.ConfigOptionStatus();
       
   268 	}
       
   269 
       
   270 inline TL2CapConfigurationOptionGroupBase::TOptionConfigStatus TL2CapFecNegotiator::OutgoingConfigOptionStatus() const
       
   271 	{
       
   272 	return iOutgoingNegotiator.ConfigOptionStatus();
       
   273 	}
       
   274 
       
   275 inline TL2CapDataControllerConfig TL2CapFecNegotiator::DataControllerConfig() const
       
   276 	{
       
   277 	return TL2CapDataControllerConfig(OutgoingLinkMode(),
       
   278 									  OutgoingTxWindowSize(),
       
   279 									  OutgoingMaxTransmit(),
       
   280 									  OutgoingRetransmissionTimeout(),
       
   281 									  IncomingMonitorTimeout(),
       
   282 									  IncomingTxWindowSize(),
       
   283 									  IncomingRetransmissionTimeout(),
       
   284 									  IncomingMaximumPDUSize());
       
   285 	}
       
   286 
       
   287 
       
   288 // The general rule for methods below is that for the Outgoing direction we get the parameters
       
   289 // from the Preferred fields since in case of wildcard params (TxWin, MPS), these fields contain
       
   290 // the correct minimized values. For the same reason the Incoming direction parameters are fetched
       
   291 // from the Peer values.
       
   292 // Note that it's not always that simple in case of non-negotiated parameters like MaxTransmit,
       
   293 // Retransmission & Monitor TO, which is the reason these methods exist.
       
   294 
       
   295 inline TL2CapChannelMode TL2CapFecNegotiator::OutgoingLinkMode() const
       
   296 	{
       
   297 	return iOutgoingNegotiator.Preferred().LinkMode();
       
   298 	}
       
   299 
       
   300 inline TL2CapChannelMode TL2CapFecNegotiator::IncomingLinkMode() const
       
   301 	{
       
   302 	return iIncomingNegotiator.Peer().LinkMode();
       
   303 	}
       
   304 
       
   305 inline TUint8 TL2CapFecNegotiator::OutgoingLinkModeAsUnsignedByte() const
       
   306 	{
       
   307 	return iOutgoingNegotiator.Preferred().LinkModeAsUnsignedByte();
       
   308 	}
       
   309 
       
   310 inline TUint8 TL2CapFecNegotiator::IncomingLinkModeAsUnsignedByte() const
       
   311 	{
       
   312 	return iIncomingNegotiator.Peer().LinkModeAsUnsignedByte();
       
   313 	}
       
   314 
       
   315 inline TUint8 TL2CapFecNegotiator::OutgoingTxWindowSize() const
       
   316 	{
       
   317 	return iOutgoingNegotiator.Preferred().TxWindowSize();
       
   318 	}
       
   319 
       
   320 inline TUint8 TL2CapFecNegotiator::IncomingTxWindowSize() const
       
   321 	{
       
   322 	return iIncomingNegotiator.Peer().TxWindowSize();
       
   323 	}
       
   324 
       
   325 inline TUint8 TL2CapFecNegotiator::OutgoingMaxTransmit() const
       
   326 	{
       
   327 	// Peer sends us the value to use in its Config Request.
       
   328 	return iOutgoingNegotiator.Peer().MaxTransmit();
       
   329 	}
       
   330 
       
   331 inline TUint8 TL2CapFecNegotiator::IncomingMaxTransmit() const
       
   332 	{
       
   333 	// We send the peer the value to use in our Config Request.
       
   334 	return iIncomingNegotiator.Preferred().MaxTransmit();
       
   335 	}
       
   336 
       
   337 inline TUint16 TL2CapFecNegotiator::OutgoingRetransmissionTimeout() const
       
   338 	{
       
   339 	return iOutgoingNegotiator.Preferred().RetransmissionTimeout();
       
   340 	}
       
   341 
       
   342 inline TUint16 TL2CapFecNegotiator::IncomingRetransmissionTimeout() const
       
   343 	{
       
   344 	return iIncomingNegotiator.Peer().RetransmissionTimeout();
       
   345 	}
       
   346 
       
   347 // Outgoing traffic -> Incoming S-Frames -> Monitor TO that our peer will use.
       
   348 inline TUint16 TL2CapFecNegotiator::OutgoingMonitorTimeout() const
       
   349 	{
       
   350 	if (iIncomingNegotiator.Preferred().LinkMode() == EL2CAPEnhancedRetransmissionMode ||
       
   351 		iIncomingNegotiator.Preferred().LinkMode() == EL2CAPStreamingMode)
       
   352 		{
       
   353 		// Peer sends the time-outs it'll use in its Config Response.
       
   354 		return iIncomingNegotiator.Peer().MonitorTimeout();
       
   355 		}
       
   356 	else
       
   357 		{
       
   358 		// Negotiated in the direction it relates to.
       
   359 		return iOutgoingNegotiator.Preferred().MonitorTimeout();
       
   360 		}
       
   361 	}
       
   362 
       
   363 // Incoming traffic -> Outgoing S-Frames -> Monitor TO that we will use.
       
   364 inline TUint16 TL2CapFecNegotiator::IncomingMonitorTimeout() const
       
   365 	{
       
   366 	if (iIncomingNegotiator.Preferred().LinkMode() == EL2CAPEnhancedRetransmissionMode ||
       
   367 		iIncomingNegotiator.Preferred().LinkMode() == EL2CAPStreamingMode)
       
   368 		{
       
   369 		// We send the time-outs we'll use in our Config Response.
       
   370 		return iOutgoingNegotiator.Preferred().MonitorTimeout();
       
   371 		}
       
   372 	else
       
   373 		{
       
   374 		// Negotiated in the direction it relates to.
       
   375 		return iIncomingNegotiator.Peer().MonitorTimeout();
       
   376 		}
       
   377 	}
       
   378 
       
   379 inline TUint16 TL2CapFecNegotiator::OutgoingMaximumPDUSize() const
       
   380 	{
       
   381 	return iOutgoingNegotiator.Preferred().MaximumPDUSize();
       
   382 	}
       
   383 
       
   384 inline TUint16 TL2CapFecNegotiator::IncomingMaximumPDUSize() const
       
   385 	{
       
   386 	return iIncomingNegotiator.Peer().MaximumPDUSize();
       
   387 	}
       
   388 
       
   389 #endif /*L2CAPFECNEGOTIATOR_INL*/