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