Skip to content

Commit e88ecd3

Browse files
htiboschHein TiboschAniruddhaKanhere
authored
Before sending a challenge ACK, check the sequence number more properly (#225)
* Before sending a challenge ACK, check the sequence number more properly * Make xSequenceLessThan and xSequenceGreaterThan public functions * Extended comments on two public functions. * Fix Spell check * Although no changes were made to MPS2_AN385, some formatting changes to that driver Co-authored-by: Hein Tibosch <[email protected]> Co-authored-by: Aniruddha Kanhere <[email protected]>
1 parent 65d7cfd commit e88ecd3

File tree

4 files changed

+60
-43
lines changed

4 files changed

+60
-43
lines changed

.github/lexicon.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ gmacsa
325325
gnw
326326
gpio
327327
gpl
328+
greaterthan
328329
grr
329330
gswutr
330331
hal
@@ -417,6 +418,7 @@ ldistance
417418
leds
418419
len
419420
lendofframe
421+
lessthan
420422
linkcurr
421423
linklayer
422424
linkmd

FreeRTOS_TCP_IP.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3583,9 +3583,9 @@
35833583
vTCPStateChange( pxSocket, eCLOSED );
35843584
}
35853585
/* Otherwise, check whether the packet is within the receive window. */
3586-
else if( ( ulSequenceNumber > pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber ) &&
3587-
( ulSequenceNumber < ( pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber +
3588-
pxSocket->u.xTCP.xTCPWindow.xSize.ulRxWindowLength ) ) )
3586+
else if( ( xSequenceGreaterThan( ulSequenceNumber, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber ) ) &&
3587+
( xSequenceLessThan( ulSequenceNumber, ( pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber +
3588+
pxSocket->u.xTCP.xTCPWindow.xSize.ulRxWindowLength ) ) ) )
35893589
{
35903590
/* Send a challenge ACK. */
35913591
( void ) prvTCPSendChallengeAck( pxNetworkBuffer );

FreeRTOS_TCP_WIN.c

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,6 @@
269269
#endif /* ipconfigUSE_TCP_WIN */
270270
/*-----------------------------------------------------------*/
271271

272-
#if ( ipconfigUSE_TCP_WIN == 1 )
273-
static portINLINE BaseType_t xSequenceLessThan( uint32_t a,
274-
uint32_t b );
275-
276272
/**
277273
* @brief Check if a < b.
278274
*
@@ -281,30 +277,25 @@
281277
*
282278
* @return pdTRUE when "( b - ( a + 1 ) ) < 0x80000000", else pdFALSE.
283279
*/
284-
static portINLINE BaseType_t xSequenceLessThan( uint32_t a,
285-
uint32_t b )
286-
{
287-
BaseType_t xResult;
288-
289-
/* Test if a < b */
290-
if( ( ( b - ( a + 1UL ) ) & 0x80000000UL ) == 0UL )
291-
{
292-
xResult = pdTRUE;
293-
}
294-
else
295-
{
296-
xResult = pdFALSE;
297-
}
280+
BaseType_t xSequenceLessThan( uint32_t a,
281+
uint32_t b )
282+
{
283+
BaseType_t xResult;
298284

299-
return xResult;
285+
/* Test if a < b */
286+
if( ( ( b - ( a + 1UL ) ) & 0x80000000UL ) == 0UL )
287+
{
288+
xResult = pdTRUE;
289+
}
290+
else
291+
{
292+
xResult = pdFALSE;
300293
}
301294

302-
#endif /* ipconfigUSE_TCP_WIN */
303-
/*-----------------------------------------------------------*/
295+
return xResult;
296+
}
304297

305-
#if ( ipconfigUSE_TCP_WIN == 1 )
306-
static portINLINE BaseType_t xSequenceGreaterThan( uint32_t a,
307-
uint32_t b );
298+
/*-----------------------------------------------------------*/
308299

309300
/**
310301
* @brief Check if a > b.
@@ -314,25 +305,24 @@
314305
*
315306
* @return pdTRUE when "( a - b ) < 0x80000000", else pdFALSE.
316307
*/
317-
static portINLINE BaseType_t xSequenceGreaterThan( uint32_t a,
318-
uint32_t b )
319-
{
320-
BaseType_t xResult;
321-
322-
/* Test if a > b */
323-
if( ( ( a - ( b + 1UL ) ) & 0x80000000UL ) == 0UL )
324-
{
325-
xResult = pdTRUE;
326-
}
327-
else
328-
{
329-
xResult = pdFALSE;
330-
}
308+
BaseType_t xSequenceGreaterThan( uint32_t a,
309+
uint32_t b )
310+
{
311+
BaseType_t xResult;
331312

332-
return xResult;
313+
/* Test if a > b */
314+
if( ( ( a - ( b + 1UL ) ) & 0x80000000UL ) == 0UL )
315+
{
316+
xResult = pdTRUE;
317+
}
318+
else
319+
{
320+
xResult = pdFALSE;
333321
}
334322

335-
#endif /* ipconfigUSE_TCP_WIN */
323+
return xResult;
324+
}
325+
336326

337327
/*-----------------------------------------------------------*/
338328
static portINLINE BaseType_t xSequenceGreaterThanOrEqual( uint32_t a,

include/FreeRTOS_TCP_WIN.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,31 @@
229229
uint32_t ulFirst,
230230
uint32_t ulLast );
231231

232+
/**
233+
* @brief Check if a > b, where a and b are rolling counters.
234+
*
235+
* @param[in] a: The value on the left-hand side.
236+
* @param[in] b: The value on the right-hand side.
237+
*
238+
* @return pdTRUE if a > b, otherwise pdFALSE.
239+
*
240+
* @note GreaterThan is calculated as "( a - ( b + 1U ) ) < 0x80000000".
241+
*/
242+
BaseType_t xSequenceGreaterThan( uint32_t a,
243+
uint32_t b );
244+
245+
/**
246+
* @brief Check if a < b, where a and b are rolling counters.
247+
*
248+
* @param[in] a: The value on the left-hand side.
249+
* @param[in] b: The value on the right-hand side.
250+
*
251+
* @return pdTRUE if a < b, otherwise pdFALSE.
252+
*
253+
* @note LessThan is implemented as "( b - ( a + 1 ) ) < 0x80000000".
254+
*/
255+
BaseType_t xSequenceLessThan( uint32_t a,
256+
uint32_t b );
232257

233258
#ifdef __cplusplus
234259
} /* extern "C" */

0 commit comments

Comments
 (0)