tcp_misc.h
Go to the documentation of this file.
1 /**
2  * @file tcp_misc.h
3  * @brief Helper functions for TCP
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
31 #ifndef _TCP_MISC_H
32 #define _TCP_MISC_H
33 
34 //Dependencies
35 #include "core/tcp.h"
36 
37 //C++ guard
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 //TCP related functions
43 error_t tcpSendSegment(Socket *socket, uint8_t flags, uint32_t seqNum,
44  uint32_t ackNum, size_t length, bool_t addToQueue);
45 
47  IpPseudoHeader *pseudoHeader, TcpHeader *segment, size_t length);
48 
49 error_t tcpAddOption(TcpHeader *segment, uint8_t kind, const void *value,
50  uint8_t length);
51 
52 TcpOption *tcpGetOption(TcpHeader *segment, uint8_t kind);
53 
55 error_t tcpCheckSyn(Socket *socket, TcpHeader *segment, size_t length);
56 error_t tcpCheckAck(Socket *socket, TcpHeader *segment, size_t length);
57 
59  TcpHeader *segment);
60 
62 
64 void tcpFastRecovery(Socket *socket, TcpHeader *segment, uint_t n);
66 
68  const NetBuffer *buffer, size_t offset, size_t length);
69 
71 
74 
76 
77 void tcpUpdateSackBlocks(Socket *socket, uint32_t *leftEdge, uint32_t *rightEdge);
80 
84 
85 void tcpChangeState(Socket *socket, TcpState newState);
86 
88 uint_t tcpWaitForEvents(Socket *socket, uint_t eventMask, systime_t timeout);
89 
90 void tcpWriteTxBuffer(Socket *socket, uint32_t seqNum,
91  const uint8_t *data, size_t length);
92 
94  NetBuffer *buffer, size_t length);
95 
96 void tcpWriteRxBuffer(Socket *socket, uint32_t seqNum,
97  const NetBuffer *data, size_t dataOffset, size_t length);
98 
99 void tcpReadRxBuffer(Socket *socket, uint32_t seqNum, uint8_t *data,
100  size_t length);
101 
102 void tcpDumpHeader(const TcpHeader *segment, size_t length, uint32_t iss,
103  uint32_t irs);
104 
105 //C++ guard
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif
__start_packed struct @121 TcpOption
TCP option.
uint8_t length
Definition: dtls_misc.h:149
uint_t tcpWaitForEvents(Socket *socket, uint_t eventMask, systime_t timeout)
Wait for a particular TCP event.
Definition: tcp_misc.c:1885
int bool_t
Definition: compiler_port.h:49
bool_t tcpIsDuplicateAck(Socket *socket, TcpHeader *segment, size_t length)
Test whether the incoming acknowledgment is a duplicate.
Definition: tcp_misc.c:895
void tcpUpdateEvents(Socket *socket)
Update TCP related events.
Definition: tcp_misc.c:1756
__start_packed struct @120 TcpHeader
TCP header.
void tcpFlushRetransmitQueue(Socket *socket)
Flush retransmission queue.
Definition: tcp_misc.c:1227
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:88
void tcpChangeState(Socket *socket, TcpState newState)
Update TCP FSM current state.
Definition: tcp_misc.c:1725
void tcpFastRetransmit(Socket *socket)
Fast retransmit procedure.
Definition: tcp_misc.c:937
void tcpWriteTxBuffer(Socket *socket, uint32_t seqNum, const uint8_t *data, size_t length)
Copy incoming data to the send buffer.
Definition: tcp_misc.c:1923
void tcpFastLossRecovery(Socket *socket, TcpHeader *segment)
Fast loss recovery procedure.
Definition: tcp_misc.c:1025
error_t tcpRetransmitSegment(Socket *socket)
TCP segment retransmission.
Definition: tcp_misc.c:1493
bool_t tcpIsDuplicateSyn(Socket *socket, IpPseudoHeader *pseudoHeader, TcpHeader *segment)
Test whether the incoming SYN segment is a duplicate.
Definition: tcp_misc.c:819
void tcpReadRxBuffer(Socket *socket, uint32_t seqNum, uint8_t *data, size_t length)
Copy data from the receive buffer.
Definition: tcp_misc.c:2034
void tcpDeleteControlBlock(Socket *socket)
Delete TCB structure.
Definition: tcp_misc.c:1130
error_t tcpCheckSyn(Socket *socket, TcpHeader *segment, size_t length)
Check the SYN bit of an incoming segment.
Definition: tcp_misc.c:594
error_t tcpCheckSequenceNumber(Socket *socket, TcpHeader *segment, size_t length)
Test the sequence number of an incoming segment.
Definition: tcp_misc.c:525
IP pseudo header.
Definition: ip.h:90
TcpState
TCP FSM states.
Definition: tcp.h:231
void tcpFastRecovery(Socket *socket, TcpHeader *segment, uint_t n)
Fast recovery procedure.
Definition: tcp_misc.c:976
void tcpProcessSegmentData(Socket *socket, TcpHeader *segment, const NetBuffer *buffer, size_t offset, size_t length)
Process the segment text.
Definition: tcp_misc.c:1063
error_t
Error codes.
Definition: error.h:42
error_t tcpReadTxBuffer(Socket *socket, uint32_t seqNum, NetBuffer *buffer, size_t length)
Copy data from the send buffer.
Definition: tcp_misc.c:1957
int_t socket(int_t family, int_t type, int_t protocol)
Create a socket that is bound to a specific transport service provider.
Definition: bsd_socket.c:108
error_t tcpSendResetSegment(NetInterface *interface, IpPseudoHeader *pseudoHeader, TcpHeader *segment, size_t length)
Send a TCP reset in response to an invalid segment.
Definition: tcp_misc.c:285
#define NetInterface
Definition: net.h:36
bool_t tcpComputeRto(Socket *socket)
Compute retransmission timeout.
Definition: tcp_misc.c:1424
NetInterface * interface
Definition: tcp.h:375
void tcpUpdateRetransmitQueue(Socket *socket)
Remove acknowledged segments from retransmission queue.
Definition: tcp_misc.c:1151
uint8_t kind
Definition: tcp.h:330
TcpOption * tcpGetOption(TcpHeader *segment, uint8_t kind)
Find a specified option in a TCP segment.
Definition: tcp_misc.c:469
uint8_t flags
Definition: tcp.h:314
uint32_t ackNum
Definition: tcp.h:305
void tcpFlushSynQueue(Socket *socket)
Flush SYN queue.
Definition: tcp_misc.c:1256
error_t tcpSendSegment(Socket *socket, uint8_t flags, uint32_t seqNum, uint32_t ackNum, size_t length, bool_t addToQueue)
Send a TCP segment.
Definition: tcp_misc.c:65
uint8_t n
TCP (Transmission Control Protocol)
void tcpDumpHeader(const TcpHeader *segment, size_t length, uint32_t iss, uint32_t irs)
Dump TCP header for debugging purpose.
Definition: tcp_misc.c:2067
void tcpUpdateSendWindow(Socket *socket, TcpHeader *segment)
Update send window.
Definition: tcp_misc.c:1337
#define Socket
Definition: socket.h:36
uint8_t dataOffset
Definition: tcp.h:313
error_t tcpAddOption(TcpHeader *segment, uint8_t kind, const void *value, uint8_t length)
Append an option to a TCP segment.
Definition: tcp_misc.c:421
DtlsSequenceNumber seqNum
Definition: dtls_misc.h:174
void tcpWriteRxBuffer(Socket *socket, uint32_t seqNum, const NetBuffer *data, size_t dataOffset, size_t length)
Copy incoming data to the receive buffer.
Definition: tcp_misc.c:2001
uint8_t value[]
Definition: dtls_misc.h:150
unsigned int uint_t
Definition: compiler_port.h:45
uint8_t data[]
Definition: dtls_misc.h:176
error_t tcpCheckAck(Socket *socket, TcpHeader *segment, size_t length)
Test the ACK field of an incoming segment.
Definition: tcp_misc.c:628
uint32_t systime_t
Definition: compiler_port.h:46
error_t tcpNagleAlgo(Socket *socket, uint_t flags)
Nagle algorithm implementation.
Definition: tcp_misc.c:1596
void tcpUpdateReceiveWindow(Socket *socket)
Update receive window so as to avoid Silly Window Syndrome.
Definition: tcp_misc.c:1387
void tcpUpdateSackBlocks(Socket *socket, uint32_t *leftEdge, uint32_t *rightEdge)
Update the list of non-contiguous blocks that have been received.
Definition: tcp_misc.c:1284