diff options
Diffstat (limited to 'FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h')
-rw-r--r-- | FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h | 171 |
1 files changed, 118 insertions, 53 deletions
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h index 46a215777..7b37f955e 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h @@ -1,5 +1,5 @@ /* - * FreeRTOS+TCP V2.2.0 + * FreeRTOS+TCP V2.2.1 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -30,36 +30,71 @@ extern "C" { #endif +#include "FreeRTOS.h" +#include "task.h" + /* Application level configuration options. */ #include "FreeRTOSIPConfig.h" #include "FreeRTOSIPConfigDefaults.h" #include "IPTraceMacroDefaults.h" -/* Some constants defining the sizes of several parts of a packet */ -#define ipSIZE_OF_ETH_HEADER 14u -#define ipSIZE_OF_IPv4_HEADER 20u -#define ipSIZE_OF_IGMP_HEADER 8u -#define ipSIZE_OF_ICMP_HEADER 8u -#define ipSIZE_OF_UDP_HEADER 8u -#define ipSIZE_OF_TCP_HEADER 20u +#ifdef __COVERITY__ + /* Coverity static checks don't like inlined functions. + As it is up to the users to allow inlining, don't let + let Coverity know about it. */ + + #ifdef portINLINE + /* The usage of #undef violates the rule. */ + #undef portINLINE + + #endif + + #define portINLINE +#endif + +/* Some constants defining the sizes of several parts of a packet. +These defines come before inlucding the configuration header files. */ +/* The size of the Ethernet header is 14, meaning that 802.1Q VLAN tags +are not ( yet ) supported. */ +#define ipSIZE_OF_ETH_HEADER 14U +#define ipSIZE_OF_IPv4_HEADER 20U +#define ipSIZE_OF_IGMP_HEADER 8U +#define ipSIZE_OF_ICMP_HEADER 8U +#define ipSIZE_OF_UDP_HEADER 8U +#define ipSIZE_OF_TCP_HEADER 20U +#define ipSIZE_OF_IPv4_ADDRESS 4U + +/* + * Generate a randomized TCP Initial Sequence Number per RFC. + * This function must be provided by the application builder. + */ +/* This function is defined generally by the application. */ +extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress, + uint16_t usSourcePort, + uint32_t ulDestinationAddress, + uint16_t usDestinationPort ); /* The number of octets in the MAC and IP addresses respectively. */ #define ipMAC_ADDRESS_LENGTH_BYTES ( 6 ) #define ipIP_ADDRESS_LENGTH_BYTES ( 4 ) /* IP protocol definitions. */ -#define ipPROTOCOL_ICMP ( 1 ) -#define ipPROTOCOL_IGMP ( 2 ) -#define ipPROTOCOL_TCP ( 6 ) -#define ipPROTOCOL_UDP ( 17 ) +#define ipPROTOCOL_ICMP ( 1U ) +#define ipPROTOCOL_IGMP ( 2U ) +#define ipPROTOCOL_TCP ( 6U ) +#define ipPROTOCOL_UDP ( 17U ) + +/* The character used to fill ICMP echo requests, and therefore also the +character expected to fill ICMP echo replies. */ +#define ipECHO_DATA_FILL_BYTE 'x' /* Dimensions the buffers that are filled by received Ethernet frames. */ #define ipSIZE_OF_ETH_CRC_BYTES ( 4UL ) #define ipSIZE_OF_ETH_OPTIONAL_802_1Q_TAG_BYTES ( 4UL ) #define ipTOTAL_ETHERNET_FRAME_SIZE ( ( ( uint32_t ) ipconfigNETWORK_MTU ) + ( ( uint32_t ) ipSIZE_OF_ETH_HEADER ) + ipSIZE_OF_ETH_CRC_BYTES + ipSIZE_OF_ETH_OPTIONAL_802_1Q_TAG_BYTES ) -/*_RB_ Comment may need updating. */ + /* Space left at the beginning of a network buffer storage area to store a pointer back to the network buffer. Should be a multiple of 8 to ensure 8 byte alignment is maintained on architectures that require it. @@ -77,10 +112,11 @@ buffer will have the following contents: uint8_t ucVersionHeaderLength; etc */ + #if( ipconfigBUFFER_PADDING != 0 ) #define ipBUFFER_PADDING ipconfigBUFFER_PADDING #else - #define ipBUFFER_PADDING ( 8u + ipconfigPACKET_FILLER_SIZE ) + #define ipBUFFER_PADDING ( 8U + ipconfigPACKET_FILLER_SIZE ) #endif /* The structure used to store buffers and pass them around the network stack. @@ -114,6 +150,8 @@ typedef enum eNETWORK_EVENTS eNetworkDown /* The network connection has been lost. */ } eIPCallbackEvent_t; +/* MISRA check: some modules refer to this typedef even though +ipconfigSUPPORT_OUTGOING_PINGS is not enabled. */ typedef enum ePING_REPLY_STATUS { eSuccess = 0, /* A correct reply has been received for an outgoing ping. */ @@ -121,12 +159,15 @@ typedef enum ePING_REPLY_STATUS eInvalidData /* A reply was received to an outgoing ping but the payload of the reply was not correct. */ } ePingReplyStatus_t; -typedef enum eNETWORK_ADDRESS_TYPE +typedef struct xIP_TIMER { - eNetWorkAddressTypeIPV4, - eNetWorkAddressTypeIPV6, - eNetWorkAddressTypeHostName -} eNetWorkAddressType_t; + uint32_t + bActive : 1, /* This timer is running and must be processed. */ + bExpired : 1; /* Timer has expired and a task must be processed. */ + TimeOut_t xTimeOut; + TickType_t ulRemainingTime; + TickType_t ulReloadTime; +} IPTimer_t; /* Endian related definitions. */ #if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) @@ -169,52 +210,45 @@ typedef enum eNETWORK_ADDRESS_TYPE static portINLINE uint32_t FreeRTOS_round_up (uint32_t a, uint32_t d); static portINLINE uint32_t FreeRTOS_round_down (uint32_t a, uint32_t d); static portINLINE BaseType_t FreeRTOS_min_BaseType (BaseType_t a, BaseType_t b); - static portINLINE BaseType_t FreeRTOS_max_BaseType (BaseType_t a, BaseType_t b); - static portINLINE UBaseType_t FreeRTOS_max_UBaseType (UBaseType_t a, UBaseType_t b); - static portINLINE UBaseType_t FreeRTOS_min_UBaseType (UBaseType_t a, UBaseType_t b); - - static portINLINE int32_t FreeRTOS_max_int32 (int32_t a, int32_t b) { return a >= b ? a : b; } - static portINLINE uint32_t FreeRTOS_max_uint32 (uint32_t a, uint32_t b) { return a >= b ? a : b; } - static portINLINE int32_t FreeRTOS_min_int32 (int32_t a, int32_t b) { return a <= b ? a : b; } - static portINLINE uint32_t FreeRTOS_min_uint32 (uint32_t a, uint32_t b) { return a <= b ? a : b; } - static portINLINE uint32_t FreeRTOS_round_up (uint32_t a, uint32_t d) { return d * ( ( a + d - 1u ) / d ); } + static portINLINE int32_t FreeRTOS_max_int32 (int32_t a, int32_t b) { return ( a >= b ) ? a : b; } + static portINLINE uint32_t FreeRTOS_max_uint32 (uint32_t a, uint32_t b) { return ( a >= b ) ? a : b; } + static portINLINE int32_t FreeRTOS_min_int32 (int32_t a, int32_t b) { return ( a <= b ) ? a : b; } + static portINLINE uint32_t FreeRTOS_min_uint32 (uint32_t a, uint32_t b) { return ( a <= b ) ? a : b; } + static portINLINE uint32_t FreeRTOS_round_up (uint32_t a, uint32_t d) { return d * ( ( a + d - 1U ) / d ); } static portINLINE uint32_t FreeRTOS_round_down (uint32_t a, uint32_t d) { return d * ( a / d ); } - static portINLINE BaseType_t FreeRTOS_max_BaseType (BaseType_t a, BaseType_t b) { return a >= b ? a : b; } - static portINLINE UBaseType_t FreeRTOS_max_UBaseType (UBaseType_t a, UBaseType_t b) { return a >= b ? a : b; } - static portINLINE BaseType_t FreeRTOS_min_BaseType (BaseType_t a, BaseType_t b) { return a <= b ? a : b; } - static portINLINE UBaseType_t FreeRTOS_min_UBaseType (UBaseType_t a, UBaseType_t b) { return a <= b ? a : b; } + static portINLINE BaseType_t FreeRTOS_min_BaseType (BaseType_t a, BaseType_t b) { return ( a <= b ) ? a : b; } #else - #define FreeRTOS_max_int32(a,b) ( ( ( int32_t ) ( a ) ) >= ( ( int32_t ) ( b ) ) ? ( ( int32_t ) ( a ) ) : ( ( int32_t ) ( b ) ) ) - #define FreeRTOS_max_uint32(a,b) ( ( ( uint32_t ) ( a ) ) >= ( ( uint32_t ) ( b ) ) ? ( ( uint32_t ) ( a ) ) : ( ( uint32_t ) ( b ) ) ) + #define FreeRTOS_max_int32(a,b) ( ( ( ( int32_t ) ( a ) ) >= ( ( int32_t ) ( b ) ) ) ? ( ( int32_t ) ( a ) ) : ( ( int32_t ) ( b ) ) ) + #define FreeRTOS_max_uint32(a,b) ( ( ( ( uint32_t ) ( a ) ) >= ( ( uint32_t ) ( b ) ) ) ? ( ( uint32_t ) ( a ) ) : ( ( uint32_t ) ( b ) ) ) - #define FreeRTOS_min_int32(a,b) ( ( ( int32_t ) a ) <= ( ( int32_t ) b ) ? ( ( int32_t ) a ) : ( ( int32_t ) b ) ) - #define FreeRTOS_min_uint32(a,b) ( ( ( uint32_t ) a ) <= ( ( uint32_t ) b ) ? ( ( uint32_t ) a ) : ( ( uint32_t ) b ) ) + #define FreeRTOS_min_int32(a,b) ( ( ( ( int32_t ) a ) <= ( ( int32_t ) b ) ) ? ( ( int32_t ) a ) : ( ( int32_t ) b ) ) + #define FreeRTOS_min_uint32(a,b) ( ( ( ( uint32_t ) a ) <= ( ( uint32_t ) b ) ) ? ( ( uint32_t ) a ) : ( ( uint32_t ) b ) ) - /* Round-up: a = d * ( ( a + d - 1 ) / d ) */ + /* Round-up: divide a by d and round=up the result. */ #define FreeRTOS_round_up(a,d) ( ( ( uint32_t ) ( d ) ) * ( ( ( ( uint32_t ) ( a ) ) + ( ( uint32_t ) ( d ) ) - 1UL ) / ( ( uint32_t ) ( d ) ) ) ) #define FreeRTOS_round_down(a,d) ( ( ( uint32_t ) ( d ) ) * ( ( ( uint32_t ) ( a ) ) / ( ( uint32_t ) ( d ) ) ) ) - #define FreeRTOS_ms_to_tick(ms) ( ( ms * configTICK_RATE_HZ + 500 ) / 1000 ) - - #define FreeRTOS_max_BaseType(a, b) ( ( ( BaseType_t ) ( a ) ) >= ( ( BaseType_t ) ( b ) ) ? ( ( BaseType_t ) ( a ) ) : ( ( BaseType_t ) ( b ) ) ) - #define FreeRTOS_max_UBaseType(a, b) ( ( ( UBaseType_t ) ( a ) ) >= ( ( UBaseType_t ) ( b ) ) ? ( ( UBaseType_t ) ( a ) ) : ( ( UBaseType_t ) ( b ) ) ) #define FreeRTOS_min_BaseType(a, b) ( ( ( BaseType_t ) ( a ) ) <= ( ( BaseType_t ) ( b ) ) ? ( ( BaseType_t ) ( a ) ) : ( ( BaseType_t ) ( b ) ) ) - #define FreeRTOS_min_UBaseType(a, b) ( ( ( UBaseType_t ) ( a ) ) <= ( ( UBaseType_t ) ( b ) ) ? ( ( UBaseType_t ) ( a ) ) : ( ( UBaseType_t ) ( b ) ) ) #endif /* ipconfigHAS_INLINE_FUNCTIONS */ -#define pdMS_TO_MIN_TICKS( xTimeInMs ) ( pdMS_TO_TICKS( ( xTimeInMs ) ) < ( ( TickType_t ) 1 ) ? ( ( TickType_t ) 1 ) : pdMS_TO_TICKS( ( xTimeInMs ) ) ) +#define ipMS_TO_MIN_TICKS( xTimeInMs ) ( ( pdMS_TO_TICKS( ( xTimeInMs ) ) < ( ( TickType_t ) 1U ) ) ? ( ( TickType_t ) 1U ) : pdMS_TO_TICKS( ( xTimeInMs ) ) ) + +/* For backward compatibility. */ +#define pdMS_TO_MIN_TICKS( xTimeInMs ) ipMS_TO_MIN_TICKS( xTimeInMs ) #ifndef pdTRUE_SIGNED /* Temporary solution: eventually the defines below will appear in 'Source\include\projdefs.h' */ #define pdTRUE_SIGNED pdTRUE #define pdFALSE_SIGNED pdFALSE - #define pdTRUE_UNSIGNED ( ( UBaseType_t ) 1u ) - #define pdFALSE_UNSIGNED ( ( UBaseType_t ) 0u ) + #define pdTRUE_UNSIGNED ( 1U ) + #define pdFALSE_UNSIGNED ( 0U ) + #define ipTRUE_BOOL ( 1 == 1 ) + #define ipFALSE_BOOL ( 1 == 2 ) #endif /* @@ -228,15 +262,31 @@ BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ], const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] ); -void * FreeRTOS_GetUDPPayloadBuffer( size_t xRequestedSizeBytes, TickType_t xBlockTimeTicks ); -void FreeRTOS_GetAddressConfiguration( uint32_t *pulIPAddress, uint32_t *pulNetMask, uint32_t *pulGatewayAddress, uint32_t *pulDNSServerAddress ); -void FreeRTOS_SetAddressConfiguration( const uint32_t *pulIPAddress, const uint32_t *pulNetMask, const uint32_t *pulGatewayAddress, const uint32_t *pulDNSServerAddress ); -BaseType_t FreeRTOS_SendPingRequest( uint32_t ulIPAddress, size_t xNumberOfBytesToSend, TickType_t xBlockTimeTicks ); -void FreeRTOS_ReleaseUDPPayloadBuffer( void *pvBuffer ); +void * FreeRTOS_GetUDPPayloadBuffer( size_t uxRequestedSizeBytes, TickType_t uxBlockTimeTicks ); +void FreeRTOS_GetAddressConfiguration( uint32_t *pulIPAddress, + uint32_t *pulNetMask, + uint32_t *pulGatewayAddress, + uint32_t *pulDNSServerAddress ); + +void FreeRTOS_SetAddressConfiguration( const uint32_t *pulIPAddress, + const uint32_t *pulNetMask, + const uint32_t *pulGatewayAddress, + const uint32_t *pulDNSServerAddress ); + +/* MISRA defining 'FreeRTOS_SendPingRequest' should be dependent on 'ipconfigSUPPORT_OUTGOING_PINGS'. +In order not to break some existing project, define it unconditionally. */ +BaseType_t FreeRTOS_SendPingRequest( uint32_t ulIPAddress, size_t uxNumberOfBytesToSend, TickType_t uxBlockTimeTicks ); + +void FreeRTOS_ReleaseUDPPayloadBuffer( void const * pvBuffer ); const uint8_t * FreeRTOS_GetMACAddress( void ); void FreeRTOS_UpdateMACAddress( const uint8_t ucMACAddress[ipMAC_ADDRESS_LENGTH_BYTES] ); -void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent ); -void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier ); +#if( ipconfigUSE_NETWORK_EVENT_HOOK == 1 ) + /* This function shall be defined by the application. */ + void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent ); +#endif +#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) + void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier ); +#endif uint32_t FreeRTOS_GetIPAddress( void ); void FreeRTOS_SetIPAddress( uint32_t ulIPAddress ); void FreeRTOS_SetNetmask( uint32_t ulNetmask ); @@ -251,6 +301,12 @@ BaseType_t FreeRTOS_IsNetworkUp( void ); UBaseType_t uxGetMinimumIPQueueSpace( void ); #endif +#if ( ipconfigHAS_PRINTF != 0 ) + extern void vPrintResourceStats( void ); +#else + #define vPrintResourceStats() do {} while( ipFALSE_BOOL ) +#endif + /* * Defined in FreeRTOS_Sockets.c * //_RB_ Don't think this comment is correct. If this is for internal use only it should appear after all the public API functions and not start with FreeRTOS_. @@ -264,12 +320,19 @@ const char *FreeRTOS_GetTCPStateName( UBaseType_t ulState); void FreeRTOS_PrintARPCache( void ); void FreeRTOS_ClearARP( void ); +/* Return pdTRUE if the IPv4 address is a multicast address. */ +BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress ); + +/* Set the MAC-address that belongs to a given IPv4 multi-cast address. */ +void vSetMultiCastIPv4MacAddress( uint32_t ulIPAddress, MACAddress_t *pxMACAddress ); + #if( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) /* DHCP has an option for clients to register their hostname. It doesn't have much use, except that a device can be found in a router along with its name. If this option is used the callback below must be provided by the application writer to return a const string, denoting the device's name. */ + /* Typically this function is defined in a user module. */ const char *pcApplicationHostnameHook( void ); #endif /* ipconfigDHCP_REGISTER_HOSTNAME */ @@ -282,7 +345,9 @@ The function is defined in 'iot_secure_sockets.c'. If that module is not included in the project, the application must provide an implementation of it. The macro's ipconfigRAND32() and configRAND32() are not in use anymore. */ -BaseType_t xApplicationGetRandomNumber( uint32_t *pulNumber ); +/* "xApplicationGetRandomNumber" is declared but never defined, because it may +be defined in a user module. */ +extern BaseType_t xApplicationGetRandomNumber( uint32_t *pulNumber ); /* For backward compatibility define old structure names to the newer equivalent structure name. */ |