These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

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 
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 #ifndef UIP_CONF_EXTERNAL_BUFFER
00423     extern u8_t uip_buf[UIP_BUFSIZE+2];
00424 #else
00425     extern unsigned char *uip_buf;
00426 #endif
00427 
00428 /** @} */
00429 
00430 /*---------------------------------------------------------------------------*/
00431 /* Functions that are used by the uIP application program. Opening and
00432  * closing connections, sending and receiving data, etc. is all
00433  * handled by the functions below.
00434 */
00435 /**
00436  * \defgroup uipappfunc uIP application functions
00437  * @{
00438  *
00439  * Functions used by an application running of top of uIP.
00440  */
00441 
00442 /**
00443  * Start listening to the specified port.
00444  *
00445  * \note Since this function expects the port number in network byte
00446  * order, a conversion using HTONS() or htons() is necessary.
00447  *
00448  \code
00449  uip_listen(HTONS(80));
00450  \endcode
00451  *
00452  * \param port A 16-bit port number in network byte order.
00453  */
00454 void uip_listen(u16_t port);
00455 
00456 /**
00457  * Stop listening to the specified port.
00458  *
00459  * \note Since this function expects the port number in network byte
00460  * order, a conversion using HTONS() or htons() is necessary.
00461  *
00462  \code
00463  uip_unlisten(HTONS(80));
00464  \endcode
00465  *
00466  * \param port A 16-bit port number in network byte order.
00467  */
00468 void uip_unlisten(u16_t port);
00469 
00470 /**
00471  * Connect to a remote host using TCP.
00472  *
00473  * This function is used to start a new connection to the specified
00474  * port on the specied host. It allocates a new connection identifier,
00475  * sets the connection to the SYN_SENT state and sets the
00476  * retransmission timer to 0. This will cause a TCP SYN segment to be
00477  * sent out the next time this connection is periodically processed,
00478  * which usually is done within 0.5 seconds after the call to
00479  * uip_connect().
00480  *
00481  * \note This function is avaliable only if support for active open
00482  * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
00483  *
00484  * \note Since this function requires the port number to be in network
00485  * byte order, a conversion using HTONS() or htons() is necessary.
00486  *
00487  \code
00488  uip_ipaddr_t ipaddr;
00489 
00490  uip_ipaddr(&ipaddr, 192,168,1,2);
00491  uip_connect(&ipaddr, HTONS(80));
00492  \endcode
00493  *
00494  * \param ripaddr The IP address of the remote hot.
00495  *
00496  * \param port A 16-bit port number in network byte order.
00497  *
00498  * \return A pointer to the uIP connection identifier for the new connection,
00499  * or NULL if no connection could be allocated.
00500  *
00501  */
00502 struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, u16_t port);
00503 
00504 
00505 
00506 /**
00507  * \internal
00508  *
00509  * Check if a connection has outstanding (i.e., unacknowledged) data.
00510  *
00511  * \param conn A pointer to the uip_conn structure for the connection.
00512  *
00513  * \hideinitializer
00514  */
00515 #define uip_outstanding(conn) ((conn)->len)
00516 
00517 /**
00518  * Send data on the current connection.
00519  *
00520  * This function is used to send out a single segment of TCP
00521  * data. Only applications that have been invoked by uIP for event
00522  * processing can send data.
00523  *
00524  * The amount of data that actually is sent out after a call to this
00525  * funcion is determined by the maximum amount of data TCP allows. uIP
00526  * will automatically crop the data so that only the appropriate
00527  * amount of data is sent. The function uip_mss() can be used to query
00528  * uIP for the amount of data that actually will be sent.
00529  *
00530  * \note This function does not guarantee that the sent data will
00531  * arrive at the destination. If the data is lost in the network, the
00532  * application will be invoked with the uip_rexmit() event being
00533  * set. The application will then have to resend the data using this
00534  * function.
00535  *
00536  * \param data A pointer to the data which is to be sent.
00537  *
00538  * \param len The maximum amount of data bytes to be sent.
00539  *
00540  * \hideinitializer
00541  */
00542 void uip_send(const void *data, int len);
00543 
00544 /**
00545  * The length of any incoming data that is currently avaliable (if avaliable)
00546  * in the uip_appdata buffer.
00547  *
00548  * The test function uip_data() must first be used to check if there
00549  * is any data available at all.
00550  *
00551  * \hideinitializer
00552  */
00553 /*void uip_datalen(void);*/
00554 #define uip_datalen()       uip_len
00555 
00556 /**
00557  * The length of any out-of-band data (urgent data) that has arrived
00558  * on the connection.
00559  *
00560  * \note The configuration parameter UIP_URGDATA must be set for this
00561  * function to be enabled.
00562  *
00563  * \hideinitializer
00564  */
00565 #define uip_urgdatalen()    uip_urglen
00566 
00567 /**
00568  * Close the current connection.
00569  *
00570  * This function will close the current connection in a nice way.
00571  *
00572  * \hideinitializer
00573  */
00574 #define uip_close()         (uip_flags = UIP_CLOSE)
00575 
00576 /**
00577  * Abort the current connection.
00578  *
00579  * This function will abort (reset) the current connection, and is
00580  * usually used when an error has occured that prevents using the
00581  * uip_close() function.
00582  *
00583  * \hideinitializer
00584  */
00585 #define uip_abort()         (uip_flags = UIP_ABORT)
00586 
00587 /**
00588  * Tell the sending host to stop sending data.
00589  *
00590  * This function will close our receiver's window so that we stop
00591  * receiving data for the current connection.
00592  *
00593  * \hideinitializer
00594  */
00595 #define uip_stop()          (uip_conn->tcpstateflags |= UIP_STOPPED)
00596 
00597 /**
00598  * Find out if the current connection has been previously stopped with
00599  * uip_stop().
00600  *
00601  * \hideinitializer
00602  */
00603 #define uip_stopped(conn)   ((conn)->tcpstateflags & UIP_STOPPED)
00604 
00605 /**
00606  * Restart the current connection, if is has previously been stopped
00607  * with uip_stop().
00608  *
00609  * This function will open the receiver's window again so that we
00610  * start receiving data for the current connection.
00611  *
00612  * \hideinitializer
00613  */
00614 #define uip_restart()         do { uip_flags |= UIP_NEWDATA; \
00615                                    uip_conn->tcpstateflags &= ~UIP_STOPPED; \
00616                               } while(0)
00617 
00618 
00619 /* uIP tests that can be made to determine in what state the current
00620    connection is, and what the application function should do. */
00621 
00622 /**
00623  * Is the current connection a UDP connection?
00624  *
00625  * This function checks whether the current connection is a UDP connection.
00626  *
00627  * \hideinitializer
00628  *
00629  */
00630 #define uip_udpconnection() (uip_conn == NULL)
00631 
00632 /**
00633  * Is new incoming data available?
00634  *
00635  * Will reduce to non-zero if there is new data for the application
00636  * present at the uip_appdata pointer. The size of the data is
00637  * avaliable through the uip_len variable.
00638  *
00639  * \hideinitializer
00640  */
00641 #define uip_newdata()   (uip_flags & UIP_NEWDATA)
00642 
00643 /**
00644  * Has previously sent data been acknowledged?
00645  *
00646  * Will reduce to non-zero if the previously sent data has been
00647  * acknowledged by the remote host. This means that the application
00648  * can send new data.
00649  *
00650  * \hideinitializer
00651  */
00652 #define uip_acked()   (uip_flags & UIP_ACKDATA)
00653 
00654 /**
00655  * Has the connection just been connected?
00656  *
00657  * Reduces to non-zero if the current connection has been connected to
00658  * a remote host. This will happen both if the connection has been
00659  * actively opened (with uip_connect()) or passively opened (with
00660  * uip_listen()).
00661  *
00662  * \hideinitializer
00663  */
00664 #define uip_connected() (uip_flags & UIP_CONNECTED)
00665 
00666 /**
00667  * Has the connection been closed by the other end?
00668  *
00669  * Is non-zero if the connection has been closed by the remote
00670  * host. The application may then do the necessary clean-ups.
00671  *
00672  * \hideinitializer
00673  */
00674 #define uip_closed()    (uip_flags & UIP_CLOSE)
00675 
00676 /**
00677  * Has the connection been aborted by the other end?
00678  *
00679  * Non-zero if the current connection has been aborted (reset) by the
00680  * remote host.
00681  *
00682  * \hideinitializer
00683  */
00684 #define uip_aborted()    (uip_flags & UIP_ABORT)
00685 
00686 /**
00687  * Has the connection timed out?
00688  *
00689  * Non-zero if the current connection has been aborted due to too many
00690  * retransmissions.
00691  *
00692  * \hideinitializer
00693  */
00694 #define uip_timedout()    (uip_flags & UIP_TIMEDOUT)
00695 
00696 /**
00697  * Do we need to retransmit previously data?
00698  *
00699  * Reduces to non-zero if the previously sent data has been lost in
00700  * the network, and the application should retransmit it. The
00701  * application should send the exact same data as it did the last
00702  * time, using the uip_send() function.
00703  *
00704  * \hideinitializer
00705  */
00706 #define uip_rexmit()     (uip_flags & UIP_REXMIT)
00707 
00708 /**
00709  * Is the connection being polled by uIP?
00710  *
00711  * Is non-zero if the reason the application is invoked is that the
00712  * current connection has been idle for a while and should be
00713  * polled.
00714  *
00715  * The polling event can be used for sending data without having to
00716  * wait for the remote host to send data.
00717  *
00718  * \hideinitializer
00719  */
00720 #define uip_poll()       (uip_flags & UIP_POLL)
00721 
00722 /**
00723  * Get the initial maxium segment size (MSS) of the current
00724  * connection.
00725  *
00726  * \hideinitializer
00727  */
00728 #define uip_initialmss()             (uip_conn->initialmss)
00729 
00730 /**
00731  * Get the current maxium segment size that can be sent on the current
00732  * connection.
00733  *
00734  * The current maxiumum segment size that can be sent on the
00735  * connection is computed from the receiver's window and the MSS of
00736  * the connection (which also is available by calling
00737  * uip_initialmss()).
00738  *
00739  * \hideinitializer
00740  */
00741 #define uip_mss()             (uip_conn->mss)
00742 
00743 /**
00744  * Set up a new UDP connection.
00745  *
00746  * This function sets up a new UDP connection. The function will
00747  * automatically allocate an unused local port for the new
00748  * connection. However, another port can be chosen by using the
00749  * uip_udp_bind() call, after the uip_udp_new() function has been
00750  * called.
00751  *
00752  * Example:
00753  \code
00754  uip_ipaddr_t addr;
00755  struct uip_udp_conn *c;
00756 
00757  uip_ipaddr(&addr, 192,168,2,1);
00758  c = uip_udp_new(&addr, HTONS(12345));
00759  if(c != NULL) {
00760    uip_udp_bind(c, HTONS(12344));
00761  }
00762  \endcode
00763  * \param ripaddr The IP address of the remote host.
00764  *
00765  * \param rport The remote port number in network byte order.
00766  *
00767  * \return The uip_udp_conn structure for the new connection or NULL
00768  * if no connection could be allocated.
00769  */
00770 struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport);
00771 
00772 /**
00773  * Removed a UDP connection.
00774  *
00775  * \param conn A pointer to the uip_udp_conn structure for the connection.
00776  *
00777  * \hideinitializer
00778  */
00779 #define uip_udp_remove(conn) (conn)->lport = 0
00780 
00781 /**
00782  * Bind a UDP connection to a local port.
00783  *
00784  * \param conn A pointer to the uip_udp_conn structure for the
00785  * connection.
00786  *
00787  * \param port The local port number, in network byte order.
00788  *
00789  * \hideinitializer
00790  */
00791 #define uip_udp_bind(conn, port) (conn)->lport = port
00792 
00793 /**
00794  * Send a UDP datagram of length len on the current connection.
00795  *
00796  * This function can only be called in response to a UDP event (poll
00797  * or newdata). The data must be present in the uip_buf buffer, at the
00798  * place pointed to by the uip_appdata pointer.
00799  *
00800  * \param len The length of the data in the uip_buf buffer.
00801  *
00802  * \hideinitializer
00803  */
00804 #define uip_udp_send(len) uip_send((char *)uip_appdata, len)
00805 
00806 /** @} */
00807 
00808 /* uIP convenience and converting functions. */
00809 
00810 /**
00811  * \defgroup uipconvfunc uIP conversion functions
00812  * @{
00813  *
00814  * These functions can be used for converting between different data
00815  * formats used by uIP.
00816  */
00817 
00818 /**
00819  * Construct an IP address from four bytes.
00820  *
00821  * This function constructs an IP address of the type that uIP handles
00822  * internally from four bytes. The function is handy for specifying IP
00823  * addresses to use with e.g. the uip_connect() function.
00824  *
00825  * Example:
00826  \code
00827  uip_ipaddr_t ipaddr;
00828  struct uip_conn *c;
00829 
00830  uip_ipaddr(&ipaddr, 192,168,1,2);
00831  c = uip_connect(&ipaddr, HTONS(80));
00832  \endcode
00833  *
00834  * \param addr A pointer to a uip_ipaddr_t variable that will be
00835  * filled in with the IP address.
00836  *
00837  * \param addr0 The first octet of the IP address.
00838  * \param addr1 The second octet of the IP address.
00839  * \param addr2 The third octet of the IP address.
00840  * \param addr3 The forth octet of the IP address.
00841  *
00842  * \hideinitializer
00843  */
00844 #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
00845                      ((u16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \
00846                      ((u16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \
00847                   } while(0)
00848 
00849 /**
00850  * Construct an IPv6 address from eight 16-bit words.
00851  *
00852  * This function constructs an IPv6 address.
00853  *
00854  * \hideinitializer
00855  */
00856 #define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
00857                      ((u16_t *)(addr))[0] = HTONS((addr0)); \
00858                      ((u16_t *)(addr))[1] = HTONS((addr1)); \
00859                      ((u16_t *)(addr))[2] = HTONS((addr2)); \
00860                      ((u16_t *)(addr))[3] = HTONS((addr3)); \
00861                      ((u16_t *)(addr))[4] = HTONS((addr4)); \
00862                      ((u16_t *)(addr))[5] = HTONS((addr5)); \
00863                      ((u16_t *)(addr))[6] = HTONS((addr6)); \
00864                      ((u16_t *)(addr))[7] = HTONS((addr7)); \
00865                   } while(0)
00866 
00867 /**
00868  * Copy an IP address to another IP address.
00869  *
00870  * Copies an IP address from one place to another.
00871  *
00872  * Example:
00873  \code
00874  uip_ipaddr_t ipaddr1, ipaddr2;
00875 
00876  uip_ipaddr(&ipaddr1, 192,16,1,2);
00877  uip_ipaddr_copy(&ipaddr2, &ipaddr1);
00878  \endcode
00879  *
00880  * \param dest The destination for the copy.
00881  * \param src The source from where to copy.
00882  *
00883  * \hideinitializer
00884  */
00885 #if !UIP_CONF_IPV6
00886 #define uip_ipaddr_copy(dest, src) do { \
00887                      ((u16_t *)dest)[0] = ((u16_t *)src)[0]; \
00888                      ((u16_t *)dest)[1] = ((u16_t *)src)[1]; \
00889                   } while(0)
00890 #else /* !UIP_CONF_IPV6 */
00891 #define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t))
00892 #endif /* !UIP_CONF_IPV6 */
00893 
00894 /**
00895  * Compare two IP addresses
00896  *
00897  * Compares two IP addresses.
00898  *
00899  * Example:
00900  \code
00901  uip_ipaddr_t ipaddr1, ipaddr2;
00902 
00903  uip_ipaddr(&ipaddr1, 192,16,1,2);
00904  if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
00905     printf("They are the same");
00906  }
00907  \endcode
00908  *
00909  * \param addr1 The first IP address.
00910  * \param addr2 The second IP address.
00911  *
00912  * \hideinitializer
00913  */
00914 #if !UIP_CONF_IPV6
00915 #define uip_ipaddr_cmp(addr1, addr2) (((u16_t *)addr1)[0] == ((u16_t *)addr2)[0] && \
00916                       ((u16_t *)addr1)[1] == ((u16_t *)addr2)[1])
00917 #else /* !UIP_CONF_IPV6 */
00918 #define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
00919 #endif /* !UIP_CONF_IPV6 */
00920 
00921 /**
00922  * Compare two IP addresses with netmasks
00923  *
00924  * Compares two IP addresses with netmasks. The masks are used to mask
00925  * out the bits that are to be compared.
00926  *
00927  * Example:
00928  \code
00929  uip_ipaddr_t ipaddr1, ipaddr2, mask;
00930 
00931  uip_ipaddr(&mask, 255,255,255,0);
00932  uip_ipaddr(&ipaddr1, 192,16,1,2);
00933  uip_ipaddr(&ipaddr2, 192,16,1,3);
00934  if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
00935     printf("They are the same");
00936  }
00937  \endcode
00938  *
00939  * \param addr1 The first IP address.
00940  * \param addr2 The second IP address.
00941  * \param mask The netmask.
00942  *
00943  * \hideinitializer
00944  */
00945 #define uip_ipaddr_maskcmp(addr1, addr2, mask) \
00946                           (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \
00947                             (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \
00948                            ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \
00949                             (((u16_t *)addr2)[1] & ((u16_t *)mask)[1])))
00950 
00951 
00952 /**
00953  * Mask out the network part of an IP address.
00954  *
00955  * Masks out the network part of an IP address, given the address and
00956  * the netmask.
00957  *
00958  * Example:
00959  \code
00960  uip_ipaddr_t ipaddr1, ipaddr2, netmask;
00961 
00962  uip_ipaddr(&ipaddr1, 192,16,1,2);
00963  uip_ipaddr(&netmask, 255,255,255,0);
00964  uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
00965  \endcode
00966  *
00967  * In the example above, the variable "ipaddr2" will contain the IP
00968  * address 192.168.1.0.
00969  *
00970  * \param dest Where the result is to be placed.
00971  * \param src The IP address.
00972  * \param mask The netmask.
00973  *
00974  * \hideinitializer
00975  */
00976 #define uip_ipaddr_mask(dest, src, mask) do { \
00977                      ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \
00978                      ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \
00979                   } while(0)
00980 
00981 /**
00982  * Pick the first octet of an IP address.
00983  *
00984  * Picks out the first octet of an IP address.
00985  *
00986  * Example:
00987  \code
00988  uip_ipaddr_t ipaddr;
00989  u8_t octet;
00990 
00991  uip_ipaddr(&ipaddr, 1,2,3,4);
00992  octet = uip_ipaddr1(&ipaddr);
00993  \endcode
00994  *
00995  * In the example above, the variable "octet" will contain the value 1.
00996  *
00997  * \hideinitializer
00998  */
00999 #define uip_ipaddr1(addr) (htons(((u16_t *)(addr))[0]) >> 8)
01000 
01001 /**
01002  * Pick the second octet of an IP address.
01003  *
01004  * Picks out the second octet of an IP address.
01005  *
01006  * Example:
01007  \code
01008  uip_ipaddr_t ipaddr;
01009  u8_t octet;
01010 
01011  uip_ipaddr(&ipaddr, 1,2,3,4);
01012  octet = uip_ipaddr2(&ipaddr);
01013  \endcode
01014  *
01015  * In the example above, the variable "octet" will contain the value 2.
01016  *
01017  * \hideinitializer
01018  */
01019 #define uip_ipaddr2(addr) (htons(((u16_t *)(addr))[0]) & 0xff)
01020 
01021 /**
01022  * Pick the third octet of an IP address.
01023  *
01024  * Picks out the third octet of an IP address.
01025  *
01026  * Example:
01027  \code
01028  uip_ipaddr_t ipaddr;
01029  u8_t octet;
01030 
01031  uip_ipaddr(&ipaddr, 1,2,3,4);
01032  octet = uip_ipaddr3(&ipaddr);
01033  \endcode
01034  *
01035  * In the example above, the variable "octet" will contain the value 3.
01036  *
01037  * \hideinitializer
01038  */
01039 #define uip_ipaddr3(addr) (htons(((u16_t *)(addr))[1]) >> 8)
01040 
01041 /**
01042  * Pick the fourth octet of an IP address.
01043  *
01044  * Picks out the fourth octet of an IP address.
01045  *
01046  * Example:
01047  \code
01048  uip_ipaddr_t ipaddr;
01049  u8_t octet;
01050 
01051  uip_ipaddr(&ipaddr, 1,2,3,4);
01052  octet = uip_ipaddr4(&ipaddr);
01053  \endcode
01054  *
01055  * In the example above, the variable "octet" will contain the value 4.
01056  *
01057  * \hideinitializer
01058  */
01059 #define uip_ipaddr4(addr) (htons(((u16_t *)(addr))[1]) & 0xff)
01060 
01061 /**
01062  * Convert 16-bit quantity from host byte order to network byte order.
01063  *
01064  * This macro is primarily used for converting constants from host
01065  * byte order to network byte order. For converting variables to
01066  * network byte order, use the htons() function instead.
01067  *
01068  * \hideinitializer
01069  */
01070 #ifndef HTONS
01071 #   if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
01072 #      define HTONS(n) (n)
01073 #   else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
01074 #      define HTONS(n) (u16_t)((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8))
01075 #   endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
01076 #else
01077 #error "HTONS already defined!"
01078 #endif /* HTONS */
01079 
01080 /**
01081  * Convert 16-bit quantity from host byte order to network byte order.
01082  *
01083  * This function is primarily used for converting variables from host
01084  * byte order to network byte order. For converting constants to
01085  * network byte order, use the HTONS() macro instead.
01086  */
01087 #ifndef htons
01088 u16_t htons(u16_t val);
01089 #endif /* htons */
01090 #ifndef ntohs
01091 #define ntohs htons
01092 #endif
01093 
01094 /** @} */
01095 
01096 /**
01097  * Pointer to the application data in the packet buffer.
01098  *
01099  * This pointer points to the application data when the application is
01100  * called. If the application wishes to send data, the application may
01101  * use this space to write the data into before calling uip_send().
01102  */
01103 extern void *uip_appdata;
01104 
01105 #if UIP_URGDATA > 0
01106 /* u8_t *uip_urgdata:
01107  *
01108  * This pointer points to any urgent data that has been received. Only
01109  * present if compiled with support for urgent data (UIP_URGDATA).
01110  */
01111 extern void *uip_urgdata;
01112 #endif /* UIP_URGDATA > 0 */
01113 
01114 
01115 /**
01116  * \defgroup uipdrivervars Variables used in uIP device drivers
01117  * @{
01118  *
01119  * uIP has a few global variables that are used in device drivers for
01120  * uIP.
01121  */
01122 
01123 /**
01124  * The length of the packet in the uip_buf buffer.
01125  *
01126  * The global variable uip_len holds the length of the packet in the
01127  * uip_buf buffer.
01128  *
01129  * When the network device driver calls the uIP input function,
01130  * uip_len should be set to the length of the packet in the uip_buf
01131  * buffer.
01132  *
01133  * When sending packets, the device driver should use the contents of
01134  * the uip_len variable to determine the length of the outgoing
01135  * packet.
01136  *
01137  */
01138 extern u16_t uip_len;
01139 
01140 /** @} */
01141 
01142 #if UIP_URGDATA > 0
01143 extern u16_t uip_urglen, uip_surglen;
01144 #endif /* UIP_URGDATA > 0 */
01145 
01146 
01147 /**
01148  * Representation of a uIP TCP connection.
01149  *
01150  * The uip_conn structure is used for identifying a connection. All
01151  * but one field in the structure are to be considered read-only by an
01152  * application. The only exception is the appstate field whos purpose
01153  * is to let the application store application-specific state (e.g.,
01154  * file pointers) for the connection. The type of this field is
01155  * configured in the "uipopt.h" header file.
01156  */
01157 struct uip_conn {
01158   uip_ipaddr_t ripaddr;   /**< The IP address of the remote host. */
01159 
01160   u16_t lport;        /**< The local TCP port, in network byte order. */
01161   u16_t rport;        /**< The local remote TCP port, in network byte
01162              order. */
01163 
01164   u8_t rcv_nxt[4];    /**< The sequence number that we expect to
01165              receive next. */
01166   u8_t snd_nxt[4];    /**< The sequence number that was last sent by
01167                          us. */
01168   u16_t len;          /**< Length of the data that was previously sent. */
01169   u16_t mss;          /**< Current maximum segment size for the
01170              connection. */
01171   u16_t initialmss;   /**< Initial maximum segment size for the
01172              connection. */
01173   u8_t sa;            /**< Retransmission time-out calculation state
01174              variable. */
01175   u8_t sv;            /**< Retransmission time-out calculation state
01176              variable. */
01177   u8_t rto;           /**< Retransmission time-out. */
01178   u8_t tcpstateflags; /**< TCP state and flags. */
01179   u8_t timer;         /**< The retransmission timer. */
01180   u8_t nrtx;          /**< The number of retransmissions for the last
01181              segment sent. */
01182 
01183   /** The application state. */
01184   uip_tcp_appstate_t appstate;
01185 };
01186 
01187 
01188 /**
01189  * Pointer to the current TCP connection.
01190  *
01191  * The uip_conn pointer can be used to access the current TCP
01192  * connection.
01193  */
01194 extern struct uip_conn *uip_conn;
01195 /* The array containing all uIP connections. */
01196 extern struct uip_conn uip_conns[UIP_CONNS];
01197 /**
01198  * \addtogroup uiparch
01199  * @{
01200  */
01201 
01202 /**
01203  * 4-byte array used for the 32-bit sequence number calculations.
01204  */
01205 extern u8_t uip_acc32[4];
01206 
01207 /** @} */
01208 
01209 
01210 #if UIP_UDP
01211 /**
01212  * Representation of a uIP UDP connection.
01213  */
01214 struct uip_udp_conn {
01215   uip_ipaddr_t ripaddr;   /**< The IP address of the remote peer. */
01216   u16_t lport;        /**< The local port number in network byte order. */
01217   u16_t rport;        /**< The remote port number in network byte order. */
01218   u8_t  ttl;          /**< Default time-to-live. */
01219 
01220   /** The application state. */
01221   uip_udp_appstate_t appstate;
01222 };
01223 
01224 /**
01225  * The current UDP connection.
01226  */
01227 extern struct uip_udp_conn *uip_udp_conn;
01228 extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
01229 #endif /* UIP_UDP */
01230 
01231 /**
01232  * The structure holding the TCP/IP statistics that are gathered if
01233  * UIP_STATISTICS is set to 1.
01234  *
01235  */
01236 struct uip_stats {
01237   struct {
01238     uip_stats_t drop;     /**< Number of dropped packets at the IP
01239                  layer. */
01240     uip_stats_t recv;     /**< Number of received packets at the IP
01241                  layer. */
01242     uip_stats_t sent;     /**< Number of sent packets at the IP
01243                  layer. */
01244     uip_stats_t vhlerr;   /**< Number of packets dropped due to wrong
01245                  IP version or header length. */
01246     uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
01247                  IP length, high byte. */
01248     uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
01249                  IP length, low byte. */
01250     uip_stats_t fragerr;  /**< Number of packets dropped since they
01251                  were IP fragments. */
01252     uip_stats_t chkerr;   /**< Number of packets dropped due to IP
01253                  checksum errors. */
01254     uip_stats_t protoerr; /**< Number of packets dropped since they
01255                  were neither ICMP, UDP nor TCP. */
01256   } ip;                   /**< IP statistics. */
01257   struct {
01258     uip_stats_t drop;     /**< Number of dropped ICMP packets. */
01259     uip_stats_t recv;     /**< Number of received ICMP packets. */
01260     uip_stats_t sent;     /**< Number of sent ICMP packets. */
01261     uip_stats_t typeerr;  /**< Number of ICMP packets with a wrong
01262                  type. */
01263   } icmp;                 /**< ICMP statistics. */
01264   struct {
01265     uip_stats_t drop;     /**< Number of dropped TCP segments. */
01266     uip_stats_t recv;     /**< Number of recived TCP segments. */
01267     uip_stats_t sent;     /**< Number of sent TCP segments. */
01268     uip_stats_t chkerr;   /**< Number of TCP segments with a bad
01269                  checksum. */
01270     uip_stats_t ackerr;   /**< Number of TCP segments with a bad ACK
01271                  number. */
01272     uip_stats_t rst;      /**< Number of recevied TCP RST (reset) segments. */
01273     uip_stats_t rexmit;   /**< Number of retransmitted TCP segments. */
01274     uip_stats_t syndrop;  /**< Number of dropped SYNs due to too few
01275                  connections was avaliable. */
01276     uip_stats_t synrst;   /**< Number of SYNs for closed ports,
01277                  triggering a RST. */
01278   } tcp;                  /**< TCP statistics. */
01279 #if UIP_UDP
01280   struct {
01281     uip_stats_t drop;     /**< Number of dropped UDP segments. */
01282     uip_stats_t recv;     /**< Number of recived UDP segments. */
01283     uip_stats_t sent;     /**< Number of sent UDP segments. */
01284     uip_stats_t chkerr;   /**< Number of UDP segments with a bad
01285                  checksum. */
01286   } udp;                  /**< UDP statistics. */
01287 #endif /* UIP_UDP */
01288 };
01289 
01290 /**
01291  * The uIP TCP/IP statistics.
01292  *
01293  * This is the variable in which the uIP TCP/IP statistics are gathered.
01294  */
01295 extern struct uip_stats uip_stat;
01296 
01297 
01298 /*---------------------------------------------------------------------------*/
01299 /* All the stuff below this point is internal to uIP and should not be
01300  * used directly by an application or by a device driver.
01301  */
01302 /*---------------------------------------------------------------------------*/
01303 /* u8_t uip_flags:
01304  *
01305  * When the application is called, uip_flags will contain the flags
01306  * that are defined in this file. Please read below for more
01307  * infomation.
01308  */
01309 extern u8_t uip_flags;
01310 
01311 /* The following flags may be set in the global variable uip_flags
01312    before calling the application callback. The UIP_ACKDATA,
01313    UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
01314    whereas the others are mutualy exclusive. Note that these flags
01315    should *NOT* be accessed directly, but only through the uIP
01316    functions/macros. */
01317 
01318 #define UIP_ACKDATA   1     /* Signifies that the outstanding data was
01319                    acked and the application should send
01320                    out new data instead of retransmitting
01321                    the last data. */
01322 #define UIP_NEWDATA   2     /* Flags the fact that the peer has sent
01323                    us new data. */
01324 #define UIP_REXMIT    4     /* Tells the application to retransmit the
01325                    data that was last sent. */
01326 #define UIP_POLL      8     /* Used for polling the application, to
01327                    check if the application has data that
01328                    it wants to send. */
01329 #define UIP_CLOSE     16    /* The remote host has closed the
01330                    connection, thus the connection has
01331                    gone away. Or the application signals
01332                    that it wants to close the
01333                    connection. */
01334 #define UIP_ABORT     32    /* The remote host has aborted the
01335                    connection, thus the connection has
01336                    gone away. Or the application signals
01337                    that it wants to abort the
01338                    connection. */
01339 #define UIP_CONNECTED 64    /* We have got a connection from a remote
01340                                host and have set up a new connection
01341                                for it, or an active connection has
01342                                been successfully established. */
01343 
01344 #define UIP_TIMEDOUT  128   /* The connection has been aborted due to
01345                    too many retransmissions. */
01346 
01347 /* uip_process(flag):
01348  *
01349  * The actual uIP function which does all the work.
01350  */
01351 void uip_process(u8_t flag);
01352 
01353 /* The following flags are passed as an argument to the uip_process()
01354    function. They are used to distinguish between the two cases where
01355    uip_process() is called. It can be called either because we have
01356    incoming data that should be processed, or because the periodic
01357    timer has fired. These values are never used directly, but only in
01358    the macrose defined in this file. */
01359 
01360 #define UIP_DATA          1     /* Tells uIP that there is incoming
01361                    data in the uip_buf buffer. The
01362                    length of the data is stored in the
01363                    global variable uip_len. */
01364 #define UIP_TIMER         2     /* Tells uIP that the periodic timer
01365                    has fired. */
01366 #define UIP_POLL_REQUEST  3     /* Tells uIP that a connection should
01367                    be polled. */
01368 #define UIP_UDP_SEND_CONN 4     /* Tells uIP that a UDP datagram
01369                    should be constructed in the
01370                    uip_buf buffer. */
01371 #if UIP_UDP
01372 #define UIP_UDP_TIMER     5
01373 #endif /* UIP_UDP */
01374 
01375 /* The TCP states used in the uip_conn->tcpstateflags. */
01376 #define UIP_CLOSED      0
01377 #define UIP_SYN_RCVD    1
01378 #define UIP_SYN_SENT    2
01379 #define UIP_ESTABLISHED 3
01380 #define UIP_FIN_WAIT_1  4
01381 #define UIP_FIN_WAIT_2  5
01382 #define UIP_CLOSING     6
01383 #define UIP_TIME_WAIT   7
01384 #define UIP_LAST_ACK    8
01385 #define UIP_TS_MASK     15
01386 
01387 #define UIP_STOPPED      16
01388 
01389 /* The TCP and IP headers. */
01390 
01391 #ifdef __ICCARM__
01392     #pragma pack(1)
01393 #endif
01394 
01395 
01396 #if defined ( __CC_ARM   )
01397 __packed
01398 #elif defined   (  __GNUC__  )
01399 __attribute__ ((__packed__))
01400 #endif
01401 struct uip_tcpip_hdr {
01402 #if UIP_CONF_IPV6
01403   /* IPv6 header. */
01404   u8_t vtc,
01405     tcflow;
01406   u16_t flow;
01407   u8_t len[2];
01408   u8_t proto, ttl;
01409   uip_ip6addr_t srcipaddr, destipaddr;
01410 #else /* UIP_CONF_IPV6 */
01411   /* IPv4 header. */
01412   u8_t vhl,
01413     tos,
01414     len[2],
01415     ipid[2],
01416     ipoffset[2],
01417     ttl,
01418     proto;
01419   u16_t ipchksum;
01420   u16_t srcipaddr[2],
01421     destipaddr[2];
01422 #endif /* UIP_CONF_IPV6 */
01423 
01424   /* TCP header. */
01425   u16_t srcport,
01426     destport;
01427   u8_t seqno[4],
01428     ackno[4],
01429     tcpoffset,
01430     flags,
01431     wnd[2];
01432   u16_t tcpchksum;
01433   u8_t urgp[2];
01434   u8_t optdata[4];
01435 } /*PACK_STRUCT_END*/;
01436 
01437 #ifdef __ICCARM__
01438     #pragma pack()
01439 #endif
01440 
01441 /* The ICMP and IP headers. */
01442 #ifdef __ICCARM__
01443     #pragma pack(1)
01444 #endif
01445 
01446 
01447 #if defined ( __CC_ARM   )
01448 __packed
01449 #elif defined   (  __GNUC__  )
01450 __attribute__ ((__packed__))
01451 #endif
01452 struct uip_icmpip_hdr {
01453 #if UIP_CONF_IPV6
01454   /* IPv6 header. */
01455   u8_t vtc,
01456     tcf;
01457   u16_t flow;
01458   u8_t len[2];
01459   u8_t proto, ttl;
01460   uip_ip6addr_t srcipaddr, destipaddr;
01461 #else /* UIP_CONF_IPV6 */
01462   /* IPv4 header. */
01463   u8_t vhl,
01464     tos,
01465     len[2],
01466     ipid[2],
01467     ipoffset[2],
01468     ttl,
01469     proto;
01470   u16_t ipchksum;
01471   u16_t srcipaddr[2],
01472     destipaddr[2];
01473 #endif /* UIP_CONF_IPV6 */
01474 
01475   /* ICMP (echo) header. */
01476   u8_t type, icode;
01477   u16_t icmpchksum;
01478 #if !UIP_CONF_IPV6
01479   u16_t id, seqno;
01480 #else /* !UIP_CONF_IPV6 */
01481   u8_t flags, reserved1, reserved2, reserved3;
01482   u8_t icmp6data[16];
01483   u8_t options[1];
01484 #endif /* !UIP_CONF_IPV6 */
01485 } /*PACK_STRUCT_END*/;
01486 
01487 #ifdef __ICCARM__
01488     #pragma pack()
01489 #endif
01490 
01491 
01492 /* The UDP and IP headers. */
01493 #ifdef __ICCARM__
01494     #pragma pack(1)
01495 #endif
01496 
01497 
01498 #if defined ( __CC_ARM   )
01499 __packed
01500 #elif defined   (  __GNUC__  )
01501 __attribute__ ((__packed__))
01502 #endif
01503 struct uip_udpip_hdr {
01504 #if UIP_CONF_IPV6
01505   /* IPv6 header. */
01506   u8_t vtc,
01507     tcf;
01508   u16_t flow;
01509   u8_t len[2];
01510   u8_t proto, ttl;
01511   uip_ip6addr_t srcipaddr, destipaddr;
01512 #else /* UIP_CONF_IPV6 */
01513   /* IP header. */
01514   u8_t vhl,
01515     tos,
01516     len[2],
01517     ipid[2],
01518     ipoffset[2],
01519     ttl,
01520     proto;
01521   u16_t ipchksum;
01522   u16_t srcipaddr[2],
01523     destipaddr[2];
01524 #endif /* UIP_CONF_IPV6 */
01525 
01526   /* UDP header. */
01527   u16_t srcport,
01528     destport;
01529   u16_t udplen;
01530   u16_t udpchksum;
01531 } /*PACK_STRUCT_END*/;
01532 
01533 #ifdef __ICCARM__
01534     #pragma pack()
01535 #endif
01536 
01537 
01538 
01539 /**
01540  * The buffer size available for user data in the \ref uip_buf buffer.
01541  *
01542  * This macro holds the available size for user data in the \ref
01543  * uip_buf buffer. The macro is intended to be used for checking
01544  * bounds of available user data.
01545  *
01546  * Example:
01547  \code
01548  snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
01549  \endcode
01550  *
01551  * \hideinitializer
01552  */
01553 #define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
01554 
01555 
01556 #define UIP_PROTO_ICMP  1
01557 #define UIP_PROTO_TCP   6
01558 #define UIP_PROTO_UDP   17
01559 #define UIP_PROTO_ICMP6 58
01560 
01561 /* Header sizes. */
01562 #if UIP_CONF_IPV6
01563 #define UIP_IPH_LEN    40
01564 #else /* UIP_CONF_IPV6 */
01565 #define UIP_IPH_LEN    20    /* Size of IP header */
01566 #endif /* UIP_CONF_IPV6 */
01567 #define UIP_UDPH_LEN    8    /* Size of UDP header */
01568 #define UIP_TCPH_LEN   20    /* Size of TCP header */
01569 #define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN)    /* Size of IP +
01570                               UDP
01571                               header */
01572 #define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN)    /* Size of IP +
01573                               TCP
01574                               header */
01575 #define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
01576 
01577 
01578 #if UIP_FIXEDADDR
01579 extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
01580 #else /* UIP_FIXEDADDR */
01581 extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
01582 #endif /* UIP_FIXEDADDR */
01583 
01584 
01585 
01586 /**
01587  * Representation of a 48-bit Ethernet address.
01588  */
01589 #ifdef __ICCARM__
01590     #pragma pack(1)
01591 #endif
01592 
01593 
01594 #if defined ( __CC_ARM   )
01595 __packed
01596 #elif defined   (  __GNUC__  )
01597 __attribute__ ((__packed__))
01598 #endif
01599 struct uip_eth_addr {
01600   u8_t addr[6];
01601 } /*PACK_STRUCT_END*/;
01602 
01603 #ifdef __ICCARM__
01604     #pragma pack()
01605 #endif
01606 
01607 /**
01608  * Calculate the Internet checksum over a buffer.
01609  *
01610  * The Internet checksum is the one's complement of the one's
01611  * complement sum of all 16-bit words in the buffer.
01612  *
01613  * See RFC1071.
01614  *
01615  * \param buf A pointer to the buffer over which the checksum is to be
01616  * computed.
01617  *
01618  * \param len The length of the buffer over which the checksum is to
01619  * be computed.
01620  *
01621  * \return The Internet checksum of the buffer.
01622  */
01623 u16_t uip_chksum(u16_t *buf, u16_t len);
01624 
01625 /**
01626  * Calculate the IP header checksum of the packet header in uip_buf.
01627  *
01628  * The IP header checksum is the Internet checksum of the 20 bytes of
01629  * the IP header.
01630  *
01631  * \return The IP header checksum of the IP header in the uip_buf
01632  * buffer.
01633  */
01634 u16_t uip_ipchksum(void);
01635 
01636 /**
01637  * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
01638  *
01639  * The TCP checksum is the Internet checksum of data contents of the
01640  * TCP segment, and a pseudo-header as defined in RFC793.
01641  *
01642  * \return The TCP checksum of the TCP segment in uip_buf and pointed
01643  * to by uip_appdata.
01644  */
01645 u16_t uip_tcpchksum(void);
01646 
01647 /**
01648  * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
01649  *
01650  * The UDP checksum is the Internet checksum of data contents of the
01651  * UDP segment, and a pseudo-header as defined in RFC768.
01652  *
01653  * \return The UDP checksum of the UDP segment in uip_buf and pointed
01654  * to by uip_appdata.
01655  */
01656 u16_t uip_udpchksum(void);
01657 
01658 
01659 #endif /* __UIP_H__ */
01660 
01661 
01662 /** @} */