[修改] 增加freeRTOS
1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,159 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* Application level configuration options. */
|
||||
#include "FreeRTOSIPConfig.h"
|
||||
#include "FreeRTOSIPConfigDefaults.h"
|
||||
#include "IPTraceMacroDefaults.h"
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* Miscellaneous structure and definitions. */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
} ARPCacheRow_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
eARPCacheMiss = 0, /* 0 An ARP table lookup did not find a valid entry. */
|
||||
eARPCacheHit, /* 1 An ARP table lookup found a valid entry. */
|
||||
eCantSendPacket /* 2 There is no IP address, or an ARP is still in progress, so the packet cannot be sent. */
|
||||
} eARPLookupResult_t;
|
||||
|
||||
/*
|
||||
* 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 );
|
||||
|
||||
#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 eARPCacheHit. If the IP address does not exist in the ARP
|
||||
* cache return eARPCacheMiss. 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 eCantSendPacket.
|
||||
*/
|
||||
eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress,
|
||||
MACAddress_t * const pxMACAddress );
|
||||
|
||||
#if ( ipconfigUSE_ARP_REVERSED_LOOKUP != 0 )
|
||||
|
||||
/* Lookup an IP-address if only the MAC-address is known */
|
||||
eARPLookupResult_t eARPGetCacheEntryByMac( const MACAddress_t * const pxMACAddress,
|
||||
uint32_t * pulIPAddress );
|
||||
|
||||
#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 );
|
||||
|
||||
/*
|
||||
* 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 );
|
||||
|
||||
/*
|
||||
* After DHCP is ready and when changing IP address, force a quick send of our new IP
|
||||
* address
|
||||
*/
|
||||
void vARPSendGratuitous( void );
|
||||
|
||||
/* This function will check if the target IP-address belongs to this device.
|
||||
* If so, the packet will be passed to the IP-stack, who will answer it.
|
||||
* The function is to be called within the function xNetworkInterfaceOutput()
|
||||
* in NetworkInterface.c as follows:
|
||||
*
|
||||
* if( xCheckLoopback( pxDescriptor, bReleaseAfterSend ) != 0 )
|
||||
* {
|
||||
* / * The packet has been sent back to the IP-task.
|
||||
* * The IP-task will further handle it.
|
||||
* * Do not release the descriptor.
|
||||
* * /
|
||||
* return pdTRUE;
|
||||
* }
|
||||
* / * Send the packet as usual. * /
|
||||
*/
|
||||
BaseType_t xCheckLoopback( NetworkBufferDescriptor_t * const pxDescriptor,
|
||||
BaseType_t bReleaseAfterSend );
|
||||
|
||||
void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress );
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* FREERTOS_ARP_H */
|
||||
@ -0,0 +1,250 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* Application level configuration options. */
|
||||
#include "FreeRTOSIPConfig.h"
|
||||
#include "IPTraceMacroDefaults.h"
|
||||
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
|
||||
#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
|
||||
|
||||
/* 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. */
|
||||
|
||||
/* The following define is temporary and serves to make the /single source
|
||||
* code more similar to the /multi version. */
|
||||
|
||||
#define EP_DHCPData xDHCPData /**< Temporary define to make /single source similar to /multi version. */
|
||||
#define EP_IPv4_SETTINGS xNetworkAddressing /**< Temporary define to make /single source similar to /multi version. */
|
||||
|
||||
/** @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 68. */
|
||||
#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 of the DHCP transaction */
|
||||
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 time for which the current IP address is leased */
|
||||
TickType_t xDHCPTxTime; /**< The time at which a DHCP request was sent. */
|
||||
TickType_t xDHCPTxPeriod; /**< The maximum time that the client will wait for a reply. */
|
||||
BaseType_t xUseBroadcast; /**< Try both without and with the broadcast flag */
|
||||
eDHCPState_t eDHCPState; /**< Maintains the DHCP state machine state. */
|
||||
};
|
||||
|
||||
typedef struct xDHCP_DATA DHCPData_t;
|
||||
|
||||
/* Returns the current state of a DHCP process. */
|
||||
eDHCPState_t eGetDHCPState( void );
|
||||
|
||||
/*
|
||||
* 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,
|
||||
eDHCPState_t eExpectedState );
|
||||
|
||||
/* Internal call: returns true if socket is the current DHCP socket */
|
||||
BaseType_t xIsDHCPSocket( const ConstSocket_t xSocket );
|
||||
|
||||
|
||||
/* The application can indicate a preferred IP address by calling this function
|
||||
* before FreeRTOS_IPInit() is called. */
|
||||
uint32_t vDHCPSetPreferredIPAddress( uint32_t ulIPAddress );
|
||||
|
||||
#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
|
||||
*/
|
||||
eDHCPCallbackAnswer_t xApplicationDHCPHook( eDHCPCallbackPhase_t eDHCPPhase,
|
||||
uint32_t ulIPAddress );
|
||||
#endif /* ( ipconfigUSE_DHCP_HOOK != 0 ) */
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* FREERTOS_DHCP_H */
|
||||
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* Application level configuration options. */
|
||||
#include "FreeRTOS_DNS_Globals.h"
|
||||
#include "FreeRTOS_DNS_Callback.h"
|
||||
#include "FreeRTOS_DNS_Cache.h"
|
||||
|
||||
/*
|
||||
* LLMNR is very similar to DNS, so is handled by the DNS routines.
|
||||
*/
|
||||
uint32_t ulDNSHandlePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer );
|
||||
|
||||
#if ( ipconfigUSE_LLMNR == 1 )
|
||||
/* The LLMNR MAC address is 01:00:5e:00:00:fc */
|
||||
extern const MACAddress_t xLLMNR_MacAdress;
|
||||
#endif /* ipconfigUSE_LLMNR */
|
||||
|
||||
#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 );
|
||||
|
||||
|
||||
#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 );
|
||||
|
||||
#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,56 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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"
|
||||
|
||||
/* FreeRTOS+TCP includes. */
|
||||
#include "FreeRTOS_IP.h"
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdint.h>
|
||||
|
||||
#if ( ( ipconfigUSE_DNS_CACHE == 1 ) && ( ipconfigUSE_DNS != 0 ) )
|
||||
|
||||
uint32_t FreeRTOS_dnslookup( const char * pcHostName );
|
||||
|
||||
void FreeRTOS_dnsclear( void );
|
||||
|
||||
BaseType_t FreeRTOS_dns_update( const char * pcName,
|
||||
uint32_t * pulIP,
|
||||
uint32_t ulTTL );
|
||||
|
||||
BaseType_t FreeRTOS_ProcessDNSCache( const char * pcName,
|
||||
uint32_t * pulIP,
|
||||
uint32_t ulTTL,
|
||||
BaseType_t xLookUp );
|
||||
#endif /* if ( ipconfigUSE_DNS_CACHE == 1 ) */
|
||||
|
||||
#endif /* ifndef FREERTOS_DNS_CACHE_H */
|
||||
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
/* FreeRTOS+TCP includes. */
|
||||
#include "FreeRTOS_IP.h"
|
||||
|
||||
#include "FreeRTOS_DNS_Globals.h"
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdint.h>
|
||||
/* Application level configuration options. */
|
||||
|
||||
#if ( ( ipconfigDNS_USE_CALLBACKS == 1 ) && ( ipconfigUSE_DNS != 0 ) )
|
||||
|
||||
BaseType_t xDNSDoCallback( TickType_t uxIdentifier,
|
||||
const char * pcName,
|
||||
uint32_t ulIPAddress );
|
||||
|
||||
void vDNSSetCallBack( const char * pcHostName,
|
||||
void * pvSearchID,
|
||||
FOnDNSEvent pCallbackFunction,
|
||||
TickType_t uxTimeout,
|
||||
TickType_t uxIdentifier );
|
||||
|
||||
void vDNSCheckCallBack( void * pvSearchID );
|
||||
|
||||
|
||||
void vDNSCallbackInitialise();
|
||||
|
||||
#endif /* ipconfigDNS_USE_CALLBACKS && ipconfigUSE_DNS */
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* ifndef FREERTOS_DNS_CALLBACK_H */
|
||||
@ -0,0 +1,251 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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 "IPTraceMacroDefaults.h"
|
||||
|
||||
/* Standard includes. */
|
||||
|
||||
#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 )
|
||||
|
||||
/** @brief The maximum number of times a DNS request should be sent out if a response
|
||||
* is not received, before giving up. */
|
||||
#ifndef ipconfigDNS_REQUEST_ATTEMPTS
|
||||
#define ipconfigDNS_REQUEST_ATTEMPTS 5
|
||||
#endif
|
||||
|
||||
|
||||
/* 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 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_REPONSE 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 ) */
|
||||
|
||||
|
||||
#ifndef _lint
|
||||
#if ( ipconfigUSE_DNS_CACHE == 0 )
|
||||
#if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY != 1 )
|
||||
#error When DNS caching is disabled, please make ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY equal to 1.
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** @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 */
|
||||
|
||||
#define ipLLMNR_PORT 5355 /* Standard LLMNR port. */
|
||||
#define ipDNS_PORT 53 /* Standard DNS port. */
|
||||
#define ipDHCP_CLIENT 67
|
||||
#define ipDHCP_SERVER 68
|
||||
#define ipNBNS_PORT 137 /* NetBIOS Name Service. */
|
||||
#define ipNBDGM_PORT 138 /* Datagram Service, not included. */
|
||||
|
||||
/* 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;
|
||||
|
||||
#if ( ipconfigUSE_LLMNR == 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 ) */
|
||||
|
||||
#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 */,
|
||||
uint32_t /* ulIPAddress */ );
|
||||
/** @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. */
|
||||
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 */
|
||||
size_t uxPayloadSize; /**< Total buffer size */
|
||||
} DNSBuffer_t;
|
||||
|
||||
#if ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_NBNS == 1 )
|
||||
|
||||
/*
|
||||
* The following function should be provided by the user and return true if it
|
||||
* matches the domain name.
|
||||
*/
|
||||
extern BaseType_t xApplicationDNSQueryHook( const char * pcName );
|
||||
#endif /* ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_NBNS == 1 ) */
|
||||
#endif /* ipconfigUSE_DNS */
|
||||
#endif /* ifndef FREERTOS_DNS_GLOBALS_H */
|
||||
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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_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 );
|
||||
|
||||
BaseType_t DNS_SendRequest( Socket_t xDNSSocket,
|
||||
const struct freertos_sockaddr * xAddress,
|
||||
const struct xDNSBuffer * pxDNSBuf );
|
||||
|
||||
void DNS_ReadReply( const ConstSocket_t xDNSSocket,
|
||||
struct freertos_sockaddr * xAddress,
|
||||
struct xDNSBuffer * pxReceiveBuffer );
|
||||
|
||||
void DNS_CloseSocket( Socket_t xDNSSocket );
|
||||
#endif /* if ( ipconfigUSE_DNS != 0 ) */
|
||||
#endif /* ifndef FREERTOS_DNS_NETWORKING_H */
|
||||
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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>
|
||||
#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( const uint8_t * pucByte,
|
||||
size_t uxRemainingBytes,
|
||||
char * pcName,
|
||||
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,
|
||||
BaseType_t xExpected );
|
||||
|
||||
/*
|
||||
* The NBNS and the LLMNR protocol share this reply function.
|
||||
*/
|
||||
#if ( ( ipconfigUSE_NBNS == 1 ) || ( ipconfigUSE_LLMNR == 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
|
||||
|
||||
uint32_t parseDNSAnswer( const DNSMessage_t * pxDNSMessageHeader,
|
||||
uint8_t * pucByte,
|
||||
size_t uxSourceBytesRemaining,
|
||||
size_t * uxBytesRead
|
||||
#if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 )
|
||||
,
|
||||
const char * pcName,
|
||||
BaseType_t xDoStore
|
||||
#endif
|
||||
);
|
||||
#endif /* if ( ipconfigUSE_DNS != 0 ) */
|
||||
#endif /* ifndef FREERTOS_DNS_PARSER_H */
|
||||
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* 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_ARP.h"
|
||||
#include "FreeRTOS_UDP_IP.h"
|
||||
#include "FreeRTOS_DHCP.h"
|
||||
#include "NetworkInterface.h"
|
||||
#include "NetworkBufferManagement.h"
|
||||
#include "FreeRTOS_DNS.h"
|
||||
|
||||
/* ICMP protocol definitions. */
|
||||
#define ipICMP_ECHO_REQUEST ( ( uint8_t ) 8 ) /**< ICMP echo request. */
|
||||
#define ipICMP_ECHO_REPLY ( ( uint8_t ) 0 ) /**< ICMP echo reply. */
|
||||
|
||||
#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,456 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* Application level configuration options. */
|
||||
#include "FreeRTOSIPConfig.h"
|
||||
#include "FreeRTOSIPConfigDefaults.h"
|
||||
#include "IPTraceMacroDefaults.h"
|
||||
|
||||
/* Constants defining the current version of the FreeRTOS+TCP
|
||||
* network stack. */
|
||||
#define ipFR_TCP_VERSION_NUMBER "V3.1.0"
|
||||
#define ipFR_TCP_VERSION_MAJOR 3
|
||||
#define ipFR_TCP_VERSION_MINOR 1
|
||||
/* Development builds are always version 999. */
|
||||
#define ipFR_TCP_VERSION_BUILD 0
|
||||
|
||||
/* 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_IPv4_HEADER 20U
|
||||
#define ipSIZE_OF_IGMP_HEADER 8U
|
||||
#define ipSIZE_OF_ICMP_HEADER 8U
|
||||
#define ipSIZE_OF_UDP_HEADER 8U
|
||||
#define ipSIZE_OF_TCP_HEADER 20U
|
||||
|
||||
#define ipSIZE_OF_IPv4_ADDRESS 4U
|
||||
|
||||
/*
|
||||
* Generate a randomized TCP Initial Sequence Number per RFC.
|
||||
* This function must be provided by the application builder.
|
||||
*/
|
||||
/* This function is defined generally by the application. */
|
||||
extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
|
||||
uint16_t usSourcePort,
|
||||
uint32_t ulDestinationAddress,
|
||||
uint16_t usDestinationPort );
|
||||
|
||||
/* The number of octets in the MAC and IP addresses respectively. */
|
||||
#define ipMAC_ADDRESS_LENGTH_BYTES ( 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 alignment of network packets, an offset of 2 bytes
|
||||
* would be desirable, as defined by ipconfigPACKET_FILLER_SIZE. So the malloc'd
|
||||
* buffer will have the following contents:
|
||||
* uint32_t pointer; // word-aligned
|
||||
* uchar_8 filler[6];
|
||||
* << ETH-header >> // half-word-aligned
|
||||
* uchar_8 dest[6]; // start of pucEthernetBuffer
|
||||
* uchar_8 dest[6];
|
||||
* uchar16_t type;
|
||||
* << IP-header >> // word-aligned
|
||||
* uint8_t ucVersionHeaderLength;
|
||||
* etc
|
||||
*/
|
||||
|
||||
#if ( ipconfigBUFFER_PADDING != 0 )
|
||||
#define ipBUFFER_PADDING ipconfigBUFFER_PADDING
|
||||
#else
|
||||
#define ipBUFFER_PADDING ( 8U + ipconfigPACKET_FILLER_SIZE )
|
||||
#endif
|
||||
|
||||
/* The offset of ucTCPFlags within the TCP header. */
|
||||
#define ipTCP_FLAGS_OFFSET 13U
|
||||
|
||||
#define ipFIRST_LOOPBACK_IPv4 0x7F000000UL /**< Lowest IPv4 loopback address (including). */
|
||||
#define ipLAST_LOOPBACK_IPv4 0x80000000UL /**< Highest IPv4 loopback address (excluding). */
|
||||
|
||||
/** @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
|
||||
|
||||
/** @brief The maximum time the IP task is allowed to remain in the Blocked state if no
|
||||
* events are posted to the network event queue. */
|
||||
#ifndef ipconfigMAX_IP_TASK_SLEEP_TIME
|
||||
#define ipconfigMAX_IP_TASK_SLEEP_TIME ( pdMS_TO_TICKS( 10000UL ) )
|
||||
#endif
|
||||
|
||||
/* 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. */
|
||||
uint32_t ulIPAddress; /**< 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. */
|
||||
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
|
||||
} 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 )
|
||||
|
||||
/* 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 );
|
||||
|
||||
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
|
||||
/* Temporary solution: eventually the defines below will appear in 'Source\include\projdefs.h' */
|
||||
#define pdTRUE_SIGNED pdTRUE
|
||||
#define pdFALSE_SIGNED pdFALSE
|
||||
#define pdTRUE_UNSIGNED ( 1U )
|
||||
#define pdFALSE_UNSIGNED ( 0U )
|
||||
#define ipTRUE_BOOL ( 1 == 1 )
|
||||
#define ipFALSE_BOOL ( 1 == 2 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* FULL, UP-TO-DATE AND MAINTAINED REFERENCE DOCUMENTATION FOR ALL THESE
|
||||
* FUNCTIONS IS AVAILABLE ON THE FOLLOWING URL:
|
||||
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FreeRTOS_TCP_API_Functions.html
|
||||
*/
|
||||
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 ] );
|
||||
|
||||
TaskHandle_t FreeRTOS_GetIPTaskHandle( void );
|
||||
|
||||
void * FreeRTOS_GetUDPPayloadBuffer( size_t uxRequestedSizeBytes,
|
||||
TickType_t uxBlockTimeTicks );
|
||||
void FreeRTOS_GetAddressConfiguration( uint32_t * pulIPAddress,
|
||||
uint32_t * pulNetMask,
|
||||
uint32_t * pulGatewayAddress,
|
||||
uint32_t * pulDNSServerAddress );
|
||||
|
||||
void FreeRTOS_SetAddressConfiguration( const uint32_t * pulIPAddress,
|
||||
const uint32_t * pulNetMask,
|
||||
const uint32_t * pulGatewayAddress,
|
||||
const uint32_t * pulDNSServerAddress );
|
||||
|
||||
/* MISRA defining 'FreeRTOS_SendPingRequest' should be dependent on 'ipconfigSUPPORT_OUTGOING_PINGS'.
|
||||
* In order not to break some existing project, define it unconditionally. */
|
||||
BaseType_t FreeRTOS_SendPingRequest( uint32_t ulIPAddress,
|
||||
size_t uxNumberOfBytesToSend,
|
||||
TickType_t uxBlockTimeTicks );
|
||||
|
||||
void FreeRTOS_ReleaseUDPPayloadBuffer( void const * pvBuffer );
|
||||
const uint8_t * FreeRTOS_GetMACAddress( void );
|
||||
void FreeRTOS_UpdateMACAddress( const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] );
|
||||
#if ( ipconfigUSE_NETWORK_EVENT_HOOK == 1 )
|
||||
/* This function shall be defined by the application. */
|
||||
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent );
|
||||
#endif
|
||||
#if ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
|
||||
void vApplicationPingReplyHook( ePingReplyStatus_t eStatus,
|
||||
uint16_t usIdentifier );
|
||||
#endif
|
||||
uint32_t FreeRTOS_GetIPAddress( void );
|
||||
void FreeRTOS_SetIPAddress( uint32_t ulIPAddress );
|
||||
void FreeRTOS_SetNetmask( uint32_t ulNetmask );
|
||||
void FreeRTOS_SetGatewayAddress( uint32_t ulGatewayAddress );
|
||||
uint32_t FreeRTOS_GetGatewayAddress( void );
|
||||
uint32_t FreeRTOS_GetDNSServerAddress( void );
|
||||
uint32_t FreeRTOS_GetNetmask( void );
|
||||
BaseType_t xARPWaitResolution( uint32_t ulIPAddress,
|
||||
TickType_t uxTicksToWait );
|
||||
|
||||
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
|
||||
|
||||
/* _HT_ Temporary: show all valid ARP entries
|
||||
*/
|
||||
#if ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 )
|
||||
void FreeRTOS_PrintARPCache( void );
|
||||
#endif
|
||||
|
||||
void FreeRTOS_ClearARP( void );
|
||||
|
||||
/* Return pdTRUE if the IPv4 address is a multicast address. */
|
||||
BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress );
|
||||
|
||||
/* Set the MAC-address that belongs to a given IPv4 multi-cast address. */
|
||||
void vSetMultiCastIPv4MacAddress( uint32_t ulIPAddress,
|
||||
MACAddress_t * pxMACAddress );
|
||||
|
||||
#if ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
|
||||
|
||||
/* DHCP has an option for clients to register their hostname. It doesn't
|
||||
* have much use, except that a device can be found in a router along with its
|
||||
* name. If this option is used the callback below must be provided by the
|
||||
* application writer to return a const string, denoting the device's name. */
|
||||
/* Typically this function is defined in a user module. */
|
||||
const char * pcApplicationHostnameHook( void );
|
||||
|
||||
#endif /* ipconfigDHCP_REGISTER_HOSTNAME */
|
||||
|
||||
|
||||
/* 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 pointer to buffer with packet waiting for ARP resolution. This variable
|
||||
* is defined in FreeRTOS_IP.c.
|
||||
* This pointer is for internal use only. */
|
||||
extern NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer;
|
||||
|
||||
/* For backward compatibility define old structure names to the newer equivalent
|
||||
* structure name. */
|
||||
#ifndef ipconfigENABLE_BACKWARD_COMPATIBILITY
|
||||
#define ipconfigENABLE_BACKWARD_COMPATIBILITY 1
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#if ( ipconfigUSE_TCP != 0 )
|
||||
|
||||
/** @brief Set to a non-zero value if one or more TCP message have been processed
|
||||
* within the last round. */
|
||||
extern BaseType_t xProcessedTCPMessage;
|
||||
#endif
|
||||
|
||||
#include "FreeRTOS_IP_Utils.h"
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* FREERTOS_IP_H */
|
||||
@ -0,0 +1,857 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* Application level configuration options. */
|
||||
#include "FreeRTOSIPConfig.h"
|
||||
#include "FreeRTOSIPConfigDefaults.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
#include "IPTraceMacroDefaults.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"
|
||||
|
||||
#ifdef TEST
|
||||
int ipFOREVER( void );
|
||||
#else
|
||||
#define ipFOREVER() 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* 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 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 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;
|
||||
|
||||
#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 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;
|
||||
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* Nested protocol packets. */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#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 "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;
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
} ProtocolHeaders_t;
|
||||
|
||||
/* The maximum UDP payload length. */
|
||||
#define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER )
|
||||
|
||||
typedef enum
|
||||
{
|
||||
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. */
|
||||
eWaitingARPResolution /* Frame is awaiting ARP 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. */
|
||||
eStackTxEvent, /* 4: The software stack has queued a packet to transmit. */
|
||||
eDHCPEvent, /* 5: Process the DHCP state machine. */
|
||||
eTCPTimerEvent, /* 6: See if any TCP socket needs attention. */
|
||||
eTCPAcceptEvent, /* 7: Client API FreeRTOS_accept() waiting for client connections. */
|
||||
eTCPNetStat, /* 8: IP-task is asked to produce a netstat listing. */
|
||||
eSocketBindEvent, /* 9: Send a message to the IP-task to bind a socket to a port. */
|
||||
eSocketCloseEvent, /*10: Send a message to the IP-task to close a socket. */
|
||||
eSocketSelectEvent, /*11: Send a message to the IP-task for select(). */
|
||||
eSocketSignalEvent, /*12: A socket must be signalled. */
|
||||
eSocketSetDeleteEvent, /*13: A socket set must be deleted. */
|
||||
} eIPEvent_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;
|
||||
|
||||
#define ipBROADCAST_IP_ADDRESS 0xffffffffU
|
||||
|
||||
/* 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 )
|
||||
|
||||
|
||||
/* The offset into a UDP packet at which the UDP data (payload) starts. */
|
||||
#define ipUDP_PAYLOAD_OFFSET_IPv4 ( sizeof( UDPPacket_t ) )
|
||||
|
||||
/* The offset into an IP packet into which the IP data (payload) starts. */
|
||||
#define ipIP_PAYLOAD_OFFSET ( sizeof( IPPacket_t ) )
|
||||
|
||||
#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;
|
||||
|
||||
/**
|
||||
* Define a default UDP packet header (declared in FreeRTOS_UDP_IP.c)
|
||||
*/
|
||||
typedef union xUDPPacketHeader
|
||||
{
|
||||
uint8_t ucBytes[ 24 ]; /**< Member: 8-bit array */
|
||||
uint32_t ulWords[ 6 ]; /**< Member: 32-bit array */
|
||||
} UDPPacketHeader_t;
|
||||
extern UDPPacketHeader_t xDefaultPartUDPPacketHeader;
|
||||
|
||||
|
||||
/* Structure that stores the netmask, gateway address and DNS server addresses. */
|
||||
extern NetworkAddressingParameters_t xNetworkAddressing;
|
||||
|
||||
/* Structure that stores the defaults for netmask, gateway address and DNS.
|
||||
* These values will be copied to 'xNetworkAddressing' in case DHCP is not used,
|
||||
* and also in case DHCP does not lead to a confirmed request. */
|
||||
/*lint -e9003*/
|
||||
extern NetworkAddressingParameters_t xDefaultAddressing; /*lint !e9003 could define variable 'xDefaultAddressing' at block scope [MISRA 2012 Rule 8.9, advisory]. */
|
||||
|
||||
/* True when BufferAllocation_1.c was included, false for BufferAllocation_2.c */
|
||||
extern const BaseType_t xBufferAllocFixedSize;
|
||||
|
||||
/* Defined in FreeRTOS_Sockets.c */
|
||||
#if ( ipconfigUSE_TCP == 1 )
|
||||
extern List_t xBoundTCPSocketsList;
|
||||
#endif
|
||||
|
||||
/* The local IP address is accessed from within xDefaultPartUDPPacketHeader,
|
||||
* rather than duplicated in its own variable. */
|
||||
#define ipLOCAL_IP_ADDRESS_POINTER ( ( uint32_t * ) &( xDefaultPartUDPPacketHeader.ulWords[ 20U / sizeof( uint32_t ) ] ) )
|
||||
|
||||
/* The local MAC address is accessed from within xDefaultPartUDPPacketHeader,
|
||||
* rather than duplicated in its own variable. */
|
||||
#define ipLOCAL_MAC_ADDRESS ( xDefaultPartUDPPacketHeader.ucBytes )
|
||||
|
||||
/* 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 ) \
|
||||
{ \
|
||||
( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 0 ] = ( uint8_t ) ( ( usValue ) >> 8 ); \
|
||||
( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 1 ] = ( uint8_t ) ( ( usValue ) & 0xffU ); \
|
||||
}
|
||||
|
||||
#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 )
|
||||
|
||||
/* 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( void );
|
||||
BaseType_t FreeRTOS_NetworkDownFromISR( void );
|
||||
|
||||
/*
|
||||
* Processes incoming ARP packets.
|
||||
*/
|
||||
eFrameProcessingResult_t eARPProcessPacket( ARPPacket_t * const pxARPFrame );
|
||||
|
||||
/*
|
||||
* 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. */
|
||||
|
||||
/*
|
||||
* 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 * pxIsWaitingForARPResolution );
|
||||
|
||||
/*
|
||||
* 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 );
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
uint64_t ullAlignmentWord; /**< Increase the alignment of this union by adding a 64-bit variable. */
|
||||
} a; /**< A struct to increase alignment. */
|
||||
struct
|
||||
{
|
||||
/* The next field only serves to give 'ucLastPacket' a correct
|
||||
* alignment of 8 + 2. See comments in FreeRTOS_IP.h */
|
||||
uint8_t ucFillPacket[ ipconfigPACKET_FILLER_SIZE ];
|
||||
uint8_t ucLastPacket[ sizeof( TCPPacket_t ) ];
|
||||
} u; /**< The structure to give an alignment of 8 + 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
|
||||
{
|
||||
uint32_t ulRemoteIP; /**< 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, /**< when true, this socket may be returned in a call to accept() */
|
||||
bPassQueued : 1, /**< when true, this socket is an orphan until it gets connected
|
||||
* Why an orphan? Because it may not be returned in a accept() call until it
|
||||
* gets the state eESTABLISHED */
|
||||
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.
|
||||
*/
|
||||
typedef struct xSOCKET
|
||||
{
|
||||
EventBits_t xEventBits; /**< The eventbits to keep track of events. */
|
||||
EventGroupHandle_t xEventGroup; /**< The event group for this socket. */
|
||||
|
||||
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 */
|
||||
|
||||
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 */
|
||||
/* 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 */
|
||||
|
||||
uint64_t ullTCPAlignment; /**< Make sure that xTCP is 8-bytes aligned by
|
||||
* declaring a 64-bit variable in the same union */
|
||||
#endif /* ipconfigUSE_TCP */
|
||||
} u; /**< Union of TCP/UDP socket */
|
||||
} FreeRTOS_Socket_t;
|
||||
|
||||
#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,
|
||||
uint32_t ulRemoteIP,
|
||||
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 );
|
||||
|
||||
/*
|
||||
* 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 timer. */
|
||||
void vIPNetworkUpCalls( void );
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* FREERTOS_IP_PRIVATE_H */
|
||||
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* 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_ARP.h"
|
||||
#include "FreeRTOS_UDP_IP.h"
|
||||
#include "FreeRTOS_DHCP.h"
|
||||
#include "NetworkInterface.h"
|
||||
#include "NetworkBufferManagement.h"
|
||||
#include "FreeRTOS_DNS.h"
|
||||
|
||||
/*
|
||||
* Checks the ARP, DHCP and TCP timers to see if any periodic or timeout
|
||||
* processing is required.
|
||||
*/
|
||||
void vCheckNetworkTimers( void );
|
||||
|
||||
/*
|
||||
* 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 );
|
||||
|
||||
void vIPTimerStartARPResolution( TickType_t xTime );
|
||||
|
||||
void vIPSetTCPTimerExpiredState( BaseType_t xExpiredState );
|
||||
|
||||
void vIPSetARPTimerEnableState( BaseType_t xEnableState );
|
||||
|
||||
void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState );
|
||||
|
||||
#if ( ipconfigUSE_DHCP != 0 )
|
||||
|
||||
/**
|
||||
* @brief Enable/disable the DHCP timer.
|
||||
* @param[in] xEnableState: pdTRUE - enable timer; pdFALSE - disable timer.
|
||||
*/
|
||||
void vIPSetDHCPTimerEnableState( BaseType_t xEnableState );
|
||||
#endif
|
||||
|
||||
#if ( ipconfigDNS_USE_CALLBACKS != 0 )
|
||||
|
||||
/**
|
||||
* @brief Enable/disable the DNS timer.
|
||||
* @param[in] xEnableState: pdTRUE - enable timer; pdFALSE - disable timer.
|
||||
*/
|
||||
void vIPSetDNSTimerEnableState( BaseType_t xEnableState );
|
||||
#endif
|
||||
|
||||
void vARPTimerReload( TickType_t xTime );
|
||||
void vTCPTimerReload( TickType_t xTime );
|
||||
#if ( ipconfigUSE_DHCP == 1 )
|
||||
void vDHCPTimerReload( TickType_t xLeaseTime );
|
||||
#endif
|
||||
|
||||
#if ( ipconfigDNS_USE_CALLBACKS != 0 )
|
||||
void vDNSTimerReload( uint32_t ulCheckTime );
|
||||
#endif
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* FREERTOS_IP_TIMERS_H */
|
||||
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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_UTILS_H
|
||||
#define FREERTOS_IP_UTILS_H
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/**
|
||||
* @file FreeRTOS_IP_Utils.h
|
||||
* @brief Implements the utility functions for FreeRTOS_IP.c
|
||||
*/
|
||||
|
||||
/* 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_ARP.h"
|
||||
#include "FreeRTOS_UDP_IP.h"
|
||||
#include "FreeRTOS_DHCP.h"
|
||||
#include "NetworkInterface.h"
|
||||
#include "NetworkBufferManagement.h"
|
||||
#include "FreeRTOS_DNS.h"
|
||||
|
||||
#if ( ipconfigUSE_DHCP != 0 )
|
||||
|
||||
/**
|
||||
* @brief Create a DHCP event.
|
||||
*
|
||||
* @return pdPASS or pdFAIL, depending on whether xSendEventStructToIPTask()
|
||||
* succeeded.
|
||||
*/
|
||||
BaseType_t xSendDHCPEvent( void );
|
||||
#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( void );
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* FREERTOS_IP_UTILS_H */
|
||||
@ -0,0 +1,551 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
|
||||
/* Event bit definitions are required by the select functions. */
|
||||
#include "event_groups.h"
|
||||
|
||||
#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 )
|
||||
|
||||
/* 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
|
||||
|
||||
#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
|
||||
{
|
||||
/* _HT_ On 32- and 64-bit architectures, the addition of the two uint8_t
|
||||
* fields sin_len and sin_family doesn't make the structure bigger, due to alignment.
|
||||
* These fields are only inserted as a preparation for IPv6
|
||||
* and are not used in the IPv4-only release. */
|
||||
uint8_t sin_len; /**< length of this structure. */
|
||||
uint8_t sin_family; /**< FREERTOS_AF_INET. */
|
||||
uint16_t sin_port; /**< The port. */
|
||||
uint32_t sin_addr; /**< The IP address. */
|
||||
};
|
||||
|
||||
/* 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:
|
||||
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FreeRTOS_TCP_API_Functions.html
|
||||
*/
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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,
|
||||
const 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 );
|
||||
|
||||
#if ( ipconfigUSE_TCP == 1 )
|
||||
|
||||
/* 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 );
|
||||
#endif /* ( ipconfigUSE_TCP == 1 ) */
|
||||
|
||||
/* 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 circular transmit buffer.
|
||||
* '*pxLength' will contain the number of bytes that may be written. */
|
||||
uint8_t * FreeRTOS_get_tx_head( ConstSocket_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 ) ) << 24UL ) | \
|
||||
( ( ( uint32_t ) ( ucOctet2 ) ) << 16UL ) | \
|
||||
( ( ( uint32_t ) ( ucOctet1 ) ) << 8UL ) | \
|
||||
( ( uint32_t ) ( ucOctet0 ) ) )
|
||||
|
||||
#else /* ( ipconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN ) */
|
||||
|
||||
#define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \
|
||||
( ( ( ( uint32_t ) ( ucOctet0 ) ) << 24UL ) | \
|
||||
( ( ( uint32_t ) ( ucOctet1 ) ) << 16UL ) | \
|
||||
( ( ( uint32_t ) ( ucOctet2 ) ) << 8UL ) | \
|
||||
( ( 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 );
|
||||
|
||||
BaseType_t FreeRTOS_inet_pton4( const char * pcSource,
|
||||
void * pvDestination );
|
||||
|
||||
const char * FreeRTOS_inet_ntop4( 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 ) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* FREERTOS_SOCKETS_H */
|
||||
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
*
|
||||
* 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_STREAM_BUFFER_H
|
||||
#define FREERTOS_STREAM_BUFFER_H
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/**
|
||||
* structure 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;
|
||||
|
||||
void vStreamBufferClear( StreamBuffer_t * pxBuffer );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
size_t uxStreamBufferSpace( const StreamBuffer_t * pxBuffer,
|
||||
const size_t uxLower,
|
||||
const size_t uxUpper );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
size_t uxStreamBufferDistance( const StreamBuffer_t * pxBuffer,
|
||||
const size_t uxLower,
|
||||
const size_t uxUpper );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
size_t uxStreamBufferGetSpace( const StreamBuffer_t * pxBuffer );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
size_t uxStreamBufferFrontSpace( const StreamBuffer_t * pxBuffer );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
size_t uxStreamBufferGetSize( const StreamBuffer_t * pxBuffer );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
size_t uxStreamBufferMidSpace( const StreamBuffer_t * pxBuffer );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStreamBufferMoveMid( StreamBuffer_t * pxBuffer,
|
||||
size_t uxCount );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xStreamBufferLessThenEqual( const StreamBuffer_t * pxBuffer,
|
||||
const size_t uxLeft,
|
||||
const size_t uxRight );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
size_t uxStreamBufferGetPtr( StreamBuffer_t * pxBuffer,
|
||||
uint8_t ** ppucData );
|
||||
|
||||
/*
|
||||
* Add bytes to a stream buffer.
|
||||
*
|
||||
* pxBuffer - The buffer to which the bytes will be added.
|
||||
* uxOffset - If uxOffset > 0, data will be written at an offset from uxHead
|
||||
* while uxHead will not be moved yet.
|
||||
* pucData - A pointer to the data to be added.
|
||||
* uxCount - The number of bytes to add.
|
||||
*/
|
||||
size_t uxStreamBufferAdd( StreamBuffer_t * pxBuffer,
|
||||
size_t uxOffset,
|
||||
const uint8_t * pucData,
|
||||
size_t uxByteCount );
|
||||
|
||||
/*
|
||||
* Read bytes from a stream buffer.
|
||||
*
|
||||
* pxBuffer - The buffer from which the bytes will be read.
|
||||
* uxOffset - Can be used to read data located at a certain offset from 'uxTail'.
|
||||
* pucData - A pointer to the buffer into which data will be read.
|
||||
* uxMaxCount - The number of bytes to read.
|
||||
* xPeek - If set to pdTRUE the data will remain in the buffer.
|
||||
*/
|
||||
size_t uxStreamBufferGet( StreamBuffer_t * pxBuffer,
|
||||
size_t uxOffset,
|
||||
uint8_t * pucData,
|
||||
size_t uxMaxCount,
|
||||
BaseType_t xPeek );
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* !defined( FREERTOS_STREAM_BUFFER_H ) */
|
||||
@ -0,0 +1,175 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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* */
|
||||
|
||||
BaseType_t xProcessReceivedTCPPacket( 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_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
|
||||
|
||||
/* Two macro's that were introduced to work with both IPv4 and IPv6. */
|
||||
#define xIPHeaderSize( pxNetworkBuffer ) ( ipSIZE_OF_IPv4_HEADER ) /**< Size of IP Header. */
|
||||
#define uxIPHeaderSizeSocket( pxSocket ) ( ipSIZE_OF_IPv4_HEADER ) /**< Size of IP Header socket. */
|
||||
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* FREERTOS_TCP_IP_H */
|
||||
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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,74 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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 );
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* FREERTOS_TCP_STATE_HANDLING_H */
|
||||
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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 );
|
||||
|
||||
/*
|
||||
* Initialise the data structures which keep track of the TCP windowing system.
|
||||
*/
|
||||
void 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 );
|
||||
|
||||
/*
|
||||
* 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,56 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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 );
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* FREERTOS_TCP_UTILS_H */
|
||||
@ -0,0 +1,258 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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 */
|
||||
void vTCPWindowCreate( 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,55 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* Application level configuration options. */
|
||||
#include "FreeRTOSIPConfig.h"
|
||||
#include "FreeRTOSIPConfigDefaults.h"
|
||||
#include "IPTraceMacroDefaults.h"
|
||||
#include "FreeRTOS_IP.h"
|
||||
|
||||
/*
|
||||
* Called when the application has generated a UDP packet to send.
|
||||
*/
|
||||
void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
|
||||
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* FREERTOS_UDP_IP_H */
|
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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_ERRNO_TCP
|
||||
#define FREERTOS_ERRNO_TCP
|
||||
|
||||
/* The following definitions will be included in the core FreeRTOS code in
|
||||
* future versions of FreeRTOS - hence the 'pd' (ProjDefs) prefix - at which time
|
||||
* this file will be removed. */
|
||||
|
||||
/* The following errno values are used by FreeRTOS+ components, not FreeRTOS
|
||||
* itself. */
|
||||
|
||||
/* For future compatibility (see comment above), check the definitions have not
|
||||
* already been made. */
|
||||
#ifndef pdFREERTOS_ERRNO_NONE
|
||||
#define pdFREERTOS_ERRNO_NONE 0 /* No errors */
|
||||
#define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */
|
||||
#define pdFREERTOS_ERRNO_EINTR 4 /* Interrupted system call */
|
||||
#define pdFREERTOS_ERRNO_EIO 5 /* I/O error */
|
||||
#define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */
|
||||
#define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */
|
||||
#define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */
|
||||
#define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */
|
||||
#define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */
|
||||
#define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */
|
||||
#define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */
|
||||
#define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */
|
||||
#define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */
|
||||
#define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */
|
||||
#define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */
|
||||
#define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */
|
||||
#define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */
|
||||
#define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */
|
||||
#define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */
|
||||
#define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */
|
||||
#define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */
|
||||
#define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */
|
||||
#define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */
|
||||
#define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */
|
||||
#define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */
|
||||
#define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */
|
||||
#define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */
|
||||
#define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
||||
#define pdFREERTOS_ERRNO_EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
||||
#define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */
|
||||
#define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */
|
||||
#define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */
|
||||
#define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */
|
||||
#define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */
|
||||
#define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */
|
||||
#define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */
|
||||
#define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */
|
||||
#define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */
|
||||
#define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */
|
||||
#define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */
|
||||
#define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */
|
||||
|
||||
/* The following endian values are used by FreeRTOS+ components, not FreeRTOS
|
||||
* itself. */
|
||||
#define pdFREERTOS_LITTLE_ENDIAN 0
|
||||
#define pdFREERTOS_BIG_ENDIAN 1
|
||||
#else /* ifndef pdFREERTOS_ERRNO_NONE */
|
||||
#ifndef pdFREERTOS_ERRNO_EAFNOSUPPORT
|
||||
#define pdFREERTOS_ERRNO_EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
||||
#endif /* pdFREERTOS_ERRNO_EAFNOSUPPORT */
|
||||
#endif /* pdFREERTOS_ERRNO_NONE */
|
||||
|
||||
/* Translate a pdFREERTOS_ERRNO code to a human readable string. */
|
||||
const char * FreeRTOS_strerror_r( BaseType_t xErrnum,
|
||||
char * pcBuffer,
|
||||
size_t uxLength );
|
||||
|
||||
#endif /* FREERTOS_ERRNO_TCP */
|
||||
@ -0,0 +1,277 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* This file provides default (empty) implementations for any IP trace macros
|
||||
* that are not defined by the user. See
|
||||
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Trace.html */
|
||||
|
||||
#ifndef UDP_TRACE_MACRO_DEFAULTS_H
|
||||
#define UDP_TRACE_MACRO_DEFAULTS_H
|
||||
|
||||
#ifndef iptraceNETWORK_DOWN
|
||||
#define iptraceNETWORK_DOWN()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceNETWORK_BUFFER_RELEASED
|
||||
#define iptraceNETWORK_BUFFER_RELEASED( pxBufferAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceNETWORK_BUFFER_OBTAINED
|
||||
#define iptraceNETWORK_BUFFER_OBTAINED( pxBufferAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR
|
||||
#define iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR( pxBufferAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceNETWORK_INTERFACE_INPUT
|
||||
/* An Ethernet packet has been received. */
|
||||
#define iptraceNETWORK_INTERFACE_INPUT( uxDataLength, pucEthernetBuffer )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceNETWORK_INTERFACE_OUTPUT
|
||||
/* An Ethernet packet will be sent. */
|
||||
#define iptraceNETWORK_INTERFACE_OUTPUT( uxDataLength, pucEthernetBuffer )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER
|
||||
#define iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER_FROM_ISR
|
||||
#define iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER_FROM_ISR()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceDROPPED_INVALID_ARP_PACKET
|
||||
#define iptraceDROPPED_INVALID_ARP_PACKET( pxARPHeader )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceCREATING_ARP_REQUEST
|
||||
#define iptraceCREATING_ARP_REQUEST( ulIPAddress )
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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
|
||||
|
||||
#ifndef iptraceARP_TABLE_ENTRY_WILL_EXPIRE
|
||||
#define iptraceARP_TABLE_ENTRY_WILL_EXPIRE( ulIPAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceARP_TABLE_ENTRY_EXPIRED
|
||||
#define iptraceARP_TABLE_ENTRY_EXPIRED( ulIPAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceARP_TABLE_ENTRY_CREATED
|
||||
#define iptraceARP_TABLE_ENTRY_CREATED( ulIPAddress, ucMACAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceSENDING_UDP_PACKET
|
||||
#define iptraceSENDING_UDP_PACKET( ulIPAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptracePACKET_DROPPED_TO_GENERATE_ARP
|
||||
#define iptracePACKET_DROPPED_TO_GENERATE_ARP( ulIPAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceICMP_PACKET_RECEIVED
|
||||
#define iptraceICMP_PACKET_RECEIVED()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceSENDING_PING_REPLY
|
||||
#define iptraceSENDING_PING_REPLY( ulIPAddress )
|
||||
#endif
|
||||
|
||||
#ifndef traceARP_PACKET_RECEIVED
|
||||
#define traceARP_PACKET_RECEIVED()
|
||||
#endif
|
||||
|
||||
#ifndef iptracePROCESSING_RECEIVED_ARP_REPLY
|
||||
#define iptracePROCESSING_RECEIVED_ARP_REPLY( ulIPAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceSENDING_ARP_REPLY
|
||||
#define iptraceSENDING_ARP_REPLY( ulIPAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceFAILED_TO_CREATE_SOCKET
|
||||
#define iptraceFAILED_TO_CREATE_SOCKET()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceFAILED_TO_CREATE_EVENT_GROUP
|
||||
#define iptraceFAILED_TO_CREATE_EVENT_GROUP()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceRECVFROM_DISCARDING_BYTES
|
||||
#define iptraceRECVFROM_DISCARDING_BYTES( xNumberOfBytesDiscarded )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceETHERNET_RX_EVENT_LOST
|
||||
#define iptraceETHERNET_RX_EVENT_LOST()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceSTACK_TX_EVENT_LOST
|
||||
#define iptraceSTACK_TX_EVENT_LOST( xEvent )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceNETWORK_EVENT_RECEIVED
|
||||
#define iptraceNETWORK_EVENT_RECEIVED( eEvent )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceBIND_FAILED
|
||||
#define iptraceBIND_FAILED( xSocket, usPort )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS
|
||||
#define iptraceDHCP_REQUESTS_FAILED_USING_DEFAULT_IP_ADDRESS( ulIPAddress )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceSENDING_DHCP_DISCOVER
|
||||
#define iptraceSENDING_DHCP_DISCOVER()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceSENDING_DHCP_REQUEST
|
||||
#define iptraceSENDING_DHCP_REQUEST()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceDHCP_SUCCEDEED
|
||||
#define iptraceDHCP_SUCCEDEED( address )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceNETWORK_INTERFACE_TRANSMIT
|
||||
#define iptraceNETWORK_INTERFACE_TRANSMIT()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceNETWORK_INTERFACE_RECEIVE
|
||||
#define iptraceNETWORK_INTERFACE_RECEIVE()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceSENDING_DNS_REQUEST
|
||||
#define iptraceSENDING_DNS_REQUEST()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceWAITING_FOR_TX_DMA_DESCRIPTOR
|
||||
#define iptraceWAITING_FOR_TX_DMA_DESCRIPTOR()
|
||||
#endif
|
||||
|
||||
#ifndef ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS
|
||||
#define ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS 0
|
||||
#endif
|
||||
|
||||
#ifndef iptraceFAILED_TO_NOTIFY_SELECT_GROUP
|
||||
#define iptraceFAILED_TO_NOTIFY_SELECT_GROUP( xSocket )
|
||||
#endif
|
||||
|
||||
#ifndef pvPortMallocSocket
|
||||
#define pvPortMallocSocket( xSize ) pvPortMalloc( ( xSize ) )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceRECVFROM_TIMEOUT
|
||||
#define iptraceRECVFROM_TIMEOUT()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceRECVFROM_INTERRUPTED
|
||||
#define iptraceRECVFROM_INTERRUPTED()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceNO_BUFFER_FOR_SENDTO
|
||||
#define iptraceNO_BUFFER_FOR_SENDTO()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceSENDTO_SOCKET_NOT_BOUND
|
||||
#define iptraceSENDTO_SOCKET_NOT_BOUND()
|
||||
#endif
|
||||
|
||||
#ifndef iptraceSENDTO_DATA_TOO_LONG
|
||||
#define iptraceSENDTO_DATA_TOO_LONG()
|
||||
#endif
|
||||
|
||||
#ifndef ipconfigUSE_TCP_MEM_STATS
|
||||
#define ipconfigUSE_TCP_MEM_STATS 0
|
||||
#endif
|
||||
|
||||
#if ( ipconfigUSE_TCP_MEM_STATS == 0 )
|
||||
|
||||
/* See tools/tcp_mem_stat.c */
|
||||
|
||||
#ifndef iptraceMEM_STATS_CREATE
|
||||
#define iptraceMEM_STATS_CREATE( xMemType, pxObject, uxSize )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceMEM_STATS_DELETE
|
||||
#define iptraceMEM_STATS_DELETE( pxObject )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceMEM_STATS_CLOSE
|
||||
#define iptraceMEM_STATS_CLOSE()
|
||||
#endif
|
||||
|
||||
#endif /* ( ipconfigUSE_TCP_MEM_STATS != 0 ) */
|
||||
|
||||
#ifndef ipconfigUSE_DUMP_PACKETS
|
||||
#define ipconfigUSE_DUMP_PACKETS 0
|
||||
#endif
|
||||
|
||||
#if ( ipconfigUSE_DUMP_PACKETS == 0 )
|
||||
|
||||
/* See tools/tcp_dump_packets.c */
|
||||
|
||||
#ifndef iptraceDUMP_INIT
|
||||
#define iptraceDUMP_INIT( pcFileName, pxEntries )
|
||||
#endif
|
||||
|
||||
#ifndef iptraceDUMP_PACKET
|
||||
#define iptraceDUMP_PACKET( pucBuffer, uxLength, xIncoming )
|
||||
#endif
|
||||
|
||||
#endif /* ( ipconfigUSE_DUMP_PACKETS != 0 ) */
|
||||
|
||||
#endif /* UDP_TRACE_MACRO_DEFAULTS_H */
|
||||
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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* */
|
||||
|
||||
/* 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,54 @@
|
||||
/*
|
||||
* FreeRTOS+TCP V3.1.0
|
||||
* 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* */
|
||||
|
||||
/* INTERNAL API FUNCTIONS. */
|
||||
BaseType_t xNetworkInterfaceInitialise( void );
|
||||
BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer,
|
||||
BaseType_t xReleaseAfterSend );
|
||||
|
||||
/* The following function is defined only when BufferAllocation_1.c is linked in the project. */
|
||||
void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] );
|
||||
|
||||
/* The following function is defined only when BufferAllocation_1.c is linked in the project. */
|
||||
BaseType_t xGetPhyLinkStatus( void );
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* NETWORK_INTERFACE_H */
|
||||
Reference in New Issue
Block a user