uIP 1.0 based webserver for LPC1114 + ENC28J60

Dependencies:   mbed TMP102

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uip.h Source File

uip.h

Go to the documentation of this file.
00001 
00002 /**
00003  * \addtogroup uip
00004  * @{
00005  */
00006 
00007 /**
00008  * \file
00009  * Header file for the uIP TCP/IP stack.
00010  * \author  Adam Dunkels <adam@dunkels.com>
00011  * \author  Julien Abeille <jabeille@cisco.com> (IPv6 related code)
00012  * \author  Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)
00013  *
00014  * The uIP TCP/IP stack header file contains definitions for a number
00015  * of C macros that are used by uIP programs as well as internal uIP
00016  * structures, TCP/IP header structures and function declarations.
00017  *
00018  */
00019 
00020 /*
00021  * Copyright (c) 2001-2003, Adam Dunkels.
00022  * All rights reserved.
00023  *
00024  * Redistribution and use in source and binary forms, with or without
00025  * modification, are permitted provided that the following conditions
00026  * are met:
00027  * 1. Redistributions of source code must retain the above copyright
00028  *    notice, this list of conditions and the following disclaimer.
00029  * 2. Redistributions in binary form must reproduce the above copyright
00030  *    notice, this list of conditions and the following disclaimer in the
00031  *    documentation and/or other materials provided with the distribution.
00032  * 3. The name of the author may not be used to endorse or promote
00033  *    products derived from this software without specific prior
00034  *    written permission.
00035  *
00036  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00037  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00038  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00039  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00040  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00041  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00042  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00043  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00044  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00045  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00046  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00047  *
00048  * This file is part of the uIP TCP/IP stack.
00049  *
00050  *
00051  */
00052 
00053 #ifndef __UIP_H__
00054 #define __UIP_H__
00055 
00056 #include "uipopt.h"
00057 
00058 /**
00059  * Representation of an IP address.
00060  *
00061  */
00062 typedef union uip_ip4addr_t {
00063   uint8_t  u8[4];           /* Initializer, must come first. */
00064   uint16_t u16[2];
00065 } uip_ip4addr_t;
00066 
00067 typedef union uip_ip6addr_t {
00068   uint8_t  u8[16];          /* Initializer, must come first. */
00069   uint16_t u16[8];
00070 } uip_ip6addr_t;
00071 
00072 #if UIP_CONF_IPV6
00073 typedef uip_ip6addr_t uip_ipaddr_t;
00074 #else /* UIP_CONF_IPV6 */
00075 typedef uip_ip4addr_t uip_ipaddr_t;
00076 #endif /* UIP_CONF_IPV6 */
00077 
00078 
00079 /*---------------------------------------------------------------------------*/
00080 
00081 /** \brief 16 bit 802.15.4 address */
00082 typedef struct uip_802154_shortaddr {
00083   uint8_t addr[2];
00084 } uip_802154_shortaddr;
00085 /** \brief 64 bit 802.15.4 address */
00086 typedef struct uip_802154_longaddr {
00087   uint8_t addr[8];
00088 } uip_802154_longaddr;
00089 
00090 /** \brief 802.11 address */
00091 typedef struct uip_80211_addr {
00092   uint8_t addr[6];
00093 } uip_80211_addr;
00094 
00095 /** \brief 802.3 address */
00096 typedef struct uip_eth_addr {
00097   uint8_t addr[6];
00098 } uip_eth_addr;
00099 
00100 
00101 #if UIP_CONF_LL_802154
00102 /** \brief 802.15.4 address */
00103 typedef uip_802154_longaddr uip_lladdr_t;
00104 #define UIP_802154_SHORTADDR_LEN 2
00105 #define UIP_802154_LONGADDR_LEN  8
00106 #define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN
00107 #else /*UIP_CONF_LL_802154*/
00108 #if UIP_CONF_LL_80211
00109 /** \brief 802.11 address */
00110 typedef uip_80211_addr uip_lladdr_t;
00111 #define UIP_LLADDR_LEN 6
00112 #else /*UIP_CONF_LL_80211*/
00113 /** \brief Ethernet address */
00114 typedef uip_eth_addr uip_lladdr_t;
00115 #define UIP_LLADDR_LEN 6
00116 #endif /*UIP_CONF_LL_80211*/
00117 #endif /*UIP_CONF_LL_802154*/
00118 
00119 //#include "tcpip.h"
00120 
00121 /*---------------------------------------------------------------------------*/
00122 /* First, the functions that should be called from the
00123  * system. Initialization, the periodic timer, and incoming packets are
00124  * handled by the following three functions.
00125  */
00126 /**
00127  * \defgroup uipconffunc uIP configuration functions
00128  * @{
00129  *
00130  * The uIP configuration functions are used for setting run-time
00131  * parameters in uIP such as IP addresses.
00132  */
00133 
00134 /**
00135  * Set the IP address of this host.
00136  *
00137  * The IP address is represented as a 4-byte array where the first
00138  * octet of the IP address is put in the first member of the 4-byte
00139  * array.
00140  *
00141  * Example:
00142  \code
00143 
00144  uip_ipaddr_t addr;
00145 
00146  uip_ipaddr(&addr, 192,168,1,2);
00147  uip_sethostaddr(&addr);
00148  
00149  \endcode
00150  * \param addr A pointer to an IP address of type uip_ipaddr_t;
00151  *
00152  * \sa uip_ipaddr()
00153  *
00154  * \hideinitializer
00155  */
00156 #define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr))
00157 
00158 /**
00159  * Get the IP address of this host.
00160  *
00161  * The IP address is represented as a 4-byte array where the first
00162  * octet of the IP address is put in the first member of the 4-byte
00163  * array.
00164  *
00165  * Example:
00166  \code
00167  uip_ipaddr_t hostaddr;
00168 
00169  uip_gethostaddr(&hostaddr);
00170  \endcode
00171  * \param addr A pointer to a uip_ipaddr_t variable that will be
00172  * filled in with the currently configured IP address.
00173  *
00174  * \hideinitializer
00175  */
00176 #define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr)
00177 
00178 /**
00179  * Set the default router's IP address.
00180  *
00181  * \param addr A pointer to a uip_ipaddr_t variable containing the IP
00182  * address of the default router.
00183  *
00184  * \sa uip_ipaddr()
00185  *
00186  * \hideinitializer
00187  */
00188 #define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr))
00189 
00190 /**
00191  * Set the netmask.
00192  *
00193  * \param addr A pointer to a uip_ipaddr_t variable containing the IP
00194  * address of the netmask.
00195  *
00196  * \sa uip_ipaddr()
00197  *
00198  * \hideinitializer
00199  */
00200 #define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr))
00201 
00202 
00203 /**
00204  * Get the default router's IP address.
00205  *
00206  * \param addr A pointer to a uip_ipaddr_t variable that will be
00207  * filled in with the IP address of the default router.
00208  *
00209  * \hideinitializer
00210  */
00211 #define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr)
00212 
00213 /**
00214  * Get the netmask.
00215  *
00216  * \param addr A pointer to a uip_ipaddr_t variable that will be
00217  * filled in with the value of the netmask.
00218  *
00219  * \hideinitializer
00220  */
00221 #define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask)
00222 
00223 /** @} */
00224 
00225 /**
00226  * \defgroup uipinit uIP initialization functions
00227  * @{
00228  *
00229  * The uIP initialization functions are used for booting uIP.
00230  */
00231 
00232 /**
00233  * uIP initialization function.
00234  *
00235  * This function should be called at boot up to initilize the uIP
00236  * TCP/IP stack.
00237  */
00238 void uip_init(void);
00239 
00240 /**
00241  * uIP initialization function.
00242  *
00243  * This function may be used at boot time to set the initial ip_id.
00244  */
00245 void uip_setipid(uint16_t id);
00246 
00247 /** @} */
00248 
00249 /**
00250  * \defgroup uipdevfunc uIP device driver functions
00251  * @{
00252  *
00253  * These functions are used by a network device driver for interacting
00254  * with uIP.
00255  */
00256 
00257 /**
00258  * Process an incoming packet.
00259  *
00260  * This function should be called when the device driver has received
00261  * a packet from the network. The packet from the device driver must
00262  * be present in the uip_buf buffer, and the length of the packet
00263  * should be placed in the uip_len variable.
00264  *
00265  * When the function returns, there may be an outbound packet placed
00266  * in the uip_buf packet buffer. If so, the uip_len variable is set to
00267  * the length of the packet. If no packet is to be sent out, the
00268  * uip_len variable is set to 0.
00269  *
00270  * The usual way of calling the function is presented by the source
00271  * code below.
00272  \code
00273  uip_len = devicedriver_poll();
00274  if(uip_len > 0) {
00275  uip_input();
00276  if(uip_len > 0) {
00277  devicedriver_send();
00278  }
00279  }
00280  \endcode
00281  *
00282  * \note If you are writing a uIP device driver that needs ARP
00283  * (Address Resolution Protocol), e.g., when running uIP over
00284  * Ethernet, you will need to call the uIP ARP code before calling
00285  * this function:
00286  \code
00287  #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
00288  uip_len = ethernet_devicedrver_poll();
00289  if(uip_len > 0) {
00290  if(BUF->type == UIP_HTONS(UIP_ETHTYPE_IP)) {
00291  uip_arp_ipin();
00292  uip_input();
00293  if(uip_len > 0) {
00294  uip_arp_out();
00295  ethernet_devicedriver_send();
00296  }
00297  } else if(BUF->type == UIP_HTONS(UIP_ETHTYPE_ARP)) {
00298  uip_arp_arpin();
00299  if(uip_len > 0) {
00300  ethernet_devicedriver_send();
00301  }
00302  }
00303  \endcode
00304  *
00305  * \hideinitializer
00306  */
00307 #define uip_input()        uip_process(UIP_DATA)
00308 
00309 
00310 /**
00311  * Periodic processing for a connection identified by its number.
00312  *
00313  * This function does the necessary periodic processing (timers,
00314  * polling) for a uIP TCP conneciton, and should be called when the
00315  * periodic uIP timer goes off. It should be called for every
00316  * connection, regardless of whether they are open of closed.
00317  *
00318  * When the function returns, it may have an outbound packet waiting
00319  * for service in the uIP packet buffer, and if so the uip_len
00320  * variable is set to a value larger than zero. The device driver
00321  * should be called to send out the packet.
00322  *
00323  * The usual way of calling the function is through a for() loop like
00324  * this:
00325  \code
00326  for(i = 0; i < UIP_CONNS; ++i) {
00327  uip_periodic(i);
00328  if(uip_len > 0) {
00329  devicedriver_send();
00330  }
00331  }
00332  \endcode
00333  *
00334  * \note If you are writing a uIP device driver that needs ARP
00335  * (Address Resolution Protocol), e.g., when running uIP over
00336  * Ethernet, you will need to call the uip_arp_out() function before
00337  * calling the device driver:
00338  \code
00339  for(i = 0; i < UIP_CONNS; ++i) {
00340  uip_periodic(i);
00341  if(uip_len > 0) {
00342  uip_arp_out();
00343  ethernet_devicedriver_send();
00344  }
00345  }
00346  \endcode
00347  *
00348  * \param conn The number of the connection which is to be periodically polled.
00349  *
00350  * \hideinitializer
00351  */
00352 #if UIP_TCP
00353 #define uip_periodic(conn) do { uip_conn = &uip_conns[conn];    \
00354     uip_process(UIP_TIMER); } while (0)
00355 
00356 /**
00357  *
00358  *
00359  */
00360 #define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED)
00361 
00362 /**
00363  * Perform periodic processing for a connection identified by a pointer
00364  * to its structure.
00365  *
00366  * Same as uip_periodic() but takes a pointer to the actual uip_conn
00367  * struct instead of an integer as its argument. This function can be
00368  * used to force periodic processing of a specific connection.
00369  *
00370  * \param conn A pointer to the uip_conn struct for the connection to
00371  * be processed.
00372  *
00373  * \hideinitializer
00374  */
00375 #define uip_periodic_conn(conn) do { uip_conn = conn;   \
00376     uip_process(UIP_TIMER); } while (0)
00377 
00378 /**
00379  * Request that a particular connection should be polled.
00380  *
00381  * Similar to uip_periodic_conn() but does not perform any timer
00382  * processing. The application is polled for new data.
00383  *
00384  * \param conn A pointer to the uip_conn struct for the connection to
00385  * be processed.
00386  *
00387  * \hideinitializer
00388  */
00389 #define uip_poll_conn(conn) do { uip_conn = conn;       \
00390     uip_process(UIP_POLL_REQUEST); } while (0)
00391 
00392 #endif /* UIP_TCP */
00393 
00394 #if UIP_UDP
00395 /**
00396  * Periodic processing for a UDP connection identified by its number.
00397  *
00398  * This function is essentially the same as uip_periodic(), but for
00399  * UDP connections. It is called in a similar fashion as the
00400  * uip_periodic() function:
00401  \code
00402  for(i = 0; i < UIP_UDP_CONNS; i++) {
00403  uip_udp_periodic(i);
00404  if(uip_len > 0) {
00405  devicedriver_send();
00406  }
00407  }
00408  \endcode
00409  *
00410  * \note As for the uip_periodic() function, special care has to be
00411  * taken when using uIP together with ARP and Ethernet:
00412  \code
00413  for(i = 0; i < UIP_UDP_CONNS; i++) {
00414  uip_udp_periodic(i);
00415  if(uip_len > 0) {
00416  uip_arp_out();
00417  ethernet_devicedriver_send();
00418  }
00419  }
00420  \endcode
00421  *
00422  * \param conn The number of the UDP connection to be processed.
00423  *
00424  * \hideinitializer
00425  */
00426 #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
00427     uip_process(UIP_UDP_TIMER); } while(0)
00428 
00429 /**
00430  * Periodic processing for a UDP connection identified by a pointer to
00431  * its structure.
00432  *
00433  * Same as uip_udp_periodic() but takes a pointer to the actual
00434  * uip_conn struct instead of an integer as its argument. This
00435  * function can be used to force periodic processing of a specific
00436  * connection.
00437  *
00438  * \param conn A pointer to the uip_udp_conn struct for the connection
00439  * to be processed.
00440  *
00441  * \hideinitializer
00442  */
00443 #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn;   \
00444     uip_process(UIP_UDP_TIMER); } while(0)
00445 #endif /* UIP_UDP */
00446 
00447 /** \brief Abandon the reassembly of the current packet */
00448 void uip_reass_over(void);
00449 
00450 /**
00451  * The uIP packet buffer.
00452  *
00453  * The uip_buf array is used to hold incoming and outgoing
00454  * packets. The device driver should place incoming data into this
00455  * buffer. When sending data, the device driver should read the link
00456  * level headers and the TCP/IP headers from this buffer. The size of
00457  * the link level headers is configured by the UIP_LLH_LEN define.
00458  *
00459  * \note The application data need not be placed in this buffer, so
00460  * the device driver must read it from the place pointed to by the
00461  * uip_appdata pointer as illustrated by the following example:
00462  \code
00463  void
00464  devicedriver_send(void)
00465  {
00466  hwsend(&uip_buf[0], UIP_LLH_LEN);
00467  if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
00468  hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
00469  } else {
00470  hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
00471  hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
00472  }
00473  }
00474  \endcode
00475 */
00476 
00477 typedef union {
00478   uint32_t u32[(UIP_BUFSIZE + 3) / 4];
00479   uint8_t u8[UIP_BUFSIZE];
00480 } uip_buf_t;
00481 
00482 CCIF extern uip_buf_t uip_aligned_buf;
00483 #define uip_buf (uip_aligned_buf.u8)
00484 
00485 
00486 /** @} */
00487 
00488 /*---------------------------------------------------------------------------*/
00489 /* Functions that are used by the uIP application program. Opening and
00490  * closing connections, sending and receiving data, etc. is all
00491  * handled by the functions below.
00492  */
00493 /**
00494  * \defgroup uipappfunc uIP application functions
00495  * @{
00496  *
00497  * Functions used by an application running of top of uIP.
00498  */
00499 
00500 /**
00501  * Start listening to the specified port.
00502  *
00503  * \note Since this function expects the port number in network byte
00504  * order, a conversion using UIP_HTONS() or uip_htons() is necessary.
00505  *
00506  \code
00507  uip_listen(UIP_HTONS(80));
00508  \endcode
00509  *
00510  * \param port A 16-bit port number in network byte order.
00511  */
00512 void uip_listen(uint16_t port);
00513 
00514 /**
00515  * Stop listening to the specified port.
00516  *
00517  * \note Since this function expects the port number in network byte
00518  * order, a conversion using UIP_HTONS() or uip_htons() is necessary.
00519  *
00520  \code
00521  uip_unlisten(UIP_HTONS(80));
00522  \endcode
00523  *
00524  * \param port A 16-bit port number in network byte order.
00525  */
00526 void uip_unlisten(uint16_t port);
00527 
00528 /**
00529  * Connect to a remote host using TCP.
00530  *
00531  * This function is used to start a new connection to the specified
00532  * port on the specified host. It allocates a new connection identifier,
00533  * sets the connection to the SYN_SENT state and sets the
00534  * retransmission timer to 0. This will cause a TCP SYN segment to be
00535  * sent out the next time this connection is periodically processed,
00536  * which usually is done within 0.5 seconds after the call to
00537  * uip_connect().
00538  *
00539  * \note This function is available only if support for active open
00540  * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
00541  *
00542  * \note Since this function requires the port number to be in network
00543  * byte order, a conversion using UIP_HTONS() or uip_htons() is necessary.
00544  *
00545  \code
00546  uip_ipaddr_t ipaddr;
00547 
00548  uip_ipaddr(&ipaddr, 192,168,1,2);
00549  uip_connect(&ipaddr, UIP_HTONS(80));
00550  \endcode
00551  *
00552  * \param ripaddr The IP address of the remote host.
00553  *
00554  * \param port A 16-bit port number in network byte order.
00555  *
00556  * \return A pointer to the uIP connection identifier for the new connection,
00557  * or NULL if no connection could be allocated.
00558  *
00559  */
00560 struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, uint16_t port);
00561 
00562 
00563 
00564 /**
00565  * \internal
00566  *
00567  * Check if a connection has outstanding (i.e., unacknowledged) data.
00568  *
00569  * \param conn A pointer to the uip_conn structure for the connection.
00570  *
00571  * \hideinitializer
00572  */
00573 #define uip_outstanding(conn) ((conn)->len)
00574 
00575 /**
00576  * Send data on the current connection.
00577  *
00578  * This function is used to send out a single segment of TCP
00579  * data. Only applications that have been invoked by uIP for event
00580  * processing can send data.
00581  *
00582  * The amount of data that actually is sent out after a call to this
00583  * function is determined by the maximum amount of data TCP allows. uIP
00584  * will automatically crop the data so that only the appropriate
00585  * amount of data is sent. The function uip_mss() can be used to query
00586  * uIP for the amount of data that actually will be sent.
00587  *
00588  * \note This function does not guarantee that the sent data will
00589  * arrive at the destination. If the data is lost in the network, the
00590  * application will be invoked with the uip_rexmit() event being
00591  * set. The application will then have to resend the data using this
00592  * function.
00593  *
00594  * \param data A pointer to the data which is to be sent.
00595  *
00596  * \param len The maximum amount of data bytes to be sent.
00597  *
00598  * \hideinitializer
00599  */
00600 CCIF void uip_send(const void *data, int len);
00601 
00602 /**
00603  * The length of any incoming data that is currently available (if available)
00604  * in the uip_appdata buffer.
00605  *
00606  * The test function uip_data() must first be used to check if there
00607  * is any data available at all.
00608  *
00609  * \hideinitializer
00610  */
00611 /*void uip_datalen(void);*/
00612 #define uip_datalen()       uip_len
00613 
00614 /**
00615  * The length of any out-of-band data (urgent data) that has arrived
00616  * on the connection.
00617  *
00618  * \note The configuration parameter UIP_URGDATA must be set for this
00619  * function to be enabled.
00620  *
00621  * \hideinitializer
00622  */
00623 #define uip_urgdatalen()    uip_urglen
00624 
00625 /**
00626  * Close the current connection.
00627  *
00628  * This function will close the current connection in a nice way.
00629  *
00630  * \hideinitializer
00631  */
00632 #define uip_close()         (uip_flags = UIP_CLOSE)
00633 
00634 /**
00635  * Abort the current connection.
00636  *
00637  * This function will abort (reset) the current connection, and is
00638  * usually used when an error has occurred that prevents using the
00639  * uip_close() function.
00640  *
00641  * \hideinitializer
00642  */
00643 #define uip_abort()         (uip_flags = UIP_ABORT)
00644 
00645 /**
00646  * Tell the sending host to stop sending data.
00647  *
00648  * This function will close our receiver's window so that we stop
00649  * receiving data for the current connection.
00650  *
00651  * \hideinitializer
00652  */
00653 #define uip_stop()          (uip_conn->tcpstateflags |= UIP_STOPPED)
00654 
00655 /**
00656  * Find out if the current connection has been previously stopped with
00657  * uip_stop().
00658  *
00659  * \hideinitializer
00660  */
00661 #define uip_stopped(conn)   ((conn)->tcpstateflags & UIP_STOPPED)
00662 
00663 /**
00664  * Restart the current connection, if is has previously been stopped
00665  * with uip_stop().
00666  *
00667  * This function will open the receiver's window again so that we
00668  * start receiving data for the current connection.
00669  *
00670  * \hideinitializer
00671  */
00672 #define uip_restart()         do { uip_flags |= UIP_NEWDATA;    \
00673     uip_conn->tcpstateflags &= ~UIP_STOPPED;                    \
00674   } while(0)
00675 
00676 
00677 /* uIP tests that can be made to determine in what state the current
00678    connection is, and what the application function should do. */
00679 
00680 /**
00681  * Is the current connection a UDP connection?
00682  *
00683  * This function checks whether the current connection is a UDP connection.
00684  *
00685  * \hideinitializer
00686  *
00687  */
00688 #define uip_udpconnection() (uip_conn == NULL)
00689 
00690 /**
00691  * Is new incoming data available?
00692  *
00693  * Will reduce to non-zero if there is new data for the application
00694  * present at the uip_appdata pointer. The size of the data is
00695  * available through the uip_len variable.
00696  *
00697  * \hideinitializer
00698  */
00699 #define uip_newdata()   (uip_flags & UIP_NEWDATA)
00700 
00701 /**
00702  * Has previously sent data been acknowledged?
00703  *
00704  * Will reduce to non-zero if the previously sent data has been
00705  * acknowledged by the remote host. This means that the application
00706  * can send new data.
00707  *
00708  * \hideinitializer
00709  */
00710 #define uip_acked()   (uip_flags & UIP_ACKDATA)
00711 
00712 /**
00713  * Has the connection just been connected?
00714  *
00715  * Reduces to non-zero if the current connection has been connected to
00716  * a remote host. This will happen both if the connection has been
00717  * actively opened (with uip_connect()) or passively opened (with
00718  * uip_listen()).
00719  *
00720  * \hideinitializer
00721  */
00722 #define uip_connected() (uip_flags & UIP_CONNECTED)
00723 
00724 /**
00725  * Has the connection been closed by the other end?
00726  *
00727  * Is non-zero if the connection has been closed by the remote
00728  * host. The application may then do the necessary clean-ups.
00729  *
00730  * \hideinitializer
00731  */
00732 #define uip_closed()    (uip_flags & UIP_CLOSE)
00733 
00734 /**
00735  * Has the connection been aborted by the other end?
00736  *
00737  * Non-zero if the current connection has been aborted (reset) by the
00738  * remote host.
00739  *
00740  * \hideinitializer
00741  */
00742 #define uip_aborted()    (uip_flags & UIP_ABORT)
00743 
00744 /**
00745  * Has the connection timed out?
00746  *
00747  * Non-zero if the current connection has been aborted due to too many
00748  * retransmissions.
00749  *
00750  * \hideinitializer
00751  */
00752 #define uip_timedout()    (uip_flags & UIP_TIMEDOUT)
00753 
00754 /**
00755  * Do we need to retransmit previously data?
00756  *
00757  * Reduces to non-zero if the previously sent data has been lost in
00758  * the network, and the application should retransmit it. The
00759  * application should send the exact same data as it did the last
00760  * time, using the uip_send() function.
00761  *
00762  * \hideinitializer
00763  */
00764 #define uip_rexmit()     (uip_flags & UIP_REXMIT)
00765 
00766 /**
00767  * Is the connection being polled by uIP?
00768  *
00769  * Is non-zero if the reason the application is invoked is that the
00770  * current connection has been idle for a while and should be
00771  * polled.
00772  *
00773  * The polling event can be used for sending data without having to
00774  * wait for the remote host to send data.
00775  *
00776  * \hideinitializer
00777  */
00778 #define uip_poll()       (uip_flags & UIP_POLL)
00779 
00780 /**
00781  * Get the initial maximum segment size (MSS) of the current
00782  * connection.
00783  *
00784  * \hideinitializer
00785  */
00786 #define uip_initialmss()             (uip_conn->initialmss)
00787 
00788 /**
00789  * Get the current maximum segment size that can be sent on the current
00790  * connection.
00791  *
00792  * The current maximum segment size that can be sent on the
00793  * connection is computed from the receiver's window and the MSS of
00794  * the connection (which also is available by calling
00795  * uip_initialmss()).
00796  *
00797  * \hideinitializer
00798  */
00799 #define uip_mss()             (uip_conn->mss)
00800 
00801 /**
00802  * Set up a new UDP connection.
00803  *
00804  * This function sets up a new UDP connection. The function will
00805  * automatically allocate an unused local port for the new
00806  * connection. However, another port can be chosen by using the
00807  * uip_udp_bind() call, after the uip_udp_new() function has been
00808  * called.
00809  *
00810  * Example:
00811  \code
00812  uip_ipaddr_t addr;
00813  struct uip_udp_conn *c;
00814  
00815  uip_ipaddr(&addr, 192,168,2,1);
00816  c = uip_udp_new(&addr, UIP_HTONS(12345));
00817  if(c != NULL) {
00818  uip_udp_bind(c, UIP_HTONS(12344));
00819  }
00820  \endcode
00821  * \param ripaddr The IP address of the remote host.
00822  *
00823  * \param rport The remote port number in network byte order.
00824  *
00825  * \return The uip_udp_conn structure for the new connection, or NULL
00826  * if no connection could be allocated.
00827  */
00828 struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport);
00829 
00830 /**
00831  * Remove a UDP connection.
00832  *
00833  * \param conn A pointer to the uip_udp_conn structure for the connection.
00834  *
00835  * \hideinitializer
00836  */
00837 #define uip_udp_remove(conn) (conn)->lport = 0
00838 
00839 /**
00840  * Bind a UDP connection to a local port.
00841  *
00842  * \param conn A pointer to the uip_udp_conn structure for the
00843  * connection.
00844  *
00845  * \param port The local port number, in network byte order.
00846  *
00847  * \hideinitializer
00848  */
00849 #define uip_udp_bind(conn, port) (conn)->lport = port
00850 
00851 /**
00852  * Send a UDP datagram of length len on the current connection.
00853  *
00854  * This function can only be called in response to a UDP event (poll
00855  * or newdata). The data must be present in the uip_buf buffer, at the
00856  * place pointed to by the uip_appdata pointer.
00857  *
00858  * \param len The length of the data in the uip_buf buffer.
00859  *
00860  * \hideinitializer
00861  */
00862 #define uip_udp_send(len) uip_send((char *)uip_appdata, len)
00863 
00864 /** @} */
00865 
00866 /* uIP convenience and converting functions. */
00867 
00868 /**
00869  * \defgroup uipconvfunc uIP conversion functions
00870  * @{
00871  *
00872  * These functions can be used for converting between different data
00873  * formats used by uIP.
00874  */
00875  
00876 /**
00877  * Convert an IP address to four bytes separated by commas.
00878  *
00879  * Example:
00880  \code
00881  uip_ipaddr_t ipaddr;
00882  printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr));
00883  \endcode
00884  *
00885  * \param a A pointer to a uip_ipaddr_t.
00886  * \hideinitializer
00887  */
00888 #define uip_ipaddr_to_quad(a) (a)->u8[0],(a)->u8[1],(a)->u8[2],(a)->u8[3]
00889 
00890 /**
00891  * Construct an IP address from four bytes.
00892  *
00893  * This function constructs an IP address of the type that uIP handles
00894  * internally from four bytes. The function is handy for specifying IP
00895  * addresses to use with e.g. the uip_connect() function.
00896  *
00897  * Example:
00898  \code
00899  uip_ipaddr_t ipaddr;
00900  struct uip_conn *c;
00901  
00902  uip_ipaddr(&ipaddr, 192,168,1,2);
00903  c = uip_connect(&ipaddr, UIP_HTONS(80));
00904  \endcode
00905  *
00906  * \param addr A pointer to a uip_ipaddr_t variable that will be
00907  * filled in with the IP address.
00908  *
00909  * \param addr0 The first octet of the IP address.
00910  * \param addr1 The second octet of the IP address.
00911  * \param addr2 The third octet of the IP address.
00912  * \param addr3 The forth octet of the IP address.
00913  *
00914  * \hideinitializer
00915  */
00916 #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do {  \
00917     (addr)->u8[0] = addr0;                              \
00918     (addr)->u8[1] = addr1;                              \
00919     (addr)->u8[2] = addr2;                              \
00920     (addr)->u8[3] = addr3;                              \
00921   } while(0)
00922 
00923 /**
00924  * Construct an IPv6 address from eight 16-bit words.
00925  *
00926  * This function constructs an IPv6 address.
00927  *
00928  * \hideinitializer
00929  */
00930 #define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
00931     (addr)->u16[0] = UIP_HTONS(addr0);                                      \
00932     (addr)->u16[1] = UIP_HTONS(addr1);                                      \
00933     (addr)->u16[2] = UIP_HTONS(addr2);                                      \
00934     (addr)->u16[3] = UIP_HTONS(addr3);                                      \
00935     (addr)->u16[4] = UIP_HTONS(addr4);                                      \
00936     (addr)->u16[5] = UIP_HTONS(addr5);                                      \
00937     (addr)->u16[6] = UIP_HTONS(addr6);                                      \
00938     (addr)->u16[7] = UIP_HTONS(addr7);                                      \
00939   } while(0)
00940 
00941 /**
00942  * Construct an IPv6 address from sixteen 8-bit words.
00943  *
00944  * This function constructs an IPv6 address.
00945  *
00946  * \hideinitializer
00947  */
00948 #define uip_ip6addr_u8(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7,addr8,addr9,addr10,addr11,addr12,addr13,addr14,addr15) do { \
00949     (addr)->u8[0] = addr0;                                       \
00950     (addr)->u8[1] = addr1;                                       \
00951     (addr)->u8[2] = addr2;                                       \
00952     (addr)->u8[3] = addr3;                                       \
00953     (addr)->u8[4] = addr4;                                       \
00954     (addr)->u8[5] = addr5;                                       \
00955     (addr)->u8[6] = addr6;                                       \
00956     (addr)->u8[7] = addr7;                                       \
00957     (addr)->u8[8] = addr8;                                       \
00958     (addr)->u8[9] = addr9;                                       \
00959     (addr)->u8[10] = addr10;                                     \
00960     (addr)->u8[11] = addr11;                                     \
00961     (addr)->u8[12] = addr12;                                     \
00962     (addr)->u8[13] = addr13;                                     \
00963     (addr)->u8[14] = addr14;                                     \
00964     (addr)->u8[15] = addr15;                                     \
00965   } while(0)
00966 
00967 
00968 /**
00969  * Copy an IP address from one place to another.
00970  *
00971  * Copies an IP address from one place to another.
00972  *
00973  * Example:
00974  \code
00975  uip_ipaddr_t ipaddr1, ipaddr2;
00976 
00977  uip_ipaddr(&ipaddr1, 192,16,1,2);
00978  uip_ipaddr_copy(&ipaddr2, &ipaddr1);
00979  \endcode
00980  *
00981  * \param dest The destination for the copy.
00982  * \param src The source from where to copy.
00983  *
00984  * \hideinitializer
00985  */
00986 #ifndef uip_ipaddr_copy
00987 #define uip_ipaddr_copy(dest, src) (*(dest) = *(src))
00988 #endif
00989 #ifndef uip_ip4addr_copy
00990 #define uip_ip4addr_copy(dest, src) (*(dest) = *(src))
00991 #endif
00992 #ifndef uip_ip6addr_copy
00993 #define uip_ip6addr_copy(dest, src) (*(dest) = *(src))
00994 #endif
00995 
00996 /**
00997  * Compare two IP addresses
00998  *
00999  * Compares two IP addresses.
01000  *
01001  * Example:
01002  \code
01003  uip_ipaddr_t ipaddr1, ipaddr2;
01004 
01005  uip_ipaddr(&ipaddr1, 192,16,1,2);
01006  if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
01007   printf("They are the same");
01008  }
01009  \endcode
01010  *
01011  * \param addr1 The first IP address.
01012  * \param addr2 The second IP address.
01013  *
01014  * \hideinitializer
01015  */
01016 #define uip_ip4addr_cmp(addr1, addr2) ((addr1)->u16[0] == (addr2)->u16[0] && \
01017                       (addr1)->u16[1] == (addr2)->u16[1])
01018 #define uip_ip6addr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
01019 
01020 #if UIP_CONF_IPV6
01021 #define uip_ipaddr_cmp(addr1, addr2) uip_ip6addr_cmp(addr1, addr2)
01022 #else /* UIP_CONF_IPV6 */
01023 #define uip_ipaddr_cmp(addr1, addr2) uip_ip4addr_cmp(addr1, addr2)
01024 #endif /* UIP_CONF_IPV6 */
01025 
01026 /**
01027  * Compare two IP addresses with netmasks
01028  *
01029  * Compares two IP addresses with netmasks. The masks are used to mask
01030  * out the bits that are to be compared.
01031  *
01032  * Example:
01033  \code
01034  uip_ipaddr_t ipaddr1, ipaddr2, mask;
01035 
01036  uip_ipaddr(&mask, 255,255,255,0);
01037  uip_ipaddr(&ipaddr1, 192,16,1,2);
01038  uip_ipaddr(&ipaddr2, 192,16,1,3);
01039  if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
01040  printf("They are the same");
01041  }
01042  \endcode
01043  *
01044  * \param addr1 The first IP address.
01045  * \param addr2 The second IP address.
01046  * \param mask The netmask.
01047  *
01048  * \hideinitializer
01049  */
01050 
01051 #define uip_ipaddr_maskcmp(addr1, addr2, mask)          \
01052   (((((uint16_t *)addr1)[0] & ((uint16_t *)mask)[0]) ==       \
01053     (((uint16_t *)addr2)[0] & ((uint16_t *)mask)[0])) &&      \
01054    ((((uint16_t *)addr1)[1] & ((uint16_t *)mask)[1]) ==       \
01055     (((uint16_t *)addr2)[1] & ((uint16_t *)mask)[1])))
01056 
01057 #define uip_ipaddr_prefixcmp(addr1, addr2, length) (memcmp(addr1, addr2, length>>3) == 0)
01058 
01059 
01060 
01061 /**
01062  * Check if an address is a broadcast address for a network.
01063  *
01064  * Checks if an address is the broadcast address for a network. The
01065  * network is defined by an IP address that is on the network and the
01066  * network's netmask.
01067  *
01068  * \param addr The IP address.
01069  * \param netaddr The network's IP address.
01070  * \param netmask The network's netmask.
01071  *
01072  * \hideinitializer
01073  */
01074 /*#define uip_ipaddr_isbroadcast(addr, netaddr, netmask)
01075   ((uip_ipaddr_t *)(addr)).u16 & ((uip_ipaddr_t *)(addr)).u16*/
01076 
01077 
01078 
01079 /**
01080  * Mask out the network part of an IP address.
01081  *
01082  * Masks out the network part of an IP address, given the address and
01083  * the netmask.
01084  *
01085  * Example:
01086  \code
01087  uip_ipaddr_t ipaddr1, ipaddr2, netmask;
01088 
01089  uip_ipaddr(&ipaddr1, 192,16,1,2);
01090  uip_ipaddr(&netmask, 255,255,255,0);
01091  uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
01092  \endcode
01093  *
01094  * In the example above, the variable "ipaddr2" will contain the IP
01095  * address 192.168.1.0.
01096  *
01097  * \param dest Where the result is to be placed.
01098  * \param src The IP address.
01099  * \param mask The netmask.
01100  *
01101  * \hideinitializer
01102  */
01103 #define uip_ipaddr_mask(dest, src, mask) do {                           \
01104     ((uint16_t *)dest)[0] = ((uint16_t *)src)[0] & ((uint16_t *)mask)[0];        \
01105     ((uint16_t *)dest)[1] = ((uint16_t *)src)[1] & ((uint16_t *)mask)[1];        \
01106   } while(0)
01107 
01108 /**
01109  * Pick the first octet of an IP address.
01110  *
01111  * Picks out the first octet of an IP address.
01112  *
01113  * Example:
01114  \code
01115  uip_ipaddr_t ipaddr;
01116  uint8_t octet;
01117 
01118  uip_ipaddr(&ipaddr, 1,2,3,4);
01119  octet = uip_ipaddr1(&ipaddr);
01120  \endcode
01121  *
01122  * In the example above, the variable "octet" will contain the value 1.
01123  *
01124  * \hideinitializer
01125  */
01126 #define uip_ipaddr1(addr) ((addr)->u8[0])
01127 
01128 /**
01129  * Pick the second octet of an IP address.
01130  *
01131  * Picks out the second octet of an IP address.
01132  *
01133  * Example:
01134  \code
01135  uip_ipaddr_t ipaddr;
01136  uint8_t octet;
01137 
01138  uip_ipaddr(&ipaddr, 1,2,3,4);
01139  octet = uip_ipaddr2(&ipaddr);
01140  \endcode
01141  *
01142  * In the example above, the variable "octet" will contain the value 2.
01143  *
01144  * \hideinitializer
01145  */
01146 #define uip_ipaddr2(addr) ((addr)->u8[1])
01147 
01148 /**
01149  * Pick the third octet of an IP address.
01150  *
01151  * Picks out the third octet of an IP address.
01152  *
01153  * Example:
01154  \code
01155  uip_ipaddr_t ipaddr;
01156  uint8_t octet;
01157 
01158  uip_ipaddr(&ipaddr, 1,2,3,4);
01159  octet = uip_ipaddr3(&ipaddr);
01160  \endcode
01161  *
01162  * In the example above, the variable "octet" will contain the value 3.
01163  *
01164  * \hideinitializer
01165  */
01166 #define uip_ipaddr3(addr) ((addr)->u8[2])
01167 
01168 /**
01169  * Pick the fourth octet of an IP address.
01170  *
01171  * Picks out the fourth octet of an IP address.
01172  *
01173  * Example:
01174  \code
01175  uip_ipaddr_t ipaddr;
01176  uint8_t octet;
01177 
01178  uip_ipaddr(&ipaddr, 1,2,3,4);
01179  octet = uip_ipaddr4(&ipaddr);
01180  \endcode
01181  *
01182  * In the example above, the variable "octet" will contain the value 4.
01183  *
01184  * \hideinitializer
01185  */
01186 #define uip_ipaddr4(addr) ((addr)->u8[3])
01187 
01188 /**
01189  * Convert 16-bit quantity from host byte order to network byte order.
01190  *
01191  * This macro is primarily used for converting constants from host
01192  * byte order to network byte order. For converting variables to
01193  * network byte order, use the uip_htons() function instead.
01194  *
01195  * \hideinitializer
01196  */
01197 #ifndef UIP_HTONS
01198 #   if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
01199 #      define UIP_HTONS(n) (n)
01200 #      define UIP_HTONL(n) (n)
01201 #   else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
01202 #      define UIP_HTONS(n) (uint16_t)((((uint16_t) (n)) << 8) | (((uint16_t) (n)) >> 8))
01203 #      define UIP_HTONL(n) (((uint32_t)UIP_HTONS(n) << 16) | UIP_HTONS((uint32_t)(n) >> 16))
01204 #   endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
01205 #else
01206 #error "UIP_HTONS already defined!"
01207 #endif /* UIP_HTONS */
01208 
01209 /**
01210  * Convert a 16-bit quantity from host byte order to network byte order.
01211  *
01212  * This function is primarily used for converting variables from host
01213  * byte order to network byte order. For converting constants to
01214  * network byte order, use the UIP_HTONS() macro instead.
01215  */
01216 #ifndef uip_htons
01217 CCIF uint16_t uip_htons(uint16_t val);
01218 #endif /* uip_htons */
01219 #ifndef uip_ntohs
01220 #define uip_ntohs uip_htons
01221 #endif
01222 
01223 #ifndef uip_htonl
01224 CCIF uint32_t uip_htonl(uint32_t val);
01225 #endif /* uip_htonl */
01226 #ifndef uip_ntohl
01227 #define uip_ntohl uip_htonl
01228 #endif
01229 
01230 /** @} */
01231 
01232 /**
01233  * Pointer to the application data in the packet buffer.
01234  *
01235  * This pointer points to the application data when the application is
01236  * called. If the application wishes to send data, the application may
01237  * use this space to write the data into before calling uip_send().
01238  */
01239 CCIF extern void *uip_appdata;
01240 
01241 #if UIP_URGDATA > 0
01242 /* uint8_t *uip_urgdata:
01243  *
01244  * This pointer points to any urgent data that has been received. Only
01245  * present if compiled with support for urgent data (UIP_URGDATA).
01246  */
01247 extern void *uip_urgdata;
01248 #endif /* UIP_URGDATA > 0 */
01249 
01250 
01251 /**
01252  * \defgroup uipdrivervars Variables used in uIP device drivers
01253  * @{
01254  *
01255  * uIP has a few global variables that are used in device drivers for
01256  * uIP.
01257  */
01258 
01259 /**
01260  * The length of the packet in the uip_buf buffer.
01261  *
01262  * The global variable uip_len holds the length of the packet in the
01263  * uip_buf buffer.
01264  *
01265  * When the network device driver calls the uIP input function,
01266  * uip_len should be set to the length of the packet in the uip_buf
01267  * buffer.
01268  *
01269  * When sending packets, the device driver should use the contents of
01270  * the uip_len variable to determine the length of the outgoing
01271  * packet.
01272  *
01273  */
01274 CCIF extern uint16_t uip_len;
01275 
01276 /**
01277  * The length of the extension headers
01278  */
01279 extern uint8_t uip_ext_len;
01280 /** @} */
01281 
01282 #if UIP_URGDATA > 0
01283 extern uint16_t uip_urglen, uip_surglen;
01284 #endif /* UIP_URGDATA > 0 */
01285 
01286 
01287 /**
01288  * Representation of a uIP TCP connection.
01289  *
01290  * The uip_conn structure is used for identifying a connection. All
01291  * but one field in the structure are to be considered read-only by an
01292  * application. The only exception is the appstate field whose purpose
01293  * is to let the application store application-specific state (e.g.,
01294  * file pointers) for the connection. The type of this field is
01295  * configured in the "uipopt.h" header file.
01296  */
01297 struct uip_conn {
01298   uip_ipaddr_t ripaddr;   /**< The IP address of the remote host. */
01299   
01300   uint16_t lport;        /**< The local TCP port, in network byte order. */
01301   uint16_t rport;        /**< The local remote TCP port, in network byte
01302              order. */
01303   
01304   uint8_t rcv_nxt[4];    /**< The sequence number that we expect to
01305              receive next. */
01306   uint8_t snd_nxt[4];    /**< The sequence number that was last sent by
01307                          us. */
01308   uint16_t len;          /**< Length of the data that was previously sent. */
01309   uint16_t mss;          /**< Current maximum segment size for the
01310              connection. */
01311   uint16_t initialmss;   /**< Initial maximum segment size for the
01312              connection. */
01313   uint8_t sa;            /**< Retransmission time-out calculation state
01314              variable. */
01315   uint8_t sv;            /**< Retransmission time-out calculation state
01316              variable. */
01317   uint8_t rto;           /**< Retransmission time-out. */
01318   uint8_t tcpstateflags; /**< TCP state and flags. */
01319   uint8_t timer;         /**< The retransmission timer. */
01320   uint8_t nrtx;          /**< The number of retransmissions for the last
01321              segment sent. */
01322 
01323   /** The application state. */
01324   uip_tcp_appstate_t appstate;
01325 };
01326 
01327 
01328 /**
01329  * Pointer to the current TCP connection.
01330  *
01331  * The uip_conn pointer can be used to access the current TCP
01332  * connection.
01333  */
01334 
01335 CCIF extern struct uip_conn *uip_conn;
01336 #if UIP_TCP
01337 /* The array containing all uIP connections. */
01338 CCIF extern struct uip_conn uip_conns[UIP_CONNS];
01339 #endif
01340 
01341 /**
01342  * \addtogroup uiparch
01343  * @{
01344  */
01345 
01346 /**
01347  * 4-byte array used for the 32-bit sequence number calculations.
01348  */
01349 extern uint8_t uip_acc32[4];
01350 /** @} */
01351 
01352 
01353 #if UIP_UDP
01354 /**
01355  * Representation of a uIP UDP connection.
01356  */
01357 struct uip_udp_conn {
01358   uip_ipaddr_t ripaddr;   /**< The IP address of the remote peer. */
01359   uint16_t lport;        /**< The local port number in network byte order. */
01360   uint16_t rport;        /**< The remote port number in network byte order. */
01361   uint8_t  ttl;          /**< Default time-to-live. */
01362 
01363   /** The application state. */
01364   uip_udp_appstate_t appstate;
01365 };
01366 
01367 /**
01368  * The current UDP connection.
01369  */
01370 extern struct uip_udp_conn *uip_udp_conn;
01371 extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
01372 #endif /* UIP_UDP */
01373 
01374 struct uip_fallback_interface {
01375   void (*init)(void);
01376   void (*output)(void);
01377 };
01378 
01379 #if UIP_CONF_ICMP6
01380 struct uip_icmp6_conn {
01381   uip_icmp6_appstate_t appstate;
01382 };
01383 extern struct uip_icmp6_conn uip_icmp6_conns;
01384 #endif /*UIP_CONF_ICMP6*/
01385 
01386 /**
01387  * The uIP TCP/IP statistics.
01388  *
01389  * This is the variable in which the uIP TCP/IP statistics are gathered.
01390  */
01391 #if UIP_STATISTICS == 1
01392 extern struct uip_stats uip_stat;
01393 #define UIP_STAT(s) s
01394 #else
01395 #define UIP_STAT(s)
01396 #endif /* UIP_STATISTICS == 1 */
01397 
01398 /**
01399  * The structure holding the TCP/IP statistics that are gathered if
01400  * UIP_STATISTICS is set to 1.
01401  *
01402  */
01403 struct uip_stats {
01404   struct {
01405     uip_stats_t recv;     /**< Number of received packets at the IP
01406                  layer. */
01407     uip_stats_t sent;     /**< Number of sent packets at the IP
01408                  layer. */
01409     uip_stats_t forwarded;/**< Number of forwarded packets at the IP 
01410                  layer. */
01411     uip_stats_t drop;     /**< Number of dropped packets at the IP
01412                  layer. */
01413     uip_stats_t vhlerr;   /**< Number of packets dropped due to wrong
01414                  IP version or header length. */
01415     uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
01416                  IP length, high byte. */
01417     uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
01418                  IP length, low byte. */
01419     uip_stats_t fragerr;  /**< Number of packets dropped because they
01420                  were IP fragments. */
01421     uip_stats_t chkerr;   /**< Number of packets dropped due to IP
01422                  checksum errors. */
01423     uip_stats_t protoerr; /**< Number of packets dropped because they
01424                  were neither ICMP, UDP nor TCP. */
01425   } ip;                   /**< IP statistics. */
01426   struct {
01427     uip_stats_t recv;     /**< Number of received ICMP packets. */
01428     uip_stats_t sent;     /**< Number of sent ICMP packets. */
01429     uip_stats_t drop;     /**< Number of dropped ICMP packets. */
01430     uip_stats_t typeerr;  /**< Number of ICMP packets with a wrong
01431                  type. */
01432     uip_stats_t chkerr;   /**< Number of ICMP packets with a bad
01433                  checksum. */
01434   } icmp;                 /**< ICMP statistics. */
01435 #if UIP_TCP
01436   struct {
01437     uip_stats_t recv;     /**< Number of recived TCP segments. */
01438     uip_stats_t sent;     /**< Number of sent TCP segments. */
01439     uip_stats_t drop;     /**< Number of dropped TCP segments. */
01440     uip_stats_t chkerr;   /**< Number of TCP segments with a bad
01441                  checksum. */
01442     uip_stats_t ackerr;   /**< Number of TCP segments with a bad ACK
01443                  number. */
01444     uip_stats_t rst;      /**< Number of received TCP RST (reset) segments. */
01445     uip_stats_t rexmit;   /**< Number of retransmitted TCP segments. */
01446     uip_stats_t syndrop;  /**< Number of dropped SYNs because too few
01447                  connections were available. */
01448     uip_stats_t synrst;   /**< Number of SYNs for closed ports,
01449                  triggering a RST. */
01450   } tcp;                  /**< TCP statistics. */
01451 #endif
01452 #if UIP_UDP
01453   struct {
01454     uip_stats_t drop;     /**< Number of dropped UDP segments. */
01455     uip_stats_t recv;     /**< Number of recived UDP segments. */
01456     uip_stats_t sent;     /**< Number of sent UDP segments. */
01457     uip_stats_t chkerr;   /**< Number of UDP segments with a bad
01458                  checksum. */
01459   } udp;                  /**< UDP statistics. */
01460 #endif /* UIP_UDP */
01461 #if UIP_CONF_IPV6
01462   struct {
01463     uip_stats_t drop;     /**< Number of dropped ND6 packets. */
01464     uip_stats_t recv;     /**< Number of recived ND6 packets */
01465     uip_stats_t sent;     /**< Number of sent ND6 packets */
01466   } nd6;
01467 #endif /*UIP_CONF_IPV6*/
01468 };
01469 
01470 
01471 /*---------------------------------------------------------------------------*/
01472 /* All the stuff below this point is internal to uIP and should not be
01473  * used directly by an application or by a device driver.
01474  */
01475 /*---------------------------------------------------------------------------*/
01476 
01477 
01478 
01479 /* uint8_t uip_flags:
01480  *
01481  * When the application is called, uip_flags will contain the flags
01482  * that are defined in this file. Please read below for more
01483  * information.
01484  */
01485 CCIF extern uint8_t uip_flags;
01486 
01487 /* The following flags may be set in the global variable uip_flags
01488    before calling the application callback. The UIP_ACKDATA,
01489    UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
01490    whereas the others are mutually exclusive. Note that these flags
01491    should *NOT* be accessed directly, but only through the uIP
01492    functions/macros. */
01493 
01494 #define UIP_ACKDATA   1     /* Signifies that the outstanding data was
01495                    acked and the application should send
01496                    out new data instead of retransmitting
01497                    the last data. */
01498 #define UIP_NEWDATA   2     /* Flags the fact that the peer has sent
01499                    us new data. */
01500 #define UIP_REXMIT    4     /* Tells the application to retransmit the
01501                    data that was last sent. */
01502 #define UIP_POLL      8     /* Used for polling the application, to
01503                    check if the application has data that
01504                    it wants to send. */
01505 #define UIP_CLOSE     16    /* The remote host has closed the
01506                    connection, thus the connection has
01507                    gone away. Or the application signals
01508                    that it wants to close the
01509                    connection. */
01510 #define UIP_ABORT     32    /* The remote host has aborted the
01511                    connection, thus the connection has
01512                    gone away. Or the application signals
01513                    that it wants to abort the
01514                    connection. */
01515 #define UIP_CONNECTED 64    /* We have got a connection from a remote
01516                                host and have set up a new connection
01517                                for it, or an active connection has
01518                                been successfully established. */
01519 
01520 #define UIP_TIMEDOUT  128   /* The connection has been aborted due to
01521                    too many retransmissions. */
01522 
01523 
01524 /**
01525  * \brief process the options within a hop by hop or destination option header
01526  * \retval 0: nothing to send,
01527  * \retval 1: drop pkt
01528  * \retval 2: ICMP error message to send
01529 */
01530 /*static uint8_t
01531 uip_ext_hdr_options_process(); */
01532 
01533 /* uip_process(flag):
01534  *
01535  * The actual uIP function which does all the work.
01536  */
01537 void uip_process(uint8_t flag);
01538   
01539   /* The following flags are passed as an argument to the uip_process()
01540    function. They are used to distinguish between the two cases where
01541    uip_process() is called. It can be called either because we have
01542    incoming data that should be processed, or because the periodic
01543    timer has fired. These values are never used directly, but only in
01544    the macros defined in this file. */
01545  
01546 #define UIP_DATA          1     /* Tells uIP that there is incoming
01547                    data in the uip_buf buffer. The
01548                    length of the data is stored in the
01549                    global variable uip_len. */
01550 #define UIP_TIMER         2     /* Tells uIP that the periodic timer
01551                    has fired. */
01552 #define UIP_POLL_REQUEST  3     /* Tells uIP that a connection should
01553                    be polled. */
01554 #define UIP_UDP_SEND_CONN 4     /* Tells uIP that a UDP datagram
01555                    should be constructed in the
01556                    uip_buf buffer. */
01557 #if UIP_UDP
01558 #define UIP_UDP_TIMER     5
01559 #endif /* UIP_UDP */
01560 
01561 /* The TCP states used in the uip_conn->tcpstateflags. */
01562 #define UIP_CLOSED      0
01563 #define UIP_SYN_RCVD    1
01564 #define UIP_SYN_SENT    2
01565 #define UIP_ESTABLISHED 3
01566 #define UIP_FIN_WAIT_1  4
01567 #define UIP_FIN_WAIT_2  5
01568 #define UIP_CLOSING     6
01569 #define UIP_TIME_WAIT   7
01570 #define UIP_LAST_ACK    8
01571 #define UIP_TS_MASK     15
01572   
01573 #define UIP_STOPPED      16
01574 
01575 /* The TCP and IP headers. */
01576 struct uip_tcpip_hdr {
01577 #if UIP_CONF_IPV6
01578   /* IPv6 header. */
01579   uint8_t vtc,
01580     tcflow;
01581   uint16_t flow;
01582   uint8_t len[2];
01583   uint8_t proto, ttl;
01584   uip_ip6addr_t srcipaddr, destipaddr;
01585 #else /* UIP_CONF_IPV6 */
01586   /* IPv4 header. */
01587   uint8_t vhl,
01588     tos,
01589     len[2],
01590     ipid[2],
01591     ipoffset[2],
01592     ttl,
01593     proto;
01594   uint16_t ipchksum;
01595   uip_ipaddr_t srcipaddr, destipaddr;
01596 #endif /* UIP_CONF_IPV6 */
01597   
01598   /* TCP header. */
01599   uint16_t srcport,
01600     destport;
01601   uint8_t seqno[4],
01602     ackno[4],
01603     tcpoffset,
01604     flags,
01605     wnd[2];
01606   uint16_t tcpchksum;
01607   uint8_t urgp[2];
01608   uint8_t optdata[4];
01609 };
01610 
01611 /* The ICMP and IP headers. */
01612 struct uip_icmpip_hdr {
01613 #if UIP_CONF_IPV6
01614   /* IPv6 header. */
01615   uint8_t vtc,
01616     tcf;
01617   uint16_t flow;
01618   uint8_t len[2];
01619   uint8_t proto, ttl;
01620   uip_ip6addr_t srcipaddr, destipaddr;
01621 #else /* UIP_CONF_IPV6 */
01622   /* IPv4 header. */
01623   uint8_t vhl,
01624     tos,
01625     len[2],
01626     ipid[2],
01627     ipoffset[2],
01628     ttl,
01629     proto;
01630   uint16_t ipchksum;
01631   uip_ipaddr_t srcipaddr, destipaddr;
01632 #endif /* UIP_CONF_IPV6 */
01633   
01634   /* ICMP header. */
01635   uint8_t type, icode;
01636   uint16_t icmpchksum;
01637 #if !UIP_CONF_IPV6
01638   uint16_t id, seqno;
01639   uint8_t payload[1];
01640 #endif /* !UIP_CONF_IPV6 */
01641 };
01642 
01643 
01644 /* The UDP and IP headers. */
01645 struct uip_udpip_hdr {
01646 #if UIP_CONF_IPV6
01647   /* IPv6 header. */
01648   uint8_t vtc,
01649     tcf;
01650   uint16_t flow;
01651   uint8_t len[2];
01652   uint8_t proto, ttl;
01653   uip_ip6addr_t srcipaddr, destipaddr;
01654 #else /* UIP_CONF_IPV6 */
01655   /* IP header. */
01656   uint8_t vhl,
01657     tos,
01658     len[2],
01659     ipid[2],
01660     ipoffset[2],
01661     ttl,
01662     proto;
01663   uint16_t ipchksum;
01664   uip_ipaddr_t srcipaddr, destipaddr;
01665 #endif /* UIP_CONF_IPV6 */
01666   
01667   /* UDP header. */
01668   uint16_t srcport,
01669     destport;
01670   uint16_t udplen;
01671   uint16_t udpchksum;
01672 };
01673 
01674 /*
01675  * In IPv6 the length of the L3 headers before the transport header is
01676  * not fixed, due to the possibility to include extension option headers
01677  * after the IP header. hence we split here L3 and L4 headers
01678  */
01679 /* The IP header */
01680 struct uip_ip_hdr {
01681 #if UIP_CONF_IPV6
01682   /* IPV6 header */
01683   uint8_t vtc;
01684   uint8_t tcflow;
01685   uint16_t flow;
01686   uint8_t len[2];
01687   uint8_t proto, ttl;
01688   uip_ip6addr_t srcipaddr, destipaddr;
01689 #else /* UIP_CONF_IPV6 */
01690   /* IPV4 header */
01691   uint8_t vhl,
01692     tos,
01693     len[2],
01694     ipid[2],
01695     ipoffset[2],
01696     ttl,
01697     proto;
01698   uint16_t ipchksum;
01699   uip_ipaddr_t srcipaddr, destipaddr;
01700 #endif /* UIP_CONF_IPV6 */
01701 };
01702 
01703 
01704 /*
01705  * IPv6 extension option headers: we are able to process
01706  * the 4 extension headers defined in RFC2460 (IPv6):
01707  * - Hop by hop option header, destination option header:
01708  *   These two are not used by any core IPv6 protocol, hence
01709  *   we just read them and go to the next. They convey options,
01710  *   the options defined in RFC2460 are Pad1 and PadN, which do
01711  *   some padding, and that we do not need to read (the length
01712  *   field in the header is enough)
01713  * - Routing header: this one is most notably used by MIPv6,
01714  *   which we do not implement, hence we just read it and go
01715  *   to the next
01716  * - Fragmentation header: we read this header and are able to
01717  *   reassemble packets
01718  *
01719  * We do not offer any means to send packets with extension headers
01720  *
01721  * We do not implement Authentication and ESP headers, which are
01722  * used in IPSec and defined in RFC4302,4303,4305,4385
01723  */
01724 /* common header part */
01725 typedef struct uip_ext_hdr {
01726   uint8_t next;
01727   uint8_t len;
01728 } uip_ext_hdr;
01729 
01730 /* Hop by Hop option header */
01731 typedef struct uip_hbho_hdr {
01732   uint8_t next;
01733   uint8_t len;
01734 } uip_hbho_hdr;
01735 
01736 /* destination option header */
01737 typedef struct uip_desto_hdr {
01738   uint8_t next;
01739   uint8_t len;
01740 } uip_desto_hdr;
01741 
01742 /* We do not define structures for PAD1 and PADN options */
01743 
01744 /*
01745  * routing header
01746  * the routing header as 4 common bytes, then routing header type
01747  * specific data there are several types of routing header. Type 0 was
01748  * deprecated as per RFC5095 most notable other type is 2, used in
01749  * RFC3775 (MIPv6) here we do not implement MIPv6, so we just need to
01750  * parse the 4 first bytes
01751  */
01752 typedef struct uip_routing_hdr {
01753   uint8_t next;
01754   uint8_t len;
01755   uint8_t routing_type;
01756   uint8_t seg_left;
01757 } uip_routing_hdr;
01758 
01759 /* fragmentation header */
01760 typedef struct uip_frag_hdr {
01761   uint8_t next;
01762   uint8_t res;
01763   uint16_t offsetresmore;
01764   uint32_t id;
01765 } uip_frag_hdr;
01766 
01767 /*
01768  * an option within the destination or hop by hop option headers
01769  * it contains type an length, which is true for all options but PAD1
01770  */
01771 typedef struct uip_ext_hdr_opt {
01772   uint8_t type;
01773   uint8_t len;
01774 } uip_ext_hdr_opt;
01775 
01776 /* PADN option */
01777 typedef struct uip_ext_hdr_opt_padn {
01778   uint8_t opt_type;
01779   uint8_t opt_len;
01780 } uip_ext_hdr_opt_padn;
01781 
01782 /* RPL option */
01783 typedef struct uip_ext_hdr_opt_rpl {
01784   uint8_t opt_type;
01785   uint8_t opt_len;
01786   uint8_t flags;
01787   uint8_t instance;
01788   uint16_t senderrank;
01789 } uip_ext_hdr_opt_rpl;
01790 
01791 /* TCP header */
01792 struct uip_tcp_hdr {
01793   uint16_t srcport;
01794   uint16_t destport;
01795   uint8_t seqno[4];
01796   uint8_t ackno[4];
01797   uint8_t tcpoffset;
01798   uint8_t flags;
01799   uint8_t  wnd[2];
01800   uint16_t tcpchksum;
01801   uint8_t urgp[2];
01802   uint8_t optdata[4];
01803 };
01804 
01805 /* The ICMP headers. */
01806 struct uip_icmp_hdr {
01807   uint8_t type, icode;
01808   uint16_t icmpchksum;
01809 #if !UIP_CONF_IPV6
01810   uint16_t id, seqno;
01811 #endif /* !UIP_CONF_IPV6 */
01812 };
01813 
01814 
01815 /* The UDP headers. */
01816 struct uip_udp_hdr {
01817   uint16_t srcport;
01818   uint16_t destport;
01819   uint16_t udplen;
01820   uint16_t udpchksum;
01821 };
01822 
01823 
01824 /**
01825  * The buffer size available for user data in the \ref uip_buf buffer.
01826  *
01827  * This macro holds the available size for user data in the \ref
01828  * uip_buf buffer. The macro is intended to be used for checking
01829  * bounds of available user data.
01830  *
01831  * Example:
01832  \code
01833  snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
01834  \endcode
01835  *
01836  * \hideinitializer
01837  */
01838 #define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
01839 #define UIP_APPDATA_PTR (void *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]
01840 
01841 #define UIP_PROTO_ICMP  1
01842 #define UIP_PROTO_TCP   6
01843 #define UIP_PROTO_UDP   17
01844 #define UIP_PROTO_ICMP6 58
01845 
01846 
01847 #if UIP_CONF_IPV6
01848 /** @{ */
01849 /** \brief  extension headers types */
01850 #define UIP_PROTO_HBHO        0
01851 #define UIP_PROTO_DESTO       60
01852 #define UIP_PROTO_ROUTING     43
01853 #define UIP_PROTO_FRAG        44
01854 #define UIP_PROTO_NONE        59
01855 /** @} */
01856 
01857 /** @{ */
01858 /** \brief  Destination and Hop By Hop extension headers option types */
01859 #define UIP_EXT_HDR_OPT_PAD1  0
01860 #define UIP_EXT_HDR_OPT_PADN  1
01861 #define UIP_EXT_HDR_OPT_RPL   0x63
01862 
01863 /** @} */
01864 
01865 /** @{ */
01866 /**
01867  * \brief Bitmaps for extension header processing
01868  *
01869  * When processing extension headers, we should record somehow which one we
01870  * see, because you cannot have twice the same header, except for destination
01871  * We store all this in one uint8_t bitmap one bit for each header expected. The
01872  * order in the bitmap is the order recommended in RFC2460
01873  */
01874 #define UIP_EXT_HDR_BITMAP_HBHO 0x01
01875 #define UIP_EXT_HDR_BITMAP_DESTO1 0x02
01876 #define UIP_EXT_HDR_BITMAP_ROUTING 0x04
01877 #define UIP_EXT_HDR_BITMAP_FRAG 0x08
01878 #define UIP_EXT_HDR_BITMAP_AH 0x10
01879 #define UIP_EXT_HDR_BITMAP_ESP 0x20
01880 #define UIP_EXT_HDR_BITMAP_DESTO2 0x40
01881 /** @} */
01882 
01883 
01884 #endif /* UIP_CONF_IPV6 */
01885 
01886 
01887 /* Header sizes. */
01888 #if UIP_CONF_IPV6
01889 #define UIP_IPH_LEN    40
01890 #define UIP_FRAGH_LEN  8
01891 #else /* UIP_CONF_IPV6 */
01892 #define UIP_IPH_LEN    20    /* Size of IP header */
01893 #endif /* UIP_CONF_IPV6 */
01894 
01895 #define UIP_UDPH_LEN    8    /* Size of UDP header */
01896 #define UIP_TCPH_LEN   20    /* Size of TCP header */
01897 #ifdef UIP_IPH_LEN
01898 #define UIP_ICMPH_LEN   4    /* Size of ICMP header */
01899 #endif
01900 #define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN)    /* Size of IP +
01901                         * UDP
01902                                * header */
01903 #define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN)    /* Size of IP +
01904                                * TCP
01905                                * header */
01906 #define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
01907 #define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* size of ICMP
01908                                                          + IP header */
01909 #define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN)    /* size of L2
01910                                                         + IP header */
01911 #if UIP_CONF_IPV6
01912 /**
01913  * The sums below are quite used in ND. When used for uip_buf, we
01914  * include link layer length when used for uip_len, we do not, hence
01915  * we need values with and without LLH_LEN we do not use capital
01916  * letters as these values are variable
01917  */
01918 #define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len)
01919 #define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
01920 #define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len)
01921 #define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
01922 #endif /*UIP_CONF_IPV6*/
01923 
01924 
01925 #if UIP_FIXEDADDR
01926 CCIF extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
01927 #else /* UIP_FIXEDADDR */
01928 CCIF extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
01929 #endif /* UIP_FIXEDADDR */
01930 CCIF extern const uip_ipaddr_t uip_broadcast_addr;
01931 CCIF extern const uip_ipaddr_t uip_all_zeroes_addr;
01932 
01933 #if UIP_FIXEDETHADDR
01934 CCIF extern const uip_lladdr_t uip_lladdr;
01935 #else
01936 CCIF extern uip_lladdr_t uip_lladdr;
01937 #endif
01938 
01939 
01940 
01941 
01942 #if UIP_CONF_IPV6
01943 /** Length of the link local prefix */
01944 #define UIP_LLPREF_LEN     10
01945 
01946 /**
01947  * \brief Is IPv6 address a the unspecified address
01948  * a is of type uip_ipaddr_t
01949  */
01950 #define uip_is_addr_loopback(a)                  \
01951   ((((a)->u16[0]) == 0) &&                       \
01952    (((a)->u16[1]) == 0) &&                       \
01953    (((a)->u16[2]) == 0) &&                       \
01954    (((a)->u16[3]) == 0) &&                       \
01955    (((a)->u16[4]) == 0) &&                       \
01956    (((a)->u16[5]) == 0) &&                       \
01957    (((a)->u16[6]) == 0) &&                       \
01958    (((a)->u8[14]) == 0) &&                       \
01959    (((a)->u8[15]) == 0x01))
01960 /**
01961  * \brief Is IPv6 address a the unspecified address
01962  * a is of type uip_ipaddr_t
01963  */
01964 #define uip_is_addr_unspecified(a)               \
01965   ((((a)->u16[0]) == 0) &&                       \
01966    (((a)->u16[1]) == 0) &&                       \
01967    (((a)->u16[2]) == 0) &&                       \
01968    (((a)->u16[3]) == 0) &&                       \
01969    (((a)->u16[4]) == 0) &&                       \
01970    (((a)->u16[5]) == 0) &&                       \
01971    (((a)->u16[6]) == 0) &&                       \
01972    (((a)->u16[7]) == 0))
01973 
01974 /** \brief Is IPv6 address a the link local all-nodes multicast address */
01975 #define uip_is_addr_linklocal_allnodes_mcast(a)     \
01976   ((((a)->u8[0]) == 0xff) &&                        \
01977    (((a)->u8[1]) == 0x02) &&                        \
01978    (((a)->u16[1]) == 0) &&                          \
01979    (((a)->u16[2]) == 0) &&                          \
01980    (((a)->u16[3]) == 0) &&                          \
01981    (((a)->u16[4]) == 0) &&                          \
01982    (((a)->u16[5]) == 0) &&                          \
01983    (((a)->u16[6]) == 0) &&                          \
01984    (((a)->u8[14]) == 0) &&                          \
01985    (((a)->u8[15]) == 0x01))
01986 
01987 /** \brief Is IPv6 address a the link local all-routers multicast address */
01988 #define uip_is_addr_linklocal_allrouters_mcast(a)     \
01989   ((((a)->u8[0]) == 0xff) &&                        \
01990    (((a)->u8[1]) == 0x02) &&                        \
01991    (((a)->u16[1]) == 0) &&                          \
01992    (((a)->u16[2]) == 0) &&                          \
01993    (((a)->u16[3]) == 0) &&                          \
01994    (((a)->u16[4]) == 0) &&                          \
01995    (((a)->u16[5]) == 0) &&                          \
01996    (((a)->u16[6]) == 0) &&                          \
01997    (((a)->u8[14]) == 0) &&                          \
01998    (((a)->u8[15]) == 0x02))
01999 
02000 /**
02001  * \brief Checks whether the address a is link local.
02002  * a is of type uip_ipaddr_t
02003  */
02004 #define uip_is_addr_linklocal(a)                 \
02005   ((a)->u8[0] == 0xfe &&                         \
02006    (a)->u8[1] == 0x80)
02007 
02008 /** \brief set IP address a to unspecified */
02009 #define uip_create_unspecified(a) uip_ip6addr(a, 0, 0, 0, 0, 0, 0, 0, 0)
02010 
02011 /** \brief set IP address a to the link local all-nodes multicast address */
02012 #define uip_create_linklocal_allnodes_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001)
02013 
02014 /** \brief set IP address a to the link local all-routers multicast address */
02015 #define uip_create_linklocal_allrouters_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002)
02016 #define uip_create_linklocal_prefix(addr) do { \
02017     (addr)->u16[0] = UIP_HTONS(0xfe80);            \
02018     (addr)->u16[1] = 0;                        \
02019     (addr)->u16[2] = 0;                        \
02020     (addr)->u16[3] = 0;                        \
02021   } while(0)
02022 
02023 /**
02024  * \brief  is addr (a) a solicited node multicast address, see RFC3513
02025  *  a is of type uip_ipaddr_t*
02026  */
02027 #define uip_is_addr_solicited_node(a)          \
02028   ((((a)->u8[0])  == 0xFF) &&                  \
02029    (((a)->u8[1])  == 0x02) &&                  \
02030    (((a)->u16[1]) == 0x00) &&                  \
02031    (((a)->u16[2]) == 0x00) &&                  \
02032    (((a)->u16[3]) == 0x00) &&                  \
02033    (((a)->u16[4]) == 0x00) &&                  \
02034    (((a)->u8[10]) == 0x00) &&                  \
02035    (((a)->u8[11]) == 0x01) &&                  \
02036    (((a)->u8[12]) == 0xFF))
02037 
02038 /**
02039  * \briefput in b the solicited node address corresponding to address a
02040  * both a and b are of type uip_ipaddr_t*
02041  * */
02042 #define uip_create_solicited_node(a, b)    \
02043   (((b)->u8[0]) = 0xFF);                        \
02044   (((b)->u8[1]) = 0x02);                        \
02045   (((b)->u16[1]) = 0);                          \
02046   (((b)->u16[2]) = 0);                          \
02047   (((b)->u16[3]) = 0);                          \
02048   (((b)->u16[4]) = 0);                          \
02049   (((b)->u8[10]) = 0);                          \
02050   (((b)->u8[11]) = 0x01);                       \
02051   (((b)->u8[12]) = 0xFF);                       \
02052   (((b)->u8[13]) = ((a)->u8[13]));              \
02053   (((b)->u16[7]) = ((a)->u16[7]))
02054 
02055 /**
02056  * \brief is addr (a) a link local unicast address, see RFC3513
02057  *  i.e. is (a) on prefix FE80::/10
02058  *  a is of type uip_ipaddr_t*
02059  */
02060 #define uip_is_addr_link_local(a) \
02061   ((((a)->u8[0]) == 0xFE) && \
02062   (((a)->u8[1]) == 0x80))
02063 
02064 /**
02065  * \brief was addr (a) forged based on the mac address m
02066  * a type is uip_ipaddr_t
02067  * m type is uiplladdr_t
02068  */
02069 #if UIP_CONF_LL_802154
02070 #define uip_is_addr_mac_addr_based(a, m) \
02071   ((((a)->u8[8])  == (((m)->addr[0]) ^ 0x02)) &&   \
02072    (((a)->u8[9])  == (m)->addr[1]) &&            \
02073    (((a)->u8[10]) == (m)->addr[2]) &&            \
02074    (((a)->u8[11]) == (m)->addr[3]) &&            \
02075    (((a)->u8[12]) == (m)->addr[4]) &&            \
02076    (((a)->u8[13]) == (m)->addr[5]) &&            \
02077    (((a)->u8[14]) == (m)->addr[6]) &&            \
02078    (((a)->u8[15]) == (m)->addr[7]))
02079 #else
02080 
02081 #define uip_is_addr_mac_addr_based(a, m) \
02082   ((((a)->u8[8])  == (((m)->addr[0]) | 0x02)) &&   \
02083    (((a)->u8[9])  == (m)->addr[1]) &&            \
02084    (((a)->u8[10]) == (m)->addr[2]) &&            \
02085    (((a)->u8[11]) == 0xff) &&            \
02086    (((a)->u8[12]) == 0xfe) &&            \
02087    (((a)->u8[13]) == (m)->addr[3]) &&            \
02088    (((a)->u8[14]) == (m)->addr[4]) &&            \
02089    (((a)->u8[15]) == (m)->addr[5]))
02090    
02091 #endif /*UIP_CONF_LL_802154*/
02092 
02093 /**
02094  * \brief is address a multicast address, see RFC 3513
02095  * a is of type uip_ipaddr_t*
02096  * */
02097 #define uip_is_addr_mcast(a)                    \
02098   (((a)->u8[0]) == 0xFF)
02099 
02100 /**
02101  * \brief is group-id of multicast address a
02102  * the all nodes group-id
02103  */
02104 #define uip_is_mcast_group_id_all_nodes(a) \
02105   ((((a)->u16[1])  == 0) &&                 \
02106    (((a)->u16[2])  == 0) &&                 \
02107    (((a)->u16[3])  == 0) &&                 \
02108    (((a)->u16[4])  == 0) &&                 \
02109    (((a)->u16[5])  == 0) &&                 \
02110    (((a)->u16[6])  == 0) &&                 \
02111    (((a)->u8[14])  == 0) &&                 \
02112    (((a)->u8[15])  == 1))
02113 
02114 /**
02115  * \brief is group-id of multicast address a
02116  * the all routers group-id
02117  */
02118 #define uip_is_mcast_group_id_all_routers(a) \
02119   ((((a)->u16[1])  == 0) &&                 \
02120    (((a)->u16[2])  == 0) &&                 \
02121    (((a)->u16[3])  == 0) &&                 \
02122    (((a)->u16[4])  == 0) &&                 \
02123    (((a)->u16[5])  == 0) &&                 \
02124    (((a)->u16[6])  == 0) &&                 \
02125    (((a)->u8[14])  == 0) &&                 \
02126    (((a)->u8[15])  == 2))
02127 
02128 
02129 /**
02130  * \brief are last three bytes of both addresses equal?
02131  * This is used to compare solicited node multicast addresses
02132  */
02133 #define uip_are_solicited_bytes_equal(a, b)             \
02134   ((((a)->u8[13])  == ((b)->u8[13])) &&                 \
02135    (((a)->u8[14])  == ((b)->u8[14])) &&                 \
02136    (((a)->u8[15])  == ((b)->u8[15])))
02137 
02138 #endif /*UIP_CONF_IPV6*/
02139 
02140 /**
02141  * Calculate the Internet checksum over a buffer.
02142  *
02143  * The Internet checksum is the one's complement of the one's
02144  * complement sum of all 16-bit words in the buffer.
02145  *
02146  * See RFC1071.
02147  *
02148  * \param buf A pointer to the buffer over which the checksum is to be
02149  * computed.
02150  *
02151  * \param len The length of the buffer over which the checksum is to
02152  * be computed.
02153  *
02154  * \return The Internet checksum of the buffer.
02155  */
02156 uint16_t uip_chksum(uint16_t *buf, uint16_t len);
02157 
02158 /**
02159  * Calculate the IP header checksum of the packet header in uip_buf.
02160  *
02161  * The IP header checksum is the Internet checksum of the 20 bytes of
02162  * the IP header.
02163  *
02164  * \return The IP header checksum of the IP header in the uip_buf
02165  * buffer.
02166  */
02167 uint16_t uip_ipchksum(void);
02168 
02169 /**
02170  * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
02171  *
02172  * The TCP checksum is the Internet checksum of data contents of the
02173  * TCP segment, and a pseudo-header as defined in RFC793.
02174  *
02175  * \return The TCP checksum of the TCP segment in uip_buf and pointed
02176  * to by uip_appdata.
02177  */
02178 uint16_t uip_tcpchksum(void);
02179 
02180 /**
02181  * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
02182  *
02183  * The UDP checksum is the Internet checksum of data contents of the
02184  * UDP segment, and a pseudo-header as defined in RFC768.
02185  *
02186  * \return The UDP checksum of the UDP segment in uip_buf and pointed
02187  * to by uip_appdata.
02188  */
02189 uint16_t uip_udpchksum(void);
02190 
02191 /**
02192  * Calculate the ICMP checksum of the packet in uip_buf.
02193  *
02194  * \return The ICMP checksum of the ICMP packet in uip_buf
02195  */
02196 uint16_t uip_icmp6chksum(void);
02197 
02198 
02199 #endif /* __UIP_H__ */
02200 
02201 
02202 /** @} */