diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index 2f58d47294..8fd9672fa9 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -1064,7 +1064,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, } else { - ulAddressToLookup = *pulIPAddress; + ulAddressToLookup = 0U; } } } diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index e25c5de036..cfba8d04fb 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -49,6 +49,7 @@ #include "FreeRTOS_IP.h" #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" +#include "FreeRTOS_IP_Utils.h" #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" @@ -95,6 +96,7 @@ const char * prvTCPFlagMeaning( UBaseType_t xFlags ); #endif /* ipconfigHAS_DEBUG_PRINTF != 0 */ + static IPv46_Address_t xGetSourceAddrFromBuffer( const uint8_t * const pucEthernetBuffer ); /*-----------------------------------------------------------*/ @@ -628,6 +630,47 @@ } /*-----------------------------------------------------------*/ +/** + * @brief IP frame agnostic helper to obtain the source IP Address from a buffer. + * + * @param[in] pucEthernetBuffer The Ethernet buffer from which the source address will be retrieved. + * + * @return IPv46_Address_t struct containing the source IP address. + */ + static IPv46_Address_t xGetSourceAddrFromBuffer( const uint8_t * const pucEthernetBuffer ) + { + IPv46_Address_t xSourceAddr; + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + const EthernetHeader_t * pxHeader = ( ( const EthernetHeader_t * ) pucEthernetBuffer ); + + if( pxHeader->usFrameType == ( uint16_t ) ipIPv6_FRAME_TYPE ) + { + /* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */ + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + const IPHeader_IPv6_t * const pxIPHeader_IPv6 = ( ( const IPHeader_IPv6_t * ) &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); + xSourceAddr.xIs_IPv6 = pdTRUE; + ( void ) memcpy( xSourceAddr.xIPAddress.xIP_IPv6.ucBytes, pxIPHeader_IPv6->xSourceAddress.ucBytes, sizeof( IPv6_Address_t ) ); + } + else + { + /* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */ + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + const IPHeader_t * const pxIPHeader = ( ( const IPHeader_t * ) &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); + xSourceAddr.xIs_IPv6 = pdFALSE; + xSourceAddr.xIPAddress.ulIP_IPv4 = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress ); + } + + return xSourceAddr; + } + /** * @brief Process the received TCP packet. * @@ -648,36 +691,244 @@ */ BaseType_t xProcessReceivedTCPPacket( NetworkBufferDescriptor_t * pxDescriptor ) { + BaseType_t xResult = pdPASS; /* Function might modify the parameter. */ - const NetworkBufferDescriptor_t * pxNetworkBuffer = pxDescriptor; - BaseType_t xResult; + NetworkBufferDescriptor_t * pxNetworkBuffer; + size_t uxIPHeaderOffset; - configASSERT( pxNetworkBuffer != NULL ); - configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); + configASSERT( pxDescriptor != NULL ); + configASSERT( pxDescriptor->pucEthernetBuffer != NULL ); - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - switch( ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer )->usFrameType ) - { - #if ( ipconfigUSE_IPv4 != 0 ) - case ipIPv4_FRAME_TYPE: - xResult = xProcessReceivedTCPPacket_IPV4( pxDescriptor ); - break; - #endif /* ( ipconfigUSE_IPv4 != 0 ) */ + pxNetworkBuffer = pxDescriptor; + uxIPHeaderOffset = ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ); - #if ( ipconfigUSE_IPv6 != 0 ) - case ipIPv6_FRAME_TYPE: - xResult = xProcessReceivedTCPPacket_IPV6( pxDescriptor ); - break; - #endif /* ( ipconfigUSE_IPv6 != 0 ) */ + /* Check for a minimum packet size. */ + if( pxNetworkBuffer->xDataLength < ( uxIPHeaderOffset + ipSIZE_OF_TCP_HEADER ) ) + { + xResult = pdFAIL; + } + else + { + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + const TCPHeader_t * pxTCPHeader = ( ( const TCPHeader_t * ) + &( pxNetworkBuffer->pucEthernetBuffer[ uxIPHeaderOffset ] ) ); + + const uint16_t ucTCPFlags = pxTCPHeader->ucTCPFlags; + const uint16_t usLocalPort = FreeRTOS_htons( pxTCPHeader->usDestinationPort ); + const uint16_t usRemotePort = FreeRTOS_htons( pxTCPHeader->usSourcePort ); + const IPv46_Address_t xRemoteIP = xGetSourceAddrFromBuffer( pxNetworkBuffer->pucEthernetBuffer ); + + /* Find the destination socket, and if not found: return a socket listening to + * the destination PORT. */ + FreeRTOS_Socket_t * pxSocket = pxTCPSocketLookup( 0U, usLocalPort, xRemoteIP, usRemotePort ); + + if( ( pxSocket == NULL ) || ( prvTCPSocketIsActive( pxSocket->u.xTCP.eTCPState ) == pdFALSE ) ) + { + /* A TCP messages is received but either there is no socket with the + * given port number or the there is a socket, but it is in one of these + * non-active states: eCLOSED, eCLOSE_WAIT, eFIN_WAIT_2, eCLOSING, or + * eTIME_WAIT. */ + + FreeRTOS_debug_printf( ( "TCP: No active socket on port %d (%d)\n", usLocalPort, usRemotePort ) ); + + /* Send a RST to all packets that can not be handled. As a result + * the other party will get a ECONN error. There are two exceptions: + * 1) A packet that already has the RST flag set. + * 2) A packet that only has the ACK flag set. + * A packet with only the ACK flag set might be the last ACK in + * a three-way hand-shake that closes a connection. */ + if( ( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) != tcpTCP_FLAG_ACK ) && + ( ( ucTCPFlags & tcpTCP_FLAG_RST ) == 0U ) ) + { + ( void ) prvTCPSendReset( pxNetworkBuffer ); + } - default: - /* Shouldn't reach here */ + /* The packet can't be handled. */ xResult = pdFAIL; - break; + } + else + { + pxSocket->u.xTCP.ucRepCount = 0U; + + if( pxSocket->u.xTCP.eTCPState == eTCP_LISTEN ) + { + /* The matching socket is in a listening state. Test if the peer + * has set the SYN flag. */ + if( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) != tcpTCP_FLAG_SYN ) + { + /* What happens: maybe after a reboot, a client doesn't know the + * connection had gone. Send a RST in order to get a new connect + * request. */ + #if ( ipconfigHAS_DEBUG_PRINTF == 1 ) + { + FreeRTOS_debug_printf( ( "TCP: Server can't handle flags: %s from %u to port %u\n", + prvTCPFlagMeaning( ( UBaseType_t ) ucTCPFlags ), usRemotePort, usLocalPort ) ); + } + #endif /* ipconfigHAS_DEBUG_PRINTF */ + + if( ( ucTCPFlags & tcpTCP_FLAG_RST ) == 0U ) + { + ( void ) prvTCPSendReset( pxNetworkBuffer ); + } + + xResult = pdFAIL; + } + else + { + /* prvHandleListen() will either return a newly created socket + * (if bReuseSocket is false), otherwise it returns the current + * socket which will later get connected. */ + pxSocket = prvHandleListen( pxSocket, pxNetworkBuffer ); + + if( pxSocket == NULL ) + { + xResult = pdFAIL; + } + } + } /* if( pxSocket->u.xTCP.eTCPState == eTCP_LISTEN ). */ + else + { + /* This is not a socket in listening mode. Check for the RST + * flag. */ + if( ( ucTCPFlags & tcpTCP_FLAG_RST ) != 0U ) + { + FreeRTOS_debug_printf( ( "TCP: RST received from %u for %u\n", usRemotePort, usLocalPort ) ); + + /* Implement https://tools.ietf.org/html/rfc5961#section-3.2. */ + if( pxSocket->u.xTCP.eTCPState == eCONNECT_SYN ) + { + const uint32_t ulAckNumber = FreeRTOS_ntohl( pxTCPHeader->ulAckNr ); + + /* Per the above RFC, "In the SYN-SENT state ... the RST is + * acceptable if the ACK field acknowledges the SYN." */ + if( ulAckNumber == ( pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber + 1U ) ) + { + vTCPStateChange( pxSocket, eCLOSED ); + } + } + else + { + const uint32_t ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber ); + + /* Check whether the packet matches the next expected sequence number. */ + if( ulSequenceNumber == pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber ) + { + vTCPStateChange( pxSocket, eCLOSED ); + } + /* Otherwise, check whether the packet is within the receive window. */ + else if( ( xSequenceGreaterThan( ulSequenceNumber, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber ) != pdFALSE ) && + ( xSequenceLessThan( ulSequenceNumber, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber + + pxSocket->u.xTCP.xTCPWindow.xSize.ulRxWindowLength ) != pdFALSE ) ) + { + /* Send a challenge ACK. */ + ( void ) prvTCPSendChallengeAck( pxNetworkBuffer ); + } + else + { + /* Nothing. */ + } + } + + /* Otherwise, do nothing. In any case, the packet cannot be handled. */ + xResult = pdFAIL; + } + /* Check whether there is a pure SYN amongst the TCP flags while the connection is established. */ + else if( ( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) == tcpTCP_FLAG_SYN ) && ( pxSocket->u.xTCP.eTCPState >= eESTABLISHED ) ) + { + /* SYN flag while this socket is already connected. */ + FreeRTOS_debug_printf( ( "TCP: SYN unexpected from %u\n", usRemotePort ) ); + + /* The packet cannot be handled. */ + xResult = pdFAIL; + } + else + { + /* Update the copy of the TCP header only (skipping eth and IP + * headers). It might be used later on, whenever data must be sent + * to the peer. */ + const size_t uxOffset = ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ); + ( void ) memcpy( ( void * ) ( &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ uxOffset ] ) ), + ( const void * ) ( &( pxNetworkBuffer->pucEthernetBuffer[ uxOffset ] ) ), + ipSIZE_OF_TCP_HEADER ); + /* Clear flags that are set by the peer, and set the ACK flag. */ + pxSocket->u.xTCP.xPacket.u.ucLastPacket[ uxOffset + ipTCP_FLAGS_OFFSET ] = tcpTCP_FLAG_ACK; + } + } + } + + if( xResult != pdFAIL ) + { + uint16_t usWindow; + + /* pxSocket is not NULL when xResult != pdFAIL. */ + configASSERT( pxSocket != NULL ); /* LCOV_EXCL_LINE ,this branch will not be hit*/ + + /* Touch the alive timers because we received a message for this + * socket. */ + prvTCPTouchSocket( pxSocket ); + + /* Parse the TCP option(s), if present. */ + + /* _HT_ : if we're in the SYN phase, and peer does not send a MSS option, + * then we MUST assume an MSS size of 536 bytes for backward compatibility. */ + + /* When there are no TCP options, the TCP offset equals 20 bytes, which is stored as + * the number 5 (words) in the higher nibble of the TCP-offset byte. */ + if( ( pxTCPHeader->ucTCPOffset & tcpTCP_OFFSET_LENGTH_BITS ) > tcpTCP_OFFSET_STANDARD_LENGTH ) + { + xResult = prvCheckOptions( pxSocket, pxNetworkBuffer ); + } + + if( xResult != pdFAIL ) + { + usWindow = FreeRTOS_ntohs( pxTCPHeader->usWindow ); + pxSocket->u.xTCP.ulWindowSize = ( uint32_t ) usWindow; + #if ( ipconfigUSE_TCP_WIN == 1 ) + { + /* rfc1323 : The Window field in a SYN (i.e., a or ) + * segment itself is never scaled. */ + if( ( ucTCPFlags & ( uint8_t ) tcpTCP_FLAG_SYN ) == 0U ) + { + pxSocket->u.xTCP.ulWindowSize = + ( pxSocket->u.xTCP.ulWindowSize << pxSocket->u.xTCP.ucPeerWinScaleFactor ); + } + } + #endif /* ipconfigUSE_TCP_WIN */ + + /* In prvTCPHandleState() the incoming messages will be handled + * depending on the current state of the connection. */ + if( prvTCPHandleState( pxSocket, &pxNetworkBuffer ) > 0 ) + { + /* prvTCPHandleState() has sent a message, see if there are more to + * be transmitted. */ + #if ( ipconfigUSE_TCP_WIN == 1 ) + { + ( void ) prvTCPSendRepeated( pxSocket, &pxNetworkBuffer ); + } + #endif /* ipconfigUSE_TCP_WIN */ + } + + if( pxNetworkBuffer != NULL ) + { + /* We must check if the buffer is unequal to NULL, because the + * socket might keep a reference to it in case a delayed ACK must be + * sent. */ + vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); + #ifndef _lint + /* Clear pointers that are freed. */ + pxNetworkBuffer = NULL; + #endif + } + + /* And finally, calculate when this socket wants to be woken up. */ + ( void ) prvTCPNextTimeout( pxSocket ); + } + } } + /* pdPASS being returned means the buffer has been consumed. */ return xResult; } /*-----------------------------------------------------------*/ diff --git a/source/FreeRTOS_TCP_IP_IPv4.c b/source/FreeRTOS_TCP_IP_IPv4.c index ced279dcb7..9ccb729014 100644 --- a/source/FreeRTOS_TCP_IP_IPv4.c +++ b/source/FreeRTOS_TCP_IP_IPv4.c @@ -66,290 +66,6 @@ #if( ipconfigUSE_IPv4 != 0 ) && ( ipconfigUSE_TCP == 1 ) /* *INDENT-ON* */ -#if ( ipconfigHAS_DEBUG_PRINTF != 0 ) - -/* - * For logging and debugging: make a string showing the TCP flags. - */ - const char * prvTCPFlagMeaning( UBaseType_t xFlags ); -#endif /* ipconfigHAS_DEBUG_PRINTF != 0 */ - - -/*-----------------------------------------------------------*/ - - -/** - * @brief Process the received TCP packet. - * - * @param[in] pxDescriptor The descriptor in which the TCP packet is held. - * - * @return If the processing of the packet was successful, then pdPASS is returned - * or else pdFAIL. - * - * @note FreeRTOS_TCP_IP has only 2 public functions, this is the second one: - * xProcessReceivedTCPPacket() - * prvTCPHandleState() - * prvTCPPrepareSend() - * prvTCPReturnPacket() - * xNetworkInterfaceOutput() // Sends data to the NIC - * prvTCPSendRepeated() - * prvTCPReturnPacket() // Prepare for returning - * xNetworkInterfaceOutput() // Sends data to the NIC - */ -BaseType_t xProcessReceivedTCPPacket_IPV4( NetworkBufferDescriptor_t * pxDescriptor ) -{ - /* Function might modify the parameter. */ - NetworkBufferDescriptor_t * pxNetworkBuffer = pxDescriptor; - const ProtocolHeaders_t * pxProtocolHeaders; - FreeRTOS_Socket_t * pxSocket; - uint16_t ucTCPFlags; - uint32_t ulLocalIP; - uint16_t usLocalPort; - uint16_t usRemotePort; - IPv46_Address_t xRemoteIP; - uint32_t ulSequenceNumber; - uint32_t ulAckNumber; - BaseType_t xResult = pdPASS; - - const IPHeader_t * pxIPHeader; - - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - pxProtocolHeaders = ( ( ProtocolHeaders_t * ) - &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); - - ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags; - usLocalPort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usDestinationPort ); - usRemotePort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usSourcePort ); - ulSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); - ulAckNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulAckNr ); - - /* Check for a minimum packet size. */ - if( pxNetworkBuffer->xDataLength < ( ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) + ipSIZE_OF_TCP_HEADER ) ) - { - xResult = pdFAIL; - } - else - { - /* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */ - - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - pxIPHeader = ( ( const IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); - ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress ); - xRemoteIP.xIs_IPv6 = pdFALSE; - xRemoteIP.xIPAddress.ulIP_IPv4 = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress ); - - /* Find the destination socket, and if not found: return a socket listening to - * the destination PORT. */ - pxSocket = ( FreeRTOS_Socket_t * ) pxTCPSocketLookup( ulLocalIP, usLocalPort, xRemoteIP, usRemotePort ); - - if( ( pxSocket == NULL ) || ( prvTCPSocketIsActive( pxSocket->u.xTCP.eTCPState ) == pdFALSE ) ) - { - /* A TCP messages is received but either there is no socket with the - * given port number or the there is a socket, but it is in one of these - * non-active states: eCLOSED, eCLOSE_WAIT, eFIN_WAIT_2, eCLOSING, or - * eTIME_WAIT. */ - - FreeRTOS_debug_printf( ( "TCP: No active socket on port %d (%xip:%d)\n", usLocalPort, ( unsigned ) xRemoteIP.xIPAddress.ulIP_IPv4, usRemotePort ) ); - - /* Send a RST to all packets that can not be handled. As a result - * the other party will get a ECONN error. There are two exceptions: - * 1) A packet that already has the RST flag set. - * 2) A packet that only has the ACK flag set. - * A packet with only the ACK flag set might be the last ACK in - * a three-way hand-shake that closes a connection. */ - if( ( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) != tcpTCP_FLAG_ACK ) && - ( ( ucTCPFlags & tcpTCP_FLAG_RST ) == 0U ) ) - { - ( void ) prvTCPSendReset( pxNetworkBuffer ); - } - - /* The packet can't be handled. */ - xResult = pdFAIL; - } - else - { - pxSocket->u.xTCP.ucRepCount = 0U; - - if( pxSocket->u.xTCP.eTCPState == eTCP_LISTEN ) - { - /* The matching socket is in a listening state. Test if the peer - * has set the SYN flag. */ - if( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) != tcpTCP_FLAG_SYN ) - { - /* What happens: maybe after a reboot, a client doesn't know the - * connection had gone. Send a RST in order to get a new connect - * request. */ - #if ( ipconfigHAS_DEBUG_PRINTF == 1 ) - { - FreeRTOS_debug_printf( ( "TCP: Server can't handle flags: %s from %xip:%u to port %u\n", - prvTCPFlagMeaning( ( UBaseType_t ) ucTCPFlags ), ( unsigned ) xRemoteIP.xIPAddress.ulIP_IPv4, usRemotePort, usLocalPort ) ); - } - #endif /* ipconfigHAS_DEBUG_PRINTF */ - - if( ( ucTCPFlags & tcpTCP_FLAG_RST ) == 0U ) - { - ( void ) prvTCPSendReset( pxNetworkBuffer ); - } - - xResult = pdFAIL; - } - else - { - /* prvHandleListen() will either return a newly created socket - * (if bReuseSocket is false), otherwise it returns the current - * socket which will later get connected. */ - pxSocket = prvHandleListen( pxSocket, pxNetworkBuffer ); - - if( pxSocket == NULL ) - { - xResult = pdFAIL; - } - } - } /* if( pxSocket->u.xTCP.eTCPState == eTCP_LISTEN ). */ - else - { - /* This is not a socket in listening mode. Check for the RST - * flag. */ - if( ( ucTCPFlags & tcpTCP_FLAG_RST ) != 0U ) - { - FreeRTOS_debug_printf( ( "TCP: RST received from %xip:%u for %u\n", ( unsigned ) xRemoteIP.xIPAddress.ulIP_IPv4, usRemotePort, usLocalPort ) ); - - /* Implement https://tools.ietf.org/html/rfc5961#section-3.2. */ - if( pxSocket->u.xTCP.eTCPState == eCONNECT_SYN ) - { - /* Per the above RFC, "In the SYN-SENT state ... the RST is - * acceptable if the ACK field acknowledges the SYN." */ - if( ulAckNumber == ( pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber + 1U ) ) - { - vTCPStateChange( pxSocket, eCLOSED ); - } - } - else - { - /* Check whether the packet matches the next expected sequence number. */ - if( ulSequenceNumber == pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber ) - { - vTCPStateChange( pxSocket, eCLOSED ); - } - /* Otherwise, check whether the packet is within the receive window. */ - else if( ( xSequenceGreaterThan( ulSequenceNumber, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber ) != pdFALSE ) && - ( xSequenceLessThan( ulSequenceNumber, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber + - pxSocket->u.xTCP.xTCPWindow.xSize.ulRxWindowLength ) != pdFALSE ) ) - { - /* Send a challenge ACK. */ - ( void ) prvTCPSendChallengeAck( pxNetworkBuffer ); - } - else - { - /* Nothing. */ - } - } - - /* Otherwise, do nothing. In any case, the packet cannot be handled. */ - xResult = pdFAIL; - } - /* Check whether there is a pure SYN amongst the TCP flags while the connection is established. */ - else if( ( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) == tcpTCP_FLAG_SYN ) && ( pxSocket->u.xTCP.eTCPState >= eESTABLISHED ) ) - { - /* SYN flag while this socket is already connected. */ - FreeRTOS_debug_printf( ( "TCP: SYN unexpected from %xip:%u\n", ( unsigned ) xRemoteIP.xIPAddress.ulIP_IPv4, usRemotePort ) ); - - /* The packet cannot be handled. */ - xResult = pdFAIL; - } - else - { - /* Update the copy of the TCP header only (skipping eth and IP - * headers). It might be used later on, whenever data must be sent - * to the peer. */ - const size_t uxOffset = ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ); - ( void ) memcpy( ( void * ) ( &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ uxOffset ] ) ), - ( const void * ) ( &( pxNetworkBuffer->pucEthernetBuffer[ uxOffset ] ) ), - ipSIZE_OF_TCP_HEADER ); - /* Clear flags that are set by the peer, and set the ACK flag. */ - pxSocket->u.xTCP.xPacket.u.ucLastPacket[ uxOffset + ipTCP_FLAGS_OFFSET ] = tcpTCP_FLAG_ACK; - } - } - } - - if( xResult != pdFAIL ) - { - uint16_t usWindow; - - /* pxSocket is not NULL when xResult != pdFAIL. */ - configASSERT( pxSocket != NULL ); /* LCOV_EXCL_LINE ,this branch will not be hit*/ - - /* Touch the alive timers because we received a message for this - * socket. */ - prvTCPTouchSocket( pxSocket ); - - /* Parse the TCP option(s), if present. */ - - /* _HT_ : if we're in the SYN phase, and peer does not send a MSS option, - * then we MUST assume an MSS size of 536 bytes for backward compatibility. */ - - /* When there are no TCP options, the TCP offset equals 20 bytes, which is stored as - * the number 5 (words) in the higher nibble of the TCP-offset byte. */ - if( ( pxProtocolHeaders->xTCPHeader.ucTCPOffset & tcpTCP_OFFSET_LENGTH_BITS ) > tcpTCP_OFFSET_STANDARD_LENGTH ) - { - xResult = prvCheckOptions( pxSocket, pxNetworkBuffer ); - } - - if( xResult != pdFAIL ) - { - usWindow = FreeRTOS_ntohs( pxProtocolHeaders->xTCPHeader.usWindow ); - pxSocket->u.xTCP.ulWindowSize = ( uint32_t ) usWindow; - #if ( ipconfigUSE_TCP_WIN == 1 ) - { - /* rfc1323 : The Window field in a SYN (i.e., a or ) - * segment itself is never scaled. */ - if( ( ucTCPFlags & ( uint8_t ) tcpTCP_FLAG_SYN ) == 0U ) - { - pxSocket->u.xTCP.ulWindowSize = - ( pxSocket->u.xTCP.ulWindowSize << pxSocket->u.xTCP.ucPeerWinScaleFactor ); - } - } - #endif /* ipconfigUSE_TCP_WIN */ - - /* In prvTCPHandleState() the incoming messages will be handled - * depending on the current state of the connection. */ - if( prvTCPHandleState( pxSocket, &pxNetworkBuffer ) > 0 ) - { - /* prvTCPHandleState() has sent a message, see if there are more to - * be transmitted. */ - #if ( ipconfigUSE_TCP_WIN == 1 ) - { - ( void ) prvTCPSendRepeated( pxSocket, &pxNetworkBuffer ); - } - #endif /* ipconfigUSE_TCP_WIN */ - } - - if( pxNetworkBuffer != NULL ) - { - /* We must check if the buffer is unequal to NULL, because the - * socket might keep a reference to it in case a delayed ACK must be - * sent. */ - vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); - #ifndef _lint - /* Clear pointers that are freed. */ - pxNetworkBuffer = NULL; - #endif - } - - /* And finally, calculate when this socket wants to be woken up. */ - ( void ) prvTCPNextTimeout( pxSocket ); - } - } - } - - /* pdPASS being returned means the buffer has been consumed. */ - return xResult; -} -/*-----------------------------------------------------------*/ /* *INDENT-OFF* */ #endif /* ( ipconfigUSE_IPv4 != 0 ) && ( ipconfigUSE_TCP == 1 ) */ diff --git a/source/FreeRTOS_TCP_IP_IPv6.c b/source/FreeRTOS_TCP_IP_IPv6.c index 386b89e63f..f9b2dd75f7 100644 --- a/source/FreeRTOS_TCP_IP_IPv6.c +++ b/source/FreeRTOS_TCP_IP_IPv6.c @@ -66,291 +66,6 @@ #if( ipconfigUSE_IPv6 != 0 ) && ( ipconfigUSE_TCP == 1 ) /* *INDENT-ON* */ -#if ( ipconfigHAS_DEBUG_PRINTF != 0 ) - -/* - * For logging and debugging: make a string showing the TCP flags. - */ - const char * prvTCPFlagMeaning( UBaseType_t xFlags ); -#endif /* ipconfigHAS_DEBUG_PRINTF != 0 */ - - -/*-----------------------------------------------------------*/ - - -/** - * @brief Process the received TCP packet. - * - * @param[in] pxDescriptor The descriptor in which the TCP packet is held. - * - * @return If the processing of the packet was successful, then pdPASS is returned - * or else pdFAIL. - * - * @note FreeRTOS_TCP_IP has only 2 public functions, this is the second one: - * xProcessReceivedTCPPacket() - * prvTCPHandleState() - * prvTCPPrepareSend() - * prvTCPReturnPacket() - * xNetworkInterfaceOutput() // Sends data to the NIC - * prvTCPSendRepeated() - * prvTCPReturnPacket() // Prepare for returning - * xNetworkInterfaceOutput() // Sends data to the NIC - */ -BaseType_t xProcessReceivedTCPPacket_IPV6( NetworkBufferDescriptor_t * pxDescriptor ) -{ - /* Function might modify the parameter. */ - NetworkBufferDescriptor_t * pxNetworkBuffer = pxDescriptor; - const ProtocolHeaders_t * pxProtocolHeaders; - FreeRTOS_Socket_t * pxSocket; - uint16_t ucTCPFlags; - uint16_t usLocalPort; - uint16_t usRemotePort; - IPv46_Address_t xRemoteIP; - uint32_t ulSequenceNumber; - uint32_t ulAckNumber; - BaseType_t xResult = pdPASS; - - configASSERT( pxNetworkBuffer != NULL ); - configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); - - /* Map the buffer onto a ProtocolHeaders_t struct for easy access to the fields. */ - - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) - &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); - - ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags; - usLocalPort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usDestinationPort ); - usRemotePort = FreeRTOS_htons( pxProtocolHeaders->xTCPHeader.usSourcePort ); - ulSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); - ulAckNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulAckNr ); - - /* Check for a minimum packet size. */ - if( pxNetworkBuffer->xDataLength < ( ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) + ipSIZE_OF_TCP_HEADER ) ) - { - xResult = pdFAIL; - } - else - { - /* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */ - - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - const IPHeader_IPv6_t * pxIPHeader_IPv6 = ( ( IPHeader_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); - ( void ) memcpy( xRemoteIP.xIPAddress.xIP_IPv6.ucBytes, pxIPHeader_IPv6->xSourceAddress.ucBytes, sizeof( IPv6_Address_t ) ); - xRemoteIP.xIs_IPv6 = pdTRUE; - - /* Find the destination socket, and if not found: return a socket listing to - * the destination PORT. */ - pxSocket = ( FreeRTOS_Socket_t * ) pxTCPSocketLookup( 0U, usLocalPort, xRemoteIP, usRemotePort ); - - if( ( pxSocket == NULL ) || ( prvTCPSocketIsActive( pxSocket->u.xTCP.eTCPState ) == pdFALSE ) ) - { - /* A TCP messages is received but either there is no socket with the - * given port number or the there is a socket, but it is in one of these - * non-active states: eCLOSED, eCLOSE_WAIT, eFIN_WAIT_2, eCLOSING, or - * eTIME_WAIT. */ - - FreeRTOS_debug_printf( ( "TCP: No active socket on port %d (%xip:%d)\n", usLocalPort, ( unsigned ) xRemoteIP.xIPAddress.ulIP_IPv4, usRemotePort ) ); - - /* Send a RST to all packets that can not be handled. As a result - * the other party will get a ECONN error. There are two exceptions: - * 1) A packet that already has the RST flag set. - * 2) A packet that only has the ACK flag set. - * A packet with only the ACK flag set might be the last ACK in - * a three-way hand-shake that closes a connection. */ - if( ( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) != tcpTCP_FLAG_ACK ) && - ( ( ucTCPFlags & tcpTCP_FLAG_RST ) == 0U ) ) - { - ( void ) prvTCPSendReset( pxNetworkBuffer ); - } - - /* The packet can't be handled. */ - xResult = pdFAIL; - } - else - { - pxSocket->u.xTCP.ucRepCount = 0U; - - if( pxSocket->u.xTCP.eTCPState == eTCP_LISTEN ) - { - /* The matching socket is in a listening state. Test if the peer - * has set the SYN flag. */ - if( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) != tcpTCP_FLAG_SYN ) - { - /* What happens: maybe after a reboot, a client doesn't know the - * connection had gone. Send a RST in order to get a new connect - * request. */ - #if ( ipconfigHAS_DEBUG_PRINTF == 1 ) - { - FreeRTOS_debug_printf( ( "TCP: Server can't handle flags: %s from %xip:%u to port %u\n", - prvTCPFlagMeaning( ( UBaseType_t ) ucTCPFlags ), ( unsigned ) xRemoteIP.xIPAddress.ulIP_IPv4, usRemotePort, usLocalPort ) ); - } - #endif /* ipconfigHAS_DEBUG_PRINTF */ - - if( ( ucTCPFlags & tcpTCP_FLAG_RST ) == 0U ) - { - ( void ) prvTCPSendReset( pxNetworkBuffer ); - } - - xResult = pdFAIL; - } - else - { - /* prvHandleListen() will either return a newly created socket - * (if bReuseSocket is false), otherwise it returns the current - * socket which will later get connected. */ - pxSocket = prvHandleListen( pxSocket, pxNetworkBuffer ); - - if( pxSocket == NULL ) - { - xResult = pdFAIL; - } - } - } /* if( pxSocket->u.xTCP.eTCPState == eTCP_LISTEN ). */ - else - { - /* This is not a socket in listening mode. Check for the RST - * flag. */ - if( ( ucTCPFlags & tcpTCP_FLAG_RST ) != 0U ) - { - FreeRTOS_debug_printf( ( "TCP: RST received from %xip:%u for %u\n", ( unsigned ) xRemoteIP.xIPAddress.ulIP_IPv4, usRemotePort, usLocalPort ) ); - - /* Implement https://tools.ietf.org/html/rfc5961#section-3.2. */ - if( pxSocket->u.xTCP.eTCPState == eCONNECT_SYN ) - { - /* Per the above RFC, "In the SYN-SENT state ... the RST is - * acceptable if the ACK field acknowledges the SYN." */ - if( ulAckNumber == ( pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber + 1U ) ) - { - vTCPStateChange( pxSocket, eCLOSED ); - } - } - else - { - /* Check whether the packet matches the next expected sequence number. */ - if( ulSequenceNumber == pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber ) - { - vTCPStateChange( pxSocket, eCLOSED ); - } - /* Otherwise, check whether the packet is within the receive window. */ - else if( ( xSequenceGreaterThan( ulSequenceNumber, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber ) != pdFALSE ) && - ( xSequenceLessThan( ulSequenceNumber, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber + - pxSocket->u.xTCP.xTCPWindow.xSize.ulRxWindowLength ) != pdFALSE ) ) - { - /* Send a challenge ACK. */ - ( void ) prvTCPSendChallengeAck( pxNetworkBuffer ); - } - else - { - /* Nothing. */ - } - } - - /* Otherwise, do nothing. In any case, the packet cannot be handled. */ - xResult = pdFAIL; - } - /* Check whether there is a pure SYN amongst the TCP flags while the connection is established. */ - else if( ( ( ucTCPFlags & tcpTCP_FLAG_CTRL ) == tcpTCP_FLAG_SYN ) && ( pxSocket->u.xTCP.eTCPState >= eESTABLISHED ) ) - { - /* SYN flag while this socket is already connected. */ - FreeRTOS_debug_printf( ( "TCP: SYN unexpected from %xip:%u\n", ( unsigned ) xRemoteIP.xIPAddress.ulIP_IPv4, usRemotePort ) ); - - /* The packet cannot be handled. */ - xResult = pdFAIL; - } - else - { - /* Update the copy of the TCP header only (skipping eth and IP - * headers). It might be used later on, whenever data must be sent - * to the peer. */ - const size_t uxOffset = ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ); - ( void ) memcpy( ( void * ) ( &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ uxOffset ] ) ), - ( const void * ) ( &( pxNetworkBuffer->pucEthernetBuffer[ uxOffset ] ) ), - ipSIZE_OF_TCP_HEADER ); - /* Clear flags that are set by the peer, and set the ACK flag. */ - pxSocket->u.xTCP.xPacket.u.ucLastPacket[ uxOffset + ipTCP_FLAGS_OFFSET ] = tcpTCP_FLAG_ACK; - } - } - } - - if( xResult != pdFAIL ) - { - uint16_t usWindow; - - /* pxSocket is not NULL when xResult != pdFAIL. */ - configASSERT( pxSocket != NULL ); /* LCOV_EXCL_LINE ,this branch will not be hit*/ - - /* Touch the alive timers because we received a message for this - * socket. */ - prvTCPTouchSocket( pxSocket ); - - /* Parse the TCP option(s), if present. */ - - /* _HT_ : if we're in the SYN phase, and peer does not send a MSS option, - * then we MUST assume an MSS size of 536 bytes for backward compatibility. */ - - /* When there are no TCP options, the TCP offset equals 20 bytes, which is stored as - * the number 5 (words) in the higher nibble of the TCP-offset byte. */ - if( ( pxProtocolHeaders->xTCPHeader.ucTCPOffset & tcpTCP_OFFSET_LENGTH_BITS ) > tcpTCP_OFFSET_STANDARD_LENGTH ) - { - xResult = prvCheckOptions( pxSocket, pxNetworkBuffer ); - } - - if( xResult != pdFAIL ) - { - usWindow = FreeRTOS_ntohs( pxProtocolHeaders->xTCPHeader.usWindow ); - pxSocket->u.xTCP.ulWindowSize = ( uint32_t ) usWindow; - #if ( ipconfigUSE_TCP_WIN == 1 ) - { - /* rfc1323 : The Window field in a SYN (i.e., a or ) - * segment itself is never scaled. */ - if( ( ucTCPFlags & ( uint8_t ) tcpTCP_FLAG_SYN ) == 0U ) - { - pxSocket->u.xTCP.ulWindowSize = - ( pxSocket->u.xTCP.ulWindowSize << pxSocket->u.xTCP.ucPeerWinScaleFactor ); - } - } - #endif /* ipconfigUSE_TCP_WIN */ - - /* In prvTCPHandleState() the incoming messages will be handled - * depending on the current state of the connection. */ - if( prvTCPHandleState( pxSocket, &pxNetworkBuffer ) > 0 ) - { - /* prvTCPHandleState() has sent a message, see if there are more to - * be transmitted. */ - #if ( ipconfigUSE_TCP_WIN == 1 ) - { - ( void ) prvTCPSendRepeated( pxSocket, &pxNetworkBuffer ); - } - #endif /* ipconfigUSE_TCP_WIN */ - } - - if( pxNetworkBuffer != NULL ) - { - /* We must check if the buffer is unequal to NULL, because the - * socket might keep a reference to it in case a delayed ACK must be - * sent. */ - vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); - #ifndef _lint - /* Clear pointers that are freed. */ - pxNetworkBuffer = NULL; - #endif - } - - /* And finally, calculate when this socket wants to be woken up. */ - ( void ) prvTCPNextTimeout( pxSocket ); - } - } - } - - /* pdPASS being returned means the buffer has been consumed. */ - return xResult; -} -/*-----------------------------------------------------------*/ /* Provide access to private members for testing. */ #ifdef FREERTOS_ENABLE_UNIT_TESTS diff --git a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/ProcessReceivedTCPPacket_harness.c b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/ProcessReceivedTCPPacket_harness.c index cf5a9ea362..00f6e8014c 100644 --- a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/ProcessReceivedTCPPacket_harness.c +++ b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/ProcessReceivedTCPPacket_harness.c @@ -82,6 +82,20 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS return pxNetworkBuffer; } +/* Abstraction of uxIPHeaderSizePacket. Because we're testing IPv4 in this test case, the network buffer is + * guaranteed to be IPv4 packet. Thus returns IPv4 header size here directly. */ +size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + return ipSIZE_OF_IPv4_HEADER; +} + +/* Abstraction of uxIPHeaderSizePacket. Because we're testing IPv4 in this test case, all socket handlers returned + * by functions are for IPv4. Thus returns IPv4 header size here directly. */ +size_t uxIPHeaderSizeSocket( const FreeRTOS_Socket_t * pxSocket ) +{ + return ipSIZE_OF_IPv4_HEADER; +} + void harness() { NetworkBufferDescriptor_t * pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); diff --git a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c index 11f75f5c7e..5d829bee58 100644 --- a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c +++ b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c @@ -2270,8 +2270,7 @@ void test_eARPGetCacheEntry_GatewayAddressZero( void ) FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn( NULL ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL_MESSAGE( eARPCacheMiss, eResult, "Test 9" ); - TEST_ASSERT_NOT_EQUAL( pxEndPoint, &xEndPoint ); + TEST_ASSERT_EQUAL_MESSAGE( eCantSendPacket, eResult, "Test 9" ); /* =================================================== */ } diff --git a/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c b/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c index ac9c38f09c..55d4c112b1 100644 --- a/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c +++ b/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c @@ -1649,11 +1649,14 @@ void test_xProcessReceivedTCPPacket_IPv6_FrameType( void ) xEthHeader.usFrameType = ipIPv6_FRAME_TYPE; - pxNetworkBuffer->xDataLength = 40; + pxNetworkBuffer->xDataLength = 100; + + uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); + pxTCPSocketLookup_ExpectAnyArgsAndReturn( NULL ); Return = xProcessReceivedTCPPacket( pxNetworkBuffer ); - TEST_ASSERT_EQUAL( pdTRUE, Return ); + TEST_ASSERT_EQUAL( pdFAIL, Return ); } /** @@ -1672,6 +1675,8 @@ void test_xProcessReceivedTCPPacket_Incorrect_FrameType( void ) pxNetworkBuffer->xDataLength = 40; + uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); + Return = xProcessReceivedTCPPacket( pxNetworkBuffer ); TEST_ASSERT_EQUAL( pdFALSE, Return ); @@ -1690,7 +1695,6 @@ void test_xProcessReceivedTCPPacket_Minimal_Data_Length( void ) pxNetworkBuffer->xDataLength = 40; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); Return = xProcessReceivedTCPPacket( pxNetworkBuffer ); @@ -1712,7 +1716,6 @@ void test_xProcessReceivedTCPPacket_No_Socket( void ) pxNetworkBuffer->xDataLength = 100; pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_ACK; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( NULL ); @@ -1737,7 +1740,6 @@ void test_xProcessReceivedTCPPacket_No_Active_Socket( void ) pxSocket->u.xTCP.eTCPState = eCLOSE_WAIT; pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_RST; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdFALSE ); @@ -1763,7 +1765,6 @@ void test_xProcessReceivedTCPPacket_No_Active_Socket_Send_Reset( void ) pxSocket->u.xTCP.eTCPState = eCLOSE_WAIT; pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_ACK | tcpTCP_FLAG_FIN; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdFALSE ); @@ -1790,7 +1791,6 @@ void test_xProcessReceivedTCPPacket_Listen_State_Not_Syn_No_Rst( void ) pxSocket->u.xTCP.eTCPState = eTCP_LISTEN; pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_RST; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -1816,7 +1816,6 @@ void test_xProcessReceivedTCPPacket_Listen_State_Not_Syn_Rst( void ) pxSocket->u.xTCP.eTCPState = eTCP_LISTEN; pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_ACK; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -1843,7 +1842,6 @@ void test_xProcessReceivedTCPPacket_Listen_State_Syn_Null_Socket( void ) pxSocket->u.xTCP.eTCPState = eTCP_LISTEN; pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_SYN; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -1872,7 +1870,6 @@ void test_xProcessReceivedTCPPacket_Listen_State_Syn_NoOp_Sent_Something( void ) pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_SYN; pxProtocolHeaders->xTCPHeader.ucTCPOffset = 0x50; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -1906,7 +1903,6 @@ void test_xProcessReceivedTCPPacket_Listen_State_Syn_NoOp_Sent_None( void ) pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_SYN; pxProtocolHeaders->xTCPHeader.ucTCPOffset = 0x50; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -1940,7 +1936,6 @@ void test_xProcessReceivedTCPPacket_Listen_State_Syn_With_Op_Check_Failed( void pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_SYN; pxProtocolHeaders->xTCPHeader.ucTCPOffset = 0x80; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -1974,7 +1969,6 @@ void test_xProcessReceivedTCPPacket_Listen_State_Syn_With_Op_Sent_Something_Buff pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_SYN; pxProtocolHeaders->xTCPHeader.ucTCPOffset = 0x80; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -2007,7 +2001,6 @@ void test_xProcessReceivedTCPPacket_Establish_State_Syn( void ) pxSocket->u.xTCP.eTCPState = eESTABLISHED; pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_SYN; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -2035,7 +2028,6 @@ void test_xProcessReceivedTCPPacket_ConnectSyn_State_Rst_Change_State( void ) pxProtocolHeaders->xTCPHeader.ulAckNr = FreeRTOS_htonl( 1 ); pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_RST; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -2071,7 +2063,6 @@ void test_xProcessReceivedTCPPacket_ConnectSyn_State_Rst_SeqNo_Wrong( void ) pxProtocolHeaders->xTCPHeader.ulAckNr = FreeRTOS_htonl( 100 ); pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_RST; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -2101,7 +2092,6 @@ void test_xProcessReceivedTCPPacket_SynReceived_State_Rst( void ) pxProtocolHeaders->xTCPHeader.ulAckNr = FreeRTOS_htonl( 100 ); pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_SYN; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); @@ -2137,7 +2127,6 @@ void test_xProcessReceivedTCPPacket_Establish_State_Rst_Change_State( void ) pxProtocolHeaders->xTCPHeader.ulAckNr = FreeRTOS_htonl( 100 ); pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_RST; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -2175,7 +2164,6 @@ void test_xProcessReceivedTCPPacket_Establish_State_Rst_Seq_InRange( void ) pxProtocolHeaders->xTCPHeader.ulAckNr = FreeRTOS_htonl( 100 ); pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_RST; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -2207,7 +2195,6 @@ void test_xProcessReceivedTCPPacket_Establish_State_Rst_Seq_OutRange1( void ) pxProtocolHeaders->xTCPHeader.ulAckNr = FreeRTOS_htonl( 100 ); pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_RST; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -2238,7 +2225,6 @@ void test_xProcessReceivedTCPPacket_Establish_State_Rst_Seq_OutRange2( void ) pxProtocolHeaders->xTCPHeader.ulAckNr = FreeRTOS_htonl( 100 ); pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_RST; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE ); @@ -2270,7 +2256,6 @@ void test_xProcessReceivedTCPPacket_Establish_State_Ack( void ) pxProtocolHeaders->xTCPHeader.ulAckNr = FreeRTOS_htonl( 100 ); pxProtocolHeaders->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_ACK; - uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( pxSocket ); prvTCPSocketIsActive_ExpectAnyArgsAndReturn( pdTRUE );