|
1 // Copyright (c) 2008-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 L2CAPENHANCEDDATACONTROLLER_INL |
|
17 #define L2CAPENHANCEDDATACONTROLLER_INL |
|
18 |
|
19 |
|
20 inline TBool RL2CapErtmTimerManager::IsLocalBusyDelayTimerRunning() const |
|
21 { |
|
22 return iLocalBusyDelayTimerRunning; |
|
23 } |
|
24 |
|
25 |
|
26 inline void RL2CapErtmUnacknowledgedIFrames::Append(HIFramePDU& aFrame) |
|
27 { |
|
28 __ASSERT_DEBUG(iFrameIndex[aFrame.TxSeqNumber()] == NULL, |
|
29 Panic(EL2CAPTryingToAppendSameTxSeqIFrameTwice)); |
|
30 |
|
31 iFrameList.AddLast(aFrame); |
|
32 iFrameIndex[aFrame.TxSeqNumber()] = &aFrame; |
|
33 } |
|
34 |
|
35 inline void RL2CapErtmUnacknowledgedIFrames::Remove(HIFramePDU& aFrame) |
|
36 { |
|
37 __ASSERT_DEBUG(iFrameIndex[aFrame.TxSeqNumber()] == &aFrame, |
|
38 Panic(EL2CAPTryingToRemoveUnackedIFrameWithSameTxSeqButDifferentAddress)); |
|
39 |
|
40 aFrame.iLink.Deque(); |
|
41 iFrameIndex[aFrame.TxSeqNumber()] = NULL; |
|
42 } |
|
43 |
|
44 inline HIFramePDU* RL2CapErtmUnacknowledgedIFrames::First() const |
|
45 { |
|
46 return iFrameList.First(); |
|
47 } |
|
48 |
|
49 inline HIFramePDU* RL2CapErtmUnacknowledgedIFrames::Last() const |
|
50 { |
|
51 return iFrameList.Last(); |
|
52 } |
|
53 |
|
54 inline HIFramePDU* RL2CapErtmUnacknowledgedIFrames::operator[](TUint8 aTxSeq) const |
|
55 { |
|
56 return iFrameIndex[aTxSeq]; |
|
57 } |
|
58 |
|
59 inline TBool RL2CapErtmUnacknowledgedIFrames::IsEmpty() const |
|
60 { |
|
61 return iFrameList.IsEmpty(); |
|
62 } |
|
63 |
|
64 inline TDblQueIter<HIFramePDU> RL2CapErtmUnacknowledgedIFrames::Iterator() |
|
65 { |
|
66 return TDblQueIter<HIFramePDU>(iFrameList); |
|
67 } |
|
68 |
|
69 |
|
70 inline TBool CL2CapErtmDataTransmitter::RemoteBusy() const |
|
71 { |
|
72 return iRemoteBusy; |
|
73 } |
|
74 |
|
75 inline TBool CL2CapErtmDataTransmitter::IsWaitAckStatePending() const |
|
76 { |
|
77 return iWaitAckStatePending; |
|
78 } |
|
79 |
|
80 inline void CL2CapErtmDataTransmitter::EnterWaitAckState() |
|
81 { |
|
82 __ASSERT_DEBUG(!iController.IsPollOutstanding(), |
|
83 Panic(EL2CAPAttemptToEnterWaitAckWhenAlreadyInAWaitState)); |
|
84 |
|
85 iWaitAckStatePending = EFalse; |
|
86 iInWaitAckState = ETrue; |
|
87 } |
|
88 |
|
89 inline TBool CL2CapErtmDataTransmitter::InWaitAckState() const |
|
90 { |
|
91 return iInWaitAckState; |
|
92 } |
|
93 |
|
94 inline void CL2CapErtmDataTransmitter::SendOrPendL(HIFramePDU& aIFrame) |
|
95 { |
|
96 if (iInWaitAckState) |
|
97 { |
|
98 iController.OutgoingQ().PendRetransmitIFrameL(aIFrame); |
|
99 } |
|
100 else |
|
101 { |
|
102 iController.OutgoingQ().QueueIFrameL(aIFrame); |
|
103 } |
|
104 } |
|
105 |
|
106 inline RL2CapRetransmissionModeTimerManager& CL2CapErtmDataTransmitter::TimerMan() |
|
107 { |
|
108 return iController.TimerMan(); |
|
109 } |
|
110 |
|
111 inline RL2CapErtmOutgoingQueue& CL2CapErtmDataTransmitter::OutgoingQ() |
|
112 { |
|
113 return iController.OutgoingQ(); |
|
114 } |
|
115 |
|
116 inline TBool CL2CapErtmDataTransmitter::HaveUnackedIFrames() const |
|
117 { |
|
118 return !iUnackedIFrames.IsEmpty(); |
|
119 } |
|
120 |
|
121 inline TBool CL2CapErtmDataTransmitter::IsRetransmittingUnackedIFrames() const |
|
122 { |
|
123 return iUnackedIFrames[iNextTxSeq] != NULL; |
|
124 } |
|
125 |
|
126 inline TBool CL2CapErtmDataTransmitter::IsNextUnackedIFrameAwaitingHciCompletion() const |
|
127 { |
|
128 __ASSERT_DEBUG(IsRetransmittingUnackedIFrames(), Panic(EL2CapReferencingUnackedIFrameWhenNoRetransmissionGoing)); |
|
129 return iUnackedIFrames[iNextTxSeq]->IsAwaitingHciCompletion(); |
|
130 } |
|
131 |
|
132 inline TBool CL2CapErtmDataTransmitter::IsReqSeqValid(TUint8 aReqSeq) |
|
133 { |
|
134 // Per the spec: |
|
135 // With-Valid-ReqSeq: The ReqSeq of the received frame is in the range |
|
136 // ExpectedAckSeq <= ReqSeq <= NextTxSeq. |
|
137 // |
|
138 // We can't just use NextTxSeq though because in our implementation we slip it back when we |
|
139 // retransmit all unacked I-Frames, which means it doesn't always point to the next TxSeq to |
|
140 // allocate, it's rather the next TxSeq to allocate OR retransmit. The real boundary of the |
|
141 // TxSeqs sent out so far in the current window is the youngest I-Frame on the unacknowledged |
|
142 // list, so we use that in this check. |
|
143 // |
|
144 // Note: ideally we should just be able to use NextTxSeq because the protocol is designed |
|
145 // so that you only retransmit all unacked I-Frames once you've made sure they haven't been |
|
146 // received by the peer, which would mean that we only slip NextTxSeq back having made |
|
147 // sure that the peer will not acknowledge anything beyond that value. There is however |
|
148 // one loophole in the protocol: when the peer exits LocalBusy and sends us an RR (we need |
|
149 // to restart the transmission from the ReqSeq given in that RR) while we keep on sending |
|
150 // I-Frames during the RR's travel time. These I-Frames will obviously have newer TxSeqs |
|
151 // than the ReqSeq from the RR acknowledges and will thus be retransmitted when we receive |
|
152 // the RR. So if the peer didn't ignore the original transmissions that came through |
|
153 // when it was in WAIT_F, it will detect the retransmissions as duplicates and (if it's a |
|
154 // correct implementation) close the connection. Some unwisely coded remotes however will |
|
155 // accept the originals and ignore the duplicates, and in that case we may receive a ReqSeq |
|
156 // for the originals while we're retransmitting them, which means it will be a younger |
|
157 // seqNum than NextTxSeq. |
|
158 |
|
159 const TUint8 lastValidReqSeq = iUnackedIFrames.IsEmpty() ? iNextTxSeq : L2CapDataUtils::Mod64(iUnackedIFrames.Last()->TxSeqNumber() + 1); |
|
160 return L2CapDataUtils::InWindow(aReqSeq, iExpectedAckSeq, lastValidReqSeq); |
|
161 } |
|
162 |
|
163 inline TUint8 CL2CapErtmDataTransmitter::ExpectedAckSeq() const |
|
164 { |
|
165 return iExpectedAckSeq; |
|
166 } |
|
167 |
|
168 inline TUint8 CL2CapErtmDataTransmitter::NextTxSeq() const |
|
169 { |
|
170 return iNextTxSeq; |
|
171 } |
|
172 |
|
173 |
|
174 inline void TL2CapErtmMissingTxSeqs::AppendTxSeq(TUint8 aTxSeq) |
|
175 { |
|
176 __ASSERT_DEBUG(iNumMissingTxSeqs < KMaxSRejsInFlight, |
|
177 Panic(EL2CAPGivenMoreSRejedTxSeqsToTraceThanCanStore)); |
|
178 |
|
179 iMissingTxSeqs[iNumMissingTxSeqs++] = aTxSeq; |
|
180 } |
|
181 |
|
182 inline TBool TL2CapErtmMissingTxSeqs::GetNextTxSeqForResend(TUint8& aTxSeq) |
|
183 { |
|
184 __ASSERT_DEBUG(iResendIdx < iNumMissingTxSeqs, |
|
185 Panic(EL2CAPStrayCallToGetTxSeqForResend)); |
|
186 |
|
187 aTxSeq = iMissingTxSeqs[iResendIdx++]; |
|
188 return iResendIdx < iNumMissingTxSeqs; |
|
189 } |
|
190 |
|
191 inline TUint8 TL2CapErtmMissingTxSeqs::LastTxSeq() const |
|
192 { |
|
193 __ASSERT_DEBUG(!IsEmpty(), |
|
194 Panic(EL2CAPLastTxSeqCalledWhenNoneAreExpected)); |
|
195 |
|
196 return iMissingTxSeqs[iNumMissingTxSeqs - 1]; |
|
197 } |
|
198 |
|
199 inline TBool TL2CapErtmMissingTxSeqs::IsEmpty() const |
|
200 { |
|
201 return iNumMissingTxSeqs == 0; |
|
202 } |
|
203 |
|
204 inline TBool TL2CapErtmMissingTxSeqs::AllRequestedFramesReceived() const |
|
205 { |
|
206 return iExpectedRecvIdx == iNumMissingTxSeqs; |
|
207 } |
|
208 |
|
209 inline TUint8 TL2CapErtmMissingTxSeqs::ExpectedSRejTxSeq() const |
|
210 { |
|
211 __ASSERT_DEBUG(!IsEmpty() && !AllRequestedFramesReceived(), |
|
212 Panic(EL2CAPNextExpectedTxSeqCalledWhenNoneAreExpected)); |
|
213 return iMissingTxSeqs[iExpectedRecvIdx]; |
|
214 } |
|
215 |
|
216 inline TInt TL2CapErtmMissingTxSeqs::NumMissingTxSeqs() const |
|
217 { |
|
218 return iNumMissingTxSeqs; |
|
219 } |
|
220 |
|
221 inline TBool TL2CapErtmMissingTxSeqs::HaveSpaceForNewTxSeqs(TInt aNumTxSeqs) const |
|
222 { |
|
223 return KMaxSRejsInFlight - iNumMissingTxSeqs >= aNumTxSeqs; |
|
224 } |
|
225 |
|
226 |
|
227 inline void TL2CapErtmMissingTxSeqs::Reset() |
|
228 { |
|
229 iNumMissingTxSeqs = iExpectedRecvIdx = iResendIdx = 0; |
|
230 } |
|
231 |
|
232 |
|
233 inline TBool RL2CapErtmIncomingIFrameQueue::IsEmpty() const |
|
234 { |
|
235 return iQueue.IsEmpty(); |
|
236 } |
|
237 |
|
238 inline void RL2CapErtmIncomingIFrameQueue::DeleteAllFrames() |
|
239 { |
|
240 iQueue.Free(); |
|
241 } |
|
242 |
|
243 inline TUint8 RL2CapErtmIncomingIFrameQueue::TxSeqExpectedBySduQ() const |
|
244 { |
|
245 return iTxSeqExpectedBySduQ; |
|
246 } |
|
247 |
|
248 inline void CL2CapErtmDataReceiver::PassToIncomingQL(RMBufChain& aIFrame) |
|
249 { |
|
250 iIncomingIFrameQ.HandleIncomingIFrameL(aIFrame, *this); |
|
251 } |
|
252 |
|
253 inline void CL2CapErtmDataReceiver::PassToSduQL(RMBufChain& aIFrame) const |
|
254 { |
|
255 iController.PassToSduQL(aIFrame); |
|
256 } |
|
257 |
|
258 inline TBool CL2CapErtmDataReceiver::IsIncomingSduQFull() const |
|
259 { |
|
260 return iIncomingSduQFull; |
|
261 } |
|
262 |
|
263 inline TBool CL2CapErtmDataReceiver::LocalBusy() const |
|
264 { |
|
265 return iLocalBusy; |
|
266 } |
|
267 |
|
268 inline void CL2CapErtmDataReceiver::FlushBufferedIncomingIFrames() |
|
269 { |
|
270 __ASSERT_DEBUG(iReceiveState == &iStateRecv, |
|
271 Panic(EL2CAPFlushingIncomingIFramesInStateOtherThanRecv)); |
|
272 iIncomingIFrameQ.DeleteAllFrames(); |
|
273 iExpectedTxSeq = iIncomingIFrameQ.TxSeqExpectedBySduQ(); |
|
274 } |
|
275 |
|
276 inline TBool CL2CapErtmDataReceiver::IsWaitFStatePending() const |
|
277 { |
|
278 return iWaitFStatePending; |
|
279 } |
|
280 |
|
281 inline void CL2CapErtmDataReceiver::EnterWaitFState() |
|
282 { |
|
283 __ASSERT_DEBUG(!iController.IsPollOutstanding(), |
|
284 Panic(EL2CAPAttemptToEnterWaitFWhenAlreadyInAWaitState)); |
|
285 |
|
286 iWaitFStatePending = EFalse; |
|
287 iInWaitFState = ETrue; |
|
288 } |
|
289 |
|
290 inline TBool CL2CapErtmDataReceiver::InWaitFState() const |
|
291 { |
|
292 return iInWaitFState; |
|
293 } |
|
294 |
|
295 inline TBool CL2CapErtmDataReceiver::SendAck() const |
|
296 { |
|
297 return iSendAck; |
|
298 } |
|
299 |
|
300 inline RL2CapErtmTimerManager& CL2CapErtmDataReceiver::TimerMan() |
|
301 { |
|
302 return iController.TimerMan(); |
|
303 } |
|
304 |
|
305 inline RL2CapErtmOutgoingQueue& CL2CapErtmDataReceiver::OutgoingQ() |
|
306 { |
|
307 return iController.OutgoingQ(); |
|
308 } |
|
309 |
|
310 inline TUint8 CL2CapErtmDataReceiver::ExpectedTxSeq() const |
|
311 { |
|
312 return iExpectedTxSeq; |
|
313 } |
|
314 |
|
315 inline void CL2CapErtmDataReceiver::SetExpectedTxSeq(TUint8 aTxSeq) |
|
316 { |
|
317 iExpectedTxSeq = aTxSeq; |
|
318 } |
|
319 |
|
320 inline void CL2CapErtmDataReceiver::IncExpectedTxSeq() |
|
321 { |
|
322 iExpectedTxSeq = L2CapDataUtils::Mod64(iExpectedTxSeq + 1); |
|
323 } |
|
324 |
|
325 inline TUint8 CL2CapErtmDataReceiver::BufferSeq() const |
|
326 { |
|
327 return iBufferSeq; |
|
328 } |
|
329 |
|
330 inline void CL2CapErtmDataReceiver::SetBufferSeq(TUint8 aTxSeq) |
|
331 { |
|
332 iBufferSeq = aTxSeq; |
|
333 } |
|
334 |
|
335 inline TUint8 CL2CapErtmDataReceiver::LastAckReqSeq() const |
|
336 { |
|
337 return iLastAckReqSeq; |
|
338 } |
|
339 |
|
340 inline TUint8 CL2CapErtmDataReceiver::TxSeqExpectedBySduQ() const |
|
341 { |
|
342 return iIncomingIFrameQ.TxSeqExpectedBySduQ(); |
|
343 } |
|
344 |
|
345 inline void CL2CapErtmDataReceiver::SetStateRecvL() |
|
346 { |
|
347 SetStateL(iStateRecv, NULL); |
|
348 } |
|
349 |
|
350 inline void CL2CapErtmDataReceiver::SetStateRejSentL() |
|
351 { |
|
352 SetStateL(iStateRejSent, NULL); |
|
353 } |
|
354 |
|
355 inline void CL2CapErtmDataReceiver::SetStateSRejSentL(RMBufChain& aUnexpectedIFrame) |
|
356 { |
|
357 SetStateL(iStateSRejSent, &aUnexpectedIFrame); |
|
358 } |
|
359 |
|
360 inline CL2CapEnhancedReTxController& CL2CapErtmDataReceiver::Controller() const |
|
361 { |
|
362 return iController; |
|
363 } |
|
364 |
|
365 inline TBool CL2CapErtmDataReceiver::IsTxSeqUnexpected(TUint8 aTxSeq) |
|
366 { |
|
367 // With-unexpected-TxSeq: The TxSeq of the received I-frame is within the |
|
368 // TxWindow of the L2CAP entity receiving the I-frame but has a TxSeq "greater" |
|
369 // than ExpectedTxSeq where "greater" means later in sequence than ExpectedTxSeq. |
|
370 return // in sender's window |
|
371 L2CapDataUtils::InWindow(aTxSeq, iBufferSeq, L2CapDataUtils::Mod64(iBufferSeq + iController.Config().PeerTXWindowSize() - 1)) && |
|
372 // ... and "greater" than the expected one |
|
373 !L2CapDataUtils::InWindow(aTxSeq, iBufferSeq, iExpectedTxSeq); |
|
374 } |
|
375 |
|
376 inline TBool CL2CapErtmDataReceiver::IsTxSeqInvalid(TUint8 aTxSeq) |
|
377 { |
|
378 // With-Invalid-TxSeq: The TxSeq of the received I-frame is not within the |
|
379 // TxWindow of the L2CAP entity receiving the frame. |
|
380 return !L2CapDataUtils::InWindow(aTxSeq, iBufferSeq, L2CapDataUtils::Mod64(iBufferSeq + iController.Config().PeerTXWindowSize() - 1)); |
|
381 } |
|
382 |
|
383 |
|
384 inline TBool RL2CapErtmOutgoingQueue::HaveFramesToTransmit() const |
|
385 { |
|
386 return !iOutgoingQ.IsEmpty(); |
|
387 } |
|
388 |
|
389 inline TBool RL2CapErtmOutgoingQueue::HavePendingRetransmitIFrames() const |
|
390 { |
|
391 return !iPendRetransmitIFrameQ.IsEmpty(); |
|
392 } |
|
393 |
|
394 |
|
395 template<typename FrameType> |
|
396 inline void CL2CapEnhancedReTxController::StampWithReqSeq(FrameType& aFrame) |
|
397 { |
|
398 iReceiver->StampWithReqSeq(aFrame); |
|
399 } |
|
400 |
|
401 inline RL2CapErtmOutgoingQueue& CL2CapEnhancedReTxController::OutgoingQ() |
|
402 { |
|
403 return iOutgoingQ; |
|
404 } |
|
405 |
|
406 inline RL2CapErtmTimerManager& CL2CapEnhancedReTxController::TimerMan() |
|
407 { |
|
408 return iTimerMan; |
|
409 } |
|
410 |
|
411 inline TBool CL2CapEnhancedReTxController::IsOutgoingDataPathClosing() |
|
412 { |
|
413 return iDeliverOutgoingDataAndSignalToSduQWhenDone; |
|
414 } |
|
415 |
|
416 inline void CL2CapEnhancedReTxController::SignalOutgoingDataDeliveredToSduQ() |
|
417 { |
|
418 iSDUQueue.DataControllerDeliveredOutgoingData(); |
|
419 } |
|
420 |
|
421 inline void CL2CapEnhancedReTxController::PassToSduQL(RMBufChain& aIFrame) |
|
422 { |
|
423 User::LeaveIfError(iSDUQueue.PutIFramePDU(aIFrame)); |
|
424 } |
|
425 |
|
426 inline TBool CL2CapEnhancedReTxController::IsPollOutstanding() const |
|
427 { |
|
428 return iTransmitter->InWaitAckState() || iReceiver->InWaitFState(); |
|
429 } |
|
430 |
|
431 inline TBool CL2CapEnhancedReTxController::IsFBitValid(TBool aFinal) |
|
432 { |
|
433 // With-Valid-F-bit: The F-bit of a received frame is valid if it is 0 or if it is 1 and |
|
434 // a frame sent with P=1 by the local L2CAP entity is unanswered (i.e. the local |
|
435 // L2CAP entity send a frame with P=1 and has not yet received a frame with F=1 |
|
436 // until receiving this one). If the Transmitter state machine is in the WAIT_ACK or |
|
437 // WAIT_F states then a frame sent with P=1 is unanswered. |
|
438 return (aFinal && IsPollOutstanding()) || !aFinal; |
|
439 } |
|
440 |
|
441 #endif /*L2CAPENHANCEDDATACONTROLLER_INL*/ |