9 * Header file for the uIP TCP/IP stack.
10 * \author Adam Dunkels <adam@dunkels.com>
11 * \author Julien Abeille <jabeille@cisco.com> (IPv6 related code)
12 * \author Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)
14 * The uIP TCP/IP stack header file contains definitions for a number
15 * of C macros that are used by uIP programs as well as internal uIP
16 * structures, TCP/IP header structures and function declarations.
21 * Copyright (c) 2001-2003, Adam Dunkels.
22 * All rights reserved.
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * 3. The name of the author may not be used to endorse or promote
33 * products derived from this software without specific prior
36 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
37 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
40 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
45 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 * This file is part of the uIP TCP/IP stack.
50 * $Id: uip.h,v 1.24 2009/04/06 13:18:50 nvt-se Exp $
60 * Representation of an IP address.
64 typedef union uip_ip6addr_t
{
65 u8_t u8
[16]; /* Initializer, must come first!!! */
69 typedef uip_ip6addr_t uip_ipaddr_t
;
70 #else /* UIP_CONF_IPV6 */
71 typedef union uip_ip4addr_t
{
72 u8_t u8
[4]; /* Initializer, must come first!!! */
78 typedef uip_ip4addr_t uip_ipaddr_t
;
79 #endif /* UIP_CONF_IPV6 */
82 /*---------------------------------------------------------------------------*/
84 /** \brief 16 bit 802.15.4 address */
85 struct uip_802154_shortaddr
{
88 /** \brief 64 bit 802.15.4 address */
89 struct uip_802154_longaddr
{
93 /** \brief 802.11 address */
94 struct uip_80211_addr
{
98 /** \brief 802.3 address */
103 #if UIP_CONF_LL_802154
104 /** \brief 802.15.4 address */
105 typedef struct uip_802154_longaddr uip_lladdr_t
;
106 #define UIP_802154_SHORTADDR_LEN 2
107 #define UIP_802154_LONGADDR_LEN 8
108 #define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN
109 #else /*UIP_CONF_LL_802154*/
110 #if UIP_CONF_LL_80211
111 /** \brief 802.11 address */
112 typedef struct uip_80211_addr uip_lladdr_t
;
113 #define UIP_LLADDR_LEN 6
114 #else /*UIP_CONF_LL_80211*/
115 /** \brief Ethernet address */
116 typedef struct uip_eth_addr uip_lladdr_t
;
117 #define UIP_LLADDR_LEN 6
118 #endif /*UIP_CONF_LL_80211*/
119 #endif /*UIP_CONF_LL_802154*/
121 /*---------------------------------------------------------------------------*/
122 /* First, the functions that should be called from the
123 * system. Initialization, the periodic timer, and incoming packets are
124 * handled by the following three functions.
127 * \defgroup uipconffunc uIP configuration functions
130 * The uIP configuration functions are used for setting run-time
131 * parameters in uIP such as IP addresses.
135 * Set the IP address of this host.
137 * The IP address is represented as a 4-byte array where the first
138 * octet of the IP address is put in the first member of the 4-byte
146 uip_ipaddr(&addr, 192,168,1,2);
147 uip_sethostaddr(&addr);
150 * \param addr A pointer to an IP address of type uip_ipaddr_t;
156 #define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr))
159 * Get the IP address of this host.
161 * The IP address is represented as a 4-byte array where the first
162 * octet of the IP address is put in the first member of the 4-byte
167 uip_ipaddr_t hostaddr;
169 uip_gethostaddr(&hostaddr);
171 * \param addr A pointer to a uip_ipaddr_t variable that will be
172 * filled in with the currently configured IP address.
176 #define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr)
179 * Set the default router's IP address.
181 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
182 * address of the default router.
188 #define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr))
193 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
194 * address of the netmask.
200 #define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr))
204 * Get the default router's IP address.
206 * \param addr A pointer to a uip_ipaddr_t variable that will be
207 * filled in with the IP address of the default router.
211 #define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr)
216 * \param addr A pointer to a uip_ipaddr_t variable that will be
217 * filled in with the value of the netmask.
221 #define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask)
226 * \defgroup uipinit uIP initialization functions
229 * The uIP initialization functions are used for booting uIP.
233 * uIP initialization function.
235 * This function should be called at boot up to initilize the uIP
241 * uIP initialization function.
243 * This function may be used at boot time to set the initial ip_id.
245 void uip_setipid(u16_t id
);
250 * \defgroup uipdevfunc uIP device driver functions
253 * These functions are used by a network device driver for interacting
258 * Process an incoming packet.
260 * This function should be called when the device driver has received
261 * a packet from the network. The packet from the device driver must
262 * be present in the uip_buf buffer, and the length of the packet
263 * should be placed in the uip_len variable.
265 * When the function returns, there may be an outbound packet placed
266 * in the uip_buf packet buffer. If so, the uip_len variable is set to
267 * the length of the packet. If no packet is to be sent out, the
268 * uip_len variable is set to 0.
270 * The usual way of calling the function is presented by the source
273 uip_len = devicedriver_poll();
282 * \note If you are writing a uIP device driver that needs ARP
283 * (Address Resolution Protocol), e.g., when running uIP over
284 * Ethernet, you will need to call the uIP ARP code before calling
287 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
288 uip_len = ethernet_devicedrver_poll();
290 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
295 ethernet_devicedriver_send();
297 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
300 ethernet_devicedriver_send();
307 #define uip_input() uip_process(UIP_DATA)
311 * Periodic processing for a connection identified by its number.
313 * This function does the necessary periodic processing (timers,
314 * polling) for a uIP TCP conneciton, and should be called when the
315 * periodic uIP timer goes off. It should be called for every
316 * connection, regardless of whether they are open of closed.
318 * When the function returns, it may have an outbound packet waiting
319 * for service in the uIP packet buffer, and if so the uip_len
320 * variable is set to a value larger than zero. The device driver
321 * should be called to send out the packet.
323 * The usual way of calling the function is through a for() loop like
326 for(i = 0; i < UIP_CONNS; ++i) {
334 * \note If you are writing a uIP device driver that needs ARP
335 * (Address Resolution Protocol), e.g., when running uIP over
336 * Ethernet, you will need to call the uip_arp_out() function before
337 * calling the device driver:
339 for(i = 0; i < UIP_CONNS; ++i) {
343 ethernet_devicedriver_send();
348 * \param conn The number of the connection which is to be periodically polled.
353 #define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \
354 uip_process(UIP_TIMER); } while (0)
360 #define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED)
363 * Perform periodic processing for a connection identified by a pointer
366 * Same as uip_periodic() but takes a pointer to the actual uip_conn
367 * struct instead of an integer as its argument. This function can be
368 * used to force periodic processing of a specific connection.
370 * \param conn A pointer to the uip_conn struct for the connection to
375 #define uip_periodic_conn(conn) do { uip_conn = conn; \
376 uip_process(UIP_TIMER); } while (0)
379 * Request that a particular connection should be polled.
381 * Similar to uip_periodic_conn() but does not perform any timer
382 * processing. The application is polled for new data.
384 * \param conn A pointer to the uip_conn struct for the connection to
389 #define uip_poll_conn(conn) do { uip_conn = conn; \
390 uip_process(UIP_POLL_REQUEST); } while (0)
396 * Periodic processing for a UDP connection identified by its number.
398 * This function is essentially the same as uip_periodic(), but for
399 * UDP connections. It is called in a similar fashion as the
400 * uip_periodic() function:
402 for(i = 0; i < UIP_UDP_CONNS; i++) {
410 * \note As for the uip_periodic() function, special care has to be
411 * taken when using uIP together with ARP and Ethernet:
413 for(i = 0; i < UIP_UDP_CONNS; i++) {
417 ethernet_devicedriver_send();
422 * \param conn The number of the UDP connection to be processed.
426 #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
427 uip_process(UIP_UDP_TIMER); } while(0)
430 * Periodic processing for a UDP connection identified by a pointer to
433 * Same as uip_udp_periodic() but takes a pointer to the actual
434 * uip_conn struct instead of an integer as its argument. This
435 * function can be used to force periodic processing of a specific
438 * \param conn A pointer to the uip_udp_conn struct for the connection
443 #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
444 uip_process(UIP_UDP_TIMER); } while(0)
447 /** \brief Abandon the reassembly of the current packet */
448 void uip_reass_over(void);
451 * The uIP packet buffer.
453 * The uip_buf array is used to hold incoming and outgoing
454 * packets. The device driver should place incoming data into this
455 * buffer. When sending data, the device driver should read the link
456 * level headers and the TCP/IP headers from this buffer. The size of
457 * the link level headers is configured by the UIP_LLH_LEN define.
459 * \note The application data need not be placed in this buffer, so
460 * the device driver must read it from the place pointed to by the
461 * uip_appdata pointer as illustrated by the following example:
464 devicedriver_send(void)
466 hwsend(&uip_buf[0], UIP_LLH_LEN);
467 if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
468 hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
470 hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
471 hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
476 extern u8_t uip_buf
[UIP_BUFSIZE
+2];
482 /*---------------------------------------------------------------------------*/
483 /* Functions that are used by the uIP application program. Opening and
484 * closing connections, sending and receiving data, etc. is all
485 * handled by the functions below.
488 * \defgroup uipappfunc uIP application functions
491 * Functions used by an application running of top of uIP.
495 * Start listening to the specified port.
497 * \note Since this function expects the port number in network byte
498 * order, a conversion using HTONS() or htons() is necessary.
501 uip_listen(HTONS(80));
504 * \param port A 16-bit port number in network byte order.
506 void uip_listen(u16_t port
);
509 * Stop listening to the specified port.
511 * \note Since this function expects the port number in network byte
512 * order, a conversion using HTONS() or htons() is necessary.
515 uip_unlisten(HTONS(80));
518 * \param port A 16-bit port number in network byte order.
520 void uip_unlisten(u16_t port
);
523 * Connect to a remote host using TCP.
525 * This function is used to start a new connection to the specified
526 * port on the specified host. It allocates a new connection identifier,
527 * sets the connection to the SYN_SENT state and sets the
528 * retransmission timer to 0. This will cause a TCP SYN segment to be
529 * sent out the next time this connection is periodically processed,
530 * which usually is done within 0.5 seconds after the call to
533 * \note This function is available only if support for active open
534 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
536 * \note Since this function requires the port number to be in network
537 * byte order, a conversion using HTONS() or htons() is necessary.
542 uip_ipaddr(&ipaddr, 192,168,1,2);
543 uip_connect(&ipaddr, HTONS(80));
546 * \param ripaddr The IP address of the remote host.
548 * \param port A 16-bit port number in network byte order.
550 * \return A pointer to the uIP connection identifier for the new connection,
551 * or NULL if no connection could be allocated.
554 struct uip_conn
*uip_connect(uip_ipaddr_t
*ripaddr
, u16_t port
);
561 * Check if a connection has outstanding (i.e., unacknowledged) data.
563 * \param conn A pointer to the uip_conn structure for the connection.
567 #define uip_outstanding(conn) ((conn)->len)
570 * Send data on the current connection.
572 * This function is used to send out a single segment of TCP
573 * data. Only applications that have been invoked by uIP for event
574 * processing can send data.
576 * The amount of data that actually is sent out after a call to this
577 * function is determined by the maximum amount of data TCP allows. uIP
578 * will automatically crop the data so that only the appropriate
579 * amount of data is sent. The function uip_mss() can be used to query
580 * uIP for the amount of data that actually will be sent.
582 * \note This function does not guarantee that the sent data will
583 * arrive at the destination. If the data is lost in the network, the
584 * application will be invoked with the uip_rexmit() event being
585 * set. The application will then have to resend the data using this
588 * \param data A pointer to the data which is to be sent.
590 * \param len The maximum amount of data bytes to be sent.
594 void uip_send(const void *data
, int len
);
597 * The length of any incoming data that is currently available (if available)
598 * in the uip_appdata buffer.
600 * The test function uip_data() must first be used to check if there
601 * is any data available at all.
605 /*void uip_datalen(void);*/
606 #define uip_datalen() uip_len
609 * The length of any out-of-band data (urgent data) that has arrived
612 * \note The configuration parameter UIP_URGDATA must be set for this
613 * function to be enabled.
617 #define uip_urgdatalen() uip_urglen
620 * Close the current connection.
622 * This function will close the current connection in a nice way.
626 #define uip_close() (uip_flags = UIP_CLOSE)
629 * Abort the current connection.
631 * This function will abort (reset) the current connection, and is
632 * usually used when an error has occurred that prevents using the
633 * uip_close() function.
637 #define uip_abort() (uip_flags = UIP_ABORT)
640 * Tell the sending host to stop sending data.
642 * This function will close our receiver's window so that we stop
643 * receiving data for the current connection.
647 #define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)
650 * Find out if the current connection has been previously stopped with
655 #define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED)
658 * Restart the current connection, if is has previously been stopped
661 * This function will open the receiver's window again so that we
662 * start receiving data for the current connection.
666 #define uip_restart() do { uip_flags |= UIP_NEWDATA; \
667 uip_conn->tcpstateflags &= ~UIP_STOPPED; \
671 /* uIP tests that can be made to determine in what state the current
672 connection is, and what the application function should do. */
675 * Is the current connection a UDP connection?
677 * This function checks whether the current connection is a UDP connection.
682 #define uip_udpconnection() (uip_conn == NULL)
685 * Is new incoming data available?
687 * Will reduce to non-zero if there is new data for the application
688 * present at the uip_appdata pointer. The size of the data is
689 * available through the uip_len variable.
693 #define uip_newdata() (uip_flags & UIP_NEWDATA)
696 * Has previously sent data been acknowledged?
698 * Will reduce to non-zero if the previously sent data has been
699 * acknowledged by the remote host. This means that the application
704 #define uip_acked() (uip_flags & UIP_ACKDATA)
707 * Has the connection just been connected?
709 * Reduces to non-zero if the current connection has been connected to
710 * a remote host. This will happen both if the connection has been
711 * actively opened (with uip_connect()) or passively opened (with
716 #define uip_connected() (uip_flags & UIP_CONNECTED)
719 * Has the connection been closed by the other end?
721 * Is non-zero if the connection has been closed by the remote
722 * host. The application may then do the necessary clean-ups.
726 #define uip_closed() (uip_flags & UIP_CLOSE)
729 * Has the connection been aborted by the other end?
731 * Non-zero if the current connection has been aborted (reset) by the
736 #define uip_aborted() (uip_flags & UIP_ABORT)
739 * Has the connection timed out?
741 * Non-zero if the current connection has been aborted due to too many
746 #define uip_timedout() (uip_flags & UIP_TIMEDOUT)
749 * Do we need to retransmit previously data?
751 * Reduces to non-zero if the previously sent data has been lost in
752 * the network, and the application should retransmit it. The
753 * application should send the exact same data as it did the last
754 * time, using the uip_send() function.
758 #define uip_rexmit() (uip_flags & UIP_REXMIT)
761 * Is the connection being polled by uIP?
763 * Is non-zero if the reason the application is invoked is that the
764 * current connection has been idle for a while and should be
767 * The polling event can be used for sending data without having to
768 * wait for the remote host to send data.
772 #define uip_poll() (uip_flags & UIP_POLL)
775 * Get the initial maximum segment size (MSS) of the current
780 #define uip_initialmss() (uip_conn->initialmss)
783 * Get the current maximum segment size that can be sent on the current
786 * The current maximum segment size that can be sent on the
787 * connection is computed from the receiver's window and the MSS of
788 * the connection (which also is available by calling
793 #define uip_mss() (uip_conn->mss)
796 * Set up a new UDP connection.
798 * This function sets up a new UDP connection. The function will
799 * automatically allocate an unused local port for the new
800 * connection. However, another port can be chosen by using the
801 * uip_udp_bind() call, after the uip_udp_new() function has been
807 struct uip_udp_conn *c;
809 uip_ipaddr(&addr, 192,168,2,1);
810 c = uip_udp_new(&addr, HTONS(12345));
812 uip_udp_bind(c, HTONS(12344));
815 * \param ripaddr The IP address of the remote host.
817 * \param rport The remote port number in network byte order.
819 * \return The uip_udp_conn structure for the new connection or NULL
820 * if no connection could be allocated.
822 struct uip_udp_conn
*uip_udp_new(const uip_ipaddr_t
*ripaddr
, u16_t rport
);
825 * Removed a UDP connection.
827 * \param conn A pointer to the uip_udp_conn structure for the connection.
831 #define uip_udp_remove(conn) (conn)->lport = 0
834 * Bind a UDP connection to a local port.
836 * \param conn A pointer to the uip_udp_conn structure for the
839 * \param port The local port number, in network byte order.
843 #define uip_udp_bind(conn, port) (conn)->lport = port
846 * Send a UDP datagram of length len on the current connection.
848 * This function can only be called in response to a UDP event (poll
849 * or newdata). The data must be present in the uip_buf buffer, at the
850 * place pointed to by the uip_appdata pointer.
852 * \param len The length of the data in the uip_buf buffer.
856 #define uip_udp_send(len) uip_send((char *)uip_appdata, len)
860 /* uIP convenience and converting functions. */
863 * \defgroup uipconvfunc uIP conversion functions
866 * These functions can be used for converting between different data
867 * formats used by uIP.
871 * Convert an IP address to four bytes separated by commas.
876 printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr));
879 * \param a A pointer to a uip_ipaddr_t.
882 #define uip_ipaddr_to_quad(a) (a)->u8[0],(a)->u8[1],(a)->u8[2],(a)->u8[3]
885 * Construct an IP address from four bytes.
887 * This function constructs an IP address of the type that uIP handles
888 * internally from four bytes. The function is handy for specifying IP
889 * addresses to use with e.g. the uip_connect() function.
896 uip_ipaddr(&ipaddr, 192,168,1,2);
897 c = uip_connect(&ipaddr, HTONS(80));
900 * \param addr A pointer to a uip_ipaddr_t variable that will be
901 * filled in with the IP address.
903 * \param addr0 The first octet of the IP address.
904 * \param addr1 The second octet of the IP address.
905 * \param addr2 The third octet of the IP address.
906 * \param addr3 The forth octet of the IP address.
910 #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
911 (addr)->u8[0] = addr0; \
912 (addr)->u8[1] = addr1; \
913 (addr)->u8[2] = addr2; \
914 (addr)->u8[3] = addr3; \
918 * Construct an IPv6 address from eight 16-bit words.
920 * This function constructs an IPv6 address.
924 #define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
925 (addr)->u16[0] = HTONS(addr0); \
926 (addr)->u16[1] = HTONS(addr1); \
927 (addr)->u16[2] = HTONS(addr2); \
928 (addr)->u16[3] = HTONS(addr3); \
929 (addr)->u16[4] = HTONS(addr4); \
930 (addr)->u16[5] = HTONS(addr5); \
931 (addr)->u16[6] = HTONS(addr6); \
932 (addr)->u16[7] = HTONS(addr7); \
936 * Construct an IPv6 address from eight 8-bit words.
938 * This function constructs an IPv6 address.
942 #define uip_ip6addr_u8(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7,addr8,addr9,addr10,addr11,addr12,addr13,addr14,addr15) do { \
943 (addr)->u8[0] = addr0; \
944 (addr)->u8[1] = addr1; \
945 (addr)->u8[2] = addr2; \
946 (addr)->u8[3] = addr3; \
947 (addr)->u8[4] = addr4; \
948 (addr)->u8[5] = addr5; \
949 (addr)->u8[6] = addr6; \
950 (addr)->u8[7] = addr7; \
951 (addr)->u8[8] = addr8; \
952 (addr)->u8[9] = addr9; \
953 (addr)->u8[10] = addr10; \
954 (addr)->u8[11] = addr11; \
955 (addr)->u8[12] = addr12; \
956 (addr)->u8[13] = addr13; \
957 (addr)->u8[14] = addr14; \
958 (addr)->u8[15] = addr15; \
963 * Copy an IP address to another IP address.
965 * Copies an IP address from one place to another.
969 uip_ipaddr_t ipaddr1, ipaddr2;
971 uip_ipaddr(&ipaddr1, 192,16,1,2);
972 uip_ipaddr_copy(&ipaddr2, &ipaddr1);
975 * \param dest The destination for the copy.
976 * \param src The source from where to copy.
980 #ifndef uip_ipaddr_copy
981 #define uip_ipaddr_copy(dest, src) (*(dest) = *(src))
985 * Compare two IP addresses
987 * Compares two IP addresses.
991 uip_ipaddr_t ipaddr1, ipaddr2;
993 uip_ipaddr(&ipaddr1, 192,16,1,2);
994 if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
995 printf("They are the same");
999 * \param addr1 The first IP address.
1000 * \param addr2 The second IP address.
1005 #define uip_ipaddr_cmp(addr1, addr2) ((addr1)->u16[0] == (addr2)->u16[0] && \
1006 (addr1)->u16[1] == (addr2)->u16[1])
1007 #else /* !UIP_CONF_IPV6 */
1008 #define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
1009 #endif /* !UIP_CONF_IPV6 */
1012 * Compare two IP addresses with netmasks
1014 * Compares two IP addresses with netmasks. The masks are used to mask
1015 * out the bits that are to be compared.
1019 uip_ipaddr_t ipaddr1, ipaddr2, mask;
1021 uip_ipaddr(&mask, 255,255,255,0);
1022 uip_ipaddr(&ipaddr1, 192,16,1,2);
1023 uip_ipaddr(&ipaddr2, 192,16,1,3);
1024 if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
1025 printf("They are the same");
1029 * \param addr1 The first IP address.
1030 * \param addr2 The second IP address.
1031 * \param mask The netmask.
1036 #define uip_ipaddr_maskcmp(addr1, addr2, mask) \
1037 (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \
1038 (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \
1039 ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \
1040 (((u16_t *)addr2)[1] & ((u16_t *)mask)[1])))
1042 #define uip_ipaddr_prefixcmp(addr1, addr2, length) (memcmp(addr1, addr2, length>>3) == 0)
1047 * Check if an address is a broadcast address for a network.
1049 * Checks if an address is the broadcast address for a network. The
1050 * network is defined by an IP address that is on the network and the
1051 * network's netmask.
1053 * \param addr The IP address.
1054 * \param netaddr The network's IP address.
1055 * \param netmask The network's netmask.
1059 /*#define uip_ipaddr_isbroadcast(addr, netaddr, netmask)
1060 ((uip_ipaddr_t *)(addr)).u16 & ((uip_ipaddr_t *)(addr)).u16*/
1065 * Mask out the network part of an IP address.
1067 * Masks out the network part of an IP address, given the address and
1072 uip_ipaddr_t ipaddr1, ipaddr2, netmask;
1074 uip_ipaddr(&ipaddr1, 192,16,1,2);
1075 uip_ipaddr(&netmask, 255,255,255,0);
1076 uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
1079 * In the example above, the variable "ipaddr2" will contain the IP
1080 * address 192.168.1.0.
1082 * \param dest Where the result is to be placed.
1083 * \param src The IP address.
1084 * \param mask The netmask.
1088 #define uip_ipaddr_mask(dest, src, mask) do { \
1089 ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \
1090 ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \
1094 * Pick the first octet of an IP address.
1096 * Picks out the first octet of an IP address.
1100 uip_ipaddr_t ipaddr;
1103 uip_ipaddr(&ipaddr, 1,2,3,4);
1104 octet = uip_ipaddr1(&ipaddr);
1107 * In the example above, the variable "octet" will contain the value 1.
1111 #define uip_ipaddr1(addr) ((addr)->u8[0])
1114 * Pick the second octet of an IP address.
1116 * Picks out the second octet of an IP address.
1120 uip_ipaddr_t ipaddr;
1123 uip_ipaddr(&ipaddr, 1,2,3,4);
1124 octet = uip_ipaddr2(&ipaddr);
1127 * In the example above, the variable "octet" will contain the value 2.
1131 #define uip_ipaddr2(addr) ((addr)->u8[1])
1134 * Pick the third octet of an IP address.
1136 * Picks out the third octet of an IP address.
1140 uip_ipaddr_t ipaddr;
1143 uip_ipaddr(&ipaddr, 1,2,3,4);
1144 octet = uip_ipaddr3(&ipaddr);
1147 * In the example above, the variable "octet" will contain the value 3.
1151 #define uip_ipaddr3(addr) ((addr)->u8[2])
1154 * Pick the fourth octet of an IP address.
1156 * Picks out the fourth octet of an IP address.
1160 uip_ipaddr_t ipaddr;
1163 uip_ipaddr(&ipaddr, 1,2,3,4);
1164 octet = uip_ipaddr4(&ipaddr);
1167 * In the example above, the variable "octet" will contain the value 4.
1171 #define uip_ipaddr4(addr) ((addr)->u8[3])
1174 * Convert 16-bit quantity from host byte order to network byte order.
1176 * This macro is primarily used for converting constants from host
1177 * byte order to network byte order. For converting variables to
1178 * network byte order, use the htons() function instead.
1183 # if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
1184 # define HTONS(n) (n)
1185 # define HTONL(n) (n)
1186 # else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
1187 # define HTONS(n) (u16_t)((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8))
1188 # define HTONL(n) (((u32_t)HTONS(n) << 16) | HTONS((u32_t)(n) >> 16))
1189 # endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
1191 #error "HTONS already defined!"
1195 * Convert 16-bit quantity from host byte order to network byte order.
1197 * This function is primarily used for converting variables from host
1198 * byte order to network byte order. For converting constants to
1199 * network byte order, use the HTONS() macro instead.
1202 u16_t
htons(u16_t val
);
1209 u32_t
htonl(u32_t val
);
1218 * Pointer to the application data in the packet buffer.
1220 * This pointer points to the application data when the application is
1221 * called. If the application wishes to send data, the application may
1222 * use this space to write the data into before calling uip_send().
1224 extern void *uip_appdata
;
1227 /* u8_t *uip_urgdata:
1229 * This pointer points to any urgent data that has been received. Only
1230 * present if compiled with support for urgent data (UIP_URGDATA).
1232 extern void *uip_urgdata
;
1233 #endif /* UIP_URGDATA > 0 */
1237 * \defgroup uipdrivervars Variables used in uIP device drivers
1240 * uIP has a few global variables that are used in device drivers for
1245 * The length of the packet in the uip_buf buffer.
1247 * The global variable uip_len holds the length of the packet in the
1250 * When the network device driver calls the uIP input function,
1251 * uip_len should be set to the length of the packet in the uip_buf
1254 * When sending packets, the device driver should use the contents of
1255 * the uip_len variable to determine the length of the outgoing
1259 extern u16_t uip_len
;
1262 * The length of the extension headers
1264 extern u8_t uip_ext_len
;
1268 extern u16_t uip_urglen
, uip_surglen
;
1269 #endif /* UIP_URGDATA > 0 */
1273 * Representation of a uIP TCP connection.
1275 * The uip_conn structure is used for identifying a connection. All
1276 * but one field in the structure are to be considered read-only by an
1277 * application. The only exception is the appstate field whose purpose
1278 * is to let the application store application-specific state (e.g.,
1279 * file pointers) for the connection. The type of this field is
1280 * configured in the "uipopt.h" header file.
1283 uip_ipaddr_t ripaddr
; /**< The IP address of the remote host. */
1285 u16_t lport
; /**< The local TCP port, in network byte order. */
1286 u16_t rport
; /**< The local remote TCP port, in network byte
1289 u8_t rcv_nxt
[4]; /**< The sequence number that we expect to
1291 u8_t snd_nxt
[4]; /**< The sequence number that was last sent by
1293 u16_t len
; /**< Length of the data that was previously sent. */
1294 u16_t mss
; /**< Current maximum segment size for the
1296 u16_t initialmss
; /**< Initial maximum segment size for the
1298 u8_t sa
; /**< Retransmission time-out calculation state
1300 u8_t sv
; /**< Retransmission time-out calculation state
1302 u8_t rto
; /**< Retransmission time-out. */
1303 u8_t tcpstateflags
; /**< TCP state and flags. */
1304 u8_t timer
; /**< The retransmission timer. */
1305 u8_t nrtx
; /**< The number of retransmissions for the last
1308 /** The application state. */
1309 uip_tcp_appstate_t appstate
;
1314 * Pointer to the current TCP connection.
1316 * The uip_conn pointer can be used to access the current TCP
1320 extern struct uip_conn
*uip_conn
;
1322 /* The array containing all uIP connections. */
1323 extern struct uip_conn uip_conns
[UIP_CONNS
];
1327 * \addtogroup uiparch
1332 * 4-byte array used for the 32-bit sequence number calculations.
1334 extern u8_t uip_acc32
[4];
1338 * Representation of a uIP UDP connection.
1340 struct uip_udp_conn
{
1341 uip_ipaddr_t ripaddr
; /**< The IP address of the remote peer. */
1342 u16_t lport
; /**< The local port number in network byte order. */
1343 u16_t rport
; /**< The remote port number in network byte order. */
1344 u8_t ttl
; /**< Default time-to-live. */
1346 /** The application state. */
1347 uip_udp_appstate_t appstate
;
1351 * The current UDP connection.
1353 extern struct uip_udp_conn
*uip_udp_conn
;
1354 extern struct uip_udp_conn uip_udp_conns
[UIP_UDP_CONNS
];
1357 int (*activate
)(void);
1358 int (*deactivate
)(void);
1359 uip_ipaddr_t
*(*lookup
)(uip_ipaddr_t
*destipaddr
, uip_ipaddr_t
*nexthop
);
1363 extern const struct uip_router
*uip_router
;
1366 * uIP routing driver registration function.
1368 void uip_router_register(const struct uip_router
*router
);
1369 #endif /*UIP_CONF_ROUTER*/
1372 struct uip_icmp6_conn
{
1373 uip_icmp6_appstate_t appstate
;
1375 extern struct uip_icmp6_conn uip_icmp6_conns
;
1376 #endif /*UIP_CONF_ICMP6*/
1379 * The uIP TCP/IP statistics.
1381 * This is the variable in which the uIP TCP/IP statistics are gathered.
1383 #if UIP_STATISTICS == 1
1384 extern struct uip_stats uip_stat
;
1385 #define UIP_STAT(s) s
1388 #endif /* UIP_STATISTICS == 1 */
1391 * The structure holding the TCP/IP statistics that are gathered if
1392 * UIP_STATISTICS is set to 1.
1397 uip_stats_t recv
; /**< Number of received packets at the IP
1399 uip_stats_t sent
; /**< Number of sent packets at the IP
1401 uip_stats_t forwarded
;/**< Number of forwarded packets at the IP
1403 uip_stats_t drop
; /**< Number of dropped packets at the IP
1405 uip_stats_t vhlerr
; /**< Number of packets dropped due to wrong
1406 IP version or header length. */
1407 uip_stats_t hblenerr
; /**< Number of packets dropped due to wrong
1408 IP length, high byte. */
1409 uip_stats_t lblenerr
; /**< Number of packets dropped due to wrong
1410 IP length, low byte. */
1411 uip_stats_t fragerr
; /**< Number of packets dropped since they
1412 were IP fragments. */
1413 uip_stats_t chkerr
; /**< Number of packets dropped due to IP
1415 uip_stats_t protoerr
; /**< Number of packets dropped since they
1416 were neither ICMP, UDP nor TCP. */
1417 } ip
; /**< IP statistics. */
1419 uip_stats_t recv
; /**< Number of received ICMP packets. */
1420 uip_stats_t sent
; /**< Number of sent ICMP packets. */
1421 uip_stats_t drop
; /**< Number of dropped ICMP packets. */
1422 uip_stats_t typeerr
; /**< Number of ICMP packets with a wrong
1424 uip_stats_t chkerr
; /**< Number of ICMP packets with a bad
1426 } icmp
; /**< ICMP statistics. */
1429 uip_stats_t recv
; /**< Number of recived TCP segments. */
1430 uip_stats_t sent
; /**< Number of sent TCP segments. */
1431 uip_stats_t drop
; /**< Number of dropped TCP segments. */
1432 uip_stats_t chkerr
; /**< Number of TCP segments with a bad
1434 uip_stats_t ackerr
; /**< Number of TCP segments with a bad ACK
1436 uip_stats_t rst
; /**< Number of recevied TCP RST (reset) segments. */
1437 uip_stats_t rexmit
; /**< Number of retransmitted TCP segments. */
1438 uip_stats_t syndrop
; /**< Number of dropped SYNs due to too few
1439 connections was avaliable. */
1440 uip_stats_t synrst
; /**< Number of SYNs for closed ports,
1441 triggering a RST. */
1442 } tcp
; /**< TCP statistics. */
1446 uip_stats_t drop
; /**< Number of dropped UDP segments. */
1447 uip_stats_t recv
; /**< Number of recived UDP segments. */
1448 uip_stats_t sent
; /**< Number of sent UDP segments. */
1449 uip_stats_t chkerr
; /**< Number of UDP segments with a bad
1451 } udp
; /**< UDP statistics. */
1452 #endif /* UIP_UDP */
1455 uip_stats_t drop
; /**< Number of dropped ND6 packets. */
1456 uip_stats_t recv
; /**< Number of recived ND6 packets */
1457 uip_stats_t sent
; /**< Number of sent ND6 packets */
1459 #endif /*UIP_CONF_IPV6*/
1463 /*---------------------------------------------------------------------------*/
1464 /* All the stuff below this point is internal to uIP and should not be
1465 * used directly by an application or by a device driver.
1467 /*---------------------------------------------------------------------------*/
1473 * When the application is called, uip_flags will contain the flags
1474 * that are defined in this file. Please read below for more
1477 extern u8_t uip_flags
;
1479 /* The following flags may be set in the global variable uip_flags
1480 before calling the application callback. The UIP_ACKDATA,
1481 UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
1482 whereas the others are mutually exclusive. Note that these flags
1483 should *NOT* be accessed directly, but only through the uIP
1484 functions/macros. */
1486 #define UIP_ACKDATA 1 /* Signifies that the outstanding data was
1487 acked and the application should send
1488 out new data instead of retransmitting
1490 #define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
1492 #define UIP_REXMIT 4 /* Tells the application to retransmit the
1493 data that was last sent. */
1494 #define UIP_POLL 8 /* Used for polling the application, to
1495 check if the application has data that
1496 it wants to send. */
1497 #define UIP_CLOSE 16 /* The remote host has closed the
1498 connection, thus the connection has
1499 gone away. Or the application signals
1500 that it wants to close the
1502 #define UIP_ABORT 32 /* The remote host has aborted the
1503 connection, thus the connection has
1504 gone away. Or the application signals
1505 that it wants to abort the
1507 #define UIP_CONNECTED 64 /* We have got a connection from a remote
1508 host and have set up a new connection
1509 for it, or an active connection has
1510 been successfully established. */
1512 #define UIP_TIMEDOUT 128 /* The connection has been aborted due to
1513 too many retransmissions. */
1517 * \brief process the options within a hop by hop or destination option header
1518 * \retval 0: nothing to send,
1519 * \retval 1: drop pkt
1520 * \retval 2: ICMP error message to send
1523 uip_ext_hdr_options_process(); */
1525 /* uip_process(flag):
1527 * The actual uIP function which does all the work.
1529 void uip_process(u8_t flag
);
1531 /* The following flags are passed as an argument to the uip_process()
1532 function. They are used to distinguish between the two cases where
1533 uip_process() is called. It can be called either because we have
1534 incoming data that should be processed, or because the periodic
1535 timer has fired. These values are never used directly, but only in
1536 the macros defined in this file. */
1538 #define UIP_DATA 1 /* Tells uIP that there is incoming
1539 data in the uip_buf buffer. The
1540 length of the data is stored in the
1541 global variable uip_len. */
1542 #define UIP_TIMER 2 /* Tells uIP that the periodic timer
1544 #define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should
1546 #define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram
1547 should be constructed in the
1550 #define UIP_UDP_TIMER 5
1551 #endif /* UIP_UDP */
1553 /* The TCP states used in the uip_conn->tcpstateflags. */
1554 #define UIP_CLOSED 0
1555 #define UIP_SYN_RCVD 1
1556 #define UIP_SYN_SENT 2
1557 #define UIP_ESTABLISHED 3
1558 #define UIP_FIN_WAIT_1 4
1559 #define UIP_FIN_WAIT_2 5
1560 #define UIP_CLOSING 6
1561 #define UIP_TIME_WAIT 7
1562 #define UIP_LAST_ACK 8
1563 #define UIP_TS_MASK 15
1565 #define UIP_STOPPED 16
1567 /* The TCP and IP headers. */
1568 struct uip_tcpip_hdr
{
1576 uip_ip6addr_t srcipaddr
, destipaddr
;
1577 #else /* UIP_CONF_IPV6 */
1587 uip_ipaddr_t srcipaddr
, destipaddr
;
1588 #endif /* UIP_CONF_IPV6 */
1603 /* The ICMP and IP headers. */
1604 struct uip_icmpip_hdr
{
1612 uip_ip6addr_t srcipaddr
, destipaddr
;
1613 #else /* UIP_CONF_IPV6 */
1623 uip_ipaddr_t srcipaddr
, destipaddr
;
1624 #endif /* UIP_CONF_IPV6 */
1632 #endif /* !UIP_CONF_IPV6 */
1636 /* The UDP and IP headers. */
1637 struct uip_udpip_hdr
{
1645 uip_ip6addr_t srcipaddr
, destipaddr
;
1646 #else /* UIP_CONF_IPV6 */
1656 uip_ipaddr_t srcipaddr
, destipaddr
;
1657 #endif /* UIP_CONF_IPV6 */
1667 * In IPv6 the length of the L3 headers before the transport header is
1668 * not fixed, due to the possibility to include extension option headers
1669 * after the IP header. hence we split here L3 and L4 headers
1680 uip_ip6addr_t srcipaddr
, destipaddr
;
1681 #else /* UIP_CONF_IPV6 */
1691 uip_ipaddr_t srcipaddr
, destipaddr
;
1692 #endif /* UIP_CONF_IPV6 */
1697 * IPv6 extension option headers: we are able to process
1698 * the 4 extension headers defined in RFC2460 (IPv6):
1699 * - Hop by hop option header, destination option header:
1700 * These two are not used by any core IPv6 protocol, hence
1701 * we just read them and go to the next. They convey options,
1702 * the options defined in RFC2460 are Pad1 and PadN, which do
1703 * some padding, and that we do not need to read (the length
1704 * field in the header is enough)
1705 * - Routing header: this one is most notably used by MIPv6,
1706 * which we do not implement, hence we just read it and go
1708 * - Fragmentation header: we read this header and are able to
1709 * reassemble packets
1711 * We do not offer any means to send packets with extension headers
1713 * We do not implement Authentication and ESP headers, which are
1714 * used in IPSec and defined in RFC4302,4303,4305,4385
1716 /* common header part */
1717 struct uip_ext_hdr
{
1722 /* Hop by Hop option header */
1723 struct uip_hbho_hdr
{
1728 /* destination option header */
1729 struct uip_desto_hdr
{
1734 /* We do not define structures for PAD1 and PADN options */
1738 * the routing header as 4 common bytes, then routing header type
1739 * specific data there are several types of routing header. Type 0 was
1740 * deprecated as per RFC5095 most notable other type is 2, used in
1741 * RFC3775 (MIPv6) here we do not implement MIPv6, so we just need to
1742 * parse the 4 first bytes
1744 struct uip_routing_hdr
{
1751 /* fragmentation header */
1752 struct uip_frag_hdr
{
1755 u16_t offsetresmore
;
1760 * an option within the destination or hop by hop option headers
1761 * it contains type an length, which is true for all options but PAD1
1763 struct uip_ext_hdr_opt
{
1769 struct uip_ext_hdr_opt_padn
{
1775 struct uip_tcp_hdr
{
1788 /* The ICMP headers. */
1789 struct uip_icmp_hdr
{
1794 #endif /* !UIP_CONF_IPV6 */
1798 /* The UDP headers. */
1799 struct uip_udp_hdr
{
1808 * The buffer size available for user data in the \ref uip_buf buffer.
1810 * This macro holds the available size for user data in the \ref
1811 * uip_buf buffer. The macro is intended to be used for checking
1812 * bounds of available user data.
1816 snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
1821 #define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
1822 #define UIP_APPDATA_PTR (void *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]
1824 #define UIP_PROTO_ICMP 1
1825 #define UIP_PROTO_TCP 6
1826 #define UIP_PROTO_UDP 17
1827 #define UIP_PROTO_ICMP6 58
1832 /** \brief extension headers types */
1833 #define UIP_PROTO_HBHO 0
1834 #define UIP_PROTO_DESTO 60
1835 #define UIP_PROTO_ROUTING 43
1836 #define UIP_PROTO_FRAG 44
1837 #define UIP_PROTO_NONE 59
1841 /** \brief Destination and Hop By Hop extension headers option types */
1842 #define UIP_EXT_HDR_OPT_PAD1 0
1843 #define UIP_EXT_HDR_OPT_PADN 1
1848 * \brief Bitmaps for extension header processing
1850 * When processing extension headers, we should record somehow which one we
1851 * see, because you cannot have twice the same header, except for destination
1852 * We store all this in one u8_t bitmap one bit for each header expected. The
1853 * order in the bitmap is the order recommended in RFC2460
1855 #define UIP_EXT_HDR_BITMAP_HBHO 0x01
1856 #define UIP_EXT_HDR_BITMAP_DESTO1 0x02
1857 #define UIP_EXT_HDR_BITMAP_ROUTING 0x04
1858 #define UIP_EXT_HDR_BITMAP_FRAG 0x08
1859 #define UIP_EXT_HDR_BITMAP_AH 0x10
1860 #define UIP_EXT_HDR_BITMAP_ESP 0x20
1861 #define UIP_EXT_HDR_BITMAP_DESTO2 0x40
1865 #endif /* UIP_CONF_IPV6 */
1870 #define UIP_IPH_LEN 40
1871 #define UIP_FRAGH_LEN 8
1872 #else /* UIP_CONF_IPV6 */
1873 #define UIP_IPH_LEN 20 /* Size of IP header */
1874 #endif /* UIP_CONF_IPV6 */
1876 #define UIP_UDPH_LEN 8 /* Size of UDP header */
1877 #define UIP_TCPH_LEN 20 /* Size of TCP header */
1879 #define UIP_ICMPH_LEN 4 /* Size of ICMP header */
1881 #define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP +
1884 #define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP +
1887 #define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
1888 #define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* size of ICMP
1890 #define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN) /* size of L2
1894 * The sums below are quite used in ND. When used for uip_buf, we
1895 * include link layer length when used for uip_len, we do not, hence
1896 * we need values with and without LLH_LEN we do not use capital
1897 * letters as these values are variable
1899 #define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len)
1900 #define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
1901 #define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len)
1902 #define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
1903 #endif /*UIP_CONF_IPV6*/
1907 extern const uip_ipaddr_t uip_hostaddr
, uip_netmask
, uip_draddr
;
1908 #else /* UIP_FIXEDADDR */
1909 extern uip_ipaddr_t uip_hostaddr
, uip_netmask
, uip_draddr
;
1910 #endif /* UIP_FIXEDADDR */
1911 extern const uip_ipaddr_t uip_broadcast_addr
;
1912 extern const uip_ipaddr_t uip_all_zeroes_addr
;
1914 #if UIP_FIXEDETHADDR
1915 extern const uip_lladdr_t uip_lladdr
;
1917 extern uip_lladdr_t uip_lladdr
;
1923 #ifdef UIP_CONF_IPV6
1925 * \brief Is IPv6 address a the unspecified address
1926 * a is of type uip_ipaddr_t
1928 #define uip_is_addr_unspecified(a) \
1929 ((((a)->u16[0]) == 0) && \
1930 (((a)->u16[1]) == 0) && \
1931 (((a)->u16[2]) == 0) && \
1932 (((a)->u16[3]) == 0) && \
1933 (((a)->u16[4]) == 0) && \
1934 (((a)->u16[5]) == 0) && \
1935 (((a)->u16[6]) == 0) && \
1936 (((a)->u16[7]) == 0))
1938 /** \brief Is IPv6 address a the link local all-nodes multicast address */
1939 #define uip_is_addr_linklocal_allnodes_mcast(a) \
1940 ((((a)->u8[0]) == 0xff) && \
1941 (((a)->u8[1]) == 0x02) && \
1942 (((a)->u16[1]) == 0) && \
1943 (((a)->u16[2]) == 0) && \
1944 (((a)->u16[3]) == 0) && \
1945 (((a)->u16[4]) == 0) && \
1946 (((a)->u16[5]) == 0) && \
1947 (((a)->u16[6]) == 0) && \
1948 (((a)->u8[14]) == 0) && \
1949 (((a)->u8[15]) == 0x01))
1951 /** \brief set IP address a to unspecified */
1952 #define uip_create_unspecified(a) uip_ip6addr(a, 0, 0, 0, 0, 0, 0, 0, 0)
1954 /** \brief set IP address a to the link local all-nodes multicast address */
1955 #define uip_create_linklocal_allnodes_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001)
1957 /** \brief set IP address a to the link local all-routers multicast address */
1958 #define uip_create_linklocal_allrouters_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002)
1961 * \brief is addr (a) a solicited node multicast address, see RFC3513
1962 * a is of type uip_ipaddr_t*
1964 #define uip_is_addr_solicited_node(a) \
1965 ((((a)->u8[0]) == 0xFF) && \
1966 (((a)->u8[1]) == 0x02) && \
1967 (((a)->u16[1]) == 0) && \
1968 (((a)->u16[2]) == 0) && \
1969 (((a)->u16[3]) == 0) && \
1970 (((a)->u16[4]) == 0) && \
1971 (((a)->u16[5]) == 1) && \
1972 (((a)->u8[12]) == 0xFF))
1975 * \briefput in b the solicited node address corresponding to address a
1976 * both a and b are of type uip_ipaddr_t*
1978 #define uip_create_solicited_node(a, b) \
1979 (((b)->u8[0]) = 0xFF); \
1980 (((b)->u8[1]) = 0x02); \
1981 (((b)->u16[1]) = 0); \
1982 (((b)->u16[2]) = 0); \
1983 (((b)->u16[3]) = 0); \
1984 (((b)->u16[4]) = 0); \
1985 (((b)->u8[10]) = 0); \
1986 (((b)->u8[11]) = 0x01); \
1987 (((b)->u8[12]) = 0xFF); \
1988 (((b)->u8[13]) = ((a)->u8[13])); \
1989 (((b)->u16[7]) = ((a)->u16[7]))
1992 * \brief is addr (a) a link local unicast address, see RFC3513
1993 * i.e. is (a) on prefix FE80::/10
1994 * a is of type uip_ipaddr_t*
1996 #define uip_is_addr_link_local(a) \
1997 ((((a)->u8[0]) == 0xFE) && \
1998 (((a)->u8[1]) == 0x80))
2001 * \brief was addr (a) forged based on the mac address m
2002 * a type is uip_ipaddr_t
2003 * m type is uiplladdr_t
2005 #if UIP_CONF_LL_802154
2006 #define uip_is_addr_mac_addr_based(a, m) \
2007 ((((a)->u8[8]) == (((m)->addr[0]) ^ 0x02)) && \
2008 (((a)->u8[9]) == (m)->addr[1]) && \
2009 (((a)->u8[10]) == (m)->addr[2]) && \
2010 (((a)->u8[11]) == (m)->addr[3]) && \
2011 (((a)->u8[12]) == (m)->addr[4]) && \
2012 (((a)->u8[13]) == (m)->addr[5]) && \
2013 (((a)->u8[14]) == (m)->addr[6]) && \
2014 (((a)->u8[15]) == (m)->addr[7]))
2017 #define uip_is_addr_mac_addr_based(a, m) \
2018 ((((a)->u8[8]) == (((m)->addr[0]) | 0x02)) && \
2019 (((a)->u8[9]) == (m)->addr[1]) && \
2020 (((a)->u8[10]) == (m)->addr[2]) && \
2021 (((a)->u8[11]) == 0xff) && \
2022 (((a)->u8[12]) == 0xfe) && \
2023 (((a)->u8[13]) == (m)->addr[3]) && \
2024 (((a)->u8[14]) == (m)->addr[4]) && \
2025 (((a)->u8[15]) == (m)->addr[5]))
2027 #endif /*UIP_CONF_LL_802154*/
2030 * \brief is address a multicast address, see RFC 3513
2031 * a is of type uip_ipaddr_t*
2033 #define uip_is_addr_mcast(a) \
2034 (((a)->u8[0]) == 0xFF)
2037 * \brief is group-id of multicast address a
2038 * the all nodes group-id
2040 #define uip_is_mcast_group_id_all_nodes(a) \
2041 ((((a)->u16[1]) == 0) && \
2042 (((a)->u16[2]) == 0) && \
2043 (((a)->u16[3]) == 0) && \
2044 (((a)->u16[4]) == 0) && \
2045 (((a)->u16[5]) == 0) && \
2046 (((a)->u16[6]) == 0) && \
2047 (((a)->u8[14]) == 0) && \
2048 (((a)->u8[15]) == 1))
2051 * \brief is group-id of multicast address a
2052 * the all routers group-id
2054 #define uip_is_mcast_group_id_all_routers(a) \
2055 ((((a)->u16[1]) == 0) && \
2056 (((a)->u16[2]) == 0) && \
2057 (((a)->u16[3]) == 0) && \
2058 (((a)->u16[4]) == 0) && \
2059 (((a)->u16[5]) == 0) && \
2060 (((a)->u16[6]) == 0) && \
2061 (((a)->u8[14]) == 0) && \
2062 (((a)->u8[15]) == 2))
2065 #endif /*UIP_CONF_IPV6*/
2068 * Calculate the Internet checksum over a buffer.
2070 * The Internet checksum is the one's complement of the one's
2071 * complement sum of all 16-bit words in the buffer.
2075 * \param buf A pointer to the buffer over which the checksum is to be
2078 * \param len The length of the buffer over which the checksum is to
2081 * \return The Internet checksum of the buffer.
2083 u16_t
uip_chksum(u16_t
*buf
, u16_t len
);
2086 * Calculate the IP header checksum of the packet header in uip_buf.
2088 * The IP header checksum is the Internet checksum of the 20 bytes of
2091 * \return The IP header checksum of the IP header in the uip_buf
2094 u16_t
uip_ipchksum(void);
2097 * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
2099 * The TCP checksum is the Internet checksum of data contents of the
2100 * TCP segment, and a pseudo-header as defined in RFC793.
2102 * \return The TCP checksum of the TCP segment in uip_buf and pointed
2103 * to by uip_appdata.
2105 u16_t
uip_tcpchksum(void);
2108 * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
2110 * The UDP checksum is the Internet checksum of data contents of the
2111 * UDP segment, and a pseudo-header as defined in RFC768.
2113 * \return The UDP checksum of the UDP segment in uip_buf and pointed
2114 * to by uip_appdata.
2116 u16_t
uip_udpchksum(void);
2119 * Calculate the ICMP checksum of the packet in uip_buf.
2121 * \return The ICMP checksum of the ICMP packet in uip_buf
2123 u16_t
uip_icmp6chksum(void);
2126 #endif /* __UIP_H__ */