Introduction of sequential-API build variant, better thread safety (lwIP only)

This commit is contained in:
Joseph Henry
2017-09-27 02:29:04 -07:00
parent e4620e4c85
commit 5f1e9fe795
176 changed files with 16494 additions and 20406 deletions

View File

@@ -0,0 +1,59 @@
#
# Copyright (c) 2001, 2002 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. 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 lwIP TCP/IP stack.
#
# Author: Adam Dunkels <adam@sics.se>
#
all compile: simhost simrouter simnode makefsdata
.PHONY: all
include ../Common.mk
MAKEFSDATAOBJS=$(notdir $(MAKEFSDATAFILES:.c=.o))
clean:
rm -f *.o $(LWIPLIBCOMMON) $(APPLIB) simhost simnode simrouter *.s .depend* *.core core
depend dep: .depend
include .depend
.depend: simhost.c simnode.c simrouter.c $(LWIPFILES) $(APPFILES) $(MAKEFSDATAFILES)
$(CCDEP) $(CFLAGS) -MM $^ > .depend || rm -f .depend
simhost: .depend $(LWIPLIBCOMMON) $(APPLIB) simhost.o
$(CC) $(CFLAGS) -o simhost simhost.o -Wl,--start-group $(APPLIB) $(LWIPLIBCOMMON) -Wl,--end-group $(LDFLAGS)
simrouter: .depend $(LWIPLIBCOMMON) $(APPLIB) simrouter.o
$(CC) $(CFLAGS) -o simrouter simrouter.o -Wl,--start-group $(APPLIB) $(LWIPLIBCOMMON) -Wl,--end-group $(LDFLAGS)
simnode: .depend $(LWIPLIBCOMMON) $(APPLIB) simnode.o
$(CC) $(CFLAGS) -o simnode simnode.o -Wl,--start-group $(APPLIB) $(LWIPLIBCOMMON) -Wl,--end-group $(LDFLAGS)
makefsdata: .depend $(MAKEFSDATAOBJS)
$(CC) $(CFLAGS) -o makefsdata $(MAKEFSDATAOBJS)

View File

@@ -0,0 +1,61 @@
This directory contains an example of how a project using lwIP might
look. It is also the development platform of lwIP, since it can be run
as a user process under FreeBSD or Linux. There are also a number of
example applications (including a simple web server) in the apps/
directory.
Some short instructions on how to build and run lwIP on a FreeBSD or
Linux host. For FreeBSD, the tap interface must be enabled in the
kernel configuration and the kernel must be recompiled. The tap
interface is enabled by adding the line "pseudo-device tap" in the
kernel configuration. See Chapter 9 in the FreeBSD handbook for
instructions on how to build a custom FreeBSD kernel.
For Linux you might need to create a device node with
> mknod /dev/net/tun c 10 200
* Compile the code. This must be done by using GNU Make. Under
FreeBSD, GNU Make can be found in the ports collection under
/usr/ports/devel/gmake (type "make install distclean" to
install). Under Linux, GNU Make is the default "make".
> gmake (FreeBSD)
> make (Linux)
* The compilation process produces the executable file "simhost". To
run this, you have to be root.
> su (Type password for the root account)
# ./simhost
* The lwIP TCP/IP stack is now running with IP address
192.168.0.2. Some things that you can try:
To see the packets that are going to and from the lwIP stack, run
tcpdump:
# tcpdump -l -n -i tap0
You can ping lwIP:
> ping 192.168.0.2
For a telnet shell, run:
> telnet 192.168.0.2
Finally, "simhost" also includes a simple web server; the URL is
of course http://192.168.0.2/.
* Simhost has some extra features that can be
selected with command line options.
To enable runtime debug output (project must be build with -DLWIP_DEBUG):
# ./simhost -d
To ping any host, e.g. the gateway:
# ./simhost -p 192.168.0.1

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef LWIP_HOOKS_H
#define LWIP_HOOKS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "addons/tcp_isn/tcp_isn.h"
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
#ifdef __cplusplus
}
#endif
#endif /* LWIP_HOOKS_H */

View File

@@ -0,0 +1,374 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef LWIP_LWIPOPTS_H
#define LWIP_LWIPOPTS_H
#include "lwip/arch.h"
#define LWIP_HOOK_FILENAME "lwip_hooks.h"
#define LWIP_IPV4 1
#define LWIP_IPV6 1
#define LWIP_DBG_MIN_LEVEL 0
#define LWIP_COMPAT_SOCKETS 1
#define TAPIF_DEBUG LWIP_DBG_ON
#define TUNIF_DEBUG LWIP_DBG_OFF
#define UNIXIF_DEBUG LWIP_DBG_OFF
#define DELIF_DEBUG LWIP_DBG_OFF
#define SIO_FIFO_DEBUG LWIP_DBG_OFF
#define TCPDUMP_DEBUG LWIP_DBG_ON
#define SLIP_DEBUG LWIP_DBG_OFF
#define PPP_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
#define API_LIB_DEBUG LWIP_DBG_ON
#define API_MSG_DEBUG LWIP_DBG_ON
#define TCPIP_DEBUG LWIP_DBG_ON
#define NETIF_DEBUG LWIP_DBG_ON
#define SOCKETS_DEBUG LWIP_DBG_ON
#define DEMO_DEBUG LWIP_DBG_ON
#define IP_DEBUG LWIP_DBG_ON
#define IP_REASS_DEBUG LWIP_DBG_ON
#define RAW_DEBUG LWIP_DBG_ON
#define ICMP_DEBUG LWIP_DBG_ON
#define UDP_DEBUG LWIP_DBG_ON
#define TCP_DEBUG LWIP_DBG_ON
#define TCP_INPUT_DEBUG LWIP_DBG_ON
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
#define TCP_RTO_DEBUG LWIP_DBG_ON
#define TCP_CWND_DEBUG LWIP_DBG_ON
#define TCP_WND_DEBUG LWIP_DBG_ON
#define TCP_FR_DEBUG LWIP_DBG_ON
#define TCP_QLEN_DEBUG LWIP_DBG_ON
#define TCP_RST_DEBUG LWIP_DBG_ON
extern unsigned char debug_flags;
#define LWIP_DBG_TYPES_ON debug_flags
#define NO_SYS 0
#define LWIP_SOCKET (NO_SYS==0)
#define LWIP_NETCONN (NO_SYS==0)
#define SO_REUSE 1
#define IP_SOF_BROADCAST_RECV 1
#define IP_SOF_BROADCAST 1
#define SO_REUSE_RXTOALL 1
#define LWIP_SO_RCVTIMEO (LWIP_SOCKET)
/* ---------- Memory options ---------- */
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
byte alignment -> define MEM_ALIGNMENT to 2. */
/* MSVC port: intel processors don't need 4-byte alignment,
but are faster that way! */
#define MEM_ALIGNMENT 4U
/* MEM_SIZE: the size of the heap memory. If the application will send
a lot of data that needs to be copied, this should be set high. */
#define MEM_SIZE 10240
/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
sends a lot of data out of ROM (or other static memory), this
should be set high. */
#define MEMP_NUM_PBUF 16
/* MEMP_NUM_RAW_PCB: the number of UDP protocol control blocks. One
per active RAW "connection". */
#define MEMP_NUM_RAW_PCB 3
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
per active UDP "connection". */
#define MEMP_NUM_UDP_PCB 6
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
connections. */
#define MEMP_NUM_TCP_PCB 5
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
connections. */
#define MEMP_NUM_TCP_PCB_LISTEN 8
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
segments. */
#define MEMP_NUM_TCP_SEG 16
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
timeouts. */
#define MEMP_NUM_SYS_TIMEOUT 17
/* The following four are used only with the sequential API and can be
set to 0 if the application only will use the raw API. */
/* MEMP_NUM_NETBUF: the number of struct netbufs. */
#define MEMP_NUM_NETBUF 2
/* MEMP_NUM_NETCONN: the number of struct netconns. */
#define MEMP_NUM_NETCONN 10
/* MEMP_NUM_TCPIP_MSG_*: the number of struct tcpip_msg, which is used
for sequential API communication and incoming packets. Used in
src/api/tcpip.c. */
#define MEMP_NUM_TCPIP_MSG_API 16
#define MEMP_NUM_TCPIP_MSG_INPKT 16
#define MEMP_OVERFLOW_CHECK 1
/* ---------- Pbuf options ---------- */
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
#define PBUF_POOL_SIZE 200
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
#define PBUF_POOL_BUFSIZE 128
/* PBUF_LINK_HLEN: the number of bytes that should be allocated for a
link level header. */
#define PBUF_LINK_HLEN 16u
/** SYS_LIGHTWEIGHT_PROT
* define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
* for certain critical regions during buffer allocation, deallocation and memory
* allocation and deallocation.
*/
#define SYS_LIGHTWEIGHT_PROT 1
#define LWIP_TCPIP_TIMEOUT 1
/* ---------- TCP options ---------- */
#define LWIP_TCP 1
#define LWIP_ALTCP (LWIP_TCP)
#define TCP_TTL 255
#ifdef LWIP_HAVE_MBEDTLS
#define LWIP_ALTCP_TLS (LWIP_TCP)
#define LWIP_ALTCP_TLS_MBEDTLS (LWIP_TCP)
#endif
#define TCP_LISTEN_BACKLOG 1
/* Controls if TCP should queue segments that arrive out of
order. Define to 0 if your device is low on memory. */
#define TCP_QUEUE_OOSEQ 1
/* TCP Maximum segment size. */
#define TCP_MSS 1024
/* TCP sender buffer space (bytes). */
#define TCP_SND_BUF 2048
/* TCP sender buffer space (pbufs). This must be at least = 2 *
TCP_SND_BUF/TCP_MSS for things to work. */
#define TCP_SND_QUEUELEN (4 * TCP_SND_BUF/TCP_MSS)
/* TCP writable space (bytes). This must be less than or equal
to TCP_SND_BUF. It is the amount of space which must be
available in the tcp snd_buf for select to return writable */
#define TCP_SNDLOWAT (TCP_SND_BUF/2)
/* TCP receive window. */
#define TCP_WND 8096
/* Maximum number of retransmissions of data segments. */
#define TCP_MAXRTX 12
/* Maximum number of retransmissions of SYN segments. */
#define TCP_SYNMAXRTX 4
/* ---------- ARP options ---------- */
#define LWIP_ARP 1
#define ARP_TABLE_SIZE 10
#define ARP_QUEUEING 1
/* ---------- IP options ---------- */
/* Define IP_FORWARD to 1 if you wish to have the ability to forward
IP packets across network interfaces. If you are going to run lwIP
on a device with only one network interface, define this to 0. */
#define IP_FORWARD 1
/* IP reassembly and segmentation.These are orthogonal even
* if they both deal with IP fragments */
#define IP_REASSEMBLY 1
#define IP_REASS_MAX_PBUFS 10
#define MEMP_NUM_REASSDATA 10
#define IP_FRAG 1
#define IPV6_FRAG_COPYHEADER 1
#define LWIP_IPV6_FRAG 1
#define LWIP_IGMP (LWIP_IPV4)
/* ---------- ICMP options ---------- */
#define ICMP_TTL 255
/* ---------- DHCP options ---------- */
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
interfaces. */
#define LWIP_DHCP 0
#define LWIP_DHCP_GET_NTP_SRV (LWIP_DHCP)
/* 1 if you want to do an ARP check on the offered address
(recommended if using DHCP). */
#define DHCP_DOES_ARP_CHECK (LWIP_DHCP)
/* ---------- AUTOIP options ------- */
#define LWIP_AUTOIP (LWIP_DHCP)
#define LWIP_DHCP_AUTOIP_COOP (LWIP_DHCP)
#define LWIP_DHCP_AUTOIP_COOP_TRIES 3
/* ---------- SNTP options --------- */
extern void sntp_set_system_time(u32_t sec);
#define SNTP_SET_SYSTEM_TIME(s) sntp_set_system_time(s)
/* ---------- SNMP options ---------- */
#define LWIP_SNMP (LWIP_UDP)
#ifdef LWIP_HAVE_MBEDTLS
#define LWIP_SNMP_V3 (LWIP_SNMP)
#endif
#define MIB2_STATS (LWIP_SNMP)
#define SNMP_USE_NETCONN (LWIP_NETCONN)
#define SNMP_USE_RAW (!LWIP_NETCONN)
/* ---------- DNS options ---------- */
#define LWIP_DNS 1
/* ---------- MDNS options ---------- */
#define LWIP_MDNS_RESPONDER 1
#define LWIP_NUM_NETIF_CLIENT_DATA (LWIP_MDNS_RESPONDER)
/* ---------- UDP options ---------- */
#define LWIP_UDP 1
#define UDP_TTL 255
/* ---------- RAW options ---------- */
#define LWIP_RAW 1
#define RAW_TTL 255
/* ---------- Statistics options ---------- */
/* individual STATS options can be turned off by defining them to 0
* (e.g #define TCP_STATS 0). All of them are turned off if LWIP_STATS
* is 0
* */
#define LWIP_STATS 1
#define LWIP_NETIF_API 1
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
#define LWIP_NETIF_HOSTNAME 0
/* ---------- SLIP options ---------- */
#define LWIP_HAVE_SLIPIF 1 /* Set > 0 for SLIP */
/* Maximum packet size that is received by this netif */
#define SLIP_MAX_SIZE 1500
#define sio_tryread sio_read
/* ---------- 6LoWPAN options ---------- */
#define LWIP_6LOWPAN 1
/* ---------- PPP options ---------- */
#define PPP_SUPPORT 1 /* Set > 0 for PPP */
#define MPPE_SUPPORT PPP_SUPPORT
#define PPPOE_SUPPORT PPP_SUPPORT
#define PPPOL2TP_SUPPORT PPP_SUPPORT
#define PPPOS_SUPPORT PPP_SUPPORT
#if PPP_SUPPORT > 0
#define NUM_PPP 1 /* Max PPP sessions. */
/* Select modules to enable. Ideally these would be set in the makefile but
* we're limited by the command line length so you need to modify the settings
* in this file.
*/
#define PAP_SUPPORT 1 /* Set > 0 for PAP. */
#define CHAP_SUPPORT 1 /* Set > 0 for CHAP. */
#define MSCHAP_SUPPORT 0 /* Set > 0 for MSCHAP (NOT FUNCTIONAL!) */
#define CBCP_SUPPORT 0 /* Set > 0 for CBCP (NOT FUNCTIONAL!) */
#define CCP_SUPPORT 0 /* Set > 0 for CCP (NOT FUNCTIONAL!) */
#define VJ_SUPPORT 1 /* Set > 0 for VJ header compression. */
#define MD5_SUPPORT 1 /* Set > 0 for MD5 (see also CHAP) */
/*
* Timeouts.
*/
#define FSM_DEFTIMEOUT 6 /* Timeout time in seconds */
#define FSM_DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */
#define FSM_DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */
#define FSM_DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */
#define UPAP_DEFTIMEOUT 6 /* Timeout (seconds) for retransmitting req */
#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */
#define CHAP_DEFTIMEOUT 6 /* Timeout time in seconds */
#define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */
/* Interval in seconds between keepalive echo requests, 0 to disable. */
#if 1
#define LCP_ECHOINTERVAL 0
#else
#define LCP_ECHOINTERVAL 10
#endif
/* Number of unanswered echo requests before failure. */
#define LCP_MAXECHOFAILS 3
/* Max Xmit idle time (in jiffies) before resend flag char. */
#define PPP_MAXIDLEFLAG 100
/*
* Packet sizes
*
* Note - lcp shouldn't be allowed to negotiate stuff outside these
* limits. See lcp.h in the pppd directory.
* (XXX - these constants should simply be shared by lcp.c instead
* of living in lcp.h)
*/
#define PPP_MTU 1500 /* Default MTU (size of Info field) */
#if 0
#define PPP_MAXMTU 65535 - (PPP_HDRLEN + PPP_FCSLEN)
#else
#define PPP_MAXMTU 1500 /* Largest MTU we allow */
#endif
#define PPP_MINMTU 64
#define PPP_MRU 1500 /* default MRU = max length of info field */
#define PPP_MAXMRU 1500 /* Largest MRU we allow */
#define PPP_DEFMRU 296 /* Try for this */
#define PPP_MINMRU 128 /* No MRUs below this */
#define MAXNAMELEN 256 /* max length of hostname or name for auth */
#define MAXSECRETLEN 256 /* max length of password or secret */
#endif /* PPP_SUPPORT > 0 */
#define LWIP_HTTPD_SSI 1
#endif /* LWIP_LWIPOPTS_H */

View File

@@ -0,0 +1,670 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include <unistd.h>
#include <fcntl.h>
#include <getopt.h>
#include <time.h>
#include <string.h>
#include "lwip/opt.h"
#include "lwip/init.h"
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/sys.h"
#include "lwip/timeouts.h"
#include "lwip/ip_addr.h"
#include "lwip/dns.h"
#include "lwip/dhcp.h"
#include "lwip/stats.h"
#include "lwip/tcp.h"
#include "lwip/inet_chksum.h"
#include "lwip/tcpip.h"
#include "lwip/sockets.h"
#include "netif/tapif.h"
#include "netif/tunif.h"
#include "netif/unixif.h"
#include "netif/dropif.h"
#include "netif/pcapif.h"
#include "netif/tcpdump.h"
#ifndef LWIP_HAVE_SLIPIF
#define LWIP_HAVE_SLIPIF 0
#endif
#if LWIP_HAVE_SLIPIF
#include "netif/slipif.h"
#define SLIP_PTY_TEST 1
#endif
#if PPP_SUPPORT
#include "netif/ppp/pppos.h"
#include "lwip/sio.h"
#define PPP_PTY_TEST 1
#include <termios.h>
#endif
#include "lwip/ip_addr.h"
#include "arch/perf.h"
#include "lwip/apps/httpd.h"
#include "apps/udpecho/udpecho.h"
#include "apps/tcpecho/tcpecho.h"
#include "apps/shell/shell.h"
#include "apps/chargen/chargen.h"
#include "apps/netio/netio.h"
#include "apps/ping/ping.h"
#include "lwip/apps/netbiosns.h"
#include "lwip/apps/mdns.h"
#include "lwip/apps/sntp.h"
#include "lwip/apps/snmp.h"
#include "lwip/apps/snmp_mib2.h"
#include "apps/snmp_private_mib/private_mib.h"
#include "lwip/apps/snmpv3.h"
#include "apps/snmp_v3/snmpv3_dummy.h"
#include "lwip/apps/snmp_snmpv2_framework.h"
#include "lwip/apps/snmp_snmpv2_usm.h"
#include "lwip/apps/tftp_server.h"
#include "addons/tcp_isn/tcp_isn.h"
#if LWIP_RAW
#include "lwip/icmp.h"
#include "lwip/raw.h"
#endif
#if LWIP_SNMP
static const struct snmp_mib *mibs[] = {
&mib2,
&mib_private
#if LWIP_SNMP_V3
, &snmpframeworkmib
, &snmpusmmib
#endif
};
#endif /* LWIP_SNMP */
#if LWIP_IPV4
/* (manual) host IP configuration */
static ip_addr_t ipaddr, netmask, gw;
#endif /* LWIP_IPV4 */
struct netif netif;
/* ping out destination cmd option */
static unsigned char ping_flag;
static ip_addr_t ping_addr;
/* nonstatic debug cmd option, exported in lwipopts.h */
unsigned char debug_flags;
/** @todo add options for selecting netif, starting DHCP client etc */
static struct option longopts[] = {
/* turn on debugging output (if build with LWIP_DEBUG) */
{"debug", no_argument, NULL, 'd'},
/* help */
{"help", no_argument, NULL, 'h'},
#if LWIP_IPV4
/* gateway address */
{"gateway", required_argument, NULL, 'g'},
/* ip address */
{"ipaddr", required_argument, NULL, 'i'},
/* netmask */
{"netmask", required_argument, NULL, 'm'},
/* ping destination */
{"ping", required_argument, NULL, 'p'},
#endif /* LWIP_IPV4 */
/* new command line options go here! */
{NULL, 0, NULL, 0}
};
#define NUM_OPTS ((sizeof(longopts) / sizeof(struct option)) - 1)
static void init_netifs(void);
static void usage(void)
{
unsigned char i;
printf("options:\n");
for (i = 0; i < NUM_OPTS; i++) {
printf("-%c --%s\n",longopts[i].val, longopts[i].name);
}
}
#if 0
static void
tcp_debug_timeout(void *data)
{
LWIP_UNUSED_ARG(data);
#if TCP_DEBUG
tcp_debug_print_pcbs();
#endif /* TCP_DEBUG */
sys_timeout(5000, tcp_debug_timeout, NULL);
}
#endif
void
sntp_set_system_time(u32_t sec)
{
char buf[32];
struct tm current_time_val;
time_t current_time = (time_t)sec;
localtime_r(&current_time, &current_time_val);
strftime(buf, sizeof(buf), "%d.%m.%Y %H:%M:%S", &current_time_val);
printf("SNTP time: %s\n", buf);
}
#if LWIP_MDNS_RESPONDER
static void
srv_txt(struct mdns_service *service, void *txt_userdata)
{
err_t res;
LWIP_UNUSED_ARG(txt_userdata);
res = mdns_resp_add_service_txtitem(service, "path=/", 6);
LWIP_ERROR("mdns add service txt failed\n", (res == ERR_OK), return);
}
#endif
#if LWIP_UDP
static void*
tftp_open(const char* fname, const char* mode, u8_t is_write)
{
LWIP_UNUSED_ARG(mode);
if (is_write) {
return (void*)fopen(fname, "wb");
} else {
return (void*)fopen(fname, "rb");
}
}
static void
tftp_close(void* handle)
{
fclose((FILE*)handle);
}
static int
tftp_read(void* handle, void* buf, int bytes)
{
int ret = fread(buf, 1, bytes, (FILE*)handle);
if (ret <= 0) {
return -1;
}
return ret;
}
static int
tftp_write(void* handle, struct pbuf* p)
{
while (p != NULL) {
if (fwrite(p->payload, 1, p->len, (FILE*)handle) != (size_t)p->len) {
return -1;
}
p = p->next;
}
return 0;
}
static const struct tftp_context tftp = {
tftp_open,
tftp_close,
tftp_read,
tftp_write
};
#endif /* LWIP_UDP */
static void
tcpip_init_done(void *arg)
{
sys_sem_t *sem;
sem = (sys_sem_t *)arg;
init_netifs();
#if LWIP_IPV4
netbiosns_set_name("simhost");
netbiosns_init();
#endif /* LWIP_IPV4 */
sntp_setoperatingmode(SNTP_OPMODE_POLL);
#if LWIP_DHCP
sntp_servermode_dhcp(1); /* get SNTP server via DHCP */
#else /* LWIP_DHCP */
#if LWIP_IPV4
sntp_setserver(0, netif_ip_gw4(&netif));
#endif /* LWIP_IPV4 */
#endif /* LWIP_DHCP */
sntp_init();
#if LWIP_SNMP
lwip_privmib_init();
#if SNMP_LWIP_MIB2
#if SNMP_USE_NETCONN
snmp_threadsync_init(&snmp_mib2_lwip_locks, snmp_mib2_lwip_synchronizer);
#endif /* SNMP_USE_NETCONN */
snmp_mib2_set_syscontact_readonly((const u8_t*)"root", NULL);
snmp_mib2_set_syslocation_readonly((const u8_t*)"lwIP development PC", NULL);
snmp_mib2_set_sysdescr((const u8_t*)"simhost", NULL);
#endif /* SNMP_LWIP_MIB2 */
#if LWIP_SNMP_V3
snmpv3_dummy_init();
#endif
snmp_set_mibs(mibs, LWIP_ARRAYSIZE(mibs));
snmp_init();
#endif /* LWIP_SNMP */
#if LWIP_MDNS_RESPONDER
mdns_resp_init();
mdns_resp_add_netif(&netif, "simhost", 3600);
mdns_resp_add_service(&netif, "myweb", "_http", DNSSD_PROTO_TCP, 80, 3600, srv_txt, NULL);
#endif
#if LWIP_UDP
tftp_init(&tftp);
#endif /* LWIP_UDP */
sys_sem_signal(sem);
}
/*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
#if LWIP_HAVE_SLIPIF
/* (manual) host IP configuration */
#if LWIP_IPV4
static ip_addr_t ipaddr_slip, netmask_slip, gw_slip;
#endif /* LWIP_IPV4 */
struct netif slipif;
#endif /* LWIP_HAVE_SLIPIF */
#if PPP_SUPPORT
sio_fd_t ppp_sio;
ppp_pcb *ppp;
struct netif pppos_netif;
static void
pppos_rx_thread(void *arg)
{
u32_t len;
u8_t buffer[128];
LWIP_UNUSED_ARG(arg);
/* Please read the "PPPoS input path" chapter in the PPP documentation. */
while (1) {
len = sio_read(ppp_sio, buffer, sizeof(buffer));
if (len > 0) {
/* Pass received raw characters from PPPoS to be decoded through lwIP
* TCPIP thread using the TCPIP API. This is thread safe in all cases
* but you should avoid passing data byte after byte. */
pppos_input_tcpip(ppp, buffer, len);
}
}
}
static void
ppp_link_status_cb(ppp_pcb *pcb, int err_code, void *ctx)
{
struct netif *pppif = ppp_netif(pcb);
LWIP_UNUSED_ARG(ctx);
switch(err_code) {
case PPPERR_NONE: /* No error. */
{
#if LWIP_DNS
const ip_addr_t *ns;
#endif /* LWIP_DNS */
fprintf(stderr, "ppp_link_status_cb: PPPERR_NONE\n\r");
#if LWIP_IPV4
fprintf(stderr, " our_ip4addr = %s\n\r", ip4addr_ntoa(netif_ip4_addr(pppif)));
fprintf(stderr, " his_ipaddr = %s\n\r", ip4addr_ntoa(netif_ip4_gw(pppif)));
fprintf(stderr, " netmask = %s\n\r", ip4addr_ntoa(netif_ip4_netmask(pppif)));
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
fprintf(stderr, " our_ip6addr = %s\n\r", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
#endif /* LWIP_IPV6 */
#if LWIP_DNS
ns = dns_getserver(0);
fprintf(stderr, " dns1 = %s\n\r", ipaddr_ntoa(ns));
ns = dns_getserver(1);
fprintf(stderr, " dns2 = %s\n\r", ipaddr_ntoa(ns));
#endif /* LWIP_DNS */
#if PPP_IPV6_SUPPORT
fprintf(stderr, " our6_ipaddr = %s\n\r", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
#endif /* PPP_IPV6_SUPPORT */
}
break;
case PPPERR_PARAM: /* Invalid parameter. */
printf("ppp_link_status_cb: PPPERR_PARAM\n");
break;
case PPPERR_OPEN: /* Unable to open PPP session. */
printf("ppp_link_status_cb: PPPERR_OPEN\n");
break;
case PPPERR_DEVICE: /* Invalid I/O device for PPP. */
printf("ppp_link_status_cb: PPPERR_DEVICE\n");
break;
case PPPERR_ALLOC: /* Unable to allocate resources. */
printf("ppp_link_status_cb: PPPERR_ALLOC\n");
break;
case PPPERR_USER: /* User interrupt. */
printf("ppp_link_status_cb: PPPERR_USER\n");
break;
case PPPERR_CONNECT: /* Connection lost. */
printf("ppp_link_status_cb: PPPERR_CONNECT\n");
break;
case PPPERR_AUTHFAIL: /* Failed authentication challenge. */
printf("ppp_link_status_cb: PPPERR_AUTHFAIL\n");
break;
case PPPERR_PROTOCOL: /* Failed to meet protocol. */
printf("ppp_link_status_cb: PPPERR_PROTOCOL\n");
break;
case PPPERR_PEERDEAD: /* Connection timeout. */
printf("ppp_link_status_cb: PPPERR_PEERDEAD\n");
break;
case PPPERR_IDLETIMEOUT: /* Idle Timeout. */
printf("ppp_link_status_cb: PPPERR_IDLETIMEOUT\n");
break;
case PPPERR_CONNECTTIME: /* PPPERR_CONNECTTIME. */
printf("ppp_link_status_cb: PPPERR_CONNECTTIME\n");
break;
case PPPERR_LOOPBACK: /* Connection timeout. */
printf("ppp_link_status_cb: PPPERR_LOOPBACK\n");
break;
default:
printf("ppp_link_status_cb: unknown errCode %d\n", err_code);
break;
}
}
static u32_t
ppp_output_cb(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx)
{
LWIP_UNUSED_ARG(pcb);
LWIP_UNUSED_ARG(ctx);
return sio_write(ppp_sio, data, len);
}
#endif
#if LWIP_NETIF_STATUS_CALLBACK
static void
netif_status_callback(struct netif *nif)
{
printf("NETIF: %c%c%d is %s\n", nif->name[0], nif->name[1], nif->num,
netif_is_up(nif) ? "UP" : "DOWN");
#if LWIP_IPV4
printf("IPV4: Host at %s ", ip4addr_ntoa(netif_ip4_addr(nif)));
printf("mask %s ", ip4addr_ntoa(netif_ip4_netmask(nif)));
printf("gateway %s\n", ip4addr_ntoa(netif_ip4_gw(nif)));
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
printf("IPV6: Host at %s\n", ip6addr_ntoa(netif_ip6_addr(nif, 0)));
#endif /* LWIP_IPV6 */
#if LWIP_NETIF_HOSTNAME
printf("FQDN: %s\n", netif_get_hostname(nif));
#endif /* LWIP_NETIF_HOSTNAME */
}
#endif /* LWIP_NETIF_STATUS_CALLBACK */
static void
init_netifs(void)
{
#if LWIP_HAVE_SLIPIF
#if SLIP_PTY_TEST
u8_t siodev_slip = 3;
#else
u8_t siodev_slip = 0;
#endif
#if LWIP_IPV4
netif_add(&slipif, ip_2_ip4(&ipaddr_slip), ip_2_ip4(&netmask_slip), ip_2_ip4(&gw_slip),
(void*)&siodev_slip, slipif_init, tcpip_input);
#else /* LWIP_IPV4 */
netif_add(&slipif, (void*)&siodev_slip, slipif_init, tcpip_input);
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
netif_create_ip6_linklocal_address(&slipif, 1);
#endif
#if LWIP_NETIF_STATUS_CALLBACK
netif_set_status_callback(&slipif, netif_status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
netif_set_link_up(&slipif);
netif_set_up(&slipif);
#endif /* LWIP_HAVE_SLIPIF */
#if PPP_SUPPORT
#if PPP_PTY_TEST
ppp_sio = sio_open(2);
#else
ppp_sio = sio_open(0);
#endif
if(!ppp_sio)
{
perror("Error opening device: ");
exit(1);
}
ppp = pppos_create(&pppos_netif, ppp_output_cb, ppp_link_status_cb, NULL);
if (!ppp)
{
printf("Could not create PPP control interface");
exit(1);
}
#ifdef LWIP_PPP_CHAP_TEST
ppp_set_auth(ppp, PPPAUTHTYPE_CHAP, "lwip", "mysecret");
#endif
ppp_connect(ppp, 0);
#if LWIP_NETIF_STATUS_CALLBACK
netif_set_status_callback(&pppos_netif, netif_status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#endif /* PPP_SUPPORT */
#if LWIP_IPV4
#if LWIP_DHCP
IP_ADDR4(&gw, 0,0,0,0);
IP_ADDR4(&ipaddr, 0,0,0,0);
IP_ADDR4(&netmask, 0,0,0,0);
#endif /* LWIP_DHCP */
netif_add(&netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw), NULL, tapif_init, tcpip_input);
#else /* LWIP_IPV4 */
netif_add(&netif, NULL, tapif_init, tcpip_input);
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
netif_create_ip6_linklocal_address(&netif, 1);
netif.ip6_autoconfig_enabled = 1;
#endif
#if LWIP_NETIF_STATUS_CALLBACK
netif_set_status_callback(&netif, netif_status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
netif_set_default(&netif);
netif_set_up(&netif);
#if LWIP_DHCP
dhcp_start(&netif);
#endif /* LWIP_DHCP */
#if 0
/* Only used for testing purposes: */
netif_add(&ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input);
#endif
#if LWIP_TCP
netio_init();
#endif
#if LWIP_TCP && LWIP_NETCONN
tcpecho_init();
shell_init();
httpd_init();
#endif
#if LWIP_UDP && LWIP_NETCONN
udpecho_init();
#endif
#if LWIP_SOCKET
chargen_init();
#endif
/* sys_timeout(5000, tcp_debug_timeout, NULL);*/
}
/*-----------------------------------------------------------------------------------*/
static void
main_thread(void *arg)
{
sys_sem_t sem;
LWIP_UNUSED_ARG(arg);
lwip_init_tcp_isn(sys_now(), (u8_t*)&netif);
if(sys_sem_new(&sem, 0) != ERR_OK) {
LWIP_ASSERT("Failed to create semaphore", 0);
}
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(&sem);
printf("TCP/IP initialized.\n");
#if LWIP_SOCKET
if (ping_flag) {
ping_init(&ping_addr);
}
#endif
printf("Applications started.\n");
#ifdef MEM_PERF
mem_perf_init("/tmp/memstats.client");
#endif /* MEM_PERF */
#if 0
stats_display();
#endif
#if PPP_SUPPORT
/* Block forever. */
sys_thread_new("pppos_rx_thread", pppos_rx_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
sys_sem_wait(&sem);
#endif
}
/*-----------------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
int ch;
char ip_str[IPADDR_STRLEN_MAX] = {0};
/* startup defaults (may be overridden by one or more opts) */
#if LWIP_IPV4
IP_ADDR4(&gw, 192,168, 0,1);
IP_ADDR4(&netmask, 255,255,255,0);
IP_ADDR4(&ipaddr, 192,168, 0,2);
#if LWIP_HAVE_SLIPIF
IP_ADDR4(&gw_slip, 192,168, 2, 1);
IP_ADDR4(&netmask_slip, 255,255,255,255);
IP_ADDR4(&ipaddr_slip, 192,168, 2, 2);
#endif
#endif /* LWIP_IPV4 */
ping_flag = 0;
/* use debug flags defined by debug.h */
debug_flags = LWIP_DBG_OFF;
while ((ch = getopt_long(argc, argv, "dhg:i:m:p:", longopts, NULL)) != -1) {
switch (ch) {
case 'd':
debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT);
break;
case 'h':
usage();
exit(0);
break;
#if LWIP_IPV4
case 'g':
ipaddr_aton(optarg, &gw);
break;
case 'i':
ipaddr_aton(optarg, &ipaddr);
break;
case 'm':
ipaddr_aton(optarg, &netmask);
break;
#endif /* LWIP_IPV4 */
case 'p':
ping_flag = !0;
ipaddr_aton(optarg, &ping_addr);
strncpy(ip_str,ipaddr_ntoa(&ping_addr),sizeof(ip_str));
ip_str[sizeof(ip_str)-1] = 0; /* ensure \0 termination */
printf("Using %s to ping\n", ip_str);
break;
default:
usage();
break;
}
}
argc -= optind;
argv += optind;
#ifdef PERF
perf_init("/tmp/simhost.perf");
#endif /* PERF */
printf("System initialized.\n");
sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
pause();
return 0;
}
/*-----------------------------------------------------------------------------------*/

View File

@@ -0,0 +1,181 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/debug.h"
#include <unistd.h>
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/sys.h"
#include "lwip/tcp.h"
#include "lwip/priv/tcp_priv.h" /* for tcp_debug_print_pcbs() */
#include "lwip/timeouts.h"
#include "lwip/stats.h"
#include "lwip/tcpip.h"
#include "netif/unixif.h"
#include "netif/dropif.h"
#include "netif/tcpdump.h"
#include "lwip/ip_addr.h"
#include "arch/perf.h"
#include "lwip/apps/httpd.h"
#include "apps/udpecho/udpecho.h"
#include "apps/tcpecho/tcpecho.h"
#include "apps/shell/shell.h"
#if LWIP_IPV4 /* @todo: IPv6 */
/* nonstatic debug cmd option, exported in lwipopts.h */
unsigned char debug_flags;
/*-----------------------------------------------------------------------------------*/
static void
tcp_timeout(void *data)
{
LWIP_UNUSED_ARG(data);
#if TCP_DEBUG && LWIP_TCP
tcp_debug_print_pcbs();
#endif /* TCP_DEBUG */
sys_timeout(5000, tcp_timeout, NULL);
}
/*-----------------------------------------------------------------------------------*/
struct netif netif_unix;
/*-----------------------------------------------------------------------------------*/
static void
tcpip_init_done(void *arg)
{
ip4_addr_t ipaddr, netmask, gw;
sys_sem_t *sem;
sem = (sys_sem_t *)arg;
IP4_ADDR(&gw, 192,168,1,1);
IP4_ADDR(&ipaddr, 192,168,1,2);
IP4_ADDR(&netmask, 255,255,255,0);
netif_set_default(netif_add(&netif_unix, &ipaddr, &netmask, &gw, NULL, unixif_init_client,
tcpip_input));
netif_set_up(&netif_unix);
#if LWIP_IPV6
netif_create_ip6_linklocal_address(&netif_unix, 1);
#endif
/* netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, sioslipif_init1,
tcpip_input)); */
#if LWIP_NETCONN
tcpecho_init();
shell_init();
#if LWIP_IPV4 && LWIP_TCP
httpd_init();
#endif
udpecho_init();
#endif
printf("Applications started.\n");
sys_timeout(5000, tcp_timeout, NULL);
sys_sem_signal(sem);
}
/*-----------------------------------------------------------------------------------*/
static void
main_thread(void *arg)
{
sys_sem_t sem;
LWIP_UNUSED_ARG(arg);
if(sys_sem_new(&sem, 0) != ERR_OK) {
LWIP_ASSERT("Failed to create semaphore", 0);
}
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(&sem);
printf("TCP/IP initialized.\n");
#ifdef MEM_PERF
mem_perf_init("/tmp/memstats.client");
#endif /* MEM_PERF */
/* Block forever. */
sys_sem_wait(&sem);
}
/*-----------------------------------------------------------------------------------*/
int
main(void)
{
#ifdef PERF
perf_init("/tmp/client.perf");
#endif /* PERF */
#if LWIP_IPV4 && LWIP_TCP
tcpdump_init();
#endif
printf("System initialized.\n");
sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
pause();
return 0;
}
#else /* LWIP_IPV4 */
int
main(int argc, char **argv)
{
LWIP_UNUSED_ARG(argc);
LWIP_UNUSED_ARG(argv);
printf("simnode only works with IPv4\n");
return 0;
}
#endif /* LWIP_IPV4 */
/* dummy, because SNTP is pulled in via LWIP_DHCP_GET_NTP_SRV */
void
sntp_set_system_time(u32_t sec)
{
LWIP_UNUSED_ARG(sec);
}
/*-----------------------------------------------------------------------------------*/

View File

@@ -0,0 +1,203 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/debug.h"
#include <unistd.h>
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/sys.h"
#include "lwip/tcp.h"
#include "lwip/priv/tcp_priv.h" /* for tcp_debug_print_pcbs() */
#include "lwip/timeouts.h"
#include "lwip/stats.h"
#include "lwip/tcpip.h"
#include "netif/tapif.h"
#include "netif/unixif.h"
#include "netif/dropif.h"
#include "netif/tcpdump.h"
#include "lwip/ip_addr.h"
#include "arch/perf.h"
#include "lwip/apps/httpd.h"
#include "apps/udpecho/udpecho.h"
#include "apps/tcpecho/tcpecho.h"
#include "apps/shell/shell.h"
#if LWIP_IPV4 /* @todo: IPv6 */
/* nonstatic debug cmd option, exported in lwipopts.h */
unsigned char debug_flags;
/*-----------------------------------------------------------------------------------*/
static void
tcp_timeout(void *data)
{
LWIP_UNUSED_ARG(data);
#if TCP_DEBUG && LWIP_TCP
tcp_debug_print_pcbs();
#endif /* TCP_DEBUG */
sys_timeout(5000, tcp_timeout, NULL);
}
/*-----------------------------------------------------------------------------------*/
struct netif netif_tap, netif_unix;
/*-----------------------------------------------------------------------------------*/
static void
tcpip_init_done(void *arg)
{
ip4_addr_t ipaddr, netmask, gw;
sys_sem_t *sem;
sem = (sys_sem_t *)arg;
IP4_ADDR(&gw, 192,168,0,1);
IP4_ADDR(&ipaddr, 192,168,0,2);
IP4_ADDR(&netmask, 255,255,255,0);
netif_set_default(netif_add(&netif_tap, &ipaddr, &netmask, &gw, NULL, tapif_init,
tcpip_input));
netif_set_up(&netif_tap);
#if LWIP_IPV6
netif_create_ip6_linklocal_address(&netif_tap, 1);
#endif
IP4_ADDR(&gw, 192,168,1,1);
IP4_ADDR(&ipaddr, 192,168,1,1);
IP4_ADDR(&netmask, 255,255,255,0);
netif_set_default(netif_add(&netif_unix, &ipaddr, &netmask, &gw, NULL, unixif_init_server,
tcpip_input));
netif_set_up(&netif_unix);
#if LWIP_IPV6
netif_create_ip6_linklocal_address(&netif_unix, 1);
#endif
if(system("route add 192.168.1.1 192.168.0.2") != 0) {
return;
}
if(system("route add 192.168.1.2 192.168.0.2") != 0) {
return;
}
/*netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, sioslipif_init1,
tcpip_input)); */
#if LWIP_NETCONN
tcpecho_init();
shell_init();
#if LWIP_IPV4 && LWIP_TCP
httpd_init();
#endif
udpecho_init();
#endif
printf("Applications started.\n");
sys_timeout(5000, tcp_timeout, NULL);
sys_sem_signal(sem);
}
static void
main_thread(void *arg)
{
sys_sem_t sem;
LWIP_UNUSED_ARG(arg);
if(sys_sem_new(&sem, 0) != ERR_OK) {
LWIP_ASSERT("Failed to create semaphore", 0);
}
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(&sem);
printf("TCP/IP initialized.\n");
#ifdef MEM_PERF
mem_perf_init("/tmp/memstats.client");
#endif /* MEM_PERF */
/* Block forever. */
sys_sem_wait(&sem);
}
/*-----------------------------------------------------------------------------------*/
int
main(void)
{
#ifdef PERF
perf_init("/tmp/client.perf");
#endif /* PERF */
#if LWIP_IPV4 && LWIP_TCP
tcpdump_init();
#endif
printf("System initialized.\n");
sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
pause();
return 0;
}
#else /* LWIP_IPV4 */
int
main(int argc, char **argv)
{
LWIP_UNUSED_ARG(argc);
LWIP_UNUSED_ARG(argv);
printf("simrouter only works with IPv4\n");
return 0;
}
#endif /* LWIP_IPV4 */
/* dummy, because SNTP is pulled in via LWIP_DHCP_GET_NTP_SRV */
void
sntp_set_system_time(u32_t sec)
{
LWIP_UNUSED_ARG(sec);
}
/*-----------------------------------------------------------------------------------*/