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