37 #ifndef LWIP_HDR_TCP_PRIV_H 38 #define LWIP_HDR_TCP_PRIV_H 67 void tcp_slowtmr (
void);
68 void tcp_fasttmr (
void);
74 void tcp_txnow (
void);
77 void tcp_input (
struct pbuf *p,
struct netif *inp);
79 struct tcp_pcb * tcp_alloc (u8_t prio);
80 void tcp_free (
struct tcp_pcb *pcb);
81 void tcp_abandon (
struct tcp_pcb *pcb,
int reset);
82 err_t tcp_send_empty_ack(
struct tcp_pcb *pcb);
83 err_t tcp_rexmit (
struct tcp_pcb *pcb);
84 err_t tcp_rexmit_rto_prepare(
struct tcp_pcb *pcb);
85 void tcp_rexmit_rto_commit(
struct tcp_pcb *pcb);
86 void tcp_rexmit_rto (
struct tcp_pcb *pcb);
87 void tcp_rexmit_fast (
struct tcp_pcb *pcb);
88 u32_t tcp_update_rcv_ann_wnd(
struct tcp_pcb *pcb);
89 err_t tcp_process_refused_data(
struct tcp_pcb *pcb);
100 #define tcp_do_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \ 101 ((tpcb)->flags & (TF_NODELAY | TF_INFR)) || \ 102 (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \ 103 ((tpcb)->unsent->len >= (tpcb)->mss))) || \ 104 ((tcp_sndbuf(tpcb) == 0) || (tcp_sndqueuelen(tpcb) >= TCP_SND_QUEUELEN)) \ 106 #define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK) 109 #define TCP_SEQ_LT(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) < 0) 110 #define TCP_SEQ_LEQ(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) <= 0) 111 #define TCP_SEQ_GT(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) > 0) 112 #define TCP_SEQ_GEQ(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) >= 0) 115 #define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b)) 117 #define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c)) 119 #ifndef TCP_TMR_INTERVAL 120 #define TCP_TMR_INTERVAL 250 123 #ifndef TCP_FAST_INTERVAL 124 #define TCP_FAST_INTERVAL TCP_TMR_INTERVAL 127 #ifndef TCP_SLOW_INTERVAL 128 #define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) 131 #define TCP_FIN_WAIT_TIMEOUT 20000 132 #define TCP_SYN_RCVD_TIMEOUT 20000 134 #define TCP_OOSEQ_TIMEOUT 6U 137 #define TCP_MSL 60000UL 141 #ifndef TCP_KEEPIDLE_DEFAULT 142 #define TCP_KEEPIDLE_DEFAULT 7200000UL 145 #ifndef TCP_KEEPINTVL_DEFAULT 146 #define TCP_KEEPINTVL_DEFAULT 75000UL 149 #ifndef TCP_KEEPCNT_DEFAULT 150 #define TCP_KEEPCNT_DEFAULT 9U 153 #define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT 155 #define TCP_TCPLEN(seg) ((seg)->len + (((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0) ? 1U : 0U)) 159 #define TF_RESET (u8_t)0x08U 160 #define TF_CLOSED (u8_t)0x10U 161 #define TF_GOT_FIN (u8_t)0x20U 166 #define TCP_EVENT_ACCEPT(lpcb,pcb,arg,err,ret) ret = lwip_tcp_event(arg, (pcb),\ 167 LWIP_EVENT_ACCEPT, NULL, 0, err) 168 #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ 169 LWIP_EVENT_SENT, NULL, space, ERR_OK) 170 #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ 171 LWIP_EVENT_RECV, (p), 0, (err)) 172 #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ 173 LWIP_EVENT_RECV, NULL, 0, ERR_OK) 174 #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ 175 LWIP_EVENT_CONNECTED, NULL, 0, (err)) 176 #define TCP_EVENT_POLL(pcb,ret) do { if ((pcb)->state != SYN_RCVD) { \ 177 ret = lwip_tcp_event((pcb)->callback_arg, (pcb), LWIP_EVENT_POLL, NULL, 0, ERR_OK); \ 179 ret = ERR_ARG; } } while(0) 182 #define TCP_EVENT_ERR(last_state,errf,arg,err) do { if (last_state != SYN_RCVD) { \ 183 lwip_tcp_event((arg), NULL, LWIP_EVENT_ERR, NULL, 0, (err)); } } while(0) 187 #define TCP_EVENT_ACCEPT(lpcb,pcb,arg,err,ret) \ 189 if((lpcb)->accept != NULL) \ 190 (ret) = (lpcb)->accept((arg),(pcb),(err)); \ 191 else (ret) = ERR_ARG; \ 194 #define TCP_EVENT_SENT(pcb,space,ret) \ 196 if((pcb)->sent != NULL) \ 197 (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \ 198 else (ret) = ERR_OK; \ 201 #define TCP_EVENT_RECV(pcb,p,err,ret) \ 203 if((pcb)->recv != NULL) { \ 204 (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));\ 206 (ret) = tcp_recv_null(NULL, (pcb), (p), (err)); \ 210 #define TCP_EVENT_CLOSED(pcb,ret) \ 212 if(((pcb)->recv != NULL)) { \ 213 (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),NULL,ERR_OK);\ 219 #define TCP_EVENT_CONNECTED(pcb,err,ret) \ 221 if((pcb)->connected != NULL) \ 222 (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \ 223 else (ret) = ERR_OK; \ 226 #define TCP_EVENT_POLL(pcb,ret) \ 228 if((pcb)->poll != NULL) \ 229 (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \ 230 else (ret) = ERR_OK; \ 233 #define TCP_EVENT_ERR(last_state,errf,arg,err) \ 235 LWIP_UNUSED_ARG(last_state); \ 237 (errf)((arg),(err)); \ 243 #if TCP_OVERSIZE && defined(LWIP_DEBUG) 244 #define TCP_OVERSIZE_DBGCHECK 1 246 #define TCP_OVERSIZE_DBGCHECK 0 250 #define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP) 254 struct tcp_seg *next;
257 #if TCP_OVERSIZE_DBGCHECK 262 #if TCP_CHECKSUM_ON_COPY 267 #define TF_SEG_OPTS_MSS (u8_t)0x01U 268 #define TF_SEG_OPTS_TS (u8_t)0x02U 269 #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U 271 #define TF_SEG_OPTS_WND_SCALE (u8_t)0x08U 272 #define TF_SEG_OPTS_SACK_PERM (u8_t)0x10U 276 #define LWIP_TCP_OPT_EOL 0 277 #define LWIP_TCP_OPT_NOP 1 278 #define LWIP_TCP_OPT_MSS 2 279 #define LWIP_TCP_OPT_WS 3 280 #define LWIP_TCP_OPT_SACK_PERM 4 281 #define LWIP_TCP_OPT_TS 8 283 #define LWIP_TCP_OPT_LEN_MSS 4 284 #if LWIP_TCP_TIMESTAMPS 285 #define LWIP_TCP_OPT_LEN_TS 10 286 #define LWIP_TCP_OPT_LEN_TS_OUT 12 288 #define LWIP_TCP_OPT_LEN_TS_OUT 0 291 #define LWIP_TCP_OPT_LEN_WS 3 292 #define LWIP_TCP_OPT_LEN_WS_OUT 4 294 #define LWIP_TCP_OPT_LEN_WS_OUT 0 297 #if LWIP_TCP_SACK_OUT 298 #define LWIP_TCP_OPT_LEN_SACK_PERM 2 299 #define LWIP_TCP_OPT_LEN_SACK_PERM_OUT 4 301 #define LWIP_TCP_OPT_LEN_SACK_PERM_OUT 0 304 #define LWIP_TCP_OPT_LENGTH(flags) \ 305 ((flags) & TF_SEG_OPTS_MSS ? LWIP_TCP_OPT_LEN_MSS : 0) + \ 306 ((flags) & TF_SEG_OPTS_TS ? LWIP_TCP_OPT_LEN_TS_OUT : 0) + \ 307 ((flags) & TF_SEG_OPTS_WND_SCALE ? LWIP_TCP_OPT_LEN_WS_OUT : 0) + \ 308 ((flags) & TF_SEG_OPTS_SACK_PERM ? LWIP_TCP_OPT_LEN_SACK_PERM_OUT : 0) 311 #define TCP_BUILD_MSS_OPTION(mss) lwip_htonl(0x02040000 | ((mss) & 0xFFFF)) 314 #define TCPWNDSIZE_F U32_F 315 #define TCPWND_MAX 0xFFFFFFFFU 316 #define TCPWND_CHECK16(x) LWIP_ASSERT("window size > 0xFFFF", (x) <= 0xFFFF) 317 #define TCPWND_MIN16(x) ((u16_t)LWIP_MIN((x), 0xFFFF)) 319 #define TCPWNDSIZE_F U16_F 320 #define TCPWND_MAX 0xFFFFU 321 #define TCPWND_CHECK16(x) 322 #define TCPWND_MIN16(x) x 326 extern struct tcp_pcb *tcp_input_pcb;
327 extern u32_t tcp_ticks;
328 extern u8_t tcp_active_pcbs_changed;
331 union tcp_listen_pcbs_t {
332 struct tcp_pcb_listen *listen_pcbs;
333 struct tcp_pcb *pcbs;
335 extern struct tcp_pcb *tcp_bound_pcbs;
336 extern union tcp_listen_pcbs_t tcp_listen_pcbs;
337 extern struct tcp_pcb *tcp_active_pcbs;
340 extern struct tcp_pcb *tcp_tw_pcbs;
342 #define NUM_TCP_PCB_LISTS_NO_TIME_WAIT 3 343 #define NUM_TCP_PCB_LISTS 4 344 extern struct tcp_pcb **
const tcp_pcb_lists[NUM_TCP_PCB_LISTS];
354 #ifndef TCP_DEBUG_PCB_LISTS 355 #define TCP_DEBUG_PCB_LISTS 0 357 #if TCP_DEBUG_PCB_LISTS 358 #define TCP_REG(pcbs, npcb) do {\ 359 struct tcp_pcb *tcp_tmp_pcb; \ 360 LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %"U16_F"\n", (void *)(npcb), (npcb)->local_port)); \ 361 for (tcp_tmp_pcb = *(pcbs); \ 362 tcp_tmp_pcb != NULL; \ 363 tcp_tmp_pcb = tcp_tmp_pcb->next) { \ 364 LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \ 366 LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \ 367 (npcb)->next = *(pcbs); \ 368 LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \ 370 LWIP_ASSERT("TCP_REG: tcp_pcbs sane", tcp_pcbs_sane()); \ 371 tcp_timer_needed(); \ 373 #define TCP_RMV(pcbs, npcb) do { \ 374 struct tcp_pcb *tcp_tmp_pcb; \ 375 LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ 376 LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (void *)(npcb), (void *)(*(pcbs)))); \ 377 if(*(pcbs) == (npcb)) { \ 378 *(pcbs) = (*pcbs)->next; \ 379 } else for (tcp_tmp_pcb = *(pcbs); tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \ 380 if(tcp_tmp_pcb->next == (npcb)) { \ 381 tcp_tmp_pcb->next = (npcb)->next; \ 385 (npcb)->next = NULL; \ 386 LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ 387 LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (void *)(npcb), (void *)(*(pcbs)))); \ 392 #define TCP_REG(pcbs, npcb) \ 394 (npcb)->next = *pcbs; \ 396 tcp_timer_needed(); \ 399 #define TCP_RMV(pcbs, npcb) \ 401 if(*(pcbs) == (npcb)) { \ 402 (*(pcbs)) = (*pcbs)->next; \ 405 struct tcp_pcb *tcp_tmp_pcb; \ 406 for (tcp_tmp_pcb = *pcbs; \ 407 tcp_tmp_pcb != NULL; \ 408 tcp_tmp_pcb = tcp_tmp_pcb->next) { \ 409 if(tcp_tmp_pcb->next == (npcb)) { \ 410 tcp_tmp_pcb->next = (npcb)->next; \ 415 (npcb)->next = NULL; \ 420 #define TCP_REG_ACTIVE(npcb) \ 422 TCP_REG(&tcp_active_pcbs, npcb); \ 423 tcp_active_pcbs_changed = 1; \ 426 #define TCP_RMV_ACTIVE(npcb) \ 428 TCP_RMV(&tcp_active_pcbs, npcb); \ 429 tcp_active_pcbs_changed = 1; \ 432 #define TCP_PCB_REMOVE_ACTIVE(pcb) \ 434 tcp_pcb_remove(&tcp_active_pcbs, pcb); \ 435 tcp_active_pcbs_changed = 1; \ 440 struct tcp_pcb *tcp_pcb_copy(
struct tcp_pcb *pcb);
441 void tcp_pcb_purge(
struct tcp_pcb *pcb);
442 void tcp_pcb_remove(
struct tcp_pcb **pcblist,
struct tcp_pcb *pcb);
444 void tcp_segs_free(
struct tcp_seg *seg);
445 void tcp_seg_free(
struct tcp_seg *seg);
446 struct tcp_seg *tcp_seg_copy(
struct tcp_seg *seg);
448 #define tcp_ack(pcb) \ 450 if((pcb)->flags & TF_ACK_DELAY) { \ 451 tcp_clear_flags(pcb, TF_ACK_DELAY); \ 455 tcp_set_flags(pcb, TF_ACK_DELAY); \ 459 #define tcp_ack_now(pcb) \ 460 tcp_set_flags(pcb, TF_ACK_NOW) 462 err_t tcp_send_fin(
struct tcp_pcb *pcb);
463 err_t tcp_enqueue_flags(
struct tcp_pcb *pcb, u8_t flags);
465 void tcp_rexmit_seg(
struct tcp_pcb *pcb,
struct tcp_seg *seg);
467 void tcp_rst(
const struct tcp_pcb* pcb, u32_t seqno, u32_t ackno,
469 u16_t local_port, u16_t remote_port);
471 u32_t tcp_next_iss(
struct tcp_pcb *pcb);
473 err_t tcp_keepalive(
struct tcp_pcb *pcb);
474 err_t tcp_split_unsent_seg(
struct tcp_pcb *pcb, u16_t split);
475 err_t tcp_zero_window_probe(
struct tcp_pcb *pcb);
476 void tcp_trigger_input_pcb_close(
void);
478 #if TCP_CALCULATE_EFF_SEND_MSS 479 u16_t tcp_eff_send_mss_netif(u16_t sendmss,
struct netif *outif,
481 #define tcp_eff_send_mss(sendmss, src, dest) \ 482 tcp_eff_send_mss_netif(sendmss, ip_route(src, dest), dest) 485 #if LWIP_CALLBACK_API 486 err_t tcp_recv_null(
void *arg,
struct tcp_pcb *pcb,
struct pbuf *p, err_t err);
489 #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG 490 void tcp_debug_print(
struct tcp_hdr *tcphdr);
491 void tcp_debug_print_flags(u8_t flags);
492 void tcp_debug_print_state(
enum tcp_state s);
493 void tcp_debug_print_pcbs(
void);
494 s16_t tcp_pcbs_sane(
void);
496 # define tcp_debug_print(tcphdr) 497 # define tcp_debug_print_flags(flags) 498 # define tcp_debug_print_state(s) 499 # define tcp_debug_print_pcbs() 500 # define tcp_pcbs_sane() 1 505 void tcp_timer_needed(
void);
510 void tcp_free_ooseq(
struct tcp_pcb *pcb);
513 #if LWIP_TCP_PCB_NUM_EXT_ARGS 514 err_t tcp_ext_arg_invoke_callbacks_passive_open(
struct tcp_pcb_listen *lpcb,
struct tcp_pcb *cpcb);
lwIP Options Configuration
TCP protocol definitions.
Main packet buffer struct.
Generic data structure used for all lwIP network interfaces.
IP address structure for passing IP addresses by value.
TCP API (to be used from TCPIP thread) See also tcp_raw.