From 0f1a83b62836a29730669d3adbf104e79363d465 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Sun, 19 Feb 2023 16:32:23 +0800 Subject: [PATCH] Main/TCP4 : ACK number in TCP RESET reply to SYN packet (#724) * 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 <110539926+amazonKamath@users.noreply.github.com> Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> --- .../FreeRTOS_TCP_Transmission_utest.c | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c index 759b4f3de0..72f83a5749 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c @@ -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 ) {