From 97cbf09372237f4e071fd63a25df8b98219b1194 Mon Sep 17 00:00:00 2001 From: Holden Date: Mon, 19 Jun 2023 15:07:19 -0400 Subject: [PATCH] Attempt to bring up to date --- source/FreeRTOS_DNS.c | 499 ++-- source/include/FreeRTOSIPConfigDefaults.h | 2985 +++++++++++++-------- 2 files changed, 2137 insertions(+), 1347 deletions(-) diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 7ab2933928..10f285e5fd 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -108,10 +108,6 @@ */ const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6 = { - #ifndef _MSC_VER - /* MSC doesn't like this C-style initialisation. */ - ucBytes : - #endif { /* ff02::1:3 */ 0xff, 0x02, 0x00, 0x00, @@ -127,7 +123,6 @@ /** * @brief The IPv6 link-scope multicast MAC address */ - const const MACAddress_t xLLMNR_MacAdressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } }; #endif /* ipconfigUSE_LLMNR && ipconfigUSE_IPv6 */ @@ -138,10 +133,6 @@ */ const IPv6_Address_t ipMDNS_IP_ADDR_IPv6 = { - #ifndef _MSC_VER - /* MSC doesn't like this C-style initialisation. */ - ucBytes : - #endif { /* ff02::fb */ 0xff, 0x02, 0x00, 0x00, @@ -189,8 +180,10 @@ #include "pack_struct_end.h" typedef struct xDNSTail DNSTail_t; + #if ( ipconfigUSE_IPv4 != 0 ) /** @brief Increment the field 'ucDNSIndex', which is an index in the array */ - static void prvIncreaseDNS4Index( NetworkEndPoint_t * pxEndPoint ); + static void prvIncreaseDNS4Index( NetworkEndPoint_t * pxEndPoint ); + #endif #if ( ipconfigUSE_IPv6 != 0 ) /** @brief Increment the field 'ucDNSIndex', which is an index in the array */ @@ -203,7 +196,7 @@ /** * @brief Define FreeRTOS_gethostbyname() as a normal blocking call. - * @param[in] pcHostName: The hostname whose IP address is being searched for. + * @param[in] pcHostName The hostname whose IP address is being searched for. * @return The IP-address of the hostname. */ uint32_t FreeRTOS_gethostbyname( const char * pcHostName ) @@ -228,7 +221,7 @@ /** * @brief Remove the entry defined by the search ID to cancel a DNS request. - * @param[in] pvSearchID: The search ID of the callback function associated with + * @param[in] pvSearchID The search ID of the callback function associated with * the DNS request being cancelled. Note that the value of * the pointer matters, not the pointee. */ @@ -245,10 +238,10 @@ /** * @brief Look-up the IP-address of a host. * - * @param[in] pcName: The name of the node or device - * @param[in] pcService: Ignored for now. - * @param[in] pxHints: If not NULL: preferences. Can be used to indicate the preferred type if IP ( v4 or v6 ). - * @param[out] ppxResult: An allocated struct, containing the results. + * @param[in] pcName The name of the node or device + * @param[in] pcService Ignored for now. + * @param[in] pxHints If not NULL preferences. Can be used to indicate the preferred type if IP ( v4 or v6 ). + * @param[out] ppxResult An allocated struct, containing the results. * * @return Zero when the operation was successful, otherwise a negative errno value. */ @@ -266,9 +259,9 @@ /** * @brief Internal function: allocate and initialise a new struct of type freertos_addrinfo. * - * @param[in] pcName: the name of the host. - * @param[in] xFamily: the type of IP-address: FREERTOS_AF_INET4 or FREERTOS_AF_INET6. - * @param[in] pucAddress: The IP-address of the host. + * @param[in] pcName the name of the host. + * @param[in] xFamily the type of IP-address: FREERTOS_AF_INET4 or FREERTOS_AF_INET6. + * @param[in] pucAddress The IP-address of the host. * * @return A pointer to the newly allocated struct, or NULL in case malloc failed.. */ @@ -291,26 +284,39 @@ pxAddrInfo->ai_canonname = pxAddrInfo->xPrivateStorage.ucName; ( void ) strncpy( pxAddrInfo->xPrivateStorage.ucName, pcName, sizeof( pxAddrInfo->xPrivateStorage.ucName ) ); - #if ( ipconfigUSE_IPv6 == 0 ) - pxAddrInfo->ai_addr = &( pxAddrInfo->xPrivateStorage.sockaddr ); - #else - pxAddrInfo->ai_addr = ( ( struct freertos_sockaddr * ) &( pxAddrInfo->xPrivateStorage.sockaddr ) ); + pxAddrInfo->ai_addr = ( ( struct freertos_sockaddr * ) &( pxAddrInfo->xPrivateStorage.sockaddr ) ); - if( xFamily == ( BaseType_t ) FREERTOS_AF_INET6 ) - { - pxAddrInfo->ai_family = FREERTOS_AF_INET6; - pxAddrInfo->ai_addrlen = ipSIZE_OF_IPv6_ADDRESS; - ( void ) memcpy( pxAddrInfo->xPrivateStorage.sockaddr.sin_address.xIP_IPv6.ucBytes, pucAddress, ipSIZE_OF_IPv6_ADDRESS ); - } - else - #endif /* ( ipconfigUSE_IPv6 == 0 ) */ + switch( xFamily ) { - /* ulChar2u32 reads from big-endian to host-endian. */ - uint32_t ulIPAddress = ulChar2u32( pucAddress ); - /* Translate to network-endian. */ - pxAddrInfo->ai_addr->sin_addr = FreeRTOS_htonl( ulIPAddress ); - pxAddrInfo->ai_family = FREERTOS_AF_INET4; - pxAddrInfo->ai_addrlen = ipSIZE_OF_IPv4_ADDRESS; + #if ( ipconfigUSE_IPv4 != 0 ) + case FREERTOS_AF_INET4: + { + /* ulChar2u32 reads from big-endian to host-endian. */ + uint32_t ulIPAddress = ulChar2u32( pucAddress ); + /* Translate to network-endian. */ + pxAddrInfo->ai_addr->sin_address.ulIP_IPv4 = FreeRTOS_htonl( ulIPAddress ); + pxAddrInfo->ai_family = FREERTOS_AF_INET4; + pxAddrInfo->ai_addrlen = ipSIZE_OF_IPv4_ADDRESS; + } + break; + #endif /* ( ipconfigUSE_IPv4 != 0 ) */ + + #if ( ipconfigUSE_IPv6 != 0 ) + case FREERTOS_AF_INET6: + pxAddrInfo->ai_family = FREERTOS_AF_INET6; + pxAddrInfo->ai_addrlen = ipSIZE_OF_IPv6_ADDRESS; + ( void ) memcpy( pxAddrInfo->xPrivateStorage.sockaddr.sin_address.xIP_IPv6.ucBytes, pucAddress, ipSIZE_OF_IPv6_ADDRESS ); + break; + #endif /* ( ipconfigUSE_IPv6 != 0 ) */ + + default: + /* MISRA 16.4 Compliance */ + FreeRTOS_debug_printf( ( "pxNew_AddrInfo: Undefined xFamily Type \n" ) ); + + vPortFree( pvBuffer ); + pxAddrInfo = NULL; + + break; } } @@ -320,7 +326,7 @@ /** * @brief Free a chain of structs of type 'freertos_addrinfo'. - * @param[in] pxInfo: The first find result. + * @param[in] pxInfo The first find result. */ void FreeRTOS_freeaddrinfo( struct freertos_addrinfo * pxInfo ) { @@ -344,13 +350,13 @@ /** * @brief Asynchronous version of getaddrinfo(). * - * @param[in] pcName: The name of the node or device - * @param[in] pcService: Ignored for now. - * @param[in] pxHints: If not NULL: preferences. Can be used to indicate the preferred type if IP ( v4 or v6 ). - * @param[out] ppxResult: An allocated struct, containing the results. - * @param[in] pCallback: A user-defined function which will be called on completion, either when found or after a time-out. - * @param[in] pvSearchID: A user provided void pointer that will be communicated on completion. - * @param[in] uxTimeout: The maximum number of clock ticks that must be waited for a reply. + * @param[in] pcName The name of the node or device + * @param[in] pcService Ignored for now. + * @param[in] pxHints If not NULL preferences. Can be used to indicate the preferred type if IP ( v4 or v6 ). + * @param[out] ppxResult An allocated struct, containing the results. + * @param[in] pCallback A user-defined function which will be called on completion, either when found or after a time-out. + * @param[in] pvSearchID A user provided void pointer that will be communicated on completion. + * @param[in] uxTimeout The maximum number of clock ticks that must be waited for a reply. * * @return Zero when the operation was successful, otherwise a negative errno value. */ @@ -365,10 +371,10 @@ /** * @brief Look-up the IP-address of a host. - * @param[in] pcName: The name of the node or device - * @param[in] pcService: Ignored for now. - * @param[in] pxHints: If not NULL: preferences. Can be used to indicate the preferred type if IP ( v4 or v6 ). - * @param[out] ppxResult: An allocated struct, containing the results. + * @param[in] pcName The name of the node or device + * @param[in] pcService Ignored for now. + * @param[in] pxHints If not NULL preferences. Can be used to indicate the preferred type if IP ( v4 or v6 ). + * @param[out] ppxResult An allocated struct, containing the results. * @return Zero when the operation was successful, otherwise a negative errno value. */ BaseType_t FreeRTOS_getaddrinfo( const char * pcName, /* The name of the node or device */ @@ -450,7 +456,7 @@ /** * @brief Get the IP-address corresponding to the given hostname. - * @param[in] pcHostName: The hostname whose IP address is being queried. + * @param[in] pcHostName The hostname whose IP address is being queried. * @return The IP-address corresponding to the hostname. 0 is returned in * case of failure. */ @@ -462,14 +468,14 @@ /** * @brief Get the IP-address corresponding to the given hostname. - * @param[in] pcHostName: The hostname whose IP address is being queried. - * @param[in] pCallback: The callback function which will be called upon DNS response. It will be called + * @param[in] pcHostName The hostname whose IP address is being queried. + * @param[in] pCallback The callback function which will be called upon DNS response. It will be called * with pcHostName, pvSearchID and pxAddressInfo which points to address info. * The pxAddressInfo should be freed by the application once the callback * has been called by the FreeRTOS_freeaddrinfo(). * In case of timeouts pxAddressInfo can be NULL. - * @param[in] pvSearchID: Search ID for the callback function. - * @param[in] uxTimeout: Timeout for the callback function. + * @param[in] pvSearchID Search ID for the callback function. + * @param[in] uxTimeout Timeout for the callback function. * @return The IP-address corresponding to the hostname. 0 is returned in case of * failure. */ @@ -492,59 +498,71 @@ } #endif /* if ( ipconfigDNS_USE_CALLBACKS == 0 ) */ + #if ( ipconfigINCLUDE_FULL_INET_ADDR == 1 ) + /** * @brief See if pcHostName contains a valid IPv4 or IPv6 IP-address. - * @param[in] pcHostName: The name to be looked up - * @param[in] xFamily: the IP-type, either FREERTOS_AF_INET4 or FREERTOS_AF_INET6. - * @param[in] ppxAddressInfo: A pointer to a pointer where the find results will + * @param[in] pcHostName The name to be looked up + * @param[in] xFamily the IP-type, either FREERTOS_AF_INET4 or FREERTOS_AF_INET6. + * @param[in] ppxAddressInfo A pointer to a pointer where the find results will * be stored. * @return Either 0 or an IP=address. */ - static uint32_t prvPrepare_ReadIPAddress( const char * pcHostName, - BaseType_t xFamily, - struct freertos_addrinfo ** ppxAddressInfo ) - { - uint32_t ulIPAddress = 0U; + static uint32_t prvPrepare_ReadIPAddress( const char * pcHostName, + BaseType_t xFamily, + struct freertos_addrinfo ** ppxAddressInfo ) + { + uint32_t ulIPAddress = 0U; - ( void ) xFamily; + ( void ) xFamily; - /* Check if the hostname given is actually an IP-address. */ - #if ( ipconfigUSE_IPv6 != 0 ) - if( xFamily == FREERTOS_AF_INET6 ) + /* Check if the hostname given is actually an IP-address. */ + switch( xFamily ) /* LCOV_EXCL_BR_LINE - Family is always either FREERTOS_AF_INET or FREERTOS_AF_INET6. */ { - IPv6_Address_t xAddress_IPv6; - BaseType_t xResult; + #if ( ipconfigUSE_IPv4 != 0 ) + case FREERTOS_AF_INET: + ulIPAddress = FreeRTOS_inet_addr( pcHostName ); - /* ulIPAddress does not represent an IPv4 address here. It becomes non-zero when the look-up succeeds. */ - xResult = FreeRTOS_inet_pton6( pcHostName, xAddress_IPv6.ucBytes ); + if( ( ulIPAddress != 0U ) && ( ppxAddressInfo != NULL ) ) + { + const uint8_t * ucBytes = ( uint8_t * ) &( ulIPAddress ); - if( xResult == 1 ) - { - /* This function returns either a valid IPv4 address, or - * in case of an IPv6 lookup, it will return a non-zero */ - ulIPAddress = 1U; + *( ppxAddressInfo ) = pxNew_AddrInfo( pcHostName, FREERTOS_AF_INET4, ucBytes ); + } + break; + #endif /* ( ipconfigUSE_IPv4 != 0 ) */ - if( ppxAddressInfo != NULL ) - { - *( ppxAddressInfo ) = pxNew_AddrInfo( pcHostName, FREERTOS_AF_INET6, xAddress_IPv6.ucBytes ); - } - } + #if ( ipconfigUSE_IPv6 != 0 ) + case FREERTOS_AF_INET6: + { + IPv6_Address_t xAddress_IPv6; + BaseType_t xResult; + + /* ulIPAddress does not represent an IPv4 address here. It becomes non-zero when the look-up succeeds. */ + xResult = FreeRTOS_inet_pton6( pcHostName, xAddress_IPv6.ucBytes ); + + if( xResult == 1 ) + { + /* This function returns either a valid IPv4 address, or + * in case of an IPv6 lookup, it will return a non-zero */ + ulIPAddress = 1U; + + /* ppxAddressInfo is always non-NULL in IPv6 case. */ + *( ppxAddressInfo ) = pxNew_AddrInfo( pcHostName, FREERTOS_AF_INET6, xAddress_IPv6.ucBytes ); + } + } + break; + #endif /* ( ipconfigUSE_IPv6 != 0 ) */ + + default: /* LCOV_EXCL_LINE - Family is always either FREERTOS_AF_INET or FREERTOS_AF_INET6. */ + /* MISRA 16.4 Compliance */ + FreeRTOS_debug_printf( ( "prvPrepare_ReadIPAddress: Undefined xFamily Type \n" ) ); + break; /* LCOV_EXCL_LINE - Family is always either FREERTOS_AF_INET or FREERTOS_AF_INET6. */ } - else - #endif /* ipconfigUSE_IPv6 */ - { - ulIPAddress = FreeRTOS_inet_addr( pcHostName ); - if( ( ulIPAddress != 0U ) && ( ppxAddressInfo != NULL ) ) - { - const uint8_t * ucBytes = ( uint8_t * ) &( ulIPAddress ); - - *( ppxAddressInfo ) = pxNew_AddrInfo( pcHostName, FREERTOS_AF_INET4, ucBytes ); - } + return ulIPAddress; } - - return ulIPAddress; - } + #endif /* ( ipconfigINCLUDE_FULL_INET_ADDR == 1 ) */ /*-----------------------------------------------------------*/ #if ( ipconfigDNS_USE_CALLBACKS == 1 ) @@ -552,14 +570,14 @@ /** * @brief Check if hostname is already known. If not, call prvGetHostByName() to send a DNS request. * - * @param[in] pcHostName: The hostname whose IP address is being queried. - * @param[in,out] ppxAddressInfo: A pointer to a pointer where the find results + * @param[in] pcHostName The hostname whose IP address is being queried. + * @param[in,out] ppxAddressInfo A pointer to a pointer where the find results * will be stored. * @param [in] xFamily indicate what type of record is needed: * FREERTOS_AF_INET4 or FREERTOS_AF_INET6. - * @param[in] pCallbackFunction: The callback function which will be called upon DNS response. - * @param[in] pvSearchID: Search ID for the callback function. - * @param[in] uxTimeout: Timeout for the callback function. + * @param[in] pCallbackFunction The callback function which will be called upon DNS response. + * @param[in] pvSearchID Search ID for the callback function. + * @param[in] uxTimeout Timeout for the callback function. * @return The IP-address corresponding to the hostname. */ static uint32_t prvPrepareLookup( const char * pcHostName, @@ -572,7 +590,7 @@ /** * @brief Check if hostname is already known. If not, call prvGetHostByName() to send a DNS request. - * @param[in] pcHostName: The hostname whose IP address is being queried. + * @param[in] pcHostName The hostname whose IP address is being queried. * @return The IP-address corresponding to the hostname. */ static uint32_t prvPrepareLookup( const char * pcHostName, @@ -605,7 +623,7 @@ } else { - FreeRTOS_printf( ( "prvPrepareLookup: name is too long ( %lu > %lu )\n", + FreeRTOS_printf( ( "prvPrepareLookup: name is too long ( %u > %u )\n", ( unsigned ) uxLength, ( unsigned ) ipconfigDNS_CACHE_NAME_LENGTH ) ); } @@ -619,7 +637,11 @@ { /* If the supplied hostname is an IP address, put it in ppxAddressInfo * and return. */ - ulIPAddress = prvPrepare_ReadIPAddress( pcHostName, xFamily, ppxAddressInfo ); + #if ( ipconfigINCLUDE_FULL_INET_ADDR == 1 ) + { + ulIPAddress = prvPrepare_ReadIPAddress( pcHostName, xFamily, ppxAddressInfo ); + } + #endif /* ipconfigINCLUDE_FULL_INET_ADDR == 1 */ /* If a DNS cache is used then check the cache before issuing another DNS * request. */ @@ -674,7 +696,7 @@ ( xFamily == FREERTOS_AF_INET6 ) ? pdTRUE : pdFALSE ); } } - else if( ppxAddressInfo != NULL ) + else /* When ipconfigDNS_USE_CALLBACKS enabled, ppxAddressInfo is always non null. */ { /* The IP address is known, do the call-back now. */ pCallbackFunction( pcHostName, pvSearchID, *( ppxAddressInfo ) ); @@ -702,7 +724,7 @@ /** * @brief Increment the field 'ucDNSIndex', which is an index in the array * of DNS addresses. - * @param[in] pxEndPoint: The end-point of which the DNS index should be + * @param[in] pxEndPoint The end-point of which the DNS index should be * incremented. */ static void prvIncreaseDNS6Index( NetworkEndPoint_t * pxEndPoint ) @@ -732,37 +754,40 @@ #endif /* ( ipconfigUSE_IPv6 != 0 ) */ /*-----------------------------------------------------------*/ + #if ( ipconfigUSE_IPv4 != 0 ) + /** * @brief Increment the field 'ucDNSIndex', which is an index in the array * of DNS addresses. - * @param[in] pxEndPoint: The end-point of which the DNS index should be + * @param[in] pxEndPoint The end-point of which the DNS index should be * incremented. */ - static void prvIncreaseDNS4Index( NetworkEndPoint_t * pxEndPoint ) - { - uint8_t ucIndex = pxEndPoint->ipv4_settings.ucDNSIndex; - uint8_t ucInitialIndex = ucIndex; - - for( ; ; ) + static void prvIncreaseDNS4Index( NetworkEndPoint_t * pxEndPoint ) { - ucIndex++; + uint8_t ucIndex = pxEndPoint->ipv4_settings.ucDNSIndex; + uint8_t ucInitialIndex = ucIndex; - if( ucIndex >= ( uint8_t ) ipconfigENDPOINT_DNS_ADDRESS_COUNT ) + for( ; ; ) { - ucIndex = 0U; - } + ucIndex++; - if( ( pxEndPoint->ipv4_settings.ulDNSServerAddresses[ ucIndex ] != 0U ) || - ( ucInitialIndex == ucIndex ) ) - { - break; + if( ucIndex >= ( uint8_t ) ipconfigENDPOINT_DNS_ADDRESS_COUNT ) + { + ucIndex = 0U; + } + + if( ( pxEndPoint->ipv4_settings.ulDNSServerAddresses[ ucIndex ] != 0U ) || + ( ucInitialIndex == ucIndex ) ) + { + break; + } } - } - FreeRTOS_printf( ( "prvIncreaseDNS4Index: from %d to %d\n", ( int ) ucInitialIndex, ( int ) ucIndex ) ); - pxEndPoint->ipv4_settings.ucDNSIndex = ucIndex; - } + FreeRTOS_printf( ( "prvIncreaseDNS4Index: from %d to %d\n", ( int ) ucInitialIndex, ( int ) ucIndex ) ); + pxEndPoint->ipv4_settings.ucDNSIndex = ucIndex; + } /*-----------------------------------------------------------*/ + #endif /* #if ( ipconfigUSE_IPv4 != 0 ) */ /*! * @brief create a payload buffer and return it through the parameter @@ -863,19 +888,35 @@ { /* Looking up a name like "mydevice.local". * Use mDNS addresses. */ - pxAddress->sin_addr = ipMDNS_IP_ADDRESS; /* Is in network byte order. */ + pxAddress->sin_port = ipMDNS_PORT; pxAddress->sin_port = FreeRTOS_ntohs( pxAddress->sin_port ); xNeed_Endpoint = pdTRUE; - #if ( ipconfigUSE_IPv6 != 0 ) - if( xDNS_IP_Preference == xPreferenceIPv6 ) - { - memcpy( pxAddress->sin_address.xIP_IPv6.ucBytes, - ipMDNS_IP_ADDR_IPv6.ucBytes, - ipSIZE_OF_IPv6_ADDRESS ); - pxAddress->sin_family = FREERTOS_AF_INET6; - } - #endif + + switch( xDNS_IP_Preference ) + { + #if ( ipconfigUSE_IPv4 != 0 ) + case xPreferenceIPv4: + pxAddress->sin_address.ulIP_IPv4 = ipMDNS_IP_ADDRESS; /* Is in network byte order. */ + /* sin_family is default set to FREERTOS_AF_INET */ + break; + #endif /* ( ipconfigUSE_IPv4 != 0 ) */ + + #if ( ipconfigUSE_IPv6 != 0 ) + case xPreferenceIPv6: + memcpy( pxAddress->sin_address.xIP_IPv6.ucBytes, + ipMDNS_IP_ADDR_IPv6.ucBytes, + ipSIZE_OF_IPv6_ADDRESS ); + pxAddress->sin_family = FREERTOS_AF_INET6; + break; + #endif /* ( ipconfigUSE_IPv6 != 0 ) */ + + default: + /* MISRA 16.4 Compliance */ + xNeed_Endpoint = pdFALSE; + FreeRTOS_debug_printf( ( "prvFillSockAddress: Undefined xDNS_IP_Preference \n" ) ); + break; + } } } #endif /* if ( ipconfigUSE_MDNS == 1 ) */ @@ -885,19 +926,34 @@ if( bHasDot == pdFALSE ) { /* Use LLMNR addressing. */ - pxAddress->sin_addr = ipLLMNR_IP_ADDR; /* Is in network byte order. */ pxAddress->sin_port = ipLLMNR_PORT; pxAddress->sin_port = FreeRTOS_ntohs( pxAddress->sin_port ); xNeed_Endpoint = pdTRUE; - #if ( ipconfigUSE_IPv6 != 0 ) - if( xDNS_IP_Preference == xPreferenceIPv6 ) - { - memcpy( pxAddress->sin_address.xIP_IPv6.ucBytes, - ipLLMNR_IP_ADDR_IPv6.ucBytes, - ipSIZE_OF_IPv6_ADDRESS ); - pxAddress->sin_family = FREERTOS_AF_INET6; - } - #endif + + switch( xDNS_IP_Preference ) + { + #if ( ipconfigUSE_IPv4 != 0 ) + case xPreferenceIPv4: + pxAddress->sin_address.ulIP_IPv4 = ipLLMNR_IP_ADDR; /* Is in network byte order. */ + pxAddress->sin_family = FREERTOS_AF_INET; + break; + #endif /* ( ipconfigUSE_IPv4 != 0 ) */ + + #if ( ipconfigUSE_IPv6 != 0 ) + case xPreferenceIPv6: + memcpy( pxAddress->sin_address.xIP_IPv6.ucBytes, + ipLLMNR_IP_ADDR_IPv6.ucBytes, + ipSIZE_OF_IPv6_ADDRESS ); + pxAddress->sin_family = FREERTOS_AF_INET6; + break; + #endif /* ( ipconfigUSE_IPv6 != 0 ) */ + + default: + /* MISRA 16.4 Compliance */ + xNeed_Endpoint = pdFALSE; + FreeRTOS_debug_printf( ( "prvFillSockAddress: Undefined xDNS_IP_Preference (LLMNR) \n" ) ); + break; + } } } #endif /* if ( ipconfigUSE_LLMNR == 1 ) */ @@ -912,17 +968,19 @@ #if ( ipconfigUSE_IPv6 != 0 ) if( xDNS_IP_Preference == xPreferenceIPv6 ) { - if( ENDPOINT_IS_IPv6( pxEndPoint ) ) + if( pxEndPoint->bits.bIPv6 != 0U ) { break; } } else { - if( ENDPOINT_IS_IPv4( pxEndPoint ) ) - { - break; - } + #if ( ipconfigUSE_IPv4 != 0 ) + if( pxEndPoint->bits.bIPv6 == 0U ) + { + break; + } + #endif /* if ( ipconfigUSE_IPv4 != 0 ) */ } #else /* if ( ipconfigUSE_IPv6 != 0 ) */ /* IPv6 is not included, so all end-points are IPv4. */ @@ -934,47 +992,67 @@ } else { + BaseType_t xBreakLoop = pdFALSE; + /* Look for an end-point that has defined a DNS server address. */ for( pxEndPoint = FreeRTOS_FirstEndPoint( NULL ); pxEndPoint != NULL; pxEndPoint = FreeRTOS_NextEndPoint( NULL, pxEndPoint ) ) { - #if ( ipconfigUSE_IPv6 != 0 ) - if( ( xDNS_IP_Preference == xPreferenceIPv6 ) && ENDPOINT_IS_IPv6( pxEndPoint ) ) - { - uint8_t ucIndex = pxEndPoint->ipv6_settings.ucDNSIndex; - configASSERT( ucIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT ); - const uint8_t * ucBytes = pxEndPoint->ipv6_settings.xDNSServerAddresses[ ucIndex ].ucBytes; + switch( xDNS_IP_Preference ) + { + #if ( ipconfigUSE_IPv4 != 0 ) + case xPreferenceIPv4: - /* Test if the DNS entry is in used. */ - if( ( ucBytes[ 0 ] != 0U ) && ( ucBytes[ 1 ] != 0U ) ) - { - pxAddress->sin_family = FREERTOS_AF_INET6; - pxAddress->sin_len = ( uint8_t ) sizeof( struct freertos_sockaddr ); - ( void ) memcpy( pxAddress->sin_addr6.ucBytes, - pxEndPoint->ipv6_settings.xDNSServerAddresses[ ucIndex ].ucBytes, - ipSIZE_OF_IPv6_ADDRESS ); + if( pxEndPoint->bits.bIPv6 == 0U ) + { + uint8_t ucIndex = pxEndPoint->ipv4_settings.ucDNSIndex; + configASSERT( ucIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT ); + uint32_t ulIPAddress = pxEndPoint->ipv4_settings.ulDNSServerAddresses[ ucIndex ]; + + if( ( ulIPAddress != 0U ) && ( ulIPAddress != ipBROADCAST_IP_ADDRESS ) ) + { + pxAddress->sin_family = FREERTOS_AF_INET; + pxAddress->sin_len = ( uint8_t ) sizeof( struct freertos_sockaddr ); + pxAddress->sin_address.ulIP_IPv4 = ulIPAddress; + xBreakLoop = pdTRUE; + } + } break; - } - } - else if( ( xDNS_IP_Preference == xPreferenceIPv4 ) && ENDPOINT_IS_IPv4( pxEndPoint ) ) - #endif /* if ( ipconfigUSE_IPv6 != 0 ) */ - { - uint8_t ucIndex = pxEndPoint->ipv4_settings.ucDNSIndex; - configASSERT( ucIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT ); - uint32_t ulIPAddress = pxEndPoint->ipv4_settings.ulDNSServerAddresses[ ucIndex ]; + #endif /* ( ipconfigUSE_IPv4 != 0 ) */ - if( ( ulIPAddress != 0U ) && ( ulIPAddress != ipBROADCAST_IP_ADDRESS ) ) - { - pxAddress->sin_family = FREERTOS_AF_INET; - pxAddress->sin_len = ( uint8_t ) sizeof( struct freertos_sockaddr ); - pxAddress->sin_addr = ulIPAddress; + #if ( ipconfigUSE_IPv6 != 0 ) + case xPreferenceIPv6: + + if( pxEndPoint->bits.bIPv6 != 0U ) + { + uint8_t ucIndex = pxEndPoint->ipv6_settings.ucDNSIndex; + configASSERT( ucIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT ); + const uint8_t * ucBytes = pxEndPoint->ipv6_settings.xDNSServerAddresses[ ucIndex ].ucBytes; + + /* Test if the DNS entry is in used. */ + if( ( ucBytes[ 0 ] != 0U ) && ( ucBytes[ 1 ] != 0U ) ) + { + pxAddress->sin_family = FREERTOS_AF_INET6; + pxAddress->sin_len = ( uint8_t ) sizeof( struct freertos_sockaddr ); + ( void ) memcpy( pxAddress->sin_address.xIP_IPv6.ucBytes, + pxEndPoint->ipv6_settings.xDNSServerAddresses[ ucIndex ].ucBytes, + ipSIZE_OF_IPv6_ADDRESS ); + xBreakLoop = pdTRUE; + } + } + break; + #endif /* ( ipconfigUSE_IPv6 != 0 ) */ + + default: + /* MISRA 16.4 Compliance */ + FreeRTOS_debug_printf( ( "prvFillSockAddress: Undefined xDNS_IP_Preference \n" ) ); break; - } } - else + + if( xBreakLoop == pdTRUE ) { - /* do nothing, coverity happy */ + break; } } } @@ -985,7 +1063,7 @@ /*! * @brief return ip address from the dns reply message * @param [in] pxReceiveBuffer received buffer from the DNS server - * @param[in,out] ppxAddressInfo: A pointer to a pointer where the find results + * @param[in,out] ppxAddressInfo A pointer to a pointer where the find results * will be stored. * @param [in] uxIdentifier matches sent and received packets * @param [in] usPort Port from which DNS reply was read @@ -1001,7 +1079,7 @@ BaseType_t xExpected; /* MISRA Ref 11.3.1 [Misaligned access] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* 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 DNSMessage_t * pxDNSMessageHeader = ( ( const DNSMessage_t * ) @@ -1047,7 +1125,7 @@ /*! * @brief prepare the buffer before sending - * @param [in] pcHostName + * @param [in] pcHostName hostname to be looked up * @param [in] uxIdentifier matches sent and received packets * @param [in] xDNSSocket a valid socket * @param [in] xFamily indicate what type of record is needed: @@ -1127,7 +1205,7 @@ uxHostType ); /* ipLLMNR_IP_ADDR is in network byte order. */ - if( ( pxAddress->sin_addr == ipLLMNR_IP_ADDR ) || ( pxAddress->sin_addr == ipMDNS_IP_ADDRESS ) ) + if( ( pxAddress->sin_address.ulIP_IPv4 == ipLLMNR_IP_ADDR ) || ( pxAddress->sin_address.ulIP_IPv4 == ipMDNS_IP_ADDRESS ) ) { /* Use LLMNR addressing. */ /* MISRA Ref 11.3.1 [Misaligned access] */ @@ -1155,9 +1233,9 @@ * @param [in] pcHostName hostname to get its ip address * @param [in] uxIdentifier Identifier to match sent and received packets * @param [in] xDNSSocket socket - * @param[in,out] ppxAddressInfo: A pointer to a pointer where the find results + * @param[in,out] ppxAddressInfo A pointer to a pointer where the find results * will be stored. - * @param[in] xFamily: Either FREERTOS_AF_INET4 or FREERTOS_AF_INET6. + * @param[in] xFamily Either FREERTOS_AF_INET4 or FREERTOS_AF_INET6. * @param[in] uxReadTimeOut_ticks The timeout in ticks for waiting. In case the user has supplied * a call-back function, this value should be zero. * @returns ip address or zero on error @@ -1180,10 +1258,12 @@ /* Make sure all fields of the 'sockaddr' are cleared. */ ( void ) memset( ( void * ) &xAddress, 0, sizeof( xAddress ) ); - if( xFamily == ( BaseType_t ) FREERTOS_AF_INET6 ) - { - xDNS_IP_Preference = xPreferenceIPv6; - } + #if ( ipconfigUSE_IPv6 != 0 ) + if( xFamily == ( BaseType_t ) FREERTOS_AF_INET6 ) + { + xDNS_IP_Preference = xPreferenceIPv6; + } + #endif /* ( ipconfigUSE_IPv6 != 0 ) */ pxEndPoint = prvFillSockAddress( &xAddress, pcHostName ); @@ -1233,15 +1313,24 @@ ( xBytes == 0 ) ) ) { /* This search timed out, next time try with a different DNS. */ - #if ( ipconfigUSE_IPv6 != 0 ) - if( xAddress.sin_family == ( uint8_t ) FREERTOS_AF_INET6 ) - { - prvIncreaseDNS6Index( pxEndPoint ); - } - else - #endif + switch( xAddress.sin_family ) /* LCOV_EXCL_BR_LINE - This is filled by static function, default case is impossible to reach. */ { - prvIncreaseDNS4Index( pxEndPoint ); + #if ( ipconfigUSE_IPv4 != 0 ) + case FREERTOS_AF_INET: + prvIncreaseDNS4Index( pxEndPoint ); + break; + #endif /* ( ipconfigUSE_IPv4 != 0 ) */ + + #if ( ipconfigUSE_IPv6 != 0 ) + case FREERTOS_AF_INET6: + prvIncreaseDNS6Index( pxEndPoint ); + break; + #endif /* ( ipconfigUSE_IPv6 != 0 ) */ + + default: /* LCOV_EXCL_LINE - This is filled by static function, default case is impossible to reach. */ + /* MISRA 16.4 Compliance */ + FreeRTOS_debug_printf( ( "prvGetHostByNameOp: Undefined sin_family \n" ) ); + break; /* LCOV_EXCL_LINE - This is filled by static function, default case is impossible to reach. */ } } @@ -1276,9 +1365,9 @@ * @param [in] pcHostName hostname to get its ip address * @param [in] uxIdentifier Identifier to match sent and received packets * @param [in] xDNSSocket socket - * @param[in,out] ppxAddressInfo: A pointer to a pointer where the find results + * @param[in,out] ppxAddressInfo A pointer to a pointer where the find results * will be stored. - * @param[in] xFamily: Either FREERTOS_AF_INET4 or FREERTOS_AF_INET6. + * @param[in] xFamily Either FREERTOS_AF_INET4 or FREERTOS_AF_INET6. * @param[in] uxReadTimeOut_ticks The timeout in ticks for waiting. In case the user has supplied * a call-back function, this value should be zero. * @returns ip address or zero on error @@ -1291,7 +1380,7 @@ BaseType_t xFamily, TickType_t uxReadTimeOut_ticks ) { - uint32_t ulIPAddress; + uint32_t ulIPAddress = 0; BaseType_t xAttempt; for( xAttempt = 0; xAttempt < ipconfigDNS_REQUEST_ATTEMPTS; xAttempt++ ) @@ -1321,9 +1410,9 @@ * @param[in] uxIdentifier Identifier to match sent and received packets * @param[in] uxReadTimeOut_ticks The timeout in ticks for waiting. In case the user has supplied * a call-back function, this value should be zero. - * @param[in,out] ppxAddressInfo: A pointer to a pointer where the find results + * @param[in,out] ppxAddressInfo A pointer to a pointer where the find results * will be stored. - * @param[in] xFamily: Either FREERTOS_AF_INET4 or FREERTOS_AF_INET6. + * @param[in] xFamily Either FREERTOS_AF_INET4 or FREERTOS_AF_INET6. * @return The IPv4 IP address for the hostname being queried. It will be zero if there is no reply. */ static uint32_t prvGetHostByName( const char * pcHostName, @@ -1373,7 +1462,7 @@ * @param[in,out] pucUDPPayloadBuffer The zero copy buffer where the DNS message will be created. * @param[in] pcHostName Hostname to be looked up. * @param[in] uxIdentifier Identifier to match sent and received packets - * @param[in] uxHostType: dnsTYPE_A_HOST ( IPv4 ) or dnsTYPE_AAAA_HOST ( IPv6 ). + * @param[in] uxHostType dnsTYPE_A_HOST ( IPv4 ) or dnsTYPE_AAAA_HOST ( IPv6 ). * @return Total size of the generated message, which is the space from the last written byte * to the beginning of the buffer. */ @@ -1417,7 +1506,7 @@ * to easily access fields of the DNS Message. */ /* MISRA Ref 11.3.1 [Misaligned access] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSMessageHeader = ( ( DNSMessage_t * ) pucUDPPayloadBuffer ); pxDNSMessageHeader->usIdentifier = ( uint16_t ) uxIdentifier; @@ -1462,7 +1551,7 @@ * access the fields of the DNS Message. */ /* MISRA Ref 11.3.1 [Misaligned access] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxTail = ( ( DNSTail_t * ) &( pucUDPPayloadBuffer[ uxStart + 1U ] ) ); @@ -1488,7 +1577,7 @@ /** * @brief Perform some preliminary checks and then parse the DNS packet. - * @param[in] pxNetworkBuffer: The network buffer to be parsed. + * @param[in] pxNetworkBuffer The network buffer to be parsed. * @return Always pdFAIL to indicate that the packet was not consumed and must * be released by the caller. */ @@ -1533,7 +1622,7 @@ /** * @brief Handle an NBNS packet. - * @param[in] pxNetworkBuffer: The network buffer holding the NBNS packet. + * @param[in] pxNetworkBuffer The network buffer holding the NBNS packet. * @return pdFAIL to show that the packet was not consumed. */ uint32_t ulNBNSHandlePacket( NetworkBufferDescriptor_t * pxNetworkBuffer ) diff --git a/source/include/FreeRTOSIPConfigDefaults.h b/source/include/FreeRTOSIPConfigDefaults.h index 9b686f7e1d..7fff724989 100644 --- a/source/include/FreeRTOSIPConfigDefaults.h +++ b/source/include/FreeRTOSIPConfigDefaults.h @@ -1,6 +1,6 @@ /* * FreeRTOS+TCP - * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * SPDX-License-Identifier: MIT * @@ -28,7 +28,7 @@ /** * @file FreeRTOSIPConfigDefaults.h * @brief File that provides default values for configuration options that are - * missing from FreeRTOSIPConfig.h. The complete documentation of the + * missing from FreeRTOSIPConfig.h. The complete documentation of the * configuration parameters can be found here: * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html */ @@ -46,6 +46,8 @@ #include "FreeRTOSIPDeprecatedDefinitions.h" +#include + /*===========================================================================*/ /*---------------------------------------------------------------------------*/ /*===========================================================================*/ @@ -57,6 +59,7 @@ /* * Used to define away static keyword for CBMC proofs */ + #ifndef _static #define _static static #endif @@ -65,23 +68,49 @@ /* * Since all code is made compatible with the MISRA rules, the inline functions - * disappear. Normally defined in portmacro.h or FreeRTOSConfig.h. + * disappear. Normally defined in portmacro.h or FreeRTOSConfig.h. */ + #ifndef portINLINE #define portINLINE inline #endif /*---------------------------------------------------------------------------*/ +/* + * Used to standardize macro checks since ( MACRO == 1 ) and ( MACRO != 0 ) + * are used inconsistently. + */ + +#ifndef ipconfigENABLE + #define ipconfigENABLE 1 +#endif + +#ifndef ipconfigDISABLE + #define ipconfigDISABLE 0 +#endif + +#ifndef ipconfigIS_ENABLED + #define ipconfigIS_ENABLED( x ) ( x != ipconfigDISABLE ) +#endif + +#ifndef ipconfigIS_DISABLED + #define ipconfigIS_DISABLED( x ) ( x == ipconfigDISABLE ) +#endif + +/*---------------------------------------------------------------------------*/ + /* * pdFREERTOS_ERRNO_EAFNOSUPPORT * * Address family not supported by protocol. * - * Note: To be removed when added to projdefs.h in FreeRTOS-Kernel + * Note: Now included in FreeRTOS-Kernel/projdefs.h, so this serves as a + * temporary kernel version check. To be removed in a future version. */ + #ifndef pdFREERTOS_ERRNO_EAFNOSUPPORT - #define pdFREERTOS_ERRNO_EAFNOSUPPORT 97 + #error Missing pdFREERTOS_ERRNO_EAFNOSUPPORT definition, please update FreeRTOS-Kernel #endif /*---------------------------------------------------------------------------*/ @@ -101,11 +130,17 @@ /* * ipconfigIPv4_BACKWARD_COMPATIBLE * - * If defined this macro enables the APIs that are backward compatible - * with single end point IPv4 version of the FreeRTOS+TCP library. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables the APIs that are backward compatible with single end point IPv4. */ + #ifndef ipconfigIPv4_BACKWARD_COMPATIBLE - #define ipconfigIPv4_BACKWARD_COMPATIBLE 0 + #define ipconfigIPv4_BACKWARD_COMPATIBLE ipconfigDISABLE +#endif + +#if ( ( ipconfigIPv4_BACKWARD_COMPATIBLE != ipconfigDISABLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE != ipconfigENABLE ) ) + #error ipconfigIPv4_BACKWARD_COMPATIBLE should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -113,11 +148,19 @@ /* * ipconfigUSE_IPv4 * - * Include all API's and code that is needed for the IPv4 protocol. - * When defined as zero, the application should uses IPv6. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Include support for the IPv4 protocol. + * + * If disabled, the application must enable IPv6. */ + #ifndef ipconfigUSE_IPv4 - #define ipconfigUSE_IPv4 1 + #define ipconfigUSE_IPv4 ipconfigENABLE +#endif + +#if ( ( ipconfigUSE_IPv4 != ipconfigDISABLE ) && ( ipconfigUSE_IPv4 != ipconfigENABLE ) ) + #error ipconfigUSE_IPv4 should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -125,106 +168,213 @@ /* * ipconfigUSE_IPv6 * - * Include all API's and code that is needed for the IPv6 protocol. - * When defined as zero, the application should uses IPv4. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Include support for the IPv6 protocol. + * + * If disabled, the application must enable IPv4. */ + #ifndef ipconfigUSE_IPv6 - #define ipconfigUSE_IPv6 1 + #define ipconfigUSE_IPv6 ipconfigENABLE +#endif + +#if ( ( ipconfigUSE_IPv6 != ipconfigDISABLE ) && ( ipconfigUSE_IPv6 != ipconfigENABLE ) ) + #error ipconfigUSE_IPv6 should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ -#if ( ipconfigUSE_IPv4 == 0 ) || ( ipconfigUSE_IPv6 == 0 ) - #error "Build separation for both IPv4 and IPv6 is work in progress. \ - Please enable both ipconfigUSE_IPv4 and ipconfigUSE_IPv6 flags." +#if ( ipconfigIS_DISABLED( ipconfigUSE_IPv4 ) || ipconfigIS_DISABLED( ipconfigUSE_IPv6 ) ) + #error Build separation for both IPv4 & IPv6 is work in progress. Please enable both ipconfigUSE_IPv4 & ipconfigUSE_IPv6 #endif /*---------------------------------------------------------------------------*/ -#if ( ipconfigUSE_IPv6 != 0 ) +#if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) ) + +/*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ +/* + * ipconfigND_CACHE_ENTRIES + * + * Type: size_t + * Unit: length of NDCacheRow_t array + * Minimum: 1 + * + * Maximum number of entries in the Neighbour Discovery cache of IPv6 addresses + * & MAC addresses + */ - /* - * ipconfigND_CACHE_ENTRIES - */ #ifndef ipconfigND_CACHE_ENTRIES - #define ipconfigND_CACHE_ENTRIES 24U + #define ipconfigND_CACHE_ENTRIES 24 + #endif + + #if ( ipconfigND_CACHE_ENTRIES < 1 ) + #error ipconfigND_CACHE_ENTRIES must be at least 1 + #endif + + #if ( ipconfigND_CACHE_ENTRIES > SIZE_MAX ) + #error ipconfigND_CACHE_ENTRIES overflows a size_t #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigUSE_RA + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Include support for Router Advertisement (RA). + */ - /* - * ipconfigUSE_RA - */ #ifndef ipconfigUSE_RA - #define ipconfigUSE_RA 1 + #define ipconfigUSE_RA ipconfigENABLE + #endif + + #if ( ( ipconfigUSE_RA != ipconfigDISABLE ) && ( ipconfigUSE_RA != ipconfigENABLE ) ) + #error ipconfigUSE_RA should be pdFALSE or pdTRUE #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ + + #if ( ipconfigIS_ENABLED( ipconfigUSE_RA ) ) - #if ( ipconfigUSE_RA != 0 ) +/*-------------------------------------------------------------------*/ - /*-------------------------------------------------------------------*/ +/* + * ipconfigRA_SEARCH_COUNT + * + * Type: UBaseType_t + * Minimum: 0 + * + * Sets the amount of times a router solicitation message can + * be retransmitted after timing out. + */ - /* - * ipconfigRA_SEARCH_COUNT - * - * RA or Router Advertisement/SLAAC: see end-point flag 'bWantRA'. - * An Router Solicitation will be sent. It will wait for - * ipconfigRA_SEARCH_TIME_OUT_MSEC ms. When there is no response, it - * will be repeated ipconfigRA_SEARCH_COUNT times. Then it will be - * checked if the chosen IP-address already exists, repeating this - * ipconfigRA_IP_TEST_COUNT times, each time with a timeout of - * ipconfigRA_IP_TEST_TIME_OUT_MSEC ms. Finally the end-point will go - * in the UP state. - */ #ifndef ipconfigRA_SEARCH_COUNT #define ipconfigRA_SEARCH_COUNT 3U #endif - /*-------------------------------------------------------------------*/ + #if ( ipconfigRA_SEARCH_COUNT < 0 ) + #error ipconfigRA_SEARCH_COUNT must be at least 0 + #endif + + #if ( ipconfigRA_SEARCH_COUNT > UINT_FAST8_MAX ) + #error ipconfigRA_SEARCH_COUNT overflows a UBaseType_t + #endif + +/*-------------------------------------------------------------------*/ + +/* + * ipconfigRA_SEARCH_TIME_OUT_MSEC + * + * Type: TickType_t + * Unit: milliseconds + * Minimum: 0 + * Maximum: portMAX_DELAY * portTICK_PERIOD_MS + * + * Sets the timeout to wait for a response to a router + * solicitation message. + */ - /* - * ipconfigRA_SEARCH_TIME_OUT_MSEC - */ #ifndef ipconfigRA_SEARCH_TIME_OUT_MSEC #define ipconfigRA_SEARCH_TIME_OUT_MSEC 10000U #endif - /*-------------------------------------------------------------------*/ + #if ( ipconfigRA_SEARCH_TIME_OUT_MSEC < 0 ) + #error ipconfigRA_SEARCH_TIME_OUT_MSEC must be at least 0 + #endif + + #if ( ipconfigRA_SEARCH_TIME_OUT_MSEC > SIZE_MAX ) + #error ipconfigRA_SEARCH_TIME_OUT_MSEC must be at most portMAX_DELAY * portTICK_PERIOD_MS + #endif + +/*-------------------------------------------------------------------*/ + +/* + * ipconfigRA_IP_TEST_COUNT + * + * Type: UBaseType_t + * Unit: max iterations of RA wait state process + * Minimum: 0 + * + * Sets the amount of times a neighbour solicitation message can be + * retransmitted after timing out. + */ - /* - * ipconfigRA_IP_TEST_COUNT - */ #ifndef ipconfigRA_IP_TEST_COUNT #define ipconfigRA_IP_TEST_COUNT 3U #endif - /*-------------------------------------------------------------------*/ + #if ( ipconfigRA_IP_TEST_COUNT < 0 ) + #error ipconfigRA_IP_TEST_COUNT must be at least 0 + #endif + + #if ( ipconfigRA_IP_TEST_COUNT > UINT_FAST8_MAX ) + #error ipconfigRA_IP_TEST_COUNT overflows a UBaseType_t + #endif + +/*-------------------------------------------------------------------*/ + +/* + * ipconfigRA_IP_TEST_TIME_OUT_MSEC + * + * Type: TickType_t + * Unit: milliseconds + * Minimum: 0 + * Maximum: portMAX_DELAY * portTICK_PERIOD_MS + * + * Sets the timeout to wait for a response to a neighbour solicitation message. + */ - /* - * ipconfigRA_IP_TEST_TIME_OUT_MSEC - */ #ifndef ipconfigRA_IP_TEST_TIME_OUT_MSEC #define ipconfigRA_IP_TEST_TIME_OUT_MSEC 1500U #endif - /*-------------------------------------------------------------------*/ + #if ( ipconfigRA_IP_TEST_TIME_OUT_MSEC < 0 ) + #error ipconfigRA_IP_TEST_TIME_OUT_MSEC must be at least 0 + #endif + + #if ( ipconfigRA_IP_TEST_TIME_OUT_MSEC > SIZE_MAX ) + #error ipconfigRA_IP_TEST_TIME_OUT_MSEC must be at most portMAX_DELAY * portTICK_PERIOD_MS + #endif + +/*-------------------------------------------------------------------*/ - #endif /* if ( ipconfigUSE_RA != 0 ) */ + #endif /* if ( ipconfigIS_ENABLED( ipconfigUSE_RA ) ) */ - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ -#endif /* if ( ipconfigUSE_IPv6 != 0 ) */ +#endif /* if ( ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) ) */ /*---------------------------------------------------------------------------*/ /* * ipconfigENDPOINT_DNS_ADDRESS_COUNT + * + * Type: uint8_t + * Unit: max count of IP addresses of DNS servers + * Minimum: 1 + * + * Sets the length of the array of addresses of Domain Name Servers for each + * endpoint. + * + * The field ucDNSIndex in the IP parameters of a NetworkEndPoint_t will point + * to the DNS in use. When a DNS times out, ucDNSIndex will be moved to the + * next available DNS. */ + #ifndef ipconfigENDPOINT_DNS_ADDRESS_COUNT - #define ipconfigENDPOINT_DNS_ADDRESS_COUNT 2U + #define ipconfigENDPOINT_DNS_ADDRESS_COUNT UINT8_C( 2 ) +#endif + +#if ( ipconfigENDPOINT_DNS_ADDRESS_COUNT < 1 ) + #error ipconfigENDPOINT_DNS_ADDRESS_COUNT must be at least 1 +#endif + +#if ( ipconfigENDPOINT_DNS_ADDRESS_COUNT > UINT8_MAX ) + #error ipconfigENDPOINT_DNS_ADDRESS_COUNT overflows a uint8_t #endif /*---------------------------------------------------------------------------*/ @@ -234,17 +384,24 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigFORCE_IP_DONT_FRAGMENT * - * This macro is about IP-fragmentation. When sending an IP-packet over the - * Internet, a big packet may be split up into smaller parts which are then - * combined by the receiver. The sender can determine if this fragmentation is - * allowed or not. ipconfigFORCE_IP_DONT_FRAGMENT is zero by default, which - * means that fragmentation is allowed. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Sets the ipFRAGMENT_FLAGS_DONT_FRAGMENT flag in an IP header. + * + * When sending an IP-packet over the internet, a big packet may be split up + * into smaller parts which are then combined by the receiver. The sender can + * determine if this fragmentation is allowed or not. * * Note that the FreeRTOS-Plus-TCP stack does not accept received fragmented * packets. */ + #ifndef ipconfigFORCE_IP_DONT_FRAGMENT - #define ipconfigFORCE_IP_DONT_FRAGMENT 0 + #define ipconfigFORCE_IP_DONT_FRAGMENT ipconfigDISABLE +#endif + +#if ( ( ipconfigFORCE_IP_DONT_FRAGMENT != ipconfigDISABLE ) && ( ipconfigFORCE_IP_DONT_FRAGMENT != ipconfigENABLE ) ) + #error ipconfigFORCE_IP_DONT_FRAGMENT should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -254,15 +411,17 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS * - * If ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS is set to 1, then - * FreeRTOS-Plus-TCP accepts IP packets that contain IP options, but does not - * process the options (IP options are not supported). + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) * - * If ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS is set to 0, then - * FreeRTOS-Plus-TCP will drop IP packets that contain IP options. + * Determines if IP packets with IP options are accepted (but not processed). */ + #ifndef ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS - #define ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS 1 + #define ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS ipconfigENABLE +#endif + +#if ( ( ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS != ipconfigDISABLE ) && ( ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS != ipconfigENABLE ) ) + #error ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -284,6 +443,10 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigBUFFER_PADDING * + * Type: size_t + * Unit: bytes + * Minimum: 0 + * * Advanced driver implementation use only. * * When the application requests a network buffer, the size of the network @@ -292,45 +455,64 @@ * first ipconfigBUFFER_PADDING bytes of the buffer is then used to hold * metadata about the buffer, and the area that actually stores the data * follows the metadata. This mechanism is transparent to the user as the user - * only see a pointer to the area within the buffer actually used to hold + * only sees a pointer to the area within the buffer actually used to hold * network data. * * Some network hardware has very specific byte alignment requirements, so * ipconfigBUFFER_PADDING is provided as a configurable parameter to allow the * writer of the network driver to influence the alignment of the start of the * data that follows the metadata. + * + * When defined as zero ( default ), the driver will determine the optimal + * padding as: + * + * #define ipBUFFER_PADDING ( 8U + ipconfigPACKET_FILLER_SIZE ) + * + * See ipconfigPACKET_FILLER_SIZE. */ + #ifndef ipconfigBUFFER_PADDING #define ipconfigBUFFER_PADDING 0U #endif +#if ( ipconfigBUFFER_PADDING < 0 ) + #error ipconfigBUFFER_PADDING must be at least 0 +#endif + +#if ( ipconfigBUFFER_PADDING > SIZE_MAX ) + #error ipconfigBUFFER_PADDING overflows a size_t +#endif + /*---------------------------------------------------------------------------*/ /* * ipconfigPACKET_FILLER_SIZE * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigBUFFER_PADDING - * - * Advanced driver implementation use only. + * Type: size_t + * Unit: bytes + * Minimum: 0 * - * When the application requests a network buffer, the size of the network - * buffer is specified by the application writer, but the size of the network - * buffer actually obtained is increased by ipconfigBUFFER_PADDING bytes. The - * first ipconfigBUFFER_PADDING bytes of the buffer is then used to hold - * metadata about the buffer, and the area that actually stores the data - * follows the metadata. This mechanism is transparent to the user as the user - * only see a pointer to the area within the buffer actually used to hold - * network data. + * In most projects, network buffers are 32-bit aligned plus 16 bits. + * The two extra bytes are called "filler bytes". They make sure that the + * IP-header starts at a 32-bit aligned address. That makes the code + * very efficient and easy to maintain. An 'uint32_t' can be assigned/ + * changed without having to worry about alignment. * - * Some network hardware has very specific byte alignment requirements, so - * ipconfigBUFFER_PADDING is provided as a configurable parameter to allow the - * writer of the network driver to influence the alignment of the start of the - * data that follows the metadata. + * See ipconfigBUFFER_PADDING. */ + #ifndef ipconfigPACKET_FILLER_SIZE #define ipconfigPACKET_FILLER_SIZE 2U #endif +#if ( ipconfigPACKET_FILLER_SIZE < 0 ) + #error ipconfigPACKET_FILLER_SIZE must be at least 0 +#endif + +#if ( ipconfigPACKET_FILLER_SIZE > SIZE_MAX ) + #error ipconfigPACKET_FILLER_SIZE overflows a size_t +#endif + /*---------------------------------------------------------------------------*/ /* @@ -338,6 +520,8 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigBYTE_ORDER * + * Type: BaseType_t ( pdFREERTOS_LITTLE_ENDIAN | pdFREERTOS_BIG_ENDIAN ) + * * If the microcontroller on which FreeRTOS-Plus-TCP is running is big endian * then ipconfigBYTE_ORDER must be set to pdFREERTOS_BIG_ENDIAN. If the * microcontroller is little endian then ipconfigBYTE_ORDER must be set to @@ -345,8 +529,13 @@ * Networking Basics and Glossary page provides an explanation of byte order * considerations in IP networks. */ + #ifndef ipconfigBYTE_ORDER - #error The macro 'ipconfigBYTE_ORDER' must be defined at this point + #error ipconfigBYTE_ORDER must be defined +#endif + +#if ( ( ipconfigBYTE_ORDER != pdFREERTOS_LITTLE_ENDIAN ) && ( ipconfigBYTE_ORDER != pdFREERTOS_BIG_ENDIAN ) ) + #error ipconfigBYTE_ORDER should be pdFREERTOS_LITTLE_ENDIAN or pdFREERTOS_BIG_ENDIAN #endif /*---------------------------------------------------------------------------*/ @@ -356,19 +545,26 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * * If the network driver or network hardware is calculating the IP, TCP and UDP * checksums of incoming packets, and discarding packets that are found to * contain invalid checksums, then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM * to 1, otherwise set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 0. * * Throughput and processor load are greatly improved by implementing drivers - * that make use of hardware checksum calculations. + * that make use of hardware checksum calculations, so-called "checksum offloading". * * Note: From FreeRTOS-Plus-TCP V2.3.0, the length is checked in software even * when it has already been checked in hardware. */ + #ifndef ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM - #define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 0 + #define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM ipconfigDISABLE +#endif + +#if ( ( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM != ipconfigDISABLE ) && ( ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM != ipconfigENABLE ) ) + #error ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -378,6 +574,8 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * * If the network driver or network hardware is calculating the IP, TCP and UDP * checksums of outgoing packets then set * ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM to 1, otherwise set @@ -386,8 +584,13 @@ * Throughput and processor load are greatly improved by implementing drivers * that make use of hardware checksum calculations. */ + #ifndef ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM - #define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM 0 + #define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM ipconfigDISABLE +#endif + +#if ( ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM != ipconfigDISABLE ) && ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM != ipconfigENABLE ) ) + #error ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -403,6 +606,8 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * * Ethernet/hardware MAC addresses are used to address Ethernet frames. If the * network driver or hardware is discarding packets that do not contain a MAC * address of interest then set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to @@ -418,7 +623,11 @@ */ #ifndef ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES - #define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1 + #define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES ipconfigENABLE +#endif + +#if ( ( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES != ipconfigDISABLE ) && ( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES != ipconfigENABLE ) ) + #error ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -434,6 +643,8 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigETHERNET_DRIVER_FILTERS_PACKETS * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * * For expert users only. * * Whereas ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is used to specify @@ -451,31 +662,36 @@ * xPortHasUDPSocket() can be used as follows: * * if( ( xPortHasUdpSocket( xUDPHeader->usDestinationPort ) ) - * #if( ipconfigUSE_DNS == 1 )/* DNS is also UDP. * + * #if( ipconfigUSE_DNS == 1 ) * DNS is also UDP. * * || ( xUDPHeader->usSourcePort == FreeRTOS_ntohs( ipDNS_PORT ) ) * #endif - * #if( ipconfigUSE_LLMNR == 1 ) /* LLMNR is also UDP. * + * #if( ipconfigUSE_LLMNR == 1 ) * LLMNR is also UDP. * * || ( xUDPHeader->usDestinationPort == FreeRTOS_ntohs( ipLLMNR_PORT ) ) * #endif - * #if( ipconfigUSE_NBNS == 1 ) /* NBNS is also UDP. * + * #if( ipconfigUSE_NBNS == 1 ) * NBNS is also UDP. * * || ( xUDPHeader->usDestinationPort == FreeRTOS_ntohs( ipNBNS_PORT ) ) * #endif * ) * { - * /* Forward packet to the IP-stack. * + * * Forward packet to the IP-stack. * * } * else * { - * /* Discard the UDP packet. * + * * Discard the UDP packet. * * } * * When disabled, the IP-task will perform sanity checks on the IP-header, * also checking the target IP address. Also when disabled, xPortHasUDPSocket() - * won't be included. That means that the IP-task can access the + * won't be included. That means that the IP-task can access the * 'xBoundUDPSocketsList' without locking. */ + #ifndef ipconfigETHERNET_DRIVER_FILTERS_PACKETS - #define ipconfigETHERNET_DRIVER_FILTERS_PACKETS 0 + #define ipconfigETHERNET_DRIVER_FILTERS_PACKETS ipconfigDISABLE +#endif + +#if ( ( ipconfigETHERNET_DRIVER_FILTERS_PACKETS != ipconfigDISABLE ) && ( ipconfigETHERNET_DRIVER_FILTERS_PACKETS != ipconfigENABLE ) ) + #error ipconfigETHERNET_DRIVER_FILTERS_PACKETS should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -485,41 +701,62 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigETHERNET_MINIMUM_PACKET_BYTES * + * Type: size_t + * Unit: minimum size of packet in bytes + * Minimum: 0 + * * When the device is connected to a LAN, it is strongly recommended to give * each outgoing packet a minimum length of 60 bytes (plus 4 bytes CRC). The * macro ipconfigETHERNET_MINIMUM_PACKET_BYTES determines the minimum length. * By default, it is defined as zero, meaning that packets will be sent as they - * are. + * are. A minimum packet length is needed to be able to detect collisions of + * short packets as well. By default, packets of any size can be sent. */ + #ifndef ipconfigETHERNET_MINIMUM_PACKET_BYTES #define ipconfigETHERNET_MINIMUM_PACKET_BYTES 0U #endif +#if ( ipconfigETHERNET_MINIMUM_PACKET_BYTES < 0 ) + #error ipconfigETHERNET_MINIMUM_PACKET_BYTES must be at least 0 +#endif + +#if ( ipconfigETHERNET_MINIMUM_PACKET_BYTES > SIZE_MAX ) + #error ipconfigETHERNET_MINIMUM_PACKET_BYTES overflows a size_t +#endif + /*---------------------------------------------------------------------------*/ -#if ( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 ) +#if ( ipconfigIS_DISABLED( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES ) ) + +/*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ +/* + * ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet + * frames that are not in Ethernet II format will be dropped. This option + * is included for potential future IP stack developments. + * + * When enabled, the function 'eConsiderFrameForProcessing()' will also + * check if the Ethernet frame type is acceptable. + */ - /* - * ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES - * - * If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet - * frames that are not in Ethernet II format will be dropped. This option - * is included for potential future IP stack developments. - * - * When enabled, the function 'eConsiderFrameForProcessing()' will also - * check if the Ethernet frame type is acceptable. - */ #ifndef ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES - #define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1 + #define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES ipconfigENABLE #endif - /*-----------------------------------------------------------------------*/ + #if ( ( ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES != ipconfigDISABLE ) && ( ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES != ipconfigENABLE ) ) + #error ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES should be pdFALSE or pdTRUE + #endif + +/*-----------------------------------------------------------------------*/ -#endif /* if ( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 ) */ +#endif /* if ( ipconfigIS_DISABLED( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES ) ) */ /*---------------------------------------------------------------------------*/ @@ -528,30 +765,26 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigNETWORK_MTU * + * Type: size_t + * Unit: bytes + * Minimum: 46 + * * The MTU is the maximum number of bytes the payload of a network frame can * contain. For normal Ethernet V2 frames the maximum MTU is 1500 (although a * lower number may be required for Internet routing). Setting a lower value * can save RAM, depending on the buffer management scheme used. - * - * If ipconfigNETWORK_MTU is not defined then the following defaults will be - * applied: - * - * #ifndef ipconfigNETWORK_MTU - * #ifdef( ipconfigUSE_TCP_WIN == 1 ) - * #define ipconfigNETWORK_MTU ( 1526 ) - * #else - * #define ipconfigNETWORK_MTU ( 1514 ) - * #endif - * #endif */ + #ifndef ipconfigNETWORK_MTU - #define ipconfigNETWORK_MTU 1500U + #define ipconfigNETWORK_MTU 1500 +#endif + +#if ( ipconfigNETWORK_MTU < 46 ) + #error ipconfigNETWORK_MTU must be at least 46 #endif -#if ( ipconfigNETWORK_MTU > ( SIZE_MAX >> 1 ) ) - #error ipconfigNETWORK_MTU overflows a size_t. -#elif ( ipconfigNETWORK_MTU < 46 ) - #error ipconfigNETWORK_MTU must be at least 46. +#if ( ipconfigNETWORK_MTU > SIZE_MAX ) + #error ipconfigNETWORK_MTU overflows a size_t #endif /*---------------------------------------------------------------------------*/ @@ -561,6 +794,10 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * + * Type: size_t + * Unit: length of NetworkBufferDescriptor_t array + * Minimum: 1 + * * ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network * buffer that are available to the TCP/IP stack. The total number of network * buffers is limited to ensure the total amount of RAM that can be consumed by @@ -574,10 +811,19 @@ * hardware and the pxGetNetworkBufferWithDescriptor() porting specific API * function. */ + #ifndef ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS #define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 45U #endif +#if ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS < 1 ) + #error ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS must be at least 1 +#endif + +#if ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS > SIZE_MAX ) + #error ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS overflows a size_t +#endif + /*---------------------------------------------------------------------------*/ /* @@ -585,6 +831,8 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_LINKED_RX_MESSAGES * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * * Advanced users only. * * When pconfigUSE_LINKED_RX_MESSAGES is set to 1 it is possible to reduce CPU @@ -592,8 +840,13 @@ * packets together, then passing all the linked packets to the IP RTOS task in * one go. */ + #ifndef ipconfigUSE_LINKED_RX_MESSAGES - #define ipconfigUSE_LINKED_RX_MESSAGES 0 + #define ipconfigUSE_LINKED_RX_MESSAGES ipconfigDISABLE +#endif + +#if ( ( ipconfigUSE_LINKED_RX_MESSAGES != ipconfigDISABLE ) && ( ipconfigUSE_LINKED_RX_MESSAGES != ipconfigENABLE ) ) + #error ipconfigUSE_LINKED_RX_MESSAGES should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -603,17 +856,24 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigZERO_COPY_RX_DRIVER * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * * Advanced users only. * * If ipconfigZERO_COPY_RX_DRIVER is set to 1 then the network interface will * assign network buffers NetworkBufferDescriptor_t::pucEthernetBuffer to the * DMA of the EMAC. When a packet is received, no data is copied. Instead, the - * buffer is sent directly to the IP-task. If the TX zero-copy option is + * buffer is sent directly to the IP-task. If the RX zero-copy option is * disabled, every received packet will be copied from the DMA buffer to the * network buffer of type NetworkBufferDescriptor_t. */ + #ifndef ipconfigZERO_COPY_RX_DRIVER - #define ipconfigZERO_COPY_RX_DRIVER 0 + #define ipconfigZERO_COPY_RX_DRIVER ipconfigDISABLE +#endif + +#if ( ( ipconfigZERO_COPY_RX_DRIVER != ipconfigDISABLE ) && ( ipconfigZERO_COPY_RX_DRIVER != ipconfigENABLE ) ) + #error ipconfigZERO_COPY_RX_DRIVER should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -623,6 +883,8 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigZERO_COPY_TX_DRIVER * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * * Advanced users only. * * If ipconfigZERO_COPY_TX_DRIVER is set to 1 then the driver function @@ -642,8 +904,13 @@ * FreeRTOS to a Different Microcontroller documentation page for worked * examples. */ + #ifndef ipconfigZERO_COPY_TX_DRIVER - #define ipconfigZERO_COPY_TX_DRIVER 0 + #define ipconfigZERO_COPY_TX_DRIVER ipconfigDISABLE +#endif + +#if ( ( ipconfigZERO_COPY_TX_DRIVER != ipconfigDISABLE ) && ( ipconfigZERO_COPY_TX_DRIVER != ipconfigENABLE ) ) + #error ipconfigZERO_COPY_TX_DRIVER should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -665,17 +932,31 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigEVENT_QUEUE_LENGTH * + * Type: size_t + * Unit: count of queue spaces + * Minimum: 1 + * * A FreeRTOS queue is used to send events from application tasks to the IP * stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can * be queued for processing at any one time. The event queue must be a minimum * of 5 greater than the total number of network buffers. + * + * The actual number of items in the event queue can be monitored. + * See 'ipconfigCHECK_IP_QUEUE_SPACE' described here below. + * + * Tasks should never have to wait for space in the 'xNetworkEventQueue'. */ + #ifndef ipconfigEVENT_QUEUE_LENGTH #define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5U ) #endif #if ( ipconfigEVENT_QUEUE_LENGTH < ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5U ) ) - #error The ipconfigEVENT_QUEUE_LENGTH parameter must be at least ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 + #error ipconfigEVENT_QUEUE_LENGTH must be at least ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 +#endif + +#if ( ipconfigEVENT_QUEUE_LENGTH > SIZE_MAX ) + #error ipconfigEVENT_QUEUE_LENGTH overflows a size_t #endif /*---------------------------------------------------------------------------*/ @@ -685,7 +966,12 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigIP_TASK_PRIORITY * - * the TCP/IP stack executes it its own RTOS task (although any application + * Type: UBaseType_t + * Unit: task priority + * Minimum: 0 + * Maximum: configMAX_PRIORITIES - 1 + * + * The TCP/IP stack executes in its own RTOS task (although any application * RTOS task can make use of its services through the published sockets API). * ipconfigIP_TASK_PRIORITY sets the priority of the RTOS task that executes * the TCP/IP stack. @@ -698,11 +984,26 @@ * Consideration needs to be given as to the priority assigned to the RTOS task * executing the TCP/IP stack relative to the priority assigned to tasks that * use the TCP/IP stack. + * + * It is recommended to assign the following task priorities: + * + * Higher : EMAC task "Deferred interrupt handler" + * Medium : IP-task + * Lower : User tasks that make use of the TCP/IP stack */ + #ifndef ipconfigIP_TASK_PRIORITY #define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2U ) #endif +#if ( ipconfigIP_TASK_PRIORITY < 0 ) + #error ipconfigIP_TASK_PRIORITY must be at least 0 +#endif + +#if ( ipconfigIP_TASK_PRIORITY > ( configMAX_PRIORITIES - 1 ) ) + #error ipconfigIP_TASK_PRIORITY must be at most configMAX_PRIORITIES - 1 +#endif + /*---------------------------------------------------------------------------*/ /* @@ -710,12 +1011,25 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigIP_TASK_STACK_SIZE_WORDS * + * Type: size_t + * Unit: words + * Minimum: configMINIMAL_STACK_SIZE + * * The size, in words (not bytes), of the stack allocated to the * FreeRTOS-Plus-TCP RTOS task. FreeRTOS includes optional stack overflow * detection. */ + #ifndef ipconfigIP_TASK_STACK_SIZE_WORDS - #define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5U ) + #define ipconfigIP_TASK_STACK_SIZE_WORDS configMINIMAL_STACK_SIZE +#endif + +#if ( ipconfigIP_TASK_STACK_SIZE_WORDS < configMINIMAL_STACK_SIZE ) + #error ipconfigIP_TASK_STACK_SIZE_WORDS must be at least configMINIMAL_STACK_SIZE +#endif + +#if ( ipconfigIP_TASK_STACK_SIZE_WORDS > SIZE_MAX ) + #error ipconfigIP_TASK_STACK_SIZE_WORDS overflows a size_t #endif /*---------------------------------------------------------------------------*/ @@ -725,12 +1039,22 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES * - * If ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES is set to 1, then the TCP/IP stack - * will call eApplicationProcessCustomFrameHook to process any unknown frame, + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables usage of an application defined hook to process any unknown frame, * that is, any frame that expects ARP or IP. + * + * Function prototype: + * + * eFrameProcessingResult_t eApplicationProcessCustomFrameHook( NetworkBufferDescriptor_t * const pxNetworkBuffer ) */ + #ifndef ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES - #define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES 0 + #define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES ipconfigDISABLE +#endif + +#if ( ( ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES != ipconfigDISABLE ) && ( ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES != ipconfigENABLE ) ) + #error ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -740,13 +1064,28 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_NETWORK_EVENT_HOOK * - * If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS-Plus-TCP will - * call the network event hook at the appropriate times. If - * ipconfigUSE_NETWORK_EVENT_HOOK is not set to 1 then the network event hook - * will never be called. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables usage of a hook to process network events. + * + * This hook is affected by ipconfigIPv4_BACKWARD_COMPATIBLE. + * + * Function prototype if ipconfigIPv4_BACKWARD_COMPATIBLE is enabled: + * + * void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent ) + * + * Function prototype by default: + * + * void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent, + * struct xNetworkEndPoint * pxEndPoint ) */ + #ifndef ipconfigUSE_NETWORK_EVENT_HOOK - #define ipconfigUSE_NETWORK_EVENT_HOOK 0 + #define ipconfigUSE_NETWORK_EVENT_HOOK ipconfigDISABLE +#endif + +#if ( ( ipconfigUSE_NETWORK_EVENT_HOOK != ipconfigDISABLE ) && ( ipconfigUSE_NETWORK_EVENT_HOOK != ipconfigENABLE ) ) + #error ipconfigUSE_NETWORK_EVENT_HOOK should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -768,332 +1107,449 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_TCP * - * Set ipconfigUSE_TCP to 1 to enable TCP. If ipconfigUSE_TCP is set to 0 then - * only UDP is available. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Include support for TCP. */ + #ifndef ipconfigUSE_TCP - #define ipconfigUSE_TCP 1 + #define ipconfigUSE_TCP ipconfigENABLE +#endif + +#if ( ( ipconfigUSE_TCP != ipconfigDISABLE ) && ( ipconfigUSE_TCP != ipconfigENABLE ) ) + #error ipconfigUSE_TCP should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ -#if ( ipconfigUSE_TCP != 0 ) +#if ( ipconfigIS_ENABLED( ipconfigUSE_TCP ) ) - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigIGNORE_UNKNOWN_PACKETS + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigIGNORE_UNKNOWN_PACKETS + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Advanced users only. + * + * Prevents sending RESET responses to TCP packets that have a bad or unknown + * destination. + */ - /* - * ipconfigIGNORE_UNKNOWN_PACKETS - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigIGNORE_UNKNOWN_PACKETS - * - * Normally TCP packets that have a bad or unknown destination will result - * in a RESET being sent back to the remote host. If - * ipconfigIGNORE_UNKNOWN_PACKETS is set to 1 then such resets will be - * suppressed (not sent). - */ #ifndef ipconfigIGNORE_UNKNOWN_PACKETS - #define ipconfigIGNORE_UNKNOWN_PACKETS 0 + #define ipconfigIGNORE_UNKNOWN_PACKETS ipconfigDISABLE #endif - /*-----------------------------------------------------------------------*/ - - /* - * ipconfigTCP_HANG_PROTECTION - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_HANG_PROTECTION - * - * If ipconfigTCP_HANG_PROTECTION is set to 1 then FreeRTOS-Plus-TCP will - * mark a socket as closed if there is no status change on the socket - * within the period of time specified by ipconfigTCP_HANG_PROTECTION_TIME. - */ - #ifndef ipconfigTCP_HANG_PROTECTION - #define ipconfigTCP_HANG_PROTECTION 1 + #if ( ( ipconfigIGNORE_UNKNOWN_PACKETS != ipconfigDISABLE ) && ( ipconfigIGNORE_UNKNOWN_PACKETS != ipconfigENABLE ) ) + #error ipconfigIGNORE_UNKNOWN_PACKETS should be pdFALSE or pdTRUE #endif - /*-----------------------------------------------------------------------*/ - #if ( ipconfigTCP_HANG_PROTECTION != 0 ) +/*-----------------------------------------------------------------------*/ - /*-------------------------------------------------------------------*/ +/* + * ipconfigTCP_HANG_PROTECTION + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_HANG_PROTECTION + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables automatic closure of a TCP socket after a timeout of no status + * changes. + * + * See ipconfigTCP_HANG_PROTECTION_TIME + */ - /* - * ipconfigTCP_HANG_PROTECTION_TIME - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_HANG_PROTECTION_TIME - * - * If ipconfigTCP_HANG_PROTECTION is set to 1 then - * ipconfigTCP_HANG_PROTECTION_TIME sets the interval in seconds - * between the status of a socket last changing and the anti-hang - * mechanism marking the socket as closed. - */ - #ifndef ipconfigTCP_HANG_PROTECTION_TIME - #define ipconfigTCP_HANG_PROTECTION_TIME 30U - #endif + #ifndef ipconfigTCP_HANG_PROTECTION + #define ipconfigTCP_HANG_PROTECTION ipconfigENABLE + #endif - /*-------------------------------------------------------------------*/ - - #endif /* if ( ipconfigTCP_HANG_PROTECTION != 0 ) */ - - /*-----------------------------------------------------------------------*/ - - /* - * ipconfigTCP_KEEP_ALIVE - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_KEEP_ALIVE - * - * Sockets that are connected but do not transmit any data for an extended - * period can be disconnected by routers or firewalls that time out. This - * can be avoided at the application level by ensuring the application - * periodically sends a packet. Alternatively FreeRTOS-Plus-TCP can be - * configured to automatically send keep alive messages when it detects - * that a connection is dormant. Note that, while having FreeRTOS-Plus-TCP - * automatically send keep alive messages is the more convenient method, it - * is also the least reliable method because some routers will discard keep - * alive messages. - * - * Set ipconfigTCP_KEEP_ALIVE to 1 to have FreeRTOS-Plus-TCP periodically - * send keep alive messages on connected but dormant sockets. Set - * ipconfigTCP_KEEP_ALIVE to 0 to prevent the automatic transmission of - * keep alive messages. - * - * If FreeRTOS-Plus-TCP does not receive a reply to a keep alive message - * then the connection will be broken and the socket will be marked as - * closed. Subsequent FreeRTOS_recv() calls on the socket will return - * -pdFREERTOS_ERRNO_ENOTCONN. - */ - #ifndef ipconfigTCP_KEEP_ALIVE - #define ipconfigTCP_KEEP_ALIVE 0 + #if ( ( ipconfigTCP_HANG_PROTECTION != ipconfigDISABLE ) && ( ipconfigTCP_HANG_PROTECTION != ipconfigENABLE ) ) + #error ipconfigTCP_HANG_PROTECTION should be pdFALSE or pdTRUE #endif - /*-----------------------------------------------------------------------*/ - #if ( ipconfigTCP_KEEP_ALIVE != 0 ) +/*-----------------------------------------------------------------------*/ - /*-------------------------------------------------------------------*/ + #if ( ipconfigIS_ENABLED( ipconfigTCP_HANG_PROTECTION ) ) - /* - * ipconfigTCP_KEEP_ALIVE_INTERVAL - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_KEEP_ALIVE_INTERVAL - * - * If ipconfigTCP_KEEP_ALIVE is set to 1 then - * ipconfigTCP_KEEP_ALIVE_INTERVAL sets the interval in seconds between - * successive keep alive messages. Keep alive messages are not sent at - * all unless ipconfigTCP_KEEP_ALIVE_INTERVAL seconds have passed since - * the last packet was sent or received. - */ - #ifndef ipconfigTCP_KEEP_ALIVE_INTERVAL - #define ipconfigTCP_KEEP_ALIVE_INTERVAL 20U - #endif +/*-------------------------------------------------------------------*/ - /*-------------------------------------------------------------------*/ +/* + * ipconfigTCP_HANG_PROTECTION_TIME + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_HANG_PROTECTION_TIME + * + * Type: TickType_t + * Unit: seconds + * Minimum: 0 + * Maximum: portMAX_DELAY / configTICK_RATE_HZ + * + * If ipconfigTCP_HANG_PROTECTION is set to 1 then + * ipconfigTCP_HANG_PROTECTION_TIME sets the interval in seconds + * between the status of a socket last changing and the anti-hang + * mechanism marking the socket as closed. + */ - #endif /* if ( ipconfigTCP_KEEP_ALIVE != 0 ) */ + #ifndef ipconfigTCP_HANG_PROTECTION_TIME + #define ipconfigTCP_HANG_PROTECTION_TIME 30 + #endif - /*-----------------------------------------------------------------------*/ + #if ( ipconfigTCP_HANG_PROTECTION_TIME < 0 ) + #error ipconfigTCP_HANG_PROTECTION_TIME must be at least 0 + #endif + + #if ( ipconfigTCP_HANG_PROTECTION_TIME > SIZE_MAX ) + #error ipconfigTCP_HANG_PROTECTION_TIME must be at most portMAX_DELAY / configTICK_RATE_HZ + #endif + +/*-------------------------------------------------------------------*/ + + #endif /* if ( ipconfigIS_ENABLED( ipconfigTCP_HANG_PROTECTION ) ) */ + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigTCP_KEEP_ALIVE + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_KEEP_ALIVE + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Sockets that are connected but do not transmit any data for an extended + * period can be disconnected by routers or firewalls that time out. This + * can be avoided at the application level by ensuring the application + * periodically sends a packet. Alternatively FreeRTOS-Plus-TCP can be + * configured to automatically send keep alive messages when it detects + * that a connection is dormant. Note that, while having FreeRTOS-Plus-TCP + * automatically send keep alive messages is the more convenient method, it + * is also the least reliable method because some routers will discard keep + * alive messages. + * + * Set ipconfigTCP_KEEP_ALIVE to 1 to have FreeRTOS-Plus-TCP periodically + * send keep alive messages on connected but dormant sockets. Set + * ipconfigTCP_KEEP_ALIVE to 0 to prevent the automatic transmission of + * keep alive messages. + * + * If FreeRTOS-Plus-TCP does not receive a reply to a keep alive message + * then the connection will be broken and the socket will be marked as + * closed. Subsequent FreeRTOS_recv() calls on the socket will return + * -pdFREERTOS_ERRNO_ENOTCONN. + */ + + #ifndef ipconfigTCP_KEEP_ALIVE + #define ipconfigTCP_KEEP_ALIVE ipconfigDISABLE + #endif + + #if ( ( ipconfigTCP_KEEP_ALIVE != ipconfigDISABLE ) && ( ipconfigTCP_KEEP_ALIVE != ipconfigENABLE ) ) + #error ipconfigTCP_KEEP_ALIVE should be pdFALSE or pdTRUE + #endif + +/*-----------------------------------------------------------------------*/ + + #if ( ipconfigIS_ENABLED( ipconfigTCP_KEEP_ALIVE ) ) + +/*-------------------------------------------------------------------*/ + +/* + * ipconfigTCP_KEEP_ALIVE_INTERVAL + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_KEEP_ALIVE_INTERVAL + * + * Type: TickType_t + * Unit: Seconds + * Minimum: 0 + * Maximum: portMAX_DELAY / configTICK_RATE_HZ + * + * If ipconfigTCP_KEEP_ALIVE is set to 1 then + * ipconfigTCP_KEEP_ALIVE_INTERVAL sets the interval in seconds between + * successive keep alive messages. Keep alive messages are not sent at + * all unless ipconfigTCP_KEEP_ALIVE_INTERVAL seconds have passed since + * the last packet was sent or received. + */ + + #ifndef ipconfigTCP_KEEP_ALIVE_INTERVAL + #define ipconfigTCP_KEEP_ALIVE_INTERVAL 20 + #endif + + #if ( ipconfigTCP_KEEP_ALIVE_INTERVAL < 0 ) + #error ipconfigTCP_KEEP_ALIVE_INTERVAL must be at least 0 + #endif + + #if ( ipconfigTCP_KEEP_ALIVE_INTERVAL > SIZE_MAX ) + #error ipconfigTCP_KEEP_ALIVE_INTERVAL must be at most portMAX_DELAY / configTICK_RATE_HZ + #endif + +/*-------------------------------------------------------------------*/ + + #endif /* if ( ipconfigIS_ENABLED( ipconfigTCP_KEEP_ALIVE ) ) */ + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigTCP_MSS + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_MSS + * + * Type: size_t + * Unit: bytes + * Minimum: 1 + * + * Sets the MSS value (in bytes) for all TCP packets. + * + * Note that FreeRTOS-Plus-TCP contains checks that the defined + * ipconfigNETWORK_MTU and ipconfigTCP_MSS values are consistent with each + * other. + * + * The default definition of 'ipconfigTCP_MSS' works well for most projects. + * Note that IPv6 headers are larger than IPv4 headers, leaving less space for + * the TCP payload. In prvSocketSetMSS_IPV6(), 20 bytes will be subtracted from + * 'ipconfigTCP_MSS'. + * + * The default is derived from MTU - ( ipconfigNETWORK_MTU + ipSIZE_OF_TCP_HEADER ) + */ - /* - * ipconfigTCP_MSS - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_MSS - * - * Sets the MSS value (in bytes) for all TCP packets. - * - * Note that FreeRTOS-Plus-TCP contains checks that the defined - * ipconfigNETWORK_MTU and ipconfigTCP_MSS values are consistent with each - * other. - */ #ifndef ipconfigTCP_MSS - #define ipconfigTCP_MSS ( ipconfigNETWORK_MTU - ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ) ) - #endif - - /*-----------------------------------------------------------------------*/ - - /* - * ipconfigTCP_RX_BUFFER_LENGTH - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_RX_BUFFER_LENGTH - * - * Each TCP socket has a buffer for reception and a separate buffer for - * transmission. - * - * The default buffer size is (4 * ipconfigTCP_MSS). - * - * FreeRTOS_setsockopt() can be used with the FREERTOS_SO_RCVBUF and - * FREERTOS_SO_SNDBUF parameters to set the receive and send buffer sizes - * respectively - but this must be done between the time that the socket is - * created and the buffers used by the socket are created. The receive - * buffer is not created until data is actually received, and the transmit - * buffer is not created until data is actually sent to the socket for - * transmission. Once the buffers have been created their sizes cannot be - * changed. - * - * If a listening socket creates a new socket in response to an incoming - * connect request then the new socket will inherit the buffers sizes of - * the listening socket. - */ + #define ipconfigTCP_MSS ( ipconfigNETWORK_MTU - 40 ) + #endif + + #if ( ipconfigTCP_MSS < 1 ) + #error ipconfigTCP_MSS must be at least 1 + #endif + + #if ( ipconfigTCP_MSS > SIZE_MAX ) + #error ipconfigTCP_MSS overflows a size_t + #endif + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigTCP_RX_BUFFER_LENGTH + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_RX_BUFFER_LENGTH + * + * Type: size_t + * Unit: size of StreamBuffer_t in bytes + * Minimum: 0 + * + * Each TCP socket has a buffer for reception and a separate buffer for + * transmission. + * + * FreeRTOS_setsockopt() can be used with the FREERTOS_SO_RCVBUF and + * FREERTOS_SO_SNDBUF parameters to set the receive and send buffer sizes + * respectively - but this must be done between the time that the socket is + * created and the buffers used by the socket are created. The receive + * buffer is not created until data is actually received, and the transmit + * buffer is not created until data is actually sent to the socket for + * transmission. Once the buffers have been created their sizes cannot be + * changed. + * + * If a listening socket creates a new socket in response to an incoming + * connect request then the new socket will inherit the buffers sizes of + * the listening socket. + * + * The buffer length defaults to 5840 bytes. + */ + #ifndef ipconfigTCP_RX_BUFFER_LENGTH - /* When MTU equals 1500, the buffer length defaults to 5840 bytes */ #define ipconfigTCP_RX_BUFFER_LENGTH ( 4U * ipconfigTCP_MSS ) #endif - /*-----------------------------------------------------------------------*/ - - /* - * ipconfigTCP_TX_BUFFER_LENGTH - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_RX_BUFFER_LENGTH - * - * Each TCP socket has a buffer for reception and a separate buffer for - * transmission. - * - * The default buffer size is (4 * ipconfigTCP_MSS). - * - * FreeRTOS_setsockopt() can be used with the FREERTOS_SO_RCVBUF and - * FREERTOS_SO_SNDBUF parameters to set the receive and send buffer sizes - * respectively - but this must be done between the time that the socket is - * created and the buffers used by the socket are created. The receive - * buffer is not created until data is actually received, and the transmit - * buffer is not created until data is actually sent to the socket for - * transmission. Once the buffers have been created their sizes cannot be - * changed. - * - * If a listening socket creates a new socket in response to an incoming - * connect request then the new socket will inherit the buffers sizes of - * the listening socket. - */ + #if ( ipconfigTCP_RX_BUFFER_LENGTH < 0 ) + #error ipconfigTCP_RX_BUFFER_LENGTH must be at least 0 + #endif + + #if ( ipconfigTCP_RX_BUFFER_LENGTH > SIZE_MAX ) + #error ipconfigTCP_RX_BUFFER_LENGTH overflows a size_t + #endif + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigTCP_TX_BUFFER_LENGTH + * + * Type: size_t + * Unit: size of StreamBuffer_t in bytes + * Minimum: 0 + * + * See ipconfigTCP_RX_BUFFER_LENGTH + */ + #ifndef ipconfigTCP_TX_BUFFER_LENGTH #define ipconfigTCP_TX_BUFFER_LENGTH ( 4U * ipconfigTCP_MSS ) #endif - /*-----------------------------------------------------------------------*/ + #if ( ipconfigTCP_TX_BUFFER_LENGTH < 0 ) + #error ipconfigTCP_TX_BUFFER_LENGTH must be at least 0 + #endif + + #if ( ipconfigTCP_TX_BUFFER_LENGTH > SIZE_MAX ) + #error ipconfigTCP_TX_BUFFER_LENGTH overflows a size_t + #endif + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigTCP_TIME_TO_LIVE + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_TIME_TO_LIVE + * + * Type: uint8_t + * Unit: 'hops' + * Minimum: 0 + * + * Defines the Time To Live (TTL) values used in outgoing TCP packets. + */ - /* - * ipconfigTCP_TIME_TO_LIVE - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_TIME_TO_LIVE - * - * Defines the Time To Live TTL) values used in outgoing TCP packets. - */ #ifndef ipconfigTCP_TIME_TO_LIVE - #define ipconfigTCP_TIME_TO_LIVE 128U - #endif - - /*-----------------------------------------------------------------------*/ - - /* - * ipconfigUSE_TCP_WIN - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_TCP_WIN - * - * Sliding Windows allows messages to arrive out-of-order. - * - * Set ipconfigUSE_TCP_WIN to 1 to include sliding window behavior in TCP - * sockets. Set ipconfigUSE_TCP_WIN to 0 to exclude sliding window - * behavior in TCP sockets. - * - * Sliding windows can increase throughput while minimizing network traffic - * at the expense of consuming more RAM. - * - * The size of the sliding window can be changed from its default using the - * FREERTOS_SO_WIN_PROPERTIES parameter to FreeRTOS_setsockopt(). The - * sliding window size is specified in units of MSS (so if the MSS is set - * to 200 bytes then a sliding window size of 2 is equal to 400 bytes) and - * must always be smaller than or equal to the size of the internal buffers - * in both directions. - * - * If a listening socket creates a new socket in response to an incoming - * connect request then the new socket will inherit the sliding window - * sizes of the listening socket. - */ + #define ipconfigTCP_TIME_TO_LIVE UINT8_C( 128 ) + #endif + + #if ( ipconfigTCP_TIME_TO_LIVE < 0 ) + #error ipconfigTCP_TIME_TO_LIVE must be at least 0 + #endif + + #if ( ipconfigTCP_TIME_TO_LIVE > UINT8_MAX ) + #error ipconfigTCP_TIME_TO_LIVE overflows a uint8_t + #endif + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigUSE_TCP_WIN + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_TCP_WIN + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Sliding Windows allows messages to arrive out-of-order. + * + * Set ipconfigUSE_TCP_WIN to 1 to include sliding window behaviour in TCP + * sockets. Set ipconfigUSE_TCP_WIN to 0 to exclude sliding window + * behaviour in TCP sockets. + * + * Sliding windows can increase throughput while minimizing network traffic + * at the expense of consuming more RAM. + * + * The size of the sliding window can be changed from its default using the + * FREERTOS_SO_WIN_PROPERTIES parameter to FreeRTOS_setsockopt(). The + * sliding window size is specified in units of MSS (so if the MSS is set + * to 200 bytes then a sliding window size of 2 is equal to 400 bytes) and + * must always be smaller than or equal to the size of the internal buffers + * in both directions. + * + * If a listening socket creates a new socket in response to an incoming + * connect request then the new socket will inherit the sliding window + * sizes of the listening socket. + */ + #ifndef ipconfigUSE_TCP_WIN - #define ipconfigUSE_TCP_WIN 1 + #define ipconfigUSE_TCP_WIN ipconfigENABLE #endif - /*-----------------------------------------------------------------------*/ + #if ( ( ipconfigUSE_TCP_WIN != ipconfigDISABLE ) && ( ipconfigUSE_TCP_WIN != ipconfigENABLE ) ) + #error ipconfigUSE_TCP_WIN should be pdFALSE or pdTRUE + #endif + +/*-----------------------------------------------------------------------*/ - #if ( ipconfigUSE_TCP_WIN != 0 ) + #if ( ipconfigIS_ENABLED( ipconfigUSE_TCP_WIN ) ) - /*-------------------------------------------------------------------*/ +/*-------------------------------------------------------------------*/ + +/* + * ipconfigTCP_SRTT_MINIMUM_VALUE_MS + * + * Type: uint32_t + * Unit: milliseconds + * Minimum: 0 + * + * When measuring the Smoothed Round Trip Time (SRTT), + * the result will be rounded up to a minimum value. + * The default has always been 50, but a value of 1000 + * is recommended ( see RFC6298 ) because hosts often delay the + * sending of ACK packets with 200 ms. + */ - /* - * ipconfigTCP_SRTT_MINIMUM_VALUE_MS - * - * when measuring the Smoothed Round Trip Time (SRTT), - * the result will be rounded up to a minimum value. - * The default has always been 50, but a value of 1000 - * is recommended ( see RFC6298 ) because hosts often delay the - * sending of ACK packets with 200 ms. - */ #ifndef ipconfigTCP_SRTT_MINIMUM_VALUE_MS - #define ipconfigTCP_SRTT_MINIMUM_VALUE_MS 50U + #define ipconfigTCP_SRTT_MINIMUM_VALUE_MS UINT32_C( 50 ) + #endif + + #if ( ipconfigTCP_SRTT_MINIMUM_VALUE_MS < 0 ) + #error ipconfigTCP_SRTT_MINIMUM_VALUE_MS must be at least 0 #endif - /*-------------------------------------------------------------------*/ - - /* - * ipconfigTCP_WIN_SEG_COUNT - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_WIN_SEG_COUNT - * - * If ipconfigUSE_TCP_WIN is set to 1 then each socket will use a - * sliding window. Sliding windows allow messages to arrive out-of - * order, and FreeRTOS-Plus-TCP uses window descriptors to track - * information about the packets in a window. - * - * A pool of descriptors is allocated when the first TCP connection is - * made. The descriptors are shared between all the sockets. - * ipconfigTCP_WIN_SEG_COUNT sets the number of descriptors in the - * pool, and each descriptor is approximately 64 bytes. - * - * As an example: If a system will have at most 16 simultaneous TCP - * connections, and each connection will have an Rx and Tx window of at - * most 8 segments, then the worst case maximum number of descriptors - * that will be required is 256 ( 16 * 2 * 8 ). However, the practical - * worst case is normally much lower than this as most packets will - * arrive in order. - */ + #if ( ipconfigTCP_SRTT_MINIMUM_VALUE_MS > UINT32_MAX ) + #error ipconfigTCP_SRTT_MINIMUM_VALUE_MS overflows a uint32_t + #endif + +/*-------------------------------------------------------------------*/ + +/* + * ipconfigTCP_WIN_SEG_COUNT + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_WIN_SEG_COUNT + * + * Type: size_t + * Unit: count of sliding windows + * Minimum: 1 + * + * If ipconfigUSE_TCP_WIN is set to 1 then each socket will use a + * sliding window. Sliding windows allow messages to arrive out-of + * order, and FreeRTOS-Plus-TCP uses window descriptors to track + * information about the packets in a window. + * + * A pool of descriptors is allocated when the first TCP connection is + * made. The descriptors are shared between all the sockets. + * ipconfigTCP_WIN_SEG_COUNT sets the number of descriptors in the + * pool, and each descriptor is approximately 64 bytes. + * + * As an example: If a system will have at most 16 simultaneous TCP + * connections, and each connection will have an Rx and Tx window of at + * most 8 segments, then the worst case maximum number of descriptors + * that will be required is 256 ( 16 * 2 * 8 ). However, the practical + * worst case is normally much lower than this as most packets will + * arrive in order. + */ + #ifndef ipconfigTCP_WIN_SEG_COUNT #define ipconfigTCP_WIN_SEG_COUNT 256U #endif - /*-------------------------------------------------------------------*/ + #if ( ipconfigTCP_WIN_SEG_COUNT < 1 ) + #error ipconfigTCP_WIN_SEG_COUNT must be at least 1 + #endif + + #if ( ipconfigTCP_WIN_SEG_COUNT > SIZE_MAX ) + #error ipconfigTCP_WIN_SEG_COUNT overflows a size_t + #endif - #endif /* if ( ipconfigUSE_TCP_WIN != 0 ) */ +/*-------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ + #endif /* if ( ipconfigIS_ENABLED( ipconfigUSE_TCP_WIN ) */ + +/*-----------------------------------------------------------------------*/ + +/* + * pvPortMallocLarge / vPortFreeLarge + * + * Malloc functions specific to large TCP buffers for Rx/Tx. + */ - /* - * pvPortMallocLarge - * - * Malloc functions. Within most applications of FreeRTOS, the couple - * pvPortMalloc()/vPortFree() will be used. - * If there are different types of RAM, the user may decide to use a different - * memory allocator for different purposes: - * MallocLarge is used to allocate large TCP buffers (for Rx/Tx) - */ #ifndef pvPortMallocLarge - #define pvPortMallocLarge( x ) pvPortMalloc( x ) + #define pvPortMallocLarge( size ) pvPortMalloc( size ) #endif - /*-----------------------------------------------------------------------*/ - - /* - * vPortFreeLarge - * - * Malloc functions. Within most applications of FreeRTOS, the couple - * pvPortMalloc()/vPortFree() will be used. - * If there are different types of RAM, the user may decide to use a different - * memory allocator for different purposes: - * MallocLarge is used to allocate large TCP buffers (for Rx/Tx) - */ #ifndef vPortFreeLarge #define vPortFreeLarge( ptr ) vPortFree( ptr ) #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ -#endif /* ( ipconfigUSE_TCP != 0 ) */ +#endif /* ( ipconfigIS_ENABLED( ipconfigUSE_TCP ) ) */ /*---------------------------------------------------------------------------*/ @@ -1114,16 +1570,29 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUDP_MAX_RX_PACKETS * + * Type: UBaseType_t + * Unit: rx packets + * Minimum: 0 + * * ipconfigUDP_MAX_RX_PACKETS defines the maximum number of packets that can * exist in the Rx queue of a UDP socket. For example, if * ipconfigUDP_MAX_RX_PACKETS is set to 5 and there are already 5 packets * queued on the UDP socket then subsequent packets received on that socket * will be dropped until the queue length is less than 5 again. */ + #ifndef ipconfigUDP_MAX_RX_PACKETS #define ipconfigUDP_MAX_RX_PACKETS 0U #endif +#if ( ipconfigUDP_MAX_RX_PACKETS < 0 ) + #error ipconfigUDP_MAX_RX_PACKETS must be at least 0 +#endif + +#if ( ipconfigUDP_MAX_RX_PACKETS > UINT_FAST8_MAX ) + #error ipconfigUDP_MAX_RX_PACKETS overflows a UBaseType_t +#endif + /*---------------------------------------------------------------------------*/ /* @@ -1131,6 +1600,11 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS * + * Type: TickType_t + * Unit: Ticks + * Minimum: 0 + * Maximum: portMAX_DELAY + * * Sockets have a send block time attribute. If FreeRTOS_sendto() is called but * a network buffer cannot be obtained, then the calling RTOS task is held in * the Blocked state (so other tasks can continue to executed) until either a @@ -1147,8 +1621,9 @@ * milliseconds can be converted to a time in ticks by dividing the time in * milliseconds by portTICK_PERIOD_MS. */ + #ifndef ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS - #define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( pdMS_TO_TICKS( 20U ) ) + #define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 20 ) #endif /*---------------------------------------------------------------------------*/ @@ -1158,18 +1633,19 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS * - * If ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS is set to 1 then FreeRTOS-Plus-TCP - * will accept UDP packets that have their checksum value set to 0, which is in - * compliance with the UDP specification. - * - * If ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS is set to 0 then FreeRTOS-Plus-TCP - * will drop UDP packets that have their checksum value set to 0, which - * deviates from the UDP specification, but is safer. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) * - * Note: This configuration parameter defaults to 0. + * If enabled then UDP packets that have their checksum value set to 0 will be + * accepted, which is in compliance with the UDP specification. Otherwise they + * will be dropped, which deviates from the UDP specification, but is safer. */ + #ifndef ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS - #define ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS 0 + #define ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS ipconfigDISABLE +#endif + +#if ( ( ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS != ipconfigDISABLE ) && ( ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS != ipconfigENABLE ) ) + #error ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -1179,10 +1655,23 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUDP_TIME_TO_LIVE * + * Type: uint8_t + * Units: 'hops' + * Minimum: 0 + * * Defines the Time To Live (TTL) values used in outgoing UDP packets. */ + #ifndef ipconfigUDP_TIME_TO_LIVE - #define ipconfigUDP_TIME_TO_LIVE 128U + #define ipconfigUDP_TIME_TO_LIVE UINT8_C( 128 ) +#endif + +#if ( ipconfigUDP_TIME_TO_LIVE < 0 ) + #error ipconfigUDP_TIME_TO_LIVE must be at least 0 +#endif + +#if ( ipconfigUDP_TIME_TO_LIVE > UINT8_MAX ) + #error ipconfigUDP_TIME_TO_LIVE overflows a uint8_t #endif /*---------------------------------------------------------------------------*/ @@ -1204,6 +1693,8 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * * The address of a socket is the combination of its IP address and its port * number. FreeRTOS_bind() is used to manually allocate a port number to a * socket (to 'bind' the socket to a port), but manual binding is not normally @@ -1217,8 +1708,13 @@ * FreeRTOS_sendto() on a socket that has not yet been bound will result * in the send operation being aborted. */ + #ifndef ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND - #define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1 + #define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND ipconfigENABLE +#endif + +#if ( ( ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND != ipconfigDISABLE ) && ( ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND != ipconfigENABLE ) ) + #error ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -1228,41 +1724,52 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigSUPPORT_SELECT_FUNCTION * - * Set ipconfigSUPPORT_SELECT_FUNCTION to 1 to include support for the - * FreeRTOS_select() and associated API functions, or 0 to exclude - * FreeRTOS_select() and associated API functions from the build. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Include support for FreeRTOS_select() and associated API functions. */ + #ifndef ipconfigSUPPORT_SELECT_FUNCTION - #define ipconfigSUPPORT_SELECT_FUNCTION 0 + #define ipconfigSUPPORT_SELECT_FUNCTION ipconfigDISABLE +#endif + +#if ( ( ipconfigSUPPORT_SELECT_FUNCTION != ipconfigDISABLE ) && ( ipconfigSUPPORT_SELECT_FUNCTION != ipconfigENABLE ) ) + #error ipconfigSUPPORT_SELECT_FUNCTION should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ -#if ( ipconfigSUPPORT_SELECT_FUNCTION != 0 ) +#if ( ipconfigIS_ENABLED( ipconfigSUPPORT_SELECT_FUNCTION ) ) - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigSELECT_USES_NOTIFY + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigSELECT_USES_NOTIFY + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * This option is only used in case the socket-select functions are + * activated (when ipconfigSUPPORT_SELECT_FUNCTION is non-zero). When + * calling select() for a given socket from the same task, this macro is + * not required. Only when there are multiple tasks using select on the + * same sockets, this option may prevent a dead-lock. The problem is that + * the event bit eSELECT_CALL_IP is waited for and cleared by multiple + * tasks. + */ - /* - * ipconfigSELECT_USES_NOTIFY - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigSELECT_USES_NOTIFY - * - * This option is only used in case the socket-select functions are - * activated (when ipconfigSUPPORT_SELECT_FUNCTION is non-zero). When - * calling select() for a given socket from the same task, this macro is - * not required. Only when there are multiple tasks using select on the - * same sockets, this option may prevent a dead-lock. The problem is that - * the event bit eSELECT_CALL_IP is waited for and cleared by multiple - * tasks. The macro ipconfigSELECT_USES_NOTIFY defaults to zero, meaning - * not active. - */ #ifndef ipconfigSELECT_USES_NOTIFY - #define ipconfigSELECT_USES_NOTIFY 0 + #define ipconfigSELECT_USES_NOTIFY ipconfigDISABLE + #endif + + #if ( ( ipconfigSELECT_USES_NOTIFY != ipconfigDISABLE ) && ( ipconfigSELECT_USES_NOTIFY != ipconfigENABLE ) ) + #error ipconfigSELECT_USES_NOTIFY should be pdFALSE or pdTRUE #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ -#endif /* if ( ipconfigSUPPORT_SELECT_FUNCTION != 0 ) */ +#endif /* if ( ipconfigIS_ENABLED( ipconfigSUPPORT_SELECT_FUNCTION ) ) */ /*---------------------------------------------------------------------------*/ @@ -1271,6 +1778,11 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME * + * Type: TickType_t + * Unit: Ticks + * Minimum: 0 + * Maximum: portMAX_DELAY + * * API functions used to read data from a socket can block to wait for data to * become available. ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME sets the default * block time defined in RTOS ticks. If ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME @@ -1281,7 +1793,9 @@ * * ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME is specified in ticks. The macros * pdMS_TO_TICKS() and portTICK_PERIOD_MS can both be used to convert a time - * specified in milliseconds to a time specified in ticks. + * specified in milliseconds to a time specified in ticks, e.g. 2000 ms: + * + * #define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME pdMS_TO_TICKS( 2000U ) * * The timeout time can be changed at any time using the FREERTOS_SO_RCVTIMEO * parameter with FreeRTOS_setsockopt(). Note: Infinite block times should be @@ -1296,6 +1810,7 @@ * set ipconfigSOCKET_HAS_USER_SEMAPHORE to one, then block on its own * semaphore. */ + #ifndef ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME #define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME portMAX_DELAY #endif @@ -1307,36 +1822,18 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME * + * Type: TickType_t + * Unit: Ticks + * Minimum: 0 + * Maximum: portMAX_DELAY + * * When writing to a socket, the write may not be able to proceed immediately. * For example, depending on the configuration, a write might have to wait for - * a network buffer to become available. API functions used to write data to a - * socket can block to wait for the write to succeed. - * ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME sets the default block time (defined in - * RTOS ticks). If ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME is not defined, then - * the default block time will be set to portMAX_DELAY - meaning an RTOS task - * that is blocked on a socket read will not leave the Blocked state until data - * is available. Note that tasks in the Blocked state do not consume any CPU - * time. - * - * ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME is specified in ticks. - * The macros pdMS_TO_TICKS() and portTICK_PERIOD_MS can both be used to - * convert a time specified in milliseconds to a time specified in ticks. - * - * The timeout time can be changed at any time using the FREERTOS_SO_SNDTIMEO - * parameter with FreeRTOS_setsockopt(). Note: Infinite block times should be - * used with extreme care in order to avoid a situation where all tasks are - * blocked indefinitely to wait for another RTOS task (which is also blocked - * indefinitely) to free a network buffer. - * - * A socket can be set to non-blocking mode by setting both the send and - * receive block time to 0. This might be desirable when an RTOS task is using - * more than one socket - in which case blocking can instead by performed on - * all the sockets at once using FreeRTOS_select(), or the RTOS task can set - * ipconfigSOCKET_HAS_USER_SEMAPHORE to one, then block on its own semaphore. + * a network buffer to become available. * - * A socket can be set to non-blocking mode by setting both the send and - * receive block time to 0. + * See ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME */ + #ifndef ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME #define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME portMAX_DELAY #endif @@ -1348,24 +1845,24 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigSOCKET_HAS_USER_SEMAPHORE * - * By default, sockets will block on a send or receive that cannot complete - * immediately. See the description of the - * ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME and - * ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME parameters. - * - * If an RTOS task is using multiple sockets and cannot block on one socket at - * a time, then the sockets can be set into non-blocking mode, and the RTOS - * task can block on all the sockets at once by either using the - * FreeRTOS_select() function or by setting ipconfigSOCKET_HAS_USER_SEMAPHORE - * to 1, using the FREERTOS_SO_SET_SEMAPHORE parameter with - * FreeRTOS_setsockopt() to provide a semaphore to the socket, and then - * blocking on the semaphore. The semaphore will be given when any of the - * sockets are able to proceed - at which time the RTOS task can inspect all - * the sockets individually using non blocking API calls to determine which - * socket caused it to unblock. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Allows a semaphore to be provided that will be given after important events + * to wake up the user. + * + * Set by calling FreeRTOS_setsockopt() with the FREERTOS_SO_SET_SEMAPHORE + * option and a pointer to a semaphore. + * + * Can be used with non-blocking sockets as an alternative to + * FreeRTOS_select in order to handle multiple sockets at once. */ + #ifndef ipconfigSOCKET_HAS_USER_SEMAPHORE - #define ipconfigSOCKET_HAS_USER_SEMAPHORE 0 + #define ipconfigSOCKET_HAS_USER_SEMAPHORE ipconfigDISABLE +#endif + +#if ( ( ipconfigSOCKET_HAS_USER_SEMAPHORE != ipconfigDISABLE ) && ( ipconfigSOCKET_HAS_USER_SEMAPHORE != ipconfigENABLE ) ) + #error ipconfigSOCKET_HAS_USER_SEMAPHORE should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -1375,26 +1872,35 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigSOCKET_HAS_USER_WAKE_CALLBACK * - * It is possible to install an application hook that will be called after - * every essential socket event. The hook has one parameter: the socket, and it - * has no return value: - * typedef void (* SocketWakeupCallback_t)( Socket_t pxSocket ); - * The reason for calling the hook can be one or more of these events: + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables usage of an application defined hook that will be called after + * one of the following events: + * + * eSOCKET_RECEIVE = 0x0001, * Reception of new data. * + * eSOCKET_SEND = 0x0002, * Some data has been sent. * + * eSOCKET_ACCEPT = 0x0004, * A new TCP client was detected, please call accept(). * + * eSOCKET_CONNECT = 0x0008, * A TCP connect has succeeded or timed-out. * + * eSOCKET_BOUND = 0x0010, * A socket got bound. * + * eSOCKET_CLOSED = 0x0020, * A TCP connection got closed. * + * eSOCKET_INTR = 0x0040, * A blocking API call got interrupted, because + * * the function FreeRTOS_SignalSocket() was called. * + * + * It is not a good idea to do a lot of processing in any of the application + * hooks. Normally the hook will only notify the task that owns the socket so + * that the socket gets immediate attention. * - * eSOCKET_RECEIVE = 0x0001, /* Reception of new data. * - * eSOCKET_SEND = 0x0002, /* Some data has been sent. * - * eSOCKET_ACCEPT = 0x0004, /* A new TCP client was detected, please call accept(). * - * eSOCKET_CONNECT = 0x0008, /* A TCP connect has succeeded or timed-out. * - * eSOCKET_BOUND = 0x0010, /* A socket got bound. * - * eSOCKET_CLOSED = 0x0020, /* A TCP connection got closed. * - * eSOCKET_INTR = 0x0040, /* A blocking API call got interrupted, because - * * the function FreeRTOS_SignalSocket() was called. * + * Function prototype: * - * Normally the hook will only notify the task that owns the socket so that the - * socket gets immediate attention. + * typedef void (* SocketWakeupCallback_t)( Socket_t pxSocket ) */ + #ifndef ipconfigSOCKET_HAS_USER_WAKE_CALLBACK - #define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK 0 + #define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ipconfigDISABLE +#endif + +#if ( ( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK != ipconfigDISABLE ) && ( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK != ipconfigENABLE ) ) + #error ipconfigSOCKET_HAS_USER_WAKE_CALLBACK should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -1404,13 +1910,23 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigSUPPORT_SIGNALS * - * If ipconfigSUPPORT_SIGNALS is set to 1 then the FreeRTOS_SignalSocket() API - * function is included in the build. FreeRTOS_SignalSocket() can be used to - * send a signal to a socket, so that any task blocked on a read from the - * socket will leave the Blocked state (abort the blocking read operation). + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Advanced users only. + * + * Include support for FreeRTOS_SignalSocket(). + * + * Used to interrupt a socket during a blocked read allowing the task proceed. + * A signal interruption can be distinguished from a read through the return + * value -pdFREERTOS_ERRNO_EINTR. */ + #ifndef ipconfigSUPPORT_SIGNALS - #define ipconfigSUPPORT_SIGNALS 0 + #define ipconfigSUPPORT_SIGNALS ipconfigDISABLE +#endif + +#if ( ( ipconfigSUPPORT_SIGNALS != ipconfigDISABLE ) && ( ipconfigSUPPORT_SIGNALS != ipconfigENABLE ) ) + #error ipconfigSUPPORT_SIGNALS should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -1420,79 +1936,109 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_CALLBACKS * - * When this macro is defined as non-zero, it is possible to bind specific - * application hooks (callbacks) to a socket. There is a different application - * hook for every type of event: - * - * FREERTOS_SO_TCP_CONN_HANDLER * Callback for (dis) connection events. - * * Supply pointer to 'F_TCP_UDP_Handler_t' - * FREERTOS_SO_TCP_RECV_HANDLER * Callback for receiving TCP data. - * * Supply pointer to 'F_TCP_UDP_Handler_t' - * FREERTOS_SO_TCP_SENT_HANDLER * Callback for sending TCP data. - * * Supply pointer to 'F_TCP_UDP_Handler_t' - * FREERTOS_SO_UDP_RECV_HANDLER * Callback for receiving UDP data. - * * Supply pointer to 'F_TCP_UDP_Handler_t' - * FREERTOS_SO_UDP_SENT_HANDLER * Callback for sending UDP data. - * * Supply pointer to 'F_TCP_UDP_Handler_t' + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Advanced users only. + * + * Allows usage of application defined hooks for socket events. + * + * Can be set by calling FreeRTOS_setsockopt() with any of the following + * options and a pointer to a F_TCP_UDP_Handler_t. + * + * FREERTOS_SO_TCP_CONN_HANDLER * Callback for (dis)connection events. * + * FREERTOS_SO_TCP_RECV_HANDLER * Callback for receiving TCP data. * + * FREERTOS_SO_TCP_SENT_HANDLER * Callback for sending TCP data. * + * FREERTOS_SO_UDP_RECV_HANDLER * Callback for receiving UDP data. * + * FREERTOS_SO_UDP_SENT_HANDLER * Callback for sending UDP data. * + * + * typedef struct xTCP_UDP_HANDLER + * { + * FOnConnected_t pxOnTCPConnected; * FREERTOS_SO_TCP_CONN_HANDLER * + * FOnTCPReceive_t pxOnTCPReceive; * FREERTOS_SO_TCP_RECV_HANDLER * + * FOnTCPSent_t pxOnTCPSent; * FREERTOS_SO_TCP_SENT_HANDLER * + * FOnUDPReceive_t pxOnUDPReceive; * FREERTOS_SO_UDP_RECV_HANDLER * + * FOnUDPSent_t pxOnUDPSent; * FREERTOS_SO_UDP_SENT_HANDLER * + * } F_TCP_UDP_Handler_t + * + * Function Prototypes: + * + * typedef void (* FOnConnected_t )( Socket_t xSocket, + * BaseType_t ulConnected ) + * + * typedef BaseType_t (* FOnTCPReceive_t )( Socket_t xSocket, + * void * pData, + * size_t xLength ) + * + * typedef void (* FOnTCPSent_t )( Socket_t xSocket, + * size_t xLength ) + * + * typedef BaseType_t (* FOnUDPReceive_t ) ( Socket_t xSocket, + * void * pData, + * size_t xLength, + * const struct freertos_sockaddr * pxFrom, + * const struct freertos_sockaddr * pxDest ) + * + * typedef void (* FOnUDPSent_t )( Socket_t xSocket, + * size_t xLength ); */ + #ifndef ipconfigUSE_CALLBACKS - #define ipconfigUSE_CALLBACKS 0 + #define ipconfigUSE_CALLBACKS ipconfigDISABLE +#endif + +#if ( ( ipconfigUSE_CALLBACKS != ipconfigDISABLE ) && ( ipconfigUSE_CALLBACKS != ipconfigENABLE ) ) + #error ipconfigUSE_CALLBACKS should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ -#if ( ipconfigUSE_CALLBACKS != 0 ) +#if ( ipconfigIS_ENABLED( ipconfigUSE_CALLBACKS ) ) + +/*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ +/* + * ipconfigIS_VALID_PROG_ADDRESS + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigIS_VALID_PROG_ADDRESS + * + * Type: Macro Function + * Value: BaseType_t ( pdTRUE | pdFALSE ) + * + * Verifies that a given address refers to valid (instruction) memory. + * + * Used to check if application defined hooks are valid. + * + * Example: + * if( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleSent ) ) + * { + * pxSocket->u.xTCP.pxHandleSent( pxSocket, ulCount ); + * } + */ - /* - * ipconfigIS_VALID_PROG_ADDRESS - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigIS_VALID_PROG_ADDRESS - * - * In cases where installable application hooks are used, this macro is - * called to check if a given address refers to valid (instruction) memory. - * This is a small example taken from FreeRTOS_TCP_IP.c: - * - * if( ipconfigIS_VALID_PROG_ADDRESS( pxSocket->u.xTCP.pxHandleSent ) ) - * { - * pxSocket->u.xTCP.pxHandleSent( pxSocket, ulCount ); - * } - */ #ifndef ipconfigIS_VALID_PROG_ADDRESS - #define ipconfigIS_VALID_PROG_ADDRESS( pxAddress ) ( ( pxAddress ) != NULL ) + #define ipconfigIS_VALID_PROG_ADDRESS( pxAddress ) ( pxAddress != 0 ) #endif - /*-----------------------------------------------------------------------*/ + #if ( ( ipconfigIS_VALID_PROG_ADDRESS( 0 ) != 0 ) && ( ipconfigIS_VALID_PROG_ADDRESS( 0 ) != 1 ) ) + #error ipconfigIS_VALID_PROG_ADDRESS() should equate to pdFALSE or pdTRUE + #endif + +/*-----------------------------------------------------------------------*/ -#endif /* if ( ipconfigUSE_CALLBACKS != 0 ) */ +#endif /* if ( ipconfigIS_ENABLED( ipconfigUSE_CALLBACKS ) ) */ /*---------------------------------------------------------------------------*/ /* - * pvPortMallocSocket + * pvPortMallocSocket/vPortFreeSocket * - * Malloc functions. Within most applications of FreeRTOS, the couple - * pvPortMalloc()/vPortFree() will be used. - * If there are different types of RAM, the user may decide to use a different - * memory allocator for different purposes: - * MallocSocket is used to allocate the space for the sockets + * Malloc functions specific to sockets. */ + #ifndef pvPortMallocSocket - #define pvPortMallocSocket( x ) pvPortMalloc( x ) + #define pvPortMallocSocket( size ) pvPortMalloc( size ) #endif -/*---------------------------------------------------------------------------*/ - -/* - * vPortFreeSocket - * - * Malloc functions. Within most applications of FreeRTOS, the couple - * pvPortMalloc()/vPortFree() will be used. - * If there are different types of RAM, the user may decide to use a different - * memory allocator for different purposes: - * MallocSocket is used to allocate the space for the sockets - */ #ifndef vPortFreeSocket #define vPortFreeSocket( ptr ) vPortFree( ptr ) #endif @@ -1516,17 +2062,26 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_DHCP * - * If ipconfigUSE_DHCP is 1 then FreeRTOS-Plus-TCP will attempt to retrieve an - * IP address, netmask, DNS server address and gateway address from a DHCP - * server - and revert to using the defined static address if an IP address - * cannot be obtained. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Allows DHCP to be enabled by setting by setting `endpoint->bits.bWantDHCP`. * - * If ipconfigUSE_DHCP is 0 then FreeRTOS-Plus-TCP will not attempt to obtain - * its address information from a DHCP server. Instead, it will immediately use - * the defined static address information. + * When successful, DHCP will assign an IP-address, a netmask, a gateway + * address, and one or more DNS addresses to the endpoint. */ + #ifndef ipconfigUSE_DHCP - #define ipconfigUSE_DHCP 1 + #define ipconfigUSE_DHCP ipconfigENABLE +#endif + +#if ( ( ipconfigUSE_DHCP != ipconfigDISABLE ) && ( ipconfigUSE_DHCP != ipconfigENABLE ) ) + #error ipconfigUSE_DHCP should be pdFALSE or pdTRUE +#endif + +#if ( ( ipconfigUSE_DHCP != ipconfigDISABLE ) && ( ipconfigNETWORK_MTU < 586U ) ) +/* DHCP must be able to receive an options field of 312 bytes, the fixed + * part of the DHCP packet is 240 bytes, and the IP/UDP headers take 28 bytes. */ + #error ipconfigNETWORK_MTU needs to be at least 586 to use DHCP #endif /*---------------------------------------------------------------------------*/ @@ -1534,246 +2089,152 @@ /* * ipconfigUSE_DHCPv6 * - * Disable DHCPv6 by default. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Include support for DHCPv6. + * + * The use of DHCP can be enabled per endpoint by setting + * `endpoint->bits.bWantDHCP`. + * + * An alternative way of obtaining an IP-address is Router Advertisement ("RA"). + * As RA is generally preferred above DHCP, ipconfigUSE_RA is enabled and + * ipconfigUSE_DHCPv6 is disabled by default. */ + #ifndef ipconfigUSE_DHCPv6 - #define ipconfigUSE_DHCPv6 0 + #define ipconfigUSE_DHCPv6 ipconfigDISABLE #endif -/*---------------------------------------------------------------------------*/ +#if ( ( ipconfigUSE_DHCPv6 != ipconfigDISABLE ) && ( ipconfigUSE_DHCPv6 != ipconfigENABLE ) ) + #error ipconfigUSE_DHCPv6 should be pdFALSE or pdTRUE +#endif -#if ( ( ipconfigUSE_DHCPv6 != 0 ) && ( ipconfigUSE_IPv6 == 0 ) ) +#if ( ipconfigIS_ENABLED( ipconfigUSE_DHCPv6 ) && ipconfigIS_DISABLED( ipconfigUSE_IPv6 ) ) #error DHCPv6 Cannot be enabled without IPv6 #endif /*---------------------------------------------------------------------------*/ -#if ( ipconfigUSE_DHCP != 0 ) +#if ( ipconfigIS_ENABLED( ipconfigUSE_DHCP ) ) - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigDHCP_REGISTER_HOSTNAME + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDHCP_REGISTER_HOSTNAME + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables usage of an application defined hook to provide a hostname to a DHCP + * server. + * + * Function prototype: + * + * const char *pcApplicationHostnameHook( void ) + */ - /* - * ipconfigDHCP_REGISTER_HOSTNAME - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDHCP_REGISTER_HOSTNAME - * - * Often DHCP servers can show the names of devices that have leased IP - * addresses. When ipconfigDHCP_REGISTER_HOSTNAME is set to 1, the device - * running FreeRTOS-Plus-TCP can identify itself to a DHCP server with a - * human readable name by returning the name from an application provided - * hook (or 'callback') function called pcApplicationHostnameHook(). - * - * When ipconfigDHCP_REGISTER_HOSTNAME is set to 1 the application must - * provide a hook (callback) function with the following name and - * prototype: - * - * const char *pcApplicationHostnameHook( void ); - */ #ifndef ipconfigDHCP_REGISTER_HOSTNAME - #define ipconfigDHCP_REGISTER_HOSTNAME 0 - #endif - - /*-----------------------------------------------------------------------*/ - -#endif /* if ( ipconfigUSE_DHCP != 0 ) */ - -/*---------------------------------------------------------------------------*/ - -#if ( ( ipconfigUSE_DHCP != 0 ) || ( ipconfigUSE_DHCPv6 != 0 ) ) - - /*-----------------------------------------------------------------------*/ - - /* - * ipconfigUSE_DHCP_HOOK - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_DHCP_HOOK - * - * A normal DHCP transaction involves the following sequence: - * - * 1. The client sends a DHCP discovery packet to request an IP address - * from the DHCP server. - * - * 2. The DHCP server responds with an offer packet that contains the - * offered IP address. - * - * 3. The client sends a DHCP request packet in order to claim the - * offered IP address - * - * 4. The DHCP server sends an acknowledgement packet to grant the - * client use of the offered IP address, and to send additional - * configuration information to the client. Additional configuration - * information typically includes the IP address of the gateway, the IP - * address of the DNS server, and the IP address lease length. - * - * If ipconfigUSE_DHCP_HOOK is set to 1 then FreeRTOS-Plus-TCP will call an - * application provided hook (or 'callback') function called - * xApplicationDHCPUserHook() both before the initial discovery packet is - * sent, and after a DHCP offer has been received - the hook function can - * be used to terminate the DHCP process at either one of these two phases - * in the DHCP sequence. For example, the application writer can - * effectively disable DHCP, even when ipconfigUSE_DHCP is set to 1, by - * terminating the DHCP process before the initial discovery packet is - * sent. As another example, the application writer can check a static IP - * address is compatible with the network to which the device is connected - * by receiving an IP address offer from a DHCP server, but then - * terminating the DHCP process without sending a request packet to claim - * the offered IP address. - * - * If ipconfigUSE_DHCP_HOOK is set to 1, then the application writer must - * provide a hook (callback) function with the following name and - * prototype: - * - * eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase, - * uint32_t ulIPAddress ); - * - * Where eDHCPCallbackQuestion_t and eDHCPCallbackAnswer_t are defined as - * follows - * - * typedef enum eDHCP_QUESTIONS - * { - * /* About to send discover packet. - * eDHCPPhasePreDiscover, - * /* About to send a request packet. - * eDHCPPhasePreRequest, - * } eDHCPCallbackQuestion_t; - * - * typedef enum eDHCP_ANSWERS - * { - * /* Continue the DHCP process as normal. - * eDHCPContinue, - * /* Stop the DHCP process, and use the static defaults. - * eDHCPUseDefaults, - * /* Stop the DHCP process, and continue with current settings. - * eDHCPStopNoChanges, - * } eDHCPCallbackAnswer_t; - * - * For example purposes only, below is a reference xApplicationDHCPHook - * implementation that allows the DHCP sequence to proceed up to the point - * where an IP address is offered, at which point the offered IP address is - * compared to the statically configured IP address. If the offered and - * statically configured IP addresses are on the same subnet, then the - * statically configured IP address is used. If the offered and statically - * configured IP addresses are not on the same subnet, then the IP address - * offered by the DHCP server is used. - * - * eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase, - * uint32_t ulIPAddress ) - * { - * eDHCPCallbackAnswer_t eReturn; - * uint32_t ulStaticIPAddress, ulStaticNetMask; - * - * /* This hook is called in a couple of places during the DHCP process, as - * identified by the eDHCPPhase parameter. * - * switch( eDHCPPhase ) - * { - * case eDHCPPhasePreDiscover : - * /* A DHCP discovery is about to be sent out. eDHCPContinue is - * returned to allow the discovery to go out. - * - * If eDHCPUseDefaults had been returned instead then the DHCP process - * would be stopped and the statically configured IP address would be - * used. - * - * If eDHCPStopNoChanges had been returned instead then the DHCP - * process would be stopped and whatever the current network - * configuration was would continue to be used. * - * eReturn = eDHCPContinue; - * break; - * - * case eDHCPPhasePreRequest : - * /* An offer has been received from the DHCP server, and the - * offered IP address is passed in the ulIPAddress parameter. - * Convert the offered and statically allocated IP addresses to - * 32-bit values. * - * ulStaticIPAddress = FreeRTOS_inet_addr_quick( configIP_ADDR0, - * configIP_ADDR1, - * configIP_ADDR2, - * configIP_ADDR3 ); - * - * ulStaticNetMask = FreeRTOS_inet_addr_quick( configNET_MASK0, - * configNET_MASK1, - * configNET_MASK2, - * configNET_MASK3 ); - * - * /* Mask the IP addresses to leave just the sub-domain - * octets. * - * ulStaticIPAddress &= ulStaticNetMask; - * ulIPAddress &= ulStaticNetMask; - * - * /* Are the sub-domains the same? * - * if( ulStaticIPAddress == ulIPAddress ) - * { - * /* The sub-domains match, so the default IP address can be - * used. The DHCP process is stopped at this point. * - * eReturn = eDHCPUseDefaults; - * } - * else - * { - * /* The sub-domains don't match, so continue with the - * DHCP process so the offered IP address is used. * - * eReturn = eDHCPContinue; - * } - * - * break; - * - * default : - * /* Cannot be reached, but set eReturn to prevent compiler - * warnings where compilers are disposed to generating one. * - * eReturn = eDHCPContinue; - * break; - * } - * - * return eReturn; - * } - * - * When the eDHCPPhase parameter is set to eDHCPPhasePreDiscover, the - * ulIPAddress parameter is set to the IP address already in use. When the - * eDHCPPhase parameter is set to eDHCPPhasePreRequest, the ulIPAddress - * parameter is set to the IP address offered by the DHCP server. - */ + #define ipconfigDHCP_REGISTER_HOSTNAME ipconfigDISABLE + #endif + + #if ( ( ipconfigDHCP_REGISTER_HOSTNAME != ipconfigDISABLE ) && ( ipconfigDHCP_REGISTER_HOSTNAME != ipconfigENABLE ) ) + #error ipconfigDHCP_REGISTER_HOSTNAME should be pdFALSE or pdTRUE + #endif + +/*-----------------------------------------------------------------------*/ + +#endif /* if ( ipconfigIS_ENABLED( ipconfigUSE_DHCP ) ) */ + +/*---------------------------------------------------------------------------*/ + +#if ( ipconfigIS_ENABLED( ipconfigUSE_DHCP ) || ipconfigIS_ENABLED( ipconfigUSE_DHCPv6 ) ) + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigUSE_DHCP_HOOK + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_DHCP_HOOK + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables usage of an application defined hook during the DHCP process before + * the initial discovery packet is sent, and after a DHCP offer has been + * received. + * + * Function Prototype: + * + * eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase, + * uint32_t ulIPAddress ) + */ + #ifndef ipconfigUSE_DHCP_HOOK - #define ipconfigUSE_DHCP_HOOK 1 + #define ipconfigUSE_DHCP_HOOK ipconfigENABLE + #endif + + #if ( ( ipconfigUSE_DHCP_HOOK != ipconfigDISABLE ) && ( ipconfigUSE_DHCP_HOOK != ipconfigENABLE ) ) + #error ipconfigUSE_DHCP_HOOK should be pdFALSE or pdTRUE #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigDHCP_FALL_BACK_AUTO_IP + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * If no DHCP server responds, allocate a random LinkLayer IP address. + * + * Requires ipconfigARP_USE_CLASH_DETECTION to be enabled as well in order to + * test if it is still available. + * + * An alternative is to resort to a static IP address. + */ - /* - * ipconfigDHCP_FALL_BACK_AUTO_IP - * - * Only applicable when DHCP is in use. If no DHCP server responds, use - * "Auto-IP"; the device will allocate a random LinkLayer IP address, and - * test if it is still available. - */ #ifndef ipconfigDHCP_FALL_BACK_AUTO_IP - #define ipconfigDHCP_FALL_BACK_AUTO_IP 0 - #endif - - /*-----------------------------------------------------------------------*/ - - /* - * ipconfigMAXIMUM_DISCOVER_TX_PERIOD - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigMAXIMUM_DISCOVER_TX_PERIOD - * - * When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at - * increasing time intervals until either a reply is received from a DHCP - * server and accepted, or the interval between transmissions reaches - * ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The TCP/IP stack will revert to - * using the static IP address passed as a parameter to FreeRTOS_IPInit() - * if the re-transmission time interval reaches - * ipconfigMAXIMUM_DISCOVER_TX_PERIOD without a DHCP reply being received. - */ + #define ipconfigDHCP_FALL_BACK_AUTO_IP ipconfigDISABLE + #endif + + #if ( ( ipconfigDHCP_FALL_BACK_AUTO_IP != ipconfigDISABLE ) && ( ipconfigDHCP_FALL_BACK_AUTO_IP != ipconfigENABLE ) ) + #error ipconfigDHCP_FALL_BACK_AUTO_IP should be pdFALSE or pdTRUE + #endif + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigMAXIMUM_DISCOVER_TX_PERIOD + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigMAXIMUM_DISCOVER_TX_PERIOD + * + * Type: TickType_t + * Unit: Ticks + * Minimum: 0 + * Maximum: portMAX_DELAY + * + * Sets the max interval allowed between transmissions of DHCP requests before + * the default IP address will be used. + * + * When 'endpoint->bits.bWantDHCP' is set, DHCP requests will be sent out at + * increasing time intervals until either a reply is received from a DHCP + * server and accepted, or the interval between transmissions reaches + * ipconfigMAXIMUM_DISCOVER_TX_PERIOD. If no reply is received, the TCP/IP + * stack will revert to using the default IP address of the endpoint + * 'endpoint->ipv4_defaults.ulIPAddress' or + * 'endpoint->ipv6_defaults.xIPAddress'. + */ + #ifndef ipconfigMAXIMUM_DISCOVER_TX_PERIOD #ifdef _WINDOWS_ - #define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( pdMS_TO_TICKS( 999U ) ) + #define ipconfigMAXIMUM_DISCOVER_TX_PERIOD pdMS_TO_TICKS( 999 ) #else - #define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( pdMS_TO_TICKS( 30000U ) ) + #define ipconfigMAXIMUM_DISCOVER_TX_PERIOD pdMS_TO_TICKS( 30000 ) #endif #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ -#endif /* if ( ( ipconfigUSE_DHCP != 0 ) || ( ipconfigUSE_DHCPv6 != 0 ) ) */ +#endif /* if ( ipconfigIS_ENABLED( ipconfigUSE_DHCP ) || ipconfigIS_ENABLED( ipconfigUSE_DHCPv6 ) ) */ /*---------------------------------------------------------------------------*/ @@ -1794,173 +2255,244 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_DNS * - * Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used - * through the FreeRTOS_gethostbyname() API function. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enable ipconfigUSE_DNS to include a basic DNS client/resolver. DNS is used + * through functions like FreeRTOS_getaddrinfo() and FreeRTOS_gethostbyname(). + * + * Allows name discovery protocols like mDNS, LLMNR and NBNS to be enabled as + * well. + * + * See: ipconfigUSE_MDNS, ipconfigUSE_LLMNR, ipconfigUSE_NBNS */ + #ifndef ipconfigUSE_DNS - #define ipconfigUSE_DNS 1 + #define ipconfigUSE_DNS ipconfigENABLE #endif -/*---------------------------------------------------------------------------*/ +#if ( ( ipconfigUSE_DNS != ipconfigDISABLE ) && ( ipconfigUSE_DNS != ipconfigENABLE ) ) + #error ipconfigUSE_DNS should be pdFALSE or pdTRUE +#endif -#if ( ipconfigUSE_DNS != 0 ) +/*---------------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ +#if ( ipconfigIS_ENABLED( ipconfigUSE_DNS ) ) - /* - * ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY - * - * When looking up a URL, multiple answers (IP-addresses) may be received. - * This macro determines how many answers will be stored per URL. - */ - #ifndef ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY - #define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY 1U - #endif +/*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ +/* + * ipconfigUSE_DNS_CACHE + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_DNS_CACHE + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables usage of the DNS cache. + */ - /* - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_DNS_CACHE - * - * ipconfigUSE_DNS_CACHE - * - * If ipconfigUSE_DNS_CACHE is set to 1, then the DNS cache will be - * enabled. If ipconfigUSE_DNS_CACHE is set to 0, then the DNS cache will - * be disabled. - */ #ifndef ipconfigUSE_DNS_CACHE - #define ipconfigUSE_DNS_CACHE 1 + #define ipconfigUSE_DNS_CACHE ipconfigENABLE + #endif + + #if ( ( ipconfigUSE_DNS_CACHE != ipconfigDISABLE ) && ( ipconfigUSE_DNS_CACHE != ipconfigENABLE ) ) + #error ipconfigUSE_DNS_CACHE should be pdFALSE or pdTRUE #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ + + #if ( ipconfigIS_ENABLED( ipconfigUSE_DNS_CACHE ) ) - #if ( ipconfigUSE_DNS_CACHE != 0 ) +/*-------------------------------------------------------------------*/ - /*-------------------------------------------------------------------*/ +/* + * ipconfigDNS_CACHE_ENTRIES + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDNS_CACHE_ENTRIES + * + * Type: size_t + * Unit: count of DNS cache entries + * Minimum: 1 + * + * Defines the number of entries in the DNS cache. + */ - /* - * ipconfigDNS_CACHE_ENTRIES - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDNS_CACHE_ENTRIES - * - * If ipconfigUSE_DNS_CACHE is set to 1 then ipconfigDNS_CACHE_ENTRIES - * defines the number of entries in the DNS cache. - */ #ifndef ipconfigDNS_CACHE_ENTRIES #define ipconfigDNS_CACHE_ENTRIES 1U #endif - /*-------------------------------------------------------------------*/ + #if ( ipconfigDNS_CACHE_ENTRIES < 1 ) + #error ipconfigDNS_CACHE_ENTRIES must be at least 1 + #endif + + #if ( ipconfigDNS_CACHE_ENTRIES > SIZE_MAX ) + #error ipconfigDNS_CACHE_ENTRIES overflows a size_t + #endif + +/*-------------------------------------------------------------------*/ + +/* + * ipconfigDNS_CACHE_NAME_LENGTH + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDNS_CACHE_NAME_LENGTH + * + * Type: size_t + * Unit: count of hostname chars + * Minimum: 1 + * + * The maximum number of characters a DNS host name can take, including + * the NULL terminator. + * + * Stack warning: the function DNS_ParseDNSReply() declares a local object + * of type 'ParseSet_t', which contains a copy of an URL: + * + * char pcName[ ipconfigDNS_CACHE_NAME_LENGTH ]; + * + * plus another 52 bytes. + */ - /* - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDNS_CACHE_NAME_LENGTH - * - * ipconfigDNS_CACHE_NAME_LENGTH - * - * The maximum number of characters a DNS host name can take, including - * the NULL terminator. - */ #ifndef ipconfigDNS_CACHE_NAME_LENGTH #define ipconfigDNS_CACHE_NAME_LENGTH 254U #endif - /*-------------------------------------------------------------------*/ - - #endif /* if ( ipconfigUSE_DNS_CACHE != 0 ) */ - - /*-----------------------------------------------------------------------*/ - - /* - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDNS_REQUEST_ATTEMPTS - * - * ipconfigDNS_REQUEST_ATTEMPTS - * - * When looking up a host, the library has to send a DNS request and wait - * for a result. This process will be repeated at most - * ipconfigDNS_REQUEST_ATTEMPTS times. The macro - * ipconfigDNS_SEND_BLOCK_TIME_TICKS determines how long the function - * FreeRTOS_sendto() may block. - * - * When sending, by default, the function will block for at most 500 - * milliseconds. When waiting for a reply, FreeRTOS_recvfrom() will wait - * for at most 5000 milliseconds. - */ + #if ( ipconfigDNS_CACHE_NAME_LENGTH < 1 ) + #error ipconfigDNS_CACHE_NAME_LENGTH must be at least 1 + #endif + + #if ( ipconfigDNS_CACHE_NAME_LENGTH > SIZE_MAX ) + #error ipconfigDNS_CACHE_NAME_LENGTH overflows a size_t + #endif + +/*-------------------------------------------------------------------*/ + + #endif /* if ( ipconfigIS_ENABLED( ipconfigUSE_DNS_CACHE ) ) */ + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + * + * Type: size_t + * Unit: count of IP addresses + * Minimum: 1 + * + * Sets how many IP addresses can be stored when looking up a URL. + */ + + #ifndef ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + #define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY 1U + #endif + + #if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY < 1 ) + #error ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY must be at least 1 + #endif + + #if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > SIZE_MAX ) + #error ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY overflows a size_t + #endif + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigDNS_REQUEST_ATTEMPTS + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDNS_REQUEST_ATTEMPTS + * + * Type: size_t + * Unit: count of request attempts + * Minimum: 1 + * + * Sets the most amount of times the library can send a DNS result and wait for + * a result when looking up a host. + * + * See ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS & ipconfigDNS_SEND_BLOCK_TIME_TICKS + */ + #ifndef ipconfigDNS_REQUEST_ATTEMPTS #define ipconfigDNS_REQUEST_ATTEMPTS 5U #endif - /*-----------------------------------------------------------------------*/ + #if ( ipconfigDNS_REQUEST_ATTEMPTS < 1 ) + #error ipconfigDNS_REQUEST_ATTEMPTS must be at least 1 + #endif + + #if ( ipconfigDNS_REQUEST_ATTEMPTS > SIZE_MAX ) + #error ipconfigDNS_REQUEST_ATTEMPTS overflows a size_t + #endif + +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS + * + * Type: TickType_t + * Unit: Ticks + * Minimum: 0 + * Maximum: portMAX_DELAY + * + * See ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME + * + * Applies to DNS socket only. + */ - /* - * ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS - * - * When waiting for a reply, FreeRTOS_recvfrom() will wait for at most 5000 - * milliseconds. - */ #ifndef ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS - #define ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS pdMS_TO_TICKS( 5000U ) + #define ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS pdMS_TO_TICKS( 5000 ) #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigDNS_SEND_BLOCK_TIME_TICKS + * + * Type: TickType_t + * Unit: Ticks + * Minimum: 0 + * Maximum: portMAX_DELAY + * + * See ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME + * + * Applies to DNS socket only. + */ - /* - * ipconfigDNS_SEND_BLOCK_TIME_TICKS - * - * The macro ipconfigDNS_SEND_BLOCK_TIME_TICKS determines how long the - * function FreeRTOS_sendto() may block. When sending, by default, the - * function will block for at most 500 milliseconds. - */ #ifndef ipconfigDNS_SEND_BLOCK_TIME_TICKS - #define ipconfigDNS_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 500U ) - #endif - - /*-----------------------------------------------------------------------*/ - - /* - * ipconfigDNS_USE_CALLBACKS - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDNS_USE_CALLBACKS - * - * When defined, the function FreeRTOS_gethostbyname_a() becomes available. - * This function will start a DNS-lookup and set an application 'hook'. - * This user function (or 'hook') will be called when either the URL has - * been found, or when a time-out has been reached. Note that the function - * FreeRTOS_gethostbyname_a() will not make use of the macros - * ipconfigDNS_SEND_BLOCK_TIME_TICKS and - * ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS. - */ - #ifndef ipconfigDNS_USE_CALLBACKS - #define ipconfigDNS_USE_CALLBACKS 0 + #define ipconfigDNS_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 500 ) #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigDNS_USE_CALLBACKS + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigDNS_USE_CALLBACKS + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables callback functionality in the DNS process. + * + * Application defined callbacks can be provided as parameters in calls + * to FreeRTOS_gethostbyname_a() & FreeRTOS_getaddrinfo_a(). These functions + * will start a DNS-lookup and call the callback when either the URL has been + * found, or when a time-out has been reached. These functions are + * non-blocking, the suffix "_a" stands for asynchronous. The callback can be + * canceled by using FreeRTOS_gethostbyname_cancel(). + * + * Function Prototype: + * + * void (* FOnDNSEvent ) ( const char * pcName, void * pvSearchID, struct freertos_addrinfo * pxAddressInfo ) + */ + + #ifndef ipconfigDNS_USE_CALLBACKS + #define ipconfigDNS_USE_CALLBACKS ipconfigDISABLE + #endif - /* - * ipconfigINCLUDE_FULL_INET_ADDR - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigINCLUDE_FULL_INET_ADDR - * - * Implementing FreeRTOS_inet_addr() necessitates the use of string - * handling routines, which are relatively large. To save code space, the - * full FreeRTOS_inet_addr() implementation is made optional, and a smaller - * and faster alternative called FreeRTOS_inet_addr_quick() is provided. - * FreeRTOS_inet_addr() takes an IP in decimal dot format (for example, - * "192.168.0.1") as its parameter. FreeRTOS_inet_addr_quick() takes an IP - * address as four separate numerical octets (for example, 192, 168, 0, 1) - * as its parameters. If ipconfigINCLUDE_FULL_INET_ADDR is set to 1, then - * both FreeRTOS_inet_addr() and FreeRTOS_indet_addr_quick() are available. - * If ipconfigINCLUDE_FULL_INET_ADDR is not set to 1, then only - * FreeRTOS_indet_addr_quick() is available. - */ - #ifndef ipconfigINCLUDE_FULL_INET_ADDR - #define ipconfigINCLUDE_FULL_INET_ADDR 1 + #if ( ( ipconfigDNS_USE_CALLBACKS != ipconfigDISABLE ) && ( ipconfigDNS_USE_CALLBACKS != ipconfigENABLE ) ) + #error ipconfigDNS_USE_CALLBACKS should be pdFALSE or pdTRUE #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ -#endif /* if ( ipconfigUSE_DNS != 0 ) */ +#endif /* if ( ipconfigIS_ENABLED( ipconfigUSE_DNS ) ) */ /*---------------------------------------------------------------------------*/ @@ -1969,14 +2501,21 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_LLMNR * - * Set ipconfigUSE_LLMNR to 1 to include LLMNR. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Include support for Link Local Multicast Name Resolution (LLMNR). */ + #ifndef ipconfigUSE_LLMNR - #define ipconfigUSE_LLMNR ( 0 ) + #define ipconfigUSE_LLMNR ipconfigDISABLE #endif -#if ( ( ipconfigUSE_LLMNR != 0 ) && ( ipconfigUSE_DNS == 0 ) ) - #error When either LLMNR is used, ipconfigUSE_DNS must be defined +#if ( ( ipconfigUSE_LLMNR != ipconfigDISABLE ) && ( ipconfigUSE_LLMNR != ipconfigENABLE ) ) + #error ipconfigUSE_LLMNR should be pdFALSE or pdTRUE +#endif + +#if ( ipconfigIS_ENABLED( ipconfigUSE_LLMNR ) && ipconfigIS_DISABLED( ipconfigUSE_DNS ) ) + #error When LLMNR is enabled, ipconfigUSE_DNS must also be enabled #endif /*---------------------------------------------------------------------------*/ @@ -1986,14 +2525,21 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_NBNS * - * Set ipconfigUSE_NBNS to 1 to include NBNS. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Include support for NetBIOS Name Service (NBNS). */ + #ifndef ipconfigUSE_NBNS - #define ipconfigUSE_NBNS 0 + #define ipconfigUSE_NBNS ipconfigDISABLE #endif -#if ( ( ipconfigUSE_NBNS != 0 ) && ( ipconfigUSE_DNS == 0 ) ) - #error When either NBNS is used, ipconfigUSE_DNS must be defined +#if ( ( ipconfigUSE_NBNS != ipconfigDISABLE ) && ( ipconfigUSE_NBNS != ipconfigENABLE ) ) + #error ipconfigUSE_NBNS should be pdFALSE or pdTRUE +#endif + +#if ( ipconfigIS_ENABLED( ipconfigUSE_NBNS ) && ipconfigIS_DISABLED( ipconfigUSE_DNS ) ) + #error When NBNS is enabled, ipconfigUSE_DNS must also be enabled #endif /*---------------------------------------------------------------------------*/ @@ -2001,14 +2547,21 @@ /* * ipconfigUSE_MDNS * - * Include support for MDNS: Multicast DNS. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Include support for Multicast DNS (MDNS). */ + #ifndef ipconfigUSE_MDNS - #define ipconfigUSE_MDNS 0 + #define ipconfigUSE_MDNS ipconfigDISABLE #endif -#if ( ( ipconfigUSE_MDNS != 0 ) && ( ipconfigUSE_DNS == 0 ) ) - #error When either MDNS is used, ipconfigUSE_DNS must be defined +#if ( ( ipconfigUSE_MDNS != ipconfigDISABLE ) && ( ipconfigUSE_MDNS != ipconfigENABLE ) ) + #error ipconfigUSE_MDNS should be pdFALSE or pdTRUE +#endif + +#if ( ipconfigIS_ENABLED( ipconfigUSE_MDNS ) && ipconfigIS_DISABLED( ipconfigUSE_DNS ) ) + #error When MDNS is enabled, ipconfigUSE_DNS must also be enabled #endif /*---------------------------------------------------------------------------*/ @@ -2030,23 +2583,35 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigARP_CACHE_ENTRIES * - * The ARP cache is a table that maps IP addresses to MAC addresses. + * Type: size_t + * Unit: count of arp cache entries + * Minimum: 1 * - * The IP stack can only send a UDP message to a remove IP address if it knowns + * Defines the maximum number of entries that can exist in the ARP table at any + * one time. + * + * The ARP cache is a table that maps IP addresses to MAC addresses. The IP + * stack can only send a UDP message to a remove IP address if it knowns * the MAC address associated with the IP address, or the MAC address of the * router used to contact the remote IP address. When a UDP message is received * from a remote IP address, the MAC address and IP address are added to the * ARP cache. When a UDP message is sent to a remote IP address that does not * already appear in the ARP cache, then the UDP message is replaced by a ARP * message that solicits the required MAC address information. - * - * ipconfigARP_CACHE_ENTRIES defines the maximum number of entries that can - * exist in the ARP table at any one time. */ + #ifndef ipconfigARP_CACHE_ENTRIES #define ipconfigARP_CACHE_ENTRIES 10U #endif +#if ( ipconfigARP_CACHE_ENTRIES < 1 ) + #error ipconfigARP_CACHE_ENTRIES must be at least 1 +#endif + +#if ( ipconfigARP_CACHE_ENTRIES > SIZE_MAX ) + #error ipconfigARP_CACHE_ENTRIES overflows a size_t +#endif + /*---------------------------------------------------------------------------*/ /* @@ -2054,62 +2619,79 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigARP_STORES_REMOTE_ADDRESSES * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * * Advanced users only. * - * ipconfigARP_STORES_REMOTE_ADDRESSES is provided for the case when a message - * that requires a reply arrives from the Internet, but from a computer - * attached to a LAN rather than via the defined gateway. Before replying to - * the message, the TCP/IP stack RTOS task will loop up the message's IP - * address in the ARP table - but if ipconfigARP_STORES_REMOTE_ADDRESSES is set - * to 0, then ARP will return the MAC address of the defined gateway, because - * the destination address is outside of the netmask. That might prevent the - * reply reaching its intended destination. - * - * If ipconfigARP_STORES_REMOTE_ADDRESSES is set to 1, then remote addresses - * will also be stored in the ARP table, along with the MAC address from which - * the message was received. This can allow the message in the scenario above + * Enables the storage of remote addresses in the ARP table along with the + * associated MAC address from which the message was received. + * + * Provided for the case when a message that requires a reply arrives from the + * Internet, but from a computer attached to a LAN rather than via the defined + * gateway. Before replying to the message, the TCP/IP stack RTOS task will + * loop up the message's IP address in the ARP table. If disabled then ARP will + * return the MAC address of the defined gateway because the destination + * address is outside of the netmask, which might prevent the reply reaching + * its intended destination. This macro can allow the message in this scenario * to be routed and delivered correctly. */ + #ifndef ipconfigARP_STORES_REMOTE_ADDRESSES - #define ipconfigARP_STORES_REMOTE_ADDRESSES 0 + #define ipconfigARP_STORES_REMOTE_ADDRESSES ipconfigDISABLE +#endif + +#if ( ( ipconfigARP_STORES_REMOTE_ADDRESSES != ipconfigDISABLE ) && ( ipconfigARP_STORES_REMOTE_ADDRESSES != ipconfigENABLE ) ) + #error ipconfigARP_STORES_REMOTE_ADDRESSES should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ -#if ( defined( ipconfigDHCP_FALL_BACK_AUTO_IP ) && ( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 ) ) +#if ( ipconfigIS_ENABLED( ipconfigUSE_DHCP ) && ipconfigIS_ENABLED( ipconfigDHCP_FALL_BACK_AUTO_IP ) ) - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ + +/* + * ipconfigARP_USE_CLASH_DETECTION + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigARP_USE_CLASH_DETECTION + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables the driver to test if an assigned link-layer address is already + * taken by another device by sending ARP requests. + * + * ipconfigDHCP_FALL_BACK_AUTO_IP requires this feature to be enabled. + */ - /* - * ipconfigARP_USE_CLASH_DETECTION - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigARP_USE_CLASH_DETECTION - * - * When a link-layer address is assigned, the driver will test if it is - * already taken by a different device by sending ARP requests. Therefore, - * ipconfigARP_USE_CLASH_DETECTION must be defined as non-zero. - */ #ifndef ipconfigARP_USE_CLASH_DETECTION - #define ipconfigARP_USE_CLASH_DETECTION 1 + #define ipconfigARP_USE_CLASH_DETECTION ipconfigENABLE + #endif + + #if ( ( ipconfigARP_USE_CLASH_DETECTION != ipconfigDISABLE ) && ( ipconfigARP_USE_CLASH_DETECTION != ipconfigENABLE ) ) + #error ipconfigARP_USE_CLASH_DETECTION should be pdFALSE or pdTRUE #endif - #if ( ipconfigARP_USE_CLASH_DETECTION == 0 ) - #error ipconfigARP_USE_CLASH_DETECTION should be defined as 1 when ipconfigDHCP_FALL_BACK_AUTO_IP is used. + #if ( ipconfigIS_DISABLED( ipconfigARP_USE_CLASH_DETECTION ) ) + #error When ipconfigDHCP_FALL_BACK_AUTO_IP is enabled, ipconfigARP_USE_CLASH_DETECTION must also be enabled #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ -#else /* if ( defined( ipconfigDHCP_FALL_BACK_AUTO_IP ) && ( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 ) ) */ +#else /* if ( ipconfigIS_ENABLED( ipconfigUSE_DHCP ) && ipconfigIS_ENABLED( ipconfigDHCP_FALL_BACK_AUTO_IP ) ) */ - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ #ifndef ipconfigARP_USE_CLASH_DETECTION - #define ipconfigARP_USE_CLASH_DETECTION 0 + #define ipconfigARP_USE_CLASH_DETECTION ipconfigDISABLE + #endif + + #if ( ipconfigIS_ENABLED( ipconfigARP_USE_CLASH_DETECTION ) ) + #error ipconfigARP_USE_CLASH_DETECTION is unused when ipconfigDHCP_FALL_BACK_AUTO_IP is disabled #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ -#endif /* if ( defined( ipconfigDHCP_FALL_BACK_AUTO_IP ) && ( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 ) ) */ +#endif /* if ( ipconfigIS_ENABLED( ipconfigUSE_DHCP ) && ipconfigIS_ENABLED( ipconfigDHCP_FALL_BACK_AUTO_IP ) ) */ /*---------------------------------------------------------------------------*/ @@ -2118,16 +2700,28 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigMAX_ARP_AGE * - * ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP - * table being created or refreshed and the entry being removed because it is - * stale. New ARP requests are sent for ARP cache entries that are nearing - * their maximum age. + * Type: uint8_t + * Unit: decaseconds + * Minimum: 0 + * + * Defines the maximum time between an entry in the ARP table being created or + * refreshed and the entry being removed because it is stale. New ARP requests + * are sent for ARP cache entries that are nearing their maximum age. * - * ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is - * equal to 1500 seconds (or 25 minutes). + * Units are derived from ipARP_TIMER_PERIOD_MS, which is 10000 ms or 10 sec. + * So, a value of 150 is equal to 1500 seconds. */ + #ifndef ipconfigMAX_ARP_AGE - #define ipconfigMAX_ARP_AGE 150U + #define ipconfigMAX_ARP_AGE UINT8_C( 150 ) +#endif + +#if ( ipconfigMAX_ARP_AGE < 0 ) + #error ipconfigMAX_ARP_AGE must be at least 0 +#endif + +#if ( ipconfigMAX_ARP_AGE > UINT8_MAX ) + #error ipconfigMAX_ARP_AGE overflows a uint8_t #endif /*---------------------------------------------------------------------------*/ @@ -2137,12 +2731,24 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigMAX_ARP_RETRANSMISSIONS * - * ARP requests that do not result in an ARP response will be re-transmitted a - * maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is - * aborted. + * Type: uint8_t + * Unit: count of retransmissions + * Minimum: 0 + * + * Sets the maximum amount of retransmissions of ARP requests that do not + * result in an ARP response before the ARP request is aborted. */ + #ifndef ipconfigMAX_ARP_RETRANSMISSIONS - #define ipconfigMAX_ARP_RETRANSMISSIONS 5U + #define ipconfigMAX_ARP_RETRANSMISSIONS UINT8_C( 5 ) +#endif + +#if ( ipconfigMAX_ARP_RETRANSMISSIONS < 0 ) + #error ipconfigMAX_ARP_RETRANSMISSIONS must be at least 0 +#endif + +#if ( ipconfigMAX_ARP_RETRANSMISSIONS > UINT8_MAX ) + #error ipconfigMAX_ARP_RETRANSMISSIONS overflows a uint8_t #endif /*---------------------------------------------------------------------------*/ @@ -2152,21 +2758,22 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_ARP_REMOVE_ENTRY * - * Advanced users only. - * - * If ipconfigUSE_ARP_REMOVE_ENTRY is set to 1 then - * ulARPRemoveCacheEntryByMac() is included in the build. - * ulARPRemoveCacheEntryByMac() uses a MAC address to look up, and then remove, - * an entry from the ARP cache. If the MAC address is found in the ARP cache, - * then the IP address associated with the MAC address is returned. If the MAC - * address is not found in the ARP cache, then 0 is returned. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) * - * uint32_t ulARPRemoveCacheEntryByMac( const MACAddress_t * pxMACAddress ); + * Advanced users only. * - * ulARPRemoveCacheEntryByMac() function prototype + * Include support for ulARPRemoveCacheEntryByMac() which uses a MAC address to + * look up and remove an entry from the ARP cache. If the MAC address is found + * in the ARP cache, then the IP address associated with the MAC address is + * returned, otherwise 0 is returned. */ + #ifndef ipconfigUSE_ARP_REMOVE_ENTRY - #define ipconfigUSE_ARP_REMOVE_ENTRY 0 + #define ipconfigUSE_ARP_REMOVE_ENTRY ipconfigDISABLE +#endif + +#if ( ( ipconfigUSE_ARP_REMOVE_ENTRY != ipconfigDISABLE ) && ( ipconfigUSE_ARP_REMOVE_ENTRY != ipconfigENABLE ) ) + #error ipconfigUSE_ARP_REMOVE_ENTRY should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -2176,20 +2783,23 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_ARP_REVERSED_LOOKUP * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * * Advanced users only. * - * Normally ARP will look up an IP address from a MAC address. If - * ipconfigUSE_ARP_REVERSED_LOOKUP is set to 1 then a function that does the - * reverse is also available. eARPGetCacheEntryByMac() looks up a MAC address + * Include support for eARPGetCacheEntryByMac() which looks up a MAC address * from an IP address. * - * eARPLookupResult_t eARPGetCacheEntryByMac( MACAddress_t * const pxMACAddress, - * uint32_t *pulIPAddress ); - * - * eARPGetCacheEntryByMac() function prototype + * ARP normally does the reverse by looking up an IP address from a MAC + * address. */ + #ifndef ipconfigUSE_ARP_REVERSED_LOOKUP - #define ipconfigUSE_ARP_REVERSED_LOOKUP 0 + #define ipconfigUSE_ARP_REVERSED_LOOKUP ipconfigDISABLE +#endif + +#if ( ( ipconfigUSE_ARP_REVERSED_LOOKUP != ipconfigDISABLE ) && ( ipconfigUSE_ARP_REVERSED_LOOKUP != ipconfigENABLE ) ) + #error ipconfigUSE_ARP_REVERSED_LOOKUP should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -2211,35 +2821,59 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigREPLY_TO_INCOMING_PINGS * - * If ipconfigREPLY_TO_INCOMING_PINGS is set to 1, then the TCP/IP stack will - * generate replies to incoming ICMP echo (ping) requests. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables generation of replies to incoming ICMP echo (ping) requests. + * + * Normally it is quite desirable when embedded devices respond to a ping + * request. Endpoints of the type IPv6 will reply to a ping request + * unconditionally. */ + #ifndef ipconfigREPLY_TO_INCOMING_PINGS - #define ipconfigREPLY_TO_INCOMING_PINGS 1 + #define ipconfigREPLY_TO_INCOMING_PINGS ipconfigENABLE +#endif + +#if ( ( ipconfigREPLY_TO_INCOMING_PINGS != ipconfigDISABLE ) && ( ipconfigREPLY_TO_INCOMING_PINGS != ipconfigENABLE ) ) + #error ipconfigREPLY_TO_INCOMING_PINGS should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ -#if ( ipconfigREPLY_TO_INCOMING_PINGS != 0 ) +#if ( ipconfigIS_ENABLED( ipconfigREPLY_TO_INCOMING_PINGS ) ) + +/*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ +/* + * ipconfigICMP_TIME_TO_LIVE + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigICMP_TIME_TO_LIVE + * + * Type: uint8_t + * Unit: 'hops' + * Minimum: 0 + * + * Sets the value of the TTL field when replying to an ICMP packet. + * + * Only used when replying to an ICMP IPv4 ping request. The default of 64 is + * recommended by RFC 1700. + */ - /* - * ipconfigICMP_TIME_TO_LIVE - * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigICMP_TIME_TO_LIVE - * - * When replying to an ICMP packet, the TTL field will be set to the value - * of this macro. The default value is 64 (as recommended by RFC 1700). - * The minimum value is 1, the maximum value is 255. - */ #ifndef ipconfigICMP_TIME_TO_LIVE - #define ipconfigICMP_TIME_TO_LIVE 64U + #define ipconfigICMP_TIME_TO_LIVE UINT8_C( 64 ) + #endif + + #if ( ipconfigICMP_TIME_TO_LIVE < 0 ) + #error ipconfigICMP_TIME_TO_LIVE must be at least 0 + #endif + + #if ( ipconfigICMP_TIME_TO_LIVE > UINT8_MAX ) + #error ipconfigICMP_TIME_TO_LIVE overflows a uint8_t #endif - /*-----------------------------------------------------------------------*/ +/*-----------------------------------------------------------------------*/ -#endif /* if ( ipconfigREPLY_TO_INCOMING_PINGS != 0 ) */ +#endif /* if ( ipconfigIS_ENABLED( ipconfigREPLY_TO_INCOMING_PINGS ) ) */ /*---------------------------------------------------------------------------*/ @@ -2248,11 +2882,18 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigSUPPORT_OUTGOING_PINGS * - * If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the - * FreeRTOS_SendPingRequest() API function is available. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Include support for FreeRTOS_SendPingRequest() and + * FreeRTOS_SendPingRequestIPv6() */ + #ifndef ipconfigSUPPORT_OUTGOING_PINGS - #define ipconfigSUPPORT_OUTGOING_PINGS 0 + #define ipconfigSUPPORT_OUTGOING_PINGS ipconfigDISABLE +#endif + +#if ( ( ipconfigSUPPORT_OUTGOING_PINGS != ipconfigDISABLE ) && ( ipconfigSUPPORT_OUTGOING_PINGS != ipconfigENABLE ) ) + #error ipconfigSUPPORT_OUTGOING_PINGS should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -2271,40 +2912,70 @@ /* * ipconfigCOMPATIBLE_WITH_SINGLE + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Retains compatibility with older versions that only supported one interface. */ + #ifndef ipconfigCOMPATIBLE_WITH_SINGLE - #define ipconfigCOMPATIBLE_WITH_SINGLE 0 + #define ipconfigCOMPATIBLE_WITH_SINGLE ipconfigDISABLE +#endif + +#if ( ( ipconfigCOMPATIBLE_WITH_SINGLE != ipconfigDISABLE ) && ( ipconfigCOMPATIBLE_WITH_SINGLE != ipconfigENABLE ) ) + #error ipconfigCOMPATIBLE_WITH_SINGLE should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ -#if ( ipconfigCOMPATIBLE_WITH_SINGLE == 0 ) +#if ( ipconfigIS_DISABLED( ipconfigCOMPATIBLE_WITH_SINGLE ) ) + +/*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ +/* + * ipconfigHAS_ROUTING_STATISTICS + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * This feature was only used while developing the IPv6/multi branch. + */ - /* - * ipconfigHAS_ROUTING_STATISTICS - */ #ifndef ipconfigHAS_ROUTING_STATISTICS - #define ipconfigHAS_ROUTING_STATISTICS 1 + #define ipconfigHAS_ROUTING_STATISTICS ipconfigENABLE #endif - /*-----------------------------------------------------------------------*/ + #if ( ( ipconfigHAS_ROUTING_STATISTICS != ipconfigDISABLE ) && ( ipconfigHAS_ROUTING_STATISTICS != ipconfigENABLE ) ) + #error ipconfigHAS_ROUTING_STATISTICS should be pdFALSE or pdTRUE + #endif -#else /* if ( ipconfigCOMPATIBLE_WITH_SINGLE == 0 ) */ +/*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ +#endif /* if ( ipconfigIS_DISABLED( ipconfigCOMPATIBLE_WITH_SINGLE ) ) */ - /* - * ipconfigMULTI_INTERFACE - */ - #ifndef ipconfigMULTI_INTERFACE - #define ipconfigMULTI_INTERFACE 1 - #endif +/*---------------------------------------------------------------------------*/ + +/* + * ipconfigMULTI_INTERFACE + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Used to let applications know that multiple interfaces are supported by + * this version of the TCP/IP stack. + * + * Must be enabled for demo applications to work. + */ + +#ifndef ipconfigMULTI_INTERFACE + #define ipconfigMULTI_INTERFACE ipconfigENABLE +#endif - /*-----------------------------------------------------------------------*/ +#if ( ( ipconfigMULTI_INTERFACE != ipconfigDISABLE ) && ( ipconfigMULTI_INTERFACE != ipconfigENABLE ) ) + #error ipconfigMULTI_INTERFACE should be pdFALSE or pdTRUE +#endif -#endif /* if ( ipconfigCOMPATIBLE_WITH_SINGLE == 0 ) */ +#if ( ipconfigIS_DISABLED( ipconfigMULTI_INTERFACE ) ) + #error ipconfigMULTI_INTERFACE must be enabled +#endif /*---------------------------------------------------------------------------*/ @@ -2325,104 +2996,90 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigCHECK_IP_QUEUE_SPACE * - * A FreeRTOS queue is used to send events from application tasks to the IP - * stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can - * be queued for processing at any one time. If ipconfigCHECK_IP_QUEUE_SPACE is - * set to 1 then the uxGetMinimumIPQueueSpace() function can be used to query - * the minimum amount of free space that has existed in the queue since the - * system booted. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables the IP-Task to track the run-time minimum free space that has + * existed in the event queue (uxQueueMinimumSpace). This value can be + * retrieved using the function uxGetMinimumIPQueueSpace(). * - * UBaseType_t uxGetMinimumIPQueueSpace( void ); + * Enables vPrintResourceStats() to log warnings about shrinking queue space. + * + * See ipconfigEVENT_QUEUE_LENGTH for setting the length of the event queue. */ + #ifndef ipconfigCHECK_IP_QUEUE_SPACE - #define ipconfigCHECK_IP_QUEUE_SPACE 0 + #define ipconfigCHECK_IP_QUEUE_SPACE ipconfigDISABLE +#endif + +#if ( ( ipconfigCHECK_IP_QUEUE_SPACE != ipconfigDISABLE ) && ( ipconfigCHECK_IP_QUEUE_SPACE != ipconfigENABLE ) ) + #error ipconfigCHECK_IP_QUEUE_SPACE should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ /* - * ipconfigHAS_DEBUG_PRINTF & FreeRTOS_debug_printf + * ipconfigHAS_DEBUG_PRINTF * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigHAS_DEBUG_PRINTF * - * The TCP/IP stack outputs debugging messages by calling the - * FreeRTOS_debug_printf macro. To obtain debugging messages set - * ipconfigHAS_DEBUG_PRINTF to 1, then define FreeRTOS_debug_printf() to a - * function that takes a printf() style format string and variable number of - * inputs, and sends the formatted messages to an output of your choice. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) * - * Do not define FreeRTOS_debug_printf if ipconfigHAS_DEBUG_PRINTF is set to 0. + * ipconfigHAS_DEBUG_PRINTF enables usage of the macro FreeRTOS_debug_printf to + * generate output messages mostly from the TCP/IP stack. * - * The following code is taken from the FreeRTOS-Plus-TCP example for the - * RTOS's Win32 simulator, which has the ability to output debugging messages - * to a UDP port, standard out, and to a disk file: + * Requires a reentrant application defined macro function + * FreeRTOS_debug_printf with a return value that is ignored. * - * Prototype for the function function that actually performs the output. + * Example: * - * extern void vLoggingPrintf( const char *pcFormatString, ... ); + * void vLoggingPrintf( const char *pcFormatString, ... ) * - * Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to - * 1 then FreeRTOS_debug_printf should be defined to the function used to print - * out the debugging messages. + * #define ipconfigHAS_DEBUG_PRINTF ipconfigENABLE + * #define FreeRTOS_debug_printf( X ) if( ipconfigIS_ENABLED( ipconfigHAS_DEBUG_PRINTF ) vLoggingPrintf X * - * #define ipconfigHAS_DEBUG_PRINTF 0 - * #if( ipconfigHAS_DEBUG_PRINTF == 1 ) - * #define FreeRTOS_debug_printf(X) vLoggingPrintf X - * #endif - * - * The function that performs the output (vLoggingPrintf() in the code above) - * must be reentrant. + * FreeRTOS_debug_printf( ( "FunctionName: Failed with error code: %u\n", xErrorCode ) ) */ + #ifndef ipconfigHAS_DEBUG_PRINTF - #define ipconfigHAS_DEBUG_PRINTF 0 + #define ipconfigHAS_DEBUG_PRINTF ipconfigDISABLE +#endif + +#if ( ( ipconfigHAS_DEBUG_PRINTF != ipconfigDISABLE ) && ( ipconfigHAS_DEBUG_PRINTF != ipconfigENABLE ) ) + #error ipconfigHAS_DEBUG_PRINTF should be pdFALSE or pdTRUE #endif #ifndef FreeRTOS_debug_printf - #define FreeRTOS_debug_printf( MSG ) do {} while( ipFALSE_BOOL ) + #define FreeRTOS_debug_printf( MSG ) if( ipconfigHAS_DEBUG_PRINTF ) configPRINTF #endif /*---------------------------------------------------------------------------*/ /* - * ipconfigHAS_PRINTF & FreeRTOS_printf + * ipconfigHAS_PRINTF * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigHAS_PRINTF * - * Some of the TCP/IP stack demo applications generate output messages. - * The TCP/IP stack outputs these messages by calling the FreeRTOS_printf - * macro. To obtain the demo application messages set ipconfigHAS_PRINTF to 1, - * then define FreeRTOS_printf() to a function that takes a printf() style - * format string and variable number of inputs, and sends the formatted - * messages to an output of your choice. - * - * Do not define FreeRTOS_printf if ipconfigHAS_PRINTF is set to 0. - * - * The following code is taken from the FreeRTOS-Plus-TCP example for the - * RTOS's Win32 simulator, which has the ability to output application messages - * to a UDP port, standard out, and to a disk file: + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) * - * Prototype for the function function that actually performs the output. + * ipconfigHAS_PRINTF enables usage of the macro FreeRTOS_printf to + * generate output messages mostly from TCP/IP stack demo applications. * - * extern void vLoggingPrintf( const char *pcFormatString, ... ); + * Requires a reentrant application defined macro function FreeRTOS_printf with + * a return value that is ignored. * - * Set to 1 to print out application messages. If ipconfigHAS_PRINTF is set to - * 1 then FreeRTOS_printf should be defined to the function used to print out - * the application messages. - * - * #define ipconfigHAS_PRINTF 0 - * #if( ipconfigHAS_PRINTF == 1 ) - * #define FreeRTOS_printf(X) vLoggingPrintf X - * #endif - * - * The function that performs the output (vLoggingPrintf() in the code above) - * must be reentrant. + * See ipconfigHAS_DEBUG_PRINTF */ + #ifndef ipconfigHAS_PRINTF - #define ipconfigHAS_PRINTF 0 + #define ipconfigHAS_PRINTF ipconfigDISABLE +#endif + +#if ( ( ipconfigHAS_PRINTF != ipconfigDISABLE ) && ( ipconfigHAS_PRINTF != ipconfigENABLE ) ) + #error ipconfigHAS_PRINTF should be pdFALSE or pdTRUE #endif #ifndef FreeRTOS_printf - #define FreeRTOS_printf( MSG ) do {} while( ipFALSE_BOOL ) + #define FreeRTOS_printf( MSG ) if( ipconfigHAS_PRINTF ) configPRINTF #endif /*---------------------------------------------------------------------------*/ @@ -2430,29 +3087,15 @@ /* * FreeRTOS_flush_logging * - * In cases where a lot of logging is produced, this will be called to give the - * logging module a chance to flush the data. - */ -#ifndef FreeRTOS_flush_logging - #define FreeRTOS_flush_logging() do {} while( ipFALSE_BOOL ) -#endif - -/*---------------------------------------------------------------------------*/ - -/* - * ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS + * Type: Macro Function * - * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS + * Macro that is called in cases where a lot of logging is produced. * - * The macro configINCLUDE_TRACE_RELATED_CLI_COMMANDS can be defined in - * FreeRTOSConfig.h. When defined, it will be assigned to - * ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS. It allows the inclusion - * of a CLI for tracing purposes. + * This gives the logging module a chance to flush the data. */ -#ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS - #define ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS 0 -#else - #define ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS configINCLUDE_TRACE_RELATED_CLI_COMMANDS + +#ifndef FreeRTOS_flush_logging + #define FreeRTOS_flush_logging() if( ipconfigHAS_PRINTF || ipconfigHAS_DEBUG_PRINTF ) do {} while( pdFALSE ) #endif /*---------------------------------------------------------------------------*/ @@ -2462,12 +3105,18 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_IP_SANITY * - * The name of this macro is a bit misleading: it only checks the behavior of - * the module BufferAllocation_1.c. It issues warnings when irregularities are - * detected. + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * Enables warnings when irregularities are detected when using + * BufferAllocation_1.c. */ + #ifndef ipconfigTCP_IP_SANITY - #define ipconfigTCP_IP_SANITY 0 + #define ipconfigTCP_IP_SANITY ipconfigDISABLE +#endif + +#if ( ( ipconfigTCP_IP_SANITY != ipconfigDISABLE ) && ( ipconfigTCP_IP_SANITY != ipconfigENABLE ) ) + #error ipconfigTCP_IP_SANITY should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ @@ -2477,15 +3126,24 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigTCP_MAY_LOG_PORT * - * ipconfigTCP_MAY_LOG_PORT( x ) can be defined to specify which port numbers - * should or should not be logged by FreeRTOS_lprintf(). For example, the - * following definition will not generate log messages for ports 23 or 2402: - * #define ipconfigTCP_MAY_LOG_PORT(xPort) ( ( ( xPort ) != 23 ) && ( ( xPort ) != 2402 ) ) + * Type: Macro Function + * + * Specifies which port numbers should be logged by FreeRTOS_debug_printf(). + * The return value should be a BaseType_t ( pdFALSE | pdTRUE ) + * For example, the following definition will not generate log messages for + * ports 23 or 2402: + * + * #define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( ( xPort ) != 23 ) && ( ( xPort ) != 2402 ) ) */ + #ifndef ipconfigTCP_MAY_LOG_PORT #define ipconfigTCP_MAY_LOG_PORT( xPort ) ( xPort != 23U ) #endif +#if ( ( ipconfigTCP_MAY_LOG_PORT( 0 ) != 0 ) && ( ipconfigTCP_MAY_LOG_PORT( 0 ) != 1 ) ) + #error ipconfigTCP_MAY_LOG_PORT() should equate to pdFALSE or pdTRUE +#endif + /*---------------------------------------------------------------------------*/ /* @@ -2493,59 +3151,102 @@ * * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigWATCHDOG_TIMER * - * ipconfigWATCHDOG_TIMER() is a macro that is called on each iteration of the - * IP task and may be useful if the application included watchdog type - * functionality that needs to know the IP task is still cycling - * (although the fact that the IP task is cycling does not necessarily indicate - * it is functioning correctly). + * Type: Macro Function + * + * Macro that is called on each iteration of the IP task. * - * ipconfigWATCHDOG_TIMER() can be defined to perform any action desired by the - * application writer. If ipconfigWATCHDOG_TIMER() is left undefined then it - * will be removed completely by the pre-processor (it will default to an empty - * macro). + * May be useful if the application includes watchdog type functionality that + * needs to know that the IP task is still cycling (although the fact that the + * IP task is cycling does not necessarily indicate it is functioning + * correctly). The return value is ignored. */ + #ifndef ipconfigWATCHDOG_TIMER - #define ipconfigWATCHDOG_TIMER() + #define ipconfigWATCHDOG_TIMER() do {} while( pdFALSE ) #endif /*---------------------------------------------------------------------------*/ /* * ipconfigUSE_DUMP_PACKETS + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * See this utility: tools/tcp_utilities/tcp_dump_packets.md + * + * Allow inclusion of a utility that writes of network packets to files. + * + * Useful for testing and development. Assumes the presence of full stdio + * disk access. */ + #ifndef ipconfigUSE_DUMP_PACKETS - #define ipconfigUSE_DUMP_PACKETS 0 + #define ipconfigUSE_DUMP_PACKETS ipconfigDISABLE +#endif + +#if ( ( ipconfigUSE_DUMP_PACKETS != ipconfigDISABLE ) && ( ipconfigUSE_DUMP_PACKETS != ipconfigENABLE ) ) + #error ipconfigUSE_DUMP_PACKETS should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ /* * ipconfigUSE_TCP_MEM_STATS + * + * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) + * + * See this utility: tools/tcp_utilities/tcp_mem_stats.md + * + * Allow inclusion of a utility that monitors all allocation and releases of + * network-related resources. + * + * After running for a while, it will print all data + * in a CSV format, which can be analysed in a spreadsheet program. */ + #ifndef ipconfigUSE_TCP_MEM_STATS - #define ipconfigUSE_TCP_MEM_STATS 0 + #define ipconfigUSE_TCP_MEM_STATS ipconfigDISABLE +#endif + +#if ( ( ipconfigUSE_TCP_MEM_STATS != ipconfigDISABLE ) && ( ipconfigUSE_TCP_MEM_STATS != ipconfigENABLE ) ) + #error ipconfigUSE_TCP_MEM_STATS should be pdFALSE or pdTRUE #endif /*---------------------------------------------------------------------------*/ -#if ( ipconfigUSE_TCP_MEM_STATS != 0 ) +#if ( ipconfigIS_ENABLED( ipconfigUSE_TCP_MEM_STATS ) ) + +/*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ +/* + * ipconfigTCP_MEM_STATS_MAX_ALLOCATION + * + * Type: size_t + * Unit: count of TCP_ALLOCATION_t + * Minimum: 1 + * + * Defines the maximum number of allocations that can be stored/monitored. + */ - /* - * ipconfigTCP_MEM_STATS_MAX_ALLOCATION - */ #ifndef ipconfigTCP_MEM_STATS_MAX_ALLOCATION #define ipconfigTCP_MEM_STATS_MAX_ALLOCATION 128U #endif - /*-----------------------------------------------------------------------*/ + #if ( ipconfigTCP_MEM_STATS_MAX_ALLOCATION < 1 ) + #error ipconfigTCP_MEM_STATS_MAX_ALLOCATION must be at least 1 + #endif + + #if ( ipconfigTCP_MEM_STATS_MAX_ALLOCATION > SIZE_MAX ) + #error ipconfigTCP_MEM_STATS_MAX_ALLOCATION overflows a size_t + #endif + +/*-----------------------------------------------------------------------*/ -#endif /* if ( ipconfigUSE_TCP_MEM_STATS != 0 ) */ +#endif /* if ( ipconfigIS_ENABLED( ipconfigUSE_TCP_MEM_STATS ) ) */ /*---------------------------------------------------------------------------*/ -/* Should only be included here, ensures trace config is set first */ +/* Should only be included here, ensures trace config is set first. */ #include "IPTraceMacroDefaults.h" /*---------------------------------------------------------------------------*/ @@ -2556,4 +3257,4 @@ /*---------------------------------------------------------------------------*/ /*===========================================================================*/ -#endif /* FREERTOS_IP_CONFIG_DEFAULTS_H */ +#endif /* FREERTOS_IP_CONFIG_DEFAULTS_H */ \ No newline at end of file