mbed Phone Platform

Dependencies:   ulaw mbed ConfigFile

Committer:
okini3939
Date:
Sun Dec 26 15:49:07 2010 +0000
Revision:
1:0f82c574096f

        

Who changed what in which revision?

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