LwIP with PPP & Ethernet integration

Dependents:   NetworkingCoreLib

This is the mbed port of the LwIP stack: http://savannah.nongnu.org/projects/lwip/

It includes contributed content from NXP's port for LPCxxxx devices: http://www.lpcware.com/content/project/lightweight-ip-lwip-networking-stack

Licence

LwIP is licenced under the BSD licence:

Copyright (c) 2001-2004 Swedish Institute of Computer Science. 
All rights reserved. 
Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met: 
1. Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution. 
3. The name of the author may not be used to endorse or promote products 
derived from this software without specific prior written permission. 
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
Committer:
donatien
Date:
Fri May 25 08:56:35 2012 +0000
Revision:
2:1a87f74b8e3b
Parent:
0:8e01dca41002
Removed compilation of EMAC driver when using PPP

Who changed what in which revision?

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