Mbed library for ENC28J60 Ethernet modules. Full support for TCP/IP and UDP Server, Client and HTTP server (webserver). DHCP and DNS is included.

Dependents:   mBuino_ENC28_MQTT Nucleo_Web_ENC28J60 Nucleo_Web_ENC28J60_ADC Serial_over_Ethernet ... more

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  *
00012  * The UIP TCP/IP stack header file contains definitions for a number
00013  * of C macros that are used by UIP programs as well as internal UIP
00014  * structures, TCP/IP header structures and function declarations.
00015  *
00016  */
00017 /*
00018  * Copyright (c) 2001-2003, Adam Dunkels.
00019  * All rights reserved.
00020  *
00021  * Redistribution and use in source and binary forms, with or without
00022  * modification, are permitted provided that the following conditions
00023  * are met:
00024  * 1. Redistributions of source code must retain the above copyright
00025  *    notice, this list of conditions and the following disclaimer.
00026  * 2. Redistributions in binary form must reproduce the above copyright
00027  *    notice, this list of conditions and the following disclaimer in the
00028  *    documentation and/or other materials provided with the distribution.
00029  * 3. The name of the author may not be used to endorse or promote
00030  *    products derived from this software without specific prior
00031  *    written permission.
00032  *
00033  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00034  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00035  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00036  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00037  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00038  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00039  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00040  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00041  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00042  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00043  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00044  *
00045  * This file is part of the UIP TCP/IP stack.
00046  *
00047  * $Id: uip.h,v 1.40 2006/06/08 07:12:07 adam Exp $
00048  *
00049  */
00050 #ifndef __UIP_H__
00051 #define __UIP_H__
00052 
00053 #include "uipopt.h"
00054 
00055 /**
00056  * Repressentation of an IP address.
00057  *
00058  */
00059 
00060 typedef u16_t uip_ip4addr_t[2];
00061 typedef u16_t uip_ip6addr_t[8];
00062 #if UIP_CONF_IPV6
00063 typedef uip_ip6addr_t   uip_ipaddr_t;
00064 #else /* UIP_CONF_IPV6 */
00065 
00066 typedef uip_ip4addr_t   uip_ipaddr_t;
00067 #endif /* UIP_CONF_IPV6 */
00068 
00069 /*---------------------------------------------------------------------------*/
00070 
00071 /* First, the functions that should be called from the
00072  * system. Initialization, the periodic timer and incoming packets are
00073  * handled by the following three functions.
00074  */
00075 /**
00076  * \defgroup uipconffunc UIP configuration functions
00077  * @{
00078  *
00079  * The UIP configuration functions are used for setting run-time
00080  * parameters in UIP such as IP addresses.
00081  */
00082 
00083 /**
00084  * Set the IP address of this host.
00085  *
00086  * The IP address is represented as a 4-byte array where the first
00087  * octet of the IP address is put in the first member of the 4-byte
00088  * array.
00089  *
00090  * Example:
00091  \code
00092 
00093  uip_ipaddr_t addr;
00094 
00095  uip_ipaddr(&addr, 192,168,1,2);
00096  uip_sethostaddr(&addr);
00097  
00098  \endcode
00099  * \param addr A pointer to an IP address of type uip_ipaddr_t;
00100  *
00101  * \sa uip_ipaddr()
00102  *
00103  * \hideinitializer
00104  */
00105 #define uip_sethostaddr(addr)   uip_ipaddr_copy(uip_hostaddr, (addr))
00106 
00107 /**
00108  * Get the IP address of this host.
00109  *
00110  * The IP address is represented as a 4-byte array where the first
00111  * octet of the IP address is put in the first member of the 4-byte
00112  * array.
00113  *
00114  * Example:
00115  \code
00116  uip_ipaddr_t hostaddr;
00117 
00118  uip_gethostaddr(&hostaddr);
00119  \endcode
00120  * \param addr A pointer to a uip_ipaddr_t variable that will be
00121  * filled in with the currently configured IP address.
00122  *
00123  * \hideinitializer
00124  */
00125 
00126 #define uip_gethostaddr(addr)   uip_ipaddr_copy((addr), uip_hostaddr)
00127 
00128 /**
00129  * Set the default router's IP address.
00130  *
00131  * \param addr A pointer to a uip_ipaddr_t variable containing the IP
00132  * address of the default router.
00133  *
00134  * \sa uip_ipaddr()
00135  *
00136  * \hideinitializer
00137  */
00138 
00139 #define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr))
00140 
00141 /**
00142  * Set the netmask.
00143  *
00144  * \param addr A pointer to a uip_ipaddr_t variable containing the IP
00145  * address of the netmask.
00146  *
00147  * \sa uip_ipaddr()
00148  *
00149  * \hideinitializer
00150  */
00151 
00152 #define uip_setnetmask(addr)    uip_ipaddr_copy(uip_netmask, (addr))
00153 
00154 /**
00155  * Get the default router's IP address.
00156  *
00157  * \param addr A pointer to a uip_ipaddr_t variable that will be
00158  * filled in with the IP address of the default router.
00159  *
00160  * \hideinitializer
00161  */
00162 
00163 #define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr)
00164 
00165 /**
00166  * Get the netmask.
00167  *
00168  * \param addr A pointer to a uip_ipaddr_t variable that will be
00169  * filled in with the value of the netmask.
00170  *
00171  * \hideinitializer
00172  */
00173 
00174 #define uip_getnetmask(addr)    uip_ipaddr_copy((addr), uip_netmask)
00175 
00176 /** @} */
00177 
00178 /**
00179  * \defgroup uipinit UIP initialization functions
00180  * @{
00181  *
00182  * The UIP initialization functions are used for booting UIP.
00183  */
00184 /**
00185  * UIP initialization function.
00186  *
00187  * This function should be called at boot up to initilize the UIP
00188  * TCP/IP stack.
00189  */
00190 void    uip_init(void);
00191 
00192 /**
00193  * UIP initialization function.
00194  *
00195  * This function may be used at boot time to set the initial ip_id.
00196  */
00197 void    uip_setipid(u16_t id);
00198 
00199 /** @} */
00200 
00201 /**
00202  * \defgroup uipdevfunc UIP device driver functions
00203  * @{
00204  *
00205  * These functions are used by a network device driver for interacting
00206  * with UIP.
00207  */
00208 
00209 /**
00210  * Process an incoming packet.
00211  *
00212  * This function should be called when the device driver has received
00213  * a packet from the network. The packet from the device driver must
00214  * be present in the uip_buf buffer, and the length of the packet
00215  * should be placed in the uip_len variable.
00216  *
00217  * When the function returns, there may be an outbound packet placed
00218  * in the uip_buf packet buffer. If so, the uip_len variable is set to
00219  * the length of the packet. If no packet is to be sent out, the
00220  * uip_len variable is set to 0.
00221  *
00222  * The usual way of calling the function is presented by the source
00223  * code below.
00224  \code
00225   uip_len = devicedriver_poll();
00226   if(uip_len > 0) {
00227     uip_input();
00228     if(uip_len > 0) {
00229       devicedriver_send();
00230     }
00231   }
00232  \endcode
00233  *
00234  * \note If you are writing a UIP device driver that needs ARP
00235  * (Address Resolution Protocol), e.g., when running UIP over
00236  * Ethernet, you will need to call the UIP ARP code before calling
00237  * this function:
00238  \code
00239   #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
00240   uip_len = ethernet_devicedrver_poll();
00241   if(uip_len > 0) {
00242     if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
00243       uip_arp_ipin();
00244       uip_input();
00245       if(uip_len > 0) {
00246         uip_arp_out();
00247     ethernet_devicedriver_send();
00248       }
00249     } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
00250       uip_arp_arpin();
00251       if(uip_len > 0) {
00252     ethernet_devicedriver_send();
00253       }
00254     }
00255  \endcode
00256  *
00257  * \hideinitializer
00258  */
00259 #define uip_input() uip_process(UIP_DATA)
00260 
00261 /**
00262  * Periodic processing for a connection identified by its number.
00263  *
00264  * This function does the necessary periodic processing (timers,
00265  * polling) for a UIP TCP conneciton, and should be called when the
00266  * periodic UIP timer goes off. It should be called for every
00267  * connection, regardless of whether they are open of closed.
00268  *
00269  * When the function returns, it may have an outbound packet waiting
00270  * for service in the UIP packet buffer, and if so the uip_len
00271  * variable is set to a value larger than zero. The device driver
00272  * should be called to send out the packet.
00273  *
00274  * The ususal way of calling the function is through a for() loop like
00275  * this:
00276  \code
00277   for(i = 0; i < UIP_CONNS; ++i) {
00278     uip_periodic(i);
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_out() function before
00288  * calling the device driver:
00289  \code
00290   for(i = 0; i < UIP_CONNS; ++i) {
00291     uip_periodic(i);
00292     if(uip_len > 0) {
00293       uip_arp_out();
00294       ethernet_devicedriver_send();
00295     }
00296   }
00297  \endcode
00298  *
00299  * \param conn The number of the connection which is to be periodically polled.
00300  *
00301  * \hideinitializer
00302  */
00303 
00304 #define uip_periodic(conn) \
00305     do { \
00306         uip_conn = &uip_conns[conn]; \
00307         uip_process(UIP_TIMER); \
00308     } while (0)
00309 
00310 /**
00311  *
00312  *
00313  */
00314 
00315 #define uip_conn_active(conn)   (uip_conns[conn].tcpstateflags != UIP_CLOSED)
00316 
00317 /**
00318  * Perform periodic processing for a connection identified by a pointer
00319  * to its structure.
00320  *
00321  * Same as uip_periodic() but takes a pointer to the actual uip_conn
00322  * struct instead of an integer as its argument. This function can be
00323  * used to force periodic processing of a specific connection.
00324  *
00325  * \param conn A pointer to the uip_conn struct for the connection to
00326  * be processed.
00327  *
00328  * \hideinitializer
00329  */
00330 
00331 #define uip_periodic_conn(conn) \
00332     do { \
00333         uip_conn = conn; \
00334         uip_process(UIP_TIMER); \
00335     } while (0)
00336 
00337 /**
00338  * Reuqest that a particular connection should be polled.
00339  *
00340  * Similar to uip_periodic_conn() but does not perform any timer
00341  * processing. The application is polled for new data.
00342  *
00343  * \param conn A pointer to the uip_conn struct for the connection to
00344  * be processed.
00345  *
00346  * \hideinitializer
00347  */
00348 
00349 #define uip_poll_conn(conn) \
00350     do { \
00351         uip_conn = conn; \
00352         uip_process(UIP_POLL_REQUEST); \
00353     } while (0)
00354 #if UIP_UDP
00355 
00356 /**
00357  * Periodic processing for a UDP connection identified by its number.
00358  *
00359  * This function is essentially the same as uip_periodic(), but for
00360  * UDP connections. It is called in a similar fashion as the
00361  * uip_periodic() function:
00362  \code
00363   for(i = 0; i < UIP_UDP_CONNS; i++) {
00364     uip_udp_periodic(i);
00365     if(uip_len > 0) {
00366       devicedriver_send();
00367     }
00368   }
00369  \endcode
00370  *
00371  * \note As for the uip_periodic() function, special care has to be
00372  * taken when using UIP together with ARP and Ethernet:
00373  \code
00374   for(i = 0; i < UIP_UDP_CONNS; i++) {
00375     uip_udp_periodic(i);
00376     if(uip_len > 0) {
00377       uip_arp_out();
00378       ethernet_devicedriver_send();
00379     }
00380   }
00381  \endcode
00382  *
00383  * \param conn The number of the UDP connection to be processed.
00384  *
00385  * \hideinitializer
00386  */
00387 
00388 #define uip_udp_periodic(conn) \
00389     do { \
00390         uip_udp_conn = &uip_udp_conns[conn]; \
00391         uip_process(UIP_UDP_TIMER); \
00392     } while (0)
00393 
00394 /**
00395  * Periodic processing for a UDP connection identified by a pointer to
00396  * its structure.
00397  *
00398  * Same as uip_udp_periodic() but takes a pointer to the actual
00399  * uip_conn struct instead of an integer as its argument. This
00400  * function can be used to force periodic processing of a specific
00401  * connection.
00402  *
00403  * \param conn A pointer to the uip_udp_conn struct for the connection
00404  * to be processed.
00405  *
00406  * \hideinitializer
00407  */
00408 
00409 #define uip_udp_periodic_conn(conn) \
00410     do { \
00411         uip_udp_conn = conn; \
00412         uip_process(UIP_UDP_TIMER); \
00413     } while (0)
00414 #endif /* UIP_UDP */
00415 
00416                     /**
00417  * The UIP packet buffer.
00418  *
00419  * The uip_buf array is used to hold incoming and outgoing
00420  * packets. The device driver should place incoming data into this
00421  * buffer. When sending data, the device driver should read the link
00422  * level headers and the TCP/IP headers from this buffer. The size of
00423  * the link level headers is configured by the UIP_LLH_LEN define.
00424  *
00425  * \note The application data need not be placed in this buffer, so
00426  * the device driver must read it from the place pointed to by the
00427  * uip_appdata pointer as illustrated by the following example:
00428  \code
00429  void
00430  devicedriver_send(void)
00431  {
00432     hwsend(&uip_buf[0], UIP_LLH_LEN);
00433     if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
00434       hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
00435     } else {
00436       hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
00437       hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
00438     }
00439  }
00440  \endcode
00441  */
00442                     extern u8_t uip_buf[UIP_BUFSIZE + 2];
00443 
00444 /** @} */
00445 
00446 /*---------------------------------------------------------------------------*/
00447 /* Functions that are used by the UIP application program. Opening and
00448  * closing connections, sending and receiving data, etc. is all
00449  * handled by the functions below.
00450 */
00451 /**
00452  * \defgroup uipappfunc UIP application functions
00453  * @{
00454  *
00455  * Functions used by an application running of top of UIP.
00456  */
00457 /**
00458  * Start listening to the specified port.
00459  *
00460  * \note Since this function expects the port number in network byte
00461  * order, a conversion using HTONS() or htons() is necessary.
00462  *
00463  \code
00464  uip_listen(HTONS(80));
00465  \endcode
00466  *
00467  * \param port A 16-bit port number in network byte order.
00468  */
00469 void                            uip_listen(u16_t port);
00470 
00471 /**
00472  * Stop listening to the specified port.
00473  *
00474  * \note Since this function expects the port number in network byte
00475  * order, a conversion using HTONS() or htons() is necessary.
00476  *
00477  \code
00478  uip_unlisten(HTONS(80));
00479  \endcode
00480  *
00481  * \param port A 16-bit port number in network byte order.
00482  */
00483 void                            uip_unlisten(u16_t port);
00484 
00485 /**
00486  * Connect to a remote host using TCP.
00487  *
00488  * This function is used to start a new connection to the specified
00489  * port on the specied host. It allocates a new connection identifier,
00490  * sets the connection to the SYN_SENT state and sets the
00491  * retransmission timer to 0. This will cause a TCP SYN segment to be
00492  * sent out the next time this connection is periodically processed,
00493  * which usually is done within 0.5 seconds after the call to
00494  * uip_connect().
00495  *
00496  * \note This function is avaliable only if support for active open
00497  * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
00498  *
00499  * \note Since this function requires the port number to be in network
00500  * byte order, a conversion using HTONS() or htons() is necessary.
00501  *
00502  \code
00503  uip_ipaddr_t ipaddr;
00504 
00505  uip_ipaddr(&ipaddr, 192,168,1,2);
00506  uip_connect(&ipaddr, HTONS(80));
00507  \endcode
00508  *
00509  * \param ripaddr The IP address of the remote hot.
00510  *
00511  * \param port A 16-bit port number in network byte order.
00512  *
00513  * \return A pointer to the UIP connection identifier for the new connection,
00514  * or NULL if no connection could be allocated.
00515  *
00516  */
00517 struct uip_conn*                uip_connect(uip_ipaddr_t* ripaddr, u16_t port);
00518 
00519 /**
00520  * \internal
00521  *
00522  * Check if a connection has outstanding (i.e., unacknowledged) data.
00523  *
00524  * \param conn A pointer to the uip_conn structure for the connection.
00525  *
00526  * \hideinitializer
00527  */
00528 
00529 #define uip_outstanding(conn)   ((conn)->len)
00530 
00531 /**
00532  * Send data on the current connection.
00533  *
00534  * This function is used to send out a single segment of TCP
00535  * data. Only applications that have been invoked by UIP for event
00536  * processing can send data.
00537  *
00538  * The amount of data that actually is sent out after a call to this
00539  * funcion is determined by the maximum amount of data TCP allows. UIP
00540  * will automatically crop the data so that only the appropriate
00541  * amount of data is sent. The function uip_mss() can be used to query
00542  * UIP for the amount of data that actually will be sent.
00543  *
00544  * \note This function does not guarantee that the sent data will
00545  * arrive at the destination. If the data is lost in the network, the
00546  * application will be invoked with the uip_rexmit() event being
00547  * set. The application will then have to resend the data using this
00548  * function.
00549  *
00550  * \param data A pointer to the data which is to be sent.
00551  *
00552  * \param len The maximum amount of data bytes to be sent.
00553  *
00554  * \hideinitializer
00555  */
00556 void    uip_send(const void* data, int len);
00557 
00558 /**
00559  * The length of any incoming data that is currently avaliable (if avaliable)
00560  * in the uip_appdata buffer.
00561  *
00562  * The test function uip_data() must first be used to check if there
00563  * is any data available at all.
00564  *
00565  * \hideinitializer
00566  */
00567 
00568 /*void uip_datalen(void);*/
00569 #define uip_datalen()   uip_len
00570 
00571 /**
00572  * The length of any out-of-band data (urgent data) that has arrived
00573  * on the connection.
00574  *
00575  * \note The configuration parameter UIP_URGDATA must be set for this
00576  * function to be enabled.
00577  *
00578  * \hideinitializer
00579  */
00580 
00581 #define uip_urgdatalen()    uip_urglen
00582 
00583 /**
00584  * Close the current connection.
00585  *
00586  * This function will close the current connection in a nice way.
00587  *
00588  * \hideinitializer
00589  */
00590 
00591 #define uip_close() (uip_flags = UIP_CLOSE)
00592 
00593 /**
00594  * Abort the current connection.
00595  *
00596  * This function will abort (reset) the current connection, and is
00597  * usually used when an error has occured that prevents using the
00598  * uip_close() function.
00599  *
00600  * \hideinitializer
00601  */
00602 
00603 #define uip_abort() (uip_flags = UIP_ABORT)
00604 
00605 /**
00606  * Tell the sending host to stop sending data.
00607  *
00608  * This function will close our receiver's window so that we stop
00609  * receiving data for the current connection.
00610  *
00611  * \hideinitializer
00612  */
00613 
00614 #define uip_stop()  (uip_conn->tcpstateflags |= UIP_STOPPED)
00615 
00616 /**
00617  * Find out if the current connection has been previously stopped with
00618  * uip_stop().
00619  *
00620  * \hideinitializer
00621  */
00622 
00623 #define uip_stopped(conn)   ((conn)->tcpstateflags & UIP_STOPPED)
00624 
00625 /**
00626  * Restart the current connection, if is has previously been stopped
00627  * with uip_stop().
00628  *
00629  * This function will open the receiver's window again so that we
00630  * start receiving data for the current connection.
00631  *
00632  * \hideinitializer
00633  */
00634 
00635 #define uip_restart() \
00636     do { \
00637         uip_flags |= UIP_NEWDATA; \
00638         uip_conn->tcpstateflags &= ~UIP_STOPPED; \
00639     } while (0)
00640 
00641     /* UIP tests that can be made to determine in what state the current
00642    connection is, and what the application function should do. */
00643 
00644 /**
00645  * Is the current connection a UDP connection?
00646  *
00647  * This function checks whether the current connection is a UDP connection.
00648  *
00649  * \hideinitializer
00650  *
00651  */
00652 #define uip_udpconnection() (uip_conn == NULL)
00653 
00654 /**
00655  * Is new incoming data available?
00656  *
00657  * Will reduce to non-zero if there is new data for the application
00658  * present at the uip_appdata pointer. The size of the data is
00659  * avaliable through the uip_len variable.
00660  *
00661  * \hideinitializer
00662  */
00663 
00664 #define uip_newdata()   (uip_flags & UIP_NEWDATA)
00665 
00666 /**
00667  * Has previously sent data been acknowledged?
00668  *
00669  * Will reduce to non-zero if the previously sent data has been
00670  * acknowledged by the remote host. This means that the application
00671  * can send new data.
00672  *
00673  * \hideinitializer
00674  */
00675 
00676 #define uip_acked() (uip_flags & UIP_ACKDATA)
00677 
00678 /**
00679  * Has the connection just been connected?
00680  *
00681  * Reduces to non-zero if the current connection has been connected to
00682  * a remote host. This will happen both if the connection has been
00683  * actively opened (with uip_connect()) or passively opened (with
00684  * uip_listen()).
00685  *
00686  * \hideinitializer
00687  */
00688 
00689 #define uip_connected() (uip_flags & UIP_CONNECTED)
00690 
00691 /**
00692  * Has the connection been closed by the other end?
00693  *
00694  * Is non-zero if the connection has been closed by the remote
00695  * host. The application may then do the necessary clean-ups.
00696  *
00697  * \hideinitializer
00698  */
00699 
00700 #define uip_closed()    (uip_flags & UIP_CLOSE)
00701 
00702 /**
00703  * Has the connection been aborted by the other end?
00704  *
00705  * Non-zero if the current connection has been aborted (reset) by the
00706  * remote host.
00707  *
00708  * \hideinitializer
00709  */
00710 
00711 #define uip_aborted()   (uip_flags & UIP_ABORT)
00712 
00713 /**
00714  * Has the connection timed out?
00715  *
00716  * Non-zero if the current connection has been aborted due to too many
00717  * retransmissions.
00718  *
00719  * \hideinitializer
00720  */
00721 
00722 #define uip_timedout()  (uip_flags & UIP_TIMEDOUT)
00723 
00724 /**
00725  * Do we need to retransmit previously data?
00726  *
00727  * Reduces to non-zero if the previously sent data has been lost in
00728  * the network, and the application should retransmit it. The
00729  * application should send the exact same data as it did the last
00730  * time, using the uip_send() function.
00731  *
00732  * \hideinitializer
00733  */
00734 
00735 #define uip_rexmit()    (uip_flags & UIP_REXMIT)
00736 
00737 /**
00738  * Is the connection being polled by UIP?
00739  *
00740  * Is non-zero if the reason the application is invoked is that the
00741  * current connection has been idle for a while and should be
00742  * polled.
00743  *
00744  * The polling event can be used for sending data without having to
00745  * wait for the remote host to send data.
00746  *
00747  * \hideinitializer
00748  */
00749 
00750 #define uip_poll()  (uip_flags & UIP_POLL)
00751 
00752 /**
00753  * Get the initial maxium segment size (MSS) of the current
00754  * connection.
00755  *
00756  * \hideinitializer
00757  */
00758 
00759 #define uip_initialmss()    (uip_conn->initialmss)
00760 
00761 /**
00762  * Get the current maxium segment size that can be sent on the current
00763  * connection.
00764  *
00765  * The current maxiumum segment size that can be sent on the
00766  * connection is computed from the receiver's window and the MSS of
00767  * the connection (which also is available by calling
00768  * uip_initialmss()).
00769  *
00770  * \hideinitializer
00771  */
00772 
00773 #define uip_mss()   (uip_conn->mss)
00774     /**
00775  * Set up a new UDP connection.
00776  *
00777  * This function sets up a new UDP connection. The function will
00778  * automatically allocate an unused local port for the new
00779  * connection. However, another port can be chosen by using the
00780  * uip_udp_bind() call, after the uip_udp_new() function has been
00781  * called.
00782  *
00783  * Example:
00784  \code
00785  uip_ipaddr_t addr;
00786  struct uip_udp_conn *c;
00787  
00788  uip_ipaddr(&addr, 192,168,2,1);
00789  c = uip_udp_new(&addr, HTONS(12345));
00790  if(c != NULL) {
00791    uip_udp_bind(c, HTONS(12344));
00792  }
00793  \endcode
00794  * \param ripaddr The IP address of the remote host.
00795  *
00796  * \param rport The remote port number in network byte order.
00797  *
00798  * \return The uip_udp_conn structure for the new connection or NULL
00799  * if no connection could be allocated.
00800  */
00801     struct uip_udp_conn*    uip_udp_new(uip_ipaddr_t* ripaddr, u16_t rport);
00802 
00803 /**
00804  * Removed a UDP connection.
00805  *
00806  * \param conn A pointer to the uip_udp_conn structure for the connection.
00807  *
00808  * \hideinitializer
00809  */
00810 
00811 #define uip_udp_remove(conn)    (conn)->lport = 0
00812 
00813 /**
00814  * Bind a UDP connection to a local port.
00815  *
00816  * \param conn A pointer to the uip_udp_conn structure for the
00817  * connection.
00818  *
00819  * \param port The local port number, in network byte order.
00820  *
00821  * \hideinitializer
00822  */
00823 
00824 #define uip_udp_bind(conn, port)    (conn)->lport = port
00825 
00826 /**
00827  * Send a UDP datagram of length len on the current connection.
00828  *
00829  * This function can only be called in response to a UDP event (poll
00830  * or newdata). The data must be present in the uip_buf buffer, at the
00831  * place pointed to by the uip_appdata pointer.
00832  *
00833  * \param len The length of the data in the uip_buf buffer.
00834  *
00835  * \hideinitializer
00836  */
00837 
00838 #define uip_udp_send(len)   uip_send((char*)uip_appdata, len)
00839 
00840 /** @} */
00841 
00842 /* UIP convenience and converting functions. */
00843 /**
00844  * \defgroup uipconvfunc UIP conversion functions
00845  * @{
00846  *
00847  * These functions can be used for converting between different data
00848  * formats used by UIP.
00849  */
00850 
00851 /**
00852  * Construct an IP address from four bytes.
00853  *
00854  * This function constructs an IP address of the type that UIP handles
00855  * internally from four bytes. The function is handy for specifying IP
00856  * addresses to use with e.g. the uip_connect() function.
00857  *
00858  * Example:
00859  \code
00860  uip_ipaddr_t ipaddr;
00861  struct uip_conn *c;
00862  
00863  uip_ipaddr(&ipaddr, 192,168,1,2);
00864  c = uip_connect(&ipaddr, HTONS(80));
00865  \endcode
00866  *
00867  * \param addr A pointer to a uip_ipaddr_t variable that will be
00868  * filled in with the IP address.
00869  *
00870  * \param addr0 The first octet of the IP address.
00871  * \param addr1 The second octet of the IP address.
00872  * \param addr2 The third octet of the IP address.
00873  * \param addr3 The forth octet of the IP address.
00874  *
00875  * \hideinitializer
00876  */
00877 #define uip_ipaddr(addr, addr0, addr1, addr2, addr3) \
00878     do { \
00879         ((u16_t *) (addr))[0] = HTONS(((addr0) << 8) | (addr1)); \
00880         ((u16_t *) (addr))[1] = HTONS(((addr2) << 8) | (addr3)); \
00881     } while (0)
00882 
00883 /**
00884  * Construct an IPv6 address from eight 16-bit words.
00885  *
00886  * This function constructs an IPv6 address.
00887  *
00888  * \hideinitializer
00889  */
00890 
00891 #define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7) \
00892     do { \
00893         ((u16_t *) (addr))[0] = HTONS((addr0)); \
00894         ((u16_t *) (addr))[1] = HTONS((addr1)); \
00895         ((u16_t *) (addr))[2] = HTONS((addr2)); \
00896         ((u16_t *) (addr))[3] = HTONS((addr3)); \
00897         ((u16_t *) (addr))[4] = HTONS((addr4)); \
00898         ((u16_t *) (addr))[5] = HTONS((addr5)); \
00899         ((u16_t *) (addr))[6] = HTONS((addr6)); \
00900         ((u16_t *) (addr))[7] = HTONS((addr7)); \
00901     } while (0) /**
00902  * Copy an IP address to another IP address.
00903  *
00904  * Copies an IP address from one place to another.
00905  *
00906  * Example:
00907  \code
00908  uip_ipaddr_t ipaddr1, ipaddr2;
00909 
00910  uip_ipaddr(&ipaddr1, 192,16,1,2);
00911  uip_ipaddr_copy(&ipaddr2, &ipaddr1);
00912  \endcode
00913  *
00914  * \param dest The destination for the copy.
00915  * \param src The source from where to copy.
00916  *
00917  * \hideinitializer
00918  */
00919 
00920 #if !UIP_CONF_IPV6
00921 #define uip_ipaddr_copy(dest, src) \
00922     do { \
00923         ((u16_t*)dest)[0] = ((u16_t*)src)[0]; \
00924         ((u16_t*)dest)[1] = ((u16_t*)src)[1]; \
00925     } while (0)
00926 #else /* !UIP_CONF_IPV6 */
00927 
00928 #define uip_ipaddr_copy(dest, src)  memcpy(dest, src, sizeof(uip_ip6addr_t))
00929 #endif /* !UIP_CONF_IPV6 */
00930 
00931             /**
00932  * Compare two IP addresses
00933  *
00934  * Compares two IP addresses.
00935  *
00936  * Example:
00937  \code
00938  uip_ipaddr_t ipaddr1, ipaddr2;
00939 
00940  uip_ipaddr(&ipaddr1, 192,16,1,2);
00941  if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
00942     printf("They are the same");
00943  }
00944  \endcode
00945  *
00946  * \param addr1 The first IP address.
00947  * \param addr2 The second IP address.
00948  *
00949  * \hideinitializer
00950  */
00951 
00952 #if !UIP_CONF_IPV6
00953 #define uip_ipaddr_cmp(addr1, addr2) \
00954         (((u16_t*)addr1)[0] == ((u16_t*)addr2)[0] && ((u16_t*)addr1)[1] == ((u16_t*)addr2)[1])
00955 #else /* !UIP_CONF_IPV6 */
00956 
00957 #define uip_ipaddr_cmp(addr1, addr2)    (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
00958 #endif /* !UIP_CONF_IPV6 */
00959 
00960 /**
00961  * Compare two IP addresses with netmasks
00962  *
00963  * Compares two IP addresses with netmasks. The masks are used to mask
00964  * out the bits that are to be compared.
00965  *
00966  * Example:
00967  \code
00968  uip_ipaddr_t ipaddr1, ipaddr2, mask;
00969 
00970  uip_ipaddr(&mask, 255,255,255,0);
00971  uip_ipaddr(&ipaddr1, 192,16,1,2);
00972  uip_ipaddr(&ipaddr2, 192,16,1,3);
00973  if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
00974     printf("They are the same");
00975  }
00976  \endcode
00977  *
00978  * \param addr1 The first IP address.
00979  * \param addr2 The second IP address.
00980  * \param mask The netmask.
00981  *
00982  * \hideinitializer
00983  */
00984 
00985 #define uip_ipaddr_maskcmp(addr1, addr2, mask) \
00986         ( \
00987             ((((u16_t*)addr1)[0] & ((u16_t*)mask)[0]) == (((u16_t*)addr2)[0] & ((u16_t*)mask)[0])) \
00988         &&  ((((u16_t*)addr1)[1] & ((u16_t*)mask)[1]) == (((u16_t*)addr2)[1] & ((u16_t*)mask)[1])) \
00989         )
00990 
00991 /**
00992  * Mask out the network part of an IP address.
00993  *
00994  * Masks out the network part of an IP address, given the address and
00995  * the netmask.
00996  *
00997  * Example:
00998  \code
00999  uip_ipaddr_t ipaddr1, ipaddr2, netmask;
01000 
01001  uip_ipaddr(&ipaddr1, 192,16,1,2);
01002  uip_ipaddr(&netmask, 255,255,255,0);
01003  uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
01004  \endcode
01005  *
01006  * In the example above, the variable "ipaddr2" will contain the IP
01007  * address 192.168.1.0.
01008  *
01009  * \param dest Where the result is to be placed.
01010  * \param src The IP address.
01011  * \param mask The netmask.
01012  *
01013  * \hideinitializer
01014  */
01015 
01016 #define uip_ipaddr_mask(dest, src, mask) \
01017     do { \
01018         ((u16_t*)dest)[0] = ((u16_t*)src)[0] & ((u16_t*)mask)[0]; \
01019         ((u16_t*)dest)[1] = ((u16_t*)src)[1] & ((u16_t*)mask)[1]; \
01020     } while (0)
01021 
01022 /**
01023  * Pick the first octet of an IP address.
01024  *
01025  * Picks out the first octet of an IP address.
01026  *
01027  * Example:
01028  \code
01029  uip_ipaddr_t ipaddr;
01030  u8_t octet;
01031 
01032  uip_ipaddr(&ipaddr, 1,2,3,4);
01033  octet = uip_ipaddr1(&ipaddr);
01034  \endcode
01035  *
01036  * In the example above, the variable "octet" will contain the value 1.
01037  *
01038  * \hideinitializer
01039  */
01040 
01041 #define uip_ipaddr1(addr)   (htons(((u16_t *) (addr))[0]) >> 8)
01042 
01043 /**
01044  * Pick the second octet of an IP address.
01045  *
01046  * Picks out the second octet of an IP address.
01047  *
01048  * Example:
01049  \code
01050  uip_ipaddr_t ipaddr;
01051  u8_t octet;
01052 
01053  uip_ipaddr(&ipaddr, 1,2,3,4);
01054  octet = uip_ipaddr2(&ipaddr);
01055  \endcode
01056  *
01057  * In the example above, the variable "octet" will contain the value 2.
01058  *
01059  * \hideinitializer
01060  */
01061 
01062 #define uip_ipaddr2(addr)   (htons(((u16_t *) (addr))[0]) & 0xff)
01063 
01064 /**
01065  * Pick the third octet of an IP address.
01066  *
01067  * Picks out the third octet of an IP address.
01068  *
01069  * Example:
01070  \code
01071  uip_ipaddr_t ipaddr;
01072  u8_t octet;
01073 
01074  uip_ipaddr(&ipaddr, 1,2,3,4);
01075  octet = uip_ipaddr3(&ipaddr);
01076  \endcode
01077  *
01078  * In the example above, the variable "octet" will contain the value 3.
01079  *
01080  * \hideinitializer
01081  */
01082 
01083 #define uip_ipaddr3(addr)   (htons(((u16_t *) (addr))[1]) >> 8)
01084 
01085 /**
01086  * Pick the fourth octet of an IP address.
01087  *
01088  * Picks out the fourth octet of an IP address.
01089  *
01090  * Example:
01091  \code
01092  uip_ipaddr_t ipaddr;
01093  u8_t octet;
01094 
01095  uip_ipaddr(&ipaddr, 1,2,3,4);
01096  octet = uip_ipaddr4(&ipaddr);
01097  \endcode
01098  *
01099  * In the example above, the variable "octet" will contain the value 4.
01100  *
01101  * \hideinitializer
01102  */
01103 
01104 #define uip_ipaddr4(addr)   (htons(((u16_t *) (addr))[1]) & 0xff)
01105                 /**
01106  * Convert 16-bit quantity from host byte order to network byte order.
01107  *
01108  * This macro is primarily used for converting constants from host
01109  * byte order to network byte order. For converting variables to
01110  * network byte order, use the htons() function instead.
01111  *
01112  * \hideinitializer
01113  */
01114 
01115 #ifndef HTONS
01116 #if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
01117 #define HTONS(n)    (n)
01118 #else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
01119 
01120 #define HTONS(n)    (u16_t) ((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8))
01121 #endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
01122 
01123 #else
01124 #error "HTONS already defined!"
01125 #endif /* HTONS */
01126 
01127                 /**
01128  * Convert 16-bit quantity from host byte order to network byte order.
01129  *
01130  * This function is primarily used for converting variables from host
01131  * byte order to network byte order. For converting constants to
01132  * network byte order, use the HTONS() macro instead.
01133  */
01134 
01135 #ifndef htons
01136                 u16_t htons(u16_t val);
01137 #endif /* htons */
01138 
01139 #ifndef ntohs
01140 #define ntohs   htons
01141 #endif
01142 /** @} */
01143 
01144 /**
01145  * Pointer to the application data in the packet buffer.
01146  *
01147  * This pointer points to the application data when the application is
01148  * called. If the application wishes to send data, the application may
01149  * use this space to write the data into before calling uip_send().
01150  */
01151 extern void*    uip_appdata;
01152 
01153 #if UIP_URGDATA > 0
01154 /* u8_t *uip_urgdata:
01155  *
01156  * This pointer points to any urgent data that has been received. Only
01157  * present if compiled with support for urgent data (UIP_URGDATA).
01158  */
01159 extern void*    uip_urgdata;
01160 #endif /* UIP_URGDATA > 0 */
01161 
01162 /**
01163  * \defgroup uipdrivervars Variables used in UIP device drivers
01164  * @{
01165  *
01166  * UIP has a few global variables that are used in device drivers for
01167  * UIP.
01168  */
01169 
01170 /**
01171  * The length of the packet in the uip_buf buffer.
01172  *
01173  * The global variable uip_len holds the length of the packet in the
01174  * uip_buf buffer.
01175  *
01176  * When the network device driver calls the UIP input function,
01177  * uip_len should be set to the length of the packet in the uip_buf
01178  * buffer.
01179  *
01180  * When sending packets, the device driver should use the contents of
01181  * the uip_len variable to determine the length of the outgoing
01182  * packet.
01183  *
01184  */
01185 extern u16_t    uip_len;
01186 
01187 /** @} */
01188 #if UIP_URGDATA > 0
01189 extern u16_t    uip_urglen, uip_surglen;
01190 #endif /* UIP_URGDATA > 0 */
01191 
01192 /**
01193  * Representation of a UIP TCP connection.
01194  *
01195  * The uip_conn structure is used for identifying a connection. All
01196  * but one field in the structure are to be considered read-only by an
01197  * application. The only exception is the appstate field whos purpose
01198  * is to let the application store application-specific state (e.g.,
01199  * file pointers) for the connection. The type of this field is
01200  * configured in the "uipopt.h" header file.
01201  */
01202 
01203 struct uip_conn
01204 {
01205     uip_ipaddr_t        ripaddr;        /**< The IP address of the remote host. */
01206     u16_t               lport;          /**< The local TCP port, in network byte order. */
01207     u16_t               rport;          /**< The local remote TCP port, in network byte order. */
01208     u8_t                rcv_nxt[4];     /**< The sequence number that we expect to receive next. */
01209     u8_t                snd_nxt[4];     /**< The sequence number that was last sent by us. */
01210     u16_t               len;            /**< Length of the data that was previously sent. */
01211     u16_t               mss;            /**< Current maximum segment size for the connection. */
01212     u16_t               initialmss;     /**< Initial maximum segment size for the connection. */
01213     u8_t                sa;             /**< Retransmission time-out calculation state variable. */
01214     u8_t                sv;             /**< Retransmission time-out calculation state variable. */
01215     u8_t                rto;            /**< Retransmission time-out. */
01216     u8_t                tcpstateflags;  /**< TCP state and flags. */
01217     u8_t                timer;          /**< The retransmission timer. */
01218     u8_t                nrtx;           /**< The number of retransmissions for the last segment sent. */
01219 
01220     /** The application state. */
01221     uip_tcp_appstate_t  appstate;
01222 };
01223 
01224 /**
01225  * Pointer to the current TCP connection.
01226  *
01227  * The uip_conn pointer can be used to access the current TCP
01228  * connection.
01229  */
01230 extern struct uip_conn*     uip_conn;
01231 
01232 /* The array containing all UIP connections. */
01233 extern struct uip_conn      uip_conns[UIP_CONNS];
01234 
01235 /**
01236  * \addtogroup uiparch
01237  * @{
01238  */
01239 /**
01240  * 4-byte array used for the 32-bit sequence number calculations.
01241  */
01242 extern u8_t                 uip_acc32[4];
01243 
01244 /** @} */
01245 
01246 #if UIP_UDP
01247 
01248 /**
01249  * Representation of a UIP UDP connection.
01250  */
01251 struct uip_udp_conn
01252 {
01253     uip_ipaddr_t        ripaddr;    /**< The IP address of the remote peer. */
01254     u16_t               lport;      /**< The local port number in network byte order. */
01255     u16_t               rport;      /**< The remote port number in network byte order. */
01256     u8_t                ttl;        /**< Default time-to-live. */
01257 
01258     /** The application state. */
01259     uip_udp_appstate_t  appstate;
01260 };
01261 
01262 /**
01263  * The current UDP connection.
01264  */
01265 extern struct uip_udp_conn*     uip_udp_conn;
01266 extern struct uip_udp_conn      uip_udp_conns[UIP_UDP_CONNS];
01267 #endif /* UIP_UDP */
01268 
01269 /**
01270  * The structure holding the TCP/IP statistics that are gathered if
01271  * UIP_STATISTICS is set to 1.
01272  *
01273  */
01274 
01275 struct uip_stats
01276 {
01277     struct
01278     {
01279         uip_stats_t drop;       /**< Number of dropped packets at the IP layer. */
01280         uip_stats_t recv;       /**< Number of received packets at the IP layer. */
01281         uip_stats_t sent;       /**< Number of sent packets at the IP layer. */
01282         uip_stats_t vhlerr;     /**< Number of packets dropped due to wrong IP version or header length. */
01283         uip_stats_t hblenerr;   /**< Number of packets dropped due to wrong IP length, high byte. */
01284         uip_stats_t lblenerr;   /**< Number of packets dropped due to wrong IP length, low byte. */
01285         uip_stats_t fragerr;    /**< Number of packets dropped since they were IP fragments. */
01286         uip_stats_t chkerr;     /**< Number of packets dropped due to IP checksum errors. */
01287         uip_stats_t protoerr;   /**< Number of packets dropped since they were neither ICMP, UDP nor TCP. */
01288     } ip;   /**< IP statistics. */
01289     struct
01290     {
01291         uip_stats_t drop;       /**< Number of dropped ICMP packets. */
01292         uip_stats_t recv;       /**< Number of received ICMP packets. */
01293         uip_stats_t sent;       /**< Number of sent ICMP packets. */
01294         uip_stats_t typeerr;    /**< Number of ICMP packets with a wrong type. */
01295     } icmp; /**< ICMP statistics. */
01296     struct
01297     {
01298         uip_stats_t drop;       /**< Number of dropped TCP segments. */
01299         uip_stats_t recv;       /**< Number of recived TCP segments. */
01300         uip_stats_t sent;       /**< Number of sent TCP segments. */
01301         uip_stats_t chkerr;     /**< Number of TCP segments with a bad checksum. */
01302         uip_stats_t ackerr;     /**< Number of TCP segments with a bad ACK number. */
01303         uip_stats_t rst;        /**< Number of recevied TCP RST (reset) segments. */
01304         uip_stats_t rexmit;     /**< Number of retransmitted TCP segments. */
01305         uip_stats_t syndrop;    /**< Number of dropped SYNs due to too few connections was avaliable. */
01306         uip_stats_t synrst;     /**< Number of SYNs for closed ports, triggering a RST. */
01307     } tcp;  /**< TCP statistics. */
01308 #if UIP_UDP
01309     struct
01310     {
01311         uip_stats_t drop;   /**< Number of dropped UDP segments. */
01312         uip_stats_t recv;   /**< Number of recived UDP segments. */
01313         uip_stats_t sent;   /**< Number of sent UDP segments. */
01314         uip_stats_t chkerr; /**< Number of UDP segments with a bad checksum. */
01315     } udp;  /**< UDP statistics. */
01316 #endif /* UIP_UDP */
01317 };
01318 
01319 /**
01320  * The UIP TCP/IP statistics.
01321  *
01322  * This is the variable in which the UIP TCP/IP statistics are gathered.
01323  */
01324 extern struct uip_stats uip_stat;
01325 
01326 /*---------------------------------------------------------------------------*/
01327 /* All the stuff below this point is internal to UIP and should not be
01328  * used directly by an application or by a device driver.
01329  */
01330 /*---------------------------------------------------------------------------*/
01331 /* u8_t uip_flags:
01332  *
01333  * When the application is called, uip_flags will contain the flags
01334  * that are defined in this file. Please read below for more
01335  * infomation.
01336  */
01337 extern u8_t             uip_flags;
01338 
01339 /* The following flags may be set in the global variable uip_flags
01340    before calling the application callback. The UIP_ACKDATA,
01341    UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
01342    whereas the others are mutualy exclusive. Note that these flags
01343    should *NOT* be accessed directly, but only through the UIP
01344    functions/macros. */
01345 
01346 #define UIP_ACKDATA     1        /* Signifies that the outstanding data was
01347                                     acked and the application should send
01348                                     out new data instead of retransmitting
01349                                     the last data. */
01350 
01351 #define UIP_NEWDATA     2        /* Flags the fact that the peer has sent
01352                                     us new data. */
01353 
01354 #define UIP_REXMIT      4        /* Tells the application to retransmit the
01355                                     ata that was last sent. */
01356 
01357 #define UIP_POLL        8        /* Used for polling the application, to
01358                                     check if the application has data that
01359                                     it wants to send. */
01360 
01361 #define UIP_CLOSE       16       /* The remote host has closed the
01362                                     connection, thus the connection has
01363                                     gone away. Or the application signals
01364                                     that it wants to close the
01365                                     connection. */
01366 
01367 #define UIP_ABORT       32       /* The remote host has aborted the
01368                                     connection, thus the connection has
01369                                     gone away. Or the application signals
01370                                     that it wants to abort the
01371                                     connection. */
01372 
01373 #define UIP_CONNECTED   64       /* We have got a connection from a remote
01374                                     host and have set up a new connection
01375                                     for it, or an active connection has
01376                                     been successfully established. */
01377 
01378 #define UIP_TIMEDOUT    128      /* The connection has been aborted due to
01379                                     too many retransmissions. */
01380 
01381 /* uip_process(flag):
01382  *
01383  * The actual UIP function which does all the work.
01384  */
01385 void    uip_process(u8_t flag);
01386 
01387 /* The following flags are passed as an argument to the uip_process()
01388    function. They are used to distinguish between the two cases where
01389    uip_process() is called. It can be called either because we have
01390    incoming data that should be processed, or because the periodic
01391    timer has fired. These values are never used directly, but only in
01392    the macrose defined in this file. */
01393 
01394 #define UIP_DATA            1    /* Tells UIP that there is incoming
01395                                     data in the uip_buf buffer. The
01396                                     length of the data is stored in the
01397                                     global variable uip_len.
01398                                  */
01399 #define UIP_TIMER           2    /* Tells UIP that the periodic timer has fired. */
01400 #define UIP_POLL_REQUEST    3    /* Tells UIP that a connection should be polled. */
01401 #define UIP_UDP_SEND_CONN   4    /* Tells UIP that a UDP datagram should be constructed
01402                                     in the uip_buf buffer. */
01403 
01404 #if UIP_UDP
01405 #define UIP_UDP_TIMER   5
01406 #endif /* UIP_UDP */
01407 
01408 /* The TCP states used in the uip_conn->tcpstateflags. */
01409 
01410 #define UIP_CLOSED      0
01411 #define UIP_SYN_RCVD    1
01412 #define UIP_SYN_SENT    2
01413 #define UIP_ESTABLISHED 3
01414 #define UIP_FIN_WAIT_1  4
01415 #define UIP_FIN_WAIT_2  5
01416 #define UIP_CLOSING     6
01417 #define UIP_TIME_WAIT   7
01418 #define UIP_LAST_ACK    8
01419 #define UIP_TS_MASK     15
01420 
01421 #define UIP_STOPPED     16
01422 
01423 /* The TCP and IP headers. */
01424 struct uip_tcpip_hdr
01425 {
01426 #if UIP_CONF_IPV6
01427     /* IPv6 header. */
01428     u8_t            vtc, tcflow;
01429     u16_t           flow;
01430     u8_t            len[2];
01431     u8_t            proto, ttl;
01432     uip_ip6addr_t   srcipaddr, destipaddr;
01433 #else /* UIP_CONF_IPV6 */
01434     /* IPv4 header. */
01435 
01436     u8_t            vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
01437     u16_t           ipchksum;
01438     u16_t           srcipaddr[2], destipaddr[2];
01439 #endif /* UIP_CONF_IPV6 */
01440 
01441     /* TCP header. */
01442 
01443     u16_t           srcport, destport;
01444     u8_t            seqno[4], ackno[4], tcpoffset, flags, wnd[2];
01445     u16_t           tcpchksum;
01446     u8_t            urgp[2];
01447     u8_t            optdata[4];
01448 };
01449 
01450 /* The ICMP and IP headers. */
01451 struct uip_icmpip_hdr
01452 {
01453 #if UIP_CONF_IPV6
01454     /* IPv6 header. */
01455     u8_t            vtc, tcf;
01456     u16_t           flow;
01457     u8_t            len[2];
01458     u8_t            proto, ttl;
01459     uip_ip6addr_t   srcipaddr, destipaddr;
01460 #else /* UIP_CONF_IPV6 */
01461     /* IPv4 header. */
01462 
01463     u8_t            vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
01464     u16_t           ipchksum;
01465     u16_t           srcipaddr[2], destipaddr[2];
01466 #endif /* UIP_CONF_IPV6 */
01467 
01468     /* ICMP (echo) header. */
01469 
01470     u8_t            type, icode;
01471     u16_t           icmpchksum;
01472 #if !UIP_CONF_IPV6
01473     u16_t           id, seqno;
01474 #else /* !UIP_CONF_IPV6 */
01475     u8_t            flags, reserved1, reserved2, reserved3;
01476     u8_t            icmp6data[16];
01477     u8_t            options[1];
01478 #endif /* !UIP_CONF_IPV6 */
01479 };
01480 
01481 /* The UDP and IP headers. */
01482 struct uip_udpip_hdr
01483 {
01484 #if UIP_CONF_IPV6
01485     /* IPv6 header. */
01486     u8_t            vtc, tcf;
01487     u16_t           flow;
01488     u8_t            len[2];
01489     u8_t            proto, ttl;
01490     uip_ip6addr_t   srcipaddr, destipaddr;
01491 #else /* UIP_CONF_IPV6 */
01492     /* IP header. */
01493 
01494     u8_t            vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
01495     u16_t           ipchksum;
01496     u16_t           srcipaddr[2], destipaddr[2];
01497 #endif /* UIP_CONF_IPV6 */
01498 
01499     /* UDP header. */
01500 
01501     u16_t           srcport, destport;
01502     u16_t           udplen;
01503     u16_t           udpchksum;
01504 };
01505 
01506 /**
01507  * The buffer size available for user data in the \ref uip_buf buffer.
01508  *
01509  * This macro holds the available size for user data in the \ref
01510  * uip_buf buffer. The macro is intended to be used for checking
01511  * bounds of available user data.
01512  *
01513  * Example:
01514  \code
01515  snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
01516  \endcode
01517  *
01518  * \hideinitializer
01519  */
01520 #define UIP_APPDATA_SIZE    (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
01521 #define UIP_PROTO_ICMP      1
01522 #define UIP_PROTO_TCP       6
01523 #define UIP_PROTO_UDP       17
01524 #define UIP_PROTO_ICMP6     58
01525 
01526 /* Header sizes. */
01527 
01528 #if UIP_CONF_IPV6
01529 #define UIP_IPH_LEN 40
01530 #else /* UIP_CONF_IPV6 */
01531 
01532 #define UIP_IPH_LEN 20      /* Size of IP header */
01533 #endif /* UIP_CONF_IPV6 */
01534 
01535 #define UIP_UDPH_LEN    8   /* Size of UDP header */
01536 
01537 #define UIP_TCPH_LEN    20  /* Size of TCP header */
01538 
01539 #define UIP_IPUDPH_LEN  (UIP_UDPH_LEN + UIP_IPH_LEN)    /* Size of IP +
01540                               UDP
01541                               header */
01542 
01543 #define UIP_IPTCPH_LEN  (UIP_TCPH_LEN + UIP_IPH_LEN)    /* Size of IP +
01544                               TCP
01545                               header */
01546 
01547 #define UIP_TCPIP_HLEN  UIP_IPTCPH_LEN
01548 
01549 #if UIP_FIXEDADDR
01550 extern const uip_ipaddr_t   uip_hostaddr, uip_netmask, uip_draddr;
01551 #else /* UIP_FIXEDADDR */
01552 
01553 extern uip_ipaddr_t         uip_hostaddr, uip_netmask, uip_draddr;
01554 #endif /* UIP_FIXEDADDR */
01555 
01556 /**
01557  * Representation of a 48-bit Ethernet address.
01558  */
01559 
01560 struct uip_eth_addr
01561 {
01562     u8_t    addr[6];
01563 };
01564 
01565 /**
01566  * Calculate the Internet checksum over a buffer.
01567  *
01568  * The Internet checksum is the one's complement of the one's
01569  * complement sum of all 16-bit words in the buffer.
01570  *
01571  * See RFC1071.
01572  *
01573  * \param buf A pointer to the buffer over which the checksum is to be
01574  * computed.
01575  *
01576  * \param len The length of the buffer over which the checksum is to
01577  * be computed.
01578  *
01579  * \return The Internet checksum of the buffer.
01580  */
01581 u16_t   uip_chksum(u16_t* buf, u16_t len);
01582 
01583 /**
01584  * Calculate the IP header checksum of the packet header in uip_buf.
01585  *
01586  * The IP header checksum is the Internet checksum of the 20 bytes of
01587  * the IP header.
01588  *
01589  * \return The IP header checksum of the IP header in the uip_buf
01590  * buffer.
01591  */
01592 u16_t   uip_ipchksum(void);
01593 
01594 /**
01595  * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
01596  *
01597  * The TCP checksum is the Internet checksum of data contents of the
01598  * TCP segment, and a pseudo-header as defined in RFC793.
01599  *
01600  * \return The TCP checksum of the TCP segment in uip_buf and pointed
01601  * to by uip_appdata.
01602  */
01603 u16_t   uip_tcpchksum(void);
01604 
01605 /**
01606  * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
01607  *
01608  * The UDP checksum is the Internet checksum of data contents of the
01609  * UDP segment, and a pseudo-header as defined in RFC768.
01610  *
01611  * \return The UDP checksum of the UDP segment in uip_buf and pointed
01612  * to by uip_appdata.
01613  */
01614 u16_t   uip_udpchksum(void);
01615 #endif /* __UIP_H__ */
01616 
01617 /** @} */