Dependencies:   mbed

Committer:
robertcook
Date:
Wed Jun 13 18:39:46 2012 +0000
Revision:
0:32a0996dff0f

        

Who changed what in which revision?

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