summaryrefslogtreecommitdiffstats
path: root/lib/lufa/Projects/Webserver/Lib/uip
diff options
context:
space:
mode:
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 e71f7209d2..0000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/clock.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <LUFA/Common/Common.h>
-
-#include "clock.h"
-
-//Counted time
-volatile clock_time_t clock_datetime = 0;
-
-//Overflow interrupt
-ISR(TIMER1_COMPA_vect, ISR_BLOCK)
-{
- clock_datetime += 1;
-}
-
-//Initialise the clock
-void clock_init()
-{
- OCR1A = (((F_CPU / 1024) / 100) - 1);
- TCCR1B = ((1 << WGM12) | (1 << CS12) | (1 << CS10));
- TIMSK1 = (1 << OCIE1A);
-}
-
-//Return time
-clock_time_t clock_time()
-{
- clock_time_t time;
-
- GlobalInterruptDisable();
- time = clock_datetime;
- GlobalInterruptEnable();
-
- return time;
-}
-
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 bbfa4ac0e3..0000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/clock.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef __CLOCK_ARCH_H__
-#define __CLOCK_ARCH_H__
-
-#include <stdint.h>
-#include <util/atomic.h>
-
-typedef uint16_t clock_time_t;
-#define CLOCK_SECOND 100
-void clock_init(void);
-clock_time_t clock_time(void);
-
-#endif /* __CLOCK_ARCH_H__ */
-
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 eae06f43bd..0000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/timer.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * \addtogroup timer
- * @{
- */
-
-/**
- * \file
- * Timer library implementation.
- * \author
- * Adam Dunkels <adam@sics.se>
- */
-
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the uIP TCP/IP stack
- *
- * Author: Adam Dunkels <adam@sics.se>
- *
- * $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $
- */
-
-#include "clock.h"
-#include "timer.h"
-
-/*---------------------------------------------------------------------------*/
-/**
- * Set a timer.
- *
- * This function is used to set a timer for a time sometime in the
- * future. The function timer_expired() will evaluate to true after
- * the timer has expired.
- *
- * \param t A pointer to the timer
- * \param interval The interval before the timer expires.
- *
- */
-void
-timer_set(struct timer *t, clock_time_t interval)
-{
- t->interval = interval;
- t->start = clock_time();
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Reset the timer with the same interval.
- *
- * This function resets the timer with the same interval that was
- * given to the timer_set() function. The start point of the interval
- * is the exact time that the timer last expired. Therefore, this
- * function will cause the timer to be stable over time, unlike the
- * timer_restart() function.
- *
- * \param t A pointer to the timer.
- *
- * \sa timer_restart()
- */
-void
-timer_reset(struct timer *t)
-{
- t->start += t->interval;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Restart the timer from the current point in time
- *
- * This function restarts a timer with the same interval that was
- * given to the timer_set() function. The timer will start at the
- * current time.
- *
- * \note A periodic timer will drift if this function is used to reset
- * it. For periodic timers, use the timer_reset() function instead.
- *
- * \param t A pointer to the timer.
- *
- * \sa timer_reset()
- */
-void
-timer_restart(struct timer *t)
-{
- t->start = clock_time();
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Check if a timer has expired.
- *
- * This function tests if a timer has expired and returns true or
- * false depending on its status.
- *
- * \param t A pointer to the timer
- *
- * \return Non-zero if the timer has expired, zero otherwise.
- *
- */
-int
-timer_expired(struct timer *t)
-{
- return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval;
-}
-/*---------------------------------------------------------------------------*/
-
-/** @} */
-
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 04917e4c52..0000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/timer.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * \defgroup timer Timer library
- *
- * The timer library provides functions for setting, resetting and
- * restarting timers, and for checking if a timer has expired. An
- * application must "manually" check if its timers have expired; this
- * is not done automatically.
- *
- * A timer is declared as a \c struct \c timer and all access to the
- * timer is made by a pointer to the declared timer.
- *
- * \note The timer library uses the \ref clock "Clock library" to
- * measure time. Intervals should be specified in the format used by
- * the clock library.
- *
- * @{
- */
-
-
-/**
- * \file
- * Timer library header file.
- * \author
- * Adam Dunkels <adam@sics.se>
- */
-
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the uIP TCP/IP stack
- *
- * Author: Adam Dunkels <adam@sics.se>
- *
- * $Id: timer.h,v 1.3 2006/06/11 21:46:39 adam Exp $
- */
-#ifndef __TIMER_H__
-#define __TIMER_H__
-
-#include "clock.h"
-
-/**
- * A timer.
- *
- * This structure is used for declaring a timer. The timer must be set
- * with timer_set() before it can be used.
- *
- * \hideinitializer
- */
-struct timer {
- clock_time_t start;
- clock_time_t interval;
-};
-
-void timer_set(struct timer *t, clock_time_t interval);
-void timer_reset(struct timer *t);
-void timer_restart(struct timer *t);
-int timer_expired(struct timer *t);
-
-#endif /* __TIMER_H__ */
-
-/** @} */
-
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 5222a05b63..0000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/uip-split.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <adam@sics.se>
- *
- * $Id: uip-split.c,v 1.2 2008/10/14 13:39:12 julienabeille Exp $
- */
-
-#include "uip-split.h"
-
-
-#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
-
-/*-----------------------------------------------------------------------------*/
-void
-uip_split_output(void)
-{
-#if UIP_TCP
- u16_t tcplen, len1, len2;
-
- /* We only try to split maximum sized TCP segments. */
- if(BUF->proto == UIP_PROTO_TCP && uip_len == UIP_BUFSIZE) {
-
- tcplen = uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN;
- /* Split the segment in two. If the original packet length was
- odd, we make the second packet one byte larger. */
- len1 = len2 = tcplen / 2;
- if(len1 + len2 < tcplen) {
- ++len2;
- }
-
- /* Create the first packet. This is done by altering the length
- field of the IP header and updating the checksums. */
- uip_len = len1 + UIP_TCPIP_HLEN + UIP_LLH_LEN;
-#if UIP_CONF_IPV6
- /* For IPv6, the IP length field does not include the IPv6 IP header
- length. */
- BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
- BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
-#else /* UIP_CONF_IPV6 */
- BUF->len[0] = (uip_len - UIP_LLH_LEN) >> 8;
- BUF->len[1] = (uip_len - UIP_LLH_LEN) & 0xff;
-#endif /* UIP_CONF_IPV6 */
-
- /* Recalculate the TCP checksum. */
- BUF->tcpchksum = 0;
- BUF->tcpchksum = ~(uip_tcpchksum());
-
-#if !UIP_CONF_IPV6
- /* Recalculate the IP checksum. */
- BUF->ipchksum = 0;
- BUF->ipchksum = ~(uip_ipchksum());
-#endif /* UIP_CONF_IPV6 */
-
- /* Transmit the first packet. */
-#if UIP_CONF_IPV6
- tcpip_ipv6_output();
-#else
- if (USB_CurrentMode == USB_MODE_Device)
- RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface_Device, uip_buf, uip_len);
- else
- RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface_Host, uip_buf, uip_len);
-#endif /* UIP_CONF_IPV6 */
-
- /* Now, create the second packet. To do this, it is not enough to
- just alter the length field, but we must also update the TCP
- sequence number and point the uip_appdata to a new place in
- memory. This place is determined by the length of the first
- packet (len1). */
- uip_len = len2 + UIP_TCPIP_HLEN + UIP_LLH_LEN;
-#if UIP_CONF_IPV6
- /* For IPv6, the IP length field does not include the IPv6 IP header
- length. */
- BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
- BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
-#else /* UIP_CONF_IPV6 */
- BUF->len[0] = (uip_len - UIP_LLH_LEN) >> 8;
- BUF->len[1] = (uip_len - UIP_LLH_LEN) & 0xff;
-#endif /* UIP_CONF_IPV6 */
-
- memcpy(uip_appdata, (u8_t *)uip_appdata + len1, len2);
-
- uip_add32(BUF->seqno, len1);
- BUF->seqno[0] = uip_acc32[0];
- BUF->seqno[1] = uip_acc32[1];
- BUF->seqno[2] = uip_acc32[2];
- BUF->seqno[3] = uip_acc32[3];
-
- /* Recalculate the TCP checksum. */
- BUF->tcpchksum = 0;
- BUF->tcpchksum = ~(uip_tcpchksum());
-
-#if !UIP_CONF_IPV6
- /* Recalculate the IP checksum. */
- BUF->ipchksum = 0;
- BUF->ipchksum = ~(uip_ipchksum());
-#endif /* UIP_CONF_IPV6 */
-
- /* Transmit the second packet. */
-#if UIP_CONF_IPV6
- tcpip_ipv6_output();
-#else
- if (USB_CurrentMode == USB_MODE_Device)
- RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface_Device, uip_buf, uip_len);
- else
- RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface_Host, uip_buf, uip_len);
-#endif /* UIP_CONF_IPV6 */
- return;
- }
-#endif /* UIP_TCP */
-
- /* uip_fw_output();*/
-#if UIP_CONF_IPV6
- tcpip_ipv6_output();
-#else
- if (USB_CurrentMode == USB_MODE_Device)
- RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface_Device, uip_buf, uip_len);
- else
- RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface_Host, uip_buf, uip_len);
-#endif /* UIP_CONF_IPV6 */
-}
-
-/*-----------------------------------------------------------------------------*/
-
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 0c768ce40a..0000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/uip-split.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <adam@sics.se>
- *
- * $Id: uip-split.h,v 1.1 2006/06/17 22:41:19 adamdunkels Exp $
- */
-/**
- * \addtogroup uip
- * @{
- */
-
-/**
- * \defgroup uipsplit uIP TCP throughput booster hack
- * @{
- *
- * The basic uIP TCP implementation only allows each TCP connection to
- * have a single TCP segment in flight at any given time. Because of
- * the delayed ACK algorithm employed by most TCP receivers, uIP's
- * limit on the amount of in-flight TCP segments seriously reduces the
- * maximum achievable throughput for sending data from uIP.
- *
- * The uip-split module is a hack which tries to remedy this
- * situation. By splitting maximum sized outgoing TCP segments into
- * two, the delayed ACK algorithm is not invoked at TCP
- * receivers. This improves the throughput when sending data from uIP
- * by orders of magnitude.
- *
- * The uip-split module uses the uip-fw module (uIP IP packet
- * forwarding) for sending packets. Therefore, the uip-fw module must
- * be set up with the appropriate network interfaces for this module
- * to work.
- */
-
-
-/**
- * \file
- * Module for splitting outbound TCP segments in two to avoid the
- * delayed ACK throughput degradation.
- * \author
- * Adam Dunkels <adam@sics.se>
- *
- */
-
-#ifndef __UIP_SPLIT_H__
-#define __UIP_SPLIT_H__
-
-#include <string.h>
-#include <uip.h>
-
-#include "../../USBHostMode.h"
-
-#include <LUFA/Drivers/USB/USB.h>
-
-/**
- * Handle outgoing packets.
- *
- * This function inspects an outgoing packet in the uip_buf buffer and
- * sends it out using the uip_fw_output() function. If the packet is a
- * full-sized TCP segment it will be split into two segments and
- * transmitted separately. This function should be called instead of
- * the actual device driver output function, or the uip_fw_output()
- * function.
- *
- * The headers of the outgoing packet is assumed to be in the uip_buf
- * buffer and the payload is assumed to be wherever uip_appdata
- * points. The length of the outgoing packet is assumed to be in the
- * uip_len variable.
- *
- */
-void uip_split_output(void);
-void uip_add32(u8_t *op32, u16_t op16);
-#endif /* __UIP_SPLIT_H__ */
-
-/** @} */
-/** @} */
-
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 fead75775c..0000000000
--- a/lib/lufa/Projects/Webserver/Lib/uip/uip.c
+++ /dev/null
@@ -1,1941 +0,0 @@
-#define DEBUG_PRINTF(...) /*printf(__VA_ARGS__)*/
-
-/**
- * \addtogroup uip
- * @{
- */
-
-/**
- * \file
- * The uIP TCP/IP stack code.
- * \author Adam Dunkels <adam@dunkels.com>
- */
-
-/*
- * Copyright (c) 2001-2003, Adam Dunkels.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This file is part of the uIP TCP/IP stack.
- *
- * $Id: uip.c,v 1.15 2008/10/15 08:08:32 adamdunkels Exp $
- *
- */
-
-/*
- * uIP is a small implementation of the IP, UDP and TCP protocols (as
- * well as some basic ICMP stuff). The implementation couples the IP,
- * UDP, TCP and the application layers very tightly. To keep the size
- * of the compiled code down, this code frequently uses the goto
- * statement. While it would be possible to break the uip_process()
- * function into many smaller functions, this would increase the code
- * size because of the overhead of parameter passing and the fact that
- * the optimizer would not be as efficient.
- *
- * The principle is that we have a small buffer, called the uip_buf,
- * in which the device driver puts an incoming packet. The TCP/IP
- * stack parses the headers in the packet, and calls the
- * application. If the remote host has sent data to the application,
- * this data is present in the uip_buf and the application read the
- * data from there. It is up to the application to put this data into
- * a byte stream if needed. The application will not be fed with data
- * that is out of sequence.
- *
- * If the application whishes to send data to the peer, it should put
- * its data into the uip_buf. The uip_appdata pointer points to the
- * first available byte. The TCP/IP stack will calculate the
- * checksums, and fill in the necessary header fields and finally send
- * the packet back to the peer.
-*/
-
-#include "uip.h"
-#include "uipopt.h"
-#include "uip_arp.h"
-
-#if !UIP_CONF_IPV6 /* If UIP_CONF_IPV6 is defined, we compile the
- uip6.c file instead of this one. Therefore
- this #ifndef removes the entire compilation
- output of the uip.c file */
-
-
-#if UIP_CONF_IPV6
-#include "net/uip-neighbor.h"
-#endif /* UIP_CONF_IPV6 */
-
-#include <string.h>
-
-/*---------------------------------------------------------------------------*/
-/* Variable definitions. */
-
-
-/* The IP address of this host. If it is defined to be fixed (by
- setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set
- here. Otherwise, the address */
-#if UIP_FIXEDADDR > 0
-const uip_ipaddr_t uip_hostaddr =
- { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };
-const uip_ipaddr_t uip_draddr =
- { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };
-const uip_ipaddr_t uip_netmask =
- { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };
-#else
-uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
-#endif /* UIP_FIXEDADDR */
-
-const uip_ipaddr_t uip_broadcast_addr =
-#if UIP_CONF_IPV6
- { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
-#else /* UIP_CONF_IPV6 */
- { { 0xff, 0xff, 0xff, 0xff } };
-#endif /* UIP_CONF_IPV6 */
-const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };
-
-#if UIP_FIXEDETHADDR
-const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
- UIP_ETHADDR1,
- UIP_ETHADDR2,
- UIP_ETHADDR3,
- UIP_ETHADDR4,
- UIP_ETHADDR5}};
-#else
-struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
-#endif
-
-#ifndef UIP_CONF_EXTERNAL_BUFFER
-u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains
- incoming packets. */
-#endif /* UIP_CONF_EXTERNAL_BUFFER */
-
-void *uip_appdata; /* The uip_appdata pointer points to
- application data. */
-void *uip_sappdata; /* The uip_appdata pointer points to
- the application data which is to
- be sent. */
-#if UIP_URGDATA > 0
-void *uip_urgdata; /* The uip_urgdata pointer points to
- urgent data (out-of-band data), if
- present. */
-u16_t uip_urglen, uip_surglen;
-#endif /* UIP_URGDATA > 0 */
-
-u16_t uip_len, uip_slen;
- /* The uip_len is either 8 or 16 bits,
- depending on the maximum packet
- size. */
-
-u8_t uip_flags; /* The uip_flags variable is used for
- communication between the TCP/IP stack
- and the application program. */
-struct uip_conn *uip_conn; /* uip_conn always points to the current
- connection. */
-
-struct uip_conn uip_conns[UIP_CONNS];
- /* The uip_conns array holds all TCP
- connections. */
-u16_t uip_listenports[UIP_LISTENPORTS];
- /* The uip_listenports list all currently
- listening ports. */
-#if UIP_UDP
-struct uip_udp_conn *uip_udp_conn;
-struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
-#endif /* UIP_UDP */
-
-static u16_t ipid; /* Ths ipid variable is an increasing
- number that is used for the IP ID
- field. */
-
-void uip_setipid(u16_t id) { ipid = id; }
-
-static u8_t iss[4]; /* The iss variable is used for the TCP
- initial sequence number. */
-
-#if UIP_ACTIVE_OPEN
-static u16_t lastport; /* Keeps track of the last port used for
- a new connection. */
-#endif /* UIP_ACTIVE_OPEN */
-
-/* Temporary variables. */
-u8_t uip_acc32[4];
-static u8_t c, opt;
-static u16_t tmp16;
-
-/* Structures and definitions. */
-#define TCP_FIN 0x01
-#define TCP_SYN 0x02
-#define TCP_RST 0x04
-#define TCP_PSH 0x08
-#define TCP_ACK 0x10
-#define TCP_URG 0x20
-#define TCP_CTL 0x3f
-
-#define TCP_OPT_END 0 /* End of TCP options list */
-#define TCP_OPT_NOOP 1 /* "No-operation" TCP option */
-#define TCP_OPT_MSS 2 /* Maximum segment size TCP option */
-
-#define TCP_OPT_MSS_LEN 4 /* Length of TCP MSS option. */
-
-#define ICMP_ECHO_REPLY 0
-#define ICMP_ECHO 8
-
-#define ICMP_DEST_UNREACHABLE 3
-#define ICMP_PORT_UNREACHABLE 3
-
-#define ICMP6_ECHO_REPLY 129
-#define ICMP6_ECHO 128
-#define ICMP6_NEIGHBOR_SOLICITATION 135
-#define ICMP6_NEIGHBOR_ADVERTISEMENT 136
-
-#define ICMP6_FLAG_S (1 << 6)
-
-#define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1
-#define ICMP6_OPTION_TARGET_LINK_ADDRESS 2
-
-
-/* Macros. */
-#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
-#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])
-#define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
-#define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
-
-
-#if UIP_STATISTICS == 1
-struct uip_stats uip_stat;
-#define UIP_STAT(s) s
-#else
-#define UIP_STAT(s)
-#endif /* UIP_STATISTICS == 1 */
-
-#if UIP_LOGGING == 1
-#include <stdio.h>
-void uip_log(char *msg);
-#define UIP_LOG(m) uip_log(m)
-#else
-#define UIP_LOG(m)
-#endif /* UIP_LOGGING == 1 */
-
-#if ! UIP_ARCH_ADD32
-void
-uip_add32(u8_t *op32, u16_t op16)
-{
- uip_acc32[3] = op32[3] + (op16 & 0xff);
- uip_acc32[2] = op32[2] + (op16 >> 8);
- uip_acc32[1] = op32[1];
- uip_acc32[0] = op32[0];
-
- if(uip_acc32[2] < (op16 >> 8)) {
- ++uip_acc32[1];
- if(uip_acc32[1] == 0) {
- ++uip_acc32[0];
- }
- }
-
-
- if(uip_acc32[3] < (op16 & 0xff)) {
- ++uip_acc32[2];
- if(uip_acc32[2] == 0) {
- ++uip_acc32[1];
- if(uip_acc32[1] == 0) {
- ++uip_acc32[0];
- }
- }
- }
-}
-
-#endif /* UIP_ARCH_ADD32 */
-
-#if ! UIP_ARCH_CHKSUM
-/*---------------------------------------------------------------------------*/
-static u16_t
-chksum(u16_t sum, const u8_t *data, u16_t len)
-{
- u16_t t;
- const u8_t *dataptr;
- const u8_t *last_byte;
-
- dataptr = data;
- last_byte = data + len - 1;
-
- while(dataptr < last_byte) { /* At least two more bytes */
- t = (dataptr[0] << 8) + dataptr[1];
- sum += t;
- if(sum < t) {
- sum++; /* carry */
- }
- dataptr += 2;
- }
-
- if(dataptr == last_byte) {
- t = (dataptr[0] << 8) + 0;
- sum += t;
- if(sum < t) {
- sum++; /* carry */
- }
- }
-
- /* Return sum in host byte order. */
- return sum;
-}
-/*---------------------------------------------------------------------------*/
-u16_t
-uip_chksum(u16_t *data, u16_t len)
-{
- return htons(chksum(0, (u8_t *)data, len));
-}
-/*---------------------------------------------------------------------------*/
-#ifndef UIP_ARCH_IPCHKSUM
-u16_t
-uip_ipchksum(void)
-{
- u16_t sum;
-
- sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN);
- DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum);
- return (sum == 0) ? 0xffff : htons(sum);
-}
-#endif
-/*---------------------------------------------------------------------------*/
-static u16_t
-upper_layer_chksum(u8_t proto)
-{
- u16_t upper_layer_len;
- u16_t sum;
-
-#if UIP_CONF_IPV6
- upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]);
-#else /* UIP_CONF_IPV6 */
- upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;
-#endif /* UIP_CONF_IPV6 */
-
- /* First sum pseudo-header. */
-
- /* IP protocol and length fields. This addition cannot carry. */
- sum = upper_layer_len + proto;
- /* Sum IP source and destination addresses. */
- sum = chksum(sum, (u8_t *)&BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));
-
- /* Sum TCP header and data. */
- sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
- upper_layer_len);
-
- return (sum == 0) ? 0xffff : htons(sum);
-}
-/*---------------------------------------------------------------------------*/
-#if UIP_CONF_IPV6
-u16_t
-uip_icmp6chksum(void)
-{
- return upper_layer_chksum(UIP_PROTO_ICMP6);
-
-}
-#endif /* UIP_CONF_IPV6 */
-/*---------------------------------------------------------------------------*/
-u16_t
-uip_tcpchksum(void)
-{
- return upper_layer_chksum(UIP_PROTO_TCP);
-}
-/*---------------------------------------------------------------------------*/
-#if UIP_UDP_CHECKSUMS
-u16_t
-uip_udpchksum(void)
-{
- return upper_layer_chksum(UIP_PROTO_UDP);
-}
-#endif /* UIP_UDP_CHECKSUMS */
-#endif /* UIP_ARCH_CHKSUM */
-/*---------------------------------------------------------------------------*/
-void
-uip_init(void)
-{
- for(c = 0; c < UIP_LISTENPORTS; ++c) {
- uip_listenports[c] = 0;
- }
- for(c = 0; c < UIP_CONNS; ++c) {
- uip_conns[c].tcpstateflags = UIP_CLOSED;
- }
-#if UIP_ACTIVE_OPEN
- lastport = 1024;
-#endif /* UIP_ACTIVE_OPEN */
-
-#if UIP_UDP
- for(c = 0; c < UIP_UDP_CONNS; ++c) {
- uip_udp_conns[c].lport = 0;
- }
-#endif /* UIP_UDP */
-
-
- /* IPv4 initialization. */
-#if UIP_FIXEDADDR == 0
- /* uip_hostaddr[0] = uip_hostaddr[1] = 0;*/
-#endif /* UIP_FIXEDADDR */
-
-}
-/*---------------------------------------------------------------------------*/
-#if UIP_ACTIVE_OPEN
-struct uip_conn *
-uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
-{
- register struct uip_conn *conn, *cconn;
-
- /* Find an unused local port. */
- again:
- ++lastport;
-
- if(lastport >= 32000) {
- lastport = 4096;
- }
-
- /* Check if this port is already in use, and if so try to find
- another one. */
- for(c = 0; c < UIP_CONNS; ++c) {
- conn = &uip_conns[c];
- if(conn->tcpstateflags != UIP_CLOSED &&
- conn->lport == htons(lastport)) {
- goto again;
- }
- }
-
- conn = 0;
- for(c = 0; c < UIP_CONNS; ++c) {
- cconn = &uip_conns[c];
- if(cconn->tcpstateflags == UIP_CLOSED) {
- conn = cconn;
- break;
- }
- if(cconn->tcpstateflags == UIP_TIME_WAIT) {
- if(conn == 0 ||
- cconn->timer > conn->timer) {
- conn = cconn;
- }
- }
- }
-
- if(conn == 0) {
- return 0;
- }
-
- conn->tcpstateflags = UIP_SYN_SENT;
-
- conn->snd_nxt[0] = iss[0];