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