These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

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