Beifengdo commited on
Commit
63dc91f
·
verified ·
1 Parent(s): c40c007

Archive original Arduino development files (part 4)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +10 -0
  2. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/pbuf.c +931 -0
  3. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/raw.c +355 -0
  4. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/stats.c +151 -0
  5. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp.c +1463 -0
  6. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp_in.c +1508 -0
  7. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp_out.c +1071 -0
  8. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/udp.c +843 -0
  9. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/autoip.h +118 -0
  10. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/icmp.h +113 -0
  11. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/igmp.h +164 -0
  12. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/inet.h +105 -0
  13. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/inet_chksum.h +62 -0
  14. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/ip.h +200 -0
  15. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/ip_addr.h +175 -0
  16. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/ip_frag.h +78 -0
  17. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/api.h +224 -0
  18. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/api_msg.h +164 -0
  19. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/arch.h +235 -0
  20. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/debug.h +100 -0
  21. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/def.h +49 -0
  22. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/dhcp.h +248 -0
  23. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/dns.h +99 -0
  24. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/err.h +89 -0
  25. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/init.h +74 -0
  26. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/mem.h +109 -0
  27. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/memp.h +118 -0
  28. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/memp_std.h +104 -0
  29. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/netbuf.h +88 -0
  30. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/netdb.h +113 -0
  31. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/netif.h +265 -0
  32. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/netifapi.h +107 -0
  33. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/opt.h +1842 -0
  34. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/pbuf.h +122 -0
  35. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/raw.h +99 -0
  36. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/sio.h +143 -0
  37. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/snmp.h +366 -0
  38. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/snmp_asn1.h +103 -0
  39. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/snmp_msg.h +313 -0
  40. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/snmp_structs.h +264 -0
  41. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/sockets.h +359 -0
  42. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/stats.h +285 -0
  43. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/sys.h +245 -0
  44. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/tcp.h +709 -0
  45. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/tcpip.h +143 -0
  46. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/udp.h +155 -0
  47. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/netif/etharp.h +194 -0
  48. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/netif/loopif.h +55 -0
  49. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/netif/ppp_oe.h +163 -0
  50. hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/netif/slipif.h +53 -0
.gitattributes CHANGED
@@ -118,3 +118,13 @@ hardware/arduino/avr/firmwares/wifishield/wifi_dnld/src/Doc/gettingstarted.pdf f
118
  hardware/arduino/avr/firmwares/wifishield/wifi_dnld/src/Doc/SPB104[[:space:]]product[[:space:]]brief.pdf filter=lfs diff=lfs merge=lfs -text
119
  hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/v2.7.0/UCR1/GCC/lib_ucr1_hd_wl_sta_intwpa_v2.7.0.a filter=lfs diff=lfs merge=lfs -text
120
  hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/v2.7.0/UCR2/GCC/lib_ucr2_hd_wl_sta_intwpa_v2.7.0.a filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
118
  hardware/arduino/avr/firmwares/wifishield/wifi_dnld/src/Doc/SPB104[[:space:]]product[[:space:]]brief.pdf filter=lfs diff=lfs merge=lfs -text
119
  hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/v2.7.0/UCR1/GCC/lib_ucr1_hd_wl_sta_intwpa_v2.7.0.a filter=lfs diff=lfs merge=lfs -text
120
  hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/v2.7.0/UCR2/GCC/lib_ucr2_hd_wl_sta_intwpa_v2.7.0.a filter=lfs diff=lfs merge=lfs -text
121
+ hardware/tools/avr/avr/bin/ar.exe filter=lfs diff=lfs merge=lfs -text
122
+ hardware/tools/avr/avr/bin/as.exe filter=lfs diff=lfs merge=lfs -text
123
+ hardware/tools/avr/avr/bin/ld.exe filter=lfs diff=lfs merge=lfs -text
124
+ hardware/tools/avr/avr/bin/libiconv-2.dll filter=lfs diff=lfs merge=lfs -text
125
+ hardware/tools/avr/avr/bin/nm.exe filter=lfs diff=lfs merge=lfs -text
126
+ hardware/tools/avr/avr/bin/objcopy.exe filter=lfs diff=lfs merge=lfs -text
127
+ hardware/tools/avr/avr/bin/objdump.exe filter=lfs diff=lfs merge=lfs -text
128
+ hardware/tools/avr/avr/bin/ranlib.exe filter=lfs diff=lfs merge=lfs -text
129
+ hardware/tools/avr/avr/bin/readelf.exe filter=lfs diff=lfs merge=lfs -text
130
+ hardware/tools/avr/avr/bin/strip.exe filter=lfs diff=lfs merge=lfs -text
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/pbuf.c ADDED
@@ -0,0 +1,931 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ * Packet buffer management
6
+ *
7
+ * Packets are built from the pbuf data structure. It supports dynamic
8
+ * memory allocation for packet contents or can reference externally
9
+ * managed packet contents both in RAM and ROM. Quick allocation for
10
+ * incoming packets is provided through pools with fixed sized pbufs.
11
+ *
12
+ * A packet may span over multiple pbufs, chained as a singly linked
13
+ * list. This is called a "pbuf chain".
14
+ *
15
+ * Multiple packets may be queued, also using this singly linked list.
16
+ * This is called a "packet queue".
17
+ *
18
+ * So, a packet queue consists of one or more pbuf chains, each of
19
+ * which consist of one or more pbufs. CURRENTLY, PACKET QUEUES ARE
20
+ * NOT SUPPORTED!!! Use helper structs to queue multiple packets.
21
+ *
22
+ * The differences between a pbuf chain and a packet queue are very
23
+ * precise but subtle.
24
+ *
25
+ * The last pbuf of a packet has a ->tot_len field that equals the
26
+ * ->len field. It can be found by traversing the list. If the last
27
+ * pbuf of a packet has a ->next field other than NULL, more packets
28
+ * are on the queue.
29
+ *
30
+ * Therefore, looping through a pbuf of a single packet, has an
31
+ * loop end condition (tot_len == p->len), NOT (next == NULL).
32
+ */
33
+
34
+ /*
35
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
36
+ * All rights reserved.
37
+ *
38
+ * Redistribution and use in source and binary forms, with or without modification,
39
+ * are permitted provided that the following conditions are met:
40
+ *
41
+ * 1. Redistributions of source code must retain the above copyright notice,
42
+ * this list of conditions and the following disclaimer.
43
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
44
+ * this list of conditions and the following disclaimer in the documentation
45
+ * and/or other materials provided with the distribution.
46
+ * 3. The name of the author may not be used to endorse or promote products
47
+ * derived from this software without specific prior written permission.
48
+ *
49
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
50
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
51
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
52
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
53
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
54
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
56
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
57
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
58
+ * OF SUCH DAMAGE.
59
+ *
60
+ * This file is part of the lwIP TCP/IP stack.
61
+ *
62
+ * Author: Adam Dunkels <adam@sics.se>
63
+ *
64
+ */
65
+
66
+ #include "lwip/opt.h"
67
+
68
+ #include "lwip/stats.h"
69
+ #include "lwip/def.h"
70
+ #include "lwip/mem.h"
71
+ #include "lwip/memp.h"
72
+ #include "lwip/pbuf.h"
73
+ #include "lwip/sys.h"
74
+ #include "arch/perf.h"
75
+ #if TCP_QUEUE_OOSEQ
76
+ #include "lwip/tcp.h"
77
+ #endif
78
+
79
+ #include <string.h>
80
+
81
+ #define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
82
+ /* Since the pool is created in memp, PBUF_POOL_BUFSIZE will be automatically
83
+ aligned there. Therefore, PBUF_POOL_BUFSIZE_ALIGNED can be used here. */
84
+ #define PBUF_POOL_BUFSIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE)
85
+
86
+ #if !TCP_QUEUE_OOSEQ || NO_SYS
87
+ #define PBUF_POOL_IS_EMPTY()
88
+ #else /* !TCP_QUEUE_OOSEQ || NO_SYS */
89
+ /** Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty */
90
+ #ifndef PBUF_POOL_FREE_OOSEQ
91
+ #define PBUF_POOL_FREE_OOSEQ 1
92
+ #endif /* PBUF_POOL_FREE_OOSEQ */
93
+
94
+ #if PBUF_POOL_FREE_OOSEQ
95
+ #include "lwip/tcpip.h"
96
+ #define PBUF_POOL_IS_EMPTY() pbuf_pool_is_empty()
97
+ static u8_t pbuf_free_ooseq_queued;
98
+ /**
99
+ * Attempt to reclaim some memory from queued out-of-sequence TCP segments
100
+ * if we run out of pool pbufs. It's better to give priority to new packets
101
+ * if we're running out.
102
+ *
103
+ * This must be done in the correct thread context therefore this function
104
+ * can only be used with NO_SYS=0 and through tcpip_callback.
105
+ */
106
+ static void
107
+ pbuf_free_ooseq(void* arg)
108
+ {
109
+ struct tcp_pcb* pcb;
110
+ SYS_ARCH_DECL_PROTECT(old_level);
111
+ LWIP_UNUSED_ARG(arg);
112
+
113
+ SYS_ARCH_PROTECT(old_level);
114
+ pbuf_free_ooseq_queued = 0;
115
+ SYS_ARCH_UNPROTECT(old_level);
116
+
117
+ for (pcb = tcp_active_pcbs; NULL != pcb; pcb = pcb->next) {
118
+ if (NULL != pcb->ooseq) {
119
+ /** Free the ooseq pbufs of one PCB only */
120
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free_ooseq: freeing out-of-sequence pbufs\n"));
121
+ tcp_segs_free(pcb->ooseq);
122
+ pcb->ooseq = NULL;
123
+ return;
124
+ }
125
+ }
126
+ }
127
+
128
+ /** Queue a call to pbuf_free_ooseq if not already queued. */
129
+ static void
130
+ pbuf_pool_is_empty(void)
131
+ {
132
+ u8_t queued;
133
+ SYS_ARCH_DECL_PROTECT(old_level);
134
+
135
+ SYS_ARCH_PROTECT(old_level);
136
+ queued = pbuf_free_ooseq_queued;
137
+ pbuf_free_ooseq_queued = 1;
138
+ SYS_ARCH_UNPROTECT(old_level);
139
+
140
+ if(!queued) {
141
+ /* queue a call to pbuf_free_ooseq if not already queued */
142
+ if(tcpip_callback_with_block(pbuf_free_ooseq, NULL, 0) != ERR_OK) {
143
+ SYS_ARCH_PROTECT(old_level);
144
+ pbuf_free_ooseq_queued = 0;
145
+ SYS_ARCH_UNPROTECT(old_level);
146
+ }
147
+ }
148
+ }
149
+ #endif /* PBUF_POOL_FREE_OOSEQ */
150
+ #endif /* !TCP_QUEUE_OOSEQ || NO_SYS */
151
+
152
+ /**
153
+ * Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type).
154
+ *
155
+ * The actual memory allocated for the pbuf is determined by the
156
+ * layer at which the pbuf is allocated and the requested size
157
+ * (from the size parameter).
158
+ *
159
+ * @param layer flag to define header size
160
+ * @param length size of the pbuf's payload
161
+ * @param type this parameter decides how and where the pbuf
162
+ * should be allocated as follows:
163
+ *
164
+ * - PBUF_RAM: buffer memory for pbuf is allocated as one large
165
+ * chunk. This includes protocol headers as well.
166
+ * - PBUF_ROM: no buffer memory is allocated for the pbuf, even for
167
+ * protocol headers. Additional headers must be prepended
168
+ * by allocating another pbuf and chain in to the front of
169
+ * the ROM pbuf. It is assumed that the memory used is really
170
+ * similar to ROM in that it is immutable and will not be
171
+ * changed. Memory which is dynamic should generally not
172
+ * be attached to PBUF_ROM pbufs. Use PBUF_REF instead.
173
+ * - PBUF_REF: no buffer memory is allocated for the pbuf, even for
174
+ * protocol headers. It is assumed that the pbuf is only
175
+ * being used in a single thread. If the pbuf gets queued,
176
+ * then pbuf_take should be called to copy the buffer.
177
+ * - PBUF_POOL: the pbuf is allocated as a pbuf chain, with pbufs from
178
+ * the pbuf pool that is allocated during pbuf_init().
179
+ *
180
+ * @return the allocated pbuf. If multiple pbufs where allocated, this
181
+ * is the first pbuf of a pbuf chain.
182
+ */
183
+ struct pbuf *
184
+ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
185
+ {
186
+ struct pbuf *p, *q, *r;
187
+ u16_t offset;
188
+ s32_t rem_len; /* remaining length */
189
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F")\n", length));
190
+
191
+ /* determine header offset */
192
+ offset = 0;
193
+ switch (layer) {
194
+ case PBUF_TRANSPORT:
195
+ /* add room for transport (often TCP) layer header */
196
+ offset += PBUF_TRANSPORT_HLEN;
197
+ /* FALLTHROUGH */
198
+ case PBUF_IP:
199
+ /* add room for IP layer header */
200
+ offset += PBUF_IP_HLEN;
201
+ /* FALLTHROUGH */
202
+ case PBUF_LINK:
203
+ /* add room for link layer header */
204
+ offset += PBUF_LINK_HLEN;
205
+ break;
206
+ case PBUF_RAW:
207
+ break;
208
+ default:
209
+ LWIP_ASSERT("pbuf_alloc: bad pbuf layer", 0);
210
+ return NULL;
211
+ }
212
+
213
+ switch (type) {
214
+ case PBUF_POOL:
215
+ /* allocate head of pbuf chain into p */
216
+ p = memp_malloc(MEMP_PBUF_POOL);
217
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc: allocated pbuf %p\n", (void *)p));
218
+ if (p == NULL) {
219
+ PBUF_POOL_IS_EMPTY();
220
+ return NULL;
221
+ }
222
+ p->type = type;
223
+ p->next = NULL;
224
+
225
+ /* make the payload pointer point 'offset' bytes into pbuf data memory */
226
+ p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + (SIZEOF_STRUCT_PBUF + offset)));
227
+ LWIP_ASSERT("pbuf_alloc: pbuf p->payload properly aligned",
228
+ ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
229
+ /* the total length of the pbuf chain is the requested size */
230
+ p->tot_len = length;
231
+ /* set the length of the first pbuf in the chain */
232
+ p->len = LWIP_MIN(length, PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset));
233
+ LWIP_ASSERT("check p->payload + p->len does not overflow pbuf",
234
+ ((u8_t*)p->payload + p->len <=
235
+ (u8_t*)p + SIZEOF_STRUCT_PBUF + PBUF_POOL_BUFSIZE_ALIGNED));
236
+ LWIP_ASSERT("PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT",
237
+ (PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset)) > 0 );
238
+ /* set reference count (needed here in case we fail) */
239
+ p->ref = 1;
240
+
241
+ /* now allocate the tail of the pbuf chain */
242
+
243
+ /* remember first pbuf for linkage in next iteration */
244
+ r = p;
245
+ /* remaining length to be allocated */
246
+ rem_len = length - p->len;
247
+ /* any remaining pbufs to be allocated? */
248
+ while (rem_len > 0) {
249
+ q = memp_malloc(MEMP_PBUF_POOL);
250
+ if (q == NULL) {
251
+ PBUF_POOL_IS_EMPTY();
252
+ /* free chain so far allocated */
253
+ pbuf_free(p);
254
+ /* bail out unsuccesfully */
255
+ return NULL;
256
+ }
257
+ q->type = type;
258
+ q->flags = 0;
259
+ q->next = NULL;
260
+ /* make previous pbuf point to this pbuf */
261
+ r->next = q;
262
+ /* set total length of this pbuf and next in chain */
263
+ LWIP_ASSERT("rem_len < max_u16_t", rem_len < 0xffff);
264
+ q->tot_len = (u16_t)rem_len;
265
+ /* this pbuf length is pool size, unless smaller sized tail */
266
+ q->len = LWIP_MIN((u16_t)rem_len, PBUF_POOL_BUFSIZE_ALIGNED);
267
+ q->payload = (void *)((u8_t *)q + SIZEOF_STRUCT_PBUF);
268
+ LWIP_ASSERT("pbuf_alloc: pbuf q->payload properly aligned",
269
+ ((mem_ptr_t)q->payload % MEM_ALIGNMENT) == 0);
270
+ LWIP_ASSERT("check p->payload + p->len does not overflow pbuf",
271
+ ((u8_t*)p->payload + p->len <=
272
+ (u8_t*)p + SIZEOF_STRUCT_PBUF + PBUF_POOL_BUFSIZE_ALIGNED));
273
+ q->ref = 1;
274
+ /* calculate remaining length to be allocated */
275
+ rem_len -= q->len;
276
+ /* remember this pbuf for linkage in next iteration */
277
+ r = q;
278
+ }
279
+ /* end of chain */
280
+ /*r->next = NULL;*/
281
+
282
+ break;
283
+ case PBUF_RAM:
284
+ /* If pbuf is to be allocated in RAM, allocate memory for it. */
285
+ p = (struct pbuf*)mem_malloc(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF + offset) + LWIP_MEM_ALIGN_SIZE(length));
286
+ if (p == NULL) {
287
+ return NULL;
288
+ }
289
+ /* Set up internal structure of the pbuf. */
290
+ p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset));
291
+ p->len = p->tot_len = length;
292
+ p->next = NULL;
293
+ p->type = type;
294
+
295
+ LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
296
+ ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
297
+ break;
298
+ /* pbuf references existing (non-volatile static constant) ROM payload? */
299
+ case PBUF_ROM:
300
+ /* pbuf references existing (externally allocated) RAM payload? */
301
+ case PBUF_REF:
302
+ /* only allocate memory for the pbuf structure */
303
+ p = memp_malloc(MEMP_PBUF);
304
+ if (p == NULL) {
305
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
306
+ ("pbuf_alloc: Could not allocate MEMP_PBUF for PBUF_%s.\n",
307
+ (type == PBUF_ROM) ? "ROM" : "REF"));
308
+ return NULL;
309
+ }
310
+ /* caller must set this field properly, afterwards */
311
+ p->payload = NULL;
312
+ p->len = p->tot_len = length;
313
+ p->next = NULL;
314
+ p->type = type;
315
+ break;
316
+ default:
317
+ LWIP_ASSERT("pbuf_alloc: erroneous type", 0);
318
+ return NULL;
319
+ }
320
+ /* set reference count */
321
+ p->ref = 1;
322
+ /* set flags */
323
+ p->flags = 0;
324
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p));
325
+ return p;
326
+ }
327
+
328
+
329
+ /**
330
+ * Shrink a pbuf chain to a desired length.
331
+ *
332
+ * @param p pbuf to shrink.
333
+ * @param new_len desired new length of pbuf chain
334
+ *
335
+ * Depending on the desired length, the first few pbufs in a chain might
336
+ * be skipped and left unchanged. The new last pbuf in the chain will be
337
+ * resized, and any remaining pbufs will be freed.
338
+ *
339
+ * @note If the pbuf is ROM/REF, only the ->tot_len and ->len fields are adjusted.
340
+ * @note May not be called on a packet queue.
341
+ *
342
+ * @note Despite its name, pbuf_realloc cannot grow the size of a pbuf (chain).
343
+ */
344
+ void
345
+ pbuf_realloc(struct pbuf *p, u16_t new_len)
346
+ {
347
+ struct pbuf *q;
348
+ u16_t rem_len; /* remaining length */
349
+ s32_t grow;
350
+
351
+ LWIP_ASSERT("pbuf_realloc: p != NULL", p != NULL);
352
+ LWIP_ASSERT("pbuf_realloc: sane p->type", p->type == PBUF_POOL ||
353
+ p->type == PBUF_ROM ||
354
+ p->type == PBUF_RAM ||
355
+ p->type == PBUF_REF);
356
+
357
+ /* desired length larger than current length? */
358
+ if (new_len >= p->tot_len) {
359
+ /* enlarging not yet supported */
360
+ return;
361
+ }
362
+
363
+ /* the pbuf chain grows by (new_len - p->tot_len) bytes
364
+ * (which may be negative in case of shrinking) */
365
+ grow = new_len - p->tot_len;
366
+
367
+ /* first, step over any pbufs that should remain in the chain */
368
+ rem_len = new_len;
369
+ q = p;
370
+ /* should this pbuf be kept? */
371
+ while (rem_len > q->len) {
372
+ /* decrease remaining length by pbuf length */
373
+ rem_len -= q->len;
374
+ /* decrease total length indicator */
375
+ LWIP_ASSERT("grow < max_u16_t", grow < 0xffff);
376
+ q->tot_len += (u16_t)grow;
377
+ /* proceed to next pbuf in chain */
378
+ q = q->next;
379
+ LWIP_ASSERT("pbuf_realloc: q != NULL", q != NULL);
380
+ }
381
+ /* we have now reached the new last pbuf (in q) */
382
+ /* rem_len == desired length for pbuf q */
383
+
384
+ /* shrink allocated memory for PBUF_RAM */
385
+ /* (other types merely adjust their length fields */
386
+ if ((q->type == PBUF_RAM) && (rem_len != q->len)) {
387
+ /* reallocate and adjust the length of the pbuf that will be split */
388
+ q = mem_realloc(q, (u8_t *)q->payload - (u8_t *)q + rem_len);
389
+ LWIP_ASSERT("mem_realloc give q == NULL", q != NULL);
390
+ }
391
+ /* adjust length fields for new last pbuf */
392
+ q->len = rem_len;
393
+ q->tot_len = q->len;
394
+
395
+ /* any remaining pbufs in chain? */
396
+ if (q->next != NULL) {
397
+ /* free remaining pbufs in chain */
398
+ pbuf_free(q->next);
399
+ }
400
+ /* q is last packet in chain */
401
+ q->next = NULL;
402
+
403
+ }
404
+
405
+ /**
406
+ * Adjusts the payload pointer to hide or reveal headers in the payload.
407
+ *
408
+ * Adjusts the ->payload pointer so that space for a header
409
+ * (dis)appears in the pbuf payload.
410
+ *
411
+ * The ->payload, ->tot_len and ->len fields are adjusted.
412
+ *
413
+ * @param p pbuf to change the header size.
414
+ * @param header_size_increment Number of bytes to increment header size which
415
+ * increases the size of the pbuf. New space is on the front.
416
+ * (Using a negative value decreases the header size.)
417
+ * If hdr_size_inc is 0, this function does nothing and returns succesful.
418
+ *
419
+ * PBUF_ROM and PBUF_REF type buffers cannot have their sizes increased, so
420
+ * the call will fail. A check is made that the increase in header size does
421
+ * not move the payload pointer in front of the start of the buffer.
422
+ * @return non-zero on failure, zero on success.
423
+ *
424
+ */
425
+ u8_t
426
+ pbuf_header(struct pbuf *p, s16_t header_size_increment)
427
+ {
428
+ u16_t type;
429
+ void *payload;
430
+ u16_t increment_magnitude;
431
+
432
+ LWIP_ASSERT("p != NULL", p != NULL);
433
+ if ((header_size_increment == 0) || (p == NULL))
434
+ return 0;
435
+
436
+ if (header_size_increment < 0){
437
+ increment_magnitude = -header_size_increment;
438
+ /* Check that we aren't going to move off the end of the pbuf */
439
+ LWIP_ERROR("increment_magnitude <= p->len", (increment_magnitude <= p->len), return 1;);
440
+ } else {
441
+ increment_magnitude = header_size_increment;
442
+ #if 0
443
+ /* Can't assert these as some callers speculatively call
444
+ pbuf_header() to see if it's OK. Will return 1 below instead. */
445
+ /* Check that we've got the correct type of pbuf to work with */
446
+ LWIP_ASSERT("p->type == PBUF_RAM || p->type == PBUF_POOL",
447
+ p->type == PBUF_RAM || p->type == PBUF_POOL);
448
+ /* Check that we aren't going to move off the beginning of the pbuf */
449
+ LWIP_ASSERT("p->payload - increment_magnitude >= p + SIZEOF_STRUCT_PBUF",
450
+ (u8_t *)p->payload - increment_magnitude >= (u8_t *)p + SIZEOF_STRUCT_PBUF);
451
+ #endif
452
+ }
453
+
454
+ type = p->type;
455
+ /* remember current payload pointer */
456
+ payload = p->payload;
457
+
458
+ /* pbuf types containing payloads? */
459
+ if (type == PBUF_RAM || type == PBUF_POOL) {
460
+ /* set new payload pointer */
461
+ p->payload = (u8_t *)p->payload - header_size_increment;
462
+ /* boundary check fails? */
463
+ if ((u8_t *)p->payload < (u8_t *)p + SIZEOF_STRUCT_PBUF) {
464
+ LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
465
+ ("pbuf_header: failed as %p < %p (not enough space for new header size)\n",
466
+ (void *)p->payload, (void *)(p + 1)));
467
+ /* restore old payload pointer */
468
+ p->payload = payload;
469
+ /* bail out unsuccesfully */
470
+ return 1;
471
+ }
472
+ /* pbuf types refering to external payloads? */
473
+ } else if (type == PBUF_REF || type == PBUF_ROM) {
474
+ /* hide a header in the payload? */
475
+ if ((header_size_increment < 0) && (increment_magnitude <= p->len)) {
476
+ /* increase payload pointer */
477
+ p->payload = (u8_t *)p->payload - header_size_increment;
478
+ } else {
479
+ /* cannot expand payload to front (yet!)
480
+ * bail out unsuccesfully */
481
+ return 1;
482
+ }
483
+ }
484
+ else {
485
+ /* Unknown type */
486
+ LWIP_ASSERT("bad pbuf type", 0);
487
+ return 1;
488
+ }
489
+ /* modify pbuf length fields */
490
+ p->len += header_size_increment;
491
+ p->tot_len += header_size_increment;
492
+
493
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_header: old %p new %p (%"S16_F")\n",
494
+ (void *)payload, (void *)p->payload, header_size_increment));
495
+
496
+ return 0;
497
+ }
498
+
499
+ /**
500
+ * Dereference a pbuf chain or queue and deallocate any no-longer-used
501
+ * pbufs at the head of this chain or queue.
502
+ *
503
+ * Decrements the pbuf reference count. If it reaches zero, the pbuf is
504
+ * deallocated.
505
+ *
506
+ * For a pbuf chain, this is repeated for each pbuf in the chain,
507
+ * up to the first pbuf which has a non-zero reference count after
508
+ * decrementing. So, when all reference counts are one, the whole
509
+ * chain is free'd.
510
+ *
511
+ * @param p The pbuf (chain) to be dereferenced.
512
+ *
513
+ * @return the number of pbufs that were de-allocated
514
+ * from the head of the chain.
515
+ *
516
+ * @note MUST NOT be called on a packet queue (Not verified to work yet).
517
+ * @note the reference counter of a pbuf equals the number of pointers
518
+ * that refer to the pbuf (or into the pbuf).
519
+ *
520
+ * @internal examples:
521
+ *
522
+ * Assuming existing chains a->b->c with the following reference
523
+ * counts, calling pbuf_free(a) results in:
524
+ *
525
+ * 1->2->3 becomes ...1->3
526
+ * 3->3->3 becomes 2->3->3
527
+ * 1->1->2 becomes ......1
528
+ * 2->1->1 becomes 1->1->1
529
+ * 1->1->1 becomes .......
530
+ *
531
+ */
532
+ u8_t
533
+ pbuf_free(struct pbuf *p)
534
+ {
535
+ u16_t type;
536
+ struct pbuf *q;
537
+ u8_t count;
538
+
539
+ if (p == NULL) {
540
+ LWIP_ASSERT("p != NULL", p != NULL);
541
+ /* if assertions are disabled, proceed with debug output */
542
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
543
+ ("pbuf_free(p == NULL) was called.\n"));
544
+ return 0;
545
+ }
546
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free(%p)\n", (void *)p));
547
+
548
+ PERF_START;
549
+
550
+ LWIP_ASSERT("pbuf_free: sane type",
551
+ p->type == PBUF_RAM || p->type == PBUF_ROM ||
552
+ p->type == PBUF_REF || p->type == PBUF_POOL);
553
+
554
+ count = 0;
555
+ /* de-allocate all consecutive pbufs from the head of the chain that
556
+ * obtain a zero reference count after decrementing*/
557
+ while (p != NULL) {
558
+ u16_t ref;
559
+ SYS_ARCH_DECL_PROTECT(old_level);
560
+ /* Since decrementing ref cannot be guaranteed to be a single machine operation
561
+ * we must protect it. We put the new ref into a local variable to prevent
562
+ * further protection. */
563
+ SYS_ARCH_PROTECT(old_level);
564
+ /* all pbufs in a chain are referenced at least once */
565
+ LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0);
566
+ /* decrease reference count (number of pointers to pbuf) */
567
+ ref = --(p->ref);
568
+ SYS_ARCH_UNPROTECT(old_level);
569
+ /* this pbuf is no longer referenced to? */
570
+ if (ref == 0) {
571
+ /* remember next pbuf in chain for next iteration */
572
+ q = p->next;
573
+ LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: deallocating %p\n", (void *)p));
574
+ type = p->type;
575
+ /* is this a pbuf from the pool? */
576
+ if (type == PBUF_POOL) {
577
+ memp_free(MEMP_PBUF_POOL, p);
578
+ /* is this a ROM or RAM referencing pbuf? */
579
+ } else if (type == PBUF_ROM || type == PBUF_REF) {
580
+ memp_free(MEMP_PBUF, p);
581
+ /* type == PBUF_RAM */
582
+ } else {
583
+ mem_free(p);
584
+ }
585
+ count++;
586
+ /* proceed to next pbuf */
587
+ p = q;
588
+ /* p->ref > 0, this pbuf is still referenced to */
589
+ /* (and so the remaining pbufs in chain as well) */
590
+ } else {
591
+ LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: %p has ref %"U16_F", ending here.\n", (void *)p, ref));
592
+ /* stop walking through the chain */
593
+ p = NULL;
594
+ }
595
+ }
596
+ PERF_STOP("pbuf_free");
597
+ /* return number of de-allocated pbufs */
598
+ return count;
599
+ }
600
+
601
+ /**
602
+ * Count number of pbufs in a chain
603
+ *
604
+ * @param p first pbuf of chain
605
+ * @return the number of pbufs in a chain
606
+ */
607
+
608
+ u8_t
609
+ pbuf_clen(struct pbuf *p)
610
+ {
611
+ u8_t len;
612
+
613
+ len = 0;
614
+ while (p != NULL) {
615
+ ++len;
616
+ p = p->next;
617
+ }
618
+ return len;
619
+ }
620
+
621
+ /**
622
+ * Increment the reference count of the pbuf.
623
+ *
624
+ * @param p pbuf to increase reference counter of
625
+ *
626
+ */
627
+ void
628
+ pbuf_ref(struct pbuf *p)
629
+ {
630
+ SYS_ARCH_DECL_PROTECT(old_level);
631
+ /* pbuf given? */
632
+ if (p != NULL) {
633
+ SYS_ARCH_PROTECT(old_level);
634
+ ++(p->ref);
635
+ SYS_ARCH_UNPROTECT(old_level);
636
+ }
637
+ }
638
+
639
+ /**
640
+ * Concatenate two pbufs (each may be a pbuf chain) and take over
641
+ * the caller's reference of the tail pbuf.
642
+ *
643
+ * @note The caller MAY NOT reference the tail pbuf afterwards.
644
+ * Use pbuf_chain() for that purpose.
645
+ *
646
+ * @see pbuf_chain()
647
+ */
648
+
649
+ void
650
+ pbuf_cat(struct pbuf *h, struct pbuf *t)
651
+ {
652
+ struct pbuf *p;
653
+
654
+ LWIP_ERROR("(h != NULL) && (t != NULL) (programmer violates API)",
655
+ ((h != NULL) && (t != NULL)), return;);
656
+
657
+ /* proceed to last pbuf of chain */
658
+ for (p = h; p->next != NULL; p = p->next) {
659
+ /* add total length of second chain to all totals of first chain */
660
+ p->tot_len += t->tot_len;
661
+ }
662
+ /* { p is last pbuf of first h chain, p->next == NULL } */
663
+ LWIP_ASSERT("p->tot_len == p->len (of last pbuf in chain)", p->tot_len == p->len);
664
+ LWIP_ASSERT("p->next == NULL", p->next == NULL);
665
+ /* add total length of second chain to last pbuf total of first chain */
666
+ p->tot_len += t->tot_len;
667
+ /* chain last pbuf of head (p) with first of tail (t) */
668
+ p->next = t;
669
+ /* p->next now references t, but the caller will drop its reference to t,
670
+ * so netto there is no change to the reference count of t.
671
+ */
672
+ }
673
+
674
+ /**
675
+ * Chain two pbufs (or pbuf chains) together.
676
+ *
677
+ * The caller MUST call pbuf_free(t) once it has stopped
678
+ * using it. Use pbuf_cat() instead if you no longer use t.
679
+ *
680
+ * @param h head pbuf (chain)
681
+ * @param t tail pbuf (chain)
682
+ * @note The pbufs MUST belong to the same packet.
683
+ * @note MAY NOT be called on a packet queue.
684
+ *
685
+ * The ->tot_len fields of all pbufs of the head chain are adjusted.
686
+ * The ->next field of the last pbuf of the head chain is adjusted.
687
+ * The ->ref field of the first pbuf of the tail chain is adjusted.
688
+ *
689
+ */
690
+ void
691
+ pbuf_chain(struct pbuf *h, struct pbuf *t)
692
+ {
693
+ pbuf_cat(h, t);
694
+ /* t is now referenced by h */
695
+ pbuf_ref(t);
696
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_chain: %p references %p\n", (void *)h, (void *)t));
697
+ }
698
+
699
+ /**
700
+ * Dechains the first pbuf from its succeeding pbufs in the chain.
701
+ *
702
+ * Makes p->tot_len field equal to p->len.
703
+ * @param p pbuf to dechain
704
+ * @return remainder of the pbuf chain, or NULL if it was de-allocated.
705
+ * @note May not be called on a packet queue.
706
+ */
707
+ struct pbuf *
708
+ pbuf_dechain(struct pbuf *p)
709
+ {
710
+ struct pbuf *q;
711
+ u8_t tail_gone = 1;
712
+ /* tail */
713
+ q = p->next;
714
+ /* pbuf has successor in chain? */
715
+ if (q != NULL) {
716
+ /* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */
717
+ LWIP_ASSERT("p->tot_len == p->len + q->tot_len", q->tot_len == p->tot_len - p->len);
718
+ /* enforce invariant if assertion is disabled */
719
+ q->tot_len = p->tot_len - p->len;
720
+ /* decouple pbuf from remainder */
721
+ p->next = NULL;
722
+ /* total length of pbuf p is its own length only */
723
+ p->tot_len = p->len;
724
+ /* q is no longer referenced by p, free it */
725
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_dechain: unreferencing %p\n", (void *)q));
726
+ tail_gone = pbuf_free(q);
727
+ if (tail_gone > 0) {
728
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE,
729
+ ("pbuf_dechain: deallocated %p (as it is no longer referenced)\n", (void *)q));
730
+ }
731
+ /* return remaining tail or NULL if deallocated */
732
+ }
733
+ /* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */
734
+ LWIP_ASSERT("p->tot_len == p->len", p->tot_len == p->len);
735
+ return ((tail_gone > 0) ? NULL : q);
736
+ }
737
+
738
+ /**
739
+ *
740
+ * Create PBUF_RAM copies of pbufs.
741
+ *
742
+ * Used to queue packets on behalf of the lwIP stack, such as
743
+ * ARP based queueing.
744
+ *
745
+ * @note You MUST explicitly use p = pbuf_take(p);
746
+ *
747
+ * @note Only one packet is copied, no packet queue!
748
+ *
749
+ * @param p_to pbuf destination of the copy
750
+ * @param p_from pbuf source of the copy
751
+ *
752
+ * @return ERR_OK if pbuf was copied
753
+ * ERR_ARG if one of the pbufs is NULL or p_to is not big
754
+ * enough to hold p_from
755
+ */
756
+ err_t
757
+ pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)
758
+ {
759
+ u16_t offset_to=0, offset_from=0, len;
760
+
761
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy(%p, %p)\n",
762
+ (void*)p_to, (void*)p_from));
763
+
764
+ /* is the target big enough to hold the source? */
765
+ LWIP_ERROR("pbuf_copy: target not big enough to hold source", ((p_to != NULL) &&
766
+ (p_from != NULL) && (p_to->tot_len >= p_from->tot_len)), return ERR_ARG;);
767
+
768
+ /* iterate through pbuf chain */
769
+ do
770
+ {
771
+ LWIP_ASSERT("p_to != NULL", p_to != NULL);
772
+ /* copy one part of the original chain */
773
+ if ((p_to->len - offset_to) >= (p_from->len - offset_from)) {
774
+ /* complete current p_from fits into current p_to */
775
+ len = p_from->len - offset_from;
776
+ } else {
777
+ /* current p_from does not fit into current p_to */
778
+ len = p_to->len - offset_to;
779
+ }
780
+ MEMCPY((u8_t*)p_to->payload + offset_to, (u8_t*)p_from->payload + offset_from, len);
781
+ offset_to += len;
782
+ offset_from += len;
783
+ LWIP_ASSERT("offset_to <= p_to->len", offset_to <= p_to->len);
784
+ if (offset_to == p_to->len) {
785
+ /* on to next p_to (if any) */
786
+ offset_to = 0;
787
+ p_to = p_to->next;
788
+ }
789
+ LWIP_ASSERT("offset_from <= p_from->len", offset_from <= p_from->len);
790
+ if (offset_from >= p_from->len) {
791
+ /* on to next p_from (if any) */
792
+ offset_from = 0;
793
+ p_from = p_from->next;
794
+ }
795
+
796
+ if((p_from != NULL) && (p_from->len == p_from->tot_len)) {
797
+ /* don't copy more than one packet! */
798
+ LWIP_ERROR("pbuf_copy() does not allow packet queues!\n",
799
+ (p_from->next == NULL), return ERR_VAL;);
800
+ }
801
+ if((p_to != NULL) && (p_to->len == p_to->tot_len)) {
802
+ /* don't copy more than one packet! */
803
+ LWIP_ERROR("pbuf_copy() does not allow packet queues!\n",
804
+ (p_to->next == NULL), return ERR_VAL;);
805
+ }
806
+ } while (p_from);
807
+ LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy: end of chain reached.\n"));
808
+ return ERR_OK;
809
+ }
810
+
811
+ /**
812
+ * Copy (part of) the contents of a packet buffer
813
+ * to an application supplied buffer.
814
+ *
815
+ * @param buf the pbuf from which to copy data
816
+ * @param dataptr the application supplied buffer
817
+ * @param len length of data to copy (dataptr must be big enough). No more
818
+ * than buf->tot_len will be copied, irrespective of len
819
+ * @param offset offset into the packet buffer from where to begin copying len bytes
820
+ * @return the number of bytes copied, or 0 on failure
821
+ */
822
+ u16_t
823
+ pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
824
+ {
825
+ struct pbuf *p;
826
+ u16_t left;
827
+ u16_t buf_copy_len;
828
+ u16_t copied_total = 0;
829
+
830
+ LWIP_ERROR("pbuf_copy_partial: invalid buf", (buf != NULL), return 0;);
831
+ LWIP_ERROR("pbuf_copy_partial: invalid dataptr", (dataptr != NULL), return 0;);
832
+
833
+ left = 0;
834
+
835
+ if((buf == NULL) || (dataptr == NULL)) {
836
+ return 0;
837
+ }
838
+
839
+ /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
840
+ for(p = buf; len != 0 && p != NULL; p = p->next) {
841
+ if ((offset != 0) && (offset >= p->len)) {
842
+ /* don't copy from this buffer -> on to the next */
843
+ offset -= p->len;
844
+ } else {
845
+ /* copy from this buffer. maybe only partially. */
846
+ buf_copy_len = p->len - offset;
847
+ if (buf_copy_len > len)
848
+ buf_copy_len = len;
849
+ /* copy the necessary parts of the buffer */
850
+ MEMCPY(&((char*)dataptr)[left], &((char*)p->payload)[offset], buf_copy_len);
851
+ copied_total += buf_copy_len;
852
+ left += buf_copy_len;
853
+ len -= buf_copy_len;
854
+ offset = 0;
855
+ }
856
+ }
857
+ return copied_total;
858
+ }
859
+
860
+ /**
861
+ * Copy application supplied data into a pbuf.
862
+ * This function can only be used to copy the equivalent of buf->tot_len data.
863
+ *
864
+ * @param buf pbuf to fill with data
865
+ * @param dataptr application supplied data buffer
866
+ * @param len length of the application supplied data buffer
867
+ *
868
+ * @return ERR_OK if successful, ERR_MEM if the pbuf is not big enough
869
+ */
870
+ err_t
871
+ pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
872
+ {
873
+ struct pbuf *p;
874
+ u16_t buf_copy_len;
875
+ u16_t total_copy_len = len;
876
+ u16_t copied_total = 0;
877
+
878
+ LWIP_ERROR("pbuf_take: invalid buf", (buf != NULL), return 0;);
879
+ LWIP_ERROR("pbuf_take: invalid dataptr", (dataptr != NULL), return 0;);
880
+
881
+ if ((buf == NULL) || (dataptr == NULL) || (buf->tot_len < len)) {
882
+ return ERR_ARG;
883
+ }
884
+
885
+ /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
886
+ for(p = buf; total_copy_len != 0; p = p->next) {
887
+ LWIP_ASSERT("pbuf_take: invalid pbuf", p != NULL);
888
+ buf_copy_len = total_copy_len;
889
+ if (buf_copy_len > p->len) {
890
+ /* this pbuf cannot hold all remaining data */
891
+ buf_copy_len = p->len;
892
+ }
893
+ /* copy the necessary parts of the buffer */
894
+ MEMCPY(p->payload, &((char*)dataptr)[copied_total], buf_copy_len);
895
+ total_copy_len -= buf_copy_len;
896
+ copied_total += buf_copy_len;
897
+ }
898
+ LWIP_ASSERT("did not copy all data", total_copy_len == 0 && copied_total == len);
899
+ return ERR_OK;
900
+ }
901
+
902
+ /**
903
+ * Creates a single pbuf out of a queue of pbufs.
904
+ *
905
+ * @remark: The source pbuf 'p' is not freed by this function because that can
906
+ * be illegal in some places!
907
+ *
908
+ * @param p the source pbuf
909
+ * @param layer pbuf_layer of the new pbuf
910
+ *
911
+ * @return a new, single pbuf (p->next is NULL)
912
+ * or the old pbuf if allocation fails
913
+ */
914
+ struct pbuf*
915
+ pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
916
+ {
917
+ struct pbuf *q;
918
+ err_t err;
919
+ if (p->next == NULL) {
920
+ return p;
921
+ }
922
+ q = pbuf_alloc(layer, p->tot_len, PBUF_RAM);
923
+ if (q == NULL) {
924
+ /* @todo: what do we do now? */
925
+ return p;
926
+ }
927
+ err = pbuf_copy(q, p);
928
+ LWIP_ASSERT("pbuf_copy failed", err == ERR_OK);
929
+ pbuf_free(p);
930
+ return q;
931
+ }
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/raw.c ADDED
@@ -0,0 +1,355 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ * Implementation of raw protocol PCBs for low-level handling of
6
+ * different types of protocols besides (or overriding) those
7
+ * already available in lwIP.
8
+ *
9
+ */
10
+
11
+ /*
12
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
13
+ * All rights reserved.
14
+ *
15
+ * Redistribution and use in source and binary forms, with or without modification,
16
+ * are permitted provided that the following conditions are met:
17
+ *
18
+ * 1. Redistributions of source code must retain the above copyright notice,
19
+ * this list of conditions and the following disclaimer.
20
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
21
+ * this list of conditions and the following disclaimer in the documentation
22
+ * and/or other materials provided with the distribution.
23
+ * 3. The name of the author may not be used to endorse or promote products
24
+ * derived from this software without specific prior written permission.
25
+ *
26
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
29
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
31
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35
+ * OF SUCH DAMAGE.
36
+ *
37
+ * This file is part of the lwIP TCP/IP stack.
38
+ *
39
+ * Author: Adam Dunkels <adam@sics.se>
40
+ *
41
+ */
42
+
43
+ #include "lwip/opt.h"
44
+
45
+ #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
46
+
47
+ #include "lwip/def.h"
48
+ #include "lwip/memp.h"
49
+ #include "lwip/inet.h"
50
+ #include "lwip/ip_addr.h"
51
+ #include "lwip/netif.h"
52
+ #include "lwip/raw.h"
53
+ #include "lwip/stats.h"
54
+ #include "lwip/snmp.h"
55
+ #include "arch/perf.h"
56
+
57
+ #include <string.h>
58
+
59
+ /** The list of RAW PCBs */
60
+ static struct raw_pcb *raw_pcbs;
61
+
62
+ /**
63
+ * Determine if in incoming IP packet is covered by a RAW PCB
64
+ * and if so, pass it to a user-provided receive callback function.
65
+ *
66
+ * Given an incoming IP datagram (as a chain of pbufs) this function
67
+ * finds a corresponding RAW PCB and calls the corresponding receive
68
+ * callback function.
69
+ *
70
+ * @param p pbuf to be demultiplexed to a RAW PCB.
71
+ * @param inp network interface on which the datagram was received.
72
+ * @return - 1 if the packet has been eaten by a RAW PCB receive
73
+ * callback function. The caller MAY NOT not reference the
74
+ * packet any longer, and MAY NOT call pbuf_free().
75
+ * @return - 0 if packet is not eaten (pbuf is still referenced by the
76
+ * caller).
77
+ *
78
+ */
79
+ u8_t
80
+ raw_input(struct pbuf *p, struct netif *inp)
81
+ {
82
+ struct raw_pcb *pcb, *prev;
83
+ struct ip_hdr *iphdr;
84
+ s16_t proto;
85
+ u8_t eaten = 0;
86
+
87
+ LWIP_UNUSED_ARG(inp);
88
+
89
+ iphdr = p->payload;
90
+ proto = IPH_PROTO(iphdr);
91
+
92
+ prev = NULL;
93
+ pcb = raw_pcbs;
94
+ /* loop through all raw pcbs until the packet is eaten by one */
95
+ /* this allows multiple pcbs to match against the packet by design */
96
+ while ((eaten == 0) && (pcb != NULL)) {
97
+ if (pcb->protocol == proto) {
98
+ #if IP_SOF_BROADCAST_RECV
99
+ /* broadcast filter? */
100
+ if ((pcb->so_options & SOF_BROADCAST) || !ip_addr_isbroadcast(&(iphdr->dest), inp))
101
+ #endif /* IP_SOF_BROADCAST_RECV */
102
+ {
103
+ /* receive callback function available? */
104
+ if (pcb->recv != NULL) {
105
+ /* the receive callback function did not eat the packet? */
106
+ if (pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src)) != 0) {
107
+ /* receive function ate the packet */
108
+ p = NULL;
109
+ eaten = 1;
110
+ if (prev != NULL) {
111
+ /* move the pcb to the front of raw_pcbs so that is
112
+ found faster next time */
113
+ prev->next = pcb->next;
114
+ pcb->next = raw_pcbs;
115
+ raw_pcbs = pcb;
116
+ }
117
+ }
118
+ }
119
+ /* no receive callback function was set for this raw PCB */
120
+ }
121
+ /* drop the packet */
122
+ }
123
+ prev = pcb;
124
+ pcb = pcb->next;
125
+ }
126
+ return eaten;
127
+ }
128
+
129
+ /**
130
+ * Bind a RAW PCB.
131
+ *
132
+ * @param pcb RAW PCB to be bound with a local address ipaddr.
133
+ * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to
134
+ * bind to all local interfaces.
135
+ *
136
+ * @return lwIP error code.
137
+ * - ERR_OK. Successful. No error occured.
138
+ * - ERR_USE. The specified IP address is already bound to by
139
+ * another RAW PCB.
140
+ *
141
+ * @see raw_disconnect()
142
+ */
143
+ err_t
144
+ raw_bind(struct raw_pcb *pcb, struct ip_addr *ipaddr)
145
+ {
146
+ ip_addr_set(&pcb->local_ip, ipaddr);
147
+ return ERR_OK;
148
+ }
149
+
150
+ /**
151
+ * Connect an RAW PCB. This function is required by upper layers
152
+ * of lwip. Using the raw api you could use raw_sendto() instead
153
+ *
154
+ * This will associate the RAW PCB with the remote address.
155
+ *
156
+ * @param pcb RAW PCB to be connected with remote address ipaddr and port.
157
+ * @param ipaddr remote IP address to connect with.
158
+ *
159
+ * @return lwIP error code
160
+ *
161
+ * @see raw_disconnect() and raw_sendto()
162
+ */
163
+ err_t
164
+ raw_connect(struct raw_pcb *pcb, struct ip_addr *ipaddr)
165
+ {
166
+ ip_addr_set(&pcb->remote_ip, ipaddr);
167
+ return ERR_OK;
168
+ }
169
+
170
+
171
+ /**
172
+ * Set the callback function for received packets that match the
173
+ * raw PCB's protocol and binding.
174
+ *
175
+ * The callback function MUST either
176
+ * - eat the packet by calling pbuf_free() and returning non-zero. The
177
+ * packet will not be passed to other raw PCBs or other protocol layers.
178
+ * - not free the packet, and return zero. The packet will be matched
179
+ * against further PCBs and/or forwarded to another protocol layers.
180
+ *
181
+ * @return non-zero if the packet was free()d, zero if the packet remains
182
+ * available for others.
183
+ */
184
+ void
185
+ raw_recv(struct raw_pcb *pcb,
186
+ u8_t (* recv)(void *arg, struct raw_pcb *upcb, struct pbuf *p,
187
+ struct ip_addr *addr),
188
+ void *recv_arg)
189
+ {
190
+ /* remember recv() callback and user data */
191
+ pcb->recv = recv;
192
+ pcb->recv_arg = recv_arg;
193
+ }
194
+
195
+ /**
196
+ * Send the raw IP packet to the given address. Note that actually you cannot
197
+ * modify the IP headers (this is inconsistent with the receive callback where
198
+ * you actually get the IP headers), you can only specify the IP payload here.
199
+ * It requires some more changes in lwIP. (there will be a raw_send() function
200
+ * then.)
201
+ *
202
+ * @param pcb the raw pcb which to send
203
+ * @param p the IP payload to send
204
+ * @param ipaddr the destination address of the IP packet
205
+ *
206
+ */
207
+ err_t
208
+ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr)
209
+ {
210
+ err_t err;
211
+ struct netif *netif;
212
+ struct ip_addr *src_ip;
213
+ struct pbuf *q; /* q will be sent down the stack */
214
+
215
+ LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE, ("raw_sendto\n"));
216
+
217
+ /* not enough space to add an IP header to first pbuf in given p chain? */
218
+ if (pbuf_header(p, IP_HLEN)) {
219
+ /* allocate header in new pbuf */
220
+ q = pbuf_alloc(PBUF_IP, 0, PBUF_RAM);
221
+ /* new header pbuf could not be allocated? */
222
+ if (q == NULL) {
223
+ LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("raw_sendto: could not allocate header\n"));
224
+ return ERR_MEM;
225
+ }
226
+ /* chain header q in front of given pbuf p */
227
+ pbuf_chain(q, p);
228
+ /* { first pbuf q points to header pbuf } */
229
+ LWIP_DEBUGF(RAW_DEBUG, ("raw_sendto: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
230
+ } else {
231
+ /* first pbuf q equals given pbuf */
232
+ q = p;
233
+ if(pbuf_header(q, -IP_HLEN)) {
234
+ LWIP_ASSERT("Can't restore header we just removed!", 0);
235
+ return ERR_MEM;
236
+ }
237
+ }
238
+
239
+ if ((netif = ip_route(ipaddr)) == NULL) {
240
+ LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to 0x%"X32_F"\n", ipaddr->addr));
241
+ /* free any temporary header pbuf allocated by pbuf_header() */
242
+ if (q != p) {
243
+ pbuf_free(q);
244
+ }
245
+ return ERR_RTE;
246
+ }
247
+
248
+ #if IP_SOF_BROADCAST
249
+ /* broadcast filter? */
250
+ if ( ((pcb->so_options & SOF_BROADCAST) == 0) && ip_addr_isbroadcast(ipaddr, netif) ) {
251
+ LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
252
+ /* free any temporary header pbuf allocated by pbuf_header() */
253
+ if (q != p) {
254
+ pbuf_free(q);
255
+ }
256
+ return ERR_VAL;
257
+ }
258
+ #endif /* IP_SOF_BROADCAST */
259
+
260
+ if (ip_addr_isany(&pcb->local_ip)) {
261
+ /* use outgoing network interface IP address as source address */
262
+ src_ip = &(netif->ip_addr);
263
+ } else {
264
+ /* use RAW PCB local IP address as source address */
265
+ src_ip = &(pcb->local_ip);
266
+ }
267
+
268
+ #if LWIP_NETIF_HWADDRHINT
269
+ netif->addr_hint = &(pcb->addr_hint);
270
+ #endif /* LWIP_NETIF_HWADDRHINT*/
271
+ err = ip_output_if (q, src_ip, ipaddr, pcb->ttl, pcb->tos, pcb->protocol, netif);
272
+ #if LWIP_NETIF_HWADDRHINT
273
+ netif->addr_hint = NULL;
274
+ #endif /* LWIP_NETIF_HWADDRHINT*/
275
+
276
+ /* did we chain a header earlier? */
277
+ if (q != p) {
278
+ /* free the header */
279
+ pbuf_free(q);
280
+ }
281
+ return err;
282
+ }
283
+
284
+ /**
285
+ * Send the raw IP packet to the address given by raw_connect()
286
+ *
287
+ * @param pcb the raw pcb which to send
288
+ * @param p the IP payload to send
289
+ *
290
+ */
291
+ err_t
292
+ raw_send(struct raw_pcb *pcb, struct pbuf *p)
293
+ {
294
+ return raw_sendto(pcb, p, &pcb->remote_ip);
295
+ }
296
+
297
+ /**
298
+ * Remove an RAW PCB.
299
+ *
300
+ * @param pcb RAW PCB to be removed. The PCB is removed from the list of
301
+ * RAW PCB's and the data structure is freed from memory.
302
+ *
303
+ * @see raw_new()
304
+ */
305
+ void
306
+ raw_remove(struct raw_pcb *pcb)
307
+ {
308
+ struct raw_pcb *pcb2;
309
+ /* pcb to be removed is first in list? */
310
+ if (raw_pcbs == pcb) {
311
+ /* make list start at 2nd pcb */
312
+ raw_pcbs = raw_pcbs->next;
313
+ /* pcb not 1st in list */
314
+ } else {
315
+ for(pcb2 = raw_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
316
+ /* find pcb in raw_pcbs list */
317
+ if (pcb2->next != NULL && pcb2->next == pcb) {
318
+ /* remove pcb from list */
319
+ pcb2->next = pcb->next;
320
+ }
321
+ }
322
+ }
323
+ memp_free(MEMP_RAW_PCB, pcb);
324
+ }
325
+
326
+ /**
327
+ * Create a RAW PCB.
328
+ *
329
+ * @return The RAW PCB which was created. NULL if the PCB data structure
330
+ * could not be allocated.
331
+ *
332
+ * @param proto the protocol number of the IPs payload (e.g. IP_PROTO_ICMP)
333
+ *
334
+ * @see raw_remove()
335
+ */
336
+ struct raw_pcb *
337
+ raw_new(u8_t proto) {
338
+ struct raw_pcb *pcb;
339
+
340
+ LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE, ("raw_new\n"));
341
+
342
+ pcb = memp_malloc(MEMP_RAW_PCB);
343
+ /* could allocate RAW PCB? */
344
+ if (pcb != NULL) {
345
+ /* initialize PCB to all zeroes */
346
+ memset(pcb, 0, sizeof(struct raw_pcb));
347
+ pcb->protocol = proto;
348
+ pcb->ttl = RAW_TTL;
349
+ pcb->next = raw_pcbs;
350
+ raw_pcbs = pcb;
351
+ }
352
+ return pcb;
353
+ }
354
+
355
+ #endif /* LWIP_RAW */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/stats.c ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ * Statistics module
6
+ *
7
+ */
8
+
9
+ /*
10
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
11
+ * All rights reserved.
12
+ *
13
+ * Redistribution and use in source and binary forms, with or without modification,
14
+ * are permitted provided that the following conditions are met:
15
+ *
16
+ * 1. Redistributions of source code must retain the above copyright notice,
17
+ * this list of conditions and the following disclaimer.
18
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
19
+ * this list of conditions and the following disclaimer in the documentation
20
+ * and/or other materials provided with the distribution.
21
+ * 3. The name of the author may not be used to endorse or promote products
22
+ * derived from this software without specific prior written permission.
23
+ *
24
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33
+ * OF SUCH DAMAGE.
34
+ *
35
+ * This file is part of the lwIP TCP/IP stack.
36
+ *
37
+ * Author: Adam Dunkels <adam@sics.se>
38
+ *
39
+ */
40
+
41
+ #include "lwip/opt.h"
42
+
43
+ #if LWIP_STATS /* don't build if not configured for use in lwipopts.h */
44
+
45
+ #include "lwip/def.h"
46
+ #include "lwip/stats.h"
47
+ #include "lwip/mem.h"
48
+
49
+ #include <string.h>
50
+
51
+ struct stats_ lwip_stats;
52
+
53
+ #if LWIP_STATS_DISPLAY
54
+ void
55
+ stats_display_proto(struct stats_proto *proto, char *name)
56
+ {
57
+ LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
58
+ LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", proto->xmit));
59
+ LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", proto->recv));
60
+ LWIP_PLATFORM_DIAG(("fw: %"STAT_COUNTER_F"\n\t", proto->fw));
61
+ LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", proto->drop));
62
+ LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", proto->chkerr));
63
+ LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", proto->lenerr));
64
+ LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", proto->memerr));
65
+ LWIP_PLATFORM_DIAG(("rterr: %"STAT_COUNTER_F"\n\t", proto->rterr));
66
+ LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", proto->proterr));
67
+ LWIP_PLATFORM_DIAG(("opterr: %"STAT_COUNTER_F"\n\t", proto->opterr));
68
+ LWIP_PLATFORM_DIAG(("err: %"STAT_COUNTER_F"\n\t", proto->err));
69
+ LWIP_PLATFORM_DIAG(("cachehit: %"STAT_COUNTER_F"\n", proto->cachehit));
70
+ }
71
+
72
+ #if IGMP_STATS
73
+ void
74
+ stats_display_igmp(struct stats_igmp *igmp)
75
+ {
76
+ LWIP_PLATFORM_DIAG(("\nIGMP\n\t"));
77
+ LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", igmp->lenerr));
78
+ LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", igmp->chkerr));
79
+ LWIP_PLATFORM_DIAG(("v1_rxed: %"STAT_COUNTER_F"\n\t", igmp->v1_rxed));
80
+ LWIP_PLATFORM_DIAG(("join_sent: %"STAT_COUNTER_F"\n\t", igmp->join_sent));
81
+ LWIP_PLATFORM_DIAG(("leave_sent: %"STAT_COUNTER_F"\n\t", igmp->leave_sent));
82
+ LWIP_PLATFORM_DIAG(("unicast_query: %"STAT_COUNTER_F"\n\t", igmp->unicast_query));
83
+ LWIP_PLATFORM_DIAG(("report_sent: %"STAT_COUNTER_F"\n\t", igmp->report_sent));
84
+ LWIP_PLATFORM_DIAG(("report_rxed: %"STAT_COUNTER_F"\n\t", igmp->report_rxed));
85
+ LWIP_PLATFORM_DIAG(("group_query_rxed: %"STAT_COUNTER_F"\n", igmp->group_query_rxed));
86
+ }
87
+ #endif /* IGMP_STATS */
88
+
89
+ #if MEM_STATS || MEMP_STATS
90
+ void
91
+ stats_display_mem(struct stats_mem *mem, char *name)
92
+ {
93
+ LWIP_PLATFORM_DIAG(("\nMEM %s\n\t", name));
94
+ LWIP_PLATFORM_DIAG(("avail: %"U32_F"\n\t", (u32_t)mem->avail));
95
+ LWIP_PLATFORM_DIAG(("used: %"U32_F"\n\t", (u32_t)mem->used));
96
+ LWIP_PLATFORM_DIAG(("max: %"U32_F"\n\t", (u32_t)mem->max));
97
+ LWIP_PLATFORM_DIAG(("err: %"U32_F"\n", (u32_t)mem->err));
98
+ }
99
+
100
+ #if MEMP_STATS
101
+ void
102
+ stats_display_memp(struct stats_mem *mem, int index)
103
+ {
104
+ char * memp_names[] = {
105
+ #define LWIP_MEMPOOL(name,num,size,desc) desc,
106
+ #include "lwip/memp_std.h"
107
+ };
108
+ if(index < MEMP_MAX) {
109
+ stats_display_mem(mem, memp_names[index]);
110
+ }
111
+ }
112
+ #endif /* MEMP_STATS */
113
+ #endif /* MEM_STATS || MEMP_STATS */
114
+
115
+ #if SYS_STATS
116
+ void
117
+ stats_display_sys(struct stats_sys *sys)
118
+ {
119
+ LWIP_PLATFORM_DIAG(("\nSYS\n\t"));
120
+ LWIP_PLATFORM_DIAG(("sem.used: %"U32_F"\n\t", (u32_t)sys->sem.used));
121
+ LWIP_PLATFORM_DIAG(("sem.max: %"U32_F"\n\t", (u32_t)sys->sem.max));
122
+ LWIP_PLATFORM_DIAG(("sem.err: %"U32_F"\n\t", (u32_t)sys->sem.err));
123
+ LWIP_PLATFORM_DIAG(("mbox.used: %"U32_F"\n\t", (u32_t)sys->mbox.used));
124
+ LWIP_PLATFORM_DIAG(("mbox.max: %"U32_F"\n\t", (u32_t)sys->mbox.max));
125
+ LWIP_PLATFORM_DIAG(("mbox.err: %"U32_F"\n\t", (u32_t)sys->mbox.err));
126
+ }
127
+ #endif /* SYS_STATS */
128
+
129
+ void
130
+ stats_display(void)
131
+ {
132
+ s16_t i;
133
+
134
+ LINK_STATS_DISPLAY();
135
+ ETHARP_STATS_DISPLAY();
136
+ IPFRAG_STATS_DISPLAY();
137
+ IP_STATS_DISPLAY();
138
+ IGMP_STATS_DISPLAY();
139
+ ICMP_STATS_DISPLAY();
140
+ UDP_STATS_DISPLAY();
141
+ TCP_STATS_DISPLAY();
142
+ MEM_STATS_DISPLAY();
143
+ for (i = 0; i < MEMP_MAX; i++) {
144
+ MEMP_STATS_DISPLAY(i);
145
+ }
146
+ SYS_STATS_DISPLAY();
147
+ }
148
+ #endif /* LWIP_STATS_DISPLAY */
149
+
150
+ #endif /* LWIP_STATS */
151
+
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp.c ADDED
@@ -0,0 +1,1463 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ * Transmission Control Protocol for IP
6
+ *
7
+ * This file contains common functions for the TCP implementation, such as functinos
8
+ * for manipulating the data structures and the TCP timer functions. TCP functions
9
+ * related to input and output is found in tcp_in.c and tcp_out.c respectively.
10
+ *
11
+ */
12
+
13
+ /*
14
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
15
+ * All rights reserved.
16
+ *
17
+ * Redistribution and use in source and binary forms, with or without modification,
18
+ * are permitted provided that the following conditions are met:
19
+ *
20
+ * 1. Redistributions of source code must retain the above copyright notice,
21
+ * this list of conditions and the following disclaimer.
22
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
23
+ * this list of conditions and the following disclaimer in the documentation
24
+ * and/or other materials provided with the distribution.
25
+ * 3. The name of the author may not be used to endorse or promote products
26
+ * derived from this software without specific prior written permission.
27
+ *
28
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
29
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
31
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
33
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
37
+ * OF SUCH DAMAGE.
38
+ *
39
+ * This file is part of the lwIP TCP/IP stack.
40
+ *
41
+ * Author: Adam Dunkels <adam@sics.se>
42
+ *
43
+ */
44
+
45
+ #include "lwip/opt.h"
46
+
47
+ #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
48
+
49
+ #include "lwip/def.h"
50
+ #include "lwip/mem.h"
51
+ #include "lwip/memp.h"
52
+ #include "lwip/snmp.h"
53
+ #include "lwip/tcp.h"
54
+ #include "lwip/debug.h"
55
+ #include "lwip/stats.h"
56
+
57
+ #include <string.h>
58
+
59
+ const char *tcp_state_str[] = {
60
+ "CLOSED",
61
+ "LISTEN",
62
+ "SYN_SENT",
63
+ "SYN_RCVD",
64
+ "ESTABLISHED",
65
+ "FIN_WAIT_1",
66
+ "FIN_WAIT_2",
67
+ "CLOSE_WAIT",
68
+ "CLOSING",
69
+ "LAST_ACK",
70
+ "TIME_WAIT"
71
+ };
72
+
73
+ /* Incremented every coarse grained timer shot (typically every 500 ms). */
74
+ u32_t tcp_ticks;
75
+ const u8_t tcp_backoff[13] =
76
+ { 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7};
77
+ /* Times per slowtmr hits */
78
+ const u8_t tcp_persist_backoff[7] = { 3, 6, 12, 24, 48, 96, 120 };
79
+
80
+ /* The TCP PCB lists. */
81
+
82
+ /** List of all TCP PCBs bound but not yet (connected || listening) */
83
+ struct tcp_pcb *tcp_bound_pcbs;
84
+ /** List of all TCP PCBs in LISTEN state */
85
+ union tcp_listen_pcbs_t tcp_listen_pcbs;
86
+ /** List of all TCP PCBs that are in a state in which
87
+ * they accept or send data. */
88
+ struct tcp_pcb *tcp_active_pcbs;
89
+ /** List of all TCP PCBs in TIME-WAIT state */
90
+ struct tcp_pcb *tcp_tw_pcbs;
91
+
92
+ struct tcp_pcb *tcp_tmp_pcb;
93
+
94
+ static u8_t tcp_timer;
95
+ static u16_t tcp_new_port(void);
96
+
97
+ /**
98
+ * Called periodically to dispatch TCP timers.
99
+ *
100
+ */
101
+ void
102
+ tcp_tmr(void)
103
+ {
104
+ /* Call tcp_fasttmr() every 250 ms */
105
+ tcp_fasttmr();
106
+
107
+ if (++tcp_timer & 1) {
108
+ /* Call tcp_tmr() every 500 ms, i.e., every other timer
109
+ tcp_tmr() is called. */
110
+ tcp_slowtmr();
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Closes the connection held by the PCB.
116
+ *
117
+ * Listening pcbs are freed and may not be referenced any more.
118
+ * Connection pcbs are freed if not yet connected and may not be referenced
119
+ * any more. If a connection is established (at least SYN received or in
120
+ * a closing state), the connection is closed, and put in a closing state.
121
+ * The pcb is then automatically freed in tcp_slowtmr(). It is therefore
122
+ * unsafe to reference it.
123
+ *
124
+ * @param pcb the tcp_pcb to close
125
+ * @return ERR_OK if connection has been closed
126
+ * another err_t if closing failed and pcb is not freed
127
+ */
128
+ err_t
129
+ tcp_close(struct tcp_pcb *pcb)
130
+ {
131
+ err_t err;
132
+
133
+ #if TCP_DEBUG
134
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_close: closing in "));
135
+ tcp_debug_print_state(pcb->state);
136
+ #endif /* TCP_DEBUG */
137
+
138
+ switch (pcb->state) {
139
+ case CLOSED:
140
+ /* Closing a pcb in the CLOSED state might seem erroneous,
141
+ * however, it is in this state once allocated and as yet unused
142
+ * and the user needs some way to free it should the need arise.
143
+ * Calling tcp_close() with a pcb that has already been closed, (i.e. twice)
144
+ * or for a pcb that has been used and then entered the CLOSED state
145
+ * is erroneous, but this should never happen as the pcb has in those cases
146
+ * been freed, and so any remaining handles are bogus. */
147
+ err = ERR_OK;
148
+ TCP_RMV(&tcp_bound_pcbs, pcb);
149
+ memp_free(MEMP_TCP_PCB, pcb);
150
+ pcb = NULL;
151
+ break;
152
+ case LISTEN:
153
+ err = ERR_OK;
154
+ tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs.pcbs, pcb);
155
+ memp_free(MEMP_TCP_PCB_LISTEN, pcb);
156
+ pcb = NULL;
157
+ break;
158
+ case SYN_SENT:
159
+ err = ERR_OK;
160
+ tcp_pcb_remove(&tcp_active_pcbs, pcb);
161
+ memp_free(MEMP_TCP_PCB, pcb);
162
+ pcb = NULL;
163
+ snmp_inc_tcpattemptfails();
164
+ break;
165
+ case SYN_RCVD:
166
+ err = tcp_send_ctrl(pcb, TCP_FIN);
167
+ if (err == ERR_OK) {
168
+ snmp_inc_tcpattemptfails();
169
+ pcb->state = FIN_WAIT_1;
170
+ }
171
+ break;
172
+ case ESTABLISHED:
173
+ err = tcp_send_ctrl(pcb, TCP_FIN);
174
+ if (err == ERR_OK) {
175
+ snmp_inc_tcpestabresets();
176
+ pcb->state = FIN_WAIT_1;
177
+ }
178
+ break;
179
+ case CLOSE_WAIT:
180
+ err = tcp_send_ctrl(pcb, TCP_FIN);
181
+ if (err == ERR_OK) {
182
+ snmp_inc_tcpestabresets();
183
+ pcb->state = LAST_ACK;
184
+ }
185
+ break;
186
+ default:
187
+ /* Has already been closed, do nothing. */
188
+ err = ERR_OK;
189
+ pcb = NULL;
190
+ break;
191
+ }
192
+
193
+ if (pcb != NULL && err == ERR_OK) {
194
+ /* To ensure all data has been sent when tcp_close returns, we have
195
+ to make sure tcp_output doesn't fail.
196
+ Since we don't really have to ensure all data has been sent when tcp_close
197
+ returns (unsent data is sent from tcp timer functions, also), we don't care
198
+ for the return value of tcp_output for now. */
199
+ /* @todo: When implementing SO_LINGER, this must be changed somehow:
200
+ If SOF_LINGER is set, the data should be sent when tcp_close returns. */
201
+ tcp_output(pcb);
202
+ }
203
+ return err;
204
+ }
205
+
206
+ /**
207
+ * Abandons a connection and optionally sends a RST to the remote
208
+ * host. Deletes the local protocol control block. This is done when
209
+ * a connection is killed because of shortage of memory.
210
+ *
211
+ * @param pcb the tcp_pcb to abort
212
+ * @param reset boolean to indicate whether a reset should be sent
213
+ */
214
+ void
215
+ tcp_abandon(struct tcp_pcb *pcb, int reset)
216
+ {
217
+ u32_t seqno, ackno;
218
+ u16_t remote_port, local_port;
219
+ struct ip_addr remote_ip, local_ip;
220
+ #if LWIP_CALLBACK_API
221
+ void (* errf)(void *arg, err_t err);
222
+ #endif /* LWIP_CALLBACK_API */
223
+ void *errf_arg;
224
+
225
+
226
+ /* Figure out on which TCP PCB list we are, and remove us. If we
227
+ are in an active state, call the receive function associated with
228
+ the PCB with a NULL argument, and send an RST to the remote end. */
229
+ if (pcb->state == TIME_WAIT) {
230
+ tcp_pcb_remove(&tcp_tw_pcbs, pcb);
231
+ memp_free(MEMP_TCP_PCB, pcb);
232
+ } else {
233
+ seqno = pcb->snd_nxt;
234
+ ackno = pcb->rcv_nxt;
235
+ ip_addr_set(&local_ip, &(pcb->local_ip));
236
+ ip_addr_set(&remote_ip, &(pcb->remote_ip));
237
+ local_port = pcb->local_port;
238
+ remote_port = pcb->remote_port;
239
+ #if LWIP_CALLBACK_API
240
+ errf = pcb->errf;
241
+ #endif /* LWIP_CALLBACK_API */
242
+ errf_arg = pcb->callback_arg;
243
+ tcp_pcb_remove(&tcp_active_pcbs, pcb);
244
+ if (pcb->unacked != NULL) {
245
+ tcp_segs_free(pcb->unacked);
246
+ }
247
+ if (pcb->unsent != NULL) {
248
+ tcp_segs_free(pcb->unsent);
249
+ }
250
+ #if TCP_QUEUE_OOSEQ
251
+ if (pcb->ooseq != NULL) {
252
+ tcp_segs_free(pcb->ooseq);
253
+ }
254
+ #endif /* TCP_QUEUE_OOSEQ */
255
+ memp_free(MEMP_TCP_PCB, pcb);
256
+ TCP_EVENT_ERR(errf, errf_arg, ERR_ABRT);
257
+ if (reset) {
258
+ LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_abandon: sending RST\n"));
259
+ tcp_rst(seqno, ackno, &local_ip, &remote_ip, local_port, remote_port);
260
+ }
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Binds the connection to a local portnumber and IP address. If the
266
+ * IP address is not given (i.e., ipaddr == NULL), the IP address of
267
+ * the outgoing network interface is used instead.
268
+ *
269
+ * @param pcb the tcp_pcb to bind (no check is done whether this pcb is
270
+ * already bound!)
271
+ * @param ipaddr the local ip address to bind to (use IP_ADDR_ANY to bind
272
+ * to any local address
273
+ * @param port the local port to bind to
274
+ * @return ERR_USE if the port is already in use
275
+ * ERR_OK if bound
276
+ */
277
+ err_t
278
+ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
279
+ {
280
+ struct tcp_pcb *cpcb;
281
+
282
+ LWIP_ERROR("tcp_bind: can only bind in state CLOSED", pcb->state == CLOSED, return ERR_ISCONN);
283
+
284
+ if (port == 0) {
285
+ port = tcp_new_port();
286
+ }
287
+ /* Check if the address already is in use. */
288
+ /* Check the listen pcbs. */
289
+ for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs;
290
+ cpcb != NULL; cpcb = cpcb->next) {
291
+ if (cpcb->local_port == port) {
292
+ if (ip_addr_isany(&(cpcb->local_ip)) ||
293
+ ip_addr_isany(ipaddr) ||
294
+ ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
295
+ return ERR_USE;
296
+ }
297
+ }
298
+ }
299
+ /* Check the connected pcbs. */
300
+ for(cpcb = tcp_active_pcbs;
301
+ cpcb != NULL; cpcb = cpcb->next) {
302
+ if (cpcb->local_port == port) {
303
+ if (ip_addr_isany(&(cpcb->local_ip)) ||
304
+ ip_addr_isany(ipaddr) ||
305
+ ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
306
+ return ERR_USE;
307
+ }
308
+ }
309
+ }
310
+ /* Check the bound, not yet connected pcbs. */
311
+ for(cpcb = tcp_bound_pcbs; cpcb != NULL; cpcb = cpcb->next) {
312
+ if (cpcb->local_port == port) {
313
+ if (ip_addr_isany(&(cpcb->local_ip)) ||
314
+ ip_addr_isany(ipaddr) ||
315
+ ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
316
+ return ERR_USE;
317
+ }
318
+ }
319
+ }
320
+ /* @todo: until SO_REUSEADDR is implemented (see task #6995 on savannah),
321
+ * we have to check the pcbs in TIME-WAIT state, also: */
322
+ for(cpcb = tcp_tw_pcbs; cpcb != NULL; cpcb = cpcb->next) {
323
+ if (cpcb->local_port == port) {
324
+ if (ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
325
+ return ERR_USE;
326
+ }
327
+ }
328
+ }
329
+
330
+ if (!ip_addr_isany(ipaddr)) {
331
+ pcb->local_ip = *ipaddr;
332
+ }
333
+ pcb->local_port = port;
334
+ TCP_REG(&tcp_bound_pcbs, pcb);
335
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %"U16_F"\n", port));
336
+ return ERR_OK;
337
+ }
338
+ #if LWIP_CALLBACK_API
339
+ /**
340
+ * Default accept callback if no accept callback is specified by the user.
341
+ */
342
+ static err_t
343
+ tcp_accept_null(void *arg, struct tcp_pcb *pcb, err_t err)
344
+ {
345
+ LWIP_UNUSED_ARG(arg);
346
+ LWIP_UNUSED_ARG(pcb);
347
+ LWIP_UNUSED_ARG(err);
348
+
349
+ return ERR_ABRT;
350
+ }
351
+ #endif /* LWIP_CALLBACK_API */
352
+
353
+ /**
354
+ * Set the state of the connection to be LISTEN, which means that it
355
+ * is able to accept incoming connections. The protocol control block
356
+ * is reallocated in order to consume less memory. Setting the
357
+ * connection to LISTEN is an irreversible process.
358
+ *
359
+ * @param pcb the original tcp_pcb
360
+ * @param backlog the incoming connections queue limit
361
+ * @return tcp_pcb used for listening, consumes less memory.
362
+ *
363
+ * @note The original tcp_pcb is freed. This function therefore has to be
364
+ * called like this:
365
+ * tpcb = tcp_listen(tpcb);
366
+ */
367
+ struct tcp_pcb *
368
+ tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
369
+ {
370
+ struct tcp_pcb_listen *lpcb;
371
+
372
+ LWIP_UNUSED_ARG(backlog);
373
+ LWIP_ERROR("tcp_listen: pcb already connected", pcb->state == CLOSED, return NULL);
374
+
375
+ /* already listening? */
376
+ if (pcb->state == LISTEN) {
377
+ return pcb;
378
+ }
379
+ lpcb = memp_malloc(MEMP_TCP_PCB_LISTEN);
380
+ if (lpcb == NULL) {
381
+ return NULL;
382
+ }
383
+ lpcb->callback_arg = pcb->callback_arg;
384
+ lpcb->local_port = pcb->local_port;
385
+ lpcb->state = LISTEN;
386
+ lpcb->so_options = pcb->so_options;
387
+ lpcb->so_options |= SOF_ACCEPTCONN;
388
+ lpcb->ttl = pcb->ttl;
389
+ lpcb->tos = pcb->tos;
390
+ ip_addr_set(&lpcb->local_ip, &pcb->local_ip);
391
+ TCP_RMV(&tcp_bound_pcbs, pcb);
392
+ memp_free(MEMP_TCP_PCB, pcb);
393
+ #if LWIP_CALLBACK_API
394
+ lpcb->accept = tcp_accept_null;
395
+ #endif /* LWIP_CALLBACK_API */
396
+ #if TCP_LISTEN_BACKLOG
397
+ lpcb->accepts_pending = 0;
398
+ lpcb->backlog = (backlog ? backlog : 1);
399
+ #endif /* TCP_LISTEN_BACKLOG */
400
+ TCP_REG(&tcp_listen_pcbs.listen_pcbs, lpcb);
401
+ return (struct tcp_pcb *)lpcb;
402
+ }
403
+
404
+ /**
405
+ * Update the state that tracks the available window space to advertise.
406
+ *
407
+ * Returns how much extra window would be advertised if we sent an
408
+ * update now.
409
+ */
410
+ u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)
411
+ {
412
+ u32_t new_right_edge = pcb->rcv_nxt + pcb->rcv_wnd;
413
+
414
+ if (TCP_SEQ_GEQ(new_right_edge, pcb->rcv_ann_right_edge + LWIP_MIN((TCP_WND / 2), pcb->mss))) {
415
+ /* we can advertise more window */
416
+ pcb->rcv_ann_wnd = pcb->rcv_wnd;
417
+ return new_right_edge - pcb->rcv_ann_right_edge;
418
+ } else {
419
+ if (TCP_SEQ_GT(pcb->rcv_nxt, pcb->rcv_ann_right_edge)) {
420
+ /* Can happen due to other end sending out of advertised window,
421
+ * but within actual available (but not yet advertised) window */
422
+ pcb->rcv_ann_wnd = 0;
423
+ } else {
424
+ /* keep the right edge of window constant */
425
+ pcb->rcv_ann_wnd = pcb->rcv_ann_right_edge - pcb->rcv_nxt;
426
+ }
427
+ return 0;
428
+ }
429
+ }
430
+
431
+ /**
432
+ * This function should be called by the application when it has
433
+ * processed the data. The purpose is to advertise a larger window
434
+ * when the data has been processed.
435
+ *
436
+ * @param pcb the tcp_pcb for which data is read
437
+ * @param len the amount of bytes that have been read by the application
438
+ */
439
+ void
440
+ tcp_recved(struct tcp_pcb *pcb, u16_t len)
441
+ {
442
+ int wnd_inflation;
443
+
444
+ LWIP_ASSERT("tcp_recved: len would wrap rcv_wnd\n",
445
+ len <= 0xffff - pcb->rcv_wnd );
446
+
447
+ pcb->rcv_wnd += len;
448
+ if (pcb->rcv_wnd > TCP_WND)
449
+ pcb->rcv_wnd = TCP_WND;
450
+
451
+ wnd_inflation = tcp_update_rcv_ann_wnd(pcb);
452
+
453
+ /* If the change in the right edge of window is significant (default
454
+ * watermark is TCP_WND/2), then send an explicit update now.
455
+ * Otherwise wait for a packet to be sent in the normal course of
456
+ * events (or more window to be available later) */
457
+ if (wnd_inflation >= TCP_WND_UPDATE_THRESHOLD)
458
+ tcp_ack_now(pcb);
459
+
460
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_recved: recveived %"U16_F" bytes, wnd %"U16_F" (%"U16_F").\n",
461
+ len, pcb->rcv_wnd, TCP_WND - pcb->rcv_wnd));
462
+ }
463
+
464
+ /**
465
+ * A nastly hack featuring 'goto' statements that allocates a
466
+ * new TCP local port.
467
+ *
468
+ * @return a new (free) local TCP port number
469
+ */
470
+ static u16_t
471
+ tcp_new_port(void)
472
+ {
473
+ struct tcp_pcb *pcb;
474
+ #ifndef TCP_LOCAL_PORT_RANGE_START
475
+ #define TCP_LOCAL_PORT_RANGE_START 4096
476
+ #define TCP_LOCAL_PORT_RANGE_END 0x7fff
477
+ #endif
478
+ static u16_t port = TCP_LOCAL_PORT_RANGE_START;
479
+
480
+ again:
481
+ if (++port > TCP_LOCAL_PORT_RANGE_END) {
482
+ port = TCP_LOCAL_PORT_RANGE_START;
483
+ }
484
+
485
+ for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
486
+ if (pcb->local_port == port) {
487
+ goto again;
488
+ }
489
+ }
490
+ for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
491
+ if (pcb->local_port == port) {
492
+ goto again;
493
+ }
494
+ }
495
+ for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) {
496
+ if (pcb->local_port == port) {
497
+ goto again;
498
+ }
499
+ }
500
+ return port;
501
+ }
502
+
503
+ /**
504
+ * Connects to another host. The function given as the "connected"
505
+ * argument will be called when the connection has been established.
506
+ *
507
+ * @param pcb the tcp_pcb used to establish the connection
508
+ * @param ipaddr the remote ip address to connect to
509
+ * @param port the remote tcp port to connect to
510
+ * @param connected callback function to call when connected (or on error)
511
+ * @return ERR_VAL if invalid arguments are given
512
+ * ERR_OK if connect request has been sent
513
+ * other err_t values if connect request couldn't be sent
514
+ */
515
+ err_t
516
+ tcp_connect(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port,
517
+ err_t (* connected)(void *arg, struct tcp_pcb *tpcb, err_t err))
518
+ {
519
+ err_t ret;
520
+ u32_t iss;
521
+
522
+ LWIP_ERROR("tcp_connect: can only connected from state CLOSED", pcb->state == CLOSED, return ERR_ISCONN);
523
+
524
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_connect to port %"U16_F"\n", port));
525
+ if (ipaddr != NULL) {
526
+ pcb->remote_ip = *ipaddr;
527
+ } else {
528
+ return ERR_VAL;
529
+ }
530
+ pcb->remote_port = port;
531
+ if (pcb->local_port == 0) {
532
+ pcb->local_port = tcp_new_port();
533
+ }
534
+ iss = tcp_next_iss();
535
+ pcb->rcv_nxt = 0;
536
+ pcb->snd_nxt = iss;
537
+ pcb->lastack = iss - 1;
538
+ pcb->snd_lbb = iss - 1;
539
+ pcb->rcv_wnd = TCP_WND;
540
+ pcb->rcv_ann_wnd = TCP_WND;
541
+ pcb->rcv_ann_right_edge = pcb->rcv_nxt;
542
+ pcb->snd_wnd = TCP_WND;
543
+ /* As initial send MSS, we use TCP_MSS but limit it to 536.
544
+ The send MSS is updated when an MSS option is received. */
545
+ pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
546
+ #if TCP_CALCULATE_EFF_SEND_MSS
547
+ pcb->mss = tcp_eff_send_mss(pcb->mss, ipaddr);
548
+ #endif /* TCP_CALCULATE_EFF_SEND_MSS */
549
+ pcb->cwnd = 1;
550
+ pcb->ssthresh = pcb->mss * 10;
551
+ pcb->state = SYN_SENT;
552
+ #if LWIP_CALLBACK_API
553
+ pcb->connected = connected;
554
+ #endif /* LWIP_CALLBACK_API */
555
+ TCP_RMV(&tcp_bound_pcbs, pcb);
556
+ TCP_REG(&tcp_active_pcbs, pcb);
557
+
558
+ snmp_inc_tcpactiveopens();
559
+
560
+ ret = tcp_enqueue(pcb, NULL, 0, TCP_SYN, 0, TF_SEG_OPTS_MSS
561
+ #if LWIP_TCP_TIMESTAMPS
562
+ | TF_SEG_OPTS_TS
563
+ #endif
564
+ );
565
+ if (ret == ERR_OK) {
566
+ tcp_output(pcb);
567
+ }
568
+ return ret;
569
+ }
570
+
571
+ /**
572
+ * Called every 500 ms and implements the retransmission timer and the timer that
573
+ * removes PCBs that have been in TIME-WAIT for enough time. It also increments
574
+ * various timers such as the inactivity timer in each PCB.
575
+ *
576
+ * Automatically called from tcp_tmr().
577
+ */
578
+ void
579
+ tcp_slowtmr(void)
580
+ {
581
+ struct tcp_pcb *pcb, *pcb2, *prev;
582
+ u16_t eff_wnd;
583
+ u8_t pcb_remove; /* flag if a PCB should be removed */
584
+ u8_t pcb_reset; /* flag if a RST should be sent when removing */
585
+ err_t err;
586
+
587
+ err = ERR_OK;
588
+
589
+ ++tcp_ticks;
590
+
591
+ /* Steps through all of the active PCBs. */
592
+ prev = NULL;
593
+ pcb = tcp_active_pcbs;
594
+ if (pcb == NULL) {
595
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: no active pcbs\n"));
596
+ }
597
+ while (pcb != NULL) {
598
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: processing active pcb\n"));
599
+ LWIP_ASSERT("tcp_slowtmr: active pcb->state != CLOSED\n", pcb->state != CLOSED);
600
+ LWIP_ASSERT("tcp_slowtmr: active pcb->state != LISTEN\n", pcb->state != LISTEN);
601
+ LWIP_ASSERT("tcp_slowtmr: active pcb->state != TIME-WAIT\n", pcb->state != TIME_WAIT);
602
+
603
+ pcb_remove = 0;
604
+ pcb_reset = 0;
605
+
606
+ if (pcb->state == SYN_SENT && pcb->nrtx == TCP_SYNMAXRTX) {
607
+ ++pcb_remove;
608
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max SYN retries reached\n"));
609
+ }
610
+ else if (pcb->nrtx == TCP_MAXRTX) {
611
+ ++pcb_remove;
612
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max DATA retries reached\n"));
613
+ } else {
614
+ if (pcb->persist_backoff > 0) {
615
+ /* If snd_wnd is zero, use persist timer to send 1 byte probes
616
+ * instead of using the standard retransmission mechanism. */
617
+ pcb->persist_cnt++;
618
+ if (pcb->persist_cnt >= tcp_persist_backoff[pcb->persist_backoff-1]) {
619
+ pcb->persist_cnt = 0;
620
+ if (pcb->persist_backoff < sizeof(tcp_persist_backoff)) {
621
+ pcb->persist_backoff++;
622
+ }
623
+ tcp_zero_window_probe(pcb);
624
+ }
625
+ } else {
626
+ /* Increase the retransmission timer if it is running */
627
+ if(pcb->rtime >= 0)
628
+ ++pcb->rtime;
629
+
630
+ if (pcb->unacked != NULL && pcb->rtime >= pcb->rto) {
631
+ /* Time for a retransmission. */
632
+ LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_slowtmr: rtime %"S16_F
633
+ " pcb->rto %"S16_F"\n",
634
+ pcb->rtime, pcb->rto));
635
+
636
+ /* Double retransmission time-out unless we are trying to
637
+ * connect to somebody (i.e., we are in SYN_SENT). */
638
+ if (pcb->state != SYN_SENT) {
639
+ pcb->rto = ((pcb->sa >> 3) + pcb->sv) << tcp_backoff[pcb->nrtx];
640
+ }
641
+
642
+ /* Reset the retransmission timer. */
643
+ pcb->rtime = 0;
644
+
645
+ /* Reduce congestion window and ssthresh. */
646
+ eff_wnd = LWIP_MIN(pcb->cwnd, pcb->snd_wnd);
647
+ pcb->ssthresh = eff_wnd >> 1;
648
+ if (pcb->ssthresh < pcb->mss) {
649
+ pcb->ssthresh = pcb->mss * 2;
650
+ }
651
+ pcb->cwnd = pcb->mss;
652
+ LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: cwnd %"U16_F
653
+ " ssthresh %"U16_F"\n",
654
+ pcb->cwnd, pcb->ssthresh));
655
+
656
+ /* The following needs to be called AFTER cwnd is set to one
657
+ mss - STJ */
658
+ tcp_rexmit_rto(pcb);
659
+ }
660
+ }
661
+ }
662
+ /* Check if this PCB has stayed too long in FIN-WAIT-2 */
663
+ if (pcb->state == FIN_WAIT_2) {
664
+ if ((u32_t)(tcp_ticks - pcb->tmr) >
665
+ TCP_FIN_WAIT_TIMEOUT / TCP_SLOW_INTERVAL) {
666
+ ++pcb_remove;
667
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in FIN-WAIT-2\n"));
668
+ }
669
+ }
670
+
671
+ /* Check if KEEPALIVE should be sent */
672
+ if((pcb->so_options & SOF_KEEPALIVE) &&
673
+ ((pcb->state == ESTABLISHED) ||
674
+ (pcb->state == CLOSE_WAIT))) {
675
+ #if LWIP_TCP_KEEPALIVE
676
+ if((u32_t)(tcp_ticks - pcb->tmr) >
677
+ (pcb->keep_idle + (pcb->keep_cnt*pcb->keep_intvl))
678
+ / TCP_SLOW_INTERVAL)
679
+ #else
680
+ if((u32_t)(tcp_ticks - pcb->tmr) >
681
+ (pcb->keep_idle + TCP_MAXIDLE) / TCP_SLOW_INTERVAL)
682
+ #endif /* LWIP_TCP_KEEPALIVE */
683
+ {
684
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to %"U16_F".%"U16_F".%"U16_F".%"U16_F".\n",
685
+ ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
686
+ ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
687
+
688
+ ++pcb_remove;
689
+ ++pcb_reset;
690
+ }
691
+ #if LWIP_TCP_KEEPALIVE
692
+ else if((u32_t)(tcp_ticks - pcb->tmr) >
693
+ (pcb->keep_idle + pcb->keep_cnt_sent * pcb->keep_intvl)
694
+ / TCP_SLOW_INTERVAL)
695
+ #else
696
+ else if((u32_t)(tcp_ticks - pcb->tmr) >
697
+ (pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEPINTVL_DEFAULT)
698
+ / TCP_SLOW_INTERVAL)
699
+ #endif /* LWIP_TCP_KEEPALIVE */
700
+ {
701
+ tcp_keepalive(pcb);
702
+ pcb->keep_cnt_sent++;
703
+ }
704
+ }
705
+
706
+ /* If this PCB has queued out of sequence data, but has been
707
+ inactive for too long, will drop the data (it will eventually
708
+ be retransmitted). */
709
+ #if TCP_QUEUE_OOSEQ
710
+ if (pcb->ooseq != NULL &&
711
+ (u32_t)tcp_ticks - pcb->tmr >= pcb->rto * TCP_OOSEQ_TIMEOUT) {
712
+ tcp_segs_free(pcb->ooseq);
713
+ pcb->ooseq = NULL;
714
+ LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: dropping OOSEQ queued data\n"));
715
+ }
716
+ #endif /* TCP_QUEUE_OOSEQ */
717
+
718
+ /* Check if this PCB has stayed too long in SYN-RCVD */
719
+ if (pcb->state == SYN_RCVD) {
720
+ if ((u32_t)(tcp_ticks - pcb->tmr) >
721
+ TCP_SYN_RCVD_TIMEOUT / TCP_SLOW_INTERVAL) {
722
+ ++pcb_remove;
723
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in SYN-RCVD\n"));
724
+ }
725
+ }
726
+
727
+ /* Check if this PCB has stayed too long in LAST-ACK */
728
+ if (pcb->state == LAST_ACK) {
729
+ if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {
730
+ ++pcb_remove;
731
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in LAST-ACK\n"));
732
+ }
733
+ }
734
+
735
+ /* If the PCB should be removed, do it. */
736
+ if (pcb_remove) {
737
+ tcp_pcb_purge(pcb);
738
+ /* Remove PCB from tcp_active_pcbs list. */
739
+ if (prev != NULL) {
740
+ LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_active_pcbs", pcb != tcp_active_pcbs);
741
+ prev->next = pcb->next;
742
+ } else {
743
+ /* This PCB was the first. */
744
+ LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_active_pcbs", tcp_active_pcbs == pcb);
745
+ tcp_active_pcbs = pcb->next;
746
+ }
747
+
748
+ TCP_EVENT_ERR(pcb->errf, pcb->callback_arg, ERR_ABRT);
749
+ if (pcb_reset) {
750
+ tcp_rst(pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip,
751
+ pcb->local_port, pcb->remote_port);
752
+ }
753
+
754
+ pcb2 = pcb->next;
755
+ memp_free(MEMP_TCP_PCB, pcb);
756
+ pcb = pcb2;
757
+ } else {
758
+
759
+ /* We check if we should poll the connection. */
760
+ ++pcb->polltmr;
761
+ if (pcb->polltmr >= pcb->pollinterval) {
762
+ pcb->polltmr = 0;
763
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: polling application\n"));
764
+ TCP_EVENT_POLL(pcb, err);
765
+ if (err == ERR_OK) {
766
+ tcp_output(pcb);
767
+ }
768
+ }
769
+
770
+ prev = pcb;
771
+ pcb = pcb->next;
772
+ }
773
+ }
774
+
775
+
776
+ /* Steps through all of the TIME-WAIT PCBs. */
777
+ prev = NULL;
778
+ pcb = tcp_tw_pcbs;
779
+ while (pcb != NULL) {
780
+ LWIP_ASSERT("tcp_slowtmr: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
781
+ pcb_remove = 0;
782
+
783
+ /* Check if this PCB has stayed long enough in TIME-WAIT */
784
+ if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {
785
+ ++pcb_remove;
786
+ }
787
+
788
+
789
+
790
+ /* If the PCB should be removed, do it. */
791
+ if (pcb_remove) {
792
+ tcp_pcb_purge(pcb);
793
+ /* Remove PCB from tcp_tw_pcbs list. */
794
+ if (prev != NULL) {
795
+ LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_tw_pcbs", pcb != tcp_tw_pcbs);
796
+ prev->next = pcb->next;
797
+ } else {
798
+ /* This PCB was the first. */
799
+ LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_tw_pcbs", tcp_tw_pcbs == pcb);
800
+ tcp_tw_pcbs = pcb->next;
801
+ }
802
+ pcb2 = pcb->next;
803
+ memp_free(MEMP_TCP_PCB, pcb);
804
+ pcb = pcb2;
805
+ } else {
806
+ prev = pcb;
807
+ pcb = pcb->next;
808
+ }
809
+ }
810
+ }
811
+
812
+ /**
813
+ * Is called every TCP_FAST_INTERVAL (250 ms) and process data previously
814
+ * "refused" by upper layer (application) and sends delayed ACKs.
815
+ *
816
+ * Automatically called from tcp_tmr().
817
+ */
818
+ void
819
+ tcp_fasttmr(void)
820
+ {
821
+ struct tcp_pcb *pcb;
822
+
823
+ for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
824
+ /* If there is data which was previously "refused" by upper layer */
825
+ if (pcb->refused_data != NULL) {
826
+ /* Notify again application with data previously received. */
827
+ err_t err;
828
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_fasttmr: notify kept packet\n"));
829
+ TCP_EVENT_RECV(pcb, pcb->refused_data, ERR_OK, err);
830
+ if (err == ERR_OK) {
831
+ pcb->refused_data = NULL;
832
+ }
833
+ }
834
+
835
+ /* send delayed ACKs */
836
+ if (pcb->flags & TF_ACK_DELAY) {
837
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_fasttmr: delayed ACK\n"));
838
+ tcp_ack_now(pcb);
839
+ pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
840
+ }
841
+ }
842
+ }
843
+
844
+ /**
845
+ * Deallocates a list of TCP segments (tcp_seg structures).
846
+ *
847
+ * @param seg tcp_seg list of TCP segments to free
848
+ * @return the number of pbufs that were deallocated
849
+ */
850
+ u8_t
851
+ tcp_segs_free(struct tcp_seg *seg)
852
+ {
853
+ u8_t count = 0;
854
+ struct tcp_seg *next;
855
+ while (seg != NULL) {
856
+ next = seg->next;
857
+ count += tcp_seg_free(seg);
858
+ seg = next;
859
+ }
860
+ return count;
861
+ }
862
+
863
+ /**
864
+ * Frees a TCP segment (tcp_seg structure).
865
+ *
866
+ * @param seg single tcp_seg to free
867
+ * @return the number of pbufs that were deallocated
868
+ */
869
+ u8_t
870
+ tcp_seg_free(struct tcp_seg *seg)
871
+ {
872
+ u8_t count = 0;
873
+
874
+ if (seg != NULL) {
875
+ if (seg->p != NULL) {
876
+ count = pbuf_free(seg->p);
877
+ #if TCP_DEBUG
878
+ seg->p = NULL;
879
+ #endif /* TCP_DEBUG */
880
+ }
881
+ memp_free(MEMP_TCP_SEG, seg);
882
+ }
883
+ return count;
884
+ }
885
+
886
+ /**
887
+ * Sets the priority of a connection.
888
+ *
889
+ * @param pcb the tcp_pcb to manipulate
890
+ * @param prio new priority
891
+ */
892
+ void
893
+ tcp_setprio(struct tcp_pcb *pcb, u8_t prio)
894
+ {
895
+ pcb->prio = prio;
896
+ }
897
+ #if TCP_QUEUE_OOSEQ
898
+
899
+ /**
900
+ * Returns a copy of the given TCP segment.
901
+ * The pbuf and data are not copied, only the pointers
902
+ *
903
+ * @param seg the old tcp_seg
904
+ * @return a copy of seg
905
+ */
906
+ struct tcp_seg *
907
+ tcp_seg_copy(struct tcp_seg *seg)
908
+ {
909
+ struct tcp_seg *cseg;
910
+
911
+ cseg = memp_malloc(MEMP_TCP_SEG);
912
+ if (cseg == NULL) {
913
+ return NULL;
914
+ }
915
+ SMEMCPY((u8_t *)cseg, (const u8_t *)seg, sizeof(struct tcp_seg));
916
+ pbuf_ref(cseg->p);
917
+ return cseg;
918
+ }
919
+ #endif
920
+
921
+ #if LWIP_CALLBACK_API
922
+ /**
923
+ * Default receive callback that is called if the user didn't register
924
+ * a recv callback for the pcb.
925
+ */
926
+ err_t
927
+ tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
928
+ {
929
+ LWIP_UNUSED_ARG(arg);
930
+ if (p != NULL) {
931
+ tcp_recved(pcb, p->tot_len);
932
+ pbuf_free(p);
933
+ } else if (err == ERR_OK) {
934
+ return tcp_close(pcb);
935
+ }
936
+ return ERR_OK;
937
+ }
938
+ #endif /* LWIP_CALLBACK_API */
939
+
940
+ /**
941
+ * Kills the oldest active connection that has lower priority than prio.
942
+ *
943
+ * @param prio minimum priority
944
+ */
945
+ static void
946
+ tcp_kill_prio(u8_t prio)
947
+ {
948
+ struct tcp_pcb *pcb, *inactive;
949
+ u32_t inactivity;
950
+ u8_t mprio;
951
+
952
+
953
+ mprio = TCP_PRIO_MAX;
954
+
955
+ /* We kill the oldest active connection that has lower priority than prio. */
956
+ inactivity = 0;
957
+ inactive = NULL;
958
+ for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
959
+ if (pcb->prio <= prio &&
960
+ pcb->prio <= mprio &&
961
+ (u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
962
+ inactivity = tcp_ticks - pcb->tmr;
963
+ inactive = pcb;
964
+ mprio = pcb->prio;
965
+ }
966
+ }
967
+ if (inactive != NULL) {
968
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_prio: killing oldest PCB %p (%"S32_F")\n",
969
+ (void *)inactive, inactivity));
970
+ tcp_abort(inactive);
971
+ }
972
+ }
973
+
974
+ /**
975
+ * Kills the oldest connection that is in TIME_WAIT state.
976
+ * Called from tcp_alloc() if no more connections are available.
977
+ */
978
+ static void
979
+ tcp_kill_timewait(void)
980
+ {
981
+ struct tcp_pcb *pcb, *inactive;
982
+ u32_t inactivity;
983
+
984
+ inactivity = 0;
985
+ inactive = NULL;
986
+ /* Go through the list of TIME_WAIT pcbs and get the oldest pcb. */
987
+ for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
988
+ if ((u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
989
+ inactivity = tcp_ticks - pcb->tmr;
990
+ inactive = pcb;
991
+ }
992
+ }
993
+ if (inactive != NULL) {
994
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_timewait: killing oldest TIME-WAIT PCB %p (%"S32_F")\n",
995
+ (void *)inactive, inactivity));
996
+ tcp_abort(inactive);
997
+ }
998
+ }
999
+
1000
+ /**
1001
+ * Allocate a new tcp_pcb structure.
1002
+ *
1003
+ * @param prio priority for the new pcb
1004
+ * @return a new tcp_pcb that initially is in state CLOSED
1005
+ */
1006
+ struct tcp_pcb *
1007
+ tcp_alloc(u8_t prio)
1008
+ {
1009
+ struct tcp_pcb *pcb;
1010
+ u32_t iss;
1011
+
1012
+ pcb = memp_malloc(MEMP_TCP_PCB);
1013
+ if (pcb == NULL) {
1014
+ /* Try killing oldest connection in TIME-WAIT. */
1015
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest TIME-WAIT connection\n"));
1016
+ tcp_kill_timewait();
1017
+ /* Try to allocate a tcp_pcb again. */
1018
+ pcb = memp_malloc(MEMP_TCP_PCB);
1019
+ if (pcb == NULL) {
1020
+ /* Try killing active connections with lower priority than the new one. */
1021
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing connection with prio lower than %d\n", prio));
1022
+ tcp_kill_prio(prio);
1023
+ /* Try to allocate a tcp_pcb again. */
1024
+ pcb = memp_malloc(MEMP_TCP_PCB);
1025
+ if (pcb != NULL) {
1026
+ /* adjust err stats: memp_malloc failed twice before */
1027
+ MEMP_STATS_DEC(err, MEMP_TCP_PCB);
1028
+ }
1029
+ }
1030
+ if (pcb != NULL) {
1031
+ /* adjust err stats: timewait PCB was freed above */
1032
+ MEMP_STATS_DEC(err, MEMP_TCP_PCB);
1033
+ }
1034
+ }
1035
+ if (pcb != NULL) {
1036
+ memset(pcb, 0, sizeof(struct tcp_pcb));
1037
+ pcb->prio = TCP_PRIO_NORMAL;
1038
+ pcb->snd_buf = TCP_SND_BUF;
1039
+ pcb->snd_queuelen = 0;
1040
+ pcb->rcv_wnd = TCP_WND;
1041
+ pcb->rcv_ann_wnd = TCP_WND;
1042
+ pcb->tos = 0;
1043
+ pcb->ttl = TCP_TTL;
1044
+ /* As initial send MSS, we use TCP_MSS but limit it to 536.
1045
+ The send MSS is updated when an MSS option is received. */
1046
+ pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
1047
+ pcb->rto = 3000 / TCP_SLOW_INTERVAL;
1048
+ pcb->sa = 0;
1049
+ pcb->sv = 3000 / TCP_SLOW_INTERVAL;
1050
+ pcb->rtime = -1;
1051
+ pcb->cwnd = 1;
1052
+ iss = tcp_next_iss();
1053
+ pcb->snd_wl2 = iss;
1054
+ pcb->snd_nxt = iss;
1055
+ pcb->lastack = iss;
1056
+ pcb->snd_lbb = iss;
1057
+ pcb->tmr = tcp_ticks;
1058
+
1059
+ pcb->polltmr = 0;
1060
+
1061
+ #if LWIP_CALLBACK_API
1062
+ pcb->recv = tcp_recv_null;
1063
+ #endif /* LWIP_CALLBACK_API */
1064
+
1065
+ /* Init KEEPALIVE timer */
1066
+ pcb->keep_idle = TCP_KEEPIDLE_DEFAULT;
1067
+
1068
+ #if LWIP_TCP_KEEPALIVE
1069
+ pcb->keep_intvl = TCP_KEEPINTVL_DEFAULT;
1070
+ pcb->keep_cnt = TCP_KEEPCNT_DEFAULT;
1071
+ #endif /* LWIP_TCP_KEEPALIVE */
1072
+
1073
+ pcb->keep_cnt_sent = 0;
1074
+ }
1075
+ return pcb;
1076
+ }
1077
+
1078
+ /**
1079
+ * Creates a new TCP protocol control block but doesn't place it on
1080
+ * any of the TCP PCB lists.
1081
+ * The pcb is not put on any list until binding using tcp_bind().
1082
+ *
1083
+ * @internal: Maybe there should be a idle TCP PCB list where these
1084
+ * PCBs are put on. Port reservation using tcp_bind() is implemented but
1085
+ * allocated pcbs that are not bound can't be killed automatically if wanting
1086
+ * to allocate a pcb with higher prio (@see tcp_kill_prio())
1087
+ *
1088
+ * @return a new tcp_pcb that initially is in state CLOSED
1089
+ */
1090
+ struct tcp_pcb *
1091
+ tcp_new(void)
1092
+ {
1093
+ return tcp_alloc(TCP_PRIO_NORMAL);
1094
+ }
1095
+
1096
+ /**
1097
+ * Used to specify the argument that should be passed callback
1098
+ * functions.
1099
+ *
1100
+ * @param pcb tcp_pcb to set the callback argument
1101
+ * @param arg void pointer argument to pass to callback functions
1102
+ */
1103
+ void
1104
+ tcp_arg(struct tcp_pcb *pcb, void *arg)
1105
+ {
1106
+ pcb->callback_arg = arg;
1107
+ }
1108
+ #if LWIP_CALLBACK_API
1109
+
1110
+ /**
1111
+ * Used to specify the function that should be called when a TCP
1112
+ * connection receives data.
1113
+ *
1114
+ * @param pcb tcp_pcb to set the recv callback
1115
+ * @param recv callback function to call for this pcb when data is received
1116
+ */
1117
+ void
1118
+ tcp_recv(struct tcp_pcb *pcb,
1119
+ err_t (* recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err))
1120
+ {
1121
+ pcb->recv = recv;
1122
+ }
1123
+
1124
+ /**
1125
+ * Used to specify the function that should be called when TCP data
1126
+ * has been successfully delivered to the remote host.
1127
+ *
1128
+ * @param pcb tcp_pcb to set the sent callback
1129
+ * @param sent callback function to call for this pcb when data is successfully sent
1130
+ */
1131
+ void
1132
+ tcp_sent(struct tcp_pcb *pcb,
1133
+ err_t (* sent)(void *arg, struct tcp_pcb *tpcb, u16_t len))
1134
+ {
1135
+ pcb->sent = sent;
1136
+ }
1137
+
1138
+ /**
1139
+ * Used to specify the function that should be called when a fatal error
1140
+ * has occured on the connection.
1141
+ *
1142
+ * @param pcb tcp_pcb to set the err callback
1143
+ * @param errf callback function to call for this pcb when a fatal error
1144
+ * has occured on the connection
1145
+ */
1146
+ void
1147
+ tcp_err(struct tcp_pcb *pcb,
1148
+ void (* errf)(void *arg, err_t err))
1149
+ {
1150
+ pcb->errf = errf;
1151
+ }
1152
+
1153
+ /**
1154
+ * Used for specifying the function that should be called when a
1155
+ * LISTENing connection has been connected to another host.
1156
+ *
1157
+ * @param pcb tcp_pcb to set the accept callback
1158
+ * @param accept callback function to call for this pcb when LISTENing
1159
+ * connection has been connected to another host
1160
+ */
1161
+ void
1162
+ tcp_accept(struct tcp_pcb *pcb,
1163
+ err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err))
1164
+ {
1165
+ pcb->accept = accept;
1166
+ }
1167
+ #endif /* LWIP_CALLBACK_API */
1168
+
1169
+
1170
+ /**
1171
+ * Used to specify the function that should be called periodically
1172
+ * from TCP. The interval is specified in terms of the TCP coarse
1173
+ * timer interval, which is called twice a second.
1174
+ *
1175
+ */
1176
+ void
1177
+ tcp_poll(struct tcp_pcb *pcb,
1178
+ err_t (* poll)(void *arg, struct tcp_pcb *tpcb), u8_t interval)
1179
+ {
1180
+ #if LWIP_CALLBACK_API
1181
+ pcb->poll = poll;
1182
+ #endif /* LWIP_CALLBACK_API */
1183
+ pcb->pollinterval = interval;
1184
+ }
1185
+
1186
+ /**
1187
+ * Purges a TCP PCB. Removes any buffered data and frees the buffer memory
1188
+ * (pcb->ooseq, pcb->unsent and pcb->unacked are freed).
1189
+ *
1190
+ * @param pcb tcp_pcb to purge. The pcb itself is not deallocated!
1191
+ */
1192
+ void
1193
+ tcp_pcb_purge(struct tcp_pcb *pcb)
1194
+ {
1195
+ if (pcb->state != CLOSED &&
1196
+ pcb->state != TIME_WAIT &&
1197
+ pcb->state != LISTEN) {
1198
+
1199
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge\n"));
1200
+
1201
+ #if TCP_LISTEN_BACKLOG
1202
+ if (pcb->state == SYN_RCVD) {
1203
+ /* Need to find the corresponding listen_pcb and decrease its accepts_pending */
1204
+ struct tcp_pcb_listen *lpcb;
1205
+ LWIP_ASSERT("tcp_pcb_purge: pcb->state == SYN_RCVD but tcp_listen_pcbs is NULL",
1206
+ tcp_listen_pcbs.listen_pcbs != NULL);
1207
+ for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
1208
+ if ((lpcb->local_port == pcb->local_port) &&
1209
+ (ip_addr_isany(&lpcb->local_ip) ||
1210
+ ip_addr_cmp(&pcb->local_ip, &lpcb->local_ip))) {
1211
+ /* port and address of the listen pcb match the timed-out pcb */
1212
+ LWIP_ASSERT("tcp_pcb_purge: listen pcb does not have accepts pending",
1213
+ lpcb->accepts_pending > 0);
1214
+ lpcb->accepts_pending--;
1215
+ break;
1216
+ }
1217
+ }
1218
+ }
1219
+ #endif /* TCP_LISTEN_BACKLOG */
1220
+
1221
+
1222
+ if (pcb->refused_data != NULL) {
1223
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->refused_data\n"));
1224
+ pbuf_free(pcb->refused_data);
1225
+ pcb->refused_data = NULL;
1226
+ }
1227
+ if (pcb->unsent != NULL) {
1228
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: not all data sent\n"));
1229
+ }
1230
+ if (pcb->unacked != NULL) {
1231
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->unacked\n"));
1232
+ }
1233
+ #if TCP_QUEUE_OOSEQ /* LW */
1234
+ if (pcb->ooseq != NULL) {
1235
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->ooseq\n"));
1236
+ }
1237
+
1238
+ /* Stop the retransmission timer as it will expect data on unacked
1239
+ queue if it fires */
1240
+ pcb->rtime = -1;
1241
+
1242
+ tcp_segs_free(pcb->ooseq);
1243
+ pcb->ooseq = NULL;
1244
+ #endif /* TCP_QUEUE_OOSEQ */
1245
+ tcp_segs_free(pcb->unsent);
1246
+ tcp_segs_free(pcb->unacked);
1247
+ pcb->unacked = pcb->unsent = NULL;
1248
+ }
1249
+ }
1250
+
1251
+ /**
1252
+ * Purges the PCB and removes it from a PCB list. Any delayed ACKs are sent first.
1253
+ *
1254
+ * @param pcblist PCB list to purge.
1255
+ * @param pcb tcp_pcb to purge. The pcb itself is NOT deallocated!
1256
+ */
1257
+ void
1258
+ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
1259
+ {
1260
+ TCP_RMV(pcblist, pcb);
1261
+
1262
+ tcp_pcb_purge(pcb);
1263
+
1264
+ /* if there is an outstanding delayed ACKs, send it */
1265
+ if (pcb->state != TIME_WAIT &&
1266
+ pcb->state != LISTEN &&
1267
+ pcb->flags & TF_ACK_DELAY) {
1268
+ pcb->flags |= TF_ACK_NOW;
1269
+ tcp_output(pcb);
1270
+ }
1271
+
1272
+ if (pcb->state != LISTEN) {
1273
+ LWIP_ASSERT("unsent segments leaking", pcb->unsent == NULL);
1274
+ LWIP_ASSERT("unacked segments leaking", pcb->unacked == NULL);
1275
+ #if TCP_QUEUE_OOSEQ
1276
+ LWIP_ASSERT("ooseq segments leaking", pcb->ooseq == NULL);
1277
+ #endif /* TCP_QUEUE_OOSEQ */
1278
+ }
1279
+
1280
+ pcb->state = CLOSED;
1281
+
1282
+ LWIP_ASSERT("tcp_pcb_remove: tcp_pcbs_sane()", tcp_pcbs_sane());
1283
+ }
1284
+
1285
+ /**
1286
+ * Calculates a new initial sequence number for new connections.
1287
+ *
1288
+ * @return u32_t pseudo random sequence number
1289
+ */
1290
+ u32_t
1291
+ tcp_next_iss(void)
1292
+ {
1293
+ static u32_t iss = 6510;
1294
+
1295
+ iss += tcp_ticks; /* XXX */
1296
+ return iss;
1297
+ }
1298
+
1299
+ #if TCP_CALCULATE_EFF_SEND_MSS
1300
+ /**
1301
+ * Calcluates the effective send mss that can be used for a specific IP address
1302
+ * by using ip_route to determin the netif used to send to the address and
1303
+ * calculating the minimum of TCP_MSS and that netif's mtu (if set).
1304
+ */
1305
+ u16_t
1306
+ tcp_eff_send_mss(u16_t sendmss, struct ip_addr *addr)
1307
+ {
1308
+ u16_t mss_s;
1309
+ struct netif *outif;
1310
+
1311
+ outif = ip_route(addr);
1312
+ if ((outif != NULL) && (outif->mtu != 0)) {
1313
+ mss_s = outif->mtu - IP_HLEN - TCP_HLEN;
1314
+ /* RFC 1122, chap 4.2.2.6:
1315
+ * Eff.snd.MSS = min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize
1316
+ * We correct for TCP options in tcp_enqueue(), and don't support
1317
+ * IP options
1318
+ */
1319
+ sendmss = LWIP_MIN(sendmss, mss_s);
1320
+ }
1321
+ return sendmss;
1322
+ }
1323
+ #endif /* TCP_CALCULATE_EFF_SEND_MSS */
1324
+
1325
+ const char*
1326
+ tcp_debug_state_str(enum tcp_state s)
1327
+ {
1328
+ return tcp_state_str[s];
1329
+ }
1330
+
1331
+ #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
1332
+ /**
1333
+ * Print a tcp header for debugging purposes.
1334
+ *
1335
+ * @param tcphdr pointer to a struct tcp_hdr
1336
+ */
1337
+ void
1338
+ tcp_debug_print(struct tcp_hdr *tcphdr)
1339
+ {
1340
+ LWIP_DEBUGF(TCP_DEBUG, ("TCP header:\n"));
1341
+ LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1342
+ LWIP_DEBUGF(TCP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n",
1343
+ ntohs(tcphdr->src), ntohs(tcphdr->dest)));
1344
+ LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1345
+ LWIP_DEBUGF(TCP_DEBUG, ("| %010"U32_F" | (seq no)\n",
1346
+ ntohl(tcphdr->seqno)));
1347
+ LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1348
+ LWIP_DEBUGF(TCP_DEBUG, ("| %010"U32_F" | (ack no)\n",
1349
+ ntohl(tcphdr->ackno)));
1350
+ LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1351
+ LWIP_DEBUGF(TCP_DEBUG, ("| %2"U16_F" | |%"U16_F"%"U16_F"%"U16_F"%"U16_F"%"U16_F"%"U16_F"| %5"U16_F" | (hdrlen, flags (",
1352
+ TCPH_HDRLEN(tcphdr),
1353
+ TCPH_FLAGS(tcphdr) >> 5 & 1,
1354
+ TCPH_FLAGS(tcphdr) >> 4 & 1,
1355
+ TCPH_FLAGS(tcphdr) >> 3 & 1,
1356
+ TCPH_FLAGS(tcphdr) >> 2 & 1,
1357
+ TCPH_FLAGS(tcphdr) >> 1 & 1,
1358
+ TCPH_FLAGS(tcphdr) & 1,
1359
+ ntohs(tcphdr->wnd)));
1360
+ tcp_debug_print_flags(TCPH_FLAGS(tcphdr));
1361
+ LWIP_DEBUGF(TCP_DEBUG, ("), win)\n"));
1362
+ LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1363
+ LWIP_DEBUGF(TCP_DEBUG, ("| 0x%04"X16_F" | %5"U16_F" | (chksum, urgp)\n",
1364
+ ntohs(tcphdr->chksum), ntohs(tcphdr->urgp)));
1365
+ LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1366
+ }
1367
+
1368
+ /**
1369
+ * Print a tcp state for debugging purposes.
1370
+ *
1371
+ * @param s enum tcp_state to print
1372
+ */
1373
+ void
1374
+ tcp_debug_print_state(enum tcp_state s)
1375
+ {
1376
+ LWIP_DEBUGF(TCP_DEBUG, ("State: %s\n", tcp_state_str[s]));
1377
+ }
1378
+
1379
+ /**
1380
+ * Print tcp flags for debugging purposes.
1381
+ *
1382
+ * @param flags tcp flags, all active flags are printed
1383
+ */
1384
+ void
1385
+ tcp_debug_print_flags(u8_t flags)
1386
+ {
1387
+ if (flags & TCP_FIN) {
1388
+ LWIP_DEBUGF(TCP_DEBUG, ("FIN "));
1389
+ }
1390
+ if (flags & TCP_SYN) {
1391
+ LWIP_DEBUGF(TCP_DEBUG, ("SYN "));
1392
+ }
1393
+ if (flags & TCP_RST) {
1394
+ LWIP_DEBUGF(TCP_DEBUG, ("RST "));
1395
+ }
1396
+ if (flags & TCP_PSH) {
1397
+ LWIP_DEBUGF(TCP_DEBUG, ("PSH "));
1398
+ }
1399
+ if (flags & TCP_ACK) {
1400
+ LWIP_DEBUGF(TCP_DEBUG, ("ACK "));
1401
+ }
1402
+ if (flags & TCP_URG) {
1403
+ LWIP_DEBUGF(TCP_DEBUG, ("URG "));
1404
+ }
1405
+ if (flags & TCP_ECE) {
1406
+ LWIP_DEBUGF(TCP_DEBUG, ("ECE "));
1407
+ }
1408
+ if (flags & TCP_CWR) {
1409
+ LWIP_DEBUGF(TCP_DEBUG, ("CWR "));
1410
+ }
1411
+ LWIP_DEBUGF(TCP_DEBUG, ("\n"));
1412
+ }
1413
+
1414
+ /**
1415
+ * Print all tcp_pcbs in every list for debugging purposes.
1416
+ */
1417
+ void
1418
+ tcp_debug_print_pcbs(void)
1419
+ {
1420
+ struct tcp_pcb *pcb;
1421
+ LWIP_DEBUGF(TCP_DEBUG, ("Active PCB states:\n"));
1422
+ for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
1423
+ LWIP_DEBUGF(TCP_DEBUG, ("[%p]Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ",
1424
+ pcb, pcb->local_port, pcb->remote_port,
1425
+ pcb->snd_nxt, pcb->rcv_nxt));
1426
+ tcp_debug_print_state(pcb->state);
1427
+ }
1428
+ LWIP_DEBUGF(TCP_DEBUG, ("Listen PCB states:\n"));
1429
+ for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) {
1430
+ LWIP_DEBUGF(TCP_DEBUG, ("[%p]Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ",
1431
+ pcb, pcb->local_port, pcb->remote_port,
1432
+ pcb->snd_nxt, pcb->rcv_nxt));
1433
+ tcp_debug_print_state(pcb->state);
1434
+ }
1435
+ LWIP_DEBUGF(TCP_DEBUG, ("TIME-WAIT PCB states:\n"));
1436
+ for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
1437
+ LWIP_DEBUGF(TCP_DEBUG, ("[%p]Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ",
1438
+ pcb, pcb->local_port, pcb->remote_port,
1439
+ pcb->snd_nxt, pcb->rcv_nxt));
1440
+ tcp_debug_print_state(pcb->state);
1441
+ }
1442
+ }
1443
+
1444
+ /**
1445
+ * Check state consistency of the tcp_pcb lists.
1446
+ */
1447
+ s16_t
1448
+ tcp_pcbs_sane(void)
1449
+ {
1450
+ struct tcp_pcb *pcb;
1451
+ for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
1452
+ LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != CLOSED", pcb->state != CLOSED);
1453
+ LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != LISTEN", pcb->state != LISTEN);
1454
+ LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
1455
+ }
1456
+ for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
1457
+ LWIP_ASSERT("tcp_pcbs_sane: tw pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
1458
+ }
1459
+ return 1;
1460
+ }
1461
+ #endif /* TCP_DEBUG */
1462
+
1463
+ #endif /* LWIP_TCP */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp_in.c ADDED
@@ -0,0 +1,1508 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ * Transmission Control Protocol, incoming traffic
6
+ *
7
+ * The input processing functions of the TCP layer.
8
+ *
9
+ * These functions are generally called in the order (ip_input() ->)
10
+ * tcp_input() -> * tcp_process() -> tcp_receive() (-> application).
11
+ *
12
+ */
13
+
14
+ /*
15
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
16
+ * All rights reserved.
17
+ *
18
+ * Redistribution and use in source and binary forms, with or without modification,
19
+ * are permitted provided that the following conditions are met:
20
+ *
21
+ * 1. Redistributions of source code must retain the above copyright notice,
22
+ * this list of conditions and the following disclaimer.
23
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
24
+ * this list of conditions and the following disclaimer in the documentation
25
+ * and/or other materials provided with the distribution.
26
+ * 3. The name of the author may not be used to endorse or promote products
27
+ * derived from this software without specific prior written permission.
28
+ *
29
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
30
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
32
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
34
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
38
+ * OF SUCH DAMAGE.
39
+ *
40
+ * This file is part of the lwIP TCP/IP stack.
41
+ *
42
+ * Author: Adam Dunkels <adam@sics.se>
43
+ *
44
+ */
45
+
46
+ #include "lwip/opt.h"
47
+
48
+ #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
49
+
50
+ #include "lwip/tcp.h"
51
+ #include "lwip/def.h"
52
+ #include "lwip/ip_addr.h"
53
+ #include "lwip/netif.h"
54
+ #include "lwip/mem.h"
55
+ #include "lwip/memp.h"
56
+ #include "lwip/inet.h"
57
+ #include "lwip/inet_chksum.h"
58
+ #include "lwip/stats.h"
59
+ #include "lwip/snmp.h"
60
+ #include "arch/perf.h"
61
+
62
+ /* These variables are global to all functions involved in the input
63
+ processing of TCP segments. They are set by the tcp_input()
64
+ function. */
65
+ static struct tcp_seg inseg;
66
+ static struct tcp_hdr *tcphdr;
67
+ static struct ip_hdr *iphdr;
68
+ static u32_t seqno, ackno;
69
+ static u8_t flags;
70
+ static u16_t tcplen;
71
+
72
+ static u8_t recv_flags;
73
+ static struct pbuf *recv_data;
74
+
75
+ struct tcp_pcb *tcp_input_pcb;
76
+
77
+ /* Forward declarations. */
78
+ static err_t tcp_process(struct tcp_pcb *pcb);
79
+ static void tcp_receive(struct tcp_pcb *pcb);
80
+ static void tcp_parseopt(struct tcp_pcb *pcb);
81
+
82
+ static err_t tcp_listen_input(struct tcp_pcb_listen *pcb);
83
+ static err_t tcp_timewait_input(struct tcp_pcb *pcb);
84
+
85
+ /**
86
+ * The initial input processing of TCP. It verifies the TCP header, demultiplexes
87
+ * the segment between the PCBs and passes it on to tcp_process(), which implements
88
+ * the TCP finite state machine. This function is called by the IP layer (in
89
+ * ip_input()).
90
+ *
91
+ * @param p received TCP segment to process (p->payload pointing to the IP header)
92
+ * @param inp network interface on which this segment was received
93
+ */
94
+ void
95
+ tcp_input(struct pbuf *p, struct netif *inp)
96
+ {
97
+ struct tcp_pcb *pcb, *prev;
98
+ struct tcp_pcb_listen *lpcb;
99
+ u8_t hdrlen;
100
+ err_t err;
101
+
102
+ PERF_START;
103
+
104
+ TCP_STATS_INC(tcp.recv);
105
+ snmp_inc_tcpinsegs();
106
+
107
+ iphdr = p->payload;
108
+ tcphdr = (struct tcp_hdr *)((u8_t *)p->payload + IPH_HL(iphdr) * 4);
109
+
110
+ #if TCP_INPUT_DEBUG
111
+ tcp_debug_print(tcphdr);
112
+ #endif
113
+
114
+ /* remove header from payload */
115
+ if (pbuf_header(p, -((s16_t)(IPH_HL(iphdr) * 4))) || (p->tot_len < sizeof(struct tcp_hdr))) {
116
+ /* drop short packets */
117
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: short packet (%"U16_F" bytes) discarded\n", p->tot_len));
118
+ TCP_STATS_INC(tcp.lenerr);
119
+ TCP_STATS_INC(tcp.drop);
120
+ snmp_inc_tcpinerrs();
121
+ pbuf_free(p);
122
+ return;
123
+ }
124
+
125
+ /* Don't even process incoming broadcasts/multicasts. */
126
+ if (ip_addr_isbroadcast(&(iphdr->dest), inp) ||
127
+ ip_addr_ismulticast(&(iphdr->dest))) {
128
+ TCP_STATS_INC(tcp.proterr);
129
+ TCP_STATS_INC(tcp.drop);
130
+ snmp_inc_tcpinerrs();
131
+ pbuf_free(p);
132
+ return;
133
+ }
134
+
135
+ #if CHECKSUM_CHECK_TCP
136
+ /* Verify TCP checksum. */
137
+ if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
138
+ (struct ip_addr *)&(iphdr->dest),
139
+ IP_PROTO_TCP, p->tot_len) != 0) {
140
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packet discarded due to failing checksum 0x%04"X16_F"\n",
141
+ inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), (struct ip_addr *)&(iphdr->dest),
142
+ IP_PROTO_TCP, p->tot_len)));
143
+ #if TCP_DEBUG
144
+ tcp_debug_print(tcphdr);
145
+ #endif /* TCP_DEBUG */
146
+ TCP_STATS_INC(tcp.chkerr);
147
+ TCP_STATS_INC(tcp.drop);
148
+ snmp_inc_tcpinerrs();
149
+ pbuf_free(p);
150
+ return;
151
+ }
152
+ #endif
153
+
154
+ /* Move the payload pointer in the pbuf so that it points to the
155
+ TCP data instead of the TCP header. */
156
+ hdrlen = TCPH_HDRLEN(tcphdr);
157
+ if(pbuf_header(p, -(hdrlen * 4))){
158
+ /* drop short packets */
159
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: short packet\n"));
160
+ TCP_STATS_INC(tcp.lenerr);
161
+ TCP_STATS_INC(tcp.drop);
162
+ snmp_inc_tcpinerrs();
163
+ pbuf_free(p);
164
+ return;
165
+ }
166
+
167
+ /* Convert fields in TCP header to host byte order. */
168
+ tcphdr->src = ntohs(tcphdr->src);
169
+ tcphdr->dest = ntohs(tcphdr->dest);
170
+ seqno = tcphdr->seqno = ntohl(tcphdr->seqno);
171
+ ackno = tcphdr->ackno = ntohl(tcphdr->ackno);
172
+ tcphdr->wnd = ntohs(tcphdr->wnd);
173
+
174
+ flags = TCPH_FLAGS(tcphdr);
175
+ tcplen = p->tot_len + ((flags & (TCP_FIN | TCP_SYN)) ? 1 : 0);
176
+
177
+ /* Demultiplex an incoming segment. First, we check if it is destined
178
+ for an active connection. */
179
+ prev = NULL;
180
+
181
+
182
+ for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
183
+ LWIP_ASSERT("tcp_input: active pcb->state != CLOSED", pcb->state != CLOSED);
184
+ LWIP_ASSERT("tcp_input: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
185
+ LWIP_ASSERT("tcp_input: active pcb->state != LISTEN", pcb->state != LISTEN);
186
+ if (pcb->remote_port == tcphdr->src &&
187
+ pcb->local_port == tcphdr->dest &&
188
+ ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)) &&
189
+ ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest))) {
190
+
191
+ /* Move this PCB to the front of the list so that subsequent
192
+ lookups will be faster (we exploit locality in TCP segment
193
+ arrivals). */
194
+ LWIP_ASSERT("tcp_input: pcb->next != pcb (before cache)", pcb->next != pcb);
195
+ if (prev != NULL) {
196
+ prev->next = pcb->next;
197
+ pcb->next = tcp_active_pcbs;
198
+ tcp_active_pcbs = pcb;
199
+ }
200
+ LWIP_ASSERT("tcp_input: pcb->next != pcb (after cache)", pcb->next != pcb);
201
+ break;
202
+ }
203
+ prev = pcb;
204
+ }
205
+
206
+ if (pcb == NULL) {
207
+ /* If it did not go to an active connection, we check the connections
208
+ in the TIME-WAIT state. */
209
+ for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
210
+ LWIP_ASSERT("tcp_input: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
211
+ if (pcb->remote_port == tcphdr->src &&
212
+ pcb->local_port == tcphdr->dest &&
213
+ ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)) &&
214
+ ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest))) {
215
+ /* We don't really care enough to move this PCB to the front
216
+ of the list since we are not very likely to receive that
217
+ many segments for connections in TIME-WAIT. */
218
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for TIME_WAITing connection.\n"));
219
+ tcp_timewait_input(pcb);
220
+ pbuf_free(p);
221
+ return;
222
+ }
223
+ }
224
+
225
+ /* Finally, if we still did not get a match, we check all PCBs that
226
+ are LISTENing for incoming connections. */
227
+ prev = NULL;
228
+ for(lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
229
+ if ((ip_addr_isany(&(lpcb->local_ip)) ||
230
+ ip_addr_cmp(&(lpcb->local_ip), &(iphdr->dest))) &&
231
+ lpcb->local_port == tcphdr->dest) {
232
+ /* Move this PCB to the front of the list so that subsequent
233
+ lookups will be faster (we exploit locality in TCP segment
234
+ arrivals). */
235
+ if (prev != NULL) {
236
+ ((struct tcp_pcb_listen *)prev)->next = lpcb->next;
237
+ /* our successor is the remainder of the listening list */
238
+ lpcb->next = tcp_listen_pcbs.listen_pcbs;
239
+ /* put this listening pcb at the head of the listening list */
240
+ tcp_listen_pcbs.listen_pcbs = lpcb;
241
+ }
242
+
243
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for LISTENing connection.\n"));
244
+ tcp_listen_input(lpcb);
245
+ pbuf_free(p);
246
+ return;
247
+ }
248
+ prev = (struct tcp_pcb *)lpcb;
249
+ }
250
+ }
251
+
252
+ #if TCP_INPUT_DEBUG
253
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("+-+-+-+-+-+-+-+-+-+-+-+-+-+- tcp_input: flags "));
254
+ tcp_debug_print_flags(TCPH_FLAGS(tcphdr));
255
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"));
256
+ #endif /* TCP_INPUT_DEBUG */
257
+
258
+
259
+ if (pcb != NULL) {
260
+ /* The incoming segment belongs to a connection. */
261
+ #if TCP_INPUT_DEBUG
262
+ #if TCP_DEBUG
263
+ tcp_debug_print_state(pcb->state);
264
+ #endif /* TCP_DEBUG */
265
+ #endif /* TCP_INPUT_DEBUG */
266
+
267
+ /* Set up a tcp_seg structure. */
268
+ inseg.next = NULL;
269
+ inseg.len = p->tot_len;
270
+ inseg.dataptr = p->payload;
271
+ inseg.p = p;
272
+ inseg.tcphdr = tcphdr;
273
+
274
+ recv_data = NULL;
275
+ recv_flags = 0;
276
+
277
+ /* If there is data which was previously "refused" by upper layer */
278
+ if (pcb->refused_data != NULL) {
279
+ /* Notify again application with data previously received. */
280
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: notify kept packet\n"));
281
+ TCP_EVENT_RECV(pcb, pcb->refused_data, ERR_OK, err);
282
+ if (err == ERR_OK) {
283
+ pcb->refused_data = NULL;
284
+ } else {
285
+ /* drop incoming packets, because pcb is "full" */
286
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: drop incoming packets, because pcb is \"full\"\n"));
287
+ TCP_STATS_INC(tcp.drop);
288
+ snmp_inc_tcpinerrs();
289
+ pbuf_free(p);
290
+ return;
291
+ }
292
+ }
293
+ tcp_input_pcb = pcb;
294
+ err = tcp_process(pcb);
295
+ /* A return value of ERR_ABRT means that tcp_abort() was called
296
+ and that the pcb has been freed. If so, we don't do anything. */
297
+ if (err != ERR_ABRT) {
298
+ if (recv_flags & TF_RESET) {
299
+ /* TF_RESET means that the connection was reset by the other
300
+ end. We then call the error callback to inform the
301
+ application that the connection is dead before we
302
+ deallocate the PCB. */
303
+ TCP_EVENT_ERR(pcb->errf, pcb->callback_arg, ERR_RST);
304
+ tcp_pcb_remove(&tcp_active_pcbs, pcb);
305
+ memp_free(MEMP_TCP_PCB, pcb);
306
+ } else if (recv_flags & TF_CLOSED) {
307
+ /* The connection has been closed and we will deallocate the
308
+ PCB. */
309
+ tcp_pcb_remove(&tcp_active_pcbs, pcb);
310
+ memp_free(MEMP_TCP_PCB, pcb);
311
+ } else {
312
+ err = ERR_OK;
313
+ /* If the application has registered a "sent" function to be
314
+ called when new send buffer space is available, we call it
315
+ now. */
316
+ if (pcb->acked > 0) {
317
+ TCP_EVENT_SENT(pcb, pcb->acked, err);
318
+ }
319
+
320
+ if (recv_data != NULL) {
321
+ if(flags & TCP_PSH) {
322
+ recv_data->flags |= PBUF_FLAG_PUSH;
323
+ }
324
+
325
+ /* Notify application that data has been received. */
326
+ TCP_EVENT_RECV(pcb, recv_data, ERR_OK, err);
327
+
328
+ /* If the upper layer can't receive this data, store it */
329
+ if (err != ERR_OK) {
330
+ pcb->refused_data = recv_data;
331
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: keep incoming packet, because pcb is \"full\"\n"));
332
+ }
333
+ }
334
+
335
+ /* If a FIN segment was received, we call the callback
336
+ function with a NULL buffer to indicate EOF. */
337
+ if (recv_flags & TF_GOT_FIN) {
338
+ TCP_EVENT_RECV(pcb, NULL, ERR_OK, err);
339
+ }
340
+
341
+ tcp_input_pcb = NULL;
342
+ /* Try to send something out. */
343
+ tcp_output(pcb);
344
+ #if TCP_INPUT_DEBUG
345
+ #if TCP_DEBUG
346
+ tcp_debug_print_state(pcb->state);
347
+ #endif /* TCP_DEBUG */
348
+ #endif /* TCP_INPUT_DEBUG */
349
+ }
350
+ }
351
+ tcp_input_pcb = NULL;
352
+
353
+
354
+ /* give up our reference to inseg.p */
355
+ if (inseg.p != NULL)
356
+ {
357
+ pbuf_free(inseg.p);
358
+ inseg.p = NULL;
359
+ }
360
+ } else {
361
+
362
+ /* If no matching PCB was found, send a TCP RST (reset) to the
363
+ sender. */
364
+ LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_input: no PCB match found, resetting.\n"));
365
+ if (!(TCPH_FLAGS(tcphdr) & TCP_RST)) {
366
+ TCP_STATS_INC(tcp.proterr);
367
+ TCP_STATS_INC(tcp.drop);
368
+ tcp_rst(ackno, seqno + tcplen,
369
+ &(iphdr->dest), &(iphdr->src),
370
+ tcphdr->dest, tcphdr->src);
371
+ }
372
+ pbuf_free(p);
373
+ }
374
+
375
+ LWIP_ASSERT("tcp_input: tcp_pcbs_sane()", tcp_pcbs_sane());
376
+ PERF_STOP("tcp_input");
377
+ }
378
+
379
+ /**
380
+ * Called by tcp_input() when a segment arrives for a listening
381
+ * connection (from tcp_input()).
382
+ *
383
+ * @param pcb the tcp_pcb_listen for which a segment arrived
384
+ * @return ERR_OK if the segment was processed
385
+ * another err_t on error
386
+ *
387
+ * @note the return value is not (yet?) used in tcp_input()
388
+ * @note the segment which arrived is saved in global variables, therefore only the pcb
389
+ * involved is passed as a parameter to this function
390
+ */
391
+ static err_t
392
+ tcp_listen_input(struct tcp_pcb_listen *pcb)
393
+ {
394
+ struct tcp_pcb *npcb;
395
+ err_t rc;
396
+
397
+ /* In the LISTEN state, we check for incoming SYN segments,
398
+ creates a new PCB, and responds with a SYN|ACK. */
399
+ if (flags & TCP_ACK) {
400
+ /* For incoming segments with the ACK flag set, respond with a
401
+ RST. */
402
+ LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n"));
403
+ tcp_rst(ackno + 1, seqno + tcplen,
404
+ &(iphdr->dest), &(iphdr->src),
405
+ tcphdr->dest, tcphdr->src);
406
+ } else if (flags & TCP_SYN) {
407
+ LWIP_DEBUGF(TCP_DEBUG, ("TCP connection request %"U16_F" -> %"U16_F".\n", tcphdr->src, tcphdr->dest));
408
+ #if TCP_LISTEN_BACKLOG
409
+ if (pcb->accepts_pending >= pcb->backlog) {
410
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_listen_input: listen backlog exceeded for port %"U16_F"\n", tcphdr->dest));
411
+ return ERR_ABRT;
412
+ }
413
+ #endif /* TCP_LISTEN_BACKLOG */
414
+ npcb = tcp_alloc(pcb->prio);
415
+ /* If a new PCB could not be created (probably due to lack of memory),
416
+ we don't do anything, but rely on the sender will retransmit the
417
+ SYN at a time when we have more memory available. */
418
+ if (npcb == NULL) {
419
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_listen_input: could not allocate PCB\n"));
420
+ TCP_STATS_INC(tcp.memerr);
421
+ return ERR_MEM;
422
+ }
423
+ #if TCP_LISTEN_BACKLOG
424
+ pcb->accepts_pending++;
425
+ #endif /* TCP_LISTEN_BACKLOG */
426
+ /* Set up the new PCB. */
427
+ ip_addr_set(&(npcb->local_ip), &(iphdr->dest));
428
+ npcb->local_port = pcb->local_port;
429
+ ip_addr_set(&(npcb->remote_ip), &(iphdr->src));
430
+ npcb->remote_port = tcphdr->src;
431
+ npcb->state = SYN_RCVD;
432
+ npcb->rcv_nxt = seqno + 1;
433
+ npcb->rcv_ann_right_edge = npcb->rcv_nxt;
434
+ npcb->snd_wnd = tcphdr->wnd;
435
+ npcb->ssthresh = npcb->snd_wnd;
436
+ npcb->snd_wl1 = seqno - 1;/* initialise to seqno-1 to force window update */
437
+ npcb->callback_arg = pcb->callback_arg;
438
+ #if LWIP_CALLBACK_API
439
+ npcb->accept = pcb->accept;
440
+ #endif /* LWIP_CALLBACK_API */
441
+ /* inherit socket options */
442
+ npcb->so_options = pcb->so_options & (SOF_DEBUG|SOF_DONTROUTE|SOF_KEEPALIVE|SOF_OOBINLINE|SOF_LINGER);
443
+ /* Register the new PCB so that we can begin receiving segments
444
+ for it. */
445
+ TCP_REG(&tcp_active_pcbs, npcb);
446
+
447
+ /* Parse any options in the SYN. */
448
+ tcp_parseopt(npcb);
449
+ #if TCP_CALCULATE_EFF_SEND_MSS
450
+ npcb->mss = tcp_eff_send_mss(npcb->mss, &(npcb->remote_ip));
451
+ #endif /* TCP_CALCULATE_EFF_SEND_MSS */
452
+
453
+ snmp_inc_tcppassiveopens();
454
+
455
+ /* Send a SYN|ACK together with the MSS option. */
456
+ rc = tcp_enqueue(npcb, NULL, 0, TCP_SYN | TCP_ACK, 0, TF_SEG_OPTS_MSS
457
+ #if LWIP_TCP_TIMESTAMPS
458
+ /* and maybe include the TIMESTAMP option */
459
+ | (npcb->flags & TF_TIMESTAMP ? TF_SEG_OPTS_TS : 0)
460
+ #endif
461
+ );
462
+ if (rc != ERR_OK) {
463
+ tcp_abandon(npcb, 0);
464
+ return rc;
465
+ }
466
+ return tcp_output(npcb);
467
+ }
468
+ return ERR_OK;
469
+ }
470
+
471
+ /**
472
+ * Called by tcp_input() when a segment arrives for a connection in
473
+ * TIME_WAIT.
474
+ *
475
+ * @param pcb the tcp_pcb for which a segment arrived
476
+ *
477
+ * @note the segment which arrived is saved in global variables, therefore only the pcb
478
+ * involved is passed as a parameter to this function
479
+ */
480
+ static err_t
481
+ tcp_timewait_input(struct tcp_pcb *pcb)
482
+ {
483
+ /* RFC 1337: in TIME_WAIT, ignore RST and ACK FINs + any 'acceptable' segments */
484
+ /* RFC 793 3.9 Event Processing - Segment Arrives:
485
+ * - first check sequence number - we skip that one in TIME_WAIT (always
486
+ * acceptable since we only send ACKs)
487
+ * - second check the RST bit (... return) */
488
+ if (flags & TCP_RST) {
489
+ return ERR_OK;
490
+ }
491
+ /* - fourth, check the SYN bit, */
492
+ if (flags & TCP_SYN) {
493
+ /* If an incoming segment is not acceptable, an acknowledgment
494
+ should be sent in reply */
495
+ if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt+pcb->rcv_wnd)) {
496
+ /* If the SYN is in the window it is an error, send a reset */
497
+ tcp_rst(ackno, seqno + tcplen, &(iphdr->dest), &(iphdr->src),
498
+ tcphdr->dest, tcphdr->src);
499
+ return ERR_OK;
500
+ }
501
+ } else if (flags & TCP_FIN) {
502
+ /* - eighth, check the FIN bit: Remain in the TIME-WAIT state.
503
+ Restart the 2 MSL time-wait timeout.*/
504
+ pcb->tmr = tcp_ticks;
505
+ }
506
+
507
+ if ((tcplen > 0)) {
508
+ /* Acknowledge data, FIN or out-of-window SYN */
509
+ pcb->flags |= TF_ACK_NOW;
510
+ return tcp_output(pcb);
511
+ }
512
+ return ERR_OK;
513
+ }
514
+
515
+ /**
516
+ * Implements the TCP state machine. Called by tcp_input. In some
517
+ * states tcp_receive() is called to receive data. The tcp_seg
518
+ * argument will be freed by the caller (tcp_input()) unless the
519
+ * recv_data pointer in the pcb is set.
520
+ *
521
+ * @param pcb the tcp_pcb for which a segment arrived
522
+ *
523
+ * @note the segment which arrived is saved in global variables, therefore only the pcb
524
+ * involved is passed as a parameter to this function
525
+ */
526
+ static err_t
527
+ tcp_process(struct tcp_pcb *pcb)
528
+ {
529
+ struct tcp_seg *rseg;
530
+ u8_t acceptable = 0;
531
+ err_t err;
532
+
533
+ err = ERR_OK;
534
+
535
+ /* Process incoming RST segments. */
536
+ if (flags & TCP_RST) {
537
+ /* First, determine if the reset is acceptable. */
538
+ if (pcb->state == SYN_SENT) {
539
+ if (ackno == pcb->snd_nxt) {
540
+ acceptable = 1;
541
+ }
542
+ } else {
543
+ if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt,
544
+ pcb->rcv_nxt+pcb->rcv_wnd)) {
545
+ acceptable = 1;
546
+ }
547
+ }
548
+
549
+ if (acceptable) {
550
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_process: Connection RESET\n"));
551
+ LWIP_ASSERT("tcp_input: pcb->state != CLOSED", pcb->state != CLOSED);
552
+ recv_flags |= TF_RESET;
553
+ pcb->flags &= ~TF_ACK_DELAY;
554
+ return ERR_RST;
555
+ } else {
556
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_process: unacceptable reset seqno %"U32_F" rcv_nxt %"U32_F"\n",
557
+ seqno, pcb->rcv_nxt));
558
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_process: unacceptable reset seqno %"U32_F" rcv_nxt %"U32_F"\n",
559
+ seqno, pcb->rcv_nxt));
560
+ return ERR_OK;
561
+ }
562
+ }
563
+
564
+ if ((flags & TCP_SYN) && (pcb->state != SYN_SENT && pcb->state != SYN_RCVD)) {
565
+ /* Cope with new connection attempt after remote end crashed */
566
+ tcp_ack_now(pcb);
567
+ return ERR_OK;
568
+ }
569
+
570
+ /* Update the PCB (in)activity timer. */
571
+ pcb->tmr = tcp_ticks;
572
+ pcb->keep_cnt_sent = 0;
573
+
574
+ tcp_parseopt(pcb);
575
+
576
+ /* Do different things depending on the TCP state. */
577
+ switch (pcb->state) {
578
+ case SYN_SENT:
579
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("SYN-SENT: ackno %"U32_F" pcb->snd_nxt %"U32_F" unacked %"U32_F"\n", ackno,
580
+ pcb->snd_nxt, ntohl(pcb->unacked->tcphdr->seqno)));
581
+ /* received SYN ACK with expected sequence number? */
582
+ if ((flags & TCP_ACK) && (flags & TCP_SYN)
583
+ && ackno == ntohl(pcb->unacked->tcphdr->seqno) + 1) {
584
+ pcb->snd_buf++;
585
+ pcb->rcv_nxt = seqno + 1;
586
+ pcb->rcv_ann_right_edge = pcb->rcv_nxt;
587
+ pcb->lastack = ackno;
588
+ pcb->snd_wnd = tcphdr->wnd;
589
+ pcb->snd_wl1 = seqno - 1; /* initialise to seqno - 1 to force window update */
590
+ pcb->state = ESTABLISHED;
591
+
592
+ #if TCP_CALCULATE_EFF_SEND_MSS
593
+ pcb->mss = tcp_eff_send_mss(pcb->mss, &(pcb->remote_ip));
594
+ #endif /* TCP_CALCULATE_EFF_SEND_MSS */
595
+
596
+ /* Set ssthresh again after changing pcb->mss (already set in tcp_connect
597
+ * but for the default value of pcb->mss) */
598
+ pcb->ssthresh = pcb->mss * 10;
599
+
600
+ pcb->cwnd = ((pcb->cwnd == 1) ? (pcb->mss * 2) : pcb->mss);
601
+ LWIP_ASSERT("pcb->snd_queuelen > 0", (pcb->snd_queuelen > 0));
602
+ --pcb->snd_queuelen;
603
+ LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_process: SYN-SENT --queuelen %"U16_F"\n", (u16_t)pcb->snd_queuelen));
604
+ rseg = pcb->unacked;
605
+ pcb->unacked = rseg->next;
606
+
607
+ /* If there's nothing left to acknowledge, stop the retransmit
608
+ timer, otherwise reset it to start again */
609
+ if(pcb->unacked == NULL)
610
+ pcb->rtime = -1;
611
+ else {
612
+ pcb->rtime = 0;
613
+ pcb->nrtx = 0;
614
+ }
615
+
616
+ tcp_seg_free(rseg);
617
+
618
+ /* Call the user specified function to call when sucessfully
619
+ * connected. */
620
+ TCP_EVENT_CONNECTED(pcb, ERR_OK, err);
621
+ tcp_ack_now(pcb);
622
+ }
623
+ /* received ACK? possibly a half-open connection */
624
+ else if (flags & TCP_ACK) {
625
+ /* send a RST to bring the other side in a non-synchronized state. */
626
+ tcp_rst(ackno, seqno + tcplen, &(iphdr->dest), &(iphdr->src),
627
+ tcphdr->dest, tcphdr->src);
628
+ }
629
+ break;
630
+ case SYN_RCVD:
631
+ if (flags & TCP_ACK) {
632
+ /* expected ACK number? */
633
+ if (TCP_SEQ_BETWEEN(ackno, pcb->lastack+1, pcb->snd_nxt)) {
634
+ u16_t old_cwnd;
635
+ pcb->state = ESTABLISHED;
636
+ LWIP_DEBUGF(TCP_DEBUG, ("TCP connection established %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest));
637
+ #if LWIP_CALLBACK_API
638
+ LWIP_ASSERT("pcb->accept != NULL", pcb->accept != NULL);
639
+ #endif
640
+ /* Call the accept function. */
641
+ TCP_EVENT_ACCEPT(pcb, ERR_OK, err);
642
+ if (err != ERR_OK) {
643
+ /* If the accept function returns with an error, we abort
644
+ * the connection. */
645
+ tcp_abort(pcb);
646
+ return ERR_ABRT;
647
+ }
648
+ old_cwnd = pcb->cwnd;
649
+ /* If there was any data contained within this ACK,
650
+ * we'd better pass it on to the application as well. */
651
+ tcp_receive(pcb);
652
+
653
+ /* Prevent ACK for SYN to generate a sent event */
654
+ if (pcb->acked != 0) {
655
+ pcb->acked--;
656
+ }
657
+
658
+ pcb->cwnd = ((old_cwnd == 1) ? (pcb->mss * 2) : pcb->mss);
659
+
660
+ if (recv_flags & TF_GOT_FIN) {
661
+ tcp_ack_now(pcb);
662
+ pcb->state = CLOSE_WAIT;
663
+ }
664
+ }
665
+ /* incorrect ACK number */
666
+ else {
667
+ /* send RST */
668
+ tcp_rst(ackno, seqno + tcplen, &(iphdr->dest), &(iphdr->src),
669
+ tcphdr->dest, tcphdr->src);
670
+ }
671
+ } else if ((flags & TCP_SYN) && (seqno == pcb->rcv_nxt - 1)) {
672
+ /* Looks like another copy of the SYN - retransmit our SYN-ACK */
673
+ tcp_rexmit(pcb);
674
+ }
675
+ break;
676
+ case CLOSE_WAIT:
677
+ /* FALLTHROUGH */
678
+ case ESTABLISHED:
679
+ tcp_receive(pcb);
680
+ if (recv_flags & TF_GOT_FIN) { /* passive close */
681
+ tcp_ack_now(pcb);
682
+ pcb->state = CLOSE_WAIT;
683
+ }
684
+ break;
685
+ case FIN_WAIT_1:
686
+ tcp_receive(pcb);
687
+ if (recv_flags & TF_GOT_FIN) {
688
+ if ((flags & TCP_ACK) && (ackno == pcb->snd_nxt)) {
689
+ LWIP_DEBUGF(TCP_DEBUG,
690
+ ("TCP connection closed: FIN_WAIT_1 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest));
691
+ tcp_ack_now(pcb);
692
+ tcp_pcb_purge(pcb);
693
+ TCP_RMV(&tcp_active_pcbs, pcb);
694
+ pcb->state = TIME_WAIT;
695
+ TCP_REG(&tcp_tw_pcbs, pcb);
696
+ } else {
697
+ tcp_ack_now(pcb);
698
+ pcb->state = CLOSING;
699
+ }
700
+ } else if ((flags & TCP_ACK) && (ackno == pcb->snd_nxt)) {
701
+ pcb->state = FIN_WAIT_2;
702
+ }
703
+ break;
704
+ case FIN_WAIT_2:
705
+ tcp_receive(pcb);
706
+ if (recv_flags & TF_GOT_FIN) {
707
+ LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: FIN_WAIT_2 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest));
708
+ tcp_ack_now(pcb);
709
+ tcp_pcb_purge(pcb);
710
+ TCP_RMV(&tcp_active_pcbs, pcb);
711
+ pcb->state = TIME_WAIT;
712
+ TCP_REG(&tcp_tw_pcbs, pcb);
713
+ }
714
+ break;
715
+ case CLOSING:
716
+ tcp_receive(pcb);
717
+ if (flags & TCP_ACK && ackno == pcb->snd_nxt) {
718
+ LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: CLOSING %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest));
719
+ tcp_pcb_purge(pcb);
720
+ TCP_RMV(&tcp_active_pcbs, pcb);
721
+ pcb->state = TIME_WAIT;
722
+ TCP_REG(&tcp_tw_pcbs, pcb);
723
+ }
724
+ break;
725
+ case LAST_ACK:
726
+ tcp_receive(pcb);
727
+ if (flags & TCP_ACK && ackno == pcb->snd_nxt) {
728
+ LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: LAST_ACK %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest));
729
+ /* bugfix #21699: don't set pcb->state to CLOSED here or we risk leaking segments */
730
+ recv_flags |= TF_CLOSED;
731
+ }
732
+ break;
733
+ default:
734
+ break;
735
+ }
736
+ return ERR_OK;
737
+ }
738
+
739
+ #if TCP_QUEUE_OOSEQ
740
+ /**
741
+ * Insert segment into the list (segments covered with new one will be deleted)
742
+ *
743
+ * Called from tcp_receive()
744
+ */
745
+ static void
746
+ tcp_oos_insert_segment(struct tcp_seg *cseg, struct tcp_seg *next)
747
+ {
748
+ struct tcp_seg *old_seg;
749
+
750
+ if (TCPH_FLAGS(cseg->tcphdr) & TCP_FIN) {
751
+ /* received segment overlaps all following segments */
752
+ tcp_segs_free(next);
753
+ next = NULL;
754
+ }
755
+ else {
756
+ /* delete some following segments
757
+ oos queue may have segments with FIN flag */
758
+ while (next &&
759
+ TCP_SEQ_GEQ((seqno + cseg->len),
760
+ (next->tcphdr->seqno + next->len))) {
761
+ /* cseg with FIN already processed */
762
+ if (TCPH_FLAGS(next->tcphdr) & TCP_FIN) {
763
+ TCPH_FLAGS_SET(cseg->tcphdr, TCPH_FLAGS(cseg->tcphdr) | TCP_FIN);
764
+ }
765
+ old_seg = next;
766
+ next = next->next;
767
+ tcp_seg_free(old_seg);
768
+ }
769
+ if (next &&
770
+ TCP_SEQ_GT(seqno + cseg->len, next->tcphdr->seqno)) {
771
+ /* We need to trim the incoming segment. */
772
+ cseg->len = (u16_t)(next->tcphdr->seqno - seqno);
773
+ pbuf_realloc(cseg->p, cseg->len);
774
+ }
775
+ }
776
+ cseg->next = next;
777
+ }
778
+ #endif
779
+
780
+ /**
781
+ * Called by tcp_process. Checks if the given segment is an ACK for outstanding
782
+ * data, and if so frees the memory of the buffered data. Next, is places the
783
+ * segment on any of the receive queues (pcb->recved or pcb->ooseq). If the segment
784
+ * is buffered, the pbuf is referenced by pbuf_ref so that it will not be freed until
785
+ * i it has been removed from the buffer.
786
+ *
787
+ * If the incoming segment constitutes an ACK for a segment that was used for RTT
788
+ * estimation, the RTT is estimated here as well.
789
+ *
790
+ * Called from tcp_process().
791
+ */
792
+ static void
793
+ tcp_receive(struct tcp_pcb *pcb)
794
+ {
795
+ struct tcp_seg *next;
796
+ #if TCP_QUEUE_OOSEQ
797
+ struct tcp_seg *prev, *cseg;
798
+ #endif
799
+ struct pbuf *p;
800
+ s32_t off;
801
+ s16_t m;
802
+ u32_t right_wnd_edge;
803
+ u16_t new_tot_len;
804
+ int found_dupack = 0;
805
+
806
+ if (flags & TCP_ACK) {
807
+ right_wnd_edge = pcb->snd_wnd + pcb->snd_wl2;
808
+
809
+ /* Update window. */
810
+ if (TCP_SEQ_LT(pcb->snd_wl1, seqno) ||
811
+ (pcb->snd_wl1 == seqno && TCP_SEQ_LT(pcb->snd_wl2, ackno)) ||
812
+ (pcb->snd_wl2 == ackno && tcphdr->wnd > pcb->snd_wnd)) {
813
+ pcb->snd_wnd = tcphdr->wnd;
814
+ pcb->snd_wl1 = seqno;
815
+ pcb->snd_wl2 = ackno;
816
+ if (pcb->snd_wnd > 0 && pcb->persist_backoff > 0) {
817
+ pcb->persist_backoff = 0;
818
+ }
819
+ LWIP_DEBUGF(TCP_WND_DEBUG, ("tcp_receive: window update %"U16_F"\n", pcb->snd_wnd));
820
+ #if TCP_WND_DEBUG
821
+ } else {
822
+ if (pcb->snd_wnd != tcphdr->wnd) {
823
+ LWIP_DEBUGF(TCP_WND_DEBUG,
824
+ ("tcp_receive: no window update lastack %"U32_F" ackno %"
825
+ U32_F" wl1 %"U32_F" seqno %"U32_F" wl2 %"U32_F"\n",
826
+ pcb->lastack, ackno, pcb->snd_wl1, seqno, pcb->snd_wl2));
827
+ }
828
+ #endif /* TCP_WND_DEBUG */
829
+ }
830
+
831
+ /* (From Stevens TCP/IP Illustrated Vol II, p970.) Its only a
832
+ * duplicate ack if:
833
+ * 1) It doesn't ACK new data
834
+ * 2) length of received packet is zero (i.e. no payload)
835
+ * 3) the advertised window hasn't changed
836
+ * 4) There is outstanding unacknowledged data (retransmission timer running)
837
+ * 5) The ACK is == biggest ACK sequence number so far seen (snd_una)
838
+ *
839
+ * If it passes all five, should process as a dupack:
840
+ * a) dupacks < 3: do nothing
841
+ * b) dupacks == 3: fast retransmit
842
+ * c) dupacks > 3: increase cwnd
843
+ *
844
+ * If it only passes 1-3, should reset dupack counter (and add to
845
+ * stats, which we don't do in lwIP)
846
+ *
847
+ * If it only passes 1, should reset dupack counter
848
+ *
849
+ */
850
+
851
+ /* Clause 1 */
852
+ if (TCP_SEQ_LEQ(ackno, pcb->lastack)) {
853
+ pcb->acked = 0;
854
+ /* Clause 2 */
855
+ if (tcplen == 0) {
856
+ /* Clause 3 */
857
+ if (pcb->snd_wl2 + pcb->snd_wnd == right_wnd_edge){
858
+ /* Clause 4 */
859
+ if (pcb->rtime >= 0) {
860
+ /* Clause 5 */
861
+ if (pcb->lastack == ackno) {
862
+ found_dupack = 1;
863
+ if (pcb->dupacks + 1 > pcb->dupacks)
864
+ ++pcb->dupacks;
865
+ if (pcb->dupacks > 3) {
866
+ /* Inflate the congestion window, but not if it means that
867
+ the value overflows. */
868
+ if ((u16_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) {
869
+ pcb->cwnd += pcb->mss;
870
+ }
871
+ } else if (pcb->dupacks == 3) {
872
+ /* Do fast retransmit */
873
+ tcp_rexmit_fast(pcb);
874
+ }
875
+ }
876
+ }
877
+ }
878
+ }
879
+ /* If Clause (1) or more is true, but not a duplicate ack, reset
880
+ * count of consecutive duplicate acks */
881
+ if (!found_dupack) {
882
+ pcb->dupacks = 0;
883
+ }
884
+ } else if (TCP_SEQ_BETWEEN(ackno, pcb->lastack+1, pcb->snd_nxt)){
885
+ /* We come here when the ACK acknowledges new data. */
886
+
887
+ /* Reset the "IN Fast Retransmit" flag, since we are no longer
888
+ in fast retransmit. Also reset the congestion window to the
889
+ slow start threshold. */
890
+ if (pcb->flags & TF_INFR) {
891
+ pcb->flags &= ~TF_INFR;
892
+ pcb->cwnd = pcb->ssthresh;
893
+ }
894
+
895
+ /* Reset the number of retransmissions. */
896
+ pcb->nrtx = 0;
897
+
898
+ /* Reset the retransmission time-out. */
899
+ pcb->rto = (pcb->sa >> 3) + pcb->sv;
900
+
901
+ /* Update the send buffer space. Diff between the two can never exceed 64K? */
902
+ pcb->acked = (u16_t)(ackno - pcb->lastack);
903
+
904
+ pcb->snd_buf += pcb->acked;
905
+
906
+ /* Reset the fast retransmit variables. */
907
+ pcb->dupacks = 0;
908
+ pcb->lastack = ackno;
909
+
910
+ /* Update the congestion control variables (cwnd and
911
+ ssthresh). */
912
+ if (pcb->state >= ESTABLISHED) {
913
+ if (pcb->cwnd < pcb->ssthresh) {
914
+ if ((u16_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) {
915
+ pcb->cwnd += pcb->mss;
916
+ }
917
+ LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: slow start cwnd %"U16_F"\n", pcb->cwnd));
918
+ } else {
919
+ u16_t new_cwnd = (pcb->cwnd + pcb->mss * pcb->mss / pcb->cwnd);
920
+ if (new_cwnd > pcb->cwnd) {
921
+ pcb->cwnd = new_cwnd;
922
+ }
923
+ LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: congestion avoidance cwnd %"U16_F"\n", pcb->cwnd));
924
+ }
925
+ }
926
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: ACK for %"U32_F", unacked->seqno %"U32_F":%"U32_F"\n",
927
+ ackno,
928
+ pcb->unacked != NULL?
929
+ ntohl(pcb->unacked->tcphdr->seqno): 0,
930
+ pcb->unacked != NULL?
931
+ ntohl(pcb->unacked->tcphdr->seqno) + TCP_TCPLEN(pcb->unacked): 0));
932
+
933
+ /* Remove segment from the unacknowledged list if the incoming
934
+ ACK acknowlegdes them. */
935
+ while (pcb->unacked != NULL &&
936
+ TCP_SEQ_LEQ(ntohl(pcb->unacked->tcphdr->seqno) +
937
+ TCP_TCPLEN(pcb->unacked), ackno)) {
938
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: removing %"U32_F":%"U32_F" from pcb->unacked\n",
939
+ ntohl(pcb->unacked->tcphdr->seqno),
940
+ ntohl(pcb->unacked->tcphdr->seqno) +
941
+ TCP_TCPLEN(pcb->unacked)));
942
+
943
+ next = pcb->unacked;
944
+ pcb->unacked = pcb->unacked->next;
945
+
946
+ LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"U16_F" ... ", (u16_t)pcb->snd_queuelen));
947
+ LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p)));
948
+ /* Prevent ACK for FIN to generate a sent event */
949
+ if ((pcb->acked != 0) && ((TCPH_FLAGS(next->tcphdr) & TCP_FIN) != 0)) {
950
+ pcb->acked--;
951
+ }
952
+
953
+ pcb->snd_queuelen -= pbuf_clen(next->p);
954
+ tcp_seg_free(next);
955
+
956
+ LWIP_DEBUGF(TCP_QLEN_DEBUG, ("%"U16_F" (after freeing unacked)\n", (u16_t)pcb->snd_queuelen));
957
+ if (pcb->snd_queuelen != 0) {
958
+ LWIP_ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL ||
959
+ pcb->unsent != NULL);
960
+ }
961
+ }
962
+
963
+ /* If there's nothing left to acknowledge, stop the retransmit
964
+ timer, otherwise reset it to start again */
965
+ if(pcb->unacked == NULL)
966
+ pcb->rtime = -1;
967
+ else
968
+ pcb->rtime = 0;
969
+
970
+ pcb->polltmr = 0;
971
+ } else {
972
+ /* Fix bug bug #21582: out of sequence ACK, didn't really ack anything */
973
+ pcb->acked = 0;
974
+ }
975
+
976
+ /* We go through the ->unsent list to see if any of the segments
977
+ on the list are acknowledged by the ACK. This may seem
978
+ strange since an "unsent" segment shouldn't be acked. The
979
+ rationale is that lwIP puts all outstanding segments on the
980
+ ->unsent list after a retransmission, so these segments may
981
+ in fact have been sent once. */
982
+ while (pcb->unsent != NULL &&
983
+ TCP_SEQ_BETWEEN(ackno, ntohl(pcb->unsent->tcphdr->seqno) +
984
+ TCP_TCPLEN(pcb->unsent), pcb->snd_nxt)) {
985
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: removing %"U32_F":%"U32_F" from pcb->unsent\n",
986
+ ntohl(pcb->unsent->tcphdr->seqno), ntohl(pcb->unsent->tcphdr->seqno) +
987
+ TCP_TCPLEN(pcb->unsent)));
988
+
989
+ next = pcb->unsent;
990
+ pcb->unsent = pcb->unsent->next;
991
+ LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"U16_F" ... ", (u16_t)pcb->snd_queuelen));
992
+ LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p)));
993
+ /* Prevent ACK for FIN to generate a sent event */
994
+ if ((pcb->acked != 0) && ((TCPH_FLAGS(next->tcphdr) & TCP_FIN) != 0)) {
995
+ pcb->acked--;
996
+ }
997
+ pcb->snd_queuelen -= pbuf_clen(next->p);
998
+ tcp_seg_free(next);
999
+ LWIP_DEBUGF(TCP_QLEN_DEBUG, ("%"U16_F" (after freeing unsent)\n", (u16_t)pcb->snd_queuelen));
1000
+ if (pcb->snd_queuelen != 0) {
1001
+ LWIP_ASSERT("tcp_receive: valid queue length",
1002
+ pcb->unacked != NULL || pcb->unsent != NULL);
1003
+ }
1004
+ }
1005
+ /* End of ACK for new data processing. */
1006
+
1007
+ LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_receive: pcb->rttest %"U32_F" rtseq %"U32_F" ackno %"U32_F"\n",
1008
+ pcb->rttest, pcb->rtseq, ackno));
1009
+
1010
+ /* RTT estimation calculations. This is done by checking if the
1011
+ incoming segment acknowledges the segment we use to take a
1012
+ round-trip time measurement. */
1013
+ if (pcb->rttest && TCP_SEQ_LT(pcb->rtseq, ackno)) {
1014
+ /* diff between this shouldn't exceed 32K since this are tcp timer ticks
1015
+ and a round-trip shouldn't be that long... */
1016
+ m = (s16_t)(tcp_ticks - pcb->rttest);
1017
+
1018
+ LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_receive: experienced rtt %"U16_F" ticks (%"U16_F" msec).\n",
1019
+ m, m * TCP_SLOW_INTERVAL));
1020
+
1021
+ /* This is taken directly from VJs original code in his paper */
1022
+ m = m - (pcb->sa >> 3);
1023
+ pcb->sa += m;
1024
+ if (m < 0) {
1025
+ m = -m;
1026
+ }
1027
+ m = m - (pcb->sv >> 2);
1028
+ pcb->sv += m;
1029
+ pcb->rto = (pcb->sa >> 3) + pcb->sv;
1030
+
1031
+ LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_receive: RTO %"U16_F" (%"U16_F" milliseconds)\n",
1032
+ pcb->rto, pcb->rto * TCP_SLOW_INTERVAL));
1033
+
1034
+ pcb->rttest = 0;
1035
+ }
1036
+ }
1037
+
1038
+ /* If the incoming segment contains data, we must process it
1039
+ further. */
1040
+ if (tcplen > 0) {
1041
+ /* This code basically does three things:
1042
+
1043
+ +) If the incoming segment contains data that is the next
1044
+ in-sequence data, this data is passed to the application. This
1045
+ might involve trimming the first edge of the data. The rcv_nxt
1046
+ variable and the advertised window are adjusted.
1047
+
1048
+ +) If the incoming segment has data that is above the next
1049
+ sequence number expected (->rcv_nxt), the segment is placed on
1050
+ the ->ooseq queue. This is done by finding the appropriate
1051
+ place in the ->ooseq queue (which is ordered by sequence
1052
+ number) and trim the segment in both ends if needed. An
1053
+ immediate ACK is sent to indicate that we received an
1054
+ out-of-sequence segment.
1055
+
1056
+ +) Finally, we check if the first segment on the ->ooseq queue
1057
+ now is in sequence (i.e., if rcv_nxt >= ooseq->seqno). If
1058
+ rcv_nxt > ooseq->seqno, we must trim the first edge of the
1059
+ segment on ->ooseq before we adjust rcv_nxt. The data in the
1060
+ segments that are now on sequence are chained onto the
1061
+ incoming segment so that we only need to call the application
1062
+ once.
1063
+ */
1064
+
1065
+ /* First, we check if we must trim the first edge. We have to do
1066
+ this if the sequence number of the incoming segment is less
1067
+ than rcv_nxt, and the sequence number plus the length of the
1068
+ segment is larger than rcv_nxt. */
1069
+ /* if (TCP_SEQ_LT(seqno, pcb->rcv_nxt)){
1070
+ if (TCP_SEQ_LT(pcb->rcv_nxt, seqno + tcplen)) {*/
1071
+ if (TCP_SEQ_BETWEEN(pcb->rcv_nxt, seqno + 1, seqno + tcplen - 1)){
1072
+ /* Trimming the first edge is done by pushing the payload
1073
+ pointer in the pbuf downwards. This is somewhat tricky since
1074
+ we do not want to discard the full contents of the pbuf up to
1075
+ the new starting point of the data since we have to keep the
1076
+ TCP header which is present in the first pbuf in the chain.
1077
+
1078
+ What is done is really quite a nasty hack: the first pbuf in
1079
+ the pbuf chain is pointed to by inseg.p. Since we need to be
1080
+ able to deallocate the whole pbuf, we cannot change this
1081
+ inseg.p pointer to point to any of the later pbufs in the
1082
+ chain. Instead, we point the ->payload pointer in the first
1083
+ pbuf to data in one of the later pbufs. We also set the
1084
+ inseg.data pointer to point to the right place. This way, the
1085
+ ->p pointer will still point to the first pbuf, but the
1086
+ ->p->payload pointer will point to data in another pbuf.
1087
+
1088
+ After we are done with adjusting the pbuf pointers we must
1089
+ adjust the ->data pointer in the seg and the segment
1090
+ length.*/
1091
+
1092
+ off = pcb->rcv_nxt - seqno;
1093
+ p = inseg.p;
1094
+ LWIP_ASSERT("inseg.p != NULL", inseg.p);
1095
+ LWIP_ASSERT("insane offset!", (off < 0x7fff));
1096
+ if (inseg.p->len < off) {
1097
+ LWIP_ASSERT("pbuf too short!", (((s32_t)inseg.p->tot_len) >= off));
1098
+ new_tot_len = (u16_t)(inseg.p->tot_len - off);
1099
+ while (p->len < off) {
1100
+ off -= p->len;
1101
+ /* KJM following line changed (with addition of new_tot_len var)
1102
+ to fix bug #9076
1103
+ inseg.p->tot_len -= p->len; */
1104
+ p->tot_len = new_tot_len;
1105
+ p->len = 0;
1106
+ p = p->next;
1107
+ }
1108
+ if(pbuf_header(p, (s16_t)-off)) {
1109
+ /* Do we need to cope with this failing? Assert for now */
1110
+ LWIP_ASSERT("pbuf_header failed", 0);
1111
+ }
1112
+ } else {
1113
+ if(pbuf_header(inseg.p, (s16_t)-off)) {
1114
+ /* Do we need to cope with this failing? Assert for now */
1115
+ LWIP_ASSERT("pbuf_header failed", 0);
1116
+ }
1117
+ }
1118
+ /* KJM following line changed to use p->payload rather than inseg->p->payload
1119
+ to fix bug #9076 */
1120
+ inseg.dataptr = p->payload;
1121
+ inseg.len -= (u16_t)(pcb->rcv_nxt - seqno);
1122
+ inseg.tcphdr->seqno = seqno = pcb->rcv_nxt;
1123
+ }
1124
+ else {
1125
+ if (TCP_SEQ_LT(seqno, pcb->rcv_nxt)){
1126
+ /* the whole segment is < rcv_nxt */
1127
+ /* must be a duplicate of a packet that has already been correctly handled */
1128
+
1129
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: duplicate seqno %"U32_F"\n", seqno));
1130
+ tcp_ack_now(pcb);
1131
+ }
1132
+ }
1133
+
1134
+ /* The sequence number must be within the window (above rcv_nxt
1135
+ and below rcv_nxt + rcv_wnd) in order to be further
1136
+ processed. */
1137
+ if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt,
1138
+ pcb->rcv_nxt + pcb->rcv_wnd - 1)){
1139
+ if (pcb->rcv_nxt == seqno) {
1140
+ /* The incoming segment is the next in sequence. We check if
1141
+ we have to trim the end of the segment and update rcv_nxt
1142
+ and pass the data to the application. */
1143
+ tcplen = TCP_TCPLEN(&inseg);
1144
+
1145
+ if (tcplen > pcb->rcv_wnd) {
1146
+ LWIP_DEBUGF(TCP_INPUT_DEBUG,
1147
+ ("tcp_receive: other end overran receive window"
1148
+ "seqno %"U32_F" len %"U32_F" right edge %"U32_F"\n",
1149
+ seqno, tcplen, pcb->rcv_nxt + pcb->rcv_wnd));
1150
+ if (TCPH_FLAGS(inseg.tcphdr) & TCP_FIN) {
1151
+ /* Must remove the FIN from the header as we're trimming
1152
+ * that byte of sequence-space from the packet */
1153
+ TCPH_FLAGS_SET(inseg.tcphdr, TCPH_FLAGS(inseg.tcphdr) &~ TCP_FIN);
1154
+ }
1155
+ /* Adjust length of segment to fit in the window. */
1156
+ inseg.len = pcb->rcv_wnd;
1157
+ if (TCPH_FLAGS(inseg.tcphdr) & TCP_SYN) {
1158
+ inseg.len -= 1;
1159
+ }
1160
+ pbuf_realloc(inseg.p, inseg.len);
1161
+ tcplen = TCP_TCPLEN(&inseg);
1162
+ LWIP_ASSERT("tcp_receive: segment not trimmed correctly to rcv_wnd\n",
1163
+ (seqno + tcplen) == (pcb->rcv_nxt + pcb->rcv_wnd));
1164
+ }
1165
+ #if TCP_QUEUE_OOSEQ
1166
+ if (pcb->ooseq != NULL) {
1167
+ if (TCPH_FLAGS(inseg.tcphdr) & TCP_FIN) {
1168
+ LWIP_DEBUGF(TCP_INPUT_DEBUG,
1169
+ ("tcp_receive: received in-order FIN, binning ooseq queue\n"));
1170
+ /* Received in-order FIN means anything that was received
1171
+ * out of order must now have been received in-order, so
1172
+ * bin the ooseq queue
1173
+ * rcv_nxt
1174
+ * . |--ooseq--|
1175
+ * .==seg============|FIN
1176
+ */
1177
+ while (pcb->ooseq != NULL) {
1178
+ struct tcp_seg *old_ooseq = pcb->ooseq;
1179
+ pcb->ooseq = pcb->ooseq->next;
1180
+ tcp_seg_free(old_ooseq);
1181
+ }
1182
+ }
1183
+ else {
1184
+ struct tcp_seg* next = pcb->ooseq;
1185
+ struct tcp_seg *old_seg;
1186
+ /* rcv_nxt
1187
+ * . |--ooseq--|
1188
+ * .==seg============|
1189
+ */
1190
+ while (next &&
1191
+ TCP_SEQ_GEQ(seqno + tcplen,
1192
+ next->tcphdr->seqno + next->len)) {
1193
+ /* inseg doesn't have FIN (already processed) */
1194
+ if (TCPH_FLAGS(next->tcphdr) & TCP_FIN &&
1195
+ (TCPH_FLAGS(inseg.tcphdr) & TCP_SYN) == 0) {
1196
+ TCPH_FLAGS_SET(inseg.tcphdr,
1197
+ TCPH_FLAGS(inseg.tcphdr) | TCP_FIN);
1198
+ tcplen = TCP_TCPLEN(&inseg);
1199
+ }
1200
+ old_seg = next;
1201
+ next = next->next;
1202
+ tcp_seg_free(old_seg);
1203
+ }
1204
+ /* rcv_nxt
1205
+ * . |--ooseq--|
1206
+ * .==seg============|
1207
+ */
1208
+ if (next &&
1209
+ TCP_SEQ_GT(seqno + tcplen,
1210
+ next->tcphdr->seqno)) {
1211
+ /* FIN in inseg already handled by dropping whole ooseq queue */
1212
+ inseg.len = (u16_t)(pcb->ooseq->tcphdr->seqno - seqno);
1213
+ if (TCPH_FLAGS(inseg.tcphdr) & TCP_SYN) {
1214
+ inseg.len -= 1;
1215
+ }
1216
+ pbuf_realloc(inseg.p, inseg.len);
1217
+ tcplen = TCP_TCPLEN(&inseg);
1218
+ LWIP_ASSERT("tcp_receive: segment not trimmed correctly to ooseq queue\n",
1219
+ (seqno + tcplen) == pcb->ooseq->tcphdr->seqno);
1220
+ }
1221
+ pcb->ooseq = next;
1222
+ }
1223
+ }
1224
+ #endif /* TCP_QUEUE_OOSEQ */
1225
+
1226
+ pcb->rcv_nxt = seqno + tcplen;
1227
+
1228
+ /* Update the receiver's (our) window. */
1229
+ LWIP_ASSERT("tcp_receive: tcplen > rcv_wnd\n", pcb->rcv_wnd >= tcplen);
1230
+ pcb->rcv_wnd -= tcplen;
1231
+
1232
+ tcp_update_rcv_ann_wnd(pcb);
1233
+
1234
+ /* If there is data in the segment, we make preparations to
1235
+ pass this up to the application. The ->recv_data variable
1236
+ is used for holding the pbuf that goes to the
1237
+ application. The code for reassembling out-of-sequence data
1238
+ chains its data on this pbuf as well.
1239
+
1240
+ If the segment was a FIN, we set the TF_GOT_FIN flag that will
1241
+ be used to indicate to the application that the remote side has
1242
+ closed its end of the connection. */
1243
+ if (inseg.p->tot_len > 0) {
1244
+ recv_data = inseg.p;
1245
+ /* Since this pbuf now is the responsibility of the
1246
+ application, we delete our reference to it so that we won't
1247
+ (mistakingly) deallocate it. */
1248
+ inseg.p = NULL;
1249
+ }
1250
+ if (TCPH_FLAGS(inseg.tcphdr) & TCP_FIN) {
1251
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: received FIN.\n"));
1252
+ recv_flags |= TF_GOT_FIN;
1253
+ }
1254
+
1255
+ #if TCP_QUEUE_OOSEQ
1256
+ /* We now check if we have segments on the ->ooseq queue that
1257
+ is now in sequence. */
1258
+ while (pcb->ooseq != NULL &&
1259
+ pcb->ooseq->tcphdr->seqno == pcb->rcv_nxt) {
1260
+
1261
+ cseg = pcb->ooseq;
1262
+ seqno = pcb->ooseq->tcphdr->seqno;
1263
+
1264
+ pcb->rcv_nxt += TCP_TCPLEN(cseg);
1265
+ LWIP_ASSERT("tcp_receive: ooseq tcplen > rcv_wnd\n",
1266
+ pcb->rcv_wnd >= TCP_TCPLEN(cseg));
1267
+ pcb->rcv_wnd -= TCP_TCPLEN(cseg);
1268
+
1269
+ tcp_update_rcv_ann_wnd(pcb);
1270
+
1271
+ if (cseg->p->tot_len > 0) {
1272
+ /* Chain this pbuf onto the pbuf that we will pass to
1273
+ the application. */
1274
+ if (recv_data) {
1275
+ pbuf_cat(recv_data, cseg->p);
1276
+ } else {
1277
+ recv_data = cseg->p;
1278
+ }
1279
+ cseg->p = NULL;
1280
+ }
1281
+ if (TCPH_FLAGS(cseg->tcphdr) & TCP_FIN) {
1282
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: dequeued FIN.\n"));
1283
+ recv_flags |= TF_GOT_FIN;
1284
+ if (pcb->state == ESTABLISHED) { /* force passive close or we can move to active close */
1285
+ pcb->state = CLOSE_WAIT;
1286
+ }
1287
+ }
1288
+
1289
+ pcb->ooseq = cseg->next;
1290
+ tcp_seg_free(cseg);
1291
+ }
1292
+ #endif /* TCP_QUEUE_OOSEQ */
1293
+
1294
+
1295
+ /* Acknowledge the segment(s). */
1296
+ tcp_ack(pcb);
1297
+
1298
+ } else {
1299
+ /* We get here if the incoming segment is out-of-sequence. */
1300
+ tcp_send_empty_ack(pcb);
1301
+ #if TCP_QUEUE_OOSEQ
1302
+ /* We queue the segment on the ->ooseq queue. */
1303
+ if (pcb->ooseq == NULL) {
1304
+ pcb->ooseq = tcp_seg_copy(&inseg);
1305
+ } else {
1306
+ /* If the queue is not empty, we walk through the queue and
1307
+ try to find a place where the sequence number of the
1308
+ incoming segment is between the sequence numbers of the
1309
+ previous and the next segment on the ->ooseq queue. That is
1310
+ the place where we put the incoming segment. If needed, we
1311
+ trim the second edges of the previous and the incoming
1312
+ segment so that it will fit into the sequence.
1313
+
1314
+ If the incoming segment has the same sequence number as a
1315
+ segment on the ->ooseq queue, we discard the segment that
1316
+ contains less data. */
1317
+
1318
+ prev = NULL;
1319
+ for(next = pcb->ooseq; next != NULL; next = next->next) {
1320
+ if (seqno == next->tcphdr->seqno) {
1321
+ /* The sequence number of the incoming segment is the
1322
+ same as the sequence number of the segment on
1323
+ ->ooseq. We check the lengths to see which one to
1324
+ discard. */
1325
+ if (inseg.len > next->len) {
1326
+ /* The incoming segment is larger than the old
1327
+ segment. We replace some segments with the new
1328
+ one. */
1329
+ cseg = tcp_seg_copy(&inseg);
1330
+ if (cseg != NULL) {
1331
+ if (prev != NULL) {
1332
+ prev->next = cseg;
1333
+ } else {
1334
+ pcb->ooseq = cseg;
1335
+ }
1336
+ tcp_oos_insert_segment(cseg, next);
1337
+ }
1338
+ break;
1339
+ } else {
1340
+ /* Either the lenghts are the same or the incoming
1341
+ segment was smaller than the old one; in either
1342
+ case, we ditch the incoming segment. */
1343
+ break;
1344
+ }
1345
+ } else {
1346
+ if (prev == NULL) {
1347
+ if (TCP_SEQ_LT(seqno, next->tcphdr->seqno)) {
1348
+ /* The sequence number of the incoming segment is lower
1349
+ than the sequence number of the first segment on the
1350
+ queue. We put the incoming segment first on the
1351
+ queue. */
1352
+ cseg = tcp_seg_copy(&inseg);
1353
+ if (cseg != NULL) {
1354
+ pcb->ooseq = cseg;
1355
+ tcp_oos_insert_segment(cseg, next);
1356
+ }
1357
+ break;
1358
+ }
1359
+ } else {
1360
+ /*if (TCP_SEQ_LT(prev->tcphdr->seqno, seqno) &&
1361
+ TCP_SEQ_LT(seqno, next->tcphdr->seqno)) {*/
1362
+ if (TCP_SEQ_BETWEEN(seqno, prev->tcphdr->seqno+1, next->tcphdr->seqno-1)) {
1363
+ /* The sequence number of the incoming segment is in
1364
+ between the sequence numbers of the previous and
1365
+ the next segment on ->ooseq. We trim trim the previous
1366
+ segment, delete next segments that included in received segment
1367
+ and trim received, if needed. */
1368
+ cseg = tcp_seg_copy(&inseg);
1369
+ if (cseg != NULL) {
1370
+ if (TCP_SEQ_GT(prev->tcphdr->seqno + prev->len, seqno)) {
1371
+ /* We need to trim the prev segment. */
1372
+ prev->len = (u16_t)(seqno - prev->tcphdr->seqno);
1373
+ pbuf_realloc(prev->p, prev->len);
1374
+ }
1375
+ prev->next = cseg;
1376
+ tcp_oos_insert_segment(cseg, next);
1377
+ }
1378
+ break;
1379
+ }
1380
+ }
1381
+ /* If the "next" segment is the last segment on the
1382
+ ooseq queue, we add the incoming segment to the end
1383
+ of the list. */
1384
+ if (next->next == NULL &&
1385
+ TCP_SEQ_GT(seqno, next->tcphdr->seqno)) {
1386
+ if (TCPH_FLAGS(next->tcphdr) & TCP_FIN) {
1387
+ /* segment "next" already contains all data */
1388
+ break;
1389
+ }
1390
+ next->next = tcp_seg_copy(&inseg);
1391
+ if (next->next != NULL) {
1392
+ if (TCP_SEQ_GT(next->tcphdr->seqno + next->len, seqno)) {
1393
+ /* We need to trim the last segment. */
1394
+ next->len = (u16_t)(seqno - next->tcphdr->seqno);
1395
+ pbuf_realloc(next->p, next->len);
1396
+ }
1397
+ }
1398
+ break;
1399
+ }
1400
+ }
1401
+ prev = next;
1402
+ }
1403
+ }
1404
+ #endif /* TCP_QUEUE_OOSEQ */
1405
+
1406
+ }
1407
+ } else {
1408
+ /* The incoming segment is not withing the window. */
1409
+ tcp_send_empty_ack(pcb);
1410
+ }
1411
+ } else {
1412
+ /* Segments with length 0 is taken care of here. Segments that
1413
+ fall out of the window are ACKed. */
1414
+ /*if (TCP_SEQ_GT(pcb->rcv_nxt, seqno) ||
1415
+ TCP_SEQ_GEQ(seqno, pcb->rcv_nxt + pcb->rcv_wnd)) {*/
1416
+ if(!TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt + pcb->rcv_wnd-1)){
1417
+ tcp_ack_now(pcb);
1418
+ }
1419
+ }
1420
+ }
1421
+
1422
+ /**
1423
+ * Parses the options contained in the incoming segment.
1424
+ *
1425
+ * Called from tcp_listen_input() and tcp_process().
1426
+ * Currently, only the MSS option is supported!
1427
+ *
1428
+ * @param pcb the tcp_pcb for which a segment arrived
1429
+ */
1430
+ static void
1431
+ tcp_parseopt(struct tcp_pcb *pcb)
1432
+ {
1433
+ u16_t c, max_c;
1434
+ u16_t mss;
1435
+ u8_t *opts, opt;
1436
+ #if LWIP_TCP_TIMESTAMPS
1437
+ u32_t tsval;
1438
+ #endif
1439
+
1440
+ opts = (u8_t *)tcphdr + TCP_HLEN;
1441
+
1442
+ /* Parse the TCP MSS option, if present. */
1443
+ if(TCPH_HDRLEN(tcphdr) > 0x5) {
1444
+ max_c = (TCPH_HDRLEN(tcphdr) - 5) << 2;
1445
+ for (c = 0; c < max_c; ) {
1446
+ opt = opts[c];
1447
+ switch (opt) {
1448
+ case 0x00:
1449
+ /* End of options. */
1450
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: EOL\n"));
1451
+ return;
1452
+ case 0x01:
1453
+ /* NOP option. */
1454
+ ++c;
1455
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: NOP\n"));
1456
+ break;
1457
+ case 0x02:
1458
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: MSS\n"));
1459
+ if (opts[c + 1] != 0x04 || c + 0x04 > max_c) {
1460
+ /* Bad length */
1461
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n"));
1462
+ return;
1463
+ }
1464
+ /* An MSS option with the right option length. */
1465
+ mss = (opts[c + 2] << 8) | opts[c + 3];
1466
+ /* Limit the mss to the configured TCP_MSS and prevent division by zero */
1467
+ pcb->mss = ((mss > TCP_MSS) || (mss == 0)) ? TCP_MSS : mss;
1468
+ /* Advance to next option */
1469
+ c += 0x04;
1470
+ break;
1471
+ #if LWIP_TCP_TIMESTAMPS
1472
+ case 0x08:
1473
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: TS\n"));
1474
+ if (opts[c + 1] != 0x0A || c + 0x0A > max_c) {
1475
+ /* Bad length */
1476
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n"));
1477
+ return;
1478
+ }
1479
+ /* TCP timestamp option with valid length */
1480
+ tsval = (opts[c+2]) | (opts[c+3] << 8) |
1481
+ (opts[c+4] << 16) | (opts[c+5] << 24);
1482
+ if (flags & TCP_SYN) {
1483
+ pcb->ts_recent = ntohl(tsval);
1484
+ pcb->flags |= TF_TIMESTAMP;
1485
+ } else if (TCP_SEQ_BETWEEN(pcb->ts_lastacksent, seqno, seqno+tcplen)) {
1486
+ pcb->ts_recent = ntohl(tsval);
1487
+ }
1488
+ /* Advance to next option */
1489
+ c += 0x0A;
1490
+ break;
1491
+ #endif
1492
+ default:
1493
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: other\n"));
1494
+ if (opts[c + 1] == 0) {
1495
+ LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n"));
1496
+ /* If the length field is zero, the options are malformed
1497
+ and we don't process them further. */
1498
+ return;
1499
+ }
1500
+ /* All other options have a length field, so that we easily
1501
+ can skip past them. */
1502
+ c += opts[c + 1];
1503
+ }
1504
+ }
1505
+ }
1506
+ }
1507
+
1508
+ #endif /* LWIP_TCP */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp_out.c ADDED
@@ -0,0 +1,1071 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ * Transmission Control Protocol, outgoing traffic
6
+ *
7
+ * The output functions of TCP.
8
+ *
9
+ */
10
+
11
+ /*
12
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
13
+ * All rights reserved.
14
+ *
15
+ * Redistribution and use in source and binary forms, with or without modification,
16
+ * are permitted provided that the following conditions are met:
17
+ *
18
+ * 1. Redistributions of source code must retain the above copyright notice,
19
+ * this list of conditions and the following disclaimer.
20
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
21
+ * this list of conditions and the following disclaimer in the documentation
22
+ * and/or other materials provided with the distribution.
23
+ * 3. The name of the author may not be used to endorse or promote products
24
+ * derived from this software without specific prior written permission.
25
+ *
26
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
29
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
31
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35
+ * OF SUCH DAMAGE.
36
+ *
37
+ * This file is part of the lwIP TCP/IP stack.
38
+ *
39
+ * Author: Adam Dunkels <adam@sics.se>
40
+ *
41
+ */
42
+
43
+ #include "lwip/opt.h"
44
+
45
+ #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
46
+
47
+ #include "lwip/tcp.h"
48
+ #include "lwip/def.h"
49
+ #include "lwip/mem.h"
50
+ #include "lwip/memp.h"
51
+ #include "lwip/sys.h"
52
+ #include "lwip/ip_addr.h"
53
+ #include "lwip/netif.h"
54
+ #include "lwip/inet.h"
55
+ #include "lwip/inet_chksum.h"
56
+ #include "lwip/stats.h"
57
+ #include "lwip/snmp.h"
58
+
59
+ #include <string.h>
60
+ #define _TEST_HD_
61
+ /* Forward declarations.*/
62
+ static void tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb);
63
+
64
+ static struct tcp_hdr *
65
+ tcp_output_set_header(struct tcp_pcb *pcb, struct pbuf *p, int optlen,
66
+ u32_t seqno_be /* already in network byte order */)
67
+ {
68
+ struct tcp_hdr *tcphdr = p->payload;
69
+ tcphdr->src = htons(pcb->local_port);
70
+ tcphdr->dest = htons(pcb->remote_port);
71
+ tcphdr->seqno = seqno_be;
72
+ tcphdr->ackno = htonl(pcb->rcv_nxt);
73
+ TCPH_FLAGS_SET(tcphdr, TCP_ACK);
74
+ tcphdr->wnd = htons(pcb->rcv_ann_wnd);
75
+ tcphdr->urgp = 0;
76
+ TCPH_HDRLEN_SET(tcphdr, (5 + optlen / 4));
77
+ tcphdr->chksum = 0;
78
+
79
+ /* If we're sending a packet, update the announced right window edge */
80
+ pcb->rcv_ann_right_edge = pcb->rcv_nxt + pcb->rcv_ann_wnd;
81
+
82
+ return tcphdr;
83
+ }
84
+
85
+ /**
86
+ * Called by tcp_close() to send a segment including flags but not data.
87
+ *
88
+ * @param pcb the tcp_pcb over which to send a segment
89
+ * @param flags the flags to set in the segment header
90
+ * @return ERR_OK if sent, another err_t otherwise
91
+ */
92
+ err_t
93
+ tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags)
94
+ {
95
+ /* no data, no length, flags, copy=1, no optdata */
96
+ return tcp_enqueue(pcb, NULL, 0, flags, TCP_WRITE_FLAG_COPY, 0);
97
+ }
98
+
99
+ /**
100
+ * Write data for sending (but does not send it immediately).
101
+ *
102
+ * It waits in the expectation of more data being sent soon (as
103
+ * it can send them more efficiently by combining them together).
104
+ * To prompt the system to send data now, call tcp_output() after
105
+ * calling tcp_write().
106
+ *
107
+ * @param pcb Protocol control block of the TCP connection to enqueue data for.
108
+ * @param data pointer to the data to send
109
+ * @param len length (in bytes) of the data to send
110
+ * @param apiflags combination of following flags :
111
+ * - TCP_WRITE_FLAG_COPY (0x01) data will be copied into memory belonging to the stack
112
+ * - TCP_WRITE_FLAG_MORE (0x02) for TCP connection, PSH flag will be set on last segment sent,
113
+ * @return ERR_OK if enqueued, another err_t on error
114
+ *
115
+ * @see tcp_write()
116
+ */
117
+ err_t
118
+ tcp_write(struct tcp_pcb *pcb, const void *data, u16_t len, u8_t apiflags)
119
+ {
120
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_write(pcb=%p, data=%p, len=%"U16_F", apiflags=%"U16_F")\n", (void *)pcb,
121
+ data, len, (u16_t)apiflags));
122
+ /* connection is in valid state for data transmission? */
123
+ if (pcb->state == ESTABLISHED ||
124
+ pcb->state == CLOSE_WAIT ||
125
+ pcb->state == SYN_SENT ||
126
+ pcb->state == SYN_RCVD) {
127
+ if (len > 0) {
128
+ #if LWIP_TCP_TIMESTAMPS
129
+ return tcp_enqueue(pcb, (void *)data, len, 0, apiflags,
130
+ pcb->flags & TF_TIMESTAMP ? TF_SEG_OPTS_TS : 0);
131
+ #else
132
+ return tcp_enqueue(pcb, (void *)data, len, 0, apiflags, 0);
133
+ #endif
134
+ }
135
+ return ERR_OK;
136
+ } else {
137
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_STATE | LWIP_DBG_LEVEL_SEVERE, ("tcp_write() called in invalid state\n"));
138
+ return ERR_CONN;
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Enqueue data and/or TCP options for transmission
144
+ *
145
+ * Called by tcp_connect(), tcp_listen_input(), tcp_send_ctrl() and tcp_write().
146
+ *
147
+ * @param pcb Protocol control block for the TCP connection to enqueue data for.
148
+ * @param arg Pointer to the data to be enqueued for sending.
149
+ * @param len Data length in bytes
150
+ * @param flags tcp header flags to set in the outgoing segment
151
+ * @param apiflags combination of following flags :
152
+ * - TCP_WRITE_FLAG_COPY (0x01) data will be copied into memory belonging to the stack
153
+ * - TCP_WRITE_FLAG_MORE (0x02) for TCP connection, PSH flag will be set on last segment sent,
154
+ * @param optflags options to include in segment later on (see definition of struct tcp_seg)
155
+ */
156
+ err_t
157
+ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
158
+ u8_t flags, u8_t apiflags, u8_t optflags)
159
+ {
160
+ struct pbuf *p;
161
+ struct tcp_seg *seg, *useg, *queue;
162
+ u32_t seqno;
163
+ u16_t left, seglen;
164
+ void *ptr;
165
+ u16_t queuelen;
166
+ u8_t optlen;
167
+
168
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG,
169
+ ("tcp_enqueue(pcb=%p, arg=%p, len=%"U16_F", flags=%"X16_F", apiflags=%"U16_F")\n",
170
+ (void *)pcb, arg, len, (u16_t)flags, (u16_t)apiflags));
171
+ LWIP_ERROR("tcp_enqueue: packet needs payload, options, or SYN/FIN (programmer violates API)",
172
+ ((len != 0) || (optflags != 0) || ((flags & (TCP_SYN | TCP_FIN)) != 0)),
173
+ return ERR_ARG;);
174
+ LWIP_ERROR("tcp_enqueue: len != 0 || arg == NULL (programmer violates API)",
175
+ ((len != 0) || (arg == NULL)), return ERR_ARG;);
176
+
177
+ /* fail on too much data */
178
+ if (len > pcb->snd_buf) {
179
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_WARNING,
180
+ ("tcp_enqueue: too much data (len=%"U16_F" > snd_buf=%"U16_F")\n", len, pcb->snd_buf));
181
+ pcb->flags |= TF_NAGLEMEMERR;
182
+ return ERR_MEM;
183
+ }
184
+ left = len;
185
+ ptr = arg;
186
+
187
+ optlen = LWIP_TCP_OPT_LENGTH(optflags);
188
+
189
+ /* seqno will be the sequence number of the first segment enqueued
190
+ * by the call to this function. */
191
+ seqno = pcb->snd_lbb;
192
+
193
+ LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue: queuelen: %"U16_F"\n", (u16_t)pcb->snd_queuelen));
194
+
195
+ /* If total number of pbufs on the unsent/unacked queues exceeds the
196
+ * configured maximum, return an error */
197
+ queuelen = pcb->snd_queuelen;
198
+ /* check for configured max queuelen and possible overflow */
199
+ if ((queuelen >= TCP_SND_QUEUELEN) || (queuelen > TCP_SNDQUEUELEN_OVERFLOW)) {
200
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_WARNING,
201
+ ("tcp_enqueue: too long queue %"U16_F" (max %"U16_F")\n", queuelen, TCP_SND_QUEUELEN));
202
+ TCP_STATS_INC(tcp.memerr);
203
+ pcb->flags |= TF_NAGLEMEMERR;
204
+ return ERR_MEM;
205
+ }
206
+ if (queuelen != 0) {
207
+ LWIP_ASSERT("tcp_enqueue: pbufs on queue => at least one queue non-empty",
208
+ pcb->unacked != NULL || pcb->unsent != NULL);
209
+ } else {
210
+ LWIP_ASSERT("tcp_enqueue: no pbufs on queue => both queues empty",
211
+ pcb->unacked == NULL && pcb->unsent == NULL);
212
+ }
213
+
214
+ /* First, break up the data into segments and tuck them together in
215
+ * the local "queue" variable. */
216
+ useg = queue = seg = NULL;
217
+ seglen = 0;
218
+ while (queue == NULL || left > 0) {
219
+ /* The segment length (including options) should be at most the MSS */
220
+ seglen = left > (pcb->mss - optlen) ? (pcb->mss - optlen) : left;
221
+
222
+ /* Allocate memory for tcp_seg, and fill in fields. */
223
+ seg = memp_malloc(MEMP_TCP_SEG);
224
+ if (seg == NULL) {
225
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
226
+ ("tcp_enqueue: could not allocate memory for tcp_seg\n"));
227
+ goto memerr;
228
+ }
229
+ seg->next = NULL;
230
+ seg->p = NULL;
231
+
232
+ /* first segment of to-be-queued data? */
233
+ if (queue == NULL) {
234
+ queue = seg;
235
+ }
236
+ /* subsequent segments of to-be-queued data */
237
+ else {
238
+ /* Attach the segment to the end of the queued segments */
239
+ LWIP_ASSERT("useg != NULL", useg != NULL);
240
+ useg->next = seg;
241
+ }
242
+ /* remember last segment of to-be-queued data for next iteration */
243
+ useg = seg;
244
+
245
+ /* If copy is set, memory should be allocated
246
+ * and data copied into pbuf, otherwise data comes from
247
+ * ROM or other static memory, and need not be copied. */
248
+ if (apiflags & TCP_WRITE_FLAG_COPY) {
249
+ if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, seglen + optlen, PBUF_RAM)) == NULL) {
250
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
251
+ ("tcp_enqueue : could not allocate memory for pbuf copy size %"U16_F"\n", seglen));
252
+ goto memerr;
253
+ }
254
+ LWIP_ASSERT("check that first pbuf can hold the complete seglen",
255
+ (seg->p->len >= seglen + optlen));
256
+ queuelen += pbuf_clen(seg->p);
257
+ if (arg != NULL) {
258
+ MEMCPY((char *)seg->p->payload + optlen, ptr, seglen);
259
+ }
260
+ seg->dataptr = seg->p->payload;
261
+ }
262
+ /* do not copy data */
263
+ else {
264
+ /* First, allocate a pbuf for the headers. */
265
+ if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, optlen, PBUF_RAM)) == NULL) {
266
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
267
+ ("tcp_enqueue: could not allocate memory for header pbuf\n"));
268
+ goto memerr;
269
+ }
270
+ queuelen += pbuf_clen(seg->p);
271
+
272
+ /* Second, allocate a pbuf for holding the data.
273
+ * since the referenced data is available at least until it is sent out on the
274
+ * link (as it has to be ACKed by the remote party) we can safely use PBUF_ROM
275
+ * instead of PBUF_REF here.
276
+ */
277
+ if (left > 0) {
278
+ if ((p = pbuf_alloc(PBUF_RAW, seglen, PBUF_ROM)) == NULL) {
279
+ /* If allocation fails, we have to deallocate the header pbuf as well. */
280
+ pbuf_free(seg->p);
281
+ seg->p = NULL;
282
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
283
+ ("tcp_enqueue: could not allocate memory for zero-copy pbuf\n"));
284
+ goto memerr;
285
+ }
286
+ ++queuelen;
287
+ /* reference the non-volatile payload data */
288
+ p->payload = ptr;
289
+ seg->dataptr = ptr;
290
+
291
+ /* Concatenate the headers and data pbufs together. */
292
+ pbuf_cat(seg->p/*header*/, p/*data*/);
293
+ p = NULL;
294
+ }
295
+ }
296
+
297
+ /* Now that there are more segments queued, we check again if the
298
+ length of the queue exceeds the configured maximum or overflows. */
299
+ if ((queuelen > TCP_SND_QUEUELEN) || (queuelen > TCP_SNDQUEUELEN_OVERFLOW)) {
300
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
301
+ ("tcp_enqueue: queue too long %"U16_F" (%"U16_F")\n", queuelen, TCP_SND_QUEUELEN));
302
+ goto memerr;
303
+ }
304
+
305
+ seg->len = seglen;
306
+
307
+ /* build TCP header */
308
+ if (pbuf_header(seg->p, TCP_HLEN)) {
309
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("tcp_enqueue: no room for TCP header in pbuf.\n"));
310
+ TCP_STATS_INC(tcp.err);
311
+ goto memerr;
312
+ }
313
+ seg->tcphdr = seg->p->payload;
314
+ seg->tcphdr->src = htons(pcb->local_port);
315
+ seg->tcphdr->dest = htons(pcb->remote_port);
316
+ seg->tcphdr->seqno = htonl(seqno);
317
+ seg->tcphdr->urgp = 0;
318
+ TCPH_FLAGS_SET(seg->tcphdr, flags);
319
+ /* don't fill in tcphdr->ackno and tcphdr->wnd until later */
320
+
321
+ seg->flags = optflags;
322
+
323
+ /* Set the length of the header */
324
+ TCPH_HDRLEN_SET(seg->tcphdr, (5 + optlen / 4));
325
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_TRACE, ("tcp_enqueue: queueing %"U32_F":%"U32_F" (0x%"X16_F")\n",
326
+ ntohl(seg->tcphdr->seqno),
327
+ ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg),
328
+ (u16_t)flags));
329
+
330
+ left -= seglen;
331
+ seqno += seglen;
332
+ ptr = (void *)((u8_t *)ptr + seglen);
333
+ }
334
+
335
+ /* Now that the data to be enqueued has been broken up into TCP
336
+ segments in the queue variable, we add them to the end of the
337
+ pcb->unsent queue. */
338
+ if (pcb->unsent == NULL) {
339
+ useg = NULL;
340
+ }
341
+ else {
342
+ for (useg = pcb->unsent; useg->next != NULL; useg = useg->next);
343
+ }
344
+ /* { useg is last segment on the unsent queue, NULL if list is empty } */
345
+
346
+ /* If there is room in the last pbuf on the unsent queue,
347
+ chain the first pbuf on the queue together with that. */
348
+ if (useg != NULL &&
349
+ TCP_TCPLEN(useg) != 0 &&
350
+ !(TCPH_FLAGS(useg->tcphdr) & (TCP_SYN | TCP_FIN)) &&
351
+ (!(flags & (TCP_SYN | TCP_FIN)) || (flags == TCP_FIN)) &&
352
+ /* fit within max seg size */
353
+ (useg->len + queue->len <= pcb->mss) &&
354
+ /* only concatenate segments with the same options */
355
+ (useg->flags == queue->flags) &&
356
+ /* segments are consecutive */
357
+ (ntohl(useg->tcphdr->seqno) + useg->len == ntohl(queue->tcphdr->seqno)) ) {
358
+ /* Remove TCP header from first segment of our to-be-queued list */
359
+ if(pbuf_header(queue->p, -(TCP_HLEN + optlen))) {
360
+ /* Can we cope with this failing? Just assert for now */
361
+ LWIP_ASSERT("pbuf_header failed\n", 0);
362
+ TCP_STATS_INC(tcp.err);
363
+ goto memerr;
364
+ }
365
+ if (queue->p->len == 0) {
366
+ /* free the first (header-only) pbuf if it is now empty (contained only headers) */
367
+ struct pbuf *old_q = queue->p;
368
+ queue->p = queue->p->next;
369
+ old_q->next = NULL;
370
+ queuelen--;
371
+ pbuf_free(old_q);
372
+ }
373
+ if (flags & TCP_FIN) {
374
+ /* the new segment contains only FIN, no data -> put the FIN into the last segment */
375
+ LWIP_ASSERT("FIN enqueued together with data", queue->p == NULL && queue->len == 0);
376
+ TCPH_SET_FLAG(useg->tcphdr, TCP_FIN);
377
+ } else {
378
+ LWIP_ASSERT("zero-length pbuf", (queue->p != NULL) && (queue->p->len > 0));
379
+ pbuf_cat(useg->p, queue->p);
380
+ useg->len += queue->len;
381
+ useg->next = queue->next;
382
+ }
383
+
384
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("tcp_enqueue: chaining segments, new len %"U16_F"\n", useg->len));
385
+ if (seg == queue) {
386
+ seg = useg;
387
+ seglen = useg->len;
388
+ }
389
+ memp_free(MEMP_TCP_SEG, queue);
390
+ }
391
+ else {
392
+ /* empty list */
393
+ if (useg == NULL) {
394
+ /* initialize list with this segment */
395
+ pcb->unsent = queue;
396
+ }
397
+ /* enqueue segment */
398
+ else {
399
+ useg->next = queue;
400
+ }
401
+ }
402
+ if ((flags & TCP_SYN) || (flags & TCP_FIN)) {
403
+ ++len;
404
+ }
405
+ if (flags & TCP_FIN) {
406
+ pcb->flags |= TF_FIN;
407
+ }
408
+ pcb->snd_lbb += len;
409
+
410
+ pcb->snd_buf -= len;
411
+
412
+ /* update number of segments on the queues */
413
+ pcb->snd_queuelen = queuelen;
414
+ LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue: %"S16_F" (after enqueued)\n", pcb->snd_queuelen));
415
+ if (pcb->snd_queuelen != 0) {
416
+ LWIP_ASSERT("tcp_enqueue: valid queue length",
417
+ pcb->unacked != NULL || pcb->unsent != NULL);
418
+ }
419
+
420
+ /* Set the PSH flag in the last segment that we enqueued, but only
421
+ if the segment has data (indicated by seglen > 0). */
422
+ if (seg != NULL && seglen > 0 && seg->tcphdr != NULL && ((apiflags & TCP_WRITE_FLAG_MORE)==0)) {
423
+ TCPH_SET_FLAG(seg->tcphdr, TCP_PSH);
424
+ }
425
+
426
+ return ERR_OK;
427
+ memerr:
428
+ pcb->flags |= TF_NAGLEMEMERR;
429
+ TCP_STATS_INC(tcp.memerr);
430
+
431
+ if (queue != NULL) {
432
+ tcp_segs_free(queue);
433
+ }
434
+ if (pcb->snd_queuelen != 0) {
435
+ LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
436
+ pcb->unsent != NULL);
437
+ }
438
+ LWIP_DEBUGF(TCP_QLEN_DEBUG | LWIP_DBG_STATE, ("tcp_enqueue: %"S16_F" (with mem err)\n", pcb->snd_queuelen));
439
+ return ERR_MEM;
440
+ }
441
+
442
+
443
+ #if LWIP_TCP_TIMESTAMPS
444
+ /* Build a timestamp option (12 bytes long) at the specified options pointer)
445
+ *
446
+ * @param pcb tcp_pcb
447
+ * @param opts option pointer where to store the timestamp option
448
+ */
449
+ static void
450
+ tcp_build_timestamp_option(struct tcp_pcb *pcb, u32_t *opts)
451
+ {
452
+ /* Pad with two NOP options to make everything nicely aligned */
453
+ opts[0] = htonl(0x0101080A);
454
+ opts[1] = htonl(sys_now());
455
+ opts[2] = htonl(pcb->ts_recent);
456
+ }
457
+ #endif
458
+
459
+ /** Send an ACK without data.
460
+ *
461
+ * @param pcb Protocol control block for the TCP connection to send the ACK
462
+ */
463
+ err_t
464
+ tcp_send_empty_ack(struct tcp_pcb *pcb)
465
+ {
466
+ struct pbuf *p;
467
+ struct tcp_hdr *tcphdr;
468
+ u8_t optlen = 0;
469
+
470
+ #if LWIP_TCP_TIMESTAMPS
471
+ if (pcb->flags & TF_TIMESTAMP) {
472
+ optlen = LWIP_TCP_OPT_LENGTH(TF_SEG_OPTS_TS);
473
+ }
474
+ #endif
475
+ p = pbuf_alloc(PBUF_IP, TCP_HLEN + optlen, PBUF_RAM);
476
+ if (p == NULL) {
477
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: (ACK) could not allocate pbuf\n"));
478
+ return ERR_BUF;
479
+ }
480
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG,
481
+ ("tcp_output: sending ACK for %"U32_F"\n", pcb->rcv_nxt));
482
+ /* remove ACK flags from the PCB, as we send an empty ACK now */
483
+ pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
484
+
485
+ tcphdr = tcp_output_set_header(pcb, p, optlen, htonl(pcb->snd_nxt));
486
+
487
+ /* NB. MSS option is only sent on SYNs, so ignore it here */
488
+ #if LWIP_TCP_TIMESTAMPS
489
+ pcb->ts_lastacksent = pcb->rcv_nxt;
490
+
491
+ if (pcb->flags & TF_TIMESTAMP) {
492
+ tcp_build_timestamp_option(pcb, (u32_t *)(tcphdr + 1));
493
+ }
494
+ #endif
495
+
496
+ #if CHECKSUM_GEN_TCP
497
+ tcphdr->chksum = inet_chksum_pseudo(p, &(pcb->local_ip), &(pcb->remote_ip),
498
+ IP_PROTO_TCP, p->tot_len);
499
+ #endif
500
+ #if LWIP_NETIF_HWADDRHINT
501
+ ip_output_hinted(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
502
+ IP_PROTO_TCP, &(pcb->addr_hint));
503
+ #else /* LWIP_NETIF_HWADDRHINT*/
504
+ ip_output(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
505
+ IP_PROTO_TCP);
506
+ #endif /* LWIP_NETIF_HWADDRHINT*/
507
+ pbuf_free(p);
508
+
509
+ return ERR_OK;
510
+ }
511
+
512
+ /**
513
+ * Find out what we can send and send it
514
+ *
515
+ * @param pcb Protocol control block for the TCP connection to send data
516
+ * @return ERR_OK if data has been sent or nothing to send
517
+ * another err_t on error
518
+ */
519
+ err_t
520
+ tcp_output(struct tcp_pcb *pcb)
521
+ {
522
+ struct tcp_seg *seg, *useg;
523
+ u32_t wnd, snd_nxt;
524
+ #if TCP_CWND_DEBUG
525
+ s16_t i = 0;
526
+ #endif /* TCP_CWND_DEBUG */
527
+
528
+ /* First, check if we are invoked by the TCP input processing
529
+ code. If so, we do not output anything. Instead, we rely on the
530
+ input processing code to call us when input processing is done
531
+ with. */
532
+ if (tcp_input_pcb == pcb) {
533
+ return ERR_OK;
534
+ }
535
+
536
+ wnd = LWIP_MIN(pcb->snd_wnd, pcb->cwnd);
537
+
538
+ seg = pcb->unsent;
539
+
540
+ /* If the TF_ACK_NOW flag is set and no data will be sent (either
541
+ * because the ->unsent queue is empty or because the window does
542
+ * not allow it), construct an empty ACK segment and send it.
543
+ *
544
+ * If data is to be sent, we will just piggyback the ACK (see below).
545
+ */
546
+ if (pcb->flags & TF_ACK_NOW &&
547
+ (seg == NULL ||
548
+ ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd)) {
549
+ return tcp_send_empty_ack(pcb);
550
+ }
551
+
552
+ /* useg should point to last segment on unacked queue */
553
+ useg = pcb->unacked;
554
+ if (useg != NULL) {
555
+ for (; useg->next != NULL; useg = useg->next);
556
+ }
557
+
558
+ #if TCP_OUTPUT_DEBUG
559
+ if (seg == NULL) {
560
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: nothing to send (%p)\n",
561
+ (void*)pcb->unsent));
562
+ }
563
+ #endif /* TCP_OUTPUT_DEBUG */
564
+ #if TCP_CWND_DEBUG
565
+ if (seg == NULL) {
566
+ LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"U16_F
567
+ ", cwnd %"U16_F", wnd %"U32_F
568
+ ", seg == NULL, ack %"U32_F"\n",
569
+ pcb->snd_wnd, pcb->cwnd, wnd, pcb->lastack));
570
+ } else {
571
+ LWIP_DEBUGF(TCP_CWND_DEBUG,
572
+ ("tcp_output: snd_wnd %"U16_F", cwnd %"U16_F", wnd %"U32_F
573
+ ", effwnd %"U32_F", seq %"U32_F", ack %"U32_F"\n",
574
+ pcb->snd_wnd, pcb->cwnd, wnd,
575
+ ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len,
576
+ ntohl(seg->tcphdr->seqno), pcb->lastack));
577
+ }
578
+ #endif /* TCP_CWND_DEBUG */
579
+ /* data available and window allows it to be sent? */
580
+ while (seg != NULL &&
581
+ ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len <= wnd) {
582
+ LWIP_ASSERT("RST not expected here!",
583
+ (TCPH_FLAGS(seg->tcphdr) & TCP_RST) == 0);
584
+ /* Stop sending if the nagle algorithm would prevent it
585
+ * Don't stop:
586
+ * - if tcp_enqueue had a memory error before (prevent delayed ACK timeout) or
587
+ * - if FIN was already enqueued for this PCB (SYN is always alone in a segment -
588
+ * either seg->next != NULL or pcb->unacked == NULL;
589
+ * RST is no sent using tcp_enqueue/tcp_output.
590
+ */
591
+ if((tcp_do_output_nagle(pcb) == 0) &&
592
+ ((pcb->flags & (TF_NAGLEMEMERR | TF_FIN)) == 0)){
593
+ break;
594
+ }
595
+ #if TCP_CWND_DEBUG
596
+ LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"U16_F", cwnd %"U16_F", wnd %"U32_F", effwnd %"U32_F", seq %"U32_F", ack %"U32_F", i %"S16_F"\n",
597
+ pcb->snd_wnd, pcb->cwnd, wnd,
598
+ ntohl(seg->tcphdr->seqno) + seg->len -
599
+ pcb->lastack,
600
+ ntohl(seg->tcphdr->seqno), pcb->lastack, i));
601
+ ++i;
602
+ #endif /* TCP_CWND_DEBUG */
603
+
604
+ pcb->unsent = seg->next;
605
+
606
+ if (pcb->state != SYN_SENT) {
607
+ TCPH_SET_FLAG(seg->tcphdr, TCP_ACK);
608
+ pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
609
+ }
610
+
611
+ tcp_output_segment(seg, pcb);
612
+ snd_nxt = ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg);
613
+ if (TCP_SEQ_LT(pcb->snd_nxt, snd_nxt)) {
614
+ pcb->snd_nxt = snd_nxt;
615
+ }
616
+ /* put segment on unacknowledged list if length > 0 */
617
+ if (TCP_TCPLEN(seg) > 0) {
618
+ seg->next = NULL;
619
+ /* unacked list is empty? */
620
+ if (pcb->unacked == NULL) {
621
+ pcb->unacked = seg;
622
+ useg = seg;
623
+ /* unacked list is not empty? */
624
+ } else {
625
+ /* In the case of fast retransmit, the packet should not go to the tail
626
+ * of the unacked queue, but rather somewhere before it. We need to check for
627
+ * this case. -STJ Jul 27, 2004 */
628
+ if (TCP_SEQ_LT(ntohl(seg->tcphdr->seqno), ntohl(useg->tcphdr->seqno))){
629
+ /* add segment to before tail of unacked list, keeping the list sorted */
630
+ struct tcp_seg **cur_seg = &(pcb->unacked);
631
+ while (*cur_seg &&
632
+ TCP_SEQ_LT(ntohl((*cur_seg)->tcphdr->seqno), ntohl(seg->tcphdr->seqno))) {
633
+ cur_seg = &((*cur_seg)->next );
634
+ }
635
+ seg->next = (*cur_seg);
636
+ (*cur_seg) = seg;
637
+ } else {
638
+ /* add segment to tail of unacked list */
639
+ useg->next = seg;
640
+ useg = useg->next;
641
+ }
642
+ }
643
+ /* do not queue empty segments on the unacked list */
644
+ } else {
645
+ tcp_seg_free(seg);
646
+ }
647
+ seg = pcb->unsent;
648
+ }
649
+
650
+ if (seg != NULL && pcb->persist_backoff == 0 &&
651
+ ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > pcb->snd_wnd) {
652
+ /* prepare for persist timer */
653
+ pcb->persist_cnt = 0;
654
+ pcb->persist_backoff = 1;
655
+ }
656
+
657
+ pcb->flags &= ~TF_NAGLEMEMERR;
658
+ return ERR_OK;
659
+ }
660
+
661
+ /**
662
+ * Called by tcp_output() to actually send a TCP segment over IP.
663
+ *
664
+ * @param seg the tcp_seg to send
665
+ * @param pcb the tcp_pcb for the TCP connection used to send the segment
666
+ */
667
+ static void
668
+ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
669
+ {
670
+ u16_t len;
671
+ struct netif *netif;
672
+ u32_t *opts;
673
+
674
+ /** @bug Exclude retransmitted segments from this count. */
675
+ snmp_inc_tcpoutsegs();
676
+
677
+ /* The TCP header has already been constructed, but the ackno and
678
+ wnd fields remain. */
679
+ seg->tcphdr->ackno = htonl(pcb->rcv_nxt);
680
+
681
+ /* advertise our receive window size in this TCP segment */
682
+ seg->tcphdr->wnd = htons(pcb->rcv_ann_wnd);
683
+
684
+ pcb->rcv_ann_right_edge = pcb->rcv_nxt + pcb->rcv_ann_wnd;
685
+
686
+ /* Add any requested options. NB MSS option is only set on SYN
687
+ packets, so ignore it here */
688
+ opts = (u32_t *)(seg->tcphdr + 1);
689
+ if (seg->flags & TF_SEG_OPTS_MSS) {
690
+ TCP_BUILD_MSS_OPTION(*opts);
691
+ opts += 1;
692
+ }
693
+ #if LWIP_TCP_TIMESTAMPS
694
+ pcb->ts_lastacksent = pcb->rcv_nxt;
695
+
696
+ if (seg->flags & TF_SEG_OPTS_TS) {
697
+ tcp_build_timestamp_option(pcb, opts);
698
+ opts += 3;
699
+ }
700
+ #endif
701
+
702
+ #ifdef _TEST_HD_
703
+ /* ANGR: set rtime this _before_ checking ip_route(). Otherwise TCP_SYN will
704
+ * not be retransmitted in case the interface was down and tcp_connect()
705
+ * will not return any error. Since we still want the err_cb() (or maybe
706
+ * the wifi link comes up), make sure that we fulfill the retransmissions in
707
+ * tcp_slowtmr()
708
+ */
709
+
710
+ /* Set retransmission timer running if it is not currently enabled */
711
+ if(pcb->rtime == -1)
712
+ pcb->rtime = 0;
713
+ #endif
714
+
715
+ /* If we don't have a local IP address, we get one by
716
+ calling ip_route(). */
717
+ if (ip_addr_isany(&(pcb->local_ip))) {
718
+ netif = ip_route(&(pcb->remote_ip));
719
+ if (netif == NULL) {
720
+ return;
721
+ }
722
+ ip_addr_set(&(pcb->local_ip), &(netif->ip_addr));
723
+ }
724
+
725
+ #ifndef _TEST_HD_
726
+ //Set retransmission timer running if it is not currently enabled
727
+ if(pcb->rtime == -1)
728
+ pcb->rtime = 0;
729
+ #endif
730
+
731
+ if (pcb->rttest == 0) {
732
+ pcb->rttest = tcp_ticks;
733
+ pcb->rtseq = ntohl(seg->tcphdr->seqno);
734
+
735
+ LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_output_segment: rtseq %"U32_F"\n", pcb->rtseq));
736
+ }
737
+ LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output_segment: %"U32_F":%"U32_F"\n",
738
+ htonl(seg->tcphdr->seqno), htonl(seg->tcphdr->seqno) +
739
+ seg->len));
740
+
741
+ len = (u16_t)((u8_t *)seg->tcphdr - (u8_t *)seg->p->payload);
742
+
743
+ seg->p->len -= len;
744
+ seg->p->tot_len -= len;
745
+
746
+ seg->p->payload = seg->tcphdr;
747
+
748
+ seg->tcphdr->chksum = 0;
749
+ #if CHECKSUM_GEN_TCP
750
+ seg->tcphdr->chksum = inet_chksum_pseudo(seg->p,
751
+ &(pcb->local_ip),
752
+ &(pcb->remote_ip),
753
+ IP_PROTO_TCP, seg->p->tot_len);
754
+ #endif
755
+ TCP_STATS_INC(tcp.xmit);
756
+
757
+ #if LWIP_NETIF_HWADDRHINT
758
+ ip_output_hinted(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
759
+ IP_PROTO_TCP, &(pcb->addr_hint));
760
+ #else /* LWIP_NETIF_HWADDRHINT*/
761
+ ip_output(seg->p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
762
+ IP_PROTO_TCP);
763
+ #endif /* LWIP_NETIF_HWADDRHINT*/
764
+ }
765
+
766
+ /**
767
+ * Send a TCP RESET packet (empty segment with RST flag set) either to
768
+ * abort a connection or to show that there is no matching local connection
769
+ * for a received segment.
770
+ *
771
+ * Called by tcp_abort() (to abort a local connection), tcp_input() (if no
772
+ * matching local pcb was found), tcp_listen_input() (if incoming segment
773
+ * has ACK flag set) and tcp_process() (received segment in the wrong state)
774
+ *
775
+ * Since a RST segment is in most cases not sent for an active connection,
776
+ * tcp_rst() has a number of arguments that are taken from a tcp_pcb for
777
+ * most other segment output functions.
778
+ *
779
+ * @param seqno the sequence number to use for the outgoing segment
780
+ * @param ackno the acknowledge number to use for the outgoing segment
781
+ * @param local_ip the local IP address to send the segment from
782
+ * @param remote_ip the remote IP address to send the segment to
783
+ * @param local_port the local TCP port to send the segment from
784
+ * @param remote_port the remote TCP port to send the segment to
785
+ */
786
+ void
787
+ tcp_rst(u32_t seqno, u32_t ackno,
788
+ struct ip_addr *local_ip, struct ip_addr *remote_ip,
789
+ u16_t local_port, u16_t remote_port)
790
+ {
791
+ struct pbuf *p;
792
+ struct tcp_hdr *tcphdr;
793
+ p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM);
794
+ if (p == NULL) {
795
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_rst: could not allocate memory for pbuf\n"));
796
+ return;
797
+ }
798
+ LWIP_ASSERT("check that first pbuf can hold struct tcp_hdr",
799
+ (p->len >= sizeof(struct tcp_hdr)));
800
+
801
+ tcphdr = p->payload;
802
+ tcphdr->src = htons(local_port);
803
+ tcphdr->dest = htons(remote_port);
804
+ tcphdr->seqno = htonl(seqno);
805
+ tcphdr->ackno = htonl(ackno);
806
+ TCPH_FLAGS_SET(tcphdr, TCP_RST | TCP_ACK);
807
+ tcphdr->wnd = htons(TCP_WND);
808
+ tcphdr->urgp = 0;
809
+ TCPH_HDRLEN_SET(tcphdr, 5);
810
+
811
+ tcphdr->chksum = 0;
812
+ #if CHECKSUM_GEN_TCP
813
+ tcphdr->chksum = inet_chksum_pseudo(p, local_ip, remote_ip,
814
+ IP_PROTO_TCP, p->tot_len);
815
+ #endif
816
+ TCP_STATS_INC(tcp.xmit);
817
+ snmp_inc_tcpoutrsts();
818
+ /* Send output with hardcoded TTL since we have no access to the pcb */
819
+ ip_output(p, local_ip, remote_ip, TCP_TTL, 0, IP_PROTO_TCP);
820
+ pbuf_free(p);
821
+ LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_rst: seqno %"U32_F" ackno %"U32_F".\n", seqno, ackno));
822
+ }
823
+
824
+ /**
825
+ * Requeue all unacked segments for retransmission
826
+ *
827
+ * Called by tcp_slowtmr() for slow retransmission.
828
+ *
829
+ * @param pcb the tcp_pcb for which to re-enqueue all unacked segments
830
+ */
831
+ void
832
+ tcp_rexmit_rto(struct tcp_pcb *pcb)
833
+ {
834
+ struct tcp_seg *seg;
835
+
836
+ if (pcb->unacked == NULL) {
837
+ return;
838
+ }
839
+
840
+ /* Move all unacked segments to the head of the unsent queue */
841
+ for (seg = pcb->unacked; seg->next != NULL; seg = seg->next);
842
+ /* concatenate unsent queue after unacked queue */
843
+ seg->next = pcb->unsent;
844
+ /* unsent queue is the concatenated queue (of unacked, unsent) */
845
+ pcb->unsent = pcb->unacked;
846
+ /* unacked queue is now empty */
847
+ pcb->unacked = NULL;
848
+
849
+ /* increment number of retransmissions */
850
+ ++pcb->nrtx;
851
+
852
+ /* Don't take any RTT measurements after retransmitting. */
853
+ pcb->rttest = 0;
854
+
855
+ /* Do the actual retransmission */
856
+ tcp_output(pcb);
857
+ }
858
+
859
+ /**
860
+ * Requeue the first unacked segment for retransmission
861
+ *
862
+ * Called by tcp_receive() for fast retramsmit.
863
+ *
864
+ * @param pcb the tcp_pcb for which to retransmit the first unacked segment
865
+ */
866
+ void
867
+ tcp_rexmit(struct tcp_pcb *pcb)
868
+ {
869
+ struct tcp_seg *seg;
870
+ struct tcp_seg **cur_seg;
871
+
872
+ if (pcb->unacked == NULL) {
873
+ return;
874
+ }
875
+
876
+ /* Move the first unacked segment to the unsent queue */
877
+ /* Keep the unsent queue sorted. */
878
+ seg = pcb->unacked;
879
+ pcb->unacked = seg->next;
880
+
881
+ cur_seg = &(pcb->unsent);
882
+ while (*cur_seg &&
883
+ TCP_SEQ_LT(ntohl((*cur_seg)->tcphdr->seqno), ntohl(seg->tcphdr->seqno))) {
884
+ cur_seg = &((*cur_seg)->next );
885
+ }
886
+ seg->next = *cur_seg;
887
+ *cur_seg = seg;
888
+
889
+ ++pcb->nrtx;
890
+
891
+ /* Don't take any rtt measurements after retransmitting. */
892
+ pcb->rttest = 0;
893
+
894
+ /* Do the actual retransmission. */
895
+ snmp_inc_tcpretranssegs();
896
+ /* No need to call tcp_output: we are always called from tcp_input()
897
+ and thus tcp_output directly returns. */
898
+ }
899
+
900
+
901
+ /**
902
+ * Handle retransmission after three dupacks received
903
+ *
904
+ * @param pcb the tcp_pcb for which to retransmit the first unacked segment
905
+ */
906
+ void
907
+ tcp_rexmit_fast(struct tcp_pcb *pcb)
908
+ {
909
+ if (pcb->unacked != NULL && !(pcb->flags & TF_INFR)) {
910
+ /* This is fast retransmit. Retransmit the first unacked segment. */
911
+ LWIP_DEBUGF(TCP_FR_DEBUG,
912
+ ("tcp_receive: dupacks %"U16_F" (%"U32_F
913
+ "), fast retransmit %"U32_F"\n",
914
+ (u16_t)pcb->dupacks, pcb->lastack,
915
+ ntohl(pcb->unacked->tcphdr->seqno)));
916
+ tcp_rexmit(pcb);
917
+
918
+ /* Set ssthresh to half of the minimum of the current
919
+ * cwnd and the advertised window */
920
+ if (pcb->cwnd > pcb->snd_wnd)
921
+ pcb->ssthresh = pcb->snd_wnd / 2;
922
+ else
923
+ pcb->ssthresh = pcb->cwnd / 2;
924
+
925
+ /* The minimum value for ssthresh should be 2 MSS */
926
+ if (pcb->ssthresh < 2*pcb->mss) {
927
+ LWIP_DEBUGF(TCP_FR_DEBUG,
928
+ ("tcp_receive: The minimum value for ssthresh %"U16_F
929
+ " should be min 2 mss %"U16_F"...\n",
930
+ pcb->ssthresh, 2*pcb->mss));
931
+ pcb->ssthresh = 2*pcb->mss;
932
+ }
933
+
934
+ pcb->cwnd = pcb->ssthresh + 3 * pcb->mss;
935
+ pcb->flags |= TF_INFR;
936
+ }
937
+ }
938
+
939
+
940
+ /**
941
+ * Send keepalive packets to keep a connection active although
942
+ * no data is sent over it.
943
+ *
944
+ * Called by tcp_slowtmr()
945
+ *
946
+ * @param pcb the tcp_pcb for which to send a keepalive packet
947
+ */
948
+ void
949
+ tcp_keepalive(struct tcp_pcb *pcb)
950
+ {
951
+ struct pbuf *p;
952
+ struct tcp_hdr *tcphdr;
953
+
954
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: sending KEEPALIVE probe to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
955
+ ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
956
+ ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
957
+
958
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: tcp_ticks %"U32_F" pcb->tmr %"U32_F" pcb->keep_cnt_sent %"U16_F"\n",
959
+ tcp_ticks, pcb->tmr, pcb->keep_cnt_sent));
960
+
961
+ p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM);
962
+
963
+ if(p == NULL) {
964
+ LWIP_DEBUGF(TCP_DEBUG,
965
+ ("tcp_keepalive: could not allocate memory for pbuf\n"));
966
+ return;
967
+ }
968
+ LWIP_ASSERT("check that first pbuf can hold struct tcp_hdr",
969
+ (p->len >= sizeof(struct tcp_hdr)));
970
+
971
+ tcphdr = tcp_output_set_header(pcb, p, 0, htonl(pcb->snd_nxt - 1));
972
+
973
+ #if CHECKSUM_GEN_TCP
974
+ tcphdr->chksum = inet_chksum_pseudo(p, &pcb->local_ip, &pcb->remote_ip,
975
+ IP_PROTO_TCP, p->tot_len);
976
+ #endif
977
+ TCP_STATS_INC(tcp.xmit);
978
+
979
+ /* Send output to IP */
980
+ #if LWIP_NETIF_HWADDRHINT
981
+ ip_output_hinted(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP,
982
+ &(pcb->addr_hint));
983
+ #else /* LWIP_NETIF_HWADDRHINT*/
984
+ ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP);
985
+ #endif /* LWIP_NETIF_HWADDRHINT*/
986
+
987
+ pbuf_free(p);
988
+
989
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: seqno %"U32_F" ackno %"U32_F".\n",
990
+ pcb->snd_nxt - 1, pcb->rcv_nxt));
991
+ }
992
+
993
+
994
+ /**
995
+ * Send persist timer zero-window probes to keep a connection active
996
+ * when a window update is lost.
997
+ *
998
+ * Called by tcp_slowtmr()
999
+ *
1000
+ * @param pcb the tcp_pcb for which to send a zero-window probe packet
1001
+ */
1002
+ void
1003
+ tcp_zero_window_probe(struct tcp_pcb *pcb)
1004
+ {
1005
+ struct pbuf *p;
1006
+ struct tcp_hdr *tcphdr;
1007
+ struct tcp_seg *seg;
1008
+ u16_t len;
1009
+ u8_t is_fin;
1010
+
1011
+ LWIP_DEBUGF(TCP_DEBUG,
1012
+ ("tcp_zero_window_probe: sending ZERO WINDOW probe to %"
1013
+ U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
1014
+ ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
1015
+ ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
1016
+
1017
+ LWIP_DEBUGF(TCP_DEBUG,
1018
+ ("tcp_zero_window_probe: tcp_ticks %"U32_F
1019
+ " pcb->tmr %"U32_F" pcb->keep_cnt_sent %"U16_F"\n",
1020
+ tcp_ticks, pcb->tmr, pcb->keep_cnt_sent));
1021
+
1022
+ seg = pcb->unacked;
1023
+
1024
+ if(seg == NULL)
1025
+ seg = pcb->unsent;
1026
+
1027
+ if(seg == NULL)
1028
+ return;
1029
+
1030
+ is_fin = ((TCPH_FLAGS(seg->tcphdr) & TCP_FIN) != 0) && (seg->len == 0);
1031
+ len = is_fin ? TCP_HLEN : TCP_HLEN + 1;
1032
+
1033
+ p = pbuf_alloc(PBUF_IP, len, PBUF_RAM);
1034
+ if(p == NULL) {
1035
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_zero_window_probe: no memory for pbuf\n"));
1036
+ return;
1037
+ }
1038
+ LWIP_ASSERT("check that first pbuf can hold struct tcp_hdr",
1039
+ (p->len >= sizeof(struct tcp_hdr)));
1040
+
1041
+ tcphdr = tcp_output_set_header(pcb, p, 0, seg->tcphdr->seqno);
1042
+
1043
+ if (is_fin) {
1044
+ /* FIN segment, no data */
1045
+ TCPH_FLAGS_SET(tcphdr, TCP_ACK | TCP_FIN);
1046
+ } else {
1047
+ /* Data segment, copy in one byte from the head of the unacked queue */
1048
+ *((char *)p->payload + sizeof(struct tcp_hdr)) = *(char *)seg->dataptr;
1049
+ }
1050
+
1051
+ #if CHECKSUM_GEN_TCP
1052
+ tcphdr->chksum = inet_chksum_pseudo(p, &pcb->local_ip, &pcb->remote_ip,
1053
+ IP_PROTO_TCP, p->tot_len);
1054
+ #endif
1055
+ TCP_STATS_INC(tcp.xmit);
1056
+
1057
+ /* Send output to IP */
1058
+ #if LWIP_NETIF_HWADDRHINT
1059
+ ip_output_hinted(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP,
1060
+ &(pcb->addr_hint));
1061
+ #else /* LWIP_NETIF_HWADDRHINT*/
1062
+ ip_output(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP);
1063
+ #endif /* LWIP_NETIF_HWADDRHINT*/
1064
+
1065
+ pbuf_free(p);
1066
+
1067
+ LWIP_DEBUGF(TCP_DEBUG, ("tcp_zero_window_probe: seqno %"U32_F
1068
+ " ackno %"U32_F".\n",
1069
+ pcb->snd_nxt - 1, pcb->rcv_nxt));
1070
+ }
1071
+ #endif /* LWIP_TCP */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/udp.c ADDED
@@ -0,0 +1,843 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ * User Datagram Protocol module
6
+ *
7
+ */
8
+
9
+ /*
10
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
11
+ * All rights reserved.
12
+ *
13
+ * Redistribution and use in source and binary forms, with or without modification,
14
+ * are permitted provided that the following conditions are met:
15
+ *
16
+ * 1. Redistributions of source code must retain the above copyright notice,
17
+ * this list of conditions and the following disclaimer.
18
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
19
+ * this list of conditions and the following disclaimer in the documentation
20
+ * and/or other materials provided with the distribution.
21
+ * 3. The name of the author may not be used to endorse or promote products
22
+ * derived from this software without specific prior written permission.
23
+ *
24
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33
+ * OF SUCH DAMAGE.
34
+ *
35
+ * This file is part of the lwIP TCP/IP stack.
36
+ *
37
+ * Author: Adam Dunkels <adam@sics.se>
38
+ *
39
+ */
40
+
41
+
42
+ /* udp.c
43
+ *
44
+ * The code for the User Datagram Protocol UDP & UDPLite (RFC 3828).
45
+ *
46
+ */
47
+
48
+ /* @todo Check the use of '(struct udp_pcb).chksum_len_rx'!
49
+ */
50
+
51
+ #include "lwip/opt.h"
52
+
53
+ #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
54
+
55
+ #include "lwip/udp.h"
56
+ #include "lwip/def.h"
57
+ #include "lwip/memp.h"
58
+ #include "lwip/inet.h"
59
+ #include "lwip/inet_chksum.h"
60
+ #include "lwip/ip_addr.h"
61
+ #include "lwip/netif.h"
62
+ #include "lwip/icmp.h"
63
+ #include "lwip/stats.h"
64
+ #include "lwip/snmp.h"
65
+ #include "arch/perf.h"
66
+ #include "lwip/dhcp.h"
67
+
68
+ #include <string.h>
69
+
70
+ /* The list of UDP PCBs */
71
+ /* exported in udp.h (was static) */
72
+ struct udp_pcb *udp_pcbs;
73
+
74
+ /**
75
+ * Process an incoming UDP datagram.
76
+ *
77
+ * Given an incoming UDP datagram (as a chain of pbufs) this function
78
+ * finds a corresponding UDP PCB and hands over the pbuf to the pcbs
79
+ * recv function. If no pcb is found or the datagram is incorrect, the
80
+ * pbuf is freed.
81
+ *
82
+ * @param p pbuf to be demultiplexed to a UDP PCB.
83
+ * @param inp network interface on which the datagram was received.
84
+ *
85
+ */
86
+ void
87
+ udp_input(struct pbuf *p, struct netif *inp)
88
+ {
89
+ struct udp_hdr *udphdr;
90
+ struct udp_pcb *pcb, *prev;
91
+ struct udp_pcb *uncon_pcb;
92
+ struct ip_hdr *iphdr;
93
+ u16_t src, dest;
94
+ u8_t local_match;
95
+ u8_t broadcast;
96
+
97
+ PERF_START;
98
+
99
+ UDP_STATS_INC(udp.recv);
100
+
101
+ iphdr = p->payload;
102
+
103
+ /* Check minimum length (IP header + UDP header)
104
+ * and move payload pointer to UDP header */
105
+ if (p->tot_len < (IPH_HL(iphdr) * 4 + UDP_HLEN) || pbuf_header(p, -(s16_t)(IPH_HL(iphdr) * 4))) {
106
+ /* drop short packets */
107
+ LWIP_DEBUGF(UDP_DEBUG,
108
+ ("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
109
+ UDP_STATS_INC(udp.lenerr);
110
+ UDP_STATS_INC(udp.drop);
111
+ snmp_inc_udpinerrors();
112
+ pbuf_free(p);
113
+ goto end;
114
+ }
115
+
116
+ udphdr = (struct udp_hdr *)p->payload;
117
+
118
+ /* is broadcast packet ? */
119
+ broadcast = ip_addr_isbroadcast(&(iphdr->dest), inp);
120
+
121
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len));
122
+
123
+ /* convert src and dest ports to host byte order */
124
+ src = ntohs(udphdr->src);
125
+ dest = ntohs(udphdr->dest);
126
+
127
+ udp_debug_print(udphdr);
128
+
129
+ /* print the UDP source and destination */
130
+ LWIP_DEBUGF(UDP_DEBUG,
131
+ ("udp (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") <-- "
132
+ "(%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
133
+ ip4_addr1(&iphdr->dest), ip4_addr2(&iphdr->dest),
134
+ ip4_addr3(&iphdr->dest), ip4_addr4(&iphdr->dest), ntohs(udphdr->dest),
135
+ ip4_addr1(&iphdr->src), ip4_addr2(&iphdr->src),
136
+ ip4_addr3(&iphdr->src), ip4_addr4(&iphdr->src), ntohs(udphdr->src)));
137
+
138
+ #if LWIP_DHCP
139
+ pcb = NULL;
140
+ /* when LWIP_DHCP is active, packets to DHCP_CLIENT_PORT may only be processed by
141
+ the dhcp module, no other UDP pcb may use the local UDP port DHCP_CLIENT_PORT */
142
+ if (dest == DHCP_CLIENT_PORT) {
143
+ /* all packets for DHCP_CLIENT_PORT not coming from DHCP_SERVER_PORT are dropped! */
144
+ if (src == DHCP_SERVER_PORT) {
145
+ if ((inp->dhcp != NULL) && (inp->dhcp->pcb != NULL)) {
146
+ /* accept the packe if
147
+ (- broadcast or directed to us) -> DHCP is link-layer-addressed, local ip is always ANY!
148
+ - inp->dhcp->pcb->remote == ANY or iphdr->src */
149
+ if ((ip_addr_isany(&inp->dhcp->pcb->remote_ip) ||
150
+ ip_addr_cmp(&(inp->dhcp->pcb->remote_ip), &(iphdr->src)))) {
151
+ pcb = inp->dhcp->pcb;
152
+ }
153
+ }
154
+ }
155
+ } else
156
+ #endif /* LWIP_DHCP */
157
+ {
158
+ prev = NULL;
159
+ local_match = 0;
160
+ uncon_pcb = NULL;
161
+ /* Iterate through the UDP pcb list for a matching pcb.
162
+ * 'Perfect match' pcbs (connected to the remote port & ip address) are
163
+ * preferred. If no perfect match is found, the first unconnected pcb that
164
+ * matches the local port and ip address gets the datagram. */
165
+ for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
166
+ local_match = 0;
167
+ /* print the PCB local and remote address */
168
+ LWIP_DEBUGF(UDP_DEBUG,
169
+ ("pcb (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") --- "
170
+ "(%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
171
+ ip4_addr1(&pcb->local_ip), ip4_addr2(&pcb->local_ip),
172
+ ip4_addr3(&pcb->local_ip), ip4_addr4(&pcb->local_ip), pcb->local_port,
173
+ ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
174
+ ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), pcb->remote_port));
175
+
176
+ /* compare PCB local addr+port to UDP destination addr+port */
177
+ if ((pcb->local_port == dest) &&
178
+ ((!broadcast && ip_addr_isany(&pcb->local_ip)) ||
179
+ ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)) ||
180
+ #if LWIP_IGMP
181
+ ip_addr_ismulticast(&(iphdr->dest)) ||
182
+ #endif /* LWIP_IGMP */
183
+ #if IP_SOF_BROADCAST_RECV
184
+ (broadcast && (pcb->so_options & SOF_BROADCAST)))) {
185
+ #else /* IP_SOF_BROADCAST_RECV */
186
+ (broadcast))) {
187
+ #endif /* IP_SOF_BROADCAST_RECV */
188
+ local_match = 1;
189
+ if ((uncon_pcb == NULL) &&
190
+ ((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) {
191
+ /* the first unconnected matching PCB */
192
+ uncon_pcb = pcb;
193
+ }
194
+ }
195
+ /* compare PCB remote addr+port to UDP source addr+port */
196
+ if ((local_match != 0) &&
197
+ (pcb->remote_port == src) &&
198
+ (ip_addr_isany(&pcb->remote_ip) ||
199
+ ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)))) {
200
+ /* the first fully matching PCB */
201
+ if (prev != NULL) {
202
+ /* move the pcb to the front of udp_pcbs so that is
203
+ found faster next time */
204
+ prev->next = pcb->next;
205
+ pcb->next = udp_pcbs;
206
+ udp_pcbs = pcb;
207
+ } else {
208
+ UDP_STATS_INC(udp.cachehit);
209
+ }
210
+ break;
211
+ }
212
+ prev = pcb;
213
+ }
214
+ /* no fully matching pcb found? then look for an unconnected pcb */
215
+ if (pcb == NULL) {
216
+ pcb = uncon_pcb;
217
+ }
218
+ }
219
+
220
+ /* Check checksum if this is a match or if it was directed at us. */
221
+ if (pcb != NULL || ip_addr_cmp(&inp->ip_addr, &iphdr->dest)) {
222
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: calculating checksum\n"));
223
+ #if LWIP_UDPLITE
224
+ if (IPH_PROTO(iphdr) == IP_PROTO_UDPLITE) {
225
+ /* Do the UDP Lite checksum */
226
+ #if CHECKSUM_CHECK_UDP
227
+ u16_t chklen = ntohs(udphdr->len);
228
+ if (chklen < sizeof(struct udp_hdr)) {
229
+ if (chklen == 0) {
230
+ /* For UDP-Lite, checksum length of 0 means checksum
231
+ over the complete packet (See RFC 3828 chap. 3.1) */
232
+ chklen = p->tot_len;
233
+ } else {
234
+ /* At least the UDP-Lite header must be covered by the
235
+ checksum! (Again, see RFC 3828 chap. 3.1) */
236
+ UDP_STATS_INC(udp.chkerr);
237
+ UDP_STATS_INC(udp.drop);
238
+ snmp_inc_udpinerrors();
239
+ pbuf_free(p);
240
+ goto end;
241
+ }
242
+ }
243
+ if (inet_chksum_pseudo_partial(p, (struct ip_addr *)&(iphdr->src),
244
+ (struct ip_addr *)&(iphdr->dest),
245
+ IP_PROTO_UDPLITE, p->tot_len, chklen) != 0) {
246
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
247
+ ("udp_input: UDP Lite datagram discarded due to failing checksum\n"));
248
+ UDP_STATS_INC(udp.chkerr);
249
+ UDP_STATS_INC(udp.drop);
250
+ snmp_inc_udpinerrors();
251
+ pbuf_free(p);
252
+ goto end;
253
+ }
254
+ #endif /* CHECKSUM_CHECK_UDP */
255
+ } else
256
+ #endif /* LWIP_UDPLITE */
257
+ {
258
+ #if CHECKSUM_CHECK_UDP
259
+ if (udphdr->chksum != 0) {
260
+ if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
261
+ (struct ip_addr *)&(iphdr->dest),
262
+ IP_PROTO_UDP, p->tot_len) != 0) {
263
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
264
+ ("udp_input: UDP datagram discarded due to failing checksum\n"));
265
+ UDP_STATS_INC(udp.chkerr);
266
+ UDP_STATS_INC(udp.drop);
267
+ snmp_inc_udpinerrors();
268
+ pbuf_free(p);
269
+ goto end;
270
+ }
271
+ }
272
+ #endif /* CHECKSUM_CHECK_UDP */
273
+ }
274
+ if(pbuf_header(p, -UDP_HLEN)) {
275
+ /* Can we cope with this failing? Just assert for now */
276
+ LWIP_ASSERT("pbuf_header failed\n", 0);
277
+ UDP_STATS_INC(udp.drop);
278
+ snmp_inc_udpinerrors();
279
+ pbuf_free(p);
280
+ goto end;
281
+ }
282
+ if (pcb != NULL) {
283
+ snmp_inc_udpindatagrams();
284
+ /* callback */
285
+ if (pcb->recv != NULL) {
286
+ /* now the recv function is responsible for freeing p */
287
+ pcb->recv(pcb->recv_arg, pcb, p, &iphdr->src, src);
288
+ } else {
289
+ /* no recv function registered? then we have to free the pbuf! */
290
+ pbuf_free(p);
291
+ goto end;
292
+ }
293
+ } else {
294
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: not for us.\n"));
295
+
296
+ #if LWIP_ICMP
297
+ /* No match was found, send ICMP destination port unreachable unless
298
+ destination address was broadcast/multicast. */
299
+ if (!broadcast &&
300
+ !ip_addr_ismulticast(&iphdr->dest)) {
301
+ /* move payload pointer back to ip header */
302
+ pbuf_header(p, (IPH_HL(iphdr) * 4) + UDP_HLEN);
303
+ LWIP_ASSERT("p->payload == iphdr", (p->payload == iphdr));
304
+ icmp_dest_unreach(p, ICMP_DUR_PORT);
305
+ }
306
+ #endif /* LWIP_ICMP */
307
+ UDP_STATS_INC(udp.proterr);
308
+ UDP_STATS_INC(udp.drop);
309
+ snmp_inc_udpnoports();
310
+ pbuf_free(p);
311
+ }
312
+ } else {
313
+ pbuf_free(p);
314
+ }
315
+ end:
316
+ PERF_STOP("udp_input");
317
+ }
318
+
319
+ /**
320
+ * Send data using UDP.
321
+ *
322
+ * @param pcb UDP PCB used to send the data.
323
+ * @param p chain of pbuf's to be sent.
324
+ *
325
+ * The datagram will be sent to the current remote_ip & remote_port
326
+ * stored in pcb. If the pcb is not bound to a port, it will
327
+ * automatically be bound to a random port.
328
+ *
329
+ * @return lwIP error code.
330
+ * - ERR_OK. Successful. No error occured.
331
+ * - ERR_MEM. Out of memory.
332
+ * - ERR_RTE. Could not find route to destination address.
333
+ * - More errors could be returned by lower protocol layers.
334
+ *
335
+ * @see udp_disconnect() udp_sendto()
336
+ */
337
+ err_t
338
+ udp_send(struct udp_pcb *pcb, struct pbuf *p)
339
+ {
340
+ /* send to the packet using remote ip and port stored in the pcb */
341
+ return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
342
+ }
343
+
344
+ /**
345
+ * Send data to a specified address using UDP.
346
+ *
347
+ * @param pcb UDP PCB used to send the data.
348
+ * @param p chain of pbuf's to be sent.
349
+ * @param dst_ip Destination IP address.
350
+ * @param dst_port Destination UDP port.
351
+ *
352
+ * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
353
+ *
354
+ * If the PCB already has a remote address association, it will
355
+ * be restored after the data is sent.
356
+ *
357
+ * @return lwIP error code (@see udp_send for possible error codes)
358
+ *
359
+ * @see udp_disconnect() udp_send()
360
+ */
361
+ err_t
362
+ udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
363
+ struct ip_addr *dst_ip, u16_t dst_port)
364
+ {
365
+ struct netif *netif;
366
+
367
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send\n"));
368
+
369
+ /* find the outgoing network interface for this packet */
370
+ #if LWIP_IGMP
371
+ netif = ip_route((ip_addr_ismulticast(dst_ip))?(&(pcb->multicast_ip)):(dst_ip));
372
+ #else
373
+ netif = ip_route(dst_ip);
374
+ #endif /* LWIP_IGMP */
375
+
376
+ /* no outgoing network interface could be found? */
377
+ if (netif == NULL) {
378
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: No route to 0x%"X32_F"\n", dst_ip->addr));
379
+ UDP_STATS_INC(udp.rterr);
380
+ return ERR_RTE;
381
+ }
382
+ return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
383
+ }
384
+
385
+ /**
386
+ * Send data to a specified address using UDP.
387
+ * The netif used for sending can be specified.
388
+ *
389
+ * This function exists mainly for DHCP, to be able to send UDP packets
390
+ * on a netif that is still down.
391
+ *
392
+ * @param pcb UDP PCB used to send the data.
393
+ * @param p chain of pbuf's to be sent.
394
+ * @param dst_ip Destination IP address.
395
+ * @param dst_port Destination UDP port.
396
+ * @param netif the netif used for sending.
397
+ *
398
+ * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
399
+ *
400
+ * @return lwIP error code (@see udp_send for possible error codes)
401
+ *
402
+ * @see udp_disconnect() udp_send()
403
+ */
404
+ err_t
405
+ udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
406
+ struct ip_addr *dst_ip, u16_t dst_port, struct netif *netif)
407
+ {
408
+ struct udp_hdr *udphdr;
409
+ struct ip_addr *src_ip;
410
+ err_t err;
411
+ struct pbuf *q; /* q will be sent down the stack */
412
+
413
+ #if IP_SOF_BROADCAST
414
+ /* broadcast filter? */
415
+ if ( ((pcb->so_options & SOF_BROADCAST) == 0) && ip_addr_isbroadcast(dst_ip, netif) ) {
416
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
417
+ ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
418
+ return ERR_VAL;
419
+ }
420
+ #endif /* IP_SOF_BROADCAST */
421
+
422
+ /* if the PCB is not yet bound to a port, bind it here */
423
+ if (pcb->local_port == 0) {
424
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send: not yet bound to a port, binding now\n"));
425
+ err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
426
+ if (err != ERR_OK) {
427
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: forced port bind failed\n"));
428
+ return err;
429
+ }
430
+ }
431
+
432
+ /* not enough space to add an UDP header to first pbuf in given p chain? */
433
+ if (pbuf_header(p, UDP_HLEN)) {
434
+ /* allocate header in a separate new pbuf */
435
+ q = pbuf_alloc(PBUF_IP, UDP_HLEN, PBUF_RAM);
436
+ /* new header pbuf could not be allocated? */
437
+ if (q == NULL) {
438
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: could not allocate header\n"));
439
+ return ERR_MEM;
440
+ }
441
+ /* chain header q in front of given pbuf p */
442
+ pbuf_chain(q, p);
443
+ /* first pbuf q points to header pbuf */
444
+ LWIP_DEBUGF(UDP_DEBUG,
445
+ ("udp_send: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
446
+ } else {
447
+ /* adding space for header within p succeeded */
448
+ /* first pbuf q equals given pbuf */
449
+ q = p;
450
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_send: added header in given pbuf %p\n", (void *)p));
451
+ }
452
+ LWIP_ASSERT("check that first pbuf can hold struct udp_hdr",
453
+ (q->len >= sizeof(struct udp_hdr)));
454
+ /* q now represents the packet to be sent */
455
+ udphdr = q->payload;
456
+ udphdr->src = htons(pcb->local_port);
457
+ udphdr->dest = htons(dst_port);
458
+ /* in UDP, 0 checksum means 'no checksum' */
459
+ udphdr->chksum = 0x0000;
460
+
461
+ /* PCB local address is IP_ANY_ADDR? */
462
+ if (ip_addr_isany(&pcb->local_ip)) {
463
+ /* use outgoing network interface IP address as source address */
464
+ src_ip = &(netif->ip_addr);
465
+ } else {
466
+ /* check if UDP PCB local IP address is correct
467
+ * this could be an old address if netif->ip_addr has changed */
468
+ if (!ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
469
+ /* local_ip doesn't match, drop the packet */
470
+ if (q != p) {
471
+ /* free the header pbuf */
472
+ pbuf_free(q);
473
+ q = NULL;
474
+ /* p is still referenced by the caller, and will live on */
475
+ }
476
+ return ERR_VAL;
477
+ }
478
+ /* use UDP PCB local IP address as source address */
479
+ src_ip = &(pcb->local_ip);
480
+ }
481
+
482
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %"U16_F"\n", q->tot_len));
483
+
484
+ #if LWIP_UDPLITE
485
+ /* UDP Lite protocol? */
486
+ if (pcb->flags & UDP_FLAGS_UDPLITE) {
487
+ u16_t chklen, chklen_hdr;
488
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE packet length %"U16_F"\n", q->tot_len));
489
+ /* set UDP message length in UDP header */
490
+ chklen_hdr = chklen = pcb->chksum_len_tx;
491
+ if ((chklen < sizeof(struct udp_hdr)) || (chklen > q->tot_len)) {
492
+ if (chklen != 0) {
493
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE pcb->chksum_len is illegal: %"U16_F"\n", chklen));
494
+ }
495
+ /* For UDP-Lite, checksum length of 0 means checksum
496
+ over the complete packet. (See RFC 3828 chap. 3.1)
497
+ At least the UDP-Lite header must be covered by the
498
+ checksum, therefore, if chksum_len has an illegal
499
+ value, we generate the checksum over the complete
500
+ packet to be safe. */
501
+ chklen_hdr = 0;
502
+ chklen = q->tot_len;
503
+ }
504
+ udphdr->len = htons(chklen_hdr);
505
+ /* calculate checksum */
506
+ #if CHECKSUM_GEN_UDP
507
+ udphdr->chksum = inet_chksum_pseudo_partial(q, src_ip, dst_ip,
508
+ IP_PROTO_UDPLITE, q->tot_len, chklen);
509
+ /* chksum zero must become 0xffff, as zero means 'no checksum' */
510
+ if (udphdr->chksum == 0x0000)
511
+ udphdr->chksum = 0xffff;
512
+ #endif /* CHECKSUM_CHECK_UDP */
513
+ /* output to IP */
514
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDPLITE,)\n"));
515
+ #if LWIP_NETIF_HWADDRHINT
516
+ netif->addr_hint = &(pcb->addr_hint);
517
+ #endif /* LWIP_NETIF_HWADDRHINT*/
518
+ err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif);
519
+ #if LWIP_NETIF_HWADDRHINT
520
+ netif->addr_hint = NULL;
521
+ #endif /* LWIP_NETIF_HWADDRHINT*/
522
+ } else
523
+ #endif /* LWIP_UDPLITE */
524
+ { /* UDP */
525
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %"U16_F"\n", q->tot_len));
526
+ udphdr->len = htons(q->tot_len);
527
+ /* calculate checksum */
528
+ #if CHECKSUM_GEN_UDP
529
+ if ((pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
530
+ udphdr->chksum = inet_chksum_pseudo(q, src_ip, dst_ip, IP_PROTO_UDP, q->tot_len);
531
+ /* chksum zero must become 0xffff, as zero means 'no checksum' */
532
+ if (udphdr->chksum == 0x0000) udphdr->chksum = 0xffff;
533
+ }
534
+ #endif /* CHECKSUM_CHECK_UDP */
535
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum));
536
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDP,)\n"));
537
+ /* output to IP */
538
+ #if LWIP_NETIF_HWADDRHINT
539
+ netif->addr_hint = &(pcb->addr_hint);
540
+ #endif /* LWIP_NETIF_HWADDRHINT*/
541
+ err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif);
542
+ #if LWIP_NETIF_HWADDRHINT
543
+ netif->addr_hint = NULL;
544
+ #endif /* LWIP_NETIF_HWADDRHINT*/
545
+ }
546
+ /* TODO: must this be increased even if error occured? */
547
+ snmp_inc_udpoutdatagrams();
548
+
549
+ /* did we chain a separate header pbuf earlier? */
550
+ if (q != p) {
551
+ /* free the header pbuf */
552
+ pbuf_free(q);
553
+ q = NULL;
554
+ /* p is still referenced by the caller, and will live on */
555
+ }
556
+
557
+ UDP_STATS_INC(udp.xmit);
558
+ return err;
559
+ }
560
+
561
+ /**
562
+ * Bind an UDP PCB.
563
+ *
564
+ * @param pcb UDP PCB to be bound with a local address ipaddr and port.
565
+ * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to
566
+ * bind to all local interfaces.
567
+ * @param port local UDP port to bind with. Use 0 to automatically bind
568
+ * to a random port between UDP_LOCAL_PORT_RANGE_START and
569
+ * UDP_LOCAL_PORT_RANGE_END.
570
+ *
571
+ * ipaddr & port are expected to be in the same byte order as in the pcb.
572
+ *
573
+ * @return lwIP error code.
574
+ * - ERR_OK. Successful. No error occured.
575
+ * - ERR_USE. The specified ipaddr and port are already bound to by
576
+ * another UDP PCB.
577
+ *
578
+ * @see udp_disconnect()
579
+ */
580
+ err_t
581
+ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
582
+ {
583
+ struct udp_pcb *ipcb;
584
+ u8_t rebind;
585
+
586
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
587
+ ip_addr_debug_print(UDP_DEBUG, ipaddr);
588
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, (", port = %"U16_F")\n", port));
589
+
590
+ rebind = 0;
591
+ /* Check for double bind and rebind of the same pcb */
592
+ for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
593
+ /* is this UDP PCB already on active list? */
594
+ if (pcb == ipcb) {
595
+ /* pcb may occur at most once in active list */
596
+ LWIP_ASSERT("rebind == 0", rebind == 0);
597
+ /* pcb already in list, just rebind */
598
+ rebind = 1;
599
+ }
600
+
601
+ /* this code does not allow upper layer to share a UDP port for
602
+ listening to broadcast or multicast traffic (See SO_REUSE_ADDR and
603
+ SO_REUSE_PORT under *BSD). TODO: See where it fits instead, OR
604
+ combine with implementation of UDP PCB flags. Leon Woestenberg. */
605
+ #ifdef LWIP_UDP_TODO
606
+ /* port matches that of PCB in list? */
607
+ else
608
+ if ((ipcb->local_port == port) &&
609
+ /* IP address matches, or one is IP_ADDR_ANY? */
610
+ (ip_addr_isany(&(ipcb->local_ip)) ||
611
+ ip_addr_isany(ipaddr) ||
612
+ ip_addr_cmp(&(ipcb->local_ip), ipaddr))) {
613
+ /* other PCB already binds to this local IP and port */
614
+ LWIP_DEBUGF(UDP_DEBUG,
615
+ ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
616
+ return ERR_USE;
617
+ }
618
+ #endif
619
+ }
620
+
621
+ ip_addr_set(&pcb->local_ip, ipaddr);
622
+
623
+ /* no port specified? */
624
+ if (port == 0) {
625
+ #ifndef UDP_LOCAL_PORT_RANGE_START
626
+ #define UDP_LOCAL_PORT_RANGE_START 4096
627
+ #define UDP_LOCAL_PORT_RANGE_END 0x7fff
628
+ #endif
629
+ port = UDP_LOCAL_PORT_RANGE_START;
630
+ ipcb = udp_pcbs;
631
+ while ((ipcb != NULL) && (port != UDP_LOCAL_PORT_RANGE_END)) {
632
+ if (ipcb->local_port == port) {
633
+ /* port is already used by another udp_pcb */
634
+ port++;
635
+ /* restart scanning all udp pcbs */
636
+ ipcb = udp_pcbs;
637
+ } else
638
+ /* go on with next udp pcb */
639
+ ipcb = ipcb->next;
640
+ }
641
+ if (ipcb != NULL) {
642
+ /* no more ports available in local range */
643
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
644
+ return ERR_USE;
645
+ }
646
+ }
647
+ pcb->local_port = port;
648
+ snmp_insert_udpidx_tree(pcb);
649
+ /* pcb not active yet? */
650
+ if (rebind == 0) {
651
+ /* place the PCB on the active list if not already there */
652
+ pcb->next = udp_pcbs;
653
+ udp_pcbs = pcb;
654
+ }
655
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
656
+ ("udp_bind: bound to %"U16_F".%"U16_F".%"U16_F".%"U16_F", port %"U16_F"\n",
657
+ (u16_t)((ntohl(pcb->local_ip.addr) >> 24) & 0xff),
658
+ (u16_t)((ntohl(pcb->local_ip.addr) >> 16) & 0xff),
659
+ (u16_t)((ntohl(pcb->local_ip.addr) >> 8) & 0xff),
660
+ (u16_t)(ntohl(pcb->local_ip.addr) & 0xff), pcb->local_port));
661
+ return ERR_OK;
662
+ }
663
+ /**
664
+ * Connect an UDP PCB.
665
+ *
666
+ * This will associate the UDP PCB with the remote address.
667
+ *
668
+ * @param pcb UDP PCB to be connected with remote address ipaddr and port.
669
+ * @param ipaddr remote IP address to connect with.
670
+ * @param port remote UDP port to connect with.
671
+ *
672
+ * @return lwIP error code
673
+ *
674
+ * ipaddr & port are expected to be in the same byte order as in the pcb.
675
+ *
676
+ * The udp pcb is bound to a random local port if not already bound.
677
+ *
678
+ * @see udp_disconnect()
679
+ */
680
+ err_t
681
+ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
682
+ {
683
+ struct udp_pcb *ipcb;
684
+
685
+ if (pcb->local_port == 0) {
686
+ err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
687
+ if (err != ERR_OK)
688
+ return err;
689
+ }
690
+
691
+ ip_addr_set(&pcb->remote_ip, ipaddr);
692
+ pcb->remote_port = port;
693
+ pcb->flags |= UDP_FLAGS_CONNECTED;
694
+ /** TODO: this functionality belongs in upper layers */
695
+ #ifdef LWIP_UDP_TODO
696
+ /* Nail down local IP for netconn_addr()/getsockname() */
697
+ if (ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
698
+ struct netif *netif;
699
+
700
+ if ((netif = ip_route(&(pcb->remote_ip))) == NULL) {
701
+ LWIP_DEBUGF(UDP_DEBUG, ("udp_connect: No route to 0x%lx\n", pcb->remote_ip.addr));
702
+ UDP_STATS_INC(udp.rterr);
703
+ return ERR_RTE;
704
+ }
705
+ /** TODO: this will bind the udp pcb locally, to the interface which
706
+ is used to route output packets to the remote address. However, we
707
+ might want to accept incoming packets on any interface! */
708
+ pcb->local_ip = netif->ip_addr;
709
+ } else if (ip_addr_isany(&pcb->remote_ip)) {
710
+ pcb->local_ip.addr = 0;
711
+ }
712
+ #endif
713
+ LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
714
+ ("udp_connect: connected to %"U16_F".%"U16_F".%"U16_F".%"U16_F",port %"U16_F"\n",
715
+ (u16_t)((ntohl(pcb->remote_ip.addr) >> 24) & 0xff),
716
+ (u16_t)((ntohl(pcb->remote_ip.addr) >> 16) & 0xff),
717
+ (u16_t)((ntohl(pcb->remote_ip.addr) >> 8) & 0xff),
718
+ (u16_t)(ntohl(pcb->remote_ip.addr) & 0xff), pcb->remote_port));
719
+
720
+ /* Insert UDP PCB into the list of active UDP PCBs. */
721
+ for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
722
+ if (pcb == ipcb) {
723
+ /* already on the list, just return */
724
+ return ERR_OK;
725
+ }
726
+ }
727
+ /* PCB not yet on the list, add PCB now */
728
+ pcb->next = udp_pcbs;
729
+ udp_pcbs = pcb;
730
+ return ERR_OK;
731
+ }
732
+
733
+ /**
734
+ * Disconnect a UDP PCB
735
+ *
736
+ * @param pcb the udp pcb to disconnect.
737
+ */
738
+ void
739
+ udp_disconnect(struct udp_pcb *pcb)
740
+ {
741
+ /* reset remote address association */
742
+ ip_addr_set(&pcb->remote_ip, IP_ADDR_ANY);
743
+ pcb->remote_port = 0;
744
+ /* mark PCB as unconnected */
745
+ pcb->flags &= ~UDP_FLAGS_CONNECTED;
746
+ }
747
+
748
+ /**
749
+ * Set a receive callback for a UDP PCB
750
+ *
751
+ * This callback will be called when receiving a datagram for the pcb.
752
+ *
753
+ * @param pcb the pcb for wich to set the recv callback
754
+ * @param recv function pointer of the callback function
755
+ * @param recv_arg additional argument to pass to the callback function
756
+ */
757
+ void
758
+ udp_recv(struct udp_pcb *pcb,
759
+ void (* recv)(void *arg, struct udp_pcb *upcb, struct pbuf *p,
760
+ struct ip_addr *addr, u16_t port),
761
+ void *recv_arg)
762
+ {
763
+ /* remember recv() callback and user data */
764
+ pcb->recv = recv;
765
+ pcb->recv_arg = recv_arg;
766
+ }
767
+
768
+ /**
769
+ * Remove an UDP PCB.
770
+ *
771
+ * @param pcb UDP PCB to be removed. The PCB is removed from the list of
772
+ * UDP PCB's and the data structure is freed from memory.
773
+ *
774
+ * @see udp_new()
775
+ */
776
+ void
777
+ udp_remove(struct udp_pcb *pcb)
778
+ {
779
+ struct udp_pcb *pcb2;
780
+
781
+ snmp_delete_udpidx_tree(pcb);
782
+ /* pcb to be removed is first in list? */
783
+ if (udp_pcbs == pcb) {
784
+ /* make list start at 2nd pcb */
785
+ udp_pcbs = udp_pcbs->next;
786
+ /* pcb not 1st in list */
787
+ } else
788
+ for (pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
789
+ /* find pcb in udp_pcbs list */
790
+ if (pcb2->next != NULL && pcb2->next == pcb) {
791
+ /* remove pcb from list */
792
+ pcb2->next = pcb->next;
793
+ }
794
+ }
795
+ memp_free(MEMP_UDP_PCB, pcb);
796
+ }
797
+
798
+ /**
799
+ * Create a UDP PCB.
800
+ *
801
+ * @return The UDP PCB which was created. NULL if the PCB data structure
802
+ * could not be allocated.
803
+ *
804
+ * @see udp_remove()
805
+ */
806
+ struct udp_pcb *
807
+ udp_new(void)
808
+ {
809
+ struct udp_pcb *pcb;
810
+ pcb = memp_malloc(MEMP_UDP_PCB);
811
+ /* could allocate UDP PCB? */
812
+ if (pcb != NULL) {
813
+ /* UDP Lite: by initializing to all zeroes, chksum_len is set to 0
814
+ * which means checksum is generated over the whole datagram per default
815
+ * (recommended as default by RFC 3828). */
816
+ /* initialize PCB to all zeroes */
817
+ memset(pcb, 0, sizeof(struct udp_pcb));
818
+ pcb->ttl = UDP_TTL;
819
+ }
820
+ return pcb;
821
+ }
822
+
823
+ #if UDP_DEBUG
824
+ /**
825
+ * Print UDP header information for debug purposes.
826
+ *
827
+ * @param udphdr pointer to the udp header in memory.
828
+ */
829
+ void
830
+ udp_debug_print(struct udp_hdr *udphdr)
831
+ {
832
+ LWIP_DEBUGF(UDP_DEBUG, ("UDP header:\n"));
833
+ LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
834
+ LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n",
835
+ ntohs(udphdr->src), ntohs(udphdr->dest)));
836
+ LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
837
+ LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | 0x%04"X16_F" | (len, chksum)\n",
838
+ ntohs(udphdr->len), ntohs(udphdr->chksum)));
839
+ LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
840
+ }
841
+ #endif /* UDP_DEBUG */
842
+
843
+ #endif /* LWIP_UDP */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/autoip.h ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ *
6
+ * AutoIP Automatic LinkLocal IP Configuration
7
+ */
8
+
9
+ /*
10
+ *
11
+ * Copyright (c) 2007 Dominik Spies <kontakt@dspies.de>
12
+ * All rights reserved.
13
+ *
14
+ * Redistribution and use in source and binary forms, with or without modification,
15
+ * are permitted provided that the following conditions are met:
16
+ *
17
+ * 1. Redistributions of source code must retain the above copyright notice,
18
+ * this list of conditions and the following disclaimer.
19
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
20
+ * this list of conditions and the following disclaimer in the documentation
21
+ * and/or other materials provided with the distribution.
22
+ * 3. The name of the author may not be used to endorse or promote products
23
+ * derived from this software without specific prior written permission.
24
+ *
25
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
26
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
28
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
30
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34
+ * OF SUCH DAMAGE.
35
+ *
36
+ * Author: Dominik Spies <kontakt@dspies.de>
37
+ *
38
+ * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform
39
+ * with RFC 3927.
40
+ *
41
+ *
42
+ * Please coordinate changes and requests with Dominik Spies
43
+ * <kontakt@dspies.de>
44
+ */
45
+
46
+ #ifndef __LWIP_AUTOIP_H__
47
+ #define __LWIP_AUTOIP_H__
48
+
49
+ #include "lwip/opt.h"
50
+
51
+ #if LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */
52
+
53
+ #include "lwip/netif.h"
54
+ #include "lwip/udp.h"
55
+ #include "netif/etharp.h"
56
+
57
+ #ifdef __cplusplus
58
+ extern "C" {
59
+ #endif
60
+
61
+ /* AutoIP Timing */
62
+ #define AUTOIP_TMR_INTERVAL 100
63
+ #define AUTOIP_TICKS_PER_SECOND (1000 / AUTOIP_TMR_INTERVAL)
64
+
65
+ /* RFC 3927 Constants */
66
+ #define PROBE_WAIT 1 /* second (initial random delay) */
67
+ #define PROBE_MIN 1 /* second (minimum delay till repeated probe) */
68
+ #define PROBE_MAX 2 /* seconds (maximum delay till repeated probe) */
69
+ #define PROBE_NUM 3 /* (number of probe packets) */
70
+ #define ANNOUNCE_NUM 2 /* (number of announcement packets) */
71
+ #define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */
72
+ #define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */
73
+ #define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */
74
+ #define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */
75
+ #define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */
76
+
77
+ /* AutoIP client states */
78
+ #define AUTOIP_STATE_OFF 0
79
+ #define AUTOIP_STATE_PROBING 1
80
+ #define AUTOIP_STATE_ANNOUNCING 2
81
+ #define AUTOIP_STATE_BOUND 3
82
+
83
+ struct autoip
84
+ {
85
+ struct ip_addr llipaddr; /* the currently selected, probed, announced or used LL IP-Address */
86
+ u8_t state; /* current AutoIP state machine state */
87
+ u8_t sent_num; /* sent number of probes or announces, dependent on state */
88
+ u16_t ttw; /* ticks to wait, tick is AUTOIP_TMR_INTERVAL long */
89
+ u8_t lastconflict; /* ticks until a conflict can be solved by defending */
90
+ u8_t tried_llipaddr; /* total number of probed/used Link Local IP-Addresses */
91
+ };
92
+
93
+
94
+ /** Init srand, has to be called before entering mainloop */
95
+ void autoip_init(void);
96
+
97
+ /** Start AutoIP client */
98
+ err_t autoip_start(struct netif *netif);
99
+
100
+ /** Stop AutoIP client */
101
+ err_t autoip_stop(struct netif *netif);
102
+
103
+ /** Handles every incoming ARP Packet, called by etharp_arp_input */
104
+ void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr);
105
+
106
+ /** Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds */
107
+ void autoip_tmr(void);
108
+
109
+ /** Handle a possible change in the network configuration */
110
+ void autoip_network_changed(struct netif *netif);
111
+
112
+ #ifdef __cplusplus
113
+ }
114
+ #endif
115
+
116
+ #endif /* LWIP_AUTOIP */
117
+
118
+ #endif /* __LWIP_AUTOIP_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/icmp.h ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_ICMP_H__
35
+ #define __LWIP_ICMP_H__
36
+
37
+ #include "lwip/opt.h"
38
+ #include "lwip/pbuf.h"
39
+ #include "lwip/ip_addr.h"
40
+ #include "lwip/netif.h"
41
+
42
+ #ifdef __cplusplus
43
+ extern "C" {
44
+ #endif
45
+
46
+ #define ICMP_ER 0 /* echo reply */
47
+ #define ICMP_DUR 3 /* destination unreachable */
48
+ #define ICMP_SQ 4 /* source quench */
49
+ #define ICMP_RD 5 /* redirect */
50
+ #define ICMP_ECHO 8 /* echo */
51
+ #define ICMP_TE 11 /* time exceeded */
52
+ #define ICMP_PP 12 /* parameter problem */
53
+ #define ICMP_TS 13 /* timestamp */
54
+ #define ICMP_TSR 14 /* timestamp reply */
55
+ #define ICMP_IRQ 15 /* information request */
56
+ #define ICMP_IR 16 /* information reply */
57
+
58
+ enum icmp_dur_type {
59
+ ICMP_DUR_NET = 0, /* net unreachable */
60
+ ICMP_DUR_HOST = 1, /* host unreachable */
61
+ ICMP_DUR_PROTO = 2, /* protocol unreachable */
62
+ ICMP_DUR_PORT = 3, /* port unreachable */
63
+ ICMP_DUR_FRAG = 4, /* fragmentation needed and DF set */
64
+ ICMP_DUR_SR = 5 /* source route failed */
65
+ };
66
+
67
+ enum icmp_te_type {
68
+ ICMP_TE_TTL = 0, /* time to live exceeded in transit */
69
+ ICMP_TE_FRAG = 1 /* fragment reassembly time exceeded */
70
+ };
71
+
72
+ #ifdef PACK_STRUCT_USE_INCLUDES
73
+ # include "arch/bpstruct.h"
74
+ #endif
75
+ /** This is the standard ICMP header only that the u32_t data
76
+ * is splitted to two u16_t like ICMP echo needs it.
77
+ * This header is also used for other ICMP types that do not
78
+ * use the data part.
79
+ */
80
+ PACK_STRUCT_BEGIN
81
+ struct icmp_echo_hdr {
82
+ PACK_STRUCT_FIELD(u8_t type);
83
+ PACK_STRUCT_FIELD(u8_t code);
84
+ PACK_STRUCT_FIELD(u16_t chksum);
85
+ PACK_STRUCT_FIELD(u16_t id);
86
+ PACK_STRUCT_FIELD(u16_t seqno);
87
+ } PACK_STRUCT_STRUCT;
88
+ PACK_STRUCT_END
89
+ #ifdef PACK_STRUCT_USE_INCLUDES
90
+ # include "arch/epstruct.h"
91
+ #endif
92
+
93
+ #define ICMPH_TYPE(hdr) ((hdr)->type)
94
+ #define ICMPH_CODE(hdr) ((hdr)->code)
95
+
96
+ /** Combines type and code to an u16_t */
97
+ #define ICMPH_TYPE_SET(hdr, t) ((hdr)->type = (t))
98
+ #define ICMPH_CODE_SET(hdr, c) ((hdr)->code = (c))
99
+
100
+
101
+ #if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */
102
+
103
+ void icmp_input(struct pbuf *p, struct netif *inp);
104
+ void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t);
105
+ void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t);
106
+
107
+ #endif /* LWIP_ICMP */
108
+
109
+ #ifdef __cplusplus
110
+ }
111
+ #endif
112
+
113
+ #endif /* __LWIP_ICMP_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/igmp.h ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2002 CITEL Technologies Ltd.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions
9
+ * are met:
10
+ * 1. Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright
13
+ * notice, this list of conditions and the following disclaimer in the
14
+ * documentation and/or other materials provided with the distribution.
15
+ * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
16
+ * may be used to endorse or promote products derived from this software
17
+ * without specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
20
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
23
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
+ * SUCH DAMAGE.
30
+ *
31
+ * This file is a contribution to the lwIP TCP/IP stack.
32
+ * The Swedish Institute of Computer Science and Adam Dunkels
33
+ * are specifically granted permission to redistribute this
34
+ * source code.
35
+ */
36
+
37
+ #ifndef __LWIP_IGMP_H__
38
+ #define __LWIP_IGMP_H__
39
+
40
+ #include "lwip/opt.h"
41
+ #include "lwip/ip_addr.h"
42
+ #include "lwip/netif.h"
43
+ #include "lwip/pbuf.h"
44
+
45
+ #if LWIP_IGMP /* don't build if not configured for use in lwipopts.h */
46
+
47
+ #ifdef __cplusplus
48
+ extern "C" {
49
+ #endif
50
+
51
+ /*
52
+ * IGMP constants
53
+ */
54
+ #define IP_PROTO_IGMP 2
55
+ #define IGMP_TTL 1
56
+ #define IGMP_MINLEN 8
57
+ #define ROUTER_ALERT 0x9404
58
+ #define ROUTER_ALERTLEN 4
59
+
60
+ /*
61
+ * IGMP message types, including version number.
62
+ */
63
+ #define IGMP_MEMB_QUERY 0x11 /* Membership query */
64
+ #define IGMP_V1_MEMB_REPORT 0x12 /* Ver. 1 membership report */
65
+ #define IGMP_V2_MEMB_REPORT 0x16 /* Ver. 2 membership report */
66
+ #define IGMP_LEAVE_GROUP 0x17 /* Leave-group message */
67
+
68
+ /* IGMP timer */
69
+ #define IGMP_TMR_INTERVAL 100 /* Milliseconds */
70
+ #define IGMP_V1_DELAYING_MEMBER_TMR (1000/IGMP_TMR_INTERVAL)
71
+ #define IGMP_JOIN_DELAYING_MEMBER_TMR (500 /IGMP_TMR_INTERVAL)
72
+
73
+ /* MAC Filter Actions */
74
+ #define IGMP_DEL_MAC_FILTER 0
75
+ #define IGMP_ADD_MAC_FILTER 1
76
+
77
+ /* Group membership states */
78
+ #define IGMP_GROUP_NON_MEMBER 0
79
+ #define IGMP_GROUP_DELAYING_MEMBER 1
80
+ #define IGMP_GROUP_IDLE_MEMBER 2
81
+
82
+ /*
83
+ * IGMP packet format.
84
+ */
85
+ #ifdef PACK_STRUCT_USE_INCLUDES
86
+ # include "arch/bpstruct.h"
87
+ #endif
88
+ PACK_STRUCT_BEGIN
89
+ struct igmp_msg {
90
+ PACK_STRUCT_FIELD(u8_t igmp_msgtype);
91
+ PACK_STRUCT_FIELD(u8_t igmp_maxresp);
92
+ PACK_STRUCT_FIELD(u16_t igmp_checksum);
93
+ PACK_STRUCT_FIELD(struct ip_addr igmp_group_address);
94
+ } PACK_STRUCT_STRUCT;
95
+ PACK_STRUCT_END
96
+ #ifdef PACK_STRUCT_USE_INCLUDES
97
+ # include "arch/epstruct.h"
98
+ #endif
99
+
100
+ /*
101
+ * now a group structure - there is
102
+ * a list of groups for each interface
103
+ * these should really be linked from the interface, but
104
+ * if we keep them separate we will not affect the lwip original code
105
+ * too much
106
+ *
107
+ * There will be a group for the all systems group address but this
108
+ * will not run the state machine as it is used to kick off reports
109
+ * from all the other groups
110
+ */
111
+
112
+ struct igmp_group {
113
+ struct igmp_group *next;
114
+ struct netif *interface;
115
+ struct ip_addr group_address;
116
+ u8_t last_reporter_flag; /* signifies we were the last person to report */
117
+ u8_t group_state;
118
+ u16_t timer;
119
+ u8_t use; /* counter of simultaneous uses */
120
+ };
121
+
122
+
123
+ /* Prototypes */
124
+ void igmp_init(void);
125
+
126
+ err_t igmp_start( struct netif *netif);
127
+
128
+ err_t igmp_stop( struct netif *netif);
129
+
130
+ void igmp_report_groups( struct netif *netif);
131
+
132
+ struct igmp_group *igmp_lookfor_group( struct netif *ifp, struct ip_addr *addr);
133
+
134
+ struct igmp_group *igmp_lookup_group( struct netif *ifp, struct ip_addr *addr);
135
+
136
+ err_t igmp_remove_group( struct igmp_group *group);
137
+
138
+ void igmp_input( struct pbuf *p, struct netif *inp, struct ip_addr *dest);
139
+
140
+ err_t igmp_joingroup( struct ip_addr *ifaddr, struct ip_addr *groupaddr);
141
+
142
+ err_t igmp_leavegroup( struct ip_addr *ifaddr, struct ip_addr *groupaddr);
143
+
144
+ void igmp_tmr(void);
145
+
146
+ void igmp_timeout( struct igmp_group *group);
147
+
148
+ void igmp_start_timer( struct igmp_group *group, u8_t max_time);
149
+
150
+ void igmp_stop_timer( struct igmp_group *group);
151
+
152
+ void igmp_delaying_member( struct igmp_group *group, u8_t maxresp);
153
+
154
+ err_t igmp_ip_output_if( struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t proto, struct netif *netif);
155
+
156
+ void igmp_send( struct igmp_group *group, u8_t type);
157
+
158
+ #ifdef __cplusplus
159
+ }
160
+ #endif
161
+
162
+ #endif /* LWIP_IGMP */
163
+
164
+ #endif /* __LWIP_IGMP_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/inet.h ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_INET_H__
35
+ #define __LWIP_INET_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* For compatibility with BSD code */
44
+ struct in_addr {
45
+ u32_t s_addr;
46
+ };
47
+
48
+ #define INADDR_NONE ((u32_t)0xffffffffUL) /* 255.255.255.255 */
49
+ #define INADDR_LOOPBACK ((u32_t)0x7f000001UL) /* 127.0.0.1 */
50
+ #define INADDR_ANY ((u32_t)0x00000000UL) /* 0.0.0.0 */
51
+ #define INADDR_BROADCAST ((u32_t)0xffffffffUL) /* 255.255.255.255 */
52
+
53
+ u32_t inet_addr(const char *cp);
54
+ int inet_aton(const char *cp, struct in_addr *addr);
55
+ char *inet_ntoa(struct in_addr addr); /* returns ptr to static buffer; not reentrant! */
56
+
57
+ #ifdef htons
58
+ #undef htons
59
+ #endif /* htons */
60
+ #ifdef htonl
61
+ #undef htonl
62
+ #endif /* htonl */
63
+ #ifdef ntohs
64
+ #undef ntohs
65
+ #endif /* ntohs */
66
+ #ifdef ntohl
67
+ #undef ntohl
68
+ #endif /* ntohl */
69
+
70
+ #ifndef LWIP_PLATFORM_BYTESWAP
71
+ #define LWIP_PLATFORM_BYTESWAP 0
72
+ #endif
73
+
74
+ #if BYTE_ORDER == BIG_ENDIAN
75
+ #define htons(x) (x)
76
+ #define ntohs(x) (x)
77
+ #define htonl(x) (x)
78
+ #define ntohl(x) (x)
79
+ #else /* BYTE_ORDER != BIG_ENDIAN */
80
+ #ifdef LWIP_PREFIX_BYTEORDER_FUNCS
81
+ /* workaround for naming collisions on some platforms */
82
+ #define htons lwip_htons
83
+ #define ntohs lwip_ntohs
84
+ #define htonl lwip_htonl
85
+ #define ntohl lwip_ntohl
86
+ #endif /* LWIP_PREFIX_BYTEORDER_FUNCS */
87
+ #if LWIP_PLATFORM_BYTESWAP
88
+ #define htons(x) LWIP_PLATFORM_HTONS(x)
89
+ #define ntohs(x) LWIP_PLATFORM_HTONS(x)
90
+ #define htonl(x) LWIP_PLATFORM_HTONL(x)
91
+ #define ntohl(x) LWIP_PLATFORM_HTONL(x)
92
+ #else /* LWIP_PLATFORM_BYTESWAP */
93
+ u16_t htons(u16_t x);
94
+ u16_t ntohs(u16_t x);
95
+ u32_t htonl(u32_t x);
96
+ u32_t ntohl(u32_t x);
97
+ #endif /* LWIP_PLATFORM_BYTESWAP */
98
+
99
+ #endif /* BYTE_ORDER == BIG_ENDIAN */
100
+
101
+ #ifdef __cplusplus
102
+ }
103
+ #endif
104
+
105
+ #endif /* __LWIP_INET_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/inet_chksum.h ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_INET_CHKSUM_H__
35
+ #define __LWIP_INET_CHKSUM_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #include "lwip/pbuf.h"
40
+ #include "lwip/ip_addr.h"
41
+
42
+ #ifdef __cplusplus
43
+ extern "C" {
44
+ #endif
45
+
46
+ u16_t inet_chksum(void *dataptr, u16_t len);
47
+ u16_t inet_chksum_pbuf(struct pbuf *p);
48
+ u16_t inet_chksum_pseudo(struct pbuf *p,
49
+ struct ip_addr *src, struct ip_addr *dest,
50
+ u8_t proto, u16_t proto_len);
51
+ #if LWIP_UDPLITE
52
+ u16_t inet_chksum_pseudo_partial(struct pbuf *p,
53
+ struct ip_addr *src, struct ip_addr *dest,
54
+ u8_t proto, u16_t proto_len, u16_t chksum_len);
55
+ #endif
56
+
57
+ #ifdef __cplusplus
58
+ }
59
+ #endif
60
+
61
+ #endif /* __LWIP_INET_H__ */
62
+
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/ip.h ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_IP_H__
35
+ #define __LWIP_IP_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #include "lwip/def.h"
40
+ #include "lwip/pbuf.h"
41
+ #include "lwip/ip_addr.h"
42
+ #include "lwip/err.h"
43
+ #include "lwip/netif.h"
44
+
45
+ #ifdef __cplusplus
46
+ extern "C" {
47
+ #endif
48
+
49
+ /** Currently, the function ip_output_if_opt() is only used with IGMP */
50
+ #define IP_OPTIONS_SEND LWIP_IGMP
51
+
52
+ #define IP_HLEN 20
53
+
54
+ #define IP_PROTO_ICMP 1
55
+ #define IP_PROTO_UDP 17
56
+ #define IP_PROTO_UDPLITE 136
57
+ #define IP_PROTO_TCP 6
58
+
59
+ /* This is passed as the destination address to ip_output_if (not
60
+ to ip_output), meaning that an IP header already is constructed
61
+ in the pbuf. This is used when TCP retransmits. */
62
+ #ifdef IP_HDRINCL
63
+ #undef IP_HDRINCL
64
+ #endif /* IP_HDRINCL */
65
+ #define IP_HDRINCL NULL
66
+
67
+ #if LWIP_NETIF_HWADDRHINT
68
+ #define IP_PCB_ADDRHINT ;u8_t addr_hint
69
+ #else
70
+ #define IP_PCB_ADDRHINT
71
+ #endif /* LWIP_NETIF_HWADDRHINT */
72
+
73
+ /* This is the common part of all PCB types. It needs to be at the
74
+ beginning of a PCB type definition. It is located here so that
75
+ changes to this common part are made in one location instead of
76
+ having to change all PCB structs. */
77
+ #define IP_PCB \
78
+ /* ip addresses in network byte order */ \
79
+ struct ip_addr local_ip; \
80
+ struct ip_addr remote_ip; \
81
+ /* Socket options */ \
82
+ u16_t so_options; \
83
+ /* Type Of Service */ \
84
+ u8_t tos; \
85
+ /* Time To Live */ \
86
+ u8_t ttl \
87
+ /* link layer address resolution hint */ \
88
+ IP_PCB_ADDRHINT
89
+
90
+ struct ip_pcb {
91
+ /* Common members of all PCB types */
92
+ IP_PCB;
93
+ };
94
+
95
+ /*
96
+ * Option flags per-socket. These are the same like SO_XXX.
97
+ */
98
+ #define SOF_DEBUG (u16_t)0x0001U /* turn on debugging info recording */
99
+ #define SOF_ACCEPTCONN (u16_t)0x0002U /* socket has had listen() */
100
+ #define SOF_REUSEADDR (u16_t)0x0004U /* allow local address reuse */
101
+ #define SOF_KEEPALIVE (u16_t)0x0008U /* keep connections alive */
102
+ #define SOF_DONTROUTE (u16_t)0x0010U /* just use interface addresses */
103
+ #define SOF_BROADCAST (u16_t)0x0020U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
104
+ #define SOF_USELOOPBACK (u16_t)0x0040U /* bypass hardware when possible */
105
+ #define SOF_LINGER (u16_t)0x0080U /* linger on close if data present */
106
+ #define SOF_OOBINLINE (u16_t)0x0100U /* leave received OOB data in line */
107
+ #define SOF_REUSEPORT (u16_t)0x0200U /* allow local address & port reuse */
108
+
109
+
110
+ #ifdef PACK_STRUCT_USE_INCLUDES
111
+ # include "arch/bpstruct.h"
112
+ #endif
113
+ PACK_STRUCT_BEGIN
114
+ struct ip_hdr {
115
+ /* version / header length / type of service */
116
+ PACK_STRUCT_FIELD(u16_t _v_hl_tos);
117
+ /* total length */
118
+ PACK_STRUCT_FIELD(u16_t _len);
119
+ /* identification */
120
+ PACK_STRUCT_FIELD(u16_t _id);
121
+ /* fragment offset field */
122
+ PACK_STRUCT_FIELD(u16_t _offset);
123
+ #define IP_RF 0x8000 /* reserved fragment flag */
124
+ #define IP_DF 0x4000 /* dont fragment flag */
125
+ #define IP_MF 0x2000 /* more fragments flag */
126
+ #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
127
+ /* time to live / protocol*/
128
+ PACK_STRUCT_FIELD(u16_t _ttl_proto);
129
+ /* checksum */
130
+ PACK_STRUCT_FIELD(u16_t _chksum);
131
+ /* source and destination IP addresses */
132
+ PACK_STRUCT_FIELD(struct ip_addr src);
133
+ PACK_STRUCT_FIELD(struct ip_addr dest);
134
+ } PACK_STRUCT_STRUCT;
135
+ PACK_STRUCT_END
136
+ #ifdef PACK_STRUCT_USE_INCLUDES
137
+ # include "arch/epstruct.h"
138
+ #endif
139
+
140
+ #define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12)
141
+ #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
142
+ #define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff)
143
+ #define IPH_LEN(hdr) ((hdr)->_len)
144
+ #define IPH_ID(hdr) ((hdr)->_id)
145
+ #define IPH_OFFSET(hdr) ((hdr)->_offset)
146
+ #define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8)
147
+ #define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff)
148
+ #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
149
+
150
+ #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
151
+ #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
152
+ #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
153
+ #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
154
+ #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | ((u16_t)(ttl) << 8)))
155
+ #define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (IPH_TTL(hdr) << 8)))
156
+ #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
157
+
158
+ /** The interface that provided the packet for the current callback invocation. */
159
+ extern struct netif *current_netif;
160
+ /** Header of the input packet currently being processed. */
161
+ extern const struct ip_hdr *current_header;
162
+
163
+ #define ip_init() /* Compatibility define, not init needed. */
164
+ struct netif *ip_route(struct ip_addr *dest);
165
+ err_t ip_input(struct pbuf *p, struct netif *inp);
166
+ err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
167
+ u8_t ttl, u8_t tos, u8_t proto);
168
+ err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
169
+ u8_t ttl, u8_t tos, u8_t proto,
170
+ struct netif *netif);
171
+ #if LWIP_NETIF_HWADDRHINT
172
+ err_t ip_output_hinted(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
173
+ u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint);
174
+ #endif /* LWIP_NETIF_HWADDRHINT */
175
+ #if IP_OPTIONS_SEND
176
+ err_t ip_output_if_opt(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
177
+ u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
178
+ u16_t optlen);
179
+ #endif /* IP_OPTIONS_SEND */
180
+ /** Get the interface that received the current packet.
181
+ * This function must only be called from a receive callback (udp_recv,
182
+ * raw_recv, tcp_accept). It will return NULL otherwise. */
183
+ #define ip_current_netif() (current_netif)
184
+ /** Get the IP header of the current packet.
185
+ * This function must only be called from a receive callback (udp_recv,
186
+ * raw_recv, tcp_accept). It will return NULL otherwise. */
187
+ #define ip_current_header() (current_header)
188
+ #if IP_DEBUG
189
+ void ip_debug_print(struct pbuf *p);
190
+ #else
191
+ #define ip_debug_print(p)
192
+ #endif /* IP_DEBUG */
193
+
194
+ #ifdef __cplusplus
195
+ }
196
+ #endif
197
+
198
+ #endif /* __LWIP_IP_H__ */
199
+
200
+
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/ip_addr.h ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_IP_ADDR_H__
35
+ #define __LWIP_IP_ADDR_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #include "lwip/inet.h"
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ #ifdef PACK_STRUCT_USE_INCLUDES
46
+ # include "arch/bpstruct.h"
47
+ #endif
48
+ PACK_STRUCT_BEGIN
49
+ struct ip_addr {
50
+ PACK_STRUCT_FIELD(u32_t addr);
51
+ } PACK_STRUCT_STRUCT;
52
+ PACK_STRUCT_END
53
+ #ifdef PACK_STRUCT_USE_INCLUDES
54
+ # include "arch/epstruct.h"
55
+ #endif
56
+
57
+ /*
58
+ * struct ipaddr2 is used in the definition of the ARP packet format in
59
+ * order to support compilers that don't have structure packing.
60
+ */
61
+ #ifdef PACK_STRUCT_USE_INCLUDES
62
+ # include "arch/bpstruct.h"
63
+ #endif
64
+ PACK_STRUCT_BEGIN
65
+ struct ip_addr2 {
66
+ PACK_STRUCT_FIELD(u16_t addrw[2]);
67
+ } PACK_STRUCT_STRUCT;
68
+ PACK_STRUCT_END
69
+ #ifdef PACK_STRUCT_USE_INCLUDES
70
+ # include "arch/epstruct.h"
71
+ #endif
72
+
73
+ struct netif;
74
+
75
+ extern const struct ip_addr ip_addr_any;
76
+ extern const struct ip_addr ip_addr_broadcast;
77
+
78
+ /** IP_ADDR_ can be used as a fixed IP address
79
+ * for the wildcard and the broadcast address
80
+ */
81
+ #define IP_ADDR_ANY ((struct ip_addr *)&ip_addr_any)
82
+ #define IP_ADDR_BROADCAST ((struct ip_addr *)&ip_addr_broadcast)
83
+
84
+ /* Definitions of the bits in an Internet address integer.
85
+
86
+ On subnets, host and network parts are found according to
87
+ the subnet mask, not these masks. */
88
+
89
+ #define IN_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0)
90
+ #define IN_CLASSA_NET 0xff000000
91
+ #define IN_CLASSA_NSHIFT 24
92
+ #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
93
+ #define IN_CLASSA_MAX 128
94
+
95
+ #define IN_CLASSB(a) ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
96
+ #define IN_CLASSB_NET 0xffff0000
97
+ #define IN_CLASSB_NSHIFT 16
98
+ #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
99
+ #define IN_CLASSB_MAX 65536
100
+
101
+ #define IN_CLASSC(a) ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
102
+ #define IN_CLASSC_NET 0xffffff00
103
+ #define IN_CLASSC_NSHIFT 8
104
+ #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
105
+
106
+ #define IN_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
107
+ #define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */
108
+ #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */
109
+ #define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */
110
+ #define IN_MULTICAST(a) IN_CLASSD(a)
111
+
112
+ #define IN_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
113
+ #define IN_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
114
+
115
+ #define IN_LOOPBACKNET 127 /* official! */
116
+
117
+ #define IP4_ADDR(ipaddr, a,b,c,d) \
118
+ (ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \
119
+ ((u32_t)((b) & 0xff) << 16) | \
120
+ ((u32_t)((c) & 0xff) << 8) | \
121
+ (u32_t)((d) & 0xff))
122
+
123
+ #define ip_addr_set(dest, src) (dest)->addr = \
124
+ ((src) == NULL? 0:\
125
+ (src)->addr)
126
+ /**
127
+ * Determine if two address are on the same network.
128
+ *
129
+ * @arg addr1 IP address 1
130
+ * @arg addr2 IP address 2
131
+ * @arg mask network identifier mask
132
+ * @return !0 if the network identifiers of both address match
133
+ */
134
+ #define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
135
+ (mask)->addr) == \
136
+ ((addr2)->addr & \
137
+ (mask)->addr))
138
+ #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
139
+
140
+ #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
141
+
142
+ u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *);
143
+
144
+ #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000UL)) == ntohl(0xe0000000UL))
145
+
146
+ #define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL))
147
+
148
+ #define ip_addr_debug_print(debug, ipaddr) \
149
+ LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
150
+ ipaddr != NULL ? \
151
+ (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \
152
+ ipaddr != NULL ? \
153
+ (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0, \
154
+ ipaddr != NULL ? \
155
+ (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0, \
156
+ ipaddr != NULL ? \
157
+ (u16_t)ntohl((ipaddr)->addr) & 0xff : 0))
158
+
159
+ /* These are cast to u16_t, with the intent that they are often arguments
160
+ * to printf using the U16_F format from cc.h. */
161
+ #define ip4_addr1(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff)
162
+ #define ip4_addr2(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff)
163
+ #define ip4_addr3(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)
164
+ #define ip4_addr4(ipaddr) ((u16_t)(ntohl((ipaddr)->addr)) & 0xff)
165
+
166
+ /**
167
+ * Same as inet_ntoa() but takes a struct ip_addr*
168
+ */
169
+ #define ip_ntoa(addr) ((addr != NULL) ? inet_ntoa(*((struct in_addr*)(addr))) : "NULL")
170
+
171
+ #ifdef __cplusplus
172
+ }
173
+ #endif
174
+
175
+ #endif /* __LWIP_IP_ADDR_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4/lwip/ip_frag.h ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Jani Monoses <jani@iv.ro>
32
+ *
33
+ */
34
+
35
+ #ifndef __LWIP_IP_FRAG_H__
36
+ #define __LWIP_IP_FRAG_H__
37
+
38
+ #include "lwip/opt.h"
39
+ #include "lwip/err.h"
40
+ #include "lwip/pbuf.h"
41
+ #include "lwip/netif.h"
42
+ #include "lwip/ip_addr.h"
43
+ #include "lwip/ip.h"
44
+
45
+ #ifdef __cplusplus
46
+ extern "C" {
47
+ #endif
48
+
49
+ #if IP_REASSEMBLY
50
+ /* The IP reassembly timer interval in milliseconds. */
51
+ #define IP_TMR_INTERVAL 1000
52
+
53
+ /* IP reassembly helper struct.
54
+ * This is exported because memp needs to know the size.
55
+ */
56
+ struct ip_reassdata {
57
+ struct ip_reassdata *next;
58
+ struct pbuf *p;
59
+ struct ip_hdr iphdr;
60
+ u16_t datagram_len;
61
+ u8_t flags;
62
+ u8_t timer;
63
+ };
64
+
65
+ void ip_reass_init(void);
66
+ void ip_reass_tmr(void);
67
+ struct pbuf * ip_reass(struct pbuf *p);
68
+ #endif /* IP_REASSEMBLY */
69
+
70
+ #if IP_FRAG
71
+ err_t ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest);
72
+ #endif /* IP_FRAG */
73
+
74
+ #ifdef __cplusplus
75
+ }
76
+ #endif
77
+
78
+ #endif /* __LWIP_IP_FRAG_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/api.h ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_API_H__
35
+ #define __LWIP_API_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
40
+
41
+ #include <stddef.h> /* for size_t */
42
+
43
+ #include "lwip/netbuf.h"
44
+ #include "lwip/sys.h"
45
+ #include "lwip/ip_addr.h"
46
+ #include "lwip/err.h"
47
+
48
+ #ifdef __cplusplus
49
+ extern "C" {
50
+ #endif
51
+
52
+ /* Throughout this file, IP addresses and port numbers are expected to be in
53
+ * the same byte order as in the corresponding pcb.
54
+ */
55
+
56
+ /* Flags for netconn_write */
57
+ #define NETCONN_NOFLAG 0x00
58
+ #define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */
59
+ #define NETCONN_COPY 0x01
60
+ #define NETCONN_MORE 0x02
61
+
62
+ /* Helpers to process several netconn_types by the same code */
63
+ #define NETCONNTYPE_GROUP(t) (t&0xF0)
64
+ #define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
65
+
66
+ enum netconn_type {
67
+ NETCONN_INVALID = 0,
68
+ /* NETCONN_TCP Group */
69
+ NETCONN_TCP = 0x10,
70
+ /* NETCONN_UDP Group */
71
+ NETCONN_UDP = 0x20,
72
+ NETCONN_UDPLITE = 0x21,
73
+ NETCONN_UDPNOCHKSUM= 0x22,
74
+ /* NETCONN_RAW Group */
75
+ NETCONN_RAW = 0x40
76
+ };
77
+
78
+ enum netconn_state {
79
+ NETCONN_NONE,
80
+ NETCONN_WRITE,
81
+ NETCONN_LISTEN,
82
+ NETCONN_CONNECT,
83
+ NETCONN_CLOSE
84
+ };
85
+
86
+ enum netconn_evt {
87
+ NETCONN_EVT_RCVPLUS,
88
+ NETCONN_EVT_RCVMINUS,
89
+ NETCONN_EVT_SENDPLUS,
90
+ NETCONN_EVT_SENDMINUS
91
+ };
92
+
93
+ #if LWIP_IGMP
94
+ enum netconn_igmp {
95
+ NETCONN_JOIN,
96
+ NETCONN_LEAVE
97
+ };
98
+ #endif /* LWIP_IGMP */
99
+
100
+ /* forward-declare some structs to avoid to include their headers */
101
+ struct ip_pcb;
102
+ struct tcp_pcb;
103
+ struct udp_pcb;
104
+ struct raw_pcb;
105
+ struct netconn;
106
+
107
+ /** A callback prototype to inform about events for a netconn */
108
+ typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len);
109
+
110
+ /** A netconn descriptor */
111
+ struct netconn {
112
+ /** type of the netconn (TCP, UDP or RAW) */
113
+ enum netconn_type type;
114
+ /** current state of the netconn */
115
+ enum netconn_state state;
116
+ /** the lwIP internal protocol control block */
117
+ union {
118
+ struct ip_pcb *ip;
119
+ struct tcp_pcb *tcp;
120
+ struct udp_pcb *udp;
121
+ struct raw_pcb *raw;
122
+ } pcb;
123
+ /** the last error this netconn had */
124
+ err_t err;
125
+ /** sem that is used to synchroneously execute functions in the core context */
126
+ sys_sem_t op_completed;
127
+ /** mbox where received packets are stored until they are fetched
128
+ by the netconn application thread (can grow quite big) */
129
+ sys_mbox_t recvmbox;
130
+ /** mbox where new connections are stored until processed
131
+ by the application thread */
132
+ sys_mbox_t acceptmbox;
133
+ /** only used for socket layer */
134
+ int socket;
135
+ #if LWIP_SO_RCVTIMEO
136
+ /** timeout to wait for new data to be received
137
+ (or connections to arrive for listening netconns) */
138
+ int recv_timeout;
139
+ #endif /* LWIP_SO_RCVTIMEO */
140
+ #if LWIP_SO_RCVBUF
141
+ /** maximum amount of bytes queued in recvmbox */
142
+ int recv_bufsize;
143
+ #endif /* LWIP_SO_RCVBUF */
144
+ s16_t recv_avail;
145
+ #if LWIP_TCP
146
+ /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
147
+ this temporarily stores the message. */
148
+ struct api_msg_msg *write_msg;
149
+ /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
150
+ this temporarily stores how much is already sent. */
151
+ size_t write_offset;
152
+ #if LWIP_TCPIP_CORE_LOCKING
153
+ /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
154
+ this temporarily stores whether to wake up the original application task
155
+ if data couldn't be sent in the first try. */
156
+ u8_t write_delayed;
157
+ #endif /* LWIP_TCPIP_CORE_LOCKING */
158
+ #endif /* LWIP_TCP */
159
+ /** A callback function that is informed about events for this netconn */
160
+ netconn_callback callback;
161
+ };
162
+
163
+ /* Register an Network connection event */
164
+ #define API_EVENT(c,e,l) if (c->callback) { \
165
+ (*c->callback)(c, e, l); \
166
+ }
167
+
168
+ /* Network connection functions: */
169
+ #define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL)
170
+ #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
171
+ struct
172
+ netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
173
+ netconn_callback callback);
174
+ err_t netconn_delete (struct netconn *conn);
175
+ /** Get the type of a netconn (as enum netconn_type). */
176
+ #define netconn_type(conn) (conn->type)
177
+
178
+ err_t netconn_getaddr (struct netconn *conn,
179
+ struct ip_addr *addr,
180
+ u16_t *port,
181
+ u8_t local);
182
+ #define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
183
+ #define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
184
+
185
+ err_t netconn_bind (struct netconn *conn,
186
+ struct ip_addr *addr,
187
+ u16_t port);
188
+ err_t netconn_connect (struct netconn *conn,
189
+ struct ip_addr *addr,
190
+ u16_t port);
191
+ err_t netconn_disconnect (struct netconn *conn);
192
+ err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
193
+ #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
194
+ struct netconn * netconn_accept (struct netconn *conn);
195
+ struct netbuf * netconn_recv (struct netconn *conn);
196
+ err_t netconn_sendto (struct netconn *conn,
197
+ struct netbuf *buf, struct ip_addr *addr, u16_t port);
198
+ err_t netconn_send (struct netconn *conn,
199
+ struct netbuf *buf);
200
+ err_t netconn_write (struct netconn *conn,
201
+ const void *dataptr, size_t size,
202
+ u8_t apiflags);
203
+ err_t netconn_close (struct netconn *conn);
204
+
205
+ #if LWIP_IGMP
206
+ err_t netconn_join_leave_group (struct netconn *conn,
207
+ struct ip_addr *multiaddr,
208
+ struct ip_addr *interface,
209
+ enum netconn_igmp join_or_leave);
210
+ #endif /* LWIP_IGMP */
211
+ #if LWIP_DNS
212
+ err_t netconn_gethostbyname(const char *name, struct ip_addr *addr);
213
+ #endif /* LWIP_DNS */
214
+
215
+ #define netconn_err(conn) ((conn)->err)
216
+ #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
217
+
218
+ #ifdef __cplusplus
219
+ }
220
+ #endif
221
+
222
+ #endif /* LWIP_NETCONN */
223
+
224
+ #endif /* __LWIP_API_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/api_msg.h ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_API_MSG_H__
35
+ #define __LWIP_API_MSG_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
40
+
41
+ #include <stddef.h> /* for size_t */
42
+
43
+ #include "lwip/ip_addr.h"
44
+ #include "lwip/err.h"
45
+ #include "lwip/sys.h"
46
+ #include "lwip/igmp.h"
47
+ #include "lwip/api.h"
48
+
49
+ #ifdef __cplusplus
50
+ extern "C" {
51
+ #endif
52
+
53
+ /* IP addresses and port numbers are expected to be in
54
+ * the same byte order as in the corresponding pcb.
55
+ */
56
+ /** This struct includes everything that is necessary to execute a function
57
+ for a netconn in another thread context (mainly used to process netconns
58
+ in the tcpip_thread context to be thread safe). */
59
+ struct api_msg_msg {
60
+ /** The netconn which to process - always needed: it includes the semaphore
61
+ which is used to block the application thread until the function finished. */
62
+ struct netconn *conn;
63
+ /** Depending on the executed function, one of these union members is used */
64
+ union {
65
+ /** used for do_send */
66
+ struct netbuf *b;
67
+ /** used for do_newconn */
68
+ struct {
69
+ u8_t proto;
70
+ } n;
71
+ /** used for do_bind and do_connect */
72
+ struct {
73
+ struct ip_addr *ipaddr;
74
+ u16_t port;
75
+ } bc;
76
+ /** used for do_getaddr */
77
+ struct {
78
+ struct ip_addr *ipaddr;
79
+ u16_t *port;
80
+ u8_t local;
81
+ } ad;
82
+ /** used for do_write */
83
+ struct {
84
+ const void *dataptr;
85
+ size_t len;
86
+ u8_t apiflags;
87
+ } w;
88
+ /** used for do_recv */
89
+ struct {
90
+ u16_t len;
91
+ } r;
92
+ #if LWIP_IGMP
93
+ /** used for do_join_leave_group */
94
+ struct {
95
+ struct ip_addr *multiaddr;
96
+ struct ip_addr *interface;
97
+ enum netconn_igmp join_or_leave;
98
+ } jl;
99
+ #endif /* LWIP_IGMP */
100
+ #if TCP_LISTEN_BACKLOG
101
+ struct {
102
+ u8_t backlog;
103
+ } lb;
104
+ #endif /* TCP_LISTEN_BACKLOG */
105
+ } msg;
106
+ };
107
+
108
+ /** This struct contains a function to execute in another thread context and
109
+ a struct api_msg_msg that serves as an argument for this function.
110
+ This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */
111
+ struct api_msg {
112
+ /** function to execute in tcpip_thread context */
113
+ void (* function)(struct api_msg_msg *msg);
114
+ /** arguments for this function */
115
+ struct api_msg_msg msg;
116
+ };
117
+
118
+ #if LWIP_DNS
119
+ /** As do_gethostbyname requires more arguments but doesn't require a netconn,
120
+ it has its own struct (to avoid struct api_msg getting bigger than necessary).
121
+ do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
122
+ (see netconn_gethostbyname). */
123
+ struct dns_api_msg {
124
+ /** Hostname to query or dotted IP address string */
125
+ const char *name;
126
+ /** Rhe resolved address is stored here */
127
+ struct ip_addr *addr;
128
+ /** This semaphore is posted when the name is resolved, the application thread
129
+ should wait on it. */
130
+ sys_sem_t sem;
131
+ /** Errors are given back here */
132
+ err_t *err;
133
+ };
134
+ #endif /* LWIP_DNS */
135
+
136
+ void do_newconn ( struct api_msg_msg *msg);
137
+ void do_delconn ( struct api_msg_msg *msg);
138
+ void do_bind ( struct api_msg_msg *msg);
139
+ void do_connect ( struct api_msg_msg *msg);
140
+ void do_disconnect ( struct api_msg_msg *msg);
141
+ void do_listen ( struct api_msg_msg *msg);
142
+ void do_send ( struct api_msg_msg *msg);
143
+ void do_recv ( struct api_msg_msg *msg);
144
+ void do_write ( struct api_msg_msg *msg);
145
+ void do_getaddr ( struct api_msg_msg *msg);
146
+ void do_close ( struct api_msg_msg *msg);
147
+ #if LWIP_IGMP
148
+ void do_join_leave_group( struct api_msg_msg *msg);
149
+ #endif /* LWIP_IGMP */
150
+
151
+ #if LWIP_DNS
152
+ void do_gethostbyname(void *arg);
153
+ #endif /* LWIP_DNS */
154
+
155
+ struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
156
+ void netconn_free(struct netconn *conn);
157
+
158
+ #ifdef __cplusplus
159
+ }
160
+ #endif
161
+
162
+ #endif /* LWIP_NETCONN */
163
+
164
+ #endif /* __LWIP_API_MSG_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/arch.h ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_ARCH_H__
35
+ #define __LWIP_ARCH_H__
36
+
37
+ #ifndef LITTLE_ENDIAN
38
+ #define LITTLE_ENDIAN 1234
39
+ #endif
40
+
41
+ #ifndef BIG_ENDIAN
42
+ #define BIG_ENDIAN 4321
43
+ #endif
44
+
45
+ #include "arch/cc.h"
46
+
47
+ /** Temporary: define format string for size_t if not defined in cc.h */
48
+ #ifndef SZT_F
49
+ #define SZT_F U32_F
50
+ #endif /* SZT_F */
51
+
52
+ #ifdef __cplusplus
53
+ extern "C" {
54
+ #endif
55
+
56
+ #ifndef PACK_STRUCT_BEGIN
57
+ #define PACK_STRUCT_BEGIN
58
+ #endif /* PACK_STRUCT_BEGIN */
59
+
60
+ #ifndef PACK_STRUCT_END
61
+ #define PACK_STRUCT_END
62
+ #endif /* PACK_STRUCT_END */
63
+
64
+ #ifndef PACK_STRUCT_FIELD
65
+ #define PACK_STRUCT_FIELD(x) x
66
+ #endif /* PACK_STRUCT_FIELD */
67
+
68
+
69
+ #ifndef LWIP_UNUSED_ARG
70
+ #define LWIP_UNUSED_ARG(x) (void)x
71
+ #endif /* LWIP_UNUSED_ARG */
72
+
73
+
74
+ #ifdef LWIP_PROVIDE_ERRNO
75
+
76
+ #define EPERM 1 /* Operation not permitted */
77
+ #define ENOENT 2 /* No such file or directory */
78
+ #define ESRCH 3 /* No such process */
79
+ #define EINTR 4 /* Interrupted system call */
80
+ #define EIO 5 /* I/O error */
81
+ #define ENXIO 6 /* No such device or address */
82
+ #define E2BIG 7 /* Arg list too long */
83
+ #define ENOEXEC 8 /* Exec format error */
84
+ #define EBADF 9 /* Bad file number */
85
+ #define ECHILD 10 /* No child processes */
86
+ #define EAGAIN 11 /* Try again */
87
+ #define ENOMEM 12 /* Out of memory */
88
+ #define EACCES 13 /* Permission denied */
89
+ #define EFAULT 14 /* Bad address */
90
+ #define ENOTBLK 15 /* Block device required */
91
+ #define EBUSY 16 /* Device or resource busy */
92
+ #define EEXIST 17 /* File exists */
93
+ #define EXDEV 18 /* Cross-device link */
94
+ #define ENODEV 19 /* No such device */
95
+ #define ENOTDIR 20 /* Not a directory */
96
+ #define EISDIR 21 /* Is a directory */
97
+ #define EINVAL 22 /* Invalid argument */
98
+ #define ENFILE 23 /* File table overflow */
99
+ #define EMFILE 24 /* Too many open files */
100
+ #define ENOTTY 25 /* Not a typewriter */
101
+ #define ETXTBSY 26 /* Text file busy */
102
+ #define EFBIG 27 /* File too large */
103
+ #define ENOSPC 28 /* No space left on device */
104
+ #define ESPIPE 29 /* Illegal seek */
105
+ #define EROFS 30 /* Read-only file system */
106
+ #define EMLINK 31 /* Too many links */
107
+ #define EPIPE 32 /* Broken pipe */
108
+ #define EDOM 33 /* Math argument out of domain of func */
109
+ #define ERANGE 34 /* Math result not representable */
110
+ #define EDEADLK 35 /* Resource deadlock would occur */
111
+ #define ENAMETOOLONG 36 /* File name too long */
112
+ #define ENOLCK 37 /* No record locks available */
113
+ #define ENOSYS 38 /* Function not implemented */
114
+ #define ENOTEMPTY 39 /* Directory not empty */
115
+ #define ELOOP 40 /* Too many symbolic links encountered */
116
+ #define EWOULDBLOCK EAGAIN /* Operation would block */
117
+ #define ENOMSG 42 /* No message of desired type */
118
+ #define EIDRM 43 /* Identifier removed */
119
+ #define ECHRNG 44 /* Channel number out of range */
120
+ #define EL2NSYNC 45 /* Level 2 not synchronized */
121
+ #define EL3HLT 46 /* Level 3 halted */
122
+ #define EL3RST 47 /* Level 3 reset */
123
+ #define ELNRNG 48 /* Link number out of range */
124
+ #define EUNATCH 49 /* Protocol driver not attached */
125
+ #define ENOCSI 50 /* No CSI structure available */
126
+ #define EL2HLT 51 /* Level 2 halted */
127
+ #define EBADE 52 /* Invalid exchange */
128
+ #define EBADR 53 /* Invalid request descriptor */
129
+ #define EXFULL 54 /* Exchange full */
130
+ #define ENOANO 55 /* No anode */
131
+ #define EBADRQC 56 /* Invalid request code */
132
+ #define EBADSLT 57 /* Invalid slot */
133
+
134
+ #define EDEADLOCK EDEADLK
135
+
136
+ #define EBFONT 59 /* Bad font file format */
137
+ #define ENOSTR 60 /* Device not a stream */
138
+ #define ENODATA 61 /* No data available */
139
+ #define ETIME 62 /* Timer expired */
140
+ #define ENOSR 63 /* Out of streams resources */
141
+ #define ENONET 64 /* Machine is not on the network */
142
+ #define ENOPKG 65 /* Package not installed */
143
+ #define EREMOTE 66 /* Object is remote */
144
+ #define ENOLINK 67 /* Link has been severed */
145
+ #define EADV 68 /* Advertise error */
146
+ #define ESRMNT 69 /* Srmount error */
147
+ #define ECOMM 70 /* Communication error on send */
148
+ #define EPROTO 71 /* Protocol error */
149
+ #define EMULTIHOP 72 /* Multihop attempted */
150
+ #define EDOTDOT 73 /* RFS specific error */
151
+ #define EBADMSG 74 /* Not a data message */
152
+ #define EOVERFLOW 75 /* Value too large for defined data type */
153
+ #define ENOTUNIQ 76 /* Name not unique on network */
154
+ #define EBADFD 77 /* File descriptor in bad state */
155
+ #define EREMCHG 78 /* Remote address changed */
156
+ #define ELIBACC 79 /* Can not access a needed shared library */
157
+ #define ELIBBAD 80 /* Accessing a corrupted shared library */
158
+ #define ELIBSCN 81 /* .lib section in a.out corrupted */
159
+ #define ELIBMAX 82 /* Attempting to link in too many shared libraries */
160
+ #define ELIBEXEC 83 /* Cannot exec a shared library directly */
161
+ #define EILSEQ 84 /* Illegal byte sequence */
162
+ #define ERESTART 85 /* Interrupted system call should be restarted */
163
+ #define ESTRPIPE 86 /* Streams pipe error */
164
+ #define EUSERS 87 /* Too many users */
165
+ #define ENOTSOCK 88 /* Socket operation on non-socket */
166
+ #define EDESTADDRREQ 89 /* Destination address required */
167
+ #define EMSGSIZE 90 /* Message too long */
168
+ #define EPROTOTYPE 91 /* Protocol wrong type for socket */
169
+ #define ENOPROTOOPT 92 /* Protocol not available */
170
+ #define EPROTONOSUPPORT 93 /* Protocol not supported */
171
+ #define ESOCKTNOSUPPORT 94 /* Socket type not supported */
172
+ #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
173
+ #define EPFNOSUPPORT 96 /* Protocol family not supported */
174
+ #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
175
+ #define EADDRINUSE 98 /* Address already in use */
176
+ #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
177
+ #define ENETDOWN 100 /* Network is down */
178
+ #define ENETUNREACH 101 /* Network is unreachable */
179
+ #define ENETRESET 102 /* Network dropped connection because of reset */
180
+ #define ECONNABORTED 103 /* Software caused connection abort */
181
+ #define ECONNRESET 104 /* Connection reset by peer */
182
+ #define ENOBUFS 105 /* No buffer space available */
183
+ #define EISCONN 106 /* Transport endpoint is already connected */
184
+ #define ENOTCONN 107 /* Transport endpoint is not connected */
185
+ #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
186
+ #define ETOOMANYREFS 109 /* Too many references: cannot splice */
187
+ #define ETIMEDOUT 110 /* Connection timed out */
188
+ #define ECONNREFUSED 111 /* Connection refused */
189
+ #define EHOSTDOWN 112 /* Host is down */
190
+ #define EHOSTUNREACH 113 /* No route to host */
191
+ #define EALREADY 114 /* Operation already in progress */
192
+ #define EINPROGRESS 115 /* Operation now in progress */
193
+ #define ESTALE 116 /* Stale NFS file handle */
194
+ #define EUCLEAN 117 /* Structure needs cleaning */
195
+ #define ENOTNAM 118 /* Not a XENIX named type file */
196
+ #define ENAVAIL 119 /* No XENIX semaphores available */
197
+ #define EISNAM 120 /* Is a named type file */
198
+ #define EREMOTEIO 121 /* Remote I/O error */
199
+ #define EDQUOT 122 /* Quota exceeded */
200
+
201
+ #define ENOMEDIUM 123 /* No medium found */
202
+ #define EMEDIUMTYPE 124 /* Wrong medium type */
203
+
204
+
205
+ #define ENSROK 0 /* DNS server returned answer with no data */
206
+ #define ENSRNODATA 160 /* DNS server returned answer with no data */
207
+ #define ENSRFORMERR 161 /* DNS server claims query was misformatted */
208
+ #define ENSRSERVFAIL 162 /* DNS server returned general failure */
209
+ #define ENSRNOTFOUND 163 /* Domain name not found */
210
+ #define ENSRNOTIMP 164 /* DNS server does not implement requested operation */
211
+ #define ENSRREFUSED 165 /* DNS server refused query */
212
+ #define ENSRBADQUERY 166 /* Misformatted DNS query */
213
+ #define ENSRBADNAME 167 /* Misformatted domain name */
214
+ #define ENSRBADFAMILY 168 /* Unsupported address family */
215
+ #define ENSRBADRESP 169 /* Misformatted DNS reply */
216
+ #define ENSRCONNREFUSED 170 /* Could not contact DNS servers */
217
+ #define ENSRTIMEOUT 171 /* Timeout while contacting DNS servers */
218
+ #define ENSROF 172 /* End of file */
219
+ #define ENSRFILE 173 /* Error reading file */
220
+ #define ENSRNOMEM 174 /* Out of memory */
221
+ #define ENSRDESTRUCTION 175 /* Application terminated lookup */
222
+ #define ENSRQUERYDOMAINTOOLONG 176 /* Domain name is too long */
223
+ #define ENSRCNAMELOOP 177 /* Domain name is too long */
224
+
225
+ #ifndef errno
226
+ extern int errno;
227
+ #endif
228
+
229
+ #endif /* LWIP_PROVIDE_ERRNO */
230
+
231
+ #ifdef __cplusplus
232
+ }
233
+ #endif
234
+
235
+ #endif /* __LWIP_ARCH_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/debug.h ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_DEBUG_H__
35
+ #define __LWIP_DEBUG_H__
36
+
37
+ #include "lwip/arch.h"
38
+
39
+ /** lower two bits indicate debug level
40
+ * - 0 all
41
+ * - 1 warning
42
+ * - 2 serious
43
+ * - 3 severe
44
+ */
45
+ #define LWIP_DBG_LEVEL_ALL 0x00
46
+ #define LWIP_DBG_LEVEL_OFF LWIP_DBG_LEVEL_ALL /* compatibility define only */
47
+ #define LWIP_DBG_LEVEL_WARNING 0x01 /* bad checksums, dropped packets, ... */
48
+ #define LWIP_DBG_LEVEL_SERIOUS 0x02 /* memory allocation failures, ... */
49
+ #define LWIP_DBG_LEVEL_SEVERE 0x03
50
+ #define LWIP_DBG_MASK_LEVEL 0x03
51
+
52
+ /** flag for LWIP_DEBUGF to enable that debug message */
53
+ #define LWIP_DBG_ON 0x80U
54
+ /** flag for LWIP_DEBUGF to disable that debug message */
55
+ #define LWIP_DBG_OFF 0x00U
56
+
57
+ /** flag for LWIP_DEBUGF indicating a tracing message (to follow program flow) */
58
+ #define LWIP_DBG_TRACE 0x40U
59
+ /** flag for LWIP_DEBUGF indicating a state debug message (to follow module states) */
60
+ #define LWIP_DBG_STATE 0x20U
61
+ /** flag for LWIP_DEBUGF indicating newly added code, not thoroughly tested yet */
62
+ #define LWIP_DBG_FRESH 0x10U
63
+ /** flag for LWIP_DEBUGF to halt after printing this debug message */
64
+ #define LWIP_DBG_HALT 0x08U
65
+
66
+ #ifndef LWIP_NOASSERT
67
+ #define LWIP_ASSERT(message, assertion) do { if(!(assertion)) \
68
+ LWIP_PLATFORM_ASSERT(message); } while(0)
69
+ #else /* LWIP_NOASSERT */
70
+ #define LWIP_ASSERT(message, assertion)
71
+ #endif /* LWIP_NOASSERT */
72
+
73
+ /** if "expression" isn't true, then print "message" and execute "handler" expression */
74
+ #ifndef LWIP_ERROR
75
+ #define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
76
+ LWIP_PLATFORM_ASSERT(message); handler;}} while(0)
77
+ #endif /* LWIP_ERROR */
78
+
79
+ #ifdef LWIP_DEBUG
80
+ /** print debug message only if debug message type is enabled...
81
+ * AND is of correct type AND is at least LWIP_DBG_LEVEL
82
+ */
83
+ #define LWIP_DEBUGF(debug, message) do { \
84
+ if ( \
85
+ ((debug) & LWIP_DBG_ON) && \
86
+ ((debug) & LWIP_DBG_TYPES_ON) && \
87
+ ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \
88
+ LWIP_PLATFORM_DIAG(message); \
89
+ if ((debug) & LWIP_DBG_HALT) { \
90
+ while(1); \
91
+ } \
92
+ } \
93
+ } while(0)
94
+
95
+ #else /* LWIP_DEBUG */
96
+ #define LWIP_DEBUGF(debug, message)
97
+ #endif /* LWIP_DEBUG */
98
+
99
+ #endif /* __LWIP_DEBUG_H__ */
100
+
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/def.h ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_DEF_H__
35
+ #define __LWIP_DEF_H__
36
+
37
+ /* this might define NULL already */
38
+ #include "lwip/arch.h"
39
+
40
+ #define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y))
41
+ #define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y))
42
+
43
+ #ifndef NULL
44
+ #define NULL ((void *)0)
45
+ #endif
46
+
47
+
48
+ #endif /* __LWIP_DEF_H__ */
49
+
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/dhcp.h ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /** @file
4
+ */
5
+
6
+ #ifndef __LWIP_DHCP_H__
7
+ #define __LWIP_DHCP_H__
8
+
9
+ #include "lwip/opt.h"
10
+
11
+ #if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
12
+
13
+ #include "lwip/netif.h"
14
+ #include "lwip/udp.h"
15
+
16
+ #ifdef __cplusplus
17
+ extern "C" {
18
+ #endif
19
+
20
+ /** period (in seconds) of the application calling dhcp_coarse_tmr() */
21
+ #define DHCP_COARSE_TIMER_SECS 60
22
+ /** period (in milliseconds) of the application calling dhcp_coarse_tmr() */
23
+ #define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL)
24
+ /** period (in milliseconds) of the application calling dhcp_fine_tmr() */
25
+ #define DHCP_FINE_TIMER_MSECS 500
26
+
27
+ struct dhcp
28
+ {
29
+ /** transaction identifier of last sent request */
30
+ u32_t xid;
31
+ /** our connection to the DHCP server */
32
+ struct udp_pcb *pcb;
33
+ /** incoming msg */
34
+ struct dhcp_msg *msg_in;
35
+ /** incoming msg options */
36
+ void *options_in;
37
+ /** ingoing msg options length */
38
+ u16_t options_in_len;
39
+ /** current DHCP state machine state */
40
+ u8_t state;
41
+ /** retries of current request */
42
+ u8_t tries;
43
+
44
+ struct pbuf *p_out; /* pbuf of outcoming msg */
45
+ struct dhcp_msg *msg_out; /* outgoing msg */
46
+ u16_t options_out_len; /* outgoing msg options length */
47
+ u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
48
+ u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
49
+ u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
50
+ struct ip_addr server_ip_addr; /* dhcp server address that offered this lease */
51
+ struct ip_addr offered_ip_addr;
52
+ struct ip_addr offered_sn_mask;
53
+ struct ip_addr offered_gw_addr;
54
+ struct ip_addr offered_bc_addr;
55
+ #define DHCP_MAX_DNS 2
56
+ u32_t dns_count; /* actual number of DNS servers obtained */
57
+ struct ip_addr offered_dns_addr[DHCP_MAX_DNS]; /* DNS server addresses */
58
+
59
+ u32_t offered_t0_lease; /* lease period (in seconds) */
60
+ u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
61
+ u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period) */
62
+ #if LWIP_DHCP_AUTOIP_COOP
63
+ u8_t autoip_coop_state;
64
+ #endif
65
+ /** Patch #1308
66
+ * TODO: See dhcp.c "TODO"s
67
+ */
68
+ #if 0
69
+ struct ip_addr offered_si_addr;
70
+ u8_t *boot_file_name;
71
+ #endif
72
+ };
73
+
74
+ /* MUST be compiled with "pack structs" or equivalent! */
75
+ #ifdef PACK_STRUCT_USE_INCLUDES
76
+ # include "arch/bpstruct.h"
77
+ #endif
78
+ PACK_STRUCT_BEGIN
79
+ /** minimum set of fields of any DHCP message */
80
+ struct dhcp_msg
81
+ {
82
+ PACK_STRUCT_FIELD(u8_t op);
83
+ PACK_STRUCT_FIELD(u8_t htype);
84
+ PACK_STRUCT_FIELD(u8_t hlen);
85
+ PACK_STRUCT_FIELD(u8_t hops);
86
+ PACK_STRUCT_FIELD(u32_t xid);
87
+ PACK_STRUCT_FIELD(u16_t secs);
88
+ PACK_STRUCT_FIELD(u16_t flags);
89
+ PACK_STRUCT_FIELD(struct ip_addr ciaddr);
90
+ PACK_STRUCT_FIELD(struct ip_addr yiaddr);
91
+ PACK_STRUCT_FIELD(struct ip_addr siaddr);
92
+ PACK_STRUCT_FIELD(struct ip_addr giaddr);
93
+ #define DHCP_CHADDR_LEN 16U
94
+ PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]);
95
+ #define DHCP_SNAME_LEN 64U
96
+ PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]);
97
+ #define DHCP_FILE_LEN 128U
98
+ PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]);
99
+ PACK_STRUCT_FIELD(u32_t cookie);
100
+ #define DHCP_MIN_OPTIONS_LEN 68U
101
+ /** make sure user does not configure this too small */
102
+ #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
103
+ # undef DHCP_OPTIONS_LEN
104
+ #endif
105
+ /** allow this to be configured in lwipopts.h, but not too small */
106
+ #if (!defined(DHCP_OPTIONS_LEN))
107
+ /** set this to be sufficient for your options in outgoing DHCP msgs */
108
+ # define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
109
+ #endif
110
+ PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]);
111
+ } PACK_STRUCT_STRUCT;
112
+ PACK_STRUCT_END
113
+ #ifdef PACK_STRUCT_USE_INCLUDES
114
+ # include "arch/epstruct.h"
115
+ #endif
116
+
117
+ /** start DHCP configuration */
118
+ err_t dhcp_start(struct netif *netif);
119
+ /** enforce early lease renewal (not needed normally)*/
120
+ err_t dhcp_renew(struct netif *netif);
121
+ /** release the DHCP lease, usually called before dhcp_stop()*/
122
+ err_t dhcp_release(struct netif *netif);
123
+ /** stop DHCP configuration */
124
+ void dhcp_stop(struct netif *netif);
125
+ /** inform server of our manual IP address */
126
+ void dhcp_inform(struct netif *netif);
127
+ /** Handle a possible change in the network configuration */
128
+ void dhcp_network_changed(struct netif *netif);
129
+
130
+ /** if enabled, check whether the offered IP address is not in use, using ARP */
131
+ #if DHCP_DOES_ARP_CHECK
132
+ void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr);
133
+ #endif
134
+
135
+ /** to be called every minute */
136
+ void dhcp_coarse_tmr(void);
137
+ /** to be called every half second */
138
+ void dhcp_fine_tmr(void);
139
+
140
+ /** DHCP message item offsets and length */
141
+ #define DHCP_MSG_OFS (UDP_DATA_OFS)
142
+ #define DHCP_OP_OFS (DHCP_MSG_OFS + 0)
143
+ #define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1)
144
+ #define DHCP_HLEN_OFS (DHCP_MSG_OFS + 2)
145
+ #define DHCP_HOPS_OFS (DHCP_MSG_OFS + 3)
146
+ #define DHCP_XID_OFS (DHCP_MSG_OFS + 4)
147
+ #define DHCP_SECS_OFS (DHCP_MSG_OFS + 8)
148
+ #define DHCP_FLAGS_OFS (DHCP_MSG_OFS + 10)
149
+ #define DHCP_CIADDR_OFS (DHCP_MSG_OFS + 12)
150
+ #define DHCP_YIADDR_OFS (DHCP_MSG_OFS + 16)
151
+ #define DHCP_SIADDR_OFS (DHCP_MSG_OFS + 20)
152
+ #define DHCP_GIADDR_OFS (DHCP_MSG_OFS + 24)
153
+ #define DHCP_CHADDR_OFS (DHCP_MSG_OFS + 28)
154
+ #define DHCP_SNAME_OFS (DHCP_MSG_OFS + 44)
155
+ #define DHCP_FILE_OFS (DHCP_MSG_OFS + 108)
156
+ #define DHCP_MSG_LEN 236
157
+
158
+ #define DHCP_COOKIE_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN)
159
+ #define DHCP_OPTIONS_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN + 4)
160
+
161
+ #define DHCP_CLIENT_PORT 68
162
+ #define DHCP_SERVER_PORT 67
163
+
164
+ /** DHCP client states */
165
+ #define DHCP_REQUESTING 1
166
+ #define DHCP_INIT 2
167
+ #define DHCP_REBOOTING 3
168
+ #define DHCP_REBINDING 4
169
+ #define DHCP_RENEWING 5
170
+ #define DHCP_SELECTING 6
171
+ #define DHCP_INFORMING 7
172
+ #define DHCP_CHECKING 8
173
+ #define DHCP_PERMANENT 9
174
+ #define DHCP_BOUND 10
175
+ /** not yet implemented #define DHCP_RELEASING 11 */
176
+ #define DHCP_BACKING_OFF 12
177
+ #define DHCP_OFF 13
178
+
179
+ /** AUTOIP cooperatation flags */
180
+ #define DHCP_AUTOIP_COOP_STATE_OFF 0
181
+ #define DHCP_AUTOIP_COOP_STATE_ON 1
182
+
183
+ #define DHCP_BOOTREQUEST 1
184
+ #define DHCP_BOOTREPLY 2
185
+
186
+ #define DHCP_DISCOVER 1
187
+ #define DHCP_OFFER 2
188
+ #define DHCP_REQUEST 3
189
+ #define DHCP_DECLINE 4
190
+ #define DHCP_ACK 5
191
+ #define DHCP_NAK 6
192
+ #define DHCP_RELEASE 7
193
+ #define DHCP_INFORM 8
194
+
195
+ #define DHCP_HTYPE_ETH 1
196
+
197
+ #define DHCP_HLEN_ETH 6
198
+
199
+ #define DHCP_BROADCAST_FLAG 15
200
+ #define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST)
201
+
202
+ /** BootP options */
203
+ #define DHCP_OPTION_PAD 0
204
+ #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
205
+ #define DHCP_OPTION_ROUTER 3
206
+ #define DHCP_OPTION_DNS_SERVER 6
207
+ #define DHCP_OPTION_HOSTNAME 12
208
+ #define DHCP_OPTION_IP_TTL 23
209
+ #define DHCP_OPTION_MTU 26
210
+ #define DHCP_OPTION_BROADCAST 28
211
+ #define DHCP_OPTION_TCP_TTL 37
212
+ #define DHCP_OPTION_END 255
213
+
214
+ /** DHCP options */
215
+ #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
216
+ #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
217
+ #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
218
+
219
+ #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
220
+ #define DHCP_OPTION_MESSAGE_TYPE_LEN 1
221
+
222
+
223
+ #define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
224
+ #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */
225
+
226
+ #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */
227
+ #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
228
+
229
+ #define DHCP_OPTION_T1 58 /* T1 renewal time */
230
+ #define DHCP_OPTION_T2 59 /* T2 rebinding time */
231
+ #define DHCP_OPTION_US 60
232
+ #define DHCP_OPTION_CLIENT_ID 61
233
+ #define DHCP_OPTION_TFTP_SERVERNAME 66
234
+ #define DHCP_OPTION_BOOTFILE 67
235
+
236
+ /** possible combinations of overloading the file and sname fields with options */
237
+ #define DHCP_OVERLOAD_NONE 0
238
+ #define DHCP_OVERLOAD_FILE 1
239
+ #define DHCP_OVERLOAD_SNAME 2
240
+ #define DHCP_OVERLOAD_SNAME_FILE 3
241
+
242
+ #ifdef __cplusplus
243
+ }
244
+ #endif
245
+
246
+ #endif /* LWIP_DHCP */
247
+
248
+ #endif /*__LWIP_DHCP_H__*/
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/dns.h ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * lwip DNS resolver header file.
5
+
6
+ * Author: Jim Pettinato
7
+ * April 2007
8
+
9
+ * ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels.
10
+ *
11
+ * Redistribution and use in source and binary forms, with or without
12
+ * modification, are permitted provided that the following conditions
13
+ * are met:
14
+ * 1. Redistributions of source code must retain the above copyright
15
+ * notice, this list of conditions and the following disclaimer.
16
+ * 2. Redistributions in binary form must reproduce the above copyright
17
+ * notice, this list of conditions and the following disclaimer in the
18
+ * documentation and/or other materials provided with the distribution.
19
+ * 3. The name of the author may not be used to endorse or promote
20
+ * products derived from this software without specific prior
21
+ * written permission.
22
+ *
23
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
24
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
27
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ */
35
+
36
+ #ifndef __LWIP_DNS_H__
37
+ #define __LWIP_DNS_H__
38
+
39
+ #include "lwip/opt.h"
40
+
41
+ #if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
42
+
43
+ /** DNS timer period */
44
+ #define DNS_TMR_INTERVAL 1000
45
+
46
+ /** DNS field TYPE used for "Resource Records" */
47
+ #define DNS_RRTYPE_A 1 /* a host address */
48
+ #define DNS_RRTYPE_NS 2 /* an authoritative name server */
49
+ #define DNS_RRTYPE_MD 3 /* a mail destination (Obsolete - use MX) */
50
+ #define DNS_RRTYPE_MF 4 /* a mail forwarder (Obsolete - use MX) */
51
+ #define DNS_RRTYPE_CNAME 5 /* the canonical name for an alias */
52
+ #define DNS_RRTYPE_SOA 6 /* marks the start of a zone of authority */
53
+ #define DNS_RRTYPE_MB 7 /* a mailbox domain name (EXPERIMENTAL) */
54
+ #define DNS_RRTYPE_MG 8 /* a mail group member (EXPERIMENTAL) */
55
+ #define DNS_RRTYPE_MR 9 /* a mail rename domain name (EXPERIMENTAL) */
56
+ #define DNS_RRTYPE_NULL 10 /* a null RR (EXPERIMENTAL) */
57
+ #define DNS_RRTYPE_WKS 11 /* a well known service description */
58
+ #define DNS_RRTYPE_PTR 12 /* a domain name pointer */
59
+ #define DNS_RRTYPE_HINFO 13 /* host information */
60
+ #define DNS_RRTYPE_MINFO 14 /* mailbox or mail list information */
61
+ #define DNS_RRTYPE_MX 15 /* mail exchange */
62
+ #define DNS_RRTYPE_TXT 16 /* text strings */
63
+
64
+ /** DNS field CLASS used for "Resource Records" */
65
+ #define DNS_RRCLASS_IN 1 /* the Internet */
66
+ #define DNS_RRCLASS_CS 2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */
67
+ #define DNS_RRCLASS_CH 3 /* the CHAOS class */
68
+ #define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */
69
+ #define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */
70
+
71
+ /** Callback which is invoked when a hostname is found.
72
+ * A function of this type must be implemented by the application using the DNS resolver.
73
+ * @param name pointer to the name that was looked up.
74
+ * @param ipaddr pointer to a struct ip_addr containing the IP address of the hostname,
75
+ * or NULL if the name could not be found (or on any other error).
76
+ * @param callback_arg a user-specified callback argument passed to dns_gethostbyname
77
+ */
78
+ typedef void (*dns_found_callback)(const char *name, struct ip_addr *ipaddr, void *callback_arg);
79
+
80
+
81
+ void dns_init(void);
82
+
83
+ void dns_tmr(void);
84
+
85
+ void dns_setserver(u8_t numdns, struct ip_addr *dnsserver);
86
+
87
+ struct ip_addr dns_getserver(u8_t numdns);
88
+
89
+ err_t dns_gethostbyname(const char *hostname, struct ip_addr *addr,
90
+ dns_found_callback found, void *callback_arg);
91
+
92
+ #if DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC
93
+ int dns_local_removehost(const char *hostname, const struct ip_addr *addr);
94
+ err_t dns_local_addhost(const char *hostname, const struct ip_addr *addr);
95
+ #endif /* DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
96
+
97
+ #endif /* LWIP_DNS */
98
+
99
+ #endif /* __LWIP_DNS_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/err.h ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_ERR_H__
35
+ #define __LWIP_ERR_H__
36
+
37
+ #include "lwip/opt.h"
38
+ #include "lwip/arch.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /** Define LWIP_ERR_T in cc.h if you want to use
45
+ * a different type for your platform (must be signed). */
46
+ #ifdef LWIP_ERR_T
47
+ typedef LWIP_ERR_T err_t;
48
+ #else /* LWIP_ERR_T */
49
+ typedef s8_t err_t;
50
+ #endif /* LWIP_ERR_T*/
51
+
52
+ /* Definitions for error constants. */
53
+
54
+ #define ERR_OK 0 /* No error, everything OK. */
55
+ #define ERR_MEM -1 /* Out of memory error. */
56
+ #define ERR_BUF -2 /* Buffer error. */
57
+ #define ERR_TIMEOUT -3 /* Timeout. */
58
+ #define ERR_RTE -4 /* Routing problem. */
59
+
60
+ #define ERR_IS_FATAL(e) ((e) < ERR_RTE)
61
+
62
+ #define ERR_ABRT -5 /* Connection aborted. */
63
+ #define ERR_RST -6 /* Connection reset. */
64
+ #define ERR_CLSD -7 /* Connection closed. */
65
+ #define ERR_CONN -8 /* Not connected. */
66
+
67
+ #define ERR_VAL -9 /* Illegal value. */
68
+
69
+ #define ERR_ARG -10 /* Illegal argument. */
70
+
71
+ #define ERR_USE -11 /* Address in use. */
72
+
73
+ #define ERR_IF -12 /* Low-level netif error */
74
+ #define ERR_ISCONN -13 /* Already connected. */
75
+
76
+ #define ERR_INPROGRESS -14 /* Operation in progress */
77
+
78
+
79
+ #ifdef LWIP_DEBUG
80
+ extern const char *lwip_strerr(err_t err);
81
+ #else
82
+ #define lwip_strerr(x) ""
83
+ #endif /* LWIP_DEBUG */
84
+
85
+ #ifdef __cplusplus
86
+ }
87
+ #endif
88
+
89
+ #endif /* __LWIP_ERR_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/init.h ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_INIT_H__
35
+ #define __LWIP_INIT_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /** X.x.x: Major version of the stack */
44
+ #define LWIP_VERSION_MAJOR 1U
45
+ /** x.X.x: Minor version of the stack */
46
+ #define LWIP_VERSION_MINOR 3U
47
+ /** x.x.X: Revision of the stack */
48
+ #define LWIP_VERSION_REVISION 2U
49
+ /** For release candidates, this is set to 1..254
50
+ * For official releases, this is set to 255 (LWIP_RC_RELEASE)
51
+ * For development versions (CVS), this is set to 0 (LWIP_RC_DEVELOPMENT) */
52
+ #define LWIP_VERSION_RC 255U
53
+
54
+ /** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */
55
+ #define LWIP_RC_RELEASE 255U
56
+ /** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for CVS versions */
57
+ #define LWIP_RC_DEVELOPMENT 0U
58
+
59
+ #define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE)
60
+ #define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT)
61
+ #define LWIP_VERSION_IS_RC ((LWIP_VERSION_RC != LWIP_RC_RELEASE) && (LWIP_VERSION_RC != LWIP_RC_DEVELOPMENT))
62
+
63
+ /** Provides the version of the stack */
64
+ #define LWIP_VERSION (LWIP_VERSION_MAJOR << 24 | LWIP_VERSION_MINOR << 16 | \
65
+ LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC)
66
+
67
+ /* Modules initialization */
68
+ void lwip_init(void);
69
+
70
+ #ifdef __cplusplus
71
+ }
72
+ #endif
73
+
74
+ #endif /* __LWIP_INIT_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/mem.h ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_MEM_H__
35
+ #define __LWIP_MEM_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ #if MEM_LIBC_MALLOC
44
+
45
+ #include <stddef.h> /* for size_t */
46
+
47
+ typedef size_t mem_size_t;
48
+
49
+ /* aliases for C library malloc() */
50
+ #define mem_init()
51
+ /* in case C library malloc() needs extra protection,
52
+ * allow these defines to be overridden.
53
+ */
54
+ #ifndef mem_free
55
+ #define mem_free free
56
+ #endif
57
+ #ifndef mem_malloc
58
+ #define mem_malloc malloc
59
+ #endif
60
+ #ifndef mem_calloc
61
+ #define mem_calloc calloc
62
+ #endif
63
+ #ifndef mem_realloc
64
+ static void *mem_realloc(void *mem, mem_size_t size)
65
+ {
66
+ LWIP_UNUSED_ARG(size);
67
+ return mem;
68
+ }
69
+ #endif
70
+ #else /* MEM_LIBC_MALLOC */
71
+
72
+ /* MEM_SIZE would have to be aligned, but using 64000 here instead of
73
+ * 65535 leaves some room for alignment...
74
+ */
75
+ #if MEM_SIZE > 64000l
76
+ typedef u32_t mem_size_t;
77
+ #else
78
+ typedef u16_t mem_size_t;
79
+ #endif /* MEM_SIZE > 64000 */
80
+
81
+ #if MEM_USE_POOLS
82
+ /** mem_init is not used when using pools instead of a heap */
83
+ #define mem_init()
84
+ /** mem_realloc is not used when using pools instead of a heap:
85
+ we can't free part of a pool element and don't want to copy the rest */
86
+ #define mem_realloc(mem, size) (mem)
87
+ #else /* MEM_USE_POOLS */
88
+ /* lwIP alternative malloc */
89
+ void mem_init(void);
90
+ void *mem_realloc(void *mem, mem_size_t size);
91
+ #endif /* MEM_USE_POOLS */
92
+ void *mem_malloc(mem_size_t size);
93
+ void *mem_calloc(mem_size_t count, mem_size_t size);
94
+ void mem_free(void *mem);
95
+ #endif /* MEM_LIBC_MALLOC */
96
+
97
+ #ifndef LWIP_MEM_ALIGN_SIZE
98
+ #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))
99
+ #endif
100
+
101
+ #ifndef LWIP_MEM_ALIGN
102
+ #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
103
+ #endif
104
+
105
+ #ifdef __cplusplus
106
+ }
107
+ #endif
108
+
109
+ #endif /* __LWIP_MEM_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/memp.h ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+
35
+ #ifndef __LWIP_MEMP_H__
36
+ #define __LWIP_MEMP_H__
37
+
38
+ #include "lwip/opt.h"
39
+
40
+ #ifdef __cplusplus
41
+ extern "C" {
42
+ #endif
43
+
44
+ /* Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end */
45
+ typedef enum {
46
+ #define LWIP_MEMPOOL(name,num,size,desc) MEMP_##name,
47
+ #include "lwip/memp_std.h"
48
+ MEMP_MAX
49
+ } memp_t;
50
+
51
+ #if MEM_USE_POOLS
52
+ /* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */
53
+ typedef enum {
54
+ /* Get the first (via:
55
+ MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/
56
+ MEMP_POOL_HELPER_FIRST = ((u8_t)
57
+ #define LWIP_MEMPOOL(name,num,size,desc)
58
+ #define LWIP_MALLOC_MEMPOOL_START 1
59
+ #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
60
+ #define LWIP_MALLOC_MEMPOOL_END
61
+ #include "lwip/memp_std.h"
62
+ ) ,
63
+ /* Get the last (via:
64
+ MEMP_POOL_HELPER_END = ((u8_t) 0 + MEMP_POOL_A*0 + MEMP_POOL_B*0 + MEMP_POOL_C*1) */
65
+ MEMP_POOL_HELPER_LAST = ((u8_t)
66
+ #define LWIP_MEMPOOL(name,num,size,desc)
67
+ #define LWIP_MALLOC_MEMPOOL_START
68
+ #define LWIP_MALLOC_MEMPOOL(num, size) 0 + MEMP_POOL_##size *
69
+ #define LWIP_MALLOC_MEMPOOL_END 1
70
+ #include "lwip/memp_std.h"
71
+ )
72
+ } memp_pool_helper_t;
73
+
74
+ /* The actual start and stop values are here (cast them over)
75
+ We use this helper type and these defines so we can avoid using const memp_t values */
76
+ #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST)
77
+ #define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST)
78
+ #endif /* MEM_USE_POOLS */
79
+
80
+ #if MEMP_MEM_MALLOC || MEM_USE_POOLS
81
+ extern const u16_t memp_sizes[MEMP_MAX];
82
+ #endif /* MEMP_MEM_MALLOC || MEM_USE_POOLS */
83
+
84
+ #if MEMP_MEM_MALLOC
85
+
86
+ #include "mem.h"
87
+
88
+ #define memp_init()
89
+ #define memp_malloc(type) mem_malloc(memp_sizes[type])
90
+ #define memp_free(type, mem) mem_free(mem)
91
+
92
+ #else /* MEMP_MEM_MALLOC */
93
+
94
+ #if MEM_USE_POOLS
95
+ /** This structure is used to save the pool one element came from. */
96
+ struct memp_malloc_helper
97
+ {
98
+ memp_t poolnr;
99
+ };
100
+ #endif /* MEM_USE_POOLS */
101
+
102
+ void memp_init(void);
103
+
104
+ #if MEMP_OVERFLOW_CHECK
105
+ void *memp_malloc_fn(memp_t type, const char* file, const int line);
106
+ #define memp_malloc(t) memp_malloc_fn((t), __FILE__, __LINE__)
107
+ #else
108
+ void *memp_malloc(memp_t type);
109
+ #endif
110
+ void memp_free(memp_t type, void *mem);
111
+
112
+ #endif /* MEMP_MEM_MALLOC */
113
+
114
+ #ifdef __cplusplus
115
+ }
116
+ #endif
117
+
118
+ #endif /* __LWIP_MEMP_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/memp_std.h ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * SETUP: Make sure we define everything we will need.
5
+ *
6
+ * We have create three types of pools:
7
+ * 1) MEMPOOL - standard pools
8
+ * 2) MALLOC_MEMPOOL - to be used by mem_malloc in mem.c
9
+ * 3) PBUF_MEMPOOL - a mempool of pbuf's, so include space for the pbuf struct
10
+ *
11
+ * If the include'r doesn't require any special treatment of each of the types
12
+ * above, then will declare #2 & #3 to be just standard mempools.
13
+ */
14
+ #ifndef LWIP_MALLOC_MEMPOOL
15
+ /* This treats "malloc pools" just like any other pool.
16
+ The pools are a little bigger to provide 'size' as the amount of user data. */
17
+ #define LWIP_MALLOC_MEMPOOL(num, size) LWIP_MEMPOOL(POOL_##size, num, (size + sizeof(struct memp_malloc_helper)), "MALLOC_"#size)
18
+ #define LWIP_MALLOC_MEMPOOL_START
19
+ #define LWIP_MALLOC_MEMPOOL_END
20
+ #endif /* LWIP_MALLOC_MEMPOOL */
21
+
22
+ #ifndef LWIP_PBUF_MEMPOOL
23
+ /* This treats "pbuf pools" just like any other pool.
24
+ * Allocates buffers for a pbuf struct AND a payload size */
25
+ #define LWIP_PBUF_MEMPOOL(name, num, payload, desc) LWIP_MEMPOOL(name, num, (MEMP_ALIGN_SIZE(sizeof(struct pbuf)) + MEMP_ALIGN_SIZE(payload)), desc)
26
+ #endif /* LWIP_PBUF_MEMPOOL */
27
+
28
+
29
+ /*
30
+ * A list of internal pools used by LWIP.
31
+ *
32
+ * LWIP_MEMPOOL(pool_name, number_elements, element_size, pool_description)
33
+ * creates a pool name MEMP_pool_name. description is used in stats.c
34
+ */
35
+ #if LWIP_RAW
36
+ LWIP_MEMPOOL(RAW_PCB, MEMP_NUM_RAW_PCB, sizeof(struct raw_pcb), "RAW_PCB")
37
+ #endif /* LWIP_RAW */
38
+
39
+ #if LWIP_UDP
40
+ LWIP_MEMPOOL(UDP_PCB, MEMP_NUM_UDP_PCB, sizeof(struct udp_pcb), "UDP_PCB")
41
+ #endif /* LWIP_UDP */
42
+
43
+ #if LWIP_TCP
44
+ LWIP_MEMPOOL(TCP_PCB, MEMP_NUM_TCP_PCB, sizeof(struct tcp_pcb), "TCP_PCB")
45
+ LWIP_MEMPOOL(TCP_PCB_LISTEN, MEMP_NUM_TCP_PCB_LISTEN, sizeof(struct tcp_pcb_listen), "TCP_PCB_LISTEN")
46
+ LWIP_MEMPOOL(TCP_SEG, MEMP_NUM_TCP_SEG, sizeof(struct tcp_seg), "TCP_SEG")
47
+ #endif /* LWIP_TCP */
48
+
49
+ #if IP_REASSEMBLY
50
+ LWIP_MEMPOOL(REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip_reassdata), "REASSDATA")
51
+ #endif /* IP_REASSEMBLY */
52
+
53
+ #if LWIP_NETCONN
54
+ LWIP_MEMPOOL(NETBUF, MEMP_NUM_NETBUF, sizeof(struct netbuf), "NETBUF")
55
+ LWIP_MEMPOOL(NETCONN, MEMP_NUM_NETCONN, sizeof(struct netconn), "NETCONN")
56
+ #endif /* LWIP_NETCONN */
57
+
58
+ #if NO_SYS==0
59
+ LWIP_MEMPOOL(TCPIP_MSG_API, MEMP_NUM_TCPIP_MSG_API, sizeof(struct tcpip_msg), "TCPIP_MSG_API")
60
+ LWIP_MEMPOOL(TCPIP_MSG_INPKT,MEMP_NUM_TCPIP_MSG_INPKT, sizeof(struct tcpip_msg), "TCPIP_MSG_INPKT")
61
+ #endif /* NO_SYS==0 */
62
+
63
+ #if ARP_QUEUEING
64
+ LWIP_MEMPOOL(ARP_QUEUE, MEMP_NUM_ARP_QUEUE, sizeof(struct etharp_q_entry), "ARP_QUEUE")
65
+ #endif /* ARP_QUEUEING */
66
+
67
+ #if LWIP_IGMP
68
+ LWIP_MEMPOOL(IGMP_GROUP, MEMP_NUM_IGMP_GROUP, sizeof(struct igmp_group), "IGMP_GROUP")
69
+ #endif /* LWIP_IGMP */
70
+
71
+ #if NO_SYS==0
72
+ LWIP_MEMPOOL(SYS_TIMEOUT, MEMP_NUM_SYS_TIMEOUT, sizeof(struct sys_timeo), "SYS_TIMEOUT")
73
+ #endif /* NO_SYS==0 */
74
+
75
+
76
+ /*
77
+ * A list of pools of pbuf's used by LWIP.
78
+ *
79
+ * LWIP_PBUF_MEMPOOL(pool_name, number_elements, pbuf_payload_size, pool_description)
80
+ * creates a pool name MEMP_pool_name. description is used in stats.c
81
+ * This allocates enough space for the pbuf struct and a payload.
82
+ * (Example: pbuf_payload_size=0 allocates only size for the struct)
83
+ */
84
+ LWIP_PBUF_MEMPOOL(PBUF, MEMP_NUM_PBUF, 0, "PBUF_REF/ROM")
85
+ LWIP_PBUF_MEMPOOL(PBUF_POOL, PBUF_POOL_SIZE, PBUF_POOL_BUFSIZE, "PBUF_POOL")
86
+
87
+
88
+ /*
89
+ * Allow for user-defined pools; this must be explicitly set in lwipopts.h
90
+ * since the default is to NOT look for lwippools.h
91
+ */
92
+ #if MEMP_USE_CUSTOM_POOLS
93
+ #include "lwippools.h"
94
+ #endif /* MEMP_USE_CUSTOM_POOLS */
95
+
96
+ /*
97
+ * REQUIRED CLEANUP: Clear up so we don't get "multiply defined" error later
98
+ * (#undef is ignored for something that is not defined)
99
+ */
100
+ #undef LWIP_MEMPOOL
101
+ #undef LWIP_MALLOC_MEMPOOL
102
+ #undef LWIP_MALLOC_MEMPOOL_START
103
+ #undef LWIP_MALLOC_MEMPOOL_END
104
+ #undef LWIP_PBUF_MEMPOOL
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/netbuf.h ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_NETBUF_H__
35
+ #define __LWIP_NETBUF_H__
36
+
37
+ #include "lwip/opt.h"
38
+ #include "lwip/pbuf.h"
39
+ #include "lwip/ip_addr.h"
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ struct netbuf {
46
+ struct pbuf *p, *ptr;
47
+ struct ip_addr *addr;
48
+ u16_t port;
49
+ #if LWIP_NETBUF_RECVINFO
50
+ struct ip_addr *toaddr;
51
+ u16_t toport;
52
+ #endif /* LWIP_NETBUF_RECVINFO */
53
+ };
54
+
55
+ /* Network buffer functions: */
56
+ struct netbuf * netbuf_new (void);
57
+ void netbuf_delete (struct netbuf *buf);
58
+ void * netbuf_alloc (struct netbuf *buf, u16_t size);
59
+ void netbuf_free (struct netbuf *buf);
60
+ err_t netbuf_ref (struct netbuf *buf,
61
+ const void *dataptr, u16_t size);
62
+ void netbuf_chain (struct netbuf *head,
63
+ struct netbuf *tail);
64
+
65
+ u16_t netbuf_len (struct netbuf *buf);
66
+ err_t netbuf_data (struct netbuf *buf,
67
+ void **dataptr, u16_t *len);
68
+ s8_t netbuf_next (struct netbuf *buf);
69
+ void netbuf_first (struct netbuf *buf);
70
+
71
+
72
+ #define netbuf_copy_partial(buf, dataptr, len, offset) \
73
+ pbuf_copy_partial((buf)->p, (dataptr), (len), (offset))
74
+ #define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0)
75
+ #define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len)
76
+ #define netbuf_len(buf) ((buf)->p->tot_len)
77
+ #define netbuf_fromaddr(buf) ((buf)->addr)
78
+ #define netbuf_fromport(buf) ((buf)->port)
79
+ #if LWIP_NETBUF_RECVINFO
80
+ #define netbuf_destaddr(buf) ((buf)->toaddr)
81
+ #define netbuf_destport(buf) ((buf)->toport)
82
+ #endif /* LWIP_NETBUF_RECVINFO */
83
+
84
+ #ifdef __cplusplus
85
+ }
86
+ #endif
87
+
88
+ #endif /* __LWIP_NETBUF_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/netdb.h ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Redistribution and use in source and binary forms, with or without modification,
5
+ * are permitted provided that the following conditions are met:
6
+ *
7
+ * 1. Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * 3. The name of the author may not be used to endorse or promote products
13
+ * derived from this software without specific prior written permission.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
18
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
24
+ * OF SUCH DAMAGE.
25
+ *
26
+ * This file is part of the lwIP TCP/IP stack.
27
+ *
28
+ * Author: Simon Goldschmidt
29
+ *
30
+ */
31
+
32
+ #include "lwip/opt.h"
33
+
34
+ #if LWIP_DNS && LWIP_SOCKET
35
+
36
+ #include <stddef.h> /* for size_t */
37
+
38
+ #include "lwip/sockets.h"
39
+
40
+ /* some rarely used options */
41
+ #ifndef LWIP_DNS_API_DECLARE_H_ERRNO
42
+ #define LWIP_DNS_API_DECLARE_H_ERRNO 1
43
+ #endif
44
+
45
+ #ifndef LWIP_DNS_API_DEFINE_ERRORS
46
+ #define LWIP_DNS_API_DEFINE_ERRORS 1
47
+ #endif
48
+
49
+ #ifndef LWIP_DNS_API_DECLARE_STRUCTS
50
+ #define LWIP_DNS_API_DECLARE_STRUCTS 1
51
+ #endif
52
+
53
+ #if LWIP_DNS_API_DEFINE_ERRORS
54
+ /** Errors used by the DNS API functions, h_errno can be one of them */
55
+ #define EAI_NONAME 200
56
+ #define EAI_SERVICE 201
57
+ #define EAI_FAIL 202
58
+ #define EAI_MEMORY 203
59
+
60
+ #define HOST_NOT_FOUND 210
61
+ #define NO_DATA 211
62
+ #define NO_RECOVERY 212
63
+ #define TRY_AGAIN 213
64
+ #endif /* LWIP_DNS_API_DEFINE_ERRORS */
65
+
66
+ #if LWIP_DNS_API_DECLARE_STRUCTS
67
+ struct hostent {
68
+ char *h_name; /* Official name of the host. */
69
+ char **h_aliases; /* A pointer to an array of pointers to alternative host names,
70
+ terminated by a null pointer. */
71
+ int h_addrtype; /* Address type. */
72
+ int h_length; /* The length, in bytes, of the address. */
73
+ char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
74
+ network byte order) for the host, terminated by a null pointer. */
75
+ #define h_addr h_addr_list[0] /* for backward compatibility */
76
+ };
77
+
78
+ struct addrinfo {
79
+ int ai_flags; /* Input flags. */
80
+ int ai_family; /* Address family of socket. */
81
+ int ai_socktype; /* Socket type. */
82
+ int ai_protocol; /* Protocol of socket. */
83
+ socklen_t ai_addrlen; /* Length of socket address. */
84
+ struct sockaddr *ai_addr; /* Socket address of socket. */
85
+ char *ai_canonname; /* Canonical name of service location. */
86
+ struct addrinfo *ai_next; /* Pointer to next in list. */
87
+ };
88
+ #endif /* LWIP_DNS_API_DECLARE_STRUCTS */
89
+
90
+ #if LWIP_DNS_API_DECLARE_H_ERRNO
91
+ /* application accessable error code set by the DNS API functions */
92
+ extern int h_errno;
93
+ #endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/
94
+
95
+ struct hostent *lwip_gethostbyname(const char *name);
96
+ int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
97
+ size_t buflen, struct hostent **result, int *h_errnop);
98
+ void lwip_freeaddrinfo(struct addrinfo *ai);
99
+ int lwip_getaddrinfo(const char *nodename,
100
+ const char *servname,
101
+ const struct addrinfo *hints,
102
+ struct addrinfo **res);
103
+
104
+ #if LWIP_COMPAT_SOCKETS
105
+ #define gethostbyname(name) lwip_gethostbyname(name)
106
+ #define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \
107
+ lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop)
108
+ #define freeaddrinfo(addrinfo) lwip_freeaddrinfo(addrinfo)
109
+ #define getaddrinfo(nodname, servname, hints, res) \
110
+ lwip_getaddrinfo(nodname, servname, hints, res)
111
+ #endif /* LWIP_COMPAT_SOCKETS */
112
+
113
+ #endif /* LWIP_DNS && LWIP_SOCKET */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/netif.h ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_NETIF_H__
35
+ #define __LWIP_NETIF_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
40
+
41
+ #include "lwip/err.h"
42
+
43
+ #include "lwip/ip_addr.h"
44
+
45
+ #include "lwip/inet.h"
46
+ #include "lwip/pbuf.h"
47
+ #if LWIP_DHCP
48
+ struct dhcp;
49
+ #endif
50
+ #if LWIP_AUTOIP
51
+ struct autoip;
52
+ #endif
53
+
54
+ #ifdef __cplusplus
55
+ extern "C" {
56
+ #endif
57
+
58
+ /* Throughout this file, IP addresses are expected to be in
59
+ * the same byte order as in IP_PCB. */
60
+
61
+ /** must be the maximum of all used hardware address lengths
62
+ across all types of interfaces in use */
63
+ #define NETIF_MAX_HWADDR_LEN 6U
64
+
65
+ /** TODO: define the use (where, when, whom) of netif flags */
66
+
67
+ /** whether the network interface is 'up'. this is
68
+ * a software flag used to control whether this network
69
+ * interface is enabled and processes traffic.
70
+ */
71
+ #define NETIF_FLAG_UP 0x01U
72
+ /** if set, the netif has broadcast capability */
73
+ #define NETIF_FLAG_BROADCAST 0x02U
74
+ /** if set, the netif is one end of a point-to-point connection */
75
+ #define NETIF_FLAG_POINTTOPOINT 0x04U
76
+ /** if set, the interface is configured using DHCP */
77
+ #define NETIF_FLAG_DHCP 0x08U
78
+ /** if set, the interface has an active link
79
+ * (set by the network interface driver) */
80
+ #define NETIF_FLAG_LINK_UP 0x10U
81
+ /** if set, the netif is an device using ARP */
82
+ #define NETIF_FLAG_ETHARP 0x20U
83
+ /** if set, the netif has IGMP capability */
84
+ #define NETIF_FLAG_IGMP 0x40U
85
+
86
+ /** Generic data structure used for all lwIP network interfaces.
87
+ * The following fields should be filled in by the initialization
88
+ * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
89
+
90
+ struct netif {
91
+ /** pointer to next in linked list */
92
+ struct netif *next;
93
+
94
+ /** IP address configuration in network byte order */
95
+ struct ip_addr ip_addr;
96
+ struct ip_addr netmask;
97
+ struct ip_addr gw;
98
+
99
+ /** This function is called by the network device driver
100
+ * to pass a packet up the TCP/IP stack. */
101
+ err_t (* input)(struct pbuf *p, struct netif *inp);
102
+ /** This function is called by the IP module when it wants
103
+ * to send a packet on the interface. This function typically
104
+ * first resolves the hardware address, then sends the packet. */
105
+ err_t (* output)(struct netif *netif, struct pbuf *p,
106
+ struct ip_addr *ipaddr);
107
+ /** This function is called by the ARP module when it wants
108
+ * to send a packet on the interface. This function outputs
109
+ * the pbuf as-is on the link medium. */
110
+ err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
111
+ #if LWIP_NETIF_STATUS_CALLBACK
112
+ /** This function is called when the netif state is set to up or down
113
+ */
114
+ void (* status_callback)(struct netif *netif);
115
+ #endif /* LWIP_NETIF_STATUS_CALLBACK */
116
+ #if LWIP_NETIF_LINK_CALLBACK
117
+ /** This function is called when the netif link is set to up or down
118
+ */
119
+ void (* link_callback)(struct netif *netif);
120
+ #endif /* LWIP_NETIF_LINK_CALLBACK */
121
+ /** This field can be set by the device driver and could point
122
+ * to state information for the device. */
123
+ void *state;
124
+ #if LWIP_DHCP
125
+ /** the DHCP client state information for this netif */
126
+ struct dhcp *dhcp;
127
+ #endif /* LWIP_DHCP */
128
+ #if LWIP_AUTOIP
129
+ /** the AutoIP client state information for this netif */
130
+ struct autoip *autoip;
131
+ #endif
132
+ #if LWIP_NETIF_HOSTNAME
133
+ /* the hostname for this netif, NULL is a valid value */
134
+ char* hostname;
135
+ #endif /* LWIP_NETIF_HOSTNAME */
136
+ /** maximum transfer unit (in bytes) */
137
+ u16_t mtu;
138
+ /** number of bytes used in hwaddr */
139
+ u8_t hwaddr_len;
140
+ /** link level hardware address of this interface */
141
+ u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
142
+ /** flags (see NETIF_FLAG_ above) */
143
+ u8_t flags;
144
+ /** descriptive abbreviation */
145
+ char name[2];
146
+ /** number of this interface */
147
+ u8_t num;
148
+ #if LWIP_SNMP
149
+ /** link type (from "snmp_ifType" enum from snmp.h) */
150
+ u8_t link_type;
151
+ /** (estimate) link speed */
152
+ u32_t link_speed;
153
+ /** timestamp at last change made (up/down) */
154
+ u32_t ts;
155
+ /** counters */
156
+ u32_t ifinoctets;
157
+ u32_t ifinucastpkts;
158
+ u32_t ifinnucastpkts;
159
+ u32_t ifindiscards;
160
+ u32_t ifoutoctets;
161
+ u32_t ifoutucastpkts;
162
+ u32_t ifoutnucastpkts;
163
+ u32_t ifoutdiscards;
164
+ #endif /* LWIP_SNMP */
165
+ #if LWIP_IGMP
166
+ /* This function could be called to add or delete a entry in the multicast filter table of the ethernet MAC.*/
167
+ err_t (*igmp_mac_filter)( struct netif *netif, struct ip_addr *group, u8_t action);
168
+ #endif /* LWIP_IGMP */
169
+ #if LWIP_NETIF_HWADDRHINT
170
+ u8_t *addr_hint;
171
+ #endif /* LWIP_NETIF_HWADDRHINT */
172
+ #if ENABLE_LOOPBACK
173
+ /* List of packets to be queued for ourselves. */
174
+ struct pbuf *loop_first;
175
+ struct pbuf *loop_last;
176
+ #if LWIP_LOOPBACK_MAX_PBUFS
177
+ u16_t loop_cnt_current;
178
+ #endif /* LWIP_LOOPBACK_MAX_PBUFS */
179
+ #endif /* ENABLE_LOOPBACK */
180
+ };
181
+
182
+ #if LWIP_SNMP
183
+ #define NETIF_INIT_SNMP(netif, type, speed) \
184
+ /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \
185
+ netif->link_type = type; \
186
+ /* your link speed here (units: bits per second) */ \
187
+ netif->link_speed = speed; \
188
+ netif->ts = 0; \
189
+ netif->ifinoctets = 0; \
190
+ netif->ifinucastpkts = 0; \
191
+ netif->ifinnucastpkts = 0; \
192
+ netif->ifindiscards = 0; \
193
+ netif->ifoutoctets = 0; \
194
+ netif->ifoutucastpkts = 0; \
195
+ netif->ifoutnucastpkts = 0; \
196
+ netif->ifoutdiscards = 0
197
+ #else /* LWIP_SNMP */
198
+ #define NETIF_INIT_SNMP(netif, type, speed)
199
+ #endif /* LWIP_SNMP */
200
+
201
+
202
+ /** The list of network interfaces. */
203
+ extern struct netif *netif_list;
204
+ /** The default network interface. */
205
+ extern struct netif *netif_default;
206
+
207
+ #define netif_init() /* Compatibility define, not init needed. */
208
+
209
+ struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
210
+ struct ip_addr *gw,
211
+ void *state,
212
+ err_t (* init)(struct netif *netif),
213
+ err_t (* input)(struct pbuf *p, struct netif *netif));
214
+
215
+ void
216
+ netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
217
+ struct ip_addr *gw);
218
+ void netif_remove(struct netif * netif);
219
+
220
+ /* Returns a network interface given its name. The name is of the form
221
+ "et0", where the first two letters are the "name" field in the
222
+ netif structure, and the digit is in the num field in the same
223
+ structure. */
224
+ struct netif *netif_find(char *name);
225
+
226
+ void netif_set_default(struct netif *netif);
227
+
228
+ void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
229
+ void netif_set_netmask(struct netif *netif, struct ip_addr *netmask);
230
+ void netif_set_gw(struct netif *netif, struct ip_addr *gw);
231
+
232
+ void netif_set_up(struct netif *netif);
233
+ void netif_set_down(struct netif *netif);
234
+ u8_t netif_is_up(struct netif *netif);
235
+
236
+ #if LWIP_NETIF_STATUS_CALLBACK
237
+ /*
238
+ * Set callback to be called when interface is brought up/down
239
+ */
240
+ void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif));
241
+ #endif /* LWIP_NETIF_STATUS_CALLBACK */
242
+
243
+ #if LWIP_NETIF_LINK_CALLBACK
244
+ void netif_set_link_up(struct netif *netif);
245
+ void netif_set_link_down(struct netif *netif);
246
+ u8_t netif_is_link_up(struct netif *netif);
247
+ /*
248
+ * Set callback to be called when link is brought up/down
249
+ */
250
+ void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif));
251
+ #endif /* LWIP_NETIF_LINK_CALLBACK */
252
+
253
+ #ifdef __cplusplus
254
+ }
255
+ #endif
256
+
257
+ #if ENABLE_LOOPBACK
258
+ err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *dest_ip);
259
+ void netif_poll(struct netif *netif);
260
+ #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
261
+ void netif_poll_all(void);
262
+ #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
263
+ #endif /* ENABLE_LOOPBACK */
264
+
265
+ #endif /* __LWIP_NETIF_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/netifapi.h ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Redistribution and use in source and binary forms, with or without modification,
5
+ * are permitted provided that the following conditions are met:
6
+ *
7
+ * 1. Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * 3. The name of the author may not be used to endorse or promote products
13
+ * derived from this software without specific prior written permission.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
18
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
24
+ * OF SUCH DAMAGE.
25
+ *
26
+ * This file is part of the lwIP TCP/IP stack.
27
+ *
28
+ */
29
+
30
+ #ifndef __LWIP_NETIFAPI_H__
31
+ #define __LWIP_NETIFAPI_H__
32
+
33
+ #include "lwip/opt.h"
34
+
35
+ #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
36
+
37
+ #include "lwip/sys.h"
38
+ #include "lwip/netif.h"
39
+ #include "lwip/dhcp.h"
40
+ #include "lwip/autoip.h"
41
+
42
+ #ifdef __cplusplus
43
+ extern "C" {
44
+ #endif
45
+
46
+ struct netifapi_msg_msg {
47
+ #if !LWIP_TCPIP_CORE_LOCKING
48
+ sys_sem_t sem;
49
+ #endif /* !LWIP_TCPIP_CORE_LOCKING */
50
+ err_t err;
51
+ struct netif *netif;
52
+ union {
53
+ struct {
54
+ struct ip_addr *ipaddr;
55
+ struct ip_addr *netmask;
56
+ struct ip_addr *gw;
57
+ void *state;
58
+ err_t (* init) (struct netif *netif);
59
+ err_t (* input)(struct pbuf *p, struct netif *netif);
60
+ } add;
61
+ struct {
62
+ void (* voidfunc)(struct netif *netif);
63
+ err_t (* errtfunc)(struct netif *netif);
64
+ } common;
65
+ } msg;
66
+ };
67
+
68
+ struct netifapi_msg {
69
+ void (* function)(struct netifapi_msg_msg *msg);
70
+ struct netifapi_msg_msg msg;
71
+ };
72
+
73
+
74
+ /* API for application */
75
+ err_t netifapi_netif_add ( struct netif *netif,
76
+ struct ip_addr *ipaddr,
77
+ struct ip_addr *netmask,
78
+ struct ip_addr *gw,
79
+ void *state,
80
+ err_t (* init)(struct netif *netif),
81
+ err_t (* input)(struct pbuf *p, struct netif *netif) );
82
+
83
+ err_t netifapi_netif_set_addr ( struct netif *netif,
84
+ struct ip_addr *ipaddr,
85
+ struct ip_addr *netmask,
86
+ struct ip_addr *gw );
87
+
88
+ err_t netifapi_netif_common ( struct netif *netif,
89
+ void (* voidfunc)(struct netif *netif),
90
+ err_t (* errtfunc)(struct netif *netif) );
91
+
92
+ #define netifapi_netif_remove(n) netifapi_netif_common(n, netif_remove, NULL)
93
+ #define netifapi_netif_set_up(n) netifapi_netif_common(n, netif_set_up, NULL)
94
+ #define netifapi_netif_set_down(n) netifapi_netif_common(n, netif_set_down, NULL)
95
+ #define netifapi_netif_set_default(n) netifapi_netif_common(n, netif_set_default, NULL)
96
+ #define netifapi_dhcp_start(n) netifapi_netif_common(n, NULL, dhcp_start)
97
+ #define netifapi_dhcp_stop(n) netifapi_netif_common(n, dhcp_stop, NULL)
98
+ #define netifapi_autoip_start(n) netifapi_netif_common(n, NULL, autoip_start)
99
+ #define netifapi_autoip_stop(n) netifapi_netif_common(n, NULL, autoip_stop)
100
+
101
+ #ifdef __cplusplus
102
+ }
103
+ #endif
104
+
105
+ #endif /* LWIP_NETIF_API */
106
+
107
+ #endif /* __LWIP_NETIFAPI_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/opt.h ADDED
@@ -0,0 +1,1842 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ *
6
+ * lwIP Options Configuration
7
+ */
8
+
9
+ /*
10
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
11
+ * All rights reserved.
12
+ *
13
+ * Redistribution and use in source and binary forms, with or without modification,
14
+ * are permitted provided that the following conditions are met:
15
+ *
16
+ * 1. Redistributions of source code must retain the above copyright notice,
17
+ * this list of conditions and the following disclaimer.
18
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
19
+ * this list of conditions and the following disclaimer in the documentation
20
+ * and/or other materials provided with the distribution.
21
+ * 3. The name of the author may not be used to endorse or promote products
22
+ * derived from this software without specific prior written permission.
23
+ *
24
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33
+ * OF SUCH DAMAGE.
34
+ *
35
+ * This file is part of the lwIP TCP/IP stack.
36
+ *
37
+ * Author: Adam Dunkels <adam@sics.se>
38
+ *
39
+ */
40
+ #ifndef __LWIP_OPT_H__
41
+ #define __LWIP_OPT_H__
42
+
43
+ /*
44
+ * Include user defined options first. Anything not defined in these files
45
+ * will be set to standard values. Override anything you dont like!
46
+ */
47
+ #include "lwipopts.h"
48
+ #include "lwip/debug.h"
49
+
50
+ /*
51
+ -----------------------------------------------
52
+ ---------- Platform specific locking ----------
53
+ -----------------------------------------------
54
+ */
55
+
56
+ /**
57
+ * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
58
+ * critical regions during buffer allocation, deallocation and memory
59
+ * allocation and deallocation.
60
+ */
61
+ #ifndef SYS_LIGHTWEIGHT_PROT
62
+ #define SYS_LIGHTWEIGHT_PROT 0
63
+ #endif
64
+
65
+ /**
66
+ * NO_SYS==1: Provides VERY minimal functionality. Otherwise,
67
+ * use lwIP facilities.
68
+ */
69
+ #ifndef NO_SYS
70
+ #define NO_SYS 0
71
+ #endif
72
+
73
+ /**
74
+ * MEMCPY: override this if you have a faster implementation at hand than the
75
+ * one included in your C library
76
+ */
77
+ #ifndef MEMCPY
78
+ #define MEMCPY(dst,src,len) memcpy(dst,src,len)
79
+ #endif
80
+
81
+ /**
82
+ * SMEMCPY: override this with care! Some compilers (e.g. gcc) can inline a
83
+ * call to memcpy() if the length is known at compile time and is small.
84
+ */
85
+ #ifndef SMEMCPY
86
+ #define SMEMCPY(dst,src,len) memcpy(dst,src,len)
87
+ #endif
88
+
89
+ /*
90
+ ------------------------------------
91
+ ---------- Memory options ----------
92
+ ------------------------------------
93
+ */
94
+ /**
95
+ * MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library
96
+ * instead of the lwip internal allocator. Can save code size if you
97
+ * already use it.
98
+ */
99
+ #ifndef MEM_LIBC_MALLOC
100
+ #define MEM_LIBC_MALLOC 0
101
+ #endif
102
+
103
+ /**
104
+ * MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator.
105
+ * Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution
106
+ * speed and usage from interrupts!
107
+ */
108
+ #ifndef MEMP_MEM_MALLOC
109
+ #define MEMP_MEM_MALLOC 0
110
+ #endif
111
+
112
+ /**
113
+ * MEM_ALIGNMENT: should be set to the alignment of the CPU
114
+ * 4 byte alignment -> #define MEM_ALIGNMENT 4
115
+ * 2 byte alignment -> #define MEM_ALIGNMENT 2
116
+ */
117
+ #ifndef MEM_ALIGNMENT
118
+ #define MEM_ALIGNMENT 1
119
+ #endif
120
+
121
+ /**
122
+ * MEM_SIZE: the size of the heap memory. If the application will send
123
+ * a lot of data that needs to be copied, this should be set high.
124
+ */
125
+ #ifndef MEM_SIZE
126
+ #define MEM_SIZE 1600
127
+ #endif
128
+
129
+ /**
130
+ * MEMP_OVERFLOW_CHECK: memp overflow protection reserves a configurable
131
+ * amount of bytes before and after each memp element in every pool and fills
132
+ * it with a prominent default value.
133
+ * MEMP_OVERFLOW_CHECK == 0 no checking
134
+ * MEMP_OVERFLOW_CHECK == 1 checks each element when it is freed
135
+ * MEMP_OVERFLOW_CHECK >= 2 checks each element in every pool every time
136
+ * memp_malloc() or memp_free() is called (useful but slow!)
137
+ */
138
+ #ifndef MEMP_OVERFLOW_CHECK
139
+ #define MEMP_OVERFLOW_CHECK 0
140
+ #endif
141
+
142
+ /**
143
+ * MEMP_SANITY_CHECK==1: run a sanity check after each memp_free() to make
144
+ * sure that there are no cycles in the linked lists.
145
+ */
146
+ #ifndef MEMP_SANITY_CHECK
147
+ #define MEMP_SANITY_CHECK 0
148
+ #endif
149
+
150
+ /**
151
+ * MEM_USE_POOLS==1: Use an alternative to malloc() by allocating from a set
152
+ * of memory pools of various sizes. When mem_malloc is called, an element of
153
+ * the smallest pool that can provide the length needed is returned.
154
+ * To use this, MEMP_USE_CUSTOM_POOLS also has to be enabled.
155
+ */
156
+ #ifndef MEM_USE_POOLS
157
+ #define MEM_USE_POOLS 0
158
+ #endif
159
+
160
+ /**
161
+ * MEM_USE_POOLS_TRY_BIGGER_POOL==1: if one malloc-pool is empty, try the next
162
+ * bigger pool - WARNING: THIS MIGHT WASTE MEMORY but it can make a system more
163
+ * reliable. */
164
+ #ifndef MEM_USE_POOLS_TRY_BIGGER_POOL
165
+ #define MEM_USE_POOLS_TRY_BIGGER_POOL 0
166
+ #endif
167
+
168
+ /**
169
+ * MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h
170
+ * that defines additional pools beyond the "standard" ones required
171
+ * by lwIP. If you set this to 1, you must have lwippools.h in your
172
+ * inlude path somewhere.
173
+ */
174
+ #ifndef MEMP_USE_CUSTOM_POOLS
175
+ #define MEMP_USE_CUSTOM_POOLS 0
176
+ #endif
177
+
178
+ /**
179
+ * Set this to 1 if you want to free PBUF_RAM pbufs (or call mem_free()) from
180
+ * interrupt context (or another context that doesn't allow waiting for a
181
+ * semaphore).
182
+ * If set to 1, mem_malloc will be protected by a semaphore and SYS_ARCH_PROTECT,
183
+ * while mem_free will only use SYS_ARCH_PROTECT. mem_malloc SYS_ARCH_UNPROTECTs
184
+ * with each loop so that mem_free can run.
185
+ *
186
+ * ATTENTION: As you can see from the above description, this leads to dis-/
187
+ * enabling interrupts often, which can be slow! Also, on low memory, mem_malloc
188
+ * can need longer.
189
+ *
190
+ * If you don't want that, at least for NO_SYS=0, you can still use the following
191
+ * functions to enqueue a deallocation call which then runs in the tcpip_thread
192
+ * context:
193
+ * - pbuf_free_callback(p);
194
+ * - mem_free_callback(m);
195
+ */
196
+ #ifndef LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
197
+ #define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 0
198
+ #endif
199
+
200
+ /*
201
+ ------------------------------------------------
202
+ ---------- Internal Memory Pool Sizes ----------
203
+ ------------------------------------------------
204
+ */
205
+ /**
206
+ * MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM and PBUF_REF).
207
+ * If the application sends a lot of data out of ROM (or other static memory),
208
+ * this should be set high.
209
+ */
210
+ #ifndef MEMP_NUM_PBUF
211
+ #define MEMP_NUM_PBUF 16
212
+ #endif
213
+
214
+ /**
215
+ * MEMP_NUM_RAW_PCB: Number of raw connection PCBs
216
+ * (requires the LWIP_RAW option)
217
+ */
218
+ #ifndef MEMP_NUM_RAW_PCB
219
+ #define MEMP_NUM_RAW_PCB 4
220
+ #endif
221
+
222
+ /**
223
+ * MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
224
+ * per active UDP "connection".
225
+ * (requires the LWIP_UDP option)
226
+ */
227
+ #ifndef MEMP_NUM_UDP_PCB
228
+ #define MEMP_NUM_UDP_PCB 4
229
+ #endif
230
+
231
+ /**
232
+ * MEMP_NUM_TCP_PCB: the number of simulatenously active TCP connections.
233
+ * (requires the LWIP_TCP option)
234
+ */
235
+ #ifndef MEMP_NUM_TCP_PCB
236
+ #define MEMP_NUM_TCP_PCB 5
237
+ #endif
238
+
239
+ /**
240
+ * MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP connections.
241
+ * (requires the LWIP_TCP option)
242
+ */
243
+ #ifndef MEMP_NUM_TCP_PCB_LISTEN
244
+ #define MEMP_NUM_TCP_PCB_LISTEN 8
245
+ #endif
246
+
247
+ /**
248
+ * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments.
249
+ * (requires the LWIP_TCP option)
250
+ */
251
+ #ifndef MEMP_NUM_TCP_SEG
252
+ #define MEMP_NUM_TCP_SEG 16
253
+ #endif
254
+
255
+ /**
256
+ * MEMP_NUM_REASSDATA: the number of simultaneously IP packets queued for
257
+ * reassembly (whole packets, not fragments!)
258
+ */
259
+ #ifndef MEMP_NUM_REASSDATA
260
+ #define MEMP_NUM_REASSDATA 5
261
+ #endif
262
+
263
+ /**
264
+ * MEMP_NUM_ARP_QUEUE: the number of simulateously queued outgoing
265
+ * packets (pbufs) that are waiting for an ARP request (to resolve
266
+ * their destination address) to finish.
267
+ * (requires the ARP_QUEUEING option)
268
+ */
269
+ #ifndef MEMP_NUM_ARP_QUEUE
270
+ #define MEMP_NUM_ARP_QUEUE 30
271
+ #endif
272
+
273
+ /**
274
+ * MEMP_NUM_IGMP_GROUP: The number of multicast groups whose network interfaces
275
+ * can be members et the same time (one per netif - allsystems group -, plus one
276
+ * per netif membership).
277
+ * (requires the LWIP_IGMP option)
278
+ */
279
+ #ifndef MEMP_NUM_IGMP_GROUP
280
+ #define MEMP_NUM_IGMP_GROUP 8
281
+ #endif
282
+
283
+ /**
284
+ * MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts.
285
+ * (requires NO_SYS==0)
286
+ */
287
+ #ifndef MEMP_NUM_SYS_TIMEOUT
288
+ #define MEMP_NUM_SYS_TIMEOUT 3
289
+ #endif
290
+
291
+ /**
292
+ * MEMP_NUM_NETBUF: the number of struct netbufs.
293
+ * (only needed if you use the sequential API, like api_lib.c)
294
+ */
295
+ #ifndef MEMP_NUM_NETBUF
296
+ #define MEMP_NUM_NETBUF 2
297
+ #endif
298
+
299
+ /**
300
+ * MEMP_NUM_NETCONN: the number of struct netconns.
301
+ * (only needed if you use the sequential API, like api_lib.c)
302
+ */
303
+ #ifndef MEMP_NUM_NETCONN
304
+ #define MEMP_NUM_NETCONN 4
305
+ #endif
306
+
307
+ /**
308
+ * MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used
309
+ * for callback/timeout API communication.
310
+ * (only needed if you use tcpip.c)
311
+ */
312
+ #ifndef MEMP_NUM_TCPIP_MSG_API
313
+ #define MEMP_NUM_TCPIP_MSG_API 8
314
+ #endif
315
+
316
+ /**
317
+ * MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used
318
+ * for incoming packets.
319
+ * (only needed if you use tcpip.c)
320
+ */
321
+ #ifndef MEMP_NUM_TCPIP_MSG_INPKT
322
+ #define MEMP_NUM_TCPIP_MSG_INPKT 8
323
+ #endif
324
+
325
+ /**
326
+ * PBUF_POOL_SIZE: the number of buffers in the pbuf pool.
327
+ */
328
+ #ifndef PBUF_POOL_SIZE
329
+ #define PBUF_POOL_SIZE 16
330
+ #endif
331
+
332
+ /*
333
+ ---------------------------------
334
+ ---------- ARP options ----------
335
+ ---------------------------------
336
+ */
337
+ /**
338
+ * LWIP_ARP==1: Enable ARP functionality.
339
+ */
340
+ #ifndef LWIP_ARP
341
+ #define LWIP_ARP 1
342
+ #endif
343
+
344
+ /**
345
+ * ARP_TABLE_SIZE: Number of active MAC-IP address pairs cached.
346
+ */
347
+ #ifndef ARP_TABLE_SIZE
348
+ #define ARP_TABLE_SIZE 10
349
+ #endif
350
+
351
+ /**
352
+ * ARP_QUEUEING==1: Outgoing packets are queued during hardware address
353
+ * resolution.
354
+ */
355
+ #ifndef ARP_QUEUEING
356
+ #define ARP_QUEUEING 1
357
+ #endif
358
+
359
+ /**
360
+ * ETHARP_TRUST_IP_MAC==1: Incoming IP packets cause the ARP table to be
361
+ * updated with the source MAC and IP addresses supplied in the packet.
362
+ * You may want to disable this if you do not trust LAN peers to have the
363
+ * correct addresses, or as a limited approach to attempt to handle
364
+ * spoofing. If disabled, lwIP will need to make a new ARP request if
365
+ * the peer is not already in the ARP table, adding a little latency.
366
+ */
367
+ #ifndef ETHARP_TRUST_IP_MAC
368
+ #define ETHARP_TRUST_IP_MAC 1
369
+ #endif
370
+
371
+ /**
372
+ * ETHARP_SUPPORT_VLAN==1: support receiving ethernet packets with VLAN header.
373
+ * Additionally, you can define ETHARP_VLAN_CHECK to an u16_t VLAN ID to check.
374
+ * If ETHARP_VLAN_CHECK is defined, only VLAN-traffic for this VLAN is accepted.
375
+ * If ETHARP_VLAN_CHECK is not defined, all traffic is accepted.
376
+ */
377
+ #ifndef ETHARP_SUPPORT_VLAN
378
+ #define ETHARP_SUPPORT_VLAN 0
379
+ #endif
380
+
381
+ /*
382
+ --------------------------------
383
+ ---------- IP options ----------
384
+ --------------------------------
385
+ */
386
+ /**
387
+ * IP_FORWARD==1: Enables the ability to forward IP packets across network
388
+ * interfaces. If you are going to run lwIP on a device with only one network
389
+ * interface, define this to 0.
390
+ */
391
+ #ifndef IP_FORWARD
392
+ #define IP_FORWARD 0
393
+ #endif
394
+
395
+ /**
396
+ * IP_OPTIONS_ALLOWED: Defines the behavior for IP options.
397
+ * IP_OPTIONS_ALLOWED==0: All packets with IP options are dropped.
398
+ * IP_OPTIONS_ALLOWED==1: IP options are allowed (but not parsed).
399
+ */
400
+ #ifndef IP_OPTIONS_ALLOWED
401
+ #define IP_OPTIONS_ALLOWED 1
402
+ #endif
403
+
404
+ /**
405
+ * IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets. Note that
406
+ * this option does not affect outgoing packet sizes, which can be controlled
407
+ * via IP_FRAG.
408
+ */
409
+ #ifndef IP_REASSEMBLY
410
+ #define IP_REASSEMBLY 1
411
+ #endif
412
+
413
+ /**
414
+ * IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU. Note
415
+ * that this option does not affect incoming packet sizes, which can be
416
+ * controlled via IP_REASSEMBLY.
417
+ */
418
+ #ifndef IP_FRAG
419
+ #define IP_FRAG 1
420
+ #endif
421
+
422
+ /**
423
+ * IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally)
424
+ * a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived
425
+ * in this time, the whole packet is discarded.
426
+ */
427
+ #ifndef IP_REASS_MAXAGE
428
+ #define IP_REASS_MAXAGE 3
429
+ #endif
430
+
431
+ /**
432
+ * IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled.
433
+ * Since the received pbufs are enqueued, be sure to configure
434
+ * PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive
435
+ * packets even if the maximum amount of fragments is enqueued for reassembly!
436
+ */
437
+ #ifndef IP_REASS_MAX_PBUFS
438
+ #define IP_REASS_MAX_PBUFS 10
439
+ #endif
440
+
441
+ /**
442
+ * IP_FRAG_USES_STATIC_BUF==1: Use a static MTU-sized buffer for IP
443
+ * fragmentation. Otherwise pbufs are allocated and reference the original
444
+ * packet data to be fragmented.
445
+ */
446
+ #ifndef IP_FRAG_USES_STATIC_BUF
447
+ #define IP_FRAG_USES_STATIC_BUF 1
448
+ #endif
449
+
450
+ /**
451
+ * IP_FRAG_MAX_MTU: Assumed max MTU on any interface for IP frag buffer
452
+ * (requires IP_FRAG_USES_STATIC_BUF==1)
453
+ */
454
+ #if IP_FRAG_USES_STATIC_BUF && !defined(IP_FRAG_MAX_MTU)
455
+ #define IP_FRAG_MAX_MTU 1500
456
+ #endif
457
+
458
+ /**
459
+ * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers.
460
+ */
461
+ #ifndef IP_DEFAULT_TTL
462
+ #define IP_DEFAULT_TTL 255
463
+ #endif
464
+
465
+ /**
466
+ * IP_SOF_BROADCAST=1: Use the SOF_BROADCAST field to enable broadcast
467
+ * filter per pcb on udp and raw send operations. To enable broadcast filter
468
+ * on recv operations, you also have to set IP_SOF_BROADCAST_RECV=1.
469
+ */
470
+ #ifndef IP_SOF_BROADCAST
471
+ #define IP_SOF_BROADCAST 0
472
+ #endif
473
+
474
+ /**
475
+ * IP_SOF_BROADCAST_RECV (requires IP_SOF_BROADCAST=1) enable the broadcast
476
+ * filter on recv operations.
477
+ */
478
+ #ifndef IP_SOF_BROADCAST_RECV
479
+ #define IP_SOF_BROADCAST_RECV 0
480
+ #endif
481
+
482
+ /*
483
+ ----------------------------------
484
+ ---------- ICMP options ----------
485
+ ----------------------------------
486
+ */
487
+ /**
488
+ * LWIP_ICMP==1: Enable ICMP module inside the IP stack.
489
+ * Be careful, disable that make your product non-compliant to RFC1122
490
+ */
491
+ #ifndef LWIP_ICMP
492
+ #define LWIP_ICMP 1
493
+ #endif
494
+
495
+ /**
496
+ * ICMP_TTL: Default value for Time-To-Live used by ICMP packets.
497
+ */
498
+ #ifndef ICMP_TTL
499
+ #define ICMP_TTL (IP_DEFAULT_TTL)
500
+ #endif
501
+
502
+ /**
503
+ * LWIP_BROADCAST_PING==1: respond to broadcast pings (default is unicast only)
504
+ */
505
+ #ifndef LWIP_BROADCAST_PING
506
+ #define LWIP_BROADCAST_PING 0
507
+ #endif
508
+
509
+ /**
510
+ * LWIP_MULTICAST_PING==1: respond to multicast pings (default is unicast only)
511
+ */
512
+ #ifndef LWIP_MULTICAST_PING
513
+ #define LWIP_MULTICAST_PING 0
514
+ #endif
515
+
516
+ /*
517
+ ---------------------------------
518
+ ---------- RAW options ----------
519
+ ---------------------------------
520
+ */
521
+ /**
522
+ * LWIP_RAW==1: Enable application layer to hook into the IP layer itself.
523
+ */
524
+ #ifndef LWIP_RAW
525
+ #define LWIP_RAW 1
526
+ #endif
527
+
528
+ /**
529
+ * LWIP_RAW==1: Enable application layer to hook into the IP layer itself.
530
+ */
531
+ #ifndef RAW_TTL
532
+ #define RAW_TTL (IP_DEFAULT_TTL)
533
+ #endif
534
+
535
+ /*
536
+ ----------------------------------
537
+ ---------- DHCP options ----------
538
+ ----------------------------------
539
+ */
540
+ /**
541
+ * LWIP_DHCP==1: Enable DHCP module.
542
+ */
543
+ #ifndef LWIP_DHCP
544
+ #define LWIP_DHCP 0
545
+ #endif
546
+
547
+ /**
548
+ * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address.
549
+ */
550
+ #ifndef DHCP_DOES_ARP_CHECK
551
+ #define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP))
552
+ #endif
553
+
554
+ /*
555
+ ------------------------------------
556
+ ---------- AUTOIP options ----------
557
+ ------------------------------------
558
+ */
559
+ /**
560
+ * LWIP_AUTOIP==1: Enable AUTOIP module.
561
+ */
562
+ #ifndef LWIP_AUTOIP
563
+ #define LWIP_AUTOIP 0
564
+ #endif
565
+
566
+ /**
567
+ * LWIP_DHCP_AUTOIP_COOP==1: Allow DHCP and AUTOIP to be both enabled on
568
+ * the same interface at the same time.
569
+ */
570
+ #ifndef LWIP_DHCP_AUTOIP_COOP
571
+ #define LWIP_DHCP_AUTOIP_COOP 0
572
+ #endif
573
+
574
+ /**
575
+ * LWIP_DHCP_AUTOIP_COOP_TRIES: Set to the number of DHCP DISCOVER probes
576
+ * that should be sent before falling back on AUTOIP. This can be set
577
+ * as low as 1 to get an AutoIP address very quickly, but you should
578
+ * be prepared to handle a changing IP address when DHCP overrides
579
+ * AutoIP.
580
+ */
581
+ #ifndef LWIP_DHCP_AUTOIP_COOP_TRIES
582
+ #define LWIP_DHCP_AUTOIP_COOP_TRIES 9
583
+ #endif
584
+
585
+ /*
586
+ ----------------------------------
587
+ ---------- SNMP options ----------
588
+ ----------------------------------
589
+ */
590
+ /**
591
+ * LWIP_SNMP==1: Turn on SNMP module. UDP must be available for SNMP
592
+ * transport.
593
+ */
594
+ #ifndef LWIP_SNMP
595
+ #define LWIP_SNMP 0
596
+ #endif
597
+
598
+ /**
599
+ * SNMP_CONCURRENT_REQUESTS: Number of concurrent requests the module will
600
+ * allow. At least one request buffer is required.
601
+ */
602
+ #ifndef SNMP_CONCURRENT_REQUESTS
603
+ #define SNMP_CONCURRENT_REQUESTS 1
604
+ #endif
605
+
606
+ /**
607
+ * SNMP_TRAP_DESTINATIONS: Number of trap destinations. At least one trap
608
+ * destination is required
609
+ */
610
+ #ifndef SNMP_TRAP_DESTINATIONS
611
+ #define SNMP_TRAP_DESTINATIONS 1
612
+ #endif
613
+
614
+ /**
615
+ * SNMP_PRIVATE_MIB:
616
+ */
617
+ #ifndef SNMP_PRIVATE_MIB
618
+ #define SNMP_PRIVATE_MIB 0
619
+ #endif
620
+
621
+ /**
622
+ * Only allow SNMP write actions that are 'safe' (e.g. disabeling netifs is not
623
+ * a safe action and disabled when SNMP_SAFE_REQUESTS = 1).
624
+ * Unsafe requests are disabled by default!
625
+ */
626
+ #ifndef SNMP_SAFE_REQUESTS
627
+ #define SNMP_SAFE_REQUESTS 1
628
+ #endif
629
+
630
+ /*
631
+ ----------------------------------
632
+ ---------- IGMP options ----------
633
+ ----------------------------------
634
+ */
635
+ /**
636
+ * LWIP_IGMP==1: Turn on IGMP module.
637
+ */
638
+ #ifndef LWIP_IGMP
639
+ #define LWIP_IGMP 0
640
+ #endif
641
+
642
+ /*
643
+ ----------------------------------
644
+ ---------- DNS options -----------
645
+ ----------------------------------
646
+ */
647
+ /**
648
+ * LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS
649
+ * transport.
650
+ */
651
+ #ifndef LWIP_DNS
652
+ #define LWIP_DNS 0
653
+ #endif
654
+
655
+ /** DNS maximum number of entries to maintain locally. */
656
+ #ifndef DNS_TABLE_SIZE
657
+ #define DNS_TABLE_SIZE 4
658
+ #endif
659
+
660
+ /** DNS maximum host name length supported in the name table. */
661
+ #ifndef DNS_MAX_NAME_LENGTH
662
+ #define DNS_MAX_NAME_LENGTH 256
663
+ #endif
664
+
665
+ /** The maximum of DNS servers */
666
+ #ifndef DNS_MAX_SERVERS
667
+ #define DNS_MAX_SERVERS 2
668
+ #endif
669
+
670
+ /** DNS do a name checking between the query and the response. */
671
+ #ifndef DNS_DOES_NAME_CHECK
672
+ #define DNS_DOES_NAME_CHECK 1
673
+ #endif
674
+
675
+ /** DNS use a local buffer if DNS_USES_STATIC_BUF=0, a static one if
676
+ DNS_USES_STATIC_BUF=1, or a dynamic one if DNS_USES_STATIC_BUF=2.
677
+ The buffer will be of size DNS_MSG_SIZE */
678
+ #ifndef DNS_USES_STATIC_BUF
679
+ #define DNS_USES_STATIC_BUF 1
680
+ #endif
681
+
682
+ /** DNS message max. size. Default value is RFC compliant. */
683
+ #ifndef DNS_MSG_SIZE
684
+ #define DNS_MSG_SIZE 512
685
+ #endif
686
+
687
+ /** DNS_LOCAL_HOSTLIST: Implements a local host-to-address list. If enabled,
688
+ * you have to define
689
+ * #define DNS_LOCAL_HOSTLIST_INIT {{"host1", 0x123}, {"host2", 0x234}}
690
+ * (an array of structs name/address, where address is an u32_t in network
691
+ * byte order).
692
+ *
693
+ * Instead, you can also use an external function:
694
+ * #define DNS_LOOKUP_LOCAL_EXTERN(x) extern u32_t my_lookup_function(const char *name)
695
+ * that returns the IP address or INADDR_NONE if not found.
696
+ */
697
+ #ifndef DNS_LOCAL_HOSTLIST
698
+ #define DNS_LOCAL_HOSTLIST 0
699
+ #endif /* DNS_LOCAL_HOSTLIST */
700
+
701
+ /** If this is turned on, the local host-list can be dynamically changed
702
+ * at runtime. */
703
+ #ifndef DNS_LOCAL_HOSTLIST_IS_DYNAMIC
704
+ #define DNS_LOCAL_HOSTLIST_IS_DYNAMIC 0
705
+ #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
706
+
707
+ /*
708
+ ---------------------------------
709
+ ---------- UDP options ----------
710
+ ---------------------------------
711
+ */
712
+ /**
713
+ * LWIP_UDP==1: Turn on UDP.
714
+ */
715
+ #ifndef LWIP_UDP
716
+ #define LWIP_UDP 1
717
+ #endif
718
+
719
+ /**
720
+ * LWIP_UDPLITE==1: Turn on UDP-Lite. (Requires LWIP_UDP)
721
+ */
722
+ #ifndef LWIP_UDPLITE
723
+ #define LWIP_UDPLITE 0
724
+ #endif
725
+
726
+ /**
727
+ * UDP_TTL: Default Time-To-Live value.
728
+ */
729
+ #ifndef UDP_TTL
730
+ #define UDP_TTL (IP_DEFAULT_TTL)
731
+ #endif
732
+
733
+ /**
734
+ * LWIP_NETBUF_RECVINFO==1: append destination addr and port to every netbuf.
735
+ */
736
+ #ifndef LWIP_NETBUF_RECVINFO
737
+ #define LWIP_NETBUF_RECVINFO 0
738
+ #endif
739
+
740
+ /*
741
+ ---------------------------------
742
+ ---------- TCP options ----------
743
+ ---------------------------------
744
+ */
745
+ /**
746
+ * LWIP_TCP==1: Turn on TCP.
747
+ */
748
+ #ifndef LWIP_TCP
749
+ #define LWIP_TCP 1
750
+ #endif
751
+
752
+ /**
753
+ * TCP_TTL: Default Time-To-Live value.
754
+ */
755
+ #ifndef TCP_TTL
756
+ #define TCP_TTL (IP_DEFAULT_TTL)
757
+ #endif
758
+
759
+ /**
760
+ * TCP_WND: The size of a TCP window. This must be at least
761
+ * (2 * TCP_MSS) for things to work well
762
+ */
763
+ #ifndef TCP_WND
764
+ #define TCP_WND (4 * TCP_MSS)
765
+ #endif
766
+
767
+ /**
768
+ * TCP_MAXRTX: Maximum number of retransmissions of data segments.
769
+ */
770
+ #ifndef TCP_MAXRTX
771
+ #define TCP_MAXRTX 12
772
+ #endif
773
+
774
+ /**
775
+ * TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments.
776
+ */
777
+ #ifndef TCP_SYNMAXRTX
778
+ #define TCP_SYNMAXRTX 6
779
+ #endif
780
+
781
+ /**
782
+ * TCP_QUEUE_OOSEQ==1: TCP will queue segments that arrive out of order.
783
+ * Define to 0 if your device is low on memory.
784
+ */
785
+ #ifndef TCP_QUEUE_OOSEQ
786
+ #define TCP_QUEUE_OOSEQ (LWIP_TCP)
787
+ #endif
788
+
789
+ /**
790
+ * TCP_MSS: TCP Maximum segment size. (default is 536, a conservative default,
791
+ * you might want to increase this.)
792
+ * For the receive side, this MSS is advertised to the remote side
793
+ * when opening a connection. For the transmit size, this MSS sets
794
+ * an upper limit on the MSS advertised by the remote host.
795
+ */
796
+ #ifndef TCP_MSS
797
+ #define TCP_MSS 536
798
+ #endif
799
+
800
+ /**
801
+ * TCP_CALCULATE_EFF_SEND_MSS: "The maximum size of a segment that TCP really
802
+ * sends, the 'effective send MSS,' MUST be the smaller of the send MSS (which
803
+ * reflects the available reassembly buffer size at the remote host) and the
804
+ * largest size permitted by the IP layer" (RFC 1122)
805
+ * Setting this to 1 enables code that checks TCP_MSS against the MTU of the
806
+ * netif used for a connection and limits the MSS if it would be too big otherwise.
807
+ */
808
+ #ifndef TCP_CALCULATE_EFF_SEND_MSS
809
+ #define TCP_CALCULATE_EFF_SEND_MSS 1
810
+ #endif
811
+
812
+
813
+ /**
814
+ * TCP_SND_BUF: TCP sender buffer space (bytes).
815
+ */
816
+ #ifndef TCP_SND_BUF
817
+ #define TCP_SND_BUF 256
818
+ #endif
819
+
820
+ /**
821
+ * TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
822
+ * as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work.
823
+ */
824
+ #ifndef TCP_SND_QUEUELEN
825
+ #define TCP_SND_QUEUELEN (4 * (TCP_SND_BUF)/(TCP_MSS))
826
+ #endif
827
+
828
+ /**
829
+ * TCP_SNDLOWAT: TCP writable space (bytes). This must be less than or equal
830
+ * to TCP_SND_BUF. It is the amount of space which must be available in the
831
+ * TCP snd_buf for select to return writable.
832
+ */
833
+ #ifndef TCP_SNDLOWAT
834
+ #define TCP_SNDLOWAT ((TCP_SND_BUF)/2)
835
+ #endif
836
+
837
+ /**
838
+ * TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb.
839
+ */
840
+ #ifndef TCP_LISTEN_BACKLOG
841
+ #define TCP_LISTEN_BACKLOG 0
842
+ #endif
843
+
844
+ /**
845
+ * The maximum allowed backlog for TCP listen netconns.
846
+ * This backlog is used unless another is explicitly specified.
847
+ * 0xff is the maximum (u8_t).
848
+ */
849
+ #ifndef TCP_DEFAULT_LISTEN_BACKLOG
850
+ #define TCP_DEFAULT_LISTEN_BACKLOG 0xff
851
+ #endif
852
+
853
+ /**
854
+ * LWIP_TCP_TIMESTAMPS==1: support the TCP timestamp option.
855
+ */
856
+ #ifndef LWIP_TCP_TIMESTAMPS
857
+ #define LWIP_TCP_TIMESTAMPS 0
858
+ #endif
859
+
860
+ /**
861
+ * TCP_WND_UPDATE_THRESHOLD: difference in window to trigger an
862
+ * explicit window update
863
+ */
864
+ #ifndef TCP_WND_UPDATE_THRESHOLD
865
+ #define TCP_WND_UPDATE_THRESHOLD (TCP_WND / 4)
866
+ #endif
867
+
868
+ /**
869
+ * LWIP_EVENT_API and LWIP_CALLBACK_API: Only one of these should be set to 1.
870
+ * LWIP_EVENT_API==1: The user defines lwip_tcp_event() to receive all
871
+ * events (accept, sent, etc) that happen in the system.
872
+ * LWIP_CALLBACK_API==1: The PCB callback function is called directly
873
+ * for the event.
874
+ */
875
+ #ifndef LWIP_EVENT_API
876
+ #define LWIP_EVENT_API 0
877
+ #define LWIP_CALLBACK_API 1
878
+ #else
879
+ #define LWIP_EVENT_API 1
880
+ #define LWIP_CALLBACK_API 0
881
+ #endif
882
+
883
+
884
+ /*
885
+ ----------------------------------
886
+ ---------- Pbuf options ----------
887
+ ----------------------------------
888
+ */
889
+ /**
890
+ * PBUF_LINK_HLEN: the number of bytes that should be allocated for a
891
+ * link level header. The default is 14, the standard value for
892
+ * Ethernet.
893
+ */
894
+ #ifndef PBUF_LINK_HLEN
895
+ #define PBUF_LINK_HLEN 14
896
+ #endif
897
+
898
+ /**
899
+ * PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. The default is
900
+ * designed to accomodate single full size TCP frame in one pbuf, including
901
+ * TCP_MSS, IP header, and link header.
902
+ */
903
+ #ifndef PBUF_POOL_BUFSIZE
904
+ #define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN)
905
+ #endif
906
+
907
+ /*
908
+ ------------------------------------------------
909
+ ---------- Network Interfaces options ----------
910
+ ------------------------------------------------
911
+ */
912
+ /**
913
+ * LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname
914
+ * field.
915
+ */
916
+ #ifndef LWIP_NETIF_HOSTNAME
917
+ #define LWIP_NETIF_HOSTNAME 0
918
+ #endif
919
+
920
+ /**
921
+ * LWIP_NETIF_API==1: Support netif api (in netifapi.c)
922
+ */
923
+ #ifndef LWIP_NETIF_API
924
+ #define LWIP_NETIF_API 0
925
+ #endif
926
+
927
+ /**
928
+ * LWIP_NETIF_STATUS_CALLBACK==1: Support a callback function whenever an interface
929
+ * changes its up/down status (i.e., due to DHCP IP acquistion)
930
+ */
931
+ #ifndef LWIP_NETIF_STATUS_CALLBACK
932
+ #define LWIP_NETIF_STATUS_CALLBACK 0
933
+ #endif
934
+
935
+ /**
936
+ * LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface
937
+ * whenever the link changes (i.e., link down)
938
+ */
939
+ #ifndef LWIP_NETIF_LINK_CALLBACK
940
+ #define LWIP_NETIF_LINK_CALLBACK 0
941
+ #endif
942
+
943
+ /**
944
+ * LWIP_NETIF_HWADDRHINT==1: Cache link-layer-address hints (e.g. table
945
+ * indices) in struct netif. TCP and UDP can make use of this to prevent
946
+ * scanning the ARP table for every sent packet. While this is faster for big
947
+ * ARP tables or many concurrent connections, it might be counterproductive
948
+ * if you have a tiny ARP table or if there never are concurrent connections.
949
+ */
950
+ #ifndef LWIP_NETIF_HWADDRHINT
951
+ #define LWIP_NETIF_HWADDRHINT 0
952
+ #endif
953
+
954
+ /**
955
+ * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP
956
+ * address equal to the netif IP address, looping them back up the stack.
957
+ */
958
+ #ifndef LWIP_NETIF_LOOPBACK
959
+ #define LWIP_NETIF_LOOPBACK 0
960
+ #endif
961
+
962
+ /**
963
+ * LWIP_LOOPBACK_MAX_PBUFS: Maximum number of pbufs on queue for loopback
964
+ * sending for each netif (0 = disabled)
965
+ */
966
+ #ifndef LWIP_LOOPBACK_MAX_PBUFS
967
+ #define LWIP_LOOPBACK_MAX_PBUFS 0
968
+ #endif
969
+
970
+ /**
971
+ * LWIP_NETIF_LOOPBACK_MULTITHREADING: Indicates whether threading is enabled in
972
+ * the system, as netifs must change how they behave depending on this setting
973
+ * for the LWIP_NETIF_LOOPBACK option to work.
974
+ * Setting this is needed to avoid reentering non-reentrant functions like
975
+ * tcp_input().
976
+ * LWIP_NETIF_LOOPBACK_MULTITHREADING==1: Indicates that the user is using a
977
+ * multithreaded environment like tcpip.c. In this case, netif->input()
978
+ * is called directly.
979
+ * LWIP_NETIF_LOOPBACK_MULTITHREADING==0: Indicates a polling (or NO_SYS) setup.
980
+ * The packets are put on a list and netif_poll() must be called in
981
+ * the main application loop.
982
+ */
983
+ #ifndef LWIP_NETIF_LOOPBACK_MULTITHREADING
984
+ #define LWIP_NETIF_LOOPBACK_MULTITHREADING (!NO_SYS)
985
+ #endif
986
+
987
+ /**
988
+ * LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP tries to put all data
989
+ * to be sent into one single pbuf. This is for compatibility with DMA-enabled
990
+ * MACs that do not support scatter-gather.
991
+ * Beware that this might involve CPU-memcpy before transmitting that would not
992
+ * be needed without this flag! Use this only if you need to!
993
+ *
994
+ * @todo: TCP and IP-frag do not work with this, yet:
995
+ */
996
+ #ifndef LWIP_NETIF_TX_SINGLE_PBUF
997
+ #define LWIP_NETIF_TX_SINGLE_PBUF 0
998
+ #endif /* LWIP_NETIF_TX_SINGLE_PBUF */
999
+
1000
+ /*
1001
+ ------------------------------------
1002
+ ---------- LOOPIF options ----------
1003
+ ------------------------------------
1004
+ */
1005
+ /**
1006
+ * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1) and loopif.c
1007
+ */
1008
+ #ifndef LWIP_HAVE_LOOPIF
1009
+ #define LWIP_HAVE_LOOPIF 0
1010
+ #endif
1011
+
1012
+ /*
1013
+ ------------------------------------
1014
+ ---------- SLIPIF options ----------
1015
+ ------------------------------------
1016
+ */
1017
+ /**
1018
+ * LWIP_HAVE_SLIPIF==1: Support slip interface and slipif.c
1019
+ */
1020
+ #ifndef LWIP_HAVE_SLIPIF
1021
+ #define LWIP_HAVE_SLIPIF 0
1022
+ #endif
1023
+
1024
+ /*
1025
+ ------------------------------------
1026
+ ---------- Thread options ----------
1027
+ ------------------------------------
1028
+ */
1029
+ /**
1030
+ * TCPIP_THREAD_NAME: The name assigned to the main tcpip thread.
1031
+ */
1032
+ #ifndef TCPIP_THREAD_NAME
1033
+ #define TCPIP_THREAD_NAME "tcpip_thread"
1034
+ #endif
1035
+
1036
+ /**
1037
+ * TCPIP_THREAD_STACKSIZE: The stack size used by the main tcpip thread.
1038
+ * The stack size value itself is platform-dependent, but is passed to
1039
+ * sys_thread_new() when the thread is created.
1040
+ */
1041
+ #ifndef TCPIP_THREAD_STACKSIZE
1042
+ #define TCPIP_THREAD_STACKSIZE 0
1043
+ #endif
1044
+
1045
+ /**
1046
+ * TCPIP_THREAD_PRIO: The priority assigned to the main tcpip thread.
1047
+ * The priority value itself is platform-dependent, but is passed to
1048
+ * sys_thread_new() when the thread is created.
1049
+ */
1050
+ #ifndef TCPIP_THREAD_PRIO
1051
+ #define TCPIP_THREAD_PRIO 1
1052
+ #endif
1053
+
1054
+ /**
1055
+ * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages
1056
+ * The queue size value itself is platform-dependent, but is passed to
1057
+ * sys_mbox_new() when tcpip_init is called.
1058
+ */
1059
+ #ifndef TCPIP_MBOX_SIZE
1060
+ #define TCPIP_MBOX_SIZE 0
1061
+ #endif
1062
+
1063
+ /**
1064
+ * SLIPIF_THREAD_NAME: The name assigned to the slipif_loop thread.
1065
+ */
1066
+ #ifndef SLIPIF_THREAD_NAME
1067
+ #define SLIPIF_THREAD_NAME "slipif_loop"
1068
+ #endif
1069
+
1070
+ /**
1071
+ * SLIP_THREAD_STACKSIZE: The stack size used by the slipif_loop thread.
1072
+ * The stack size value itself is platform-dependent, but is passed to
1073
+ * sys_thread_new() when the thread is created.
1074
+ */
1075
+ #ifndef SLIPIF_THREAD_STACKSIZE
1076
+ #define SLIPIF_THREAD_STACKSIZE 0
1077
+ #endif
1078
+
1079
+ /**
1080
+ * SLIPIF_THREAD_PRIO: The priority assigned to the slipif_loop thread.
1081
+ * The priority value itself is platform-dependent, but is passed to
1082
+ * sys_thread_new() when the thread is created.
1083
+ */
1084
+ #ifndef SLIPIF_THREAD_PRIO
1085
+ #define SLIPIF_THREAD_PRIO 1
1086
+ #endif
1087
+
1088
+ /**
1089
+ * PPP_THREAD_NAME: The name assigned to the pppMain thread.
1090
+ */
1091
+ #ifndef PPP_THREAD_NAME
1092
+ #define PPP_THREAD_NAME "pppMain"
1093
+ #endif
1094
+
1095
+ /**
1096
+ * PPP_THREAD_STACKSIZE: The stack size used by the pppMain thread.
1097
+ * The stack size value itself is platform-dependent, but is passed to
1098
+ * sys_thread_new() when the thread is created.
1099
+ */
1100
+ #ifndef PPP_THREAD_STACKSIZE
1101
+ #define PPP_THREAD_STACKSIZE 0
1102
+ #endif
1103
+
1104
+ /**
1105
+ * PPP_THREAD_PRIO: The priority assigned to the pppMain thread.
1106
+ * The priority value itself is platform-dependent, but is passed to
1107
+ * sys_thread_new() when the thread is created.
1108
+ */
1109
+ #ifndef PPP_THREAD_PRIO
1110
+ #define PPP_THREAD_PRIO 1
1111
+ #endif
1112
+
1113
+ /**
1114
+ * DEFAULT_THREAD_NAME: The name assigned to any other lwIP thread.
1115
+ */
1116
+ #ifndef DEFAULT_THREAD_NAME
1117
+ #define DEFAULT_THREAD_NAME "lwIP"
1118
+ #endif
1119
+
1120
+ /**
1121
+ * DEFAULT_THREAD_STACKSIZE: The stack size used by any other lwIP thread.
1122
+ * The stack size value itself is platform-dependent, but is passed to
1123
+ * sys_thread_new() when the thread is created.
1124
+ */
1125
+ #ifndef DEFAULT_THREAD_STACKSIZE
1126
+ #define DEFAULT_THREAD_STACKSIZE 0
1127
+ #endif
1128
+
1129
+ /**
1130
+ * DEFAULT_THREAD_PRIO: The priority assigned to any other lwIP thread.
1131
+ * The priority value itself is platform-dependent, but is passed to
1132
+ * sys_thread_new() when the thread is created.
1133
+ */
1134
+ #ifndef DEFAULT_THREAD_PRIO
1135
+ #define DEFAULT_THREAD_PRIO 1
1136
+ #endif
1137
+
1138
+ /**
1139
+ * DEFAULT_RAW_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
1140
+ * NETCONN_RAW. The queue size value itself is platform-dependent, but is passed
1141
+ * to sys_mbox_new() when the recvmbox is created.
1142
+ */
1143
+ #ifndef DEFAULT_RAW_RECVMBOX_SIZE
1144
+ #define DEFAULT_RAW_RECVMBOX_SIZE 0
1145
+ #endif
1146
+
1147
+ /**
1148
+ * DEFAULT_UDP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
1149
+ * NETCONN_UDP. The queue size value itself is platform-dependent, but is passed
1150
+ * to sys_mbox_new() when the recvmbox is created.
1151
+ */
1152
+ #ifndef DEFAULT_UDP_RECVMBOX_SIZE
1153
+ #define DEFAULT_UDP_RECVMBOX_SIZE 0
1154
+ #endif
1155
+
1156
+ /**
1157
+ * DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
1158
+ * NETCONN_TCP. The queue size value itself is platform-dependent, but is passed
1159
+ * to sys_mbox_new() when the recvmbox is created.
1160
+ */
1161
+ #ifndef DEFAULT_TCP_RECVMBOX_SIZE
1162
+ #define DEFAULT_TCP_RECVMBOX_SIZE 0
1163
+ #endif
1164
+
1165
+ /**
1166
+ * DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections.
1167
+ * The queue size value itself is platform-dependent, but is passed to
1168
+ * sys_mbox_new() when the acceptmbox is created.
1169
+ */
1170
+ #ifndef DEFAULT_ACCEPTMBOX_SIZE
1171
+ #define DEFAULT_ACCEPTMBOX_SIZE 0
1172
+ #endif
1173
+
1174
+ /*
1175
+ ----------------------------------------------
1176
+ ---------- Sequential layer options ----------
1177
+ ----------------------------------------------
1178
+ */
1179
+ /**
1180
+ * LWIP_TCPIP_CORE_LOCKING: (EXPERIMENTAL!)
1181
+ * Don't use it if you're not an active lwIP project member
1182
+ */
1183
+ #ifndef LWIP_TCPIP_CORE_LOCKING
1184
+ #define LWIP_TCPIP_CORE_LOCKING 0
1185
+ #endif
1186
+
1187
+ /**
1188
+ * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
1189
+ */
1190
+ #ifndef LWIP_NETCONN
1191
+ #define LWIP_NETCONN 1
1192
+ #endif
1193
+
1194
+ /*
1195
+ ------------------------------------
1196
+ ---------- Socket options ----------
1197
+ ------------------------------------
1198
+ */
1199
+ /**
1200
+ * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
1201
+ */
1202
+ #ifndef LWIP_SOCKET
1203
+ #define LWIP_SOCKET 1
1204
+ #endif
1205
+
1206
+ /**
1207
+ * LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names.
1208
+ * (only used if you use sockets.c)
1209
+ */
1210
+ #ifndef LWIP_COMPAT_SOCKETS
1211
+ #define LWIP_COMPAT_SOCKETS 1
1212
+ #endif
1213
+
1214
+ /**
1215
+ * LWIP_POSIX_SOCKETS_IO_NAMES==1: Enable POSIX-style sockets functions names.
1216
+ * Disable this option if you use a POSIX operating system that uses the same
1217
+ * names (read, write & close). (only used if you use sockets.c)
1218
+ */
1219
+ #ifndef LWIP_POSIX_SOCKETS_IO_NAMES
1220
+ #define LWIP_POSIX_SOCKETS_IO_NAMES 1
1221
+ #endif
1222
+
1223
+ /**
1224
+ * LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT
1225
+ * options processing. Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set
1226
+ * in seconds. (does not require sockets.c, and will affect tcp.c)
1227
+ */
1228
+ #ifndef LWIP_TCP_KEEPALIVE
1229
+ #define LWIP_TCP_KEEPALIVE 1
1230
+ #endif
1231
+
1232
+ /**
1233
+ * LWIP_SO_RCVTIMEO==1: Enable SO_RCVTIMEO processing.
1234
+ */
1235
+ #ifndef LWIP_SO_RCVTIMEO
1236
+ #define LWIP_SO_RCVTIMEO 0
1237
+ #endif
1238
+
1239
+ /**
1240
+ * LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
1241
+ */
1242
+ #ifndef LWIP_SO_RCVBUF
1243
+ #define LWIP_SO_RCVBUF 0
1244
+ #endif
1245
+
1246
+ /**
1247
+ * If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize.
1248
+ */
1249
+ #ifndef RECV_BUFSIZE_DEFAULT
1250
+ #define RECV_BUFSIZE_DEFAULT INT_MAX
1251
+ #endif
1252
+
1253
+ /**
1254
+ * SO_REUSE==1: Enable SO_REUSEADDR and SO_REUSEPORT options. DO NOT USE!
1255
+ */
1256
+ #ifndef SO_REUSE
1257
+ #define SO_REUSE 0
1258
+ #endif
1259
+
1260
+ /*
1261
+ ----------------------------------------
1262
+ ---------- Statistics options ----------
1263
+ ----------------------------------------
1264
+ */
1265
+ /**
1266
+ * LWIP_STATS==1: Enable statistics collection in lwip_stats.
1267
+ */
1268
+ #ifndef LWIP_STATS
1269
+ #define LWIP_STATS 1
1270
+ #endif
1271
+
1272
+ #if LWIP_STATS
1273
+
1274
+ /**
1275
+ * LWIP_STATS_DISPLAY==1: Compile in the statistics output functions.
1276
+ */
1277
+ #ifndef LWIP_STATS_DISPLAY
1278
+ #define LWIP_STATS_DISPLAY 0
1279
+ #endif
1280
+
1281
+ /**
1282
+ * LINK_STATS==1: Enable link stats.
1283
+ */
1284
+ #ifndef LINK_STATS
1285
+ #define LINK_STATS 1
1286
+ #endif
1287
+
1288
+ /**
1289
+ * ETHARP_STATS==1: Enable etharp stats.
1290
+ */
1291
+ #ifndef ETHARP_STATS
1292
+ #define ETHARP_STATS (LWIP_ARP)
1293
+ #endif
1294
+
1295
+ /**
1296
+ * IP_STATS==1: Enable IP stats.
1297
+ */
1298
+ #ifndef IP_STATS
1299
+ #define IP_STATS 1
1300
+ #endif
1301
+
1302
+ /**
1303
+ * IPFRAG_STATS==1: Enable IP fragmentation stats. Default is
1304
+ * on if using either frag or reass.
1305
+ */
1306
+ #ifndef IPFRAG_STATS
1307
+ #define IPFRAG_STATS (IP_REASSEMBLY || IP_FRAG)
1308
+ #endif
1309
+
1310
+ /**
1311
+ * ICMP_STATS==1: Enable ICMP stats.
1312
+ */
1313
+ #ifndef ICMP_STATS
1314
+ #define ICMP_STATS 1
1315
+ #endif
1316
+
1317
+ /**
1318
+ * IGMP_STATS==1: Enable IGMP stats.
1319
+ */
1320
+ #ifndef IGMP_STATS
1321
+ #define IGMP_STATS (LWIP_IGMP)
1322
+ #endif
1323
+
1324
+ /**
1325
+ * UDP_STATS==1: Enable UDP stats. Default is on if
1326
+ * UDP enabled, otherwise off.
1327
+ */
1328
+ #ifndef UDP_STATS
1329
+ #define UDP_STATS (LWIP_UDP)
1330
+ #endif
1331
+
1332
+ /**
1333
+ * TCP_STATS==1: Enable TCP stats. Default is on if TCP
1334
+ * enabled, otherwise off.
1335
+ */
1336
+ #ifndef TCP_STATS
1337
+ #define TCP_STATS (LWIP_TCP)
1338
+ #endif
1339
+
1340
+ /**
1341
+ * MEM_STATS==1: Enable mem.c stats.
1342
+ */
1343
+ #ifndef MEM_STATS
1344
+ #define MEM_STATS ((MEM_LIBC_MALLOC == 0) && (MEM_USE_POOLS == 0))
1345
+ #endif
1346
+
1347
+ /**
1348
+ * MEMP_STATS==1: Enable memp.c pool stats.
1349
+ */
1350
+ #ifndef MEMP_STATS
1351
+ #define MEMP_STATS (MEMP_MEM_MALLOC == 0)
1352
+ #endif
1353
+
1354
+ /**
1355
+ * SYS_STATS==1: Enable system stats (sem and mbox counts, etc).
1356
+ */
1357
+ #ifndef SYS_STATS
1358
+ #define SYS_STATS (NO_SYS == 0)
1359
+ #endif
1360
+
1361
+ #else
1362
+
1363
+ #define LINK_STATS 0
1364
+ #define IP_STATS 0
1365
+ #define IPFRAG_STATS 0
1366
+ #define ICMP_STATS 0
1367
+ #define IGMP_STATS 0
1368
+ #define UDP_STATS 0
1369
+ #define TCP_STATS 0
1370
+ #define MEM_STATS 0
1371
+ #define MEMP_STATS 0
1372
+ #define SYS_STATS 0
1373
+ #define LWIP_STATS_DISPLAY 0
1374
+
1375
+ #endif /* LWIP_STATS */
1376
+
1377
+ /*
1378
+ ---------------------------------
1379
+ ---------- PPP options ----------
1380
+ ---------------------------------
1381
+ */
1382
+ /**
1383
+ * PPP_SUPPORT==1: Enable PPP.
1384
+ */
1385
+ #ifndef PPP_SUPPORT
1386
+ #define PPP_SUPPORT 0
1387
+ #endif
1388
+
1389
+ /**
1390
+ * PPPOE_SUPPORT==1: Enable PPP Over Ethernet
1391
+ */
1392
+ #ifndef PPPOE_SUPPORT
1393
+ #define PPPOE_SUPPORT 0
1394
+ #endif
1395
+
1396
+ /**
1397
+ * PPPOS_SUPPORT==1: Enable PPP Over Serial
1398
+ */
1399
+ #ifndef PPPOS_SUPPORT
1400
+ #define PPPOS_SUPPORT PPP_SUPPORT
1401
+ #endif
1402
+
1403
+ #if PPP_SUPPORT
1404
+
1405
+ /**
1406
+ * NUM_PPP: Max PPP sessions.
1407
+ */
1408
+ #ifndef NUM_PPP
1409
+ #define NUM_PPP 1
1410
+ #endif
1411
+
1412
+ /**
1413
+ * PAP_SUPPORT==1: Support PAP.
1414
+ */
1415
+ #ifndef PAP_SUPPORT
1416
+ #define PAP_SUPPORT 0
1417
+ #endif
1418
+
1419
+ /**
1420
+ * CHAP_SUPPORT==1: Support CHAP.
1421
+ */
1422
+ #ifndef CHAP_SUPPORT
1423
+ #define CHAP_SUPPORT 0
1424
+ #endif
1425
+
1426
+ /**
1427
+ * MSCHAP_SUPPORT==1: Support MSCHAP. CURRENTLY NOT SUPPORTED! DO NOT SET!
1428
+ */
1429
+ #ifndef MSCHAP_SUPPORT
1430
+ #define MSCHAP_SUPPORT 0
1431
+ #endif
1432
+
1433
+ /**
1434
+ * CBCP_SUPPORT==1: Support CBCP. CURRENTLY NOT SUPPORTED! DO NOT SET!
1435
+ */
1436
+ #ifndef CBCP_SUPPORT
1437
+ #define CBCP_SUPPORT 0
1438
+ #endif
1439
+
1440
+ /**
1441
+ * CCP_SUPPORT==1: Support CCP. CURRENTLY NOT SUPPORTED! DO NOT SET!
1442
+ */
1443
+ #ifndef CCP_SUPPORT
1444
+ #define CCP_SUPPORT 0
1445
+ #endif
1446
+
1447
+ /**
1448
+ * VJ_SUPPORT==1: Support VJ header compression.
1449
+ */
1450
+ #ifndef VJ_SUPPORT
1451
+ #define VJ_SUPPORT 0
1452
+ #endif
1453
+
1454
+ /**
1455
+ * MD5_SUPPORT==1: Support MD5 (see also CHAP).
1456
+ */
1457
+ #ifndef MD5_SUPPORT
1458
+ #define MD5_SUPPORT 0
1459
+ #endif
1460
+
1461
+ /*
1462
+ * Timeouts
1463
+ */
1464
+ #ifndef FSM_DEFTIMEOUT
1465
+ #define FSM_DEFTIMEOUT 6 /* Timeout time in seconds */
1466
+ #endif
1467
+
1468
+ #ifndef FSM_DEFMAXTERMREQS
1469
+ #define FSM_DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */
1470
+ #endif
1471
+
1472
+ #ifndef FSM_DEFMAXCONFREQS
1473
+ #define FSM_DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */
1474
+ #endif
1475
+
1476
+ #ifndef FSM_DEFMAXNAKLOOPS
1477
+ #define FSM_DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */
1478
+ #endif
1479
+
1480
+ #ifndef UPAP_DEFTIMEOUT
1481
+ #define UPAP_DEFTIMEOUT 6 /* Timeout (seconds) for retransmitting req */
1482
+ #endif
1483
+
1484
+ #ifndef UPAP_DEFREQTIME
1485
+ #define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */
1486
+ #endif
1487
+
1488
+ #ifndef CHAP_DEFTIMEOUT
1489
+ #define CHAP_DEFTIMEOUT 6 /* Timeout time in seconds */
1490
+ #endif
1491
+
1492
+ #ifndef CHAP_DEFTRANSMITS
1493
+ #define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */
1494
+ #endif
1495
+
1496
+ /* Interval in seconds between keepalive echo requests, 0 to disable. */
1497
+ #ifndef LCP_ECHOINTERVAL
1498
+ #define LCP_ECHOINTERVAL 0
1499
+ #endif
1500
+
1501
+ /* Number of unanswered echo requests before failure. */
1502
+ #ifndef LCP_MAXECHOFAILS
1503
+ #define LCP_MAXECHOFAILS 3
1504
+ #endif
1505
+
1506
+ /* Max Xmit idle time (in jiffies) before resend flag char. */
1507
+ #ifndef PPP_MAXIDLEFLAG
1508
+ #define PPP_MAXIDLEFLAG 100
1509
+ #endif
1510
+
1511
+ /*
1512
+ * Packet sizes
1513
+ *
1514
+ * Note - lcp shouldn't be allowed to negotiate stuff outside these
1515
+ * limits. See lcp.h in the pppd directory.
1516
+ * (XXX - these constants should simply be shared by lcp.c instead
1517
+ * of living in lcp.h)
1518
+ */
1519
+ #define PPP_MTU 1500 /* Default MTU (size of Info field) */
1520
+ #ifndef PPP_MAXMTU
1521
+ /* #define PPP_MAXMTU 65535 - (PPP_HDRLEN + PPP_FCSLEN) */
1522
+ #define PPP_MAXMTU 1500 /* Largest MTU we allow */
1523
+ #endif
1524
+ #define PPP_MINMTU 64
1525
+ #define PPP_MRU 1500 /* default MRU = max length of info field */
1526
+ #define PPP_MAXMRU 1500 /* Largest MRU we allow */
1527
+ #ifndef PPP_DEFMRU
1528
+ #define PPP_DEFMRU 296 /* Try for this */
1529
+ #endif
1530
+ #define PPP_MINMRU 128 /* No MRUs below this */
1531
+
1532
+ #ifndef MAXNAMELEN
1533
+ #define MAXNAMELEN 256 /* max length of hostname or name for auth */
1534
+ #endif
1535
+ #ifndef MAXSECRETLEN
1536
+ #define MAXSECRETLEN 256 /* max length of password or secret */
1537
+ #endif
1538
+
1539
+ #endif /* PPP_SUPPORT */
1540
+
1541
+ /*
1542
+ --------------------------------------
1543
+ ---------- Checksum options ----------
1544
+ --------------------------------------
1545
+ */
1546
+ /**
1547
+ * CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.
1548
+ */
1549
+ #ifndef CHECKSUM_GEN_IP
1550
+ #define CHECKSUM_GEN_IP 1
1551
+ #endif
1552
+
1553
+ /**
1554
+ * CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.
1555
+ */
1556
+ #ifndef CHECKSUM_GEN_UDP
1557
+ #define CHECKSUM_GEN_UDP 1
1558
+ #endif
1559
+
1560
+ /**
1561
+ * CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.
1562
+ */
1563
+ #ifndef CHECKSUM_GEN_TCP
1564
+ #define CHECKSUM_GEN_TCP 1
1565
+ #endif
1566
+
1567
+ /**
1568
+ * CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.
1569
+ */
1570
+ #ifndef CHECKSUM_CHECK_IP
1571
+ #define CHECKSUM_CHECK_IP 1
1572
+ #endif
1573
+
1574
+ /**
1575
+ * CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.
1576
+ */
1577
+ #ifndef CHECKSUM_CHECK_UDP
1578
+ #define CHECKSUM_CHECK_UDP 1
1579
+ #endif
1580
+
1581
+ /**
1582
+ * CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.
1583
+ */
1584
+ #ifndef CHECKSUM_CHECK_TCP
1585
+ #define CHECKSUM_CHECK_TCP 1
1586
+ #endif
1587
+
1588
+ /*
1589
+ ---------------------------------------
1590
+ ---------- Debugging options ----------
1591
+ ---------------------------------------
1592
+ */
1593
+ /**
1594
+ * LWIP_DBG_MIN_LEVEL: After masking, the value of the debug is
1595
+ * compared against this value. If it is smaller, then debugging
1596
+ * messages are written.
1597
+ */
1598
+ #ifndef LWIP_DBG_MIN_LEVEL
1599
+ #define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
1600
+ #endif
1601
+
1602
+ /**
1603
+ * LWIP_DBG_TYPES_ON: A mask that can be used to globally enable/disable
1604
+ * debug messages of certain types.
1605
+ */
1606
+ #ifndef LWIP_DBG_TYPES_ON
1607
+ #define LWIP_DBG_TYPES_ON LWIP_DBG_ON
1608
+ #endif
1609
+
1610
+ /**
1611
+ * ETHARP_DEBUG: Enable debugging in etharp.c.
1612
+ */
1613
+ #ifndef ETHARP_DEBUG
1614
+ #define ETHARP_DEBUG LWIP_DBG_OFF
1615
+ #endif
1616
+
1617
+ /**
1618
+ * NETIF_DEBUG: Enable debugging in netif.c.
1619
+ */
1620
+ #ifndef NETIF_DEBUG
1621
+ #define NETIF_DEBUG LWIP_DBG_OFF
1622
+ #endif
1623
+
1624
+ /**
1625
+ * PBUF_DEBUG: Enable debugging in pbuf.c.
1626
+ */
1627
+ #ifndef PBUF_DEBUG
1628
+ #define PBUF_DEBUG LWIP_DBG_OFF
1629
+ #endif
1630
+
1631
+ /**
1632
+ * API_LIB_DEBUG: Enable debugging in api_lib.c.
1633
+ */
1634
+ #ifndef API_LIB_DEBUG
1635
+ #define API_LIB_DEBUG LWIP_DBG_OFF
1636
+ #endif
1637
+
1638
+ /**
1639
+ * API_MSG_DEBUG: Enable debugging in api_msg.c.
1640
+ */
1641
+ #ifndef API_MSG_DEBUG
1642
+ #define API_MSG_DEBUG LWIP_DBG_OFF
1643
+ #endif
1644
+
1645
+ /**
1646
+ * SOCKETS_DEBUG: Enable debugging in sockets.c.
1647
+ */
1648
+ #ifndef SOCKETS_DEBUG
1649
+ #define SOCKETS_DEBUG LWIP_DBG_OFF
1650
+ #endif
1651
+
1652
+ /**
1653
+ * ICMP_DEBUG: Enable debugging in icmp.c.
1654
+ */
1655
+ #ifndef ICMP_DEBUG
1656
+ #define ICMP_DEBUG LWIP_DBG_OFF
1657
+ #endif
1658
+
1659
+ /**
1660
+ * IGMP_DEBUG: Enable debugging in igmp.c.
1661
+ */
1662
+ #ifndef IGMP_DEBUG
1663
+ #define IGMP_DEBUG LWIP_DBG_OFF
1664
+ #endif
1665
+
1666
+ /**
1667
+ * INET_DEBUG: Enable debugging in inet.c.
1668
+ */
1669
+ #ifndef INET_DEBUG
1670
+ #define INET_DEBUG LWIP_DBG_OFF
1671
+ #endif
1672
+
1673
+ /**
1674
+ * IP_DEBUG: Enable debugging for IP.
1675
+ */
1676
+ #ifndef IP_DEBUG
1677
+ #define IP_DEBUG LWIP_DBG_OFF
1678
+ #endif
1679
+
1680
+ /**
1681
+ * IP_REASS_DEBUG: Enable debugging in ip_frag.c for both frag & reass.
1682
+ */
1683
+ #ifndef IP_REASS_DEBUG
1684
+ #define IP_REASS_DEBUG LWIP_DBG_OFF
1685
+ #endif
1686
+
1687
+ /**
1688
+ * RAW_DEBUG: Enable debugging in raw.c.
1689
+ */
1690
+ #ifndef RAW_DEBUG
1691
+ #define RAW_DEBUG LWIP_DBG_OFF
1692
+ #endif
1693
+
1694
+ /**
1695
+ * MEM_DEBUG: Enable debugging in mem.c.
1696
+ */
1697
+ #ifndef MEM_DEBUG
1698
+ #define MEM_DEBUG LWIP_DBG_OFF
1699
+ #endif
1700
+
1701
+ /**
1702
+ * MEMP_DEBUG: Enable debugging in memp.c.
1703
+ */
1704
+ #ifndef MEMP_DEBUG
1705
+ #define MEMP_DEBUG LWIP_DBG_OFF
1706
+ #endif
1707
+
1708
+ /**
1709
+ * SYS_DEBUG: Enable debugging in sys.c.
1710
+ */
1711
+ #ifndef SYS_DEBUG
1712
+ #define SYS_DEBUG LWIP_DBG_OFF
1713
+ #endif
1714
+
1715
+ /**
1716
+ * TCP_DEBUG: Enable debugging for TCP.
1717
+ */
1718
+ #ifndef TCP_DEBUG
1719
+ #define TCP_DEBUG LWIP_DBG_OFF
1720
+ #endif
1721
+
1722
+ /**
1723
+ * TCP_INPUT_DEBUG: Enable debugging in tcp_in.c for incoming debug.
1724
+ */
1725
+ #ifndef TCP_INPUT_DEBUG
1726
+ #define TCP_INPUT_DEBUG LWIP_DBG_ON
1727
+ #endif
1728
+
1729
+ /**
1730
+ * TCP_FR_DEBUG: Enable debugging in tcp_in.c for fast retransmit.
1731
+ */
1732
+ #ifndef TCP_FR_DEBUG
1733
+ #define TCP_FR_DEBUG LWIP_DBG_OFF
1734
+ #endif
1735
+
1736
+ /**
1737
+ * TCP_RTO_DEBUG: Enable debugging in TCP for retransmit
1738
+ * timeout.
1739
+ */
1740
+ #ifndef TCP_RTO_DEBUG
1741
+ #define TCP_RTO_DEBUG LWIP_DBG_OFF
1742
+ #endif
1743
+
1744
+ /**
1745
+ * TCP_CWND_DEBUG: Enable debugging for TCP congestion window.
1746
+ */
1747
+ #ifndef TCP_CWND_DEBUG
1748
+ #define TCP_CWND_DEBUG LWIP_DBG_OFF
1749
+ #endif
1750
+
1751
+ /**
1752
+ * TCP_WND_DEBUG: Enable debugging in tcp_in.c for window updating.
1753
+ */
1754
+ #ifndef TCP_WND_DEBUG
1755
+ #define TCP_WND_DEBUG LWIP_DBG_OFF
1756
+ #endif
1757
+
1758
+ /**
1759
+ * TCP_OUTPUT_DEBUG: Enable debugging in tcp_out.c output functions.
1760
+ */
1761
+ #ifndef TCP_OUTPUT_DEBUG
1762
+ #define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
1763
+ #endif
1764
+
1765
+ /**
1766
+ * TCP_RST_DEBUG: Enable debugging for TCP with the RST message.
1767
+ */
1768
+ #ifndef TCP_RST_DEBUG
1769
+ #define TCP_RST_DEBUG LWIP_DBG_OFF
1770
+ #endif
1771
+
1772
+ /**
1773
+ * TCP_QLEN_DEBUG: Enable debugging for TCP queue lengths.
1774
+ */
1775
+ #ifndef TCP_QLEN_DEBUG
1776
+ #define TCP_QLEN_DEBUG LWIP_DBG_OFF
1777
+ #endif
1778
+
1779
+ /**
1780
+ * UDP_DEBUG: Enable debugging in UDP.
1781
+ */
1782
+ #ifndef UDP_DEBUG
1783
+ #define UDP_DEBUG LWIP_DBG_OFF
1784
+ #endif
1785
+
1786
+ /**
1787
+ * TCPIP_DEBUG: Enable debugging in tcpip.c.
1788
+ */
1789
+ #ifndef TCPIP_DEBUG
1790
+ #define TCPIP_DEBUG LWIP_DBG_OFF
1791
+ #endif
1792
+
1793
+ /**
1794
+ * PPP_DEBUG: Enable debugging for PPP.
1795
+ */
1796
+ #ifndef PPP_DEBUG
1797
+ #define PPP_DEBUG LWIP_DBG_OFF
1798
+ #endif
1799
+
1800
+ /**
1801
+ * SLIP_DEBUG: Enable debugging in slipif.c.
1802
+ */
1803
+ #ifndef SLIP_DEBUG
1804
+ #define SLIP_DEBUG LWIP_DBG_OFF
1805
+ #endif
1806
+
1807
+ /**
1808
+ * DHCP_DEBUG: Enable debugging in dhcp.c.
1809
+ */
1810
+ #ifndef DHCP_DEBUG
1811
+ #define DHCP_DEBUG LWIP_DBG_OFF
1812
+ #endif
1813
+
1814
+ /**
1815
+ * AUTOIP_DEBUG: Enable debugging in autoip.c.
1816
+ */
1817
+ #ifndef AUTOIP_DEBUG
1818
+ #define AUTOIP_DEBUG LWIP_DBG_OFF
1819
+ #endif
1820
+
1821
+ /**
1822
+ * SNMP_MSG_DEBUG: Enable debugging for SNMP messages.
1823
+ */
1824
+ #ifndef SNMP_MSG_DEBUG
1825
+ #define SNMP_MSG_DEBUG LWIP_DBG_OFF
1826
+ #endif
1827
+
1828
+ /**
1829
+ * SNMP_MIB_DEBUG: Enable debugging for SNMP MIBs.
1830
+ */
1831
+ #ifndef SNMP_MIB_DEBUG
1832
+ #define SNMP_MIB_DEBUG LWIP_DBG_OFF
1833
+ #endif
1834
+
1835
+ /**
1836
+ * DNS_DEBUG: Enable debugging for DNS.
1837
+ */
1838
+ #ifndef DNS_DEBUG
1839
+ #define DNS_DEBUG LWIP_DBG_OFF
1840
+ #endif
1841
+
1842
+ #endif /* __LWIP_OPT_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/pbuf.h ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+
35
+ #ifndef __LWIP_PBUF_H__
36
+ #define __LWIP_PBUF_H__
37
+
38
+ #include "lwip/opt.h"
39
+ #include "lwip/err.h"
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ #define PBUF_TRANSPORT_HLEN 20
46
+ #define PBUF_IP_HLEN 20
47
+
48
+ typedef enum {
49
+ PBUF_TRANSPORT,
50
+ PBUF_IP,
51
+ PBUF_LINK,
52
+ PBUF_RAW
53
+ } pbuf_layer;
54
+
55
+ typedef enum {
56
+ PBUF_RAM, /* pbuf data is stored in RAM */
57
+ PBUF_ROM, /* pbuf data is stored in ROM */
58
+ PBUF_REF, /* pbuf comes from the pbuf pool */
59
+ PBUF_POOL /* pbuf payload refers to RAM */
60
+ } pbuf_type;
61
+
62
+
63
+ /** indicates this packet's data should be immediately passed to the application */
64
+ #define PBUF_FLAG_PUSH 0x01U
65
+
66
+ struct pbuf {
67
+ /** next pbuf in singly linked pbuf chain */
68
+ struct pbuf *next;
69
+
70
+ /** pointer to the actual data in the buffer */
71
+ void *payload;
72
+
73
+ /**
74
+ * total length of this buffer and all next buffers in chain
75
+ * belonging to the same packet.
76
+ *
77
+ * For non-queue packet chains this is the invariant:
78
+ * p->tot_len == p->len + (p->next? p->next->tot_len: 0)
79
+ */
80
+ u16_t tot_len;
81
+
82
+ /** length of this buffer */
83
+ u16_t len;
84
+
85
+ /** pbuf_type as u8_t instead of enum to save space */
86
+ u8_t /*pbuf_type*/ type;
87
+
88
+ /** misc flags */
89
+ u8_t flags;
90
+
91
+ /**
92
+ * the reference count always equals the number of pointers
93
+ * that refer to this pbuf. This can be pointers from an application,
94
+ * the stack itself, or pbuf->next pointers from a chain.
95
+ */
96
+ u16_t ref;
97
+
98
+ };
99
+
100
+ /* Initializes the pbuf module. This call is empty for now, but may not be in future. */
101
+ #define pbuf_init()
102
+
103
+ struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_type type);
104
+ void pbuf_realloc(struct pbuf *p, u16_t size);
105
+ u8_t pbuf_header(struct pbuf *p, s16_t header_size);
106
+ void pbuf_ref(struct pbuf *p);
107
+ void pbuf_ref_chain(struct pbuf *p);
108
+ u8_t pbuf_free(struct pbuf *p);
109
+ u8_t pbuf_clen(struct pbuf *p);
110
+ void pbuf_cat(struct pbuf *head, struct pbuf *tail);
111
+ void pbuf_chain(struct pbuf *head, struct pbuf *tail);
112
+ struct pbuf *pbuf_dechain(struct pbuf *p);
113
+ err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from);
114
+ u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset);
115
+ err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len);
116
+ struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer);
117
+
118
+ #ifdef __cplusplus
119
+ }
120
+ #endif
121
+
122
+ #endif /* __LWIP_PBUF_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/raw.h ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_RAW_H__
35
+ #define __LWIP_RAW_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
40
+
41
+ #include "lwip/pbuf.h"
42
+ #include "lwip/inet.h"
43
+ #include "lwip/ip.h"
44
+ #include "lwip/ip_addr.h"
45
+
46
+ #ifdef __cplusplus
47
+ extern "C" {
48
+ #endif
49
+
50
+ struct raw_pcb {
51
+ /* Common members of all PCB types */
52
+ IP_PCB;
53
+
54
+ struct raw_pcb *next;
55
+
56
+ u8_t protocol;
57
+
58
+ /* receive callback function
59
+ * @param arg user supplied argument (raw_pcb.recv_arg)
60
+ * @param pcb the raw_pcb which received data
61
+ * @param p the packet buffer that was received
62
+ * @param addr the remote IP address from which the packet was received
63
+ * @return 1 if the packet was 'eaten' (aka. deleted),
64
+ * 0 if the packet lives on
65
+ * If returning 1, the callback is responsible for freeing the pbuf
66
+ * if it's not used any more.
67
+ */
68
+ u8_t (* recv)(void *arg, struct raw_pcb *pcb, struct pbuf *p,
69
+ struct ip_addr *addr);
70
+ /* user-supplied argument for the recv callback */
71
+ void *recv_arg;
72
+ };
73
+
74
+ /* The following functions is the application layer interface to the
75
+ RAW code. */
76
+ struct raw_pcb * raw_new (u8_t proto);
77
+ void raw_remove (struct raw_pcb *pcb);
78
+ err_t raw_bind (struct raw_pcb *pcb, struct ip_addr *ipaddr);
79
+ err_t raw_connect (struct raw_pcb *pcb, struct ip_addr *ipaddr);
80
+
81
+ void raw_recv (struct raw_pcb *pcb,
82
+ u8_t (* recv)(void *arg, struct raw_pcb *pcb,
83
+ struct pbuf *p,
84
+ struct ip_addr *addr),
85
+ void *recv_arg);
86
+ err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr);
87
+ err_t raw_send (struct raw_pcb *pcb, struct pbuf *p);
88
+
89
+ /* The following functions are the lower layer interface to RAW. */
90
+ u8_t raw_input (struct pbuf *p, struct netif *inp);
91
+ #define raw_init() /* Compatibility define, not init needed. */
92
+
93
+ #ifdef __cplusplus
94
+ }
95
+ #endif
96
+
97
+ #endif /* LWIP_RAW */
98
+
99
+ #endif /* __LWIP_RAW_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/sio.h ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ */
31
+
32
+ /*
33
+ * This is the interface to the platform specific serial IO module
34
+ * It needs to be implemented by those platforms which need SLIP or PPP
35
+ */
36
+
37
+ #ifndef __SIO_H__
38
+ #define __SIO_H__
39
+
40
+ #include "lwip/arch.h"
41
+
42
+ #ifdef __cplusplus
43
+ extern "C" {
44
+ #endif
45
+
46
+ /* If you want to define sio_fd_t elsewhere or differently,
47
+ define this in your cc.h file. */
48
+ #ifndef __sio_fd_t_defined
49
+ typedef void * sio_fd_t;
50
+ #endif
51
+
52
+ /* The following functions can be defined to something else in your cc.h file
53
+ or be implemented in your custom sio.c file. */
54
+
55
+ #ifndef sio_open
56
+ /**
57
+ * Opens a serial device for communication.
58
+ *
59
+ * @param devnum device number
60
+ * @return handle to serial device if successful, NULL otherwise
61
+ */
62
+ sio_fd_t sio_open(u8_t devnum);
63
+ #endif
64
+
65
+ #ifndef sio_send
66
+ /**
67
+ * Sends a single character to the serial device.
68
+ *
69
+ * @param c character to send
70
+ * @param fd serial device handle
71
+ *
72
+ * @note This function will block until the character can be sent.
73
+ */
74
+ void sio_send(u8_t c, sio_fd_t fd);
75
+ #endif
76
+
77
+ #ifndef sio_recv
78
+ /**
79
+ * Receives a single character from the serial device.
80
+ *
81
+ * @param fd serial device handle
82
+ *
83
+ * @note This function will block until a character is received.
84
+ */
85
+ u8_t sio_recv(sio_fd_t fd);
86
+ #endif
87
+
88
+ #ifndef sio_read
89
+ /**
90
+ * Reads from the serial device.
91
+ *
92
+ * @param fd serial device handle
93
+ * @param data pointer to data buffer for receiving
94
+ * @param len maximum length (in bytes) of data to receive
95
+ * @return number of bytes actually received - may be 0 if aborted by sio_read_abort
96
+ *
97
+ * @note This function will block until data can be received. The blocking
98
+ * can be cancelled by calling sio_read_abort().
99
+ */
100
+ u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len);
101
+ #endif
102
+
103
+ #ifndef sio_tryread
104
+ /**
105
+ * Tries to read from the serial device. Same as sio_read but returns
106
+ * immediately if no data is available and never blocks.
107
+ *
108
+ * @param fd serial device handle
109
+ * @param data pointer to data buffer for receiving
110
+ * @param len maximum length (in bytes) of data to receive
111
+ * @return number of bytes actually received
112
+ */
113
+ u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len);
114
+ #endif
115
+
116
+ #ifndef sio_write
117
+ /**
118
+ * Writes to the serial device.
119
+ *
120
+ * @param fd serial device handle
121
+ * @param data pointer to data to send
122
+ * @param len length (in bytes) of data to send
123
+ * @return number of bytes actually sent
124
+ *
125
+ * @note This function will block until all data can be sent.
126
+ */
127
+ u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len);
128
+ #endif
129
+
130
+ #ifndef sio_read_abort
131
+ /**
132
+ * Aborts a blocking sio_read() call.
133
+ *
134
+ * @param fd serial device handle
135
+ */
136
+ void sio_read_abort(sio_fd_t fd);
137
+ #endif
138
+
139
+ #ifdef __cplusplus
140
+ }
141
+ #endif
142
+
143
+ #endif /* __SIO_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/snmp.h ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001, 2002 Leon Woestenberg <leon.woestenberg@axon.tv>
5
+ * Copyright (c) 2001, 2002 Axon Digital Design B.V., The Netherlands.
6
+ * All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without modification,
9
+ * are permitted provided that the following conditions are met:
10
+ *
11
+ * 1. Redistributions of source code must retain the above copyright notice,
12
+ * this list of conditions and the following disclaimer.
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
14
+ * this list of conditions and the following disclaimer in the documentation
15
+ * and/or other materials provided with the distribution.
16
+ * 3. The name of the author may not be used to endorse or promote products
17
+ * derived from this software without specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28
+ * OF SUCH DAMAGE.
29
+ *
30
+ * This file is part of the lwIP TCP/IP stack.
31
+ *
32
+ * Author: Leon Woestenberg <leon.woestenberg@axon.tv>
33
+ *
34
+ */
35
+ #ifndef __LWIP_SNMP_H__
36
+ #define __LWIP_SNMP_H__
37
+
38
+ #include "lwip/opt.h"
39
+ #include "lwip/netif.h"
40
+ #include "lwip/udp.h"
41
+
42
+ #ifdef __cplusplus
43
+ extern "C" {
44
+ #endif
45
+
46
+ /**
47
+ * @see RFC1213, "MIB-II, 6. Definitions"
48
+ */
49
+ enum snmp_ifType {
50
+ snmp_ifType_other=1, /* none of the following */
51
+ snmp_ifType_regular1822,
52
+ snmp_ifType_hdh1822,
53
+ snmp_ifType_ddn_x25,
54
+ snmp_ifType_rfc877_x25,
55
+ snmp_ifType_ethernet_csmacd,
56
+ snmp_ifType_iso88023_csmacd,
57
+ snmp_ifType_iso88024_tokenBus,
58
+ snmp_ifType_iso88025_tokenRing,
59
+ snmp_ifType_iso88026_man,
60
+ snmp_ifType_starLan,
61
+ snmp_ifType_proteon_10Mbit,
62
+ snmp_ifType_proteon_80Mbit,
63
+ snmp_ifType_hyperchannel,
64
+ snmp_ifType_fddi,
65
+ snmp_ifType_lapb,
66
+ snmp_ifType_sdlc,
67
+ snmp_ifType_ds1, /* T-1 */
68
+ snmp_ifType_e1, /* european equiv. of T-1 */
69
+ snmp_ifType_basicISDN,
70
+ snmp_ifType_primaryISDN, /* proprietary serial */
71
+ snmp_ifType_propPointToPointSerial,
72
+ snmp_ifType_ppp,
73
+ snmp_ifType_softwareLoopback,
74
+ snmp_ifType_eon, /* CLNP over IP [11] */
75
+ snmp_ifType_ethernet_3Mbit,
76
+ snmp_ifType_nsip, /* XNS over IP */
77
+ snmp_ifType_slip, /* generic SLIP */
78
+ snmp_ifType_ultra, /* ULTRA technologies */
79
+ snmp_ifType_ds3, /* T-3 */
80
+ snmp_ifType_sip, /* SMDS */
81
+ snmp_ifType_frame_relay
82
+ };
83
+
84
+ #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
85
+
86
+ /** SNMP "sysuptime" Interval */
87
+ #define SNMP_SYSUPTIME_INTERVAL 10
88
+
89
+ /** fixed maximum length for object identifier type */
90
+ #define LWIP_SNMP_OBJ_ID_LEN 32
91
+
92
+ /** internal object identifier representation */
93
+ struct snmp_obj_id
94
+ {
95
+ u8_t len;
96
+ s32_t id[LWIP_SNMP_OBJ_ID_LEN];
97
+ };
98
+
99
+ /* system */
100
+ void snmp_set_sysdesr(u8_t* str, u8_t* len);
101
+ void snmp_set_sysobjid(struct snmp_obj_id *oid);
102
+ void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid);
103
+ void snmp_inc_sysuptime(void);
104
+ void snmp_add_sysuptime(u32_t value);
105
+ void snmp_get_sysuptime(u32_t *value);
106
+ void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen);
107
+ void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen);
108
+ void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen);
109
+
110
+ /* network interface */
111
+ void snmp_add_ifinoctets(struct netif *ni, u32_t value);
112
+ void snmp_inc_ifinucastpkts(struct netif *ni);
113
+ void snmp_inc_ifinnucastpkts(struct netif *ni);
114
+ void snmp_inc_ifindiscards(struct netif *ni);
115
+ void snmp_add_ifoutoctets(struct netif *ni, u32_t value);
116
+ void snmp_inc_ifoutucastpkts(struct netif *ni);
117
+ void snmp_inc_ifoutnucastpkts(struct netif *ni);
118
+ void snmp_inc_ifoutdiscards(struct netif *ni);
119
+ void snmp_inc_iflist(void);
120
+ void snmp_dec_iflist(void);
121
+
122
+ /* ARP (for atTable and ipNetToMediaTable) */
123
+ void snmp_insert_arpidx_tree(struct netif *ni, struct ip_addr *ip);
124
+ void snmp_delete_arpidx_tree(struct netif *ni, struct ip_addr *ip);
125
+
126
+ /* IP */
127
+ void snmp_inc_ipinreceives(void);
128
+ void snmp_inc_ipinhdrerrors(void);
129
+ void snmp_inc_ipinaddrerrors(void);
130
+ void snmp_inc_ipforwdatagrams(void);
131
+ void snmp_inc_ipinunknownprotos(void);
132
+ void snmp_inc_ipindiscards(void);
133
+ void snmp_inc_ipindelivers(void);
134
+ void snmp_inc_ipoutrequests(void);
135
+ void snmp_inc_ipoutdiscards(void);
136
+ void snmp_inc_ipoutnoroutes(void);
137
+ void snmp_inc_ipreasmreqds(void);
138
+ void snmp_inc_ipreasmoks(void);
139
+ void snmp_inc_ipreasmfails(void);
140
+ void snmp_inc_ipfragoks(void);
141
+ void snmp_inc_ipfragfails(void);
142
+ void snmp_inc_ipfragcreates(void);
143
+ void snmp_inc_iproutingdiscards(void);
144
+ void snmp_insert_ipaddridx_tree(struct netif *ni);
145
+ void snmp_delete_ipaddridx_tree(struct netif *ni);
146
+ void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni);
147
+ void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni);
148
+
149
+ /* ICMP */
150
+ void snmp_inc_icmpinmsgs(void);
151
+ void snmp_inc_icmpinerrors(void);
152
+ void snmp_inc_icmpindestunreachs(void);
153
+ void snmp_inc_icmpintimeexcds(void);
154
+ void snmp_inc_icmpinparmprobs(void);
155
+ void snmp_inc_icmpinsrcquenchs(void);
156
+ void snmp_inc_icmpinredirects(void);
157
+ void snmp_inc_icmpinechos(void);
158
+ void snmp_inc_icmpinechoreps(void);
159
+ void snmp_inc_icmpintimestamps(void);
160
+ void snmp_inc_icmpintimestampreps(void);
161
+ void snmp_inc_icmpinaddrmasks(void);
162
+ void snmp_inc_icmpinaddrmaskreps(void);
163
+ void snmp_inc_icmpoutmsgs(void);
164
+ void snmp_inc_icmpouterrors(void);
165
+ void snmp_inc_icmpoutdestunreachs(void);
166
+ void snmp_inc_icmpouttimeexcds(void);
167
+ void snmp_inc_icmpoutparmprobs(void);
168
+ void snmp_inc_icmpoutsrcquenchs(void);
169
+ void snmp_inc_icmpoutredirects(void);
170
+ void snmp_inc_icmpoutechos(void);
171
+ void snmp_inc_icmpoutechoreps(void);
172
+ void snmp_inc_icmpouttimestamps(void);
173
+ void snmp_inc_icmpouttimestampreps(void);
174
+ void snmp_inc_icmpoutaddrmasks(void);
175
+ void snmp_inc_icmpoutaddrmaskreps(void);
176
+
177
+ /* TCP */
178
+ void snmp_inc_tcpactiveopens(void);
179
+ void snmp_inc_tcppassiveopens(void);
180
+ void snmp_inc_tcpattemptfails(void);
181
+ void snmp_inc_tcpestabresets(void);
182
+ void snmp_inc_tcpinsegs(void);
183
+ void snmp_inc_tcpoutsegs(void);
184
+ void snmp_inc_tcpretranssegs(void);
185
+ void snmp_inc_tcpinerrs(void);
186
+ void snmp_inc_tcpoutrsts(void);
187
+
188
+ /* UDP */
189
+ void snmp_inc_udpindatagrams(void);
190
+ void snmp_inc_udpnoports(void);
191
+ void snmp_inc_udpinerrors(void);
192
+ void snmp_inc_udpoutdatagrams(void);
193
+ void snmp_insert_udpidx_tree(struct udp_pcb *pcb);
194
+ void snmp_delete_udpidx_tree(struct udp_pcb *pcb);
195
+
196
+ /* SNMP */
197
+ void snmp_inc_snmpinpkts(void);
198
+ void snmp_inc_snmpoutpkts(void);
199
+ void snmp_inc_snmpinbadversions(void);
200
+ void snmp_inc_snmpinbadcommunitynames(void);
201
+ void snmp_inc_snmpinbadcommunityuses(void);
202
+ void snmp_inc_snmpinasnparseerrs(void);
203
+ void snmp_inc_snmpintoobigs(void);
204
+ void snmp_inc_snmpinnosuchnames(void);
205
+ void snmp_inc_snmpinbadvalues(void);
206
+ void snmp_inc_snmpinreadonlys(void);
207
+ void snmp_inc_snmpingenerrs(void);
208
+ void snmp_add_snmpintotalreqvars(u8_t value);
209
+ void snmp_add_snmpintotalsetvars(u8_t value);
210
+ void snmp_inc_snmpingetrequests(void);
211
+ void snmp_inc_snmpingetnexts(void);
212
+ void snmp_inc_snmpinsetrequests(void);
213
+ void snmp_inc_snmpingetresponses(void);
214
+ void snmp_inc_snmpintraps(void);
215
+ void snmp_inc_snmpouttoobigs(void);
216
+ void snmp_inc_snmpoutnosuchnames(void);
217
+ void snmp_inc_snmpoutbadvalues(void);
218
+ void snmp_inc_snmpoutgenerrs(void);
219
+ void snmp_inc_snmpoutgetrequests(void);
220
+ void snmp_inc_snmpoutgetnexts(void);
221
+ void snmp_inc_snmpoutsetrequests(void);
222
+ void snmp_inc_snmpoutgetresponses(void);
223
+ void snmp_inc_snmpouttraps(void);
224
+ void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid);
225
+ void snmp_set_snmpenableauthentraps(u8_t *value);
226
+ void snmp_get_snmpenableauthentraps(u8_t *value);
227
+
228
+ /* LWIP_SNMP support not available */
229
+ /* define everything to be empty */
230
+ #else
231
+
232
+ /* system */
233
+ #define snmp_set_sysdesr(str, len)
234
+ #define snmp_set_sysobjid(oid);
235
+ #define snmp_get_sysobjid_ptr(oid)
236
+ #define snmp_inc_sysuptime()
237
+ #define snmp_add_sysuptime(value)
238
+ #define snmp_get_sysuptime(value)
239
+ #define snmp_set_syscontact(ocstr, ocstrlen);
240
+ #define snmp_set_sysname(ocstr, ocstrlen);
241
+ #define snmp_set_syslocation(ocstr, ocstrlen);
242
+
243
+ /* network interface */
244
+ #define snmp_add_ifinoctets(ni,value)
245
+ #define snmp_inc_ifinucastpkts(ni)
246
+ #define snmp_inc_ifinnucastpkts(ni)
247
+ #define snmp_inc_ifindiscards(ni)
248
+ #define snmp_add_ifoutoctets(ni,value)
249
+ #define snmp_inc_ifoutucastpkts(ni)
250
+ #define snmp_inc_ifoutnucastpkts(ni)
251
+ #define snmp_inc_ifoutdiscards(ni)
252
+ #define snmp_inc_iflist()
253
+ #define snmp_dec_iflist()
254
+
255
+ /* ARP */
256
+ #define snmp_insert_arpidx_tree(ni,ip)
257
+ #define snmp_delete_arpidx_tree(ni,ip)
258
+
259
+ /* IP */
260
+ #define snmp_inc_ipinreceives()
261
+ #define snmp_inc_ipinhdrerrors()
262
+ #define snmp_inc_ipinaddrerrors()
263
+ #define snmp_inc_ipforwdatagrams()
264
+ #define snmp_inc_ipinunknownprotos()
265
+ #define snmp_inc_ipindiscards()
266
+ #define snmp_inc_ipindelivers()
267
+ #define snmp_inc_ipoutrequests()
268
+ #define snmp_inc_ipoutdiscards()
269
+ #define snmp_inc_ipoutnoroutes()
270
+ #define snmp_inc_ipreasmreqds()
271
+ #define snmp_inc_ipreasmoks()
272
+ #define snmp_inc_ipreasmfails()
273
+ #define snmp_inc_ipfragoks()
274
+ #define snmp_inc_ipfragfails()
275
+ #define snmp_inc_ipfragcreates()
276
+ #define snmp_inc_iproutingdiscards()
277
+ #define snmp_insert_ipaddridx_tree(ni)
278
+ #define snmp_delete_ipaddridx_tree(ni)
279
+ #define snmp_insert_iprteidx_tree(dflt, ni)
280
+ #define snmp_delete_iprteidx_tree(dflt, ni)
281
+
282
+ /* ICMP */
283
+ #define snmp_inc_icmpinmsgs()
284
+ #define snmp_inc_icmpinerrors()
285
+ #define snmp_inc_icmpindestunreachs()
286
+ #define snmp_inc_icmpintimeexcds()
287
+ #define snmp_inc_icmpinparmprobs()
288
+ #define snmp_inc_icmpinsrcquenchs()
289
+ #define snmp_inc_icmpinredirects()
290
+ #define snmp_inc_icmpinechos()
291
+ #define snmp_inc_icmpinechoreps()
292
+ #define snmp_inc_icmpintimestamps()
293
+ #define snmp_inc_icmpintimestampreps()
294
+ #define snmp_inc_icmpinaddrmasks()
295
+ #define snmp_inc_icmpinaddrmaskreps()
296
+ #define snmp_inc_icmpoutmsgs()
297
+ #define snmp_inc_icmpouterrors()
298
+ #define snmp_inc_icmpoutdestunreachs()
299
+ #define snmp_inc_icmpouttimeexcds()
300
+ #define snmp_inc_icmpoutparmprobs()
301
+ #define snmp_inc_icmpoutsrcquenchs()
302
+ #define snmp_inc_icmpoutredirects()
303
+ #define snmp_inc_icmpoutechos()
304
+ #define snmp_inc_icmpoutechoreps()
305
+ #define snmp_inc_icmpouttimestamps()
306
+ #define snmp_inc_icmpouttimestampreps()
307
+ #define snmp_inc_icmpoutaddrmasks()
308
+ #define snmp_inc_icmpoutaddrmaskreps()
309
+ /* TCP */
310
+ #define snmp_inc_tcpactiveopens()
311
+ #define snmp_inc_tcppassiveopens()
312
+ #define snmp_inc_tcpattemptfails()
313
+ #define snmp_inc_tcpestabresets()
314
+ #define snmp_inc_tcpinsegs()
315
+ #define snmp_inc_tcpoutsegs()
316
+ #define snmp_inc_tcpretranssegs()
317
+ #define snmp_inc_tcpinerrs()
318
+ #define snmp_inc_tcpoutrsts()
319
+
320
+ /* UDP */
321
+ #define snmp_inc_udpindatagrams()
322
+ #define snmp_inc_udpnoports()
323
+ #define snmp_inc_udpinerrors()
324
+ #define snmp_inc_udpoutdatagrams()
325
+ #define snmp_insert_udpidx_tree(pcb)
326
+ #define snmp_delete_udpidx_tree(pcb)
327
+
328
+ /* SNMP */
329
+ #define snmp_inc_snmpinpkts()
330
+ #define snmp_inc_snmpoutpkts()
331
+ #define snmp_inc_snmpinbadversions()
332
+ #define snmp_inc_snmpinbadcommunitynames()
333
+ #define snmp_inc_snmpinbadcommunityuses()
334
+ #define snmp_inc_snmpinasnparseerrs()
335
+ #define snmp_inc_snmpintoobigs()
336
+ #define snmp_inc_snmpinnosuchnames()
337
+ #define snmp_inc_snmpinbadvalues()
338
+ #define snmp_inc_snmpinreadonlys()
339
+ #define snmp_inc_snmpingenerrs()
340
+ #define snmp_add_snmpintotalreqvars(value)
341
+ #define snmp_add_snmpintotalsetvars(value)
342
+ #define snmp_inc_snmpingetrequests()
343
+ #define snmp_inc_snmpingetnexts()
344
+ #define snmp_inc_snmpinsetrequests()
345
+ #define snmp_inc_snmpingetresponses()
346
+ #define snmp_inc_snmpintraps()
347
+ #define snmp_inc_snmpouttoobigs()
348
+ #define snmp_inc_snmpoutnosuchnames()
349
+ #define snmp_inc_snmpoutbadvalues()
350
+ #define snmp_inc_snmpoutgenerrs()
351
+ #define snmp_inc_snmpoutgetrequests()
352
+ #define snmp_inc_snmpoutgetnexts()
353
+ #define snmp_inc_snmpoutsetrequests()
354
+ #define snmp_inc_snmpoutgetresponses()
355
+ #define snmp_inc_snmpouttraps()
356
+ #define snmp_get_snmpgrpid_ptr(oid)
357
+ #define snmp_set_snmpenableauthentraps(value)
358
+ #define snmp_get_snmpenableauthentraps(value)
359
+
360
+ #endif /* LWIP_SNMP */
361
+
362
+ #ifdef __cplusplus
363
+ }
364
+ #endif
365
+
366
+ #endif /* __LWIP_SNMP_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/snmp_asn1.h ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ * Abstract Syntax Notation One (ISO 8824, 8825) codec.
6
+ */
7
+
8
+ /*
9
+ * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
10
+ * All rights reserved.
11
+ *
12
+ * Redistribution and use in source and binary forms, with or without modification,
13
+ * are permitted provided that the following conditions are met:
14
+ *
15
+ * 1. Redistributions of source code must retain the above copyright notice,
16
+ * this list of conditions and the following disclaimer.
17
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
18
+ * this list of conditions and the following disclaimer in the documentation
19
+ * and/or other materials provided with the distribution.
20
+ * 3. The name of the author may not be used to endorse or promote products
21
+ * derived from this software without specific prior written permission.
22
+ *
23
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
26
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32
+ * OF SUCH DAMAGE.
33
+ *
34
+ * Author: Christiaan Simons <christiaan.simons@axon.tv>
35
+ */
36
+
37
+ #ifndef __LWIP_SNMP_ASN1_H__
38
+ #define __LWIP_SNMP_ASN1_H__
39
+
40
+ #include "lwip/opt.h"
41
+ #include "lwip/err.h"
42
+ #include "lwip/pbuf.h"
43
+ #include "lwip/snmp.h"
44
+
45
+ #if LWIP_SNMP
46
+
47
+ #ifdef __cplusplus
48
+ extern "C" {
49
+ #endif
50
+
51
+ #define SNMP_ASN1_UNIV (!0x80 | !0x40)
52
+ #define SNMP_ASN1_APPLIC (!0x80 | 0x40)
53
+ #define SNMP_ASN1_CONTXT ( 0x80 | !0x40)
54
+
55
+ #define SNMP_ASN1_CONSTR (0x20)
56
+ #define SNMP_ASN1_PRIMIT (!0x20)
57
+
58
+ /* universal tags */
59
+ #define SNMP_ASN1_INTEG 2
60
+ #define SNMP_ASN1_OC_STR 4
61
+ #define SNMP_ASN1_NUL 5
62
+ #define SNMP_ASN1_OBJ_ID 6
63
+ #define SNMP_ASN1_SEQ 16
64
+
65
+ /* application specific (SNMP) tags */
66
+ #define SNMP_ASN1_IPADDR 0 /* octet string size(4) */
67
+ #define SNMP_ASN1_COUNTER 1 /* u32_t */
68
+ #define SNMP_ASN1_GAUGE 2 /* u32_t */
69
+ #define SNMP_ASN1_TIMETICKS 3 /* u32_t */
70
+ #define SNMP_ASN1_OPAQUE 4 /* octet string */
71
+
72
+ /* context specific (SNMP) tags */
73
+ #define SNMP_ASN1_PDU_GET_REQ 0
74
+ #define SNMP_ASN1_PDU_GET_NEXT_REQ 1
75
+ #define SNMP_ASN1_PDU_GET_RESP 2
76
+ #define SNMP_ASN1_PDU_SET_REQ 3
77
+ #define SNMP_ASN1_PDU_TRAP 4
78
+
79
+ err_t snmp_asn1_dec_type(struct pbuf *p, u16_t ofs, u8_t *type);
80
+ err_t snmp_asn1_dec_length(struct pbuf *p, u16_t ofs, u8_t *octets_used, u16_t *length);
81
+ err_t snmp_asn1_dec_u32t(struct pbuf *p, u16_t ofs, u16_t len, u32_t *value);
82
+ err_t snmp_asn1_dec_s32t(struct pbuf *p, u16_t ofs, u16_t len, s32_t *value);
83
+ err_t snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid);
84
+ err_t snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw);
85
+
86
+ void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed);
87
+ void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed);
88
+ void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed);
89
+ void snmp_asn1_enc_oid_cnt(u8_t ident_len, s32_t *ident, u16_t *octets_needed);
90
+ err_t snmp_asn1_enc_type(struct pbuf *p, u16_t ofs, u8_t type);
91
+ err_t snmp_asn1_enc_length(struct pbuf *p, u16_t ofs, u16_t length);
92
+ err_t snmp_asn1_enc_u32t(struct pbuf *p, u16_t ofs, u8_t octets_needed, u32_t value);
93
+ err_t snmp_asn1_enc_s32t(struct pbuf *p, u16_t ofs, u8_t octets_needed, s32_t value);
94
+ err_t snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u8_t ident_len, s32_t *ident);
95
+ err_t snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u8_t raw_len, u8_t *raw);
96
+
97
+ #ifdef __cplusplus
98
+ }
99
+ #endif
100
+
101
+ #endif /* LWIP_SNMP */
102
+
103
+ #endif /* __LWIP_SNMP_ASN1_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/snmp_msg.h ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ * SNMP Agent message handling structures.
6
+ */
7
+
8
+ /*
9
+ * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
10
+ * All rights reserved.
11
+ *
12
+ * Redistribution and use in source and binary forms, with or without modification,
13
+ * are permitted provided that the following conditions are met:
14
+ *
15
+ * 1. Redistributions of source code must retain the above copyright notice,
16
+ * this list of conditions and the following disclaimer.
17
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
18
+ * this list of conditions and the following disclaimer in the documentation
19
+ * and/or other materials provided with the distribution.
20
+ * 3. The name of the author may not be used to endorse or promote products
21
+ * derived from this software without specific prior written permission.
22
+ *
23
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
26
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32
+ * OF SUCH DAMAGE.
33
+ *
34
+ * Author: Christiaan Simons <christiaan.simons@axon.tv>
35
+ */
36
+
37
+ #ifndef __LWIP_SNMP_MSG_H__
38
+ #define __LWIP_SNMP_MSG_H__
39
+
40
+ #include "lwip/opt.h"
41
+ #include "lwip/snmp.h"
42
+ #include "lwip/snmp_structs.h"
43
+
44
+ #if LWIP_SNMP
45
+
46
+ #if SNMP_PRIVATE_MIB
47
+ #include "private_mib.h"
48
+ #endif
49
+
50
+ #ifdef __cplusplus
51
+ extern "C" {
52
+ #endif
53
+
54
+ /* The listen port of the SNMP agent. Clients have to make their requests to
55
+ this port. Most standard clients won't work if you change this! */
56
+ #ifndef SNMP_IN_PORT
57
+ #define SNMP_IN_PORT 161
58
+ #endif
59
+ /* The remote port the SNMP agent sends traps to. Most standard trap sinks won't
60
+ work if you change this! */
61
+ #ifndef SNMP_TRAP_PORT
62
+ #define SNMP_TRAP_PORT 162
63
+ #endif
64
+
65
+ #define SNMP_ES_NOERROR 0
66
+ #define SNMP_ES_TOOBIG 1
67
+ #define SNMP_ES_NOSUCHNAME 2
68
+ #define SNMP_ES_BADVALUE 3
69
+ #define SNMP_ES_READONLY 4
70
+ #define SNMP_ES_GENERROR 5
71
+
72
+ #define SNMP_GENTRAP_COLDSTART 0
73
+ #define SNMP_GENTRAP_WARMSTART 1
74
+ #define SNMP_GENTRAP_AUTHFAIL 4
75
+ #define SNMP_GENTRAP_ENTERPRISESPC 6
76
+
77
+ struct snmp_varbind
78
+ {
79
+ /* next pointer, NULL for last in list */
80
+ struct snmp_varbind *next;
81
+ /* previous pointer, NULL for first in list */
82
+ struct snmp_varbind *prev;
83
+
84
+ /* object identifier length (in s32_t) */
85
+ u8_t ident_len;
86
+ /* object identifier array */
87
+ s32_t *ident;
88
+
89
+ /* object value ASN1 type */
90
+ u8_t value_type;
91
+ /* object value length (in u8_t) */
92
+ u8_t value_len;
93
+ /* object value */
94
+ void *value;
95
+
96
+ /* encoding varbind seq length length */
97
+ u8_t seqlenlen;
98
+ /* encoding object identifier length length */
99
+ u8_t olenlen;
100
+ /* encoding object value length length */
101
+ u8_t vlenlen;
102
+ /* encoding varbind seq length */
103
+ u16_t seqlen;
104
+ /* encoding object identifier length */
105
+ u16_t olen;
106
+ /* encoding object value length */
107
+ u16_t vlen;
108
+ };
109
+
110
+ struct snmp_varbind_root
111
+ {
112
+ struct snmp_varbind *head;
113
+ struct snmp_varbind *tail;
114
+ /* number of variable bindings in list */
115
+ u8_t count;
116
+ /* encoding varbind-list seq length length */
117
+ u8_t seqlenlen;
118
+ /* encoding varbind-list seq length */
119
+ u16_t seqlen;
120
+ };
121
+
122
+ /** output response message header length fields */
123
+ struct snmp_resp_header_lengths
124
+ {
125
+ /* encoding error-index length length */
126
+ u8_t erridxlenlen;
127
+ /* encoding error-status length length */
128
+ u8_t errstatlenlen;
129
+ /* encoding request id length length */
130
+ u8_t ridlenlen;
131
+ /* encoding pdu length length */
132
+ u8_t pdulenlen;
133
+ /* encoding community length length */
134
+ u8_t comlenlen;
135
+ /* encoding version length length */
136
+ u8_t verlenlen;
137
+ /* encoding sequence length length */
138
+ u8_t seqlenlen;
139
+
140
+ /* encoding error-index length */
141
+ u16_t erridxlen;
142
+ /* encoding error-status length */
143
+ u16_t errstatlen;
144
+ /* encoding request id length */
145
+ u16_t ridlen;
146
+ /* encoding pdu length */
147
+ u16_t pdulen;
148
+ /* encoding community length */
149
+ u16_t comlen;
150
+ /* encoding version length */
151
+ u16_t verlen;
152
+ /* encoding sequence length */
153
+ u16_t seqlen;
154
+ };
155
+
156
+ /** output response message header length fields */
157
+ struct snmp_trap_header_lengths
158
+ {
159
+ /* encoding timestamp length length */
160
+ u8_t tslenlen;
161
+ /* encoding specific-trap length length */
162
+ u8_t strplenlen;
163
+ /* encoding generic-trap length length */
164
+ u8_t gtrplenlen;
165
+ /* encoding agent-addr length length */
166
+ u8_t aaddrlenlen;
167
+ /* encoding enterprise-id length length */
168
+ u8_t eidlenlen;
169
+ /* encoding pdu length length */
170
+ u8_t pdulenlen;
171
+ /* encoding community length length */
172
+ u8_t comlenlen;
173
+ /* encoding version length length */
174
+ u8_t verlenlen;
175
+ /* encoding sequence length length */
176
+ u8_t seqlenlen;
177
+
178
+ /* encoding timestamp length */
179
+ u16_t tslen;
180
+ /* encoding specific-trap length */
181
+ u16_t strplen;
182
+ /* encoding generic-trap length */
183
+ u16_t gtrplen;
184
+ /* encoding agent-addr length */
185
+ u16_t aaddrlen;
186
+ /* encoding enterprise-id length */
187
+ u16_t eidlen;
188
+ /* encoding pdu length */
189
+ u16_t pdulen;
190
+ /* encoding community length */
191
+ u16_t comlen;
192
+ /* encoding version length */
193
+ u16_t verlen;
194
+ /* encoding sequence length */
195
+ u16_t seqlen;
196
+ };
197
+
198
+ /* Accepting new SNMP messages. */
199
+ #define SNMP_MSG_EMPTY 0
200
+ /* Search for matching object for variable binding. */
201
+ #define SNMP_MSG_SEARCH_OBJ 1
202
+ /* Perform SNMP operation on in-memory object.
203
+ Pass-through states, for symmetry only. */
204
+ #define SNMP_MSG_INTERNAL_GET_OBJDEF 2
205
+ #define SNMP_MSG_INTERNAL_GET_VALUE 3
206
+ #define SNMP_MSG_INTERNAL_SET_TEST 4
207
+ #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5
208
+ #define SNMP_MSG_INTERNAL_SET_VALUE 6
209
+ /* Perform SNMP operation on object located externally.
210
+ In theory this could be used for building a proxy agent.
211
+ Practical use is for an enterprise spc. app. gateway. */
212
+ #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7
213
+ #define SNMP_MSG_EXTERNAL_GET_VALUE 8
214
+ #define SNMP_MSG_EXTERNAL_SET_TEST 9
215
+ #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10
216
+ #define SNMP_MSG_EXTERNAL_SET_VALUE 11
217
+
218
+ #define SNMP_COMMUNITY_STR_LEN 64
219
+ struct snmp_msg_pstat
220
+ {
221
+ /* lwIP local port (161) binding */
222
+ struct udp_pcb *pcb;
223
+ /* source IP address */
224
+ struct ip_addr sip;
225
+ /* source UDP port */
226
+ u16_t sp;
227
+ /* request type */
228
+ u8_t rt;
229
+ /* request ID */
230
+ s32_t rid;
231
+ /* error status */
232
+ s32_t error_status;
233
+ /* error index */
234
+ s32_t error_index;
235
+ /* community name (zero terminated) */
236
+ u8_t community[SNMP_COMMUNITY_STR_LEN + 1];
237
+ /* community string length (exclusive zero term) */
238
+ u8_t com_strlen;
239
+ /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */
240
+ u8_t state;
241
+ /* saved arguments for MSG_EXTERNAL_x */
242
+ struct mib_external_node *ext_mib_node;
243
+ struct snmp_name_ptr ext_name_ptr;
244
+ struct obj_def ext_object_def;
245
+ struct snmp_obj_id ext_oid;
246
+ /* index into input variable binding list */
247
+ u8_t vb_idx;
248
+ /* ptr into input variable binding list */
249
+ struct snmp_varbind *vb_ptr;
250
+ /* list of variable bindings from input */
251
+ struct snmp_varbind_root invb;
252
+ /* list of variable bindings to output */
253
+ struct snmp_varbind_root outvb;
254
+ /* output response lengths used in ASN encoding */
255
+ struct snmp_resp_header_lengths rhl;
256
+ };
257
+
258
+ struct snmp_msg_trap
259
+ {
260
+ /* lwIP local port (161) binding */
261
+ struct udp_pcb *pcb;
262
+ /* destination IP address in network order */
263
+ struct ip_addr dip;
264
+
265
+ /* source enterprise ID (sysObjectID) */
266
+ struct snmp_obj_id *enterprise;
267
+ /* source IP address, raw network order format */
268
+ u8_t sip_raw[4];
269
+ /* generic trap code */
270
+ u32_t gen_trap;
271
+ /* specific trap code */
272
+ u32_t spc_trap;
273
+ /* timestamp */
274
+ u32_t ts;
275
+ /* list of variable bindings to output */
276
+ struct snmp_varbind_root outvb;
277
+ /* output trap lengths used in ASN encoding */
278
+ struct snmp_trap_header_lengths thl;
279
+ };
280
+
281
+ /** Agent Version constant, 0 = v1 oddity */
282
+ extern const s32_t snmp_version;
283
+ /** Agent default "public" community string */
284
+ extern const char snmp_publiccommunity[7];
285
+
286
+ extern struct snmp_msg_trap trap_msg;
287
+
288
+ /** Agent setup, start listening to port 161. */
289
+ void snmp_init(void);
290
+ void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable);
291
+ void snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst);
292
+
293
+ /** Varbind-list functions. */
294
+ struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len);
295
+ void snmp_varbind_free(struct snmp_varbind *vb);
296
+ void snmp_varbind_list_free(struct snmp_varbind_root *root);
297
+ void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb);
298
+ struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root);
299
+
300
+ /** Handle an internal (recv) or external (private response) event. */
301
+ void snmp_msg_event(u8_t request_id);
302
+ err_t snmp_send_response(struct snmp_msg_pstat *m_stat);
303
+ err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap);
304
+ void snmp_coldstart_trap(void);
305
+ void snmp_authfail_trap(void);
306
+
307
+ #ifdef __cplusplus
308
+ }
309
+ #endif
310
+
311
+ #endif /* LWIP_SNMP */
312
+
313
+ #endif /* __LWIP_SNMP_MSG_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/snmp_structs.h ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /**
4
+ * @file
5
+ * Generic MIB tree structures.
6
+ *
7
+ * @todo namespace prefixes
8
+ */
9
+
10
+ /*
11
+ * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
12
+ * All rights reserved.
13
+ *
14
+ * Redistribution and use in source and binary forms, with or without modification,
15
+ * are permitted provided that the following conditions are met:
16
+ *
17
+ * 1. Redistributions of source code must retain the above copyright notice,
18
+ * this list of conditions and the following disclaimer.
19
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
20
+ * this list of conditions and the following disclaimer in the documentation
21
+ * and/or other materials provided with the distribution.
22
+ * 3. The name of the author may not be used to endorse or promote products
23
+ * derived from this software without specific prior written permission.
24
+ *
25
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
26
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
28
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
30
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34
+ * OF SUCH DAMAGE.
35
+ *
36
+ * Author: Christiaan Simons <christiaan.simons@axon.tv>
37
+ */
38
+
39
+ #ifndef __LWIP_SNMP_STRUCTS_H__
40
+ #define __LWIP_SNMP_STRUCTS_H__
41
+
42
+ #include "lwip/opt.h"
43
+
44
+ #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
45
+
46
+ #include "lwip/snmp.h"
47
+
48
+ #if SNMP_PRIVATE_MIB
49
+ #include "private_mib.h"
50
+ #endif
51
+
52
+ #ifdef __cplusplus
53
+ extern "C" {
54
+ #endif
55
+
56
+ /* MIB object instance */
57
+ #define MIB_OBJECT_NONE 0
58
+ #define MIB_OBJECT_SCALAR 1
59
+ #define MIB_OBJECT_TAB 2
60
+
61
+ /* MIB object access */
62
+ #define MIB_OBJECT_READ_ONLY 0
63
+ #define MIB_OBJECT_READ_WRITE 1
64
+ #define MIB_OBJECT_WRITE_ONLY 2
65
+ #define MIB_OBJECT_NOT_ACCESSIBLE 3
66
+
67
+ /** object definition returned by (get_object_def)() */
68
+ struct obj_def
69
+ {
70
+ /* MIB_OBJECT_NONE (0), MIB_OBJECT_SCALAR (1), MIB_OBJECT_TAB (2) */
71
+ u8_t instance;
72
+ /* 0 read-only, 1 read-write, 2 write-only, 3 not-accessible */
73
+ u8_t access;
74
+ /* ASN type for this object */
75
+ u8_t asn_type;
76
+ /* value length (host length) */
77
+ u16_t v_len;
78
+ /* length of instance part of supplied object identifier */
79
+ u8_t id_inst_len;
80
+ /* instance part of supplied object identifier */
81
+ s32_t *id_inst_ptr;
82
+ };
83
+
84
+ struct snmp_name_ptr
85
+ {
86
+ u8_t ident_len;
87
+ s32_t *ident;
88
+ };
89
+
90
+ /** MIB const scalar (.0) node */
91
+ #define MIB_NODE_SC 0x01
92
+ /** MIB const array node */
93
+ #define MIB_NODE_AR 0x02
94
+ /** MIB array node (mem_malloced from RAM) */
95
+ #define MIB_NODE_RA 0x03
96
+ /** MIB list root node (mem_malloced from RAM) */
97
+ #define MIB_NODE_LR 0x04
98
+ /** MIB node for external objects */
99
+ #define MIB_NODE_EX 0x05
100
+
101
+ /** node "base class" layout, the mandatory fields for a node */
102
+ struct mib_node
103
+ {
104
+ /** returns struct obj_def for the given object identifier */
105
+ void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
106
+ /** returns object value for the given object identifier,
107
+ @note the caller must allocate at least len bytes for the value */
108
+ void (*get_value)(struct obj_def *od, u16_t len, void *value);
109
+ /** tests length and/or range BEFORE setting */
110
+ u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
111
+ /** sets object value, only to be called when set_test() */
112
+ void (*set_value)(struct obj_def *od, u16_t len, void *value);
113
+ /** One out of MIB_NODE_AR, MIB_NODE_LR or MIB_NODE_EX */
114
+ const u8_t node_type;
115
+ /* array or max list length */
116
+ const u16_t maxlength;
117
+ };
118
+
119
+ /** derived node for scalars .0 index */
120
+ typedef struct mib_node mib_scalar_node;
121
+
122
+ /** derived node, points to a fixed size const array
123
+ of sub-identifiers plus a 'child' pointer */
124
+ struct mib_array_node
125
+ {
126
+ /* inherited "base class" members */
127
+ void (* const get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
128
+ void (* const get_value)(struct obj_def *od, u16_t len, void *value);
129
+ u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
130
+ void (*set_value)(struct obj_def *od, u16_t len, void *value);
131
+
132
+ const u8_t node_type;
133
+ const u16_t maxlength;
134
+
135
+ /* aditional struct members */
136
+ const s32_t *objid;
137
+ struct mib_node* const *nptr;
138
+ };
139
+
140
+ /** derived node, points to a fixed size mem_malloced array
141
+ of sub-identifiers plus a 'child' pointer */
142
+ struct mib_ram_array_node
143
+ {
144
+ /* inherited "base class" members */
145
+ void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
146
+ void (*get_value)(struct obj_def *od, u16_t len, void *value);
147
+ u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
148
+ void (*set_value)(struct obj_def *od, u16_t len, void *value);
149
+
150
+ u8_t node_type;
151
+ u16_t maxlength;
152
+
153
+ /* aditional struct members */
154
+ s32_t *objid;
155
+ struct mib_node **nptr;
156
+ };
157
+
158
+ struct mib_list_node
159
+ {
160
+ struct mib_list_node *prev;
161
+ struct mib_list_node *next;
162
+ s32_t objid;
163
+ struct mib_node *nptr;
164
+ };
165
+
166
+ /** derived node, points to a doubly linked list
167
+ of sub-identifiers plus a 'child' pointer */
168
+ struct mib_list_rootnode
169
+ {
170
+ /* inherited "base class" members */
171
+ void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
172
+ void (*get_value)(struct obj_def *od, u16_t len, void *value);
173
+ u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
174
+ void (*set_value)(struct obj_def *od, u16_t len, void *value);
175
+
176
+ u8_t node_type;
177
+ u16_t maxlength;
178
+
179
+ /* aditional struct members */
180
+ struct mib_list_node *head;
181
+ struct mib_list_node *tail;
182
+ /* counts list nodes in list */
183
+ u16_t count;
184
+ };
185
+
186
+ /** derived node, has access functions for mib object in external memory or device
187
+ using 'tree_level' and 'idx', with a range 0 .. (level_length() - 1) */
188
+ struct mib_external_node
189
+ {
190
+ /* inherited "base class" members */
191
+ void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
192
+ void (*get_value)(struct obj_def *od, u16_t len, void *value);
193
+ u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
194
+ void (*set_value)(struct obj_def *od, u16_t len, void *value);
195
+
196
+ u8_t node_type;
197
+ u16_t maxlength;
198
+
199
+ /* aditional struct members */
200
+ /** points to an extenal (in memory) record of some sort of addressing
201
+ information, passed to and interpreted by the funtions below */
202
+ void* addr_inf;
203
+ /** tree levels under this node */
204
+ u8_t tree_levels;
205
+ /** number of objects at this level */
206
+ u16_t (*level_length)(void* addr_inf, u8_t level);
207
+ /** compares object sub identifier with external id
208
+ return zero when equal, nonzero when unequal */
209
+ s32_t (*ident_cmp)(void* addr_inf, u8_t level, u16_t idx, s32_t sub_id);
210
+ void (*get_objid)(void* addr_inf, u8_t level, u16_t idx, s32_t *sub_id);
211
+
212
+ /** async Questions */
213
+ void (*get_object_def_q)(void* addr_inf, u8_t rid, u8_t ident_len, s32_t *ident);
214
+ void (*get_value_q)(u8_t rid, struct obj_def *od);
215
+ void (*set_test_q)(u8_t rid, struct obj_def *od);
216
+ void (*set_value_q)(u8_t rid, struct obj_def *od, u16_t len, void *value);
217
+ /** async Answers */
218
+ void (*get_object_def_a)(u8_t rid, u8_t ident_len, s32_t *ident, struct obj_def *od);
219
+ void (*get_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
220
+ u8_t (*set_test_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
221
+ void (*set_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
222
+ /** async Panic Close (agent returns error reply,
223
+ e.g. used for external transaction cleanup) */
224
+ void (*get_object_def_pc)(u8_t rid, u8_t ident_len, s32_t *ident);
225
+ void (*get_value_pc)(u8_t rid, struct obj_def *od);
226
+ void (*set_test_pc)(u8_t rid, struct obj_def *od);
227
+ void (*set_value_pc)(u8_t rid, struct obj_def *od);
228
+ };
229
+
230
+ /** export MIB tree from mib2.c */
231
+ extern const struct mib_array_node internet;
232
+
233
+ /** dummy function pointers for non-leaf MIB nodes from mib2.c */
234
+ void noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
235
+ void noleafs_get_value(struct obj_def *od, u16_t len, void *value);
236
+ u8_t noleafs_set_test(struct obj_def *od, u16_t len, void *value);
237
+ void noleafs_set_value(struct obj_def *od, u16_t len, void *value);
238
+
239
+ void snmp_oidtoip(s32_t *ident, struct ip_addr *ip);
240
+ void snmp_iptooid(struct ip_addr *ip, s32_t *ident);
241
+ void snmp_ifindextonetif(s32_t ifindex, struct netif **netif);
242
+ void snmp_netiftoifindex(struct netif *netif, s32_t *ifidx);
243
+
244
+ struct mib_list_node* snmp_mib_ln_alloc(s32_t id);
245
+ void snmp_mib_ln_free(struct mib_list_node *ln);
246
+ struct mib_list_rootnode* snmp_mib_lrn_alloc(void);
247
+ void snmp_mib_lrn_free(struct mib_list_rootnode *lrn);
248
+
249
+ s8_t snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **insn);
250
+ s8_t snmp_mib_node_find(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **fn);
251
+ struct mib_list_rootnode *snmp_mib_node_delete(struct mib_list_rootnode *rn, struct mib_list_node *n);
252
+
253
+ struct mib_node* snmp_search_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_name_ptr *np);
254
+ struct mib_node* snmp_expand_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret);
255
+ u8_t snmp_iso_prefix_tst(u8_t ident_len, s32_t *ident);
256
+ u8_t snmp_iso_prefix_expand(u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret);
257
+
258
+ #ifdef __cplusplus
259
+ }
260
+ #endif
261
+
262
+ #endif /* LWIP_SNMP */
263
+
264
+ #endif /* __LWIP_SNMP_STRUCTS_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/sockets.h ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+
35
+
36
+ #ifndef __LWIP_SOCKETS_H__
37
+ #define __LWIP_SOCKETS_H__
38
+
39
+ #include "lwip/opt.h"
40
+
41
+ #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
42
+
43
+ #include <stddef.h> /* for size_t */
44
+
45
+ #include "lwip/ip_addr.h"
46
+ #include "lwip/inet.h"
47
+
48
+ #ifdef __cplusplus
49
+ extern "C" {
50
+ #endif
51
+
52
+ /* members are in network byte order */
53
+ struct sockaddr_in {
54
+ u8_t sin_len;
55
+ u8_t sin_family;
56
+ u16_t sin_port;
57
+ struct in_addr sin_addr;
58
+ char sin_zero[8];
59
+ };
60
+
61
+ struct sockaddr {
62
+ u8_t sa_len;
63
+ u8_t sa_family;
64
+ char sa_data[14];
65
+ };
66
+
67
+ #ifndef socklen_t
68
+ # define socklen_t u32_t
69
+ #endif
70
+
71
+ /* Socket protocol types (TCP/UDP/RAW) */
72
+ #define SOCK_STREAM 1
73
+ #define SOCK_DGRAM 2
74
+ #define SOCK_RAW 3
75
+
76
+ /*
77
+ * Option flags per-socket. These must match the SOF_ flags in ip.h!
78
+ */
79
+ #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
80
+ #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
81
+ #define SO_REUSEADDR 0x0004 /* Unimplemented: allow local address reuse */
82
+ #define SO_KEEPALIVE 0x0008 /* keep connections alive */
83
+ #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */
84
+ #define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
85
+ #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
86
+ #define SO_LINGER 0x0080 /* linger on close if data present */
87
+ #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */
88
+ #define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */
89
+
90
+ #define SO_DONTLINGER ((int)(~SO_LINGER))
91
+
92
+ /*
93
+ * Additional options, not kept in so_options.
94
+ */
95
+ #define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */
96
+ #define SO_RCVBUF 0x1002 /* receive buffer size */
97
+ #define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */
98
+ #define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */
99
+ #define SO_SNDTIMEO 0x1005 /* Unimplemented: send timeout */
100
+ #define SO_RCVTIMEO 0x1006 /* receive timeout */
101
+ #define SO_ERROR 0x1007 /* get error status and clear */
102
+ #define SO_TYPE 0x1008 /* get socket type */
103
+ #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
104
+ #define SO_NO_CHECK 0x100a /* don't create UDP checksum */
105
+
106
+
107
+ /*
108
+ * Structure used for manipulating linger option.
109
+ */
110
+ struct linger {
111
+ int l_onoff; /* option on/off */
112
+ int l_linger; /* linger time */
113
+ };
114
+
115
+ /*
116
+ * Level number for (get/set)sockopt() to apply to socket itself.
117
+ */
118
+ #define SOL_SOCKET 0xfff /* options for socket level */
119
+
120
+
121
+ #define AF_UNSPEC 0
122
+ #define AF_INET 2
123
+ #define PF_INET AF_INET
124
+ #define PF_UNSPEC AF_UNSPEC
125
+
126
+ #define IPPROTO_IP 0
127
+ #define IPPROTO_TCP 6
128
+ #define IPPROTO_UDP 17
129
+ #define IPPROTO_UDPLITE 136
130
+
131
+ /* Flags we can use with send and recv. */
132
+ #define MSG_PEEK 0x01 /* Peeks at an incoming message */
133
+ #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
134
+ #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
135
+ #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
136
+ #define MSG_MORE 0x10 /* Sender will send more */
137
+
138
+
139
+ /*
140
+ * Options for level IPPROTO_IP
141
+ */
142
+ #define IP_TOS 1
143
+ #define IP_TTL 2
144
+
145
+ #if LWIP_TCP
146
+ /*
147
+ * Options for level IPPROTO_TCP
148
+ */
149
+ #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
150
+ #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
151
+ #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
152
+ #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
153
+ #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
154
+ #endif /* LWIP_TCP */
155
+
156
+ #if LWIP_UDP && LWIP_UDPLITE
157
+ /*
158
+ * Options for level IPPROTO_UDPLITE
159
+ */
160
+ #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
161
+ #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
162
+ #endif /* LWIP_UDP && LWIP_UDPLITE*/
163
+
164
+
165
+ #if LWIP_IGMP
166
+ /*
167
+ * Options and types for UDP multicast traffic handling
168
+ */
169
+ #define IP_ADD_MEMBERSHIP 3
170
+ #define IP_DROP_MEMBERSHIP 4
171
+ #define IP_MULTICAST_TTL 5
172
+ #define IP_MULTICAST_IF 6
173
+ #define IP_MULTICAST_LOOP 7
174
+
175
+ typedef struct ip_mreq {
176
+ struct in_addr imr_multiaddr; /* IP multicast address of group */
177
+ struct in_addr imr_interface; /* local IP address of interface */
178
+ } ip_mreq;
179
+ #endif /* LWIP_IGMP */
180
+
181
+ /*
182
+ * The Type of Service provides an indication of the abstract
183
+ * parameters of the quality of service desired. These parameters are
184
+ * to be used to guide the selection of the actual service parameters
185
+ * when transmitting a datagram through a particular network. Several
186
+ * networks offer service precedence, which somehow treats high
187
+ * precedence traffic as more important than other traffic (generally
188
+ * by accepting only traffic above a certain precedence at time of high
189
+ * load). The major choice is a three way tradeoff between low-delay,
190
+ * high-reliability, and high-throughput.
191
+ * The use of the Delay, Throughput, and Reliability indications may
192
+ * increase the cost (in some sense) of the service. In many networks
193
+ * better performance for one of these parameters is coupled with worse
194
+ * performance on another. Except for very unusual cases at most two
195
+ * of these three indications should be set.
196
+ */
197
+ #define IPTOS_TOS_MASK 0x1E
198
+ #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
199
+ #define IPTOS_LOWDELAY 0x10
200
+ #define IPTOS_THROUGHPUT 0x08
201
+ #define IPTOS_RELIABILITY 0x04
202
+ #define IPTOS_LOWCOST 0x02
203
+ #define IPTOS_MINCOST IPTOS_LOWCOST
204
+
205
+ /*
206
+ * The Network Control precedence designation is intended to be used
207
+ * within a network only. The actual use and control of that
208
+ * designation is up to each network. The Internetwork Control
209
+ * designation is intended for use by gateway control originators only.
210
+ * If the actual use of these precedence designations is of concern to
211
+ * a particular network, it is the responsibility of that network to
212
+ * control the access to, and use of, those precedence designations.
213
+ */
214
+ #define IPTOS_PREC_MASK 0xe0
215
+ #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
216
+ #define IPTOS_PREC_NETCONTROL 0xe0
217
+ #define IPTOS_PREC_INTERNETCONTROL 0xc0
218
+ #define IPTOS_PREC_CRITIC_ECP 0xa0
219
+ #define IPTOS_PREC_FLASHOVERRIDE 0x80
220
+ #define IPTOS_PREC_FLASH 0x60
221
+ #define IPTOS_PREC_IMMEDIATE 0x40
222
+ #define IPTOS_PREC_PRIORITY 0x20
223
+ #define IPTOS_PREC_ROUTINE 0x00
224
+
225
+
226
+ /*
227
+ * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
228
+ * lwip_ioctl only supports FIONREAD and FIONBIO, for now
229
+ *
230
+ * Ioctl's have the command encoded in the lower word,
231
+ * and the size of any in or out parameters in the upper
232
+ * word. The high 2 bits of the upper word are used
233
+ * to encode the in/out status of the parameter; for now
234
+ * we restrict parameters to at most 128 bytes.
235
+ */
236
+ #if !defined(FIONREAD) || !defined(FIONBIO)
237
+ #define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */
238
+ #define IOC_VOID 0x20000000UL /* no parameters */
239
+ #define IOC_OUT 0x40000000UL /* copy out parameters */
240
+ #define IOC_IN 0x80000000UL /* copy in parameters */
241
+ #define IOC_INOUT (IOC_IN|IOC_OUT)
242
+ /* 0x20000000 distinguishes new &
243
+ old ioctl's */
244
+ #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
245
+
246
+ #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
247
+
248
+ #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
249
+ #endif /* !defined(FIONREAD) || !defined(FIONBIO) */
250
+
251
+ #ifndef FIONREAD
252
+ #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
253
+ #endif
254
+ #ifndef FIONBIO
255
+ #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
256
+ #endif
257
+
258
+ /* Socket I/O Controls: unimplemented */
259
+ #ifndef SIOCSHIWAT
260
+ #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
261
+ #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
262
+ #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
263
+ #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
264
+ #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
265
+ #endif
266
+
267
+ /* Socket flags: */
268
+ #ifndef O_NONBLOCK
269
+ #define O_NONBLOCK 04000U
270
+ #endif
271
+
272
+ /* FD_SET used for lwip_select */
273
+ #ifndef FD_SET
274
+ #undef FD_SETSIZE
275
+ /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
276
+ #define FD_SETSIZE MEMP_NUM_NETCONN
277
+ #define FD_SET(n, p) ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7)))
278
+ #define FD_CLR(n, p) ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
279
+ #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] & (1 << ((n) & 7)))
280
+ #define FD_ZERO(p) memset((void*)(p),0,sizeof(*(p)))
281
+
282
+ typedef struct fd_set {
283
+ unsigned char fd_bits [(FD_SETSIZE+7)/8];
284
+ } fd_set;
285
+
286
+ #endif /* FD_SET */
287
+
288
+ /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
289
+ * by your system, set this to 0 and include <sys/time.h> in cc.h */
290
+ #ifndef LWIP_TIMEVAL_PRIVATE
291
+ #define LWIP_TIMEVAL_PRIVATE 1
292
+ #endif
293
+
294
+ #if LWIP_TIMEVAL_PRIVATE
295
+ struct timeval {
296
+ long tv_sec; /* seconds */
297
+ long tv_usec; /* and microseconds */
298
+ };
299
+ #endif /* LWIP_TIMEVAL_PRIVATE */
300
+
301
+ void lwip_socket_init(void);
302
+
303
+ int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
304
+ int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen);
305
+ int lwip_shutdown(int s, int how);
306
+ int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
307
+ int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
308
+ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
309
+ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
310
+ int lwip_close(int s);
311
+ int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen);
312
+ int lwip_listen(int s, int backlog);
313
+ int lwip_recv(int s, void *mem, size_t len, int flags);
314
+ int lwip_read(int s, void *mem, size_t len);
315
+ int lwip_recvfrom(int s, void *mem, size_t len, int flags,
316
+ struct sockaddr *from, socklen_t *fromlen);
317
+ int lwip_send(int s, const void *dataptr, size_t size, int flags);
318
+ int lwip_sendto(int s, const void *dataptr, size_t size, int flags,
319
+ const struct sockaddr *to, socklen_t tolen);
320
+ int lwip_socket(int domain, int type, int protocol);
321
+ int lwip_write(int s, const void *dataptr, size_t size);
322
+ int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
323
+ struct timeval *timeout);
324
+ int lwip_ioctl(int s, long cmd, void *argp);
325
+
326
+ #if LWIP_COMPAT_SOCKETS
327
+ #define accept(a,b,c) lwip_accept(a,b,c)
328
+ #define bind(a,b,c) lwip_bind(a,b,c)
329
+ #define shutdown(a,b) lwip_shutdown(a,b)
330
+ #define closesocket(s) lwip_close(s)
331
+ #define connect(a,b,c) lwip_connect(a,b,c)
332
+ #define getsockname(a,b,c) lwip_getsockname(a,b,c)
333
+ #define getpeername(a,b,c) lwip_getpeername(a,b,c)
334
+ #define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
335
+ #define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
336
+ #define listen(a,b) lwip_listen(a,b)
337
+ #define recv(a,b,c,d) lwip_recv(a,b,c,d)
338
+ #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
339
+ #define send(a,b,c,d) lwip_send(a,b,c,d)
340
+ #define sendto(a,b,c,d,e,f) lwip_sendto(a,b,c,d,e,f)
341
+ #define socket(a,b,c) lwip_socket(a,b,c)
342
+ #define select(a,b,c,d,e) lwip_select(a,b,c,d,e)
343
+ #define ioctlsocket(a,b,c) lwip_ioctl(a,b,c)
344
+
345
+ #if LWIP_POSIX_SOCKETS_IO_NAMES
346
+ #define read(a,b,c) lwip_read(a,b,c)
347
+ #define write(a,b,c) lwip_write(a,b,c)
348
+ #define close(s) lwip_close(s)
349
+ #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
350
+
351
+ #endif /* LWIP_COMPAT_SOCKETS */
352
+
353
+ #ifdef __cplusplus
354
+ }
355
+ #endif
356
+
357
+ #endif /* LWIP_SOCKET */
358
+
359
+ #endif /* __LWIP_SOCKETS_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/stats.h ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_STATS_H__
35
+ #define __LWIP_STATS_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #include "lwip/mem.h"
40
+ #include "lwip/memp.h"
41
+
42
+ #ifdef __cplusplus
43
+ extern "C" {
44
+ #endif
45
+
46
+ #if LWIP_STATS
47
+
48
+ #ifndef LWIP_STATS_LARGE
49
+ #define LWIP_STATS_LARGE 0
50
+ #endif
51
+
52
+ #if LWIP_STATS_LARGE
53
+ #define STAT_COUNTER u32_t
54
+ #define STAT_COUNTER_F U32_F
55
+ #else
56
+ #define STAT_COUNTER u16_t
57
+ #define STAT_COUNTER_F U16_F
58
+ #endif
59
+
60
+ struct stats_proto {
61
+ STAT_COUNTER xmit; /* Transmitted packets. */
62
+ STAT_COUNTER recv; /* Received packets. */
63
+ STAT_COUNTER fw; /* Forwarded packets. */
64
+ STAT_COUNTER drop; /* Dropped packets. */
65
+ STAT_COUNTER chkerr; /* Checksum error. */
66
+ STAT_COUNTER lenerr; /* Invalid length error. */
67
+ STAT_COUNTER memerr; /* Out of memory error. */
68
+ STAT_COUNTER rterr; /* Routing error. */
69
+ STAT_COUNTER proterr; /* Protocol error. */
70
+ STAT_COUNTER opterr; /* Error in options. */
71
+ STAT_COUNTER err; /* Misc error. */
72
+ STAT_COUNTER cachehit;
73
+ };
74
+
75
+ struct stats_igmp {
76
+ STAT_COUNTER lenerr; /* Invalid length error. */
77
+ STAT_COUNTER chkerr; /* Checksum error. */
78
+ STAT_COUNTER v1_rxed; /* */
79
+ STAT_COUNTER join_sent; /* */
80
+ STAT_COUNTER leave_sent; /* */
81
+ STAT_COUNTER unicast_query; /* */
82
+ STAT_COUNTER report_sent; /* */
83
+ STAT_COUNTER report_rxed; /* */
84
+ STAT_COUNTER group_query_rxed; /* */
85
+ };
86
+
87
+ struct stats_mem {
88
+ mem_size_t avail;
89
+ mem_size_t used;
90
+ mem_size_t max;
91
+ STAT_COUNTER err;
92
+ STAT_COUNTER illegal;
93
+ };
94
+
95
+ struct stats_syselem {
96
+ STAT_COUNTER used;
97
+ STAT_COUNTER max;
98
+ STAT_COUNTER err;
99
+ };
100
+
101
+ struct stats_sys {
102
+ struct stats_syselem sem;
103
+ struct stats_syselem mbox;
104
+ };
105
+
106
+ struct stats_ {
107
+ #if LINK_STATS
108
+ struct stats_proto link;
109
+ #endif
110
+ #if ETHARP_STATS
111
+ struct stats_proto etharp;
112
+ #endif
113
+ #if IPFRAG_STATS
114
+ struct stats_proto ip_frag;
115
+ #endif
116
+ #if IP_STATS
117
+ struct stats_proto ip;
118
+ #endif
119
+ #if ICMP_STATS
120
+ struct stats_proto icmp;
121
+ #endif
122
+ #if IGMP_STATS
123
+ struct stats_igmp igmp;
124
+ #endif
125
+ #if UDP_STATS
126
+ struct stats_proto udp;
127
+ #endif
128
+ #if TCP_STATS
129
+ struct stats_proto tcp;
130
+ #endif
131
+ #if MEM_STATS
132
+ struct stats_mem mem;
133
+ #endif
134
+ #if MEMP_STATS
135
+ struct stats_mem memp[MEMP_MAX];
136
+ #endif
137
+ #if SYS_STATS
138
+ struct stats_sys sys;
139
+ #endif
140
+ };
141
+
142
+ extern struct stats_ lwip_stats;
143
+
144
+ #define stats_init() /* Compatibility define, not init needed. */
145
+
146
+ #define STATS_INC(x) ++lwip_stats.x
147
+ #define STATS_DEC(x) --lwip_stats.x
148
+ #else
149
+ #define stats_init()
150
+ #define STATS_INC(x)
151
+ #define STATS_DEC(x)
152
+ #endif /* LWIP_STATS */
153
+
154
+ #if TCP_STATS
155
+ #define TCP_STATS_INC(x) STATS_INC(x)
156
+ #define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
157
+ #else
158
+ #define TCP_STATS_INC(x)
159
+ #define TCP_STATS_DISPLAY()
160
+ #endif
161
+
162
+ #if UDP_STATS
163
+ #define UDP_STATS_INC(x) STATS_INC(x)
164
+ #define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
165
+ #else
166
+ #define UDP_STATS_INC(x)
167
+ #define UDP_STATS_DISPLAY()
168
+ #endif
169
+
170
+ #if ICMP_STATS
171
+ #define ICMP_STATS_INC(x) STATS_INC(x)
172
+ #define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
173
+ #else
174
+ #define ICMP_STATS_INC(x)
175
+ #define ICMP_STATS_DISPLAY()
176
+ #endif
177
+
178
+ #if IGMP_STATS
179
+ #define IGMP_STATS_INC(x) STATS_INC(x)
180
+ #define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp)
181
+ #else
182
+ #define IGMP_STATS_INC(x)
183
+ #define IGMP_STATS_DISPLAY()
184
+ #endif
185
+
186
+ #if IP_STATS
187
+ #define IP_STATS_INC(x) STATS_INC(x)
188
+ #define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
189
+ #else
190
+ #define IP_STATS_INC(x)
191
+ #define IP_STATS_DISPLAY()
192
+ #endif
193
+
194
+ #if IPFRAG_STATS
195
+ #define IPFRAG_STATS_INC(x) STATS_INC(x)
196
+ #define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
197
+ #else
198
+ #define IPFRAG_STATS_INC(x)
199
+ #define IPFRAG_STATS_DISPLAY()
200
+ #endif
201
+
202
+ #if ETHARP_STATS
203
+ #define ETHARP_STATS_INC(x) STATS_INC(x)
204
+ #define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
205
+ #else
206
+ #define ETHARP_STATS_INC(x)
207
+ #define ETHARP_STATS_DISPLAY()
208
+ #endif
209
+
210
+ #if LINK_STATS
211
+ #define LINK_STATS_INC(x) STATS_INC(x)
212
+ #define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
213
+ #else
214
+ #define LINK_STATS_INC(x)
215
+ #define LINK_STATS_DISPLAY()
216
+ #endif
217
+
218
+ #if MEM_STATS
219
+ #define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
220
+ #define MEM_STATS_INC(x) STATS_INC(mem.x)
221
+ #define MEM_STATS_INC_USED(x, y) do { lwip_stats.mem.used += y; \
222
+ if (lwip_stats.mem.max < lwip_stats.mem.used) { \
223
+ lwip_stats.mem.max = lwip_stats.mem.used; \
224
+ } \
225
+ } while(0)
226
+ #define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
227
+ #define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
228
+ #else
229
+ #define MEM_STATS_AVAIL(x, y)
230
+ #define MEM_STATS_INC(x)
231
+ #define MEM_STATS_INC_USED(x, y)
232
+ #define MEM_STATS_DEC_USED(x, y)
233
+ #define MEM_STATS_DISPLAY()
234
+ #endif
235
+
236
+ #if MEMP_STATS
237
+ #define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
238
+ #define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
239
+ #define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
240
+ #define MEMP_STATS_INC_USED(x, i) do { ++lwip_stats.memp[i].used; \
241
+ if (lwip_stats.memp[i].max < lwip_stats.memp[i].used) { \
242
+ lwip_stats.memp[i].max = lwip_stats.memp[i].used; \
243
+ } \
244
+ } while(0)
245
+ #define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
246
+ #else
247
+ #define MEMP_STATS_AVAIL(x, i, y)
248
+ #define MEMP_STATS_INC(x, i)
249
+ #define MEMP_STATS_DEC(x, i)
250
+ #define MEMP_STATS_INC_USED(x, i)
251
+ #define MEMP_STATS_DISPLAY(i)
252
+ #endif
253
+
254
+ #if SYS_STATS
255
+ #define SYS_STATS_INC(x) STATS_INC(sys.x)
256
+ #define SYS_STATS_DEC(x) STATS_DEC(sys.x)
257
+ #define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
258
+ #else
259
+ #define SYS_STATS_INC(x)
260
+ #define SYS_STATS_DEC(x)
261
+ #define SYS_STATS_DISPLAY()
262
+ #endif
263
+
264
+ /* Display of statistics */
265
+ #if LWIP_STATS_DISPLAY
266
+ void stats_display(void);
267
+ void stats_display_proto(struct stats_proto *proto, char *name);
268
+ void stats_display_igmp(struct stats_igmp *igmp);
269
+ void stats_display_mem(struct stats_mem *mem, char *name);
270
+ void stats_display_memp(struct stats_mem *mem, int index);
271
+ void stats_display_sys(struct stats_sys *sys);
272
+ #else
273
+ #define stats_display()
274
+ #define stats_display_proto(proto, name)
275
+ #define stats_display_igmp(igmp)
276
+ #define stats_display_mem(mem, name)
277
+ #define stats_display_memp(mem, index)
278
+ #define stats_display_sys(sys)
279
+ #endif /* LWIP_STATS_DISPLAY */
280
+
281
+ #ifdef __cplusplus
282
+ }
283
+ #endif
284
+
285
+ #endif /* __LWIP_STATS_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/sys.h ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_SYS_H__
35
+ #define __LWIP_SYS_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ #if NO_SYS
44
+
45
+ /* For a totally minimal and standalone system, we provide null
46
+ definitions of the sys_ functions. */
47
+ typedef u8_t sys_sem_t;
48
+ typedef u8_t sys_mbox_t;
49
+ struct sys_timeo {u8_t dummy;};
50
+
51
+ #define sys_init()
52
+ #define sys_timeout(m,h,a)
53
+ #define sys_untimeout(m,a)
54
+ #define sys_sem_new(c) c
55
+ #define sys_sem_signal(s)
56
+ #define sys_sem_wait(s)
57
+ #define sys_sem_wait_timeout(s,t)
58
+ #define sys_arch_sem_wait(s,t)
59
+ #define sys_sem_free(s)
60
+ #define sys_mbox_new(s) 0
61
+ #define sys_mbox_fetch(m,d)
62
+ #define sys_mbox_tryfetch(m,d)
63
+ #define sys_mbox_post(m,d)
64
+ #define sys_mbox_trypost(m,d)
65
+ #define sys_mbox_free(m)
66
+
67
+ #define sys_thread_new(n,t,a,s,p)
68
+
69
+ #else /* NO_SYS */
70
+
71
+ /** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */
72
+ #define SYS_ARCH_TIMEOUT 0xffffffffUL
73
+
74
+ /* sys_mbox_tryfetch returns SYS_MBOX_EMPTY if appropriate.
75
+ * For now we use the same magic value, but we allow this to change in future.
76
+ */
77
+ #define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT
78
+
79
+ #include "lwip/err.h"
80
+ #include "arch/sys_arch.h"
81
+
82
+ typedef void (* sys_timeout_handler)(void *arg);
83
+
84
+ struct sys_timeo {
85
+ struct sys_timeo *next;
86
+ u32_t time;
87
+ sys_timeout_handler h;
88
+ void *arg;
89
+ };
90
+
91
+ struct sys_timeouts {
92
+ struct sys_timeo *next;
93
+ };
94
+
95
+ /* sys_init() must be called before anthing else. */
96
+ void sys_init(void);
97
+
98
+ /*
99
+ * sys_timeout():
100
+ *
101
+ * Schedule a timeout a specified amount of milliseconds in the
102
+ * future. When the timeout occurs, the specified timeout handler will
103
+ * be called. The handler will be passed the "arg" argument when
104
+ * called.
105
+ *
106
+ */
107
+ void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
108
+ void sys_untimeout(sys_timeout_handler h, void *arg);
109
+ struct sys_timeouts *sys_arch_timeouts(void);
110
+
111
+ /* Semaphore functions. */
112
+ sys_sem_t sys_sem_new(u8_t count);
113
+ void sys_sem_signal(sys_sem_t sem);
114
+ u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout);
115
+ void sys_sem_free(sys_sem_t sem);
116
+ void sys_sem_wait(sys_sem_t sem);
117
+ int sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout);
118
+
119
+ /* Time functions. */
120
+ #ifndef sys_msleep
121
+ void sys_msleep(u32_t ms); /* only has a (close to) 1 jiffy resolution. */
122
+ #endif
123
+ #ifndef sys_jiffies
124
+ u32_t sys_jiffies(void); /* since power up. */
125
+ #endif
126
+
127
+ /* Mailbox functions. */
128
+ sys_mbox_t sys_mbox_new(int size);
129
+ void sys_mbox_post(sys_mbox_t mbox, void *msg);
130
+ err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg);
131
+ u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout);
132
+ #ifndef sys_arch_mbox_tryfetch /* Allow port to override with a macro */
133
+ u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg);
134
+ #endif
135
+ /* For now, we map straight to sys_arch implementation. */
136
+ #define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg)
137
+ void sys_mbox_free(sys_mbox_t mbox);
138
+ void sys_mbox_fetch(sys_mbox_t mbox, void **msg);
139
+
140
+ /* Thread functions. */
141
+ sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio);
142
+
143
+ #endif /* NO_SYS */
144
+
145
+ /** Returns the current time in milliseconds. */
146
+ u32_t sys_now(void);
147
+
148
+ /* Critical Region Protection */
149
+ /* These functions must be implemented in the sys_arch.c file.
150
+ In some implementations they can provide a more light-weight protection
151
+ mechanism than using semaphores. Otherwise semaphores can be used for
152
+ implementation */
153
+ #ifndef SYS_ARCH_PROTECT
154
+ /** SYS_LIGHTWEIGHT_PROT
155
+ * define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
156
+ * for certain critical regions during buffer allocation, deallocation and memory
157
+ * allocation and deallocation.
158
+ */
159
+ #if SYS_LIGHTWEIGHT_PROT
160
+
161
+ /** SYS_ARCH_DECL_PROTECT
162
+ * declare a protection variable. This macro will default to defining a variable of
163
+ * type sys_prot_t. If a particular port needs a different implementation, then
164
+ * this macro may be defined in sys_arch.h.
165
+ */
166
+ #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
167
+ /** SYS_ARCH_PROTECT
168
+ * Perform a "fast" protect. This could be implemented by
169
+ * disabling interrupts for an embedded system or by using a semaphore or
170
+ * mutex. The implementation should allow calling SYS_ARCH_PROTECT when
171
+ * already protected. The old protection level is returned in the variable
172
+ * "lev". This macro will default to calling the sys_arch_protect() function
173
+ * which should be implemented in sys_arch.c. If a particular port needs a
174
+ * different implementation, then this macro may be defined in sys_arch.h
175
+ */
176
+ #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
177
+ /** SYS_ARCH_UNPROTECT
178
+ * Perform a "fast" set of the protection level to "lev". This could be
179
+ * implemented by setting the interrupt level to "lev" within the MACRO or by
180
+ * using a semaphore or mutex. This macro will default to calling the
181
+ * sys_arch_unprotect() function which should be implemented in
182
+ * sys_arch.c. If a particular port needs a different implementation, then
183
+ * this macro may be defined in sys_arch.h
184
+ */
185
+ #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)
186
+ sys_prot_t sys_arch_protect(void);
187
+ void sys_arch_unprotect(sys_prot_t pval);
188
+
189
+ #else
190
+
191
+ #define SYS_ARCH_DECL_PROTECT(lev)
192
+ #define SYS_ARCH_PROTECT(lev)
193
+ #define SYS_ARCH_UNPROTECT(lev)
194
+
195
+ #endif /* SYS_LIGHTWEIGHT_PROT */
196
+
197
+ #endif /* SYS_ARCH_PROTECT */
198
+
199
+ /*
200
+ * Macros to set/get and increase/decrease variables in a thread-safe way.
201
+ * Use these for accessing variable that are used from more than one thread.
202
+ */
203
+
204
+ #ifndef SYS_ARCH_INC
205
+ #define SYS_ARCH_INC(var, val) do { \
206
+ SYS_ARCH_DECL_PROTECT(old_level); \
207
+ SYS_ARCH_PROTECT(old_level); \
208
+ var += val; \
209
+ SYS_ARCH_UNPROTECT(old_level); \
210
+ } while(0)
211
+ #endif /* SYS_ARCH_INC */
212
+
213
+ #ifndef SYS_ARCH_DEC
214
+ #define SYS_ARCH_DEC(var, val) do { \
215
+ SYS_ARCH_DECL_PROTECT(old_level); \
216
+ SYS_ARCH_PROTECT(old_level); \
217
+ var -= val; \
218
+ SYS_ARCH_UNPROTECT(old_level); \
219
+ } while(0)
220
+ #endif /* SYS_ARCH_DEC */
221
+
222
+ #ifndef SYS_ARCH_GET
223
+ #define SYS_ARCH_GET(var, ret) do { \
224
+ SYS_ARCH_DECL_PROTECT(old_level); \
225
+ SYS_ARCH_PROTECT(old_level); \
226
+ ret = var; \
227
+ SYS_ARCH_UNPROTECT(old_level); \
228
+ } while(0)
229
+ #endif /* SYS_ARCH_GET */
230
+
231
+ #ifndef SYS_ARCH_SET
232
+ #define SYS_ARCH_SET(var, val) do { \
233
+ SYS_ARCH_DECL_PROTECT(old_level); \
234
+ SYS_ARCH_PROTECT(old_level); \
235
+ var = val; \
236
+ SYS_ARCH_UNPROTECT(old_level); \
237
+ } while(0)
238
+ #endif /* SYS_ARCH_SET */
239
+
240
+
241
+ #ifdef __cplusplus
242
+ }
243
+ #endif
244
+
245
+ #endif /* __LWIP_SYS_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/tcp.h ADDED
@@ -0,0 +1,709 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_TCP_H__
35
+ #define __LWIP_TCP_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
40
+
41
+ #include "lwip/sys.h"
42
+ #include "lwip/mem.h"
43
+ #include "lwip/pbuf.h"
44
+ #include "lwip/ip.h"
45
+ #include "lwip/icmp.h"
46
+ #include "lwip/err.h"
47
+
48
+ #ifdef __cplusplus
49
+ extern "C" {
50
+ #endif
51
+
52
+ struct tcp_pcb;
53
+
54
+ /* Functions for interfacing with TCP: */
55
+
56
+ /* Lower layer interface to TCP: */
57
+ #define tcp_init() /* Compatibility define, not init needed. */
58
+ void tcp_tmr (void); /* Must be called every
59
+ TCP_TMR_INTERVAL
60
+ ms. (Typically 250 ms). */
61
+ /* Application program's interface: */
62
+ struct tcp_pcb * tcp_new (void);
63
+ struct tcp_pcb * tcp_alloc (u8_t prio);
64
+
65
+ void tcp_arg (struct tcp_pcb *pcb, void *arg);
66
+ void tcp_accept (struct tcp_pcb *pcb,
67
+ err_t (* accept)(void *arg, struct tcp_pcb *newpcb,
68
+ err_t err));
69
+ void tcp_recv (struct tcp_pcb *pcb,
70
+ err_t (* recv)(void *arg, struct tcp_pcb *tpcb,
71
+ struct pbuf *p, err_t err));
72
+ void tcp_sent (struct tcp_pcb *pcb,
73
+ err_t (* sent)(void *arg, struct tcp_pcb *tpcb,
74
+ u16_t len));
75
+ void tcp_poll (struct tcp_pcb *pcb,
76
+ err_t (* poll)(void *arg, struct tcp_pcb *tpcb),
77
+ u8_t interval);
78
+ void tcp_err (struct tcp_pcb *pcb,
79
+ void (* err)(void *arg, err_t err));
80
+
81
+ #define tcp_mss(pcb) ((pcb)->mss)
82
+ #define tcp_sndbuf(pcb) ((pcb)->snd_buf)
83
+ #define tcp_nagle_disable(pcb) ((pcb)->flags |= TF_NODELAY)
84
+ #define tcp_nagle_enable(pcb) ((pcb)->flags &= ~TF_NODELAY)
85
+ #define tcp_nagle_disabled(pcb) (((pcb)->flags & TF_NODELAY) != 0)
86
+
87
+ #if TCP_LISTEN_BACKLOG
88
+ #define tcp_accepted(pcb) (((struct tcp_pcb_listen *)(pcb))->accepts_pending--)
89
+ #else /* TCP_LISTEN_BACKLOG */
90
+ #define tcp_accepted(pcb)
91
+ #endif /* TCP_LISTEN_BACKLOG */
92
+
93
+ void tcp_recved (struct tcp_pcb *pcb, u16_t len);
94
+ err_t tcp_bind (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
95
+ u16_t port);
96
+ err_t tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
97
+ u16_t port, err_t (* connected)(void *arg,
98
+ struct tcp_pcb *tpcb,
99
+ err_t err));
100
+
101
+ struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog);
102
+ #define tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG)
103
+
104
+ void tcp_abandon (struct tcp_pcb *pcb, int reset);
105
+ #define tcp_abort(pcb) tcp_abandon((pcb), 1)
106
+ err_t tcp_close (struct tcp_pcb *pcb);
107
+
108
+ /* Flags for "apiflags" parameter in tcp_write and tcp_enqueue */
109
+ #define TCP_WRITE_FLAG_COPY 0x01
110
+ #define TCP_WRITE_FLAG_MORE 0x02
111
+
112
+ err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, u16_t len,
113
+ u8_t apiflags);
114
+
115
+ void tcp_setprio (struct tcp_pcb *pcb, u8_t prio);
116
+
117
+ #define TCP_PRIO_MIN 1
118
+ #define TCP_PRIO_NORMAL 64
119
+ #define TCP_PRIO_MAX 127
120
+
121
+ /* It is also possible to call these two functions at the right
122
+ intervals (instead of calling tcp_tmr()). */
123
+ void tcp_slowtmr (void);
124
+ void tcp_fasttmr (void);
125
+
126
+
127
+ /* Only used by IP to pass a TCP segment to TCP: */
128
+ void tcp_input (struct pbuf *p, struct netif *inp);
129
+ /* Used within the TCP code only: */
130
+ err_t tcp_send_empty_ack(struct tcp_pcb *pcb);
131
+ err_t tcp_output (struct tcp_pcb *pcb);
132
+ void tcp_rexmit (struct tcp_pcb *pcb);
133
+ void tcp_rexmit_rto (struct tcp_pcb *pcb);
134
+ void tcp_rexmit_fast (struct tcp_pcb *pcb);
135
+ u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb);
136
+
137
+ /**
138
+ * This is the Nagle algorithm: try to combine user data to send as few TCP
139
+ * segments as possible. Only send if
140
+ * - no previously transmitted data on the connection remains unacknowledged or
141
+ * - the TF_NODELAY flag is set (nagle algorithm turned off for this pcb) or
142
+ * - the only unsent segment is at least pcb->mss bytes long (or there is more
143
+ * than one unsent segment - with lwIP, this can happen although unsent->len < mss)
144
+ * - or if we are in fast-retransmit (TF_INFR)
145
+ */
146
+ #define tcp_do_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \
147
+ ((tpcb)->flags & (TF_NODELAY | TF_INFR)) || \
148
+ (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \
149
+ ((tpcb)->unsent->len >= (tpcb)->mss))) \
150
+ ) ? 1 : 0)
151
+ #define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK)
152
+
153
+
154
+ #define TCP_SEQ_LT(a,b) ((s32_t)((a)-(b)) < 0)
155
+ #define TCP_SEQ_LEQ(a,b) ((s32_t)((a)-(b)) <= 0)
156
+ #define TCP_SEQ_GT(a,b) ((s32_t)((a)-(b)) > 0)
157
+ #define TCP_SEQ_GEQ(a,b) ((s32_t)((a)-(b)) >= 0)
158
+ /* is b<=a<=c? */
159
+ #if 0 /* see bug #10548 */
160
+ #define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b))
161
+ #endif
162
+ #define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
163
+ #define TCP_FIN 0x01U
164
+ #define TCP_SYN 0x02U
165
+ #define TCP_RST 0x04U
166
+ #define TCP_PSH 0x08U
167
+ #define TCP_ACK 0x10U
168
+ #define TCP_URG 0x20U
169
+ #define TCP_ECE 0x40U
170
+ #define TCP_CWR 0x80U
171
+
172
+ #define TCP_FLAGS 0x3fU
173
+
174
+ /* Length of the TCP header, excluding options. */
175
+ #define TCP_HLEN 20
176
+
177
+ #ifndef TCP_TMR_INTERVAL
178
+ #define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */
179
+ #endif /* TCP_TMR_INTERVAL */
180
+
181
+ #ifndef TCP_FAST_INTERVAL
182
+ #define TCP_FAST_INTERVAL TCP_TMR_INTERVAL /* the fine grained timeout in milliseconds */
183
+ #endif /* TCP_FAST_INTERVAL */
184
+
185
+ #ifndef TCP_SLOW_INTERVAL
186
+ #define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) /* the coarse grained timeout in milliseconds */
187
+ #endif /* TCP_SLOW_INTERVAL */
188
+
189
+ #define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */
190
+ #define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */
191
+
192
+ #define TCP_OOSEQ_TIMEOUT 6U /* x RTO */
193
+
194
+ #ifndef TCP_MSL
195
+ #define TCP_MSL 60000UL /* The maximum segment lifetime in milliseconds */
196
+ #endif
197
+
198
+ /* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */
199
+ #ifndef TCP_KEEPIDLE_DEFAULT
200
+ #define TCP_KEEPIDLE_DEFAULT 7200000UL /* Default KEEPALIVE timer in milliseconds */
201
+ #endif
202
+
203
+ #ifndef TCP_KEEPINTVL_DEFAULT
204
+ #define TCP_KEEPINTVL_DEFAULT 75000UL /* Default Time between KEEPALIVE probes in milliseconds */
205
+ #endif
206
+
207
+ #ifndef TCP_KEEPCNT_DEFAULT
208
+ #define TCP_KEEPCNT_DEFAULT 9U /* Default Counter for KEEPALIVE probes */
209
+ #endif
210
+
211
+ #define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */
212
+
213
+ /* Fields are (of course) in network byte order.
214
+ * Some fields are converted to host byte order in tcp_input().
215
+ */
216
+ #ifdef PACK_STRUCT_USE_INCLUDES
217
+ # include "arch/bpstruct.h"
218
+ #endif
219
+ PACK_STRUCT_BEGIN
220
+ struct tcp_hdr {
221
+ PACK_STRUCT_FIELD(u16_t src);
222
+ PACK_STRUCT_FIELD(u16_t dest);
223
+ PACK_STRUCT_FIELD(u32_t seqno);
224
+ PACK_STRUCT_FIELD(u32_t ackno);
225
+ PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);
226
+ PACK_STRUCT_FIELD(u16_t wnd);
227
+ PACK_STRUCT_FIELD(u16_t chksum);
228
+ PACK_STRUCT_FIELD(u16_t urgp);
229
+ } PACK_STRUCT_STRUCT;
230
+ PACK_STRUCT_END
231
+ #ifdef PACK_STRUCT_USE_INCLUDES
232
+ # include "arch/epstruct.h"
233
+ #endif
234
+
235
+ #define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
236
+ #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
237
+ #define TCPH_FLAGS(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
238
+
239
+ #define TCPH_OFFSET_SET(phdr, offset) (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
240
+ #define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
241
+ #define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & htons((u16_t)(~(u16_t)(TCP_FLAGS)))) | htons(flags))
242
+ #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
243
+ #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
244
+
245
+ #define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
246
+
247
+ enum tcp_state {
248
+ CLOSED = 0,
249
+ LISTEN = 1,
250
+ SYN_SENT = 2,
251
+ SYN_RCVD = 3,
252
+ ESTABLISHED = 4,
253
+ FIN_WAIT_1 = 5,
254
+ FIN_WAIT_2 = 6,
255
+ CLOSE_WAIT = 7,
256
+ CLOSING = 8,
257
+ LAST_ACK = 9,
258
+ TIME_WAIT = 10
259
+ };
260
+
261
+ /** Flags used on input processing, not on pcb->flags
262
+ */
263
+ #define TF_RESET (u8_t)0x08U /* Connection was reset. */
264
+ #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */
265
+ #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */
266
+
267
+
268
+ #if LWIP_CALLBACK_API
269
+ /* Function to call when a listener has been connected.
270
+ * @param arg user-supplied argument (tcp_pcb.callback_arg)
271
+ * @param pcb a new tcp_pcb that now is connected
272
+ * @param err an error argument (TODO: that is current always ERR_OK?)
273
+ * @return ERR_OK: accept the new connection,
274
+ * any other err_t abortsthe new connection
275
+ */
276
+ #define DEF_ACCEPT_CALLBACK err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err)
277
+ #else /* LWIP_CALLBACK_API */
278
+ #define DEF_ACCEPT_CALLBACK
279
+ #endif /* LWIP_CALLBACK_API */
280
+
281
+ /**
282
+ * members common to struct tcp_pcb and struct tcp_listen_pcb
283
+ */
284
+ #define TCP_PCB_COMMON(type) \
285
+ type *next; /* for the linked list */ \
286
+ enum tcp_state state; /* TCP state */ \
287
+ u8_t prio; \
288
+ void *callback_arg; \
289
+ /* ports are in host byte order */ \
290
+ u16_t local_port; \
291
+ /* the accept callback for listen- and normal pcbs, if LWIP_CALLBACK_API */ \
292
+ DEF_ACCEPT_CALLBACK
293
+
294
+
295
+ /* the TCP protocol control block */
296
+ struct tcp_pcb {
297
+ /** common PCB members */
298
+ IP_PCB;
299
+ /** protocol specific PCB members */
300
+ TCP_PCB_COMMON(struct tcp_pcb);
301
+
302
+ /* ports are in host byte order */
303
+ u16_t remote_port;
304
+
305
+ u8_t flags;
306
+ #define TF_ACK_DELAY ((u8_t)0x01U) /* Delayed ACK. */
307
+ #define TF_ACK_NOW ((u8_t)0x02U) /* Immediate ACK. */
308
+ #define TF_INFR ((u8_t)0x04U) /* In fast recovery. */
309
+ #define TF_TIMESTAMP ((u8_t)0x08U) /* Timestamp option enabled */
310
+ #define TF_FIN ((u8_t)0x20U) /* Connection was closed locally (FIN segment enqueued). */
311
+ #define TF_NODELAY ((u8_t)0x40U) /* Disable Nagle algorithm */
312
+ #define TF_NAGLEMEMERR ((u8_t)0x80U) /* nagle enabled, memerr, try to output to prevent delayed ACK to happen */
313
+
314
+ /* the rest of the fields are in host byte order
315
+ as we have to do some math with them */
316
+ /* receiver variables */
317
+ u32_t rcv_nxt; /* next seqno expected */
318
+ u16_t rcv_wnd; /* receiver window available */
319
+ u16_t rcv_ann_wnd; /* receiver window to announce */
320
+ u32_t rcv_ann_right_edge; /* announced right edge of window */
321
+
322
+ /* Timers */
323
+ u32_t tmr;
324
+ u8_t polltmr, pollinterval;
325
+
326
+ /* Retransmission timer. */
327
+ s16_t rtime;
328
+
329
+ u16_t mss; /* maximum segment size */
330
+
331
+ /* RTT (round trip time) estimation variables */
332
+ u32_t rttest; /* RTT estimate in 500ms ticks */
333
+ u32_t rtseq; /* sequence number being timed */
334
+ s16_t sa, sv; /* @todo document this */
335
+
336
+ s16_t rto; /* retransmission time-out */
337
+ u8_t nrtx; /* number of retransmissions */
338
+
339
+ /* fast retransmit/recovery */
340
+ u32_t lastack; /* Highest acknowledged seqno. */
341
+ u8_t dupacks;
342
+
343
+ /* congestion avoidance/control variables */
344
+ u16_t cwnd;
345
+ u16_t ssthresh;
346
+
347
+ /* sender variables */
348
+ u32_t snd_nxt; /* next new seqno to be sent */
349
+ u16_t snd_wnd; /* sender window */
350
+ u32_t snd_wl1, snd_wl2; /* Sequence and acknowledgement numbers of last
351
+ window update. */
352
+ u32_t snd_lbb; /* Sequence number of next byte to be buffered. */
353
+
354
+ u16_t acked;
355
+
356
+ u16_t snd_buf; /* Available buffer space for sending (in bytes). */
357
+ #define TCP_SNDQUEUELEN_OVERFLOW (0xffff-3)
358
+ u16_t snd_queuelen; /* Available buffer space for sending (in tcp_segs). */
359
+
360
+
361
+ /* These are ordered by sequence number: */
362
+ struct tcp_seg *unsent; /* Unsent (queued) segments. */
363
+ struct tcp_seg *unacked; /* Sent but unacknowledged segments. */
364
+ #if TCP_QUEUE_OOSEQ
365
+ struct tcp_seg *ooseq; /* Received out of sequence segments. */
366
+ #endif /* TCP_QUEUE_OOSEQ */
367
+
368
+ struct pbuf *refused_data; /* Data previously received but not yet taken by upper layer */
369
+
370
+ #if LWIP_CALLBACK_API
371
+ /* Function to be called when more send buffer space is available.
372
+ * @param arg user-supplied argument (tcp_pcb.callback_arg)
373
+ * @param pcb the tcp_pcb which has send buffer space available
374
+ * @param space the amount of bytes available
375
+ * @return ERR_OK: try to send some data by calling tcp_output
376
+ */
377
+ err_t (* sent)(void *arg, struct tcp_pcb *pcb, u16_t space);
378
+
379
+ /* Function to be called when (in-sequence) data has arrived.
380
+ * @param arg user-supplied argument (tcp_pcb.callback_arg)
381
+ * @param pcb the tcp_pcb for which data has arrived
382
+ * @param p the packet buffer which arrived
383
+ * @param err an error argument (TODO: that is current always ERR_OK?)
384
+ * @return ERR_OK: try to send some data by calling tcp_output
385
+ */
386
+ err_t (* recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
387
+
388
+ /* Function to be called when a connection has been set up.
389
+ * @param arg user-supplied argument (tcp_pcb.callback_arg)
390
+ * @param pcb the tcp_pcb that now is connected
391
+ * @param err an error argument (TODO: that is current always ERR_OK?)
392
+ * @return value is currently ignored
393
+ */
394
+ err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err);
395
+
396
+ /* Function which is called periodically.
397
+ * The period can be adjusted in multiples of the TCP slow timer interval
398
+ * by changing tcp_pcb.polltmr.
399
+ * @param arg user-supplied argument (tcp_pcb.callback_arg)
400
+ * @param pcb the tcp_pcb to poll for
401
+ * @return ERR_OK: try to send some data by calling tcp_output
402
+ */
403
+ err_t (* poll)(void *arg, struct tcp_pcb *pcb);
404
+
405
+ /* Function to be called whenever a fatal error occurs.
406
+ * There is no pcb parameter since most of the times, the pcb is
407
+ * already deallocated (or there is no pcb) when this function is called.
408
+ * @param arg user-supplied argument (tcp_pcb.callback_arg)
409
+ * @param err an indication why the error callback is called:
410
+ * ERR_ABRT: aborted through tcp_abort or by a TCP timer
411
+ * ERR_RST: the connection was reset by the remote host
412
+ */
413
+ void (* errf)(void *arg, err_t err);
414
+ #endif /* LWIP_CALLBACK_API */
415
+
416
+ #if LWIP_TCP_TIMESTAMPS
417
+ u32_t ts_lastacksent;
418
+ u32_t ts_recent;
419
+ #endif /* LWIP_TCP_TIMESTAMPS */
420
+
421
+ /* idle time before KEEPALIVE is sent */
422
+ u32_t keep_idle;
423
+ #if LWIP_TCP_KEEPALIVE
424
+ u32_t keep_intvl;
425
+ u32_t keep_cnt;
426
+ #endif /* LWIP_TCP_KEEPALIVE */
427
+
428
+ /* Persist timer counter */
429
+ u32_t persist_cnt;
430
+ /* Persist timer back-off */
431
+ u8_t persist_backoff;
432
+
433
+ /* KEEPALIVE counter */
434
+ u8_t keep_cnt_sent;
435
+ };
436
+
437
+ struct tcp_pcb_listen {
438
+ /* Common members of all PCB types */
439
+ IP_PCB;
440
+ /* Protocol specific PCB members */
441
+ TCP_PCB_COMMON(struct tcp_pcb_listen);
442
+
443
+ #if TCP_LISTEN_BACKLOG
444
+ u8_t backlog;
445
+ u8_t accepts_pending;
446
+ #endif /* TCP_LISTEN_BACKLOG */
447
+ };
448
+
449
+ #if LWIP_EVENT_API
450
+
451
+ enum lwip_event {
452
+ LWIP_EVENT_ACCEPT,
453
+ LWIP_EVENT_SENT,
454
+ LWIP_EVENT_RECV,
455
+ LWIP_EVENT_CONNECTED,
456
+ LWIP_EVENT_POLL,
457
+ LWIP_EVENT_ERR
458
+ };
459
+
460
+ err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb,
461
+ enum lwip_event,
462
+ struct pbuf *p,
463
+ u16_t size,
464
+ err_t err);
465
+
466
+ #define TCP_EVENT_ACCEPT(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
467
+ LWIP_EVENT_ACCEPT, NULL, 0, err)
468
+ #define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
469
+ LWIP_EVENT_SENT, NULL, space, ERR_OK)
470
+ #define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
471
+ LWIP_EVENT_RECV, (p), 0, (err))
472
+ #define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
473
+ LWIP_EVENT_CONNECTED, NULL, 0, (err))
474
+ #define TCP_EVENT_POLL(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\
475
+ LWIP_EVENT_POLL, NULL, 0, ERR_OK)
476
+ #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \
477
+ LWIP_EVENT_ERR, NULL, 0, (err))
478
+ #else /* LWIP_EVENT_API */
479
+
480
+ #define TCP_EVENT_ACCEPT(pcb,err,ret) \
481
+ do { \
482
+ if((pcb)->accept != NULL) \
483
+ (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \
484
+ else (ret) = ERR_OK; \
485
+ } while (0)
486
+
487
+ #define TCP_EVENT_SENT(pcb,space,ret) \
488
+ do { \
489
+ if((pcb)->sent != NULL) \
490
+ (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \
491
+ else (ret) = ERR_OK; \
492
+ } while (0)
493
+
494
+ #define TCP_EVENT_RECV(pcb,p,err,ret) \
495
+ do { \
496
+ if((pcb)->recv != NULL) { \
497
+ (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err)); \
498
+ } else { \
499
+ (ret) = tcp_recv_null(NULL, (pcb), (p), (err)); \
500
+ } \
501
+ } while (0)
502
+
503
+ #define TCP_EVENT_CONNECTED(pcb,err,ret) \
504
+ do { \
505
+ if((pcb)->connected != NULL) \
506
+ (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \
507
+ else (ret) = ERR_OK; \
508
+ } while (0)
509
+
510
+ #define TCP_EVENT_POLL(pcb,ret) \
511
+ do { \
512
+ if((pcb)->poll != NULL) \
513
+ (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \
514
+ else (ret) = ERR_OK; \
515
+ } while (0)
516
+
517
+ #define TCP_EVENT_ERR(errf,arg,err) \
518
+ do { \
519
+ if((errf) != NULL) \
520
+ (errf)((arg),(err)); \
521
+ } while (0)
522
+
523
+ #endif /* LWIP_EVENT_API */
524
+
525
+ /* This structure represents a TCP segment on the unsent and unacked queues */
526
+ struct tcp_seg {
527
+ struct tcp_seg *next; /* used when putting segements on a queue */
528
+ struct pbuf *p; /* buffer containing data + TCP header */
529
+ void *dataptr; /* pointer to the TCP data in the pbuf */
530
+ u16_t len; /* the TCP length of this segment */
531
+ u8_t flags;
532
+ #define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */
533
+ #define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */
534
+ struct tcp_hdr *tcphdr; /* the TCP header */
535
+ };
536
+
537
+ #define LWIP_TCP_OPT_LENGTH(flags) \
538
+ (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \
539
+ (flags & TF_SEG_OPTS_TS ? 12 : 0)
540
+
541
+ /** This returns a TCP header option for MSS in an u32_t */
542
+ #define TCP_BUILD_MSS_OPTION(x) (x) = htonl(((u32_t)2 << 24) | \
543
+ ((u32_t)4 << 16) | \
544
+ (((u32_t)TCP_MSS / 256) << 8) | \
545
+ (TCP_MSS & 255))
546
+
547
+ /* Internal functions and global variables: */
548
+ struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb);
549
+ void tcp_pcb_purge(struct tcp_pcb *pcb);
550
+ void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb);
551
+
552
+ u8_t tcp_segs_free(struct tcp_seg *seg);
553
+ u8_t tcp_seg_free(struct tcp_seg *seg);
554
+ struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);
555
+
556
+ #define tcp_ack(pcb) \
557
+ do { \
558
+ if((pcb)->flags & TF_ACK_DELAY) { \
559
+ (pcb)->flags &= ~TF_ACK_DELAY; \
560
+ (pcb)->flags |= TF_ACK_NOW; \
561
+ tcp_output(pcb); \
562
+ } \
563
+ else { \
564
+ (pcb)->flags |= TF_ACK_DELAY; \
565
+ } \
566
+ } while (0)
567
+
568
+ #define tcp_ack_now(pcb) \
569
+ do { \
570
+ (pcb)->flags |= TF_ACK_NOW; \
571
+ tcp_output(pcb); \
572
+ } while (0)
573
+
574
+ err_t tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags);
575
+ err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, u16_t len,
576
+ u8_t flags, u8_t apiflags, u8_t optflags);
577
+
578
+ void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
579
+
580
+ void tcp_rst(u32_t seqno, u32_t ackno,
581
+ struct ip_addr *local_ip, struct ip_addr *remote_ip,
582
+ u16_t local_port, u16_t remote_port);
583
+
584
+ u32_t tcp_next_iss(void);
585
+
586
+ void tcp_keepalive(struct tcp_pcb *pcb);
587
+ void tcp_zero_window_probe(struct tcp_pcb *pcb);
588
+
589
+ #if TCP_CALCULATE_EFF_SEND_MSS
590
+ u16_t tcp_eff_send_mss(u16_t sendmss, struct ip_addr *addr);
591
+ #endif /* TCP_CALCULATE_EFF_SEND_MSS */
592
+
593
+ #if LWIP_CALLBACK_API
594
+ err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
595
+ #endif /* LWIP_CALLBACK_API */
596
+
597
+ extern struct tcp_pcb *tcp_input_pcb;
598
+ extern u32_t tcp_ticks;
599
+
600
+ const char* tcp_debug_state_str(enum tcp_state s);
601
+ #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
602
+ void tcp_debug_print(struct tcp_hdr *tcphdr);
603
+ void tcp_debug_print_flags(u8_t flags);
604
+ void tcp_debug_print_state(enum tcp_state s);
605
+ void tcp_debug_print_pcbs(void);
606
+ s16_t tcp_pcbs_sane(void);
607
+ #else
608
+ # define tcp_debug_print(tcphdr)
609
+ # define tcp_debug_print_flags(flags)
610
+ # define tcp_debug_print_state(s)
611
+ # define tcp_debug_print_pcbs()
612
+ # define tcp_pcbs_sane() 1
613
+ #endif /* TCP_DEBUG */
614
+
615
+ #if NO_SYS
616
+ #define tcp_timer_needed()
617
+ #else
618
+ void tcp_timer_needed(void);
619
+ #endif
620
+
621
+ /* The TCP PCB lists. */
622
+ union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
623
+ struct tcp_pcb_listen *listen_pcbs;
624
+ struct tcp_pcb *pcbs;
625
+ };
626
+ extern union tcp_listen_pcbs_t tcp_listen_pcbs;
627
+ extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a
628
+ state in which they accept or send
629
+ data. */
630
+ extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */
631
+
632
+ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
633
+
634
+ /* Axioms about the above lists:
635
+ 1) Every TCP PCB that is not CLOSED is in one of the lists.
636
+ 2) A PCB is only in one of the lists.
637
+ 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
638
+ 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.
639
+ */
640
+
641
+ /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB
642
+ with a PCB list or removes a PCB from a list, respectively. */
643
+ #if 0
644
+ #define TCP_REG(pcbs, npcb) do {\
645
+ LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", npcb, npcb->local_port)); \
646
+ for(tcp_tmp_pcb = *pcbs; \
647
+ tcp_tmp_pcb != NULL; \
648
+ tcp_tmp_pcb = tcp_tmp_pcb->next) { \
649
+ LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != npcb); \
650
+ } \
651
+ LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", npcb->state != CLOSED); \
652
+ npcb->next = *pcbs; \
653
+ LWIP_ASSERT("TCP_REG: npcb->next != npcb", npcb->next != npcb); \
654
+ *(pcbs) = npcb; \
655
+ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
656
+ tcp_timer_needed(); \
657
+ } while(0)
658
+ #define TCP_RMV(pcbs, npcb) do { \
659
+ LWIP_ASSERT("TCP_RMV: pcbs != NULL", *pcbs != NULL); \
660
+ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", npcb, *pcbs)); \
661
+ if(*pcbs == npcb) { \
662
+ *pcbs = (*pcbs)->next; \
663
+ } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
664
+ if(tcp_tmp_pcb->next == npcb) { \
665
+ tcp_tmp_pcb->next = npcb->next; \
666
+ break; \
667
+ } \
668
+ } \
669
+ npcb->next = NULL; \
670
+ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
671
+ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", npcb, *pcbs)); \
672
+ } while(0)
673
+
674
+ #else /* LWIP_DEBUG */
675
+
676
+ #define TCP_REG(pcbs, npcb) \
677
+ do { \
678
+ npcb->next = *pcbs; \
679
+ *(pcbs) = npcb; \
680
+ tcp_timer_needed(); \
681
+ } while (0)
682
+
683
+ #define TCP_RMV(pcbs, npcb) \
684
+ do { \
685
+ if(*(pcbs) == npcb) { \
686
+ (*(pcbs)) = (*pcbs)->next; \
687
+ } \
688
+ else { \
689
+ for(tcp_tmp_pcb = *pcbs; \
690
+ tcp_tmp_pcb != NULL; \
691
+ tcp_tmp_pcb = tcp_tmp_pcb->next) { \
692
+ if(tcp_tmp_pcb->next == npcb) { \
693
+ tcp_tmp_pcb->next = npcb->next; \
694
+ break; \
695
+ } \
696
+ } \
697
+ } \
698
+ npcb->next = NULL; \
699
+ } while(0)
700
+
701
+ #endif /* LWIP_DEBUG */
702
+
703
+ #ifdef __cplusplus
704
+ }
705
+ #endif
706
+
707
+ #endif /* LWIP_TCP */
708
+
709
+ #endif /* __LWIP_TCP_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/tcpip.h ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_TCPIP_H__
35
+ #define __LWIP_TCPIP_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #if !NO_SYS /* don't build if not configured for use in lwipopts.h */
40
+
41
+ #include "lwip/api_msg.h"
42
+ #include "lwip/netifapi.h"
43
+ #include "lwip/pbuf.h"
44
+ #include "lwip/api.h"
45
+ #include "lwip/sys.h"
46
+ #include "lwip/netif.h"
47
+
48
+ #ifdef __cplusplus
49
+ extern "C" {
50
+ #endif
51
+
52
+ #if LWIP_TCPIP_CORE_LOCKING
53
+ /** The global semaphore to lock the stack. */
54
+ extern sys_sem_t lock_tcpip_core;
55
+ #define LOCK_TCPIP_CORE() sys_sem_wait(lock_tcpip_core)
56
+ #define UNLOCK_TCPIP_CORE() sys_sem_signal(lock_tcpip_core)
57
+ #define TCPIP_APIMSG(m) tcpip_apimsg_lock(m)
58
+ #define TCPIP_APIMSG_ACK(m)
59
+ #define TCPIP_NETIFAPI(m) tcpip_netifapi_lock(m)
60
+ #define TCPIP_NETIFAPI_ACK(m)
61
+ #else
62
+ #define LOCK_TCPIP_CORE()
63
+ #define UNLOCK_TCPIP_CORE()
64
+ #define TCPIP_APIMSG(m) tcpip_apimsg(m)
65
+ #define TCPIP_APIMSG_ACK(m) sys_sem_signal(m->conn->op_completed)
66
+ #define TCPIP_NETIFAPI(m) tcpip_netifapi(m)
67
+ #define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(m->sem)
68
+ #endif /* LWIP_TCPIP_CORE_LOCKING */
69
+
70
+ void tcpip_init(void (* tcpip_init_done)(void *), void *arg);
71
+
72
+ #if LWIP_NETCONN
73
+ err_t tcpip_apimsg(struct api_msg *apimsg);
74
+ #if LWIP_TCPIP_CORE_LOCKING
75
+ err_t tcpip_apimsg_lock(struct api_msg *apimsg);
76
+ #endif /* LWIP_TCPIP_CORE_LOCKING */
77
+ #endif /* LWIP_NETCONN */
78
+
79
+ err_t tcpip_input(struct pbuf *p, struct netif *inp);
80
+
81
+ #if LWIP_NETIF_API
82
+ err_t tcpip_netifapi(struct netifapi_msg *netifapimsg);
83
+ #if LWIP_TCPIP_CORE_LOCKING
84
+ err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg);
85
+ #endif /* LWIP_TCPIP_CORE_LOCKING */
86
+ #endif /* LWIP_NETIF_API */
87
+
88
+ err_t tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block);
89
+ #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1)
90
+
91
+ /* free pbufs or heap memory from another context without blocking */
92
+ err_t pbuf_free_callback(struct pbuf *p);
93
+ err_t mem_free_callback(void *m);
94
+
95
+ err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
96
+ err_t tcpip_untimeout(sys_timeout_handler h, void *arg);
97
+
98
+ enum tcpip_msg_type {
99
+ #if LWIP_NETCONN
100
+ TCPIP_MSG_API,
101
+ #endif /* LWIP_NETCONN */
102
+ TCPIP_MSG_INPKT,
103
+ #if LWIP_NETIF_API
104
+ TCPIP_MSG_NETIFAPI,
105
+ #endif /* LWIP_NETIF_API */
106
+ TCPIP_MSG_CALLBACK,
107
+ TCPIP_MSG_TIMEOUT,
108
+ TCPIP_MSG_UNTIMEOUT
109
+ };
110
+
111
+ struct tcpip_msg {
112
+ enum tcpip_msg_type type;
113
+ sys_sem_t *sem;
114
+ union {
115
+ #if LWIP_NETCONN
116
+ struct api_msg *apimsg;
117
+ #endif /* LWIP_NETCONN */
118
+ #if LWIP_NETIF_API
119
+ struct netifapi_msg *netifapimsg;
120
+ #endif /* LWIP_NETIF_API */
121
+ struct {
122
+ struct pbuf *p;
123
+ struct netif *netif;
124
+ } inp;
125
+ struct {
126
+ void (*f)(void *ctx);
127
+ void *ctx;
128
+ } cb;
129
+ struct {
130
+ u32_t msecs;
131
+ sys_timeout_handler h;
132
+ void *arg;
133
+ } tmo;
134
+ } msg;
135
+ };
136
+
137
+ #ifdef __cplusplus
138
+ }
139
+ #endif
140
+
141
+ #endif /* !NO_SYS */
142
+
143
+ #endif /* __LWIP_TCPIP_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/lwip/udp.h ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __LWIP_UDP_H__
35
+ #define __LWIP_UDP_H__
36
+
37
+ #include "lwip/opt.h"
38
+
39
+ #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
40
+
41
+ #include "lwip/pbuf.h"
42
+ #include "lwip/netif.h"
43
+ #include "lwip/ip_addr.h"
44
+ #include "lwip/ip.h"
45
+
46
+ #ifdef __cplusplus
47
+ extern "C" {
48
+ #endif
49
+
50
+ #define UDP_HLEN 8
51
+
52
+ /* Fields are (of course) in network byte order. */
53
+ #ifdef PACK_STRUCT_USE_INCLUDES
54
+ # include "arch/bpstruct.h"
55
+ #endif
56
+ PACK_STRUCT_BEGIN
57
+ struct udp_hdr {
58
+ PACK_STRUCT_FIELD(u16_t src);
59
+ PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */
60
+ PACK_STRUCT_FIELD(u16_t len);
61
+ PACK_STRUCT_FIELD(u16_t chksum);
62
+ } PACK_STRUCT_STRUCT;
63
+ PACK_STRUCT_END
64
+ #ifdef PACK_STRUCT_USE_INCLUDES
65
+ # include "arch/epstruct.h"
66
+ #endif
67
+
68
+ #define UDP_FLAGS_NOCHKSUM 0x01U
69
+ #define UDP_FLAGS_UDPLITE 0x02U
70
+ #define UDP_FLAGS_CONNECTED 0x04U
71
+
72
+ struct udp_pcb {
73
+ /* Common members of all PCB types */
74
+ IP_PCB;
75
+
76
+ /* Protocol specific PCB members */
77
+
78
+ struct udp_pcb *next;
79
+
80
+ u8_t flags;
81
+ /* ports are in host byte order */
82
+ u16_t local_port, remote_port;
83
+
84
+ #if LWIP_IGMP
85
+ /* outgoing network interface for multicast packets */
86
+ struct ip_addr multicast_ip;
87
+ #endif /* LWIP_IGMP */
88
+
89
+ #if LWIP_UDPLITE
90
+ /* used for UDP_LITE only */
91
+ u16_t chksum_len_rx, chksum_len_tx;
92
+ #endif /* LWIP_UDPLITE */
93
+
94
+ /* receive callback function
95
+ * addr and port are in same byte order as in the pcb
96
+ * The callback is responsible for freeing the pbuf
97
+ * if it's not used any more.
98
+ *
99
+ * ATTENTION: Be aware that 'addr' points into the pbuf 'p' so freeing this pbuf
100
+ * makes 'addr' invalid, too.
101
+ *
102
+ * @param arg user supplied argument (udp_pcb.recv_arg)
103
+ * @param pcb the udp_pcb which received data
104
+ * @param p the packet buffer that was received
105
+ * @param addr the remote IP address from which the packet was received
106
+ * @param port the remote port from which the packet was received
107
+ */
108
+ void (* recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
109
+ struct ip_addr *addr, u16_t port);
110
+ /* user-supplied argument for the recv callback */
111
+ void *recv_arg;
112
+ };
113
+ /* udp_pcbs export for exernal reference (e.g. SNMP agent) */
114
+ extern struct udp_pcb *udp_pcbs;
115
+
116
+ /* The following functions is the application layer interface to the
117
+ UDP code. */
118
+ struct udp_pcb * udp_new (void);
119
+ void udp_remove (struct udp_pcb *pcb);
120
+ err_t udp_bind (struct udp_pcb *pcb, struct ip_addr *ipaddr,
121
+ u16_t port);
122
+ err_t udp_connect (struct udp_pcb *pcb, struct ip_addr *ipaddr,
123
+ u16_t port);
124
+ void udp_disconnect (struct udp_pcb *pcb);
125
+ void udp_recv (struct udp_pcb *pcb,
126
+ void (* recv)(void *arg, struct udp_pcb *upcb,
127
+ struct pbuf *p,
128
+ struct ip_addr *addr,
129
+ u16_t port),
130
+ void *recv_arg);
131
+ err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port, struct netif *netif);
132
+ err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port);
133
+ err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
134
+
135
+ #define udp_flags(pcb) ((pcb)->flags)
136
+ #define udp_setflags(pcb, f) ((pcb)->flags = (f))
137
+
138
+ /* The following functions are the lower layer interface to UDP. */
139
+ void udp_input (struct pbuf *p, struct netif *inp);
140
+
141
+ #define udp_init() /* Compatibility define, not init needed. */
142
+
143
+ #if UDP_DEBUG
144
+ void udp_debug_print(struct udp_hdr *udphdr);
145
+ #else
146
+ #define udp_debug_print(udphdr)
147
+ #endif
148
+
149
+ #ifdef __cplusplus
150
+ }
151
+ #endif
152
+
153
+ #endif /* LWIP_UDP */
154
+
155
+ #endif /* __LWIP_UDP_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/netif/etharp.h ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
5
+ * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
6
+ * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
7
+ * All rights reserved.
8
+ *
9
+ * Redistribution and use in source and binary forms, with or without modification,
10
+ * are permitted provided that the following conditions are met:
11
+ *
12
+ * 1. Redistributions of source code must retain the above copyright notice,
13
+ * this list of conditions and the following disclaimer.
14
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
15
+ * this list of conditions and the following disclaimer in the documentation
16
+ * and/or other materials provided with the distribution.
17
+ * 3. The name of the author may not be used to endorse or promote products
18
+ * derived from this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
23
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
25
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29
+ * OF SUCH DAMAGE.
30
+ *
31
+ * This file is part of the lwIP TCP/IP stack.
32
+ *
33
+ * Author: Adam Dunkels <adam@sics.se>
34
+ *
35
+ */
36
+
37
+ #ifndef __NETIF_ETHARP_H__
38
+ #define __NETIF_ETHARP_H__
39
+
40
+ #include "lwip/opt.h"
41
+
42
+ #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
43
+
44
+ #include "lwip/pbuf.h"
45
+ #include "lwip/ip_addr.h"
46
+ #include "lwip/netif.h"
47
+ #include "lwip/ip.h"
48
+
49
+ #ifdef __cplusplus
50
+ extern "C" {
51
+ #endif
52
+
53
+ #ifndef ETH_PAD_SIZE
54
+ #define ETH_PAD_SIZE 0
55
+ #endif
56
+
57
+ #ifndef ETHARP_HWADDR_LEN
58
+ #define ETHARP_HWADDR_LEN 6
59
+ #endif
60
+
61
+ #ifdef PACK_STRUCT_USE_INCLUDES
62
+ # include "arch/bpstruct.h"
63
+ #endif
64
+ PACK_STRUCT_BEGIN
65
+ struct eth_addr {
66
+ PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
67
+ } PACK_STRUCT_STRUCT;
68
+ PACK_STRUCT_END
69
+ #ifdef PACK_STRUCT_USE_INCLUDES
70
+ # include "arch/epstruct.h"
71
+ #endif
72
+
73
+ #ifdef PACK_STRUCT_USE_INCLUDES
74
+ # include "arch/bpstruct.h"
75
+ #endif
76
+ PACK_STRUCT_BEGIN
77
+ struct eth_hdr {
78
+ #if ETH_PAD_SIZE
79
+ PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
80
+ #endif
81
+ PACK_STRUCT_FIELD(struct eth_addr dest);
82
+ PACK_STRUCT_FIELD(struct eth_addr src);
83
+ PACK_STRUCT_FIELD(u16_t type);
84
+ } PACK_STRUCT_STRUCT;
85
+ PACK_STRUCT_END
86
+ #ifdef PACK_STRUCT_USE_INCLUDES
87
+ # include "arch/epstruct.h"
88
+ #endif
89
+
90
+ #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
91
+
92
+ #if ETHARP_SUPPORT_VLAN
93
+
94
+ #ifdef PACK_STRUCT_USE_INCLUDES
95
+ # include "arch/bpstruct.h"
96
+ #endif
97
+ PACK_STRUCT_BEGIN
98
+ struct eth_vlan_hdr {
99
+ PACK_STRUCT_FIELD(u16_t tpid);
100
+ PACK_STRUCT_FIELD(u16_t prio_vid);
101
+ } PACK_STRUCT_STRUCT;
102
+ PACK_STRUCT_END
103
+ #ifdef PACK_STRUCT_USE_INCLUDES
104
+ # include "arch/epstruct.h"
105
+ #endif
106
+
107
+ #define SIZEOF_VLAN_HDR 4
108
+ #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
109
+
110
+ #endif /* ETHARP_SUPPORT_VLAN */
111
+
112
+ #ifdef PACK_STRUCT_USE_INCLUDES
113
+ # include "arch/bpstruct.h"
114
+ #endif
115
+ PACK_STRUCT_BEGIN
116
+ /** the ARP message */
117
+ struct etharp_hdr {
118
+ PACK_STRUCT_FIELD(u16_t hwtype);
119
+ PACK_STRUCT_FIELD(u16_t proto);
120
+ PACK_STRUCT_FIELD(u16_t _hwlen_protolen);
121
+ PACK_STRUCT_FIELD(u16_t opcode);
122
+ PACK_STRUCT_FIELD(struct eth_addr shwaddr);
123
+ PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
124
+ PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
125
+ PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
126
+ } PACK_STRUCT_STRUCT;
127
+ PACK_STRUCT_END
128
+ #ifdef PACK_STRUCT_USE_INCLUDES
129
+ # include "arch/epstruct.h"
130
+ #endif
131
+
132
+ #define SIZEOF_ETHARP_HDR 28
133
+ #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
134
+
135
+ /** 5 seconds period */
136
+ #define ARP_TMR_INTERVAL 5000
137
+
138
+ #define ETHTYPE_ARP 0x0806
139
+ #define ETHTYPE_IP 0x0800
140
+ #define ETHTYPE_VLAN 0x8100
141
+ #define ETHTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
142
+ #define ETHTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
143
+
144
+ /** ARP message types (opcodes) */
145
+ #define ARP_REQUEST 1
146
+ #define ARP_REPLY 2
147
+
148
+ #if ARP_QUEUEING
149
+ /** struct for queueing outgoing packets for unknown address
150
+ * defined here to be accessed by memp.h
151
+ */
152
+ struct etharp_q_entry {
153
+ struct etharp_q_entry *next;
154
+ struct pbuf *p;
155
+ };
156
+ #endif /* ARP_QUEUEING */
157
+
158
+ #define etharp_init() /* Compatibility define, not init needed. */
159
+ void etharp_tmr(void);
160
+ s8_t etharp_find_addr(struct netif *netif, struct ip_addr *ipaddr,
161
+ struct eth_addr **eth_ret, struct ip_addr **ip_ret);
162
+ void etharp_ip_input(struct netif *netif, struct pbuf *p);
163
+ void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr,
164
+ struct pbuf *p);
165
+ err_t etharp_output(struct netif *netif, struct pbuf *q, struct ip_addr *ipaddr);
166
+ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q);
167
+ err_t etharp_request(struct netif *netif, struct ip_addr *ipaddr);
168
+ /** For Ethernet network interfaces, we might want to send "gratuitous ARP";
169
+ * this is an ARP packet sent by a node in order to spontaneously cause other
170
+ * nodes to update an entry in their ARP cache.
171
+ * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */
172
+ #define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr)
173
+
174
+ err_t ethernet_input(struct pbuf *p, struct netif *netif);
175
+
176
+ #if LWIP_AUTOIP
177
+ err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
178
+ const struct eth_addr *ethdst_addr,
179
+ const struct eth_addr *hwsrc_addr, const struct ip_addr *ipsrc_addr,
180
+ const struct eth_addr *hwdst_addr, const struct ip_addr *ipdst_addr,
181
+ const u16_t opcode);
182
+ #endif /* LWIP_AUTOIP */
183
+
184
+ #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
185
+
186
+ extern const struct eth_addr ethbroadcast, ethzero;
187
+
188
+ #ifdef __cplusplus
189
+ }
190
+ #endif
191
+
192
+ #endif /* LWIP_ARP */
193
+
194
+ #endif /* __NETIF_ARP_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/netif/loopif.h ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification,
8
+ * are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
+ * OF SUCH DAMAGE.
28
+ *
29
+ * This file is part of the lwIP TCP/IP stack.
30
+ *
31
+ * Author: Adam Dunkels <adam@sics.se>
32
+ *
33
+ */
34
+ #ifndef __NETIF_LOOPIF_H__
35
+ #define __NETIF_LOOPIF_H__
36
+
37
+ #include "lwip/opt.h"
38
+ #include "lwip/netif.h"
39
+ #include "lwip/err.h"
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
46
+ #define loopif_poll netif_poll
47
+ #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
48
+
49
+ err_t loopif_init(struct netif *netif);
50
+
51
+ #ifdef __cplusplus
52
+ }
53
+ #endif
54
+
55
+ #endif /* __NETIF_LOOPIF_H__ */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/netif/ppp_oe.h ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*****************************************************************************
4
+ * ppp_oe.h - PPP Over Ethernet implementation for lwIP.
5
+ *
6
+ * Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc.
7
+ *
8
+ * The authors hereby grant permission to use, copy, modify, distribute,
9
+ * and license this software and its documentation for any purpose, provided
10
+ * that existing copyright notices are retained in all copies and that this
11
+ * notice and the following disclaimer are included verbatim in any
12
+ * distributions. No written agreement, license, or royalty fee is required
13
+ * for any of the authorized uses.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
16
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
+ * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ *
26
+ ******************************************************************************
27
+ * REVISION HISTORY
28
+ *
29
+ * 06-01-01 Marc Boucher <marc@mbsi.ca>
30
+ * Ported to lwIP.
31
+ *****************************************************************************/
32
+
33
+
34
+
35
+ /* based on NetBSD: if_pppoe.c,v 1.64 2006/01/31 23:50:15 martin Exp */
36
+
37
+ /*-
38
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
39
+ * All rights reserved.
40
+ *
41
+ * This code is derived from software contributed to The NetBSD Foundation
42
+ * by Martin Husemann <martin@NetBSD.org>.
43
+ *
44
+ * Redistribution and use in source and binary forms, with or without
45
+ * modification, are permitted provided that the following conditions
46
+ * are met:
47
+ * 1. Redistributions of source code must retain the above copyright
48
+ * notice, this list of conditions and the following disclaimer.
49
+ * 2. Redistributions in binary form must reproduce the above copyright
50
+ * notice, this list of conditions and the following disclaimer in the
51
+ * documentation and/or other materials provided with the distribution.
52
+ * 3. All advertising materials mentioning features or use of this software
53
+ * must display the following acknowledgement:
54
+ * This product includes software developed by the NetBSD
55
+ * Foundation, Inc. and its contributors.
56
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
57
+ * contributors may be used to endorse or promote products derived
58
+ * from this software without specific prior written permission.
59
+ *
60
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
61
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
62
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
63
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
64
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
65
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
66
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
67
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
68
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
69
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
70
+ * POSSIBILITY OF SUCH DAMAGE.
71
+ */
72
+ #ifndef PPP_OE_H
73
+ #define PPP_OE_H
74
+
75
+ #include "lwip/opt.h"
76
+
77
+ #if PPPOE_SUPPORT > 0
78
+
79
+ #ifdef PACK_STRUCT_USE_INCLUDES
80
+ # include "arch/bpstruct.h"
81
+ #endif
82
+ PACK_STRUCT_BEGIN
83
+ struct pppoehdr {
84
+ PACK_STRUCT_FIELD(u8_t vertype);
85
+ PACK_STRUCT_FIELD(u8_t code);
86
+ PACK_STRUCT_FIELD(u16_t session);
87
+ PACK_STRUCT_FIELD(u16_t plen);
88
+ } PACK_STRUCT_STRUCT;
89
+ PACK_STRUCT_END
90
+ #ifdef PACK_STRUCT_USE_INCLUDES
91
+ # include "arch/epstruct.h"
92
+ #endif
93
+
94
+ #ifdef PACK_STRUCT_USE_INCLUDES
95
+ # include "arch/bpstruct.h"
96
+ #endif
97
+ PACK_STRUCT_BEGIN
98
+ struct pppoetag {
99
+ PACK_STRUCT_FIELD(u16_t tag);
100
+ PACK_STRUCT_FIELD(u16_t len);
101
+ } PACK_STRUCT_STRUCT;
102
+ PACK_STRUCT_END
103
+ #ifdef PACK_STRUCT_USE_INCLUDES
104
+ # include "arch/epstruct.h"
105
+ #endif
106
+
107
+
108
+ #define PPPOE_STATE_INITIAL 0
109
+ #define PPPOE_STATE_PADI_SENT 1
110
+ #define PPPOE_STATE_PADR_SENT 2
111
+ #define PPPOE_STATE_SESSION 3
112
+ #define PPPOE_STATE_CLOSING 4
113
+ /* passive */
114
+ #define PPPOE_STATE_PADO_SENT 1
115
+
116
+ #define PPPOE_HEADERLEN sizeof(struct pppoehdr)
117
+ #define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */
118
+
119
+ #define PPPOE_TAG_EOL 0x0000 /* end of list */
120
+ #define PPPOE_TAG_SNAME 0x0101 /* service name */
121
+ #define PPPOE_TAG_ACNAME 0x0102 /* access concentrator name */
122
+ #define PPPOE_TAG_HUNIQUE 0x0103 /* host unique */
123
+ #define PPPOE_TAG_ACCOOKIE 0x0104 /* AC cookie */
124
+ #define PPPOE_TAG_VENDOR 0x0105 /* vendor specific */
125
+ #define PPPOE_TAG_RELAYSID 0x0110 /* relay session id */
126
+ #define PPPOE_TAG_SNAME_ERR 0x0201 /* service name error */
127
+ #define PPPOE_TAG_ACSYS_ERR 0x0202 /* AC system error */
128
+ #define PPPOE_TAG_GENERIC_ERR 0x0203 /* gerneric error */
129
+
130
+ #define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */
131
+ #define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */
132
+ #define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */
133
+ #define PPPOE_CODE_PADS 0x65 /* Active Discovery Session confirmation */
134
+ #define PPPOE_CODE_PADT 0xA7 /* Active Discovery Terminate */
135
+
136
+ #ifndef ETHERMTU
137
+ #define ETHERMTU 1500
138
+ #endif
139
+
140
+ /* two byte PPP protocol discriminator, then IP data */
141
+ #define PPPOE_MAXMTU (ETHERMTU-PPPOE_HEADERLEN-2)
142
+
143
+ struct pppoe_softc;
144
+
145
+
146
+ void pppoe_init(void);
147
+
148
+ err_t pppoe_create(struct netif *ethif, int pd, void (*linkStatusCB)(int pd, int up), struct pppoe_softc **scptr);
149
+ err_t pppoe_destroy(struct netif *ifp);
150
+
151
+ int pppoe_connect(struct pppoe_softc *sc);
152
+ void pppoe_disconnect(struct pppoe_softc *sc);
153
+
154
+ void pppoe_disc_input(struct netif *netif, struct pbuf *p);
155
+ void pppoe_data_input(struct netif *netif, struct pbuf *p);
156
+
157
+ err_t pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb);
158
+
159
+ extern int pppoe_hdrlen;
160
+
161
+ #endif /* PPPOE_SUPPORT */
162
+
163
+ #endif /* PPP_OE_H */
hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/netif/slipif.h ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
+
3
+ /*
4
+ * Copyright (c) 2001, Swedish Institute of Computer Science.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions
9
+ * are met:
10
+ * 1. Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright
13
+ * notice, this list of conditions and the following disclaimer in the
14
+ * documentation and/or other materials provided with the distribution.
15
+ * 3. Neither the name of the Institute nor the names of its contributors
16
+ * may be used to endorse or promote products derived from this software
17
+ * without specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
20
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
23
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
+ * SUCH DAMAGE.
30
+ *
31
+ * This file is part of the lwIP TCP/IP stack.
32
+ *
33
+ * Author: Adam Dunkels <adam@sics.se>
34
+ *
35
+ */
36
+ #ifndef __NETIF_SLIPIF_H__
37
+ #define __NETIF_SLIPIF_H__
38
+
39
+ #include "lwip/netif.h"
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ err_t slipif_init(struct netif * netif);
46
+ void slipif_poll(struct netif *netif);
47
+
48
+ #ifdef __cplusplus
49
+ }
50
+ #endif
51
+
52
+ #endif
53
+