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