]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h
Added +TCP code to main repo.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / include / FreeRTOS_IP.h
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP.h
new file mode 100644 (file)
index 0000000..59311c4
--- /dev/null
@@ -0,0 +1,350 @@
+/*\r
+ * FreeRTOS+TCP Labs Build 160919 (C) 2016 Real Time Engineers ltd.\r
+ * Authors include Hein Tibosch and Richard Barry\r
+ *\r
+ *******************************************************************************\r
+ ***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***\r
+ ***                                                                         ***\r
+ ***                                                                         ***\r
+ ***   FREERTOS+TCP IS STILL IN THE LAB (mainly because the FTP and HTTP     ***\r
+ ***   demos have a dependency on FreeRTOS+FAT, which is only in the Labs    ***\r
+ ***   download):                                                            ***\r
+ ***                                                                         ***\r
+ ***   FreeRTOS+TCP is functional and has been used in commercial products   ***\r
+ ***   for some time.  Be aware however that we are still refining its       ***\r
+ ***   design, the source code does not yet quite conform to the strict      ***\r
+ ***   coding and style standards mandated by Real Time Engineers ltd., and  ***\r
+ ***   the documentation and testing is not necessarily complete.            ***\r
+ ***                                                                         ***\r
+ ***   PLEASE REPORT EXPERIENCES USING THE SUPPORT RESOURCES FOUND ON THE    ***\r
+ ***   URL: http://www.FreeRTOS.org/contact  Active early adopters may, at   ***\r
+ ***   the sole discretion of Real Time Engineers Ltd., be offered versions  ***\r
+ ***   under a license other than that described below.                      ***\r
+ ***                                                                         ***\r
+ ***                                                                         ***\r
+ ***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***\r
+ *******************************************************************************\r
+ *\r
+ * FreeRTOS+TCP can be used under two different free open source licenses.  The\r
+ * license that applies is dependent on the processor on which FreeRTOS+TCP is\r
+ * executed, as follows:\r
+ *\r
+ * If FreeRTOS+TCP is executed on one of the processors listed under the Special\r
+ * License Arrangements heading of the FreeRTOS+TCP license information web\r
+ * page, then it can be used under the terms of the FreeRTOS Open Source\r
+ * License.  If FreeRTOS+TCP is used on any other processor, then it can be used\r
+ * under the terms of the GNU General Public License V2.  Links to the relevant\r
+ * licenses follow:\r
+ *\r
+ * The FreeRTOS+TCP License Information Page: http://www.FreeRTOS.org/tcp_license\r
+ * The FreeRTOS Open Source License: http://www.FreeRTOS.org/license\r
+ * The GNU General Public License Version 2: http://www.FreeRTOS.org/gpl-2.0.txt\r
+ *\r
+ * FreeRTOS+TCP is distributed in the hope that it will be useful.  You cannot\r
+ * use FreeRTOS+TCP unless you agree that you use the software 'as is'.\r
+ * FreeRTOS+TCP is provided WITHOUT ANY WARRANTY; without even the implied\r
+ * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR\r
+ * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they\r
+ * implied, expressed, or statutory.\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://www.FreeRTOS.org/plus\r
+ * http://www.FreeRTOS.org/labs\r
+ *\r
+ */\r
+\r
+#ifndef FREERTOS_IP_H\r
+#define FREERTOS_IP_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Application level configuration options. */\r
+#include "FreeRTOSIPConfig.h"\r
+#include "FreeRTOSIPConfigDefaults.h"\r
+#include "IPTraceMacroDefaults.h"\r
+\r
+/* Some constants defining the sizes of several parts of a packet */\r
+#define ipSIZE_OF_ETH_HEADER                   14u\r
+#define ipSIZE_OF_IPv4_HEADER                  20u\r
+#define ipSIZE_OF_IGMP_HEADER                  8u\r
+#define ipSIZE_OF_ICMP_HEADER                  8u\r
+#define ipSIZE_OF_UDP_HEADER                   8u\r
+#define ipSIZE_OF_TCP_HEADER                   20u\r
+\r
+\r
+/* The number of octets in the MAC and IP addresses respectively. */\r
+#define ipMAC_ADDRESS_LENGTH_BYTES ( 6 )\r
+#define ipIP_ADDRESS_LENGTH_BYTES ( 4 )\r
+\r
+/* IP protocol definitions. */\r
+#define ipPROTOCOL_ICMP                        ( 1 )\r
+#define ipPROTOCOL_IGMP         ( 2 )\r
+#define ipPROTOCOL_TCP                 ( 6 )\r
+#define ipPROTOCOL_UDP                 ( 17 )\r
+\r
+/* Dimensions the buffers that are filled by received Ethernet frames. */\r
+#define ipSIZE_OF_ETH_CRC_BYTES                                        ( 4UL )\r
+#define ipSIZE_OF_ETH_OPTIONAL_802_1Q_TAG_BYTES        ( 4UL )\r
+#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 )\r
+\r
+/*_RB_ Comment may need updating. */\r
+/* Space left at the beginning of a network buffer storage area to store a\r
+pointer back to the network buffer.  Should be a multiple of 8 to ensure 8 byte\r
+alignment is maintained on architectures that require it.\r
+\r
+In order to get a 32-bit alignment of network packets, an offset of 2 bytes\r
+would be desirable, as defined by ipconfigPACKET_FILLER_SIZE.  So the malloc'd\r
+buffer will have the following contents:\r
+       uint32_t pointer;       // word-aligned\r
+       uchar_8 filler[6];\r
+       << ETH-header >>        // half-word-aligned\r
+       uchar_8 dest[6];    // start of pucEthernetBuffer\r
+       uchar_8 dest[6];\r
+       uchar16_t type;\r
+       << IP-header >>         // word-aligned\r
+       uint8_t ucVersionHeaderLength;\r
+       etc\r
+ */\r
+#if( ipconfigBUFFER_PADDING != 0 )\r
+    #define ipBUFFER_PADDING    ipconfigBUFFER_PADDING\r
+#else\r
+    #define ipBUFFER_PADDING    ( 8u + ipconfigPACKET_FILLER_SIZE )\r
+#endif\r
+\r
+/* The structure used to store buffers and pass them around the network stack.\r
+Buffers can be in use by the stack, in use by the network interface hardware\r
+driver, or free (not in use). */\r
+typedef struct xNETWORK_BUFFER\r
+{\r
+       ListItem_t xBufferListItem;     /* Used to reference the buffer form the free buffer list or a socket. */\r
+       uint32_t ulIPAddress;                   /* Source or destination IP address, depending on usage scenario. */\r
+       uint8_t *pucEthernetBuffer;     /* Pointer to the start of the Ethernet frame. */\r
+       size_t xDataLength;                     /* Starts by holding the total Ethernet frame length, then the UDP/TCP payload length. */\r
+       uint16_t usPort;                                /* Source or destination port, depending on usage scenario. */\r
+       uint16_t usBoundPort;                   /* The port to which a transmitting socket is bound. */\r
+       #if( ipconfigUSE_LINKED_RX_MESSAGES != 0 )\r
+               struct xNETWORK_BUFFER *pxNextBuffer; /* Possible optimisation for expert users - requires network driver support. */\r
+       #endif\r
+} NetworkBufferDescriptor_t;\r
+\r
+#include "pack_struct_start.h"\r
+struct xMAC_ADDRESS\r
+{\r
+       uint8_t ucBytes[ ipMAC_ADDRESS_LENGTH_BYTES ];\r
+}\r
+#include "pack_struct_end.h"\r
+\r
+typedef struct xMAC_ADDRESS MACAddress_t;\r
+\r
+typedef enum eNETWORK_EVENTS\r
+{\r
+       eNetworkUp,             /* The network is configured. */\r
+       eNetworkDown    /* The network connection has been lost. */\r
+} eIPCallbackEvent_t;\r
+\r
+typedef enum ePING_REPLY_STATUS\r
+{\r
+       eSuccess = 0,           /* A correct reply has been received for an outgoing ping. */\r
+       eInvalidChecksum,       /* A reply was received for an outgoing ping but the checksum of the reply was incorrect. */\r
+       eInvalidData            /* A reply was received to an outgoing ping but the payload of the reply was not correct. */\r
+} ePingReplyStatus_t;\r
+\r
+/* Endian related definitions. */\r
+#if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )\r
+\r
+       /* FreeRTOS_htons / FreeRTOS_htonl: some platforms might have built-in versions\r
+       using a single instruction so allow these versions to be overridden. */\r
+       #ifndef FreeRTOS_htons\r
+               #define FreeRTOS_htons( usIn ) ( (uint16_t) ( ( ( usIn ) << 8U ) | ( ( usIn ) >> 8U ) ) )\r
+       #endif\r
+\r
+       #ifndef FreeRTOS_htonl\r
+               #define FreeRTOS_htonl( ulIn )                                                                                  \\r
+                       (                                                                                                                                       \\r
+                               ( uint32_t )                                                                                                    \\r
+                               (                                                                                                                               \\r
+                                       ( ( ( ( uint32_t ) ( ulIn ) )                ) << 24  ) |       \\r
+                                       ( ( ( ( uint32_t ) ( ulIn ) ) & 0x0000ff00UL ) <<  8  ) |       \\r
+                                       ( ( ( ( uint32_t ) ( ulIn ) ) & 0x00ff0000UL ) >>  8  ) |       \\r
+                                       ( ( ( ( uint32_t ) ( ulIn ) )                ) >> 24  )         \\r
+                               )                                                                                                                               \\r
+                       )\r
+       #endif\r
+\r
+#else /* ipconfigBYTE_ORDER */\r
+\r
+       #define FreeRTOS_htons( x ) ( ( uint16_t ) ( x ) )\r
+       #define FreeRTOS_htonl( x ) ( ( uint32_t ) ( x ) )\r
+\r
+#endif /* ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN */\r
+\r
+#define FreeRTOS_ntohs( x ) FreeRTOS_htons( x )\r
+#define FreeRTOS_ntohl( x ) FreeRTOS_htonl( x )\r
+\r
+#if( ipconfigHAS_INLINE_FUNCTIONS == 1 )\r
+\r
+       static portINLINE int32_t  FreeRTOS_max_int32  (int32_t  a, int32_t  b);\r
+       static portINLINE uint32_t FreeRTOS_max_uint32 (uint32_t a, uint32_t b);\r
+       static portINLINE int32_t  FreeRTOS_min_int32  (int32_t  a, int32_t  b);\r
+       static portINLINE uint32_t FreeRTOS_min_uint32 (uint32_t a, uint32_t b);\r
+       static portINLINE uint32_t FreeRTOS_round_up   (uint32_t a, uint32_t d);\r
+       static portINLINE uint32_t FreeRTOS_round_down (uint32_t a, uint32_t d);\r
+       static portINLINE BaseType_t  FreeRTOS_min_BaseType  (BaseType_t  a, BaseType_t  b);\r
+       static portINLINE BaseType_t  FreeRTOS_max_BaseType  (BaseType_t  a, BaseType_t  b);\r
+       static portINLINE UBaseType_t FreeRTOS_max_UBaseType (UBaseType_t a, UBaseType_t b);\r
+       static portINLINE UBaseType_t FreeRTOS_min_UBaseType (UBaseType_t a, UBaseType_t  b);\r
+\r
+\r
+       static portINLINE int32_t  FreeRTOS_max_int32  (int32_t  a, int32_t  b) { return a >= b ? a : b; }\r
+       static portINLINE uint32_t FreeRTOS_max_uint32 (uint32_t a, uint32_t b) { return a >= b ? a : b; }\r
+       static portINLINE int32_t  FreeRTOS_min_int32  (int32_t  a, int32_t  b) { return a <= b ? a : b; }\r
+       static portINLINE uint32_t FreeRTOS_min_uint32 (uint32_t a, uint32_t b) { return a <= b ? a : b; }\r
+       static portINLINE uint32_t FreeRTOS_round_up   (uint32_t a, uint32_t d) { return d * ( ( a + d - 1u ) / d ); }\r
+       static portINLINE uint32_t FreeRTOS_round_down (uint32_t a, uint32_t d) { return d * ( a / d ); }\r
+\r
+       static portINLINE BaseType_t  FreeRTOS_max_BaseType  (BaseType_t  a, BaseType_t  b) { return a >= b ? a : b; }\r
+       static portINLINE UBaseType_t FreeRTOS_max_UBaseType (UBaseType_t a, UBaseType_t b) { return a >= b ? a : b; }\r
+       static portINLINE BaseType_t  FreeRTOS_min_BaseType  (BaseType_t  a, BaseType_t  b) { return a <= b ? a : b; }\r
+       static portINLINE UBaseType_t FreeRTOS_min_UBaseType (UBaseType_t  a, UBaseType_t  b) { return a <= b ? a : b; }\r
+\r
+#else\r
+\r
+       #define FreeRTOS_max_int32(a,b)  ( ( ( int32_t  ) ( a ) ) >= ( ( int32_t  ) ( b ) ) ? ( ( int32_t  ) ( a ) ) : ( ( int32_t  ) ( b ) ) )\r
+       #define FreeRTOS_max_uint32(a,b) ( ( ( uint32_t ) ( a ) ) >= ( ( uint32_t ) ( b ) ) ? ( ( uint32_t ) ( a ) ) : ( ( uint32_t ) ( b ) ) )\r
+\r
+       #define FreeRTOS_min_int32(a,b)  ( ( ( int32_t  ) a ) <= ( ( int32_t  ) b ) ? ( ( int32_t  ) a ) : ( ( int32_t  ) b ) )\r
+       #define FreeRTOS_min_uint32(a,b) ( ( ( uint32_t ) a ) <= ( ( uint32_t ) b ) ? ( ( uint32_t ) a ) : ( ( uint32_t ) b ) )\r
+\r
+       /*  Round-up: a = d * ( ( a + d - 1 ) / d ) */\r
+       #define FreeRTOS_round_up(a,d)   ( ( ( uint32_t ) ( d ) ) * ( ( ( ( uint32_t ) ( a ) ) + ( ( uint32_t ) ( d ) ) - 1UL ) / ( ( uint32_t ) ( d ) ) ) )\r
+       #define FreeRTOS_round_down(a,d) ( ( ( uint32_t ) ( d ) ) * ( ( ( uint32_t ) ( a ) ) / ( ( uint32_t ) ( d ) ) ) )\r
+\r
+       #define FreeRTOS_max_BaseType(a, b)  ( ( ( BaseType_t  ) ( a ) ) >= ( ( BaseType_t  ) ( b ) ) ? ( ( BaseType_t  ) ( a ) ) : ( ( BaseType_t  ) ( b ) ) )\r
+       #define FreeRTOS_max_UBaseType(a, b) ( ( ( UBaseType_t ) ( a ) ) >= ( ( UBaseType_t ) ( b ) ) ? ( ( UBaseType_t ) ( a ) ) : ( ( UBaseType_t ) ( b ) ) )\r
+       #define FreeRTOS_min_BaseType(a, b)  ( ( ( BaseType_t  ) ( a ) ) <= ( ( BaseType_t  ) ( b ) ) ? ( ( BaseType_t  ) ( a ) ) : ( ( BaseType_t  ) ( b ) ) )\r
+       #define FreeRTOS_min_UBaseType(a, b) ( ( ( UBaseType_t ) ( a ) ) <= ( ( UBaseType_t ) ( b ) ) ? ( ( UBaseType_t ) ( a ) ) : ( ( UBaseType_t ) ( b ) ) )\r
+\r
+#endif /* ipconfigHAS_INLINE_FUNCTIONS */\r
+\r
+#define pdMS_TO_MIN_TICKS( xTimeInMs ) ( pdMS_TO_TICKS( ( xTimeInMs ) ) < ( ( TickType_t ) 1 ) ? ( ( TickType_t ) 1 ) : pdMS_TO_TICKS( ( xTimeInMs ) ) )\r
+\r
+#ifndef pdTRUE_SIGNED\r
+       /* Temporary solution: eventually the defines below will appear in 'Source\include\projdefs.h' */\r
+       #define pdTRUE_SIGNED           pdTRUE\r
+       #define pdFALSE_SIGNED          pdFALSE\r
+       #define pdTRUE_UNSIGNED         ( ( UBaseType_t ) 1u )\r
+       #define pdFALSE_UNSIGNED        ( ( UBaseType_t ) 0u )\r
+#endif\r
+\r
+/*\r
+ * FULL, UP-TO-DATE AND MAINTAINED REFERENCE DOCUMENTATION FOR ALL THESE\r
+ * FUNCTIONS IS AVAILABLE ON THE FOLLOWING URL:\r
+ * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FreeRTOS_TCP_API_Functions.html\r
+ */\r
+BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ],\r
+       const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ],\r
+       const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ],\r
+       const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ],\r
+       const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] );\r
+\r
+void * FreeRTOS_GetUDPPayloadBuffer( size_t xRequestedSizeBytes, TickType_t xBlockTimeTicks );\r
+void FreeRTOS_GetAddressConfiguration( uint32_t *pulIPAddress, uint32_t *pulNetMask, uint32_t *pulGatewayAddress, uint32_t *pulDNSServerAddress );\r
+void FreeRTOS_SetAddressConfiguration( const uint32_t *pulIPAddress, const uint32_t *pulNetMask, const uint32_t *pulGatewayAddress, const uint32_t *pulDNSServerAddress );\r
+BaseType_t FreeRTOS_SendPingRequest( uint32_t ulIPAddress, size_t xNumberOfBytesToSend, TickType_t xBlockTimeTicks );\r
+void FreeRTOS_ReleaseUDPPayloadBuffer( void *pvBuffer );\r
+const uint8_t * FreeRTOS_GetMACAddress( void );\r
+void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent );\r
+void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier );\r
+uint32_t FreeRTOS_GetIPAddress( void );\r
+void FreeRTOS_SetIPAddress( uint32_t ulIPAddress );\r
+void FreeRTOS_SetNetmask( uint32_t ulNetmask );\r
+void FreeRTOS_SetGatewayAddress( uint32_t ulGatewayAddress );\r
+uint32_t FreeRTOS_GetGatewayAddress( void );\r
+uint32_t FreeRTOS_GetDNSServerAddress( void );\r
+uint32_t FreeRTOS_GetNetmask( void );\r
+void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress );\r
+BaseType_t FreeRTOS_IsNetworkUp( void );\r
+\r
+#if( ipconfigCHECK_IP_QUEUE_SPACE != 0 )\r
+       UBaseType_t uxGetMinimumIPQueueSpace( void );\r
+#endif\r
+\r
+/*\r
+ * Defined in FreeRTOS_Sockets.c\r
+ * //_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_.\r
+ * Socket has had activity, reset the timer so it will not be closed\r
+ * because of inactivity\r
+ */\r
+const char *FreeRTOS_GetTCPStateName( UBaseType_t ulState);\r
+\r
+/* _HT_ Temporary: show all valid ARP entries\r
+ */\r
+void FreeRTOS_PrintARPCache( void );\r
+void FreeRTOS_ClearARP( void );\r
+\r
+#if( ipconfigDHCP_REGISTER_HOSTNAME == 1 )\r
+\r
+       /* DHCP has an option for clients to register their hostname.  It doesn't\r
+       have much use, except that a device can be found in a router along with its\r
+       name. If this option is used the callback below must be provided by the\r
+       application     writer to return a const string, denoting the device's name. */\r
+       const char *pcApplicationHostnameHook( void );\r
+\r
+#endif /* ipconfigDHCP_REGISTER_HOSTNAME */\r
+\r
+\r
+/* For backward compatibility define old structure names to the newer equivalent\r
+structure name. */\r
+#ifndef ipconfigENABLE_BACKWARD_COMPATIBILITY\r
+       #define ipconfigENABLE_BACKWARD_COMPATIBILITY   1\r
+#endif\r
+\r
+#if( ipconfigENABLE_BACKWARD_COMPATIBILITY == 1 )\r
+       #define xIPStackEvent_t                         IPStackEvent_t\r
+       #define xNetworkBufferDescriptor_t      NetworkBufferDescriptor_t\r
+       #define xMACAddress_t                           MACAddress_t\r
+       #define xWinProperties_t                        WinProperties_t\r
+       #define xSocket_t                                       Socket_t\r
+       #define xSocketSet_t                            SocketSet_t\r
+       #define ipSIZE_OF_IP_HEADER                     ipSIZE_OF_IPv4_HEADER\r
+\r
+       /* Since August 2016, the public types and fields below have changed name:\r
+       abbreviations TCP/UDP are now written in capitals, and type names now end with "_t". */\r
+       #define FOnConnected                            FOnConnected_t\r
+       #define FOnTcpReceive                           FOnTCPReceive_t\r
+       #define FOnTcpSent                                      FOnTCPSent_t\r
+       #define FOnUdpReceive                           FOnUDPReceive_t\r
+       #define FOnUdpSent                                      FOnUDPSent_t\r
+\r
+       #define pOnTcpConnected                         pxOnTCPConnected\r
+       #define pOnTcpReceive                           pxOnTCPReceive\r
+       #define pOnTcpSent                                      pxOnTCPSent\r
+       #define pOnUdpReceive                           pxOnUDPReceive\r
+       #define pOnUdpSent                                      pxOnUDPSent\r
+\r
+       #define FOnUdpSent                                      FOnUDPSent_t\r
+       #define FOnTcpSent                                      FOnTCPSent_t\r
+#endif /* ipconfigENABLE_BACKWARD_COMPATIBILITY */\r
+\r
+#ifdef __cplusplus\r
+} /* extern "C" */\r
+#endif\r
+\r
+#endif /* FREERTOS_IP_H */\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r