Fork for fixes

Committer:
hudakz
Date:
Thu Nov 20 21:26:54 2014 +0000
Revision:
1:01c2344f98a3
Parent:
uitility/uip.h@0:5350a66d5279
rev. 01

Who changed what in which revision?

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