Microchip® Advanced Software Framework

tcp.c File Reference

Transmission Control Protocol for IP.

This file contains common functions for the TCP implementation, such as functinos for manipulating the data structures and the TCP timer functions. TCP functions related to input and output is found in tcp_in.c and tcp_out.c respectively.

#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/snmp.h"
#include "lwip/tcp.h"
#include "lwip/tcp_impl.h"
#include "lwip/debug.h"
#include "lwip/stats.h"
#include <string.h>

Macros

#define NUM_TCP_PCB_LISTS   4
 
#define NUM_TCP_PCB_LISTS_NO_TIME_WAIT   3
 
#define TCP_ENSURE_LOCAL_PORT_RANGE(port)   (((port) & ~TCP_LOCAL_PORT_RANGE_START) + TCP_LOCAL_PORT_RANGE_START)
 
#define TCP_KEEP_DUR(pcb)   TCP_MAXIDLE
 
#define TCP_KEEP_INTVL(pcb)   TCP_KEEPINTVL_DEFAULT
 
#define TCP_LOCAL_PORT_RANGE_END   0xffff
 
#define TCP_LOCAL_PORT_RANGE_START   0xc000
 

Functions

void tcp_abandon (struct tcp_pcb *pcb, int reset)
 Abandons a connection and optionally sends a RST to the remote host. More...
 
void tcp_abort (struct tcp_pcb *pcb)
 Aborts the connection by sending a RST (reset) segment to the remote host. More...
 
void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept)
 Used for specifying the function that should be called when a LISTENing connection has been connected to another host. More...
 
static err_t tcp_accept_null (void *arg, struct tcp_pcb *pcb, err_t err)
 Default accept callback if no accept callback is specified by the user. More...
 
struct tcp_pcbtcp_alloc (u8_t prio)
 Allocate a new tcp_pcb structure. More...
 
void tcp_arg (struct tcp_pcb *pcb, void *arg)
 Used to specify the argument that should be passed callback functions. More...
 
err_t tcp_bind (struct tcp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
 Binds the connection to a local portnumber and IP address. More...
 
err_t tcp_close (struct tcp_pcb *pcb)
 Closes the connection held by the PCB. More...
 
static err_t tcp_close_shutdown (struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
 Closes the TX side of a connection held by the PCB. More...
 
err_t tcp_connect (struct tcp_pcb *pcb, ip_addr_t *ipaddr, u16_t port, tcp_connected_fn connected)
 Connects to another host. More...
 
const char * tcp_debug_state_str (enum tcp_state s)
 
u16_t tcp_eff_send_mss (u16_t sendmss, ip_addr_t *addr)
 Calcluates the effective send mss that can be used for a specific IP address by using ip_route to determin the netif used to send to the address and calculating the minimum of TCP_MSS and that netif's mtu (if set). More...
 
void tcp_err (struct tcp_pcb *pcb, tcp_err_fn err)
 Used to specify the function that should be called when a fatal error has occured on the connection. More...
 
void tcp_fasttmr (void)
 Is called every TCP_FAST_INTERVAL (250 ms) and process data previously "refused" by upper layer (application) and sends delayed ACKs. More...
 
void tcp_init (void)
 Initialize this module. More...
 
static void tcp_kill_prio (u8_t prio)
 Kills the oldest active connection that has the same or lower priority than 'prio'. More...
 
static void tcp_kill_timewait (void)
 Kills the oldest connection that is in TIME_WAIT state. More...
 
struct tcp_pcbtcp_listen_with_backlog (struct tcp_pcb *pcb, u8_t backlog)
 Set the state of the connection to be LISTEN, which means that it is able to accept incoming connections. More...
 
struct tcp_pcbtcp_new (void)
 Creates a new TCP protocol control block but doesn't place it on any of the TCP PCB lists. More...
 
static u16_t tcp_new_port (void)
 Allocate a new local TCP port. More...
 
u32_t tcp_next_iss (void)
 Calculates a new initial sequence number for new connections. More...
 
void tcp_pcb_purge (struct tcp_pcb *pcb)
 Purges a TCP PCB. More...
 
void tcp_pcb_remove (struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
 Purges the PCB and removes it from a PCB list. More...
 
void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval)
 Used to specify the function that should be called periodically from TCP. More...
 
err_t tcp_process_refused_data (struct tcp_pcb *pcb)
 Pass pcb->refused_data to the recv callback. More...
 
void tcp_recv (struct tcp_pcb *pcb, tcp_recv_fn recv)
 Used to specify the function that should be called when a TCP connection receives data. More...
 
err_t tcp_recv_null (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
 Default receive callback that is called if the user didn't register a recv callback for the pcb. More...
 
void tcp_recved (struct tcp_pcb *pcb, u16_t len)
 This function should be called by the application when it has processed the data. More...
 
struct tcp_segtcp_seg_copy (struct tcp_seg *seg)
 Returns a copy of the given TCP segment. More...
 
void tcp_seg_free (struct tcp_seg *seg)
 Frees a TCP segment (tcp_seg structure). More...
 
void tcp_segs_free (struct tcp_seg *seg)
 Deallocates a list of TCP segments (tcp_seg structures). More...
 
void tcp_sent (struct tcp_pcb *pcb, tcp_sent_fn sent)
 Used to specify the function that should be called when TCP data has been successfully delivered to the remote host. More...
 
void tcp_setprio (struct tcp_pcb *pcb, u8_t prio)
 Sets the priority of a connection. More...
 
err_t tcp_shutdown (struct tcp_pcb *pcb, int shut_rx, int shut_tx)
 Causes all or part of a full-duplex connection of this PCB to be shut down. More...
 
void tcp_slowtmr (void)
 Called every 500 ms and implements the retransmission timer and the timer that removes PCBs that have been in TIME-WAIT for enough time. More...
 
void tcp_tmr (void)
 Called periodically to dispatch TCP timers. More...
 
u32_t tcp_update_rcv_ann_wnd (struct tcp_pcb *pcb)
 Update the state that tracks the available window space to advertise. More...
 

Variables

struct tcp_pcbtcp_active_pcbs
 List of all TCP PCBs that are in a state in which they accept or send data. More...
 
u8_t tcp_active_pcbs_changed
 
const u8_t tcp_backoff [13]
 
struct tcp_pcbtcp_bound_pcbs
 List of all TCP PCBs bound but not yet (connected || listening) More...
 
union tcp_listen_pcbs_t tcp_listen_pcbs
 List of all TCP PCBs in LISTEN state. More...
 
struct tcp_pcb **const tcp_pcb_lists []
 An array with all (non-temporary) PCB lists, mainly used for smaller code size. More...
 
const u8_t tcp_persist_backoff [7] = { 3, 6, 12, 24, 48, 96, 120 }
 
static u16_t tcp_port = TCP_LOCAL_PORT_RANGE_START
 
const char *const tcp_state_str []
 
u32_t tcp_ticks
 
static u8_t tcp_timer
 Timer counter to handle calling slow-timer from tcp_tmr() More...
 
static u8_t tcp_timer_ctr
 
struct tcp_pcbtcp_tmp_pcb
 Only used for temporary storage. More...
 
struct tcp_pcbtcp_tw_pcbs
 List of all TCP PCBs in TIME-WAIT state. More...
 

#define NUM_TCP_PCB_LISTS   4

Referenced by tcp_bind(), tcp_connect(), and tcp_new_port().

#define NUM_TCP_PCB_LISTS_NO_TIME_WAIT   3

Referenced by tcp_bind().

#define TCP_ENSURE_LOCAL_PORT_RANGE (   port)    (((port) & ~TCP_LOCAL_PORT_RANGE_START) + TCP_LOCAL_PORT_RANGE_START)

Referenced by tcp_init().

#define TCP_KEEP_DUR (   pcb)    TCP_MAXIDLE

Referenced by tcp_slowtmr().

#define TCP_KEEP_INTVL (   pcb)    TCP_KEEPINTVL_DEFAULT

Referenced by tcp_slowtmr().

#define TCP_LOCAL_PORT_RANGE_END   0xffff

Referenced by tcp_new_port().

#define TCP_LOCAL_PORT_RANGE_START   0xc000

Referenced by tcp_new_port().

void tcp_abandon ( struct tcp_pcb pcb,
int  reset 
)

Abandons a connection and optionally sends a RST to the remote host.

Deletes the local protocol control block. This is done when a connection is killed because of shortage of memory.

Parameters
pcbthe tcp_pcb to abort
resetboolean to indicate whether a reset should be sent

References ackno, ERR_ABRT, tcp_pcb::errf, LISTEN, LWIP_ASSERT, LWIP_DEBUGF, memp_free(), NULL, tcp_pcb::ooseq, tcp_pcb::rcv_nxt, tcp_pcb::remote_port, seqno, tcp_pcb::snd_nxt, TCP_EVENT_ERR, tcp_pcb_remove(), TCP_PCB_REMOVE_ACTIVE, tcp_rst(), TCP_RST_DEBUG, tcp_segs_free(), TIME_WAIT, tcp_pcb::unacked, and tcp_pcb::unsent.

Referenced by tcp_abort(), and tcp_listen_input().

void tcp_abort ( struct tcp_pcb pcb)

Aborts the connection by sending a RST (reset) segment to the remote host.

The pcb is deallocated. This function never fails.

ATTENTION: When calling this from one of the TCP callbacks, make sure you always return ERR_ABRT (and never return ERR_ABRT otherwise or you will risk accessing deallocated memory or memory leaks!

Parameters
pcbthe tcp pcb to abort

References tcp_abandon().

Referenced by http_poll(), netif_set_ipaddr(), tcp_input(), tcp_kill_prio(), tcp_kill_timewait(), and tcp_process().

void tcp_accept ( struct tcp_pcb pcb,
tcp_accept_fn  accept 
)

Used for specifying the function that should be called when a LISTENing connection has been connected to another host.

Parameters
pcbtcp_pcb to set the accept callback
acceptcallback function to call for this pcb when LISTENing connection has been connected to another host

Referenced by httpd_init().

static err_t tcp_accept_null ( void arg,
struct tcp_pcb pcb,
err_t  err 
)
static

Default accept callback if no accept callback is specified by the user.

References ERR_ABRT, and LWIP_UNUSED_ARG.

Referenced by tcp_listen_with_backlog().

void tcp_arg ( struct tcp_pcb pcb,
void arg 
)

Used to specify the argument that should be passed callback functions.

Parameters
pcbtcp_pcb to set the callback argument
argvoid pointer argument to pass to callback functions

References arg.

Referenced by http_accept(), and http_close_conn().

err_t tcp_bind ( struct tcp_pcb pcb,
ip_addr_t ipaddr,
u16_t  port 
)

Binds the connection to a local portnumber and IP address.

If the IP address is not given (i.e., ipaddr == NULL), the IP address of the outgoing network interface is used instead.

Parameters
pcbthe tcp_pcb to bind (no check is done whether this pcb is already bound!)
ipaddrthe local ip address to bind to (use IP_ADDR_ANY to bind to any local address
portthe local port to bind to
Returns
ERR_USE if the port is already in use ERR_VAL if bind failed because the PCB is not in a valid state ERR_OK if bound

References CLOSED, ERR_BUF, ERR_OK, ERR_USE, ERR_VAL, ip_addr_cmp, ip_addr_isany, ip_get_option, LWIP_DEBUGF, LWIP_ERROR(), NULL, NUM_TCP_PCB_LISTS, NUM_TCP_PCB_LISTS_NO_TIME_WAIT, SOF_REUSEADDR, TCP_DEBUG, tcp_new_port(), TCP_REG, and U16_F.

Referenced by httpd_init().

err_t tcp_close ( struct tcp_pcb pcb)

Closes the connection held by the PCB.

Listening pcbs are freed and may not be referenced any more. Connection pcbs are freed if not yet connected and may not be referenced any more. If a connection is established (at least SYN received or in a closing state), the connection is closed, and put in a closing state. The pcb is then automatically freed in tcp_slowtmr(). It is therefore unsafe to reference it (unless an error is returned).

Parameters
pcbthe tcp_pcb to close
Returns
ERR_OK if connection has been closed another err_t if closing failed and pcb is not freed

References tcp_pcb::flags, LISTEN, LWIP_DEBUGF, tcp_close_shutdown(), TCP_DEBUG, tcp_debug_print_state, and TF_RXCLOSED.

Referenced by http_close_conn(), and tcp_recv_null().

static err_t tcp_close_shutdown ( struct tcp_pcb pcb,
u8_t  rst_on_unacked_data 
)
static

Closes the TX side of a connection held by the PCB.

For tcp_close(), a RST is sent if the application didn't receive all data (tcp_recved() not called for all data passed to recv callback).

Listening pcbs are freed and may not be referenced any more. Connection pcbs are freed if not yet connected and may not be referenced any more. If a connection is established (at least SYN received or in a closing state), the connection is closed, and put in a closing state. The pcb is then automatically freed in tcp_slowtmr(). It is therefore unsafe to reference it.

Parameters
pcbthe tcp_pcb to close
Returns
ERR_OK if connection has been closed another err_t if closing failed and pcb is not freed

References CLOSE_WAIT, CLOSED, ERR_OK, ESTABLISHED, FIN_WAIT_1, tcp_pcb::flags, LAST_ACK, LISTEN, LWIP_ASSERT, memp_free(), NULL, tcp_listen_pcbs_t::pcbs, tcp_pcb::rcv_nxt, tcp_pcb::rcv_wnd, tcp_pcb::refused_data, tcp_pcb::remote_port, tcp_pcb::snd_nxt, snmp_inc_tcpattemptfails, snmp_inc_tcpestabresets, SYN_RCVD, SYN_SENT, tcp_listen_pcbs, tcp_output(), tcp_pcb_purge(), tcp_pcb_remove(), TCP_PCB_REMOVE_ACTIVE, TCP_REG, TCP_RMV, TCP_RMV_ACTIVE, tcp_rst(), tcp_send_fin(), TCP_WND, TF_RXCLOSED, and TIME_WAIT.

Referenced by tcp_close(), and tcp_shutdown().

err_t tcp_connect ( struct tcp_pcb pcb,
ip_addr_t ipaddr,
u16_t  port,
tcp_connected_fn  connected 
)

Connects to another host.

The function given as the "connected" argument will be called when the connection has been established.

Parameters
pcbthe tcp_pcb used to establish the connection
ipaddrthe remote ip address to connect to
portthe remote tcp port to connect to
connectedcallback function to call when connected (or on error)
Returns
ERR_VAL if invalid arguments are given ERR_OK if connect request has been sent other err_t values if connect request couldn't be sent

References CLOSED, tcp_pcb::connected, tcp_pcb::cwnd, ERR_BUF, ERR_ISCONN, ERR_OK, ERR_RTE, ERR_USE, ERR_VAL, netif::ip_addr, ip_addr_cmp, ip_addr_copy, ip_addr_isany, ip_get_option, ip_route(), tcp_pcb::lastack, LWIP_DEBUGF, LWIP_ERROR(), LWIP_UNUSED_ARG, tcp_pcb::mss, NULL, NUM_TCP_PCB_LISTS, tcp_pcb::rcv_ann_right_edge, tcp_pcb::rcv_ann_wnd, tcp_pcb::rcv_nxt, tcp_pcb::rcv_wnd, tcp_pcb::remote_port, tcp_pcb::snd_lbb, tcp_pcb::snd_nxt, tcp_pcb::snd_wnd, snmp_inc_tcpactiveopens, SOF_REUSEADDR, tcp_pcb::ssthresh, SYN_SENT, TCP_DEBUG, tcp_eff_send_mss(), tcp_enqueue_flags(), TCP_MSS, tcp_new_port(), tcp_next_iss(), tcp_output(), TCP_REG_ACTIVE, TCP_RMV, TCP_SYN, TCP_WND, and U16_F.

const char* tcp_debug_state_str ( enum tcp_state  s)

References tcp_state_str.

u16_t tcp_eff_send_mss ( u16_t  sendmss,
ip_addr_t addr 
)

Calcluates the effective send mss that can be used for a specific IP address by using ip_route to determin the netif used to send to the address and calculating the minimum of TCP_MSS and that netif's mtu (if set).

References IP_HLEN, ip_route(), LWIP_MIN, netif::mtu, NULL, and TCP_HLEN.

Referenced by tcp_connect(), tcp_listen_input(), tcp_output_segment(), and tcp_process().

void tcp_err ( struct tcp_pcb pcb,
tcp_err_fn  err 
)

Used to specify the function that should be called when a fatal error has occured on the connection.

Parameters
pcbtcp_pcb to set the err callback
errcallback function to call for this pcb when a fatal error has occured on the connection

References tcp_pcb::errf, LISTEN, and LWIP_ASSERT.

Referenced by http_accept().

void tcp_fasttmr ( void  )

Is called every TCP_FAST_INTERVAL (250 ms) and process data previously "refused" by upper layer (application) and sends delayed ACKs.

Automatically called from tcp_tmr().

References tcp_pcb::flags, tcp_pcb::last_timer, LWIP_DEBUGF, next, NULL, tcp_pcb::refused_data, tcp_ack_now, tcp_active_pcbs, tcp_active_pcbs_changed, TCP_DEBUG, tcp_output(), tcp_process_refused_data(), tcp_timer_ctr, TF_ACK_DELAY, and TF_ACK_NOW.

Referenced by tcp_tmr().

void tcp_init ( void  )

Initialize this module.

References TCP_ENSURE_LOCAL_PORT_RANGE, and tcp_port.

Referenced by lwip_init().

static void tcp_kill_prio ( u8_t  prio)
static

Kills the oldest active connection that has the same or lower priority than 'prio'.

Parameters
priominimum priority

References LWIP_DEBUGF, NULL, S32_F, tcp_abort(), TCP_DEBUG, TCP_PRIO_MAX, tcp_ticks, and tcp_pcb::tmr.

Referenced by tcp_alloc().

static void tcp_kill_timewait ( void  )
static

Kills the oldest connection that is in TIME_WAIT state.

Called from tcp_alloc() if no more connections are available.

References LWIP_DEBUGF, NULL, S32_F, tcp_abort(), TCP_DEBUG, tcp_ticks, and tcp_pcb::tmr.

Referenced by tcp_alloc().

struct tcp_pcb* tcp_listen_with_backlog ( struct tcp_pcb pcb,
u8_t  backlog 
)

Set the state of the connection to be LISTEN, which means that it is able to accept incoming connections.

The protocol control block is reallocated in order to consume less memory. Setting the connection to LISTEN is an irreversible process.

Parameters
pcbthe original tcp_pcb
backlogthe incoming connections queue limit
Returns
tcp_pcb used for listening, consumes less memory.
Note
The original tcp_pcb is freed. This function therefore has to be called like this: tpcb = tcp_listen(tpcb);

References CLOSED, ip_addr_cmp, ip_addr_copy, ip_get_option, ip_set_option, LISTEN, tcp_listen_pcbs_t::listen_pcbs, LWIP_ERROR(), LWIP_UNUSED_ARG, memp_free(), memp_malloc(), NULL, tcp_listen_pcbs_t::pcbs, SOF_ACCEPTCONN, SOF_REUSEADDR, tcp_accept_null(), tcp_listen_pcbs, TCP_REG, and TCP_RMV.

struct tcp_pcb* tcp_new ( void  )

Creates a new TCP protocol control block but doesn't place it on any of the TCP PCB lists.

The pcb is not put on any list until binding using tcp_bind().

: Maybe there should be a idle TCP PCB list where these PCBs are put on. Port reservation using tcp_bind() is implemented but allocated pcbs that are not bound can't be killed automatically if wanting to allocate a pcb with higher prio (

See Also
tcp_kill_prio())
Returns
a new tcp_pcb that initially is in state CLOSED

References tcp_alloc(), and TCP_PRIO_NORMAL.

Referenced by httpd_init().

static u16_t tcp_new_port ( void  )
static

Allocate a new local TCP port.

Returns
a new (free) local TCP port number

References NULL, NUM_TCP_PCB_LISTS, TCP_LOCAL_PORT_RANGE_END, TCP_LOCAL_PORT_RANGE_START, and tcp_port.

Referenced by tcp_bind(), and tcp_connect().

u32_t tcp_next_iss ( void  )

Calculates a new initial sequence number for new connections.

Returns
u32_t pseudo random sequence number

References tcp_ticks.

Referenced by tcp_alloc(), and tcp_connect().

void tcp_pcb_purge ( struct tcp_pcb pcb)

Purges a TCP PCB.

Removes any buffered data and frees the buffer memory (pcb->ooseq, pcb->unsent and pcb->unacked are freed).

Parameters
pcbtcp_pcb to purge. The pcb itself is not deallocated!

References CLOSED, ip_addr_cmp, ip_addr_isany, LISTEN, tcp_listen_pcbs_t::listen_pcbs, LWIP_ASSERT, LWIP_DEBUGF, NULL, tcp_pcb::ooseq, pbuf_free(), tcp_pcb::refused_data, tcp_pcb::rtime, SYN_RCVD, TCP_DEBUG, tcp_listen_pcbs, tcp_segs_free(), TIME_WAIT, tcp_pcb::unacked, tcp_pcb::unsent, and tcp_pcb::unsent_oversize.

Referenced by tcp_close_shutdown(), tcp_pcb_remove(), tcp_process(), and tcp_slowtmr().

void tcp_pcb_remove ( struct tcp_pcb **  pcblist,
struct tcp_pcb pcb 
)

Purges the PCB and removes it from a PCB list.

Any delayed ACKs are sent first.

Parameters
pcblistPCB list to purge.
pcbtcp_pcb to purge. The pcb itself is NOT deallocated!

References CLOSED, tcp_pcb::flags, LISTEN, LWIP_ASSERT, NULL, tcp_pcb::ooseq, tcp_output(), tcp_pcb_purge(), tcp_pcbs_sane, TCP_RMV, TF_ACK_DELAY, TF_ACK_NOW, TIME_WAIT, tcp_pcb::unacked, and tcp_pcb::unsent.

Referenced by tcp_abandon(), tcp_close_shutdown(), and tcp_input().

void tcp_poll ( struct tcp_pcb pcb,
tcp_poll_fn  poll,
u8_t  interval 
)

Used to specify the function that should be called periodically from TCP.

The interval is specified in terms of the TCP coarse timer interval, which is called twice a second.

References LISTEN, LWIP_ASSERT, LWIP_UNUSED_ARG, tcp_pcb::poll, and tcp_pcb::pollinterval.

Referenced by http_accept().

err_t tcp_process_refused_data ( struct tcp_pcb pcb)
void tcp_recv ( struct tcp_pcb pcb,
tcp_recv_fn  recv 
)

Used to specify the function that should be called when a TCP connection receives data.

Parameters
pcbtcp_pcb to set the recv callback
recvcallback function to call for this pcb when data is received

References LISTEN, LWIP_ASSERT, and tcp_pcb::recv.

Referenced by http_accept(), and http_close_conn().

err_t tcp_recv_null ( void arg,
struct tcp_pcb pcb,
struct pbuf p,
err_t  err 
)

Default receive callback that is called if the user didn't register a recv callback for the pcb.

References ERR_OK, LWIP_UNUSED_ARG, NULL, pbuf_free(), tcp_close(), tcp_recved(), and pbuf::tot_len.

Referenced by tcp_alloc().

void tcp_recved ( struct tcp_pcb pcb,
u16_t  len 
)

This function should be called by the application when it has processed the data.

The purpose is to advertise a larger window when the data has been processed.

Parameters
pcbthe tcp_pcb for which data is read
lenthe amount of bytes that have been read by the application

References LISTEN, LWIP_ASSERT, LWIP_DEBUGF, tcp_pcb::rcv_wnd, tcp_ack_now, TCP_DEBUG, tcp_output(), tcp_update_rcv_ann_wnd(), TCP_WND, and U16_F.

Referenced by http_recv(), and tcp_recv_null().

struct tcp_seg* tcp_seg_copy ( struct tcp_seg seg)

Returns a copy of the given TCP segment.

The pbuf and data are not copied, only the pointers

Parameters
segthe old tcp_seg
Returns
a copy of seg

References memp_malloc(), NULL, tcp_seg::p, and pbuf_ref().

Referenced by tcp_receive().

void tcp_seg_free ( struct tcp_seg seg)

Frees a TCP segment (tcp_seg structure).

Parameters
segsingle tcp_seg to free

References memp_free(), NULL, tcp_seg::p, and pbuf_free().

Referenced by tcp_create_segment(), tcp_oos_insert_segment(), tcp_output(), tcp_process(), tcp_receive(), and tcp_segs_free().

void tcp_segs_free ( struct tcp_seg seg)

Deallocates a list of TCP segments (tcp_seg structures).

Parameters
segtcp_seg list of TCP segments to free

References next, tcp_seg::next, NULL, and tcp_seg_free().

Referenced by pbuf_free_ooseq(), tcp_abandon(), tcp_oos_insert_segment(), tcp_pcb_purge(), tcp_receive(), tcp_slowtmr(), and tcp_write().

void tcp_sent ( struct tcp_pcb pcb,
tcp_sent_fn  sent 
)

Used to specify the function that should be called when TCP data has been successfully delivered to the remote host.

Parameters
pcbtcp_pcb to set the sent callback
sentcallback function to call for this pcb when data is successfully sent

References LISTEN, LWIP_ASSERT, and tcp_pcb::sent.

Referenced by http_close_conn(), and http_write().

void tcp_setprio ( struct tcp_pcb pcb,
u8_t  prio 
)

Sets the priority of a connection.

Parameters
pcbthe tcp_pcb to manipulate
prionew priority

Referenced by http_accept().

err_t tcp_shutdown ( struct tcp_pcb pcb,
int  shut_rx,
int  shut_tx 
)

Causes all or part of a full-duplex connection of this PCB to be shut down.

This doesn't deallocate the PCB unless shutting down both sides! Shutting down both sides is the same as calling tcp_close, so if it succeds, the PCB should not be referenced any more.

Parameters
pcbPCB to shutdown
shut_rxshut down receive side if this is != 0
shut_txshut down send side if this is != 0
Returns
ERR_OK if shutdown succeeded (or the PCB has already been shut down) another err_t on error.

References CLOSE_WAIT, ERR_CONN, ERR_OK, ESTABLISHED, tcp_pcb::flags, LISTEN, NULL, pbuf_free(), tcp_pcb::refused_data, SYN_RCVD, tcp_close_shutdown(), and TF_RXCLOSED.

void tcp_tmr ( void  )

Called periodically to dispatch TCP timers.

References tcp_fasttmr(), tcp_slowtmr(), and tcp_timer.

Referenced by tcpip_tcp_timer().

u32_t tcp_update_rcv_ann_wnd ( struct tcp_pcb pcb)

Update the state that tracks the available window space to advertise.

Returns how much extra window would be advertised if we sent an update now.

References LWIP_ASSERT, LWIP_MIN, tcp_pcb::mss, tcp_pcb::rcv_ann_right_edge, tcp_pcb::rcv_ann_wnd, tcp_pcb::rcv_nxt, tcp_pcb::rcv_wnd, TCP_SEQ_GEQ, TCP_SEQ_GT, and TCP_WND.

Referenced by tcp_receive(), and tcp_recved().

struct tcp_pcb* tcp_active_pcbs

List of all TCP PCBs that are in a state in which they accept or send data.

Referenced by netif_set_ipaddr(), pbuf_free_ooseq(), tcp_fasttmr(), tcp_input(), tcp_slowtmr(), tcp_timer_needed(), and tcpip_tcp_timer().

u8_t tcp_active_pcbs_changed

Referenced by tcp_fasttmr(), and tcp_slowtmr().

const u8_t tcp_backoff[13]
Initial value:
=
{ 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7}

Referenced by tcp_slowtmr().

struct tcp_pcb* tcp_bound_pcbs

List of all TCP PCBs bound but not yet (connected || listening)

union tcp_listen_pcbs_t tcp_listen_pcbs

List of all TCP PCBs in LISTEN state.

Referenced by netif_set_ipaddr(), tcp_close_shutdown(), tcp_input(), tcp_listen_with_backlog(), and tcp_pcb_purge().

struct tcp_pcb** const tcp_pcb_lists[]
Initial value:
struct tcp_pcb * pcbs
Definition: tcp_impl.h:313
struct tcp_pcb * tcp_bound_pcbs
List of all TCP PCBs bound but not yet (connected || listening)
Definition: tcp.c:101
struct tcp_pcb * tcp_tw_pcbs
List of all TCP PCBs in TIME-WAIT state.
Definition: tcp.c:108
struct tcp_pcb * tcp_active_pcbs
List of all TCP PCBs that are in a state in which they accept or send data.
Definition: tcp.c:106
union tcp_listen_pcbs_t tcp_listen_pcbs
List of all TCP PCBs in LISTEN state.
Definition: tcp.c:103

An array with all (non-temporary) PCB lists, mainly used for smaller code size.

const u8_t tcp_persist_backoff[7] = { 3, 6, 12, 24, 48, 96, 120 }

Referenced by tcp_slowtmr().

u16_t tcp_port = TCP_LOCAL_PORT_RANGE_START
static

Referenced by tcp_init(), and tcp_new_port().

const char* const tcp_state_str[]
Initial value:
= {
"CLOSED",
"LISTEN",
"SYN_SENT",
"SYN_RCVD",
"ESTABLISHED",
"FIN_WAIT_1",
"FIN_WAIT_2",
"CLOSE_WAIT",
"CLOSING",
"LAST_ACK",
"TIME_WAIT"
}

Referenced by tcp_debug_state_str().

u8_t tcp_timer
static

Timer counter to handle calling slow-timer from tcp_tmr()

Referenced by tcp_tmr().

u8_t tcp_timer_ctr
static

Referenced by tcp_alloc(), tcp_fasttmr(), and tcp_slowtmr().

struct tcp_pcb* tcp_tmp_pcb

Only used for temporary storage.

struct tcp_pcb* tcp_tw_pcbs

List of all TCP PCBs in TIME-WAIT state.

Referenced by tcp_input(), tcp_process(), tcp_slowtmr(), tcp_timer_needed(), and tcpip_tcp_timer().