Contiki 2.5
uip.h
Go to the documentation of this file.
1 
2 /**
3  * \addtogroup uip
4  * @{
5  */
6 
7 /**
8  * \file
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)
13  *
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.
17  *
18  */
19 
20 /*
21  * Copyright (c) 2001-2003, Adam Dunkels.
22  * All rights reserved.
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
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
34  * written permission.
35  *
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.
47  *
48  * This file is part of the uIP TCP/IP stack.
49  *
50  * $Id: uip.h,v 1.35 2010/10/19 18:29:04 adamdunkels Exp $
51  *
52  */
53 
54 #ifndef __UIP_H__
55 #define __UIP_H__
56 
57 #include "net/uipopt.h"
58 
59 /**
60  * Representation of an IP address.
61  *
62  */
63 #if UIP_CONF_IPV6
64 typedef union uip_ip6addr_t {
65  u8_t u8[16]; /* Initializer, must come first!!! */
66  u16_t u16[8];
67 } uip_ip6addr_t;
68 
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!!! */
73  u16_t u16[2];
74 #if 0
75  u32_t u32;
76 #endif
79 #endif /* UIP_CONF_IPV6 */
80 
81 
82 /*---------------------------------------------------------------------------*/
83 
84 /** \brief 16 bit 802.15.4 address */
85 typedef struct uip_802154_shortaddr {
86  u8_t addr[2];
88 /** \brief 64 bit 802.15.4 address */
89 typedef struct uip_802154_longaddr {
90  u8_t addr[8];
92 
93 /** \brief 802.11 address */
94 typedef struct uip_80211_addr {
95  u8_t addr[6];
97 
98 /** \brief 802.3 address */
99 typedef struct uip_eth_addr {
100  u8_t addr[6];
101 } uip_eth_addr;
102 
103 
104 #if UIP_CONF_LL_802154
105 /** \brief 802.15.4 address */
107 #define UIP_802154_SHORTADDR_LEN 2
108 #define UIP_802154_LONGADDR_LEN 8
109 #define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN
110 #else /*UIP_CONF_LL_802154*/
111 #if UIP_CONF_LL_80211
112 /** \brief 802.11 address */
114 #define UIP_LLADDR_LEN 6
115 #else /*UIP_CONF_LL_80211*/
116 /** \brief Ethernet address */
118 #define UIP_LLADDR_LEN 6
119 #endif /*UIP_CONF_LL_80211*/
120 #endif /*UIP_CONF_LL_802154*/
121 
122 #include "net/tcpip.h"
123 
124 /*---------------------------------------------------------------------------*/
125 /* First, the functions that should be called from the
126  * system. Initialization, the periodic timer, and incoming packets are
127  * handled by the following three functions.
128  */
129 /**
130  * \defgroup uipconffunc uIP configuration functions
131  * @{
132  *
133  * The uIP configuration functions are used for setting run-time
134  * parameters in uIP such as IP addresses.
135  */
136 
137 /**
138  * Set the IP address of this host.
139  *
140  * The IP address is represented as a 4-byte array where the first
141  * octet of the IP address is put in the first member of the 4-byte
142  * array.
143  *
144  * Example:
145  \code
146 
147  uip_ipaddr_t addr;
148 
149  uip_ipaddr(&addr, 192,168,1,2);
150  uip_sethostaddr(&addr);
151 
152  \endcode
153  * \param addr A pointer to an IP address of type uip_ipaddr_t;
154  *
155  * \sa uip_ipaddr()
156  *
157  * \hideinitializer
158  */
159 #define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr))
160 
161 /**
162  * Get the IP address of this host.
163  *
164  * The IP address is represented as a 4-byte array where the first
165  * octet of the IP address is put in the first member of the 4-byte
166  * array.
167  *
168  * Example:
169  \code
170  uip_ipaddr_t hostaddr;
171 
172  uip_gethostaddr(&hostaddr);
173  \endcode
174  * \param addr A pointer to a uip_ipaddr_t variable that will be
175  * filled in with the currently configured IP address.
176  *
177  * \hideinitializer
178  */
179 #define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr)
180 
181 /**
182  * Set the default router's IP address.
183  *
184  * \param addr A pointer to a uip_ipaddr_t variable containing the IP
185  * address of the default router.
186  *
187  * \sa uip_ipaddr()
188  *
189  * \hideinitializer
190  */
191 #define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr))
192 
193 /**
194  * Set the netmask.
195  *
196  * \param addr A pointer to a uip_ipaddr_t variable containing the IP
197  * address of the netmask.
198  *
199  * \sa uip_ipaddr()
200  *
201  * \hideinitializer
202  */
203 #define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr))
204 
205 
206 /**
207  * Get the default router's IP address.
208  *
209  * \param addr A pointer to a uip_ipaddr_t variable that will be
210  * filled in with the IP address of the default router.
211  *
212  * \hideinitializer
213  */
214 #define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr)
215 
216 /**
217  * Get the netmask.
218  *
219  * \param addr A pointer to a uip_ipaddr_t variable that will be
220  * filled in with the value of the netmask.
221  *
222  * \hideinitializer
223  */
224 #define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask)
225 
226 /** @} */
227 
228 /**
229  * \defgroup uipinit uIP initialization functions
230  * @{
231  *
232  * The uIP initialization functions are used for booting uIP.
233  */
234 
235 /**
236  * uIP initialization function.
237  *
238  * This function should be called at boot up to initilize the uIP
239  * TCP/IP stack.
240  */
241 void uip_init(void);
242 
243 /**
244  * uIP initialization function.
245  *
246  * This function may be used at boot time to set the initial ip_id.
247  */
248 void uip_setipid(u16_t id);
249 
250 /** @} */
251 
252 /**
253  * \defgroup uipdevfunc uIP device driver functions
254  * @{
255  *
256  * These functions are used by a network device driver for interacting
257  * with uIP.
258  */
259 
260 /**
261  * Process an incoming packet.
262  *
263  * This function should be called when the device driver has received
264  * a packet from the network. The packet from the device driver must
265  * be present in the uip_buf buffer, and the length of the packet
266  * should be placed in the uip_len variable.
267  *
268  * When the function returns, there may be an outbound packet placed
269  * in the uip_buf packet buffer. If so, the uip_len variable is set to
270  * the length of the packet. If no packet is to be sent out, the
271  * uip_len variable is set to 0.
272  *
273  * The usual way of calling the function is presented by the source
274  * code below.
275  \code
276  uip_len = devicedriver_poll();
277  if(uip_len > 0) {
278  uip_input();
279  if(uip_len > 0) {
280  devicedriver_send();
281  }
282  }
283  \endcode
284  *
285  * \note If you are writing a uIP device driver that needs ARP
286  * (Address Resolution Protocol), e.g., when running uIP over
287  * Ethernet, you will need to call the uIP ARP code before calling
288  * this function:
289  \code
290  #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
291  uip_len = ethernet_devicedrver_poll();
292  if(uip_len > 0) {
293  if(BUF->type == UIP_HTONS(UIP_ETHTYPE_IP)) {
294  uip_arp_ipin();
295  uip_input();
296  if(uip_len > 0) {
297  uip_arp_out();
298  ethernet_devicedriver_send();
299  }
300  } else if(BUF->type == UIP_HTONS(UIP_ETHTYPE_ARP)) {
301  uip_arp_arpin();
302  if(uip_len > 0) {
303  ethernet_devicedriver_send();
304  }
305  }
306  \endcode
307  *
308  * \hideinitializer
309  */
310 #define uip_input() uip_process(UIP_DATA)
311 
312 
313 /**
314  * Periodic processing for a connection identified by its number.
315  *
316  * This function does the necessary periodic processing (timers,
317  * polling) for a uIP TCP conneciton, and should be called when the
318  * periodic uIP timer goes off. It should be called for every
319  * connection, regardless of whether they are open of closed.
320  *
321  * When the function returns, it may have an outbound packet waiting
322  * for service in the uIP packet buffer, and if so the uip_len
323  * variable is set to a value larger than zero. The device driver
324  * should be called to send out the packet.
325  *
326  * The usual way of calling the function is through a for() loop like
327  * this:
328  \code
329  for(i = 0; i < UIP_CONNS; ++i) {
330  uip_periodic(i);
331  if(uip_len > 0) {
332  devicedriver_send();
333  }
334  }
335  \endcode
336  *
337  * \note If you are writing a uIP device driver that needs ARP
338  * (Address Resolution Protocol), e.g., when running uIP over
339  * Ethernet, you will need to call the uip_arp_out() function before
340  * calling the device driver:
341  \code
342  for(i = 0; i < UIP_CONNS; ++i) {
343  uip_periodic(i);
344  if(uip_len > 0) {
345  uip_arp_out();
346  ethernet_devicedriver_send();
347  }
348  }
349  \endcode
350  *
351  * \param conn The number of the connection which is to be periodically polled.
352  *
353  * \hideinitializer
354  */
355 #if UIP_TCP
356 #define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \
357  uip_process(UIP_TIMER); } while (0)
358 
359 /**
360  *
361  *
362  */
363 #define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED)
364 
365 /**
366  * Perform periodic processing for a connection identified by a pointer
367  * to its structure.
368  *
369  * Same as uip_periodic() but takes a pointer to the actual uip_conn
370  * struct instead of an integer as its argument. This function can be
371  * used to force periodic processing of a specific connection.
372  *
373  * \param conn A pointer to the uip_conn struct for the connection to
374  * be processed.
375  *
376  * \hideinitializer
377  */
378 #define uip_periodic_conn(conn) do { uip_conn = conn; \
379  uip_process(UIP_TIMER); } while (0)
380 
381 /**
382  * Request that a particular connection should be polled.
383  *
384  * Similar to uip_periodic_conn() but does not perform any timer
385  * processing. The application is polled for new data.
386  *
387  * \param conn A pointer to the uip_conn struct for the connection to
388  * be processed.
389  *
390  * \hideinitializer
391  */
392 #define uip_poll_conn(conn) do { uip_conn = conn; \
393  uip_process(UIP_POLL_REQUEST); } while (0)
394 
395 #endif /* UIP_TCP */
396 
397 #if UIP_UDP
398 /**
399  * Periodic processing for a UDP connection identified by its number.
400  *
401  * This function is essentially the same as uip_periodic(), but for
402  * UDP connections. It is called in a similar fashion as the
403  * uip_periodic() function:
404  \code
405  for(i = 0; i < UIP_UDP_CONNS; i++) {
406  uip_udp_periodic(i);
407  if(uip_len > 0) {
408  devicedriver_send();
409  }
410  }
411  \endcode
412  *
413  * \note As for the uip_periodic() function, special care has to be
414  * taken when using uIP together with ARP and Ethernet:
415  \code
416  for(i = 0; i < UIP_UDP_CONNS; i++) {
417  uip_udp_periodic(i);
418  if(uip_len > 0) {
419  uip_arp_out();
420  ethernet_devicedriver_send();
421  }
422  }
423  \endcode
424  *
425  * \param conn The number of the UDP connection to be processed.
426  *
427  * \hideinitializer
428  */
429 #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
430  uip_process(UIP_UDP_TIMER); } while(0)
431 
432 /**
433  * Periodic processing for a UDP connection identified by a pointer to
434  * its structure.
435  *
436  * Same as uip_udp_periodic() but takes a pointer to the actual
437  * uip_conn struct instead of an integer as its argument. This
438  * function can be used to force periodic processing of a specific
439  * connection.
440  *
441  * \param conn A pointer to the uip_udp_conn struct for the connection
442  * to be processed.
443  *
444  * \hideinitializer
445  */
446 #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
447  uip_process(UIP_UDP_TIMER); } while(0)
448 #endif /* UIP_UDP */
449 
450 /** \brief Abandon the reassembly of the current packet */
451 void uip_reass_over(void);
452 
453 /**
454  * The uIP packet buffer.
455  *
456  * The uip_buf array is used to hold incoming and outgoing
457  * packets. The device driver should place incoming data into this
458  * buffer. When sending data, the device driver should read the link
459  * level headers and the TCP/IP headers from this buffer. The size of
460  * the link level headers is configured by the UIP_LLH_LEN define.
461  *
462  * \note The application data need not be placed in this buffer, so
463  * the device driver must read it from the place pointed to by the
464  * uip_appdata pointer as illustrated by the following example:
465  \code
466  void
467  devicedriver_send(void)
468  {
469  hwsend(&uip_buf[0], UIP_LLH_LEN);
470  if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
471  hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
472  } else {
473  hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
474  hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
475  }
476  }
477  \endcode
478 */
479 
480 typedef union {
481  uint32_t u32[(UIP_BUFSIZE + 3) / 4];
482  uint8_t u8[UIP_BUFSIZE];
483 } uip_buf_t;
484 
485 CCIF extern uip_buf_t uip_aligned_buf;
486 #define uip_buf (uip_aligned_buf.u8)
487 
488 
489 /** @} */
490 
491 /*---------------------------------------------------------------------------*/
492 /* Functions that are used by the uIP application program. Opening and
493  * closing connections, sending and receiving data, etc. is all
494  * handled by the functions below.
495  */
496 /**
497  * \defgroup uipappfunc uIP application functions
498  * @{
499  *
500  * Functions used by an application running of top of uIP.
501  */
502 
503 /**
504  * Start listening to the specified port.
505  *
506  * \note Since this function expects the port number in network byte
507  * order, a conversion using UIP_HTONS() or uip_htons() is necessary.
508  *
509  \code
510  uip_listen(UIP_HTONS(80));
511  \endcode
512  *
513  * \param port A 16-bit port number in network byte order.
514  */
515 void uip_listen(u16_t port);
516 
517 /**
518  * Stop listening to the specified port.
519  *
520  * \note Since this function expects the port number in network byte
521  * order, a conversion using UIP_HTONS() or uip_htons() is necessary.
522  *
523  \code
524  uip_unlisten(UIP_HTONS(80));
525  \endcode
526  *
527  * \param port A 16-bit port number in network byte order.
528  */
529 void uip_unlisten(u16_t port);
530 
531 /**
532  * Connect to a remote host using TCP.
533  *
534  * This function is used to start a new connection to the specified
535  * port on the specified host. It allocates a new connection identifier,
536  * sets the connection to the SYN_SENT state and sets the
537  * retransmission timer to 0. This will cause a TCP SYN segment to be
538  * sent out the next time this connection is periodically processed,
539  * which usually is done within 0.5 seconds after the call to
540  * uip_connect().
541  *
542  * \note This function is available only if support for active open
543  * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
544  *
545  * \note Since this function requires the port number to be in network
546  * byte order, a conversion using UIP_HTONS() or uip_htons() is necessary.
547  *
548  \code
549  uip_ipaddr_t ipaddr;
550 
551  uip_ipaddr(&ipaddr, 192,168,1,2);
552  uip_connect(&ipaddr, UIP_HTONS(80));
553  \endcode
554  *
555  * \param ripaddr The IP address of the remote host.
556  *
557  * \param port A 16-bit port number in network byte order.
558  *
559  * \return A pointer to the uIP connection identifier for the new connection,
560  * or NULL if no connection could be allocated.
561  *
562  */
563 struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, u16_t port);
564 
565 
566 
567 /**
568  * \internal
569  *
570  * Check if a connection has outstanding (i.e., unacknowledged) data.
571  *
572  * \param conn A pointer to the uip_conn structure for the connection.
573  *
574  * \hideinitializer
575  */
576 #define uip_outstanding(conn) ((conn)->len)
577 
578 /**
579  * Send data on the current connection.
580  *
581  * This function is used to send out a single segment of TCP
582  * data. Only applications that have been invoked by uIP for event
583  * processing can send data.
584  *
585  * The amount of data that actually is sent out after a call to this
586  * function is determined by the maximum amount of data TCP allows. uIP
587  * will automatically crop the data so that only the appropriate
588  * amount of data is sent. The function uip_mss() can be used to query
589  * uIP for the amount of data that actually will be sent.
590  *
591  * \note This function does not guarantee that the sent data will
592  * arrive at the destination. If the data is lost in the network, the
593  * application will be invoked with the uip_rexmit() event being
594  * set. The application will then have to resend the data using this
595  * function.
596  *
597  * \param data A pointer to the data which is to be sent.
598  *
599  * \param len The maximum amount of data bytes to be sent.
600  *
601  * \hideinitializer
602  */
603 CCIF void uip_send(const void *data, int len);
604 
605 /**
606  * The length of any incoming data that is currently available (if available)
607  * in the uip_appdata buffer.
608  *
609  * The test function uip_data() must first be used to check if there
610  * is any data available at all.
611  *
612  * \hideinitializer
613  */
614 /*void uip_datalen(void);*/
615 #define uip_datalen() uip_len
616 
617 /**
618  * The length of any out-of-band data (urgent data) that has arrived
619  * on the connection.
620  *
621  * \note The configuration parameter UIP_URGDATA must be set for this
622  * function to be enabled.
623  *
624  * \hideinitializer
625  */
626 #define uip_urgdatalen() uip_urglen
627 
628 /**
629  * Close the current connection.
630  *
631  * This function will close the current connection in a nice way.
632  *
633  * \hideinitializer
634  */
635 #define uip_close() (uip_flags = UIP_CLOSE)
636 
637 /**
638  * Abort the current connection.
639  *
640  * This function will abort (reset) the current connection, and is
641  * usually used when an error has occurred that prevents using the
642  * uip_close() function.
643  *
644  * \hideinitializer
645  */
646 #define uip_abort() (uip_flags = UIP_ABORT)
647 
648 /**
649  * Tell the sending host to stop sending data.
650  *
651  * This function will close our receiver's window so that we stop
652  * receiving data for the current connection.
653  *
654  * \hideinitializer
655  */
656 #define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)
657 
658 /**
659  * Find out if the current connection has been previously stopped with
660  * uip_stop().
661  *
662  * \hideinitializer
663  */
664 #define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED)
665 
666 /**
667  * Restart the current connection, if is has previously been stopped
668  * with uip_stop().
669  *
670  * This function will open the receiver's window again so that we
671  * start receiving data for the current connection.
672  *
673  * \hideinitializer
674  */
675 #define uip_restart() do { uip_flags |= UIP_NEWDATA; \
676  uip_conn->tcpstateflags &= ~UIP_STOPPED; \
677  } while(0)
678 
679 
680 /* uIP tests that can be made to determine in what state the current
681  connection is, and what the application function should do. */
682 
683 /**
684  * Is the current connection a UDP connection?
685  *
686  * This function checks whether the current connection is a UDP connection.
687  *
688  * \hideinitializer
689  *
690  */
691 #define uip_udpconnection() (uip_conn == NULL)
692 
693 /**
694  * Is new incoming data available?
695  *
696  * Will reduce to non-zero if there is new data for the application
697  * present at the uip_appdata pointer. The size of the data is
698  * available through the uip_len variable.
699  *
700  * \hideinitializer
701  */
702 #define uip_newdata() (uip_flags & UIP_NEWDATA)
703 
704 /**
705  * Has previously sent data been acknowledged?
706  *
707  * Will reduce to non-zero if the previously sent data has been
708  * acknowledged by the remote host. This means that the application
709  * can send new data.
710  *
711  * \hideinitializer
712  */
713 #define uip_acked() (uip_flags & UIP_ACKDATA)
714 
715 /**
716  * Has the connection just been connected?
717  *
718  * Reduces to non-zero if the current connection has been connected to
719  * a remote host. This will happen both if the connection has been
720  * actively opened (with uip_connect()) or passively opened (with
721  * uip_listen()).
722  *
723  * \hideinitializer
724  */
725 #define uip_connected() (uip_flags & UIP_CONNECTED)
726 
727 /**
728  * Has the connection been closed by the other end?
729  *
730  * Is non-zero if the connection has been closed by the remote
731  * host. The application may then do the necessary clean-ups.
732  *
733  * \hideinitializer
734  */
735 #define uip_closed() (uip_flags & UIP_CLOSE)
736 
737 /**
738  * Has the connection been aborted by the other end?
739  *
740  * Non-zero if the current connection has been aborted (reset) by the
741  * remote host.
742  *
743  * \hideinitializer
744  */
745 #define uip_aborted() (uip_flags & UIP_ABORT)
746 
747 /**
748  * Has the connection timed out?
749  *
750  * Non-zero if the current connection has been aborted due to too many
751  * retransmissions.
752  *
753  * \hideinitializer
754  */
755 #define uip_timedout() (uip_flags & UIP_TIMEDOUT)
756 
757 /**
758  * Do we need to retransmit previously data?
759  *
760  * Reduces to non-zero if the previously sent data has been lost in
761  * the network, and the application should retransmit it. The
762  * application should send the exact same data as it did the last
763  * time, using the uip_send() function.
764  *
765  * \hideinitializer
766  */
767 #define uip_rexmit() (uip_flags & UIP_REXMIT)
768 
769 /**
770  * Is the connection being polled by uIP?
771  *
772  * Is non-zero if the reason the application is invoked is that the
773  * current connection has been idle for a while and should be
774  * polled.
775  *
776  * The polling event can be used for sending data without having to
777  * wait for the remote host to send data.
778  *
779  * \hideinitializer
780  */
781 #define uip_poll() (uip_flags & UIP_POLL)
782 
783 /**
784  * Get the initial maximum segment size (MSS) of the current
785  * connection.
786  *
787  * \hideinitializer
788  */
789 #define uip_initialmss() (uip_conn->initialmss)
790 
791 /**
792  * Get the current maximum segment size that can be sent on the current
793  * connection.
794  *
795  * The current maximum segment size that can be sent on the
796  * connection is computed from the receiver's window and the MSS of
797  * the connection (which also is available by calling
798  * uip_initialmss()).
799  *
800  * \hideinitializer
801  */
802 #define uip_mss() (uip_conn->mss)
803 
804 /**
805  * Set up a new UDP connection.
806  *
807  * This function sets up a new UDP connection. The function will
808  * automatically allocate an unused local port for the new
809  * connection. However, another port can be chosen by using the
810  * uip_udp_bind() call, after the uip_udp_new() function has been
811  * called.
812  *
813  * Example:
814  \code
815  uip_ipaddr_t addr;
816  struct uip_udp_conn *c;
817 
818  uip_ipaddr(&addr, 192,168,2,1);
819  c = uip_udp_new(&addr, UIP_HTONS(12345));
820  if(c != NULL) {
821  uip_udp_bind(c, UIP_HTONS(12344));
822  }
823  \endcode
824  * \param ripaddr The IP address of the remote host.
825  *
826  * \param rport The remote port number in network byte order.
827  *
828  * \return The uip_udp_conn structure for the new connection or NULL
829  * if no connection could be allocated.
830  */
831 struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, u16_t rport);
832 
833 /**
834  * Removed a UDP connection.
835  *
836  * \param conn A pointer to the uip_udp_conn structure for the connection.
837  *
838  * \hideinitializer
839  */
840 #define uip_udp_remove(conn) (conn)->lport = 0
841 
842 /**
843  * Bind a UDP connection to a local port.
844  *
845  * \param conn A pointer to the uip_udp_conn structure for the
846  * connection.
847  *
848  * \param port The local port number, in network byte order.
849  *
850  * \hideinitializer
851  */
852 #define uip_udp_bind(conn, port) (conn)->lport = port
853 
854 /**
855  * Send a UDP datagram of length len on the current connection.
856  *
857  * This function can only be called in response to a UDP event (poll
858  * or newdata). The data must be present in the uip_buf buffer, at the
859  * place pointed to by the uip_appdata pointer.
860  *
861  * \param len The length of the data in the uip_buf buffer.
862  *
863  * \hideinitializer
864  */
865 #define uip_udp_send(len) uip_send((char *)uip_appdata, len)
866 
867 /** @} */
868 
869 /* uIP convenience and converting functions. */
870 
871 /**
872  * \defgroup uipconvfunc uIP conversion functions
873  * @{
874  *
875  * These functions can be used for converting between different data
876  * formats used by uIP.
877  */
878 
879 /**
880  * Convert an IP address to four bytes separated by commas.
881  *
882  * Example:
883  \code
884  uip_ipaddr_t ipaddr;
885  printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr));
886  \endcode
887  *
888  * \param a A pointer to a uip_ipaddr_t.
889  * \hideinitializer
890  */
891 #define uip_ipaddr_to_quad(a) (a)->u8[0],(a)->u8[1],(a)->u8[2],(a)->u8[3]
892 
893 /**
894  * Construct an IP address from four bytes.
895  *
896  * This function constructs an IP address of the type that uIP handles
897  * internally from four bytes. The function is handy for specifying IP
898  * addresses to use with e.g. the uip_connect() function.
899  *
900  * Example:
901  \code
902  uip_ipaddr_t ipaddr;
903  struct uip_conn *c;
904 
905  uip_ipaddr(&ipaddr, 192,168,1,2);
906  c = uip_connect(&ipaddr, UIP_HTONS(80));
907  \endcode
908  *
909  * \param addr A pointer to a uip_ipaddr_t variable that will be
910  * filled in with the IP address.
911  *
912  * \param addr0 The first octet of the IP address.
913  * \param addr1 The second octet of the IP address.
914  * \param addr2 The third octet of the IP address.
915  * \param addr3 The forth octet of the IP address.
916  *
917  * \hideinitializer
918  */
919 #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
920  (addr)->u8[0] = addr0; \
921  (addr)->u8[1] = addr1; \
922  (addr)->u8[2] = addr2; \
923  (addr)->u8[3] = addr3; \
924  } while(0)
925 
926 /**
927  * Construct an IPv6 address from eight 16-bit words.
928  *
929  * This function constructs an IPv6 address.
930  *
931  * \hideinitializer
932  */
933 #define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
934  (addr)->u16[0] = UIP_HTONS(addr0); \
935  (addr)->u16[1] = UIP_HTONS(addr1); \
936  (addr)->u16[2] = UIP_HTONS(addr2); \
937  (addr)->u16[3] = UIP_HTONS(addr3); \
938  (addr)->u16[4] = UIP_HTONS(addr4); \
939  (addr)->u16[5] = UIP_HTONS(addr5); \
940  (addr)->u16[6] = UIP_HTONS(addr6); \
941  (addr)->u16[7] = UIP_HTONS(addr7); \
942  } while(0)
943 
944 /**
945  * Construct an IPv6 address from eight 8-bit words.
946  *
947  * This function constructs an IPv6 address.
948  *
949  * \hideinitializer
950  */
951 #define uip_ip6addr_u8(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7,addr8,addr9,addr10,addr11,addr12,addr13,addr14,addr15) do { \
952  (addr)->u8[0] = addr0; \
953  (addr)->u8[1] = addr1; \
954  (addr)->u8[2] = addr2; \
955  (addr)->u8[3] = addr3; \
956  (addr)->u8[4] = addr4; \
957  (addr)->u8[5] = addr5; \
958  (addr)->u8[6] = addr6; \
959  (addr)->u8[7] = addr7; \
960  (addr)->u8[8] = addr8; \
961  (addr)->u8[9] = addr9; \
962  (addr)->u8[10] = addr10; \
963  (addr)->u8[11] = addr11; \
964  (addr)->u8[12] = addr12; \
965  (addr)->u8[13] = addr13; \
966  (addr)->u8[14] = addr14; \
967  (addr)->u8[15] = addr15; \
968  } while(0)
969 
970 
971 /**
972  * Copy an IP address to another IP address.
973  *
974  * Copies an IP address from one place to another.
975  *
976  * Example:
977  \code
978  uip_ipaddr_t ipaddr1, ipaddr2;
979 
980  uip_ipaddr(&ipaddr1, 192,16,1,2);
981  uip_ipaddr_copy(&ipaddr2, &ipaddr1);
982  \endcode
983  *
984  * \param dest The destination for the copy.
985  * \param src The source from where to copy.
986  *
987  * \hideinitializer
988  */
989 #ifndef uip_ipaddr_copy
990 #define uip_ipaddr_copy(dest, src) (*(dest) = *(src))
991 #endif
992 
993 /**
994  * Compare two IP addresses
995  *
996  * Compares two IP addresses.
997  *
998  * Example:
999  \code
1000  uip_ipaddr_t ipaddr1, ipaddr2;
1001 
1002  uip_ipaddr(&ipaddr1, 192,16,1,2);
1003  if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
1004  printf("They are the same");
1005  }
1006  \endcode
1007  *
1008  * \param addr1 The first IP address.
1009  * \param addr2 The second IP address.
1010  *
1011  * \hideinitializer
1012  */
1013 #if !UIP_CONF_IPV6
1014 #define uip_ipaddr_cmp(addr1, addr2) ((addr1)->u16[0] == (addr2)->u16[0] && \
1015  (addr1)->u16[1] == (addr2)->u16[1])
1016 #else /* !UIP_CONF_IPV6 */
1017 #define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
1018 #endif /* !UIP_CONF_IPV6 */
1019 
1020 /**
1021  * Compare two IP addresses with netmasks
1022  *
1023  * Compares two IP addresses with netmasks. The masks are used to mask
1024  * out the bits that are to be compared.
1025  *
1026  * Example:
1027  \code
1028  uip_ipaddr_t ipaddr1, ipaddr2, mask;
1029 
1030  uip_ipaddr(&mask, 255,255,255,0);
1031  uip_ipaddr(&ipaddr1, 192,16,1,2);
1032  uip_ipaddr(&ipaddr2, 192,16,1,3);
1033  if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
1034  printf("They are the same");
1035  }
1036  \endcode
1037  *
1038  * \param addr1 The first IP address.
1039  * \param addr2 The second IP address.
1040  * \param mask The netmask.
1041  *
1042  * \hideinitializer
1043  */
1044 #if !UIP_CONF_IPV6
1045 #define uip_ipaddr_maskcmp(addr1, addr2, mask) \
1046  (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \
1047  (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \
1048  ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \
1049  (((u16_t *)addr2)[1] & ((u16_t *)mask)[1])))
1050 #else
1051 #define uip_ipaddr_prefixcmp(addr1, addr2, length) (memcmp(addr1, addr2, length>>3) == 0)
1052 #endif
1053 
1054 
1055 /**
1056  * Check if an address is a broadcast address for a network.
1057  *
1058  * Checks if an address is the broadcast address for a network. The
1059  * network is defined by an IP address that is on the network and the
1060  * network's netmask.
1061  *
1062  * \param addr The IP address.
1063  * \param netaddr The network's IP address.
1064  * \param netmask The network's netmask.
1065  *
1066  * \hideinitializer
1067  */
1068 /*#define uip_ipaddr_isbroadcast(addr, netaddr, netmask)
1069  ((uip_ipaddr_t *)(addr)).u16 & ((uip_ipaddr_t *)(addr)).u16*/
1070 
1071 
1072 
1073 /**
1074  * Mask out the network part of an IP address.
1075  *
1076  * Masks out the network part of an IP address, given the address and
1077  * the netmask.
1078  *
1079  * Example:
1080  \code
1081  uip_ipaddr_t ipaddr1, ipaddr2, netmask;
1082 
1083  uip_ipaddr(&ipaddr1, 192,16,1,2);
1084  uip_ipaddr(&netmask, 255,255,255,0);
1085  uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
1086  \endcode
1087  *
1088  * In the example above, the variable "ipaddr2" will contain the IP
1089  * address 192.168.1.0.
1090  *
1091  * \param dest Where the result is to be placed.
1092  * \param src The IP address.
1093  * \param mask The netmask.
1094  *
1095  * \hideinitializer
1096  */
1097 #define uip_ipaddr_mask(dest, src, mask) do { \
1098  ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \
1099  ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \
1100  } while(0)
1101 
1102 /**
1103  * Pick the first octet of an IP address.
1104  *
1105  * Picks out the first octet of an IP address.
1106  *
1107  * Example:
1108  \code
1109  uip_ipaddr_t ipaddr;
1110  u8_t octet;
1111 
1112  uip_ipaddr(&ipaddr, 1,2,3,4);
1113  octet = uip_ipaddr1(&ipaddr);
1114  \endcode
1115  *
1116  * In the example above, the variable "octet" will contain the value 1.
1117  *
1118  * \hideinitializer
1119  */
1120 #define uip_ipaddr1(addr) ((addr)->u8[0])
1121 
1122 /**
1123  * Pick the second octet of an IP address.
1124  *
1125  * Picks out the second octet of an IP address.
1126  *
1127  * Example:
1128  \code
1129  uip_ipaddr_t ipaddr;
1130  u8_t octet;
1131 
1132  uip_ipaddr(&ipaddr, 1,2,3,4);
1133  octet = uip_ipaddr2(&ipaddr);
1134  \endcode
1135  *
1136  * In the example above, the variable "octet" will contain the value 2.
1137  *
1138  * \hideinitializer
1139  */
1140 #define uip_ipaddr2(addr) ((addr)->u8[1])
1141 
1142 /**
1143  * Pick the third octet of an IP address.
1144  *
1145  * Picks out the third octet of an IP address.
1146  *
1147  * Example:
1148  \code
1149  uip_ipaddr_t ipaddr;
1150  u8_t octet;
1151 
1152  uip_ipaddr(&ipaddr, 1,2,3,4);
1153  octet = uip_ipaddr3(&ipaddr);
1154  \endcode
1155  *
1156  * In the example above, the variable "octet" will contain the value 3.
1157  *
1158  * \hideinitializer
1159  */
1160 #define uip_ipaddr3(addr) ((addr)->u8[2])
1161 
1162 /**
1163  * Pick the fourth octet of an IP address.
1164  *
1165  * Picks out the fourth octet of an IP address.
1166  *
1167  * Example:
1168  \code
1169  uip_ipaddr_t ipaddr;
1170  u8_t octet;
1171 
1172  uip_ipaddr(&ipaddr, 1,2,3,4);
1173  octet = uip_ipaddr4(&ipaddr);
1174  \endcode
1175  *
1176  * In the example above, the variable "octet" will contain the value 4.
1177  *
1178  * \hideinitializer
1179  */
1180 #define uip_ipaddr4(addr) ((addr)->u8[3])
1181 
1182 /**
1183  * Convert 16-bit quantity from host byte order to network byte order.
1184  *
1185  * This macro is primarily used for converting constants from host
1186  * byte order to network byte order. For converting variables to
1187  * network byte order, use the uip_htons() function instead.
1188  *
1189  * \hideinitializer
1190  */
1191 #ifndef UIP_HTONS
1192 # if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
1193 # define UIP_HTONS(n) (n)
1194 # define UIP_HTONL(n) (n)
1195 # else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
1196 # define UIP_HTONS(n) (u16_t)((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8))
1197 # define UIP_HTONL(n) (((u32_t)UIP_HTONS(n) << 16) | UIP_HTONS((u32_t)(n) >> 16))
1198 # endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
1199 #else
1200 #error "UIP_HTONS already defined!"
1201 #endif /* UIP_HTONS */
1202 
1203 /**
1204  * Convert 16-bit quantity from host byte order to network byte order.
1205  *
1206  * This function is primarily used for converting variables from host
1207  * byte order to network byte order. For converting constants to
1208  * network byte order, use the UIP_HTONS() macro instead.
1209  */
1210 #ifndef uip_htons
1211 CCIF u16_t uip_htons(u16_t val);
1212 #endif /* uip_htons */
1213 #ifndef uip_ntohs
1214 #define uip_ntohs uip_htons
1215 #endif
1216 
1217 #ifndef uip_htonl
1218 CCIF u32_t uip_htonl(u32_t val);
1219 #endif /* uip_htonl */
1220 #ifndef uip_ntohl
1221 #define uip_ntohl uip_htonl
1222 #endif
1223 
1224 /** @} */
1225 
1226 /**
1227  * Pointer to the application data in the packet buffer.
1228  *
1229  * This pointer points to the application data when the application is
1230  * called. If the application wishes to send data, the application may
1231  * use this space to write the data into before calling uip_send().
1232  */
1233 CCIF extern void *uip_appdata;
1234 
1235 #if UIP_URGDATA > 0
1236 /* u8_t *uip_urgdata:
1237  *
1238  * This pointer points to any urgent data that has been received. Only
1239  * present if compiled with support for urgent data (UIP_URGDATA).
1240  */
1241 extern void *uip_urgdata;
1242 #endif /* UIP_URGDATA > 0 */
1243 
1244 
1245 /**
1246  * \defgroup uipdrivervars Variables used in uIP device drivers
1247  * @{
1248  *
1249  * uIP has a few global variables that are used in device drivers for
1250  * uIP.
1251  */
1252 
1253 /**
1254  * The length of the packet in the uip_buf buffer.
1255  *
1256  * The global variable uip_len holds the length of the packet in the
1257  * uip_buf buffer.
1258  *
1259  * When the network device driver calls the uIP input function,
1260  * uip_len should be set to the length of the packet in the uip_buf
1261  * buffer.
1262  *
1263  * When sending packets, the device driver should use the contents of
1264  * the uip_len variable to determine the length of the outgoing
1265  * packet.
1266  *
1267  */
1268 CCIF extern u16_t uip_len;
1269 
1270 /**
1271  * The length of the extension headers
1272  */
1273 extern u8_t uip_ext_len;
1274 /** @} */
1275 
1276 #if UIP_URGDATA > 0
1277 extern u16_t uip_urglen, uip_surglen;
1278 #endif /* UIP_URGDATA > 0 */
1279 
1280 
1281 /**
1282  * Representation of a uIP TCP connection.
1283  *
1284  * The uip_conn structure is used for identifying a connection. All
1285  * but one field in the structure are to be considered read-only by an
1286  * application. The only exception is the appstate field whose purpose
1287  * is to let the application store application-specific state (e.g.,
1288  * file pointers) for the connection. The type of this field is
1289  * configured in the "uipopt.h" header file.
1290  */
1291 struct uip_conn {
1292  uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */
1293 
1294  u16_t lport; /**< The local TCP port, in network byte order. */
1295  u16_t rport; /**< The local remote TCP port, in network byte
1296  order. */
1297 
1298  u8_t rcv_nxt[4]; /**< The sequence number that we expect to
1299  receive next. */
1300  u8_t snd_nxt[4]; /**< The sequence number that was last sent by
1301  us. */
1302  u16_t len; /**< Length of the data that was previously sent. */
1303  u16_t mss; /**< Current maximum segment size for the
1304  connection. */
1305  u16_t initialmss; /**< Initial maximum segment size for the
1306  connection. */
1307  u8_t sa; /**< Retransmission time-out calculation state
1308  variable. */
1309  u8_t sv; /**< Retransmission time-out calculation state
1310  variable. */
1311  u8_t rto; /**< Retransmission time-out. */
1312  u8_t tcpstateflags; /**< TCP state and flags. */
1313  u8_t timer; /**< The retransmission timer. */
1314  u8_t nrtx; /**< The number of retransmissions for the last
1315  segment sent. */
1316 
1317  /** The application state. */
1319 };
1320 
1321 
1322 /**
1323  * Pointer to the current TCP connection.
1324  *
1325  * The uip_conn pointer can be used to access the current TCP
1326  * connection.
1327  */
1328 
1329 CCIF extern struct uip_conn *uip_conn;
1330 #if UIP_TCP
1331 /* The array containing all uIP connections. */
1332 CCIF extern struct uip_conn uip_conns[UIP_CONNS];
1333 #endif
1334 
1335 /**
1336  * \addtogroup uiparch
1337  * @{
1338  */
1339 
1340 /**
1341  * 4-byte array used for the 32-bit sequence number calculations.
1342  */
1343 extern u8_t uip_acc32[4];
1344 /** @} */
1345 
1346 /**
1347  * Representation of a uIP UDP connection.
1348  */
1350  uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */
1351  u16_t lport; /**< The local port number in network byte order. */
1352  u16_t rport; /**< The remote port number in network byte order. */
1353  u8_t ttl; /**< Default time-to-live. */
1354 
1355  /** The application state. */
1357 };
1358 
1359 /**
1360  * The current UDP connection.
1361  */
1362 extern struct uip_udp_conn *uip_udp_conn;
1363 extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
1364 
1365 struct uip_fallback_interface {
1366  void (*init)(void);
1367  void (*output)(void);
1368 };
1369 
1370 #if UIP_CONF_ICMP6
1371 struct uip_icmp6_conn {
1372  uip_icmp6_appstate_t appstate;
1373 };
1374 extern struct uip_icmp6_conn uip_icmp6_conns;
1375 #endif /*UIP_CONF_ICMP6*/
1376 
1377 /**
1378  * The uIP TCP/IP statistics.
1379  *
1380  * This is the variable in which the uIP TCP/IP statistics are gathered.
1381  */
1382 #if UIP_STATISTICS == 1
1383 extern struct uip_stats uip_stat;
1384 #define UIP_STAT(s) s
1385 #else
1386 #define UIP_STAT(s)
1387 #endif /* UIP_STATISTICS == 1 */
1388 
1389 /**
1390  * The structure holding the TCP/IP statistics that are gathered if
1391  * UIP_STATISTICS is set to 1.
1392  *
1393  */
1394 struct uip_stats {
1395  struct {
1396  uip_stats_t recv; /**< Number of received packets at the IP
1397  layer. */
1398  uip_stats_t sent; /**< Number of sent packets at the IP
1399  layer. */
1400  uip_stats_t forwarded;/**< Number of forwarded packets at the IP
1401  layer. */
1402  uip_stats_t drop; /**< Number of dropped packets at the IP
1403  layer. */
1404  uip_stats_t vhlerr; /**< Number of packets dropped due to wrong
1405  IP version or header length. */
1406  uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
1407  IP length, high byte. */
1408  uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
1409  IP length, low byte. */
1410  uip_stats_t fragerr; /**< Number of packets dropped since they
1411  were IP fragments. */
1412  uip_stats_t chkerr; /**< Number of packets dropped due to IP
1413  checksum errors. */
1414  uip_stats_t protoerr; /**< Number of packets dropped since they
1415  were neither ICMP, UDP nor TCP. */
1416  } ip; /**< IP statistics. */
1417  struct {
1418  uip_stats_t recv; /**< Number of received ICMP packets. */
1419  uip_stats_t sent; /**< Number of sent ICMP packets. */
1420  uip_stats_t drop; /**< Number of dropped ICMP packets. */
1421  uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
1422  type. */
1423  uip_stats_t chkerr; /**< Number of ICMP packets with a bad
1424  checksum. */
1425  } icmp; /**< ICMP statistics. */
1426 #if UIP_TCP
1427  struct {
1428  uip_stats_t recv; /**< Number of recived TCP segments. */
1429  uip_stats_t sent; /**< Number of sent TCP segments. */
1430  uip_stats_t drop; /**< Number of dropped TCP segments. */
1431  uip_stats_t chkerr; /**< Number of TCP segments with a bad
1432  checksum. */
1433  uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK
1434  number. */
1435  uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */
1436  uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */
1437  uip_stats_t syndrop; /**< Number of dropped SYNs due to too few
1438  connections was avaliable. */
1439  uip_stats_t synrst; /**< Number of SYNs for closed ports,
1440  triggering a RST. */
1441  } tcp; /**< TCP statistics. */
1442 #endif
1443 #if UIP_UDP
1444  struct {
1445  uip_stats_t drop; /**< Number of dropped UDP segments. */
1446  uip_stats_t recv; /**< Number of recived UDP segments. */
1447  uip_stats_t sent; /**< Number of sent UDP segments. */
1448  uip_stats_t chkerr; /**< Number of UDP segments with a bad
1449  checksum. */
1450  } udp; /**< UDP statistics. */
1451 #endif /* UIP_UDP */
1452 #if UIP_CONF_IPV6
1453  struct {
1454  uip_stats_t drop; /**< Number of dropped ND6 packets. */
1455  uip_stats_t recv; /**< Number of recived ND6 packets */
1456  uip_stats_t sent; /**< Number of sent ND6 packets */
1457  } nd6;
1458 #endif /*UIP_CONF_IPV6*/
1459 };
1460 
1461 
1462 /*---------------------------------------------------------------------------*/
1463 /* All the stuff below this point is internal to uIP and should not be
1464  * used directly by an application or by a device driver.
1465  */
1466 /*---------------------------------------------------------------------------*/
1467 
1468 
1469 
1470 /* u8_t uip_flags:
1471  *
1472  * When the application is called, uip_flags will contain the flags
1473  * that are defined in this file. Please read below for more
1474  * information.
1475  */
1476 CCIF extern u8_t uip_flags;
1477 
1478 /* The following flags may be set in the global variable uip_flags
1479  before calling the application callback. The UIP_ACKDATA,
1480  UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
1481  whereas the others are mutually exclusive. Note that these flags
1482  should *NOT* be accessed directly, but only through the uIP
1483  functions/macros. */
1484 
1485 #define UIP_ACKDATA 1 /* Signifies that the outstanding data was
1486  acked and the application should send
1487  out new data instead of retransmitting
1488  the last data. */
1489 #define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
1490  us new data. */
1491 #define UIP_REXMIT 4 /* Tells the application to retransmit the
1492  data that was last sent. */
1493 #define UIP_POLL 8 /* Used for polling the application, to
1494  check if the application has data that
1495  it wants to send. */
1496 #define UIP_CLOSE 16 /* The remote host has closed the
1497  connection, thus the connection has
1498  gone away. Or the application signals
1499  that it wants to close the
1500  connection. */
1501 #define UIP_ABORT 32 /* The remote host has aborted the
1502  connection, thus the connection has
1503  gone away. Or the application signals
1504  that it wants to abort the
1505  connection. */
1506 #define UIP_CONNECTED 64 /* We have got a connection from a remote
1507  host and have set up a new connection
1508  for it, or an active connection has
1509  been successfully established. */
1510 
1511 #define UIP_TIMEDOUT 128 /* The connection has been aborted due to
1512  too many retransmissions. */
1513 
1514 
1515 /**
1516  * \brief process the options within a hop by hop or destination option header
1517  * \retval 0: nothing to send,
1518  * \retval 1: drop pkt
1519  * \retval 2: ICMP error message to send
1520 */
1521 /*static u8_t
1522 uip_ext_hdr_options_process(); */
1523 
1524 /* uip_process(flag):
1525  *
1526  * The actual uIP function which does all the work.
1527  */
1528 void uip_process(u8_t flag);
1529 
1530  /* The following flags are passed as an argument to the uip_process()
1531  function. They are used to distinguish between the two cases where
1532  uip_process() is called. It can be called either because we have
1533  incoming data that should be processed, or because the periodic
1534  timer has fired. These values are never used directly, but only in
1535  the macros defined in this file. */
1536 
1537 #define UIP_DATA 1 /* Tells uIP that there is incoming
1538  data in the uip_buf buffer. The
1539  length of the data is stored in the
1540  global variable uip_len. */
1541 #define UIP_TIMER 2 /* Tells uIP that the periodic timer
1542  has fired. */
1543 #define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should
1544  be polled. */
1545 #define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram
1546  should be constructed in the
1547  uip_buf buffer. */
1548 #if UIP_UDP
1549 #define UIP_UDP_TIMER 5
1550 #endif /* UIP_UDP */
1551 
1552 /* The TCP states used in the uip_conn->tcpstateflags. */
1553 #define UIP_CLOSED 0
1554 #define UIP_SYN_RCVD 1
1555 #define UIP_SYN_SENT 2
1556 #define UIP_ESTABLISHED 3
1557 #define UIP_FIN_WAIT_1 4
1558 #define UIP_FIN_WAIT_2 5
1559 #define UIP_CLOSING 6
1560 #define UIP_TIME_WAIT 7
1561 #define UIP_LAST_ACK 8
1562 #define UIP_TS_MASK 15
1563 
1564 #define UIP_STOPPED 16
1565 
1566 /* The TCP and IP headers. */
1567 struct uip_tcpip_hdr {
1568 #if UIP_CONF_IPV6
1569  /* IPv6 header. */
1570  u8_t vtc,
1571  tcflow;
1572  u16_t flow;
1573  u8_t len[2];
1574  u8_t proto, ttl;
1575  uip_ip6addr_t srcipaddr, destipaddr;
1576 #else /* UIP_CONF_IPV6 */
1577  /* IPv4 header. */
1578  u8_t vhl,
1579  tos,
1580  len[2],
1581  ipid[2],
1582  ipoffset[2],
1583  ttl,
1584  proto;
1585  u16_t ipchksum;
1586  uip_ipaddr_t srcipaddr, destipaddr;
1587 #endif /* UIP_CONF_IPV6 */
1588 
1589  /* TCP header. */
1590  u16_t srcport,
1591  destport;
1592  u8_t seqno[4],
1593  ackno[4],
1594  tcpoffset,
1595  flags,
1596  wnd[2];
1597  u16_t tcpchksum;
1598  u8_t urgp[2];
1599  u8_t optdata[4];
1600 };
1601 
1602 /* The ICMP and IP headers. */
1603 struct uip_icmpip_hdr {
1604 #if UIP_CONF_IPV6
1605  /* IPv6 header. */
1606  u8_t vtc,
1607  tcf;
1608  u16_t flow;
1609  u8_t len[2];
1610  u8_t proto, ttl;
1611  uip_ip6addr_t srcipaddr, destipaddr;
1612 #else /* UIP_CONF_IPV6 */
1613  /* IPv4 header. */
1614  u8_t vhl,
1615  tos,
1616  len[2],
1617  ipid[2],
1618  ipoffset[2],
1619  ttl,
1620  proto;
1621  u16_t ipchksum;
1622  uip_ipaddr_t srcipaddr, destipaddr;
1623 #endif /* UIP_CONF_IPV6 */
1624 
1625  /* ICMP header. */
1626  u8_t type, icode;
1627  u16_t icmpchksum;
1628 #if !UIP_CONF_IPV6
1629  u16_t id, seqno;
1630  u8_t payload[1];
1631 #endif /* !UIP_CONF_IPV6 */
1632 };
1633 
1634 
1635 /* The UDP and IP headers. */
1636 struct uip_udpip_hdr {
1637 #if UIP_CONF_IPV6
1638  /* IPv6 header. */
1639  u8_t vtc,
1640  tcf;
1641  u16_t flow;
1642  u8_t len[2];
1643  u8_t proto, ttl;
1644  uip_ip6addr_t srcipaddr, destipaddr;
1645 #else /* UIP_CONF_IPV6 */
1646  /* IP header. */
1647  u8_t vhl,
1648  tos,
1649  len[2],
1650  ipid[2],
1651  ipoffset[2],
1652  ttl,
1653  proto;
1654  u16_t ipchksum;
1655  uip_ipaddr_t srcipaddr, destipaddr;
1656 #endif /* UIP_CONF_IPV6 */
1657 
1658  /* UDP header. */
1659  u16_t srcport,
1660  destport;
1661  u16_t udplen;
1662  u16_t udpchksum;
1663 };
1664 
1665 /*
1666  * In IPv6 the length of the L3 headers before the transport header is
1667  * not fixed, due to the possibility to include extension option headers
1668  * after the IP header. hence we split here L3 and L4 headers
1669  */
1670 /* The IP header */
1671 struct uip_ip_hdr {
1672 #if UIP_CONF_IPV6
1673  /* IPV6 header */
1674  u8_t vtc;
1675  u8_t tcflow;
1676  u16_t flow;
1677  u8_t len[2];
1678  u8_t proto, ttl;
1679  uip_ip6addr_t srcipaddr, destipaddr;
1680 #else /* UIP_CONF_IPV6 */
1681  /* IPV4 header */
1682  u8_t vhl,
1683  tos,
1684  len[2],
1685  ipid[2],
1686  ipoffset[2],
1687  ttl,
1688  proto;
1689  u16_t ipchksum;
1690  uip_ipaddr_t srcipaddr, destipaddr;
1691 #endif /* UIP_CONF_IPV6 */
1692 };
1693 
1694 
1695 /*
1696  * IPv6 extension option headers: we are able to process
1697  * the 4 extension headers defined in RFC2460 (IPv6):
1698  * - Hop by hop option header, destination option header:
1699  * These two are not used by any core IPv6 protocol, hence
1700  * we just read them and go to the next. They convey options,
1701  * the options defined in RFC2460 are Pad1 and PadN, which do
1702  * some padding, and that we do not need to read (the length
1703  * field in the header is enough)
1704  * - Routing header: this one is most notably used by MIPv6,
1705  * which we do not implement, hence we just read it and go
1706  * to the next
1707  * - Fragmentation header: we read this header and are able to
1708  * reassemble packets
1709  *
1710  * We do not offer any means to send packets with extension headers
1711  *
1712  * We do not implement Authentication and ESP headers, which are
1713  * used in IPSec and defined in RFC4302,4303,4305,4385
1714  */
1715 /* common header part */
1716 typedef struct uip_ext_hdr {
1717  u8_t next;
1718  u8_t len;
1719 } uip_ext_hdr;
1720 
1721 /* Hop by Hop option header */
1722 typedef struct uip_hbho_hdr {
1723  u8_t next;
1724  u8_t len;
1725 } uip_hbho_hdr;
1726 
1727 /* destination option header */
1728 typedef struct uip_desto_hdr {
1729  u8_t next;
1730  u8_t len;
1731 } uip_desto_hdr;
1732 
1733 /* We do not define structures for PAD1 and PADN options */
1734 
1735 /*
1736  * routing header
1737  * the routing header as 4 common bytes, then routing header type
1738  * specific data there are several types of routing header. Type 0 was
1739  * deprecated as per RFC5095 most notable other type is 2, used in
1740  * RFC3775 (MIPv6) here we do not implement MIPv6, so we just need to
1741  * parse the 4 first bytes
1742  */
1743 typedef struct uip_routing_hdr {
1744  u8_t next;
1745  u8_t len;
1746  u8_t routing_type;
1747  u8_t seg_left;
1748 } uip_routing_hdr;
1749 
1750 /* fragmentation header */
1751 typedef struct uip_frag_hdr {
1752  u8_t next;
1753  u8_t res;
1754  u16_t offsetresmore;
1755  u32_t id;
1756 } uip_frag_hdr;
1757 
1758 /*
1759  * an option within the destination or hop by hop option headers
1760  * it contains type an length, which is true for all options but PAD1
1761  */
1762 typedef struct uip_ext_hdr_opt {
1763  u8_t type;
1764  u8_t len;
1765 } uip_ext_hdr_opt;
1766 
1767 /* PADN option */
1768 typedef struct uip_ext_hdr_opt_padn {
1769  u8_t opt_type;
1770  u8_t opt_len;
1771 } uip_ext_hdr_opt_padn;
1772 
1773 /* TCP header */
1774 struct uip_tcp_hdr {
1775  u16_t srcport;
1776  u16_t destport;
1777  u8_t seqno[4];
1778  u8_t ackno[4];
1779  u8_t tcpoffset;
1780  u8_t flags;
1781  u8_t wnd[2];
1782  u16_t tcpchksum;
1783  u8_t urgp[2];
1784  u8_t optdata[4];
1785 };
1786 
1787 /* The ICMP headers. */
1788 struct uip_icmp_hdr {
1789  u8_t type, icode;
1790  u16_t icmpchksum;
1791 #if !UIP_CONF_IPV6
1792  u16_t id, seqno;
1793 #endif /* !UIP_CONF_IPV6 */
1794 };
1795 
1796 
1797 /* The UDP headers. */
1798 struct uip_udp_hdr {
1799  u16_t srcport;
1800  u16_t destport;
1801  u16_t udplen;
1802  u16_t udpchksum;
1803 };
1804 
1805 
1806 /**
1807  * The buffer size available for user data in the \ref uip_buf buffer.
1808  *
1809  * This macro holds the available size for user data in the \ref
1810  * uip_buf buffer. The macro is intended to be used for checking
1811  * bounds of available user data.
1812  *
1813  * Example:
1814  \code
1815  snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
1816  \endcode
1817  *
1818  * \hideinitializer
1819  */
1820 #define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
1821 #define UIP_APPDATA_PTR (void *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]
1822 
1823 #define UIP_PROTO_ICMP 1
1824 #define UIP_PROTO_TCP 6
1825 #define UIP_PROTO_UDP 17
1826 #define UIP_PROTO_ICMP6 58
1827 
1828 
1829 #if UIP_CONF_IPV6
1830 /** @{ */
1831 /** \brief extension headers types */
1832 #define UIP_PROTO_HBHO 0
1833 #define UIP_PROTO_DESTO 60
1834 #define UIP_PROTO_ROUTING 43
1835 #define UIP_PROTO_FRAG 44
1836 #define UIP_PROTO_NONE 59
1837 /** @} */
1838 
1839 /** @{ */
1840 /** \brief Destination and Hop By Hop extension headers option types */
1841 #define UIP_EXT_HDR_OPT_PAD1 0
1842 #define UIP_EXT_HDR_OPT_PADN 1
1843 /** @} */
1844 
1845 /** @{ */
1846 /**
1847  * \brief Bitmaps for extension header processing
1848  *
1849  * When processing extension headers, we should record somehow which one we
1850  * see, because you cannot have twice the same header, except for destination
1851  * We store all this in one u8_t bitmap one bit for each header expected. The
1852  * order in the bitmap is the order recommended in RFC2460
1853  */
1854 #define UIP_EXT_HDR_BITMAP_HBHO 0x01
1855 #define UIP_EXT_HDR_BITMAP_DESTO1 0x02
1856 #define UIP_EXT_HDR_BITMAP_ROUTING 0x04
1857 #define UIP_EXT_HDR_BITMAP_FRAG 0x08
1858 #define UIP_EXT_HDR_BITMAP_AH 0x10
1859 #define UIP_EXT_HDR_BITMAP_ESP 0x20
1860 #define UIP_EXT_HDR_BITMAP_DESTO2 0x40
1861 /** @} */
1862 
1863 
1864 #endif /* UIP_CONF_IPV6 */
1865 
1866 
1867 /* Header sizes. */
1868 #if UIP_CONF_IPV6
1869 #define UIP_IPH_LEN 40
1870 #define UIP_FRAGH_LEN 8
1871 #else /* UIP_CONF_IPV6 */
1872 #define UIP_IPH_LEN 20 /* Size of IP header */
1873 #endif /* UIP_CONF_IPV6 */
1874 
1875 #define UIP_UDPH_LEN 8 /* Size of UDP header */
1876 #define UIP_TCPH_LEN 20 /* Size of TCP header */
1877 #ifdef UIP_IPH_LEN
1878 #define UIP_ICMPH_LEN 4 /* Size of ICMP header */
1879 #endif
1880 #define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP +
1881  * UDP
1882  * header */
1883 #define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP +
1884  * TCP
1885  * header */
1886 #define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
1887 #define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* size of ICMP
1888  + IP header */
1889 #define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN) /* size of L2
1890  + IP header */
1891 #if UIP_CONF_IPV6
1892 /**
1893  * The sums below are quite used in ND. When used for uip_buf, we
1894  * include link layer length when used for uip_len, we do not, hence
1895  * we need values with and without LLH_LEN we do not use capital
1896  * letters as these values are variable
1897  */
1898 #define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len)
1899 #define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
1900 #define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len)
1901 #define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
1902 #endif /*UIP_CONF_IPV6*/
1903 
1904 
1905 #if UIP_FIXEDADDR
1906 CCIF extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
1907 #else /* UIP_FIXEDADDR */
1908 CCIF extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
1909 #endif /* UIP_FIXEDADDR */
1910 CCIF extern const uip_ipaddr_t uip_broadcast_addr;
1911 CCIF extern const uip_ipaddr_t uip_all_zeroes_addr;
1912 
1913 #if UIP_FIXEDETHADDR
1914 CCIF extern const uip_lladdr_t uip_lladdr;
1915 #else
1916 CCIF extern uip_lladdr_t uip_lladdr;
1917 #endif
1918 
1919 
1920 
1921 
1922 #ifdef UIP_CONF_IPV6
1923 /** Length of the link local prefix */
1924 #define UIP_LLPREF_LEN 10
1925 
1926 /**
1927  * \brief Is IPv6 address a the unspecified address
1928  * a is of type uip_ipaddr_t
1929  */
1930 #define uip_is_addr_loopback(a) \
1931  ((((a)->u16[0]) == 0) && \
1932  (((a)->u16[1]) == 0) && \
1933  (((a)->u16[2]) == 0) && \
1934  (((a)->u16[3]) == 0) && \
1935  (((a)->u16[4]) == 0) && \
1936  (((a)->u16[5]) == 0) && \
1937  (((a)->u16[6]) == 0) && \
1938  (((a)->u8[14]) == 0) && \
1939  (((a)->u8[15]) == 0x01))
1940 /**
1941  * \brief Is IPv6 address a the unspecified address
1942  * a is of type uip_ipaddr_t
1943  */
1944 #define uip_is_addr_unspecified(a) \
1945  ((((a)->u16[0]) == 0) && \
1946  (((a)->u16[1]) == 0) && \
1947  (((a)->u16[2]) == 0) && \
1948  (((a)->u16[3]) == 0) && \
1949  (((a)->u16[4]) == 0) && \
1950  (((a)->u16[5]) == 0) && \
1951  (((a)->u16[6]) == 0) && \
1952  (((a)->u16[7]) == 0))
1953 
1954 /** \brief Is IPv6 address a the link local all-nodes multicast address */
1955 #define uip_is_addr_linklocal_allnodes_mcast(a) \
1956  ((((a)->u8[0]) == 0xff) && \
1957  (((a)->u8[1]) == 0x02) && \
1958  (((a)->u16[1]) == 0) && \
1959  (((a)->u16[2]) == 0) && \
1960  (((a)->u16[3]) == 0) && \
1961  (((a)->u16[4]) == 0) && \
1962  (((a)->u16[5]) == 0) && \
1963  (((a)->u16[6]) == 0) && \
1964  (((a)->u8[14]) == 0) && \
1965  (((a)->u8[15]) == 0x01))
1966 
1967 /** \brief Is IPv6 address a the link local all-routers multicast address */
1968 #define uip_is_addr_linklocal_allrouters_mcast(a) \
1969  ((((a)->u8[0]) == 0xff) && \
1970  (((a)->u8[1]) == 0x02) && \
1971  (((a)->u16[1]) == 0) && \
1972  (((a)->u16[2]) == 0) && \
1973  (((a)->u16[3]) == 0) && \
1974  (((a)->u16[4]) == 0) && \
1975  (((a)->u16[5]) == 0) && \
1976  (((a)->u16[6]) == 0) && \
1977  (((a)->u8[14]) == 0) && \
1978  (((a)->u8[15]) == 0x02))
1979 
1980 /**
1981  * \brief Checks whether the address a is link local.
1982  * a is of type uip_ipaddr_t
1983  */
1984 #define uip_is_addr_linklocal(a) \
1985  ((a)->u8[0] == 0xfe && \
1986  (a)->u8[1] == 0x80)
1987 
1988 /** \brief set IP address a to unspecified */
1989 #define uip_create_unspecified(a) uip_ip6addr(a, 0, 0, 0, 0, 0, 0, 0, 0)
1990 
1991 /** \brief set IP address a to the link local all-nodes multicast address */
1992 #define uip_create_linklocal_allnodes_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001)
1993 
1994 /** \brief set IP address a to the link local all-routers multicast address */
1995 #define uip_create_linklocal_allrouters_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002)
1996 #define uip_create_linklocal_prefix(addr) do { \
1997  (addr)->u16[0] = UIP_HTONS(0xfe80); \
1998  (addr)->u16[1] = 0; \
1999  (addr)->u16[2] = 0; \
2000  (addr)->u16[3] = 0; \
2001  } while(0)
2002 
2003 /**
2004  * \brief is addr (a) a solicited node multicast address, see RFC3513
2005  * a is of type uip_ipaddr_t*
2006  */
2007 #define uip_is_addr_solicited_node(a) \
2008  ((((a)->u8[0]) == 0xFF) && \
2009  (((a)->u8[1]) == 0x02) && \
2010  (((a)->u16[1]) == 0x00) && \
2011  (((a)->u16[2]) == 0x00) && \
2012  (((a)->u16[3]) == 0x00) && \
2013  (((a)->u16[4]) == 0x00) && \
2014  (((a)->u8[10]) == 0x00) && \
2015  (((a)->u8[11]) == 0x01) && \
2016  (((a)->u8[12]) == 0xFF))
2017 
2018 /**
2019  * \briefput in b the solicited node address corresponding to address a
2020  * both a and b are of type uip_ipaddr_t*
2021  * */
2022 #define uip_create_solicited_node(a, b) \
2023  (((b)->u8[0]) = 0xFF); \
2024  (((b)->u8[1]) = 0x02); \
2025  (((b)->u16[1]) = 0); \
2026  (((b)->u16[2]) = 0); \
2027  (((b)->u16[3]) = 0); \
2028  (((b)->u16[4]) = 0); \
2029  (((b)->u8[10]) = 0); \
2030  (((b)->u8[11]) = 0x01); \
2031  (((b)->u8[12]) = 0xFF); \
2032  (((b)->u8[13]) = ((a)->u8[13])); \
2033  (((b)->u16[7]) = ((a)->u16[7]))
2034 
2035 /**
2036  * \brief is addr (a) a link local unicast address, see RFC3513
2037  * i.e. is (a) on prefix FE80::/10
2038  * a is of type uip_ipaddr_t*
2039  */
2040 #define uip_is_addr_link_local(a) \
2041  ((((a)->u8[0]) == 0xFE) && \
2042  (((a)->u8[1]) == 0x80))
2043 
2044 /**
2045  * \brief was addr (a) forged based on the mac address m
2046  * a type is uip_ipaddr_t
2047  * m type is uiplladdr_t
2048  */
2049 #if UIP_CONF_LL_802154
2050 #define uip_is_addr_mac_addr_based(a, m) \
2051  ((((a)->u8[8]) == (((m)->addr[0]) ^ 0x02)) && \
2052  (((a)->u8[9]) == (m)->addr[1]) && \
2053  (((a)->u8[10]) == (m)->addr[2]) && \
2054  (((a)->u8[11]) == (m)->addr[3]) && \
2055  (((a)->u8[12]) == (m)->addr[4]) && \
2056  (((a)->u8[13]) == (m)->addr[5]) && \
2057  (((a)->u8[14]) == (m)->addr[6]) && \
2058  (((a)->u8[15]) == (m)->addr[7]))
2059 #else
2060 
2061 #define uip_is_addr_mac_addr_based(a, m) \
2062  ((((a)->u8[8]) == (((m)->addr[0]) | 0x02)) && \
2063  (((a)->u8[9]) == (m)->addr[1]) && \
2064  (((a)->u8[10]) == (m)->addr[2]) && \
2065  (((a)->u8[11]) == 0xff) && \
2066  (((a)->u8[12]) == 0xfe) && \
2067  (((a)->u8[13]) == (m)->addr[3]) && \
2068  (((a)->u8[14]) == (m)->addr[4]) && \
2069  (((a)->u8[15]) == (m)->addr[5]))
2070 
2071 #endif /*UIP_CONF_LL_802154*/
2072 
2073 /**
2074  * \brief is address a multicast address, see RFC 3513
2075  * a is of type uip_ipaddr_t*
2076  * */
2077 #define uip_is_addr_mcast(a) \
2078  (((a)->u8[0]) == 0xFF)
2079 
2080 /**
2081  * \brief is group-id of multicast address a
2082  * the all nodes group-id
2083  */
2084 #define uip_is_mcast_group_id_all_nodes(a) \
2085  ((((a)->u16[1]) == 0) && \
2086  (((a)->u16[2]) == 0) && \
2087  (((a)->u16[3]) == 0) && \
2088  (((a)->u16[4]) == 0) && \
2089  (((a)->u16[5]) == 0) && \
2090  (((a)->u16[6]) == 0) && \
2091  (((a)->u8[14]) == 0) && \
2092  (((a)->u8[15]) == 1))
2093 
2094 /**
2095  * \brief is group-id of multicast address a
2096  * the all routers group-id
2097  */
2098 #define uip_is_mcast_group_id_all_routers(a) \
2099  ((((a)->u16[1]) == 0) && \
2100  (((a)->u16[2]) == 0) && \
2101  (((a)->u16[3]) == 0) && \
2102  (((a)->u16[4]) == 0) && \
2103  (((a)->u16[5]) == 0) && \
2104  (((a)->u16[6]) == 0) && \
2105  (((a)->u8[14]) == 0) && \
2106  (((a)->u8[15]) == 2))
2107 
2108 
2109 /**
2110  * \brief are last three bytes of both addresses equal?
2111  * This is used to compare solicited node multicast addresses
2112  */
2113 #define uip_are_solicited_bytes_equal(a, b) \
2114  ((((a)->u8[13]) == ((b)->u8[13])) && \
2115  (((a)->u8[14]) == ((b)->u8[14])) && \
2116  (((a)->u8[15]) == ((b)->u8[15])))
2117 
2118 #endif /*UIP_CONF_IPV6*/
2119 
2120 /**
2121  * Calculate the Internet checksum over a buffer.
2122  *
2123  * The Internet checksum is the one's complement of the one's
2124  * complement sum of all 16-bit words in the buffer.
2125  *
2126  * See RFC1071.
2127  *
2128  * \param buf A pointer to the buffer over which the checksum is to be
2129  * computed.
2130  *
2131  * \param len The length of the buffer over which the checksum is to
2132  * be computed.
2133  *
2134  * \return The Internet checksum of the buffer.
2135  */
2136 u16_t uip_chksum(u16_t *buf, u16_t len);
2137 
2138 /**
2139  * Calculate the IP header checksum of the packet header in uip_buf.
2140  *
2141  * The IP header checksum is the Internet checksum of the 20 bytes of
2142  * the IP header.
2143  *
2144  * \return The IP header checksum of the IP header in the uip_buf
2145  * buffer.
2146  */
2147 u16_t uip_ipchksum(void);
2148 
2149 /**
2150  * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
2151  *
2152  * The TCP checksum is the Internet checksum of data contents of the
2153  * TCP segment, and a pseudo-header as defined in RFC793.
2154  *
2155  * \return The TCP checksum of the TCP segment in uip_buf and pointed
2156  * to by uip_appdata.
2157  */
2158 u16_t uip_tcpchksum(void);
2159 
2160 /**
2161  * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
2162  *
2163  * The UDP checksum is the Internet checksum of data contents of the
2164  * UDP segment, and a pseudo-header as defined in RFC768.
2165  *
2166  * \return The UDP checksum of the UDP segment in uip_buf and pointed
2167  * to by uip_appdata.
2168  */
2169 u16_t uip_udpchksum(void);
2170 
2171 /**
2172  * Calculate the ICMP checksum of the packet in uip_buf.
2173  *
2174  * \return The ICMP checksum of the ICMP packet in uip_buf
2175  */
2176 u16_t uip_icmp6chksum(void);
2177 
2178 
2179 #endif /* __UIP_H__ */
2180 
2181 
2182 /** @} */