Web server based weather station using Sparkfun Weather Meters.

Dependencies:   FatFileSystem mbed WeatherMeters SDFileSystem

Committer:
AdamGreen
Date:
Thu Feb 23 21:38:39 2012 +0000
Revision:
0:616601bde9fb

        

Who changed what in which revision?

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