ban4jp -
/
uIP-1-0_webserver
uIP 1.0 based webserver for LPC1114 + ENC28J60
uip/uip.h@3:a2715e9c7737, 2014-06-30 (annotated)
- Committer:
- ban4jp
- Date:
- Mon Jun 30 16:00:08 2014 +0000
- Revision:
- 3:a2715e9c7737
- Parent:
- 0:685224d2f66d
backported from Contiki 2.7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ban4jp | 0:685224d2f66d | 1 | |
ban4jp | 0:685224d2f66d | 2 | /** |
ban4jp | 0:685224d2f66d | 3 | * \addtogroup uip |
ban4jp | 0:685224d2f66d | 4 | * @{ |
ban4jp | 0:685224d2f66d | 5 | */ |
ban4jp | 0:685224d2f66d | 6 | |
ban4jp | 0:685224d2f66d | 7 | /** |
ban4jp | 0:685224d2f66d | 8 | * \file |
ban4jp | 0:685224d2f66d | 9 | * Header file for the uIP TCP/IP stack. |
ban4jp | 3:a2715e9c7737 | 10 | * \author Adam Dunkels <adam@dunkels.com> |
ban4jp | 3:a2715e9c7737 | 11 | * \author Julien Abeille <jabeille@cisco.com> (IPv6 related code) |
ban4jp | 3:a2715e9c7737 | 12 | * \author Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code) |
ban4jp | 0:685224d2f66d | 13 | * |
ban4jp | 0:685224d2f66d | 14 | * The uIP TCP/IP stack header file contains definitions for a number |
ban4jp | 0:685224d2f66d | 15 | * of C macros that are used by uIP programs as well as internal uIP |
ban4jp | 0:685224d2f66d | 16 | * structures, TCP/IP header structures and function declarations. |
ban4jp | 0:685224d2f66d | 17 | * |
ban4jp | 0:685224d2f66d | 18 | */ |
ban4jp | 0:685224d2f66d | 19 | |
ban4jp | 0:685224d2f66d | 20 | /* |
ban4jp | 0:685224d2f66d | 21 | * Copyright (c) 2001-2003, Adam Dunkels. |
ban4jp | 0:685224d2f66d | 22 | * All rights reserved. |
ban4jp | 0:685224d2f66d | 23 | * |
ban4jp | 0:685224d2f66d | 24 | * Redistribution and use in source and binary forms, with or without |
ban4jp | 0:685224d2f66d | 25 | * modification, are permitted provided that the following conditions |
ban4jp | 0:685224d2f66d | 26 | * are met: |
ban4jp | 0:685224d2f66d | 27 | * 1. Redistributions of source code must retain the above copyright |
ban4jp | 0:685224d2f66d | 28 | * notice, this list of conditions and the following disclaimer. |
ban4jp | 0:685224d2f66d | 29 | * 2. Redistributions in binary form must reproduce the above copyright |
ban4jp | 0:685224d2f66d | 30 | * notice, this list of conditions and the following disclaimer in the |
ban4jp | 0:685224d2f66d | 31 | * documentation and/or other materials provided with the distribution. |
ban4jp | 0:685224d2f66d | 32 | * 3. The name of the author may not be used to endorse or promote |
ban4jp | 0:685224d2f66d | 33 | * products derived from this software without specific prior |
ban4jp | 0:685224d2f66d | 34 | * written permission. |
ban4jp | 0:685224d2f66d | 35 | * |
ban4jp | 0:685224d2f66d | 36 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
ban4jp | 0:685224d2f66d | 37 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
ban4jp | 0:685224d2f66d | 38 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
ban4jp | 0:685224d2f66d | 39 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
ban4jp | 0:685224d2f66d | 40 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ban4jp | 0:685224d2f66d | 41 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
ban4jp | 0:685224d2f66d | 42 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
ban4jp | 0:685224d2f66d | 43 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
ban4jp | 0:685224d2f66d | 44 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
ban4jp | 0:685224d2f66d | 45 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
ban4jp | 0:685224d2f66d | 46 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ban4jp | 0:685224d2f66d | 47 | * |
ban4jp | 0:685224d2f66d | 48 | * This file is part of the uIP TCP/IP stack. |
ban4jp | 0:685224d2f66d | 49 | * |
ban4jp | 0:685224d2f66d | 50 | * |
ban4jp | 0:685224d2f66d | 51 | */ |
ban4jp | 0:685224d2f66d | 52 | |
ban4jp | 0:685224d2f66d | 53 | #ifndef __UIP_H__ |
ban4jp | 0:685224d2f66d | 54 | #define __UIP_H__ |
ban4jp | 0:685224d2f66d | 55 | |
ban4jp | 0:685224d2f66d | 56 | #include "uipopt.h" |
ban4jp | 0:685224d2f66d | 57 | |
ban4jp | 0:685224d2f66d | 58 | /** |
ban4jp | 3:a2715e9c7737 | 59 | * Representation of an IP address. |
ban4jp | 0:685224d2f66d | 60 | * |
ban4jp | 0:685224d2f66d | 61 | */ |
ban4jp | 3:a2715e9c7737 | 62 | typedef union uip_ip4addr_t { |
ban4jp | 3:a2715e9c7737 | 63 | uint8_t u8[4]; /* Initializer, must come first. */ |
ban4jp | 3:a2715e9c7737 | 64 | uint16_t u16[2]; |
ban4jp | 3:a2715e9c7737 | 65 | } uip_ip4addr_t; |
ban4jp | 3:a2715e9c7737 | 66 | |
ban4jp | 3:a2715e9c7737 | 67 | typedef union uip_ip6addr_t { |
ban4jp | 3:a2715e9c7737 | 68 | uint8_t u8[16]; /* Initializer, must come first. */ |
ban4jp | 3:a2715e9c7737 | 69 | uint16_t u16[8]; |
ban4jp | 3:a2715e9c7737 | 70 | } uip_ip6addr_t; |
ban4jp | 3:a2715e9c7737 | 71 | |
ban4jp | 0:685224d2f66d | 72 | #if UIP_CONF_IPV6 |
ban4jp | 0:685224d2f66d | 73 | typedef uip_ip6addr_t uip_ipaddr_t; |
ban4jp | 0:685224d2f66d | 74 | #else /* UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 75 | typedef uip_ip4addr_t uip_ipaddr_t; |
ban4jp | 0:685224d2f66d | 76 | #endif /* UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 77 | |
ban4jp | 3:a2715e9c7737 | 78 | |
ban4jp | 3:a2715e9c7737 | 79 | /*---------------------------------------------------------------------------*/ |
ban4jp | 3:a2715e9c7737 | 80 | |
ban4jp | 3:a2715e9c7737 | 81 | /** \brief 16 bit 802.15.4 address */ |
ban4jp | 3:a2715e9c7737 | 82 | typedef struct uip_802154_shortaddr { |
ban4jp | 3:a2715e9c7737 | 83 | uint8_t addr[2]; |
ban4jp | 3:a2715e9c7737 | 84 | } uip_802154_shortaddr; |
ban4jp | 3:a2715e9c7737 | 85 | /** \brief 64 bit 802.15.4 address */ |
ban4jp | 3:a2715e9c7737 | 86 | typedef struct uip_802154_longaddr { |
ban4jp | 3:a2715e9c7737 | 87 | uint8_t addr[8]; |
ban4jp | 3:a2715e9c7737 | 88 | } uip_802154_longaddr; |
ban4jp | 3:a2715e9c7737 | 89 | |
ban4jp | 3:a2715e9c7737 | 90 | /** \brief 802.11 address */ |
ban4jp | 3:a2715e9c7737 | 91 | typedef struct uip_80211_addr { |
ban4jp | 3:a2715e9c7737 | 92 | uint8_t addr[6]; |
ban4jp | 3:a2715e9c7737 | 93 | } uip_80211_addr; |
ban4jp | 3:a2715e9c7737 | 94 | |
ban4jp | 3:a2715e9c7737 | 95 | /** \brief 802.3 address */ |
ban4jp | 3:a2715e9c7737 | 96 | typedef struct uip_eth_addr { |
ban4jp | 3:a2715e9c7737 | 97 | uint8_t addr[6]; |
ban4jp | 3:a2715e9c7737 | 98 | } uip_eth_addr; |
ban4jp | 3:a2715e9c7737 | 99 | |
ban4jp | 3:a2715e9c7737 | 100 | |
ban4jp | 3:a2715e9c7737 | 101 | #if UIP_CONF_LL_802154 |
ban4jp | 3:a2715e9c7737 | 102 | /** \brief 802.15.4 address */ |
ban4jp | 3:a2715e9c7737 | 103 | typedef uip_802154_longaddr uip_lladdr_t; |
ban4jp | 3:a2715e9c7737 | 104 | #define UIP_802154_SHORTADDR_LEN 2 |
ban4jp | 3:a2715e9c7737 | 105 | #define UIP_802154_LONGADDR_LEN 8 |
ban4jp | 3:a2715e9c7737 | 106 | #define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN |
ban4jp | 3:a2715e9c7737 | 107 | #else /*UIP_CONF_LL_802154*/ |
ban4jp | 3:a2715e9c7737 | 108 | #if UIP_CONF_LL_80211 |
ban4jp | 3:a2715e9c7737 | 109 | /** \brief 802.11 address */ |
ban4jp | 3:a2715e9c7737 | 110 | typedef uip_80211_addr uip_lladdr_t; |
ban4jp | 3:a2715e9c7737 | 111 | #define UIP_LLADDR_LEN 6 |
ban4jp | 3:a2715e9c7737 | 112 | #else /*UIP_CONF_LL_80211*/ |
ban4jp | 3:a2715e9c7737 | 113 | /** \brief Ethernet address */ |
ban4jp | 3:a2715e9c7737 | 114 | typedef uip_eth_addr uip_lladdr_t; |
ban4jp | 3:a2715e9c7737 | 115 | #define UIP_LLADDR_LEN 6 |
ban4jp | 3:a2715e9c7737 | 116 | #endif /*UIP_CONF_LL_80211*/ |
ban4jp | 3:a2715e9c7737 | 117 | #endif /*UIP_CONF_LL_802154*/ |
ban4jp | 3:a2715e9c7737 | 118 | |
ban4jp | 3:a2715e9c7737 | 119 | //#include "tcpip.h" |
ban4jp | 3:a2715e9c7737 | 120 | |
ban4jp | 0:685224d2f66d | 121 | /*---------------------------------------------------------------------------*/ |
ban4jp | 0:685224d2f66d | 122 | /* First, the functions that should be called from the |
ban4jp | 3:a2715e9c7737 | 123 | * system. Initialization, the periodic timer, and incoming packets are |
ban4jp | 0:685224d2f66d | 124 | * handled by the following three functions. |
ban4jp | 0:685224d2f66d | 125 | */ |
ban4jp | 0:685224d2f66d | 126 | /** |
ban4jp | 0:685224d2f66d | 127 | * \defgroup uipconffunc uIP configuration functions |
ban4jp | 0:685224d2f66d | 128 | * @{ |
ban4jp | 0:685224d2f66d | 129 | * |
ban4jp | 0:685224d2f66d | 130 | * The uIP configuration functions are used for setting run-time |
ban4jp | 0:685224d2f66d | 131 | * parameters in uIP such as IP addresses. |
ban4jp | 0:685224d2f66d | 132 | */ |
ban4jp | 0:685224d2f66d | 133 | |
ban4jp | 0:685224d2f66d | 134 | /** |
ban4jp | 0:685224d2f66d | 135 | * Set the IP address of this host. |
ban4jp | 0:685224d2f66d | 136 | * |
ban4jp | 0:685224d2f66d | 137 | * The IP address is represented as a 4-byte array where the first |
ban4jp | 0:685224d2f66d | 138 | * octet of the IP address is put in the first member of the 4-byte |
ban4jp | 0:685224d2f66d | 139 | * array. |
ban4jp | 0:685224d2f66d | 140 | * |
ban4jp | 0:685224d2f66d | 141 | * Example: |
ban4jp | 0:685224d2f66d | 142 | \code |
ban4jp | 0:685224d2f66d | 143 | |
ban4jp | 0:685224d2f66d | 144 | uip_ipaddr_t addr; |
ban4jp | 0:685224d2f66d | 145 | |
ban4jp | 0:685224d2f66d | 146 | uip_ipaddr(&addr, 192,168,1,2); |
ban4jp | 0:685224d2f66d | 147 | uip_sethostaddr(&addr); |
ban4jp | 0:685224d2f66d | 148 | |
ban4jp | 0:685224d2f66d | 149 | \endcode |
ban4jp | 0:685224d2f66d | 150 | * \param addr A pointer to an IP address of type uip_ipaddr_t; |
ban4jp | 0:685224d2f66d | 151 | * |
ban4jp | 0:685224d2f66d | 152 | * \sa uip_ipaddr() |
ban4jp | 0:685224d2f66d | 153 | * |
ban4jp | 0:685224d2f66d | 154 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 155 | */ |
ban4jp | 3:a2715e9c7737 | 156 | #define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr)) |
ban4jp | 0:685224d2f66d | 157 | |
ban4jp | 0:685224d2f66d | 158 | /** |
ban4jp | 0:685224d2f66d | 159 | * Get the IP address of this host. |
ban4jp | 0:685224d2f66d | 160 | * |
ban4jp | 0:685224d2f66d | 161 | * The IP address is represented as a 4-byte array where the first |
ban4jp | 0:685224d2f66d | 162 | * octet of the IP address is put in the first member of the 4-byte |
ban4jp | 0:685224d2f66d | 163 | * array. |
ban4jp | 0:685224d2f66d | 164 | * |
ban4jp | 0:685224d2f66d | 165 | * Example: |
ban4jp | 0:685224d2f66d | 166 | \code |
ban4jp | 0:685224d2f66d | 167 | uip_ipaddr_t hostaddr; |
ban4jp | 0:685224d2f66d | 168 | |
ban4jp | 0:685224d2f66d | 169 | uip_gethostaddr(&hostaddr); |
ban4jp | 0:685224d2f66d | 170 | \endcode |
ban4jp | 0:685224d2f66d | 171 | * \param addr A pointer to a uip_ipaddr_t variable that will be |
ban4jp | 0:685224d2f66d | 172 | * filled in with the currently configured IP address. |
ban4jp | 0:685224d2f66d | 173 | * |
ban4jp | 0:685224d2f66d | 174 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 175 | */ |
ban4jp | 3:a2715e9c7737 | 176 | #define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr) |
ban4jp | 0:685224d2f66d | 177 | |
ban4jp | 0:685224d2f66d | 178 | /** |
ban4jp | 0:685224d2f66d | 179 | * Set the default router's IP address. |
ban4jp | 0:685224d2f66d | 180 | * |
ban4jp | 0:685224d2f66d | 181 | * \param addr A pointer to a uip_ipaddr_t variable containing the IP |
ban4jp | 0:685224d2f66d | 182 | * address of the default router. |
ban4jp | 0:685224d2f66d | 183 | * |
ban4jp | 0:685224d2f66d | 184 | * \sa uip_ipaddr() |
ban4jp | 0:685224d2f66d | 185 | * |
ban4jp | 0:685224d2f66d | 186 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 187 | */ |
ban4jp | 3:a2715e9c7737 | 188 | #define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr)) |
ban4jp | 0:685224d2f66d | 189 | |
ban4jp | 0:685224d2f66d | 190 | /** |
ban4jp | 0:685224d2f66d | 191 | * Set the netmask. |
ban4jp | 0:685224d2f66d | 192 | * |
ban4jp | 0:685224d2f66d | 193 | * \param addr A pointer to a uip_ipaddr_t variable containing the IP |
ban4jp | 0:685224d2f66d | 194 | * address of the netmask. |
ban4jp | 0:685224d2f66d | 195 | * |
ban4jp | 0:685224d2f66d | 196 | * \sa uip_ipaddr() |
ban4jp | 0:685224d2f66d | 197 | * |
ban4jp | 0:685224d2f66d | 198 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 199 | */ |
ban4jp | 3:a2715e9c7737 | 200 | #define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr)) |
ban4jp | 0:685224d2f66d | 201 | |
ban4jp | 0:685224d2f66d | 202 | |
ban4jp | 0:685224d2f66d | 203 | /** |
ban4jp | 0:685224d2f66d | 204 | * Get the default router's IP address. |
ban4jp | 0:685224d2f66d | 205 | * |
ban4jp | 0:685224d2f66d | 206 | * \param addr A pointer to a uip_ipaddr_t variable that will be |
ban4jp | 0:685224d2f66d | 207 | * filled in with the IP address of the default router. |
ban4jp | 0:685224d2f66d | 208 | * |
ban4jp | 0:685224d2f66d | 209 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 210 | */ |
ban4jp | 3:a2715e9c7737 | 211 | #define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr) |
ban4jp | 0:685224d2f66d | 212 | |
ban4jp | 0:685224d2f66d | 213 | /** |
ban4jp | 0:685224d2f66d | 214 | * Get the netmask. |
ban4jp | 0:685224d2f66d | 215 | * |
ban4jp | 0:685224d2f66d | 216 | * \param addr A pointer to a uip_ipaddr_t variable that will be |
ban4jp | 0:685224d2f66d | 217 | * filled in with the value of the netmask. |
ban4jp | 0:685224d2f66d | 218 | * |
ban4jp | 0:685224d2f66d | 219 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 220 | */ |
ban4jp | 3:a2715e9c7737 | 221 | #define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask) |
ban4jp | 0:685224d2f66d | 222 | |
ban4jp | 0:685224d2f66d | 223 | /** @} */ |
ban4jp | 0:685224d2f66d | 224 | |
ban4jp | 0:685224d2f66d | 225 | /** |
ban4jp | 0:685224d2f66d | 226 | * \defgroup uipinit uIP initialization functions |
ban4jp | 0:685224d2f66d | 227 | * @{ |
ban4jp | 0:685224d2f66d | 228 | * |
ban4jp | 0:685224d2f66d | 229 | * The uIP initialization functions are used for booting uIP. |
ban4jp | 0:685224d2f66d | 230 | */ |
ban4jp | 0:685224d2f66d | 231 | |
ban4jp | 0:685224d2f66d | 232 | /** |
ban4jp | 0:685224d2f66d | 233 | * uIP initialization function. |
ban4jp | 0:685224d2f66d | 234 | * |
ban4jp | 0:685224d2f66d | 235 | * This function should be called at boot up to initilize the uIP |
ban4jp | 0:685224d2f66d | 236 | * TCP/IP stack. |
ban4jp | 0:685224d2f66d | 237 | */ |
ban4jp | 0:685224d2f66d | 238 | void uip_init(void); |
ban4jp | 0:685224d2f66d | 239 | |
ban4jp | 0:685224d2f66d | 240 | /** |
ban4jp | 0:685224d2f66d | 241 | * uIP initialization function. |
ban4jp | 0:685224d2f66d | 242 | * |
ban4jp | 0:685224d2f66d | 243 | * This function may be used at boot time to set the initial ip_id. |
ban4jp | 0:685224d2f66d | 244 | */ |
ban4jp | 3:a2715e9c7737 | 245 | void uip_setipid(uint16_t id); |
ban4jp | 0:685224d2f66d | 246 | |
ban4jp | 0:685224d2f66d | 247 | /** @} */ |
ban4jp | 0:685224d2f66d | 248 | |
ban4jp | 0:685224d2f66d | 249 | /** |
ban4jp | 0:685224d2f66d | 250 | * \defgroup uipdevfunc uIP device driver functions |
ban4jp | 0:685224d2f66d | 251 | * @{ |
ban4jp | 0:685224d2f66d | 252 | * |
ban4jp | 0:685224d2f66d | 253 | * These functions are used by a network device driver for interacting |
ban4jp | 0:685224d2f66d | 254 | * with uIP. |
ban4jp | 0:685224d2f66d | 255 | */ |
ban4jp | 0:685224d2f66d | 256 | |
ban4jp | 0:685224d2f66d | 257 | /** |
ban4jp | 0:685224d2f66d | 258 | * Process an incoming packet. |
ban4jp | 0:685224d2f66d | 259 | * |
ban4jp | 0:685224d2f66d | 260 | * This function should be called when the device driver has received |
ban4jp | 0:685224d2f66d | 261 | * a packet from the network. The packet from the device driver must |
ban4jp | 0:685224d2f66d | 262 | * be present in the uip_buf buffer, and the length of the packet |
ban4jp | 0:685224d2f66d | 263 | * should be placed in the uip_len variable. |
ban4jp | 0:685224d2f66d | 264 | * |
ban4jp | 0:685224d2f66d | 265 | * When the function returns, there may be an outbound packet placed |
ban4jp | 0:685224d2f66d | 266 | * in the uip_buf packet buffer. If so, the uip_len variable is set to |
ban4jp | 0:685224d2f66d | 267 | * the length of the packet. If no packet is to be sent out, the |
ban4jp | 0:685224d2f66d | 268 | * uip_len variable is set to 0. |
ban4jp | 0:685224d2f66d | 269 | * |
ban4jp | 0:685224d2f66d | 270 | * The usual way of calling the function is presented by the source |
ban4jp | 0:685224d2f66d | 271 | * code below. |
ban4jp | 0:685224d2f66d | 272 | \code |
ban4jp | 3:a2715e9c7737 | 273 | uip_len = devicedriver_poll(); |
ban4jp | 3:a2715e9c7737 | 274 | if(uip_len > 0) { |
ban4jp | 3:a2715e9c7737 | 275 | uip_input(); |
ban4jp | 3:a2715e9c7737 | 276 | if(uip_len > 0) { |
ban4jp | 3:a2715e9c7737 | 277 | devicedriver_send(); |
ban4jp | 3:a2715e9c7737 | 278 | } |
ban4jp | 3:a2715e9c7737 | 279 | } |
ban4jp | 0:685224d2f66d | 280 | \endcode |
ban4jp | 0:685224d2f66d | 281 | * |
ban4jp | 0:685224d2f66d | 282 | * \note If you are writing a uIP device driver that needs ARP |
ban4jp | 0:685224d2f66d | 283 | * (Address Resolution Protocol), e.g., when running uIP over |
ban4jp | 0:685224d2f66d | 284 | * Ethernet, you will need to call the uIP ARP code before calling |
ban4jp | 0:685224d2f66d | 285 | * this function: |
ban4jp | 0:685224d2f66d | 286 | \code |
ban4jp | 3:a2715e9c7737 | 287 | #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) |
ban4jp | 3:a2715e9c7737 | 288 | uip_len = ethernet_devicedrver_poll(); |
ban4jp | 3:a2715e9c7737 | 289 | if(uip_len > 0) { |
ban4jp | 3:a2715e9c7737 | 290 | if(BUF->type == UIP_HTONS(UIP_ETHTYPE_IP)) { |
ban4jp | 3:a2715e9c7737 | 291 | uip_arp_ipin(); |
ban4jp | 3:a2715e9c7737 | 292 | uip_input(); |
ban4jp | 3:a2715e9c7737 | 293 | if(uip_len > 0) { |
ban4jp | 3:a2715e9c7737 | 294 | uip_arp_out(); |
ban4jp | 3:a2715e9c7737 | 295 | ethernet_devicedriver_send(); |
ban4jp | 3:a2715e9c7737 | 296 | } |
ban4jp | 3:a2715e9c7737 | 297 | } else if(BUF->type == UIP_HTONS(UIP_ETHTYPE_ARP)) { |
ban4jp | 3:a2715e9c7737 | 298 | uip_arp_arpin(); |
ban4jp | 3:a2715e9c7737 | 299 | if(uip_len > 0) { |
ban4jp | 3:a2715e9c7737 | 300 | ethernet_devicedriver_send(); |
ban4jp | 3:a2715e9c7737 | 301 | } |
ban4jp | 3:a2715e9c7737 | 302 | } |
ban4jp | 0:685224d2f66d | 303 | \endcode |
ban4jp | 0:685224d2f66d | 304 | * |
ban4jp | 0:685224d2f66d | 305 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 306 | */ |
ban4jp | 0:685224d2f66d | 307 | #define uip_input() uip_process(UIP_DATA) |
ban4jp | 0:685224d2f66d | 308 | |
ban4jp | 3:a2715e9c7737 | 309 | |
ban4jp | 0:685224d2f66d | 310 | /** |
ban4jp | 0:685224d2f66d | 311 | * Periodic processing for a connection identified by its number. |
ban4jp | 0:685224d2f66d | 312 | * |
ban4jp | 0:685224d2f66d | 313 | * This function does the necessary periodic processing (timers, |
ban4jp | 0:685224d2f66d | 314 | * polling) for a uIP TCP conneciton, and should be called when the |
ban4jp | 0:685224d2f66d | 315 | * periodic uIP timer goes off. It should be called for every |
ban4jp | 0:685224d2f66d | 316 | * connection, regardless of whether they are open of closed. |
ban4jp | 0:685224d2f66d | 317 | * |
ban4jp | 0:685224d2f66d | 318 | * When the function returns, it may have an outbound packet waiting |
ban4jp | 0:685224d2f66d | 319 | * for service in the uIP packet buffer, and if so the uip_len |
ban4jp | 0:685224d2f66d | 320 | * variable is set to a value larger than zero. The device driver |
ban4jp | 0:685224d2f66d | 321 | * should be called to send out the packet. |
ban4jp | 0:685224d2f66d | 322 | * |
ban4jp | 3:a2715e9c7737 | 323 | * The usual way of calling the function is through a for() loop like |
ban4jp | 0:685224d2f66d | 324 | * this: |
ban4jp | 0:685224d2f66d | 325 | \code |
ban4jp | 3:a2715e9c7737 | 326 | for(i = 0; i < UIP_CONNS; ++i) { |
ban4jp | 3:a2715e9c7737 | 327 | uip_periodic(i); |
ban4jp | 3:a2715e9c7737 | 328 | if(uip_len > 0) { |
ban4jp | 3:a2715e9c7737 | 329 | devicedriver_send(); |
ban4jp | 3:a2715e9c7737 | 330 | } |
ban4jp | 3:a2715e9c7737 | 331 | } |
ban4jp | 0:685224d2f66d | 332 | \endcode |
ban4jp | 0:685224d2f66d | 333 | * |
ban4jp | 0:685224d2f66d | 334 | * \note If you are writing a uIP device driver that needs ARP |
ban4jp | 0:685224d2f66d | 335 | * (Address Resolution Protocol), e.g., when running uIP over |
ban4jp | 0:685224d2f66d | 336 | * Ethernet, you will need to call the uip_arp_out() function before |
ban4jp | 0:685224d2f66d | 337 | * calling the device driver: |
ban4jp | 0:685224d2f66d | 338 | \code |
ban4jp | 3:a2715e9c7737 | 339 | for(i = 0; i < UIP_CONNS; ++i) { |
ban4jp | 3:a2715e9c7737 | 340 | uip_periodic(i); |
ban4jp | 3:a2715e9c7737 | 341 | if(uip_len > 0) { |
ban4jp | 3:a2715e9c7737 | 342 | uip_arp_out(); |
ban4jp | 3:a2715e9c7737 | 343 | ethernet_devicedriver_send(); |
ban4jp | 3:a2715e9c7737 | 344 | } |
ban4jp | 3:a2715e9c7737 | 345 | } |
ban4jp | 0:685224d2f66d | 346 | \endcode |
ban4jp | 0:685224d2f66d | 347 | * |
ban4jp | 0:685224d2f66d | 348 | * \param conn The number of the connection which is to be periodically polled. |
ban4jp | 0:685224d2f66d | 349 | * |
ban4jp | 0:685224d2f66d | 350 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 351 | */ |
ban4jp | 3:a2715e9c7737 | 352 | #if UIP_TCP |
ban4jp | 3:a2715e9c7737 | 353 | #define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \ |
ban4jp | 3:a2715e9c7737 | 354 | uip_process(UIP_TIMER); } while (0) |
ban4jp | 0:685224d2f66d | 355 | |
ban4jp | 0:685224d2f66d | 356 | /** |
ban4jp | 0:685224d2f66d | 357 | * |
ban4jp | 0:685224d2f66d | 358 | * |
ban4jp | 0:685224d2f66d | 359 | */ |
ban4jp | 0:685224d2f66d | 360 | #define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED) |
ban4jp | 0:685224d2f66d | 361 | |
ban4jp | 0:685224d2f66d | 362 | /** |
ban4jp | 0:685224d2f66d | 363 | * Perform periodic processing for a connection identified by a pointer |
ban4jp | 0:685224d2f66d | 364 | * to its structure. |
ban4jp | 0:685224d2f66d | 365 | * |
ban4jp | 0:685224d2f66d | 366 | * Same as uip_periodic() but takes a pointer to the actual uip_conn |
ban4jp | 0:685224d2f66d | 367 | * struct instead of an integer as its argument. This function can be |
ban4jp | 0:685224d2f66d | 368 | * used to force periodic processing of a specific connection. |
ban4jp | 0:685224d2f66d | 369 | * |
ban4jp | 0:685224d2f66d | 370 | * \param conn A pointer to the uip_conn struct for the connection to |
ban4jp | 0:685224d2f66d | 371 | * be processed. |
ban4jp | 0:685224d2f66d | 372 | * |
ban4jp | 0:685224d2f66d | 373 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 374 | */ |
ban4jp | 3:a2715e9c7737 | 375 | #define uip_periodic_conn(conn) do { uip_conn = conn; \ |
ban4jp | 3:a2715e9c7737 | 376 | uip_process(UIP_TIMER); } while (0) |
ban4jp | 0:685224d2f66d | 377 | |
ban4jp | 0:685224d2f66d | 378 | /** |
ban4jp | 3:a2715e9c7737 | 379 | * Request that a particular connection should be polled. |
ban4jp | 0:685224d2f66d | 380 | * |
ban4jp | 0:685224d2f66d | 381 | * Similar to uip_periodic_conn() but does not perform any timer |
ban4jp | 0:685224d2f66d | 382 | * processing. The application is polled for new data. |
ban4jp | 0:685224d2f66d | 383 | * |
ban4jp | 0:685224d2f66d | 384 | * \param conn A pointer to the uip_conn struct for the connection to |
ban4jp | 0:685224d2f66d | 385 | * be processed. |
ban4jp | 0:685224d2f66d | 386 | * |
ban4jp | 0:685224d2f66d | 387 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 388 | */ |
ban4jp | 3:a2715e9c7737 | 389 | #define uip_poll_conn(conn) do { uip_conn = conn; \ |
ban4jp | 3:a2715e9c7737 | 390 | uip_process(UIP_POLL_REQUEST); } while (0) |
ban4jp | 0:685224d2f66d | 391 | |
ban4jp | 3:a2715e9c7737 | 392 | #endif /* UIP_TCP */ |
ban4jp | 0:685224d2f66d | 393 | |
ban4jp | 0:685224d2f66d | 394 | #if UIP_UDP |
ban4jp | 0:685224d2f66d | 395 | /** |
ban4jp | 0:685224d2f66d | 396 | * Periodic processing for a UDP connection identified by its number. |
ban4jp | 0:685224d2f66d | 397 | * |
ban4jp | 0:685224d2f66d | 398 | * This function is essentially the same as uip_periodic(), but for |
ban4jp | 0:685224d2f66d | 399 | * UDP connections. It is called in a similar fashion as the |
ban4jp | 0:685224d2f66d | 400 | * uip_periodic() function: |
ban4jp | 0:685224d2f66d | 401 | \code |
ban4jp | 3:a2715e9c7737 | 402 | for(i = 0; i < UIP_UDP_CONNS; i++) { |
ban4jp | 3:a2715e9c7737 | 403 | uip_udp_periodic(i); |
ban4jp | 3:a2715e9c7737 | 404 | if(uip_len > 0) { |
ban4jp | 3:a2715e9c7737 | 405 | devicedriver_send(); |
ban4jp | 3:a2715e9c7737 | 406 | } |
ban4jp | 3:a2715e9c7737 | 407 | } |
ban4jp | 0:685224d2f66d | 408 | \endcode |
ban4jp | 0:685224d2f66d | 409 | * |
ban4jp | 0:685224d2f66d | 410 | * \note As for the uip_periodic() function, special care has to be |
ban4jp | 0:685224d2f66d | 411 | * taken when using uIP together with ARP and Ethernet: |
ban4jp | 0:685224d2f66d | 412 | \code |
ban4jp | 3:a2715e9c7737 | 413 | for(i = 0; i < UIP_UDP_CONNS; i++) { |
ban4jp | 3:a2715e9c7737 | 414 | uip_udp_periodic(i); |
ban4jp | 3:a2715e9c7737 | 415 | if(uip_len > 0) { |
ban4jp | 3:a2715e9c7737 | 416 | uip_arp_out(); |
ban4jp | 3:a2715e9c7737 | 417 | ethernet_devicedriver_send(); |
ban4jp | 3:a2715e9c7737 | 418 | } |
ban4jp | 3:a2715e9c7737 | 419 | } |
ban4jp | 0:685224d2f66d | 420 | \endcode |
ban4jp | 0:685224d2f66d | 421 | * |
ban4jp | 0:685224d2f66d | 422 | * \param conn The number of the UDP connection to be processed. |
ban4jp | 0:685224d2f66d | 423 | * |
ban4jp | 0:685224d2f66d | 424 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 425 | */ |
ban4jp | 0:685224d2f66d | 426 | #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \ |
ban4jp | 3:a2715e9c7737 | 427 | uip_process(UIP_UDP_TIMER); } while(0) |
ban4jp | 0:685224d2f66d | 428 | |
ban4jp | 0:685224d2f66d | 429 | /** |
ban4jp | 0:685224d2f66d | 430 | * Periodic processing for a UDP connection identified by a pointer to |
ban4jp | 0:685224d2f66d | 431 | * its structure. |
ban4jp | 0:685224d2f66d | 432 | * |
ban4jp | 0:685224d2f66d | 433 | * Same as uip_udp_periodic() but takes a pointer to the actual |
ban4jp | 0:685224d2f66d | 434 | * uip_conn struct instead of an integer as its argument. This |
ban4jp | 0:685224d2f66d | 435 | * function can be used to force periodic processing of a specific |
ban4jp | 0:685224d2f66d | 436 | * connection. |
ban4jp | 0:685224d2f66d | 437 | * |
ban4jp | 0:685224d2f66d | 438 | * \param conn A pointer to the uip_udp_conn struct for the connection |
ban4jp | 0:685224d2f66d | 439 | * to be processed. |
ban4jp | 0:685224d2f66d | 440 | * |
ban4jp | 0:685224d2f66d | 441 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 442 | */ |
ban4jp | 3:a2715e9c7737 | 443 | #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \ |
ban4jp | 3:a2715e9c7737 | 444 | uip_process(UIP_UDP_TIMER); } while(0) |
ban4jp | 3:a2715e9c7737 | 445 | #endif /* UIP_UDP */ |
ban4jp | 0:685224d2f66d | 446 | |
ban4jp | 3:a2715e9c7737 | 447 | /** \brief Abandon the reassembly of the current packet */ |
ban4jp | 3:a2715e9c7737 | 448 | void uip_reass_over(void); |
ban4jp | 0:685224d2f66d | 449 | |
ban4jp | 0:685224d2f66d | 450 | /** |
ban4jp | 0:685224d2f66d | 451 | * The uIP packet buffer. |
ban4jp | 0:685224d2f66d | 452 | * |
ban4jp | 0:685224d2f66d | 453 | * The uip_buf array is used to hold incoming and outgoing |
ban4jp | 0:685224d2f66d | 454 | * packets. The device driver should place incoming data into this |
ban4jp | 0:685224d2f66d | 455 | * buffer. When sending data, the device driver should read the link |
ban4jp | 0:685224d2f66d | 456 | * level headers and the TCP/IP headers from this buffer. The size of |
ban4jp | 0:685224d2f66d | 457 | * the link level headers is configured by the UIP_LLH_LEN define. |
ban4jp | 0:685224d2f66d | 458 | * |
ban4jp | 0:685224d2f66d | 459 | * \note The application data need not be placed in this buffer, so |
ban4jp | 0:685224d2f66d | 460 | * the device driver must read it from the place pointed to by the |
ban4jp | 0:685224d2f66d | 461 | * uip_appdata pointer as illustrated by the following example: |
ban4jp | 0:685224d2f66d | 462 | \code |
ban4jp | 0:685224d2f66d | 463 | void |
ban4jp | 0:685224d2f66d | 464 | devicedriver_send(void) |
ban4jp | 0:685224d2f66d | 465 | { |
ban4jp | 3:a2715e9c7737 | 466 | hwsend(&uip_buf[0], UIP_LLH_LEN); |
ban4jp | 3:a2715e9c7737 | 467 | if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) { |
ban4jp | 3:a2715e9c7737 | 468 | hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN); |
ban4jp | 3:a2715e9c7737 | 469 | } else { |
ban4jp | 3:a2715e9c7737 | 470 | hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN); |
ban4jp | 3:a2715e9c7737 | 471 | hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN); |
ban4jp | 3:a2715e9c7737 | 472 | } |
ban4jp | 0:685224d2f66d | 473 | } |
ban4jp | 0:685224d2f66d | 474 | \endcode |
ban4jp | 3:a2715e9c7737 | 475 | */ |
ban4jp | 3:a2715e9c7737 | 476 | |
ban4jp | 3:a2715e9c7737 | 477 | typedef union { |
ban4jp | 3:a2715e9c7737 | 478 | uint32_t u32[(UIP_BUFSIZE + 3) / 4]; |
ban4jp | 3:a2715e9c7737 | 479 | uint8_t u8[UIP_BUFSIZE]; |
ban4jp | 3:a2715e9c7737 | 480 | } uip_buf_t; |
ban4jp | 3:a2715e9c7737 | 481 | |
ban4jp | 3:a2715e9c7737 | 482 | CCIF extern uip_buf_t uip_aligned_buf; |
ban4jp | 3:a2715e9c7737 | 483 | #define uip_buf (uip_aligned_buf.u8) |
ban4jp | 3:a2715e9c7737 | 484 | |
ban4jp | 0:685224d2f66d | 485 | |
ban4jp | 0:685224d2f66d | 486 | /** @} */ |
ban4jp | 0:685224d2f66d | 487 | |
ban4jp | 0:685224d2f66d | 488 | /*---------------------------------------------------------------------------*/ |
ban4jp | 0:685224d2f66d | 489 | /* Functions that are used by the uIP application program. Opening and |
ban4jp | 0:685224d2f66d | 490 | * closing connections, sending and receiving data, etc. is all |
ban4jp | 0:685224d2f66d | 491 | * handled by the functions below. |
ban4jp | 3:a2715e9c7737 | 492 | */ |
ban4jp | 0:685224d2f66d | 493 | /** |
ban4jp | 0:685224d2f66d | 494 | * \defgroup uipappfunc uIP application functions |
ban4jp | 0:685224d2f66d | 495 | * @{ |
ban4jp | 0:685224d2f66d | 496 | * |
ban4jp | 0:685224d2f66d | 497 | * Functions used by an application running of top of uIP. |
ban4jp | 0:685224d2f66d | 498 | */ |
ban4jp | 0:685224d2f66d | 499 | |
ban4jp | 0:685224d2f66d | 500 | /** |
ban4jp | 0:685224d2f66d | 501 | * Start listening to the specified port. |
ban4jp | 0:685224d2f66d | 502 | * |
ban4jp | 0:685224d2f66d | 503 | * \note Since this function expects the port number in network byte |
ban4jp | 3:a2715e9c7737 | 504 | * order, a conversion using UIP_HTONS() or uip_htons() is necessary. |
ban4jp | 0:685224d2f66d | 505 | * |
ban4jp | 0:685224d2f66d | 506 | \code |
ban4jp | 3:a2715e9c7737 | 507 | uip_listen(UIP_HTONS(80)); |
ban4jp | 0:685224d2f66d | 508 | \endcode |
ban4jp | 0:685224d2f66d | 509 | * |
ban4jp | 0:685224d2f66d | 510 | * \param port A 16-bit port number in network byte order. |
ban4jp | 0:685224d2f66d | 511 | */ |
ban4jp | 3:a2715e9c7737 | 512 | void uip_listen(uint16_t port); |
ban4jp | 0:685224d2f66d | 513 | |
ban4jp | 0:685224d2f66d | 514 | /** |
ban4jp | 0:685224d2f66d | 515 | * Stop listening to the specified port. |
ban4jp | 0:685224d2f66d | 516 | * |
ban4jp | 0:685224d2f66d | 517 | * \note Since this function expects the port number in network byte |
ban4jp | 3:a2715e9c7737 | 518 | * order, a conversion using UIP_HTONS() or uip_htons() is necessary. |
ban4jp | 0:685224d2f66d | 519 | * |
ban4jp | 0:685224d2f66d | 520 | \code |
ban4jp | 3:a2715e9c7737 | 521 | uip_unlisten(UIP_HTONS(80)); |
ban4jp | 0:685224d2f66d | 522 | \endcode |
ban4jp | 0:685224d2f66d | 523 | * |
ban4jp | 0:685224d2f66d | 524 | * \param port A 16-bit port number in network byte order. |
ban4jp | 0:685224d2f66d | 525 | */ |
ban4jp | 3:a2715e9c7737 | 526 | void uip_unlisten(uint16_t port); |
ban4jp | 0:685224d2f66d | 527 | |
ban4jp | 0:685224d2f66d | 528 | /** |
ban4jp | 0:685224d2f66d | 529 | * Connect to a remote host using TCP. |
ban4jp | 0:685224d2f66d | 530 | * |
ban4jp | 0:685224d2f66d | 531 | * This function is used to start a new connection to the specified |
ban4jp | 3:a2715e9c7737 | 532 | * port on the specified host. It allocates a new connection identifier, |
ban4jp | 0:685224d2f66d | 533 | * sets the connection to the SYN_SENT state and sets the |
ban4jp | 0:685224d2f66d | 534 | * retransmission timer to 0. This will cause a TCP SYN segment to be |
ban4jp | 0:685224d2f66d | 535 | * sent out the next time this connection is periodically processed, |
ban4jp | 0:685224d2f66d | 536 | * which usually is done within 0.5 seconds after the call to |
ban4jp | 0:685224d2f66d | 537 | * uip_connect(). |
ban4jp | 0:685224d2f66d | 538 | * |
ban4jp | 3:a2715e9c7737 | 539 | * \note This function is available only if support for active open |
ban4jp | 0:685224d2f66d | 540 | * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h. |
ban4jp | 0:685224d2f66d | 541 | * |
ban4jp | 0:685224d2f66d | 542 | * \note Since this function requires the port number to be in network |
ban4jp | 3:a2715e9c7737 | 543 | * byte order, a conversion using UIP_HTONS() or uip_htons() is necessary. |
ban4jp | 0:685224d2f66d | 544 | * |
ban4jp | 0:685224d2f66d | 545 | \code |
ban4jp | 0:685224d2f66d | 546 | uip_ipaddr_t ipaddr; |
ban4jp | 0:685224d2f66d | 547 | |
ban4jp | 0:685224d2f66d | 548 | uip_ipaddr(&ipaddr, 192,168,1,2); |
ban4jp | 3:a2715e9c7737 | 549 | uip_connect(&ipaddr, UIP_HTONS(80)); |
ban4jp | 0:685224d2f66d | 550 | \endcode |
ban4jp | 0:685224d2f66d | 551 | * |
ban4jp | 3:a2715e9c7737 | 552 | * \param ripaddr The IP address of the remote host. |
ban4jp | 0:685224d2f66d | 553 | * |
ban4jp | 0:685224d2f66d | 554 | * \param port A 16-bit port number in network byte order. |
ban4jp | 0:685224d2f66d | 555 | * |
ban4jp | 0:685224d2f66d | 556 | * \return A pointer to the uIP connection identifier for the new connection, |
ban4jp | 0:685224d2f66d | 557 | * or NULL if no connection could be allocated. |
ban4jp | 0:685224d2f66d | 558 | * |
ban4jp | 0:685224d2f66d | 559 | */ |
ban4jp | 3:a2715e9c7737 | 560 | struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, uint16_t port); |
ban4jp | 0:685224d2f66d | 561 | |
ban4jp | 0:685224d2f66d | 562 | |
ban4jp | 0:685224d2f66d | 563 | |
ban4jp | 0:685224d2f66d | 564 | /** |
ban4jp | 0:685224d2f66d | 565 | * \internal |
ban4jp | 0:685224d2f66d | 566 | * |
ban4jp | 0:685224d2f66d | 567 | * Check if a connection has outstanding (i.e., unacknowledged) data. |
ban4jp | 0:685224d2f66d | 568 | * |
ban4jp | 0:685224d2f66d | 569 | * \param conn A pointer to the uip_conn structure for the connection. |
ban4jp | 0:685224d2f66d | 570 | * |
ban4jp | 0:685224d2f66d | 571 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 572 | */ |
ban4jp | 0:685224d2f66d | 573 | #define uip_outstanding(conn) ((conn)->len) |
ban4jp | 0:685224d2f66d | 574 | |
ban4jp | 0:685224d2f66d | 575 | /** |
ban4jp | 0:685224d2f66d | 576 | * Send data on the current connection. |
ban4jp | 0:685224d2f66d | 577 | * |
ban4jp | 0:685224d2f66d | 578 | * This function is used to send out a single segment of TCP |
ban4jp | 0:685224d2f66d | 579 | * data. Only applications that have been invoked by uIP for event |
ban4jp | 0:685224d2f66d | 580 | * processing can send data. |
ban4jp | 0:685224d2f66d | 581 | * |
ban4jp | 0:685224d2f66d | 582 | * The amount of data that actually is sent out after a call to this |
ban4jp | 3:a2715e9c7737 | 583 | * function is determined by the maximum amount of data TCP allows. uIP |
ban4jp | 0:685224d2f66d | 584 | * will automatically crop the data so that only the appropriate |
ban4jp | 0:685224d2f66d | 585 | * amount of data is sent. The function uip_mss() can be used to query |
ban4jp | 0:685224d2f66d | 586 | * uIP for the amount of data that actually will be sent. |
ban4jp | 0:685224d2f66d | 587 | * |
ban4jp | 0:685224d2f66d | 588 | * \note This function does not guarantee that the sent data will |
ban4jp | 0:685224d2f66d | 589 | * arrive at the destination. If the data is lost in the network, the |
ban4jp | 0:685224d2f66d | 590 | * application will be invoked with the uip_rexmit() event being |
ban4jp | 0:685224d2f66d | 591 | * set. The application will then have to resend the data using this |
ban4jp | 0:685224d2f66d | 592 | * function. |
ban4jp | 0:685224d2f66d | 593 | * |
ban4jp | 0:685224d2f66d | 594 | * \param data A pointer to the data which is to be sent. |
ban4jp | 0:685224d2f66d | 595 | * |
ban4jp | 0:685224d2f66d | 596 | * \param len The maximum amount of data bytes to be sent. |
ban4jp | 0:685224d2f66d | 597 | * |
ban4jp | 0:685224d2f66d | 598 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 599 | */ |
ban4jp | 3:a2715e9c7737 | 600 | CCIF void uip_send(const void *data, int len); |
ban4jp | 0:685224d2f66d | 601 | |
ban4jp | 0:685224d2f66d | 602 | /** |
ban4jp | 3:a2715e9c7737 | 603 | * The length of any incoming data that is currently available (if available) |
ban4jp | 0:685224d2f66d | 604 | * in the uip_appdata buffer. |
ban4jp | 0:685224d2f66d | 605 | * |
ban4jp | 0:685224d2f66d | 606 | * The test function uip_data() must first be used to check if there |
ban4jp | 0:685224d2f66d | 607 | * is any data available at all. |
ban4jp | 0:685224d2f66d | 608 | * |
ban4jp | 0:685224d2f66d | 609 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 610 | */ |
ban4jp | 0:685224d2f66d | 611 | /*void uip_datalen(void);*/ |
ban4jp | 0:685224d2f66d | 612 | #define uip_datalen() uip_len |
ban4jp | 0:685224d2f66d | 613 | |
ban4jp | 0:685224d2f66d | 614 | /** |
ban4jp | 0:685224d2f66d | 615 | * The length of any out-of-band data (urgent data) that has arrived |
ban4jp | 0:685224d2f66d | 616 | * on the connection. |
ban4jp | 0:685224d2f66d | 617 | * |
ban4jp | 0:685224d2f66d | 618 | * \note The configuration parameter UIP_URGDATA must be set for this |
ban4jp | 0:685224d2f66d | 619 | * function to be enabled. |
ban4jp | 0:685224d2f66d | 620 | * |
ban4jp | 0:685224d2f66d | 621 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 622 | */ |
ban4jp | 0:685224d2f66d | 623 | #define uip_urgdatalen() uip_urglen |
ban4jp | 0:685224d2f66d | 624 | |
ban4jp | 0:685224d2f66d | 625 | /** |
ban4jp | 0:685224d2f66d | 626 | * Close the current connection. |
ban4jp | 0:685224d2f66d | 627 | * |
ban4jp | 0:685224d2f66d | 628 | * This function will close the current connection in a nice way. |
ban4jp | 0:685224d2f66d | 629 | * |
ban4jp | 0:685224d2f66d | 630 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 631 | */ |
ban4jp | 0:685224d2f66d | 632 | #define uip_close() (uip_flags = UIP_CLOSE) |
ban4jp | 0:685224d2f66d | 633 | |
ban4jp | 0:685224d2f66d | 634 | /** |
ban4jp | 0:685224d2f66d | 635 | * Abort the current connection. |
ban4jp | 0:685224d2f66d | 636 | * |
ban4jp | 0:685224d2f66d | 637 | * This function will abort (reset) the current connection, and is |
ban4jp | 3:a2715e9c7737 | 638 | * usually used when an error has occurred that prevents using the |
ban4jp | 0:685224d2f66d | 639 | * uip_close() function. |
ban4jp | 0:685224d2f66d | 640 | * |
ban4jp | 0:685224d2f66d | 641 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 642 | */ |
ban4jp | 0:685224d2f66d | 643 | #define uip_abort() (uip_flags = UIP_ABORT) |
ban4jp | 0:685224d2f66d | 644 | |
ban4jp | 0:685224d2f66d | 645 | /** |
ban4jp | 0:685224d2f66d | 646 | * Tell the sending host to stop sending data. |
ban4jp | 0:685224d2f66d | 647 | * |
ban4jp | 0:685224d2f66d | 648 | * This function will close our receiver's window so that we stop |
ban4jp | 0:685224d2f66d | 649 | * receiving data for the current connection. |
ban4jp | 0:685224d2f66d | 650 | * |
ban4jp | 0:685224d2f66d | 651 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 652 | */ |
ban4jp | 0:685224d2f66d | 653 | #define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED) |
ban4jp | 0:685224d2f66d | 654 | |
ban4jp | 0:685224d2f66d | 655 | /** |
ban4jp | 0:685224d2f66d | 656 | * Find out if the current connection has been previously stopped with |
ban4jp | 0:685224d2f66d | 657 | * uip_stop(). |
ban4jp | 0:685224d2f66d | 658 | * |
ban4jp | 0:685224d2f66d | 659 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 660 | */ |
ban4jp | 0:685224d2f66d | 661 | #define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED) |
ban4jp | 0:685224d2f66d | 662 | |
ban4jp | 0:685224d2f66d | 663 | /** |
ban4jp | 0:685224d2f66d | 664 | * Restart the current connection, if is has previously been stopped |
ban4jp | 0:685224d2f66d | 665 | * with uip_stop(). |
ban4jp | 0:685224d2f66d | 666 | * |
ban4jp | 0:685224d2f66d | 667 | * This function will open the receiver's window again so that we |
ban4jp | 0:685224d2f66d | 668 | * start receiving data for the current connection. |
ban4jp | 0:685224d2f66d | 669 | * |
ban4jp | 0:685224d2f66d | 670 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 671 | */ |
ban4jp | 3:a2715e9c7737 | 672 | #define uip_restart() do { uip_flags |= UIP_NEWDATA; \ |
ban4jp | 3:a2715e9c7737 | 673 | uip_conn->tcpstateflags &= ~UIP_STOPPED; \ |
ban4jp | 3:a2715e9c7737 | 674 | } while(0) |
ban4jp | 0:685224d2f66d | 675 | |
ban4jp | 0:685224d2f66d | 676 | |
ban4jp | 0:685224d2f66d | 677 | /* uIP tests that can be made to determine in what state the current |
ban4jp | 0:685224d2f66d | 678 | connection is, and what the application function should do. */ |
ban4jp | 0:685224d2f66d | 679 | |
ban4jp | 0:685224d2f66d | 680 | /** |
ban4jp | 0:685224d2f66d | 681 | * Is the current connection a UDP connection? |
ban4jp | 0:685224d2f66d | 682 | * |
ban4jp | 0:685224d2f66d | 683 | * This function checks whether the current connection is a UDP connection. |
ban4jp | 0:685224d2f66d | 684 | * |
ban4jp | 0:685224d2f66d | 685 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 686 | * |
ban4jp | 0:685224d2f66d | 687 | */ |
ban4jp | 0:685224d2f66d | 688 | #define uip_udpconnection() (uip_conn == NULL) |
ban4jp | 0:685224d2f66d | 689 | |
ban4jp | 0:685224d2f66d | 690 | /** |
ban4jp | 0:685224d2f66d | 691 | * Is new incoming data available? |
ban4jp | 0:685224d2f66d | 692 | * |
ban4jp | 0:685224d2f66d | 693 | * Will reduce to non-zero if there is new data for the application |
ban4jp | 0:685224d2f66d | 694 | * present at the uip_appdata pointer. The size of the data is |
ban4jp | 3:a2715e9c7737 | 695 | * available through the uip_len variable. |
ban4jp | 0:685224d2f66d | 696 | * |
ban4jp | 0:685224d2f66d | 697 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 698 | */ |
ban4jp | 0:685224d2f66d | 699 | #define uip_newdata() (uip_flags & UIP_NEWDATA) |
ban4jp | 0:685224d2f66d | 700 | |
ban4jp | 0:685224d2f66d | 701 | /** |
ban4jp | 0:685224d2f66d | 702 | * Has previously sent data been acknowledged? |
ban4jp | 0:685224d2f66d | 703 | * |
ban4jp | 0:685224d2f66d | 704 | * Will reduce to non-zero if the previously sent data has been |
ban4jp | 0:685224d2f66d | 705 | * acknowledged by the remote host. This means that the application |
ban4jp | 0:685224d2f66d | 706 | * can send new data. |
ban4jp | 0:685224d2f66d | 707 | * |
ban4jp | 0:685224d2f66d | 708 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 709 | */ |
ban4jp | 0:685224d2f66d | 710 | #define uip_acked() (uip_flags & UIP_ACKDATA) |
ban4jp | 0:685224d2f66d | 711 | |
ban4jp | 0:685224d2f66d | 712 | /** |
ban4jp | 0:685224d2f66d | 713 | * Has the connection just been connected? |
ban4jp | 0:685224d2f66d | 714 | * |
ban4jp | 0:685224d2f66d | 715 | * Reduces to non-zero if the current connection has been connected to |
ban4jp | 0:685224d2f66d | 716 | * a remote host. This will happen both if the connection has been |
ban4jp | 0:685224d2f66d | 717 | * actively opened (with uip_connect()) or passively opened (with |
ban4jp | 0:685224d2f66d | 718 | * uip_listen()). |
ban4jp | 0:685224d2f66d | 719 | * |
ban4jp | 0:685224d2f66d | 720 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 721 | */ |
ban4jp | 0:685224d2f66d | 722 | #define uip_connected() (uip_flags & UIP_CONNECTED) |
ban4jp | 0:685224d2f66d | 723 | |
ban4jp | 0:685224d2f66d | 724 | /** |
ban4jp | 0:685224d2f66d | 725 | * Has the connection been closed by the other end? |
ban4jp | 0:685224d2f66d | 726 | * |
ban4jp | 0:685224d2f66d | 727 | * Is non-zero if the connection has been closed by the remote |
ban4jp | 0:685224d2f66d | 728 | * host. The application may then do the necessary clean-ups. |
ban4jp | 0:685224d2f66d | 729 | * |
ban4jp | 0:685224d2f66d | 730 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 731 | */ |
ban4jp | 0:685224d2f66d | 732 | #define uip_closed() (uip_flags & UIP_CLOSE) |
ban4jp | 0:685224d2f66d | 733 | |
ban4jp | 0:685224d2f66d | 734 | /** |
ban4jp | 0:685224d2f66d | 735 | * Has the connection been aborted by the other end? |
ban4jp | 0:685224d2f66d | 736 | * |
ban4jp | 0:685224d2f66d | 737 | * Non-zero if the current connection has been aborted (reset) by the |
ban4jp | 0:685224d2f66d | 738 | * remote host. |
ban4jp | 0:685224d2f66d | 739 | * |
ban4jp | 0:685224d2f66d | 740 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 741 | */ |
ban4jp | 0:685224d2f66d | 742 | #define uip_aborted() (uip_flags & UIP_ABORT) |
ban4jp | 0:685224d2f66d | 743 | |
ban4jp | 0:685224d2f66d | 744 | /** |
ban4jp | 0:685224d2f66d | 745 | * Has the connection timed out? |
ban4jp | 0:685224d2f66d | 746 | * |
ban4jp | 0:685224d2f66d | 747 | * Non-zero if the current connection has been aborted due to too many |
ban4jp | 0:685224d2f66d | 748 | * retransmissions. |
ban4jp | 0:685224d2f66d | 749 | * |
ban4jp | 0:685224d2f66d | 750 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 751 | */ |
ban4jp | 0:685224d2f66d | 752 | #define uip_timedout() (uip_flags & UIP_TIMEDOUT) |
ban4jp | 0:685224d2f66d | 753 | |
ban4jp | 0:685224d2f66d | 754 | /** |
ban4jp | 0:685224d2f66d | 755 | * Do we need to retransmit previously data? |
ban4jp | 0:685224d2f66d | 756 | * |
ban4jp | 0:685224d2f66d | 757 | * Reduces to non-zero if the previously sent data has been lost in |
ban4jp | 0:685224d2f66d | 758 | * the network, and the application should retransmit it. The |
ban4jp | 0:685224d2f66d | 759 | * application should send the exact same data as it did the last |
ban4jp | 0:685224d2f66d | 760 | * time, using the uip_send() function. |
ban4jp | 0:685224d2f66d | 761 | * |
ban4jp | 0:685224d2f66d | 762 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 763 | */ |
ban4jp | 0:685224d2f66d | 764 | #define uip_rexmit() (uip_flags & UIP_REXMIT) |
ban4jp | 0:685224d2f66d | 765 | |
ban4jp | 0:685224d2f66d | 766 | /** |
ban4jp | 0:685224d2f66d | 767 | * Is the connection being polled by uIP? |
ban4jp | 0:685224d2f66d | 768 | * |
ban4jp | 0:685224d2f66d | 769 | * Is non-zero if the reason the application is invoked is that the |
ban4jp | 0:685224d2f66d | 770 | * current connection has been idle for a while and should be |
ban4jp | 0:685224d2f66d | 771 | * polled. |
ban4jp | 0:685224d2f66d | 772 | * |
ban4jp | 0:685224d2f66d | 773 | * The polling event can be used for sending data without having to |
ban4jp | 0:685224d2f66d | 774 | * wait for the remote host to send data. |
ban4jp | 0:685224d2f66d | 775 | * |
ban4jp | 0:685224d2f66d | 776 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 777 | */ |
ban4jp | 0:685224d2f66d | 778 | #define uip_poll() (uip_flags & UIP_POLL) |
ban4jp | 0:685224d2f66d | 779 | |
ban4jp | 0:685224d2f66d | 780 | /** |
ban4jp | 3:a2715e9c7737 | 781 | * Get the initial maximum segment size (MSS) of the current |
ban4jp | 0:685224d2f66d | 782 | * connection. |
ban4jp | 0:685224d2f66d | 783 | * |
ban4jp | 0:685224d2f66d | 784 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 785 | */ |
ban4jp | 0:685224d2f66d | 786 | #define uip_initialmss() (uip_conn->initialmss) |
ban4jp | 0:685224d2f66d | 787 | |
ban4jp | 0:685224d2f66d | 788 | /** |
ban4jp | 3:a2715e9c7737 | 789 | * Get the current maximum segment size that can be sent on the current |
ban4jp | 0:685224d2f66d | 790 | * connection. |
ban4jp | 0:685224d2f66d | 791 | * |
ban4jp | 3:a2715e9c7737 | 792 | * The current maximum segment size that can be sent on the |
ban4jp | 0:685224d2f66d | 793 | * connection is computed from the receiver's window and the MSS of |
ban4jp | 0:685224d2f66d | 794 | * the connection (which also is available by calling |
ban4jp | 0:685224d2f66d | 795 | * uip_initialmss()). |
ban4jp | 0:685224d2f66d | 796 | * |
ban4jp | 0:685224d2f66d | 797 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 798 | */ |
ban4jp | 0:685224d2f66d | 799 | #define uip_mss() (uip_conn->mss) |
ban4jp | 0:685224d2f66d | 800 | |
ban4jp | 0:685224d2f66d | 801 | /** |
ban4jp | 0:685224d2f66d | 802 | * Set up a new UDP connection. |
ban4jp | 0:685224d2f66d | 803 | * |
ban4jp | 0:685224d2f66d | 804 | * This function sets up a new UDP connection. The function will |
ban4jp | 0:685224d2f66d | 805 | * automatically allocate an unused local port for the new |
ban4jp | 0:685224d2f66d | 806 | * connection. However, another port can be chosen by using the |
ban4jp | 0:685224d2f66d | 807 | * uip_udp_bind() call, after the uip_udp_new() function has been |
ban4jp | 0:685224d2f66d | 808 | * called. |
ban4jp | 0:685224d2f66d | 809 | * |
ban4jp | 0:685224d2f66d | 810 | * Example: |
ban4jp | 0:685224d2f66d | 811 | \code |
ban4jp | 0:685224d2f66d | 812 | uip_ipaddr_t addr; |
ban4jp | 0:685224d2f66d | 813 | struct uip_udp_conn *c; |
ban4jp | 0:685224d2f66d | 814 | |
ban4jp | 0:685224d2f66d | 815 | uip_ipaddr(&addr, 192,168,2,1); |
ban4jp | 3:a2715e9c7737 | 816 | c = uip_udp_new(&addr, UIP_HTONS(12345)); |
ban4jp | 0:685224d2f66d | 817 | if(c != NULL) { |
ban4jp | 3:a2715e9c7737 | 818 | uip_udp_bind(c, UIP_HTONS(12344)); |
ban4jp | 0:685224d2f66d | 819 | } |
ban4jp | 0:685224d2f66d | 820 | \endcode |
ban4jp | 0:685224d2f66d | 821 | * \param ripaddr The IP address of the remote host. |
ban4jp | 0:685224d2f66d | 822 | * |
ban4jp | 0:685224d2f66d | 823 | * \param rport The remote port number in network byte order. |
ban4jp | 0:685224d2f66d | 824 | * |
ban4jp | 3:a2715e9c7737 | 825 | * \return The uip_udp_conn structure for the new connection, or NULL |
ban4jp | 0:685224d2f66d | 826 | * if no connection could be allocated. |
ban4jp | 0:685224d2f66d | 827 | */ |
ban4jp | 3:a2715e9c7737 | 828 | struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport); |
ban4jp | 0:685224d2f66d | 829 | |
ban4jp | 0:685224d2f66d | 830 | /** |
ban4jp | 3:a2715e9c7737 | 831 | * Remove a UDP connection. |
ban4jp | 0:685224d2f66d | 832 | * |
ban4jp | 0:685224d2f66d | 833 | * \param conn A pointer to the uip_udp_conn structure for the connection. |
ban4jp | 0:685224d2f66d | 834 | * |
ban4jp | 0:685224d2f66d | 835 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 836 | */ |
ban4jp | 0:685224d2f66d | 837 | #define uip_udp_remove(conn) (conn)->lport = 0 |
ban4jp | 0:685224d2f66d | 838 | |
ban4jp | 0:685224d2f66d | 839 | /** |
ban4jp | 0:685224d2f66d | 840 | * Bind a UDP connection to a local port. |
ban4jp | 0:685224d2f66d | 841 | * |
ban4jp | 0:685224d2f66d | 842 | * \param conn A pointer to the uip_udp_conn structure for the |
ban4jp | 0:685224d2f66d | 843 | * connection. |
ban4jp | 0:685224d2f66d | 844 | * |
ban4jp | 0:685224d2f66d | 845 | * \param port The local port number, in network byte order. |
ban4jp | 0:685224d2f66d | 846 | * |
ban4jp | 0:685224d2f66d | 847 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 848 | */ |
ban4jp | 0:685224d2f66d | 849 | #define uip_udp_bind(conn, port) (conn)->lport = port |
ban4jp | 0:685224d2f66d | 850 | |
ban4jp | 0:685224d2f66d | 851 | /** |
ban4jp | 0:685224d2f66d | 852 | * Send a UDP datagram of length len on the current connection. |
ban4jp | 0:685224d2f66d | 853 | * |
ban4jp | 0:685224d2f66d | 854 | * This function can only be called in response to a UDP event (poll |
ban4jp | 0:685224d2f66d | 855 | * or newdata). The data must be present in the uip_buf buffer, at the |
ban4jp | 0:685224d2f66d | 856 | * place pointed to by the uip_appdata pointer. |
ban4jp | 0:685224d2f66d | 857 | * |
ban4jp | 0:685224d2f66d | 858 | * \param len The length of the data in the uip_buf buffer. |
ban4jp | 0:685224d2f66d | 859 | * |
ban4jp | 0:685224d2f66d | 860 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 861 | */ |
ban4jp | 0:685224d2f66d | 862 | #define uip_udp_send(len) uip_send((char *)uip_appdata, len) |
ban4jp | 0:685224d2f66d | 863 | |
ban4jp | 0:685224d2f66d | 864 | /** @} */ |
ban4jp | 0:685224d2f66d | 865 | |
ban4jp | 0:685224d2f66d | 866 | /* uIP convenience and converting functions. */ |
ban4jp | 0:685224d2f66d | 867 | |
ban4jp | 0:685224d2f66d | 868 | /** |
ban4jp | 0:685224d2f66d | 869 | * \defgroup uipconvfunc uIP conversion functions |
ban4jp | 0:685224d2f66d | 870 | * @{ |
ban4jp | 0:685224d2f66d | 871 | * |
ban4jp | 0:685224d2f66d | 872 | * These functions can be used for converting between different data |
ban4jp | 0:685224d2f66d | 873 | * formats used by uIP. |
ban4jp | 0:685224d2f66d | 874 | */ |
ban4jp | 0:685224d2f66d | 875 | |
ban4jp | 0:685224d2f66d | 876 | /** |
ban4jp | 3:a2715e9c7737 | 877 | * Convert an IP address to four bytes separated by commas. |
ban4jp | 3:a2715e9c7737 | 878 | * |
ban4jp | 3:a2715e9c7737 | 879 | * Example: |
ban4jp | 3:a2715e9c7737 | 880 | \code |
ban4jp | 3:a2715e9c7737 | 881 | uip_ipaddr_t ipaddr; |
ban4jp | 3:a2715e9c7737 | 882 | printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr)); |
ban4jp | 3:a2715e9c7737 | 883 | \endcode |
ban4jp | 3:a2715e9c7737 | 884 | * |
ban4jp | 3:a2715e9c7737 | 885 | * \param a A pointer to a uip_ipaddr_t. |
ban4jp | 3:a2715e9c7737 | 886 | * \hideinitializer |
ban4jp | 3:a2715e9c7737 | 887 | */ |
ban4jp | 3:a2715e9c7737 | 888 | #define uip_ipaddr_to_quad(a) (a)->u8[0],(a)->u8[1],(a)->u8[2],(a)->u8[3] |
ban4jp | 3:a2715e9c7737 | 889 | |
ban4jp | 3:a2715e9c7737 | 890 | /** |
ban4jp | 0:685224d2f66d | 891 | * Construct an IP address from four bytes. |
ban4jp | 0:685224d2f66d | 892 | * |
ban4jp | 0:685224d2f66d | 893 | * This function constructs an IP address of the type that uIP handles |
ban4jp | 0:685224d2f66d | 894 | * internally from four bytes. The function is handy for specifying IP |
ban4jp | 0:685224d2f66d | 895 | * addresses to use with e.g. the uip_connect() function. |
ban4jp | 0:685224d2f66d | 896 | * |
ban4jp | 0:685224d2f66d | 897 | * Example: |
ban4jp | 0:685224d2f66d | 898 | \code |
ban4jp | 0:685224d2f66d | 899 | uip_ipaddr_t ipaddr; |
ban4jp | 0:685224d2f66d | 900 | struct uip_conn *c; |
ban4jp | 0:685224d2f66d | 901 | |
ban4jp | 0:685224d2f66d | 902 | uip_ipaddr(&ipaddr, 192,168,1,2); |
ban4jp | 3:a2715e9c7737 | 903 | c = uip_connect(&ipaddr, UIP_HTONS(80)); |
ban4jp | 0:685224d2f66d | 904 | \endcode |
ban4jp | 0:685224d2f66d | 905 | * |
ban4jp | 0:685224d2f66d | 906 | * \param addr A pointer to a uip_ipaddr_t variable that will be |
ban4jp | 0:685224d2f66d | 907 | * filled in with the IP address. |
ban4jp | 0:685224d2f66d | 908 | * |
ban4jp | 0:685224d2f66d | 909 | * \param addr0 The first octet of the IP address. |
ban4jp | 0:685224d2f66d | 910 | * \param addr1 The second octet of the IP address. |
ban4jp | 0:685224d2f66d | 911 | * \param addr2 The third octet of the IP address. |
ban4jp | 0:685224d2f66d | 912 | * \param addr3 The forth octet of the IP address. |
ban4jp | 0:685224d2f66d | 913 | * |
ban4jp | 0:685224d2f66d | 914 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 915 | */ |
ban4jp | 3:a2715e9c7737 | 916 | #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \ |
ban4jp | 3:a2715e9c7737 | 917 | (addr)->u8[0] = addr0; \ |
ban4jp | 3:a2715e9c7737 | 918 | (addr)->u8[1] = addr1; \ |
ban4jp | 3:a2715e9c7737 | 919 | (addr)->u8[2] = addr2; \ |
ban4jp | 3:a2715e9c7737 | 920 | (addr)->u8[3] = addr3; \ |
ban4jp | 3:a2715e9c7737 | 921 | } while(0) |
ban4jp | 0:685224d2f66d | 922 | |
ban4jp | 0:685224d2f66d | 923 | /** |
ban4jp | 0:685224d2f66d | 924 | * Construct an IPv6 address from eight 16-bit words. |
ban4jp | 0:685224d2f66d | 925 | * |
ban4jp | 0:685224d2f66d | 926 | * This function constructs an IPv6 address. |
ban4jp | 0:685224d2f66d | 927 | * |
ban4jp | 0:685224d2f66d | 928 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 929 | */ |
ban4jp | 0:685224d2f66d | 930 | #define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \ |
ban4jp | 3:a2715e9c7737 | 931 | (addr)->u16[0] = UIP_HTONS(addr0); \ |
ban4jp | 3:a2715e9c7737 | 932 | (addr)->u16[1] = UIP_HTONS(addr1); \ |
ban4jp | 3:a2715e9c7737 | 933 | (addr)->u16[2] = UIP_HTONS(addr2); \ |
ban4jp | 3:a2715e9c7737 | 934 | (addr)->u16[3] = UIP_HTONS(addr3); \ |
ban4jp | 3:a2715e9c7737 | 935 | (addr)->u16[4] = UIP_HTONS(addr4); \ |
ban4jp | 3:a2715e9c7737 | 936 | (addr)->u16[5] = UIP_HTONS(addr5); \ |
ban4jp | 3:a2715e9c7737 | 937 | (addr)->u16[6] = UIP_HTONS(addr6); \ |
ban4jp | 3:a2715e9c7737 | 938 | (addr)->u16[7] = UIP_HTONS(addr7); \ |
ban4jp | 3:a2715e9c7737 | 939 | } while(0) |
ban4jp | 0:685224d2f66d | 940 | |
ban4jp | 0:685224d2f66d | 941 | /** |
ban4jp | 3:a2715e9c7737 | 942 | * Construct an IPv6 address from sixteen 8-bit words. |
ban4jp | 3:a2715e9c7737 | 943 | * |
ban4jp | 3:a2715e9c7737 | 944 | * This function constructs an IPv6 address. |
ban4jp | 3:a2715e9c7737 | 945 | * |
ban4jp | 3:a2715e9c7737 | 946 | * \hideinitializer |
ban4jp | 3:a2715e9c7737 | 947 | */ |
ban4jp | 3:a2715e9c7737 | 948 | #define uip_ip6addr_u8(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7,addr8,addr9,addr10,addr11,addr12,addr13,addr14,addr15) do { \ |
ban4jp | 3:a2715e9c7737 | 949 | (addr)->u8[0] = addr0; \ |
ban4jp | 3:a2715e9c7737 | 950 | (addr)->u8[1] = addr1; \ |
ban4jp | 3:a2715e9c7737 | 951 | (addr)->u8[2] = addr2; \ |
ban4jp | 3:a2715e9c7737 | 952 | (addr)->u8[3] = addr3; \ |
ban4jp | 3:a2715e9c7737 | 953 | (addr)->u8[4] = addr4; \ |
ban4jp | 3:a2715e9c7737 | 954 | (addr)->u8[5] = addr5; \ |
ban4jp | 3:a2715e9c7737 | 955 | (addr)->u8[6] = addr6; \ |
ban4jp | 3:a2715e9c7737 | 956 | (addr)->u8[7] = addr7; \ |
ban4jp | 3:a2715e9c7737 | 957 | (addr)->u8[8] = addr8; \ |
ban4jp | 3:a2715e9c7737 | 958 | (addr)->u8[9] = addr9; \ |
ban4jp | 3:a2715e9c7737 | 959 | (addr)->u8[10] = addr10; \ |
ban4jp | 3:a2715e9c7737 | 960 | (addr)->u8[11] = addr11; \ |
ban4jp | 3:a2715e9c7737 | 961 | (addr)->u8[12] = addr12; \ |
ban4jp | 3:a2715e9c7737 | 962 | (addr)->u8[13] = addr13; \ |
ban4jp | 3:a2715e9c7737 | 963 | (addr)->u8[14] = addr14; \ |
ban4jp | 3:a2715e9c7737 | 964 | (addr)->u8[15] = addr15; \ |
ban4jp | 3:a2715e9c7737 | 965 | } while(0) |
ban4jp | 3:a2715e9c7737 | 966 | |
ban4jp | 3:a2715e9c7737 | 967 | |
ban4jp | 3:a2715e9c7737 | 968 | /** |
ban4jp | 3:a2715e9c7737 | 969 | * Copy an IP address from one place to another. |
ban4jp | 0:685224d2f66d | 970 | * |
ban4jp | 0:685224d2f66d | 971 | * Copies an IP address from one place to another. |
ban4jp | 0:685224d2f66d | 972 | * |
ban4jp | 0:685224d2f66d | 973 | * Example: |
ban4jp | 0:685224d2f66d | 974 | \code |
ban4jp | 0:685224d2f66d | 975 | uip_ipaddr_t ipaddr1, ipaddr2; |
ban4jp | 0:685224d2f66d | 976 | |
ban4jp | 0:685224d2f66d | 977 | uip_ipaddr(&ipaddr1, 192,16,1,2); |
ban4jp | 0:685224d2f66d | 978 | uip_ipaddr_copy(&ipaddr2, &ipaddr1); |
ban4jp | 0:685224d2f66d | 979 | \endcode |
ban4jp | 0:685224d2f66d | 980 | * |
ban4jp | 0:685224d2f66d | 981 | * \param dest The destination for the copy. |
ban4jp | 0:685224d2f66d | 982 | * \param src The source from where to copy. |
ban4jp | 0:685224d2f66d | 983 | * |
ban4jp | 0:685224d2f66d | 984 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 985 | */ |
ban4jp | 3:a2715e9c7737 | 986 | #ifndef uip_ipaddr_copy |
ban4jp | 3:a2715e9c7737 | 987 | #define uip_ipaddr_copy(dest, src) (*(dest) = *(src)) |
ban4jp | 3:a2715e9c7737 | 988 | #endif |
ban4jp | 3:a2715e9c7737 | 989 | #ifndef uip_ip4addr_copy |
ban4jp | 3:a2715e9c7737 | 990 | #define uip_ip4addr_copy(dest, src) (*(dest) = *(src)) |
ban4jp | 3:a2715e9c7737 | 991 | #endif |
ban4jp | 3:a2715e9c7737 | 992 | #ifndef uip_ip6addr_copy |
ban4jp | 3:a2715e9c7737 | 993 | #define uip_ip6addr_copy(dest, src) (*(dest) = *(src)) |
ban4jp | 3:a2715e9c7737 | 994 | #endif |
ban4jp | 0:685224d2f66d | 995 | |
ban4jp | 0:685224d2f66d | 996 | /** |
ban4jp | 0:685224d2f66d | 997 | * Compare two IP addresses |
ban4jp | 0:685224d2f66d | 998 | * |
ban4jp | 0:685224d2f66d | 999 | * Compares two IP addresses. |
ban4jp | 0:685224d2f66d | 1000 | * |
ban4jp | 0:685224d2f66d | 1001 | * Example: |
ban4jp | 0:685224d2f66d | 1002 | \code |
ban4jp | 0:685224d2f66d | 1003 | uip_ipaddr_t ipaddr1, ipaddr2; |
ban4jp | 0:685224d2f66d | 1004 | |
ban4jp | 0:685224d2f66d | 1005 | uip_ipaddr(&ipaddr1, 192,16,1,2); |
ban4jp | 0:685224d2f66d | 1006 | if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) { |
ban4jp | 3:a2715e9c7737 | 1007 | printf("They are the same"); |
ban4jp | 0:685224d2f66d | 1008 | } |
ban4jp | 0:685224d2f66d | 1009 | \endcode |
ban4jp | 0:685224d2f66d | 1010 | * |
ban4jp | 0:685224d2f66d | 1011 | * \param addr1 The first IP address. |
ban4jp | 0:685224d2f66d | 1012 | * \param addr2 The second IP address. |
ban4jp | 0:685224d2f66d | 1013 | * |
ban4jp | 0:685224d2f66d | 1014 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 1015 | */ |
ban4jp | 3:a2715e9c7737 | 1016 | #define uip_ip4addr_cmp(addr1, addr2) ((addr1)->u16[0] == (addr2)->u16[0] && \ |
ban4jp | 3:a2715e9c7737 | 1017 | (addr1)->u16[1] == (addr2)->u16[1]) |
ban4jp | 3:a2715e9c7737 | 1018 | #define uip_ip6addr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0) |
ban4jp | 3:a2715e9c7737 | 1019 | |
ban4jp | 3:a2715e9c7737 | 1020 | #if UIP_CONF_IPV6 |
ban4jp | 3:a2715e9c7737 | 1021 | #define uip_ipaddr_cmp(addr1, addr2) uip_ip6addr_cmp(addr1, addr2) |
ban4jp | 3:a2715e9c7737 | 1022 | #else /* UIP_CONF_IPV6 */ |
ban4jp | 3:a2715e9c7737 | 1023 | #define uip_ipaddr_cmp(addr1, addr2) uip_ip4addr_cmp(addr1, addr2) |
ban4jp | 3:a2715e9c7737 | 1024 | #endif /* UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 1025 | |
ban4jp | 0:685224d2f66d | 1026 | /** |
ban4jp | 0:685224d2f66d | 1027 | * Compare two IP addresses with netmasks |
ban4jp | 0:685224d2f66d | 1028 | * |
ban4jp | 0:685224d2f66d | 1029 | * Compares two IP addresses with netmasks. The masks are used to mask |
ban4jp | 0:685224d2f66d | 1030 | * out the bits that are to be compared. |
ban4jp | 0:685224d2f66d | 1031 | * |
ban4jp | 0:685224d2f66d | 1032 | * Example: |
ban4jp | 0:685224d2f66d | 1033 | \code |
ban4jp | 0:685224d2f66d | 1034 | uip_ipaddr_t ipaddr1, ipaddr2, mask; |
ban4jp | 0:685224d2f66d | 1035 | |
ban4jp | 0:685224d2f66d | 1036 | uip_ipaddr(&mask, 255,255,255,0); |
ban4jp | 0:685224d2f66d | 1037 | uip_ipaddr(&ipaddr1, 192,16,1,2); |
ban4jp | 0:685224d2f66d | 1038 | uip_ipaddr(&ipaddr2, 192,16,1,3); |
ban4jp | 0:685224d2f66d | 1039 | if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) { |
ban4jp | 3:a2715e9c7737 | 1040 | printf("They are the same"); |
ban4jp | 0:685224d2f66d | 1041 | } |
ban4jp | 0:685224d2f66d | 1042 | \endcode |
ban4jp | 0:685224d2f66d | 1043 | * |
ban4jp | 0:685224d2f66d | 1044 | * \param addr1 The first IP address. |
ban4jp | 0:685224d2f66d | 1045 | * \param addr2 The second IP address. |
ban4jp | 0:685224d2f66d | 1046 | * \param mask The netmask. |
ban4jp | 0:685224d2f66d | 1047 | * |
ban4jp | 0:685224d2f66d | 1048 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 1049 | */ |
ban4jp | 3:a2715e9c7737 | 1050 | |
ban4jp | 3:a2715e9c7737 | 1051 | #define uip_ipaddr_maskcmp(addr1, addr2, mask) \ |
ban4jp | 3:a2715e9c7737 | 1052 | (((((uint16_t *)addr1)[0] & ((uint16_t *)mask)[0]) == \ |
ban4jp | 3:a2715e9c7737 | 1053 | (((uint16_t *)addr2)[0] & ((uint16_t *)mask)[0])) && \ |
ban4jp | 3:a2715e9c7737 | 1054 | ((((uint16_t *)addr1)[1] & ((uint16_t *)mask)[1]) == \ |
ban4jp | 3:a2715e9c7737 | 1055 | (((uint16_t *)addr2)[1] & ((uint16_t *)mask)[1]))) |
ban4jp | 3:a2715e9c7737 | 1056 | |
ban4jp | 3:a2715e9c7737 | 1057 | #define uip_ipaddr_prefixcmp(addr1, addr2, length) (memcmp(addr1, addr2, length>>3) == 0) |
ban4jp | 3:a2715e9c7737 | 1058 | |
ban4jp | 3:a2715e9c7737 | 1059 | |
ban4jp | 3:a2715e9c7737 | 1060 | |
ban4jp | 3:a2715e9c7737 | 1061 | /** |
ban4jp | 3:a2715e9c7737 | 1062 | * Check if an address is a broadcast address for a network. |
ban4jp | 3:a2715e9c7737 | 1063 | * |
ban4jp | 3:a2715e9c7737 | 1064 | * Checks if an address is the broadcast address for a network. The |
ban4jp | 3:a2715e9c7737 | 1065 | * network is defined by an IP address that is on the network and the |
ban4jp | 3:a2715e9c7737 | 1066 | * network's netmask. |
ban4jp | 3:a2715e9c7737 | 1067 | * |
ban4jp | 3:a2715e9c7737 | 1068 | * \param addr The IP address. |
ban4jp | 3:a2715e9c7737 | 1069 | * \param netaddr The network's IP address. |
ban4jp | 3:a2715e9c7737 | 1070 | * \param netmask The network's netmask. |
ban4jp | 3:a2715e9c7737 | 1071 | * |
ban4jp | 3:a2715e9c7737 | 1072 | * \hideinitializer |
ban4jp | 3:a2715e9c7737 | 1073 | */ |
ban4jp | 3:a2715e9c7737 | 1074 | /*#define uip_ipaddr_isbroadcast(addr, netaddr, netmask) |
ban4jp | 3:a2715e9c7737 | 1075 | ((uip_ipaddr_t *)(addr)).u16 & ((uip_ipaddr_t *)(addr)).u16*/ |
ban4jp | 3:a2715e9c7737 | 1076 | |
ban4jp | 0:685224d2f66d | 1077 | |
ban4jp | 0:685224d2f66d | 1078 | |
ban4jp | 0:685224d2f66d | 1079 | /** |
ban4jp | 0:685224d2f66d | 1080 | * Mask out the network part of an IP address. |
ban4jp | 0:685224d2f66d | 1081 | * |
ban4jp | 0:685224d2f66d | 1082 | * Masks out the network part of an IP address, given the address and |
ban4jp | 0:685224d2f66d | 1083 | * the netmask. |
ban4jp | 0:685224d2f66d | 1084 | * |
ban4jp | 0:685224d2f66d | 1085 | * Example: |
ban4jp | 0:685224d2f66d | 1086 | \code |
ban4jp | 0:685224d2f66d | 1087 | uip_ipaddr_t ipaddr1, ipaddr2, netmask; |
ban4jp | 0:685224d2f66d | 1088 | |
ban4jp | 0:685224d2f66d | 1089 | uip_ipaddr(&ipaddr1, 192,16,1,2); |
ban4jp | 0:685224d2f66d | 1090 | uip_ipaddr(&netmask, 255,255,255,0); |
ban4jp | 0:685224d2f66d | 1091 | uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask); |
ban4jp | 0:685224d2f66d | 1092 | \endcode |
ban4jp | 0:685224d2f66d | 1093 | * |
ban4jp | 0:685224d2f66d | 1094 | * In the example above, the variable "ipaddr2" will contain the IP |
ban4jp | 0:685224d2f66d | 1095 | * address 192.168.1.0. |
ban4jp | 0:685224d2f66d | 1096 | * |
ban4jp | 0:685224d2f66d | 1097 | * \param dest Where the result is to be placed. |
ban4jp | 0:685224d2f66d | 1098 | * \param src The IP address. |
ban4jp | 0:685224d2f66d | 1099 | * \param mask The netmask. |
ban4jp | 0:685224d2f66d | 1100 | * |
ban4jp | 0:685224d2f66d | 1101 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 1102 | */ |
ban4jp | 3:a2715e9c7737 | 1103 | #define uip_ipaddr_mask(dest, src, mask) do { \ |
ban4jp | 3:a2715e9c7737 | 1104 | ((uint16_t *)dest)[0] = ((uint16_t *)src)[0] & ((uint16_t *)mask)[0]; \ |
ban4jp | 3:a2715e9c7737 | 1105 | ((uint16_t *)dest)[1] = ((uint16_t *)src)[1] & ((uint16_t *)mask)[1]; \ |
ban4jp | 3:a2715e9c7737 | 1106 | } while(0) |
ban4jp | 0:685224d2f66d | 1107 | |
ban4jp | 0:685224d2f66d | 1108 | /** |
ban4jp | 0:685224d2f66d | 1109 | * Pick the first octet of an IP address. |
ban4jp | 0:685224d2f66d | 1110 | * |
ban4jp | 0:685224d2f66d | 1111 | * Picks out the first octet of an IP address. |
ban4jp | 0:685224d2f66d | 1112 | * |
ban4jp | 0:685224d2f66d | 1113 | * Example: |
ban4jp | 0:685224d2f66d | 1114 | \code |
ban4jp | 0:685224d2f66d | 1115 | uip_ipaddr_t ipaddr; |
ban4jp | 3:a2715e9c7737 | 1116 | uint8_t octet; |
ban4jp | 0:685224d2f66d | 1117 | |
ban4jp | 0:685224d2f66d | 1118 | uip_ipaddr(&ipaddr, 1,2,3,4); |
ban4jp | 0:685224d2f66d | 1119 | octet = uip_ipaddr1(&ipaddr); |
ban4jp | 0:685224d2f66d | 1120 | \endcode |
ban4jp | 0:685224d2f66d | 1121 | * |
ban4jp | 0:685224d2f66d | 1122 | * In the example above, the variable "octet" will contain the value 1. |
ban4jp | 0:685224d2f66d | 1123 | * |
ban4jp | 0:685224d2f66d | 1124 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 1125 | */ |
ban4jp | 3:a2715e9c7737 | 1126 | #define uip_ipaddr1(addr) ((addr)->u8[0]) |
ban4jp | 0:685224d2f66d | 1127 | |
ban4jp | 0:685224d2f66d | 1128 | /** |
ban4jp | 0:685224d2f66d | 1129 | * Pick the second octet of an IP address. |
ban4jp | 0:685224d2f66d | 1130 | * |
ban4jp | 0:685224d2f66d | 1131 | * Picks out the second octet of an IP address. |
ban4jp | 0:685224d2f66d | 1132 | * |
ban4jp | 0:685224d2f66d | 1133 | * Example: |
ban4jp | 0:685224d2f66d | 1134 | \code |
ban4jp | 0:685224d2f66d | 1135 | uip_ipaddr_t ipaddr; |
ban4jp | 3:a2715e9c7737 | 1136 | uint8_t octet; |
ban4jp | 0:685224d2f66d | 1137 | |
ban4jp | 0:685224d2f66d | 1138 | uip_ipaddr(&ipaddr, 1,2,3,4); |
ban4jp | 0:685224d2f66d | 1139 | octet = uip_ipaddr2(&ipaddr); |
ban4jp | 0:685224d2f66d | 1140 | \endcode |
ban4jp | 0:685224d2f66d | 1141 | * |
ban4jp | 0:685224d2f66d | 1142 | * In the example above, the variable "octet" will contain the value 2. |
ban4jp | 0:685224d2f66d | 1143 | * |
ban4jp | 0:685224d2f66d | 1144 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 1145 | */ |
ban4jp | 3:a2715e9c7737 | 1146 | #define uip_ipaddr2(addr) ((addr)->u8[1]) |
ban4jp | 0:685224d2f66d | 1147 | |
ban4jp | 0:685224d2f66d | 1148 | /** |
ban4jp | 0:685224d2f66d | 1149 | * Pick the third octet of an IP address. |
ban4jp | 0:685224d2f66d | 1150 | * |
ban4jp | 0:685224d2f66d | 1151 | * Picks out the third octet of an IP address. |
ban4jp | 0:685224d2f66d | 1152 | * |
ban4jp | 0:685224d2f66d | 1153 | * Example: |
ban4jp | 0:685224d2f66d | 1154 | \code |
ban4jp | 0:685224d2f66d | 1155 | uip_ipaddr_t ipaddr; |
ban4jp | 3:a2715e9c7737 | 1156 | uint8_t octet; |
ban4jp | 0:685224d2f66d | 1157 | |
ban4jp | 0:685224d2f66d | 1158 | uip_ipaddr(&ipaddr, 1,2,3,4); |
ban4jp | 0:685224d2f66d | 1159 | octet = uip_ipaddr3(&ipaddr); |
ban4jp | 0:685224d2f66d | 1160 | \endcode |
ban4jp | 0:685224d2f66d | 1161 | * |
ban4jp | 0:685224d2f66d | 1162 | * In the example above, the variable "octet" will contain the value 3. |
ban4jp | 0:685224d2f66d | 1163 | * |
ban4jp | 0:685224d2f66d | 1164 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 1165 | */ |
ban4jp | 3:a2715e9c7737 | 1166 | #define uip_ipaddr3(addr) ((addr)->u8[2]) |
ban4jp | 0:685224d2f66d | 1167 | |
ban4jp | 0:685224d2f66d | 1168 | /** |
ban4jp | 0:685224d2f66d | 1169 | * Pick the fourth octet of an IP address. |
ban4jp | 0:685224d2f66d | 1170 | * |
ban4jp | 0:685224d2f66d | 1171 | * Picks out the fourth octet of an IP address. |
ban4jp | 0:685224d2f66d | 1172 | * |
ban4jp | 0:685224d2f66d | 1173 | * Example: |
ban4jp | 0:685224d2f66d | 1174 | \code |
ban4jp | 0:685224d2f66d | 1175 | uip_ipaddr_t ipaddr; |
ban4jp | 3:a2715e9c7737 | 1176 | uint8_t octet; |
ban4jp | 0:685224d2f66d | 1177 | |
ban4jp | 0:685224d2f66d | 1178 | uip_ipaddr(&ipaddr, 1,2,3,4); |
ban4jp | 0:685224d2f66d | 1179 | octet = uip_ipaddr4(&ipaddr); |
ban4jp | 0:685224d2f66d | 1180 | \endcode |
ban4jp | 0:685224d2f66d | 1181 | * |
ban4jp | 0:685224d2f66d | 1182 | * In the example above, the variable "octet" will contain the value 4. |
ban4jp | 0:685224d2f66d | 1183 | * |
ban4jp | 0:685224d2f66d | 1184 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 1185 | */ |
ban4jp | 3:a2715e9c7737 | 1186 | #define uip_ipaddr4(addr) ((addr)->u8[3]) |
ban4jp | 0:685224d2f66d | 1187 | |
ban4jp | 0:685224d2f66d | 1188 | /** |
ban4jp | 0:685224d2f66d | 1189 | * Convert 16-bit quantity from host byte order to network byte order. |
ban4jp | 0:685224d2f66d | 1190 | * |
ban4jp | 0:685224d2f66d | 1191 | * This macro is primarily used for converting constants from host |
ban4jp | 0:685224d2f66d | 1192 | * byte order to network byte order. For converting variables to |
ban4jp | 3:a2715e9c7737 | 1193 | * network byte order, use the uip_htons() function instead. |
ban4jp | 0:685224d2f66d | 1194 | * |
ban4jp | 0:685224d2f66d | 1195 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 1196 | */ |
ban4jp | 3:a2715e9c7737 | 1197 | #ifndef UIP_HTONS |
ban4jp | 0:685224d2f66d | 1198 | # if UIP_BYTE_ORDER == UIP_BIG_ENDIAN |
ban4jp | 3:a2715e9c7737 | 1199 | # define UIP_HTONS(n) (n) |
ban4jp | 3:a2715e9c7737 | 1200 | # define UIP_HTONL(n) (n) |
ban4jp | 0:685224d2f66d | 1201 | # else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ |
ban4jp | 3:a2715e9c7737 | 1202 | # define UIP_HTONS(n) (uint16_t)((((uint16_t) (n)) << 8) | (((uint16_t) (n)) >> 8)) |
ban4jp | 3:a2715e9c7737 | 1203 | # define UIP_HTONL(n) (((uint32_t)UIP_HTONS(n) << 16) | UIP_HTONS((uint32_t)(n) >> 16)) |
ban4jp | 0:685224d2f66d | 1204 | # endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ |
ban4jp | 0:685224d2f66d | 1205 | #else |
ban4jp | 3:a2715e9c7737 | 1206 | #error "UIP_HTONS already defined!" |
ban4jp | 3:a2715e9c7737 | 1207 | #endif /* UIP_HTONS */ |
ban4jp | 0:685224d2f66d | 1208 | |
ban4jp | 0:685224d2f66d | 1209 | /** |
ban4jp | 3:a2715e9c7737 | 1210 | * Convert a 16-bit quantity from host byte order to network byte order. |
ban4jp | 0:685224d2f66d | 1211 | * |
ban4jp | 0:685224d2f66d | 1212 | * This function is primarily used for converting variables from host |
ban4jp | 0:685224d2f66d | 1213 | * byte order to network byte order. For converting constants to |
ban4jp | 3:a2715e9c7737 | 1214 | * network byte order, use the UIP_HTONS() macro instead. |
ban4jp | 0:685224d2f66d | 1215 | */ |
ban4jp | 3:a2715e9c7737 | 1216 | #ifndef uip_htons |
ban4jp | 3:a2715e9c7737 | 1217 | CCIF uint16_t uip_htons(uint16_t val); |
ban4jp | 3:a2715e9c7737 | 1218 | #endif /* uip_htons */ |
ban4jp | 3:a2715e9c7737 | 1219 | #ifndef uip_ntohs |
ban4jp | 3:a2715e9c7737 | 1220 | #define uip_ntohs uip_htons |
ban4jp | 3:a2715e9c7737 | 1221 | #endif |
ban4jp | 3:a2715e9c7737 | 1222 | |
ban4jp | 3:a2715e9c7737 | 1223 | #ifndef uip_htonl |
ban4jp | 3:a2715e9c7737 | 1224 | CCIF uint32_t uip_htonl(uint32_t val); |
ban4jp | 3:a2715e9c7737 | 1225 | #endif /* uip_htonl */ |
ban4jp | 3:a2715e9c7737 | 1226 | #ifndef uip_ntohl |
ban4jp | 3:a2715e9c7737 | 1227 | #define uip_ntohl uip_htonl |
ban4jp | 0:685224d2f66d | 1228 | #endif |
ban4jp | 0:685224d2f66d | 1229 | |
ban4jp | 0:685224d2f66d | 1230 | /** @} */ |
ban4jp | 0:685224d2f66d | 1231 | |
ban4jp | 0:685224d2f66d | 1232 | /** |
ban4jp | 0:685224d2f66d | 1233 | * Pointer to the application data in the packet buffer. |
ban4jp | 0:685224d2f66d | 1234 | * |
ban4jp | 0:685224d2f66d | 1235 | * This pointer points to the application data when the application is |
ban4jp | 0:685224d2f66d | 1236 | * called. If the application wishes to send data, the application may |
ban4jp | 0:685224d2f66d | 1237 | * use this space to write the data into before calling uip_send(). |
ban4jp | 0:685224d2f66d | 1238 | */ |
ban4jp | 3:a2715e9c7737 | 1239 | CCIF extern void *uip_appdata; |
ban4jp | 0:685224d2f66d | 1240 | |
ban4jp | 0:685224d2f66d | 1241 | #if UIP_URGDATA > 0 |
ban4jp | 3:a2715e9c7737 | 1242 | /* uint8_t *uip_urgdata: |
ban4jp | 0:685224d2f66d | 1243 | * |
ban4jp | 0:685224d2f66d | 1244 | * This pointer points to any urgent data that has been received. Only |
ban4jp | 0:685224d2f66d | 1245 | * present if compiled with support for urgent data (UIP_URGDATA). |
ban4jp | 0:685224d2f66d | 1246 | */ |
ban4jp | 0:685224d2f66d | 1247 | extern void *uip_urgdata; |
ban4jp | 0:685224d2f66d | 1248 | #endif /* UIP_URGDATA > 0 */ |
ban4jp | 0:685224d2f66d | 1249 | |
ban4jp | 0:685224d2f66d | 1250 | |
ban4jp | 0:685224d2f66d | 1251 | /** |
ban4jp | 0:685224d2f66d | 1252 | * \defgroup uipdrivervars Variables used in uIP device drivers |
ban4jp | 0:685224d2f66d | 1253 | * @{ |
ban4jp | 0:685224d2f66d | 1254 | * |
ban4jp | 0:685224d2f66d | 1255 | * uIP has a few global variables that are used in device drivers for |
ban4jp | 0:685224d2f66d | 1256 | * uIP. |
ban4jp | 0:685224d2f66d | 1257 | */ |
ban4jp | 0:685224d2f66d | 1258 | |
ban4jp | 0:685224d2f66d | 1259 | /** |
ban4jp | 0:685224d2f66d | 1260 | * The length of the packet in the uip_buf buffer. |
ban4jp | 0:685224d2f66d | 1261 | * |
ban4jp | 0:685224d2f66d | 1262 | * The global variable uip_len holds the length of the packet in the |
ban4jp | 0:685224d2f66d | 1263 | * uip_buf buffer. |
ban4jp | 0:685224d2f66d | 1264 | * |
ban4jp | 0:685224d2f66d | 1265 | * When the network device driver calls the uIP input function, |
ban4jp | 0:685224d2f66d | 1266 | * uip_len should be set to the length of the packet in the uip_buf |
ban4jp | 0:685224d2f66d | 1267 | * buffer. |
ban4jp | 0:685224d2f66d | 1268 | * |
ban4jp | 0:685224d2f66d | 1269 | * When sending packets, the device driver should use the contents of |
ban4jp | 0:685224d2f66d | 1270 | * the uip_len variable to determine the length of the outgoing |
ban4jp | 0:685224d2f66d | 1271 | * packet. |
ban4jp | 0:685224d2f66d | 1272 | * |
ban4jp | 0:685224d2f66d | 1273 | */ |
ban4jp | 3:a2715e9c7737 | 1274 | CCIF extern uint16_t uip_len; |
ban4jp | 0:685224d2f66d | 1275 | |
ban4jp | 3:a2715e9c7737 | 1276 | /** |
ban4jp | 3:a2715e9c7737 | 1277 | * The length of the extension headers |
ban4jp | 3:a2715e9c7737 | 1278 | */ |
ban4jp | 3:a2715e9c7737 | 1279 | extern uint8_t uip_ext_len; |
ban4jp | 0:685224d2f66d | 1280 | /** @} */ |
ban4jp | 0:685224d2f66d | 1281 | |
ban4jp | 0:685224d2f66d | 1282 | #if UIP_URGDATA > 0 |
ban4jp | 3:a2715e9c7737 | 1283 | extern uint16_t uip_urglen, uip_surglen; |
ban4jp | 0:685224d2f66d | 1284 | #endif /* UIP_URGDATA > 0 */ |
ban4jp | 0:685224d2f66d | 1285 | |
ban4jp | 0:685224d2f66d | 1286 | |
ban4jp | 0:685224d2f66d | 1287 | /** |
ban4jp | 0:685224d2f66d | 1288 | * Representation of a uIP TCP connection. |
ban4jp | 0:685224d2f66d | 1289 | * |
ban4jp | 0:685224d2f66d | 1290 | * The uip_conn structure is used for identifying a connection. All |
ban4jp | 0:685224d2f66d | 1291 | * but one field in the structure are to be considered read-only by an |
ban4jp | 3:a2715e9c7737 | 1292 | * application. The only exception is the appstate field whose purpose |
ban4jp | 0:685224d2f66d | 1293 | * is to let the application store application-specific state (e.g., |
ban4jp | 0:685224d2f66d | 1294 | * file pointers) for the connection. The type of this field is |
ban4jp | 0:685224d2f66d | 1295 | * configured in the "uipopt.h" header file. |
ban4jp | 0:685224d2f66d | 1296 | */ |
ban4jp | 0:685224d2f66d | 1297 | struct uip_conn { |
ban4jp | 0:685224d2f66d | 1298 | uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */ |
ban4jp | 0:685224d2f66d | 1299 | |
ban4jp | 3:a2715e9c7737 | 1300 | uint16_t lport; /**< The local TCP port, in network byte order. */ |
ban4jp | 3:a2715e9c7737 | 1301 | uint16_t rport; /**< The local remote TCP port, in network byte |
ban4jp | 0:685224d2f66d | 1302 | order. */ |
ban4jp | 0:685224d2f66d | 1303 | |
ban4jp | 3:a2715e9c7737 | 1304 | uint8_t rcv_nxt[4]; /**< The sequence number that we expect to |
ban4jp | 0:685224d2f66d | 1305 | receive next. */ |
ban4jp | 3:a2715e9c7737 | 1306 | uint8_t snd_nxt[4]; /**< The sequence number that was last sent by |
ban4jp | 0:685224d2f66d | 1307 | us. */ |
ban4jp | 3:a2715e9c7737 | 1308 | uint16_t len; /**< Length of the data that was previously sent. */ |
ban4jp | 3:a2715e9c7737 | 1309 | uint16_t mss; /**< Current maximum segment size for the |
ban4jp | 0:685224d2f66d | 1310 | connection. */ |
ban4jp | 3:a2715e9c7737 | 1311 | uint16_t initialmss; /**< Initial maximum segment size for the |
ban4jp | 0:685224d2f66d | 1312 | connection. */ |
ban4jp | 3:a2715e9c7737 | 1313 | uint8_t sa; /**< Retransmission time-out calculation state |
ban4jp | 0:685224d2f66d | 1314 | variable. */ |
ban4jp | 3:a2715e9c7737 | 1315 | uint8_t sv; /**< Retransmission time-out calculation state |
ban4jp | 0:685224d2f66d | 1316 | variable. */ |
ban4jp | 3:a2715e9c7737 | 1317 | uint8_t rto; /**< Retransmission time-out. */ |
ban4jp | 3:a2715e9c7737 | 1318 | uint8_t tcpstateflags; /**< TCP state and flags. */ |
ban4jp | 3:a2715e9c7737 | 1319 | uint8_t timer; /**< The retransmission timer. */ |
ban4jp | 3:a2715e9c7737 | 1320 | uint8_t nrtx; /**< The number of retransmissions for the last |
ban4jp | 0:685224d2f66d | 1321 | segment sent. */ |
ban4jp | 0:685224d2f66d | 1322 | |
ban4jp | 0:685224d2f66d | 1323 | /** The application state. */ |
ban4jp | 0:685224d2f66d | 1324 | uip_tcp_appstate_t appstate; |
ban4jp | 0:685224d2f66d | 1325 | }; |
ban4jp | 0:685224d2f66d | 1326 | |
ban4jp | 0:685224d2f66d | 1327 | |
ban4jp | 0:685224d2f66d | 1328 | /** |
ban4jp | 0:685224d2f66d | 1329 | * Pointer to the current TCP connection. |
ban4jp | 0:685224d2f66d | 1330 | * |
ban4jp | 0:685224d2f66d | 1331 | * The uip_conn pointer can be used to access the current TCP |
ban4jp | 0:685224d2f66d | 1332 | * connection. |
ban4jp | 0:685224d2f66d | 1333 | */ |
ban4jp | 3:a2715e9c7737 | 1334 | |
ban4jp | 3:a2715e9c7737 | 1335 | CCIF extern struct uip_conn *uip_conn; |
ban4jp | 3:a2715e9c7737 | 1336 | #if UIP_TCP |
ban4jp | 0:685224d2f66d | 1337 | /* The array containing all uIP connections. */ |
ban4jp | 3:a2715e9c7737 | 1338 | CCIF extern struct uip_conn uip_conns[UIP_CONNS]; |
ban4jp | 3:a2715e9c7737 | 1339 | #endif |
ban4jp | 3:a2715e9c7737 | 1340 | |
ban4jp | 0:685224d2f66d | 1341 | /** |
ban4jp | 0:685224d2f66d | 1342 | * \addtogroup uiparch |
ban4jp | 0:685224d2f66d | 1343 | * @{ |
ban4jp | 0:685224d2f66d | 1344 | */ |
ban4jp | 0:685224d2f66d | 1345 | |
ban4jp | 0:685224d2f66d | 1346 | /** |
ban4jp | 0:685224d2f66d | 1347 | * 4-byte array used for the 32-bit sequence number calculations. |
ban4jp | 0:685224d2f66d | 1348 | */ |
ban4jp | 3:a2715e9c7737 | 1349 | extern uint8_t uip_acc32[4]; |
ban4jp | 0:685224d2f66d | 1350 | /** @} */ |
ban4jp | 0:685224d2f66d | 1351 | |
ban4jp | 0:685224d2f66d | 1352 | |
ban4jp | 0:685224d2f66d | 1353 | #if UIP_UDP |
ban4jp | 0:685224d2f66d | 1354 | /** |
ban4jp | 0:685224d2f66d | 1355 | * Representation of a uIP UDP connection. |
ban4jp | 0:685224d2f66d | 1356 | */ |
ban4jp | 0:685224d2f66d | 1357 | struct uip_udp_conn { |
ban4jp | 0:685224d2f66d | 1358 | uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */ |
ban4jp | 3:a2715e9c7737 | 1359 | uint16_t lport; /**< The local port number in network byte order. */ |
ban4jp | 3:a2715e9c7737 | 1360 | uint16_t rport; /**< The remote port number in network byte order. */ |
ban4jp | 3:a2715e9c7737 | 1361 | uint8_t ttl; /**< Default time-to-live. */ |
ban4jp | 0:685224d2f66d | 1362 | |
ban4jp | 0:685224d2f66d | 1363 | /** The application state. */ |
ban4jp | 0:685224d2f66d | 1364 | uip_udp_appstate_t appstate; |
ban4jp | 0:685224d2f66d | 1365 | }; |
ban4jp | 0:685224d2f66d | 1366 | |
ban4jp | 0:685224d2f66d | 1367 | /** |
ban4jp | 0:685224d2f66d | 1368 | * The current UDP connection. |
ban4jp | 0:685224d2f66d | 1369 | */ |
ban4jp | 0:685224d2f66d | 1370 | extern struct uip_udp_conn *uip_udp_conn; |
ban4jp | 0:685224d2f66d | 1371 | extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS]; |
ban4jp | 0:685224d2f66d | 1372 | #endif /* UIP_UDP */ |
ban4jp | 0:685224d2f66d | 1373 | |
ban4jp | 3:a2715e9c7737 | 1374 | struct uip_fallback_interface { |
ban4jp | 3:a2715e9c7737 | 1375 | void (*init)(void); |
ban4jp | 3:a2715e9c7737 | 1376 | void (*output)(void); |
ban4jp | 3:a2715e9c7737 | 1377 | }; |
ban4jp | 3:a2715e9c7737 | 1378 | |
ban4jp | 3:a2715e9c7737 | 1379 | #if UIP_CONF_ICMP6 |
ban4jp | 3:a2715e9c7737 | 1380 | struct uip_icmp6_conn { |
ban4jp | 3:a2715e9c7737 | 1381 | uip_icmp6_appstate_t appstate; |
ban4jp | 3:a2715e9c7737 | 1382 | }; |
ban4jp | 3:a2715e9c7737 | 1383 | extern struct uip_icmp6_conn uip_icmp6_conns; |
ban4jp | 3:a2715e9c7737 | 1384 | #endif /*UIP_CONF_ICMP6*/ |
ban4jp | 3:a2715e9c7737 | 1385 | |
ban4jp | 3:a2715e9c7737 | 1386 | /** |
ban4jp | 3:a2715e9c7737 | 1387 | * The uIP TCP/IP statistics. |
ban4jp | 3:a2715e9c7737 | 1388 | * |
ban4jp | 3:a2715e9c7737 | 1389 | * This is the variable in which the uIP TCP/IP statistics are gathered. |
ban4jp | 3:a2715e9c7737 | 1390 | */ |
ban4jp | 3:a2715e9c7737 | 1391 | #if UIP_STATISTICS == 1 |
ban4jp | 3:a2715e9c7737 | 1392 | extern struct uip_stats uip_stat; |
ban4jp | 3:a2715e9c7737 | 1393 | #define UIP_STAT(s) s |
ban4jp | 3:a2715e9c7737 | 1394 | #else |
ban4jp | 3:a2715e9c7737 | 1395 | #define UIP_STAT(s) |
ban4jp | 3:a2715e9c7737 | 1396 | #endif /* UIP_STATISTICS == 1 */ |
ban4jp | 3:a2715e9c7737 | 1397 | |
ban4jp | 0:685224d2f66d | 1398 | /** |
ban4jp | 0:685224d2f66d | 1399 | * The structure holding the TCP/IP statistics that are gathered if |
ban4jp | 0:685224d2f66d | 1400 | * UIP_STATISTICS is set to 1. |
ban4jp | 0:685224d2f66d | 1401 | * |
ban4jp | 0:685224d2f66d | 1402 | */ |
ban4jp | 0:685224d2f66d | 1403 | struct uip_stats { |
ban4jp | 0:685224d2f66d | 1404 | struct { |
ban4jp | 0:685224d2f66d | 1405 | uip_stats_t recv; /**< Number of received packets at the IP |
ban4jp | 0:685224d2f66d | 1406 | layer. */ |
ban4jp | 0:685224d2f66d | 1407 | uip_stats_t sent; /**< Number of sent packets at the IP |
ban4jp | 0:685224d2f66d | 1408 | layer. */ |
ban4jp | 3:a2715e9c7737 | 1409 | uip_stats_t forwarded;/**< Number of forwarded packets at the IP |
ban4jp | 3:a2715e9c7737 | 1410 | layer. */ |
ban4jp | 3:a2715e9c7737 | 1411 | uip_stats_t drop; /**< Number of dropped packets at the IP |
ban4jp | 3:a2715e9c7737 | 1412 | layer. */ |
ban4jp | 0:685224d2f66d | 1413 | uip_stats_t vhlerr; /**< Number of packets dropped due to wrong |
ban4jp | 0:685224d2f66d | 1414 | IP version or header length. */ |
ban4jp | 0:685224d2f66d | 1415 | uip_stats_t hblenerr; /**< Number of packets dropped due to wrong |
ban4jp | 0:685224d2f66d | 1416 | IP length, high byte. */ |
ban4jp | 0:685224d2f66d | 1417 | uip_stats_t lblenerr; /**< Number of packets dropped due to wrong |
ban4jp | 0:685224d2f66d | 1418 | IP length, low byte. */ |
ban4jp | 3:a2715e9c7737 | 1419 | uip_stats_t fragerr; /**< Number of packets dropped because they |
ban4jp | 0:685224d2f66d | 1420 | were IP fragments. */ |
ban4jp | 0:685224d2f66d | 1421 | uip_stats_t chkerr; /**< Number of packets dropped due to IP |
ban4jp | 0:685224d2f66d | 1422 | checksum errors. */ |
ban4jp | 3:a2715e9c7737 | 1423 | uip_stats_t protoerr; /**< Number of packets dropped because they |
ban4jp | 0:685224d2f66d | 1424 | were neither ICMP, UDP nor TCP. */ |
ban4jp | 0:685224d2f66d | 1425 | } ip; /**< IP statistics. */ |
ban4jp | 0:685224d2f66d | 1426 | struct { |
ban4jp | 0:685224d2f66d | 1427 | uip_stats_t recv; /**< Number of received ICMP packets. */ |
ban4jp | 0:685224d2f66d | 1428 | uip_stats_t sent; /**< Number of sent ICMP packets. */ |
ban4jp | 3:a2715e9c7737 | 1429 | uip_stats_t drop; /**< Number of dropped ICMP packets. */ |
ban4jp | 0:685224d2f66d | 1430 | uip_stats_t typeerr; /**< Number of ICMP packets with a wrong |
ban4jp | 0:685224d2f66d | 1431 | type. */ |
ban4jp | 3:a2715e9c7737 | 1432 | uip_stats_t chkerr; /**< Number of ICMP packets with a bad |
ban4jp | 3:a2715e9c7737 | 1433 | checksum. */ |
ban4jp | 0:685224d2f66d | 1434 | } icmp; /**< ICMP statistics. */ |
ban4jp | 3:a2715e9c7737 | 1435 | #if UIP_TCP |
ban4jp | 0:685224d2f66d | 1436 | struct { |
ban4jp | 0:685224d2f66d | 1437 | uip_stats_t recv; /**< Number of recived TCP segments. */ |
ban4jp | 0:685224d2f66d | 1438 | uip_stats_t sent; /**< Number of sent TCP segments. */ |
ban4jp | 3:a2715e9c7737 | 1439 | uip_stats_t drop; /**< Number of dropped TCP segments. */ |
ban4jp | 0:685224d2f66d | 1440 | uip_stats_t chkerr; /**< Number of TCP segments with a bad |
ban4jp | 0:685224d2f66d | 1441 | checksum. */ |
ban4jp | 0:685224d2f66d | 1442 | uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK |
ban4jp | 0:685224d2f66d | 1443 | number. */ |
ban4jp | 3:a2715e9c7737 | 1444 | uip_stats_t rst; /**< Number of received TCP RST (reset) segments. */ |
ban4jp | 0:685224d2f66d | 1445 | uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */ |
ban4jp | 3:a2715e9c7737 | 1446 | uip_stats_t syndrop; /**< Number of dropped SYNs because too few |
ban4jp | 3:a2715e9c7737 | 1447 | connections were available. */ |
ban4jp | 0:685224d2f66d | 1448 | uip_stats_t synrst; /**< Number of SYNs for closed ports, |
ban4jp | 0:685224d2f66d | 1449 | triggering a RST. */ |
ban4jp | 0:685224d2f66d | 1450 | } tcp; /**< TCP statistics. */ |
ban4jp | 3:a2715e9c7737 | 1451 | #endif |
ban4jp | 0:685224d2f66d | 1452 | #if UIP_UDP |
ban4jp | 0:685224d2f66d | 1453 | struct { |
ban4jp | 0:685224d2f66d | 1454 | uip_stats_t drop; /**< Number of dropped UDP segments. */ |
ban4jp | 0:685224d2f66d | 1455 | uip_stats_t recv; /**< Number of recived UDP segments. */ |
ban4jp | 0:685224d2f66d | 1456 | uip_stats_t sent; /**< Number of sent UDP segments. */ |
ban4jp | 0:685224d2f66d | 1457 | uip_stats_t chkerr; /**< Number of UDP segments with a bad |
ban4jp | 0:685224d2f66d | 1458 | checksum. */ |
ban4jp | 0:685224d2f66d | 1459 | } udp; /**< UDP statistics. */ |
ban4jp | 0:685224d2f66d | 1460 | #endif /* UIP_UDP */ |
ban4jp | 3:a2715e9c7737 | 1461 | #if UIP_CONF_IPV6 |
ban4jp | 3:a2715e9c7737 | 1462 | struct { |
ban4jp | 3:a2715e9c7737 | 1463 | uip_stats_t drop; /**< Number of dropped ND6 packets. */ |
ban4jp | 3:a2715e9c7737 | 1464 | uip_stats_t recv; /**< Number of recived ND6 packets */ |
ban4jp | 3:a2715e9c7737 | 1465 | uip_stats_t sent; /**< Number of sent ND6 packets */ |
ban4jp | 3:a2715e9c7737 | 1466 | } nd6; |
ban4jp | 3:a2715e9c7737 | 1467 | #endif /*UIP_CONF_IPV6*/ |
ban4jp | 0:685224d2f66d | 1468 | }; |
ban4jp | 0:685224d2f66d | 1469 | |
ban4jp | 0:685224d2f66d | 1470 | |
ban4jp | 0:685224d2f66d | 1471 | /*---------------------------------------------------------------------------*/ |
ban4jp | 0:685224d2f66d | 1472 | /* All the stuff below this point is internal to uIP and should not be |
ban4jp | 0:685224d2f66d | 1473 | * used directly by an application or by a device driver. |
ban4jp | 0:685224d2f66d | 1474 | */ |
ban4jp | 0:685224d2f66d | 1475 | /*---------------------------------------------------------------------------*/ |
ban4jp | 3:a2715e9c7737 | 1476 | |
ban4jp | 3:a2715e9c7737 | 1477 | |
ban4jp | 3:a2715e9c7737 | 1478 | |
ban4jp | 3:a2715e9c7737 | 1479 | /* uint8_t uip_flags: |
ban4jp | 0:685224d2f66d | 1480 | * |
ban4jp | 0:685224d2f66d | 1481 | * When the application is called, uip_flags will contain the flags |
ban4jp | 0:685224d2f66d | 1482 | * that are defined in this file. Please read below for more |
ban4jp | 3:a2715e9c7737 | 1483 | * information. |
ban4jp | 0:685224d2f66d | 1484 | */ |
ban4jp | 3:a2715e9c7737 | 1485 | CCIF extern uint8_t uip_flags; |
ban4jp | 0:685224d2f66d | 1486 | |
ban4jp | 0:685224d2f66d | 1487 | /* The following flags may be set in the global variable uip_flags |
ban4jp | 0:685224d2f66d | 1488 | before calling the application callback. The UIP_ACKDATA, |
ban4jp | 0:685224d2f66d | 1489 | UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time, |
ban4jp | 3:a2715e9c7737 | 1490 | whereas the others are mutually exclusive. Note that these flags |
ban4jp | 0:685224d2f66d | 1491 | should *NOT* be accessed directly, but only through the uIP |
ban4jp | 0:685224d2f66d | 1492 | functions/macros. */ |
ban4jp | 0:685224d2f66d | 1493 | |
ban4jp | 0:685224d2f66d | 1494 | #define UIP_ACKDATA 1 /* Signifies that the outstanding data was |
ban4jp | 0:685224d2f66d | 1495 | acked and the application should send |
ban4jp | 0:685224d2f66d | 1496 | out new data instead of retransmitting |
ban4jp | 0:685224d2f66d | 1497 | the last data. */ |
ban4jp | 0:685224d2f66d | 1498 | #define UIP_NEWDATA 2 /* Flags the fact that the peer has sent |
ban4jp | 0:685224d2f66d | 1499 | us new data. */ |
ban4jp | 0:685224d2f66d | 1500 | #define UIP_REXMIT 4 /* Tells the application to retransmit the |
ban4jp | 0:685224d2f66d | 1501 | data that was last sent. */ |
ban4jp | 0:685224d2f66d | 1502 | #define UIP_POLL 8 /* Used for polling the application, to |
ban4jp | 0:685224d2f66d | 1503 | check if the application has data that |
ban4jp | 0:685224d2f66d | 1504 | it wants to send. */ |
ban4jp | 0:685224d2f66d | 1505 | #define UIP_CLOSE 16 /* The remote host has closed the |
ban4jp | 0:685224d2f66d | 1506 | connection, thus the connection has |
ban4jp | 0:685224d2f66d | 1507 | gone away. Or the application signals |
ban4jp | 0:685224d2f66d | 1508 | that it wants to close the |
ban4jp | 0:685224d2f66d | 1509 | connection. */ |
ban4jp | 0:685224d2f66d | 1510 | #define UIP_ABORT 32 /* The remote host has aborted the |
ban4jp | 0:685224d2f66d | 1511 | connection, thus the connection has |
ban4jp | 0:685224d2f66d | 1512 | gone away. Or the application signals |
ban4jp | 0:685224d2f66d | 1513 | that it wants to abort the |
ban4jp | 0:685224d2f66d | 1514 | connection. */ |
ban4jp | 0:685224d2f66d | 1515 | #define UIP_CONNECTED 64 /* We have got a connection from a remote |
ban4jp | 0:685224d2f66d | 1516 | host and have set up a new connection |
ban4jp | 0:685224d2f66d | 1517 | for it, or an active connection has |
ban4jp | 0:685224d2f66d | 1518 | been successfully established. */ |
ban4jp | 0:685224d2f66d | 1519 | |
ban4jp | 0:685224d2f66d | 1520 | #define UIP_TIMEDOUT 128 /* The connection has been aborted due to |
ban4jp | 0:685224d2f66d | 1521 | too many retransmissions. */ |
ban4jp | 0:685224d2f66d | 1522 | |
ban4jp | 3:a2715e9c7737 | 1523 | |
ban4jp | 3:a2715e9c7737 | 1524 | /** |
ban4jp | 3:a2715e9c7737 | 1525 | * \brief process the options within a hop by hop or destination option header |
ban4jp | 3:a2715e9c7737 | 1526 | * \retval 0: nothing to send, |
ban4jp | 3:a2715e9c7737 | 1527 | * \retval 1: drop pkt |
ban4jp | 3:a2715e9c7737 | 1528 | * \retval 2: ICMP error message to send |
ban4jp | 3:a2715e9c7737 | 1529 | */ |
ban4jp | 3:a2715e9c7737 | 1530 | /*static uint8_t |
ban4jp | 3:a2715e9c7737 | 1531 | uip_ext_hdr_options_process(); */ |
ban4jp | 3:a2715e9c7737 | 1532 | |
ban4jp | 0:685224d2f66d | 1533 | /* uip_process(flag): |
ban4jp | 0:685224d2f66d | 1534 | * |
ban4jp | 0:685224d2f66d | 1535 | * The actual uIP function which does all the work. |
ban4jp | 0:685224d2f66d | 1536 | */ |
ban4jp | 3:a2715e9c7737 | 1537 | void uip_process(uint8_t flag); |
ban4jp | 3:a2715e9c7737 | 1538 | |
ban4jp | 3:a2715e9c7737 | 1539 | /* The following flags are passed as an argument to the uip_process() |
ban4jp | 0:685224d2f66d | 1540 | function. They are used to distinguish between the two cases where |
ban4jp | 0:685224d2f66d | 1541 | uip_process() is called. It can be called either because we have |
ban4jp | 0:685224d2f66d | 1542 | incoming data that should be processed, or because the periodic |
ban4jp | 0:685224d2f66d | 1543 | timer has fired. These values are never used directly, but only in |
ban4jp | 3:a2715e9c7737 | 1544 | the macros defined in this file. */ |
ban4jp | 0:685224d2f66d | 1545 | |
ban4jp | 0:685224d2f66d | 1546 | #define UIP_DATA 1 /* Tells uIP that there is incoming |
ban4jp | 0:685224d2f66d | 1547 | data in the uip_buf buffer. The |
ban4jp | 0:685224d2f66d | 1548 | length of the data is stored in the |
ban4jp | 0:685224d2f66d | 1549 | global variable uip_len. */ |
ban4jp | 0:685224d2f66d | 1550 | #define UIP_TIMER 2 /* Tells uIP that the periodic timer |
ban4jp | 0:685224d2f66d | 1551 | has fired. */ |
ban4jp | 0:685224d2f66d | 1552 | #define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should |
ban4jp | 0:685224d2f66d | 1553 | be polled. */ |
ban4jp | 0:685224d2f66d | 1554 | #define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram |
ban4jp | 0:685224d2f66d | 1555 | should be constructed in the |
ban4jp | 0:685224d2f66d | 1556 | uip_buf buffer. */ |
ban4jp | 0:685224d2f66d | 1557 | #if UIP_UDP |
ban4jp | 0:685224d2f66d | 1558 | #define UIP_UDP_TIMER 5 |
ban4jp | 0:685224d2f66d | 1559 | #endif /* UIP_UDP */ |
ban4jp | 0:685224d2f66d | 1560 | |
ban4jp | 0:685224d2f66d | 1561 | /* The TCP states used in the uip_conn->tcpstateflags. */ |
ban4jp | 0:685224d2f66d | 1562 | #define UIP_CLOSED 0 |
ban4jp | 0:685224d2f66d | 1563 | #define UIP_SYN_RCVD 1 |
ban4jp | 0:685224d2f66d | 1564 | #define UIP_SYN_SENT 2 |
ban4jp | 0:685224d2f66d | 1565 | #define UIP_ESTABLISHED 3 |
ban4jp | 0:685224d2f66d | 1566 | #define UIP_FIN_WAIT_1 4 |
ban4jp | 0:685224d2f66d | 1567 | #define UIP_FIN_WAIT_2 5 |
ban4jp | 0:685224d2f66d | 1568 | #define UIP_CLOSING 6 |
ban4jp | 0:685224d2f66d | 1569 | #define UIP_TIME_WAIT 7 |
ban4jp | 0:685224d2f66d | 1570 | #define UIP_LAST_ACK 8 |
ban4jp | 0:685224d2f66d | 1571 | #define UIP_TS_MASK 15 |
ban4jp | 0:685224d2f66d | 1572 | |
ban4jp | 0:685224d2f66d | 1573 | #define UIP_STOPPED 16 |
ban4jp | 0:685224d2f66d | 1574 | |
ban4jp | 0:685224d2f66d | 1575 | /* The TCP and IP headers. */ |
ban4jp | 0:685224d2f66d | 1576 | struct uip_tcpip_hdr { |
ban4jp | 0:685224d2f66d | 1577 | #if UIP_CONF_IPV6 |
ban4jp | 0:685224d2f66d | 1578 | /* IPv6 header. */ |
ban4jp | 3:a2715e9c7737 | 1579 | uint8_t vtc, |
ban4jp | 0:685224d2f66d | 1580 | tcflow; |
ban4jp | 3:a2715e9c7737 | 1581 | uint16_t flow; |
ban4jp | 3:a2715e9c7737 | 1582 | uint8_t len[2]; |
ban4jp | 3:a2715e9c7737 | 1583 | uint8_t proto, ttl; |
ban4jp | 0:685224d2f66d | 1584 | uip_ip6addr_t srcipaddr, destipaddr; |
ban4jp | 0:685224d2f66d | 1585 | #else /* UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 1586 | /* IPv4 header. */ |
ban4jp | 3:a2715e9c7737 | 1587 | uint8_t vhl, |
ban4jp | 0:685224d2f66d | 1588 | tos, |
ban4jp | 0:685224d2f66d | 1589 | len[2], |
ban4jp | 0:685224d2f66d | 1590 | ipid[2], |
ban4jp | 0:685224d2f66d | 1591 | ipoffset[2], |
ban4jp | 0:685224d2f66d | 1592 | ttl, |
ban4jp | 0:685224d2f66d | 1593 | proto; |
ban4jp | 3:a2715e9c7737 | 1594 | uint16_t ipchksum; |
ban4jp | 3:a2715e9c7737 | 1595 | uip_ipaddr_t srcipaddr, destipaddr; |
ban4jp | 0:685224d2f66d | 1596 | #endif /* UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 1597 | |
ban4jp | 0:685224d2f66d | 1598 | /* TCP header. */ |
ban4jp | 3:a2715e9c7737 | 1599 | uint16_t srcport, |
ban4jp | 0:685224d2f66d | 1600 | destport; |
ban4jp | 3:a2715e9c7737 | 1601 | uint8_t seqno[4], |
ban4jp | 0:685224d2f66d | 1602 | ackno[4], |
ban4jp | 0:685224d2f66d | 1603 | tcpoffset, |
ban4jp | 0:685224d2f66d | 1604 | flags, |
ban4jp | 0:685224d2f66d | 1605 | wnd[2]; |
ban4jp | 3:a2715e9c7737 | 1606 | uint16_t tcpchksum; |
ban4jp | 3:a2715e9c7737 | 1607 | uint8_t urgp[2]; |
ban4jp | 3:a2715e9c7737 | 1608 | uint8_t optdata[4]; |
ban4jp | 0:685224d2f66d | 1609 | }; |
ban4jp | 0:685224d2f66d | 1610 | |
ban4jp | 0:685224d2f66d | 1611 | /* The ICMP and IP headers. */ |
ban4jp | 0:685224d2f66d | 1612 | struct uip_icmpip_hdr { |
ban4jp | 0:685224d2f66d | 1613 | #if UIP_CONF_IPV6 |
ban4jp | 0:685224d2f66d | 1614 | /* IPv6 header. */ |
ban4jp | 3:a2715e9c7737 | 1615 | uint8_t vtc, |
ban4jp | 0:685224d2f66d | 1616 | tcf; |
ban4jp | 3:a2715e9c7737 | 1617 | uint16_t flow; |
ban4jp | 3:a2715e9c7737 | 1618 | uint8_t len[2]; |
ban4jp | 3:a2715e9c7737 | 1619 | uint8_t proto, ttl; |
ban4jp | 0:685224d2f66d | 1620 | uip_ip6addr_t srcipaddr, destipaddr; |
ban4jp | 0:685224d2f66d | 1621 | #else /* UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 1622 | /* IPv4 header. */ |
ban4jp | 3:a2715e9c7737 | 1623 | uint8_t vhl, |
ban4jp | 0:685224d2f66d | 1624 | tos, |
ban4jp | 0:685224d2f66d | 1625 | len[2], |
ban4jp | 0:685224d2f66d | 1626 | ipid[2], |
ban4jp | 0:685224d2f66d | 1627 | ipoffset[2], |
ban4jp | 0:685224d2f66d | 1628 | ttl, |
ban4jp | 0:685224d2f66d | 1629 | proto; |
ban4jp | 3:a2715e9c7737 | 1630 | uint16_t ipchksum; |
ban4jp | 3:a2715e9c7737 | 1631 | uip_ipaddr_t srcipaddr, destipaddr; |
ban4jp | 0:685224d2f66d | 1632 | #endif /* UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 1633 | |
ban4jp | 3:a2715e9c7737 | 1634 | /* ICMP header. */ |
ban4jp | 3:a2715e9c7737 | 1635 | uint8_t type, icode; |
ban4jp | 3:a2715e9c7737 | 1636 | uint16_t icmpchksum; |
ban4jp | 0:685224d2f66d | 1637 | #if !UIP_CONF_IPV6 |
ban4jp | 3:a2715e9c7737 | 1638 | uint16_t id, seqno; |
ban4jp | 3:a2715e9c7737 | 1639 | uint8_t payload[1]; |
ban4jp | 0:685224d2f66d | 1640 | #endif /* !UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 1641 | }; |
ban4jp | 0:685224d2f66d | 1642 | |
ban4jp | 0:685224d2f66d | 1643 | |
ban4jp | 0:685224d2f66d | 1644 | /* The UDP and IP headers. */ |
ban4jp | 0:685224d2f66d | 1645 | struct uip_udpip_hdr { |
ban4jp | 0:685224d2f66d | 1646 | #if UIP_CONF_IPV6 |
ban4jp | 0:685224d2f66d | 1647 | /* IPv6 header. */ |
ban4jp | 3:a2715e9c7737 | 1648 | uint8_t vtc, |
ban4jp | 0:685224d2f66d | 1649 | tcf; |
ban4jp | 3:a2715e9c7737 | 1650 | uint16_t flow; |
ban4jp | 3:a2715e9c7737 | 1651 | uint8_t len[2]; |
ban4jp | 3:a2715e9c7737 | 1652 | uint8_t proto, ttl; |
ban4jp | 0:685224d2f66d | 1653 | uip_ip6addr_t srcipaddr, destipaddr; |
ban4jp | 0:685224d2f66d | 1654 | #else /* UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 1655 | /* IP header. */ |
ban4jp | 3:a2715e9c7737 | 1656 | uint8_t vhl, |
ban4jp | 3:a2715e9c7737 | 1657 | tos, |
ban4jp | 3:a2715e9c7737 | 1658 | len[2], |
ban4jp | 3:a2715e9c7737 | 1659 | ipid[2], |
ban4jp | 3:a2715e9c7737 | 1660 | ipoffset[2], |
ban4jp | 3:a2715e9c7737 | 1661 | ttl, |
ban4jp | 3:a2715e9c7737 | 1662 | proto; |
ban4jp | 3:a2715e9c7737 | 1663 | uint16_t ipchksum; |
ban4jp | 3:a2715e9c7737 | 1664 | uip_ipaddr_t srcipaddr, destipaddr; |
ban4jp | 3:a2715e9c7737 | 1665 | #endif /* UIP_CONF_IPV6 */ |
ban4jp | 3:a2715e9c7737 | 1666 | |
ban4jp | 3:a2715e9c7737 | 1667 | /* UDP header. */ |
ban4jp | 3:a2715e9c7737 | 1668 | uint16_t srcport, |
ban4jp | 3:a2715e9c7737 | 1669 | destport; |
ban4jp | 3:a2715e9c7737 | 1670 | uint16_t udplen; |
ban4jp | 3:a2715e9c7737 | 1671 | uint16_t udpchksum; |
ban4jp | 3:a2715e9c7737 | 1672 | }; |
ban4jp | 3:a2715e9c7737 | 1673 | |
ban4jp | 3:a2715e9c7737 | 1674 | /* |
ban4jp | 3:a2715e9c7737 | 1675 | * In IPv6 the length of the L3 headers before the transport header is |
ban4jp | 3:a2715e9c7737 | 1676 | * not fixed, due to the possibility to include extension option headers |
ban4jp | 3:a2715e9c7737 | 1677 | * after the IP header. hence we split here L3 and L4 headers |
ban4jp | 3:a2715e9c7737 | 1678 | */ |
ban4jp | 3:a2715e9c7737 | 1679 | /* The IP header */ |
ban4jp | 3:a2715e9c7737 | 1680 | struct uip_ip_hdr { |
ban4jp | 3:a2715e9c7737 | 1681 | #if UIP_CONF_IPV6 |
ban4jp | 3:a2715e9c7737 | 1682 | /* IPV6 header */ |
ban4jp | 3:a2715e9c7737 | 1683 | uint8_t vtc; |
ban4jp | 3:a2715e9c7737 | 1684 | uint8_t tcflow; |
ban4jp | 3:a2715e9c7737 | 1685 | uint16_t flow; |
ban4jp | 3:a2715e9c7737 | 1686 | uint8_t len[2]; |
ban4jp | 3:a2715e9c7737 | 1687 | uint8_t proto, ttl; |
ban4jp | 3:a2715e9c7737 | 1688 | uip_ip6addr_t srcipaddr, destipaddr; |
ban4jp | 3:a2715e9c7737 | 1689 | #else /* UIP_CONF_IPV6 */ |
ban4jp | 3:a2715e9c7737 | 1690 | /* IPV4 header */ |
ban4jp | 3:a2715e9c7737 | 1691 | uint8_t vhl, |
ban4jp | 0:685224d2f66d | 1692 | tos, |
ban4jp | 0:685224d2f66d | 1693 | len[2], |
ban4jp | 0:685224d2f66d | 1694 | ipid[2], |
ban4jp | 0:685224d2f66d | 1695 | ipoffset[2], |
ban4jp | 0:685224d2f66d | 1696 | ttl, |
ban4jp | 0:685224d2f66d | 1697 | proto; |
ban4jp | 3:a2715e9c7737 | 1698 | uint16_t ipchksum; |
ban4jp | 3:a2715e9c7737 | 1699 | uip_ipaddr_t srcipaddr, destipaddr; |
ban4jp | 0:685224d2f66d | 1700 | #endif /* UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 1701 | }; |
ban4jp | 0:685224d2f66d | 1702 | |
ban4jp | 0:685224d2f66d | 1703 | |
ban4jp | 3:a2715e9c7737 | 1704 | /* |
ban4jp | 3:a2715e9c7737 | 1705 | * IPv6 extension option headers: we are able to process |
ban4jp | 3:a2715e9c7737 | 1706 | * the 4 extension headers defined in RFC2460 (IPv6): |
ban4jp | 3:a2715e9c7737 | 1707 | * - Hop by hop option header, destination option header: |
ban4jp | 3:a2715e9c7737 | 1708 | * These two are not used by any core IPv6 protocol, hence |
ban4jp | 3:a2715e9c7737 | 1709 | * we just read them and go to the next. They convey options, |
ban4jp | 3:a2715e9c7737 | 1710 | * the options defined in RFC2460 are Pad1 and PadN, which do |
ban4jp | 3:a2715e9c7737 | 1711 | * some padding, and that we do not need to read (the length |
ban4jp | 3:a2715e9c7737 | 1712 | * field in the header is enough) |
ban4jp | 3:a2715e9c7737 | 1713 | * - Routing header: this one is most notably used by MIPv6, |
ban4jp | 3:a2715e9c7737 | 1714 | * which we do not implement, hence we just read it and go |
ban4jp | 3:a2715e9c7737 | 1715 | * to the next |
ban4jp | 3:a2715e9c7737 | 1716 | * - Fragmentation header: we read this header and are able to |
ban4jp | 3:a2715e9c7737 | 1717 | * reassemble packets |
ban4jp | 3:a2715e9c7737 | 1718 | * |
ban4jp | 3:a2715e9c7737 | 1719 | * We do not offer any means to send packets with extension headers |
ban4jp | 3:a2715e9c7737 | 1720 | * |
ban4jp | 3:a2715e9c7737 | 1721 | * We do not implement Authentication and ESP headers, which are |
ban4jp | 3:a2715e9c7737 | 1722 | * used in IPSec and defined in RFC4302,4303,4305,4385 |
ban4jp | 3:a2715e9c7737 | 1723 | */ |
ban4jp | 3:a2715e9c7737 | 1724 | /* common header part */ |
ban4jp | 3:a2715e9c7737 | 1725 | typedef struct uip_ext_hdr { |
ban4jp | 3:a2715e9c7737 | 1726 | uint8_t next; |
ban4jp | 3:a2715e9c7737 | 1727 | uint8_t len; |
ban4jp | 3:a2715e9c7737 | 1728 | } uip_ext_hdr; |
ban4jp | 3:a2715e9c7737 | 1729 | |
ban4jp | 3:a2715e9c7737 | 1730 | /* Hop by Hop option header */ |
ban4jp | 3:a2715e9c7737 | 1731 | typedef struct uip_hbho_hdr { |
ban4jp | 3:a2715e9c7737 | 1732 | uint8_t next; |
ban4jp | 3:a2715e9c7737 | 1733 | uint8_t len; |
ban4jp | 3:a2715e9c7737 | 1734 | } uip_hbho_hdr; |
ban4jp | 3:a2715e9c7737 | 1735 | |
ban4jp | 3:a2715e9c7737 | 1736 | /* destination option header */ |
ban4jp | 3:a2715e9c7737 | 1737 | typedef struct uip_desto_hdr { |
ban4jp | 3:a2715e9c7737 | 1738 | uint8_t next; |
ban4jp | 3:a2715e9c7737 | 1739 | uint8_t len; |
ban4jp | 3:a2715e9c7737 | 1740 | } uip_desto_hdr; |
ban4jp | 3:a2715e9c7737 | 1741 | |
ban4jp | 3:a2715e9c7737 | 1742 | /* We do not define structures for PAD1 and PADN options */ |
ban4jp | 3:a2715e9c7737 | 1743 | |
ban4jp | 3:a2715e9c7737 | 1744 | /* |
ban4jp | 3:a2715e9c7737 | 1745 | * routing header |
ban4jp | 3:a2715e9c7737 | 1746 | * the routing header as 4 common bytes, then routing header type |
ban4jp | 3:a2715e9c7737 | 1747 | * specific data there are several types of routing header. Type 0 was |
ban4jp | 3:a2715e9c7737 | 1748 | * deprecated as per RFC5095 most notable other type is 2, used in |
ban4jp | 3:a2715e9c7737 | 1749 | * RFC3775 (MIPv6) here we do not implement MIPv6, so we just need to |
ban4jp | 3:a2715e9c7737 | 1750 | * parse the 4 first bytes |
ban4jp | 3:a2715e9c7737 | 1751 | */ |
ban4jp | 3:a2715e9c7737 | 1752 | typedef struct uip_routing_hdr { |
ban4jp | 3:a2715e9c7737 | 1753 | uint8_t next; |
ban4jp | 3:a2715e9c7737 | 1754 | uint8_t len; |
ban4jp | 3:a2715e9c7737 | 1755 | uint8_t routing_type; |
ban4jp | 3:a2715e9c7737 | 1756 | uint8_t seg_left; |
ban4jp | 3:a2715e9c7737 | 1757 | } uip_routing_hdr; |
ban4jp | 3:a2715e9c7737 | 1758 | |
ban4jp | 3:a2715e9c7737 | 1759 | /* fragmentation header */ |
ban4jp | 3:a2715e9c7737 | 1760 | typedef struct uip_frag_hdr { |
ban4jp | 3:a2715e9c7737 | 1761 | uint8_t next; |
ban4jp | 3:a2715e9c7737 | 1762 | uint8_t res; |
ban4jp | 3:a2715e9c7737 | 1763 | uint16_t offsetresmore; |
ban4jp | 3:a2715e9c7737 | 1764 | uint32_t id; |
ban4jp | 3:a2715e9c7737 | 1765 | } uip_frag_hdr; |
ban4jp | 3:a2715e9c7737 | 1766 | |
ban4jp | 3:a2715e9c7737 | 1767 | /* |
ban4jp | 3:a2715e9c7737 | 1768 | * an option within the destination or hop by hop option headers |
ban4jp | 3:a2715e9c7737 | 1769 | * it contains type an length, which is true for all options but PAD1 |
ban4jp | 3:a2715e9c7737 | 1770 | */ |
ban4jp | 3:a2715e9c7737 | 1771 | typedef struct uip_ext_hdr_opt { |
ban4jp | 3:a2715e9c7737 | 1772 | uint8_t type; |
ban4jp | 3:a2715e9c7737 | 1773 | uint8_t len; |
ban4jp | 3:a2715e9c7737 | 1774 | } uip_ext_hdr_opt; |
ban4jp | 3:a2715e9c7737 | 1775 | |
ban4jp | 3:a2715e9c7737 | 1776 | /* PADN option */ |
ban4jp | 3:a2715e9c7737 | 1777 | typedef struct uip_ext_hdr_opt_padn { |
ban4jp | 3:a2715e9c7737 | 1778 | uint8_t opt_type; |
ban4jp | 3:a2715e9c7737 | 1779 | uint8_t opt_len; |
ban4jp | 3:a2715e9c7737 | 1780 | } uip_ext_hdr_opt_padn; |
ban4jp | 3:a2715e9c7737 | 1781 | |
ban4jp | 3:a2715e9c7737 | 1782 | /* RPL option */ |
ban4jp | 3:a2715e9c7737 | 1783 | typedef struct uip_ext_hdr_opt_rpl { |
ban4jp | 3:a2715e9c7737 | 1784 | uint8_t opt_type; |
ban4jp | 3:a2715e9c7737 | 1785 | uint8_t opt_len; |
ban4jp | 3:a2715e9c7737 | 1786 | uint8_t flags; |
ban4jp | 3:a2715e9c7737 | 1787 | uint8_t instance; |
ban4jp | 3:a2715e9c7737 | 1788 | uint16_t senderrank; |
ban4jp | 3:a2715e9c7737 | 1789 | } uip_ext_hdr_opt_rpl; |
ban4jp | 3:a2715e9c7737 | 1790 | |
ban4jp | 3:a2715e9c7737 | 1791 | /* TCP header */ |
ban4jp | 3:a2715e9c7737 | 1792 | struct uip_tcp_hdr { |
ban4jp | 3:a2715e9c7737 | 1793 | uint16_t srcport; |
ban4jp | 3:a2715e9c7737 | 1794 | uint16_t destport; |
ban4jp | 3:a2715e9c7737 | 1795 | uint8_t seqno[4]; |
ban4jp | 3:a2715e9c7737 | 1796 | uint8_t ackno[4]; |
ban4jp | 3:a2715e9c7737 | 1797 | uint8_t tcpoffset; |
ban4jp | 3:a2715e9c7737 | 1798 | uint8_t flags; |
ban4jp | 3:a2715e9c7737 | 1799 | uint8_t wnd[2]; |
ban4jp | 3:a2715e9c7737 | 1800 | uint16_t tcpchksum; |
ban4jp | 3:a2715e9c7737 | 1801 | uint8_t urgp[2]; |
ban4jp | 3:a2715e9c7737 | 1802 | uint8_t optdata[4]; |
ban4jp | 3:a2715e9c7737 | 1803 | }; |
ban4jp | 3:a2715e9c7737 | 1804 | |
ban4jp | 3:a2715e9c7737 | 1805 | /* The ICMP headers. */ |
ban4jp | 3:a2715e9c7737 | 1806 | struct uip_icmp_hdr { |
ban4jp | 3:a2715e9c7737 | 1807 | uint8_t type, icode; |
ban4jp | 3:a2715e9c7737 | 1808 | uint16_t icmpchksum; |
ban4jp | 3:a2715e9c7737 | 1809 | #if !UIP_CONF_IPV6 |
ban4jp | 3:a2715e9c7737 | 1810 | uint16_t id, seqno; |
ban4jp | 3:a2715e9c7737 | 1811 | #endif /* !UIP_CONF_IPV6 */ |
ban4jp | 3:a2715e9c7737 | 1812 | }; |
ban4jp | 3:a2715e9c7737 | 1813 | |
ban4jp | 3:a2715e9c7737 | 1814 | |
ban4jp | 3:a2715e9c7737 | 1815 | /* The UDP headers. */ |
ban4jp | 3:a2715e9c7737 | 1816 | struct uip_udp_hdr { |
ban4jp | 3:a2715e9c7737 | 1817 | uint16_t srcport; |
ban4jp | 3:a2715e9c7737 | 1818 | uint16_t destport; |
ban4jp | 3:a2715e9c7737 | 1819 | uint16_t udplen; |
ban4jp | 3:a2715e9c7737 | 1820 | uint16_t udpchksum; |
ban4jp | 3:a2715e9c7737 | 1821 | }; |
ban4jp | 3:a2715e9c7737 | 1822 | |
ban4jp | 0:685224d2f66d | 1823 | |
ban4jp | 0:685224d2f66d | 1824 | /** |
ban4jp | 0:685224d2f66d | 1825 | * The buffer size available for user data in the \ref uip_buf buffer. |
ban4jp | 0:685224d2f66d | 1826 | * |
ban4jp | 0:685224d2f66d | 1827 | * This macro holds the available size for user data in the \ref |
ban4jp | 0:685224d2f66d | 1828 | * uip_buf buffer. The macro is intended to be used for checking |
ban4jp | 0:685224d2f66d | 1829 | * bounds of available user data. |
ban4jp | 0:685224d2f66d | 1830 | * |
ban4jp | 0:685224d2f66d | 1831 | * Example: |
ban4jp | 0:685224d2f66d | 1832 | \code |
ban4jp | 0:685224d2f66d | 1833 | snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i); |
ban4jp | 0:685224d2f66d | 1834 | \endcode |
ban4jp | 0:685224d2f66d | 1835 | * |
ban4jp | 0:685224d2f66d | 1836 | * \hideinitializer |
ban4jp | 0:685224d2f66d | 1837 | */ |
ban4jp | 0:685224d2f66d | 1838 | #define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) |
ban4jp | 3:a2715e9c7737 | 1839 | #define UIP_APPDATA_PTR (void *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN] |
ban4jp | 0:685224d2f66d | 1840 | |
ban4jp | 0:685224d2f66d | 1841 | #define UIP_PROTO_ICMP 1 |
ban4jp | 0:685224d2f66d | 1842 | #define UIP_PROTO_TCP 6 |
ban4jp | 0:685224d2f66d | 1843 | #define UIP_PROTO_UDP 17 |
ban4jp | 0:685224d2f66d | 1844 | #define UIP_PROTO_ICMP6 58 |
ban4jp | 0:685224d2f66d | 1845 | |
ban4jp | 3:a2715e9c7737 | 1846 | |
ban4jp | 3:a2715e9c7737 | 1847 | #if UIP_CONF_IPV6 |
ban4jp | 3:a2715e9c7737 | 1848 | /** @{ */ |
ban4jp | 3:a2715e9c7737 | 1849 | /** \brief extension headers types */ |
ban4jp | 3:a2715e9c7737 | 1850 | #define UIP_PROTO_HBHO 0 |
ban4jp | 3:a2715e9c7737 | 1851 | #define UIP_PROTO_DESTO 60 |
ban4jp | 3:a2715e9c7737 | 1852 | #define UIP_PROTO_ROUTING 43 |
ban4jp | 3:a2715e9c7737 | 1853 | #define UIP_PROTO_FRAG 44 |
ban4jp | 3:a2715e9c7737 | 1854 | #define UIP_PROTO_NONE 59 |
ban4jp | 3:a2715e9c7737 | 1855 | /** @} */ |
ban4jp | 3:a2715e9c7737 | 1856 | |
ban4jp | 3:a2715e9c7737 | 1857 | /** @{ */ |
ban4jp | 3:a2715e9c7737 | 1858 | /** \brief Destination and Hop By Hop extension headers option types */ |
ban4jp | 3:a2715e9c7737 | 1859 | #define UIP_EXT_HDR_OPT_PAD1 0 |
ban4jp | 3:a2715e9c7737 | 1860 | #define UIP_EXT_HDR_OPT_PADN 1 |
ban4jp | 3:a2715e9c7737 | 1861 | #define UIP_EXT_HDR_OPT_RPL 0x63 |
ban4jp | 3:a2715e9c7737 | 1862 | |
ban4jp | 3:a2715e9c7737 | 1863 | /** @} */ |
ban4jp | 3:a2715e9c7737 | 1864 | |
ban4jp | 3:a2715e9c7737 | 1865 | /** @{ */ |
ban4jp | 3:a2715e9c7737 | 1866 | /** |
ban4jp | 3:a2715e9c7737 | 1867 | * \brief Bitmaps for extension header processing |
ban4jp | 3:a2715e9c7737 | 1868 | * |
ban4jp | 3:a2715e9c7737 | 1869 | * When processing extension headers, we should record somehow which one we |
ban4jp | 3:a2715e9c7737 | 1870 | * see, because you cannot have twice the same header, except for destination |
ban4jp | 3:a2715e9c7737 | 1871 | * We store all this in one uint8_t bitmap one bit for each header expected. The |
ban4jp | 3:a2715e9c7737 | 1872 | * order in the bitmap is the order recommended in RFC2460 |
ban4jp | 3:a2715e9c7737 | 1873 | */ |
ban4jp | 3:a2715e9c7737 | 1874 | #define UIP_EXT_HDR_BITMAP_HBHO 0x01 |
ban4jp | 3:a2715e9c7737 | 1875 | #define UIP_EXT_HDR_BITMAP_DESTO1 0x02 |
ban4jp | 3:a2715e9c7737 | 1876 | #define UIP_EXT_HDR_BITMAP_ROUTING 0x04 |
ban4jp | 3:a2715e9c7737 | 1877 | #define UIP_EXT_HDR_BITMAP_FRAG 0x08 |
ban4jp | 3:a2715e9c7737 | 1878 | #define UIP_EXT_HDR_BITMAP_AH 0x10 |
ban4jp | 3:a2715e9c7737 | 1879 | #define UIP_EXT_HDR_BITMAP_ESP 0x20 |
ban4jp | 3:a2715e9c7737 | 1880 | #define UIP_EXT_HDR_BITMAP_DESTO2 0x40 |
ban4jp | 3:a2715e9c7737 | 1881 | /** @} */ |
ban4jp | 3:a2715e9c7737 | 1882 | |
ban4jp | 3:a2715e9c7737 | 1883 | |
ban4jp | 3:a2715e9c7737 | 1884 | #endif /* UIP_CONF_IPV6 */ |
ban4jp | 3:a2715e9c7737 | 1885 | |
ban4jp | 3:a2715e9c7737 | 1886 | |
ban4jp | 0:685224d2f66d | 1887 | /* Header sizes. */ |
ban4jp | 0:685224d2f66d | 1888 | #if UIP_CONF_IPV6 |
ban4jp | 0:685224d2f66d | 1889 | #define UIP_IPH_LEN 40 |
ban4jp | 3:a2715e9c7737 | 1890 | #define UIP_FRAGH_LEN 8 |
ban4jp | 0:685224d2f66d | 1891 | #else /* UIP_CONF_IPV6 */ |
ban4jp | 0:685224d2f66d | 1892 | #define UIP_IPH_LEN 20 /* Size of IP header */ |
ban4jp | 0:685224d2f66d | 1893 | #endif /* UIP_CONF_IPV6 */ |
ban4jp | 3:a2715e9c7737 | 1894 | |
ban4jp | 0:685224d2f66d | 1895 | #define UIP_UDPH_LEN 8 /* Size of UDP header */ |
ban4jp | 0:685224d2f66d | 1896 | #define UIP_TCPH_LEN 20 /* Size of TCP header */ |
ban4jp | 3:a2715e9c7737 | 1897 | #ifdef UIP_IPH_LEN |
ban4jp | 3:a2715e9c7737 | 1898 | #define UIP_ICMPH_LEN 4 /* Size of ICMP header */ |
ban4jp | 3:a2715e9c7737 | 1899 | #endif |
ban4jp | 0:685224d2f66d | 1900 | #define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + |
ban4jp | 3:a2715e9c7737 | 1901 | * UDP |
ban4jp | 3:a2715e9c7737 | 1902 | * header */ |
ban4jp | 0:685224d2f66d | 1903 | #define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + |
ban4jp | 3:a2715e9c7737 | 1904 | * TCP |
ban4jp | 3:a2715e9c7737 | 1905 | * header */ |
ban4jp | 0:685224d2f66d | 1906 | #define UIP_TCPIP_HLEN UIP_IPTCPH_LEN |
ban4jp | 3:a2715e9c7737 | 1907 | #define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* size of ICMP |
ban4jp | 3:a2715e9c7737 | 1908 | + IP header */ |
ban4jp | 3:a2715e9c7737 | 1909 | #define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN) /* size of L2 |
ban4jp | 3:a2715e9c7737 | 1910 | + IP header */ |
ban4jp | 3:a2715e9c7737 | 1911 | #if UIP_CONF_IPV6 |
ban4jp | 3:a2715e9c7737 | 1912 | /** |
ban4jp | 3:a2715e9c7737 | 1913 | * The sums below are quite used in ND. When used for uip_buf, we |
ban4jp | 3:a2715e9c7737 | 1914 | * include link layer length when used for uip_len, we do not, hence |
ban4jp | 3:a2715e9c7737 | 1915 | * we need values with and without LLH_LEN we do not use capital |
ban4jp | 3:a2715e9c7737 | 1916 | * letters as these values are variable |
ban4jp | 3:a2715e9c7737 | 1917 | */ |
ban4jp | 3:a2715e9c7737 | 1918 | #define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len) |
ban4jp | 3:a2715e9c7737 | 1919 | #define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) |
ban4jp | 3:a2715e9c7737 | 1920 | #define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len) |
ban4jp | 3:a2715e9c7737 | 1921 | #define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) |
ban4jp | 3:a2715e9c7737 | 1922 | #endif /*UIP_CONF_IPV6*/ |
ban4jp | 0:685224d2f66d | 1923 | |
ban4jp | 0:685224d2f66d | 1924 | |
ban4jp | 0:685224d2f66d | 1925 | #if UIP_FIXEDADDR |
ban4jp | 3:a2715e9c7737 | 1926 | CCIF extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; |
ban4jp | 0:685224d2f66d | 1927 | #else /* UIP_FIXEDADDR */ |
ban4jp | 3:a2715e9c7737 | 1928 | CCIF extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; |
ban4jp | 0:685224d2f66d | 1929 | #endif /* UIP_FIXEDADDR */ |
ban4jp | 3:a2715e9c7737 | 1930 | CCIF extern const uip_ipaddr_t uip_broadcast_addr; |
ban4jp | 3:a2715e9c7737 | 1931 | CCIF extern const uip_ipaddr_t uip_all_zeroes_addr; |
ban4jp | 3:a2715e9c7737 | 1932 | |
ban4jp | 3:a2715e9c7737 | 1933 | #if UIP_FIXEDETHADDR |
ban4jp | 3:a2715e9c7737 | 1934 | CCIF extern const uip_lladdr_t uip_lladdr; |
ban4jp | 3:a2715e9c7737 | 1935 | #else |
ban4jp | 3:a2715e9c7737 | 1936 | CCIF extern uip_lladdr_t uip_lladdr; |
ban4jp | 3:a2715e9c7737 | 1937 | #endif |
ban4jp | 3:a2715e9c7737 | 1938 | |
ban4jp | 0:685224d2f66d | 1939 | |
ban4jp | 0:685224d2f66d | 1940 | |
ban4jp | 0:685224d2f66d | 1941 | |
ban4jp | 3:a2715e9c7737 | 1942 | #if UIP_CONF_IPV6 |
ban4jp | 3:a2715e9c7737 | 1943 | /** Length of the link local prefix */ |
ban4jp | 3:a2715e9c7737 | 1944 | #define UIP_LLPREF_LEN 10 |
ban4jp | 3:a2715e9c7737 | 1945 | |
ban4jp | 0:685224d2f66d | 1946 | /** |
ban4jp | 3:a2715e9c7737 | 1947 | * \brief Is IPv6 address a the unspecified address |
ban4jp | 3:a2715e9c7737 | 1948 | * a is of type uip_ipaddr_t |
ban4jp | 3:a2715e9c7737 | 1949 | */ |
ban4jp | 3:a2715e9c7737 | 1950 | #define uip_is_addr_loopback(a) \ |
ban4jp | 3:a2715e9c7737 | 1951 | ((((a)->u16[0]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1952 | (((a)->u16[1]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1953 | (((a)->u16[2]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1954 | (((a)->u16[3]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1955 | (((a)->u16[4]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1956 | (((a)->u16[5]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1957 | (((a)->u16[6]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1958 | (((a)->u8[14]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1959 | (((a)->u8[15]) == 0x01)) |
ban4jp | 3:a2715e9c7737 | 1960 | /** |
ban4jp | 3:a2715e9c7737 | 1961 | * \brief Is IPv6 address a the unspecified address |
ban4jp | 3:a2715e9c7737 | 1962 | * a is of type uip_ipaddr_t |
ban4jp | 3:a2715e9c7737 | 1963 | */ |
ban4jp | 3:a2715e9c7737 | 1964 | #define uip_is_addr_unspecified(a) \ |
ban4jp | 3:a2715e9c7737 | 1965 | ((((a)->u16[0]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1966 | (((a)->u16[1]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1967 | (((a)->u16[2]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1968 | (((a)->u16[3]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1969 | (((a)->u16[4]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1970 | (((a)->u16[5]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1971 | (((a)->u16[6]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1972 | (((a)->u16[7]) == 0)) |
ban4jp | 3:a2715e9c7737 | 1973 | |
ban4jp | 3:a2715e9c7737 | 1974 | /** \brief Is IPv6 address a the link local all-nodes multicast address */ |
ban4jp | 3:a2715e9c7737 | 1975 | #define uip_is_addr_linklocal_allnodes_mcast(a) \ |
ban4jp | 3:a2715e9c7737 | 1976 | ((((a)->u8[0]) == 0xff) && \ |
ban4jp | 3:a2715e9c7737 | 1977 | (((a)->u8[1]) == 0x02) && \ |
ban4jp | 3:a2715e9c7737 | 1978 | (((a)->u16[1]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1979 | (((a)->u16[2]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1980 | (((a)->u16[3]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1981 | (((a)->u16[4]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1982 | (((a)->u16[5]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1983 | (((a)->u16[6]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1984 | (((a)->u8[14]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1985 | (((a)->u8[15]) == 0x01)) |
ban4jp | 3:a2715e9c7737 | 1986 | |
ban4jp | 3:a2715e9c7737 | 1987 | /** \brief Is IPv6 address a the link local all-routers multicast address */ |
ban4jp | 3:a2715e9c7737 | 1988 | #define uip_is_addr_linklocal_allrouters_mcast(a) \ |
ban4jp | 3:a2715e9c7737 | 1989 | ((((a)->u8[0]) == 0xff) && \ |
ban4jp | 3:a2715e9c7737 | 1990 | (((a)->u8[1]) == 0x02) && \ |
ban4jp | 3:a2715e9c7737 | 1991 | (((a)->u16[1]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1992 | (((a)->u16[2]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1993 | (((a)->u16[3]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1994 | (((a)->u16[4]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1995 | (((a)->u16[5]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1996 | (((a)->u16[6]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1997 | (((a)->u8[14]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 1998 | (((a)->u8[15]) == 0x02)) |
ban4jp | 3:a2715e9c7737 | 1999 | |
ban4jp | 3:a2715e9c7737 | 2000 | /** |
ban4jp | 3:a2715e9c7737 | 2001 | * \brief Checks whether the address a is link local. |
ban4jp | 3:a2715e9c7737 | 2002 | * a is of type uip_ipaddr_t |
ban4jp | 3:a2715e9c7737 | 2003 | */ |
ban4jp | 3:a2715e9c7737 | 2004 | #define uip_is_addr_linklocal(a) \ |
ban4jp | 3:a2715e9c7737 | 2005 | ((a)->u8[0] == 0xfe && \ |
ban4jp | 3:a2715e9c7737 | 2006 | (a)->u8[1] == 0x80) |
ban4jp | 3:a2715e9c7737 | 2007 | |
ban4jp | 3:a2715e9c7737 | 2008 | /** \brief set IP address a to unspecified */ |
ban4jp | 3:a2715e9c7737 | 2009 | #define uip_create_unspecified(a) uip_ip6addr(a, 0, 0, 0, 0, 0, 0, 0, 0) |
ban4jp | 3:a2715e9c7737 | 2010 | |
ban4jp | 3:a2715e9c7737 | 2011 | /** \brief set IP address a to the link local all-nodes multicast address */ |
ban4jp | 3:a2715e9c7737 | 2012 | #define uip_create_linklocal_allnodes_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001) |
ban4jp | 3:a2715e9c7737 | 2013 | |
ban4jp | 3:a2715e9c7737 | 2014 | /** \brief set IP address a to the link local all-routers multicast address */ |
ban4jp | 3:a2715e9c7737 | 2015 | #define uip_create_linklocal_allrouters_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002) |
ban4jp | 3:a2715e9c7737 | 2016 | #define uip_create_linklocal_prefix(addr) do { \ |
ban4jp | 3:a2715e9c7737 | 2017 | (addr)->u16[0] = UIP_HTONS(0xfe80); \ |
ban4jp | 3:a2715e9c7737 | 2018 | (addr)->u16[1] = 0; \ |
ban4jp | 3:a2715e9c7737 | 2019 | (addr)->u16[2] = 0; \ |
ban4jp | 3:a2715e9c7737 | 2020 | (addr)->u16[3] = 0; \ |
ban4jp | 3:a2715e9c7737 | 2021 | } while(0) |
ban4jp | 3:a2715e9c7737 | 2022 | |
ban4jp | 3:a2715e9c7737 | 2023 | /** |
ban4jp | 3:a2715e9c7737 | 2024 | * \brief is addr (a) a solicited node multicast address, see RFC3513 |
ban4jp | 3:a2715e9c7737 | 2025 | * a is of type uip_ipaddr_t* |
ban4jp | 0:685224d2f66d | 2026 | */ |
ban4jp | 3:a2715e9c7737 | 2027 | #define uip_is_addr_solicited_node(a) \ |
ban4jp | 3:a2715e9c7737 | 2028 | ((((a)->u8[0]) == 0xFF) && \ |
ban4jp | 3:a2715e9c7737 | 2029 | (((a)->u8[1]) == 0x02) && \ |
ban4jp | 3:a2715e9c7737 | 2030 | (((a)->u16[1]) == 0x00) && \ |
ban4jp | 3:a2715e9c7737 | 2031 | (((a)->u16[2]) == 0x00) && \ |
ban4jp | 3:a2715e9c7737 | 2032 | (((a)->u16[3]) == 0x00) && \ |
ban4jp | 3:a2715e9c7737 | 2033 | (((a)->u16[4]) == 0x00) && \ |
ban4jp | 3:a2715e9c7737 | 2034 | (((a)->u8[10]) == 0x00) && \ |
ban4jp | 3:a2715e9c7737 | 2035 | (((a)->u8[11]) == 0x01) && \ |
ban4jp | 3:a2715e9c7737 | 2036 | (((a)->u8[12]) == 0xFF)) |
ban4jp | 3:a2715e9c7737 | 2037 | |
ban4jp | 3:a2715e9c7737 | 2038 | /** |
ban4jp | 3:a2715e9c7737 | 2039 | * \briefput in b the solicited node address corresponding to address a |
ban4jp | 3:a2715e9c7737 | 2040 | * both a and b are of type uip_ipaddr_t* |
ban4jp | 3:a2715e9c7737 | 2041 | * */ |
ban4jp | 3:a2715e9c7737 | 2042 | #define uip_create_solicited_node(a, b) \ |
ban4jp | 3:a2715e9c7737 | 2043 | (((b)->u8[0]) = 0xFF); \ |
ban4jp | 3:a2715e9c7737 | 2044 | (((b)->u8[1]) = 0x02); \ |
ban4jp | 3:a2715e9c7737 | 2045 | (((b)->u16[1]) = 0); \ |
ban4jp | 3:a2715e9c7737 | 2046 | (((b)->u16[2]) = 0); \ |
ban4jp | 3:a2715e9c7737 | 2047 | (((b)->u16[3]) = 0); \ |
ban4jp | 3:a2715e9c7737 | 2048 | (((b)->u16[4]) = 0); \ |
ban4jp | 3:a2715e9c7737 | 2049 | (((b)->u8[10]) = 0); \ |
ban4jp | 3:a2715e9c7737 | 2050 | (((b)->u8[11]) = 0x01); \ |
ban4jp | 3:a2715e9c7737 | 2051 | (((b)->u8[12]) = 0xFF); \ |
ban4jp | 3:a2715e9c7737 | 2052 | (((b)->u8[13]) = ((a)->u8[13])); \ |
ban4jp | 3:a2715e9c7737 | 2053 | (((b)->u16[7]) = ((a)->u16[7])) |
ban4jp | 3:a2715e9c7737 | 2054 | |
ban4jp | 3:a2715e9c7737 | 2055 | /** |
ban4jp | 3:a2715e9c7737 | 2056 | * \brief is addr (a) a link local unicast address, see RFC3513 |
ban4jp | 3:a2715e9c7737 | 2057 | * i.e. is (a) on prefix FE80::/10 |
ban4jp | 3:a2715e9c7737 | 2058 | * a is of type uip_ipaddr_t* |
ban4jp | 3:a2715e9c7737 | 2059 | */ |
ban4jp | 3:a2715e9c7737 | 2060 | #define uip_is_addr_link_local(a) \ |
ban4jp | 3:a2715e9c7737 | 2061 | ((((a)->u8[0]) == 0xFE) && \ |
ban4jp | 3:a2715e9c7737 | 2062 | (((a)->u8[1]) == 0x80)) |
ban4jp | 3:a2715e9c7737 | 2063 | |
ban4jp | 3:a2715e9c7737 | 2064 | /** |
ban4jp | 3:a2715e9c7737 | 2065 | * \brief was addr (a) forged based on the mac address m |
ban4jp | 3:a2715e9c7737 | 2066 | * a type is uip_ipaddr_t |
ban4jp | 3:a2715e9c7737 | 2067 | * m type is uiplladdr_t |
ban4jp | 3:a2715e9c7737 | 2068 | */ |
ban4jp | 3:a2715e9c7737 | 2069 | #if UIP_CONF_LL_802154 |
ban4jp | 3:a2715e9c7737 | 2070 | #define uip_is_addr_mac_addr_based(a, m) \ |
ban4jp | 3:a2715e9c7737 | 2071 | ((((a)->u8[8]) == (((m)->addr[0]) ^ 0x02)) && \ |
ban4jp | 3:a2715e9c7737 | 2072 | (((a)->u8[9]) == (m)->addr[1]) && \ |
ban4jp | 3:a2715e9c7737 | 2073 | (((a)->u8[10]) == (m)->addr[2]) && \ |
ban4jp | 3:a2715e9c7737 | 2074 | (((a)->u8[11]) == (m)->addr[3]) && \ |
ban4jp | 3:a2715e9c7737 | 2075 | (((a)->u8[12]) == (m)->addr[4]) && \ |
ban4jp | 3:a2715e9c7737 | 2076 | (((a)->u8[13]) == (m)->addr[5]) && \ |
ban4jp | 3:a2715e9c7737 | 2077 | (((a)->u8[14]) == (m)->addr[6]) && \ |
ban4jp | 3:a2715e9c7737 | 2078 | (((a)->u8[15]) == (m)->addr[7])) |
ban4jp | 3:a2715e9c7737 | 2079 | #else |
ban4jp | 3:a2715e9c7737 | 2080 | |
ban4jp | 3:a2715e9c7737 | 2081 | #define uip_is_addr_mac_addr_based(a, m) \ |
ban4jp | 3:a2715e9c7737 | 2082 | ((((a)->u8[8]) == (((m)->addr[0]) | 0x02)) && \ |
ban4jp | 3:a2715e9c7737 | 2083 | (((a)->u8[9]) == (m)->addr[1]) && \ |
ban4jp | 3:a2715e9c7737 | 2084 | (((a)->u8[10]) == (m)->addr[2]) && \ |
ban4jp | 3:a2715e9c7737 | 2085 | (((a)->u8[11]) == 0xff) && \ |
ban4jp | 3:a2715e9c7737 | 2086 | (((a)->u8[12]) == 0xfe) && \ |
ban4jp | 3:a2715e9c7737 | 2087 | (((a)->u8[13]) == (m)->addr[3]) && \ |
ban4jp | 3:a2715e9c7737 | 2088 | (((a)->u8[14]) == (m)->addr[4]) && \ |
ban4jp | 3:a2715e9c7737 | 2089 | (((a)->u8[15]) == (m)->addr[5])) |
ban4jp | 3:a2715e9c7737 | 2090 | |
ban4jp | 3:a2715e9c7737 | 2091 | #endif /*UIP_CONF_LL_802154*/ |
ban4jp | 3:a2715e9c7737 | 2092 | |
ban4jp | 3:a2715e9c7737 | 2093 | /** |
ban4jp | 3:a2715e9c7737 | 2094 | * \brief is address a multicast address, see RFC 3513 |
ban4jp | 3:a2715e9c7737 | 2095 | * a is of type uip_ipaddr_t* |
ban4jp | 3:a2715e9c7737 | 2096 | * */ |
ban4jp | 3:a2715e9c7737 | 2097 | #define uip_is_addr_mcast(a) \ |
ban4jp | 3:a2715e9c7737 | 2098 | (((a)->u8[0]) == 0xFF) |
ban4jp | 3:a2715e9c7737 | 2099 | |
ban4jp | 3:a2715e9c7737 | 2100 | /** |
ban4jp | 3:a2715e9c7737 | 2101 | * \brief is group-id of multicast address a |
ban4jp | 3:a2715e9c7737 | 2102 | * the all nodes group-id |
ban4jp | 3:a2715e9c7737 | 2103 | */ |
ban4jp | 3:a2715e9c7737 | 2104 | #define uip_is_mcast_group_id_all_nodes(a) \ |
ban4jp | 3:a2715e9c7737 | 2105 | ((((a)->u16[1]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2106 | (((a)->u16[2]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2107 | (((a)->u16[3]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2108 | (((a)->u16[4]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2109 | (((a)->u16[5]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2110 | (((a)->u16[6]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2111 | (((a)->u8[14]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2112 | (((a)->u8[15]) == 1)) |
ban4jp | 3:a2715e9c7737 | 2113 | |
ban4jp | 3:a2715e9c7737 | 2114 | /** |
ban4jp | 3:a2715e9c7737 | 2115 | * \brief is group-id of multicast address a |
ban4jp | 3:a2715e9c7737 | 2116 | * the all routers group-id |
ban4jp | 3:a2715e9c7737 | 2117 | */ |
ban4jp | 3:a2715e9c7737 | 2118 | #define uip_is_mcast_group_id_all_routers(a) \ |
ban4jp | 3:a2715e9c7737 | 2119 | ((((a)->u16[1]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2120 | (((a)->u16[2]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2121 | (((a)->u16[3]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2122 | (((a)->u16[4]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2123 | (((a)->u16[5]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2124 | (((a)->u16[6]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2125 | (((a)->u8[14]) == 0) && \ |
ban4jp | 3:a2715e9c7737 | 2126 | (((a)->u8[15]) == 2)) |
ban4jp | 3:a2715e9c7737 | 2127 | |
ban4jp | 3:a2715e9c7737 | 2128 | |
ban4jp | 3:a2715e9c7737 | 2129 | /** |
ban4jp | 3:a2715e9c7737 | 2130 | * \brief are last three bytes of both addresses equal? |
ban4jp | 3:a2715e9c7737 | 2131 | * This is used to compare solicited node multicast addresses |
ban4jp | 3:a2715e9c7737 | 2132 | */ |
ban4jp | 3:a2715e9c7737 | 2133 | #define uip_are_solicited_bytes_equal(a, b) \ |
ban4jp | 3:a2715e9c7737 | 2134 | ((((a)->u8[13]) == ((b)->u8[13])) && \ |
ban4jp | 3:a2715e9c7737 | 2135 | (((a)->u8[14]) == ((b)->u8[14])) && \ |
ban4jp | 3:a2715e9c7737 | 2136 | (((a)->u8[15]) == ((b)->u8[15]))) |
ban4jp | 3:a2715e9c7737 | 2137 | |
ban4jp | 3:a2715e9c7737 | 2138 | #endif /*UIP_CONF_IPV6*/ |
ban4jp | 0:685224d2f66d | 2139 | |
ban4jp | 0:685224d2f66d | 2140 | /** |
ban4jp | 0:685224d2f66d | 2141 | * Calculate the Internet checksum over a buffer. |
ban4jp | 0:685224d2f66d | 2142 | * |
ban4jp | 0:685224d2f66d | 2143 | * The Internet checksum is the one's complement of the one's |
ban4jp | 0:685224d2f66d | 2144 | * complement sum of all 16-bit words in the buffer. |
ban4jp | 0:685224d2f66d | 2145 | * |
ban4jp | 0:685224d2f66d | 2146 | * See RFC1071. |
ban4jp | 0:685224d2f66d | 2147 | * |
ban4jp | 0:685224d2f66d | 2148 | * \param buf A pointer to the buffer over which the checksum is to be |
ban4jp | 0:685224d2f66d | 2149 | * computed. |
ban4jp | 0:685224d2f66d | 2150 | * |
ban4jp | 0:685224d2f66d | 2151 | * \param len The length of the buffer over which the checksum is to |
ban4jp | 0:685224d2f66d | 2152 | * be computed. |
ban4jp | 0:685224d2f66d | 2153 | * |
ban4jp | 0:685224d2f66d | 2154 | * \return The Internet checksum of the buffer. |
ban4jp | 0:685224d2f66d | 2155 | */ |
ban4jp | 3:a2715e9c7737 | 2156 | uint16_t uip_chksum(uint16_t *buf, uint16_t len); |
ban4jp | 0:685224d2f66d | 2157 | |
ban4jp | 0:685224d2f66d | 2158 | /** |
ban4jp | 0:685224d2f66d | 2159 | * Calculate the IP header checksum of the packet header in uip_buf. |
ban4jp | 0:685224d2f66d | 2160 | * |
ban4jp | 0:685224d2f66d | 2161 | * The IP header checksum is the Internet checksum of the 20 bytes of |
ban4jp | 0:685224d2f66d | 2162 | * the IP header. |
ban4jp | 0:685224d2f66d | 2163 | * |
ban4jp | 0:685224d2f66d | 2164 | * \return The IP header checksum of the IP header in the uip_buf |
ban4jp | 0:685224d2f66d | 2165 | * buffer. |
ban4jp | 0:685224d2f66d | 2166 | */ |
ban4jp | 3:a2715e9c7737 | 2167 | uint16_t uip_ipchksum(void); |
ban4jp | 0:685224d2f66d | 2168 | |
ban4jp | 0:685224d2f66d | 2169 | /** |
ban4jp | 0:685224d2f66d | 2170 | * Calculate the TCP checksum of the packet in uip_buf and uip_appdata. |
ban4jp | 0:685224d2f66d | 2171 | * |
ban4jp | 0:685224d2f66d | 2172 | * The TCP checksum is the Internet checksum of data contents of the |
ban4jp | 0:685224d2f66d | 2173 | * TCP segment, and a pseudo-header as defined in RFC793. |
ban4jp | 0:685224d2f66d | 2174 | * |
ban4jp | 0:685224d2f66d | 2175 | * \return The TCP checksum of the TCP segment in uip_buf and pointed |
ban4jp | 0:685224d2f66d | 2176 | * to by uip_appdata. |
ban4jp | 0:685224d2f66d | 2177 | */ |
ban4jp | 3:a2715e9c7737 | 2178 | uint16_t uip_tcpchksum(void); |
ban4jp | 0:685224d2f66d | 2179 | |
ban4jp | 0:685224d2f66d | 2180 | /** |
ban4jp | 0:685224d2f66d | 2181 | * Calculate the UDP checksum of the packet in uip_buf and uip_appdata. |
ban4jp | 0:685224d2f66d | 2182 | * |
ban4jp | 0:685224d2f66d | 2183 | * The UDP checksum is the Internet checksum of data contents of the |
ban4jp | 0:685224d2f66d | 2184 | * UDP segment, and a pseudo-header as defined in RFC768. |
ban4jp | 0:685224d2f66d | 2185 | * |
ban4jp | 0:685224d2f66d | 2186 | * \return The UDP checksum of the UDP segment in uip_buf and pointed |
ban4jp | 0:685224d2f66d | 2187 | * to by uip_appdata. |
ban4jp | 0:685224d2f66d | 2188 | */ |
ban4jp | 3:a2715e9c7737 | 2189 | uint16_t uip_udpchksum(void); |
ban4jp | 3:a2715e9c7737 | 2190 | |
ban4jp | 3:a2715e9c7737 | 2191 | /** |
ban4jp | 3:a2715e9c7737 | 2192 | * Calculate the ICMP checksum of the packet in uip_buf. |
ban4jp | 3:a2715e9c7737 | 2193 | * |
ban4jp | 3:a2715e9c7737 | 2194 | * \return The ICMP checksum of the ICMP packet in uip_buf |
ban4jp | 3:a2715e9c7737 | 2195 | */ |
ban4jp | 3:a2715e9c7737 | 2196 | uint16_t uip_icmp6chksum(void); |
ban4jp | 0:685224d2f66d | 2197 | |
ban4jp | 0:685224d2f66d | 2198 | |
ban4jp | 0:685224d2f66d | 2199 | #endif /* __UIP_H__ */ |
ban4jp | 0:685224d2f66d | 2200 | |
ban4jp | 0:685224d2f66d | 2201 | |
ban4jp | 0:685224d2f66d | 2202 | /** @} */ |