This commit is contained in:
刘可亮
2024-06-04 19:00:30 +08:00
parent 990c72f5be
commit 0a13af6a1d
1668 changed files with 342810 additions and 37726 deletions

View File

@@ -1,337 +0,0 @@
/**
* @file
* Ethernet Interface Skeleton
*
*/
/*
* Copyright (c) 2001-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. 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>
*
*/
/*
* This file is a skeleton for developing Ethernet network interface
* drivers for lwIP. Add code to the low_level functions and do a
* search-and-replace for the word "ethernetif" to replace it with
* something that better describes your network interface.
*/
#include "lwip/opt.h"
#if 0 /* don't build, this is only a skeleton, see previous comment */
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/ethip6.h"
#include "lwip/etharp.h"
#include "netif/ppp/pppoe.h"
/* Define those to better describe your network interface. */
#define IFNAME0 'e'
#define IFNAME1 'n'
/**
* Helper struct to hold private data used to operate your ethernet interface.
* Keeping the ethernet address of the MAC in this struct is not necessary
* as it is already kept in the struct netif.
* But this is only an example, anyway...
*/
struct ethernetif {
struct eth_addr *ethaddr;
/* Add whatever per-interface state that is needed here. */
};
/* Forward declarations. */
static void ethernetif_input(struct netif *netif);
/**
* In this function, the hardware should be initialized.
* Called from ethernetif_init().
*
* @param netif the already initialized lwip network interface structure
* for this ethernetif
*/
static void
low_level_init(struct netif *netif)
{
struct ethernetif *ethernetif = netif->state;
/* set MAC hardware address length */
netif->hwaddr_len = ETHARP_HWADDR_LEN;
/* set MAC hardware address */
netif->hwaddr[0] = ;
...
netif->hwaddr[5] = ;
/* maximum transfer unit */
netif->mtu = 1500;
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
#if LWIP_IPV6 && LWIP_IPV6_MLD
/*
* For hardware/netifs that implement MAC filtering.
* All-nodes link-local is handled by default, so we must let the hardware know
* to allow multicast packets in.
* Should set mld_mac_filter previously. */
if (netif->mld_mac_filter != NULL) {
ip6_addr_t ip6_allnodes_ll;
ip6_addr_set_allnodes_linklocal(&ip6_allnodes_ll);
netif->mld_mac_filter(netif, &ip6_allnodes_ll, NETIF_ADD_MAC_FILTER);
}
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
/* Do whatever else is needed to initialize interface. */
}
/**
* This function should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf
* might be chained.
*
* @param netif the lwip network interface structure for this ethernetif
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
* @return ERR_OK if the packet could be sent
* an err_t value if the packet couldn't be sent
*
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
* strange results. You might consider waiting for space in the DMA queue
* to become available since the stack doesn't retry to send a packet
* dropped because of memory failure (except for the TCP timers).
*/
static err_t
low_level_output(struct netif *netif, struct pbuf *p)
{
struct ethernetif *ethernetif = netif->state;
struct pbuf *q;
initiate transfer();
#if ETH_PAD_SIZE
pbuf_remove_header(p, ETH_PAD_SIZE); /* drop the padding word */
#endif
for (q = p; q != NULL; q = q->next) {
/* Send the data from the pbuf to the interface, one pbuf at a
time. The size of the data in each pbuf is kept in the ->len
variable. */
send data from(q->payload, q->len);
}
signal that packet should be sent();
MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len);
if (((u8_t *)p->payload)[0] & 1) {
/* broadcast or multicast packet*/
MIB2_STATS_NETIF_INC(netif, ifoutnucastpkts);
} else {
/* unicast packet */
MIB2_STATS_NETIF_INC(netif, ifoutucastpkts);
}
/* increase ifoutdiscards or ifouterrors on error */
#if ETH_PAD_SIZE
pbuf_add_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif
LINK_STATS_INC(link.xmit);
return ERR_OK;
}
/**
* Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf.
*
* @param netif the lwip network interface structure for this ethernetif
* @return a pbuf filled with the received packet (including MAC header)
* NULL on memory error
*/
static struct pbuf *
low_level_input(struct netif *netif)
{
struct ethernetif *ethernetif = netif->state;
struct pbuf *p, *q;
u16_t len;
/* Obtain the size of the packet and put it into the "len"
variable. */
len = ;
#if ETH_PAD_SIZE
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
#endif
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL) {
#if ETH_PAD_SIZE
pbuf_remove_header(p, ETH_PAD_SIZE); /* drop the padding word */
#endif
/* We iterate over the pbuf chain until we have read the entire
* packet into the pbuf. */
for (q = p; q != NULL; q = q->next) {
/* Read enough bytes to fill this pbuf in the chain. The
* available data in the pbuf is given by the q->len
* variable.
* This does not necessarily have to be a memcpy, you can also preallocate
* pbufs for a DMA-enabled MAC and after receiving truncate it to the
* actually received size. In this case, ensure the tot_len member of the
* pbuf is the sum of the chained pbuf len members.
*/
read data into(q->payload, q->len);
}
acknowledge that packet has been read();
MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len);
if (((u8_t *)p->payload)[0] & 1) {
/* broadcast or multicast packet*/
MIB2_STATS_NETIF_INC(netif, ifinnucastpkts);
} else {
/* unicast packet*/
MIB2_STATS_NETIF_INC(netif, ifinucastpkts);
}
#if ETH_PAD_SIZE
pbuf_add_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif
LINK_STATS_INC(link.recv);
} else {
drop packet();
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
MIB2_STATS_NETIF_INC(netif, ifindiscards);
}
return p;
}
/**
* This function should be called when a packet is ready to be read
* from the interface. It uses the function low_level_input() that
* should handle the actual reception of bytes from the network
* interface. Then the type of the received packet is determined and
* the appropriate input function is called.
*
* @param netif the lwip network interface structure for this ethernetif
*/
static void
ethernetif_input(struct netif *netif)
{
struct ethernetif *ethernetif;
struct eth_hdr *ethhdr;
struct pbuf *p;
ethernetif = netif->state;
/* move received packet into a new pbuf */
p = low_level_input(netif);
/* if no packet could be read, silently ignore this */
if (p != NULL) {
/* pass all packets to ethernet_input, which decides what packets it supports */
if (netif->input(p, netif) != ERR_OK) {
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
pbuf_free(p);
p = NULL;
}
}
}
/**
* Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the
* actual setup of the hardware.
*
* This function should be passed as a parameter to netif_add().
*
* @param netif the lwip network interface structure for this ethernetif
* @return ERR_OK if the loopif is initialized
* ERR_MEM if private data couldn't be allocated
* any other err_t on error
*/
err_t
ethernetif_init(struct netif *netif)
{
struct ethernetif *ethernetif;
LWIP_ASSERT("netif != NULL", (netif != NULL));
ethernetif = mem_malloc(sizeof(struct ethernetif));
if (ethernetif == NULL) {
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));
return ERR_MEM;
}
#if LWIP_NETIF_HOSTNAME
/* Initialize interface hostname */
netif->hostname = "lwip";
#endif /* LWIP_NETIF_HOSTNAME */
/*
* Initialize the snmp variables and counters inside the struct netif.
* The last argument should be replaced with your link speed, in units
* of bits per second.
*/
MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
netif->state = ethernetif;
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output()
* from it if you have to do some checks before sending (e.g. if link
* is available...) */
#if LWIP_IPV4
netif->output = etharp_output;
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
netif->linkoutput = low_level_output;
ethernetif->ethaddr = (struct eth_addr *) & (netif->hwaddr[0]);
/* initialize the hardware */
low_level_init(netif);
return ERR_OK;
}
#endif /* 0 */

View File

@@ -21,10 +21,13 @@ static void list_ifconfig(void)
struct netif *netif;
for (netif = netif_list; netif != NULL; netif = netif->next) {
printf("%s%d:\n",netif->name, netif->num);
printf(" IPv4 Address : %s\n", ip4addr_ntoa(&netif->ip_addr));
printf(" Default Gateway: %s\n", ip4addr_ntoa(&netif->gw));
printf(" Subnet mask : %s\n", ip4addr_ntoa(&netif->netmask));
printf("%c%c%d:\n",netif->name[0], netif->name[1], netif->num);
printf(" IPv4 Address : %s\n", ip_ntoa(&netif->ip_addr));
printf(" Default Gateway: %s\n", ip_ntoa(&netif->gw));
printf(" Subnet mask : %s\n", ip_ntoa(&netif->netmask));
#if LWIP_IPV6
printf(" IPv6 Local address : %s\n", ip6addr_ntoa(netif_ip6_addr(netif, 0)));
#endif
printf(" MAC addr : %02x:%02x:%02x:%02x:%02x:%02x\n",
netif->hwaddr[0],
netif->hwaddr[1],
@@ -39,36 +42,38 @@ static void list_ifconfig(void)
#include "ethernetif.h"
#include "aic_mac.h"
aicmac_netif_t aic_netif;
#if LWIP_IPV4
void init_gmac_netif(const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw)
void init_gmac_netif(int gmac_no, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw)
#else
void init_gmac_netif(void)
#endif
void init_gmac_netif(int gmac_no)
#endif /* LWIP_IPV4 */
{
/* Select aic mac port num */
aic_netif.port = 0;
/* ethernet init */
#ifdef AIC_USING_GMAC0
#if LWIP_IPV4
aicmac_netif_t *aic_netif = malloc(sizeof(aicmac_netif_t));
if (aic_netif == NULL) {
printf("No enough memory for ethernet%d\n", gmac_no);
return;
}
/* Select aic mac port num */
aic_netif->port = gmac_no;
#if LWIP_IPV4
#if NO_SYS
netif_add(&aic_netif.netif, ipaddr, netmask, gw, NULL, ethernetif_init, netif_input);
netif_add(&aic_netif->netif, ipaddr, netmask, gw, NULL, ethernetif_init, netif_input);
#else /* NO_SYS */
netif_add(&aic_netif.netif, ipaddr, netmask, gw, NULL, ethernetif_init, tcpip_input);
netif_add(&aic_netif->netif, ipaddr, netmask, gw, NULL, ethernetif_init, tcpip_input);
#endif /* !NO_SYS */
#else /* LWIP_IPV4 */
#if NO_SYS
netif_add(&aic_netif.netif, NULL, ethernetif_init, netif_input);
netif_add(&aic_netif->netif, NULL, ethernetif_init, netif_input);
#else
netif_add(&aic_netif.netif, NULL, ethernetif_init, tcpip_input);
netif_add(&aic_netif->netif, NULL, ethernetif_init, tcpip_input);
#endif /* !NO_SYS */
#endif /* !LWIP_IPV4 */
netif_set_up(&aic_netif.netif);
#endif /* AIC_USING_GMAC0 */
netif_set_up(&aic_netif->netif);
}
#endif /* defined(AIC_USING_GMAC0) | defined(AIC_USING_GMAC1) */
@@ -90,11 +95,25 @@ void netif_startup(void)
ip4addr_aton(AIC_DEV_GMAC0_IPADDR, &ipaddr);
ip4addr_aton(AIC_DEV_GMAC0_NETMASK, &netmask);
#endif
init_gmac_netif(&ipaddr, &netmask, &gw);
init_gmac_netif(0, &ipaddr, &netmask, &gw);
#else
init_gmac_netif();
init_gmac_netif(0);
#endif /* LWIP_IPV4 */
#endif /* WLAN */
#endif /* AIC_USING_GMAC0 */
#ifdef AIC_USING_GMAC1
#if LWIP_IPV4
#if !LWIP_DHCP
ip4addr_aton(AIC_DEV_GMAC1_GW, &gw);
ip4addr_aton(AIC_DEV_GMAC1_IPADDR, &ipaddr);
ip4addr_aton(AIC_DEV_GMAC1_NETMASK, &netmask);
#endif
init_gmac_netif(1, &ipaddr, &netmask, &gw);
#else
init_gmac_netif(1);
#endif /* LWIP_IPV4 */
#endif /* AIC_USING_GMAC1 */
#ifdef AIC_USING_REALTEK_WLAN0
#if LWIP_IPV4
@@ -129,16 +148,15 @@ void netif_startup(void)
}
#if NO_SYS
extern void aic_phy_poll(void);
extern void aic_phy_poll(struct netif *netif);
void netif_baremetal_poll(void)
{
struct netif *netif;
aic_phy_poll();
for (netif = netif_list; netif != NULL; netif = netif->next) {
aic_phy_poll(netif);
if (netif_is_link_up(netif)) {
ethernetif_input_poll();
ethernetif_input_poll(netif);
}
}
}

View File

@@ -116,11 +116,6 @@
#define USE_DEFAULT_ETH_NETIF 1
#endif
/** Define this to 1 to enable a PPP interface. */
#ifndef USE_PPP
#define USE_PPP 0
#endif
/** Define this to 1 or 2 to support 1 or 2 SLIP interfaces. */
#ifndef USE_SLIPIF
#define USE_SLIPIF 0
@@ -158,112 +153,6 @@ struct dhcp netif_dhcp;
struct autoip netif_autoip;
#endif /* LWIP_AUTOIP */
#endif /* USE_ETHERNET */
#if USE_PPP
/* THE PPP PCB */
ppp_pcb *ppp;
/* THE PPP interface */
struct netif ppp_netif;
/* THE PPP descriptor */
u8_t sio_idx = 0;
sio_fd_t ppp_sio;
#endif /* USE_PPP */
#if USE_SLIPIF
struct netif slipif1;
#if USE_SLIPIF > 1
struct netif slipif2;
#endif /* USE_SLIPIF > 1 */
#endif /* USE_SLIPIF */
#if USE_PPP
static void
pppLinkStatusCallback(ppp_pcb *pcb, int errCode, void *ctx)
{
struct netif *pppif = ppp_netif(pcb);
LWIP_UNUSED_ARG(ctx);
switch(errCode) {
case PPPERR_NONE: { /* No error. */
printf("pppLinkStatusCallback: PPPERR_NONE\n");
#if LWIP_IPV4
printf(" our_ipaddr = %s\n", ip4addr_ntoa(netif_ip4_addr(pppif)));
printf(" his_ipaddr = %s\n", ip4addr_ntoa(netif_ip4_gw(pppif)));
printf(" netmask = %s\n", ip4addr_ntoa(netif_ip4_netmask(pppif)));
#endif /* LWIP_IPV4 */
#if LWIP_DNS
printf(" dns1 = %s\n", ipaddr_ntoa(dns_getserver(0)));
printf(" dns2 = %s\n", ipaddr_ntoa(dns_getserver(1)));
#endif /* LWIP_DNS */
#if PPP_IPV6_SUPPORT
printf(" our6_ipaddr = %s\n", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
#endif /* PPP_IPV6_SUPPORT */
break;
}
case PPPERR_PARAM: { /* Invalid parameter. */
printf("pppLinkStatusCallback: PPPERR_PARAM\n");
break;
}
case PPPERR_OPEN: { /* Unable to open PPP session. */
printf("pppLinkStatusCallback: PPPERR_OPEN\n");
break;
}
case PPPERR_DEVICE: { /* Invalid I/O device for PPP. */
printf("pppLinkStatusCallback: PPPERR_DEVICE\n");
break;
}
case PPPERR_ALLOC: { /* Unable to allocate resources. */
printf("pppLinkStatusCallback: PPPERR_ALLOC\n");
break;
}
case PPPERR_USER: { /* User interrupt. */
printf("pppLinkStatusCallback: PPPERR_USER\n");
break;
}
case PPPERR_CONNECT: { /* Connection lost. */
printf("pppLinkStatusCallback: PPPERR_CONNECT\n");
break;
}
case PPPERR_AUTHFAIL: { /* Failed authentication challenge. */
printf("pppLinkStatusCallback: PPPERR_AUTHFAIL\n");
break;
}
case PPPERR_PROTOCOL: { /* Failed to meet protocol. */
printf("pppLinkStatusCallback: PPPERR_PROTOCOL\n");
break;
}
case PPPERR_PEERDEAD: { /* Connection timeout */
printf("pppLinkStatusCallback: PPPERR_PEERDEAD\n");
break;
}
case PPPERR_IDLETIMEOUT: { /* Idle Timeout */
printf("pppLinkStatusCallback: PPPERR_IDLETIMEOUT\n");
break;
}
case PPPERR_CONNECTTIME: { /* Max connect time reached */
printf("pppLinkStatusCallback: PPPERR_CONNECTTIME\n");
break;
}
case PPPERR_LOOPBACK: { /* Loopback detected */
printf("pppLinkStatusCallback: PPPERR_LOOPBACK\n");
break;
}
default: {
printf("pppLinkStatusCallback: unknown errCode %d\n", errCode);
break;
}
}
}
#if PPPOS_SUPPORT
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 /* PPPOS_SUPPORT */
#endif /* USE_PPP */
#if LWIP_NETIF_STATUS_CALLBACK
static void
@@ -292,52 +181,15 @@ link_callback(struct netif *state_netif)
}
}
#endif /* LWIP_NETIF_LINK_CALLBACK */
#include "lwip/mld6.h"
/* This function initializes all network interfaces */
static void
test_netif_init(void)
{
#if USE_SLIPIF
u8_t num_slip1 = 0;
#if LWIP_IPV4
ip4_addr_t ipaddr_slip1, netmask_slip1, gw_slip1;
#endif
#if USE_SLIPIF > 1
u8_t num_slip2 = 1;
#if LWIP_IPV4
ip4_addr_t ipaddr_slip2, netmask_slip2, gw_slip2;
#endif
#endif /* USE_SLIPIF > 1 */
#endif /* USE_SLIPIF */
#if USE_DHCP || USE_AUTOIP
err_t err;
#endif
#if USE_PPP
const char *username = NULL, *password = NULL;
#ifdef PPP_USERNAME
username = PPP_USERNAME;
#endif
#ifdef PPP_PASSWORD
password = PPP_PASSWORD;
#endif
printf("ppp_connect: COM%d\n", (int)sio_idx);
#if PPPOS_SUPPORT
ppp_sio = sio_open(sio_idx);
if (ppp_sio == NULL) {
printf("sio_open error\n");
} else {
ppp = pppos_create(&ppp_netif, ppp_output_cb, pppLinkStatusCallback, NULL);
if (ppp == NULL) {
printf("pppos_create error\n");
} else {
ppp_set_auth(ppp, PPPAUTHTYPE_ANY, username, password);
ppp_connect(ppp, 0);
}
}
#endif /* PPPOS_SUPPORT */
#endif /* USE_PPP */
#if USE_ETHERNET
netif_startup();
@@ -348,6 +200,7 @@ test_netif_init(void)
#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 */
@@ -376,102 +229,9 @@ test_netif_init(void)
netif.flags |= NETIF_FLAG_ETHERNET; /* but pure ethernet */
#endif /* USE_ETHERNET_TCPIP */
#if USE_PPP && PPPOE_SUPPORT
/* start PPPoE after ethernet netif is added! */
ppp = pppoe_create(&ppp_netif, netif_default, NULL, NULL, pppLinkStatusCallback, NULL);
if (ppp == NULL) {
printf("pppoe_create error\n");
} else {
ppp_set_auth(ppp, PPPAUTHTYPE_ANY, username, password);
ppp_connect(ppp, 0);
}
#endif /* USE_PPP && PPPOE_SUPPORT */
#endif /* USE_ETHERNET */
#if USE_SLIPIF
#if LWIP_IPV4
#define SLIP1_ADDRS &ipaddr_slip1, &netmask_slip1, &gw_slip1,
LWIP_PORT_INIT_SLIP1_IPADDR(&ipaddr_slip1);
LWIP_PORT_INIT_SLIP1_GW(&gw_slip1);
LWIP_PORT_INIT_SLIP1_NETMASK(&netmask_slip1);
printf("Starting lwIP slipif, local interface IP is %s\n", ip4addr_ntoa(&ipaddr_slip1));
#else
#define SLIP1_ADDRS
printf("Starting lwIP slipif\n");
#endif
#if defined(SIO_USE_COMPORT) && SIO_USE_COMPORT
num_slip1++; /* COM ports cannot be 0-based */
#endif
netif_add(&slipif1, SLIP1_ADDRS &num_slip1, slipif_init, ip_input);
#if !USE_ETHERNET
netif_set_default(&slipif1);
#endif /* !USE_ETHERNET */
#if LWIP_IPV6
netif_create_ip6_linklocal_address(&slipif1, 1);
printf("SLIP ip6 linklocal address: %s\n", ip6addr_ntoa(netif_ip6_addr(&slipif1, 0)));
#endif /* LWIP_IPV6 */
#if LWIP_NETIF_STATUS_CALLBACK
netif_set_status_callback(&slipif1, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
netif_set_link_callback(&slipif1, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */
netif_set_up(&slipif1);
#if USE_SLIPIF > 1
#if LWIP_IPV4
#define SLIP2_ADDRS &ipaddr_slip2, &netmask_slip2, &gw_slip2,
LWIP_PORT_INIT_SLIP2_IPADDR(&ipaddr_slip2);
LWIP_PORT_INIT_SLIP2_GW(&gw_slip2);
LWIP_PORT_INIT_SLIP2_NETMASK(&netmask_slip2);
printf("Starting lwIP SLIP if #2, local interface IP is %s\n", ip4addr_ntoa(&ipaddr_slip2));
#else
#define SLIP2_ADDRS
printf("Starting lwIP SLIP if #2\n");
#endif
#if defined(SIO_USE_COMPORT) && SIO_USE_COMPORT
num_slip2++; /* COM ports cannot be 0-based */
#endif
netif_add(&slipif2, SLIP2_ADDRS &num_slip2, slipif_init, ip_input);
#if LWIP_IPV6
netif_create_ip6_linklocal_address(&slipif1, 1);
printf("SLIP2 ip6 linklocal address: ");
ip6_addr_debug_print(0xFFFFFFFF & ~LWIP_DBG_HALT, netif_ip6_addr(&slipif2, 0));
printf("\n");
#endif /* LWIP_IPV6 */
#if LWIP_NETIF_STATUS_CALLBACK
netif_set_status_callback(&slipif2, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
netif_set_link_callback(&slipif2, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */
netif_set_up(&slipif2);
#endif /* USE_SLIPIF > 1*/
#endif /* USE_SLIPIF */
}
#if LWIP_DNS_APP && LWIP_DNS
static void
dns_found(const char *name, const ip_addr_t *addr, void *arg)
{
LWIP_UNUSED_ARG(arg);
printf("%s: %s\n", name, addr ? ipaddr_ntoa(addr) : "<not found>");
}
static void
dns_dorequest(void *arg)
{
const char* dnsname = "3com.com";
ip_addr_t dnsresp;
LWIP_UNUSED_ARG(arg);
if (dns_gethostbyname(dnsname, &dnsresp, dns_found, 0) == ERR_OK) {
dns_found(dnsname, &dnsresp, 0);
}
}
#endif /* LWIP_DNS_APP && LWIP_DNS */
/* 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 */
@@ -486,9 +246,6 @@ test_init(void * arg)
init_sem = (sys_sem_t*)arg;
#endif /* NO_SYS */
/* init randomizer again (seed per thread) */
//srand((unsigned int)time(0));
/* init network interfaces */
test_netif_init();
@@ -507,13 +264,6 @@ void lwip_test_example_main_loop(void * data)
err_t err;
sys_sem_t init_sem;
#endif /* NO_SYS */
#if USE_PPP
#if !USE_ETHERNET
int count;
u8_t rxbuf[1024];
#endif
volatile int callClosePpp = 0;
#endif /* USE_PPP */
/* initialize lwIP stack, network interfaces and applications */
#if NO_SYS
@@ -530,115 +280,17 @@ void lwip_test_example_main_loop(void * data)
sys_sem_free(&init_sem);
#endif /* NO_SYS */
#if (LWIP_SOCKET || LWIP_NETCONN) && LWIP_NETCONN_SEM_PER_THREAD
netconn_thread_init();
#endif
#if NO_SYS
/* MAIN LOOP for driver update (and timers if NO_SYS) */
while (!LWIP_EXAMPLE_APP_ABORT()) {
#if NO_SYS
/* handle timers (already done in tcpip.c when NO_SYS=0) */
sys_check_timeouts();
netif_baremetal_poll();
}
#endif /* NO_SYS */
#if USE_ETHERNET
sys_msleep(5000);
#else /* USE_ETHERNET */
/* try to read characters from serial line and pass them to PPPoS */
count = sio_read(ppp_sio, (u8_t*)rxbuf, 1024);
if(count > 0) {
pppos_input(ppp, rxbuf, count);
} else {
/* nothing received, give other tasks a chance to run */
sys_msleep(1);
}
#endif /* USE_ETHERNET */
#if USE_SLIPIF
slipif_poll(&slipif1);
#if USE_SLIPIF > 1
slipif_poll(&slipif2);
#endif /* USE_SLIPIF > 1 */
#endif /* USE_SLIPIF */
#if ENABLE_LOOPBACK && !LWIP_NETIF_LOOPBACK_MULTITHREADING
/* check for loopback packets on all netifs */
netif_poll_all();
#endif /* ENABLE_LOOPBACK && !LWIP_NETIF_LOOPBACK_MULTITHREADING */
#if USE_PPP
{
int do_hup = 0;
if(do_hup) {
ppp_close(ppp, 1);
do_hup = 0;
}
}
if(callClosePpp && ppp) {
/* make sure to disconnect PPP before stopping the program... */
callClosePpp = 0;
#if NO_SYS
ppp_close(ppp, 0);
#else
pppapi_close(ppp, 0);
#endif
ppp = NULL;
}
#endif /* USE_PPP */
}
#if USE_PPP
if(ppp) {
u32_t started;
printf("Closing PPP connection...\n");
/* make sure to disconnect PPP before stopping the program... */
#if NO_SYS
ppp_close(ppp, 0);
#else
pppapi_close(ppp, 0);
#endif
ppp = NULL;
/* Wait for some time to let PPP finish... */
started = sys_now();
do
{
#if USE_ETHERNET
default_netif_poll();
#endif
/* @todo: need a better check here: only wait until PPP is down */
} while(sys_now() - started < 5000);
}
#endif /* USE_PPP */
#if (LWIP_SOCKET || LWIP_NETCONN) && LWIP_NETCONN_SEM_PER_THREAD
netconn_thread_cleanup();
#endif
#if USE_ETHERNET
// default_netif_shutdown();
#endif /* USE_ETHERNET */
}
#if 0
#if USE_PPP && PPPOS_SUPPORT
int main(int argc, char **argv)
#else /* USE_PPP && PPPOS_SUPPORT */
int main(void)
#endif /* USE_PPP && PPPOS_SUPPORT */
{
#if USE_PPP && PPPOS_SUPPORT
if(argc > 1) {
sio_idx = (u8_t)atoi(argv[1]);
}
printf("Using serial port %d for PPP\n", sio_idx);
#endif /* USE_PPP && PPPOS_SUPPORT */
/* no stdio-buffering, please! */
setvbuf(stdout, NULL,_IONBF, 0);
main_loop();
return 0;
}
#endif
#if defined(KERNEL_RTTHREAD)
#include <rtthread.h>
#include <rtdevice.h>