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