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