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