lwIP  2.1.0
Lightweight IP stack
tcp.c File Reference
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/tcp.h"
#include "lwip/priv/tcp_priv.h"
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "lwip/ip6.h"
#include "lwip/ip6_addr.h"
#include "lwip/nd6.h"
#include <string.h>
#include "path/to/my/lwip_hooks.h"

Functions

void tcp_init (void)
 
void tcp_free (struct tcp_pcb *pcb)
 
void tcp_tmr (void)
 
void tcp_backlog_delayed (struct tcp_pcb *pcb)
 
void tcp_backlog_accepted (struct tcp_pcb *pcb)
 
err_t tcp_close (struct tcp_pcb *pcb)
 
err_t tcp_shutdown (struct tcp_pcb *pcb, int shut_rx, int shut_tx)
 
void tcp_abandon (struct tcp_pcb *pcb, int reset)
 
void tcp_abort (struct tcp_pcb *pcb)
 
err_t tcp_bind (struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
 
void tcp_bind_netif (struct tcp_pcb *pcb, const struct netif *netif)
 
struct tcp_pcbtcp_listen_with_backlog (struct tcp_pcb *pcb, u8_t backlog)
 
struct tcp_pcbtcp_listen_with_backlog_and_err (struct tcp_pcb *pcb, u8_t backlog, err_t *err)
 
u32_t tcp_update_rcv_ann_wnd (struct tcp_pcb *pcb)
 
void tcp_recved (struct tcp_pcb *pcb, u16_t len)
 
err_t tcp_connect (struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, tcp_connected_fn connected)
 
void tcp_slowtmr (void)
 
void tcp_fasttmr (void)
 
void tcp_txnow (void)
 
err_t tcp_process_refused_data (struct tcp_pcb *pcb)
 
void tcp_segs_free (struct tcp_seg *seg)
 
void tcp_seg_free (struct tcp_seg *seg)
 
void tcp_setprio (struct tcp_pcb *pcb, u8_t prio)
 
struct tcp_seg * tcp_seg_copy (struct tcp_seg *seg)
 
err_t tcp_recv_null (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
 
struct tcp_pcbtcp_alloc (u8_t prio)
 
struct tcp_pcbtcp_new (void)
 
struct tcp_pcbtcp_new_ip_type (u8_t type)
 
void tcp_arg (struct tcp_pcb *pcb, void *arg)
 
void tcp_recv (struct tcp_pcb *pcb, tcp_recv_fn recv)
 
void tcp_sent (struct tcp_pcb *pcb, tcp_sent_fn sent)
 
void tcp_err (struct tcp_pcb *pcb, tcp_err_fn err)
 
void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept)
 
void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval)
 
void tcp_pcb_purge (struct tcp_pcb *pcb)
 
void tcp_pcb_remove (struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
 
u32_t tcp_next_iss (struct tcp_pcb *pcb)
 
u16_t tcp_eff_send_mss_netif (u16_t sendmss, struct netif *outif, const ip_addr_t *dest)
 
void tcp_netif_ip_addr_changed (const ip_addr_t *old_addr, const ip_addr_t *new_addr)
 
u8_t tcp_ext_arg_alloc_id (void)
 
void tcp_ext_arg_set_callbacks (struct tcp_pcb *pcb, uint8_t id, const struct tcp_ext_arg_callbacks *const callbacks)
 
void tcp_ext_arg_set (struct tcp_pcb *pcb, uint8_t id, void *arg)
 
void * tcp_ext_arg_get (const struct tcp_pcb *pcb, uint8_t id)
 
err_t tcp_ext_arg_invoke_callbacks_passive_open (struct tcp_pcb_listen *lpcb, struct tcp_pcb *cpcb)
 

Variables

struct tcp_pcbtcp_bound_pcbs
 
union tcp_listen_pcbs_t tcp_listen_pcbs
 
struct tcp_pcbtcp_active_pcbs
 
struct tcp_pcbtcp_tw_pcbs
 
struct tcp_pcb **const tcp_pcb_lists []
 

Detailed Description

Transmission Control Protocol for IP See also TCP

Function Documentation

◆ tcp_abandon()

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

◆ tcp_alloc()

struct tcp_pcb* tcp_alloc ( u8_t  prio)

Allocate a new tcp_pcb structure.

Parameters
priopriority for the new pcb
Returns
a new tcp_pcb that initially is in state CLOSED

◆ tcp_eff_send_mss_netif()

u16_t tcp_eff_send_mss_netif ( u16_t  sendmss,
struct netif outif,
const ip_addr_t dest 
)

Calculates the effective send mss that can be used for a specific IP address by calculating the minimum of TCP_MSS and the mtu (if set) of the target netif (if not NULL).

◆ tcp_ext_arg_invoke_callbacks_passive_open()

err_t tcp_ext_arg_invoke_callbacks_passive_open ( struct tcp_pcb_listen lpcb,
struct tcp_pcb cpcb 
)

This function calls the "passive_open" callback for all ext_args if a connection is in the process of being accepted. This is called just after the SYN is received and before a SYN/ACK is sent, to allow to modify the very first segment sent even on passive open. Naturally, the "accepted" callback of the pcb has not been called yet!

◆ tcp_fasttmr()

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 or pending FINs.

Automatically called from tcp_tmr().

◆ tcp_free()

void tcp_free ( struct tcp_pcb pcb)

Free a tcp pcb

◆ tcp_init()

void tcp_init ( void  )

Initialize this module.

◆ tcp_netif_ip_addr_changed()

void tcp_netif_ip_addr_changed ( const ip_addr_t old_addr,
const ip_addr_t new_addr 
)

This function is called from netif.c when address is changed or netif is removed

Parameters
old_addrIP address of the netif before change
new_addrIP address of the netif after change or NULL if netif has been removed

◆ tcp_next_iss()

u32_t tcp_next_iss ( struct tcp_pcb pcb)

Calculates a new initial sequence number for new connections.

Returns
u32_t pseudo random sequence number

◆ tcp_pcb_purge()

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!

◆ tcp_pcb_remove()

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!

◆ tcp_process_refused_data()

err_t tcp_process_refused_data ( struct tcp_pcb pcb)

Pass pcb->refused_data to the recv callback

◆ tcp_recv_null()

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.

◆ tcp_seg_copy()

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

◆ tcp_seg_free()

void tcp_seg_free ( struct tcp_seg *  seg)

Frees a TCP segment (tcp_seg structure).

Parameters
segsingle tcp_seg to free

◆ 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

◆ tcp_setprio()

void tcp_setprio ( struct tcp_pcb pcb,
u8_t  prio 
)

Sets the priority of a connection.

Parameters
pcbthe tcp_pcb to manipulate
prionew priority

◆ tcp_slowtmr()

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. It also increments various timers such as the inactivity timer in each PCB.

Automatically called from tcp_tmr().

◆ tcp_tmr()

void tcp_tmr ( void  )

Called periodically to dispatch TCP timers.

◆ tcp_txnow()

void tcp_txnow ( void  )

Call tcp_output for all active pcbs that have TF_NAGLEMEMERR set

◆ tcp_update_rcv_ann_wnd()

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.

Variable Documentation

◆ tcp_active_pcbs

struct tcp_pcb* tcp_active_pcbs

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

◆ tcp_bound_pcbs

struct tcp_pcb* tcp_bound_pcbs

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

◆ tcp_listen_pcbs

union tcp_listen_pcbs_t tcp_listen_pcbs

List of all TCP PCBs in LISTEN state

◆ tcp_pcb_lists

struct tcp_pcb** const tcp_pcb_lists[]
Initial value:
}
struct tcp_pcb * tcp_bound_pcbs
Definition: tcp.c:171
struct tcp_pcb * tcp_tw_pcbs
Definition: tcp.c:178
struct tcp_pcb * tcp_active_pcbs
Definition: tcp.c:176
union tcp_listen_pcbs_t tcp_listen_pcbs
Definition: tcp.c:173

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

◆ tcp_tw_pcbs

struct tcp_pcb* tcp_tw_pcbs

List of all TCP PCBs in TIME-WAIT state