Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers tcp_impl.h Source File

tcp_impl.h

00001 /*
00002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission. 
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  * 
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 #ifndef __LWIP_TCP_IMPL_H__
00033 #define __LWIP_TCP_IMPL_H__
00034 
00035 #include "lwip/opt.h"
00036 
00037 #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
00038 
00039 #include "lwip/tcp.h"
00040 #include "lwip/sys.h"
00041 #include "lwip/mem.h"
00042 #include "lwip/pbuf.h"
00043 #include "lwip/ip.h"
00044 #include "lwip/icmp.h"
00045 #include "lwip/err.h"
00046 
00047 #ifdef __cplusplus
00048 extern "C" {
00049 #endif
00050 
00051 /* Functions for interfacing with TCP: */
00052 
00053 /* Lower layer interface to TCP: */
00054 #define tcp_init() /* Compatibility define, no init needed. */
00055 void             tcp_tmr     (void);  /* Must be called every
00056                                          TCP_TMR_INTERVAL
00057                                          ms. (Typically 250 ms). */
00058 /* It is also possible to call these two functions at the right
00059    intervals (instead of calling tcp_tmr()). */
00060 void             tcp_slowtmr (void);
00061 void             tcp_fasttmr (void);
00062 
00063 
00064 /* Only used by IP to pass a TCP segment to TCP: */
00065 void             tcp_input   (struct pbuf *p, struct netif *inp);
00066 /* Used within the TCP code only: */
00067 struct tcp_pcb * tcp_alloc   (u8_t prio);
00068 void             tcp_abandon (struct tcp_pcb *pcb, int reset);
00069 err_t            tcp_send_empty_ack(struct tcp_pcb *pcb);
00070 void             tcp_rexmit  (struct tcp_pcb *pcb);
00071 void             tcp_rexmit_rto  (struct tcp_pcb *pcb);
00072 void             tcp_rexmit_fast (struct tcp_pcb *pcb);
00073 u32_t            tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb);
00074 
00075 /**
00076  * This is the Nagle algorithm: try to combine user data to send as few TCP
00077  * segments as possible. Only send if
00078  * - no previously transmitted data on the connection remains unacknowledged or
00079  * - the TF_NODELAY flag is set (nagle algorithm turned off for this pcb) or
00080  * - the only unsent segment is at least pcb->mss bytes long (or there is more
00081  *   than one unsent segment - with lwIP, this can happen although unsent->len < mss)
00082  * - or if we are in fast-retransmit (TF_INFR)
00083  */
00084 #define tcp_do_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \
00085                             ((tpcb)->flags & (TF_NODELAY | TF_INFR)) || \
00086                             (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \
00087                               ((tpcb)->unsent->len >= (tpcb)->mss))) \
00088                             ) ? 1 : 0)
00089 #define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK)
00090 
00091 
00092 #define TCP_SEQ_LT(a,b)     ((s32_t)((a)-(b)) < 0)
00093 #define TCP_SEQ_LEQ(a,b)    ((s32_t)((a)-(b)) <= 0)
00094 #define TCP_SEQ_GT(a,b)     ((s32_t)((a)-(b)) > 0)
00095 #define TCP_SEQ_GEQ(a,b)    ((s32_t)((a)-(b)) >= 0)
00096 /* is b<=a<=c? */
00097 #if 0 /* see bug #10548 */
00098 #define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b))
00099 #endif
00100 #define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
00101 #define TCP_FIN 0x01U
00102 #define TCP_SYN 0x02U
00103 #define TCP_RST 0x04U
00104 #define TCP_PSH 0x08U
00105 #define TCP_ACK 0x10U
00106 #define TCP_URG 0x20U
00107 #define TCP_ECE 0x40U
00108 #define TCP_CWR 0x80U
00109 
00110 #define TCP_FLAGS 0x3fU
00111 
00112 /* Length of the TCP header, excluding options. */
00113 #define TCP_HLEN 20
00114 
00115 #ifndef TCP_TMR_INTERVAL
00116 #define TCP_TMR_INTERVAL       250  /* The TCP timer interval in milliseconds. */
00117 #endif /* TCP_TMR_INTERVAL */
00118 
00119 #ifndef TCP_FAST_INTERVAL
00120 #define TCP_FAST_INTERVAL      TCP_TMR_INTERVAL /* the fine grained timeout in milliseconds */
00121 #endif /* TCP_FAST_INTERVAL */
00122 
00123 #ifndef TCP_SLOW_INTERVAL
00124 #define TCP_SLOW_INTERVAL      (2*TCP_TMR_INTERVAL)  /* the coarse grained timeout in milliseconds */
00125 #endif /* TCP_SLOW_INTERVAL */
00126 
00127 #define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */
00128 #define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */
00129 
00130 #define TCP_OOSEQ_TIMEOUT        6U /* x RTO */
00131 
00132 #ifndef TCP_MSL
00133 #define TCP_MSL 60000UL /* The maximum segment lifetime in milliseconds */
00134 #endif
00135 
00136 /* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */
00137 #ifndef  TCP_KEEPIDLE_DEFAULT
00138 #define  TCP_KEEPIDLE_DEFAULT     7200000UL /* Default KEEPALIVE timer in milliseconds */
00139 #endif
00140 
00141 #ifndef  TCP_KEEPINTVL_DEFAULT
00142 #define  TCP_KEEPINTVL_DEFAULT    75000UL   /* Default Time between KEEPALIVE probes in milliseconds */
00143 #endif
00144 
00145 #ifndef  TCP_KEEPCNT_DEFAULT
00146 #define  TCP_KEEPCNT_DEFAULT      9U        /* Default Counter for KEEPALIVE probes */
00147 #endif
00148 
00149 #define  TCP_MAXIDLE              TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT  /* Maximum KEEPALIVE probe time */
00150 
00151 /* Fields are (of course) in network byte order.
00152  * Some fields are converted to host byte order in tcp_input().
00153  */
00154 #ifdef PACK_STRUCT_USE_INCLUDES
00155 #  include "arch/bpstruct.h"
00156 #endif
00157 PACK_STRUCT_BEGIN
00158 struct tcp_hdr {
00159   PACK_STRUCT_FIELD(u16_t src);
00160   PACK_STRUCT_FIELD(u16_t dest);
00161   PACK_STRUCT_FIELD(u32_t seqno);
00162   PACK_STRUCT_FIELD(u32_t ackno);
00163   PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);
00164   PACK_STRUCT_FIELD(u16_t wnd);
00165   PACK_STRUCT_FIELD(u16_t chksum);
00166   PACK_STRUCT_FIELD(u16_t urgp);
00167 } PACK_STRUCT_STRUCT;
00168 PACK_STRUCT_END
00169 #ifdef PACK_STRUCT_USE_INCLUDES
00170 #  include "arch/epstruct.h"
00171 #endif
00172 
00173 #define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
00174 #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
00175 #define TCPH_FLAGS(phdr)  (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
00176 
00177 #define TCPH_OFFSET_SET(phdr, offset) (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
00178 #define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
00179 #define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS((u16_t)(~(u16_t)(TCP_FLAGS)))) | htons(flags))
00180 #define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags))
00181 
00182 #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
00183 #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
00184 
00185 #define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
00186 
00187 /** Flags used on input processing, not on pcb->flags
00188 */
00189 #define TF_RESET     (u8_t)0x08U   /* Connection was reset. */
00190 #define TF_CLOSED    (u8_t)0x10U   /* Connection was sucessfully closed. */
00191 #define TF_GOT_FIN   (u8_t)0x20U   /* Connection was closed by the remote end. */
00192 
00193 
00194 #if LWIP_EVENT_API
00195 
00196 #define TCP_EVENT_ACCEPT(pcb,err,ret)    ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
00197                 LWIP_EVENT_ACCEPT, NULL, 0, err)
00198 #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
00199                    LWIP_EVENT_SENT, NULL, space, ERR_OK)
00200 #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
00201                 LWIP_EVENT_RECV, (p), 0, (err))
00202 #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
00203                 LWIP_EVENT_RECV, NULL, 0, ERR_OK)
00204 #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
00205                 LWIP_EVENT_CONNECTED, NULL, 0, (err))
00206 #define TCP_EVENT_POLL(pcb,ret)       ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
00207                 LWIP_EVENT_POLL, NULL, 0, ERR_OK)
00208 #define TCP_EVENT_ERR(errf,arg,err)  lwip_tcp_event((arg), NULL, \
00209                 LWIP_EVENT_ERR, NULL, 0, (err))
00210 
00211 #else /* LWIP_EVENT_API */
00212 
00213 #define TCP_EVENT_ACCEPT(pcb,err,ret)                          \
00214   do {                                                         \
00215     if((pcb)->accept != NULL)                                  \
00216       (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err));  \
00217     else (ret) = ERR_ARG;                                      \
00218   } while (0)
00219 
00220 #define TCP_EVENT_SENT(pcb,space,ret)                          \
00221   do {                                                         \
00222     if((pcb)->sent != NULL)                                    \
00223       (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space));  \
00224     else (ret) = ERR_OK;                                       \
00225   } while (0)
00226 
00227 #define TCP_EVENT_RECV(pcb,p,err,ret)                          \
00228   do {                                                         \
00229     if((pcb)->recv != NULL) {                                  \
00230       (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));\
00231     } else {                                                   \
00232       (ret) = tcp_recv_null(NULL, (pcb), (p), (err));          \
00233     }                                                          \
00234   } while (0)
00235 
00236 #define TCP_EVENT_CLOSED(pcb,ret)                                \
00237   do {                                                           \
00238     if(((pcb)->recv != NULL)) {                                  \
00239       (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),NULL,ERR_OK);\
00240     } else {                                                     \
00241       (ret) = ERR_OK;                                            \
00242     }                                                            \
00243   } while (0)
00244 
00245 #define TCP_EVENT_CONNECTED(pcb,err,ret)                         \
00246   do {                                                           \
00247     if((pcb)->connected != NULL)                                 \
00248       (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \
00249     else (ret) = ERR_OK;                                         \
00250   } while (0)
00251 
00252 #define TCP_EVENT_POLL(pcb,ret)                                \
00253   do {                                                         \
00254     if((pcb)->poll != NULL)                                    \
00255       (ret) = (pcb)->poll((pcb)->callback_arg,(pcb));          \
00256     else (ret) = ERR_OK;                                       \
00257   } while (0)
00258 
00259 #define TCP_EVENT_ERR(errf,arg,err)                            \
00260   do {                                                         \
00261     if((errf) != NULL)                                         \
00262       (errf)((arg),(err));                                     \
00263   } while (0)
00264 
00265 #endif /* LWIP_EVENT_API */
00266 
00267 /** Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled */
00268 #if TCP_OVERSIZE && defined(LWIP_DEBUG)
00269 #define TCP_OVERSIZE_DBGCHECK 1
00270 #else
00271 #define TCP_OVERSIZE_DBGCHECK 0
00272 #endif
00273 
00274 /** Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled */
00275 #define TCP_CHECKSUM_ON_COPY  (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP)
00276 
00277 /* This structure represents a TCP segment on the unsent, unacked and ooseq queues */
00278 struct tcp_seg {
00279   struct tcp_seg *next;    /* used when putting segements on a queue */
00280   struct pbuf *p;          /* buffer containing data + TCP header */
00281   void *dataptr;           /* pointer to the TCP data in the pbuf */
00282   u16_t len;               /* the TCP length of this segment */
00283 #if TCP_OVERSIZE_DBGCHECK
00284   u16_t oversize_left;     /* Extra bytes available at the end of the last
00285                               pbuf in unsent (used for asserting vs.
00286                               tcp_pcb.unsent_oversized only) */
00287 #endif /* TCP_OVERSIZE_DBGCHECK */ 
00288 #if TCP_CHECKSUM_ON_COPY
00289   u16_t chksum;
00290   u8_t  chksum_swapped;
00291 #endif /* TCP_CHECKSUM_ON_COPY */
00292   u8_t  flags;
00293 #define TF_SEG_OPTS_MSS         (u8_t)0x01U /* Include MSS option. */
00294 #define TF_SEG_OPTS_TS          (u8_t)0x02U /* Include timestamp option. */
00295 #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is
00296                                                checksummed into 'chksum' */
00297   struct tcp_hdr *tcphdr;  /* the TCP header */
00298 };
00299 
00300 #define LWIP_TCP_OPT_LENGTH(flags)              \
00301   (flags & TF_SEG_OPTS_MSS ? 4  : 0) +          \
00302   (flags & TF_SEG_OPTS_TS  ? 12 : 0)
00303 
00304 /** This returns a TCP header option for MSS in an u32_t */
00305 #define TCP_BUILD_MSS_OPTION(x) (x) = PP_HTONL(((u32_t)2 << 24) |          \
00306                                                ((u32_t)4 << 16) |          \
00307                                                (((u32_t)TCP_MSS / 256) << 8) | \
00308                                                (TCP_MSS & 255))
00309 
00310 /* Global variables: */
00311 extern struct tcp_pcb *tcp_input_pcb;
00312 extern u32_t tcp_ticks;
00313 
00314 /* The TCP PCB lists. */
00315 union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
00316   struct tcp_pcb_listen *listen_pcbs; 
00317   struct tcp_pcb *pcbs;
00318 };
00319 extern struct tcp_pcb *tcp_bound_pcbs;
00320 extern union tcp_listen_pcbs_t tcp_listen_pcbs;
00321 extern struct tcp_pcb *tcp_active_pcbs;  /* List of all TCP PCBs that are in a
00322               state in which they accept or send
00323               data. */
00324 extern struct tcp_pcb *tcp_tw_pcbs;      /* List of all TCP PCBs in TIME-WAIT. */
00325 
00326 extern struct tcp_pcb *tcp_tmp_pcb;      /* Only used for temporary storage. */
00327 
00328 /* Axioms about the above lists:   
00329    1) Every TCP PCB that is not CLOSED is in one of the lists.
00330    2) A PCB is only in one of the lists.
00331    3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
00332    4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.
00333 */
00334 /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB
00335    with a PCB list or removes a PCB from a list, respectively. */
00336 #ifndef TCP_DEBUG_PCB_LISTS
00337 #define TCP_DEBUG_PCB_LISTS 0
00338 #endif
00339 #if TCP_DEBUG_PCB_LISTS
00340 #define TCP_REG(pcbs, npcb) do {\
00341                             LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \
00342                             for(tcp_tmp_pcb = *(pcbs); \
00343           tcp_tmp_pcb != NULL; \
00344         tcp_tmp_pcb = tcp_tmp_pcb->next) { \
00345                                 LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \
00346                             } \
00347                             LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \
00348                             (npcb)->next = *(pcbs); \
00349                             LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \
00350                             *(pcbs) = (npcb); \
00351                             LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
00352               tcp_timer_needed(); \
00353                             } while(0)
00354 #define TCP_RMV(pcbs, npcb) do { \
00355                             LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \
00356                             LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \
00357                             if(*(pcbs) == (npcb)) { \
00358                                *(pcbs) = (*pcbs)->next; \
00359                             } else for(tcp_tmp_pcb = *(pcbs); tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
00360                                if(tcp_tmp_pcb->next == (npcb)) { \
00361                                   tcp_tmp_pcb->next = (npcb)->next; \
00362                                   break; \
00363                                } \
00364                             } \
00365                             (npcb)->next = NULL; \
00366                             LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
00367                             LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \
00368                             } while(0)
00369 
00370 #else /* LWIP_DEBUG */
00371 
00372 #define TCP_REG(pcbs, npcb)                        \
00373   do {                                             \
00374     (npcb)->next = *pcbs;                          \
00375     *(pcbs) = (npcb);                              \
00376     tcp_timer_needed();                            \
00377   } while (0)
00378 
00379 #define TCP_RMV(pcbs, npcb)                        \
00380   do {                                             \
00381     if(*(pcbs) == (npcb)) {                        \
00382       (*(pcbs)) = (*pcbs)->next;                   \
00383     }                                              \
00384     else {                                         \
00385       for(tcp_tmp_pcb = *pcbs;                     \
00386           tcp_tmp_pcb != NULL;                     \
00387           tcp_tmp_pcb = tcp_tmp_pcb->next) {       \
00388         if(tcp_tmp_pcb->next == (npcb)) {          \
00389           tcp_tmp_pcb->next = (npcb)->next;        \
00390           break;                                   \
00391         }                                          \
00392       }                                            \
00393     }                                              \
00394     (npcb)->next = NULL;                           \
00395   } while(0)
00396 
00397 #endif /* LWIP_DEBUG */
00398 
00399 
00400 /* Internal functions: */
00401 struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb);
00402 void tcp_pcb_purge(struct tcp_pcb *pcb);
00403 void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb);
00404 
00405 void tcp_segs_free(struct tcp_seg *seg);
00406 void tcp_seg_free(struct tcp_seg *seg);
00407 struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);
00408 
00409 #define tcp_ack(pcb)                               \
00410   do {                                             \
00411     if((pcb)->flags & TF_ACK_DELAY) {              \
00412       (pcb)->flags &= ~TF_ACK_DELAY;               \
00413       (pcb)->flags |= TF_ACK_NOW;                  \
00414     }                                              \
00415     else {                                         \
00416       (pcb)->flags |= TF_ACK_DELAY;                \
00417     }                                              \
00418   } while (0)
00419 
00420 #define tcp_ack_now(pcb)                           \
00421   do {                                             \
00422     (pcb)->flags |= TF_ACK_NOW;                    \
00423   } while (0)
00424 
00425 err_t tcp_send_fin(struct tcp_pcb *pcb);
00426 err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags);
00427 
00428 void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
00429 
00430 void tcp_rst(u32_t seqno, u32_t ackno,
00431        ip_addr_t *local_ip, ip_addr_t *remote_ip,
00432        u16_t local_port, u16_t remote_port);
00433 
00434 u32_t tcp_next_iss(void);
00435 
00436 void tcp_keepalive(struct tcp_pcb *pcb);
00437 void tcp_zero_window_probe(struct tcp_pcb *pcb);
00438 
00439 #if TCP_CALCULATE_EFF_SEND_MSS
00440 u16_t tcp_eff_send_mss(u16_t sendmss, ip_addr_t *addr);
00441 #endif /* TCP_CALCULATE_EFF_SEND_MSS */
00442 
00443 #if LWIP_CALLBACK_API
00444 err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
00445 #endif /* LWIP_CALLBACK_API */
00446 
00447 #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
00448 void tcp_debug_print(struct tcp_hdr *tcphdr);
00449 void tcp_debug_print_flags(u8_t flags);
00450 void tcp_debug_print_state(enum tcp_state s);
00451 void tcp_debug_print_pcbs(void);
00452 s16_t tcp_pcbs_sane(void);
00453 #else
00454 #  define tcp_debug_print(tcphdr)
00455 #  define tcp_debug_print_flags(flags)
00456 #  define tcp_debug_print_state(s)
00457 #  define tcp_debug_print_pcbs()
00458 #  define tcp_pcbs_sane() 1
00459 #endif /* TCP_DEBUG */
00460 
00461 /** External function (implemented in timers.c), called when TCP detects
00462  * that a timer is needed (i.e. active- or time-wait-pcb found). */
00463 void tcp_timer_needed(void);
00464 
00465 
00466 #ifdef __cplusplus
00467 }
00468 #endif
00469 
00470 #endif /* LWIP_TCP */
00471 
00472 #endif /* __LWIP_TCP_H__ */