38 #ifndef LWIP_HDR_TCP_H
39 #define LWIP_HDR_TCP_H
68 typedef err_t (*tcp_accept_fn)(
void *arg,
struct tcp_pcb *newpcb,
err_t err);
80 typedef err_t (*tcp_recv_fn)(
void *arg,
struct tcp_pcb *tpcb,
94 typedef err_t (*tcp_sent_fn)(
void *arg,
struct tcp_pcb *tpcb,
106 typedef err_t (*tcp_poll_fn)(
void *arg,
struct tcp_pcb *tpcb);
118 typedef void (*tcp_err_fn)(
void *arg,
err_t err);
132 typedef err_t (*tcp_connected_fn)(
void *arg,
struct tcp_pcb *tpcb,
err_t err);
135 #define RCV_WND_SCALE(pcb, wnd) (((wnd) >> (pcb)->rcv_scale))
136 #define SND_WND_SCALE(pcb, wnd) (((wnd) << (pcb)->snd_scale))
137 #define TCPWND16(x) ((u16_t)LWIP_MIN((x), 0xFFFF))
138 #define TCP_WND_MAX(pcb) ((tcpwnd_size_t)(((pcb)->flags & TF_WND_SCALE) ? TCP_WND : TCPWND16(TCP_WND)))
139 typedef u32_t tcpwnd_size_t;
141 #define RCV_WND_SCALE(pcb, wnd) (wnd)
142 #define SND_WND_SCALE(pcb, wnd) (wnd)
143 #define TCPWND16(x) (x)
144 #define TCP_WND_MAX(pcb) TCP_WND
145 typedef u16_t tcpwnd_size_t;
148 #if LWIP_WND_SCALE || TCP_LISTEN_BACKLOG || LWIP_TCP_TIMESTAMPS
149 typedef u16_t tcpflags_t;
151 typedef u8_t tcpflags_t;
171 #define TCP_PCB_COMMON(type) \
173 void *callback_arg; \
174 enum tcp_state state; \
181 struct tcp_pcb_listen {
185 TCP_PCB_COMMON(
struct tcp_pcb_listen);
187 #if LWIP_CALLBACK_API
189 tcp_accept_fn accept;
192 #if TCP_LISTEN_BACKLOG
194 u8_t accepts_pending;
204 TCP_PCB_COMMON(
struct tcp_pcb);
210 #define TF_ACK_DELAY 0x01U
211 #define TF_ACK_NOW 0x02U
212 #define TF_INFR 0x04U
213 #define TF_CLOSEPEND 0x08U
214 #define TF_RXCLOSED 0x10U
216 #define TF_NODELAY 0x40U
217 #define TF_NAGLEMEMERR 0x80U
219 #define TF_WND_SCALE 0x0100U
221 #if TCP_LISTEN_BACKLOG
222 #define TF_BACKLOGPEND 0x0200U
224 #if LWIP_TCP_TIMESTAMPS
225 #define TF_TIMESTAMP 0x0400U
232 u8_t polltmr, pollinterval;
238 tcpwnd_size_t rcv_wnd;
239 tcpwnd_size_t rcv_ann_wnd;
240 u32_t rcv_ann_right_edge;
261 tcpwnd_size_t ssthresh;
265 u32_t snd_wl1, snd_wl2;
268 tcpwnd_size_t snd_wnd;
269 tcpwnd_size_t snd_wnd_max;
271 tcpwnd_size_t snd_buf;
272 #define TCP_SNDQUEUELEN_OVERFLOW (0xffffU-3)
277 u16_t unsent_oversize;
281 struct tcp_seg *unsent;
282 struct tcp_seg *unacked;
284 struct tcp_seg *ooseq;
287 struct pbuf *refused_data;
289 #if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG
290 struct tcp_pcb_listen* listener;
293 #if LWIP_CALLBACK_API
299 tcp_connected_fn connected;
306 #if LWIP_TCP_TIMESTAMPS
307 u32_t ts_lastacksent;
313 #if LWIP_TCP_KEEPALIVE
321 u8_t persist_backoff;
338 LWIP_EVENT_CONNECTED,
343 err_t lwip_tcp_event(
void *arg,
struct tcp_pcb *pcb,
352 struct tcp_pcb * tcp_new (
void);
353 struct tcp_pcb * tcp_new_ip_type (
u8_t type);
355 void tcp_arg (
struct tcp_pcb *pcb,
void *arg);
356 #if LWIP_CALLBACK_API
357 void tcp_recv (
struct tcp_pcb *pcb, tcp_recv_fn recv);
358 void tcp_sent (
struct tcp_pcb *pcb, tcp_sent_fn sent);
359 void tcp_err (
struct tcp_pcb *pcb, tcp_err_fn err);
360 void tcp_accept (
struct tcp_pcb *pcb, tcp_accept_fn accept);
362 void tcp_poll (
struct tcp_pcb *pcb, tcp_poll_fn poll,
u8_t interval);
364 #if LWIP_TCP_TIMESTAMPS
365 #define tcp_mss(pcb) (((pcb)->flags & TF_TIMESTAMP) ? ((pcb)->mss - 12) : (pcb)->mss)
367 #define tcp_mss(pcb) ((pcb)->mss)
369 #define tcp_sndbuf(pcb) (TCPWND16((pcb)->snd_buf))
370 #define tcp_sndqueuelen(pcb) ((pcb)->snd_queuelen)
372 #define tcp_nagle_disable(pcb) ((pcb)->flags |= TF_NODELAY)
374 #define tcp_nagle_enable(pcb) ((pcb)->flags = (tcpflags_t)((pcb)->flags & ~TF_NODELAY))
376 #define tcp_nagle_disabled(pcb) (((pcb)->flags & TF_NODELAY) != 0)
378 #if TCP_LISTEN_BACKLOG
379 #define tcp_backlog_set(pcb, new_backlog) do { \
380 LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", (pcb)->state == LISTEN); \
381 ((struct tcp_pcb_listen *)(pcb))->backlog = ((new_backlog) ? (new_backlog) : 1); } while(0)
382 void tcp_backlog_delayed(
struct tcp_pcb* pcb);
383 void tcp_backlog_accepted(
struct tcp_pcb* pcb);
385 #define tcp_backlog_set(pcb, new_backlog)
386 #define tcp_backlog_delayed(pcb)
387 #define tcp_backlog_accepted(pcb)
389 #define tcp_accepted(pcb)
391 void tcp_recved (
struct tcp_pcb *pcb,
u16_t len);
395 u16_t port, tcp_connected_fn connected);
397 struct tcp_pcb * tcp_listen_with_backlog_and_err(
struct tcp_pcb *pcb,
u8_t backlog,
err_t *err);
398 struct tcp_pcb * tcp_listen_with_backlog(
struct tcp_pcb *pcb,
u8_t backlog);
400 #define tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG)
402 void tcp_abort (
struct tcp_pcb *pcb);
403 err_t tcp_close (
struct tcp_pcb *pcb);
404 err_t tcp_shutdown(
struct tcp_pcb *pcb,
int shut_rx,
int shut_tx);
407 #define TCP_WRITE_FLAG_COPY 0x01
408 #define TCP_WRITE_FLAG_MORE 0x02
410 err_t tcp_write (
struct tcp_pcb *pcb,
const void *dataptr,
u16_t len,
413 void tcp_setprio (
struct tcp_pcb *pcb,
u8_t prio);
415 #define TCP_PRIO_MIN 1
416 #define TCP_PRIO_NORMAL 64
417 #define TCP_PRIO_MAX 127
419 err_t tcp_output (
struct tcp_pcb *pcb);
422 const char* tcp_debug_state_str(
enum tcp_state s);
425 #define tcp_new_ip6() tcp_new_ip_type(IPADDR_TYPE_V6)