Hi. This is the feed program for Cosm. (The previous name of the services is Pachube.)

Dependencies:   mbed ThermistorPack Pachube ConfigFile EthernetNetIf TextLCD HTTPClient_ToBeRemoved FatFileSystem SDFileSystem

Committer:
shintamainjp
Date:
Mon Aug 06 12:37:59 2012 +0000
Revision:
0:521ba375aa0f
Pachube renamed to Cosm.

Who changed what in which revision?

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