first commit

This commit is contained in:
fewikay committed 2026-10-16 13:08:06 +02:00
commit 92cbe97616
1978 files changed
+1688498

No files matched your search

@@ -0,0 +1,140 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/**
* @file FreeRTOSIPDeprecatedDefinitions.h
* @brief File that ensures defined configuration constants are using the most up to date naming.
*/
#ifndef FREERTOS_IP_DEPRECATED_DEFINITIONS_H
#define FREERTOS_IP_DEPRECATED_DEFINITIONS_H
#ifndef FREERTOS_IP_CONFIG_DEFAULTS_H
#error FreeRTOSIPConfigDefaults.h has not been included yet
#endif
#ifdef dnsMAX_REQUEST_ATTEMPTS
#error dnsMAX_REQUEST_ATTEMPTS is now called ipconfigDNS_REQUEST_ATTEMPTS
#endif
#ifdef FreeRTOS_lprintf
#error FreeRTOS_lprintf is now called FreeRTOS_debug_printf/FreeRTOS_printf
#endif
#ifdef HAS_TX_CRC_OFFLOADING
#error HAS_TX_CRC_OFFLOADING is deprecated
#endif
#ifdef HAS_RX_CRC_OFFLOADING
#error HAS_RX_CRC_OFFLOADING is deprecated
#endif
#ifdef ipconfigBUFFER_ALLOC_FIXED_SIZE
#error ipconfigBUFFER_ALLOC_FIXED_SIZE is deprecated
#endif
#ifdef ipconfigDHCP_USES_USER_HOOK
#error ipconfigDHCP_USES_USER_HOOK has been replaced by ipconfigUSE_DHCP_HOOK
#endif
#ifdef ipconfigDRIVER_INCLUDED_RX_IP_FILTERING
#error ipconfigDRIVER_INCLUDED_RX_IP_FILTERING is now called ipconfigETHERNET_DRIVER_FILTERS_PACKETS
#endif
#ifdef ipconfigHAS_INLINE_FUNCTIONS
#error ipconfigHAS_INLINE_FUNCTIONS is deprecated
#endif
#ifdef ipconfigMAX_SEND_BLOCK_TIME_TICKS
#error ipconfigMAX_SEND_BLOCK_TIME_TICKS is now called ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS
#endif
#ifdef ipconfigNIC_SEND_PASSES_DMA
#error ipconfigNIC_SEND_PASSES_DMA is now called ipconfigZERO_COPY_TX_DRIVER
#endif
#ifdef ipconfigNUM_NETWORK_BUFFERS
#error ipconfigNUM_NETWORK_BUFFERS is now now called ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS
#endif
#ifdef ipconfigRAND32
#error ipconfigRAND32 has been replaced by xApplicationGetRandomNumber( uint32_t *pulValue )
#endif
#ifdef ipconfigTCP_HANG_PROT
#error ipconfigTCP_HANG_PROT is now called ipconfigTCP_HANG_PROTECTION
#endif
#ifdef ipconfigTCP_HANG_PROT_TIME
#error ipconfigTCP_HANG_PROT_TIME is now called ipconfigTCP_HANG_PROTECTION_TIME
#endif
#ifdef ipconfigTCP_RX_BUF_LEN
#error ipconfigTCP_RX_BUF_LEN is now called ipconfigTCP_RX_BUFFER_LENGTH
#endif
#ifdef ipconfigTCP_TX_BUF_LEN
#error ipconfigTCP_TX_BUF_LEN is now called ipconfigTCP_TX_BUFFER_LENGTH
#endif
#ifdef ipconfigUDP_TASK_PRIORITY
#error ipconfigUDP_TASK_PRIORITY is now called ipconfigIP_TASK_PRIORITY
#endif
#ifdef ipconfigUDP_TASK_STACK_SIZE_WORDS
#error ipconfigUDP_TASK_STACK_SIZE_WORDS is now called ipconfigIP_TASK_STACK_SIZE_WORDS
#endif
#ifdef ipconfigUSE_RECEIVE_CONNECT_CALLBACKS
#error ipconfigUSE_RECEIVE_CONNECT_CALLBACKS is now called ipconfigUSE_CALLBACKS
#endif
#ifdef ipconfigUSE_TCP_TIMESTAMPS
#error ipconfigUSE_TCP_TIMESTAMPS is deprecated
#endif
#ifdef ipFILLER_SIZE
#error ipFILLER_SIZE is now called ipconfigPACKET_FILLER_SIZE
#endif
#ifdef tcpconfigIP_TIME_TO_LIVE
#error tcpconfigIP_TIME_TO_LIVE is now called ipconfigTCP_TIME_TO_LIVE
#endif
#ifdef updconfigIP_TIME_TO_LIVE
#error updconfigIP_TIME_TO_LIVE is now called ipconfigUDP_TIME_TO_LIVE
#endif
#ifdef PHY_LS_HIGH_CHECK_TIME_MS
#error PHY_LS_HIGH_CHECK_TIME_MS is now called ipconfigPHY_LS_HIGH_CHECK_TIME_MS
#endif
#ifdef PHY_LS_LOW_CHECK_TIME_MS
#error PHY_LS_LOW_CHECK_TIME_MS is now called ipconfigPHY_LS_LOW_CHECK_TIME_MS
#endif
#endif /* FREERTOS_IP_DEPRECATED_DEFINITIONS_H */
@@ -0,0 +1,182 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_ARP_H
#define FREERTOS_ARP_H
/* Application level configuration options. */
#include "FreeRTOSIPConfig.h"
#include "FreeRTOSIPConfigDefaults.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Routing.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/*-----------------------------------------------------------*/
/* Miscellaneous structure and definitions. */
/*-----------------------------------------------------------*/
/* A forward declaration of 'xNetworkInterface' which is
* declared in FreeRTOS_Routing.h */
struct xNetworkInterface;
struct xNetworkEndPoint;
/**
* Structure for one row in the ARP cache table.
*/
typedef struct xARP_CACHE_TABLE_ROW
{
uint32_t ulIPAddress; /**< The IP address of an ARP cache entry. */
MACAddress_t xMACAddress; /**< The MAC address of an ARP cache entry. */
uint8_t ucAge; /**< A value that is periodically decremented but can also be refreshed by active communication. The ARP cache entry is removed if the value reaches zero. */
uint8_t ucValid; /**< pdTRUE: xMACAddress is valid, pdFALSE: waiting for ARP reply */
struct xNetworkEndPoint
* pxEndPoint; /**< The end-point on which the MAC address was last seen. */
} ARPCacheRow_t;
/** @brief A structure used internally in FreeRTOS_ARP.c.
* It is used as a parameter for the function prvFindCacheEntry().*/
typedef struct xCacheLocation
{
BaseType_t xIpEntry; /**< The index of the matching IP-address. */
BaseType_t xMacEntry; /**< The index of the matching MAC-address. */
BaseType_t xUseEntry; /**< The index of the first free location. */
} CacheLocation_t;
/**
* Look for an IP-MAC couple in ARP cache and reset the 'age' field. If no match
* is found then no action will be taken.
*/
void vARPRefreshCacheEntryAge( const MACAddress_t * pxMACAddress,
const uint32_t ulIPAddress );
/*
* If ulIPAddress is already in the ARP cache table then reset the age of the
* entry back to its maximum value. If ulIPAddress is not already in the ARP
* cache table then add it - replacing the oldest current entry if there is not
* a free space available.
*/
void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress,
const uint32_t ulIPAddress,
struct xNetworkEndPoint * pxEndPoint );
#if ( ipconfigARP_USE_CLASH_DETECTION != 0 )
/* Becomes non-zero if another device responded to a gratuitous ARP message. */
extern BaseType_t xARPHadIPClash;
/* MAC-address of the other device containing the same IP-address. */
extern MACAddress_t xARPClashMacAddress;
#endif /* ipconfigARP_USE_CLASH_DETECTION */
#if ( ipconfigUSE_ARP_REMOVE_ENTRY != 0 )
/*
* In some rare cases, it might be useful to remove a ARP cache entry of a
* known MAC address to make sure it gets refreshed.
*/
uint32_t ulARPRemoveCacheEntryByMac( const MACAddress_t * pxMACAddress );
#endif /* ipconfigUSE_ARP_REMOVE_ENTRY != 0 */
BaseType_t xIsIPInARPCache( uint32_t ulAddressToLookup );
BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer );
/*
* Look for ulIPAddress in the ARP cache. If the IP address exists, copy the
* associated MAC address into pxMACAddress, refresh the ARP cache entry's
* age, and return eResolutionCacheHit. If the IP address does not exist in the ARP
* cache return eResolutionCacheMiss. If the packet cannot be sent for any reason
* (maybe DHCP is still in process, or the addressing needs a gateway but there
* isn't a gateway defined) then return eResolutionFailed.
*/
eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress,
MACAddress_t * const pxMACAddress,
struct xNetworkEndPoint ** ppxEndPoint );
#if ( ipconfigUSE_ARP_REVERSED_LOOKUP != 0 )
/* Lookup an IP-address if only the MAC-address is known */
eResolutionLookupResult_t eARPGetCacheEntryByMac( const MACAddress_t * const pxMACAddress,
uint32_t * pulIPAddress,
struct xNetworkInterface ** ppxInterface );
#endif
/*
* Reduce the age count in each entry within the ARP cache. An entry is no
* longer considered valid and is deleted if its age reaches zero.
*/
void vARPAgeCache( void );
/*
* After DHCP is ready and when changing IP address, force a quick send of our new IP
* address
*/
void vARPSendGratuitous( void );
/*
* Send out an ARP request for the IP address contained in pxNetworkBuffer, and
* add an entry into the ARP table that indicates that an ARP reply is
* outstanding so re-transmissions can be generated.
*/
void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress );
/*
* Create and send an ARP request packet to IPv4 endpoints of an interface.
*/
void FreeRTOS_OutputARPRequest_Multi( NetworkEndPoint_t * pxEndPoint,
uint32_t ulIPAddress );
/* xARPWaitResolution checks if an IPv4 address is already known. If not
* it may send an ARP request and wait for a reply. This function will
* only be called from an application. */
BaseType_t xARPWaitResolution( uint32_t ulIPAddress,
TickType_t uxTicksToWait );
/* Clear all entries in the ARp cache. */
void FreeRTOS_ClearARP( const struct xNetworkEndPoint * pxEndPoint );
/* Show all valid ARP entries */
#if ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 )
void FreeRTOS_PrintARPCache( void );
#endif
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_ARP_H */
@@ -0,0 +1,82 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*
* FreeRTOS_Stream_Buffer.h
*
* A circular character buffer
* An implementation of a circular buffer without a length field
* If LENGTH defines the size of the buffer, a maximum of (LENGTH-1) bytes can be stored
* In order to add or read data from the buffer, memcpy() will be called at most 2 times
*/
#ifndef FREERTOS_BITCONFIG_H
#define FREERTOS_BITCONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/**< @brief The struct BitConfig_t holds a character array, its length and an index. */
typedef struct xBitConfig
{
uint8_t * ucContents; /**< An allocated buffer to hold the binary data stream. */
size_t uxIndex; /**< Points to the next character to analyse or write. */
size_t uxSize; /**< The size of the allocated buffer 'uxContents'. */
BaseType_t xHasError; /**< It will be set to pdTRUE in case an error occurred, usually because the buffer is too small. */
} BitConfig_t;
BaseType_t xBitConfig_init( BitConfig_t * pxConfig,
const uint8_t * pucData,
size_t uxSize );
uint8_t ucBitConfig_read_8( BitConfig_t * pxConfig );
uint16_t usBitConfig_read_16( BitConfig_t * pxConfig );
uint32_t ulBitConfig_read_32( BitConfig_t * pxConfig );
BaseType_t xBitConfig_read_uc( BitConfig_t * pxConfig,
uint8_t * pucData,
size_t uxSize );
BaseType_t pucBitConfig_peek_last_index_uc( BitConfig_t * pxConfig,
uint8_t * pucData,
size_t uxSize );
void vBitConfig_write_8( BitConfig_t * pxConfig,
uint8_t ucValue );
void vBitConfig_write_16( BitConfig_t * pxConfig,
uint16_t usValue );
void vBitConfig_write_32( BitConfig_t * pxConfig,
uint32_t ulValue );
void vBitConfig_write_uc( BitConfig_t * pxConfig,
const uint8_t * pucData,
size_t uxSize );
void vBitConfig_release( BitConfig_t * pxConfig );
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* FREERTOS_STREAM_BUFFER_H */
@@ -0,0 +1,282 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_DHCP_H
#define FREERTOS_DHCP_H
#include "FreeRTOS.h"
/* Application level configuration options. */
#include "FreeRTOSIPConfig.h"
#include "FreeRTOS_Sockets.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
#if ( ipconfigUSE_DHCP != 0 ) && ( 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
/* Parameter widths in the DHCP packet. */
#define dhcpCLIENT_HARDWARE_ADDRESS_LENGTH 16 /**< Client hardware address length.*/
#define dhcpSERVER_HOST_NAME_LENGTH 64 /**< Server host name length. */
#define dhcpBOOT_FILE_NAME_LENGTH 128 /**< Boot file name length. */
/* Timer parameters */
#ifndef dhcpINITIAL_TIMER_PERIOD
/** @brief The interval at which the DHCP state handler is called. */
#define dhcpINITIAL_TIMER_PERIOD ( pdMS_TO_TICKS( 250U ) )
#endif
#ifndef dhcpINITIAL_DHCP_TX_PERIOD
/** @brief The initial amount of time to wait for a DHCP reply. When repeating an
* unanswered request, this time-out shall be multiplied by 2. */
#define dhcpINITIAL_DHCP_TX_PERIOD ( pdMS_TO_TICKS( 5000U ) )
#endif
#define dhcpIPv6_CLIENT_DUID_LENGTH ( 14U )
/* Codes of interest found in the DHCP options field. */
#define dhcpIPv4_ZERO_PAD_OPTION_CODE ( 0U ) /**< Used to pad other options to make them aligned. See RFC 2132. */
#define dhcpIPv4_SUBNET_MASK_OPTION_CODE ( 1U ) /**< Subnet mask. See RFC 2132. */
#define dhcpIPv4_GATEWAY_OPTION_CODE ( 3U ) /**< Available routers. See RFC 2132. */
#define dhcpIPv4_DNS_SERVER_OPTIONS_CODE ( 6U ) /**< Domain name server. See RFC 2132. */
#define dhcpIPv4_DNS_HOSTNAME_OPTIONS_CODE ( 12U ) /**< Host name. See RFC 2132. */
#define dhcpIPv4_REQUEST_IP_ADDRESS_OPTION_CODE ( 50U ) /**< Requested IP-address. See RFC 2132. */
#define dhcpIPv4_LEASE_TIME_OPTION_CODE ( 51U ) /**< IP-address lease time. See RFC 2132. */
#define dhcpIPv4_MESSAGE_TYPE_OPTION_CODE ( 53U ) /**< DHCP message type. See RFC 2132. */
#define dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE ( 54U ) /**< Server Identifier. See RFC 2132. */
#define dhcpIPv4_PARAMETER_REQUEST_OPTION_CODE ( 55U ) /**< Parameter Request list. See RFC 2132. */
#define dhcpIPv4_CLIENT_IDENTIFIER_OPTION_CODE ( 61U ) /**< Client Identifier. See RFC 2132. */
/* The four DHCP message types of interest. */
#define dhcpMESSAGE_TYPE_DISCOVER ( 1 ) /**< DHCP discover message. */
#define dhcpMESSAGE_TYPE_OFFER ( 2 ) /**< DHCP offer message. */
#define dhcpMESSAGE_TYPE_REQUEST ( 3 ) /**< DHCP request message. */
#define dhcpMESSAGE_TYPE_ACK ( 5 ) /**< DHCP acknowledgement. */
#define dhcpMESSAGE_TYPE_NACK ( 6 ) /**< DHCP NACK. (Negative acknowledgement) */
/* Offsets into the transmitted DHCP options fields at which various parameters
* are located. */
#define dhcpCLIENT_IDENTIFIER_OFFSET ( 6U ) /**< Offset for the client ID option. */
#define dhcpREQUESTED_IP_ADDRESS_OFFSET ( 14U ) /**< Offset for the requested IP-address option. */
#define dhcpDHCP_SERVER_IP_ADDRESS_OFFSET ( 20U ) /**< Offset for the server IP-address option. */
#define dhcpOPTION_50_OFFSET ( 12U ) /**< Offset of option-50. */
#define dhcpOPTION_50_SIZE ( 6U ) /**< Number of bytes included in option-50. */
/* Values used in the DHCP packets. */
#define dhcpREQUEST_OPCODE ( 1U ) /**< DHCP request opcode. */
#define dhcpREPLY_OPCODE ( 2U ) /**< DHCP reply opcode. */
#define dhcpADDRESS_TYPE_ETHERNET ( 1U ) /**< Address type: ethernet opcode. */
#define dhcpETHERNET_ADDRESS_LENGTH ( 6U ) /**< Ethernet address length opcode. */
/** @brief If a lease time is not received, use the default of two days (48 hours in ticks).
* Can not use pdMS_TO_TICKS() as integer overflow can occur. */
#define dhcpDEFAULT_LEASE_TIME ( ( 48UL * 60UL * 60UL ) * configTICK_RATE_HZ )
/** @brief Don't allow the lease time to be too short. */
#define dhcpMINIMUM_LEASE_TIME ( pdMS_TO_TICKS( 60000UL ) ) /* 60 seconds in ticks. */
/** @brief Marks the end of the variable length options field in the DHCP packet. */
#define dhcpOPTION_END_BYTE 0xffu
/** @brief Offset into a DHCP message at which the first byte of the options is
* located. */
#define dhcpFIRST_OPTION_BYTE_OFFSET ( 0xf0U )
/* Standard DHCP port numbers and magic cookie value.
* DHCPv4 uses UDP port number 68 for clients and port number 67 for servers.
*/
#if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
#define dhcpCLIENT_PORT_IPv4 0x4400U /**< Little endian representation of port 68. */
#define dhcpSERVER_PORT_IPv4 0x4300U /**< Little endian representation of port 67. */
#define dhcpCOOKIE 0x63538263UL /**< Little endian representation of magic cookie. */
#define dhcpBROADCAST 0x0080U /**< Little endian representation of broadcast flag. */
#else
#define dhcpCLIENT_PORT_IPv4 0x0044U /**< Big endian representation of port 68. */
#define dhcpSERVER_PORT_IPv4 0x0043U /**< Big endian representation of port 67. */
#define dhcpCOOKIE 0x63825363UL /**< Big endian representation of magic cookie. */
#define dhcpBROADCAST 0x8000U /**< Big endian representation of broadcast flag. */
#endif /* ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) */
#include "pack_struct_start.h"
struct xDHCPMessage_IPv4
{
uint8_t ucOpcode; /**< Operation Code: Specifies the general type of message. */
uint8_t ucAddressType; /**< Hardware type used on the local network. */
uint8_t ucAddressLength; /**< Hardware Address Length: Specifies how long hardware
* addresses are in this message. */
uint8_t ucHops; /**< Hops. */
uint32_t ulTransactionID; /**< A 32-bit identification field generated by the client,
* to allow it to match up the request with replies received
* from DHCP servers. */
uint16_t usElapsedTime; /**< Number of seconds elapsed since a client began an attempt to acquire or renew a lease. */
uint16_t usFlags; /**< Just one bit used to indicate broadcast. */
uint32_t ulClientIPAddress_ciaddr; /**< Client's IP address if it has one or 0 is put in this field. */
uint32_t ulYourIPAddress_yiaddr; /**< The IP address that the server is assigning to the client. */
uint32_t ulServerIPAddress_siaddr; /**< The DHCP server address that the client should use. */
uint32_t ulRelayAgentIPAddress_giaddr; /**< Gateway IP address in case the server client are on different subnets. */
uint8_t ucClientHardwareAddress[ dhcpCLIENT_HARDWARE_ADDRESS_LENGTH ]; /**< The client hardware address. */
uint8_t ucServerHostName[ dhcpSERVER_HOST_NAME_LENGTH ]; /**< Server's hostname. */
uint8_t ucBootFileName[ dhcpBOOT_FILE_NAME_LENGTH ]; /**< Boot file full directory path. */
uint32_t ulDHCPCookie; /**< Magic cookie option. */
/* Option bytes from here on. */
}
#include "pack_struct_end.h"
typedef struct xDHCPMessage_IPv4 DHCPMessage_IPv4_t;
#if ( ipconfigUSE_DHCP_HOOK != 0 )
/* Used in the DHCP callback if ipconfigUSE_DHCP_HOOK is set to 1. */
typedef enum eDHCP_PHASE
{
eDHCPPhasePreDiscover, /**< Driver is about to send a DHCP discovery. */
eDHCPPhasePreRequest /**< Driver is about to request DHCP an IP address. */
} eDHCPCallbackPhase_t;
/** @brief Used in the DHCP callback if ipconfigUSE_DHCP_HOOK is set to 1. */
typedef enum eDHCP_ANSWERS
{
eDHCPContinue, /**< Continue the DHCP process */
eDHCPUseDefaults, /**< Stop DHCP and use the static defaults. */
eDHCPStopNoChanges /**< Stop DHCP and continue with current settings. */
} eDHCPCallbackAnswer_t;
#endif /* #if( ipconfigUSE_DHCP_HOOK != 0 ) */
/** @brief DHCP state machine states. */
typedef enum
{
eInitialWait = 0, /**< Initial state: open a socket and wait a short time. */
eWaitingSendFirstDiscover, /**< Send a discover the first time it is called, and reset all timers. */
eWaitingOffer, /**< Either resend the discover, or, if the offer is forthcoming, send a request. */
eWaitingAcknowledge, /**< Either resend the request. */
eSendDHCPRequest, /**< Sendto failed earlier, resend the request to lease the IP-address offered. */
#if ( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 )
eGetLinkLayerAddress, /**< When DHCP didn't respond, try to obtain a LinkLayer address 168.254.x.x. */
#endif
eLeasedAddress, /**< Resend the request at the appropriate time to renew the lease. */
eNotUsingLeasedAddress /**< DHCP failed, and a default IP address is being used. */
} eDHCPState_t;
/** @brief Hold information in between steps in the DHCP state machine. */
struct xDHCP_DATA
{
uint32_t ulTransactionId; /**< The ID used in all transactions. */
uint32_t ulOfferedIPAddress; /**< The IP-address offered by the DHCP server. */
uint32_t ulPreferredIPAddress; /**< A preferred IP address */
uint32_t ulDHCPServerAddress; /**< The IP-address of the DHCP server. */
uint32_t ulLeaseTime; /**< The maximum time that the IP-address can be leased. */
/* Hold information on the current timer state. */
TickType_t xDHCPTxTime; /**< The time at which a request was sent, initialised with xTaskGetTickCount(). */
TickType_t xDHCPTxPeriod; /**< The maximum time to wait for a response. */
/* Try both without and with the broadcast flag */
BaseType_t xUseBroadcast; /**< pdTRUE if the broadcast bit 'dhcpBROADCAST' must be set. */
/* Maintains the DHCP state machine state. */
eDHCPState_t eDHCPState; /**< The current state of the DHCP state machine. */
eDHCPState_t eExpectedState; /**< If the state is not equal the the expected state, no cycle needs to be done. */
Socket_t xDHCPSocket;
/**< Record latest client ID for DHCPv6. */
uint8_t ucClientDUID[ dhcpIPv6_CLIENT_DUID_LENGTH ];
};
typedef struct xDHCP_DATA DHCPData_t;
/** brief: a set of parameters that are passed to helper functions. */
typedef struct xProcessSet
{
uint8_t ucOptionCode; /**< The code currently being handled. */
size_t uxIndex; /**< The index within 'pucByte'. */
size_t uxPayloadDataLength; /**< The number of bytes in the UDP payload. */
size_t uxLength; /**< The size of the current option. */
uint32_t ulParameter; /**< The uint32 value of the answer, if available. */
uint32_t ulProcessed; /**< The number of essential options that were parsed. */
const uint8_t * pucByte; /**< A pointer to the data to be analysed. */
} ProcessSet_t;
/*
* NOT A PUBLIC API FUNCTION.
* It will be called when the DHCP timer expires, or when
* data has been received on the DHCP socket.
*/
void vDHCPProcess( BaseType_t xReset,
struct xNetworkEndPoint * pxEndPoint );
/*
* NOT A PUBLIC API FUNCTION.
* It will be called when the network interface, that the endpoint is associated with, goes down.
*/
void vDHCPStop( struct xNetworkEndPoint * pxEndPoint );
/* Internal call: returns true if socket is the current DHCP socket */
BaseType_t xIsDHCPSocket( const ConstSocket_t xSocket );
#if ( ipconfigUSE_DHCP_HOOK != 0 )
/* Prototype of the hook (or callback) function that must be provided by the
* application if ipconfigUSE_DHCP_HOOK is set to 1. See the following URL for
* usage information:
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigUSE_DHCP_HOOK
*/
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase,
uint32_t ulIPAddress );
#else /* ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) */
eDHCPCallbackAnswer_t xApplicationDHCPHook_Multi( eDHCPCallbackPhase_t eDHCPPhase,
struct xNetworkEndPoint * pxEndPoint,
IP_Address_t * pxIPAddress );
#endif /* ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) */
#endif /* ( ipconfigUSE_DHCP_HOOK != 0 ) */
#if ( ipconfigDHCP_FALL_BACK_AUTO_IP != 0 )
struct xNetworkEndPoint;
/**
* @brief When DHCP has failed, the code can assign a Link-Layer
* address, and check if another device already uses the IP-address.
*
* param[in] pxEndPoint: The end-point that wants to obtain a link-layer address.
*/
void prvPrepareLinkLayerIPLookUp( struct xNetworkEndPoint * pxEndPoint );
#endif
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_DHCP_H */
@@ -0,0 +1,169 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_DHCPV6_H
#define FREERTOS_DHCPV6_H
/* Application level configuration options. */
#include "FreeRTOS_DHCP.h"
#include "FreeRTOSIPConfig.h"
#ifdef __cplusplus
extern "C" {
#endif
/* IPv6 option numbers. */
/** @brief IPv6 DHCP option number - Solicit */
#define DHCPv6_message_Type_Solicit 1U
/** @brief IPv6 DHCP option number - Advertise */
#define DHCPv6_message_Type_Advertise 2U
/** @brief IPv6 DHCP option number - Request */
#define DHCPv6_message_Type_Request 3U
/** @brief IPv6 DHCP option number - Confirm */
#define DHCPv6_message_Type_Confirm 4U
/** @brief IPv6 DHCP option number - Renew */
#define DHCPv6_message_Type_Renew 5U
/** @brief IPv6 DHCP option number - Reply */
#define DHCPv6_message_Type_Reply 7U
/** @brief IPv6 DHCP option number - Release */
#define DHCPv6_message_Type_Release 8U
/** @brief IPv6 DHCP option number - Decline */
#define DHCPv6_message_Type_Decline 9U
/* Note: IA stands for "Identity_Association". */
/** @brief IPv6 DHCP option - Client Identifier */
#define DHCPv6_Option_Client_Identifier 1U
/** @brief IPv6 DHCP option - Server Identifier */
#define DHCPv6_Option_Server_Identifier 2U
/** @brief IPv6 DHCP option - Non Temporary Address */
#define DHCPv6_Option_NonTemporaryAddress 3U
/** @brief IPv6 DHCP option - Temporary Address */
#define DHCPv6_Option_TemporaryAddress 4U
/** @brief IPv6 DHCP option - Identity_Association Address */
#define DHCPv6_Option_IA_Address 5U
/** @brief IPv6 DHCP option - Option */
#define DHCPv6_Option_Option_List 6U
/** @brief IPv6 DHCP option - Preference */
#define DHCPv6_Option_Preference 7U
/** @brief IPv6 DHCP option - Elapsed time */
#define DHCPv6_Option_Elapsed_Time 8U
/** @brief IPv6 DHCP option - Status code */
#define DHCPv6_Option_Status_Code 13U
/** @brief IPv6 DHCP option - Recursive name server */
#define DHCPv6_Option_DNS_recursive_name_server 23U
/** @brief IPv6 DHCP option - Search list */
#define DHCPv6_Option_Domain_Search_List 24U
/** @brief IPv6 DHCP option - IA for prefix delegation */
#define DHCPv6_Option_IA_for_Prefix_Delegation 25U
/** @brief IPv6 DHCP option - IA Prefix */
#define DHCPv6_Option_IA_Prefix 26U
/** @brief DHCPv6 option request, used in combination with 'DHCPv6_Option_Option_List' */
#define DHCP6_OPTION_REQUEST_DNS 0x0017
/** @brief DHCPv6 option request domain search list, used in combination with 'DHCPv6_Option_Option_List' */
#define DHCP6_OPTION_REQUEST_DOMAIN_SEARCH_LIST 0x0018
#define DHCPv6_MAX_CLIENT_SERVER_ID_LENGTH 128
/** @brief The function time() counts since 1-1-1970. The DHCPv6 time-stamp however
* uses a time stamp that had zero on 1-1-2000. */
#define SECS_FROM_1970_TILL_2000 946684800U
/** @brief If a lease time is not received, use the default of two days. 48 hours in ticks.
* Do not use the macro pdMS_TO_TICKS() here as integer overflow can occur. */
#define dhcpv6DEFAULT_LEASE_TIME ( ( 48U * 60U * 60U ) * configTICK_RATE_HZ )
/** @brief Don't allow the lease time to be too short. */
#define dhcpv6MINIMUM_LEASE_TIME ( pdMS_TO_TICKS( 60000U ) ) /* 60 seconds in ticks. */
/** @brief Default v6 DHCP client port. */
#define ipDHCPv6_CLIENT_PORT 546U
/** @brief Default v6 DHCP server port. */
#define ipDHCPv6_SERVER_PORT 547U
/** @brief The ID of a client or a server. */
typedef struct xClientServerID
{
uint16_t usDUIDType; /**< A DHCP Unique Identifier ( DUID ). */
uint16_t usHardwareType; /**< The hardware type: 1 = Ethernet. */
uint8_t pucID[ DHCPv6_MAX_CLIENT_SERVER_ID_LENGTH ]; /**< Universally Unique IDentifier (UUID) format. */
size_t uxLength; /**< The number of valid bytes within 'pucID'. */
} ClientServerID_t;
/** @brief DHCPMessage_IPv6_t holds all data of a DHCP client. */
typedef struct xDHCPMessage_IPv6
{
uint8_t uxMessageType; /**< The type of the last message received: Advertise / Confirm / Reply / Decline */
uint8_t ucTransactionID[ 3 ]; /**< ID of a transaction, shall be renewed when the transaction is ready ( and a reply has been received ). */
uint32_t ulTransactionID; /**< The same as above but now as a long integer. */
IP_Address_t xDNSServers[ ipconfigENDPOINT_DNS_ADDRESS_COUNT ]; /**< The IP-address of the DNS server. */
size_t uxDNSCount; /**< The number of the DNS server stored in xDNSServers. */
uint32_t ulPreferredLifeTime; /**< The preferred life time. */
uint32_t ulValidLifeTime; /**< The valid life time. */
uint32_t ulTimeStamp; /**< DUID Time: seconds since 1-1-2000. */
uint8_t ucprefixLength; /**< The length of the prefix offered. */
uint8_t ucHasUID; /**< When pdFALSE: a transaction ID must be created. */
IP_Address_t xPrefixAddress; /**< The prefix offered. */
IP_Address_t xIPAddress; /**< The IP-address offered. */
ClientServerID_t xClientID; /**< The UUID of the client. */
ClientServerID_t xServerID; /**< The UUID of the server. */
} DHCPMessage_IPv6_t;
/** @brief A struct describing an option. */
typedef struct xDHCPOptionSet
{
size_t uxOptionLength; /**< The length of the option being handled. */
size_t uxStart; /**< The position in xMessage where the option starts. */
} DHCPOptionSet_t;
struct xNetworkEndPoint;
/* Returns the current state of a DHCP process. */
eDHCPState_t eGetDHCPv6State( struct xNetworkEndPoint * pxEndPoint );
/*
* NOT A PUBLIC API FUNCTION.
* It will be called when the DHCP timer expires, or when
* data has been received on the DHCP socket.
*/
void vDHCPv6Process( BaseType_t xReset,
struct xNetworkEndPoint * pxEndPoint );
/*
* NOT A PUBLIC API FUNCTION.
* It will be called when the network interface, that the endpoint is associated with, goes down.
*/
void vDHCPv6Stop( struct xNetworkEndPoint * pxEndPoint );
#ifdef __cplusplus
} /* extern "C" */
#endif
/* The application should supply the following time-function.
* It must return the number of seconds that have passed since
* 1/1/1970. */
extern uint32_t ulApplicationTimeHook( void );
#endif /* FREERTOS_DHCPV6_H */
@@ -0,0 +1,175 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://github.com/FreeRTOS
* https://www.FreeRTOS.org
*/
#ifndef FREERTOS_DNS_H
#define FREERTOS_DNS_H
#include "FreeRTOS.h"
/* Application level configuration options. */
#include "FreeRTOS_DNS_Globals.h"
#include "FreeRTOS_DNS_Callback.h"
#include "FreeRTOS_DNS_Cache.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* The LLMNR MAC address is 01:00:5e:00:00:fc */
extern const MACAddress_t xLLMNR_MacAddress;
/* The LLMNR IPv6 MAC address is 33:33:00:01:00:03 */
extern const MACAddress_t xLLMNR_MacAddressIPv6;
#if ( ( ipconfigUSE_LLMNR != 0 ) && ( ipconfigUSE_IPv6 != 0 ) )
/* The LLMNR IPv6 address is ff02::1:3 */
extern const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6;
#endif /* ( ( ipconfigUSE_LLMNR != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) */
/* The MDNS MAC address is 01:00:5e:00:00:fc */
extern const MACAddress_t xMDNS_MacAddress;
/* The MDNS IPv6 MAC address is 33:33:00:01:00:03 */
/* This type-name was formally "misspelled" as
* xMDNS_MACAddressIPv6 with "MAC": */
extern const MACAddress_t xMDNS_MacAddressIPv6;
/* Guarantee backward compatibility. */
#define xMDNS_MACAddressIPv6 xMDNS_MacAddressIPv6
#if ( ( ipconfigUSE_MDNS != 0 ) && ( ipconfigUSE_IPv6 != 0 ) )
/* The MDNS IPv6 address is ff02::1:3 */
extern const IPv6_Address_t ipMDNS_IP_ADDR_IPv6;
#endif /* ( ( ipconfigUSE_MDNS != 0 ) && ( ipconfigUSE_IPv6 != 0 ) ) */
/** @brief While doing integration tests, it is necessary to influence the choice
* between DNS/IPv4 and DNS/IPv4. Depending on this, a DNS server will be
* addressed via IPv4 or IPv6 messages. */
typedef enum xIPPreference
{
xPreferenceNone,
xPreferenceIPv4
#if ( ipconfigUSE_IPv6 != 0 )
,
xPreferenceIPv6
#endif
} IPPreference_t;
/** @brief This variable determines he choice of DNS server, either IPv4 or IPv6. */
extern IPPreference_t xDNS_IP_Preference;
/*
* LLMNR is very similar to DNS, so is handled by the DNS routines.
*/
BaseType_t xDNSHandlePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer );
#if ( ipconfigUSE_NBNS != 0 )
/*
* Inspect a NetBIOS Names-Service message. If the name matches with ours
* (xApplicationDNSQueryHook returns true) an answer will be sent back.
* Note that LLMNR is a better protocol for name services on a LAN as it is
* less polluted
*/
uint32_t ulNBNSHandlePacket( NetworkBufferDescriptor_t * pxNetworkBuffer );
#endif /* ipconfigUSE_NBNS */
#if ( ipconfigDNS_USE_CALLBACKS != 0 )
/*
* Asynchronous version of gethostbyname()
* xTimeout is in units of ms.
*/
uint32_t FreeRTOS_gethostbyname_a( const char * pcHostName,
FOnDNSEvent pCallback,
void * pvSearchID,
TickType_t uxTimeout );
void FreeRTOS_gethostbyname_cancel( void * pvSearchID );
/* The asynchronous versions of FreeRTOS_getaddrinfo(). */
BaseType_t FreeRTOS_getaddrinfo_a( const char * pcName, /* The name of the node or device */
const char * pcService, /* Ignored for now. */
const struct freertos_addrinfo * pxHints, /* If not NULL: preferences. */
struct freertos_addrinfo ** ppxResult, /* An allocated struct, containing the results. */
FOnDNSEvent pCallback,
void * pvSearchID,
TickType_t uxTimeout );
#endif /* if ( ipconfigDNS_USE_CALLBACKS != 0 ) */
/*
* Lookup a IPv4 node in a blocking-way.
* It returns a 32-bit IP-address, 0 when not found.
* gethostbyname() is already deprecated.
*/
uint32_t FreeRTOS_gethostbyname( const char * pcHostName );
/* _HT_ Although this function is private to the library, it needs a global declaration. */
struct freertos_addrinfo * pxNew_AddrInfo( const char * pcName,
BaseType_t xFamily,
const uint8_t * pucAddress );
/*
* FreeRTOS_getaddrinfo() replaces FreeRTOS_gethostbyname().
* When 'ipconfigUSE_IPv6' is defined, it can also retrieve IPv6 addresses,
* in case pxHints->ai_family equals FREERTOS_AF_INET6.
* Otherwise, or when pxHints is NULL, only IPv4 addresses will be returned.
*/
BaseType_t FreeRTOS_getaddrinfo( const char * pcName, /* The name of the node or device */
const char * pcService, /* Ignored for now. */
const struct freertos_addrinfo * pxHints, /* If not NULL: preferences. */
struct freertos_addrinfo ** ppxResult ); /* An allocated struct, containing the results. */
/* When FreeRTOS_getaddrinfo() is successful, ppxResult will point to an
* allocated structure. This pointer must be released by the user by calling
* FreeRTOS_freeaddrinfo().
*/
void FreeRTOS_freeaddrinfo( struct freertos_addrinfo * pxInfo );
/* Sets the DNS IP preference while doing DNS lookup to indicate the preference
* for a DNS server: either IPv4 or IPv6. Defaults to xPreferenceIPv4 */
BaseType_t FreeRTOS_SetDNSIPPreference( IPPreference_t eIPPreference );
#if ( ipconfigDNS_USE_CALLBACKS == 1 )
/*
* The function vDNSInitialise() initialises the DNS module.
* It will be called "internally", by the IP-task.
*/
void vDNSInitialise( void );
#endif /* ( ipconfigDNS_USE_CALLBACKS == 1 ) */
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_DNS_H */
@@ -0,0 +1,84 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://github.com/FreeRTOS
* https://www.FreeRTOS.org
*/
#ifndef FREERTOS_DNS_CACHE_H
#define FREERTOS_DNS_CACHE_H
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "FreeRTOS_DNS_Globals.h"
/* Standard includes. */
#include <stdint.h>
#if ( ( ipconfigUSE_DNS_CACHE == 1 ) && ( ipconfigUSE_DNS != 0 ) )
/**
* @brief cache entry format structure
*/
typedef struct xDNS_CACHE_TABLE_ROW
{
IPv46_Address_t xAddresses[ ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ]; /*!< The IP address(es) of a DNS cache entry. */
char pcName[ ipconfigDNS_CACHE_NAME_LENGTH ]; /*!< The name of the host */
uint32_t ulTTL; /*!< Time-to-Live (in seconds) from the DNS server. */
uint32_t ulTimeWhenAddedInSeconds; /*!< time at which the entry was added */
#if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 )
uint8_t ucNumIPAddresses; /*!< number of ip addresses for the same entry */
uint8_t ucCurrentIPAddress; /*!< current ip address index */
#endif
} DNSCacheRow_t;
/* Look for the indicated host name in the DNS cache. Returns the IPv4
* address if present, or 0x0 otherwise. */
uint32_t FreeRTOS_dnslookup( const char * pcHostName );
void FreeRTOS_dnsclear( void );
/**
* @brief For debugging only: prints the contents of the DNS cache table.
*/
void vShowDNSCacheTable( void );
BaseType_t FreeRTOS_dns_update( const char * pcName,
IPv46_Address_t * pxIP,
uint32_t ulTTL,
BaseType_t xLookUp,
struct freertos_addrinfo ** ppxAddressInfo );
BaseType_t FreeRTOS_ProcessDNSCache( const char * pcName,
IPv46_Address_t * pxIP,
uint32_t ulTTL,
BaseType_t xLookUp,
struct freertos_addrinfo ** ppxAddressInfo );
uint32_t Prepare_CacheLookup( const char * pcHostName,
BaseType_t xFamily,
struct freertos_addrinfo ** ppxAddressInfo );
#endif /* if ( ipconfigUSE_DNS_CACHE == 1 ) */
#endif /* FREERTOS_DNS_CACHE_H */
@@ -0,0 +1,75 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://github.com/FreeRTOS
* https://www.FreeRTOS.org
*/
#ifndef FREERTOS_DNS_CALLBACK_H
#define FREERTOS_DNS_CALLBACK_H
/* FreeRTOS includes. */
#include "FreeRTOS.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_DNS_Globals.h"
/* Standard includes. */
#include <stdint.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Application level configuration options. */
#if ( ( ipconfigDNS_USE_CALLBACKS == 1 ) && ( ipconfigUSE_DNS != 0 ) )
BaseType_t xDNSDoCallback( ParseSet_t * pxSet,
struct freertos_addrinfo * pxAddress );
BaseType_t xDNSSetCallBack( const char * pcHostName,
void * pvSearchID,
FOnDNSEvent pCallbackFunction,
TickType_t uxTimeout,
TickType_t uxIdentifier,
BaseType_t xIsIPv6 );
void vDNSCheckCallBack( void * pvSearchID );
void vDNSCallbackInitialise( void );
#endif /* ipconfigDNS_USE_CALLBACKS && ipconfigUSE_DNS */
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_DNS_CALLBACK_H */
@@ -0,0 +1,315 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_DNS_GLOBALS_H
#define FREERTOS_DNS_GLOBALS_H
#include "FreeRTOS.h"
#include "FreeRTOSIPConfig.h"
#include "FreeRTOSIPConfigDefaults.h"
#include "FreeRTOS_Sockets.h"
#define dnsPARSE_ERROR 0UL
#if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
#define dnsDNS_PORT 0x3500U /**< Little endian: Port used for DNS. */
#define dnsONE_QUESTION 0x0100U /**< Little endian representation of a DNS question.*/
#define dnsOUTGOING_FLAGS 0x0001U /**< Little endian representation of standard query. */
#define dnsRX_FLAGS_MASK 0x0f80U /**< Little endian: The bits of interest in the flags field of incoming DNS messages. */
#define dnsEXPECTED_RX_FLAGS 0x0080U /**< Little Endian: Should be a response, without any errors. */
#else
#define dnsDNS_PORT 0x0035U /**< Big endian: Port used for DNS. */
#define dnsONE_QUESTION 0x0001U /**< Big endian representation of a DNS question.*/
#define dnsOUTGOING_FLAGS 0x0100U /**< Big endian representation of standard query. */
#define dnsRX_FLAGS_MASK 0x800fU /**< Big endian: The bits of interest in the flags field of incoming DNS messages. */
#define dnsEXPECTED_RX_FLAGS 0x8000U /**< Big endian: Should be a response, without any errors. */
#endif /* ipconfigBYTE_ORDER */
#if ( ipconfigUSE_DNS != 0 )
/** @brief If the top two bits in the first character of a name field are set then the
* name field is an offset to the string, rather than the string itself. */
#define dnsNAME_IS_OFFSET ( ( uint8_t ) 0xc0 )
/* NBNS flags. */
#if ( ipconfigUSE_NBNS == 1 )
#define dnsNBNS_FLAGS_RESPONSE 0x8000U /**< NBNS response flag. */
#define dnsNBNS_FLAGS_OPCODE_MASK 0x7800U /**< NBNS opcode bitmask. */
#define dnsNBNS_FLAGS_OPCODE_QUERY 0x0000U /**< NBNS opcode query. */
#endif /* ( ipconfigUSE_NBNS == 1 ) */
/* Host types. */
#define dnsTYPE_A_HOST 0x01U /**< DNS type A host. */
#define dnsTYPE_AAAA_HOST 0x001CU
#define dnsTYPE_ANY_HOST 0x00FFU
#define dnsCLASS_IN 0x01U /**< DNS class IN (Internet). */
/* Maximum hostname length as defined in RFC 1035 section 3.1. */
#define dnsMAX_HOSTNAME_LENGTH 0xFFU
#ifndef _lint
/* LLMNR constants. */
#define dnsLLMNR_TTL_VALUE 300U /**< LLMNR time to live value of 5 minutes. */
#define dnsLLMNR_FLAGS_IS_RESPONSE 0x8000U /**< LLMNR flag value for response. */
#endif /* _lint */
/* NBNS constants. */
#if ( ipconfigUSE_NBNS != 0 )
#define dnsNBNS_TTL_VALUE 3600UL /**< NBNS TTL: 1 hour valid. */
#define dnsNBNS_TYPE_NET_BIOS 0x0020U /**< NBNS Type: NetBIOS. */
#define dnsNBNS_CLASS_IN 0x01U /**< NBNS Class: IN (Internet). */
#define dnsNBNS_NAME_FLAGS 0x6000U /**< NBNS name flags. */
#define dnsNBNS_ENCODED_NAME_LENGTH 32 /**< NBNS encoded name length. */
/** @brief If the queried NBNS name matches with the device's name,
* the query will be responded to with these flags: */
#define dnsNBNS_QUERY_RESPONSE_FLAGS ( 0x8500U )
#endif /* ( ipconfigUSE_NBNS != 0 ) */
/** @brief Define the ASCII value of '.' (Period/Full-stop). */
#define ASCII_BASELINE_DOT 46U
/* The Link-local Multicast Name Resolution (LLMNR)
* is included.
* Note that a special MAC address is required in addition to the NIC's actual
* MAC address: 01:00:5E:00:00:FC
*
* The target IP address will be 224.0.0.252
*/
#if ( ipconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN )
#define ipLLMNR_IP_ADDR 0xE00000FCUL
#else
#define ipLLMNR_IP_ADDR 0xFC0000E0UL
#endif /* ipconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN */
/* MDNS constants. */
#define ipMDNS_TIME_TO_LIVE 255U
#define dnsMDNS_FLAGS_IS_RESPONSE 0x8400U /**< MDNS flag value for response. */
#define ipLLMNR_PORT 5355U /* Standard LLMNR port. */
#define ipDNS_PORT 53U /* Standard DNS port. */
#define ipNBNS_PORT 137U /* NetBIOS Name Service. */
#define ipNBDGM_PORT 138U /* Datagram Service, not included. */
/** @brief freertos_addrinfo is the equivalent of 'struct addrinfo'. */
struct freertos_addrinfo
{
BaseType_t ai_flags; /**< The field is included for completeness, but it is not used. */
BaseType_t ai_family; /**< The type of IP-address, either FREERTOS_AF_INET4 or FREERTOS_AF_INET6. */
BaseType_t ai_socktype; /**< n.a. */
BaseType_t ai_protocol; /**< n.a. */
socklen_t ai_addrlen; /**< The length of the address, either ipSIZE_OF_IPv4_ADDRESS or ipSIZE_OF_IPv6_ADDRESS. */
struct freertos_sockaddr * ai_addr; /**< The socket address. */
char * ai_canonname; /**< The name of the host. */
struct freertos_addrinfo * ai_next; /**< A pointer to the next find result, or NULL. */
struct
{
/* In order to avoid allocations, reserve space here for *ai_addr and *ai_canonname. */
struct freertos_sockaddr sockaddr;
#if ( ipconfigUSE_DNS_CACHE != 0 )
char ucName[ ipconfigDNS_CACHE_NAME_LENGTH ];
#endif
}
xPrivateStorage; /**< In order to avoid extra calls to malloc, the necessary space is reserved 'statically'. */
};
/* DNS answer record header. */
#include "pack_struct_start.h"
struct xDNSAnswerRecord
{
uint16_t usType; /**< Type of DNS answer record. */
uint16_t usClass; /**< Class of DNS answer record. */
uint32_t ulTTL; /**< Number of seconds the result can be cached. */
uint16_t usDataLength; /**< Length of the data field. */
}
#include "pack_struct_end.h"
typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
/* Below #include just tells the compiler to pack the structure.
* It is included in to make the code more readable */
#include "pack_struct_start.h"
struct xDNSMessage
{
uint16_t usIdentifier; /**< Query identifier. Used to match up replies to outstanding queries. */
uint16_t usFlags; /**< Flags. */
uint16_t usQuestions; /**< Number of questions asked in this query. */
uint16_t usAnswers; /**< Number of answers being provided in this query. */
uint16_t usAuthorityRRs; /**< Authoritative name server resource records. */
uint16_t usAdditionalRRs; /**< Additional resource records.*/
}
#include "pack_struct_end.h"
typedef struct xDNSMessage DNSMessage_t;
/** @brief A struct with a set of variables that are shared among the helper functions
* for the function 'DNS_ParseDNSReply()'. For internal use only.
*/
typedef struct xParseSet
{
DNSMessage_t * pxDNSMessageHeader; /**< A pointer to the UDP payload buffer where the DNS message is stored. */
uint16_t usQuestions; /**< The number of DNS questions that were asked. */
uint16_t usAnswers; /**< The number of DNS answers that were given. */
uint8_t * pucUDPPayloadBuffer; /**< A pointer to the original UDP load buffer. */
uint8_t * pucByte; /**< A pointer that is used while parsing. */
size_t uxSkipCount; /**< Points to the byte after the complete name (mDNS only) */
size_t uxBufferLength; /**< The total number of bytes received in the UDP payload. */
size_t uxSourceBytesRemaining; /**< As pucByte is incremented, 'uxSourceBytesRemaining' will be decremented. */
uint16_t usType; /**< The type of address, recognised are dnsTYPE_A_HOST ( Ipv4 ) and
* dnsTYPE_AAAA_HOST ( IPv6 ). */
uint32_t ulIPAddress; /**< The IPv4 address found. In an IPv6 look-up, store a non-zero value when
* an IPv6 address was found. */
size_t uxAddressLength; /**< The size of the address, either ipSIZE_OF_IPv4_ADDRESS or
* ipSIZE_OF_IPv6_ADDRESS */
uint16_t usNumARecordsStored; /**< The number of A-records stored during a look-up. */
uint16_t usPortNumber; /**< The port number that belong to the protocol ( DNS, MDNS etc ). */
#if ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_MDNS == 1 )
uint16_t usClass; /**< Only the value 'dnsCLASS_IN' is recognised, which stands for "Internet". */
char * pcRequestedName; /**< A pointer to the full name of the host being looked up. */
#endif
#if ( ( ipconfigUSE_DNS_CACHE != 0 ) || ( ipconfigDNS_USE_CALLBACKS != 0 ) || ( ipconfigUSE_MDNS != 0 ) || ( ipconfigUSE_LLMNR != 0 ) )
BaseType_t xDoStore; /**< Becomes true when a DNS reply was requested by this device,
* i.e. it has a matching request ID. */
char pcName[ ipconfigDNS_CACHE_NAME_LENGTH ]; /**< A copy of the name that is mentioned in the questions. */
#endif
struct freertos_addrinfo * pxLastAddress; /**< This variable is used while creating a linked-list of IP-addresses. */
struct freertos_addrinfo ** ppxLastAddress; /**< This variable is also used while creating a linked-list of IP-addresses. */
} ParseSet_t;
#if ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_MDNS == 1 )
#include "pack_struct_start.h"
struct xLLMNRAnswer
{
uint8_t ucNameCode; /**< Name type. */
uint8_t ucNameOffset; /**< The name is not repeated in the answer, only the offset is given with "0xc0 <offs>" */
uint16_t usType; /**< Type of the Resource record. */
uint16_t usClass; /**< Class of the Resource record. */
uint32_t ulTTL; /**< Seconds till this entry can be cached. */
uint16_t usDataLength; /**< Length of the address in this record. */
uint32_t ulIPAddress; /**< The IP-address. */
}
#include "pack_struct_end.h"
typedef struct xLLMNRAnswer LLMNRAnswer_t;
#endif /* if ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_MDNS == 1 ) */
#if ( ipconfigUSE_NBNS == 1 )
#include "pack_struct_start.h"
struct xNBNSRequest
{
uint16_t usRequestId; /**< NBNS request ID. */
uint16_t usFlags; /**< Flags of the DNS message. */
uint16_t ulRequestCount; /**< The number of requests/questions in this query. */
uint16_t usAnswerRSS; /**< The number of answers in this query. */
uint16_t usAuthRSS; /**< Number of authoritative resource records. */
uint16_t usAdditionalRSS; /**< Number of additional resource records. */
uint8_t ucNameSpace; /**< Length of name. */
uint8_t ucName[ dnsNBNS_ENCODED_NAME_LENGTH ]; /**< The domain name. */
uint8_t ucNameZero; /**< Terminator of the name. */
uint16_t usType; /**< Type of NBNS record. */
uint16_t usClass; /**< Class of NBNS request. */
}
#include "pack_struct_end.h"
typedef struct xNBNSRequest NBNSRequest_t;
#include "pack_struct_start.h"
struct xNBNSAnswer
{
uint16_t usType; /**< Type of NBNS answer. */
uint16_t usClass; /**< Class of NBNS answer. */
uint32_t ulTTL; /**< Time in seconds for which the answer can be cached. */
uint16_t usDataLength; /**< Data length. */
uint16_t usNbFlags; /**< NetBIOS flags 0x6000 : IP-address, big-endian. */
uint32_t ulIPAddress; /**< The IPv4 address. */
}
#include "pack_struct_end.h"
typedef struct xNBNSAnswer NBNSAnswer_t;
#endif /* if ( ipconfigUSE_NBNS == 1 ) */
#if ( ipconfigDNS_USE_CALLBACKS != 0 )
/*
* Users may define this type of function as a callback.
* It will be called when a DNS reply is received or when a timeout has been reached.
*/
typedef void (* FOnDNSEvent ) ( const char * /* pcName */,
void * /* pvSearchID */,
struct freertos_addrinfo * /* pxAddressInfo */ );
/** @brief The structure to hold information for a DNS callback. */
typedef struct xDNS_Callback
{
TickType_t uxRemainingTime; /**< Timeout in ms */
FOnDNSEvent pCallbackFunction; /**< Function to be called when the address has been found or when a timeout has been reached */
TimeOut_t uxTimeoutState; /**< Timeout state. */
void * pvSearchID; /**< Search ID of the callback function. */
struct xLIST_ITEM xListItem; /**< List struct. */
BaseType_t xIsIPv6; /**< Remember whether this was a IPv6 lookup. */
char pcName[ 1 ]; /**< 1 character name. */
} DNSCallback_t;
#endif /* if ( ipconfigDNS_USE_CALLBACKS != 0 ) */
/**
* @brief structure to hold the buffer, its size and the data length
*/
typedef struct xDNSBuffer
{
uint8_t * pucPayloadBuffer; /**< Buffer pointer */
size_t uxPayloadLength; /**< Payload size */
} DNSBuffer_t;
#if ( ipconfigUSE_MDNS == 1 ) || ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_NBNS == 1 )
/*
* The following function should be provided by the user and return true if it
* matches the domain name.
*/
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
/* Even though the function is defined in main.c, the rule is violated. */
/* misra_c_2012_rule_8_6_violation */
extern BaseType_t xApplicationDNSQueryHook( const char * pcName );
#else
/* Even though the function is defined in main.c, the rule is violated. */
/* misra_c_2012_rule_8_6_violation */
extern BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint,
const char * pcName );
#endif
#endif /* ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_NBNS == 1 ) */
#endif /* ipconfigUSE_DNS */
/* Keeping this outside of ipconfigUSE_DNS flag as these are used inside IPv4 UDP code */
#define ipMDNS_PORT 5353U /* Standard mDNS port. */
#if ( ipconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN )
#define ipMDNS_IP_ADDRESS 0xe00000fbU /* 224.0.0.251 */
#else
#define ipMDNS_IP_ADDRESS 0xfb0000e0U /* 224.0.0.251 */
#endif
#endif /* FREERTOS_DNS_GLOBALS_H */
@@ -0,0 +1,62 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://github.com/FreeRTOS
* https://www.FreeRTOS.org
*/
#ifndef FREERTOS_DNS_NETWORKING_H
#define FREERTOS_DNS_NETWORKING_H
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_DNS_Globals.h"
#if ( ipconfigUSE_DNS != 0 )
/*
* Create a socket and bind it to the standard DNS port number. Return the
* the created socket - or NULL if the socket could not be created or bound.
*/
Socket_t DNS_CreateSocket( TickType_t uxReadTimeOut_ticks );
/**
* @brief Bind the socket to a port number.
* @param[in] xSocket: the socket that must be bound.
* @param[in] usPort: the port number to bind to.
* @return The created socket - or NULL if the socket could not be created or could not be bound.
*/
BaseType_t DNS_BindSocket( Socket_t xSocket,
uint16_t usPort );
BaseType_t DNS_SendRequest( Socket_t xDNSSocket,
const struct freertos_sockaddr * xAddress,
const struct xDNSBuffer * pxDNSBuf );
BaseType_t DNS_ReadReply( ConstSocket_t xDNSSocket,
struct freertos_sockaddr * xAddress,
struct xDNSBuffer * pxReceiveBuffer );
void DNS_CloseSocket( Socket_t xDNSSocket );
#endif /* if ( ipconfigUSE_DNS != 0 ) */
#endif /* FREERTOS_DNS_NETWORKING_H */
@@ -0,0 +1,104 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://github.com/FreeRTOS
* https://www.FreeRTOS.org
*/
#ifndef FREERTOS_DNS_PARSER_H
#define FREERTOS_DNS_PARSER_H
/* FreeRTOS includes. */
#include "FreeRTOS.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_DNS_Globals.h"
/* Standard includes. */
#include <stdint.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#if ( ipconfigUSE_DNS != 0 )
/** @brief Flag DNS parsing errors in situations where an IPv4 address is the return
* type. */
#if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 )
size_t DNS_ReadNameField( ParseSet_t * pxSet,
size_t uxDestLen );
#endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS */
/*
* Simple routine that jumps over the NAME field of a resource record.
* It returns the number of bytes read.
*/
size_t DNS_SkipNameField( const uint8_t * pucByte,
size_t uxLength );
/*
* Process a response packet from a DNS server.
* The parameter 'xExpected' indicates whether the identifier in the reply
* was expected, and thus if the DNS cache may be updated with the reply.
*/
uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer,
size_t uxBufferLength,
struct freertos_addrinfo ** ppxAddressInfo,
BaseType_t xExpected,
uint16_t usPort );
/*
* The NBNS and the LLMNR protocol share this reply function.
*/
#if ( ( ipconfigUSE_MDNS == 1 ) || ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_NBNS == 1 ) )
void prepareReplyDNSMessage( NetworkBufferDescriptor_t * pxNetworkBuffer,
BaseType_t lNetLength );
#endif
#if ( ipconfigUSE_NBNS == 1 )
void DNS_TreatNBNS( uint8_t * pucPayload,
size_t uxBufferLength,
uint32_t ulIPAddress );
#endif
/**
* Parse the DNS answer/response.
*/
uint32_t parseDNSAnswer( ParseSet_t * pxSet,
struct freertos_addrinfo ** ppxAddressInfo,
size_t * uxBytesRead );
#endif /* if ( ipconfigUSE_DNS != 0 ) */
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_DNS_PARSER_H */
@@ -0,0 +1,64 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/**
* @file FreeRTOS_ICMP.h
* @brief Header file for Internet Control Message Protocol for the FreeRTOS+TCP network stack.
*/
#ifndef FREERTOS_ICMP_H
#define FREERTOS_ICMP_H
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* ICMP protocol definitions. */
#define ipICMP_ECHO_REQUEST ( ( uint8_t ) 8 ) /**< ICMP echo request. */
#define ipICMP_ECHO_REPLY ( ( uint8_t ) 0 ) /**< ICMP echo reply. */
#if ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
/*
* Process incoming ICMP packets.
*/
eFrameProcessingResult_t ProcessICMPPacket( const NetworkBufferDescriptor_t * const pxNetworkBuffer );
#endif /* ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) */
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_ICMP_H */
@@ -0,0 +1,501 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_IP_H
#define FREERTOS_IP_H
#include "FreeRTOS.h"
#include "task.h"
/* Application level configuration options. */
#include "FreeRTOSIPConfig.h"
#include "FreeRTOSIPConfigDefaults.h"
#include "FreeRTOS_IP_Common.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Constants defining the current version of the FreeRTOS+TCP
* network stack. */
#define ipFR_TCP_VERSION_NUMBER "V4.4.1"
#define ipFR_TCP_VERSION_MAJOR 4
#define ipFR_TCP_VERSION_MINOR 4
/* Development builds are always version 999. */
#define ipFR_TCP_VERSION_BUILD 1
/* Some constants defining the sizes of several parts of a packet.
* These defines come before including the configuration header files. */
/* The size of the Ethernet header is 14, meaning that 802.1Q VLAN tags
* are not ( yet ) supported. */
#define ipSIZE_OF_ETH_HEADER 14U
#define ipSIZE_OF_IGMP_HEADER 8U
#define ipSIZE_OF_UDP_HEADER 8U
#define ipSIZE_OF_TCP_HEADER 20U
/* The maximum of int32 value. */
#define ipINT32_MAX_VALUE ( ( int32_t ) 0x7FFFFFFFU )
/* The minimum of int32 value. */
#define ipINT32_MIN_VALUE ( ( int32_t ) 0x80000000U )
/*
* Generate a randomized TCP Initial Sequence Number per RFC.
* This function must be provided by the application builder.
*/
/* This function is defined generally by the application. */
extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort );
/* The number of octets in the MAC and IP addresses respectively. */
#define ipMAC_ADDRESS_LENGTH_BYTES ( 6U )
#define ipIP_ADDRESS_LENGTH_BYTES ( 4U )
/* IP protocol definitions. */
#define ipPROTOCOL_ICMP ( 1U )
#define ipPROTOCOL_IGMP ( 2U )
#define ipPROTOCOL_TCP ( 6U )
#define ipPROTOCOL_UDP ( 17U )
/* The character used to fill ICMP echo requests, and therefore also the
* character expected to fill ICMP echo replies. */
#define ipECHO_DATA_FILL_BYTE 'x'
/* Dimensions the buffers that are filled by received Ethernet frames. */
#define ipSIZE_OF_ETH_CRC_BYTES ( 4UL )
#define ipSIZE_OF_ETH_OPTIONAL_802_1Q_TAG_BYTES ( 4UL )
#define ipTOTAL_ETHERNET_FRAME_SIZE ( ( ( uint32_t ) ipconfigNETWORK_MTU ) + ( ( uint32_t ) ipSIZE_OF_ETH_HEADER ) + ipSIZE_OF_ETH_CRC_BYTES + ipSIZE_OF_ETH_OPTIONAL_802_1Q_TAG_BYTES )
/* Space left at the beginning of a network buffer storage area to store a
* pointer back to the network buffer. Should be a multiple of 8 to ensure 8 byte
* alignment is maintained on architectures that require it.
*
* In order to get a 32-bit or 64-bit alignment of network packets, an offset of 2 bytes
* is ideal as defined by ipconfigPACKET_FILLER_SIZE. So the malloc'd
* buffer will have the following contents:
*
* +---------+-----------+---------+
* | Offset | Alignment | Length |
* | 32 | 64 | 32 | 64 | 32 | 64 |
* |----|----|-----|-----|----|----|
* | 0 | 0 | 4 | 8 | 4 | 8 | uchar_8 * pointer; // Points to the 'NetworkBufferDescriptor_t'.
* | 4 | 8 | 4 | 8 | 6 | 6 | uchar_8 filler[6]; // To give the +2 byte offset.
* |-------------------------------|
* | 10 | 14 | 4+2 | 8+2 | 6 | 6 | uchar_8 dest_mac[6]; // Destination address.
* | 16 | 20 | 4 | 8 | 6 | 6 | uchar_8 src_mac[6]; // Source address.
* | 22 | 26 | 4+2 | 4+2 | 2 | 2 | uchar16_t ethertype;
* | 24 | 28 | 4 | 4 | ~ | ~ | << IP-header >> // word-aligned, either 4 or 8 bytes.
* uint8_t ucVersionHeaderLength;
* etc
*/
/* Use setting from FreeRTOS if defined and non-zero */
#if ( ipconfigBUFFER_PADDING != 0 )
#define ipBUFFER_PADDING ipconfigBUFFER_PADDING
#elif ( UINTPTR_MAX > 0xFFFFFFFFU )
#define ipBUFFER_PADDING ( 12U + ipconfigPACKET_FILLER_SIZE )
#else
#define ipBUFFER_PADDING ( 8U + ipconfigPACKET_FILLER_SIZE )
#endif
/* The offset of ucTCPFlags within the TCP header. */
#define ipTCP_FLAGS_OFFSET 13U
/** @brief Returned to indicate a valid checksum. */
#define ipCORRECT_CRC 0xffffU
/** @brief Returned to indicate incorrect checksum. */
#define ipWRONG_CRC 0x0000U
/** @brief Returned as the (invalid) checksum when the length of the data being checked
* had an invalid length. */
#define ipINVALID_LENGTH 0x1234U
/** @brief Returned as the (invalid) checksum when the protocol being checked is not
* handled. The value is chosen simply to be easy to spot when debugging. */
#define ipUNHANDLED_PROTOCOL 0x4321U
/* Trace macros to aid in debugging, disabled if ipconfigHAS_PRINTF != 1 */
#if ( ipconfigHAS_PRINTF == 1 )
#define DEBUG_DECLARE_TRACE_VARIABLE( type, var, init ) type var = ( init ) /**< Trace macro to set "type var = init". */
#define DEBUG_SET_TRACE_VARIABLE( var, value ) var = ( value ) /**< Trace macro to set var = value. */
#else
#define DEBUG_DECLARE_TRACE_VARIABLE( type, var, init ) /**< Empty definition since ipconfigHAS_PRINTF != 1. */
#define DEBUG_SET_TRACE_VARIABLE( var, value ) /**< Empty definition since ipconfigHAS_PRINTF != 1. */
#endif
/**
* The structure used to store buffers and pass them around the network stack.
* Buffers can be in use by the stack, in use by the network interface hardware
* driver, or free (not in use).
*/
typedef struct xNETWORK_BUFFER
{
ListItem_t xBufferListItem; /**< Used to reference the buffer form the free buffer list or a socket. */
IP_Address_t xIPAddress; /**< Source or destination IP address, depending on usage scenario. */
uint8_t * pucEthernetBuffer; /**< Pointer to the start of the Ethernet frame. */
size_t xDataLength; /**< Starts by holding the total Ethernet frame length, then the UDP/TCP payload length. */
struct xNetworkInterface * pxInterface; /**< The interface on which the packet was received. */
struct xNetworkEndPoint * pxEndPoint; /**< The end-point through which this packet shall be sent. */
uint16_t usPort; /**< Source or destination port, depending on usage scenario. */
uint16_t usBoundPort; /**< The port to which a transmitting socket is bound. */
#if ( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
struct xNETWORK_BUFFER * pxNextBuffer; /**< Possible optimisation for expert users - requires network driver support. */
#endif
#define ul_IPAddress xIPAddress.xIP_IPv4
#define x_IPv6Address xIPAddress.xIP_IPv6
} NetworkBufferDescriptor_t;
#include "pack_struct_start.h"
/**
* MAC address structure.
*/
struct xMAC_ADDRESS
{
uint8_t ucBytes[ ipMAC_ADDRESS_LENGTH_BYTES ]; /**< Byte array of the MAC address */
}
#include "pack_struct_end.h"
typedef struct xMAC_ADDRESS MACAddress_t;
typedef enum eNETWORK_EVENTS
{
eNetworkUp, /* The network is configured. */
eNetworkDown /* The network connection has been lost. */
} eIPCallbackEvent_t;
/* MISRA check: some modules refer to this typedef even though
* ipconfigSUPPORT_OUTGOING_PINGS is not enabled. */
typedef enum ePING_REPLY_STATUS
{
eSuccess = 0, /**< A correct reply has been received for an outgoing ping. */
eInvalidChecksum, /**< A reply was received for an outgoing ping but the checksum of the reply was incorrect. */
eInvalidData /**< A reply was received to an outgoing ping but the payload of the reply was not correct. */
} ePingReplyStatus_t;
/**
* The software timer struct for various IP functions
*/
typedef struct xIP_TIMER
{
uint32_t
bActive : 1, /**< This timer is running and must be processed. */
bExpired : 1; /**< Timer has expired and a task must be processed. */
TimeOut_t xTimeOut; /**< The timeout value. */
TickType_t ulRemainingTime; /**< The amount of time remaining. */
TickType_t ulReloadTime; /**< The value of reload time. */
} IPTimer_t;
/* Endian related definitions. */
#if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
/* FreeRTOS_htons / FreeRTOS_htonl: some platforms might have built-in versions
* using a single instruction so allow these versions to be overridden. */
#ifndef FreeRTOS_htons
#define FreeRTOS_htons( usIn ) ( ( uint16_t ) ( ( ( usIn ) << 8U ) | ( ( usIn ) >> 8U ) ) )
#endif
#ifndef FreeRTOS_htonl
#define FreeRTOS_htonl( ulIn ) \
( \
( uint32_t ) \
( \
( ( ( ( uint32_t ) ( ulIn ) ) ) << 24 ) | \
( ( ( ( uint32_t ) ( ulIn ) ) & 0x0000ff00U ) << 8 ) | \
( ( ( ( uint32_t ) ( ulIn ) ) & 0x00ff0000U ) >> 8 ) | \
( ( ( ( uint32_t ) ( ulIn ) ) ) >> 24 ) \
) \
)
#endif /* ifndef FreeRTOS_htonl */
#else /* ipconfigBYTE_ORDER */
#define FreeRTOS_htons( x ) ( ( uint16_t ) ( x ) )
#define FreeRTOS_htonl( x ) ( ( uint32_t ) ( x ) )
#endif /* ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN */
#define FreeRTOS_ntohs( x ) FreeRTOS_htons( x )
#define FreeRTOS_ntohl( x ) FreeRTOS_htonl( x )
/* Translate a pdFREERTOS_ERRNO code to a human readable string. */
const char * FreeRTOS_strerror_r( BaseType_t xErrnum,
char * pcBuffer,
size_t uxLength );
/* Some simple helper functions. */
int32_t FreeRTOS_max_int32( int32_t a,
int32_t b );
uint32_t FreeRTOS_max_uint32( uint32_t a,
uint32_t b );
size_t FreeRTOS_max_size_t( size_t a,
size_t b );
int32_t FreeRTOS_min_int32( int32_t a,
int32_t b );
uint32_t FreeRTOS_min_uint32( uint32_t a,
uint32_t b );
size_t FreeRTOS_min_size_t( size_t a,
size_t b );
int32_t FreeRTOS_add_int32( int32_t a,
int32_t b );
int32_t FreeRTOS_multiply_int32( int32_t a,
int32_t b );
uint32_t FreeRTOS_round_up( uint32_t a,
uint32_t d );
uint32_t FreeRTOS_round_down( uint32_t a,
uint32_t d );
#define ipMS_TO_MIN_TICKS( xTimeInMs ) ( ( pdMS_TO_TICKS( ( xTimeInMs ) ) < ( ( TickType_t ) 1U ) ) ? ( ( TickType_t ) 1U ) : pdMS_TO_TICKS( ( xTimeInMs ) ) )
/* For backward compatibility. */
#define pdMS_TO_MIN_TICKS( xTimeInMs ) ipMS_TO_MIN_TICKS( xTimeInMs )
#ifndef pdTRUE_SIGNED
#define pdTRUE_SIGNED pdTRUE
#endif /* pdTRUE_SIGNED */
#ifndef pdFALSE_SIGNED
#define pdFALSE_SIGNED pdFALSE
#endif /* pdFALSE_SIGNED */
#ifndef pdTRUE_UNSIGNED
#define pdTRUE_UNSIGNED ( 1U )
#endif /* pdTRUE_UNSIGNED */
#ifndef pdFALSE_UNSIGNED
#define pdFALSE_UNSIGNED ( 0U )
#endif /* pdFALSE_UNSIGNED */
#ifndef ipTRUE_BOOL
#define ipTRUE_BOOL ( pdPASS == pdPASS )
#endif /* ipTRUE_BOOL */
#ifndef ipFALSE_BOOL
#define ipFALSE_BOOL ( pdPASS == pdFAIL )
#endif /* ipFALSE_BOOL */
/*
* FULL, UP-TO-DATE AND MAINTAINED REFERENCE DOCUMENTATION FOR ALL THESE
* FUNCTIONS IS AVAILABLE ON THE FOLLOWING URL:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/01-FreeRTOS-plus-TCP-APIs
*/
/* FreeRTOS_IPInit_Multi() replaces the earlier FreeRTOS_IPInit(). It assumes
* that network interfaces and IP-addresses have been added using the functions
* from FreeRTOS_Routing.h. */
BaseType_t FreeRTOS_IPInit_Multi( void );
struct xNetworkInterface;
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
/* Do not call the following function directly. It is there for downward compatibility.
* The function FreeRTOS_IPInit() will call it to initialise the interface and end-point
* objects. See the description in FreeRTOS_Routing.h. */
struct xNetworkInterface * pxFillInterfaceDescriptor( BaseType_t xEMACIndex,
struct xNetworkInterface * pxInterface );
/* The following function is only provided to allow backward compatibility
* with the earlier version of FreeRTOS+TCP which had a single interface only. */
BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ],
const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] );
/* The following 2 functions also assume that there is only 1 network endpoint/interface.
* The new function are called: FreeRTOS_GetEndPointConfiguration() and
* FreeRTOS_SetEndPointConfiguration() */
void FreeRTOS_GetAddressConfiguration( uint32_t * pulIPAddress,
uint32_t * pulNetMask,
uint32_t * pulGatewayAddress,
uint32_t * pulDNSServerAddress );
void FreeRTOS_SetAddressConfiguration( const uint32_t * pulIPAddress,
const uint32_t * pulNetMask,
const uint32_t * pulGatewayAddress,
const uint32_t * pulDNSServerAddress );
void * FreeRTOS_GetUDPPayloadBuffer( size_t uxRequestedSizeBytes,
TickType_t uxBlockTimeTicks );
#endif /* if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) */
/*
* Returns the addresses stored in an end-point structure.
* This function already existed in the release with the single-interface.
* Only the first parameters is new: an end-point
*/
void FreeRTOS_GetEndPointConfiguration( uint32_t * pulIPAddress,
uint32_t * pulNetMask,
uint32_t * pulGatewayAddress,
uint32_t * pulDNSServerAddress,
const struct xNetworkEndPoint * pxEndPoint );
void FreeRTOS_SetEndPointConfiguration( const uint32_t * pulIPAddress,
const uint32_t * pulNetMask,
const uint32_t * pulGatewayAddress,
const uint32_t * pulDNSServerAddress,
struct xNetworkEndPoint * pxEndPoint );
TaskHandle_t FreeRTOS_GetIPTaskHandle( void );
void * FreeRTOS_GetUDPPayloadBuffer_Multi( size_t uxRequestedSizeBytes,
TickType_t uxBlockTimeTicks,
uint8_t ucIPType );
/* MISRA defining 'FreeRTOS_SendPingRequest' should be dependent on 'ipconfigSUPPORT_OUTGOING_PINGS'.
* In order not to break some existing project, define it unconditionally. */
BaseType_t FreeRTOS_SendPingRequest( uint32_t ulIPAddress,
size_t uxNumberOfBytesToSend,
TickType_t uxBlockTimeTicks );
void FreeRTOS_ReleaseUDPPayloadBuffer( void const * pvBuffer );
const uint8_t * FreeRTOS_GetMACAddress( void );
void FreeRTOS_UpdateMACAddress( const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] );
#if ( ipconfigUSE_NETWORK_EVENT_HOOK == 1 )
/* This function shall be defined by the application. */
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent );
#else
void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent,
struct xNetworkEndPoint * pxEndPoint );
#endif
#endif
#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
void vApplicationPingReplyHook( ePingReplyStatus_t eStatus,
uint16_t usIdentifier );
#endif
BaseType_t FreeRTOS_IsNetworkUp( void );
#if ( ipconfigCHECK_IP_QUEUE_SPACE != 0 )
UBaseType_t uxGetMinimumIPQueueSpace( void );
#endif
BaseType_t xIsNetworkDownEventPending( void );
/*
* Defined in FreeRTOS_Sockets.c
* //_RB_ Don't think this comment is correct. If this is for internal use only it should appear after all the public API functions and not start with FreeRTOS_.
* Socket has had activity, reset the timer so it will not be closed
* because of inactivity
*/
#if ( ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) )
const char * FreeRTOS_GetTCPStateName( UBaseType_t ulState );
#endif
#if ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
/* DHCP has an option for clients to register their hostname. It doesn't
* have much use, except that a device can be found in a router along with its
* name. If this option is used the callback below must be provided by the
* application writer to return a const string, denoting the device's name. */
/* Typically this function is defined in a user module. */
const char * pcApplicationHostnameHook( void );
#endif /* ipconfigDHCP_REGISTER_HOSTNAME */
/* This xApplicationGetRandomNumber() will set *pulNumber to a random number,
* and return pdTRUE. When the random number generator is broken, it shall return
* pdFALSE.
* The function is defined in 'iot_secure_sockets.c'.
* If that module is not included in the project, the application must provide an
* implementation of it.
* The macro's ipconfigRAND32() and configRAND32() are not in use anymore. */
/* "xApplicationGetRandomNumber" is declared but never defined, because it may
* be defined in a user module. */
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber );
/** @brief The pointers to buffers with packet waiting for resolution. These variables
* are defined in FreeRTOS_IP.c.
* These pointers are for internal use only. */
extern NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer;
extern NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer;
#if ( ipconfigENABLE_BACKWARD_COMPATIBILITY == 1 )
#define xIPStackEvent_t IPStackEvent_t
#define xNetworkBufferDescriptor_t NetworkBufferDescriptor_t
#define xMACAddress_t MACAddress_t
#define xWinProperties_t WinProperties_t
#define xSocket_t Socket_t
#define xSocketSet_t SocketSet_t
#define ipSIZE_OF_IP_HEADER ipSIZE_OF_IPv4_HEADER
/* Since August 2016, the public types and fields below have changed name:
* abbreviations TCP/UDP are now written in capitals, and type names now end with "_t". */
#define FOnConnected FOnConnected_t
#define FOnTcpReceive FOnTCPReceive_t
#define FOnTcpSent FOnTCPSent_t
#define FOnUdpReceive FOnUDPReceive_t
#define FOnUdpSent FOnUDPSent_t
#define pOnTcpConnected pxOnTCPConnected
#define pOnTcpReceive pxOnTCPReceive
#define pOnTcpSent pxOnTCPSent
#define pOnUdpReceive pxOnUDPReceive
#define pOnUdpSent pxOnUDPSent
#define FOnUdpSent FOnUDPSent_t
#define FOnTcpSent FOnTCPSent_t
#endif /* ipconfigENABLE_BACKWARD_COMPATIBILITY */
#if ( ipconfigHAS_PRINTF != 0 )
extern void vPrintResourceStats( void );
#else
#define vPrintResourceStats() do {} while( ipFALSE_BOOL ) /**< ipconfigHAS_PRINTF is not defined. Define vPrintResourceStats to a do-while( 0 ). */
#endif
#include "FreeRTOS_IP_Utils.h"
#include "FreeRTOS_IPv4.h"
#include "FreeRTOS_IPv6.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IP_H */
@@ -0,0 +1,76 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_IP_COMMON_H
#define FREERTOS_IP_COMMON_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
struct xIPv6_Address
{
uint8_t ucBytes[ 16 ];
};
typedef struct xIPv6_Address IPv6_Address_t;
typedef union IP_Address
{
uint32_t ulIP_IPv4; /**< IPv4 address */
IPv6_Address_t xIP_IPv6; /**< IPv6 address */
} IP_Address_t;
/** @brief A struct that can hold either an IPv4 or an IPv6 address. */
typedef struct xxIPv46_Address
{
/* A struct that can hold either an IPv4 or an IPv6 address. */
IP_Address_t xIPAddress; /**< IP address contains either IPv4 or IPv6. */
BaseType_t xIs_IPv6; /**< pdTRUE if IPv6 address. */
} IPv46_Address_t;
struct xNetworkEndPoint;
struct xNetworkInterface;
/* Return true if a given end-point is up and running.
* When FreeRTOS_IsNetworkUp() is called with NULL as a parameter,
* it will return pdTRUE when all end-points are up. */
BaseType_t FreeRTOS_IsEndPointUp( const struct xNetworkEndPoint * pxEndPoint );
/* Return pdTRUE if all end-points are up.
* When pxInterface is null, all end-points will be checked. */
BaseType_t FreeRTOS_AllEndPointsUp( const struct xNetworkInterface * pxInterface );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IP_COMMON_H */
@@ -0,0 +1,856 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
#ifndef FREERTOS_IP_PRIVATE_H
#define FREERTOS_IP_PRIVATE_H
/* Application level configuration options. */
#include "FreeRTOSIPConfig.h"
#include "FreeRTOSIPConfigDefaults.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_Stream_Buffer.h"
#include "FreeRTOS_Routing.h"
#if ( ipconfigUSE_TCP == 1 )
#include "FreeRTOS_TCP_WIN.h"
#include "FreeRTOS_TCP_IP.h"
#endif
#include "semphr.h"
#include "event_groups.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#ifdef TEST
int ipFOREVER( void );
#else
#define ipFOREVER() 1
#endif
/* Forward declaration. */
struct xNetworkEndPoint;
typedef enum eFrameProcessingResult
{
eReleaseBuffer = 0, /* Processing the frame did not find anything to do - just release the buffer. */
eProcessBuffer, /* An Ethernet frame has a valid address - continue process its contents. */
eReturnEthernetFrame, /* The Ethernet frame contains an ARP or ICMP packet that can be returned to its source. */
eFrameConsumed, /* Processing the Ethernet packet contents resulted in the payload being sent to the stack. */
eWaitingResolution /* Frame is awaiting resolution. */
} eFrameProcessingResult_t;
typedef enum
{
eNoEvent = -1,
eNetworkDownEvent, /* 0: The network interface has been lost and/or needs [re]connecting. */
eNetworkRxEvent, /* 1: The network interface has queued a received Ethernet frame. */
eNetworkTxEvent, /* 2: Let the IP-task send a network packet. */
eARPTimerEvent, /* 3: The ARP timer expired. */
eNDTimerEvent, /* 4: The ND timer expired. */
eStackTxEvent, /* 5: The software stack has queued a packet to transmit. */
eDHCPEvent, /* 6: Process the DHCP state machine. */
eTCPTimerEvent, /* 7: See if any TCP socket needs attention. */
eTCPAcceptEvent, /* 8: Client API FreeRTOS_accept() waiting for client connections. */
eTCPNetStat, /* 9: IP-task is asked to produce a netstat listing. */
eSocketBindEvent, /*10: Send a message to the IP-task to bind a socket to a port. */
eSocketCloseEvent, /*11: Send a message to the IP-task to close a socket. */
eSocketSelectEvent, /*12: Send a message to the IP-task for select(). */
eSocketSignalEvent, /*13: A socket must be signalled. */
eSocketSetDeleteEvent /*14: A socket set must be deleted. */
} eIPEvent_t;
/**
* Structure to hold the information about the Network parameters.
*/
typedef struct xNetworkAddressingParameters
{
uint32_t ulDefaultIPAddress; /**< The default IP address */
uint32_t ulNetMask; /**< The netmask */
uint32_t ulGatewayAddress; /**< The gateway address */
uint32_t ulDNSServerAddress; /**< The DNS server address */
uint32_t ulBroadcastAddress; /**< The Broadcast address */
} NetworkAddressingParameters_t;
extern BaseType_t xTCPWindowLoggingLevel;
extern QueueHandle_t xNetworkEventQueue;
typedef struct xSOCKET FreeRTOS_Socket_t;
/*-----------------------------------------------------------*/
/* Protocol headers. */
/*-----------------------------------------------------------*/
#include "pack_struct_start.h"
struct xETH_HEADER
{
MACAddress_t xDestinationAddress; /**< Destination address 0 + 6 = 6 */
MACAddress_t xSourceAddress; /**< Source address 6 + 6 = 12 */
uint16_t usFrameType; /**< The EtherType field 12 + 2 = 14 */
}
#include "pack_struct_end.h"
typedef struct xETH_HEADER EthernetHeader_t;
#include "pack_struct_start.h"
struct xARP_HEADER
{
uint16_t usHardwareType; /**< Network Link Protocol type 0 + 2 = 2 */
uint16_t usProtocolType; /**< The internetwork protocol 2 + 2 = 4 */
uint8_t ucHardwareAddressLength; /**< Length in octets of a hardware address 4 + 1 = 5 */
uint8_t ucProtocolAddressLength; /**< Length in octets of the internetwork protocol 5 + 1 = 6 */
uint16_t usOperation; /**< Operation that the sender is performing 6 + 2 = 8 */
MACAddress_t xSenderHardwareAddress; /**< Media address of the sender 8 + 6 = 14 */
uint8_t ucSenderProtocolAddress[ 4 ]; /**< Internetwork address of sender 14 + 4 = 18 */
MACAddress_t xTargetHardwareAddress; /**< Media address of the intended receiver 18 + 6 = 24 */
uint32_t ulTargetProtocolAddress; /**< Internetwork address of the intended receiver 24 + 4 = 28 */
}
#include "pack_struct_end.h"
typedef struct xARP_HEADER ARPHeader_t;
#include "pack_struct_start.h"
struct xICMP_HEADER
{
uint8_t ucTypeOfMessage; /**< The ICMP type 0 + 1 = 1 */
uint8_t ucTypeOfService; /**< The ICMP subtype 1 + 1 = 2 */
uint16_t usChecksum; /**< The checksum of whole ICMP packet 2 + 2 = 4 */
uint16_t usIdentifier; /**< Used in some types of ICMP 4 + 2 = 6 */
uint16_t usSequenceNumber; /**< Used in some types of ICMP 6 + 2 = 8 */
}
#include "pack_struct_end.h"
typedef struct xICMP_HEADER ICMPHeader_t;
#include "pack_struct_start.h"
struct xICMPHeader_IPv6
{
uint8_t ucTypeOfMessage; /**< The message type. 0 + 1 = 1 */
uint8_t ucTypeOfService; /**< Type of service. 1 + 1 = 2 */
uint16_t usChecksum; /**< Checksum. 2 + 2 = 4 */
uint32_t ulReserved; /**< Reserved. 4 + 4 = 8 */
IPv6_Address_t xIPv6Address; /**< The IPv6 address. 8 + 16 = 24 */
uint8_t ucOptionType; /**< The option type. 24 + 1 = 25 */
uint8_t ucOptionLength; /**< The option length. 25 + 1 = 26 */
uint8_t ucOptionBytes[ 6 ]; /**< Option bytes. 26 + 6 = 32 */
}
#include "pack_struct_end.h"
typedef struct xICMPHeader_IPv6 ICMPHeader_IPv6_t;
#include "pack_struct_start.h"
struct xUDP_HEADER
{
uint16_t usSourcePort; /**< The source port 0 + 2 = 2 */
uint16_t usDestinationPort; /**< The destination port 2 + 2 = 4 */
uint16_t usLength; /**< The size of the whole UDP packet 4 + 2 = 6 */
uint16_t usChecksum; /**< The checksum of the whole UDP Packet 6 + 2 = 8 */
}
#include "pack_struct_end.h"
typedef struct xUDP_HEADER UDPHeader_t;
#include "pack_struct_start.h"
struct xTCP_HEADER
{
uint16_t usSourcePort; /**< The Source port + 2 = 2 */
uint16_t usDestinationPort; /**< The destination port + 2 = 4 */
uint32_t ulSequenceNumber; /**< The Sequence number + 4 = 8 */
uint32_t ulAckNr; /**< The acknowledgement number + 4 = 12 */
uint8_t ucTCPOffset; /**< The value of TCP offset + 1 = 13 */
uint8_t ucTCPFlags; /**< The TCP-flags field + 1 = 14 */
uint16_t usWindow; /**< The size of the receive window + 2 = 15 */
uint16_t usChecksum; /**< The checksum of the header + 2 = 18 */
uint16_t usUrgent; /**< Pointer to the last urgent data byte + 2 = 20 */
#if ipconfigUSE_TCP == 1
uint8_t ucOptdata[ ipSIZE_TCP_OPTIONS ]; /**< The options + 12 = 32 */
#endif
}
#include "pack_struct_end.h"
typedef struct xTCP_HEADER TCPHeader_t;
#include "pack_struct_start.h"
struct xARP_PACKET
{
EthernetHeader_t xEthernetHeader; /**< The ethernet header of an ARP Packet 0 + 14 = 14 */
ARPHeader_t xARPHeader; /**< The ARP header of an ARP Packet 14 + 28 = 42 */
}
#include "pack_struct_end.h"
typedef struct xARP_PACKET ARPPacket_t;
#include "FreeRTOS_IPv4_Private.h"
#include "FreeRTOS_IPv6_Private.h"
/**
* Union for the protocol packet to save space. Any packet cannot have more than one
* of the below protocol packets.
*/
typedef union XPROT_PACKET
{
ARPPacket_t xARPPacket; /**< Union member: ARP packet struct */
TCPPacket_t xTCPPacket; /**< Union member: TCP packet struct */
UDPPacket_t xUDPPacket; /**< Union member: UDP packet struct */
ICMPPacket_t xICMPPacket; /**< Union member: ICMP packet struct */
} ProtocolPacket_t;
/**
* Union for protocol headers to save space (RAM). Any packet cannot have more than one of
* the below protocols.
*/
typedef union xPROT_HEADERS
{
ICMPHeader_t xICMPHeader; /**< Union member: ICMP header */
UDPHeader_t xUDPHeader; /**< Union member: UDP header */
TCPHeader_t xTCPHeader; /**< Union member: TCP header */
ICMPHeader_IPv6_t xICMPHeaderIPv6; /**< Union member: ICMPv6 header */
} ProtocolHeaders_t;
/**
* Structure for the information of the commands issued to the IP task.
*/
typedef struct IP_TASK_COMMANDS
{
eIPEvent_t eEventType; /**< The event-type enum */
void * pvData; /**< The data in the event */
} IPStackEvent_t;
/** @brief This struct describes a packet, it is used by the function
* usGenerateProtocolChecksum(). */
struct xPacketSummary
{
BaseType_t xIsIPv6; /**< pdTRUE for IPv6 packets. */
#if ipconfigUSE_IPv6
const IPHeader_IPv6_t * pxIPPacket_IPv6; /**< A pointer to the IPv6 header. */
#endif
#if ( ipconfigHAS_DEBUG_PRINTF != 0 )
const char * pcType; /**< Just for logging purposes: the name of the protocol. */
#endif
size_t uxIPHeaderLength; /**< Either 40 or 20, depending on the IP-type */
size_t uxProtocolHeaderLength; /**< Either 8, 20, or more or 20, depending on the protocol-type */
uint16_t usChecksum; /**< Checksum accumulator. */
uint8_t ucProtocol; /**< ipPROTOCOL_TCP, ipPROTOCOL_UDP, ipPROTOCOL_ICMP */
const IPPacket_t * pxIPPacket; /**< A pointer to the IPv4 header. */
ProtocolHeaders_t * pxProtocolHeaders; /**< Points to first byte after IP-header */
uint16_t usPayloadLength; /**< Property of IP-header (for IPv4: length of IP-header included) */
uint16_t usProtocolBytes; /**< The total length of the protocol data. */
};
/* Offset into the Ethernet frame that is used to temporarily store information
* on the fragmentation status of the packet being sent. The value is important,
* as it is past the location into which the destination address will get placed. */
#define ipFRAGMENTATION_PARAMETERS_OFFSET ( 6 )
#define ipSOCKET_OPTIONS_OFFSET ( 6 )
#if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
/* Ethernet frame types. */
#define ipARP_FRAME_TYPE ( 0x0608U )
#define ipIPv4_FRAME_TYPE ( 0x0008U )
/* ARP related definitions. */
#define ipARP_PROTOCOL_TYPE ( 0x0008U )
#define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0100U )
#define ipARP_REQUEST ( 0x0100U )
#define ipARP_REPLY ( 0x0200U )
/* The bits in the two byte IP header field that make up the fragment offset value. */
#define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0xff1fU )
/* The bits in the two byte IP header field that make up the flags value. */
#define ipFRAGMENT_FLAGS_BIT_MASK ( ( uint16_t ) 0x00e0U )
/* Don't Fragment Flag */
#define ipFRAGMENT_FLAGS_DONT_FRAGMENT ( ( uint16_t ) 0x0040U )
/* More Fragments Flag */
#define ipFRAGMENT_FLAGS_MORE_FRAGMENTS ( ( uint16_t ) 0x0020U )
#else /* if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) */
/* Ethernet frame types. */
#define ipARP_FRAME_TYPE ( 0x0806U )
#define ipIPv4_FRAME_TYPE ( 0x0800U )
/* ARP related definitions. */
#define ipARP_PROTOCOL_TYPE ( 0x0800U )
#define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0001U )
#define ipARP_REQUEST ( 0x0001 )
#define ipARP_REPLY ( 0x0002 )
/* The bits in the two byte IP header field that make up the fragment offset value. */
#define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0x1fffU )
/* The bits in the two byte IP header field that make up the flags value. */
#define ipFRAGMENT_FLAGS_BIT_MASK ( ( uint16_t ) 0xe000U )
/* Don't Fragment Flag */
#define ipFRAGMENT_FLAGS_DONT_FRAGMENT ( ( uint16_t ) 0x4000U )
/* More Fragments Flag */
#define ipFRAGMENT_FLAGS_MORE_FRAGMENTS ( ( uint16_t ) 0x2000U )
#endif /* ipconfigBYTE_ORDER */
/* For convenience, a MAC address of all zeros and another of all 0xffs are
* defined const for quick reference. */
extern const MACAddress_t xBroadcastMACAddress; /* all 0xff's */
extern uint16_t usPacketIdentifier;
/** @brief The list that contains mappings between sockets and port numbers.
* Accesses to this list must be protected by critical sections of
* some kind.
*/
extern List_t xBoundUDPSocketsList;
/* True when BufferAllocation_1.c was included, false for BufferAllocation_2.c */
extern const BaseType_t xBufferAllocFixedSize;
/* As FreeRTOS_Routing is included later, use forward declarations
* of the two structs. */
struct xNetworkEndPoint;
struct xNetworkInterface;
/* A list of all network end-points: */
extern struct xNetworkEndPoint * pxNetworkEndPoints;
/* A list of all network interfaces: */
extern struct xNetworkInterface * pxNetworkInterfaces;
/* Defined in FreeRTOS_Sockets.c */
#if ( ipconfigUSE_TCP == 1 )
extern List_t xBoundTCPSocketsList;
#endif
/* ICMP packets are sent using the same function as UDP packets. The port
* number is used to distinguish between the two, as 0 is an invalid UDP port. */
#define ipPACKET_CONTAINS_ICMP_DATA ( 0 )
/* For now, the lower 8 bits in 'xEventBits' will be reserved for the above
* socket events. */
#define SOCKET_EVENT_BIT_COUNT 8
#define vSetField16( pxBase, xType, xField, usValue ) \
do { \
( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 0 ] = ( uint8_t ) ( ( usValue ) >> 8 ); \
( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 1 ] = ( uint8_t ) ( ( usValue ) & 0xffU ); \
} while( ipFALSE_BOOL )
#define vSetField32( pxBase, xType, xField, ulValue ) \
{ \
( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 0 ] = ( uint8_t ) ( ( ulValue ) >> 24 ); \
( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 1 ] = ( uint8_t ) ( ( ( ulValue ) >> 16 ) & 0xffU ); \
( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 2 ] = ( uint8_t ) ( ( ( ulValue ) >> 8 ) & 0xffU ); \
( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 3 ] = ( uint8_t ) ( ( ulValue ) & 0xffU ); \
}
#define vFlip_16( left, right ) \
do { \
uint16_t tmp = ( left ); \
( left ) = ( right ); \
( right ) = tmp; \
} while( ipFALSE_BOOL )
#define vFlip_32( left, right ) \
do { \
uint32_t tmp = ( left ); \
( left ) = ( right ); \
( right ) = tmp; \
} while( ipFALSE_BOOL )
/** @brief Macro calculates the number of elements in an array as a size_t. */
#ifndef ARRAY_SIZE_X
#ifndef _WINDOWS_
#define ARRAY_SIZE_X( x ) ( ( BaseType_t ) sizeof( x ) / ( BaseType_t ) sizeof( x[ 0 ] ) )
#else
#define ARRAY_SIZE_X( x ) ( sizeof( x ) / sizeof( x[ 0 ] ) )
#endif
#endif
/* WARNING: Do NOT use this macro when the array was received as a parameter. */
#ifndef ARRAY_SIZE
#define ARRAY_SIZE( x ) ( ( BaseType_t ) ( sizeof( x ) / sizeof( ( x )[ 0 ] ) ) )
#endif
#ifndef ARRAY_USIZE
#define ARRAY_USIZE( x ) ( ( UBaseType_t ) ( sizeof( x ) / sizeof( ( x )[ 0 ] ) ) )
#endif
/*
* Create a message that contains a command to initialise the network interface.
* This is used during initialisation, and at any time the network interface
* goes down thereafter. The network interface hardware driver is responsible
* for sending the message that contains the network interface down command/
* event.
*
* Only use the FreeRTOS_NetworkDownFromISR() version if the function is to be
* called from an interrupt service routine. If FreeRTOS_NetworkDownFromISR()
* returns a non-zero value then a context switch should be performed before
* the interrupt is exited.
*/
void FreeRTOS_NetworkDown( struct xNetworkInterface * pxNetworkInterface );
BaseType_t FreeRTOS_NetworkDownFromISR( struct xNetworkInterface * pxNetworkInterface );
/*
* Processes incoming ARP packets.
*/
eFrameProcessingResult_t eARPProcessPacket( const NetworkBufferDescriptor_t * pxNetworkBuffer );
/*
* Inspect an Ethernet frame to see if it contains data that the stack needs to
* process. eProcessBuffer is returned if the frame should be processed by the
* stack. eReleaseBuffer is returned if the frame should be discarded.
*/
eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer );
/*
* Return the checksum generated over xDataLengthBytes from pucNextData.
*/
uint16_t usGenerateChecksum( uint16_t usSum,
const uint8_t * pucNextData,
size_t uxByteCount );
/* Socket related private functions. */
/*
* Initialize the socket list data structures for TCP and UDP.
*/
void vNetworkSocketsInit( void );
/*
* Returns pdTRUE if the IP task has been created and is initialised. Otherwise
* returns pdFALSE.
*/
BaseType_t xIPIsNetworkTaskReady( void );
#if ( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK == 1 )
struct xSOCKET;
typedef void (* SocketWakeupCallback_t)( struct xSOCKET * pxSocket );
#endif
#if ( ipconfigUSE_TCP == 1 )
/*
* Actually a user thing, but because xBoundTCPSocketsList, let it do by the
* IP-task
*/
#if ( ipconfigHAS_PRINTF != 0 )
void vTCPNetStat( void );
#endif
/*
* At least one socket needs to check for timeouts
*/
TickType_t xTCPTimerCheck( BaseType_t xWillSleep );
/**
* About the TCP flags 'bPassQueued' and 'bPassAccept':
*
* When a new TCP connection request is received on a listening socket, the bPassQueued and
* bPassAccept members of the newly created socket are updated as follows:
*
* 1. bPassQueued is set to indicate that the 3-way TCP handshake is in progress.
* 2. When the 3-way TCP handshake is complete, bPassQueued is cleared. At the same time,
* bPassAccept is set to indicate that the socket is ready to be picked up by the task
* that called FreeRTOS_accept().
* 3. When the socket is picked up by the task that called FreeRTOS_accept, the bPassAccept
* is cleared.
*/
/**
* Every TCP socket has a buffer space just big enough to store
* the last TCP header received.
* As a reference of this field may be passed to DMA, force the
* alignment to 8 bytes.
*/
typedef union
{
struct
{
uint32_t ullAlignmentWord; /**< Increase the alignment of this union by adding a 32-bit variable. */
} a; /**< A struct to increase alignment. */
struct
{
/* The next field only serves to give 'ucLastPacket' a correct
* alignment of 4 + 2. See comments in FreeRTOS_IP.h */
uint8_t ucFillPacket[ ipconfigPACKET_FILLER_SIZE ];
uint8_t ucLastPacket[ TCP_PACKET_SIZE ];
} u; /**< The structure to give an alignment of 4 + 2 */
} LastTCPPacket_t;
/**
* Note that the values of all short and long integers in these structs
* are being stored in the native-endian way
* Translation should take place when accessing any structure which defines
* network packets, such as IPHeader_t and TCPHeader_t
*/
typedef struct TCPSOCKET
{
IP_Address_t xRemoteIP; /**< IP address of remote machine */
uint16_t usRemotePort; /**< Port on remote machine */
struct
{
/* Most compilers do like bit-flags */
uint32_t
bMssChange : 1, /**< This socket has seen a change in MSS */
bPassAccept : 1, /**< See comment here above. */
bPassQueued : 1, /**< See comment here above. */
bReuseSocket : 1, /**< When a listening socket gets a connection, do not create a new instance but keep on using it */
bCloseAfterSend : 1, /**< As soon as the last byte has been transmitted, finalise the connection
* Useful in e.g. FTP connections, where the last data bytes are sent along with the FIN flag */
bUserShutdown : 1, /**< User requesting a graceful shutdown */
bCloseRequested : 1, /**< Request to finalise the connection */
bLowWater : 1, /**< high-water level has been reached. Cleared as soon as 'rx-count < lo-water' */
bWinChange : 1, /**< The value of bLowWater has changed, must send a window update */
bSendKeepAlive : 1, /**< When this flag is true, a TCP keep-alive message must be send */
bWaitKeepAlive : 1, /**< When this flag is true, a TCP keep-alive reply is expected */
bConnPrepared : 1, /**< Connecting socket: Message has been prepared */
#if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
bConnPassed : 1, /**< Connecting socket: Socket has been passed in a successful select() */
#endif /* ipconfigSUPPORT_SELECT_FUNCTION */
bFinAccepted : 1, /**< This socket has received (or sent) a FIN and accepted it */
bFinSent : 1, /**< We've sent out a FIN */
bFinRecv : 1, /**< We've received a FIN from our peer */
bFinAcked : 1, /**< Our FIN packet has been acked */
bFinLast : 1, /**< The last ACK (after FIN and FIN+ACK) has been sent or will be sent by the peer */
bRxStopped : 1, /**< Application asked to temporarily stop reception */
bMallocError : 1, /**< There was an error allocating a stream */
bWinScaling : 1; /**< A TCP-Window Scaling option was offered and accepted in the SYN phase. */
} bits; /**< The bits structure */
uint32_t ulHighestRxAllowed; /**< The highest sequence number that we can receive at any moment */
uint16_t usTimeout; /**< Time (in ticks) after which this socket needs attention */
uint16_t usMSS; /**< Current Maximum Segment Size */
uint16_t usChildCount; /**< In case of a listening socket: number of connections on this port number */
uint16_t usBacklog; /**< In case of a listening socket: maximum number of concurrent connections on this port number */
uint8_t ucRepCount; /**< Send repeat count, for retransmissions
* This counter is separate from the xmitCount in the
* TCP win segments */
eIPTCPState_t eTCPState; /**< TCP state: see eTCP_STATE */
struct xSOCKET * pxPeerSocket; /**< for server socket: child, for child socket: parent */
#if ( ipconfigTCP_KEEP_ALIVE == 1 )
uint8_t ucKeepRepCount;
TickType_t xLastAliveTime; /**< The last value of keepalive time.*/
#endif /* ipconfigTCP_KEEP_ALIVE */
#if ( ipconfigTCP_HANG_PROTECTION == 1 )
TickType_t xLastActTime; /**< The last time when hang-protection was done.*/
#endif /* ipconfigTCP_HANG_PROTECTION */
size_t uxLittleSpace; /**< The value deemed as low amount of space. */
size_t uxEnoughSpace; /**< The value deemed as enough space. */
size_t uxRxStreamSize; /**< The Receive stream size */
size_t uxTxStreamSize; /**< The transmit stream size */
StreamBuffer_t * rxStream; /**< The pointer to the receive stream buffer. */
StreamBuffer_t * txStream; /**< The pointer to the transmit stream buffer. */
#if ( ipconfigUSE_TCP_WIN == 1 )
NetworkBufferDescriptor_t * pxAckMessage; /**< The pointer to the ACK message */
#endif /* ipconfigUSE_TCP_WIN */
LastTCPPacket_t xPacket; /**< Buffer space to store the last TCP header received. */
uint8_t tcpflags; /**< TCP flags */
#if ( ipconfigUSE_TCP_WIN != 0 )
uint8_t ucMyWinScaleFactor; /**< Scaling factor of this device. */
uint8_t ucPeerWinScaleFactor; /**< Scaling factor of the peer. */
#endif
#if ( ipconfigUSE_CALLBACKS == 1 )
FOnTCPReceive_t pxHandleReceive; /**<
* In case of a TCP socket:
* typedef void (* FOnTCPReceive_t) (Socket_t xSocket, void *pData, size_t xLength );
*/
FOnTCPSent_t pxHandleSent; /**< Function pointer to handle a successful send event. */
FOnConnected_t pxHandleConnected; /**< Actually type: typedef void (* FOnConnected_t) (Socket_t xSocket, BaseType_t ulConnected ); */
#endif /* ipconfigUSE_CALLBACKS */
uint32_t ulWindowSize; /**< Current Window size advertised by peer */
size_t uxRxWinSize; /**< Fixed value: size of the TCP reception window */
size_t uxTxWinSize; /**< Fixed value: size of the TCP transmit window */
TCPWindow_t xTCPWindow; /**< The TCP window struct*/
} IPTCPSocket_t;
#endif /* ipconfigUSE_TCP */
/**
* Structure to hold the information about a UDP socket.
*/
typedef struct UDPSOCKET
{
List_t xWaitingPacketsList; /**< Incoming packets */
#if ( ipconfigUDP_MAX_RX_PACKETS > 0 )
UBaseType_t uxMaxPackets; /**< Protection: limits the number of packets buffered per socket */
#endif /* ipconfigUDP_MAX_RX_PACKETS */
#if ( ipconfigUSE_CALLBACKS == 1 )
FOnUDPReceive_t pxHandleReceive; /**<
* In case of a UDP socket:
* typedef void (* FOnUDPReceive_t) (Socket_t xSocket, void *pData, size_t xLength, struct freertos_sockaddr *pxAddr );
*/
FOnUDPSent_t pxHandleSent; /**< Function pointer to handle the events after a successful send. */
#endif /* ipconfigUSE_CALLBACKS */
} IPUDPSocket_t;
/* Formally typedef'd as eSocketEvent_t. */
enum eSOCKET_EVENT
{
eSOCKET_RECEIVE = 0x0001,
eSOCKET_SEND = 0x0002,
eSOCKET_ACCEPT = 0x0004,
eSOCKET_CONNECT = 0x0008,
eSOCKET_BOUND = 0x0010,
eSOCKET_CLOSED = 0x0020,
eSOCKET_INTR = 0x0040,
eSOCKET_ALL = 0x007F
};
/**
* Structure to hold information for a socket.
*/
struct xSOCKET
{
EventBits_t xEventBits; /**< The eventbits to keep track of events. */
EventGroupHandle_t xEventGroup; /**< The event group for this socket. */
/* Most compilers do like bit-flags */
struct
{
uint32_t bIsIPv6 : 1; /**< Non-zero in case the connection is using IPv6. */
uint32_t bSomeFlag : 1;
}
bits;
ListItem_t xBoundSocketListItem; /**< Used to reference the socket from a bound sockets list. */
TickType_t xReceiveBlockTime; /**< if recv[to] is called while no data is available, wait this amount of time. Unit in clock-ticks */
TickType_t xSendBlockTime; /**< if send[to] is called while there is not enough space to send, wait this amount of time. Unit in clock-ticks */
IP_Address_t xLocalAddress; /**< Local IP address */
uint16_t usLocalPort; /**< Local port on this machine */
uint8_t ucSocketOptions; /**< Socket options */
uint8_t ucProtocol; /**< choice of FREERTOS_IPPROTO_UDP/TCP */
#if ( ipconfigSOCKET_HAS_USER_SEMAPHORE == 1 )
SemaphoreHandle_t pxUserSemaphore; /**< The user semaphore */
#endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */
#if ( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK == 1 )
SocketWakeupCallback_t pxUserWakeCallback; /**< Pointer to the callback function. */
#endif /* ipconfigSOCKET_HAS_USER_WAKE_CALLBACK */
#if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
struct xSOCKET_SET * pxSocketSet; /**< Pointer to the socket set structure */
EventBits_t xSelectBits; /**< User may indicate which bits are interesting for this socket. */
EventBits_t xSocketBits; /**< These bits indicate the events which have actually occurred.
* They are maintained by the IP-task */
#endif /* ipconfigSUPPORT_SELECT_FUNCTION */
struct xNetworkEndPoint * pxEndPoint; /**< The end-point to which the socket is bound. */
/* This field is only only by the user, and can be accessed with
* vSocketSetSocketID() / vSocketGetSocketID().
* All fields of a socket will be cleared by memset() in FreeRTOS_socket().
*/
void * pvSocketID;
/* TCP/UDP specific fields: */
/* Before accessing any member of this structure, it should be confirmed */
/* that the protocol corresponds with the type of structure */
union
{
IPUDPSocket_t xUDP; /**< Union member: UDP socket*/
#if ( ipconfigUSE_TCP == 1 )
IPTCPSocket_t xTCP; /**< Union member: TCP socket */
#endif /* ipconfigUSE_TCP */
}
u; /**< Union of TCP/UDP socket */
};
#if ( ipconfigUSE_TCP == 1 )
/*
* Close the socket another time.
*/
void vSocketCloseNextTime( FreeRTOS_Socket_t * pxSocket );
/*
* Postpone a call to listen() by the IP-task.
*/
void vSocketListenNextTime( FreeRTOS_Socket_t * pxSocket );
/*
* Lookup a TCP socket, using a multiple matching: both port numbers and
* return IP address.
*/
FreeRTOS_Socket_t * pxTCPSocketLookup( uint32_t ulLocalIP,
UBaseType_t uxLocalPort,
IPv46_Address_t xRemoteIP,
UBaseType_t uxRemotePort );
#endif /* ipconfigUSE_TCP */
/*
* Look up a local socket by finding a match with the local port.
*/
FreeRTOS_Socket_t * pxUDPSocketLookup( UBaseType_t uxLocalPort );
/*
* Calculate the upper-layer checksum
* Works both for UDP, ICMP and TCP packages
* bOut = true: checksum will be set in outgoing packets
* bOut = false: checksum will be calculated for incoming packets
* returning 0xffff means: checksum was correct
*/
uint16_t usGenerateProtocolChecksum( uint8_t * pucEthernetBuffer,
size_t uxBufferLength,
BaseType_t xOutgoingPacket );
/*
* An Ethernet frame has been updated (maybe it was an ARP request or a PING
* request?) and is to be sent back to its source.
*/
void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
BaseType_t xReleaseAfterSend );
/*
* The internal version of bind()
* If 'ulInternal' is true, it is called by the driver
* The TCP driver needs to bind a socket at the moment a listening socket
* creates a new connected socket
*/
BaseType_t vSocketBind( FreeRTOS_Socket_t * pxSocket,
struct freertos_sockaddr * pxBindAddress,
size_t uxAddressLength,
BaseType_t xInternal );
/*
* Internal function to add streaming data to a TCP socket. If ulIn == true,
* data will be added to the rxStream, otherwise to the tXStream. Normally data
* will be written with ulOffset == 0, meaning: at the end of the FIFO. When
* packet come in out-of-order, an offset will be used to put it in front and
* the head will not change yet.
*/
int32_t lTCPAddRxdata( FreeRTOS_Socket_t * pxSocket,
size_t uxOffset,
const uint8_t * pcData,
uint32_t ulByteCount );
/*
* Currently called for any important event.
*/
void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket );
/*
* Some helping function, their meaning should be clear.
* Going by MISRA rules, these utility functions should not be defined
* if they are not being used anywhere. But their use depends on the
* application and hence these functions are defined unconditionally.
*/
extern uint32_t ulChar2u32( const uint8_t * pucPtr );
extern uint16_t usChar2u16( const uint8_t * pucPtr );
/* Check a single socket for retransmissions and timeouts */
BaseType_t xTCPSocketCheck( FreeRTOS_Socket_t * pxSocket );
BaseType_t xTCPCheckNewClient( FreeRTOS_Socket_t * pxSocket );
/* Defined in FreeRTOS_Sockets.c
* Close a socket
*/
void * vSocketClose( FreeRTOS_Socket_t * pxSocket );
/*
* Send the event eEvent to the IP task event queue, using a block time of
* zero. Return pdPASS if the message was sent successfully, otherwise return
* pdFALSE.
*/
BaseType_t xSendEventToIPTask( eIPEvent_t eEvent );
/*
* The same as above, but a struct as a parameter, containing:
* eIPEvent_t eEventType;
* void *pvData;
*/
BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent,
TickType_t uxTimeout );
/*
* Returns a pointer to the original NetworkBuffer from a pointer to a UDP
* payload buffer.
*/
NetworkBufferDescriptor_t * pxUDPPayloadBuffer_to_NetworkBuffer( const void * pvBuffer );
/* Get the size of the IP-header.
* 'usFrameType' must be filled in if IPv6is to be recognised. */
size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer );
/*-----------------------------------------------------------*/
/* Get the size of the IP-header.
* The socket is checked for its type: IPv4 or IPv6. */
size_t uxIPHeaderSizeSocket( const FreeRTOS_Socket_t * pxSocket );
/*-----------------------------------------------------------*/
/*
* Internal: Sets a new state for a TCP socket and performs the necessary
* actions like calling a OnConnected handler to notify the socket owner.
*/
#if ( ipconfigUSE_TCP == 1 )
void vTCPStateChange( FreeRTOS_Socket_t * pxSocket,
enum eTCP_STATE eTCPState );
#endif /* ipconfigUSE_TCP */
/* Returns pdTRUE is this function is called from the IP-task */
BaseType_t xIsCallingFromIPTask( void );
#if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
/** @brief Structure for event groups of the Socket Select functions */
typedef struct xSOCKET_SET
{
/** @brief Event group for the socket select function.
*/
EventGroupHandle_t xSelectGroup;
} SocketSelect_t;
extern void vSocketSelect( const SocketSelect_t * pxSocketSet );
/** @brief Define the data that must be passed for a 'eSocketSelectEvent'. */
typedef struct xSocketSelectMessage
{
TaskHandle_t xTaskhandle; /**< Task handle for use in the socket select functionality. */
SocketSelect_t * pxSocketSet; /**< The event group for the socket select functionality. */
} SocketSelectMessage_t;
#endif /* ipconfigSUPPORT_SELECT_FUNCTION */
/* Send the network-up event and start the ARP/ND timers. */
void vIPNetworkUpCalls( struct xNetworkEndPoint * pxEndPoint );
/* Mark whether all interfaces are up or at least one interface is down. */
void vSetAllNetworksUp( BaseType_t xIsAllNetworksUp );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IP_PRIVATE_H */
@@ -0,0 +1,175 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/**
* @file FreeRTOS_IP_Timers.h
* @brief Header file for IP Timers on FreeRTOS+TCP network stack.
*/
#ifndef FREERTOS_IP_TIMERS_H
#define FREERTOS_IP_TIMERS_H
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <string.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_DHCP.h"
#include "NetworkInterface.h"
#include "NetworkBufferManagement.h"
#include "FreeRTOS_DNS.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/*
* Checks the ARP, ND, DHCP and TCP timers to see if any periodic or timeout
* processing is required.
*/
void vCheckNetworkTimers( void );
/*
* Determine how long the IP task can sleep for, which depends on when the next
* periodic or timeout processing must be performed.
*/
TickType_t xCalculateSleepTime( void );
/*
* Enable/disable the TCP timer.
*/
void vIPSetTCPTimerExpiredState( BaseType_t xExpiredState );
#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 )
/**
* Sets the reload time of an ARP timer and restarts it.
*/
void vARPTimerReload( TickType_t xTime );
/*
* Start an ARP Resolution timer.
*/
void vIPTimerStartARPResolution( TickType_t xTime );
/*
* Enable/disable the ARP timer.
*/
void vIPSetARPTimerEnableState( BaseType_t xEnableState );
/*
* Enable or disable the ARP resolution timer.
*/
void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState );
#endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */
#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 )
/**
* Sets the reload time of an ND timer and restarts it.
*/
void vNDTimerReload( TickType_t xTime );
/*
* Start an ND Resolution timer.
*/
void vIPTimerStartNDResolution( TickType_t xTime );
/*
* Enable/disable the ND timer.
*/
void vIPSetNDTimerEnableState( BaseType_t xEnableState );
/*
* Enable or disable the ARP resolution timer.
*/
void vIPSetNDResolutionTimerEnableState( BaseType_t xEnableState );
#endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) */
#if ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 )
/**
* @brief Enable/disable the DHCP/RA timer.
* @param[in] pxEndPoint: The end-point for which the timer will be called.
* @param[in] xEnableState: pdTRUE - enable timer; pdFALSE - disable timer.
*/
void vIPSetDHCP_RATimerEnableState( NetworkEndPoint_t * pxEndPoint,
BaseType_t xEnableState );
#endif /* ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 ) */
#if ( ipconfigDNS_USE_CALLBACKS != 0 )
/**
* @brief Enable/disable the DNS timer.
* @param[in] xEnableState: pdTRUE - enable timer; pdFALSE - disable timer.
*/
void vIPSetDNSTimerEnableState( BaseType_t xEnableState );
#endif /* ipconfigDNS_USE_CALLBACKS != 0 */
/**
* Sets the reload time of an TCP timer and restarts it.
*/
void vTCPTimerReload( TickType_t xTime );
#if ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 )
void vDHCP_RATimerReload( NetworkEndPoint_t * pxEndPoint,
TickType_t uxClockTicks );
#endif /* ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 ) */
#if ( ipconfigDNS_USE_CALLBACKS != 0 )
/**
* Reload the DNS timer.
*/
void vDNSTimerReload( uint32_t ulCheckTime );
#endif /* ipconfigDNS_USE_CALLBACKS != 0 */
/**
* Reload the Network timer.
*/
void vNetworkTimerReload( TickType_t xTime );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IP_TIMERS_H */
@@ -0,0 +1,123 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/**
* @file FreeRTOS_IP_Utils.h
* @brief Implements the utility functions for FreeRTOS_IP.c
*/
#ifndef FREERTOS_IP_UTILS_H
#define FREERTOS_IP_UTILS_H
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <string.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_DHCP.h"
#include "NetworkInterface.h"
#include "NetworkBufferManagement.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_IPv4_Utils.h"
#include "FreeRTOS_IPv6_Utils.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Forward declaration. */
struct xNetworkInterface;
struct xNetworkEndPoint;
#if ( ( ipconfigUSE_DHCPv6 == 1 ) || ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 ) )
/**
* @brief Create a DHCP event.
*
* @return pdPASS or pdFAIL, depending on whether xSendEventStructToIPTask()
* succeeded.
*/
BaseType_t xSendDHCPEvent( struct xNetworkEndPoint * pxEndPoint );
#endif
#if ( ( ipconfigUSE_DHCPv6 == 1 ) || ( ipconfigUSE_DHCP == 1 ) )
/* Returns the current state of a DHCP process. */
eDHCPState_t eGetDHCPState( const struct xNetworkEndPoint * pxEndPoint );
#endif
#if ( ipconfigZERO_COPY_TX_DRIVER != 0 ) || ( ipconfigZERO_COPY_RX_DRIVER != 0 )
/**
* @brief Get the network buffer from the packet buffer.
*
* @param[in] pvBuffer: Pointer to the packet buffer.
*
* @return The network buffer if the alignment is correct. Else a NULL is returned.
*/
NetworkBufferDescriptor_t * pxPacketBuffer_to_NetworkBuffer( const void * pvBuffer );
#endif
/**
* @brief Check the values of configuration options and assert on it. Also verify that the IP-task
* has not already been initialized.
*/
void vPreCheckConfigs( void );
/**
* @brief Called to create a network connection when the stack is first
* started, or when the network connection is lost.
*/
void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface );
/**
* @brief Release single UDP packet from a given socket
*/
void vReleaseSinglePacketFromUDPSocket( const ConstSocket_t xSocket );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IP_UTILS_H */
@@ -0,0 +1,107 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_IPV4_H
#define FREERTOS_IPV4_H
#include "FreeRTOS.h"
#include "task.h"
/* Application level configuration options. */
#include "FreeRTOSIPConfig.h"
#include "FreeRTOSIPConfigDefaults.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Forward declarations. */
struct xNETWORK_BUFFER;
struct xIP_PACKET;
#define ipSIZE_OF_IPv4_HEADER 20U
#define ipSIZE_OF_IPv4_ADDRESS 4U
#define ipSIZE_OF_ICMPv4_HEADER 8U
#define ipTYPE_IPv4 ( 0x40U )
#define ipFIRST_LOOPBACK_IPv4 0x7F000000UL /**< Lowest IPv4 loopback address (including). */
#define ipLAST_LOOPBACK_IPv4 0x80000000UL /**< Highest IPv4 loopback address (excluding). */
/* The first byte in the IPv4 header combines the IP version (4) with
* with the length of the IP header. */
#define ipIPV4_VERSION_HEADER_LENGTH_MIN 0x45U /**< Minimum IPv4 header length. */
#define ipIPV4_VERSION_HEADER_LENGTH_MAX 0x4FU /**< Maximum IPv4 header length. */
/* IPv4 multicast MAC address starts with 01-00-5E. */
#define ipMULTICAST_MAC_ADDRESS_IPv4_0 0x01U
#define ipMULTICAST_MAC_ADDRESS_IPv4_1 0x00U
#define ipMULTICAST_MAC_ADDRESS_IPv4_2 0x5EU
/*
* These functions come from the IPv4-only library.
* void FreeRTOS_SetIPAddress( uint32_t ulIPAddress );
* void FreeRTOS_SetNetmask( uint32_t ulNetmask );
* void FreeRTOS_SetGatewayAddress( uint32_t ulGatewayAddress );
* uint32_t FreeRTOS_GetGatewayAddress( void );
* uint32_t FreeRTOS_GetDNSServerAddress( void );
* uint32_t FreeRTOS_GetNetmask( void );
*/
void FreeRTOS_SetIPAddress( uint32_t ulIPAddress );
void FreeRTOS_SetNetmask( uint32_t ulNetmask );
void FreeRTOS_SetGatewayAddress( uint32_t ulGatewayAddress );
uint32_t FreeRTOS_GetGatewayAddress( void );
uint32_t FreeRTOS_GetDNSServerAddress( void );
uint32_t FreeRTOS_GetNetmask( void );
uint32_t FreeRTOS_GetIPAddress( void );
/* Return pdTRUE if the IPv4 address is a multicast address. */
BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress );
/* Return pdTRUE if the IPv4 address is a broadcast address. */
BaseType_t xIsIPv4Broadcast( uint32_t ulIPAddress,
struct xNetworkEndPoint ** ppxEndPoint );
/* Return pdTRUE if the IPv4 address is a loopback address. */
BaseType_t xIsIPv4Loopback( uint32_t ulAddress );
/*
* Return pdTRUE if either source or destination is a loopback address.
* A loopback IP-address may only communicate internally with another
* loopback IP-address.
*/
BaseType_t xBadIPv4Loopback( const IPHeader_t * const pxIPHeader );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IPV4_H */
@@ -0,0 +1,143 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
#ifndef FREERTOS_IPV4_PRIVATE_H
#define FREERTOS_IPV4_PRIVATE_H
#include "FreeRTOS_IP_Private.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* The maximum UDP payload length. */
#define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER )
#define TCP_PACKET_SIZE ( sizeof( TCPPacket_t ) )
/* The offset into an IP packet into which the IP data (payload) starts. */
#define ipIP_PAYLOAD_OFFSET ( sizeof( IPPacket_t ) )
/* The offset into a UDP packet at which the UDP data (payload) starts. */
#define ipUDP_PAYLOAD_OFFSET_IPv4 ( sizeof( UDPPacket_t ) )
/* The value of 'ipUDP_PAYLOAD_IP_TYPE_OFFSET' is 8 + 40 = 48 bytes. */
#define ipUDP_PAYLOAD_IP_TYPE_OFFSET ( sizeof( UDPHeader_t ) + sizeof( IPHeader_IPv6_t ) )
/* ipIP_TYPE_OFFSET is involved in some sorcery. pxUDPPayloadBuffer_to_NetworkBuffer() must be able to convert
* a payload pointer ( like for example a pointer to the DNS payload of a packet ) back to a NetworkBufferDescriptor_t.
* This must work for both IPv4 and IPv6 packets. The pointer conversion is done by subtracting a constant from the payload pointer.
* For IPv6, this magic number is ( sizeof( UDPHeader_t ) + sizeof( IPHeader_IPv6_t ) ) which equals 48 bytes.
* If however we use that same constant for an IPv4 packet, we end up somewhere in front of the Ethernet header.
* In order to accommodate that, the Ethernet frame buffer gets allocated a bit larger than needed.
* For IPv4 frames, prvProcessIPPacket() stores the version header field at a negative offset, a few bytes before the start
* of the Ethernet header. That IPv4 version field MUST be stored the same distance from the payload as in IPv6.
* ipIP_TYPE_OFFSET must be equal to: sizeof( UDPHeader_t ) + sizeof( IPHeader_IPv6_t ) - ( sizeof( UDPPacket_t )
* In most situations, ipIP_TYPE_OFFSET will end up being equal to 6. If the Ethernet header is enlarged to include VLAN
* tag support, ipIP_TYPE_OFFSET will shrink to 2. With the current design, the Ethernet header cannot be expanded to contain
* more than one VLAN tag or ipIP_TYPE_OFFSET will become less than zero. ipIP_TYPE_OFFSET should never be allowed to be <= 0
* or storing of the IPv4 version byte will overwrite the Ethernet header of the frame.
*/
#define ipIP_TYPE_OFFSET ( ( int32_t ) sizeof( UDPHeader_t ) + ( int32_t ) sizeof( IPHeader_IPv6_t ) - ( int32_t ) sizeof( UDPPacket_t ) )
#include "pack_struct_start.h"
struct xIP_HEADER
{
uint8_t ucVersionHeaderLength; /**< The version field + internet header length 0 + 1 = 1 */
uint8_t ucDifferentiatedServicesCode; /**< Differentiated services code point + ECN 1 + 1 = 2 */
uint16_t usLength; /**< Entire Packet size, ex. Ethernet header. 2 + 2 = 4 */
uint16_t usIdentification; /**< Identification field 4 + 2 = 6 */
uint16_t usFragmentOffset; /**< Fragment flags and fragment offset 6 + 2 = 8 */
uint8_t ucTimeToLive; /**< Time to live field 8 + 1 = 9 */
uint8_t ucProtocol; /**< Protocol used in the IP-datagram 9 + 1 = 10 */
uint16_t usHeaderChecksum; /**< Checksum of the IP-header 10 + 2 = 12 */
uint32_t ulSourceIPAddress; /**< IP address of the source 12 + 4 = 16 */
uint32_t ulDestinationIPAddress; /**< IP address of the destination 16 + 4 = 20 */
}
#include "pack_struct_end.h"
typedef struct xIP_HEADER IPHeader_t;
/*-----------------------------------------------------------*/
/* Nested protocol packets. */
/*-----------------------------------------------------------*/
#include "pack_struct_start.h"
struct xIP_PACKET
{
EthernetHeader_t xEthernetHeader;
IPHeader_t xIPHeader;
}
#include "pack_struct_end.h"
typedef struct xIP_PACKET IPPacket_t;
#include "pack_struct_start.h"
struct xICMP_PACKET
{
EthernetHeader_t xEthernetHeader; /**< The Ethernet header of an ICMP packet. */
IPHeader_t xIPHeader; /**< The IP header of an ICMP packet. */
ICMPHeader_t xICMPHeader; /**< The ICMP header of an ICMP packet. */
}
#include "pack_struct_end.h"
typedef struct xICMP_PACKET ICMPPacket_t;
#include "pack_struct_start.h"
struct xUDP_PACKET
{
EthernetHeader_t xEthernetHeader; /**< UDP-Packet ethernet header 0 + 14 = 14 */
IPHeader_t xIPHeader; /**< UDP-Packet IP header 14 + 20 = 34 */
UDPHeader_t xUDPHeader; /**< UDP-Packet UDP header 34 + 8 = 42 */
}
#include "pack_struct_end.h"
typedef struct xUDP_PACKET UDPPacket_t;
#include "pack_struct_start.h"
struct xTCP_PACKET
{
EthernetHeader_t xEthernetHeader; /**< The ethernet header 0 + 14 = 14 */
IPHeader_t xIPHeader; /**< The IP header 14 + 20 = 34 */
TCPHeader_t xTCPHeader; /**< The TCP header 34 + 32 = 66 */
}
#include "pack_struct_end.h"
typedef struct xTCP_PACKET TCPPacket_t;
/* The function 'prvAllowIPPacket()' checks if a packets should be processed. */
enum eFrameProcessingResult prvAllowIPPacketIPv4( const struct xIP_PACKET * const pxIPPacket,
const struct xNETWORK_BUFFER * const pxNetworkBuffer,
UBaseType_t uxHeaderLength );
/* Check if the IP-header is carrying options. */
enum eFrameProcessingResult prvCheckIP4HeaderOptions( struct xNETWORK_BUFFER * const pxNetworkBuffer );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IPV4_PRIVATE_H */
@@ -0,0 +1,59 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_IPV4_SOCKETS_H
#define FREERTOS_IPV4_SOCKETS_H
/* Standard includes. */
#include <string.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Called by prvSendUDPPacket(), this function will UDP packet
* fields and IPv4 address for the packet to be send.
*/
void * xSend_UDP_Update_IPv4( NetworkBufferDescriptor_t * pxNetworkBuffer,
const struct freertos_sockaddr * pxDestinationAddress );
/**
* @brief Called by FreeRTOS_recvfrom(), this function will update socket
* address with IPv4 address from the packet received.
*/
size_t xRecv_Update_IPv4( const NetworkBufferDescriptor_t * pxNetworkBuffer,
struct freertos_sockaddr * pxSourceAddress );
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* FREERTOS_IPV4_SOCKETS_H */
@@ -0,0 +1,67 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_IPV4_UTILS_H
#define FREERTOS_IPV4_UTILS_H
/**
* @file FreeRTOS_IPv4_Utils.h
* @brief Implements the utility functions for FreeRTOS_IP.c
*/
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Set the MAC-address that belongs to a given IPv4 multi-cast address. */
void vSetMultiCastIPv4MacAddress( uint32_t ulIPAddress,
MACAddress_t * pxMACAddress );
/* The first IPv4 length checks at the IP-header level. */
BaseType_t prvChecksumIPv4Checks( uint8_t * pucEthernetBuffer,
size_t uxBufferLength,
struct xPacketSummary * pxSet );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IPV4_UTILS_H */
@@ -0,0 +1,134 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_IPV6_H
#define FREERTOS_IPV6_H
#include "FreeRTOS.h"
#include "task.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Common.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Some constants defining the sizes of several parts of a packet.
* These defines come before including the configuration header files. */
#define ipSIZE_OF_IPv6_HEADER 40U
#define ipSIZE_OF_ICMPv6_HEADER 24U
#define ipSIZE_OF_IPv6_ADDRESS 16U
#define ipPROTOCOL_ICMP_IPv6 ( 58U )
#define ipTYPE_IPv6 ( 0x60U )
/* Some IPv6 ICMP requests. */
#define ipICMP_DEST_UNREACHABLE_IPv6 ( ( uint8_t ) 1U )
#define ipICMP_PACKET_TOO_BIG_IPv6 ( ( uint8_t ) 2U )
#define ipICMP_TIME_EXCEEDED_IPv6 ( ( uint8_t ) 3U )
#define ipICMP_PARAMETER_PROBLEM_IPv6 ( ( uint8_t ) 4U )
#define ipICMP_PING_REQUEST_IPv6 ( ( uint8_t ) 128U )
#define ipICMP_PING_REPLY_IPv6 ( ( uint8_t ) 129U )
#define ipICMP_ROUTER_SOLICITATION_IPv6 ( ( uint8_t ) 133U )
#define ipICMP_ROUTER_ADVERTISEMENT_IPv6 ( ( uint8_t ) 134U )
#define ipICMP_NEIGHBOR_SOLICITATION_IPv6 ( ( uint8_t ) 135U )
#define ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6 ( ( uint8_t ) 136U )
#define ipIPv6_EXT_HEADER_HOP_BY_HOP 0U
#define ipIPv6_EXT_HEADER_ROUTING_HEADER 43U
#define ipIPv6_EXT_HEADER_FRAGMENT_HEADER 44U
#define ipIPv6_EXT_HEADER_SECURE_PAYLOAD 50U
#define ipIPv6_EXT_HEADER_AUTHEN_HEADER 51U
#define ipIPv6_EXT_HEADER_DESTINATION_OPTIONS 60U
/* Destination options may follow here in case there are no routing options. */
#define ipIPv6_EXT_HEADER_MOBILITY_HEADER 135U
extern const struct xIPv6_Address FreeRTOS_in6addr_any;
extern const struct xIPv6_Address FreeRTOS_in6addr_loopback;
/* IPv6 multicast MAC address starts with 33-33-. */
#define ipMULTICAST_MAC_ADDRESS_IPv6_0 0x33U
#define ipMULTICAST_MAC_ADDRESS_IPv6_1 0x33U
/* A forward declaration of 'struct xNetworkEndPoint' and 'xNetworkInterface'.
* The actual declaration can be found in FreeRTOS_Routing.h which is included
* as the last +TCP header file. */
struct xNetworkEndPoint;
struct xNetworkInterface;
/* The function 'prvAllowIPPacket()' checks if a IPv6 packets should be processed. */
eFrameProcessingResult_t prvAllowIPPacketIPv6( const IPHeader_IPv6_t * const pxIPv6Header,
const NetworkBufferDescriptor_t * const pxNetworkBuffer,
UBaseType_t uxHeaderLength );
#if ( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 0 )
/*
* Return pdTRUE if either source or destination is a loopback address.
* A loopback IP-address may only communicate internally with another
* loopback IP-address.
*/
BaseType_t xBadIPv6Loopback( const IPHeader_IPv6_t * const pxIPv6Header );
#endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 0 */
/*
* Check if the address is a loopback IP-address.
*/
BaseType_t xIsIPv6Loopback( const IPv6_Address_t * pxAddress );
/** @brief Handle the IPv6 extension headers. */
eFrameProcessingResult_t eHandleIPv6ExtensionHeaders( NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xDoRemove );
/* Check whether this IPv6 address is an allowed multicast address or not. */
BaseType_t xIsIPv6AllowedMulticast( const IPv6_Address_t * pxIPAddress );
/* Note that 'xCompareIPv6_Address' will also check if 'pxRight' is
* the special unicast address: ff02::1:ffnn:nnnn, where nn:nnnn are
* the last 3 bytes of the IPv6 address. */
BaseType_t xCompareIPv6_Address( const IPv6_Address_t * pxLeft,
const IPv6_Address_t * pxRight,
size_t uxPrefixLength );
/* FreeRTOS_dnslookup6() returns pdTRUE when a host has been found. */
uint32_t FreeRTOS_dnslookup6( const char * pcHostName,
IPv6_Address_t * pxAddress_IPv6 );
/* Return IPv6 header extension order number */
BaseType_t xGetExtensionOrder( uint8_t ucProtocol,
uint8_t ucNextHeader );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IPV6_H */
@@ -0,0 +1,275 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
#ifndef FREERTOS_IPV6_PRIVATE_H
#define FREERTOS_IPV6_PRIVATE_H
/* Application level configuration options. */
#include "FreeRTOSIPConfig.h"
#include "FreeRTOSIPConfigDefaults.h"
#include "FreeRTOS_IP_Common.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_Stream_Buffer.h"
#if ( ipconfigUSE_TCP == 1 )
#include "FreeRTOS_TCP_WIN.h"
#include "FreeRTOS_TCP_IP.h"
#endif
#include "semphr.h"
#include "event_groups.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* MISRA Ref 20.5.1 [Use of undef] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2051 */
/* coverity[misra_c_2012_rule_20_5_violation] */
#undef TCP_PACKET_SIZE
#define TCP_PACKET_SIZE ( sizeof( TCPPacket_IPv6_t ) )
/* The offset into an IP packet into which the IP data (payload) starts. */
#define ipIPv6_PAYLOAD_OFFSET ( sizeof( IPPacket_IPv6_t ) )
/* The maximum UDP payload length. */
/* MISRA Ref 20.5.1 [Use of undef] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-2051 */
/* coverity[misra_c_2012_rule_20_5_violation] */
#undef ipMAX_UDP_PAYLOAD_LENGTH
#define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv6_HEADER ) - ipSIZE_OF_UDP_HEADER )
/* The offset into a UDP packet at which the UDP data (payload) starts. */
#define ipUDP_PAYLOAD_OFFSET_IPv6 ( sizeof( UDPPacket_IPv6_t ) )
#if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
#define ipIPv6_FRAME_TYPE ( 0xDD86U ) /* Ethernet frame types. */
#else /* if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) */
#define ipIPv6_FRAME_TYPE ( 0x86DDU ) /* Ethernet frame types. */
#endif /* ipconfigBYTE_ORDER */
/* In this library, there is often a cast from a character pointer
* to a pointer to a struct.
* In order to suppress MISRA warnings, do the cast within a macro,
* which can be exempt from warnings:
*
* 3 required by MISRA:
* -emacro(740,ipPOINTER_CAST) // 750: Unusual pointer cast (incompatible indirect types) [MISRA 2012 Rule 1.3, required])
* -emacro(9005,ipPOINTER_CAST) // 9005: attempt to cast away const/volatile from a pointer or reference [MISRA 2012 Rule 11.8, required]
* -emacro(9087,ipPOINTER_CAST) // 9087: cast performed between a pointer to object type and a pointer to a different object type [MISRA 2012 Rule 11.3, required]
*
* 2 advisory by MISRA:
* -emacro(9079,ipPOINTER_CAST) // 9079: conversion from pointer to void to pointer to other type [MISRA 2012 Rule 11.5, advisory])
* --emacro((826),ipPOINTER_CAST) // 826: Suspicious pointer-to-pointer conversion (area too small)
*
* The MISRA warnings can safely be suppressed because all casts are planned with care.
*/
#define ipPOINTER_CAST( TYPE, pointer ) ( ( TYPE ) ( pointer ) )
/* Sequence and ACK numbers are essentially unsigned (uint32_t). But when
* a distance is calculated, it is useful to use signed numbers:
* int32_t lDistance = ( int32_t ) ( ulSeq1 - ulSeq2 );
*
* 1 required by MISRA:
* -emacro(9033,ipNUMERIC_CAST) // 9033: Impermissible cast of composite expression (different essential type categories) [MISRA 2012 Rule 10.8, required])
*
* 1 advisory by MISRA:
* -emacro(9030,ipNUMERIC_CAST) // 9030: Impermissible cast; cannot cast from 'essentially Boolean' to 'essentially signed' [MISRA 2012 Rule 10.5, advisory])
*/
#define ipNUMERIC_CAST( TYPE, expression ) ( ( TYPE ) ( expression ) )
/** @brief The macros vSetField16() and vSetField32() will write either a short or a 32-bit
* value into an array of bytes. They will be stored big-endian.
* The helper functions do the actual work.
*/
/*extern void vSetField16helper( uint8_t * pucBase,
* size_t uxOffset,
* uint16_t usValue );
#define vSetField16( pucBase, xType, xField, usValue ) \
* vSetField16helper( pucBase, offsetof( xType, xField ), usValue )
*
* extern void vSetField32helper( uint8_t * pucBase,
* size_t uxOffset,
* uint32_t ulValue );
#define vSetField32( pucBase, xType, xField, ulValue ) \
* vSetField32helper( pucBase, offsetof( xType, xField ), ulValue )
*/
/* As FreeRTOS_Routing is included later, use forward declarations
* of the two structs. */
struct xNetworkEndPoint;
struct xNetworkInterface;
#define ipICMPv6_GENERAL_FIELD_SIZE ( 4U )
#include "pack_struct_start.h"
struct xIP_HEADER_IPv6
{
uint8_t ucVersionTrafficClass; /**< The version field. 0 + 1 = 1 */
uint8_t ucTrafficClassFlow; /**< Traffic class and flow. 1 + 1 = 2 */
uint16_t usFlowLabel; /**< Flow label. 2 + 2 = 4 */
uint16_t usPayloadLength; /**< Number of bytes after the IPv6 header. 4 + 2 = 6 */
uint8_t ucNextHeader; /**< Next header: TCP, UDP, or ICMP. 6 + 1 = 7 */
uint8_t ucHopLimit; /**< Replaces the time to live from IPv4. 7 + 1 = 8 */
IPv6_Address_t xSourceAddress; /**< The IPv6 address of the sender. 8 + 16 = 24 */
IPv6_Address_t xDestinationAddress; /**< The IPv6 address of the receiver. 24 + 16 = 40 */
}
#include "pack_struct_end.h"
typedef struct xIP_HEADER_IPv6 IPHeader_IPv6_t;
#include "pack_struct_start.h"
struct xIP_EXT_HEADER_IPv6
{
uint8_t ucNextHeader; /**< Next header: TCP, UDP, or ICMP. 0 + 1 = 1 */
uint8_t ucHeaderExtLength; /**< Length of this header in 8-octet units, not including the first 8 octets. 1 + 1 = 2 */
}
#include "pack_struct_end.h"
typedef struct xIP_EXT_HEADER_IPv6 IPExtHeader_IPv6_t;
#include "pack_struct_start.h"
struct xICMPEcho_IPv6
{
uint8_t ucTypeOfMessage; /**< The message type. 0 + 1 = 1 */
uint8_t ucTypeOfService; /**< Type of service. 1 + 1 = 2 */
uint16_t usChecksum; /**< Checksum. 2 + 2 = 4 */
uint16_t usIdentifier; /**< Identifier. 4 + 2 = 6 */
uint16_t usSequenceNumber; /**< Sequence number. 6 + 2 = 8 */
}
#include "pack_struct_end.h"
typedef struct xICMPEcho_IPv6 ICMPEcho_IPv6_t;
#include "pack_struct_start.h"
struct xICMPRouterSolicitation_IPv6
{
uint8_t ucTypeOfMessage; /**< 0 + 1 = 1 */
uint8_t ucTypeOfService; /**< 1 + 1 = 2 */
uint16_t usChecksum; /**< 2 + 2 = 4 */
uint32_t ulReserved; /**< 4 + 4 = 8 */
}
#include "pack_struct_end.h"
typedef struct xICMPRouterSolicitation_IPv6 ICMPRouterSolicitation_IPv6_t;
#include "pack_struct_start.h"
struct xICMPRouterAdvertisement_IPv6
{
uint8_t ucTypeOfMessage; /* 0 + 1 = 1 */
uint8_t ucTypeOfService; /* 1 + 1 = 2 */
uint16_t usChecksum; /* 2 + 2 = 4 */
uint8_t ucHopLimit; /* 4 + 1 = 5 */
uint8_t ucFlags; /* 5 + 1 = 6 */
uint16_t usLifetime; /* 6 + 2 = 8 */
uint16_t usReachableTime[ 2 ]; /* 8 + 4 = 12 */
uint16_t usRetransTime[ 2 ]; /* 12 + 4 = 16 */
}
#include "pack_struct_end.h"
typedef struct xICMPRouterAdvertisement_IPv6 ICMPRouterAdvertisement_IPv6_t;
#if ( ipconfigUSE_RA != 0 )
#include "pack_struct_start.h"
struct xICMPPrefixOption_IPv6
{
uint8_t ucType; /* 0 + 1 = 1 */
uint8_t ucLength; /* 1 + 1 = 2 */
uint8_t ucPrefixLength; /* 2 + 1 = 3 */
uint8_t ucFlags; /* 3 + 1 = 4 */
uint32_t ulValidLifeTime; /* 4 + 4 = 8 */
uint32_t ulPreferredLifeTime; /* 8 + 4 = 12 */
uint32_t ulReserved; /* 12 + 4 = 16 */
uint8_t ucPrefix[ 16 ]; /* 16 + 16 = 32 */
}
#include "pack_struct_end.h"
typedef struct xICMPPrefixOption_IPv6 ICMPPrefixOption_IPv6_t;
#endif /* ipconfigUSE_RA != 0 */
/*-----------------------------------------------------------*/
/* Nested protocol packets. */
/*-----------------------------------------------------------*/
#include "pack_struct_start.h"
struct xIP_PACKET_IPv6
{
EthernetHeader_t xEthernetHeader;
IPHeader_IPv6_t xIPHeader;
}
#include "pack_struct_end.h"
typedef struct xIP_PACKET_IPv6 IPPacket_IPv6_t;
#include "pack_struct_start.h"
struct xICMP_PACKET_IPv6
{
EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */
IPHeader_IPv6_t xIPHeader; /* 14 + 40 = 54 */
ICMPHeader_IPv6_t xICMPHeaderIPv6; /* 54 + 8 = 62 */
}
#include "pack_struct_end.h"
typedef struct xICMP_PACKET_IPv6 ICMPPacket_IPv6_t;
#include "pack_struct_start.h"
struct xUDP_PACKET_IPv6
{
EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */
IPHeader_IPv6_t xIPHeader; /* 14 + 40 = 54 */
UDPHeader_t xUDPHeader; /* 54 + 8 = 62 */
}
#include "pack_struct_end.h"
typedef struct xUDP_PACKET_IPv6 UDPPacket_IPv6_t;
#include "pack_struct_start.h"
struct xTCP_PACKET_IPv6
{
EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */
IPHeader_IPv6_t xIPHeader; /* 14 + 40 = 54 */
TCPHeader_t xTCPHeader; /* 54 + 32 = 86 */
}
#include "pack_struct_end.h"
typedef struct xTCP_PACKET_IPv6 TCPPacket_IPv6_t;
/* prvProcessICMPMessage_IPv6() is declared in FreeRTOS_routing.c
* It handles all ICMP messages except the PING requests. */
eFrameProcessingResult_t prvProcessICMPMessage_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer );
#if ( ( ipconfigHAS_DEBUG_PRINTF != 0 ) || ( ipconfigHAS_PRINTF != 0 ) )
/* prepare a string which describes a socket, just for logging. */
const char * prvSocketProps( FreeRTOS_Socket_t * pxSocket );
#endif /* ipconfigHAS_DEBUG_PRINTF || ipconfigHAS_PRINTF */
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IPV6_PRIVATE_H */
@@ -0,0 +1,118 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_IPV6_SOCKETS_H
#define FREERTOS_IPV6_SOCKETS_H
/* Standard includes. */
#include <string.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "FreeRTOS_IP_Common.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @brief When ucASCIIToHex() can not convert a character,
* the value 255 will be returned.
*/
#define socketINVALID_HEX_CHAR ( 0xffU )
/** @brief The struct sNTOP6_Set is a set of parameters used by the function FreeRTOS_inet_ntop6().
* It passes this set to a few helper functions. */
struct sNTOP6_Set
{
const uint16_t * pusAddress; /**< The network address, 8 short values. */
BaseType_t xZeroStart; /**< The position of the first byte of the longest train of zero values. */
BaseType_t xZeroLength; /**< The number of short values in the longest train of zero values. */
BaseType_t xIndex; /**< The read index in the array of short values, the network address. */
socklen_t uxTargetIndex; /**< The write index in 'pcDestination'. */
};
/** @brief The struct sNTOP6_Set is a set of parameters used by the function FreeRTOS_inet_ntop6().
* It passes this set to a few helper functions.
*/
struct sPTON6_Set
{
uint32_t ulValue; /**< A 32-bit accumulator, only 16 bits are used. */
BaseType_t xHadDigit; /**< Becomes pdTRUE as soon as ulValue has valid data. */
BaseType_t xTargetIndex; /**< The index in the array pucTarget to write the next byte. */
BaseType_t xColon; /**< The position in the output where the train of zero's will start. */
BaseType_t xHighestIndex; /**< The highest allowed value of xTargetIndex. */
uint8_t * pucTarget; /**< The array of bytes in which the resulting IPv6 address is written. */
};
/**
* @brief Convert an ASCII character to its corresponding hexadecimal value.
* Accepted characters are 0-9, a-f, and A-F.
*/
uint8_t ucASCIIToHex( char cChar );
/* @brief Converts a hex value to a readable hex character, e.g. 14 becomes 'e'.
*/
char cHexToChar( uint16_t usValue );
/** @brief Converts a hex value to a readable hex character, *
* e.g. 14 becomes 'e'.static char cHexToChar( unsigned short usValue );
*/
socklen_t uxHexPrintShort( char * pcBuffer,
size_t uxBufferSize,
uint16_t usValue );
/** @brief Scan the binary IPv6 address and find the longest train of consecutive zero's.
* The result of this search will be stored in 'xZeroStart' and 'xZeroLength'.
*/
void prv_ntop6_search_zeros( struct sNTOP6_Set * pxSet );
/** @brief Called by pxTCPSocketLookup(), this function will check if a socket
* is connected to a remote IP-address. It will be called from a loop
* iterating through all sockets. */
FreeRTOS_Socket_t * pxTCPSocketLookup_IPv6( FreeRTOS_Socket_t * pxSocket,
const IPv46_Address_t * pxAddress );
/**
* @brief Called by prvSendUDPPacket(), this function will UDP packet
* fields and IPv6 address for the packet to be send.
*/
void * xSend_UDP_Update_IPv6( NetworkBufferDescriptor_t * pxNetworkBuffer,
const struct freertos_sockaddr * pxDestinationAddress );
/**
* @brief Called by FreeRTOS_recvfrom(), this function will update socket
* address with IPv6 address from the packet received.
*/
size_t xRecv_Update_IPv6( const NetworkBufferDescriptor_t * pxNetworkBuffer,
struct freertos_sockaddr * pxSourceAddress );
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* FREERTOS_IPV6_SOCKETS_H */
@@ -0,0 +1,78 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_IPV6_UTILS_H
#define FREERTOS_IPV6_UTILS_H
/**
* @file FreeRTOS_IPv6_Utils.h
* @brief Implements the utility functions for FreeRTOS_IP.c
*/
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Set the MAC-address that belongs to a given IPv6 multi-cast address. */
void vSetMultiCastIPv6MacAddress( const IPv6_Address_t * pxAddress,
MACAddress_t * pxMACAddress );
extern BaseType_t prvChecksumIPv6Checks( uint8_t * pucEthernetBuffer,
size_t uxBufferLength,
struct xPacketSummary * pxSet );
extern BaseType_t prvChecksumICMPv6Checks( size_t uxBufferLength,
struct xPacketSummary * pxSet );
/* Get total length of all extension headers in IPv6 packet. */
size_t usGetExtensionHeaderLength( const uint8_t * pucEthernetBuffer,
size_t uxBufferLength,
uint8_t * pucProtocol );
void vManageSolicitedNodeAddress( const struct xNetworkEndPoint * pxEndPoint,
BaseType_t xNetworkGoingUp );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_IPV6_UTILS_H */
@@ -0,0 +1,224 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_ND_H
#define FREERTOS_ND_H
#include "FreeRTOS.h"
/* Application level configuration options. */
#include "FreeRTOSIPConfig.h"
#include "FreeRTOSIPConfigDefaults.h"
#include "FreeRTOS_Routing.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#if ( ipconfigUSE_IPv6 != 0 )
/*-----------------------------------------------------------*/
/* Miscellaneous structure and definitions. */
/*-----------------------------------------------------------*/
/**
* @brief 'NDCacheRow_t' defines one row in the ND address cache.
* @note About A value that is periodically decremented but can
* also be refreshed by active communication. The ND cache entry
* is removed if the value reaches zero.
*/
typedef struct xND_CACHE_TABLE_ROW
{
IPv6_Address_t xIPAddress; /**< The IP address of an ND cache entry. */
MACAddress_t xMACAddress; /**< The MAC address of an ND cache entry. */
struct xNetworkEndPoint * pxEndPoint; /**< The end-point on which the
* remote device had responded. */
uint8_t ucAge; /**< See here above. */
uint8_t ucValid; /**< pdTRUE: xMACAddress is valid, pdFALSE: waiting for ND reply */
} NDCacheRow_t;
/*
* If ulIPAddress is already in the ND cache table then reset the age of the
* entry back to its maximum value. If ulIPAddress is not already in the ND
* cache table then add it - replacing the oldest current entry if there is not
* a free space available.
*/
void vNDRefreshCacheEntry( const MACAddress_t * pxMACAddress,
const IPv6_Address_t * pxIPAddress,
NetworkEndPoint_t * pxEndPoint );
/** @brief Options that can be sent in a ROuter Advertisement packet. */
#define ndICMP_SOURCE_LINK_LAYER_ADDRESS 1
#define ndICMP_TARGET_LINK_LAYER_ADDRESS 2
#define ndICMP_PREFIX_INFORMATION 3
#define ndICMP_REDIRECTED_HEADER 4
#define ndICMP_MTU_OPTION 5
/*
* @brief Send a neighbour solicitation.
* @param[in] pxIPAddress: A network buffer big enough to hold the ICMP packet.
* @param[in,out] pxMACAddress: When found, the array of 6 bytes will be filled
* with the MAC-address.
* @param[in,out] ppxEndPoint: The pointer to a pointer will point to an
* end-point to which the device has responded.
*
* @note Look for ulIPAddress in the ND cache. If the IP address exists, copy the
* associated MAC address into pxMACAddress, refresh the ND cache entry's
* age, and return eResolutionCacheHit. If the IP address does not exist in the ND
* cache return eResolutionCacheMiss. If the packet cannot be sent for any reason
* (maybe DHCP is still in process, or the addressing needs a gateway but there
* isn't a gateway defined) then return eResolutionFailed.
*/
eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress,
MACAddress_t * const pxMACAddress,
struct xNetworkEndPoint ** ppxEndPoint );
/**
* @brief Reduce the age counter in each entry within the ND cache. An entry is no
* longer considered valid and is deleted if its age reaches zero.
* Just before getting to zero, 3 times a neighbour solicitation will be sent.
*/
void vNDAgeCache( void );
/**
* @brief Send a neighbour solicitation.
* @param[in] pxNetworkBuffer: A network buffer big enough to hold the ICMP packet.
* @param[in] pxIPAddress: The IPv6 address of the target device.
*
* @note Send out an ND request for the IPv6 address contained in pxNetworkBuffer, and
* add an entry into the ND table that indicates that an ND reply is
* outstanding so re-transmissions can be generated.
*/
void vNDSendNeighbourSolicitation( NetworkBufferDescriptor_t * pxNetworkBuffer,
const IPv6_Address_t * pxIPAddress );
#if ( ipconfigUSE_RA != 0 )
/**
* @brief Send a router solicitation.
* @param[in] pxNetworkBuffer: A network buffer big enough to hold the ICMP packet.
* @param[in] pxIPAddress: The multi-cast address of the routers ( normally ff02::2 ).
*/
void vNDSendRouterSolicitation( NetworkBufferDescriptor_t * pxNetworkBuffer,
IPv6_Address_t * pxIPAddress );
#endif /* ( ipconfigUSE_RA != 0 ) */
#if ( ipconfigUSE_RA != 0 )
/**
* @brief Work on the RA/SLAAC processing.
* @param[in] xDoReset: WHen true, the state-machine will be reset and initialised.
* @param[in] pxEndPoint: The end-point for which the RA/SLAAC process should be done..
*/
void vRAProcess( BaseType_t xDoReset,
NetworkEndPoint_t * pxEndPoint );
#endif /* ( ipconfigUSE_RA != 0 ) */
/**
* @brief Send an ND advertisement.
* @param[in] pxEndPoint: The end-point for which an ND advertisement should be sent.
*/
void FreeRTOS_OutputAdvertiseIPv6( NetworkEndPoint_t * pxEndPoint );
#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
/**
* @brief Send an IPv6 ping message to a remote device.
* @param[in] pxIPAddress: The IPv6 address of the other device.
* @param[in] uxNumberOfBytesToSend: The number of bytes to be echoed.
* @param[in] uxBlockTimeTicks: The number of clock-tick to wait
* for space in the IP-task queue.
* @return pdTRUE when a packets was successfully created
* and passed to the IP-task.
*/
BaseType_t FreeRTOS_SendPingRequestIPv6( const IPv6_Address_t * pxIPAddress,
size_t uxNumberOfBytesToSend,
TickType_t uxBlockTimeTicks );
#endif
/**
* @brief Create an IPv16 address, based on a prefix.
*
* @param[out] pxIPAddress: The location where the new IPv6 address
* will be stored.
* @param[in] pxPrefix: The prefix to be used.
* @param[in] uxPrefixLength: The length of the prefix.
* @param[in] xDoRandom: A non-zero value if the bits after the
* prefix should have a random value.
*
* @return pdPASS if the operation was successful. Or pdFAIL in
* case xApplicationGetRandomNumber()
* returned an error.
*/
BaseType_t FreeRTOS_CreateIPv6Address( IPv6_Address_t * pxIPAddress,
const IPv6_Address_t * pxPrefix,
size_t uxPrefixLength,
BaseType_t xDoRandom );
/* Receive a Neighbour Advertisement. */
#if ( ipconfigUSE_RA != 0 )
/** @brief A neighbour advertisement has been received. Store its
* address in the ND address cache.
* @param[in] pxNetworkBuffer The buffer containing the packet.
*/
void vReceiveNA( const NetworkBufferDescriptor_t * pxNetworkBuffer );
#endif
/* Receive a Router Advertisement. */
#if ( ipconfigUSE_RA != 0 )
/** @brief A router advertisement has been received. See if it is
* applicable for this device.
* @param[in] pxNetworkBuffer The buffer containing the packet.
*/
void vReceiveRA( const NetworkBufferDescriptor_t * pxNetworkBuffer );
#endif
#if ( ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) )
/** @brief Print the contents of the ND cache, for debugging only. */
void FreeRTOS_PrintNDCache( void );
#endif
BaseType_t xCheckRequiresNDResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer );
/* Clear all entries in the ND cache. */
void FreeRTOS_ClearND( const struct xNetworkEndPoint * pxEndPoint );
extern const uint8_t pcLOCAL_ALL_NODES_MULTICAST_IP[ ipSIZE_OF_IPv6_ADDRESS ];
extern const uint8_t pcLOCAL_ALL_NODES_MULTICAST_MAC[ ipMAC_ADDRESS_LENGTH_BYTES ];
#endif /* ipconfigUSE_IPv6 != 0 */
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_ND_H */
@@ -0,0 +1,387 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_ROUTING_H
#define FREERTOS_ROUTING_H
#include "FreeRTOS.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#if ( ipconfigUSE_DHCP != 0 )
#include "FreeRTOS_DHCP.h"
#endif
#if ( ipconfigUSE_IPv6 != 0 )
#include "FreeRTOS_DHCPv6.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Every NetworkInterface needs a set of access functions: */
/* Initialise the interface. */
typedef BaseType_t ( * NetworkInterfaceInitialiseFunction_t ) ( struct xNetworkInterface * pxDescriptor );
/* Send out an Ethernet packet. */
typedef BaseType_t ( * NetworkInterfaceOutputFunction_t ) ( struct xNetworkInterface * pxDescriptor,
NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xReleaseAfterSend );
/* Return true as long as the LinkStatus on the PHY is present. */
typedef BaseType_t ( * GetPhyLinkStatusFunction_t ) ( struct xNetworkInterface * pxDescriptor );
/* Functions that manipulate what MAC addresses are received by this interface */
typedef void ( * NetworkInterfaceMACFilterFunction_t ) ( struct xNetworkInterface * pxInterface,
const uint8_t * pucMacAddressBytes );
/** @brief These NetworkInterface access functions are collected in a struct: */
typedef struct xNetworkInterface
{
const char * pcName; /**< Just for logging, debugging. */
void * pvArgument; /**< Will be passed to the access functions. */
NetworkInterfaceInitialiseFunction_t pfInitialise; /**< This function will be called upon initialisation and repeated until it returns pdPASS. */
NetworkInterfaceOutputFunction_t pfOutput; /**< This function is supposed to send out a packet. */
GetPhyLinkStatusFunction_t pfGetPhyLinkStatus; /**< This function will return pdTRUE as long as the PHY Link Status is high. */
/*
* pfAddAllowedMAC and pfRemoveAllowedMAC form the network driver's address filtering API.
* The network stack uses these functions to alter which MAC addresses will be received.
* The MAC addresses passed to the functions can be unicast or multicast. It is important
* to note that the stack may call these functions multiple times for the the same MAC address.
* For example, if two sockets subscribe to the same multicast group, pfAddAllowedMAC()
* will be called twice with the same MAC address. The network driver is responsible for
* keeping track of these calls. The network driver should continue receiving that
* particular MAC address until pfRemoveAllowedMAC() is called the same number of times.
*
* Most EMAC hardware nowadays can filter frames based on both specific MAC address matching
* and hash matching. Specific address matching is ideal because as the name suggests,
* only frames with the exact MAC address are received. Usually however, the number of
* specific MAC addresses is limited ( to 4 in many cases ) and is sometimes not enough for
* all the MAC addresses that the network stack needs to receive.
* Hash matching is usually based around a 64-bit hash table. For every incoming frame,
* the EMAC calculates a hash value (mod 64) of the destination MAC address.
* The hash value is looked up in the 64-bit hash table and if that bit is set, the frame is
* received. If the bit is clear, the frame is dropped. With hash matching, multiple
* MAC addresses are represented by a single bit. It is the responsibility of the network
* driver to manage both the hash address matching and specific address matching capabilities
* of the EMAC hardware.
* A quick and dirty implementation option is to receive all MAC addresses and set both
* pfAddAllowedMAC and pfRemoveAllowedMAC to NULL. This results in an interface running
* in promiscuous mode and the entire burden of MAC filtering falls on the network stack.
* For a more realistic implementation, check out
* "portable/NetworkInterface/DriverSAM/NetworkInterface.c" It demonstrates the use of both
* specific and hash address matching as well as keeping count of how many time the
* individual registers/bits have been used. That implementation's init functions also
* demonstrates the use of prvAddAllowedMACAddress() function to register all end-point's
* MAC addresses whether the endpoints used the same or different MAC addresses.
*/
NetworkInterfaceMACFilterFunction_t pfAddAllowedMAC;
NetworkInterfaceMACFilterFunction_t pfRemoveAllowedMAC;
struct
{
uint32_t
bInterfaceUp : 1, /**< Non-zero as soon as the interface is up. */
bCallDownEvent : 1; /**< The down-event must be called. */
} bits; /**< A collection of boolean flags. */
struct xNetworkEndPoint * pxEndPoint; /**< A list of end-points bound to this interface. */
struct xNetworkInterface * pxNext; /**< The next interface in a linked list. */
} NetworkInterface_t;
/*
* // As an example:
* NetworkInterface_t xZynqDescriptor = {
* .pcName = "Zynq-GEM",
* .pvArgument = ( void * )1,
* .pfInitialise = xZynqGEMInitialise,
* .pfOutput = xZynqGEMOutput,
* .pfGetPhyLinkStatus = xZynqGEMGetPhyLinkStatus,
* };
*/
/** @brief The network settings for IPv4. */
typedef struct xIPV4Parameters
{
uint32_t ulIPAddress; /**< The actual IPv4 address. Will be 0 as long as end-point is still down. */
uint32_t ulNetMask; /**< The netmask. */
uint32_t ulGatewayAddress; /**< The IP-address of the gateway. */
uint32_t ulDNSServerAddresses[ ipconfigENDPOINT_DNS_ADDRESS_COUNT ]; /**< IP-addresses of DNS servers. */
uint32_t ulBroadcastAddress; /**< The local broadcast address, e.g. '192.168.1.255'. */
uint8_t ucDNSIndex; /**< The index of the next DNS address to be used. */
} IPV4Parameters_t;
#if ( ipconfigUSE_IPv6 != 0 )
typedef struct xIPV6Parameters
{
IPv6_Address_t xIPAddress; /* The actual IPv4 address. Will be 0 as long as end-point is still down. */
size_t uxPrefixLength; /* Number of valid bytes in the network prefix. */
IPv6_Address_t xPrefix; /* The network prefix, e.g. fe80::/10 */
IPv6_Address_t xGatewayAddress; /* Gateway to the web. */
IPv6_Address_t xDNSServerAddresses[ ipconfigENDPOINT_DNS_ADDRESS_COUNT ];
uint8_t ucDNSIndex; /**< The index of the next DNS address to be used. */
} IPV6Parameters_t;
#endif
#if ( ipconfigUSE_RA != 0 )
/* Router Advertisement (RA). End-points can obtain their IP-address by asking for a RA. */
typedef enum xRAState
{
eRAStateApply, /* Send a Router Solicitation. */
eRAStateWait, /* Wait for a Router Advertisement. */
eRAStateIPTest, /* Take a random IP address, test if another device is using it already. */
eRAStateIPWait, /* Wait for a reply, if any */
eRAStatePreLease, /* The device is ready to go to the 'eRAStateLease' state. */
eRAStateLease, /* The device is up, repeat the RA-process when timer expires. */
eRAStateFailed
} eRAState_t;
struct xRA_DATA
{
struct
{
uint32_t
bRouterReplied : 1,
bIPAddressInUse : 1;
}
bits;
TickType_t ulPreferredLifeTime;
UBaseType_t uxRetryCount;
/* Maintains the RA state machine state. */
eRAState_t eRAState;
};
typedef struct xRA_DATA RAData_t;
#endif /* ( ipconfigUSE_RA != 0 ) */
/** @brief The description of an end-point. */
typedef struct xNetworkEndPoint
{
#if ( ipconfigUSE_IPv4 != 0 )
IPV4Parameters_t ipv4_settings; /**< Actual IPv4 settings used by the end-point. */
IPV4Parameters_t ipv4_defaults; /**< Use values form "ipv4_defaults" in case DHCP has failed. */
#endif
#if ( ipconfigUSE_IPv6 != 0 )
IPV6Parameters_t ipv6_settings; /**< Actual IPv6 settings used by the end-point. */
IPV6Parameters_t ipv6_defaults; /**< Use values form "ipv6_defaults" in case DHCP has failed. */
#endif
MACAddress_t xMACAddress; /**< The MAC-address assigned to this end-point. */
struct
{
uint32_t
bIsDefault : 1, /**< This bit will be removed. */
#if ( ipconfigUSE_DHCP != 0 ) || ( ipconfigUSE_DHCPv6 != 0 )
bWantDHCP : 1, /**< This end-point wants to use DHCPv4 to obtain an IP-address. */
#endif /* ipconfigUSE_DHCP */
#if ( ipconfigUSE_RA != 0 )
bWantRA : 1, /**< This end-point wants to use RA/SLAAC to obtain an IP-address. */
#endif /* ipconfigUSE_RA */
bIPv6 : 1, /**< This end-point has an IP-address of type IPv6. */
#if ( ipconfigUSE_NETWORK_EVENT_HOOK != 0 )
bCallDownHook : 1, /**< The network down hook-must be called for this end-point. */
#endif /* ipconfigUSE_NETWORK_EVENT_HOOK */
bEndPointUp : 1; /**< The end-point is up. */
} bits; /**< A collection of boolean properties. */
uint8_t usDNSType; /**< A LLMNR/mDNS lookup is being done for an IPv6 address.
* This field is only valid while xApplicationDNSQueryHook() is called. */
#if ( ipconfigUSE_DHCP != 0 ) || ( ipconfigUSE_RA != 0 )
IPTimer_t xDHCP_RATimer; /**< The timer used to call the DHCP/DHCPv6/RA state machine. */
#endif /* ( ipconfigUSE_DHCP != 0 ) || ( ipconfigUSE_RA != 0 ) */
#if ( ipconfigUSE_DHCP != 0 ) || ( ipconfigUSE_DHCPv6 != 0 )
DHCPData_t xDHCPData; /**< A description of the DHCP client state machine. */
#endif /* ( ipconfigUSE_DHCP != 0 ) || ( ipconfigUSE_DHCPv6 != 0 ) */
#if ( ipconfigUSE_IPv6 != 0 )
DHCPMessage_IPv6_t * pxDHCPMessage; /**< A description of the DHCPv6 client state machine. */
#endif
#if ( ipconfigUSE_RA != 0 )
RAData_t xRAData; /**< A description of the Router Advertisement ( RA ) client state machine. */
#endif /* ( ipconfigUSE_RA != 0 ) */
NetworkInterface_t * pxNetworkInterface; /**< The network interface that owns this end-point. */
struct xNetworkEndPoint * pxNext; /**< The next end-point in the chain. */
} NetworkEndPoint_t;
#define END_POINT_USES_DHCP( pxEndPoint ) ( ( pxEndPoint )->bits.bWantDHCP != pdFALSE_UNSIGNED )
#define END_POINT_USES_RA( pxEndPoint ) ( ( ( pxEndPoint )->bits.bIPv6 != pdFALSE_UNSIGNED ) && ( ( pxEndPoint )->bits.bWantRA != pdFALSE_UNSIGNED ) )
#define ENDPOINT_IS_IPv4( pxEndPoint ) ( ( ( pxEndPoint ) != NULL ) && ( ( pxEndPoint )->bits.bIPv6 == 0U ) )
#define ENDPOINT_IS_IPv6( pxEndPoint ) ( ( ( pxEndPoint ) != NULL ) && ( ( pxEndPoint )->bits.bIPv6 != 0U ) )
/*
* Add a new physical Network Interface. The object pointed to by 'pxInterface'
* must continue to exist.
* Only the Network Interface function xx_FillInterfaceDescriptor() shall call this function.
*/
NetworkInterface_t * FreeRTOS_AddNetworkInterface( NetworkInterface_t * pxInterface );
/*
* Get the first Network Interface.
*/
NetworkInterface_t * FreeRTOS_FirstNetworkInterface( void );
/*
* Get the next Network Interface.
*/
NetworkInterface_t * FreeRTOS_NextNetworkInterface( const NetworkInterface_t * pxInterface );
/*
* Get the first end-point belonging to a given interface. When pxInterface is
* NULL, the very first end-point will be returned.
*/
NetworkEndPoint_t * FreeRTOS_FirstEndPoint( const NetworkInterface_t * pxInterface );
/*
* Get the next end-point. When pxInterface is null, all end-points can be
* iterated.
*/
NetworkEndPoint_t * FreeRTOS_NextEndPoint( const NetworkInterface_t * pxInterface,
NetworkEndPoint_t * pxEndPoint );
/*
* Find the end-point with given IP-address.
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress );
#if ( ipconfigUSE_IPv6 != 0 )
/* Find the end-point with given IP-address. */
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv6( const IPv6_Address_t * pxIPAddress );
#endif /* ipconfigUSE_IPv6 */
/*
* Find the end-point with given MAC-address.
* The search can be limited by supplying a particular interface.
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnMAC( const MACAddress_t * pxMACAddress,
const NetworkInterface_t * pxInterface );
/*
* Find the best fitting end-point to reach a given IP-address.
* Find an end-point whose IP-address is in the same network as the IP-address provided.
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress );
/*
* Find the best fitting IPv4 end-point to reach a given IP-address on a given interface
*/
NetworkEndPoint_t * FreeRTOS_InterfaceEndPointOnNetMask( const NetworkInterface_t * pxInterface,
uint32_t ulIPAddress );
/*
* Finds an endpoint on the given interface which is in the same subnet as the
* given IP address. If NULL is passed for pxInterface, it looks through all the
* interfaces to find an endpoint in the same subnet as the given IP address.
*/
NetworkEndPoint_t * FreeRTOS_InterfaceEPInSameSubnet_IPv6( const NetworkInterface_t * pxInterface,
const IPv6_Address_t * pxIPAddress );
#if ( ipconfigUSE_IPv6 != 0 )
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask_IPv6( const IPv6_Address_t * pxIPv6Address );
#endif /* ipconfigUSE_IPv6 */
#if ( ipconfigUSE_IPv6 != 0 )
/* Get the first end-point belonging to a given interface.
* When pxInterface is NULL, the very first end-point will be returned. */
NetworkEndPoint_t * FreeRTOS_FirstEndPoint_IPv6( const NetworkInterface_t * pxInterface );
#endif /* ipconfigUSE_IPv6 */
/* A ethernet packet has come in on a certain network interface.
* Find the best matching end-point. */
NetworkEndPoint_t * FreeRTOS_MatchingEndpoint( const NetworkInterface_t * pxNetworkInterface,
const uint8_t * pucEthernetBuffer );
/* Find an end-point that has a defined gateway.
* xIPType should equal ipTYPE_IPv4 or ipTYPE_IPv6. */
NetworkEndPoint_t * FreeRTOS_FindGateWay( BaseType_t xIPType );
/* Fill-in the end-point structure. */
void FreeRTOS_FillEndPoint( NetworkInterface_t * pxNetworkInterface,
NetworkEndPoint_t * pxEndPoint,
const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ],
const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ],
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] );
#if ( ipconfigUSE_IPv6 != 0 )
/* Fill-in the end-point structure. */
void FreeRTOS_FillEndPoint_IPv6( NetworkInterface_t * pxNetworkInterface,
NetworkEndPoint_t * pxEndPoint,
const IPv6_Address_t * pxIPAddress,
const IPv6_Address_t * pxNetPrefix,
size_t uxPrefixLength,
const IPv6_Address_t * pxGatewayAddress,
const IPv6_Address_t * pxDNSServerAddress, /* Not used yet. */
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] );
#endif
NetworkEndPoint_t * pxGetSocketEndpoint( ConstSocket_t xSocket );
void vSetSocketEndpoint( Socket_t xSocket,
NetworkEndPoint_t * pxEndPoint );
#if ( ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) )
const char * pcEndpointName( const NetworkEndPoint_t * pxEndPoint,
char * pcBuffer,
size_t uxSize );
#endif /* ( ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) ) */
typedef enum
{
eIPv6_Global, /* 001 */
eIPv6_LinkLocal, /* 1111 1110 10 */
eIPv6_SiteLocal, /* 1111 1110 11 */
eIPv6_Multicast, /* 1111 1111 */
eIPv6_Loopback, /* 1111 (::1) */
eIPv6_Unknown /* Not implemented. */
}
IPv6_Type_t;
#if ( ipconfigUSE_IPv6 != 0 )
/**
* @brief Check the type of an IPv16 address.
*
* @return A value from enum IPv6_Type_t.
*/
IPv6_Type_t xIPv6_GetIPType( const IPv6_Address_t * pxAddress );
#endif
BaseType_t xCheckRequiresResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer );
typedef enum
{
eResolutionCacheMiss = 0, /* 0 A cache lookup did not find a valid entry. */
eResolutionCacheHit, /* 1 A cache lookup found a valid entry. */
eResolutionFailed /* 2 There is no IP address, or a resolution is still in progress, so the packet cannot be sent. */
} eResolutionLookupResult_t;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* FREERTOS_ROUTING_H */
@@ -0,0 +1,597 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_SOCKETS_H
#define FREERTOS_SOCKETS_H
/* Standard includes. */
#include <string.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Application level configuration options. */
#include "FreeRTOSIPConfig.h"
#include "FreeRTOSIPConfigDefaults.h"
#ifndef FREERTOS_IP_CONFIG_H
#error FreeRTOSIPConfig.h has not been included yet
#endif
#include "FreeRTOS_IP_Common.h"
/* Event bit definitions are required by the select functions. */
#include "event_groups.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef INC_FREERTOS_H
#error FreeRTOS.h must be included before FreeRTOS_Sockets.h.
#endif
#ifndef INC_TASK_H
#ifndef TASK_H /* For compatibility with older FreeRTOS versions. */
#error The FreeRTOS header file task.h must be included before FreeRTOS_Sockets.h.
#endif
#endif
/* Assigned to an Socket_t variable when the socket is not valid, probably
* because it could not be created. */
#define FREERTOS_INVALID_SOCKET ( ( Socket_t ) ~0U )
/* API function error values. As errno is supported, the FreeRTOS sockets
* functions return error codes rather than just a pass or fail indication.
*
* Like in errno.h, the error codes are defined as positive numbers.
* However, in case of an error, API 's will still negative values, e.g.
* return -pdFREERTOS_ERRNO_EWOULDBLOCK;
* in case an operation would block.
*
* The following defines are obsolete, please use -pdFREERTOS_ERRNO_Exxx. */
#define FREERTOS_SOCKET_ERROR ( -1 )
#define FREERTOS_EWOULDBLOCK ( -pdFREERTOS_ERRNO_EWOULDBLOCK )
#define FREERTOS_EINVAL ( -pdFREERTOS_ERRNO_EINVAL )
#define FREERTOS_EADDRNOTAVAIL ( -pdFREERTOS_ERRNO_EADDRNOTAVAIL )
#define FREERTOS_EADDRINUSE ( -pdFREERTOS_ERRNO_EADDRINUSE )
#define FREERTOS_ENOBUFS ( -pdFREERTOS_ERRNO_ENOBUFS )
#define FREERTOS_ENOPROTOOPT ( -pdFREERTOS_ERRNO_ENOPROTOOPT )
#define FREERTOS_ECLOSED ( -pdFREERTOS_ERRNO_ENOTCONN )
/* Values for the parameters to FreeRTOS_socket(), inline with the Berkeley
* standard. See the documentation of FreeRTOS_socket() for more information. */
#define FREERTOS_AF_INET ( 2 )
#define FREERTOS_AF_INET6 ( 10 )
#define FREERTOS_SOCK_DGRAM ( 2 )
#define FREERTOS_IPPROTO_UDP ( 17 )
#define FREERTOS_SOCK_STREAM ( 1 )
#define FREERTOS_IPPROTO_TCP ( 6 )
#define FREERTOS_SOCK_DEPENDENT_PROTO ( 0 )
#define FREERTOS_AF_INET4 FREERTOS_AF_INET
/* Values for xFlags parameter of Receive/Send functions. */
#define FREERTOS_ZERO_COPY ( 1 ) /* Can be used with recvfrom(), sendto() and recv(),
* Indicates that the zero copy interface is being used.
* See the documentation for FreeRTOS_sockets() for more information. */
#define FREERTOS_MSG_OOB ( 2 ) /* Not used. */
#define FREERTOS_MSG_PEEK ( 4 ) /* Can be used with recvfrom() and recv(). */
#define FREERTOS_MSG_DONTROUTE ( 8 ) /* Not used. */
#define FREERTOS_MSG_DONTWAIT ( 16 ) /* Can be used with recvfrom(), sendto(), recv() and send(). */
/* Values that can be passed in the option name parameter of calls to
* FreeRTOS_setsockopt(). */
#define FREERTOS_SO_RCVTIMEO ( 0 ) /* Used to set the receive time out. */
#define FREERTOS_SO_SNDTIMEO ( 1 ) /* Used to set the send time out. */
#define FREERTOS_SO_UDPCKSUM_OUT ( 2 ) /* Used to turn the use of the UDP checksum
* by a socket on or off. This also doubles
* as part of an 8-bit bitwise socket option. */
#if ( ipconfigSOCKET_HAS_USER_SEMAPHORE == 1 )
#define FREERTOS_SO_SET_SEMAPHORE ( 3 ) /* Used to set a user's semaphore. */
#endif
#if ( ipconfigUSE_TCP == 1 )
#define FREERTOS_SO_SNDBUF ( 4 ) /* Set the size of the send buffer (TCP only). */
#define FREERTOS_SO_RCVBUF ( 5 ) /* Set the size of the receive buffer (TCP only). */
#endif
#if ( ipconfigUSE_CALLBACKS == 1 )
/* Supply pointer to 'F_TCP_UDP_Handler_t' for pvOptionValue parameter in
* FreeRTOS_setsockopt() */
#define FREERTOS_SO_TCP_CONN_HANDLER ( 6 ) /* Install a callback for (dis) connection events. */
#define FREERTOS_SO_TCP_RECV_HANDLER ( 7 ) /* Install a callback for receiving TCP data. */
#define FREERTOS_SO_TCP_SENT_HANDLER ( 8 ) /* Install a callback for sending TCP data. */
#define FREERTOS_SO_UDP_RECV_HANDLER ( 9 ) /* Install a callback for receiving UDP data. */
#define FREERTOS_SO_UDP_SENT_HANDLER ( 10 ) /* Install a callback for sending UDP data. */
#endif
#if ( ipconfigUSE_TCP == 1 )
#define FREERTOS_SO_REUSE_LISTEN_SOCKET ( 11 ) /* When a listening socket gets connected, do not create a new one but re-use it. */
#define FREERTOS_SO_CLOSE_AFTER_SEND ( 12 ) /* As soon as the last byte has been transmitted, finalise the connection. */
#define FREERTOS_SO_WIN_PROPERTIES ( 13 ) /* Set all buffer and window properties in one call, parameter is pointer to WinProperties_t. */
#define FREERTOS_SO_SET_FULL_SIZE ( 14 ) /* Refuse to send packets smaller than MSS. */
#define FREERTOS_SO_STOP_RX ( 15 ) /* Temporarily hold up reception, used by streaming client. */
#endif
#if ( ipconfigUDP_MAX_RX_PACKETS > 0 )
#define FREERTOS_SO_UDP_MAX_RX_PACKETS ( 16 ) /* This option helps to limit the maximum number of packets a UDP socket will buffer. */
#endif
#if ( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK == 1 )
#define FREERTOS_SO_WAKEUP_CALLBACK ( 17 )
#endif
#if ( ipconfigUSE_TCP == 1 )
#define FREERTOS_SO_SET_LOW_HIGH_WATER ( 18 )
#endif
#define FREERTOS_INADDR_ANY ( 0U ) /* The 0.0.0.0 IPv4 address. */
#define FREERTOS_INADDR_BROADCAST ( 0xffffffffUL ) /* 255.255.255.255 is a special broadcast address that represents all host attached to the physical network. */
#if ( 0 ) /* Not Used */
#define FREERTOS_NOT_LAST_IN_FRAGMENTED_PACKET ( 0x80 )
#define FREERTOS_FRAGMENTED_PACKET ( 0x40 )
#endif
#if ( ipconfigUSE_TCP == 1 )
/* Values for 'xHow' flag of FreeRTOS_shutdown(), currently ignored. */
#define FREERTOS_SHUT_RD ( 0 )
#define FREERTOS_SHUT_WR ( 1 )
#define FREERTOS_SHUT_RDWR ( 2 )
#endif
/* For compatibility with the expected Berkeley sockets naming. */
#define socklen_t uint32_t
/**
* For this limited implementation, only two members are required in the
* Berkeley style sockaddr structure.
*/
struct freertos_sockaddr
{
uint8_t sin_len; /**< length of this structure. */
uint8_t sin_family; /**< FREERTOS_AF_INET. */
uint16_t sin_port; /**< The port. */
uint32_t sin_flowinfo; /**< IPv6 flow information, not used in this library. */
IP_Address_t sin_address; /**< The IPv4/IPv6 address. */
};
#if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 )
#define sin_addr sin_address.ulIP_IPv4
#endif
/** Introduce a short name to make casting easier. */
typedef struct freertos_sockaddr xFreertosSocAddr;
/* The socket type itself. */
struct xSOCKET;
typedef struct xSOCKET * Socket_t;
typedef struct xSOCKET const * ConstSocket_t;
extern BaseType_t xSocketValid( const ConstSocket_t xSocket );
/**
* FULL, UP-TO-DATE AND MAINTAINED REFERENCE DOCUMENTATION FOR ALL THESE
* FUNCTIONS IS AVAILABLE ON THE FOLLOWING URL:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/01-FreeRTOS-plus-TCP-APIs
*/
/* Common Socket Attributes. */
/* Create a TCP or UDP socket. */
Socket_t FreeRTOS_socket( BaseType_t xDomain,
BaseType_t xType,
BaseType_t xProtocol );
/* Binds a socket to a local port number. */
BaseType_t FreeRTOS_bind( Socket_t xSocket,
struct freertos_sockaddr const * pxAddress,
socklen_t xAddressLength );
/* Sets a socket option. */
BaseType_t FreeRTOS_setsockopt( Socket_t xSocket,
int32_t lLevel,
int32_t lOptionName,
const void * pvOptionValue,
size_t uxOptionLength );
/* Close a socket. */
BaseType_t FreeRTOS_closesocket( Socket_t xSocket );
#if ( ipconfigSUPPORT_SIGNALS != 0 )
/* Send a signal to the task which is waiting for a given socket. */
BaseType_t FreeRTOS_SignalSocket( Socket_t xSocket );
/* Send a signal to the task which reads from this socket (FromISR version). */
BaseType_t FreeRTOS_SignalSocketFromISR( Socket_t xSocket,
BaseType_t * pxHigherPriorityTaskWoken );
#endif
/* This option adds the possibility to have a user-ID attached to a socket.
* The type of this ID is a void *. Both UDP and TCP sockets have
* this ID. It has a default value of NULL.
*/
BaseType_t xSocketSetSocketID( const Socket_t xSocket,
void * pvSocketID );
void * pvSocketGetSocketID( const ConstSocket_t xSocket );
/* Get the type of IP: either 'ipTYPE_IPv4' or 'ipTYPE_IPv6'. */
BaseType_t FreeRTOS_GetIPType( ConstSocket_t xSocket );
/* End Common Socket Attributes */
/* UDP Socket Attributes. */
/* Send data to a UDP socket. */
int32_t FreeRTOS_sendto( Socket_t xSocket,
const void * pvBuffer,
size_t uxTotalDataLength,
BaseType_t xFlags,
const struct freertos_sockaddr * pxDestinationAddress,
socklen_t xDestinationAddressLength );
/* Receive data from a UDP socket */
int32_t FreeRTOS_recvfrom( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength );
/* Function to get the local address and IP port. */
size_t FreeRTOS_GetLocalAddress( ConstSocket_t xSocket,
struct freertos_sockaddr * pxAddress );
#if ( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 1 )
/* Returns true if an UDP socket exists bound to mentioned port number. */
BaseType_t xPortHasUDPSocket( uint16_t usPortNr );
#endif
/* End UDP Socket Attributes */
#if ( ipconfigUSE_TCP == 1 )
/* TCP Socket Attributes. */
/**
* Structure to hold the properties of Tx/Rx buffers and windows.
*/
typedef struct xWIN_PROPS
{
/* Properties of the Tx buffer and Tx window. */
int32_t lTxBufSize; /**< Unit: bytes. */
int32_t lTxWinSize; /**< Unit: MSS. */
/* Properties of the Rx buffer and Rx window. */
int32_t lRxBufSize; /**< Unit: bytes. */
int32_t lRxWinSize; /**< Unit: MSS. */
} WinProperties_t;
/**
* Structure to pass for the 'FREERTOS_SO_SET_LOW_HIGH_WATER' option.
*/
typedef struct xLOW_HIGH_WATER
{
size_t uxLittleSpace; /**< Send a STOP when buffer space drops below X bytes */
size_t uxEnoughSpace; /**< Send a GO when buffer space grows above X bytes */
} LowHighWater_t;
/* Connect a TCP socket to a remote socket. */
BaseType_t FreeRTOS_connect( Socket_t xClientSocket,
const struct freertos_sockaddr * pxAddress,
socklen_t xAddressLength );
/* Places a TCP socket into a state where it is listening for and can accept
* incoming connection requests from remote sockets. */
BaseType_t FreeRTOS_listen( Socket_t xSocket,
BaseType_t xBacklog );
/* Accept a connection on a TCP socket. */
Socket_t FreeRTOS_accept( Socket_t xServerSocket,
struct freertos_sockaddr * pxAddress,
socklen_t * pxAddressLength );
/* Send data to a TCP socket. */
BaseType_t FreeRTOS_send( Socket_t xSocket,
const void * pvBuffer,
size_t uxDataLength,
BaseType_t xFlags );
/* Receive data from a TCP socket */
BaseType_t FreeRTOS_recv( Socket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags );
/* Disable reads and writes on a connected TCP socket. */
BaseType_t FreeRTOS_shutdown( Socket_t xSocket,
BaseType_t xHow );
/* Release a TCP payload buffer that was obtained by
* calling FreeRTOS_recv() with the FREERTOS_ZERO_COPY flag,
* and a pointer to a void pointer. */
BaseType_t FreeRTOS_ReleaseTCPPayloadBuffer( Socket_t xSocket,
void const * pvBuffer,
BaseType_t xByteCount );
/* Returns the number of bytes available in the Rx buffer. */
BaseType_t FreeRTOS_rx_size( ConstSocket_t xSocket );
#define FreeRTOS_recvcount( xSocket ) FreeRTOS_rx_size( xSocket )
/* Returns the free space in the Tx buffer. */
BaseType_t FreeRTOS_tx_space( ConstSocket_t xSocket );
#define FreeRTOS_outstanding( xSocket ) FreeRTOS_tx_size( xSocket )
/* Returns the number of bytes stored in the Tx buffer. */
BaseType_t FreeRTOS_tx_size( ConstSocket_t xSocket );
/* Returns pdTRUE if TCP socket is connected. */
BaseType_t FreeRTOS_issocketconnected( ConstSocket_t xSocket );
/* Return the remote address and IP port of a connected TCP Socket. */
BaseType_t FreeRTOS_GetRemoteAddress( ConstSocket_t xSocket,
struct freertos_sockaddr * pxAddress );
/* Returns the number of bytes that may be added to txStream. */
BaseType_t FreeRTOS_maywrite( ConstSocket_t xSocket );
/* Returns the actual size of MSS being used. */
BaseType_t FreeRTOS_mss( ConstSocket_t xSocket );
/* For internal use only: return the connection status. */
BaseType_t FreeRTOS_connstatus( ConstSocket_t xSocket );
/* For advanced applications only:
* Get a direct pointer to the beginning of the circular transmit buffer.
* In case the buffer was not yet created, it will be created in
* this call.
*/
uint8_t * FreeRTOS_get_tx_base( Socket_t xSocket );
/* For advanced applications only:
* Get a direct pointer to the circular transmit buffer.
* '*pxLength' will contain the number of bytes that may be written. */
uint8_t * FreeRTOS_get_tx_head( Socket_t xSocket,
BaseType_t * pxLength );
/* For the web server: borrow the circular Rx buffer for inspection
* HTML driver wants to see if a sequence of 13/10/13/10 is available. */
const struct xSTREAM_BUFFER * FreeRTOS_get_rx_buf( ConstSocket_t xSocket );
void FreeRTOS_netstat( void );
/* End TCP Socket Attributes. */
#endif /* ( ipconfigUSE_TCP == 1 ) */
#if ( ipconfigUSE_CALLBACKS == 1 )
/*
* Callback handlers for a socket
* User-provided functions will be called for each sockopt callback defined
* For example:
* static void xOnTCPConnect( Socket_t xSocket, BaseType_t ulConnected ) {}
* static BaseType_t xOnTCPReceive( Socket_t xSocket, void * pData, size_t uxLength )
* {
* // handle the message
* return pdFALSE; // Not Used
* }
* static void xOnTCPSent( Socket_t xSocket, size_t xLength ) {}
* static BaseType_t xOnUDPReceive( Socket_t xSocket, void * pData, size_t xLength, const struct freertos_sockaddr * pxFrom, const struct freertos_sockaddr * pxDest )
* {
* // handle the message
* return pdTRUE; // message processing is finished, don't store
* }
* static void xOnUDPSent( Socket_t xSocket, size_t xLength ) {}
* F_TCP_UDP_Handler_t xHand = { xOnTCPConnect, xOnTCPReceive, xOnTCPSent, xOnUDPReceive, xOnUDPSent };
* FreeRTOS_setsockopt( sock, 0, FREERTOS_SO_TCP_CONN_HANDLER, ( void * ) &xHand, 0 );
*/
/* Connected callback handler for a TCP Socket. */
typedef void (* FOnConnected_t )( Socket_t xSocket,
BaseType_t ulConnected );
/* Received callback handler for a TCP Socket.
* Return value is not currently used. */
typedef BaseType_t (* FOnTCPReceive_t )( Socket_t xSocket,
void * pData,
size_t xLength );
/* Sent callback handler for a TCP Socket. */
typedef void (* FOnTCPSent_t )( Socket_t xSocket,
size_t xLength );
/* Received callback handler for a UDP Socket.
* If a positive number is returned, the messages will not be stored in
* xWaitingPacketsList for later processing by recvfrom(). */
typedef BaseType_t (* FOnUDPReceive_t ) ( Socket_t xSocket,
void * pData,
size_t xLength,
const struct freertos_sockaddr * pxFrom,
const struct freertos_sockaddr * pxDest );
/* Sent callback handler for a UDP Socket */
typedef void (* FOnUDPSent_t )( Socket_t xSocket,
size_t xLength );
/* The following values are used in the lOptionName parameter of setsockopt()
* to set the callback handlers options. */
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;
#endif /* ( ipconfigUSE_CALLBACKS == 1 ) */
/* Conversion Functions */
/* Converts an IP address expressed as a 32-bit number in network byte order
* to a string in decimal dot notation. */
extern const char * FreeRTOS_inet_ntoa( uint32_t ulIPAddress,
char * pcBuffer );
#if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
/* Converts an IP address expressed as four separate numeric octets into an
* IP address expressed as a 32-bit number in network byte order */
#define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \
( ( ( ( uint32_t ) ( ucOctet3 ) ) << 24 ) | \
( ( ( uint32_t ) ( ucOctet2 ) ) << 16 ) | \
( ( ( uint32_t ) ( ucOctet1 ) ) << 8 ) | \
( ( uint32_t ) ( ucOctet0 ) ) )
#else /* ( ipconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN ) */
#define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \
( ( ( ( uint32_t ) ( ucOctet0 ) ) << 24 ) | \
( ( ( uint32_t ) ( ucOctet1 ) ) << 16 ) | \
( ( ( uint32_t ) ( ucOctet2 ) ) << 8 ) | \
( ( uint32_t ) ( ucOctet3 ) ) )
#endif /* ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) */
/* Convert a null-terminated string in dot-decimal-notation (d.d.d.d)
* to a 32-bit unsigned integer. */
uint32_t FreeRTOS_inet_addr( const char * pcIPAddress );
BaseType_t FreeRTOS_inet_pton( BaseType_t xAddressFamily,
const char * pcSource,
void * pvDestination );
const char * FreeRTOS_inet_ntop( BaseType_t xAddressFamily,
const void * pvSource,
char * pcDestination,
socklen_t uxSize );
/** @brief This function converts a human readable string, representing an 48-bit MAC address,
* into a 6-byte address. Valid inputs are e.g. "62:48:5:83:A0:b2" and "0-12-34-fe-dc-ba". */
BaseType_t FreeRTOS_EUI48_pton( const char * pcSource,
uint8_t * pucTarget );
/** @brief This function converts a 48-bit MAC address to a human readable string. */
void FreeRTOS_EUI48_ntop( const uint8_t * pucSource,
char * pcTarget,
char cTen,
char cSeparator );
/* End Conversion Functions */
#if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
/* The SocketSet_t type is the equivalent to the fd_set type used by the
* Berkeley API. */
struct xSOCKET_SET;
typedef struct xSOCKET_SET * SocketSet_t;
typedef struct xSOCKET_SET const * ConstSocketSet_t;
/* Create a socket set for use with the FreeRTOS_select() function */
SocketSet_t FreeRTOS_CreateSocketSet( void );
void FreeRTOS_DeleteSocketSet( SocketSet_t xSocketSet );
/* Block on a "socket set" until an event of interest occurs on a
* socket within the set. */
BaseType_t FreeRTOS_select( SocketSet_t xSocketSet,
TickType_t xBlockTimeTicks );
/* For FD_SET and FD_CLR, a combination of the following bits can be used: */
typedef enum eSELECT_EVENT
{
eSELECT_READ = 0x0001,
eSELECT_WRITE = 0x0002,
eSELECT_EXCEPT = 0x0004,
eSELECT_INTR = 0x0008,
eSELECT_ALL = 0x000F,
/* Reserved for internal use: */
eSELECT_CALL_IP = 0x0010
/* end */
} eSelectEvent_t;
/* Add a socket to a socket set, and set the event bits of interest
* for the added socket. */
void FreeRTOS_FD_SET( Socket_t xSocket,
SocketSet_t xSocketSet,
EventBits_t xBitsToSet );
/* Clear a set event bit of interest for a socket of the socket set.
* If all the event bits are clear then the socket will be removed
* from the socket set. */
void FreeRTOS_FD_CLR( Socket_t xSocket,
SocketSet_t xSocketSet,
EventBits_t xBitsToClear );
/* Check if a socket in a socket set has an event bit set. */
EventBits_t FreeRTOS_FD_ISSET( const ConstSocket_t xSocket,
const ConstSocketSet_t xSocketSet );
#endif /* ( ipconfigSUPPORT_SELECT_FUNCTION == 1 ) */
#if ipconfigUSE_IPv4
/* Translate from dot-decimal notation (example 192.168.1.1) to a 32-bit number. */
BaseType_t FreeRTOS_inet_pton4( const char * pcSource,
void * pvDestination );
/* Translate 32-bit IPv4 address representation dot-decimal notation. */
const char * FreeRTOS_inet_ntop4( const void * pvSource,
char * pcDestination,
socklen_t uxSize );
#endif
#if ipconfigUSE_IPv6
/* Translate hexadecimal IPv6 address to 16 bytes binary format */
BaseType_t FreeRTOS_inet_pton6( const char * pcSource,
void * pvDestination );
/*
* Convert a string like 'fe80::8d11:cd9b:8b66:4a80'
* to a 16-byte IPv6 address
*/
const char * FreeRTOS_inet_ntop6( const void * pvSource,
char * pcDestination,
socklen_t uxSize );
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* FREERTOS_SOCKETS_H */
@@ -0,0 +1,101 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*
* FreeRTOS_Stream_Buffer.h
*
* An implementation of a circular character buffer without a length field
* If LENGTH defines the size of the buffer, a maximum of (LENGTH-1) bytes can be stored
* In order to add or read data from the buffer, memcpy() will be called at most 2 times
*/
#ifndef FREERTOS_STREAM_BUFFER_H
#define FREERTOS_STREAM_BUFFER_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Struct to store all the details of a stream buffer. */
typedef struct xSTREAM_BUFFER
{
volatile size_t uxTail; /**< next item to read */
volatile size_t uxMid; /**< iterator within the valid items */
volatile size_t uxHead; /**< next position store a new item */
volatile size_t uxFront; /**< iterator within the free space */
size_t LENGTH; /**< const value: number of reserved elements */
uint8_t ucArray[ sizeof( size_t ) ]; /**< array big enough to store any pointer address */
} StreamBuffer_t;
size_t uxStreamBufferSpace( const StreamBuffer_t * const pxBuffer,
size_t uxLower,
size_t uxUpper );
size_t uxStreamBufferDistance( const StreamBuffer_t * const pxBuffer,
size_t uxLower,
size_t uxUpper );
size_t uxStreamBufferGetSpace( const StreamBuffer_t * const pxBuffer );
size_t uxStreamBufferFrontSpace( const StreamBuffer_t * const pxBuffer );
size_t uxStreamBufferGetSize( const StreamBuffer_t * const pxBuffer );
size_t uxStreamBufferMidSpace( const StreamBuffer_t * const pxBuffer );
void vStreamBufferClear( StreamBuffer_t * const pxBuffer );
void vStreamBufferMoveMid( StreamBuffer_t * const pxBuffer,
const size_t uxCount );
BaseType_t xStreamBufferLessThenEqual( const StreamBuffer_t * const pxBuffer,
size_t uxLeft,
size_t uxRight );
size_t uxStreamBufferGetPtr( StreamBuffer_t * const pxBuffer,
uint8_t ** const ppucData );
size_t uxStreamBufferAdd( StreamBuffer_t * const pxBuffer,
size_t uxOffset,
const uint8_t * const pucData,
size_t uxByteCount );
size_t uxStreamBufferGet( StreamBuffer_t * const pxBuffer,
size_t uxOffset,
uint8_t * const pucData,
size_t uxMaxCount,
BaseType_t xPeek );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_STREAM_BUFFER_H */
@@ -0,0 +1,200 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_TCP_IP_H
#define FREERTOS_TCP_IP_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/**
* @brief Process the received TCP packet.
*
*/
BaseType_t xProcessReceivedTCPPacket( NetworkBufferDescriptor_t * pxDescriptor );
/**
* @brief Process the received TCP packet.
*/
BaseType_t xProcessReceivedTCPPacket_IPV4( NetworkBufferDescriptor_t * pxDescriptor );
/**
* @brief Process the received TCP packet.
*/
BaseType_t xProcessReceivedTCPPacket_IPV6( NetworkBufferDescriptor_t * pxDescriptor );
typedef enum eTCP_STATE
{
/* Comments about the TCP states are borrowed from the very useful
* Wiki page:
* http://en.wikipedia.org/wiki/Transmission_Control_Protocol */
eCLOSED = 0U, /* 0 (server + client) no connection state at all. */
eTCP_LISTEN, /* 1 (server) waiting for a connection request
* from any remote TCP and port. */
eCONNECT_SYN, /* 2 (client) internal state: socket wants to send
* a connect */
eSYN_FIRST, /* 3 (server) Just created, must ACK the SYN request. */
eSYN_RECEIVED, /* 4 (server) waiting for a confirming connection request
* acknowledgement after having both received and sent a connection request. */
eESTABLISHED, /* 5 (server + client) an open connection, data received can be
* delivered to the user. The normal state for the data transfer phase of the connection. */
eFIN_WAIT_1, /* 6 (server + client) waiting for a connection termination request from the remote TCP,
* or an acknowledgement of the connection termination request previously sent. */
eFIN_WAIT_2, /* 7 (server + client) waiting for a connection termination request from the remote TCP. */
eCLOSE_WAIT, /* 8 (server + client) waiting for a connection termination request from the local user. */
eCLOSING, /* 9 (server + client) waiting for a connection termination request acknowledgement from the remote TCP. */
eLAST_ACK, /*10 (server + client) waiting for an acknowledgement of the connection termination request
* previously sent to the remote TCP
* (which includes an acknowledgement of its connection termination request). */
eTIME_WAIT /*11 (either server or client) waiting for enough time to pass to be sure the remote TCP received the
* acknowledgement of its connection termination request. [According to RFC 793 a connection can
* stay in TIME-WAIT for a maximum of four minutes known as a MSL (maximum segment lifetime).] */
} eIPTCPState_t;
/*
* The meaning of the TCP flags:
*/
#define tcpTCP_FLAG_FIN ( ( uint8_t ) 0x01U ) /**< No more data from sender. */
#define tcpTCP_FLAG_SYN ( ( uint8_t ) 0x02U ) /**< Synchronize sequence numbers. */
#define tcpTCP_FLAG_RST ( ( uint8_t ) 0x04U ) /**< Reset the connection. */
#define tcpTCP_FLAG_PSH ( ( uint8_t ) 0x08U ) /**< Push function: please push buffered data to the recv application. */
#define tcpTCP_FLAG_ACK ( ( uint8_t ) 0x10U ) /**< Acknowledgment field is significant. */
#define tcpTCP_FLAG_URG ( ( uint8_t ) 0x20U ) /**< Urgent pointer field is significant. */
#define tcpTCP_FLAG_ECN ( ( uint8_t ) 0x40U ) /**< ECN-Echo. */
#define tcpTCP_FLAG_CWR ( ( uint8_t ) 0x80U ) /**< Congestion Window Reduced. */
#define tcpTCP_FLAG_CTRL ( ( uint8_t ) 0x1FU ) /**< A mask to filter all protocol flags. */
/*
* A few values of the TCP options:
*/
#define tcpTCP_OPT_END 0U /**< End of TCP options list. */
#define tcpTCP_OPT_NOOP 1U /**< "No-operation" TCP option. */
#define tcpTCP_OPT_MSS 2U /**< Maximum segment size TCP option. */
#define tcpTCP_OPT_WSOPT 3U /**< TCP Window Scale Option (3-byte long). */
#define tcpTCP_OPT_SACK_P 4U /**< Advertise that SACK is permitted. */
#define tcpTCP_OPT_SACK_A 5U /**< SACK option with first/last. */
#define tcpTCP_OPT_TIMESTAMP 8U /**< Time-stamp option. */
#define tcpTCP_OPT_MSS_LEN 4U /**< Length of TCP MSS option. */
#define tcpTCP_OPT_WSOPT_LEN 3U /**< Length of TCP WSOPT option. */
#define tcpTCP_OPT_WSOPT_MAXIMUM_VALUE ( 14U ) /**< Maximum value of TCP WSOPT option. */
#define tcpTCP_OPT_TIMESTAMP_LEN 10 /**< fixed length of the time-stamp option. */
/** @brief
* Minimum segment length as outlined by RFC 791 section 3.1.
* Minimum segment length ( 536 ) = Minimum MTU ( 576 ) - IP Header ( 20 ) - TCP Header ( 20 ).
*/
#define tcpMINIMUM_SEGMENT_LENGTH 536U
/** @brief
* The macro tcpNOW_CONNECTED() is use to determine if the connection makes a
* transition from connected to non-connected and vice versa.
* tcpNOW_CONNECTED() returns true when the status has one of these values:
* eESTABLISHED, eFIN_WAIT_1, eFIN_WAIT_2, eCLOSING, eLAST_ACK, eTIME_WAIT
* Technically the connection status is closed earlier, but the library wants
* to prevent that the socket will be deleted before the last ACK has been
* and thus causing a 'RST' packet on either side.
*/
#define tcpNOW_CONNECTED( status ) \
( ( ( ( status ) >= ( BaseType_t ) eESTABLISHED ) && ( ( status ) != ( BaseType_t ) eCLOSE_WAIT ) ) ? 1 : 0 )
/** @brief
* The highest 4 bits in the TCP offset byte indicate the total length of the
* TCP header, divided by 4.
*/
#define tcpVALID_BITS_IN_TCP_OFFSET_BYTE ( 0xF0U )
/*
* Acknowledgements to TCP data packets may be delayed as long as more is being expected.
* A normal delay would be 200ms. Here a much shorter delay of 20 ms is being used to
* gain performance.
*/
#define tcpDELAYED_ACK_SHORT_DELAY_MS ( 2 ) /**< Should not become smaller than 1. */
#define tcpDELAYED_ACK_LONGER_DELAY_MS ( 20 ) /**< Longer delay for ACK. */
/** @brief
* The MSS (Maximum Segment Size) will be taken as large as possible. However, packets with
* an MSS of 1460 bytes won't be transported through the internet. The MSS will be reduced
* to 1400 bytes.
*/
#define tcpREDUCED_MSS_THROUGH_INTERNET ( 1400 )
/** @brief
* When there are no TCP options, the TCP offset equals 20 bytes, which is stored as
* the number 5 (words) in the higher nibble of the TCP-offset byte.
*/
#define tcpTCP_OFFSET_LENGTH_BITS ( 0xf0U )
#define tcpTCP_OFFSET_STANDARD_LENGTH ( 0x50U ) /**< Standard TCP packet offset. */
/** @brief
* Each TCP socket is checked regularly to see if it can send data packets.
* By default, the maximum number of packets sent during one check is limited to 8.
* This amount may be further limited by setting the socket's TX window size.
*/
#if ( !defined( SEND_REPEATED_COUNT ) )
#define SEND_REPEATED_COUNT ( 8 )
#endif /* !defined( SEND_REPEATED_COUNT ) */
/** @brief
* Define a maximum period of time (ms) to leave a TCP-socket unattended.
* When a TCP timer expires, retries and keep-alive messages will be checked.
*/
#ifndef tcpMAXIMUM_TCP_WAKEUP_TIME_MS
#define tcpMAXIMUM_TCP_WAKEUP_TIME_MS 20000U
#endif
struct xSOCKET;
/*
* For anti-hang protection and TCP keep-alive messages. Called in two places:
* after receiving a packet and after a state change. The socket's alive timer
* may be reset.
*/
void prvTCPTouchSocket( struct xSOCKET * pxSocket );
/*
* Calculate when this socket needs to be checked to do (re-)transmissions.
*/
TickType_t prvTCPNextTimeout( struct xSOCKET * pxSocket );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_TCP_IP_H */
@@ -0,0 +1,66 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_TCP_RECEPTION_H
#define FREERTOS_TCP_RECEPTION_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/*
* Called from xProcessReceivedTCPPacket. Parse the TCP option(s) received,
* if present. This function returns pdFALSE if the options are not well formed.
*/
BaseType_t prvCheckOptions( FreeRTOS_Socket_t * pxSocket,
const NetworkBufferDescriptor_t * pxNetworkBuffer );
/*
* Called from prvTCPHandleState(). Find the TCP payload data and check and
* return its length.
*/
BaseType_t prvCheckRxData( const NetworkBufferDescriptor_t * pxNetworkBuffer,
uint8_t ** ppucRecvData );
/*
* Called from prvTCPHandleState(). Check if the payload data may be accepted.
* If so, it will be added to the socket's reception queue.
*/
BaseType_t prvStoreRxData( FreeRTOS_Socket_t * pxSocket,
const uint8_t * pucRecvData,
NetworkBufferDescriptor_t * pxNetworkBuffer,
uint32_t ulReceiveLength );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_TCP_RECEPTION_H */
@@ -0,0 +1,117 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_TCP_STATE_HANDLING_H
#define FREERTOS_TCP_STATE_HANDLING_H
#include "FreeRTOS_TCP_IP.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/*
* Returns true if the socket must be checked. Non-active sockets are waiting
* for user action, either connect() or close().
*/
BaseType_t prvTCPSocketIsActive( eIPTCPState_t eStatus );
/*
* prvTCPStatusAgeCheck() will see if the socket has been in a non-connected
* state for too long. If so, the socket will be closed, and -1 will be
* returned.
*/
#if ( ipconfigTCP_HANG_PROTECTION == 1 )
BaseType_t prvTCPStatusAgeCheck( FreeRTOS_Socket_t * pxSocket );
#endif
/*
* The heart of all: check incoming packet for valid data and acks and do what
* is necessary in each state.
*/
BaseType_t prvTCPHandleState( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t ** ppxNetworkBuffer );
/*
* Return either a newly created socket, or the current socket in a connected
* state (depends on the 'bReuseSocket' flag).
*/
FreeRTOS_Socket_t * prvHandleListen( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxNetworkBuffer );
/*
* Return either a newly created socket, or the current socket in a connected
* state (depends on the 'bReuseSocket' flag).
*/
FreeRTOS_Socket_t * prvHandleListen_IPV4( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxNetworkBuffer );
/*
* Return either a newly created socket, or the current socket in a connected
* state (depends on the 'bReuseSocket' flag).
*/
FreeRTOS_Socket_t * prvHandleListen_IPV6( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxNetworkBuffer );
/*
* Common code for sending a TCP protocol control packet (i.e. no options, no
* payload, just flags).
*/
BaseType_t prvTCPSendSpecialPacketHelper( NetworkBufferDescriptor_t * pxNetworkBuffer,
uint8_t ucTCPFlags );
/*
* Common code for sending a TCP protocol control packet (i.e. no options, no
* payload, just flags).
*/
BaseType_t prvTCPSendSpecialPktHelper_IPV4( NetworkBufferDescriptor_t * pxNetworkBuffer,
uint8_t ucTCPFlags );
/*
* Common code for sending a TCP protocol control packet (i.e. no options, no
* payload, just flags).
*/
BaseType_t prvTCPSendSpecialPktHelper_IPV6( NetworkBufferDescriptor_t * pxNetworkBuffer,
uint8_t ucTCPFlags );
/*
* After a listening socket receives a new connection, it may duplicate itself.
* The copying takes place in prvTCPSocketCopy.
*/
BaseType_t prvTCPSocketCopy( FreeRTOS_Socket_t * pxNewSocket,
FreeRTOS_Socket_t * pxSocket );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_TCP_STATE_HANDLING_H */
@@ -0,0 +1,175 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_TCP_TRANSMISSION_H
#define FREERTOS_TCP_TRANSMISSION_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/*
* Either sends a SYN or calls prvTCPSendRepeated (for regular messages).
*/
int32_t prvTCPSendPacket( FreeRTOS_Socket_t * pxSocket );
/*
* Try to send a series of messages.
*/
int32_t prvTCPSendRepeated( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t ** ppxNetworkBuffer );
/*
* Return or send a packet to the other party.
*/
void prvTCPReturnPacket( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxDescriptor,
uint32_t ulLen,
BaseType_t xReleaseAfterSend );
/**
* Called by prvTCPReturnPacket(), this function will set the the window
* size on this side: 'xTCPHeader.usWindow'.
*/
void prvTCPReturn_CheckTCPWindow( FreeRTOS_Socket_t * pxSocket,
const NetworkBufferDescriptor_t * pxNetworkBuffer,
size_t uxIPHeaderSize );
/*
* Called by prvTCPReturnPacket(), this function sets the sequence and ack numbers
* in the TCP-header.
*/
void prvTCPReturn_SetSequenceNumber( FreeRTOS_Socket_t * pxSocket,
const NetworkBufferDescriptor_t * pxNetworkBuffer,
size_t uxIPHeaderSize,
uint32_t ulLen );
/*
* Return or send a packet to the other party.
*/
void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxDescriptor,
uint32_t ulLen,
BaseType_t xReleaseAfterSend );
/*
* Return or send a packet to the other party.
*/
void prvTCPReturnPacket_IPV6( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxDescriptor,
uint32_t ulLen,
BaseType_t xReleaseAfterSend );
void prvTCPReturn_SetEndPoint( const FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxNetworkBuffer,
size_t uxIPHeaderSize );
/*
* Let ARP look-up the MAC-address of the peer and initialise the first SYN
* packet.
*/
BaseType_t prvTCPPrepareConnect_IPV4( FreeRTOS_Socket_t * pxSocket );
/*
* Let ND look-up the MAC-address of the peer and initialise the first SYN
* packet.
*/
BaseType_t prvTCPPrepareConnect_IPV6( FreeRTOS_Socket_t * pxSocket );
/*
* Initialise the data structures which keep track of the TCP windowing system.
*/
BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket );
/*
* Set the initial properties in the options fields, like the preferred
* value of MSS and whether SACK allowed. Will be transmitted in the state
* 'eCONNECT_SYN'.
*/
UBaseType_t prvSetSynAckOptions( FreeRTOS_Socket_t * pxSocket,
TCPHeader_t * pxTCPHeader );
/*
* Prepare an outgoing message, if anything has to be sent.
*/
int32_t prvTCPPrepareSend( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t ** ppxNetworkBuffer,
UBaseType_t uxOptionsLength );
/*
* The API FreeRTOS_send() adds data to the TX stream. Add
* this data to the windowing system to it can be transmitted.
*/
void prvTCPAddTxData( FreeRTOS_Socket_t * pxSocket );
/*
* Set the TCP options (if any) for the outgoing packet.
*/
UBaseType_t prvSetOptions( FreeRTOS_Socket_t * pxSocket,
const NetworkBufferDescriptor_t * pxNetworkBuffer );
/*
* Called from prvTCPHandleState(). There is data to be sent.
* If ipconfigUSE_TCP_WIN is defined, and if only an ACK must be sent, it will
* be checked if it would better be postponed for efficiency.
*/
BaseType_t prvSendData( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t ** ppxNetworkBuffer,
uint32_t ulReceiveLength,
BaseType_t xByteCount );
/*
* A "challenge ACK" is as per https://tools.ietf.org/html/rfc5961#section-3.2,
* case #3. In summary, an RST was received with a sequence number that is
* unexpected but still within the window.
*/
BaseType_t prvTCPSendChallengeAck( NetworkBufferDescriptor_t * pxNetworkBuffer,
uint32_t ulCurrentSequenceNumber,
uint32_t ulOurSequenceNumber );
/*
* Reply to a peer with the RST flag on, in case a packet can not be handled.
*/
BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t * pxNetworkBuffer );
/*
* Check if the size of a network buffer is big enough to hold the outgoing message.
* Allocate a new bigger network buffer when necessary.
*/
NetworkBufferDescriptor_t * prvTCPBufferResize( const FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t * pxNetworkBuffer,
int32_t lDataLen,
UBaseType_t uxOptionsLength );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_TCP_TRANSMISSION_H */
@@ -0,0 +1,66 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_TCP_UTILS_H
#define FREERTOS_TCP_UTILS_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/*
* For logging and debugging: make a string showing the TCP flags.
*/
#if ( ipconfigHAS_DEBUG_PRINTF != 0 )
const char * prvTCPFlagMeaning( UBaseType_t xFlags );
#endif /* ipconfigHAS_DEBUG_PRINTF != 0 */
/*
* Set the initial value for MSS (Maximum Segment Size) to be used.
*/
void prvSocketSetMSS( FreeRTOS_Socket_t * pxSocket );
/*
* Set the initial value for MSS (Maximum Segment Size) to be used.
*/
void prvSocketSetMSS_IPV4( FreeRTOS_Socket_t * pxSocket );
/*
* Set the initial value for MSS (Maximum Segment Size) to be used.
*/
void prvSocketSetMSS_IPV6( FreeRTOS_Socket_t * pxSocket );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_TCP_UTILS_H */
@@ -0,0 +1,258 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*
* FreeRTOS_TCP_WIN.c
* Module which handles the TCP windowing schemes for FreeRTOS-PLUS-TCP
*/
#ifndef FREERTOS_TCP_WIN_H
#define FREERTOS_TCP_WIN_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/** @brief A very simple timer that registers the time that a packet was sent. It is used to trigger re-sending. */
typedef struct xTCPTimerStruct
{
TickType_t uxBorn; /**< The time at which a packet was sent ( using xTaskGetTickCount() ). */
} TCPTimer_t;
/** @brief This struct collects the properties of a TCP segment. A segment is a chunk of data which
* is sent in a single TCP packet, at most 1460 bytes. */
typedef struct xTCP_SEGMENT
{
uint32_t ulSequenceNumber; /**< The sequence number of the first byte in this packet */
int32_t lMaxLength; /**< Maximum space, number of bytes which can be stored in this segment */
int32_t lDataLength; /**< Actual number of bytes */
int32_t lStreamPos; /**< reference to the [t|r]xStream of the socket */
TCPTimer_t xTransmitTimer; /**< saves a timestamp at the moment this segment gets transmitted (TX only) */
union
{
struct
{
uint32_t
ucTransmitCount : 8, /**< Number of times the segment has been transmitted, used to calculate the RTT */
ucDupAckCount : 8, /**< Counts the number of times that a higher segment was ACK'd. After 3 times a Fast Retransmission takes place */
bOutstanding : 1, /**< It the peer's turn, we're just waiting for an ACK */
bAcked : 1, /**< This segment has been acknowledged */
bIsForRx : 1; /**< pdTRUE if segment is used for reception */
} bits;
uint32_t ulFlags;
} u; /**< A collection of boolean flags. */
#if ( ipconfigUSE_TCP_WIN != 0 )
struct xLIST_ITEM xQueueItem; /**< TX only: segments can be linked in one of three queues: xPriorityQueue, xTxQueue, and xWaitQueue */
struct xLIST_ITEM xSegmentItem; /**< With this item the segment can be connected to a list, depending on who is owning it */
#endif
} TCPSegment_t;
/** @brief This struct describes the windows sizes, both for incoming and outgoing. */
typedef struct xTCP_WINSIZE
{
uint32_t ulRxWindowLength; /**< The TCP window size of the incoming stream. */
uint32_t ulTxWindowLength; /**< The TCP window size of the outgoing stream. */
} TCPWinSize_t;
/** @brief If TCP time-stamps are being used, they will occupy 12 bytes in
* each packet, and thus the message space will become smaller.
* Keep this as a multiple of 4 */
#if ( ipconfigUSE_TCP_WIN == 1 )
#define ipSIZE_TCP_OPTIONS 16U
#else
#define ipSIZE_TCP_OPTIONS 12U
#endif
/** @brief Every TCP connection owns a TCP window for the administration of all packets
* It owns two sets of segment descriptors, incoming and outgoing
*/
typedef struct xTCP_WINDOW
{
union
{
struct
{
uint32_t
bHasInit : 1, /**< The window structure has been initialised */
bSendFullSize : 1, /**< May only send packets with a size equal to MSS (for optimisation) */
bTimeStamps : 1; /**< Socket is supposed to use TCP time-stamps. This depends on the */
} bits; /**< party which opens the connection */
uint32_t ulFlags;
} u; /**< A collection of boolean flags. */
TCPWinSize_t xSize; /**< The TCP window sizes of the incoming and outgoing streams. */
struct
{
uint32_t ulFirstSequenceNumber; /**< Logging & debug: the first segment received/sent in this connection
* for Tx: initial send sequence number (ISS)
* for Rx: initial receive sequence number (IRS) */
uint32_t ulCurrentSequenceNumber; /**< Tx/Rx: the oldest sequence number not yet confirmed, also SND.UNA / RCV.NXT
* In other words: the sequence number of the left side of the sliding window */
uint32_t ulFINSequenceNumber; /**< The sequence number which carried the FIN flag */
uint32_t ulHighestSequenceNumber; /**< Sequence number of the right-most byte + 1 */
} rx, /**< Sequence number of the incoming data stream. */
tx; /**< Sequence number of the outgoing data stream. */
uint32_t ulOurSequenceNumber; /**< The SEQ number we're sending out */
uint32_t ulUserDataLength; /**< Number of bytes in Rx buffer which may be passed to the user, after having received a 'missing packet' */
uint32_t ulNextTxSequenceNumber; /**< The sequence number given to the next byte to be added for transmission */
int32_t lSRTT; /**< Smoothed Round Trip Time, it may increment quickly and it decrements slower */
uint8_t ucOptionLength; /**< Number of valid bytes in ulOptionsData[] */
#if ( ipconfigUSE_TCP_WIN == 1 )
List_t xPriorityQueue; /**< Priority queue: segments which must be sent immediately */
List_t xTxQueue; /**< Transmit queue: segments queued for transmission */
List_t xWaitQueue; /**< Waiting queue: outstanding segments */
TCPSegment_t * pxHeadSegment; /**< points to a segment which has not been transmitted and it's size is still growing (user data being added) */
uint32_t ulOptionsData[ ipSIZE_TCP_OPTIONS / sizeof( uint32_t ) ]; /**< Contains the options we send out */
List_t xTxSegments; /**< A linked list of all transmission segments, sorted on sequence number */
List_t xRxSegments; /**< A linked list of reception segments, order depends on sequence of arrival */
#else
/* For tiny TCP, there is only 1 outstanding TX segment */
TCPSegment_t xTxSegment; /**< Priority queue */
#endif
uint16_t usOurPortNumber; /**< Mostly for debugging/logging: our TCP port number */
uint16_t usPeerPortNumber; /**< debugging/logging: the peer's TCP port number */
uint16_t usMSS; /**< Current accepted MSS */
uint16_t usMSSInit; /**< MSS as configured by the socket owner */
} TCPWindow_t;
/*=============================================================================
*
* Creation and destruction
*
*=============================================================================*/
/* Create and initialize a window */
BaseType_t xTCPWindowCreate( TCPWindow_t * pxWindow,
uint32_t ulRxWindowLength,
uint32_t ulTxWindowLength,
uint32_t ulAckNumber,
uint32_t ulSequenceNumber,
uint32_t ulMSS );
/* Destroy a window (always returns NULL)
* It will free some resources: a collection of segments */
void vTCPWindowDestroy( TCPWindow_t const * pxWindow );
/* Initialize a window */
void vTCPWindowInit( TCPWindow_t * pxWindow,
uint32_t ulAckNumber,
uint32_t ulSequenceNumber,
uint32_t ulMSS );
/* Clean up allocated segments. Should only be called when FreeRTOS+TCP will no longer be used. */
void vTCPSegmentCleanup( void );
/*=============================================================================
*
* Rx functions
*
*=============================================================================*/
/* if true may be passed directly to user (segment expected and window is empty)
* But pxWindow->ackno should always be used to set "BUF->ackno" */
int32_t lTCPWindowRxCheck( TCPWindow_t * pxWindow,
uint32_t ulSequenceNumber,
uint32_t ulLength,
uint32_t ulSpace,
uint32_t * pulSkipCount );
/* This function will be called as soon as a FIN is received. It will return true
* if there are no 'open' reception segments */
BaseType_t xTCPWindowRxEmpty( const TCPWindow_t * pxWindow );
/*=============================================================================
*
* Tx functions
*
*=============================================================================*/
/* Adds data to the Tx-window */
int32_t lTCPWindowTxAdd( TCPWindow_t * pxWindow,
uint32_t ulLength,
int32_t lPosition,
int32_t lMax );
/* Check data to be sent and calculate the time period we may sleep */
BaseType_t xTCPWindowTxHasData( TCPWindow_t const * pxWindow,
uint32_t ulWindowSize,
TickType_t * pulDelay );
/* See if anything is left to be sent
* Function will be called when a FIN has been received. Only when the TX window is clean,
* it will return pdTRUE */
BaseType_t xTCPWindowTxDone( const TCPWindow_t * pxWindow );
/* Fetches data to be sent.
* 'plPosition' will point to a location with the circular data buffer: txStream */
uint32_t ulTCPWindowTxGet( TCPWindow_t * pxWindow,
uint32_t ulWindowSize,
int32_t * plPosition );
/* Receive a normal ACK */
uint32_t ulTCPWindowTxAck( TCPWindow_t * pxWindow,
uint32_t ulSequenceNumber );
/* Receive a SACK option */
uint32_t ulTCPWindowTxSack( TCPWindow_t * pxWindow,
uint32_t ulFirst,
uint32_t ulLast );
/**
* @brief Check if a > b, where a and b are rolling counters.
*
* @param[in] a: The value on the left-hand side.
* @param[in] b: The value on the right-hand side.
*
* @return pdTRUE if a > b, otherwise pdFALSE.
*
* @note GreaterThan is calculated as "( a - ( b + 1U ) ) < 0x80000000".
*/
BaseType_t xSequenceGreaterThan( uint32_t a,
uint32_t b );
/**
* @brief Check if a < b, where a and b are rolling counters.
*
* @param[in] a: The value on the left-hand side.
* @param[in] b: The value on the right-hand side.
*
* @return pdTRUE if a < b, otherwise pdFALSE.
*
* @note LessThan is implemented as "( b - ( a + 1 ) ) < 0x80000000".
*/
BaseType_t xSequenceLessThan( uint32_t a,
uint32_t b );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_TCP_WIN_H */
@@ -0,0 +1,73 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef FREERTOS_UDP_IP_H
#define FREERTOS_UDP_IP_H
/* Application level configuration options. */
#include "FreeRTOSIPConfig.h"
#include "FreeRTOSIPConfigDefaults.h"
#include "FreeRTOS_IP.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/*
* Called when the application has generated a UDP packet to send.
*/
void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetworkBuffer );
void vProcessGeneratedUDPPacket_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer );
/*
* The caller must ensure that pxNetworkBuffer->xDataLength is the UDP packet
* payload size (excluding packet headers) and that the packet in pucEthernetBuffer
* is at least the size of UDPPacket_t.
*/
BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffer,
uint16_t usPort,
BaseType_t * pxIsWaitingForResolution );
BaseType_t xProcessReceivedUDPPacket_IPv4( NetworkBufferDescriptor_t * pxNetworkBuffer,
uint16_t usPort,
BaseType_t * pxIsWaitingForARPResolution );
BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetworkBuffer,
uint16_t usPort,
BaseType_t * pxIsWaitingForNDResolution );
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* FREERTOS_UDP_IP_H */
@@ -0,0 +1,900 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/**
* @file IPTraceMacroDefaults.h
* @brief This file provides default (empty) implementations for any IP trace
* macros that are not defined by the user. See
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/08-Trace-macros
*/
#ifndef IP_TRACE_MACRO_DEFAULTS_H
#define IP_TRACE_MACRO_DEFAULTS_H
#ifndef FREERTOS_IP_CONFIG_DEFAULTS_H
#error FreeRTOSIPConfigDefaults.h has not been included yet
#endif
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* NETWORK TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*
* iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER
*
* Called when a task attempts to obtain a network buffer, but a buffer was
* not available even after any defined block period.
*/
#ifndef iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER
#define iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER_FROM_ISR
*
* Called when an interrupt service routine attempts to obtain a network
* buffer, but a buffer was not available.
*/
#ifndef iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER_FROM_ISR
#define iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER_FROM_ISR()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceNETWORK_BUFFER_OBTAINED
*
* Called when the network buffer at address pxBufferAddress is obtained from
* the TCP/IP stack by an RTOS task.
*/
#ifndef iptraceNETWORK_BUFFER_OBTAINED
#define iptraceNETWORK_BUFFER_OBTAINED( pxBufferAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR
*
* Called when the network buffer at address pxBufferAddress is obtained from
* the TCP/IP stack by an interrupt service routine.
*/
#ifndef iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR
#define iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR( pxBufferAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceNETWORK_BUFFER_RELEASED
*
* Called when the network buffer at address pxBufferAddress is released back
* to the TCP/IP stack.
*/
#ifndef iptraceNETWORK_BUFFER_RELEASED
#define iptraceNETWORK_BUFFER_RELEASED( pxBufferAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceNETWORK_DOWN
*
* Called when the network driver indicates that the network connection has
* been lost (not implemented by all network drivers).
*/
#ifndef iptraceNETWORK_DOWN
#define iptraceNETWORK_DOWN()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceNETWORK_EVENT_RECEIVED
*
* Called when the TCP/IP stack processes an event previously posted to the
* network event queue. eEvent will be one of the following values:
*
* eNetworkDownEvent - The network interface has been lost and/or needs
* [re]connecting.
* eNetworkRxEvent - The network interface has queued a received Ethernet
* frame.
* eARPTimerEvent - The Resolution timer expired.
* eStackTxEvent - The software stack has queued a packet to transmit.
* eDHCPEvent - Process the DHCP state machine.
*
* Note the events are defined by the private eIPEvent_t type which is not
* generally accessible.
*/
#ifndef iptraceNETWORK_EVENT_RECEIVED
#define iptraceNETWORK_EVENT_RECEIVED( eEvent )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceNETWORK_INTERFACE_INPUT
*
* Called when a packet of length uxDataLength and with the contents at
* address pucEthernetBuffer has been received.
*/
#ifndef iptraceNETWORK_INTERFACE_INPUT
#define iptraceNETWORK_INTERFACE_INPUT( uxDataLength, pucEthernetBuffer )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceNETWORK_INTERFACE_OUTPUT
*
* Called when a packet of length uxDataLength and with the contents at
* address pucEthernetBuffer has been sent.
*/
#ifndef iptraceNETWORK_INTERFACE_OUTPUT
#define iptraceNETWORK_INTERFACE_OUTPUT( uxDataLength, pucEthernetBuffer )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceNETWORK_INTERFACE_RECEIVE
*
* Called when a packet is received from the network by the network driver.
* Note this macro is called by the network driver rather than the TCP/IP stack
* and may not be called at all by drivers provided by third parties.
*/
#ifndef iptraceNETWORK_INTERFACE_RECEIVE
#define iptraceNETWORK_INTERFACE_RECEIVE()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceNETWORK_INTERFACE_TRANSMIT
*
* Called when a packet is sent to the network by the network driver. Note this
* macro is called by the network driver rather than the TCP/IP stack and may
* not be called at all by drivers provided by third parties.
*/
#ifndef iptraceNETWORK_INTERFACE_TRANSMIT
#define iptraceNETWORK_INTERFACE_TRANSMIT()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceSTACK_TX_EVENT_LOST
*
* Called when a packet generated by the TCP/IP stack is dropped because there
* is insufficient space in the network event queue (see the
* ipconfigEVENT_QUEUE_LENGTH setting in FreeRTOSIPConfig.h).
*/
#ifndef iptraceSTACK_TX_EVENT_LOST
#define iptraceSTACK_TX_EVENT_LOST( xEvent )
#endif
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* NETWORK TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* DRIVER TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*
* iptraceETHERNET_RX_EVENT_LOST
*
* Called when a packet received by the network driver is dropped for one of
* the following reasons: There is insufficient space in the network event
* queue (see the ipconfigEVENT_QUEUE_LENGTH setting in FreeRTOSIPConfig.h),
* the received packet has an invalid data length, or there are no network
* buffers available (see the ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS setting
* in FreeRTOSIPConfig.h). Note this macro is called by the network driver
* rather than the TCP/IP stack and may not be called at all by drivers
* provided by third parties.
*/
#ifndef iptraceETHERNET_RX_EVENT_LOST
#define iptraceETHERNET_RX_EVENT_LOST()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceWAITING_FOR_TX_DMA_DESCRIPTOR
*
* Called when a transmission at the network driver level cannot complete
* immediately because the driver is having to wait for a DMA descriptor to
* become free. Try increasing the configNUM_TX_ETHERNET_DMA_DESCRIPTORS
* setting in FreeRTOSConfig.h (if it exists for the network driver being
* used).
*/
#ifndef iptraceWAITING_FOR_TX_DMA_DESCRIPTOR
#define iptraceWAITING_FOR_TX_DMA_DESCRIPTOR()
#endif
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* DRIVER TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* UDP TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*
* iptraceSENDING_UDP_PACKET
*
* Called when a UDP packet is sent to the IP address ulIPAddress. ulIPAddress
* is expressed as a 32-bit number in network byte order.
*/
#ifndef iptraceSENDING_UDP_PACKET
#define iptraceSENDING_UDP_PACKET( ulIPAddress )
#endif
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* UDP TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* SOCKET TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*
* iptraceBIND_FAILED
*
* A call to FreeRTOS_bind() failed. usPort is the port number the socket
* xSocket was to be bound to.
*/
#ifndef iptraceBIND_FAILED
#define iptraceBIND_FAILED( xSocket, usPort )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceFAILED_TO_CREATE_EVENT_GROUP
*
* Called when an event group could not be created, possibly due to
* insufficient heap space, during new socket creation.
*/
#ifndef iptraceFAILED_TO_CREATE_EVENT_GROUP
#define iptraceFAILED_TO_CREATE_EVENT_GROUP()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceFAILED_TO_CREATE_SOCKET
*
* A call to FreeRTOS_socket() failed because there was insufficient FreeRTOS
* heap memory available for the socket structure to be created.
*/
#ifndef iptraceFAILED_TO_CREATE_SOCKET
#define iptraceFAILED_TO_CREATE_SOCKET()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceFAILED_TO_NOTIFY_SELECT_GROUP
*/
#ifndef iptraceFAILED_TO_NOTIFY_SELECT_GROUP
#define iptraceFAILED_TO_NOTIFY_SELECT_GROUP( xSocket )
#endif
/*-----------------------------------------------------------------------*/
/*
* iptraceNO_BUFFER_FOR_SENDTO
*
* Called when a call to FreeRTOS_sendto() tries to allocate a buffer, but a
* buffer was not available even after any defined block period.
*/
#ifndef iptraceNO_BUFFER_FOR_SENDTO
#define iptraceNO_BUFFER_FOR_SENDTO()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceRECVFROM_DISCARDING_BYTES
*
* FreeRTOS_recvfrom() is discarding xNumberOfBytesDiscarded bytes because the
* number of bytes received is greater than the number of bytes that will fit
* in the user supplied buffer (the buffer passed in as a FreeRTOS_recvfrom()
* function parameter).
*/
#ifndef iptraceRECVFROM_DISCARDING_BYTES
#define iptraceRECVFROM_DISCARDING_BYTES( xNumberOfBytesDiscarded )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceRECVFROM_INTERRUPTED
*
* Called when a blocking call to FreeRTOS_recvfrom() is interrupted through a
* call to FreeRTOS_SignalSocket().
*/
#ifndef iptraceRECVFROM_INTERRUPTED
#define iptraceRECVFROM_INTERRUPTED()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceRECVFROM_TIMEOUT
*
* Called when FreeRTOS_recvfrom() gets no data on the given socket even after
* any defined block period.
*/
#ifndef iptraceRECVFROM_TIMEOUT
#define iptraceRECVFROM_TIMEOUT()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceSENDTO_DATA_TOO_LONG
*
* Called when the data requested to be sent using a call to FreeRTOS_sendto()
* is too long and could not be sent.
*/
#ifndef iptraceSENDTO_DATA_TOO_LONG
#define iptraceSENDTO_DATA_TOO_LONG()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceSENDTO_SOCKET_NOT_BOUND
*
* Called when the socket used in the call to FreeRTOS_sendto() is not already
* bound to a port.
*/
#ifndef iptraceSENDTO_SOCKET_NOT_BOUND
#define iptraceSENDTO_SOCKET_NOT_BOUND()
#endif
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* SOCKET TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* ARP TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*
* iptraceARP_PACKET_RECEIVED
*
* Called when an ARP packet is received, even if the local network node is not
* involved in the ARP transaction.
*/
#ifndef iptraceARP_PACKET_RECEIVED
#define iptraceARP_PACKET_RECEIVED()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceARP_TABLE_ENTRY_CREATED
*
* Called when a new entry in the ARP table is created to map the IP address
* ulIPAddress to the MAC address ucMACAddress. ulIPAddress is expressed as a
* 32-bit number in network byte order. ucMACAddress is a pointer to an
* MACAddress_t structure.
*/
#ifndef iptraceARP_TABLE_ENTRY_CREATED
#define iptraceARP_TABLE_ENTRY_CREATED( ulIPAddress, ucMACAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceARP_TABLE_ENTRY_EXPIRED
*
* Called when the entry for the IP address ulIPAddress in the ARP cache is
* removed. ulIPAddress is expressed as a 32-bit number in network byte order.
*/
#ifndef iptraceARP_TABLE_ENTRY_EXPIRED
#define iptraceARP_TABLE_ENTRY_EXPIRED( ulIPAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceARP_TABLE_ENTRY_WILL_EXPIRE
*
* Called when an ARP request is about to be sent because the entry for the IP
* address ulIPAddress in the ARP cache has become stale. ulIPAddress is
* expressed as a 32-bit number in network byte order.
*/
#ifndef iptraceARP_TABLE_ENTRY_WILL_EXPIRE
#define iptraceARP_TABLE_ENTRY_WILL_EXPIRE( ulIPAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceCREATING_ARP_REQUEST
*
* Called when the IP generates an ARP request packet.
*/
#ifndef iptraceCREATING_ARP_REQUEST
#define iptraceCREATING_ARP_REQUEST( ulIPAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceDELAYED_ARP_BUFFER_FULL
*
* A packet has come in from an unknown IPv4 address. An ARP request has been
* sent, but the queue is still filled with a different packet.
*/
#ifndef iptraceDELAYED_ARP_BUFFER_FULL
#define iptraceDELAYED_ARP_BUFFER_FULL()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptrace_DELAYED_ARP_REQUEST_REPLIED
*
* An ARP request has been sent, and a matching reply is received. Now the
* original packet will be processed by the IP-task.
*/
#ifndef iptrace_DELAYED_ARP_REQUEST_REPLIED
#define iptrace_DELAYED_ARP_REQUEST_REPLIED()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceDELAYED_ARP_REQUEST_STARTED
*
* A packet came in from an unknown IPv4 address. An ARP request has been sent
* and the network buffer is stored for processing later.
*/
#ifndef iptraceDELAYED_ARP_REQUEST_STARTED
#define iptraceDELAYED_ARP_REQUEST_STARTED()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceDELAYED_ARP_TIMER_EXPIRED
*
* A packet was stored for delayed processing, but there is no ARP reply. The
* network buffer will be released without being processed.
*/
#ifndef iptraceDELAYED_ARP_TIMER_EXPIRED
#define iptraceDELAYED_ARP_TIMER_EXPIRED()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceDROPPED_INVALID_ARP_PACKET
*
* Called when an ARP packet is dropped due to invalid protocol and hardware
* fields in the header at address pxARPHeader.
*/
#ifndef iptraceDROPPED_INVALID_ARP_PACKET
#define iptraceDROPPED_INVALID_ARP_PACKET( pxARPHeader )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptracePACKET_DROPPED_TO_GENERATE_ARP
*
* Called when a packet destined for the IP address ulIPAddress is dropped
* because the ARP cache does not contain an entry for the IP address. The
* packet is automatically replaced by an ARP packet. ulIPAddress is expressed
* as a 32-bit number in network byte order.
*/
#ifndef iptracePACKET_DROPPED_TO_GENERATE_ARP
#define iptracePACKET_DROPPED_TO_GENERATE_ARP( ulIPAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptracePROCESSING_RECEIVED_ARP_REPLY
*
* Called when the ARP cache is about to be updated in response to the
* reception of an ARP reply. ulIPAddress holds the ARP message's target IP
* address (as a 32-bit number in network byte order), which may not be the
* local network node (depending on the FreeRTOSIPConfig.h settings).
*/
#ifndef iptracePROCESSING_RECEIVED_ARP_REPLY
#define iptracePROCESSING_RECEIVED_ARP_REPLY( ulIPAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceSENDING_ARP_REPLY
*
* An ARP reply is being sent in response to an ARP request from the IP address
* ulIPAddress. ulIPAddress is expressed as a 32-bit number in network byte
* order.
*/
#ifndef iptraceSENDING_ARP_REPLY
#define iptraceSENDING_ARP_REPLY( ulIPAddress )
#endif
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* ARP TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* ND TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*
* iptraceND_TABLE_ENTRY_EXPIRED
*/
#ifndef iptraceND_TABLE_ENTRY_EXPIRED
#define iptraceND_TABLE_ENTRY_EXPIRED( pxIPAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceND_TABLE_ENTRY_WILL_EXPIRE
*/
#ifndef iptraceND_TABLE_ENTRY_WILL_EXPIRE
#define iptraceND_TABLE_ENTRY_WILL_EXPIRE( pxIPAddress )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceDELAYED_ND_BUFFER_FULL
*
* A packet has come in from an unknown IPv6 address. An ND request has been
* sent, but the queue is still filled with a different packet.
*/
#ifndef iptraceDELAYED_ND_BUFFER_FULL
#define iptraceDELAYED_ND_BUFFER_FULL()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptrace_DELAYED_ND_REQUEST_REPLIED
*/
#ifndef iptrace_DELAYED_ND_REQUEST_REPLIED
#define iptrace_DELAYED_ND_REQUEST_REPLIED()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceDELAYED_ND_REQUEST_STARTED
*
* A packet came in from an unknown IPv6 address. An ND request has been sent
* and the network buffer is stored for processing later.
*/
#ifndef iptraceDELAYED_ND_REQUEST_STARTED
#define iptraceDELAYED_ND_REQUEST_STARTED()
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceDELAYED_ND_TIMER_EXPIRED
*
* A packet was stored for delayed processing, but there is no ND reply. The
* network buffer will be released without being processed.
*/
#ifndef iptraceDELAYED_ND_TIMER_EXPIRED
#define iptraceDELAYED_ND_TIMER_EXPIRED()
#endif
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* ND TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* DHCP TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*
* iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS
*
* Called when the default IP address is used because an IP address could not
* be obtained from a DHCP. ulIPAddress is expressed as a 32-bit number in
* network byte order.
*/
#ifndef iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS
#define iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS( ulIPAddress )
#endif
/*-----------------------------------------------------------------------*/
/*
* iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IPv6_ADDRESS
*/
#ifndef iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IPv6_ADDRESS
#define iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IPv6_ADDRESS( xIPAddress )
#endif
/*-----------------------------------------------------------------------*/
/*
* iptraceDHCP_SUCCEEDED
*
* Called when DHCP negotiation is complete and the IP address in
* ulOfferedIPAddress is offered to the device.
*/
#ifndef iptraceDHCP_SUCCEEDED
#define iptraceDHCP_SUCCEEDED( ulOfferedIPAddress )
#endif
/*-----------------------------------------------------------------------*/
/*
* iptraceSENDING_DHCP_DISCOVER
*
* Called when a DHCP discover packet is sent.
*/
#ifndef iptraceSENDING_DHCP_DISCOVER
#define iptraceSENDING_DHCP_DISCOVER()
#endif
/*-----------------------------------------------------------------------*/
/*
* iptraceSENDING_DHCP_REQUEST
*
* Called when a DHCP request packet is sent.
*/
#ifndef iptraceSENDING_DHCP_REQUEST
#define iptraceSENDING_DHCP_REQUEST()
#endif
/*-----------------------------------------------------------------------*/
/*===========================================================================*/
/* DHCP TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* DNS TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*
* iptraceSENDING_DNS_REQUEST
*
* Called when a DNS request is sent.
*/
#ifndef iptraceSENDING_DNS_REQUEST
#define iptraceSENDING_DNS_REQUEST()
#endif
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* DNS TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* ICMP TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*
* iptraceICMP_PACKET_RECEIVED
*
* Called when an ICMP packet is received.
*/
#ifndef iptraceICMP_PACKET_RECEIVED
#define iptraceICMP_PACKET_RECEIVED()
#endif
/*-----------------------------------------------------------------------*/
/*
* iptraceSENDING_PING_REPLY
*
* Called when an ICMP echo reply (ping reply) is sent to the IP address
* ulIPAddress in response to an ICMP echo request (ping request) originating
* from the same address. ulIPAddress is expressed as a 32-bit number in
* network byte order.
*/
#ifndef iptraceSENDING_PING_REPLY
#define iptraceSENDING_PING_REPLY( ulIPAddress )
#endif
/*-----------------------------------------------------------------------*/
/*===========================================================================*/
/* ICMP TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* ROUTER ADVERTISEMENT TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*
* iptraceRA_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS
*/
#ifndef iptraceRA_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS
#define iptraceRA_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS( ipv6_address )
#endif
/*---------------------------------------------------------------------------*/
/*
* iptraceRA_SUCCEEDED
*/
#ifndef iptraceRA_SUCCEEDED
#define iptraceRA_SUCCEEDED( ipv6_address )
#endif
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* ROUTER ADVERTISEMENT TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* MEM STATS MACROS */
/*===========================================================================*/
/*-----------------------------------------------------------------------*/
/*
* iptraceMEM_STATS_CLOSE
*
* Should be called by the application when the collection of memory
* statistics should be stopped.
*/
#ifndef iptraceMEM_STATS_CLOSE
#define iptraceMEM_STATS_CLOSE()
#endif
/*-----------------------------------------------------------------------*/
/*
* iptraceMEM_STATS_CREATE
*
* Called when an object at address pxObject of type xMemType and size
* uxSize has been allocated from the heap.
*/
#ifndef iptraceMEM_STATS_CREATE
#define iptraceMEM_STATS_CREATE( xMemType, pxObject, uxSize )
#endif
/*-----------------------------------------------------------------------*/
/*
* iptraceMEM_STATS_DELETE
*
* Called when an object at address pxObject has been deallocated and the
* memory has been returned to the heap.
*/
#ifndef iptraceMEM_STATS_DELETE
#define iptraceMEM_STATS_DELETE( pxObject )
#endif
/*-----------------------------------------------------------------------*/
/*===========================================================================*/
/* MEM STATS MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* TCP DUMP TRACE MACROS */
/*===========================================================================*/
/*-----------------------------------------------------------------------*/
/*
* iptraceDUMP_INIT
*/
#ifndef iptraceDUMP_INIT
#define iptraceDUMP_INIT( pcFileName, pxEntries )
#endif
/*-----------------------------------------------------------------------*/
/*
* iptraceDUMP_PACKET
*/
#ifndef iptraceDUMP_PACKET
#define iptraceDUMP_PACKET( pucBuffer, uxLength, xIncoming )
#endif
/*-----------------------------------------------------------------------*/
/*===========================================================================*/
/* TCP DUMP TRACE MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
#endif /* IP_TRACE_MACRO_DEFAULTS_H */
@@ -0,0 +1,90 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef NETWORK_BUFFER_MANAGEMENT_H
#define NETWORK_BUFFER_MANAGEMENT_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#include "FreeRTOS_IP.h"
/* _HT_ Two macro's needed while debugging/testing, please ignore. */
#define BUFFER_FROM_WHERE_DECL
#define BUFFER_FROM_WHERE_CALL( aWhere )
/* NOTE PUBLIC API FUNCTIONS. */
BaseType_t xNetworkBuffersInitialise( void );
NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes,
TickType_t xBlockTimeTicks );
/* The definition of the below function is only available if BufferAllocation_2.c has been linked into the source. */
NetworkBufferDescriptor_t * pxNetworkBufferGetFromISR( size_t xRequestedSizeBytes );
void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer );
/* The definition of the below function is only available if BufferAllocation_2.c has been linked into the source. */
BaseType_t vNetworkBufferReleaseFromISR( NetworkBufferDescriptor_t * const pxNetworkBuffer );
uint8_t * pucGetNetworkBuffer( size_t * pxRequestedSizeBytes );
void vReleaseNetworkBuffer( uint8_t * pucEthernetBuffer );
/* Get the current number of free network buffers. */
UBaseType_t uxGetNumberOfFreeNetworkBuffers( void );
/* Get the lowest number of free network buffers. */
UBaseType_t uxGetMinimumFreeNetworkBuffers( void );
/* Copy a network buffer into a bigger buffer. */
NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer,
size_t uxNewLength );
/* Increase the size of a Network Buffer.
* In case BufferAllocation_2.c is used, the new space must be allocated. */
NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer,
size_t xNewSizeBytes );
#if ipconfigTCP_IP_SANITY
/*
* Check if an address is a valid pointer to a network descriptor
* by looking it up in the array of network descriptors
*/
UBaseType_t bIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc );
BaseType_t prvIsFreeBuffer( const NetworkBufferDescriptor_t * pxDescr );
#endif
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* NETWORK_BUFFER_MANAGEMENT_H */
@@ -0,0 +1,64 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef NETWORK_INTERFACE_H
#define NETWORK_INTERFACE_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#include "FreeRTOS_IP.h"
/* INTERNAL API FUNCTIONS. */
/* Since there are multiple interfaces, there are multiple versions
* of the following functions.
* These are now declared static in NetworkInterface.c and their addresses
* are stored in a struct NetworkInterfaceDescriptor_t.
*
* BaseType_t xNetworkInterfaceInitialise( struct xNetworkInterface *pxInterface );
* BaseType_t xGetPhyLinkStatus( struct xNetworkInterface *pxInterface );
*/
/* The following function is defined only when BufferAllocation_1.c is linked in the project. */
size_t uxNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] );
BaseType_t xGetPhyLinkStatus( struct xNetworkInterface * pxInterface );
#define MAC_IS_MULTICAST( pucMACAddressBytes ) ( ( pucMACAddressBytes[ 0 ] & 1U ) != 0U )
#define MAC_IS_UNICAST( pucMACAddressBytes ) ( ( pucMACAddressBytes[ 0 ] & 1U ) == 0U )
/* *INDENT-OFF* */
#ifdef __cplusplus
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* NETWORK_INTERFACE_H */