2003-01-31 13:35:43 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2006-07-03 07:16:48 +00:00
|
|
|
* RT timer modifications by Christiaan Simons
|
2003-01-31 13:35:43 +00:00
|
|
|
*/
|
|
|
|
|
2006-09-12 07:11:22 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
2008-01-15 13:10:51 +00:00
|
|
|
|
|
|
|
#include "lwip/init.h"
|
|
|
|
|
2003-01-31 13:35:43 +00:00
|
|
|
#include "lwip/debug.h"
|
|
|
|
|
|
|
|
#include "lwip/mem.h"
|
|
|
|
#include "lwip/memp.h"
|
|
|
|
#include "lwip/sys.h"
|
|
|
|
|
|
|
|
#include "lwip/stats.h"
|
|
|
|
|
|
|
|
#include "lwip/ip.h"
|
2006-03-02 16:28:49 +00:00
|
|
|
#include "lwip/ip_frag.h"
|
2003-01-31 13:35:43 +00:00
|
|
|
#include "lwip/udp.h"
|
2006-08-21 10:21:54 +00:00
|
|
|
#include "lwip/snmp_msg.h"
|
2003-01-31 13:35:43 +00:00
|
|
|
#include "lwip/tcp.h"
|
|
|
|
#include "mintapif.h"
|
2006-03-02 16:28:49 +00:00
|
|
|
#include "netif/etharp.h"
|
2003-01-31 13:35:43 +00:00
|
|
|
|
2006-07-03 07:16:48 +00:00
|
|
|
#include "timer.h"
|
|
|
|
#include <signal.h>
|
|
|
|
|
2004-04-29 21:52:25 +00:00
|
|
|
#include "echo.h"
|
2006-10-06 09:59:46 +00:00
|
|
|
#include "private_mib.h"
|
2006-09-12 07:11:22 +00:00
|
|
|
|
|
|
|
/* (manual) host IP configuration */
|
|
|
|
static struct ip_addr ipaddr, netmask, gw;
|
|
|
|
|
|
|
|
/* SNMP trap destination cmd option */
|
|
|
|
static unsigned char trap_flag;
|
|
|
|
static struct ip_addr trap_addr;
|
|
|
|
|
|
|
|
/* nonstatic debug cmd option, exported in lwipopts.h */
|
|
|
|
unsigned char debug_flags;
|
|
|
|
|
|
|
|
/* 'non-volatile' SNMP settings
|
|
|
|
@todo: make these truly non-volatile */
|
|
|
|
u8_t syscontact_str[255];
|
|
|
|
u8_t syscontact_len = 0;
|
|
|
|
u8_t syslocation_str[255];
|
|
|
|
u8_t syslocation_len = 0;
|
|
|
|
/* enable == 1, disable == 2 */
|
|
|
|
u8_t snmpauthentraps_set = 2;
|
|
|
|
|
|
|
|
static struct option longopts[] = {
|
|
|
|
/* turn on debugging output (if build with LWIP_DEBUG) */
|
|
|
|
{"debug", no_argument, NULL, 'd'},
|
|
|
|
/* help */
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
/* gateway address */
|
|
|
|
{"gateway", required_argument, NULL, 'g'},
|
|
|
|
/* ip address */
|
|
|
|
{"ipaddr", required_argument, NULL, 'i'},
|
|
|
|
/* netmask */
|
|
|
|
{"netmask", required_argument, NULL, 'm'},
|
|
|
|
/* ping destination */
|
|
|
|
{"trap_destination", required_argument, NULL, 't'},
|
|
|
|
/* new command line options go here! */
|
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
#define NUM_OPTS ((sizeof(longopts) / sizeof(struct option)) - 1)
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-31 13:35:43 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2003-11-24 08:24:55 +00:00
|
|
|
struct netif netif;
|
2006-07-03 07:16:48 +00:00
|
|
|
sigset_t mask, oldmask, empty;
|
2006-09-12 07:11:22 +00:00
|
|
|
int ch;
|
|
|
|
char ip_str[16] = {0}, nm_str[16] = {0}, gw_str[16] = {0};
|
|
|
|
|
|
|
|
/* startup defaults (may be overridden by one or more opts) */
|
|
|
|
IP4_ADDR(&gw, 192,168,0,1);
|
|
|
|
IP4_ADDR(&ipaddr, 192,168,0,2);
|
|
|
|
IP4_ADDR(&netmask, 255,255,255,0);
|
|
|
|
|
|
|
|
trap_flag = 0;
|
|
|
|
/* use debug flags defined by debug.h */
|
2007-04-05 09:21:12 +00:00
|
|
|
debug_flags = LWIP_DBG_OFF;
|
2006-09-12 07:11:22 +00:00
|
|
|
|
|
|
|
while ((ch = getopt_long(argc, argv, "dhg:i:m:t:", longopts, NULL)) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'd':
|
2007-04-05 09:21:12 +00:00
|
|
|
debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT);
|
2006-09-12 07:11:22 +00:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
case 'g':
|
2010-01-30 14:16:47 +00:00
|
|
|
ipaddr_aton(optarg, &gw);
|
2006-09-12 07:11:22 +00:00
|
|
|
break;
|
|
|
|
case 'i':
|
2010-01-30 14:16:47 +00:00
|
|
|
ipaddr_aton(optarg, &ipaddr);
|
2006-09-12 07:11:22 +00:00
|
|
|
break;
|
|
|
|
case 'm':
|
2010-01-30 14:16:47 +00:00
|
|
|
ipaddr_aton(optarg, &netmask);
|
2006-09-12 07:11:22 +00:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
trap_flag = !0;
|
|
|
|
/* @todo: remove this authentraps tweak
|
|
|
|
when we have proper SET & non-volatile mem */
|
|
|
|
snmpauthentraps_set = 1;
|
2010-01-30 14:16:47 +00:00
|
|
|
ipaddr_aton(optarg, &trap_addr);
|
|
|
|
strncpy(ip_str, ipaddr_ntoa(&trap_addr),sizeof(ip_str));
|
2006-09-12 07:11:22 +00:00
|
|
|
printf("SNMP trap destination %s\n", ip_str);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2010-01-30 14:16:47 +00:00
|
|
|
|
|
|
|
strncpy(ip_str, ipaddr_ntoa(&ipaddr), sizeof(ip_str));
|
|
|
|
strncpy(nm_str, ipaddr_ntoa(&netmask), sizeof(nm_str));
|
|
|
|
strncpy(gw_str, ipaddr_ntoa(&gw), sizeof(gw_str));
|
2006-09-12 07:11:22 +00:00
|
|
|
printf("Host at %s mask %s gateway %s\n", ip_str, nm_str, gw_str);
|
|
|
|
|
2010-01-30 14:16:47 +00:00
|
|
|
|
2003-01-31 13:35:43 +00:00
|
|
|
#ifdef PERF
|
|
|
|
perf_init("/tmp/minimal.perf");
|
|
|
|
#endif /* PERF */
|
2008-01-15 13:10:51 +00:00
|
|
|
|
|
|
|
lwip_init();
|
|
|
|
|
2003-01-31 13:35:43 +00:00
|
|
|
printf("TCP/IP initialized.\n");
|
2010-01-30 14:16:47 +00:00
|
|
|
|
2009-04-18 11:21:24 +00:00
|
|
|
netif_add(&netif, &ipaddr, &netmask, &gw, NULL, mintapif_init, ethernet_input);
|
2003-11-24 08:24:55 +00:00
|
|
|
netif_set_default(&netif);
|
2005-10-10 07:25:35 +00:00
|
|
|
netif_set_up(&netif);
|
|
|
|
|
2006-10-06 09:59:46 +00:00
|
|
|
|
|
|
|
#if SNMP_PRIVATE_MIB != 0
|
|
|
|
/* initialize our private example MIB */
|
|
|
|
lwip_privmib_init();
|
|
|
|
#endif
|
2006-09-12 07:11:22 +00:00
|
|
|
snmp_trap_dst_ip_set(0,&trap_addr);
|
|
|
|
snmp_trap_dst_enable(0,trap_flag);
|
|
|
|
snmp_set_syscontact(syscontact_str,&syscontact_len);
|
|
|
|
snmp_set_syslocation(syslocation_str,&syslocation_len);
|
|
|
|
snmp_set_snmpenableauthentraps(&snmpauthentraps_set);
|
|
|
|
snmp_init();
|
|
|
|
|
2003-01-31 13:35:43 +00:00
|
|
|
echo_init();
|
2010-01-30 14:16:47 +00:00
|
|
|
|
2006-07-03 07:16:48 +00:00
|
|
|
timer_init();
|
2009-04-18 11:21:24 +00:00
|
|
|
timer_set_interval(TIMER_EVT_ETHARPTMR, ARP_TMR_INTERVAL / 10);
|
|
|
|
timer_set_interval(TIMER_EVT_TCPTMR, TCP_TMR_INTERVAL / 10);
|
2006-07-03 07:16:48 +00:00
|
|
|
#if IP_REASSEMBLY
|
2009-04-18 11:21:24 +00:00
|
|
|
timer_set_interval(TIMER_EVT_IPREASSTMR, IP_TMR_INTERVAL / 10);
|
2006-07-03 07:16:48 +00:00
|
|
|
#endif
|
|
|
|
|
2003-01-31 13:35:43 +00:00
|
|
|
printf("Applications started.\n");
|
|
|
|
|
|
|
|
|
2003-05-01 13:27:52 +00:00
|
|
|
while (1) {
|
2003-01-31 13:35:43 +00:00
|
|
|
|
2006-07-03 07:16:48 +00:00
|
|
|
/* poll for input packet and ensure
|
|
|
|
select() or read() arn't interrupted */
|
|
|
|
sigemptyset(&mask);
|
|
|
|
sigaddset(&mask, SIGALRM);
|
|
|
|
sigprocmask(SIG_BLOCK, &mask, &oldmask);
|
2005-10-10 07:25:35 +00:00
|
|
|
|
2006-07-03 07:16:48 +00:00
|
|
|
/* start of critical section,
|
|
|
|
poll netif, pass packet to lwIP */
|
|
|
|
if (mintapif_select(&netif) > 0)
|
|
|
|
{
|
|
|
|
/* work, immediatly end critical section
|
|
|
|
hoping lwIP ended quickly ... */
|
|
|
|
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* no work, wait a little (10 msec) for SIGALRM */
|
|
|
|
sigemptyset(&empty);
|
|
|
|
sigsuspend(&empty);
|
|
|
|
/* ... end critical section */
|
|
|
|
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
|
|
|
}
|
|
|
|
|
2009-04-18 11:21:24 +00:00
|
|
|
if(timer_testclr_evt(TIMER_EVT_TCPTMR))
|
2006-07-03 07:16:48 +00:00
|
|
|
{
|
2009-04-18 11:21:24 +00:00
|
|
|
tcp_tmr();
|
2006-07-03 07:16:48 +00:00
|
|
|
}
|
2006-03-02 16:28:49 +00:00
|
|
|
#if IP_REASSEMBLY
|
2006-07-03 07:16:48 +00:00
|
|
|
if(timer_testclr_evt(TIMER_EVT_IPREASSTMR))
|
|
|
|
{
|
2006-03-02 16:28:49 +00:00
|
|
|
ip_reass_tmr();
|
|
|
|
}
|
2006-07-03 07:16:48 +00:00
|
|
|
#endif
|
|
|
|
if(timer_testclr_evt(TIMER_EVT_ETHARPTMR))
|
|
|
|
{
|
2006-03-02 16:28:49 +00:00
|
|
|
etharp_tmr();
|
2005-10-10 07:25:35 +00:00
|
|
|
}
|
2006-03-02 16:28:49 +00:00
|
|
|
|
2003-01-31 13:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|