mirror of
https://gitee.com/Vancouver2017/luban-lite-t3e-pro.git
synced 2025-12-14 18:38:55 +00:00
310 lines
8.5 KiB
C
310 lines
8.5 KiB
C
/*
|
|
* Copyright (c) 2001,2002 Florian Schulze.
|
|
* 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 authors nor the names of the contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 AUTHORS 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.
|
|
*
|
|
* test.c - This file is part of lwIP test
|
|
*
|
|
*/
|
|
|
|
/* C runtime includes */
|
|
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
#include <time.h>
|
|
#include <string.h>
|
|
|
|
/* lwIP core includes */
|
|
#include "lwip/opt.h"
|
|
|
|
#include "lwip/sys.h"
|
|
#include "lwip/timeouts.h"
|
|
#include "lwip/debug.h"
|
|
#include "lwip/stats.h"
|
|
#include "lwip/init.h"
|
|
#include "lwip/tcpip.h"
|
|
#include "lwip/netif.h"
|
|
#include "lwip/api.h"
|
|
|
|
#include "lwip/tcp.h"
|
|
#include "lwip/udp.h"
|
|
#include "lwip/dns.h"
|
|
#include "lwip/dhcp.h"
|
|
#include "lwip/autoip.h"
|
|
|
|
/* lwIP netif includes */
|
|
#include "lwip/etharp.h"
|
|
#include "netif/ethernet.h"
|
|
|
|
/* applications includes */
|
|
#include "lwip/apps/netbiosns.h"
|
|
#include "lwip/apps/httpd.h"
|
|
#include "apps/httpserver/httpserver-netconn.h"
|
|
#include "apps/netio/netio.h"
|
|
#include "apps/ping/ping.h"
|
|
#include "apps/rtp/rtp.h"
|
|
#include "apps/chargen/chargen.h"
|
|
#include "apps/shell/shell.h"
|
|
#include "apps/tcpecho/tcpecho.h"
|
|
#include "apps/udpecho/udpecho.h"
|
|
#include "apps/tcpecho_raw/tcpecho_raw.h"
|
|
#include "apps/socket_examples/socket_examples.h"
|
|
|
|
#include "examples/lwiperf/lwiperf_example.h"
|
|
#include "examples/mdns/mdns_example.h"
|
|
#include "examples/snmp/snmp_example.h"
|
|
#include "examples/tftp/tftp_example.h"
|
|
#include "examples/sntp/sntp_example.h"
|
|
#include "examples/mqtt/mqtt_example.h"
|
|
|
|
#include "examples/httpd/cgi_example/cgi_example.h"
|
|
#include "examples/httpd/fs_example/fs_example.h"
|
|
#include "examples/httpd/ssi_example/ssi_example.h"
|
|
|
|
#include "netif_startup.h"
|
|
|
|
#if NO_SYS
|
|
/* ... then we need information about the timer intervals: */
|
|
#include "lwip/ip4_frag.h"
|
|
#include "lwip/igmp.h"
|
|
#endif /* NO_SYS */
|
|
|
|
#include "netif/ppp/ppp_opts.h"
|
|
#if PPP_SUPPORT
|
|
/* PPP includes */
|
|
#include "lwip/sio.h"
|
|
#include "netif/ppp/pppapi.h"
|
|
#include "netif/ppp/pppos.h"
|
|
#include "netif/ppp/pppoe.h"
|
|
#if !NO_SYS && !LWIP_PPP_API
|
|
#error With NO_SYS==0, LWIP_PPP_API==1 is required.
|
|
#endif
|
|
#endif /* PPP_SUPPORT */
|
|
|
|
/* include the port-dependent configuration */
|
|
#include "lwipcfg.h"
|
|
|
|
#ifndef LWIP_EXAMPLE_APP_ABORT
|
|
#define LWIP_EXAMPLE_APP_ABORT() 0
|
|
#endif
|
|
|
|
/** Define this to 1 to enable a port-specific ethernet interface as default interface. */
|
|
#ifndef USE_DEFAULT_ETH_NETIF
|
|
#define USE_DEFAULT_ETH_NETIF 1
|
|
#endif
|
|
|
|
/** Define this to 1 or 2 to support 1 or 2 SLIP interfaces. */
|
|
#ifndef USE_SLIPIF
|
|
#define USE_SLIPIF 0
|
|
#endif
|
|
|
|
/** Use an ethernet adapter? Default to enabled if port-specific ethernet netif or PPPoE are used. */
|
|
#ifndef USE_ETHERNET
|
|
#define USE_ETHERNET (USE_DEFAULT_ETH_NETIF || PPPOE_SUPPORT)
|
|
#endif
|
|
|
|
/** Use an ethernet adapter for TCP/IP? By default only if port-specific ethernet netif is used. */
|
|
#ifndef USE_ETHERNET_TCPIP
|
|
#define USE_ETHERNET_TCPIP (USE_DEFAULT_ETH_NETIF)
|
|
#endif
|
|
|
|
#if USE_SLIPIF
|
|
#include <netif/slipif.h>
|
|
#endif /* USE_SLIPIF */
|
|
|
|
#ifndef USE_DHCP
|
|
#define USE_DHCP LWIP_DHCP
|
|
#endif
|
|
#ifndef USE_AUTOIP
|
|
#define USE_AUTOIP LWIP_AUTOIP
|
|
#endif
|
|
|
|
/* globales variables for netifs */
|
|
#if USE_ETHERNET
|
|
#if LWIP_DHCP
|
|
/* dhcp struct for the ethernet netif */
|
|
struct dhcp netif_dhcp;
|
|
#endif /* LWIP_DHCP */
|
|
#if LWIP_AUTOIP
|
|
/* autoip struct for the ethernet netif */
|
|
struct autoip netif_autoip;
|
|
#endif /* LWIP_AUTOIP */
|
|
#endif /* USE_ETHERNET */
|
|
|
|
#if LWIP_NETIF_STATUS_CALLBACK
|
|
static void
|
|
status_callback(struct netif *state_netif)
|
|
{
|
|
if (netif_is_up(state_netif)) {
|
|
#if LWIP_IPV4
|
|
printf("status_callback==UP, local interface IP is %s\n", ip4addr_ntoa(netif_ip4_addr(state_netif)));
|
|
#else
|
|
printf("status_callback==UP\n");
|
|
#endif
|
|
} else {
|
|
printf("status_callback==DOWN\n");
|
|
}
|
|
}
|
|
#endif /* LWIP_NETIF_STATUS_CALLBACK */
|
|
|
|
#if LWIP_NETIF_LINK_CALLBACK
|
|
static void
|
|
link_callback(struct netif *state_netif)
|
|
{
|
|
if (netif_is_link_up(state_netif)) {
|
|
printf("link_callback==UP\n");
|
|
} else {
|
|
printf("link_callback==DOWN\n");
|
|
}
|
|
}
|
|
#endif /* LWIP_NETIF_LINK_CALLBACK */
|
|
#include "lwip/mld6.h"
|
|
/* This function initializes all network interfaces */
|
|
static void
|
|
test_netif_init(void)
|
|
{
|
|
#if USE_DHCP || USE_AUTOIP
|
|
err_t err;
|
|
#endif
|
|
|
|
#if USE_ETHERNET
|
|
netif_startup();
|
|
|
|
#if LWIP_IPV6
|
|
netif_create_ip6_linklocal_address(netif_default, 1);
|
|
#if LWIP_IPV6_AUTOCONFIG
|
|
netif_default->ip6_autoconfig_enabled = 1;
|
|
#endif
|
|
printf("ip6 linklocal address: %s\n", ip6addr_ntoa(netif_ip6_addr(netif_default, 0)));
|
|
#endif /* LWIP_IPV6 */
|
|
|
|
#if LWIP_NETIF_STATUS_CALLBACK
|
|
netif_set_status_callback(netif_default, status_callback);
|
|
#endif /* LWIP_NETIF_STATUS_CALLBACK */
|
|
#if LWIP_NETIF_LINK_CALLBACK
|
|
netif_set_link_callback(netif_default, link_callback);
|
|
#endif /* LWIP_NETIF_LINK_CALLBACK */
|
|
|
|
#if USE_ETHERNET_TCPIP
|
|
#if LWIP_AUTOIP
|
|
autoip_set_struct(netif_default, &netif_autoip);
|
|
#endif /* LWIP_AUTOIP */
|
|
#if LWIP_DHCP
|
|
dhcp_set_struct(netif_default, &netif_dhcp);
|
|
#endif /* LWIP_DHCP */
|
|
|
|
#if USE_DHCP
|
|
err = dhcp_start(netif_default);
|
|
LWIP_ASSERT("dhcp_start failed", err == ERR_OK);
|
|
#elif USE_AUTOIP
|
|
err = autoip_start(netif_default);
|
|
LWIP_ASSERT("autoip_start failed", err == ERR_OK);
|
|
#endif /* USE_DHCP */
|
|
#else /* USE_ETHERNET_TCPIP */
|
|
/* Use ethernet for PPPoE only */
|
|
netif.flags &= ~(NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP); /* no ARP */
|
|
netif.flags |= NETIF_FLAG_ETHERNET; /* but pure ethernet */
|
|
#endif /* USE_ETHERNET_TCPIP */
|
|
|
|
#endif /* USE_ETHERNET */
|
|
}
|
|
|
|
/* This function initializes this lwIP test. When NO_SYS=1, this is done in
|
|
* the main_loop context (there is no other one), when NO_SYS=0, this is done
|
|
* in the tcpip_thread context */
|
|
static void
|
|
test_init(void * arg)
|
|
{ /* remove compiler warning */
|
|
#if NO_SYS
|
|
LWIP_UNUSED_ARG(arg);
|
|
#else /* NO_SYS */
|
|
sys_sem_t *init_sem;
|
|
LWIP_ASSERT("arg != NULL", arg != NULL);
|
|
init_sem = (sys_sem_t*)arg;
|
|
#endif /* NO_SYS */
|
|
|
|
/* init network interfaces */
|
|
test_netif_init();
|
|
|
|
#if !NO_SYS
|
|
sys_sem_signal(init_sem);
|
|
#endif /* !NO_SYS */
|
|
}
|
|
|
|
/* This is somewhat different to other ports: we have a main loop here:
|
|
* a dedicated task that waits for packets to arrive. This would normally be
|
|
* done from interrupt context with embedded hardware, but we don't get an
|
|
* interrupt in windows for that :-) */
|
|
void lwip_test_example_main_loop(void * data)
|
|
{
|
|
#if !NO_SYS
|
|
err_t err;
|
|
sys_sem_t init_sem;
|
|
#endif /* NO_SYS */
|
|
|
|
/* initialize lwIP stack, network interfaces and applications */
|
|
#if NO_SYS
|
|
lwip_init();
|
|
test_init(NULL);
|
|
#else /* NO_SYS */
|
|
err = sys_sem_new(&init_sem, 0);
|
|
LWIP_ASSERT("failed to create init_sem", err == ERR_OK);
|
|
LWIP_UNUSED_ARG(err);
|
|
tcpip_init(test_init, &init_sem);
|
|
/* we have to wait for initialization to finish before
|
|
* calling update_adapter()! */
|
|
sys_sem_wait(&init_sem);
|
|
sys_sem_free(&init_sem);
|
|
#endif /* NO_SYS */
|
|
|
|
#if NO_SYS
|
|
/* MAIN LOOP for driver update (and timers if NO_SYS) */
|
|
while (!LWIP_EXAMPLE_APP_ABORT()) {
|
|
/* handle timers (already done in tcpip.c when NO_SYS=0) */
|
|
sys_check_timeouts();
|
|
|
|
netif_baremetal_poll();
|
|
}
|
|
#endif /* NO_SYS */
|
|
}
|
|
|
|
#if defined(KERNEL_RTTHREAD)
|
|
#include <rtthread.h>
|
|
#include <rtdevice.h>
|
|
#include <aic_core.h>
|
|
|
|
int lwip_test_example_init(void)
|
|
{
|
|
aicos_thread_create("lwip_test_example", 2048,
|
|
20, lwip_test_example_main_loop, NULL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
INIT_DEVICE_EXPORT(lwip_test_example_init);
|
|
#endif
|
|
|