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