ESP8266
tcp_impl.h
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 #ifndef __LWIP_TCP_IMPL_H__
33 #define __LWIP_TCP_IMPL_H__
34 
35 #include "lwip/opt.h"
36 
37 #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
38 
39 #include "lwip/tcp.h"
40 #include "lwip/sys.h"
41 #include "lwip/mem.h"
42 #include "lwip/pbuf.h"
43 #include "lwip/ip.h"
44 #include "lwip/icmp.h"
45 #include "lwip/err.h"
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /* Functions for interfacing with TCP: */
52 
53 /* Lower layer interface to TCP: */
54 #define tcp_init() /* Compatibility define, no init needed. */
55 void tcp_tmr (void)ICACHE_FLASH_ATTR; /* Must be called every
56  TCP_TMR_INTERVAL
57  ms. (Typically 250 ms). */
58 /* It is also possible to call these two functions at the right
59  intervals (instead of calling tcp_tmr()). */
60 void tcp_slowtmr (void)ICACHE_FLASH_ATTR;
61 void tcp_fasttmr (void)ICACHE_FLASH_ATTR;
62 
63 
64 /* Only used by IP to pass a TCP segment to TCP: */
65 void tcp_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_ATTR;
66 /* Used within the TCP code only: */
67 struct tcp_pcb * tcp_alloc (u8_t prio)ICACHE_FLASH_ATTR;
68 void tcp_abandon (struct tcp_pcb *pcb, int reset)ICACHE_FLASH_ATTR;
69 err_t tcp_send_empty_ack(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
70 void tcp_rexmit (struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
71 void tcp_rexmit_rto (struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
72 void tcp_rexmit_fast (struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
73 u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
74 
84 #define tcp_do_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \
85  ((tpcb)->flags & (TF_NODELAY | TF_INFR)) || \
86  (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \
87  ((tpcb)->unsent->len >= (tpcb)->mss))) \
88  ) ? 1 : 0)
89 #define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK)
90 
91 
92 #define TCP_SEQ_LT(a,b) ((s32_t)((a)-(b)) < 0)
93 #define TCP_SEQ_LEQ(a,b) ((s32_t)((a)-(b)) <= 0)
94 #define TCP_SEQ_GT(a,b) ((s32_t)((a)-(b)) > 0)
95 #define TCP_SEQ_GEQ(a,b) ((s32_t)((a)-(b)) >= 0)
96 /* is b<=a<=c? */
97 #if 0 /* see bug #10548 */
98 #define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b))
99 #endif
100 #define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
101 #define TCP_FIN 0x01U
102 #define TCP_SYN 0x02U
103 #define TCP_RST 0x04U
104 #define TCP_PSH 0x08U
105 #define TCP_ACK 0x10U
106 #define TCP_URG 0x20U
107 #define TCP_ECE 0x40U
108 #define TCP_CWR 0x80U
109 
110 #define TCP_FLAGS 0x3fU
111 
112 /* Length of the TCP header, excluding options. */
113 #define TCP_HLEN 20
114 
115 #ifndef TCP_TMR_INTERVAL
116 #define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */
117 #endif /* TCP_TMR_INTERVAL */
118 
119 #ifndef TCP_FAST_INTERVAL
120 #define TCP_FAST_INTERVAL TCP_TMR_INTERVAL /* the fine grained timeout in milliseconds */
121 #endif /* TCP_FAST_INTERVAL */
122 
123 #ifndef TCP_SLOW_INTERVAL
124 #define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) /* the coarse grained timeout in milliseconds */
125 #endif /* TCP_SLOW_INTERVAL */
126 
127 #define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */
128 #define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */
129 
130 #define TCP_OOSEQ_TIMEOUT 6U /* x RTO */
131 
132 #ifndef TCP_MSL
133 #define TCP_MSL 60000UL /* The maximum segment lifetime in milliseconds */
134 #endif
135 
136 /* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */
137 #ifndef TCP_KEEPIDLE_DEFAULT
138 #define TCP_KEEPIDLE_DEFAULT 3000UL /* Default KEEPALIVE timer in milliseconds */
139 #endif
140 
141 #ifndef TCP_KEEPINTVL_DEFAULT
142 #define TCP_KEEPINTVL_DEFAULT 1000UL /* Default Time between KEEPALIVE probes in milliseconds */
143 #endif
144 
145 #ifndef TCP_KEEPCNT_DEFAULT
146 #define TCP_KEEPCNT_DEFAULT 3U /* Default Counter for KEEPALIVE probes */
147 #endif
148 
149 #define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */
150 
151 /* Fields are (of course) in network byte order.
152  * Some fields are converted to host byte order in tcp_input().
153  */
154 #ifdef PACK_STRUCT_USE_INCLUDES
155 # include "arch/bpstruct.h"
156 #endif
157 PACK_STRUCT_BEGIN
158 struct tcp_hdr {
159  PACK_STRUCT_FIELD(u16_t src); //源端口 PACK_STRUCT_FIELD(u16_t dest); //目的端口 PACK_STRUCT_FIELD(u32_t seqno); //序号 PACK_STRUCT_FIELD(u32_t ackno); //应答序号 PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);//首部长度+保留位+标志位 PACK_STRUCT_FIELD(u16_t wnd); //窗口大小 PACK_STRUCT_FIELD(u16_t chksum); //校验和 PACK_STRUCT_FIELD(u16_t urgp); //紧急指针 } PACK_STRUCT_STRUCT; PACK_STRUCT_END #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/epstruct.h" #endif #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)) /** Flags used on input processing, not on pcb->flags */ #define TF_RESET (u8_t)0x08U /* Connection was reset. */ #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */ #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */ #if LWIP_EVENT_API #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_ACCEPT, NULL, 0, err) #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_SENT, NULL, space, ERR_OK) #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_RECV, (p), 0, (err)) #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_RECV, NULL, 0, ERR_OK) #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_CONNECTED, NULL, 0, (err)) #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_POLL, NULL, 0, ERR_OK) #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \ LWIP_EVENT_ERR, NULL, 0, (err)) #else /* LWIP_EVENT_API */ #define TCP_EVENT_ACCEPT(pcb,err,ret) \ do { \ if((pcb)->accept != NULL) \ (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \ else (ret) = ERR_ARG; \ } while (0) #define TCP_EVENT_SENT(pcb,space,ret) \ do { \ if((pcb)->sent != NULL) \ (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_RECV(pcb,p,err,ret) \ 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_CLOSED(pcb,ret) \ 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) \ do { \ if((pcb)->connected != NULL) \ (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_POLL(pcb,ret) \ do { \ if((pcb)->poll != NULL) \ (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_ERR(errf,arg,err) \ do { \ if((errf) != NULL) \ (errf)((arg),(err)); \ } while (0) #endif /* LWIP_EVENT_API */ /** Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled */ #if TCP_OVERSIZE && defined(LWIP_DEBUG) #define TCP_OVERSIZE_DBGCHECK 1 #else #define TCP_OVERSIZE_DBGCHECK 0 #endif /** Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled */ #define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP) /* This structure represents a TCP segment on the unsent, unacked and ooseq queues */ struct tcp_seg { struct tcp_seg *next; /* used when putting segements on a queue */ struct pbuf *p; /* buffer containing data + TCP header */ void *dataptr; /* pointer to the TCP data in the pbuf */ u16_t len; /* the TCP length of this segment */ #if TCP_OVERSIZE_DBGCHECK u16_t oversize_left; /* Extra bytes available at the end of the last pbuf in unsent (used for asserting vs. tcp_pcb.unsent_oversized only) */ #endif /* TCP_OVERSIZE_DBGCHECK */ #if TCP_CHECKSUM_ON_COPY u16_t chksum; u8_t chksum_swapped; #endif /* TCP_CHECKSUM_ON_COPY */ u8_t flags; #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */ #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */ #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is checksummed into 'chksum' */ struct tcp_hdr *tcphdr; /* the TCP header */ }; #define LWIP_TCP_OPT_LENGTH(flags) \ (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \ (flags & TF_SEG_OPTS_TS ? 12 : 0) /** This returns a TCP header option for MSS in an u32_t */ #define TCP_BUILD_MSS_OPTION(x) (x) = PP_HTONL(((u32_t)2 << 24) | \ ((u32_t)4 << 16) | \ (((u32_t)TCP_MSS / 256) << 8) | \ (TCP_MSS & 255)) /* Global variables: */ extern struct tcp_pcb *tcp_input_pcb; extern u32_t tcp_ticks; /* The TCP PCB lists. */ union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */ struct tcp_pcb_listen *listen_pcbs; struct tcp_pcb *pcbs; }; extern struct tcp_pcb *tcp_bound_pcbs; extern union tcp_listen_pcbs_t tcp_listen_pcbs; extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a state in which they accept or send data. */ extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */ /* Axioms about the above lists: 1) Every TCP PCB that is not CLOSED is in one of the lists. 2) A PCB is only in one of the lists. 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state. 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state. */ /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB with a PCB list or removes a PCB from a list, respectively. */ #ifndef TCP_DEBUG_PCB_LISTS #define TCP_DEBUG_PCB_LISTS 0 #endif #if TCP_DEBUG_PCB_LISTS #define TCP_REG(pcbs, npcb) do {\ LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \ for(tcp_tmp_pcb = *(pcbs); \ tcp_tmp_pcb != NULL; \ tcp_tmp_pcb = tcp_tmp_pcb->next) { \ LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \ } \ LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \ (npcb)->next = *(pcbs); \ LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \ *(pcbs) = (npcb); \ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ tcp_timer_needed(); \ } while(0) #define TCP_RMV(pcbs, npcb) do { \ LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \ 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; \ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \ } while(0) #else /* LWIP_DEBUG */ #define TCP_REG(pcbs, npcb) \ do { \ (npcb)->next = *pcbs; \ *(pcbs) = (npcb); \ tcp_timer_needed(); \ } while (0) #define TCP_RMV(pcbs, npcb) \ 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) #endif /* LWIP_DEBUG */ /* Internal functions: */ struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_pcb_purge(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_segs_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR; void tcp_seg_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR; struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg)ICACHE_FLASH_ATTR; #define tcp_ack(pcb) \ 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) \ do { \ (pcb)->flags |= TF_ACK_NOW; \ } while (0) err_t tcp_send_fin(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)ICACHE_FLASH_ATTR; void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg)ICACHE_FLASH_ATTR; 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)ICACHE_FLASH_ATTR; u32_t tcp_next_iss(void)ICACHE_FLASH_ATTR; void tcp_keepalive(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_zero_window_probe(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; #if TCP_CALCULATE_EFF_SEND_MSS u16_t tcp_eff_send_mss(u16_t sendmss, ip_addr_t *addr)ICACHE_FLASH_ATTR; #endif /* TCP_CALCULATE_EFF_SEND_MSS */ #if LWIP_CALLBACK_API err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)ICACHE_FLASH_ATTR; #endif /* LWIP_CALLBACK_API */ #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG void tcp_debug_print(struct tcp_hdr *tcphdr)ICACHE_FLASH_ATTR; void tcp_debug_print_flags(u8_t flags)ICACHE_FLASH_ATTR; void tcp_debug_print_state(enum tcp_state s)ICACHE_FLASH_ATTR; void tcp_debug_print_pcbs(void)ICACHE_FLASH_ATTR; s16_t tcp_pcbs_sane(void)ICACHE_FLASH_ATTR; #else # 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 #endif /* TCP_DEBUG */ /** 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_timer_needed(void)ICACHE_FLASH_ATTR; #ifdef __cplusplus } #endif #endif /* LWIP_TCP */ #endif /* __LWIP_TCP_H__ */
160  PACK_STRUCT_FIELD(u16_t dest); //目的端口 PACK_STRUCT_FIELD(u32_t seqno); //序号 PACK_STRUCT_FIELD(u32_t ackno); //应答序号 PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);//首部长度+保留位+标志位 PACK_STRUCT_FIELD(u16_t wnd); //窗口大小 PACK_STRUCT_FIELD(u16_t chksum); //校验和 PACK_STRUCT_FIELD(u16_t urgp); //紧急指针 } PACK_STRUCT_STRUCT; PACK_STRUCT_END #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/epstruct.h" #endif #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)) /** Flags used on input processing, not on pcb->flags */ #define TF_RESET (u8_t)0x08U /* Connection was reset. */ #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */ #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */ #if LWIP_EVENT_API #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_ACCEPT, NULL, 0, err) #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_SENT, NULL, space, ERR_OK) #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_RECV, (p), 0, (err)) #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_RECV, NULL, 0, ERR_OK) #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_CONNECTED, NULL, 0, (err)) #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_POLL, NULL, 0, ERR_OK) #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \ LWIP_EVENT_ERR, NULL, 0, (err)) #else /* LWIP_EVENT_API */ #define TCP_EVENT_ACCEPT(pcb,err,ret) \ do { \ if((pcb)->accept != NULL) \ (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \ else (ret) = ERR_ARG; \ } while (0) #define TCP_EVENT_SENT(pcb,space,ret) \ do { \ if((pcb)->sent != NULL) \ (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_RECV(pcb,p,err,ret) \ 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_CLOSED(pcb,ret) \ 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) \ do { \ if((pcb)->connected != NULL) \ (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_POLL(pcb,ret) \ do { \ if((pcb)->poll != NULL) \ (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_ERR(errf,arg,err) \ do { \ if((errf) != NULL) \ (errf)((arg),(err)); \ } while (0) #endif /* LWIP_EVENT_API */ /** Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled */ #if TCP_OVERSIZE && defined(LWIP_DEBUG) #define TCP_OVERSIZE_DBGCHECK 1 #else #define TCP_OVERSIZE_DBGCHECK 0 #endif /** Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled */ #define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP) /* This structure represents a TCP segment on the unsent, unacked and ooseq queues */ struct tcp_seg { struct tcp_seg *next; /* used when putting segements on a queue */ struct pbuf *p; /* buffer containing data + TCP header */ void *dataptr; /* pointer to the TCP data in the pbuf */ u16_t len; /* the TCP length of this segment */ #if TCP_OVERSIZE_DBGCHECK u16_t oversize_left; /* Extra bytes available at the end of the last pbuf in unsent (used for asserting vs. tcp_pcb.unsent_oversized only) */ #endif /* TCP_OVERSIZE_DBGCHECK */ #if TCP_CHECKSUM_ON_COPY u16_t chksum; u8_t chksum_swapped; #endif /* TCP_CHECKSUM_ON_COPY */ u8_t flags; #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */ #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */ #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is checksummed into 'chksum' */ struct tcp_hdr *tcphdr; /* the TCP header */ }; #define LWIP_TCP_OPT_LENGTH(flags) \ (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \ (flags & TF_SEG_OPTS_TS ? 12 : 0) /** This returns a TCP header option for MSS in an u32_t */ #define TCP_BUILD_MSS_OPTION(x) (x) = PP_HTONL(((u32_t)2 << 24) | \ ((u32_t)4 << 16) | \ (((u32_t)TCP_MSS / 256) << 8) | \ (TCP_MSS & 255)) /* Global variables: */ extern struct tcp_pcb *tcp_input_pcb; extern u32_t tcp_ticks; /* The TCP PCB lists. */ union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */ struct tcp_pcb_listen *listen_pcbs; struct tcp_pcb *pcbs; }; extern struct tcp_pcb *tcp_bound_pcbs; extern union tcp_listen_pcbs_t tcp_listen_pcbs; extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a state in which they accept or send data. */ extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */ /* Axioms about the above lists: 1) Every TCP PCB that is not CLOSED is in one of the lists. 2) A PCB is only in one of the lists. 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state. 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state. */ /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB with a PCB list or removes a PCB from a list, respectively. */ #ifndef TCP_DEBUG_PCB_LISTS #define TCP_DEBUG_PCB_LISTS 0 #endif #if TCP_DEBUG_PCB_LISTS #define TCP_REG(pcbs, npcb) do {\ LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \ for(tcp_tmp_pcb = *(pcbs); \ tcp_tmp_pcb != NULL; \ tcp_tmp_pcb = tcp_tmp_pcb->next) { \ LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \ } \ LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \ (npcb)->next = *(pcbs); \ LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \ *(pcbs) = (npcb); \ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ tcp_timer_needed(); \ } while(0) #define TCP_RMV(pcbs, npcb) do { \ LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \ 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; \ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \ } while(0) #else /* LWIP_DEBUG */ #define TCP_REG(pcbs, npcb) \ do { \ (npcb)->next = *pcbs; \ *(pcbs) = (npcb); \ tcp_timer_needed(); \ } while (0) #define TCP_RMV(pcbs, npcb) \ 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) #endif /* LWIP_DEBUG */ /* Internal functions: */ struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_pcb_purge(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_segs_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR; void tcp_seg_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR; struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg)ICACHE_FLASH_ATTR; #define tcp_ack(pcb) \ 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) \ do { \ (pcb)->flags |= TF_ACK_NOW; \ } while (0) err_t tcp_send_fin(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)ICACHE_FLASH_ATTR; void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg)ICACHE_FLASH_ATTR; 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)ICACHE_FLASH_ATTR; u32_t tcp_next_iss(void)ICACHE_FLASH_ATTR; void tcp_keepalive(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_zero_window_probe(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; #if TCP_CALCULATE_EFF_SEND_MSS u16_t tcp_eff_send_mss(u16_t sendmss, ip_addr_t *addr)ICACHE_FLASH_ATTR; #endif /* TCP_CALCULATE_EFF_SEND_MSS */ #if LWIP_CALLBACK_API err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)ICACHE_FLASH_ATTR; #endif /* LWIP_CALLBACK_API */ #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG void tcp_debug_print(struct tcp_hdr *tcphdr)ICACHE_FLASH_ATTR; void tcp_debug_print_flags(u8_t flags)ICACHE_FLASH_ATTR; void tcp_debug_print_state(enum tcp_state s)ICACHE_FLASH_ATTR; void tcp_debug_print_pcbs(void)ICACHE_FLASH_ATTR; s16_t tcp_pcbs_sane(void)ICACHE_FLASH_ATTR; #else # 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 #endif /* TCP_DEBUG */ /** 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_timer_needed(void)ICACHE_FLASH_ATTR; #ifdef __cplusplus } #endif #endif /* LWIP_TCP */ #endif /* __LWIP_TCP_H__ */
161  PACK_STRUCT_FIELD(u32_t seqno); //序号 PACK_STRUCT_FIELD(u32_t ackno); //应答序号 PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);//首部长度+保留位+标志位 PACK_STRUCT_FIELD(u16_t wnd); //窗口大小 PACK_STRUCT_FIELD(u16_t chksum); //校验和 PACK_STRUCT_FIELD(u16_t urgp); //紧急指针 } PACK_STRUCT_STRUCT; PACK_STRUCT_END #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/epstruct.h" #endif #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)) /** Flags used on input processing, not on pcb->flags */ #define TF_RESET (u8_t)0x08U /* Connection was reset. */ #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */ #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */ #if LWIP_EVENT_API #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_ACCEPT, NULL, 0, err) #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_SENT, NULL, space, ERR_OK) #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_RECV, (p), 0, (err)) #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_RECV, NULL, 0, ERR_OK) #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_CONNECTED, NULL, 0, (err)) #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_POLL, NULL, 0, ERR_OK) #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \ LWIP_EVENT_ERR, NULL, 0, (err)) #else /* LWIP_EVENT_API */ #define TCP_EVENT_ACCEPT(pcb,err,ret) \ do { \ if((pcb)->accept != NULL) \ (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \ else (ret) = ERR_ARG; \ } while (0) #define TCP_EVENT_SENT(pcb,space,ret) \ do { \ if((pcb)->sent != NULL) \ (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_RECV(pcb,p,err,ret) \ 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_CLOSED(pcb,ret) \ 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) \ do { \ if((pcb)->connected != NULL) \ (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_POLL(pcb,ret) \ do { \ if((pcb)->poll != NULL) \ (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_ERR(errf,arg,err) \ do { \ if((errf) != NULL) \ (errf)((arg),(err)); \ } while (0) #endif /* LWIP_EVENT_API */ /** Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled */ #if TCP_OVERSIZE && defined(LWIP_DEBUG) #define TCP_OVERSIZE_DBGCHECK 1 #else #define TCP_OVERSIZE_DBGCHECK 0 #endif /** Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled */ #define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP) /* This structure represents a TCP segment on the unsent, unacked and ooseq queues */ struct tcp_seg { struct tcp_seg *next; /* used when putting segements on a queue */ struct pbuf *p; /* buffer containing data + TCP header */ void *dataptr; /* pointer to the TCP data in the pbuf */ u16_t len; /* the TCP length of this segment */ #if TCP_OVERSIZE_DBGCHECK u16_t oversize_left; /* Extra bytes available at the end of the last pbuf in unsent (used for asserting vs. tcp_pcb.unsent_oversized only) */ #endif /* TCP_OVERSIZE_DBGCHECK */ #if TCP_CHECKSUM_ON_COPY u16_t chksum; u8_t chksum_swapped; #endif /* TCP_CHECKSUM_ON_COPY */ u8_t flags; #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */ #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */ #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is checksummed into 'chksum' */ struct tcp_hdr *tcphdr; /* the TCP header */ }; #define LWIP_TCP_OPT_LENGTH(flags) \ (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \ (flags & TF_SEG_OPTS_TS ? 12 : 0) /** This returns a TCP header option for MSS in an u32_t */ #define TCP_BUILD_MSS_OPTION(x) (x) = PP_HTONL(((u32_t)2 << 24) | \ ((u32_t)4 << 16) | \ (((u32_t)TCP_MSS / 256) << 8) | \ (TCP_MSS & 255)) /* Global variables: */ extern struct tcp_pcb *tcp_input_pcb; extern u32_t tcp_ticks; /* The TCP PCB lists. */ union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */ struct tcp_pcb_listen *listen_pcbs; struct tcp_pcb *pcbs; }; extern struct tcp_pcb *tcp_bound_pcbs; extern union tcp_listen_pcbs_t tcp_listen_pcbs; extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a state in which they accept or send data. */ extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */ /* Axioms about the above lists: 1) Every TCP PCB that is not CLOSED is in one of the lists. 2) A PCB is only in one of the lists. 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state. 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state. */ /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB with a PCB list or removes a PCB from a list, respectively. */ #ifndef TCP_DEBUG_PCB_LISTS #define TCP_DEBUG_PCB_LISTS 0 #endif #if TCP_DEBUG_PCB_LISTS #define TCP_REG(pcbs, npcb) do {\ LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \ for(tcp_tmp_pcb = *(pcbs); \ tcp_tmp_pcb != NULL; \ tcp_tmp_pcb = tcp_tmp_pcb->next) { \ LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \ } \ LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \ (npcb)->next = *(pcbs); \ LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \ *(pcbs) = (npcb); \ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ tcp_timer_needed(); \ } while(0) #define TCP_RMV(pcbs, npcb) do { \ LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \ 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; \ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \ } while(0) #else /* LWIP_DEBUG */ #define TCP_REG(pcbs, npcb) \ do { \ (npcb)->next = *pcbs; \ *(pcbs) = (npcb); \ tcp_timer_needed(); \ } while (0) #define TCP_RMV(pcbs, npcb) \ 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) #endif /* LWIP_DEBUG */ /* Internal functions: */ struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_pcb_purge(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_segs_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR; void tcp_seg_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR; struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg)ICACHE_FLASH_ATTR; #define tcp_ack(pcb) \ 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) \ do { \ (pcb)->flags |= TF_ACK_NOW; \ } while (0) err_t tcp_send_fin(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)ICACHE_FLASH_ATTR; void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg)ICACHE_FLASH_ATTR; 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)ICACHE_FLASH_ATTR; u32_t tcp_next_iss(void)ICACHE_FLASH_ATTR; void tcp_keepalive(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_zero_window_probe(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; #if TCP_CALCULATE_EFF_SEND_MSS u16_t tcp_eff_send_mss(u16_t sendmss, ip_addr_t *addr)ICACHE_FLASH_ATTR; #endif /* TCP_CALCULATE_EFF_SEND_MSS */ #if LWIP_CALLBACK_API err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)ICACHE_FLASH_ATTR; #endif /* LWIP_CALLBACK_API */ #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG void tcp_debug_print(struct tcp_hdr *tcphdr)ICACHE_FLASH_ATTR; void tcp_debug_print_flags(u8_t flags)ICACHE_FLASH_ATTR; void tcp_debug_print_state(enum tcp_state s)ICACHE_FLASH_ATTR; void tcp_debug_print_pcbs(void)ICACHE_FLASH_ATTR; s16_t tcp_pcbs_sane(void)ICACHE_FLASH_ATTR; #else # 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 #endif /* TCP_DEBUG */ /** 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_timer_needed(void)ICACHE_FLASH_ATTR; #ifdef __cplusplus } #endif #endif /* LWIP_TCP */ #endif /* __LWIP_TCP_H__ */
162  PACK_STRUCT_FIELD(u32_t ackno); //应答序号 PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);//首部长度+保留位+标志位 PACK_STRUCT_FIELD(u16_t wnd); //窗口大小 PACK_STRUCT_FIELD(u16_t chksum); //校验和 PACK_STRUCT_FIELD(u16_t urgp); //紧急指针 } PACK_STRUCT_STRUCT; PACK_STRUCT_END #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/epstruct.h" #endif #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)) /** Flags used on input processing, not on pcb->flags */ #define TF_RESET (u8_t)0x08U /* Connection was reset. */ #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */ #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */ #if LWIP_EVENT_API #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_ACCEPT, NULL, 0, err) #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_SENT, NULL, space, ERR_OK) #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_RECV, (p), 0, (err)) #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_RECV, NULL, 0, ERR_OK) #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_CONNECTED, NULL, 0, (err)) #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_POLL, NULL, 0, ERR_OK) #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \ LWIP_EVENT_ERR, NULL, 0, (err)) #else /* LWIP_EVENT_API */ #define TCP_EVENT_ACCEPT(pcb,err,ret) \ do { \ if((pcb)->accept != NULL) \ (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \ else (ret) = ERR_ARG; \ } while (0) #define TCP_EVENT_SENT(pcb,space,ret) \ do { \ if((pcb)->sent != NULL) \ (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_RECV(pcb,p,err,ret) \ 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_CLOSED(pcb,ret) \ 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) \ do { \ if((pcb)->connected != NULL) \ (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_POLL(pcb,ret) \ do { \ if((pcb)->poll != NULL) \ (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_ERR(errf,arg,err) \ do { \ if((errf) != NULL) \ (errf)((arg),(err)); \ } while (0) #endif /* LWIP_EVENT_API */ /** Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled */ #if TCP_OVERSIZE && defined(LWIP_DEBUG) #define TCP_OVERSIZE_DBGCHECK 1 #else #define TCP_OVERSIZE_DBGCHECK 0 #endif /** Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled */ #define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP) /* This structure represents a TCP segment on the unsent, unacked and ooseq queues */ struct tcp_seg { struct tcp_seg *next; /* used when putting segements on a queue */ struct pbuf *p; /* buffer containing data + TCP header */ void *dataptr; /* pointer to the TCP data in the pbuf */ u16_t len; /* the TCP length of this segment */ #if TCP_OVERSIZE_DBGCHECK u16_t oversize_left; /* Extra bytes available at the end of the last pbuf in unsent (used for asserting vs. tcp_pcb.unsent_oversized only) */ #endif /* TCP_OVERSIZE_DBGCHECK */ #if TCP_CHECKSUM_ON_COPY u16_t chksum; u8_t chksum_swapped; #endif /* TCP_CHECKSUM_ON_COPY */ u8_t flags; #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */ #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */ #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is checksummed into 'chksum' */ struct tcp_hdr *tcphdr; /* the TCP header */ }; #define LWIP_TCP_OPT_LENGTH(flags) \ (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \ (flags & TF_SEG_OPTS_TS ? 12 : 0) /** This returns a TCP header option for MSS in an u32_t */ #define TCP_BUILD_MSS_OPTION(x) (x) = PP_HTONL(((u32_t)2 << 24) | \ ((u32_t)4 << 16) | \ (((u32_t)TCP_MSS / 256) << 8) | \ (TCP_MSS & 255)) /* Global variables: */ extern struct tcp_pcb *tcp_input_pcb; extern u32_t tcp_ticks; /* The TCP PCB lists. */ union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */ struct tcp_pcb_listen *listen_pcbs; struct tcp_pcb *pcbs; }; extern struct tcp_pcb *tcp_bound_pcbs; extern union tcp_listen_pcbs_t tcp_listen_pcbs; extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a state in which they accept or send data. */ extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */ /* Axioms about the above lists: 1) Every TCP PCB that is not CLOSED is in one of the lists. 2) A PCB is only in one of the lists. 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state. 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state. */ /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB with a PCB list or removes a PCB from a list, respectively. */ #ifndef TCP_DEBUG_PCB_LISTS #define TCP_DEBUG_PCB_LISTS 0 #endif #if TCP_DEBUG_PCB_LISTS #define TCP_REG(pcbs, npcb) do {\ LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \ for(tcp_tmp_pcb = *(pcbs); \ tcp_tmp_pcb != NULL; \ tcp_tmp_pcb = tcp_tmp_pcb->next) { \ LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \ } \ LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \ (npcb)->next = *(pcbs); \ LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \ *(pcbs) = (npcb); \ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ tcp_timer_needed(); \ } while(0) #define TCP_RMV(pcbs, npcb) do { \ LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \ 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; \ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \ } while(0) #else /* LWIP_DEBUG */ #define TCP_REG(pcbs, npcb) \ do { \ (npcb)->next = *pcbs; \ *(pcbs) = (npcb); \ tcp_timer_needed(); \ } while (0) #define TCP_RMV(pcbs, npcb) \ 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) #endif /* LWIP_DEBUG */ /* Internal functions: */ struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_pcb_purge(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_segs_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR; void tcp_seg_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR; struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg)ICACHE_FLASH_ATTR; #define tcp_ack(pcb) \ 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) \ do { \ (pcb)->flags |= TF_ACK_NOW; \ } while (0) err_t tcp_send_fin(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)ICACHE_FLASH_ATTR; void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg)ICACHE_FLASH_ATTR; 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)ICACHE_FLASH_ATTR; u32_t tcp_next_iss(void)ICACHE_FLASH_ATTR; void tcp_keepalive(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_zero_window_probe(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; #if TCP_CALCULATE_EFF_SEND_MSS u16_t tcp_eff_send_mss(u16_t sendmss, ip_addr_t *addr)ICACHE_FLASH_ATTR; #endif /* TCP_CALCULATE_EFF_SEND_MSS */ #if LWIP_CALLBACK_API err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)ICACHE_FLASH_ATTR; #endif /* LWIP_CALLBACK_API */ #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG void tcp_debug_print(struct tcp_hdr *tcphdr)ICACHE_FLASH_ATTR; void tcp_debug_print_flags(u8_t flags)ICACHE_FLASH_ATTR; void tcp_debug_print_state(enum tcp_state s)ICACHE_FLASH_ATTR; void tcp_debug_print_pcbs(void)ICACHE_FLASH_ATTR; s16_t tcp_pcbs_sane(void)ICACHE_FLASH_ATTR; #else # 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 #endif /* TCP_DEBUG */ /** 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_timer_needed(void)ICACHE_FLASH_ATTR; #ifdef __cplusplus } #endif #endif /* LWIP_TCP */ #endif /* __LWIP_TCP_H__ */
163  PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);//首部长度+保留位+标志位
164  PACK_STRUCT_FIELD(u16_t wnd); //窗口大小
165  PACK_STRUCT_FIELD(u16_t chksum); //校验和 PACK_STRUCT_FIELD(u16_t urgp); //紧急指针 } PACK_STRUCT_STRUCT; PACK_STRUCT_END #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/epstruct.h" #endif #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)) /** Flags used on input processing, not on pcb->flags */ #define TF_RESET (u8_t)0x08U /* Connection was reset. */ #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */ #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */ #if LWIP_EVENT_API #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_ACCEPT, NULL, 0, err) #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_SENT, NULL, space, ERR_OK) #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_RECV, (p), 0, (err)) #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_RECV, NULL, 0, ERR_OK) #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_CONNECTED, NULL, 0, (err)) #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ LWIP_EVENT_POLL, NULL, 0, ERR_OK) #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \ LWIP_EVENT_ERR, NULL, 0, (err)) #else /* LWIP_EVENT_API */ #define TCP_EVENT_ACCEPT(pcb,err,ret) \ do { \ if((pcb)->accept != NULL) \ (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \ else (ret) = ERR_ARG; \ } while (0) #define TCP_EVENT_SENT(pcb,space,ret) \ do { \ if((pcb)->sent != NULL) \ (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_RECV(pcb,p,err,ret) \ 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_CLOSED(pcb,ret) \ 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) \ do { \ if((pcb)->connected != NULL) \ (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_POLL(pcb,ret) \ do { \ if((pcb)->poll != NULL) \ (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \ else (ret) = ERR_OK; \ } while (0) #define TCP_EVENT_ERR(errf,arg,err) \ do { \ if((errf) != NULL) \ (errf)((arg),(err)); \ } while (0) #endif /* LWIP_EVENT_API */ /** Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled */ #if TCP_OVERSIZE && defined(LWIP_DEBUG) #define TCP_OVERSIZE_DBGCHECK 1 #else #define TCP_OVERSIZE_DBGCHECK 0 #endif /** Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled */ #define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP) /* This structure represents a TCP segment on the unsent, unacked and ooseq queues */ struct tcp_seg { struct tcp_seg *next; /* used when putting segements on a queue */ struct pbuf *p; /* buffer containing data + TCP header */ void *dataptr; /* pointer to the TCP data in the pbuf */ u16_t len; /* the TCP length of this segment */ #if TCP_OVERSIZE_DBGCHECK u16_t oversize_left; /* Extra bytes available at the end of the last pbuf in unsent (used for asserting vs. tcp_pcb.unsent_oversized only) */ #endif /* TCP_OVERSIZE_DBGCHECK */ #if TCP_CHECKSUM_ON_COPY u16_t chksum; u8_t chksum_swapped; #endif /* TCP_CHECKSUM_ON_COPY */ u8_t flags; #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */ #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */ #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is checksummed into 'chksum' */ struct tcp_hdr *tcphdr; /* the TCP header */ }; #define LWIP_TCP_OPT_LENGTH(flags) \ (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \ (flags & TF_SEG_OPTS_TS ? 12 : 0) /** This returns a TCP header option for MSS in an u32_t */ #define TCP_BUILD_MSS_OPTION(x) (x) = PP_HTONL(((u32_t)2 << 24) | \ ((u32_t)4 << 16) | \ (((u32_t)TCP_MSS / 256) << 8) | \ (TCP_MSS & 255)) /* Global variables: */ extern struct tcp_pcb *tcp_input_pcb; extern u32_t tcp_ticks; /* The TCP PCB lists. */ union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */ struct tcp_pcb_listen *listen_pcbs; struct tcp_pcb *pcbs; }; extern struct tcp_pcb *tcp_bound_pcbs; extern union tcp_listen_pcbs_t tcp_listen_pcbs; extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a state in which they accept or send data. */ extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */ /* Axioms about the above lists: 1) Every TCP PCB that is not CLOSED is in one of the lists. 2) A PCB is only in one of the lists. 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state. 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state. */ /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB with a PCB list or removes a PCB from a list, respectively. */ #ifndef TCP_DEBUG_PCB_LISTS #define TCP_DEBUG_PCB_LISTS 0 #endif #if TCP_DEBUG_PCB_LISTS #define TCP_REG(pcbs, npcb) do {\ LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \ for(tcp_tmp_pcb = *(pcbs); \ tcp_tmp_pcb != NULL; \ tcp_tmp_pcb = tcp_tmp_pcb->next) { \ LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \ } \ LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \ (npcb)->next = *(pcbs); \ LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \ *(pcbs) = (npcb); \ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ tcp_timer_needed(); \ } while(0) #define TCP_RMV(pcbs, npcb) do { \ LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \ 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; \ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \ } while(0) #else /* LWIP_DEBUG */ #define TCP_REG(pcbs, npcb) \ do { \ (npcb)->next = *pcbs; \ *(pcbs) = (npcb); \ tcp_timer_needed(); \ } while (0) #define TCP_RMV(pcbs, npcb) \ 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) #endif /* LWIP_DEBUG */ /* Internal functions: */ struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_pcb_purge(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_segs_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR; void tcp_seg_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR; struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg)ICACHE_FLASH_ATTR; #define tcp_ack(pcb) \ 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) \ do { \ (pcb)->flags |= TF_ACK_NOW; \ } while (0) err_t tcp_send_fin(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)ICACHE_FLASH_ATTR; void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg)ICACHE_FLASH_ATTR; 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)ICACHE_FLASH_ATTR; u32_t tcp_next_iss(void)ICACHE_FLASH_ATTR; void tcp_keepalive(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; void tcp_zero_window_probe(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR; #if TCP_CALCULATE_EFF_SEND_MSS u16_t tcp_eff_send_mss(u16_t sendmss, ip_addr_t *addr)ICACHE_FLASH_ATTR; #endif /* TCP_CALCULATE_EFF_SEND_MSS */ #if LWIP_CALLBACK_API err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)ICACHE_FLASH_ATTR; #endif /* LWIP_CALLBACK_API */ #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG void tcp_debug_print(struct tcp_hdr *tcphdr)ICACHE_FLASH_ATTR; void tcp_debug_print_flags(u8_t flags)ICACHE_FLASH_ATTR; void tcp_debug_print_state(enum tcp_state s)ICACHE_FLASH_ATTR; void tcp_debug_print_pcbs(void)ICACHE_FLASH_ATTR; s16_t tcp_pcbs_sane(void)ICACHE_FLASH_ATTR; #else # 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 #endif /* TCP_DEBUG */ /** 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_timer_needed(void)ICACHE_FLASH_ATTR; #ifdef __cplusplus } #endif #endif /* LWIP_TCP */ #endif /* __LWIP_TCP_H__ */
166  PACK_STRUCT_FIELD(u16_t urgp); //紧急指针
167 } PACK_STRUCT_STRUCT;
168 PACK_STRUCT_END
169 #ifdef PACK_STRUCT_USE_INCLUDES
170 # include "arch/epstruct.h"
171 #endif
172 
173 #define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
174 #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
175 #define TCPH_FLAGS(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
176 
177 #define TCPH_OFFSET_SET(phdr, offset) (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
178 #define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
179 #define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS((u16_t)(~(u16_t)(TCP_FLAGS)))) | htons(flags))
180 #define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags))
181 
182 #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
183 #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
184 
185 #define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
186 
189 #define TF_RESET (u8_t)0x08U /* Connection was reset. */
190 #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */
191 #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */
192 
193 
194 #if LWIP_EVENT_API
195 
196 #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
197  LWIP_EVENT_ACCEPT, NULL, 0, err)
198 #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
199  LWIP_EVENT_SENT, NULL, space, ERR_OK)
200 #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
201  LWIP_EVENT_RECV, (p), 0, (err))
202 #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
203  LWIP_EVENT_RECV, NULL, 0, ERR_OK)
204 #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
205  LWIP_EVENT_CONNECTED, NULL, 0, (err))
206 #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
207  LWIP_EVENT_POLL, NULL, 0, ERR_OK)
208 #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \
209  LWIP_EVENT_ERR, NULL, 0, (err))
210 
211 #else /* LWIP_EVENT_API */
212 
213 #define TCP_EVENT_ACCEPT(pcb,err,ret) \
214  do { \
215  if((pcb)->accept != NULL) \
216  (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \
217  else (ret) = ERR_ARG; \
218  } while (0)
219 
220 #define TCP_EVENT_SENT(pcb,space,ret) \
221  do { \
222  if((pcb)->sent != NULL) \
223  (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \
224  else (ret) = ERR_OK; \
225  } while (0)
226 
227 #define TCP_EVENT_RECV(pcb,p,err,ret) \
228  do { \
229  if((pcb)->recv != NULL) { \
230  (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));\
231  } else { \
232  (ret) = tcp_recv_null(NULL, (pcb), (p), (err)); \
233  } \
234  } while (0)
235 
236 #define TCP_EVENT_CLOSED(pcb,ret) \
237  do { \
238  if(((pcb)->recv != NULL)) { \
239  (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),NULL,ERR_OK);\
240  } else { \
241  (ret) = ERR_OK; \
242  } \
243  } while (0)
244 
245 #define TCP_EVENT_CONNECTED(pcb,err,ret) \
246  do { \
247  if((pcb)->connected != NULL) \
248  (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \
249  else (ret) = ERR_OK; \
250  } while (0)
251 
252 #define TCP_EVENT_POLL(pcb,ret) \
253  do { \
254  if((pcb)->poll != NULL) \
255  (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \
256  else (ret) = ERR_OK; \
257  } while (0)
258 
259 #define TCP_EVENT_ERR(errf,arg,err) \
260  do { \
261  if((errf) != NULL) \
262  (errf)((arg),(err)); \
263  } while (0)
264 
265 #endif /* LWIP_EVENT_API */
266 
268 #if TCP_OVERSIZE && defined(LWIP_DEBUG)
269 #define TCP_OVERSIZE_DBGCHECK 1
270 #else
271 #define TCP_OVERSIZE_DBGCHECK 0
272 #endif
273 
275 #define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP)
276 
277 /* This structure represents a TCP segment on the unsent, unacked and ooseq queues */
278 struct tcp_seg {
279  struct tcp_seg *next; /* used when putting segements on a queue */
280  struct pbuf *p; /* buffer containing data + TCP header */
281  void *dataptr; /* pointer to the TCP data in the pbuf */
282  u16_t len; /* the TCP length of this segment */
283 #if TCP_OVERSIZE_DBGCHECK
284  u16_t oversize_left; /* Extra bytes available at the end of the last
285  pbuf in unsent (used for asserting vs.
286  tcp_pcb.unsent_oversized only) */
287 #endif /* TCP_OVERSIZE_DBGCHECK */
288 #if TCP_CHECKSUM_ON_COPY
289  u16_t chksum;
290  u8_t chksum_swapped;
291 #endif /* TCP_CHECKSUM_ON_COPY */
292  u8_t flags;
293 #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */
294 #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */
295 #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is
296  checksummed into 'chksum' */
297  struct tcp_hdr *tcphdr; /* the TCP header */
298 };
299 
300 #define LWIP_TCP_OPT_LENGTH(flags) \
301  (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \
302  (flags & TF_SEG_OPTS_TS ? 12 : 0)
303 
305 #define TCP_BUILD_MSS_OPTION(x) (x) = PP_HTONL(((u32_t)2 << 24) | \
306  ((u32_t)4 << 16) | \
307  (((u32_t)TCP_MSS / 256) << 8) | \
308  (TCP_MSS & 255))
309 
310 /* Global variables: */
311 extern struct tcp_pcb *tcp_input_pcb;
312 extern u32_t tcp_ticks;
313 
314 /* The TCP PCB lists. */
315 union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
316  struct tcp_pcb_listen *listen_pcbs;
317  struct tcp_pcb *pcbs;
318 };
319 extern struct tcp_pcb *tcp_bound_pcbs;
320 extern union tcp_listen_pcbs_t tcp_listen_pcbs;
321 extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a
322  state in which they accept or send
323  data. */
324 extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */
325 
326 extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
327 
328 /* Axioms about the above lists:
329  1) Every TCP PCB that is not CLOSED is in one of the lists.
330  2) A PCB is only in one of the lists.
331  3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
332  4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.
333 */
334 /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB
335  with a PCB list or removes a PCB from a list, respectively. */
336 #ifndef TCP_DEBUG_PCB_LISTS
337 #define TCP_DEBUG_PCB_LISTS 0
338 #endif
339 #if TCP_DEBUG_PCB_LISTS
340 #define TCP_REG(pcbs, npcb) do {\
341  LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \
342  for(tcp_tmp_pcb = *(pcbs); \
343  tcp_tmp_pcb != NULL; \
344  tcp_tmp_pcb = tcp_tmp_pcb->next) { \
345  LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \
346  } \
347  LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \
348  (npcb)->next = *(pcbs); \
349  LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \
350  *(pcbs) = (npcb); \
351  LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
352  tcp_timer_needed(); \
353  } while(0)
354 #define TCP_RMV(pcbs, npcb) do { \
355  LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \
356  LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \
357  if(*(pcbs) == (npcb)) { \
358  *(pcbs) = (*pcbs)->next; \
359  } else for(tcp_tmp_pcb = *(pcbs); tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
360  if(tcp_tmp_pcb->next == (npcb)) { \
361  tcp_tmp_pcb->next = (npcb)->next; \
362  break; \
363  } \
364  } \
365  (npcb)->next = NULL; \
366  LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
367  LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \
368  } while(0)
369 
370 #else /* LWIP_DEBUG */
371 
372 #define TCP_REG(pcbs, npcb) \
373  do { \
374  (npcb)->next = *pcbs; \
375  *(pcbs) = (npcb); \
376  tcp_timer_needed(); \
377  } while (0)
378 
379 #define TCP_RMV(pcbs, npcb) \
380  do { \
381  if(*(pcbs) == (npcb)) { \
382  (*(pcbs)) = (*pcbs)->next; \
383  } \
384  else { \
385  for(tcp_tmp_pcb = *pcbs; \
386  tcp_tmp_pcb != NULL; \
387  tcp_tmp_pcb = tcp_tmp_pcb->next) { \
388  if(tcp_tmp_pcb->next == (npcb)) { \
389  tcp_tmp_pcb->next = (npcb)->next; \
390  break; \
391  } \
392  } \
393  } \
394  (npcb)->next = NULL; \
395  } while(0)
396 
397 #endif /* LWIP_DEBUG */
398 
399 
400 /* Internal functions: */
401 struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
402 void tcp_pcb_purge(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
403 void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
404 
405 void tcp_segs_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR;
406 void tcp_seg_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR;
407 struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg)ICACHE_FLASH_ATTR;
408 
409 #define tcp_ack(pcb) \
410  do { \
411  if((pcb)->flags & TF_ACK_DELAY) { \
412  (pcb)->flags &= ~TF_ACK_DELAY; \
413  (pcb)->flags |= TF_ACK_NOW; \
414  } \
415  else { \
416  (pcb)->flags |= TF_ACK_DELAY; \
417  } \
418  } while (0)
419 
420 #define tcp_ack_now(pcb) \
421  do { \
422  (pcb)->flags |= TF_ACK_NOW; \
423  } while (0)
424 
425 err_t tcp_send_fin(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
426 err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)ICACHE_FLASH_ATTR;
427 
428 void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg)ICACHE_FLASH_ATTR;
429 
430 void tcp_rst(u32_t seqno, u32_t ackno,
431  ip_addr_t *local_ip, ip_addr_t *remote_ip,
432  u16_t local_port, u16_t remote_port)ICACHE_FLASH_ATTR;
433 
434 u32_t tcp_next_iss(void)ICACHE_FLASH_ATTR;
435 
436 void tcp_keepalive(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
437 void tcp_zero_window_probe(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
438 
439 #if TCP_CALCULATE_EFF_SEND_MSS
440 u16_t tcp_eff_send_mss(u16_t sendmss, ip_addr_t *addr)ICACHE_FLASH_ATTR;
441 #endif /* TCP_CALCULATE_EFF_SEND_MSS */
442 
443 #if LWIP_CALLBACK_API
444 err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)ICACHE_FLASH_ATTR;
445 #endif /* LWIP_CALLBACK_API */
446 
447 #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
448 void tcp_debug_print(struct tcp_hdr *tcphdr)ICACHE_FLASH_ATTR;
449 void tcp_debug_print_flags(u8_t flags)ICACHE_FLASH_ATTR;
450 void tcp_debug_print_state(enum tcp_state s)ICACHE_FLASH_ATTR;
451 void tcp_debug_print_pcbs(void)ICACHE_FLASH_ATTR;
452 s16_t tcp_pcbs_sane(void)ICACHE_FLASH_ATTR;
453 #else
454 # define tcp_debug_print(tcphdr)
455 # define tcp_debug_print_flags(flags)
456 # define tcp_debug_print_state(s)
457 # define tcp_debug_print_pcbs()
458 # define tcp_pcbs_sane() 1
459 #endif /* TCP_DEBUG */
460 
463 void tcp_timer_needed(void)ICACHE_FLASH_ATTR;
464 
465 
466 #ifdef __cplusplus
467 }
468 #endif
469 
470 #endif /* LWIP_TCP */
471 
472 #endif /* __LWIP_TCP_H__ */
u16_t len
Definition: pbuf.h:93
u8_t flags
Definition: pbuf.h:99
Definition: pbuf.h:76
Definition: netif.h:136