TCP
[Base Protocols]

Collaboration diagram for TCP:
RFC 793 Transmission Control Protocol. More...

Defines

#define TCP_RTTO_MIN   200
#define TCP_RTTO_MAX   20000
#define min(a, b)   ((a>b)?b:a)
#define max(a, b)   ((a>b)?a:b)

Functions

int NutTcpInput (NUTDEVICE *dev, NETBUF *nb)
 Process incoming TCP segments from IP layer.
int NutTcpStatePassiveOpenEvent (TCPSOCKET *sock)
 Initiated by the application.
int NutTcpStateActiveOpenEvent (TCPSOCKET *sock)
 Initiated by the application.
int NutTcpStateCloseEvent (TCPSOCKET *sock)
 Socket close by application.
int NutTcpStateWindowEvent (TCPSOCKET *sock)
 Initiated by the application.
int NutTcpStateRetranTimeout (TCPSOCKET *sock)
 Retransmit a segment after ACK timeout.
void NutTcpSm (void *arg)
 TCP state machine thread.
void NutTcpStateMachine (NETBUF *nb)
 Process incoming TCP segments.
int NutTcpInitStateMachine (void)
 Start TCP state machine.
int NutTcpAbortSocket (TCPSOCKET *sock, uint16_t last_error)
 Closes socket with error.
int IsInLimits (uint32_t x, uint32_t low, uint32_t high)
 Sequence number comparisons.
void NutTcpCalcRtt (TCPSOCKET *sock)

Variables

HANDLE tcp_in_rdy
NETBUF *volatile tcp_in_nbq

Detailed Description

RFC 793 Transmission Control Protocol.

TCP provides reliable, in-sequence delivery of a full-duplex stream of octets. It is used by applications which need a reliable, connection-oriented data transport.

Applications should call the TCP Socket API when using this protocol.

Todo:
Use an indirect call for NutTcpInput(). Right now, the whole TCP code is linked to any application, even if only UDP is used.

Define Documentation

#define TCP_RTTO_MIN   200

Definition at line 74 of file tcputil.c.

Referenced by NutTcpCalcRtt().

#define TCP_RTTO_MAX   20000

Definition at line 77 of file tcputil.c.

Referenced by NutTcpCalcRtt().

#define min ( a,
 )     ((a>b)?b:a)

Definition at line 97 of file tcputil.c.

Referenced by NutTcpCalcRtt().

#define max ( a,
 )     ((a>b)?a:b)

Definition at line 98 of file tcputil.c.

Referenced by NutTcpCalcRtt().


Function Documentation

int NutTcpInput ( NUTDEVICE dev,
NETBUF nb 
)

Process incoming TCP segments from IP layer.

Warning:
The caller must take care not to pass broadcast or multicast segments.
Note:
This routine is called by the IP layer on incoming TCP segments. Applications typically do not call this function.

Definition at line 148 of file tcpin.c.

References _NETBUF::nb_ap, _NETBUF::nb_flags, _NETBUF::nb_tp, NBAF_UNICAST, NutNetBufFree(), NutTcpStateMachine(), _NBDATA::sz, TCPHDR::th_off, and _NBDATA::vp.

int NutTcpStatePassiveOpenEvent ( TCPSOCKET sock  ) 

Initiated by the application.

Parameters:
sock Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket().
Returns:
0 if granted, error code otherwise.

Definition at line 798 of file tcpsm.c.

References EISCONN, NutEventWait(), tcp_socket::so_last_error, tcp_socket::so_pc_tq, tcp_socket::so_state, TCPS_CLOSED, and TCPS_LISTEN.

int NutTcpStateActiveOpenEvent ( TCPSOCKET sock  ) 

Initiated by the application.

The caller must make sure, that the socket is in closed state.

Parameters:
sock Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket().
Returns:
0 if granted, -1 otherwise.

Definition at line 823 of file tcpsm.c.

References NutEventWait(), tcp_socket::so_ac_tq, tcp_socket::so_state, TCPS_ESTABLISHED, and TCPS_SYN_SENT.

int NutTcpStateCloseEvent ( TCPSOCKET sock  ) 

Socket close by application.

If socket is in state SYN_RECEIVED or ESTABLISHED, it is changed to FINWAIT1.

No further data sending is accepted. Receiving is still allowed.

Parameters:
sock Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket().

Definition at line 855 of file tcpsm.c.

References EALREADY, ENOTCONN, NutTcpDestroySocket(), NutThreadYield(), tcp_socket::so_last_error, tcp_socket::so_state, TCPS_CLOSE_WAIT, TCPS_CLOSED, TCPS_CLOSING, TCPS_ESTABLISHED, TCPS_FIN_WAIT_1, TCPS_FIN_WAIT_2, TCPS_LAST_ACK, TCPS_LISTEN, TCPS_SYN_RECEIVED, TCPS_SYN_SENT, and TCPS_TIME_WAIT.

int NutTcpStateWindowEvent ( TCPSOCKET sock  ) 

Initiated by the application.

Parameters:
sock Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket().

Definition at line 910 of file tcpsm.c.

References NutTcpOutput(), SO_ACK, SO_FORCE, and tcp_socket::so_tx_flags.

int NutTcpStateRetranTimeout ( TCPSOCKET sock  ) 

Retransmit a segment after ACK timeout.

This function is called by the TCP timer.

Parameters:
sock Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket().
Returns:
Nonzero if socket was aborted due to reach of retransmit limit or network error.

Definition at line 935 of file tcpsm.c.

References __tcp_trf, __tcp_trs, ENETDOWN, ETIMEDOUT, IPPROTO_TCP, _NETBUF::nb_next, NutDumpTcpHeader(), NutGetMillis(), NutIpOutput(), NutTcpAbortSocket(), tcp_socket::so_remote_addr, tcp_socket::so_retran_time, tcp_socket::so_retransmits, tcp_socket::so_tx_nbq, and TCP_RETRIES_MAX.

NutTcpSm ( void *  arg  ) 

TCP state machine thread.

The TCP state machine serves two purposes: It processes incoming TCP segments and handles TCP timers.

Definition at line 1635 of file tcpsm.c.

References __tcp_trf, __tcp_trs, ip::ip_src, _NETBUF::nb_next, _NETBUF::nb_nw, _NETBUF::nb_tp, NutDumpTcpHeader(), NutEventWait(), NutGetMillis(), NutTcpDestroySocket(), NutTcpFindSocket(), NutTcpOutput(), NutTcpReject(), NutTcpStateRetranTimeout(), NutThreadSetPriority(), SO_ACK, SO_FORCE, tcp_socket::so_next, tcp_socket::so_retran_time, tcp_socket::so_rtto, tcp_socket::so_state, tcp_socket::so_time_wait, tcp_socket::so_tx_flags, tcp_socket::so_tx_nbq, tcp_in_rdy, TCPS_FIN_WAIT_2, TCPS_LISTEN, TCPS_SYN_RECEIVED, TCPS_TIME_WAIT, TCPHDR::th_dport, TCPHDR::th_sport, and _NBDATA::vp.

Referenced by NutTcpInitStateMachine().

void NutTcpStateMachine ( NETBUF nb  ) 

Process incoming TCP segments.

All incoming TCP packets are passed to this routine. They will be added to a global queue and processed by the TCP state machine, which is running on a separate thread.

Note:
This routine is called by the IP layer on incoming TCP segments. Applications typically do not call this function.

Definition at line 1732 of file tcpsm.c.

References _NETBUF::nb_ap, _NETBUF::nb_next, _NETBUF::nb_nw, _NETBUF::nb_tp, NutEventPost(), NutHeapAvailable, NutNetBufFree(), NutTcpReject(), _NBDATA::sz, and tcp_in_rdy.

int NutTcpInitStateMachine ( void   ) 

Start TCP state machine.

The socket interface will automatically call this routine as soon as the first socket is created.

Returns:
0 on success, -1 otherwise.

Definition at line 1774 of file tcpsm.c.

References NUT_THREAD_STACK_ADD, NUT_THREAD_STACK_MULT, NUT_THREAD_TCPSMSTACK, NutTcpSm(), and NutThreadCreate().

int NutTcpAbortSocket ( TCPSOCKET sock,
uint16_t  last_error 
)

Closes socket with error.

Aborts any socket activity and sets last error.

Parameters:
sock Socket descriptor.
last_error Error number to report
Note:
This routine is called internally by Nut/Net. Applications typically do not call this function.
Returns:
0 on success, -1 otherwise.

Definition at line 1795 of file tcpsm.c.

References NutEventBroadcast(), NutTcpDiscardBuffers(), tcp_socket::so_ac_tq, tcp_socket::so_last_error, tcp_socket::so_pc_tq, tcp_socket::so_retran_time, tcp_socket::so_rx_tq, tcp_socket::so_state, tcp_socket::so_time_wait, tcp_socket::so_tx_tq, TCPS_CLOSED, TCPS_FIN_WAIT_1, and TCPS_TIME_WAIT.

int IsInLimits ( uint32_t  x,
uint32_t  low,
uint32_t  high 
)

Sequence number comparisons.

Return true if x is between low and high inclusive, false otherwise

Definition at line 86 of file tcputil.c.

void NutTcpCalcRtt ( TCPSOCKET sock  ) 

Definition at line 103 of file tcputil.c.

References max, min, NutGetMillis(), tcp_socket::so_retran_time, tcp_socket::so_rtto, TCP_RTTO_MAX, and TCP_RTTO_MIN.


Variable Documentation

HANDLE tcp_in_rdy

Definition at line 274 of file tcpsm.c.

Referenced by NutTcpSm(), and NutTcpStateMachine().

NETBUF* volatile tcp_in_nbq

Definition at line 275 of file tcpsm.c.


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/