# tcp.h File Reference

`#include "net/sys.h"`
`#include "net/mem.h"`
`#include "net/pbuf.h"`
`#include "net/opt.h"`
`#include "net/ipv4/ip.h"`
`#include "net/ipv4/icmp.h"`
`#include "net/err.h"`

Go to the source code of this file.

## Data Structures

struct | tcp_hdr
struct | tcp_pcb
struct | tcp_pcb_listen
struct | tcp_seg

## Defines

#define | tcp_ack(pcb)
#define | TCP_ACK 0x10
#define | tcp_ack_now(pcb)
#define | TCP_FAST_INTERVAL 200
#define | TCP_FIN 0x01
#define | TCP_FIN_WAIT_TIMEOUT 20000
#define | TCP_HLEN 20
#define | TCP_MSL 60000
#define | TCP_OOSEQ_TIMEOUT 6
#define | tcp_pcbs_sane() 1
#define | TCP_PSH 0x08
#define | TCP_REG(pcbs, npcb)
#define | TCP_RMV(pcbs, npcb)
#define | TCP_RST 0x04
#define | TCP_SEQ_GEQ(a, b) ((Int32)((a)-(b)) >= 0)
#define | TCP_SEQ_GT(a, b) ((Int32)((a)-(b)) > 0)
#define | TCP_SEQ_LEQ(a, b) ((Int32)((a)-(b)) <= 0)
#define | TCP_SEQ_LT(a, b) ((Int32)((a)-(b)) < 0)
#define | TCP_SLOW_INTERVAL 500
#define | tcp_sndbuf(pcb) ((pcb)->snd_buf)
#define | TCP_SYN 0x02
#define | TCP_SYN_RCVD_TIMEOUT 20000
#define | TCP_TCPLEN(seg)
#define | TCP_TMR_INTERVAL 100
#define | TCP_URG 0x20
#define | TCPH_FLAGS(hdr) (NTOHS((hdr)->_offset_flags) & 0xff)
#define | TCPH_FLAGS_SET(hdr, flags) (hdr)->_offset_flags = HTONS((TCPH_OFFSET(hdr) << 8) | (flags))
#define | TCPH_OFFSET(hdr) (NTOHS((hdr)->_offset_flags) >> 8)
#define | TCPH_OFFSET_SET(hdr, offset) (hdr)->_offset_flags = HTONS(((offset) << 8) | TCPH_FLAGS(hdr))
#define | TF_ACK_DELAY 0x01
#define | TF_ACK_NOW 0x02
#define | TF_CLOSED 0x10
#define | TF_GOT_FIN 0x20
#define | TF_INFR 0x04
#define | TF_RESET 0x08

## Enumerations

enum | tcp_state { CLOSED = 0, LISTEN = 1, SYN_SENT = 2, SYN_RCVD = 3, ESTABLISHED = 4, FIN_WAIT_1 = 5, FIN_WAIT_2 = 6, CLOSE_WAIT = 7, CLOSING = 8, LAST_ACK = 9, TIME_WAIT = 10 }

## Functions

void | tcp_abort (struct tcp_pcb *pcb)
void | tcp_accept (struct tcp_pcb *pcb, err_t(*accept)(void *arg, struct tcp_pcb *newpcb, err_t err))
void | tcp_arg (struct tcp_pcb *pcb, void *arg)
err_t | tcp_bind (struct tcp_pcb *pcb, struct ip_addr *ipaddr, uInt16 port)
err_t | tcp_close (struct tcp_pcb *pcb)
err_t | tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr, uInt16 port, err_t(*connected)(void *arg, struct tcp_pcb *tpcb, err_t err))
err_t | tcp_enqueue (struct tcp_pcb *pcb, void *dataptr, uInt16 len, uInt8 flags, uInt8 copy, uInt8 *optdata, uInt8 optlen)
void | tcp_err (struct tcp_pcb *pcb, void(*err)(void *arg, err_t err))
void | tcp_fasttmr (void)
void | tcp_init (void)
void | tcp_input (struct pbuf *p, struct netif *inp)
tcp_pcb * | tcp_listen (struct tcp_pcb *pcb)
tcp_pcb * | tcp_new (void)
uInt32 | tcp_next_iss (void)
err_t | tcp_output (struct tcp_pcb *pcb)
tcp_pcb * | tcp_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_poll (struct tcp_pcb *pcb, err_t(*poll)(void *arg, struct tcp_pcb *tpcb), uInt8 interval)
void | tcp_recv (struct tcp_pcb *pcb, err_t(*recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err))
void | tcp_recved (struct tcp_pcb *pcb, uInt16 len)
void | tcp_rexmit_seg (struct tcp_pcb *pcb, struct tcp_seg *seg)
void | tcp_rst (uInt32 seqno, uInt32 ackno, struct ip_addr *local_ip, struct ip_addr *remote_ip, uInt16 local_port, uInt16 remote_port)
tcp_seg * | tcp_seg_copy (struct tcp_seg *seg)
uInt8 | tcp_seg_free (struct tcp_seg *seg)
uInt8 | tcp_segs_free (struct tcp_seg *seg)
err_t | tcp_send_ctrl (struct tcp_pcb *pcb, uInt8 flags)
void | tcp_sent (struct tcp_pcb *pcb, err_t(*sent)(void *arg, struct tcp_pcb *tpcb, uInt16 len))
void | tcp_slowtmr (void)
void | tcp_tmr (void)
err_t | tcp_write (struct tcp_pcb *pcb, const void *dataptr, uInt16 len, uInt8 copy)

## Variables

tcp_hdr | PACK_STRUCT_STRUCT
tcp_pcb * | tcp_active_pcbs
tcp_pcb_listen * | tcp_listen_pcbs
uInt32 | tcp_ticks
tcp_pcb * | tcp_tmp_pcb
tcp_pcb * | tcp_tw_pcbs

## Define Documentation

#define tcp_ack | ( | pcb |  | ) |

Value:

    if((pcb)->flags & TF_ACK_DELAY) { \
                                (pcb)->flags |= TF_ACK_NOW; \
                                tcp_output(pcb); \
                             } else { \
                                (pcb)->flags |= TF_ACK_DELAY; \
                             }

Definition at line 297 of file tcp.h.

#define TCP_ACK 0x10

Definition at line 119 of file tcp.h.

#define tcp_ack_now | ( | pcb |  | ) |

Value:

    (pcb)->flags |= TF_ACK_NOW; \
                             tcp_output(pcb)

Definition at line 304 of file tcp.h.

#define TCP_FAST_INTERVAL 200

Definition at line 128 of file tcp.h.

#define TCP_FIN 0x01

Definition at line 115 of file tcp.h.

#define TCP_FIN_WAIT_TIMEOUT 20000

Definition at line 132 of file tcp.h.

#define TCP_HLEN 20

Definition at line 123 of file tcp.h.

#define TCP_MSL 60000

Definition at line 137 of file tcp.h.

#define TCP_OOSEQ_TIMEOUT 6

Definition at line 135 of file tcp.h.

#define tcp_pcbs_sane | ( |  | ) | 1

Definition at line 329 of file tcp.h.

#define TCP_PSH 0x08

Definition at line 118 of file tcp.h.

#define TCP_REG | ( | pcbs,
|  | npcb |  | ) |

Value:

    do { \
                                npcb->next = *pcbs; \
                                *pcbs = npcb; \
                                } while(0)

Definition at line 382 of file tcp.h.

#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 != NULL && tcp_tmp_pcb->next == npcb) { \
                                      tcp_tmp_pcb->next = npcb->next; \
                                      break; \
                                   } \
                                } \
                                npcb->next = NULL; \
                                } while(0)

Definition at line 386 of file tcp.h.

#define TCP_RST 0x04

Definition at line 117 of file tcp.h.

#define TCP_SEQ_GEQ | ( | a,
|  | b |  | ) | ((Int32)((a)-(b)) >= 0)

Definition at line 113 of file tcp.h.

#define TCP_SEQ_GT | ( | a,
|  | b |  | ) | ((Int32)((a)-(b)) > 0)

Definition at line 112 of file tcp.h.

#define TCP_SEQ_LEQ | ( | a,
|  | b |  | ) | ((Int32)((a)-(b)) <= 0)

Definition at line 111 of file tcp.h.

#define TCP_SEQ_LT | ( | a,
|  | b |  | ) | ((Int32)((a)-(b)) < 0)

Definition at line 110 of file tcp.h.

#define TCP_SLOW_INTERVAL 500

Definition at line 130 of file tcp.h.

#define tcp_sndbuf | ( | pcb |  | ) | ((pcb)->snd_buf)

Definition at line 81 of file tcp.h.

Referenced by netconn_write().

#define TCP_SYN 0x02

Definition at line 116 of file tcp.h.

#define TCP_SYN_RCVD_TIMEOUT 20000

Definition at line 133 of file tcp.h.

#define TCP_TCPLEN | ( | seg |  | ) |

Value:

    ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & TCP_FIN || \
                                            TCPH_FLAGS((seg)->tcphdr) & TCP_SYN)? 1: 0))

Definition at line 156 of file tcp.h.

#define TCP_TMR_INTERVAL 100

Definition at line 125 of file tcp.h.

Referenced by tcpip_tcp_timer(), and tcpip_thread().

#define TCP_URG 0x20

Definition at line 120 of file tcp.h.

#define TCPH_FLAGS | ( | hdr |  | ) | (NTOHS((hdr)->_offset_flags) & 0xff)

Definition at line 151 of file tcp.h.

#define TCPH_FLAGS_SET | ( | hdr,
|  | flags |  | ) | (hdr)->_offset_flags = HTONS((TCPH_OFFSET(hdr) << 8) | (flags))

Definition at line 154 of file tcp.h.

#define TCPH_OFFSET | ( | hdr |  | ) | (NTOHS((hdr)->_offset_flags) >> 8)

Definition at line 150 of file tcp.h.

#define TCPH_OFFSET_SET | ( | hdr,
|  | offset |  | ) | (hdr)->_offset_flags = HTONS(((offset) << 8) | TCPH_FLAGS(hdr))

Definition at line 153 of file tcp.h.

#define TF_ACK_DELAY 0x01

Definition at line 204 of file tcp.h.

#define TF_ACK_NOW 0x02

Definition at line 205 of file tcp.h.

#define TF_CLOSED 0x10

Definition at line 208 of file tcp.h.

#define TF_GOT_FIN 0x20

Definition at line 209 of file tcp.h.

#define TF_INFR 0x04

Definition at line 206 of file tcp.h.

#define TF_RESET 0x08

Definition at line 207 of file tcp.h.

## Enumeration Type Documentation

enum tcp_state

Enumerator:

  CLOSED |
  LISTEN |
  SYN_SENT |
  SYN_RCVD |
  ESTABLISHED |
  FIN_WAIT_1 |
  FIN_WAIT_2 |
  CLOSE_WAIT |
  CLOSING |
  LAST_ACK |
  TIME_WAIT |

Definition at line 159 of file tcp.h.

## Function Documentation

void tcp_abort | ( | struct tcp_pcb * | pcb | ) |

Referenced by do_delconn().

void tcp_accept | ( | struct tcp_pcb * | pcb,
|  | err_t(*)(void *arg, struct tcp_pcb *newpcb, err_t err) | accept |
| ) |  |  |

Referenced by do_delconn(), and do_listen().

void tcp_arg | ( | struct tcp_pcb * | pcb,
|  | void * | arg |
| ) |  |  |

Referenced by do_delconn(), do_listen(), and setup_tcp().

err_t tcp_bind | ( | struct tcp_pcb * | pcb,
|  | struct ip_addr * | ipaddr,
|  | uInt16 | port |
| ) |  |  |

Referenced by do_bind().

err_t tcp_close | ( | struct tcp_pcb * | pcb | ) |

Referenced by do_close(), and do_delconn().

err_t tcp_connect | ( | struct tcp_pcb * | pcb,
|  | struct ip_addr * | ipaddr,
|  | uInt16 | port,
|  | err_t(*)(void *arg, struct tcp_pcb *tpcb, err_t err) | connected |
| ) |  |  |

Referenced by do_connect().

err_t tcp_enqueue | ( | struct tcp_pcb * | pcb,
|  | void * | dataptr,
|  | uInt16 | len,
|  | uInt8 | flags,
|  | uInt8 | copy,
|  | uInt8 * | optdata,
|  | uInt8 | optlen |
| ) |  |  |

void tcp_err | ( | struct tcp_pcb * | pcb,
|  | void(*)(void *arg, err_t err) | err |
| ) |  |  |

Referenced by do_delconn(), and setup_tcp().

void tcp_fasttmr | ( | void |  | ) |

void tcp_init | ( | void |  | ) |

Referenced by tcpip_thread().

void tcp_input | ( | struct pbuf * | p,
|  | struct netif * | inp |
| ) |  |  |

struct tcp_pcb* tcp_listen | ( | struct tcp_pcb * | pcb | ) |

Referenced by do_listen().

struct tcp_pcb* tcp_new | ( | void |  | ) |

Referenced by do_bind(), and do_connect().

uInt32 tcp_next_iss | ( | void |  | ) |

err_t tcp_output | ( | struct tcp_pcb * | pcb | ) |

Referenced by do_write().

struct tcp_pcb* tcp_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_poll | ( | struct tcp_pcb * | pcb,
|  | err_t(*)(void *arg, struct tcp_pcb *tpcb) | poll,
|  | uInt8 | interval |
| ) |  |  |

Referenced by do_delconn(), and setup_tcp().

void tcp_recv | ( | struct tcp_pcb * | pcb,
|  | err_t(*)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) | recv |
| ) |  |  |

Referenced by do_delconn(), and setup_tcp().

void tcp_recved | ( | struct tcp_pcb * | pcb,
|  | uInt16 | len |
| ) |  |  |

Referenced by do_recv().

void tcp_rexmit_seg | ( | struct tcp_pcb * | pcb,
|  | struct tcp_seg * | seg |
| ) |  |  |

void tcp_rst | ( | uInt32 | seqno,
|  | uInt32 | ackno,
|  | struct ip_addr * | local_ip,
|  | struct ip_addr * | remote_ip,
|  | uInt16 | local_port,
|  | uInt16 | remote_port |
| ) |  |  |

struct tcp_seg* tcp_seg_copy | ( | struct tcp_seg * | seg | ) |

uInt8 tcp_seg_free | ( | struct tcp_seg * | seg | ) |

uInt8 tcp_segs_free | ( | struct tcp_seg * | seg | ) |

err_t tcp_send_ctrl | ( | struct tcp_pcb * | pcb,
|  | uInt8 | flags |
| ) |  |  |

void tcp_sent | ( | struct tcp_pcb * | pcb,
|  | err_t(*)(void *arg, struct tcp_pcb *tpcb, uInt16 len) | sent |
| ) |  |  |

Referenced by do_delconn(), and setup_tcp().

void tcp_slowtmr | ( | void |  | ) |

void tcp_tmr | ( | void |  | ) |

Referenced by tcpip_tcp_timer().

err_t tcp_write | ( | struct tcp_pcb * | pcb,
|  | const void * | dataptr,
|  | uInt16 | len,
|  | uInt8 | copy |
| ) |  |  |

Referenced by do_write().

## Variable Documentation

struct tcp_hdr PACK_STRUCT_STRUCT

struct tcp_pcb* tcp_active_pcbs

struct tcp_pcb_listen* tcp_listen_pcbs

uInt32 tcp_ticks

struct tcp_pcb* tcp_tmp_pcb

struct tcp_pcb* tcp_tw_pcbs