Contiki 2.6

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