1 /*
2  * FreeRTOS+TCP V3.1.0
3  * Copyright (C) 2022 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * SPDX-License-Identifier: MIT
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of
8  * this software and associated documentation files (the "Software"), to deal in
9  * the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11  * the Software, and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * http://aws.amazon.com/freertos
25  * http://www.FreeRTOS.org
26  */
27 
28 #ifndef FREERTOS_TCP_TRANSMISSION_H
29 #define FREERTOS_TCP_TRANSMISSION_H
30 
31 /* *INDENT-OFF* */
32 #ifdef __cplusplus
33     extern "C" {
34 #endif
35 /* *INDENT-ON* */
36 
37 /*
38  * Either sends a SYN or calls prvTCPSendRepeated (for regular messages).
39  */
40 int32_t prvTCPSendPacket( FreeRTOS_Socket_t * pxSocket );
41 
42 /*
43  * Try to send a series of messages.
44  */
45 int32_t prvTCPSendRepeated( FreeRTOS_Socket_t * pxSocket,
46                             NetworkBufferDescriptor_t ** ppxNetworkBuffer );
47 
48 /*
49  * Return or send a packet to the other party.
50  */
51 void prvTCPReturnPacket( FreeRTOS_Socket_t * pxSocket,
52                          NetworkBufferDescriptor_t * pxDescriptor,
53                          uint32_t ulLen,
54                          BaseType_t xReleaseAfterSend );
55 
56 /*
57  * Initialise the data structures which keep track of the TCP windowing system.
58  */
59 void prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket );
60 
61 /*
62  * Set the initial properties in the options fields, like the preferred
63  * value of MSS and whether SACK allowed.  Will be transmitted in the state
64  * 'eCONNECT_SYN'.
65  */
66 UBaseType_t prvSetSynAckOptions( FreeRTOS_Socket_t * pxSocket,
67                                  TCPHeader_t * pxTCPHeader );
68 
69 /*
70  * Prepare an outgoing message, if anything has to be sent.
71  */
72 int32_t prvTCPPrepareSend( FreeRTOS_Socket_t * pxSocket,
73                            NetworkBufferDescriptor_t ** ppxNetworkBuffer,
74                            UBaseType_t uxOptionsLength );
75 
76 /*
77  * The API FreeRTOS_send() adds data to the TX stream.  Add
78  * this data to the windowing system to it can be transmitted.
79  */
80 void prvTCPAddTxData( FreeRTOS_Socket_t * pxSocket );
81 
82 /*
83  * Set the TCP options (if any) for the outgoing packet.
84  */
85 UBaseType_t prvSetOptions( FreeRTOS_Socket_t * pxSocket,
86                            const NetworkBufferDescriptor_t * pxNetworkBuffer );
87 
88 /*
89  * Called from prvTCPHandleState().  There is data to be sent.
90  * If ipconfigUSE_TCP_WIN is defined, and if only an ACK must be sent, it will
91  * be checked if it would better be postponed for efficiency.
92  */
93 BaseType_t prvSendData( FreeRTOS_Socket_t * pxSocket,
94                         NetworkBufferDescriptor_t ** ppxNetworkBuffer,
95                         uint32_t ulReceiveLength,
96                         BaseType_t xByteCount );
97 
98 /*
99  * A "challenge ACK" is as per https://tools.ietf.org/html/rfc5961#section-3.2,
100  * case #3. In summary, an RST was received with a sequence number that is
101  * unexpected but still within the window.
102  */
103 BaseType_t prvTCPSendChallengeAck( NetworkBufferDescriptor_t * pxNetworkBuffer );
104 
105 /*
106  * Reply to a peer with the RST flag on, in case a packet can not be handled.
107  */
108 BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t * pxNetworkBuffer );
109 
110 /*
111  *  Check if the size of a network buffer is big enough to hold the outgoing message.
112  *  Allocate a new bigger network buffer when necessary.
113  */
114 NetworkBufferDescriptor_t * prvTCPBufferResize( const FreeRTOS_Socket_t * pxSocket,
115                                                 NetworkBufferDescriptor_t * pxNetworkBuffer,
116                                                 int32_t lDataLen,
117                                                 UBaseType_t uxOptionsLength );
118 /* *INDENT-OFF* */
119 #ifdef __cplusplus
120     } /* extern "C" */
121 #endif
122 /* *INDENT-ON* */
123 
124 #endif /* FREERTOS_TCP_TRANSMISSION_H */
125