Skip to content

Commit

Permalink
Main/TCP4 : ACK number in TCP RESET reply to SYN packet (FreeRTOS#724)
Browse files Browse the repository at this point in the history
* Main/TCP4 : ACK number in TCP RESET reply to SYN packet

* Typo fix

* Add unit-test for coverage; Fix ntohl to htonl

* Fix unit-test

---------

Co-authored-by: Nikhil Kamath <[email protected]>
Co-authored-by: Aniruddha Kanhere <[email protected]>
  • Loading branch information
3 people authored and moninom1 committed Mar 15, 2023
1 parent f90e5e9 commit 9e71095
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,33 @@ void test_prvTCPSendSpecialPacketHelper( void )
TEST_ASSERT_EQUAL( 0x50, pxTCPPacket->xTCPHeader.ucTCPOffset );
}

/* test prvTCPSendSpecialPacketHelper function */
void test_prvTCPSendSpecialPacketHelper_flagSYN( void )
{
BaseType_t Return = pdTRUE;
const uint32_t ulSequenceNumber = 0xABC12300;

pxSocket = &xSocket;
pxNetworkBuffer = &xNetworkBuffer;
pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer;
TCPPacket_t * pxTCPPacket = ( ( const TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer );

pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_SYN;
pxTCPPacket->xTCPHeader.ucTCPOffset = 0;
pxTCPPacket->xTCPHeader.ulSequenceNumber = FreeRTOS_htonl( ulSequenceNumber );

usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 );
usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 );
eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit );
xNetworkInterfaceOutput_ExpectAnyArgsAndReturn( pdTRUE );

Return = prvTCPSendSpecialPacketHelper( pxNetworkBuffer, tcpTCP_FLAG_ACK );
TEST_ASSERT_EQUAL( pdFALSE, Return );
TEST_ASSERT_EQUAL( tcpTCP_FLAG_ACK, pxTCPPacket->xTCPHeader.ucTCPFlags );
TEST_ASSERT_EQUAL( 0x50, pxTCPPacket->xTCPHeader.ucTCPOffset );
TEST_ASSERT_EQUAL( ulSequenceNumber + 1, FreeRTOS_ntohl( pxTCPPacket->xTCPHeader.ulAckNr ) );
}

/* test prvTCPSendChallengeAck function */
void test_prvTCPSendChallengeAck( void )
{
Expand Down

0 comments on commit 9e71095

Please sign in to comment.