9 * Header file for the uIP TCP/IP stack.
\r
10 * \author Adam Dunkels <adam@dunkels.com>
\r
11 * \author Julien Abeille <jabeille@cisco.com> (IPv6 related code)
\r
12 * \author Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)
\r
14 * The uIP TCP/IP stack header file contains definitions for a number
\r
15 * of C macros that are used by uIP programs as well as internal uIP
\r
16 * structures, TCP/IP header structures and function declarations.
\r
21 * Copyright (c) 2001-2003, Adam Dunkels.
\r
22 * All rights reserved.
\r
24 * Redistribution and use in source and binary forms, with or without
\r
25 * modification, are permitted provided that the following conditions
\r
27 * 1. Redistributions of source code must retain the above copyright
\r
28 * notice, this list of conditions and the following disclaimer.
\r
29 * 2. Redistributions in binary form must reproduce the above copyright
\r
30 * notice, this list of conditions and the following disclaimer in the
\r
31 * documentation and/or other materials provided with the distribution.
\r
32 * 3. The name of the author may not be used to endorse or promote
\r
33 * products derived from this software without specific prior
\r
34 * written permission.
\r
36 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
\r
37 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
38 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
39 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
\r
40 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
41 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
\r
42 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
43 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
\r
44 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
45 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
46 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
48 * This file is part of the uIP TCP/IP stack.
\r
50 * $Id: uip.h,v 1.24 2009/04/06 13:18:50 nvt-se Exp $
\r
56 #include "net/uipopt.h"
\r
57 #include "uip-conf.h"
\r
60 * Representation of an IP address.
\r
63 #if UIP_CONF_IPV6 != 0
\r
64 typedef union uip_ip6addr_t
\r
66 u8_t u8[16]; /* Initializer, must come first!!! */
\r
70 typedef uip_ip6addr_t uip_ipaddr_t;
\r
71 #else /* UIP_CONF_IPV6 */
\r
72 #include "pack_struct_start.h"
\r
73 typedef union uip_ip4addr_t
\r
75 u8_t u8[4]; /* Initializer, must come first!!! */
\r
78 typedef uip_ip4addr_t uip_ipaddr_t
\r
79 #include "pack_struct_end.h"
\r
80 #endif /* UIP_CONF_IPV6 */
\r
82 /*---------------------------------------------------------------------------*/
\r
84 /** \brief 16 bit 802.15.4 address */
\r
85 struct uip_802154_shortaddr
\r
90 /** \brief 64 bit 802.15.4 address */
\r
91 struct uip_802154_longaddr
\r
96 /** \brief 802.11 address */
\r
97 struct uip_80211_addr
\r
102 /** \brief 802.3 address */
\r
103 #include "net/pack_struct_start.h"
\r
104 struct uip_eth_addr
\r
108 #include "net/pack_struct_end.h"
\r
110 #ifdef UIP_CONF_LL_802154
\r
112 /** \brief 802.15.4 address */
\r
113 typedef struct uip_802154_longaddr uip_lladdr_t;
\r
114 #define UIP_802154_SHORTADDR_LEN 2
\r
115 #define UIP_802154_LONGADDR_LEN 8
\r
116 #define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN
\r
117 #else /*UIP_CONF_LL_802154*/
\r
118 #ifdef UIP_CONF_LL_80211
\r
119 /** \brief 802.11 address */
\r
120 typedef struct uip_80211_addr uip_lladdr_t;
\r
121 #define UIP_LLADDR_LEN 6
\r
122 #else /*UIP_CONF_LL_80211*/
\r
124 /** \brief Ethernet address */
\r
125 typedef struct uip_eth_addr uip_lladdr_t;
\r
127 #define UIP_LLADDR_LEN 6
\r
128 #endif /*UIP_CONF_LL_80211*/
\r
129 #endif /*UIP_CONF_LL_802154*/
\r
131 //_RB_#include "net/tcpip.h"
\r
133 /*---------------------------------------------------------------------------*/
\r
135 /* First, the functions that should be called from the
\r
136 * system. Initialization, the periodic timer, and incoming packets are
\r
137 * handled by the following three functions.
\r
141 * \defgroup uipconffunc uIP configuration functions
\r
144 * The uIP configuration functions are used for setting run-time
\r
145 * parameters in uIP such as IP addresses.
\r
149 * Set the IP address of this host.
\r
151 * The IP address is represented as a 4-byte array where the first
\r
152 * octet of the IP address is put in the first member of the 4-byte
\r
160 uip_ipaddr(&addr, 192,168,1,2);
\r
161 uip_sethostaddr(&addr);
\r
164 * \param addr A pointer to an IP address of type uip_ipaddr_t;
\r
170 #define uip_sethostaddr( addr ) uip_ipaddr_copy( &uip_hostaddr, (addr) )
\r
173 * Get the IP address of this host.
\r
175 * The IP address is represented as a 4-byte array where the first
\r
176 * octet of the IP address is put in the first member of the 4-byte
\r
181 uip_ipaddr_t hostaddr;
\r
183 uip_gethostaddr(&hostaddr);
\r
185 * \param addr A pointer to a uip_ipaddr_t variable that will be
\r
186 * filled in with the currently configured IP address.
\r
190 #define uip_gethostaddr( addr ) uip_ipaddr_copy( (addr), &uip_hostaddr )
\r
193 * Set the default router's IP address.
\r
195 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
\r
196 * address of the default router.
\r
202 #define uip_setdraddr( addr ) uip_ipaddr_copy( &uip_draddr, (addr) )
\r
207 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
\r
208 * address of the netmask.
\r
214 #define uip_setnetmask( addr ) uip_ipaddr_copy( &uip_netmask, (addr) )
\r
217 * Get the default router's IP address.
\r
219 * \param addr A pointer to a uip_ipaddr_t variable that will be
\r
220 * filled in with the IP address of the default router.
\r
224 #define uip_getdraddr( addr ) uip_ipaddr_copy( (addr), &uip_draddr )
\r
229 * \param addr A pointer to a uip_ipaddr_t variable that will be
\r
230 * filled in with the value of the netmask.
\r
234 #define uip_getnetmask( addr ) uip_ipaddr_copy( (addr), &uip_netmask )
\r
239 * \defgroup uipinit uIP initialization functions
\r
242 * The uIP initialization functions are used for booting uIP.
\r
246 * uIP initialization function.
\r
248 * This function should be called at boot up to initilize the uIP
\r
251 void uip_init( void );
\r
254 * uIP initialization function.
\r
256 * This function may be used at boot time to set the initial ip_id.
\r
258 void uip_setipid( u16_t id );
\r
263 * \defgroup uipdevfunc uIP device driver functions
\r
266 * These functions are used by a network device driver for interacting
\r
271 * Process an incoming packet.
\r
273 * This function should be called when the device driver has received
\r
274 * a packet from the network. The packet from the device driver must
\r
275 * be present in the uip_buf buffer, and the length of the packet
\r
276 * should be placed in the uip_len variable.
\r
278 * When the function returns, there may be an outbound packet placed
\r
279 * in the uip_buf packet buffer. If so, the uip_len variable is set to
\r
280 * the length of the packet. If no packet is to be sent out, the
\r
281 * uip_len variable is set to 0.
\r
283 * The usual way of calling the function is presented by the source
\r
286 uip_len = devicedriver_poll();
\r
290 devicedriver_send();
\r
295 * \note If you are writing a uIP device driver that needs ARP
\r
296 * (Address Resolution Protocol), e.g., when running uIP over
\r
297 * Ethernet, you will need to call the uIP ARP code before calling
\r
300 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
\r
301 uip_len = ethernet_devicedrver_poll();
\r
303 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
\r
308 ethernet_devicedriver_send();
\r
310 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
\r
313 ethernet_devicedriver_send();
\r
320 #define uip_input() uip_process( UIP_DATA )
\r
323 * Periodic processing for a connection identified by its number.
\r
325 * This function does the necessary periodic processing (timers,
\r
326 * polling) for a uIP TCP conneciton, and should be called when the
\r
327 * periodic uIP timer goes off. It should be called for every
\r
328 * connection, regardless of whether they are open of closed.
\r
330 * When the function returns, it may have an outbound packet waiting
\r
331 * for service in the uIP packet buffer, and if so the uip_len
\r
332 * variable is set to a value larger than zero. The device driver
\r
333 * should be called to send out the packet.
\r
335 * The usual way of calling the function is through a for() loop like
\r
338 for(i = 0; i < UIP_CONNS; ++i) {
\r
341 devicedriver_send();
\r
346 * \note If you are writing a uIP device driver that needs ARP
\r
347 * (Address Resolution Protocol), e.g., when running uIP over
\r
348 * Ethernet, you will need to call the uip_arp_out() function before
\r
349 * calling the device driver:
\r
351 for(i = 0; i < UIP_CONNS; ++i) {
\r
355 ethernet_devicedriver_send();
\r
360 * \param conn The number of the connection which is to be periodically polled.
\r
365 #define uip_periodic( conn ) \
\r
368 uip_conn = &uip_conns[conn]; \
\r
369 uip_process( UIP_TIMER ); \
\r
376 #define uip_conn_active( conn ) ( uip_conns[conn].tcpstateflags != UIP_CLOSED )
\r
379 * Perform periodic processing for a connection identified by a pointer
\r
380 * to its structure.
\r
382 * Same as uip_periodic() but takes a pointer to the actual uip_conn
\r
383 * struct instead of an integer as its argument. This function can be
\r
384 * used to force periodic processing of a specific connection.
\r
386 * \param conn A pointer to the uip_conn struct for the connection to
\r
391 #define uip_periodic_conn( conn ) \
\r
395 uip_process( UIP_TIMER ); \
\r
399 * Request that a particular connection should be polled.
\r
401 * Similar to uip_periodic_conn() but does not perform any timer
\r
402 * processing. The application is polled for new data.
\r
404 * \param conn A pointer to the uip_conn struct for the connection to
\r
409 #define uip_poll_conn( conn ) \
\r
413 uip_process( UIP_POLL_REQUEST ); \
\r
415 #endif /* UIP_TCP */
\r
420 * Periodic processing for a UDP connection identified by its number.
\r
422 * This function is essentially the same as uip_periodic(), but for
\r
423 * UDP connections. It is called in a similar fashion as the
\r
424 * uip_periodic() function:
\r
426 for(i = 0; i < UIP_UDP_CONNS; i++) {
\r
427 uip_udp_periodic(i);
\r
429 devicedriver_send();
\r
434 * \note As for the uip_periodic() function, special care has to be
\r
435 * taken when using uIP together with ARP and Ethernet:
\r
437 for(i = 0; i < UIP_UDP_CONNS; i++) {
\r
438 uip_udp_periodic(i);
\r
441 ethernet_devicedriver_send();
\r
446 * \param conn The number of the UDP connection to be processed.
\r
450 #define uip_udp_periodic( conn ) \
\r
453 uip_udp_conn = &uip_udp_conns[conn]; \
\r
454 uip_process( UIP_UDP_TIMER ); \
\r
458 * Periodic processing for a UDP connection identified by a pointer to
\r
461 * Same as uip_udp_periodic() but takes a pointer to the actual
\r
462 * uip_conn struct instead of an integer as its argument. This
\r
463 * function can be used to force periodic processing of a specific
\r
466 * \param conn A pointer to the uip_udp_conn struct for the connection
\r
471 #define uip_udp_periodic_conn( conn ) \
\r
474 uip_udp_conn = conn; \
\r
475 uip_process( UIP_UDP_TIMER ); \
\r
477 #endif /* UIP_UDP */
\r
479 /** \brief Abandon the reassembly of the current packet */
\r
480 void uip_reass_over( void );
\r
483 * The uIP packet buffer.
\r
485 * The uip_buf array is used to hold incoming and outgoing
\r
486 * packets. The device driver should place incoming data into this
\r
487 * buffer. When sending data, the device driver should read the link
\r
488 * level headers and the TCP/IP headers from this buffer. The size of
\r
489 * the link level headers is configured by the UIP_LLH_LEN define.
\r
491 * \note The application data need not be placed in this buffer, so
\r
492 * the device driver must read it from the place pointed to by the
\r
493 * uip_appdata pointer as illustrated by the following example:
\r
496 devicedriver_send(void)
\r
498 hwsend(&uip_buf[0], UIP_LLH_LEN);
\r
499 if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
\r
500 hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
\r
502 hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
\r
503 hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
\r
508 #ifndef UIP_CONF_EXTERNAL_BUFFER
\r
509 CCIF extern u8_t uip_buf[UIP_BUFSIZE + 2];
\r
511 CCIF extern unsigned char *uip_buf;
\r
516 /*---------------------------------------------------------------------------*/
\r
518 /* Functions that are used by the uIP application program. Opening and
\r
519 * closing connections, sending and receiving data, etc. is all
\r
520 * handled by the functions below.
\r
524 * \defgroup uipappfunc uIP application functions
\r
527 * Functions used by an application running of top of uIP.
\r
531 * Start listening to the specified port.
\r
533 * \note Since this function expects the port number in network byte
\r
534 * order, a conversion using HTONS() or htons() is necessary.
\r
537 uip_listen(HTONS(80));
\r
540 * \param port A 16-bit port number in network byte order.
\r
542 void uip_listen( u16_t port );
\r
545 * Stop listening to the specified port.
\r
547 * \note Since this function expects the port number in network byte
\r
548 * order, a conversion using HTONS() or htons() is necessary.
\r
551 uip_unlisten(HTONS(80));
\r
554 * \param port A 16-bit port number in network byte order.
\r
556 void uip_unlisten( u16_t port );
\r
559 * Connect to a remote host using TCP.
\r
561 * This function is used to start a new connection to the specified
\r
562 * port on the specified host. It allocates a new connection identifier,
\r
563 * sets the connection to the SYN_SENT state and sets the
\r
564 * retransmission timer to 0. This will cause a TCP SYN segment to be
\r
565 * sent out the next time this connection is periodically processed,
\r
566 * which usually is done within 0.5 seconds after the call to
\r
569 * \note This function is available only if support for active open
\r
570 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
\r
572 * \note Since this function requires the port number to be in network
\r
573 * byte order, a conversion using HTONS() or htons() is necessary.
\r
576 uip_ipaddr_t ipaddr;
\r
578 uip_ipaddr(&ipaddr, 192,168,1,2);
\r
579 uip_connect(&ipaddr, HTONS(80));
\r
582 * \param ripaddr The IP address of the remote host.
\r
584 * \param port A 16-bit port number in network byte order.
\r
586 * \return A pointer to the uIP connection identifier for the new connection,
\r
587 * or NULL if no connection could be allocated.
\r
590 struct uip_conn *uip_connect( uip_ipaddr_t *ripaddr, u16_t port );
\r
595 * Check if a connection has outstanding (i.e., unacknowledged) data.
\r
597 * \param conn A pointer to the uip_conn structure for the connection.
\r
601 #define uip_outstanding( conn ) ( (conn)->len )
\r
604 * Send data on the current connection.
\r
606 * This function is used to send out a single segment of TCP
\r
607 * data. Only applications that have been invoked by uIP for event
\r
608 * processing can send data.
\r
610 * The amount of data that actually is sent out after a call to this
\r
611 * function is determined by the maximum amount of data TCP allows. uIP
\r
612 * will automatically crop the data so that only the appropriate
\r
613 * amount of data is sent. The function uip_mss() can be used to query
\r
614 * uIP for the amount of data that actually will be sent.
\r
616 * \note This function does not guarantee that the sent data will
\r
617 * arrive at the destination. If the data is lost in the network, the
\r
618 * application will be invoked with the uip_rexmit() event being
\r
619 * set. The application will then have to resend the data using this
\r
622 * \param data A pointer to the data which is to be sent.
\r
624 * \param len The maximum amount of data bytes to be sent.
\r
628 CCIF void uip_send( const void *data, int len );
\r
631 * The length of any incoming data that is currently available (if available)
\r
632 * in the uip_appdata buffer.
\r
634 * The test function uip_data() must first be used to check if there
\r
635 * is any data available at all.
\r
640 /*void uip_datalen(void);*/
\r
641 #define uip_datalen() uip_len
\r
644 * The length of any out-of-band data (urgent data) that has arrived
\r
645 * on the connection.
\r
647 * \note The configuration parameter UIP_URGDATA must be set for this
\r
648 * function to be enabled.
\r
652 #define uip_urgdatalen() uip_urglen
\r
655 * Close the current connection.
\r
657 * This function will close the current connection in a nice way.
\r
661 #define uip_close() ( uip_flags = UIP_CLOSE )
\r
664 * Abort the current connection.
\r
666 * This function will abort (reset) the current connection, and is
\r
667 * usually used when an error has occurred that prevents using the
\r
668 * uip_close() function.
\r
672 #define uip_abort() ( uip_flags = UIP_ABORT )
\r
675 * Tell the sending host to stop sending data.
\r
677 * This function will close our receiver's window so that we stop
\r
678 * receiving data for the current connection.
\r
682 #define uip_stop() ( uip_conn->tcpstateflags |= UIP_STOPPED )
\r
685 * Find out if the current connection has been previously stopped with
\r
690 #define uip_stopped( conn ) ( (conn)->tcpstateflags & UIP_STOPPED )
\r
693 * Restart the current connection, if is has previously been stopped
\r
696 * This function will open the receiver's window again so that we
\r
697 * start receiving data for the current connection.
\r
701 #define uip_restart() \
\r
704 uip_flags |= UIP_NEWDATA; \
\r
705 uip_conn->tcpstateflags &= ~UIP_STOPPED; \
\r
708 /* uIP tests that can be made to determine in what state the current
\r
709 connection is, and what the application function should do. */
\r
712 * Is the current connection a UDP connection?
\r
714 * This function checks whether the current connection is a UDP connection.
\r
719 #define uip_udpconnection() ( uip_conn == NULL )
\r
722 * Is new incoming data available?
\r
724 * Will reduce to non-zero if there is new data for the application
\r
725 * present at the uip_appdata pointer. The size of the data is
\r
726 * available through the uip_len variable.
\r
730 #define uip_newdata() ( uip_flags & UIP_NEWDATA )
\r
733 * Has previously sent data been acknowledged?
\r
735 * Will reduce to non-zero if the previously sent data has been
\r
736 * acknowledged by the remote host. This means that the application
\r
737 * can send new data.
\r
741 #define uip_acked() ( uip_flags & UIP_ACKDATA )
\r
744 * Has the connection just been connected?
\r
746 * Reduces to non-zero if the current connection has been connected to
\r
747 * a remote host. This will happen both if the connection has been
\r
748 * actively opened (with uip_connect()) or passively opened (with
\r
753 #define uip_connected() ( uip_flags & UIP_CONNECTED )
\r
756 * Has the connection been closed by the other end?
\r
758 * Is non-zero if the connection has been closed by the remote
\r
759 * host. The application may then do the necessary clean-ups.
\r
763 #define uip_closed() ( uip_flags & UIP_CLOSE )
\r
766 * Has the connection been aborted by the other end?
\r
768 * Non-zero if the current connection has been aborted (reset) by the
\r
773 #define uip_aborted() ( uip_flags & UIP_ABORT )
\r
776 * Has the connection timed out?
\r
778 * Non-zero if the current connection has been aborted due to too many
\r
783 #define uip_timedout() ( uip_flags & UIP_TIMEDOUT )
\r
786 * Do we need to retransmit previously data?
\r
788 * Reduces to non-zero if the previously sent data has been lost in
\r
789 * the network, and the application should retransmit it. The
\r
790 * application should send the exact same data as it did the last
\r
791 * time, using the uip_send() function.
\r
795 #define uip_rexmit() ( uip_flags & UIP_REXMIT )
\r
798 * Is the connection being polled by uIP?
\r
800 * Is non-zero if the reason the application is invoked is that the
\r
801 * current connection has been idle for a while and should be
\r
804 * The polling event can be used for sending data without having to
\r
805 * wait for the remote host to send data.
\r
809 #define uip_poll() ( uip_flags & UIP_POLL )
\r
812 * Get the initial maximum segment size (MSS) of the current
\r
817 #define uip_initialmss() ( uip_conn->initialmss )
\r
820 * Get the current maximum segment size that can be sent on the current
\r
823 * The current maximum segment size that can be sent on the
\r
824 * connection is computed from the receiver's window and the MSS of
\r
825 * the connection (which also is available by calling
\r
826 * uip_initialmss()).
\r
830 #define uip_mss() ( uip_conn->mss )
\r
832 * Set up a new UDP connection.
\r
834 * This function sets up a new UDP connection. The function will
\r
835 * automatically allocate an unused local port for the new
\r
836 * connection. However, another port can be chosen by using the
\r
837 * uip_udp_bind() call, after the uip_udp_new() function has been
\r
843 struct uip_udp_conn *c;
\r
845 uip_ipaddr(&addr, 192,168,2,1);
\r
846 c = uip_udp_new(&addr, HTONS(12345));
\r
848 uip_udp_bind(c, HTONS(12344));
\r
851 * \param ripaddr The IP address of the remote host.
\r
853 * \param rport The remote port number in network byte order.
\r
855 * \return The uip_udp_conn structure for the new connection or NULL
\r
856 * if no connection could be allocated.
\r
858 struct uip_udp_conn *uip_udp_new( const uip_ipaddr_t *ripaddr, u16_t rport );
\r
861 * Removed a UDP connection.
\r
863 * \param conn A pointer to the uip_udp_conn structure for the connection.
\r
867 #define uip_udp_remove( conn ) ( conn )->lport = 0
\r
870 * Bind a UDP connection to a local port.
\r
872 * \param conn A pointer to the uip_udp_conn structure for the
\r
875 * \param port The local port number, in network byte order.
\r
879 #define uip_udp_bind( conn, port ) ( conn )->lport = port
\r
882 * Send a UDP datagram of length len on the current connection.
\r
884 * This function can only be called in response to a UDP event (poll
\r
885 * or newdata). The data must be present in the uip_buf buffer, at the
\r
886 * place pointed to by the uip_appdata pointer.
\r
888 * \param len The length of the data in the uip_buf buffer.
\r
892 #define uip_udp_send( len ) uip_send( ( char * ) uip_appdata, len )
\r
896 /* uIP convenience and converting functions. */
\r
899 * \defgroup uipconvfunc uIP conversion functions
\r
902 * These functions can be used for converting between different data
\r
903 * formats used by uIP.
\r
907 * Convert an IP address to four bytes separated by commas.
\r
911 uip_ipaddr_t ipaddr;
\r
912 printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr));
\r
915 * \param a A pointer to a uip_ipaddr_t.
\r
918 #define uip_ipaddr_to_quad( a ) ( a )->u8[0], ( a )->u8[1], ( a )->u8[2], ( a )->u8[3]
\r
921 * Construct an IP address from four bytes.
\r
923 * This function constructs an IP address of the type that uIP handles
\r
924 * internally from four bytes. The function is handy for specifying IP
\r
925 * addresses to use with e.g. the uip_connect() function.
\r
929 uip_ipaddr_t ipaddr;
\r
930 struct uip_conn *c;
\r
932 uip_ipaddr(&ipaddr, 192,168,1,2);
\r
933 c = uip_connect(&ipaddr, HTONS(80));
\r
936 * \param addr A pointer to a uip_ipaddr_t variable that will be
\r
937 * filled in with the IP address.
\r
939 * \param addr0 The first octet of the IP address.
\r
940 * \param addr1 The second octet of the IP address.
\r
941 * \param addr2 The third octet of the IP address.
\r
942 * \param addr3 The forth octet of the IP address.
\r
946 #define uip_ipaddr( addr, addr0, addr1, addr2, addr3 ) \
\r
949 ( addr )->u8[0] = addr0; \
\r
950 ( addr )->u8[1] = addr1; \
\r
951 ( addr )->u8[2] = addr2; \
\r
952 ( addr )->u8[3] = addr3; \
\r
956 * Construct an IPv6 address from eight 16-bit words.
\r
958 * This function constructs an IPv6 address.
\r
962 #define uip_ip6addr( addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7 ) \
\r
965 ( addr )->u16[0] = HTONS( addr0 ); \
\r
966 ( addr )->u16[1] = HTONS( addr1 ); \
\r
967 ( addr )->u16[2] = HTONS( addr2 ); \
\r
968 ( addr )->u16[3] = HTONS( addr3 ); \
\r
969 ( addr )->u16[4] = HTONS( addr4 ); \
\r
970 ( addr )->u16[5] = HTONS( addr5 ); \
\r
971 ( addr )->u16[6] = HTONS( addr6 ); \
\r
972 ( addr )->u16[7] = HTONS( addr7 ); \
\r
974 * Construct an IPv6 address from eight 8-bit words.
\r
976 * This function constructs an IPv6 address.
\r
980 #define uip_ip6addr_u8 ( addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8, addr9, addr10, addr11, addr12, addr13, addr14, \
\r
983 ( addr )->u8[0] = addr0; \
\r
984 ( addr )->u8[1] = addr1; \
\r
985 ( addr )->u8[2] = addr2; \
\r
986 ( addr )->u8[3] = addr3; \
\r
987 ( addr )->u8[4] = addr4; \
\r
988 ( addr )->u8[5] = addr5; \
\r
989 ( addr )->u8[6] = addr6; \
\r
990 ( addr )->u8[7] = addr7; \
\r
991 ( addr )->u8[8] = addr8; \
\r
992 ( addr )->u8[9] = addr9; \
\r
993 ( addr )->u8[10] = addr10; \
\r
994 ( addr )->u8[11] = addr11; \
\r
995 ( addr )->u8[12] = addr12; \
\r
996 ( addr )->u8[13] = addr13; \
\r
997 ( addr )->u8[14] = addr14; \
\r
998 ( addr )->u8[15] = addr15; \
\r
1001 * Copy an IP address to another IP address.
\r
1003 * Copies an IP address from one place to another.
\r
1007 uip_ipaddr_t ipaddr1, ipaddr2;
\r
1009 uip_ipaddr(&ipaddr1, 192,16,1,2);
\r
1010 uip_ipaddr_copy(&ipaddr2, &ipaddr1);
\r
1013 * \param dest The destination for the copy.
\r
1014 * \param src The source from where to copy.
\r
1016 * \hideinitializer
\r
1018 #ifndef uip_ipaddr_copy
\r
1019 #define uip_ipaddr_copy( dest, src ) \
\r
1022 (dest)->u8[0] = (src)->u8[0]; \
\r
1023 (dest)->u8[1] = (src)->u8[1]; \
\r
1024 (dest)->u8[2] = (src)->u8[2]; \
\r
1025 (dest)->u8[3] = (src)->u8[3]; \
\r
1030 * Compare two IP addresses
\r
1032 * Compares two IP addresses.
\r
1036 uip_ipaddr_t ipaddr1, ipaddr2;
\r
1038 uip_ipaddr(&ipaddr1, 192,16,1,2);
\r
1039 if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
\r
1040 printf("They are the same");
\r
1044 * \param addr1 The first IP address.
\r
1045 * \param addr2 The second IP address.
\r
1047 * \hideinitializer
\r
1049 #if !UIP_CONF_IPV6
\r
1050 #define uip_ipaddr_cmp( addr1, addr2 ) ( (addr1)->u16[0] == (addr2)->u16[0] && (addr1)->u16[1] == (addr2)->u16[1] )
\r
1051 #else /* !UIP_CONF_IPV6 */
\r
1052 #define uip_ipaddr_cmp( addr1, addr2 ) ( memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0 )
\r
1053 #endif /* !UIP_CONF_IPV6 */
\r
1056 * Compare two IP addresses with netmasks
\r
1058 * Compares two IP addresses with netmasks. The masks are used to mask
\r
1059 * out the bits that are to be compared.
\r
1063 uip_ipaddr_t ipaddr1, ipaddr2, mask;
\r
1065 uip_ipaddr(&mask, 255,255,255,0);
\r
1066 uip_ipaddr(&ipaddr1, 192,16,1,2);
\r
1067 uip_ipaddr(&ipaddr2, 192,16,1,3);
\r
1068 if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
\r
1069 printf("They are the same");
\r
1073 * \param addr1 The first IP address.
\r
1074 * \param addr2 The second IP address.
\r
1075 * \param mask The netmask.
\r
1077 * \hideinitializer
\r
1079 #if !UIP_CONF_IPV6
\r
1080 #define uip_ipaddr_maskcmp( addr1, addr2, mask ) \
\r
1082 (((( u16_t * ) addr1)[0] & (( u16_t * ) mask)[0]) == ((( u16_t * ) addr2)[0] & (( u16_t * ) mask)[0])) && \
\r
1083 (((( u16_t * ) addr1)[1] & (( u16_t * ) mask)[1]) == ((( u16_t * ) addr2)[1] & (( u16_t * ) mask)[1])) \
\r
1086 #define uip_ipaddr_prefixcmp( addr1, addr2, length ) ( memcmp(addr1, addr2, length >> 3) == 0 )
\r
1090 * Check if an address is a broadcast address for a network.
\r
1092 * Checks if an address is the broadcast address for a network. The
\r
1093 * network is defined by an IP address that is on the network and the
\r
1094 * network's netmask.
\r
1096 * \param addr The IP address.
\r
1097 * \param netaddr The network's IP address.
\r
1098 * \param netmask The network's netmask.
\r
1100 * \hideinitializer
\r
1103 /*#define uip_ipaddr_isbroadcast(addr, netaddr, netmask)
\r
1104 ((uip_ipaddr_t *)(addr)).u16 & ((uip_ipaddr_t *)(addr)).u16*/
\r
1107 * Mask out the network part of an IP address.
\r
1109 * Masks out the network part of an IP address, given the address and
\r
1114 uip_ipaddr_t ipaddr1, ipaddr2, netmask;
\r
1116 uip_ipaddr(&ipaddr1, 192,16,1,2);
\r
1117 uip_ipaddr(&netmask, 255,255,255,0);
\r
1118 uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
\r
1121 * In the example above, the variable "ipaddr2" will contain the IP
\r
1122 * address 192.168.1.0.
\r
1124 * \param dest Where the result is to be placed.
\r
1125 * \param src The IP address.
\r
1126 * \param mask The netmask.
\r
1128 * \hideinitializer
\r
1130 #define uip_ipaddr_mask( dest, src, mask ) \
\r
1133 ( ( u16_t * ) dest )[0] = ( ( u16_t * ) src )[0] & ( ( u16_t * ) mask )[0]; \
\r
1134 ( ( u16_t * ) dest )[1] = ( ( u16_t * ) src )[1] & ( ( u16_t * ) mask )[1]; \
\r
1138 * Pick the first octet of an IP address.
\r
1140 * Picks out the first octet of an IP address.
\r
1144 uip_ipaddr_t ipaddr;
\r
1147 uip_ipaddr(&ipaddr, 1,2,3,4);
\r
1148 octet = uip_ipaddr1(&ipaddr);
\r
1151 * In the example above, the variable "octet" will contain the value 1.
\r
1153 * \hideinitializer
\r
1155 #define uip_ipaddr1( addr ) ( (addr)->u8[0] )
\r
1158 * Pick the second octet of an IP address.
\r
1160 * Picks out the second octet of an IP address.
\r
1164 uip_ipaddr_t ipaddr;
\r
1167 uip_ipaddr(&ipaddr, 1,2,3,4);
\r
1168 octet = uip_ipaddr2(&ipaddr);
\r
1171 * In the example above, the variable "octet" will contain the value 2.
\r
1173 * \hideinitializer
\r
1175 #define uip_ipaddr2( addr ) ( (addr)->u8[1] )
\r
1178 * Pick the third octet of an IP address.
\r
1180 * Picks out the third octet of an IP address.
\r
1184 uip_ipaddr_t ipaddr;
\r
1187 uip_ipaddr(&ipaddr, 1,2,3,4);
\r
1188 octet = uip_ipaddr3(&ipaddr);
\r
1191 * In the example above, the variable "octet" will contain the value 3.
\r
1193 * \hideinitializer
\r
1195 #define uip_ipaddr3( addr ) ( (addr)->u8[2] )
\r
1198 * Pick the fourth octet of an IP address.
\r
1200 * Picks out the fourth octet of an IP address.
\r
1204 uip_ipaddr_t ipaddr;
\r
1207 uip_ipaddr(&ipaddr, 1,2,3,4);
\r
1208 octet = uip_ipaddr4(&ipaddr);
\r
1211 * In the example above, the variable "octet" will contain the value 4.
\r
1213 * \hideinitializer
\r
1215 #define uip_ipaddr4( addr ) ( (addr)->u8[3] )
\r
1217 * Convert 16-bit quantity from host byte order to network byte order.
\r
1219 * This macro is primarily used for converting constants from host
\r
1220 * byte order to network byte order. For converting variables to
\r
1221 * network byte order, use the htons() function instead.
\r
1223 * \hideinitializer
\r
1226 #if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
\r
1227 #define HTONS( n ) ( n )
\r
1228 #define HTONL( n ) ( n )
\r
1229 #else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
\r
1230 #define HTONS( n ) ( u16_t ) ( (((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8) )
\r
1231 #define HTONL( n ) ( ((u32_t) HTONS(n) << 16) | HTONS((u32_t) (n) >> 16) )
\r
1232 #endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
\r
1234 #error "HTONS already defined!"
\r
1235 #endif /* HTONS */
\r
1238 * Convert 16-bit quantity from host byte order to network byte order.
\r
1240 * This function is primarily used for converting variables from host
\r
1241 * byte order to network byte order. For converting constants to
\r
1242 * network byte order, use the HTONS() macro instead.
\r
1245 CCIF u16_t htons( u16_t val );
\r
1246 #endif /* htons */
\r
1249 #define ntohs htons
\r
1253 CCIF u32_t htonl( u32_t val );
\r
1254 #endif /* htonl */
\r
1257 #define ntohl htonl
\r
1263 * Pointer to the application data in the packet buffer.
\r
1265 * This pointer points to the application data when the application is
\r
1266 * called. If the application wishes to send data, the application may
\r
1267 * use this space to write the data into before calling uip_send().
\r
1269 CCIF extern void *uip_appdata;
\r
1271 #if UIP_URGDATA > 0
\r
1273 /* u8_t *uip_urgdata:
\r
1275 * This pointer points to any urgent data that has been received. Only
\r
1276 * present if compiled with support for urgent data (UIP_URGDATA).
\r
1278 extern void *uip_urgdata;
\r
1279 #endif /* UIP_URGDATA > 0 */
\r
1282 * \defgroup uipdrivervars Variables used in uIP device drivers
\r
1285 * uIP has a few global variables that are used in device drivers for
\r
1290 * The length of the packet in the uip_buf buffer.
\r
1292 * The global variable uip_len holds the length of the packet in the
\r
1295 * When the network device driver calls the uIP input function,
\r
1296 * uip_len should be set to the length of the packet in the uip_buf
\r
1299 * When sending packets, the device driver should use the contents of
\r
1300 * the uip_len variable to determine the length of the outgoing
\r
1304 CCIF extern u16_t uip_len;
\r
1307 * The length of the extension headers
\r
1309 extern u8_t uip_ext_len;
\r
1312 #if UIP_URGDATA > 0
\r
1313 extern u16_t uip_urglen, uip_surglen;
\r
1314 #endif /* UIP_URGDATA > 0 */
\r
1317 * Representation of a uIP TCP connection.
\r
1319 * The uip_conn structure is used for identifying a connection. All
\r
1320 * but one field in the structure are to be considered read-only by an
\r
1321 * application. The only exception is the appstate field whose purpose
\r
1322 * is to let the application store application-specific state (e.g.,
\r
1323 * file pointers) for the connection. The type of this field is
\r
1324 * configured in the "uipopt.h" header file.
\r
1328 uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */
\r
1330 u16_t lport; /**< The local TCP port, in network byte order. */
\r
1331 u16_t rport; /**< The local remote TCP port, in network byte
\r
1334 u8_t rcv_nxt[4]; /**< The sequence number that we expect to
\r
1336 u8_t snd_nxt[4]; /**< The sequence number that was last sent by
\r
1338 u16_t len; /**< Length of the data that was previously sent. */
\r
1339 u16_t mss; /**< Current maximum segment size for the
\r
1341 u16_t initialmss; /**< Initial maximum segment size for the
\r
1343 u8_t sa; /**< Retransmission time-out calculation state
\r
1345 u8_t sv; /**< Retransmission time-out calculation state
\r
1347 u8_t rto; /**< Retransmission time-out. */
\r
1348 u8_t tcpstateflags; /**< TCP state and flags. */
\r
1349 u8_t timer; /**< The retransmission timer. */
\r
1350 u8_t nrtx; /**< The number of retransmissions for the last
\r
1353 /** The application state. */
\r
1354 uip_tcp_appstate_t appstate;
\r
1358 * Pointer to the current TCP connection.
\r
1360 * The uip_conn pointer can be used to access the current TCP
\r
1363 CCIF extern struct uip_conn *uip_conn;
\r
1366 /* The array containing all uIP connections. */
\r
1367 CCIF extern struct uip_conn uip_conns[UIP_CONNS];
\r
1371 * \addtogroup uiparch
\r
1376 * 4-byte array used for the 32-bit sequence number calculations.
\r
1378 extern u8_t uip_acc32[4];
\r
1383 * Representation of a uIP UDP connection.
\r
1385 struct uip_udp_conn
\r
1387 uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */
\r
1388 u16_t lport; /**< The local port number in network byte order. */
\r
1389 u16_t rport; /**< The remote port number in network byte order. */
\r
1390 u8_t ttl; /**< Default time-to-live. */
\r
1392 /** The application state. */
\r
1393 uip_udp_appstate_t appstate;
\r
1397 * The current UDP connection.
\r
1399 extern struct uip_udp_conn *uip_udp_conn;
\r
1400 extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
\r
1401 #endif /* UIP_UDP */
\r
1405 int ( *activate ) ( void );
\r
1406 int ( *deactivate ) ( void );
\r
1407 uip_ipaddr_t * ( *lookup ) ( uip_ipaddr_t *destipaddr, uip_ipaddr_t *nexthop );
\r
1410 #ifdef UIP_CONF_ROUTER
\r
1411 extern const struct uip_router *uip_router;
\r
1414 * uIP routing driver registration function.
\r
1416 void uip_router_register( const struct uip_router *router );
\r
1417 #endif /*UIP_CONF_ROUTER*/
\r
1419 #ifdef UIP_CONF_ICMP6
\r
1420 struct uip_icmp6_conn
\r
1422 uip_icmp6_appstate_t appstate;
\r
1424 extern struct uip_icmp6_conn uip_icmp6_conns;
\r
1425 #endif /*UIP_CONF_ICMP6*/
\r
1428 * The uIP TCP/IP statistics.
\r
1430 * This is the variable in which the uIP TCP/IP statistics are gathered.
\r
1432 #if UIP_STATISTICS == 1
\r
1433 extern struct uip_stats uip_stat;
\r
1434 #define UIP_STAT( s ) s
\r
1436 #define UIP_STAT( s )
\r
1437 #endif /* UIP_STATISTICS == 1 */
\r
1440 * The structure holding the TCP/IP statistics that are gathered if
\r
1441 * UIP_STATISTICS is set to 1.
\r
1448 uip_stats_t recv; /**< Number of received packets at the IP
\r
1450 uip_stats_t sent; /**< Number of sent packets at the IP
\r
1452 uip_stats_t forwarded; /**< Number of forwarded packets at the IP
\r
1454 uip_stats_t drop; /**< Number of dropped packets at the IP
\r
1456 uip_stats_t vhlerr; /**< Number of packets dropped due to wrong
\r
1457 IP version or header length. */
\r
1458 uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
\r
1459 IP length, high byte. */
\r
1460 uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
\r
1461 IP length, low byte. */
\r
1462 uip_stats_t fragerr; /**< Number of packets dropped since they
\r
1463 were IP fragments. */
\r
1464 uip_stats_t chkerr; /**< Number of packets dropped due to IP
\r
1465 checksum errors. */
\r
1466 uip_stats_t protoerr; /**< Number of packets dropped since they
\r
1467 were neither ICMP, UDP nor TCP. */
\r
1468 } ip; /**< IP statistics. */
\r
1471 uip_stats_t recv; /**< Number of received ICMP packets. */
\r
1472 uip_stats_t sent; /**< Number of sent ICMP packets. */
\r
1473 uip_stats_t drop; /**< Number of dropped ICMP packets. */
\r
1474 uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
\r
1476 uip_stats_t chkerr; /**< Number of ICMP packets with a bad
\r
1478 } icmp; /**< ICMP statistics. */
\r
1482 uip_stats_t recv; /**< Number of recived TCP segments. */
\r
1483 uip_stats_t sent; /**< Number of sent TCP segments. */
\r
1484 uip_stats_t drop; /**< Number of dropped TCP segments. */
\r
1485 uip_stats_t chkerr; /**< Number of TCP segments with a bad
\r
1487 uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK
\r
1489 uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */
\r
1490 uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */
\r
1491 uip_stats_t syndrop; /**< Number of dropped SYNs due to too few
\r
1492 connections was avaliable. */
\r
1493 uip_stats_t synrst; /**< Number of SYNs for closed ports,
\r
1494 triggering a RST. */
\r
1495 } tcp; /**< TCP statistics. */
\r
1500 uip_stats_t drop; /**< Number of dropped UDP segments. */
\r
1501 uip_stats_t recv; /**< Number of recived UDP segments. */
\r
1502 uip_stats_t sent; /**< Number of sent UDP segments. */
\r
1503 uip_stats_t chkerr; /**< Number of UDP segments with a bad
\r
1505 } udp; /**< UDP statistics. */
\r
1506 #endif /* UIP_UDP */
\r
1507 #if UIP_CONF_IPV6 != 0
\r
1510 uip_stats_t drop; /**< Number of dropped ND6 packets. */
\r
1511 uip_stats_t recv; /**< Number of recived ND6 packets */
\r
1512 uip_stats_t sent; /**< Number of sent ND6 packets */
\r
1514 #endif /*UIP_CONF_IPV6*/
\r
1517 /*---------------------------------------------------------------------------*/
\r
1519 /* All the stuff below this point is internal to uIP and should not be
\r
1520 * used directly by an application or by a device driver.
\r
1523 /*---------------------------------------------------------------------------*/
\r
1525 /* u8_t uip_flags:
\r
1527 * When the application is called, uip_flags will contain the flags
\r
1528 * that are defined in this file. Please read below for more
\r
1531 CCIF extern u8_t uip_flags;
\r
1533 /* The following flags may be set in the global variable uip_flags
\r
1534 before calling the application callback. The UIP_ACKDATA,
\r
1535 UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
\r
1536 whereas the others are mutually exclusive. Note that these flags
\r
1537 should *NOT* be accessed directly, but only through the uIP
\r
1538 functions/macros. */
\r
1539 #define UIP_ACKDATA 1 /* Signifies that the outstanding data was
\r
1540 acked and the application should send
\r
1541 out new data instead of retransmitting
\r
1543 #define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
\r
1545 #define UIP_REXMIT 4 /* Tells the application to retransmit the
\r
1546 data that was last sent. */
\r
1547 #define UIP_POLL 8 /* Used for polling the application, to
\r
1548 check if the application has data that
\r
1549 it wants to send. */
\r
1550 #define UIP_CLOSE 16 /* The remote host has closed the
\r
1551 connection, thus the connection has
\r
1552 gone away. Or the application signals
\r
1553 that it wants to close the
\r
1555 #define UIP_ABORT 32 /* The remote host has aborted the
\r
1556 connection, thus the connection has
\r
1557 gone away. Or the application signals
\r
1558 that it wants to abort the
\r
1560 #define UIP_CONNECTED 64 /* We have got a connection from a remote
\r
1561 host and have set up a new connection
\r
1562 for it, or an active connection has
\r
1563 been successfully established. */
\r
1565 #define UIP_TIMEDOUT 128 /* The connection has been aborted due to
\r
1566 too many retransmissions. */
\r
1569 * \brief process the options within a hop by hop or destination option header
\r
1570 * \retval 0: nothing to send,
\r
1571 * \retval 1: drop pkt
\r
1572 * \retval 2: ICMP error message to send
\r
1576 uip_ext_hdr_options_process(); */
\r
1578 /* uip_process(flag):
\r
1580 * The actual uIP function which does all the work.
\r
1582 void uip_process( u8_t flag );
\r
1584 /* The following flags are passed as an argument to the uip_process()
\r
1585 function. They are used to distinguish between the two cases where
\r
1586 uip_process() is called. It can be called either because we have
\r
1587 incoming data that should be processed, or because the periodic
\r
1588 timer has fired. These values are never used directly, but only in
\r
1589 the macros defined in this file. */
\r
1590 #define UIP_DATA 1 /* Tells uIP that there is incoming
\r
1591 data in the uip_buf buffer. The
\r
1592 length of the data is stored in the
\r
1593 global variable uip_len. */
\r
1594 #define UIP_TIMER 2 /* Tells uIP that the periodic timer
\r
1596 #define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should
\r
1598 #define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram
\r
1599 should be constructed in the
\r
1600 uip_buf buffer. */
\r
1602 #define UIP_UDP_TIMER 5
\r
1603 #endif /* UIP_UDP */
\r
1605 /* The TCP states used in the uip_conn->tcpstateflags. */
\r
1606 #define UIP_CLOSED 0
\r
1607 #define UIP_SYN_RCVD 1
\r
1608 #define UIP_SYN_SENT 2
\r
1609 #define UIP_ESTABLISHED 3
\r
1610 #define UIP_FIN_WAIT_1 4
\r
1611 #define UIP_FIN_WAIT_2 5
\r
1612 #define UIP_CLOSING 6
\r
1613 #define UIP_TIME_WAIT 7
\r
1614 #define UIP_LAST_ACK 8
\r
1615 #define UIP_TS_MASK 15
\r
1617 #define UIP_STOPPED 16
\r
1619 /* The TCP and IP headers. */
\r
1620 #include "net/pack_struct_start.h"
\r
1621 struct uip_tcpip_hdr
\r
1623 #if UIP_CONF_IPV6 != 0
\r
1624 /* IPv6 header. */
\r
1629 uip_ip6addr_t srcipaddr, destipaddr;
\r
1630 #else /* UIP_CONF_IPV6 */
\r
1631 /* IPv4 header. */
\r
1632 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
\r
1634 uip_ipaddr_t srcipaddr, destipaddr;
\r
1635 #endif /* UIP_CONF_IPV6 */
\r
1638 u16_t srcport, destport;
\r
1639 u8_t seqno[4], ackno[4], tcpoffset, flags, wnd[2];
\r
1644 #include "net/pack_struct_end.h"
\r
1646 /* The ICMP and IP headers. */
\r
1647 #include "net/pack_struct_start.h"
\r
1648 struct uip_icmpip_hdr
\r
1650 #if UIP_CONF_IPV6 != 0
\r
1651 /* IPv6 header. */
\r
1656 uip_ip6addr_t srcipaddr, destipaddr;
\r
1657 #else /* UIP_CONF_IPV6 */
\r
1658 /* IPv4 header. */
\r
1659 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
\r
1661 uip_ipaddr_t srcipaddr, destipaddr;
\r
1662 #endif /* UIP_CONF_IPV6 */
\r
1664 /* ICMP header. */
\r
1667 #if !UIP_CONF_IPV6
\r
1670 #endif /* !UIP_CONF_IPV6 */
\r
1673 #include "net/pack_struct_end.h"
\r
1675 /* The UDP and IP headers. */
\r
1676 #include "net/pack_struct_start.h"
\r
1677 struct uip_udpip_hdr
\r
1679 #if UIP_CONF_IPV6 != 0
\r
1680 /* IPv6 header. */
\r
1685 uip_ip6addr_t srcipaddr, destipaddr;
\r
1686 #else /* UIP_CONF_IPV6 */
\r
1688 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
\r
1690 uip_ipaddr_t srcipaddr, destipaddr;
\r
1691 #endif /* UIP_CONF_IPV6 */
\r
1694 u16_t srcport, destport;
\r
1699 #include "net/pack_struct_end.h"
\r
1702 * In IPv6 the length of the L3 headers before the transport header is
\r
1703 * not fixed, due to the possibility to include extension option headers
\r
1704 * after the IP header. hence we split here L3 and L4 headers
\r
1707 /* The IP header */
\r
1710 #if UIP_CONF_IPV6 != 0
\r
1717 uip_ip6addr_t srcipaddr, destipaddr;
\r
1718 #else /* UIP_CONF_IPV6 */
\r
1720 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
\r
1722 uip_ipaddr_t srcipaddr, destipaddr;
\r
1723 #endif /* UIP_CONF_IPV6 */
\r
1727 * IPv6 extension option headers: we are able to process
\r
1728 * the 4 extension headers defined in RFC2460 (IPv6):
\r
1729 * - Hop by hop option header, destination option header:
\r
1730 * These two are not used by any core IPv6 protocol, hence
\r
1731 * we just read them and go to the next. They convey options,
\r
1732 * the options defined in RFC2460 are Pad1 and PadN, which do
\r
1733 * some padding, and that we do not need to read (the length
\r
1734 * field in the header is enough)
\r
1735 * - Routing header: this one is most notably used by MIPv6,
\r
1736 * which we do not implement, hence we just read it and go
\r
1738 * - Fragmentation header: we read this header and are able to
\r
1739 * reassemble packets
\r
1741 * We do not offer any means to send packets with extension headers
\r
1743 * We do not implement Authentication and ESP headers, which are
\r
1744 * used in IPSec and defined in RFC4302,4303,4305,4385
\r
1747 /* common header part */
\r
1748 struct uip_ext_hdr
\r
1754 /* Hop by Hop option header */
\r
1755 struct uip_hbho_hdr
\r
1761 /* destination option header */
\r
1762 struct uip_desto_hdr
\r
1768 /* We do not define structures for PAD1 and PADN options */
\r
1772 * the routing header as 4 common bytes, then routing header type
\r
1773 * specific data there are several types of routing header. Type 0 was
\r
1774 * deprecated as per RFC5095 most notable other type is 2, used in
\r
1775 * RFC3775 (MIPv6) here we do not implement MIPv6, so we just need to
\r
1776 * parse the 4 first bytes
\r
1778 struct uip_routing_hdr
\r
1782 u8_t routing_type;
\r
1786 /* fragmentation header */
\r
1787 struct uip_frag_hdr
\r
1791 u16_t offsetresmore;
\r
1796 * an option within the destination or hop by hop option headers
\r
1797 * it contains type an length, which is true for all options but PAD1
\r
1799 struct uip_ext_hdr_opt
\r
1806 struct uip_ext_hdr_opt_padn
\r
1813 struct uip_tcp_hdr
\r
1827 /* The ICMP headers. */
\r
1828 struct uip_icmp_hdr
\r
1832 #if !UIP_CONF_IPV6
\r
1834 #endif /* !UIP_CONF_IPV6 */
\r
1837 /* The UDP headers. */
\r
1838 struct uip_udp_hdr
\r
1847 * The buffer size available for user data in the \ref uip_buf buffer.
\r
1849 * This macro holds the available size for user data in the \ref
\r
1850 * uip_buf buffer. The macro is intended to be used for checking
\r
1851 * bounds of available user data.
\r
1855 snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
\r
1858 * \hideinitializer
\r
1860 #define UIP_APPDATA_SIZE ( UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN )
\r
1861 #define UIP_APPDATA_PTR ( void * ) &uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]
\r
1863 #define UIP_PROTO_ICMP 1
\r
1864 #define UIP_PROTO_TCP 6
\r
1865 #define UIP_PROTO_UDP 17
\r
1866 #define UIP_PROTO_ICMP6 58
\r
1868 #if UIP_CONF_IPV6 != 0
\r
1872 /** \brief extension headers types */
\r
1873 #define UIP_PROTO_HBHO 0
\r
1874 #define UIP_PROTO_DESTO 60
\r
1875 #define UIP_PROTO_ROUTING 43
\r
1876 #define UIP_PROTO_FRAG 44
\r
1877 #define UIP_PROTO_NONE 59
\r
1883 /** \brief Destination and Hop By Hop extension headers option types */
\r
1884 #define UIP_EXT_HDR_OPT_PAD1 0
\r
1885 #define UIP_EXT_HDR_OPT_PADN 1
\r
1892 * \brief Bitmaps for extension header processing
\r
1894 * When processing extension headers, we should record somehow which one we
\r
1895 * see, because you cannot have twice the same header, except for destination
\r
1896 * We store all this in one u8_t bitmap one bit for each header expected. The
\r
1897 * order in the bitmap is the order recommended in RFC2460
\r
1899 #define UIP_EXT_HDR_BITMAP_HBHO 0x01
\r
1900 #define UIP_EXT_HDR_BITMAP_DESTO1 0x02
\r
1901 #define UIP_EXT_HDR_BITMAP_ROUTING 0x04
\r
1902 #define UIP_EXT_HDR_BITMAP_FRAG 0x08
\r
1903 #define UIP_EXT_HDR_BITMAP_AH 0x10
\r
1904 #define UIP_EXT_HDR_BITMAP_ESP 0x20
\r
1905 #define UIP_EXT_HDR_BITMAP_DESTO2 0x40
\r
1908 #endif /* UIP_CONF_IPV6 */
\r
1910 /* Header sizes. */
\r
1911 #if UIP_CONF_IPV6 != 0
\r
1912 #define UIP_IPH_LEN 40
\r
1913 #define UIP_FRAGH_LEN 8
\r
1914 #else /* UIP_CONF_IPV6 */
\r
1915 #define UIP_IPH_LEN 20 /* Size of IP header */
\r
1916 #endif /* UIP_CONF_IPV6 */
\r
1918 #define UIP_UDPH_LEN 8 /* Size of UDP header */
\r
1919 #define UIP_TCPH_LEN 20 /* Size of TCP header */
\r
1920 #ifdef UIP_IPH_LEN
\r
1921 #define UIP_ICMPH_LEN 4 /* Size of ICMP header */
\r
1923 #define UIP_IPUDPH_LEN ( UIP_UDPH_LEN + UIP_IPH_LEN ) /* Size of IP +
\r
1926 #define UIP_IPTCPH_LEN ( UIP_TCPH_LEN + UIP_IPH_LEN ) /* Size of IP +
\r
1929 #define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
\r
1930 #define UIP_IPICMPH_LEN ( UIP_IPH_LEN + UIP_ICMPH_LEN ) /* size of ICMP
\r
1932 #define UIP_LLIPH_LEN ( UIP_LLH_LEN + UIP_IPH_LEN ) /* size of L2
\r
1934 #if UIP_CONF_IPV6 != 0
\r
1937 * The sums below are quite used in ND. When used for uip_buf, we
\r
1938 * include link layer length when used for uip_len, we do not, hence
\r
1939 * we need values with and without LLH_LEN we do not use capital
\r
1940 * letters as these values are variable
\r
1942 #define uip_l2_l3_hdr_len ( UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len )
\r
1943 #define uip_l2_l3_icmp_hdr_len ( UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN )
\r
1944 #define uip_l3_hdr_len ( UIP_IPH_LEN + uip_ext_len )
\r
1945 #define uip_l3_icmp_hdr_len ( UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN )
\r
1946 #endif /*UIP_CONF_IPV6*/
\r
1948 #ifdef UIP_FIXEDADDR
\r
1949 CCIF extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
\r
1950 #else /* UIP_FIXEDADDR */
\r
1951 CCIF extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
\r
1952 #endif /* UIP_FIXEDADDR */
\r
1953 CCIF extern const uip_ipaddr_t uip_broadcast_addr;
\r
1954 CCIF extern const uip_ipaddr_t uip_all_zeroes_addr;
\r
1956 #ifdef UIP_FIXEDETHADDR
\r
1957 CCIF extern const uip_lladdr_t uip_lladdr;
\r
1959 CCIF extern uip_lladdr_t uip_lladdr;
\r
1961 #if UIP_CONF_IPV6 != 0
\r
1964 * \brief Is IPv6 address a the unspecified address
\r
1965 * a is of type uip_ipaddr_t
\r
1967 #define uip_is_addr_unspecified( a ) \
\r
1969 (((a)->u16[0]) == 0) && \
\r
1970 (((a)->u16[1]) == 0) && \
\r
1971 (((a)->u16[2]) == 0) && \
\r
1972 (((a)->u16[3]) == 0) && \
\r
1973 (((a)->u16[4]) == 0) && \
\r
1974 (((a)->u16[5]) == 0) && \
\r
1975 (((a)->u16[6]) == 0) && \
\r
1976 (((a)->u16[7]) == 0) \
\r
1979 /** \brief Is IPv6 address a the link local all-nodes multicast address */
\r
1980 #define uip_is_addr_linklocal_allnodes_mcast( a ) \
\r
1982 (((a)->u8[0]) == 0xff) && \
\r
1983 (((a)->u8[1]) == 0x02) && \
\r
1984 (((a)->u16[1]) == 0) && \
\r
1985 (((a)->u16[2]) == 0) && \
\r
1986 (((a)->u16[3]) == 0) && \
\r
1987 (((a)->u16[4]) == 0) && \
\r
1988 (((a)->u16[5]) == 0) && \
\r
1989 (((a)->u16[6]) == 0) && \
\r
1990 (((a)->u8[14]) == 0) && \
\r
1991 (((a)->u8[15]) == 0x01) \
\r
1994 /** \brief set IP address a to unspecified */
\r
1995 #define uip_create_unspecified( a ) uip_ip6addr( a, 0, 0, 0, 0, 0, 0, 0, 0 )
\r
1997 /** \brief set IP address a to the link local all-nodes multicast address */
\r
1998 #define uip_create_linklocal_allnodes_mcast( a ) uip_ip6addr( a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001 )
\r
2000 /** \brief set IP address a to the link local all-routers multicast address */
\r
2001 #define uip_create_linklocal_allrouters_mcast( a ) uip_ip6addr( a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002 )
\r
2004 * \brief is addr (a) a solicited node multicast address, see RFC3513
\r
2005 * a is of type uip_ipaddr_t*
\r
2007 #define uip_is_addr_solicited_node( a ) \
\r
2009 (((a)->u8[0]) == 0xFF) && \
\r
2010 (((a)->u8[1]) == 0x02) && \
\r
2011 (((a)->u16[1]) == 0) && \
\r
2012 (((a)->u16[2]) == 0) && \
\r
2013 (((a)->u16[3]) == 0) && \
\r
2014 (((a)->u16[4]) == 0) && \
\r
2015 (((a)->u16[5]) == 1) && \
\r
2016 (((a)->u8[12]) == 0xFF) \
\r
2020 * \briefput in b the solicited node address corresponding to address a
\r
2021 * both a and b are of type uip_ipaddr_t*
\r
2023 #define uip_create_solicited_node( a, b ) \
\r
2024 ( ((b)->u8[0]) = 0xFF ); \
\r
2025 ( ((b)->u8[1]) = 0x02 ); \
\r
2026 ( ((b)->u16[1]) = 0 ); \
\r
2027 ( ((b)->u16[2]) = 0 ); \
\r
2028 ( ((b)->u16[3]) = 0 ); \
\r
2029 ( ((b)->u16[4]) = 0 ); \
\r
2030 ( ((b)->u8[10]) = 0 ); \
\r
2031 ( ((b)->u8[11]) = 0x01 ); \
\r
2032 ( ((b)->u8[12]) = 0xFF ); \
\r
2033 ( ((b)->u8[13]) = ((a)->u8[13]) ); \
\r
2034 ( ((b)->u16[7]) = ((a)->u16[7]) )
\r
2037 * \brief is addr (a) a link local unicast address, see RFC3513
\r
2038 * i.e. is (a) on prefix FE80::/10
\r
2039 * a is of type uip_ipaddr_t*
\r
2041 #define uip_is_addr_link_local( a ) ( (((a)->u8[0]) == 0xFE) && (((a)->u8[1]) == 0x80) )
\r
2044 * \brief was addr (a) forged based on the mac address m
\r
2045 * a type is uip_ipaddr_t
\r
2046 * m type is uiplladdr_t
\r
2048 #ifdef UIP_CONF_LL_802154
\r
2049 #define uip_is_addr_mac_addr_based( a, m ) \
\r
2051 (((a)->u8[8]) == (((m)->addr[0]) ^ 0x02)) && \
\r
2052 (((a)->u8[9]) == (m)->addr[1]) && \
\r
2053 (((a)->u8[10]) == (m)->addr[2]) && \
\r
2054 (((a)->u8[11]) == (m)->addr[3]) && \
\r
2055 (((a)->u8[12]) == (m)->addr[4]) && \
\r
2056 (((a)->u8[13]) == (m)->addr[5]) && \
\r
2057 (((a)->u8[14]) == (m)->addr[6]) && \
\r
2058 (((a)->u8[15]) == (m)->addr[7]) \
\r
2061 #define uip_is_addr_mac_addr_based( a, m ) \
\r
2063 (((a)->u8[8]) == (((m)->addr[0]) | 0x02)) && \
\r
2064 (((a)->u8[9]) == (m)->addr[1]) && \
\r
2065 (((a)->u8[10]) == (m)->addr[2]) && \
\r
2066 (((a)->u8[11]) == 0xff) && \
\r
2067 (((a)->u8[12]) == 0xfe) && \
\r
2068 (((a)->u8[13]) == (m)->addr[3]) && \
\r
2069 (((a)->u8[14]) == (m)->addr[4]) && \
\r
2070 (((a)->u8[15]) == (m)->addr[5]) \
\r
2072 #endif /*UIP_CONF_LL_802154*/
\r
2075 * \brief is address a multicast address, see RFC 3513
\r
2076 * a is of type uip_ipaddr_t*
\r
2078 #define uip_is_addr_mcast( a ) ( ((a)->u8[0]) == 0xFF )
\r
2081 * \brief is group-id of multicast address a
\r
2082 * the all nodes group-id
\r
2084 #define uip_is_mcast_group_id_all_nodes( a ) \
\r
2086 (((a)->u16[1]) == 0) && \
\r
2087 (((a)->u16[2]) == 0) && \
\r
2088 (((a)->u16[3]) == 0) && \
\r
2089 (((a)->u16[4]) == 0) && \
\r
2090 (((a)->u16[5]) == 0) && \
\r
2091 (((a)->u16[6]) == 0) && \
\r
2092 (((a)->u8[14]) == 0) && \
\r
2093 (((a)->u8[15]) == 1) \
\r
2097 * \brief is group-id of multicast address a
\r
2098 * the all routers group-id
\r
2100 #define uip_is_mcast_group_id_all_routers( a ) \
\r
2102 (((a)->u16[1]) == 0) && \
\r
2103 (((a)->u16[2]) == 0) && \
\r
2104 (((a)->u16[3]) == 0) && \
\r
2105 (((a)->u16[4]) == 0) && \
\r
2106 (((a)->u16[5]) == 0) && \
\r
2107 (((a)->u16[6]) == 0) && \
\r
2108 (((a)->u8[14]) == 0) && \
\r
2109 (((a)->u8[15]) == 2) \
\r
2111 #endif /*UIP_CONF_IPV6*/
\r
2114 * Calculate the Internet checksum over a buffer.
\r
2116 * The Internet checksum is the one's complement of the one's
\r
2117 * complement sum of all 16-bit words in the buffer.
\r
2121 * \param buf A pointer to the buffer over which the checksum is to be
\r
2124 * \param len The length of the buffer over which the checksum is to
\r
2127 * \return The Internet checksum of the buffer.
\r
2129 u16_t uip_chksum( u16_t *buf, u16_t len );
\r
2132 * Calculate the IP header checksum of the packet header in uip_buf.
\r
2134 * The IP header checksum is the Internet checksum of the 20 bytes of
\r
2137 * \return The IP header checksum of the IP header in the uip_buf
\r
2140 u16_t uip_ipchksum( void );
\r
2143 * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
\r
2145 * The TCP checksum is the Internet checksum of data contents of the
\r
2146 * TCP segment, and a pseudo-header as defined in RFC793.
\r
2148 * \return The TCP checksum of the TCP segment in uip_buf and pointed
\r
2149 * to by uip_appdata.
\r
2151 u16_t uip_tcpchksum( void );
\r
2154 * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
\r
2156 * The UDP checksum is the Internet checksum of data contents of the
\r
2157 * UDP segment, and a pseudo-header as defined in RFC768.
\r
2159 * \return The UDP checksum of the UDP segment in uip_buf and pointed
\r
2160 * to by uip_appdata.
\r
2162 u16_t uip_udpchksum( void );
\r
2165 * Calculate the ICMP checksum of the packet in uip_buf.
\r
2167 * \return The ICMP checksum of the ICMP packet in uip_buf
\r
2169 u16_t uip_icmp6chksum( void );
\r
2171 /* Events that can get posted to the uIP event queue. These are events
\r
2172 originating from the Ethernet interface or from a timer. */
\r
2173 #define uipETHERNET_RX_EVENT 0x01UL
\r
2174 #define uipETHERNET_TX_EVENT 0x02UL
\r
2175 #define uipARP_TIMER_EVENT 0x04UL
\r
2176 #define uipPERIODIC_TIMER_EVENT 0x08UL
\r
2177 #define uipAPPLICATION_SEND_EVENT 0x10UL
\r
2180 #endif /* __UIP_H__ */
\r