testing of combination of LCS and LAN

Dependencies:   mbed

Committer:
damir
Date:
Wed Jan 14 13:29:55 2015 +0000
Revision:
0:a7a6a692162f
Test of LAN

Who changed what in which revision?

UserRevisionLine numberNew contents of line
damir 0:a7a6a692162f 1 /*
damir 0:a7a6a692162f 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
damir 0:a7a6a692162f 3 * All rights reserved.
damir 0:a7a6a692162f 4 *
damir 0:a7a6a692162f 5 * Redistribution and use in source and binary forms, with or without modification,
damir 0:a7a6a692162f 6 * are permitted provided that the following conditions are met:
damir 0:a7a6a692162f 7 *
damir 0:a7a6a692162f 8 * 1. Redistributions of source code must retain the above copyright notice,
damir 0:a7a6a692162f 9 * this list of conditions and the following disclaimer.
damir 0:a7a6a692162f 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
damir 0:a7a6a692162f 11 * this list of conditions and the following disclaimer in the documentation
damir 0:a7a6a692162f 12 * and/or other materials provided with the distribution.
damir 0:a7a6a692162f 13 * 3. The name of the author may not be used to endorse or promote products
damir 0:a7a6a692162f 14 * derived from this software without specific prior written permission.
damir 0:a7a6a692162f 15 *
damir 0:a7a6a692162f 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
damir 0:a7a6a692162f 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
damir 0:a7a6a692162f 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
damir 0:a7a6a692162f 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
damir 0:a7a6a692162f 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
damir 0:a7a6a692162f 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
damir 0:a7a6a692162f 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
damir 0:a7a6a692162f 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
damir 0:a7a6a692162f 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
damir 0:a7a6a692162f 25 * OF SUCH DAMAGE.
damir 0:a7a6a692162f 26 *
damir 0:a7a6a692162f 27 * This file is part of the lwIP TCP/IP stack.
damir 0:a7a6a692162f 28 *
damir 0:a7a6a692162f 29 * Author: Adam Dunkels <adam@sics.se>
damir 0:a7a6a692162f 30 *
damir 0:a7a6a692162f 31 */
damir 0:a7a6a692162f 32 #ifndef __LWIP_TCP_IMPL_H__
damir 0:a7a6a692162f 33 #define __LWIP_TCP_IMPL_H__
damir 0:a7a6a692162f 34
damir 0:a7a6a692162f 35 #include "lwip/opt.h"
damir 0:a7a6a692162f 36
damir 0:a7a6a692162f 37 #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
damir 0:a7a6a692162f 38
damir 0:a7a6a692162f 39 #include "lwip/tcp.h"
damir 0:a7a6a692162f 40 #include "lwip/sys.h"
damir 0:a7a6a692162f 41 #include "lwip/mem.h"
damir 0:a7a6a692162f 42 #include "lwip/pbuf.h"
damir 0:a7a6a692162f 43 #include "lwip/ip.h"
damir 0:a7a6a692162f 44 #include "lwip/icmp.h"
damir 0:a7a6a692162f 45 #include "lwip/err.h"
damir 0:a7a6a692162f 46
damir 0:a7a6a692162f 47 #ifdef __cplusplus
damir 0:a7a6a692162f 48 extern "C" {
damir 0:a7a6a692162f 49 #endif
damir 0:a7a6a692162f 50
damir 0:a7a6a692162f 51 /* Functions for interfacing with TCP: */
damir 0:a7a6a692162f 52
damir 0:a7a6a692162f 53 /* Lower layer interface to TCP: */
damir 0:a7a6a692162f 54 #define tcp_init() /* Compatibility define, no init needed. */
damir 0:a7a6a692162f 55 void tcp_tmr (void); /* Must be called every
damir 0:a7a6a692162f 56 TCP_TMR_INTERVAL
damir 0:a7a6a692162f 57 ms. (Typically 250 ms). */
damir 0:a7a6a692162f 58 /* It is also possible to call these two functions at the right
damir 0:a7a6a692162f 59 intervals (instead of calling tcp_tmr()). */
damir 0:a7a6a692162f 60 void tcp_slowtmr (void);
damir 0:a7a6a692162f 61 void tcp_fasttmr (void);
damir 0:a7a6a692162f 62
damir 0:a7a6a692162f 63
damir 0:a7a6a692162f 64 /* Only used by IP to pass a TCP segment to TCP: */
damir 0:a7a6a692162f 65 void tcp_input (struct pbuf *p, struct netif *inp);
damir 0:a7a6a692162f 66 /* Used within the TCP code only: */
damir 0:a7a6a692162f 67 struct tcp_pcb * tcp_alloc (u8_t prio);
damir 0:a7a6a692162f 68 void tcp_abandon (struct tcp_pcb *pcb, int reset);
damir 0:a7a6a692162f 69 err_t tcp_send_empty_ack(struct tcp_pcb *pcb);
damir 0:a7a6a692162f 70 void tcp_rexmit (struct tcp_pcb *pcb);
damir 0:a7a6a692162f 71 void tcp_rexmit_rto (struct tcp_pcb *pcb);
damir 0:a7a6a692162f 72 void tcp_rexmit_fast (struct tcp_pcb *pcb);
damir 0:a7a6a692162f 73 u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb);
damir 0:a7a6a692162f 74
damir 0:a7a6a692162f 75 /**
damir 0:a7a6a692162f 76 * This is the Nagle algorithm: try to combine user data to send as few TCP
damir 0:a7a6a692162f 77 * segments as possible. Only send if
damir 0:a7a6a692162f 78 * - no previously transmitted data on the connection remains unacknowledged or
damir 0:a7a6a692162f 79 * - the TF_NODELAY flag is set (nagle algorithm turned off for this pcb) or
damir 0:a7a6a692162f 80 * - the only unsent segment is at least pcb->mss bytes long (or there is more
damir 0:a7a6a692162f 81 * than one unsent segment - with lwIP, this can happen although unsent->len < mss)
damir 0:a7a6a692162f 82 * - or if we are in fast-retransmit (TF_INFR)
damir 0:a7a6a692162f 83 */
damir 0:a7a6a692162f 84 #define tcp_do_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \
damir 0:a7a6a692162f 85 ((tpcb)->flags & (TF_NODELAY | TF_INFR)) || \
damir 0:a7a6a692162f 86 (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \
damir 0:a7a6a692162f 87 ((tpcb)->unsent->len >= (tpcb)->mss))) \
damir 0:a7a6a692162f 88 ) ? 1 : 0)
damir 0:a7a6a692162f 89 #define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK)
damir 0:a7a6a692162f 90
damir 0:a7a6a692162f 91
damir 0:a7a6a692162f 92 #define TCP_SEQ_LT(a,b) ((s32_t)((a)-(b)) < 0)
damir 0:a7a6a692162f 93 #define TCP_SEQ_LEQ(a,b) ((s32_t)((a)-(b)) <= 0)
damir 0:a7a6a692162f 94 #define TCP_SEQ_GT(a,b) ((s32_t)((a)-(b)) > 0)
damir 0:a7a6a692162f 95 #define TCP_SEQ_GEQ(a,b) ((s32_t)((a)-(b)) >= 0)
damir 0:a7a6a692162f 96 /* is b<=a<=c? */
damir 0:a7a6a692162f 97 #if 0 /* see bug #10548 */
damir 0:a7a6a692162f 98 #define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b))
damir 0:a7a6a692162f 99 #endif
damir 0:a7a6a692162f 100 #define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
damir 0:a7a6a692162f 101 #define TCP_FIN 0x01U
damir 0:a7a6a692162f 102 #define TCP_SYN 0x02U
damir 0:a7a6a692162f 103 #define TCP_RST 0x04U
damir 0:a7a6a692162f 104 #define TCP_PSH 0x08U
damir 0:a7a6a692162f 105 #define TCP_ACK 0x10U
damir 0:a7a6a692162f 106 #define TCP_URG 0x20U
damir 0:a7a6a692162f 107 #define TCP_ECE 0x40U
damir 0:a7a6a692162f 108 #define TCP_CWR 0x80U
damir 0:a7a6a692162f 109
damir 0:a7a6a692162f 110 #define TCP_FLAGS 0x3fU
damir 0:a7a6a692162f 111
damir 0:a7a6a692162f 112 /* Length of the TCP header, excluding options. */
damir 0:a7a6a692162f 113 #define TCP_HLEN 20
damir 0:a7a6a692162f 114
damir 0:a7a6a692162f 115 #ifndef TCP_TMR_INTERVAL
damir 0:a7a6a692162f 116 #define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */
damir 0:a7a6a692162f 117 #endif /* TCP_TMR_INTERVAL */
damir 0:a7a6a692162f 118
damir 0:a7a6a692162f 119 #ifndef TCP_FAST_INTERVAL
damir 0:a7a6a692162f 120 #define TCP_FAST_INTERVAL TCP_TMR_INTERVAL /* the fine grained timeout in milliseconds */
damir 0:a7a6a692162f 121 #endif /* TCP_FAST_INTERVAL */
damir 0:a7a6a692162f 122
damir 0:a7a6a692162f 123 #ifndef TCP_SLOW_INTERVAL
damir 0:a7a6a692162f 124 #define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) /* the coarse grained timeout in milliseconds */
damir 0:a7a6a692162f 125 #endif /* TCP_SLOW_INTERVAL */
damir 0:a7a6a692162f 126
damir 0:a7a6a692162f 127 #define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */
damir 0:a7a6a692162f 128 #define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */
damir 0:a7a6a692162f 129
damir 0:a7a6a692162f 130 #define TCP_OOSEQ_TIMEOUT 6U /* x RTO */
damir 0:a7a6a692162f 131
damir 0:a7a6a692162f 132 #ifndef TCP_MSL
damir 0:a7a6a692162f 133 #define TCP_MSL 60000UL /* The maximum segment lifetime in milliseconds */
damir 0:a7a6a692162f 134 #endif
damir 0:a7a6a692162f 135
damir 0:a7a6a692162f 136 /* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */
damir 0:a7a6a692162f 137 #ifndef TCP_KEEPIDLE_DEFAULT
damir 0:a7a6a692162f 138 #define TCP_KEEPIDLE_DEFAULT 7200000UL /* Default KEEPALIVE timer in milliseconds */
damir 0:a7a6a692162f 139 #endif
damir 0:a7a6a692162f 140
damir 0:a7a6a692162f 141 #ifndef TCP_KEEPINTVL_DEFAULT
damir 0:a7a6a692162f 142 #define TCP_KEEPINTVL_DEFAULT 75000UL /* Default Time between KEEPALIVE probes in milliseconds */
damir 0:a7a6a692162f 143 #endif
damir 0:a7a6a692162f 144
damir 0:a7a6a692162f 145 #ifndef TCP_KEEPCNT_DEFAULT
damir 0:a7a6a692162f 146 #define TCP_KEEPCNT_DEFAULT 9U /* Default Counter for KEEPALIVE probes */
damir 0:a7a6a692162f 147 #endif
damir 0:a7a6a692162f 148
damir 0:a7a6a692162f 149 #define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */
damir 0:a7a6a692162f 150
damir 0:a7a6a692162f 151 /* Fields are (of course) in network byte order.
damir 0:a7a6a692162f 152 * Some fields are converted to host byte order in tcp_input().
damir 0:a7a6a692162f 153 */
damir 0:a7a6a692162f 154 #ifdef PACK_STRUCT_USE_INCLUDES
damir 0:a7a6a692162f 155 # include "arch/bpstruct.h"
damir 0:a7a6a692162f 156 #endif
damir 0:a7a6a692162f 157 PACK_STRUCT_BEGIN
damir 0:a7a6a692162f 158 struct tcp_hdr {
damir 0:a7a6a692162f 159 PACK_STRUCT_FIELD(u16_t src);
damir 0:a7a6a692162f 160 PACK_STRUCT_FIELD(u16_t dest);
damir 0:a7a6a692162f 161 PACK_STRUCT_FIELD(u32_t seqno);
damir 0:a7a6a692162f 162 PACK_STRUCT_FIELD(u32_t ackno);
damir 0:a7a6a692162f 163 PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);
damir 0:a7a6a692162f 164 PACK_STRUCT_FIELD(u16_t wnd);
damir 0:a7a6a692162f 165 PACK_STRUCT_FIELD(u16_t chksum);
damir 0:a7a6a692162f 166 PACK_STRUCT_FIELD(u16_t urgp);
damir 0:a7a6a692162f 167 } PACK_STRUCT_STRUCT;
damir 0:a7a6a692162f 168 PACK_STRUCT_END
damir 0:a7a6a692162f 169 #ifdef PACK_STRUCT_USE_INCLUDES
damir 0:a7a6a692162f 170 # include "arch/epstruct.h"
damir 0:a7a6a692162f 171 #endif
damir 0:a7a6a692162f 172
damir 0:a7a6a692162f 173 #define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
damir 0:a7a6a692162f 174 #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
damir 0:a7a6a692162f 175 #define TCPH_FLAGS(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
damir 0:a7a6a692162f 176
damir 0:a7a6a692162f 177 #define TCPH_OFFSET_SET(phdr, offset) (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
damir 0:a7a6a692162f 178 #define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
damir 0:a7a6a692162f 179 #define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS((u16_t)(~(u16_t)(TCP_FLAGS)))) | htons(flags))
damir 0:a7a6a692162f 180 #define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags))
damir 0:a7a6a692162f 181
damir 0:a7a6a692162f 182 #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
damir 0:a7a6a692162f 183 #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
damir 0:a7a6a692162f 184
damir 0:a7a6a692162f 185 #define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
damir 0:a7a6a692162f 186
damir 0:a7a6a692162f 187 /** Flags used on input processing, not on pcb->flags
damir 0:a7a6a692162f 188 */
damir 0:a7a6a692162f 189 #define TF_RESET (u8_t)0x08U /* Connection was reset. */
damir 0:a7a6a692162f 190 #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */
damir 0:a7a6a692162f 191 #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */
damir 0:a7a6a692162f 192
damir 0:a7a6a692162f 193
damir 0:a7a6a692162f 194 #if LWIP_EVENT_API
damir 0:a7a6a692162f 195
damir 0:a7a6a692162f 196 #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
damir 0:a7a6a692162f 197 LWIP_EVENT_ACCEPT, NULL, 0, err)
damir 0:a7a6a692162f 198 #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
damir 0:a7a6a692162f 199 LWIP_EVENT_SENT, NULL, space, ERR_OK)
damir 0:a7a6a692162f 200 #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
damir 0:a7a6a692162f 201 LWIP_EVENT_RECV, (p), 0, (err))
damir 0:a7a6a692162f 202 #define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
damir 0:a7a6a692162f 203 LWIP_EVENT_RECV, NULL, 0, ERR_OK)
damir 0:a7a6a692162f 204 #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
damir 0:a7a6a692162f 205 LWIP_EVENT_CONNECTED, NULL, 0, (err))
damir 0:a7a6a692162f 206 #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
damir 0:a7a6a692162f 207 LWIP_EVENT_POLL, NULL, 0, ERR_OK)
damir 0:a7a6a692162f 208 #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \
damir 0:a7a6a692162f 209 LWIP_EVENT_ERR, NULL, 0, (err))
damir 0:a7a6a692162f 210
damir 0:a7a6a692162f 211 #else /* LWIP_EVENT_API */
damir 0:a7a6a692162f 212
damir 0:a7a6a692162f 213 #define TCP_EVENT_ACCEPT(pcb,err,ret) \
damir 0:a7a6a692162f 214 do { \
damir 0:a7a6a692162f 215 if((pcb)->accept != NULL) \
damir 0:a7a6a692162f 216 (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \
damir 0:a7a6a692162f 217 else (ret) = ERR_ARG; \
damir 0:a7a6a692162f 218 } while (0)
damir 0:a7a6a692162f 219
damir 0:a7a6a692162f 220 #define TCP_EVENT_SENT(pcb,space,ret) \
damir 0:a7a6a692162f 221 do { \
damir 0:a7a6a692162f 222 if((pcb)->sent != NULL) \
damir 0:a7a6a692162f 223 (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \
damir 0:a7a6a692162f 224 else (ret) = ERR_OK; \
damir 0:a7a6a692162f 225 } while (0)
damir 0:a7a6a692162f 226
damir 0:a7a6a692162f 227 #define TCP_EVENT_RECV(pcb,p,err,ret) \
damir 0:a7a6a692162f 228 do { \
damir 0:a7a6a692162f 229 if((pcb)->recv != NULL) { \
damir 0:a7a6a692162f 230 (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));\
damir 0:a7a6a692162f 231 } else { \
damir 0:a7a6a692162f 232 (ret) = tcp_recv_null(NULL, (pcb), (p), (err)); \
damir 0:a7a6a692162f 233 } \
damir 0:a7a6a692162f 234 } while (0)
damir 0:a7a6a692162f 235
damir 0:a7a6a692162f 236 #define TCP_EVENT_CLOSED(pcb,ret) \
damir 0:a7a6a692162f 237 do { \
damir 0:a7a6a692162f 238 if(((pcb)->recv != NULL)) { \
damir 0:a7a6a692162f 239 (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),NULL,ERR_OK);\
damir 0:a7a6a692162f 240 } else { \
damir 0:a7a6a692162f 241 (ret) = ERR_OK; \
damir 0:a7a6a692162f 242 } \
damir 0:a7a6a692162f 243 } while (0)
damir 0:a7a6a692162f 244
damir 0:a7a6a692162f 245 #define TCP_EVENT_CONNECTED(pcb,err,ret) \
damir 0:a7a6a692162f 246 do { \
damir 0:a7a6a692162f 247 if((pcb)->connected != NULL) \
damir 0:a7a6a692162f 248 (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \
damir 0:a7a6a692162f 249 else (ret) = ERR_OK; \
damir 0:a7a6a692162f 250 } while (0)
damir 0:a7a6a692162f 251
damir 0:a7a6a692162f 252 #define TCP_EVENT_POLL(pcb,ret) \
damir 0:a7a6a692162f 253 do { \
damir 0:a7a6a692162f 254 if((pcb)->poll != NULL) \
damir 0:a7a6a692162f 255 (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \
damir 0:a7a6a692162f 256 else (ret) = ERR_OK; \
damir 0:a7a6a692162f 257 } while (0)
damir 0:a7a6a692162f 258
damir 0:a7a6a692162f 259 #define TCP_EVENT_ERR(errf,arg,err) \
damir 0:a7a6a692162f 260 do { \
damir 0:a7a6a692162f 261 if((errf) != NULL) \
damir 0:a7a6a692162f 262 (errf)((arg),(err)); \
damir 0:a7a6a692162f 263 } while (0)
damir 0:a7a6a692162f 264
damir 0:a7a6a692162f 265 #endif /* LWIP_EVENT_API */
damir 0:a7a6a692162f 266
damir 0:a7a6a692162f 267 /** Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled */
damir 0:a7a6a692162f 268 #if TCP_OVERSIZE && defined(LWIP_DEBUG)
damir 0:a7a6a692162f 269 #define TCP_OVERSIZE_DBGCHECK 1
damir 0:a7a6a692162f 270 #else
damir 0:a7a6a692162f 271 #define TCP_OVERSIZE_DBGCHECK 0
damir 0:a7a6a692162f 272 #endif
damir 0:a7a6a692162f 273
damir 0:a7a6a692162f 274 /** Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled */
damir 0:a7a6a692162f 275 #define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP)
damir 0:a7a6a692162f 276
damir 0:a7a6a692162f 277 /* This structure represents a TCP segment on the unsent, unacked and ooseq queues */
damir 0:a7a6a692162f 278 struct tcp_seg {
damir 0:a7a6a692162f 279 struct tcp_seg *next; /* used when putting segements on a queue */
damir 0:a7a6a692162f 280 struct pbuf *p; /* buffer containing data + TCP header */
damir 0:a7a6a692162f 281 void *dataptr; /* pointer to the TCP data in the pbuf */
damir 0:a7a6a692162f 282 u16_t len; /* the TCP length of this segment */
damir 0:a7a6a692162f 283 #if TCP_OVERSIZE_DBGCHECK
damir 0:a7a6a692162f 284 u16_t oversize_left; /* Extra bytes available at the end of the last
damir 0:a7a6a692162f 285 pbuf in unsent (used for asserting vs.
damir 0:a7a6a692162f 286 tcp_pcb.unsent_oversized only) */
damir 0:a7a6a692162f 287 #endif /* TCP_OVERSIZE_DBGCHECK */
damir 0:a7a6a692162f 288 #if TCP_CHECKSUM_ON_COPY
damir 0:a7a6a692162f 289 u16_t chksum;
damir 0:a7a6a692162f 290 u8_t chksum_swapped;
damir 0:a7a6a692162f 291 #endif /* TCP_CHECKSUM_ON_COPY */
damir 0:a7a6a692162f 292 u8_t flags;
damir 0:a7a6a692162f 293 #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */
damir 0:a7a6a692162f 294 #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */
damir 0:a7a6a692162f 295 #define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is
damir 0:a7a6a692162f 296 checksummed into 'chksum' */
damir 0:a7a6a692162f 297 struct tcp_hdr *tcphdr; /* the TCP header */
damir 0:a7a6a692162f 298 };
damir 0:a7a6a692162f 299
damir 0:a7a6a692162f 300 #define LWIP_TCP_OPT_LENGTH(flags) \
damir 0:a7a6a692162f 301 (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \
damir 0:a7a6a692162f 302 (flags & TF_SEG_OPTS_TS ? 12 : 0)
damir 0:a7a6a692162f 303
damir 0:a7a6a692162f 304 /** This returns a TCP header option for MSS in an u32_t */
damir 0:a7a6a692162f 305 #define TCP_BUILD_MSS_OPTION(x) (x) = PP_HTONL(((u32_t)2 << 24) | \
damir 0:a7a6a692162f 306 ((u32_t)4 << 16) | \
damir 0:a7a6a692162f 307 (((u32_t)TCP_MSS / 256) << 8) | \
damir 0:a7a6a692162f 308 (TCP_MSS & 255))
damir 0:a7a6a692162f 309
damir 0:a7a6a692162f 310 /* Global variables: */
damir 0:a7a6a692162f 311 extern struct tcp_pcb *tcp_input_pcb;
damir 0:a7a6a692162f 312 extern u32_t tcp_ticks;
damir 0:a7a6a692162f 313
damir 0:a7a6a692162f 314 /* The TCP PCB lists. */
damir 0:a7a6a692162f 315 union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
damir 0:a7a6a692162f 316 struct tcp_pcb_listen *listen_pcbs;
damir 0:a7a6a692162f 317 struct tcp_pcb *pcbs;
damir 0:a7a6a692162f 318 };
damir 0:a7a6a692162f 319 extern struct tcp_pcb *tcp_bound_pcbs;
damir 0:a7a6a692162f 320 extern union tcp_listen_pcbs_t tcp_listen_pcbs;
damir 0:a7a6a692162f 321 extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a
damir 0:a7a6a692162f 322 state in which they accept or send
damir 0:a7a6a692162f 323 data. */
damir 0:a7a6a692162f 324 extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */
damir 0:a7a6a692162f 325
damir 0:a7a6a692162f 326 extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
damir 0:a7a6a692162f 327
damir 0:a7a6a692162f 328 /* Axioms about the above lists:
damir 0:a7a6a692162f 329 1) Every TCP PCB that is not CLOSED is in one of the lists.
damir 0:a7a6a692162f 330 2) A PCB is only in one of the lists.
damir 0:a7a6a692162f 331 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
damir 0:a7a6a692162f 332 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.
damir 0:a7a6a692162f 333 */
damir 0:a7a6a692162f 334 /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB
damir 0:a7a6a692162f 335 with a PCB list or removes a PCB from a list, respectively. */
damir 0:a7a6a692162f 336 #ifndef TCP_DEBUG_PCB_LISTS
damir 0:a7a6a692162f 337 #define TCP_DEBUG_PCB_LISTS 0
damir 0:a7a6a692162f 338 #endif
damir 0:a7a6a692162f 339 #if TCP_DEBUG_PCB_LISTS
damir 0:a7a6a692162f 340 #define TCP_REG(pcbs, npcb) do {\
damir 0:a7a6a692162f 341 LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \
damir 0:a7a6a692162f 342 for(tcp_tmp_pcb = *(pcbs); \
damir 0:a7a6a692162f 343 tcp_tmp_pcb != NULL; \
damir 0:a7a6a692162f 344 tcp_tmp_pcb = tcp_tmp_pcb->next) { \
damir 0:a7a6a692162f 345 LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \
damir 0:a7a6a692162f 346 } \
damir 0:a7a6a692162f 347 LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \
damir 0:a7a6a692162f 348 (npcb)->next = *(pcbs); \
damir 0:a7a6a692162f 349 LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \
damir 0:a7a6a692162f 350 *(pcbs) = (npcb); \
damir 0:a7a6a692162f 351 LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
damir 0:a7a6a692162f 352 tcp_timer_needed(); \
damir 0:a7a6a692162f 353 } while(0)
damir 0:a7a6a692162f 354 #define TCP_RMV(pcbs, npcb) do { \
damir 0:a7a6a692162f 355 LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \
damir 0:a7a6a692162f 356 LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \
damir 0:a7a6a692162f 357 if(*(pcbs) == (npcb)) { \
damir 0:a7a6a692162f 358 *(pcbs) = (*pcbs)->next; \
damir 0:a7a6a692162f 359 } else for(tcp_tmp_pcb = *(pcbs); tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
damir 0:a7a6a692162f 360 if(tcp_tmp_pcb->next == (npcb)) { \
damir 0:a7a6a692162f 361 tcp_tmp_pcb->next = (npcb)->next; \
damir 0:a7a6a692162f 362 break; \
damir 0:a7a6a692162f 363 } \
damir 0:a7a6a692162f 364 } \
damir 0:a7a6a692162f 365 (npcb)->next = NULL; \
damir 0:a7a6a692162f 366 LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
damir 0:a7a6a692162f 367 LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \
damir 0:a7a6a692162f 368 } while(0)
damir 0:a7a6a692162f 369
damir 0:a7a6a692162f 370 #else /* LWIP_DEBUG */
damir 0:a7a6a692162f 371
damir 0:a7a6a692162f 372 #define TCP_REG(pcbs, npcb) \
damir 0:a7a6a692162f 373 do { \
damir 0:a7a6a692162f 374 (npcb)->next = *pcbs; \
damir 0:a7a6a692162f 375 *(pcbs) = (npcb); \
damir 0:a7a6a692162f 376 tcp_timer_needed(); \
damir 0:a7a6a692162f 377 } while (0)
damir 0:a7a6a692162f 378
damir 0:a7a6a692162f 379 #define TCP_RMV(pcbs, npcb) \
damir 0:a7a6a692162f 380 do { \
damir 0:a7a6a692162f 381 if(*(pcbs) == (npcb)) { \
damir 0:a7a6a692162f 382 (*(pcbs)) = (*pcbs)->next; \
damir 0:a7a6a692162f 383 } \
damir 0:a7a6a692162f 384 else { \
damir 0:a7a6a692162f 385 for(tcp_tmp_pcb = *pcbs; \
damir 0:a7a6a692162f 386 tcp_tmp_pcb != NULL; \
damir 0:a7a6a692162f 387 tcp_tmp_pcb = tcp_tmp_pcb->next) { \
damir 0:a7a6a692162f 388 if(tcp_tmp_pcb->next == (npcb)) { \
damir 0:a7a6a692162f 389 tcp_tmp_pcb->next = (npcb)->next; \
damir 0:a7a6a692162f 390 break; \
damir 0:a7a6a692162f 391 } \
damir 0:a7a6a692162f 392 } \
damir 0:a7a6a692162f 393 } \
damir 0:a7a6a692162f 394 (npcb)->next = NULL; \
damir 0:a7a6a692162f 395 } while(0)
damir 0:a7a6a692162f 396
damir 0:a7a6a692162f 397 #endif /* LWIP_DEBUG */
damir 0:a7a6a692162f 398
damir 0:a7a6a692162f 399
damir 0:a7a6a692162f 400 /* Internal functions: */
damir 0:a7a6a692162f 401 struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb);
damir 0:a7a6a692162f 402 void tcp_pcb_purge(struct tcp_pcb *pcb);
damir 0:a7a6a692162f 403 void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb);
damir 0:a7a6a692162f 404
damir 0:a7a6a692162f 405 void tcp_segs_free(struct tcp_seg *seg);
damir 0:a7a6a692162f 406 void tcp_seg_free(struct tcp_seg *seg);
damir 0:a7a6a692162f 407 struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);
damir 0:a7a6a692162f 408
damir 0:a7a6a692162f 409 #define tcp_ack(pcb) \
damir 0:a7a6a692162f 410 do { \
damir 0:a7a6a692162f 411 if((pcb)->flags & TF_ACK_DELAY) { \
damir 0:a7a6a692162f 412 (pcb)->flags &= ~TF_ACK_DELAY; \
damir 0:a7a6a692162f 413 (pcb)->flags |= TF_ACK_NOW; \
damir 0:a7a6a692162f 414 } \
damir 0:a7a6a692162f 415 else { \
damir 0:a7a6a692162f 416 (pcb)->flags |= TF_ACK_DELAY; \
damir 0:a7a6a692162f 417 } \
damir 0:a7a6a692162f 418 } while (0)
damir 0:a7a6a692162f 419
damir 0:a7a6a692162f 420 #define tcp_ack_now(pcb) \
damir 0:a7a6a692162f 421 do { \
damir 0:a7a6a692162f 422 (pcb)->flags |= TF_ACK_NOW; \
damir 0:a7a6a692162f 423 } while (0)
damir 0:a7a6a692162f 424
damir 0:a7a6a692162f 425 err_t tcp_send_fin(struct tcp_pcb *pcb);
damir 0:a7a6a692162f 426 err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags);
damir 0:a7a6a692162f 427
damir 0:a7a6a692162f 428 void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
damir 0:a7a6a692162f 429
damir 0:a7a6a692162f 430 void tcp_rst(u32_t seqno, u32_t ackno,
damir 0:a7a6a692162f 431 ip_addr_t *local_ip, ip_addr_t *remote_ip,
damir 0:a7a6a692162f 432 u16_t local_port, u16_t remote_port);
damir 0:a7a6a692162f 433
damir 0:a7a6a692162f 434 u32_t tcp_next_iss(void);
damir 0:a7a6a692162f 435
damir 0:a7a6a692162f 436 void tcp_keepalive(struct tcp_pcb *pcb);
damir 0:a7a6a692162f 437 void tcp_zero_window_probe(struct tcp_pcb *pcb);
damir 0:a7a6a692162f 438
damir 0:a7a6a692162f 439 #if TCP_CALCULATE_EFF_SEND_MSS
damir 0:a7a6a692162f 440 u16_t tcp_eff_send_mss(u16_t sendmss, ip_addr_t *addr);
damir 0:a7a6a692162f 441 #endif /* TCP_CALCULATE_EFF_SEND_MSS */
damir 0:a7a6a692162f 442
damir 0:a7a6a692162f 443 #if LWIP_CALLBACK_API
damir 0:a7a6a692162f 444 err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
damir 0:a7a6a692162f 445 #endif /* LWIP_CALLBACK_API */
damir 0:a7a6a692162f 446
damir 0:a7a6a692162f 447 #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
damir 0:a7a6a692162f 448 void tcp_debug_print(struct tcp_hdr *tcphdr);
damir 0:a7a6a692162f 449 void tcp_debug_print_flags(u8_t flags);
damir 0:a7a6a692162f 450 void tcp_debug_print_state(enum tcp_state s);
damir 0:a7a6a692162f 451 void tcp_debug_print_pcbs(void);
damir 0:a7a6a692162f 452 s16_t tcp_pcbs_sane(void);
damir 0:a7a6a692162f 453 #else
damir 0:a7a6a692162f 454 # define tcp_debug_print(tcphdr)
damir 0:a7a6a692162f 455 # define tcp_debug_print_flags(flags)
damir 0:a7a6a692162f 456 # define tcp_debug_print_state(s)
damir 0:a7a6a692162f 457 # define tcp_debug_print_pcbs()
damir 0:a7a6a692162f 458 # define tcp_pcbs_sane() 1
damir 0:a7a6a692162f 459 #endif /* TCP_DEBUG */
damir 0:a7a6a692162f 460
damir 0:a7a6a692162f 461 /** External function (implemented in timers.c), called when TCP detects
damir 0:a7a6a692162f 462 * that a timer is needed (i.e. active- or time-wait-pcb found). */
damir 0:a7a6a692162f 463 void tcp_timer_needed(void);
damir 0:a7a6a692162f 464
damir 0:a7a6a692162f 465
damir 0:a7a6a692162f 466 #ifdef __cplusplus
damir 0:a7a6a692162f 467 }
damir 0:a7a6a692162f 468 #endif
damir 0:a7a6a692162f 469
damir 0:a7a6a692162f 470 #endif /* LWIP_TCP */
damir 0:a7a6a692162f 471
damir 0:a7a6a692162f 472 #endif /* __LWIP_TCP_H__ */