SAMV71 Xplained Ultra Software Package 1.4

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