Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

tcp_misc.c File Reference

tcp_misc.c File Reference

Helper functions for TCP. More...

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

Detailed Description

Helper functions for TCP.

License

Copyright (C) 2010-2017 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:
1.7.6

Definition in file tcp_misc.c.


Function Documentation

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

Append an option to a TCP segment.

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

Definition at line 414 of file tcp_misc.c.

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 1630 of file tcp_misc.c.

error_t tcpCheckAck ( Socket *  socket,
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 615 of file tcp_misc.c.

error_t tcpCheckSequenceNumber ( Socket *  socket,
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 517 of file tcp_misc.c.

error_t tcpCheckSyn ( Socket *  socket,
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 586 of file tcp_misc.c.

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 1332 of file tcp_misc.c.

void tcpDeleteControlBlock ( Socket *  socket )

Delete TCB structure.

Parameters:
[in]socketHandle referencing the socket

Definition at line 1036 of file tcp_misc.c.

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 1971 of file tcp_misc.c.

void tcpFastLossRecovery ( Socket *  socket,
TcpHeader *  segment 
)

Fast loss recovery procedure.

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

Definition at line 934 of file tcp_misc.c.

void tcpFastRecovery ( Socket *  socket,
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 885 of file tcp_misc.c.

void tcpFastRetransmit ( Socket *  socket )

Fast retransmit procedure.

Parameters:
[in]socketHandle referencing the current socket

Definition at line 846 of file tcp_misc.c.

void tcpFlushRetransmitQueue ( Socket *  socket )

Flush retransmission queue.

Parameters:
[in]socketHandle referencing the socket

Definition at line 1135 of file tcp_misc.c.

void tcpFlushSynQueue ( Socket *  socket )

Flush SYN queue.

Parameters:
[in]socketHandle referencing the socket

Definition at line 1164 of file tcp_misc.c.

TcpOption* tcpGetOption ( TcpHeader *  segment,
uint8_t  kind 
)

Find a specified option in a TCP segment.

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 461 of file tcp_misc.c.

bool_t tcpIsDuplicateAck ( Socket *  socket,
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 806 of file tcp_misc.c.

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 1500 of file tcp_misc.c.

void tcpProcessSegmentData ( Socket *  socket,
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 972 of file tcp_misc.c.

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 1939 of file tcp_misc.c.

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 1862 of file tcp_misc.c.

error_t tcpRetransmitSegment ( Socket *  socket )

TCP segment retransmission.

Parameters:
[in]socketHandle referencing the socket
Returns:
Error code

Definition at line 1399 of file tcp_misc.c.

error_t tcpSendResetSegment ( NetInterface *  interface,
IpPseudoHeader pseudoHeader,
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 280 of file tcp_misc.c.

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 62 of file tcp_misc.c.

void tcpUpdateEvents ( Socket *  socket )

Update TCP related events.

Parameters:
[in]socketHandle referencing the socket

Definition at line 1661 of file tcp_misc.c.

void tcpUpdateReceiveWindow ( Socket *  socket )

Update receive window so as to avoid Silly Window Syndrome.

Parameters:
[in]socketHandle referencing the socket

Definition at line 1295 of file tcp_misc.c.

void tcpUpdateRetransmitQueue ( Socket *  socket )

Remove acknowledged segments from retransmission queue.

Parameters:
[in]socketHandle referencing the socket

Definition at line 1057 of file tcp_misc.c.

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 1192 of file tcp_misc.c.

void tcpUpdateSendWindow ( Socket *  socket,
TcpHeader *  segment 
)

Update send window.

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

Definition at line 1245 of file tcp_misc.c.

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 1790 of file tcp_misc.c.

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 1906 of file tcp_misc.c.

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 1828 of file tcp_misc.c.