Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

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