tcp_impl.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. #include "lwip/opt.h"
  35. #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
  36. #include "lwip/tcp.h"
  37. #include "lwip/sys.h"
  38. #include "lwip/mem.h"
  39. #include "lwip/pbuf.h"
  40. #include "lwip/ip.h"
  41. #include "lwip/icmp.h"
  42. #include "lwip/err.h"
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /* Functions for interfacing with TCP: */
  47. /* Lower layer interface to TCP: */
  48. #define tcp_init() /* Compatibility define, no init needed. */
  49. void tcp_tmr (void)ICACHE_FLASH_ATTR; /* Must be called every
  50. TCP_TMR_INTERVAL
  51. ms. (Typically 250 ms). */
  52. /* It is also possible to call these two functions at the right
  53. intervals (instead of calling tcp_tmr()). */
  54. void tcp_slowtmr (void)ICACHE_FLASH_ATTR;
  55. void tcp_fasttmr (void)ICACHE_FLASH_ATTR;
  56. /* Only used by IP to pass a TCP segment to TCP: */
  57. void tcp_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_ATTR;
  58. /* Used within the TCP code only: */
  59. struct tcp_pcb * tcp_alloc (u8_t prio)ICACHE_FLASH_ATTR;
  60. void tcp_abandon (struct tcp_pcb *pcb, int reset)ICACHE_FLASH_ATTR;
  61. err_t tcp_send_empty_ack(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  62. void tcp_rexmit (struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  63. void tcp_rexmit_rto (struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  64. void tcp_rexmit_fast (struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  65. u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  66. /**
  67. * This is the Nagle algorithm: try to combine user data to send as few TCP
  68. * segments as possible. Only send if
  69. * - no previously transmitted data on the connection remains unacknowledged or
  70. * - the TF_NODELAY flag is set (nagle algorithm turned off for this pcb) or
  71. * - the only unsent segment is at least pcb->mss bytes long (or there is more
  72. * than one unsent segment - with lwIP, this can happen although unsent->len < mss)
  73. * - or if we are in fast-retransmit (TF_INFR)
  74. */
  75. #define tcp_do_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \
  76. ((tpcb)->flags & (TF_NODELAY | TF_INFR)) || \
  77. (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \
  78. ((tpcb)->unsent->len >= (tpcb)->mss))) \
  79. ) ? 1 : 0)
  80. #define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK)
  81. #define TCP_SEQ_LT(a,b) ((s32_t)((a)-(b)) < 0)
  82. #define TCP_SEQ_LEQ(a,b) ((s32_t)((a)-(b)) <= 0)
  83. #define TCP_SEQ_GT(a,b) ((s32_t)((a)-(b)) > 0)
  84. #define TCP_SEQ_GEQ(a,b) ((s32_t)((a)-(b)) >= 0)
  85. /* is b<=a<=c? */
  86. #if 0 /* see bug #10548 */
  87. #define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b))
  88. #endif
  89. #define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
  90. #define TCP_FIN 0x01U
  91. #define TCP_SYN 0x02U
  92. #define TCP_RST 0x04U
  93. #define TCP_PSH 0x08U
  94. #define TCP_ACK 0x10U
  95. #define TCP_URG 0x20U
  96. #define TCP_ECE 0x40U
  97. #define TCP_CWR 0x80U
  98. #define TCP_FLAGS 0x3fU
  99. /* Length of the TCP header, excluding options. */
  100. #define TCP_HLEN 20
  101. #ifndef TCP_TMR_INTERVAL
  102. #define TCP_TMR_INTERVAL 125 /* The TCP timer interval in milliseconds. */
  103. #endif /* TCP_TMR_INTERVAL */
  104. #ifndef TCP_FAST_INTERVAL
  105. #define TCP_FAST_INTERVAL TCP_TMR_INTERVAL /* the fine grained timeout in milliseconds */
  106. #endif /* TCP_FAST_INTERVAL */
  107. #ifndef TCP_SLOW_INTERVAL
  108. #define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) /* the coarse grained timeout in milliseconds */
  109. #endif /* TCP_SLOW_INTERVAL */
  110. #define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */
  111. #define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */
  112. #define TCP_OOSEQ_TIMEOUT 6U /* x RTO */
  113. #ifndef TCP_MSL
  114. #define TCP_MSL 60000UL /* The maximum segment lifetime in milliseconds */
  115. #endif
  116. /* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */
  117. #ifndef TCP_KEEPIDLE_DEFAULT
  118. #define TCP_KEEPIDLE_DEFAULT 120000UL /* Default KEEPALIVE timer in milliseconds */
  119. #endif
  120. #ifndef TCP_KEEPINTVL_DEFAULT
  121. #define TCP_KEEPINTVL_DEFAULT 10000UL /* Default Time between KEEPALIVE probes in milliseconds */
  122. #endif
  123. #ifndef TCP_KEEPCNT_DEFAULT
  124. #define TCP_KEEPCNT_DEFAULT 9U /* Default Counter for KEEPALIVE probes */
  125. #endif
  126. #define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */
  127. /* Fields are (of course) in network byte order.
  128. * Some fields are converted to host byte order in tcp_input().
  129. */
  130. #ifdef PACK_STRUCT_USE_INCLUDES
  131. # include "arch/bpstruct.h"
  132. #endif
  133. PACK_STRUCT_BEGIN
  134. struct tcp_hdr {
  135. PACK_STRUCT_FIELD(u16_t src); //Դ�˿�
  136. PACK_STRUCT_FIELD(u16_t dest); //Ŀ�Ķ˿�
  137. PACK_STRUCT_FIELD(u32_t seqno); //���
  138. PACK_STRUCT_FIELD(u32_t ackno); //Ӧ�����
  139. PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);//�ײ�����+����λ+��־λ
  140. PACK_STRUCT_FIELD(u16_t wnd); //���ڴ�С
  141. PACK_STRUCT_FIELD(u16_t chksum); //���
  142. PACK_STRUCT_FIELD(u16_t urgp); //����ָ��
  143. } PACK_STRUCT_STRUCT;
  144. PACK_STRUCT_END
  145. #ifdef PACK_STRUCT_USE_INCLUDES
  146. # include "arch/epstruct.h"
  147. #endif
  148. #define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
  149. #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
  150. #define TCPH_FLAGS(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
  151. #define TCPH_OFFSET_SET(phdr, offset) (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
  152. #define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
  153. #define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS((u16_t)(~(u16_t)(TCP_FLAGS)))) | htons(flags))
  154. #define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags))
  155. #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
  156. #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
  157. #define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
  158. /** Flags used on input processing, not on pcb->flags
  159. */
  160. #define TF_RESET (u8_t)0x08U /* Connection was reset. */
  161. #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */
  162. #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */
  163. #if LWIP_EVENT_API
  164. #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
  165. LWIP_EVENT_ACCEPT, NULL, 0, err)
  166. #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
  167. LWIP_EVENT_SENT, NULL, space, ERR_OK)
  168. #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
  169. LWIP_EVENT_RECV, (p), 0, (err))
  170. #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
  171. LWIP_EVENT_RECV, NULL, 0, ERR_OK)
  172. #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
  173. LWIP_EVENT_CONNECTED, NULL, 0, (err))
  174. #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
  175. LWIP_EVENT_POLL, NULL, 0, ERR_OK)
  176. #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \
  177. LWIP_EVENT_ERR, NULL, 0, (err))
  178. #else /* LWIP_EVENT_API */
  179. #define TCP_EVENT_ACCEPT(pcb,err,ret) \
  180. do { \
  181. if((pcb)->accept != NULL) \
  182. (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \
  183. else (ret) = ERR_ARG; \
  184. } while (0)
  185. #define TCP_EVENT_SENT(pcb,space,ret) \
  186. do { \
  187. if((pcb)->sent != NULL) \
  188. (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \
  189. else (ret) = ERR_OK; \
  190. } while (0)
  191. #define TCP_EVENT_RECV(pcb,p,err,ret) \
  192. do { \
  193. if((pcb)->recv != NULL) { \
  194. (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));\
  195. } else { \
  196. (ret) = tcp_recv_null(NULL, (pcb), (p), (err)); \
  197. } \
  198. } while (0)
  199. #define TCP_EVENT_CLOSED(pcb,ret) \
  200. do { \
  201. if(((pcb)->recv != NULL)) { \
  202. (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),NULL,ERR_OK);\
  203. } else { \
  204. (ret) = ERR_OK; \
  205. } \
  206. } while (0)
  207. #define TCP_EVENT_CONNECTED(pcb,err,ret) \
  208. do { \
  209. if((pcb)->connected != NULL) \
  210. (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \
  211. else (ret) = ERR_OK; \
  212. } while (0)
  213. #define TCP_EVENT_POLL(pcb,ret) \
  214. do { \
  215. if((pcb)->poll != NULL) \
  216. (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \
  217. else (ret) = ERR_OK; \
  218. } while (0)
  219. #define TCP_EVENT_ERR(errf,arg,err) \
  220. do { \
  221. if((errf) != NULL) \
  222. (errf)((arg),(err)); \
  223. } while (0)
  224. #endif /* LWIP_EVENT_API */
  225. /** Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled */
  226. #if TCP_OVERSIZE && defined(LWIP_DEBUG)
  227. #define TCP_OVERSIZE_DBGCHECK 1
  228. #else
  229. #define TCP_OVERSIZE_DBGCHECK 0
  230. #endif
  231. /** Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled */
  232. #define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP)
  233. /* This structure represents a TCP segment on the unsent, unacked and ooseq queues */
  234. struct tcp_seg {
  235. struct tcp_seg *next; /* used when putting segements on a queue */
  236. struct pbuf *p; /* buffer containing data + TCP header */
  237. void *dataptr; /* pointer to the TCP data in the pbuf */
  238. u16_t len; /* the TCP length of this segment */
  239. #if TCP_OVERSIZE_DBGCHECK
  240. u16_t oversize_left; /* Extra bytes available at the end of the last
  241. pbuf in unsent (used for asserting vs.
  242. tcp_pcb.unsent_oversized only) */
  243. #endif /* TCP_OVERSIZE_DBGCHECK */
  244. #if TCP_CHECKSUM_ON_COPY
  245. u16_t chksum;
  246. u8_t chksum_swapped;
  247. #endif /* TCP_CHECKSUM_ON_COPY */
  248. u8_t flags;
  249. #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */
  250. #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */
  251. #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is
  252. checksummed into 'chksum' */
  253. struct tcp_hdr *tcphdr; /* the TCP header */
  254. };
  255. #define LWIP_TCP_OPT_LENGTH(flags) \
  256. (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \
  257. (flags & TF_SEG_OPTS_TS ? 12 : 0)
  258. /** This returns a TCP header option for MSS in an u32_t */
  259. #define TCP_BUILD_MSS_OPTION(x) (x) = PP_HTONL(((u32_t)2 << 24) | \
  260. ((u32_t)4 << 16) | \
  261. (((u32_t)TCP_MSS / 256) << 8) | \
  262. (TCP_MSS & 255))
  263. /* Global variables: */
  264. extern struct tcp_pcb *tcp_input_pcb;
  265. extern u32_t tcp_ticks;
  266. /* The TCP PCB lists. */
  267. union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
  268. struct tcp_pcb_listen *listen_pcbs;
  269. struct tcp_pcb *pcbs;
  270. };
  271. extern struct tcp_pcb *tcp_bound_pcbs;
  272. extern union tcp_listen_pcbs_t tcp_listen_pcbs;
  273. extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a
  274. state in which they accept or send
  275. data. */
  276. extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */
  277. extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
  278. /* Axioms about the above lists:
  279. 1) Every TCP PCB that is not CLOSED is in one of the lists.
  280. 2) A PCB is only in one of the lists.
  281. 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
  282. 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.
  283. */
  284. /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB
  285. with a PCB list or removes a PCB from a list, respectively. */
  286. #ifndef TCP_DEBUG_PCB_LISTS
  287. #define TCP_DEBUG_PCB_LISTS 0
  288. #endif
  289. #if TCP_DEBUG_PCB_LISTS
  290. #define TCP_REG(pcbs, npcb) do {\
  291. LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \
  292. for(tcp_tmp_pcb = *(pcbs); \
  293. tcp_tmp_pcb != NULL; \
  294. tcp_tmp_pcb = tcp_tmp_pcb->next) { \
  295. LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \
  296. } \
  297. LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \
  298. (npcb)->next = *(pcbs); \
  299. LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \
  300. *(pcbs) = (npcb); \
  301. LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
  302. tcp_timer_needed(); \
  303. } while(0)
  304. #define TCP_RMV(pcbs, npcb) do { \
  305. LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \
  306. LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \
  307. if(*(pcbs) == (npcb)) { \
  308. *(pcbs) = (*pcbs)->next; \
  309. } else for(tcp_tmp_pcb = *(pcbs); tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
  310. if(tcp_tmp_pcb->next == (npcb)) { \
  311. tcp_tmp_pcb->next = (npcb)->next; \
  312. break; \
  313. } \
  314. } \
  315. (npcb)->next = NULL; \
  316. LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
  317. LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \
  318. } while(0)
  319. #else /* LWIP_DEBUG */
  320. #define TCP_REG(pcbs, npcb) \
  321. do { \
  322. (npcb)->next = *pcbs; \
  323. *(pcbs) = (npcb); \
  324. tcp_timer_needed(); \
  325. } while (0)
  326. #define TCP_RMV(pcbs, npcb) \
  327. do { \
  328. if(*(pcbs) == (npcb)) { \
  329. (*(pcbs)) = (*pcbs)->next; \
  330. } \
  331. else { \
  332. for(tcp_tmp_pcb = *pcbs; \
  333. tcp_tmp_pcb != NULL; \
  334. tcp_tmp_pcb = tcp_tmp_pcb->next) { \
  335. if(tcp_tmp_pcb->next == (npcb)) { \
  336. tcp_tmp_pcb->next = (npcb)->next; \
  337. break; \
  338. } \
  339. } \
  340. } \
  341. (npcb)->next = NULL; \
  342. } while(0)
  343. #endif /* LWIP_DEBUG */
  344. /* Internal functions: */
  345. struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  346. void tcp_pcb_purge(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  347. void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  348. void tcp_segs_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR;
  349. void tcp_seg_free(struct tcp_seg *seg)ICACHE_FLASH_ATTR;
  350. struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg)ICACHE_FLASH_ATTR;
  351. #define tcp_ack(pcb) \
  352. do { \
  353. if((pcb)->flags & TF_ACK_DELAY) { \
  354. (pcb)->flags &= ~TF_ACK_DELAY; \
  355. (pcb)->flags |= TF_ACK_NOW; \
  356. } \
  357. else { \
  358. (pcb)->flags |= TF_ACK_DELAY; \
  359. } \
  360. } while (0)
  361. #define tcp_ack_now(pcb) \
  362. do { \
  363. (pcb)->flags |= TF_ACK_NOW; \
  364. } while (0)
  365. err_t tcp_send_fin(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  366. err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)ICACHE_FLASH_ATTR;
  367. void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg)ICACHE_FLASH_ATTR;
  368. void tcp_rst(u32_t seqno, u32_t ackno,
  369. ip_addr_t *local_ip, ip_addr_t *remote_ip,
  370. u16_t local_port, u16_t remote_port)ICACHE_FLASH_ATTR;
  371. u32_t tcp_next_iss(void)ICACHE_FLASH_ATTR;
  372. void tcp_keepalive(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  373. void tcp_zero_window_probe(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
  374. #if TCP_CALCULATE_EFF_SEND_MSS
  375. u16_t tcp_eff_send_mss(u16_t sendmss, ip_addr_t *addr)ICACHE_FLASH_ATTR;
  376. #endif /* TCP_CALCULATE_EFF_SEND_MSS */
  377. #if LWIP_CALLBACK_API
  378. err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)ICACHE_FLASH_ATTR;
  379. #endif /* LWIP_CALLBACK_API */
  380. #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
  381. void tcp_debug_print(struct tcp_hdr *tcphdr)ICACHE_FLASH_ATTR;
  382. void tcp_debug_print_flags(u8_t flags)ICACHE_FLASH_ATTR;
  383. void tcp_debug_print_state(enum tcp_state s)ICACHE_FLASH_ATTR;
  384. void tcp_debug_print_pcbs(void)ICACHE_FLASH_ATTR;
  385. s16_t tcp_pcbs_sane(void)ICACHE_FLASH_ATTR;
  386. #else
  387. # define tcp_debug_print(tcphdr)
  388. # define tcp_debug_print_flags(flags)
  389. # define tcp_debug_print_state(s)
  390. # define tcp_debug_print_pcbs()
  391. # define tcp_pcbs_sane() 1
  392. #endif /* TCP_DEBUG */
  393. /** External function (implemented in timers.c), called when TCP detects
  394. * that a timer is needed (i.e. active- or time-wait-pcb found). */
  395. void tcp_timer_needed(void)ICACHE_FLASH_ATTR;
  396. #ifdef __cplusplus
  397. }
  398. #endif
  399. #endif /* LWIP_TCP */
  400. #endif /* __LWIP_TCP_H__ */