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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (
26  * @version 1.9.0
27  **/
29 #ifndef _TCP_MISC_H
30 #define _TCP_MISC_H
32 //Dependencies
33 #include "core/tcp.h"
35 //C++ guard
36 #ifdef __cplusplus
37  extern "C" {
38 #endif
40 //TCP related functions
41 error_t tcpSendSegment(Socket *socket, uint8_t flags, uint32_t seqNum,
42  uint32_t ackNum, size_t length, bool_t addToQueue);
45  IpPseudoHeader *pseudoHeader, TcpHeader *segment, size_t length);
47 error_t tcpAddOption(TcpHeader *segment, uint8_t kind, const void *value,
48  uint8_t length);
50 TcpOption *tcpGetOption(TcpHeader *segment, uint8_t kind);
53 error_t tcpCheckSyn(Socket *socket, TcpHeader *segment, size_t length);
54 error_t tcpCheckAck(Socket *socket, TcpHeader *segment, size_t length);
57  TcpHeader *segment);
62 void tcpFastRecovery(Socket *socket, TcpHeader *segment, uint_t n);
66  const NetBuffer *buffer, size_t offset, size_t length);
75 void tcpUpdateSackBlocks(Socket *socket, uint32_t *leftEdge, uint32_t *rightEdge);
83 void tcpChangeState(Socket *socket, TcpState newState);
86 uint_t tcpWaitForEvents(Socket *socket, uint_t eventMask, systime_t timeout);
88 void tcpWriteTxBuffer(Socket *socket, uint32_t seqNum,
89  const uint8_t *data, size_t length);
92  NetBuffer *buffer, size_t length);
94 void tcpWriteRxBuffer(Socket *socket, uint32_t seqNum,
95  const NetBuffer *data, size_t dataOffset, size_t length);
97 void tcpReadRxBuffer(Socket *socket, uint32_t seqNum, uint8_t *data,
98  size_t length);
100 void tcpDumpHeader(const TcpHeader *segment, size_t length, uint32_t iss,
101  uint32_t irs);
103 //C++ guard
104 #ifdef __cplusplus
105  }
106 #endif
108 #endif
NetInterface * interface
Definition: tcp.h:373
TCP FSM states.
Definition: tcp.h:229
uint32_t systime_t
Definition: compiler_port.h:44
uint_t tcpWaitForEvents(Socket *socket, uint_t eventMask, systime_t timeout)
Wait for a particular TCP event.
Definition: tcp_misc.c:1883
uint8_t flags
Definition: tcp.h:312
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:1999
void tcpDeleteControlBlock(Socket *socket)
Delete TCB structure.
Definition: tcp_misc.c:1128
error_t tcpCheckAck(Socket *socket, TcpHeader *segment, size_t length)
Test the ACK field of an incoming segment.
Definition: tcp_misc.c:626
void tcpFastRetransmit(Socket *socket)
Fast retransmit procedure.
Definition: tcp_misc.c:935
void tcpProcessSegmentData(Socket *socket, TcpHeader *segment, const NetBuffer *buffer, size_t offset, size_t length)
Process the segment text.
Definition: tcp_misc.c:1061
TcpOption * tcpGetOption(TcpHeader *segment, uint8_t kind)
Find a specified option in a TCP segment.
Definition: tcp_misc.c:467
void tcpFastRecovery(Socket *socket, TcpHeader *segment, uint_t n)
Fast recovery procedure.
Definition: tcp_misc.c:974
__start_packed struct @124 TcpHeader
TCP header.
uint32_t ackNum
Definition: tcp.h:303
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:419
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:283
bool_t tcpComputeRto(Socket *socket)
Compute retransmission timeout.
Definition: tcp_misc.c:1422
void tcpFlushSynQueue(Socket *socket)
Flush SYN queue.
Definition: tcp_misc.c:1254
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:63
void tcpUpdateRetransmitQueue(Socket *socket)
Remove acknowledged segments from retransmission queue.
Definition: tcp_misc.c:1149
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:1921
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:106
#define Socket
Definition: socket.h:34
error_t tcpCheckSyn(Socket *socket, TcpHeader *segment, size_t length)
Check the SYN bit of an incoming segment.
Definition: tcp_misc.c:592
uint8_t kind
Definition: tcp.h:328
uint8_t dataOffset
Definition: tcp.h:311
error_t tcpNagleAlgo(Socket *socket, uint_t flags)
Nagle algorithm implementation.
Definition: tcp_misc.c:1594
void tcpFastLossRecovery(Socket *socket, TcpHeader *segment)
Fast loss recovery procedure.
Definition: tcp_misc.c:1023
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
void tcpReadRxBuffer(Socket *socket, uint32_t seqNum, uint8_t *data, size_t length)
Copy data from the receive buffer.
Definition: tcp_misc.c:2032
Error codes.
Definition: error.h:40
void tcpDumpHeader(const TcpHeader *segment, size_t length, uint32_t iss, uint32_t irs)
Dump TCP header for debugging purpose.
Definition: tcp_misc.c:2065
error_t tcpCheckSequenceNumber(Socket *socket, TcpHeader *segment, size_t length)
Test the sequence number of an incoming segment.
Definition: tcp_misc.c:523
bool_t tcpIsDuplicateAck(Socket *socket, TcpHeader *segment, size_t length)
Test whether the incoming acknowledgment is a duplicate.
Definition: tcp_misc.c:893
void tcpChangeState(Socket *socket, TcpState newState)
Update TCP FSM current state.
Definition: tcp_misc.c:1723
DtlsSequenceNumber seqNum
Definition: dtls_misc.h:165
unsigned int uint_t
Definition: compiler_port.h:43
error_t tcpReadTxBuffer(Socket *socket, uint32_t seqNum, NetBuffer *buffer, size_t length)
Copy data from the send buffer.
Definition: tcp_misc.c:1955
uint8_t data[]
Definition: dtls_misc.h:167
void tcpUpdateReceiveWindow(Socket *socket)
Update receive window so as to avoid Silly Window Syndrome.
Definition: tcp_misc.c:1385
#define NetInterface
Definition: net.h:34
uint8_t value[]
Definition: dtls_misc.h:141
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:1282
IP pseudo header.
Definition: ip.h:76
error_t tcpRetransmitSegment(Socket *socket)
TCP segment retransmission.
Definition: tcp_misc.c:1491
void tcpUpdateEvents(Socket *socket)
Update TCP related events.
Definition: tcp_misc.c:1754
uint8_t length
Definition: dtls_misc.h:140
uint8_t n
TCP (Transmission Control Protocol)
bool_t tcpIsDuplicateSyn(Socket *socket, IpPseudoHeader *pseudoHeader, TcpHeader *segment)
Test whether the incoming SYN segment is a duplicate.
Definition: tcp_misc.c:817
int bool_t
Definition: compiler_port.h:47
void tcpUpdateSendWindow(Socket *socket, TcpHeader *segment)
Update send window.
Definition: tcp_misc.c:1335
void tcpFlushRetransmitQueue(Socket *socket)
Flush retransmission queue.
Definition: tcp_misc.c:1225
__start_packed struct @125 TcpOption
TCP option.