uIP 1.0 based webserver for LPC1114 + ENC28J60

Dependencies:   mbed TMP102

Committer:
ban4jp
Date:
Sat Jun 14 16:02:21 2014 +0000
Revision:
0:685224d2f66d
Child:
3:a2715e9c7737
initial commit.

Who changed what in which revision?

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