Contiki 3.x
uipopt.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2003, Adam Dunkels.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote
14  * products derived from this software without specific prior
15  * written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * This file is part of the uIP TCP/IP stack.
30  *
31  *
32  */
33 
34 /**
35  * \file
36  * Configuration options for uIP.
37  * \author Adam Dunkels <adam@dunkels.com>
38  *
39  * This file is used for tweaking various configuration options for
40  * uIP. You should make a copy of this file into one of your project's
41  * directories instead of editing this example "uipopt.h" file that
42  * comes with the uIP distribution.
43  */
44 
45 /**
46  * \addtogroup uip
47  * @{
48  */
49 
50 /**
51  * \defgroup uipopt Configuration options for uIP
52  * @{
53  *
54  * uIP is configured using the per-project configuration file
55  * "uipopt.h". This file contains all compile-time options for uIP and
56  * should be tweaked to match each specific project. The uIP
57  * distribution contains a documented example "uipopt.h" that can be
58  * copied and modified for each project.
59  *
60  * \note Contiki does not use the uipopt.h file to configure uIP, but
61  * uses a per-port uip-conf.h file that should be edited instead.
62  */
63 
64 #ifndef UIPOPT_H_
65 #define UIPOPT_H_
66 
67 #ifndef UIP_LITTLE_ENDIAN
68 #define UIP_LITTLE_ENDIAN 3412
69 #endif /* UIP_LITTLE_ENDIAN */
70 #ifndef UIP_BIG_ENDIAN
71 #define UIP_BIG_ENDIAN 1234
72 #endif /* UIP_BIG_ENDIAN */
73 
74 #include "contiki-conf.h"
75 
76 /*------------------------------------------------------------------------------*/
77 
78 /**
79  * \defgroup uipoptstaticconf Static configuration options
80  * @{
81  *
82  * These configuration options can be used for setting the IP address
83  * settings statically, but only if UIP_FIXEDADDR is set to 1. The
84  * configuration options for a specific node includes IP address,
85  * netmask and default router as well as the Ethernet address. The
86  * netmask, default router and Ethernet address are applicable only
87  * if uIP should be run over Ethernet.
88  *
89  * This options are meaningful only for the IPv4 code.
90  *
91  * All of these should be changed to suit your project.
92  */
93 
94 /**
95  * Determines if uIP should use a fixed IP address or not.
96  *
97  * If uIP should use a fixed IP address, the settings are set in the
98  * uipopt.h file. If not, the macros uip_sethostaddr(),
99  * uip_setdraddr() and uip_setnetmask() should be used instead.
100  *
101  * \hideinitializer
102  */
103 #define UIP_FIXEDADDR 0
104 
105 /**
106  * Ping IP address assignment.
107  *
108  * uIP uses a "ping" packets for setting its own IP address if this
109  * option is set. If so, uIP will start with an empty IP address and
110  * the destination IP address of the first incoming "ping" (ICMP echo)
111  * packet will be used for setting the hosts IP address.
112  *
113  * \note This works only if UIP_FIXEDADDR is 0.
114  *
115  * \hideinitializer
116  */
117 #ifdef UIP_CONF_PINGADDRCONF
118 #define UIP_PINGADDRCONF (UIP_CONF_PINGADDRCONF)
119 #else /* UIP_CONF_PINGADDRCONF */
120 #define UIP_PINGADDRCONF 0
121 #endif /* UIP_CONF_PINGADDRCONF */
122 
123 
124 /**
125  * Specifies if the uIP ARP module should be compiled with a fixed
126  * Ethernet MAC address or not.
127  *
128  * If this configuration option is 0, the macro uip_setethaddr() can
129  * be used to specify the Ethernet address at run-time.
130  *
131  * \hideinitializer
132  */
133 #define UIP_FIXEDETHADDR 0
134 
135 /** @} */
136 /*------------------------------------------------------------------------------*/
137 
138 /**
139  * \defgroup uipoptgeneral General configuration options
140  * @{
141  */
142 
143 /**
144  * The link level header length.
145  *
146  * This is the offset into the uip_buf where the IP header can be
147  * found. For Ethernet, this should be set to 14. For SLIP, this
148  * should be set to 0.
149  *
150  * \note we probably won't use this constant for other link layers than
151  * ethernet as they have variable header length (this is due to variable
152  * number and type of address fields and to optional security features)
153  * E.g.: 802.15.4 -> 2 + (1/2*4/8) + 0/5/6/10/14
154  * 802.11 -> 4 + (6*3/4) + 2
155  * \hideinitializer
156  */
157 #ifdef UIP_CONF_LLH_LEN
158 #define UIP_LLH_LEN (UIP_CONF_LLH_LEN)
159 #else /* UIP_LLH_LEN */
160 #define UIP_LLH_LEN 0
161 #endif /* UIP_CONF_LLH_LEN */
162 
163 /**
164  * The size of the uIP packet buffer.
165  *
166  * The uIP packet buffer should not be smaller than 60 bytes, and does
167  * not need to be larger than 1514 bytes. Lower size results in lower
168  * TCP throughput, larger size results in higher TCP throughput.
169  *
170  * \hideinitializer
171  */
172 #ifndef UIP_CONF_BUFFER_SIZE
173 #define UIP_BUFSIZE (UIP_LINK_MTU + UIP_LLH_LEN)
174 #else /* UIP_CONF_BUFFER_SIZE */
175 #define UIP_BUFSIZE (UIP_CONF_BUFFER_SIZE)
176 #endif /* UIP_CONF_BUFFER_SIZE */
177 
178 
179 /**
180  * Determines if statistics support should be compiled in.
181  *
182  * The statistics is useful for debugging and to show the user.
183  *
184  * \hideinitializer
185  */
186 #ifndef UIP_CONF_STATISTICS
187 #define UIP_STATISTICS 0
188 #else /* UIP_CONF_STATISTICS */
189 #define UIP_STATISTICS (UIP_CONF_STATISTICS)
190 #endif /* UIP_CONF_STATISTICS */
191 
192 /**
193  * Determines if logging of certain events should be compiled in.
194  *
195  * This is useful mostly for debugging. The function uip_log()
196  * must be implemented to suit the architecture of the project, if
197  * logging is turned on.
198  *
199  * \hideinitializer
200  */
201 #ifndef UIP_CONF_LOGGING
202 #define UIP_LOGGING 0
203 #else /* UIP_CONF_LOGGING */
204 #define UIP_LOGGING (UIP_CONF_LOGGING)
205 #endif /* UIP_CONF_LOGGING */
206 
207 /**
208  * Broadcast support.
209  *
210  * This flag configures IP broadcast support. This is useful only
211  * together with UDP.
212  *
213  * \hideinitializer
214  *
215  */
216 #ifndef UIP_CONF_BROADCAST
217 #define UIP_BROADCAST 0
218 #else /* UIP_CONF_BROADCAST */
219 #define UIP_BROADCAST (UIP_CONF_BROADCAST)
220 #endif /* UIP_CONF_BROADCAST */
221 
222 /**
223  * Print out a uIP log message.
224  *
225  * This function must be implemented by the module that uses uIP, and
226  * is called by uIP whenever a log message is generated.
227  */
228 void uip_log(char *msg);
229 
230 /** @} */
231 /*------------------------------------------------------------------------------*/
232 /**
233  * \defgroup uipoptip IP configuration options
234  * @{
235  *
236  */
237 /**
238  * The IP TTL (time to live) of IP packets sent by uIP.
239  *
240  * This should normally not be changed.
241  */
242 #ifdef UIP_CONF_TTL
243 #define UIP_TTL UIP_CONF_TTL
244 #else /* UIP_CONF_TTL */
245 #define UIP_TTL 64
246 #endif /* UIP_CONF_TTL */
247 
248 /**
249  * The maximum time an IP fragment should wait in the reassembly
250  * buffer before it is dropped.
251  *
252  */
253 #define UIP_REASS_MAXAGE 60 /*60s*/
254 
255 /**
256  * Turn on support for IP packet reassembly.
257  *
258  * uIP supports reassembly of fragmented IP packets. This features
259  * requires an additional amount of RAM to hold the reassembly buffer
260  * and the reassembly code size is approximately 700 bytes. The
261  * reassembly buffer is of the same size as the uip_buf buffer
262  * (configured by UIP_BUFSIZE).
263  *
264  * \note IP packet reassembly is not heavily tested.
265  *
266  * \hideinitializer
267  */
268 #ifdef UIP_CONF_REASSEMBLY
269 #define UIP_REASSEMBLY (UIP_CONF_REASSEMBLY)
270 #else /* UIP_CONF_REASSEMBLY */
271 #define UIP_REASSEMBLY 0
272 #endif /* UIP_CONF_REASSEMBLY */
273 /** @} */
274 
275 /*------------------------------------------------------------------------------*/
276 /**
277  * \defgroup uipoptipv6 IPv6 configuration options
278  * @{
279  *
280  */
281 
282 /** The maximum transmission unit at the IP Layer*/
283 #define UIP_LINK_MTU 1280
284 
285 #ifndef UIP_CONF_IPV6
286 /** Do we use IPv6 or not (default: no) */
287 #define UIP_CONF_IPV6 0
288 #endif
289 
290 #ifndef UIP_CONF_IPV6_QUEUE_PKT
291 /** Do we do per %neighbor queuing during address resolution (default: no) */
292 #define UIP_CONF_IPV6_QUEUE_PKT 0
293 #endif
294 
295 #ifndef UIP_CONF_IPV6_CHECKS
296 /** Do we do IPv6 consistency checks (highly recommended, default: yes) */
297 #define UIP_CONF_IPV6_CHECKS 1
298 #endif
299 
300 #ifndef UIP_CONF_IPV6_REASSEMBLY
301 /** Do we do IPv6 fragmentation (default: no) */
302 #define UIP_CONF_IPV6_REASSEMBLY 0
303 #endif
304 
305 #ifndef UIP_CONF_NETIF_MAX_ADDRESSES
306 /** Default number of IPv6 addresses associated to the node's interface */
307 #define UIP_CONF_NETIF_MAX_ADDRESSES 3
308 #endif
309 
310 #ifndef UIP_CONF_DS6_PREFIX_NBU
311 /** Default number of IPv6 prefixes associated to the node's interface */
312 #define UIP_CONF_DS6_PREFIX_NBU 2
313 #endif
314 
315 #ifndef UIP_CONF_DS6_DEFRT_NBU
316 /** Minimum number of default routers */
317 #define UIP_CONF_DS6_DEFRT_NBU 2
318 #endif
319 /** @} */
320 
321 /*------------------------------------------------------------------------------*/
322 /**
323  * \defgroup uipoptudp UDP configuration options
324  * @{
325  *
326  * \note The UDP support in uIP is still not entirely complete; there
327  * is no support for sending or receiving broadcast or multicast
328  * packets, but it works well enough to support a number of vital
329  * applications such as DNS queries, though
330  */
331 
332 /**
333  * Toggles whether UDP support should be compiled in or not.
334  *
335  * \hideinitializer
336  */
337 #ifdef UIP_CONF_UDP
338 #define UIP_UDP UIP_CONF_UDP
339 #else /* UIP_CONF_UDP */
340 #define UIP_UDP 1
341 #endif /* UIP_CONF_UDP */
342 
343 /**
344  * Toggles if UDP checksums should be used or not.
345  *
346  * \note Support for UDP checksums is currently not included in uIP,
347  * so this option has no function.
348  *
349  * \hideinitializer
350  */
351 #ifdef UIP_CONF_UDP_CHECKSUMS
352 #define UIP_UDP_CHECKSUMS (UIP_CONF_UDP_CHECKSUMS)
353 #else
354 #define UIP_UDP_CHECKSUMS (UIP_CONF_IPV6)
355 #endif
356 
357 /**
358  * The maximum amount of concurrent UDP connections.
359  *
360  * \hideinitializer
361  */
362 #ifdef UIP_CONF_UDP_CONNS
363 #define UIP_UDP_CONNS (UIP_CONF_UDP_CONNS)
364 #else /* UIP_CONF_UDP_CONNS */
365 #define UIP_UDP_CONNS 10
366 #endif /* UIP_CONF_UDP_CONNS */
367 
368 /**
369  * The name of the function that should be called when UDP datagrams arrive.
370  *
371  * \hideinitializer
372  */
373 
374 
375 /** @} */
376 /*------------------------------------------------------------------------------*/
377 /**
378  * \defgroup uipopttcp TCP configuration options
379  * @{
380  */
381 
382 /**
383  * Toggles whether TCP support should be compiled in or not.
384  *
385  * \hideinitializer
386  */
387 #ifdef UIP_CONF_TCP
388 #define UIP_TCP (UIP_CONF_TCP)
389 #else /* UIP_CONF_TCP */
390 #define UIP_TCP 1
391 #endif /* UIP_CONF_TCP */
392 
393 /**
394  * Determines if support for opening connections from uIP should be
395  * compiled in.
396  *
397  * If the applications that are running on top of uIP for this project
398  * do not need to open outgoing TCP connections, this configuration
399  * option can be turned off to reduce the code size of uIP.
400  *
401  * \hideinitializer
402  */
403 #ifndef UIP_CONF_ACTIVE_OPEN
404 #define UIP_ACTIVE_OPEN 1
405 #else /* UIP_CONF_ACTIVE_OPEN */
406 #define UIP_ACTIVE_OPEN (UIP_CONF_ACTIVE_OPEN)
407 #endif /* UIP_CONF_ACTIVE_OPEN */
408 
409 /**
410  * The maximum number of simultaneously open TCP connections.
411  *
412  * Since the TCP connections are statically allocated, turning this
413  * configuration knob down results in less RAM used. Each TCP
414  * connection requires approximately 30 bytes of memory.
415  *
416  * \hideinitializer
417  */
418 #ifndef UIP_CONF_MAX_CONNECTIONS
419 #define UIP_CONNS 10
420 #else /* UIP_CONF_MAX_CONNECTIONS */
421 #define UIP_CONNS (UIP_CONF_MAX_CONNECTIONS)
422 #endif /* UIP_CONF_MAX_CONNECTIONS */
423 
424 
425 /**
426  * The maximum number of simultaneously listening TCP ports.
427  *
428  * Each listening TCP port requires 2 bytes of memory.
429  *
430  * \hideinitializer
431  */
432 #ifndef UIP_CONF_MAX_LISTENPORTS
433 #define UIP_LISTENPORTS 20
434 #else /* UIP_CONF_MAX_LISTENPORTS */
435 #define UIP_LISTENPORTS (UIP_CONF_MAX_LISTENPORTS)
436 #endif /* UIP_CONF_MAX_LISTENPORTS */
437 
438 /**
439  * Determines if support for TCP urgent data notification should be
440  * compiled in.
441  *
442  * Urgent data (out-of-band data) is a rarely used TCP feature that
443  * very seldom would be required.
444  *
445  * \hideinitializer
446  */
447 #define UIP_URGDATA 0
448 
449 /**
450  * The initial retransmission timeout counted in timer pulses.
451  *
452  * This should not be changed.
453  */
454 #define UIP_RTO 3
455 
456 /**
457  * The maximum number of times a segment should be retransmitted
458  * before the connection should be aborted.
459  *
460  * This should not be changed.
461  */
462 #define UIP_MAXRTX 8
463 
464 /**
465  * The maximum number of times a SYN segment should be retransmitted
466  * before a connection request should be deemed to have been
467  * unsuccessful.
468  *
469  * This should not need to be changed.
470  */
471 #define UIP_MAXSYNRTX 5
472 
473 /**
474  * The TCP maximum segment size.
475  *
476  * This is should not be to set to more than
477  * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN.
478  */
479 #ifdef UIP_CONF_TCP_MSS
480 #if UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
481 #error UIP_CONF_TCP_MSS is too large for the current UIP_BUFSIZE
482 #endif /* UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) */
483 #define UIP_TCP_MSS (UIP_CONF_TCP_MSS)
484 #else /* UIP_CONF_TCP_MSS */
485 #define UIP_TCP_MSS (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
486 #endif /* UIP_CONF_TCP_MSS */
487 
488 /**
489  * The size of the advertised receiver's window.
490  *
491  * Should be set low (i.e., to the size of the uip_buf buffer) if the
492  * application is slow to process incoming data, or high (32768 bytes)
493  * if the application processes data quickly.
494  *
495  * \hideinitializer
496  */
497 #ifndef UIP_CONF_RECEIVE_WINDOW
498 #define UIP_RECEIVE_WINDOW (UIP_TCP_MSS)
499 #else
500 #define UIP_RECEIVE_WINDOW (UIP_CONF_RECEIVE_WINDOW)
501 #endif
502 
503 /**
504  * How long a connection should stay in the TIME_WAIT state.
505  *
506  * This can be reduced for faster entry into power saving modes.
507  */
508 #ifndef UIP_CONF_WAIT_TIMEOUT
509 #define UIP_TIME_WAIT_TIMEOUT 120
510 #else
511 #define UIP_TIME_WAIT_TIMEOUT UIP_CONF_WAIT_TIMEOUT
512 #endif
513 
514 /** @} */
515 /*------------------------------------------------------------------------------*/
516 /**
517  * \defgroup uipoptarp ARP configuration options
518  * @{
519  */
520 
521 /**
522  * The size of the ARP table.
523  *
524  * This option should be set to a larger value if this uIP node will
525  * have many connections from the local network.
526  *
527  * \hideinitializer
528  */
529 #ifdef UIP_CONF_ARPTAB_SIZE
530 #define UIP_ARPTAB_SIZE (UIP_CONF_ARPTAB_SIZE)
531 #else
532 #define UIP_ARPTAB_SIZE 8
533 #endif
534 
535 /**
536  * The maximum age of ARP table entries measured in 10ths of seconds.
537  *
538  * An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD
539  * default).
540  */
541 #define UIP_ARP_MAXAGE 120
542 
543 
544 /** @} */
545 
546 /*------------------------------------------------------------------------------*/
547 
548 /**
549  * \defgroup uipoptmac layer 2 options (for ipv6)
550  * @{
551  */
552 
553 #define UIP_DEFAULT_PREFIX_LEN 64
554 
555 /** @} */
556 
557 /*------------------------------------------------------------------------------*/
558 
559 /**
560  * \defgroup uipoptsics 6lowpan options (for ipv6)
561  * @{
562  */
563 /**
564  * Timeout for packet reassembly at the 6lowpan layer
565  * (should be < 60s)
566  */
567 #ifdef SICSLOWPAN_CONF_MAXAGE
568 #define SICSLOWPAN_REASS_MAXAGE (SICSLOWPAN_CONF_MAXAGE)
569 #else
570 #define SICSLOWPAN_REASS_MAXAGE 20
571 #endif
572 
573 /**
574  * Do we compress the IP header or not (default: no)
575  */
576 #ifndef SICSLOWPAN_CONF_COMPRESSION
577 #define SICSLOWPAN_CONF_COMPRESSION 0
578 #endif
579 
580 /**
581  * If we use IPHC compression, how many address contexts do we support
582  */
583 #ifndef SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS
584 #define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 1
585 #endif
586 
587 /**
588  * Do we support 6lowpan fragmentation
589  */
590 #ifndef SICSLOWPAN_CONF_FRAG
591 #define SICSLOWPAN_CONF_FRAG 0
592 #endif
593 
594 /** @} */
595 
596 /*------------------------------------------------------------------------------*/
597 /**
598  * \defgroup uipoptcpu CPU architecture configuration
599  * @{
600  *
601  * The CPU architecture configuration is where the endianess of the
602  * CPU on which uIP is to be run is specified. Most CPUs today are
603  * little endian, and the most notable exception are the Motorolas
604  * which are big endian. The BYTE_ORDER macro should be changed to
605  * reflect the CPU architecture on which uIP is to be run.
606  */
607 
608 /**
609  * The byte order of the CPU architecture on which uIP is to be run.
610  *
611  * This option can be either UIP_BIG_ENDIAN (Motorola byte order) or
612  * UIP_LITTLE_ENDIAN (Intel byte order).
613  *
614  * \hideinitializer
615  */
616 #ifdef UIP_CONF_BYTE_ORDER
617 #define UIP_BYTE_ORDER (UIP_CONF_BYTE_ORDER)
618 #else /* UIP_CONF_BYTE_ORDER */
619 #define UIP_BYTE_ORDER (UIP_LITTLE_ENDIAN)
620 #endif /* UIP_CONF_BYTE_ORDER */
621 
622 /** @} */
623 /*------------------------------------------------------------------------------*/
624 
625 /**
626  * \defgroup uipoptapp Application specific configurations
627  * @{
628  *
629  * An uIP application is implemented using a single application
630  * function that is called by uIP whenever a TCP/IP event occurs. The
631  * name of this function must be registered with uIP at compile time
632  * using the UIP_APPCALL definition.
633  *
634  * uIP applications can store the application state within the
635  * uip_conn structure by specifying the type of the application
636  * structure by typedef:ing the type uip_tcp_appstate_t and uip_udp_appstate_t.
637  *
638  * The file containing the definitions must be included in the
639  * uipopt.h file.
640  *
641  * The following example illustrates how this can look.
642  \code
643 
644  void httpd_appcall(void);
645  #define UIP_APPCALL httpd_appcall
646 
647  struct httpd_state {
648  uint8_t state;
649  uint16_t count;
650  char *dataptr;
651  char *script;
652  };
653  typedef struct httpd_state uip_tcp_appstate_t
654  \endcode
655 */
656 
657 /**
658  * \var #define UIP_APPCALL
659  *
660  * The name of the application function that uIP should call in
661  * response to TCP/IP events.
662  *
663  */
664 
665 /**
666  * \var typedef uip_tcp_appstate_t
667  *
668  * The type of the application state that is to be stored in the
669  * uip_conn structure. This usually is typedef:ed to a struct holding
670  * application state information.
671  */
672 
673 /**
674  * \var typedef uip_udp_appstate_t
675  *
676  * The type of the application state that is to be stored in the
677  * uip_conn structure. This usually is typedef:ed to a struct holding
678  * application state information.
679  */
680 /** @} */
681 
682 #endif /* UIPOPT_H_ */
683 /** @} */
684 /** @} */
void uip_log(char *msg)
Print out a uIP log message.
Definition: uip-log.c:3