tcp_misc.h File Reference

Helper functions for TCP. More...

#include "core/tcp.h"

Go to the source code of this file.

Functions

error_t tcpSendSegment (Socket *socket, uint8_t flags, uint32_t seqNum, uint32_t ackNum, size_t length, bool_t addToQueue)
 Send a TCP segment. More...
 
error_t tcpSendResetSegment (Socket *socket, uint32_t seqNum)
 Send a TCP reset segment. More...
 
error_t tcpRejectSegment (NetInterface *interface, const IpPseudoHeader *pseudoHeader, const TcpHeader *segment, size_t length)
 Send a TCP reset in response to an invalid segment. More...
 
error_t tcpAddOption (TcpHeader *segment, uint8_t kind, const void *value, uint8_t length)
 Append an option to the TCP header. More...
 
const TcpOptiontcpGetOption (const TcpHeader *segment, uint8_t kind)
 Search the TCP header for a given option. More...
 
uint32_t tcpGenerateInitialSeqNum (const IpAddr *localIpAddr, uint16_t localPort, const IpAddr *remoteIpAddr, uint16_t remotePort)
 Initial sequence number generation. More...
 
error_t tcpCheckSeqNum (Socket *socket, const TcpHeader *segment, size_t length)
 Test the sequence number of an incoming segment. More...
 
error_t tcpCheckSyn (Socket *socket, const TcpHeader *segment, size_t length)
 Check the SYN bit of an incoming segment. More...
 
error_t tcpCheckAck (Socket *socket, const TcpHeader *segment, size_t length)
 Test the ACK field of an incoming segment. More...
 
bool_t tcpIsDuplicateSyn (Socket *socket, const IpPseudoHeader *pseudoHeader, const TcpHeader *segment)
 Test whether the incoming SYN segment is a duplicate. More...
 
bool_t tcpIsDuplicateAck (Socket *socket, const TcpHeader *segment, size_t length)
 Test whether the incoming acknowledgment is a duplicate. More...
 
void tcpFastRetransmit (Socket *socket)
 Fast retransmit procedure. More...
 
void tcpFastRecovery (Socket *socket, const TcpHeader *segment, uint_t n)
 Fast recovery procedure. More...
 
void tcpFastLossRecovery (Socket *socket, const TcpHeader *segment)
 Fast loss recovery procedure. More...
 
void tcpProcessSegmentData (Socket *socket, const TcpHeader *segment, const NetBuffer *buffer, size_t offset, size_t length)
 Process the segment text. More...
 
void tcpDeleteControlBlock (Socket *socket)
 Delete TCB structure. More...
 
void tcpUpdateRetransmitQueue (Socket *socket)
 Remove acknowledged segments from retransmission queue. More...
 
void tcpFlushRetransmitQueue (Socket *socket)
 Flush retransmission queue. More...
 
void tcpFlushSynQueue (Socket *socket)
 Flush SYN queue. More...
 
void tcpUpdateSackBlocks (Socket *socket, uint32_t *leftEdge, uint32_t *rightEdge)
 Update the list of non-contiguous blocks that have been received. More...
 
void tcpUpdateSendWindow (Socket *socket, const TcpHeader *segment)
 Update send window. More...
 
void tcpUpdateReceiveWindow (Socket *socket)
 Update receive window so as to avoid Silly Window Syndrome. More...
 
bool_t tcpComputeRto (Socket *socket)
 Compute retransmission timeout. More...
 
error_t tcpRetransmitSegment (Socket *socket)
 TCP segment retransmission. More...
 
error_t tcpNagleAlgo (Socket *socket, uint_t flags)
 Nagle algorithm implementation. More...
 
void tcpChangeState (Socket *socket, TcpState newState)
 Update TCP FSM current state. More...
 
void tcpUpdateEvents (Socket *socket)
 Update TCP related events. More...
 
uint_t tcpWaitForEvents (Socket *socket, uint_t eventMask, systime_t timeout)
 Wait for a particular TCP event. More...
 
void tcpWriteTxBuffer (Socket *socket, uint32_t seqNum, const uint8_t *data, size_t length)
 Copy incoming data to the send buffer. More...
 
error_t tcpReadTxBuffer (Socket *socket, uint32_t seqNum, NetBuffer *buffer, size_t length)
 Copy data from the send buffer. More...
 
void tcpWriteRxBuffer (Socket *socket, uint32_t seqNum, const NetBuffer *data, size_t dataOffset, size_t length)
 Copy incoming data to the receive buffer. More...
 
void tcpReadRxBuffer (Socket *socket, uint32_t seqNum, uint8_t *data, size_t length)
 Copy data from the receive buffer. More...
 
void tcpDumpHeader (const TcpHeader *segment, size_t length, uint32_t iss, uint32_t irs)
 Dump TCP header for debugging purpose. More...
 

Detailed Description

Helper functions for TCP.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.0

Definition in file tcp_misc.h.

Function Documentation

◆ tcpAddOption()

error_t tcpAddOption ( TcpHeader segment,
uint8_t  kind,
const void *  value,
uint8_t  length 
)

Append an option to the TCP header.

Parameters
[in]segmentPointer to the TCP header
[in]kindOption code
[in]valueOption value
[in]lengthLength of the option value, in bytes
Returns
Error code

Definition at line 554 of file tcp_misc.c.

◆ tcpChangeState()

void tcpChangeState ( Socket socket,
TcpState  newState 
)

Update TCP FSM current state.

Parameters
[in]socketHandle referencing the socket
[in]newStateNew TCP state to switch to

Definition at line 2021 of file tcp_misc.c.

◆ tcpCheckAck()

error_t tcpCheckAck ( Socket socket,
const TcpHeader segment,
size_t  length 
)

Test the ACK field of an incoming segment.

Parameters
[in]socketHandle referencing the current socket
[in]segmentPointer to the TCP segment to check
[in]lengthLength of the segment data
Returns
NO_ERROR if the acknowledgment is acceptable, ERROR_FAILURE otherwise

Definition at line 844 of file tcp_misc.c.

◆ tcpCheckSeqNum()

error_t tcpCheckSeqNum ( Socket socket,
const TcpHeader segment,
size_t  length 
)

Test the sequence number of an incoming segment.

Parameters
[in]socketHandle referencing the current socket
[in]segmentPointer to the TCP segment to check
[in]lengthLength of the segment data
Returns
NO_ERROR if the incoming segment is acceptable, ERROR_FAILURE otherwise

Definition at line 719 of file tcp_misc.c.

◆ tcpCheckSyn()

error_t tcpCheckSyn ( Socket socket,
const TcpHeader segment,
size_t  length 
)

Check the SYN bit of an incoming segment.

Parameters
[in]socketHandle referencing the current socket
[in]segmentPointer to the TCP segment to check
[in]lengthLength of the segment data
Returns
ERROR_FAILURE if the SYN is in the window, NO_ERROR otherwise

Definition at line 810 of file tcp_misc.c.

◆ tcpComputeRto()

bool_t tcpComputeRto ( Socket socket)

Compute retransmission timeout.

Parameters
[in]socketHandle referencing the socket
Returns
TRUE if the RTT measurement is complete, else FALSE

Definition at line 1675 of file tcp_misc.c.

◆ tcpDeleteControlBlock()

void tcpDeleteControlBlock ( Socket socket)

Delete TCB structure.

Parameters
[in]socketHandle referencing the socket

Definition at line 1371 of file tcp_misc.c.

◆ tcpDumpHeader()

void tcpDumpHeader ( const TcpHeader segment,
size_t  length,
uint32_t  iss,
uint32_t  irs 
)

Dump TCP header for debugging purpose.

Parameters
[in]segmentPointer to the TCP header
[in]lengthLength of the segment data
[in]issInitial send sequence number (needed to compute relative SEQ number)
[in]irsInitial receive sequence number (needed to compute relative ACK number)

Definition at line 2388 of file tcp_misc.c.

◆ tcpFastLossRecovery()

void tcpFastLossRecovery ( Socket socket,
const TcpHeader segment 
)

Fast loss recovery procedure.

Parameters
[in]socketHandle referencing the current socket
[in]segmentPointer to the incoming TCP segment

Definition at line 1265 of file tcp_misc.c.

◆ tcpFastRecovery()

void tcpFastRecovery ( Socket socket,
const TcpHeader segment,
uint_t  n 
)

Fast recovery procedure.

Parameters
[in]socketHandle referencing the current socket
[in]segmentPointer to the incoming TCP segment
[in]nNumber of bytes acknowledged by the incoming ACK

Definition at line 1216 of file tcp_misc.c.

◆ tcpFastRetransmit()

void tcpFastRetransmit ( Socket socket)

Fast retransmit procedure.

Parameters
[in]socketHandle referencing the current socket

Definition at line 1177 of file tcp_misc.c.

◆ tcpFlushRetransmitQueue()

void tcpFlushRetransmitQueue ( Socket socket)

Flush retransmission queue.

Parameters
[in]socketHandle referencing the socket

Definition at line 1474 of file tcp_misc.c.

◆ tcpFlushSynQueue()

void tcpFlushSynQueue ( Socket socket)

Flush SYN queue.

Parameters
[in]socketHandle referencing the socket

Definition at line 1503 of file tcp_misc.c.

◆ tcpGenerateInitialSeqNum()

uint32_t tcpGenerateInitialSeqNum ( const IpAddr localIpAddr,
uint16_t  localPort,
const IpAddr remoteIpAddr,
uint16_t  remotePort 
)

Initial sequence number generation.

Parameters
[in]localIpAddrLocal IP address
[in]localPortLocal port
[in]remoteIpAddrRemote IP address
[in]remotePortRemote port
Returns
Value of the initial sequence number

Definition at line 683 of file tcp_misc.c.

◆ tcpGetOption()

const TcpOption* tcpGetOption ( const TcpHeader segment,
uint8_t  kind 
)

Search the TCP header for a given option.

Parameters
[in]segmentPointer to the TCP header
[in]kindCode of the option to find
Returns
If the specified option is found, a pointer to the corresponding option is returned. Otherwise NULL pointer is returned

Definition at line 617 of file tcp_misc.c.

◆ tcpIsDuplicateAck()

bool_t tcpIsDuplicateAck ( Socket socket,
const TcpHeader segment,
size_t  length 
)

Test whether the incoming acknowledgment is a duplicate.

Parameters
[in]socketHandle referencing the current socket
[in]segmentPointer to the TCP segment to check
[in]lengthLength of the segment data
Returns
TRUE if the ACK is duplicate, else FALSE

Definition at line 1134 of file tcp_misc.c.

◆ tcpIsDuplicateSyn()

bool_t tcpIsDuplicateSyn ( Socket socket,
const IpPseudoHeader pseudoHeader,
const TcpHeader segment 
)

Test whether the incoming SYN segment is a duplicate.

Parameters
[in]socketHandle referencing the current socket
[in]pseudoHeaderTCP pseudo header
[in]segmentPointer to the TCP segment to check
Returns
TRUE if the SYN segment is duplicate, else FALSE

Definition at line 1058 of file tcp_misc.c.

◆ tcpNagleAlgo()

error_t tcpNagleAlgo ( Socket socket,
uint_t  flags 
)

Nagle algorithm implementation.

Parameters
[in]socketHandle referencing the socket
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1900 of file tcp_misc.c.

◆ tcpProcessSegmentData()

void tcpProcessSegmentData ( Socket socket,
const TcpHeader segment,
const NetBuffer buffer,
size_t  offset,
size_t  length 
)

Process the segment text.

Parameters
[in]socketHandle referencing the current socket
[in]segmentPointer to the TCP header
[in]bufferMulti-part buffer containing the incoming TCP segment
[in]offsetOffset to the first data byte
[in]lengthLength of the segment data

Definition at line 1303 of file tcp_misc.c.

◆ tcpReadRxBuffer()

void tcpReadRxBuffer ( Socket socket,
uint32_t  seqNum,
uint8_t *  data,
size_t  length 
)

Copy data from the receive buffer.

Parameters
[in]socketHandle referencing the socket
[in]seqNumSequence number of the first data to read
[out]dataPointer to the output buffer
[in]lengthNumber of data to read

Definition at line 2353 of file tcp_misc.c.

◆ tcpReadTxBuffer()

error_t tcpReadTxBuffer ( Socket socket,
uint32_t  seqNum,
NetBuffer buffer,
size_t  length 
)

Copy data from the send buffer.

Parameters
[in]socketHandle referencing the socket
[in]seqNumSequence number of the first data to read
[out]bufferPointer to the output buffer
[in]lengthNumber of data to read
Returns
Error code

Definition at line 2274 of file tcp_misc.c.

◆ tcpRejectSegment()

error_t tcpRejectSegment ( NetInterface interface,
const IpPseudoHeader pseudoHeader,
const TcpHeader segment,
size_t  length 
)

Send a TCP reset in response to an invalid segment.

Parameters
[in]interfaceUnderlying network interface
[in]pseudoHeaderTCP pseudo header describing the incoming segment
[in]segmentIncoming TCP segment
[in]lengthLength of the incoming segment data
Returns
Error code

Definition at line 404 of file tcp_misc.c.

◆ tcpRetransmitSegment()

error_t tcpRetransmitSegment ( Socket socket)

TCP segment retransmission.

Parameters
[in]socketHandle referencing the socket
Returns
Error code

Definition at line 1744 of file tcp_misc.c.

◆ tcpSendResetSegment()

error_t tcpSendResetSegment ( Socket socket,
uint32_t  seqNum 
)

Send a TCP reset segment.

Parameters
[in]socketHandle referencing a socket
[in]seqNumSequence number
Returns
Error code

Definition at line 371 of file tcp_misc.c.

◆ tcpSendSegment()

error_t tcpSendSegment ( Socket socket,
uint8_t  flags,
uint32_t  seqNum,
uint32_t  ackNum,
size_t  length,
bool_t  addToQueue 
)

Send a TCP segment.

Parameters
[in]socketHandle referencing a socket
[in]flagsValue that contains bitwise OR of flags (see TcpFlags enumeration)
[in]seqNumSequence number
[in]ackNumAcknowledgment number
[in]lengthLength of the segment data
[in]addToQueueAdd the segment to retransmission queue
Returns
Error code

Definition at line 68 of file tcp_misc.c.

◆ tcpUpdateEvents()

void tcpUpdateEvents ( Socket socket)

Update TCP related events.

Parameters
[in]socketHandle referencing the socket

Definition at line 2052 of file tcp_misc.c.

◆ tcpUpdateReceiveWindow()

void tcpUpdateReceiveWindow ( Socket socket)

Update receive window so as to avoid Silly Window Syndrome.

Parameters
[in]socketHandle referencing the socket

Definition at line 1636 of file tcp_misc.c.

◆ tcpUpdateRetransmitQueue()

void tcpUpdateRetransmitQueue ( Socket socket)

Remove acknowledged segments from retransmission queue.

Parameters
[in]socketHandle referencing the socket

Definition at line 1392 of file tcp_misc.c.

◆ tcpUpdateSackBlocks()

void tcpUpdateSackBlocks ( Socket socket,
uint32_t *  leftEdge,
uint32_t *  rightEdge 
)

Update the list of non-contiguous blocks that have been received.

Parameters
[in]socketHandle referencing the socket
[in,out]leftEdgeFirst sequence number occupied by the incoming data
[in,out]rightEdgeSequence number immediately following the incoming data

Definition at line 1531 of file tcp_misc.c.

◆ tcpUpdateSendWindow()

void tcpUpdateSendWindow ( Socket socket,
const TcpHeader segment 
)

Update send window.

Parameters
[in]socketHandle referencing the socket
[in]segmentPointer to the incoming TCP segment

Definition at line 1586 of file tcp_misc.c.

◆ tcpWaitForEvents()

uint_t tcpWaitForEvents ( Socket socket,
uint_t  eventMask,
systime_t  timeout 
)

Wait for a particular TCP event.

Parameters
[in]socketHandle referencing the socket
[in]eventMaskLogic OR of all the TCP events that will complete the wait
[in]timeoutMaximum time to wait
Returns
Logic OR of all the TCP events that satisfied the wait

Definition at line 2200 of file tcp_misc.c.

◆ tcpWriteRxBuffer()

void tcpWriteRxBuffer ( Socket socket,
uint32_t  seqNum,
const NetBuffer data,
size_t  dataOffset,
size_t  length 
)

Copy incoming data to the receive buffer.

Parameters
[in]socketHandle referencing the socket
[in]seqNumFirst sequence number occupied by the incoming data
[in]dataMulti-part buffer containing the incoming data
[in]dataOffsetOffset to the first data byte
[in]lengthNumber of data to write

Definition at line 2318 of file tcp_misc.c.

◆ tcpWriteTxBuffer()

void tcpWriteTxBuffer ( Socket socket,
uint32_t  seqNum,
const uint8_t *  data,
size_t  length 
)

Copy incoming data to the send buffer.

Parameters
[in]socketHandle referencing the socket
[in]seqNumFirst sequence number occupied by the incoming data
[in]dataData to write
[in]lengthNumber of data to write

Definition at line 2238 of file tcp_misc.c.