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
73 __packed /* The ARM compiler insists on this being packed, but with other compilers packing it generates a warning as it will be packed anyway. */
\r
76 typedef union uip_ip4addr_t
\r
78 u8_t u8[4]; /* Initializer, must come first!!! */
\r
81 typedef uip_ip4addr_t uip_ipaddr_t;
\r
82 #endif /* UIP_CONF_IPV6 */
\r
84 /*---------------------------------------------------------------------------*/
\r
86 /** \brief 16 bit 802.15.4 address */
\r
87 struct uip_802154_shortaddr
\r
92 /** \brief 64 bit 802.15.4 address */
\r
93 struct uip_802154_longaddr
\r
98 /** \brief 802.11 address */
\r
99 struct uip_80211_addr
\r
104 /** \brief 802.3 address */
\r
105 #include "net/pack_struct_start.h"
\r
106 struct uip_eth_addr
\r
110 #include "net/pack_struct_end.h"
\r
112 #ifdef UIP_CONF_LL_802154
\r
114 /** \brief 802.15.4 address */
\r
115 typedef struct uip_802154_longaddr uip_lladdr_t;
\r
116 #define UIP_802154_SHORTADDR_LEN 2
\r
117 #define UIP_802154_LONGADDR_LEN 8
\r
118 #define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN
\r
119 #else /*UIP_CONF_LL_802154*/
\r
120 #ifdef UIP_CONF_LL_80211
\r
121 /** \brief 802.11 address */
\r
122 typedef struct uip_80211_addr uip_lladdr_t;
\r
123 #define UIP_LLADDR_LEN 6
\r
124 #else /*UIP_CONF_LL_80211*/
\r
126 /** \brief Ethernet address */
\r
127 typedef struct uip_eth_addr uip_lladdr_t;
\r
129 #define UIP_LLADDR_LEN 6
\r
130 #endif /*UIP_CONF_LL_80211*/
\r
131 #endif /*UIP_CONF_LL_802154*/
\r
133 //_RB_#include "net/tcpip.h"
\r
135 /*---------------------------------------------------------------------------*/
\r
137 /* First, the functions that should be called from the
\r
138 * system. Initialization, the periodic timer, and incoming packets are
\r
139 * handled by the following three functions.
\r
143 * \defgroup uipconffunc uIP configuration functions
\r
146 * The uIP configuration functions are used for setting run-time
\r
147 * parameters in uIP such as IP addresses.
\r
151 * Set the IP address of this host.
\r
153 * The IP address is represented as a 4-byte array where the first
\r
154 * octet of the IP address is put in the first member of the 4-byte
\r
162 uip_ipaddr(&addr, 192,168,1,2);
\r
163 uip_sethostaddr(&addr);
\r
166 * \param addr A pointer to an IP address of type uip_ipaddr_t;
\r
172 #define uip_sethostaddr( addr ) uip_ipaddr_copy( &uip_hostaddr, (addr) )
\r
175 * Get the IP address of this host.
\r
177 * The IP address is represented as a 4-byte array where the first
\r
178 * octet of the IP address is put in the first member of the 4-byte
\r
183 uip_ipaddr_t hostaddr;
\r
185 uip_gethostaddr(&hostaddr);
\r
187 * \param addr A pointer to a uip_ipaddr_t variable that will be
\r
188 * filled in with the currently configured IP address.
\r
192 #define uip_gethostaddr( addr ) uip_ipaddr_copy( (addr), &uip_hostaddr )
\r
195 * Set the default router's IP address.
\r
197 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
\r
198 * address of the default router.
\r
204 #define uip_setdraddr( addr ) uip_ipaddr_copy( &uip_draddr, (addr) )
\r
209 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
\r
210 * address of the netmask.
\r
216 #define uip_setnetmask( addr ) uip_ipaddr_copy( &uip_netmask, (addr) )
\r
219 * Get the default router's IP address.
\r
221 * \param addr A pointer to a uip_ipaddr_t variable that will be
\r
222 * filled in with the IP address of the default router.
\r
226 #define uip_getdraddr( addr ) uip_ipaddr_copy( (addr), &uip_draddr )
\r
231 * \param addr A pointer to a uip_ipaddr_t variable that will be
\r
232 * filled in with the value of the netmask.
\r
236 #define uip_getnetmask( addr ) uip_ipaddr_copy( (addr), &uip_netmask )
\r
241 * \defgroup uipinit uIP initialization functions
\r
244 * The uIP initialization functions are used for booting uIP.
\r
248 * uIP initialization function.
\r
250 * This function should be called at boot up to initilize the uIP
\r
253 void uip_init( void );
\r
256 * uIP initialization function.
\r
258 * This function may be used at boot time to set the initial ip_id.
\r
260 void uip_setipid( u16_t id );
\r
265 * \defgroup uipdevfunc uIP device driver functions
\r
268 * These functions are used by a network device driver for interacting
\r
273 * Process an incoming packet.
\r
275 * This function should be called when the device driver has received
\r
276 * a packet from the network. The packet from the device driver must
\r
277 * be present in the uip_buf buffer, and the length of the packet
\r
278 * should be placed in the uip_len variable.
\r
280 * When the function returns, there may be an outbound packet placed
\r
281 * in the uip_buf packet buffer. If so, the uip_len variable is set to
\r
282 * the length of the packet. If no packet is to be sent out, the
\r
283 * uip_len variable is set to 0.
\r
285 * The usual way of calling the function is presented by the source
\r
288 uip_len = devicedriver_poll();
\r
292 devicedriver_send();
\r
297 * \note If you are writing a uIP device driver that needs ARP
\r
298 * (Address Resolution Protocol), e.g., when running uIP over
\r
299 * Ethernet, you will need to call the uIP ARP code before calling
\r
302 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
\r
303 uip_len = ethernet_devicedrver_poll();
\r
305 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
\r
310 ethernet_devicedriver_send();
\r
312 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
\r
315 ethernet_devicedriver_send();
\r
322 #define uip_input() uip_process( UIP_DATA )
\r
325 * Periodic processing for a connection identified by its number.
\r
327 * This function does the necessary periodic processing (timers,
\r
328 * polling) for a uIP TCP conneciton, and should be called when the
\r
329 * periodic uIP timer goes off. It should be called for every
\r
330 * connection, regardless of whether they are open of closed.
\r
332 * When the function returns, it may have an outbound packet waiting
\r
333 * for service in the uIP packet buffer, and if so the uip_len
\r
334 * variable is set to a value larger than zero. The device driver
\r
335 * should be called to send out the packet.
\r
337 * The usual way of calling the function is through a for() loop like
\r
340 for(i = 0; i < UIP_CONNS; ++i) {
\r
343 devicedriver_send();
\r
348 * \note If you are writing a uIP device driver that needs ARP
\r
349 * (Address Resolution Protocol), e.g., when running uIP over
\r
350 * Ethernet, you will need to call the uip_arp_out() function before
\r
351 * calling the device driver:
\r
353 for(i = 0; i < UIP_CONNS; ++i) {
\r
357 ethernet_devicedriver_send();
\r
362 * \param conn The number of the connection which is to be periodically polled.
\r
367 #define uip_periodic( conn ) \
\r
370 uip_conn = &uip_conns[conn]; \
\r
371 uip_process( UIP_TIMER ); \
\r
378 #define uip_conn_active( conn ) ( uip_conns[conn].tcpstateflags != UIP_CLOSED )
\r
381 * Perform periodic processing for a connection identified by a pointer
\r
382 * to its structure.
\r
384 * Same as uip_periodic() but takes a pointer to the actual uip_conn
\r
385 * struct instead of an integer as its argument. This function can be
\r
386 * used to force periodic processing of a specific connection.
\r
388 * \param conn A pointer to the uip_conn struct for the connection to
\r
393 #define uip_periodic_conn( conn ) \
\r
397 uip_process( UIP_TIMER ); \
\r
401 * Request that a particular connection should be polled.
\r
403 * Similar to uip_periodic_conn() but does not perform any timer
\r
404 * processing. The application is polled for new data.
\r
406 * \param conn A pointer to the uip_conn struct for the connection to
\r
411 #define uip_poll_conn( conn ) \
\r
415 uip_process( UIP_POLL_REQUEST ); \
\r
417 #endif /* UIP_TCP */
\r
422 * Periodic processing for a UDP connection identified by its number.
\r
424 * This function is essentially the same as uip_periodic(), but for
\r
425 * UDP connections. It is called in a similar fashion as the
\r
426 * uip_periodic() function:
\r
428 for(i = 0; i < UIP_UDP_CONNS; i++) {
\r
429 uip_udp_periodic(i);
\r
431 devicedriver_send();
\r
436 * \note As for the uip_periodic() function, special care has to be
\r
437 * taken when using uIP together with ARP and Ethernet:
\r
439 for(i = 0; i < UIP_UDP_CONNS; i++) {
\r
440 uip_udp_periodic(i);
\r
443 ethernet_devicedriver_send();
\r
448 * \param conn The number of the UDP connection to be processed.
\r
452 #define uip_udp_periodic( conn ) \
\r
455 uip_udp_conn = &uip_udp_conns[conn]; \
\r
456 uip_process( UIP_UDP_TIMER ); \
\r
460 * Periodic processing for a UDP connection identified by a pointer to
\r
463 * Same as uip_udp_periodic() but takes a pointer to the actual
\r
464 * uip_conn struct instead of an integer as its argument. This
\r
465 * function can be used to force periodic processing of a specific
\r
468 * \param conn A pointer to the uip_udp_conn struct for the connection
\r
473 #define uip_udp_periodic_conn( conn ) \
\r
476 uip_udp_conn = conn; \
\r
477 uip_process( UIP_UDP_TIMER ); \
\r
479 #endif /* UIP_UDP */
\r
481 /** \brief Abandon the reassembly of the current packet */
\r
482 void uip_reass_over( void );
\r
485 * The uIP packet buffer.
\r
487 * The uip_buf array is used to hold incoming and outgoing
\r
488 * packets. The device driver should place incoming data into this
\r
489 * buffer. When sending data, the device driver should read the link
\r
490 * level headers and the TCP/IP headers from this buffer. The size of
\r
491 * the link level headers is configured by the UIP_LLH_LEN define.
\r
493 * \note The application data need not be placed in this buffer, so
\r
494 * the device driver must read it from the place pointed to by the
\r
495 * uip_appdata pointer as illustrated by the following example:
\r
498 devicedriver_send(void)
\r
500 hwsend(&uip_buf[0], UIP_LLH_LEN);
\r
501 if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
\r
502 hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
\r
504 hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
\r
505 hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
\r
510 #ifndef UIP_CONF_EXTERNAL_BUFFER
\r
511 CCIF extern u8_t uip_buf[UIP_BUFSIZE + 2];
\r
513 CCIF extern unsigned char *uip_buf;
\r
518 /*---------------------------------------------------------------------------*/
\r
520 /* Functions that are used by the uIP application program. Opening and
\r
521 * closing connections, sending and receiving data, etc. is all
\r
522 * handled by the functions below.
\r
526 * \defgroup uipappfunc uIP application functions
\r
529 * Functions used by an application running of top of uIP.
\r
533 * Start listening to the specified port.
\r
535 * \note Since this function expects the port number in network byte
\r
536 * order, a conversion using HTONS() or htons() is necessary.
\r
539 uip_listen(HTONS(80));
\r
542 * \param port A 16-bit port number in network byte order.
\r
544 void uip_listen( u16_t port );
\r
547 * Stop listening to the specified port.
\r
549 * \note Since this function expects the port number in network byte
\r
550 * order, a conversion using HTONS() or htons() is necessary.
\r
553 uip_unlisten(HTONS(80));
\r
556 * \param port A 16-bit port number in network byte order.
\r
558 void uip_unlisten( u16_t port );
\r
561 * Connect to a remote host using TCP.
\r
563 * This function is used to start a new connection to the specified
\r
564 * port on the specified host. It allocates a new connection identifier,
\r
565 * sets the connection to the SYN_SENT state and sets the
\r
566 * retransmission timer to 0. This will cause a TCP SYN segment to be
\r
567 * sent out the next time this connection is periodically processed,
\r
568 * which usually is done within 0.5 seconds after the call to
\r
571 * \note This function is available only if support for active open
\r
572 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
\r
574 * \note Since this function requires the port number to be in network
\r
575 * byte order, a conversion using HTONS() or htons() is necessary.
\r
578 uip_ipaddr_t ipaddr;
\r
580 uip_ipaddr(&ipaddr, 192,168,1,2);
\r
581 uip_connect(&ipaddr, HTONS(80));
\r
584 * \param ripaddr The IP address of the remote host.
\r
586 * \param port A 16-bit port number in network byte order.
\r
588 * \return A pointer to the uIP connection identifier for the new connection,
\r
589 * or NULL if no connection could be allocated.
\r
592 struct uip_conn *uip_connect( uip_ipaddr_t *ripaddr, u16_t port );
\r
597 * Check if a connection has outstanding (i.e., unacknowledged) data.
\r
599 * \param conn A pointer to the uip_conn structure for the connection.
\r
603 #define uip_outstanding( conn ) ( (conn)->len )
\r
606 * Send data on the current connection.
\r
608 * This function is used to send out a single segment of TCP
\r
609 * data. Only applications that have been invoked by uIP for event
\r
610 * processing can send data.
\r
612 * The amount of data that actually is sent out after a call to this
\r
613 * function is determined by the maximum amount of data TCP allows. uIP
\r
614 * will automatically crop the data so that only the appropriate
\r
615 * amount of data is sent. The function uip_mss() can be used to query
\r
616 * uIP for the amount of data that actually will be sent.
\r
618 * \note This function does not guarantee that the sent data will
\r
619 * arrive at the destination. If the data is lost in the network, the
\r
620 * application will be invoked with the uip_rexmit() event being
\r
621 * set. The application will then have to resend the data using this
\r
624 * \param data A pointer to the data which is to be sent.
\r
626 * \param len The maximum amount of data bytes to be sent.
\r
630 CCIF void uip_send( const void *data, int len );
\r
633 * The length of any incoming data that is currently available (if available)
\r
634 * in the uip_appdata buffer.
\r
636 * The test function uip_data() must first be used to check if there
\r
637 * is any data available at all.
\r
642 /*void uip_datalen(void);*/
\r
643 #define uip_datalen() uip_len
\r
646 * The length of any out-of-band data (urgent data) that has arrived
\r
647 * on the connection.
\r
649 * \note The configuration parameter UIP_URGDATA must be set for this
\r
650 * function to be enabled.
\r
654 #define uip_urgdatalen() uip_urglen
\r
657 * Close the current connection.
\r
659 * This function will close the current connection in a nice way.
\r
663 #define uip_close() ( uip_flags = UIP_CLOSE )
\r
666 * Abort the current connection.
\r
668 * This function will abort (reset) the current connection, and is
\r
669 * usually used when an error has occurred that prevents using the
\r
670 * uip_close() function.
\r
674 #define uip_abort() ( uip_flags = UIP_ABORT )
\r
677 * Tell the sending host to stop sending data.
\r
679 * This function will close our receiver's window so that we stop
\r
680 * receiving data for the current connection.
\r
684 #define uip_stop() ( uip_conn->tcpstateflags |= UIP_STOPPED )
\r
687 * Find out if the current connection has been previously stopped with
\r
692 #define uip_stopped( conn ) ( (conn)->tcpstateflags & UIP_STOPPED )
\r
695 * Restart the current connection, if is has previously been stopped
\r
698 * This function will open the receiver's window again so that we
\r
699 * start receiving data for the current connection.
\r
703 #define uip_restart() \
\r
706 uip_flags |= UIP_NEWDATA; \
\r
707 uip_conn->tcpstateflags &= ~UIP_STOPPED; \
\r
710 /* uIP tests that can be made to determine in what state the current
\r
711 connection is, and what the application function should do. */
\r
714 * Is the current connection a UDP connection?
\r
716 * This function checks whether the current connection is a UDP connection.
\r
721 #define uip_udpconnection() ( uip_conn == NULL )
\r
724 * Is new incoming data available?
\r
726 * Will reduce to non-zero if there is new data for the application
\r
727 * present at the uip_appdata pointer. The size of the data is
\r
728 * available through the uip_len variable.
\r
732 #define uip_newdata() ( uip_flags & UIP_NEWDATA )
\r
735 * Has previously sent data been acknowledged?
\r
737 * Will reduce to non-zero if the previously sent data has been
\r
738 * acknowledged by the remote host. This means that the application
\r
739 * can send new data.
\r
743 #define uip_acked() ( uip_flags & UIP_ACKDATA )
\r
746 * Has the connection just been connected?
\r
748 * Reduces to non-zero if the current connection has been connected to
\r
749 * a remote host. This will happen both if the connection has been
\r
750 * actively opened (with uip_connect()) or passively opened (with
\r
755 #define uip_connected() ( uip_flags & UIP_CONNECTED )
\r
758 * Has the connection been closed by the other end?
\r
760 * Is non-zero if the connection has been closed by the remote
\r
761 * host. The application may then do the necessary clean-ups.
\r
765 #define uip_closed() ( uip_flags & UIP_CLOSE )
\r
768 * Has the connection been aborted by the other end?
\r
770 * Non-zero if the current connection has been aborted (reset) by the
\r
775 #define uip_aborted() ( uip_flags & UIP_ABORT )
\r
778 * Has the connection timed out?
\r
780 * Non-zero if the current connection has been aborted due to too many
\r
785 #define uip_timedout() ( uip_flags & UIP_TIMEDOUT )
\r
788 * Do we need to retransmit previously data?
\r
790 * Reduces to non-zero if the previously sent data has been lost in
\r
791 * the network, and the application should retransmit it. The
\r
792 * application should send the exact same data as it did the last
\r
793 * time, using the uip_send() function.
\r
797 #define uip_rexmit() ( uip_flags & UIP_REXMIT )
\r
800 * Is the connection being polled by uIP?
\r
802 * Is non-zero if the reason the application is invoked is that the
\r
803 * current connection has been idle for a while and should be
\r
806 * The polling event can be used for sending data without having to
\r
807 * wait for the remote host to send data.
\r
811 #define uip_poll() ( uip_flags & UIP_POLL )
\r
814 * Get the initial maximum segment size (MSS) of the current
\r
819 #define uip_initialmss() ( uip_conn->initialmss )
\r
822 * Get the current maximum segment size that can be sent on the current
\r
825 * The current maximum segment size that can be sent on the
\r
826 * connection is computed from the receiver's window and the MSS of
\r
827 * the connection (which also is available by calling
\r
828 * uip_initialmss()).
\r
832 #define uip_mss() ( uip_conn->mss )
\r
834 * Set up a new UDP connection.
\r
836 * This function sets up a new UDP connection. The function will
\r
837 * automatically allocate an unused local port for the new
\r
838 * connection. However, another port can be chosen by using the
\r
839 * uip_udp_bind() call, after the uip_udp_new() function has been
\r
845 struct uip_udp_conn *c;
\r
847 uip_ipaddr(&addr, 192,168,2,1);
\r
848 c = uip_udp_new(&addr, HTONS(12345));
\r
850 uip_udp_bind(c, HTONS(12344));
\r
853 * \param ripaddr The IP address of the remote host.
\r
855 * \param rport The remote port number in network byte order.
\r
857 * \return The uip_udp_conn structure for the new connection or NULL
\r
858 * if no connection could be allocated.
\r
860 struct uip_udp_conn *uip_udp_new( const uip_ipaddr_t *ripaddr, u16_t rport );
\r
863 * Removed a UDP connection.
\r
865 * \param conn A pointer to the uip_udp_conn structure for the connection.
\r
869 #define uip_udp_remove( conn ) ( conn )->lport = 0
\r
872 * Bind a UDP connection to a local port.
\r
874 * \param conn A pointer to the uip_udp_conn structure for the
\r
877 * \param port The local port number, in network byte order.
\r
881 #define uip_udp_bind( conn, port ) ( conn )->lport = port
\r
884 * Send a UDP datagram of length len on the current connection.
\r
886 * This function can only be called in response to a UDP event (poll
\r
887 * or newdata). The data must be present in the uip_buf buffer, at the
\r
888 * place pointed to by the uip_appdata pointer.
\r
890 * \param len The length of the data in the uip_buf buffer.
\r
894 #define uip_udp_send( len ) uip_send( ( char * ) uip_appdata, len )
\r
898 /* uIP convenience and converting functions. */
\r
901 * \defgroup uipconvfunc uIP conversion functions
\r
904 * These functions can be used for converting between different data
\r
905 * formats used by uIP.
\r
909 * Convert an IP address to four bytes separated by commas.
\r
913 uip_ipaddr_t ipaddr;
\r
914 printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr));
\r
917 * \param a A pointer to a uip_ipaddr_t.
\r
920 #define uip_ipaddr_to_quad( a ) ( a )->u8[0], ( a )->u8[1], ( a )->u8[2], ( a )->u8[3]
\r
923 * Construct an IP address from four bytes.
\r
925 * This function constructs an IP address of the type that uIP handles
\r
926 * internally from four bytes. The function is handy for specifying IP
\r
927 * addresses to use with e.g. the uip_connect() function.
\r
931 uip_ipaddr_t ipaddr;
\r
932 struct uip_conn *c;
\r
934 uip_ipaddr(&ipaddr, 192,168,1,2);
\r
935 c = uip_connect(&ipaddr, HTONS(80));
\r
938 * \param addr A pointer to a uip_ipaddr_t variable that will be
\r
939 * filled in with the IP address.
\r
941 * \param addr0 The first octet of the IP address.
\r
942 * \param addr1 The second octet of the IP address.
\r
943 * \param addr2 The third octet of the IP address.
\r
944 * \param addr3 The forth octet of the IP address.
\r
948 #define uip_ipaddr( addr, addr0, addr1, addr2, addr3 ) \
\r
951 ( addr )->u8[0] = addr0; \
\r
952 ( addr )->u8[1] = addr1; \
\r
953 ( addr )->u8[2] = addr2; \
\r
954 ( addr )->u8[3] = addr3; \
\r
958 * Construct an IPv6 address from eight 16-bit words.
\r
960 * This function constructs an IPv6 address.
\r
964 #define uip_ip6addr( addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7 ) \
\r
967 ( addr )->u16[0] = HTONS( addr0 ); \
\r
968 ( addr )->u16[1] = HTONS( addr1 ); \
\r
969 ( addr )->u16[2] = HTONS( addr2 ); \
\r
970 ( addr )->u16[3] = HTONS( addr3 ); \
\r
971 ( addr )->u16[4] = HTONS( addr4 ); \
\r
972 ( addr )->u16[5] = HTONS( addr5 ); \
\r
973 ( addr )->u16[6] = HTONS( addr6 ); \
\r
974 ( addr )->u16[7] = HTONS( addr7 ); \
\r
976 * Construct an IPv6 address from eight 8-bit words.
\r
978 * This function constructs an IPv6 address.
\r
982 #define uip_ip6addr_u8 ( addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8, addr9, addr10, addr11, addr12, addr13, addr14, \
\r
985 ( addr )->u8[0] = addr0; \
\r
986 ( addr )->u8[1] = addr1; \
\r
987 ( addr )->u8[2] = addr2; \
\r
988 ( addr )->u8[3] = addr3; \
\r
989 ( addr )->u8[4] = addr4; \
\r
990 ( addr )->u8[5] = addr5; \
\r
991 ( addr )->u8[6] = addr6; \
\r
992 ( addr )->u8[7] = addr7; \
\r
993 ( addr )->u8[8] = addr8; \
\r
994 ( addr )->u8[9] = addr9; \
\r
995 ( addr )->u8[10] = addr10; \
\r
996 ( addr )->u8[11] = addr11; \
\r
997 ( addr )->u8[12] = addr12; \
\r
998 ( addr )->u8[13] = addr13; \
\r
999 ( addr )->u8[14] = addr14; \
\r
1000 ( addr )->u8[15] = addr15; \
\r
1003 * Copy an IP address to another IP address.
\r
1005 * Copies an IP address from one place to another.
\r
1009 uip_ipaddr_t ipaddr1, ipaddr2;
\r
1011 uip_ipaddr(&ipaddr1, 192,16,1,2);
\r
1012 uip_ipaddr_copy(&ipaddr2, &ipaddr1);
\r
1015 * \param dest The destination for the copy.
\r
1016 * \param src The source from where to copy.
\r
1018 * \hideinitializer
\r
1020 #ifndef uip_ipaddr_copy
\r
1021 #define uip_ipaddr_copy( dest, src ) \
\r
1024 (dest)->u8[0] = (src)->u8[0]; \
\r
1025 (dest)->u8[1] = (src)->u8[1]; \
\r
1026 (dest)->u8[2] = (src)->u8[2]; \
\r
1027 (dest)->u8[3] = (src)->u8[3]; \
\r
1032 * Compare two IP addresses
\r
1034 * Compares two IP addresses.
\r
1038 uip_ipaddr_t ipaddr1, ipaddr2;
\r
1040 uip_ipaddr(&ipaddr1, 192,16,1,2);
\r
1041 if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
\r
1042 printf("They are the same");
\r
1046 * \param addr1 The first IP address.
\r
1047 * \param addr2 The second IP address.
\r
1049 * \hideinitializer
\r
1051 #if !UIP_CONF_IPV6
\r
1052 #define uip_ipaddr_cmp( addr1, addr2 ) ( (addr1)->u16[0] == (addr2)->u16[0] && (addr1)->u16[1] == (addr2)->u16[1] )
\r
1053 #else /* !UIP_CONF_IPV6 */
\r
1054 #define uip_ipaddr_cmp( addr1, addr2 ) ( memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0 )
\r
1055 #endif /* !UIP_CONF_IPV6 */
\r
1058 * Compare two IP addresses with netmasks
\r
1060 * Compares two IP addresses with netmasks. The masks are used to mask
\r
1061 * out the bits that are to be compared.
\r
1065 uip_ipaddr_t ipaddr1, ipaddr2, mask;
\r
1067 uip_ipaddr(&mask, 255,255,255,0);
\r
1068 uip_ipaddr(&ipaddr1, 192,16,1,2);
\r
1069 uip_ipaddr(&ipaddr2, 192,16,1,3);
\r
1070 if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
\r
1071 printf("They are the same");
\r
1075 * \param addr1 The first IP address.
\r
1076 * \param addr2 The second IP address.
\r
1077 * \param mask The netmask.
\r
1079 * \hideinitializer
\r
1081 #if !UIP_CONF_IPV6
\r
1082 #define uip_ipaddr_maskcmp( addr1, addr2, mask ) \
\r
1084 (((( u16_t * ) addr1)[0] & (( u16_t * ) mask)[0]) == ((( u16_t * ) addr2)[0] & (( u16_t * ) mask)[0])) && \
\r
1085 (((( u16_t * ) addr1)[1] & (( u16_t * ) mask)[1]) == ((( u16_t * ) addr2)[1] & (( u16_t * ) mask)[1])) \
\r
1088 #define uip_ipaddr_prefixcmp( addr1, addr2, length ) ( memcmp(addr1, addr2, length >> 3) == 0 )
\r
1092 * Check if an address is a broadcast address for a network.
\r
1094 * Checks if an address is the broadcast address for a network. The
\r
1095 * network is defined by an IP address that is on the network and the
\r
1096 * network's netmask.
\r
1098 * \param addr The IP address.
\r
1099 * \param netaddr The network's IP address.
\r
1100 * \param netmask The network's netmask.
\r
1102 * \hideinitializer
\r
1105 /*#define uip_ipaddr_isbroadcast(addr, netaddr, netmask)
\r
1106 ((uip_ipaddr_t *)(addr)).u16 & ((uip_ipaddr_t *)(addr)).u16*/
\r
1109 * Mask out the network part of an IP address.
\r
1111 * Masks out the network part of an IP address, given the address and
\r
1116 uip_ipaddr_t ipaddr1, ipaddr2, netmask;
\r
1118 uip_ipaddr(&ipaddr1, 192,16,1,2);
\r
1119 uip_ipaddr(&netmask, 255,255,255,0);
\r
1120 uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
\r
1123 * In the example above, the variable "ipaddr2" will contain the IP
\r
1124 * address 192.168.1.0.
\r
1126 * \param dest Where the result is to be placed.
\r
1127 * \param src The IP address.
\r
1128 * \param mask The netmask.
\r
1130 * \hideinitializer
\r
1132 #define uip_ipaddr_mask( dest, src, mask ) \
\r
1135 ( ( u16_t * ) dest )[0] = ( ( u16_t * ) src )[0] & ( ( u16_t * ) mask )[0]; \
\r
1136 ( ( u16_t * ) dest )[1] = ( ( u16_t * ) src )[1] & ( ( u16_t * ) mask )[1]; \
\r
1140 * Pick the first octet of an IP address.
\r
1142 * Picks out the first octet of an IP address.
\r
1146 uip_ipaddr_t ipaddr;
\r
1149 uip_ipaddr(&ipaddr, 1,2,3,4);
\r
1150 octet = uip_ipaddr1(&ipaddr);
\r
1153 * In the example above, the variable "octet" will contain the value 1.
\r
1155 * \hideinitializer
\r
1157 #define uip_ipaddr1( addr ) ( (addr)->u8[0] )
\r
1160 * Pick the second octet of an IP address.
\r
1162 * Picks out the second octet of an IP address.
\r
1166 uip_ipaddr_t ipaddr;
\r
1169 uip_ipaddr(&ipaddr, 1,2,3,4);
\r
1170 octet = uip_ipaddr2(&ipaddr);
\r
1173 * In the example above, the variable "octet" will contain the value 2.
\r
1175 * \hideinitializer
\r
1177 #define uip_ipaddr2( addr ) ( (addr)->u8[1] )
\r
1180 * Pick the third octet of an IP address.
\r
1182 * Picks out the third octet of an IP address.
\r
1186 uip_ipaddr_t ipaddr;
\r
1189 uip_ipaddr(&ipaddr, 1,2,3,4);
\r
1190 octet = uip_ipaddr3(&ipaddr);
\r
1193 * In the example above, the variable "octet" will contain the value 3.
\r
1195 * \hideinitializer
\r
1197 #define uip_ipaddr3( addr ) ( (addr)->u8[2] )
\r
1200 * Pick the fourth octet of an IP address.
\r
1202 * Picks out the fourth octet of an IP address.
\r
1206 uip_ipaddr_t ipaddr;
\r
1209 uip_ipaddr(&ipaddr, 1,2,3,4);
\r
1210 octet = uip_ipaddr4(&ipaddr);
\r
1213 * In the example above, the variable "octet" will contain the value 4.
\r
1215 * \hideinitializer
\r
1217 #define uip_ipaddr4( addr ) ( (addr)->u8[3] )
\r
1219 * Convert 16-bit quantity from host byte order to network byte order.
\r
1221 * This macro is primarily used for converting constants from host
\r
1222 * byte order to network byte order. For converting variables to
\r
1223 * network byte order, use the htons() function instead.
\r
1225 * \hideinitializer
\r
1228 #if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
\r
1229 #define HTONS( n ) ( n )
\r
1230 #define HTONL( n ) ( n )
\r
1231 #else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
\r
1232 #define HTONS( n ) ( u16_t ) ( (((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8) )
\r
1233 #define HTONL( n ) ( ((u32_t) HTONS(n) << 16) | HTONS((u32_t) (n) >> 16) )
\r
1234 #endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
\r
1236 #error "HTONS already defined!"
\r
1237 #endif /* HTONS */
\r
1240 * Convert 16-bit quantity from host byte order to network byte order.
\r
1242 * This function is primarily used for converting variables from host
\r
1243 * byte order to network byte order. For converting constants to
\r
1244 * network byte order, use the HTONS() macro instead.
\r
1247 CCIF u16_t htons( u16_t val );
\r
1248 #endif /* htons */
\r
1251 #define ntohs htons
\r
1255 CCIF u32_t htonl( u32_t val );
\r
1256 #endif /* htonl */
\r
1259 #define ntohl htonl
\r
1265 * Pointer to the application data in the packet buffer.
\r
1267 * This pointer points to the application data when the application is
\r
1268 * called. If the application wishes to send data, the application may
\r
1269 * use this space to write the data into before calling uip_send().
\r
1271 CCIF extern void *uip_appdata;
\r
1273 #if UIP_URGDATA > 0
\r
1275 /* u8_t *uip_urgdata:
\r
1277 * This pointer points to any urgent data that has been received. Only
\r
1278 * present if compiled with support for urgent data (UIP_URGDATA).
\r
1280 extern void *uip_urgdata;
\r
1281 #endif /* UIP_URGDATA > 0 */
\r
1284 * \defgroup uipdrivervars Variables used in uIP device drivers
\r
1287 * uIP has a few global variables that are used in device drivers for
\r
1292 * The length of the packet in the uip_buf buffer.
\r
1294 * The global variable uip_len holds the length of the packet in the
\r
1297 * When the network device driver calls the uIP input function,
\r
1298 * uip_len should be set to the length of the packet in the uip_buf
\r
1301 * When sending packets, the device driver should use the contents of
\r
1302 * the uip_len variable to determine the length of the outgoing
\r
1306 CCIF extern u16_t uip_len;
\r
1309 * The length of the extension headers
\r
1311 extern u8_t uip_ext_len;
\r
1314 #if UIP_URGDATA > 0
\r
1315 extern u16_t uip_urglen, uip_surglen;
\r
1316 #endif /* UIP_URGDATA > 0 */
\r
1319 * Representation of a uIP TCP connection.
\r
1321 * The uip_conn structure is used for identifying a connection. All
\r
1322 * but one field in the structure are to be considered read-only by an
\r
1323 * application. The only exception is the appstate field whose purpose
\r
1324 * is to let the application store application-specific state (e.g.,
\r
1325 * file pointers) for the connection. The type of this field is
\r
1326 * configured in the "uipopt.h" header file.
\r
1330 uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */
\r
1332 u16_t lport; /**< The local TCP port, in network byte order. */
\r
1333 u16_t rport; /**< The local remote TCP port, in network byte
\r
1336 u8_t rcv_nxt[4]; /**< The sequence number that we expect to
\r
1338 u8_t snd_nxt[4]; /**< The sequence number that was last sent by
\r
1340 u16_t len; /**< Length of the data that was previously sent. */
\r
1341 u16_t mss; /**< Current maximum segment size for the
\r
1343 u16_t initialmss; /**< Initial maximum segment size for the
\r
1345 u8_t sa; /**< Retransmission time-out calculation state
\r
1347 u8_t sv; /**< Retransmission time-out calculation state
\r
1349 u8_t rto; /**< Retransmission time-out. */
\r
1350 u8_t tcpstateflags; /**< TCP state and flags. */
\r
1351 u8_t timer; /**< The retransmission timer. */
\r
1352 u8_t nrtx; /**< The number of retransmissions for the last
\r
1355 /** The application state. */
\r
1356 uip_tcp_appstate_t appstate;
\r
1360 * Pointer to the current TCP connection.
\r
1362 * The uip_conn pointer can be used to access the current TCP
\r
1365 CCIF extern struct uip_conn *uip_conn;
\r
1368 /* The array containing all uIP connections. */
\r
1369 CCIF extern struct uip_conn uip_conns[UIP_CONNS];
\r
1373 * \addtogroup uiparch
\r
1378 * 4-byte array used for the 32-bit sequence number calculations.
\r
1380 extern u8_t uip_acc32[4];
\r
1385 * Representation of a uIP UDP connection.
\r
1387 struct uip_udp_conn
\r
1389 uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */
\r
1390 u16_t lport; /**< The local port number in network byte order. */
\r
1391 u16_t rport; /**< The remote port number in network byte order. */
\r
1392 u8_t ttl; /**< Default time-to-live. */
\r
1394 /** The application state. */
\r
1395 uip_udp_appstate_t appstate;
\r
1399 * The current UDP connection.
\r
1401 extern struct uip_udp_conn *uip_udp_conn;
\r
1402 extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
\r
1403 #endif /* UIP_UDP */
\r
1407 int ( *activate ) ( void );
\r
1408 int ( *deactivate ) ( void );
\r
1409 uip_ipaddr_t * ( *lookup ) ( uip_ipaddr_t *destipaddr, uip_ipaddr_t *nexthop );
\r
1412 #ifdef UIP_CONF_ROUTER
\r
1413 extern const struct uip_router *uip_router;
\r
1416 * uIP routing driver registration function.
\r
1418 void uip_router_register( const struct uip_router *router );
\r
1419 #endif /*UIP_CONF_ROUTER*/
\r
1421 #ifdef UIP_CONF_ICMP6
\r
1422 struct uip_icmp6_conn
\r
1424 uip_icmp6_appstate_t appstate;
\r
1426 extern struct uip_icmp6_conn uip_icmp6_conns;
\r
1427 #endif /*UIP_CONF_ICMP6*/
\r
1430 * The uIP TCP/IP statistics.
\r
1432 * This is the variable in which the uIP TCP/IP statistics are gathered.
\r
1434 #if UIP_STATISTICS == 1
\r
1435 extern struct uip_stats uip_stat;
\r
1436 #define UIP_STAT( s ) s
\r
1438 #define UIP_STAT( s )
\r
1439 #endif /* UIP_STATISTICS == 1 */
\r
1442 * The structure holding the TCP/IP statistics that are gathered if
\r
1443 * UIP_STATISTICS is set to 1.
\r
1450 uip_stats_t recv; /**< Number of received packets at the IP
\r
1452 uip_stats_t sent; /**< Number of sent packets at the IP
\r
1454 uip_stats_t forwarded; /**< Number of forwarded packets at the IP
\r
1456 uip_stats_t drop; /**< Number of dropped packets at the IP
\r
1458 uip_stats_t vhlerr; /**< Number of packets dropped due to wrong
\r
1459 IP version or header length. */
\r
1460 uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
\r
1461 IP length, high byte. */
\r
1462 uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
\r
1463 IP length, low byte. */
\r
1464 uip_stats_t fragerr; /**< Number of packets dropped since they
\r
1465 were IP fragments. */
\r
1466 uip_stats_t chkerr; /**< Number of packets dropped due to IP
\r
1467 checksum errors. */
\r
1468 uip_stats_t protoerr; /**< Number of packets dropped since they
\r
1469 were neither ICMP, UDP nor TCP. */
\r
1470 } ip; /**< IP statistics. */
\r
1473 uip_stats_t recv; /**< Number of received ICMP packets. */
\r
1474 uip_stats_t sent; /**< Number of sent ICMP packets. */
\r
1475 uip_stats_t drop; /**< Number of dropped ICMP packets. */
\r
1476 uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
\r
1478 uip_stats_t chkerr; /**< Number of ICMP packets with a bad
\r
1480 } icmp; /**< ICMP statistics. */
\r
1484 uip_stats_t recv; /**< Number of recived TCP segments. */
\r
1485 uip_stats_t sent; /**< Number of sent TCP segments. */
\r
1486 uip_stats_t drop; /**< Number of dropped TCP segments. */
\r
1487 uip_stats_t chkerr; /**< Number of TCP segments with a bad
\r
1489 uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK
\r
1491 uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */
\r
1492 uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */
\r
1493 uip_stats_t syndrop; /**< Number of dropped SYNs due to too few
\r
1494 connections was avaliable. */
\r
1495 uip_stats_t synrst; /**< Number of SYNs for closed ports,
\r
1496 triggering a RST. */
\r
1497 } tcp; /**< TCP statistics. */
\r
1502 uip_stats_t drop; /**< Number of dropped UDP segments. */
\r
1503 uip_stats_t recv; /**< Number of recived UDP segments. */
\r
1504 uip_stats_t sent; /**< Number of sent UDP segments. */
\r
1505 uip_stats_t chkerr; /**< Number of UDP segments with a bad
\r
1507 } udp; /**< UDP statistics. */
\r
1508 #endif /* UIP_UDP */
\r
1509 #if UIP_CONF_IPV6 != 0
\r
1512 uip_stats_t drop; /**< Number of dropped ND6 packets. */
\r
1513 uip_stats_t recv; /**< Number of recived ND6 packets */
\r
1514 uip_stats_t sent; /**< Number of sent ND6 packets */
\r
1516 #endif /*UIP_CONF_IPV6*/
\r
1519 /*---------------------------------------------------------------------------*/
\r
1521 /* All the stuff below this point is internal to uIP and should not be
\r
1522 * used directly by an application or by a device driver.
\r
1525 /*---------------------------------------------------------------------------*/
\r
1527 /* u8_t uip_flags:
\r
1529 * When the application is called, uip_flags will contain the flags
\r
1530 * that are defined in this file. Please read below for more
\r
1533 CCIF extern u8_t uip_flags;
\r
1535 /* The following flags may be set in the global variable uip_flags
\r
1536 before calling the application callback. The UIP_ACKDATA,
\r
1537 UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
\r
1538 whereas the others are mutually exclusive. Note that these flags
\r
1539 should *NOT* be accessed directly, but only through the uIP
\r
1540 functions/macros. */
\r
1541 #define UIP_ACKDATA 1 /* Signifies that the outstanding data was
\r
1542 acked and the application should send
\r
1543 out new data instead of retransmitting
\r
1545 #define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
\r
1547 #define UIP_REXMIT 4 /* Tells the application to retransmit the
\r
1548 data that was last sent. */
\r
1549 #define UIP_POLL 8 /* Used for polling the application, to
\r
1550 check if the application has data that
\r
1551 it wants to send. */
\r
1552 #define UIP_CLOSE 16 /* The remote host has closed the
\r
1553 connection, thus the connection has
\r
1554 gone away. Or the application signals
\r
1555 that it wants to close the
\r
1557 #define UIP_ABORT 32 /* The remote host has aborted the
\r
1558 connection, thus the connection has
\r
1559 gone away. Or the application signals
\r
1560 that it wants to abort the
\r
1562 #define UIP_CONNECTED 64 /* We have got a connection from a remote
\r
1563 host and have set up a new connection
\r
1564 for it, or an active connection has
\r
1565 been successfully established. */
\r
1567 #define UIP_TIMEDOUT 128 /* The connection has been aborted due to
\r
1568 too many retransmissions. */
\r
1571 * \brief process the options within a hop by hop or destination option header
\r
1572 * \retval 0: nothing to send,
\r
1573 * \retval 1: drop pkt
\r
1574 * \retval 2: ICMP error message to send
\r
1578 uip_ext_hdr_options_process(); */
\r
1580 /* uip_process(flag):
\r
1582 * The actual uIP function which does all the work.
\r
1584 void uip_process( u8_t flag );
\r
1586 /* The following flags are passed as an argument to the uip_process()
\r
1587 function. They are used to distinguish between the two cases where
\r
1588 uip_process() is called. It can be called either because we have
\r
1589 incoming data that should be processed, or because the periodic
\r
1590 timer has fired. These values are never used directly, but only in
\r
1591 the macros defined in this file. */
\r
1592 #define UIP_DATA 1 /* Tells uIP that there is incoming
\r
1593 data in the uip_buf buffer. The
\r
1594 length of the data is stored in the
\r
1595 global variable uip_len. */
\r
1596 #define UIP_TIMER 2 /* Tells uIP that the periodic timer
\r
1598 #define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should
\r
1600 #define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram
\r
1601 should be constructed in the
\r
1602 uip_buf buffer. */
\r
1604 #define UIP_UDP_TIMER 5
\r
1605 #endif /* UIP_UDP */
\r
1607 /* The TCP states used in the uip_conn->tcpstateflags. */
\r
1608 #define UIP_CLOSED 0
\r
1609 #define UIP_SYN_RCVD 1
\r
1610 #define UIP_SYN_SENT 2
\r
1611 #define UIP_ESTABLISHED 3
\r
1612 #define UIP_FIN_WAIT_1 4
\r
1613 #define UIP_FIN_WAIT_2 5
\r
1614 #define UIP_CLOSING 6
\r
1615 #define UIP_TIME_WAIT 7
\r
1616 #define UIP_LAST_ACK 8
\r
1617 #define UIP_TS_MASK 15
\r
1619 #define UIP_STOPPED 16
\r
1621 /* The TCP and IP headers. */
\r
1622 #include "net/pack_struct_start.h"
\r
1623 struct uip_tcpip_hdr
\r
1625 #if UIP_CONF_IPV6 != 0
\r
1626 /* IPv6 header. */
\r
1631 uip_ip6addr_t srcipaddr, destipaddr;
\r
1632 #else /* UIP_CONF_IPV6 */
\r
1633 /* IPv4 header. */
\r
1634 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
\r
1636 uip_ipaddr_t srcipaddr, destipaddr;
\r
1637 #endif /* UIP_CONF_IPV6 */
\r
1640 u16_t srcport, destport;
\r
1641 u8_t seqno[4], ackno[4], tcpoffset, flags, wnd[2];
\r
1646 #include "net/pack_struct_end.h"
\r
1648 /* The ICMP and IP headers. */
\r
1649 #include "net/pack_struct_start.h"
\r
1650 struct uip_icmpip_hdr
\r
1652 #if UIP_CONF_IPV6 != 0
\r
1653 /* IPv6 header. */
\r
1658 uip_ip6addr_t srcipaddr, destipaddr;
\r
1659 #else /* UIP_CONF_IPV6 */
\r
1660 /* IPv4 header. */
\r
1661 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
\r
1663 uip_ipaddr_t srcipaddr, destipaddr;
\r
1664 #endif /* UIP_CONF_IPV6 */
\r
1666 /* ICMP header. */
\r
1669 #if !UIP_CONF_IPV6
\r
1672 #endif /* !UIP_CONF_IPV6 */
\r
1675 #include "net/pack_struct_end.h"
\r
1677 /* The UDP and IP headers. */
\r
1678 #include "net/pack_struct_start.h"
\r
1679 struct uip_udpip_hdr
\r
1681 #if UIP_CONF_IPV6 != 0
\r
1682 /* IPv6 header. */
\r
1687 uip_ip6addr_t srcipaddr, destipaddr;
\r
1688 #else /* UIP_CONF_IPV6 */
\r
1690 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
\r
1692 uip_ipaddr_t srcipaddr, destipaddr;
\r
1693 #endif /* UIP_CONF_IPV6 */
\r
1696 u16_t srcport, destport;
\r
1701 #include "net/pack_struct_end.h"
\r
1704 * In IPv6 the length of the L3 headers before the transport header is
\r
1705 * not fixed, due to the possibility to include extension option headers
\r
1706 * after the IP header. hence we split here L3 and L4 headers
\r
1709 /* The IP header */
\r
1712 #if UIP_CONF_IPV6 != 0
\r
1719 uip_ip6addr_t srcipaddr, destipaddr;
\r
1720 #else /* UIP_CONF_IPV6 */
\r
1722 u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
\r
1724 uip_ipaddr_t srcipaddr, destipaddr;
\r
1725 #endif /* UIP_CONF_IPV6 */
\r
1729 * IPv6 extension option headers: we are able to process
\r
1730 * the 4 extension headers defined in RFC2460 (IPv6):
\r
1731 * - Hop by hop option header, destination option header:
\r
1732 * These two are not used by any core IPv6 protocol, hence
\r
1733 * we just read them and go to the next. They convey options,
\r
1734 * the options defined in RFC2460 are Pad1 and PadN, which do
\r
1735 * some padding, and that we do not need to read (the length
\r
1736 * field in the header is enough)
\r
1737 * - Routing header: this one is most notably used by MIPv6,
\r
1738 * which we do not implement, hence we just read it and go
\r
1740 * - Fragmentation header: we read this header and are able to
\r
1741 * reassemble packets
\r
1743 * We do not offer any means to send packets with extension headers
\r
1745 * We do not implement Authentication and ESP headers, which are
\r
1746 * used in IPSec and defined in RFC4302,4303,4305,4385
\r
1749 /* common header part */
\r
1750 struct uip_ext_hdr
\r
1756 /* Hop by Hop option header */
\r
1757 struct uip_hbho_hdr
\r
1763 /* destination option header */
\r
1764 struct uip_desto_hdr
\r
1770 /* We do not define structures for PAD1 and PADN options */
\r
1774 * the routing header as 4 common bytes, then routing header type
\r
1775 * specific data there are several types of routing header. Type 0 was
\r
1776 * deprecated as per RFC5095 most notable other type is 2, used in
\r
1777 * RFC3775 (MIPv6) here we do not implement MIPv6, so we just need to
\r
1778 * parse the 4 first bytes
\r
1780 struct uip_routing_hdr
\r
1784 u8_t routing_type;
\r
1788 /* fragmentation header */
\r
1789 struct uip_frag_hdr
\r
1793 u16_t offsetresmore;
\r
1798 * an option within the destination or hop by hop option headers
\r
1799 * it contains type an length, which is true for all options but PAD1
\r
1801 struct uip_ext_hdr_opt
\r
1808 struct uip_ext_hdr_opt_padn
\r
1815 struct uip_tcp_hdr
\r
1829 /* The ICMP headers. */
\r
1830 struct uip_icmp_hdr
\r
1834 #if !UIP_CONF_IPV6
\r
1836 #endif /* !UIP_CONF_IPV6 */
\r
1839 /* The UDP headers. */
\r
1840 struct uip_udp_hdr
\r
1849 * The buffer size available for user data in the \ref uip_buf buffer.
\r
1851 * This macro holds the available size for user data in the \ref
\r
1852 * uip_buf buffer. The macro is intended to be used for checking
\r
1853 * bounds of available user data.
\r
1857 snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
\r
1860 * \hideinitializer
\r
1862 #define UIP_APPDATA_SIZE ( UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN )
\r
1863 #define UIP_APPDATA_PTR ( void * ) &uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]
\r
1865 #define UIP_PROTO_ICMP 1
\r
1866 #define UIP_PROTO_TCP 6
\r
1867 #define UIP_PROTO_UDP 17
\r
1868 #define UIP_PROTO_ICMP6 58
\r
1870 #if UIP_CONF_IPV6 != 0
\r
1874 /** \brief extension headers types */
\r
1875 #define UIP_PROTO_HBHO 0
\r
1876 #define UIP_PROTO_DESTO 60
\r
1877 #define UIP_PROTO_ROUTING 43
\r
1878 #define UIP_PROTO_FRAG 44
\r
1879 #define UIP_PROTO_NONE 59
\r
1885 /** \brief Destination and Hop By Hop extension headers option types */
\r
1886 #define UIP_EXT_HDR_OPT_PAD1 0
\r
1887 #define UIP_EXT_HDR_OPT_PADN 1
\r
1894 * \brief Bitmaps for extension header processing
\r
1896 * When processing extension headers, we should record somehow which one we
\r
1897 * see, because you cannot have twice the same header, except for destination
\r
1898 * We store all this in one u8_t bitmap one bit for each header expected. The
\r
1899 * order in the bitmap is the order recommended in RFC2460
\r
1901 #define UIP_EXT_HDR_BITMAP_HBHO 0x01
\r
1902 #define UIP_EXT_HDR_BITMAP_DESTO1 0x02
\r
1903 #define UIP_EXT_HDR_BITMAP_ROUTING 0x04
\r
1904 #define UIP_EXT_HDR_BITMAP_FRAG 0x08
\r
1905 #define UIP_EXT_HDR_BITMAP_AH 0x10
\r
1906 #define UIP_EXT_HDR_BITMAP_ESP 0x20
\r
1907 #define UIP_EXT_HDR_BITMAP_DESTO2 0x40
\r
1910 #endif /* UIP_CONF_IPV6 */
\r
1912 /* Header sizes. */
\r
1913 #if UIP_CONF_IPV6 != 0
\r
1914 #define UIP_IPH_LEN 40
\r
1915 #define UIP_FRAGH_LEN 8
\r
1916 #else /* UIP_CONF_IPV6 */
\r
1917 #define UIP_IPH_LEN 20 /* Size of IP header */
\r
1918 #endif /* UIP_CONF_IPV6 */
\r
1920 #define UIP_UDPH_LEN 8 /* Size of UDP header */
\r
1921 #define UIP_TCPH_LEN 20 /* Size of TCP header */
\r
1922 #ifdef UIP_IPH_LEN
\r
1923 #define UIP_ICMPH_LEN 4 /* Size of ICMP header */
\r
1925 #define UIP_IPUDPH_LEN ( UIP_UDPH_LEN + UIP_IPH_LEN ) /* Size of IP +
\r
1928 #define UIP_IPTCPH_LEN ( UIP_TCPH_LEN + UIP_IPH_LEN ) /* Size of IP +
\r
1931 #define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
\r
1932 #define UIP_IPICMPH_LEN ( UIP_IPH_LEN + UIP_ICMPH_LEN ) /* size of ICMP
\r
1934 #define UIP_LLIPH_LEN ( UIP_LLH_LEN + UIP_IPH_LEN ) /* size of L2
\r
1936 #if UIP_CONF_IPV6 != 0
\r
1939 * The sums below are quite used in ND. When used for uip_buf, we
\r
1940 * include link layer length when used for uip_len, we do not, hence
\r
1941 * we need values with and without LLH_LEN we do not use capital
\r
1942 * letters as these values are variable
\r
1944 #define uip_l2_l3_hdr_len ( UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len )
\r
1945 #define uip_l2_l3_icmp_hdr_len ( UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN )
\r
1946 #define uip_l3_hdr_len ( UIP_IPH_LEN + uip_ext_len )
\r
1947 #define uip_l3_icmp_hdr_len ( UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN )
\r
1948 #endif /*UIP_CONF_IPV6*/
\r
1950 #ifdef UIP_FIXEDADDR
\r
1951 CCIF extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
\r
1952 #else /* UIP_FIXEDADDR */
\r
1953 CCIF extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
\r
1954 #endif /* UIP_FIXEDADDR */
\r
1955 CCIF extern const uip_ipaddr_t uip_broadcast_addr;
\r
1956 CCIF extern const uip_ipaddr_t uip_all_zeroes_addr;
\r
1958 #ifdef UIP_FIXEDETHADDR
\r
1959 CCIF extern const uip_lladdr_t uip_lladdr;
\r
1961 CCIF extern uip_lladdr_t uip_lladdr;
\r
1963 #if UIP_CONF_IPV6 != 0
\r
1966 * \brief Is IPv6 address a the unspecified address
\r
1967 * a is of type uip_ipaddr_t
\r
1969 #define uip_is_addr_unspecified( a ) \
\r
1971 (((a)->u16[0]) == 0) && \
\r
1972 (((a)->u16[1]) == 0) && \
\r
1973 (((a)->u16[2]) == 0) && \
\r
1974 (((a)->u16[3]) == 0) && \
\r
1975 (((a)->u16[4]) == 0) && \
\r
1976 (((a)->u16[5]) == 0) && \
\r
1977 (((a)->u16[6]) == 0) && \
\r
1978 (((a)->u16[7]) == 0) \
\r
1981 /** \brief Is IPv6 address a the link local all-nodes multicast address */
\r
1982 #define uip_is_addr_linklocal_allnodes_mcast( a ) \
\r
1984 (((a)->u8[0]) == 0xff) && \
\r
1985 (((a)->u8[1]) == 0x02) && \
\r
1986 (((a)->u16[1]) == 0) && \
\r
1987 (((a)->u16[2]) == 0) && \
\r
1988 (((a)->u16[3]) == 0) && \
\r
1989 (((a)->u16[4]) == 0) && \
\r
1990 (((a)->u16[5]) == 0) && \
\r
1991 (((a)->u16[6]) == 0) && \
\r
1992 (((a)->u8[14]) == 0) && \
\r
1993 (((a)->u8[15]) == 0x01) \
\r
1996 /** \brief set IP address a to unspecified */
\r
1997 #define uip_create_unspecified( a ) uip_ip6addr( a, 0, 0, 0, 0, 0, 0, 0, 0 )
\r
1999 /** \brief set IP address a to the link local all-nodes multicast address */
\r
2000 #define uip_create_linklocal_allnodes_mcast( a ) uip_ip6addr( a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001 )
\r
2002 /** \brief set IP address a to the link local all-routers multicast address */
\r
2003 #define uip_create_linklocal_allrouters_mcast( a ) uip_ip6addr( a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002 )
\r
2006 * \brief is addr (a) a solicited node multicast address, see RFC3513
\r
2007 * a is of type uip_ipaddr_t*
\r
2009 #define uip_is_addr_solicited_node( a ) \
\r
2011 (((a)->u8[0]) == 0xFF) && \
\r
2012 (((a)->u8[1]) == 0x02) && \
\r
2013 (((a)->u16[1]) == 0) && \
\r
2014 (((a)->u16[2]) == 0) && \
\r
2015 (((a)->u16[3]) == 0) && \
\r
2016 (((a)->u16[4]) == 0) && \
\r
2017 (((a)->u16[5]) == 1) && \
\r
2018 (((a)->u8[12]) == 0xFF) \
\r
2022 * \briefput in b the solicited node address corresponding to address a
\r
2023 * both a and b are of type uip_ipaddr_t*
\r
2025 #define uip_create_solicited_node( a, b ) \
\r
2026 ( ((b)->u8[0]) = 0xFF ); \
\r
2027 ( ((b)->u8[1]) = 0x02 ); \
\r
2028 ( ((b)->u16[1]) = 0 ); \
\r
2029 ( ((b)->u16[2]) = 0 ); \
\r
2030 ( ((b)->u16[3]) = 0 ); \
\r
2031 ( ((b)->u16[4]) = 0 ); \
\r
2032 ( ((b)->u8[10]) = 0 ); \
\r
2033 ( ((b)->u8[11]) = 0x01 ); \
\r
2034 ( ((b)->u8[12]) = 0xFF ); \
\r
2035 ( ((b)->u8[13]) = ((a)->u8[13]) ); \
\r
2036 ( ((b)->u16[7]) = ((a)->u16[7]) )
\r
2039 * \brief is addr (a) a link local unicast address, see RFC3513
\r
2040 * i.e. is (a) on prefix FE80::/10
\r
2041 * a is of type uip_ipaddr_t*
\r
2043 #define uip_is_addr_link_local( a ) ( (((a)->u8[0]) == 0xFE) && (((a)->u8[1]) == 0x80) )
\r
2046 * \brief was addr (a) forged based on the mac address m
\r
2047 * a type is uip_ipaddr_t
\r
2048 * m type is uiplladdr_t
\r
2050 #ifdef UIP_CONF_LL_802154
\r
2051 #define uip_is_addr_mac_addr_based( a, m ) \
\r
2053 (((a)->u8[8]) == (((m)->addr[0]) ^ 0x02)) && \
\r
2054 (((a)->u8[9]) == (m)->addr[1]) && \
\r
2055 (((a)->u8[10]) == (m)->addr[2]) && \
\r
2056 (((a)->u8[11]) == (m)->addr[3]) && \
\r
2057 (((a)->u8[12]) == (m)->addr[4]) && \
\r
2058 (((a)->u8[13]) == (m)->addr[5]) && \
\r
2059 (((a)->u8[14]) == (m)->addr[6]) && \
\r
2060 (((a)->u8[15]) == (m)->addr[7]) \
\r
2063 #define uip_is_addr_mac_addr_based( a, m ) \
\r
2065 (((a)->u8[8]) == (((m)->addr[0]) | 0x02)) && \
\r
2066 (((a)->u8[9]) == (m)->addr[1]) && \
\r
2067 (((a)->u8[10]) == (m)->addr[2]) && \
\r
2068 (((a)->u8[11]) == 0xff) && \
\r
2069 (((a)->u8[12]) == 0xfe) && \
\r
2070 (((a)->u8[13]) == (m)->addr[3]) && \
\r
2071 (((a)->u8[14]) == (m)->addr[4]) && \
\r
2072 (((a)->u8[15]) == (m)->addr[5]) \
\r
2074 #endif /*UIP_CONF_LL_802154*/
\r
2077 * \brief is address a multicast address, see RFC 3513
\r
2078 * a is of type uip_ipaddr_t*
\r
2080 #define uip_is_addr_mcast( a ) ( ((a)->u8[0]) == 0xFF )
\r
2083 * \brief is group-id of multicast address a
\r
2084 * the all nodes group-id
\r
2086 #define uip_is_mcast_group_id_all_nodes( a ) \
\r
2088 (((a)->u16[1]) == 0) && \
\r
2089 (((a)->u16[2]) == 0) && \
\r
2090 (((a)->u16[3]) == 0) && \
\r
2091 (((a)->u16[4]) == 0) && \
\r
2092 (((a)->u16[5]) == 0) && \
\r
2093 (((a)->u16[6]) == 0) && \
\r
2094 (((a)->u8[14]) == 0) && \
\r
2095 (((a)->u8[15]) == 1) \
\r
2099 * \brief is group-id of multicast address a
\r
2100 * the all routers group-id
\r
2102 #define uip_is_mcast_group_id_all_routers( a ) \
\r
2104 (((a)->u16[1]) == 0) && \
\r
2105 (((a)->u16[2]) == 0) && \
\r
2106 (((a)->u16[3]) == 0) && \
\r
2107 (((a)->u16[4]) == 0) && \
\r
2108 (((a)->u16[5]) == 0) && \
\r
2109 (((a)->u16[6]) == 0) && \
\r
2110 (((a)->u8[14]) == 0) && \
\r
2111 (((a)->u8[15]) == 2) \
\r
2113 #endif /*UIP_CONF_IPV6*/
\r
2116 * Calculate the Internet checksum over a buffer.
\r
2118 * The Internet checksum is the one's complement of the one's
\r
2119 * complement sum of all 16-bit words in the buffer.
\r
2123 * \param buf A pointer to the buffer over which the checksum is to be
\r
2126 * \param len The length of the buffer over which the checksum is to
\r
2129 * \return The Internet checksum of the buffer.
\r
2131 u16_t uip_chksum( u16_t *buf, u16_t len );
\r
2134 * Calculate the IP header checksum of the packet header in uip_buf.
\r
2136 * The IP header checksum is the Internet checksum of the 20 bytes of
\r
2139 * \return The IP header checksum of the IP header in the uip_buf
\r
2142 u16_t uip_ipchksum( void );
\r
2145 * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
\r
2147 * The TCP checksum is the Internet checksum of data contents of the
\r
2148 * TCP segment, and a pseudo-header as defined in RFC793.
\r
2150 * \return The TCP checksum of the TCP segment in uip_buf and pointed
\r
2151 * to by uip_appdata.
\r
2153 u16_t uip_tcpchksum( void );
\r
2156 * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
\r
2158 * The UDP checksum is the Internet checksum of data contents of the
\r
2159 * UDP segment, and a pseudo-header as defined in RFC768.
\r
2161 * \return The UDP checksum of the UDP segment in uip_buf and pointed
\r
2162 * to by uip_appdata.
\r
2164 u16_t uip_udpchksum( void );
\r
2167 * Calculate the ICMP checksum of the packet in uip_buf.
\r
2169 * \return The ICMP checksum of the ICMP packet in uip_buf
\r
2171 u16_t uip_icmp6chksum( void );
\r
2173 /* Events that can get posted to the uIP event queue. These are events
\r
2174 originating from the Ethernet interface or from a timer. */
\r
2175 #define uipETHERNET_RX_EVENT 0x01UL
\r
2176 #define uipETHERNET_TX_EVENT 0x02UL
\r
2177 #define uipARP_TIMER_EVENT 0x04UL
\r
2178 #define uipPERIODIC_TIMER_EVENT 0x08UL
\r
2179 #define uipAPPLICATION_SEND_EVENT 0x10UL
\r
2182 #endif /* __UIP_H__ */
\r