Committer:
mbed714
Date:
Sat Sep 18 23:05:49 2010 +0000
Revision:
0:d616ece2d859

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed714 0:d616ece2d859 1 /*
mbed714 0:d616ece2d859 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
mbed714 0:d616ece2d859 3 * All rights reserved.
mbed714 0:d616ece2d859 4 *
mbed714 0:d616ece2d859 5 * Redistribution and use in source and binary forms, with or without modification,
mbed714 0:d616ece2d859 6 * are permitted provided that the following conditions are met:
mbed714 0:d616ece2d859 7 *
mbed714 0:d616ece2d859 8 * 1. Redistributions of source code must retain the above copyright notice,
mbed714 0:d616ece2d859 9 * this list of conditions and the following disclaimer.
mbed714 0:d616ece2d859 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed714 0:d616ece2d859 11 * this list of conditions and the following disclaimer in the documentation
mbed714 0:d616ece2d859 12 * and/or other materials provided with the distribution.
mbed714 0:d616ece2d859 13 * 3. The name of the author may not be used to endorse or promote products
mbed714 0:d616ece2d859 14 * derived from this software without specific prior written permission.
mbed714 0:d616ece2d859 15 *
mbed714 0:d616ece2d859 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
mbed714 0:d616ece2d859 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed714 0:d616ece2d859 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
mbed714 0:d616ece2d859 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mbed714 0:d616ece2d859 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
mbed714 0:d616ece2d859 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbed714 0:d616ece2d859 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbed714 0:d616ece2d859 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
mbed714 0:d616ece2d859 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
mbed714 0:d616ece2d859 25 * OF SUCH DAMAGE.
mbed714 0:d616ece2d859 26 *
mbed714 0:d616ece2d859 27 * This file is part of the lwIP TCP/IP stack.
mbed714 0:d616ece2d859 28 *
mbed714 0:d616ece2d859 29 * Author: Adam Dunkels <adam@sics.se>
mbed714 0:d616ece2d859 30 *
mbed714 0:d616ece2d859 31 */
mbed714 0:d616ece2d859 32 #ifndef __LWIP_TCP_H__
mbed714 0:d616ece2d859 33 #define __LWIP_TCP_H__
mbed714 0:d616ece2d859 34
mbed714 0:d616ece2d859 35 #include "lwip/opt.h"
mbed714 0:d616ece2d859 36
mbed714 0:d616ece2d859 37 #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
mbed714 0:d616ece2d859 38
mbed714 0:d616ece2d859 39 #include "lwip/sys.h"
mbed714 0:d616ece2d859 40 #include "lwip/mem.h"
mbed714 0:d616ece2d859 41 #include "lwip/pbuf.h"
mbed714 0:d616ece2d859 42 #include "lwip/ip.h"
mbed714 0:d616ece2d859 43 #include "lwip/icmp.h"
mbed714 0:d616ece2d859 44 #include "lwip/err.h"
mbed714 0:d616ece2d859 45
mbed714 0:d616ece2d859 46 #ifdef __cplusplus
mbed714 0:d616ece2d859 47 extern "C" {
mbed714 0:d616ece2d859 48 #endif
mbed714 0:d616ece2d859 49
mbed714 0:d616ece2d859 50 struct tcp_pcb;
mbed714 0:d616ece2d859 51
mbed714 0:d616ece2d859 52 /** Function prototype for tcp accept callback functions. Called when a new
mbed714 0:d616ece2d859 53 * connection can be accepted on a listening pcb.
mbed714 0:d616ece2d859 54 *
mbed714 0:d616ece2d859 55 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
mbed714 0:d616ece2d859 56 * @param newpcb The new connection pcb
mbed714 0:d616ece2d859 57 * @param err An error code if there has been an error accepting.
mbed714 0:d616ece2d859 58 * Only return ERR_ABRT if you have called tcp_abort from within the
mbed714 0:d616ece2d859 59 * callback function!
mbed714 0:d616ece2d859 60 */
mbed714 0:d616ece2d859 61 typedef err_t (*tcp_accept_fn)(void *arg, struct tcp_pcb *newpcb, err_t err);
mbed714 0:d616ece2d859 62
mbed714 0:d616ece2d859 63 /** Function prototype for tcp receive callback functions. Called when data has
mbed714 0:d616ece2d859 64 * been received.
mbed714 0:d616ece2d859 65 *
mbed714 0:d616ece2d859 66 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
mbed714 0:d616ece2d859 67 * @param tpcb The connection pcb which received data
mbed714 0:d616ece2d859 68 * @param p The received data (or NULL when the connection has been closed!)
mbed714 0:d616ece2d859 69 * @param err An error code if there has been an error receiving
mbed714 0:d616ece2d859 70 * Only return ERR_ABRT if you have called tcp_abort from within the
mbed714 0:d616ece2d859 71 * callback function!
mbed714 0:d616ece2d859 72 */
mbed714 0:d616ece2d859 73 typedef err_t (*tcp_recv_fn)(void *arg, struct tcp_pcb *tpcb,
mbed714 0:d616ece2d859 74 struct pbuf *p, err_t err);
mbed714 0:d616ece2d859 75
mbed714 0:d616ece2d859 76 /** Function prototype for tcp sent callback functions. Called when sent data has
mbed714 0:d616ece2d859 77 * been acknowledged by the remote side. Use it to free corresponding resources.
mbed714 0:d616ece2d859 78 * This also means that the pcb has now space available to send new data.
mbed714 0:d616ece2d859 79 *
mbed714 0:d616ece2d859 80 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
mbed714 0:d616ece2d859 81 * @param tpcb The connection pcb for which data has been acknowledged
mbed714 0:d616ece2d859 82 * @param len The amount of bytes acknowledged
mbed714 0:d616ece2d859 83 * @return ERR_OK: try to send some data by calling tcp_output
mbed714 0:d616ece2d859 84 * Only return ERR_ABRT if you have called tcp_abort from within the
mbed714 0:d616ece2d859 85 * callback function!
mbed714 0:d616ece2d859 86 */
mbed714 0:d616ece2d859 87 typedef err_t (*tcp_sent_fn)(void *arg, struct tcp_pcb *tpcb,
mbed714 0:d616ece2d859 88 u16_t len);
mbed714 0:d616ece2d859 89
mbed714 0:d616ece2d859 90 /** Function prototype for tcp poll callback functions. Called periodically as
mbed714 0:d616ece2d859 91 * specified by @see tcp_poll.
mbed714 0:d616ece2d859 92 *
mbed714 0:d616ece2d859 93 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
mbed714 0:d616ece2d859 94 * @param tpcb tcp pcb
mbed714 0:d616ece2d859 95 * @return ERR_OK: try to send some data by calling tcp_output
mbed714 0:d616ece2d859 96 * Only return ERR_ABRT if you have called tcp_abort from within the
mbed714 0:d616ece2d859 97 * callback function!
mbed714 0:d616ece2d859 98 */
mbed714 0:d616ece2d859 99 typedef err_t (*tcp_poll_fn)(void *arg, struct tcp_pcb *tpcb);
mbed714 0:d616ece2d859 100
mbed714 0:d616ece2d859 101 /** Function prototype for tcp error callback functions. Called when the pcb
mbed714 0:d616ece2d859 102 * receives a RST or is unexpectedly closed for any other reason.
mbed714 0:d616ece2d859 103 *
mbed714 0:d616ece2d859 104 * @note The corresponding pcb is already freed when this callback is called!
mbed714 0:d616ece2d859 105 *
mbed714 0:d616ece2d859 106 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
mbed714 0:d616ece2d859 107 * @param err Error code to indicate why the pcb has been closed
mbed714 0:d616ece2d859 108 * ERR_ABRT: aborted through tcp_abort or by a TCP timer
mbed714 0:d616ece2d859 109 * ERR_RST: the connection was reset by the remote host
mbed714 0:d616ece2d859 110 */
mbed714 0:d616ece2d859 111 typedef void (*tcp_err_fn)(void *arg, err_t err);
mbed714 0:d616ece2d859 112
mbed714 0:d616ece2d859 113 /** Function prototype for tcp connected callback functions. Called when a pcb
mbed714 0:d616ece2d859 114 * is connected to the remote side after initiating a connection attempt by
mbed714 0:d616ece2d859 115 * calling tcp_connect().
mbed714 0:d616ece2d859 116 *
mbed714 0:d616ece2d859 117 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
mbed714 0:d616ece2d859 118 * @param tpcb The connection pcb which is connected
mbed714 0:d616ece2d859 119 * @param err An unused error code, always ERR_OK currently ;-) TODO!
mbed714 0:d616ece2d859 120 * Only return ERR_ABRT if you have called tcp_abort from within the
mbed714 0:d616ece2d859 121 * callback function!
mbed714 0:d616ece2d859 122 *
mbed714 0:d616ece2d859 123 * @note When a connection attempt fails, the error callback is currently called!
mbed714 0:d616ece2d859 124 */
mbed714 0:d616ece2d859 125 typedef err_t (*tcp_connected_fn)(void *arg, struct tcp_pcb *tpcb, err_t err);
mbed714 0:d616ece2d859 126
mbed714 0:d616ece2d859 127 enum tcp_state {
mbed714 0:d616ece2d859 128 CLOSED = 0,
mbed714 0:d616ece2d859 129 LISTEN = 1,
mbed714 0:d616ece2d859 130 SYN_SENT = 2,
mbed714 0:d616ece2d859 131 SYN_RCVD = 3,
mbed714 0:d616ece2d859 132 ESTABLISHED = 4,
mbed714 0:d616ece2d859 133 FIN_WAIT_1 = 5,
mbed714 0:d616ece2d859 134 FIN_WAIT_2 = 6,
mbed714 0:d616ece2d859 135 CLOSE_WAIT = 7,
mbed714 0:d616ece2d859 136 CLOSING = 8,
mbed714 0:d616ece2d859 137 LAST_ACK = 9,
mbed714 0:d616ece2d859 138 TIME_WAIT = 10
mbed714 0:d616ece2d859 139 };
mbed714 0:d616ece2d859 140
mbed714 0:d616ece2d859 141 #if LWIP_CALLBACK_API
mbed714 0:d616ece2d859 142 /* Function to call when a listener has been connected.
mbed714 0:d616ece2d859 143 * @param arg user-supplied argument (tcp_pcb.callback_arg)
mbed714 0:d616ece2d859 144 * @param pcb a new tcp_pcb that now is connected
mbed714 0:d616ece2d859 145 * @param err an error argument (TODO: that is current always ERR_OK?)
mbed714 0:d616ece2d859 146 * @return ERR_OK: accept the new connection,
mbed714 0:d616ece2d859 147 * any other err_t abortsthe new connection
mbed714 0:d616ece2d859 148 */
mbed714 0:d616ece2d859 149 #define DEF_ACCEPT_CALLBACK tcp_accept_fn accept;
mbed714 0:d616ece2d859 150 #else /* LWIP_CALLBACK_API */
mbed714 0:d616ece2d859 151 #define DEF_ACCEPT_CALLBACK
mbed714 0:d616ece2d859 152 #endif /* LWIP_CALLBACK_API */
mbed714 0:d616ece2d859 153
mbed714 0:d616ece2d859 154 /**
mbed714 0:d616ece2d859 155 * members common to struct tcp_pcb and struct tcp_listen_pcb
mbed714 0:d616ece2d859 156 */
mbed714 0:d616ece2d859 157 #define TCP_PCB_COMMON(type) \
mbed714 0:d616ece2d859 158 type *next; /* for the linked list */ \
mbed714 0:d616ece2d859 159 enum tcp_state state; /* TCP state */ \
mbed714 0:d616ece2d859 160 u8_t prio; \
mbed714 0:d616ece2d859 161 void *callback_arg; \
mbed714 0:d616ece2d859 162 /* the accept callback for listen- and normal pcbs, if LWIP_CALLBACK_API */ \
mbed714 0:d616ece2d859 163 DEF_ACCEPT_CALLBACK \
mbed714 0:d616ece2d859 164 /* ports are in host byte order */ \
mbed714 0:d616ece2d859 165 u16_t local_port
mbed714 0:d616ece2d859 166
mbed714 0:d616ece2d859 167
mbed714 0:d616ece2d859 168 /* the TCP protocol control block */
mbed714 0:d616ece2d859 169 struct tcp_pcb {
mbed714 0:d616ece2d859 170 /** common PCB members */
mbed714 0:d616ece2d859 171 IP_PCB;
mbed714 0:d616ece2d859 172 /** protocol specific PCB members */
mbed714 0:d616ece2d859 173 TCP_PCB_COMMON(struct tcp_pcb);
mbed714 0:d616ece2d859 174
mbed714 0:d616ece2d859 175 /* ports are in host byte order */
mbed714 0:d616ece2d859 176 u16_t remote_port;
mbed714 0:d616ece2d859 177
mbed714 0:d616ece2d859 178 u8_t flags;
mbed714 0:d616ece2d859 179 #define TF_ACK_DELAY ((u8_t)0x01U) /* Delayed ACK. */
mbed714 0:d616ece2d859 180 #define TF_ACK_NOW ((u8_t)0x02U) /* Immediate ACK. */
mbed714 0:d616ece2d859 181 #define TF_INFR ((u8_t)0x04U) /* In fast recovery. */
mbed714 0:d616ece2d859 182 #define TF_TIMESTAMP ((u8_t)0x08U) /* Timestamp option enabled */
mbed714 0:d616ece2d859 183 #define TF_RXCLOSED ((u8_t)0x10U) /* rx closed by tcp_shutdown */
mbed714 0:d616ece2d859 184 #define TF_FIN ((u8_t)0x20U) /* Connection was closed locally (FIN segment enqueued). */
mbed714 0:d616ece2d859 185 #define TF_NODELAY ((u8_t)0x40U) /* Disable Nagle algorithm */
mbed714 0:d616ece2d859 186 #define TF_NAGLEMEMERR ((u8_t)0x80U) /* nagle enabled, memerr, try to output to prevent delayed ACK to happen */
mbed714 0:d616ece2d859 187
mbed714 0:d616ece2d859 188 /* the rest of the fields are in host byte order
mbed714 0:d616ece2d859 189 as we have to do some math with them */
mbed714 0:d616ece2d859 190 /* receiver variables */
mbed714 0:d616ece2d859 191 u32_t rcv_nxt; /* next seqno expected */
mbed714 0:d616ece2d859 192 u16_t rcv_wnd; /* receiver window available */
mbed714 0:d616ece2d859 193 u16_t rcv_ann_wnd; /* receiver window to announce */
mbed714 0:d616ece2d859 194 u32_t rcv_ann_right_edge; /* announced right edge of window */
mbed714 0:d616ece2d859 195
mbed714 0:d616ece2d859 196 /* Timers */
mbed714 0:d616ece2d859 197 u32_t tmr;
mbed714 0:d616ece2d859 198 u8_t polltmr, pollinterval;
mbed714 0:d616ece2d859 199
mbed714 0:d616ece2d859 200 /* Retransmission timer. */
mbed714 0:d616ece2d859 201 s16_t rtime;
mbed714 0:d616ece2d859 202
mbed714 0:d616ece2d859 203 u16_t mss; /* maximum segment size */
mbed714 0:d616ece2d859 204
mbed714 0:d616ece2d859 205 /* RTT (round trip time) estimation variables */
mbed714 0:d616ece2d859 206 u32_t rttest; /* RTT estimate in 500ms ticks */
mbed714 0:d616ece2d859 207 u32_t rtseq; /* sequence number being timed */
mbed714 0:d616ece2d859 208 s16_t sa, sv; /* @todo document this */
mbed714 0:d616ece2d859 209
mbed714 0:d616ece2d859 210 s16_t rto; /* retransmission time-out */
mbed714 0:d616ece2d859 211 u8_t nrtx; /* number of retransmissions */
mbed714 0:d616ece2d859 212
mbed714 0:d616ece2d859 213 /* fast retransmit/recovery */
mbed714 0:d616ece2d859 214 u32_t lastack; /* Highest acknowledged seqno. */
mbed714 0:d616ece2d859 215 u8_t dupacks;
mbed714 0:d616ece2d859 216
mbed714 0:d616ece2d859 217 /* congestion avoidance/control variables */
mbed714 0:d616ece2d859 218 u16_t cwnd;
mbed714 0:d616ece2d859 219 u16_t ssthresh;
mbed714 0:d616ece2d859 220
mbed714 0:d616ece2d859 221 /* sender variables */
mbed714 0:d616ece2d859 222 u32_t snd_nxt; /* next new seqno to be sent */
mbed714 0:d616ece2d859 223 u16_t snd_wnd; /* sender window */
mbed714 0:d616ece2d859 224 u32_t snd_wl1, snd_wl2; /* Sequence and acknowledgement numbers of last
mbed714 0:d616ece2d859 225 window update. */
mbed714 0:d616ece2d859 226 u32_t snd_lbb; /* Sequence number of next byte to be buffered. */
mbed714 0:d616ece2d859 227
mbed714 0:d616ece2d859 228 u16_t acked;
mbed714 0:d616ece2d859 229
mbed714 0:d616ece2d859 230 u16_t snd_buf; /* Available buffer space for sending (in bytes). */
mbed714 0:d616ece2d859 231 #define TCP_SNDQUEUELEN_OVERFLOW (0xffff-3)
mbed714 0:d616ece2d859 232 u16_t snd_queuelen; /* Available buffer space for sending (in tcp_segs). */
mbed714 0:d616ece2d859 233
mbed714 0:d616ece2d859 234 #if TCP_OVERSIZE
mbed714 0:d616ece2d859 235 /* Extra bytes available at the end of the last pbuf in unsent. */
mbed714 0:d616ece2d859 236 u16_t unsent_oversize;
mbed714 0:d616ece2d859 237 #endif /* TCP_OVERSIZE */
mbed714 0:d616ece2d859 238
mbed714 0:d616ece2d859 239 /* These are ordered by sequence number: */
mbed714 0:d616ece2d859 240 struct tcp_seg *unsent; /* Unsent (queued) segments. */
mbed714 0:d616ece2d859 241 struct tcp_seg *unacked; /* Sent but unacknowledged segments. */
mbed714 0:d616ece2d859 242 #if TCP_QUEUE_OOSEQ
mbed714 0:d616ece2d859 243 struct tcp_seg *ooseq; /* Received out of sequence segments. */
mbed714 0:d616ece2d859 244 #endif /* TCP_QUEUE_OOSEQ */
mbed714 0:d616ece2d859 245
mbed714 0:d616ece2d859 246 struct pbuf *refused_data; /* Data previously received but not yet taken by upper layer */
mbed714 0:d616ece2d859 247
mbed714 0:d616ece2d859 248 #if LWIP_CALLBACK_API
mbed714 0:d616ece2d859 249 /* Function to be called when more send buffer space is available. */
mbed714 0:d616ece2d859 250 tcp_sent_fn sent;
mbed714 0:d616ece2d859 251 /* Function to be called when (in-sequence) data has arrived. */
mbed714 0:d616ece2d859 252 tcp_recv_fn recv;
mbed714 0:d616ece2d859 253 /* Function to be called when a connection has been set up. */
mbed714 0:d616ece2d859 254 tcp_connected_fn connected;
mbed714 0:d616ece2d859 255 /* Function which is called periodically. */
mbed714 0:d616ece2d859 256 tcp_poll_fn poll;
mbed714 0:d616ece2d859 257 /* Function to be called whenever a fatal error occurs. */
mbed714 0:d616ece2d859 258 tcp_err_fn errf;
mbed714 0:d616ece2d859 259 #endif /* LWIP_CALLBACK_API */
mbed714 0:d616ece2d859 260
mbed714 0:d616ece2d859 261 #if LWIP_TCP_TIMESTAMPS
mbed714 0:d616ece2d859 262 u32_t ts_lastacksent;
mbed714 0:d616ece2d859 263 u32_t ts_recent;
mbed714 0:d616ece2d859 264 #endif /* LWIP_TCP_TIMESTAMPS */
mbed714 0:d616ece2d859 265
mbed714 0:d616ece2d859 266 /* idle time before KEEPALIVE is sent */
mbed714 0:d616ece2d859 267 u32_t keep_idle;
mbed714 0:d616ece2d859 268 #if LWIP_TCP_KEEPALIVE
mbed714 0:d616ece2d859 269 u32_t keep_intvl;
mbed714 0:d616ece2d859 270 u32_t keep_cnt;
mbed714 0:d616ece2d859 271 #endif /* LWIP_TCP_KEEPALIVE */
mbed714 0:d616ece2d859 272
mbed714 0:d616ece2d859 273 /* Persist timer counter */
mbed714 0:d616ece2d859 274 u32_t persist_cnt;
mbed714 0:d616ece2d859 275 /* Persist timer back-off */
mbed714 0:d616ece2d859 276 u8_t persist_backoff;
mbed714 0:d616ece2d859 277
mbed714 0:d616ece2d859 278 /* KEEPALIVE counter */
mbed714 0:d616ece2d859 279 u8_t keep_cnt_sent;
mbed714 0:d616ece2d859 280 };
mbed714 0:d616ece2d859 281
mbed714 0:d616ece2d859 282 struct tcp_pcb_listen {
mbed714 0:d616ece2d859 283 /* Common members of all PCB types */
mbed714 0:d616ece2d859 284 IP_PCB;
mbed714 0:d616ece2d859 285 /* Protocol specific PCB members */
mbed714 0:d616ece2d859 286 TCP_PCB_COMMON(struct tcp_pcb_listen);
mbed714 0:d616ece2d859 287
mbed714 0:d616ece2d859 288 #if TCP_LISTEN_BACKLOG
mbed714 0:d616ece2d859 289 u8_t backlog;
mbed714 0:d616ece2d859 290 u8_t accepts_pending;
mbed714 0:d616ece2d859 291 #endif /* TCP_LISTEN_BACKLOG */
mbed714 0:d616ece2d859 292 };
mbed714 0:d616ece2d859 293
mbed714 0:d616ece2d859 294 #if LWIP_EVENT_API
mbed714 0:d616ece2d859 295
mbed714 0:d616ece2d859 296 enum lwip_event {
mbed714 0:d616ece2d859 297 LWIP_EVENT_ACCEPT,
mbed714 0:d616ece2d859 298 LWIP_EVENT_SENT,
mbed714 0:d616ece2d859 299 LWIP_EVENT_RECV,
mbed714 0:d616ece2d859 300 LWIP_EVENT_CONNECTED,
mbed714 0:d616ece2d859 301 LWIP_EVENT_POLL,
mbed714 0:d616ece2d859 302 LWIP_EVENT_ERR
mbed714 0:d616ece2d859 303 };
mbed714 0:d616ece2d859 304
mbed714 0:d616ece2d859 305 err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb,
mbed714 0:d616ece2d859 306 enum lwip_event,
mbed714 0:d616ece2d859 307 struct pbuf *p,
mbed714 0:d616ece2d859 308 u16_t size,
mbed714 0:d616ece2d859 309 err_t err);
mbed714 0:d616ece2d859 310
mbed714 0:d616ece2d859 311 #endif /* LWIP_EVENT_API */
mbed714 0:d616ece2d859 312
mbed714 0:d616ece2d859 313 /* Application program's interface: */
mbed714 0:d616ece2d859 314 struct tcp_pcb * tcp_new (void);
mbed714 0:d616ece2d859 315
mbed714 0:d616ece2d859 316 void tcp_arg (struct tcp_pcb *pcb, void *arg);
mbed714 0:d616ece2d859 317 void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept);
mbed714 0:d616ece2d859 318 void tcp_recv (struct tcp_pcb *pcb, tcp_recv_fn recv);
mbed714 0:d616ece2d859 319 void tcp_sent (struct tcp_pcb *pcb, tcp_sent_fn sent);
mbed714 0:d616ece2d859 320 void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval);
mbed714 0:d616ece2d859 321 void tcp_err (struct tcp_pcb *pcb, tcp_err_fn err);
mbed714 0:d616ece2d859 322
mbed714 0:d616ece2d859 323 #define tcp_mss(pcb) (((pcb)->flags & TF_TIMESTAMP) ? ((pcb)->mss - 12) : (pcb)->mss)
mbed714 0:d616ece2d859 324 #define tcp_sndbuf(pcb) ((pcb)->snd_buf)
mbed714 0:d616ece2d859 325 #define tcp_sndqueuelen(pcb) ((pcb)->snd_queuelen)
mbed714 0:d616ece2d859 326 #define tcp_nagle_disable(pcb) ((pcb)->flags |= TF_NODELAY)
mbed714 0:d616ece2d859 327 #define tcp_nagle_enable(pcb) ((pcb)->flags &= ~TF_NODELAY)
mbed714 0:d616ece2d859 328 #define tcp_nagle_disabled(pcb) (((pcb)->flags & TF_NODELAY) != 0)
mbed714 0:d616ece2d859 329
mbed714 0:d616ece2d859 330 #if TCP_LISTEN_BACKLOG
mbed714 0:d616ece2d859 331 #define tcp_accepted(pcb) do { \
mbed714 0:d616ece2d859 332 LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", pcb->state == LISTEN); \
mbed714 0:d616ece2d859 333 (((struct tcp_pcb_listen *)(pcb))->accepts_pending--); } while(0)
mbed714 0:d616ece2d859 334 #else /* TCP_LISTEN_BACKLOG */
mbed714 0:d616ece2d859 335 #define tcp_accepted(pcb) LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", \
mbed714 0:d616ece2d859 336 pcb->state == LISTEN)
mbed714 0:d616ece2d859 337 #endif /* TCP_LISTEN_BACKLOG */
mbed714 0:d616ece2d859 338
mbed714 0:d616ece2d859 339 void tcp_recved (struct tcp_pcb *pcb, u16_t len);
mbed714 0:d616ece2d859 340 err_t tcp_bind (struct tcp_pcb *pcb, ip_addr_t *ipaddr,
mbed714 0:d616ece2d859 341 u16_t port);
mbed714 0:d616ece2d859 342 err_t tcp_connect (struct tcp_pcb *pcb, ip_addr_t *ipaddr,
mbed714 0:d616ece2d859 343 u16_t port, tcp_connected_fn connected);
mbed714 0:d616ece2d859 344
mbed714 0:d616ece2d859 345 struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog);
mbed714 0:d616ece2d859 346 #define tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG)
mbed714 0:d616ece2d859 347
mbed714 0:d616ece2d859 348 void tcp_abort (struct tcp_pcb *pcb);
mbed714 0:d616ece2d859 349 err_t tcp_close (struct tcp_pcb *pcb);
mbed714 0:d616ece2d859 350 err_t tcp_shutdown(struct tcp_pcb *pcb, int shut_rx, int shut_tx);
mbed714 0:d616ece2d859 351
mbed714 0:d616ece2d859 352 /* Flags for "apiflags" parameter in tcp_write */
mbed714 0:d616ece2d859 353 #define TCP_WRITE_FLAG_COPY 0x01
mbed714 0:d616ece2d859 354 #define TCP_WRITE_FLAG_MORE 0x02
mbed714 0:d616ece2d859 355
mbed714 0:d616ece2d859 356 err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, u16_t len,
mbed714 0:d616ece2d859 357 u8_t apiflags);
mbed714 0:d616ece2d859 358
mbed714 0:d616ece2d859 359 void tcp_setprio (struct tcp_pcb *pcb, u8_t prio);
mbed714 0:d616ece2d859 360
mbed714 0:d616ece2d859 361 #define TCP_PRIO_MIN 1
mbed714 0:d616ece2d859 362 #define TCP_PRIO_NORMAL 64
mbed714 0:d616ece2d859 363 #define TCP_PRIO_MAX 127
mbed714 0:d616ece2d859 364
mbed714 0:d616ece2d859 365 err_t tcp_output (struct tcp_pcb *pcb);
mbed714 0:d616ece2d859 366
mbed714 0:d616ece2d859 367
mbed714 0:d616ece2d859 368 const char* tcp_debug_state_str(enum tcp_state s);
mbed714 0:d616ece2d859 369
mbed714 0:d616ece2d859 370
mbed714 0:d616ece2d859 371 #ifdef __cplusplus
mbed714 0:d616ece2d859 372 }
mbed714 0:d616ece2d859 373 #endif
mbed714 0:d616ece2d859 374
mbed714 0:d616ece2d859 375 #endif /* LWIP_TCP */
mbed714 0:d616ece2d859 376
mbed714 0:d616ece2d859 377 #endif /* __LWIP_TCP_H__ */