]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_TCP_WIN.h
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / include / FreeRTOS_TCP_WIN.h
index 9532fd159887cac0d220dff23203398f516202f9..1cb7eebc03a7b0d51200cd508dddf58301a2e1ab 100644 (file)
-/*\r
- * FreeRTOS+TCP V2.2.0\r
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
- * this software and associated documentation files (the "Software"), to deal in\r
- * the Software without restriction, including without limitation the rights to\r
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
- * the Software, and to permit persons to whom the Software is furnished to do so,\r
- * subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- * http://aws.amazon.com/freertos\r
- * http://www.FreeRTOS.org\r
- */\r
-\r
-/*\r
- *     FreeRTOS_TCP_WIN.c\r
- *  Module which handles the TCP windowing schemes for FreeRTOS-PLUS-TCP\r
- */\r
-\r
-#ifndef        FREERTOS_TCP_WIN_H\r
-#define        FREERTOS_TCP_WIN_H\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-extern BaseType_t xTCPWindowLoggingLevel;\r
-\r
-typedef struct xTCPTimer\r
-{\r
-       uint32_t ulBorn;\r
-} TCPTimer_t;\r
-\r
-typedef struct xTCP_SEGMENT\r
-{\r
-       uint32_t ulSequenceNumber;              /* The sequence number of the first byte in this packet */\r
-       int32_t lMaxLength;                             /* Maximum space, number of bytes which can be stored in this segment */\r
-       int32_t lDataLength;                    /* Actual number of bytes */\r
-       int32_t lStreamPos;                             /* reference to the [t|r]xStream of the socket */\r
-       TCPTimer_t xTransmitTimer;              /* saves a timestamp at the moment this segment gets transmitted (TX only) */\r
-       union\r
-       {\r
-               struct\r
-               {\r
-                       uint32_t\r
-                               ucTransmitCount : 8,/* Number of times the segment has been transmitted, used to calculate the RTT */\r
-                               ucDupAckCount : 8,      /* Counts the number of times that a higher segment was ACK'd. After 3 times a Fast Retransmission takes place */\r
-                               bOutstanding : 1,       /* It the peer's turn, we're just waiting for an ACK */\r
-                               bAcked : 1,                     /* This segment has been acknowledged */\r
-                               bIsForRx : 1;           /* pdTRUE if segment is used for reception */\r
-               } bits;\r
-               uint32_t ulFlags;\r
-       } u;\r
-#if( ipconfigUSE_TCP_WIN != 0 )\r
-       struct xLIST_ITEM xQueueItem;   /* TX only: segments can be linked in one of three queues: xPriorityQueue, xTxQueue, and xWaitQueue */\r
-       struct xLIST_ITEM xListItem;    /* With this item the segment can be connected to a list, depending on who is owning it */\r
-#endif\r
-} TCPSegment_t;\r
-\r
-typedef struct xTCP_WINSIZE\r
-{\r
-       uint32_t ulRxWindowLength;\r
-       uint32_t ulTxWindowLength;\r
-} TCPWinSize_t;\r
-\r
-/*\r
- * If TCP time-stamps are being used, they will occupy 12 bytes in\r
- * each packet, and thus the message space will become smaller\r
- */\r
-/* Keep this as a multiple of 4 */\r
-#if( ipconfigUSE_TCP_WIN == 1 )\r
-       #define ipSIZE_TCP_OPTIONS      16u\r
-#else\r
-       #define ipSIZE_TCP_OPTIONS   12u\r
-#endif\r
-\r
-/*\r
- *     Every TCP connection owns a TCP window for the administration of all packets\r
- *     It owns two sets of segment descriptors, incoming and outgoing\r
- */\r
-typedef struct xTCP_WINDOW\r
-{\r
-       union\r
-       {\r
-               struct\r
-               {\r
-                       uint32_t\r
-                               bHasInit : 1,           /* The window structure has been initialised */\r
-                               bSendFullSize : 1,      /* May only send packets with a size equal to MSS (for optimisation) */\r
-                               bTimeStamps : 1;        /* Socket is supposed to use TCP time-stamps. This depends on the */\r
-               } bits;                                         /* party which opens the connection */\r
-               uint32_t ulFlags;\r
-       } u;\r
-       TCPWinSize_t xSize;\r
-       struct\r
-       {\r
-               uint32_t ulFirstSequenceNumber;  /* Logging & debug: the first segment received/sent in this connection\r
-                                                                                 * for Tx: initial send sequence number (ISS)\r
-                                                                                 * for Rx: initial receive sequence number (IRS) */\r
-               uint32_t ulCurrentSequenceNumber;/* Tx/Rx: the oldest sequence number not yet confirmed, also SND.UNA / RCV.NXT\r
-                                                                                 * In other words: the sequence number of the left side of the sliding window */\r
-               uint32_t ulFINSequenceNumber;    /* The sequence number which carried the FIN flag */\r
-               uint32_t ulHighestSequenceNumber;/* Sequence number of the right-most byte + 1 */\r
-       } rx, tx;\r
-       uint32_t ulOurSequenceNumber;           /* The SEQ number we're sending out */\r
-       uint32_t ulUserDataLength;                      /* Number of bytes in Rx buffer which may be passed to the user, after having received a 'missing packet' */\r
-       uint32_t ulNextTxSequenceNumber;        /* The sequence number given to the next byte to be added for transmission */\r
-       int32_t lSRTT;                                          /* Smoothed Round Trip Time, it may increment quickly and it decrements slower */\r
-       uint8_t ucOptionLength;                         /* Number of valid bytes in ulOptionsData[] */\r
-#if( ipconfigUSE_TCP_WIN == 1 )\r
-       List_t xPriorityQueue;                          /* Priority queue: segments which must be sent immediately */\r
-       List_t xTxQueue;                                        /* Transmit queue: segments queued for transmission */\r
-       List_t xWaitQueue;                                      /* Waiting queue:  outstanding segments */\r
-       TCPSegment_t *pxHeadSegment;            /* points to a segment which has not been transmitted and it's size is still growing (user data being added) */\r
-       uint32_t ulOptionsData[ipSIZE_TCP_OPTIONS/sizeof(uint32_t)];    /* Contains the options we send out */\r
-       List_t xTxSegments;                                     /* A linked list of all transmission segments, sorted on sequence number */\r
-       List_t xRxSegments;                                     /* A linked list of reception segments, order depends on sequence of arrival */\r
-#else\r
-       /* For tiny TCP, there is only 1 outstanding TX segment */\r
-       TCPSegment_t xTxSegment;                        /* Priority queue */\r
-#endif\r
-       uint16_t usOurPortNumber;                       /* Mostly for debugging/logging: our TCP port number */\r
-       uint16_t usPeerPortNumber;                      /* debugging/logging: the peer's TCP port number */\r
-       uint16_t usMSS;                                         /* Current accepted MSS */\r
-       uint16_t usMSSInit;                                     /* MSS as configured by the socket owner */\r
-} TCPWindow_t;\r
-\r
-\r
-/*=============================================================================\r
- *\r
- * Creation and destruction\r
- *\r
- *=============================================================================*/\r
-\r
-/* Create and initialize a window */\r
-void vTCPWindowCreate( TCPWindow_t *pxWindow, uint32_t ulRxWindowLength,\r
-       uint32_t ulTxWindowLength, uint32_t ulAckNumber, uint32_t ulSequenceNumber, uint32_t ulMSS );\r
-\r
-/* Destroy a window (always returns NULL)\r
- * It will free some resources: a collection of segments */\r
-void vTCPWindowDestroy( TCPWindow_t *pxWindow );\r
-\r
-/* Initialize a window */\r
-void vTCPWindowInit( TCPWindow_t *pxWindow, uint32_t ulAckNumber, uint32_t ulSequenceNumber, uint32_t ulMSS );\r
-\r
-/* Clean up allocated segments. Should only be called when FreeRTOS+TCP will no longer be used. */\r
-void vTCPSegmentCleanup( void );\r
-\r
-/*=============================================================================\r
- *\r
- * Rx functions\r
- *\r
- *=============================================================================*/\r
-\r
-/* if true may be passed directly to user (segment expected and window is empty)\r
- * But pxWindow->ackno should always be used to set "BUF->ackno" */\r
-int32_t lTCPWindowRxCheck( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, uint32_t ulLength, uint32_t ulSpace );\r
-\r
-/* When lTCPWindowRxCheck returned false, please call store for this unexpected data */\r
-BaseType_t xTCPWindowRxStore( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, uint32_t ulLength );\r
-\r
-/* This function will be called as soon as a FIN is received. It will return true\r
- * if there are no 'open' reception segments */\r
-BaseType_t xTCPWindowRxEmpty( TCPWindow_t *pxWindow );\r
-\r
-/* _HT_ Temporary function for testing/debugging\r
- * Not used at this moment */\r
-void vTCPWinShowSegments( TCPWindow_t *pxWindow, BaseType_t bForRx );\r
-\r
-/*=============================================================================\r
- *\r
- * Tx functions\r
- *\r
- *=============================================================================*/\r
-\r
-/* Adds data to the Tx-window */\r
-int32_t lTCPWindowTxAdd( TCPWindow_t *pxWindow, uint32_t ulLength, int32_t lPosition, int32_t lMax );\r
-\r
-/* Check data to be sent and calculate the time period we may sleep */\r
-BaseType_t xTCPWindowTxHasData( TCPWindow_t *pxWindow, uint32_t ulWindowSize, TickType_t *pulDelay );\r
-\r
-/* See if anything is left to be sent\r
- * Function will be called when a FIN has been received. Only when the TX window is clean,\r
- * it will return pdTRUE */\r
-BaseType_t xTCPWindowTxDone( TCPWindow_t *pxWindow );\r
-\r
-/* Fetches data to be sent.\r
- * apPos will point to a location with the circular data buffer: txStream */\r
-uint32_t ulTCPWindowTxGet( TCPWindow_t *pxWindow, uint32_t ulWindowSize, int32_t *plPosition );\r
-\r
-/* Receive a normal ACK */\r
-uint32_t ulTCPWindowTxAck( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber );\r
-\r
-/* Receive a SACK option */\r
-uint32_t ulTCPWindowTxSack( TCPWindow_t *pxWindow, uint32_t ulFirst, uint32_t ulLast );\r
-\r
-\r
-#ifdef __cplusplus\r
-}      /* extern "C" */\r
-#endif\r
-\r
-#endif /* FREERTOS_TCP_WIN_H */\r
+/*
+ * FreeRTOS+TCP V2.2.0
+ * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * 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
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern BaseType_t xTCPWindowLoggingLevel;
+
+typedef struct xTCPTimer
+{
+       uint32_t ulBorn;
+} TCPTimer_t;
+
+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;
+#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 xListItem;    /* With this item the segment can be connected to a list, depending on who is owning it */
+#endif
+} TCPSegment_t;
+
+typedef struct xTCP_WINSIZE
+{
+       uint32_t ulRxWindowLength;
+       uint32_t ulTxWindowLength;
+} TCPWinSize_t;
+
+/*
+ * 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
+
+/*
+ *     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;
+       TCPWinSize_t xSize;
+       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, tx;
+       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 *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 );
+
+/* When lTCPWindowRxCheck returned false, please call store for this unexpected data */
+BaseType_t xTCPWindowRxStore( TCPWindow_t *pxWindow, uint32_t ulSequenceNumber, uint32_t ulLength );
+
+/* 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( TCPWindow_t *pxWindow );
+
+/* _HT_ Temporary function for testing/debugging
+ * Not used at this moment */
+void vTCPWinShowSegments( TCPWindow_t *pxWindow, BaseType_t bForRx );
+
+/*=============================================================================
+ *
+ * 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 *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( TCPWindow_t *pxWindow );
+
+/* Fetches data to be sent.
+ * apPos 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 );
+
+
+#ifdef __cplusplus
+}      /* extern "C" */
+#endif
+
+#endif /* FREERTOS_TCP_WIN_H */