Classes | Defines | Functions | Variables

alexb/lib/lwip/contrib/src/include/lwip/tcp_impl.h File Reference

#include "lwip/opt.h"
#include "lwip/tcp.h"
#include "lwip/sys.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/ip.h"
#include "lwip/icmp.h"
#include "lwip/err.h"

Classes

struct  tcp_hdr
struct  tcp_seg
union  tcp_listen_pcbs_t

Defines

#define tcp_init()
#define tcp_do_output_nagle(tpcb)
 This is the Nagle algorithm: try to combine user data to send as few TCP segments as possible.
#define tcp_output_nagle(tpcb)   (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK)
#define TCP_SEQ_LT(a, b)   ((s32_t)((a)-(b)) < 0)
#define TCP_SEQ_LEQ(a, b)   ((s32_t)((a)-(b)) <= 0)
#define TCP_SEQ_GT(a, b)   ((s32_t)((a)-(b)) > 0)
#define TCP_SEQ_GEQ(a, b)   ((s32_t)((a)-(b)) >= 0)
#define TCP_SEQ_BETWEEN(a, b, c)   (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
#define TCP_FIN   0x01U
#define TCP_SYN   0x02U
#define TCP_RST   0x04U
#define TCP_PSH   0x08U
#define TCP_ACK   0x10U
#define TCP_URG   0x20U
#define TCP_ECE   0x40U
#define TCP_CWR   0x80U
#define TCP_FLAGS   0x3fU
#define TCP_HLEN   20
#define TCP_TMR_INTERVAL   250
#define TCP_FAST_INTERVAL   TCP_TMR_INTERVAL
#define TCP_SLOW_INTERVAL   (2*TCP_TMR_INTERVAL)
#define TCP_FIN_WAIT_TIMEOUT   20000
#define TCP_SYN_RCVD_TIMEOUT   20000
#define TCP_OOSEQ_TIMEOUT   6U
#define TCP_MSL   60000UL
#define TCP_KEEPIDLE_DEFAULT   7200000UL
#define TCP_KEEPINTVL_DEFAULT   75000UL
#define TCP_KEEPCNT_DEFAULT   9U
#define TCP_MAXIDLE   TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT
#define TCPH_OFFSET(phdr)   (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
#define TCPH_HDRLEN(phdr)   (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
#define TCPH_FLAGS(phdr)   (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
#define TCPH_OFFSET_SET(phdr, offset)   (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
#define TCPH_HDRLEN_SET(phdr, len)   (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
#define TCPH_FLAGS_SET(phdr, flags)   (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS((u16_t)(~(u16_t)(TCP_FLAGS)))) | htons(flags))
#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags)   (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags))
#define TCPH_SET_FLAG(phdr, flags)   (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
#define TCPH_UNSET_FLAG(phdr, flags)   (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
#define TCP_TCPLEN(seg)   ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
#define TF_RESET   (u8_t)0x08U
 Flags used on input processing, not on pcb->flags.
#define TF_CLOSED   (u8_t)0x10U
#define TF_GOT_FIN   (u8_t)0x20U
#define TCP_EVENT_ACCEPT(pcb, err, ret)
#define TCP_EVENT_SENT(pcb, space, ret)
#define TCP_EVENT_RECV(pcb, p, err, ret)
#define TCP_EVENT_CLOSED(pcb, ret)
#define TCP_EVENT_CONNECTED(pcb, err, ret)
#define TCP_EVENT_POLL(pcb, ret)
#define TCP_EVENT_ERR(errf, arg, err)
#define TCP_OVERSIZE_DBGCHECK   0
 Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled.
#define TCP_CHECKSUM_ON_COPY   (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP)
 Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled.
#define TF_SEG_OPTS_MSS   (u8_t)0x01U
#define TF_SEG_OPTS_TS   (u8_t)0x02U
#define TF_SEG_DATA_CHECKSUMMED   (u8_t)0x04U
#define LWIP_TCP_OPT_LENGTH(flags)
#define TCP_BUILD_MSS_OPTION(x)
 This returns a TCP header option for MSS in an u32_t.
#define TCP_DEBUG_PCB_LISTS   0
#define TCP_REG(pcbs, npcb)
#define TCP_RMV(pcbs, npcb)
#define tcp_ack(pcb)
#define tcp_ack_now(pcb)
#define tcp_debug_print(tcphdr)
#define tcp_debug_print_flags(flags)
#define tcp_debug_print_state(s)
#define tcp_debug_print_pcbs()
#define tcp_pcbs_sane()   1

Functions

void tcp_tmr (void)
void tcp_slowtmr (void)
void tcp_fasttmr (void)
void tcp_input (struct pbuf *p, struct netif *inp)
struct tcp_pcbtcp_alloc (u8_t prio)
void tcp_abandon (struct tcp_pcb *pcb, int reset)
err_t tcp_send_empty_ack (struct tcp_pcb *pcb)
void tcp_rexmit (struct tcp_pcb *pcb)
void tcp_rexmit_rto (struct tcp_pcb *pcb)
void tcp_rexmit_fast (struct tcp_pcb *pcb)
u32_t tcp_update_rcv_ann_wnd (struct tcp_pcb *pcb)
struct tcp_pcbtcp_pcb_copy (struct tcp_pcb *pcb)
void tcp_pcb_purge (struct tcp_pcb *pcb)
void tcp_pcb_remove (struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
void tcp_segs_free (struct tcp_seg *seg)
void tcp_seg_free (struct tcp_seg *seg)
struct tcp_segtcp_seg_copy (struct tcp_seg *seg)
err_t tcp_send_fin (struct tcp_pcb *pcb)
err_t tcp_enqueue_flags (struct tcp_pcb *pcb, u8_t flags)
void tcp_rexmit_seg (struct tcp_pcb *pcb, struct tcp_seg *seg)
void tcp_rst (u32_t seqno, u32_t ackno, ip_addr_t *local_ip, ip_addr_t *remote_ip, u16_t local_port, u16_t remote_port)
u32_t tcp_next_iss (void)
void tcp_keepalive (struct tcp_pcb *pcb)
void tcp_zero_window_probe (struct tcp_pcb *pcb)
u16_t tcp_eff_send_mss (u16_t sendmss, ip_addr_t *addr)
err_t tcp_recv_null (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
void tcp_timer_needed (void)
 External function (implemented in timers.c), called when TCP detects that a timer is needed (i.e.

Variables

PACK_STRUCT_BEGIN struct tcp_hdr PACK_STRUCT_STRUCT
struct tcp_pcbtcp_input_pcb
u32_t tcp_ticks
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_pcbtcp_tmp_pcb

Define Documentation

#define LWIP_TCP_OPT_LENGTH (   flags  ) 
Value:
(flags & TF_SEG_OPTS_MSS ? 4  : 0) +          \
  (flags & TF_SEG_OPTS_TS  ? 12 : 0)
#define TCP_ACK   0x10U
#define tcp_ack (   pcb  ) 
Value:
do {                                             \
    if((pcb)->flags & TF_ACK_DELAY) {              \
      (pcb)->flags &= ~TF_ACK_DELAY;               \
      (pcb)->flags |= TF_ACK_NOW;                  \
    }                                              \
    else {                                         \
      (pcb)->flags |= TF_ACK_DELAY;                \
    }                                              \
  } while (0)
#define tcp_ack_now (   pcb  ) 
Value:
do {                                             \
    (pcb)->flags |= TF_ACK_NOW;                    \
  } while (0)
#define TCP_BUILD_MSS_OPTION (   x  ) 
Value:
(x) = PP_HTONL(((u32_t)2 << 24) |          \
                                               ((u32_t)4 << 16) |          \
                                               (((u32_t)TCP_MSS / 256) << 8) | \
                                               (TCP_MSS & 255))

This returns a TCP header option for MSS in an u32_t.

#define TCP_CHECKSUM_ON_COPY   (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP)

Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled.

#define TCP_CWR   0x80U
#define TCP_DEBUG_PCB_LISTS   0
#define tcp_debug_print (   tcphdr  ) 
#define tcp_debug_print_flags (   flags  ) 
#define tcp_debug_print_pcbs (  ) 
#define tcp_debug_print_state (   s  ) 
#define tcp_do_output_nagle (   tpcb  ) 
Value:
((((tpcb)->unacked == NULL) || \
                            ((tpcb)->flags & (TF_NODELAY | TF_INFR)) || \
                            (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \
                              ((tpcb)->unsent->len >= (tpcb)->mss))) \
                            ) ? 1 : 0)

This is the Nagle algorithm: try to combine user data to send as few TCP segments as possible.

Only send if

  • no previously transmitted data on the connection remains unacknowledged or
  • the TF_NODELAY flag is set (nagle algorithm turned off for this pcb) or
  • the only unsent segment is at least pcb->mss bytes long (or there is more than one unsent segment - with lwIP, this can happen although unsent->len < mss)
  • or if we are in fast-retransmit (TF_INFR)
#define TCP_ECE   0x40U
#define TCP_EVENT_ACCEPT (   pcb,
  err,
  ret 
)
Value:
do {                                                         \
    if((pcb)->accept != NULL)                                  \
      (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err));  \
    else (ret) = ERR_ARG;                                      \
  } while (0)
#define TCP_EVENT_CLOSED (   pcb,
  ret 
)
Value:
do {                                                           \
    if(((pcb)->recv != NULL)) {                                  \
      (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),NULL,ERR_OK);\
    } else {                                                     \
      (ret) = ERR_OK;                                            \
    }                                                            \
  } while (0)
#define TCP_EVENT_CONNECTED (   pcb,
  err,
  ret 
)
Value:
do {                                                           \
    if((pcb)->connected != NULL)                                 \
      (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \
    else (ret) = ERR_OK;                                         \
  } while (0)
#define TCP_EVENT_ERR (   errf,
  arg,
  err 
)
Value:
do {                                                         \
    if((errf) != NULL)                                         \
      (errf)((arg),(err));                                     \
  } while (0)
#define TCP_EVENT_POLL (   pcb,
  ret 
)
Value:
do {                                                         \
    if((pcb)->poll != NULL)                                    \
      (ret) = (pcb)->poll((pcb)->callback_arg,(pcb));          \
    else (ret) = ERR_OK;                                       \
  } while (0)
#define TCP_EVENT_RECV (   pcb,
  p,
  err,
  ret 
)
Value:
do {                                                         \
    if((pcb)->recv != NULL) {                                  \
      (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));\
    } else {                                                   \
      (ret) = tcp_recv_null(NULL, (pcb), (p), (err));          \
    }                                                          \
  } while (0)
#define TCP_EVENT_SENT (   pcb,
  space,
  ret 
)
Value:
do {                                                         \
    if((pcb)->sent != NULL)                                    \
      (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space));  \
    else (ret) = ERR_OK;                                       \
  } while (0)
#define TCP_FAST_INTERVAL   TCP_TMR_INTERVAL
#define TCP_FIN   0x01U
#define TCP_FIN_WAIT_TIMEOUT   20000
#define TCP_FLAGS   0x3fU
#define TCP_HLEN   20
#define tcp_init (  ) 
#define TCP_KEEPCNT_DEFAULT   9U
#define TCP_KEEPIDLE_DEFAULT   7200000UL
#define TCP_KEEPINTVL_DEFAULT   75000UL
#define TCP_MAXIDLE   TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT
#define TCP_MSL   60000UL
#define TCP_OOSEQ_TIMEOUT   6U
#define tcp_output_nagle (   tpcb  )     (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK)
#define TCP_OVERSIZE_DBGCHECK   0

Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled.

#define tcp_pcbs_sane (  )     1
#define TCP_PSH   0x08U
#define TCP_REG (   pcbs,
  npcb 
)
Value:
do {                                             \
    (npcb)->next = *pcbs;                          \
    *(pcbs) = (npcb);                              \
    tcp_timer_needed();                            \
  } while (0)
#define TCP_RMV (   pcbs,
  npcb 
)
Value:
do {                                             \
    if(*(pcbs) == (npcb)) {                        \
      (*(pcbs)) = (*pcbs)->next;                   \
    }                                              \
    else {                                         \
      for(tcp_tmp_pcb = *pcbs;                     \
          tcp_tmp_pcb != NULL;                     \
          tcp_tmp_pcb = tcp_tmp_pcb->next) {       \
        if(tcp_tmp_pcb->next == (npcb)) {          \
          tcp_tmp_pcb->next = (npcb)->next;        \
          break;                                   \
        }                                          \
      }                                            \
    }                                              \
    (npcb)->next = NULL;                           \
  } while(0)
#define TCP_RST   0x04U
#define TCP_SEQ_BETWEEN (   a,
  b,
  c 
)    (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
#define TCP_SEQ_GEQ (   a,
  b 
)    ((s32_t)((a)-(b)) >= 0)
#define TCP_SEQ_GT (   a,
  b 
)    ((s32_t)((a)-(b)) > 0)
#define TCP_SEQ_LEQ (   a,
  b 
)    ((s32_t)((a)-(b)) <= 0)
#define TCP_SEQ_LT (   a,
  b 
)    ((s32_t)((a)-(b)) < 0)
#define TCP_SLOW_INTERVAL   (2*TCP_TMR_INTERVAL)
#define TCP_SYN   0x02U
#define TCP_SYN_RCVD_TIMEOUT   20000
#define TCP_TCPLEN (   seg  )     ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
#define TCP_TMR_INTERVAL   250
#define TCP_URG   0x20U
#define TCPH_FLAGS (   phdr  )     (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
#define TCPH_FLAGS_SET (   phdr,
  flags 
)    (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS((u16_t)(~(u16_t)(TCP_FLAGS)))) | htons(flags))
#define TCPH_HDRLEN (   phdr  )     (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
#define TCPH_HDRLEN_FLAGS_SET (   phdr,
  len,
  flags 
)    (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags))
#define TCPH_HDRLEN_SET (   phdr,
  len 
)    (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
#define TCPH_OFFSET (   phdr  )     (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
#define TCPH_OFFSET_SET (   phdr,
  offset 
)    (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
#define TCPH_SET_FLAG (   phdr,
  flags 
)    (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
#define TCPH_UNSET_FLAG (   phdr,
  flags 
)    (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
#define TF_CLOSED   (u8_t)0x10U
#define TF_GOT_FIN   (u8_t)0x20U
#define TF_RESET   (u8_t)0x08U

Flags used on input processing, not on pcb->flags.

#define TF_SEG_DATA_CHECKSUMMED   (u8_t)0x04U
#define TF_SEG_OPTS_MSS   (u8_t)0x01U
#define TF_SEG_OPTS_TS   (u8_t)0x02U

Function Documentation

void tcp_abandon ( struct tcp_pcb pcb,
int  reset 
)
struct tcp_pcb* tcp_alloc ( u8_t  prio  )  [read]
u16_t tcp_eff_send_mss ( u16_t  sendmss,
ip_addr_t addr 
)
err_t tcp_enqueue_flags ( struct tcp_pcb pcb,
u8_t  flags 
)
void tcp_fasttmr ( void   ) 
void tcp_input ( struct pbuf p,
struct netif inp 
)
void tcp_keepalive ( struct tcp_pcb pcb  ) 
u32_t tcp_next_iss ( void   ) 
struct tcp_pcb* tcp_pcb_copy ( struct tcp_pcb pcb  )  [read]
void tcp_pcb_purge ( struct tcp_pcb pcb  ) 
void tcp_pcb_remove ( struct tcp_pcb **  pcblist,
struct tcp_pcb pcb 
)
err_t tcp_recv_null ( void *  arg,
struct tcp_pcb pcb,
struct pbuf p,
err_t  err 
)
void tcp_rexmit ( struct tcp_pcb pcb  ) 
void tcp_rexmit_fast ( struct tcp_pcb pcb  ) 
void tcp_rexmit_rto ( struct tcp_pcb pcb  ) 
void tcp_rexmit_seg ( struct tcp_pcb pcb,
struct tcp_seg seg 
)
void tcp_rst ( u32_t  seqno,
u32_t  ackno,
ip_addr_t local_ip,
ip_addr_t remote_ip,
u16_t  local_port,
u16_t  remote_port 
)
struct tcp_seg* tcp_seg_copy ( struct tcp_seg seg  )  [read]
void tcp_seg_free ( struct tcp_seg seg  ) 
void tcp_segs_free ( struct tcp_seg seg  ) 
err_t tcp_send_empty_ack ( struct tcp_pcb pcb  ) 
err_t tcp_send_fin ( struct tcp_pcb pcb  ) 
void tcp_slowtmr ( void   ) 
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).

void tcp_tmr ( void   ) 
u32_t tcp_update_rcv_ann_wnd ( struct tcp_pcb pcb  ) 
void tcp_zero_window_probe ( struct tcp_pcb pcb  ) 

Variable Documentation

PACK_STRUCT_BEGIN struct tcp_hdr PACK_STRUCT_STRUCT
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines