A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Committer:
root@mbed.org
Date:
Tue May 08 15:32:10 2012 +0100
Revision:
0:5e1631496985
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
root@mbed.org 0:5e1631496985 1 /*
root@mbed.org 0:5e1631496985 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
root@mbed.org 0:5e1631496985 3 * All rights reserved.
root@mbed.org 0:5e1631496985 4 *
root@mbed.org 0:5e1631496985 5 * Redistribution and use in source and binary forms, with or without modification,
root@mbed.org 0:5e1631496985 6 * are permitted provided that the following conditions are met:
root@mbed.org 0:5e1631496985 7 *
root@mbed.org 0:5e1631496985 8 * 1. Redistributions of source code must retain the above copyright notice,
root@mbed.org 0:5e1631496985 9 * this list of conditions and the following disclaimer.
root@mbed.org 0:5e1631496985 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
root@mbed.org 0:5e1631496985 11 * this list of conditions and the following disclaimer in the documentation
root@mbed.org 0:5e1631496985 12 * and/or other materials provided with the distribution.
root@mbed.org 0:5e1631496985 13 * 3. The name of the author may not be used to endorse or promote products
root@mbed.org 0:5e1631496985 14 * derived from this software without specific prior written permission.
root@mbed.org 0:5e1631496985 15 *
root@mbed.org 0:5e1631496985 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
root@mbed.org 0:5e1631496985 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
root@mbed.org 0:5e1631496985 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
root@mbed.org 0:5e1631496985 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
root@mbed.org 0:5e1631496985 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
root@mbed.org 0:5e1631496985 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
root@mbed.org 0:5e1631496985 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
root@mbed.org 0:5e1631496985 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
root@mbed.org 0:5e1631496985 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
root@mbed.org 0:5e1631496985 25 * OF SUCH DAMAGE.
root@mbed.org 0:5e1631496985 26 *
root@mbed.org 0:5e1631496985 27 * This file is part of the lwIP TCP/IP stack.
root@mbed.org 0:5e1631496985 28 *
root@mbed.org 0:5e1631496985 29 * Author: Adam Dunkels <adam@sics.se>
root@mbed.org 0:5e1631496985 30 *
root@mbed.org 0:5e1631496985 31 */
root@mbed.org 0:5e1631496985 32 #ifndef __LWIP_TCP_H__
root@mbed.org 0:5e1631496985 33 #define __LWIP_TCP_H__
root@mbed.org 0:5e1631496985 34
root@mbed.org 0:5e1631496985 35 #include "lwip/opt.h"
root@mbed.org 0:5e1631496985 36
root@mbed.org 0:5e1631496985 37 #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
root@mbed.org 0:5e1631496985 38
root@mbed.org 0:5e1631496985 39 #include "lwip/sys.h"
root@mbed.org 0:5e1631496985 40 #include "lwip/mem.h"
root@mbed.org 0:5e1631496985 41 #include "lwip/pbuf.h"
root@mbed.org 0:5e1631496985 42 #include "lwip/ip.h"
root@mbed.org 0:5e1631496985 43 #include "lwip/icmp.h"
root@mbed.org 0:5e1631496985 44 #include "lwip/err.h"
root@mbed.org 0:5e1631496985 45
root@mbed.org 0:5e1631496985 46 #ifdef __cplusplus
root@mbed.org 0:5e1631496985 47 extern "C" {
root@mbed.org 0:5e1631496985 48 #endif
root@mbed.org 0:5e1631496985 49
root@mbed.org 0:5e1631496985 50 struct tcp_pcb;
root@mbed.org 0:5e1631496985 51
root@mbed.org 0:5e1631496985 52 /* Functions for interfacing with TCP: */
root@mbed.org 0:5e1631496985 53
root@mbed.org 0:5e1631496985 54 /* Lower layer interface to TCP: */
root@mbed.org 0:5e1631496985 55 #define tcp_init() /* Compatibility define, not init needed. */
root@mbed.org 0:5e1631496985 56 void tcp_tmr (void); /* Must be called every
root@mbed.org 0:5e1631496985 57 TCP_TMR_INTERVAL
root@mbed.org 0:5e1631496985 58 ms. (Typically 250 ms). */
root@mbed.org 0:5e1631496985 59 /* Application program's interface: */
root@mbed.org 0:5e1631496985 60 struct tcp_pcb * tcp_new (void);
root@mbed.org 0:5e1631496985 61 struct tcp_pcb * tcp_alloc (u8_t prio);
root@mbed.org 0:5e1631496985 62
root@mbed.org 0:5e1631496985 63 void tcp_arg (struct tcp_pcb *pcb, void *arg);
root@mbed.org 0:5e1631496985 64 void tcp_accept (struct tcp_pcb *pcb,
root@mbed.org 0:5e1631496985 65 err_t (* accept)(void *arg, struct tcp_pcb *newpcb,
root@mbed.org 0:5e1631496985 66 err_t err));
root@mbed.org 0:5e1631496985 67 void tcp_recv (struct tcp_pcb *pcb,
root@mbed.org 0:5e1631496985 68 err_t (* recv)(void *arg, struct tcp_pcb *tpcb,
root@mbed.org 0:5e1631496985 69 struct pbuf *p, err_t err));
root@mbed.org 0:5e1631496985 70 void tcp_sent (struct tcp_pcb *pcb,
root@mbed.org 0:5e1631496985 71 err_t (* sent)(void *arg, struct tcp_pcb *tpcb,
root@mbed.org 0:5e1631496985 72 u16_t len));
root@mbed.org 0:5e1631496985 73 void tcp_poll (struct tcp_pcb *pcb,
root@mbed.org 0:5e1631496985 74 err_t (* poll)(void *arg, struct tcp_pcb *tpcb),
root@mbed.org 0:5e1631496985 75 u8_t interval);
root@mbed.org 0:5e1631496985 76 void tcp_err (struct tcp_pcb *pcb,
root@mbed.org 0:5e1631496985 77 void (* err)(void *arg, err_t err));
root@mbed.org 0:5e1631496985 78
root@mbed.org 0:5e1631496985 79 #define tcp_mss(pcb) ((pcb)->mss)
root@mbed.org 0:5e1631496985 80 #define tcp_sndbuf(pcb) ((pcb)->snd_buf)
root@mbed.org 0:5e1631496985 81
root@mbed.org 0:5e1631496985 82 #if TCP_LISTEN_BACKLOG
root@mbed.org 0:5e1631496985 83 #define tcp_accepted(pcb) (((struct tcp_pcb_listen *)(pcb))->accepts_pending--)
root@mbed.org 0:5e1631496985 84 #else /* TCP_LISTEN_BACKLOG */
root@mbed.org 0:5e1631496985 85 #define tcp_accepted(pcb)
root@mbed.org 0:5e1631496985 86 #endif /* TCP_LISTEN_BACKLOG */
root@mbed.org 0:5e1631496985 87
root@mbed.org 0:5e1631496985 88 void tcp_recved (struct tcp_pcb *pcb, u16_t len);
root@mbed.org 0:5e1631496985 89 err_t tcp_bind (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
root@mbed.org 0:5e1631496985 90 u16_t port);
root@mbed.org 0:5e1631496985 91 err_t tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
root@mbed.org 0:5e1631496985 92 u16_t port, err_t (* connected)(void *arg,
root@mbed.org 0:5e1631496985 93 struct tcp_pcb *tpcb,
root@mbed.org 0:5e1631496985 94 err_t err));
root@mbed.org 0:5e1631496985 95
root@mbed.org 0:5e1631496985 96 struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog);
root@mbed.org 0:5e1631496985 97 #define tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG)
root@mbed.org 0:5e1631496985 98
root@mbed.org 0:5e1631496985 99 void tcp_abandon (struct tcp_pcb *pcb, int reset);
root@mbed.org 0:5e1631496985 100 #define tcp_abort(pcb) tcp_abandon((pcb), 1)
root@mbed.org 0:5e1631496985 101 err_t tcp_close (struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 102
root@mbed.org 0:5e1631496985 103 /* Flags for "apiflags" parameter in tcp_write and tcp_enqueue */
root@mbed.org 0:5e1631496985 104 #define TCP_WRITE_FLAG_COPY 0x01
root@mbed.org 0:5e1631496985 105 #define TCP_WRITE_FLAG_MORE 0x02
root@mbed.org 0:5e1631496985 106
root@mbed.org 0:5e1631496985 107 err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, u16_t len,
root@mbed.org 0:5e1631496985 108 u8_t apiflags);
root@mbed.org 0:5e1631496985 109
root@mbed.org 0:5e1631496985 110 void tcp_setprio (struct tcp_pcb *pcb, u8_t prio);
root@mbed.org 0:5e1631496985 111
root@mbed.org 0:5e1631496985 112 #define TCP_PRIO_MIN 1
root@mbed.org 0:5e1631496985 113 #define TCP_PRIO_NORMAL 64
root@mbed.org 0:5e1631496985 114 #define TCP_PRIO_MAX 127
root@mbed.org 0:5e1631496985 115
root@mbed.org 0:5e1631496985 116 /* It is also possible to call these two functions at the right
root@mbed.org 0:5e1631496985 117 intervals (instead of calling tcp_tmr()). */
root@mbed.org 0:5e1631496985 118 void tcp_slowtmr (void);
root@mbed.org 0:5e1631496985 119 void tcp_fasttmr (void);
root@mbed.org 0:5e1631496985 120
root@mbed.org 0:5e1631496985 121
root@mbed.org 0:5e1631496985 122 /* Only used by IP to pass a TCP segment to TCP: */
root@mbed.org 0:5e1631496985 123 void tcp_input (struct pbuf *p, struct netif *inp);
root@mbed.org 0:5e1631496985 124 /* Used within the TCP code only: */
root@mbed.org 0:5e1631496985 125 err_t tcp_output (struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 126 void tcp_rexmit (struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 127 void tcp_rexmit_rto (struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 128 void tcp_rexmit_fast (struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 129 u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 130
root@mbed.org 0:5e1631496985 131 /**
root@mbed.org 0:5e1631496985 132 * This is the Nagle algorithm: try to combine user data to send as few TCP
root@mbed.org 0:5e1631496985 133 * segments as possible. Only send if
root@mbed.org 0:5e1631496985 134 * - no previously transmitted data on the connection remains unacknowledged or
root@mbed.org 0:5e1631496985 135 * - the TF_NODELAY flag is set (nagle algorithm turned off for this pcb) or
root@mbed.org 0:5e1631496985 136 * - the only unsent segment is at least pcb->mss bytes long (or there is more
root@mbed.org 0:5e1631496985 137 * than one unsent segment - with lwIP, this can happen although unsent->len < mss)
root@mbed.org 0:5e1631496985 138 */
root@mbed.org 0:5e1631496985 139 #define tcp_do_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \
root@mbed.org 0:5e1631496985 140 ((tpcb)->flags & TF_NODELAY) || \
root@mbed.org 0:5e1631496985 141 (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \
root@mbed.org 0:5e1631496985 142 ((tpcb)->unsent->len >= (tpcb)->mss))) \
root@mbed.org 0:5e1631496985 143 ) ? 1 : 0)
root@mbed.org 0:5e1631496985 144 #define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK)
root@mbed.org 0:5e1631496985 145
root@mbed.org 0:5e1631496985 146
root@mbed.org 0:5e1631496985 147 #define TCP_SEQ_LT(a,b) ((s32_t)((a)-(b)) < 0)
root@mbed.org 0:5e1631496985 148 #define TCP_SEQ_LEQ(a,b) ((s32_t)((a)-(b)) <= 0)
root@mbed.org 0:5e1631496985 149 #define TCP_SEQ_GT(a,b) ((s32_t)((a)-(b)) > 0)
root@mbed.org 0:5e1631496985 150 #define TCP_SEQ_GEQ(a,b) ((s32_t)((a)-(b)) >= 0)
root@mbed.org 0:5e1631496985 151 /* is b<=a<=c? */
root@mbed.org 0:5e1631496985 152 #if 0 /* see bug #10548 */
root@mbed.org 0:5e1631496985 153 #define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b))
root@mbed.org 0:5e1631496985 154 #endif
root@mbed.org 0:5e1631496985 155 #define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
root@mbed.org 0:5e1631496985 156 #define TCP_FIN 0x01U
root@mbed.org 0:5e1631496985 157 #define TCP_SYN 0x02U
root@mbed.org 0:5e1631496985 158 #define TCP_RST 0x04U
root@mbed.org 0:5e1631496985 159 #define TCP_PSH 0x08U
root@mbed.org 0:5e1631496985 160 #define TCP_ACK 0x10U
root@mbed.org 0:5e1631496985 161 #define TCP_URG 0x20U
root@mbed.org 0:5e1631496985 162 #define TCP_ECE 0x40U
root@mbed.org 0:5e1631496985 163 #define TCP_CWR 0x80U
root@mbed.org 0:5e1631496985 164
root@mbed.org 0:5e1631496985 165 #define TCP_FLAGS 0x3fU
root@mbed.org 0:5e1631496985 166
root@mbed.org 0:5e1631496985 167 /* Length of the TCP header, excluding options. */
root@mbed.org 0:5e1631496985 168 #define TCP_HLEN 20
root@mbed.org 0:5e1631496985 169
root@mbed.org 0:5e1631496985 170 #ifndef TCP_TMR_INTERVAL
root@mbed.org 0:5e1631496985 171 #define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */
root@mbed.org 0:5e1631496985 172 #endif /* TCP_TMR_INTERVAL */
root@mbed.org 0:5e1631496985 173
root@mbed.org 0:5e1631496985 174 #ifndef TCP_FAST_INTERVAL
root@mbed.org 0:5e1631496985 175 #define TCP_FAST_INTERVAL TCP_TMR_INTERVAL /* the fine grained timeout in milliseconds */
root@mbed.org 0:5e1631496985 176 #endif /* TCP_FAST_INTERVAL */
root@mbed.org 0:5e1631496985 177
root@mbed.org 0:5e1631496985 178 #ifndef TCP_SLOW_INTERVAL
root@mbed.org 0:5e1631496985 179 #define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) /* the coarse grained timeout in milliseconds */
root@mbed.org 0:5e1631496985 180 #endif /* TCP_SLOW_INTERVAL */
root@mbed.org 0:5e1631496985 181
root@mbed.org 0:5e1631496985 182 #define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */
root@mbed.org 0:5e1631496985 183 #define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */
root@mbed.org 0:5e1631496985 184
root@mbed.org 0:5e1631496985 185 #define TCP_OOSEQ_TIMEOUT 6U /* x RTO */
root@mbed.org 0:5e1631496985 186
root@mbed.org 0:5e1631496985 187 #ifndef TCP_MSL
root@mbed.org 0:5e1631496985 188 #define TCP_MSL 60000UL /* The maximum segment lifetime in milliseconds */
root@mbed.org 0:5e1631496985 189 #endif
root@mbed.org 0:5e1631496985 190
root@mbed.org 0:5e1631496985 191 /* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */
root@mbed.org 0:5e1631496985 192 #ifndef TCP_KEEPIDLE_DEFAULT
root@mbed.org 0:5e1631496985 193 #define TCP_KEEPIDLE_DEFAULT 7200000UL /* Default KEEPALIVE timer in milliseconds */
root@mbed.org 0:5e1631496985 194 #endif
root@mbed.org 0:5e1631496985 195
root@mbed.org 0:5e1631496985 196 #ifndef TCP_KEEPINTVL_DEFAULT
root@mbed.org 0:5e1631496985 197 #define TCP_KEEPINTVL_DEFAULT 75000UL /* Default Time between KEEPALIVE probes in milliseconds */
root@mbed.org 0:5e1631496985 198 #endif
root@mbed.org 0:5e1631496985 199
root@mbed.org 0:5e1631496985 200 #ifndef TCP_KEEPCNT_DEFAULT
root@mbed.org 0:5e1631496985 201 #define TCP_KEEPCNT_DEFAULT 9U /* Default Counter for KEEPALIVE probes */
root@mbed.org 0:5e1631496985 202 #endif
root@mbed.org 0:5e1631496985 203
root@mbed.org 0:5e1631496985 204 #define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */
root@mbed.org 0:5e1631496985 205
root@mbed.org 0:5e1631496985 206 /* Fields are (of course) in network byte order.
root@mbed.org 0:5e1631496985 207 * Some fields are converted to host byte order in tcp_input().
root@mbed.org 0:5e1631496985 208 */
root@mbed.org 0:5e1631496985 209 #ifdef PACK_STRUCT_USE_INCLUDES
root@mbed.org 0:5e1631496985 210 # include "arch/bpstruct.h"
root@mbed.org 0:5e1631496985 211 #endif
root@mbed.org 0:5e1631496985 212 PACK_STRUCT_BEGIN
root@mbed.org 0:5e1631496985 213 struct tcp_hdr {
root@mbed.org 0:5e1631496985 214 PACK_STRUCT_FIELD(u16_t src);
root@mbed.org 0:5e1631496985 215 PACK_STRUCT_FIELD(u16_t dest);
root@mbed.org 0:5e1631496985 216 PACK_STRUCT_FIELD(u32_t seqno);
root@mbed.org 0:5e1631496985 217 PACK_STRUCT_FIELD(u32_t ackno);
root@mbed.org 0:5e1631496985 218 PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);
root@mbed.org 0:5e1631496985 219 PACK_STRUCT_FIELD(u16_t wnd);
root@mbed.org 0:5e1631496985 220 PACK_STRUCT_FIELD(u16_t chksum);
root@mbed.org 0:5e1631496985 221 PACK_STRUCT_FIELD(u16_t urgp);
root@mbed.org 0:5e1631496985 222 } PACK_STRUCT_STRUCT;
root@mbed.org 0:5e1631496985 223 PACK_STRUCT_END
root@mbed.org 0:5e1631496985 224 #ifdef PACK_STRUCT_USE_INCLUDES
root@mbed.org 0:5e1631496985 225 # include "arch/epstruct.h"
root@mbed.org 0:5e1631496985 226 #endif
root@mbed.org 0:5e1631496985 227
root@mbed.org 0:5e1631496985 228 #define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
root@mbed.org 0:5e1631496985 229 #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
root@mbed.org 0:5e1631496985 230 #define TCPH_FLAGS(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
root@mbed.org 0:5e1631496985 231
root@mbed.org 0:5e1631496985 232 #define TCPH_OFFSET_SET(phdr, offset) (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
root@mbed.org 0:5e1631496985 233 #define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
root@mbed.org 0:5e1631496985 234 #define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & htons((u16_t)(~(u16_t)(TCP_FLAGS)))) | htons(flags))
root@mbed.org 0:5e1631496985 235 #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
root@mbed.org 0:5e1631496985 236 #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
root@mbed.org 0:5e1631496985 237
root@mbed.org 0:5e1631496985 238 #define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
root@mbed.org 0:5e1631496985 239
root@mbed.org 0:5e1631496985 240 enum tcp_state {
root@mbed.org 0:5e1631496985 241 CLOSED = 0,
root@mbed.org 0:5e1631496985 242 LISTEN = 1,
root@mbed.org 0:5e1631496985 243 SYN_SENT = 2,
root@mbed.org 0:5e1631496985 244 SYN_RCVD = 3,
root@mbed.org 0:5e1631496985 245 ESTABLISHED = 4,
root@mbed.org 0:5e1631496985 246 FIN_WAIT_1 = 5,
root@mbed.org 0:5e1631496985 247 FIN_WAIT_2 = 6,
root@mbed.org 0:5e1631496985 248 CLOSE_WAIT = 7,
root@mbed.org 0:5e1631496985 249 CLOSING = 8,
root@mbed.org 0:5e1631496985 250 LAST_ACK = 9,
root@mbed.org 0:5e1631496985 251 TIME_WAIT = 10
root@mbed.org 0:5e1631496985 252 };
root@mbed.org 0:5e1631496985 253
root@mbed.org 0:5e1631496985 254 /** Flags used on input processing, not on pcb->flags
root@mbed.org 0:5e1631496985 255 */
root@mbed.org 0:5e1631496985 256 #define TF_RESET (u8_t)0x08U /* Connection was reset. */
root@mbed.org 0:5e1631496985 257 #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */
root@mbed.org 0:5e1631496985 258 #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */
root@mbed.org 0:5e1631496985 259
root@mbed.org 0:5e1631496985 260
root@mbed.org 0:5e1631496985 261 #if LWIP_CALLBACK_API
root@mbed.org 0:5e1631496985 262 /* Function to call when a listener has been connected.
root@mbed.org 0:5e1631496985 263 * @param arg user-supplied argument (tcp_pcb.callback_arg)
root@mbed.org 0:5e1631496985 264 * @param pcb a new tcp_pcb that now is connected
root@mbed.org 0:5e1631496985 265 * @param err an error argument (TODO: that is current always ERR_OK?)
root@mbed.org 0:5e1631496985 266 * @return ERR_OK: accept the new connection,
root@mbed.org 0:5e1631496985 267 * any other err_t abortsthe new connection
root@mbed.org 0:5e1631496985 268 */
root@mbed.org 0:5e1631496985 269 #define DEF_ACCEPT_CALLBACK err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err)
root@mbed.org 0:5e1631496985 270 #else /* LWIP_CALLBACK_API */
root@mbed.org 0:5e1631496985 271 #define DEF_ACCEPT_CALLBACK
root@mbed.org 0:5e1631496985 272 #endif /* LWIP_CALLBACK_API */
root@mbed.org 0:5e1631496985 273
root@mbed.org 0:5e1631496985 274 /**
root@mbed.org 0:5e1631496985 275 * members common to struct tcp_pcb and struct tcp_listen_pcb
root@mbed.org 0:5e1631496985 276 */
root@mbed.org 0:5e1631496985 277 #define TCP_PCB_COMMON(type) \
root@mbed.org 0:5e1631496985 278 type *next; /* for the linked list */ \
root@mbed.org 0:5e1631496985 279 enum tcp_state state; /* TCP state */ \
root@mbed.org 0:5e1631496985 280 u8_t prio; \
root@mbed.org 0:5e1631496985 281 void *callback_arg; \
root@mbed.org 0:5e1631496985 282 /* ports are in host byte order */ \
root@mbed.org 0:5e1631496985 283 u16_t local_port; \
root@mbed.org 0:5e1631496985 284 /* the accept callback for listen- and normal pcbs, if LWIP_CALLBACK_API */ \
root@mbed.org 0:5e1631496985 285 DEF_ACCEPT_CALLBACK
root@mbed.org 0:5e1631496985 286
root@mbed.org 0:5e1631496985 287
root@mbed.org 0:5e1631496985 288 /* the TCP protocol control block */
root@mbed.org 0:5e1631496985 289 struct tcp_pcb {
root@mbed.org 0:5e1631496985 290 /** common PCB members */
root@mbed.org 0:5e1631496985 291 IP_PCB;
root@mbed.org 0:5e1631496985 292 /** protocol specific PCB members */
root@mbed.org 0:5e1631496985 293 TCP_PCB_COMMON(struct tcp_pcb);
root@mbed.org 0:5e1631496985 294
root@mbed.org 0:5e1631496985 295 /* ports are in host byte order */
root@mbed.org 0:5e1631496985 296 u16_t remote_port;
root@mbed.org 0:5e1631496985 297
root@mbed.org 0:5e1631496985 298 u8_t flags;
root@mbed.org 0:5e1631496985 299 #define TF_ACK_DELAY ((u8_t)0x01U) /* Delayed ACK. */
root@mbed.org 0:5e1631496985 300 #define TF_ACK_NOW ((u8_t)0x02U) /* Immediate ACK. */
root@mbed.org 0:5e1631496985 301 #define TF_INFR ((u8_t)0x04U) /* In fast recovery. */
root@mbed.org 0:5e1631496985 302 #define TF_TIMESTAMP ((u8_t)0x08U) /* Timestamp option enabled */
root@mbed.org 0:5e1631496985 303 #define TF_FIN ((u8_t)0x20U) /* Connection was closed locally (FIN segment enqueued). */
root@mbed.org 0:5e1631496985 304 #define TF_NODELAY ((u8_t)0x40U) /* Disable Nagle algorithm */
root@mbed.org 0:5e1631496985 305 #define TF_NAGLEMEMERR ((u8_t)0x80U) /* nagle enabled, memerr, try to output to prevent delayed ACK to happen */
root@mbed.org 0:5e1631496985 306
root@mbed.org 0:5e1631496985 307 /* the rest of the fields are in host byte order
root@mbed.org 0:5e1631496985 308 as we have to do some math with them */
root@mbed.org 0:5e1631496985 309 /* receiver variables */
root@mbed.org 0:5e1631496985 310 u32_t rcv_nxt; /* next seqno expected */
root@mbed.org 0:5e1631496985 311 u16_t rcv_wnd; /* receiver window available */
root@mbed.org 0:5e1631496985 312 u16_t rcv_ann_wnd; /* receiver window to announce */
root@mbed.org 0:5e1631496985 313 u32_t rcv_ann_right_edge; /* announced right edge of window */
root@mbed.org 0:5e1631496985 314
root@mbed.org 0:5e1631496985 315 /* Timers */
root@mbed.org 0:5e1631496985 316 u32_t tmr;
root@mbed.org 0:5e1631496985 317 u8_t polltmr, pollinterval;
root@mbed.org 0:5e1631496985 318
root@mbed.org 0:5e1631496985 319 /* Retransmission timer. */
root@mbed.org 0:5e1631496985 320 s16_t rtime;
root@mbed.org 0:5e1631496985 321
root@mbed.org 0:5e1631496985 322 u16_t mss; /* maximum segment size */
root@mbed.org 0:5e1631496985 323
root@mbed.org 0:5e1631496985 324 /* RTT (round trip time) estimation variables */
root@mbed.org 0:5e1631496985 325 u32_t rttest; /* RTT estimate in 500ms ticks */
root@mbed.org 0:5e1631496985 326 u32_t rtseq; /* sequence number being timed */
root@mbed.org 0:5e1631496985 327 s16_t sa, sv; /* @todo document this */
root@mbed.org 0:5e1631496985 328
root@mbed.org 0:5e1631496985 329 s16_t rto; /* retransmission time-out */
root@mbed.org 0:5e1631496985 330 u8_t nrtx; /* number of retransmissions */
root@mbed.org 0:5e1631496985 331
root@mbed.org 0:5e1631496985 332 /* fast retransmit/recovery */
root@mbed.org 0:5e1631496985 333 u32_t lastack; /* Highest acknowledged seqno. */
root@mbed.org 0:5e1631496985 334 u8_t dupacks;
root@mbed.org 0:5e1631496985 335
root@mbed.org 0:5e1631496985 336 /* congestion avoidance/control variables */
root@mbed.org 0:5e1631496985 337 u16_t cwnd;
root@mbed.org 0:5e1631496985 338 u16_t ssthresh;
root@mbed.org 0:5e1631496985 339
root@mbed.org 0:5e1631496985 340 /* sender variables */
root@mbed.org 0:5e1631496985 341 u32_t snd_nxt; /* next new seqno to be sent */
root@mbed.org 0:5e1631496985 342 u16_t snd_wnd; /* sender window */
root@mbed.org 0:5e1631496985 343 u32_t snd_wl1, snd_wl2; /* Sequence and acknowledgement numbers of last
root@mbed.org 0:5e1631496985 344 window update. */
root@mbed.org 0:5e1631496985 345 u32_t snd_lbb; /* Sequence number of next byte to be buffered. */
root@mbed.org 0:5e1631496985 346
root@mbed.org 0:5e1631496985 347 u16_t acked;
root@mbed.org 0:5e1631496985 348
root@mbed.org 0:5e1631496985 349 u16_t snd_buf; /* Available buffer space for sending (in bytes). */
root@mbed.org 0:5e1631496985 350 #define TCP_SNDQUEUELEN_OVERFLOW (0xffff-3)
root@mbed.org 0:5e1631496985 351 u16_t snd_queuelen; /* Available buffer space for sending (in tcp_segs). */
root@mbed.org 0:5e1631496985 352
root@mbed.org 0:5e1631496985 353
root@mbed.org 0:5e1631496985 354 /* These are ordered by sequence number: */
root@mbed.org 0:5e1631496985 355 struct tcp_seg *unsent; /* Unsent (queued) segments. */
root@mbed.org 0:5e1631496985 356 struct tcp_seg *unacked; /* Sent but unacknowledged segments. */
root@mbed.org 0:5e1631496985 357 #if TCP_QUEUE_OOSEQ
root@mbed.org 0:5e1631496985 358 struct tcp_seg *ooseq; /* Received out of sequence segments. */
root@mbed.org 0:5e1631496985 359 #endif /* TCP_QUEUE_OOSEQ */
root@mbed.org 0:5e1631496985 360
root@mbed.org 0:5e1631496985 361 struct pbuf *refused_data; /* Data previously received but not yet taken by upper layer */
root@mbed.org 0:5e1631496985 362
root@mbed.org 0:5e1631496985 363 #if LWIP_CALLBACK_API
root@mbed.org 0:5e1631496985 364 /* Function to be called when more send buffer space is available.
root@mbed.org 0:5e1631496985 365 * @param arg user-supplied argument (tcp_pcb.callback_arg)
root@mbed.org 0:5e1631496985 366 * @param pcb the tcp_pcb which has send buffer space available
root@mbed.org 0:5e1631496985 367 * @param space the amount of bytes available
root@mbed.org 0:5e1631496985 368 * @return ERR_OK: try to send some data by calling tcp_output
root@mbed.org 0:5e1631496985 369 */
root@mbed.org 0:5e1631496985 370 err_t (* sent)(void *arg, struct tcp_pcb *pcb, u16_t space);
root@mbed.org 0:5e1631496985 371
root@mbed.org 0:5e1631496985 372 /* Function to be called when (in-sequence) data has arrived.
root@mbed.org 0:5e1631496985 373 * @param arg user-supplied argument (tcp_pcb.callback_arg)
root@mbed.org 0:5e1631496985 374 * @param pcb the tcp_pcb for which data has arrived
root@mbed.org 0:5e1631496985 375 * @param p the packet buffer which arrived
root@mbed.org 0:5e1631496985 376 * @param err an error argument (TODO: that is current always ERR_OK?)
root@mbed.org 0:5e1631496985 377 * @return ERR_OK: try to send some data by calling tcp_output
root@mbed.org 0:5e1631496985 378 */
root@mbed.org 0:5e1631496985 379 err_t (* recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
root@mbed.org 0:5e1631496985 380
root@mbed.org 0:5e1631496985 381 /* Function to be called when a connection has been set up.
root@mbed.org 0:5e1631496985 382 * @param arg user-supplied argument (tcp_pcb.callback_arg)
root@mbed.org 0:5e1631496985 383 * @param pcb the tcp_pcb that now is connected
root@mbed.org 0:5e1631496985 384 * @param err an error argument (TODO: that is current always ERR_OK?)
root@mbed.org 0:5e1631496985 385 * @return value is currently ignored
root@mbed.org 0:5e1631496985 386 */
root@mbed.org 0:5e1631496985 387 err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err);
root@mbed.org 0:5e1631496985 388
root@mbed.org 0:5e1631496985 389 /* Function which is called periodically.
root@mbed.org 0:5e1631496985 390 * The period can be adjusted in multiples of the TCP slow timer interval
root@mbed.org 0:5e1631496985 391 * by changing tcp_pcb.polltmr.
root@mbed.org 0:5e1631496985 392 * @param arg user-supplied argument (tcp_pcb.callback_arg)
root@mbed.org 0:5e1631496985 393 * @param pcb the tcp_pcb to poll for
root@mbed.org 0:5e1631496985 394 * @return ERR_OK: try to send some data by calling tcp_output
root@mbed.org 0:5e1631496985 395 */
root@mbed.org 0:5e1631496985 396 err_t (* poll)(void *arg, struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 397
root@mbed.org 0:5e1631496985 398 /* Function to be called whenever a fatal error occurs.
root@mbed.org 0:5e1631496985 399 * There is no pcb parameter since most of the times, the pcb is
root@mbed.org 0:5e1631496985 400 * already deallocated (or there is no pcb) when this function is called.
root@mbed.org 0:5e1631496985 401 * @param arg user-supplied argument (tcp_pcb.callback_arg)
root@mbed.org 0:5e1631496985 402 * @param err an indication why the error callback is called:
root@mbed.org 0:5e1631496985 403 * ERR_ABRT: aborted through tcp_abort or by a TCP timer
root@mbed.org 0:5e1631496985 404 * ERR_RST: the connection was reset by the remote host
root@mbed.org 0:5e1631496985 405 */
root@mbed.org 0:5e1631496985 406 void (* errf)(void *arg, err_t err);
root@mbed.org 0:5e1631496985 407 #endif /* LWIP_CALLBACK_API */
root@mbed.org 0:5e1631496985 408
root@mbed.org 0:5e1631496985 409 #if LWIP_TCP_TIMESTAMPS
root@mbed.org 0:5e1631496985 410 u32_t ts_lastacksent;
root@mbed.org 0:5e1631496985 411 u32_t ts_recent;
root@mbed.org 0:5e1631496985 412 #endif /* LWIP_TCP_TIMESTAMPS */
root@mbed.org 0:5e1631496985 413
root@mbed.org 0:5e1631496985 414 /* idle time before KEEPALIVE is sent */
root@mbed.org 0:5e1631496985 415 u32_t keep_idle;
root@mbed.org 0:5e1631496985 416 #if LWIP_TCP_KEEPALIVE
root@mbed.org 0:5e1631496985 417 u32_t keep_intvl;
root@mbed.org 0:5e1631496985 418 u32_t keep_cnt;
root@mbed.org 0:5e1631496985 419 #endif /* LWIP_TCP_KEEPALIVE */
root@mbed.org 0:5e1631496985 420
root@mbed.org 0:5e1631496985 421 /* Persist timer counter */
root@mbed.org 0:5e1631496985 422 u32_t persist_cnt;
root@mbed.org 0:5e1631496985 423 /* Persist timer back-off */
root@mbed.org 0:5e1631496985 424 u8_t persist_backoff;
root@mbed.org 0:5e1631496985 425
root@mbed.org 0:5e1631496985 426 /* KEEPALIVE counter */
root@mbed.org 0:5e1631496985 427 u8_t keep_cnt_sent;
root@mbed.org 0:5e1631496985 428 };
root@mbed.org 0:5e1631496985 429
root@mbed.org 0:5e1631496985 430 struct tcp_pcb_listen {
root@mbed.org 0:5e1631496985 431 /* Common members of all PCB types */
root@mbed.org 0:5e1631496985 432 IP_PCB;
root@mbed.org 0:5e1631496985 433 /* Protocol specific PCB members */
root@mbed.org 0:5e1631496985 434 TCP_PCB_COMMON(struct tcp_pcb_listen);
root@mbed.org 0:5e1631496985 435
root@mbed.org 0:5e1631496985 436 #if TCP_LISTEN_BACKLOG
root@mbed.org 0:5e1631496985 437 u8_t backlog;
root@mbed.org 0:5e1631496985 438 u8_t accepts_pending;
root@mbed.org 0:5e1631496985 439 #endif /* TCP_LISTEN_BACKLOG */
root@mbed.org 0:5e1631496985 440 };
root@mbed.org 0:5e1631496985 441
root@mbed.org 0:5e1631496985 442 #if LWIP_EVENT_API
root@mbed.org 0:5e1631496985 443
root@mbed.org 0:5e1631496985 444 enum lwip_event {
root@mbed.org 0:5e1631496985 445 LWIP_EVENT_ACCEPT,
root@mbed.org 0:5e1631496985 446 LWIP_EVENT_SENT,
root@mbed.org 0:5e1631496985 447 LWIP_EVENT_RECV,
root@mbed.org 0:5e1631496985 448 LWIP_EVENT_CONNECTED,
root@mbed.org 0:5e1631496985 449 LWIP_EVENT_POLL,
root@mbed.org 0:5e1631496985 450 LWIP_EVENT_ERR
root@mbed.org 0:5e1631496985 451 };
root@mbed.org 0:5e1631496985 452
root@mbed.org 0:5e1631496985 453 err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb,
root@mbed.org 0:5e1631496985 454 enum lwip_event,
root@mbed.org 0:5e1631496985 455 struct pbuf *p,
root@mbed.org 0:5e1631496985 456 u16_t size,
root@mbed.org 0:5e1631496985 457 err_t err);
root@mbed.org 0:5e1631496985 458
root@mbed.org 0:5e1631496985 459 #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
root@mbed.org 0:5e1631496985 460 LWIP_EVENT_ACCEPT, NULL, 0, err)
root@mbed.org 0:5e1631496985 461 #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
root@mbed.org 0:5e1631496985 462 LWIP_EVENT_SENT, NULL, space, ERR_OK)
root@mbed.org 0:5e1631496985 463 #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
root@mbed.org 0:5e1631496985 464 LWIP_EVENT_RECV, (p), 0, (err))
root@mbed.org 0:5e1631496985 465 #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
root@mbed.org 0:5e1631496985 466 LWIP_EVENT_CONNECTED, NULL, 0, (err))
root@mbed.org 0:5e1631496985 467 #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
root@mbed.org 0:5e1631496985 468 LWIP_EVENT_POLL, NULL, 0, ERR_OK)
root@mbed.org 0:5e1631496985 469 #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \
root@mbed.org 0:5e1631496985 470 LWIP_EVENT_ERR, NULL, 0, (err))
root@mbed.org 0:5e1631496985 471 #else /* LWIP_EVENT_API */
root@mbed.org 0:5e1631496985 472
root@mbed.org 0:5e1631496985 473 #define TCP_EVENT_ACCEPT(pcb,err,ret) \
root@mbed.org 0:5e1631496985 474 do { \
root@mbed.org 0:5e1631496985 475 if((pcb)->accept != NULL) \
root@mbed.org 0:5e1631496985 476 (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \
root@mbed.org 0:5e1631496985 477 else (ret) = ERR_OK; \
root@mbed.org 0:5e1631496985 478 } while (0)
root@mbed.org 0:5e1631496985 479
root@mbed.org 0:5e1631496985 480 #define TCP_EVENT_SENT(pcb,space,ret) \
root@mbed.org 0:5e1631496985 481 do { \
root@mbed.org 0:5e1631496985 482 if((pcb)->sent != NULL) \
root@mbed.org 0:5e1631496985 483 (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \
root@mbed.org 0:5e1631496985 484 else (ret) = ERR_OK; \
root@mbed.org 0:5e1631496985 485 } while (0)
root@mbed.org 0:5e1631496985 486
root@mbed.org 0:5e1631496985 487 #define TCP_EVENT_RECV(pcb,p,err,ret) \
root@mbed.org 0:5e1631496985 488 do { \
root@mbed.org 0:5e1631496985 489 if((pcb)->recv != NULL) { \
root@mbed.org 0:5e1631496985 490 (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err)); \
root@mbed.org 0:5e1631496985 491 } else { \
root@mbed.org 0:5e1631496985 492 (ret) = ERR_OK; \
root@mbed.org 0:5e1631496985 493 if (p != NULL) { \
root@mbed.org 0:5e1631496985 494 tcp_recved((pcb), ((struct pbuf*)(p))->tot_len); \
root@mbed.org 0:5e1631496985 495 pbuf_free(p); \
root@mbed.org 0:5e1631496985 496 } \
root@mbed.org 0:5e1631496985 497 } \
root@mbed.org 0:5e1631496985 498 } while (0)
root@mbed.org 0:5e1631496985 499
root@mbed.org 0:5e1631496985 500 #define TCP_EVENT_CONNECTED(pcb,err,ret) \
root@mbed.org 0:5e1631496985 501 do { \
root@mbed.org 0:5e1631496985 502 if((pcb)->connected != NULL) \
root@mbed.org 0:5e1631496985 503 (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \
root@mbed.org 0:5e1631496985 504 else (ret) = ERR_OK; \
root@mbed.org 0:5e1631496985 505 } while (0)
root@mbed.org 0:5e1631496985 506
root@mbed.org 0:5e1631496985 507 #define TCP_EVENT_POLL(pcb,ret) \
root@mbed.org 0:5e1631496985 508 do { \
root@mbed.org 0:5e1631496985 509 if((pcb)->poll != NULL) \
root@mbed.org 0:5e1631496985 510 (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \
root@mbed.org 0:5e1631496985 511 else (ret) = ERR_OK; \
root@mbed.org 0:5e1631496985 512 } while (0)
root@mbed.org 0:5e1631496985 513
root@mbed.org 0:5e1631496985 514 #define TCP_EVENT_ERR(errf,arg,err) \
root@mbed.org 0:5e1631496985 515 do { \
root@mbed.org 0:5e1631496985 516 if((errf) != NULL) \
root@mbed.org 0:5e1631496985 517 (errf)((arg),(err)); \
root@mbed.org 0:5e1631496985 518 } while (0)
root@mbed.org 0:5e1631496985 519
root@mbed.org 0:5e1631496985 520 #endif /* LWIP_EVENT_API */
root@mbed.org 0:5e1631496985 521
root@mbed.org 0:5e1631496985 522 /* This structure represents a TCP segment on the unsent and unacked queues */
root@mbed.org 0:5e1631496985 523 struct tcp_seg {
root@mbed.org 0:5e1631496985 524 struct tcp_seg *next; /* used when putting segements on a queue */
root@mbed.org 0:5e1631496985 525 struct pbuf *p; /* buffer containing data + TCP header */
root@mbed.org 0:5e1631496985 526 void *dataptr; /* pointer to the TCP data in the pbuf */
root@mbed.org 0:5e1631496985 527 u16_t len; /* the TCP length of this segment */
root@mbed.org 0:5e1631496985 528 u8_t flags;
root@mbed.org 0:5e1631496985 529 #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */
root@mbed.org 0:5e1631496985 530 #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */
root@mbed.org 0:5e1631496985 531 struct tcp_hdr *tcphdr; /* the TCP header */
root@mbed.org 0:5e1631496985 532 };
root@mbed.org 0:5e1631496985 533
root@mbed.org 0:5e1631496985 534 #define LWIP_TCP_OPT_LENGTH(flags) \
root@mbed.org 0:5e1631496985 535 (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \
root@mbed.org 0:5e1631496985 536 (flags & TF_SEG_OPTS_TS ? 12 : 0)
root@mbed.org 0:5e1631496985 537
root@mbed.org 0:5e1631496985 538 /** This returns a TCP header option for MSS in an u32_t */
root@mbed.org 0:5e1631496985 539 #define TCP_BUILD_MSS_OPTION(x) (x) = htonl(((u32_t)2 << 24) | \
root@mbed.org 0:5e1631496985 540 ((u32_t)4 << 16) | \
root@mbed.org 0:5e1631496985 541 (((u32_t)TCP_MSS / 256) << 8) | \
root@mbed.org 0:5e1631496985 542 (TCP_MSS & 255))
root@mbed.org 0:5e1631496985 543
root@mbed.org 0:5e1631496985 544 /* Internal functions and global variables: */
root@mbed.org 0:5e1631496985 545 struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 546 void tcp_pcb_purge(struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 547 void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 548
root@mbed.org 0:5e1631496985 549 u8_t tcp_segs_free(struct tcp_seg *seg);
root@mbed.org 0:5e1631496985 550 u8_t tcp_seg_free(struct tcp_seg *seg);
root@mbed.org 0:5e1631496985 551 struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);
root@mbed.org 0:5e1631496985 552
root@mbed.org 0:5e1631496985 553 #define tcp_ack(pcb) \
root@mbed.org 0:5e1631496985 554 do { \
root@mbed.org 0:5e1631496985 555 if((pcb)->flags & TF_ACK_DELAY) { \
root@mbed.org 0:5e1631496985 556 (pcb)->flags &= ~TF_ACK_DELAY; \
root@mbed.org 0:5e1631496985 557 (pcb)->flags |= TF_ACK_NOW; \
root@mbed.org 0:5e1631496985 558 tcp_output(pcb); \
root@mbed.org 0:5e1631496985 559 } \
root@mbed.org 0:5e1631496985 560 else { \
root@mbed.org 0:5e1631496985 561 (pcb)->flags |= TF_ACK_DELAY; \
root@mbed.org 0:5e1631496985 562 } \
root@mbed.org 0:5e1631496985 563 } while (0)
root@mbed.org 0:5e1631496985 564
root@mbed.org 0:5e1631496985 565 #define tcp_ack_now(pcb) \
root@mbed.org 0:5e1631496985 566 do { \
root@mbed.org 0:5e1631496985 567 (pcb)->flags |= TF_ACK_NOW; \
root@mbed.org 0:5e1631496985 568 tcp_output(pcb); \
root@mbed.org 0:5e1631496985 569 } while (0)
root@mbed.org 0:5e1631496985 570
root@mbed.org 0:5e1631496985 571 err_t tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags);
root@mbed.org 0:5e1631496985 572 err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, u16_t len,
root@mbed.org 0:5e1631496985 573 u8_t flags, u8_t apiflags, u8_t optflags);
root@mbed.org 0:5e1631496985 574
root@mbed.org 0:5e1631496985 575 void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
root@mbed.org 0:5e1631496985 576
root@mbed.org 0:5e1631496985 577 void tcp_rst(u32_t seqno, u32_t ackno,
root@mbed.org 0:5e1631496985 578 struct ip_addr *local_ip, struct ip_addr *remote_ip,
root@mbed.org 0:5e1631496985 579 u16_t local_port, u16_t remote_port);
root@mbed.org 0:5e1631496985 580
root@mbed.org 0:5e1631496985 581 u32_t tcp_next_iss(void);
root@mbed.org 0:5e1631496985 582
root@mbed.org 0:5e1631496985 583 void tcp_keepalive(struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 584 void tcp_zero_window_probe(struct tcp_pcb *pcb);
root@mbed.org 0:5e1631496985 585
root@mbed.org 0:5e1631496985 586 #if TCP_CALCULATE_EFF_SEND_MSS
root@mbed.org 0:5e1631496985 587 u16_t tcp_eff_send_mss(u16_t sendmss, struct ip_addr *addr);
root@mbed.org 0:5e1631496985 588 #endif /* TCP_CALCULATE_EFF_SEND_MSS */
root@mbed.org 0:5e1631496985 589
root@mbed.org 0:5e1631496985 590 extern struct tcp_pcb *tcp_input_pcb;
root@mbed.org 0:5e1631496985 591 extern u32_t tcp_ticks;
root@mbed.org 0:5e1631496985 592
root@mbed.org 0:5e1631496985 593 const char* tcp_debug_state_str(enum tcp_state s);
root@mbed.org 0:5e1631496985 594 #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
root@mbed.org 0:5e1631496985 595 void tcp_debug_print(struct tcp_hdr *tcphdr);
root@mbed.org 0:5e1631496985 596 void tcp_debug_print_flags(u8_t flags);
root@mbed.org 0:5e1631496985 597 void tcp_debug_print_state(enum tcp_state s);
root@mbed.org 0:5e1631496985 598 void tcp_debug_print_pcbs(void);
root@mbed.org 0:5e1631496985 599 s16_t tcp_pcbs_sane(void);
root@mbed.org 0:5e1631496985 600 #else
root@mbed.org 0:5e1631496985 601 # define tcp_debug_print(tcphdr)
root@mbed.org 0:5e1631496985 602 # define tcp_debug_print_flags(flags)
root@mbed.org 0:5e1631496985 603 # define tcp_debug_print_state(s)
root@mbed.org 0:5e1631496985 604 # define tcp_debug_print_pcbs()
root@mbed.org 0:5e1631496985 605 # define tcp_pcbs_sane() 1
root@mbed.org 0:5e1631496985 606 #endif /* TCP_DEBUG */
root@mbed.org 0:5e1631496985 607
root@mbed.org 0:5e1631496985 608 #if NO_SYS
root@mbed.org 0:5e1631496985 609 #define tcp_timer_needed()
root@mbed.org 0:5e1631496985 610 #else
root@mbed.org 0:5e1631496985 611 void tcp_timer_needed(void);
root@mbed.org 0:5e1631496985 612 #endif
root@mbed.org 0:5e1631496985 613
root@mbed.org 0:5e1631496985 614 /* The TCP PCB lists. */
root@mbed.org 0:5e1631496985 615 union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
root@mbed.org 0:5e1631496985 616 struct tcp_pcb_listen *listen_pcbs;
root@mbed.org 0:5e1631496985 617 struct tcp_pcb *pcbs;
root@mbed.org 0:5e1631496985 618 };
root@mbed.org 0:5e1631496985 619 extern union tcp_listen_pcbs_t tcp_listen_pcbs;
root@mbed.org 0:5e1631496985 620 extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a
root@mbed.org 0:5e1631496985 621 state in which they accept or send
root@mbed.org 0:5e1631496985 622 data. */
root@mbed.org 0:5e1631496985 623 extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */
root@mbed.org 0:5e1631496985 624
root@mbed.org 0:5e1631496985 625 extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
root@mbed.org 0:5e1631496985 626
root@mbed.org 0:5e1631496985 627 /* Axioms about the above lists:
root@mbed.org 0:5e1631496985 628 1) Every TCP PCB that is not CLOSED is in one of the lists.
root@mbed.org 0:5e1631496985 629 2) A PCB is only in one of the lists.
root@mbed.org 0:5e1631496985 630 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
root@mbed.org 0:5e1631496985 631 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.
root@mbed.org 0:5e1631496985 632 */
root@mbed.org 0:5e1631496985 633
root@mbed.org 0:5e1631496985 634 /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB
root@mbed.org 0:5e1631496985 635 with a PCB list or removes a PCB from a list, respectively. */
root@mbed.org 0:5e1631496985 636 #if 0
root@mbed.org 0:5e1631496985 637 #define TCP_REG(pcbs, npcb) do {\
root@mbed.org 0:5e1631496985 638 LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", npcb, npcb->local_port)); \
root@mbed.org 0:5e1631496985 639 for(tcp_tmp_pcb = *pcbs; \
root@mbed.org 0:5e1631496985 640 tcp_tmp_pcb != NULL; \
root@mbed.org 0:5e1631496985 641 tcp_tmp_pcb = tcp_tmp_pcb->next) { \
root@mbed.org 0:5e1631496985 642 LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != npcb); \
root@mbed.org 0:5e1631496985 643 } \
root@mbed.org 0:5e1631496985 644 LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", npcb->state != CLOSED); \
root@mbed.org 0:5e1631496985 645 npcb->next = *pcbs; \
root@mbed.org 0:5e1631496985 646 LWIP_ASSERT("TCP_REG: npcb->next != npcb", npcb->next != npcb); \
root@mbed.org 0:5e1631496985 647 *(pcbs) = npcb; \
root@mbed.org 0:5e1631496985 648 LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
root@mbed.org 0:5e1631496985 649 tcp_timer_needed(); \
root@mbed.org 0:5e1631496985 650 } while(0)
root@mbed.org 0:5e1631496985 651 #define TCP_RMV(pcbs, npcb) do { \
root@mbed.org 0:5e1631496985 652 LWIP_ASSERT("TCP_RMV: pcbs != NULL", *pcbs != NULL); \
root@mbed.org 0:5e1631496985 653 LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", npcb, *pcbs)); \
root@mbed.org 0:5e1631496985 654 if(*pcbs == npcb) { \
root@mbed.org 0:5e1631496985 655 *pcbs = (*pcbs)->next; \
root@mbed.org 0:5e1631496985 656 } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
root@mbed.org 0:5e1631496985 657 if(tcp_tmp_pcb->next == npcb) { \
root@mbed.org 0:5e1631496985 658 tcp_tmp_pcb->next = npcb->next; \
root@mbed.org 0:5e1631496985 659 break; \
root@mbed.org 0:5e1631496985 660 } \
root@mbed.org 0:5e1631496985 661 } \
root@mbed.org 0:5e1631496985 662 npcb->next = NULL; \
root@mbed.org 0:5e1631496985 663 LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
root@mbed.org 0:5e1631496985 664 LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", npcb, *pcbs)); \
root@mbed.org 0:5e1631496985 665 } while(0)
root@mbed.org 0:5e1631496985 666
root@mbed.org 0:5e1631496985 667 #else /* LWIP_DEBUG */
root@mbed.org 0:5e1631496985 668
root@mbed.org 0:5e1631496985 669 #define TCP_REG(pcbs, npcb) \
root@mbed.org 0:5e1631496985 670 do { \
root@mbed.org 0:5e1631496985 671 npcb->next = *pcbs; \
root@mbed.org 0:5e1631496985 672 *(pcbs) = npcb; \
root@mbed.org 0:5e1631496985 673 tcp_timer_needed(); \
root@mbed.org 0:5e1631496985 674 } while (0)
root@mbed.org 0:5e1631496985 675
root@mbed.org 0:5e1631496985 676 #define TCP_RMV(pcbs, npcb) \
root@mbed.org 0:5e1631496985 677 do { \
root@mbed.org 0:5e1631496985 678 if(*(pcbs) == npcb) { \
root@mbed.org 0:5e1631496985 679 (*(pcbs)) = (*pcbs)->next; \
root@mbed.org 0:5e1631496985 680 } \
root@mbed.org 0:5e1631496985 681 else { \
root@mbed.org 0:5e1631496985 682 for(tcp_tmp_pcb = *pcbs; \
root@mbed.org 0:5e1631496985 683 tcp_tmp_pcb != NULL; \
root@mbed.org 0:5e1631496985 684 tcp_tmp_pcb = tcp_tmp_pcb->next) { \
root@mbed.org 0:5e1631496985 685 if(tcp_tmp_pcb->next == npcb) { \
root@mbed.org 0:5e1631496985 686 tcp_tmp_pcb->next = npcb->next; \
root@mbed.org 0:5e1631496985 687 break; \
root@mbed.org 0:5e1631496985 688 } \
root@mbed.org 0:5e1631496985 689 } \
root@mbed.org 0:5e1631496985 690 } \
root@mbed.org 0:5e1631496985 691 npcb->next = NULL; \
root@mbed.org 0:5e1631496985 692 } while(0)
root@mbed.org 0:5e1631496985 693
root@mbed.org 0:5e1631496985 694 #endif /* LWIP_DEBUG */
root@mbed.org 0:5e1631496985 695
root@mbed.org 0:5e1631496985 696 #ifdef __cplusplus
root@mbed.org 0:5e1631496985 697 }
root@mbed.org 0:5e1631496985 698 #endif
root@mbed.org 0:5e1631496985 699
root@mbed.org 0:5e1631496985 700 #endif /* LWIP_TCP */
root@mbed.org 0:5e1631496985 701
root@mbed.org 0:5e1631496985 702 #endif /* __LWIP_TCP_H__ */