diff --git a/source/FreeRTOS_DHCP.c b/source/FreeRTOS_DHCP.c index 0940a0dde..2fdcd0976 100644 --- a/source/FreeRTOS_DHCP.c +++ b/source/FreeRTOS_DHCP.c @@ -689,8 +689,8 @@ ( pxDHCPMessage->ucOpcode != ( uint8_t ) dhcpREPLY_OPCODE ) || ( pxDHCPMessage->ucAddressType != ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET ) || ( pxDHCPMessage->ucAddressLength != ( uint8_t ) dhcpETHERNET_ADDRESS_LENGTH ) || - ( ( FreeRTOS_ntohl( pxDHCPMessage->ulYourIPAddress_yiaddr ) & 0xFF ) == 0xFF ) || - ( ( ( pxDHCPMessage->ulYourIPAddress_yiaddr & 0x7F ) ^ 0x7F ) == 0x00 ) ) + ( ( FreeRTOS_ntohl( pxDHCPMessage->ulYourIPAddress_yiaddr ) & 0xFFU ) == 0xFF ) || + ( ( ( pxDHCPMessage->ulYourIPAddress_yiaddr & 0x7FU ) ^ 0x7FU ) == 0x00 ) ) { /* Invalid cookie OR * Unexpected opcode OR diff --git a/source/FreeRTOS_DNS_Parser.c b/source/FreeRTOS_DNS_Parser.c index 067e0e5f4..f88126de1 100644 --- a/source/FreeRTOS_DNS_Parser.c +++ b/source/FreeRTOS_DNS_Parser.c @@ -549,6 +549,8 @@ uint32_t ulIPAddress = 0U; uint32_t ulReturnIPAddress = 0U; uint16_t usDataLength; + uint8_t * pucBuffer = pucByte; + size_t uxRxSourceByteRemaining = uxSourceBytesRemaining; for( x = 0U; x < pxDNSMessageHeader->usAnswers; x++ ) { @@ -560,8 +562,8 @@ break; } - uxResult = DNS_SkipNameField( pucByte, - uxSourceBytesRemaining ); + uxResult = DNS_SkipNameField( pucBuffer, + uxRxSourceByteRemaining ); /* Check for a malformed response. */ if( uxResult == 0U ) @@ -571,22 +573,22 @@ } *uxBytesRead += uxResult; - pucByte = &( pucByte[ uxResult ] ); - uxSourceBytesRemaining -= uxResult; + pucBuffer = &( pucBuffer[ uxResult ] ); + uxRxSourceByteRemaining -= uxResult; /* Is there enough data for an IPv4 A record answer and, if so, * is this an A record? */ - if( uxSourceBytesRemaining < sizeof( uint16_t ) ) + if( uxRxSourceByteRemaining < sizeof( uint16_t ) ) { xReturn = pdFALSE; break; } - usType = usChar2u16( pucByte ); + usType = usChar2u16( pucBuffer ); if( usType == ( uint16_t ) dnsTYPE_A_HOST ) { - if( uxSourceBytesRemaining >= ( sizeof( DNSAnswerRecord_t ) + uxAddressLength ) ) + if( uxRxSourceByteRemaining >= ( sizeof( DNSAnswerRecord_t ) + uxAddressLength ) ) { xDoAccept = pdTRUE; } @@ -605,9 +607,9 @@ { /* This is the required record type and is of sufficient size. */ - /* Mapping pucByte to a DNSAnswerRecord allows easy access of the + /* Mapping pucBuffer to a DNSAnswerRecord allows easy access of the * fields of the structure. */ - pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pucByte ); + pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pucBuffer ); /* Sanity check the data length of an IPv4 answer. */ if( FreeRTOS_ntohs( pxDNSAnswerRecord->usDataLength ) == @@ -621,7 +623,7 @@ * compliant with MISRA Rule 21.15. These should be * optimized away. */ - pvCopySource = &pucByte[ sizeof( DNSAnswerRecord_t ) ]; + pvCopySource = &pucBuffer[ sizeof( DNSAnswerRecord_t ) ]; pvCopyDest = &ulIPAddress; ( void ) memcpy( pvCopyDest, pvCopySource, uxAddressLength ); @@ -673,27 +675,27 @@ } } - pucByte = &( pucByte[ sizeof( DNSAnswerRecord_t ) + uxAddressLength ] ); - uxSourceBytesRemaining -= ( sizeof( DNSAnswerRecord_t ) + uxAddressLength ); + pucBuffer = &( pucBuffer[ sizeof( DNSAnswerRecord_t ) + uxAddressLength ] ); + uxRxSourceByteRemaining -= ( sizeof( DNSAnswerRecord_t ) + uxAddressLength ); } - else if( uxSourceBytesRemaining >= sizeof( DNSAnswerRecord_t ) ) + else if( uxRxSourceByteRemaining >= sizeof( DNSAnswerRecord_t ) ) { /* It's not an A record, so skip it. Get the header location * and then jump over the header. */ /* Cast the response to DNSAnswerRecord for easy access to fields of the DNS response. */ - pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pucByte ); + pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pucBuffer ); - pucByte = &( pucByte[ sizeof( DNSAnswerRecord_t ) ] ); - uxSourceBytesRemaining -= sizeof( DNSAnswerRecord_t ); + pucBuffer = &( pucBuffer[ sizeof( DNSAnswerRecord_t ) ] ); + uxRxSourceByteRemaining -= sizeof( DNSAnswerRecord_t ); /* Determine the length of the answer data from the header. */ usDataLength = FreeRTOS_ntohs( pxDNSAnswerRecord->usDataLength ); /* Jump over the answer. */ - if( uxSourceBytesRemaining >= usDataLength ) + if( uxRxSourceByteRemaining >= usDataLength ) { - pucByte = &( pucByte[ usDataLength ] ); - uxSourceBytesRemaining -= usDataLength; + pucBuffer = &( pucBuffer[ usDataLength ] ); + uxRxSourceByteRemaining -= usDataLength; } else { diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index fe5ddbf74..f84b01daf 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1426,8 +1426,8 @@ static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPP * packet may cause network storms. Drop the packet. */ eReturn = eReleaseBuffer; } - else if( ( memcmp( ( const void * ) xBroadcastMACAddress.ucBytes, - ( const void * ) ( pxIPPacket->xEthernetHeader.xDestinationAddress.ucBytes ), + else if( ( memcmp( xBroadcastMACAddress.ucBytes, + pxIPPacket->xEthernetHeader.xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) && ( ( FreeRTOS_ntohl( ulDestinationIPAddress ) & 0xffU ) != 0xffU ) ) { @@ -1435,8 +1435,8 @@ static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPP * broadcast address. */ eReturn = eReleaseBuffer; } - else if( memcmp( ( void * ) &xBroadcastMACAddress, - ( void * ) &( pxIPPacket->xEthernetHeader.xSourceAddress ), + else if( memcmp( xBroadcastMACAddress.ucBytes, + pxIPPacket->xEthernetHeader.xSourceAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) { /* Ethernet source is a broadcast address. Drop the packet. */ diff --git a/source/FreeRTOS_IP_Timers.c b/source/FreeRTOS_IP_Timers.c index b660bfa29..f71d944d6 100644 --- a/source/FreeRTOS_IP_Timers.c +++ b/source/FreeRTOS_IP_Timers.c @@ -54,10 +54,6 @@ #include "NetworkBufferManagement.h" #include "FreeRTOS_DNS.h" -/** @brief The pointer to buffer with packet waiting for ARP resolution. */ -extern NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer; - - /* * Utility functions for the light weight IP timers. */ @@ -90,12 +86,6 @@ static IPTimer_t xARPTimer; /** @brief DNS timer, to check for timeouts when looking-up a domain. */ static IPTimer_t xDNSTimer; #endif -#if ( ipconfigUSE_TCP != 0 ) - -/** @brief Set to a non-zero value if one or more TCP message have been processed - * within the last round. */ - extern BaseType_t xProcessedTCPMessage; -#endif /** * @brief Calculate the maximum sleep time remaining. It will go through all diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 03ec6f3e4..7c3cea281 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -72,8 +72,6 @@ #define ipINITIALISATION_RETRY_DELAY ( pdMS_TO_TICKS( 3000U ) ) #endif -extern QueueHandle_t xNetworkEventQueue; - #if ( ipconfigUSE_NETWORK_EVENT_HOOK == 1 ) static BaseType_t xCallEventHook = pdFALSE; #endif @@ -291,8 +289,12 @@ NetworkBufferDescriptor_t * pxUDPPayloadBuffer_to_NetworkBuffer( const void * pv BaseType_t xIsCallingFromIPTask( void ) { BaseType_t xReturn; + TaskHandle_t xCurrentHandle, xCurrentIPTaskHandle; - if( xTaskGetCurrentTaskHandle() == FreeRTOS_GetIPTaskHandle() ) + xCurrentHandle = xTaskGetCurrentTaskHandle(); + xCurrentIPTaskHandle = FreeRTOS_GetIPTaskHandle(); + + if( xCurrentHandle == xCurrentIPTaskHandle ) { xReturn = pdTRUE; } diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 604ccb25a..718b85184 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -2533,16 +2533,19 @@ void FreeRTOS_EUI48_ntop( const uint8_t * pucSource, cResult = cResult + ( ucNibble - 10U ); } - pcTarget[ uxTarget++ ] = cResult; + pcTarget[ uxTarget ] = cResult; + uxTarget++; } if( uxIndex == ( ipMAC_ADDRESS_LENGTH_BYTES - 1U ) ) { - pcTarget[ uxTarget++ ] = ( char ) 0; + pcTarget[ uxTarget ] = ( char ) 0; + uxTarget++; } else { - pcTarget[ uxTarget++ ] = cSeparator; + pcTarget[ uxTarget ] = cSeparator; + uxTarget++; } } } @@ -4098,7 +4101,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) size_t uxLittlePerc = sock20_PERCENT; size_t uxEnoughPerc = sock80_PERCENT; size_t uxSegmentCount = pxSocket->u.xTCP.uxRxStreamSize / pxSocket->u.xTCP.usMSS; - static const struct xPercTable + static const struct Percent { size_t uxPercLittle, uxPercEnough; } diff --git a/source/FreeRTOS_TCP_Reception.c b/source/FreeRTOS_TCP_Reception.c index effa61b33..8a69e7e44 100644 --- a/source/FreeRTOS_TCP_Reception.c +++ b/source/FreeRTOS_TCP_Reception.c @@ -53,6 +53,7 @@ #include "NetworkBufferManagement.h" #include "FreeRTOS_ARP.h" #include "FreeRTOS_TCP_Transmission.h" +#include "FreeRTOS_TCP_Reception.h" /* Just make sure the contents doesn't get compiled if TCP is not enabled. */ #if ipconfigUSE_TCP == 1 @@ -73,16 +74,11 @@ * Skip past TCP header options when doing Selective ACK, until there are no * more options left. */ - _static void prvReadSackOption( const uint8_t * const pucPtr, - size_t uxIndex, - FreeRTOS_Socket_t * const pxSocket ); + static void prvReadSackOption( const uint8_t * const pucPtr, + size_t uxIndex, + FreeRTOS_Socket_t * const pxSocket ); #endif /* ( ipconfigUSE_TCP_WIN == 1 ) */ -/* - * Reply to a peer with the RST flag on, in case a packet can not be handled. - */ - BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t * pxNetworkBuffer ); - /** * @brief Parse the TCP option(s) received, if present. * @@ -369,9 +365,9 @@ * @param[in] uxIndex: Index of options in the TCP packet options. * @param[in] pxSocket: Socket handling the TCP connection. */ - _static void prvReadSackOption( const uint8_t * const pucPtr, - size_t uxIndex, - FreeRTOS_Socket_t * const pxSocket ) + static void prvReadSackOption( const uint8_t * const pucPtr, + size_t uxIndex, + FreeRTOS_Socket_t * const pxSocket ) { uint32_t ulFirst = ulChar2u32( &( pucPtr[ uxIndex ] ) ); uint32_t ulLast = ulChar2u32( &( pucPtr[ uxIndex + 4U ] ) ); @@ -521,10 +517,12 @@ uint32_t ulSequenceNumber, ulSpace; int32_t lOffset, lStored; BaseType_t xResult = 0; + uint32_t ulRxLength = ulReceiveLength; + uint8_t * pucRxBuffer = &( pucRecvData[ 0 ] ); ulSequenceNumber = FreeRTOS_ntohl( pxTCPHeader->ulSequenceNumber ); - if( ( ulReceiveLength > 0U ) && ( pxSocket->u.xTCP.ucTCPState >= ( uint8_t ) eSYN_RECEIVED ) ) + if( ( ulRxLength > 0U ) && ( pxSocket->u.xTCP.ucTCPState >= ( uint8_t ) eSYN_RECEIVED ) ) { uint32_t ulSkipCount = 0; @@ -544,7 +542,7 @@ ulSpace = ( uint32_t ) pxSocket->u.xTCP.uxRxStreamSize; } - lOffset = lTCPWindowRxCheck( pxTCPWindow, ulSequenceNumber, ulReceiveLength, ulSpace, &( ulSkipCount ) ); + lOffset = lTCPWindowRxCheck( pxTCPWindow, ulSequenceNumber, ulRxLength, ulSpace, &( ulSkipCount ) ); if( lOffset >= 0 ) { @@ -557,15 +555,15 @@ /* A packet was received that starts before 'ulCurrentSequenceNumber', * and that ends after it. The first 'ulSkipCount' bytes shall be * skipped. */ - ulReceiveLength -= ulSkipCount; - pucRecvData = &( pucRecvData[ ulSkipCount ] ); + ulRxLength -= ulSkipCount; + pucRxBuffer = &( pucRecvData[ ulSkipCount ] ); } - lStored = lTCPAddRxdata( pxSocket, ( uint32_t ) lOffset, pucRecvData, ulReceiveLength ); + lStored = lTCPAddRxdata( pxSocket, ( uint32_t ) lOffset, pucRxBuffer, ulRxLength ); - if( lStored != ( int32_t ) ulReceiveLength ) + if( lStored != ( int32_t ) ulRxLength ) { - FreeRTOS_debug_printf( ( "lTCPAddRxdata: stored %d / %u bytes? ?\n", ( int ) lStored, ( unsigned ) ulReceiveLength ) ); + FreeRTOS_debug_printf( ( "lTCPAddRxdata: stored %d / %u bytes? ?\n", ( int ) lStored, ( unsigned ) ulRxLength ) ); /* Received data could not be stored. The socket's flag * bMallocError has been set. The socket now has the status diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index 27325b5f5..6e3678925 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -491,9 +491,8 @@ } /* Fill in the destination MAC addresses. */ - ( void ) memcpy( ( void * ) ( &( pxEthernetHeader->xDestinationAddress ) ), - pvCopySource, - sizeof( pxEthernetHeader->xDestinationAddress ) ); + pvCopyDest = &pxEthernetHeader->xDestinationAddress; + ( void ) memcpy( pvCopyDest, pvCopySource, sizeof( pxEthernetHeader->xDestinationAddress ) ); } /* diff --git a/source/FreeRTOS_TCP_WIN.c b/source/FreeRTOS_TCP_WIN.c index 882091659..7f6be59cd 100644 --- a/source/FreeRTOS_TCP_WIN.c +++ b/source/FreeRTOS_TCP_WIN.c @@ -1183,6 +1183,8 @@ int32_t lStartDistance; int32_t lLastDistance; uint32_t ulLast; + uint32_t ulRxSequenceNumber = ulSequenceNumber; + uint32_t ulRxLength = ulLength; /* If lTCPWindowRxCheck( ) returns == 0, the packet will be passed * directly to user (segment is expected). If it returns a positive @@ -1201,23 +1203,23 @@ ulCurrentSequenceNumber = pxWindow->rx.ulCurrentSequenceNumber; - ulLast = ulSequenceNumber + ulLength; + ulLast = ulRxSequenceNumber + ulRxLength; ulIntermediateResult = ulLast - ulCurrentSequenceNumber; /* The cast from unsigned long to signed long is on purpose. */ lLastDistance = ( int32_t ) ulIntermediateResult; - ulIntermediateResult = ulSequenceNumber - ulCurrentSequenceNumber; + ulIntermediateResult = ulRxSequenceNumber - ulCurrentSequenceNumber; lStartDistance = ( int32_t ) ulIntermediateResult; if( ( lStartDistance < 0 ) && ( lLastDistance > 0 ) ) { FreeRTOS_debug_printf( ( "lTCPWindowRxCheck: Received +%u bytes for %u, only using %d\n", - ( unsigned ) ulLength, - ( unsigned ) ( ulSequenceNumber - pxWindow->rx.ulFirstSequenceNumber ), + ( unsigned ) ulRxLength, + ( unsigned ) ( ulRxSequenceNumber - pxWindow->rx.ulFirstSequenceNumber ), ( int ) lLastDistance ) ); /* Increase the sequence number, decrease the length. */ - ulSequenceNumber += ( uint32_t ) ( -lStartDistance ); - ulLength += ( uint32_t ) lStartDistance; + ulRxSequenceNumber += ( uint32_t ) ( -lStartDistance ); + ulRxLength += ( uint32_t ) lStartDistance; /* Tell the caller that the first 'pulSkipCount' bytes don't * need to be stored. */ @@ -1230,23 +1232,23 @@ /* Non-zero if TCP-windows contains data which must be popped. */ pxWindow->ulUserDataLength = 0U; - if( ulCurrentSequenceNumber == ulSequenceNumber ) + if( ulCurrentSequenceNumber == ulRxSequenceNumber ) { /* This is the packet with the lowest sequence number we're waiting * for. It can be passed directly to the rx stream. */ - if( ulLength > ulSpace ) + if( ulRxLength > ulSpace ) { - FreeRTOS_debug_printf( ( "lTCPWindowRxCheck: Refuse %u bytes, due to lack of space (%u)\n", ( unsigned ) ulLength, ( unsigned ) ulSpace ) ); + FreeRTOS_debug_printf( ( "lTCPWindowRxCheck: Refuse %u bytes, due to lack of space (%u)\n", ( unsigned ) ulRxLength, ( unsigned ) ulSpace ) ); } else { /* Packet was expected, may be passed directly to the socket * buffer or application. Store the packet at offset 0. */ - prvTCPWindowRx_ExpectedRX( pxWindow, ulLength ); + prvTCPWindowRx_ExpectedRX( pxWindow, ulRxLength ); lReturn = 0; } } - else if( ulCurrentSequenceNumber == ( ulSequenceNumber + 1U ) ) + else if( ulCurrentSequenceNumber == ( ulRxSequenceNumber + 1U ) ) { /* Looks like a TCP keep-alive message. Do not accept/store Rx data * ulUserDataLength = 0. Not packet out-of-sync. Just reply to it. */ @@ -1271,12 +1273,12 @@ * sequence number of this packet is too far ahead, ignore it. */ FreeRTOS_debug_printf( ( "lTCPWindowRxCheck: Refuse %d+%u bytes, due to lack of space (%u)\n", ( int ) lLastDistance, - ( unsigned ) ulLength, + ( unsigned ) ulRxLength, ( unsigned ) ulSpace ) ); } else { - lReturn = prvTCPWindowRx_UnexpectedRX( pxWindow, ulSequenceNumber, ulLength ); + lReturn = prvTCPWindowRx_UnexpectedRX( pxWindow, ulRxSequenceNumber, ulRxLength ); } } diff --git a/source/FreeRTOS_Tiny_TCP.c b/source/FreeRTOS_Tiny_TCP.c index be05d717b..ba65365aa 100644 --- a/source/FreeRTOS_Tiny_TCP.c +++ b/source/FreeRTOS_Tiny_TCP.c @@ -64,8 +64,6 @@ #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" -/*#include "FreeRTOS_TCP_WIN.h" */ - #if ( ipconfigUSE_TCP == 1 ) #if ( ipconfigUSE_TCP_WIN == 0 ) diff --git a/source/include/FreeRTOS_DNS_Callback.h b/source/include/FreeRTOS_DNS_Callback.h index 3fc58323c..557beee41 100644 --- a/source/include/FreeRTOS_DNS_Callback.h +++ b/source/include/FreeRTOS_DNS_Callback.h @@ -27,9 +27,11 @@ #ifndef FREERTOS_DNS_CALLBACK_H -#define FREERTOS_DNS_CALLBACK_H + #define FREERTOS_DNS_CALLBACK_H -#if ( ( ipconfigDNS_USE_CALLBACKS == 1 ) && ( ipconfigUSE_DNS != 0 ) ) + #ifdef __cplusplus + extern "C" { + #endif /* FreeRTOS includes. */ #include "FreeRTOS.h" @@ -41,23 +43,29 @@ /* Standard includes. */ #include + /* Application level configuration options. */ - BaseType_t xDNSDoCallback( TickType_t uxIdentifier, - const char * pcName, - uint32_t ulIPAddress ); + #if ( ( ipconfigDNS_USE_CALLBACKS == 1 ) && ( ipconfigUSE_DNS != 0 ) ) - void vDNSSetCallBack( const char * pcHostName, - void * pvSearchID, - FOnDNSEvent pCallbackFunction, - TickType_t uxTimeout, - TickType_t uxIdentifier ); + BaseType_t xDNSDoCallback( TickType_t uxIdentifier, + const char * pcName, + uint32_t ulIPAddress ); - void vDNSCheckCallBack( void * pvSearchID ); + void vDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t uxTimeout, + TickType_t uxIdentifier ); + + void vDNSCheckCallBack( void * pvSearchID ); - void vDNSCallbackInitialise(); + void vDNSCallbackInitialise(); -#endif /* ipconfigDNS_USE_CALLBACKS && ipconfigUSE_DNS */ + #endif /* ipconfigDNS_USE_CALLBACKS && ipconfigUSE_DNS */ + #ifdef __cplusplus + } /* extern "C" */ + #endif #endif /* ifndef FREERTOS_DNS_CALLBACK_H */ diff --git a/source/include/FreeRTOS_ICMP.h b/source/include/FreeRTOS_ICMP.h index 33cffeb56..d986c6540 100644 --- a/source/include/FreeRTOS_ICMP.h +++ b/source/include/FreeRTOS_ICMP.h @@ -30,36 +30,49 @@ * @brief Header file for Internet Control Message Protocol for the FreeRTOS+TCP network stack. */ +#ifndef FREERTOS_ICMP_H + #define FREERTOS_ICMP_H + + #ifdef __cplusplus + extern "C" { + #endif + /* Standard includes. */ -#include -#include -#include + #include + #include + #include /* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "semphr.h" + #include "FreeRTOS.h" + #include "task.h" + #include "queue.h" + #include "semphr.h" /* FreeRTOS+TCP includes. */ -#include "FreeRTOS_IP.h" -#include "FreeRTOS_Sockets.h" -#include "FreeRTOS_IP_Private.h" -#include "FreeRTOS_ARP.h" -#include "FreeRTOS_UDP_IP.h" -#include "FreeRTOS_DHCP.h" -#include "NetworkInterface.h" -#include "NetworkBufferManagement.h" -#include "FreeRTOS_DNS.h" + #include "FreeRTOS_IP.h" + #include "FreeRTOS_Sockets.h" + #include "FreeRTOS_IP_Private.h" + #include "FreeRTOS_ARP.h" + #include "FreeRTOS_UDP_IP.h" + #include "FreeRTOS_DHCP.h" + #include "NetworkInterface.h" + #include "NetworkBufferManagement.h" + #include "FreeRTOS_DNS.h" /* ICMP protocol definitions. */ -#define ipICMP_ECHO_REQUEST ( ( uint8_t ) 8 ) /**< ICMP echo request. */ -#define ipICMP_ECHO_REPLY ( ( uint8_t ) 0 ) /**< ICMP echo reply. */ + #define ipICMP_ECHO_REQUEST ( ( uint8_t ) 8 ) /**< ICMP echo request. */ + #define ipICMP_ECHO_REPLY ( ( uint8_t ) 0 ) /**< ICMP echo reply. */ -#if ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) + #if ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) /* * Process incoming ICMP packets. */ - eFrameProcessingResult_t ProcessICMPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer ); -#endif /* ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) */ + eFrameProcessingResult_t ProcessICMPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer ); + #endif /* ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) */ + + #ifdef __cplusplus + } /* extern "C" */ + #endif + +#endif /* FREERTOS_ICMP_H */ diff --git a/source/include/FreeRTOS_IP.h b/source/include/FreeRTOS_IP.h index be72f5d52..f45d22449 100644 --- a/source/include/FreeRTOS_IP.h +++ b/source/include/FreeRTOS_IP.h @@ -435,6 +435,13 @@ #define vPrintResourceStats() do {} while( ipFALSE_BOOL ) /**< ipconfigHAS_PRINTF is not defined. Define vPrintResourceStats to a do-while( 0 ). */ #endif + #if ( ipconfigUSE_TCP != 0 ) + +/** @brief Set to a non-zero value if one or more TCP message have been processed + * within the last round. */ + extern BaseType_t xProcessedTCPMessage; + #endif + #include "FreeRTOS_IP_Utils.h" #ifdef __cplusplus diff --git a/source/include/FreeRTOS_IP_Timers.h b/source/include/FreeRTOS_IP_Timers.h index 004bb441e..bc545bce3 100644 --- a/source/include/FreeRTOS_IP_Timers.h +++ b/source/include/FreeRTOS_IP_Timers.h @@ -30,72 +30,85 @@ * @brief Header file for IP Timers on FreeRTOS+TCP network stack. */ +#ifndef FREERTOS_IP_TIMERS_H + #define FREERTOS_IP_TIMERS_H + + #ifdef __cplusplus + extern "C" { + #endif + /* Standard includes. */ -#include -#include -#include + #include + #include + #include /* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "semphr.h" + #include "FreeRTOS.h" + #include "task.h" + #include "queue.h" + #include "semphr.h" /* FreeRTOS+TCP includes. */ -#include "FreeRTOS_IP.h" -#include "FreeRTOS_Sockets.h" -#include "FreeRTOS_IP_Private.h" -#include "FreeRTOS_ARP.h" -#include "FreeRTOS_UDP_IP.h" -#include "FreeRTOS_DHCP.h" -#include "NetworkInterface.h" -#include "NetworkBufferManagement.h" -#include "FreeRTOS_DNS.h" + #include "FreeRTOS_IP.h" + #include "FreeRTOS_Sockets.h" + #include "FreeRTOS_IP_Private.h" + #include "FreeRTOS_ARP.h" + #include "FreeRTOS_UDP_IP.h" + #include "FreeRTOS_DHCP.h" + #include "NetworkInterface.h" + #include "NetworkBufferManagement.h" + #include "FreeRTOS_DNS.h" /* * Checks the ARP, DHCP and TCP timers to see if any periodic or timeout * processing is required. */ -void vCheckNetworkTimers( void ); + void vCheckNetworkTimers( void ); /* * Determine how long the IP task can sleep for, which depends on when the next * periodic or timeout processing must be performed. */ -TickType_t xCalculateSleepTime( void ); + TickType_t xCalculateSleepTime( void ); -void vIPTimerStartARPResolution( TickType_t xTime ); + void vIPTimerStartARPResolution( TickType_t xTime ); -void vIPSetTCPTimerEnableState( BaseType_t xEnableState ); + void vIPSetTCPTimerEnableState( BaseType_t xEnableState ); -void vIPSetARPTimerEnableState( BaseType_t xEnableState ); + void vIPSetARPTimerEnableState( BaseType_t xEnableState ); -void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState ); + void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState ); -#if ( ipconfigUSE_DHCP != 0 ) + #if ( ipconfigUSE_DHCP != 0 ) /** * @brief Enable/disable the DHCP timer. * @param[in] xEnableState: pdTRUE - enable timer; pdFALSE - disable timer. */ - void vIPSetDHCPTimerEnableState( BaseType_t xEnableState ); -#endif + void vIPSetDHCPTimerEnableState( BaseType_t xEnableState ); + #endif -#if ( ipconfigDNS_USE_CALLBACKS != 0 ) + #if ( ipconfigDNS_USE_CALLBACKS != 0 ) /** * @brief Enable/disable the DNS timer. * @param[in] xEnableState: pdTRUE - enable timer; pdFALSE - disable timer. */ - void vIPSetDNSTimerEnableState( BaseType_t xEnableState ); -#endif + void vIPSetDNSTimerEnableState( BaseType_t xEnableState ); + #endif -void vARPTimerReload( TickType_t xTime ); -void vTCPTimerReload( TickType_t xTime ); -#if ( ipconfigUSE_DHCP == 1 ) - void vDHCPTimerReload( TickType_t xLeaseTime ); -#endif + void vARPTimerReload( TickType_t xTime ); + void vTCPTimerReload( TickType_t xTime ); + #if ( ipconfigUSE_DHCP == 1 ) + void vDHCPTimerReload( TickType_t xLeaseTime ); + #endif -#if ( ipconfigDNS_USE_CALLBACKS != 0 ) - void vDNSTimerReload( uint32_t ulCheckTime ); -#endif + #if ( ipconfigDNS_USE_CALLBACKS != 0 ) + void vDNSTimerReload( uint32_t ulCheckTime ); + #endif + + #ifdef __cplusplus + } /* extern "C" */ + #endif + +#endif /* FREERTOS_IP_TIMERS_H */ diff --git a/source/include/FreeRTOS_IP_Utils.h b/source/include/FreeRTOS_IP_Utils.h index db9a455f1..f636147df 100644 --- a/source/include/FreeRTOS_IP_Utils.h +++ b/source/include/FreeRTOS_IP_Utils.h @@ -25,34 +25,41 @@ * http://www.FreeRTOS.org */ +#ifndef FREERTOS_IP_UTILS_H + #define FREERTOS_IP_UTILS_H + + #ifdef __cplusplus + extern "C" { + #endif + /** * @file FreeRTOS_IP_Utils.h * @brief Implements the utility functions for FreeRTOS_IP.c */ /* Standard includes. */ -#include -#include -#include + #include + #include + #include /* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "semphr.h" + #include "FreeRTOS.h" + #include "task.h" + #include "queue.h" + #include "semphr.h" /* FreeRTOS+TCP includes. */ -#include "FreeRTOS_IP.h" -#include "FreeRTOS_Sockets.h" -#include "FreeRTOS_IP_Private.h" -#include "FreeRTOS_ARP.h" -#include "FreeRTOS_UDP_IP.h" -#include "FreeRTOS_DHCP.h" -#include "NetworkInterface.h" -#include "NetworkBufferManagement.h" -#include "FreeRTOS_DNS.h" + #include "FreeRTOS_IP.h" + #include "FreeRTOS_Sockets.h" + #include "FreeRTOS_IP_Private.h" + #include "FreeRTOS_ARP.h" + #include "FreeRTOS_UDP_IP.h" + #include "FreeRTOS_DHCP.h" + #include "NetworkInterface.h" + #include "NetworkBufferManagement.h" + #include "FreeRTOS_DNS.h" -#if ( ipconfigUSE_DHCP != 0 ) + #if ( ipconfigUSE_DHCP != 0 ) /** * @brief Create a DHCP event. @@ -60,10 +67,10 @@ * @return pdPASS or pdFAIL, depending on whether xSendEventStructToIPTask() * succeeded. */ - BaseType_t xSendDHCPEvent( void ); -#endif + BaseType_t xSendDHCPEvent( void ); + #endif -#if ( ipconfigZERO_COPY_TX_DRIVER != 0 ) || ( ipconfigZERO_COPY_RX_DRIVER != 0 ) + #if ( ipconfigZERO_COPY_TX_DRIVER != 0 ) || ( ipconfigZERO_COPY_RX_DRIVER != 0 ) /** * @brief Get the network buffer from the packet buffer. @@ -72,31 +79,23 @@ * * @return The network buffer if the alignment is correct. Else a NULL is returned. */ - NetworkBufferDescriptor_t * pxPacketBuffer_to_NetworkBuffer( const void * pvBuffer ); -#endif + NetworkBufferDescriptor_t * pxPacketBuffer_to_NetworkBuffer( const void * pvBuffer ); + #endif /** * @brief Check the values of configuration options and assert on it. Also verify that the IP-task * has not already been initialized. */ -void vPreCheckConfigs( void ); + void vPreCheckConfigs( void ); /** * @brief Called to create a network connection when the stack is first * started, or when the network connection is lost. */ -void prvProcessNetworkDownEvent( void ); + void prvProcessNetworkDownEvent( void ); -/** - * @brief Utility function: Convert error number to a human readable - * string. Declaration in FreeRTOS_errno_TCP.h. - * - * @param[in] xErrnum: The error number. - * @param[in] pcBuffer: Buffer big enough to be filled with the human readable message. - * @param[in] uxLength: Maximum length of the buffer. - * - * @return The buffer filled with human readable error string. - */ -const char * FreeRTOS_strerror_r( BaseType_t xErrnum, - char * pcBuffer, - size_t uxLength ); + #ifdef __cplusplus + } /* extern "C" */ + #endif + +#endif /* FREERTOS_IP_UTILS_H */ diff --git a/source/include/FreeRTOS_Sockets.h b/source/include/FreeRTOS_Sockets.h index ba5d485e9..280b348d7 100644 --- a/source/include/FreeRTOS_Sockets.h +++ b/source/include/FreeRTOS_Sockets.h @@ -41,6 +41,7 @@ /* Application level configuration options. */ #include "FreeRTOSIPConfig.h" + #include "FreeRTOSIPConfigDefaults.h" #ifndef FREERTOS_IP_CONFIG_H #error FreeRTOSIPConfig.h has not been included yet diff --git a/source/include/FreeRTOS_TCP_Reception.h b/source/include/FreeRTOS_TCP_Reception.h index bed76e753..8238b7b85 100644 --- a/source/include/FreeRTOS_TCP_Reception.h +++ b/source/include/FreeRTOS_TCP_Reception.h @@ -33,24 +33,11 @@ #endif /* - * Identify and deal with a single TCP header option, advancing the pointer to - * the header. This function returns pdTRUE or pdFALSE depending on whether the - * caller should continue to parse more header options or break the loop. + * Called from xProcessReceivedTCPPacket. Parse the TCP option(s) received, + * if present. This function returns pdFALSE if the options are not well formed. */ - int32_t prvSingleStepTCPHeaderOptions( const uint8_t * const pucPtr, - size_t uxTotalLength, - FreeRTOS_Socket_t * const pxSocket, - BaseType_t xHasSYNFlag ); - -/* - * Skip past TCP header options when doing Selective ACK, until there are no - * more options left. - */ - #if ( ipconfigUSE_TCP_WIN == 1 ) - void prvReadSackOption( const uint8_t * const pucPtr, - size_t uxIndex, - FreeRTOS_Socket_t * const pxSocket ); - #endif /* ( ipconfigUSE_TCP_WIN == 1 ) */ + BaseType_t prvCheckOptions( FreeRTOS_Socket_t * pxSocket, + const NetworkBufferDescriptor_t * pxNetworkBuffer ); /* * Called from prvTCPHandleState(). Find the TCP payload data and check and diff --git a/test/cbmc/proofs/CheckOptionsOuter/CheckOptionsOuter_harness.c b/test/cbmc/proofs/CheckOptionsOuter/CheckOptionsOuter_harness.c index 2d1fd3d83..3d58d0dd1 100644 --- a/test/cbmc/proofs/CheckOptionsOuter/CheckOptionsOuter_harness.c +++ b/test/cbmc/proofs/CheckOptionsOuter/CheckOptionsOuter_harness.c @@ -41,9 +41,9 @@ size_t buffer_size; * Function contract proved correct by CheckOptionsInner ****************************************************************/ -void prvReadSackOption( const uint8_t * const pucPtr, - size_t uxIndex, - FreeRTOS_Socket_t * const pxSocket ) +void __CPROVER_file_local_FreeRTOS_TCP_Reception_c_prvReadSackOption( const uint8_t * const pucPtr, + size_t uxIndex, + FreeRTOS_Socket_t * const pxSocket ) { /* Preconditions */ __CPROVER_assert( buffer_size < CBMC_MAX_OBJECT_SIZE, diff --git a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c index dd6d2616f..fb02c73ae 100644 --- a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c +++ b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c @@ -65,8 +65,6 @@ #include "FreeRTOSIPConfig.h" -extern uint32_t xProcessedTCPMessage; - void prvIPTask( void * pvParameters ); void prvProcessIPEventsAndTimers( void ); eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket, diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_utest.c b/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_utest.c index ab400ba4b..8d71fe3e9 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_utest.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_utest.c @@ -65,8 +65,6 @@ #include "FreeRTOSIPConfig.h" -extern uint32_t xProcessedTCPMessage; - void prvIPTask( void * pvParameters ); void prvProcessIPEventsAndTimers( void ); eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket, diff --git a/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_stubs.c b/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_stubs.c index 59532be66..81666b3fe 100644 --- a/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_stubs.c +++ b/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_stubs.c @@ -44,6 +44,8 @@ volatile BaseType_t xInsideInterrupt = pdFALSE; NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer; +BaseType_t xProcessedTCPMessage; + /** @brief The expected IP version and header length coded into the IP header itself. */ #define ipIP_VERSION_AND_HEADER_LENGTH_BYTE ( ( uint8_t ) 0x45 ) diff --git a/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_utest.c b/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_utest.c index 549f8cba6..b5e64f90b 100644 --- a/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_utest.c +++ b/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_utest.c @@ -84,7 +84,7 @@ extern IPTimer_t xARPTimer; /** @brief Set to a non-zero value if one or more TCP message have been processed * within the last round. */ - BaseType_t xProcessedTCPMessage; + extern BaseType_t xProcessedTCPMessage; #endif extern IPTimer_t xARPResolutionTimer; 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 280f9b256..75ca59686 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 @@ -54,6 +54,7 @@ #include "mock_FreeRTOS_TCP_State_Handling.h" #include "mock_FreeRTOS_UDP_IP.h" #include "mock_FreeRTOS_TCP_Transmission.h" +#include "mock_FreeRTOS_TCP_Reception.h" #include "catch_assert.h" diff --git a/test/unit-test/FreeRTOS_TCP_IP/TCP_IP_list_macros.h b/test/unit-test/FreeRTOS_TCP_IP/TCP_IP_list_macros.h index e1abbea39..51ea6a0b8 100644 --- a/test/unit-test/FreeRTOS_TCP_IP/TCP_IP_list_macros.h +++ b/test/unit-test/FreeRTOS_TCP_IP/TCP_IP_list_macros.h @@ -88,10 +88,4 @@ FreeRTOS_Socket_t * pxTCPSocketLookup( uint32_t ulLocalIP, uint32_t ulRemoteIP, UBaseType_t uxRemotePort ); -/* - * Parse the TCP option(s) received, if present. - */ -BaseType_t prvCheckOptions( FreeRTOS_Socket_t * pxSocket, - const NetworkBufferDescriptor_t * pxNetworkBuffer ); - #endif /* ifndef LIST_MACRO_H */ diff --git a/test/unit-test/FreeRTOS_TCP_IP_DiffConfig/TCP_IP_DiffConfig_list_macros.h b/test/unit-test/FreeRTOS_TCP_IP_DiffConfig/TCP_IP_DiffConfig_list_macros.h index e1abbea39..51ea6a0b8 100644 --- a/test/unit-test/FreeRTOS_TCP_IP_DiffConfig/TCP_IP_DiffConfig_list_macros.h +++ b/test/unit-test/FreeRTOS_TCP_IP_DiffConfig/TCP_IP_DiffConfig_list_macros.h @@ -88,10 +88,4 @@ FreeRTOS_Socket_t * pxTCPSocketLookup( uint32_t ulLocalIP, uint32_t ulRemoteIP, UBaseType_t uxRemotePort ); -/* - * Parse the TCP option(s) received, if present. - */ -BaseType_t prvCheckOptions( FreeRTOS_Socket_t * pxSocket, - const NetworkBufferDescriptor_t * pxNetworkBuffer ); - #endif /* ifndef LIST_MACRO_H */