Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

tcp_priv.h File Reference

tcp_priv.h File Reference

TCP internal implementations (do not use in application code) More...

Go to the source code of this file.

Functions

void tcp_init (void)
 Initialize this module.
void tcp_tmr (void)
 Called periodically to dispatch TCP timers.
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.
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.
void tcp_txnow (void)
 Call tcp_output for all active pcbs that have TF_NAGLEMEMERR set.
void tcp_input (struct pbuf *p, struct netif *inp)
 The initial input processing of TCP.
struct tcp_pcbtcp_alloc (u8_t prio)
 Allocate a new tcp_pcb structure.
void tcp_free (struct tcp_pcb *pcb)
 Free a tcp pcb.
void tcp_abandon (struct tcp_pcb *pcb, int reset)
 Abandons a connection and optionally sends a RST to the remote host.
err_t tcp_send_empty_ack (struct tcp_pcb *pcb)
 Send an ACK without data.
err_t tcp_rexmit (struct tcp_pcb *pcb)
 Requeue the first unacked segment for retransmission.
err_t tcp_rexmit_rto_prepare (struct tcp_pcb *pcb)
 Requeue all unacked segments for retransmission.
void tcp_rexmit_rto_commit (struct tcp_pcb *pcb)
 Requeue all unacked segments for retransmission.
void tcp_rexmit_rto (struct tcp_pcb *pcb)
 Requeue all unacked segments for retransmission.
void tcp_rexmit_fast (struct tcp_pcb *pcb)
 Handle retransmission after three dupacks received.
u32_t tcp_update_rcv_ann_wnd (struct tcp_pcb *pcb)
 Update the state that tracks the available window space to advertise.
err_t tcp_process_refused_data (struct tcp_pcb *pcb)
 Pass pcb->refused_data to the recv callback.
void tcp_pcb_purge (struct tcp_pcb *pcb)
 Purges a TCP PCB.
void tcp_pcb_remove (struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
 Purges the PCB and removes it from a PCB list.
void tcp_segs_free (struct tcp_seg *seg)
 Deallocates a list of TCP segments (tcp_seg structures).
void tcp_seg_free (struct tcp_seg *seg)
 Frees a TCP segment (tcp_seg structure).
struct tcp_seg * tcp_seg_copy (struct tcp_seg *seg)
 Returns a copy of the given TCP segment.
err_t tcp_send_fin (struct tcp_pcb *pcb)
 Called by tcp_close() to send a segment including FIN flag but not data.
err_t tcp_enqueue_flags (struct tcp_pcb *pcb, u8_t flags)
 Enqueue SYN or FIN for transmission.
void tcp_rst (const struct tcp_pcb *pcb, u32_t seqno, u32_t ackno, const ip_addr_t *local_ip, const ip_addr_t *remote_ip, u16_t local_port, u16_t remote_port)
 Send a TCP RESET packet (empty segment with RST flag set) either to abort a connection or to show that there is no matching local connection for a received segment.
u32_t tcp_next_iss (struct tcp_pcb *pcb)
 Calculates a new initial sequence number for new connections.
err_t tcp_keepalive (struct tcp_pcb *pcb)
 Send keepalive packets to keep a connection active although no data is sent over it.
err_t tcp_split_unsent_seg (struct tcp_pcb *pcb, u16_t split)
 Split segment on the head of the unsent queue.
err_t tcp_zero_window_probe (struct tcp_pcb *pcb)
 Send persist timer zero-window probes to keep a connection active when a window update is lost.
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).
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.
void tcp_debug_print (struct tcp_hdr *tcphdr)
 Print a tcp header for debugging purposes.
void tcp_debug_print_flags (u8_t flags)
 Print tcp flags for debugging purposes.
void tcp_debug_print_state (enum tcp_state s)
 Print a tcp state for debugging purposes.
void tcp_debug_print_pcbs (void)
 Print all tcp_pcbs in every list for debugging purposes.
s16_t tcp_pcbs_sane (void)
 Check state consistency of the tcp_pcb lists.
void tcp_timer_needed (void)
 External function (implemented in timers.c), called when TCP detects that a timer is needed (i.e.
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.
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.

Variables

struct tcp_pcbtcp_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_pcbtcp_active_pcbs
 List of all TCP PCBs that are in a state in which they accept or send data.
struct tcp_pcbtcp_tw_pcbs
 List of all TCP PCBs in TIME-WAIT state.
struct tcp_pcb **const tcp_pcb_lists [NUM_TCP_PCB_LISTS]
 An array with all (non-temporary) PCB lists, mainly used for smaller code size.

Detailed Description

TCP internal implementations (do not use in application code)

Definition in file tcp_priv.h.


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

Definition at line 563 of file lwip_tcp.c.

struct tcp_pcb* tcp_alloc ( u8_t  prio ) [read]

Allocate a new tcp_pcb structure.

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

Definition at line 1834 of file lwip_tcp.c.

void tcp_debug_print ( struct tcp_hdr *  tcphdr )

Print a tcp header for debugging purposes.

Parameters:
tcphdrpointer to a struct tcp_hdr

Definition at line 2405 of file lwip_tcp.c.

void tcp_debug_print_flags ( u8_t  flags )

Print tcp flags for debugging purposes.

Parameters:
flagstcp flags, all active flags are printed

Definition at line 2452 of file lwip_tcp.c.

void tcp_debug_print_pcbs ( void   )

Print all tcp_pcbs in every list for debugging purposes.

Definition at line 2485 of file lwip_tcp.c.

void tcp_debug_print_state ( enum tcp_state  s )

Print a tcp state for debugging purposes.

Parameters:
senum tcp_state to print

Definition at line 2441 of file lwip_tcp.c.

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

Definition at line 2238 of file lwip_tcp.c.

err_t tcp_enqueue_flags ( struct tcp_pcb pcb,
u8_t  flags 
)

Enqueue SYN or FIN for transmission.

Called by tcp_connect, tcp_listen_input, and tcp_close (via tcp_send_fin)

Parameters:
pcbProtocol control block for the TCP connection.
flagsTCP header flags to set in the outgoing segment.

Definition at line 1032 of file lwip_tcp_out.c.

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!

Definition at line 2666 of file lwip_tcp.c.

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

Definition at line 1479 of file lwip_tcp.c.

void tcp_free ( struct tcp_pcb pcb )

Free a tcp pcb.

Definition at line 210 of file lwip_tcp.c.

void tcp_init ( void   )

Initialize this module.

Definition at line 201 of file lwip_tcp.c.

void tcp_input ( struct pbuf p,
struct netif inp 
)

The initial input processing of TCP.

It verifies the TCP header, demultiplexes the segment between the PCBs and passes it on to tcp_process(), which implements the TCP finite state machine. This function is called by the IP layer (in ip_input()).

Parameters:
preceived TCP segment to process (p->payload pointing to the TCP header)
inpnetwork interface on which this segment was received

Called from tcp_input to check for TF_CLOSED flag. This results in closing and deallocating a pcb at the correct place to ensure noone references it any more.

Returns:
1 if the pcb has been closed and deallocated, 0 otherwise

Called by tcp_input() when a segment arrives for a listening connection (from tcp_input()).

Parameters:
pcbthe tcp_pcb_listen for which a segment arrived
Note:
the segment which arrived is saved in global variables, therefore only the pcb involved is passed as a parameter to this function

Called by tcp_input() when a segment arrives for a connection in TIME_WAIT.

Parameters:
pcbthe tcp_pcb for which a segment arrived
Note:
the segment which arrived is saved in global variables, therefore only the pcb involved is passed as a parameter to this function

Implements the TCP state machine. Called by tcp_input. In some states tcp_receive() is called to receive data. The tcp_seg argument will be freed by the caller (tcp_input()) unless the recv_data pointer in the pcb is set.

Parameters:
pcbthe tcp_pcb for which a segment arrived
Note:
the segment which arrived is saved in global variables, therefore only the pcb involved is passed as a parameter to this function

Insert segment into the list (segments covered with new one will be deleted)

Called from tcp_receive()

Remove segments from a list if the incoming ACK acknowledges them

Called by tcp_process. Checks if the given segment is an ACK for outstanding data, and if so frees the memory of the buffered data. Next, it places the segment on any of the receive queues (pcb->recved or pcb->ooseq). If the segment is buffered, the pbuf is referenced by pbuf_ref so that it will not be freed until it has been removed from the buffer.

If the incoming segment constitutes an ACK for a segment that was used for RTT estimation, the RTT is estimated here as well.

Called from tcp_process().

Parses the options contained in the incoming segment.

Called from tcp_listen_input() and tcp_process(). Currently, only the MSS option is supported!

Parameters:
pcbthe tcp_pcb for which a segment arrived

Called by tcp_receive() to add new SACK entry.

The new SACK entry will be placed at the beginning of rcv_sacks[], as the newest one. Existing SACK entries will be "pushed back", to preserve their order. This is the behavior described in RFC 2018, section 4.

Parameters:
pcbthe tcp_pcb for which a segment arrived
leftthe left side of the SACK (the first sequence number)
rightthe right side of the SACK (the first sequence number past this SACK)

Called to remove a range of SACKs.

SACK entries will be removed or adjusted to not acknowledge any sequence numbers that are less than 'seq' passed. It not only invalidates entries, but also moves all entries that are still valid to the beginning.

Parameters:
pcbthe tcp_pcb to modify
seqthe lowest sequence number to keep in SACK entries

Called to remove a range of SACKs.

SACK entries will be removed or adjusted to not acknowledge any sequence numbers that are greater than (or equal to) 'seq' passed. It not only invalidates entries, but also moves all entries that are still valid to the beginning.

Parameters:
pcbthe tcp_pcb to modify
seqthe highest sequence number to keep in SACK entries

Definition at line 118 of file lwip_tcp_in.c.

err_t tcp_keepalive ( struct tcp_pcb pcb )

Send keepalive packets to keep a connection active although no data is sent over it.

Called by tcp_slowtmr()

Parameters:
pcbthe tcp_pcb for which to send a keepalive packet

Definition at line 2078 of file lwip_tcp_out.c.

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

Definition at line 2331 of file lwip_tcp.c.

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

Definition at line 2215 of file lwip_tcp.c.

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!

Definition at line 2127 of file lwip_tcp.c.

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!

Definition at line 2177 of file lwip_tcp.c.

s16_t tcp_pcbs_sane ( void   )

Check state consistency of the tcp_pcb lists.

Definition at line 2517 of file lwip_tcp.c.

err_t tcp_process_refused_data ( struct tcp_pcb pcb )

Pass pcb->refused_data to the recv callback.

Definition at line 1539 of file lwip_tcp.c.

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.

Definition at line 1684 of file lwip_tcp.c.

err_t tcp_rexmit ( struct tcp_pcb pcb )

Requeue the first unacked segment for retransmission.

Called by tcp_receive() for fast retransmit.

Parameters:
pcbthe tcp_pcb for which to retransmit the first unacked segment

Definition at line 1724 of file lwip_tcp_out.c.

void tcp_rexmit_fast ( struct tcp_pcb pcb )

Handle retransmission after three dupacks received.

Parameters:
pcbthe tcp_pcb for which to retransmit the first unacked segment

Definition at line 1783 of file lwip_tcp_out.c.

void tcp_rexmit_rto ( struct tcp_pcb pcb )

Requeue all unacked segments for retransmission.

Called by tcp_process() only, tcp_slowtmr() needs to do some things between "prepare" and "commit".

Parameters:
pcbthe tcp_pcb for which to re-enqueue all unacked segments

Definition at line 1707 of file lwip_tcp_out.c.

void tcp_rexmit_rto_commit ( struct tcp_pcb pcb )

Requeue all unacked segments for retransmission.

Called by tcp_slowtmr() for slow retransmission.

Parameters:
pcbthe tcp_pcb for which to re-enqueue all unacked segments

Definition at line 1686 of file lwip_tcp_out.c.

err_t tcp_rexmit_rto_prepare ( struct tcp_pcb pcb )

Requeue all unacked segments for retransmission.

Called by tcp_slowtmr() for slow retransmission.

Parameters:
pcbthe tcp_pcb for which to re-enqueue all unacked segments

Definition at line 1631 of file lwip_tcp_out.c.

void tcp_rst ( const struct tcp_pcb pcb,
u32_t  seqno,
u32_t  ackno,
const ip_addr_t local_ip,
const ip_addr_t remote_ip,
u16_t  local_port,
u16_t  remote_port 
)

Send a TCP RESET packet (empty segment with RST flag set) either to abort a connection or to show that there is no matching local connection for a received segment.

Called by tcp_abort() (to abort a local connection), tcp_input() (if no matching local pcb was found), tcp_listen_input() (if incoming segment has ACK flag set) and tcp_process() (received segment in the wrong state)

Since a RST segment is in most cases not sent for an active connection, tcp_rst() has a number of arguments that are taken from a tcp_pcb for most other segment output functions.

Parameters:
pcbTCP pcb (may be NULL if no pcb is available)
seqnothe sequence number to use for the outgoing segment
acknothe acknowledge number to use for the outgoing segment
local_ipthe local IP address to send the segment from
remote_ipthe remote IP address to send the segment to
local_portthe local TCP port to send the segment from
remote_portthe remote TCP port to send the segment to

Definition at line 1980 of file lwip_tcp_out.c.

struct tcp_seg* tcp_seg_copy ( struct tcp_seg *  seg ) [read]

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

Definition at line 1662 of file lwip_tcp.c.

void tcp_seg_free ( struct tcp_seg *  seg )

Frees a TCP segment (tcp_seg structure).

Parameters:
segsingle tcp_seg to free

Definition at line 1623 of file lwip_tcp.c.

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

Definition at line 1608 of file lwip_tcp.c.

err_t tcp_send_empty_ack ( struct tcp_pcb pcb )

Send an ACK without data.

Parameters:
pcbProtocol control block for the TCP connection to send the ACK

Definition at line 2019 of file lwip_tcp_out.c.

err_t tcp_send_fin ( struct tcp_pcb pcb )

Called by tcp_close() to send a segment including FIN flag but not data.

This FIN may be added to an existing segment or a new, otherwise empty segment is enqueued.

Parameters:
pcbthe tcp_pcb over which to send a segment
Returns:
ERR_OK if sent, another err_t otherwise

Definition at line 1001 of file lwip_tcp_out.c.

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

Definition at line 1192 of file lwip_tcp.c.

err_t tcp_split_unsent_seg ( struct tcp_pcb pcb,
u16_t  split 
)

Split segment on the head of the unsent queue.

If return is not ERR_OK, existing head remains intact

The split is accomplished by creating a new TCP segment and pbuf which holds the remainder payload after the split. The original pbuf is trimmed to new length. This allows splitting of read-only pbufs

Parameters:
pcbthe tcp_pcb for which to split the unsent head
splitthe amount of payload to remain in the head

Definition at line 827 of file lwip_tcp_out.c.

void tcp_timer_needed ( void   )

External function (implemented in timers.c), called when TCP detects that a timer is needed (i.e.

active- or time-wait-pcb found).

Definition at line 166 of file lwip_timeouts.c.

void tcp_tmr ( void   )

Called periodically to dispatch TCP timers.

Definition at line 234 of file lwip_tcp.c.

void tcp_txnow ( void   )

Call tcp_output for all active pcbs that have TF_NAGLEMEMERR set.

Definition at line 1526 of file lwip_tcp.c.

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.

Definition at line 930 of file lwip_tcp.c.

err_t tcp_zero_window_probe ( struct tcp_pcb pcb )

Send persist timer zero-window probes to keep a connection active when a window update is lost.

Called by tcp_slowtmr()

Parameters:
pcbthe tcp_pcb for which to send a zero-window probe packet

Definition at line 2116 of file lwip_tcp_out.c.


Variable Documentation

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

Definition at line 176 of file lwip_tcp.c.

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

Definition at line 171 of file lwip_tcp.c.

union tcp_listen_pcbs_t tcp_listen_pcbs

List of all TCP PCBs in LISTEN state.

Definition at line 173 of file lwip_tcp.c.

struct tcp_pcb** const tcp_pcb_lists[NUM_TCP_PCB_LISTS]

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

Definition at line 181 of file lwip_tcp.c.

List of all TCP PCBs in TIME-WAIT state.

Definition at line 178 of file lwip_tcp.c.