Fork for fixes

Committer:
hudakz
Date:
Sat Dec 20 11:10:40 2014 +0000
Revision:
3:5b17e4656dd0
Child:
4:d774541a34da
02 Name clash with "Ethernet" fixed for LPC1768

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 3:5b17e4656dd0 1
hudakz 3:5b17e4656dd0 2 /**
hudakz 3:5b17e4656dd0 3 * \addtogroup uip
hudakz 3:5b17e4656dd0 4 * @{
hudakz 3:5b17e4656dd0 5 */
hudakz 3:5b17e4656dd0 6
hudakz 3:5b17e4656dd0 7 /**
hudakz 3:5b17e4656dd0 8 * \file
hudakz 3:5b17e4656dd0 9 * Header file for the uIP TCP/IP stack.
hudakz 3:5b17e4656dd0 10 * \author Adam Dunkels <adam@dunkels.com>
hudakz 3:5b17e4656dd0 11 *
hudakz 3:5b17e4656dd0 12 * The uIP TCP/IP stack header file contains definitions for a number
hudakz 3:5b17e4656dd0 13 * of C macros that are used by uIP programs as well as internal uIP
hudakz 3:5b17e4656dd0 14 * structures, TCP/IP header structures and function declarations.
hudakz 3:5b17e4656dd0 15 *
hudakz 3:5b17e4656dd0 16 */
hudakz 3:5b17e4656dd0 17 /*
hudakz 3:5b17e4656dd0 18 * Copyright (c) 2001-2003, Adam Dunkels.
hudakz 3:5b17e4656dd0 19 * All rights reserved.
hudakz 3:5b17e4656dd0 20 *
hudakz 3:5b17e4656dd0 21 * Redistribution and use in source and binary forms, with or without
hudakz 3:5b17e4656dd0 22 * modification, are permitted provided that the following conditions
hudakz 3:5b17e4656dd0 23 * are met:
hudakz 3:5b17e4656dd0 24 * 1. Redistributions of source code must retain the above copyright
hudakz 3:5b17e4656dd0 25 * notice, this list of conditions and the following disclaimer.
hudakz 3:5b17e4656dd0 26 * 2. Redistributions in binary form must reproduce the above copyright
hudakz 3:5b17e4656dd0 27 * notice, this list of conditions and the following disclaimer in the
hudakz 3:5b17e4656dd0 28 * documentation and/or other materials provided with the distribution.
hudakz 3:5b17e4656dd0 29 * 3. The name of the author may not be used to endorse or promote
hudakz 3:5b17e4656dd0 30 * products derived from this software without specific prior
hudakz 3:5b17e4656dd0 31 * written permission.
hudakz 3:5b17e4656dd0 32 *
hudakz 3:5b17e4656dd0 33 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
hudakz 3:5b17e4656dd0 34 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
hudakz 3:5b17e4656dd0 35 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
hudakz 3:5b17e4656dd0 36 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
hudakz 3:5b17e4656dd0 37 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
hudakz 3:5b17e4656dd0 38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
hudakz 3:5b17e4656dd0 39 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
hudakz 3:5b17e4656dd0 40 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
hudakz 3:5b17e4656dd0 41 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
hudakz 3:5b17e4656dd0 42 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
hudakz 3:5b17e4656dd0 43 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hudakz 3:5b17e4656dd0 44 *
hudakz 3:5b17e4656dd0 45 * This file is part of the uIP TCP/IP stack.
hudakz 3:5b17e4656dd0 46 *
hudakz 3:5b17e4656dd0 47 * $Id: uip.h,v 1.40 2006/06/08 07:12:07 adam Exp $
hudakz 3:5b17e4656dd0 48 *
hudakz 3:5b17e4656dd0 49 */
hudakz 3:5b17e4656dd0 50 #ifndef __UIP_H__
hudakz 3:5b17e4656dd0 51 #define __UIP_H__
hudakz 3:5b17e4656dd0 52
hudakz 3:5b17e4656dd0 53 #include "uipopt.h"
hudakz 3:5b17e4656dd0 54
hudakz 3:5b17e4656dd0 55 /**
hudakz 3:5b17e4656dd0 56 * Repressentation of an IP address.
hudakz 3:5b17e4656dd0 57 *
hudakz 3:5b17e4656dd0 58 */
hudakz 3:5b17e4656dd0 59
hudakz 3:5b17e4656dd0 60 typedef u16_t uip_ip4addr_t[2];
hudakz 3:5b17e4656dd0 61 typedef u16_t uip_ip6addr_t[8];
hudakz 3:5b17e4656dd0 62 #if UIP_CONF_IPV6
hudakz 3:5b17e4656dd0 63 typedef uip_ip6addr_t uip_ipaddr_t;
hudakz 3:5b17e4656dd0 64 #else /* UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 65
hudakz 3:5b17e4656dd0 66 typedef uip_ip4addr_t uip_ipaddr_t;
hudakz 3:5b17e4656dd0 67 #endif /* UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 68
hudakz 3:5b17e4656dd0 69 /*---------------------------------------------------------------------------*/
hudakz 3:5b17e4656dd0 70
hudakz 3:5b17e4656dd0 71 /* First, the functions that should be called from the
hudakz 3:5b17e4656dd0 72 * system. Initialization, the periodic timer and incoming packets are
hudakz 3:5b17e4656dd0 73 * handled by the following three functions.
hudakz 3:5b17e4656dd0 74 */
hudakz 3:5b17e4656dd0 75 /**
hudakz 3:5b17e4656dd0 76 * \defgroup uipconffunc uIP configuration functions
hudakz 3:5b17e4656dd0 77 * @{
hudakz 3:5b17e4656dd0 78 *
hudakz 3:5b17e4656dd0 79 * The uIP configuration functions are used for setting run-time
hudakz 3:5b17e4656dd0 80 * parameters in uIP such as IP addresses.
hudakz 3:5b17e4656dd0 81 */
hudakz 3:5b17e4656dd0 82
hudakz 3:5b17e4656dd0 83 /**
hudakz 3:5b17e4656dd0 84 * Set the IP address of this host.
hudakz 3:5b17e4656dd0 85 *
hudakz 3:5b17e4656dd0 86 * The IP address is represented as a 4-byte array where the first
hudakz 3:5b17e4656dd0 87 * octet of the IP address is put in the first member of the 4-byte
hudakz 3:5b17e4656dd0 88 * array.
hudakz 3:5b17e4656dd0 89 *
hudakz 3:5b17e4656dd0 90 * Example:
hudakz 3:5b17e4656dd0 91 \code
hudakz 3:5b17e4656dd0 92
hudakz 3:5b17e4656dd0 93 uip_ipaddr_t addr;
hudakz 3:5b17e4656dd0 94
hudakz 3:5b17e4656dd0 95 uip_ipaddr(&addr, 192,168,1,2);
hudakz 3:5b17e4656dd0 96 uip_sethostaddr(&addr);
hudakz 3:5b17e4656dd0 97
hudakz 3:5b17e4656dd0 98 \endcode
hudakz 3:5b17e4656dd0 99 * \param addr A pointer to an IP address of type uip_ipaddr_t;
hudakz 3:5b17e4656dd0 100 *
hudakz 3:5b17e4656dd0 101 * \sa uip_ipaddr()
hudakz 3:5b17e4656dd0 102 *
hudakz 3:5b17e4656dd0 103 * \hideinitializer
hudakz 3:5b17e4656dd0 104 */
hudakz 3:5b17e4656dd0 105 #define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr))
hudakz 3:5b17e4656dd0 106
hudakz 3:5b17e4656dd0 107 /**
hudakz 3:5b17e4656dd0 108 * Get the IP address of this host.
hudakz 3:5b17e4656dd0 109 *
hudakz 3:5b17e4656dd0 110 * The IP address is represented as a 4-byte array where the first
hudakz 3:5b17e4656dd0 111 * octet of the IP address is put in the first member of the 4-byte
hudakz 3:5b17e4656dd0 112 * array.
hudakz 3:5b17e4656dd0 113 *
hudakz 3:5b17e4656dd0 114 * Example:
hudakz 3:5b17e4656dd0 115 \code
hudakz 3:5b17e4656dd0 116 uip_ipaddr_t hostaddr;
hudakz 3:5b17e4656dd0 117
hudakz 3:5b17e4656dd0 118 uip_gethostaddr(&hostaddr);
hudakz 3:5b17e4656dd0 119 \endcode
hudakz 3:5b17e4656dd0 120 * \param addr A pointer to a uip_ipaddr_t variable that will be
hudakz 3:5b17e4656dd0 121 * filled in with the currently configured IP address.
hudakz 3:5b17e4656dd0 122 *
hudakz 3:5b17e4656dd0 123 * \hideinitializer
hudakz 3:5b17e4656dd0 124 */
hudakz 3:5b17e4656dd0 125
hudakz 3:5b17e4656dd0 126 #define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr)
hudakz 3:5b17e4656dd0 127
hudakz 3:5b17e4656dd0 128 /**
hudakz 3:5b17e4656dd0 129 * Set the default router's IP address.
hudakz 3:5b17e4656dd0 130 *
hudakz 3:5b17e4656dd0 131 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
hudakz 3:5b17e4656dd0 132 * address of the default router.
hudakz 3:5b17e4656dd0 133 *
hudakz 3:5b17e4656dd0 134 * \sa uip_ipaddr()
hudakz 3:5b17e4656dd0 135 *
hudakz 3:5b17e4656dd0 136 * \hideinitializer
hudakz 3:5b17e4656dd0 137 */
hudakz 3:5b17e4656dd0 138
hudakz 3:5b17e4656dd0 139 #define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr))
hudakz 3:5b17e4656dd0 140
hudakz 3:5b17e4656dd0 141 /**
hudakz 3:5b17e4656dd0 142 * Set the netmask.
hudakz 3:5b17e4656dd0 143 *
hudakz 3:5b17e4656dd0 144 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
hudakz 3:5b17e4656dd0 145 * address of the netmask.
hudakz 3:5b17e4656dd0 146 *
hudakz 3:5b17e4656dd0 147 * \sa uip_ipaddr()
hudakz 3:5b17e4656dd0 148 *
hudakz 3:5b17e4656dd0 149 * \hideinitializer
hudakz 3:5b17e4656dd0 150 */
hudakz 3:5b17e4656dd0 151
hudakz 3:5b17e4656dd0 152 #define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr))
hudakz 3:5b17e4656dd0 153
hudakz 3:5b17e4656dd0 154 /**
hudakz 3:5b17e4656dd0 155 * Get the default router's IP address.
hudakz 3:5b17e4656dd0 156 *
hudakz 3:5b17e4656dd0 157 * \param addr A pointer to a uip_ipaddr_t variable that will be
hudakz 3:5b17e4656dd0 158 * filled in with the IP address of the default router.
hudakz 3:5b17e4656dd0 159 *
hudakz 3:5b17e4656dd0 160 * \hideinitializer
hudakz 3:5b17e4656dd0 161 */
hudakz 3:5b17e4656dd0 162
hudakz 3:5b17e4656dd0 163 #define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr)
hudakz 3:5b17e4656dd0 164
hudakz 3:5b17e4656dd0 165 /**
hudakz 3:5b17e4656dd0 166 * Get the netmask.
hudakz 3:5b17e4656dd0 167 *
hudakz 3:5b17e4656dd0 168 * \param addr A pointer to a uip_ipaddr_t variable that will be
hudakz 3:5b17e4656dd0 169 * filled in with the value of the netmask.
hudakz 3:5b17e4656dd0 170 *
hudakz 3:5b17e4656dd0 171 * \hideinitializer
hudakz 3:5b17e4656dd0 172 */
hudakz 3:5b17e4656dd0 173
hudakz 3:5b17e4656dd0 174 #define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask)
hudakz 3:5b17e4656dd0 175
hudakz 3:5b17e4656dd0 176 /** @} */
hudakz 3:5b17e4656dd0 177
hudakz 3:5b17e4656dd0 178 /**
hudakz 3:5b17e4656dd0 179 * \defgroup uipinit uIP initialization functions
hudakz 3:5b17e4656dd0 180 * @{
hudakz 3:5b17e4656dd0 181 *
hudakz 3:5b17e4656dd0 182 * The uIP initialization functions are used for booting uIP.
hudakz 3:5b17e4656dd0 183 */
hudakz 3:5b17e4656dd0 184 /**
hudakz 3:5b17e4656dd0 185 * uIP initialization function.
hudakz 3:5b17e4656dd0 186 *
hudakz 3:5b17e4656dd0 187 * This function should be called at boot up to initilize the uIP
hudakz 3:5b17e4656dd0 188 * TCP/IP stack.
hudakz 3:5b17e4656dd0 189 */
hudakz 3:5b17e4656dd0 190 void uip_init(void);
hudakz 3:5b17e4656dd0 191
hudakz 3:5b17e4656dd0 192 /**
hudakz 3:5b17e4656dd0 193 * uIP initialization function.
hudakz 3:5b17e4656dd0 194 *
hudakz 3:5b17e4656dd0 195 * This function may be used at boot time to set the initial ip_id.
hudakz 3:5b17e4656dd0 196 */
hudakz 3:5b17e4656dd0 197 void uip_setipid(u16_t id);
hudakz 3:5b17e4656dd0 198
hudakz 3:5b17e4656dd0 199 /** @} */
hudakz 3:5b17e4656dd0 200
hudakz 3:5b17e4656dd0 201 /**
hudakz 3:5b17e4656dd0 202 * \defgroup uipdevfunc uIP device driver functions
hudakz 3:5b17e4656dd0 203 * @{
hudakz 3:5b17e4656dd0 204 *
hudakz 3:5b17e4656dd0 205 * These functions are used by a network device driver for interacting
hudakz 3:5b17e4656dd0 206 * with uIP.
hudakz 3:5b17e4656dd0 207 */
hudakz 3:5b17e4656dd0 208
hudakz 3:5b17e4656dd0 209 /**
hudakz 3:5b17e4656dd0 210 * Process an incoming packet.
hudakz 3:5b17e4656dd0 211 *
hudakz 3:5b17e4656dd0 212 * This function should be called when the device driver has received
hudakz 3:5b17e4656dd0 213 * a packet from the network. The packet from the device driver must
hudakz 3:5b17e4656dd0 214 * be present in the uip_buf buffer, and the length of the packet
hudakz 3:5b17e4656dd0 215 * should be placed in the uip_len variable.
hudakz 3:5b17e4656dd0 216 *
hudakz 3:5b17e4656dd0 217 * When the function returns, there may be an outbound packet placed
hudakz 3:5b17e4656dd0 218 * in the uip_buf packet buffer. If so, the uip_len variable is set to
hudakz 3:5b17e4656dd0 219 * the length of the packet. If no packet is to be sent out, the
hudakz 3:5b17e4656dd0 220 * uip_len variable is set to 0.
hudakz 3:5b17e4656dd0 221 *
hudakz 3:5b17e4656dd0 222 * The usual way of calling the function is presented by the source
hudakz 3:5b17e4656dd0 223 * code below.
hudakz 3:5b17e4656dd0 224 \code
hudakz 3:5b17e4656dd0 225 uip_len = devicedriver_poll();
hudakz 3:5b17e4656dd0 226 if(uip_len > 0) {
hudakz 3:5b17e4656dd0 227 uip_input();
hudakz 3:5b17e4656dd0 228 if(uip_len > 0) {
hudakz 3:5b17e4656dd0 229 devicedriver_send();
hudakz 3:5b17e4656dd0 230 }
hudakz 3:5b17e4656dd0 231 }
hudakz 3:5b17e4656dd0 232 \endcode
hudakz 3:5b17e4656dd0 233 *
hudakz 3:5b17e4656dd0 234 * \note If you are writing a uIP device driver that needs ARP
hudakz 3:5b17e4656dd0 235 * (Address Resolution Protocol), e.g., when running uIP over
hudakz 3:5b17e4656dd0 236 * Ethernet, you will need to call the uIP ARP code before calling
hudakz 3:5b17e4656dd0 237 * this function:
hudakz 3:5b17e4656dd0 238 \code
hudakz 3:5b17e4656dd0 239 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
hudakz 3:5b17e4656dd0 240 uip_len = ethernet_devicedrver_poll();
hudakz 3:5b17e4656dd0 241 if(uip_len > 0) {
hudakz 3:5b17e4656dd0 242 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
hudakz 3:5b17e4656dd0 243 uip_arp_ipin();
hudakz 3:5b17e4656dd0 244 uip_input();
hudakz 3:5b17e4656dd0 245 if(uip_len > 0) {
hudakz 3:5b17e4656dd0 246 uip_arp_out();
hudakz 3:5b17e4656dd0 247 ethernet_devicedriver_send();
hudakz 3:5b17e4656dd0 248 }
hudakz 3:5b17e4656dd0 249 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
hudakz 3:5b17e4656dd0 250 uip_arp_arpin();
hudakz 3:5b17e4656dd0 251 if(uip_len > 0) {
hudakz 3:5b17e4656dd0 252 ethernet_devicedriver_send();
hudakz 3:5b17e4656dd0 253 }
hudakz 3:5b17e4656dd0 254 }
hudakz 3:5b17e4656dd0 255 \endcode
hudakz 3:5b17e4656dd0 256 *
hudakz 3:5b17e4656dd0 257 * \hideinitializer
hudakz 3:5b17e4656dd0 258 */
hudakz 3:5b17e4656dd0 259 #define uip_input() uip_process(UIP_DATA)
hudakz 3:5b17e4656dd0 260
hudakz 3:5b17e4656dd0 261 /**
hudakz 3:5b17e4656dd0 262 * Periodic processing for a connection identified by its number.
hudakz 3:5b17e4656dd0 263 *
hudakz 3:5b17e4656dd0 264 * This function does the necessary periodic processing (timers,
hudakz 3:5b17e4656dd0 265 * polling) for a uIP TCP conneciton, and should be called when the
hudakz 3:5b17e4656dd0 266 * periodic uIP timer goes off. It should be called for every
hudakz 3:5b17e4656dd0 267 * connection, regardless of whether they are open of closed.
hudakz 3:5b17e4656dd0 268 *
hudakz 3:5b17e4656dd0 269 * When the function returns, it may have an outbound packet waiting
hudakz 3:5b17e4656dd0 270 * for service in the uIP packet buffer, and if so the uip_len
hudakz 3:5b17e4656dd0 271 * variable is set to a value larger than zero. The device driver
hudakz 3:5b17e4656dd0 272 * should be called to send out the packet.
hudakz 3:5b17e4656dd0 273 *
hudakz 3:5b17e4656dd0 274 * The ususal way of calling the function is through a for() loop like
hudakz 3:5b17e4656dd0 275 * this:
hudakz 3:5b17e4656dd0 276 \code
hudakz 3:5b17e4656dd0 277 for(i = 0; i < UIP_CONNS; ++i) {
hudakz 3:5b17e4656dd0 278 uip_periodic(i);
hudakz 3:5b17e4656dd0 279 if(uip_len > 0) {
hudakz 3:5b17e4656dd0 280 devicedriver_send();
hudakz 3:5b17e4656dd0 281 }
hudakz 3:5b17e4656dd0 282 }
hudakz 3:5b17e4656dd0 283 \endcode
hudakz 3:5b17e4656dd0 284 *
hudakz 3:5b17e4656dd0 285 * \note If you are writing a uIP device driver that needs ARP
hudakz 3:5b17e4656dd0 286 * (Address Resolution Protocol), e.g., when running uIP over
hudakz 3:5b17e4656dd0 287 * Ethernet, you will need to call the uip_arp_out() function before
hudakz 3:5b17e4656dd0 288 * calling the device driver:
hudakz 3:5b17e4656dd0 289 \code
hudakz 3:5b17e4656dd0 290 for(i = 0; i < UIP_CONNS; ++i) {
hudakz 3:5b17e4656dd0 291 uip_periodic(i);
hudakz 3:5b17e4656dd0 292 if(uip_len > 0) {
hudakz 3:5b17e4656dd0 293 uip_arp_out();
hudakz 3:5b17e4656dd0 294 ethernet_devicedriver_send();
hudakz 3:5b17e4656dd0 295 }
hudakz 3:5b17e4656dd0 296 }
hudakz 3:5b17e4656dd0 297 \endcode
hudakz 3:5b17e4656dd0 298 *
hudakz 3:5b17e4656dd0 299 * \param conn The number of the connection which is to be periodically polled.
hudakz 3:5b17e4656dd0 300 *
hudakz 3:5b17e4656dd0 301 * \hideinitializer
hudakz 3:5b17e4656dd0 302 */
hudakz 3:5b17e4656dd0 303
hudakz 3:5b17e4656dd0 304 #define uip_periodic(conn) \
hudakz 3:5b17e4656dd0 305 do \
hudakz 3:5b17e4656dd0 306 { \
hudakz 3:5b17e4656dd0 307 uip_conn = &uip_conns[conn]; \
hudakz 3:5b17e4656dd0 308 uip_process(UIP_TIMER); \
hudakz 3:5b17e4656dd0 309 } while(0)
hudakz 3:5b17e4656dd0 310
hudakz 3:5b17e4656dd0 311 /**
hudakz 3:5b17e4656dd0 312 *
hudakz 3:5b17e4656dd0 313 *
hudakz 3:5b17e4656dd0 314 */
hudakz 3:5b17e4656dd0 315
hudakz 3:5b17e4656dd0 316 #define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED)
hudakz 3:5b17e4656dd0 317
hudakz 3:5b17e4656dd0 318 /**
hudakz 3:5b17e4656dd0 319 * Perform periodic processing for a connection identified by a pointer
hudakz 3:5b17e4656dd0 320 * to its structure.
hudakz 3:5b17e4656dd0 321 *
hudakz 3:5b17e4656dd0 322 * Same as uip_periodic() but takes a pointer to the actual uip_conn
hudakz 3:5b17e4656dd0 323 * struct instead of an integer as its argument. This function can be
hudakz 3:5b17e4656dd0 324 * used to force periodic processing of a specific connection.
hudakz 3:5b17e4656dd0 325 *
hudakz 3:5b17e4656dd0 326 * \param conn A pointer to the uip_conn struct for the connection to
hudakz 3:5b17e4656dd0 327 * be processed.
hudakz 3:5b17e4656dd0 328 *
hudakz 3:5b17e4656dd0 329 * \hideinitializer
hudakz 3:5b17e4656dd0 330 */
hudakz 3:5b17e4656dd0 331
hudakz 3:5b17e4656dd0 332 #define uip_periodic_conn(conn) \
hudakz 3:5b17e4656dd0 333 do \
hudakz 3:5b17e4656dd0 334 { \
hudakz 3:5b17e4656dd0 335 uip_conn = conn; \
hudakz 3:5b17e4656dd0 336 uip_process(UIP_TIMER); \
hudakz 3:5b17e4656dd0 337 } while(0)
hudakz 3:5b17e4656dd0 338
hudakz 3:5b17e4656dd0 339 /**
hudakz 3:5b17e4656dd0 340 * Reuqest that a particular connection should be polled.
hudakz 3:5b17e4656dd0 341 *
hudakz 3:5b17e4656dd0 342 * Similar to uip_periodic_conn() but does not perform any timer
hudakz 3:5b17e4656dd0 343 * processing. The application is polled for new data.
hudakz 3:5b17e4656dd0 344 *
hudakz 3:5b17e4656dd0 345 * \param conn A pointer to the uip_conn struct for the connection to
hudakz 3:5b17e4656dd0 346 * be processed.
hudakz 3:5b17e4656dd0 347 *
hudakz 3:5b17e4656dd0 348 * \hideinitializer
hudakz 3:5b17e4656dd0 349 */
hudakz 3:5b17e4656dd0 350
hudakz 3:5b17e4656dd0 351 #define uip_poll_conn(conn) \
hudakz 3:5b17e4656dd0 352 do \
hudakz 3:5b17e4656dd0 353 { \
hudakz 3:5b17e4656dd0 354 uip_conn = conn; \
hudakz 3:5b17e4656dd0 355 uip_process(UIP_POLL_REQUEST); \
hudakz 3:5b17e4656dd0 356 } while(0)
hudakz 3:5b17e4656dd0 357 #if UIP_UDP
hudakz 3:5b17e4656dd0 358
hudakz 3:5b17e4656dd0 359 /**
hudakz 3:5b17e4656dd0 360 * Periodic processing for a UDP connection identified by its number.
hudakz 3:5b17e4656dd0 361 *
hudakz 3:5b17e4656dd0 362 * This function is essentially the same as uip_periodic(), but for
hudakz 3:5b17e4656dd0 363 * UDP connections. It is called in a similar fashion as the
hudakz 3:5b17e4656dd0 364 * uip_periodic() function:
hudakz 3:5b17e4656dd0 365 \code
hudakz 3:5b17e4656dd0 366 for(i = 0; i < UIP_UDP_CONNS; i++) {
hudakz 3:5b17e4656dd0 367 uip_udp_periodic(i);
hudakz 3:5b17e4656dd0 368 if(uip_len > 0) {
hudakz 3:5b17e4656dd0 369 devicedriver_send();
hudakz 3:5b17e4656dd0 370 }
hudakz 3:5b17e4656dd0 371 }
hudakz 3:5b17e4656dd0 372 \endcode
hudakz 3:5b17e4656dd0 373 *
hudakz 3:5b17e4656dd0 374 * \note As for the uip_periodic() function, special care has to be
hudakz 3:5b17e4656dd0 375 * taken when using uIP together with ARP and Ethernet:
hudakz 3:5b17e4656dd0 376 \code
hudakz 3:5b17e4656dd0 377 for(i = 0; i < UIP_UDP_CONNS; i++) {
hudakz 3:5b17e4656dd0 378 uip_udp_periodic(i);
hudakz 3:5b17e4656dd0 379 if(uip_len > 0) {
hudakz 3:5b17e4656dd0 380 uip_arp_out();
hudakz 3:5b17e4656dd0 381 ethernet_devicedriver_send();
hudakz 3:5b17e4656dd0 382 }
hudakz 3:5b17e4656dd0 383 }
hudakz 3:5b17e4656dd0 384 \endcode
hudakz 3:5b17e4656dd0 385 *
hudakz 3:5b17e4656dd0 386 * \param conn The number of the UDP connection to be processed.
hudakz 3:5b17e4656dd0 387 *
hudakz 3:5b17e4656dd0 388 * \hideinitializer
hudakz 3:5b17e4656dd0 389 */
hudakz 3:5b17e4656dd0 390
hudakz 3:5b17e4656dd0 391 #define uip_udp_periodic(conn) \
hudakz 3:5b17e4656dd0 392 do \
hudakz 3:5b17e4656dd0 393 { \
hudakz 3:5b17e4656dd0 394 uip_udp_conn = &uip_udp_conns[conn]; \
hudakz 3:5b17e4656dd0 395 uip_process(UIP_UDP_TIMER); \
hudakz 3:5b17e4656dd0 396 } while(0)
hudakz 3:5b17e4656dd0 397
hudakz 3:5b17e4656dd0 398 /**
hudakz 3:5b17e4656dd0 399 * Periodic processing for a UDP connection identified by a pointer to
hudakz 3:5b17e4656dd0 400 * its structure.
hudakz 3:5b17e4656dd0 401 *
hudakz 3:5b17e4656dd0 402 * Same as uip_udp_periodic() but takes a pointer to the actual
hudakz 3:5b17e4656dd0 403 * uip_conn struct instead of an integer as its argument. This
hudakz 3:5b17e4656dd0 404 * function can be used to force periodic processing of a specific
hudakz 3:5b17e4656dd0 405 * connection.
hudakz 3:5b17e4656dd0 406 *
hudakz 3:5b17e4656dd0 407 * \param conn A pointer to the uip_udp_conn struct for the connection
hudakz 3:5b17e4656dd0 408 * to be processed.
hudakz 3:5b17e4656dd0 409 *
hudakz 3:5b17e4656dd0 410 * \hideinitializer
hudakz 3:5b17e4656dd0 411 */
hudakz 3:5b17e4656dd0 412
hudakz 3:5b17e4656dd0 413 #define uip_udp_periodic_conn(conn) \
hudakz 3:5b17e4656dd0 414 do \
hudakz 3:5b17e4656dd0 415 { \
hudakz 3:5b17e4656dd0 416 uip_udp_conn = conn; \
hudakz 3:5b17e4656dd0 417 uip_process(UIP_UDP_TIMER); \
hudakz 3:5b17e4656dd0 418 } while(0)
hudakz 3:5b17e4656dd0 419 #endif /* UIP_UDP */
hudakz 3:5b17e4656dd0 420
hudakz 3:5b17e4656dd0 421 /**
hudakz 3:5b17e4656dd0 422 * The uIP packet buffer.
hudakz 3:5b17e4656dd0 423 *
hudakz 3:5b17e4656dd0 424 * The uip_buf array is used to hold incoming and outgoing
hudakz 3:5b17e4656dd0 425 * packets. The device driver should place incoming data into this
hudakz 3:5b17e4656dd0 426 * buffer. When sending data, the device driver should read the link
hudakz 3:5b17e4656dd0 427 * level headers and the TCP/IP headers from this buffer. The size of
hudakz 3:5b17e4656dd0 428 * the link level headers is configured by the UIP_LLH_LEN define.
hudakz 3:5b17e4656dd0 429 *
hudakz 3:5b17e4656dd0 430 * \note The application data need not be placed in this buffer, so
hudakz 3:5b17e4656dd0 431 * the device driver must read it from the place pointed to by the
hudakz 3:5b17e4656dd0 432 * uip_appdata pointer as illustrated by the following example:
hudakz 3:5b17e4656dd0 433 \code
hudakz 3:5b17e4656dd0 434 void
hudakz 3:5b17e4656dd0 435 devicedriver_send(void)
hudakz 3:5b17e4656dd0 436 {
hudakz 3:5b17e4656dd0 437 hwsend(&uip_buf[0], UIP_LLH_LEN);
hudakz 3:5b17e4656dd0 438 if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
hudakz 3:5b17e4656dd0 439 hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
hudakz 3:5b17e4656dd0 440 } else {
hudakz 3:5b17e4656dd0 441 hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
hudakz 3:5b17e4656dd0 442 hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
hudakz 3:5b17e4656dd0 443 }
hudakz 3:5b17e4656dd0 444 }
hudakz 3:5b17e4656dd0 445 \endcode
hudakz 3:5b17e4656dd0 446 */
hudakz 3:5b17e4656dd0 447 extern u8_t uip_buf[UIP_BUFSIZE + 2];
hudakz 3:5b17e4656dd0 448
hudakz 3:5b17e4656dd0 449 /** @} */
hudakz 3:5b17e4656dd0 450
hudakz 3:5b17e4656dd0 451 /*---------------------------------------------------------------------------*/
hudakz 3:5b17e4656dd0 452 /* Functions that are used by the uIP application program. Opening and
hudakz 3:5b17e4656dd0 453 * closing connections, sending and receiving data, etc. is all
hudakz 3:5b17e4656dd0 454 * handled by the functions below.
hudakz 3:5b17e4656dd0 455 */
hudakz 3:5b17e4656dd0 456 /**
hudakz 3:5b17e4656dd0 457 * \defgroup uipappfunc uIP application functions
hudakz 3:5b17e4656dd0 458 * @{
hudakz 3:5b17e4656dd0 459 *
hudakz 3:5b17e4656dd0 460 * Functions used by an application running of top of uIP.
hudakz 3:5b17e4656dd0 461 */
hudakz 3:5b17e4656dd0 462 /**
hudakz 3:5b17e4656dd0 463 * Start listening to the specified port.
hudakz 3:5b17e4656dd0 464 *
hudakz 3:5b17e4656dd0 465 * \note Since this function expects the port number in network byte
hudakz 3:5b17e4656dd0 466 * order, a conversion using HTONS() or htons() is necessary.
hudakz 3:5b17e4656dd0 467 *
hudakz 3:5b17e4656dd0 468 \code
hudakz 3:5b17e4656dd0 469 uip_listen(HTONS(80));
hudakz 3:5b17e4656dd0 470 \endcode
hudakz 3:5b17e4656dd0 471 *
hudakz 3:5b17e4656dd0 472 * \param port A 16-bit port number in network byte order.
hudakz 3:5b17e4656dd0 473 */
hudakz 3:5b17e4656dd0 474 void uip_listen(u16_t port);
hudakz 3:5b17e4656dd0 475
hudakz 3:5b17e4656dd0 476 /**
hudakz 3:5b17e4656dd0 477 * Stop listening to the specified port.
hudakz 3:5b17e4656dd0 478 *
hudakz 3:5b17e4656dd0 479 * \note Since this function expects the port number in network byte
hudakz 3:5b17e4656dd0 480 * order, a conversion using HTONS() or htons() is necessary.
hudakz 3:5b17e4656dd0 481 *
hudakz 3:5b17e4656dd0 482 \code
hudakz 3:5b17e4656dd0 483 uip_unlisten(HTONS(80));
hudakz 3:5b17e4656dd0 484 \endcode
hudakz 3:5b17e4656dd0 485 *
hudakz 3:5b17e4656dd0 486 * \param port A 16-bit port number in network byte order.
hudakz 3:5b17e4656dd0 487 */
hudakz 3:5b17e4656dd0 488 void uip_unlisten(u16_t port);
hudakz 3:5b17e4656dd0 489
hudakz 3:5b17e4656dd0 490 /**
hudakz 3:5b17e4656dd0 491 * Connect to a remote host using TCP.
hudakz 3:5b17e4656dd0 492 *
hudakz 3:5b17e4656dd0 493 * This function is used to start a new connection to the specified
hudakz 3:5b17e4656dd0 494 * port on the specied host. It allocates a new connection identifier,
hudakz 3:5b17e4656dd0 495 * sets the connection to the SYN_SENT state and sets the
hudakz 3:5b17e4656dd0 496 * retransmission timer to 0. This will cause a TCP SYN segment to be
hudakz 3:5b17e4656dd0 497 * sent out the next time this connection is periodically processed,
hudakz 3:5b17e4656dd0 498 * which usually is done within 0.5 seconds after the call to
hudakz 3:5b17e4656dd0 499 * uip_connect().
hudakz 3:5b17e4656dd0 500 *
hudakz 3:5b17e4656dd0 501 * \note This function is avaliable only if support for active open
hudakz 3:5b17e4656dd0 502 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
hudakz 3:5b17e4656dd0 503 *
hudakz 3:5b17e4656dd0 504 * \note Since this function requires the port number to be in network
hudakz 3:5b17e4656dd0 505 * byte order, a conversion using HTONS() or htons() is necessary.
hudakz 3:5b17e4656dd0 506 *
hudakz 3:5b17e4656dd0 507 \code
hudakz 3:5b17e4656dd0 508 uip_ipaddr_t ipaddr;
hudakz 3:5b17e4656dd0 509
hudakz 3:5b17e4656dd0 510 uip_ipaddr(&ipaddr, 192,168,1,2);
hudakz 3:5b17e4656dd0 511 uip_connect(&ipaddr, HTONS(80));
hudakz 3:5b17e4656dd0 512 \endcode
hudakz 3:5b17e4656dd0 513 *
hudakz 3:5b17e4656dd0 514 * \param ripaddr The IP address of the remote hot.
hudakz 3:5b17e4656dd0 515 *
hudakz 3:5b17e4656dd0 516 * \param port A 16-bit port number in network byte order.
hudakz 3:5b17e4656dd0 517 *
hudakz 3:5b17e4656dd0 518 * \return A pointer to the uIP connection identifier for the new connection,
hudakz 3:5b17e4656dd0 519 * or NULL if no connection could be allocated.
hudakz 3:5b17e4656dd0 520 *
hudakz 3:5b17e4656dd0 521 */
hudakz 3:5b17e4656dd0 522 struct uip_conn* uip_connect(uip_ipaddr_t* ripaddr, u16_t port);
hudakz 3:5b17e4656dd0 523
hudakz 3:5b17e4656dd0 524 /**
hudakz 3:5b17e4656dd0 525 * \internal
hudakz 3:5b17e4656dd0 526 *
hudakz 3:5b17e4656dd0 527 * Check if a connection has outstanding (i.e., unacknowledged) data.
hudakz 3:5b17e4656dd0 528 *
hudakz 3:5b17e4656dd0 529 * \param conn A pointer to the uip_conn structure for the connection.
hudakz 3:5b17e4656dd0 530 *
hudakz 3:5b17e4656dd0 531 * \hideinitializer
hudakz 3:5b17e4656dd0 532 */
hudakz 3:5b17e4656dd0 533
hudakz 3:5b17e4656dd0 534 #define uip_outstanding(conn) ((conn)->len)
hudakz 3:5b17e4656dd0 535
hudakz 3:5b17e4656dd0 536 /**
hudakz 3:5b17e4656dd0 537 * Send data on the current connection.
hudakz 3:5b17e4656dd0 538 *
hudakz 3:5b17e4656dd0 539 * This function is used to send out a single segment of TCP
hudakz 3:5b17e4656dd0 540 * data. Only applications that have been invoked by uIP for event
hudakz 3:5b17e4656dd0 541 * processing can send data.
hudakz 3:5b17e4656dd0 542 *
hudakz 3:5b17e4656dd0 543 * The amount of data that actually is sent out after a call to this
hudakz 3:5b17e4656dd0 544 * funcion is determined by the maximum amount of data TCP allows. uIP
hudakz 3:5b17e4656dd0 545 * will automatically crop the data so that only the appropriate
hudakz 3:5b17e4656dd0 546 * amount of data is sent. The function uip_mss() can be used to query
hudakz 3:5b17e4656dd0 547 * uIP for the amount of data that actually will be sent.
hudakz 3:5b17e4656dd0 548 *
hudakz 3:5b17e4656dd0 549 * \note This function does not guarantee that the sent data will
hudakz 3:5b17e4656dd0 550 * arrive at the destination. If the data is lost in the network, the
hudakz 3:5b17e4656dd0 551 * application will be invoked with the uip_rexmit() event being
hudakz 3:5b17e4656dd0 552 * set. The application will then have to resend the data using this
hudakz 3:5b17e4656dd0 553 * function.
hudakz 3:5b17e4656dd0 554 *
hudakz 3:5b17e4656dd0 555 * \param data A pointer to the data which is to be sent.
hudakz 3:5b17e4656dd0 556 *
hudakz 3:5b17e4656dd0 557 * \param len The maximum amount of data bytes to be sent.
hudakz 3:5b17e4656dd0 558 *
hudakz 3:5b17e4656dd0 559 * \hideinitializer
hudakz 3:5b17e4656dd0 560 */
hudakz 3:5b17e4656dd0 561 void uip_send(const void* data, int len);
hudakz 3:5b17e4656dd0 562
hudakz 3:5b17e4656dd0 563 /**
hudakz 3:5b17e4656dd0 564 * The length of any incoming data that is currently avaliable (if avaliable)
hudakz 3:5b17e4656dd0 565 * in the uip_appdata buffer.
hudakz 3:5b17e4656dd0 566 *
hudakz 3:5b17e4656dd0 567 * The test function uip_data() must first be used to check if there
hudakz 3:5b17e4656dd0 568 * is any data available at all.
hudakz 3:5b17e4656dd0 569 *
hudakz 3:5b17e4656dd0 570 * \hideinitializer
hudakz 3:5b17e4656dd0 571 */
hudakz 3:5b17e4656dd0 572
hudakz 3:5b17e4656dd0 573 /*void uip_datalen(void);*/
hudakz 3:5b17e4656dd0 574 #define uip_datalen() uip_len
hudakz 3:5b17e4656dd0 575
hudakz 3:5b17e4656dd0 576 /**
hudakz 3:5b17e4656dd0 577 * The length of any out-of-band data (urgent data) that has arrived
hudakz 3:5b17e4656dd0 578 * on the connection.
hudakz 3:5b17e4656dd0 579 *
hudakz 3:5b17e4656dd0 580 * \note The configuration parameter UIP_URGDATA must be set for this
hudakz 3:5b17e4656dd0 581 * function to be enabled.
hudakz 3:5b17e4656dd0 582 *
hudakz 3:5b17e4656dd0 583 * \hideinitializer
hudakz 3:5b17e4656dd0 584 */
hudakz 3:5b17e4656dd0 585
hudakz 3:5b17e4656dd0 586 #define uip_urgdatalen() uip_urglen
hudakz 3:5b17e4656dd0 587
hudakz 3:5b17e4656dd0 588 /**
hudakz 3:5b17e4656dd0 589 * Close the current connection.
hudakz 3:5b17e4656dd0 590 *
hudakz 3:5b17e4656dd0 591 * This function will close the current connection in a nice way.
hudakz 3:5b17e4656dd0 592 *
hudakz 3:5b17e4656dd0 593 * \hideinitializer
hudakz 3:5b17e4656dd0 594 */
hudakz 3:5b17e4656dd0 595
hudakz 3:5b17e4656dd0 596 #define uip_close() (uip_flags = UIP_CLOSE)
hudakz 3:5b17e4656dd0 597
hudakz 3:5b17e4656dd0 598 /**
hudakz 3:5b17e4656dd0 599 * Abort the current connection.
hudakz 3:5b17e4656dd0 600 *
hudakz 3:5b17e4656dd0 601 * This function will abort (reset) the current connection, and is
hudakz 3:5b17e4656dd0 602 * usually used when an error has occured that prevents using the
hudakz 3:5b17e4656dd0 603 * uip_close() function.
hudakz 3:5b17e4656dd0 604 *
hudakz 3:5b17e4656dd0 605 * \hideinitializer
hudakz 3:5b17e4656dd0 606 */
hudakz 3:5b17e4656dd0 607
hudakz 3:5b17e4656dd0 608 #define uip_abort() (uip_flags = UIP_ABORT)
hudakz 3:5b17e4656dd0 609
hudakz 3:5b17e4656dd0 610 /**
hudakz 3:5b17e4656dd0 611 * Tell the sending host to stop sending data.
hudakz 3:5b17e4656dd0 612 *
hudakz 3:5b17e4656dd0 613 * This function will close our receiver's window so that we stop
hudakz 3:5b17e4656dd0 614 * receiving data for the current connection.
hudakz 3:5b17e4656dd0 615 *
hudakz 3:5b17e4656dd0 616 * \hideinitializer
hudakz 3:5b17e4656dd0 617 */
hudakz 3:5b17e4656dd0 618
hudakz 3:5b17e4656dd0 619 #define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)
hudakz 3:5b17e4656dd0 620
hudakz 3:5b17e4656dd0 621 /**
hudakz 3:5b17e4656dd0 622 * Find out if the current connection has been previously stopped with
hudakz 3:5b17e4656dd0 623 * uip_stop().
hudakz 3:5b17e4656dd0 624 *
hudakz 3:5b17e4656dd0 625 * \hideinitializer
hudakz 3:5b17e4656dd0 626 */
hudakz 3:5b17e4656dd0 627
hudakz 3:5b17e4656dd0 628 #define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED)
hudakz 3:5b17e4656dd0 629
hudakz 3:5b17e4656dd0 630 /**
hudakz 3:5b17e4656dd0 631 * Restart the current connection, if is has previously been stopped
hudakz 3:5b17e4656dd0 632 * with uip_stop().
hudakz 3:5b17e4656dd0 633 *
hudakz 3:5b17e4656dd0 634 * This function will open the receiver's window again so that we
hudakz 3:5b17e4656dd0 635 * start receiving data for the current connection.
hudakz 3:5b17e4656dd0 636 *
hudakz 3:5b17e4656dd0 637 * \hideinitializer
hudakz 3:5b17e4656dd0 638 */
hudakz 3:5b17e4656dd0 639
hudakz 3:5b17e4656dd0 640 #define uip_restart() \
hudakz 3:5b17e4656dd0 641 do \
hudakz 3:5b17e4656dd0 642 { \
hudakz 3:5b17e4656dd0 643 uip_flags |= UIP_NEWDATA; \
hudakz 3:5b17e4656dd0 644 uip_conn->tcpstateflags &= ~UIP_STOPPED; \
hudakz 3:5b17e4656dd0 645 } while(0)
hudakz 3:5b17e4656dd0 646
hudakz 3:5b17e4656dd0 647 /* uIP tests that can be made to determine in what state the current
hudakz 3:5b17e4656dd0 648 connection is, and what the application function should do. */
hudakz 3:5b17e4656dd0 649
hudakz 3:5b17e4656dd0 650 /**
hudakz 3:5b17e4656dd0 651 * Is the current connection a UDP connection?
hudakz 3:5b17e4656dd0 652 *
hudakz 3:5b17e4656dd0 653 * This function checks whether the current connection is a UDP connection.
hudakz 3:5b17e4656dd0 654 *
hudakz 3:5b17e4656dd0 655 * \hideinitializer
hudakz 3:5b17e4656dd0 656 *
hudakz 3:5b17e4656dd0 657 */
hudakz 3:5b17e4656dd0 658 #define uip_udpconnection() (uip_conn == NULL)
hudakz 3:5b17e4656dd0 659
hudakz 3:5b17e4656dd0 660 /**
hudakz 3:5b17e4656dd0 661 * Is new incoming data available?
hudakz 3:5b17e4656dd0 662 *
hudakz 3:5b17e4656dd0 663 * Will reduce to non-zero if there is new data for the application
hudakz 3:5b17e4656dd0 664 * present at the uip_appdata pointer. The size of the data is
hudakz 3:5b17e4656dd0 665 * avaliable through the uip_len variable.
hudakz 3:5b17e4656dd0 666 *
hudakz 3:5b17e4656dd0 667 * \hideinitializer
hudakz 3:5b17e4656dd0 668 */
hudakz 3:5b17e4656dd0 669
hudakz 3:5b17e4656dd0 670 #define uip_newdata() (uip_flags & UIP_NEWDATA)
hudakz 3:5b17e4656dd0 671
hudakz 3:5b17e4656dd0 672 /**
hudakz 3:5b17e4656dd0 673 * Has previously sent data been acknowledged?
hudakz 3:5b17e4656dd0 674 *
hudakz 3:5b17e4656dd0 675 * Will reduce to non-zero if the previously sent data has been
hudakz 3:5b17e4656dd0 676 * acknowledged by the remote host. This means that the application
hudakz 3:5b17e4656dd0 677 * can send new data.
hudakz 3:5b17e4656dd0 678 *
hudakz 3:5b17e4656dd0 679 * \hideinitializer
hudakz 3:5b17e4656dd0 680 */
hudakz 3:5b17e4656dd0 681
hudakz 3:5b17e4656dd0 682 #define uip_acked() (uip_flags & UIP_ACKDATA)
hudakz 3:5b17e4656dd0 683
hudakz 3:5b17e4656dd0 684 /**
hudakz 3:5b17e4656dd0 685 * Has the connection just been connected?
hudakz 3:5b17e4656dd0 686 *
hudakz 3:5b17e4656dd0 687 * Reduces to non-zero if the current connection has been connected to
hudakz 3:5b17e4656dd0 688 * a remote host. This will happen both if the connection has been
hudakz 3:5b17e4656dd0 689 * actively opened (with uip_connect()) or passively opened (with
hudakz 3:5b17e4656dd0 690 * uip_listen()).
hudakz 3:5b17e4656dd0 691 *
hudakz 3:5b17e4656dd0 692 * \hideinitializer
hudakz 3:5b17e4656dd0 693 */
hudakz 3:5b17e4656dd0 694
hudakz 3:5b17e4656dd0 695 #define uip_connected() (uip_flags & UIP_CONNECTED)
hudakz 3:5b17e4656dd0 696
hudakz 3:5b17e4656dd0 697 /**
hudakz 3:5b17e4656dd0 698 * Has the connection been closed by the other end?
hudakz 3:5b17e4656dd0 699 *
hudakz 3:5b17e4656dd0 700 * Is non-zero if the connection has been closed by the remote
hudakz 3:5b17e4656dd0 701 * host. The application may then do the necessary clean-ups.
hudakz 3:5b17e4656dd0 702 *
hudakz 3:5b17e4656dd0 703 * \hideinitializer
hudakz 3:5b17e4656dd0 704 */
hudakz 3:5b17e4656dd0 705
hudakz 3:5b17e4656dd0 706 #define uip_closed() (uip_flags & UIP_CLOSE)
hudakz 3:5b17e4656dd0 707
hudakz 3:5b17e4656dd0 708 /**
hudakz 3:5b17e4656dd0 709 * Has the connection been aborted by the other end?
hudakz 3:5b17e4656dd0 710 *
hudakz 3:5b17e4656dd0 711 * Non-zero if the current connection has been aborted (reset) by the
hudakz 3:5b17e4656dd0 712 * remote host.
hudakz 3:5b17e4656dd0 713 *
hudakz 3:5b17e4656dd0 714 * \hideinitializer
hudakz 3:5b17e4656dd0 715 */
hudakz 3:5b17e4656dd0 716
hudakz 3:5b17e4656dd0 717 #define uip_aborted() (uip_flags & UIP_ABORT)
hudakz 3:5b17e4656dd0 718
hudakz 3:5b17e4656dd0 719 /**
hudakz 3:5b17e4656dd0 720 * Has the connection timed out?
hudakz 3:5b17e4656dd0 721 *
hudakz 3:5b17e4656dd0 722 * Non-zero if the current connection has been aborted due to too many
hudakz 3:5b17e4656dd0 723 * retransmissions.
hudakz 3:5b17e4656dd0 724 *
hudakz 3:5b17e4656dd0 725 * \hideinitializer
hudakz 3:5b17e4656dd0 726 */
hudakz 3:5b17e4656dd0 727
hudakz 3:5b17e4656dd0 728 #define uip_timedout() (uip_flags & UIP_TIMEDOUT)
hudakz 3:5b17e4656dd0 729
hudakz 3:5b17e4656dd0 730 /**
hudakz 3:5b17e4656dd0 731 * Do we need to retransmit previously data?
hudakz 3:5b17e4656dd0 732 *
hudakz 3:5b17e4656dd0 733 * Reduces to non-zero if the previously sent data has been lost in
hudakz 3:5b17e4656dd0 734 * the network, and the application should retransmit it. The
hudakz 3:5b17e4656dd0 735 * application should send the exact same data as it did the last
hudakz 3:5b17e4656dd0 736 * time, using the uip_send() function.
hudakz 3:5b17e4656dd0 737 *
hudakz 3:5b17e4656dd0 738 * \hideinitializer
hudakz 3:5b17e4656dd0 739 */
hudakz 3:5b17e4656dd0 740
hudakz 3:5b17e4656dd0 741 #define uip_rexmit() (uip_flags & UIP_REXMIT)
hudakz 3:5b17e4656dd0 742
hudakz 3:5b17e4656dd0 743 /**
hudakz 3:5b17e4656dd0 744 * Is the connection being polled by uIP?
hudakz 3:5b17e4656dd0 745 *
hudakz 3:5b17e4656dd0 746 * Is non-zero if the reason the application is invoked is that the
hudakz 3:5b17e4656dd0 747 * current connection has been idle for a while and should be
hudakz 3:5b17e4656dd0 748 * polled.
hudakz 3:5b17e4656dd0 749 *
hudakz 3:5b17e4656dd0 750 * The polling event can be used for sending data without having to
hudakz 3:5b17e4656dd0 751 * wait for the remote host to send data.
hudakz 3:5b17e4656dd0 752 *
hudakz 3:5b17e4656dd0 753 * \hideinitializer
hudakz 3:5b17e4656dd0 754 */
hudakz 3:5b17e4656dd0 755
hudakz 3:5b17e4656dd0 756 #define uip_poll() (uip_flags & UIP_POLL)
hudakz 3:5b17e4656dd0 757
hudakz 3:5b17e4656dd0 758 /**
hudakz 3:5b17e4656dd0 759 * Get the initial maxium segment size (MSS) of the current
hudakz 3:5b17e4656dd0 760 * connection.
hudakz 3:5b17e4656dd0 761 *
hudakz 3:5b17e4656dd0 762 * \hideinitializer
hudakz 3:5b17e4656dd0 763 */
hudakz 3:5b17e4656dd0 764
hudakz 3:5b17e4656dd0 765 #define uip_initialmss() (uip_conn->initialmss)
hudakz 3:5b17e4656dd0 766
hudakz 3:5b17e4656dd0 767 /**
hudakz 3:5b17e4656dd0 768 * Get the current maxium segment size that can be sent on the current
hudakz 3:5b17e4656dd0 769 * connection.
hudakz 3:5b17e4656dd0 770 *
hudakz 3:5b17e4656dd0 771 * The current maxiumum segment size that can be sent on the
hudakz 3:5b17e4656dd0 772 * connection is computed from the receiver's window and the MSS of
hudakz 3:5b17e4656dd0 773 * the connection (which also is available by calling
hudakz 3:5b17e4656dd0 774 * uip_initialmss()).
hudakz 3:5b17e4656dd0 775 *
hudakz 3:5b17e4656dd0 776 * \hideinitializer
hudakz 3:5b17e4656dd0 777 */
hudakz 3:5b17e4656dd0 778
hudakz 3:5b17e4656dd0 779 #define uip_mss() (uip_conn->mss)
hudakz 3:5b17e4656dd0 780 /**
hudakz 3:5b17e4656dd0 781 * Set up a new UDP connection.
hudakz 3:5b17e4656dd0 782 *
hudakz 3:5b17e4656dd0 783 * This function sets up a new UDP connection. The function will
hudakz 3:5b17e4656dd0 784 * automatically allocate an unused local port for the new
hudakz 3:5b17e4656dd0 785 * connection. However, another port can be chosen by using the
hudakz 3:5b17e4656dd0 786 * uip_udp_bind() call, after the uip_udp_new() function has been
hudakz 3:5b17e4656dd0 787 * called.
hudakz 3:5b17e4656dd0 788 *
hudakz 3:5b17e4656dd0 789 * Example:
hudakz 3:5b17e4656dd0 790 \code
hudakz 3:5b17e4656dd0 791 uip_ipaddr_t addr;
hudakz 3:5b17e4656dd0 792 struct uip_udp_conn *c;
hudakz 3:5b17e4656dd0 793
hudakz 3:5b17e4656dd0 794 uip_ipaddr(&addr, 192,168,2,1);
hudakz 3:5b17e4656dd0 795 c = uip_udp_new(&addr, HTONS(12345));
hudakz 3:5b17e4656dd0 796 if(c != NULL) {
hudakz 3:5b17e4656dd0 797 uip_udp_bind(c, HTONS(12344));
hudakz 3:5b17e4656dd0 798 }
hudakz 3:5b17e4656dd0 799 \endcode
hudakz 3:5b17e4656dd0 800 * \param ripaddr The IP address of the remote host.
hudakz 3:5b17e4656dd0 801 *
hudakz 3:5b17e4656dd0 802 * \param rport The remote port number in network byte order.
hudakz 3:5b17e4656dd0 803 *
hudakz 3:5b17e4656dd0 804 * \return The uip_udp_conn structure for the new connection or NULL
hudakz 3:5b17e4656dd0 805 * if no connection could be allocated.
hudakz 3:5b17e4656dd0 806 */
hudakz 3:5b17e4656dd0 807 struct uip_udp_conn* uip_udp_new(uip_ipaddr_t* ripaddr, u16_t rport);
hudakz 3:5b17e4656dd0 808
hudakz 3:5b17e4656dd0 809 /**
hudakz 3:5b17e4656dd0 810 * Removed a UDP connection.
hudakz 3:5b17e4656dd0 811 *
hudakz 3:5b17e4656dd0 812 * \param conn A pointer to the uip_udp_conn structure for the connection.
hudakz 3:5b17e4656dd0 813 *
hudakz 3:5b17e4656dd0 814 * \hideinitializer
hudakz 3:5b17e4656dd0 815 */
hudakz 3:5b17e4656dd0 816
hudakz 3:5b17e4656dd0 817 #define uip_udp_remove(conn) (conn)->lport = 0
hudakz 3:5b17e4656dd0 818
hudakz 3:5b17e4656dd0 819 /**
hudakz 3:5b17e4656dd0 820 * Bind a UDP connection to a local port.
hudakz 3:5b17e4656dd0 821 *
hudakz 3:5b17e4656dd0 822 * \param conn A pointer to the uip_udp_conn structure for the
hudakz 3:5b17e4656dd0 823 * connection.
hudakz 3:5b17e4656dd0 824 *
hudakz 3:5b17e4656dd0 825 * \param port The local port number, in network byte order.
hudakz 3:5b17e4656dd0 826 *
hudakz 3:5b17e4656dd0 827 * \hideinitializer
hudakz 3:5b17e4656dd0 828 */
hudakz 3:5b17e4656dd0 829
hudakz 3:5b17e4656dd0 830 #define uip_udp_bind(conn, port) (conn)->lport = port
hudakz 3:5b17e4656dd0 831
hudakz 3:5b17e4656dd0 832 /**
hudakz 3:5b17e4656dd0 833 * Send a UDP datagram of length len on the current connection.
hudakz 3:5b17e4656dd0 834 *
hudakz 3:5b17e4656dd0 835 * This function can only be called in response to a UDP event (poll
hudakz 3:5b17e4656dd0 836 * or newdata). The data must be present in the uip_buf buffer, at the
hudakz 3:5b17e4656dd0 837 * place pointed to by the uip_appdata pointer.
hudakz 3:5b17e4656dd0 838 *
hudakz 3:5b17e4656dd0 839 * \param len The length of the data in the uip_buf buffer.
hudakz 3:5b17e4656dd0 840 *
hudakz 3:5b17e4656dd0 841 * \hideinitializer
hudakz 3:5b17e4656dd0 842 */
hudakz 3:5b17e4656dd0 843
hudakz 3:5b17e4656dd0 844 #define uip_udp_send(len) uip_send((char*)uip_appdata, len)
hudakz 3:5b17e4656dd0 845
hudakz 3:5b17e4656dd0 846 /** @} */
hudakz 3:5b17e4656dd0 847
hudakz 3:5b17e4656dd0 848 /* uIP convenience and converting functions. */
hudakz 3:5b17e4656dd0 849 /**
hudakz 3:5b17e4656dd0 850 * \defgroup uipconvfunc uIP conversion functions
hudakz 3:5b17e4656dd0 851 * @{
hudakz 3:5b17e4656dd0 852 *
hudakz 3:5b17e4656dd0 853 * These functions can be used for converting between different data
hudakz 3:5b17e4656dd0 854 * formats used by uIP.
hudakz 3:5b17e4656dd0 855 */
hudakz 3:5b17e4656dd0 856
hudakz 3:5b17e4656dd0 857 /**
hudakz 3:5b17e4656dd0 858 * Construct an IP address from four bytes.
hudakz 3:5b17e4656dd0 859 *
hudakz 3:5b17e4656dd0 860 * This function constructs an IP address of the type that uIP handles
hudakz 3:5b17e4656dd0 861 * internally from four bytes. The function is handy for specifying IP
hudakz 3:5b17e4656dd0 862 * addresses to use with e.g. the uip_connect() function.
hudakz 3:5b17e4656dd0 863 *
hudakz 3:5b17e4656dd0 864 * Example:
hudakz 3:5b17e4656dd0 865 \code
hudakz 3:5b17e4656dd0 866 uip_ipaddr_t ipaddr;
hudakz 3:5b17e4656dd0 867 struct uip_conn *c;
hudakz 3:5b17e4656dd0 868
hudakz 3:5b17e4656dd0 869 uip_ipaddr(&ipaddr, 192,168,1,2);
hudakz 3:5b17e4656dd0 870 c = uip_connect(&ipaddr, HTONS(80));
hudakz 3:5b17e4656dd0 871 \endcode
hudakz 3:5b17e4656dd0 872 *
hudakz 3:5b17e4656dd0 873 * \param addr A pointer to a uip_ipaddr_t variable that will be
hudakz 3:5b17e4656dd0 874 * filled in with the IP address.
hudakz 3:5b17e4656dd0 875 *
hudakz 3:5b17e4656dd0 876 * \param addr0 The first octet of the IP address.
hudakz 3:5b17e4656dd0 877 * \param addr1 The second octet of the IP address.
hudakz 3:5b17e4656dd0 878 * \param addr2 The third octet of the IP address.
hudakz 3:5b17e4656dd0 879 * \param addr3 The forth octet of the IP address.
hudakz 3:5b17e4656dd0 880 *
hudakz 3:5b17e4656dd0 881 * \hideinitializer
hudakz 3:5b17e4656dd0 882 */
hudakz 3:5b17e4656dd0 883 #define uip_ipaddr(addr, addr0, addr1, addr2, addr3) \
hudakz 3:5b17e4656dd0 884 do \
hudakz 3:5b17e4656dd0 885 { \
hudakz 3:5b17e4656dd0 886 ((u16_t *) (addr))[0] = HTONS(((addr0) << 8) | (addr1)); \
hudakz 3:5b17e4656dd0 887 ((u16_t *) (addr))[1] = HTONS(((addr2) << 8) | (addr3)); \
hudakz 3:5b17e4656dd0 888 } while(0)
hudakz 3:5b17e4656dd0 889
hudakz 3:5b17e4656dd0 890 /**
hudakz 3:5b17e4656dd0 891 * Construct an IPv6 address from eight 16-bit words.
hudakz 3:5b17e4656dd0 892 *
hudakz 3:5b17e4656dd0 893 * This function constructs an IPv6 address.
hudakz 3:5b17e4656dd0 894 *
hudakz 3:5b17e4656dd0 895 * \hideinitializer
hudakz 3:5b17e4656dd0 896 */
hudakz 3:5b17e4656dd0 897
hudakz 3:5b17e4656dd0 898 #define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7) \
hudakz 3:5b17e4656dd0 899 do \
hudakz 3:5b17e4656dd0 900 { \
hudakz 3:5b17e4656dd0 901 ((u16_t *) (addr))[0] = HTONS((addr0)); \
hudakz 3:5b17e4656dd0 902 ((u16_t *) (addr))[1] = HTONS((addr1)); \
hudakz 3:5b17e4656dd0 903 ((u16_t *) (addr))[2] = HTONS((addr2)); \
hudakz 3:5b17e4656dd0 904 ((u16_t *) (addr))[3] = HTONS((addr3)); \
hudakz 3:5b17e4656dd0 905 ((u16_t *) (addr))[4] = HTONS((addr4)); \
hudakz 3:5b17e4656dd0 906 ((u16_t *) (addr))[5] = HTONS((addr5)); \
hudakz 3:5b17e4656dd0 907 ((u16_t *) (addr))[6] = HTONS((addr6)); \
hudakz 3:5b17e4656dd0 908 ((u16_t *) (addr))[7] = HTONS((addr7)); \
hudakz 3:5b17e4656dd0 909 } while(0) /**
hudakz 3:5b17e4656dd0 910 * Copy an IP address to another IP address.
hudakz 3:5b17e4656dd0 911 *
hudakz 3:5b17e4656dd0 912 * Copies an IP address from one place to another.
hudakz 3:5b17e4656dd0 913 *
hudakz 3:5b17e4656dd0 914 * Example:
hudakz 3:5b17e4656dd0 915 \code
hudakz 3:5b17e4656dd0 916 uip_ipaddr_t ipaddr1, ipaddr2;
hudakz 3:5b17e4656dd0 917
hudakz 3:5b17e4656dd0 918 uip_ipaddr(&ipaddr1, 192,16,1,2);
hudakz 3:5b17e4656dd0 919 uip_ipaddr_copy(&ipaddr2, &ipaddr1);
hudakz 3:5b17e4656dd0 920 \endcode
hudakz 3:5b17e4656dd0 921 *
hudakz 3:5b17e4656dd0 922 * \param dest The destination for the copy.
hudakz 3:5b17e4656dd0 923 * \param src The source from where to copy.
hudakz 3:5b17e4656dd0 924 *
hudakz 3:5b17e4656dd0 925 * \hideinitializer
hudakz 3:5b17e4656dd0 926 */
hudakz 3:5b17e4656dd0 927
hudakz 3:5b17e4656dd0 928 #if !UIP_CONF_IPV6
hudakz 3:5b17e4656dd0 929 #define uip_ipaddr_copy(dest, src) \
hudakz 3:5b17e4656dd0 930 do \
hudakz 3:5b17e4656dd0 931 { \
hudakz 3:5b17e4656dd0 932 ((u16_t*)dest)[0] = ((u16_t*)src)[0]; \
hudakz 3:5b17e4656dd0 933 ((u16_t*)dest)[1] = ((u16_t*)src)[1]; \
hudakz 3:5b17e4656dd0 934 } while(0)
hudakz 3:5b17e4656dd0 935 #else /* !UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 936
hudakz 3:5b17e4656dd0 937 #define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t))
hudakz 3:5b17e4656dd0 938 #endif /* !UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 939
hudakz 3:5b17e4656dd0 940 /**
hudakz 3:5b17e4656dd0 941 * Compare two IP addresses
hudakz 3:5b17e4656dd0 942 *
hudakz 3:5b17e4656dd0 943 * Compares two IP addresses.
hudakz 3:5b17e4656dd0 944 *
hudakz 3:5b17e4656dd0 945 * Example:
hudakz 3:5b17e4656dd0 946 \code
hudakz 3:5b17e4656dd0 947 uip_ipaddr_t ipaddr1, ipaddr2;
hudakz 3:5b17e4656dd0 948
hudakz 3:5b17e4656dd0 949 uip_ipaddr(&ipaddr1, 192,16,1,2);
hudakz 3:5b17e4656dd0 950 if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
hudakz 3:5b17e4656dd0 951 printf("They are the same");
hudakz 3:5b17e4656dd0 952 }
hudakz 3:5b17e4656dd0 953 \endcode
hudakz 3:5b17e4656dd0 954 *
hudakz 3:5b17e4656dd0 955 * \param addr1 The first IP address.
hudakz 3:5b17e4656dd0 956 * \param addr2 The second IP address.
hudakz 3:5b17e4656dd0 957 *
hudakz 3:5b17e4656dd0 958 * \hideinitializer
hudakz 3:5b17e4656dd0 959 */
hudakz 3:5b17e4656dd0 960
hudakz 3:5b17e4656dd0 961 #if !UIP_CONF_IPV6
hudakz 3:5b17e4656dd0 962 #define uip_ipaddr_cmp(addr1, addr2) \
hudakz 3:5b17e4656dd0 963 (((u16_t*)addr1)[0] == ((u16_t*)addr2)[0] && ((u16_t*)addr1)[1] == ((u16_t*)addr2)[1])
hudakz 3:5b17e4656dd0 964 #else /* !UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 965
hudakz 3:5b17e4656dd0 966 #define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
hudakz 3:5b17e4656dd0 967 #endif /* !UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 968
hudakz 3:5b17e4656dd0 969 /**
hudakz 3:5b17e4656dd0 970 * Compare two IP addresses with netmasks
hudakz 3:5b17e4656dd0 971 *
hudakz 3:5b17e4656dd0 972 * Compares two IP addresses with netmasks. The masks are used to mask
hudakz 3:5b17e4656dd0 973 * out the bits that are to be compared.
hudakz 3:5b17e4656dd0 974 *
hudakz 3:5b17e4656dd0 975 * Example:
hudakz 3:5b17e4656dd0 976 \code
hudakz 3:5b17e4656dd0 977 uip_ipaddr_t ipaddr1, ipaddr2, mask;
hudakz 3:5b17e4656dd0 978
hudakz 3:5b17e4656dd0 979 uip_ipaddr(&mask, 255,255,255,0);
hudakz 3:5b17e4656dd0 980 uip_ipaddr(&ipaddr1, 192,16,1,2);
hudakz 3:5b17e4656dd0 981 uip_ipaddr(&ipaddr2, 192,16,1,3);
hudakz 3:5b17e4656dd0 982 if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
hudakz 3:5b17e4656dd0 983 printf("They are the same");
hudakz 3:5b17e4656dd0 984 }
hudakz 3:5b17e4656dd0 985 \endcode
hudakz 3:5b17e4656dd0 986 *
hudakz 3:5b17e4656dd0 987 * \param addr1 The first IP address.
hudakz 3:5b17e4656dd0 988 * \param addr2 The second IP address.
hudakz 3:5b17e4656dd0 989 * \param mask The netmask.
hudakz 3:5b17e4656dd0 990 *
hudakz 3:5b17e4656dd0 991 * \hideinitializer
hudakz 3:5b17e4656dd0 992 */
hudakz 3:5b17e4656dd0 993
hudakz 3:5b17e4656dd0 994 #define uip_ipaddr_maskcmp(addr1, addr2, mask) \
hudakz 3:5b17e4656dd0 995 ( \
hudakz 3:5b17e4656dd0 996 ((((u16_t*)addr1)[0] & ((u16_t*)mask)[0]) == (((u16_t*)addr2)[0] & ((u16_t*)mask)[0])) \
hudakz 3:5b17e4656dd0 997 && ((((u16_t*)addr1)[1] & ((u16_t*)mask)[1]) == (((u16_t*)addr2)[1] & ((u16_t*)mask)[1])) \
hudakz 3:5b17e4656dd0 998 )
hudakz 3:5b17e4656dd0 999
hudakz 3:5b17e4656dd0 1000 /**
hudakz 3:5b17e4656dd0 1001 * Mask out the network part of an IP address.
hudakz 3:5b17e4656dd0 1002 *
hudakz 3:5b17e4656dd0 1003 * Masks out the network part of an IP address, given the address and
hudakz 3:5b17e4656dd0 1004 * the netmask.
hudakz 3:5b17e4656dd0 1005 *
hudakz 3:5b17e4656dd0 1006 * Example:
hudakz 3:5b17e4656dd0 1007 \code
hudakz 3:5b17e4656dd0 1008 uip_ipaddr_t ipaddr1, ipaddr2, netmask;
hudakz 3:5b17e4656dd0 1009
hudakz 3:5b17e4656dd0 1010 uip_ipaddr(&ipaddr1, 192,16,1,2);
hudakz 3:5b17e4656dd0 1011 uip_ipaddr(&netmask, 255,255,255,0);
hudakz 3:5b17e4656dd0 1012 uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
hudakz 3:5b17e4656dd0 1013 \endcode
hudakz 3:5b17e4656dd0 1014 *
hudakz 3:5b17e4656dd0 1015 * In the example above, the variable "ipaddr2" will contain the IP
hudakz 3:5b17e4656dd0 1016 * address 192.168.1.0.
hudakz 3:5b17e4656dd0 1017 *
hudakz 3:5b17e4656dd0 1018 * \param dest Where the result is to be placed.
hudakz 3:5b17e4656dd0 1019 * \param src The IP address.
hudakz 3:5b17e4656dd0 1020 * \param mask The netmask.
hudakz 3:5b17e4656dd0 1021 *
hudakz 3:5b17e4656dd0 1022 * \hideinitializer
hudakz 3:5b17e4656dd0 1023 */
hudakz 3:5b17e4656dd0 1024
hudakz 3:5b17e4656dd0 1025 #define uip_ipaddr_mask(dest, src, mask) \
hudakz 3:5b17e4656dd0 1026 do \
hudakz 3:5b17e4656dd0 1027 { \
hudakz 3:5b17e4656dd0 1028 ((u16_t*)dest)[0] = ((u16_t*)src)[0] & ((u16_t*)mask)[0]; \
hudakz 3:5b17e4656dd0 1029 ((u16_t*)dest)[1] = ((u16_t*)src)[1] & ((u16_t*)mask)[1]; \
hudakz 3:5b17e4656dd0 1030 } while(0)
hudakz 3:5b17e4656dd0 1031
hudakz 3:5b17e4656dd0 1032 /**
hudakz 3:5b17e4656dd0 1033 * Pick the first octet of an IP address.
hudakz 3:5b17e4656dd0 1034 *
hudakz 3:5b17e4656dd0 1035 * Picks out the first octet of an IP address.
hudakz 3:5b17e4656dd0 1036 *
hudakz 3:5b17e4656dd0 1037 * Example:
hudakz 3:5b17e4656dd0 1038 \code
hudakz 3:5b17e4656dd0 1039 uip_ipaddr_t ipaddr;
hudakz 3:5b17e4656dd0 1040 u8_t octet;
hudakz 3:5b17e4656dd0 1041
hudakz 3:5b17e4656dd0 1042 uip_ipaddr(&ipaddr, 1,2,3,4);
hudakz 3:5b17e4656dd0 1043 octet = uip_ipaddr1(&ipaddr);
hudakz 3:5b17e4656dd0 1044 \endcode
hudakz 3:5b17e4656dd0 1045 *
hudakz 3:5b17e4656dd0 1046 * In the example above, the variable "octet" will contain the value 1.
hudakz 3:5b17e4656dd0 1047 *
hudakz 3:5b17e4656dd0 1048 * \hideinitializer
hudakz 3:5b17e4656dd0 1049 */
hudakz 3:5b17e4656dd0 1050
hudakz 3:5b17e4656dd0 1051 #define uip_ipaddr1(addr) (htons(((u16_t *) (addr))[0]) >> 8)
hudakz 3:5b17e4656dd0 1052
hudakz 3:5b17e4656dd0 1053 /**
hudakz 3:5b17e4656dd0 1054 * Pick the second octet of an IP address.
hudakz 3:5b17e4656dd0 1055 *
hudakz 3:5b17e4656dd0 1056 * Picks out the second octet of an IP address.
hudakz 3:5b17e4656dd0 1057 *
hudakz 3:5b17e4656dd0 1058 * Example:
hudakz 3:5b17e4656dd0 1059 \code
hudakz 3:5b17e4656dd0 1060 uip_ipaddr_t ipaddr;
hudakz 3:5b17e4656dd0 1061 u8_t octet;
hudakz 3:5b17e4656dd0 1062
hudakz 3:5b17e4656dd0 1063 uip_ipaddr(&ipaddr, 1,2,3,4);
hudakz 3:5b17e4656dd0 1064 octet = uip_ipaddr2(&ipaddr);
hudakz 3:5b17e4656dd0 1065 \endcode
hudakz 3:5b17e4656dd0 1066 *
hudakz 3:5b17e4656dd0 1067 * In the example above, the variable "octet" will contain the value 2.
hudakz 3:5b17e4656dd0 1068 *
hudakz 3:5b17e4656dd0 1069 * \hideinitializer
hudakz 3:5b17e4656dd0 1070 */
hudakz 3:5b17e4656dd0 1071
hudakz 3:5b17e4656dd0 1072 #define uip_ipaddr2(addr) (htons(((u16_t *) (addr))[0]) & 0xff)
hudakz 3:5b17e4656dd0 1073
hudakz 3:5b17e4656dd0 1074 /**
hudakz 3:5b17e4656dd0 1075 * Pick the third octet of an IP address.
hudakz 3:5b17e4656dd0 1076 *
hudakz 3:5b17e4656dd0 1077 * Picks out the third octet of an IP address.
hudakz 3:5b17e4656dd0 1078 *
hudakz 3:5b17e4656dd0 1079 * Example:
hudakz 3:5b17e4656dd0 1080 \code
hudakz 3:5b17e4656dd0 1081 uip_ipaddr_t ipaddr;
hudakz 3:5b17e4656dd0 1082 u8_t octet;
hudakz 3:5b17e4656dd0 1083
hudakz 3:5b17e4656dd0 1084 uip_ipaddr(&ipaddr, 1,2,3,4);
hudakz 3:5b17e4656dd0 1085 octet = uip_ipaddr3(&ipaddr);
hudakz 3:5b17e4656dd0 1086 \endcode
hudakz 3:5b17e4656dd0 1087 *
hudakz 3:5b17e4656dd0 1088 * In the example above, the variable "octet" will contain the value 3.
hudakz 3:5b17e4656dd0 1089 *
hudakz 3:5b17e4656dd0 1090 * \hideinitializer
hudakz 3:5b17e4656dd0 1091 */
hudakz 3:5b17e4656dd0 1092
hudakz 3:5b17e4656dd0 1093 #define uip_ipaddr3(addr) (htons(((u16_t *) (addr))[1]) >> 8)
hudakz 3:5b17e4656dd0 1094
hudakz 3:5b17e4656dd0 1095 /**
hudakz 3:5b17e4656dd0 1096 * Pick the fourth octet of an IP address.
hudakz 3:5b17e4656dd0 1097 *
hudakz 3:5b17e4656dd0 1098 * Picks out the fourth octet of an IP address.
hudakz 3:5b17e4656dd0 1099 *
hudakz 3:5b17e4656dd0 1100 * Example:
hudakz 3:5b17e4656dd0 1101 \code
hudakz 3:5b17e4656dd0 1102 uip_ipaddr_t ipaddr;
hudakz 3:5b17e4656dd0 1103 u8_t octet;
hudakz 3:5b17e4656dd0 1104
hudakz 3:5b17e4656dd0 1105 uip_ipaddr(&ipaddr, 1,2,3,4);
hudakz 3:5b17e4656dd0 1106 octet = uip_ipaddr4(&ipaddr);
hudakz 3:5b17e4656dd0 1107 \endcode
hudakz 3:5b17e4656dd0 1108 *
hudakz 3:5b17e4656dd0 1109 * In the example above, the variable "octet" will contain the value 4.
hudakz 3:5b17e4656dd0 1110 *
hudakz 3:5b17e4656dd0 1111 * \hideinitializer
hudakz 3:5b17e4656dd0 1112 */
hudakz 3:5b17e4656dd0 1113
hudakz 3:5b17e4656dd0 1114 #define uip_ipaddr4(addr) (htons(((u16_t *) (addr))[1]) & 0xff)
hudakz 3:5b17e4656dd0 1115 /**
hudakz 3:5b17e4656dd0 1116 * Convert 16-bit quantity from host byte order to network byte order.
hudakz 3:5b17e4656dd0 1117 *
hudakz 3:5b17e4656dd0 1118 * This macro is primarily used for converting constants from host
hudakz 3:5b17e4656dd0 1119 * byte order to network byte order. For converting variables to
hudakz 3:5b17e4656dd0 1120 * network byte order, use the htons() function instead.
hudakz 3:5b17e4656dd0 1121 *
hudakz 3:5b17e4656dd0 1122 * \hideinitializer
hudakz 3:5b17e4656dd0 1123 */
hudakz 3:5b17e4656dd0 1124
hudakz 3:5b17e4656dd0 1125 #ifndef HTONS
hudakz 3:5b17e4656dd0 1126 #if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
hudakz 3:5b17e4656dd0 1127 #define HTONS(n) (n)
hudakz 3:5b17e4656dd0 1128 #else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
hudakz 3:5b17e4656dd0 1129
hudakz 3:5b17e4656dd0 1130 #define HTONS(n) (u16_t) ((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8))
hudakz 3:5b17e4656dd0 1131 #endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
hudakz 3:5b17e4656dd0 1132
hudakz 3:5b17e4656dd0 1133 #else
hudakz 3:5b17e4656dd0 1134 #error "HTONS already defined!"
hudakz 3:5b17e4656dd0 1135 #endif /* HTONS */
hudakz 3:5b17e4656dd0 1136
hudakz 3:5b17e4656dd0 1137 /**
hudakz 3:5b17e4656dd0 1138 * Convert 16-bit quantity from host byte order to network byte order.
hudakz 3:5b17e4656dd0 1139 *
hudakz 3:5b17e4656dd0 1140 * This function is primarily used for converting variables from host
hudakz 3:5b17e4656dd0 1141 * byte order to network byte order. For converting constants to
hudakz 3:5b17e4656dd0 1142 * network byte order, use the HTONS() macro instead.
hudakz 3:5b17e4656dd0 1143 */
hudakz 3:5b17e4656dd0 1144
hudakz 3:5b17e4656dd0 1145 #ifndef htons
hudakz 3:5b17e4656dd0 1146 u16_t htons(u16_t val);
hudakz 3:5b17e4656dd0 1147 #endif /* htons */
hudakz 3:5b17e4656dd0 1148
hudakz 3:5b17e4656dd0 1149 #ifndef ntohs
hudakz 3:5b17e4656dd0 1150 #define ntohs htons
hudakz 3:5b17e4656dd0 1151 #endif
hudakz 3:5b17e4656dd0 1152 /** @} */
hudakz 3:5b17e4656dd0 1153
hudakz 3:5b17e4656dd0 1154 /**
hudakz 3:5b17e4656dd0 1155 * Pointer to the application data in the packet buffer.
hudakz 3:5b17e4656dd0 1156 *
hudakz 3:5b17e4656dd0 1157 * This pointer points to the application data when the application is
hudakz 3:5b17e4656dd0 1158 * called. If the application wishes to send data, the application may
hudakz 3:5b17e4656dd0 1159 * use this space to write the data into before calling uip_send().
hudakz 3:5b17e4656dd0 1160 */
hudakz 3:5b17e4656dd0 1161 extern void* uip_appdata;
hudakz 3:5b17e4656dd0 1162
hudakz 3:5b17e4656dd0 1163 #if UIP_URGDATA > 0
hudakz 3:5b17e4656dd0 1164 /* u8_t *uip_urgdata:
hudakz 3:5b17e4656dd0 1165 *
hudakz 3:5b17e4656dd0 1166 * This pointer points to any urgent data that has been received. Only
hudakz 3:5b17e4656dd0 1167 * present if compiled with support for urgent data (UIP_URGDATA).
hudakz 3:5b17e4656dd0 1168 */
hudakz 3:5b17e4656dd0 1169 extern void* uip_urgdata;
hudakz 3:5b17e4656dd0 1170 #endif /* UIP_URGDATA > 0 */
hudakz 3:5b17e4656dd0 1171
hudakz 3:5b17e4656dd0 1172 /**
hudakz 3:5b17e4656dd0 1173 * \defgroup uipdrivervars Variables used in uIP device drivers
hudakz 3:5b17e4656dd0 1174 * @{
hudakz 3:5b17e4656dd0 1175 *
hudakz 3:5b17e4656dd0 1176 * uIP has a few global variables that are used in device drivers for
hudakz 3:5b17e4656dd0 1177 * uIP.
hudakz 3:5b17e4656dd0 1178 */
hudakz 3:5b17e4656dd0 1179
hudakz 3:5b17e4656dd0 1180 /**
hudakz 3:5b17e4656dd0 1181 * The length of the packet in the uip_buf buffer.
hudakz 3:5b17e4656dd0 1182 *
hudakz 3:5b17e4656dd0 1183 * The global variable uip_len holds the length of the packet in the
hudakz 3:5b17e4656dd0 1184 * uip_buf buffer.
hudakz 3:5b17e4656dd0 1185 *
hudakz 3:5b17e4656dd0 1186 * When the network device driver calls the uIP input function,
hudakz 3:5b17e4656dd0 1187 * uip_len should be set to the length of the packet in the uip_buf
hudakz 3:5b17e4656dd0 1188 * buffer.
hudakz 3:5b17e4656dd0 1189 *
hudakz 3:5b17e4656dd0 1190 * When sending packets, the device driver should use the contents of
hudakz 3:5b17e4656dd0 1191 * the uip_len variable to determine the length of the outgoing
hudakz 3:5b17e4656dd0 1192 * packet.
hudakz 3:5b17e4656dd0 1193 *
hudakz 3:5b17e4656dd0 1194 */
hudakz 3:5b17e4656dd0 1195 extern u16_t uip_len;
hudakz 3:5b17e4656dd0 1196
hudakz 3:5b17e4656dd0 1197 /** @} */
hudakz 3:5b17e4656dd0 1198 #if UIP_URGDATA > 0
hudakz 3:5b17e4656dd0 1199 extern u16_t uip_urglen, uip_surglen;
hudakz 3:5b17e4656dd0 1200 #endif /* UIP_URGDATA > 0 */
hudakz 3:5b17e4656dd0 1201
hudakz 3:5b17e4656dd0 1202 /**
hudakz 3:5b17e4656dd0 1203 * Representation of a uIP TCP connection.
hudakz 3:5b17e4656dd0 1204 *
hudakz 3:5b17e4656dd0 1205 * The uip_conn structure is used for identifying a connection. All
hudakz 3:5b17e4656dd0 1206 * but one field in the structure are to be considered read-only by an
hudakz 3:5b17e4656dd0 1207 * application. The only exception is the appstate field whos purpose
hudakz 3:5b17e4656dd0 1208 * is to let the application store application-specific state (e.g.,
hudakz 3:5b17e4656dd0 1209 * file pointers) for the connection. The type of this field is
hudakz 3:5b17e4656dd0 1210 * configured in the "uipopt.h" header file.
hudakz 3:5b17e4656dd0 1211 */
hudakz 3:5b17e4656dd0 1212
hudakz 3:5b17e4656dd0 1213 struct uip_conn
hudakz 3:5b17e4656dd0 1214 {
hudakz 3:5b17e4656dd0 1215 uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */
hudakz 3:5b17e4656dd0 1216
hudakz 3:5b17e4656dd0 1217 u16_t lport; /**< The local TCP port, in network byte order. */
hudakz 3:5b17e4656dd0 1218 u16_t rport; /**< The local remote TCP port, in network byte
hudakz 3:5b17e4656dd0 1219 order. */
hudakz 3:5b17e4656dd0 1220
hudakz 3:5b17e4656dd0 1221 u8_t rcv_nxt[4]; /**< The sequence number that we expect to
hudakz 3:5b17e4656dd0 1222 receive next. */
hudakz 3:5b17e4656dd0 1223 u8_t snd_nxt[4]; /**< The sequence number that was last sent by
hudakz 3:5b17e4656dd0 1224 us. */
hudakz 3:5b17e4656dd0 1225 u16_t len; /**< Length of the data that was previously sent. */
hudakz 3:5b17e4656dd0 1226 u16_t mss; /**< Current maximum segment size for the
hudakz 3:5b17e4656dd0 1227 connection. */
hudakz 3:5b17e4656dd0 1228 u16_t initialmss; /**< Initial maximum segment size for the
hudakz 3:5b17e4656dd0 1229 connection. */
hudakz 3:5b17e4656dd0 1230 u8_t sa; /**< Retransmission time-out calculation state
hudakz 3:5b17e4656dd0 1231 variable. */
hudakz 3:5b17e4656dd0 1232 u8_t sv; /**< Retransmission time-out calculation state
hudakz 3:5b17e4656dd0 1233 variable. */
hudakz 3:5b17e4656dd0 1234 u8_t rto; /**< Retransmission time-out. */
hudakz 3:5b17e4656dd0 1235 u8_t tcpstateflags; /**< TCP state and flags. */
hudakz 3:5b17e4656dd0 1236 u8_t timer; /**< The retransmission timer. */
hudakz 3:5b17e4656dd0 1237 u8_t nrtx; /**< The number of retransmissions for the last
hudakz 3:5b17e4656dd0 1238 segment sent. */
hudakz 3:5b17e4656dd0 1239
hudakz 3:5b17e4656dd0 1240 /** The application state. */
hudakz 3:5b17e4656dd0 1241 uip_tcp_appstate_t appstate;
hudakz 3:5b17e4656dd0 1242 };
hudakz 3:5b17e4656dd0 1243
hudakz 3:5b17e4656dd0 1244 /**
hudakz 3:5b17e4656dd0 1245 * Pointer to the current TCP connection.
hudakz 3:5b17e4656dd0 1246 *
hudakz 3:5b17e4656dd0 1247 * The uip_conn pointer can be used to access the current TCP
hudakz 3:5b17e4656dd0 1248 * connection.
hudakz 3:5b17e4656dd0 1249 */
hudakz 3:5b17e4656dd0 1250 extern struct uip_conn* uip_conn;
hudakz 3:5b17e4656dd0 1251
hudakz 3:5b17e4656dd0 1252 /* The array containing all uIP connections. */
hudakz 3:5b17e4656dd0 1253 extern struct uip_conn uip_conns[UIP_CONNS];
hudakz 3:5b17e4656dd0 1254
hudakz 3:5b17e4656dd0 1255 /**
hudakz 3:5b17e4656dd0 1256 * \addtogroup uiparch
hudakz 3:5b17e4656dd0 1257 * @{
hudakz 3:5b17e4656dd0 1258 */
hudakz 3:5b17e4656dd0 1259 /**
hudakz 3:5b17e4656dd0 1260 * 4-byte array used for the 32-bit sequence number calculations.
hudakz 3:5b17e4656dd0 1261 */
hudakz 3:5b17e4656dd0 1262 extern u8_t uip_acc32[4];
hudakz 3:5b17e4656dd0 1263
hudakz 3:5b17e4656dd0 1264 /** @} */
hudakz 3:5b17e4656dd0 1265
hudakz 3:5b17e4656dd0 1266 #if UIP_UDP
hudakz 3:5b17e4656dd0 1267
hudakz 3:5b17e4656dd0 1268 /**
hudakz 3:5b17e4656dd0 1269 * Representation of a uIP UDP connection.
hudakz 3:5b17e4656dd0 1270 */
hudakz 3:5b17e4656dd0 1271 struct uip_udp_conn
hudakz 3:5b17e4656dd0 1272 {
hudakz 3:5b17e4656dd0 1273 uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */
hudakz 3:5b17e4656dd0 1274 u16_t lport; /**< The local port number in network byte order. */
hudakz 3:5b17e4656dd0 1275 u16_t rport; /**< The remote port number in network byte order. */
hudakz 3:5b17e4656dd0 1276 u8_t ttl; /**< Default time-to-live. */
hudakz 3:5b17e4656dd0 1277
hudakz 3:5b17e4656dd0 1278 /** The application state. */
hudakz 3:5b17e4656dd0 1279 uip_udp_appstate_t appstate;
hudakz 3:5b17e4656dd0 1280 };
hudakz 3:5b17e4656dd0 1281
hudakz 3:5b17e4656dd0 1282 /**
hudakz 3:5b17e4656dd0 1283 * The current UDP connection.
hudakz 3:5b17e4656dd0 1284 */
hudakz 3:5b17e4656dd0 1285 extern struct uip_udp_conn* uip_udp_conn;
hudakz 3:5b17e4656dd0 1286 extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
hudakz 3:5b17e4656dd0 1287 #endif /* UIP_UDP */
hudakz 3:5b17e4656dd0 1288
hudakz 3:5b17e4656dd0 1289 /**
hudakz 3:5b17e4656dd0 1290 * The structure holding the TCP/IP statistics that are gathered if
hudakz 3:5b17e4656dd0 1291 * UIP_STATISTICS is set to 1.
hudakz 3:5b17e4656dd0 1292 *
hudakz 3:5b17e4656dd0 1293 */
hudakz 3:5b17e4656dd0 1294
hudakz 3:5b17e4656dd0 1295 struct uip_stats
hudakz 3:5b17e4656dd0 1296 {
hudakz 3:5b17e4656dd0 1297 struct
hudakz 3:5b17e4656dd0 1298 {
hudakz 3:5b17e4656dd0 1299 uip_stats_t drop; /**< Number of dropped packets at the IP
hudakz 3:5b17e4656dd0 1300 layer. */
hudakz 3:5b17e4656dd0 1301 uip_stats_t recv; /**< Number of received packets at the IP
hudakz 3:5b17e4656dd0 1302 layer. */
hudakz 3:5b17e4656dd0 1303 uip_stats_t sent; /**< Number of sent packets at the IP
hudakz 3:5b17e4656dd0 1304 layer. */
hudakz 3:5b17e4656dd0 1305 uip_stats_t vhlerr; /**< Number of packets dropped due to wrong
hudakz 3:5b17e4656dd0 1306 IP version or header length. */
hudakz 3:5b17e4656dd0 1307 uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
hudakz 3:5b17e4656dd0 1308 IP length, high byte. */
hudakz 3:5b17e4656dd0 1309 uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
hudakz 3:5b17e4656dd0 1310 IP length, low byte. */
hudakz 3:5b17e4656dd0 1311 uip_stats_t fragerr; /**< Number of packets dropped since they
hudakz 3:5b17e4656dd0 1312 were IP fragments. */
hudakz 3:5b17e4656dd0 1313 uip_stats_t chkerr; /**< Number of packets dropped due to IP
hudakz 3:5b17e4656dd0 1314 checksum errors. */
hudakz 3:5b17e4656dd0 1315 uip_stats_t protoerr; /**< Number of packets dropped since they
hudakz 3:5b17e4656dd0 1316 were neither ICMP, UDP nor TCP. */
hudakz 3:5b17e4656dd0 1317 } ip; /**< IP statistics. */
hudakz 3:5b17e4656dd0 1318 struct
hudakz 3:5b17e4656dd0 1319 {
hudakz 3:5b17e4656dd0 1320 uip_stats_t drop; /**< Number of dropped ICMP packets. */
hudakz 3:5b17e4656dd0 1321 uip_stats_t recv; /**< Number of received ICMP packets. */
hudakz 3:5b17e4656dd0 1322 uip_stats_t sent; /**< Number of sent ICMP packets. */
hudakz 3:5b17e4656dd0 1323 uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
hudakz 3:5b17e4656dd0 1324 type. */
hudakz 3:5b17e4656dd0 1325 } icmp; /**< ICMP statistics. */
hudakz 3:5b17e4656dd0 1326 struct
hudakz 3:5b17e4656dd0 1327 {
hudakz 3:5b17e4656dd0 1328 uip_stats_t drop; /**< Number of dropped TCP segments. */
hudakz 3:5b17e4656dd0 1329 uip_stats_t recv; /**< Number of recived TCP segments. */
hudakz 3:5b17e4656dd0 1330 uip_stats_t sent; /**< Number of sent TCP segments. */
hudakz 3:5b17e4656dd0 1331 uip_stats_t chkerr; /**< Number of TCP segments with a bad
hudakz 3:5b17e4656dd0 1332 checksum. */
hudakz 3:5b17e4656dd0 1333 uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK
hudakz 3:5b17e4656dd0 1334 number. */
hudakz 3:5b17e4656dd0 1335 uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */
hudakz 3:5b17e4656dd0 1336 uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */
hudakz 3:5b17e4656dd0 1337 uip_stats_t syndrop; /**< Number of dropped SYNs due to too few
hudakz 3:5b17e4656dd0 1338 connections was avaliable. */
hudakz 3:5b17e4656dd0 1339 uip_stats_t synrst; /**< Number of SYNs for closed ports,
hudakz 3:5b17e4656dd0 1340 triggering a RST. */
hudakz 3:5b17e4656dd0 1341 } tcp; /**< TCP statistics. */
hudakz 3:5b17e4656dd0 1342 #if UIP_UDP
hudakz 3:5b17e4656dd0 1343 struct
hudakz 3:5b17e4656dd0 1344 {
hudakz 3:5b17e4656dd0 1345 uip_stats_t drop; /**< Number of dropped UDP segments. */
hudakz 3:5b17e4656dd0 1346 uip_stats_t recv; /**< Number of recived UDP segments. */
hudakz 3:5b17e4656dd0 1347 uip_stats_t sent; /**< Number of sent UDP segments. */
hudakz 3:5b17e4656dd0 1348 uip_stats_t chkerr; /**< Number of UDP segments with a bad
hudakz 3:5b17e4656dd0 1349 checksum. */
hudakz 3:5b17e4656dd0 1350 } udp; /**< UDP statistics. */
hudakz 3:5b17e4656dd0 1351 #endif /* UIP_UDP */
hudakz 3:5b17e4656dd0 1352 };
hudakz 3:5b17e4656dd0 1353
hudakz 3:5b17e4656dd0 1354 /**
hudakz 3:5b17e4656dd0 1355 * The uIP TCP/IP statistics.
hudakz 3:5b17e4656dd0 1356 *
hudakz 3:5b17e4656dd0 1357 * This is the variable in which the uIP TCP/IP statistics are gathered.
hudakz 3:5b17e4656dd0 1358 */
hudakz 3:5b17e4656dd0 1359 extern struct uip_stats uip_stat;
hudakz 3:5b17e4656dd0 1360
hudakz 3:5b17e4656dd0 1361 /*---------------------------------------------------------------------------*/
hudakz 3:5b17e4656dd0 1362 /* All the stuff below this point is internal to uIP and should not be
hudakz 3:5b17e4656dd0 1363 * used directly by an application or by a device driver.
hudakz 3:5b17e4656dd0 1364 */
hudakz 3:5b17e4656dd0 1365 /*---------------------------------------------------------------------------*/
hudakz 3:5b17e4656dd0 1366 /* u8_t uip_flags:
hudakz 3:5b17e4656dd0 1367 *
hudakz 3:5b17e4656dd0 1368 * When the application is called, uip_flags will contain the flags
hudakz 3:5b17e4656dd0 1369 * that are defined in this file. Please read below for more
hudakz 3:5b17e4656dd0 1370 * infomation.
hudakz 3:5b17e4656dd0 1371 */
hudakz 3:5b17e4656dd0 1372 extern u8_t uip_flags;
hudakz 3:5b17e4656dd0 1373
hudakz 3:5b17e4656dd0 1374 /* The following flags may be set in the global variable uip_flags
hudakz 3:5b17e4656dd0 1375 before calling the application callback. The UIP_ACKDATA,
hudakz 3:5b17e4656dd0 1376 UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
hudakz 3:5b17e4656dd0 1377 whereas the others are mutualy exclusive. Note that these flags
hudakz 3:5b17e4656dd0 1378 should *NOT* be accessed directly, but only through the uIP
hudakz 3:5b17e4656dd0 1379 functions/macros. */
hudakz 3:5b17e4656dd0 1380
hudakz 3:5b17e4656dd0 1381 #define UIP_ACKDATA 1 /* Signifies that the outstanding data was
hudakz 3:5b17e4656dd0 1382 acked and the application should send
hudakz 3:5b17e4656dd0 1383 out new data instead of retransmitting
hudakz 3:5b17e4656dd0 1384 the last data. */
hudakz 3:5b17e4656dd0 1385
hudakz 3:5b17e4656dd0 1386 #define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
hudakz 3:5b17e4656dd0 1387 us new data. */
hudakz 3:5b17e4656dd0 1388
hudakz 3:5b17e4656dd0 1389 #define UIP_REXMIT 4 /* Tells the application to retransmit the
hudakz 3:5b17e4656dd0 1390 data that was last sent. */
hudakz 3:5b17e4656dd0 1391
hudakz 3:5b17e4656dd0 1392 #define UIP_POLL 8 /* Used for polling the application, to
hudakz 3:5b17e4656dd0 1393 check if the application has data that
hudakz 3:5b17e4656dd0 1394 it wants to send. */
hudakz 3:5b17e4656dd0 1395
hudakz 3:5b17e4656dd0 1396 #define UIP_CLOSE 16 /* The remote host has closed the
hudakz 3:5b17e4656dd0 1397 connection, thus the connection has
hudakz 3:5b17e4656dd0 1398 gone away. Or the application signals
hudakz 3:5b17e4656dd0 1399 that it wants to close the
hudakz 3:5b17e4656dd0 1400 connection. */
hudakz 3:5b17e4656dd0 1401
hudakz 3:5b17e4656dd0 1402 #define UIP_ABORT 32 /* The remote host has aborted the
hudakz 3:5b17e4656dd0 1403 connection, thus the connection has
hudakz 3:5b17e4656dd0 1404 gone away. Or the application signals
hudakz 3:5b17e4656dd0 1405 that it wants to abort the
hudakz 3:5b17e4656dd0 1406 connection. */
hudakz 3:5b17e4656dd0 1407
hudakz 3:5b17e4656dd0 1408 #define UIP_CONNECTED 64 /* We have got a connection from a remote
hudakz 3:5b17e4656dd0 1409 host and have set up a new connection
hudakz 3:5b17e4656dd0 1410 for it, or an active connection has
hudakz 3:5b17e4656dd0 1411 been successfully established. */
hudakz 3:5b17e4656dd0 1412
hudakz 3:5b17e4656dd0 1413 #define UIP_TIMEDOUT 128 /* The connection has been aborted due to
hudakz 3:5b17e4656dd0 1414 too many retransmissions. */
hudakz 3:5b17e4656dd0 1415
hudakz 3:5b17e4656dd0 1416 /* uip_process(flag):
hudakz 3:5b17e4656dd0 1417 *
hudakz 3:5b17e4656dd0 1418 * The actual uIP function which does all the work.
hudakz 3:5b17e4656dd0 1419 */
hudakz 3:5b17e4656dd0 1420 void uip_process(u8_t flag);
hudakz 3:5b17e4656dd0 1421
hudakz 3:5b17e4656dd0 1422 /* The following flags are passed as an argument to the uip_process()
hudakz 3:5b17e4656dd0 1423 function. They are used to distinguish between the two cases where
hudakz 3:5b17e4656dd0 1424 uip_process() is called. It can be called either because we have
hudakz 3:5b17e4656dd0 1425 incoming data that should be processed, or because the periodic
hudakz 3:5b17e4656dd0 1426 timer has fired. These values are never used directly, but only in
hudakz 3:5b17e4656dd0 1427 the macrose defined in this file. */
hudakz 3:5b17e4656dd0 1428
hudakz 3:5b17e4656dd0 1429 #define UIP_DATA 1 /* Tells uIP that there is incoming
hudakz 3:5b17e4656dd0 1430 data in the uip_buf buffer. The
hudakz 3:5b17e4656dd0 1431 length of the data is stored in the
hudakz 3:5b17e4656dd0 1432 global variable uip_len. */
hudakz 3:5b17e4656dd0 1433
hudakz 3:5b17e4656dd0 1434 #define UIP_TIMER 2 /* Tells uIP that the periodic timer
hudakz 3:5b17e4656dd0 1435 has fired. */
hudakz 3:5b17e4656dd0 1436
hudakz 3:5b17e4656dd0 1437 #define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should
hudakz 3:5b17e4656dd0 1438 be polled. */
hudakz 3:5b17e4656dd0 1439
hudakz 3:5b17e4656dd0 1440 #define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram
hudakz 3:5b17e4656dd0 1441 should be constructed in the
hudakz 3:5b17e4656dd0 1442 uip_buf buffer. */
hudakz 3:5b17e4656dd0 1443
hudakz 3:5b17e4656dd0 1444 #if UIP_UDP
hudakz 3:5b17e4656dd0 1445 #define UIP_UDP_TIMER 5
hudakz 3:5b17e4656dd0 1446 #endif /* UIP_UDP */
hudakz 3:5b17e4656dd0 1447
hudakz 3:5b17e4656dd0 1448 /* The TCP states used in the uip_conn->tcpstateflags. */
hudakz 3:5b17e4656dd0 1449
hudakz 3:5b17e4656dd0 1450 #define UIP_CLOSED 0
hudakz 3:5b17e4656dd0 1451 #define UIP_SYN_RCVD 1
hudakz 3:5b17e4656dd0 1452 #define UIP_SYN_SENT 2
hudakz 3:5b17e4656dd0 1453 #define UIP_ESTABLISHED 3
hudakz 3:5b17e4656dd0 1454 #define UIP_FIN_WAIT_1 4
hudakz 3:5b17e4656dd0 1455 #define UIP_FIN_WAIT_2 5
hudakz 3:5b17e4656dd0 1456 #define UIP_CLOSING 6
hudakz 3:5b17e4656dd0 1457 #define UIP_TIME_WAIT 7
hudakz 3:5b17e4656dd0 1458 #define UIP_LAST_ACK 8
hudakz 3:5b17e4656dd0 1459 #define UIP_TS_MASK 15
hudakz 3:5b17e4656dd0 1460
hudakz 3:5b17e4656dd0 1461 #define UIP_STOPPED 16
hudakz 3:5b17e4656dd0 1462
hudakz 3:5b17e4656dd0 1463 /* The TCP and IP headers. */
hudakz 3:5b17e4656dd0 1464 struct uip_tcpip_hdr
hudakz 3:5b17e4656dd0 1465 {
hudakz 3:5b17e4656dd0 1466 #if UIP_CONF_IPV6
hudakz 3:5b17e4656dd0 1467 /* IPv6 header. */
hudakz 3:5b17e4656dd0 1468 u8_t vtc, tcflow;
hudakz 3:5b17e4656dd0 1469 u16_t flow;
hudakz 3:5b17e4656dd0 1470 u8_t len[2];
hudakz 3:5b17e4656dd0 1471 u8_t proto, ttl;
hudakz 3:5b17e4656dd0 1472 uip_ip6addr_t srcipaddr, destipaddr;
hudakz 3:5b17e4656dd0 1473 #else /* UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 1474 /* IPv4 header. */
hudakz 3:5b17e4656dd0 1475
hudakz 3:5b17e4656dd0 1476 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
hudakz 3:5b17e4656dd0 1477 u16_t ipchksum;
hudakz 3:5b17e4656dd0 1478 u16_t srcipaddr[2], destipaddr[2];
hudakz 3:5b17e4656dd0 1479 #endif /* UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 1480
hudakz 3:5b17e4656dd0 1481 /* TCP header. */
hudakz 3:5b17e4656dd0 1482
hudakz 3:5b17e4656dd0 1483 u16_t srcport, destport;
hudakz 3:5b17e4656dd0 1484 u8_t seqno[4], ackno[4], tcpoffset, flags, wnd[2];
hudakz 3:5b17e4656dd0 1485 u16_t tcpchksum;
hudakz 3:5b17e4656dd0 1486 u8_t urgp[2];
hudakz 3:5b17e4656dd0 1487 u8_t optdata[4];
hudakz 3:5b17e4656dd0 1488 };
hudakz 3:5b17e4656dd0 1489
hudakz 3:5b17e4656dd0 1490 /* The ICMP and IP headers. */
hudakz 3:5b17e4656dd0 1491 struct uip_icmpip_hdr
hudakz 3:5b17e4656dd0 1492 {
hudakz 3:5b17e4656dd0 1493 #if UIP_CONF_IPV6
hudakz 3:5b17e4656dd0 1494 /* IPv6 header. */
hudakz 3:5b17e4656dd0 1495 u8_t vtc, tcf;
hudakz 3:5b17e4656dd0 1496 u16_t flow;
hudakz 3:5b17e4656dd0 1497 u8_t len[2];
hudakz 3:5b17e4656dd0 1498 u8_t proto, ttl;
hudakz 3:5b17e4656dd0 1499 uip_ip6addr_t srcipaddr, destipaddr;
hudakz 3:5b17e4656dd0 1500 #else /* UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 1501 /* IPv4 header. */
hudakz 3:5b17e4656dd0 1502
hudakz 3:5b17e4656dd0 1503 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
hudakz 3:5b17e4656dd0 1504 u16_t ipchksum;
hudakz 3:5b17e4656dd0 1505 u16_t srcipaddr[2], destipaddr[2];
hudakz 3:5b17e4656dd0 1506 #endif /* UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 1507
hudakz 3:5b17e4656dd0 1508 /* ICMP (echo) header. */
hudakz 3:5b17e4656dd0 1509
hudakz 3:5b17e4656dd0 1510 u8_t type, icode;
hudakz 3:5b17e4656dd0 1511 u16_t icmpchksum;
hudakz 3:5b17e4656dd0 1512 #if !UIP_CONF_IPV6
hudakz 3:5b17e4656dd0 1513 u16_t id, seqno;
hudakz 3:5b17e4656dd0 1514 #else /* !UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 1515 u8_t flags, reserved1, reserved2, reserved3;
hudakz 3:5b17e4656dd0 1516 u8_t icmp6data[16];
hudakz 3:5b17e4656dd0 1517 u8_t options[1];
hudakz 3:5b17e4656dd0 1518 #endif /* !UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 1519 };
hudakz 3:5b17e4656dd0 1520
hudakz 3:5b17e4656dd0 1521 /* The UDP and IP headers. */
hudakz 3:5b17e4656dd0 1522 struct uip_udpip_hdr
hudakz 3:5b17e4656dd0 1523 {
hudakz 3:5b17e4656dd0 1524 #if UIP_CONF_IPV6
hudakz 3:5b17e4656dd0 1525 /* IPv6 header. */
hudakz 3:5b17e4656dd0 1526 u8_t vtc, tcf;
hudakz 3:5b17e4656dd0 1527 u16_t flow;
hudakz 3:5b17e4656dd0 1528 u8_t len[2];
hudakz 3:5b17e4656dd0 1529 u8_t proto, ttl;
hudakz 3:5b17e4656dd0 1530 uip_ip6addr_t srcipaddr, destipaddr;
hudakz 3:5b17e4656dd0 1531 #else /* UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 1532 /* IP header. */
hudakz 3:5b17e4656dd0 1533
hudakz 3:5b17e4656dd0 1534 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
hudakz 3:5b17e4656dd0 1535 u16_t ipchksum;
hudakz 3:5b17e4656dd0 1536 u16_t srcipaddr[2], destipaddr[2];
hudakz 3:5b17e4656dd0 1537 #endif /* UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 1538
hudakz 3:5b17e4656dd0 1539 /* UDP header. */
hudakz 3:5b17e4656dd0 1540
hudakz 3:5b17e4656dd0 1541 u16_t srcport, destport;
hudakz 3:5b17e4656dd0 1542 u16_t udplen;
hudakz 3:5b17e4656dd0 1543 u16_t udpchksum;
hudakz 3:5b17e4656dd0 1544 };
hudakz 3:5b17e4656dd0 1545
hudakz 3:5b17e4656dd0 1546 /**
hudakz 3:5b17e4656dd0 1547 * The buffer size available for user data in the \ref uip_buf buffer.
hudakz 3:5b17e4656dd0 1548 *
hudakz 3:5b17e4656dd0 1549 * This macro holds the available size for user data in the \ref
hudakz 3:5b17e4656dd0 1550 * uip_buf buffer. The macro is intended to be used for checking
hudakz 3:5b17e4656dd0 1551 * bounds of available user data.
hudakz 3:5b17e4656dd0 1552 *
hudakz 3:5b17e4656dd0 1553 * Example:
hudakz 3:5b17e4656dd0 1554 \code
hudakz 3:5b17e4656dd0 1555 snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
hudakz 3:5b17e4656dd0 1556 \endcode
hudakz 3:5b17e4656dd0 1557 *
hudakz 3:5b17e4656dd0 1558 * \hideinitializer
hudakz 3:5b17e4656dd0 1559 */
hudakz 3:5b17e4656dd0 1560 #define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
hudakz 3:5b17e4656dd0 1561 #define UIP_PROTO_ICMP 1
hudakz 3:5b17e4656dd0 1562 #define UIP_PROTO_TCP 6
hudakz 3:5b17e4656dd0 1563 #define UIP_PROTO_UDP 17
hudakz 3:5b17e4656dd0 1564 #define UIP_PROTO_ICMP6 58
hudakz 3:5b17e4656dd0 1565
hudakz 3:5b17e4656dd0 1566 /* Header sizes. */
hudakz 3:5b17e4656dd0 1567
hudakz 3:5b17e4656dd0 1568 #if UIP_CONF_IPV6
hudakz 3:5b17e4656dd0 1569 #define UIP_IPH_LEN 40
hudakz 3:5b17e4656dd0 1570 #else /* UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 1571
hudakz 3:5b17e4656dd0 1572 #define UIP_IPH_LEN 20 /* Size of IP header */
hudakz 3:5b17e4656dd0 1573 #endif /* UIP_CONF_IPV6 */
hudakz 3:5b17e4656dd0 1574
hudakz 3:5b17e4656dd0 1575 #define UIP_UDPH_LEN 8 /* Size of UDP header */
hudakz 3:5b17e4656dd0 1576
hudakz 3:5b17e4656dd0 1577 #define UIP_TCPH_LEN 20 /* Size of TCP header */
hudakz 3:5b17e4656dd0 1578
hudakz 3:5b17e4656dd0 1579 #define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP +
hudakz 3:5b17e4656dd0 1580 UDP
hudakz 3:5b17e4656dd0 1581 header */
hudakz 3:5b17e4656dd0 1582
hudakz 3:5b17e4656dd0 1583 #define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP +
hudakz 3:5b17e4656dd0 1584 TCP
hudakz 3:5b17e4656dd0 1585 header */
hudakz 3:5b17e4656dd0 1586
hudakz 3:5b17e4656dd0 1587 #define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
hudakz 3:5b17e4656dd0 1588
hudakz 3:5b17e4656dd0 1589 #if UIP_FIXEDADDR
hudakz 3:5b17e4656dd0 1590 extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
hudakz 3:5b17e4656dd0 1591 #else /* UIP_FIXEDADDR */
hudakz 3:5b17e4656dd0 1592
hudakz 3:5b17e4656dd0 1593 extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
hudakz 3:5b17e4656dd0 1594 #endif /* UIP_FIXEDADDR */
hudakz 3:5b17e4656dd0 1595
hudakz 3:5b17e4656dd0 1596 /**
hudakz 3:5b17e4656dd0 1597 * Representation of a 48-bit Ethernet address.
hudakz 3:5b17e4656dd0 1598 */
hudakz 3:5b17e4656dd0 1599
hudakz 3:5b17e4656dd0 1600 struct uip_eth_addr
hudakz 3:5b17e4656dd0 1601 {
hudakz 3:5b17e4656dd0 1602 u8_t addr[6];
hudakz 3:5b17e4656dd0 1603 };
hudakz 3:5b17e4656dd0 1604
hudakz 3:5b17e4656dd0 1605 /**
hudakz 3:5b17e4656dd0 1606 * Calculate the Internet checksum over a buffer.
hudakz 3:5b17e4656dd0 1607 *
hudakz 3:5b17e4656dd0 1608 * The Internet checksum is the one's complement of the one's
hudakz 3:5b17e4656dd0 1609 * complement sum of all 16-bit words in the buffer.
hudakz 3:5b17e4656dd0 1610 *
hudakz 3:5b17e4656dd0 1611 * See RFC1071.
hudakz 3:5b17e4656dd0 1612 *
hudakz 3:5b17e4656dd0 1613 * \param buf A pointer to the buffer over which the checksum is to be
hudakz 3:5b17e4656dd0 1614 * computed.
hudakz 3:5b17e4656dd0 1615 *
hudakz 3:5b17e4656dd0 1616 * \param len The length of the buffer over which the checksum is to
hudakz 3:5b17e4656dd0 1617 * be computed.
hudakz 3:5b17e4656dd0 1618 *
hudakz 3:5b17e4656dd0 1619 * \return The Internet checksum of the buffer.
hudakz 3:5b17e4656dd0 1620 */
hudakz 3:5b17e4656dd0 1621 u16_t uip_chksum(u16_t* buf, u16_t len);
hudakz 3:5b17e4656dd0 1622
hudakz 3:5b17e4656dd0 1623 /**
hudakz 3:5b17e4656dd0 1624 * Calculate the IP header checksum of the packet header in uip_buf.
hudakz 3:5b17e4656dd0 1625 *
hudakz 3:5b17e4656dd0 1626 * The IP header checksum is the Internet checksum of the 20 bytes of
hudakz 3:5b17e4656dd0 1627 * the IP header.
hudakz 3:5b17e4656dd0 1628 *
hudakz 3:5b17e4656dd0 1629 * \return The IP header checksum of the IP header in the uip_buf
hudakz 3:5b17e4656dd0 1630 * buffer.
hudakz 3:5b17e4656dd0 1631 */
hudakz 3:5b17e4656dd0 1632 u16_t uip_ipchksum(void);
hudakz 3:5b17e4656dd0 1633
hudakz 3:5b17e4656dd0 1634 /**
hudakz 3:5b17e4656dd0 1635 * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
hudakz 3:5b17e4656dd0 1636 *
hudakz 3:5b17e4656dd0 1637 * The TCP checksum is the Internet checksum of data contents of the
hudakz 3:5b17e4656dd0 1638 * TCP segment, and a pseudo-header as defined in RFC793.
hudakz 3:5b17e4656dd0 1639 *
hudakz 3:5b17e4656dd0 1640 * \return The TCP checksum of the TCP segment in uip_buf and pointed
hudakz 3:5b17e4656dd0 1641 * to by uip_appdata.
hudakz 3:5b17e4656dd0 1642 */
hudakz 3:5b17e4656dd0 1643 u16_t uip_tcpchksum(void);
hudakz 3:5b17e4656dd0 1644
hudakz 3:5b17e4656dd0 1645 /**
hudakz 3:5b17e4656dd0 1646 * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
hudakz 3:5b17e4656dd0 1647 *
hudakz 3:5b17e4656dd0 1648 * The UDP checksum is the Internet checksum of data contents of the
hudakz 3:5b17e4656dd0 1649 * UDP segment, and a pseudo-header as defined in RFC768.
hudakz 3:5b17e4656dd0 1650 *
hudakz 3:5b17e4656dd0 1651 * \return The UDP checksum of the UDP segment in uip_buf and pointed
hudakz 3:5b17e4656dd0 1652 * to by uip_appdata.
hudakz 3:5b17e4656dd0 1653 */
hudakz 3:5b17e4656dd0 1654 u16_t uip_udpchksum(void);
hudakz 3:5b17e4656dd0 1655 #endif /* __UIP_H__ */
hudakz 3:5b17e4656dd0 1656
hudakz 3:5b17e4656dd0 1657 /** @} */