aboutsummaryrefslogtreecommitdiff
path: root/lib/lufa/Projects/Webserver/Lib/uip
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2019-08-02 14:02:40 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitcf4575b94a3c65e6535a159fc71fc885aebc2620 (patch)
tree2354f2b7a200e02246a564afefedc32357e62b8e /lib/lufa/Projects/Webserver/Lib/uip
parent75ee8df19e0f14ba466f41ab673dde2fe2fdae9c (diff)
downloadqmk_firmware-cf4575b94a3c65e6535a159fc71fc885aebc2620.tar.gz
qmk_firmware-cf4575b94a3c65e6535a159fc71fc885aebc2620.zip
Fix the LUFA lib to use a submodule instead of just files (#6245)
* Remove LUFA files * Update descriptions for newer version of LUFA * Create PR6245.md * Fix CDC(Serial) type errors * Fix missed merge conflict for AUDIO_DTYPE_CSInterface
Diffstat (limited to 'lib/lufa/Projects/Webserver/Lib/uip')
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/clock.c37
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/clock.h13
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/timer.c128
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/timer.h87
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/uip-split.c151
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/uip-split.h104
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/uip.c1941
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/uip.h2130
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/uip_arp.c432
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/uip_arp.h146
-rw-r--r--lib/lufa/Projects/Webserver/Lib/uip/uipopt.h740
11 files changed, 0 insertions, 5909 deletions
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/clock.c b/lib/lufa/Projects/Webserver/Lib/uip/clock.c
deleted file mode 100644
index e71f7209d..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/clock.c
+++ /dev/null
@@ -1,37 +0,0 @@
1#include <stdint.h>
2#include <stdlib.h>
3#include <stdio.h>
4
5#include <LUFA/Common/Common.h>
6
7#include "clock.h"
8
9//Counted time
10volatile clock_time_t clock_datetime = 0;
11
12//Overflow interrupt
13ISR(TIMER1_COMPA_vect, ISR_BLOCK)
14{
15 clock_datetime += 1;
16}
17
18//Initialise the clock
19void clock_init()
20{
21 OCR1A = (((F_CPU / 1024) / 100) - 1);
22 TCCR1B = ((1 << WGM12) | (1 << CS12) | (1 << CS10));
23 TIMSK1 = (1 << OCIE1A);
24}
25
26//Return time
27clock_time_t clock_time()
28{
29 clock_time_t time;
30
31 GlobalInterruptDisable();
32 time = clock_datetime;
33 GlobalInterruptEnable();
34
35 return time;
36}
37
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/clock.h b/lib/lufa/Projects/Webserver/Lib/uip/clock.h
deleted file mode 100644
index bbfa4ac0e..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/clock.h
+++ /dev/null
@@ -1,13 +0,0 @@
1#ifndef __CLOCK_ARCH_H__
2#define __CLOCK_ARCH_H__
3
4#include <stdint.h>
5#include <util/atomic.h>
6
7typedef uint16_t clock_time_t;
8#define CLOCK_SECOND 100
9void clock_init(void);
10clock_time_t clock_time(void);
11
12#endif /* __CLOCK_ARCH_H__ */
13
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/timer.c b/lib/lufa/Projects/Webserver/Lib/uip/timer.c
deleted file mode 100644
index eae06f43b..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/timer.c
+++ /dev/null
@@ -1,128 +0,0 @@
1/**
2 * \addtogroup timer
3 * @{
4 */
5
6/**
7 * \file
8 * Timer library implementation.
9 * \author
10 * Adam Dunkels <adam@sics.se>
11 */
12
13/*
14 * Copyright (c) 2004, Swedish Institute of Computer Science.
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. Neither the name of the Institute nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * This file is part of the uIP TCP/IP stack
42 *
43 * Author: Adam Dunkels <adam@sics.se>
44 *
45 * $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $
46 */
47
48#include "clock.h"
49#include "timer.h"
50
51/*---------------------------------------------------------------------------*/
52/**
53 * Set a timer.
54 *
55 * This function is used to set a timer for a time sometime in the
56 * future. The function timer_expired() will evaluate to true after
57 * the timer has expired.
58 *
59 * \param t A pointer to the timer
60 * \param interval The interval before the timer expires.
61 *
62 */
63void
64timer_set(struct timer *t, clock_time_t interval)
65{
66 t->interval = interval;
67 t->start = clock_time();
68}
69/*---------------------------------------------------------------------------*/
70/**
71 * Reset the timer with the same interval.
72 *
73 * This function resets the timer with the same interval that was
74 * given to the timer_set() function. The start point of the interval
75 * is the exact time that the timer last expired. Therefore, this
76 * function will cause the timer to be stable over time, unlike the
77 * timer_restart() function.
78 *
79 * \param t A pointer to the timer.
80 *
81 * \sa timer_restart()
82 */
83void
84timer_reset(struct timer *t)
85{
86 t->start += t->interval;
87}
88/*---------------------------------------------------------------------------*/
89/**
90 * Restart the timer from the current point in time
91 *
92 * This function restarts a timer with the same interval that was
93 * given to the timer_set() function. The timer will start at the
94 * current time.
95 *
96 * \note A periodic timer will drift if this function is used to reset
97 * it. For periodic timers, use the timer_reset() function instead.
98 *
99 * \param t A pointer to the timer.
100 *
101 * \sa timer_reset()
102 */
103void
104timer_restart(struct timer *t)
105{
106 t->start = clock_time();
107}
108/*---------------------------------------------------------------------------*/
109/**
110 * Check if a timer has expired.
111 *
112 * This function tests if a timer has expired and returns true or
113 * false depending on its status.
114 *
115 * \param t A pointer to the timer
116 *
117 * \return Non-zero if the timer has expired, zero otherwise.
118 *
119 */
120int
121timer_expired(struct timer *t)
122{
123 return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval;
124}
125/*---------------------------------------------------------------------------*/
126
127/** @} */
128
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/timer.h b/lib/lufa/Projects/Webserver/Lib/uip/timer.h
deleted file mode 100644
index 04917e4c5..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/timer.h
+++ /dev/null
@@ -1,87 +0,0 @@
1/**
2 * \defgroup timer Timer library
3 *
4 * The timer library provides functions for setting, resetting and
5 * restarting timers, and for checking if a timer has expired. An
6 * application must "manually" check if its timers have expired; this
7 * is not done automatically.
8 *
9 * A timer is declared as a \c struct \c timer and all access to the
10 * timer is made by a pointer to the declared timer.
11 *
12 * \note The timer library uses the \ref clock "Clock library" to
13 * measure time. Intervals should be specified in the format used by
14 * the clock library.
15 *
16 * @{
17 */
18
19
20/**
21 * \file
22 * Timer library header file.
23 * \author
24 * Adam Dunkels <adam@sics.se>
25 */
26
27/*
28 * Copyright (c) 2004, Swedish Institute of Computer Science.
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. Neither the name of the Institute nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * This file is part of the uIP TCP/IP stack
56 *
57 * Author: Adam Dunkels <adam@sics.se>
58 *
59 * $Id: timer.h,v 1.3 2006/06/11 21:46:39 adam Exp $
60 */
61#ifndef __TIMER_H__
62#define __TIMER_H__
63
64#include "clock.h"
65
66/**
67 * A timer.
68 *
69 * This structure is used for declaring a timer. The timer must be set
70 * with timer_set() before it can be used.
71 *
72 * \hideinitializer
73 */
74struct timer {
75 clock_time_t start;
76 clock_time_t interval;
77};
78
79void timer_set(struct timer *t, clock_time_t interval);
80void timer_reset(struct timer *t);
81void timer_restart(struct timer *t);
82int timer_expired(struct timer *t);
83
84#endif /* __TIMER_H__ */
85
86/** @} */
87
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/uip-split.c b/lib/lufa/Projects/Webserver/Lib/uip/uip-split.c
deleted file mode 100644
index 5222a05b6..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/uip-split.c
+++ /dev/null
@@ -1,151 +0,0 @@
1/*
2 * Copyright (c) 2004, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 * Author: Adam Dunkels <adam@sics.se>
32 *
33 * $Id: uip-split.c,v 1.2 2008/10/14 13:39:12 julienabeille Exp $
34 */
35
36#include "uip-split.h"
37
38
39#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
40
41/*-----------------------------------------------------------------------------*/
42void
43uip_split_output(void)
44{
45#if UIP_TCP
46 u16_t tcplen, len1, len2;
47
48 /* We only try to split maximum sized TCP segments. */
49 if(BUF->proto == UIP_PROTO_TCP && uip_len == UIP_BUFSIZE) {
50
51 tcplen = uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN;
52 /* Split the segment in two. If the original packet length was
53 odd, we make the second packet one byte larger. */
54 len1 = len2 = tcplen / 2;
55 if(len1 + len2 < tcplen) {
56 ++len2;
57 }
58
59 /* Create the first packet. This is done by altering the length
60 field of the IP header and updating the checksums. */
61 uip_len = len1 + UIP_TCPIP_HLEN + UIP_LLH_LEN;
62#if UIP_CONF_IPV6
63 /* For IPv6, the IP length field does not include the IPv6 IP header
64 length. */
65 BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
66 BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
67#else /* UIP_CONF_IPV6 */
68 BUF->len[0] = (uip_len - UIP_LLH_LEN) >> 8;
69 BUF->len[1] = (uip_len - UIP_LLH_LEN) & 0xff;
70#endif /* UIP_CONF_IPV6 */
71
72 /* Recalculate the TCP checksum. */
73 BUF->tcpchksum = 0;
74 BUF->tcpchksum = ~(uip_tcpchksum());
75
76#if !UIP_CONF_IPV6
77 /* Recalculate the IP checksum. */
78 BUF->ipchksum = 0;
79 BUF->ipchksum = ~(uip_ipchksum());
80#endif /* UIP_CONF_IPV6 */
81
82 /* Transmit the first packet. */
83#if UIP_CONF_IPV6
84 tcpip_ipv6_output();
85#else
86 if (USB_CurrentMode == USB_MODE_Device)
87 RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface_Device, uip_buf, uip_len);
88 else
89 RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface_Host, uip_buf, uip_len);
90#endif /* UIP_CONF_IPV6 */
91
92 /* Now, create the second packet. To do this, it is not enough to
93 just alter the length field, but we must also update the TCP
94 sequence number and point the uip_appdata to a new place in
95 memory. This place is determined by the length of the first
96 packet (len1). */
97 uip_len = len2 + UIP_TCPIP_HLEN + UIP_LLH_LEN;
98#if UIP_CONF_IPV6
99 /* For IPv6, the IP length field does not include the IPv6 IP header
100 length. */
101 BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
102 BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
103#else /* UIP_CONF_IPV6 */
104 BUF->len[0] = (uip_len - UIP_LLH_LEN) >> 8;
105 BUF->len[1] = (uip_len - UIP_LLH_LEN) & 0xff;
106#endif /* UIP_CONF_IPV6 */
107
108 memcpy(uip_appdata, (u8_t *)uip_appdata + len1, len2);
109
110 uip_add32(BUF->seqno, len1);
111 BUF->seqno[0] = uip_acc32[0];
112 BUF->seqno[1] = uip_acc32[1];
113 BUF->seqno[2] = uip_acc32[2];
114 BUF->seqno[3] = uip_acc32[3];
115
116 /* Recalculate the TCP checksum. */
117 BUF->tcpchksum = 0;
118 BUF->tcpchksum = ~(uip_tcpchksum());
119
120#if !UIP_CONF_IPV6
121 /* Recalculate the IP checksum. */
122 BUF->ipchksum = 0;
123 BUF->ipchksum = ~(uip_ipchksum());
124#endif /* UIP_CONF_IPV6 */
125
126 /* Transmit the second packet. */
127#if UIP_CONF_IPV6
128 tcpip_ipv6_output();
129#else
130 if (USB_CurrentMode == USB_MODE_Device)
131 RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface_Device, uip_buf, uip_len);
132 else
133 RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface_Host, uip_buf, uip_len);
134#endif /* UIP_CONF_IPV6 */
135 return;
136 }
137#endif /* UIP_TCP */
138
139 /* uip_fw_output();*/
140#if UIP_CONF_IPV6
141 tcpip_ipv6_output();
142#else
143 if (USB_CurrentMode == USB_MODE_Device)
144 RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface_Device, uip_buf, uip_len);
145 else
146 RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface_Host, uip_buf, uip_len);
147#endif /* UIP_CONF_IPV6 */
148}
149
150/*-----------------------------------------------------------------------------*/
151
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/uip-split.h b/lib/lufa/Projects/Webserver/Lib/uip/uip-split.h
deleted file mode 100644
index 0c768ce40..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/uip-split.h
+++ /dev/null
@@ -1,104 +0,0 @@
1/*
2 * Copyright (c) 2004, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 * Author: Adam Dunkels <adam@sics.se>
32 *
33 * $Id: uip-split.h,v 1.1 2006/06/17 22:41:19 adamdunkels Exp $
34 */
35/**
36 * \addtogroup uip
37 * @{
38 */
39
40/**
41 * \defgroup uipsplit uIP TCP throughput booster hack
42 * @{
43 *
44 * The basic uIP TCP implementation only allows each TCP connection to
45 * have a single TCP segment in flight at any given time. Because of
46 * the delayed ACK algorithm employed by most TCP receivers, uIP's
47 * limit on the amount of in-flight TCP segments seriously reduces the
48 * maximum achievable throughput for sending data from uIP.
49 *
50 * The uip-split module is a hack which tries to remedy this
51 * situation. By splitting maximum sized outgoing TCP segments into
52 * two, the delayed ACK algorithm is not invoked at TCP
53 * receivers. This improves the throughput when sending data from uIP
54 * by orders of magnitude.
55 *
56 * The uip-split module uses the uip-fw module (uIP IP packet
57 * forwarding) for sending packets. Therefore, the uip-fw module must
58 * be set up with the appropriate network interfaces for this module
59 * to work.
60 */
61
62
63/**
64 * \file
65 * Module for splitting outbound TCP segments in two to avoid the
66 * delayed ACK throughput degradation.
67 * \author
68 * Adam Dunkels <adam@sics.se>
69 *
70 */
71
72#ifndef __UIP_SPLIT_H__
73#define __UIP_SPLIT_H__
74
75#include <string.h>
76#include <uip.h>
77
78#include "../../USBHostMode.h"
79
80#include <LUFA/Drivers/USB/USB.h>
81
82/**
83 * Handle outgoing packets.
84 *
85 * This function inspects an outgoing packet in the uip_buf buffer and
86 * sends it out using the uip_fw_output() function. If the packet is a
87 * full-sized TCP segment it will be split into two segments and
88 * transmitted separately. This function should be called instead of
89 * the actual device driver output function, or the uip_fw_output()
90 * function.
91 *
92 * The headers of the outgoing packet is assumed to be in the uip_buf
93 * buffer and the payload is assumed to be wherever uip_appdata
94 * points. The length of the outgoing packet is assumed to be in the
95 * uip_len variable.
96 *
97 */
98void uip_split_output(void);
99void uip_add32(u8_t *op32, u16_t op16);
100#endif /* __UIP_SPLIT_H__ */
101
102/** @} */
103/** @} */
104
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/uip.c b/lib/lufa/Projects/Webserver/Lib/uip/uip.c
deleted file mode 100644
index fead75775..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/uip.c
+++ /dev/null
@@ -1,1941 +0,0 @@
1#define DEBUG_PRINTF(...) /*printf(__VA_ARGS__)*/
2
3/**
4 * \addtogroup uip
5 * @{
6 */
7
8/**
9 * \file
10 * The uIP TCP/IP stack code.
11 * \author Adam Dunkels <adam@dunkels.com>
12 */
13
14/*
15 * Copyright (c) 2001-2003, Adam Dunkels.
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. The name of the author may not be used to endorse or promote
27 * products derived from this software without specific prior
28 * written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
31 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
34 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
36 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * This file is part of the uIP TCP/IP stack.
43 *
44 * $Id: uip.c,v 1.15 2008/10/15 08:08:32 adamdunkels Exp $
45 *
46 */
47
48/*
49 * uIP is a small implementation of the IP, UDP and TCP protocols (as
50 * well as some basic ICMP stuff). The implementation couples the IP,
51 * UDP, TCP and the application layers very tightly. To keep the size
52 * of the compiled code down, this code frequently uses the goto
53 * statement. While it would be possible to break the uip_process()
54 * function into many smaller functions, this would increase the code
55 * size because of the overhead of parameter passing and the fact that
56 * the optimizer would not be as efficient.
57 *
58 * The principle is that we have a small buffer, called the uip_buf,
59 * in which the device driver puts an incoming packet. The TCP/IP
60 * stack parses the headers in the packet, and calls the
61 * application. If the remote host has sent data to the application,
62 * this data is present in the uip_buf and the application read the
63 * data from there. It is up to the application to put this data into
64 * a byte stream if needed. The application will not be fed with data
65 * that is out of sequence.
66 *
67 * If the application whishes to send data to the peer, it should put
68 * its data into the uip_buf. The uip_appdata pointer points to the
69 * first available byte. The TCP/IP stack will calculate the
70 * checksums, and fill in the necessary header fields and finally send
71 * the packet back to the peer.
72*/
73
74#include "uip.h"
75#include "uipopt.h"
76#include "uip_arp.h"
77
78#if !UIP_CONF_IPV6 /* If UIP_CONF_IPV6 is defined, we compile the
79 uip6.c file instead of this one. Therefore
80 this #ifndef removes the entire compilation
81 output of the uip.c file */
82
83
84#if UIP_CONF_IPV6
85#include "net/uip-neighbor.h"
86#endif /* UIP_CONF_IPV6 */
87
88#include <string.h>
89
90/*---------------------------------------------------------------------------*/
91/* Variable definitions. */
92
93
94/* The IP address of this host. If it is defined to be fixed (by
95 setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set
96 here. Otherwise, the address */
97#if UIP_FIXEDADDR > 0
98const uip_ipaddr_t uip_hostaddr =
99 { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };
100const uip_ipaddr_t uip_draddr =
101 { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };
102const uip_ipaddr_t uip_netmask =
103 { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };
104#else
105uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
106#endif /* UIP_FIXEDADDR */
107
108const uip_ipaddr_t uip_broadcast_addr =
109#if UIP_CONF_IPV6
110 { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
111 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
112#else /* UIP_CONF_IPV6 */
113 { { 0xff, 0xff, 0xff, 0xff } };
114#endif /* UIP_CONF_IPV6 */
115const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };
116
117#if UIP_FIXEDETHADDR
118const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
119 UIP_ETHADDR1,
120 UIP_ETHADDR2,
121 UIP_ETHADDR3,
122 UIP_ETHADDR4,
123 UIP_ETHADDR5}};
124#else
125struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
126#endif
127
128#ifndef UIP_CONF_EXTERNAL_BUFFER
129u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains
130 incoming packets. */
131#endif /* UIP_CONF_EXTERNAL_BUFFER */
132
133void *uip_appdata; /* The uip_appdata pointer points to
134 application data. */
135void *uip_sappdata; /* The uip_appdata pointer points to
136 the application data which is to
137 be sent. */
138#if UIP_URGDATA > 0
139void *uip_urgdata; /* The uip_urgdata pointer points to
140 urgent data (out-of-band data), if
141 present. */
142u16_t uip_urglen, uip_surglen;
143#endif /* UIP_URGDATA > 0 */
144
145u16_t uip_len, uip_slen;
146 /* The uip_len is either 8 or 16 bits,
147 depending on the maximum packet
148 size. */
149
150u8_t uip_flags; /* The uip_flags variable is used for
151 communication between the TCP/IP stack
152 and the application program. */
153struct uip_conn *uip_conn; /* uip_conn always points to the current
154 connection. */
155
156struct uip_conn uip_conns[UIP_CONNS];
157 /* The uip_conns array holds all TCP
158 connections. */
159u16_t uip_listenports[UIP_LISTENPORTS];
160 /* The uip_listenports list all currently
161 listening ports. */
162#if UIP_UDP
163struct uip_udp_conn *uip_udp_conn;
164struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
165#endif /* UIP_UDP */
166
167static u16_t ipid; /* Ths ipid variable is an increasing
168 number that is used for the IP ID
169 field. */
170
171void uip_setipid(u16_t id) { ipid = id; }
172
173static u8_t iss[4]; /* The iss variable is used for the TCP
174 initial sequence number. */
175
176#if UIP_ACTIVE_OPEN
177static u16_t lastport; /* Keeps track of the last port used for
178 a new connection. */
179#endif /* UIP_ACTIVE_OPEN */
180
181/* Temporary variables. */
182u8_t uip_acc32[4];
183static u8_t c, opt;
184static u16_t tmp16;
185
186/* Structures and definitions. */
187#define TCP_FIN 0x01
188#define TCP_SYN 0x02
189#define TCP_RST 0x04
190#define TCP_PSH 0x08
191#define TCP_ACK 0x10
192#define TCP_URG 0x20
193#define TCP_CTL 0x3f
194
195#define TCP_OPT_END 0 /* End of TCP options list */
196#define TCP_OPT_NOOP 1 /* "No-operation" TCP option */
197#define TCP_OPT_MSS 2 /* Maximum segment size TCP option */
198
199#define TCP_OPT_MSS_LEN 4 /* Length of TCP MSS option. */
200
201#define ICMP_ECHO_REPLY 0
202#define ICMP_ECHO 8
203
204#define ICMP_DEST_UNREACHABLE 3
205#define ICMP_PORT_UNREACHABLE 3
206
207#define ICMP6_ECHO_REPLY 129
208#define ICMP6_ECHO 128
209#define ICMP6_NEIGHBOR_SOLICITATION 135
210#define ICMP6_NEIGHBOR_ADVERTISEMENT 136
211
212#define ICMP6_FLAG_S (1 << 6)
213
214#define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1
215#define ICMP6_OPTION_TARGET_LINK_ADDRESS 2
216
217
218/* Macros. */
219#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
220#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])
221#define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
222#define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
223
224
225#if UIP_STATISTICS == 1
226struct uip_stats uip_stat;
227#define UIP_STAT(s) s
228#else
229#define UIP_STAT(s)
230#endif /* UIP_STATISTICS == 1 */
231
232#if UIP_LOGGING == 1
233#include <stdio.h>
234void uip_log(char *msg);
235#define UIP_LOG(m) uip_log(m)
236#else
237#define UIP_LOG(m)
238#endif /* UIP_LOGGING == 1 */
239
240#if ! UIP_ARCH_ADD32
241void
242uip_add32(u8_t *op32, u16_t op16)
243{
244 uip_acc32[3] = op32[3] + (op16 & 0xff);
245 uip_acc32[2] = op32[2] + (op16 >> 8);
246 uip_acc32[1] = op32[1];
247 uip_acc32[0] = op32[0];
248
249 if(uip_acc32[2] < (op16 >> 8)) {
250 ++uip_acc32[1];
251 if(uip_acc32[1] == 0) {
252 ++uip_acc32[0];
253 }
254 }
255
256
257 if(uip_acc32[3] < (op16 & 0xff)) {
258 ++uip_acc32[2];
259 if(uip_acc32[2] == 0) {
260 ++uip_acc32[1];
261 if(uip_acc32[1] == 0) {
262 ++uip_acc32[0];
263 }
264 }
265 }
266}
267
268#endif /* UIP_ARCH_ADD32 */
269
270#if ! UIP_ARCH_CHKSUM
271/*---------------------------------------------------------------------------*/
272static u16_t
273chksum(u16_t sum, const u8_t *data, u16_t len)
274{
275 u16_t t;
276 const u8_t *dataptr;
277 const u8_t *last_byte;
278
279 dataptr = data;
280 last_byte = data + len - 1;
281
282 while(dataptr < last_byte) { /* At least two more bytes */
283 t = (dataptr[0] << 8) + dataptr[1];
284 sum += t;
285 if(sum < t) {
286 sum++; /* carry */
287 }
288 dataptr += 2;
289 }
290
291 if(dataptr == last_byte) {
292 t = (dataptr[0] << 8) + 0;
293 sum += t;
294 if(sum < t) {
295 sum++; /* carry */
296 }
297 }
298
299 /* Return sum in host byte order. */
300 return sum;
301}
302/*---------------------------------------------------------------------------*/
303u16_t
304uip_chksum(u16_t *data, u16_t len)
305{
306 return htons(chksum(0, (u8_t *)data, len));
307}
308/*---------------------------------------------------------------------------*/
309#ifndef UIP_ARCH_IPCHKSUM
310u16_t
311uip_ipchksum(void)
312{
313 u16_t sum;
314
315 sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);
316 DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum);
317 return (sum == 0) ? 0xffff : htons(sum);
318}
319#endif
320/*---------------------------------------------------------------------------*/
321static u16_t
322upper_layer_chksum(u8_t proto)
323{
324 u16_t upper_layer_len;
325 u16_t sum;
326
327#if UIP_CONF_IPV6
328 upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]);
329#else /* UIP_CONF_IPV6 */
330 upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;
331#endif /* UIP_CONF_IPV6 */
332
333 /* First sum pseudo-header. */
334
335 /* IP protocol and length fields. This addition cannot carry. */
336 sum = upper_layer_len + proto;
337 /* Sum IP source and destination addresses. */
338 sum = chksum(sum, (u8_t *)&BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));
339
340 /* Sum TCP header and data. */
341 sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
342 upper_layer_len);
343
344 return (sum == 0) ? 0xffff : htons(sum);
345}
346/*---------------------------------------------------------------------------*/
347#if UIP_CONF_IPV6
348u16_t
349uip_icmp6chksum(void)
350{
351 return upper_layer_chksum(UIP_PROTO_ICMP6);
352
353}
354#endif /* UIP_CONF_IPV6 */
355/*---------------------------------------------------------------------------*/
356u16_t
357uip_tcpchksum(void)
358{
359 return upper_layer_chksum(UIP_PROTO_TCP);
360}
361/*---------------------------------------------------------------------------*/
362#if UIP_UDP_CHECKSUMS
363u16_t
364uip_udpchksum(void)
365{
366 return upper_layer_chksum(UIP_PROTO_UDP);
367}
368#endif /* UIP_UDP_CHECKSUMS */
369#endif /* UIP_ARCH_CHKSUM */
370/*---------------------------------------------------------------------------*/
371void
372uip_init(void)
373{
374 for(c = 0; c < UIP_LISTENPORTS; ++c) {
375 uip_listenports[c] = 0;
376 }
377 for(c = 0; c < UIP_CONNS; ++c) {
378 uip_conns[c].tcpstateflags = UIP_CLOSED;
379 }
380#if UIP_ACTIVE_OPEN
381 lastport = 1024;
382#endif /* UIP_ACTIVE_OPEN */
383
384#if UIP_UDP
385 for(c = 0; c < UIP_UDP_CONNS; ++c) {
386 uip_udp_conns[c].lport = 0;
387 }
388#endif /* UIP_UDP */
389
390
391 /* IPv4 initialization. */
392#if UIP_FIXEDADDR == 0
393 /* uip_hostaddr[0] = uip_hostaddr[1] = 0;*/
394#endif /* UIP_FIXEDADDR */
395
396}
397/*---------------------------------------------------------------------------*/
398#if UIP_ACTIVE_OPEN
399struct uip_conn *
400uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
401{
402 register struct uip_conn *conn, *cconn;
403
404 /* Find an unused local port. */
405 again:
406 ++lastport;
407
408 if(lastport >= 32000) {
409 lastport = 4096;
410 }
411
412 /* Check if this port is already in use, and if so try to find
413 another one. */
414 for(c = 0; c < UIP_CONNS; ++c) {
415 conn = &uip_conns[c];
416 if(conn->tcpstateflags != UIP_CLOSED &&
417 conn->lport == htons(lastport)) {
418 goto again;
419 }
420 }
421
422 conn = 0;
423 for(c = 0; c < UIP_CONNS; ++c) {
424 cconn = &uip_conns[c];
425 if(cconn->tcpstateflags == UIP_CLOSED) {
426 conn = cconn;
427 break;
428 }
429 if(cconn->tcpstateflags == UIP_TIME_WAIT) {
430 if(conn == 0 ||
431 cconn->timer > conn->timer) {
432 conn = cconn;
433 }
434 }
435 }
436
437 if(conn == 0) {
438 return 0;
439 }
440
441 conn->tcpstateflags = UIP_SYN_SENT;
442
443 conn->snd_nxt[0] = iss[0];
444 conn->snd_nxt[1] = iss[1];
445 conn->snd_nxt[2] = iss[2];
446 conn->snd_nxt[3] = iss[3];
447
448 conn->initialmss = conn->mss = UIP_TCP_MSS;
449
450 conn->len = 1; /* TCP length of the SYN is one. */
451 conn->nrtx = 0;
452 conn->timer = 1; /* Send the SYN next time around. */
453 conn->rto = UIP_RTO;
454 conn->sa = 0;
455 conn->sv = 16; /* Initial value of the RTT variance. */
456 conn->lport = htons(lastport);
457 conn->rport = rport;
458 uip_ipaddr_copy(&conn->ripaddr, ripaddr);
459
460 return conn;
461}
462#endif /* UIP_ACTIVE_OPEN */
463/*---------------------------------------------------------------------------*/
464#if UIP_UDP
465struct uip_udp_conn *
466uip_udp_new(const uip_ipaddr_t *ripaddr, u16_t rport)
467{
468 register struct uip_udp_conn *conn;
469
470 /* Find an unused local port. */
471 again:
472 ++lastport;
473
474 if(lastport >= 32000) {
475 lastport = 4096;
476 }
477
478 for(c = 0; c < UIP_UDP_CONNS; ++c) {
479 if(uip_udp_conns[c].lport == htons(lastport)) {
480 goto again;
481 }
482 }
483
484
485 conn = 0;
486 for(c = 0; c < UIP_UDP_CONNS; ++c) {
487 if(uip_udp_conns[c].lport == 0) {
488 conn = &uip_udp_conns[c];
489 break;
490 }
491 }
492
493 if(conn == 0) {
494 return 0;
495 }
496
497 conn->lport = HTONS(lastport);
498 conn->rport = rport;
499 if(ripaddr == NULL) {
500 memset(&conn->ripaddr, 0, sizeof(uip_ipaddr_t));
501 } else {
502 uip_ipaddr_copy(&conn->ripaddr, ripaddr);
503 }
504 conn->ttl = UIP_TTL;
505
506 return conn;
507}
508#endif /* UIP_UDP */
509/*---------------------------------------------------------------------------*/
510void
511uip_unlisten(u16_t port)
512{
513 for(c = 0; c < UIP_LISTENPORTS; ++c) {
514 if(uip_listenports[c] == port) {
515 uip_listenports[c] = 0;
516 return;
517 }
518 }
519}
520/*---------------------------------------------------------------------------*/
521void
522uip_listen(u16_t port)
523{
524 for(c = 0; c < UIP_LISTENPORTS; ++c) {
525 if(uip_listenports[c] == 0) {
526 uip_listenports[c] = port;
527 return;
528 }
529 }
530}
531/*---------------------------------------------------------------------------*/
532/* XXX: IP fragment reassembly: not well-tested. */
533
534#if UIP_REASSEMBLY && !UIP_CONF_IPV6
535#define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)
536static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];
537static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
538static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
539 0x0f, 0x07, 0x03, 0x01};
540static u16_t uip_reasslen;
541static u8_t uip_reassflags;
542#define UIP_REASS_FLAG_LASTFRAG 0x01
543static u8_t uip_reasstmr;
544
545#define IP_MF 0x20
546
547static u8_t
548uip_reass(void)
549{
550 u16_t offset, len;
551 u16_t i;
552
553 /* If ip_reasstmr is zero, no packet is present in the buffer, so we
554 write the IP header of the fragment into the reassembly
555 buffer. The timer is updated with the maximum age. */
556 if(uip_reasstmr == 0) {
557 memcpy(uip_reassbuf, &BUF->vhl, UIP_IPH_LEN);
558 uip_reasstmr = UIP_REASS_MAXAGE;
559 uip_reassflags = 0;
560 /* Clear the bitmap. */
561 memset(uip_reassbitmap, 0, sizeof(uip_reassbitmap));
562 }
563
564 /* Check if the incoming fragment matches the one currently present
565 in the reasembly buffer. If so, we proceed with copying the
566 fragment into the buffer. */
567 if(BUF->srcipaddr[0] == FBUF->srcipaddr[0] &&
568 BUF->srcipaddr[1] == FBUF->srcipaddr[1] &&
569 BUF->destipaddr[0] == FBUF->destipaddr[0] &&
570 BUF->destipaddr[1] == FBUF->destipaddr[1] &&
571 BUF->ipid[0] == FBUF->ipid[0] &&
572 BUF->ipid[1] == FBUF->ipid[1]) {
573
574 len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4;
575 offset = (((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1]) * 8;
576
577 /* If the offset or the offset + fragment length overflows the
578 reassembly buffer, we discard the entire packet. */
579 if(offset > UIP_REASS_BUFSIZE ||
580 offset + len > UIP_REASS_BUFSIZE) {
581 uip_reasstmr = 0;
582 goto nullreturn;
583 }
584
585 /* Copy the fragment into the reassembly buffer, at the right
586 offset. */
587 memcpy(&uip_reassbuf[UIP_IPH_LEN + offset],
588 (char *)BUF + (int)((BUF->vhl & 0x0f) * 4),
589 len);
590
591 /* Update the bitmap. */
592 if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
593 /* If the two endpoints are in the same byte, we only update
594 that byte. */
595
596 uip_reassbitmap[offset / (8 * 8)] |=
597 bitmap_bits[(offset / 8 ) & 7] &
598 ~bitmap_bits[((offset + len) / 8 ) & 7];
599 } else {
600 /* If the two endpoints are in different bytes, we update the
601 bytes in the endpoints and fill the stuff in-between with
602 0xff. */
603 uip_reassbitmap[offset / (8 * 8)] |=
604 bitmap_bits[(offset / 8 ) & 7];
605 for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
606 uip_reassbitmap[i] = 0xff;
607 }
608 uip_reassbitmap[(offset + len) / (8 * 8)] |=
609 ~bitmap_bits[((offset + len) / 8 ) & 7];
610 }
611
612 /* If this fragment has the More Fragments flag set to zero, we
613 know that this is the last fragment, so we can calculate the
614 size of the entire packet. We also set the
615 IP_REASS_FLAG_LASTFRAG flag to indicate that we have received
616 the final fragment. */
617
618 if((BUF->ipoffset[0] & IP_MF) == 0) {
619 uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
620 uip_reasslen = offset + len;
621 }
622
623 /* Finally, we check if we have a full packet in the buffer. We do
624 this by checking if we have the last fragment and if all bits
625 in the bitmap are set. */
626 if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
627 /* Check all bytes up to and including all but the last byte in
628 the bitmap. */
629 for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {
630 if(uip_reassbitmap[i] != 0xff) {
631 goto nullreturn;
632 }
633 }
634 /* Check the last byte in the bitmap. It should contain just the
635 right amount of bits. */
636 if(uip_reassbitmap[uip_reasslen / (8 * 8)] !=
637 (u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {
638 goto nullreturn;
639 }
640
641 /* If we have come this far, we have a full packet in the
642 buffer, so we allocate a pbuf and copy the packet into it. We
643 also reset the timer. */
644 uip_reasstmr = 0;
645 memcpy(BUF, FBUF, uip_reasslen);
646
647 /* Pretend to be a "normal" (i.e., not fragmented) IP packet
648 from now on. */
649 BUF->ipoffset[0] = BUF->ipoffset[1] = 0;
650 BUF->len[0] = uip_reasslen >> 8;
651 BUF->len[1] = uip_reasslen & 0xff;
652 BUF->ipchksum = 0;
653 BUF->ipchksum = ~(uip_ipchksum());
654
655 return uip_reasslen;
656 }
657 }
658
659 nullreturn:
660 return 0;
661}
662#endif /* UIP_REASSEMBLY */
663/*---------------------------------------------------------------------------*/
664static void
665uip_add_rcv_nxt(u16_t n)
666{
667 uip_add32(uip_conn->rcv_nxt, n);
668 uip_conn->rcv_nxt[0] = uip_acc32[0];
669 uip_conn->rcv_nxt[1] = uip_acc32[1];
670 uip_conn->rcv_nxt[2] = uip_acc32[2];
671 uip_conn->rcv_nxt[3] = uip_acc32[3];
672}
673/*---------------------------------------------------------------------------*/
674void
675uip_process(u8_t flag)
676{
677 register struct uip_conn *uip_connr = uip_conn;
678
679#if UIP_UDP
680 if(flag == UIP_UDP_SEND_CONN) {
681 goto udp_send;
682 }
683#endif /* UIP_UDP */
684
685 uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
686
687 /* Check if we were invoked because of a poll request for a
688 particular connection. */
689 if(flag == UIP_POLL_REQUEST) {
690 if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&
691 !uip_outstanding(uip_connr)) {
692 uip_len = uip_slen = 0;
693 uip_flags = UIP_POLL;
694 UIP_APPCALL();
695 goto appsend;
696 }
697 goto drop;
698
699 /* Check if we were invoked because of the periodic timer firing. */
700 } else if(flag == UIP_TIMER) {
701#if UIP_REASSEMBLY
702 if(uip_reasstmr != 0) {
703 --uip_reasstmr;
704 }
705#endif /* UIP_REASSEMBLY */
706 /* Increase the initial sequence number. */
707 if(++iss[3] == 0) {
708 if(++iss[2] == 0) {
709 if(++iss[1] == 0) {
710 ++iss[0];
711 }
712 }
713 }
714
715 /* Reset the length variables. */
716 uip_len = 0;
717 uip_slen = 0;
718
719 /* Check if the connection is in a state in which we simply wait
720 for the connection to time out. If so, we increase the
721 connection's timer and remove the connection if it times
722 out. */
723 if(uip_connr->tcpstateflags == UIP_TIME_WAIT ||
724 uip_connr->tcpstateflags == UIP_FIN_WAIT_2) {
725 ++(uip_connr->timer);
726 if(uip_connr->timer == UIP_TIME_WAIT_TIMEOUT) {
727 uip_connr->tcpstateflags = UIP_CLOSED;
728 }
729 } else if(uip_connr->tcpstateflags != UIP_CLOSED) {
730 /* If the connection has outstanding data, we increase the
731 connection's timer and see if it has reached the RTO value
732 in which case we retransmit. */
733 if(uip_outstanding(uip_connr)) {
734 if(uip_connr->timer-- == 0) {
735 if(uip_connr->nrtx == UIP_MAXRTX ||
736 ((uip_connr->tcpstateflags == UIP_SYN_SENT ||
737 uip_connr->tcpstateflags == UIP_SYN_RCVD) &&
738 uip_connr->nrtx == UIP_MAXSYNRTX)) {
739 uip_connr->tcpstateflags = UIP_CLOSED;
740
741 /* We call UIP_APPCALL() with uip_flags set to
742 UIP_TIMEDOUT to inform the application that the
743 connection has timed out. */
744 uip_flags = UIP_TIMEDOUT;
745 UIP_APPCALL();
746
747 /* We also send a reset packet to the remote host. */
748 BUF->flags = TCP_RST | TCP_ACK;
749 goto tcp_send_nodata;
750 }
751
752 /* Exponential back-off. */
753 uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4?
754 4:
755 uip_connr->nrtx);
756 ++(uip_connr->nrtx);
757
758 /* Ok, so we need to retransmit. We do this differently
759 depending on which state we are in. In ESTABLISHED, we
760 call upon the application so that it may prepare the
761 data for the retransmit. In SYN_RCVD, we resend the
762 SYNACK that we sent earlier and in LAST_ACK we have to
763 retransmit our FINACK. */
764 UIP_STAT(++uip_stat.tcp.rexmit);
765 switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
766 case UIP_SYN_RCVD:
767 /* In the SYN_RCVD state, we should retransmit our
768 SYNACK. */
769 goto tcp_send_synack;
770
771#if UIP_ACTIVE_OPEN
772 case UIP_SYN_SENT:
773 /* In the SYN_SENT state, we retransmit out SYN. */
774 BUF->flags = 0;
775 goto tcp_send_syn;
776#endif /* UIP_ACTIVE_OPEN */
777
778 case UIP_ESTABLISHED:
779 /* In the ESTABLISHED state, we call upon the application
780 to do the actual retransmit after which we jump into
781 the code for sending out the packet (the apprexmit
782 label). */
783 uip_flags = UIP_REXMIT;
784 UIP_APPCALL();
785 goto apprexmit;
786
787 case UIP_FIN_WAIT_1:
788 case UIP_CLOSING:
789 case UIP_LAST_ACK:
790 /* In all these states we should retransmit a FINACK. */
791 goto tcp_send_finack;
792
793 }
794 }
795 } else if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
796 /* If there was no need for a retransmission, we poll the
797 application for new data. */
798 uip_len = uip_slen = 0;
799 uip_flags = UIP_POLL;
800 UIP_APPCALL();
801 goto appsend;
802 }
803 }
804 goto drop;
805 }
806#if UIP_UDP
807 if(flag == UIP_UDP_TIMER) {
808 if(uip_udp_conn->lport != 0) {
809 uip_conn = NULL;
810 uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
811 uip_len = uip_slen = 0;
812 uip_flags = UIP_POLL;
813 UIP_UDP_APPCALL();
814 goto udp_send;
815 } else {
816 goto drop;
817 }
818 }
819#endif
820
821 /* This is where the input processing starts. */
822 UIP_STAT(++uip_stat.ip.recv);
823
824 /* Start of IP input header processing code. */
825
826#if UIP_CONF_IPV6
827 /* Check validity of the IP header. */
828 if((BUF->vtc & 0xf0) != 0x60) { /* IP version and header length. */
829 UIP_STAT(++uip_stat.ip.drop);
830 UIP_STAT(++uip_stat.ip.vhlerr);
831 UIP_LOG("ipv6: invalid version.");
832 goto drop;
833 }
834#else /* UIP_CONF_IPV6 */
835 /* Check validity of the IP header. */
836 if(BUF->vhl != 0x45) { /* IP version and header length. */
837 UIP_STAT(++uip_stat.ip.drop);
838 UIP_STAT(++uip_stat.ip.vhlerr);
839 UIP_LOG("ip: invalid version or header length.");
840 goto drop;
841 }
842#endif /* UIP_CONF_IPV6 */
843
844 /* Check the size of the packet. If the size reported to us in
845 uip_len is smaller the size reported in the IP header, we assume
846 that the packet has been corrupted in transit. If the size of
847 uip_len is larger than the size reported in the IP packet header,
848 the packet has been padded and we set uip_len to the correct
849 value.. */
850
851 if((BUF->len[0] << 8) + BUF->len[1] <= uip_len) {
852 uip_len = (BUF->len[0] << 8) + BUF->len[1];
853#if UIP_CONF_IPV6
854 uip_len += 40; /* The length reported in the IPv6 header is the
855 length of the payload that follows the
856 header. However, uIP uses the uip_len variable
857 for holding the size of the entire packet,
858 including the IP header. For IPv4 this is not a
859 problem as the length field in the IPv4 header
860 contains the length of the entire packet. But
861 for IPv6 we need to add the size of the IPv6
862 header (40 bytes). */
863#endif /* UIP_CONF_IPV6 */
864 } else {
865 UIP_LOG("ip: packet shorter than reported in IP header.");
866 goto drop;
867 }
868
869#if !UIP_CONF_IPV6
870 /* Check the fragment flag. */
871 if((BUF->ipoffset[0] & 0x3f) != 0 ||
872 BUF->ipoffset[1] != 0) {
873#if UIP_REASSEMBLY
874 uip_len = uip_reass();
875 if(uip_len == 0) {
876 goto drop;
877 }
878#else /* UIP_REASSEMBLY */
879 UIP_STAT(++uip_stat.ip.drop);
880 UIP_STAT(++uip_stat.ip.fragerr);
881 UIP_LOG("ip: fragment dropped.");
882 goto drop;
883#endif /* UIP_REASSEMBLY */
884 }
885#endif /* UIP_CONF_IPV6 */
886
887 if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {
888 /* If we are configured to use ping IP address configuration and
889 hasn't been assigned an IP address yet, we accept all ICMP
890 packets. */
891#if UIP_PINGADDRCONF && !UIP_CONF_IPV6
892 if(BUF->proto == UIP_PROTO_ICMP) {
893 UIP_LOG("ip: possible ping config packet received.");
894 goto icmp_input;
895 } else {
896 UIP_LOG("ip: packet dropped since no address assigned.");
897 goto drop;
898 }
899#endif /* UIP_PINGADDRCONF */
900
901 } else {
902 /* If IP broadcast support is configured, we check for a broadcast
903 UDP packet, which may be destined to us. */
904#if UIP_BROADCAST
905 DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum());
906 if(BUF->proto == UIP_PROTO_UDP &&
907 uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr))
908 {
909 if (uip_ipaddr_cmp(&BUF->srcipaddr, &uip_all_zeroes_addr))
910 uip_ipaddr_copy(&BUF->srcipaddr, &uip_broadcast_addr);
911
912 goto udp_input;
913 }
914#endif /* UIP_BROADCAST */
915
916 /* Check if the packet is destined for our IP address. */
917#if !UIP_CONF_IPV6
918 if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {
919 UIP_STAT(++uip_stat.ip.drop);
920 goto drop;
921 }
922#else /* UIP_CONF_IPV6 */
923 /* For IPv6, packet reception is a little trickier as we need to
924 make sure that we listen to certain multicast addresses (all
925 hosts multicast address, and the solicited-node multicast
926 address) as well. However, we will cheat here and accept all
927 multicast packets that are sent to the ff02::/16 addresses. */
928 if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) &&
929 BUF->destipaddr.u16[0] != HTONS(0xff02)) {
930 UIP_STAT(++uip_stat.ip.drop);
931 goto drop;
932 }
933#endif /* UIP_CONF_IPV6 */
934 }
935
936#if !UIP_CONF_IPV6
937 if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header
938 checksum. */
939 UIP_STAT(++uip_stat.ip.drop);
940 UIP_STAT(++uip_stat.ip.chkerr);
941 UIP_LOG("ip: bad checksum.");
942 goto drop;
943 }
944#endif /* UIP_CONF_IPV6 */
945
946 if(BUF->proto == UIP_PROTO_TCP) { /* Check for TCP packet. If so,
947 proceed with TCP input
948 processing. */
949 goto tcp_input;
950 }
951
952#if UIP_UDP
953 if(BUF->proto == UIP_PROTO_UDP) {
954 goto udp_input;
955 }
956#endif /* UIP_UDP */
957
958#if !UIP_CONF_IPV6
959 /* ICMPv4 processing code follows. */
960 if(BUF->proto != UIP_PROTO_ICMP) { /* We only allow ICMP packets from
961 here. */
962 UIP_STAT(++uip_stat.ip.drop);
963 UIP_STAT(++uip_stat.ip.protoerr);
964 UIP_LOG("ip: neither tcp nor icmp.");
965 goto drop;
966 }
967
968#if UIP_PINGADDRCONF
969 icmp_input:
970#endif /* UIP_PINGADDRCONF */
971 UIP_STAT(++uip_stat.icmp.recv);
972
973 /* ICMP echo (i.e., ping) processing. This is simple, we only change
974 the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP
975 checksum before we return the packet. */
976 if(ICMPBUF->type != ICMP_ECHO) {
977 UIP_STAT(++uip_stat.icmp.drop);
978 UIP_STAT(++uip_stat.icmp.typeerr);
979 UIP_LOG("icmp: not icmp echo.");
980 goto drop;
981 }
982
983 /* If we are configured to use ping IP address assignment, we use
984 the destination IP address of this ping packet and assign it to
985 yourself. */
986#if UIP_PINGADDRCONF
987 if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {
988 uip_hostaddr = BUF->destipaddr;
989 }
990#endif /* UIP_PINGADDRCONF */
991
992 ICMPBUF->type = ICMP_ECHO_REPLY;
993
994 if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {
995 ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;
996 } else {
997 ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);
998 }
999
1000 /* Swap IP addresses. */
1001 uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
1002 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
1003
1004 UIP_STAT(++uip_stat.icmp.sent);
1005 BUF->ttl = UIP_TTL;
1006 goto ip_send_nolen;
1007
1008 /* End of IPv4 input header processing code. */
1009#else /* !UIP_CONF_IPV6 */
1010
1011 /* This is IPv6 ICMPv6 processing code. */
1012 DEBUG_PRINTF("icmp6_input: length %d\n", uip_len);
1013
1014 if(BUF->proto != UIP_PROTO_ICMP6) { /* We only allow ICMPv6 packets from
1015 here. */
1016 UIP_STAT(++uip_stat.ip.drop);
1017 UIP_STAT(++uip_stat.ip.protoerr);
1018 UIP_LOG("ip: neither tcp nor icmp6.");
1019 goto drop;
1020 }
1021
1022 UIP_STAT(++uip_stat.icmp.recv);
1023
1024 /* If we get a neighbor solicitation for our address we should send
1025 a neighbor advertisement message back. */
1026 if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {
1027 if(uip_ipaddr_cmp(&ICMPBUF->icmp6data, &uip_hostaddr)) {
1028
1029 if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
1030 /* Save the sender's address in our neighbor list. */
1031 uip_neighbor_add(&ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
1032 }
1033
1034 /* We should now send a neighbor advertisement back to where the
1035 neighbor solicitation came from. */
1036 ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT;
1037 ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */
1038
1039 ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;
1040
1041 uip_ipaddr_copy(&ICMPBUF->destipaddr, &ICMPBUF->srcipaddr);
1042 uip_ipaddr_copy(&ICMPBUF->srcipaddr, &uip_hostaddr);
1043 ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
1044 ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */
1045 memcpy(&(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr));
1046 ICMPBUF->icmpchksum = 0;
1047 ICMPBUF->icmpchksum = ~uip_icmp6chksum();
1048
1049 goto send;
1050
1051 }
1052 goto drop;
1053 } else if(ICMPBUF->type == ICMP6_ECHO) {
1054 /* ICMP echo (i.e., ping) processing. This is simple, we only
1055 change the ICMP type from ECHO to ECHO_REPLY and update the
1056 ICMP checksum before we return the packet. */
1057
1058 ICMPBUF->type = ICMP6_ECHO_REPLY;
1059
1060 uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
1061 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
1062 ICMPBUF->icmpchksum = 0;
1063 ICMPBUF->icmpchksum = ~uip_icmp6chksum();
1064
1065 UIP_STAT(++uip_stat.icmp.sent);
1066 goto send;
1067 } else {
1068 DEBUG_PRINTF("Unknown icmp6 message type %d\n", ICMPBUF->type);
1069 UIP_STAT(++uip_stat.icmp.drop);
1070 UIP_STAT(++uip_stat.icmp.typeerr);
1071 UIP_LOG("icmp: unknown ICMP message.");
1072 goto drop;
1073 }
1074
1075 /* End of IPv6 ICMP processing. */
1076
1077#endif /* !UIP_CONF_IPV6 */
1078
1079#if UIP_UDP
1080 /* UDP input processing. */
1081 udp_input:
1082 /* UDP processing is really just a hack. We don't do anything to the
1083 UDP/IP headers, but let the UDP application do all the hard
1084 work. If the application sets uip_slen, it has a packet to
1085 send. */
1086#if UIP_UDP_CHECKSUMS
1087 uip_len = uip_len - UIP_IPUDPH_LEN;
1088 uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
1089 if(UDPBUF->udpchksum != 0 && uip_udpchksum() != 0xffff) {
1090 UIP_STAT(++uip_stat.udp.drop);
1091 UIP_STAT(++uip_stat.udp.chkerr);
1092 UIP_LOG("udp: bad checksum.");
1093 goto drop;
1094 }
1095#else /* UIP_UDP_CHECKSUMS */
1096 uip_len = uip_len - UIP_IPUDPH_LEN;
1097#endif /* UIP_UDP_CHECKSUMS */
1098
1099 /* Demultiplex this UDP packet between the UDP "connections". */
1100 for(uip_udp_conn = &uip_udp_conns[0];
1101 uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS];
1102 ++uip_udp_conn) {
1103 /* If the local UDP port is non-zero, the connection is considered
1104 to be used. If so, the local port number is checked against the
1105 destination port number in the received packet. If the two port
1106 numbers match, the remote port number is checked if the
1107 connection is bound to a remote port. Finally, if the
1108 connection is bound to a remote IP address, the source IP
1109 address of the packet is checked. */
1110 if(uip_udp_conn->lport != 0 &&
1111 UDPBUF->destport == uip_udp_conn->lport &&
1112 (uip_udp_conn->rport == 0 ||
1113 UDPBUF->srcport == uip_udp_conn->rport) &&
1114 (uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_all_zeroes_addr) ||
1115 uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_broadcast_addr) ||
1116 uip_ipaddr_cmp(&BUF->srcipaddr, &uip_udp_conn->ripaddr))) {
1117 goto udp_found;
1118 }
1119 }
1120 UIP_LOG("udp: no matching connection found");
1121#if UIP_CONF_ICMP_DEST_UNREACH && !UIP_CONF_IPV6
1122 /* Copy fields from packet header into payload of this ICMP packet. */
1123 memcpy(&(ICMPBUF->payload[0]), ICMPBUF, UIP_IPH_LEN + 8);
1124
1125 /* Set the ICMP type and code. */
1126 ICMPBUF->type = ICMP_DEST_UNREACHABLE;
1127 ICMPBUF->icode = ICMP_PORT_UNREACHABLE;
1128
1129 /* Calculate the ICMP checksum. */
1130 ICMPBUF->icmpchksum = 0;
1131 ICMPBUF->icmpchksum = ~uip_chksum((u16_t *)&(ICMPBUF->type), 36);
1132
1133 /* Set the IP destination address to be the source address of the
1134 original packet. */
1135 uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
1136
1137 /* Set our IP address as the source address. */
1138 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
1139
1140 /* The size of the ICMP destination unreachable packet is 36 + the
1141 size of the IP header (20) = 56. */
1142 uip_len = 36 + UIP_IPH_LEN;
1143 ICMPBUF->len[0] = 0;
1144 ICMPBUF->len[1] = (u8_t)uip_len;
1145 ICMPBUF->ttl = UIP_TTL;
1146 ICMPBUF->proto = UIP_PROTO_ICMP;
1147
1148 goto ip_send_nolen;
1149#else /* UIP_CONF_ICMP_DEST_UNREACH */
1150 goto drop;
1151#endif /* UIP_CONF_ICMP_DEST_UNREACH */
1152
1153 udp_found:
1154 uip_conn = NULL;
1155 uip_flags = UIP_NEWDATA;
1156 uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
1157 uip_slen = 0;
1158 UIP_UDP_APPCALL();
1159
1160 udp_send:
1161 if(uip_slen == 0) {
1162 goto drop;
1163 }
1164 uip_len = uip_slen + UIP_IPUDPH_LEN;
1165
1166#if UIP_CONF_IPV6
1167 /* For IPv6, the IP length field does not include the IPv6 IP header
1168 length. */
1169 BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
1170 BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
1171#else /* UIP_CONF_IPV6 */
1172 BUF->len[0] = (uip_len >> 8);
1173 BUF->len[1] = (uip_len & 0xff);
1174#endif /* UIP_CONF_IPV6 */
1175
1176 BUF->ttl = uip_udp_conn->ttl;
1177 BUF->proto = UIP_PROTO_UDP;
1178
1179 UDPBUF->udplen = HTONS(uip_slen + UIP_UDPH_LEN);
1180 UDPBUF->udpchksum = 0;
1181
1182 BUF->srcport = uip_udp_conn->lport;
1183 BUF->destport = uip_udp_conn->rport;
1184
1185 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
1186 uip_ipaddr_copy(&BUF->destipaddr, &uip_udp_conn->ripaddr);
1187
1188 uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];
1189
1190#if UIP_UDP_CHECKSUMS
1191 /* Calculate UDP checksum. */
1192 UDPBUF->udpchksum = ~(uip_udpchksum());
1193 if(UDPBUF->udpchksum == 0) {
1194 UDPBUF->udpchksum = 0xffff;
1195 }
1196#endif /* UIP_UDP_CHECKSUMS */
1197
1198 goto ip_send_nolen;
1199#endif /* UIP_UDP */
1200
1201 /* TCP input processing. */
1202 tcp_input:
1203 UIP_STAT(++uip_stat.tcp.recv);
1204
1205 /* Start of TCP input header processing code. */
1206
1207 if(uip_tcpchksum() != 0xffff) { /* Compute and check the TCP
1208 checksum. */
1209 UIP_STAT(++uip_stat.tcp.drop);
1210 UIP_STAT(++uip_stat.tcp.chkerr);
1211 UIP_LOG("tcp: bad checksum.");
1212 goto drop;
1213 }
1214
1215 /* Demultiplex this segment. */
1216 /* First check any active connections. */
1217 for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1];
1218 ++uip_connr) {
1219 if(uip_connr->tcpstateflags != UIP_CLOSED &&
1220 BUF->destport == uip_connr->lport &&
1221 BUF->srcport == uip_connr->rport &&
1222 uip_ipaddr_cmp(&BUF->srcipaddr, &uip_connr->ripaddr)) {
1223 goto found;
1224 }
1225 }
1226
1227 /* If we didn't find and active connection that expected the packet,
1228 either this packet is an old duplicate, or this is a SYN packet
1229 destined for a connection in LISTEN. If the SYN flag isn't set,
1230 it is an old packet and we send a RST. */
1231 if((BUF->flags & TCP_CTL) != TCP_SYN) {
1232 goto reset;
1233 }
1234
1235 tmp16 = BUF->destport;
1236 /* Next, check listening connections. */
1237 for(c = 0; c < UIP_LISTENPORTS; ++c) {
1238 if(tmp16 == uip_listenports[c]) {
1239 goto found_listen;
1240 }
1241 }
1242
1243 /* No matching connection found, so we send a RST packet. */
1244 UIP_STAT(++uip_stat.tcp.synrst);
1245
1246 reset:
1247 /* We do not send resets in response to resets. */
1248 if(BUF->flags & TCP_RST) {
1249 goto drop;
1250 }
1251
1252 UIP_STAT(++uip_stat.tcp.rst);
1253
1254 BUF->flags = TCP_RST | TCP_ACK;
1255 uip_len = UIP_IPTCPH_LEN;
1256 BUF->tcpoffset = 5 << 4;
1257
1258 /* Flip the seqno and ackno fields in the TCP header. */
1259 c = BUF->seqno[3];
1260 BUF->seqno[3] = BUF->ackno[3];
1261 BUF->ackno[3] = c;
1262
1263 c = BUF->seqno[2];
1264 BUF->seqno[2] = BUF->ackno[2];
1265 BUF->ackno[2] = c;
1266
1267 c = BUF->seqno[1];
1268 BUF->seqno[1] = BUF->ackno[1];
1269 BUF->ackno[1] = c;
1270
1271 c = BUF->seqno[0];
1272 BUF->seqno[0] = BUF->ackno[0];
1273 BUF->ackno[0] = c;
1274
1275 /* We also have to increase the sequence number we are
1276 acknowledging. If the least significant byte overflowed, we need
1277 to propagate the carry to the other bytes as well. */
1278 if(++BUF->ackno[3] == 0) {
1279 if(++BUF->ackno[2] == 0) {
1280 if(++BUF->ackno[1] == 0) {
1281 ++BUF->ackno[0];
1282 }
1283 }
1284 }
1285
1286 /* Swap port numbers. */
1287 tmp16 = BUF->srcport;
1288 BUF->srcport = BUF->destport;
1289 BUF->destport = tmp16;
1290
1291 /* Swap IP addresses. */
1292 uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
1293 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
1294
1295 /* And send out the RST packet! */
1296 goto tcp_send_noconn;
1297
1298 /* This label will be jumped to if we matched the incoming packet
1299 with a connection in LISTEN. In that case, we should create a new
1300 connection and send a SYNACK in return. */
1301 found_listen:
1302 /* First we check if there are any connections available. Unused
1303 connections are kept in the same table as used connections, but
1304 unused ones have the tcpstate set to CLOSED. Also, connections in
1305 TIME_WAIT are kept track of and we'll use the oldest one if no
1306 CLOSED connections are found. Thanks to Eddie C. Dost for a very
1307 nice algorithm for the TIME_WAIT search. */
1308 uip_connr = 0;
1309 for(c = 0; c < UIP_CONNS; ++c) {
1310 if(uip_conns[c].tcpstateflags == UIP_CLOSED) {
1311 uip_connr = &uip_conns[c];
1312 break;
1313 }
1314 if(uip_conns[c].tcpstateflags == UIP_TIME_WAIT) {
1315 if(uip_connr == 0 ||
1316 uip_conns[c].timer > uip_connr->timer) {
1317 uip_connr = &uip_conns[c];
1318 }
1319 }
1320 }
1321
1322 if(uip_connr == 0) {
1323 /* All connections are used already, we drop packet and hope that
1324 the remote end will retransmit the packet at a time when we
1325 have more spare connections. */
1326 UIP_STAT(++uip_stat.tcp.syndrop);
1327 UIP_LOG("tcp: found no unused connections.");
1328 goto drop;
1329 }
1330 uip_conn = uip_connr;
1331
1332 /* Fill in the necessary fields for the new connection. */
1333 uip_connr->rto = uip_connr->timer = UIP_RTO;
1334 uip_connr->sa = 0;
1335 uip_connr->sv = 4;
1336 uip_connr->nrtx = 0;
1337 uip_connr->lport = BUF->destport;
1338 uip_connr->rport = BUF->srcport;
1339 uip_ipaddr_copy(&uip_connr->ripaddr, &BUF->srcipaddr);
1340 uip_connr->tcpstateflags = UIP_SYN_RCVD;
1341
1342 uip_connr->snd_nxt[0] = iss[0];
1343 uip_connr->snd_nxt[1] = iss[1];
1344 uip_connr->snd_nxt[2] = iss[2];
1345 uip_connr->snd_nxt[3] = iss[3];
1346 uip_connr->len = 1;
1347
1348 /* rcv_nxt should be the seqno from the incoming packet + 1. */
1349 uip_connr->rcv_nxt[3] = BUF->seqno[3];
1350 uip_connr->rcv_nxt[2] = BUF->seqno[2];
1351 uip_connr->rcv_nxt[1] = BUF->seqno[1];
1352 uip_connr->rcv_nxt[0] = BUF->seqno[0];
1353 uip_add_rcv_nxt(1);
1354
1355 /* Parse the TCP MSS option, if present. */
1356 if((BUF->tcpoffset & 0xf0) > 0x50) {
1357 for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
1358 opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c];
1359 if(opt == TCP_OPT_END) {
1360 /* End of options. */
1361 break;
1362 } else if(opt == TCP_OPT_NOOP) {
1363 ++c;
1364 /* NOP option. */
1365 } else if(opt == TCP_OPT_MSS &&
1366 uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
1367 /* An MSS option with the right option length. */
1368 tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
1369 (u16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];
1370 uip_connr->initialmss = uip_connr->mss =
1371 tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
1372
1373 /* And we are done processing options. */
1374 break;
1375 } else {
1376 /* All other options have a length field, so that we easily
1377 can skip past them. */
1378 if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
1379 /* If the length field is zero, the options are malformed
1380 and we don't process them further. */
1381 break;
1382 }
1383 c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
1384 }
1385 }
1386 }
1387
1388 /* Our response will be a SYNACK. */
1389#if UIP_ACTIVE_OPEN
1390 tcp_send_synack:
1391 BUF->flags = TCP_ACK;
1392
1393 tcp_send_syn:
1394 BUF->flags |= TCP_SYN;
1395#else /* UIP_ACTIVE_OPEN */
1396 tcp_send_synack:
1397 BUF->flags = TCP_SYN | TCP_ACK;
1398#endif /* UIP_ACTIVE_OPEN */
1399
1400 /* We send out the TCP Maximum Segment Size option with our
1401 SYNACK. */
1402 BUF->optdata[0] = TCP_OPT_MSS;
1403 BUF->optdata[1] = TCP_OPT_MSS_LEN;
1404 BUF->optdata[2] = (UIP_TCP_MSS) / 256;
1405 BUF->optdata[3] = (UIP_TCP_MSS) & 255;
1406 uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;
1407 BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4;
1408 goto tcp_send;
1409
1410 /* This label will be jumped to if we found an active connection. */
1411 found:
1412 uip_conn = uip_connr;
1413 uip_flags = 0;
1414 /* We do a very naive form of TCP reset processing; we just accept
1415 any RST and kill our connection. We should in fact check if the
1416 sequence number of this reset is within our advertised window
1417 before we accept the reset. */
1418 if(BUF->flags & TCP_RST) {
1419 uip_connr->tcpstateflags = UIP_CLOSED;
1420 UIP_LOG("tcp: got reset, aborting connection.");
1421 uip_flags = UIP_ABORT;
1422 UIP_APPCALL();
1423 goto drop;
1424 }
1425 /* Calculate the length of the data, if the application has sent
1426 any data to us. */
1427 c = (BUF->tcpoffset >> 4) << 2;
1428 /* uip_len will contain the length of the actual TCP data. This is
1429 calculated by subtracing the length of the TCP header (in
1430 c) and the length of the IP header (20 bytes). */
1431 uip_len = uip_len - c - UIP_IPH_LEN;
1432
1433 /* First, check if the sequence number of the incoming packet is
1434 what we're expecting next. If not, we send out an ACK with the
1435 correct numbers in. */
1436 if(!(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
1437 ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) {
1438 if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
1439 (BUF->seqno[0] != uip_connr->rcv_nxt[0] ||
1440 BUF->seqno[1] != uip_connr->rcv_nxt[1] ||
1441 BUF->seqno[2] != uip_connr->rcv_nxt[2] ||
1442 BUF->seqno[3] != uip_connr->rcv_nxt[3])) {
1443 goto tcp_send_ack;
1444 }
1445 }
1446
1447 /* Next, check if the incoming segment acknowledges any outstanding
1448 data. If so, we update the sequence number, reset the length of
1449 the outstanding data, calculate RTT estimations, and reset the
1450 retransmission timer. */
1451 if((BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) {
1452 uip_add32(uip_connr->snd_nxt, uip_connr->len);
1453
1454 if(BUF->ackno[0] == uip_acc32[0] &&
1455 BUF->ackno[1] == uip_acc32[1] &&
1456 BUF->ackno[2] == uip_acc32[2] &&
1457 BUF->ackno[3] == uip_acc32[3]) {
1458 /* Update sequence number. */
1459 uip_connr->snd_nxt[0] = uip_acc32[0];
1460 uip_connr->snd_nxt[1] = uip_acc32[1];
1461 uip_connr->snd_nxt[2] = uip_acc32[2];
1462 uip_connr->snd_nxt[3] = uip_acc32[3];
1463
1464 /* Do RTT estimation, unless we have done retransmissions. */
1465 if(uip_connr->nrtx == 0) {
1466 signed char m;
1467 m = uip_connr->rto - uip_connr->timer;
1468 /* This is taken directly from VJs original code in his paper */
1469 m = m - (uip_connr->sa >> 3);
1470 uip_connr->sa += m;
1471 if(m < 0) {
1472 m = -m;
1473 }
1474 m = m - (uip_connr->sv >> 2);
1475 uip_connr->sv += m;
1476 uip_connr->rto = (uip_connr->sa >> 3) + uip_connr->sv;
1477
1478 }
1479 /* Set the acknowledged flag. */
1480 uip_flags = UIP_ACKDATA;
1481 /* Reset the retransmission timer. */
1482 uip_connr->timer = uip_connr->rto;
1483
1484 /* Reset length of outstanding data. */
1485 uip_connr->len = 0;
1486 }
1487
1488 }
1489
1490 /* Do different things depending on in what state the connection is. */
1491 switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
1492 /* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not
1493 implemented, since we force the application to close when the
1494 peer sends a FIN (hence the application goes directly from
1495 ESTABLISHED to LAST_ACK). */
1496 case UIP_SYN_RCVD:
1497 /* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and
1498 we are waiting for an ACK that acknowledges the data we sent
1499 out the last time. Therefore, we want to have the UIP_ACKDATA
1500 flag set. If so, we enter the ESTABLISHED state. */
1501 if(uip_flags & UIP_ACKDATA) {
1502 uip_connr->tcpstateflags = UIP_ESTABLISHED;
1503 uip_flags = UIP_CONNECTED;
1504 uip_connr->len = 0;
1505 if(uip_len > 0) {
1506 uip_flags |= UIP_NEWDATA;
1507 uip_add_rcv_nxt(uip_len);
1508 }
1509 uip_slen = 0;
1510 UIP_APPCALL();
1511 goto appsend;
1512 }
1513 goto drop;
1514#if UIP_ACTIVE_OPEN
1515 case UIP_SYN_SENT:
1516 /* In SYN_SENT, we wait for a SYNACK that is sent in response to
1517 our SYN. The rcv_nxt is set to sequence number in the SYNACK
1518 plus one, and we send an ACK. We move into the ESTABLISHED
1519 state. */
1520 if((uip_flags & UIP_ACKDATA) &&
1521 (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) {
1522
1523 /* Parse the TCP MSS option, if present. */
1524 if((BUF->tcpoffset & 0xf0) > 0x50) {
1525 for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
1526 opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];
1527 if(opt == TCP_OPT_END) {
1528 /* End of options. */
1529 break;
1530 } else if(opt == TCP_OPT_NOOP) {
1531 ++c;
1532 /* NOP option. */
1533 } else if(opt == TCP_OPT_MSS &&
1534 uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
1535 /* An MSS option with the right option length. */
1536 tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
1537 uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
1538 uip_connr->initialmss =
1539 uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
1540
1541 /* And we are done processing options. */
1542 break;
1543 } else {
1544 /* All other options have a length field, so that we easily
1545 can skip past them. */
1546 if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
1547 /* If the length field is zero, the options are malformed
1548 and we don't process them further. */
1549 break;
1550 }
1551 c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
1552 }
1553 }
1554 }
1555 uip_connr->tcpstateflags = UIP_ESTABLISHED;
1556 uip_connr->rcv_nxt[0] = BUF->seqno[0];
1557 uip_connr->rcv_nxt[1] = BUF->seqno[1];
1558 uip_connr->rcv_nxt[2] = BUF->seqno[2];
1559 uip_connr->rcv_nxt[3] = BUF->seqno[3];
1560 uip_add_rcv_nxt(1);
1561 uip_flags = UIP_CONNECTED | UIP_NEWDATA;
1562 uip_connr->len = 0;
1563 uip_len = 0;
1564 uip_slen = 0;
1565 UIP_APPCALL();
1566 goto appsend;
1567 }
1568 /* Inform the application that the connection failed */
1569 uip_flags = UIP_ABORT;
1570 UIP_APPCALL();
1571 /* The connection is closed after we send the RST */
1572 uip_conn->tcpstateflags = UIP_CLOSED;
1573 goto reset;
1574#endif /* UIP_ACTIVE_OPEN */
1575
1576 case UIP_ESTABLISHED:
1577 /* In the ESTABLISHED state, we call upon the application to feed
1578 data into the uip_buf. If the UIP_ACKDATA flag is set, the
1579 application should put new data into the buffer, otherwise we are
1580 retransmitting an old segment, and the application should put that
1581 data into the buffer.
1582
1583 If the incoming packet is a FIN, we should close the connection on
1584 this side as well, and we send out a FIN and enter the LAST_ACK
1585 state. We require that there is no outstanding data; otherwise the
1586 sequence numbers will be screwed up. */
1587
1588 if(BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
1589 if(uip_outstanding(uip_connr)) {
1590 goto drop;
1591 }
1592 uip_add_rcv_nxt(1 + uip_len);
1593 uip_flags |= UIP_CLOSE;
1594 if(uip_len > 0) {
1595 uip_flags |= UIP_NEWDATA;
1596 }
1597 UIP_APPCALL();
1598 uip_connr->len = 1;
1599 uip_connr->tcpstateflags = UIP_LAST_ACK;
1600 uip_connr->nrtx = 0;
1601 tcp_send_finack:
1602 BUF->flags = TCP_FIN | TCP_ACK;
1603 goto tcp_send_nodata;
1604 }
1605
1606 /* Check the URG flag. If this is set, the segment carries urgent
1607 data that we must pass to the application. */
1608 if((BUF->flags & TCP_URG) != 0) {
1609#if UIP_URGDATA > 0
1610 uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];
1611 if(uip_urglen > uip_len) {
1612 /* There is more urgent data in the next segment to come. */
1613 uip_urglen = uip_len;
1614 }
1615 uip_add_rcv_nxt(uip_urglen);
1616 uip_len -= uip_urglen;
1617 uip_urgdata = uip_appdata;
1618 uip_appdata += uip_urglen;
1619 } else {
1620 uip_urglen = 0;
1621#else /* UIP_URGDATA > 0 */
1622 uip_appdata = ((char *)uip_appdata) + ((BUF->urgp[0] << 8) | BUF->urgp[1]);
1623 uip_len -= (BUF->urgp[0] << 8) | BUF->urgp[1];
1624#endif /* UIP_URGDATA > 0 */
1625 }
1626
1627 /* If uip_len > 0 we have TCP data in the packet, and we flag this
1628 by setting the UIP_NEWDATA flag and update the sequence number
1629 we acknowledge. If the application has stopped the dataflow
1630 using uip_stop(), we must not accept any data packets from the
1631 remote host. */
1632 if(uip_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
1633 uip_flags |= UIP_NEWDATA;
1634 uip_add_rcv_nxt(uip_len);
1635 }
1636
1637 /* Check if the available buffer space advertised by the other end
1638 is smaller than the initial MSS for this connection. If so, we
1639 set the current MSS to the window size to ensure that the
1640 application does not send more data than the other end can
1641 handle.
1642
1643 If the remote host advertises a zero window, we set the MSS to
1644 the initial MSS so that the application will send an entire MSS
1645 of data. This data will not be acknowledged by the receiver,
1646 and the application will retransmit it. This is called the
1647 "persistent timer" and uses the retransmission mechanism.
1648 */
1649 tmp16 = ((u16_t)BUF->wnd[0] << 8) + (u16_t)BUF->wnd[1];
1650 if(tmp16 > uip_connr->initialmss ||
1651 tmp16 == 0) {
1652 tmp16 = uip_connr->initialmss;
1653 }
1654 uip_connr->mss = tmp16;
1655
1656 /* If this packet constitutes an ACK for outstanding data (flagged
1657 by the UIP_ACKDATA flag, we should call the application since it
1658 might want to send more data. If the incoming packet had data
1659 from the peer (as flagged by the UIP_NEWDATA flag), the
1660 application must also be notified.
1661
1662 When the application is called, the global variable uip_len
1663 contains the length of the incoming data. The application can
1664 access the incoming data through the global pointer
1665 uip_appdata, which usually points UIP_IPTCPH_LEN + UIP_LLH_LEN
1666 bytes into the uip_buf array.
1667
1668 If the application wishes to send any data, this data should be
1669 put into the uip_appdata and the length of the data should be
1670 put into uip_len. If the application don't have any data to
1671 send, uip_len must be set to 0. */
1672 if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
1673 uip_slen = 0;
1674 UIP_APPCALL();
1675
1676 appsend:
1677
1678 if(uip_flags & UIP_ABORT) {
1679 uip_slen = 0;
1680 uip_connr->tcpstateflags = UIP_CLOSED;
1681 BUF->flags = TCP_RST | TCP_ACK;
1682 goto tcp_send_nodata;
1683 }
1684
1685 if(uip_flags & UIP_CLOSE) {
1686 uip_slen = 0;
1687 uip_connr->len = 1;
1688 uip_connr->tcpstateflags = UIP_FIN_WAIT_1;
1689 uip_connr->nrtx = 0;
1690 BUF->flags = TCP_FIN | TCP_ACK;
1691 goto tcp_send_nodata;
1692 }
1693
1694 /* If uip_slen > 0, the application has data to be sent. */
1695 if(uip_slen > 0) {
1696
1697 /* If the connection has acknowledged data, the contents of
1698 the ->len variable should be discarded. */
1699 if((uip_flags & UIP_ACKDATA) != 0) {
1700 uip_connr->len = 0;
1701 }
1702
1703 /* If the ->len variable is non-zero the connection has
1704 already data in transit and cannot send anymore right
1705 now. */
1706 if(uip_connr->len == 0) {
1707
1708 /* The application cannot send more than what is allowed by
1709 the mss (the minumum of the MSS and the available
1710 window). */
1711 if(uip_slen > uip_connr->mss) {
1712 uip_slen = uip_connr->mss;
1713 }
1714
1715 /* Remember how much data we send out now so that we know
1716 when everything has been acknowledged. */
1717 uip_connr->len = uip_slen;
1718 } else {
1719
1720 /* If the application already had unacknowledged data, we
1721 make sure that the application does not send (i.e.,
1722 retransmit) out more than it previously sent out. */
1723 uip_slen = uip_connr->len;
1724 }
1725 }
1726 uip_connr->nrtx = 0;
1727 apprexmit:
1728 uip_appdata = uip_sappdata;
1729
1730 /* If the application has data to be sent, or if the incoming
1731 packet had new data in it, we must send out a packet. */
1732 if(uip_slen > 0 && uip_connr->len > 0) {
1733 /* Add the length of the IP and TCP headers. */
1734 uip_len = uip_connr->len + UIP_TCPIP_HLEN;
1735 /* We always set the ACK flag in response packets. */
1736 BUF->flags = TCP_ACK | TCP_PSH;
1737 /* Send the packet. */
1738 goto tcp_send_noopts;
1739 }
1740 /* If there is no data to send, just send out a pure ACK if
1741 there is newdata. */
1742 if(uip_flags & UIP_NEWDATA) {
1743 uip_len = UIP_TCPIP_HLEN;
1744 BUF->flags = TCP_ACK;
1745 goto tcp_send_noopts;
1746 }
1747 }
1748 goto drop;
1749 case UIP_LAST_ACK:
1750 /* We can close this connection if the peer has acknowledged our
1751 FIN. This is indicated by the UIP_ACKDATA flag. */
1752 if(uip_flags & UIP_ACKDATA) {
1753 uip_connr->tcpstateflags = UIP_CLOSED;
1754 uip_flags = UIP_CLOSE;
1755 UIP_APPCALL();
1756 }
1757 break;
1758
1759 case UIP_FIN_WAIT_1:
1760 /* The application has closed the connection, but the remote host
1761 hasn't closed its end yet. Thus we do nothing but wait for a
1762 FIN from the other side. */
1763 if(uip_len > 0) {
1764 uip_add_rcv_nxt(uip_len);
1765 }
1766 if(BUF->flags & TCP_FIN) {
1767 if(uip_flags & UIP_ACKDATA) {
1768 uip_connr->tcpstateflags = UIP_TIME_WAIT;
1769 uip_connr->timer = 0;
1770 uip_connr->len = 0;
1771 } else {
1772 uip_connr->tcpstateflags = UIP_CLOSING;
1773 }
1774 uip_add_rcv_nxt(1);
1775 uip_flags = UIP_CLOSE;
1776 UIP_APPCALL();
1777 goto tcp_send_ack;
1778 } else if(uip_flags & UIP_ACKDATA) {
1779 uip_connr->tcpstateflags = UIP_FIN_WAIT_2;
1780 uip_connr->len = 0;
1781 goto drop;
1782 }
1783 if(uip_len > 0) {
1784 goto tcp_send_ack;
1785 }
1786 goto drop;
1787
1788 case UIP_FIN_WAIT_2:
1789 if(uip_len > 0) {
1790 uip_add_rcv_nxt(uip_len);
1791 }
1792 if(BUF->flags & TCP_FIN) {
1793 uip_connr->tcpstateflags = UIP_TIME_WAIT;
1794 uip_connr->timer = 0;
1795 uip_add_rcv_nxt(1);
1796 uip_flags = UIP_CLOSE;
1797 UIP_APPCALL();
1798 goto tcp_send_ack;
1799 }
1800 if(uip_len > 0) {
1801 goto tcp_send_ack;
1802 }
1803 goto drop;
1804
1805 case UIP_TIME_WAIT:
1806 goto tcp_send_ack;
1807
1808 case UIP_CLOSING:
1809 if(uip_flags & UIP_ACKDATA) {
1810 uip_connr->tcpstateflags = UIP_TIME_WAIT;
1811 uip_connr->timer = 0;
1812 }
1813 }
1814 goto drop;
1815
1816 /* We jump here when we are ready to send the packet, and just want
1817 to set the appropriate TCP sequence numbers in the TCP header. */
1818 tcp_send_ack:
1819 BUF->flags = TCP_ACK;
1820
1821 tcp_send_nodata:
1822 uip_len = UIP_IPTCPH_LEN;
1823
1824 tcp_send_noopts:
1825 BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;
1826
1827 /* We're done with the input processing. We are now ready to send a
1828 reply. Our job is to fill in all the fields of the TCP and IP
1829 headers before calculating the checksum and finally send the
1830 packet. */
1831 tcp_send:
1832 BUF->ackno[0] = uip_connr->rcv_nxt[0];
1833 BUF->ackno[1] = uip_connr->rcv_nxt[1];
1834 BUF->ackno[2] = uip_connr->rcv_nxt[2];
1835 BUF->ackno[3] = uip_connr->rcv_nxt[3];
1836
1837 BUF->seqno[0] = uip_connr->snd_nxt[0];
1838 BUF->seqno[1] = uip_connr->snd_nxt[1];
1839 BUF->seqno[2] = uip_connr->snd_nxt[2];
1840 BUF->seqno[3] = uip_connr->snd_nxt[3];
1841
1842 BUF->proto = UIP_PROTO_TCP;
1843
1844 BUF->srcport = uip_connr->lport;
1845 BUF->destport = uip_connr->rport;
1846
1847 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
1848 uip_ipaddr_copy(&BUF->destipaddr, &uip_connr->ripaddr);
1849
1850 if(uip_connr->tcpstateflags & UIP_STOPPED) {
1851 /* If the connection has issued uip_stop(), we advertise a zero
1852 window so that the remote host will stop sending data. */
1853 BUF->wnd[0] = BUF->wnd[1] = 0;
1854 } else {
1855 BUF->wnd[0] = ((UIP_RECEIVE_WINDOW) >> 8);
1856 BUF->wnd[1] = ((UIP_RECEIVE_WINDOW) & 0xff);
1857 }
1858
1859 tcp_send_noconn:
1860 BUF->ttl = UIP_TTL;
1861#if UIP_CONF_IPV6
1862 /* For IPv6, the IP length field does not include the IPv6 IP header
1863 length. */
1864 BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
1865 BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
1866#else /* UIP_CONF_IPV6 */
1867 BUF->len[0] = (uip_len >> 8);
1868 BUF->len[1] = (uip_len & 0xff);
1869#endif /* UIP_CONF_IPV6 */
1870
1871 BUF->urgp[0] = BUF->urgp[1] = 0;
1872
1873 /* Calculate TCP checksum. */
1874 BUF->tcpchksum = 0;
1875 BUF->tcpchksum = ~(uip_tcpchksum());
1876
1877 ip_send_nolen:
1878#if UIP_CONF_IPV6
1879 BUF->vtc = 0x60;
1880 BUF->tcflow = 0x00;
1881 BUF->flow = 0x00;
1882#else /* UIP_CONF_IPV6 */
1883 BUF->vhl = 0x45;
1884 BUF->tos = 0;
1885 BUF->ipoffset[0] = BUF->ipoffset[1] = 0;
1886 ++ipid;
1887 BUF->ipid[0] = ipid >> 8;
1888 BUF->ipid[1] = ipid & 0xff;
1889 /* Calculate IP checksum. */
1890 BUF->ipchksum = 0;
1891 BUF->ipchksum = ~(uip_ipchksum());
1892 DEBUG_PRINTF("uip ip_send_nolen: checksum 0x%04x\n", uip_ipchksum());
1893#endif /* UIP_CONF_IPV6 */
1894 UIP_STAT(++uip_stat.tcp.sent);
1895#if UIP_CONF_IPV6
1896 send:
1897#endif /* UIP_CONF_IPV6 */
1898 DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len,
1899 (BUF->len[0] << 8) | BUF->len[1]);
1900
1901 UIP_STAT(++uip_stat.ip.sent);
1902 /* Return and let the caller do the actual transmission. */
1903 uip_flags = 0;
1904 return;
1905
1906 drop:
1907 uip_len = 0;
1908 uip_flags = 0;
1909 return;
1910}
1911/*---------------------------------------------------------------------------*/
1912u16_t
1913htons(u16_t val)
1914{
1915 return HTONS(val);
1916}
1917
1918u32_t
1919htonl(u32_t val)
1920{
1921 return HTONL(val);
1922}
1923/*---------------------------------------------------------------------------*/
1924void
1925uip_send(const void *data, int len)
1926{
1927 int copylen;
1928#define MIN(a,b) ((a) < (b)? (a): (b))
1929 copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN -
1930 (int)((char *)uip_sappdata - (char *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]));
1931 if(copylen > 0) {
1932 uip_slen = copylen;
1933 if(data != uip_sappdata) {
1934 memcpy(uip_sappdata, (data), uip_slen);
1935 }
1936 }
1937}
1938/*---------------------------------------------------------------------------*/
1939/** @} */
1940#endif /* UIP_CONF_IPV6 */
1941
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/uip.h b/lib/lufa/Projects/Webserver/Lib/uip/uip.h
deleted file mode 100644
index 7b87a2c77..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/uip.h
+++ /dev/null
@@ -1,2130 +0,0 @@
1
2/**
3 * \addtogroup uip
4 * @{
5 */
6
7/**
8 * \file
9 * Header file for the uIP TCP/IP stack.
10 * \author Adam Dunkels <adam@dunkels.com>
11 * \author Julien Abeille <jabeille@cisco.com> (IPv6 related code)
12 * \author Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)
13 *
14 * The uIP TCP/IP stack header file contains definitions for a number
15 * of C macros that are used by uIP programs as well as internal uIP
16 * structures, TCP/IP header structures and function declarations.
17 *
18 */
19
20/*
21 * Copyright (c) 2001-2003, Adam Dunkels.
22 * All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * 3. The name of the author may not be used to endorse or promote
33 * products derived from this software without specific prior
34 * written permission.
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
37 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
40 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
45 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 *
48 * This file is part of the uIP TCP/IP stack.
49 *
50 * $Id: uip.h,v 1.24 2009/04/06 13:18:50 nvt-se Exp $
51 *
52 */
53
54#ifndef __UIP_H__
55#define __UIP_H__
56
57#include "uipopt.h"
58
59/**
60 * Representation of an IP address.
61 *
62 */
63#if UIP_CONF_IPV6
64typedef union uip_ip6addr_t {
65 u8_t u8[16]; /* Initialiser, must come first!!! */
66 u16_t u16[8];
67} uip_ip6addr_t;
68
69typedef uip_ip6addr_t uip_ipaddr_t;
70#else /* UIP_CONF_IPV6 */
71typedef union uip_ip4addr_t {
72 u8_t u8[4]; /* Initialiser, must come first!!! */
73 u16_t u16[2];
74#if 0
75 u32_t u32;
76#endif
77} uip_ip4addr_t;
78typedef uip_ip4addr_t uip_ipaddr_t;
79#endif /* UIP_CONF_IPV6 */
80
81
82/*---------------------------------------------------------------------------*/
83
84/** \brief 16 bit 802.15.4 address */
85struct uip_802154_shortaddr {
86 u8_t addr[2];
87};
88/** \brief 64 bit 802.15.4 address */
89struct uip_802154_longaddr {
90 u8_t addr[8];
91};
92
93/** \brief 802.11 address */
94struct uip_80211_addr {
95 u8_t addr[6];
96};
97
98/** \brief 802.3 address */
99struct uip_eth_addr {
100 u8_t addr[6];
101};
102
103#if UIP_CONF_LL_802154
104/** \brief 802.15.4 address */
105typedef struct uip_802154_longaddr uip_lladdr_t;
106#define UIP_802154_SHORTADDR_LEN 2
107#define UIP_802154_LONGADDR_LEN 8
108#define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN
109#else /*UIP_CONF_LL_802154*/
110#if UIP_CONF_LL_80211
111/** \brief 802.11 address */
112typedef struct uip_80211_addr uip_lladdr_t;
113#define UIP_LLADDR_LEN 6
114#else /*UIP_CONF_LL_80211*/
115/** \brief Ethernet address */
116typedef struct uip_eth_addr uip_lladdr_t;
117#define UIP_LLADDR_LEN 6
118#endif /*UIP_CONF_LL_80211*/
119#endif /*UIP_CONF_LL_802154*/
120
121/*---------------------------------------------------------------------------*/
122/* First, the functions that should be called from the
123 * system. Initialization, the periodic timer, and incoming packets are
124 * handled by the following three functions.
125 */
126/**
127 * \defgroup uipconffunc uIP configuration functions
128 * @{
129 *
130 * The uIP configuration functions are used for setting run-time
131 * parameters in uIP such as IP addresses.
132 */
133
134/**
135 * Set the IP address of this host.
136 *
137 * The IP address is represented as a 4-byte array where the first
138 * octet of the IP address is put in the first member of the 4-byte
139 * array.
140 *
141 * Example:
142 \code
143
144 uip_ipaddr_t addr;
145
146 uip_ipaddr(&addr, 192,168,1,2);
147 uip_sethostaddr(&addr);
148
149 \endcode
150 * \param addr A pointer to an IP address of type uip_ipaddr_t;
151 *
152 * \sa uip_ipaddr()
153 *
154 * \hideinitializer
155 */
156#define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr))
157
158/**
159 * Get the IP address of this host.
160 *
161 * The IP address is represented as a 4-byte array where the first
162 * octet of the IP address is put in the first member of the 4-byte
163 * array.
164 *
165 * Example:
166 \code
167 uip_ipaddr_t hostaddr;
168
169 uip_gethostaddr(&hostaddr);
170 \endcode
171 * \param addr A pointer to a uip_ipaddr_t variable that will be
172 * filled in with the currently configured IP address.
173 *
174 * \hideinitializer
175 */
176#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr)
177
178/**
179 * Set the default router's IP address.
180 *
181 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
182 * address of the default router.
183 *
184 * \sa uip_ipaddr()
185 *
186 * \hideinitializer
187 */
188#define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr))
189
190/**
191 * Set the netmask.
192 *
193 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
194 * address of the netmask.
195 *
196 * \sa uip_ipaddr()
197 *
198 * \hideinitializer
199 */
200#define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr))
201
202
203/**
204 * Get the default router's IP address.
205 *
206 * \param addr A pointer to a uip_ipaddr_t variable that will be
207 * filled in with the IP address of the default router.
208 *
209 * \hideinitializer
210 */
211#define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr)
212
213/**
214 * Get the netmask.
215 *
216 * \param addr A pointer to a uip_ipaddr_t variable that will be
217 * filled in with the value of the netmask.
218 *
219 * \hideinitializer
220 */
221#define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask)
222
223/** @} */
224
225/**
226 * \defgroup uipinit uIP initialization functions
227 * @{
228 *
229 * The uIP initialization functions are used for booting uIP.
230 */
231
232/**
233 * uIP initialization function.
234 *
235 * This function should be called at boot up to initialize the uIP
236 * TCP/IP stack.
237 */
238void uip_init(void);
239
240/**
241 * uIP initialization function.
242 *
243 * This function may be used at boot time to set the initial ip_id.
244 */
245void uip_setipid(u16_t id);
246
247/** @} */
248
249/**
250 * \defgroup uipdevfunc uIP device driver functions
251 * @{
252 *
253 * These functions are used by a network device driver for interacting
254 * with uIP.
255 */
256
257/**
258 * Process an incoming packet.
259 *
260 * This function should be called when the device driver has received
261 * a packet from the network. The packet from the device driver must
262 * be present in the uip_buf buffer, and the length of the packet
263 * should be placed in the uip_len variable.
264 *
265 * When the function returns, there may be an outbound packet placed
266 * in the uip_buf packet buffer. If so, the uip_len variable is set to
267 * the length of the packet. If no packet is to be sent out, the
268 * uip_len variable is set to 0.
269 *
270 * The usual way of calling the function is presented by the source
271 * code below.
272 \code
273 uip_len = devicedriver_poll();
274 if(uip_len > 0) {
275 uip_input();
276 if(uip_len > 0) {
277 devicedriver_send();
278 }
279 }
280 \endcode
281 *
282 * \note If you are writing a uIP device driver that needs ARP
283 * (Address Resolution Protocol), e.g., when running uIP over
284 * Ethernet, you will need to call the uIP ARP code before calling
285 * this function:
286 \code
287 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
288 uip_len = ethernet_devicedrver_poll();
289 if(uip_len > 0) {
290 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
291 uip_arp_ipin();
292 uip_input();
293 if(uip_len > 0) {
294 uip_arp_out();
295 ethernet_devicedriver_send();
296 }
297 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
298 uip_arp_arpin();
299 if(uip_len > 0) {
300 ethernet_devicedriver_send();
301 }
302 }
303 \endcode
304 *
305 * \hideinitializer
306 */
307#define uip_input() uip_process(UIP_DATA)
308
309
310/**
311 * Periodic processing for a connection identified by its number.
312 *
313 * This function does the necessary periodic processing (timers,
314 * polling) for a uIP TCP connection, and should be called when the
315 * periodic uIP timer goes off. It should be called for every
316 * connection, regardless of whether they are open of closed.
317 *
318 * When the function returns, it may have an outbound packet waiting
319 * for service in the uIP packet buffer, and if so the uip_len
320 * variable is set to a value larger than zero. The device driver
321 * should be called to send out the packet.
322 *
323 * The usual way of calling the function is through a for() loop like
324 * this:
325 \code
326 for(i = 0; i < UIP_CONNS; ++i) {
327 uip_periodic(i);
328 if(uip_len > 0) {
329 devicedriver_send();
330 }
331 }
332 \endcode
333 *
334 * \note If you are writing a uIP device driver that needs ARP
335 * (Address Resolution Protocol), e.g., when running uIP over
336 * Ethernet, you will need to call the uip_arp_out() function before
337 * calling the device driver:
338 \code
339 for(i = 0; i < UIP_CONNS; ++i) {
340 uip_periodic(i);
341 if(uip_len > 0) {
342 uip_arp_out();
343 ethernet_devicedriver_send();
344 }
345 }
346 \endcode
347 *
348 * \param conn The number of the connection which is to be periodically polled.
349 *
350 * \hideinitializer
351 */
352#if UIP_TCP
353#define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \
354 uip_process(UIP_TIMER); } while (0)
355
356/**
357 *
358 *
359 */
360#define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED)
361
362/**
363 * Perform periodic processing for a connection identified by a pointer
364 * to its structure.
365 *
366 * Same as uip_periodic() but takes a pointer to the actual uip_conn
367 * struct instead of an integer as its argument. This function can be
368 * used to force periodic processing of a specific connection.
369 *
370 * \param conn A pointer to the uip_conn struct for the connection to
371 * be processed.
372 *
373 * \hideinitializer
374 */
375#define uip_periodic_conn(conn) do { uip_conn = conn; \
376 uip_process(UIP_TIMER); } while (0)
377
378/**
379 * Request that a particular connection should be polled.
380 *
381 * Similar to uip_periodic_conn() but does not perform any timer
382 * processing. The application is polled for new data.
383 *
384 * \param conn A pointer to the uip_conn struct for the connection to
385 * be processed.
386 *
387 * \hideinitializer
388 */
389#define uip_poll_conn(conn) do { uip_conn = conn; \
390 uip_process(UIP_POLL_REQUEST); } while (0)
391
392#endif /* UIP_TCP */
393
394#if UIP_UDP
395/**
396 * Periodic processing for a UDP connection identified by its number.
397 *
398 * This function is essentially the same as uip_periodic(), but for
399 * UDP connections. It is called in a similar fashion as the
400 * uip_periodic() function:
401 \code
402 for(i = 0; i < UIP_UDP_CONNS; i++) {
403 uip_udp_periodic(i);
404 if(uip_len > 0) {
405 devicedriver_send();
406 }
407 }
408 \endcode
409 *
410 * \note As for the uip_periodic() function, special care has to be
411 * taken when using uIP together with ARP and Ethernet:
412 \code
413 for(i = 0; i < UIP_UDP_CONNS; i++) {
414 uip_udp_periodic(i);
415 if(uip_len > 0) {
416 uip_arp_out();
417 ethernet_devicedriver_send();
418 }
419 }
420 \endcode
421 *
422 * \param conn The number of the UDP connection to be processed.
423 *
424 * \hideinitializer
425 */
426#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
427 uip_process(UIP_UDP_TIMER); } while(0)
428
429/**
430 * Periodic processing for a UDP connection identified by a pointer to
431 * its structure.
432 *
433 * Same as uip_udp_periodic() but takes a pointer to the actual
434 * uip_conn struct instead of an integer as its argument. This
435 * function can be used to force periodic processing of a specific
436 * connection.
437 *
438 * \param conn A pointer to the uip_udp_conn struct for the connection
439 * to be processed.
440 *
441 * \hideinitializer
442 */
443#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
444 uip_process(UIP_UDP_TIMER); } while(0)
445#endif /* UIP_UDP */
446
447/** \brief Abandon the reassembly of the current packet */
448void uip_reass_over(void);
449
450/**
451 * The uIP packet buffer.
452 *
453 * The uip_buf array is used to hold incoming and outgoing
454 * packets. The device driver should place incoming data into this
455 * buffer. When sending data, the device driver should read the link
456 * level headers and the TCP/IP headers from this buffer. The size of
457 * the link level headers is configured by the UIP_LLH_LEN define.
458 *
459 * \note The application data need not be placed in this buffer, so
460 * the device driver must read it from the place pointed to by the
461 * uip_appdata pointer as illustrated by the following example:
462 \code
463 void
464 devicedriver_send(void)
465 {
466 hwsend(&uip_buf[0], UIP_LLH_LEN);
467 if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
468 hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
469 } else {
470 hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
471 hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
472 }
473 }
474 \endcode
475*/
476extern u8_t uip_buf[UIP_BUFSIZE+2];
477
478
479
480/** @} */
481
482/*---------------------------------------------------------------------------*/
483/* Functions that are used by the uIP application program. Opening and
484 * closing connections, sending and receiving data, etc. is all
485 * handled by the functions below.
486 */
487/**
488 * \defgroup uipappfunc uIP application functions
489 * @{
490 *
491 * Functions used by an application running of top of uIP.
492 */
493
494/**
495 * Start listening to the specified port.
496 *
497 * \note Since this function expects the port number in network byte
498 * order, a conversion using HTONS() or htons() is necessary.
499 *
500 \code
501 uip_listen(HTONS(80));
502 \endcode
503 *
504 * \param port A 16-bit port number in network byte order.
505 */
506void uip_listen(u16_t port);
507
508/**
509 * Stop listening to the specified port.
510 *
511 * \note Since this function expects the port number in network byte
512 * order, a conversion using HTONS() or htons() is necessary.
513 *
514 \code
515 uip_unlisten(HTONS(80));
516 \endcode
517 *
518 * \param port A 16-bit port number in network byte order.
519 */
520void uip_unlisten(u16_t port);
521
522/**
523 * Connect to a remote host using TCP.
524 *
525 * This function is used to start a new connection to the specified
526 * port on the specified host. It allocates a new connection identifier,
527 * sets the connection to the SYN_SENT state and sets the
528 * retransmission timer to 0. This will cause a TCP SYN segment to be
529 * sent out the next time this connection is periodically processed,
530 * which usually is done within 0.5 seconds after the call to
531 * uip_connect().
532 *
533 * \note This function is available only if support for active open
534 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
535 *
536 * \note Since this function requires the port number to be in network
537 * byte order, a conversion using HTONS() or htons() is necessary.
538 *
539 \code
540 uip_ipaddr_t ipaddr;
541
542 uip_ipaddr(&ipaddr, 192,168,1,2);
543 uip_connect(&ipaddr, HTONS(80));
544 \endcode
545 *
546 * \param ripaddr The IP address of the remote host.
547 *
548 * \param port A 16-bit port number in network byte order.
549 *
550 * \return A pointer to the uIP connection identifier for the new connection,
551 * or NULL if no connection could be allocated.
552 *
553 */
554struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, u16_t port);
555
556
557
558/**
559 * \internal
560 *
561 * Check if a connection has outstanding (i.e., unacknowledged) data.
562 *
563 * \param conn A pointer to the uip_conn structure for the connection.
564 *
565 * \hideinitializer
566 */
567#define uip_outstanding(conn) ((conn)->len)
568
569/**
570 * Send data on the current connection.
571 *
572 * This function is used to send out a single segment of TCP
573 * data. Only applications that have been invoked by uIP for event
574 * processing can send data.
575 *
576 * The amount of data that actually is sent out after a call to this
577 * function is determined by the maximum amount of data TCP allows. uIP
578 * will automatically crop the data so that only the appropriate
579 * amount of data is sent. The function uip_mss() can be used to query
580 * uIP for the amount of data that actually will be sent.
581 *
582 * \note This function does not guarantee that the sent data will
583 * arrive at the destination. If the data is lost in the network, the
584 * application will be invoked with the uip_rexmit() event being
585 * set. The application will then have to resend the data using this
586 * function.
587 *
588 * \param data A pointer to the data which is to be sent.
589 *
590 * \param len The maximum amount of data bytes to be sent.
591 *
592 * \hideinitializer
593 */
594void uip_send(const void *data, int len);
595
596/**
597 * The length of any incoming data that is currently available (if available)
598 * in the uip_appdata buffer.
599 *
600 * The test function uip_data() must first be used to check if there
601 * is any data available at all.
602 *
603 * \hideinitializer
604 */
605/*void uip_datalen(void);*/
606#define uip_datalen() uip_len
607
608/**
609 * The length of any out-of-band data (urgent data) that has arrived
610 * on the connection.
611 *
612 * \note The configuration parameter UIP_URGDATA must be set for this
613 * function to be enabled.
614 *
615 * \hideinitializer
616 */
617#define uip_urgdatalen() uip_urglen
618
619/**
620 * Close the current connection.
621 *
622 * This function will close the current connection in a nice way.
623 *
624 * \hideinitializer
625 */
626#define uip_close() (uip_flags = UIP_CLOSE)
627
628/**
629 * Abort the current connection.
630 *
631 * This function will abort (reset) the current connection, and is
632 * usually used when an error has occurred that prevents using the
633 * uip_close() function.
634 *
635 * \hideinitializer
636 */
637#define uip_abort() (uip_flags = UIP_ABORT)
638
639/**
640 * Tell the sending host to stop sending data.
641 *
642 * This function will close our receiver's window so that we stop
643 * receiving data for the current connection.
644 *
645 * \hideinitializer
646 */
647#define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)
648
649/**
650 * Find out if the current connection has been previously stopped with
651 * uip_stop().
652 *
653 * \hideinitializer
654 */
655#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED)
656
657/**
658 * Restart the current connection, if is has previously been stopped
659 * with uip_stop().
660 *
661 * This function will open the receiver's window again so that we
662 * start receiving data for the current connection.
663 *
664 * \hideinitializer
665 */
666#define uip_restart() do { uip_flags |= UIP_NEWDATA; \
667 uip_conn->tcpstateflags &= ~UIP_STOPPED; \
668 } while(0)
669
670
671/* uIP tests that can be made to determine in what state the current
672 connection is, and what the application function should do. */
673
674/**
675 * Is the current connection a UDP connection?
676 *
677 * This function checks whether the current connection is a UDP connection.
678 *
679 * \hideinitializer
680 *
681 */
682#define uip_udpconnection() (uip_conn == NULL)
683
684/**
685 * Is new incoming data available?
686 *
687 * Will reduce to non-zero if there is new data for the application
688 * present at the uip_appdata pointer. The size of the data is
689 * available through the uip_len variable.
690 *
691 * \hideinitializer
692 */
693#define uip_newdata() (uip_flags & UIP_NEWDATA)
694
695/**
696 * Has previously sent data been acknowledged?
697 *
698 * Will reduce to non-zero if the previously sent data has been
699 * acknowledged by the remote host. This means that the application
700 * can send new data.
701 *
702 * \hideinitializer
703 */
704#define uip_acked() (uip_flags & UIP_ACKDATA)
705
706/**
707 * Has the connection just been connected?
708 *
709 * Reduces to non-zero if the current connection has been connected to
710 * a remote host. This will happen both if the connection has been
711 * actively opened (with uip_connect()) or passively opened (with
712 * uip_listen()).
713 *
714 * \hideinitializer
715 */
716#define uip_connected() (uip_flags & UIP_CONNECTED)
717
718/**
719 * Has the connection been closed by the other end?
720 *
721 * Is non-zero if the connection has been closed by the remote
722 * host. The application may then do the necessary clean-ups.
723 *
724 * \hideinitializer
725 */
726#define uip_closed() (uip_flags & UIP_CLOSE)
727
728/**
729 * Has the connection been aborted by the other end?
730 *
731 * Non-zero if the current connection has been aborted (reset) by the
732 * remote host.
733 *
734 * \hideinitializer
735 */
736#define uip_aborted() (uip_flags & UIP_ABORT)
737
738/**
739 * Has the connection timed out?
740 *
741 * Non-zero if the current connection has been aborted due to too many
742 * retransmissions.
743 *
744 * \hideinitializer
745 */
746#define uip_timedout() (uip_flags & UIP_TIMEDOUT)
747
748/**
749 * Do we need to retransmit previously data?
750 *
751 * Reduces to non-zero if the previously sent data has been lost in
752 * the network, and the application should retransmit it. The
753 * application should send the exact same data as it did the last
754 * time, using the uip_send() function.
755 *
756 * \hideinitializer
757 */
758#define uip_rexmit() (uip_flags & UIP_REXMIT)
759
760/**
761 * Is the connection being polled by uIP?
762 *
763 * Is non-zero if the reason the application is invoked is that the
764 * current connection has been idle for a while and should be
765 * polled.
766 *
767 * The polling event can be used for sending data without having to
768 * wait for the remote host to send data.
769 *
770 * \hideinitializer
771 */
772#define uip_poll() (uip_flags & UIP_POLL)
773
774/**
775 * Get the initial maximum segment size (MSS) of the current
776 * connection.
777 *
778 * \hideinitializer
779 */
780#define uip_initialmss() (uip_conn->initialmss)
781
782/**
783 * Get the current maximum segment size that can be sent on the current
784 * connection.
785 *
786 * The current maximum segment size that can be sent on the
787 * connection is computed from the receiver's window and the MSS of
788 * the connection (which also is available by calling
789 * uip_initialmss()).
790 *
791 * \hideinitializer
792 */
793#define uip_mss() (uip_conn->mss)
794
795/**
796 * Set up a new UDP connection.
797 *
798 * This function sets up a new UDP connection. The function will
799 * automatically allocate an unused local port for the new
800 * connection. However, another port can be chosen by using the
801 * uip_udp_bind() call, after the uip_udp_new() function has been
802 * called.
803 *
804 * Example:
805 \code
806 uip_ipaddr_t addr;
807 struct uip_udp_conn *c;
808
809 uip_ipaddr(&addr, 192,168,2,1);
810 c = uip_udp_new(&addr, HTONS(12345));
811 if(c != NULL) {
812 uip_udp_bind(c, HTONS(12344));
813 }
814 \endcode
815 * \param ripaddr The IP address of the remote host.
816 *
817 * \param rport The remote port number in network byte order.
818 *
819 * \return The uip_udp_conn structure for the new connection or NULL
820 * if no connection could be allocated.
821 */
822struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, u16_t rport);
823
824/**
825 * Removed a UDP connection.
826 *
827 * \param conn A pointer to the uip_udp_conn structure for the connection.
828 *
829 * \hideinitializer
830 */
831#define uip_udp_remove(conn) (conn)->lport = 0
832
833/**
834 * Bind a UDP connection to a local port.
835 *
836 * \param conn A pointer to the uip_udp_conn structure for the
837 * connection.
838 *
839 * \param port The local port number, in network byte order.
840 *
841 * \hideinitializer
842 */
843#define uip_udp_bind(conn, port) (conn)->lport = port
844
845/**
846 * Send a UDP datagram of length len on the current connection.
847 *
848 * This function can only be called in response to a UDP event (poll
849 * or newdata). The data must be present in the uip_buf buffer, at the
850 * place pointed to by the uip_appdata pointer.
851 *
852 * \param len The length of the data in the uip_buf buffer.
853 *
854 * \hideinitializer
855 */
856#define uip_udp_send(len) uip_send((char *)uip_appdata, len)
857
858/** @} */
859
860/* uIP convenience and converting functions. */
861
862/**
863 * \defgroup uipconvfunc uIP conversion functions
864 * @{
865 *
866 * These functions can be used for converting between different data
867 * formats used by uIP.
868 */
869
870/**
871 * Convert an IP address to four bytes separated by commas.
872 *
873 * Example:
874 \code
875 uip_ipaddr_t ipaddr;
876 printf("ipaddr=%d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipaddr));
877 \endcode
878 *
879 * \param a A pointer to a uip_ipaddr_t.
880 * \hideinitializer
881 */
882#define uip_ipaddr_to_quad(a) (a)->u8[0],(a)->u8[1],(a)->u8[2],(a)->u8[3]
883
884/**
885 * Construct an IP address from four bytes.
886 *
887 * This function constructs an IP address of the type that uIP handles
888 * internally from four bytes. The function is handy for specifying IP
889 * addresses to use with e.g. the uip_connect() function.
890 *
891 * Example:
892 \code
893 uip_ipaddr_t ipaddr;
894 struct uip_conn *c;
895
896 uip_ipaddr(&ipaddr, 192,168,1,2);
897 c = uip_connect(&ipaddr, HTONS(80));
898 \endcode
899 *
900 * \param addr A pointer to a uip_ipaddr_t variable that will be
901 * filled in with the IP address.
902 *
903 * \param addr0 The first octet of the IP address.
904 * \param addr1 The second octet of the IP address.
905 * \param addr2 The third octet of the IP address.
906 * \param addr3 The forth octet of the IP address.
907 *
908 * \hideinitializer
909 */
910#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
911 (addr)->u8[0] = addr0; \
912 (addr)->u8[1] = addr1; \
913 (addr)->u8[2] = addr2; \
914 (addr)->u8[3] = addr3; \
915 } while(0)
916
917/**
918 * Construct an IPv6 address from eight 16-bit words.
919 *
920 * This function constructs an IPv6 address.
921 *
922 * \hideinitializer
923 */
924#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
925 (addr)->u16[0] = HTONS(addr0); \
926 (addr)->u16[1] = HTONS(addr1); \
927 (addr)->u16[2] = HTONS(addr2); \
928 (addr)->u16[3] = HTONS(addr3); \
929 (addr)->u16[4] = HTONS(addr4); \
930 (addr)->u16[5] = HTONS(addr5); \
931 (addr)->u16[6] = HTONS(addr6); \
932 (addr)->u16[7] = HTONS(addr7); \
933 } while(0)
934
935/**
936 * Construct an IPv6 address from sixteen 8-bit words.
937 *
938 * This function constructs an IPv6 address.
939 *
940 * \hideinitializer
941 */
942#define uip_ip6addr_u8(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7,addr8,addr9,addr10,addr11,addr12,addr13,addr14,addr15) do { \
943 (addr)->u8[0] = addr0; \
944 (addr)->u8[1] = addr1; \
945 (addr)->u8[2] = addr2; \
946 (addr)->u8[3] = addr3; \
947 (addr)->u8[4] = addr4; \
948 (addr)->u8[5] = addr5; \
949 (addr)->u8[6] = addr6; \
950 (addr)->u8[7] = addr7; \
951 (addr)->u8[8] = addr8; \
952 (addr)->u8[9] = addr9; \
953 (addr)->u8[10] = addr10; \
954 (addr)->u8[11] = addr11; \
955 (addr)->u8[12] = addr12; \
956 (addr)->u8[13] = addr13; \
957 (addr)->u8[14] = addr14; \
958 (addr)->u8[15] = addr15; \
959 } while(0)
960
961
962/**
963 * Copy an IP address to another IP address.
964 *
965 * Copies an IP address from one place to another.
966 *
967 * Example:
968 \code
969 uip_ipaddr_t ipaddr1, ipaddr2;
970
971 uip_ipaddr(&ipaddr1, 192,16,1,2);
972 uip_ipaddr_copy(&ipaddr2, &ipaddr1);
973 \endcode
974 *
975 * \param dest The destination for the copy.
976 * \param src The source from where to copy.
977 *
978 * \hideinitializer
979 */
980#ifndef uip_ipaddr_copy
981#define uip_ipaddr_copy(dest, src) (*(dest) = *(src))
982#endif
983
984/**
985 * Compare two IP addresses
986 *
987 * Compares two IP addresses.
988 *
989 * Example:
990 \code
991 uip_ipaddr_t ipaddr1, ipaddr2;
992
993 uip_ipaddr(&ipaddr1, 192,16,1,2);
994 if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
995 printf("They are the same");
996 }
997 \endcode
998 *
999 * \param addr1 The first IP address.
1000 * \param addr2 The second IP address.
1001 *
1002 * \hideinitializer
1003 */
1004#if !UIP_CONF_IPV6
1005#define uip_ipaddr_cmp(addr1, addr2) ((addr1)->u16[0] == (addr2)->u16[0] && \
1006 (addr1)->u16[1] == (addr2)->u16[1])
1007#else /* !UIP_CONF_IPV6 */
1008#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
1009#endif /* !UIP_CONF_IPV6 */
1010
1011/**
1012 * Compare two IP addresses with netmasks
1013 *
1014 * Compares two IP addresses with netmasks. The masks are used to mask
1015 * out the bits that are to be compared.
1016 *
1017 * Example:
1018 \code
1019 uip_ipaddr_t ipaddr1, ipaddr2, mask;
1020
1021 uip_ipaddr(&mask, 255,255,255,0);
1022 uip_ipaddr(&ipaddr1, 192,16,1,2);
1023 uip_ipaddr(&ipaddr2, 192,16,1,3);
1024 if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
1025 printf("They are the same");
1026 }
1027 \endcode
1028 *
1029 * \param addr1 The first IP address.
1030 * \param addr2 The second IP address.
1031 * \param mask The netmask.
1032 *
1033 * \hideinitializer
1034 */
1035#if !UIP_CONF_IPV6
1036#define uip_ipaddr_maskcmp(addr1, addr2, mask) \
1037 (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \
1038 (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \
1039 ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \
1040 (((u16_t *)addr2)[1] & ((u16_t *)mask)[1])))
1041#else
1042#define uip_ipaddr_prefixcmp(addr1, addr2, length) (memcmp(addr1, addr2, length>>3) == 0)
1043#endif
1044
1045
1046/**
1047 * Check if an address is a broadcast address for a network.
1048 *
1049 * Checks if an address is the broadcast address for a network. The
1050 * network is defined by an IP address that is on the network and the
1051 * network's netmask.
1052 *
1053 * \param addr The IP address.
1054 * \param netaddr The network's IP address.
1055 * \param netmask The network's netmask.
1056 *
1057 * \hideinitializer
1058 */
1059/*#define uip_ipaddr_isbroadcast(addr, netaddr, netmask)
1060 ((uip_ipaddr_t *)(addr)).u16 & ((uip_ipaddr_t *)(addr)).u16*/
1061
1062
1063
1064/**
1065 * Mask out the network part of an IP address.
1066 *
1067 * Masks out the network part of an IP address, given the address and
1068 * the netmask.
1069 *
1070 * Example:
1071 \code
1072 uip_ipaddr_t ipaddr1, ipaddr2, netmask;
1073
1074 uip_ipaddr(&ipaddr1, 192,16,1,2);
1075 uip_ipaddr(&netmask, 255,255,255,0);
1076 uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
1077 \endcode
1078 *
1079 * In the example above, the variable "ipaddr2" will contain the IP
1080 * address 192.168.1.0.
1081 *
1082 * \param dest Where the result is to be placed.
1083 * \param src The IP address.
1084 * \param mask The netmask.
1085 *
1086 * \hideinitializer
1087 */
1088#define uip_ipaddr_mask(dest, src, mask) do { \
1089 ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \
1090 ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \
1091 } while(0)
1092
1093/**
1094 * Pick the first octet of an IP address.
1095 *
1096 * Picks out the first octet of an IP address.
1097 *
1098 * Example:
1099 \code
1100 uip_ipaddr_t ipaddr;
1101 u8_t octet;
1102
1103 uip_ipaddr(&ipaddr, 1,2,3,4);
1104 octet = uip_ipaddr1(&ipaddr);
1105 \endcode
1106 *
1107 * In the example above, the variable "octet" will contain the value 1.
1108 *
1109 * \hideinitializer
1110 */
1111#define uip_ipaddr1(addr) ((addr)->u8[0])
1112
1113/**
1114 * Pick the second octet of an IP address.
1115 *
1116 * Picks out the second octet of an IP address.
1117 *
1118 * Example:
1119 \code
1120 uip_ipaddr_t ipaddr;
1121 u8_t octet;
1122
1123 uip_ipaddr(&ipaddr, 1,2,3,4);
1124 octet = uip_ipaddr2(&ipaddr);
1125 \endcode
1126 *
1127 * In the example above, the variable "octet" will contain the value 2.
1128 *
1129 * \hideinitializer
1130 */
1131#define uip_ipaddr2(addr) ((addr)->u8[1])
1132
1133/**
1134 * Pick the third octet of an IP address.
1135 *
1136 * Picks out the third octet of an IP address.
1137 *
1138 * Example:
1139 \code
1140 uip_ipaddr_t ipaddr;
1141 u8_t octet;
1142
1143 uip_ipaddr(&ipaddr, 1,2,3,4);
1144 octet = uip_ipaddr3(&ipaddr);
1145 \endcode
1146 *
1147 * In the example above, the variable "octet" will contain the value 3.
1148 *
1149 * \hideinitializer
1150 */
1151#define uip_ipaddr3(addr) ((addr)->u8[2])
1152
1153/**
1154 * Pick the fourth octet of an IP address.
1155 *
1156 * Picks out the fourth octet of an IP address.
1157 *
1158 * Example:
1159 \code
1160 uip_ipaddr_t ipaddr;
1161 u8_t octet;
1162
1163 uip_ipaddr(&ipaddr, 1,2,3,4);
1164 octet = uip_ipaddr4(&ipaddr);
1165 \endcode
1166 *
1167 * In the example above, the variable "octet" will contain the value 4.
1168 *
1169 * \hideinitializer
1170 */
1171#define uip_ipaddr4(addr) ((addr)->u8[3])
1172
1173/**
1174 * Convert 16-bit quantity from host byte order to network byte order.
1175 *
1176 * This macro is primarily used for converting constants from host
1177 * byte order to network byte order. For converting variables to
1178 * network byte order, use the htons() function instead.
1179 *
1180 * \hideinitializer
1181 */
1182#ifndef HTONS
1183# if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
1184# define HTONS(n) (n)
1185# define HTONL(n) (n)
1186# else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
1187# define HTONS(n) (u16_t)((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8))
1188# define HTONL(n) (((u32_t)HTONS(n) << 16) | HTONS((u32_t)(n) >> 16))
1189# endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
1190#else
1191#error "HTONS already defined!"
1192#endif /* HTONS */
1193
1194/**
1195 * Convert 16-bit quantity from host byte order to network byte order.
1196 *
1197 * This function is primarily used for converting variables from host
1198 * byte order to network byte order. For converting constants to
1199 * network byte order, use the HTONS() macro instead.
1200 */
1201#ifndef htons
1202u16_t htons(u16_t val);
1203#endif /* htons */
1204#ifndef ntohs
1205#define ntohs htons
1206#endif
1207
1208#ifndef htonl
1209u32_t htonl(u32_t val);
1210#endif /* htonl */
1211#ifndef ntohl
1212#define ntohl htonl
1213#endif
1214
1215/** @} */
1216
1217/**
1218 * Pointer to the application data in the packet buffer.
1219 *
1220 * This pointer points to the application data when the application is
1221 * called. If the application wishes to send data, the application may
1222 * use this space to write the data into before calling uip_send().
1223 */
1224extern void *uip_appdata;
1225
1226#if UIP_URGDATA > 0
1227/* u8_t *uip_urgdata:
1228 *
1229 * This pointer points to any urgent data that has been received. Only
1230 * present if compiled with support for urgent data (UIP_URGDATA).
1231 */
1232extern void *uip_urgdata;
1233#endif /* UIP_URGDATA > 0 */
1234
1235
1236/**
1237 * \defgroup uipdrivervars Variables used in uIP device drivers
1238 * @{
1239 *
1240 * uIP has a few global variables that are used in device drivers for
1241 * uIP.
1242 */
1243
1244/**
1245 * The length of the packet in the uip_buf buffer.
1246 *
1247 * The global variable uip_len holds the length of the packet in the
1248 * uip_buf buffer.
1249 *
1250 * When the network device driver calls the uIP input function,
1251 * uip_len should be set to the length of the packet in the uip_buf
1252 * buffer.
1253 *
1254 * When sending packets, the device driver should use the contents of
1255 * the uip_len variable to determine the length of the outgoing
1256 * packet.
1257 *
1258 */
1259extern u16_t uip_len;
1260
1261/**
1262 * The length of the extension headers
1263 */
1264extern u8_t uip_ext_len;
1265/** @} */
1266
1267#if UIP_URGDATA > 0
1268extern u16_t uip_urglen, uip_surglen;
1269#endif /* UIP_URGDATA > 0 */
1270
1271
1272/**
1273 * Representation of a uIP TCP connection.
1274 *
1275 * The uip_conn structure is used for identifying a connection. All
1276 * but one field in the structure are to be considered read-only by an
1277 * application. The only exception is the appstate field whose purpose
1278 * is to let the application store application-specific state (e.g.,
1279 * file pointers) for the connection. The type of this field is
1280 * configured in the "uipopt.h" header file.
1281 */
1282struct uip_conn {
1283 uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */
1284
1285 u16_t lport; /**< The local TCP port, in network byte order. */
1286 u16_t rport; /**< The local remote TCP port, in network byte
1287 order. */
1288
1289 u8_t rcv_nxt[4]; /**< The sequence number that we expect to
1290 receive next. */
1291 u8_t snd_nxt[4]; /**< The sequence number that was last sent by
1292 us. */
1293 u16_t len; /**< Length of the data that was previously sent. */
1294 u16_t mss; /**< Current maximum segment size for the
1295 connection. */
1296 u16_t initialmss; /**< Initial maximum segment size for the
1297 connection. */
1298 u8_t sa; /**< Retransmission time-out calculation state
1299 variable. */
1300 u8_t sv; /**< Retransmission time-out calculation state
1301 variable. */
1302 u8_t rto; /**< Retransmission time-out. */
1303 u8_t tcpstateflags; /**< TCP state and flags. */
1304 u8_t timer; /**< The retransmission timer. */
1305 u8_t nrtx; /**< The number of retransmissions for the last
1306 segment sent. */
1307
1308 /** The application state. */
1309 uip_tcp_appstate_t appstate;
1310};
1311
1312
1313/**
1314 * Pointer to the current TCP connection.
1315 *
1316 * The uip_conn pointer can be used to access the current TCP
1317 * connection.
1318 */
1319
1320extern struct uip_conn *uip_conn;
1321#if UIP_TCP
1322/* The array containing all uIP connections. */
1323extern struct uip_conn uip_conns[UIP_CONNS];
1324#endif
1325
1326/**
1327 * \addtogroup uiparch
1328 * @{
1329 */
1330
1331/**
1332 * 4-byte array used for the 32-bit sequence number calculations.
1333 */
1334extern u8_t uip_acc32[4];
1335/** @} */
1336
1337/**
1338 * Representation of a uIP UDP connection.
1339 */
1340struct uip_udp_conn {
1341 uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */
1342 u16_t lport; /**< The local port number in network byte order. */
1343 u16_t rport; /**< The remote port number in network byte order. */
1344 u8_t ttl; /**< Default time-to-live. */
1345
1346 /** The application state. */
1347 uip_udp_appstate_t appstate;
1348};
1349
1350/**
1351 * The current UDP connection.
1352 */
1353extern struct uip_udp_conn *uip_udp_conn;
1354extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
1355
1356struct uip_router {
1357 int (*activate)(void);
1358 int (*deactivate)(void);
1359 uip_ipaddr_t *(*lookup)(uip_ipaddr_t *destipaddr, uip_ipaddr_t *nexthop);
1360};
1361
1362#if UIP_CONF_ROUTER
1363extern const struct uip_router *uip_router;
1364
1365/**
1366 * uIP routing driver registration function.
1367 */
1368void uip_router_register(const struct uip_router *router);
1369#endif /*UIP_CONF_ROUTER*/
1370
1371#if UIP_CONF_ICMP6
1372struct uip_icmp6_conn {
1373 uip_icmp6_appstate_t appstate;
1374};
1375extern struct uip_icmp6_conn uip_icmp6_conns;
1376#endif /*UIP_CONF_ICMP6*/
1377
1378/**
1379 * The uIP TCP/IP statistics.
1380 *
1381 * This is the variable in which the uIP TCP/IP statistics are gathered.
1382 */
1383#if UIP_STATISTICS == 1
1384extern struct uip_stats uip_stat;
1385#define UIP_STAT(s) s
1386#else
1387#define UIP_STAT(s)
1388#endif /* UIP_STATISTICS == 1 */
1389
1390/**
1391 * The structure holding the TCP/IP statistics that are gathered if
1392 * UIP_STATISTICS is set to 1.
1393 *
1394 */
1395struct uip_stats {
1396 struct {
1397 uip_stats_t recv; /**< Number of received packets at the IP
1398 layer. */
1399 uip_stats_t sent; /**< Number of sent packets at the IP
1400 layer. */
1401 uip_stats_t forwarded;/**< Number of forwarded packets at the IP
1402 layer. */
1403 uip_stats_t drop; /**< Number of dropped packets at the IP
1404 layer. */
1405 uip_stats_t vhlerr; /**< Number of packets dropped due to wrong
1406 IP version or header length. */
1407 uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
1408 IP length, high byte. */
1409 uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
1410 IP length, low byte. */
1411 uip_stats_t fragerr; /**< Number of packets dropped since they
1412 were IP fragments. */
1413 uip_stats_t chkerr; /**< Number of packets dropped due to IP
1414 checksum errors. */
1415 uip_stats_t protoerr; /**< Number of packets dropped since they
1416 were neither ICMP, UDP nor TCP. */
1417 } ip; /**< IP statistics. */
1418 struct {
1419 uip_stats_t recv; /**< Number of received ICMP packets. */
1420 uip_stats_t sent; /**< Number of sent ICMP packets. */
1421 uip_stats_t drop; /**< Number of dropped ICMP packets. */
1422 uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
1423 type. */
1424 uip_stats_t chkerr; /**< Number of ICMP packets with a bad
1425 checksum. */
1426 } icmp; /**< ICMP statistics. */
1427#if UIP_TCP
1428 struct {
1429 uip_stats_t recv; /**< Number of received TCP segments. */
1430 uip_stats_t sent; /**< Number of sent TCP segments. */
1431 uip_stats_t drop; /**< Number of dropped TCP segments. */
1432 uip_stats_t chkerr; /**< Number of TCP segments with a bad
1433 checksum. */
1434 uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK
1435 number. */
1436 uip_stats_t rst; /**< Number of received TCP RST (reset) segments. */
1437 uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */
1438 uip_stats_t syndrop; /**< Number of dropped SYNs due to too few
1439 connections was available. */
1440 uip_stats_t synrst; /**< Number of SYNs for closed ports,
1441 triggering a RST. */
1442 } tcp; /**< TCP statistics. */
1443#endif
1444#if UIP_UDP
1445 struct {
1446 uip_stats_t drop; /**< Number of dropped UDP segments. */
1447 uip_stats_t recv; /**< Number of received UDP segments. */
1448 uip_stats_t sent; /**< Number of sent UDP segments. */
1449 uip_stats_t chkerr; /**< Number of UDP segments with a bad
1450 checksum. */
1451 } udp; /**< UDP statistics. */
1452#endif /* UIP_UDP */
1453#if UIP_CONF_IPV6
1454 struct {
1455 uip_stats_t drop; /**< Number of dropped ND6 packets. */
1456 uip_stats_t recv; /**< Number of received ND6 packets */
1457 uip_stats_t sent; /**< Number of sent ND6 packets */
1458 } nd6;
1459#endif /*UIP_CONF_IPV6*/
1460};
1461
1462
1463/*---------------------------------------------------------------------------*/
1464/* All the stuff below this point is internal to uIP and should not be
1465 * used directly by an application or by a device driver.
1466 */
1467/*---------------------------------------------------------------------------*/
1468
1469
1470
1471/* u8_t uip_flags:
1472 *
1473 * When the application is called, uip_flags will contain the flags
1474 * that are defined in this file. Please read below for more
1475 * information.
1476 */
1477extern u8_t uip_flags;
1478
1479/* The following flags may be set in the global variable uip_flags
1480 before calling the application callback. The UIP_ACKDATA,
1481 UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
1482 whereas the others are mutually exclusive. Note that these flags
1483 should *NOT* be accessed directly, but only through the uIP
1484 functions/macros. */
1485
1486#define UIP_ACKDATA 1 /* Signifies that the outstanding data was
1487 acked and the application should send
1488 out new data instead of retransmitting
1489 the last data. */
1490#define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
1491 us new data. */
1492#define UIP_REXMIT 4 /* Tells the application to retransmit the
1493 data that was last sent. */
1494#define UIP_POLL 8 /* Used for polling the application, to
1495 check if the application has data that
1496 it wants to send. */
1497#define UIP_CLOSE 16 /* The remote host has closed the
1498 connection, thus the connection has
1499 gone away. Or the application signals
1500 that it wants to close the
1501 connection. */
1502#define UIP_ABORT 32 /* The remote host has aborted the
1503 connection, thus the connection has
1504 gone away. Or the application signals
1505 that it wants to abort the
1506 connection. */
1507#define UIP_CONNECTED 64 /* We have got a connection from a remote
1508 host and have set up a new connection
1509 for it, or an active connection has
1510 been successfully established. */
1511
1512#define UIP_TIMEDOUT 128 /* The connection has been aborted due to
1513 too many retransmissions. */
1514
1515
1516/**
1517 * \brief process the options within a hop by hop or destination option header
1518 * \retval 0: nothing to send,
1519 * \retval 1: drop pkt
1520 * \retval 2: ICMP error message to send
1521*/
1522/*static u8_t
1523uip_ext_hdr_options_process(); */
1524
1525/* uip_process(flag):
1526 *
1527 * The actual uIP function which does all the work.
1528 */
1529void uip_process(u8_t flag);
1530
1531 /* The following flags are passed as an argument to the uip_process()
1532 function. They are used to distinguish between the two cases where
1533 uip_process() is called. It can be called either because we have
1534 incoming data that should be processed, or because the periodic
1535 timer has fired. These values are never used directly, but only in
1536 the macros defined in this file. */
1537
1538#define UIP_DATA 1 /* Tells uIP that there is incoming
1539 data in the uip_buf buffer. The
1540 length of the data is stored in the
1541 global variable uip_len. */
1542#define UIP_TIMER 2 /* Tells uIP that the periodic timer
1543 has fired. */
1544#define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should
1545 be polled. */
1546#define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram
1547 should be constructed in the
1548 uip_buf buffer. */
1549#if UIP_UDP
1550#define UIP_UDP_TIMER 5
1551#endif /* UIP_UDP */
1552
1553/* The TCP states used in the uip_conn->tcpstateflags. */
1554#define UIP_CLOSED 0
1555#define UIP_SYN_RCVD 1
1556#define UIP_SYN_SENT 2
1557#define UIP_ESTABLISHED 3
1558#define UIP_FIN_WAIT_1 4
1559#define UIP_FIN_WAIT_2 5
1560#define UIP_CLOSING 6
1561#define UIP_TIME_WAIT 7
1562#define UIP_LAST_ACK 8
1563#define UIP_TS_MASK 15
1564
1565#define UIP_STOPPED 16
1566
1567/* The TCP and IP headers. */
1568struct uip_tcpip_hdr {
1569#if UIP_CONF_IPV6
1570 /* IPv6 header. */
1571 u8_t vtc,
1572 tcflow;
1573 u16_t flow;
1574 u8_t len[2];
1575 u8_t proto, ttl;
1576 uip_ip6addr_t srcipaddr, destipaddr;
1577#else /* UIP_CONF_IPV6 */
1578 /* IPv4 header. */
1579 u8_t vhl,
1580 tos,
1581 len[2],
1582 ipid[2],
1583 ipoffset[2],
1584 ttl,
1585 proto;
1586 u16_t ipchksum;
1587 uip_ipaddr_t srcipaddr, destipaddr;
1588#endif /* UIP_CONF_IPV6 */
1589
1590 /* TCP header. */
1591 u16_t srcport,
1592 destport;
1593 u8_t seqno[4],
1594 ackno[4],
1595 tcpoffset,
1596 flags,
1597 wnd[2];
1598 u16_t tcpchksum;
1599 u8_t urgp[2];
1600 u8_t optdata[4];
1601};
1602
1603/* The ICMP and IP headers. */
1604struct uip_icmpip_hdr {
1605#if UIP_CONF_IPV6
1606 /* IPv6 header. */
1607 u8_t vtc,
1608 tcf;
1609 u16_t flow;
1610 u8_t len[2];
1611 u8_t proto, ttl;
1612 uip_ip6addr_t srcipaddr, destipaddr;
1613#else /* UIP_CONF_IPV6 */
1614 /* IPv4 header. */
1615 u8_t vhl,
1616 tos,
1617 len[2],
1618 ipid[2],
1619 ipoffset[2],
1620 ttl,
1621 proto;
1622 u16_t ipchksum;
1623 uip_ipaddr_t srcipaddr, destipaddr;
1624#endif /* UIP_CONF_IPV6 */
1625
1626 /* ICMP header. */
1627 u8_t type, icode;
1628 u16_t icmpchksum;
1629#if !UIP_CONF_IPV6
1630 u16_t id, seqno;
1631 u8_t payload[1];
1632#endif /* !UIP_CONF_IPV6 */
1633};
1634
1635
1636/* The UDP and IP headers. */
1637struct uip_udpip_hdr {
1638#if UIP_CONF_IPV6
1639 /* IPv6 header. */
1640 u8_t vtc,
1641 tcf;
1642 u16_t flow;
1643 u8_t len[2];
1644 u8_t proto, ttl;
1645 uip_ip6addr_t srcipaddr, destipaddr;
1646#else /* UIP_CONF_IPV6 */
1647 /* IP header. */
1648 u8_t vhl,
1649 tos,
1650 len[2],
1651 ipid[2],
1652 ipoffset[2],
1653 ttl,
1654 proto;
1655 u16_t ipchksum;
1656 uip_ipaddr_t srcipaddr, destipaddr;
1657#endif /* UIP_CONF_IPV6 */
1658
1659 /* UDP header. */
1660 u16_t srcport,
1661 destport;
1662 u16_t udplen;
1663 u16_t udpchksum;
1664};
1665
1666/*
1667 * In IPv6 the length of the L3 headers before the transport header is
1668 * not fixed, due to the possibility to include extension option headers
1669 * after the IP header. hence we split here L3 and L4 headers
1670 */
1671/* The IP header */
1672struct uip_ip_hdr {
1673#if UIP_CONF_IPV6
1674 /* IPV6 header */
1675 u8_t vtc;
1676 u8_t tcflow;
1677 u16_t flow;
1678 u8_t len[2];
1679 u8_t proto, ttl;
1680 uip_ip6addr_t srcipaddr, destipaddr;
1681#else /* UIP_CONF_IPV6 */
1682 /* IPV4 header */
1683 u8_t vhl,
1684 tos,
1685 len[2],
1686 ipid[2],
1687 ipoffset[2],
1688 ttl,
1689 proto;
1690 u16_t ipchksum;
1691 uip_ipaddr_t srcipaddr, destipaddr;
1692#endif /* UIP_CONF_IPV6 */
1693};
1694
1695
1696/*
1697 * IPv6 extension option headers: we are able to process
1698 * the 4 extension headers defined in RFC2460 (IPv6):
1699 * - Hop by hop option header, destination option header:
1700 * These two are not used by any core IPv6 protocol, hence
1701 * we just read them and go to the next. They convey options,
1702 * the options defined in RFC2460 are Pad1 and PadN, which do
1703 * some padding, and that we do not need to read (the length
1704 * field in the header is enough)
1705 * - Routing header: this one is most notably used by MIPv6,
1706 * which we do not implement, hence we just read it and go
1707 * to the next
1708 * - Fragmentation header: we read this header and are able to
1709 * reassemble packets
1710 *
1711 * We do not offer any means to send packets with extension headers
1712 *
1713 * We do not implement Authentication and ESP headers, which are
1714 * used in IPSec and defined in RFC4302,4303,4305,4385
1715 */
1716/* common header part */
1717struct uip_ext_hdr {
1718 u8_t next;
1719 u8_t len;
1720};
1721
1722/* Hop by Hop option header */
1723struct uip_hbho_hdr {
1724 u8_t next;
1725 u8_t len;
1726};
1727
1728/* destination option header */
1729struct uip_desto_hdr {
1730 u8_t next;
1731 u8_t len;
1732};
1733
1734/* We do not define structures for PAD1 and PADN options */
1735
1736/*
1737 * routing header
1738 * the routing header as 4 common bytes, then routing header type
1739 * specific data there are several types of routing header. Type 0 was
1740 * deprecated as per RFC5095 most notable other type is 2, used in
1741 * RFC3775 (MIPv6) here we do not implement MIPv6, so we just need to
1742 * parse the 4 first bytes
1743 */
1744struct uip_routing_hdr {
1745 u8_t next;
1746 u8_t len;
1747 u8_t routing_type;
1748 u8_t seg_left;
1749};
1750
1751/* fragmentation header */
1752struct uip_frag_hdr {
1753 u8_t next;
1754 u8_t res;
1755 u16_t offsetresmore;
1756 u32_t id;
1757};
1758
1759/*
1760 * an option within the destination or hop by hop option headers
1761 * it contains type an length, which is true for all options but PAD1
1762 */
1763struct uip_ext_hdr_opt {
1764 u8_t type;
1765 u8_t len;
1766};
1767
1768/* PADN option */
1769struct uip_ext_hdr_opt_padn {
1770 u8_t opt_type;
1771 u8_t opt_len;
1772};
1773
1774/* TCP header */
1775struct uip_tcp_hdr {
1776 u16_t srcport;
1777 u16_t destport;
1778 u8_t seqno[4];
1779 u8_t ackno[4];
1780 u8_t tcpoffset;
1781 u8_t flags;
1782 u8_t wnd[2];
1783 u16_t tcpchksum;
1784 u8_t urgp[2];
1785 u8_t optdata[4];
1786};
1787
1788/* The ICMP headers. */
1789struct uip_icmp_hdr {
1790 u8_t type, icode;
1791 u16_t icmpchksum;
1792#if !UIP_CONF_IPV6
1793 u16_t id, seqno;
1794#endif /* !UIP_CONF_IPV6 */
1795};
1796
1797
1798/* The UDP headers. */
1799struct uip_udp_hdr {
1800 u16_t srcport;
1801 u16_t destport;
1802 u16_t udplen;
1803 u16_t udpchksum;
1804};
1805
1806
1807/**
1808 * The buffer size available for user data in the \ref uip_buf buffer.
1809 *
1810 * This macro holds the available size for user data in the \ref
1811 * uip_buf buffer. The macro is intended to be used for checking
1812 * bounds of available user data.
1813 *
1814 * Example:
1815 \code
1816 snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
1817 \endcode
1818 *
1819 * \hideinitializer
1820 */
1821#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
1822#define UIP_APPDATA_PTR (void *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]
1823
1824#define UIP_PROTO_ICMP 1
1825#define UIP_PROTO_TCP 6
1826#define UIP_PROTO_UDP 17
1827#define UIP_PROTO_ICMP6 58
1828
1829
1830#if UIP_CONF_IPV6
1831/** @{ */
1832/** \brief extension headers types */
1833#define UIP_PROTO_HBHO 0
1834#define UIP_PROTO_DESTO 60
1835#define UIP_PROTO_ROUTING 43
1836#define UIP_PROTO_FRAG 44
1837#define UIP_PROTO_NONE 59
1838/** @} */
1839
1840/** @{ */
1841/** \brief Destination and Hop By Hop extension headers option types */
1842#define UIP_EXT_HDR_OPT_PAD1 0
1843#define UIP_EXT_HDR_OPT_PADN 1
1844/** @} */
1845
1846/** @{ */
1847/**
1848 * \brief Bitmaps for extension header processing
1849 *
1850 * When processing extension headers, we should record somehow which one we
1851 * see, because you cannot have twice the same header, except for destination
1852 * We store all this in one u8_t bitmap one bit for each header expected. The
1853 * order in the bitmap is the order recommended in RFC2460
1854 */
1855#define UIP_EXT_HDR_BITMAP_HBHO 0x01
1856#define UIP_EXT_HDR_BITMAP_DESTO1 0x02
1857#define UIP_EXT_HDR_BITMAP_ROUTING 0x04
1858#define UIP_EXT_HDR_BITMAP_FRAG 0x08
1859#define UIP_EXT_HDR_BITMAP_AH 0x10
1860#define UIP_EXT_HDR_BITMAP_ESP 0x20
1861#define UIP_EXT_HDR_BITMAP_DESTO2 0x40
1862/** @} */
1863
1864
1865#endif /* UIP_CONF_IPV6 */
1866
1867
1868/* Header sizes. */
1869#if UIP_CONF_IPV6
1870#define UIP_IPH_LEN 40
1871#define UIP_FRAGH_LEN 8
1872#else /* UIP_CONF_IPV6 */
1873#define UIP_IPH_LEN 20 /* Size of IP header */
1874#endif /* UIP_CONF_IPV6 */
1875
1876#define UIP_UDPH_LEN 8 /* Size of UDP header */
1877#define UIP_TCPH_LEN 20 /* Size of TCP header */
1878#ifdef UIP_IPH_LEN
1879#define UIP_ICMPH_LEN 4 /* Size of ICMP header */
1880#endif
1881#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP +
1882 * UDP
1883 * header */
1884#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP +
1885 * TCP
1886 * header */
1887#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
1888#define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* size of ICMP
1889 + IP header */
1890#define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN) /* size of L2
1891 + IP header */
1892#if UIP_CONF_IPV6
1893/**
1894 * The sums below are quite used in ND. When used for uip_buf, we
1895 * include link layer length when used for uip_len, we do not, hence
1896 * we need values with and without LLH_LEN we do not use capital
1897 * letters as these values are variable
1898 */
1899#define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len)
1900#define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
1901#define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len)
1902#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
1903#endif /*UIP_CONF_IPV6*/
1904
1905
1906#if UIP_FIXEDADDR
1907extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
1908#else /* UIP_FIXEDADDR */
1909extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
1910#endif /* UIP_FIXEDADDR */
1911extern const uip_ipaddr_t uip_broadcast_addr;
1912extern const uip_ipaddr_t uip_all_zeroes_addr;
1913
1914#if UIP_FIXEDETHADDR
1915extern const uip_lladdr_t uip_lladdr;
1916#else
1917extern uip_lladdr_t uip_lladdr;
1918#endif
1919
1920
1921
1922
1923#ifdef UIP_CONF_IPV6
1924/**
1925 * \brief Is IPv6 address a the unspecified address
1926 * a is of type uip_ipaddr_t
1927 */
1928#define uip_is_addr_unspecified(a) \
1929 ((((a)->u16[0]) == 0) && \
1930 (((a)->u16[1]) == 0) && \
1931 (((a)->u16[2]) == 0) && \
1932 (((a)->u16[3]) == 0) && \
1933 (((a)->u16[4]) == 0) && \
1934 (((a)->u16[5]) == 0) && \
1935 (((a)->u16[6]) == 0) && \
1936 (((a)->u16[7]) == 0))
1937
1938/** \brief Is IPv6 address a the link local all-nodes multicast address */
1939#define uip_is_addr_linklocal_allnodes_mcast(a) \
1940 ((((a)->u8[0]) == 0xff) && \
1941 (((a)->u8[1]) == 0x02) && \
1942 (((a)->u16[1]) == 0) && \
1943 (((a)->u16[2]) == 0) && \
1944 (((a)->u16[3]) == 0) && \
1945 (((a)->u16[4]) == 0) && \
1946 (((a)->u16[5]) == 0) && \
1947 (((a)->u16[6]) == 0) && \
1948 (((a)->u8[14]) == 0) && \
1949 (((a)->u8[15]) == 0x01))
1950
1951/** \brief set IP address a to unspecified */
1952#define uip_create_unspecified(a) uip_ip6addr(a, 0, 0, 0, 0, 0, 0, 0, 0)
1953
1954/** \brief set IP address a to the link local all-nodes multicast address */
1955#define uip_create_linklocal_allnodes_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001)
1956
1957/** \brief set IP address a to the link local all-routers multicast address */
1958#define uip_create_linklocal_allrouters_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002)
1959
1960/**
1961 * \brief is addr (a) a solicited node multicast address, see RFC3513
1962 * a is of type uip_ipaddr_t*
1963 */
1964#define uip_is_addr_solicited_node(a) \
1965 ((((a)->u8[0]) == 0xFF) && \
1966 (((a)->u8[1]) == 0x02) && \
1967 (((a)->u16[1]) == 0) && \
1968 (((a)->u16[2]) == 0) && \
1969 (((a)->u16[3]) == 0) && \
1970 (((a)->u16[4]) == 0) && \
1971 (((a)->u16[5]) == 1) && \
1972 (((a)->u8[12]) == 0xFF))
1973
1974/**
1975 * \briefput in b the solicited node address corresponding to address a
1976 * both a and b are of type uip_ipaddr_t*
1977 * */
1978#define uip_create_solicited_node(a, b) \
1979 (((b)->u8[0]) = 0xFF); \
1980 (((b)->u8[1]) = 0x02); \
1981 (((b)->u16[1]) = 0); \
1982 (((b)->u16[2]) = 0); \
1983 (((b)->u16[3]) = 0); \
1984 (((b)->u16[4]) = 0); \
1985 (((b)->u8[10]) = 0); \
1986 (((b)->u8[11]) = 0x01); \
1987 (((b)->u8[12]) = 0xFF); \
1988 (((b)->u8[13]) = ((a)->u8[13])); \
1989 (((b)->u16[7]) = ((a)->u16[7]))
1990
1991/**
1992 * \brief is addr (a) a link local unicast address, see RFC3513
1993 * i.e. is (a) on prefix FE80::/10
1994 * a is of type uip_ipaddr_t*
1995 */
1996#define uip_is_addr_link_local(a) \
1997 ((((a)->u8[0]) == 0xFE) && \
1998 (((a)->u8[1]) == 0x80))
1999
2000/**
2001 * \brief was addr (a) forged based on the mac address m
2002 * a type is uip_ipaddr_t
2003 * m type is uiplladdr_t
2004 */
2005#if UIP_CONF_LL_802154
2006#define uip_is_addr_mac_addr_based(a, m) \
2007 ((((a)->u8[8]) == (((m)->addr[0]) ^ 0x02)) && \
2008 (((a)->u8[9]) == (m)->addr[1]) && \
2009 (((a)->u8[10]) == (m)->addr[2]) && \
2010 (((a)->u8[11]) == (m)->addr[3]) && \
2011 (((a)->u8[12]) == (m)->addr[4]) && \
2012 (((a)->u8[13]) == (m)->addr[5]) && \
2013 (((a)->u8[14]) == (m)->addr[6]) && \
2014 (((a)->u8[15]) == (m)->addr[7]))
2015#else
2016
2017#define uip_is_addr_mac_addr_based(a, m) \
2018 ((((a)->u8[8]) == (((m)->addr[0]) | 0x02)) && \
2019 (((a)->u8[9]) == (m)->addr[1]) && \
2020 (((a)->u8[10]) == (m)->addr[2]) && \
2021 (((a)->u8[11]) == 0xff) && \
2022 (((a)->u8[12]) == 0xfe) && \
2023 (((a)->u8[13]) == (m)->addr[3]) && \
2024 (((a)->u8[14]) == (m)->addr[4]) && \
2025 (((a)->u8[15]) == (m)->addr[5]))
2026
2027#endif /*UIP_CONF_LL_802154*/
2028
2029/**
2030 * \brief is address a multicast address, see RFC 3513
2031 * a is of type uip_ipaddr_t*
2032 * */
2033#define uip_is_addr_mcast(a) \
2034 (((a)->u8[0]) == 0xFF)
2035
2036/**
2037 * \brief is group-id of multicast address a
2038 * the all nodes group-id
2039 */
2040#define uip_is_mcast_group_id_all_nodes(a) \
2041 ((((a)->u16[1]) == 0) && \
2042 (((a)->u16[2]) == 0) && \
2043 (((a)->u16[3]) == 0) && \
2044 (((a)->u16[4]) == 0) && \
2045 (((a)->u16[5]) == 0) && \
2046 (((a)->u16[6]) == 0) && \
2047 (((a)->u8[14]) == 0) && \
2048 (((a)->u8[15]) == 1))
2049
2050/**
2051 * \brief is group-id of multicast address a
2052 * the all routers group-id
2053 */
2054#define uip_is_mcast_group_id_all_routers(a) \
2055 ((((a)->u16[1]) == 0) && \
2056 (((a)->u16[2]) == 0) && \
2057 (((a)->u16[3]) == 0) && \
2058 (((a)->u16[4]) == 0) && \
2059 (((a)->u16[5]) == 0) && \
2060 (((a)->u16[6]) == 0) && \
2061 (((a)->u8[14]) == 0) && \
2062 (((a)->u8[15]) == 2))
2063
2064
2065#endif /*UIP_CONF_IPV6*/
2066
2067/**
2068 * Calculate the Internet checksum over a buffer.
2069 *
2070 * The Internet checksum is the one's complement of the one's
2071 * complement sum of all 16-bit words in the buffer.
2072 *
2073 * See RFC1071.
2074 *
2075 * \param buf A pointer to the buffer over which the checksum is to be
2076 * computed.
2077 *
2078 * \param len The length of the buffer over which the checksum is to
2079 * be computed.
2080 *
2081 * \return The Internet checksum of the buffer.
2082 */
2083u16_t uip_chksum(u16_t *buf, u16_t len);
2084
2085/**
2086 * Calculate the IP header checksum of the packet header in uip_buf.
2087 *
2088 * The IP header checksum is the Internet checksum of the 20 bytes of
2089 * the IP header.
2090 *
2091 * \return The IP header checksum of the IP header in the uip_buf
2092 * buffer.
2093 */
2094u16_t uip_ipchksum(void);
2095
2096/**
2097 * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
2098 *
2099 * The TCP checksum is the Internet checksum of data contents of the
2100 * TCP segment, and a pseudo-header as defined in RFC793.
2101 *
2102 * \return The TCP checksum of the TCP segment in uip_buf and pointed
2103 * to by uip_appdata.
2104 */
2105u16_t uip_tcpchksum(void);
2106
2107/**
2108 * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
2109 *
2110 * The UDP checksum is the Internet checksum of data contents of the
2111 * UDP segment, and a pseudo-header as defined in RFC768.
2112 *
2113 * \return The UDP checksum of the UDP segment in uip_buf and pointed
2114 * to by uip_appdata.
2115 */
2116u16_t uip_udpchksum(void);
2117
2118/**
2119 * Calculate the ICMP checksum of the packet in uip_buf.
2120 *
2121 * \return The ICMP checksum of the ICMP packet in uip_buf
2122 */
2123u16_t uip_icmp6chksum(void);
2124
2125
2126#endif /* __UIP_H__ */
2127
2128
2129/** @} */
2130
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/uip_arp.c b/lib/lufa/Projects/Webserver/Lib/uip/uip_arp.c
deleted file mode 100644
index fcb783b14..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/uip_arp.c
+++ /dev/null
@@ -1,432 +0,0 @@
1/**
2 * \addtogroup uip
3 * @{
4 */
5
6/**
7 * \defgroup uiparp uIP Address Resolution Protocol
8 * @{
9 *
10 * The Address Resolution Protocol ARP is used for mapping between IP
11 * addresses and link level addresses such as the Ethernet MAC
12 * addresses. ARP uses broadcast queries to ask for the link level
13 * address of a known IP address and the host which is configured with
14 * the IP address for which the query was meant, will respond with its
15 * link level address.
16 *
17 * \note This ARP implementation only supports Ethernet.
18 */
19
20/**
21 * \file
22 * Implementation of the ARP Address Resolution Protocol.
23 * \author Adam Dunkels <adam@dunkels.com>
24 *
25 */
26
27/*
28 * Copyright (c) 2001-2003, Adam Dunkels.
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. The name of the author may not be used to endorse or promote
40 * products derived from this software without specific prior
41 * written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
44 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
45 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
47 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
49 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
51 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
52 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
53 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 *
55 * This file is part of the uIP TCP/IP stack.
56 *
57 * $Id: uip_arp.c,v 1.5 2008/02/07 01:35:00 adamdunkels Exp $
58 *
59 */
60
61
62#include "uip_arp.h"
63
64#include <string.h>
65
66struct arp_hdr {
67 struct uip_eth_hdr ethhdr;
68 u16_t hwtype;
69 u16_t protocol;
70 u8_t hwlen;
71 u8_t protolen;
72 u16_t opcode;
73 struct uip_eth_addr shwaddr;
74 uip_ipaddr_t sipaddr;
75 struct uip_eth_addr dhwaddr;
76 uip_ipaddr_t dipaddr;
77};
78
79struct ethip_hdr {
80 struct uip_eth_hdr ethhdr;
81 /* IP header. */
82 u8_t vhl,
83 tos,
84 len[2],
85 ipid[2],
86 ipoffset[2],
87 ttl,
88 proto;
89 u16_t ipchksum;
90 uip_ipaddr_t srcipaddr, destipaddr;
91};
92
93#define ARP_REQUEST 1
94#define ARP_REPLY 2
95
96#define ARP_HWTYPE_ETH 1
97
98struct arp_entry {
99 uip_ipaddr_t ipaddr;
100 struct uip_eth_addr ethaddr;
101 u8_t time;
102};
103
104static const struct uip_eth_addr broadcast_ethaddr =
105 {{0xff,0xff,0xff,0xff,0xff,0xff}};
106static const u16_t broadcast_ipaddr[2] = {0xffff,0xffff};
107
108static struct arp_entry arp_table[UIP_ARPTAB_SIZE];
109static uip_ipaddr_t ipaddr;
110static u8_t i, c;
111
112static u8_t arptime;
113static u8_t tmpage;
114
115#define BUF ((struct arp_hdr *)&uip_buf[0])
116#define IPBUF ((struct ethip_hdr *)&uip_buf[0])
117
118#define DEBUG 0
119#if DEBUG
120#include <stdio.h>
121#define PRINTF(...) printf(__VA_ARGS__)
122#else
123#define PRINTF(...)
124#endif
125
126/*-----------------------------------------------------------------------------------*/
127/**
128 * Initialize the ARP module.
129 *
130 */
131/*-----------------------------------------------------------------------------------*/
132void
133uip_arp_init(void)
134{
135 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
136 memset(&arp_table[i].ipaddr, 0, 4);
137 }
138}
139/*-----------------------------------------------------------------------------------*/
140/**
141 * Periodic ARP processing function.
142 *
143 * This function performs periodic timer processing in the ARP module
144 * and should be called at regular intervals. The recommended interval
145 * is 10 seconds between the calls.
146 *
147 */
148/*-----------------------------------------------------------------------------------*/
149void
150uip_arp_timer(void)
151{
152 struct arp_entry *tabptr = NULL;
153
154 ++arptime;
155 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
156 tabptr = &arp_table[i];
157 if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr) &&
158 arptime - tabptr->time >= UIP_ARP_MAXAGE) {
159 memset(&tabptr->ipaddr, 0, 4);
160 }
161 }
162
163}
164/*-----------------------------------------------------------------------------------*/
165static void
166uip_arp_update(uip_ipaddr_t *ipaddr, struct uip_eth_addr *ethaddr)
167{
168 register struct arp_entry *tabptr = NULL;
169 /* Walk through the ARP mapping table and try to find an entry to
170 update. If none is found, the IP -> MAC address mapping is
171 inserted in the ARP table. */
172 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
173
174 tabptr = &arp_table[i];
175 /* Only check those entries that are actually in use. */
176 if(!uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {
177
178 /* Check if the source IP address of the incoming packet matches
179 the IP address in this ARP table entry. */
180 if(uip_ipaddr_cmp(ipaddr, &tabptr->ipaddr)) {
181
182 /* An old entry found, update this and return. */
183 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
184 tabptr->time = arptime;
185
186 return;
187 }
188 }
189 }
190
191 /* If we get here, no existing ARP table entry was found, so we
192 create one. */
193
194 /* First, we try to find an unused entry in the ARP table. */
195 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
196 tabptr = &arp_table[i];
197 if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) {
198 break;
199 }
200 }
201
202 /* If no unused entry is found, we try to find the oldest entry and
203 throw it away. */
204 if(i == UIP_ARPTAB_SIZE) {
205 tmpage = 0;
206 c = 0;
207 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
208 tabptr = &arp_table[i];
209 if(arptime - tabptr->time > tmpage) {
210 tmpage = arptime - tabptr->time;
211 c = i;
212 }
213 }
214 i = c;
215 tabptr = &arp_table[i];
216 }
217
218 /* Now, i is the ARP table entry which we will fill with the new
219 information. */
220 uip_ipaddr_copy(&tabptr->ipaddr, ipaddr);
221 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
222 tabptr->time = arptime;
223}
224/*-----------------------------------------------------------------------------------*/
225/**
226 * ARP processing for incoming IP packets
227 *
228 * This function should be called by the device driver when an IP
229 * packet has been received. The function will check if the address is
230 * in the ARP cache, and if so the ARP cache entry will be
231 * refreshed. If no ARP cache entry was found, a new one is created.
232 *
233 * This function expects an IP packet with a prepended Ethernet header
234 * in the uip_buf[] buffer, and the length of the packet in the global
235 * variable uip_len.
236 */
237/*-----------------------------------------------------------------------------------*/
238#if 0
239void
240uip_arp_ipin(void)
241{
242 uip_len -= sizeof(struct uip_eth_hdr);
243
244 /* Only insert/update an entry if the source IP address of the
245 incoming IP packet comes from a host on the local network. */
246 if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
247 (uip_hostaddr[0] & uip_netmask[0])) {
248 return;
249 }
250 if((IPBUF->srcipaddr[1] & uip_netmask[1]) !=
251 (uip_hostaddr[1] & uip_netmask[1])) {
252 return;
253 }
254 uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
255
256 return;
257}
258#endif /* 0 */
259/*-----------------------------------------------------------------------------------*/
260/**
261 * ARP processing for incoming ARP packets.
262 *
263 * This function should be called by the device driver when an ARP
264 * packet has been received. The function will act differently
265 * depending on the ARP packet type: if it is a reply for a request
266 * that we previously sent out, the ARP cache will be filled in with
267 * the values from the ARP reply. If the incoming ARP packet is an ARP
268 * request for our IP address, an ARP reply packet is created and put
269 * into the uip_buf[] buffer.
270 *
271 * When the function returns, the value of the global variable uip_len
272 * indicates whether the device driver should send out a packet or
273 * not. If uip_len is zero, no packet should be sent. If uip_len is
274 * non-zero, it contains the length of the outbound packet that is
275 * present in the uip_buf[] buffer.
276 *
277 * This function expects an ARP packet with a prepended Ethernet
278 * header in the uip_buf[] buffer, and the length of the packet in the
279 * global variable uip_len.
280 */
281/*-----------------------------------------------------------------------------------*/
282void
283uip_arp_arpin(void)
284{
285 if(uip_len < sizeof(struct arp_hdr)) {
286 uip_len = 0;
287 return;
288 }
289 uip_len = 0;
290
291 switch(BUF->opcode) {
292 case HTONS(ARP_REQUEST):
293 /* ARP request. If it asked for our address, we send out a
294 reply. */
295 /* if(BUF->dipaddr[0] == uip_hostaddr[0] &&
296 BUF->dipaddr[1] == uip_hostaddr[1]) {*/
297 PRINTF("uip_arp_arpin: request for %d.%d.%d.%d (we are %d.%d.%d.%d)\n",
298 BUF->dipaddr.u8[0], BUF->dipaddr.u8[1],
299 BUF->dipaddr.u8[2], BUF->dipaddr.u8[3],
300 uip_hostaddr.u8[0], uip_hostaddr.u8[1],
301 uip_hostaddr.u8[2], uip_hostaddr.u8[3]);
302 if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {
303 /* First, we register the one who made the request in our ARP
304 table, since it is likely that we will do more communication
305 with this host in the future. */
306 uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
307
308 BUF->opcode = HTONS(ARP_REPLY);
309
310 memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
311 memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
312 memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
313 memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
314
315 uip_ipaddr_copy(&BUF->dipaddr, &BUF->sipaddr);
316 uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
317
318 BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
319 uip_len = sizeof(struct arp_hdr);
320 }
321 break;
322 case HTONS(ARP_REPLY):
323 /* ARP reply. We insert or update the ARP table if it was meant
324 for us. */
325 if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) {
326 uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
327 }
328 break;
329 }
330
331 return;
332}
333/*-----------------------------------------------------------------------------------*/
334/**
335 * Prepend Ethernet header to an outbound IP packet and see if we need
336 * to send out an ARP request.
337 *
338 * This function should be called before sending out an IP packet. The
339 * function checks the destination IP address of the IP packet to see
340 * what Ethernet MAC address that should be used as a destination MAC
341 * address on the Ethernet.
342 *
343 * If the destination IP address is in the local network (determined
344 * by logical ANDing of netmask and our IP address), the function
345 * checks the ARP cache to see if an entry for the destination IP
346 * address is found. If so, an Ethernet header is prepended and the
347 * function returns. If no ARP cache entry is found for the
348 * destination IP address, the packet in the uip_buf[] is replaced by
349 * an ARP request packet for the IP address. The IP packet is dropped
350 * and it is assumed that they higher level protocols (e.g., TCP)
351 * eventually will retransmit the dropped packet.
352 *
353 * If the destination IP address is not on the local network, the IP
354 * address of the default router is used instead.
355 *
356 * When the function returns, a packet is present in the uip_buf[]
357 * buffer, and the length of the packet is in the global variable
358 * uip_len.
359 */
360/*-----------------------------------------------------------------------------------*/
361void
362uip_arp_out(void)
363{
364 struct arp_entry *tabptr = NULL;
365
366 /* Find the destination IP address in the ARP table and construct
367 the Ethernet header. If the destination IP address isn't on the
368 local network, we use the default router's IP address instead.
369
370 If not ARP table entry is found, we overwrite the original IP
371 packet with an ARP request for the IP address. */
372
373 /* First check if destination is a local broadcast. */
374 if(uip_ipaddr_cmp(&IPBUF->destipaddr, &uip_broadcast_addr)) {
375 memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);
376 } else {
377 /* Check if the destination address is on the local network. */
378 if(!uip_ipaddr_maskcmp(&IPBUF->destipaddr, &uip_hostaddr, &uip_netmask)) {
379 /* Destination address was not on the local network, so we need to
380 use the default router's IP address instead of the destination
381 address when determining the MAC address. */
382 uip_ipaddr_copy(&ipaddr, &uip_draddr);
383 } else {
384 /* Else, we use the destination IP address. */
385 uip_ipaddr_copy(&ipaddr, &IPBUF->destipaddr);
386 }
387
388 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
389 tabptr = &arp_table[i];
390 if(uip_ipaddr_cmp(&ipaddr, &tabptr->ipaddr)) {
391 break;
392 }
393 }
394
395 if(i == UIP_ARPTAB_SIZE) {
396 /* The destination address was not in our ARP table, so we
397 overwrite the IP packet with an ARP request. */
398
399 memset(BUF->ethhdr.dest.addr, 0xff, 6);
400 memset(BUF->dhwaddr.addr, 0x00, 6);
401 memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
402 memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
403
404 uip_ipaddr_copy(&BUF->dipaddr, &ipaddr);
405 uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
406 BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */
407 BUF->hwtype = HTONS(ARP_HWTYPE_ETH);
408 BUF->protocol = HTONS(UIP_ETHTYPE_IP);
409 BUF->hwlen = 6;
410 BUF->protolen = 4;
411 BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
412
413 uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
414
415 uip_len = sizeof(struct arp_hdr);
416 return;
417 }
418
419 /* Build an ethernet header. */
420 memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
421 }
422 memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
423
424 IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);
425
426 uip_len += sizeof(struct uip_eth_hdr);
427}
428/*-----------------------------------------------------------------------------------*/
429
430/** @} */
431/** @} */
432
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/uip_arp.h b/lib/lufa/Projects/Webserver/Lib/uip/uip_arp.h
deleted file mode 100644
index 4e78ce7b7..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/uip_arp.h
+++ /dev/null
@@ -1,146 +0,0 @@
1/**
2 * \addtogroup uip
3 * @{
4 */
5
6/**
7 * \addtogroup uiparp
8 * @{
9 */
10
11/**
12 * \file
13 * Macros and definitions for the ARP module.
14 * \author Adam Dunkels <adam@dunkels.com>
15 */
16
17
18/*
19 * Copyright (c) 2001-2003, Adam Dunkels.
20 * All rights reserved.
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 * 1. Redistributions of source code must retain the above copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. The name of the author may not be used to endorse or promote
31 * products derived from this software without specific prior
32 * written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
35 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
38 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 * This file is part of the uIP TCP/IP stack.
47 *
48 * $Id: uip_arp.h,v 1.2 2006/08/26 23:58:45 oliverschmidt Exp $
49 *
50 */
51
52#ifndef __UIP_ARP_H__
53#define __UIP_ARP_H__
54
55#include "uip.h"
56
57
58extern struct uip_eth_addr uip_ethaddr;
59
60/**
61 * The Ethernet header.
62 */
63struct uip_eth_hdr {
64 struct uip_eth_addr dest;
65 struct uip_eth_addr src;
66 u16_t type;
67};
68
69#define UIP_ETHTYPE_ARP 0x0806
70#define UIP_ETHTYPE_IP 0x0800
71#define UIP_ETHTYPE_IPV6 0x86dd
72
73
74/* The uip_arp_init() function must be called before any of the other
75 ARP functions. */
76void uip_arp_init(void);
77
78/* The uip_arp_ipin() function should be called whenever an IP packet
79 arrives from the Ethernet. This function refreshes the ARP table or
80 inserts a new mapping if none exists. The function assumes that an
81 IP packet with an Ethernet header is present in the uip_buf buffer
82 and that the length of the packet is in the uip_len variable. */
83/*void uip_arp_ipin(void);*/
84#define uip_arp_ipin()
85
86/* The uip_arp_arpin() should be called when an ARP packet is received
87 by the Ethernet driver. This function also assumes that the
88 Ethernet frame is present in the uip_buf buffer. When the
89 uip_arp_arpin() function returns, the contents of the uip_buf
90 buffer should be sent out on the Ethernet if the uip_len variable
91 is > 0. */
92void uip_arp_arpin(void);
93
94/* The uip_arp_out() function should be called when an IP packet
95 should be sent out on the Ethernet. This function creates an
96 Ethernet header before the IP header in the uip_buf buffer. The
97 Ethernet header will have the correct Ethernet MAC destination
98 address filled in if an ARP table entry for the destination IP
99 address (or the IP address of the default router) is present. If no
100 such table entry is found, the IP packet is overwritten with an ARP
101 request and we rely on TCP to retransmit the packet that was
102 overwritten. In any case, the uip_len variable holds the length of
103 the Ethernet frame that should be transmitted. */
104void uip_arp_out(void);
105
106/* The uip_arp_timer() function should be called every ten seconds. It
107 is responsible for flushing old entries in the ARP table. */
108void uip_arp_timer(void);
109
110/** @} */
111
112/**
113 * \addtogroup uipconffunc
114 * @{
115 */
116
117
118/**
119 * Specifiy the Ethernet MAC address.
120 *
121 * The ARP code needs to know the MAC address of the Ethernet card in
122 * order to be able to respond to ARP queries and to generate working
123 * Ethernet headers.
124 *
125 * \note This macro only specifies the Ethernet MAC address to the ARP
126 * code. It cannot be used to change the MAC address of the Ethernet
127 * card.
128 *
129 * \param eaddr A pointer to a struct uip_eth_addr containing the
130 * Ethernet MAC address of the Ethernet card.
131 *
132 * \hideinitializer
133 */
134#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \
135 uip_ethaddr.addr[1] = eaddr.addr[1];\
136 uip_ethaddr.addr[2] = eaddr.addr[2];\
137 uip_ethaddr.addr[3] = eaddr.addr[3];\
138 uip_ethaddr.addr[4] = eaddr.addr[4];\
139 uip_ethaddr.addr[5] = eaddr.addr[5];} while(0)
140
141/** @} */
142
143
144#endif /* __UIP_ARP_H__ */
145/** @} */
146
diff --git a/lib/lufa/Projects/Webserver/Lib/uip/uipopt.h b/lib/lufa/Projects/Webserver/Lib/uip/uipopt.h
deleted file mode 100644
index 520c03f25..000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/uipopt.h
+++ /dev/null
@@ -1,740 +0,0 @@
1/**
2 * \addtogroup uip
3 * @{
4 */
5
6/**
7 * \defgroup uipopt Configuration options for uIP
8 * @{
9 *
10 * uIP is configured using the per-project configuration file
11 * "uipopt.h". This file contains all compile-time options for uIP and
12 * should be tweaked to match each specific project. The uIP
13 * distribution contains a documented example "uipopt.h" that can be
14 * copied and modified for each project.
15 */
16
17/**
18 * \file
19 * Configuration options for uIP.
20 * \author Adam Dunkels <adam@dunkels.com>
21 *
22 * This file is used for tweaking various configuration options for
23 * uIP. You should make a copy of this file into one of your project's
24 * directories instead of editing this example "uipopt.h" file that
25 * comes with the uIP distribution.
26 */
27
28/*
29 * Copyright (c) 2001-2003, Adam Dunkels.
30 * All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. The name of the author may not be used to endorse or promote
41 * products derived from this software without specific prior
42 * written permission.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
45 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
46 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
48 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
50 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
52 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
53 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
54 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 *
56 * This file is part of the uIP TCP/IP stack.
57 *
58 * $Id: uipopt.h,v 1.11 2009/04/10 00:37:48 adamdunkels Exp $
59 *
60 */
61
62#ifndef __UIPOPT_H__
63#define __UIPOPT_H__
64
65#include "Config/AppConfig.h"
66
67#ifndef UIP_LITTLE_ENDIAN
68#define UIP_LITTLE_ENDIAN 3412
69#endif /* UIP_LITTLE_ENDIAN */
70#ifndef UIP_BIG_ENDIAN
71#define UIP_BIG_ENDIAN 1234
72#endif /* UIP_BIG_ENDIAN */
73
74/*------------------------------------------------------------------------------*/
75
76/**
77 * \defgroup uipoptstaticconf Static configuration options
78 * @{
79 *
80 * These configuration options can be used for setting the IP address
81 * settings statically, but only if UIP_FIXEDADDR is set to 1. The
82 * configuration options for a specific node includes IP address,
83 * netmask and default router as well as the Ethernet address. The
84 * netmask, default router and Ethernet address are applicable only
85 * if uIP should be run over Ethernet.
86 *
87 * This options are meaningful only for the IPv4 code.
88 *
89 * All of these should be changed to suit your project.
90 */
91
92/**
93 * Determines if uIP should use a fixed IP address or not.
94 *
95 * If uIP should use a fixed IP address, the settings are set in the
96 * uipopt.h file. If not, the macros uip_sethostaddr(),
97 * uip_setdraddr() and uip_setnetmask() should be used instead.
98 *
99 * \hideinitializer
100 */
101#define UIP_FIXEDADDR 0
102
103/**
104 * Ping IP address assignment.
105 *
106 * uIP uses a "ping" packets for setting its own IP address if this
107 * option is set. If so, uIP will start with an empty IP address and
108 * the destination IP address of the first incoming "ping" (ICMP echo)
109 * packet will be used for setting the hosts IP address.
110 *
111 * \note This works only if UIP_FIXEDADDR is 0.
112 *
113 * \hideinitializer
114 */
115#ifdef UIP_CONF_PINGADDRCONF
116#define UIP_PINGADDRCONF UIP_CONF_PINGADDRCONF
117#else /* UIP_CONF_PINGADDRCONF */
118#define UIP_PINGADDRCONF 0
119#endif /* UIP_CONF_PINGADDRCONF */
120
121
122/**
123 * Specifies if the uIP ARP module should be compiled with a fixed
124 * Ethernet MAC address or not.
125 *
126 * If this configuration option is 0, the macro uip_setethaddr() can
127 * be used to specify the Ethernet address at run-time.
128 *
129 * \hideinitializer
130 */
131#define UIP_FIXEDETHADDR 0
132
133/** @} */
134/*------------------------------------------------------------------------------*/
135/**
136 * \defgroup uipoptip IP configuration options
137 * @{
138 *
139 */
140/**
141 * The IP TTL (time to live) of IP packets sent by uIP.
142 *
143 * This should normally not be changed.
144 */
145#define UIP_TTL 64
146
147/**
148 * The maximum time an IP fragment should wait in the reassembly
149 * buffer before it is dropped.
150 *
151 */
152#define UIP_REASS_MAXAGE 60 /*60s*/
153
154/**
155 * Turn on support for IP packet reassembly.
156 *
157 * uIP supports reassembly of fragmented IP packets. This features
158 * requires an additional amount of RAM to hold the reassembly buffer
159 * and the reassembly code size is approximately 700 bytes. The
160 * reassembly buffer is of the same size as the uip_buf buffer
161 * (configured by UIP_BUFSIZE).
162 *
163 * \note IP packet reassembly is not heavily tested.
164 *
165 * \hideinitializer
166 */
167#ifdef UIP_CONF_REASSEMBLY
168#define UIP_REASSEMBLY UIP_CONF_REASSEMBLY
169#else /* UIP_CONF_REASSEMBLY */
170#define UIP_REASSEMBLY 0
171#endif /* UIP_CONF_REASSEMBLY */
172/** @} */
173
174/*------------------------------------------------------------------------------*/
175/**
176 * \defgroup uipoptipv6 IPv6 configuration options
177 * @{
178 *
179 */
180
181/** The maximum transmission unit at the IP Layer*/
182#define UIP_LINK_MTU 1280
183
184#ifndef UIP_CONF_IPV6
185/** Do we use IPv6 or not (default: no) */
186#define UIP_CONF_IPV6 0
187#endif
188
189#ifndef UIP_CONF_IPV6_QUEUE_PKT
190/** Do we do per %neighbor queuing during address resolution (default: no) */
191#define UIP_CONF_IPV6_QUEUE_PKT 0
192#endif
193
194#ifndef UIP_CONF_IPV6_CHECKS
195/** Do we do IPv6 consistency checks (highly recommended, default: yes) */
196#define UIP_CONF_IPV6_CHECKS 1
197#endif
198
199#ifndef UIP_CONF_IPV6_REASSEMBLY
200/** Do we do IPv6 fragmentation (default: no) */
201#define UIP_CONF_IPV6_REASSEMBLY 0
202#endif
203
204#ifndef UIP_CONF_NETIF_MAX_ADDRESSES
205/** Default number of IPv6 addresses associated to the node's interface */
206#define UIP_CONF_NETIF_MAX_ADDRESSES 3
207#endif
208
209#ifndef UIP_CONF_ND6_MAX_PREFIXES
210/** Default number of IPv6 prefixes associated to the node's interface */
211#define UIP_CONF_ND6_MAX_PREFIXES 3
212#endif
213
214#ifndef UIP_CONF_ND6_MAX_NEIGHBORS
215/** Default number of neighbors that can be stored in the %neighbor cache */
216#define UIP_CONF_ND6_MAX_NEIGHBORS 4
217#endif
218
219#ifndef UIP_CONF_ND6_MAX_DEFROUTERS
220/** Minimum number of default routers */
221#define UIP_CONF_ND6_MAX_DEFROUTERS 2
222#endif
223/** @} */
224
225/*------------------------------------------------------------------------------*/
226/**
227 * \defgroup uipoptudp UDP configuration options
228 * @{
229 *
230 * \note The UDP support in uIP is still not entirely complete; there
231 * is no support for sending or receiving broadcast or multicast
232 * packets, but it works well enough to support a number of vital
233 * applications such as DNS queries, though
234 */
235
236/**
237 * Toggles whether UDP support should be compiled in or not.
238 *
239 * \hideinitializer
240 */
241#ifdef UIP_CONF_UDP
242#define UIP_UDP UIP_CONF_UDP
243#else /* UIP_CONF_UDP */
244#define UIP_UDP 1
245#endif /* UIP_CONF_UDP */
246
247/**
248 * Toggles if UDP checksums should be used or not.
249 *
250 * \note Support for UDP checksums is currently not included in uIP,
251 * so this option has no function.
252 *
253 * \hideinitializer
254 */
255#ifdef UIP_CONF_UDP_CHECKSUMS
256#define UIP_UDP_CHECKSUMS UIP_CONF_UDP_CHECKSUMS
257#else
258#define UIP_UDP_CHECKSUMS 0
259#endif
260
261/**
262 * The maximum amount of concurrent UDP connections.
263 *
264 * \hideinitializer
265 */
266#ifdef UIP_CONF_UDP_CONNS
267#define UIP_UDP_CONNS UIP_CONF_UDP_CONNS
268#else /* UIP_CONF_UDP_CONNS */
269#define UIP_UDP_CONNS 10
270#endif /* UIP_CONF_UDP_CONNS */
271
272/**
273 * The name of the function that should be called when UDP datagrams arrive.
274 *
275 * \hideinitializer
276 */
277
278
279/** @} */
280/*------------------------------------------------------------------------------*/
281/**
282 * \defgroup uipopttcp TCP configuration options
283 * @{
284 */
285
286/**
287 * Toggles whether TCP support should be compiled in or not.
288 *
289 * \hideinitializer
290 */
291#ifdef UIP_CONF_TCP
292#define UIP_TCP UIP_CONF_TCP
293#else /* UIP_CONF_TCP */
294#define UIP_TCP 1
295#endif /* UIP_CONF_TCP */
296
297/**
298 * Determines if support for opening connections from uIP should be
299 * compiled in.
300 *
301 * If the applications that are running on top of uIP for this project
302 * do not need to open outgoing TCP connections, this configuration
303 * option can be turned off to reduce the code size of uIP.
304 *
305 * \hideinitializer
306 */
307#ifndef UIP_CONF_ACTIVE_OPEN
308#define UIP_ACTIVE_OPEN 1
309#else /* UIP_CONF_ACTIVE_OPEN */
310#define UIP_ACTIVE_OPEN UIP_CONF_ACTIVE_OPEN
311#endif /* UIP_CONF_ACTIVE_OPEN */
312
313/**
314 * The maximum number of simultaneously open TCP connections.
315 *
316 * Since the TCP connections are statically allocated, turning this
317 * configuration knob down results in less RAM used. Each TCP
318 * connection requires approximately 30 bytes of memory.
319 *
320 * \hideinitializer
321 */
322#ifndef UIP_CONF_MAX_CONNECTIONS
323#define UIP_CONNS 10
324#else /* UIP_CONF_MAX_CONNECTIONS */
325#define UIP_CONNS UIP_CONF_MAX_CONNECTIONS
326#endif /* UIP_CONF_MAX_CONNECTIONS */
327
328
329/**
330 * The maximum number of simultaneously listening TCP ports.
331 *
332 * Each listening TCP port requires 2 bytes of memory.
333 *
334 * \hideinitializer
335 */
336#ifndef UIP_CONF_MAX_LISTENPORTS
337#define UIP_LISTENPORTS 20
338#else /* UIP_CONF_MAX_LISTENPORTS */
339#define UIP_LISTENPORTS UIP_CONF_MAX_LISTENPORTS
340#endif /* UIP_CONF_MAX_LISTENPORTS */
341
342/**
343 * Determines if support for TCP urgent data notification should be
344 * compiled in.
345 *
346 * Urgent data (out-of-band data) is a rarely used TCP feature that
347 * very seldom would be required.
348 *
349 * \hideinitializer
350 */
351#if !defined(UIP_URGDATA)
352#define UIP_URGDATA 0
353#endif
354
355/**
356 * The initial retransmission timeout counted in timer pulses.
357 *
358 * This should not be changed.
359 */
360#if !defined(UIP_RTO)
361#define UIP_RTO 3
362#endif
363
364/**
365 * The maximum number of times a segment should be retransmitted
366 * before the connection should be aborted.
367 *
368 * This should not be changed.
369 */
370#if !defined(UIP_MAXRTX)
371#define UIP_MAXRTX 8
372#endif
373
374/**
375 * The maximum number of times a SYN segment should be retransmitted
376 * before a connection request should be deemed to have been
377 * unsuccessful.
378 *
379 * This should not need to be changed.
380 */
381#if !defined(UIP_MAXSYNRTX)
382#define UIP_MAXSYNRTX 5
383#endif
384
385/**
386 * The TCP maximum segment size.
387 *
388 * This is should not be to set to more than
389 * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN.
390 */
391#ifdef UIP_CONF_TCP_MSS
392#define UIP_TCP_MSS UIP_CONF_TCP_MSS
393#else
394#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
395#endif
396
397/**
398 * The size of the advertised receiver's window.
399 *
400 * Should be set low (i.e., to the size of the uip_buf buffer) if the
401 * application is slow to process incoming data, or high (32768 bytes)
402 * if the application processes data quickly.
403 *
404 * \hideinitializer
405 */
406#ifndef UIP_CONF_RECEIVE_WINDOW
407#define UIP_RECEIVE_WINDOW UIP_TCP_MSS
408#else
409#define UIP_RECEIVE_WINDOW UIP_CONF_RECEIVE_WINDOW
410#endif
411
412/**
413 * How long a connection should stay in the TIME_WAIT state.
414 *
415 * This configuration option has no real implication, and it should be
416 * left untouched.
417 */
418#define UIP_TIME_WAIT_TIMEOUT 120
419
420
421/** @} */
422/*------------------------------------------------------------------------------*/
423/**
424 * \defgroup uipoptarp ARP configuration options
425 * @{
426 */
427
428/**
429 * The size of the ARP table.
430 *
431 * This option should be set to a larger value if this uIP node will
432 * have many connections from the local network.
433 *
434 * \hideinitializer
435 */
436#ifdef UIP_CONF_ARPTAB_SIZE
437#define UIP_ARPTAB_SIZE UIP_CONF_ARPTAB_SIZE
438#else
439#define UIP_ARPTAB_SIZE 8
440#endif
441
442/**
443 * The maximum age of ARP table entries measured in 10ths of seconds.
444 *
445 * An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD
446 * default).
447 */
448#define UIP_ARP_MAXAGE 120
449
450
451/** @} */
452
453/*------------------------------------------------------------------------------*/
454
455/**
456 * \defgroup uipoptmac layer 2 options (for ipv6)
457 * @{
458 */
459
460#define UIP_DEFAULT_PREFIX_LEN 64
461
462/** @} */
463
464/*------------------------------------------------------------------------------*/
465
466/**
467 * \defgroup uipoptsics 6lowpan options (for ipv6)
468 * @{
469 */
470/**
471 * Timeout for packet reassembly at the 6lowpan layer
472 * (should be < 60s)
473 */
474#ifdef SICSLOWPAN_CONF_MAXAGE
475#define SICSLOWPAN_REASS_MAXAGE SICSLOWPAN_CONF_MAXAGE
476#else
477#define SICSLOWPAN_REASS_MAXAGE 20
478#endif
479
480/**
481 * Do we compress the IP header or not (default: no)
482 */
483#ifndef SICSLOWPAN_CONF_COMPRESSION
484#define SICSLOWPAN_CONF_COMPRESSION 0
485#endif
486
487/**
488 * If we use IPHC compression, how many address contexts do we support
489 */
490#ifndef SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS
491#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 1
492#endif
493
494/**
495 * Do we support 6lowpan fragmentation
496 */
497#ifndef SICSLOWPAN_CONF_FRAG
498#define SICSLOWPAN_CONF_FRAG 0
499#endif
500
501/** @} */
502
503/*------------------------------------------------------------------------------*/
504
505/**
506 * \defgroup uipoptgeneral General configuration options
507 * @{
508 */
509
510/**
511 * The size of the uIP packet buffer.
512 *
513 * The uIP packet buffer should not be smaller than 60 bytes, and does
514 * not need to be larger than 1514 bytes. Lower size results in lower
515 * TCP throughput, larger size results in higher TCP throughput.
516 *
517 * \hideinitializer
518 */
519#ifndef UIP_CONF_BUFFER_SIZE
520#define UIP_BUFSIZE UIP_LINK_MTU + UIP_LLH_LEN
521#else /* UIP_CONF_BUFFER_SIZE */
522#define UIP_BUFSIZE UIP_CONF_BUFFER_SIZE
523#endif /* UIP_CONF_BUFFER_SIZE */
524
525
526/**
527 * Determines if statistics support should be compiled in.
528 *
529 * The statistics is useful for debugging and to show the user.
530 *
531 * \hideinitializer
532 */
533#ifndef UIP_CONF_STATISTICS
534#define UIP_STATISTICS 0
535#else /* UIP_CONF_STATISTICS */
536#define UIP_STATISTICS UIP_CONF_STATISTICS
537#endif /* UIP_CONF_STATISTICS */
538
539/**
540 * Determines if logging of certain events should be compiled in.
541 *
542 * This is useful mostly for debugging. The function uip_log()
543 * must be implemented to suit the architecture of the project, if
544 * logging is turned on.
545 *
546 * \hideinitializer
547 */
548#ifndef UIP_CONF_LOGGING
549#define UIP_LOGGING 0
550#else /* UIP_CONF_LOGGING */
551#define UIP_LOGGING UIP_CONF_LOGGING
552#endif /* UIP_CONF_LOGGING */
553
554/**
555 * Broadcast support.
556 *
557 * This flag configures IP broadcast support. This is useful only
558 * together with UDP.
559 *
560 * \hideinitializer
561 *
562 */
563#ifndef UIP_CONF_BROADCAST
564#define UIP_BROADCAST 0
565#else /* UIP_CONF_BROADCAST */
566#define UIP_BROADCAST UIP_CONF_BROADCAST
567#endif /* UIP_CONF_BROADCAST */
568
569/**
570 * Print out a uIP log message.
571 *
572 * This function must be implemented by the module that uses uIP, and
573 * is called by uIP whenever a log message is generated.
574 */
575void uip_log(char *msg);
576
577/**
578 * The link level header length.
579 *
580 * This is the offset into the uip_buf where the IP header can be
581 * found. For Ethernet, this should be set to 14. For SLIP, this
582 * should be set to 0.
583 *
584 * \note we probably won't use this constant for other link layers than
585 * ethernet as they have variable header length (this is due to variable
586 * number and type of address fields and to optional security features)
587 * E.g.: 802.15.4 -> 2 + (1/2*4/8) + 0/5/6/10/14
588 * 802.11 -> 4 + (6*3/4) + 2
589 * \hideinitializer
590 */
591#ifdef UIP_CONF_LLH_LEN
592#define UIP_LLH_LEN UIP_CONF_LLH_LEN
593#else /* UIP_LLH_LEN */
594#define UIP_LLH_LEN 14
595#endif /* UIP_CONF_LLH_LEN */
596
597/** @} */
598/*------------------------------------------------------------------------------*/
599/**
600 * \defgroup uipoptcpu CPU architecture configuration
601 * @{
602 *
603 * The CPU architecture configuration is where the endianess of the
604 * CPU on which uIP is to be run is specified. Most CPUs today are
605 * little endian, and the most notable exception are the Motorolas
606 * which are big endian. The BYTE_ORDER macro should be changed to
607 * reflect the CPU architecture on which uIP is to be run.
608 */
609
610/**
611 * The byte order of the CPU architecture on which uIP is to be run.
612 *
613 * This option can be either UIP_BIG_ENDIAN (Motorola byte order) or
614 * UIP_LITTLE_ENDIAN (Intel byte order).
615 *
616 * \hideinitializer
617 */
618#ifdef UIP_CONF_BYTE_ORDER
619#define UIP_BYTE_ORDER UIP_CONF_BYTE_ORDER
620#else /* UIP_CONF_BYTE_ORDER */
621#define UIP_BYTE_ORDER UIP_LITTLE_ENDIAN
622#endif /* UIP_CONF_BYTE_ORDER */
623
624/** @} */
625/*------------------------------------------------------------------------------*/
626
627#include <ff.h>
628#include <stdbool.h>
629#include <stdint.h>
630
631#include "timer.h"
632
633typedef uint8_t u8_t;
634typedef uint16_t u16_t;
635typedef uint32_t u32_t;
636typedef uint32_t uip_stats_t;
637
638/**
639 * \defgroup uipoptapp Application specific configurations
640 * @{
641 *
642 * An uIP application is implemented using a single application
643 * function that is called by uIP whenever a TCP/IP event occurs. The
644 * name of this function must be registered with uIP at compile time
645 * using the UIP_APPCALL definition.
646 *
647 * uIP applications can store the application state within the
648 * uip_conn structure by specifying the type of the application
649 * structure by typedef:ing the type uip_tcp_appstate_t and uip_udp_appstate_t.
650 *
651 * The file containing the definitions must be included in the
652 * uipopt.h file.
653 *
654 * The following example illustrates how this can look.
655 \code
656
657 void httpd_appcall(void);
658 #define UIP_APPCALL httpd_appcall
659
660 struct httpd_state {
661 u8_t state;
662 u16_t count;
663 char *dataptr;
664 char *script;
665 };
666 typedef struct httpd_state uip_tcp_appstate_t
667 \endcode
668*/
669#define UIP_UDP_APPCALL uIPManagement_UDPCallback
670void UIP_UDP_APPCALL(void);
671
672/**
673 * \var #define UIP_APPCALL
674 *
675 * The name of the application function that uIP should call in
676 * response to TCP/IP events.
677 *
678 */
679#define UIP_APPCALL uIPManagement_TCPCallback
680void UIP_APPCALL(void);
681
682/**
683 * \var typedef uip_tcp_appstate_t
684 *
685 * The type of the application state that is to be stored in the
686 * uip_conn structure. This usually is typedef:ed to a struct holding
687 * application state information.
688 */
689typedef union
690{
691 struct
692 {
693 uint8_t CurrentState;
694 uint8_t NextState;
695
696 char FileName[MAX_URI_LENGTH];
697 FIL FileHandle;
698 bool FileOpen;
699 uint32_t ACKedFilePos;
700 uint16_t SentChunkSize;
701 } HTTPServer;
702
703 struct
704 {
705 uint8_t CurrentState;
706 uint8_t NextState;
707
708 uint8_t IssuedCommand;
709 } TELNETServer;
710} uip_tcp_appstate_t;
711
712/**
713 * \var typedef uip_udp_appstate_t
714 *
715 * The type of the application state that is to be stored in the
716 * uip_conn structure. This usually is typedef:ed to a struct holding
717 * application state information.
718 */
719typedef union
720{
721 struct
722 {
723 uint8_t CurrentState;
724 struct timer Timeout;
725
726 struct
727 {
728 uint8_t AllocatedIP[4];
729 uint8_t Netmask[4];
730 uint8_t GatewayIP[4];
731 uint8_t ServerIP[4];
732 } DHCPOffer_Data;
733 } DHCPClient;
734} uip_udp_appstate_t;
735/** @} */
736
737#endif /* __UIPOPT_H__ */
738/** @} */
739/** @} */
740