Trial code integration web page update with analogue data and ntp support

Dependencies:   NTPClient_NetServices mbed

Committer:
pmr1
Date:
Fri Aug 06 17:57:45 2010 +0000
Revision:
0:8cc2035bebfc

        

Who changed what in which revision?

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