lwIP  2.0.1
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>

Functions

void tcp_init (void)
 
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)
 
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_impl (u16_t sendmss, const ip_addr_t *dest, const ip_addr_t *src)
 
void tcp_netif_ip_addr_changed (const ip_addr_t *old_addr, const ip_addr_t *new_addr)
 

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

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
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
u16_t tcp_eff_send_mss_impl ( u16_t  sendmss,
const ip_addr_t dest,
const ip_addr_t src 
)

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

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().

void tcp_init ( void  )

Initialize this module.

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
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
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!
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!
err_t tcp_process_refused_data ( struct tcp_pcb pcb)

Pass pcb->refused_data to the recv callback

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.

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
void tcp_seg_free ( struct tcp_seg *  seg)

Frees a TCP segment (tcp_seg structure).

Parameters
segsingle tcp_seg to 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
void tcp_setprio ( struct tcp_pcb pcb,
u8_t  prio 
)

Sets the priority of a connection.

Parameters
pcbthe tcp_pcb to manipulate
prionew priority
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().

void tcp_tmr ( void  )

Called periodically to dispatch TCP timers.

void tcp_txnow ( void  )

Call tcp_output for all active pcbs that have TF_NAGLEMEMERR set

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

struct tcp_pcb* tcp_active_pcbs

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

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

struct tcp_pcb** const tcp_pcb_lists[]
Initial value:
struct tcp_pcb * tcp_bound_pcbs
Definition: tcp.c:115
struct tcp_pcb * tcp_tw_pcbs
Definition: tcp.c:122
struct tcp_pcb * tcp_active_pcbs
Definition: tcp.c:120
union tcp_listen_pcbs_t tcp_listen_pcbs
Definition: tcp.c:117

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

struct tcp_pcb* tcp_tw_pcbs

List of all TCP PCBs in TIME-WAIT state