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